annotate libutil/plmnlist.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 34bbb0585cab
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements a function for reading PLMN lists from files.
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <ctype.h>
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern FILE *open_script_input_file();
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 read_plmn_list_from_file(filename, buf, ef_len)
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char *filename;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 u_char *buf;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 unsigned ef_len;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 FILE *inf;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int lineno, rc;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char linebuf[1024], *cp, *np;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 u_char *dp, *endp;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 inf = open_script_input_file(filename);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (!inf) {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 perror(filename);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(-1);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 dp = buf;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 endp = buf + ef_len;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (!index(linebuf, '\n')) {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 fprintf(stderr,
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 "%s line %d: too long or missing newline\n",
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 filename, lineno);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 fclose(inf);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 return(-1);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 for (cp = linebuf; ; ) {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 while (isspace(*cp))
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 cp++;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (*cp == '\0' || *cp == '#')
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 break;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 for (np = cp; *cp && !isspace(*cp); cp++)
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 ;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (*cp)
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 *cp++ = '\0';
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (dp >= endp) {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(stderr,
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 "%s line %d: number of PLMN codes exceeds EF size\n",
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 filename, lineno);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 fclose(inf);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return(-1);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 rc = encode_plmn_3bytes(np, dp);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (rc < 0) {
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 fprintf(stderr, "%s line %d: invalid MCC-MNC\n",
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 filename, lineno);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 fclose(inf);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(-1);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 dp += 3;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 fclose(inf);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 while (dp < endp)
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 *dp++ = 0xFF;
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 return(0);
34bbb0585cab libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }