diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index ad9b676..866a1f6 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -167,6 +167,11 @@ main (int argc, char *argv[]) nfc_perror (pnd, "nfc_configure"); exit (EXIT_FAILURE); } + // Force 14443-A mode + if (!nfc_configure (pnd, NDO_FORCE_ISO14443_A, true)) { + nfc_perror (pnd, "nfc_configure"); + exit (EXIT_FAILURE); + } // Enable field so more power consuming cards can power themselves up if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, true)) { diff --git a/include/nfc/nfc-types.h b/include/nfc/nfc-types.h index e63c24e..38b86f2 100644 --- a/include/nfc/nfc-types.h +++ b/include/nfc/nfc-types.h @@ -162,6 +162,8 @@ typedef enum { NDO_AUTO_ISO14443_4 = 0x40, /** Use automatic frames encapsulation and chaining. */ NDO_EASY_FRAMING = 0x41, +/** Force the chip to switch in ISO14443-A */ + NDO_FORCE_ISO14443_A = 0x42, } nfc_device_option_t; //////////////////////////////////////////////////////////////////// diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 5aeb4c4..d2e0885 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -708,12 +708,26 @@ pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool b 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; + btValue = (bEnable) ? (SYMBOL_PARAM_fAutomaticRATS | SYMBOL_PARAM_fAutomaticATR_RES) : SYMBOL_PARAM_fAutomaticATR_RES; if (!pn53x_set_parameters (pnd, btValue)) return false; return true; break; + + case NDO_FORCE_ISO14443_A: + if(!bEnable) { + // Nothing to do + return true; + } + // Force pn53x to be in ISO1444-A mode + if (!pn53x_set_reg (pnd, REG_CIU_TX_MODE, SYMBOL_TX_FRAMING, 0x00)) { + return false; + } + if (!pn53x_set_reg (pnd, REG_CIU_RX_MODE, SYMBOL_RX_FRAMING, 0x00)) { + return false; + } + return true; + break; } // When we reach this, the configuration is completed and succesful diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index 19e80f5..3efebc4 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -32,21 +32,35 @@ // Registers and symbols masks used to covers parts within a register # define REG_CIU_TX_MODE 0x6302 # define SYMBOL_TX_CRC_ENABLE 0x80 +// TX_FRAMING bits explanation: +// 00 : ISO/IEC 14443A/MIFARE and Passive Communication mode 106 kbit/s +// 01 : Active Communication mode +// 10 : FeliCa and Passive Communication mode at 212 kbit/s and 424 kbit/s +// 11 : ISO/IEC 14443B +# define SYMBOL_TX_FRAMING 0x03 + # define REG_CIU_RX_MODE 0x6303 # define SYMBOL_RX_CRC_ENABLE 0x80 # define SYMBOL_RX_NO_ERROR 0x08 # define SYMBOL_RX_MULTIPLE 0x04 +// RX_FRAMING follow same scheme than TX_FRAMING +# define SYMBOL_RX_FRAMING 0x03 + # define REG_CIU_TX_AUTO 0x6305 # define SYMBOL_FORCE_100_ASK 0x40 # define SYMBOL_AUTO_WAKE_UP 0x20 # define SYMBOL_INITIAL_RF_ON 0x04 + # define REG_CIU_MANUAL_RCV 0x630D # define SYMBOL_PARITY_DISABLE 0x10 + # define REG_CIU_STATUS2 0x6338 # define SYMBOL_MF_CRYPTO1_ON 0x08 + # define REG_CIU_CONTROL 0x633C # define SYMBOL_INITIATOR 0x10 # define SYMBOL_RX_LAST_BITS 0x07 + # define REG_CIU_BIT_FRAMING 0x633D # define SYMBOL_TX_LAST_BITS 0x07