# HG changeset patch # User Mychaela Falconia # Date 1612655573 0 # Node ID 1232dea1d66ae2bf6ed481874a7c4a70686a6015 # Parent 43463dc9143184b321c126a8bb83cd88b4efc965 fc-simtool: grcard1-set-pin[12] commands implemented diff -r 43463dc91431 -r 1232dea1d66a simtool/Makefile --- a/simtool/Makefile Sat Feb 06 02:54:16 2021 +0000 +++ b/simtool/Makefile Sat Feb 06 23:52:53 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 hexdump.o hexread.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 hexdump.o hexread.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 43463dc91431 -r 1232dea1d66a simtool/chv.c --- a/simtool/chv.c Sat Feb 06 02:54:16 2021 +0000 +++ b/simtool/chv.c Sat Feb 06 23:52:53 2021 +0000 @@ -11,7 +11,6 @@ #include #include "globals.h" -static encode_pin_entry(arg, dest) char *arg; u_char *dest; diff -r 43463dc91431 -r 1232dea1d66a simtool/dispatch.c --- a/simtool/dispatch.c Sat Feb 06 02:54:16 2021 +0000 +++ b/simtool/dispatch.c Sat Feb 06 23:52:53 2021 +0000 @@ -14,6 +14,7 @@ extern int cmd_enable_chv(); extern int cmd_exec(); extern int cmd_fix_sysmo_msisdn(); +extern int cmd_grcard1_set_pin(); extern int cmd_iccid(); extern int cmd_imsi(); extern int cmd_pb_dump(); @@ -62,6 +63,8 @@ {"exec", 1, 1, cmd_exec}, {"exit", 0, 0, good_exit}, {"fix-sysmo-msisdn", 0, 0, cmd_fix_sysmo_msisdn}, + {"grcard1-set-pin1", 2, 2, cmd_grcard1_set_pin}, + {"grcard1-set-pin2", 2, 2, cmd_grcard1_set_pin}, {"iccid", 0, 0, cmd_iccid}, {"imsi", 0, 0, cmd_imsi}, {"pb-dump", 1, 2, cmd_pb_dump}, diff -r 43463dc91431 -r 1232dea1d66a simtool/grcard1.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/grcard1.c Sat Feb 06 23:52:53 2021 +0000 @@ -0,0 +1,52 @@ +/* + * This module implements a few special commands for those very few + * incredibly lucky people on Earth who have no-longer-available + * sysmoSIM-GR1 cards, or any other branded variant of the same card + * from Grcard. + */ + +#include +#include +#include +#include +#include +#include +#include "globals.h" + +cmd_grcard1_set_pin(argc, argv) + char **argv; +{ + u_char cmd[21]; + int rc; + + /* Grcard1 proprietary command APDU */ + cmd[0] = 0x80; + cmd[1] = 0xD4; + cmd[2] = 0x00; + switch (argv[0][15]) { + case '1': + cmd[3] = 0x01; + break; + case '2': + cmd[3] = 0x02; + break; + default: + fprintf(stderr, "BUG in grcard1-set-pinN command\n"); + return(-1); + } + cmd[4] = 16; + rc = encode_pin_entry(argv[1], cmd + 5); + if (rc < 0) + return(rc); + rc = encode_pin_entry(argv[2], cmd + 13); + if (rc < 0) + return(rc); + rc = apdu_exchange(cmd, 21); + if (rc < 0) + return(rc); + if (sim_resp_sw != 0x9000) { + fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); + return(-1); + } + return(0); +}