From 8fc39fd25b56eeb4b5f80c6a4e0504600eb01a8d Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 22 Oct 2005 17:55:57 +0000 Subject: [PATCH] mifare ultraligh have pages 0-15, not only 0-7 git-svn-id: https://svn.gnumonks.org/trunk/librfid@1552 e0336214-984f-0b4b-a45f-81c69e1f0ede --- include/rfid/rfid_protocol_mifare_ul.h | 9 +++++++++ rfid_proto_mifare_ul.c | 21 ++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/rfid/rfid_protocol_mifare_ul.h b/include/rfid/rfid_protocol_mifare_ul.h index 34d246a..6cdec22 100644 --- a/include/rfid/rfid_protocol_mifare_ul.h +++ b/include/rfid/rfid_protocol_mifare_ul.h @@ -1,6 +1,15 @@ #ifndef _RFID_PROTOCOL_MFUL_H #define _RFID_PROTOCOL_MFUL_H + +#define MIFARE_UL_CMD_WRITE 0xA2 +#define MIFARE_UL_CMD_READ 0x30 + +#define MIFARE_UL_RESP_ACK 0x0a +#define MIFARE_UL_RESP_NAK 0x00 + +#define MIFARE_UL_PAGE_MAX 15 + struct rfid_protocol rfid_protocol_mful; #endif diff --git a/rfid_proto_mifare_ul.c b/rfid_proto_mifare_ul.c index 3fec95b..1d80702 100644 --- a/rfid_proto_mifare_ul.c +++ b/rfid_proto_mifare_ul.c @@ -28,7 +28,7 @@ #include #include #include -//#include +#include //#include //#include @@ -36,9 +36,6 @@ #include "rfid_iso14443_common.h" -#define MIFARE_UL_CMD_WRITE 0xA2 -#define MIFARE_UL_CMD_READ 0x30 - /* FIXME */ #define MIFARE_UL_READ_FWT 100 #define MIFARE_UL_WRITE_FWT 100 @@ -52,7 +49,7 @@ mful_read(struct rfid_protocol_handle *ph, unsigned int page, unsigned char tx[2]; int ret; - if (page > 7) + if (page > MIFARE_UL_PAGE_MAX) return -EINVAL; tx[0] = MIFARE_UL_CMD_READ; @@ -78,12 +75,14 @@ mful_write(struct rfid_protocol_handle *ph, unsigned int page, { unsigned int i; unsigned char tx[6]; - unsigned char rx[1]; - unsigned int rx_len; + unsigned char rx[10]; + unsigned int rx_len = sizeof(rx); int ret; - if (tx_len != 4 || page > 7) +#if 0 + if (tx_len != 4 || page > MIFARE_UL_PAGE_MAX) return -EINVAL; +#endif tx[0] = MIFARE_UL_CMD_WRITE; tx[1] = page & 0xff; @@ -94,7 +93,11 @@ mful_write(struct rfid_protocol_handle *ph, unsigned int page, ret = ph->l2h->l2->fn.transcieve(ph->l2h, tx, sizeof(tx), rx, &rx_len, MIFARE_UL_WRITE_FWT, 0); - /* FIXME:look at RX, check for ACK/NAK */ + if (ret < 0) + return ret; + + if (rx[0] != MIFARE_UL_RESP_ACK) + return -EIO; return ret; } -- 2.20.1