FreeCalypso > hg > fc-sim-tools
annotate utils/fcsim1-mkprov.c @ 82:28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 10 Apr 2021 23:21:47 +0000 |
parents | 38c14fa89937 |
children | 6041c601304d |
rev | line source |
---|---|
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This utility is the provisioning data generator for FCSIM1 cards. |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/file.h> |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <unistd.h> |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 static u_char iccid_bin[19], imsi_bin[15], msisdn_bin[20]; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 static int msisdn_set, msisdn_plus; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 static unsigned num_cards = 1, access_class, msisdn_digits; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 static char *random_file = "/dev/urandom"; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static int random_fd; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 static void |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 set_iccid(arg) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char *arg; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 int rc; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 rc = parse_decimal_shorthand(arg, iccid_bin, 18); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (rc < 0) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 exit(1); /* error msg already printed */ |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 static void |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 set_imsi(arg) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 char *arg; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 int rc; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 rc = parse_decimal_shorthand(arg, imsi_bin, 15); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (rc < 0) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 exit(1); /* error msg already printed */ |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 static void |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 set_msisdn(arg) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 char *arg; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 int rc; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (*arg == '+') { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 msisdn_plus = 1; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 arg++; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 rc = parse_decimal_string_arg(arg, msisdn_bin, 20); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (rc < 0) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 exit(1); /* error msg already printed */ |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 msisdn_digits = rc; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 msisdn_set = 1; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 static void |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 parse_cmdline(argc, argv) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 char **argv; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 extern int optind; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 extern char *optarg; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 int c; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 while ((c = getopt(argc, argv, "a:m:n:r:")) != EOF) { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 switch (c) { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 case 'a': |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (optarg[0] < '0' || optarg[0] > '9' || optarg[1]) { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 fprintf(stderr, "error: invalid -a argument\n"); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 exit(1); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 access_class = optarg[0] - '0'; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 continue; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 case 'm': |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 set_msisdn(optarg); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 continue; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 case 'n': |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 num_cards = atoi(optarg); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 continue; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 case 'r': |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 random_file = optarg; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 continue; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 case '?': |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 default: |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 usage: fprintf(stderr, |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 "usage: %s [options] start-iccid start-imsi\n", |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 argv[0]); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 exit(1); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (argc - optind != 2) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 goto usage; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 set_iccid(argv[optind]); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 set_imsi(argv[optind+1]); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 |
82
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
96 static unsigned |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
97 make_odd_parity(byte) |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
98 unsigned byte; |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
99 { |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
100 unsigned mask, p; |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
101 |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
102 p = 0; |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
103 for (mask = 0x80; mask; mask >>= 1) |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
104 if (byte & mask) |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
105 p = !p; |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
106 if (!p) |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
107 byte ^= 0x01; |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
108 return byte; |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
109 } |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
110 |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 static void |
82
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
112 get_random_key(strbuf, oddpar) |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 char *strbuf; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 { |
36
38c14fa89937
fcsim1-mkprov: fix wrong length for Ki
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
115 u_char bin[16]; |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 char *dp; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 unsigned n; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 int rc; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 |
36
38c14fa89937
fcsim1-mkprov: fix wrong length for Ki
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
120 rc = read(random_fd, bin, 16); |
38c14fa89937
fcsim1-mkprov: fix wrong length for Ki
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
121 if (rc != 16) { |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 fprintf(stderr, "error reading from %s\n", random_file); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 exit(1); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } |
82
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
125 if (oddpar) { |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
126 for (n = 0; n < 16; n++) |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
127 bin[n] = make_odd_parity(bin[n]); |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
128 } |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 dp = strbuf; |
36
38c14fa89937
fcsim1-mkprov: fix wrong length for Ki
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
130 for (n = 0; n < 16; n++) { |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 sprintf(dp, "%02X", bin[n]); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 dp += 2; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 *dp = '\0'; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 static void |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 make_one_card() |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 unsigned acc_mask; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 char iccid_str[20], imsi_str[16], ki_str[33]; |
82
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
142 char msisdn_str[21], otac_str[33], otad_str[33]; |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 nibbles_to_ascii(iccid_bin, 19, iccid_str); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 nibbles_to_ascii(imsi_bin, 15, imsi_str); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 acc_mask = 1 << access_class; |
82
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
147 get_random_key(ki_str, 0); |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
148 get_random_key(otac_str, 1); |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
149 get_random_key(otad_str, 1); |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
150 printf("ICCID=%s IMSI=%s ACC=%04X Ki=%s OTA_C=%s OTA_D=%s", iccid_str, |
28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
151 imsi_str, acc_mask, ki_str, otac_str, otad_str); |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 if (msisdn_set) { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 fputs(" MSISDN=", stdout); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 if (msisdn_plus) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 putchar('+'); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 nibbles_to_ascii(msisdn_bin, msisdn_digits, msisdn_str); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 fputs(msisdn_str, stdout); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 putchar('\n'); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 main(argc, argv) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 char **argv; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 unsigned n; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 parse_cmdline(argc, argv); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 random_fd = open(random_file, O_RDONLY); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 if (random_fd < 0) { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 perror(random_file); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 exit(1); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 for (n = 0; n < num_cards; n++) { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 iccid_bin[18] = compute_iccid_luhn(iccid_bin); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 make_one_card(); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 decimal_string_increment(iccid_bin, 18); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 decimal_string_increment(imsi_bin, 15); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 if (msisdn_set) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 decimal_string_increment(msisdn_bin, msisdn_digits); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 access_class++; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 if (access_class >= 10) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 access_class = 0; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 exit(0); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 } |