annotate simtool/pnndump.c @ 158:3698c8192d2d

libutil: hex digit functions factored out
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 26 Feb 2021 20:41:31 +0000
parents 2c07684a3980
children 8b1eecb56cb5
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
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static void
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
13 dump_record(recno, outf)
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 unsigned recno;
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
15 FILE *outf;
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 u_char *dp, *endp;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *name_kw;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 unsigned ielen, code_byte, nsept;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 u_char gsm7_buf[288];
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
22 fprintf(outf, "#%u:", recno);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 dp = sim_resp_data;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 endp = sim_resp_data + sim_resp_data_len;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 while (dp < endp) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (*dp == 0xFF)
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 break;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 switch (*dp++) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 case 0x43:
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 name_kw = "Ln";
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 break;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 case 0x45:
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 name_kw = "Sn";
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 break;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 default:
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
36 fprintf(outf, " unknown-IEI\n");
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 return;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (dp >= endp) {
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
40 fprintf(outf, " truncated-IE\n");
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 ielen = *dp++;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (ielen < 1 || ielen > (endp - dp)) {
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
45 fprintf(outf, " bad-length\n");
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 code_byte = *dp++;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 ielen--;
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
50 fprintf(outf, " %s=0x%02X", name_kw, code_byte);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (!ielen)
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 continue;
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
53 putc(',', outf);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if ((code_byte & 0x70) == 0) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 nsept = ielen * 8 / 7;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 gsm7_unpack(dp, gsm7_buf, nsept);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 dp += ielen;
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
58 print_gsm7_string_to_file(gsm7_buf, nsept, outf);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 } else {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 for (; ielen; ielen--)
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
61 fprintf(outf, "%02X", *dp++);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
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 for (; dp < endp; dp++) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (*dp != 0xFF) {
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
66 fprintf(outf, " bad-padding\n");
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 return;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
70 putc('\n', outf);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
73 cmd_pnn_dump(argc, argv, outf)
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
74 char **argv;
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
75 FILE *outf;
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 int rc;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 unsigned recno;
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 rc = select_op(DF_GSM);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (rc < 0)
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 return(rc);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 rc = select_op(EF_PNN);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if (rc < 0)
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 return(rc);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 rc = parse_ef_select_response();
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (rc < 0)
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 return(rc);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (curfile_structure != 0x01) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 fprintf(stderr, "error: EF_PNN is not linear fixed\n");
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 return(-1);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 if (curfile_record_len < 3) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 fprintf(stderr,
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 "error: EF_PNN record length is less than the spec minimum of 3 bytes\n");
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 return(-1);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 for (recno = 1; recno <= curfile_record_count; recno++) {
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 rc = readrec_op(recno, 0x04, curfile_record_len);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (rc < 0)
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 return(rc);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (check_simresp_all_blank())
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 continue;
114
2c07684a3980 fc-simtool pnn-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
104 dump_record(recno, outf);
50
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 return(0);
dc8a2e6fa03e fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 }