FreeCalypso > hg > freecalypso-hwlab
diff simtool/grcard1.c @ 148:1232dea1d66a
fc-simtool: grcard1-set-pin[12] commands implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 Feb 2021 23:52:53 +0000 |
parents | |
children | 451ed3bbfe96 |
line wrap: on
line diff
--- /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 <sys/types.h> +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <pcsclite.h> +#include <winscard.h> +#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); +}