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.
This commit is contained in:
Christina Quast 2015-01-15 14:53:38 +01:00
parent 99de4e5753
commit 8d0f4a6675
3 changed files with 19 additions and 9 deletions

View File

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

View File

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

View File

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