1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
diff -Nru openct-0.6.7/src/ifd/Makefile.am openct-0.6.7-rfid/src/ifd/Makefile.am
--- openct-0.6.7/src/ifd/Makefile.am 2006-04-21 08:37:58.000000000 +0200
+++ openct-0.6.7-rfid/src/ifd/Makefile.am 2006-05-27 19:32:21.000000000 +0200
@@ -20,7 +20,7 @@
ifd-wbeiuu.c \
\
proto-gbp.c proto-sync.c proto-t0.c proto-t1.c \
- proto-trans.c \
+ proto-trans.c proto-escape.c \
\
sys-sunray.c sys-solaris.c sys-bsd.c sys-linux.c sys-null.c sys-osx.c \
\
diff -Nru openct-0.6.7/src/ifd/ifd-ccid.c openct-0.6.7-rfid/src/ifd/ifd-ccid.c
--- openct-0.6.7/src/ifd/ifd-ccid.c 2006-04-24 21:52:03.000000000 +0200
+++ openct-0.6.7-rfid/src/ifd/ifd-ccid.c 2006-05-27 19:46:29.000000000 +0200
@@ -5,6 +5,9 @@
*
* 2005-04-20: Harald Welte <laforge@gnumonks.org>
* Add support for PCMCIA based CCID Device (CardMan 4040)
+ *
+ * 2005-05-22: Harald Welte <laforge@gnumonks.org>
+ * Add suport for OmniKey Cardman 5121 RFID extensions
*/
#include "internal.h"
@@ -122,6 +125,7 @@
#define SUPPORT_T0 0x1
#define SUPPORT_T1 0x2
+#define SUPPORT_ESCAPE 0x80
#define SUPPORT_50V 1
#define SUPPORT_33V 2
@@ -740,6 +744,12 @@
st->reader_type = TYPE_TPDU;
}
+ if (de.idVendor == 0x076b && de.idProduct == 0x5121) {
+ /* special handling of RFID part of OmniKey 5121 */
+ reader->nslots++; /* one virtual slot for RFID escape */
+ st->proto_support |= SUPPORT_ESCAPE;
+ }
+
return 0;
}
@@ -816,6 +826,13 @@
int any = 0;
int i, j, bits, stat;
+ if (st->proto_support & SUPPORT_ESCAPE
+ && slot == reader->nslots-1) {
+ ifd_debug(1, "virtual escape slot, setting card present\n");
+ *status = IFD_CARD_PRESENT;
+ return 0;
+ }
+
i = 1 + (slot / 4);
j = 2 * (slot % 4);
stat = 0;
@@ -880,6 +897,8 @@
return 0;
}
+static int ccid_set_protocol(ifd_reader_t *reader, int s, int proto);
+
/*
* Reset
*/
@@ -898,6 +917,13 @@
if (!(status & IFD_CARD_PRESENT))
return IFD_ERROR_NO_CARD;
+ if (st->proto_support & SUPPORT_ESCAPE
+ && slot == reader->nslots-1) {
+ ifd_debug(1, "slot: %d, setting atr to 0xff", slot);
+ *((char *)atr) = 0xff;
+ ccid_set_protocol(reader, slot, IFD_PROTOCOL_ESCAPE);
+ return 1;
+ }
memset(ctlbuf, 0, 3);
n = -1;
@@ -940,6 +966,17 @@
ifd_atr_info_t atr_info;
int r;
+ slot = &reader->slot[s];
+
+ /* If we support RFID escaping, we only allow ESCAPE protocol
+ * at the last (== virtual) slot */
+ if ((st->proto_support & SUPPORT_ESCAPE)
+ && (proto != IFD_PROTOCOL_ESCAPE)
+ && (s == reader->nslots-1)) {
+ ct_error("reader doesn't support this protocol at this slot\n");
+ return IFD_ERROR_NOT_SUPPORTED;
+ }
+
switch (proto) {
case IFD_PROTOCOL_T0:
if (!(st->proto_support & SUPPORT_T0)) {
@@ -953,13 +990,36 @@
return IFD_ERROR_NOT_SUPPORTED;
}
break;
+ case IFD_PROTOCOL_ESCAPE:
+ /* virtual "escape" fallthrough protocol for stacking RFID
+ * protocol stack on top of openct */
+ if (!(st->proto_support & SUPPORT_ESCAPE)) {
+ ct_error("reader does not support this protocol");
+ return IFD_ERROR_NOT_SUPPORTED;
+ }
+ if (s != reader->nslots-1) {
+ ct_error("reader doesn't support this protocol at this slot");
+ return IFD_ERROR_NOT_SUPPORTED;
+ }
+ p = ifd_protocol_new(IFD_PROTOCOL_ESCAPE,reader, slot->dad);
+ if (!p) {
+ ct_error("%s: internal error", reader->name);
+ return -1;
+ }
+ if (slot->proto) {
+ ifd_protocol_free(slot->proto);
+ slot->proto = NULL;
+ }
+ slot->proto = p;
+ st->icc_proto[s] = proto;
+ ifd_debug(1, "set protocol to ESCAPE\n");
+ return 0;
+ break;
default:
ct_error("protocol unknown");
return IFD_ERROR_NOT_SUPPORTED;
}
- slot = &reader->slot[s];
-
if (st->reader_type == TYPE_APDU) {
p = ifd_protocol_new(IFD_PROTOCOL_TRANSPARENT,
reader, slot->dad);
@@ -1103,6 +1163,27 @@
return 0;
}
+static int ccid_escape(ifd_reader_t *reader, int slot, void *sbuf,
+ size_t slen, void *rbuf, size_t rlen)
+{
+ unsigned char sendbuf[CCID_MAX_MSG_LEN];
+ unsigned char recvbuf[CCID_MAX_MSG_LEN];
+ int r;
+
+ ifd_debug(1, "slot: %d, slen %d, rlen %d", slot, slen, rlen);
+
+ r = ccid_prepare_cmd(reader, sendbuf, sizeof(sendbuf), slot,
+ CCID_CMD_ESCAPE, NULL, sbuf, slen);
+ if (r < 0)
+ return r;
+
+ r = ccid_command(reader, &sendbuf[0], r, recvbuf, sizeof(recvbuf));
+ if (r < 0)
+ return r;
+
+ return ccid_extract_data(&recvbuf, r, rbuf, rlen);
+}
+
static int
ccid_transparent(ifd_reader_t * reader, int slot,
const void *sbuf, size_t slen, void *rbuf, size_t rlen)
@@ -1177,6 +1258,7 @@
ccid_driver.transparent = ccid_transparent;
ccid_driver.send = ccid_send;
ccid_driver.recv = ccid_recv;
+ ccid_driver.escape = ccid_escape;
ifd_driver_register("ccid", &ccid_driver);
}
diff -Nru openct-0.6.7/src/ifd/init.c openct-0.6.7-rfid/src/ifd/init.c
--- openct-0.6.7/src/ifd/init.c 2006-04-21 08:37:58.000000000 +0200
+++ openct-0.6.7-rfid/src/ifd/init.c 2006-05-27 19:32:21.000000000 +0200
@@ -54,6 +54,7 @@
ifd_protocol_register(&ifd_protocol_2wire);
ifd_protocol_register(&ifd_protocol_3wire);
ifd_protocol_register(&ifd_protocol_eurochip);
+ ifd_protocol_register(&ifd_protocol_esc);
if (ifd_conf_get_integer("debug", &ival) >= 0 && ival > ct_config.debug)
ct_config.debug = ival;
diff -Nru openct-0.6.7/src/ifd/internal.h openct-0.6.7-rfid/src/ifd/internal.h
--- openct-0.6.7/src/ifd/internal.h 2006-04-21 08:37:58.000000000 +0200
+++ openct-0.6.7-rfid/src/ifd/internal.h 2006-05-27 19:32:21.000000000 +0200
@@ -118,6 +118,7 @@
extern struct ifd_protocol_ops ifd_protocol_2wire;
extern struct ifd_protocol_ops ifd_protocol_3wire;
extern struct ifd_protocol_ops ifd_protocol_eurochip;
+extern struct ifd_protocol_ops ifd_protocol_esc;
extern void ifd_acr30u_register(void);
extern void ifd_cardman_register(void);
diff -Nru openct-0.6.7/src/ifd/proto-escape.c openct-0.6.7-rfid/src/ifd/proto-escape.c
--- openct-0.6.7/src/ifd/proto-escape.c 1970-01-01 01:00:00.000000000 +0100
+++ openct-0.6.7-rfid/src/ifd/proto-escape.c 2006-05-27 19:32:21.000000000 +0200
@@ -0,0 +1,77 @@
+/*
+ * Escape protocol - simply pass everything to the reader driver's escape()
+ *
+ * This is required for exporting access to vendor-specific CCID extensions,
+ * such as the Omnikey CardMan 5121 RFID support.
+ *
+ * The higher-level applications select a virtual slot (the last available slot
+ * number). This virtual slot will automatically get the IFD_PROTOCOL_ESCAPE
+ * assgigned to it and can then be used to transceive() data to/from the CCID.
+ *
+ * It's a bit ugly, but I was unable to come up with something cleaner.
+ *
+ * Copyright (C) 2005, Harald Welte <laforge@gnumonks.org>
+ */
+
+#include "internal.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int
+escape_init(ifd_protocol_t *prot)
+{
+ ifd_reader_t *reader = prot->reader;
+ const ifd_driver_t *drv;
+
+ if (!reader || !(drv = reader->driver)
+ || !drv->ops || !drv->ops->escape)
+ return -1;
+ return 0;
+}
+
+static void
+escape_release(ifd_protocol_t *prot)
+{
+ /* NOP */
+}
+
+static int
+escape_set_param(ifd_protocol_t *prot, int type, long value)
+{
+ ct_error("set_pameter not supported");
+ return -1;
+}
+
+static int
+escape_get_param(ifd_protocol_t *prot, int type, long *result)
+{
+ ct_error("get_pameter not supported");
+ return -1;
+}
+
+static int
+escape_transceive(ifd_protocol_t *prot, int dad,
+ const void *sbuf, size_t slen,
+ void *rbuf, size_t rlen)
+{
+ ifd_reader_t *reader = prot->reader;
+ const ifd_driver_t *drv = reader->driver;
+
+ return drv->ops->escape(reader, dad, sbuf, slen, rbuf, rlen);
+}
+
+struct ifd_protocol_ops ifd_protocol_esc = {
+ IFD_PROTOCOL_ESCAPE, /* id */
+ "escape", /* name */
+ sizeof(ifd_protocol_t), /* size */
+ escape_init, /* init */
+ escape_release, /* release */
+ escape_set_param, /* set_param */
+ escape_get_param, /* get_param */
+ NULL, /* resynchronize */
+ escape_transceive, /* transceive */
+ NULL, /* sync_read */
+ NULL, /* sync_write */
+};
+
diff -Nru openct-0.6.7/src/include/openct/driver.h openct-0.6.7-rfid/src/include/openct/driver.h
--- openct-0.6.7/src/include/openct/driver.h 2006-04-21 08:37:58.000000000 +0200
+++ openct-0.6.7-rfid/src/include/openct/driver.h 2006-05-27 19:32:21.000000000 +0200
@@ -318,6 +318,11 @@
int (*sync_write)(ifd_reader_t *reader, int slot, int proto,
unsigned short addr,
const unsigned char *sbuf, size_t slen);
+
+ /*Support for transparent access to "escape" */
+ int (*escape)(ifd_reader_t *reader, int slot,
+ void *sbuf, size_t slen,
+ void *rbuf, size_t rlen);
};
extern void ifd_driver_register(const char *,
diff -Nru openct-0.6.7/src/include/openct/ifd.h openct-0.6.7-rfid/src/include/openct/ifd.h
--- openct-0.6.7/src/include/openct/ifd.h 2006-04-21 08:37:58.000000000 +0200
+++ openct-0.6.7-rfid/src/include/openct/ifd.h 2006-05-27 19:42:54.000000000 +0200
@@ -29,6 +29,8 @@
IFD_PROTOCOL_TLP, /* older Gemplus protocol */
IFD_PROTOCOL_GBP, /* Gemplus block protocol */
IFD_PROTOCOL_EUROCHIP, /* Eurochip Countercard */
+ IFD_PROTOCOL_TCL, /* ISO 14443-4 T=CL */
+ IFD_PROTOCOL_ESCAPE, /* Virtual 'escape' protocol */
IFD_PROTOCOL_TRANSPARENT = 128
};
|