changeset 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
files simtool/dispatch.c simtool/miscadm.c
diffstat 2 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/dispatch.c	Sat Mar 06 04:51:56 2021 +0000
+++ b/simtool/dispatch.c	Sat Mar 06 05:07:46 2021 +0000
@@ -95,6 +95,8 @@
 extern int cmd_verify_hex();
 extern int cmd_verify_sjs1_adm1();
 extern int cmd_write_iccid();
+extern int cmd_write_iccid_sh18();
+extern int cmd_write_iccid_sh19();
 extern int cmd_write_imsi();
 
 extern int current_ef_inval();
@@ -219,6 +221,8 @@
 	{"verify-pin2", 1, 1, 0, cmd_verify_chv},
 	{"verify-sjs1-adm1", 1, 1, 0, cmd_verify_sjs1_adm1},
 	{"write-iccid", 1, 1, 0, cmd_write_iccid},
+	{"write-iccid-sh18", 1, 1, 0, cmd_write_iccid_sh18},
+	{"write-iccid-sh19", 1, 1, 0, cmd_write_iccid_sh19},
 	{"write-imsi", 1, 1, 0, cmd_write_imsi},
 	{0, 0, 0, 0, 0}
 };
--- 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;