changeset 25:9c9f6adbaedb

sim-iccid-mkrange utility added
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 15 Mar 2021 09:07:20 +0000
parents 47a491a16de3
children 322f6fcdc36e
files .hgignore libutil/Makefile libutil/decimal_incr.c utils/Makefile utils/sim-iccid-mkrange.c
diffstat 5 files changed, 68 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Mar 15 08:43:08 2021 +0000
+++ b/.hgignore	Mon Mar 15 09:07:20 2021 +0000
@@ -14,4 +14,5 @@
 ^uicc/fc-uicc-tool$
 
 ^utils/sim-iccid-mkfull$
+^utils/sim-iccid-mkrange$
 ^utils/sws-email2db$
--- a/libutil/Makefile	Mon Mar 15 08:43:08 2021 +0000
+++ b/libutil/Makefile	Mon Mar 15 09:07:20 2021 +0000
@@ -1,10 +1,10 @@
 CC=	gcc
 CFLAGS=	-O2
-OBJS=	alpha_decode.o alpha_fromfile.o alpha_valid.o decimal_str.o \
-	filesearch.o gsm7_decode.o gsm7_encode.o gsm7_encode_table.o \
-	gsm7_pack.o gsm7_unpack.o hexdigits.o hexread.o hexstr.o iccid_luhn.o \
-	nibbles2asc.o number_decode.o number_encode.o pinentry.o plmncodes.o \
-	plmnlist.o revnibbles.o shorthand.o
+OBJS=	alpha_decode.o alpha_fromfile.o alpha_valid.o decimal_incr.o \
+	decimal_str.o filesearch.o gsm7_decode.o gsm7_encode.o \
+	gsm7_encode_table.o gsm7_pack.o gsm7_unpack.o hexdigits.o hexread.o \
+	hexstr.o iccid_luhn.o nibbles2asc.o number_decode.o number_encode.o \
+	pinentry.o plmncodes.o plmnlist.o revnibbles.o shorthand.o
 LIB=	libutil.a
 
 all:	${LIB}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libutil/decimal_incr.c	Mon Mar 15 09:07:20 2021 +0000
@@ -0,0 +1,22 @@
+/*
+ * This module implements a function for incrementing decimal strings,
+ * to be used in producing ranges of ICCID and IMSI numbers.
+ */
+
+#include <sys/types.h>
+
+void
+decimal_string_increment(str, ndigits)
+	u_char *str;
+	unsigned ndigits;
+{
+	u_char *p;
+
+	for (p = str + ndigits; p > str; ) {
+		--p;
+		(*p)++;
+		if (*p < 10)
+			return;
+		*p = 0;
+	}
+}
--- a/utils/Makefile	Mon Mar 15 08:43:08 2021 +0000
+++ b/utils/Makefile	Mon Mar 15 09:07:20 2021 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	sim-iccid-mkfull sws-email2db
+PROGS=	sim-iccid-mkfull sim-iccid-mkrange sws-email2db
 LIBUTIL=../libutil/libutil.a
 
 INSTALL_PREFIX=	/opt/freecalypso
@@ -12,6 +12,9 @@
 sim-iccid-mkfull:	sim-iccid-mkfull.o ${LIBUTIL}
 	${CC} ${CFLAGS} -o $@ $@.o ${LIBUTIL}
 
+sim-iccid-mkrange:	sim-iccid-mkrange.o ${LIBUTIL}
+	${CC} ${CFLAGS} -o $@ $@.o ${LIBUTIL}
+
 sws-email2db:	sws-email2db.c
 	${CC} ${CFLAGS} -o $@ $@.c
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/utils/sim-iccid-mkrange.c	Mon Mar 15 09:07:20 2021 +0000
@@ -0,0 +1,36 @@
+/*
+ * This program is a special utility for generating lists of ICCIDs
+ * following the 18+1 convention.  The first argument is the starting
+ * ICCID without Luhn (entered as shorthand, expanded to 18 digits),
+ * the second argument is the number of consecutive ICCIDs to generate.
+ * The output is a list of full 19-digit ICCIDs.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+main(argc, argv)
+	char **argv;
+{
+	u_char digits[19];
+	char asc[20];
+	unsigned total, n;
+	int rc;
+
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s start-iccid num-cards\n", argv[0]);
+		exit(1);
+	}
+	rc = parse_decimal_shorthand(argv[1], digits, 18);
+	if (rc < 0)
+		exit(1);	/* error msg already printed */
+	total = atoi(argv[2]);
+	for (n = 0; n < total; n++) {
+		digits[18] = compute_iccid_luhn(digits);
+		nibbles_to_ascii(digits, 19, asc);
+		puts(asc);
+		decimal_string_increment(digits, 18);
+	}
+	exit(0);
+}