FreeCalypso > hg > fc-pcsc-tools
annotate simtool/pnndump.c @ 58:1861d9fb7751
fc-simtool dump-lnd command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 13 Feb 2021 21:40:38 +0000 |
parents | dc8a2e6fa03e |
children | 2c07684a3980 |
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 |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 dump_record(recno) |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 unsigned recno; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 u_char *dp, *endp; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char *name_kw; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 unsigned ielen, code_byte, nsept; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 u_char gsm7_buf[288]; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 printf("#%u:", recno); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 dp = sim_resp_data; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 endp = sim_resp_data + sim_resp_data_len; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 while (dp < endp) { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (*dp == 0xFF) |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 break; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 switch (*dp++) { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 case 0x43: |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 name_kw = "Ln"; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 break; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 case 0x45: |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 name_kw = "Sn"; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 break; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 default: |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 printf(" unknown-IEI\n"); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (dp >= endp) { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 printf(" truncated-IE\n"); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 return; |
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 ielen = *dp++; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (ielen < 1 || ielen > (endp - dp)) { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 printf(" bad-length\n"); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 code_byte = *dp++; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 ielen--; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 printf(" %s=0x%02X", name_kw, code_byte); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (!ielen) |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 continue; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 putchar(','); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if ((code_byte & 0x70) == 0) { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 nsept = ielen * 8 / 7; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 gsm7_unpack(dp, gsm7_buf, nsept); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 dp += ielen; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 print_gsm7_string_to_file(gsm7_buf, nsept, stdout); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } else { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 for (; ielen; ielen--) |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 printf("%02X", *dp++); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
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 for (; dp < endp; dp++) { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (*dp != 0xFF) { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 printf(" bad-padding\n"); |
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 } |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 putchar('\n'); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
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 cmd_pnn_dump() |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 int rc; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 unsigned recno; |
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 rc = select_op(DF_GSM); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 if (rc < 0) |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 return(rc); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 rc = select_op(EF_PNN); |
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 = parse_ef_select_response(); |
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 if (curfile_structure != 0x01) { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 fprintf(stderr, "error: EF_PNN is not linear fixed\n"); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 return(-1); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (curfile_record_len < 3) { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 fprintf(stderr, |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 "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
|
93 return(-1); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 for (recno = 1; recno <= curfile_record_count; recno++) { |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 rc = readrec_op(recno, 0x04, curfile_record_len); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 if (rc < 0) |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 return(rc); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 if (check_simresp_all_blank()) |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 continue; |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 dump_record(recno); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 } |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 return(0); |
dc8a2e6fa03e
fc-simtool pnn-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 } |