From 8d0f4a66753aef8ef8fff1bf3e089faf0049dd01 Mon Sep 17 00:00:00 2001 From: Christina Quast Date: Thu, 15 Jan 2015 14:53:38 +0100 Subject: [PATCH] Pass ISO7816_GetChar return val to higher layers The return value of ISO7816_GetChar is 0 in case of a timeout when trying to retrieve values, and status of US_CSR otherwise. Proper handling of this return value is not yet implemented though. With the naive approach of just not sending the ATR if it could not be read the simtrace firmware did not work together with pcsc_scan AT ALL. --- .../libboard_sam3s-ek/include/iso7816_4.h | 2 +- .../libboard_sam3s-ek/source/iso7816_4.c | 16 ++++++++++------ .../usb/device/ccid/cciddriver.c | 10 ++++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/sam3s_example/atmel_softpack_libraries/libboard_sam3s-ek/include/iso7816_4.h b/sam3s_example/atmel_softpack_libraries/libboard_sam3s-ek/include/iso7816_4.h index 66575fdc..912c9798 100644 --- a/sam3s_example/atmel_softpack_libraries/libboard_sam3s-ek/include/iso7816_4.h +++ b/sam3s_example/atmel_softpack_libraries/libboard_sam3s-ek/include/iso7816_4.h @@ -76,7 +76,7 @@ extern void ISO7816_Escape( void ); extern void ISO7816_RestartClock(void); extern void ISO7816_StopClock( void ); extern void ISO7816_toAPDU( void ); -extern void ISO7816_Datablock_ATR( uint8_t* pAtr, uint8_t* pLength ); +extern uint32_t ISO7816_Datablock_ATR( uint8_t* pAtr, uint8_t* pLength ); extern void ISO7816_SetDataRateandClockFrequency( uint32_t dwClockFrequency, uint32_t dwDataRate ); extern uint8_t ISO7816_StatusReset( void ); extern void ISO7816_cold_reset( void ); diff --git a/sam3s_example/atmel_softpack_libraries/libboard_sam3s-ek/source/iso7816_4.c b/sam3s_example/atmel_softpack_libraries/libboard_sam3s-ek/source/iso7816_4.c index e80ac42d..3d5c4d76 100644 --- a/sam3s_example/atmel_softpack_libraries/libboard_sam3s-ek/source/iso7816_4.c +++ b/sam3s_example/atmel_softpack_libraries/libboard_sam3s-ek/source/iso7816_4.c @@ -93,14 +93,11 @@ static uint32_t ISO7816_GetChar( uint8_t *pCharToReceive ) /* Wait USART ready for reception */ while( ((BOARD_ISO7816_BASE_USART->US_CSR & US_CSR_RXRDY) == 0) ) { if(timeout++ > 12000 * (BOARD_MCK/1000000)) { - TRACE_DEBUG("TimeOut\n\r"); + TRACE_WARN("TimeOut\n\r"); return( 0 ); } } - TRACE_DEBUG("T: %u\n\r", timeout); - - /* At least one complete character has been received and US_RHR has not yet been read. */ /* Get a char */ @@ -359,17 +356,24 @@ void ISO7816_toAPDU( void ) * Answer To Reset (ATR) * \param pAtr ATR buffer * \param pLength Pointer for store the ATR length + * \return 0: if timeout else status of US_CSR */ -void ISO7816_Datablock_ATR( uint8_t* pAtr, uint8_t* pLength ) +uint32_t ISO7816_Datablock_ATR( uint8_t* pAtr, uint8_t* pLength ) { uint32_t i; uint32_t j; uint32_t y; + uint32_t status = 0; *pLength = 0; /* Read ATR TS */ - ISO7816_GetChar(&pAtr[0]); + // FIXME: There should always be a check for the GetChar return value..0 means timeout + status = ISO7816_GetChar(&pAtr[0]); + /* if (status == 0) { + return status; + }*/ + /* Read ATR T0 */ ISO7816_GetChar(&pAtr[1]); y = pAtr[1] & 0xF0; diff --git a/sam3s_example/atmel_softpack_libraries/usb/device/ccid/cciddriver.c b/sam3s_example/atmel_softpack_libraries/usb/device/ccid/cciddriver.c index 8958890e..190227a5 100644 --- a/sam3s_example/atmel_softpack_libraries/usb/device/ccid/cciddriver.c +++ b/sam3s_example/atmel_softpack_libraries/usb/device/ccid/cciddriver.c @@ -665,10 +665,16 @@ static void RDRtoPCDatablock_ATR( void ) unsigned char i; unsigned char Atr[ATR_SIZE_MAX]; unsigned char length; + uint32_t status; - //TRACE_DEBUG("."); + TRACE_DEBUG("."); - ISO7816_Datablock_ATR( Atr, &length ); + status = ISO7816_Datablock_ATR( Atr, &length ); + if (status == 0) { + TRACE_DEBUG("Timeout occured while reading ATR"); +// FIXME: react properly to timeout.. +// return; + } if( length > 5 ) { ccidDriver.ProtocolDataStructure[1] = Atr[5]&0x0F; // TD(1)