FreeCalypso > hg > fc-sim-tools
annotate simtool/chvfunc.c @ 53:fbedb67d234f
serial: fix parity for inverse coding convention
Important note: it is my (Mother Mychaela's) understanding that
SIM cards with inverse coding convention are extremely rare,
and I have never seen such a card. Therefore, our support for
the inverse coding convention will likely remain forever untested.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 21 Mar 2021 20:46:09 +0000 |
parents | c83ec3bd9d67 |
children |
rev | line source |
---|---|
31
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements a functional interface to CHV commands, |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * intended for high-level wrappers like sws-*. |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "simresp.h" |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 verify_chv_func(p2, pin) |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 unsigned p2; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 char *pin; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 { |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 u_char cmd[13]; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int rc; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 /* VERIFY CHV command APDU */ |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 cmd[0] = 0xA0; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 cmd[1] = 0x20; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 cmd[2] = 0x00; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 cmd[3] = p2; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 cmd[4] = 8; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 rc = encode_pin_entry(pin, cmd + 5); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (rc < 0) |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 return(rc); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 rc = apdu_exchange(cmd, 13); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (rc < 0) |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(rc); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (sim_resp_sw != 0x9000) { |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 fprintf(stderr, "bad SW response to VERIFY CHV: %04X\n", |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 sim_resp_sw); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return(-1); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(0); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
33
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
36 |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
37 disable_chv_func(p2, pin) |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
38 unsigned p2; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
39 char *pin; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
40 { |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
41 u_char cmd[13]; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
42 int rc; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
43 |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
44 /* DISABLE CHV command APDU */ |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
45 cmd[0] = 0xA0; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
46 cmd[1] = 0x26; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
47 cmd[2] = 0x00; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
48 cmd[3] = p2; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
49 cmd[4] = 8; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
50 rc = encode_pin_entry(pin, cmd + 5); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
51 if (rc < 0) |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
52 return(rc); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
53 rc = apdu_exchange(cmd, 13); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
54 if (rc < 0) |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
55 return(rc); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
56 if (sim_resp_sw != 0x9000 && sim_resp_sw != 0x9808) { |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
57 fprintf(stderr, "bad SW response to DISABLE CHV: %04X\n", |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
58 sim_resp_sw); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
59 return(-1); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
60 } |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
61 return(0); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
62 } |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
63 |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
64 enable_chv_func(p2, pin) |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
65 unsigned p2; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
66 char *pin; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
67 { |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
68 u_char cmd[13]; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
69 int rc; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
70 |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
71 /* ENABLE CHV command APDU */ |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
72 cmd[0] = 0xA0; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
73 cmd[1] = 0x28; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
74 cmd[2] = 0x00; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
75 cmd[3] = p2; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
76 cmd[4] = 8; |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
77 rc = encode_pin_entry(pin, cmd + 5); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
78 if (rc < 0) |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
79 return(rc); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
80 rc = apdu_exchange(cmd, 13); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
81 if (rc < 0) |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
82 return(rc); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
83 if (sim_resp_sw != 0x9000 && sim_resp_sw != 0x9808) { |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
84 fprintf(stderr, "bad SW response to ENABLE CHV: %04X\n", |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
85 sim_resp_sw); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
86 return(-1); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
87 } |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
88 return(0); |
c83ec3bd9d67
fc-simtool sws-pin1-{dis,en}able implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
89 } |