summaryrefslogtreecommitdiff
path: root/src/rfid_reader_openpcd.c
diff options
context:
space:
mode:
authorlaforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede>2006-10-14 12:34:38 +0000
committerlaforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede>2006-10-14 12:34:38 +0000
commite404cccecd20a2418c2429cd182c18218e54bd28 (patch)
tree5a15b5ca51874f0f8e96ccc4ee0457a66de3cec7 /src/rfid_reader_openpcd.c
parent6e87a007525b313dcf2da194977bb1abdf62026f (diff)
Prepare RFID compilation in firmware mode
- switch from linked lists to static arrays - remove all non-handle dynamic allocations (at the expense of stack) - declare all proto/reader/asic/layer2 structures as const - wrap all handle allocations in macros that expand to references to static structures in case of firmware mode - update copyright notices - add skeleton code for openpcd-inside-firmware driver - update TODO with remaining TODO for firmware mode git-svn-id: https://svn.gnumonks.org/trunk/librfid@1903 e0336214-984f-0b4b-a45f-81c69e1f0ede
Diffstat (limited to 'src/rfid_reader_openpcd.c')
-rw-r--r--src/rfid_reader_openpcd.c87
1 files changed, 66 insertions, 21 deletions
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