mirror of
https://github.com/STMicroelectronics/stm32-mw-usb-device.git
synced 2026-02-08 12:08:06 -05:00
Release v2.10.0
This commit is contained in:
@@ -101,28 +101,28 @@ extern "C" {
|
||||
|
||||
#ifndef CCID_VOLTAGE_SUPP
|
||||
#define CCID_VOLTAGE_SUPP 0x07U
|
||||
#endif
|
||||
#endif /* CCID_VOLTAGE_SUPP */
|
||||
#ifndef USBD_CCID_PROTOCOL
|
||||
#define USBD_CCID_PROTOCOL 0x03U
|
||||
#endif
|
||||
#endif /* USBD_CCID_PROTOCOL */
|
||||
#ifndef USBD_CCID_DEFAULT_CLOCK_FREQ
|
||||
#define USBD_CCID_DEFAULT_CLOCK_FREQ 3600U
|
||||
#endif
|
||||
#endif /* USBD_CCID_DEFAULT_CLOCK_FREQ */
|
||||
#ifndef USBD_CCID_MAX_CLOCK_FREQ
|
||||
#define USBD_CCID_MAX_CLOCK_FREQ USBD_CCID_DEFAULT_CLOCK_FREQ
|
||||
#endif
|
||||
#endif /* USBD_CCID_MAX_CLOCK_FREQ */
|
||||
#ifndef USBD_CCID_DEFAULT_DATA_RATE
|
||||
#define USBD_CCID_DEFAULT_DATA_RATE 9677U
|
||||
#endif
|
||||
#endif /* USBD_CCID_DEFAULT_DATA_RATE */
|
||||
#ifndef USBD_CCID_MAX_DATA_RATE
|
||||
#define USBD_CCID_MAX_DATA_RATE USBD_CCID_DEFAULT_DATA_RATE
|
||||
#endif
|
||||
#endif /* USBD_CCID_MAX_DATA_RATE */
|
||||
#ifndef USBD_CCID_MAX_INF_FIELD_SIZE
|
||||
#define USBD_CCID_MAX_INF_FIELD_SIZE 254U
|
||||
#endif
|
||||
#endif /* USBD_CCID_MAX_INF_FIELD_SIZE */
|
||||
#ifndef CCID_MAX_BLOCK_SIZE_HEADER
|
||||
#define CCID_MAX_BLOCK_SIZE_HEADER 271U
|
||||
#endif
|
||||
#endif /* CCID_MAX_BLOCK_SIZE_HEADER */
|
||||
|
||||
#define TPDU_EXCHANGE 0x01U
|
||||
#define SHORT_APDU_EXCHANGE 0x02U
|
||||
@@ -131,20 +131,24 @@ extern "C" {
|
||||
|
||||
#ifndef EXCHANGE_LEVEL_FEATURE
|
||||
#define EXCHANGE_LEVEL_FEATURE TPDU_EXCHANGE
|
||||
#endif
|
||||
#endif /* EXCHANGE_LEVEL_FEATURE */
|
||||
|
||||
#define CCID_ENDPOINT_DESC_SIZE 0x07U
|
||||
|
||||
#ifndef CCID_EP0_BUFF_SIZ
|
||||
#define CCID_EP0_BUFF_SIZ 64U
|
||||
#endif
|
||||
#endif /* CCID_EP0_BUFF_SIZ */
|
||||
|
||||
#ifndef CCID_BULK_EPIN_SIZE
|
||||
#define CCID_BULK_EPIN_SIZE 64U
|
||||
#endif
|
||||
#endif /* CCID_BULK_EPIN_SIZE */
|
||||
|
||||
#define CCID_INT_BUFF_SIZ 2U
|
||||
/*---------------------------------------------------------------------*/
|
||||
/*
|
||||
* CCID Class specification revision 1.1
|
||||
* Command Pipe. Bulk Messages
|
||||
*/
|
||||
|
||||
/* CCID Bulk Out Command definitions */
|
||||
#define PC_TO_RDR_ICCPOWERON 0x62U
|
||||
@@ -213,7 +217,6 @@ typedef struct
|
||||
uint8_t datatype;
|
||||
} USBD_CCID_LineCodingTypeDef;
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bMessageType; /* Offset = 0*/
|
||||
@@ -230,10 +233,8 @@ typedef struct
|
||||
or for a TPDU T=1 block is 259 bytes,
|
||||
or for a short APDU T=1 block is 261 bytes,
|
||||
or for an extended APDU T=1 block is 65544 bytes.*/
|
||||
} USBD_CCID_BulkOut_DataTypeDef;
|
||||
#pragma pack()
|
||||
} __PACKED USBD_CCID_BulkOut_DataTypeDef;
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bMessageType; /* Offset = 0 */
|
||||
@@ -245,8 +246,7 @@ typedef struct
|
||||
uint8_t bSpecific; /* Offset = 9 */
|
||||
uint8_t abData[ABDATA_SIZE]; /* Offset = 10 */
|
||||
uint16_t u16SizeToSend;
|
||||
} USBD_CCID_BulkIn_DataTypeDef;
|
||||
#pragma pack()
|
||||
} __PACKED USBD_CCID_BulkIn_DataTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -262,6 +262,36 @@ typedef struct
|
||||
__IO uint8_t bSlot;
|
||||
} USBD_CCID_ParamTypeDef;
|
||||
|
||||
/*
|
||||
* CCID Class specification revsion 1.1
|
||||
* Smart Card Device Class Descriptor Table
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t bcdCCID;
|
||||
uint8_t bMaxSlotIndex;
|
||||
uint8_t bVoltageSupport;
|
||||
uint32_t dwProtocols;
|
||||
uint32_t dwDefaultClock;
|
||||
uint32_t dwMaximumClock;
|
||||
uint8_t bNumClockSupported;
|
||||
uint32_t dwDataRate;
|
||||
uint32_t dwMaxDataRate;
|
||||
uint8_t bNumDataRatesSupported;
|
||||
uint32_t dwMaxIFSD;
|
||||
uint32_t dwSynchProtocols;
|
||||
uint32_t dwMechanical;
|
||||
uint32_t dwFeatures;
|
||||
uint32_t dwMaxCCIDMessageLength;
|
||||
uint8_t bClassGetResponse;
|
||||
uint8_t bClassEnvelope;
|
||||
uint16_t wLcdLayout;
|
||||
uint8_t bPINSupport;
|
||||
uint8_t bMaxCCIDBusySlots;
|
||||
} __PACKED USBD_CCID_DescTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
@@ -27,11 +27,11 @@ extern "C" {
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifndef __USBD_CCID_IF_H
|
||||
#include "usbd_ccid_if_template.h"
|
||||
#endif
|
||||
#endif /* __USBD_CCID_IF_H */
|
||||
|
||||
#ifndef __USBD_CCID_SC_IF_H
|
||||
#include "usbd_ccid_sc_if_template.h"
|
||||
#endif
|
||||
#endif /* __USBD_CCID_SC_IF_H */
|
||||
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
@@ -54,6 +54,10 @@ extern "C" {
|
||||
positive number (1-127). For instance, if the CCID receives an ICC command to
|
||||
an unimplemented slot, then the Slot Error register shall be set to 5 (index of bSlot field) */
|
||||
|
||||
/*
|
||||
* CCID Class specification revsion 1.1
|
||||
*/
|
||||
|
||||
/* Following Parameters used in PC_to_RDR_XfrBlock */
|
||||
#define SLOTERROR_BAD_LENTGH 0x01U
|
||||
#define SLOTERROR_BAD_SLOT 0x05U
|
||||
@@ -97,25 +101,25 @@ extern "C" {
|
||||
/* DEFAULT_FIDI_VALUE */
|
||||
#ifndef DEFAULT_FIDI
|
||||
#define DEFAULT_FIDI 0x11U
|
||||
#endif
|
||||
#endif /* DEFAULT_FIDI */
|
||||
#ifndef DEFAULT_T01CONVCHECKSUM
|
||||
#define DEFAULT_T01CONVCHECKSUM 0x00U
|
||||
#endif
|
||||
#endif /* DEFAULT_T01CONVCHECKSUM */
|
||||
#ifndef DEFAULT_EXTRA_GUARDTIME
|
||||
#define DEFAULT_EXTRA_GUARDTIME 0x00U
|
||||
#endif
|
||||
#endif /* DEFAULT_EXTRA_GUARDTIME */
|
||||
#ifndef DEFAULT_WAITINGINTEGER
|
||||
#define DEFAULT_WAITINGINTEGER 0x0AU
|
||||
#endif
|
||||
#endif /* DEFAULT_WAITINGINTEGER */
|
||||
#ifndef DEFAULT_CLOCKSTOP
|
||||
#define DEFAULT_CLOCKSTOP 0x00U
|
||||
#endif
|
||||
#endif /* DEFAULT_CLOCKSTOP */
|
||||
#ifndef DEFAULT_IFSC
|
||||
#define DEFAULT_IFSC 0x20U
|
||||
#endif
|
||||
#endif /* DEFAULT_IFSC */
|
||||
#ifndef DEFAULT_NAD
|
||||
#define DEFAULT_NAD 0x00U
|
||||
#endif
|
||||
#endif /* DEFAULT_NAD */
|
||||
|
||||
/* Following Parameters used in PC_to_RDR_IccPowerOn */
|
||||
#define VOLTAGE_SELECTION_AUTOMATIC 0xFFU
|
||||
@@ -151,10 +155,9 @@ Offset=6 bmCommandStatus 2 bits 0, 1, 2
|
||||
#define SIZE_OF_ATR 19U
|
||||
#else
|
||||
#define SIZE_OF_ATR 15U
|
||||
#endif
|
||||
#endif /* (ATR_T01 == 0) */
|
||||
|
||||
/* defines for the CCID_CMD Layers */
|
||||
#define LEN_RDR_TO_PC_SLOTSTATUS 10U
|
||||
#define LEN_PROTOCOL_STRUCT_T0 5U
|
||||
#define LEN_PROTOCOL_STRUCT_T1 7U
|
||||
|
||||
@@ -174,8 +177,8 @@ Offset=6 bmCommandStatus 2 bits 0, 1, 2
|
||||
|
||||
#define CHK_PARAM_SLOT 0x01U
|
||||
#define CHK_PARAM_DWLENGTH 0x02U
|
||||
#define CHK_PARAM_abRFU2 0x04U
|
||||
#define CHK_PARAM_abRFU3 0x08U
|
||||
#define CHK_PARAM_ABRFU2 0x04U
|
||||
#define CHK_PARAM_ABRFU3 0x08U
|
||||
#define CHK_PARAM_CARD_PRESENT 0x10U
|
||||
#define CHK_PARAM_ABORT 0x20U
|
||||
#define CHK_ACTIVE_STATE 0x40U
|
||||
@@ -207,7 +210,7 @@ void RDR_to_PC_DataRateAndClockFrequency(uint8_t errorCode, USBD_HandleTypeDef *
|
||||
void CCID_UpdSlotStatus(USBD_HandleTypeDef *pdev, uint8_t slotStatus);
|
||||
void CCID_UpdSlotChange(USBD_HandleTypeDef *pdev, uint8_t changeStatus);
|
||||
uint8_t CCID_IsSlotStatusChange(USBD_HandleTypeDef *pdev);
|
||||
uint8_t CCID_CmdAbort(uint8_t slot, uint8_t seq);
|
||||
uint8_t CCID_CmdAbort(USBD_HandleTypeDef *pdev, uint8_t slot, uint8_t seq);
|
||||
uint8_t USBD_CCID_Transfer_Data_Request(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *dataPointer, uint16_t dataLen);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ extern "C" {
|
||||
|
||||
#ifndef __USBD_CCID_SMARTCARD_H
|
||||
#include "usbd_ccid_smartcard_template.h"
|
||||
#endif
|
||||
#endif /* __USBD_CCID_SMARTCARD_H */
|
||||
|
||||
/* Exported defines ----------------------------------------------------------*/
|
||||
|
||||
@@ -49,11 +49,11 @@ extern "C" {
|
||||
#define BOTH_DIR 2U
|
||||
|
||||
/************ Value of the Interrupt transfer status to set ******************/
|
||||
#define IntrStatus_Complete 1U
|
||||
#define IntrStatus_Reset 0U
|
||||
#define INTRSTATUS_COMPLETE 1U
|
||||
#define INTRSTATUS_RESET 0U
|
||||
/************** slot change status *******************************************/
|
||||
#define SlotStatus_Changed 1U
|
||||
#define SlotStatus_Reset 0U
|
||||
#define SLOTSTATUS_CHANGED 1U
|
||||
#define SLOTSTATUS_RESET 0U
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
extern USBD_HandleTypeDef USBD_Device;
|
||||
|
||||
@@ -30,7 +30,7 @@ extern "C" {
|
||||
|
||||
#ifndef __USBD_CCID_SMARTCARD_H
|
||||
#include "usbd_ccid_smartcard_template.h"
|
||||
#endif
|
||||
#endif /* __USBD_CCID_SMARTCARD_H */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
@@ -28,7 +28,7 @@ extern "C" {
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifndef __USBD_CCID_IF_H
|
||||
#include "usbd_ccid_if_template.h"
|
||||
#endif
|
||||
#endif /* __USBD_CCID_IF_H */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define T0_PROTOCOL 0x00U /* T0 protocol */
|
||||
@@ -162,29 +162,29 @@ typedef enum
|
||||
/* Interface Byte structure - TA(i), TB(i), TC(i) and TD(i) ------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Status; /* The Presence of the Interface byte */
|
||||
uint8_t Value; /* The Value of the Interface byte */
|
||||
} SC_InterfaceByte;
|
||||
uint8_t Status; /* The Presence of the Interface byte */
|
||||
uint8_t Value; /* The Value of the Interface byte */
|
||||
} SC_InterfaceByteTypeDef;
|
||||
|
||||
/* Protocol Level structure - ------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
SC_InterfaceByte InterfaceByte[MAX_INTERFACEBYTE]; /* The Values of the Interface byte TA(i), TB(i), TC(i)and TD(i) */
|
||||
} SC_ProtocolLevel;
|
||||
SC_InterfaceByteTypeDef InterfaceByte[MAX_INTERFACEBYTE]; /* The Values of the Interface byte
|
||||
TA(i), TB(i), TC(i)and TD(i) */
|
||||
} SC_ProtocolLevelTypeDef;
|
||||
|
||||
/* ATR structure - Answer To Reset -------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t TS; /* Bit Convention Direct/Indirect */
|
||||
uint8_t T0; /* Each bit in the high nibble = Presence of the further interface byte;
|
||||
Low nibble = Number of historical byte */
|
||||
|
||||
SC_ProtocolLevel T[MAX_PROTOCOLLEVEL]; /* Setup array */
|
||||
uint8_t H[HIST_LENGTH]; /* Historical array */
|
||||
uint8_t Tlength; /* Setup array dimension */
|
||||
uint8_t Hlength; /* Historical array dimension */
|
||||
uint8_t TS; /* Bit Convention Direct/Indirect */
|
||||
uint8_t T0; /* Each bit in the high nibble = Presence of the further interface byte;
|
||||
Low nibble = Number of historical byte */
|
||||
SC_ProtocolLevelTypeDef T[MAX_PROTOCOLLEVEL]; /* Setup array */
|
||||
uint8_t Historical[HIST_LENGTH]; /* Historical array */
|
||||
uint8_t Tlength; /* Setup array dimension */
|
||||
uint8_t Hlength; /* Historical array dimension */
|
||||
uint8_t TCK;
|
||||
} SC_ATR;
|
||||
} SC_ATRTypeDef;
|
||||
|
||||
/* ADPU-Header command structure ---------------------------------------------*/
|
||||
typedef struct
|
||||
@@ -193,7 +193,7 @@ typedef struct
|
||||
uint8_t INS; /* Operation code */
|
||||
uint8_t P1; /* Selection Mode */
|
||||
uint8_t P2; /* Selection Option */
|
||||
} SC_Header;
|
||||
} SC_HeaderTypeDef;
|
||||
|
||||
/* ADPU-Body command structure -----------------------------------------------*/
|
||||
typedef struct
|
||||
@@ -201,22 +201,22 @@ typedef struct
|
||||
uint8_t LC; /* Data field length */
|
||||
uint8_t Data[LC_MAX]; /* Command parameters */
|
||||
uint8_t LE; /* Expected length of data to be returned */
|
||||
} SC_Body;
|
||||
} SC_BodyTypeDef;
|
||||
|
||||
/* ADPU Command structure ----------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
SC_Header Header;
|
||||
SC_Body Body;
|
||||
} SC_ADPU_Commands;
|
||||
SC_HeaderTypeDef Header;
|
||||
SC_BodyTypeDef Body;
|
||||
} SC_ADPU_CommandsTypeDef;
|
||||
|
||||
/* SC response structure -----------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Data[LC_MAX]; /* Data returned from the card */
|
||||
uint8_t SW1; /* Command Processing status */
|
||||
uint8_t SW2; /* Command Processing qualification */
|
||||
} SC_ADPU_Response;
|
||||
uint8_t SW1; /* Command Processing status */
|
||||
uint8_t SW2; /* Command Processing qualification */
|
||||
} SC_ADPU_ResponseTypeDef;
|
||||
|
||||
/* SC Command Status -----------------------------------------------------*/
|
||||
typedef enum
|
||||
@@ -255,7 +255,7 @@ typedef enum
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/* APPLICATION LAYER ---------------------------------------------------------*/
|
||||
void SC_Handler(SC_State *SCState, SC_ADPU_Commands *SC_ADPU, SC_ADPU_Response *SC_Response);
|
||||
void SC_Handler(SC_State *SCState, SC_ADPU_CommandsTypeDef *SC_ADPU, SC_ADPU_ResponseTypeDef *SC_Response);
|
||||
void SC_PowerCmd(SCPowerState NewState);
|
||||
void SC_ParityErrorHandler(void);
|
||||
void SC_PTSConfig(void);
|
||||
@@ -266,11 +266,11 @@ void SC_SetState(SC_State scState);
|
||||
void SC_IOConfig(void);
|
||||
|
||||
extern uint8_t SC_ATR_Table[40];
|
||||
extern SC_ATR SC_A2R;
|
||||
extern SC_ADPU_Response SC_Response;
|
||||
extern SC_ATRTypeDef SC_A2R;
|
||||
extern SC_ADPU_ResponseTypeDef SC_Response;
|
||||
|
||||
extern uint8_t ProtocolNUM_OUT;
|
||||
extern SC_ADPU_Commands SC_ADPU;
|
||||
extern SC_ADPU_CommandsTypeDef SC_ADPU;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -85,11 +85,12 @@ static uint8_t USBD_CCID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_CCID_DispatchCommand(USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_CCID_ReceiveCmdHeader(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pDst, uint16_t u8length);
|
||||
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
static uint8_t *USBD_CCID_GetHSCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_CCID_GetFSCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_CCID_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_CCID_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -99,6 +100,10 @@ static uint8_t *USBD_CCID_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||
* @{
|
||||
*/
|
||||
|
||||
static uint8_t CCIDInEpAdd = CCID_IN_EP;
|
||||
static uint8_t CCIDOutEpAdd = CCID_OUT_EP;
|
||||
static uint8_t CCIDCmdEpAdd = CCID_CMD_EP;
|
||||
|
||||
|
||||
/* CCID interface class callbacks structure */
|
||||
USBD_ClassTypeDef USBD_CCID =
|
||||
@@ -113,14 +118,23 @@ USBD_ClassTypeDef USBD_CCID =
|
||||
NULL, /*SOF */
|
||||
NULL, /*ISOIn*/
|
||||
NULL, /*ISOOut*/
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
#else
|
||||
USBD_CCID_GetHSCfgDesc,
|
||||
USBD_CCID_GetFSCfgDesc,
|
||||
USBD_CCID_GetOtherSpeedCfgDesc,
|
||||
USBD_CCID_GetDeviceQualifierDescriptor,
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
};
|
||||
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
|
||||
/* USB CCID device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_CCID_CfgHSDesc[USB_CCID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
__ALIGN_BEGIN static uint8_t USBD_CCID_CfgDesc[USB_CCID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/* Configuration Descriptor */
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
@@ -134,7 +148,7 @@ __ALIGN_BEGIN static uint8_t USBD_CCID_CfgHSDesc[USB_CCID_CONFIG_DESC_SIZ] __ALI
|
||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||
#else
|
||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||
#endif
|
||||
#endif /* USBD_SELF_POWERED */
|
||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||
|
||||
/******************** CCID **** interface ********************/
|
||||
@@ -144,112 +158,8 @@ __ALIGN_BEGIN static uint8_t USBD_CCID_CfgHSDesc[USB_CCID_CONFIG_DESC_SIZ] __ALI
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x03, /* bNumEndpoints: 3 endpoints used */
|
||||
USB_DEVICE_CLASS_CCID, /* bInterfaceClass: user's interface for CCID */
|
||||
0x00, /* bInterfaceSubClass : No subclass, can be changed but no description in USB 2.0 Spec */
|
||||
0x00, /* nInterfaceProtocol : None */
|
||||
0x00, /* iInterface */
|
||||
|
||||
/******************* CCID class descriptor ********************/
|
||||
CCID_CLASS_DESC_SIZE, /* bLength: CCID Descriptor size */
|
||||
CCID_DESC_TYPE, /* bDescriptorType: Functional Descriptor type. */
|
||||
0x10, /* bcdCCID(LSB): CCID Class Spec release number (1.1) */
|
||||
0x01, /* bcdCCID(MSB) */
|
||||
|
||||
0x00, /* bMaxSlotIndex :highest available slot on this device */
|
||||
CCID_VOLTAGE_SUPP, /* bVoltageSupport: bVoltageSupport: 5v, 3v and 1.8v */
|
||||
LOBYTE(USBD_CCID_PROTOCOL), /* dwProtocols: supports T=0 and T=1 */
|
||||
HIBYTE(USBD_CCID_PROTOCOL),
|
||||
0x00,
|
||||
0x00,
|
||||
LOBYTE(USBD_CCID_DEFAULT_CLOCK_FREQ), /* dwDefaultClock: 3.6Mhz */
|
||||
HIBYTE(USBD_CCID_DEFAULT_CLOCK_FREQ),
|
||||
0x00,
|
||||
0x00,
|
||||
LOBYTE(USBD_CCID_MAX_CLOCK_FREQ), /* dwMaximumClock */
|
||||
HIBYTE(USBD_CCID_MAX_CLOCK_FREQ),
|
||||
0x00,
|
||||
0x00,
|
||||
0x00, /* bNumClockSupported */
|
||||
LOBYTE(USBD_CCID_DEFAULT_DATA_RATE), /* dwDataRate: 9677 bps */
|
||||
HIBYTE(USBD_CCID_DEFAULT_DATA_RATE),
|
||||
0x00,
|
||||
0x00,
|
||||
|
||||
LOBYTE(USBD_CCID_MAX_DATA_RATE), /* dwMaxDataRate: */
|
||||
HIBYTE(USBD_CCID_MAX_DATA_RATE),
|
||||
0x00,
|
||||
0x00,
|
||||
0x35, /* bNumDataRatesSupported */
|
||||
|
||||
LOBYTE(USBD_CCID_MAX_INF_FIELD_SIZE), /* dwMaxIFSD: maximum IFSD supported for T=1 */
|
||||
HIBYTE(USBD_CCID_MAX_INF_FIELD_SIZE),
|
||||
0x00,
|
||||
0x00,
|
||||
0x00, 0x00, 0x00, 0x00, /* dwSynchProtocols */
|
||||
0x00, 0x00, 0x00, 0x00, /* dwMechanical: no special characteristics */
|
||||
|
||||
0xBA, 0x04, EXCHANGE_LEVEL_FEATURE, 0x00, /* dwFeatures */
|
||||
LOBYTE(CCID_MAX_BLOCK_SIZE_HEADER), /* dwMaxCCIDMessageLength: Maximum block size + header*/
|
||||
HIBYTE(CCID_MAX_BLOCK_SIZE_HEADER),
|
||||
0x00,
|
||||
0x00,
|
||||
0x00, /* bClassGetResponse*/
|
||||
0x00, /* bClassEnvelope */
|
||||
0x00, 0x00, /* wLcdLayout : 0000h no LCD. */
|
||||
0x03, /* bPINSupport : PIN verification and PIN modification */
|
||||
0x01, /* bMaxCCIDBusySlots */
|
||||
|
||||
/******************** CCID Endpoints ********************/
|
||||
CCID_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */
|
||||
USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */
|
||||
CCID_IN_EP, /* Endpoint address (IN, address 1) */
|
||||
USBD_EP_TYPE_BULK, /* Bulk endpoint type */
|
||||
|
||||
LOBYTE(CCID_DATA_HS_MAX_PACKET_SIZE),
|
||||
HIBYTE(CCID_DATA_HS_MAX_PACKET_SIZE),
|
||||
0x00, /* Polling interval in milliseconds */
|
||||
CCID_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */
|
||||
USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */
|
||||
CCID_OUT_EP, /* Endpoint address (OUT, address 1) */
|
||||
USBD_EP_TYPE_BULK, /* Bulk endpoint type */
|
||||
|
||||
LOBYTE(CCID_DATA_HS_MAX_PACKET_SIZE),
|
||||
HIBYTE(CCID_DATA_HS_MAX_PACKET_SIZE),
|
||||
0x00, /* Polling interval in milliseconds */
|
||||
CCID_ENDPOINT_DESC_SIZE, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType:*/
|
||||
CCID_CMD_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
||||
USBD_EP_TYPE_INTR, /* bmAttributes: Interrupt endpoint */
|
||||
LOBYTE(CCID_CMD_PACKET_SIZE),
|
||||
HIBYTE(CCID_CMD_PACKET_SIZE),
|
||||
CCID_CMD_HS_BINTERVAL /* Polling interval in milliseconds */
|
||||
};
|
||||
|
||||
/* USB CCID device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_CCID_CfgFSDesc[USB_CCID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/* Configuration Descriptor */
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
USB_CCID_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
||||
0x00,
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: */
|
||||
0x00, /* iConfiguration: */
|
||||
#if (USBD_SELF_POWERED == 1U)
|
||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||
#else
|
||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||
#endif
|
||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||
|
||||
/******************** CCID **** interface ********************/
|
||||
CCID_INTERFACE_DESC_SIZE, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x03, /* bNumEndpoints: 3 endpoints used */
|
||||
USB_DEVICE_CLASS_CCID, /* bInterfaceClass: user's interface for CCID */
|
||||
0x00, /* bInterfaceSubClass : No subclass, can be changed but no description in USB 2.0 Spec */
|
||||
0x00, /* bInterfaceSubClass : No subclass,
|
||||
can be changed but no description in USB 2.0 Spec */
|
||||
0x00, /* nInterfaceProtocol : None */
|
||||
0x00, /* iInterface */
|
||||
|
||||
@@ -343,7 +253,7 @@ __ALIGN_BEGIN static uint8_t USBD_CCID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER
|
||||
0x01,
|
||||
0x00,
|
||||
};
|
||||
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -370,11 +280,19 @@ static uint8_t USBD_CCID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
|
||||
if (hccid == NULL)
|
||||
{
|
||||
pdev->pClassData = NULL;
|
||||
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
pdev->pClassData = (void *)hccid;
|
||||
pdev->pClassDataCmsit[pdev->classId] = (void *)hccid;
|
||||
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
CCIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK);
|
||||
CCIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK);
|
||||
CCIDCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/* Init the CCID parameters into a state where it can receive a new command message */
|
||||
hccid->USBD_CCID_Param.bAbortRequestFlag = 0U;
|
||||
@@ -384,23 +302,23 @@ static uint8_t USBD_CCID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
CCID_DATA_HS_MAX_PACKET_SIZE : CCID_DATA_FS_MAX_PACKET_SIZE;
|
||||
|
||||
/* Open EP IN */
|
||||
(void)USBD_LL_OpenEP(pdev, CCID_IN_EP, USBD_EP_TYPE_BULK, (uint16_t)hccid->MaxPcktLen);
|
||||
pdev->ep_in[CCID_IN_EP & 0xFU].is_used = 1U;
|
||||
(void)USBD_LL_OpenEP(pdev, CCIDInEpAdd, USBD_EP_TYPE_BULK, (uint16_t)hccid->MaxPcktLen);
|
||||
pdev->ep_in[CCIDInEpAdd & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open EP OUT */
|
||||
(void)USBD_LL_OpenEP(pdev, CCID_OUT_EP, USBD_EP_TYPE_BULK, (uint16_t)hccid->MaxPcktLen);
|
||||
pdev->ep_out[CCID_OUT_EP & 0xFU].is_used = 1U;
|
||||
(void)USBD_LL_OpenEP(pdev, CCIDOutEpAdd, USBD_EP_TYPE_BULK, (uint16_t)hccid->MaxPcktLen);
|
||||
pdev->ep_out[CCIDOutEpAdd & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open INTR EP IN */
|
||||
(void)USBD_LL_OpenEP(pdev, CCID_CMD_EP,
|
||||
(void)USBD_LL_OpenEP(pdev, CCIDCmdEpAdd,
|
||||
USBD_EP_TYPE_INTR, CCID_CMD_PACKET_SIZE);
|
||||
pdev->ep_in[CCID_CMD_EP & 0xFU].is_used = 1U;
|
||||
pdev->ep_in[CCIDCmdEpAdd & 0xFU].is_used = 1U;
|
||||
|
||||
/* Init physical Interface components */
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->Init(pdev);
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init(pdev);
|
||||
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
(void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP,
|
||||
(void)USBD_LL_PrepareReceive(pdev, CCIDOutEpAdd,
|
||||
hccid->data, hccid->MaxPcktLen);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
@@ -417,23 +335,31 @@ static uint8_t USBD_CCID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
CCIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK);
|
||||
CCIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK);
|
||||
CCIDCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/* Close EP IN */
|
||||
(void)USBD_LL_CloseEP(pdev, CCID_IN_EP);
|
||||
pdev->ep_in[CCID_IN_EP & 0xFU].is_used = 0U;
|
||||
(void)USBD_LL_CloseEP(pdev, CCIDInEpAdd);
|
||||
pdev->ep_in[CCIDInEpAdd & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close EP OUT */
|
||||
(void)USBD_LL_CloseEP(pdev, CCID_OUT_EP);
|
||||
pdev->ep_out[CCID_OUT_EP & 0xFU].is_used = 0U;
|
||||
(void)USBD_LL_CloseEP(pdev, CCIDOutEpAdd);
|
||||
pdev->ep_out[CCIDOutEpAdd & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close EP Command */
|
||||
(void)USBD_LL_CloseEP(pdev, CCID_CMD_EP);
|
||||
pdev->ep_in[CCID_CMD_EP & 0xFU].is_used = 0U;
|
||||
(void)USBD_LL_CloseEP(pdev, CCIDCmdEpAdd);
|
||||
pdev->ep_in[CCIDCmdEpAdd & 0xFU].is_used = 0U;
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if (pdev->pClassData != NULL)
|
||||
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||
{
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->DeInit(pdev);
|
||||
(void)USBD_free(pdev->pClassData);
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit(pdev);
|
||||
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
@@ -449,8 +375,8 @@ static uint8_t USBD_CCID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
*/
|
||||
static uint8_t USBD_CCID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_ItfTypeDef *hCCIDitf = (USBD_CCID_ItfTypeDef *)pdev->pUserData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
USBD_CCID_ItfTypeDef *hCCIDitf = (USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
uint8_t ifalt = 0U;
|
||||
uint16_t status_info = 0U;
|
||||
@@ -544,9 +470,15 @@ static uint8_t USBD_CCID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
|
||||
*/
|
||||
static uint8_t USBD_CCID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
if (epnum == (CCID_IN_EP & 0x7FU))
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
CCIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK);
|
||||
CCIDCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
if (epnum == (CCIDInEpAdd & 0x7FU))
|
||||
{
|
||||
/* Filter the epnum by masking with 0x7f (mask of IN Direction) */
|
||||
|
||||
@@ -561,14 +493,14 @@ static uint8_t USBD_CCID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
|
||||
/* Prepare EP to Receive Cmd */
|
||||
(void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP,
|
||||
hccid->data, CCID_DATA_FS_MAX_PACKET_SIZE);
|
||||
hccid->data, hccid->MaxPcktLen);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (epnum == (CCID_CMD_EP & 0x7FU))
|
||||
else if (epnum == (CCIDCmdEpAdd & 0x7FU))
|
||||
{
|
||||
/* Filter the epnum by masking with 0x7f (mask of IN Direction) */
|
||||
|
||||
@@ -593,15 +525,20 @@ static uint8_t USBD_CCID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
*/
|
||||
static uint8_t USBD_CCID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint16_t CurrPcktLen;
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
CCIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
if (hccid == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
if (epnum == CCID_OUT_EP)
|
||||
if (epnum == CCIDOutEpAdd)
|
||||
{
|
||||
CurrPcktLen = (uint16_t)USBD_GetRxCount(pdev, epnum);
|
||||
|
||||
@@ -735,7 +672,7 @@ static uint8_t USBD_CCID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
*/
|
||||
static uint8_t USBD_CCID_DispatchCommand(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t errorCode;
|
||||
|
||||
switch (hccid->UsbBlkOutData.bMessageType)
|
||||
@@ -828,13 +765,13 @@ static uint8_t USBD_CCID_DispatchCommand(USBD_HandleTypeDef *pdev)
|
||||
uint8_t USBD_CCID_Transfer_Data_Request(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *dataPointer, uint16_t dataLen)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_ItfTypeDef *hCCIDitf = (USBD_CCID_ItfTypeDef *)pdev->pUserData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
USBD_CCID_ItfTypeDef *hCCIDitf = (USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||
|
||||
UNUSED(dataPointer);
|
||||
|
||||
hccid->blkt_state = CCID_STATE_SEND_RESP;
|
||||
hccid->UsbMessageLength = hccid->UsbBlkInData.dwLength + (uint32_t)dataLen; /* Store for future use */
|
||||
hccid->UsbMessageLength = (uint32_t)dataLen; /* Store for future use */
|
||||
|
||||
/* use the header declared size packet must be well formed */
|
||||
hCCIDitf->Response_SendData(pdev, (uint8_t *)&hccid->UsbBlkInData,
|
||||
@@ -854,7 +791,7 @@ uint8_t USBD_CCID_Transfer_Data_Request(USBD_HandleTypeDef *pdev,
|
||||
static uint8_t USBD_CCID_ReceiveCmdHeader(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pDst, uint16_t u8length)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t *pdst = pDst;
|
||||
uint32_t Counter;
|
||||
|
||||
@@ -875,7 +812,12 @@ static uint8_t USBD_CCID_ReceiveCmdHeader(USBD_HandleTypeDef *pdev,
|
||||
*/
|
||||
uint8_t USBD_CCID_IntMessage(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
CCIDCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/* Check if there is change in Smartcard Slot status */
|
||||
if (CCID_IsSlotStatusChange(pdev) != 0U)
|
||||
@@ -884,19 +826,20 @@ uint8_t USBD_CCID_IntMessage(USBD_HandleTypeDef *pdev)
|
||||
RDR_to_PC_NotifySlotChange(pdev);
|
||||
|
||||
/* Set the Slot status */
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->SetSlotStatus(pdev);
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId])->SetSlotStatus(pdev);
|
||||
|
||||
(void)USBD_LL_Transmit(pdev, CCID_CMD_EP, hccid->UsbIntData, 2U);
|
||||
(void)USBD_LL_Transmit(pdev, CCIDCmdEpAdd, hccid->UsbIntData, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the Slot status */
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->SetSlotStatus(pdev);
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId])->SetSlotStatus(pdev);
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
/**
|
||||
* @brief USBD_CCID_GetHSCfgDesc
|
||||
* Return configuration descriptor
|
||||
@@ -905,8 +848,27 @@ uint8_t USBD_CCID_IntMessage(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
static uint8_t *USBD_CCID_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_CCID_CfgHSDesc);
|
||||
return USBD_CCID_CfgHSDesc;
|
||||
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_IN_EP);
|
||||
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_OUT_EP);
|
||||
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_CMD_EP);
|
||||
|
||||
if (pEpInDesc != NULL)
|
||||
{
|
||||
pEpInDesc->wMaxPacketSize = CCID_DATA_HS_MAX_PACKET_SIZE;
|
||||
}
|
||||
|
||||
if (pEpOutDesc != NULL)
|
||||
{
|
||||
pEpOutDesc->wMaxPacketSize = CCID_DATA_HS_MAX_PACKET_SIZE;
|
||||
}
|
||||
|
||||
if (pEpCmdDesc != NULL)
|
||||
{
|
||||
pEpCmdDesc->bInterval = CCID_CMD_HS_BINTERVAL;
|
||||
}
|
||||
|
||||
*length = (uint16_t)sizeof(USBD_CCID_CfgDesc);
|
||||
return USBD_CCID_CfgDesc;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_CCID_GetFSCfgDesc
|
||||
@@ -916,8 +878,27 @@ static uint8_t *USBD_CCID_GetHSCfgDesc(uint16_t *length)
|
||||
*/
|
||||
static uint8_t *USBD_CCID_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_CCID_CfgFSDesc);
|
||||
return USBD_CCID_CfgFSDesc;
|
||||
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_IN_EP);
|
||||
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_OUT_EP);
|
||||
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_CMD_EP);
|
||||
|
||||
if (pEpInDesc != NULL)
|
||||
{
|
||||
pEpInDesc->wMaxPacketSize = CCID_DATA_FS_MAX_PACKET_SIZE;
|
||||
}
|
||||
|
||||
if (pEpOutDesc != NULL)
|
||||
{
|
||||
pEpOutDesc->wMaxPacketSize = CCID_DATA_FS_MAX_PACKET_SIZE;
|
||||
}
|
||||
|
||||
if (pEpCmdDesc != NULL)
|
||||
{
|
||||
pEpCmdDesc->bInterval = CCID_CMD_FS_BINTERVAL;
|
||||
}
|
||||
|
||||
*length = (uint16_t)sizeof(USBD_CCID_CfgDesc);
|
||||
return USBD_CCID_CfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -928,8 +909,27 @@ static uint8_t *USBD_CCID_GetFSCfgDesc(uint16_t *length)
|
||||
*/
|
||||
static uint8_t *USBD_CCID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_CCID_CfgFSDesc);
|
||||
return USBD_CCID_CfgFSDesc;
|
||||
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_IN_EP);
|
||||
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_OUT_EP);
|
||||
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_CMD_EP);
|
||||
|
||||
if (pEpInDesc != NULL)
|
||||
{
|
||||
pEpInDesc->wMaxPacketSize = CCID_DATA_FS_MAX_PACKET_SIZE;
|
||||
}
|
||||
|
||||
if (pEpOutDesc != NULL)
|
||||
{
|
||||
pEpOutDesc->wMaxPacketSize = CCID_DATA_FS_MAX_PACKET_SIZE;
|
||||
}
|
||||
|
||||
if (pEpCmdDesc != NULL)
|
||||
{
|
||||
pEpCmdDesc->bInterval = CCID_CMD_FS_BINTERVAL;
|
||||
}
|
||||
|
||||
*length = (uint16_t)sizeof(USBD_CCID_CfgDesc);
|
||||
return USBD_CCID_CfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -943,6 +943,7 @@ static uint8_t *USBD_CCID_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||
*length = (uint16_t)(sizeof(USBD_CCID_DeviceQualifierDesc));
|
||||
return USBD_CCID_DeviceQualifierDesc;
|
||||
}
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_RegisterInterface
|
||||
@@ -958,7 +959,7 @@ uint8_t USBD_CCID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
pdev->pUserData = fops;
|
||||
pdev->pUserData[pdev->classId] = fops;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param_type);
|
||||
static void CCID_UpdateCommandStatus(uint8_t cmd_status, uint8_t icc_status);
|
||||
static void CCID_UpdateCommandStatus(USBD_HandleTypeDef *pdev, uint8_t cmd_status, uint8_t icc_status);
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
@@ -45,7 +45,7 @@ uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
|
||||
Fills the Response buffer with ICC ATR
|
||||
This Command is returned with RDR_to_PC_DataBlock();
|
||||
*/
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t voltage;
|
||||
uint8_t sc_voltage = 0U;
|
||||
uint8_t index;
|
||||
@@ -54,7 +54,7 @@ uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
|
||||
hccid->UsbBlkInData.dwLength = 0U; /* Reset Number of Bytes in abData */
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
||||
CHK_PARAM_abRFU2 | CHK_PARAM_CARD_PRESENT |
|
||||
CHK_PARAM_ABRFU2 | CHK_PARAM_CARD_PRESENT |
|
||||
CHK_PARAM_ABORT);
|
||||
if (error != 0U)
|
||||
{
|
||||
@@ -71,7 +71,7 @@ uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
|
||||
voltage = hccid->UsbBlkOutData.bSpecific_0;
|
||||
if (voltage >= VOLTAGE_SELECTION_1V8)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
return SLOTERROR_BAD_POWERSELECT; /* The Voltage specified is out of Spec */
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
|
||||
else
|
||||
{
|
||||
/* Voltage requested from Host was 5V already*/
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
||||
return error;
|
||||
}
|
||||
} /* Voltage Selection was automatic */
|
||||
@@ -128,7 +128,7 @@ uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
|
||||
|
||||
/* ATR is received, No Error Condition Found */
|
||||
hccid->UsbBlkInData.dwLength = SIZE_OF_ATR;
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
|
||||
for (index = 0U; index < SIZE_OF_ATR; index++)
|
||||
{
|
||||
@@ -150,7 +150,7 @@ uint8_t PC_to_RDR_IccPowerOff(USBD_HandleTypeDef *pdev)
|
||||
/* The response to this command is the RDR_to_PC_SlotStatus*/
|
||||
uint8_t error;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_abRFU3 |
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_ABRFU3 |
|
||||
CHK_PARAM_DWLENGTH);
|
||||
if (error != 0U)
|
||||
{
|
||||
@@ -159,11 +159,11 @@ uint8_t PC_to_RDR_IccPowerOff(USBD_HandleTypeDef *pdev)
|
||||
/* Command is ok, Check for Card Presence */
|
||||
if (SC_Detect() != 0U)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_INACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_INACTIVE));
|
||||
}
|
||||
else
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_NO_ICC_PRESENT));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_NO_ICC_PRESENT));
|
||||
}
|
||||
|
||||
/* Power OFF the card */
|
||||
@@ -183,13 +183,13 @@ uint8_t PC_to_RDR_GetSlotStatus(USBD_HandleTypeDef *pdev)
|
||||
uint8_t error;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
||||
CHK_PARAM_CARD_PRESENT | CHK_PARAM_abRFU3);
|
||||
CHK_PARAM_CARD_PRESENT | CHK_PARAM_ABRFU3);
|
||||
if (error != 0U)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
return SLOT_NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -203,13 +203,13 @@ uint8_t PC_to_RDR_GetSlotStatus(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
uint8_t PC_to_RDR_XfrBlock(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint16_t expectedLength;
|
||||
|
||||
uint8_t error;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||
CHK_PARAM_abRFU3 | CHK_PARAM_ABORT | CHK_ACTIVE_STATE);
|
||||
CHK_PARAM_ABRFU3 | CHK_PARAM_ABORT | CHK_ACTIVE_STATE);
|
||||
if (error != 0U)
|
||||
{
|
||||
return error;
|
||||
@@ -234,11 +234,11 @@ uint8_t PC_to_RDR_XfrBlock(USBD_HandleTypeDef *pdev)
|
||||
|
||||
if (error != SLOT_NO_ERROR)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
else
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
error = SLOT_NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -257,12 +257,12 @@ uint8_t PC_to_RDR_GetParameters(USBD_HandleTypeDef *pdev)
|
||||
uint8_t error;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
||||
CHK_PARAM_CARD_PRESENT | CHK_PARAM_abRFU3);
|
||||
CHK_PARAM_CARD_PRESENT | CHK_PARAM_ABRFU3);
|
||||
if (error != 0U)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
|
||||
return SLOT_NO_ERROR;
|
||||
}
|
||||
@@ -276,11 +276,11 @@ uint8_t PC_to_RDR_GetParameters(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
uint8_t PC_to_RDR_ResetParameters(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t error;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
||||
CHK_PARAM_CARD_PRESENT | CHK_PARAM_abRFU3 |
|
||||
CHK_PARAM_CARD_PRESENT | CHK_PARAM_ABRFU3 |
|
||||
CHK_ACTIVE_STATE);
|
||||
if (error != 0U)
|
||||
{
|
||||
@@ -302,11 +302,11 @@ uint8_t PC_to_RDR_ResetParameters(USBD_HandleTypeDef *pdev)
|
||||
|
||||
if (error != SLOT_NO_ERROR)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
else
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
error = SLOT_NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -321,11 +321,11 @@ uint8_t PC_to_RDR_ResetParameters(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t error;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||
CHK_PARAM_abRFU2 | CHK_ACTIVE_STATE);
|
||||
CHK_PARAM_ABRFU2 | CHK_ACTIVE_STATE);
|
||||
if (error != 0U)
|
||||
{
|
||||
return error;
|
||||
@@ -345,7 +345,7 @@ uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev)
|
||||
}
|
||||
if (error != SLOT_NO_ERROR)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
|
||||
(void)USBD_memcpy(&ProtocolData, (void const *)(&hccid->UsbBlkOutData.abData[0]),
|
||||
@@ -355,11 +355,11 @@ uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev)
|
||||
|
||||
if (error != SLOT_NO_ERROR)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
else
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
error = SLOT_NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -374,12 +374,12 @@ uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
uint8_t PC_to_RDR_Escape(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t error;
|
||||
uint32_t size;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||
CHK_PARAM_abRFU3 | CHK_PARAM_ABORT | CHK_ACTIVE_STATE);
|
||||
CHK_PARAM_ABRFU3 | CHK_PARAM_ABORT | CHK_ACTIVE_STATE);
|
||||
|
||||
if (error != 0U)
|
||||
{
|
||||
@@ -392,11 +392,11 @@ uint8_t PC_to_RDR_Escape(USBD_HandleTypeDef *pdev)
|
||||
|
||||
if (error != SLOT_NO_ERROR)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
else
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
|
||||
return error;
|
||||
@@ -410,11 +410,11 @@ uint8_t PC_to_RDR_Escape(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t error;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||
CHK_PARAM_abRFU2 | CHK_PARAM_DWLENGTH | CHK_ACTIVE_STATE);
|
||||
CHK_PARAM_ABRFU2 | CHK_PARAM_DWLENGTH | CHK_ACTIVE_STATE);
|
||||
if (error != 0U)
|
||||
{
|
||||
return error;
|
||||
@@ -424,7 +424,7 @@ uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev)
|
||||
01h Stops Clock in the state shown in the bClockStop field */
|
||||
if (hccid->UsbBlkOutData.bSpecific_0 > 1U)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
return SLOTERROR_BAD_CLOCKCOMMAND;
|
||||
}
|
||||
|
||||
@@ -432,11 +432,11 @@ uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev)
|
||||
|
||||
if (error != SLOT_NO_ERROR)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
else
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
|
||||
return error;
|
||||
@@ -451,17 +451,17 @@ uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
uint8_t PC_to_RDR_Abort(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t error;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_abRFU3 |
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_ABRFU3 |
|
||||
CHK_PARAM_DWLENGTH);
|
||||
if (error != 0U)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
(void)CCID_CmdAbort(hccid->UsbBlkOutData.bSlot, hccid->UsbBlkOutData.bSeq);
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
(void)CCID_CmdAbort(pdev, hccid->UsbBlkOutData.bSlot, hccid->UsbBlkOutData.bSeq);
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
return SLOT_NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -469,13 +469,14 @@ uint8_t PC_to_RDR_Abort(USBD_HandleTypeDef *pdev)
|
||||
* @brief CCID_CmdAbort
|
||||
* Execute the Abort command from Bulk EP or from Control EP,
|
||||
* This stops all Bulk transfers from host and ICC
|
||||
* @param pdev: device instance
|
||||
* @param slot: slot number that host wants to abort
|
||||
* @param seq : Seq number for PC_to_RDR_Abort
|
||||
* @retval status of the command execution
|
||||
*/
|
||||
uint8_t CCID_CmdAbort(uint8_t slot, uint8_t seq)
|
||||
uint8_t CCID_CmdAbort(USBD_HandleTypeDef *pdev, uint8_t slot, uint8_t seq)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)(USBD_Device.pClassData);
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
uint8_t BSlot = hccid->USBD_CCID_Param.bSlot;
|
||||
/* This function is called for REQUEST_ABORT & PC_to_RDR_Abort */
|
||||
@@ -483,7 +484,7 @@ uint8_t CCID_CmdAbort(uint8_t slot, uint8_t seq)
|
||||
if (slot >= CCID_NUMBER_OF_SLOTS)
|
||||
{
|
||||
/* error from CLASS_REQUEST*/
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
||||
return SLOTERROR_BAD_SLOT;
|
||||
}
|
||||
|
||||
@@ -517,7 +518,7 @@ uint8_t CCID_CmdAbort(uint8_t slot, uint8_t seq)
|
||||
*/
|
||||
uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t error;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||
@@ -531,7 +532,7 @@ uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev)
|
||||
/* Bit 0 is associated with bClassGetResponse
|
||||
Bit 1 is associated with bClassEnvelope */
|
||||
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
return SLOTERROR_BAD_BMCHANGES;
|
||||
}
|
||||
|
||||
@@ -541,11 +542,11 @@ uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev)
|
||||
|
||||
if (error != SLOT_NO_ERROR)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
else
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
|
||||
return error;
|
||||
@@ -560,11 +561,11 @@ uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t error;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||
CHK_PARAM_abRFU2 | CHK_PARAM_DWLENGTH);
|
||||
CHK_PARAM_ABRFU2 | CHK_PARAM_DWLENGTH);
|
||||
if (error != 0U)
|
||||
{
|
||||
return error;
|
||||
@@ -579,7 +580,7 @@ uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev)
|
||||
05h Unlock Card
|
||||
*/
|
||||
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
return SLOTERROR_BAD_BFUNCTION_MECHANICAL;
|
||||
}
|
||||
|
||||
@@ -587,11 +588,11 @@ uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev)
|
||||
|
||||
if (error != SLOT_NO_ERROR)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
else
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
|
||||
return error;
|
||||
@@ -607,21 +608,21 @@ uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t error;
|
||||
uint32_t clockFrequency;
|
||||
uint32_t dataRate;
|
||||
uint32_t temp;
|
||||
|
||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||
CHK_PARAM_abRFU3);
|
||||
CHK_PARAM_ABRFU3);
|
||||
if (error != 0U)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
if (hccid->UsbBlkOutData.dwLength != 0x08U)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
return SLOTERROR_BAD_LENTGH;
|
||||
}
|
||||
|
||||
@@ -656,7 +657,7 @@ uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev)
|
||||
if (error != SLOT_NO_ERROR)
|
||||
{
|
||||
hccid->UsbBlkInData.dwLength = 0;
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -678,7 +679,7 @@ uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev)
|
||||
|
||||
(hccid->UsbBlkInData.abData[7]) = (uint8_t)((dataRate & 0xFF000000U) >> 24);
|
||||
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
|
||||
return error;
|
||||
@@ -693,7 +694,7 @@ uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint8_t error;
|
||||
uint8_t bBWI;
|
||||
uint16_t wLevelParameter;
|
||||
@@ -717,7 +718,7 @@ uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev)
|
||||
/* TPDU level & short APDU level, wLevelParameter is RFU, = 0000h */
|
||||
if (wLevelParameter != 0U)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
error = SLOTERROR_BAD_LEVELPARAMETER;
|
||||
return error;
|
||||
}
|
||||
@@ -730,11 +731,11 @@ uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev)
|
||||
|
||||
if (error != SLOT_NO_ERROR)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
else
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||
}
|
||||
|
||||
return error;
|
||||
@@ -754,7 +755,7 @@ uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
void RDR_to_PC_DataBlock(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint32_t length = CCID_RESPONSE_HEADER_SIZE;
|
||||
|
||||
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_DATABLOCK;
|
||||
@@ -786,8 +787,8 @@ void RDR_to_PC_DataBlock(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
void RDR_to_PC_SlotStatus(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
UNUSED(errorCode);
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint16_t length = CCID_RESPONSE_HEADER_SIZE;
|
||||
|
||||
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_SLOTSTATUS;
|
||||
hccid->UsbBlkInData.dwLength = 0U;
|
||||
@@ -797,9 +798,12 @@ void RDR_to_PC_SlotStatus(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||
02h Clock stopped in state H
|
||||
03h Clock stopped in an unknown state */
|
||||
|
||||
(void)USBD_CCID_Transfer_Data_Request(pdev, (uint8_t *)(&hccid->UsbBlkInData),
|
||||
LEN_RDR_TO_PC_SLOTSTATUS);
|
||||
if (errorCode == SLOT_NO_ERROR)
|
||||
{
|
||||
length += (uint16_t)hccid->UsbBlkInData.dwLength;
|
||||
}
|
||||
|
||||
(void)USBD_CCID_Transfer_Data_Request(pdev, (uint8_t *)(&hccid->UsbBlkInData), length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -813,7 +817,7 @@ void RDR_to_PC_SlotStatus(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
void RDR_to_PC_Parameters(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint16_t length = CCID_RESPONSE_HEADER_SIZE;
|
||||
|
||||
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_PARAMETERS;
|
||||
@@ -824,12 +828,12 @@ void RDR_to_PC_Parameters(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||
if (ProtocolNUM_OUT == 0x00U)
|
||||
{
|
||||
hccid->UsbBlkInData.dwLength = LEN_PROTOCOL_STRUCT_T0;
|
||||
length += LEN_PROTOCOL_STRUCT_T0;
|
||||
length += (uint16_t)hccid->UsbBlkInData.dwLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
hccid->UsbBlkInData.dwLength = LEN_PROTOCOL_STRUCT_T1;
|
||||
length += LEN_PROTOCOL_STRUCT_T1;
|
||||
length += (uint16_t)hccid->UsbBlkInData.dwLength;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -867,7 +871,7 @@ void RDR_to_PC_Parameters(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
void RDR_to_PC_Escape(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint32_t length = CCID_RESPONSE_HEADER_SIZE;
|
||||
|
||||
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_ESCAPE;
|
||||
@@ -893,7 +897,7 @@ void RDR_to_PC_Escape(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
void RDR_to_PC_DataRateAndClockFrequency(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint32_t length = CCID_RESPONSE_HEADER_SIZE;
|
||||
|
||||
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_DATARATEANDCLOCKFREQUENCY;
|
||||
@@ -917,7 +921,7 @@ void RDR_to_PC_DataRateAndClockFrequency(uint8_t errorCode, USBD_HandleTypeDef
|
||||
*/
|
||||
void RDR_to_PC_NotifySlotChange(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
hccid->UsbIntData[OFFSET_INT_BMESSAGETYPE] = RDR_TO_PC_NOTIFYSLOTCHANGE;
|
||||
|
||||
@@ -948,7 +952,7 @@ void RDR_to_PC_NotifySlotChange(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
void CCID_UpdSlotStatus(USBD_HandleTypeDef *pdev, uint8_t slotStatus)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
hccid->SlotStatus.SlotStatus = slotStatus;
|
||||
}
|
||||
|
||||
@@ -961,7 +965,7 @@ void CCID_UpdSlotStatus(USBD_HandleTypeDef *pdev, uint8_t slotStatus)
|
||||
*/
|
||||
void CCID_UpdSlotChange(USBD_HandleTypeDef *pdev, uint8_t changeStatus)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
hccid->SlotStatus.SlotStatusChange = changeStatus;
|
||||
}
|
||||
|
||||
@@ -973,20 +977,21 @@ void CCID_UpdSlotChange(USBD_HandleTypeDef *pdev, uint8_t changeStatus)
|
||||
*/
|
||||
uint8_t CCID_IsSlotStatusChange(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
return hccid->SlotStatus.SlotStatusChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CCID_UpdateCommandStatus
|
||||
* Updates the variable for the BulkIn status
|
||||
* @param pdev: device instance
|
||||
* @param cmd_status : Command change status from the calling function
|
||||
* @param icc_status : Slot change status from the calling function
|
||||
* @retval None
|
||||
*/
|
||||
static void CCID_UpdateCommandStatus(uint8_t cmd_status, uint8_t icc_status)
|
||||
static void CCID_UpdateCommandStatus(USBD_HandleTypeDef *pdev, uint8_t cmd_status, uint8_t icc_status)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)USBD_Device.pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
hccid->UsbBlkInData.bStatus = (cmd_status | icc_status);
|
||||
}
|
||||
/**
|
||||
@@ -1000,7 +1005,7 @@ static void CCID_UpdateCommandStatus(uint8_t cmd_status, uint8_t icc_status)
|
||||
*/
|
||||
static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param_type)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint32_t parameter;
|
||||
uint8_t GetState = SC_GetState();
|
||||
|
||||
@@ -1019,7 +1024,7 @@ static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param
|
||||
if (hccid->UsbBlkOutData.bSlot >= CCID_NUMBER_OF_SLOTS)
|
||||
{
|
||||
/* Slot requested is more than supported by Firmware */
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
||||
return SLOTERROR_BAD_SLOT;
|
||||
}
|
||||
}
|
||||
@@ -1030,7 +1035,7 @@ static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param
|
||||
if (SC_Detect() == 0U)
|
||||
{
|
||||
/* Card is Not detected */
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
||||
return SLOTERROR_ICC_MUTE;
|
||||
}
|
||||
}
|
||||
@@ -1040,30 +1045,30 @@ static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param
|
||||
{
|
||||
if (hccid->UsbBlkOutData.dwLength != 0U)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
return SLOTERROR_BAD_LENTGH;
|
||||
}
|
||||
}
|
||||
|
||||
/* abRFU 2 : Reserved for Future Use*/
|
||||
if ((parameter & CHK_PARAM_abRFU2) != 0U)
|
||||
if ((parameter & CHK_PARAM_ABRFU2) != 0U)
|
||||
{
|
||||
|
||||
if ((hccid->UsbBlkOutData.bSpecific_1 != 0U) || (hccid->UsbBlkOutData.bSpecific_2 != 0U))
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
return SLOTERROR_BAD_ABRFU_2B; /* bSpecific_1 */
|
||||
}
|
||||
}
|
||||
|
||||
if ((parameter & CHK_PARAM_abRFU3) != 0U)
|
||||
if ((parameter & CHK_PARAM_ABRFU3) != 0U)
|
||||
{
|
||||
/* abRFU 3 : Reserved for Future Use*/
|
||||
if ((hccid->UsbBlkOutData.bSpecific_0 != 0U) ||
|
||||
(hccid->UsbBlkOutData.bSpecific_1 != 0U) ||
|
||||
(hccid->UsbBlkOutData.bSpecific_2 != 0U))
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||
return SLOTERROR_BAD_ABRFU_3B;
|
||||
}
|
||||
}
|
||||
@@ -1072,7 +1077,7 @@ static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param
|
||||
{
|
||||
if (hccid->USBD_CCID_Param.bAbortRequestFlag != 0U)
|
||||
{
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
||||
return SLOTERROR_CMD_ABORTED;
|
||||
}
|
||||
}
|
||||
@@ -1085,7 +1090,7 @@ static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param
|
||||
if ((GetState != (uint8_t)SC_ACTIVE_ON_T0) && (GetState != (uint8_t)SC_ACTIVE_ON_T1))
|
||||
{
|
||||
/* Check that from Lower Layers, the SmartCard come to known state */
|
||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
||||
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
||||
return SLOTERROR_HW_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,11 @@ USBD_CCID_ItfTypeDef USBD_CCID_If_fops =
|
||||
*/
|
||||
uint8_t CCID_Init(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
#else
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/* CCID Related Initialization */
|
||||
|
||||
@@ -76,8 +80,11 @@ uint8_t CCID_Init(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
uint8_t CCID_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
#else
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
hccid->blkt_state = CCID_STATE_IDLE;
|
||||
|
||||
@@ -94,7 +101,12 @@ uint8_t CCID_DeInit(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
static uint8_t CCID_ControlReq(uint8_t req, uint8_t *pbuf, uint16_t *length)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)(USBD_Device.pClassData);
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)USBD_Device.pClassDataCmsit[USBD_Device.classId];
|
||||
#else
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)USBD_Device.pClassData;
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
UNUSED(length);
|
||||
|
||||
switch (req)
|
||||
@@ -105,7 +117,7 @@ static uint8_t CCID_ControlReq(uint8_t req, uint8_t *pbuf, uint16_t *length)
|
||||
hccid->slot_nb = ((uint16_t) * pbuf & 0x0fU);
|
||||
hccid->seq_nb = (((uint16_t) * pbuf & 0xf0U) >> 8);
|
||||
|
||||
if (CCID_CmdAbort((uint8_t)hccid->slot_nb, (uint8_t)hccid->seq_nb) != 0U)
|
||||
if (CCID_CmdAbort(&USBD_Device, (uint8_t)hccid->slot_nb, (uint8_t)hccid->seq_nb) != 0U)
|
||||
{
|
||||
/* If error is returned by lower layer :
|
||||
Generally Slot# may not have matched */
|
||||
@@ -238,7 +250,11 @@ static uint8_t CCID_Response_Process(void)
|
||||
uint8_t CCID_SetSlotStatus(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Get the CCID handler pointer */
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
#else
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
if ((hccid->SlotStatus.SlotStatus) == 1U) /* Transfer Complete Status
|
||||
of previous Interrupt transfer */
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
static SC_State SCState = SC_POWER_OFF;
|
||||
|
||||
/* APDU Transport Structures */
|
||||
SC_ADPU_Commands SC_ADPU;
|
||||
SC_ADPU_Response SC_Response;
|
||||
SC_ADPU_CommandsTypeDef SC_ADPU;
|
||||
SC_ADPU_ResponseTypeDef SC_Response;
|
||||
SC_Param_t SC_Param;
|
||||
Protocol_01_DataTypeDef ProtocolData;
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ __IO uint8_t IMSI_Content[9] = {0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
static uint32_t D_Table[16] = {0, 1, 2, 4, 8, 16, 32, 64, 12, 20, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
/* Global variables definition and initialization ----------------------------*/
|
||||
SC_ATR SC_A2R;
|
||||
SC_ATRTypeDef SC_A2R;
|
||||
uint8_t SC_ATR_Table[40];
|
||||
uint8_t ProtocolNUM_OUT;
|
||||
|
||||
@@ -63,7 +63,7 @@ static void SC_Init(void);
|
||||
static void SC_DeInit(void);
|
||||
static void SC_AnswerReq(SC_State *SC_state, uint8_t *card, uint8_t length); /* Ask ATR */
|
||||
static uint8_t SC_decode_Answer2reset(uint8_t *card); /* Decode ATR */
|
||||
static void SC_SendData(SC_ADPU_Commands *SCADPU, SC_ADPU_Response *SC_ResponseStatus);
|
||||
static void SC_SendData(SC_ADPU_CommandsTypeDef *SCADPU, SC_ADPU_ResponseTypeDef *SC_ResponseStatus);
|
||||
/* static void SC_Reset(GPIO_PinState ResetState); */
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
@@ -77,7 +77,7 @@ static void SC_SendData(SC_ADPU_Commands *SCADPU, SC_ADPU_Response *SC_ResponseS
|
||||
* @param SC_Response: pointer to a SC_ADPU_Response structure which will be initialized.
|
||||
* @retval None
|
||||
*/
|
||||
void SC_Handler(SC_State *SCState, SC_ADPU_Commands *SC_ADPU, SC_ADPU_Response *SC_Response)
|
||||
void SC_Handler(SC_State *SCState, SC_ADPU_CommandsTypeDef *SC_ADPU, SC_ADPU_ResponseTypeDef *SC_Response)
|
||||
{
|
||||
uint32_t i, j;
|
||||
|
||||
@@ -110,7 +110,7 @@ void SC_Handler(SC_State *SCState, SC_ADPU_Commands *SC_ADPU, SC_ADPU_Response *
|
||||
|
||||
for (i = 0U; i < HIST_LENGTH; i++)
|
||||
{
|
||||
SC_A2R.H[i] = 0U;
|
||||
SC_A2R.Historical[i] = 0U;
|
||||
}
|
||||
|
||||
SC_A2R.Tlength = 0U;
|
||||
@@ -245,7 +245,7 @@ void SC_PTSConfig(void)
|
||||
* @param SC_Response: pointer to a SC_ADPU_Response structure which will be initialized.
|
||||
* @retval None
|
||||
*/
|
||||
static void SC_SendData(SC_ADPU_Commands *SCADPU, SC_ADPU_Response *SC_ResponseStatus)
|
||||
static void SC_SendData(SC_ADPU_CommandsTypeDef *SCADPU, SC_ADPU_ResponseTypeDef *SC_ResponseStatus)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t SC_Command[5];
|
||||
@@ -391,7 +391,7 @@ static uint8_t SC_decode_Answer2reset(uint8_t *card)
|
||||
|
||||
for (i = 0U; i < SC_A2R.Hlength; i++)
|
||||
{
|
||||
SC_A2R.H[i] = card[i + 2U + SC_A2R.Tlength];
|
||||
SC_A2R.Historical[i] = card[i + 2U + SC_A2R.Tlength];
|
||||
}
|
||||
/*************************************TCK Decode*******************************/
|
||||
SC_A2R.TCK = card[SC_A2R.Hlength + 2U + SC_A2R.Tlength];
|
||||
|
||||
Reference in New Issue
Block a user