annotate simtool/pnndump.c @ 228:a93de68711b8

original README is now README.old
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 18:16:27 +0000
parents 8b1eecb56cb5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the pnn-dump command, providing a
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * user-accessible way to identify MVNO SIMs.
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "simresp.h"
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "curfile.h"
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "file_id.h"
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
214
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
12 select_ef_pnn()
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
13 {
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
14 int rc;
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
15
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
16 rc = select_op(DF_GSM);
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
17 if (rc < 0)
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
18 return(rc);
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
19 rc = select_op(EF_PNN);
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
20 if (rc < 0)
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
21 return(rc);
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
22 rc = parse_ef_select_response();
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
23 if (rc < 0)
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
24 return(rc);
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
25 if (curfile_structure != 0x01) {
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
26 fprintf(stderr, "error: EF_PNN is not linear fixed\n");
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
27 return(-1);
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
28 }
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
29 if (curfile_record_len < 3) {
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
30 fprintf(stderr,
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
31 "error: EF_PNN record length is less than the spec minimum of 3 bytes\n");
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
32 return(-1);
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
33 }
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
34 return(0);
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
35 }
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
36
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 static void
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
38 dump_record(recno, outf)
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 unsigned recno;
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
40 FILE *outf;
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 u_char *dp, *endp;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 char *name_kw;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 unsigned ielen, code_byte, nsept;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 u_char gsm7_buf[288];
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
47 fprintf(outf, "#%u:", recno);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 dp = sim_resp_data;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 endp = sim_resp_data + sim_resp_data_len;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 while (dp < endp) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (*dp == 0xFF)
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 break;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 switch (*dp++) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 case 0x43:
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 name_kw = "Ln";
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 break;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 case 0x45:
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 name_kw = "Sn";
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 break;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 default:
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
61 fprintf(outf, " unknown-IEI\n");
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (dp >= endp) {
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
65 fprintf(outf, " truncated-IE\n");
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 return;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 ielen = *dp++;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (ielen < 1 || ielen > (endp - dp)) {
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
70 fprintf(outf, " bad-length\n");
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 return;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 code_byte = *dp++;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 ielen--;
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
75 fprintf(outf, " %s=0x%02X", name_kw, code_byte);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (!ielen)
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 continue;
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
78 putc(',', outf);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 if ((code_byte & 0x70) == 0) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 nsept = ielen * 8 / 7;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 gsm7_unpack(dp, gsm7_buf, nsept);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 dp += ielen;
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
83 print_gsm7_string_to_file(gsm7_buf, nsept, outf);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 } else {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 for (; ielen; ielen--)
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
86 fprintf(outf, "%02X", *dp++);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 for (; dp < endp; dp++) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (*dp != 0xFF) {
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
91 fprintf(outf, " bad-padding\n");
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 return;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 }
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
95 putc('\n', outf);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
98 cmd_pnn_dump(argc, argv, outf)
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
99 char **argv;
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
100 FILE *outf;
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 int rc;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 unsigned recno;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104
214
8b1eecb56cb5 simtool code: select_ef_pnn() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
105 rc = select_ef_pnn();
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if (rc < 0)
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 return(rc);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 for (recno = 1; recno <= curfile_record_count; recno++) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 rc = readrec_op(recno, 0x04, curfile_record_len);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 if (rc < 0)
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 return(rc);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 if (check_simresp_all_blank())
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 continue;
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
114 dump_record(recno, outf);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 return(0);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 }