From fd337dd0ccadd1bed36475409172009c610388d1 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Fri, 20 Aug 2010 10:40:00 +0000 Subject: [PATCH] Also detect error frames in pn532_uart (tested) and arygon drivers (not tested). --- libnfc/drivers/arygon.c | 14 +++++++++----- libnfc/drivers/pn532_uart.c | 20 ++++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 770f049..4d5c8bf 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -237,11 +237,6 @@ bool arygon_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTx PRINT_HEX("RX", abtRxBuf,szRxBufLen); #endif - // When the answer should be ignored, just return a successful result - if(pbtRx == NULL || pszRxLen == NULL) return true; - - // Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable) - if(szRxBufLen < 9) return false; #ifdef DEBUG PRINT_HEX("TX", ack_frame, 6); @@ -251,6 +246,15 @@ bool arygon_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTx return false; } + if (!pn53x_transceive_check_error_frame_callback(pnd, abtRxBuf, szRxBufLen)) + return false; + + // When the answer should be ignored, just return a successful result + if(pbtRx == NULL || pszRxLen == NULL) return true; + + // Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable) + if(szRxBufLen < 9) return false; + // Remove the preceding and appending bytes 00 00 ff 00 ff 00 00 00 FF xx Fx .. .. .. xx 00 (x = variable) *pszRxLen = szRxBufLen - 9; memcpy(pbtRx, abtRxBuf+7, *pszRxLen); diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 88d01f5..982cd82 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -237,14 +237,6 @@ bool pn532_uart_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t #endif } - // When the answer should be ignored, just return a successful result - if(pbtRx == NULL || pszRxLen == NULL) return true; - - // Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable) - if(szRxBufLen < 9) { - pnd->iLastError = DEINVAL; - return false; - } #ifdef DEBUG PRINT_HEX("TX", ack_frame,6); @@ -256,6 +248,18 @@ bool pn532_uart_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t return false; } + if (!pn53x_transceive_check_error_frame_callback (pnd, abtRxBuf, szRxBufLen)) + return false; + + // When the answer should be ignored, just return a successful result + if(pbtRx == NULL || pszRxLen == NULL) return true; + + // Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable) + if(szRxBufLen < 9) { + pnd->iLastError = DEINVAL; + return false; + } + // Remove the preceding and appending bytes 00 00 ff 00 ff 00 00 00 FF xx Fx .. .. .. xx 00 (x = variable) *pszRxLen = szRxBufLen - 9; memcpy(pbtRx, abtRxBuf+7, *pszRxLen);