FreeCalypso > hg > fc-sim-tools
annotate utils/fcsim1-mkprov.c @ 93:6041c601304d
fcsim1-mkprov: revert OTA key addition
It appears that GrcardSIM2 cards (which is what we got for FCSIM1)
do not support OTA after all, contrary to what we were previously
led to believe by some tech support emails from Grcard - apparently
those support emails and OTA descriptions referred to some other
card model(s).
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 21 Apr 2021 05:38:39 +0000 |
parents | 28fae57b3e29 |
children |
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 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 static void |
93
6041c601304d
fcsim1-mkprov: revert OTA key addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
97 get_random_ki(strbuf) |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 char *strbuf; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 { |
36
38c14fa89937
fcsim1-mkprov: fix wrong length for Ki
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
100 u_char bin[16]; |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 char *dp; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 unsigned n; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 int rc; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 |
36
38c14fa89937
fcsim1-mkprov: fix wrong length for Ki
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
105 rc = read(random_fd, bin, 16); |
38c14fa89937
fcsim1-mkprov: fix wrong length for Ki
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
106 if (rc != 16) { |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 fprintf(stderr, "error reading from %s\n", random_file); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 exit(1); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 dp = strbuf; |
36
38c14fa89937
fcsim1-mkprov: fix wrong length for Ki
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
111 for (n = 0; n < 16; n++) { |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 sprintf(dp, "%02X", bin[n]); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 dp += 2; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 *dp = '\0'; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 static void |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 make_one_card() |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 unsigned acc_mask; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 char iccid_str[20], imsi_str[16], ki_str[33]; |
93
6041c601304d
fcsim1-mkprov: revert OTA key addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
123 char msisdn_str[21]; |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 nibbles_to_ascii(iccid_bin, 19, iccid_str); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 nibbles_to_ascii(imsi_bin, 15, imsi_str); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 acc_mask = 1 << access_class; |
93
6041c601304d
fcsim1-mkprov: revert OTA key addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
128 get_random_ki(ki_str); |
6041c601304d
fcsim1-mkprov: revert OTA key addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
129 printf("ICCID=%s IMSI=%s ACC=%04X Ki=%s", iccid_str, imsi_str, |
6041c601304d
fcsim1-mkprov: revert OTA key addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
130 acc_mask, ki_str); |
35
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 if (msisdn_set) { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 fputs(" MSISDN=", stdout); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 if (msisdn_plus) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 putchar('+'); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 nibbles_to_ascii(msisdn_bin, msisdn_digits, msisdn_str); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 fputs(msisdn_str, stdout); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 putchar('\n'); |
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 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 main(argc, argv) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 char **argv; |
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 unsigned n; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 parse_cmdline(argc, argv); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 random_fd = open(random_file, O_RDONLY); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 if (random_fd < 0) { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 perror(random_file); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 exit(1); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 for (n = 0; n < num_cards; n++) { |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 iccid_bin[18] = compute_iccid_luhn(iccid_bin); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 make_one_card(); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 decimal_string_increment(iccid_bin, 18); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 decimal_string_increment(imsi_bin, 15); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 if (msisdn_set) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 decimal_string_increment(msisdn_bin, msisdn_digits); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 access_class++; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 if (access_class >= 10) |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 access_class = 0; |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 } |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 exit(0); |
26d2ef843a99
fcsim1-mkprov utility implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 } |