send/receive callbacks from internal chip io return now libnfc error code on failure.

This commit is contained in:
Audrey Diacre 2012-01-05 13:24:41 +00:00
parent 81d76c8c70
commit c30e9eed36
11 changed files with 80 additions and 79 deletions

View file

@ -314,7 +314,7 @@ select:
} while (expected_bytes_count > received_bytes_count);
LOG_HEX ("RX", pbtRx, szRx);
return 0;
return NFC_SUCCESS;
}
/**
@ -328,7 +328,7 @@ uart_send (serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
(void) timeout;
LOG_HEX ("TX", pbtTx, szTx);
if ((int) szTx == write (UART_DATA(sp)->fd, pbtTx, szTx))
return 0;
return NFC_SUCCESS;
else
return NFC_EIO;
}

View file

@ -135,7 +135,7 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT
// Call the send/receice callback functions of the current driver
if ((res = CHIP_DATA (pnd)->io->send (pnd, pbtTx, szTx, timeout)) < 0) {
return pnd->last_error;
return res;
}
// Command is sent, we store the command
@ -147,7 +147,7 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT
}
if ((res = CHIP_DATA(pnd)->io->receive (pnd, pbtRx, *pszRx, timeout)) < 0) {
return pnd->last_error;
return res;
}
if ((CHIP_DATA(pnd)->type == PN532) && (TgInitAsTarget == pbtTx[0])) { // PN532 automatically wakeup on external RF field

View file

@ -127,7 +127,7 @@ typedef enum {
} pn53x_operating_mode;
struct pn53x_io {
bool (*send)(struct nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int (*send)(struct nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int (*receive)(struct nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int timeout);
};

View file

@ -309,7 +309,7 @@ acr122_disconnect (nfc_device *pnd)
nfc_device_free (pnd);
}
bool
int
acr122_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
{
// FIXME: timeout is not handled
@ -318,7 +318,7 @@ acr122_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int t
// Make sure the command does not overflow the send buffer
if (szData > ACR122_COMMAND_LEN) {
pnd->last_error = NFC_EINVARG;
return false;
return pnd->last_error;
}
// Prepare and transmit the send buffer
@ -345,7 +345,7 @@ acr122_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int t
*/
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->last_error = NFC_EIO;
return false;
return pnd->last_error;
}
} else {
/*
@ -354,7 +354,7 @@ acr122_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int t
*/
if (SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtTxBuf, szTxBuf, NULL, DRIVER_DATA (pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
pnd->last_error = NFC_EIO;
return false;
return pnd->last_error;
}
}
@ -366,18 +366,18 @@ acr122_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int t
// Make sure we received the byte-count we expected
if (dwRxLen != 2) {
pnd->last_error = NFC_EIO;
return false;
return pnd->last_error;
}
// Check if the operation was successful, so an answer is available
if (DRIVER_DATA (pnd)->abtRx[0] == SCARD_OPERATION_ERROR) {
pnd->last_error = NFC_EIO;
return false;
return pnd->last_error;
}
} else {
DRIVER_DATA (pnd)->szRx = dwRxLen;
}
return true;
return NFC_SUCCESS;
}
int
@ -397,7 +397,7 @@ acr122_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int time
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) {
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
DRIVER_DATA (pnd)->szRx = dwRxLen;
} else {
@ -410,7 +410,7 @@ acr122_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int time
// Make sure we have an emulated answer that fits the return buffer
if (DRIVER_DATA (pnd)->szRx < 4 || (DRIVER_DATA (pnd)->szRx - 4) > szData) {
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
// Wipe out the 4 APDU emulation bytes: D5 4B .. .. .. 90 00
len = DRIVER_DATA (pnd)->szRx - 4;

View file

@ -30,7 +30,7 @@ bool acr122_probe (nfc_connstring connstrings[], size_t connstrings_len, size
// Functions used by developer to handle connection to this device
nfc_device *acr122_connect (const nfc_connstring connstring);
bool acr122_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int acr122_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int acr122_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
void acr122_disconnect (nfc_device *pnd);

View file

@ -303,7 +303,7 @@ arygon_disconnect (nfc_device *pnd)
#define ARYGON_TX_BUFFER_LEN (PN53x_NORMAL_FRAME__DATA_MAX_LEN + PN53x_NORMAL_FRAME__OVERHEAD + 1)
#define ARYGON_RX_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool
int
arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
{
// Before sending anything, we need to discard from any junk bytes
@ -316,19 +316,19 @@ arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData,
// ARYGON Reader with PN532 equipped does not support extended frame (bug in ARYGON firmware?)
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "ARYGON device does not support more than %d bytes as payload (requested: %zd)", PN53x_NORMAL_FRAME__DATA_MAX_LEN, szData);
pnd->last_error = NFC_EDEVNOTSUPP;
return false;
return pnd->last_error;
}
if (pn53x_build_frame (abtFrame + 1, &szFrame, pbtData, szData) < 0) {
pnd->last_error = NFC_EINVARG;
return false;
return pnd->last_error;
}
int res = uart_send (DRIVER_DATA (pnd)->port, abtFrame, szFrame + 1, timeout);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
pnd->last_error = NFC_EIO;
return false;
return pnd->last_error;
}
uint8_t abtRxBuf[6];
@ -336,7 +336,7 @@ arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData,
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK");
pnd->last_error = NFC_EIO;
return false;
return pnd->last_error;
}
if (pn53x_check_ack_frame (pnd, abtRxBuf, sizeof(abtRxBuf)) == 0) {
@ -345,12 +345,12 @@ arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData,
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Bad frame format." );
// We have already read 6 bytes and arygon_error_unknown_mode is 10 bytes long
// so we have to read 4 remaining bytes to be synchronized at the next receiving pass.
uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 4, 0, timeout);
return false;
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 4, 0, timeout);
return pnd->last_error;
} else {
return false;
return pnd->last_error;
}
return true;
return NFC_SUCCESS;
}
int
@ -426,40 +426,40 @@ arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen,
if (len > szDataLen) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
// TFI + PD0 (CC+1)
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0, timeout);
if (pnd->last_error != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
return pnd->last_error;
}
if (abtRxBuf[0] != 0xD5) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
if (abtRxBuf[1] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
if (len) {
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, pbtData, len, 0, timeout);
if (pnd->last_error != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
return pnd->last_error;
}
}
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0, timeout);
if (pnd->last_error != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
return pnd->last_error;
}
uint8_t btDCS = (256 - 0xD5);
@ -471,13 +471,13 @@ arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen,
if (btDCS != abtRxBuf[0]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
if (0x00 != abtRxBuf[1]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
// The PN53x command is done and we successfully received the reply
return len;

View file

@ -35,8 +35,8 @@ bool arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size
nfc_device *arygon_connect (const nfc_connstring connstring);
void arygon_disconnect (nfc_device *pnd);
bool arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDat, int timeouta);
int arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDat, int timeouta);
extern const struct nfc_driver_t arygon_driver;

