X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=src%2Frfid_layer2_iso14443a.c;h=429577cf6d7fd5440b12628782bedfd187c557d0;hb=8238838b5b280732e461d4c46bcce3c2276a1335;hp=34bd93ff3c38805fd0d70efc0f1cebbe92f1b27a;hpb=fb488a0210b1c694dba762ba086f43a5d4655c4f;p=librfid diff --git a/src/rfid_layer2_iso14443a.c b/src/rfid_layer2_iso14443a.c index 34bd93f..429577c 100644 --- a/src/rfid_layer2_iso14443a.c +++ b/src/rfid_layer2_iso14443a.c @@ -33,7 +33,7 @@ #define TIMEOUT 1236 /* Transceive a 7-bit short frame */ -static int +int iso14443a_transceive_sf(struct rfid_layer2_handle *handle, unsigned char cmd, struct iso14443a_atqa *atqa) @@ -100,19 +100,22 @@ iso14443a_anticol(struct rfid_layer2_handle *handle) int ret; unsigned int uid_size; struct iso14443a_handle *h = &handle->priv.iso14443a; - struct iso14443a_atqa atqa; + struct iso14443a_atqa *atqa = &h->atqa; struct iso14443a_anticol_cmd acf; unsigned int bit_of_col; unsigned char sak[3]; unsigned int rx_len = sizeof(sak); - char *aqptr = (char *) &atqa; + char *aqptr = (char *) atqa; memset(handle->uid, 0, sizeof(handle->uid)); memset(sak, 0, sizeof(sak)); - memset(&atqa, 0, sizeof(atqa)); + 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); @@ -122,15 +125,15 @@ iso14443a_anticol(struct rfid_layer2_handle *handle) DEBUGP("ATQA: 0x%02x 0x%02x\n", *aqptr, *(aqptr+1)); - if (!atqa.bf_anticol) { + if (!atqa->bf_anticol) { h->state = ISO14443A_STATE_NO_BITFRAME_ANTICOL; DEBUGP("no bitframe anticollission bits set, aborting\n"); return -1; } - if (atqa.uid_size == 2 || atqa.uid_size == 3) + if (atqa->uid_size == 2 || atqa->uid_size == 3) uid_size = 3; - else if (atqa.uid_size == 1) + else if (atqa->uid_size == 1) uid_size = 2; else uid_size = 1; @@ -282,6 +285,24 @@ iso14443a_setopt(struct rfid_layer2_handle *handle, int optname, return ret; } +static int +iso14443a_getopt(struct rfid_layer2_handle *handle, int optname, + void *optval, unsigned int optlen) +{ + int ret = -EINVAL; + struct iso14443a_handle *h = &handle->priv.iso14443a; + struct iso14443a_atqa *atqa = optval; + + switch (optname) { + case RFID_OPT_14443A_ATQA: + *atqa = h->atqa; + ret = 0; + break; + }; + + return ret; +} + static struct rfid_layer2_handle * iso14443a_init(struct rfid_reader_handle *rh) @@ -291,6 +312,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; @@ -323,6 +346,7 @@ const struct rfid_layer2 rfid_layer2_iso14443a = { .close = &iso14443a_hlta, .fini = &iso14443a_fini, .setopt = &iso14443a_setopt, + .getopt = &iso14443a_getopt, }, };