FreeCalypso > hg > fc-sim-tools
changeset 96:a5cfe5135701
simtool: grcard2.c split into grcard2ki.c and grcard2pins.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 05 May 2021 03:55:23 +0000 |
parents | c06c0e2da24c |
children | 9f1cc3174e45 |
files | simtool/Makefile simtool/grcard2.c simtool/grcard2ki.c simtool/grcard2pins.c |
diffstat | 4 files changed, 261 insertions(+), 248 deletions(-) [+] |
line wrap: on
line diff
--- a/simtool/Makefile Wed Apr 21 06:40:33 2021 +0000 +++ b/simtool/Makefile Wed May 05 03:55:23 2021 +0000 @@ -3,8 +3,8 @@ CPPFLAGS=-I../libcommon PROG= fc-simtool OBJS= a38.o bfsearch.o chv.o chvext.o chvfunc.o cmdtab.o curfile.o dumpdir.o \ - erasefile.o fplmn.o getresp.o grcard1.o grcard2.o hlread.o \ - inval_rehab.o lndwrite.o main.o miscadm.o opldump.o oplprog.o \ + erasefile.o fplmn.o getresp.o grcard1.o grcard2ki.o grcard2pins.o \ + hlread.o inval_rehab.o lndwrite.o main.o miscadm.o opldump.o oplprog.o \ pbcommon.o pbdump.o pberase.o pbrestore.o pbupd_imm.o pbupd_immhex.o \ plmnsel.o pnndump.o pnnprog.o readcmd.o readef.o readops.o restorebin.o\ savebin.o select.o sjs1_hacks.o smserase.o smsp_common.o smsp_dump.o \
--- a/simtool/grcard2.c Wed Apr 21 06:40:33 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,246 +0,0 @@ -/* - * This module implements special commands for the grcard.cn card model - * which is known in the Osmocom community as GrcardSIM2: - * - * https://osmocom.org/projects/cellular-infrastructure/wiki/GrcardSIM2 - * - * FreeCalypso Community SIM model FCSIM1 is GrcardSIM2, and so are - * historical sysmoSIM-GR2 and 30C3 cards. - */ - -#include <sys/types.h> -#include <stdio.h> -#include "simresp.h" -#include "curfile.h" -#include "file_id.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); -} - -cmd_grcard2_set_puk(argc, argv) - char **argv; -{ - u_char cmd[13]; - int rc; - - /* Grcard2 proprietary command APDU */ - cmd[0] = 0xA0; - cmd[1] = 0xD4; - cmd[2] = 0x3B; - switch (argv[0][15]) { - case '1': - cmd[3] = 0x00; - break; - case '2': - cmd[3] = 0x02; - break; - default: - fprintf(stderr, "BUG in grcard2-set-pukN 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); -} - -cmd_grcard2_set_adm5(argc, argv) - char **argv; -{ - u_char cmd[13]; - int rc; - - /* Grcard2 proprietary command APDU */ - cmd[0] = 0xA0; - cmd[1] = 0xD4; - cmd[2] = 0x3A; - cmd[3] = 0x05; - 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); -} - -cmd_grcard2_set_adm5_hex(argc, argv) - char **argv; -{ - u_char cmd[13]; - int rc; - - /* Grcard2 proprietary command APDU */ - cmd[0] = 0xA0; - cmd[1] = 0xD4; - cmd[2] = 0x3A; - cmd[3] = 0x05; - cmd[4] = 8; - rc = decode_hex_data_from_string(argv[1], cmd + 5, 8, 8); - 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); -} - -cmd_grcard2_set_super(argc, argv) - char **argv; -{ - u_char cmd[13]; - int rc; - - /* Grcard2 proprietary command APDU */ - cmd[0] = 0xA0; - cmd[1] = 0xD4; - cmd[2] = 0x3A; - cmd[3] = 0x0B; - 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); -} - -cmd_grcard2_set_super_hex(argc, argv) - char **argv; -{ - u_char cmd[13]; - int rc; - - /* Grcard2 proprietary command APDU */ - cmd[0] = 0xA0; - cmd[1] = 0xD4; - cmd[2] = 0x3A; - cmd[3] = 0x0B; - cmd[4] = 8; - rc = decode_hex_data_from_string(argv[1], cmd + 5, 8, 8); - 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); -} - -static -select_ef_weki() -{ - int rc; - - rc = select_op(DF_GSM); - if (rc < 0) - return(rc); - rc = select_op(0x0001); /* proprietary EF */ - if (rc < 0) - return(rc); - rc = parse_ef_select_response(); - if (rc < 0) - return(rc); - if (curfile_structure != 0x00 || curfile_total_size != 35) { - fprintf(stderr, - "error: EF_WEKI is not a transparent EF of 35 bytes\n"); - return(-1); - } - return(0); -} - -cmd_grcard2_set_comp128(argc, argv) - char **argv; -{ - int rc; - unsigned code; - u_char magic_byte; - - if (argv[1][0] < '1' || argv[1][0] > '3' || argv[1][1]) { - fprintf(stderr, "error: invalid argument\n"); - return(-1); - } - code = argv[1][0] - '1'; - rc = select_ef_weki(); - if (rc < 0) - return(rc); - rc = readbin_op(2, 1); - if (rc < 0) - return(rc); - magic_byte = sim_resp_data[0]; - magic_byte &= 0xFC; - magic_byte |= code; - return update_bin_op(2, &magic_byte, 1); -} - -cmd_grcard2_set_ki(argc, argv) - char **argv; -{ - u_char ki[16]; - int rc; - - rc = decode_hex_data_from_string(argv[1], ki, 16, 16); - if (rc < 0) - return(rc); - rc = select_ef_weki(); - if (rc < 0) - return(rc); - return update_bin_op(3, ki, 16); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/grcard2ki.c Wed May 05 03:55:23 2021 +0000 @@ -0,0 +1,76 @@ +/* + * This module implements special commands for the grcard.cn card model + * which is known in the Osmocom community as GrcardSIM2: + * + * https://osmocom.org/projects/cellular-infrastructure/wiki/GrcardSIM2 + * + * FreeCalypso Community SIM model FCSIM1 is GrcardSIM2, and so are + * historical sysmoSIM-GR2 and 30C3 cards. + */ + +#include <sys/types.h> +#include <stdio.h> +#include "simresp.h" +#include "curfile.h" +#include "file_id.h" + +static +select_ef_weki() +{ + int rc; + + rc = select_op(DF_GSM); + if (rc < 0) + return(rc); + rc = select_op(0x0001); /* proprietary EF */ + if (rc < 0) + return(rc); + rc = parse_ef_select_response(); + if (rc < 0) + return(rc); + if (curfile_structure != 0x00 || curfile_total_size != 35) { + fprintf(stderr, + "error: EF_WEKI is not a transparent EF of 35 bytes\n"); + return(-1); + } + return(0); +} + +cmd_grcard2_set_comp128(argc, argv) + char **argv; +{ + int rc; + unsigned code; + u_char magic_byte; + + if (argv[1][0] < '1' || argv[1][0] > '3' || argv[1][1]) { + fprintf(stderr, "error: invalid argument\n"); + return(-1); + } + code = argv[1][0] - '1'; + rc = select_ef_weki(); + if (rc < 0) + return(rc); + rc = readbin_op(2, 1); + if (rc < 0) + return(rc); + magic_byte = sim_resp_data[0]; + magic_byte &= 0xFC; + magic_byte |= code; + return update_bin_op(2, &magic_byte, 1); +} + +cmd_grcard2_set_ki(argc, argv) + char **argv; +{ + u_char ki[16]; + int rc; + + rc = decode_hex_data_from_string(argv[1], ki, 16, 16); + if (rc < 0) + return(rc); + rc = select_ef_weki(); + if (rc < 0) + return(rc); + return update_bin_op(3, ki, 16); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/grcard2pins.c Wed May 05 03:55:23 2021 +0000 @@ -0,0 +1,183 @@ +/* + * This module implements special commands for the grcard.cn card model + * which is known in the Osmocom community as GrcardSIM2: + * + * https://osmocom.org/projects/cellular-infrastructure/wiki/GrcardSIM2 + * + * FreeCalypso Community SIM model FCSIM1 is GrcardSIM2, and so are + * historical sysmoSIM-GR2 and 30C3 cards. + */ + +#include <sys/types.h> +#include <stdio.h> +#include "simresp.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); +} + +cmd_grcard2_set_puk(argc, argv) + char **argv; +{ + u_char cmd[13]; + int rc; + + /* Grcard2 proprietary command APDU */ + cmd[0] = 0xA0; + cmd[1] = 0xD4; + cmd[2] = 0x3B; + switch (argv[0][15]) { + case '1': + cmd[3] = 0x00; + break; + case '2': + cmd[3] = 0x02; + break; + default: + fprintf(stderr, "BUG in grcard2-set-pukN 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); +} + +cmd_grcard2_set_adm5(argc, argv) + char **argv; +{ + u_char cmd[13]; + int rc; + + /* Grcard2 proprietary command APDU */ + cmd[0] = 0xA0; + cmd[1] = 0xD4; + cmd[2] = 0x3A; + cmd[3] = 0x05; + 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); +} + +cmd_grcard2_set_adm5_hex(argc, argv) + char **argv; +{ + u_char cmd[13]; + int rc; + + /* Grcard2 proprietary command APDU */ + cmd[0] = 0xA0; + cmd[1] = 0xD4; + cmd[2] = 0x3A; + cmd[3] = 0x05; + cmd[4] = 8; + rc = decode_hex_data_from_string(argv[1], cmd + 5, 8, 8); + 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); +} + +cmd_grcard2_set_super(argc, argv) + char **argv; +{ + u_char cmd[13]; + int rc; + + /* Grcard2 proprietary command APDU */ + cmd[0] = 0xA0; + cmd[1] = 0xD4; + cmd[2] = 0x3A; + cmd[3] = 0x0B; + 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); +} + +cmd_grcard2_set_super_hex(argc, argv) + char **argv; +{ + u_char cmd[13]; + int rc; + + /* Grcard2 proprietary command APDU */ + cmd[0] = 0xA0; + cmd[1] = 0xD4; + cmd[2] = 0x3A; + cmd[3] = 0x0B; + cmd[4] = 8; + rc = decode_hex_data_from_string(argv[1], cmd + 5, 8, 8); + 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); +}