# HG changeset patch # User Mychaela Falconia # Date 1612398213 0 # Node ID d0929cb42e1c93ce1459ecf6850e01d0c947d58d # Parent f691a19f191d0b4d44912cb891136419ab32f043 fc-uicc-tool: GET RESPONSE after SELECT diff -r f691a19f191d -r d0929cb42e1c uicc/select.c --- 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); }