add (preliminary?) SAK based detection of mifare mini.
authorlaforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede>
Thu, 7 Feb 2008 16:17:18 +0000 (16:17 +0000)
committerlaforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede>
Thu, 7 Feb 2008 16:17:18 +0000 (16:17 +0000)
git-svn-id: https://svn.gnumonks.org/trunk/librfid@2073 e0336214-984f-0b4b-a45f-81c69e1f0ede

include/librfid/rfid_layer2_iso14443a.h
src/rfid_layer2_iso14443a.c
src/rfid_proto_mifare_classic.c

index a4af557..d38fb2e 100644 (file)
@@ -6,6 +6,7 @@ enum rfid_14443a_opt {
        RFID_OPT_14443A_SPEED_TX        = 0x00010002,
        RFID_OPT_14443A_ATQA            = 0x00010003,
        RFID_OPT_14443A_WUPA            = 0x00010004,
+       RFID_OPT_14443A_SAK             = 0x00010005,
 };
 
 enum rfid_14443_opt_speed {
@@ -67,6 +68,7 @@ struct iso14443a_handle {
        unsigned int level;
        unsigned int tcl_capable;
        struct iso14443a_atqa atqa;
+       u_int8_t sak;
 };
 
 enum iso14443a_level {
index 281f709..90af0f2 100644 (file)
@@ -250,6 +250,7 @@ cascade:
 
        h->level = ISO14443A_LEVEL_NONE;
        h->state = ISO14443A_STATE_SELECTED;
+       h->sak = sak[0];
 
        if (sak[0] & 0x20) {
                DEBUGP("we have a T=CL compliant PICC\n");
@@ -323,9 +324,14 @@ iso14443a_getopt(struct rfid_layer2_handle *handle, int optname,
        int ret = -EINVAL;
        struct iso14443a_handle *h = &handle->priv.iso14443a;
        struct iso14443a_atqa *atqa = optval;
+       u_int8_t *opt_u8 = optval;
        int *wupa = optval;
 
        switch (optname) {
+       case RFID_OPT_14443A_SAK:
+               *opt_u8 = h->sak;
+               optlen = sizeof(*opt_u8);
+               break;
        case RFID_OPT_14443A_ATQA:
                *atqa = h->atqa;
                ret = 0;
index 003e8b0..66e4287 100644 (file)
@@ -115,7 +115,9 @@ mfcl_getopt(struct rfid_protocol_handle *ph, int optname, void *optval,
 {
        int ret = -EINVAL;
        u_int8_t atqa[2];
+       u_int8_t sak;
        unsigned int atqa_size = sizeof(atqa);
+       unsigned int sak_size = sizeof(sak);
        unsigned int *size = optval;
 
        switch (optname) {
@@ -126,10 +128,15 @@ mfcl_getopt(struct rfid_protocol_handle *ph, int optname, void *optval,
                ret = 0;
                rfid_layer2_getopt(ph->l2h, RFID_OPT_14443A_ATQA,
                                   atqa, &atqa_size);
-               /* FIXME: ATQA of mifare mini */
-               if (atqa[0] == 0x04 && atqa[1] == 0x00)
-                       *size = 1024;
-               else if (atqa[0] == 0x02 && atqa[1] == 0x00)
+               rfid_layer2_getopt(ph->l2h, RFID_OPT_14443A_SAK,
+                                  &sak, &sak_size);
+               if (atqa[0] == 0x04 && atqa[1] == 0x00) {
+                       if (sak == 0x09) {
+                               /* mifare mini */
+                               *size = 320;
+                       } else
+                               *size = 1024;
+               } else if (atqa[0] == 0x02 && atqa[1] == 0x00)
                        *size = 4096;
                else
                        ret = -EIO;