fixed ISO 14443A anticollision
[librfid] / src / rfid_reader_cm5121.c
index d61b5f7..1514551 100644 (file)
@@ -1,6 +1,6 @@
 /* Omnikey CardMan 5121 specific RC632 transport layer 
  *
- * (C) 2005 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
  *
  * The 5121 is an Atmel AT89C5122 based USB CCID reader (probably the same
  * design like the 3121).  It's CL RC632 is connected via address/data bus,
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
 
 #include <librfid/rfid.h>
+
+#ifndef LIBRFID_FIRMWARE
+
 #include <librfid/rfid_reader.h>
 #include <librfid/rfid_asic.h>
 #include <librfid/rfid_asic_rc632.h>
 #include <librfid/rfid_reader_cm5121.h>
+#include <librfid/rfid_layer2.h>
+#include <librfid/rfid_protocol.h>
+
+#include "cm5121_source.h"
 
 /* FIXME */
 #include "rc632.h"
@@ -61,7 +67,7 @@ int Write1ByteToReg(struct rfid_asic_transport_handle *rath,
 {
        unsigned char sndbuf[SENDBUF_LEN];
        unsigned char rcvbuf[RECVBUF_LEN];
-       unsigned int retlen = RECVBUF_LEN;
+       size_t retlen = RECVBUF_LEN;
 
        sndbuf[0] = 0x20;
        sndbuf[1] = 0x00;
@@ -90,7 +96,7 @@ static int Read1ByteFromReg(struct rfid_asic_transport_handle *rath,
 {
        unsigned char sndbuf[SENDBUF_LEN];
        unsigned char recvbuf[RECVBUF_LEN];
-       unsigned int retlen = sizeof(recvbuf);
+       size_t retlen = sizeof(recvbuf);
 
        sndbuf[0] = 0x20;
        sndbuf[1] = 0x00;
@@ -118,7 +124,7 @@ static int ReadNBytesFromFIFO(struct rfid_asic_transport_handle *rath,
 {
        unsigned char sndbuf[SENDBUF_LEN];
        unsigned char recvbuf[0x7f];
-       unsigned int retlen = sizeof(recvbuf);
+       size_t retlen = sizeof(recvbuf);
 
        sndbuf[0] = 0x20;
        sndbuf[1] = 0x00;
@@ -147,7 +153,7 @@ static int WriteNBytesToFIFO(struct rfid_asic_transport_handle *rath,
 {
        unsigned char sndbuf[SENDBUF_LEN];
        unsigned char recvbuf[0x7f];
-       unsigned int retlen = sizeof(recvbuf);
+       size_t retlen = sizeof(recvbuf);
 
        sndbuf[0] = 0x20;
        sndbuf[1] = 0x00;
@@ -296,10 +302,9 @@ static int cm5121_enable_rc632(struct rfid_asic_transport_handle *rath)
 {
        unsigned char tx_buf[1] = { 0x01 };     
        unsigned char rx_buf[64];
-       unsigned int rx_len = sizeof(rx_buf);
+       size_t rx_len = sizeof(rx_buf);
 
        PC_to_RDR_Escape(rath->data, tx_buf, 1, rx_buf, &rx_len);
-       printf("received %u bytes from 01 command\n", rx_len);
 
        return 0;
 }
@@ -310,12 +315,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));
@@ -337,9 +342,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;
 }
@@ -349,15 +354,21 @@ 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,
        .transceive = &cm5121_transceive,
+       .l2_supported = (1 << RFID_LAYER2_ISO14443A) |
+                       (1 << RFID_LAYER2_ISO14443B) |
+                       (1 << RFID_LAYER2_ISO15693),
+       .proto_supported = (1 << RFID_PROTOCOL_TCL) |
+                       (1 << RFID_PROTOCOL_MIFARE_UL) |
+                       (1 << RFID_PROTOCOL_MIFARE_CLASSIC),
        .iso14443a = {
                .init = &cm5121_14443a_init,
                .transceive_sf = &cm5121_transceive_sf,
@@ -369,10 +380,13 @@ struct rfid_reader rfid_reader_cm5121 = {
        .iso14443b = {
                .init = &cm5121_14443b_init,
        },
+       .iso15693 = {
+               .init = &cm5121_15693_init,
+       },
        .mifare_classic = {
                .setkey = &cm5121_mifare_setkey,
                .auth = &cm5121_mifare_auth,
        },
 };
 
-
+#endif /* LIBRFID_FIRMWARE */