- fix multiple include of rfid_protocol_mifare_classic.h problem
authorHarald Welte <laforge@gnumonks.org>
Sun, 15 Oct 2006 19:17:22 +0000 (19:17 +0000)
committerHarald Welte <laforge@gnumonks.org>
Sun, 15 Oct 2006 19:17:22 +0000 (19:17 +0000)
- add some more layer2 {get,set}opt()s
- add rfid_protocol_{get,set}opt()
- export functions for l2/proto scanning, not just for combined scanning
- add support for sending WUPA instead of REQA in iso14443a

git-svn-id: https://svn.gnumonks.org/trunk/librfid@1910 e0336214-984f-0b4b-a45f-81c69e1f0ede

include/librfid/rfid_layer2.h
include/librfid/rfid_protocol.h
include/librfid/rfid_protocol_mifare_classic.h
include/librfid/rfid_protocol_tcl.h
include/librfid/rfid_scan.h
src/rfid_layer2_iso14443a.c
src/rfid_proto_tcl.c
src/rfid_protocol.c
src/rfid_scan.c

index 0f6f683..1ef0713 100644 (file)
@@ -18,6 +18,8 @@ enum rfid_layer2_id {
 #define RFID_OPT_L2_PRIV               0x00010000
 enum rfid_layer2_opt {
        RFID_OPT_LAYER2_UID             = 0x0001,
+       RFID_OPT_LAYER2_PROTO_SUPP      = 0x0002,
+       RFID_OPT_LAYER2_WUP             = 0x0003,
 };
 
 struct rfid_layer2_handle *rfid_layer2_init(struct rfid_reader_handle *rh,
@@ -70,6 +72,7 @@ struct rfid_layer2_handle {
        unsigned char uid[10];  /* triple size 14443a id is 10 bytes */
        unsigned int uid_len;
        unsigned int proto_supported;
+       unsigned int flags;
        union {
                struct iso14443a_handle iso14443a;
                struct iso14443b_handle iso14443b;
index 2b02a42..446abd9 100644 (file)
@@ -27,6 +27,12 @@ rfid_protocol_write(struct rfid_protocol_handle *ph,
 int rfid_protocol_fini(struct rfid_protocol_handle *ph);
 int rfid_protocol_close(struct rfid_protocol_handle *ph);
 
+int rfid_protocol_getopt(struct rfid_protocol_handle *ph, int optname,
+                        void *optval, unsigned int *optlen);
+
+int rfid_protocol_setopt(struct rfid_protocol_handle *ph, int optname,
+                        const void *optval, unsigned int optlen);
+
 char *rfid_protocol_name(struct rfid_protocol_handle *ph);
 
 enum rfid_protocol_id {
@@ -36,6 +42,9 @@ enum rfid_protocol_id {
        RFID_PROTOCOL_MIFARE_CLASSIC,
 };
 
+enum rfid_protocol_opt {
+       RFID_OPT_PROTO_ID,
+};
 
 #ifdef __LIBRFID__
 
@@ -65,6 +74,11 @@ struct rfid_protocol {
                             unsigned int page,
                             unsigned char *tx_data,
                             unsigned int tx_len);
+               int (*getopt)(struct rfid_protocol_handle *h,
+                             int optname, void *optval, unsigned int *optlen);
+               int (*setopt)(struct rfid_protocol_handle *h,
+                             int optname, const void *optval,
+                             unsigned int optlen);
        } fn;
 };
 
index 06235b8..f1e1403 100644 (file)
@@ -1,4 +1,5 @@
 #ifndef _MIFARE_CLASSIC_H
+#define _MIFARE_CLASSIC_H
 
 #include <librfid/rfid_protocol.h>
 
index 2ee1c27..535af11 100644 (file)
@@ -1,6 +1,11 @@
 #ifndef _RFID_PROTOCOL_TCL_H
 #define _RFID_PROTOCOL_TCL_H
 
+enum rfid_proto_tcl_opt {
+       RFID_OPT_P_TCL_ATS      =       0x00010001,
+       RFID_OPT_P_TCL_ATS_LEN  =       0x00010002,
+};
+
 #ifdef __LIBRFID__
 
 enum tcl_transport_rate {
index dcfd7bf..50910fb 100644 (file)
@@ -5,6 +5,12 @@
 #include <librfid/rfid_layer2.h>
 #include <librfid/rfid_protocol.h>
 
+struct rfid_layer2_handle *
+rfid_layer2_scan(struct rfid_reader_handle *rh);
+
+struct rfid_protocol_handle *
+rfid_protocol_scan(struct rfid_layer2_handle *l2h);
+
 int rfid_scan(struct rfid_reader_handle *rh,
              struct rfid_layer2_handle **l2h,
              struct rfid_protocol_handle **ph);
index 34bd93f..b8e6ef4 100644 (file)
@@ -112,7 +112,10 @@ iso14443a_anticol(struct rfid_layer2_handle *handle)
        memset(&atqa, 0, sizeof(atqa));
        memset(&acf, 0, sizeof(acf));
 
-       ret = iso14443a_transceive_sf(handle, ISO14443A_SF_CMD_REQA, &atqa);
+       if (handle->flags & RFID_OPT_LAYER2_WUP)
+               ret = iso14443a_transceive_sf(handle, ISO14443A_SF_CMD_WUPA, &atqa);
+       else
+               ret = iso14443a_transceive_sf(handle, ISO14443A_SF_CMD_REQA, &atqa);
        if (ret < 0) {
                h->state = ISO14443A_STATE_REQA_SENT;
                DEBUGP("error during transceive_sf: %d\n", ret);
@@ -291,6 +294,8 @@ iso14443a_init(struct rfid_reader_handle *rh)
        if (!h)
                return NULL;
 
+       memset(h, 0, sizeof(*h));
+
        h->l2 = &rfid_layer2_iso14443a;
        h->rh = rh;
        h->priv.iso14443a.state = ISO14443A_STATE_NONE;
index d00e966..af626c6 100644 (file)
@@ -122,7 +122,8 @@ tcl_parse_ats(struct rfid_protocol_handle *h,
                } else {
                        /* Section 7.2: fwi for type B is always in ATQB */
                        /* Value is assigned in tcl_connect() */
-                       /* This function is never called for Type B, since it has no (R)ATS */
+                       /* This function is never called for Type B, 
+                        * since Type B has no (R)ATS */
                }
                return 0;
        }
@@ -762,6 +763,43 @@ tcl_fini(struct rfid_protocol_handle *ph)
        return 0;
 }
 
+int 
+tcl_getopt(struct rfid_protocol_handle *h, int optname, void *optval,
+          unsigned int *optlen)
+{
+       u_int8_t *opt_str = optval;
+
+       switch (optname) {
+       case RFID_OPT_P_TCL_ATS:
+               if (h->priv.tcl.ats_len < *optlen)
+                       *optlen = h->priv.tcl.ats_len;
+               memcpy(opt_str, h->priv.tcl.ats, *optlen);
+               break;
+       case RFID_OPT_P_TCL_ATS_LEN:
+               if (*optlen < sizeof(u_int8_t))
+                       return -E2BIG;
+               *optlen = sizeof(u_int8_t);
+               *opt_str = h->priv.tcl.ats_len & 0xff;
+               break;
+       }
+
+       return 0;
+}
+
+int
+tcl_setopt(struct rfid_protocol_handle *h, int optname, const void *optval,
+          unsigned int optlen)
+{
+       int ret = -EINVAL;
+
+       switch (optname) {
+       default:
+               break;
+       }
+
+       return ret;
+}
+
 const struct rfid_protocol rfid_protocol_tcl = {
        .id     = RFID_PROTOCOL_TCL,
        .name   = "ISO 14443-4 / T=CL",
@@ -771,5 +809,7 @@ const struct rfid_protocol rfid_protocol_tcl = {
                .transceive = &tcl_transceive,
                .close = &tcl_deselect,
                .fini = &tcl_fini,
+               .getopt = &tcl_getopt,
+               .setopt = &tcl_setopt,
        },
 };
index 1a4262a..99fc8b1 100644 (file)
@@ -1,4 +1,4 @@
-/* librfid - layer 3 protocol handler 
+/* librfid - layer 4 protocol handler 
  * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
  */
 
@@ -106,6 +106,47 @@ rfid_protocol_close(struct rfid_protocol_handle *ph)
        return 0;
 }
 
+int
+rfid_protocol_getopt(struct rfid_protocol_handle *ph, int optname,
+                    void *optval, unsigned int *optlen)
+{
+       if (optname >> 16 == 0) {
+               unsigned char *optchar = optval;
+
+               switch (optname) {
+                       break;
+               default:
+                       return -EINVAL;
+                       break;
+               }
+       } else {
+               if (!ph->proto->fn.getopt)
+                       return -EINVAL;
+
+               return ph->proto->fn.getopt(ph, optname, optval, optlen);
+       }
+       return 0;
+}
+
+int
+rfid_protocol_setopt(struct rfid_protocol_handle *ph, int optname,
+                    const void *optval, unsigned int optlen)
+{
+       if (optname >> 16 == 0) {
+               switch (optname) {
+               default:
+                       return -EINVAL;
+                       break;
+               }
+       } else {
+               if (!ph->proto->fn.setopt)
+                       return -EINVAL;
+
+               return ph->proto->fn.setopt(ph, optname, optval, optlen);
+       }
+       return 0;
+}
+
 char *rfid_protocol_name(struct rfid_protocol_handle *ph)
 {
        return ph->proto->name;
index f50bee6..b19887e 100644 (file)
@@ -43,7 +43,7 @@ rfid_layer2_scan1(struct rfid_reader_handle *rh, int l2)
        return NULL;
 }
 
-static struct rfid_layer2_handle *
+struct rfid_layer2_handle *
 rfid_layer2_scan(struct rfid_reader_handle *rh)
 {
        struct rfid_layer2_handle *l2h;
@@ -80,7 +80,7 @@ rfid_protocol_scan1(struct rfid_layer2_handle *l2h, int proto)
        return NULL;
 }
 
-static struct rfid_protocol_handle *
+struct rfid_protocol_handle *
 rfid_protocol_scan(struct rfid_layer2_handle *l2h)
 {
        struct rfid_protocol_handle *ph;