FreeCalypso > hg > fc-pcsc-tools
comparison simtool/pnndump.c @ 50:dc8a2e6fa03e
fc-simtool pnn-dump implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 13 Feb 2021 04:31:02 +0000 |
parents | |
children | 2c07684a3980 |
comparison
equal
deleted
inserted
replaced
49:bbc2821288aa | 50:dc8a2e6fa03e |
---|---|
1 /* | |
2 * This module implements the pnn-dump command, providing a | |
3 * user-accessible way to identify MVNO SIMs. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <stdio.h> | |
8 #include "simresp.h" | |
9 #include "curfile.h" | |
10 #include "file_id.h" | |
11 | |
12 static void | |
13 dump_record(recno) | |
14 unsigned recno; | |
15 { | |
16 u_char *dp, *endp; | |
17 char *name_kw; | |
18 unsigned ielen, code_byte, nsept; | |
19 u_char gsm7_buf[288]; | |
20 | |
21 printf("#%u:", recno); | |
22 dp = sim_resp_data; | |
23 endp = sim_resp_data + sim_resp_data_len; | |
24 while (dp < endp) { | |
25 if (*dp == 0xFF) | |
26 break; | |
27 switch (*dp++) { | |
28 case 0x43: | |
29 name_kw = "Ln"; | |
30 break; | |
31 case 0x45: | |
32 name_kw = "Sn"; | |
33 break; | |
34 default: | |
35 printf(" unknown-IEI\n"); | |
36 return; | |
37 } | |
38 if (dp >= endp) { | |
39 printf(" truncated-IE\n"); | |
40 return; | |
41 } | |
42 ielen = *dp++; | |
43 if (ielen < 1 || ielen > (endp - dp)) { | |
44 printf(" bad-length\n"); | |
45 return; | |
46 } | |
47 code_byte = *dp++; | |
48 ielen--; | |
49 printf(" %s=0x%02X", name_kw, code_byte); | |
50 if (!ielen) | |
51 continue; | |
52 putchar(','); | |
53 if ((code_byte & 0x70) == 0) { | |
54 nsept = ielen * 8 / 7; | |
55 gsm7_unpack(dp, gsm7_buf, nsept); | |
56 dp += ielen; | |
57 print_gsm7_string_to_file(gsm7_buf, nsept, stdout); | |
58 } else { | |
59 for (; ielen; ielen--) | |
60 printf("%02X", *dp++); | |
61 } | |
62 } | |
63 for (; dp < endp; dp++) { | |
64 if (*dp != 0xFF) { | |
65 printf(" bad-padding\n"); | |
66 return; | |
67 } | |
68 } | |
69 putchar('\n'); | |
70 } | |
71 | |
72 cmd_pnn_dump() | |
73 { | |
74 int rc; | |
75 unsigned recno; | |
76 | |
77 rc = select_op(DF_GSM); | |
78 if (rc < 0) | |
79 return(rc); | |
80 rc = select_op(EF_PNN); | |
81 if (rc < 0) | |
82 return(rc); | |
83 rc = parse_ef_select_response(); | |
84 if (rc < 0) | |
85 return(rc); | |
86 if (curfile_structure != 0x01) { | |
87 fprintf(stderr, "error: EF_PNN is not linear fixed\n"); | |
88 return(-1); | |
89 } | |
90 if (curfile_record_len < 3) { | |
91 fprintf(stderr, | |
92 "error: EF_PNN record length is less than the spec minimum of 3 bytes\n"); | |
93 return(-1); | |
94 } | |
95 for (recno = 1; recno <= curfile_record_count; recno++) { | |
96 rc = readrec_op(recno, 0x04, curfile_record_len); | |
97 if (rc < 0) | |
98 return(rc); | |
99 if (check_simresp_all_blank()) | |
100 continue; | |
101 dump_record(recno); | |
102 } | |
103 return(0); | |
104 } |