FreeCalypso > hg > fc-pcsc-tools
annotate offline/sim-iccid-mkfull.c @ 201:fc1635333d81
allow comments in hex data files
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Mar 2021 03:58:49 +0000 |
parents | 4cd2023f56a6 |
children |
rev | line source |
---|---|
163
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program is a special utility for constructing ICCIDs |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * following the 18+1 convention. The argument is an 18-digit ICCID |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * base, usually entered in shorthand, and the output is the full |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * 19-digit ICCID. |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/types.h> |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 main(argc, argv) |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 char **argv; |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 u_char digits[19]; |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char asc[20]; |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int rc; |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 if (argc != 2) { |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 fprintf(stderr, "usage: %s shorthand-iccid\n", argv[0]); |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 exit(1); |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 } |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 rc = parse_decimal_shorthand(argv[1], digits, 18); |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (rc < 0) |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 exit(1); /* error msg already printed */ |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 digits[18] = compute_iccid_luhn(digits); |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 nibbles_to_ascii(digits, 19, asc); |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 puts(asc); |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(0); |
4cd2023f56a6
sim-iccid-mkfull utility created, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |