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