FreeCalypso > hg > fc-sim-tools
annotate utils/sim-iccid-mkfull.c @ 103:3477438b5706 default tip
new fc-simtool command script: oper-sim-test
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 Aug 2022 16:34:43 +0000 |
parents | 372ecc4aa2c4 |
children |
rev | line source |
---|---|
17
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program is a special utility for constructing ICCIDs |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * following the 18+1 convention. The argument is an 18-digit ICCID |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * base, usually entered in shorthand, and the output is the full |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * 19-digit ICCID. |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
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 #include <sys/types.h> |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 main(argc, argv) |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 char **argv; |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 u_char digits[19]; |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char asc[20]; |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int rc; |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 if (argc != 2) { |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 fprintf(stderr, "usage: %s shorthand-iccid\n", argv[0]); |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 exit(1); |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 } |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 rc = parse_decimal_shorthand(argv[1], digits, 18); |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (rc < 0) |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 exit(1); /* error msg already printed */ |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 digits[18] = compute_iccid_luhn(digits); |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 nibbles_to_ascii(digits, 19, asc); |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 puts(asc); |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(0); |
372ecc4aa2c4
off-line utils ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |