# HG changeset patch # User Mychaela Falconia # Date 1614272798 0 # Node ID d9dd52bc403b8b4760d693ecce53e5bd55c9b2d2 # Parent 0d007555ac89cee7cfaef25f6e39d8a11a72ee88 fc-uicc-tool factored-out GET RESPONSE implemented diff -r 0d007555ac89 -r d9dd52bc403b uicc/Makefile --- a/uicc/Makefile Thu Feb 25 16:55:22 2021 +0000 +++ b/uicc/Makefile Thu Feb 25 17:06:38 2021 +0000 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 -I/usr/include/PCSC -I../libcommon PROG= fc-uicc-tool -OBJS= createfile.o dispatch.o dumpdir.o hlread.o main.o pins.o readcmd.o \ - readops.o script.o select.o writecmd.o writeops.o +OBJS= createfile.o dispatch.o dumpdir.o getresp.o hlread.o main.o pins.o \ + readcmd.o readops.o script.o select.o writecmd.o writeops.o LIBS= ../libcommon/libcommon.a INSTBIN=/opt/freecalypso/bin diff -r 0d007555ac89 -r d9dd52bc403b uicc/dispatch.c --- a/uicc/dispatch.c Thu Feb 25 16:55:22 2021 +0000 +++ b/uicc/dispatch.c Thu Feb 25 17:06:38 2021 +0000 @@ -17,6 +17,7 @@ extern int cmd_disable_pin(); extern int cmd_enable_pin(); extern int cmd_exec(); +extern int cmd_get_response(); extern int cmd_iccid(); extern int cmd_pin_attempt_cnt(); extern int cmd_puk_attempt_cnt(); @@ -56,6 +57,7 @@ {"enable-pin", 2, 2, 0, cmd_enable_pin}, {"exec", 1, 1, 0, cmd_exec}, {"exit", 0, 0, 0, good_exit}, + {"get-response", 1, 1, 1, cmd_get_response}, {"iccid", 0, 0, 1, cmd_iccid}, {"pin-attempt-cnt", 1, 1, 0, cmd_pin_attempt_cnt}, {"puk-attempt-cnt", 1, 1, 0, cmd_puk_attempt_cnt}, diff -r 0d007555ac89 -r d9dd52bc403b uicc/getresp.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uicc/getresp.c Thu Feb 25 17:06:38 2021 +0000 @@ -0,0 +1,69 @@ +/* + * This module implements an elementary GET RESPONSE command + */ + +#include +#include +#include +#include "simresp.h" + +cmd_get_response(argc, argv, outf) + char **argv; + FILE *outf; +{ + u_char cmd[5]; + int rc; + unsigned len; + + len = strtoul(argv[1], 0, 0); + if (len < 1 || len > 256) { + fprintf(stderr, "error: length argument is out of range\n"); + return(-1); + } + /* GET RESPONSE command APDU */ + cmd[0] = 0x00; + cmd[1] = 0xC0; + cmd[2] = 0; + cmd[3] = 0; + cmd[4] = len; + rc = apdu_exchange(cmd, 5); + if (rc < 0) + return(rc); + if (sim_resp_sw != 0x9000) { + fprintf(stderr, "bad SW resp to GET RESPONSE: %04X\n", + sim_resp_sw); + return(-1); + } + display_sim_resp_in_hex(outf); + return(0); +} + +get_response_op() +{ + u_char cmd[5]; + int rc; + unsigned expect_resp_len; + + expect_resp_len = sim_resp_sw & 0xFF; + /* GET RESPONSE command APDU */ + cmd[0] = 0x00; + 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: %04X\n", + sim_resp_sw); + return(-1); + } + if (sim_resp_data_len != expect_resp_len) { + fprintf(stderr, + "error: GET RESPONSE returned %u bytes, expected %u\n", + sim_resp_data_len, expect_resp_len); + return(-1); + } + return(0); +}