changeset 163:4cd2023f56a6

sim-iccid-mkfull utility created, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 26 Feb 2021 21:32:41 +0000
parents 274bfd8bccd0
children e6263e1b16f8
files .hgignore Makefile offline/Makefile offline/sim-iccid-mkfull.c
diffstat 4 files changed, 51 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Feb 26 21:16:45 2021 +0000
+++ b/.hgignore	Fri Feb 26 21:32:41 2021 +0000
@@ -5,6 +5,8 @@
 ^misc/fc-pcsc-atr$
 ^misc/fc-pcsc-list$
 
+^offline/sim-iccid-mkfull$
+
 ^simtool/fc-simtool$
 
 ^uicc/fc-uicc-tool$
--- a/Makefile	Fri Feb 26 21:16:45 2021 +0000
+++ b/Makefile	Fri Feb 26 21:32:41 2021 +0000
@@ -1,10 +1,11 @@
-PROGDIR=misc simtool uicc
+PROGDIR=misc offline simtool uicc
 LIBDIR=	libcommon libutil
 SUBDIR=	${PROGDIR} ${LIBDIR}
 
 all:	${SUBDIR}
 
 misc:		libcommon libutil
+offline:	libutil
 simtool:	libcommon libutil
 uicc:		libcommon libutil
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/offline/Makefile	Fri Feb 26 21:32:41 2021 +0000
@@ -0,0 +1,17 @@
+CC=	gcc
+CFLAGS=	-O2
+PROGS=	sim-iccid-mkfull
+LIBS=	../libutil/libutil.a
+INSTBIN=/opt/freecalypso/bin
+
+all:	${PROGS}
+
+sim-iccid-mkfull:	sim-iccid-mkfull.o ${LIBS}
+	${CC} ${CFLAGS} -o $@ $@.o ${LIBS}
+
+install:
+	mkdir -p ${INSTBIN}
+	install -c ${PROGS} ${INSTBIN}
+
+clean:
+	rm -f ${PROGS} *.o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/offline/sim-iccid-mkfull.c	Fri Feb 26 21:32:41 2021 +0000
@@ -0,0 +1,30 @@
+/*
+ * This program is a special utility for constructing ICCIDs
+ * following the 18+1 convention.  The argument is an 18-digit ICCID
+ * base, usually entered in shorthand, and the output is the full
+ * 19-digit ICCID.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+main(argc, argv)
+	char **argv;
+{
+	u_char digits[19];
+	char asc[20];
+	int rc;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s shorthand-iccid\n", argv[0]);
+		exit(1);
+	}
+	rc = parse_decimal_shorthand(argv[1], digits, 18);
+	if (rc < 0)
+		exit(1);	/* error msg already printed */
+	digits[18] = compute_iccid_luhn(digits);
+	nibbles_to_ascii(digits, 19, asc);
+	puts(asc);
+	exit(0);
+}