diff simtool/miscadm.c @ 182:f4edccd4b583

fc-simtool: write-iccid-sh{18,19} commands implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 Mar 2021 05:07:46 +0000
parents 63b640562e21
children 2545dd27ca38
line wrap: on
line diff
--- a/simtool/miscadm.c	Sat Mar 06 04:51:56 2021 +0000
+++ b/simtool/miscadm.c	Sat Mar 06 05:07:46 2021 +0000
@@ -45,6 +45,39 @@
 	return write_iccid_bin(binrec);
 }
 
+cmd_write_iccid_sh18(argc, argv)
+	char **argv;
+{
+	int rc;
+	u_char nibbles[20], binrec[10];
+
+	rc = parse_decimal_shorthand(argv[1], nibbles, 18);
+	if (rc < 0)
+		return(rc);
+	nibbles[18] = compute_iccid_luhn(nibbles);
+	nibbles[19] = 0xF;
+	pack_reversed_nibbles(nibbles, binrec, 10);
+	return write_iccid_bin(binrec);
+}
+
+cmd_write_iccid_sh19(argc, argv)
+	char **argv;
+{
+	int rc;
+	u_char nibbles[20], binrec[10];
+
+	rc = parse_decimal_shorthand(argv[1], nibbles, 19);
+	if (rc < 0)
+		return(rc);
+	if (nibbles[18] != compute_iccid_luhn(nibbles)) {
+		fprintf(stderr, "error: Luhn check digit mismatch\n");
+		return(-1);
+	}
+	nibbles[19] = 0xF;
+	pack_reversed_nibbles(nibbles, binrec, 10);
+	return write_iccid_bin(binrec);
+}
+
 static
 write_imsi_bin(binrec)
 	u_char *binrec;