View file

@ -285,9 +285,10 @@ pn532_uart_wakeup (nfc_device *pnd)
}
#define PN532_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool
int
pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
{
int res = 0;
// Before sending anything, we need to discard from any junk bytes
uart_flush_input (DRIVER_DATA(pnd)->port);
@ -295,17 +296,17 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
case LOWVBAT: {
/** PN532C106 wakeup. */
if (-1 == pn532_uart_wakeup(pnd)) {
return false;
return NFC_ECHIP;
}
// According to PN532 application note, C106 appendix: to go out Low Vbat mode and enter in normal mode we need to send a SAMConfiguration command
if (pn53x_SAMConfiguration (pnd, 0x01, 500) < 0) {
return false;
if ((res = pn53x_SAMConfiguration (pnd, 0x01, 500)) < 0) {
return res;
}
}
break;
case POWERDOWN: {
if (-1 == pn532_uart_wakeup(pnd)) {
return false;
return NFC_ECHIP;
}
}
break;
@ -319,14 +320,14 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
if (pn53x_build_frame (abtFrame, &szFrame, pbtData, szData) < 0) {
pnd->last_error = NFC_EINVARG;
return false;
return pnd->last_error;
}
int res = uart_send (DRIVER_DATA(pnd)->port, abtFrame, szFrame, timeout);
res = uart_send (DRIVER_DATA(pnd)->port, abtFrame, szFrame, timeout);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
pnd->last_error = res;
return false;
return pnd->last_error;
}
uint8_t abtRxBuf[6];
@ -334,15 +335,15 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to read ACK");
pnd->last_error = res;
return false;
return pnd->last_error;
}
if (pn53x_check_ack_frame (pnd, abtRxBuf, sizeof(abtRxBuf)) == 0) {
// The PN53x is running the sent command
} else {
return false;
return pnd->last_error;
}
return true;
return NFC_SUCCESS;
}
int
@ -374,7 +375,7 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
if ((0x01 == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
@ -386,7 +387,7 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
} else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) {
// Extended frame
pnd->last_error = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0, timeout);
if (pnd->last_error) return -1;
if (pnd->last_error) return pnd->last_error;
// (abtRxBuf[0] << 8) + abtRxBuf[1] (LEN) include TFI + (CC+1)
len = (abtRxBuf[0] << 8) + abtRxBuf[1] - 2;
@ -394,7 +395,7 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
// TODO: Retry
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
} else {
// Normal frame
@ -402,7 +403,7 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
// TODO: Retry
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
// abtRxBuf[3] (LEN) include TFI + (CC+1)
@ -412,40 +413,40 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
if (len > szDataLen) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
// TFI + PD0 (CC+1)
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0, timeout);
if (pnd->last_error != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
return pnd->last_error;
}
if (abtRxBuf[0] != 0xD5) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
if (abtRxBuf[1] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
if (len) {
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, pbtData, len, 0, timeout);
if (pnd->last_error != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
return pnd->last_error;
}
}
pnd->last_error = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 2, 0, timeout);
if (pnd->last_error != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)");
return -1;
return pnd->last_error;
}
uint8_t btDCS = (256 - 0xD5);
@ -457,13 +458,13 @@ pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i
if (btDCS != abtRxBuf[0]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
if (0x00 != abtRxBuf[1]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
// The PN53x command is done and we successfully received the reply
return len;
@ -477,7 +478,7 @@ pn532_uart_ack (nfc_device *pnd)
return -1;
}
}
return (0 == uart_send (DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof (pn53x_ack_frame), 0)) ? 0 : -1;
return (uart_send (DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof (pn53x_ack_frame), 0) < 0) ? 0 : -1;
}
bool

