Rework and fix error frames detection.
While here, rename the pn53x_transceive_callback() function to pn53x_transceive_check_ack_frame_callback() to make it more obvious what it is supposed to do.
This commit is contained in:
parent
b0737bd1a0
commit
f4aa4edc94
3 changed files with 21 additions and 6 deletions
|
@ -68,9 +68,10 @@ const byte_t pncmd_target_get_status [ 2] = { 0xD4,0x8A };
|
||||||
|
|
||||||
static const byte_t pn53x_ack_frame[] = { 0x00,0x00,0xff,0x00,0xff,0x00 };
|
static const byte_t pn53x_ack_frame[] = { 0x00,0x00,0xff,0x00,0xff,0x00 };
|
||||||
static const byte_t pn53x_nack_frame[] = { 0x00,0x00,0xff,0xff,0x00,0x00 };
|
static const byte_t pn53x_nack_frame[] = { 0x00,0x00,0xff,0xff,0x00,0x00 };
|
||||||
|
static const byte_t pn53x_error_frame[] = { 0x00,0x00,0xff,0x01,0xff,0x7f,0x81,0x00 };
|
||||||
|
|
||||||
// XXX: Is this function correctly named ?
|
// XXX: Is this function correctly named ?
|
||||||
bool pn53x_transceive_callback(nfc_device_t* pnd, const byte_t *pbtRxFrame, const size_t szRxFrameLen)
|
bool pn53x_transceive_check_ack_frame_callback(nfc_device_t* pnd, const byte_t *pbtRxFrame, const size_t szRxFrameLen)
|
||||||
{
|
{
|
||||||
if (szRxFrameLen >= sizeof (pn53x_ack_frame)) {
|
if (szRxFrameLen >= sizeof (pn53x_ack_frame)) {
|
||||||
if (0 == memcmp (pbtRxFrame, pn53x_ack_frame, sizeof (pn53x_ack_frame))) {
|
if (0 == memcmp (pbtRxFrame, pn53x_ack_frame, sizeof (pn53x_ack_frame))) {
|
||||||
|
@ -93,6 +94,19 @@ bool pn53x_transceive_callback(nfc_device_t* pnd, const byte_t *pbtRxFrame, cons
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool pn53x_transceive_check_error_frame_callback(nfc_device_t* pnd, const byte_t *pbtRxFrame, const size_t szRxFrameLen)
|
||||||
|
{
|
||||||
|
if (szRxFrameLen >= sizeof (pn53x_error_frame)) {
|
||||||
|
if (0 == memcmp (pbtRxFrame, pn53x_error_frame, sizeof (pn53x_error_frame))) {
|
||||||
|
DBG("%s", "PN53x sent an error frame");
|
||||||
|
pnd->iLastError = DEISERRFRAME;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool pn53x_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
bool pn53x_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
||||||
{
|
{
|
||||||
byte_t abtRx[MAX_FRAME_LEN];
|
byte_t abtRx[MAX_FRAME_LEN];
|
||||||
|
|
|
@ -74,7 +74,8 @@
|
||||||
#define DEACKMISMATCH 0x0200 /* Unexpected data */
|
#define DEACKMISMATCH 0x0200 /* Unexpected data */
|
||||||
#define DEISERRFRAME 0x0300 /* Error frame */
|
#define DEISERRFRAME 0x0300 /* Error frame */
|
||||||
|
|
||||||
bool pn53x_transceive_callback(nfc_device_t* pnd, const byte_t *pbtRxFrame, const size_t szRxFrameLen);
|
bool pn53x_transceive_check_ack_frame_callback(nfc_device_t* pnd, const byte_t *pbtRxFrame, const size_t szRxFrameLen);
|
||||||
|
bool pn53x_transceive_check_error_frame_callback(nfc_device_t* pnd, const byte_t *pbtRxFrame, const size_t szRxFrameLen);
|
||||||
bool pn53x_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
bool pn53x_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||||
byte_t pn53x_get_reg(nfc_device_t* pnd, uint16_t ui16Reg);
|
byte_t pn53x_get_reg(nfc_device_t* pnd, uint16_t ui16Reg);
|
||||||
bool pn53x_set_reg(nfc_device_t* pnd, uint16_t ui16Reg, uint8_t ui8SybmolMask, uint8_t ui8Value);
|
bool pn53x_set_reg(nfc_device_t* pnd, uint16_t ui16Reg, uint8_t ui8SybmolMask, uint8_t ui8Value);
|
||||||
|
|
|
@ -285,7 +285,7 @@ bool pn53x_usb_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t s
|
||||||
PRINT_HEX("RX", abtRx,ret);
|
PRINT_HEX("RX", abtRx,ret);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!pn53x_transceive_callback (pnd, abtRx, ret))
|
if (!pn53x_transceive_check_ack_frame_callback (pnd, abtRx, ret))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ret = usb_bulk_read(pus->pudh, pus->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT);
|
ret = usb_bulk_read(pus->pudh, pus->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT);
|
||||||
|
@ -305,6 +305,9 @@ bool pn53x_usb_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t s
|
||||||
#endif
|
#endif
|
||||||
usb_bulk_write(pus->pudh, pus->uiEndPointOut, (char *)ack_frame, 6, USB_TIMEOUT);
|
usb_bulk_write(pus->pudh, pus->uiEndPointOut, (char *)ack_frame, 6, USB_TIMEOUT);
|
||||||
|
|
||||||
|
if (!pn53x_transceive_check_error_frame_callback (pnd, abtRx, ret))
|
||||||
|
return false;
|
||||||
|
|
||||||
// When the answer should be ignored, just return a succesful result
|
// When the answer should be ignored, just return a succesful result
|
||||||
if(pbtRx == NULL || pszRxLen == NULL) return true;
|
if(pbtRx == NULL || pszRxLen == NULL) return true;
|
||||||
|
|
||||||
|
@ -329,8 +332,5 @@ bool pn53x_usb_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t s
|
||||||
|
|
||||||
memcpy( pbtRx, abtRx + 7, *pszRxLen);
|
memcpy( pbtRx, abtRx + 7, *pszRxLen);
|
||||||
|
|
||||||
if (abtRx[5] != pbtTx[0] + 1) {
|
|
||||||
pnd->iLastError = DEISERRFRAME;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue