From 8f19b078ff8666e773c2135c31eecf8b339275b3 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 19 Aug 2010 10:58:15 +0000 Subject: [PATCH 1/2] Add configuration option to enable/disable auto iso14443-4 mode. --- include/nfc/nfc-types.h | 4 +++- libnfc/chips/pn53x.h | 3 +++ libnfc/nfc.c | 11 +++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/nfc/nfc-types.h b/include/nfc/nfc-types.h index 61c02c9..eb5d57e 100644 --- a/include/nfc/nfc-types.h +++ b/include/nfc/nfc-types.h @@ -131,7 +131,9 @@ typedef enum { /** If this option is enabled, frames that carry less than 4 bits are allowed. According to the standards these frames should normally be handles as invalid frames. */ NDO_ACCEPT_INVALID_FRAMES = 0x30, /** If the NFC device should only listen to frames, it could be useful to let it gather multiple frames in a sequence. They will be stored in the internal FIFO of the PN53X chip. This could be retrieved by using the receive data functions. Note that if the chip runs out of bytes (FIFO = 64 bytes long), it will overwrite the first received frames, so quick retrieving of the received data is desirable. */ - NDO_ACCEPT_MULTIPLE_FRAMES = 0x31 + NDO_ACCEPT_MULTIPLE_FRAMES = 0x31, +/** This option can be used to enable or disable the auto-switching mode to ISO14443-4 is device is compliant */ + NDO_AUTO_ISO14443_4 = 0x40, } nfc_device_option_t; //////////////////////////////////////////////////////////////////// diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index 88130a8..566814e 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -50,6 +50,9 @@ #define REG_CIU_BIT_FRAMING 0x633D #define SYMBOL_TX_LAST_BITS 0x07 +#define SYMBOL_PARAM_fAutomaticRATS 0x10 +#define SYMBOL_PARAM_fAutomaticATR_RES 0x04 + // Internal parameters flags #define PARAM_NONE 0x00 #define PARAM_NAD_USED 0x01 diff --git a/libnfc/nfc.c b/libnfc/nfc.c index d2780a2..0879723 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -312,8 +312,15 @@ bool nfc_configure(nfc_device_t* pnd, const nfc_device_option_t ndo, const bool case NDO_ACCEPT_MULTIPLE_FRAMES: btValue = (bEnable) ? SYMBOL_RX_MULTIPLE : 0x00; if (!pn53x_set_reg(pnd,REG_CIU_RX_MODE,SYMBOL_RX_MULTIPLE,btValue)) return false; - return true; - + return true; + break; + + case NDO_AUTO_ISO14443_4: + // TODO: PN53x parameters could not be read, so we have to buffered current value in order to prevent from configuration overwrite + // ATM, buffered current value is not needed due to a single usage of these parameters + btValue = (bEnable) ? (SYMBOL_PARAM_fAutomaticRATS | SYMBOL_PARAM_fAutomaticATR_RES): SYMBOL_PARAM_fAutomaticATR_RES; + if(!pn53x_set_parameters(pnd,btValue)) return false; + return true; break; } From 040db45ae4aeb7790aa1a3667fbbce3f6a31c41c Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 19 Aug 2010 10:59:45 +0000 Subject: [PATCH 2/2] nfc-mfclassic: disable ISO14443-4 auto-switching in order to read devices that emulate Mifare Classic with ISO14443-4 compliance.(e.g. Nokia 6212 Classic) --- examples/nfc-mfclassic.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/nfc-mfclassic.c b/examples/nfc-mfclassic.c index 7b1e628..d6ae8b2 100644 --- a/examples/nfc-mfclassic.c +++ b/examples/nfc-mfclassic.c @@ -424,6 +424,9 @@ main (int argc, const char *argv[]) // Enable field so more power consuming cards can power themselves up nfc_configure (pnd, NDO_ACTIVATE_FIELD, true); + // Disable ISO14443-4 switching in order to read devices that emulate Mifare Classic with ISO14443-4 compliance. + nfc_configure(pnd, NDO_AUTO_ISO14443_4, false); + printf ("Connected to NFC reader: %s\n", pnd->acName); // Try to find a MIFARE Classic tag @@ -446,21 +449,21 @@ main (int argc, const char *argv[]) // Compare if key dump UID is the same as the current tag UID if (memcmp (nti.nai.abtUid, pbtUID, 4) != 0) { - printf ("Expected MIFARE Classic %cK card with UID: %02x%02x%02x%02x\n", b4K ? '4' : '1', pbtUID[3], pbtUID[2], + printf ("Expected MIFARE Classic %ck card with UID: %02x%02x%02x%02x\n", b4K ? '4' : '1', pbtUID[3], pbtUID[2], pbtUID[1], pbtUID[0]); } } // Get the info from the current tag pbtUID = nti.nai.abtUid; b4K = (nti.nai.abtAtqa[1] == 0x02); - printf ("Found MIFARE Classic %cK card with UID: %02x%02x%02x%02x\n", b4K ? '4' : '1', pbtUID[3], pbtUID[2], + printf ("Found MIFARE Classic %ck card with UID: %02x%02x%02x%02x\n", b4K ? '4' : '1', pbtUID[3], pbtUID[2], pbtUID[1], pbtUID[0]); uiBlocks = (b4K) ? 0xff : 0x3f; if (atAction == ACTION_READ) { if (read_card ()) { - printf ("Writing data to file: %s ... ", argv[3]); + printf ("Writing data to file: %s ...", argv[3]); fflush (stdout); pfDump = fopen (argv[3], "wb"); if (fwrite (&mtDump, 1, sizeof (mtDump), pfDump) != sizeof (mtDump)) {