diff utils/sim-iccid-mkrange.c @ 25:9c9f6adbaedb

sim-iccid-mkrange utility added
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 15 Mar 2021 09:07:20 +0000
parents utils/sim-iccid-mkfull.c@372ecc4aa2c4
children
line wrap: on
line diff
--- /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);
+}