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.
This commit is contained in:
Romuald Conty 2013-06-13 15:56:39 +02:00
parent 5757fafe0c
commit af7eef0c54

View file

@ -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;