comparison uicc/select.c @ 138:58406ead2497

fc-uicc-tool: support output redirection for select commands
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 23 Feb 2021 02:34:46 +0000
parents 1b1468869ccf
children 77832c9f2001
comparison
equal deleted inserted replaced
137:277c66de296f 138:58406ead2497
162 if (reclen < 1 || reclen > 255) 162 if (reclen < 1 || reclen > 255)
163 return; 163 return;
164 last_sel_file_record_len = reclen; 164 last_sel_file_record_len = reclen;
165 } 165 }
166 166
167 parse_and_display_select_response() 167 parse_and_display_select_response(outf)
168 FILE *outf;
168 { 169 {
169 unsigned offset, totlen, reclen, n; 170 unsigned offset, totlen, reclen, n;
170 u_char *dp, *endp; 171 u_char *dp, *endp;
171 int rc; 172 int rc;
172 173
196 goto trunc_error; 197 goto trunc_error;
197 if (dp[0] == 0x82) 198 if (dp[0] == 0x82)
198 check_for_record_struct(dp); 199 check_for_record_struct(dp);
199 for (n = 0; n < reclen; n++) { 200 for (n = 0; n < reclen; n++) {
200 if (n) 201 if (n)
201 putchar(' '); 202 putc(' ', outf);
202 printf("%02X", *dp++); 203 fprintf(outf, "%02X", *dp++);
203 } 204 }
204 putchar('\n'); 205 putc('\n', outf);
205 } 206 }
206 return(0); 207 return(0);
207 } 208 }
208 209
209 cmd_select(argc, argv) 210 cmd_select(argc, argv, outf)
210 char **argv; 211 char **argv;
212 FILE *outf;
211 { 213 {
212 int file_id, rc; 214 int file_id, rc;
213 215
214 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) && 216 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
215 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4]) 217 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
222 return(-1); 224 return(-1);
223 } 225 }
224 rc = select_op(file_id); 226 rc = select_op(file_id);
225 if (rc < 0) 227 if (rc < 0)
226 return(rc); 228 return(rc);
227 return parse_and_display_select_response(); 229 return parse_and_display_select_response(outf);
228 } 230 }
229 231
230 cmd_select_aid(argc, argv) 232 cmd_select_aid(argc, argv, outf)
231 char **argv; 233 char **argv;
234 FILE *outf;
232 { 235 {
233 u_char aid[16]; 236 u_char aid[16];
234 unsigned aid_len; 237 unsigned aid_len;
235 int rc; 238 int rc;
236 239
239 return(rc); 242 return(rc);
240 aid_len = rc; 243 aid_len = rc;
241 rc = select_aid_op(aid, aid_len); 244 rc = select_aid_op(aid, aid_len);
242 if (rc < 0) 245 if (rc < 0)
243 return(rc); 246 return(rc);
244 return parse_and_display_select_response(); 247 return parse_and_display_select_response(outf);
245 } 248 }
246 249
247 cmd_select_usim() 250 cmd_select_usim(argc, argv, outf)
251 char **argv;
252 FILE *outf;
248 { 253 {
249 int rc; 254 int rc;
250 255
251 rc = select_aid_op(std_aid_usim, 7); 256 rc = select_aid_op(std_aid_usim, 7);
252 if (rc < 0) 257 if (rc < 0)
253 return(rc); 258 return(rc);
254 return parse_and_display_select_response(); 259 return parse_and_display_select_response(outf);
255 } 260 }
256 261
257 cmd_select_isim() 262 cmd_select_isim(argc, argv, outf)
263 char **argv;
264 FILE *outf;
258 { 265 {
259 int rc; 266 int rc;
260 267
261 rc = select_aid_op(std_aid_isim, 7); 268 rc = select_aid_op(std_aid_isim, 7);
262 if (rc < 0) 269 if (rc < 0)
263 return(rc); 270 return(rc);
264 return parse_and_display_select_response(); 271 return parse_and_display_select_response(outf);
265 } 272 }
266 273
267 u_char * 274 u_char *
268 extract_select_resp_tag(sought_tag) 275 extract_select_resp_tag(sought_tag)
269 unsigned sought_tag; 276 unsigned sought_tag;