# HG changeset patch # User Mychaela Falconia # Date 1614284230 0 # Node ID cb3c40ff443e754cc175b4ddb9e40b56386625ad # Parent 6d93a51f01dcb471c3bfd40bf3533c870033f0dd fc-uicc-tool bfsearch: handle more weird SW response cases diff -r 6d93a51f01dc -r cb3c40ff443e uicc/bfsearch.c --- a/uicc/bfsearch.c Thu Feb 25 18:40:59 2021 +0000 +++ b/uicc/bfsearch.c Thu Feb 25 20:17:10 2021 +0000 @@ -25,10 +25,10 @@ rc = elem_select_op(path[n]); if (rc < 0) return(rc); - if (!rc) { + if ((sim_resp_sw & 0xFF00) != 0x6100) { fprintf(stderr, - "error selecting 0x%04X: file not found\n", - path[n]); + "error selecting 0x%04X: SW resp 0x%04X\n", + path[n], sim_resp_sw); return(-1); } } @@ -51,8 +51,15 @@ rc = elem_select_op(bfs); if (rc < 0) return(rc); - if (!rc) + if (sim_resp_sw == 0x6A82) continue; + if ((sim_resp_sw & 0xFF00) != 0x6100) { + for (n = 0; n < pathlen; n++) + fprintf(outf, "%04X/", path[n]); + fprintf(outf, "%04X: SW response 0x%04X", bfs, + sim_resp_sw); + continue; + } rc = get_response_op(); if (rc < 0) return(rc); @@ -87,10 +94,10 @@ rc = elem_select_op(path[pathlen-1]); if (rc < 0) return(rc); - if (!rc) { + if ((sim_resp_sw & 0xFF00) != 0x6100) { fprintf(stderr, - "reselecting starting file ID 0x%04X not-found error\n", - path[pathlen-1]); + "reselecting starting file ID 0x%04X: SW resp 0x%04X\n", + path[pathlen-1], sim_resp_sw); return(-1); } } diff -r 6d93a51f01dc -r cb3c40ff443e uicc/select.c --- a/uicc/select.c Thu Feb 25 18:40:59 2021 +0000 +++ b/uicc/select.c Thu Feb 25 20:17:10 2021 +0000 @@ -16,7 +16,6 @@ { u_char cmd[7]; int rc; - unsigned expect_resp_len; last_sel_file_record_len = 0; /* SELECT command APDU */ @@ -27,17 +26,7 @@ cmd[4] = 2; cmd[5] = file_id >> 8; cmd[6] = file_id; - rc = apdu_exchange(cmd, 7); - if (rc < 0) - return(rc); - if (sim_resp_sw == 0x6A82) - return(0); - if ((sim_resp_sw & 0xFF00) == 0x6100) - return(1); - fprintf(stderr, - "error or unexpected SW response to SELECT of 0x%04X: %04X\n", - file_id, sim_resp_sw); - return(-1); + return apdu_exchange(cmd, 7); } select_op(file_id)