comparison uicc/select.c @ 144:429a8f80426e

fc-uicc-tool: catch record length from manual select
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 Feb 2021 02:03:11 +0000
parents 6c6e8705dc70
children 65a2a96386cd
comparison
equal deleted inserted replaced
143:431194b772e1 144:429a8f80426e
16 { 16 {
17 u_char cmd[7]; 17 u_char cmd[7];
18 int rc; 18 int rc;
19 unsigned expect_resp_len; 19 unsigned expect_resp_len;
20 20
21 last_sel_file_record_len = 0;
21 /* SELECT command APDU */ 22 /* SELECT command APDU */
22 cmd[0] = 0x00; 23 cmd[0] = 0x00;
23 cmd[1] = 0xA4; 24 cmd[1] = 0xA4;
24 cmd[2] = 0x00; 25 cmd[2] = 0x00;
25 cmd[3] = 0x04; 26 cmd[3] = 0x04;
65 { 66 {
66 u_char cmd[21]; 67 u_char cmd[21];
67 int rc; 68 int rc;
68 unsigned expect_resp_len; 69 unsigned expect_resp_len;
69 70
71 last_sel_file_record_len = 0;
70 /* SELECT command APDU */ 72 /* SELECT command APDU */
71 cmd[0] = 0x00; 73 cmd[0] = 0x00;
72 cmd[1] = 0xA4; 74 cmd[1] = 0xA4;
73 cmd[2] = 0x04; 75 cmd[2] = 0x04;
74 cmd[3] = 0x04; 76 cmd[3] = 0x04;
140 len = sim_resp_data[2]; 142 len = sim_resp_data[2];
141 offset = 3; 143 offset = 3;
142 goto return_check; 144 goto return_check;
143 } 145 }
144 146
147 static void
148 check_for_record_struct(tlv)
149 u_char *tlv;
150 {
151 unsigned reclen;
152
153 if (tlv[1] != 5)
154 return;
155 if (tlv[2] & 0x80)
156 return;
157 if ((tlv[2] & 0x38) == 0x38)
158 return;
159 if ((tlv[2] & 0x03) != 0x02)
160 return;
161 reclen = (tlv[4] << 8) | tlv[5];
162 if (reclen < 1 || reclen > 255)
163 return;
164 last_sel_file_record_len = reclen;
165 }
166
145 parse_and_display_select_response() 167 parse_and_display_select_response()
146 { 168 {
147 unsigned offset, totlen, reclen, n; 169 unsigned offset, totlen, reclen, n;
148 u_char *dp, *endp; 170 u_char *dp, *endp;
149 int rc; 171 int rc;
170 return(-1); 192 return(-1);
171 } 193 }
172 reclen = dp[1] + 2; 194 reclen = dp[1] + 2;
173 if (endp - dp < reclen) 195 if (endp - dp < reclen)
174 goto trunc_error; 196 goto trunc_error;
197 if (dp[0] == 0x82)
198 check_for_record_struct(dp);
175 for (n = 0; n < reclen; n++) { 199 for (n = 0; n < reclen; n++) {
176 if (n) 200 if (n)
177 putchar(' '); 201 putchar(' ');
178 printf("%02X", *dp++); 202 printf("%02X", *dp++);
179 } 203 }