annotate simtool/chv.c @ 108:6f80cfdc7e05

fc-simtool: CHV commands implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 26 Jan 2021 00:51:59 +0000
parents
children 2adb802b2a98
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 cmd_change_chv(argc, argv)
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 char **argv;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 {
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 u_char cmd[21];
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 int rc;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 /* CHANGE CHV command APDU */
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 cmd[0] = 0xA0;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 cmd[1] = 0x24;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 cmd[2] = 0x00;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 switch (argv[0][10]) {
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 case '1':
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 cmd[3] = 0x01;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 break;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 case '2':
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 cmd[3] = 0x02;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 break;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 default:
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 fprintf(stderr, "BUG in change-chvN command\n");
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 return(-1);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 }
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 cmd[4] = 16;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 rc = encode_pin_entry(argv[1], cmd + 5);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 if (rc < 0)
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 return(rc);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 rc = encode_pin_entry(argv[2], cmd + 13);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 if (rc < 0)
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 return(rc);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 rc = apdu_exchange(cmd, 21);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 if (rc < 0)
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 return(rc);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if (sim_resp_sw != 0x9000) {
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 return(-1);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 return(0);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 cmd_disable_chv(argc, argv)
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 char **argv;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 {
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 u_char cmd[13];
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 int rc;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 /* DISABLE CHV command APDU */
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 cmd[0] = 0xA0;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 cmd[1] = 0x26;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 cmd[2] = 0x00;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 cmd[3] = 0x01;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 cmd[4] = 8;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 rc = encode_pin_entry(argv[1], cmd + 5);
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, 13);
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_enable_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 /* ENABLE 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] = 0x28;
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_unblock_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[21];
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 /* UNBLOCK 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] = 0x2C;
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 switch (argv[0][11]) {
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 case '1':
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 cmd[3] = 0x00;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 break;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 case '2':
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 cmd[3] = 0x02;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 break;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 default:
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 fprintf(stderr, "BUG in unblock-chvN command\n");
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 return(-1);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 }
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 cmd[4] = 16;
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 rc = encode_pin_entry(argv[1], cmd + 5);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 if (rc < 0)
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 return(rc);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 rc = encode_pin_entry(argv[2], cmd + 13);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 if (rc < 0)
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 return(rc);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 rc = apdu_exchange(cmd, 21);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 if (rc < 0)
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 return(rc);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 if (sim_resp_sw != 0x9000) {
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 return(-1);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 }
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 return(0);
6f80cfdc7e05 fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 }