annotate simtool/sstprog.c @ 85:c179deb9bb39

uicc/writecmd.c: forgot to update #include header set
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 11 Apr 2021 02:48:22 +0000
parents ddd767f6e15b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the write-sst command for admin-level
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * programming of SIM cards.
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <ctype.h>
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "curfile.h"
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "file_id.h"
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern FILE *open_script_input_file();
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 cmd_write_sst(argc, argv)
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char **argv;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 u_char sst[255];
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 FILE *inf;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int lineno, rc;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 char linebuf[1024], *cp, *np;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 unsigned num, code, max_serv;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 rc = select_op(DF_GSM);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (rc < 0)
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return(rc);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 rc = select_op(EF_SST);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (rc < 0)
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return(rc);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 rc = parse_ef_select_response();
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (rc < 0)
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 return(rc);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (curfile_structure != 0x00) {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 fprintf(stderr, "error: EF_SST is not transparent\n");
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 return(-1);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (curfile_total_size < 2) {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 fprintf(stderr,
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 "error: EF_SST is shorter than spec minimum of 2 bytes\n");
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 return(-1);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (curfile_total_size > 255) {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fprintf(stderr,
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 "error: EF_SST is longer than our 255 byte limit\n");
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return(-1);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 memset(sst, 0, curfile_total_size);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 max_serv = curfile_total_size * 4;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 inf = open_script_input_file(argv[1]);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (!inf) {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 perror(argv[1]);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return(-1);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (!index(linebuf, '\n')) {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 fprintf(stderr,
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 "%s line %d: too long or missing newline\n",
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 argv[1], lineno);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 fclose(inf);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return(-1);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 for (cp = linebuf; ; ) {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 while (isspace(*cp))
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 cp++;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (*cp == '\0' || *cp == '#')
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 break;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (!isdigit(*cp)) {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 inv_syntax: fprintf(stderr, "%s line %d: invalid syntax\n",
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 argv[1], lineno);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 fclose(inf);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return(-1);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 num = strtoul(cp, 0, 10);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 while (isdigit(*cp))
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 cp++;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (*cp == '^') {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 cp++;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 code = 1;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 } else
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 code = 3;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (*cp && !isspace(*cp))
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 goto inv_syntax;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 if (num < 1 || num > max_serv) {
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 fprintf(stderr,
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 "%s line %d: service number is out of range\n",
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 argv[1], lineno);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 fclose(inf);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 return(-1);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 num--;
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 sst[num >> 2] |= code << ((num & 3) << 1);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 }
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 fclose(inf);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 return update_bin_op(0, sst, curfile_total_size);
ddd767f6e15b fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }