annotate simtool/chv.c @ 169:17ffa6c66951

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