# HG changeset patch # User Mychaela Falconia # Date 1613952522 0 # Node ID 277c66de296fd6c4f3d8e03a567e5e030dbe6581 # Parent 5494795406e09dbb6bcd4ef64259f7203fd667d7 fc-simtool: added STK test commands diff -r 5494795406e0 -r 277c66de296f simtool/Makefile --- a/simtool/Makefile Sun Feb 21 01:05:05 2021 +0000 +++ b/simtool/Makefile Mon Feb 22 00:08:42 2021 +0000 @@ -6,8 +6,8 @@ pbcommon.o pbdump.o pberase.o pbrestore.o pbupd_imm.o pbupd_immhex.o \ plmnsel.o pnndump.o readcmd.o readops.o restorebin.o savebin.o script.o\ select.o smserase.o smsp_common.o smsp_dump.o smsp_erase.o \ - smsp_restore.o smsp_set.o sstlist.o sysmo.o telsum.o usersum.o \ - writecmd.o writeops.o + smsp_restore.o smsp_set.o sstlist.o stktest.o sysmo.o telsum.o \ + usersum.o writecmd.o writeops.o LIBS= ../libcommon/libcommon.a INSTBIN=/opt/freecalypso/bin diff -r 5494795406e0 -r 277c66de296f simtool/dispatch.c --- a/simtool/dispatch.c Sun Feb 21 01:05:05 2021 +0000 +++ b/simtool/dispatch.c Mon Feb 22 00:08:42 2021 +0000 @@ -14,12 +14,15 @@ extern int cmd_change_chv(); extern int cmd_disable_chv(); extern int cmd_enable_chv(); +extern int cmd_envelope(); +extern int cmd_envelope_imm(); extern int cmd_exec(); extern int cmd_fix_sysmo_msisdn(); extern int cmd_fplmn_dump(); extern int cmd_fplmn_erase(); extern int cmd_fplmn_erase_all(); extern int cmd_fplmn_write(); +extern int cmd_get_response(); extern int cmd_grcard1_set_adm(); extern int cmd_grcard1_set_ki(); extern int cmd_grcard1_set_pin(); @@ -75,6 +78,7 @@ extern int cmd_spn(); extern int cmd_sst(); extern int cmd_telecom_sum(); +extern int cmd_terminal_profile(); extern int cmd_uicc_dir(); extern int cmd_unblock_chv(); extern int cmd_update_bin(); @@ -119,6 +123,8 @@ {"enable-chv1", 1, 1, 0, cmd_enable_chv}, {"enable-pin", 1, 1, 0, cmd_enable_chv}, {"enable-pin1", 1, 1, 0, cmd_enable_chv}, + {"envelope", 1, 1, 0, cmd_envelope}, + {"envelope-imm", 1, 1, 0, cmd_envelope_imm}, {"exec", 1, 1, 0, cmd_exec}, {"exit", 0, 0, 0, good_exit}, {"fix-sysmo-msisdn", 0, 0, 0, cmd_fix_sysmo_msisdn}, @@ -126,6 +132,7 @@ {"fplmn-erase", 1, 2, 0, cmd_fplmn_erase}, {"fplmn-erase-all", 0, 0, 0, cmd_fplmn_erase_all}, {"fplmn-write", 2, 2, 0, cmd_fplmn_write}, + {"get-response", 1, 1, 1, cmd_get_response}, {"grcard1-set-adm1", 2, 2, 0, cmd_grcard1_set_adm}, {"grcard1-set-adm2", 2, 2, 0, cmd_grcard1_set_adm}, {"grcard1-set-ki", 1, 1, 0, cmd_grcard1_set_ki}, @@ -186,6 +193,7 @@ {"spn", 0, 0, 1, cmd_spn}, {"sst", 0, 0, 1, cmd_sst}, {"telecom-sum", 0, 0, 0, cmd_telecom_sum}, + {"terminal-profile", 1, 1, 0, cmd_terminal_profile}, {"uicc-dir", 0, 0, 1, cmd_uicc_dir}, {"unblock-chv1", 2, 2, 0, cmd_unblock_chv}, {"unblock-chv2", 2, 2, 0, cmd_unblock_chv}, diff -r 5494795406e0 -r 277c66de296f simtool/stktest.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/stktest.c Mon Feb 22 00:08:42 2021 +0000 @@ -0,0 +1,112 @@ +/* + * This module implements some commands for testing SIM Toolkit functionality, + * just enough to be able to simulate SMS-PP SIM data download operations. + */ + +#include +#include +#include +#include "simresp.h" + +cmd_terminal_profile(argc, argv) + char **argv; +{ + u_char cmd[260]; + int rc; + unsigned len; + + rc = decode_hex_data_from_string(argv[1], cmd + 5, 1, 255); + if (rc < 0) + return(rc); + len = rc; + /* TERMINAL PROFILE command APDU */ + cmd[0] = 0xA0; + cmd[1] = 0x10; + cmd[2] = 0; + cmd[3] = 0; + cmd[4] = len; + rc = apdu_exchange(cmd, len + 5); + if (rc < 0) + return(rc); + printf("%04X\n", sim_resp_sw); + return(0); +} + +cmd_envelope(argc, argv) + char **argv; +{ + u_char cmd[260]; + int rc; + unsigned len; + + rc = read_hex_data_file(argv[1], cmd + 5); + if (rc < 0) + return(rc); + len = rc; + /* ENVELOPE command APDU */ + cmd[0] = 0xA0; + cmd[1] = 0xC2; + cmd[2] = 0; + cmd[3] = 0; + cmd[4] = len; + rc = apdu_exchange(cmd, len + 5); + if (rc < 0) + return(rc); + printf("%04X\n", sim_resp_sw); + return(0); +} + +cmd_envelope_imm(argc, argv) + char **argv; +{ + u_char cmd[260]; + int rc; + unsigned len; + + rc = decode_hex_data_from_string(argv[1], cmd + 5, 1, 255); + if (rc < 0) + return(rc); + len = rc; + /* ENVELOPE command APDU */ + cmd[0] = 0xA0; + cmd[1] = 0xC2; + cmd[2] = 0; + cmd[3] = 0; + cmd[4] = len; + rc = apdu_exchange(cmd, len + 5); + if (rc < 0) + return(rc); + printf("%04X\n", sim_resp_sw); + return(0); +} + +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] = 0xA0; + 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); +}