X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=src%2Frfid_proto_mifare_classic.c;h=e98dc28e33a3e193de34c225a2902b46e84f724e;hb=683a381a3ef8d2c1c1f0c47337808d6a72e1309f;hp=4032b8013917df1a28c4fc26ae1934ad3568f5b5;hpb=3703fbd7ddc9068bddc59dc9096affda5ecb170d;p=librfid diff --git a/src/rfid_proto_mifare_classic.c b/src/rfid_proto_mifare_classic.c index 4032b80..e98dc28 100644 --- a/src/rfid_proto_mifare_classic.c +++ b/src/rfid_proto_mifare_classic.c @@ -82,7 +82,7 @@ mfcl_write(struct rfid_protocol_handle *ph, unsigned int page, unsigned int i; unsigned char tx[18]; unsigned char rx[1]; - unsigned int rx_len; + unsigned int rx_len = sizeof(rx); int ret; if (page > MIFARE_CL_PAGE_MAX) @@ -140,6 +140,35 @@ mfcl_write(struct rfid_protocol_handle *ph, unsigned int page, return ret; } +static int +mfcl_getopt(struct rfid_protocol_handle *ph, int optname, void *optval, + unsigned int *optlen) +{ + int ret = -EINVAL; + u_int16_t atqa; + unsigned int atqa_size = sizeof(atqa); + unsigned int *size = optval; + + switch (optname) { + case RFID_OPT_PROTO_SIZE: + if (*optlen < sizeof(*size)) + return -EINVAL; + *optlen = sizeof(*size); + ret = 0; + rfid_layer2_getopt(ph->l2h, RFID_OPT_14443A_ATQA, + (void *) &atqa, &atqa_size); + if (atqa == 0x0004) + *size = 1024; + else if (atqa == 0x0002) + *size = 4096; + else + ret = -EIO; + break; + } + + return ret; +} + static struct rfid_protocol_handle * mfcl_init(struct rfid_layer2_handle *l2h) { @@ -169,6 +198,7 @@ const struct rfid_protocol rfid_protocol_mfcl = { .read = &mfcl_read, .write = &mfcl_write, .fini = &mfcl_fini, + .getopt = &mfcl_getopt, }, };