FreeCalypso > hg > fc-sim-tools
comparison uicc/select.c @ 87:0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
extended readef, savebin, restore-file and erase-file commands
from fc-simtool
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 11 Apr 2021 03:52:48 +0000 |
parents | b70d35f5476f |
children | db131929ee96 |
comparison
equal
deleted
inserted
replaced
86:de23872796cb | 87:0e46bbb801e0 |
---|---|
3 #include <string.h> | 3 #include <string.h> |
4 #include <strings.h> | 4 #include <strings.h> |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include "simresp.h" | 7 #include "simresp.h" |
8 #include "efstruct.h" | |
8 | 9 |
9 u_char std_aid_usim[7] = {0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x02}; | 10 u_char std_aid_usim[7] = {0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x02}; |
10 u_char std_aid_isim[7] = {0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x04}; | 11 u_char std_aid_isim[7] = {0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x04}; |
11 | 12 |
12 unsigned last_sel_file_record_len; | 13 unsigned last_sel_file_record_len; |
390 *rec_len_ret = reclen; | 391 *rec_len_ret = reclen; |
391 if (rec_count_ret) | 392 if (rec_count_ret) |
392 *rec_count_ret = tlv[6]; | 393 *rec_count_ret = tlv[6]; |
393 return(0); | 394 return(0); |
394 } | 395 } |
396 | |
397 select_resp_get_ef_struct(efs) | |
398 struct ef_struct *efs; | |
399 { | |
400 u_char *tlv; | |
401 | |
402 tlv = extract_select_resp_tag(0x82); | |
403 if (!tlv) | |
404 return(-1); | |
405 if (tlv[1] < 2) { | |
406 bad_file_desc: fprintf(stderr, "error: unable to figure out file structure\n"); | |
407 return(-1); | |
408 } | |
409 if (tlv[2] & 0x80) | |
410 goto bad_file_desc; | |
411 if ((tlv[2] & 0x38) == 0x38) | |
412 goto bad_file_desc; | |
413 efs->structure = tlv[2] & 0x07; | |
414 switch (efs->structure) { | |
415 case 0x01: | |
416 if (tlv[1] != 2) { | |
417 fprintf(stderr, | |
418 "error: file descriptor TLV element has wrong length\n"); | |
419 return(-1); | |
420 } | |
421 tlv = extract_select_resp_tag(0x80); | |
422 if (!tlv) | |
423 return(-1); | |
424 if (tlv[1] != 2) { | |
425 fprintf(stderr, | |
426 "error: file size TLV element has wrong length\n"); | |
427 return(-1); | |
428 } | |
429 efs->total_size = (tlv[2] << 8) | tlv[3]; | |
430 return(0); | |
431 case 0x02: | |
432 case 0x06: | |
433 if (tlv[1] != 5) { | |
434 fprintf(stderr, | |
435 "error: file descriptor TLV element has wrong length\n"); | |
436 return(-1); | |
437 } | |
438 efs->record_len = (tlv[4] << 8) | tlv[5]; | |
439 if (efs->record_len < 1 || efs->record_len > 255) { | |
440 fprintf(stderr, | |
441 "error: SELECT response gives invalid record length\n"); | |
442 return(-1); | |
443 } | |
444 efs->record_count = tlv[6]; | |
445 efs->total_size = efs->record_len * efs->record_count; | |
446 return(0); | |
447 default: | |
448 goto bad_file_desc; | |
449 } | |
450 } |