new properties to tune timeouts:
- add nfc_properties (will replace nfc_options) - introduce some error codes - rework functions to use the new timeout_command value
This commit is contained in:
parent
8b76d55fdc
commit
26b9c28f48
10 changed files with 145 additions and 30 deletions
|
@ -74,6 +74,30 @@ typedef struct {
|
||||||
*/
|
*/
|
||||||
typedef char nfc_connstring[1024];
|
typedef char nfc_connstring[1024];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Properties
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
/**
|
||||||
|
* Default command processing timeout
|
||||||
|
* Property value's (duration) unit is ms and 0 means no timeout (infinite).
|
||||||
|
* Default value is set by driver layer
|
||||||
|
*/
|
||||||
|
NP_TIMEOUT_COMMAND,
|
||||||
|
/**
|
||||||
|
* Timeout between ATR_REQ and ATR_RES
|
||||||
|
* When the device is in initiator mode, a target is considered as mute if no
|
||||||
|
* valid ATR_RES is received within this timeout value.
|
||||||
|
* Default value for this property is 103 ms on PN53x based devices.
|
||||||
|
*/
|
||||||
|
NP_TIMEOUT_ATR,
|
||||||
|
/**
|
||||||
|
* Timeout value to give up reception from the target in case of no answer.
|
||||||
|
* Default value for this property is 52 ms).
|
||||||
|
*/
|
||||||
|
NP_TIMEOUT_COM,
|
||||||
|
} nfc_property;
|
||||||
|
|
||||||
// Compiler directive, set struct alignment to 1 uint8_t for compatibility
|
// Compiler directive, set struct alignment to 1 uint8_t for compatibility
|
||||||
# pragma pack(1)
|
# pragma pack(1)
|
||||||
|
|
||||||
|
|
|
@ -98,12 +98,22 @@ extern "C" {
|
||||||
/* Special data accessors */
|
/* Special data accessors */
|
||||||
NFC_EXPORT const char *nfc_device_name (nfc_device *pnd);
|
NFC_EXPORT const char *nfc_device_name (nfc_device *pnd);
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
|
||||||
/* Misc. functions */
|
/* Misc. functions */
|
||||||
NFC_EXPORT void iso14443a_crc (uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc);
|
NFC_EXPORT void iso14443a_crc (uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc);
|
||||||
NFC_EXPORT void iso14443a_crc_append (uint8_t *pbtData, size_t szLen);
|
NFC_EXPORT void iso14443a_crc_append (uint8_t *pbtData, size_t szLen);
|
||||||
NFC_EXPORT uint8_t *iso14443a_locate_historical_bytes (uint8_t *pbtAts, size_t szAts, size_t *pszTk);
|
NFC_EXPORT uint8_t *iso14443a_locate_historical_bytes (uint8_t *pbtAts, size_t szAts, size_t *pszTk);
|
||||||
NFC_EXPORT const char *nfc_version (void);
|
NFC_EXPORT const char *nfc_version (void);
|
||||||
|
|
||||||
|
/* Error codes */
|
||||||
|
#define NFC_SUCCESS 0 // No error
|
||||||
|
#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)
|
||||||
|
|
||||||
/* PN53x specific errors */
|
/* PN53x specific errors */
|
||||||
// TODO: Be not PN53x-specific here
|
// TODO: Be not PN53x-specific here
|
||||||
#define ETIMEOUT 0x01
|
#define ETIMEOUT 0x01
|
||||||
|
|
|
@ -111,6 +111,8 @@ pn53x_transceive (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint
|
||||||
PNCMD_TRACE (pbtTx[0]);
|
PNCMD_TRACE (pbtTx[0]);
|
||||||
if (timeout > 0)
|
if (timeout > 0)
|
||||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Timeout values: %d", timeout);
|
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Timeout values: %d", timeout);
|
||||||
|
if (timeout == -1)
|
||||||
|
timeout = CHIP_DATA (pnd)->timeout_command;
|
||||||
|
|
||||||
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRx = sizeof(abtRx);
|
size_t szRx = sizeof(abtRx);
|
||||||
|
@ -161,6 +163,8 @@ pn53x_transceive (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint
|
||||||
case TgResponseToInitiator:
|
case TgResponseToInitiator:
|
||||||
case TgSetGeneralBytes:
|
case TgSetGeneralBytes:
|
||||||
case TgSetMetaData:
|
case TgSetMetaData:
|
||||||
|
if (pbtRx[0] & 0x80) { abort(); } // NAD detected
|
||||||
|
if (pbtRx[0] & 0x40) { abort(); } // MI detected
|
||||||
pnd->iLastError = pbtRx[0] & 0x3f;
|
pnd->iLastError = pbtRx[0] & 0x3f;
|
||||||
break;
|
break;
|
||||||
case InDeselect:
|
case InDeselect:
|
||||||
|
@ -469,7 +473,7 @@ pn53x_ReadRegister (nfc_device *pnd, uint16_t ui16RegisterAddress, uint8_t *ui8V
|
||||||
size_t szRegValue = sizeof (abtRegValue);
|
size_t szRegValue = sizeof (abtRegValue);
|
||||||
|
|
||||||
PNREG_TRACE (ui16RegisterAddress);
|
PNREG_TRACE (ui16RegisterAddress);
|
||||||
if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRegValue, &szRegValue, 0)) {
|
if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRegValue, &szRegValue, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (CHIP_DATA(pnd)->type == PN533) {
|
if (CHIP_DATA(pnd)->type == PN533) {
|
||||||
|
@ -491,7 +495,7 @@ pn53x_WriteRegister (nfc_device *pnd, const uint16_t ui16RegisterAddress, const
|
||||||
{
|
{
|
||||||
uint8_t abtCmd[] = { WriteRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff, ui8Value };
|
uint8_t abtCmd[] = { WriteRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff, ui8Value };
|
||||||
PNREG_TRACE (ui16RegisterAddress);
|
PNREG_TRACE (ui16RegisterAddress);
|
||||||
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, 0);
|
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -543,7 +547,7 @@ pn53x_writeback_register (nfc_device *pnd)
|
||||||
uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRes = sizeof(abtRes);
|
size_t szRes = sizeof(abtRes);
|
||||||
// It transceives the previously constructed ReadRegister command
|
// It transceives the previously constructed ReadRegister command
|
||||||
if (!pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, 0)) {
|
if (!pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
@ -581,7 +585,7 @@ pn53x_writeback_register (nfc_device *pnd)
|
||||||
|
|
||||||
if (BUFFER_SIZE (abtWriteRegisterCmd) > 1) {
|
if (BUFFER_SIZE (abtWriteRegisterCmd) > 1) {
|
||||||
// We need to write some registers
|
// We need to write some registers
|
||||||
if (!pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, 0)) {
|
if (!pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -594,7 +598,7 @@ pn53x_get_firmware_version (nfc_device *pnd, char abtFirmwareText[22])
|
||||||
const uint8_t abtCmd[] = { GetFirmwareVersion };
|
const uint8_t abtCmd[] = { GetFirmwareVersion };
|
||||||
uint8_t abtFw[4];
|
uint8_t abtFw[4];
|
||||||
size_t szFwLen = sizeof (abtFw);
|
size_t szFwLen = sizeof (abtFw);
|
||||||
if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtFw, &szFwLen, 0)) {
|
if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtFw, &szFwLen, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Determine which version of chip it is: PN531 will return only 2 bytes, while others return 4 bytes and have the first to tell the version IC
|
// Determine which version of chip it is: PN531 will return only 2 bytes, while others return 4 bytes and have the first to tell the version IC
|
||||||
|
@ -776,6 +780,42 @@ pn53x_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnabl
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t
|
||||||
|
pn53x_int_to_timeout (const int ms)
|
||||||
|
{
|
||||||
|
uint8_t res = 0;
|
||||||
|
if (ms) {
|
||||||
|
res = 0x10;
|
||||||
|
for (int i=3280; i>1; i/=2) {
|
||||||
|
if (ms > i)
|
||||||
|
break;
|
||||||
|
res--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
pn53x_set_property_int (nfc_device *pnd, const nfc_property property, const int value)
|
||||||
|
{
|
||||||
|
switch (property) {
|
||||||
|
case NP_TIMEOUT_COMMAND:
|
||||||
|
CHIP_DATA (pnd)->timeout_command = value;
|
||||||
|
break;
|
||||||
|
case NP_TIMEOUT_ATR:
|
||||||
|
CHIP_DATA (pnd)->timeout_atr = value;
|
||||||
|
return (pn53x_RFConfiguration__Various_timings (pnd, pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_communication))) ? NFC_SUCCESS : NFC_EIO;
|
||||||
|
break;
|
||||||
|
case NP_TIMEOUT_COM:
|
||||||
|
CHIP_DATA (pnd)->timeout_communication = value;
|
||||||
|
return (pn53x_RFConfiguration__Various_timings (pnd, pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA (pnd)->timeout_communication))) ? NFC_SUCCESS : NFC_EIO;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NFC_ENOTSUP;
|
||||||
|
}
|
||||||
|
return NFC_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pn53x_idle (nfc_device *pnd)
|
pn53x_idle (nfc_device *pnd)
|
||||||
{
|
{
|
||||||
|
@ -995,7 +1035,7 @@ pn53x_initiator_poll_target (nfc_device *pnd,
|
||||||
}
|
}
|
||||||
size_t szTargetFound = 0;
|
size_t szTargetFound = 0;
|
||||||
nfc_target ntTargets[2];
|
nfc_target ntTargets[2];
|
||||||
if (!pn53x_InAutoPoll (pnd, apttTargetTypes, szTargetTypes, uiPollNr, uiPeriod, ntTargets, &szTargetFound))
|
if (!pn53x_InAutoPoll (pnd, apttTargetTypes, szTargetTypes, uiPollNr, uiPeriod, ntTargets, &szTargetFound, 0))
|
||||||
return false;
|
return false;
|
||||||
switch (szTargetFound) {
|
switch (szTargetFound) {
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -1099,7 +1139,7 @@ pn53x_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const si
|
||||||
// We have to give the amount of bytes + (the command byte 0x42)
|
// We have to give the amount of bytes + (the command byte 0x42)
|
||||||
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRx = sizeof(abtRx);
|
size_t szRx = sizeof(abtRx);
|
||||||
if (!pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, abtRx, &szRx, 0))
|
if (!pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, abtRx, &szRx, -1))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get the last bit-count that is stored in the received byte
|
// Get the last bit-count that is stored in the received byte
|
||||||
|
@ -1216,7 +1256,7 @@ uint32_t __pn53x_get_timer(nfc_device *pnd, const uint8_t last_cmd_byte)
|
||||||
uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRes = sizeof(abtRes);
|
size_t szRes = sizeof(abtRes);
|
||||||
// Let's send the previously constructed ReadRegister command
|
// Let's send the previously constructed ReadRegister command
|
||||||
if (!pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, 0)) {
|
if (!pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
counter_hi = abtRes[off];
|
counter_hi = abtRes[off];
|
||||||
|
@ -1306,7 +1346,7 @@ pn53x_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, co
|
||||||
BUFFER_APPEND (abtWriteRegisterCmd, PN53X_REG_CIU_BitFraming & 0xff);
|
BUFFER_APPEND (abtWriteRegisterCmd, PN53X_REG_CIU_BitFraming & 0xff);
|
||||||
BUFFER_APPEND (abtWriteRegisterCmd, SYMBOL_START_SEND | ((szTxBits % 8) & SYMBOL_TX_LAST_BITS));
|
BUFFER_APPEND (abtWriteRegisterCmd, SYMBOL_START_SEND | ((szTxBits % 8) & SYMBOL_TX_LAST_BITS));
|
||||||
// Let's send the previously constructed WriteRegister command
|
// Let's send the previously constructed WriteRegister command
|
||||||
if (!pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, 0)) {
|
if (!pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1338,7 +1378,7 @@ pn53x_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, co
|
||||||
uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRes = sizeof(abtRes);
|
size_t szRes = sizeof(abtRes);
|
||||||
// Let's send the previously constructed ReadRegister command
|
// Let's send the previously constructed ReadRegister command
|
||||||
if (!pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, 0)) {
|
if (!pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (i = 0; i < sz; i++) {
|
for (i = 0; i < sz; i++) {
|
||||||
|
@ -1401,7 +1441,7 @@ pn53x_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, c
|
||||||
BUFFER_APPEND (abtWriteRegisterCmd, PN53X_REG_CIU_BitFraming & 0xff);
|
BUFFER_APPEND (abtWriteRegisterCmd, PN53X_REG_CIU_BitFraming & 0xff);
|
||||||
BUFFER_APPEND (abtWriteRegisterCmd, SYMBOL_START_SEND);
|
BUFFER_APPEND (abtWriteRegisterCmd, SYMBOL_START_SEND);
|
||||||
// Let's send the previously constructed WriteRegister command
|
// Let's send the previously constructed WriteRegister command
|
||||||
if (!pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, 0)) {
|
if (!pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1433,7 +1473,7 @@ pn53x_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, c
|
||||||
uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRes = sizeof(abtRes);
|
size_t szRes = sizeof(abtRes);
|
||||||
// Let's send the previously constructed ReadRegister command
|
// Let's send the previously constructed ReadRegister command
|
||||||
if (!pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, 0)) {
|
if (!pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (i = 0; i < sz; i++) {
|
for (i = 0; i < sz; i++) {
|
||||||
|
@ -1697,7 +1737,7 @@ pn53x_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRxBits, u
|
||||||
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRx = sizeof (abtRx);
|
size_t szRx = sizeof (abtRx);
|
||||||
// Try to gather a received frame from the reader
|
// Try to gather a received frame from the reader
|
||||||
if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, 0))
|
if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, -1))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get the last bit-count that is stored in the received byte
|
// Get the last bit-count that is stored in the received byte
|
||||||
|
@ -1804,7 +1844,7 @@ pn53x_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Try to send the bits to the reader
|
// Try to send the bits to the reader
|
||||||
if (!pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, NULL, NULL, 0))
|
if (!pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, NULL, NULL, -1))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Everyting seems ok, return true
|
// Everyting seems ok, return true
|
||||||
|
@ -1930,7 +1970,7 @@ bool
|
||||||
pn53x_RFConfiguration__RF_field (nfc_device *pnd, bool bEnable)
|
pn53x_RFConfiguration__RF_field (nfc_device *pnd, bool bEnable)
|
||||||
{
|
{
|
||||||
uint8_t abtCmd[] = { RFConfiguration, RFCI_FIELD, (bEnable) ? 0x01 : 0x00 };
|
uint8_t abtCmd[] = { RFConfiguration, RFCI_FIELD, (bEnable) ? 0x01 : 0x00 };
|
||||||
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, 0);
|
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -1943,7 +1983,7 @@ pn53x_RFConfiguration__Various_timings (nfc_device *pnd, const uint8_t fATR_RES_
|
||||||
fATR_RES_Timeout, // ATR_RES timeout (default: 0x0B 102.4 ms)
|
fATR_RES_Timeout, // ATR_RES timeout (default: 0x0B 102.4 ms)
|
||||||
fRetryTimeout // TimeOut during non-DEP communications (default: 0x0A 51.2 ms)
|
fRetryTimeout // TimeOut during non-DEP communications (default: 0x0A 51.2 ms)
|
||||||
};
|
};
|
||||||
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, 0);
|
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -1954,7 +1994,7 @@ pn53x_RFConfiguration__MaxRtyCOM (nfc_device *pnd, const uint8_t MaxRtyCOM)
|
||||||
RFCI_RETRY_DATA,
|
RFCI_RETRY_DATA,
|
||||||
MaxRtyCOM // MaxRtyCOM, default: 0x00 (no retry, only one try), inifite: 0xff
|
MaxRtyCOM // MaxRtyCOM, default: 0x00 (no retry, only one try), inifite: 0xff
|
||||||
};
|
};
|
||||||
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, 0);
|
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -1968,7 +2008,7 @@ pn53x_RFConfiguration__MaxRetries (nfc_device *pnd, const uint8_t MxRtyATR, cons
|
||||||
MxRtyPSL, // MxRtyPSL, default: 0x01
|
MxRtyPSL, // MxRtyPSL, default: 0x01
|
||||||
MxRtyPassiveActivation // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
|
MxRtyPassiveActivation // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
|
||||||
};
|
};
|
||||||
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, 0);
|
return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -1976,7 +2016,7 @@ pn53x_SetParameters (nfc_device *pnd, const uint8_t ui8Value)
|
||||||
{
|
{
|
||||||
uint8_t abtCmd[] = { SetParameters, ui8Value };
|
uint8_t abtCmd[] = { SetParameters, ui8Value };
|
||||||
|
|
||||||
if(!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, 0)) {
|
if(!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// We save last parameters in register cache
|
// We save last parameters in register cache
|
||||||
|
@ -2017,7 +2057,7 @@ bool
|
||||||
pn53x_PowerDown (nfc_device *pnd)
|
pn53x_PowerDown (nfc_device *pnd)
|
||||||
{
|
{
|
||||||
uint8_t abtCmd[] = { PowerDown, 0xf0 };
|
uint8_t abtCmd[] = { PowerDown, 0xf0 };
|
||||||
return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, 0));
|
return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2095,7 +2135,7 @@ pn53x_InDeselect (nfc_device *pnd, const uint8_t ui8Target)
|
||||||
uint8_t abtStatus[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtStatus[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szStatus = sizeof(abtStatus);
|
size_t szStatus = sizeof(abtStatus);
|
||||||
uint8_t abtCmdGetStatus[] = { GetGeneralStatus };
|
uint8_t abtCmdGetStatus[] = { GetGeneralStatus };
|
||||||
if (!pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, 0)) {
|
if (!pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((szStatus < 3) || (abtStatus[2] == 0)) {
|
if ((szStatus < 3) || (abtStatus[2] == 0)) {
|
||||||
|
@ -2103,10 +2143,10 @@ pn53x_InDeselect (nfc_device *pnd, const uint8_t ui8Target)
|
||||||
}
|
}
|
||||||
// No much choice what to deselect actually...
|
// No much choice what to deselect actually...
|
||||||
uint8_t abtCmdRcs360[] = { InDeselect, 0x01, 0x01 };
|
uint8_t abtCmdRcs360[] = { InDeselect, 0x01, 0x01 };
|
||||||
return (pn53x_transceive (pnd, abtCmdRcs360, sizeof (abtCmdRcs360), NULL, NULL, 0));
|
return (pn53x_transceive (pnd, abtCmdRcs360, sizeof (abtCmdRcs360), NULL, NULL, -1));
|
||||||
}
|
}
|
||||||
uint8_t abtCmd[] = { InDeselect, ui8Target };
|
uint8_t abtCmd[] = { InDeselect, ui8Target };
|
||||||
return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, 0));
|
return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -2117,7 +2157,7 @@ pn53x_InRelease (nfc_device *pnd, const uint8_t ui8Target)
|
||||||
uint8_t abtStatus[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtStatus[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szStatus = sizeof(abtStatus);
|
size_t szStatus = sizeof(abtStatus);
|
||||||
uint8_t abtCmdGetStatus[] = { GetGeneralStatus };
|
uint8_t abtCmdGetStatus[] = { GetGeneralStatus };
|
||||||
if (!pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, 0)) {
|
if (!pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((szStatus < 3) || (abtStatus[2] == 0)) {
|
if ((szStatus < 3) || (abtStatus[2] == 0)) {
|
||||||
|
@ -2125,16 +2165,17 @@ pn53x_InRelease (nfc_device *pnd, const uint8_t ui8Target)
|
||||||
}
|
}
|
||||||
// No much choice what to release actually...
|
// No much choice what to release actually...
|
||||||
uint8_t abtCmdRcs360[] = { InRelease, 0x01, 0x01 };
|
uint8_t abtCmdRcs360[] = { InRelease, 0x01, 0x01 };
|
||||||
return (pn53x_transceive (pnd, abtCmdRcs360, sizeof (abtCmdRcs360), NULL, NULL, 0));
|
return (pn53x_transceive (pnd, abtCmdRcs360, sizeof (abtCmdRcs360), NULL, NULL, -1));
|
||||||
}
|
}
|
||||||
uint8_t abtCmd[] = { InRelease, ui8Target };
|
uint8_t abtCmd[] = { InRelease, ui8Target };
|
||||||
return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, 0));
|
return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pn53x_InAutoPoll (nfc_device *pnd,
|
pn53x_InAutoPoll (nfc_device *pnd,
|
||||||
const pn53x_target_type *ppttTargetTypes, const size_t szTargetTypes,
|
const pn53x_target_type *ppttTargetTypes, const size_t szTargetTypes,
|
||||||
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target * pntTargets, size_t *pszTargetFound)
|
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target * pntTargets, size_t *pszTargetFound,
|
||||||
|
const int timeout)
|
||||||
{
|
{
|
||||||
if (CHIP_DATA(pnd)->type != PN532) {
|
if (CHIP_DATA(pnd)->type != PN532) {
|
||||||
// This function is not supported by pn531 neither pn533
|
// This function is not supported by pn531 neither pn533
|
||||||
|
@ -2151,7 +2192,7 @@ pn53x_InAutoPoll (nfc_device *pnd,
|
||||||
|
|
||||||
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRx = sizeof(abtRx);
|
size_t szRx = sizeof(abtRx);
|
||||||
bool res = pn53x_transceive (pnd, abtCmd, szTxInAutoPoll, abtRx, &szRx, 0);
|
bool res = pn53x_transceive (pnd, abtCmd, szTxInAutoPoll, abtRx, &szRx, timeout);
|
||||||
|
|
||||||
if (res == false) {
|
if (res == false) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -2343,7 +2384,7 @@ pn53x_TgInitAsTarget (nfc_device *pnd, pn53x_target_mode ptm,
|
||||||
// Request the initialization as a target
|
// Request the initialization as a target
|
||||||
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRx = sizeof (abtRx);
|
size_t szRx = sizeof (abtRx);
|
||||||
if (!pn53x_transceive (pnd, abtCmd, 36 + szOptionalBytes, abtRx, &szRx, 0))
|
if (!pn53x_transceive (pnd, abtCmd, 36 + szOptionalBytes, abtRx, &szRx, -1))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Note: the first byte is skip:
|
// Note: the first byte is skip:
|
||||||
|
@ -2633,6 +2674,15 @@ pn53x_data_new (nfc_device *pnd, const struct pn53x_io *io)
|
||||||
// WriteBack cache is clean
|
// WriteBack cache is clean
|
||||||
CHIP_DATA (pnd)->wb_trigged = false;
|
CHIP_DATA (pnd)->wb_trigged = false;
|
||||||
memset (CHIP_DATA (pnd)->wb_mask, 0x00, PN53X_CACHE_REGISTER_SIZE);
|
memset (CHIP_DATA (pnd)->wb_mask, 0x00, PN53X_CACHE_REGISTER_SIZE);
|
||||||
|
|
||||||
|
// Set default command timeout (500 ms)
|
||||||
|
CHIP_DATA (pnd)->timeout_command = 500;
|
||||||
|
|
||||||
|
// Set default ATR timeout (103 ms)
|
||||||
|
CHIP_DATA (pnd)->timeout_command = 103;
|
||||||
|
|
||||||
|
// Set default communication timeout (52 ms)
|
||||||
|
CHIP_DATA (pnd)->timeout_command = 52;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -160,6 +160,12 @@ struct pn53x_data {
|
||||||
uint8_t wb_data[PN53X_CACHE_REGISTER_SIZE];
|
uint8_t wb_data[PN53X_CACHE_REGISTER_SIZE];
|
||||||
uint8_t wb_mask[PN53X_CACHE_REGISTER_SIZE];
|
uint8_t wb_mask[PN53X_CACHE_REGISTER_SIZE];
|
||||||
bool wb_trigged;
|
bool wb_trigged;
|
||||||
|
/** Command timeout */
|
||||||
|
int timeout_command;
|
||||||
|
/** ATR timeout */
|
||||||
|
int timeout_atr;
|
||||||
|
/** Communication timeout */
|
||||||
|
int timeout_communication;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CHIP_DATA(pnd) ((struct pn53x_data*)(pnd->chip_data))
|
#define CHIP_DATA(pnd) ((struct pn53x_data*)(pnd->chip_data))
|
||||||
|
@ -271,6 +277,8 @@ bool pn53x_read_register (nfc_device *pnd, uint16_t ui16Reg, uint8_t *ui8Valu
|
||||||
bool pn53x_write_register (nfc_device *pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, 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_get_firmware_version (nfc_device *pnd, char abtFirmwareText[22]);
|
||||||
bool pn53x_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable);
|
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);
|
||||||
|
|
||||||
bool pn53x_check_communication (nfc_device *pnd);
|
bool pn53x_check_communication (nfc_device *pnd);
|
||||||
bool pn53x_idle (nfc_device *pnd);
|
bool pn53x_idle (nfc_device *pnd);
|
||||||
|
|
||||||
|
@ -323,7 +331,8 @@ bool pn53x_InDeselect (nfc_device *pnd, const uint8_t ui8Target);
|
||||||
bool pn53x_InRelease (nfc_device *pnd, const uint8_t ui8Target);
|
bool pn53x_InRelease (nfc_device *pnd, const uint8_t ui8Target);
|
||||||
bool pn53x_InAutoPoll (nfc_device *pnd, const pn53x_target_type *ppttTargetTypes, const size_t szTargetTypes,
|
bool pn53x_InAutoPoll (nfc_device *pnd, const pn53x_target_type *ppttTargetTypes, const size_t szTargetTypes,
|
||||||
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target *pntTargets,
|
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target *pntTargets,
|
||||||
size_t *pszTargetFound);
|
size_t *pszTargetFound,
|
||||||
|
const int timeout);
|
||||||
bool pn53x_InJumpForDEP (nfc_device *pnd,
|
bool pn53x_InJumpForDEP (nfc_device *pnd,
|
||||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||||
const uint8_t *pbtPassiveInitiatorData,
|
const uint8_t *pbtPassiveInitiatorData,
|
||||||
|
|
|
@ -488,6 +488,7 @@ const struct nfc_driver_t acr122_driver = {
|
||||||
.target_receive_bits = pn53x_target_receive_bits,
|
.target_receive_bits = pn53x_target_receive_bits,
|
||||||
|
|
||||||
.configure = pn53x_configure,
|
.configure = pn53x_configure,
|
||||||
|
.device_set_property_int = pn53x_set_property_int,
|
||||||
|
|
||||||
.abort_command = NULL, // FIXME: abort is not supported in this driver
|
.abort_command = NULL, // FIXME: abort is not supported in this driver
|
||||||
.idle = NULL, // FIXME: idle is not supported in this driver
|
.idle = NULL, // FIXME: idle is not supported in this driver
|
||||||
|
|
|
@ -580,6 +580,7 @@ const struct nfc_driver_t arygon_driver = {
|
||||||
.target_receive_bits = pn53x_target_receive_bits,
|
.target_receive_bits = pn53x_target_receive_bits,
|
||||||
|
|
||||||
.configure = pn53x_configure,
|
.configure = pn53x_configure,
|
||||||
|
.device_set_property_int = pn53x_set_property_int,
|
||||||
|
|
||||||
.abort_command = arygon_abort_command,
|
.abort_command = arygon_abort_command,
|
||||||
.idle = NULL, // FIXME arygon driver does not support idle()
|
.idle = NULL, // FIXME arygon driver does not support idle()
|
||||||
|
|
|
@ -526,6 +526,7 @@ const struct nfc_driver_t pn532_uart_driver = {
|
||||||
.target_receive_bits = pn53x_target_receive_bits,
|
.target_receive_bits = pn53x_target_receive_bits,
|
||||||
|
|
||||||
.configure = pn53x_configure,
|
.configure = pn53x_configure,
|
||||||
|
.device_set_property_int = pn53x_set_property_int,
|
||||||
|
|
||||||
.abort_command = pn532_uart_abort_command,
|
.abort_command = pn532_uart_abort_command,
|
||||||
.idle = pn53x_idle,
|
.idle = pn53x_idle,
|
||||||
|
|
|
@ -815,6 +815,7 @@ const struct nfc_driver_t pn53x_usb_driver = {
|
||||||
.target_receive_bits = pn53x_target_receive_bits,
|
.target_receive_bits = pn53x_target_receive_bits,
|
||||||
|
|
||||||
.configure = pn53x_usb_configure,
|
.configure = pn53x_usb_configure,
|
||||||
|
.device_set_property_int = pn53x_set_property_int,
|
||||||
|
|
||||||
.abort_command = pn53x_usb_abort_command,
|
.abort_command = pn53x_usb_abort_command,
|
||||||
.idle = pn53x_idle,
|
.idle = pn53x_idle,
|
||||||
|
|
|
@ -148,6 +148,7 @@ struct nfc_driver_t {
|
||||||
bool (*target_receive_bits) (nfc_device *pnd, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar);
|
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);
|
bool (*configure) (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable);
|
||||||
|
int (*device_set_property_int) (nfc_device *pnd, const nfc_property property, const int value);
|
||||||
|
|
||||||
bool (*abort_command) (nfc_device *pnd);
|
bool (*abort_command) (nfc_device *pnd);
|
||||||
bool (*idle) (nfc_device *pnd);
|
bool (*idle) (nfc_device *pnd);
|
||||||
|
|
17
libnfc/nfc.c
17
libnfc/nfc.c
|
@ -221,6 +221,23 @@ nfc_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable)
|
||||||
HAL (configure, pnd, ndo, 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)
|
||||||
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||||
|
* @param property \a nfc_property which will be set
|
||||||
|
* @param value integer value
|
||||||
|
*
|
||||||
|
* Sets integer property.
|
||||||
|
*
|
||||||
|
* @see nfc_property enum values
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const int value)
|
||||||
|
{
|
||||||
|
HAL (device_set_property_int, pnd, property, value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize NFC device as initiator (reader)
|
* @brief Initialize NFC device as initiator (reader)
|
||||||
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
|
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
|
||||||
|
|
Loading…
Add table
Reference in a new issue