summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rfid.c12
-rw-r--r--src/rfid_asic_rc632.c14
-rw-r--r--src/rfid_layer2.c26
-rw-r--r--src/rfid_layer2_iso14443a.c8
-rw-r--r--src/rfid_layer2_iso14443b.c34
-rw-r--r--src/rfid_layer2_iso15693.c10
-rw-r--r--src/rfid_proto_mifare_classic.c8
-rw-r--r--src/rfid_proto_mifare_ul.c8
-rw-r--r--src/rfid_proto_tcl.c10
-rw-r--r--src/rfid_protocol.c28
-rw-r--r--src/rfid_reader.c34
-rw-r--r--src/rfid_reader_cm5121.c18
-rw-r--r--src/rfid_reader_openpcd.c87
13 files changed, 168 insertions, 129 deletions
diff --git a/src/rfid.c b/src/rfid.c
index ba166a2..ec0ce1f 100644
--- a/src/rfid.c
+++ b/src/rfid.c
@@ -18,13 +18,19 @@
#include <string.h>
#include <librfid/rfid_reader.h>
-#include <librfid/rfid_reader_cm5121.h>
-#include <librfid/rfid_reader_openpcd.h>
#include <librfid/rfid_protocol.h>
#include <librfid/rfid_protocol_tcl.h>
#include <librfid/rfid_protocol_mifare_ul.h>
#include <librfid/rfid_protocol_mifare_classic.h>
+#ifdef LIBRFID_FIRMWARE
+struct rfid_asic_handle rfid_ah;
+struct rfid_layer2_handle rfid_l2h;
+struct rfid_protocol_handle rfid_ph;
+struct rfid_asic_transport_handle rfid_ath;
+struct rfid_reader_handle rfid_rh;
+#endif
+
const char *
rfid_hexdump(const void *data, unsigned int len)
{
@@ -92,6 +98,7 @@ int rfid_getopt(struct rfid_handle *rh, unsigned int level,
int rfid_init()
{
+#if 0
rfid_reader_register(&rfid_reader_cm5121);
rfid_reader_register(&rfid_reader_openpcd);
rfid_layer2_register(&rfid_layer2_iso14443a);
@@ -99,6 +106,7 @@ int rfid_init()
rfid_protocol_register(&rfid_protocol_tcl);
rfid_protocol_register(&rfid_protocol_mful);
rfid_protocol_register(&rfid_protocol_mfcl);
+#endif
return 0;
}
diff --git a/src/rfid_asic_rc632.c b/src/rfid_asic_rc632.c
index 05ed2cd..f8a8483 100644
--- a/src/rfid_asic_rc632.c
+++ b/src/rfid_asic_rc632.c
@@ -1,6 +1,6 @@
/* Generic Philips CL RC632 Routines
*
- * (C) Harald Welte <laforge@gnumonks.org>
+ * (C) 2005-2006 Harald Welte <laforge@gnumonks.org>
*
*/
@@ -41,7 +41,7 @@
#define RC632_TMO_AUTH1 14000
#define ENTER() DEBUGP("entering\n")
-struct rfid_asic rc632;
+const struct rfid_asic rc632;
/* Register and FIFO Access functions */
static int
@@ -596,7 +596,7 @@ rc632_open(struct rfid_asic_transport_handle *th)
{
struct rfid_asic_handle *h;
- h = malloc(sizeof(*h));
+ h = malloc_asic_handle(sizeof(*h));
if (!h)
return NULL;
memset(h, 0, sizeof(*h));
@@ -609,7 +609,7 @@ rc632_open(struct rfid_asic_transport_handle *th)
h->mtu = h->mru = 64;
if (rc632_init(h) < 0) {
- free(h);
+ free_asic_handle(h);
return NULL;
}
@@ -620,14 +620,14 @@ void
rc632_close(struct rfid_asic_handle *h)
{
rc632_fini(h);
- free(h);
+ free_asic_handle(h);
}
/*
* Philips CL RC632 primitives for ISO 14443-A compliant PICC's
*
- * (C) 2005 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
*
*/
@@ -1581,7 +1581,7 @@ rc632_mifare_transceive(struct rfid_asic_handle *handle,
return 0;
}
-struct rfid_asic rc632 = {
+const struct rfid_asic rc632 = {
.name = "Philips CL RC632",
.fc = ISO14443_FREQ_CARRIER,
.priv.rc632 = {
diff --git a/src/rfid_layer2.c b/src/rfid_layer2.c
index a6ee43f..ff6d2b0 100644
--- a/src/rfid_layer2.c
+++ b/src/rfid_layer2.c
@@ -24,19 +24,24 @@
#include <librfid/rfid.h>
#include <librfid/rfid_layer2.h>
-static struct rfid_layer2 *rfid_layer2_list;
+static const struct rfid_layer2 *rfid_layer2s[] = {
+ [RFID_LAYER2_ISO14443A] = &rfid_layer2_iso14443a,
+ [RFID_LAYER2_ISO14443B] = &rfid_layer2_iso14443b,
+ [RFID_LAYER2_ISO15693] = &rfid_layer2_iso15693,
+};
struct rfid_layer2_handle *
rfid_layer2_init(struct rfid_reader_handle *rh, unsigned int id)
{
struct rfid_layer2 *p;
- for (p = rfid_layer2_list; p; p = p->next)
- if (p->id == id)
- return p->fn.init(rh);
+ if (id >= ARRAY_SIZE(rfid_layer2s)) {
+ DEBUGP("unable to find matching layer2 protocol\n");
+ return NULL;
+ }
- DEBUGP("unable to find matching layer2 protocol\n");
- return NULL;
+ p = rfid_layer2s[id];
+ return p->fn.init(rh);
}
int
@@ -80,15 +85,6 @@ rfid_layer2_close(struct rfid_layer2_handle *ph)
}
int
-rfid_layer2_register(struct rfid_layer2 *p)
-{
- p->next = rfid_layer2_list;
- rfid_layer2_list = p;
-
- return 0;
-}
-
-int
rfid_layer2_getopt(struct rfid_layer2_handle *ph, int optname,
void *optval, unsigned int *optlen)
{
diff --git a/src/rfid_layer2_iso14443a.c b/src/rfid_layer2_iso14443a.c
index 7ebc240..34bd93f 100644
--- a/src/rfid_layer2_iso14443a.c
+++ b/src/rfid_layer2_iso14443a.c
@@ -287,7 +287,7 @@ static struct rfid_layer2_handle *
iso14443a_init(struct rfid_reader_handle *rh)
{
int ret;
- struct rfid_layer2_handle *h = malloc(sizeof(*h));
+ struct rfid_layer2_handle *h = malloc_layer2_handle(sizeof(*h));
if (!h)
return NULL;
@@ -298,7 +298,7 @@ iso14443a_init(struct rfid_reader_handle *rh)
ret = h->rh->reader->iso14443a.init(h->rh);
if (ret < 0) {
- free(h);
+ free_layer2_handle(h);
return NULL;
}
@@ -308,12 +308,12 @@ iso14443a_init(struct rfid_reader_handle *rh)
static int
iso14443a_fini(struct rfid_layer2_handle *handle)
{
- free(handle);
+ free_layer2_handle(handle);
return 0;
}
-struct rfid_layer2 rfid_layer2_iso14443a = {
+const struct rfid_layer2 rfid_layer2_iso14443a = {
.id = RFID_LAYER2_ISO14443A,
.name = "ISO 14443-3 A",
.fn = {
diff --git a/src/rfid_layer2_iso14443b.c b/src/rfid_layer2_iso14443b.c
index 8227a32..d88fee5 100644
--- a/src/rfid_layer2_iso14443b.c
+++ b/src/rfid_layer2_iso14443b.c
@@ -162,29 +162,24 @@ static int
transceive_attrib(struct rfid_layer2_handle *h, const unsigned char *inf,
unsigned int inf_len, unsigned char *rx_data, unsigned int *rx_len)
{
- struct iso14443b_attrib_hdr *attrib;
- unsigned int attrib_size = sizeof(*attrib) + inf_len;
- unsigned char *rx_buf;
+ struct {
+ struct iso14443b_attrib_hdr attrib;
+ char buf[256-3];
+ } _attrib_buf;
+
+ struct iso14443b_attrib_hdr *attrib = &_attrib_buf.attrib;
+ unsigned char rx_buf[256];
unsigned char fsdi;
int ret = 0;
DEBUGP("fsd is %u\n", h->priv.iso14443b.fsd);
- attrib = malloc(attrib_size);
- if (!attrib) {
- perror("attrib_alloc");
- return -1;
- }
-
- DEBUGP("fsd is %u\n", h->priv.iso14443b.fsd);
- rx_buf = malloc(*rx_len+1);
- if (!rx_buf) {
- perror("rx_buf malloc");
- ret = -1;
+ if (rx_len >= rx_len-1) {
+ perror("rx_len too large\n");
goto out_attrib;
}
/* initialize attrib frame */
- memset(attrib, 0, attrib_size);
+ memset(&_attrib_buf, 0, sizeof(_attrib_buf));
if (inf_len)
memcpy((unsigned char *)attrib+sizeof(*attrib), inf, inf_len);
@@ -237,7 +232,6 @@ transceive_attrib(struct rfid_layer2_handle *h, const unsigned char *inf,
out_rx:
free(rx_buf);
out_attrib:
- free(attrib);
return ret;
}
@@ -295,7 +289,7 @@ static struct rfid_layer2_handle *
iso14443b_init(struct rfid_reader_handle *rh)
{
int ret;
- struct rfid_layer2_handle *h = malloc(sizeof(*h));
+ struct rfid_layer2_handle *h = malloc_layer2_handle(sizeof(*h));
if (!h)
return NULL;
@@ -317,7 +311,7 @@ iso14443b_init(struct rfid_reader_handle *rh)
ret = h->rh->reader->iso14443b.init(h->rh);
if (ret < 0) {
DEBUGP("error during reader 14443b init\n");
- free(h);
+ free_layer2_handle(h);
return NULL;
}
@@ -327,7 +321,7 @@ iso14443b_init(struct rfid_reader_handle *rh)
static int
iso14443b_fini(struct rfid_layer2_handle *handle)
{
- free(handle);
+ free_layer2_handle(handle);
return 0;
}
@@ -394,7 +388,7 @@ iso14443b_setopt(struct rfid_layer2_handle *handle,
}
-struct rfid_layer2 rfid_layer2_iso14443b = {
+const struct rfid_layer2 rfid_layer2_iso14443b = {
.id = RFID_LAYER2_ISO14443B,
.name = "ISO 14443-3 B",
.fn = {
diff --git a/src/rfid_layer2_iso15693.c b/src/rfid_layer2_iso15693.c
index 8c5d808..8ab0b1e 100644
--- a/src/rfid_layer2_iso15693.c
+++ b/src/rfid_layer2_iso15693.c
@@ -1,6 +1,6 @@
/* ISO 15693 anticollision implementation
*
- * (C) 2005 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
*
*/
@@ -263,7 +263,7 @@ static struct rfid_layer2_handle *
iso15693_init(struct rfid_reader_handle *rh)
{
int ret;
- struct rfid_layer2_handle *h = malloc(sizeof(*h));
+ struct rfid_layer2_handle *h = malloc_layer2_handle(sizeof(*h));
if (!h)
return NULL;
@@ -273,7 +273,7 @@ iso15693_init(struct rfid_reader_handle *rh)
ret = h->rh->reader->iso15693.init(h->rh);
if (ret < 0) {
- free(h);
+ free_layer2_handle(h);
return NULL;
}
@@ -283,12 +283,12 @@ iso15693_init(struct rfid_reader_handle *rh)
static int
iso15693_fini(struct rfid_layer2_handle *handle)
{
- free(handle);
+ free_layer2_handle(handle);
return 0;
}
-struct rfid_layer2 rfid_layer2_iso15693 = {
+const struct rfid_layer2 rfid_layer2_iso15693 = {
.id = RFID_LAYER2_ISO15693,
.name = "ISO 15693",
.fn = {
diff --git a/src/rfid_proto_mifare_classic.c b/src/rfid_proto_mifare_classic.c
index 5d2b3ff..d45eefc 100644
--- a/src/rfid_proto_mifare_classic.c
+++ b/src/rfid_proto_mifare_classic.c
@@ -1,7 +1,7 @@
/* Mifare Classic implementation, PCD side.
*
- * (C) 2005 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
*
*/
@@ -110,17 +110,17 @@ static struct rfid_protocol_handle *
mfcl_init(struct rfid_layer2_handle *l2h)
{
struct rfid_protocol_handle *ph;
- ph = malloc(sizeof(struct rfid_protocol_handle));
+ ph = malloc_protocol_handle(sizeof(struct rfid_protocol_handle));
return ph;
}
static int mfcl_fini(struct rfid_protocol_handle *ph)
{
- free(ph);
+ free_protocol_handle(ph);
return 0;
}
-struct rfid_protocol rfid_protocol_mfcl = {
+const struct rfid_protocol rfid_protocol_mfcl = {
.id = RFID_PROTOCOL_MIFARE_CLASSIC,
.name = "Mifare Classic",
.fn = {
diff --git a/src/rfid_proto_mifare_ul.c b/src/rfid_proto_mifare_ul.c
index 5de050d..0ea55d2 100644
--- a/src/rfid_proto_mifare_ul.c
+++ b/src/rfid_proto_mifare_ul.c
@@ -1,7 +1,7 @@
/* Mifare Ultralight implementation, PCD side.
*
- * (C) 2005 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
*
*/
@@ -112,17 +112,17 @@ static struct rfid_protocol_handle *
mful_init(struct rfid_layer2_handle *l2h)
{
struct rfid_protocol_handle *ph;
- ph = malloc(sizeof(struct rfid_protocol_handle));
+ ph = malloc_protocol_handle(sizeof(struct rfid_protocol_handle));
return ph;
}
static int mful_fini(struct rfid_protocol_handle *ph)
{
- free(ph);
+ free_protocol_handle(ph);
return 0;
}
-struct rfid_protocol rfid_protocol_mful = {
+const struct rfid_protocol rfid_protocol_mful = {
.id = RFID_PROTOCOL_MIFARE_UL,
.name = "Mifare Ultralight",
.fn = {
diff --git a/src/rfid_proto_tcl.c b/src/rfid_proto_tcl.c
index 2ed7a7c..d00e966 100644
--- a/src/rfid_proto_tcl.c
+++ b/src/rfid_proto_tcl.c
@@ -1,6 +1,6 @@
/* ISO 14443-4 (T=CL) implementation, PCD side.
*
- * (C) 2005 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
*
*/
@@ -737,13 +737,13 @@ tcl_init(struct rfid_layer2_handle *l2h)
struct rfid_protocol_handle *th;
unsigned int mru = l2h->rh->ah->mru;
- th = malloc(sizeof(struct rfid_protocol_handle) + mru);
+ th = malloc_protocol_handle(sizeof(struct rfid_protocol_handle));
if (!th)
return NULL;
/* FIXME: mru should be attribute of layer2 (in case it adds/removes
* some overhead */
- memset(th, 0, sizeof(struct rfid_protocol_handle) + mru);
+ memset(th, 0, sizeof(struct rfid_protocol_handle));
/* maximum received ats length equals mru of asic/reader */
th->priv.tcl.state = TCL_STATE_INITIAL;
@@ -758,11 +758,11 @@ tcl_init(struct rfid_layer2_handle *l2h)
static int
tcl_fini(struct rfid_protocol_handle *ph)
{
- free(ph);
+ free_protocol_handle(ph);
return 0;
}
-struct rfid_protocol rfid_protocol_tcl = {
+const struct rfid_protocol rfid_protocol_tcl = {
.id = RFID_PROTOCOL_TCL,
.name = "ISO 14443-4 / T=CL",
.fn = {
diff --git a/src/rfid_protocol.c b/src/rfid_protocol.c
index b24243a..1a4262a 100644
--- a/src/rfid_protocol.c
+++ b/src/rfid_protocol.c
@@ -1,5 +1,5 @@
/* librfid - layer 3 protocol handler
- * (C) 2005 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
*/
/*
@@ -24,7 +24,11 @@
#include <librfid/rfid_layer2.h>
#include <librfid/rfid_protocol.h>
-static struct rfid_protocol *rfid_protocol_list;
+static const struct rfid_protocol *rfid_protocols[] = {
+ [RFID_PROTOCOL_MIFARE_CLASSIC] = &rfid_protocol_mfcl,
+ [RFID_PROTOCOL_MIFARE_UL] = &rfid_protocol_mful,
+ [RFID_PROTOCOL_TCL] = &rfid_protocol_tcl,
+};
struct rfid_protocol_handle *
rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id)
@@ -32,13 +36,12 @@ rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id)
struct rfid_protocol *p;
struct rfid_protocol_handle *ph = NULL;
- for (p = rfid_protocol_list; p; p = p->next) {
- if (p->id == id) {
- ph = p->fn.init(l2h);
- break;
- }
- }
+ if (id >= ARRAY_SIZE(rfid_protocols))
+ return NULL;
+
+ p = rfid_protocols[id];
+ ph = p->fn.init(l2h);
if (!ph)
return NULL;
@@ -103,15 +106,6 @@ rfid_protocol_close(struct rfid_protocol_handle *ph)
return 0;
}
-int
-rfid_protocol_register(struct rfid_protocol *p)
-{
- p->next = rfid_protocol_list;
- rfid_protocol_list = p;
-
- return 0;
-}
-
char *rfid_protocol_name(struct rfid_protocol_handle *ph)
{
return ph->proto->name;
diff --git a/src/rfid_reader.c b/src/rfid_reader.c
index f41ae8f..a5dbeb2 100644
--- a/src/rfid_reader.c
+++ b/src/rfid_reader.c
@@ -1,5 +1,5 @@
/* librfid - core reader handling
- * (C) 2005 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
*/
/*
@@ -22,20 +22,29 @@
#include <librfid/rfid.h>
#include <librfid/rfid_reader.h>
+#include <librfid/rfid_reader_cm5121.h>
+#include <librfid/rfid_reader_openpcd.h>
-static struct rfid_reader *rfid_reader_list;
+static const struct rfid_reader *rfid_readers[] = {
+#ifndef LIBRFID_FIRMWARE
+ [RFID_READER_CM5121] = &rfid_reader_cm5121,
+#endif
+ [RFID_READER_OPENPCD] = &rfid_reader_openpcd,
+};
struct rfid_reader_handle *
rfid_reader_open(void *data, unsigned int id)
{
- struct rfid_reader *p;
+ const struct rfid_reader *p;
- for (p = rfid_reader_list; p; p = p->next)
- if (p->id == id)
- return p->open(data);
+ if (id >= ARRAY_SIZE(rfid_readers)) {
+ DEBUGP("unable to find matching reader\n");
+ return NULL;
+ }
- DEBUGP("unable to find matching reader\n");
- return NULL;
+ p = rfid_readers[id];
+
+ return p->open(data);
}
int
@@ -54,12 +63,3 @@ rfid_reader_close(struct rfid_reader_handle *rh)
{
rh->reader->close(rh);
}
-
-int
-rfid_reader_register(struct rfid_reader *r)
-{
- r->next = rfid_reader_list;
- rfid_reader_list = r;
-
- return 0;
-}
diff --git a/src/rfid_reader_cm5121.c b/src/rfid_reader_cm5121.c
index a9907ad..dd15fd6 100644
--- a/src/rfid_reader_cm5121.c
+++ b/src/rfid_reader_cm5121.c
@@ -27,6 +27,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifndef LIBRFID_FIRMWARE
+
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -314,12 +316,12 @@ cm5121_open(void *data)
struct rfid_reader_handle *rh;
struct rfid_asic_transport_handle *rath;
- rh = malloc(sizeof(*rh));
+ rh = malloc_reader_handle(sizeof(*rh));
if (!rh)
return NULL;
memset(rh, 0, sizeof(*rh));
- rath = malloc(sizeof(*rath));
+ rath = malloc_rat_handle(sizeof(*rath));
if (!rath)
goto out_rh;
memset(rath, 0, sizeof(*rath));
@@ -341,9 +343,9 @@ cm5121_open(void *data)
return rh;
out_rath:
- free(rath);
+ free_rat_handle(rath);
out_rh:
- free(rh);
+ free_reader_handle(rh);
return NULL;
}
@@ -353,11 +355,11 @@ cm5121_close(struct rfid_reader_handle *rh)
{
struct rfid_asic_transport_handle *rath = rh->ah->rath;
rc632_close(rh->ah);
- free(rath);
- free(rh);
+ free_rat_handle(rath);
+ free_reader_handle(rh);
}
-struct rfid_reader rfid_reader_cm5121 = {
+const struct rfid_reader rfid_reader_cm5121 = {
.name = "Omnikey CardMan 5121 RFID",
.open = &cm5121_open,
.close = &cm5121_close,
@@ -385,4 +387,4 @@ struct rfid_reader rfid_reader_cm5121 = {
},
};
-
+#endif /* LIBRFID_FIRMWARE */
diff --git a/src/rfid_reader_openpcd.c b/src/rfid_reader_openpcd.c
index ca2cdff..15486b6 100644
--- a/src/rfid_reader_openpcd.c
+++ b/src/rfid_reader_openpcd.c
@@ -45,7 +45,6 @@
/* FIXME */
#include "rc632.h"
-
#define SENDBUF_LEN (256+4+10) /* 256bytes max FSD/FSC, plus 4 bytes header,
plus 10 bytes reserve */
#define RECVBUF_LEN SENDBUF_LEN
@@ -56,6 +55,8 @@ static struct openpcd_hdr *snd_hdr;
static struct openpcd_hdr *rcv_hdr;
+#ifndef LIBRFID_FIRMWARE
+
static struct usb_device *dev;
static struct usb_dev_handle *hdl;
@@ -129,6 +130,8 @@ static struct usb_device *find_opcd_device(void)
return NULL;
}
+/* RC632 access primitives for librfid inside reader firmware */
+
static int openpcd_reg_write(struct rfid_asic_transport_handle *rath,
unsigned char reg, unsigned char value)
{
@@ -205,6 +208,60 @@ static int openpcd_fifo_write(struct rfid_asic_transport_handle *rath,
return ret;
}
+const struct rfid_asic_transport openpcd_rat = {
+ .name = "OpenPCD Dumb USB Protocol",
+ .priv.rc632 = {
+ .fn = {
+ .reg_write = &openpcd_reg_write,
+ .reg_read = &openpcd_reg_read,
+ .fifo_write = &openpcd_fifo_write,
+ .fifo_read = &openpcd_fifo_read,
+ },
+ },
+};
+
+#else
+/* RC632 access primitives for librfid inside reader firmware */
+
+static int openpcd_reg_write(struct rfid_asic_transport_handle *rath,
+ unsigned char reg, unsigned char value)
+{
+}
+
+static int openpcd_reg_read(struct rfid_asic_transport_handle *rath,
+ unsigned char reg,
+ unsigned char *value)
+{
+}
+
+
+static int openpcd_fifo_read(struct rfid_asic_transport_handle *rath,
+ unsigned char num_bytes,
+ unsigned char *buf)
+{
+}
+
+static int openpcd_fifo_write(struct rfid_asic_transport_handle *rath,
+ unsigned char len,
+ const unsigned char *bytes,
+ unsigned char flags)
+{
+}
+
+const struct rfid_asic_transport openpcd_rat = {
+ .name = "OpenPCD Firmware RC632 Access",
+ .priv.rc632 = {
+ .fn = {
+ .reg_write = &openpcd_reg_write,
+ .reg_read = &openpcd_reg_read,
+ .fifo_write = &openpcd_fifo_write,
+ .fifo_read = &openpcd_fifo_read,
+ },
+ },
+};
+
+#endif /* LIBRFID_FIRMWARE */
+
static int openpcd_transceive(struct rfid_reader_handle *rh,
enum rfid_frametype frametype,
const unsigned char *tx_data, unsigned int tx_len,
@@ -299,18 +356,6 @@ openpcd_mifare_auth(struct rfid_reader_handle *rh, u_int8_t cmd,
cmd, serno, block);
}
-struct rfid_asic_transport openpcd_ccid = {
- .name = "OpenPCD Dumb USB Protocol",
- .priv.rc632 = {
- .fn = {
- .reg_write = &openpcd_reg_write,
- .reg_read = &openpcd_reg_read,
- .fifo_write = &openpcd_fifo_write,
- .fifo_read = &openpcd_fifo_read,
- },
- },
-};
-
static struct rfid_reader_handle *
openpcd_open(void *data)
{
@@ -344,17 +389,17 @@ openpcd_open(void *data)
return NULL;
}
- rh = malloc(sizeof(*rh));
+ rh = malloc_reader_handle(sizeof(*rh));
if (!rh)
return NULL;
memset(rh, 0, sizeof(*rh));
- rath = malloc(sizeof(*rath));
+ rath = malloc_rat_handle(sizeof(*rath));
if (!rath)
goto out_rh;
memset(rath, 0, sizeof(*rath));
- rath->rat = &openpcd_ccid;
+ rath->rat = &openpcd_rat;
rh->reader = &rfid_reader_openpcd;
rh->ah = rc632_open(rath);
@@ -365,9 +410,9 @@ openpcd_open(void *data)
return rh;
out_rath:
- free(rath);
+ free_rat_handle(rath);
out_rh:
- free(rh);
+ free_reader_handle(rh);
return NULL;
}
@@ -378,13 +423,13 @@ openpcd_close(struct rfid_reader_handle *rh)
struct rfid_asic_transport_handle *rath = rh->ah->rath;
rc632_close(rh->ah);
- free(rath);
- free(rh);
+ free_rat_handle(rath);
+ free_reader_handle(rh);
usb_close(hdl);
}
-struct rfid_reader rfid_reader_openpcd = {
+const struct rfid_reader rfid_reader_openpcd = {
.name = "OpenPCD RFID Reader",
.id = RFID_READER_OPENPCD,
.open = &openpcd_open,
personal git repositories of Harald Welte. Your mileage may vary