a88bd0b3838e1fd2aed822e808f4874e75c74fce
[librfid] / rfid_reader_cm5121_ccid_direct.c
1 /* CM5121 backend for 'internal' CCID driver */
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <stdio.h>
5
6 #include <rfid/rfid_asic.h>
7
8 #include "ccid/ccid-driver.h"
9
10 /* FIXME: remove ugly global variables */
11 static ccid_driver_t h;
12
13 /* this is the sole function required by rfid_reader_cm5121.c */
14 int 
15 PC_to_RDR_Escape(void *handle, 
16                  const unsigned char *tx_buf, unsigned int tx_len,
17                  unsigned char *rx_buf, unsigned int *rx_len)
18 {
19         int rc;
20         ccid_driver_t ch = handle;
21         size_t maxrxlen = *rx_len;
22
23         rc = ccid_transceive_escape (ch, tx_buf, tx_len,
24                                      rx_buf, maxrxlen, rx_len);
25
26         return rc;
27 }
28
29 int cm5121_source_init(struct rfid_asic_transport_handle *rath)
30 {
31         int rc;
32
33         rc = ccid_open_reader (&h, NULL);
34         if (rc) {
35                 fprintf (stderr, "failed to open CCID reader: %#x\n", rc);
36                 return -1;
37         }
38         rath->data = &h;
39         return 0;
40 }