FreeCalypso > hg > fc-pcsc-tools
comparison simtool/dumpdir.c @ 6:2c72709e0891
EF_DIR dump meaty function factored out into libcommon
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 11 Feb 2021 23:42:53 +0000 |
parents | ce189c97b7b1 |
children | dcfec53643c5 |
comparison
equal
deleted
inserted
replaced
5:ce189c97b7b1 | 6:2c72709e0891 |
---|---|
2 * This module implements the dump of EF_DIR. | 2 * This module implements the dump of EF_DIR. |
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | |
8 #include "simresp.h" | |
9 #include "curfile.h" | 7 #include "curfile.h" |
10 #include "file_id.h" | 8 #include "file_id.h" |
11 | |
12 static void | |
13 dump_aid(tlv) | |
14 u_char *tlv; | |
15 { | |
16 unsigned reclen, n; | |
17 | |
18 reclen = tlv[1]; | |
19 printf(" AID:"); | |
20 for (n = 0; n < reclen; n++) | |
21 printf(" %02X", tlv[n+2]); | |
22 putchar('\n'); | |
23 } | |
24 | |
25 static void | |
26 dump_label(tlv) | |
27 u_char *tlv; | |
28 { | |
29 int rc; | |
30 unsigned textlen; | |
31 | |
32 printf(" Label: "); | |
33 rc = validate_alpha_field(tlv + 2, tlv[1], &textlen); | |
34 if (rc < 0) { | |
35 printf("malformed\n"); | |
36 return; | |
37 } | |
38 print_alpha_field(tlv + 2, textlen, stdout); | |
39 putchar('\n'); | |
40 } | |
41 | |
42 static void | |
43 dump_unknown_tlv(tlv) | |
44 u_char *tlv; | |
45 { | |
46 unsigned reclen, n; | |
47 | |
48 reclen = tlv[1] + 2; | |
49 printf(" TLV:"); | |
50 for (n = 0; n < reclen; n++) | |
51 printf(" %02X", tlv[n]); | |
52 putchar('\n'); | |
53 } | |
54 | |
55 static void | |
56 dump_record(recno) | |
57 unsigned recno; | |
58 { | |
59 unsigned totlen, reclen; | |
60 u_char *dp, *endp; | |
61 | |
62 printf("Record #%u:\n", recno); | |
63 if (sim_resp_data[0] != 0x61) { | |
64 printf(" bad: first byte != 0x61\n"); | |
65 return; | |
66 } | |
67 totlen = sim_resp_data[1]; | |
68 if (totlen < 3 || totlen > 0x7F) { | |
69 printf(" bad: global length byte 0x%02X is invalid\n", totlen); | |
70 return; | |
71 } | |
72 if (totlen + 2 > sim_resp_data_len) { | |
73 printf(" bad: TLV global length exceeds EF record length\n"); | |
74 return; | |
75 } | |
76 dp = sim_resp_data + 2; | |
77 endp = sim_resp_data + 2 + totlen; | |
78 while (dp < endp) { | |
79 if (endp - dp < 2) { | |
80 trunc_error: printf(" bad: truncated TLV record\n"); | |
81 return; | |
82 } | |
83 if ((dp[0] & 0x1F) == 0x1F) { | |
84 printf(" bad: extended tag not supported\n"); | |
85 return; | |
86 } | |
87 if (dp[1] & 0x80) { | |
88 printf(" bad: extended length not supported\n"); | |
89 return; | |
90 } | |
91 reclen = dp[1] + 2; | |
92 if (endp - dp < reclen) | |
93 goto trunc_error; | |
94 switch (dp[0]) { | |
95 case 0x4F: | |
96 dump_aid(dp); | |
97 break; | |
98 case 0x50: | |
99 dump_label(dp); | |
100 break; | |
101 default: | |
102 dump_unknown_tlv(dp); | |
103 } | |
104 dp += reclen; | |
105 } | |
106 } | |
107 | 9 |
108 cmd_uicc_dir() | 10 cmd_uicc_dir() |
109 { | 11 { |
110 int rc; | 12 int rc; |
111 unsigned recno; | 13 unsigned recno; |
131 rc = readrec_op(recno, 0x04, curfile_record_len); | 33 rc = readrec_op(recno, 0x04, curfile_record_len); |
132 if (rc < 0) | 34 if (rc < 0) |
133 return(rc); | 35 return(rc); |
134 if (check_simresp_all_blank()) | 36 if (check_simresp_all_blank()) |
135 continue; | 37 continue; |
136 dump_record(recno); | 38 printf("Record #%u:\n", recno); |
39 dump_efdir_record(); | |
137 } | 40 } |
138 return(0); | 41 return(0); |
139 } | 42 } |