From ca49343d0dbb1d6e7c48e48ea623754ac426f745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Mon, 12 Mar 2018 17:27:15 +0100 Subject: [PATCH] Fix PIN Pad Add missing braces arround if block Hardcode some length as parameter are wrong in protocol --- .../Class/CCID/src/usbd_ccid_cmd.c | 3 +- .../Class/CCID/src/usbd_ccid_if.c | 58 ++++++++++--------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/lib_stusb/STM32_USB_Device_Library/Class/CCID/src/usbd_ccid_cmd.c b/lib_stusb/STM32_USB_Device_Library/Class/CCID/src/usbd_ccid_cmd.c index e9ec4193..b0478948 100755 --- a/lib_stusb/STM32_USB_Device_Library/Class/CCID/src/usbd_ccid_cmd.c +++ b/lib_stusb/STM32_USB_Device_Library/Class/CCID/src/usbd_ccid_cmd.c @@ -703,9 +703,10 @@ uint8_t PC_TO_RDR_Secure(void) CHK_PARAM_CARD_PRESENT |\ CHK_PARAM_ABORT ); - if (error != 0) + if (error != 0) { G_io_ccid.bulk_header.bulkin.dwLength = 0; return error; + } bBWI = G_io_ccid.bulk_header.bulkout.bSpecific_0; wLevelParameter = (G_io_ccid.bulk_header.bulkout.bSpecific_1 + ((uint16_t)G_io_ccid.bulk_header.bulkout.bSpecific_2<<8)); diff --git a/lib_stusb/STM32_USB_Device_Library/Class/CCID/src/usbd_ccid_if.c b/lib_stusb/STM32_USB_Device_Library/Class/CCID/src/usbd_ccid_if.c index e94fbe66..7e7e3b98 100755 --- a/lib_stusb/STM32_USB_Device_Library/Class/CCID/src/usbd_ccid_if.c +++ b/lib_stusb/STM32_USB_Device_Library/Class/CCID/src/usbd_ccid_if.c @@ -526,36 +526,40 @@ uint8_t SC_Secure(uint32_t dwLength, uint8_t bBWI, uint16_t wLevelParameter, UNUSED(returnLen); // return SLOTERROR_CMD_NOT_SUPPORTED; uint16_t ret_len,off; - switch(pbuf[0]) { - case 0: // verify pin - ret_len = dwLength - 15; - os_memmove(G_io_apdu_buffer, pbuf+15, dwLength-15); + switch(pbuf[0]) + { + case 0: // verify pin + off = 15; + //ret_len = dwLength - 15; + ret_len = 5; + break; + case 1: // modify pin + switch(pbuf[11]) + { + case 3: + off = 20; break; - case 1: // modify pin - switch(pbuf[11]) { - case 3: - off = 20; - break; - case 2: - case 1: - off = 19; - break; - // 0 and 4-0xFF - default: - off = 18; - break; - } - ret_len = dwLength-off; - // provide with the complete apdu - os_memmove(G_io_apdu_buffer, pbuf+off, dwLength-off); + case 2: + case 1: + off = 19; break; - default: // unsupported - G_io_ccid.bulk_header.bulkin.dwLength = 0; - RDR_to_PC_DataBlock(SLOTERROR_CMD_NOT_SUPPORTED); - CCID_Send_Reply(&USBD_Device); - return SLOTERROR_CMD_NOT_SUPPORTED; + // 0 and 4-0xFF + default: + off = 18; + break; + } + //ret_len = dwLength - off; + ret_len = 5; + break; + default: // unsupported + G_io_ccid.bulk_header.bulkin.dwLength = 0; + RDR_to_PC_DataBlock(SLOTERROR_CMD_NOT_SUPPORTED); + CCID_Send_Reply(&USBD_Device); + return SLOTERROR_CMD_NOT_SUPPORTED; } - return SC_XferBlock(G_io_apdu_buffer, ret_len, &ret_len); + pbuf += off; + pbuf[0] = 0xEF; + return SC_XferBlock(pbuf, ret_len, &ret_len); } // prepare the apdu to be processed by the application