FreeCalypso > hg > freecalypso-hwlab
diff 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 |
line wrap: on
line diff
--- a/uicc/select.c Thu Feb 04 05:12:24 2021 +0000 +++ b/uicc/select.c Sat Feb 06 02:03:11 2021 +0000 @@ -18,6 +18,7 @@ int rc; unsigned expect_resp_len; + last_sel_file_record_len = 0; /* SELECT command APDU */ cmd[0] = 0x00; cmd[1] = 0xA4; @@ -67,6 +68,7 @@ int rc; unsigned expect_resp_len; + last_sel_file_record_len = 0; /* SELECT command APDU */ cmd[0] = 0x00; cmd[1] = 0xA4; @@ -142,6 +144,26 @@ goto return_check; } +static void +check_for_record_struct(tlv) + u_char *tlv; +{ + unsigned reclen; + + if (tlv[1] != 5) + return; + if (tlv[2] & 0x80) + return; + if ((tlv[2] & 0x38) == 0x38) + return; + if ((tlv[2] & 0x03) != 0x02) + return; + reclen = (tlv[4] << 8) | tlv[5]; + if (reclen < 1 || reclen > 255) + return; + last_sel_file_record_len = reclen; +} + parse_and_display_select_response() { unsigned offset, totlen, reclen, n; @@ -172,6 +194,8 @@ reclen = dp[1] + 2; if (endp - dp < reclen) goto trunc_error; + if (dp[0] == 0x82) + check_for_record_struct(dp); for (n = 0; n < reclen; n++) { if (n) putchar(' ');