From 5fed5fd6d775183e8416d5e5c9f3fae3742be038 Mon Sep 17 00:00:00 2001 From: laforge Date: Sat, 26 Jan 2008 09:29:56 +0000 Subject: mifare classic: * Use the officially specified FWT values * READ4 is only ultralight, not classic. So remove from classic codepath (Frederic RODO) git-svn-id: https://svn.gnumonks.org/trunk/librfid@2046 e0336214-984f-0b4b-a45f-81c69e1f0ede --- src/rfid_proto_mifare_classic.c | 64 +++++++++++------------------------------ 1 file changed, 17 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/rfid_proto_mifare_classic.c b/src/rfid_proto_mifare_classic.c index e981e51..fa9b4e2 100644 --- a/src/rfid_proto_mifare_classic.c +++ b/src/rfid_proto_mifare_classic.c @@ -38,9 +38,8 @@ #define MIFARE_UL_CMD_WRITE 0xA2 #define MIFARE_UL_CMD_READ 0x30 -/* FIXME */ -#define MIFARE_CL_READ_FWT 100 -#define MIFARE_CL_WRITE_FWT 100 +#define MIFARE_CL_READ_FWT 250 +#define MIFARE_CL_WRITE_FWT 600 static int mfcl_read(struct rfid_protocol_handle *ph, unsigned int page, @@ -79,7 +78,7 @@ static int mfcl_write(struct rfid_protocol_handle *ph, unsigned int page, unsigned char *tx_data, unsigned int tx_len) { - unsigned char tx[18]; + unsigned char tx[2]; unsigned char rx[1]; unsigned int rx_len = sizeof(rx); int ret; @@ -87,54 +86,25 @@ mfcl_write(struct rfid_protocol_handle *ph, unsigned int page, if (page > MIFARE_CL_PAGE_MAX) return -EINVAL; - if (tx_len != 16 && tx_len != 4) + if (tx_len != 16) return -EINVAL; - if (tx_len == 16) { - tx[0] = MIFARE_CL_CMD_WRITE16; - tx[1] = page & 0xff; - - ret = rfid_layer2_transceive(ph->l2h, RFID_MIFARE_FRAME, tx, - 2, rx, &rx_len, - MIFARE_CL_WRITE_FWT, 0); - if (ret < 0) - return ret; - - ret = rfid_layer2_transceive(ph->l2h, RFID_MIFARE_FRAME, tx_data, - tx_len, rx, &rx_len, - MIFARE_CL_WRITE_FWT, 0); - if (ret < 0) - return ret; - - if (rx[0] != MIFARE_UL_RESP_ACK) - return -EIO; - - ret = rfid_layer2_transceive(ph->l2h, RFID_MIFARE_FRAME, tx, - sizeof(tx), rx, &rx_len, - MIFARE_CL_WRITE_FWT, 0); - if (ret < 0) - return ret; - - if (rx[0] != MIFARE_UL_RESP_ACK) - return -EIO; - - } else if (tx_len == 4) { - - tx[0] = MIFARE_CL_CMD_WRITE4; - tx[1] = page & 0xff; - - memcpy(tx+2, tx_data, 4); + tx[0] = MIFARE_CL_CMD_WRITE16; + tx[1] = page & 0xff; - ret = rfid_layer2_transceive(ph->l2h, RFID_MIFARE_FRAME, tx, - 2+4, rx, &rx_len, - MIFARE_CL_WRITE_FWT, 0); - if (ret < 0) - return ret; + ret = rfid_layer2_transceive(ph->l2h, RFID_MIFARE_FRAME, tx, 2, rx, + &rx_len, MIFARE_CL_WRITE_FWT, 0); + if (ret < 0) + return ret; - if (rx[0] != MIFARE_UL_RESP_ACK) - return -EIO; + ret = rfid_layer2_transceive(ph->l2h, RFID_MIFARE_FRAME, tx_data, + tx_len, rx, &rx_len, + MIFARE_CL_WRITE_FWT, 0); + if (ret < 0) + return ret; - } + if (rx[0] != MIFARE_UL_RESP_ACK) + return -EIO; return ret; } -- cgit v1.2.3