# HG changeset patch # User Mychaela Falconia # Date 1612664947 0 # Node ID ed34c8b7e2c9cf4a01baad675b4400420479c694 # Parent a63e4c64f1f067dce1bf72544b08bdbf10257344 fc-simtool: grcard2-set-pin[12] commands implemented diff -r a63e4c64f1f0 -r ed34c8b7e2c9 simtool/Makefile --- a/simtool/Makefile Sun Feb 07 00:46:18 2021 +0000 +++ b/simtool/Makefile Sun Feb 07 02:29:07 2021 +0000 @@ -2,10 +2,10 @@ CFLAGS= -O2 -I/usr/include/PCSC PROG= fc-simtool OBJS= a38.o alpha_decode.o alpha_valid.o apdu.o atr.o cardconnect.o chv.o \ - dispatch.o dumpdir.o exit.o globals.o grcard1.o hexdump.o hexread.o \ - hexstr.o hlread.o main.o names.o pbcommon.o pbdump.o pberase.o \ - pbupdate.o readcmd.o readops.o saverestore.o script.o select.o sysmo.o \ - telsum.o writecmd.o writeops.o + dispatch.o dumpdir.o exit.o globals.o grcard1.o grcard2.o hexdump.o \ + hexread.o hexstr.o hlread.o main.o names.o pbcommon.o pbdump.o \ + pberase.o pbupdate.o readcmd.o readops.o saverestore.o script.o \ + select.o sysmo.o telsum.o writecmd.o writeops.o INSTBIN=/opt/freecalypso/bin all: ${PROG} diff -r a63e4c64f1f0 -r ed34c8b7e2c9 simtool/dispatch.c --- a/simtool/dispatch.c Sun Feb 07 00:46:18 2021 +0000 +++ b/simtool/dispatch.c Sun Feb 07 02:29:07 2021 +0000 @@ -17,6 +17,7 @@ extern int cmd_grcard1_set_adm(); extern int cmd_grcard1_set_ki(); extern int cmd_grcard1_set_pin(); +extern int cmd_grcard2_set_pin(); extern int cmd_iccid(); extern int cmd_imsi(); extern int cmd_pb_dump(); @@ -70,6 +71,8 @@ {"grcard1-set-ki", 1, 1, cmd_grcard1_set_ki}, {"grcard1-set-pin1", 2, 2, cmd_grcard1_set_pin}, {"grcard1-set-pin2", 2, 2, cmd_grcard1_set_pin}, + {"grcard2-set-pin1", 1, 1, cmd_grcard2_set_pin}, + {"grcard2-set-pin2", 1, 1, cmd_grcard2_set_pin}, {"iccid", 0, 0, cmd_iccid}, {"imsi", 0, 0, cmd_imsi}, {"pb-dump", 1, 2, cmd_pb_dump}, diff -r a63e4c64f1f0 -r ed34c8b7e2c9 simtool/grcard2.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/grcard2.c Sun Feb 07 02:29:07 2021 +0000 @@ -0,0 +1,55 @@ +/* + * I, Mother Mychaela, am hoping to get some SIM cards from Grcard + * that follow the protocol which the Osmocom community has nicknamed + * GrcardSIM2: + * + * https://osmocom.org/projects/cellular-infrastructure/wiki/GrcardSIM2 + * + * I haven't got these cards yet and may not get them for a long time, + * hence the following code has been written blindly, untested. + * If anyone in the community happens to have a sysmoSIM-GR2 card + * that was once (aeons ago) sold by Sysmocom, please test this code! + */ + +#include +#include +#include +#include +#include +#include +#include "globals.h" + +cmd_grcard2_set_pin(argc, argv) + char **argv; +{ + u_char cmd[13]; + int rc; + + /* Grcard2 proprietary command APDU */ + cmd[0] = 0xA0; + cmd[1] = 0xD4; + cmd[2] = 0x3A; + switch (argv[0][15]) { + case '1': + cmd[3] = 0x01; + break; + case '2': + cmd[3] = 0x02; + break; + default: + fprintf(stderr, "BUG in grcard2-set-pinN command\n"); + return(-1); + } + cmd[4] = 8; + rc = encode_pin_entry(argv[1], cmd + 5); + if (rc < 0) + return(rc); + rc = apdu_exchange(cmd, 13); + if (rc < 0) + return(rc); + if (sim_resp_sw != 0x9000) { + fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); + return(-1); + } + return(0); +}