1 diff -Nru openct-0.6.7/src/ifd/Makefile.am openct-0.6.7-rfid/src/ifd/Makefile.am
2 --- openct-0.6.7/src/ifd/Makefile.am 2006-04-21 08:37:58.000000000 +0200
3 +++ openct-0.6.7-rfid/src/ifd/Makefile.am 2006-05-27 19:32:21.000000000 +0200
7 proto-gbp.c proto-sync.c proto-t0.c proto-t1.c \
9 + proto-trans.c proto-escape.c \
11 sys-sunray.c sys-solaris.c sys-bsd.c sys-linux.c sys-null.c sys-osx.c \
13 diff -Nru openct-0.6.7/src/ifd/ifd-ccid.c openct-0.6.7-rfid/src/ifd/ifd-ccid.c
14 --- openct-0.6.7/src/ifd/ifd-ccid.c 2006-04-24 21:52:03.000000000 +0200
15 +++ openct-0.6.7-rfid/src/ifd/ifd-ccid.c 2006-05-27 19:46:29.000000000 +0200
18 * 2005-04-20: Harald Welte <laforge@gnumonks.org>
19 * Add support for PCMCIA based CCID Device (CardMan 4040)
21 + * 2005-05-22: Harald Welte <laforge@gnumonks.org>
22 + * Add suport for OmniKey Cardman 5121 RFID extensions
28 #define SUPPORT_T0 0x1
29 #define SUPPORT_T1 0x2
30 +#define SUPPORT_ESCAPE 0x80
35 st->reader_type = TYPE_TPDU;
38 + if (de.idVendor == 0x076b && de.idProduct == 0x5121) {
39 + /* special handling of RFID part of OmniKey 5121 */
40 + reader->nslots++; /* one virtual slot for RFID escape */
41 + st->proto_support |= SUPPORT_ESCAPE;
51 + if (st->proto_support & SUPPORT_ESCAPE
52 + && slot == reader->nslots-1) {
53 + ifd_debug(1, "virtual escape slot, setting card present\n");
54 + *status = IFD_CARD_PRESENT;
65 +static int ccid_set_protocol(ifd_reader_t *reader, int s, int proto);
71 if (!(status & IFD_CARD_PRESENT))
72 return IFD_ERROR_NO_CARD;
74 + if (st->proto_support & SUPPORT_ESCAPE
75 + && slot == reader->nslots-1) {
76 + ifd_debug(1, "slot: %d, setting atr to 0xff", slot);
77 + *((char *)atr) = 0xff;
78 + ccid_set_protocol(reader, slot, IFD_PROTOCOL_ESCAPE);
85 ifd_atr_info_t atr_info;
88 + slot = &reader->slot[s];
90 + /* If we support RFID escaping, we only allow ESCAPE protocol
91 + * at the last (== virtual) slot */
92 + if ((st->proto_support & SUPPORT_ESCAPE)
93 + && (proto != IFD_PROTOCOL_ESCAPE)
94 + && (s == reader->nslots-1)) {
95 + ct_error("reader doesn't support this protocol at this slot\n");
96 + return IFD_ERROR_NOT_SUPPORTED;
100 case IFD_PROTOCOL_T0:
101 if (!(st->proto_support & SUPPORT_T0)) {
102 @@ -953,13 +990,36 @@
103 return IFD_ERROR_NOT_SUPPORTED;
106 + case IFD_PROTOCOL_ESCAPE:
107 + /* virtual "escape" fallthrough protocol for stacking RFID
108 + * protocol stack on top of openct */
109 + if (!(st->proto_support & SUPPORT_ESCAPE)) {
110 + ct_error("reader does not support this protocol");
111 + return IFD_ERROR_NOT_SUPPORTED;
113 + if (s != reader->nslots-1) {
114 + ct_error("reader doesn't support this protocol at this slot");
115 + return IFD_ERROR_NOT_SUPPORTED;
117 + p = ifd_protocol_new(IFD_PROTOCOL_ESCAPE,reader, slot->dad);
119 + ct_error("%s: internal error", reader->name);
123 + ifd_protocol_free(slot->proto);
124 + slot->proto = NULL;
127 + st->icc_proto[s] = proto;
128 + ifd_debug(1, "set protocol to ESCAPE\n");
132 ct_error("protocol unknown");
133 return IFD_ERROR_NOT_SUPPORTED;
136 - slot = &reader->slot[s];
138 if (st->reader_type == TYPE_APDU) {
139 p = ifd_protocol_new(IFD_PROTOCOL_TRANSPARENT,
141 @@ -1103,6 +1163,27 @@
145 +static int ccid_escape(ifd_reader_t *reader, int slot, void *sbuf,
146 + size_t slen, void *rbuf, size_t rlen)
148 + unsigned char sendbuf[CCID_MAX_MSG_LEN];
149 + unsigned char recvbuf[CCID_MAX_MSG_LEN];
152 + ifd_debug(1, "slot: %d, slen %d, rlen %d", slot, slen, rlen);
154 + r = ccid_prepare_cmd(reader, sendbuf, sizeof(sendbuf), slot,
155 + CCID_CMD_ESCAPE, NULL, sbuf, slen);
159 + r = ccid_command(reader, &sendbuf[0], r, recvbuf, sizeof(recvbuf));
163 + return ccid_extract_data(&recvbuf, r, rbuf, rlen);
167 ccid_transparent(ifd_reader_t * reader, int slot,
168 const void *sbuf, size_t slen, void *rbuf, size_t rlen)
169 @@ -1177,6 +1258,7 @@
170 ccid_driver.transparent = ccid_transparent;
171 ccid_driver.send = ccid_send;
172 ccid_driver.recv = ccid_recv;
173 + ccid_driver.escape = ccid_escape;
175 ifd_driver_register("ccid", &ccid_driver);
177 diff -Nru openct-0.6.7/src/ifd/init.c openct-0.6.7-rfid/src/ifd/init.c
178 --- openct-0.6.7/src/ifd/init.c 2006-04-21 08:37:58.000000000 +0200
179 +++ openct-0.6.7-rfid/src/ifd/init.c 2006-05-27 19:32:21.000000000 +0200
181 ifd_protocol_register(&ifd_protocol_2wire);
182 ifd_protocol_register(&ifd_protocol_3wire);
183 ifd_protocol_register(&ifd_protocol_eurochip);
184 + ifd_protocol_register(&ifd_protocol_esc);
186 if (ifd_conf_get_integer("debug", &ival) >= 0 && ival > ct_config.debug)
187 ct_config.debug = ival;
188 diff -Nru openct-0.6.7/src/ifd/internal.h openct-0.6.7-rfid/src/ifd/internal.h
189 --- openct-0.6.7/src/ifd/internal.h 2006-04-21 08:37:58.000000000 +0200
190 +++ openct-0.6.7-rfid/src/ifd/internal.h 2006-05-27 19:32:21.000000000 +0200
192 extern struct ifd_protocol_ops ifd_protocol_2wire;
193 extern struct ifd_protocol_ops ifd_protocol_3wire;
194 extern struct ifd_protocol_ops ifd_protocol_eurochip;
195 +extern struct ifd_protocol_ops ifd_protocol_esc;
197 extern void ifd_acr30u_register(void);
198 extern void ifd_cardman_register(void);
199 diff -Nru openct-0.6.7/src/ifd/proto-escape.c openct-0.6.7-rfid/src/ifd/proto-escape.c
200 --- openct-0.6.7/src/ifd/proto-escape.c 1970-01-01 01:00:00.000000000 +0100
201 +++ openct-0.6.7-rfid/src/ifd/proto-escape.c 2006-05-27 19:32:21.000000000 +0200
204 + * Escape protocol - simply pass everything to the reader driver's escape()
206 + * This is required for exporting access to vendor-specific CCID extensions,
207 + * such as the Omnikey CardMan 5121 RFID support.
209 + * The higher-level applications select a virtual slot (the last available slot
210 + * number). This virtual slot will automatically get the IFD_PROTOCOL_ESCAPE
211 + * assgigned to it and can then be used to transceive() data to/from the CCID.
213 + * It's a bit ugly, but I was unable to come up with something cleaner.
215 + * Copyright (C) 2005, Harald Welte <laforge@gnumonks.org>
218 +#include "internal.h"
224 +escape_init(ifd_protocol_t *prot)
226 + ifd_reader_t *reader = prot->reader;
227 + const ifd_driver_t *drv;
229 + if (!reader || !(drv = reader->driver)
230 + || !drv->ops || !drv->ops->escape)
236 +escape_release(ifd_protocol_t *prot)
242 +escape_set_param(ifd_protocol_t *prot, int type, long value)
244 + ct_error("set_pameter not supported");
249 +escape_get_param(ifd_protocol_t *prot, int type, long *result)
251 + ct_error("get_pameter not supported");
256 +escape_transceive(ifd_protocol_t *prot, int dad,
257 + const void *sbuf, size_t slen,
258 + void *rbuf, size_t rlen)
260 + ifd_reader_t *reader = prot->reader;
261 + const ifd_driver_t *drv = reader->driver;
263 + return drv->ops->escape(reader, dad, sbuf, slen, rbuf, rlen);
266 +struct ifd_protocol_ops ifd_protocol_esc = {
267 + IFD_PROTOCOL_ESCAPE, /* id */
268 + "escape", /* name */
269 + sizeof(ifd_protocol_t), /* size */
270 + escape_init, /* init */
271 + escape_release, /* release */
272 + escape_set_param, /* set_param */
273 + escape_get_param, /* get_param */
274 + NULL, /* resynchronize */
275 + escape_transceive, /* transceive */
276 + NULL, /* sync_read */
277 + NULL, /* sync_write */
280 diff -Nru openct-0.6.7/src/include/openct/driver.h openct-0.6.7-rfid/src/include/openct/driver.h
281 --- openct-0.6.7/src/include/openct/driver.h 2006-04-21 08:37:58.000000000 +0200
282 +++ openct-0.6.7-rfid/src/include/openct/driver.h 2006-05-27 19:32:21.000000000 +0200
284 int (*sync_write)(ifd_reader_t *reader, int slot, int proto,
286 const unsigned char *sbuf, size_t slen);
288 + /*Support for transparent access to "escape" */
289 + int (*escape)(ifd_reader_t *reader, int slot,
290 + void *sbuf, size_t slen,
291 + void *rbuf, size_t rlen);
294 extern void ifd_driver_register(const char *,
295 diff -Nru openct-0.6.7/src/include/openct/ifd.h openct-0.6.7-rfid/src/include/openct/ifd.h
296 --- openct-0.6.7/src/include/openct/ifd.h 2006-04-21 08:37:58.000000000 +0200
297 +++ openct-0.6.7-rfid/src/include/openct/ifd.h 2006-05-27 19:42:54.000000000 +0200
299 IFD_PROTOCOL_TLP, /* older Gemplus protocol */
300 IFD_PROTOCOL_GBP, /* Gemplus block protocol */
301 IFD_PROTOCOL_EUROCHIP, /* Eurochip Countercard */
302 + IFD_PROTOCOL_TCL, /* ISO 14443-4 T=CL */
303 + IFD_PROTOCOL_ESCAPE, /* Virtual 'escape' protocol */
304 IFD_PROTOCOL_TRANSPARENT = 128