annotate libutil/plmnlist.c @ 219:ac41c42ce806

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