FreeCalypso > hg > fc-sim-tools
annotate simtool/grcard1.c @ 72:5f7377392211
doc/GrcardSIM1-notes article written
| author | Mychaela Falconia <falcon@freecalypso.org> | 
|---|---|
| date | Wed, 07 Apr 2021 05:18:17 +0000 | 
| parents | c8e2a0e89d08 | 
| children | 
| rev | line source | 
|---|---|
| 10 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 1 /* | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 2 * This module implements a few special commands for those very few | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 3 * incredibly lucky people on Earth who have no-longer-available | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 4 * sysmoSIM-GR1 cards, or any other branded variant of the same card | 
| 66 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 5 * from Grcard. All knowledge of proprietary APDUs that appears in | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 6 * this code comes from this Osmocom wiki page: | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 7 * | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 8 * https://osmocom.org/projects/cellular-infrastructure/wiki/GrcardSIM | 
| 10 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 9 */ | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 10 | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 11 #include <sys/types.h> | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 12 #include <stdio.h> | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 13 #include "simresp.h" | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 14 | 
| 66 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 15 /* | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 16 * grcard1-set-pin1 command sets PIN1 and PUK1, | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 17 * grcard1-set-pin2 command sets PIN2 and PUK2. | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 18 * | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 19 * The proprietary APDU structure for these commands is naturally | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 20 * intuitive (agrees with common sense), hence they are expected | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 21 * to be correct despite lack of testing. | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 22 */ | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 23 | 
| 10 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 24 cmd_grcard1_set_pin(argc, argv) | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 25 char **argv; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 26 { | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 27 u_char cmd[21]; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 28 int rc; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 29 | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 30 /* Grcard1 proprietary command APDU */ | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 31 cmd[0] = 0x80; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 32 cmd[1] = 0xD4; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 33 cmd[2] = 0x00; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 34 switch (argv[0][15]) { | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 35 case '1': | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 36 cmd[3] = 0x01; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 37 break; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 38 case '2': | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 39 cmd[3] = 0x02; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 40 break; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 41 default: | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 42 fprintf(stderr, "BUG in grcard1-set-pinN command\n"); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 43 return(-1); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 44 } | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 45 cmd[4] = 16; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 46 rc = encode_pin_entry(argv[1], cmd + 5); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 47 if (rc < 0) | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 48 return(rc); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 49 rc = encode_pin_entry(argv[2], cmd + 13); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 50 if (rc < 0) | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 51 return(rc); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 52 rc = apdu_exchange(cmd, 21); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 53 if (rc < 0) | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 54 return(rc); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 55 if (sim_resp_sw != 0x9000) { | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 56 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 57 return(-1); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 58 } | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 59 return(0); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 60 } | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 61 | 
| 66 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 62 /* | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 63 * The ADM PIN structure of GrcardSIM1 cards is poorly understood. | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 64 * The Osmocom wiki page describes ADM1 and ADM2 per Grcard's ADMn | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 65 * naming convention (see ../doc/ADM-PIN-numbering), but each of those | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 66 * also has an associated unblock code (called AUK1 and AUK2 in the | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 67 * wiki page), and the command APDUs set ADM+AUK pairs: either | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 68 * ADM1+AUK1 or ADM2+AUK2. The following blind (untested) code is | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 69 * based on this wiki page description. | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 70 * | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 71 * Because these access control codes are proprietary to Grcard | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 72 * (not standard PIN1/PIN2/PUK1/PUK2), they can be arbitrary 64-bit | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 73 * keys, not restricted to the ASCII-decimal subset used for standard | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 74 * PINs and PUKs. According to pySim-prog, the canonical ADM2 key | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 75 * on these cards is hex 4444444444444444, which is outside of the | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 76 * ASCII-decimal range (contrast with the situation on GrcardSIM2, | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 77 * where the canonical SUPER ADM is decimal 88888888) - hence our | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 78 * grcard1-set-admN commands take hex strings for ADMn and AUKn, | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 79 * not decimal ones like grcard1-set-pinN. | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 80 */ | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 81 | 
| 10 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 82 cmd_grcard1_set_adm(argc, argv) | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 83 char **argv; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 84 { | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 85 u_char cmd[23]; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 86 int rc; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 87 | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 88 /* Grcard1 proprietary command APDU */ | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 89 cmd[0] = 0x80; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 90 cmd[1] = 0xD4; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 91 cmd[2] = 0x01; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 92 switch (argv[0][15]) { | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 93 case '1': | 
| 66 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 94 case '4': | 
| 10 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 95 cmd[3] = 0x04; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 96 break; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 97 case '2': | 
| 66 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 98 case '5': | 
| 10 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 99 cmd[3] = 0x05; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 100 break; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 101 default: | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 102 fprintf(stderr, "BUG in grcard1-set-admN command\n"); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 103 return(-1); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 104 } | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 105 cmd[4] = 18; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 106 cmd[5] = 0x03; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 107 cmd[6] = 0x00; | 
| 66 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 108 rc = decode_hex_data_from_string(argv[1], cmd + 7, 8, 8); | 
| 10 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 109 if (rc < 0) | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 110 return(rc); | 
| 66 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 111 rc = decode_hex_data_from_string(argv[2], cmd + 15, 8, 8); | 
| 10 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 112 if (rc < 0) | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 113 return(rc); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 114 rc = apdu_exchange(cmd, 23); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 115 if (rc < 0) | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 116 return(rc); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 117 if (sim_resp_sw != 0x9000) { | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 118 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 119 return(-1); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 120 } | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 121 return(0); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 122 } | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 123 | 
| 66 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 124 /* | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 125 * The command for setting Ki has been extensively exercised | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 126 * by Osmocom people, hence it is assumed to be correct. | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 127 */ | 
| 
c8e2a0e89d08
grcard1-set-admN: entry form changed from decimal to hex
 Mychaela Falconia <falcon@freecalypso.org> parents: 
10diff
changeset | 128 | 
| 10 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 129 cmd_grcard1_set_ki(argc, argv) | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 130 char **argv; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 131 { | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 132 u_char cmd[21]; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 133 int rc; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 134 | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 135 /* Grcard1 proprietary command APDU */ | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 136 cmd[0] = 0x80; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 137 cmd[1] = 0xD4; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 138 cmd[2] = 0x02; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 139 cmd[3] = 0x00; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 140 cmd[4] = 16; | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 141 rc = decode_hex_data_from_string(argv[1], cmd + 5, 16, 16); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 142 if (rc < 0) | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 143 return(rc); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 144 rc = apdu_exchange(cmd, 21); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 145 if (rc < 0) | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 146 return(rc); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 147 if (sim_resp_sw != 0x9000) { | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 148 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 149 return(-1); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 150 } | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 151 return(0); | 
| 
ddd767f6e15b
fc-simtool ported over
 Mychaela Falconia <falcon@freecalypso.org> parents: diff
changeset | 152 } | 
