From af7eef0c54b12db2ecce33c238032294d5a52194 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 13 Jun 2013 15:56:39 +0200 Subject: [PATCH] acr122_usb: check received Status Word (Touchatag) Test if SW1 is 0x61 (means more bytes have to be read) before using SW2 as length. Update issue 251 The driver now check that Status Word (SW1) is equals to 0x61 (more data available) before using SW2 as length. If SW is not as expected, it show SW1 and SW2. --- libnfc/drivers/acr122_usb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libnfc/drivers/acr122_usb.c b/libnfc/drivers/acr122_usb.c index 55d735b..de5f7fa 100644 --- a/libnfc/drivers/acr122_usb.c +++ b/libnfc/drivers/acr122_usb.c @@ -185,6 +185,9 @@ struct acr122_usb_data { #define RDR_to_PC_DataBlock 0x80 #define RDR_to_PC_Escape 0x83 +// ISO 7816-4 +#define SW1_More_Data_Available 0x61 + // This frame template is copied at init time // Its designed for TAMA sending but is also used for simple ADPU frame: acr122_build_frame_from_apdu() will overwrite needed bytes const uint8_t acr122_usb_frame_template[] = { @@ -649,6 +652,11 @@ read: pnd->last_error = NFC_EIO; return pnd->last_error; } + if (abtRxBuf[10] != SW1_More_Data_Available) { + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unexpected Status Word (SW1: %02x SW2: %02x)", abtRxBuf[10], abtRxBuf[11]); + pnd->last_error = NFC_EIO; + return pnd->last_error; + } acr122_usb_send_apdu(pnd, APDU_GetAdditionnalData, 0x00, 0x00, NULL, 0, abtRxBuf[11], abtRxBuf, sizeof(abtRxBuf)); offset = 0; break;