annotate utils/sim-iccid-mkrange.c @ 83:3055d5c9e7a3

fc-simtool update-rec* commands: check curfile_record_len and error out if it is not set
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 11 Apr 2021 02:38:31 +0000
parents 9c9f6adbaedb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
25
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
2 * This program is a special utility for generating lists of ICCIDs
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
3 * following the 18+1 convention. The first argument is the starting
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
4 * ICCID without Luhn (entered as shorthand, expanded to 18 digits),
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
5 * the second argument is the number of consecutive ICCIDs to generate.
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
6 * The output is a list of full 19-digit ICCIDs.
17
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 */
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <sys/types.h>
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 main(argc, argv)
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char **argv;
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 u_char digits[19];
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 char asc[20];
25
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
18 unsigned total, n;
17
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int rc;
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
25
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
21 if (argc != 3) {
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
22 fprintf(stderr, "usage: %s start-iccid num-cards\n", argv[0]);
17
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 exit(1);
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 rc = parse_decimal_shorthand(argv[1], digits, 18);
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (rc < 0)
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 exit(1); /* error msg already printed */
25
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
28 total = atoi(argv[2]);
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
29 for (n = 0; n < total; n++) {
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
30 digits[18] = compute_iccid_luhn(digits);
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
31 nibbles_to_ascii(digits, 19, asc);
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
32 puts(asc);
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
33 decimal_string_increment(digits, 18);
9c9f6adbaedb sim-iccid-mkrange utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 17
diff changeset
34 }
17
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 exit(0);
372ecc4aa2c4 off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }