# HG changeset patch # User Mychaela Falconia # Date 1618113168 0 # Node ID 0e46bbb801e0e37aff3892506701e541deccf103 # Parent de23872796cb972277dfba7ba03193df2116bee1 fc-uicc-tool: internal code in preparation for porting extended readef, savebin, restore-file and erase-file commands from fc-simtool diff -r de23872796cb -r 0e46bbb801e0 uicc/efstruct.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uicc/efstruct.h Sun Apr 11 03:52:48 2021 +0000 @@ -0,0 +1,11 @@ +/* + * This header file defines a simple internal struct that represents + * EF structure decoded from the messy TLV-based SELECT response. + */ + +struct ef_struct { + unsigned structure; + unsigned total_size; + unsigned record_len; + unsigned record_count; +}; diff -r de23872796cb -r 0e46bbb801e0 uicc/select.c --- a/uicc/select.c Sun Apr 11 03:19:22 2021 +0000 +++ b/uicc/select.c Sun Apr 11 03:52:48 2021 +0000 @@ -5,6 +5,7 @@ #include #include #include "simresp.h" +#include "efstruct.h" u_char std_aid_usim[7] = {0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x02}; u_char std_aid_isim[7] = {0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x04}; @@ -392,3 +393,58 @@ *rec_count_ret = tlv[6]; return(0); } + +select_resp_get_ef_struct(efs) + struct ef_struct *efs; +{ + u_char *tlv; + + tlv = extract_select_resp_tag(0x82); + if (!tlv) + return(-1); + if (tlv[1] < 2) { +bad_file_desc: fprintf(stderr, "error: unable to figure out file structure\n"); + return(-1); + } + if (tlv[2] & 0x80) + goto bad_file_desc; + if ((tlv[2] & 0x38) == 0x38) + goto bad_file_desc; + efs->structure = tlv[2] & 0x07; + switch (efs->structure) { + case 0x01: + if (tlv[1] != 2) { + fprintf(stderr, + "error: file descriptor TLV element has wrong length\n"); + return(-1); + } + tlv = extract_select_resp_tag(0x80); + if (!tlv) + return(-1); + if (tlv[1] != 2) { + fprintf(stderr, + "error: file size TLV element has wrong length\n"); + return(-1); + } + efs->total_size = (tlv[2] << 8) | tlv[3]; + return(0); + case 0x02: + case 0x06: + if (tlv[1] != 5) { + fprintf(stderr, + "error: file descriptor TLV element has wrong length\n"); + return(-1); + } + efs->record_len = (tlv[4] << 8) | tlv[5]; + if (efs->record_len < 1 || efs->record_len > 255) { + fprintf(stderr, + "error: SELECT response gives invalid record length\n"); + return(-1); + } + efs->record_count = tlv[6]; + efs->total_size = efs->record_len * efs->record_count; + return(0); + default: + goto bad_file_desc; + } +}