nfc_properties replace now nfc_options and nfc_configure is replaced by nfc_device_set_property_bool which returns error code.
This commit is contained in:
parent
c181cb35ec
commit
a615d969fd
20 changed files with 292 additions and 298 deletions
|
@ -160,18 +160,18 @@ main (int argc, char *argv[])
|
|||
nfc_initiator_init (pnd);
|
||||
|
||||
// Configure the CRC
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// Use raw send/receive methods
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// Disable 14443-4 autoswitching
|
||||
if (!nfc_configure (pnd, NDO_AUTO_ISO14443_4, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ nfc_target_emulate_tag(nfc_device *pnd, nfc_target *pnt)
|
|||
}
|
||||
if ( loop ) {
|
||||
if ( init_mfc_auth ) {
|
||||
nfc_configure (pnd, NDO_HANDLE_CRC, false);
|
||||
nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false);
|
||||
init_mfc_auth = false;
|
||||
}
|
||||
if (!nfc_target_receive_bytes(pnd, abtRx, &szRx, 0)) {
|
||||
|
@ -257,8 +257,8 @@ main (int argc, char *argv[])
|
|||
printf ("%s will emulate this ISO14443-A tag:\n", argv[0]);
|
||||
print_nfc_iso14443a_info (nt.nti.nai, true);
|
||||
|
||||
// Switch off NDO_EASY_FRAMING if target is not ISO14443-4
|
||||
nfc_configure (pnd, NDO_EASY_FRAMING, (nt.nti.nai.btSak & SAK_ISO14443_4_COMPLIANT));
|
||||
// Switch off NP_EASY_FRAMING if target is not ISO14443-4
|
||||
nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, (nt.nti.nai.btSak & SAK_ISO14443_4_COMPLIANT));
|
||||
printf ("NFC device (configured as target) is now emulating the tag, please touch it with a second NFC device (initiator)\n");
|
||||
if (!nfc_target_emulate_tag (pnd, &nt)) {
|
||||
nfc_perror (pnd, "nfc_target_emulate_tag");
|
||||
|
|
|
@ -163,8 +163,8 @@ main (int argc, char *argv[])
|
|||
printf ("[+] Received initiator command: ");
|
||||
print_hex_bits (abtRecv, szRecvBits);
|
||||
printf ("[+] Configuring communication\n");
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, false) || !nfc_configure (pnd, NDO_HANDLE_PARITY, true)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if ((nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false) < 0) || (nfc_device_set_property_bool (pnd, NP_HANDLE_PARITY, true) < 0)) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
printf ("[+] Done, the emulated tag is initialized with UID: %02X%02X%02X%02X\n\n", abtUidBcc[0], abtUidBcc[1],
|
||||
|
|
|
@ -152,9 +152,9 @@ main (int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
printf ("%s", "Configuring emulator settings...");
|
||||
if (!nfc_configure (pndTag, NDO_HANDLE_CRC, false) ||
|
||||
!nfc_configure (pndTag, NDO_HANDLE_PARITY, false) || !nfc_configure (pndTag, NDO_ACCEPT_INVALID_FRAMES, true)) {
|
||||
nfc_perror (pndTag, "nfc_configure");
|
||||
if ((nfc_device_set_property_bool (pndTag, NP_HANDLE_CRC, false) < 0) ||
|
||||
(nfc_device_set_property_bool (pndTag, NP_HANDLE_PARITY, false) < 0) || (nfc_device_set_property_bool (pndTag, NP_ACCEPT_INVALID_FRAMES, true)) < 0) {
|
||||
nfc_perror (pndTag, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
printf ("%s", "Done, emulated tag is initialized");
|
||||
|
@ -165,10 +165,10 @@ main (int argc, char *argv[])
|
|||
printf ("Connected to the NFC reader device: %s", pndReader->acName);
|
||||
printf ("%s", "Configuring NFC reader settings...");
|
||||
nfc_initiator_init (pndReader);
|
||||
if (!nfc_configure (pndReader, NDO_HANDLE_CRC, false) ||
|
||||
!nfc_configure (pndReader, NDO_HANDLE_PARITY, false) ||
|
||||
!nfc_configure (pndReader, NDO_ACCEPT_INVALID_FRAMES, true)) {
|
||||
nfc_perror (pndReader, "nfc_configure");
|
||||
if ((nfc_device_set_property_bool (pndReader, NP_HANDLE_CRC, false) < 0) ||
|
||||
(nfc_device_set_property_bool (pndReader, NP_HANDLE_PARITY, false) < 0) ||
|
||||
(nfc_device_set_property_bool (pndReader, NP_ACCEPT_INVALID_FRAMES, true)) < 0) {
|
||||
nfc_perror (pndReader, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
printf ("%s", "Done, relaying frames now!");
|
||||
|
@ -179,14 +179,14 @@ main (int argc, char *argv[])
|
|||
// Drop down the field before sending a REQA command and start a new session
|
||||
if (szReaderRxBits == 7 && abtReaderRx[0] == 0x26) {
|
||||
// Drop down field for a very short time (original tag will reboot)
|
||||
if (!nfc_configure (pndReader, NDO_ACTIVATE_FIELD, false)) {
|
||||
nfc_perror (pndReader, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pndReader, NP_ACTIVATE_FIELD, false) < 0) {
|
||||
nfc_perror (pndReader, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (!quiet_output)
|
||||
printf ("\n");
|
||||
if (!nfc_configure (pndReader, NDO_ACTIVATE_FIELD, true)) {
|
||||
nfc_perror (pndReader, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pndReader, NP_ACTIVATE_FIELD, true) < 0) {
|
||||
nfc_perror (pndReader, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,8 +131,8 @@ main (int argc, const char *argv[])
|
|||
nfc_initiator_init (pnd);
|
||||
|
||||
// Let the reader only try once to find a tag
|
||||
if (!nfc_configure (pnd, NDO_INFINITE_SELECT, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// Read the SAM's info
|
||||
|
|
|
@ -96,24 +96,14 @@ typedef enum {
|
|||
* Default value for this property is 52 ms).
|
||||
*/
|
||||
NP_TIMEOUT_COM,
|
||||
} nfc_property;
|
||||
|
||||
// Compiler directive, set struct alignment to 1 uint8_t for compatibility
|
||||
# pragma pack(1)
|
||||
|
||||
/**
|
||||
* @enum nfc_device_option
|
||||
* @brief NFC device option
|
||||
*/
|
||||
typedef enum {
|
||||
/** Let the PN53X chip handle the CRC bytes. This means that the chip appends
|
||||
/** Let the PN53X chip handle the CRC bytes. This means that the chip appends
|
||||
* the CRC bytes to the frames that are transmitted. It will parse the last
|
||||
* bytes from received frames as incoming CRC bytes. They will be verified
|
||||
* against the used modulation and protocol. If an frame is expected with
|
||||
* incorrect CRC bytes this option should be disabled. Example frames where
|
||||
* this is useful are the ATQA and UID+BCC that are transmitted without CRC
|
||||
* bytes during the anti-collision phase of the ISO14443-A protocol. */
|
||||
NDO_HANDLE_CRC = 0x00,
|
||||
NP_HANDLE_CRC = 0x00,
|
||||
/** Parity bits in the network layer of ISO14443-A are by default generated and
|
||||
* validated in the PN53X chip. This is a very convenient feature. On certain
|
||||
* times though it is useful to get full control of the transmitted data. The
|
||||
|
@ -121,31 +111,31 @@ typedef enum {
|
|||
* parity bits. For interoperability it is required to be completely
|
||||
* compatible, including the arbitrary parity bits. When this option is
|
||||
* disabled, the functions to communicating bits should be used. */
|
||||
NDO_HANDLE_PARITY = 0x01,
|
||||
NP_HANDLE_PARITY = 0x01,
|
||||
/** This option can be used to enable or disable the electronic field of the
|
||||
* NFC device. */
|
||||
NDO_ACTIVATE_FIELD = 0x10,
|
||||
NP_ACTIVATE_FIELD = 0x10,
|
||||
/** The internal CRYPTO1 co-processor can be used to transmit messages
|
||||
* encrypted. This option is automatically activated after a successful MIFARE
|
||||
* Classic authentication. */
|
||||
NDO_ACTIVATE_CRYPTO1 = 0x11,
|
||||
NP_ACTIVATE_CRYPTO1 = 0x11,
|
||||
/** The default configuration defines that the PN53X chip will try indefinitely
|
||||
* to invite a tag in the field to respond. This could be desired when it is
|
||||
* certain a tag will enter the field. On the other hand, when this is
|
||||
* uncertain, it will block the application. This option could best be compared
|
||||
* to the (NON)BLOCKING option used by (socket)network programming. */
|
||||
NDO_INFINITE_SELECT = 0x20,
|
||||
NP_INFINITE_SELECT = 0x20,
|
||||
/** 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,
|
||||
NP_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,
|
||||
NP_ACCEPT_MULTIPLE_FRAMES = 0x31,
|
||||
/** This option can be used to enable or disable the auto-switching mode to
|
||||
* ISO14443-4 is device is compliant.
|
||||
* In initiator mode, it means that NFC chip will send RATS automatically when
|
||||
|
@ -153,16 +143,19 @@ typedef enum {
|
|||
* requested.
|
||||
* In target mode, with a NFC chip compiliant (ie. PN532), the chip will
|
||||
* emulate a 14443-4 PICC using hardware capability */
|
||||
NDO_AUTO_ISO14443_4 = 0x40,
|
||||
NP_AUTO_ISO14443_4 = 0x40,
|
||||
/** Use automatic frames encapsulation and chaining. */
|
||||
NDO_EASY_FRAMING = 0x41,
|
||||
NP_EASY_FRAMING = 0x41,
|
||||
/** Force the chip to switch in ISO14443-A */
|
||||
NDO_FORCE_ISO14443_A = 0x42,
|
||||
NP_FORCE_ISO14443_A = 0x42,
|
||||
/** Force the chip to switch in ISO14443-B */
|
||||
NDO_FORCE_ISO14443_B = 0x43,
|
||||
NP_FORCE_ISO14443_B = 0x43,
|
||||
/** Force the chip to run at 106 kbps */
|
||||
NDO_FORCE_SPEED_106 = 0x50,
|
||||
} nfc_device_option;
|
||||
NP_FORCE_SPEED_106 = 0x50,
|
||||
} nfc_property;
|
||||
|
||||
// Compiler directive, set struct alignment to 1 uint8_t for compatibility
|
||||
# pragma pack(1)
|
||||
|
||||
/**
|
||||
* @enum nfc_dep_mode
|
||||
|
|
|
@ -68,7 +68,6 @@ extern "C" {
|
|||
NFC_EXPORT void nfc_disconnect (nfc_device *pnd);
|
||||
NFC_EXPORT bool nfc_abort_command (nfc_device *pnd);
|
||||
NFC_EXPORT void nfc_list_devices (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
|
||||
NFC_EXPORT bool nfc_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable);
|
||||
NFC_EXPORT bool nfc_idle (nfc_device *pnd);
|
||||
|
||||
/* NFC initiator: act as "reader" */
|
||||
|
@ -100,7 +99,7 @@ extern "C" {
|
|||
|
||||
/* Properties accessors */
|
||||
NFC_EXPORT int nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const int value);
|
||||
// NFC_EXPORT int nfc_device_set_property_bool (nfc_device *pnd, const nfc_property property, const int value);
|
||||
NFC_EXPORT int nfc_device_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable);
|
||||
|
||||
/* Misc. functions */
|
||||
NFC_EXPORT void iso14443a_crc (uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc);
|
||||
|
@ -113,6 +112,7 @@ extern "C" {
|
|||
#define NFC_EIO -1 // Input / output error, device will not be usable anymore
|
||||
#define NFC_ENOTSUP -2 // Operation not supported
|
||||
#define NFC_EINVARG -3 // Invalid argument(s)
|
||||
#define NFC_DEVICE_ERROR -4 //Device error
|
||||
|
||||
/* PN53x specific errors */
|
||||
// TODO: Be not PN53x-specific here
|
||||
|
|
|
@ -643,143 +643,6 @@ pn53x_get_firmware_version (nfc_device *pnd, char abtFirmwareText[22])
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
pn53x_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable)
|
||||
{
|
||||
uint8_t btValue;
|
||||
switch (ndo) {
|
||||
case NDO_HANDLE_CRC:
|
||||
// Enable or disable automatic receiving/sending of CRC bytes
|
||||
if (bEnable == pnd->bCrc) {
|
||||
// Nothing to do
|
||||
return true;
|
||||
}
|
||||
// TX and RX are both represented by the symbol 0x80
|
||||
btValue = (bEnable) ? 0x80 : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_CRC_ENABLE, btValue))
|
||||
return false;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_CRC_ENABLE, btValue))
|
||||
return false;
|
||||
pnd->bCrc = bEnable;
|
||||
break;
|
||||
|
||||
case NDO_HANDLE_PARITY:
|
||||
// Handle parity bit by PN53X chip or parse it as data bit
|
||||
if (bEnable == pnd->bPar)
|
||||
// Nothing to do
|
||||
return true;
|
||||
btValue = (bEnable) ? 0x00 : SYMBOL_PARITY_DISABLE;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_ManualRCV, SYMBOL_PARITY_DISABLE, btValue))
|
||||
return false;
|
||||
pnd->bPar = bEnable;
|
||||
break;
|
||||
|
||||
case NDO_EASY_FRAMING:
|
||||
pnd->bEasyFraming = bEnable;
|
||||
break;
|
||||
|
||||
case NDO_ACTIVATE_FIELD:
|
||||
{
|
||||
return pn53x_RFConfiguration__RF_field (pnd, bEnable);
|
||||
}
|
||||
break;
|
||||
|
||||
case NDO_ACTIVATE_CRYPTO1:
|
||||
btValue = (bEnable) ? SYMBOL_MF_CRYPTO1_ON : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_Status2, SYMBOL_MF_CRYPTO1_ON, btValue))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case NDO_INFINITE_SELECT:
|
||||
{
|
||||
// TODO Made some research around this point:
|
||||
// timings could be tweak better than this, and maybe we can tweak timings
|
||||
// to "gain" a sort-of hardware polling (ie. like PN532 does)
|
||||
return pn53x_RFConfiguration__MaxRetries (pnd,
|
||||
(bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02
|
||||
(bEnable) ? 0xff : 0x00, // MxRtyPSL, default: 0x01
|
||||
(bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case NDO_ACCEPT_INVALID_FRAMES:
|
||||
btValue = (bEnable) ? SYMBOL_RX_NO_ERROR : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_NO_ERROR, btValue))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case NDO_ACCEPT_MULTIPLE_FRAMES:
|
||||
btValue = (bEnable) ? SYMBOL_RX_MULTIPLE : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_MULTIPLE, btValue))
|
||||
return false;
|
||||
return true;
|
||||
break;
|
||||
|
||||
case NDO_AUTO_ISO14443_4:
|
||||
if (bEnable == pnd->bAutoIso14443_4)
|
||||
// Nothing to do
|
||||
return true;
|
||||
pnd->bAutoIso14443_4 = bEnable;
|
||||
return pn53x_set_parameters (pnd, PARAM_AUTO_RATS, bEnable);
|
||||
break;
|
||||
|
||||
case NDO_FORCE_ISO14443_A:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return true;
|
||||
}
|
||||
// Force pn53x to be in ISO14443-A mode
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_FRAMING, 0x00)) {
|
||||
return false;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_FRAMING, 0x00)) {
|
||||
return false;
|
||||
}
|
||||
// Set the PN53X to force 100% ASK Modified miller decoding (default for 14443A cards)
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxAuto, SYMBOL_FORCE_100_ASK, 0x40))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
break;
|
||||
|
||||
case NDO_FORCE_ISO14443_B:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return true;
|
||||
}
|
||||
// Force pn53x to be in ISO14443-B mode
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_FRAMING, 0x03)) {
|
||||
return false;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_FRAMING, 0x03)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
break;
|
||||
|
||||
case NDO_FORCE_SPEED_106:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return true;
|
||||
}
|
||||
// Force pn53x to be at 106 kbps
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_SPEED, 0x00)) {
|
||||
return false;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_SPEED, 0x00)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
|
||||
// When we reach this, the configuration is completed and successful
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
pn53x_int_to_timeout (const int ms)
|
||||
{
|
||||
|
@ -816,6 +679,143 @@ pn53x_set_property_int (nfc_device *pnd, const nfc_property property, const int
|
|||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
pn53x_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable)
|
||||
{
|
||||
uint8_t btValue;
|
||||
switch (property) {
|
||||
case NP_HANDLE_CRC:
|
||||
// Enable or disable automatic receiving/sending of CRC bytes
|
||||
if (bEnable == pnd->bCrc) {
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
// TX and RX are both represented by the symbol 0x80
|
||||
btValue = (bEnable) ? 0x80 : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_CRC_ENABLE, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_CRC_ENABLE, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
pnd->bCrc = bEnable;
|
||||
break;
|
||||
|
||||
case NP_HANDLE_PARITY:
|
||||
// Handle parity bit by PN53X chip or parse it as data bit
|
||||
if (bEnable == pnd->bPar)
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
btValue = (bEnable) ? 0x00 : SYMBOL_PARITY_DISABLE;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_ManualRCV, SYMBOL_PARITY_DISABLE, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
pnd->bPar = bEnable;
|
||||
break;
|
||||
|
||||
case NP_EASY_FRAMING:
|
||||
pnd->bEasyFraming = bEnable;
|
||||
break;
|
||||
|
||||
case NP_ACTIVATE_FIELD:
|
||||
{
|
||||
return pn53x_RFConfiguration__RF_field (pnd, bEnable);
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_ACTIVATE_CRYPTO1:
|
||||
btValue = (bEnable) ? SYMBOL_MF_CRYPTO1_ON : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_Status2, SYMBOL_MF_CRYPTO1_ON, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
break;
|
||||
|
||||
case NP_INFINITE_SELECT:
|
||||
{
|
||||
// TODO Made some research around this point:
|
||||
// timings could be tweak better than this, and maybe we can tweak timings
|
||||
// to "gain" a sort-of hardware polling (ie. like PN532 does)
|
||||
return pn53x_RFConfiguration__MaxRetries (pnd,
|
||||
(bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02
|
||||
(bEnable) ? 0xff : 0x00, // MxRtyPSL, default: 0x01
|
||||
(bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_ACCEPT_INVALID_FRAMES:
|
||||
btValue = (bEnable) ? SYMBOL_RX_NO_ERROR : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_NO_ERROR, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
break;
|
||||
|
||||
case NP_ACCEPT_MULTIPLE_FRAMES:
|
||||
btValue = (bEnable) ? SYMBOL_RX_MULTIPLE : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_MULTIPLE, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
return NFC_SUCCESS;
|
||||
break;
|
||||
|
||||
case NP_AUTO_ISO14443_4:
|
||||
if (bEnable == pnd->bAutoIso14443_4)
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
pnd->bAutoIso14443_4 = bEnable;
|
||||
return pn53x_set_parameters (pnd, PARAM_AUTO_RATS, bEnable);
|
||||
break;
|
||||
|
||||
case NP_FORCE_ISO14443_A:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
// Force pn53x to be in ISO14443-A mode
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_FRAMING, 0x00)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_FRAMING, 0x00)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
// Set the PN53X to force 100% ASK Modified miller decoding (default for 14443A cards)
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxAuto, SYMBOL_FORCE_100_ASK, 0x40))
|
||||
return NFC_DEVICE_ERROR;
|
||||
|
||||
return NFC_SUCCESS;
|
||||
break;
|
||||
|
||||
case NP_FORCE_ISO14443_B:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
// Force pn53x to be in ISO14443-B mode
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_FRAMING, 0x03)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_FRAMING, 0x03)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
return NFC_SUCCESS;
|
||||
break;
|
||||
|
||||
case NP_FORCE_SPEED_106:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
// Force pn53x to be at 106 kbps
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_SPEED, 0x00)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_SPEED, 0x00)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
return NFC_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
// When we reach this, the configuration is completed and successful
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
bool
|
||||
pn53x_idle (nfc_device *pnd)
|
||||
{
|
||||
|
@ -840,7 +840,7 @@ pn53x_idle (nfc_device *pnd)
|
|||
return false;
|
||||
}
|
||||
// Disable RF field to avoid heating
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, false)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (CHIP_DATA (pnd)->type == PN532) {
|
||||
|
@ -908,13 +908,13 @@ pn53x_initiator_select_passive_target_ext (nfc_device *pnd,
|
|||
return false;
|
||||
}
|
||||
// No native support in InListPassiveTarget so we do discovery by hand
|
||||
if (!nfc_configure (pnd, NDO_FORCE_ISO14443_B, true)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_FORCE_ISO14443_B, true) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (!nfc_configure (pnd, NDO_FORCE_SPEED_106, true)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_FORCE_SPEED_106, true) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, true)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true) < 0) {
|
||||
return false;
|
||||
}
|
||||
pnd->bEasyFraming = false;
|
||||
|
@ -1051,7 +1051,7 @@ pn53x_initiator_poll_target (nfc_device *pnd,
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
pn53x_configure (pnd, NDO_INFINITE_SELECT, true);
|
||||
pn53x_set_property_bool (pnd, NP_INFINITE_SELECT, true);
|
||||
// FIXME It does not support DEP targets
|
||||
do {
|
||||
for (size_t p=0; p<uiPollNr; p++) {
|
||||
|
@ -1527,7 +1527,7 @@ pn53x_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *psz
|
|||
pn53x_set_parameters (pnd, PARAM_AUTO_ATR_RES, false);
|
||||
if (CHIP_DATA(pnd)->type == 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
|
||||
// We have a ISO14443-4 tag to emulate and NP_AUTO_14443_4A option is enabled
|
||||
ptm |= PTM_ISO14443_4_PICC_ONLY; // We add ISO14443-4 restriction
|
||||
pn53x_set_parameters (pnd, PARAM_14443_4_PICC, true);
|
||||
} else {
|
||||
|
|
|
@ -276,8 +276,8 @@ bool pn53x_decode_target_data (const uint8_t *pbtRawData, size_t szRawData,
|
|||
bool pn53x_read_register (nfc_device *pnd, uint16_t ui16Reg, uint8_t *ui8Value);
|
||||
bool pn53x_write_register (nfc_device *pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value);
|
||||
bool pn53x_get_firmware_version (nfc_device *pnd, char abtFirmwareText[22]);
|
||||
bool pn53x_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable);
|
||||
int pn53x_set_property_int (nfc_device *pnd, const nfc_property property, const int value);
|
||||
int pn53x_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable);
|
||||
|
||||
bool pn53x_check_communication (nfc_device *pnd);
|
||||
bool pn53x_idle (nfc_device *pnd);
|
||||
|
|
|
@ -487,7 +487,7 @@ const struct nfc_driver_t acr122_driver = {
|
|||
.target_send_bits = pn53x_target_send_bits,
|
||||
.target_receive_bits = pn53x_target_receive_bits,
|
||||
|
||||
.configure = pn53x_configure,
|
||||
.device_set_property_bool = pn53x_set_property_bool,
|
||||
.device_set_property_int = pn53x_set_property_int,
|
||||
|
||||
.abort_command = NULL, // FIXME: abort is not supported in this driver
|
||||
|
|
|
@ -579,7 +579,7 @@ const struct nfc_driver_t arygon_driver = {
|
|||
.target_send_bits = pn53x_target_send_bits,
|
||||
.target_receive_bits = pn53x_target_receive_bits,
|
||||
|
||||
.configure = pn53x_configure,
|
||||
.device_set_property_bool = pn53x_set_property_bool,
|
||||
.device_set_property_int = pn53x_set_property_int,
|
||||
|
||||
.abort_command = arygon_abort_command,
|
||||
|
|
|
@ -525,7 +525,7 @@ const struct nfc_driver_t pn532_uart_driver = {
|
|||
.target_send_bits = pn53x_target_send_bits,
|
||||
.target_receive_bits = pn53x_target_receive_bits,
|
||||
|
||||
.configure = pn53x_configure,
|
||||
.device_set_property_bool = pn53x_set_property_bool,
|
||||
.device_set_property_int = pn53x_set_property_int,
|
||||
|
||||
.abort_command = pn532_uart_abort_command,
|
||||
|
|
|
@ -751,32 +751,32 @@ On ASK LoGO hardware:
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
pn53x_usb_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable)
|
||||
int
|
||||
pn53x_usb_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable)
|
||||
{
|
||||
if (!pn53x_configure (pnd, ndo, bEnable))
|
||||
return false;
|
||||
if (!pn53x_set_property_bool (pnd, property, bEnable))
|
||||
return NFC_DEVICE_ERROR;
|
||||
|
||||
switch (DRIVER_DATA (pnd)->model) {
|
||||
case ASK_LOGO:
|
||||
if (NDO_ACTIVATE_FIELD == ndo) {
|
||||
if (NP_ACTIVATE_FIELD == property) {
|
||||
/* Switch on/off LED2 and Progressive Field GPIO according to ACTIVATE_FIELD option */
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Switch progressive field %s", bEnable ? "On" : "Off");
|
||||
if (!pn53x_write_register (pnd, PN53X_SFR_P3, _BV(P31) | _BV(P34), bEnable ? _BV (P34) : _BV (P31)))
|
||||
return false;
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
break;
|
||||
case SCM_SCL3711:
|
||||
if (NDO_ACTIVATE_FIELD == ndo) {
|
||||
if (NP_ACTIVATE_FIELD == property) {
|
||||
// Switch on/off LED according to ACTIVATE_FIELD option
|
||||
if (!pn53x_write_register (pnd, PN53X_SFR_P3, _BV (P32), bEnable ? 0 : _BV (P32)))
|
||||
return false;
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -814,7 +814,7 @@ const struct nfc_driver_t pn53x_usb_driver = {
|
|||
.target_send_bits = pn53x_target_send_bits,
|
||||
.target_receive_bits = pn53x_target_receive_bits,
|
||||
|
||||
.configure = pn53x_usb_configure,
|
||||
.device_set_property_bool = pn53x_usb_set_property_bool,
|
||||
.device_set_property_int = pn53x_set_property_int,
|
||||
|
||||
.abort_command = pn53x_usb_abort_command,
|
||||
|
|
|
@ -147,7 +147,7 @@ struct nfc_driver_t {
|
|||
bool (*target_send_bits) (nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar);
|
||||
bool (*target_receive_bits) (nfc_device *pnd, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar);
|
||||
|
||||
bool (*configure) (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable);
|
||||
int (*device_set_property_bool) (nfc_device *pnd, const nfc_property property, const bool bEnable);
|
||||
int (*device_set_property_int) (nfc_device *pnd, const nfc_property property, const int value);
|
||||
|
||||
bool (*abort_command) (nfc_device *pnd);
|
||||
|
|
133
libnfc/nfc.c
133
libnfc/nfc.c
|
@ -203,24 +203,6 @@ nfc_list_devices (nfc_connstring connstrings[] , size_t szDevices, size_t *pszDe
|
|||
log_fini ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure advanced NFC device settings
|
||||
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
|
||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
* @param ndo \a nfc_device_option struct that contains option to set to device
|
||||
* @param bEnable boolean to activate/disactivate the option
|
||||
*
|
||||
* Configures parameters and registers that control for example timing,
|
||||
* modulation, frame and error handling. There are different categories for
|
||||
* configuring the \e PN53X chip features (handle, activate, infinite and
|
||||
* accept).
|
||||
*/
|
||||
bool
|
||||
nfc_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable)
|
||||
{
|
||||
HAL (configure, pnd, ndo, bEnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a device's integer-property value
|
||||
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value)
|
||||
|
@ -238,6 +220,25 @@ nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const
|
|||
HAL (device_set_property_int, pnd, property, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set a device's boolean-property value
|
||||
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value)
|
||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
* @param property \a nfc_property which will be set
|
||||
* @param bEnable boolean to activate/disactivate the property
|
||||
*
|
||||
* Configures parameters and registers that control for example timing,
|
||||
* modulation, frame and error handling. There are different categories for
|
||||
* configuring the \e PN53X chip features (handle, activate, infinite and
|
||||
* accept).
|
||||
*/
|
||||
int
|
||||
nfc_device_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable)
|
||||
{
|
||||
HAL (device_set_property_bool, pnd, property, bEnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize NFC device as initiator (reader)
|
||||
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
|
||||
|
@ -246,55 +247,55 @@ nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const
|
|||
* The NFC device is configured to function as RFID reader.
|
||||
* After initialization it can be used to communicate to passive RFID tags and active NFC devices.
|
||||
* The reader will act as initiator to communicate peer 2 peer (NFCIP) to other active NFC devices.
|
||||
* - Crc is handled by the device (NDO_HANDLE_CRC = true)
|
||||
* - Parity is handled the device (NDO_HANDLE_PARITY = true)
|
||||
* - Cryto1 cipher is disabled (NDO_ACTIVATE_CRYPTO1 = false)
|
||||
* - Easy framing is enabled (NDO_EASY_FRAMING = true)
|
||||
* - Auto-switching in ISO14443-4 mode is enabled (NDO_AUTO_ISO14443_4 = true)
|
||||
* - Invalid frames are not accepted (NDO_ACCEPT_INVALID_FRAMES = false)
|
||||
* - Multiple frames are not accepted (NDO_ACCEPT_MULTIPLE_FRAMES = false)
|
||||
* - 14443-A mode is activated (NDO_FORCE_ISO14443_A = true)
|
||||
* - speed is set to 106 kbps (NDO_FORCE_SPEED_106 = true)
|
||||
* - Let the device try forever to find a target (NDO_INFINITE_SELECT = true)
|
||||
* - Crc is handled by the device (NP_HANDLE_CRC = true)
|
||||
* - Parity is handled the device (NP_HANDLE_PARITY = true)
|
||||
* - Cryto1 cipher is disabled (NP_ACTIVATE_CRYPTO1 = false)
|
||||
* - Easy framing is enabled (NP_EASY_FRAMING = true)
|
||||
* - Auto-switching in ISO14443-4 mode is enabled (NP_AUTO_ISO14443_4 = true)
|
||||
* - Invalid frames are not accepted (NP_ACCEPT_INVALID_FRAMES = false)
|
||||
* - Multiple frames are not accepted (NP_ACCEPT_MULTIPLE_FRAMES = false)
|
||||
* - 14443-A mode is activated (NP_FORCE_ISO14443_A = true)
|
||||
* - speed is set to 106 kbps (NP_FORCE_SPEED_106 = true)
|
||||
* - Let the device try forever to find a target (NP_INFINITE_SELECT = true)
|
||||
* - RF field is shortly dropped (if it was enabled) then activated again
|
||||
*/
|
||||
bool
|
||||
nfc_initiator_init (nfc_device *pnd)
|
||||
{
|
||||
// Drop the field for a while
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false) < 0)
|
||||
return false;
|
||||
// Enable field so more power consuming cards can power themselves up
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, true) < 0)
|
||||
return false;
|
||||
// Let the device try forever to find a target/tag
|
||||
if (!nfc_configure (pnd, NDO_INFINITE_SELECT, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, true) < 0)
|
||||
return false;
|
||||
// Activate auto ISO14443-4 switching by default
|
||||
if (!nfc_configure (pnd, NDO_AUTO_ISO14443_4, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, true) < 0)
|
||||
return false;
|
||||
// Force 14443-A mode
|
||||
if (!nfc_configure (pnd, NDO_FORCE_ISO14443_A, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_FORCE_ISO14443_A, true) < 0)
|
||||
return false;
|
||||
// Force speed at 106kbps
|
||||
if (!nfc_configure (pnd, NDO_FORCE_SPEED_106, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_FORCE_SPEED_106, true) < 0)
|
||||
return false;
|
||||
// Disallow invalid frame
|
||||
if (!nfc_configure (pnd, NDO_ACCEPT_INVALID_FRAMES, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACCEPT_INVALID_FRAMES, false) < 0)
|
||||
return false;
|
||||
// Disallow multiple frames
|
||||
if (!nfc_configure (pnd, NDO_ACCEPT_MULTIPLE_FRAMES, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACCEPT_MULTIPLE_FRAMES, false) < 0)
|
||||
return false;
|
||||
// Make sure we reset the CRC and parity to chip handling.
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true) < 0)
|
||||
return false;
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_PARITY, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_PARITY, true) < 0)
|
||||
return false;
|
||||
// Activate "easy framing" feature by default
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true) < 0)
|
||||
return false;
|
||||
// Deactivate the CRYPTO1 cipher, it may could cause problems when still active
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_CRYPTO1, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_CRYPTO1, false) < 0)
|
||||
return false;
|
||||
|
||||
HAL (initiator_init, pnd);
|
||||
|
@ -373,7 +374,7 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
|
|||
pnd->iLastError = 0;
|
||||
|
||||
// Let the reader only try once to find a tag
|
||||
if (!nfc_configure (pnd, NDO_INFINITE_SELECT, false)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -486,14 +487,14 @@ nfc_initiator_deselect_target (nfc_device *pnd)
|
|||
* If timeout is not a null pointer, it specifies the maximum interval to wait for the function to be executed.
|
||||
* If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed).
|
||||
*
|
||||
* If \a NDO_EASY_FRAMING option is disabled the frames will sent and received in raw mode: \e PN53x will not handle input neither output data.
|
||||
* If \a NP_EASY_FRAMING option is disabled the frames will sent and received in raw mode: \e PN53x will not handle input neither output data.
|
||||
*
|
||||
* The parity bits are handled by the \e PN53x chip. The CRC can be generated automatically or handled manually.
|
||||
* Using this function, frames can be communicated very fast via the NFC initiator to the tag.
|
||||
*
|
||||
* Tests show that on average this way of communicating is much faster than using the regular driver/middle-ware (often supplied by manufacturers).
|
||||
*
|
||||
* @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value).
|
||||
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
||||
*/
|
||||
bool
|
||||
nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx,
|
||||
|
@ -550,7 +551,7 @@ nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size
|
|||
*
|
||||
* This function is similar to nfc_initiator_transceive_bytes() with the following differences:
|
||||
* - A precise cycles counter will indicate the number of cycles between emission & reception of frames.
|
||||
* - It only supports mode with \a NDO_EASY_FRAMING option disabled.
|
||||
* - It only supports mode with \a NP_EASY_FRAMING option disabled.
|
||||
* - Overall communication with the host is heavier and slower.
|
||||
*
|
||||
* Timer control:
|
||||
|
@ -561,8 +562,8 @@ nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size
|
|||
* - If you need to count more cycles, set *cycles to the maximum you expect but don't forget
|
||||
* you'll loose in precision and it'll take more time before timeout, so don't abuse!
|
||||
*
|
||||
* @warning The configuration option \a NDO_EASY_FRAMING must be set to \c false.
|
||||
* @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value).
|
||||
* @warning The configuration option \a NP_EASY_FRAMING must be set to \c false.
|
||||
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
||||
*/
|
||||
bool
|
||||
nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx,
|
||||
|
@ -577,7 +578,7 @@ nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, con
|
|||
*
|
||||
* This function is similar to nfc_initiator_transceive_bits() with the following differences:
|
||||
* - A precise cycles counter will indicate the number of cycles between emission & reception of frames.
|
||||
* - It only supports mode with \a NDO_EASY_FRAMING option disabled and CRC must be handled manually.
|
||||
* - It only supports mode with \a NP_EASY_FRAMING option disabled and CRC must be handled manually.
|
||||
* - Overall communication with the host is heavier and slower.
|
||||
*
|
||||
* Timer control:
|
||||
|
@ -588,9 +589,9 @@ nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, con
|
|||
* - If you need to count more cycles, set *cycles to the maximum you expect but don't forget
|
||||
* you'll loose in precision and it'll take more time before timeout, so don't abuse!
|
||||
*
|
||||
* @warning The configuration option \a NDO_EASY_FRAMING must be set to \c false.
|
||||
* @warning The configuration option \a NDO_HANDLE_CRC must be set to \c false.
|
||||
* @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value).
|
||||
* @warning The configuration option \a NP_EASY_FRAMING must be set to \c false.
|
||||
* @warning The configuration option \a NP_HANDLE_CRC must be set to \c false.
|
||||
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
||||
*/
|
||||
bool
|
||||
nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
||||
|
@ -615,13 +616,13 @@ nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, cons
|
|||
*
|
||||
* This function initializes NFC device in \e target mode in order to emulate a
|
||||
* tag using the specified \a nfc_target_mode_t.
|
||||
* - Crc is handled by the device (NDO_HANDLE_CRC = true)
|
||||
* - Parity is handled the device (NDO_HANDLE_PARITY = true)
|
||||
* - Cryto1 cipher is disabled (NDO_ACTIVATE_CRYPTO1 = false)
|
||||
* - Auto-switching in ISO14443-4 mode is enabled (NDO_AUTO_ISO14443_4 = true)
|
||||
* - Easy framing is disabled (NDO_EASY_FRAMING = false)
|
||||
* - Invalid frames are not accepted (NDO_ACCEPT_INVALID_FRAMES = false)
|
||||
* - Multiple frames are not accepted (NDO_ACCEPT_MULTIPLE_FRAMES = false)
|
||||
* - Crc is handled by the device (NP_HANDLE_CRC = true)
|
||||
* - Parity is handled the device (NP_HANDLE_PARITY = true)
|
||||
* - Cryto1 cipher is disabled (NP_ACTIVATE_CRYPTO1 = false)
|
||||
* - Auto-switching in ISO14443-4 mode is enabled (NP_AUTO_ISO14443_4 = true)
|
||||
* - Easy framing is disabled (NP_EASY_FRAMING = false)
|
||||
* - Invalid frames are not accepted (NP_ACCEPT_INVALID_FRAMES = false)
|
||||
* - Multiple frames are not accepted (NP_ACCEPT_MULTIPLE_FRAMES = false)
|
||||
* - RF field is dropped
|
||||
*
|
||||
* @warning Be aware that this function will wait (hang) until a command is
|
||||
|
@ -633,27 +634,27 @@ bool
|
|||
nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t * pszRx)
|
||||
{
|
||||
// Disallow invalid frame
|
||||
if (!nfc_configure (pnd, NDO_ACCEPT_INVALID_FRAMES, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACCEPT_INVALID_FRAMES, false) < 0)
|
||||
return false;
|
||||
// Disallow multiple frames
|
||||
if (!nfc_configure (pnd, NDO_ACCEPT_MULTIPLE_FRAMES, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACCEPT_MULTIPLE_FRAMES, false) < 0)
|
||||
return false;
|
||||
// Make sure we reset the CRC and parity to chip handling.
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true) < 0)
|
||||
return false;
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_PARITY, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_PARITY, true) < 0)
|
||||
return false;
|
||||
// Activate auto ISO14443-4 switching by default
|
||||
if (!nfc_configure (pnd, NDO_AUTO_ISO14443_4, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, true) < 0)
|
||||
return false;
|
||||
// Activate "easy framing" feature by default
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true) < 0)
|
||||
return false;
|
||||
// Deactivate the CRYPTO1 cipher, it may could cause problems when still active
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_CRYPTO1, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_CRYPTO1, false) < 0)
|
||||
return false;
|
||||
// Drop explicitely the field
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false) < 0)
|
||||
return false;
|
||||
|
||||
HAL (target_init, pnd, pnt, pbtRx, pszRx);
|
||||
|
@ -754,7 +755,7 @@ nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBi
|
|||
* the messages that are stored in the FIFO buffer of the \e PN53x chip. It
|
||||
* does not require to send any frame and thereby could be used to snoop frames
|
||||
* that are transmitted by a nearby \e initiator. @note Check out the
|
||||
* NDO_ACCEPT_MULTIPLE_FRAMES configuration option to avoid losing transmitted
|
||||
* NP_ACCEPT_MULTIPLE_FRAMES configuration option to avoid losing transmitted
|
||||
* frames.
|
||||
*/
|
||||
bool
|
||||
|
|
|
@ -95,8 +95,8 @@ nfc_initiator_mifare_cmd (nfc_device *pnd, const mifare_cmd mc, const uint8_t ui
|
|||
memcpy (abtCmd + 2, (uint8_t *) pmp, szParamLen);
|
||||
|
||||
bEasyFraming = pnd->bEasyFraming;
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, true)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
return false;
|
||||
}
|
||||
// Fire the mifare command
|
||||
|
@ -109,11 +109,11 @@ nfc_initiator_mifare_cmd (nfc_device *pnd, const mifare_cmd mc, const uint8_t ui
|
|||
} else {
|
||||
nfc_perror (pnd, "nfc_initiator_transceive_bytes");
|
||||
}
|
||||
nfc_configure (pnd, NDO_EASY_FRAMING, bEasyFraming);
|
||||
nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming);
|
||||
return false;
|
||||
}
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, bEasyFraming)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -219,12 +219,12 @@ unlock_card()
|
|||
printf ("Unlocking card\n");
|
||||
|
||||
// Configure the CRC
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, false)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// Use raw send/receive methods
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, false)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
@ -243,13 +243,13 @@ unlock_card()
|
|||
|
||||
// reset reader
|
||||
// Configure the CRC
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, true)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// Switch off raw send/receive methods
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, true)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
return true;
|
||||
|
@ -547,12 +547,12 @@ main (int argc, const char *argv[])
|
|||
nfc_initiator_init (pnd);
|
||||
|
||||
// Let the reader only try once to find a tag
|
||||
if (!nfc_configure (pnd, NDO_INFINITE_SELECT, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// 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);
|
||||
nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, false);
|
||||
|
||||
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
||||
|
||||
|
|
|
@ -189,18 +189,18 @@ main (int argc, char *argv[])
|
|||
nfc_initiator_init (pnd);
|
||||
|
||||
// Configure the CRC
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// Use raw send/receive methods
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// Disable 14443-4 autoswitching
|
||||
if (!nfc_configure (pnd, NDO_AUTO_ISO14443_4, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
|
@ -214,8 +214,8 @@ main (int argc, const char *argv[])
|
|||
nfc_initiator_init (pnd);
|
||||
|
||||
// Let the device only try once to find a tag
|
||||
if (!nfc_configure (pnd, NDO_INFINITE_SELECT, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
|
@ -245,8 +245,8 @@ main(int argc, char *argv[])
|
|||
|
||||
//print_nfc_felica_info(nt.nti.nfi, true);
|
||||
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, false) || !nfc_configure (pnd, NDO_INFINITE_SELECT, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
if ((nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, false) < 0) || (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false) < 0)) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
error = EXIT_FAILURE;
|
||||
goto error;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue