📄 cciddriver.c
字号:
0x00, // Subclass is specified in interface
0x00, // Protocol is specified in interface
BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
0x01, // One possible configuration
0x00 // Reserved for future use, must be zero
};
static const CCIDDriverConfigurationDescriptors sOtherSpeedConfigurationFS = {
// Standard USB configuration descriptor
{
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
sizeof(CCIDDriverConfigurationDescriptors),
1, // One interface in this configuration
1, // This is configuration #1
0, // No 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朓N
SMART_CARD_DEVICE_CLASS,
0, // Subclass code
0, // bulk transfers optional interrupt-IN
0 // No 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_5_0, // bVoltageSupport
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_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
}
};
static const CCIDDriverConfigurationDescriptors sOtherSpeedConfigurationHS = {
// Standard USB configuration descriptor
{
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
sizeof(CCIDDriverConfigurationDescriptors),
1, // One interface in this configuration
1, // This is configuration #1
0, // No 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朓N
SMART_CARD_DEVICE_CLASS,
0, // Subclass code
0, // bulk transfers optional interrupt-IN
0 // No 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_5_0, // bVoltageSupport
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_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_HS),
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_HS),
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_HS),
0x10
}
};
#endif
//------------------------------------------------------------------------------
// Variables: String descriptors
// languageIdDescriptor - Language ID string descriptor.
// manufacturerDescriptor - Manufacturer name.
// productDescriptor - Product name.
// serialNumberDescriptor - Product serial number.
// stringDescriptors - Array of pointers to string descriptors.
//------------------------------------------------------------------------------
static const unsigned char languageIdDescriptor[] = {
USBStringDescriptor_LENGTH(1),
USBGenericDescriptor_STRING,
USBStringDescriptor_ENGLISH_US
};
static const unsigned char manufacturerDescriptor[] = {
USBStringDescriptor_LENGTH(5),
USBGenericDescriptor_STRING,
USBStringDescriptor_UNICODE('A'),
USBStringDescriptor_UNICODE('T'),
USBStringDescriptor_UNICODE('M'),
USBStringDescriptor_UNICODE('E'),
USBStringDescriptor_UNICODE('L')
};
static const unsigned char productDescriptor[] = {
USBStringDescriptor_LENGTH(23),
USBGenericDescriptor_STRING,
USBStringDescriptor_UNICODE('A'),
USBStringDescriptor_UNICODE('T'),
USBStringDescriptor_UNICODE('M'),
USBStringDescriptor_UNICODE('E'),
USBStringDescriptor_UNICODE('L'),
USBStringDescriptor_UNICODE(' '),
USBStringDescriptor_UNICODE('A'),
USBStringDescriptor_UNICODE('T'),
USBStringDescriptor_UNICODE('9'),
USBStringDescriptor_UNICODE('1'),
USBStringDescriptor_UNICODE(' '),
USBStringDescriptor_UNICODE('C'),
USBStringDescriptor_UNICODE('C'),
USBStringDescriptor_UNICODE('I'),
USBStringDescriptor_UNICODE('D'),
USBStringDescriptor_UNICODE(' '),
USBStringDescriptor_UNICODE('D'),
USBStringDescriptor_UNICODE('R'),
USBStringDescriptor_UNICODE('I'),
USBStringDescriptor_UNICODE('V'),
USBStringDescriptor_UNICODE('E'),
USBStringDescriptor_UNICODE('R'),
USBStringDescriptor_UNICODE(' ')
};
static const unsigned char serialNumberDescriptor[] = {
USBStringDescriptor_LENGTH(12),
USBGenericDescriptor_STRING,
USBStringDescriptor_UNICODE('0'),
USBStringDescriptor_UNICODE('1'),
USBStringDescriptor_UNICODE('2'),
USBStringDescriptor_UNICODE('3'),
USBStringDescriptor_UNICODE('4'),
USBStringDescriptor_UNICODE('5'),
USBStringDescriptor_UNICODE('6'),
USBStringDescriptor_UNICODE('7'),
USBStringDescriptor_UNICODE('8'),
USBStringDescriptor_UNICODE('9'),
USBStringDescriptor_UNICODE('A'),
USBStringDescriptor_UNICODE('F')
};
static const unsigned char *stringDescriptors[] = {
languageIdDescriptor,
manufacturerDescriptor,
productDescriptor,
serialNumberDescriptor
};
//------------------------------------------------------------------------------
// Variable: ccidDriverDescriptors
// List of standard descriptors for the serial driver.
//------------------------------------------------------------------------------
const USBDDriverDescriptors ccidDriverDescriptors = {
&deviceDescriptor, // FS
(USBConfigurationDescriptor *) &configurationDescriptorsFS,
#ifdef BOARD_USB_UDPHS
(USBDeviceQualifierDescriptor *) &deviceQualifierDescriptor, // FS
(USBConfigurationDescriptor *) &sOtherSpeedConfigurationFS,
&deviceDescriptor, // HS
(USBConfigurationDescriptor *) &configurationDescriptorsHS,
(USBDeviceQualifierDescriptor *) &deviceQualifierDescriptor, // HS
(USBConfigurationDescriptor *) &sOtherSpeedConfigurationHS,
#else
0, // No qualifier descriptor FS
0, // No other-speed configuration FS
0, // No device descriptor HS
0, // No configuration HS
0, // No qualifier descriptor HS
0, // No other-speed configuration HS
#endif
stringDescriptors,
4 // Four string descriptors in array
};
//------------------------------------------------------------------------------
// Internal functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Return the Slot Status to the host
/// Answer to:
/// PC_to_RDR_IccPowerOff
/// PC_to_RDR_GetSlotStatus
/// PC_to_RDR_IccClock
/// PC_to_RDR_T0APDU
/// PC_to_RDR_Mechanical
/// PC_to_RDR_Abort and Class specific ABORT request
/// \param
//------------------------------------------------------------------------------
static void RDRtoPCSlotStatus( void )
{
trace_LOG(trace_DEBUG, "RDRtoPCSlotStatus\n\r");
// Header fields settings
ccidDriver.sCcidMessage.bMessageType = RDR_TO_PC_SLOTSTATUS;
ccidDriver.sCcidMessage.wLength = 0;
ccidDriver.sCcidMessage.bStatus = ccidDriver.SlotStatus;
ccidDriver.sCcidMessage.bError = 0;
// 00h Clock running
// 01h Clock stopped in state L
// 02h Clock stopped in state H
// 03h Clock stopped in an unknown state
// All other values are Reserved for Future Use.
ccidDriver.sCcidMessage.bSpecific = 0;
}
//------------------------------------------------------------------------------
/// Answer to:
/// PC_to_RDR_IccPowerOn
/// \param
//------------------------------------------------------------------------------
static void RDRtoPCDatablock_ATR( void )
{
unsigned char i;
unsigned char Atr[ATR_SIZE_MAX];
unsigned char length;
//trace_LOG(trace_DEBUG, "RDRtoPCDatablock\n\r");
ISO7816_Datablock_ATR( Atr, &length );
if( length > 5 ) {
ccidDriver.ProtocolDataStructure[1] = Atr[5]&0x0F; // TD(1)
ccidDriver.bProtocol = Atr[5]&0x0F; // TD(1)
}
// S_ccid_protocol_t0
// bmFindexDindex
ccidDriver.ProtocolDataStructure[0] = Atr[2]; // TA(1)
// bmTCCKST0
// For T=0 ,B0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -