FreeCalypso > hg > fc-pcsc-tools
view simtool/grcard2.c @ 192:edaccdbac95b
doc/GrcardSIM2-security-model: document ADM11 MF quirk
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 Mar 2021 21:41:12 +0000 |
parents | 36e7fc58f065 |
children | e07de8a9cedf |
line wrap: on
line source
/* * 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 * * The sample cards which Mother Mychaela received from Grcard in 2021-02 * are 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); }