FreeCalypso > hg > fc-pcsc-tools
annotate simtool/grcard2.c @ 229:ed8cb3c0d312 default tip
new README, indicating repository move
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 18:26:13 +0000 |
parents | e3059d58ec93 |
children |
rev | line source |
---|---|
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
165
8a5c132fe871
simtool/grcard2.c comment update
Mychaela Falconia <falcon@freecalypso.org>
parents:
74
diff
changeset
|
2 * This module implements special commands for the grcard.cn card model |
8a5c132fe871
simtool/grcard2.c comment update
Mychaela Falconia <falcon@freecalypso.org>
parents:
74
diff
changeset
|
3 * which is known in the Osmocom community as GrcardSIM2: |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * https://osmocom.org/projects/cellular-infrastructure/wiki/GrcardSIM2 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * |
165
8a5c132fe871
simtool/grcard2.c comment update
Mychaela Falconia <falcon@freecalypso.org>
parents:
74
diff
changeset
|
7 * The sample cards which Mother Mychaela received from Grcard in 2021-02 |
8a5c132fe871
simtool/grcard2.c comment update
Mychaela Falconia <falcon@freecalypso.org>
parents:
74
diff
changeset
|
8 * are GrcardSIM2, and so are historical sysmoSIM-GR2 and 30C3 cards. |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 */ |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <sys/types.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdio.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "simresp.h" |
220
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
14 #include "curfile.h" |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
15 #include "file_id.h" |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 cmd_grcard2_set_pin(argc, argv) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 char **argv; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 u_char cmd[13]; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 int rc; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 /* Grcard2 proprietary command APDU */ |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 cmd[0] = 0xA0; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 cmd[1] = 0xD4; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 cmd[2] = 0x3A; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 switch (argv[0][15]) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 case '1': |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 cmd[3] = 0x01; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 break; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 case '2': |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 cmd[3] = 0x02; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 break; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 default: |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fprintf(stderr, "BUG in grcard2-set-pinN command\n"); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 cmd[4] = 8; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 rc = encode_pin_entry(argv[1], cmd + 5); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 rc = apdu_exchange(cmd, 13); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (sim_resp_sw != 0x9000) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return(0); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 cmd_grcard2_set_puk(argc, argv) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 char **argv; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 u_char cmd[13]; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 int rc; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 /* Grcard2 proprietary command APDU */ |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 cmd[0] = 0xA0; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 cmd[1] = 0xD4; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 cmd[2] = 0x3B; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 switch (argv[0][15]) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 case '1': |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 cmd[3] = 0x00; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 break; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 case '2': |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 cmd[3] = 0x02; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 break; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 default: |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 fprintf(stderr, "BUG in grcard2-set-pukN command\n"); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 cmd[4] = 8; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 rc = encode_pin_entry(argv[1], cmd + 5); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 rc = apdu_exchange(cmd, 13); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 if (sim_resp_sw != 0x9000) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 return(0); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 |
187
36e7fc58f065
GrcardSIM2 ADM5 setting command is now grcard2-set-adm5
Mychaela Falconia <falcon@freecalypso.org>
parents:
165
diff
changeset
|
87 cmd_grcard2_set_adm5(argc, argv) |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 char **argv; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 u_char cmd[13]; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 int rc; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 /* Grcard2 proprietary command APDU */ |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 cmd[0] = 0xA0; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 cmd[1] = 0xD4; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 cmd[2] = 0x3A; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 cmd[3] = 0x05; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 cmd[4] = 8; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 rc = encode_pin_entry(argv[1], cmd + 5); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 rc = apdu_exchange(cmd, 13); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 if (sim_resp_sw != 0x9000) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 return(0); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 |
187
36e7fc58f065
GrcardSIM2 ADM5 setting command is now grcard2-set-adm5
Mychaela Falconia <falcon@freecalypso.org>
parents:
165
diff
changeset
|
112 cmd_grcard2_set_adm5_hex(argc, argv) |
74
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
113 char **argv; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
114 { |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
115 u_char cmd[13]; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
116 int rc; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
117 |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
118 /* Grcard2 proprietary command APDU */ |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
119 cmd[0] = 0xA0; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
120 cmd[1] = 0xD4; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
121 cmd[2] = 0x3A; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
122 cmd[3] = 0x05; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
123 cmd[4] = 8; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
124 rc = decode_hex_data_from_string(argv[1], cmd + 5, 8, 8); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
125 if (rc < 0) |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
126 return(rc); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
127 rc = apdu_exchange(cmd, 13); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
128 if (rc < 0) |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
129 return(rc); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
130 if (sim_resp_sw != 0x9000) { |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
131 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
132 return(-1); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
133 } |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
134 return(0); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
135 } |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
136 |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 cmd_grcard2_set_super(argc, argv) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 char **argv; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 u_char cmd[13]; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 int rc; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 /* Grcard2 proprietary command APDU */ |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 cmd[0] = 0xA0; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 cmd[1] = 0xD4; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 cmd[2] = 0x3A; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 cmd[3] = 0x0B; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 cmd[4] = 8; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 rc = encode_pin_entry(argv[1], cmd + 5); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 rc = apdu_exchange(cmd, 13); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 if (sim_resp_sw != 0x9000) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 return(0); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 } |
74
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
161 |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
162 cmd_grcard2_set_super_hex(argc, argv) |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
163 char **argv; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
164 { |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
165 u_char cmd[13]; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
166 int rc; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
167 |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
168 /* Grcard2 proprietary command APDU */ |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
169 cmd[0] = 0xA0; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
170 cmd[1] = 0xD4; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
171 cmd[2] = 0x3A; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
172 cmd[3] = 0x0B; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
173 cmd[4] = 8; |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
174 rc = decode_hex_data_from_string(argv[1], cmd + 5, 8, 8); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
175 if (rc < 0) |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
176 return(rc); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
177 rc = apdu_exchange(cmd, 13); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
178 if (rc < 0) |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
179 return(rc); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
180 if (sim_resp_sw != 0x9000) { |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
181 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
182 return(-1); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
183 } |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
184 return(0); |
8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
185 } |
220
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
186 |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
187 static |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
188 select_ef_weki() |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
189 { |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
190 int rc; |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
191 |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
192 rc = select_op(DF_GSM); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
193 if (rc < 0) |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
194 return(rc); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
195 rc = select_op(0x0001); /* proprietary EF */ |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
196 if (rc < 0) |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
197 return(rc); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
198 rc = parse_ef_select_response(); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
199 if (rc < 0) |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
200 return(rc); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
201 if (curfile_structure != 0x00 || curfile_total_size != 35) { |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
202 fprintf(stderr, |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
203 "error: EF_WEKI is not a transparent EF of 35 bytes\n"); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
204 return(-1); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
205 } |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
206 return(0); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
207 } |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
208 |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
209 cmd_grcard2_set_comp128(argc, argv) |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
210 char **argv; |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
211 { |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
212 int rc; |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
213 unsigned code; |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
214 u_char magic_byte; |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
215 |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
216 if (argv[1][0] < '1' || argv[1][0] > '3' || argv[1][1]) { |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
217 fprintf(stderr, "error: invalid argument\n"); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
218 return(-1); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
219 } |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
220 code = argv[1][0] - '1'; |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
221 rc = select_ef_weki(); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
222 if (rc < 0) |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
223 return(rc); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
224 rc = readbin_op(2, 1); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
225 if (rc < 0) |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
226 return(rc); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
227 magic_byte = sim_resp_data[0]; |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
228 magic_byte &= 0xFC; |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
229 magic_byte |= code; |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
230 return update_bin_op(2, &magic_byte, 1); |
e07de8a9cedf
fc-simtool grcard2-set-comp128 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
187
diff
changeset
|
231 } |
221
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
232 |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
233 cmd_grcard2_set_ki(argc, argv) |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
234 char **argv; |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
235 { |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
236 u_char ki[16]; |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
237 int rc; |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
238 |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
239 rc = decode_hex_data_from_string(argv[1], ki, 16, 16); |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
240 if (rc < 0) |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
241 return(rc); |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
242 rc = select_ef_weki(); |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
243 if (rc < 0) |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
244 return(rc); |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
245 return update_bin_op(3, ki, 16); |
e3059d58ec93
fc-simtool grcard2-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
220
diff
changeset
|
246 } |