From 0f8c23bdddcfe1bbfd2dde5ff4e47b543baaec93 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Fri, 7 Jan 2011 16:15:18 +0000 Subject: [PATCH] Inform user if target UID can be emulated New error: ETGUIDNOTSUP raised when UID is not 4 bytes long or does not start with 0x08 (Security restriction present in the NXP PN53x chips) --- configure.ac | 16 ++++++++-------- include/nfc/nfc.h | 11 +++++++---- libnfc/chips/pn53x.c | 11 +++++++++-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index cdfea5c..d80ab80 100644 --- a/configure.ac +++ b/configure.ac @@ -147,18 +147,18 @@ CFLAGS="$CFLAGS -std=c99" CFLAGS="$CFLAGS -Du_int8_t=uint8_t -Du_int16_t=uint16_t" AC_CONFIG_FILES([ + Doxyfile Makefile + cmake_modules/Makefile + examples/Makefile include/Makefile include/nfc/Makefile - libnfc/chips/Makefile - libnfc/buses/Makefile - libnfc/drivers/Makefile - libnfc/Makefile - examples/Makefile - cmake_modules/Makefile - test/Makefile libnfc.pc - Doxyfile + libnfc/Makefile + libnfc/buses/Makefile + libnfc/chips/Makefile + libnfc/drivers/Makefile + test/Makefile ]) AC_OUTPUT diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index 6387ddc..b814b1a 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -128,7 +128,7 @@ extern "C" { #define EDEPUNKCMD 0x12 #define EINVRXFRAM 0x13 #define EMFAUTH 0x14 -#define ENSECNOTSUPP 0x18 // PN533 +#define ENSECNOTSUPP 0x18 // PN533 only #define EBCC 0x23 #define EDEPINVSTATE 0x25 #define EOPNOTALL 0x26 @@ -140,10 +140,13 @@ extern "C" { #define EOVCURRENT 0x2d #define ENAD 0x2e +/* Software level errors */ +#define ETGUIDNOTSUP 0x0100 /* Target UID not supported */ + /* Common device-level errors */ -# define DEIO 0x1000/* Input/output error */ -# define DEINVAL 0x2000/* Invalid argument */ -# define DETIMEOUT 0x3000/* Operation timeout */ +#define DEIO 0x1000 /* Input/output error */ +#define DEINVAL 0x2000 /* Invalid argument */ +#define DETIMEOUT 0x3000 /* Operation timeout */ # ifdef __cplusplus } diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 864b75c..824f7f8 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -759,7 +759,9 @@ static struct sErrorMessage { { ENFCID3, "NFCID3 Mismatch" }, { EOVCURRENT, "Over Current" }, { ENAD, "NAD Missing in DEP Frame" }, - /* Driver-level error */ + /* Software level errors */ + { ETGUIDNOTSUP, "Target UID not supported" }, // In target mode, PN53x only support 4 bytes UID and the first byte must start with 0x08 + /* Driver-level errors */ { DENACK, "Received NACK" }, { DEACKMISMATCH, "Expected ACK/NACK" }, { DEISERRFRAME, "Received an error frame" }, @@ -1177,9 +1179,14 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_ switch (pnt->nm.nmt) { case NMT_ISO14443A: ptm = PTM_PASSIVE_ONLY; + if ((pnt->nti.nai.abtUid[0] != 0x08) || (pnt->nti.nai.szUidLen != 4)) { + pnd->iLastError = ETGUIDNOTSUP; + return false; + } pn53x_set_parameter(pnd, PARAM_AUTO_ATR_RES, false); if (pnd->nc == NC_PN532) { // We have a PN532 - if ((pnt->nti.nai.btSak & SAK_ISO14443_4_COMPLIANT) && (pnd->bAutoIso14443_4)) { // We have a ISO14443-4 tag to emulate and NDO_AUTO_14443_4A option is enabled + if ((pnt->nti.nai.btSak & SAK_ISO14443_4_COMPLIANT) && (pnd->bAutoIso14443_4)) { + // We have a ISO14443-4 tag to emulate and NDO_AUTO_14443_4A option is enabled ptm |= PTM_ISO14443_4_PICC_ONLY; // We add ISO14443-4 restriction pn53x_set_parameter(pnd, PARAM_14443_4_PICC, true); } else {