annotate simtool/chv.c @ 208:ead7e546ad75

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