diff --git a/firmware/src_simtrace/ccid.c b/firmware/src_simtrace/ccid.c index 7ff99da6..770e296c 100644 --- a/firmware/src_simtrace/ccid.c +++ b/firmware/src_simtrace/ccid.c @@ -46,22 +46,28 @@ /** Maximum ATR ucSize in bytes.*/ #define MAX_ATR_SIZE 55 - /*------------------------------------------------------------------------------ * Internal variables *------------------------------------------------------------------------------*/ /** ISO7816 pins */ -static const Pin pinsISO7816[] = {PINS_ISO7816}; +static const Pin pinsISO7816[] = { PINS_ISO7816 }; + /** Bus switch pins */ -static const Pin pinsBus[] = {PINS_BUS_DEFAULT}; +static const Pin pinsBus[] = { PINS_BUS_DEFAULT }; + /* SIMcard power pin */ -static const Pin pinsPower[] = {PWR_PINS}; +static const Pin pinsPower[] = { PWR_PINS }; + /** ISO7816 RST pin */ -static const Pin pinIso7816RstMC = PIN_ISO7816_RSTMC; +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, .state = USART_RCV}; +static struct Usart_info usart_info = { + .base = USART_SIM, + .id = ID_USART_SIM, + .state = USART_RCV +}; /*------------------------------------------------------------------------------ * Optional smartcard detection @@ -74,7 +80,7 @@ static const Pin pinSmartCard = SMARTCARD_CONNECT_PIN; * PIO interrupt service routine. Checks if the smartcard has been connected * or disconnected. */ -static void ISR_PioSmartCard( const Pin *pPin ) +static void ISR_PioSmartCard(const Pin * pPin) { /* FIXME: why is pinSmartCard.pio->PIO_ISR the wrong number? printf("+++++ Trying to check for pending interrupts (PIO ISR: 0x%X)\n\r", pinSmartCard.pio->PIO_ISR); @@ -83,38 +89,35 @@ Output: +++++ Trying to check for pending interrupts (PIO ISR: 0x400)) = 1<<10 +++++ Mask: 0x100 = 1<<8 */ - // PA10 is DTXD, which is the debug uart transmit pin + // PA10 is DTXD, which is the debug uart transmit pin - printf("Interrupt!!\n\r"); - /* Check all pending interrupts */ - // FIXME: this if condition is not always true... + printf("Interrupt!!\n\r"); + /* Check all pending interrupts */ + // FIXME: this if condition is not always true... // if ( (pinSmartCard.pio->PIO_ISR & pinSmartCard.mask) != 0 ) - { - /* Check current level on pin */ - if ( PIO_Get( &pinSmartCard ) == 0 ) - { - sim_inserted = 1; - printf( "-I- Smartcard inserted\n\r" ) ; - CCID_Insertion(); - } - else - { - sim_inserted = 0; - printf( "-I- Smartcard removed\n\r" ) ; - CCID_Removal(); - } - } + { + /* Check current level on pin */ + if (PIO_Get(&pinSmartCard) == 0) { + sim_inserted = 1; + printf("-I- Smartcard inserted\n\r"); + CCID_Insertion(); + } else { + sim_inserted = 0; + printf("-I- Smartcard removed\n\r"); + CCID_Removal(); + } + } } /** * Configures the smartcard detection pin to trigger an interrupt. */ -static void ConfigureCardDetection( void ) +static void ConfigureCardDetection(void) { - printf("+++++ Configure PIOs\n\r"); - PIO_Configure( &pinSmartCard, 1 ) ; - NVIC_EnableIRQ( PIOA_IRQn ); - PIO_EnableIt( &pinSmartCard ) ; + printf("+++++ Configure PIOs\n\r"); + PIO_Configure(&pinSmartCard, 1); + NVIC_EnableIRQ(PIOA_IRQn); + PIO_EnableIt(&pinSmartCard); } /*----------------------------------------------------------------------------- @@ -122,62 +125,64 @@ static void ConfigureCardDetection( void ) *-----------------------------------------------------------------------------*/ extern CCIDDriverConfigurationDescriptors configurationDescriptorCCID; -void CCID_configure ( void ) { - CCIDDriver_Initialize(); +void CCID_configure(void) +{ + CCIDDriver_Initialize(); // FIXME: Do we need to set priority?: NVIC_SetPriority( PIOA_IRQn, 10); - PIO_ConfigureIt( &pinSmartCard, ISR_PioSmartCard ) ; + PIO_ConfigureIt(&pinSmartCard, ISR_PioSmartCard); } -void CCID_exit ( void ) { - PIO_DisableIt( &pinSmartCard ) ; - USART_SetTransmitterEnabled(usart_info.base, 0); - USART_SetReceiverEnabled(usart_info.base, 0); -} - -void CCID_init( void ) +void CCID_exit(void) { - uint8_t pAtr[MAX_ATR_SIZE]; - uint8_t ucSize ; - - // FIXME: do we want to print ATR? - /* Initialize Atr buffer */ - memset( pAtr, 0, sizeof( pAtr ) ) ; - - ConfigureCardDetection() ; - - // Configure ISO7816 driver - PIO_Configure(pinsISO7816, PIO_LISTSIZE(pinsISO7816)); - PIO_Configure(pinsBus, PIO_LISTSIZE(pinsBus)); - PIO_Configure(pinsPower, PIO_LISTSIZE(pinsPower)); - - /* power up the card */ -// PIO_Set(&pinsPower[0]); - - ISO7816_Init(&usart_info, CLK_MASTER); - USART_SetTransmitterEnabled(usart_info.base, 1); - USART_SetReceiverEnabled(usart_info.base, 1); - - ISO7816_Set_Reset_Pin(&pinIso7816RstMC); - /* Read ATR */ - ISO7816_warm_reset() ; - - ISO7816_Datablock_ATR( pAtr, &ucSize ) ; - - /* Decode ATR and print it */ - ISO7816_Decode_ATR( pAtr ) ; - - // FIXME. what if smcard is not inserted? - if(PIO_Get(&pinSmartCard) == 0) { - printf("SIM card inserted\n\r"); - CCID_Insertion(); - } + PIO_DisableIt(&pinSmartCard); + USART_SetTransmitterEnabled(usart_info.base, 0); + USART_SetReceiverEnabled(usart_info.base, 0); } -void CCID_run( void ) +void CCID_init(void) +{ + uint8_t pAtr[MAX_ATR_SIZE]; + uint8_t ucSize; + + // FIXME: do we want to print ATR? + /* Initialize Atr buffer */ + memset(pAtr, 0, sizeof(pAtr)); + + ConfigureCardDetection(); + + // Configure ISO7816 driver + PIO_Configure(pinsISO7816, PIO_LISTSIZE(pinsISO7816)); + PIO_Configure(pinsBus, PIO_LISTSIZE(pinsBus)); + PIO_Configure(pinsPower, PIO_LISTSIZE(pinsPower)); + + /* power up the card */ +// PIO_Set(&pinsPower[0]); + + ISO7816_Init(&usart_info, CLK_MASTER); + USART_SetTransmitterEnabled(usart_info.base, 1); + USART_SetReceiverEnabled(usart_info.base, 1); + + ISO7816_Set_Reset_Pin(&pinIso7816RstMC); + /* Read ATR */ + ISO7816_warm_reset(); + + ISO7816_Datablock_ATR(pAtr, &ucSize); + + /* Decode ATR and print it */ + ISO7816_Decode_ATR(pAtr); + + // FIXME. what if smcard is not inserted? + if (PIO_Get(&pinSmartCard) == 0) { + printf("SIM card inserted\n\r"); + CCID_Insertion(); + } +} + +void CCID_run(void) { - //if (USBD_Read(INT, pBuffer, dLength, fCallback, pArgument); + //if (USBD_Read(INT, pBuffer, dLength, fCallback, pArgument); - CCID_SmartCardRequest(); + CCID_SmartCardRequest(); } #endif diff --git a/firmware/src_simtrace/main.c b/firmware/src_simtrace/main.c index 852b2f46..f5543b18 100644 --- a/firmware/src_simtrace/main.c +++ b/firmware/src_simtrace/main.c @@ -14,14 +14,14 @@ * Internal variables *------------------------------------------------------------------------------*/ typedef struct { - /* static initialization, called whether or not the usb config is active */ - void (* configure) ( void ); - /* initialization function after the config was selected */ - void (* init) ( void ); - /* de-initialization before selecting new config */ - void (* exit) ( void ); - /* main loop content for given configuration */ - void (* run) ( void ); + /* static initialization, called whether or not the usb config is active */ + void (*configure) (void); + /* initialization function after the config was selected */ + void (*init) (void); + /* de-initialization before selecting new config */ + void (*exit) (void); + /* main loop content for given configuration */ + void (*run) (void); } conf_func; static const conf_func config_func_ptrs[] = { @@ -55,12 +55,11 @@ static const conf_func config_func_ptrs[] = { .configure = MITM_configure, .init = MITM_init, .exit = MITM_exit, - .run = MITM_run + .run = MITM_run, }, #endif }; - /*------------------------------------------------------------------------------ * Internal variables *------------------------------------------------------------------------------*/ @@ -72,86 +71,86 @@ static volatile enum confNum simtrace_config = CFG_NUM_PHONE; static volatile enum confNum simtrace_config = CFG_NUM_CCID; #endif - /*---------------------------------------------------------------------------- * Callbacks *----------------------------------------------------------------------------*/ void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum) { - TRACE_INFO_WP("cfgChanged%d ", cfgnum); - simtrace_config = cfgnum; + TRACE_INFO_WP("cfgChanged%d ", cfgnum); + simtrace_config = cfgnum; } /*------------------------------------------------------------------------------ * Main *------------------------------------------------------------------------------*/ -#define MAX_USB_ITER BOARD_MCK/72 // This should be around a second -extern int main( void ) +#define MAX_USB_ITER BOARD_MCK/72 // This should be around a second +extern int main(void) { - uint8_t isUsbConnected = 0; - enum confNum last_simtrace_config = simtrace_config; - unsigned int i = 0; + uint8_t isUsbConnected = 0; + enum confNum last_simtrace_config = simtrace_config; + unsigned int i = 0; - LED_Configure(LED_NUM_RED); - LED_Configure(LED_NUM_GREEN); - LED_Set(LED_NUM_RED); + LED_Configure(LED_NUM_RED); + LED_Configure(LED_NUM_GREEN); + LED_Set(LED_NUM_RED); - /* Disable watchdog*/ - WDT_Disable( WDT ) ; + /* Disable watchdog */ + WDT_Disable(WDT); - req_ctx_init(); + req_ctx_init(); - PIO_InitializeInterrupts(0); + PIO_InitializeInterrupts(0); - SIMtrace_USB_Initialize(); + SIMtrace_USB_Initialize(); - TRACE_INFO("USB init...\n\r"); - while(USBD_GetState() < USBD_STATE_CONFIGURED){ - if(i >= MAX_USB_ITER*3) { - TRACE_ERROR("Resetting board (USB could not be configured)\n"); - NVIC_SystemReset(); - } - i++; - } + TRACE_INFO("USB init...\n\r"); + while (USBD_GetState() < USBD_STATE_CONFIGURED) { + if (i >= MAX_USB_ITER * 3) { + TRACE_ERROR("Resetting board (USB could " + "not be configured)\n"); + NVIC_SystemReset(); + } + i++; + } - TRACE_DEBUG("calling configure of all configurations...\n\r"); - for (i = 1; i < sizeof(config_func_ptrs)/sizeof(config_func_ptrs[0]); ++i) - { - if (config_func_ptrs[i].configure) - config_func_ptrs[i].configure(); - } + TRACE_DEBUG("calling configure of all configurations...\n\r"); + for (i = 1; i < sizeof(config_func_ptrs) / sizeof(config_func_ptrs[0]); + ++i) { + if (config_func_ptrs[i].configure) + config_func_ptrs[i].configure(); + } - TRACE_DEBUG("calling init of config %u...\n\r", simtrace_config); - config_func_ptrs[simtrace_config].init(); - last_simtrace_config = simtrace_config; + TRACE_DEBUG("calling init of config %u...\n\r", simtrace_config); + config_func_ptrs[simtrace_config].init(); + last_simtrace_config = simtrace_config; - TRACE_DEBUG("entering main loop...\n\r"); - while(1) { - const char rotor[] = { '-', '\\', '|', '/' }; - putchar('\b'); - putchar(rotor[i++ % ARRAY_SIZE(rotor)]); + TRACE_DEBUG("entering main loop...\n\r"); + while (1) { + const char rotor[] = { '-', '\\', '|', '/' }; + putchar('\b'); + putchar(rotor[i++ % ARRAY_SIZE(rotor)]); - if (USBD_GetState() < USBD_STATE_CONFIGURED) { + if (USBD_GetState() < USBD_STATE_CONFIGURED) { - if (isUsbConnected) { - isUsbConnected = 0; - } - } - else if (isUsbConnected == 0) { - TRACE_INFO("USB is now configured\n\r"); - LED_Set(LED_NUM_GREEN); - LED_Clear(LED_NUM_RED); + if (isUsbConnected) { + isUsbConnected = 0; + } + } else if (isUsbConnected == 0) { + TRACE_INFO("USB is now configured\n\r"); + LED_Set(LED_NUM_GREEN); + LED_Clear(LED_NUM_RED); - isUsbConnected = 1; - } - if (last_simtrace_config != simtrace_config) { - TRACE_INFO("USB config chg %u -> %u\r\n", last_simtrace_config, simtrace_config); - config_func_ptrs[last_simtrace_config].exit(); - config_func_ptrs[simtrace_config].init(); - last_simtrace_config = simtrace_config; - } else { - config_func_ptrs[simtrace_config].run(); - } - } + isUsbConnected = 1; + } + if (last_simtrace_config != simtrace_config) { + TRACE_INFO("USB config chg %u -> %u\r\n", + last_simtrace_config, simtrace_config); + config_func_ptrs[last_simtrace_config].exit(); + config_func_ptrs[simtrace_config].init(); + last_simtrace_config = simtrace_config; + } else { + config_func_ptrs[simtrace_config].run(); + } + } } diff --git a/firmware/src_simtrace/mitm.c b/firmware/src_simtrace/mitm.c index 90c85026..9c112d1a 100644 --- a/firmware/src_simtrace/mitm.c +++ b/firmware/src_simtrace/mitm.c @@ -37,32 +37,31 @@ #include +static const Pin pins_bus[] = { PINS_BUS_DEFAULT }; -static const Pin pins_bus[] = {PINS_BUS_DEFAULT}; - -void MITM_configure( void ) +void MITM_configure(void) { - Phone_configure(); - CCID_configure(); + Phone_configure(); + CCID_configure(); } -void MITM_init( void ) +void MITM_init(void) { - CCID_init(); - Phone_init(); + CCID_init(); + Phone_init(); - return; + return; } -void MITM_exit( void ) +void MITM_exit(void) { - Phone_exit(); - CCID_exit(); + Phone_exit(); + CCID_exit(); } -void MITM_run( void ) +void MITM_run(void) { - Phone_run(); - CCID_run(); + Phone_run(); + CCID_run(); } #endif /* HAVE_MITM */ diff --git a/firmware/src_simtrace/phone.c b/firmware/src_simtrace/phone.c index ca1dfec1..ac0edb79 100644 --- a/firmware/src_simtrace/phone.c +++ b/firmware/src_simtrace/phone.c @@ -62,31 +62,36 @@ extern volatile uint8_t timeout_occured; unsigned char USBState = STATE_IDLE; /** ISO7816 pins */ -static const Pin pinsISO7816_PHONE[] = {PINS_ISO7816_PHONE}; +static const Pin pinsISO7816_PHONE[] = { PINS_ISO7816_PHONE }; + /** Bus switch pins */ #if DEBUG_PHONE_SNIFF -# warning "Debug phone sniff via logic analyzer is enabled" +#warning "Debug phone sniff via logic analyzer is enabled" // Logic analyzer probes are easier to attach to the SIM card slot -static const Pin pins_bus[] = {PINS_BUS_SNIFF}; +static const Pin pins_bus[] = { PINS_BUS_SNIFF }; #else -static const Pin pins_bus[] = {PINS_BUS_DEFAULT}; +static const Pin pins_bus[] = { PINS_BUS_DEFAULT }; #endif /** ISO7816 RST pin */ static uint8_t sim_inserted = 0; static const Pin pPwr[] = { - /* Enable power converter 4.5-6V to 3.3V; low: off */ - {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}, - - /* Enable second power converter: VCC_PHONE to VCC_SIM; high: off */ - {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} + /* Enable power converter 4.5-6V to 3.3V; low: off */ + {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}, + + /* Enable second power converter: VCC_PHONE to VCC_SIM; high: off */ + {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} }; const Pin pinPhoneRST = PIN_ISO7816_RST_PHONE; -static struct Usart_info usart_info = {.base = USART_PHONE, .id = ID_USART_PHONE, .state = USART_RCV}; +static struct Usart_info usart_info = { + .base = USART_PHONE, + .id = ID_USART_PHONE, + .state = USART_RCV, +}; /* ===================================================*/ /* Taken from iso7816_4.c */ @@ -101,82 +106,91 @@ static struct Usart_info usart_info = {.base = USART_PHONE, .id = ID_USART_PHONE static uint8_t host_to_sim_buf[BUFLEN]; static bool change_fidi = false; -static void receive_from_host( void ); -static void sendResponse_to_phone( uint8_t *pArg, uint8_t status, uint32_t transferred, uint32_t remaining) +static void receive_from_host(void); +static void sendResponse_to_phone(uint8_t * pArg, uint8_t status, + uint32_t transferred, uint32_t remaining) { - if (status != USBD_STATUS_SUCCESS) { - TRACE_ERROR("USB err status: %d (%s)\n", __FUNCTION__, status); - return; - } - TRACE_DEBUG("sendResp, stat: %X, trnsf: %x, rem: %x\n\r", status, transferred, remaining); - TRACE_DEBUG("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]); + if (status != USBD_STATUS_SUCCESS) { + TRACE_ERROR("USB err status: %d (%s)\n", __FUNCTION__, status); + return; + } + TRACE_DEBUG("sendResp, stat: %X, trnsf: %x, rem: %x\n\r", status, + transferred, remaining); + TRACE_DEBUG("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]); - USART_SetReceiverEnabled(USART_PHONE, 0); - USART_SetTransmitterEnabled(USART_PHONE, 1); - uint32_t i = 0; - if (host_to_sim_buf[0] == 0xff) { - printf("Change FIDI detected\n"); - // PTS command, change FIDI after command - i = 2; - change_fidi = true; - } - for (; i < transferred; i++ ) { - ISO7816_SendChar(host_to_sim_buf[i], &usart_info); - } - USART_SetTransmitterEnabled(USART_PHONE, 0); - USART_SetReceiverEnabled(USART_PHONE, 1); + USART_SetReceiverEnabled(USART_PHONE, 0); + USART_SetTransmitterEnabled(USART_PHONE, 1); + uint32_t i = 0; + if (host_to_sim_buf[0] == 0xff) { + printf("Change FIDI detected\n"); + // PTS command, change FIDI after command + i = 2; + change_fidi = true; + } + for (; i < transferred; i++) { + ISO7816_SendChar(host_to_sim_buf[i], &usart_info); + } + USART_SetTransmitterEnabled(USART_PHONE, 0); + USART_SetReceiverEnabled(USART_PHONE, 1); - if (change_fidi == true) { - printf("Change FIDI: %x\n", host_to_sim_buf[2]); - update_fidi(host_to_sim_buf[2]); - change_fidi = false; - } + if (change_fidi == true) { + printf("Change FIDI: %x\n", host_to_sim_buf[2]); + update_fidi(host_to_sim_buf[2]); + change_fidi = false; + } - receive_from_host(); + receive_from_host(); } static void receive_from_host() { - int ret; - if ((ret = USBD_Read(PHONE_DATAOUT, &host_to_sim_buf, sizeof(host_to_sim_buf), - (TransferCallback)&sendResponse_to_phone, 0)) == USBD_STATUS_SUCCESS) { - } else { - TRACE_ERROR("USB Err: %X\n", ret); - } + int ret; + if ((ret = USBD_Read(PHONE_DATAOUT, &host_to_sim_buf, + sizeof(host_to_sim_buf), + (TransferCallback) &sendResponse_to_phone, + 0)) == USBD_STATUS_SUCCESS) { + } else { + TRACE_ERROR("USB Err: %X\n", ret); + } } -void Phone_configure( void ) { - PIO_ConfigureIt( &pinPhoneRST, ISR_PhoneRST ) ; - NVIC_EnableIRQ( PIOA_IRQn ); -} - -void Phone_exit( void ) { - PIO_DisableIt( &pinPhoneRST ) ; - NVIC_DisableIRQ(USART1_IRQn); - USART_DisableIt( USART_PHONE, US_IER_RXRDY) ; - USART_SetTransmitterEnabled(USART_PHONE, 0); - USART_SetReceiverEnabled(USART_PHONE, 0); -} - -void Phone_init( void ) { - PIO_Configure( pinsISO7816_PHONE, PIO_LISTSIZE( pinsISO7816_PHONE ) ) ; - PIO_Configure( pins_bus, PIO_LISTSIZE( pins_bus) ) ; - - PIO_Configure( &pinPhoneRST, 1); - - PIO_EnableIt( &pinPhoneRST ) ; - ISO7816_Init(&usart_info, CLK_SLAVE); - - USART_SetTransmitterEnabled(USART_PHONE, 0); - USART_SetReceiverEnabled(USART_PHONE, 1); - - USART_EnableIt(USART_PHONE, US_IER_RXRDY); - NVIC_EnableIRQ(USART1_IRQn); - - receive_from_host(); -} - -void Phone_run( void ) +void Phone_configure(void) { - check_data_from_phone(); + PIO_ConfigureIt(&pinPhoneRST, ISR_PhoneRST); + NVIC_EnableIRQ(PIOA_IRQn); +} + +void Phone_exit(void) +{ + PIO_DisableIt(&pinPhoneRST); + NVIC_DisableIRQ(USART1_IRQn); + USART_DisableIt(USART_PHONE, US_IER_RXRDY); + USART_SetTransmitterEnabled(USART_PHONE, 0); + USART_SetReceiverEnabled(USART_PHONE, 0); +} + +void Phone_init(void) +{ + PIO_Configure(pinsISO7816_PHONE, PIO_LISTSIZE(pinsISO7816_PHONE)); + PIO_Configure(pins_bus, PIO_LISTSIZE(pins_bus)); + + PIO_Configure(&pinPhoneRST, 1); + + PIO_EnableIt(&pinPhoneRST); + ISO7816_Init(&usart_info, CLK_SLAVE); + + USART_SetTransmitterEnabled(USART_PHONE, 0); + USART_SetReceiverEnabled(USART_PHONE, 1); + + USART_EnableIt(USART_PHONE, US_IER_RXRDY); + NVIC_EnableIRQ(USART1_IRQn); + + receive_from_host(); +} + +void Phone_run(void) +{ + check_data_from_phone(); } diff --git a/firmware/src_simtrace/ringbuffer.c b/firmware/src_simtrace/ringbuffer.c index ae3ba715..1669fdc7 100644 --- a/firmware/src_simtrace/ringbuffer.c +++ b/firmware/src_simtrace/ringbuffer.c @@ -1,40 +1,40 @@ #include "ringbuffer.h" #include "trace.h" -void rbuf_reset(volatile ringbuf *rb) +void rbuf_reset(volatile ringbuf * rb) { - rb->ird = 0; - rb->iwr = 0; + rb->ird = 0; + rb->iwr = 0; } -uint8_t rbuf_read(volatile ringbuf *rb) +uint8_t rbuf_read(volatile ringbuf * rb) { - uint8_t val = rb->buf[rb->ird]; - rb->ird = (rb->ird + 1)%RING_BUFLEN; - return val; + uint8_t val = rb->buf[rb->ird]; + rb->ird = (rb->ird + 1) % RING_BUFLEN; + return val; } -uint8_t rbuf_peek(volatile ringbuf *rb) +uint8_t rbuf_peek(volatile ringbuf * rb) { - return rb->buf[rb->ird]; + return rb->buf[rb->ird]; } -void rbuf_write(volatile volatile ringbuf *rb, uint8_t item) +void rbuf_write(volatile volatile ringbuf * rb, uint8_t item) { - if(!rbuf_is_full(rb)) { - rb->buf[rb->iwr] = item; - rb->iwr = (rb->iwr + 1)%RING_BUFLEN; - } else { - TRACE_ERROR("Ringbuffer full, losing bytes!"); - } + if (!rbuf_is_full(rb)) { + rb->buf[rb->iwr] = item; + rb->iwr = (rb->iwr + 1) % RING_BUFLEN; + } else { + TRACE_ERROR("Ringbuffer full, losing bytes!"); + } } -bool rbuf_is_empty(volatile ringbuf *rb) +bool rbuf_is_empty(volatile ringbuf * rb) { - return rb->ird == rb->iwr; + return rb->ird == rb->iwr; } -bool rbuf_is_full(volatile ringbuf *rb) +bool rbuf_is_full(volatile ringbuf * rb) { - return rb->ird == (rb->iwr+1)%RING_BUFLEN; + return rb->ird == (rb->iwr + 1) % RING_BUFLEN; } diff --git a/firmware/src_simtrace/ringbuffer.h b/firmware/src_simtrace/ringbuffer.h index 0cd82646..662ae095 100644 --- a/firmware/src_simtrace/ringbuffer.h +++ b/firmware/src_simtrace/ringbuffer.h @@ -8,16 +8,16 @@ #define RING_BUFLEN 1024 typedef struct ringbuf { - uint8_t buf[RING_BUFLEN]; - size_t ird; - size_t iwr; + uint8_t buf[RING_BUFLEN]; + size_t ird; + size_t iwr; } ringbuf; -void rbuf_reset(volatile ringbuf *rb); -uint8_t rbuf_read(volatile ringbuf *rb); -uint8_t rbuf_peek(volatile ringbuf *rb); -void rbuf_write(volatile ringbuf *rb, uint8_t item); -bool rbuf_is_empty(volatile ringbuf *rb); -bool rbuf_is_full(volatile ringbuf *rb); +void rbuf_reset(volatile ringbuf * rb); +uint8_t rbuf_read(volatile ringbuf * rb); +uint8_t rbuf_peek(volatile ringbuf * rb); +void rbuf_write(volatile ringbuf * rb, uint8_t item); +bool rbuf_is_empty(volatile ringbuf * rb); +bool rbuf_is_full(volatile ringbuf * rb); #endif /* end of include guard: SIMTRACE_RINGBUF_H */ diff --git a/firmware/src_simtrace/simtrace_iso7816.c b/firmware/src_simtrace/simtrace_iso7816.c index c24ac0a6..e1453db8 100644 --- a/firmware/src_simtrace/simtrace_iso7816.c +++ b/firmware/src_simtrace/simtrace_iso7816.c @@ -46,32 +46,36 @@ volatile ringbuf sim_rcv_buf = { {0}, 0, 0 }; /*----------------------------------------------------------------------------- * Interrupt routines *-----------------------------------------------------------------------------*/ -static void Callback_PhoneRST_ISR( uint8_t *pArg, uint8_t status, uint32_t transferred, uint32_t remaining) +static void Callback_PhoneRST_ISR(uint8_t * pArg, uint8_t status, + uint32_t transferred, uint32_t remaining) { - printf("rstCB\n\r"); - PIO_EnableIt( &pinPhoneRST ) ; + printf("rstCB\n\r"); + PIO_EnableIt(&pinPhoneRST); } -void ISR_PhoneRST( const Pin *pPin) + +void ISR_PhoneRST(const Pin * pPin) { - int ret; - // FIXME: no printfs in ISRs? - printf("+++ Int!! %x\n\r", pinPhoneRST.pio->PIO_ISR); - if ( ((pinPhoneRST.pio->PIO_ISR & pinPhoneRST.mask) != 0) ) - { - if(PIO_Get( &pinPhoneRST ) == 0) { - printf(" 0 "); - } else { - printf(" 1 "); - } - } + int ret; + // FIXME: no printfs in ISRs? + printf("+++ Int!! %x\n\r", pinPhoneRST.pio->PIO_ISR); + if (((pinPhoneRST.pio->PIO_ISR & pinPhoneRST.mask) != 0)) { + if (PIO_Get(&pinPhoneRST) == 0) { + printf(" 0 "); + } else { + printf(" 1 "); + } + } - if ((ret = USBD_Write( PHONE_INT, "R", 1, (TransferCallback)&Callback_PhoneRST_ISR, 0 )) != USBD_STATUS_SUCCESS) { - TRACE_ERROR("USB err status: %d (%s)\n", ret, __FUNCTION__); - return; - } + if ((ret = + USBD_Write(PHONE_INT, "R", 1, + (TransferCallback) & Callback_PhoneRST_ISR, + 0)) != USBD_STATUS_SUCCESS) { + TRACE_ERROR("USB err status: %d (%s)\n", ret, __FUNCTION__); + return; + } - /* Interrupt enabled after ATR is sent to phone */ - PIO_DisableIt( &pinPhoneRST ) ; + /* Interrupt enabled after ATR is sent to phone */ + PIO_DisableIt(&pinPhoneRST); } extern void usart_irq_rx(uint8_t num); @@ -79,40 +83,40 @@ extern void usart_irq_rx(uint8_t num); * char_stat is zero if no error occured. * Otherwise it is filled with the content of the status register. */ -void USART1_IrqHandler( void ) +void USART1_IrqHandler(void) { #if 0 - uint32_t stat; - char_stat = 0; - // Rcv buf full -/* if((stat & US_CSR_RXBUFF) == US_CSR_RXBUFF) { - TRACE_DEBUG("Rcv buf full"); - USART_DisableIt(USART1, US_IDR_RXBUFF); - } + uint32_t stat; + char_stat = 0; + // Rcv buf full +/* if((stat & US_CSR_RXBUFF) == US_CSR_RXBUFF) { + TRACE_DEBUG("Rcv buf full"); + USART_DisableIt(USART1, US_IDR_RXBUFF); + } */ - uint32_t csr = USART_PHONE->US_CSR; + uint32_t csr = USART_PHONE->US_CSR; - if (csr & US_CSR_TXRDY) { - /* transmit buffer empty, nothing to transmit */ - } - if (csr & US_CSR_RXRDY) { - stat = (csr&(US_CSR_OVRE|US_CSR_FRAME| - US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK| - (1<<10))); - uint8_t c = (USART_PHONE->US_RHR) & 0xFF; -// printf(" %x", c); + if (csr & US_CSR_TXRDY) { + /* transmit buffer empty, nothing to transmit */ + } + if (csr & US_CSR_RXRDY) { + stat = (csr & (US_CSR_OVRE | US_CSR_FRAME | + US_CSR_PARE | US_CSR_TIMEOUT | US_CSR_NACK | + (1 << 10))); + uint8_t c = (USART_PHONE->US_RHR) & 0xFF; +// printf(" %x", c); - if (stat == 0 ) { - /* Fill char into buffer */ - rbuf_write(&sim_rcv_buf, c); - } else { - TRACE_DEBUG("e %x st: %x\n", c, stat); - } /* else: error occured */ + if (stat == 0) { + /* Fill char into buffer */ + rbuf_write(&sim_rcv_buf, c); + } else { + TRACE_DEBUG("e %x st: %x\n", c, stat); + } /* else: error occured */ - char_stat = stat; - } + char_stat = stat; + } #else - usart_irq_rx(0); + usart_irq_rx(0); #endif } @@ -121,13 +125,13 @@ void update_fidi(uint8_t fidi) { int rc; - uint8_t fi = fidi >> 4; - uint8_t di = fidi & 0xf; + uint8_t fi = fidi >> 4; + uint8_t di = fidi & 0xf; rc = compute_fidi_ratio(fi, di); if (rc > 0 && rc < 0x400) { TRACE_INFO("computed Fi(%u) Di(%u) ratio: %d", fi, di, rc); -/* make sure UART uses new F/D ratio */ + /* make sure UART uses new F/D ratio */ USART_PHONE->US_CR |= US_CR_RXDIS | US_CR_RSTRX; USART_PHONE->US_FIDI = rc & 0x3ff; USART_PHONE->US_CR |= US_CR_RXEN | US_CR_STTTO; diff --git a/firmware/src_simtrace/sniffer.c b/firmware/src_simtrace/sniffer.c index 382ee147..3f16a7e1 100644 --- a/firmware/src_simtrace/sniffer.c +++ b/firmware/src_simtrace/sniffer.c @@ -50,50 +50,58 @@ * Internal variables *------------------------------------------------------------------------------*/ /** ISO7816 pins */ -static const Pin pinsISO7816_sniff[] = {PINS_SIM_SNIFF_SIM}; -static const Pin pins_bus[] = {PINS_BUS_SNIFF}; +static const Pin pinsISO7816_sniff[] = { PINS_SIM_SNIFF_SIM }; +static const Pin pins_bus[] = { PINS_BUS_SNIFF }; + static const Pin pPwr[] = { - /* Enable power converter 4.5-6V to 3.3V; low: off */ - {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}, - - /* Enable second power converter: VCC_PHONE to VCC_SIM; high: on */ - {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} + /* Enable power converter 4.5-6V to 3.3V; low: off */ + {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}, + + /* Enable second power converter: VCC_PHONE to VCC_SIM; high: on */ + {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} }; -static struct Usart_info usart_info = {.base = USART_PHONE, .id = ID_USART_PHONE, .state = USART_RCV}; +static struct Usart_info usart_info = { + .base = USART_PHONE, + .id = ID_USART_PHONE, + .state = USART_RCV, +}; /*----------------------------------------------------------------------------- * Initialization routine *-----------------------------------------------------------------------------*/ -void Sniffer_configure( void ){ - TRACE_INFO("Sniffer config\n"); -} - -void Sniffer_exit( void ){ - TRACE_INFO("Sniffer exit\n"); - USART_DisableIt(USART_PHONE, US_IER_RXRDY); - NVIC_DisableIRQ(USART1_IRQn); - USART_SetReceiverEnabled(USART_PHONE, 0); -} -void Sniffer_init( void ) +void Sniffer_configure(void) { - TRACE_INFO("Sniffer Init\n"); - /* Configure ISO7816 driver */ - PIO_Configure( pinsISO7816_sniff, PIO_LISTSIZE( pinsISO7816_sniff ) ) ; - PIO_Configure( pins_bus, PIO_LISTSIZE( pins_bus) ) ; - - PIO_Configure(pPwr, PIO_LISTSIZE( pPwr )); - - ISO7816_Init(&usart_info, CLK_SLAVE); - - USART_SetReceiverEnabled(USART_PHONE, 1); - USART_EnableIt(USART_PHONE, US_IER_RXRDY); - NVIC_EnableIRQ(USART1_IRQn); + TRACE_INFO("Sniffer config\n"); } -void Sniffer_run( void ) +void Sniffer_exit(void) { - check_data_from_phone(); + TRACE_INFO("Sniffer exit\n"); + USART_DisableIt(USART_PHONE, US_IER_RXRDY); + NVIC_DisableIRQ(USART1_IRQn); + USART_SetReceiverEnabled(USART_PHONE, 0); +} + +void Sniffer_init(void) +{ + TRACE_INFO("Sniffer Init\n"); + /* Configure ISO7816 driver */ + PIO_Configure(pinsISO7816_sniff, PIO_LISTSIZE(pinsISO7816_sniff)); + PIO_Configure(pins_bus, PIO_LISTSIZE(pins_bus)); + + PIO_Configure(pPwr, PIO_LISTSIZE(pPwr)); + + ISO7816_Init(&usart_info, CLK_SLAVE); + + USART_SetReceiverEnabled(USART_PHONE, 1); + USART_EnableIt(USART_PHONE, US_IER_RXRDY); + NVIC_EnableIRQ(USART1_IRQn); +} + +void Sniffer_run(void) +{ + check_data_from_phone(); } #endif /* HAVE_SNIFFER */ diff --git a/firmware/src_simtrace/usb.c b/firmware/src_simtrace/usb.c index 3d69780f..d99cce0c 100644 --- a/firmware/src_simtrace/usb.c +++ b/firmware/src_simtrace/usb.c @@ -41,205 +41,210 @@ * USB String descriptors *------------------------------------------------------------------------------*/ - static const unsigned char langDesc[] = { - USBStringDescriptor_LENGTH(1), - USBGenericDescriptor_STRING, - USBStringDescriptor_ENGLISH_US + USBStringDescriptor_LENGTH(1), + USBGenericDescriptor_STRING, + USBStringDescriptor_ENGLISH_US }; const unsigned char manufStringDescriptor[] = { - USBStringDescriptor_LENGTH(24), - USBGenericDescriptor_STRING, - USBStringDescriptor_UNICODE('s'), - USBStringDescriptor_UNICODE('y'), - USBStringDescriptor_UNICODE('s'), - USBStringDescriptor_UNICODE('m'), - USBStringDescriptor_UNICODE('o'), - USBStringDescriptor_UNICODE('c'), - USBStringDescriptor_UNICODE('o'), - USBStringDescriptor_UNICODE('m'), - USBStringDescriptor_UNICODE(' '), - USBStringDescriptor_UNICODE('-'), - USBStringDescriptor_UNICODE(' '), - USBStringDescriptor_UNICODE('s'), - USBStringDescriptor_UNICODE('.'), - USBStringDescriptor_UNICODE('f'), - USBStringDescriptor_UNICODE('.'), - USBStringDescriptor_UNICODE('m'), - USBStringDescriptor_UNICODE('.'), - USBStringDescriptor_UNICODE('c'), - USBStringDescriptor_UNICODE('.'), - USBStringDescriptor_UNICODE(' '), - USBStringDescriptor_UNICODE('G'), - USBStringDescriptor_UNICODE('m'), - USBStringDescriptor_UNICODE('b'), - USBStringDescriptor_UNICODE('H'), + USBStringDescriptor_LENGTH(24), + USBGenericDescriptor_STRING, + USBStringDescriptor_UNICODE('s'), + USBStringDescriptor_UNICODE('y'), + USBStringDescriptor_UNICODE('s'), + USBStringDescriptor_UNICODE('m'), + USBStringDescriptor_UNICODE('o'), + USBStringDescriptor_UNICODE('c'), + USBStringDescriptor_UNICODE('o'), + USBStringDescriptor_UNICODE('m'), + USBStringDescriptor_UNICODE(' '), + USBStringDescriptor_UNICODE('-'), + USBStringDescriptor_UNICODE(' '), + USBStringDescriptor_UNICODE('s'), + USBStringDescriptor_UNICODE('.'), + USBStringDescriptor_UNICODE('f'), + USBStringDescriptor_UNICODE('.'), + USBStringDescriptor_UNICODE('m'), + USBStringDescriptor_UNICODE('.'), + USBStringDescriptor_UNICODE('c'), + USBStringDescriptor_UNICODE('.'), + USBStringDescriptor_UNICODE(' '), + USBStringDescriptor_UNICODE('G'), + USBStringDescriptor_UNICODE('m'), + USBStringDescriptor_UNICODE('b'), + USBStringDescriptor_UNICODE('H'), }; const unsigned char productStringDescriptor[] = { - USBStringDescriptor_LENGTH(10), - USBGenericDescriptor_STRING, - USBStringDescriptor_UNICODE('S'), - USBStringDescriptor_UNICODE('I'), - USBStringDescriptor_UNICODE('M'), - USBStringDescriptor_UNICODE('t'), - USBStringDescriptor_UNICODE('r'), - USBStringDescriptor_UNICODE('a'), - USBStringDescriptor_UNICODE('c'), - USBStringDescriptor_UNICODE('e'), - USBStringDescriptor_UNICODE(' '), - USBStringDescriptor_UNICODE('2'), + USBStringDescriptor_LENGTH(10), + USBGenericDescriptor_STRING, + USBStringDescriptor_UNICODE('S'), + USBStringDescriptor_UNICODE('I'), + USBStringDescriptor_UNICODE('M'), + USBStringDescriptor_UNICODE('t'), + USBStringDescriptor_UNICODE('r'), + USBStringDescriptor_UNICODE('a'), + USBStringDescriptor_UNICODE('c'), + USBStringDescriptor_UNICODE('e'), + USBStringDescriptor_UNICODE(' '), + USBStringDescriptor_UNICODE('2'), }; const unsigned char snifferConfigStringDescriptor[] = { - USBStringDescriptor_LENGTH(16), - USBGenericDescriptor_STRING, - USBStringDescriptor_UNICODE('S'), - USBStringDescriptor_UNICODE('I'), - USBStringDescriptor_UNICODE('M'), - USBStringDescriptor_UNICODE('t'), - USBStringDescriptor_UNICODE('r'), - USBStringDescriptor_UNICODE('a'), - USBStringDescriptor_UNICODE('c'), - USBStringDescriptor_UNICODE('e'), - USBStringDescriptor_UNICODE(' '), - USBStringDescriptor_UNICODE('S'), - USBStringDescriptor_UNICODE('n'), - USBStringDescriptor_UNICODE('i'), - USBStringDescriptor_UNICODE('f'), - USBStringDescriptor_UNICODE('f'), - USBStringDescriptor_UNICODE('e'), - USBStringDescriptor_UNICODE('r'), + USBStringDescriptor_LENGTH(16), + USBGenericDescriptor_STRING, + USBStringDescriptor_UNICODE('S'), + USBStringDescriptor_UNICODE('I'), + USBStringDescriptor_UNICODE('M'), + USBStringDescriptor_UNICODE('t'), + USBStringDescriptor_UNICODE('r'), + USBStringDescriptor_UNICODE('a'), + USBStringDescriptor_UNICODE('c'), + USBStringDescriptor_UNICODE('e'), + USBStringDescriptor_UNICODE(' '), + USBStringDescriptor_UNICODE('S'), + USBStringDescriptor_UNICODE('n'), + USBStringDescriptor_UNICODE('i'), + USBStringDescriptor_UNICODE('f'), + USBStringDescriptor_UNICODE('f'), + USBStringDescriptor_UNICODE('e'), + USBStringDescriptor_UNICODE('r'), }; const unsigned char CCIDConfigStringDescriptor[] = { - USBStringDescriptor_LENGTH(13), - USBGenericDescriptor_STRING, - USBStringDescriptor_UNICODE('S'), - USBStringDescriptor_UNICODE('I'), - USBStringDescriptor_UNICODE('M'), - USBStringDescriptor_UNICODE('t'), - USBStringDescriptor_UNICODE('r'), - USBStringDescriptor_UNICODE('a'), - USBStringDescriptor_UNICODE('c'), - USBStringDescriptor_UNICODE('e'), - USBStringDescriptor_UNICODE(' '), - USBStringDescriptor_UNICODE('C'), - USBStringDescriptor_UNICODE('C'), - USBStringDescriptor_UNICODE('I'), - USBStringDescriptor_UNICODE('D'), + USBStringDescriptor_LENGTH(13), + USBGenericDescriptor_STRING, + USBStringDescriptor_UNICODE('S'), + USBStringDescriptor_UNICODE('I'), + USBStringDescriptor_UNICODE('M'), + USBStringDescriptor_UNICODE('t'), + USBStringDescriptor_UNICODE('r'), + USBStringDescriptor_UNICODE('a'), + USBStringDescriptor_UNICODE('c'), + USBStringDescriptor_UNICODE('e'), + USBStringDescriptor_UNICODE(' '), + USBStringDescriptor_UNICODE('C'), + USBStringDescriptor_UNICODE('C'), + USBStringDescriptor_UNICODE('I'), + USBStringDescriptor_UNICODE('D'), }; const unsigned char phoneConfigStringDescriptor[] = { - USBStringDescriptor_LENGTH(14), - USBGenericDescriptor_STRING, - USBStringDescriptor_UNICODE('S'), - USBStringDescriptor_UNICODE('I'), - USBStringDescriptor_UNICODE('M'), - USBStringDescriptor_UNICODE('t'), - USBStringDescriptor_UNICODE('r'), - USBStringDescriptor_UNICODE('a'), - USBStringDescriptor_UNICODE('c'), - USBStringDescriptor_UNICODE('e'), - USBStringDescriptor_UNICODE(' '), - USBStringDescriptor_UNICODE('P'), - USBStringDescriptor_UNICODE('h'), - USBStringDescriptor_UNICODE('o'), - USBStringDescriptor_UNICODE('n'), - USBStringDescriptor_UNICODE('e'), + USBStringDescriptor_LENGTH(14), + USBGenericDescriptor_STRING, + USBStringDescriptor_UNICODE('S'), + USBStringDescriptor_UNICODE('I'), + USBStringDescriptor_UNICODE('M'), + USBStringDescriptor_UNICODE('t'), + USBStringDescriptor_UNICODE('r'), + USBStringDescriptor_UNICODE('a'), + USBStringDescriptor_UNICODE('c'), + USBStringDescriptor_UNICODE('e'), + USBStringDescriptor_UNICODE(' '), + USBStringDescriptor_UNICODE('P'), + USBStringDescriptor_UNICODE('h'), + USBStringDescriptor_UNICODE('o'), + USBStringDescriptor_UNICODE('n'), + USBStringDescriptor_UNICODE('e'), }; - const unsigned char MITMConfigStringDescriptor[] = { - USBStringDescriptor_LENGTH(13), - USBGenericDescriptor_STRING, - USBStringDescriptor_UNICODE('S'), - USBStringDescriptor_UNICODE('I'), - USBStringDescriptor_UNICODE('M'), - USBStringDescriptor_UNICODE('t'), - USBStringDescriptor_UNICODE('r'), - USBStringDescriptor_UNICODE('a'), - USBStringDescriptor_UNICODE('c'), - USBStringDescriptor_UNICODE('e'), - USBStringDescriptor_UNICODE(' '), - USBStringDescriptor_UNICODE('M'), - USBStringDescriptor_UNICODE('I'), - USBStringDescriptor_UNICODE('T'), - USBStringDescriptor_UNICODE('M'), + USBStringDescriptor_LENGTH(13), + USBGenericDescriptor_STRING, + USBStringDescriptor_UNICODE('S'), + USBStringDescriptor_UNICODE('I'), + USBStringDescriptor_UNICODE('M'), + USBStringDescriptor_UNICODE('t'), + USBStringDescriptor_UNICODE('r'), + USBStringDescriptor_UNICODE('a'), + USBStringDescriptor_UNICODE('c'), + USBStringDescriptor_UNICODE('e'), + USBStringDescriptor_UNICODE(' '), + USBStringDescriptor_UNICODE('M'), + USBStringDescriptor_UNICODE('I'), + USBStringDescriptor_UNICODE('T'), + USBStringDescriptor_UNICODE('M'), }; const unsigned char cardem_usim1_intf_str[] = { - USBStringDescriptor_LENGTH(18), - USBGenericDescriptor_STRING, - USBStringDescriptor_UNICODE('C'), - USBStringDescriptor_UNICODE('a'), - USBStringDescriptor_UNICODE('r'), - USBStringDescriptor_UNICODE('d'), - USBStringDescriptor_UNICODE('E'), - USBStringDescriptor_UNICODE('m'), - USBStringDescriptor_UNICODE('u'), - USBStringDescriptor_UNICODE('l'), - USBStringDescriptor_UNICODE('a'), - USBStringDescriptor_UNICODE('t'), - USBStringDescriptor_UNICODE('o'), - USBStringDescriptor_UNICODE('r'), - USBStringDescriptor_UNICODE(' '), - USBStringDescriptor_UNICODE('U'), - USBStringDescriptor_UNICODE('S'), - USBStringDescriptor_UNICODE('I'), - USBStringDescriptor_UNICODE('M'), - USBStringDescriptor_UNICODE('1'), + USBStringDescriptor_LENGTH(18), + USBGenericDescriptor_STRING, + USBStringDescriptor_UNICODE('C'), + USBStringDescriptor_UNICODE('a'), + USBStringDescriptor_UNICODE('r'), + USBStringDescriptor_UNICODE('d'), + USBStringDescriptor_UNICODE('E'), + USBStringDescriptor_UNICODE('m'), + USBStringDescriptor_UNICODE('u'), + USBStringDescriptor_UNICODE('l'), + USBStringDescriptor_UNICODE('a'), + USBStringDescriptor_UNICODE('t'), + USBStringDescriptor_UNICODE('o'), + USBStringDescriptor_UNICODE('r'), + USBStringDescriptor_UNICODE(' '), + USBStringDescriptor_UNICODE('U'), + USBStringDescriptor_UNICODE('S'), + USBStringDescriptor_UNICODE('I'), + USBStringDescriptor_UNICODE('M'), + USBStringDescriptor_UNICODE('1'), }; const unsigned char cardem_usim2_intf_str[] = { - USBStringDescriptor_LENGTH(18), - USBGenericDescriptor_STRING, - USBStringDescriptor_UNICODE('C'), - USBStringDescriptor_UNICODE('a'), - USBStringDescriptor_UNICODE('r'), - USBStringDescriptor_UNICODE('d'), - USBStringDescriptor_UNICODE('E'), - USBStringDescriptor_UNICODE('m'), - USBStringDescriptor_UNICODE('u'), - USBStringDescriptor_UNICODE('l'), - USBStringDescriptor_UNICODE('a'), - USBStringDescriptor_UNICODE('t'), - USBStringDescriptor_UNICODE('o'), - USBStringDescriptor_UNICODE('r'), - USBStringDescriptor_UNICODE(' '), - USBStringDescriptor_UNICODE('U'), - USBStringDescriptor_UNICODE('S'), - USBStringDescriptor_UNICODE('I'), - USBStringDescriptor_UNICODE('M'), - USBStringDescriptor_UNICODE('2'), + USBStringDescriptor_LENGTH(18), + USBGenericDescriptor_STRING, + USBStringDescriptor_UNICODE('C'), + USBStringDescriptor_UNICODE('a'), + USBStringDescriptor_UNICODE('r'), + USBStringDescriptor_UNICODE('d'), + USBStringDescriptor_UNICODE('E'), + USBStringDescriptor_UNICODE('m'), + USBStringDescriptor_UNICODE('u'), + USBStringDescriptor_UNICODE('l'), + USBStringDescriptor_UNICODE('a'), + USBStringDescriptor_UNICODE('t'), + USBStringDescriptor_UNICODE('o'), + USBStringDescriptor_UNICODE('r'), + USBStringDescriptor_UNICODE(' '), + USBStringDescriptor_UNICODE('U'), + USBStringDescriptor_UNICODE('S'), + USBStringDescriptor_UNICODE('I'), + USBStringDescriptor_UNICODE('M'), + USBStringDescriptor_UNICODE('2'), }; enum strDescNum { - PRODUCT_STRING = 1, MANUF_STR, SNIFFER_CONF_STR, CCID_CONF_STR, PHONE_CONF_STR, MITM_CONF_STR, - CARDEM_USIM1_INTF_STR, CARDEM_USIM2_INTF_STR, STRING_DESC_CNT + PRODUCT_STRING = 1, + MANUF_STR, + SNIFFER_CONF_STR, + CCID_CONF_STR, + PHONE_CONF_STR, + MITM_CONF_STR, + CARDEM_USIM1_INTF_STR, + CARDEM_USIM2_INTF_STR, + STRING_DESC_CNT }; /** List of string descriptors used by the device */ static const unsigned char *stringDescriptors[] = { - langDesc, - [PRODUCT_STRING] = productStringDescriptor, - [MANUF_STR] = manufStringDescriptor, - [SNIFFER_CONF_STR] = snifferConfigStringDescriptor, - [CCID_CONF_STR] = CCIDConfigStringDescriptor, - [PHONE_CONF_STR] = phoneConfigStringDescriptor, - [MITM_CONF_STR] = MITMConfigStringDescriptor, - [CARDEM_USIM1_INTF_STR] = cardem_usim1_intf_str, - [CARDEM_USIM2_INTF_STR] = cardem_usim2_intf_str, + langDesc, + [PRODUCT_STRING] = productStringDescriptor, + [MANUF_STR] = manufStringDescriptor, + [SNIFFER_CONF_STR] = snifferConfigStringDescriptor, + [CCID_CONF_STR] = CCIDConfigStringDescriptor, + [PHONE_CONF_STR] = phoneConfigStringDescriptor, + [MITM_CONF_STR] = MITMConfigStringDescriptor, + [CARDEM_USIM1_INTF_STR] = cardem_usim1_intf_str, + [CARDEM_USIM2_INTF_STR] = cardem_usim2_intf_str, }; /*------------------------------------------------------------------------------ @@ -249,516 +254,523 @@ static const unsigned char *stringDescriptors[] = { #ifdef HAVE_SNIFFER typedef struct _SIMTraceDriverConfigurationDescriptorSniffer { - /** Standard configuration descriptor. */ - USBConfigurationDescriptor configuration; - USBInterfaceDescriptor sniffer; - USBEndpointDescriptor sniffer_dataOut; - USBEndpointDescriptor sniffer_dataIn; - USBEndpointDescriptor sniffer_interruptIn; + /** Standard configuration descriptor. */ + USBConfigurationDescriptor configuration; + USBInterfaceDescriptor sniffer; + USBEndpointDescriptor sniffer_dataOut; + USBEndpointDescriptor sniffer_dataIn; + USBEndpointDescriptor sniffer_interruptIn; } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorSniffer; -static const SIMTraceDriverConfigurationDescriptorSniffer configurationDescriptorSniffer = { - /* Standard configuration descriptor */ - { - sizeof(USBConfigurationDescriptor), - USBGenericDescriptor_CONFIGURATION, - sizeof(SIMTraceDriverConfigurationDescriptorSniffer), - 1, /* There is one interface in this configuration */ - CFG_NUM_SNIFF, /* configuration number */ - SNIFFER_CONF_STR, /* string descriptor for this configuration */ - USBD_BMATTRIBUTES, - USBConfigurationDescriptor_POWER(100) - }, - /* Communication class interface standard descriptor */ - { - sizeof(USBInterfaceDescriptor), - USBGenericDescriptor_INTERFACE, - 0, /* This is interface #0 */ - 0, /* This is alternate setting #0 for this interface */ - 3, /* Number of endpoints */ - 0xff, /* Descriptor Class: Vendor specific */ - 0, /* No subclass */ - 0, /* No l */ - SNIFFER_CONF_STR /* Third in string descriptor for this interface */ - }, - /* Bulk-OUT endpoint standard descriptor */ - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, - PHONE_DATAOUT), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0 /* Must be 0 for full-speed bulk endpoints */ - }, - /* Bulk-IN endpoint descriptor */ - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, - PHONE_DATAIN), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0 /* Must be 0 for full-speed bulk endpoints */ - }, - // Notification endpoint descriptor - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, PHONE_INT ), - USBEndpointDescriptor_INTERRUPT, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT), - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), - 0x10 - } +static const SIMTraceDriverConfigurationDescriptorSniffer + configurationDescriptorSniffer = { + /* Standard configuration descriptor */ + { + .bLength = sizeof(USBConfigurationDescriptor), + .bDescriptorType = USBGenericDescriptor_CONFIGURATION, + .wTotalLength = sizeof(SIMTraceDriverConfigurationDescriptorSniffer), + .bNumInterfaces = 1, + .bConfigurationValue = CFG_NUM_SNIFF, + .iConfiguration = SNIFFER_CONF_STR, + .bmAttributes = USBD_BMATTRIBUTES, + .bMaxPower = USBConfigurationDescriptor_POWER(100), + }, + /* Communication class interface standard descriptor */ + { + .bLength = sizeof(USBInterfaceDescriptor), + .bDescriptorType = USBGenericDescriptor_INTERFACE, + .bInterfaceNumber = 0, + .bAlternateSetting = 0, + .bNumEndpoints = 3, + .bInterfaceClass = 0xff, + .bInterfaceSubClass = 0, + .bInterfaceProtocol = 0, + .iInterface = SNIFFER_CONF_STR, + }, + /* Bulk-OUT endpoint standard descriptor */ + { + .bLength = sizeof(USBEndpointDescriptor), + .bDescriptorType = USBGenericDescriptor_ENDPOINT, + .bEndpointAddress = USBEndpointDescriptor_ADDRESS( + USBEndpointDescriptor_OUT, + PHONE_DATAOUT), + .bmAttributes = USBEndpointDescriptor_BULK, + .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( + PHONE_DATAOUT), + USBEndpointDescriptor_MAXBULKSIZE_FS), + .bInterval = 0, + }, + /* Bulk-IN endpoint descriptor */ + { + .bLength = sizeof(USBEndpointDescriptor), + .bDescriptorType = USBGenericDescriptor_ENDPOINT, + .bEndpointAddress = USBEndpointDescriptor_ADDRESS( + USBEndpointDescriptor_IN, + PHONE_DATAIN), + .bmAttributes = USBEndpointDescriptor_BULK, + .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( + PHONE_DATAIN), + USBEndpointDescriptor_MAXBULKSIZE_FS), + .bInterval = 0, + }, + // Notification endpoint descriptor + { + .bLength = sizeof(USBEndpointDescriptor), + .bDescriptorType = USBGenericDescriptor_ENDPOINT, + .bEndpointAddress = USBEndpointDescriptor_ADDRESS( + USBEndpointDescriptor_IN, + PHONE_INT), + .bmAttributes = USBEndpointDescriptor_INTERRUPT, + .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( + PHONE_INT), + USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), + .bInterval = 0x10, + } }; #endif /* HAVE_SNIFFER */ - #ifdef HAVE_CCID -/* -/// CCIDDriverConfiguration Descriptors -/// List of descriptors that make up the configuration descriptors of a -/// device using the CCID driver. -typedef struct { - - /// Configuration descriptor - USBConfigurationDescriptor configuration; - /// Interface descriptor - USBInterfaceDescriptor interface; - /// CCID descriptor - CCIDDescriptor ccid; - /// Bulk OUT endpoint descriptor - USBEndpointDescriptor bulkOut; - /// Bulk IN endpoint descriptor - USBEndpointDescriptor bulkIn; - /// Interrupt OUT endpoint descriptor - USBEndpointDescriptor interruptIn; -} __attribute__ ((packed)) CCIDDriverConfigurationDescriptors; -*/ - static const CCIDDriverConfigurationDescriptors configurationDescriptorCCID = { - - // Standard USB configuration descriptor - { - sizeof(USBConfigurationDescriptor), - USBGenericDescriptor_CONFIGURATION, - sizeof(CCIDDriverConfigurationDescriptors), - 1, // One interface in this configuration - CFG_NUM_CCID, // This is configuration #1 - CCID_CONF_STR, // associated string descriptor - BOARD_USB_BMATTRIBUTES, - USBConfigurationDescriptor_POWER(100) - }, - // CCID interface descriptor - // Table 4.3-1 Interface Descriptor - // Interface descriptor - { - sizeof(USBInterfaceDescriptor), - USBGenericDescriptor_INTERFACE, - 0, // Interface 0 - 0, // No alternate settings - 3, // uses bulk-IN, bulk-OUT and interrupt IN - SMART_CARD_DEVICE_CLASS, - 0, // Subclass code - 0, // bulk transfers optional interrupt-IN - CCID_CONF_STR // associated string descriptor - }, - { - sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes - CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type - CCID1_10, // bcdCCID: CCID version - 0, // bMaxSlotIndex: Value 0 indicates that one slot is supported - VOLTS_3_0, // bVoltageSupport - (1 << PROTOCOL_TO), // dwProtocols - 3580, // dwDefaultClock - 3580, // dwMaxClock - 0, // bNumClockSupported - 9600, // dwDataRate : 9600 bauds - 9600, // dwMaxDataRate : 9600 bauds - 0, // bNumDataRatesSupported - 0xfe, // dwMaxIFSD - 0, // dwSynchProtocols - 0, // dwMechanical - //0x00010042, // dwFeatures: Short APDU level exchanges - CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | - CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU, - 0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10 - 0xFF, // bClassGetResponse: Echoes the class of the APDU - 0xFF, // bClassEnvelope: Echoes the class of the APDU - 0, // wLcdLayout: no LCD - 0, // bPINSupport: No PIN - 1 // bMaxCCIDBusySlot - }, - // Bulk-OUT endpoint descriptor - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0x00 // Does not apply to Bulk endpoints - }, - // Bulk-IN endpoint descriptor - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0x00 // Does not apply to Bulk endpoints - }, - // Notification endpoint descriptor - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ), - USBEndpointDescriptor_INTERRUPT, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION), - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), - 0x10 - }, + // Standard USB configuration descriptor + { + .bLength = sizeof(USBConfigurationDescriptor), + .bDescriptorType = USBGenericDescriptor_CONFIGURATION, + .wTotalLength = sizeof(CCIDDriverConfigurationDescriptors), + .bNumInterfaces = 1, + .bConfigurationValue = CFG_NUM_CCID, + .iConfiguration = CCID_CONF_STR, + .bmAttributes = BOARD_USB_BMATTRIBUTES, + .bMaxPower = USBConfigurationDescriptor_POWER(100), + }, + // CCID interface descriptor + // Table 4.3-1 Interface Descriptor + // Interface descriptor + { + .bLength = sizeof(USBInterfaceDescriptor), + .bDescriptorType = USBGenericDescriptor_INTERFACE, + .bInterfaceNumber = 0, + .bAlternateSetting = 0, + .bNumEndpoints = 3, + .bInterfaceClass = SMART_CARD_DEVICE_CLASS, + .bInterfaceSubClass = 0, + .bInterfaceProtocol = 0, + .iInterface = CCID_CONF_STR, + }, + { + .bLength = sizeof(CCIDDescriptor), + .bDescriptorType = CCID_DECRIPTOR_TYPE, + .bcdCCID = CCID1_10, // CCID version + .bMaxSlotIndex = 0, // 1 slot + .bVoltageSupport = VOLTS_3_0, + .dwProtocols = (1 << PROTOCOL_TO), + .dwDefaultClock = 3580, + .dwMaximumClock = 3580, + .bNumClockSupported = 0, + .dwDataRate = 9600, + .dwMaxDataRate = 9600, + .bNumDataRatesSupported = 0, + .dwMaxIFSD = 0xfe, + .dwSynchProtocols = 0, + .dwMechanical = 0, + .dwFeatures = CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | + CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | + CCID_FEATURES_EXC_TPDU, + .dwMaxCCIDMessageLength = 271, /* For extended APDU + level the value shall + be between 261 + 10 */ + .bClassGetResponse = 0xFF, // Echoes the class of the APDU + .bClassEnvelope = 0xFF, // Echoes the class of the APDU + .wLcdLayout = 0, // wLcdLayout: no LCD + .bPINSupport = 0, // bPINSupport: No PIN + .bMaxCCIDBusySlots = 1, + }, + // Bulk-OUT endpoint descriptor + { + .bLength = sizeof(USBEndpointDescriptor), + .bDescriptorType = USBGenericDescriptor_ENDPOINT, + .bEndpointAddress = + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, + CCID_EPT_DATA_OUT), + .bmAttributes = USBEndpointDescriptor_BULK, + .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( + CCID_EPT_DATA_OUT), + USBEndpointDescriptor_MAXBULKSIZE_FS), + .bInterval = 0x00, + }, + // Bulk-IN endpoint descriptor + { + .bLength = sizeof(USBEndpointDescriptor), + .bDescriptorType = USBGenericDescriptor_ENDPOINT, + .bEndpointAddress = + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, + CCID_EPT_DATA_IN), + .bmAttributes = USBEndpointDescriptor_BULK, + .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( + CCID_EPT_DATA_IN), + USBEndpointDescriptor_MAXBULKSIZE_FS), + .bInterval = 0x00, + }, + // Notification endpoint descriptor + { + .bLength = sizeof(USBEndpointDescriptor), + .bDescriptorType = USBGenericDescriptor_ENDPOINT, + .bEndpointAddress = + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, + CCID_EPT_NOTIFICATION), + .bmAttributes = USBEndpointDescriptor_INTERRUPT, + .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( + CCID_EPT_NOTIFICATION), + USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), + .bInterval = 0x10, + }, }; #endif /* HAVE_CCID */ - #ifdef HAVE_CARDEM /* SIM card emulator */ typedef struct _SIMTraceDriverConfigurationDescriptorPhone { - - /** Standard configuration descriptor. */ - USBConfigurationDescriptor configuration; - USBInterfaceDescriptor phone; - USBEndpointDescriptor phone_dataOut; - USBEndpointDescriptor phone_dataIn; - USBEndpointDescriptor phone_interruptIn; + /* Standard configuration descriptor. */ + USBConfigurationDescriptor configuration; + USBInterfaceDescriptor phone; + USBEndpointDescriptor phone_dataOut; + USBEndpointDescriptor phone_dataIn; + USBEndpointDescriptor phone_interruptIn; #ifdef CARDEMU_SECOND_UART - USBInterfaceDescriptor usim2; - USBEndpointDescriptor usim2_dataOut; - USBEndpointDescriptor usim2_dataIn; - USBEndpointDescriptor usim2_interruptIn; + USBInterfaceDescriptor usim2; + USBEndpointDescriptor usim2_dataOut; + USBEndpointDescriptor usim2_dataIn; + USBEndpointDescriptor usim2_interruptIn; #endif } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorPhone; -static const SIMTraceDriverConfigurationDescriptorPhone configurationDescriptorPhone = { - /* Standard configuration descriptor */ - { - sizeof(USBConfigurationDescriptor), - USBGenericDescriptor_CONFIGURATION, - sizeof(SIMTraceDriverConfigurationDescriptorPhone), +static const SIMTraceDriverConfigurationDescriptorPhone + configurationDescriptorPhone = { + /* Standard configuration descriptor */ + { + sizeof(USBConfigurationDescriptor), + USBGenericDescriptor_CONFIGURATION, + sizeof(SIMTraceDriverConfigurationDescriptorPhone), #ifdef CARDEMU_SECOND_UART - 2, + 2, #else - 1, /* There is one interface in this configuration */ + 1, /* There is one interface in this configuration */ #endif - CFG_NUM_PHONE, /* configuration number */ - PHONE_CONF_STR, /* string descriptor for this configuration */ - USBD_BMATTRIBUTES, - USBConfigurationDescriptor_POWER(100) - }, - /* Communication class interface standard descriptor */ - { - sizeof(USBInterfaceDescriptor), - USBGenericDescriptor_INTERFACE, - 0, /* This is interface #0 */ - 0, /* This is alternate setting #0 for this interface */ - 3, /* Number of endpoints */ - 0xff, /* Descriptor Class: Vendor specific */ - 0, /* No subclass */ - 0, /* No l */ - CARDEM_USIM1_INTF_STR - }, - /* Bulk-OUT endpoint standard descriptor */ - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, - PHONE_DATAOUT), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0 /* Must be 0 for full-speed bulk endpoints */ - }, - /* Bulk-IN endpoint descriptor */ - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, - PHONE_DATAIN), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0 /* Must be 0 for full-speed bulk endpoints */ - }, - /* Notification endpoint descriptor */ - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, PHONE_INT ), - USBEndpointDescriptor_INTERRUPT, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT), - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), - 0x10 - }, + CFG_NUM_PHONE, /* configuration number */ + PHONE_CONF_STR, /* string descriptor for this configuration */ + USBD_BMATTRIBUTES, + USBConfigurationDescriptor_POWER(100) + }, + /* Communication class interface standard descriptor */ + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + 0, /* This is interface #0 */ + 0, /* This is alternate setting #0 for this interface */ + 3, /* Number of endpoints */ + 0xff, /* Descriptor Class: Vendor specific */ + 0, /* No subclass */ + 0, /* No l */ + CARDEM_USIM1_INTF_STR + }, + /* Bulk-OUT endpoint standard descriptor */ + { + sizeof(USBEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, + PHONE_DATAOUT), + USBEndpointDescriptor_BULK, + MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT), + USBEndpointDescriptor_MAXBULKSIZE_FS), + 0 /* Must be 0 for full-speed bulk endpoints */ + }, + /* Bulk-IN endpoint descriptor */ + { + sizeof(USBEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, + PHONE_DATAIN), + USBEndpointDescriptor_BULK, + MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN), + USBEndpointDescriptor_MAXBULKSIZE_FS), + 0 /* Must be 0 for full-speed bulk endpoints */ + }, + /* Notification endpoint descriptor */ + { + sizeof(USBEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, + PHONE_INT), + USBEndpointDescriptor_INTERRUPT, + MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT), + USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), + 0x10 + }, #ifdef CARDEMU_SECOND_UART - /* Communication class interface standard descriptor */ - { - sizeof(USBInterfaceDescriptor), - USBGenericDescriptor_INTERFACE, - 1, /* This is interface #0 */ - 0, /* This is alternate setting #0 for this interface */ - 3, /* Number of endpoints */ - 0xff, /* Descriptor Class: Vendor specific */ - 0, /* No subclass */ - 0, /* No l */ - CARDEM_USIM2_INTF_STR - }, - /* Bulk-OUT endpoint standard descriptor */ - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, - CARDEM_USIM2_DATAOUT), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAOUT), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0 /* Must be 0 for full-speed bulk endpoints */ - }, - /* Bulk-IN endpoint descriptor */ - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, - CARDEM_USIM2_DATAIN), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAIN), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0 /* Must be 0 for full-speed bulk endpoints */ - }, - /* Notification endpoint descriptor */ - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CARDEM_USIM2_INT ), - USBEndpointDescriptor_INTERRUPT, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_INT), - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), - 0x10 - } + /* Communication class interface standard descriptor */ + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + 1, /* This is interface #0 */ + 0, /* This is alternate setting #0 for this interface */ + 3, /* Number of endpoints */ + 0xff, /* Descriptor Class: Vendor specific */ + 0, /* No subclass */ + 0, /* No l */ + CARDEM_USIM2_INTF_STR + }, + /* Bulk-OUT endpoint standard descriptor */ + { + sizeof(USBEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, + CARDEM_USIM2_DATAOUT), + USBEndpointDescriptor_BULK, + MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAOUT), + USBEndpointDescriptor_MAXBULKSIZE_FS), + 0 /* Must be 0 for full-speed bulk endpoints */ + } + , + /* Bulk-IN endpoint descriptor */ + { + sizeof(USBEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, + CARDEM_USIM2_DATAIN), + USBEndpointDescriptor_BULK, + MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAIN), + USBEndpointDescriptor_MAXBULKSIZE_FS), + 0 /* Must be 0 for full-speed bulk endpoints */ + }, + /* Notification endpoint descriptor */ + { + sizeof(USBEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, + CARDEM_USIM2_INT), + USBEndpointDescriptor_INTERRUPT, + MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_INT), + USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), + 0x10 + }, #endif }; #endif /* HAVE_CARDEM */ #ifdef HAVE_MITM typedef struct _SIMTraceDriverConfigurationDescriptorMITM { + /* Standard configuration descriptor. */ + USBConfigurationDescriptor configuration; + USBInterfaceDescriptor simcard; + /// CCID descriptor + CCIDDescriptor ccid; + /// Bulk OUT endpoint descriptor + USBEndpointDescriptor simcard_dataOut; + /// Bulk IN endpoint descriptor + USBEndpointDescriptor simcard_dataIn; + /// Interrupt OUT endpoint descriptor + USBEndpointDescriptor simcard_interruptIn; - /** Standard configuration descriptor. */ - USBConfigurationDescriptor configuration; - USBInterfaceDescriptor simcard; - /// CCID descriptor - CCIDDescriptor ccid; - /// Bulk OUT endpoint descriptor - USBEndpointDescriptor simcard_dataOut; - /// Bulk IN endpoint descriptor - USBEndpointDescriptor simcard_dataIn; - /// Interrupt OUT endpoint descriptor - USBEndpointDescriptor simcard_interruptIn; - - USBInterfaceDescriptor phone; - USBEndpointDescriptor phone_dataOut; - USBEndpointDescriptor phone_dataIn; - USBEndpointDescriptor phone_interruptIn; + USBInterfaceDescriptor phone; + USBEndpointDescriptor phone_dataOut; + USBEndpointDescriptor phone_dataIn; + USBEndpointDescriptor phone_interruptIn; } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorMITM; -static const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorMITM = { - /* Standard configuration descriptor */ - { - sizeof(USBConfigurationDescriptor), - USBGenericDescriptor_CONFIGURATION, - sizeof(SIMTraceDriverConfigurationDescriptorMITM), - 2, /* There are two interfaces in this configuration */ - CFG_NUM_MITM, /* configuration number */ - MITM_CONF_STR, /* string descriptor for this configuration */ - USBD_BMATTRIBUTES, - USBConfigurationDescriptor_POWER(100) - }, - // CCID interface descriptor - // Table 4.3-1 Interface Descriptor - // Interface descriptor - { - sizeof(USBInterfaceDescriptor), - USBGenericDescriptor_INTERFACE, - 0, // Interface 0 - 0, // No alternate settings - 3, // uses bulk-IN, bulk-OUT and interrupt IN - SMART_CARD_DEVICE_CLASS, - 0, // Subclass code - 0, // bulk transfers optional interrupt-IN - CCID_CONF_STR // associated string descriptor - }, - { - sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes - CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type - CCID1_10, // bcdCCID: CCID version - 0, // bMaxSlotIndex: Value 0 indicates that one slot is supported - VOLTS_3_0, // bVoltageSupport - (1 << PROTOCOL_TO), // dwProtocols - 3580, // dwDefaultClock - 3580, // dwMaxClock - 0, // bNumClockSupported - 9600, // dwDataRate : 9600 bauds - 9600, // dwMaxDataRate : 9600 bauds - 0, // bNumDataRatesSupported - 0xfe, // dwMaxIFSD - 0, // dwSynchProtocols - 0, // dwMechanical - //0x00010042, // dwFeatures: Short APDU level exchanges - CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | - CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU, - 0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10 - 0xFF, // bClassGetResponse: Echoes the class of the APDU - 0xFF, // bClassEnvelope: Echoes the class of the APDU - 0, // wLcdLayout: no LCD - 0, // bPINSupport: No PIN - 1 // bMaxCCIDBusySlot - }, - // Bulk-OUT endpoint descriptor - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0x00 // Does not apply to Bulk endpoints - }, - // Bulk-IN endpoint descriptor - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0x00 // Does not apply to Bulk endpoints - }, - // Notification endpoint descriptor - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ), - USBEndpointDescriptor_INTERRUPT, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION), - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), - 0x10 - }, - /* Communication class interface standard descriptor */ - { - sizeof(USBInterfaceDescriptor), - USBGenericDescriptor_INTERFACE, - 1, /* This is interface #1 */ - 0, /* This is alternate setting #0 for this interface */ - 3, /* Number of endpoints */ - 0xff, - 0, - 0, - PHONE_CONF_STR, /* string descriptor for this interface */ - }, - /* Bulk-OUT endpoint standard descriptor */ - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, - PHONE_DATAOUT), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0 /* Must be 0 for full-speed bulk endpoints */ - }, - /* Bulk-IN endpoint descriptor */ - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, - PHONE_DATAIN), - USBEndpointDescriptor_BULK, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN), - USBEndpointDescriptor_MAXBULKSIZE_FS), - 0 /* Must be 0 for full-speed bulk endpoints */ - }, - /* Notification endpoint descriptor */ - { - sizeof(USBEndpointDescriptor), - USBGenericDescriptor_ENDPOINT, - USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, PHONE_INT ), - USBEndpointDescriptor_INTERRUPT, - MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT), - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), - 0x10 - } +static const SIMTraceDriverConfigurationDescriptorMITM + configurationDescriptorMITM = { + /* Standard configuration descriptor */ + { + sizeof(USBConfigurationDescriptor), + USBGenericDescriptor_CONFIGURATION, + sizeof(SIMTraceDriverConfigurationDescriptorMITM), + 2, /* There are two interfaces in this configuration */ + CFG_NUM_MITM, /* configuration number */ + MITM_CONF_STR, /* string descriptor for this configuration */ + USBD_BMATTRIBUTES, + USBConfigurationDescriptor_POWER(100) + }, + // CCID interface descriptor + // Table 4.3-1 Interface Descriptor + // Interface descriptor + { + .bLength = sizeof(USBInterfaceDescriptor), + .bDescriptorType = USBGenericDescriptor_INTERFACE, + .bInterfaceNumber = 0, + .bAlternateSetting = 0, + .bNumEndpoints = 3, + .bInterfaceClass = SMART_CARD_DEVICE_CLASS, + .bInterfaceSubClass = 0, + .bInterfaceProtocol = 0, + .iInterface = CCID_CONF_STR, + }, + { + .bLength = sizeof(CCIDDescriptor), + .bDescriptorType = CCID_DECRIPTOR_TYPE, + .bcdCCID = CCID1_10, // CCID version + .bMaxSlotIndex = 0, // 1 slot + .bVoltageSupport = VOLTS_3_0, + .dwProtocols = (1 << PROTOCOL_TO), + .dwDefaultClock = 3580, + .dwMaximumClock = 3580, + .bNumClockSupported = 0, + .dwDataRate = 9600, + .dwMaxDataRate = 9600, + .bNumDataRatesSupported = 0, + .dwMaxIFSD = 0xfe, + .dwSynchProtocols = 0, + .dwMechanical = 0, + .dwFeatures = CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | + CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | + CCID_FEATURES_EXC_TPDU, + .dwMaxCCIDMessageLength = 271, /* For extended APDU + level the value shall + be between 261 + 10 */ + .bClassGetResponse = 0xFF, // Echoes the class of the APDU + .bClassEnvelope = 0xFF, // Echoes the class of the APDU + .wLcdLayout = 0, // wLcdLayout: no LCD + .bPINSupport = 0, // bPINSupport: No PIN + .bMaxCCIDBusySlots = 1, + }, + // Bulk-OUT endpoint descriptor + { + .bLength = sizeof(USBEndpointDescriptor), + .bDescriptorType = USBGenericDescriptor_ENDPOINT, + .bEndpointAddress = + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, + CCID_EPT_DATA_OUT), + .bmAttributes = USBEndpointDescriptor_BULK, + .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( + CCID_EPT_DATA_OUT), + USBEndpointDescriptor_MAXBULKSIZE_FS), + .bInterval = 0x00, + }, + // Bulk-IN endpoint descriptor + { + .bLength = sizeof(USBEndpointDescriptor), + .bDescriptorType = USBGenericDescriptor_ENDPOINT, + .bEndpointAddress = + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, + CCID_EPT_DATA_IN), + .bmAttributes = USBEndpointDescriptor_BULK, + .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( + CCID_EPT_DATA_IN), + USBEndpointDescriptor_MAXBULKSIZE_FS), + .bInterval = 0x00, + }, + // Notification endpoint descriptor + { + .bLength = sizeof(USBEndpointDescriptor), + .bDescriptorType = USBGenericDescriptor_ENDPOINT, + .bEndpointAddress = + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, + CCID_EPT_NOTIFICATION), + .bmAttributes = USBEndpointDescriptor_INTERRUPT, + .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( + CCID_EPT_NOTIFICATION), + USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), + .bInterval = 0x10, + }, + + /* Communication class interface standard descriptor */ + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + 1, /* This is interface #1 */ + 0, /* This is alternate setting #0 for this interface */ + 3, /* Number of endpoints */ + 0xff, + 0, + 0, + PHONE_CONF_STR, /* string descriptor for this interface */ + } + , + /* Bulk-OUT endpoint standard descriptor */ + { + sizeof(USBEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, + PHONE_DATAOUT), + USBEndpointDescriptor_BULK, + MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT), + USBEndpointDescriptor_MAXBULKSIZE_FS), + 0 /* Must be 0 for full-speed bulk endpoints */ + } + , + /* Bulk-IN endpoint descriptor */ + { + sizeof(USBEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, + PHONE_DATAIN), + USBEndpointDescriptor_BULK, + MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN), + USBEndpointDescriptor_MAXBULKSIZE_FS), + 0 /* Must be 0 for full-speed bulk endpoints */ + } + , + /* Notification endpoint descriptor */ + { + sizeof(USBEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, PHONE_INT), + USBEndpointDescriptor_INTERRUPT, + MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT), + USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), + 0x10} }; #endif /* HAVE_CARDEM */ const USBConfigurationDescriptor *configurationDescriptorsArr[] = { #ifdef HAVE_SNIFFER - &configurationDescriptorSniffer.configuration, + &configurationDescriptorSniffer.configuration, #endif #ifdef HAVE_CCID - &configurationDescriptorCCID.configuration, + &configurationDescriptorCCID.configuration, #endif #ifdef HAVE_CARDEM - &configurationDescriptorPhone.configuration, + &configurationDescriptorPhone.configuration, #endif #ifdef HAVE_MITM - &configurationDescriptorMITM.configuration, + &configurationDescriptorMITM.configuration, #endif }; /** Standard USB device descriptor for the CDC serial driver */ const USBDeviceDescriptor deviceDescriptor = { - - sizeof(USBDeviceDescriptor), - USBGenericDescriptor_DEVICE, - USBDeviceDescriptor_USB2_00, - 0xff, -// CDCDeviceDescriptor_CLASS, - 0xff, -// CDCDeviceDescriptor_SUBCLASS, - 0xff, -// CDCDeviceDescriptor_PROTOCOL, - BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0), - SIMTRACE_VENDOR_ID, - SIMTRACE_PRODUCT_ID, - 1, /* Release number */ - MANUF_STR, /* Indesx of manufacturer string descriptor */ - PRODUCT_STRING, /* Index of product string descriptor */ - 0, /* No string descriptor for serial number */ - ARRAY_SIZE(configurationDescriptorsArr) /* Device has N possible configs */ + .bLength = sizeof(USBDeviceDescriptor), + .bDescriptorType = USBGenericDescriptor_DEVICE, + .bcdUSB = USBDeviceDescriptor_USB2_00, + .bDeviceClass = 0xff, + .bDeviceSubClass = 0xff, + .bDeviceProtocol = 0xff, + .bMaxPacketSize0 = BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0), + .idVendor = SIMTRACE_VENDOR_ID, + .idProduct = SIMTRACE_PRODUCT_ID, + .bcdDevice = 2, /* Release number */ + .iManufacturer = MANUF_STR, + .iProduct = PRODUCT_STRING, + .iSerialNumber = 0, + .bNumConfigurations = ARRAY_SIZE(configurationDescriptorsArr), }; /* AT91SAM3S only supports full speed, but not high speed USB */ static const USBDDriverDescriptors driverDescriptors = { - &deviceDescriptor, - (const USBConfigurationDescriptor **) &(configurationDescriptorsArr), /* first full-speed configuration descriptor */ - 0, /* No full-speed device qualifier descriptor */ - 0, /* No full-speed other speed configuration */ - 0, /* No high-speed device descriptor */ - 0, /* No high-speed configuration descriptor */ - 0, /* No high-speed device qualifier descriptor */ - 0, /* No high-speed other speed configuration descriptor */ - stringDescriptors, - STRING_DESC_CNT /* cnt string descriptors in list */ + &deviceDescriptor, + (const USBConfigurationDescriptor **)&(configurationDescriptorsArr), /* first full-speed configuration descriptor */ + 0, /* No full-speed device qualifier descriptor */ + 0, /* No full-speed other speed configuration */ + 0, /* No high-speed device descriptor */ + 0, /* No high-speed configuration descriptor */ + 0, /* No high-speed device qualifier descriptor */ + 0, /* No high-speed other speed configuration descriptor */ + stringDescriptors, + STRING_DESC_CNT /* cnt string descriptors in list */ }; - /*---------------------------------------------------------------------------- - * Functions + * Functions *----------------------------------------------------------------------------*/ /** @@ -766,31 +778,29 @@ static const USBDDriverDescriptors driverDescriptors = { */ static void _ConfigureUsbClock(void) { - /* Enable PLLB for USB */ - PMC->CKGR_PLLBR = CKGR_PLLBR_DIVB(5) - | CKGR_PLLBR_MULB(0xc) /* MULT+1=0xd*/ - | CKGR_PLLBR_PLLBCOUNT_Msk; - while((PMC->PMC_SR & PMC_SR_LOCKB) == 0); - /* USB Clock uses PLLB */ - PMC->PMC_USB = PMC_USB_USBDIV(0) /* /1 (no divider) */ - | PMC_USB_USBS; /* PLLB */ + /* Enable PLLB for USB */ + PMC->CKGR_PLLBR = CKGR_PLLBR_DIVB(5) + | CKGR_PLLBR_MULB(0xc) /* MULT+1=0xd */ + | CKGR_PLLBR_PLLBCOUNT_Msk; + while ((PMC->PMC_SR & PMC_SR_LOCKB) == 0) ; + + /* USB Clock uses PLLB */ + PMC->PMC_USB = PMC_USB_USBDIV(0) /* /1 (no divider) */ + | PMC_USB_USBS; /* PLLB */ } - -void SIMtrace_USB_Initialize( void ) +void SIMtrace_USB_Initialize(void) { - _ConfigureUsbClock(); - // Get std USB driver - USBDDriver *pUsbd = USBD_GetDriver(); + _ConfigureUsbClock(); + // Get std USB driver + USBDDriver *pUsbd = USBD_GetDriver(); - TRACE_DEBUG("."); + TRACE_DEBUG("."); - // Initialize standard USB driver - USBDDriver_Initialize(pUsbd, - &driverDescriptors, - 0); // Multiple interface settings not supported - USBD_Init(); - USBD_Connect(); + // Initialize standard USB driver + USBDDriver_Initialize(pUsbd, &driverDescriptors, 0); // Multiple interface settings not supported + USBD_Init(); + USBD_Connect(); - NVIC_EnableIRQ( UDP_IRQn ); + NVIC_EnableIRQ(UDP_IRQn); }