- remove prototypes for already-removed _register() functions from headers
[librfid] / src / rfid_reader_openpcd.c
index 053a711..aee3d18 100644 (file)
@@ -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;
 
@@ -118,11 +119,8 @@ static struct usb_device *find_opcd_device(void)
                struct usb_device *dev;
                for (dev = bus->devices; dev; dev = dev->next) {
                        int i;
-                       printf("usb: %4x:%4x\n", dev->descriptor.idVendor,
-                               dev->descriptor.idProduct);
                        for (i = 0; i < ARRAY_SIZE(opcd_usb_ids); i++) {
                                const struct usb_id *id = &opcd_usb_ids[i];
-                               printf("%x:%x\n", id->vid, id->pid);
                                if (dev->descriptor.idVendor == id->vid &&
                                    dev->descriptor.idProduct == id->pid)
                                        return dev;
@@ -132,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)
 {
@@ -208,6 +208,64 @@ 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)
+{
+       return rc632_reg_write(rath, reg, value);
+}
+
+static int openpcd_reg_read(struct rfid_asic_transport_handle *rath,
+                           unsigned char reg,
+                           unsigned char *value)
+{
+       return rc632_reg_read(rath, reg, value);
+}
+
+
+static int openpcd_fifo_read(struct rfid_asic_transport_handle *rath,
+                            unsigned char num_bytes,
+                            unsigned char *buf)
+{
+       return rc632_fifo_read(rath, num_bytes, buf);
+}
+
+static int openpcd_fifo_write(struct rfid_asic_transport_handle *rath,
+                            unsigned char len,
+                            const unsigned char *bytes,
+                            unsigned char flags)
+{
+       return rc632_fifo_write(rath, len, bytes, 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,
@@ -302,18 +360,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)
 {
@@ -323,6 +369,7 @@ openpcd_open(void *data)
        snd_hdr = (struct openpcd_hdr *)snd_buf;
        rcv_hdr = (struct openpcd_hdr *)rcv_buf;
 
+#ifndef LIBRFID_FIRMWARE
        usb_init();
        if (usb_find_busses() < 0)
                return NULL;
@@ -346,18 +393,19 @@ openpcd_open(void *data)
                usb_close(hdl);
                return NULL;
        }
+#endif
 
-       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);
@@ -368,9 +416,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;
 }
@@ -381,13 +429,15 @@ 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);
 
+#ifndef LIBRFID_FIRMWARE
        usb_close(hdl);
+#endif
 }
 
-struct rfid_reader rfid_reader_openpcd = {
+const struct rfid_reader rfid_reader_openpcd = {
        .name   = "OpenPCD RFID Reader",
        .id = RFID_READER_OPENPCD,
        .open = &openpcd_open,
@@ -410,6 +460,9 @@ struct rfid_reader rfid_reader_openpcd = {
        .iso14443b = {
                .init = &openpcd_14443b_init,
        },
+       .iso15693 = {
+               .init = &openpcd_15693_init,
+       },
        .mifare_classic = {
                .setkey = &openpcd_mifare_setkey,
                .auth = &openpcd_mifare_auth,