annotate simtool/grcard1.c @ 163:5f9dd4056420

vbat-adc/crude-cal-test: an experiment to prove VBAT MADC linearity
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 04 Jun 2021 03:02:18 +0000
parents a63e4c64f1f0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
148
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements a few special commands for those very few
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * incredibly lucky people on Earth who have no-longer-available
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * sysmoSIM-GR1 cards, or any other branded variant of the same card
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * from Grcard.
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/types.h>
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <ctype.h>
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <pcsclite.h>
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <winscard.h>
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "globals.h"
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 cmd_grcard1_set_pin(argc, argv)
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 char **argv;
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 u_char cmd[21];
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int rc;
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 /* Grcard1 proprietary command APDU */
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 cmd[0] = 0x80;
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cmd[1] = 0xD4;
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 cmd[2] = 0x00;
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 switch (argv[0][15]) {
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 case '1':
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 cmd[3] = 0x01;
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 break;
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 case '2':
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 cmd[3] = 0x02;
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 break;
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 default:
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 fprintf(stderr, "BUG in grcard1-set-pinN command\n");
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(-1);
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 cmd[4] = 16;
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 rc = encode_pin_entry(argv[1], cmd + 5);
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (rc < 0)
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return(rc);
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 rc = encode_pin_entry(argv[2], cmd + 13);
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (rc < 0)
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return(rc);
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 rc = apdu_exchange(cmd, 21);
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (rc < 0)
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return(rc);
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (sim_resp_sw != 0x9000) {
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 return(-1);
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return(0);
1232dea1d66a fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
149
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
53
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
54 cmd_grcard1_set_adm(argc, argv)
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
55 char **argv;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
56 {
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
57 u_char cmd[23];
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
58 int rc;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
59
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
60 /* Grcard1 proprietary command APDU */
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
61 cmd[0] = 0x80;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
62 cmd[1] = 0xD4;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
63 cmd[2] = 0x01;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
64 switch (argv[0][15]) {
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
65 case '1':
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
66 cmd[3] = 0x04;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
67 break;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
68 case '2':
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
69 cmd[3] = 0x05;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
70 break;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
71 default:
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
72 fprintf(stderr, "BUG in grcard1-set-admN command\n");
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
73 return(-1);
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
74 }
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
75 cmd[4] = 18;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
76 cmd[5] = 0x03;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
77 cmd[6] = 0x00;
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
78 rc = encode_pin_entry(argv[1], cmd + 7);
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
79 if (rc < 0)
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
80 return(rc);
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
81 rc = encode_pin_entry(argv[2], cmd + 15);
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
82 if (rc < 0)
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
83 return(rc);
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
84 rc = apdu_exchange(cmd, 23);
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
85 if (rc < 0)
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
86 return(rc);
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
87 if (sim_resp_sw != 0x9000) {
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
88 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
89 return(-1);
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
90 }
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
91 return(0);
451ed3bbfe96 fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
92 }
153
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
93
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
94 cmd_grcard1_set_ki(argc, argv)
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
95 char **argv;
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
96 {
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
97 u_char cmd[21];
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
98 int rc;
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
99
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
100 /* Grcard1 proprietary command APDU */
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
101 cmd[0] = 0x80;
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
102 cmd[1] = 0xD4;
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
103 cmd[2] = 0x02;
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
104 cmd[3] = 0x00;
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
105 cmd[4] = 16;
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
106 rc = decode_hex_data_from_string(argv[1], cmd + 5, 16, 16);
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
107 if (rc < 0)
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
108 return(rc);
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
109 rc = apdu_exchange(cmd, 21);
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
110 if (rc < 0)
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
111 return(rc);
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
112 if (sim_resp_sw != 0x9000) {
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
113 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
114 return(-1);
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
115 }
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
116 return(0);
a63e4c64f1f0 fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 149
diff changeset
117 }