mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-23 00:38:33 +03:00
convert all src_simtrace code to kernel coding style
Let's use the Osmocom standard, based on the Linux kernel standard: tab-indent and 8-charracter tab width.
This commit is contained in:
@@ -46,22 +46,28 @@
|
|||||||
/** Maximum ATR ucSize in bytes.*/
|
/** Maximum ATR ucSize in bytes.*/
|
||||||
#define MAX_ATR_SIZE 55
|
#define MAX_ATR_SIZE 55
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* Internal variables
|
* Internal variables
|
||||||
*------------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/** ISO7816 pins */
|
/** ISO7816 pins */
|
||||||
static const Pin pinsISO7816[] = { PINS_ISO7816 };
|
static const Pin pinsISO7816[] = { PINS_ISO7816 };
|
||||||
|
|
||||||
/** Bus switch pins */
|
/** Bus switch pins */
|
||||||
static const Pin pinsBus[] = { PINS_BUS_DEFAULT };
|
static const Pin pinsBus[] = { PINS_BUS_DEFAULT };
|
||||||
|
|
||||||
/* SIMcard power pin */
|
/* SIMcard power pin */
|
||||||
static const Pin pinsPower[] = { PWR_PINS };
|
static const Pin pinsPower[] = { PWR_PINS };
|
||||||
|
|
||||||
/** ISO7816 RST pin */
|
/** ISO7816 RST pin */
|
||||||
static const Pin pinIso7816RstMC = PIN_ISO7816_RSTMC;
|
static const Pin pinIso7816RstMC = PIN_ISO7816_RSTMC;
|
||||||
static uint8_t sim_inserted = 0;
|
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
|
* Optional smartcard detection
|
||||||
@@ -91,14 +97,11 @@ Output:
|
|||||||
// if ( (pinSmartCard.pio->PIO_ISR & pinSmartCard.mask) != 0 )
|
// if ( (pinSmartCard.pio->PIO_ISR & pinSmartCard.mask) != 0 )
|
||||||
{
|
{
|
||||||
/* Check current level on pin */
|
/* Check current level on pin */
|
||||||
if ( PIO_Get( &pinSmartCard ) == 0 )
|
if (PIO_Get(&pinSmartCard) == 0) {
|
||||||
{
|
|
||||||
sim_inserted = 1;
|
sim_inserted = 1;
|
||||||
printf("-I- Smartcard inserted\n\r");
|
printf("-I- Smartcard inserted\n\r");
|
||||||
CCID_Insertion();
|
CCID_Insertion();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sim_inserted = 0;
|
sim_inserted = 0;
|
||||||
printf("-I- Smartcard removed\n\r");
|
printf("-I- Smartcard removed\n\r");
|
||||||
CCID_Removal();
|
CCID_Removal();
|
||||||
@@ -122,13 +125,15 @@ static void ConfigureCardDetection( void )
|
|||||||
*-----------------------------------------------------------------------------*/
|
*-----------------------------------------------------------------------------*/
|
||||||
extern CCIDDriverConfigurationDescriptors configurationDescriptorCCID;
|
extern CCIDDriverConfigurationDescriptors configurationDescriptorCCID;
|
||||||
|
|
||||||
void CCID_configure ( void ) {
|
void CCID_configure(void)
|
||||||
|
{
|
||||||
CCIDDriver_Initialize();
|
CCIDDriver_Initialize();
|
||||||
// FIXME: Do we need to set priority?: NVIC_SetPriority( PIOA_IRQn, 10);
|
// 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 ) {
|
void CCID_exit(void)
|
||||||
|
{
|
||||||
PIO_DisableIt(&pinSmartCard);
|
PIO_DisableIt(&pinSmartCard);
|
||||||
USART_SetTransmitterEnabled(usart_info.base, 0);
|
USART_SetTransmitterEnabled(usart_info.base, 0);
|
||||||
USART_SetReceiverEnabled(usart_info.base, 0);
|
USART_SetReceiverEnabled(usart_info.base, 0);
|
||||||
|
|||||||
@@ -55,12 +55,11 @@ static const conf_func config_func_ptrs[] = {
|
|||||||
.configure = MITM_configure,
|
.configure = MITM_configure,
|
||||||
.init = MITM_init,
|
.init = MITM_init,
|
||||||
.exit = MITM_exit,
|
.exit = MITM_exit,
|
||||||
.run = MITM_run
|
.run = MITM_run,
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* Internal variables
|
* Internal variables
|
||||||
*------------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------------*/
|
||||||
@@ -72,7 +71,6 @@ static volatile enum confNum simtrace_config = CFG_NUM_PHONE;
|
|||||||
static volatile enum confNum simtrace_config = CFG_NUM_CCID;
|
static volatile enum confNum simtrace_config = CFG_NUM_CCID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
* Callbacks
|
* Callbacks
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
@@ -109,15 +107,16 @@ extern int main( void )
|
|||||||
TRACE_INFO("USB init...\n\r");
|
TRACE_INFO("USB init...\n\r");
|
||||||
while (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
while (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
||||||
if (i >= MAX_USB_ITER * 3) {
|
if (i >= MAX_USB_ITER * 3) {
|
||||||
TRACE_ERROR("Resetting board (USB could not be configured)\n");
|
TRACE_ERROR("Resetting board (USB could "
|
||||||
|
"not be configured)\n");
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE_DEBUG("calling configure of all configurations...\n\r");
|
TRACE_DEBUG("calling configure of all configurations...\n\r");
|
||||||
for (i = 1; i < sizeof(config_func_ptrs)/sizeof(config_func_ptrs[0]); ++i)
|
for (i = 1; i < sizeof(config_func_ptrs) / sizeof(config_func_ptrs[0]);
|
||||||
{
|
++i) {
|
||||||
if (config_func_ptrs[i].configure)
|
if (config_func_ptrs[i].configure)
|
||||||
config_func_ptrs[i].configure();
|
config_func_ptrs[i].configure();
|
||||||
}
|
}
|
||||||
@@ -137,8 +136,7 @@ extern int main( void )
|
|||||||
if (isUsbConnected) {
|
if (isUsbConnected) {
|
||||||
isUsbConnected = 0;
|
isUsbConnected = 0;
|
||||||
}
|
}
|
||||||
}
|
} else if (isUsbConnected == 0) {
|
||||||
else if (isUsbConnected == 0) {
|
|
||||||
TRACE_INFO("USB is now configured\n\r");
|
TRACE_INFO("USB is now configured\n\r");
|
||||||
LED_Set(LED_NUM_GREEN);
|
LED_Set(LED_NUM_GREEN);
|
||||||
LED_Clear(LED_NUM_RED);
|
LED_Clear(LED_NUM_RED);
|
||||||
@@ -146,7 +144,8 @@ extern int main( void )
|
|||||||
isUsbConnected = 1;
|
isUsbConnected = 1;
|
||||||
}
|
}
|
||||||
if (last_simtrace_config != simtrace_config) {
|
if (last_simtrace_config != simtrace_config) {
|
||||||
TRACE_INFO("USB config chg %u -> %u\r\n", 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[last_simtrace_config].exit();
|
||||||
config_func_ptrs[simtrace_config].init();
|
config_func_ptrs[simtrace_config].init();
|
||||||
last_simtrace_config = simtrace_config;
|
last_simtrace_config = simtrace_config;
|
||||||
|
|||||||
@@ -37,7 +37,6 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
static const Pin pins_bus[] = { PINS_BUS_DEFAULT };
|
static const Pin pins_bus[] = { PINS_BUS_DEFAULT };
|
||||||
|
|
||||||
void MITM_configure(void)
|
void MITM_configure(void)
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ unsigned char USBState = STATE_IDLE;
|
|||||||
|
|
||||||
/** ISO7816 pins */
|
/** ISO7816 pins */
|
||||||
static const Pin pinsISO7816_PHONE[] = { PINS_ISO7816_PHONE };
|
static const Pin pinsISO7816_PHONE[] = { PINS_ISO7816_PHONE };
|
||||||
|
|
||||||
/** Bus switch pins */
|
/** Bus switch pins */
|
||||||
|
|
||||||
#if DEBUG_PHONE_SNIFF
|
#if DEBUG_PHONE_SNIFF
|
||||||
@@ -86,7 +87,11 @@ static const Pin pPwr[] = {
|
|||||||
|
|
||||||
const Pin pinPhoneRST = PIN_ISO7816_RST_PHONE;
|
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 */
|
/* Taken from iso7816_4.c */
|
||||||
@@ -102,14 +107,18 @@ static uint8_t host_to_sim_buf[BUFLEN];
|
|||||||
static bool change_fidi = false;
|
static bool change_fidi = false;
|
||||||
|
|
||||||
static void receive_from_host(void);
|
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 sendResponse_to_phone(uint8_t * pArg, uint8_t status,
|
||||||
|
uint32_t transferred, uint32_t remaining)
|
||||||
{
|
{
|
||||||
if (status != USBD_STATUS_SUCCESS) {
|
if (status != USBD_STATUS_SUCCESS) {
|
||||||
TRACE_ERROR("USB err status: %d (%s)\n", __FUNCTION__, status);
|
TRACE_ERROR("USB err status: %d (%s)\n", __FUNCTION__, status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TRACE_DEBUG("sendResp, stat: %X, trnsf: %x, rem: %x\n\r", status, transferred, remaining);
|
TRACE_DEBUG("sendResp, stat: %X, trnsf: %x, rem: %x\n\r", status,
|
||||||
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]);
|
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_SetReceiverEnabled(USART_PHONE, 0);
|
||||||
USART_SetTransmitterEnabled(USART_PHONE, 1);
|
USART_SetTransmitterEnabled(USART_PHONE, 1);
|
||||||
@@ -138,19 +147,23 @@ static void sendResponse_to_phone( uint8_t *pArg, uint8_t status, uint32_t trans
|
|||||||
static void receive_from_host()
|
static void receive_from_host()
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
if ((ret = USBD_Read(PHONE_DATAOUT, &host_to_sim_buf, sizeof(host_to_sim_buf),
|
if ((ret = USBD_Read(PHONE_DATAOUT, &host_to_sim_buf,
|
||||||
(TransferCallback)&sendResponse_to_phone, 0)) == USBD_STATUS_SUCCESS) {
|
sizeof(host_to_sim_buf),
|
||||||
|
(TransferCallback) &sendResponse_to_phone,
|
||||||
|
0)) == USBD_STATUS_SUCCESS) {
|
||||||
} else {
|
} else {
|
||||||
TRACE_ERROR("USB Err: %X\n", ret);
|
TRACE_ERROR("USB Err: %X\n", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Phone_configure( void ) {
|
void Phone_configure(void)
|
||||||
|
{
|
||||||
PIO_ConfigureIt(&pinPhoneRST, ISR_PhoneRST);
|
PIO_ConfigureIt(&pinPhoneRST, ISR_PhoneRST);
|
||||||
NVIC_EnableIRQ(PIOA_IRQn);
|
NVIC_EnableIRQ(PIOA_IRQn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Phone_exit( void ) {
|
void Phone_exit(void)
|
||||||
|
{
|
||||||
PIO_DisableIt(&pinPhoneRST);
|
PIO_DisableIt(&pinPhoneRST);
|
||||||
NVIC_DisableIRQ(USART1_IRQn);
|
NVIC_DisableIRQ(USART1_IRQn);
|
||||||
USART_DisableIt(USART_PHONE, US_IER_RXRDY);
|
USART_DisableIt(USART_PHONE, US_IER_RXRDY);
|
||||||
@@ -158,7 +171,8 @@ void Phone_exit( void ) {
|
|||||||
USART_SetReceiverEnabled(USART_PHONE, 0);
|
USART_SetReceiverEnabled(USART_PHONE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Phone_init( void ) {
|
void Phone_init(void)
|
||||||
|
{
|
||||||
PIO_Configure(pinsISO7816_PHONE, PIO_LISTSIZE(pinsISO7816_PHONE));
|
PIO_Configure(pinsISO7816_PHONE, PIO_LISTSIZE(pinsISO7816_PHONE));
|
||||||
PIO_Configure(pins_bus, PIO_LISTSIZE(pins_bus));
|
PIO_Configure(pins_bus, PIO_LISTSIZE(pins_bus));
|
||||||
|
|
||||||
|
|||||||
@@ -46,18 +46,19 @@ volatile ringbuf sim_rcv_buf = { {0}, 0, 0 };
|
|||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
* Interrupt routines
|
* 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");
|
printf("rstCB\n\r");
|
||||||
PIO_EnableIt(&pinPhoneRST);
|
PIO_EnableIt(&pinPhoneRST);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ISR_PhoneRST(const Pin * pPin)
|
void ISR_PhoneRST(const Pin * pPin)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
// FIXME: no printfs in ISRs?
|
// FIXME: no printfs in ISRs?
|
||||||
printf("+++ Int!! %x\n\r", pinPhoneRST.pio->PIO_ISR);
|
printf("+++ Int!! %x\n\r", pinPhoneRST.pio->PIO_ISR);
|
||||||
if ( ((pinPhoneRST.pio->PIO_ISR & pinPhoneRST.mask) != 0) )
|
if (((pinPhoneRST.pio->PIO_ISR & pinPhoneRST.mask) != 0)) {
|
||||||
{
|
|
||||||
if (PIO_Get(&pinPhoneRST) == 0) {
|
if (PIO_Get(&pinPhoneRST) == 0) {
|
||||||
printf(" 0 ");
|
printf(" 0 ");
|
||||||
} else {
|
} else {
|
||||||
@@ -65,7 +66,10 @@ void ISR_PhoneRST( const Pin *pPin)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = USBD_Write( PHONE_INT, "R", 1, (TransferCallback)&Callback_PhoneRST_ISR, 0 )) != USBD_STATUS_SUCCESS) {
|
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__);
|
TRACE_ERROR("USB err status: %d (%s)\n", ret, __FUNCTION__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
/** ISO7816 pins */
|
/** ISO7816 pins */
|
||||||
static const Pin pinsISO7816_sniff[] = { PINS_SIM_SNIFF_SIM };
|
static const Pin pinsISO7816_sniff[] = { PINS_SIM_SNIFF_SIM };
|
||||||
static const Pin pins_bus[] = { PINS_BUS_SNIFF };
|
static const Pin pins_bus[] = { PINS_BUS_SNIFF };
|
||||||
|
|
||||||
static const Pin pPwr[] = {
|
static const Pin pPwr[] = {
|
||||||
/* Enable power converter 4.5-6V to 3.3V; low: off */
|
/* Enable power converter 4.5-6V to 3.3V; low: off */
|
||||||
{SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT},
|
{SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT},
|
||||||
@@ -60,22 +61,29 @@ static const Pin pPwr[] = {
|
|||||||
{VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
|
{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
|
* Initialization routine
|
||||||
*-----------------------------------------------------------------------------*/
|
*-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void Sniffer_configure( void ){
|
void Sniffer_configure(void)
|
||||||
|
{
|
||||||
TRACE_INFO("Sniffer config\n");
|
TRACE_INFO("Sniffer config\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sniffer_exit( void ){
|
void Sniffer_exit(void)
|
||||||
|
{
|
||||||
TRACE_INFO("Sniffer exit\n");
|
TRACE_INFO("Sniffer exit\n");
|
||||||
USART_DisableIt(USART_PHONE, US_IER_RXRDY);
|
USART_DisableIt(USART_PHONE, US_IER_RXRDY);
|
||||||
NVIC_DisableIRQ(USART1_IRQn);
|
NVIC_DisableIRQ(USART1_IRQn);
|
||||||
USART_SetReceiverEnabled(USART_PHONE, 0);
|
USART_SetReceiverEnabled(USART_PHONE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sniffer_init(void)
|
void Sniffer_init(void)
|
||||||
{
|
{
|
||||||
TRACE_INFO("Sniffer Init\n");
|
TRACE_INFO("Sniffer Init\n");
|
||||||
|
|||||||
@@ -41,7 +41,6 @@
|
|||||||
* USB String descriptors
|
* USB String descriptors
|
||||||
*------------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
static const unsigned char langDesc[] = {
|
static const unsigned char langDesc[] = {
|
||||||
|
|
||||||
USBStringDescriptor_LENGTH(1),
|
USBStringDescriptor_LENGTH(1),
|
||||||
@@ -156,7 +155,6 @@ const unsigned char phoneConfigStringDescriptor[] = {
|
|||||||
USBStringDescriptor_UNICODE('e'),
|
USBStringDescriptor_UNICODE('e'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const unsigned char MITMConfigStringDescriptor[] = {
|
const unsigned char MITMConfigStringDescriptor[] = {
|
||||||
|
|
||||||
USBStringDescriptor_LENGTH(13),
|
USBStringDescriptor_LENGTH(13),
|
||||||
@@ -225,8 +223,15 @@ const unsigned char cardem_usim2_intf_str[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum strDescNum {
|
enum strDescNum {
|
||||||
PRODUCT_STRING = 1, MANUF_STR, SNIFFER_CONF_STR, CCID_CONF_STR, PHONE_CONF_STR, MITM_CONF_STR,
|
PRODUCT_STRING = 1,
|
||||||
CARDEM_USIM1_INTF_STR, CARDEM_USIM2_INTF_STR, STRING_DESC_CNT
|
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 */
|
/** List of string descriptors used by the device */
|
||||||
@@ -258,180 +263,174 @@ typedef struct _SIMTraceDriverConfigurationDescriptorSniffer {
|
|||||||
|
|
||||||
} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorSniffer;
|
} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorSniffer;
|
||||||
|
|
||||||
static const SIMTraceDriverConfigurationDescriptorSniffer configurationDescriptorSniffer = {
|
static const SIMTraceDriverConfigurationDescriptorSniffer
|
||||||
|
configurationDescriptorSniffer = {
|
||||||
/* Standard configuration descriptor */
|
/* Standard configuration descriptor */
|
||||||
{
|
{
|
||||||
sizeof(USBConfigurationDescriptor),
|
.bLength = sizeof(USBConfigurationDescriptor),
|
||||||
USBGenericDescriptor_CONFIGURATION,
|
.bDescriptorType = USBGenericDescriptor_CONFIGURATION,
|
||||||
sizeof(SIMTraceDriverConfigurationDescriptorSniffer),
|
.wTotalLength = sizeof(SIMTraceDriverConfigurationDescriptorSniffer),
|
||||||
1, /* There is one interface in this configuration */
|
.bNumInterfaces = 1,
|
||||||
CFG_NUM_SNIFF, /* configuration number */
|
.bConfigurationValue = CFG_NUM_SNIFF,
|
||||||
SNIFFER_CONF_STR, /* string descriptor for this configuration */
|
.iConfiguration = SNIFFER_CONF_STR,
|
||||||
USBD_BMATTRIBUTES,
|
.bmAttributes = USBD_BMATTRIBUTES,
|
||||||
USBConfigurationDescriptor_POWER(100)
|
.bMaxPower = USBConfigurationDescriptor_POWER(100),
|
||||||
},
|
},
|
||||||
/* Communication class interface standard descriptor */
|
/* Communication class interface standard descriptor */
|
||||||
{
|
{
|
||||||
sizeof(USBInterfaceDescriptor),
|
.bLength = sizeof(USBInterfaceDescriptor),
|
||||||
USBGenericDescriptor_INTERFACE,
|
.bDescriptorType = USBGenericDescriptor_INTERFACE,
|
||||||
0, /* This is interface #0 */
|
.bInterfaceNumber = 0,
|
||||||
0, /* This is alternate setting #0 for this interface */
|
.bAlternateSetting = 0,
|
||||||
3, /* Number of endpoints */
|
.bNumEndpoints = 3,
|
||||||
0xff, /* Descriptor Class: Vendor specific */
|
.bInterfaceClass = 0xff,
|
||||||
0, /* No subclass */
|
.bInterfaceSubClass = 0,
|
||||||
0, /* No l */
|
.bInterfaceProtocol = 0,
|
||||||
SNIFFER_CONF_STR /* Third in string descriptor for this interface */
|
.iInterface = SNIFFER_CONF_STR,
|
||||||
},
|
},
|
||||||
/* Bulk-OUT endpoint standard descriptor */
|
/* Bulk-OUT endpoint standard descriptor */
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
.bLength = sizeof(USBEndpointDescriptor),
|
||||||
USBGenericDescriptor_ENDPOINT,
|
.bDescriptorType = USBGenericDescriptor_ENDPOINT,
|
||||||
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
|
.bEndpointAddress = USBEndpointDescriptor_ADDRESS(
|
||||||
|
USBEndpointDescriptor_OUT,
|
||||||
|
PHONE_DATAOUT),
|
||||||
|
.bmAttributes = USBEndpointDescriptor_BULK,
|
||||||
|
.wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
|
||||||
PHONE_DATAOUT),
|
PHONE_DATAOUT),
|
||||||
USBEndpointDescriptor_BULK,
|
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT),
|
|
||||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||||
0 /* Must be 0 for full-speed bulk endpoints */
|
.bInterval = 0,
|
||||||
},
|
},
|
||||||
/* Bulk-IN endpoint descriptor */
|
/* Bulk-IN endpoint descriptor */
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
.bLength = sizeof(USBEndpointDescriptor),
|
||||||
USBGenericDescriptor_ENDPOINT,
|
.bDescriptorType = USBGenericDescriptor_ENDPOINT,
|
||||||
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
|
.bEndpointAddress = USBEndpointDescriptor_ADDRESS(
|
||||||
|
USBEndpointDescriptor_IN,
|
||||||
|
PHONE_DATAIN),
|
||||||
|
.bmAttributes = USBEndpointDescriptor_BULK,
|
||||||
|
.wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
|
||||||
PHONE_DATAIN),
|
PHONE_DATAIN),
|
||||||
USBEndpointDescriptor_BULK,
|
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN),
|
|
||||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||||
0 /* Must be 0 for full-speed bulk endpoints */
|
.bInterval = 0,
|
||||||
},
|
},
|
||||||
// Notification endpoint descriptor
|
// Notification endpoint descriptor
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
.bLength = sizeof(USBEndpointDescriptor),
|
||||||
USBGenericDescriptor_ENDPOINT,
|
.bDescriptorType = USBGenericDescriptor_ENDPOINT,
|
||||||
USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, PHONE_INT ),
|
.bEndpointAddress = USBEndpointDescriptor_ADDRESS(
|
||||||
USBEndpointDescriptor_INTERRUPT,
|
USBEndpointDescriptor_IN,
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT),
|
PHONE_INT),
|
||||||
|
.bmAttributes = USBEndpointDescriptor_INTERRUPT,
|
||||||
|
.wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
|
||||||
|
PHONE_INT),
|
||||||
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
||||||
0x10
|
.bInterval = 0x10,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif /* HAVE_SNIFFER */
|
#endif /* HAVE_SNIFFER */
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CCID
|
#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 = {
|
static const CCIDDriverConfigurationDescriptors configurationDescriptorCCID = {
|
||||||
|
|
||||||
// Standard USB configuration descriptor
|
// Standard USB configuration descriptor
|
||||||
{
|
{
|
||||||
sizeof(USBConfigurationDescriptor),
|
.bLength = sizeof(USBConfigurationDescriptor),
|
||||||
USBGenericDescriptor_CONFIGURATION,
|
.bDescriptorType = USBGenericDescriptor_CONFIGURATION,
|
||||||
sizeof(CCIDDriverConfigurationDescriptors),
|
.wTotalLength = sizeof(CCIDDriverConfigurationDescriptors),
|
||||||
1, // One interface in this configuration
|
.bNumInterfaces = 1,
|
||||||
CFG_NUM_CCID, // This is configuration #1
|
.bConfigurationValue = CFG_NUM_CCID,
|
||||||
CCID_CONF_STR, // associated string descriptor
|
.iConfiguration = CCID_CONF_STR,
|
||||||
BOARD_USB_BMATTRIBUTES,
|
.bmAttributes = BOARD_USB_BMATTRIBUTES,
|
||||||
USBConfigurationDescriptor_POWER(100)
|
.bMaxPower = USBConfigurationDescriptor_POWER(100),
|
||||||
},
|
},
|
||||||
// CCID interface descriptor
|
// CCID interface descriptor
|
||||||
// Table 4.3-1 Interface Descriptor
|
// Table 4.3-1 Interface Descriptor
|
||||||
// Interface descriptor
|
// Interface descriptor
|
||||||
{
|
{
|
||||||
sizeof(USBInterfaceDescriptor),
|
.bLength = sizeof(USBInterfaceDescriptor),
|
||||||
USBGenericDescriptor_INTERFACE,
|
.bDescriptorType = USBGenericDescriptor_INTERFACE,
|
||||||
0, // Interface 0
|
.bInterfaceNumber = 0,
|
||||||
0, // No alternate settings
|
.bAlternateSetting = 0,
|
||||||
3, // uses bulk-IN, bulk-OUT and interrupt IN
|
.bNumEndpoints = 3,
|
||||||
SMART_CARD_DEVICE_CLASS,
|
.bInterfaceClass = SMART_CARD_DEVICE_CLASS,
|
||||||
0, // Subclass code
|
.bInterfaceSubClass = 0,
|
||||||
0, // bulk transfers optional interrupt-IN
|
.bInterfaceProtocol = 0,
|
||||||
CCID_CONF_STR // associated string descriptor
|
.iInterface = CCID_CONF_STR,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes
|
.bLength = sizeof(CCIDDescriptor),
|
||||||
CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type
|
.bDescriptorType = CCID_DECRIPTOR_TYPE,
|
||||||
CCID1_10, // bcdCCID: CCID version
|
.bcdCCID = CCID1_10, // CCID version
|
||||||
0, // bMaxSlotIndex: Value 0 indicates that one slot is supported
|
.bMaxSlotIndex = 0, // 1 slot
|
||||||
VOLTS_3_0, // bVoltageSupport
|
.bVoltageSupport = VOLTS_3_0,
|
||||||
(1 << PROTOCOL_TO), // dwProtocols
|
.dwProtocols = (1 << PROTOCOL_TO),
|
||||||
3580, // dwDefaultClock
|
.dwDefaultClock = 3580,
|
||||||
3580, // dwMaxClock
|
.dwMaximumClock = 3580,
|
||||||
0, // bNumClockSupported
|
.bNumClockSupported = 0,
|
||||||
9600, // dwDataRate : 9600 bauds
|
.dwDataRate = 9600,
|
||||||
9600, // dwMaxDataRate : 9600 bauds
|
.dwMaxDataRate = 9600,
|
||||||
0, // bNumDataRatesSupported
|
.bNumDataRatesSupported = 0,
|
||||||
0xfe, // dwMaxIFSD
|
.dwMaxIFSD = 0xfe,
|
||||||
0, // dwSynchProtocols
|
.dwSynchProtocols = 0,
|
||||||
0, // dwMechanical
|
.dwMechanical = 0,
|
||||||
//0x00010042, // dwFeatures: Short APDU level exchanges
|
.dwFeatures = CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD |
|
||||||
CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD |
|
CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO |
|
||||||
CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU,
|
CCID_FEATURES_EXC_TPDU,
|
||||||
0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10
|
.dwMaxCCIDMessageLength = 271, /* For extended APDU
|
||||||
0xFF, // bClassGetResponse: Echoes the class of the APDU
|
level the value shall
|
||||||
0xFF, // bClassEnvelope: Echoes the class of the APDU
|
be between 261 + 10 */
|
||||||
0, // wLcdLayout: no LCD
|
.bClassGetResponse = 0xFF, // Echoes the class of the APDU
|
||||||
0, // bPINSupport: No PIN
|
.bClassEnvelope = 0xFF, // Echoes the class of the APDU
|
||||||
1 // bMaxCCIDBusySlot
|
.wLcdLayout = 0, // wLcdLayout: no LCD
|
||||||
|
.bPINSupport = 0, // bPINSupport: No PIN
|
||||||
|
.bMaxCCIDBusySlots = 1,
|
||||||
},
|
},
|
||||||
// Bulk-OUT endpoint descriptor
|
// Bulk-OUT endpoint descriptor
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
.bLength = sizeof(USBEndpointDescriptor),
|
||||||
USBGenericDescriptor_ENDPOINT,
|
.bDescriptorType = USBGenericDescriptor_ENDPOINT,
|
||||||
USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ),
|
.bEndpointAddress =
|
||||||
USBEndpointDescriptor_BULK,
|
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT),
|
CCID_EPT_DATA_OUT),
|
||||||
|
.bmAttributes = USBEndpointDescriptor_BULK,
|
||||||
|
.wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
|
||||||
|
CCID_EPT_DATA_OUT),
|
||||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||||
0x00 // Does not apply to Bulk endpoints
|
.bInterval = 0x00,
|
||||||
},
|
},
|
||||||
// Bulk-IN endpoint descriptor
|
// Bulk-IN endpoint descriptor
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
.bLength = sizeof(USBEndpointDescriptor),
|
||||||
USBGenericDescriptor_ENDPOINT,
|
.bDescriptorType = USBGenericDescriptor_ENDPOINT,
|
||||||
USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ),
|
.bEndpointAddress =
|
||||||
USBEndpointDescriptor_BULK,
|
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN),
|
CCID_EPT_DATA_IN),
|
||||||
|
.bmAttributes = USBEndpointDescriptor_BULK,
|
||||||
|
.wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
|
||||||
|
CCID_EPT_DATA_IN),
|
||||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||||
0x00 // Does not apply to Bulk endpoints
|
.bInterval = 0x00,
|
||||||
},
|
},
|
||||||
// Notification endpoint descriptor
|
// Notification endpoint descriptor
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
.bLength = sizeof(USBEndpointDescriptor),
|
||||||
USBGenericDescriptor_ENDPOINT,
|
.bDescriptorType = USBGenericDescriptor_ENDPOINT,
|
||||||
USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ),
|
.bEndpointAddress =
|
||||||
USBEndpointDescriptor_INTERRUPT,
|
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION),
|
CCID_EPT_NOTIFICATION),
|
||||||
|
.bmAttributes = USBEndpointDescriptor_INTERRUPT,
|
||||||
|
.wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
|
||||||
|
CCID_EPT_NOTIFICATION),
|
||||||
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
||||||
0x10
|
.bInterval = 0x10,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
#endif /* HAVE_CCID */
|
#endif /* HAVE_CCID */
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CARDEM
|
#ifdef HAVE_CARDEM
|
||||||
/* SIM card emulator */
|
/* SIM card emulator */
|
||||||
typedef struct _SIMTraceDriverConfigurationDescriptorPhone {
|
typedef struct _SIMTraceDriverConfigurationDescriptorPhone {
|
||||||
|
/* Standard configuration descriptor. */
|
||||||
/** Standard configuration descriptor. */
|
|
||||||
USBConfigurationDescriptor configuration;
|
USBConfigurationDescriptor configuration;
|
||||||
USBInterfaceDescriptor phone;
|
USBInterfaceDescriptor phone;
|
||||||
USBEndpointDescriptor phone_dataOut;
|
USBEndpointDescriptor phone_dataOut;
|
||||||
@@ -445,7 +444,8 @@ typedef struct _SIMTraceDriverConfigurationDescriptorPhone {
|
|||||||
#endif
|
#endif
|
||||||
} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorPhone;
|
} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorPhone;
|
||||||
|
|
||||||
static const SIMTraceDriverConfigurationDescriptorPhone configurationDescriptorPhone = {
|
static const SIMTraceDriverConfigurationDescriptorPhone
|
||||||
|
configurationDescriptorPhone = {
|
||||||
/* Standard configuration descriptor */
|
/* Standard configuration descriptor */
|
||||||
{
|
{
|
||||||
sizeof(USBConfigurationDescriptor),
|
sizeof(USBConfigurationDescriptor),
|
||||||
@@ -499,7 +499,8 @@ static const SIMTraceDriverConfigurationDescriptorPhone configurationDescriptorP
|
|||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
sizeof(USBEndpointDescriptor),
|
||||||
USBGenericDescriptor_ENDPOINT,
|
USBGenericDescriptor_ENDPOINT,
|
||||||
USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, PHONE_INT ),
|
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
|
||||||
|
PHONE_INT),
|
||||||
USBEndpointDescriptor_INTERRUPT,
|
USBEndpointDescriptor_INTERRUPT,
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT),
|
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT),
|
||||||
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
||||||
@@ -528,7 +529,8 @@ static const SIMTraceDriverConfigurationDescriptorPhone configurationDescriptorP
|
|||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAOUT),
|
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAOUT),
|
||||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||||
0 /* Must be 0 for full-speed bulk endpoints */
|
0 /* Must be 0 for full-speed bulk endpoints */
|
||||||
},
|
}
|
||||||
|
,
|
||||||
/* Bulk-IN endpoint descriptor */
|
/* Bulk-IN endpoint descriptor */
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
sizeof(USBEndpointDescriptor),
|
||||||
@@ -544,20 +546,20 @@ static const SIMTraceDriverConfigurationDescriptorPhone configurationDescriptorP
|
|||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
sizeof(USBEndpointDescriptor),
|
||||||
USBGenericDescriptor_ENDPOINT,
|
USBGenericDescriptor_ENDPOINT,
|
||||||
USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CARDEM_USIM2_INT ),
|
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
|
||||||
|
CARDEM_USIM2_INT),
|
||||||
USBEndpointDescriptor_INTERRUPT,
|
USBEndpointDescriptor_INTERRUPT,
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_INT),
|
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_INT),
|
||||||
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
||||||
0x10
|
0x10
|
||||||
}
|
},
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#endif /* HAVE_CARDEM */
|
#endif /* HAVE_CARDEM */
|
||||||
|
|
||||||
#ifdef HAVE_MITM
|
#ifdef HAVE_MITM
|
||||||
typedef struct _SIMTraceDriverConfigurationDescriptorMITM {
|
typedef struct _SIMTraceDriverConfigurationDescriptorMITM {
|
||||||
|
/* Standard configuration descriptor. */
|
||||||
/** Standard configuration descriptor. */
|
|
||||||
USBConfigurationDescriptor configuration;
|
USBConfigurationDescriptor configuration;
|
||||||
USBInterfaceDescriptor simcard;
|
USBInterfaceDescriptor simcard;
|
||||||
/// CCID descriptor
|
/// CCID descriptor
|
||||||
@@ -576,7 +578,8 @@ typedef struct _SIMTraceDriverConfigurationDescriptorMITM {
|
|||||||
|
|
||||||
} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorMITM;
|
} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorMITM;
|
||||||
|
|
||||||
static const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorMITM = {
|
static const SIMTraceDriverConfigurationDescriptorMITM
|
||||||
|
configurationDescriptorMITM = {
|
||||||
/* Standard configuration descriptor */
|
/* Standard configuration descriptor */
|
||||||
{
|
{
|
||||||
sizeof(USBConfigurationDescriptor),
|
sizeof(USBConfigurationDescriptor),
|
||||||
@@ -592,72 +595,84 @@ static const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorMI
|
|||||||
// Table 4.3-1 Interface Descriptor
|
// Table 4.3-1 Interface Descriptor
|
||||||
// Interface descriptor
|
// Interface descriptor
|
||||||
{
|
{
|
||||||
sizeof(USBInterfaceDescriptor),
|
.bLength = sizeof(USBInterfaceDescriptor),
|
||||||
USBGenericDescriptor_INTERFACE,
|
.bDescriptorType = USBGenericDescriptor_INTERFACE,
|
||||||
0, // Interface 0
|
.bInterfaceNumber = 0,
|
||||||
0, // No alternate settings
|
.bAlternateSetting = 0,
|
||||||
3, // uses bulk-IN, bulk-OUT and interrupt IN
|
.bNumEndpoints = 3,
|
||||||
SMART_CARD_DEVICE_CLASS,
|
.bInterfaceClass = SMART_CARD_DEVICE_CLASS,
|
||||||
0, // Subclass code
|
.bInterfaceSubClass = 0,
|
||||||
0, // bulk transfers optional interrupt-IN
|
.bInterfaceProtocol = 0,
|
||||||
CCID_CONF_STR // associated string descriptor
|
.iInterface = CCID_CONF_STR,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes
|
.bLength = sizeof(CCIDDescriptor),
|
||||||
CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type
|
.bDescriptorType = CCID_DECRIPTOR_TYPE,
|
||||||
CCID1_10, // bcdCCID: CCID version
|
.bcdCCID = CCID1_10, // CCID version
|
||||||
0, // bMaxSlotIndex: Value 0 indicates that one slot is supported
|
.bMaxSlotIndex = 0, // 1 slot
|
||||||
VOLTS_3_0, // bVoltageSupport
|
.bVoltageSupport = VOLTS_3_0,
|
||||||
(1 << PROTOCOL_TO), // dwProtocols
|
.dwProtocols = (1 << PROTOCOL_TO),
|
||||||
3580, // dwDefaultClock
|
.dwDefaultClock = 3580,
|
||||||
3580, // dwMaxClock
|
.dwMaximumClock = 3580,
|
||||||
0, // bNumClockSupported
|
.bNumClockSupported = 0,
|
||||||
9600, // dwDataRate : 9600 bauds
|
.dwDataRate = 9600,
|
||||||
9600, // dwMaxDataRate : 9600 bauds
|
.dwMaxDataRate = 9600,
|
||||||
0, // bNumDataRatesSupported
|
.bNumDataRatesSupported = 0,
|
||||||
0xfe, // dwMaxIFSD
|
.dwMaxIFSD = 0xfe,
|
||||||
0, // dwSynchProtocols
|
.dwSynchProtocols = 0,
|
||||||
0, // dwMechanical
|
.dwMechanical = 0,
|
||||||
//0x00010042, // dwFeatures: Short APDU level exchanges
|
.dwFeatures = CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD |
|
||||||
CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD |
|
CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO |
|
||||||
CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU,
|
CCID_FEATURES_EXC_TPDU,
|
||||||
0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10
|
.dwMaxCCIDMessageLength = 271, /* For extended APDU
|
||||||
0xFF, // bClassGetResponse: Echoes the class of the APDU
|
level the value shall
|
||||||
0xFF, // bClassEnvelope: Echoes the class of the APDU
|
be between 261 + 10 */
|
||||||
0, // wLcdLayout: no LCD
|
.bClassGetResponse = 0xFF, // Echoes the class of the APDU
|
||||||
0, // bPINSupport: No PIN
|
.bClassEnvelope = 0xFF, // Echoes the class of the APDU
|
||||||
1 // bMaxCCIDBusySlot
|
.wLcdLayout = 0, // wLcdLayout: no LCD
|
||||||
|
.bPINSupport = 0, // bPINSupport: No PIN
|
||||||
|
.bMaxCCIDBusySlots = 1,
|
||||||
},
|
},
|
||||||
// Bulk-OUT endpoint descriptor
|
// Bulk-OUT endpoint descriptor
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
.bLength = sizeof(USBEndpointDescriptor),
|
||||||
USBGenericDescriptor_ENDPOINT,
|
.bDescriptorType = USBGenericDescriptor_ENDPOINT,
|
||||||
USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ),
|
.bEndpointAddress =
|
||||||
USBEndpointDescriptor_BULK,
|
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT),
|
CCID_EPT_DATA_OUT),
|
||||||
|
.bmAttributes = USBEndpointDescriptor_BULK,
|
||||||
|
.wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
|
||||||
|
CCID_EPT_DATA_OUT),
|
||||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||||
0x00 // Does not apply to Bulk endpoints
|
.bInterval = 0x00,
|
||||||
},
|
},
|
||||||
// Bulk-IN endpoint descriptor
|
// Bulk-IN endpoint descriptor
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
.bLength = sizeof(USBEndpointDescriptor),
|
||||||
USBGenericDescriptor_ENDPOINT,
|
.bDescriptorType = USBGenericDescriptor_ENDPOINT,
|
||||||
USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ),
|
.bEndpointAddress =
|
||||||
USBEndpointDescriptor_BULK,
|
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN),
|
CCID_EPT_DATA_IN),
|
||||||
|
.bmAttributes = USBEndpointDescriptor_BULK,
|
||||||
|
.wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
|
||||||
|
CCID_EPT_DATA_IN),
|
||||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||||
0x00 // Does not apply to Bulk endpoints
|
.bInterval = 0x00,
|
||||||
},
|
},
|
||||||
// Notification endpoint descriptor
|
// Notification endpoint descriptor
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
.bLength = sizeof(USBEndpointDescriptor),
|
||||||
USBGenericDescriptor_ENDPOINT,
|
.bDescriptorType = USBGenericDescriptor_ENDPOINT,
|
||||||
USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ),
|
.bEndpointAddress =
|
||||||
USBEndpointDescriptor_INTERRUPT,
|
USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION),
|
CCID_EPT_NOTIFICATION),
|
||||||
|
.bmAttributes = USBEndpointDescriptor_INTERRUPT,
|
||||||
|
.wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
|
||||||
|
CCID_EPT_NOTIFICATION),
|
||||||
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
||||||
0x10
|
.bInterval = 0x10,
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Communication class interface standard descriptor */
|
/* Communication class interface standard descriptor */
|
||||||
{
|
{
|
||||||
sizeof(USBInterfaceDescriptor),
|
sizeof(USBInterfaceDescriptor),
|
||||||
@@ -669,7 +684,8 @@ static const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorMI
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
PHONE_CONF_STR, /* string descriptor for this interface */
|
PHONE_CONF_STR, /* string descriptor for this interface */
|
||||||
},
|
}
|
||||||
|
,
|
||||||
/* Bulk-OUT endpoint standard descriptor */
|
/* Bulk-OUT endpoint standard descriptor */
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
sizeof(USBEndpointDescriptor),
|
||||||
@@ -680,7 +696,8 @@ static const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorMI
|
|||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT),
|
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT),
|
||||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||||
0 /* Must be 0 for full-speed bulk endpoints */
|
0 /* Must be 0 for full-speed bulk endpoints */
|
||||||
},
|
}
|
||||||
|
,
|
||||||
/* Bulk-IN endpoint descriptor */
|
/* Bulk-IN endpoint descriptor */
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
sizeof(USBEndpointDescriptor),
|
||||||
@@ -691,7 +708,8 @@ static const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorMI
|
|||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN),
|
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN),
|
||||||
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
USBEndpointDescriptor_MAXBULKSIZE_FS),
|
||||||
0 /* Must be 0 for full-speed bulk endpoints */
|
0 /* Must be 0 for full-speed bulk endpoints */
|
||||||
},
|
}
|
||||||
|
,
|
||||||
/* Notification endpoint descriptor */
|
/* Notification endpoint descriptor */
|
||||||
{
|
{
|
||||||
sizeof(USBEndpointDescriptor),
|
sizeof(USBEndpointDescriptor),
|
||||||
@@ -700,8 +718,7 @@ static const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorMI
|
|||||||
USBEndpointDescriptor_INTERRUPT,
|
USBEndpointDescriptor_INTERRUPT,
|
||||||
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT),
|
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT),
|
||||||
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
|
||||||
0x10
|
0x10}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
#endif /* HAVE_CARDEM */
|
#endif /* HAVE_CARDEM */
|
||||||
|
|
||||||
@@ -722,24 +739,20 @@ const USBConfigurationDescriptor *configurationDescriptorsArr[] = {
|
|||||||
|
|
||||||
/** Standard USB device descriptor for the CDC serial driver */
|
/** Standard USB device descriptor for the CDC serial driver */
|
||||||
const USBDeviceDescriptor deviceDescriptor = {
|
const USBDeviceDescriptor deviceDescriptor = {
|
||||||
|
.bLength = sizeof(USBDeviceDescriptor),
|
||||||
sizeof(USBDeviceDescriptor),
|
.bDescriptorType = USBGenericDescriptor_DEVICE,
|
||||||
USBGenericDescriptor_DEVICE,
|
.bcdUSB = USBDeviceDescriptor_USB2_00,
|
||||||
USBDeviceDescriptor_USB2_00,
|
.bDeviceClass = 0xff,
|
||||||
0xff,
|
.bDeviceSubClass = 0xff,
|
||||||
// CDCDeviceDescriptor_CLASS,
|
.bDeviceProtocol = 0xff,
|
||||||
0xff,
|
.bMaxPacketSize0 = BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
|
||||||
// CDCDeviceDescriptor_SUBCLASS,
|
.idVendor = SIMTRACE_VENDOR_ID,
|
||||||
0xff,
|
.idProduct = SIMTRACE_PRODUCT_ID,
|
||||||
// CDCDeviceDescriptor_PROTOCOL,
|
.bcdDevice = 2, /* Release number */
|
||||||
BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
|
.iManufacturer = MANUF_STR,
|
||||||
SIMTRACE_VENDOR_ID,
|
.iProduct = PRODUCT_STRING,
|
||||||
SIMTRACE_PRODUCT_ID,
|
.iSerialNumber = 0,
|
||||||
1, /* Release number */
|
.bNumConfigurations = ARRAY_SIZE(configurationDescriptorsArr),
|
||||||
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 */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* AT91SAM3S only supports full speed, but not high speed USB */
|
/* AT91SAM3S only supports full speed, but not high speed USB */
|
||||||
@@ -756,7 +769,6 @@ static const USBDDriverDescriptors driverDescriptors = {
|
|||||||
STRING_DESC_CNT /* cnt string descriptors in list */
|
STRING_DESC_CNT /* cnt string descriptors in list */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
@@ -771,12 +783,12 @@ static void _ConfigureUsbClock(void)
|
|||||||
| CKGR_PLLBR_MULB(0xc) /* MULT+1=0xd */
|
| CKGR_PLLBR_MULB(0xc) /* MULT+1=0xd */
|
||||||
| CKGR_PLLBR_PLLBCOUNT_Msk;
|
| CKGR_PLLBR_PLLBCOUNT_Msk;
|
||||||
while ((PMC->PMC_SR & PMC_SR_LOCKB) == 0) ;
|
while ((PMC->PMC_SR & PMC_SR_LOCKB) == 0) ;
|
||||||
|
|
||||||
/* USB Clock uses PLLB */
|
/* USB Clock uses PLLB */
|
||||||
PMC->PMC_USB = PMC_USB_USBDIV(0) /* /1 (no divider) */
|
PMC->PMC_USB = PMC_USB_USBDIV(0) /* /1 (no divider) */
|
||||||
| PMC_USB_USBS; /* PLLB */
|
| PMC_USB_USBS; /* PLLB */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SIMtrace_USB_Initialize(void)
|
void SIMtrace_USB_Initialize(void)
|
||||||
{
|
{
|
||||||
_ConfigureUsbClock();
|
_ConfigureUsbClock();
|
||||||
@@ -786,9 +798,7 @@ void SIMtrace_USB_Initialize( void )
|
|||||||
TRACE_DEBUG(".");
|
TRACE_DEBUG(".");
|
||||||
|
|
||||||
// Initialize standard USB driver
|
// Initialize standard USB driver
|
||||||
USBDDriver_Initialize(pUsbd,
|
USBDDriver_Initialize(pUsbd, &driverDescriptors, 0); // Multiple interface settings not supported
|
||||||
&driverDescriptors,
|
|
||||||
0); // Multiple interface settings not supported
|
|
||||||
USBD_Init();
|
USBD_Init();
|
||||||
USBD_Connect();
|
USBD_Connect();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user