Merge branch 'new_iso_init' (sniffer not working)

Conflicts:
	firmware/src_simtrace/phone.c
	firmware/src_simtrace/simtrace.h
This commit is contained in:
Christina Quast
2015-04-12 13:31:01 +02:00
10 changed files with 123 additions and 174 deletions

View File

@@ -59,6 +59,8 @@ static const Pin pinsPower[] = {PWR_PINS};
static const Pin pinIso7816RstMC = PIN_ISO7816_RSTMC;
static uint8_t sim_inserted = 0;
static struct Usart_info usart_info = {.base = USART_SIM, .id = ID_USART_SIM};
/*------------------------------------------------------------------------------
* Optional smartcard detection
*------------------------------------------------------------------------------*/
@@ -162,8 +164,8 @@ void CCID_init( void )
/* power up the card */
// PIO_Set(&pinsPower[0]);
ISO7816_Init( &pinIso7816RstMC ) ;
ISO7816_Init(&usart_info, CLK_MASTER);
ISO7816_Set_Reset_Pin(&pinIso7816RstMC);
/* Read ATR */
ISO7816_warm_reset() ;

View File

@@ -15,7 +15,7 @@ int send_to_host()
{
static uint8_t msg[RING_BUFLEN];
int ret = 0;
int i;
unsigned int i;
for(i = 0; !rbuf_is_empty(&sim_rcv_buf) && i < sizeof(msg); i++) {
msg[i] = rbuf_read(&sim_rcv_buf);

View File

@@ -71,7 +71,7 @@ it to the driver using the RDR_to_PC_DataBlock response. During this period, the
from the smart card is still in progress and hence the device cannot indefinitely wait for IN tokens on
the USB bulk-in endpoint. Hence, it is required of the driver to readily supply IN tokens on the USB
bulk-in endpoint. On failure to do so, some of the wait time extension responses, will not be queued to
the driver.
the driver.
*/
extern volatile uint8_t timeout_occured;
@@ -108,6 +108,8 @@ static const Pin pPwr[] = {
static const Pin pinPhoneRST = PIN_ISO7816_RST_PHONE;
static struct Usart_info usart_info = {.base = USART_PHONE, .id = ID_USART_PHONE};
#define PR TRACE_INFO
/* ===================================================*/
@@ -152,95 +154,6 @@ static void ISR_PhoneRST( const Pin *pPin)
// PIO_DisableIt( &pinPhoneRST ) ;
}
/**
* Get a character from ISO7816
* \param pCharToReceive Pointer for store the received char
* \return 0: if timeout else status of US_CSR
*/
/* FIXME: This code is taken from cciddriver.c
--> Reuse the code!!! */
uint32_t _ISO7816_GetChar( uint8_t *pCharToReceive )
{
uint32_t status;
uint32_t timeout=0;
TRACE_DEBUG("--");
if( StateUsartGlobal == USART_SEND ) {
while((USART_PHONE->US_CSR & US_CSR_TXEMPTY) == 0) {}
USART_PHONE->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
StateUsartGlobal = USART_RCV;
}
/* Wait USART ready for reception */
while( ((USART_PHONE->US_CSR & US_CSR_RXRDY) == 0) ) {
if(timeout++ > 12000 * (BOARD_MCK/1000000)) {
TRACE_DEBUG("TimeOut\n\r");
return( 0 );
}
}
/* At least one complete character has been received and US_RHR has not yet been read. */
/* Get a char */
*pCharToReceive = ((USART_PHONE->US_RHR) & 0xFF);
status = (USART_PHONE->US_CSR&(US_CSR_OVRE|US_CSR_FRAME|
US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
(1<<10)));
if (status != 0 ) {
TRACE_DEBUG("R:0x%X\n\r", status);
TRACE_DEBUG("R:0x%X\n\r", USART_PHONE->US_CSR);
TRACE_DEBUG("Nb:0x%X\n\r", USART_PHONE->US_NER );
USART_PHONE->US_CR = US_CR_RSTSTA;
}
/* Return status */
return( status );
}
/**
* Send a char to ISO7816
* \param CharToSend char to be send
* \return status of US_CSR
*/
uint32_t _ISO7816_SendChar( uint8_t CharToSend )
{
uint32_t status;
TRACE_DEBUG("********** Send char: %c (0x%X)\n\r", CharToSend, CharToSend);
if( StateUsartGlobal == USART_RCV ) {
USART_PHONE->US_CR = US_CR_RSTSTA | US_CR_RSTIT | US_CR_RSTNACK;
StateUsartGlobal = USART_SEND;
}
/* Wait USART ready for transmit */
while((USART_PHONE->US_CSR & US_CSR_TXRDY) == 0) {}
/* There is no character in the US_THR */
/* Transmit a char */
USART_PHONE->US_THR = CharToSend;
status = (USART_PHONE->US_CSR&(US_CSR_OVRE|US_CSR_FRAME|
US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
(1<<10)));
if (status != 0 ) {
TRACE_DEBUG("******* status: 0x%X (Overrun: %lu, NACK: %lu, Timeout: %lu, underrun: %lu)\n\r",
status, ((status & US_CSR_OVRE)>> 5), ((status & US_CSR_NACK) >> 13),
((status & US_CSR_TIMEOUT) >> 8), ((status & (1 << 10)) >> 10));
TRACE_DEBUG("E (USART CSR reg):0x%X\n\r", USART_PHONE->US_CSR);
TRACE_DEBUG("Nb (Number of errors):0x%X\n\r", USART_PHONE->US_NER );
USART_PHONE->US_CR = US_CR_RSTSTA;
}
/* Return status */
return( status );
}
void receive_from_host( void );
void sendResponse_to_phone( uint8_t *pArg, uint8_t status, uint32_t transferred, uint32_t remaining)
{
@@ -252,7 +165,7 @@ void sendResponse_to_phone( uint8_t *pArg, uint8_t status, uint32_t transferred,
PR("Resp: %x %x %x .. %x\n", host_to_sim_buf[0], host_to_sim_buf[1], host_to_sim_buf[2], host_to_sim_buf[transferred-1]);
for (uint32_t i = 0; i < transferred; i++ ) {
_ISO7816_SendChar(host_to_sim_buf[i]);
ISO7816_SendChar(host_to_sim_buf[i], &usart_info);
}
receive_from_host();
@@ -267,6 +180,7 @@ void receive_from_host()
TRACE_ERROR("USB Err: %X\n", ret);
}
}
void Phone_configure( void ) {
PIO_ConfigureIt( &pinPhoneRST, ISR_PhoneRST ) ;
NVIC_EnableIRQ( PIOA_IRQn );
@@ -286,7 +200,7 @@ void Phone_init( void ) {
PIO_Configure( &pinPhoneRST, 1);
PIO_EnableIt( &pinPhoneRST ) ;
_ISO7816_Init();
ISO7816_Init(&usart_info, CLK_SLAVE);
USART_SetTransmitterEnabled(USART_PHONE, 1);
USART_SetReceiverEnabled(USART_PHONE, 1);

View File

@@ -14,6 +14,9 @@
#define PHONE_DATAIN 5
#define PHONE_INT 6
#define CLK_MASTER 1
#define CLK_SLAVE 0
extern volatile ringbuf sim_rcv_buf;
extern volatile bool rcvdChar;
@@ -45,13 +48,8 @@ typedef struct {
extern const USBConfigurationDescriptor *configurationDescriptorsArr[];
/* Helper functions */
int check_data_from_phone();
// FIXME: static function definitions
extern uint32_t _ISO7816_GetChar( uint8_t *pCharToReceive );
extern uint32_t _ISO7816_SendChar( uint8_t CharToSend );
/* Configure functions */
extern void Sniffer_configure( void );
extern void CCID_configure( void );
@@ -65,7 +63,6 @@ extern void Phone_init( void );
extern void MITM_init( void );
extern void SIMtrace_USB_Initialize( void );
extern void _ISO7816_Init( void );
/* Exit functions */
extern void Sniffer_exit( void );

View File

@@ -79,8 +79,8 @@ void _ISO7816_Init( void )
/* Configure USART */
PMC_EnablePeripheral(ID_USART_PHONE);
USART1->US_IDR = 0xffffffff;
USART_EnableIt( USART1, US_IER_RXRDY) ;
USART_PHONE->US_IDR = 0xffffffff;
USART_EnableIt( USART_PHONE, US_IER_RXRDY) ;
/* enable USART1 interrupt */
NVIC_EnableIRQ( USART1_IRQn ) ;

View File

@@ -60,6 +60,8 @@ static const Pin pPwr[] = {
{VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
};
static struct Usart_info usart_info = {.base = USART_PHONE, .id = ID_USART_PHONE};
/*-----------------------------------------------------------------------------
* Initialization routine
*-----------------------------------------------------------------------------*/
@@ -82,7 +84,7 @@ void Sniffer_init( void )
PIO_Configure(pPwr, PIO_LISTSIZE( pPwr ));
_ISO7816_Init();
ISO7816_Init(&usart_info, CLK_SLAVE);
USART_SetReceiverEnabled(USART_PHONE, 1);
}