comparison simtool/chv.c @ 10:ddd767f6e15b

fc-simtool ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 07:11:25 +0000
parents
children
comparison
equal deleted inserted replaced
9:c9ef9e91dd8e 10:ddd767f6e15b
1 /*
2 * This module implements the standard set of CHV commands
3 * for GSM 11.11 SIMs.
4 */
5
6 #include <sys/types.h>
7 #include <stdio.h>
8 #include "simresp.h"
9
10 cmd_verify_chv(argc, argv)
11 char **argv;
12 {
13 u_char cmd[13];
14 int rc;
15
16 /* VERIFY CHV command APDU */
17 cmd[0] = 0xA0;
18 cmd[1] = 0x20;
19 cmd[2] = 0x00;
20 switch (argv[0][10]) {
21 case '1':
22 cmd[3] = 0x01;
23 break;
24 case '2':
25 cmd[3] = 0x02;
26 break;
27 default:
28 fprintf(stderr, "BUG in verify-chvN command\n");
29 return(-1);
30 }
31 cmd[4] = 8;
32 rc = encode_pin_entry(argv[1], cmd + 5);
33 if (rc < 0)
34 return(rc);
35 rc = apdu_exchange(cmd, 13);
36 if (rc < 0)
37 return(rc);
38 if (sim_resp_sw != 0x9000) {
39 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
40 return(-1);
41 }
42 return(0);
43 }
44
45 cmd_change_chv(argc, argv)
46 char **argv;
47 {
48 u_char cmd[21];
49 int rc;
50
51 /* CHANGE CHV command APDU */
52 cmd[0] = 0xA0;
53 cmd[1] = 0x24;
54 cmd[2] = 0x00;
55 switch (argv[0][10]) {
56 case '1':
57 cmd[3] = 0x01;
58 break;
59 case '2':
60 cmd[3] = 0x02;
61 break;
62 default:
63 fprintf(stderr, "BUG in change-chvN command\n");
64 return(-1);
65 }
66 cmd[4] = 16;
67 rc = encode_pin_entry(argv[1], cmd + 5);
68 if (rc < 0)
69 return(rc);
70 rc = encode_pin_entry(argv[2], cmd + 13);
71 if (rc < 0)
72 return(rc);
73 rc = apdu_exchange(cmd, 21);
74 if (rc < 0)
75 return(rc);
76 if (sim_resp_sw != 0x9000) {
77 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
78 return(-1);
79 }
80 return(0);
81 }
82
83 cmd_disable_chv1(argc, argv)
84 char **argv;
85 {
86 u_char cmd[13];
87 int rc;
88
89 /* DISABLE CHV command APDU */
90 cmd[0] = 0xA0;
91 cmd[1] = 0x26;
92 cmd[2] = 0x00;
93 cmd[3] = 0x01;
94 cmd[4] = 8;
95 rc = encode_pin_entry(argv[1], cmd + 5);
96 if (rc < 0)
97 return(rc);
98 rc = apdu_exchange(cmd, 13);
99 if (rc < 0)
100 return(rc);
101 if (sim_resp_sw != 0x9000) {
102 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
103 return(-1);
104 }
105 return(0);
106 }
107
108 cmd_disable_chv1_rpt(argc, argv)
109 char **argv;
110 {
111 u_char cmd[13];
112 int rc;
113
114 /* DISABLE CHV command APDU */
115 cmd[0] = 0xA0;
116 cmd[1] = 0x26;
117 cmd[2] = 0x00;
118 cmd[3] = 0x01;
119 cmd[4] = 8;
120 rc = encode_pin_entry(argv[1], cmd + 5);
121 if (rc < 0)
122 return(rc);
123 rc = apdu_exchange(cmd, 13);
124 if (rc < 0)
125 return(rc);
126 if (sim_resp_sw != 0x9000 && sim_resp_sw != 0x9808) {
127 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
128 return(-1);
129 }
130 return(0);
131 }
132
133 cmd_enable_chv1(argc, argv)
134 char **argv;
135 {
136 u_char cmd[13];
137 int rc;
138
139 /* ENABLE CHV command APDU */
140 cmd[0] = 0xA0;
141 cmd[1] = 0x28;
142 cmd[2] = 0x00;
143 cmd[3] = 0x01;
144 cmd[4] = 8;
145 rc = encode_pin_entry(argv[1], cmd + 5);
146 if (rc < 0)
147 return(rc);
148 rc = apdu_exchange(cmd, 13);
149 if (rc < 0)
150 return(rc);
151 if (sim_resp_sw != 0x9000) {
152 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
153 return(-1);
154 }
155 return(0);
156 }
157
158 cmd_enable_chv1_rpt(argc, argv)
159 char **argv;
160 {
161 u_char cmd[13];
162 int rc;
163
164 /* ENABLE CHV command APDU */
165 cmd[0] = 0xA0;
166 cmd[1] = 0x28;
167 cmd[2] = 0x00;
168 cmd[3] = 0x01;
169 cmd[4] = 8;
170 rc = encode_pin_entry(argv[1], cmd + 5);
171 if (rc < 0)
172 return(rc);
173 rc = apdu_exchange(cmd, 13);
174 if (rc < 0)
175 return(rc);
176 if (sim_resp_sw != 0x9000 && sim_resp_sw != 0x9808) {
177 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
178 return(-1);
179 }
180 return(0);
181 }
182
183 cmd_unblock_chv(argc, argv)
184 char **argv;
185 {
186 u_char cmd[21];
187 int rc;
188
189 /* UNBLOCK CHV command APDU */
190 cmd[0] = 0xA0;
191 cmd[1] = 0x2C;
192 cmd[2] = 0x00;
193 switch (argv[0][11]) {
194 case '1':
195 cmd[3] = 0x00;
196 break;
197 case '2':
198 cmd[3] = 0x02;
199 break;
200 default:
201 fprintf(stderr, "BUG in unblock-chvN command\n");
202 return(-1);
203 }
204 cmd[4] = 16;
205 rc = encode_pin_entry(argv[1], cmd + 5);
206 if (rc < 0)
207 return(rc);
208 rc = encode_pin_entry(argv[2], cmd + 13);
209 if (rc < 0)
210 return(rc);
211 rc = apdu_exchange(cmd, 21);
212 if (rc < 0)
213 return(rc);
214 if (sim_resp_sw != 0x9000) {
215 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
216 return(-1);
217 }
218 return(0);
219 }