summaryrefslogtreecommitdiff
path: root/src/rfid_reader_cm5121_openct.c
diff options
context:
space:
mode:
authorlaforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede>2005-11-08 08:34:15 +0000
committerlaforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede>2005-11-08 08:34:15 +0000
commit05c7e304271bcf88901da3782fcd3f28a0c7c9cf (patch)
treec7972af3be2f8a6619af551faa980cd699399b1e /src/rfid_reader_cm5121_openct.c
parentea11c6e508eb88d18847f4027bbc0a5ced0200b3 (diff)
use autoconf/automake
git-svn-id: https://svn.gnumonks.org/trunk/librfid@1658 e0336214-984f-0b4b-a45f-81c69e1f0ede
Diffstat (limited to 'src/rfid_reader_cm5121_openct.c')
-rw-r--r--src/rfid_reader_cm5121_openct.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/rfid_reader_cm5121_openct.c b/src/rfid_reader_cm5121_openct.c
new file mode 100644
index 0000000..9d96638
--- /dev/null
+++ b/src/rfid_reader_cm5121_openct.c
@@ -0,0 +1,59 @@
+/* CM5121 backend for OpenCT virtual slot */
+
+#include <stdio.h>
+
+#include <rfid/rfid_asic.h>
+#include <openct/openct.h>
+
+/* FIXME: get rid of this global crap. In fact this needs to become part of
+ * struct rfid_reader_handle */
+static ct_lock_handle lock;
+static int slot = 1;
+
+/* this is the sole function required by rfid_reader_cm5121.c */
+int
+PC_to_RDR_Escape(void *handle,
+ const unsigned char *tx_buf, unsigned int tx_len,
+ unsigned char *rx_buf, unsigned int *rx_len)
+{
+ int rc;
+ ct_handle *h = (ct_handle *) handle;
+
+ rc = ct_card_transact(h, 1, tx_buf, tx_len, rx_buf, *rx_len);
+ if (rc >= 0) {
+ *rx_len = rc;
+ return 0;
+ }
+
+ return rc;
+}
+
+
+int cm5121_source_init(struct rfid_asic_transport_handle *rath)
+{
+ struct ct_handle *h;
+ int rc;
+ unsigned char atr[64];
+
+ h = ct_reader_connect(0);
+ if (!h)
+ return -1;
+
+ printf("acquiring card lock\n");
+ rc = ct_card_lock(h, slot, IFD_LOCK_EXCLUSIVE, &lock);
+ if (rc < 0) {
+ fprintf(stderr, "error, no card lock\n");
+ return -1;
+ }
+
+ rc = ct_card_reset(h, slot, atr, sizeof(atr));
+ if (rc < 0) {
+ fprintf(stderr, "error, can't reset virtual card\n");
+ return -1;
+ }
+
+ rath->data = h;
+
+ return 0;
+}
+
personal git repositories of Harald Welte. Your mileage may vary