Error handling improvement:
- Attempt to sort errors depending their source - Rename DE* errors to differenciate Device-Error and Driver-Error - Add ENOTIMPL error to raise a error when a feature is not (yet) implemented in libnfc
This commit is contained in:
parent
9c314d5652
commit
eb70f3842e
11 changed files with 113 additions and 122 deletions
|
@ -52,8 +52,7 @@ AC_CHECK_FUNCS([memmove memset select strdup strerror strstr strtol usleep],
|
||||||
AC_DEFINE(_NETBSD_SOURCE, 1, [Define on NetBSD to activate all library features])
|
AC_DEFINE(_NETBSD_SOURCE, 1, [Define on NetBSD to activate all library features])
|
||||||
AC_DEFINE(_DARWIN_C_SOURCE, 1, [Define on Darwin to activate all library features])
|
AC_DEFINE(_DARWIN_C_SOURCE, 1, [Define on Darwin to activate all library features])
|
||||||
|
|
||||||
# XXX malloc function should be tested
|
# Note: malloc function should be tested but it produces some error while cross-compiling with MinGW
|
||||||
# but it produces some error while cross-compiling with MinGW
|
|
||||||
# AC_FUNC_MALLOC
|
# AC_FUNC_MALLOC
|
||||||
|
|
||||||
# Checks for types
|
# Checks for types
|
||||||
|
|
|
@ -131,14 +131,20 @@ extern "C" {
|
||||||
#define EOVCURRENT 0x2d
|
#define EOVCURRENT 0x2d
|
||||||
#define ENAD 0x2e
|
#define ENAD 0x2e
|
||||||
|
|
||||||
/* Software level errors */
|
/* PN53x framing-level errors */
|
||||||
#define ETGUIDNOTSUP 0x0100 /* Target UID not supported */
|
#define EFRAACKMISMATCH 0x0100 /* Unexpected data */
|
||||||
|
#define EFRAISERRFRAME 0x0101 /* Error frame */
|
||||||
|
|
||||||
/* Common device-level errors */
|
/* Communication-level errors */
|
||||||
#define DEIO 0x1000 /* Input/output error */
|
#define ECOMIO 0x1000 /* Input/output error */
|
||||||
#define DEINVAL 0x2000 /* Invalid argument */
|
#define ECOMTIMEOUT 0x1001 /* Operation timeout */
|
||||||
#define DETIMEOUT 0x3000 /* Operation timeout */
|
|
||||||
#define DEABORT 0x4000 /* Operation aborted */
|
/* Software level errors */
|
||||||
|
#define ETGUIDNOTSUP 0xFF00 /* Target UID not supported */
|
||||||
|
#define EOPABORT 0xFF01 /* Operation aborted */
|
||||||
|
#define EINVALARG 0xFF02 /* Invalid argument */
|
||||||
|
#define EDEVNOTSUP 0xFF03 /* Not supported by device */
|
||||||
|
#define ENOTIMPL 0xFF04 /* Not (yet) implemented in libnfc */
|
||||||
|
|
||||||
# ifdef __cplusplus
|
# ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,32 +276,32 @@ select:
|
||||||
// Read error
|
// Read error
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
DBG ("%s", "RX error.");
|
DBG ("%s", "RX error.");
|
||||||
return DEIO;
|
return ECOMIO;
|
||||||
}
|
}
|
||||||
// Read time-out
|
// Read time-out
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
DBG ("Timeout!");
|
DBG ("Timeout!");
|
||||||
return DETIMEOUT;
|
return ECOMTIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET (iAbortFd, &rfds)) {
|
if (FD_ISSET (iAbortFd, &rfds)) {
|
||||||
// Abort requested
|
// Abort requested
|
||||||
DBG ("Abort!");
|
DBG ("Abort!");
|
||||||
close (iAbortFd);
|
close (iAbortFd);
|
||||||
return DEABORT;
|
return EOPABORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the count of the incoming bytes
|
// Retrieve the count of the incoming bytes
|
||||||
res = ioctl (((serial_port_unix *) sp)->fd, FIONREAD, &available_bytes_count);
|
res = ioctl (((serial_port_unix *) sp)->fd, FIONREAD, &available_bytes_count);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
return DEIO;
|
return ECOMIO;
|
||||||
}
|
}
|
||||||
// There is something available, read the data
|
// There is something available, read the data
|
||||||
// DBG ("expected bytes: %zu, received bytes: %d, available bytes: %d", szRx, received_bytes_count, available_bytes_count);
|
// DBG ("expected bytes: %zu, received bytes: %d, available bytes: %d", szRx, received_bytes_count, available_bytes_count);
|
||||||
res = read (((serial_port_unix *) sp)->fd, pbtRx + received_bytes_count, MIN(available_bytes_count, (expected_bytes_count - received_bytes_count)));
|
res = read (((serial_port_unix *) sp)->fd, pbtRx + received_bytes_count, MIN(available_bytes_count, (expected_bytes_count - received_bytes_count)));
|
||||||
// Stop if the OS has some troubles reading the data
|
// Stop if the OS has some troubles reading the data
|
||||||
if (res <= 0) {
|
if (res <= 0) {
|
||||||
return DEIO;
|
return ECOMIO;
|
||||||
}
|
}
|
||||||
received_bytes_count += res;
|
received_bytes_count += res;
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx)
|
||||||
if ((int) szTx == write (((serial_port_unix *) sp)->fd, pbtTx, szTx))
|
if ((int) szTx == write (((serial_port_unix *) sp)->fd, pbtTx, szTx))
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return DEIO;
|
return ECOMIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
char **
|
char **
|
||||||
|
|
|
@ -165,18 +165,18 @@ uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p)
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
WARN("ReadFile returned error\n");
|
WARN("ReadFile returned error\n");
|
||||||
return DEIO;
|
return ECOMIO;
|
||||||
}
|
}
|
||||||
if (((DWORD)szRx) > dwTotalBytesReceived) {
|
if (((DWORD)szRx) > dwTotalBytesReceived) {
|
||||||
dwBytesToGet -= dwBytesReceived;
|
dwBytesToGet -= dwBytesReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abort_flag_p != NULL && (*abort_flag_p) && dwTotalBytesReceived == 0) {
|
if (abort_flag_p != NULL && (*abort_flag_p) && dwTotalBytesReceived == 0) {
|
||||||
return DEABORT;
|
return EOPABORT;
|
||||||
}
|
}
|
||||||
} while (((DWORD)szRx) > dwTotalBytesReceived);
|
} while (((DWORD)szRx) > dwTotalBytesReceived);
|
||||||
|
|
||||||
return (dwTotalBytesReceived == (DWORD) szRx) ? 0 : DEIO;
|
return (dwTotalBytesReceived == (DWORD) szRx) ? 0 : ECOMIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -184,10 +184,10 @@ uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx)
|
||||||
{
|
{
|
||||||
DWORD dwTxLen = 0;
|
DWORD dwTxLen = 0;
|
||||||
if (!WriteFile (((serial_port_windows *) sp)->hPort, pbtTx, szTx, &dwTxLen, NULL)) {
|
if (!WriteFile (((serial_port_windows *) sp)->hPort, pbtTx, szTx, &dwTxLen, NULL)) {
|
||||||
return DEIO;
|
return ECOMIO;
|
||||||
}
|
}
|
||||||
if (!dwTxLen)
|
if (!dwTxLen)
|
||||||
return DEIO;
|
return ECOMIO;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -935,7 +935,7 @@ pn53x_initiator_select_passive_target (nfc_device_t * pnd,
|
||||||
|
|
||||||
const pn53x_modulation_t pm = pn53x_nm_to_pm(nm);
|
const pn53x_modulation_t pm = pn53x_nm_to_pm(nm);
|
||||||
if (PM_UNDEFINED == pm) {
|
if (PM_UNDEFINED == pm) {
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EINVALARG;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -968,7 +968,7 @@ pn53x_initiator_poll_targets (nfc_device_t * pnd,
|
||||||
for (size_t n=0; n<szModulations; n++) {
|
for (size_t n=0; n<szModulations; n++) {
|
||||||
const pn53x_target_type_t ptt = pn53x_nm_to_ptt(pnmModulations[n]);
|
const pn53x_target_type_t ptt = pn53x_nm_to_ptt(pnmModulations[n]);
|
||||||
if (PTT_UNDEFINED == ptt) {
|
if (PTT_UNDEFINED == ptt) {
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EINVALARG;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
apttTargetTypes[szTargetTypes] = ptt;
|
apttTargetTypes[szTargetTypes] = ptt;
|
||||||
|
@ -1084,7 +1084,7 @@ pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, cons
|
||||||
|
|
||||||
// We can not just send bytes without parity if while the PN53X expects we handled them
|
// We can not just send bytes without parity if while the PN53X expects we handled them
|
||||||
if (!pnd->bPar) {
|
if (!pnd->bPar) {
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EINVALARG;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1215,18 +1215,17 @@ pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx,
|
||||||
|
|
||||||
// Sorry, no arbitrary parity bits support for now
|
// Sorry, no arbitrary parity bits support for now
|
||||||
if (!pnd->bPar) {
|
if (!pnd->bPar) {
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = ENOTIMPL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Sorry, no easy framing support
|
// Sorry, no easy framing support
|
||||||
if (pnd->bEasyFraming) {
|
if (pnd->bEasyFraming) {
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = ENOTIMPL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Sorry, no CRC support
|
// TODO CRC support but it probably doesn't make sense for (szTxBits % 8 != 0) ...
|
||||||
// TODO but it probably doesn't make sense for (szTxBits % 8 != 0) ...
|
|
||||||
if (pnd->bCrc) {
|
if (pnd->bCrc) {
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = ENOTIMPL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1315,13 +1314,13 @@ pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx
|
||||||
|
|
||||||
// We can not just send bytes without parity while the PN53X expects we handled them
|
// We can not just send bytes without parity while the PN53X expects we handled them
|
||||||
if (!pnd->bPar) {
|
if (!pnd->bPar) {
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EINVALARG;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Sorry, no easy framing support
|
// Sorry, no easy framing support
|
||||||
// TODO: to be changed once we'll provide easy framing support from libnfc itself...
|
// TODO to be changed once we'll provide easy framing support from libnfc itself...
|
||||||
if (pnd->bEasyFraming) {
|
if (pnd->bEasyFraming) {
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = ENOTIMPL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1459,7 +1458,7 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EDEVNOTSUP;
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1561,7 +1560,7 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_
|
||||||
case NMT_ISO14443B2SR:
|
case NMT_ISO14443B2SR:
|
||||||
case NMT_ISO14443B2CT:
|
case NMT_ISO14443B2CT:
|
||||||
case NMT_JEWEL:
|
case NMT_JEWEL:
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EDEVNOTSUP;
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1686,7 +1685,7 @@ pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx)
|
||||||
abtCmd[0] = TgGetData;
|
abtCmd[0] = TgGetData;
|
||||||
} else {
|
} else {
|
||||||
// TODO Support EasyFraming for other cases by software
|
// TODO Support EasyFraming for other cases by software
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = ENOTIMPL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1702,8 +1701,6 @@ pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx)
|
||||||
// Save the received byte count
|
// Save the received byte count
|
||||||
*pszRx = szRx - 1;
|
*pszRx = szRx - 1;
|
||||||
|
|
||||||
// FIXME szRx can be 0
|
|
||||||
|
|
||||||
// Copy the received bytes
|
// Copy the received bytes
|
||||||
memcpy (pbtRx, abtRx + 1, *pszRx);
|
memcpy (pbtRx, abtRx + 1, *pszRx);
|
||||||
|
|
||||||
|
@ -1766,7 +1763,7 @@ pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t
|
||||||
abtCmd[0] = TgSetData;
|
abtCmd[0] = TgSetData;
|
||||||
} else {
|
} else {
|
||||||
// TODO Support EasyFraming for other cases by software
|
// TODO Support EasyFraming for other cases by software
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = ENOTIMPL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1788,7 +1785,7 @@ static struct sErrorMessage {
|
||||||
int iErrorCode;
|
int iErrorCode;
|
||||||
const char *pcErrorMsg;
|
const char *pcErrorMsg;
|
||||||
} sErrorMessages[] = {
|
} sErrorMessages[] = {
|
||||||
/* Chip-level errors */
|
/* Chip-level errors (internal errors, RF errors, etc.) */
|
||||||
{ 0x00, "Success" },
|
{ 0x00, "Success" },
|
||||||
{ ETIMEOUT, "Timeout" }, // Time Out, the target has not answered
|
{ ETIMEOUT, "Timeout" }, // Time Out, the target has not answered
|
||||||
{ ECRC, "CRC Error" }, // A CRC error has been detected by the CIU
|
{ ECRC, "CRC Error" }, // A CRC error has been detected by the CIU
|
||||||
|
@ -1803,39 +1800,36 @@ static struct sErrorMessage {
|
||||||
{ EOVHEAT, "Chip Overheating" }, // Temperature error: the internal temperature sensor has detected overheating, and therefore has automatically switched off the antenna drivers
|
{ EOVHEAT, "Chip Overheating" }, // Temperature error: the internal temperature sensor has detected overheating, and therefore has automatically switched off the antenna drivers
|
||||||
{ EINBUFOVF, "Internal Buffer overflow."}, // Internal buffer overflow
|
{ EINBUFOVF, "Internal Buffer overflow."}, // Internal buffer overflow
|
||||||
{ EINVPARAM, "Invalid Parameter"}, // Invalid parameter (range, format, …)
|
{ EINVPARAM, "Invalid Parameter"}, // Invalid parameter (range, format, …)
|
||||||
/* DEP Errors */
|
{ EOPNOTALL, "Operation Not Allowed" }, // Operation not allowed in this configuration (host controller interface)
|
||||||
|
{ ECMD, "Command Not Acceptable" }, // Command is not acceptable due to the current context
|
||||||
|
{ EOVCURRENT, "Over Current" },
|
||||||
|
/* DEP errors */
|
||||||
{ EDEPUNKCMD, "Unknown DEP Command" },
|
{ EDEPUNKCMD, "Unknown DEP Command" },
|
||||||
|
{ EDEPINVSTATE, "Invalid DEP State" }, // DEP Protocol: Invalid device state, the system is in a state which does not allow the operation
|
||||||
|
{ ENAD, "NAD Missing in DEP Frame" },
|
||||||
/* MIFARE */
|
/* MIFARE */
|
||||||
{ EMFAUTH, "Mifare Authentication Error" },
|
{ EMFAUTH, "Mifare Authentication Error" },
|
||||||
/* */
|
/* Misc */
|
||||||
{ EINVRXFRAM, "Invalid Received Frame" }, // DEP Protocol, Mifare or ISO/IEC14443-4: The data format does not match to the specification.
|
{ EINVRXFRAM, "Invalid Received Frame" }, // DEP Protocol, Mifare or ISO/IEC14443-4: The data format does not match to the specification.
|
||||||
{ ENSECNOTSUPP, "NFC Secure not supported" }, // Target or Initiator does not support NFC Secure
|
{ ENSECNOTSUPP, "NFC Secure not supported" }, // Target or Initiator does not support NFC Secure
|
||||||
{ EBCC, "Wrong UID Check Byte (BCC)" }, // ISO/IEC14443-3: UID Check byte is wrong
|
{ EBCC, "Wrong UID Check Byte (BCC)" }, // ISO/IEC14443-3: UID Check byte is wrong
|
||||||
{ EDEPINVSTATE, "Invalid DEP State" }, // DEP Protocol: Invalid device state, the system is in a state which does not allow the operation
|
|
||||||
{ EOPNOTALL, "Operation Not Allowed" }, // Operation not allowed in this configuration (host controller interface)
|
|
||||||
{ ECMD, "Command Not Acceptable" }, // Command is not acceptable due to the current context
|
|
||||||
{ ETGREL, "Target Released" }, // Target have been released by initiator
|
{ ETGREL, "Target Released" }, // Target have been released by initiator
|
||||||
// FIXME: Errors can be grouped (DEP-related, MIFARE-related, ISO14443B-related, etc.)
|
|
||||||
// Purposal: Use prefix/suffix to identify them
|
|
||||||
{ ECID, "Card ID Mismatch" }, // ISO14443 type B: Card ID mismatch, meaning that the expected card has been exchanged with another one.
|
{ ECID, "Card ID Mismatch" }, // ISO14443 type B: Card ID mismatch, meaning that the expected card has been exchanged with another one.
|
||||||
{ ECDISCARDED, "Card Discarded" }, // ISO/IEC14443 type B: the card previously activated has disappeared.
|
{ ECDISCARDED, "Card Discarded" }, // ISO/IEC14443 type B: the card previously activated has disappeared.
|
||||||
{ ENFCID3, "NFCID3 Mismatch" },
|
{ ENFCID3, "NFCID3 Mismatch" },
|
||||||
{ EOVCURRENT, "Over Current" },
|
|
||||||
{ ENAD, "NAD Missing in DEP Frame" },
|
|
||||||
/* Software level errors */
|
/* 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
|
{ 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 */
|
{ EOPABORT, "Operation aborted" }, // Error used to catch a user-requested command abort
|
||||||
{ DENACK, "Received NACK" },
|
{ EINVALARG, "Invalid argument" }, // Function called with invalid argument(s)
|
||||||
{ DEACKMISMATCH, "Expected ACK/NACK" },
|
{ ENOTIMPL, "Not (yet) implemented in library" },
|
||||||
{ DEISERRFRAME, "Received an error frame" },
|
/* Framming-level errors */
|
||||||
// TODO: Move me in more generic code for libnfc 1.6
|
{ EFRAACKMISMATCH, "Expected ACK frame" },
|
||||||
// FIXME: Driver-errors and Device-errors have the same prefix (DE*)
|
{ EFRAISERRFRAME, "Received an error frame" },
|
||||||
// eg. DENACK means Driver Error NACK while DEIO means Device Error I/O
|
/* Communication-level errors */
|
||||||
{ DEINVAL, "Invalid argument" },
|
{ ECOMIO, "Input/output error" }, // Communication I/O errors: connection broken, read/write failure, unreacheable device, etc.
|
||||||
{ DEIO, "Input/output error" },
|
{ ECOMTIMEOUT, "Operation timed-out" }, // A timeout occured while reading device's reply
|
||||||
{ DETIMEOUT, "Operation timed-out" },
|
/* Device-level errors */
|
||||||
{ DEABORT, "Operation aborted" },
|
{ EDEVNOTSUP, "Operation not supported by device" } // Requested task can not be done by current device
|
||||||
{ DENOTSUP, "Operation not supported" }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@ -1891,7 +1885,7 @@ pn53x_SAMConfiguration (nfc_device_t * pnd, const uint8_t ui8Mode)
|
||||||
// TODO: Handle these SAM mode
|
// TODO: Handle these SAM mode
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EINVALARG;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (pn53x_transceive (pnd, abtCmd, szCmd, NULL, NULL));
|
return (pn53x_transceive (pnd, abtCmd, szCmd, NULL, NULL));
|
||||||
|
@ -1938,14 +1932,14 @@ pn53x_InListPassiveTarget (nfc_device_t * pnd,
|
||||||
case PM_ISO14443B_106:
|
case PM_ISO14443B_106:
|
||||||
if (!(pnd->btSupportByte & SUPPORT_ISO14443B)) {
|
if (!(pnd->btSupportByte & SUPPORT_ISO14443B)) {
|
||||||
// Eg. Some PN532 doesn't support type B!
|
// Eg. Some PN532 doesn't support type B!
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EDEVNOTSUP;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PM_JEWEL_106:
|
case PM_JEWEL_106:
|
||||||
if(CHIP_DATA(pnd)->type == PN531) {
|
if(CHIP_DATA(pnd)->type == PN531) {
|
||||||
// These modulations are not supported by pn531
|
// These modulations are not supported by pn531
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EDEVNOTSUP;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1954,12 +1948,12 @@ pn53x_InListPassiveTarget (nfc_device_t * pnd,
|
||||||
case PM_ISO14443B_847:
|
case PM_ISO14443B_847:
|
||||||
if((CHIP_DATA(pnd)->type != PN533) || (!(pnd->btSupportByte & SUPPORT_ISO14443B))) {
|
if((CHIP_DATA(pnd)->type != PN533) || (!(pnd->btSupportByte & SUPPORT_ISO14443B))) {
|
||||||
// These modulations are not supported by pn531 neither pn532
|
// These modulations are not supported by pn531 neither pn532
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EDEVNOTSUP;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EINVALARG;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
abtCmd[2] = pmInitModulation; // BrTy, the type of init modulation used for polling a passive tag
|
abtCmd[2] = pmInitModulation; // BrTy, the type of init modulation used for polling a passive tag
|
||||||
|
@ -2022,7 +2016,7 @@ pn53x_InAutoPoll (nfc_device_t * pnd,
|
||||||
{
|
{
|
||||||
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
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EDEVNOTSUP;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2103,7 +2097,7 @@ pn53x_InJumpForDEP (nfc_device_t * pnd,
|
||||||
break;
|
break;
|
||||||
case NBR_847:
|
case NBR_847:
|
||||||
case NBR_UNDEFINED:
|
case NBR_UNDEFINED:
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EINVALARG;
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2123,7 +2117,7 @@ pn53x_InJumpForDEP (nfc_device_t * pnd,
|
||||||
break;
|
break;
|
||||||
case NBR_847:
|
case NBR_847:
|
||||||
case NBR_UNDEFINED:
|
case NBR_UNDEFINED:
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = EINVALARG;
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2251,7 +2245,7 @@ pn53x_check_ack_frame (nfc_device_t * pnd, const byte_t * pbtRxFrame, const size
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pnd->iLastError = DEACKMISMATCH;
|
pnd->iLastError = EFRAACKMISMATCH;
|
||||||
ERR ("%s", "Unexpected PN53x reply!");
|
ERR ("%s", "Unexpected PN53x reply!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2262,7 +2256,7 @@ pn53x_check_error_frame (nfc_device_t * pnd, const byte_t * pbtRxFrame, const si
|
||||||
if (szRxFrameLen >= sizeof (pn53x_error_frame)) {
|
if (szRxFrameLen >= sizeof (pn53x_error_frame)) {
|
||||||
if (0 == memcmp (pbtRxFrame, pn53x_error_frame, sizeof (pn53x_error_frame))) {
|
if (0 == memcmp (pbtRxFrame, pn53x_error_frame, sizeof (pn53x_error_frame))) {
|
||||||
DBG ("%s", "PN53x sent an error frame");
|
DBG ("%s", "PN53x sent an error frame");
|
||||||
pnd->iLastError = DEISERRFRAME;
|
pnd->iLastError = EFRAISERRFRAME;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,11 +114,6 @@
|
||||||
# define RFCI_ANALOG_TYPE_B 0x0C // 3
|
# define RFCI_ANALOG_TYPE_B 0x0C // 3
|
||||||
# define RFCI_ANALOG_TYPE_14443_4 0x0D // 9
|
# define RFCI_ANALOG_TYPE_14443_4 0x0D // 9
|
||||||
|
|
||||||
/* PN53x specific device-level errors */
|
|
||||||
# define DENACK 0x0100/* NACK */
|
|
||||||
# define DEACKMISMATCH 0x0200/* Unexpected data */
|
|
||||||
# define DEISERRFRAME 0x0300/* Error frame */
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NORMAL, // In that case, there is no power saved but the PN53x reacts as fast as possible on the host controller interface.
|
NORMAL, // In that case, there is no power saved but the PN53x reacts as fast as possible on the host controller interface.
|
||||||
POWERDOWN, // Only on PN532, need to be wake up to process commands with a long preamble
|
POWERDOWN, // Only on PN532, need to be wake up to process commands with a long preamble
|
||||||
|
|
|
@ -254,7 +254,7 @@ acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
|
||||||
{
|
{
|
||||||
// Make sure the command does not overflow the send buffer
|
// Make sure the command does not overflow the send buffer
|
||||||
if (szData > ACR122_COMMAND_LEN) {
|
if (szData > ACR122_COMMAND_LEN) {
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = EINVALARG;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
|
||||||
* field.
|
* field.
|
||||||
*/
|
*/
|
||||||
if (SCardControl (DRIVER_DATA (pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtTxBuf, szTxBuf, DRIVER_DATA (pnd)->abtRx, ACR122_RESPONSE_LEN, &dwRxLen) != SCARD_S_SUCCESS) {
|
if (SCardControl (DRIVER_DATA (pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtTxBuf, szTxBuf, DRIVER_DATA (pnd)->abtRx, ACR122_RESPONSE_LEN, &dwRxLen) != SCARD_S_SUCCESS) {
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -292,7 +292,7 @@ acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
|
||||||
* receive the response from the PN532.
|
* receive the response from the PN532.
|
||||||
*/
|
*/
|
||||||
if (SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtTxBuf, szTxBuf, NULL, DRIVER_DATA (pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
|
if (SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtTxBuf, szTxBuf, NULL, DRIVER_DATA (pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,12 +304,12 @@ acr122_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
|
||||||
|
|
||||||
// Make sure we received the byte-count we expected
|
// Make sure we received the byte-count we expected
|
||||||
if (dwRxLen != 2) {
|
if (dwRxLen != 2) {
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check if the operation was successful, so an answer is available
|
// Check if the operation was successful, so an answer is available
|
||||||
if (DRIVER_DATA (pnd)->abtRx[0] == SCARD_OPERATION_ERROR) {
|
if (DRIVER_DATA (pnd)->abtRx[0] == SCARD_OPERATION_ERROR) {
|
||||||
pnd->iLastError = DEISERRFRAME;
|
pnd->iLastError = EFRAISERRFRAME;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -332,7 +332,7 @@ acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData)
|
||||||
DWORD dwRxLen = sizeof (DRIVER_DATA (pnd)->abtRx);
|
DWORD dwRxLen = sizeof (DRIVER_DATA (pnd)->abtRx);
|
||||||
abtRxCmd[4] = DRIVER_DATA (pnd)->abtRx[1];
|
abtRxCmd[4] = DRIVER_DATA (pnd)->abtRx[1];
|
||||||
if (SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtRxCmd, sizeof (abtRxCmd), NULL, DRIVER_DATA (pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
|
if (SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtRxCmd, sizeof (abtRxCmd), NULL, DRIVER_DATA (pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
DRIVER_DATA (pnd)->szRx = dwRxLen;
|
DRIVER_DATA (pnd)->szRx = dwRxLen;
|
||||||
|
@ -347,7 +347,7 @@ acr122_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szData)
|
||||||
|
|
||||||
// Make sure we have an emulated answer that fits the return buffer
|
// Make sure we have an emulated answer that fits the return buffer
|
||||||
if (DRIVER_DATA (pnd)->szRx < 4 || (DRIVER_DATA (pnd)->szRx - 4) > szData) {
|
if (DRIVER_DATA (pnd)->szRx < 4 || (DRIVER_DATA (pnd)->szRx - 4) > szData) {
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// Wipe out the 4 APDU emulation bytes: D5 4B .. .. .. 90 00
|
// Wipe out the 4 APDU emulation bytes: D5 4B .. .. .. 90 00
|
||||||
|
|
|
@ -244,12 +244,12 @@ arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szDat
|
||||||
if (szData > PN53x_NORMAL_FRAME__DATA_MAX_LEN) {
|
if (szData > PN53x_NORMAL_FRAME__DATA_MAX_LEN) {
|
||||||
// ARYGON Reader with PN532 equipped does not support extended frame (bug in ARYGON firmware?)
|
// ARYGON Reader with PN532 equipped does not support extended frame (bug in ARYGON firmware?)
|
||||||
DBG ("ARYGON device does not support more than %d bytes as payload (requested: %zd)", PN53x_NORMAL_FRAME__DATA_MAX_LEN, szData);
|
DBG ("ARYGON device does not support more than %d bytes as payload (requested: %zd)", PN53x_NORMAL_FRAME__DATA_MAX_LEN, szData);
|
||||||
pnd->iLastError = DEINVAL;
|
pnd->iLastError = EDEVNOTSUP;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pn53x_build_frame (abtFrame + 1, &szFrame, pbtData, szData)) {
|
if (!pn53x_build_frame (abtFrame + 1, &szFrame, pbtData, szData)) {
|
||||||
pnd->iLastError = DEINVAL;
|
pnd->iLastError = EINVALARG;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,11 +319,11 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
|
||||||
|
|
||||||
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_p);
|
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_p);
|
||||||
|
|
||||||
if (abort_p && (DEABORT == pnd->iLastError)) {
|
if (abort_p && (EOPABORT == pnd->iLastError)) {
|
||||||
arygon_abort (pnd);
|
arygon_abort (pnd);
|
||||||
|
|
||||||
/* iLastError got reset by arygon_abort() */
|
/* iLastError got reset by arygon_abort() */
|
||||||
pnd->iLastError = DEABORT;
|
pnd->iLastError = EOPABORT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
|
||||||
const byte_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
|
const byte_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
|
||||||
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
|
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
|
||||||
ERR ("%s", "Frame preamble+start code mismatch");
|
ERR ("%s", "Frame preamble+start code mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +343,7 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
|
||||||
// Error frame
|
// Error frame
|
||||||
uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 3, 0);
|
uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 3, 0);
|
||||||
ERR ("%s", "Application level error detected");
|
ERR ("%s", "Application level error detected");
|
||||||
pnd->iLastError = DEISERRFRAME;
|
pnd->iLastError = EFRAISERRFRAME;
|
||||||
return -1;
|
return -1;
|
||||||
} else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
|
} else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
|
||||||
// Extended frame
|
// Extended frame
|
||||||
|
@ -354,7 +354,7 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
|
||||||
if (256 != (abtRxBuf[3] + abtRxBuf[4])) {
|
if (256 != (abtRxBuf[3] + abtRxBuf[4])) {
|
||||||
// TODO: Retry
|
// TODO: Retry
|
||||||
ERR ("%s", "Length checksum mismatch");
|
ERR ("%s", "Length checksum mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,7 +364,7 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
|
||||||
|
|
||||||
if (len > szDataLen) {
|
if (len > szDataLen) {
|
||||||
ERR ("Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
ERR ("Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,13 +377,13 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
|
||||||
|
|
||||||
if (abtRxBuf[0] != 0xD5) {
|
if (abtRxBuf[0] != 0xD5) {
|
||||||
ERR ("%s", "TFI Mismatch");
|
ERR ("%s", "TFI Mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abtRxBuf[1] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
|
if (abtRxBuf[1] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
|
||||||
ERR ("%s", "Command Code verification failed");
|
ERR ("%s", "Command Code verification failed");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,13 +409,13 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
|
||||||
|
|
||||||
if (btDCS != abtRxBuf[0]) {
|
if (btDCS != abtRxBuf[0]) {
|
||||||
ERR ("%s", "Data checksum mismatch");
|
ERR ("%s", "Data checksum mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0x00 != abtRxBuf[1]) {
|
if (0x00 != abtRxBuf[1]) {
|
||||||
ERR ("%s", "Frame postamble mismatch");
|
ERR ("%s", "Frame postamble mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// The PN53x command is done and we successfully received the reply
|
// The PN53x command is done and we successfully received the reply
|
||||||
|
|
|
@ -250,7 +250,7 @@ pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData
|
||||||
size_t szFrame = 0;
|
size_t szFrame = 0;
|
||||||
|
|
||||||
if (!pn53x_build_frame (abtFrame, &szFrame, pbtData, szData)) {
|
if (!pn53x_build_frame (abtFrame, &szFrame, pbtData, szData)) {
|
||||||
pnd->iLastError = DEINVAL;
|
pnd->iLastError = EINVALARG;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
|
||||||
|
|
||||||
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p);
|
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p);
|
||||||
|
|
||||||
if (abort_p && (DEABORT == pnd->iLastError)) {
|
if (abort_p && (EOPABORT == pnd->iLastError)) {
|
||||||
pn532_uart_ack (pnd);
|
pn532_uart_ack (pnd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
|
||||||
const byte_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
|
const byte_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
|
||||||
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
|
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
|
||||||
ERR ("%s", "Frame preamble+start code mismatch");
|
ERR ("%s", "Frame preamble+start code mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
|
||||||
// Error frame
|
// Error frame
|
||||||
uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0);
|
uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0);
|
||||||
ERR ("%s", "Application level error detected");
|
ERR ("%s", "Application level error detected");
|
||||||
pnd->iLastError = DEISERRFRAME;
|
pnd->iLastError = EFRAISERRFRAME;
|
||||||
return -1;
|
return -1;
|
||||||
} else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
|
} else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
|
||||||
// Extended frame
|
// Extended frame
|
||||||
|
@ -335,7 +335,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
|
||||||
if (((abtRxBuf[0] + abtRxBuf[1] + abtRxBuf[2]) % 256) != 0) {
|
if (((abtRxBuf[0] + abtRxBuf[1] + abtRxBuf[2]) % 256) != 0) {
|
||||||
// TODO: Retry
|
// TODO: Retry
|
||||||
ERR ("%s", "Length checksum mismatch");
|
ERR ("%s", "Length checksum mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -343,7 +343,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
|
||||||
if (256 != (abtRxBuf[3] + abtRxBuf[4])) {
|
if (256 != (abtRxBuf[3] + abtRxBuf[4])) {
|
||||||
// TODO: Retry
|
// TODO: Retry
|
||||||
ERR ("%s", "Length checksum mismatch");
|
ERR ("%s", "Length checksum mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
|
||||||
|
|
||||||
if (len > szDataLen) {
|
if (len > szDataLen) {
|
||||||
ERR ("Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
ERR ("Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,13 +366,13 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
|
||||||
|
|
||||||
if (abtRxBuf[0] != 0xD5) {
|
if (abtRxBuf[0] != 0xD5) {
|
||||||
ERR ("%s", "TFI Mismatch");
|
ERR ("%s", "TFI Mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abtRxBuf[1] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
|
if (abtRxBuf[1] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
|
||||||
ERR ("%s", "Command Code verification failed");
|
ERR ("%s", "Command Code verification failed");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,13 +398,13 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
|
||||||
|
|
||||||
if (btDCS != abtRxBuf[0]) {
|
if (btDCS != abtRxBuf[0]) {
|
||||||
ERR ("%s", "Data checksum mismatch");
|
ERR ("%s", "Data checksum mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0x00 != abtRxBuf[1]) {
|
if (0x00 != abtRxBuf[1]) {
|
||||||
ERR ("%s", "Frame postamble mismatch");
|
ERR ("%s", "Frame postamble mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// The PN53x command is done and we successfully received the reply
|
// The PN53x command is done and we successfully received the reply
|
||||||
|
|
|
@ -423,14 +423,14 @@ pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
|
||||||
int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), abtFrame, szFrame);
|
int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), abtFrame, szFrame);
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte_t abtRxBuf[PN53X_USB_BUFFER_LEN];
|
byte_t abtRxBuf[PN53X_USB_BUFFER_LEN];
|
||||||
res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf));
|
res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf));
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
// try to interrupt current device state
|
// try to interrupt current device state
|
||||||
pn53x_usb_ack(pnd);
|
pn53x_usb_ack(pnd);
|
||||||
return false;
|
return false;
|
||||||
|
@ -447,7 +447,7 @@ pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData)
|
||||||
// packet.
|
// packet.
|
||||||
int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), (byte_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame));
|
int res = pn53x_usb_bulk_write (DRIVER_DATA (pnd), (byte_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame));
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
// try to interrupt current device state
|
// try to interrupt current device state
|
||||||
pn53x_usb_ack(pnd);
|
pn53x_usb_ack(pnd);
|
||||||
return false;
|
return false;
|
||||||
|
@ -485,7 +485,7 @@ read:
|
||||||
if (DRIVER_DATA (pnd)->abort_flag) {
|
if (DRIVER_DATA (pnd)->abort_flag) {
|
||||||
DRIVER_DATA (pnd)->abort_flag = false;
|
DRIVER_DATA (pnd)->abort_flag = false;
|
||||||
pn53x_usb_ack (pnd);
|
pn53x_usb_ack (pnd);
|
||||||
pnd->iLastError = DEABORT;
|
pnd->iLastError = EOPABORT;
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
goto read;
|
goto read;
|
||||||
|
@ -493,7 +493,7 @@ read:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
// try to interrupt current device state
|
// try to interrupt current device state
|
||||||
pn53x_usb_ack(pnd);
|
pn53x_usb_ack(pnd);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -502,7 +502,7 @@ read:
|
||||||
const byte_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
|
const byte_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
|
||||||
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
|
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
|
||||||
ERR ("%s", "Frame preamble+start code mismatch");
|
ERR ("%s", "Frame preamble+start code mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
offset += 3;
|
offset += 3;
|
||||||
|
@ -510,7 +510,7 @@ read:
|
||||||
if ((0x01 == abtRxBuf[offset]) && (0xff == abtRxBuf[offset + 1])) {
|
if ((0x01 == abtRxBuf[offset]) && (0xff == abtRxBuf[offset + 1])) {
|
||||||
// Error frame
|
// Error frame
|
||||||
ERR ("%s", "Application level error detected");
|
ERR ("%s", "Application level error detected");
|
||||||
pnd->iLastError = DEISERRFRAME;
|
pnd->iLastError = EFRAISERRFRAME;
|
||||||
return -1;
|
return -1;
|
||||||
} else if ((0xff == abtRxBuf[offset]) && (0xff == abtRxBuf[offset + 1])) {
|
} else if ((0xff == abtRxBuf[offset]) && (0xff == abtRxBuf[offset + 1])) {
|
||||||
// Extended frame
|
// Extended frame
|
||||||
|
@ -521,7 +521,7 @@ read:
|
||||||
if (((abtRxBuf[offset] + abtRxBuf[offset + 1] + abtRxBuf[offset + 2]) % 256) != 0) {
|
if (((abtRxBuf[offset] + abtRxBuf[offset + 1] + abtRxBuf[offset + 2]) % 256) != 0) {
|
||||||
// TODO: Retry
|
// TODO: Retry
|
||||||
ERR ("%s", "Length checksum mismatch");
|
ERR ("%s", "Length checksum mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
offset += 3;
|
offset += 3;
|
||||||
|
@ -530,7 +530,7 @@ read:
|
||||||
if (256 != (abtRxBuf[offset] + abtRxBuf[offset + 1])) {
|
if (256 != (abtRxBuf[offset] + abtRxBuf[offset + 1])) {
|
||||||
// TODO: Retry
|
// TODO: Retry
|
||||||
ERR ("%s", "Length checksum mismatch");
|
ERR ("%s", "Length checksum mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,21 +541,21 @@ read:
|
||||||
|
|
||||||
if (len > szDataLen) {
|
if (len > szDataLen) {
|
||||||
ERR ("Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
ERR ("Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TFI + PD0 (CC+1)
|
// TFI + PD0 (CC+1)
|
||||||
if (abtRxBuf[offset] != 0xD5) {
|
if (abtRxBuf[offset] != 0xD5) {
|
||||||
ERR ("%s", "TFI Mismatch");
|
ERR ("%s", "TFI Mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
offset += 1;
|
offset += 1;
|
||||||
|
|
||||||
if (abtRxBuf[offset] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
|
if (abtRxBuf[offset] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
|
||||||
ERR ("%s", "Command Code verification failed");
|
ERR ("%s", "Command Code verification failed");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
offset += 1;
|
offset += 1;
|
||||||
|
@ -571,14 +571,14 @@ read:
|
||||||
|
|
||||||
if (btDCS != abtRxBuf[offset]) {
|
if (btDCS != abtRxBuf[offset]) {
|
||||||
ERR ("%s", "Data checksum mismatch");
|
ERR ("%s", "Data checksum mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
offset += 1;
|
offset += 1;
|
||||||
|
|
||||||
if (0x00 != abtRxBuf[offset]) {
|
if (0x00 != abtRxBuf[offset]) {
|
||||||
ERR ("%s", "Frame postamble mismatch");
|
ERR ("%s", "Frame postamble mismatch");
|
||||||
pnd->iLastError = DEIO;
|
pnd->iLastError = ECOMIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// The PN53x command is done and we successfully received the reply
|
// The PN53x command is done and we successfully received the reply
|
||||||
|
|
|
@ -29,9 +29,6 @@
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
# include <err.h>
|
# include <err.h>
|
||||||
|
|
||||||
// TODO: Put generic errors here
|
|
||||||
# define DENOTSUP 0x0400/* Not supported */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @macro PRINT_HEX
|
* @macro PRINT_HEX
|
||||||
* @brief Print a byte-array in hexadecimal format (only in DEBUG mode)
|
* @brief Print a byte-array in hexadecimal format (only in DEBUG mode)
|
||||||
|
@ -96,7 +93,7 @@
|
||||||
if (pnd->driver->FUNCTION) { \
|
if (pnd->driver->FUNCTION) { \
|
||||||
return pnd->driver->FUNCTION( __VA_ARGS__ ); \
|
return pnd->driver->FUNCTION( __VA_ARGS__ ); \
|
||||||
} else { \
|
} else { \
|
||||||
pnd->iLastError = DENOTSUP; \
|
pnd->iLastError = EDEVNOTSUP; \
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue