FreeCalypso > hg > freecalypso-hwlab
changeset 131:d0929cb42e1c
fc-uicc-tool: GET RESPONSE after SELECT
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 04 Feb 2021 00:23:33 +0000 |
parents | f691a19f191d |
children | 5af88fa11b54 |
files | uicc/select.c |
diffstat | 1 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/uicc/select.c Thu Feb 04 00:08:12 2021 +0000 +++ b/uicc/select.c Thu Feb 04 00:23:33 2021 +0000 @@ -13,6 +13,7 @@ { u_char cmd[7]; int rc; + unsigned expect_resp_len; /* SELECT command APDU */ cmd[0] = 0x00; @@ -25,7 +26,33 @@ rc = apdu_exchange(cmd, 7); if (rc < 0) return(rc); - printf("SW response to SELECT: %04X\n", sim_resp_sw); + if ((sim_resp_sw & 0xFF00) != 0x6100) { + fprintf(stderr, + "error or unexpected SW response to SELECT of 0x%04X: %04X\n", + file_id, sim_resp_sw); + return(-1); + } + expect_resp_len = sim_resp_sw & 0xFF; + /* GET RESPONSE follow-up */ + cmd[1] = 0xC0; + cmd[2] = 0; + cmd[3] = 0; + cmd[4] = expect_resp_len; + rc = apdu_exchange(cmd, 5); + if (rc < 0) + return(rc); + if (sim_resp_sw != 0x9000) { + fprintf(stderr, + "bad SW resp to GET RESPONSE after SELECT: %04X\n", + sim_resp_sw); + return(-1); + } + if (sim_resp_data_len != expect_resp_len) { + fprintf(stderr, + "error: GET RESPONSE after SELECT returned %u bytes, expected %u\n", + sim_resp_data_len, expect_resp_len); + return(-1); + } return(0); }