View file

@ -33,8 +33,8 @@ bool pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len,
nfc_device *pn532_uart_connect (const nfc_connstring connstring);
void pn532_uart_disconnect (nfc_device *pnd);
bool pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
int pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
extern const struct nfc_driver_t pn532_uart_driver;

View file

@ -505,7 +505,7 @@ pn53x_usb_disconnect (nfc_device *pnd)
#define PN53X_USB_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool
int
pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, const int timeout)
{
uint8_t abtFrame[PN53X_USB_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
@ -517,7 +517,7 @@ pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, co
if (res < 0) {
pnd->last_error = NFC_EIO;
return false;
return pnd->last_error;
}
uint8_t abtRxBuf[PN53X_USB_BUFFER_LEN];
@ -526,7 +526,7 @@ pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, co
pnd->last_error = NFC_EIO;
// try to interrupt current device state
pn53x_usb_ack(pnd);
return false;
return pnd->last_error;
}
if (pn53x_check_ack_frame (pnd, abtRxBuf, res) == 0) {
@ -544,11 +544,11 @@ pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, co
pnd->last_error = NFC_EIO;
// try to interrupt current device state
pn53x_usb_ack(pnd);
return false;
return pnd->last_error;
}
}
return true;
return NFC_SUCCESS;
}
#define USB_TIMEOUT_PER_PASS 200
@ -575,7 +575,7 @@ read:
remaining_time -= USB_TIMEOUT_PER_PASS;
if (remaining_time <= 0) {
pnd->last_error = NFC_ETIMEOUT;
return -1;
return pnd->last_error;
} else {
usb_timeout = MIN(remaining_time, USB_TIMEOUT_PER_PASS);
}
@ -588,7 +588,7 @@ read:
DRIVER_DATA (pnd)->abort_flag = false;
pn53x_usb_ack (pnd);
pnd->last_error = NFC_EOPABORTED;
return -1;
return pnd->last_error;
} else {
goto read;
}
@ -598,14 +598,14 @@ read:
pnd->last_error = NFC_EIO;
// try to interrupt current device state
pn53x_usb_ack(pnd);
return -1;
return pnd->last_error;
}
const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff };
if (0 != (memcmp (abtRxBuf, pn53x_preamble, 3))) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
offset += 3;
@ -613,7 +613,7 @@ read:
// Error frame
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Application level error detected");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
} else if ((0xff == abtRxBuf[offset]) && (0xff == abtRxBuf[offset + 1])) {
// Extended frame
offset += 2;
@ -624,7 +624,7 @@ read:
// TODO: Retry
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
offset += 3;
} else {
@ -633,7 +633,7 @@ read:
// TODO: Retry
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Length checksum mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
// abtRxBuf[3] (LEN) include TFI + (CC+1)
@ -644,21 +644,21 @@ read:
if (len > szDataLen) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %zu, len: %zu)", szDataLen, len);
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
// TFI + PD0 (CC+1)
if (abtRxBuf[offset] != 0xD5) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "TFI Mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
offset += 1;
if (abtRxBuf[offset] != CHIP_DATA (pnd)->ui8LastCommand + 1) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Command Code verification failed");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
offset += 1;
@ -674,14 +674,14 @@ read:
if (btDCS != abtRxBuf[offset]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Data checksum mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
offset += 1;
if (0x00 != abtRxBuf[offset]) {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "%s", "Frame postamble mismatch");
pnd->last_error = NFC_EIO;
return -1;
return pnd->last_error;
}
// The PN53x command is done and we successfully received the reply
pnd->last_error = 0;

View file

@ -31,8 +31,8 @@
bool pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
nfc_device *pn53x_usb_connect (const nfc_connstring connstring);
bool pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int pn53x_usb_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
int pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int pn53x_usb_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
void pn53x_usb_disconnect (nfc_device *pnd);
extern const struct nfc_driver_t pn53x_usb_driver;