FreeCalypso > hg > freecalypso-hwlab
diff uicc/select.c @ 138:baf5bd698764
fc-uicc-tool: select-aid command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 04 Feb 2021 04:51:08 +0000 |
parents | 51d6aaa43a7b |
children | 6c6e8705dc70 |
line wrap: on
line diff
--- a/uicc/select.c Thu Feb 04 04:27:09 2021 +0000 +++ b/uicc/select.c Thu Feb 04 04:51:08 2021 +0000 @@ -56,6 +56,54 @@ return(0); } +select_aid_op(aid, aid_len) + u_char *aid; + unsigned aid_len; +{ + u_char cmd[21]; + int rc; + unsigned expect_resp_len; + + /* SELECT command APDU */ + cmd[0] = 0x00; + cmd[1] = 0xA4; + cmd[2] = 0x04; + cmd[3] = 0x04; + cmd[4] = aid_len; + bcopy(aid, cmd + 5, aid_len); + rc = apdu_exchange(cmd, aid_len + 5); + if (rc < 0) + return(rc); + if ((sim_resp_sw & 0xFF00) != 0x6100) { + fprintf(stderr, + "error or unexpected SW response to SELECT by AID: %04X\n", + 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); +} + select_resp_header_check(ret_offset, ret_length) unsigned *ret_offset, *ret_length; { @@ -152,6 +200,23 @@ return parse_and_display_select_response(); } +cmd_select_aid(argc, argv) + char **argv; +{ + u_char aid[16]; + unsigned aid_len; + int rc; + + rc = decode_hex_data_from_string(argv[1], aid, 16); + if (rc < 0) + return(rc); + aid_len = rc; + rc = select_aid_op(aid, aid_len); + if (rc < 0) + return(rc); + return parse_and_display_select_response(); +} + u_char * extract_select_resp_tag(sought_tag) unsigned sought_tag;