X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=src%2Frfid_proto_mifare_ul.c;h=7243c89eb1ee4b24194f92fcba6f173fc4912591;hb=da107e125605438c7cf739ad34bb6204b3d4b85e;hp=747f38c17daf7580f4a7c8e63e57020e23682bf1;hpb=1fcc35aad699f3d40ca786b99c7255cf8aa55892;p=librfid diff --git a/src/rfid_proto_mifare_ul.c b/src/rfid_proto_mifare_ul.c index 747f38c..7243c89 100644 --- a/src/rfid_proto_mifare_ul.c +++ b/src/rfid_proto_mifare_ul.c @@ -1,7 +1,7 @@ /* Mifare Ultralight implementation, PCD side. * - * (C) 2005 by Harald Welte + * (C) 2005-2006 by Harald Welte * */ @@ -52,7 +52,7 @@ mful_read(struct rfid_protocol_handle *ph, unsigned int page, tx[0] = MIFARE_UL_CMD_READ; tx[1] = page & 0xff; - ret = rfid_layer2_transcieve(ph->l2h, RFID_14443A_FRAME_REGULAR, + ret = rfid_layer2_transceive(ph->l2h, RFID_14443A_FRAME_REGULAR, tx, sizeof(tx), rx_buf, &real_rx_len, MIFARE_UL_READ_FWT, 0); @@ -86,7 +86,7 @@ mful_write(struct rfid_protocol_handle *ph, unsigned int page, for (i = 0; i < 4; i++) tx[2+i] = tx_data[i]; - ret = rfid_layer2_transcieve(ph->l2h, RFID_14443A_FRAME_REGULAR, + ret = rfid_layer2_transceive(ph->l2h, RFID_14443A_FRAME_REGULAR, tx, sizeof(tx), rx, &rx_len, MIFARE_UL_WRITE_FWT, 0); @@ -100,7 +100,7 @@ mful_write(struct rfid_protocol_handle *ph, unsigned int page, } static int -mful_transcieve(struct rfid_protocol_handle *ph, +mful_transceive(struct rfid_protocol_handle *ph, const unsigned char *tx_data, unsigned int tx_len, unsigned char *rx_data, unsigned int *rx_len, unsigned int timeout, unsigned int flags) @@ -108,21 +108,56 @@ mful_transcieve(struct rfid_protocol_handle *ph, return -EINVAL; } +static int +mful_getopt(struct rfid_protocol_handle *ph, int optname, void *optval, + unsigned int *optlen) +{ + int ret = -EINVAL; + u_int16_t atqa; + unsigned int *size = optval; + + switch (optname) { + case RFID_OPT_PROTO_SIZE: + ret = 0; + *size = 512; + break; + } + + return ret; +} + + static struct rfid_protocol_handle * mful_init(struct rfid_layer2_handle *l2h) { struct rfid_protocol_handle *ph; - ph = malloc(sizeof(struct rfid_protocol_handle)); + u_int16_t atqa; + unsigned int atqa_len = sizeof(atqa); + + if (l2h->l2->id != RFID_LAYER2_ISO14443A) + return NULL; + + /* According to "Type Identification Procedure Rev. 1.3" */ + rfid_layer2_getopt(l2h, RFID_OPT_14443A_ATQA, + &atqa, &atqa_len); + if (atqa != 0x0044) + return NULL; + + /* according to "Functional Specification Rev. 3.0 */ + if (l2h->uid_len != 7) + return NULL; + + ph = malloc_protocol_handle(sizeof(struct rfid_protocol_handle)); return ph; } static int mful_fini(struct rfid_protocol_handle *ph) { - free(ph); + free_protocol_handle(ph); return 0; } -struct rfid_protocol rfid_protocol_mful = { +const struct rfid_protocol rfid_protocol_mful = { .id = RFID_PROTOCOL_MIFARE_UL, .name = "Mifare Ultralight", .fn = { @@ -130,6 +165,7 @@ struct rfid_protocol rfid_protocol_mful = { .read = &mful_read, .write = &mful_write, .fini = &mful_fini, + .getopt = &mful_getopt, }, };