FreeCalypso > hg > fc-sim-tools
annotate serial/exchange.c @ 102:c2f18d7b0a1e
doc/Admin-write-commands: document write-hplmn-timer command
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 14 May 2022 23:20:38 +0000 |
parents | be27d1c85861 |
children |
rev | line source |
---|---|
43
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the main function of our back end: |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * exchanging APDUs with the SIM. |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 static |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 collect_one_byte() |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 u_char buf; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 int rc; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 rc = collect_bytes_from_sim(&buf, 1); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 if (rc < 0) |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 return rc; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 else |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 return buf; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 static void |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 finish_sw(sw1, data, datalen) |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 unsigned sw1, datalen; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 u_char *data; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 unsigned sw2, n; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 int rc; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 rc = collect_one_byte(); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (rc < 0) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 printf("back end error at SW2 Rx step\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 sw2 = rc; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 for (n = 0; n < datalen; n++) |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 printf("%02X", data[n]); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 printf("%02X%02X\n", sw1, sw2); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 static void |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exchange_data_out(ins, data, datalen) |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 unsigned ins, datalen; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 u_char *data; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 int rc; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 unsigned null_count, bytes_sent, ack, ack1; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 ack = ins & 0xFE; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 ack1 = ~ins & 0xFE; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 bytes_sent = 0; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 null_count = 0; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 for (;;) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 rc = collect_one_byte(); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (rc < 0) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 printf("back end error at procedure byte step\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (rc == 0x60) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 null_count++; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (null_count >= 32) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 printf( |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 "ERROR: too many stalling NULL bytes received from SIM\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 continue; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 if ((rc & 0xF0) == 0x60 || (rc & 0xF0) == 0x90) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 finish_sw(rc, 0, 0); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 if ((rc & 0xFE) == ack) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (bytes_sent >= datalen) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 bad_xfer_req: printf( |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 "ERROR: SIM requests more xfer after we sent everything\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 rc = send_bytes_to_sim(data + bytes_sent, |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 datalen - bytes_sent); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 if (rc < 0) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 printf("back end error at data output step\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 bytes_sent = datalen; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 continue; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 if ((rc & 0xFE) == ack1) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (bytes_sent >= datalen) |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 goto bad_xfer_req; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 rc = send_bytes_to_sim(data + bytes_sent, 1); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 if (rc < 0) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 printf("back end error at data output step\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 bytes_sent++; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 continue; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 printf("ERROR: non-understood procedure byte %02X\n", rc); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 static void |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 exchange_data_in(ins, datalen) |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 unsigned ins, datalen; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 int rc; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 unsigned null_count, bytes_rcvd, ack, ack1; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 u_char data[256]; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 if (!datalen) |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 datalen = 256; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 ack = ins & 0xFE; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 ack1 = ~ins & 0xFE; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 bytes_rcvd = 0; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 null_count = 0; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 for (;;) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 rc = collect_one_byte(); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 if (rc < 0) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 printf("back end error at procedure byte step\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 if (rc == 0x60) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 null_count++; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 if (null_count >= 32) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 printf( |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 "ERROR: too many stalling NULL bytes received from SIM\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 continue; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 if ((rc & 0xF0) == 0x60 || (rc & 0xF0) == 0x90) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 finish_sw(rc, data, bytes_rcvd); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if ((rc & 0xFE) == ack) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 if (bytes_rcvd >= datalen) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 bad_xfer_req: printf( |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 "ERROR: SIM requests more xfer after we received all expected data\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 rc = collect_bytes_from_sim(data + bytes_rcvd, |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 datalen - bytes_rcvd); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 if (rc < 0) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 printf("back end error at data input step\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 bytes_rcvd = datalen; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 continue; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 if ((rc & 0xFE) == ack1) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 if (bytes_rcvd >= datalen) |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 goto bad_xfer_req; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 rc = collect_one_byte(); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 if (rc < 0) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 printf("back end error at data input step\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 data[bytes_rcvd++] = rc; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 continue; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 printf("ERROR: non-understood procedure byte %02X\n", rc); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 void |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 apdu_exchange(cmd_apdu, cmd_apdu_len) |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 u_char *cmd_apdu; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 unsigned cmd_apdu_len; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 int rc; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 rc = send_bytes_to_sim(cmd_apdu, 5); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 if (rc < 0) { |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 printf("back end error at the command sending step\n"); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 return; |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 } |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 if (cmd_apdu_len > 5) |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 exchange_data_out(cmd_apdu[1], cmd_apdu + 5, cmd_apdu_len - 5); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 else |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 exchange_data_in(cmd_apdu[1], cmd_apdu[4]); |
be27d1c85861
serial: main function implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 } |