diff --git a/Class/AUDIO/Inc/usbd_audio.h b/Class/AUDIO/Inc/usbd_audio.h index dbb71cd..b445858 100644 --- a/Class/AUDIO/Inc/usbd_audio.h +++ b/Class/AUDIO/Inc/usbd_audio.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -214,5 +213,3 @@ void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset); /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/AUDIO/Inc/usbd_audio_if_template.h b/Class/AUDIO/Inc/usbd_audio_if_template.h index 21cee0d..02aa1b6 100644 --- a/Class/AUDIO/Inc/usbd_audio_if_template.h +++ b/Class/AUDIO/Inc/usbd_audio_if_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -41,5 +40,3 @@ extern USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops; #endif #endif /* __USBD_AUDIO_IF_TEMPLATE_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/AUDIO/Src/usbd_audio.c b/Class/AUDIO/Src/usbd_audio.c index acaaf05..2acc975 100644 --- a/Class/AUDIO/Src/usbd_audio.c +++ b/Class/AUDIO/Src/usbd_audio.c @@ -4,6 +4,18 @@ * @author MCD Application Team * @brief This file provides the Audio core functions. * + * + ****************************************************************************** + * @attention + * + * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** * @verbatim * * =================================================================== @@ -38,18 +50,6 @@ * * * @endverbatim - * - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * ****************************************************************************** */ @@ -93,10 +93,11 @@ EndBSPDependencies */ /** @defgroup USBD_AUDIO_Private_Macros * @{ */ -#define AUDIO_SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16)) +#define AUDIO_SAMPLE_FREQ(frq) \ + (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16)) -#define AUDIO_PACKET_SZE(frq) (uint8_t)(((frq * 2U * 2U)/1000U) & 0xFFU), \ - (uint8_t)((((frq * 2U * 2U)/1000U) >> 8) & 0xFFU) +#define AUDIO_PACKET_SZE(frq) \ + (uint8_t)(((frq * 2U * 2U) / 1000U) & 0xFFU), (uint8_t)((((frq * 2U * 2U) / 1000U) >> 8) & 0xFFU) /** * @} @@ -533,7 +534,6 @@ static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev, /** * @brief USBD_AUDIO_GetCfgDesc * return configuration descriptor - * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ @@ -620,6 +620,7 @@ static uint8_t USBD_AUDIO_SOF(USBD_HandleTypeDef *pdev) * @brief USBD_AUDIO_SOF * handle SOF event * @param pdev: device instance + * @param offset: audio offset * @retval status */ void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset) @@ -777,7 +778,7 @@ static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) /** * @brief AUDIO_Req_GetCurrent * Handles the GET_CUR Audio control request. - * @param pdev: instance + * @param pdev: device instance * @param req: setup class request * @retval status */ @@ -801,7 +802,7 @@ static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef /** * @brief AUDIO_Req_SetCurrent * Handles the SET_CUR Audio control request. - * @param pdev: instance + * @param pdev: device instance * @param req: setup class request * @retval status */ @@ -842,6 +843,7 @@ static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length) /** * @brief USBD_AUDIO_RegisterInterface + * @param pdev: device instance * @param fops: Audio interface callback * @retval status */ @@ -870,5 +872,3 @@ uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev, /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/AUDIO/Src/usbd_audio_if_template.c b/Class/AUDIO/Src/usbd_audio_if_template.c index 7c97c75..c9db989 100644 --- a/Class/AUDIO/Src/usbd_audio_if_template.c +++ b/Class/AUDIO/Src/usbd_audio_if_template.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -197,5 +196,3 @@ static int8_t TEMPLATE_GetState(void) * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/Class/BillBoard/Inc/usbd_billboard.h b/Class/BillBoard/Inc/usbd_billboard.h index 8bff7b3..e2acdaf 100644 --- a/Class/BillBoard/Inc/usbd_billboard.h +++ b/Class/BillBoard/Inc/usbd_billboard.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -159,5 +158,3 @@ void *USBD_BB_GetAltModeDesc(USBD_HandleTypeDef *pdev, uint8_t *buf, uint8_t idx /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/BillBoard/Src/usbd_billboard.c b/Class/BillBoard/Src/usbd_billboard.c index e0bacaa..f546425 100644 --- a/Class/BillBoard/Src/usbd_billboard.c +++ b/Class/BillBoard/Src/usbd_billboard.c @@ -7,6 +7,17 @@ * - Initialization and Configuration of high and low layer * - Enumeration as BillBoard Device * - Error management + ****************************************************************************** + * @attention + * + * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** * @verbatim * * =================================================================== @@ -23,17 +34,6 @@ * @endverbatim * ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ @@ -500,5 +500,3 @@ void *USBD_BB_GetAltModeDesc(USBD_HandleTypeDef *pdev, uint8_t *pBosDesc, uint8_ /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CCID/Inc/usbd_ccid.h b/Class/CCID/Inc/usbd_ccid.h new file mode 100644 index 0000000..cc4bb1d --- /dev/null +++ b/Class/CCID/Inc/usbd_ccid.h @@ -0,0 +1,343 @@ +/** + ****************************************************************************** + * @file usbd_ccid.h + * @author MCD Application Team + * @brief header file for the usbd_ccid.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CCID_H +#define __USBD_CCID_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_ioreq.h" + +/** @addtogroup STM32_USB_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup usbd_cdc + * @brief This file is the Header file for usbd_ccid.c + * @{ + */ + + +/** @defgroup usbd_cdc_Exported_Defines + * @{ + */ +#ifndef CCID_IN_EP +#define CCID_IN_EP 0x81U /* EP1 for data IN */ +#endif /* CCID_IN_EP */ + +#ifndef CCID_OUT_EP +#define CCID_OUT_EP 0x01U /* EP1 for data OUT */ +#endif /* CCID_OUT_EP */ + +#ifndef CCID_CMD_EP +#define CCID_CMD_EP 0x82U /* EP2 for CCID commands */ +#endif /* CCID_CMD_EP */ + +#ifndef CCID_CMD_HS_BINTERVAL +#define CCID_CMD_HS_BINTERVAL 0x10U +#endif /* CCID_CMD_HS_BINTERVAL */ + +#ifndef CCID_CMD_FS_BINTERVAL +#define CCID_CMD_FS_BINTERVAL 0x10U +#endif /* CCID_CMD_FS_BINTERVAL */ + + +#define CCID_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */ +#define CCID_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */ +#define CCID_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */ + +#define USB_CCID_CONFIG_DESC_SIZ 93U +#define CCID_DATA_HS_IN_PACKET_SIZE CCID_DATA_HS_MAX_PACKET_SIZE +#define CCID_DATA_HS_OUT_PACKET_SIZE CCID_DATA_HS_MAX_PACKET_SIZE + +#define CCID_DATA_FS_IN_PACKET_SIZE CCID_DATA_FS_MAX_PACKET_SIZE +#define CCID_DATA_FS_OUT_PACKET_SIZE CCID_DATA_FS_MAX_PACKET_SIZE + +/*---------------------------------------------------------------------*/ +/* CCID definitions */ +/*---------------------------------------------------------------------*/ +#define CCID_SEND_ENCAPSULATED_COMMAND 0x00U +#define CCID_GET_ENCAPSULATED_RESPONSE 0x01U +#define CCID_SET_COMM_FEATURE 0x02U +#define CCID_GET_COMM_FEATURE 0x03U +#define CCID_CLEAR_COMM_FEATURE 0x04U +#define CCID_SET_LINE_CODING 0x20U +#define CCID_GET_LINE_CODING 0x21U +#define CCID_SET_CONTROL_LINE_STATE 0x22U +#define CCID_SEND_BREAK 0x23U + +/*---------------------------------------------------------------------*/ +#define REQUEST_ABORT 0x01U +#define REQUEST_GET_CLOCK_FREQUENCIES 0x02U +#define REQUEST_GET_DATA_RATES 0x03U + +/*---------------------------------------------------------------------*/ +/* The Smart Card Device Class Descriptor definitions */ +/*---------------------------------------------------------------------*/ + +#define CCID_INTERFACE_DESC_SIZE 0x09U +#define USB_DEVICE_CLASS_CCID 0x0BU +#define CCID_CLASS_DESC_SIZE 0x36U +#define CCID_DESC_TYPE 0x21U + +#ifndef CCID_VOLTAGE_SUPP +#define CCID_VOLTAGE_SUPP 0x07U +#endif +#ifndef USBD_CCID_PROTOCOL +#define USBD_CCID_PROTOCOL 0x03U +#endif +#ifndef USBD_CCID_DEFAULT_CLOCK_FREQ +#define USBD_CCID_DEFAULT_CLOCK_FREQ 3600U +#endif +#ifndef USBD_CCID_MAX_CLOCK_FREQ +#define USBD_CCID_MAX_CLOCK_FREQ USBD_CCID_DEFAULT_CLOCK_FREQ +#endif +#ifndef USBD_CCID_DEFAULT_DATA_RATE +#define USBD_CCID_DEFAULT_DATA_RATE 9677U +#endif +#ifndef USBD_CCID_MAX_DATA_RATE +#define USBD_CCID_MAX_DATA_RATE USBD_CCID_DEFAULT_DATA_RATE +#endif +#ifndef USBD_CCID_MAX_INF_FIELD_SIZE +#define USBD_CCID_MAX_INF_FIELD_SIZE 254U +#endif +#ifndef CCID_MAX_BLOCK_SIZE_HEADER +#define CCID_MAX_BLOCK_SIZE_HEADER 271U +#endif + +#define TPDU_EXCHANGE 0x01U +#define SHORT_APDU_EXCHANGE 0x02U +#define EXTENDED_APDU_EXCHANGE 0x04U +#define CHARACTER_EXCHANGE 0x00U + +#ifndef EXCHANGE_LEVEL_FEATURE +#define EXCHANGE_LEVEL_FEATURE TPDU_EXCHANGE +#endif + +#define CCID_ENDPOINT_DESC_SIZE 0x07U + +#ifndef CCID_EP0_BUFF_SIZ +#define CCID_EP0_BUFF_SIZ 64U +#endif + +#ifndef CCID_BULK_EPIN_SIZE +#define CCID_BULK_EPIN_SIZE 64U +#endif + +#define CCID_INT_BUFF_SIZ 2U +/*---------------------------------------------------------------------*/ + +/* CCID Bulk Out Command definitions */ +#define PC_TO_RDR_ICCPOWERON 0x62U +#define PC_TO_RDR_ICCPOWEROFF 0x63U +#define PC_TO_RDR_GETSLOTSTATUS 0x65U +#define PC_TO_RDR_XFRBLOCK 0x6FU +#define PC_TO_RDR_GETPARAMETERS 0x6CU +#define PC_TO_RDR_RESETPARAMETERS 0x6DU +#define PC_TO_RDR_SETPARAMETERS 0x61U +#define PC_TO_RDR_ESCAPE 0x6BU +#define PC_TO_RDR_ICCCLOCK 0x6EU +#define PC_TO_RDR_T0APDU 0x6AU +#define PC_TO_RDR_SECURE 0x69U +#define PC_TO_RDR_MECHANICAL 0x71U +#define PC_TO_RDR_ABORT 0x72U +#define PC_TO_RDR_SETDATARATEANDCLOCKFREQUENCY 0x73U + +/* CCID Bulk In Command definitions */ +#define RDR_TO_PC_DATABLOCK 0x80U +#define RDR_TO_PC_SLOTSTATUS 0x81U +#define RDR_TO_PC_PARAMETERS 0x82U +#define RDR_TO_PC_ESCAPE 0x83U +#define RDR_TO_PC_DATARATEANDCLOCKFREQUENCY 0x84U + +/* CCID Interrupt In Command definitions */ +#define RDR_TO_PC_NOTIFYSLOTCHANGE 0x50U +#define RDR_TO_PC_HARDWAREERROR 0x51U + +/* Bulk-only Command Block Wrapper */ +#define ABDATA_SIZE 261U +#define CCID_CMD_HEADER_SIZE 10U +#define CCID_RESPONSE_HEADER_SIZE 10U + +/* Number of SLOTS. For single card, this value is 1 */ +#define CCID_NUMBER_OF_SLOTS 1U + +#define CARD_SLOT_FITTED 1U +#define CARD_SLOT_REMOVED 0U + +#define OFFSET_INT_BMESSAGETYPE 0x00U +#define OFFSET_INT_BMSLOTICCSTATE 0x01U +#define SLOT_ICC_PRESENT 0x01U +/* LSb : (0b = no ICC present, 1b = ICC present) */ +#define SLOT_ICC_CHANGE 0x02U +/* MSb : (0b = no change, 1b = change) */ + + +/** + * @} + */ + + +/** @defgroup USBD_CORE_Exported_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +typedef struct +{ + uint32_t bitrate; + uint8_t format; + uint8_t paritytype; + uint8_t datatype; +} USBD_CCID_LineCodingTypeDef; + +#pragma pack(1) +typedef struct +{ + uint8_t bMessageType; /* Offset = 0*/ + uint32_t dwLength; /* Offset = 1, The length field (dwLength) is the length + of the message not including the 10-byte header.*/ + uint8_t bSlot; /* Offset = 5*/ + uint8_t bSeq; /* Offset = 6*/ + uint8_t bSpecific_0; /* Offset = 7*/ + uint8_t bSpecific_1; /* Offset = 8*/ + uint8_t bSpecific_2; /* Offset = 9*/ + uint8_t abData [ABDATA_SIZE]; /* Offset = 10, For reference, the absolute + maximum block size for a TPDU T=0 block is 260 bytes + (5 bytes command; 255 bytes data), + 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() + +#pragma pack(1) +typedef struct +{ + uint8_t bMessageType; /* Offset = 0 */ + uint32_t dwLength; /* Offset = 1 */ + uint8_t bSlot; /* Offset = 5, Same as Bulk-OUT message */ + uint8_t bSeq; /* Offset = 6, Same as Bulk-OUT message */ + uint8_t bStatus; /* Offset = 7, Slot status as defined in section 6.2.6 */ + uint8_t bError; /* Offset = 8, Slot error as defined in section 6.2.6 */ + uint8_t bSpecific; /* Offset = 9 */ + uint8_t abData[ABDATA_SIZE]; /* Offset = 10 */ + uint16_t u16SizeToSend; +} USBD_CCID_BulkIn_DataTypeDef; +#pragma pack() + +typedef struct +{ + __IO uint8_t SlotStatus; + __IO uint8_t SlotStatusChange; +} USBD_CCID_SlotStatusTypeDef; + + +typedef struct +{ + __IO uint8_t bAbortRequestFlag; + __IO uint8_t bSeq; + __IO uint8_t bSlot; +} USBD_CCID_ParamTypeDef; + + +typedef struct +{ + uint8_t data[CCID_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32-bit alignment */ + uint32_t UsbMessageLength; + uint8_t UsbIntData[CCID_CMD_PACKET_SIZE]; /* Buffer for the Interrupt In Data */ + uint32_t alt_setting; + + USBD_CCID_BulkIn_DataTypeDef UsbBlkInData; /* Buffer for the Out Data */ + USBD_CCID_BulkOut_DataTypeDef UsbBlkOutData; /* Buffer for the In Data */ + USBD_CCID_SlotStatusTypeDef SlotStatus; + USBD_CCID_ParamTypeDef USBD_CCID_Param; + + __IO uint32_t MaxPcktLen; + __IO uint8_t blkt_state; /* Bulk transfer state */ + + uint16_t slot_nb; + uint16_t seq_nb; +} USBD_CCID_HandleTypeDef; + +/** @defgroup USBD_CORE_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_CORE_Exported_Variables + * @{ + */ + +extern USBD_ClassTypeDef USBD_CCID; +#define USBD_CCID_CLASS &USBD_CCID +/** + * @} + */ + +/** @defgroup USB_CORE_Exported_Functions + * @{ + */ +typedef struct _USBD_CCID_Itf +{ + uint8_t (* Init)(USBD_HandleTypeDef *pdev); + uint8_t (* DeInit)(USBD_HandleTypeDef *pdev); + uint8_t (* Control)(uint8_t req, uint8_t *pbuf, uint16_t *length); + uint8_t (* Response_SendData)(USBD_HandleTypeDef *pdev, uint8_t *buf, uint16_t len); + uint8_t (* Send_Process)(uint8_t *Command, uint8_t *Data); + uint8_t (* SetSlotStatus)(USBD_HandleTypeDef *pdev); +} USBD_CCID_ItfTypeDef; + +/** + * @} + */ +/** @defgroup USB_CORE_Exported_Functions + * @{ + */ +uint8_t USBD_CCID_RegisterInterface(USBD_HandleTypeDef *pdev, + USBD_CCID_ItfTypeDef *fops); + +uint8_t USBD_CCID_IntMessage(USBD_HandleTypeDef *pdev); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_CCID_H */ +/** + * @} + */ + +/** + * @} + */ diff --git a/Class/CCID/Inc/usbd_ccid_cmd.h b/Class/CCID/Inc/usbd_ccid_cmd.h new file mode 100644 index 0000000..3d9d56b --- /dev/null +++ b/Class/CCID/Inc/usbd_ccid_cmd.h @@ -0,0 +1,219 @@ +/** + ****************************************************************************** + * @file usbd_ccid_cmd.h + * @author MCD Application Team + * @brief header file for the usbd_ccid_cmd.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CCID_CMD_H +#define __USBD_CCID_CMD_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#ifndef __USBD_CCID_IF_H +#include "usbd_ccid_if_template.h" +#endif + +#ifndef __USBD_CCID_SC_IF_H +#include "usbd_ccid_sc_if_template.h" +#endif + + +/* Exported types ------------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ + +/******************************************************************************/ +/* ERROR CODES for USB Bulk In Messages : bError */ +/******************************************************************************/ + +#define SLOT_NO_ERROR 0x81U +#define SLOTERROR_UNKNOWN 0x82U +/*----------------------------------------------------------------------------*/ + +/* Index of not supported / incorrect message parameter : 7Fh to 01h */ +/* These Values are used for Return Types between Firmware Layers */ +/* + Failure of a command + The CCID cannot parse one parameter or the ICC is not supporting one parameter. + Then the Slot Error register contains the index of the first bad parameter as a + 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) */ + +/* Following Parameters used in PC_to_RDR_XfrBlock */ +#define SLOTERROR_BAD_LENTGH 0x01U +#define SLOTERROR_BAD_SLOT 0x05U +#define SLOTERROR_BAD_POWERSELECT 0x07U +#define SLOTERROR_BAD_PROTOCOLNUM 0x07U +#define SLOTERROR_BAD_CLOCKCOMMAND 0x07U +#define SLOTERROR_BAD_ABRFU_3B 0x07U +#define SLOTERROR_BAD_BMCHANGES 0x07U +#define SLOTERROR_BAD_BFUNCTION_MECHANICAL 0x07U +#define SLOTERROR_BAD_ABRFU_2B 0x08U +#define SLOTERROR_BAD_LEVELPARAMETER 0x08U +#define SLOTERROR_BAD_FIDI 0x0AU +#define SLOTERROR_BAD_T01CONVCHECKSUM 0x0BU +#define SLOTERROR_BAD_GUARDTIME 0x0CU +#define SLOTERROR_BAD_WAITINGINTEGER 0x0DU +#define SLOTERROR_BAD_CLOCKSTOP 0x0EU +#define SLOTERROR_BAD_IFSC 0x0FU +#define SLOTERROR_BAD_NAD 0x10U +#define SLOTERROR_BAD_DWLENGTH 0x08U + + +/*---------- Table 6.2-2 Slot error register when bmCommandStatus = 1 */ +#define SLOTERROR_CMD_ABORTED 0xFFU +#define SLOTERROR_ICC_MUTE 0xFEU +#define SLOTERROR_XFR_PARITY_ERROR 0xFDU +#define SLOTERROR_XFR_OVERRUN 0xFCU +#define SLOTERROR_HW_ERROR 0xFBU +#define SLOTERROR_BAD_ATR_TS 0xF8U +#define SLOTERROR_BAD_ATR_TCK 0xF7U +#define SLOTERROR_ICC_PROTOCOL_NOT_SUPPORTED 0xF6U +#define SLOTERROR_ICC_CLASS_NOT_SUPPORTED 0xF5U +#define SLOTERROR_PROCEDURE_BYTE_CONFLICT 0xF4U +#define SLOTERROR_DEACTIVATED_PROTOCOL 0xF3U +#define SLOTERROR_BUSY_WITH_AUTO_SEQUENCE 0xF2U +#define SLOTERROR_PIN_TIMEOUT 0xF0U +#define SLOTERROR_PIN_CANCELLED 0xEFU +#define SLOTERROR_CMD_SLOT_BUSY 0xE0U +#define SLOTERROR_CMD_NOT_SUPPORTED 0x00U + +/* Following Parameters used in PC_to_RDR_ResetParameters */ +/* DEFAULT_FIDI_VALUE */ +#ifndef DEFAULT_FIDI +#define DEFAULT_FIDI 0x11U +#endif +#ifndef DEFAULT_T01CONVCHECKSUM +#define DEFAULT_T01CONVCHECKSUM 0x00U +#endif +#ifndef DEFAULT_EXTRA_GUARDTIME +#define DEFAULT_EXTRA_GUARDTIME 0x00U +#endif +#ifndef DEFAULT_WAITINGINTEGER +#define DEFAULT_WAITINGINTEGER 0x0AU +#endif +#ifndef DEFAULT_CLOCKSTOP +#define DEFAULT_CLOCKSTOP 0x00U +#endif +#ifndef DEFAULT_IFSC +#define DEFAULT_IFSC 0x20U +#endif +#ifndef DEFAULT_NAD +#define DEFAULT_NAD 0x00U +#endif + +/* Following Parameters used in PC_to_RDR_IccPowerOn */ +#define VOLTAGE_SELECTION_AUTOMATIC 0xFFU +#define VOLTAGE_SELECTION_3V 0x02U +#define VOLTAGE_SELECTION_5V 0x01U +#define VOLTAGE_SELECTION_1V8 0x03U + +/* +Offset=0 bmICCStatus 2 bit 0, 1, 2 + 0 - An ICC is present and active (power is on and stable, RST is inactive) + 1 - An ICC is present and inactive (not activated or shut down by hardware error) + 2 - No ICC is present + 3 - RFU +Offset=0 bmRFU 4 bits 0 RFU +Offset=6 bmCommandStatus 2 bits 0, 1, 2 + 0 - Processed without error + 1 - Failed (error code provided by the error register) + 2 - Time Extension is requested + 3 - RFU + */ + +#define BM_ICC_PRESENT_ACTIVE 0x00U +#define BM_ICC_PRESENT_INACTIVE 0x01U +#define BM_ICC_NO_ICC_PRESENT 0x02U + +#define BM_COMMAND_STATUS_OFFSET 0x06U +#define BM_COMMAND_STATUS_NO_ERROR 0x00U +#define BM_COMMAND_STATUS_FAILED (0x01U << BM_COMMAND_STATUS_OFFSET) +#define BM_COMMAND_STATUS_TIME_EXTN (0x02 << BM_COMMAND_STATUS_OFFSET) + + +#if (ATR_T01 == 0) +#define SIZE_OF_ATR 19U +#else +#define SIZE_OF_ATR 15U +#endif + +/* 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 + +#define BPROTOCOL_NUM_T0 0U +#define BPROTOCOL_NUM_T1 1U + +/************************************************************************************/ +/* ERROR CODES for RDR_TO_PC_HARDWAREERROR Message : bHardwareErrorCode */ +/************************************************************************************/ + +#define HARDWAREERRORCODE_OVERCURRENT 0x01U +#define HARDWAREERRORCODE_VOLTAGEERROR 0x02U +#define HARDWAREERRORCODE_OVERCURRENT_IT 0x04U +#define HARDWAREERRORCODE_VOLTAGEERROR_IT 0x08U + + + +#define CHK_PARAM_SLOT 0x01U +#define CHK_PARAM_DWLENGTH 0x02U +#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 + + +/* Exported functions ------------------------------------------------------- */ +uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev); +uint8_t PC_to_RDR_IccPowerOff(USBD_HandleTypeDef *pdev); +uint8_t PC_to_RDR_GetSlotStatus(USBD_HandleTypeDef *pdev); +uint8_t PC_to_RDR_XfrBlock(USBD_HandleTypeDef *pdev); +uint8_t PC_to_RDR_GetParameters(USBD_HandleTypeDef *pdev); +uint8_t PC_to_RDR_ResetParameters(USBD_HandleTypeDef *pdev); +uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev); +uint8_t PC_to_RDR_Escape(USBD_HandleTypeDef *pdev); +uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev); +uint8_t PC_to_RDR_Abort(USBD_HandleTypeDef *pdev); +uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev); +uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev); +uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev); +uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev); + +void RDR_to_PC_DataBlock(uint8_t errorCode, USBD_HandleTypeDef *pdev); +void RDR_to_PC_NotifySlotChange(USBD_HandleTypeDef *pdev); +void RDR_to_PC_SlotStatus(uint8_t errorCode, USBD_HandleTypeDef *pdev); +void RDR_to_PC_Parameters(uint8_t errorCode, USBD_HandleTypeDef *pdev); +void RDR_to_PC_Escape(uint8_t errorCode, USBD_HandleTypeDef *pdev); +void RDR_to_PC_DataRateAndClockFrequency(uint8_t errorCode, USBD_HandleTypeDef *pdev); + +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 USBD_CCID_Transfer_Data_Request(USBD_HandleTypeDef *pdev, + uint8_t *dataPointer, uint16_t dataLen); + + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_CCID_CMD_H */ diff --git a/Class/CCID/Inc/usbd_ccid_if_template.h b/Class/CCID/Inc/usbd_ccid_if_template.h new file mode 100644 index 0000000..e690077 --- /dev/null +++ b/Class/CCID/Inc/usbd_ccid_if_template.h @@ -0,0 +1,76 @@ +/** + ****************************************************************************** + * @file usbd_ccid_if_template.h + * @author MCD Application Team + * @brief header file for the usbd_ccid_if_template.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CCID_IF_TEMPLATE_H +#define __USBD_CCID_IF_TEMPLATE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_ccid.h" +#include "usbd_ccid_cmd.h" + +#ifndef __USBD_CCID_SMARTCARD_H +#include "usbd_ccid_smartcard_template.h" +#endif + +/* Exported defines ----------------------------------------------------------*/ + +/*****************************************************************************/ +/*********************** CCID Bulk Transfer State machine ********************/ +/*****************************************************************************/ +#define CCID_STATE_IDLE 0U +#define CCID_STATE_DATA_OUT 1U +#define CCID_STATE_RECEIVE_DATA 2U +#define CCID_STATE_SEND_RESP 3U +#define CCID_STATE_DATAIN 4U +#define CCID_STATE_UNCORRECT_LENGTH 5U + +#define DIR_IN 0U +#define DIR_OUT 1U +#define BOTH_DIR 2U + +/************ Value of the Interrupt transfer status to set ******************/ +#define IntrStatus_Complete 1U +#define IntrStatus_Reset 0U +/************** slot change status *******************************************/ +#define SlotStatus_Changed 1U +#define SlotStatus_Reset 0U + +/* Exported types ------------------------------------------------------------*/ +extern USBD_HandleTypeDef USBD_Device; + +/* CCID Interface callback */ +extern USBD_CCID_ItfTypeDef USBD_CCID_If_fops; + +/* Exported macros -----------------------------------------------------------*/ +/* Exported variables --------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_CCID_IF_TEMPLATE_H */ diff --git a/Class/CCID/Inc/usbd_ccid_sc_if_template.h b/Class/CCID/Inc/usbd_ccid_sc_if_template.h new file mode 100644 index 0000000..29ba8b4 --- /dev/null +++ b/Class/CCID/Inc/usbd_ccid_sc_if_template.h @@ -0,0 +1,100 @@ +/** + ****************************************************************************** + * @file usbd_ccid_sc_if_template.h + * @author MCD Application Team + * @brief header file for the usbd_ccid_sc_if_template.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CCID_SC_IF_TEMPLATE_H +#define __USBD_CCID_SC_IF_TEMPLATE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_ccid.h" +#include "usbd_ccid_cmd.h" + +#ifndef __USBD_CCID_SMARTCARD_H +#include "usbd_ccid_smartcard_template.h" +#endif + +/* Exported constants --------------------------------------------------------*/ +/* Exported types ------------------------------------------------------------*/ +typedef struct +{ + uint8_t voltage; /* Voltage for the Card Already Selected */ + uint8_t USART_GuardTime; + uint8_t SC_A2R_FiDi; + uint8_t SC_hostFiDi; + uint8_t USART_DefaultGuardTime; + uint32_t USART_BaudRate; +} SC_Param_t; + +#pragma pack(1) +typedef struct +{ + uint8_t bmFindexDindex; + uint8_t bmTCCKST0; + uint8_t bGuardTimeT0; + uint8_t bWaitingIntegerT0; + uint8_t bClockStop; + uint8_t bIfsc; + uint8_t bNad; +} Protocol_01_DataTypeDef; +#pragma pack() + +extern Protocol_01_DataTypeDef ProtocolData; +extern SC_Param_t SC_Param; + +/* Exported macro ------------------------------------------------------------*/ +#define MAX_EXTRA_GUARD_TIME (0xFF - DEFAULT_EXTRA_GUARDTIME) + +/* Following macros are used for SC_XferBlock command */ +#define XFER_BLK_SEND_DATA 1U /* Command is for issuing the data */ +#define XFER_BLK_RECEIVE_DATA 2U /* Command is for receiving the data */ +#define XFER_BLK_NO_DATA 3U /* Command type is No data exchange */ + +/* Exported functions ------------------------------------------------------- */ +/* APPLICATION LAYER ---------------------------------------------------------*/ +void SC_Itf_InitParams(void); +void SC_Itf_IccPowerOn(uint8_t voltage); +void SC_Itf_IccPowerOff(void); +uint8_t SC_GetState(void); +uint8_t SC_Itf_XferBlock(uint8_t *ptrBlock, uint32_t blockLen, + uint16_t expectedLen, + USBD_CCID_BulkIn_DataTypeDef *CCID_BulkIn_Data); + +uint8_t SC_Itf_SetParams(Protocol_01_DataTypeDef *pPtr, uint8_t T_01); +uint8_t SC_Itf_Escape(uint8_t *escapePtr, uint32_t escapeLen, + uint8_t *responseBuff, uint32_t *responseLen); + +uint8_t SC_Itf_SetClock(uint8_t bClockCommand); +uint8_t SC_Itf_T0Apdu(uint8_t bmChanges, uint8_t bClassGetResponse, + uint8_t bClassEnvelope); + +uint8_t SC_Itf_Mechanical(uint8_t bFunction); +uint8_t SC_Itf_SetDataRateAndClockFrequency(uint32_t dwClockFrequency, + uint32_t dwDataRate); + +uint8_t SC_Itf_Secure(uint32_t dwLength, uint8_t bBWI, uint16_t wLevelParameter, + uint8_t *pbuf, uint32_t *returnLen); + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_CCID_SC_IF_TEMPLATE_H */ diff --git a/Class/CCID/Inc/usbd_ccid_smartcard_template.h b/Class/CCID/Inc/usbd_ccid_smartcard_template.h new file mode 100644 index 0000000..ac97a14 --- /dev/null +++ b/Class/CCID/Inc/usbd_ccid_smartcard_template.h @@ -0,0 +1,279 @@ +/** + ****************************************************************************** + * @file usbd_ccid_smartcard_template.h + * @author MCD Application Team + * @brief header file for the usbd_ccid_smartcard_template.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CCID_SMARTCARD_TEMPLATE_H +#define __USBD_CCID_SMARTCARD_TEMPLATE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Includes ------------------------------------------------------------------*/ +#ifndef __USBD_CCID_IF_H +#include "usbd_ccid_if_template.h" +#endif + +/* Exported constants --------------------------------------------------------*/ +#define T0_PROTOCOL 0x00U /* T0 protocol */ +#define T1_PROTOCOL 0x01U /* T1 protocol */ +#define DIRECT 0x3BU /* Direct bit convention */ +#define INDIRECT 0x3FU /* Indirect bit convention */ +#define SETUP_LENGTH 20U +#define HIST_LENGTH 20U + +#define SC_TRANSMIT_TIMEOUT 200U /* Direction to transmit */ +#define MAX_PROTOCOLLEVEL 7U /* Maximum levels of protocol */ +#define MAX_INTERFACEBYTE 4U /* Maximum number of interface bytes per protocol */ +#define LC_MAX 24U +#define SC_RECEIVE_TIMEOUT 0x8000U /* Direction to reader */ + +/* T=1 protocol constants */ +#define T1_I_BLOCK 0x00U /* PCB (I-block: b8 = 0) */ +#define T1_R_BLOCK 0x80U /* PCB (R-block: b8 b7 = 10) */ +#define T1_S_BLOCK 0xC0U /* PCB (S-block: b8 b7 = 11) */ + +/* I block */ +#define T1_I_SEQ_SHIFT 6U /* N(S) position (bit 7) */ + +/* R block */ +#define T1_IS_ERROR(pcb) ((pcb) & 0x0FU) +#define T1_EDC_ERROR 0x01U /* [b6..b1] = 0-N(R)-0001 */ +#define T1_OTHER_ERROR 0x02U /* [b6..b1] = 0-N(R)-0010 */ +#define T1_R_SEQ_SHIFT 4U /* N(R) position (b5) */ + +/* S block */ +#define T1_S_RESPONSE 0x20U /* If response: set bit b6, if request reset b6 in PCB S-Block */ +#define T1_S_RESYNC 0x00U /* RESYNCH: b6->b1: 000000 of PCB S-Block */ +#define T1_S_IFS 0x01U /* IFS: b6->b1: 000001 of PCB S-Block */ +#define T1_S_ABORT 0x02U /* ABORT: b6->b1: 000010 of PCB S-Block */ +#define T1_S_WTX 0x03U /* WTX: b6->b1: 000011 of PCB S-Block */ + +#define NAD 0U /* NAD byte position in the block */ +#define PCB 1U /* PCB byte position in the block */ +#define LEN 2U /* LEN byte position in the block */ +#define DATA 3U /* The position of the first byte of INF field in the block */ + +/* Modifiable parameters */ +#define SAD 0x0U /* Source address: reader (allowed values 0 -> 7) */ +#define DAD 0x0U /* Destination address: card (allowed values 0 -> 7) */ +#define IFSD_VALUE 254U /* Max length of INF field Supported by the reader */ +#define SC_FILE_SIZE 0x100U /* File size */ +#define SC_FILE_ID 0x0001U /* File identifier */ +#define SC_CLASS 0x00U + +/* Constant parameters */ +#define INS_SELECT_FILE 0xA4U /* Select file instruction */ +#define INS_READ_FILE 0xB0U /* Read file instruction */ +#define INS_WRITE_FILE 0xD6U /* Write file instruction */ +#define TRAILER_LENGTH 2U /* Trailer length (SW1 and SW2: 2 bytes) */ + +#define SC_T1_RECEIVE_SUCCESS 0U +#define SC_T1_BWT_TIMEOUT 1U +#define SC_T1_CWT_TIMEOUT 2U + +#define DEFAULT_FIDI_VALUE 0x11U +#define PPS_REQUEST 0xFFU + +/* SC Tree Structure ----------------------------------------------------------- + MasterFile + ________|___________ + | | | + System UserData Note +------------------------------------------------------------------------------*/ + +/* SC ADPU Command: Operation Code -------------------------------------------*/ +#define SC_CLA_NAME 0x00U + +/*------------------------ Data Area Management Commands ---------------------*/ +#define SC_SELECT_FILE 0xA4U +#define SC_GET_RESPONCE 0xC0U +#define SC_STATUS 0xF2U +#define SC_UPDATE_BINARY 0xD6U +#define SC_READ_BINARY 0xB0U +#define SC_WRITE_BINARY 0xD0U +#define SC_UPDATE_RECORD 0xDCU +#define SC_READ_RECORD 0xB2U + +/*-------------------------- Administrative Commands -------------------------*/ +#define SC_CREATE_FILE 0xE0U + +/*-------------------------- Safety Management Commands ----------------------*/ +#define SC_VERIFY 0x20U +#define SC_CHANGE 0x24U +#define SC_DISABLE 0x26U +#define SC_ENABLE 0x28U +#define SC_UNBLOCK 0x2CU +#define SC_EXTERNAL_AUTH 0x82U +#define SC_GET_CHALLENGE 0x84U + +/*-------------------------- Smartcard Interface Byte-------------------------*/ +#define SC_INTERFACEBYTE_TA 0U /* Interface byte TA(i) */ +#define SC_INTERFACEBYTE_TB 1U /* Interface byte TB(i) */ +#define SC_INTERFACEBYTE_TC 2U /* Interface byte TC(i) */ +#define SC_INTERFACEBYTE_TD 3U /* Interface byte TD(i) */ + +/*-------------------------- Answer to reset Commands ------------------------*/ +#define SC_GET_A2R 0x00U + +/* SC STATUS: Status Code ----------------------------------------------------*/ +#define SC_EF_SELECTED 0x9FU +#define SC_DF_SELECTED 0x9FU +#define SC_OP_TERMINATED 0x9000U + +/* Smartcard Voltage */ +#define SC_VOLTAGE_5V 0x00U +#define SC_VOLTAGE_3V 0x01U +#define SC_VOLTAGE_NOINIT 0xFFU +/*----------------- ATR Protocole supported ----------------------------------*/ +#define ATR_T01 0x00U + + +/* Exported types ------------------------------------------------------------*/ +typedef enum +{ + SC_POWER_ON = 0x00, + SC_RESET_LOW = 0x01, + SC_RESET_HIGH = 0x02, + SC_ACTIVE = 0x03, + SC_ACTIVE_ON_T0 = 0x04, + SC_ACTIVE_ON_T1 = 0x05, + SC_POWER_OFF = 0x06, + SC_NO_INIT = 0x07 + +} SC_State; + +/* 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; + +/* 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; + +/* 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 TCK; +} SC_ATR; + +/* ADPU-Header command structure ---------------------------------------------*/ +typedef struct +{ + uint8_t CLA; /* Command class */ + uint8_t INS; /* Operation code */ + uint8_t P1; /* Selection Mode */ + uint8_t P2; /* Selection Option */ +} SC_Header; + +/* ADPU-Body command structure -----------------------------------------------*/ +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; + +/* ADPU Command structure ----------------------------------------------------*/ +typedef struct +{ + SC_Header Header; + SC_Body Body; +} SC_ADPU_Commands; + +/* 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; + +/* SC Command Status -----------------------------------------------------*/ +typedef enum +{ + SC_CS_FAILED = 0x00, + SC_CS_PIN_ENABLED = 0x01, + SC_CS_PIN_VERIFIED = 0x02, + SC_CS_READ = 0x03, + SC_CS_PIN_CHANGED = 0x04 + +} SC_Command_State; +/* SC Response Status -----------------------------------------------------*/ +typedef enum +{ + REP_OK = 0x00, + REP_NOT_OK = 0x01, + REP_NOT_SUPP = 0x02, + REP_ENABLED = 0x03, + REP_CHANGE = 0x04 + +} REP_Command_t; +/* Conforming of Command with ICC APP -----------------------------------------------------*/ +typedef enum +{ + Command_OK = 0x00, + Command_NOT_OK = 0x01, + +} Command_State_t; + +typedef enum +{ + SC_DISABLED = 0U, + SC_ENABLED = !SC_DISABLED +} SCPowerState; + +/* Exported macro ------------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ +/* APPLICATION LAYER ---------------------------------------------------------*/ +void SC_Handler(SC_State *SCState, SC_ADPU_Commands *SC_ADPU, SC_ADPU_Response *SC_Response); +void SC_PowerCmd(SCPowerState NewState); +void SC_ParityErrorHandler(void); +void SC_PTSConfig(void); +uint8_t SC_Detect(void); +uint32_t SC_GetDTableValue(uint32_t idx); +void SC_VoltageConfig(uint32_t SC_Voltage); +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 uint8_t ProtocolNUM_OUT; +extern SC_ADPU_Commands SC_ADPU; + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_CCID_SMARTCARD_TEMPLATE_H */ diff --git a/Class/CCID/Src/usbd_ccid.c b/Class/CCID/Src/usbd_ccid.c new file mode 100644 index 0000000..0f1c973 --- /dev/null +++ b/Class/CCID/Src/usbd_ccid.c @@ -0,0 +1,968 @@ +/** + ****************************************************************************** + * @file usbd_ccid.c + * @author MCD Application Team + * @brief This file provides the high layer firmware functions to manage + * all the functionalities of the USB CCID Class: + * + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + * @verbatim + * + * =================================================================== + * CCID Class Driver Description + * =================================================================== + * This module manages the Specification for Integrated Circuit(s) + * Cards Interface Revision 1.1 + * This driver implements the following aspects of the specification: + * - Device descriptor management + * - Configuration descriptor management + * - Enumeration as CCID device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN) + * and enumeration for each implemented memory interface + * - Bulk OUT/IN data Transfers + * - Requests management + * + * @endverbatim + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_ccid.h" +#include "usbd_ccid_cmd.h" +#include "usbd_ctlreq.h" +/** @addtogroup STM32_USB_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_CCID + * @brief usbd core module + * @{ + */ + +/** @defgroup USBD_CCID_Private_TypesDefinitions + * @{ + */ +/** + * @} + */ + + +/** @defgroup USBD_CCID_Private_Defines + * @{ + */ +/** + * @} + */ + + +/** @defgroup USBD_CCID_Private_Macros + * @{ + */ + +/** + * @} + */ + + +/** @defgroup USBD_CCID_Private_FunctionPrototypes + * @{ + */ +static uint8_t USBD_CCID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx); +static uint8_t USBD_CCID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx); +static uint8_t USBD_CCID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); +static uint8_t USBD_CCID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum); +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); + +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); + +/** + * @} + */ + +/** @defgroup USBD_CCID_Private_Variables + * @{ + */ + + +/* CCID interface class callbacks structure */ +USBD_ClassTypeDef USBD_CCID = +{ + USBD_CCID_Init, + USBD_CCID_DeInit, + USBD_CCID_Setup, + NULL, /*EP0_TxSent*/ + NULL, /*EP0_RxReady*/ + USBD_CCID_DataIn, + USBD_CCID_DataOut, + NULL, /*SOF */ + NULL, /*ISOIn*/ + NULL, /*ISOOut*/ + USBD_CCID_GetHSCfgDesc, + USBD_CCID_GetFSCfgDesc, + USBD_CCID_GetOtherSpeedCfgDesc, + USBD_CCID_GetDeviceQualifierDescriptor, +}; + +/* USB CCID device Configuration Descriptor */ +__ALIGN_BEGIN static uint8_t USBD_CCID_CfgHSDesc[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, /* 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, /* 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_FS_MAX_PACKET_SIZE), + HIBYTE(CCID_DATA_FS_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_FS_MAX_PACKET_SIZE), + HIBYTE(CCID_DATA_FS_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_FS_BINTERVAL /* Polling interval in milliseconds */ +}; + +/* USB Standard Device Descriptor */ +__ALIGN_BEGIN static uint8_t USBD_CCID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = +{ + USB_LEN_DEV_QUALIFIER_DESC, + USB_DESC_TYPE_DEVICE_QUALIFIER, + 0x00, + 0x02, + 0x00, + 0x00, + 0x00, + 0x40, + 0x01, + 0x00, +}; + + +/** + * @} + */ + +/** @defgroup USBD_CCID_Private_Functions + * @{ + */ + +/** + * @brief USBD_CCID_Init + * Initialize the CCID interface + * @param pdev: device instance + * @param cfgidx: Configuration index + * @retval status + */ +static uint8_t USBD_CCID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) +{ + USBD_CCID_HandleTypeDef *hccid; + UNUSED(cfgidx); + + /* Allocate CCID structure */ + hccid = (USBD_CCID_HandleTypeDef *)USBD_malloc(sizeof(USBD_CCID_HandleTypeDef)); + + if (hccid == NULL) + { + pdev->pClassData = NULL; + return (uint8_t)USBD_EMEM; + } + + pdev->pClassData = (void *)hccid; + + /* Init the CCID parameters into a state where it can receive a new command message */ + hccid->USBD_CCID_Param.bAbortRequestFlag = 0U; + hccid->USBD_CCID_Param.bSeq = 0U; + hccid->USBD_CCID_Param.bSlot = 0U; + hccid->MaxPcktLen = (pdev->dev_speed == USBD_SPEED_HIGH) ? \ + 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; + + /* 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; + + /* Open INTR EP IN */ + (void)USBD_LL_OpenEP(pdev, CCID_CMD_EP, + USBD_EP_TYPE_INTR, CCID_CMD_PACKET_SIZE); + pdev->ep_in[CCID_CMD_EP & 0xFU].is_used = 1U; + + /* Init physical Interface components */ + ((USBD_CCID_ItfTypeDef *)pdev->pUserData)->Init(pdev); + + /* Prepare Out endpoint to receive next packet */ + (void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP, + hccid->data, hccid->MaxPcktLen); + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_CCID_DeInit + * DeInitialize the CCID layer + * @param pdev: device instance + * @param cfgidx: Configuration index + * @retval status + */ +static uint8_t USBD_CCID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) +{ + UNUSED(cfgidx); + + /* Close EP IN */ + (void)USBD_LL_CloseEP(pdev, CCID_IN_EP); + pdev->ep_in[CCID_IN_EP & 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; + + /* Close EP Command */ + (void)USBD_LL_CloseEP(pdev, CCID_CMD_EP); + pdev->ep_in[CCID_CMD_EP & 0xFU].is_used = 0U; + + /* DeInit physical Interface components */ + if (pdev->pClassData != NULL) + { + ((USBD_CCID_ItfTypeDef *)pdev->pUserData)->DeInit(pdev); + (void)USBD_free(pdev->pClassData); + pdev->pClassData = NULL; + } + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_CCID_Setup + * Handle the CCID specific requests + * @param pdev: instance + * @param req: usb requests + * @retval status + */ +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_StatusTypeDef ret = USBD_OK; + uint8_t ifalt = 0U; + uint16_t status_info = 0U; + uint16_t len; + + switch (req->bmRequest & USB_REQ_TYPE_MASK) + { + /* Class request */ + case USB_REQ_TYPE_CLASS : + if (req->wLength != 0U) + { + len = MIN(CCID_EP0_BUFF_SIZ, req->wLength); + if ((req->bmRequest & 0x80U) != 0U) + { + hCCIDitf->Control(req->bRequest, hccid->data, &len); + (void)USBD_CtlSendData(pdev, hccid->data, len); + } + else + { + (void)USBD_CtlPrepareRx(pdev, hccid->data, len); + } + } + else + { + len = 0U; + hCCIDitf->Control(req->bRequest, (uint8_t *)&req->wValue, &len); + } + break; + + /* Interface & Endpoint request */ + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) + { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + (void)USBD_CtlSendData(pdev, &ifalt, 1U); + } + else + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE: + if (pdev->dev_state != USBD_STATE_CONFIGURED) + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_CLEAR_FEATURE: + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } + + return (uint8_t)ret; +} + +/** + * @brief USBD_CCID_DataIn + * Data sent on non-control IN endpoint + * @param pdev: device instance + * @param epnum: endpoint number + * @retval status + */ +static uint8_t USBD_CCID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + + if (epnum == (CCID_IN_EP & 0x7FU)) + { + /* Filter the epnum by masking with 0x7f (mask of IN Direction) */ + + /*************** Handle Bulk Transfer IN data completion *****************/ + + switch (hccid->blkt_state) + { + case CCID_STATE_SEND_RESP: + + /* won't wait ack to avoid missing a command */ + hccid->blkt_state = CCID_STATE_IDLE; + + /* Prepare EP to Receive Cmd */ + (void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP, + hccid->data, CCID_DATA_FS_MAX_PACKET_SIZE); + break; + + default: + break; + } + } + else if (epnum == (CCID_CMD_EP & 0x7FU)) + { + /* Filter the epnum by masking with 0x7f (mask of IN Direction) */ + + /*************** Handle Interrupt Transfer IN data completion *****************/ + + (void)USBD_CCID_IntMessage(pdev); + } + else + { + return (uint8_t)USBD_FAIL; + } + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_CCID_DataOut + * Data received on non-control Out endpoint + * @param pdev: device instance + * @param epnum: endpoint number + * @retval status + */ +static uint8_t USBD_CCID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint16_t CurrPcktLen; + + if (hccid == NULL) + { + return (uint8_t)USBD_EMEM; + } + + if (epnum == CCID_OUT_EP) + { + CurrPcktLen = (uint16_t)USBD_GetRxCount(pdev, epnum); + + switch (hccid->blkt_state) + { + case CCID_STATE_IDLE: + + if (CurrPcktLen >= (uint16_t)CCID_CMD_HEADER_SIZE) + { + hccid->UsbMessageLength = CurrPcktLen; /* Store for future use */ + + /* Fill CCID_BulkOut Data Buffer from USB Buffer */ + (void)USBD_CCID_ReceiveCmdHeader(pdev, (uint8_t *)&hccid->UsbBlkOutData.bMessageType, + (uint16_t)CurrPcktLen); + + /* + Refer : 6 CCID Messages + The response messages always contain the exact same slot number, + and sequence number fields from the header that was contained in + the Bulk-OUT command message. + */ + hccid->UsbBlkInData.bSlot = hccid->UsbBlkOutData.bSlot; + hccid->UsbBlkInData.bSeq = hccid->UsbBlkOutData.bSeq; + + if (CurrPcktLen < hccid->MaxPcktLen) + { + /* Short message, less than the EP Out Size, execute the command, + if parameter like dwLength is too big, the appropriate command will + give an error */ + (void)USBD_CCID_DispatchCommand(pdev); + } + else + { + /* Check if length of data to be sent by host is > buffer size */ + if (hccid->UsbBlkOutData.dwLength > (uint32_t)ABDATA_SIZE) + { + /* Too long data received.... Error ! */ + hccid->blkt_state = CCID_STATE_UNCORRECT_LENGTH; + } + + else + { + /* Expect more data on OUT EP */ + hccid->blkt_state = CCID_STATE_RECEIVE_DATA; + + /* Prepare EP to Receive next Cmd */ + (void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP, + hccid->data, hccid->MaxPcktLen); + + } /* if (CurrPcktLen == CCID_DATA_MAX_PACKET_SIZE) ends */ + } /* if (CurrPcktLen >= CCID_DATA_MAX_PACKET_SIZE) ends */ + } /* if (CurrPcktLen >= CCID_CMD_HEADER_SIZE) ends */ + else + { + if (CurrPcktLen == 0x00U) /* Zero Length Packet Received */ + { + hccid->blkt_state = CCID_STATE_IDLE; + } + } + + break; + + case CCID_STATE_RECEIVE_DATA: + hccid->UsbMessageLength += CurrPcktLen; + + if (CurrPcktLen < hccid->MaxPcktLen) + { + /* Short message, less than the EP Out Size, execute the command, + if parameter like dwLength is too big, the appropriate command will + give an error */ + + /* Full command is received, process the Command */ + (void)USBD_CCID_ReceiveCmdHeader(pdev, (uint8_t *)&hccid->UsbBlkOutData.bMessageType, + (uint16_t)CurrPcktLen); + + (void)USBD_CCID_DispatchCommand(pdev); + } + else if (CurrPcktLen == hccid->MaxPcktLen) + { + if (hccid->UsbMessageLength < (hccid->UsbBlkOutData.dwLength + (uint32_t)CCID_CMD_HEADER_SIZE)) + { + (void)USBD_CCID_ReceiveCmdHeader(pdev, (uint8_t *)&hccid->UsbBlkOutData.bMessageType, + (uint16_t)CurrPcktLen); /* Copy data */ + + /* Prepare EP to Receive next Cmd */ + (void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP, + hccid->data, hccid->MaxPcktLen); + } + else if (hccid->UsbMessageLength == (hccid->UsbBlkOutData.dwLength + (uint32_t)CCID_CMD_HEADER_SIZE)) + { + /* Full command is received, process the Command */ + (void)USBD_CCID_ReceiveCmdHeader(pdev, (uint8_t *)&hccid->UsbBlkOutData.bMessageType, + (uint16_t)CurrPcktLen); + + (void)USBD_CCID_DispatchCommand(pdev); + } + else + { + /* Too long data received.... Error ! */ + hccid->blkt_state = CCID_STATE_UNCORRECT_LENGTH; + } + } + else + { + /* Too long data received.... Error ! */ + hccid->blkt_state = CCID_STATE_UNCORRECT_LENGTH; + } + break; + + case CCID_STATE_UNCORRECT_LENGTH: + hccid->blkt_state = CCID_STATE_IDLE; + break; + + default: + break; + } + } + else + { + return (uint8_t)USBD_FAIL; + } + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_CCID_DispatchCommand + * Parse the commands and Process command + * @param pdev: device instance + * @retval status value + */ +static uint8_t USBD_CCID_DispatchCommand(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint8_t errorCode; + + switch (hccid->UsbBlkOutData.bMessageType) + { + case PC_TO_RDR_ICCPOWERON: + errorCode = PC_to_RDR_IccPowerOn(pdev); + RDR_to_PC_DataBlock(errorCode, pdev); + break; + + case PC_TO_RDR_ICCPOWEROFF: + errorCode = PC_to_RDR_IccPowerOff(pdev); + RDR_to_PC_SlotStatus(errorCode, pdev); + break; + + case PC_TO_RDR_GETSLOTSTATUS: + errorCode = PC_to_RDR_GetSlotStatus(pdev); + RDR_to_PC_SlotStatus(errorCode, pdev); + break; + + case PC_TO_RDR_XFRBLOCK: + errorCode = PC_to_RDR_XfrBlock(pdev); + RDR_to_PC_DataBlock(errorCode, pdev); + break; + + case PC_TO_RDR_GETPARAMETERS: + errorCode = PC_to_RDR_GetParameters(pdev); + RDR_to_PC_Parameters(errorCode, pdev); + break; + + case PC_TO_RDR_RESETPARAMETERS: + errorCode = PC_to_RDR_ResetParameters(pdev); + RDR_to_PC_Parameters(errorCode, pdev); + break; + + case PC_TO_RDR_SETPARAMETERS: + errorCode = PC_to_RDR_SetParameters(pdev); + RDR_to_PC_Parameters(errorCode, pdev); + break; + + case PC_TO_RDR_ESCAPE: + errorCode = PC_to_RDR_Escape(pdev); + RDR_to_PC_Escape(errorCode, pdev); + break; + + case PC_TO_RDR_ICCCLOCK: + errorCode = PC_to_RDR_IccClock(pdev); + RDR_to_PC_SlotStatus(errorCode, pdev); + break; + + case PC_TO_RDR_ABORT: + errorCode = PC_to_RDR_Abort(pdev); + RDR_to_PC_SlotStatus(errorCode, pdev); + break; + + case PC_TO_RDR_T0APDU: + errorCode = PC_TO_RDR_T0Apdu(pdev); + RDR_to_PC_SlotStatus(errorCode, pdev); + break; + + case PC_TO_RDR_MECHANICAL: + errorCode = PC_TO_RDR_Mechanical(pdev); + RDR_to_PC_SlotStatus(errorCode, pdev); + break; + + case PC_TO_RDR_SETDATARATEANDCLOCKFREQUENCY: + errorCode = PC_TO_RDR_SetDataRateAndClockFrequency(pdev); + RDR_to_PC_DataRateAndClockFrequency(errorCode, pdev); + break; + + case PC_TO_RDR_SECURE: + errorCode = PC_TO_RDR_Secure(pdev); + RDR_to_PC_DataBlock(errorCode, pdev); + break; + + default: + RDR_to_PC_SlotStatus(SLOTERROR_CMD_NOT_SUPPORTED, pdev); + break; + } + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_CCID_Transfer_Data_Request + * Prepare the request response to be sent to the host + * @param pdev: device instance + * @param dataPointer: Pointer to the data buffer to send + * @param dataLen : number of bytes to send + * @retval status value + */ +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; + + UNUSED(dataPointer); + + hccid->blkt_state = CCID_STATE_SEND_RESP; + hccid->UsbMessageLength = hccid->UsbBlkInData.dwLength + (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, + (uint16_t)MIN(CCID_DATA_FS_MAX_PACKET_SIZE, hccid->UsbMessageLength)); + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_CCID_ReceiveCmdHeader + * Receive the Data from USB BulkOut Buffer to Pointer + * @param pdev: device instance + * @param pDst: destination address to copy the buffer + * @param u8length: length of data to copy + * @retval status + */ +static uint8_t USBD_CCID_ReceiveCmdHeader(USBD_HandleTypeDef *pdev, + uint8_t *pDst, uint16_t u8length) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint8_t *pdst = pDst; + uint32_t Counter; + + for (Counter = 0U; Counter < u8length; Counter++) + { + *pdst = hccid->data[Counter]; + pdst++; + } + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_CCID_IntMessage + * Send the Interrupt-IN data to the host + * @param pdev: device instance + * @retval None + */ +uint8_t USBD_CCID_IntMessage(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + + /* Check if there is change in Smartcard Slot status */ + if (CCID_IsSlotStatusChange(pdev) != 0U) + { + /* Check Slot Status is changed. Card is Removed/Fitted */ + RDR_to_PC_NotifySlotChange(pdev); + + /* Set the Slot status */ + ((USBD_CCID_ItfTypeDef *)pdev->pUserData)->SetSlotStatus(pdev); + + (void)USBD_LL_Transmit(pdev, CCID_CMD_EP, hccid->UsbIntData, 2U); + } + else + { + /* Set the Slot status */ + ((USBD_CCID_ItfTypeDef *)pdev->pUserData)->SetSlotStatus(pdev); + } + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_CCID_GetHSCfgDesc + * Return configuration descriptor + * @param length pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t *USBD_CCID_GetHSCfgDesc(uint16_t *length) +{ + *length = (uint16_t)sizeof(USBD_CCID_CfgHSDesc); + return USBD_CCID_CfgHSDesc; +} +/** + * @brief USBD_CCID_GetFSCfgDesc + * Return configuration descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t *USBD_CCID_GetFSCfgDesc(uint16_t *length) +{ + *length = (uint16_t)sizeof(USBD_CCID_CfgFSDesc); + return USBD_CCID_CfgFSDesc; +} + +/** + * @brief USBD_CCID_GetOtherSpeedCfgDesc + * Return configuration descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t *USBD_CCID_GetOtherSpeedCfgDesc(uint16_t *length) +{ + *length = (uint16_t)sizeof(USBD_CCID_CfgFSDesc); + return USBD_CCID_CfgFSDesc; +} + +/** + * @brief USBD_CCID_GetDeviceQualifierDescriptor + * return Device Qualifier descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t *USBD_CCID_GetDeviceQualifierDescriptor(uint16_t *length) +{ + *length = (uint16_t)(sizeof(USBD_CCID_DeviceQualifierDesc)); + return USBD_CCID_DeviceQualifierDesc; +} + +/** + * @brief USBD_CCID_RegisterInterface + * @param pdev: device instance + * @param fops: CD Interface callback + * @retval status + */ +uint8_t USBD_CCID_RegisterInterface(USBD_HandleTypeDef *pdev, + USBD_CCID_ItfTypeDef *fops) +{ + if (fops == NULL) + { + return (uint8_t)USBD_FAIL; + } + + pdev->pUserData = fops; + + return (uint8_t)USBD_OK; +} + +/** + * @} + */ diff --git a/Class/CCID/Src/usbd_ccid_cmd.c b/Class/CCID/Src/usbd_ccid_cmd.c new file mode 100644 index 0000000..7212bd9 --- /dev/null +++ b/Class/CCID/Src/usbd_ccid_cmd.c @@ -0,0 +1,1094 @@ +/** + ****************************************************************************** + * @file usbd_ccid_cmd.c + * @author MCD Application Team + * @brief CCID command (Bulk-OUT Messages / Bulk-IN Messages) handling + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_ccid.h" +#include "usbd_ccid_cmd.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* 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); + +/* Private functions ---------------------------------------------------------*/ + +/******************************************************************************/ +/* BULK OUT ROUTINES */ +/******************************************************************************/ + +/** + * @brief PC_to_RDR_IccPowerOn + * PC_TO_RDR_ICCPOWERON message execution, apply voltage and get ATR + * @param pdev: device instance + * @retval status of the command execution + */ +uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev) +{ + /* Apply the ICC VCC + 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; + uint8_t voltage; + uint8_t sc_voltage = 0U; + uint8_t index; + uint8_t error; + + 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_ABORT); + if (error != 0U) + { + return error; + } + + /* Voltage that is applied to the ICC + 00h Automatic Voltage Selection + 01h 5.0 volts + 02h 3.0 volts + 03h 1.8 volts + */ + /* UsbBlkOutData.bSpecific_0 Contains bPowerSelect */ + voltage = hccid->UsbBlkOutData.bSpecific_0; + if (voltage >= VOLTAGE_SELECTION_1V8) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + return SLOTERROR_BAD_POWERSELECT; /* The Voltage specified is out of Spec */ + } + + /* Correct Voltage Requested by the Host */ + if ((voltage == VOLTAGE_SELECTION_AUTOMATIC) || (voltage == VOLTAGE_SELECTION_3V)) + { + sc_voltage = SC_VOLTAGE_3V; + } + else + { + if (voltage == VOLTAGE_SELECTION_5V) + { + sc_voltage = SC_VOLTAGE_5V; + } + } + SC_Itf_IccPowerOn(sc_voltage); + + /* Check if the Card has come to Active State*/ + error = CCID_CheckCommandParams(pdev, (uint32_t)CHK_ACTIVE_STATE); + + if (error != 0U) + { + /* Check if Voltage is not Automatic */ + if (voltage != 0U) + { + /* If Specific Voltage requested by Host i.e 3V or 5V*/ + return error; + } + else + { + /* Automatic Voltage selection requested by Host */ + + if (sc_voltage != SC_VOLTAGE_5V) + { + /* If voltage selected was Automatic and 5V is not yet tried */ + sc_voltage = SC_VOLTAGE_5V; + SC_Itf_IccPowerOn(sc_voltage); + + /* Check again the State */ + error = CCID_CheckCommandParams(pdev, (uint32_t)CHK_ACTIVE_STATE); + if (error != 0U) + { + return error; + } + } + else + { + /* Voltage requested from Host was 5V already*/ + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE)); + return error; + } + } /* Voltage Selection was automatic */ + } /* If Active State */ + + /* ATR is received, No Error Condition Found */ + hccid->UsbBlkInData.dwLength = SIZE_OF_ATR; + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + + for (index = 0U; index < SIZE_OF_ATR; index++) + { + /* Copy the ATR to the Response Buffer */ + hccid->UsbBlkInData.abData[index] = SC_ATR_Table[index]; + } + + return SLOT_NO_ERROR; +} + +/** + * @brief PC_to_RDR_IccPowerOff + * Icc VCC is switched Off + * @param pdev: device instance + * @retval error: status of the command execution + */ +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 | + CHK_PARAM_DWLENGTH); + if (error != 0U) + { + return error; + } + /* Command is ok, Check for Card Presence */ + if (SC_Detect() != 0U) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_INACTIVE)); + } + else + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_NO_ICC_PRESENT)); + } + + /* Power OFF the card */ + SC_Itf_IccPowerOff(); + + return SLOT_NO_ERROR; +} + +/** + * @brief PC_to_RDR_GetSlotStatus + * Provides the Slot status to the host + * @param pdev: device instance + * @retval status of the command execution + */ +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); + if (error != 0U) + { + return error; + } + + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + return SLOT_NO_ERROR; +} + + +/** + * @brief PC_to_RDR_XfrBlock + * Handles the Block transfer from Host. + * Response to this command message is the RDR_to_PC_DataBlock + * @param pdev: device instance + * @retval status of the command execution + */ +uint8_t PC_to_RDR_XfrBlock(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + 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); + if (error != 0U) + { + return error; + } + if (hccid->UsbBlkOutData.dwLength > ABDATA_SIZE) + { + /* Check amount of Data Sent by Host is > than memory allocated ? */ + + return SLOTERROR_BAD_DWLENGTH; + } + + /* wLevelParameter = Size of expected data to be returned by the + bulk-IN endpoint */ + expectedLength = (uint8_t)((hccid->UsbBlkOutData.bSpecific_2 << 8) | + hccid->UsbBlkOutData.bSpecific_1); + + hccid->UsbBlkInData.dwLength = (uint16_t)expectedLength; + + error = SC_Itf_XferBlock(&(hccid->UsbBlkOutData.abData[0]), + hccid->UsbBlkOutData.dwLength, + expectedLength, &hccid->UsbBlkInData); + + if (error != SLOT_NO_ERROR) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + } + else + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + error = SLOT_NO_ERROR; + } + + return error; +} + +/** + * @brief PC_to_RDR_GetParameters + * Provides the ICC parameters to the host + * Response to this command message is the RDR_to_PC_Parameters + * @param pdev: device instance + * @retval status of the command execution + */ +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); + if (error != 0U) + { + return error; + } + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + + return SLOT_NO_ERROR; +} + +/** + * @brief PC_to_RDR_ResetParameters + * Set the ICC parameters to the default + * Response to this command message is the RDR_to_PC_Parameters + * @param pdev: device instance + * @retval status of the command execution + */ +uint8_t PC_to_RDR_ResetParameters(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint8_t error; + + error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH | + CHK_PARAM_CARD_PRESENT | CHK_PARAM_abRFU3 | + CHK_ACTIVE_STATE); + if (error != 0U) + { + return error; + } + /* This command resets the slot parameters to their default values */ + hccid->UsbBlkOutData.abData[0] = DEFAULT_FIDI; + hccid->UsbBlkOutData.abData[1] = DEFAULT_T01CONVCHECKSUM; + hccid->UsbBlkOutData.abData[2] = DEFAULT_EXTRA_GUARDTIME; + hccid->UsbBlkOutData.abData[3] = DEFAULT_WAITINGINTEGER; + hccid->UsbBlkOutData.abData[4] = DEFAULT_CLOCKSTOP; + hccid->UsbBlkOutData.abData[5] = 0x00U; + hccid->UsbBlkOutData.abData[6] = 0x00U; + + (void)USBD_memcpy(&ProtocolData, (void const *)(&hccid->UsbBlkOutData.abData[0]), + sizeof(ProtocolData)); + + error = SC_Itf_SetParams(&ProtocolData, ProtocolNUM_OUT); + + if (error != SLOT_NO_ERROR) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + } + else + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + error = SLOT_NO_ERROR; + } + + return error; +} +/** + * @brief PC_to_RDR_SetParameters + * Set the ICC parameters to the host defined parameters + * Response to this command message is the RDR_to_PC_Parameters + * @param pdev: device instance + * @retval status of the command execution + */ +uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint8_t error; + + error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT | + CHK_PARAM_abRFU2 | CHK_ACTIVE_STATE); + if (error != 0U) + { + return error; + } + error = SLOT_NO_ERROR; + + /* for Protocol T=0 (dwLength=00000005h) */ + /* for Protocol T=1 (dwLength=00000007h) */ + if (((hccid->UsbBlkOutData.dwLength == 5U) && (hccid->UsbBlkOutData.bSpecific_0 != 0U)) + || ((hccid->UsbBlkOutData.dwLength == 7U) && (hccid->UsbBlkOutData.bSpecific_0 != 1U))) + { + error = SLOTERROR_BAD_PROTOCOLNUM; + } + if (hccid->UsbBlkOutData.abData[4] != DEFAULT_CLOCKSTOP) + { + error = SLOTERROR_BAD_CLOCKSTOP; + } + if (error != SLOT_NO_ERROR) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + } + + (void)USBD_memcpy(&ProtocolData, (void const *)(&hccid->UsbBlkOutData.abData[0]), + sizeof(ProtocolData)); + + error = SC_Itf_SetParams(&ProtocolData, ProtocolNUM_OUT); + + if (error != SLOT_NO_ERROR) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + } + else + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + error = SLOT_NO_ERROR; + } + + return error; +} +/** + * @brief PC_to_RDR_Escape + * Execute the Escape command. This is user specific Implementation + * Response to this command message is the RDR_to_PC_Escape + * @param pdev: device instance + * @retval status of the command execution + */ +uint8_t PC_to_RDR_Escape(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + 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); + + if (error != 0U) + { + return error; + } + error = SC_Itf_Escape(&hccid->UsbBlkOutData.abData[0], hccid->UsbBlkOutData.dwLength, + &hccid->UsbBlkInData.abData[0], &size); + + hccid->UsbBlkInData.dwLength = size; + + if (error != SLOT_NO_ERROR) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + } + else + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + } + + return error; +} +/** + * @brief PC_to_RDR_IccClock + * Execute the Clock specific command from host + * Response to this command message is the RDR_to_PC_SlotStatus + * @param pdev: device instance + * @retval status of the command execution + */ +uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint8_t error; + + error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT | + CHK_PARAM_abRFU2 | CHK_PARAM_DWLENGTH | CHK_ACTIVE_STATE); + if (error != 0U) + { + return error; + } + /* bClockCommand : + 00h restarts Clock + 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)); + return SLOTERROR_BAD_CLOCKCOMMAND; + } + + error = SC_Itf_SetClock(hccid->UsbBlkOutData.bSpecific_0); + + if (error != SLOT_NO_ERROR) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + } + else + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + } + + return error; +} +/** + * @brief PC_to_RDR_Abort + * Execute the Abort command from host, This stops all Bulk transfers + * from host and ICC + * Response to this command message is the RDR_to_PC_SlotStatus + * @param pdev: device instance + * @retval status of the command execution + */ +uint8_t PC_to_RDR_Abort(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint8_t error; + + 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)); + return SLOT_NO_ERROR; +} + +/** + * @brief CCID_CmdAbort + * Execute the Abort command from Bulk EP or from Control EP, + * This stops all Bulk transfers from host and ICC + * @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) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)(USBD_Device.pClassData); + + uint8_t BSlot = hccid->USBD_CCID_Param.bSlot; + /* This function is called for REQUEST_ABORT & PC_to_RDR_Abort */ + + if (slot >= CCID_NUMBER_OF_SLOTS) + { + /* error from CLASS_REQUEST*/ + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT)); + return SLOTERROR_BAD_SLOT; + } + + if (hccid->USBD_CCID_Param.bAbortRequestFlag == 1U) + { + /* Abort Command was already received from ClassReq or PC_to_RDR */ + if ((hccid->USBD_CCID_Param.bSeq == seq) && (BSlot == slot)) + { + /* CLASS Specific request is already Received, Reset the abort flag */ + hccid->USBD_CCID_Param.bAbortRequestFlag = 0; + } + } + else + { + /* Abort Command was NOT received from ClassReq or PC_to_RDR, + so save them for next ABORT command to verify */ + hccid->USBD_CCID_Param.bAbortRequestFlag = 1U; + hccid->USBD_CCID_Param.bSeq = seq; + hccid->USBD_CCID_Param.bSlot = slot; + } + + return 0; +} + +/** + * @brief PC_TO_RDR_T0Apdu + * Execute the PC_TO_RDR_T0APDU command from host + * Response to this command message is the RDR_to_PC_SlotStatus + * @param pdev: device instance + * @retval status of the command execution + */ +uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint8_t error; + + error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT | + CHK_PARAM_DWLENGTH | CHK_PARAM_ABORT); + if (error != 0U) + { + return error; + } + if (hccid->UsbBlkOutData.bSpecific_0 > 0x03U) + { + /* Bit 0 is associated with bClassGetResponse + Bit 1 is associated with bClassEnvelope */ + + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + return SLOTERROR_BAD_BMCHANGES; + } + + error = SC_Itf_T0Apdu(hccid->UsbBlkOutData.bSpecific_0, + hccid->UsbBlkOutData.bSpecific_1, + hccid->UsbBlkOutData.bSpecific_2); + + if (error != SLOT_NO_ERROR) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + } + else + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + } + + return error; +} + +/** + * @brief PC_TO_RDR_Mechanical + * Execute the PC_TO_RDR_MECHANICAL command from host + * Response to this command message is the RDR_to_PC_SlotStatus + * @param pdev: device instance + * @retval status of the command execution + */ +uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint8_t error; + + error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT | + CHK_PARAM_abRFU2 | CHK_PARAM_DWLENGTH); + if (error != 0U) + { + return error; + } + if (hccid->UsbBlkOutData.bSpecific_0 > 0x05U) + { + /* + 01h Accept Card + 02h Eject Card + 03h Capture Card + 04h Lock Card + 05h Unlock Card + */ + + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + return SLOTERROR_BAD_BFUNCTION_MECHANICAL; + } + + error = SC_Itf_Mechanical(hccid->UsbBlkOutData.bSpecific_0); + + if (error != SLOT_NO_ERROR) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + } + else + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + } + + return error; +} + +/** + * @brief PC_TO_RDR_SetDataRateAndClockFrequency + * Set the required Card Frequency and Data rate from the host. + * Response to this command message is the + * RDR_to_PC_DataRateAndClockFrequency + * @param pdev: device instance + * @retval status of the command execution + */ +uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + 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); + if (error != 0U) + { + return error; + } + if (hccid->UsbBlkOutData.dwLength != 0x08U) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + return SLOTERROR_BAD_LENTGH; + } + + /* HERE we avoiding to an unaligned memory access*/ + temp = (uint32_t)(hccid->UsbBlkOutData.abData[0]) & 0x000000FFU; + clockFrequency = temp; + + temp = (uint32_t)(hccid->UsbBlkOutData.abData[1]) & 0x000000FFU; + clockFrequency |= temp << 8; + + temp = (uint32_t)(hccid->UsbBlkOutData.abData[2]) & 0x000000FFU; + clockFrequency |= temp << 16; + + temp = (uint32_t)(hccid->UsbBlkOutData.abData[3]) & 0x000000FFU; + clockFrequency |= temp << 24; + + temp = (uint32_t)(hccid->UsbBlkOutData.abData[4]) & 0x000000FFU; + dataRate = temp; + + temp = (uint32_t)(hccid->UsbBlkOutData.abData[5]) & 0x000000FFU; + dataRate |= temp << 8; + + temp = (uint32_t)(hccid->UsbBlkOutData.abData[6]) & 0x000000FFU; + dataRate |= temp << 16; + + temp = (uint32_t)(hccid->UsbBlkOutData.abData[7]) & 0x000000FFU; + dataRate |= temp << 24; + + error = SC_Itf_SetDataRateAndClockFrequency(clockFrequency, dataRate); + hccid->UsbBlkInData.bError = error; + + if (error != SLOT_NO_ERROR) + { + hccid->UsbBlkInData.dwLength = 0; + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + } + else + { + hccid->UsbBlkInData.dwLength = 8; + + (hccid->UsbBlkInData.abData[0]) = (uint8_t)(clockFrequency & 0x000000FFU) ; + + (hccid->UsbBlkInData.abData[1]) = (uint8_t)((clockFrequency & 0x0000FF00U) >> 8); + + (hccid->UsbBlkInData.abData[2]) = (uint8_t)((clockFrequency & 0x00FF0000U) >> 16); + + (hccid->UsbBlkInData.abData[3]) = (uint8_t)((clockFrequency & 0xFF000000U) >> 24); + + (hccid->UsbBlkInData.abData[4]) = (uint8_t)(dataRate & 0x000000FFU) ; + + (hccid->UsbBlkInData.abData[5]) = (uint8_t)((dataRate & 0x0000FF00U) >> 8); + + (hccid->UsbBlkInData.abData[6]) = (uint8_t)((dataRate & 0x00FF0000U) >> 16); + + (hccid->UsbBlkInData.abData[7]) = (uint8_t)((dataRate & 0xFF000000U) >> 24); + + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + } + + return error; +} + +/** + * @brief PC_TO_RDR_Secure + * Execute the Secure Command from the host. + * Response to this command message is the RDR_to_PC_DataBlock + * @param pdev: device instance + * @retval status of the command execution + */ +uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint8_t error; + uint8_t bBWI; + uint16_t wLevelParameter; + uint32_t responseLen; + + hccid->UsbBlkInData.dwLength = 0; + + error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT | + CHK_PARAM_ABORT); + + if (error != 0U) + { + return error; + } + bBWI = hccid->UsbBlkOutData.bSpecific_0; + wLevelParameter = (hccid->UsbBlkOutData.bSpecific_1 + ((uint16_t)hccid->UsbBlkOutData.bSpecific_2 << 8)); + + if ((EXCHANGE_LEVEL_FEATURE == TPDU_EXCHANGE) || + (EXCHANGE_LEVEL_FEATURE == SHORT_APDU_EXCHANGE)) + { + /* TPDU level & short APDU level, wLevelParameter is RFU, = 0000h */ + if (wLevelParameter != 0U) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + error = SLOTERROR_BAD_LEVELPARAMETER; + return error; + } + } + + error = SC_Itf_Secure(hccid->UsbBlkOutData.dwLength, bBWI, wLevelParameter, + &(hccid->UsbBlkOutData.abData[0]), &responseLen); + + hccid->UsbBlkInData.dwLength = responseLen; + + if (error != SLOT_NO_ERROR) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + } + else + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE)); + } + + return error; +} + +/******************************************************************************/ +/* BULK IN ROUTINES */ +/******************************************************************************/ + +/** + * @brief RDR_to_PC_DataBlock + * Provide the data block response to the host + * Response for PC_to_RDR_IccPowerOn, PC_to_RDR_XfrBlock + * @param errorCode: code to be returned to the host + * @param pdev: device instance + * @retval None + */ +void RDR_to_PC_DataBlock(uint8_t errorCode, USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint32_t length = CCID_RESPONSE_HEADER_SIZE; + + hccid->UsbBlkInData.bMessageType = RDR_TO_PC_DATABLOCK; + hccid->UsbBlkInData.bError = 0U; + hccid->UsbBlkInData.bSpecific = 0U; /* bChainParameter */ + + if (errorCode == SLOT_NO_ERROR) + { + length += hccid->UsbBlkInData.dwLength; /* Length Specified in Command */ + } + + (void)USBD_CCID_Transfer_Data_Request(pdev, (uint8_t *)&hccid->UsbBlkInData, (uint16_t)length); +} + +/** + * @brief RDR_to_PC_SlotStatus + * Provide the Slot status response to the host + * Response for PC_to_RDR_IccPowerOff + * PC_to_RDR_GetSlotStatus + * PC_to_RDR_IccClock + * PC_to_RDR_T0APDU + * PC_to_RDR_Mechanical + * Also the device sends this response message when it has completed + * aborting a slot after receiving both the Class Specific ABORT request + * and PC_to_RDR_Abort command message. + * @param errorCode: code to be returned to the host + * @param pdev: device instance + * @retval None + */ +void RDR_to_PC_SlotStatus(uint8_t errorCode, USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + UNUSED(errorCode); + + hccid->UsbBlkInData.bMessageType = RDR_TO_PC_SLOTSTATUS; + hccid->UsbBlkInData.dwLength = 0U; + hccid->UsbBlkInData.bError = 0U; + hccid->UsbBlkInData.bSpecific = 0U; /* bClockStatus = 00h Clock running + 01h Clock stopped in state L + 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); + +} + +/** + * @brief RDR_to_PC_Parameters + * Provide the data block response to the host + * Response for PC_to_RDR_GetParameters, PC_to_RDR_ResetParameters + * PC_to_RDR_SetParameters + * @param errorCode: code to be returned to the host + * @param pdev: device instance + * @retval None + */ +void RDR_to_PC_Parameters(uint8_t errorCode, USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint16_t length = CCID_RESPONSE_HEADER_SIZE; + + hccid->UsbBlkInData.bMessageType = RDR_TO_PC_PARAMETERS; + hccid->UsbBlkInData.bError = 0U; + + if (errorCode == SLOT_NO_ERROR) + { + if (ProtocolNUM_OUT == 0x00U) + { + hccid->UsbBlkInData.dwLength = LEN_PROTOCOL_STRUCT_T0; + length += LEN_PROTOCOL_STRUCT_T0; + } + else + { + hccid->UsbBlkInData.dwLength = LEN_PROTOCOL_STRUCT_T1; + length += LEN_PROTOCOL_STRUCT_T1; + } + } + else + { + hccid->UsbBlkInData.dwLength = 0; + } + + hccid->UsbBlkInData.abData[0] = ProtocolData.bmFindexDindex; + hccid->UsbBlkInData.abData[1] = ProtocolData.bmTCCKST0; + hccid->UsbBlkInData.abData[2] = ProtocolData.bGuardTimeT0; + hccid->UsbBlkInData.abData[3] = ProtocolData.bWaitingIntegerT0; + hccid->UsbBlkInData.abData[4] = ProtocolData.bClockStop; + hccid->UsbBlkInData.abData[5] = ProtocolData.bIfsc; + hccid->UsbBlkInData.abData[6] = ProtocolData.bNad; + + /* bProtocolNum */ + if (ProtocolNUM_OUT == 0x00U) + { + hccid->UsbBlkInData.bSpecific = BPROTOCOL_NUM_T0; + } + else + { + hccid->UsbBlkInData.bSpecific = BPROTOCOL_NUM_T1; + } + (void)USBD_CCID_Transfer_Data_Request(pdev, (uint8_t *)(&hccid->UsbBlkInData), length); +} + +/** + * @brief RDR_to_PC_Escape + * Provide the Escaped data block response to the host + * Response for PC_to_RDR_Escape + * @param errorCode: code to be returned to the host + * @param pdev: device instance + * @retval None + */ +void RDR_to_PC_Escape(uint8_t errorCode, USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint32_t length = CCID_RESPONSE_HEADER_SIZE; + + hccid->UsbBlkInData.bMessageType = RDR_TO_PC_ESCAPE; + + hccid->UsbBlkInData.bSpecific = 0U; /* Reserved for Future Use */ + hccid->UsbBlkInData.bError = errorCode; + + if (errorCode == SLOT_NO_ERROR) + { + length += hccid->UsbBlkInData.dwLength; /* Length Specified in Command */ + } + + (void)USBD_CCID_Transfer_Data_Request(pdev, (uint8_t *)(&hccid->UsbBlkInData), (uint16_t)length); +} + +/** + * @brief RDR_to_PC_DataRateAndClockFrequency + * Provide the Clock and Data Rate information to host + * Response for PC_TO_RDR_SetDataRateAndClockFrequency + * @param errorCode: code to be returned to the host + * @param pdev: device instance + * @retval None + */ +void RDR_to_PC_DataRateAndClockFrequency(uint8_t errorCode, USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint32_t length = CCID_RESPONSE_HEADER_SIZE; + + hccid->UsbBlkInData.bMessageType = RDR_TO_PC_DATARATEANDCLOCKFREQUENCY; + hccid->UsbBlkInData.bError = errorCode; + hccid->UsbBlkInData.bSpecific = 0U; /* Reserved for Future Use */ + + if (errorCode == SLOT_NO_ERROR) + { + length += hccid->UsbBlkInData.dwLength; /* Length Specified in Command */ + } + + (void)USBD_CCID_Transfer_Data_Request(pdev, (uint8_t *)(&hccid->UsbBlkInData), (uint16_t)length); +} + +/** + * @brief RDR_to_PC_NotifySlotChange + * Interrupt message to be sent to the host, Checks the card presence + * status and update the buffer accordingly + * @param pdev: device instance + * @retval None + */ +void RDR_to_PC_NotifySlotChange(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + + hccid->UsbIntData[OFFSET_INT_BMESSAGETYPE] = RDR_TO_PC_NOTIFYSLOTCHANGE; + + if (SC_Detect() != 0U) + { + /* + SLOT_ICC_PRESENT 0x01 : LSb : (0b = no ICC present, 1b = ICC present) + SLOT_ICC_CHANGE 0x02 : MSb : (0b = no change, 1b = change). + */ + hccid->UsbIntData[OFFSET_INT_BMSLOTICCSTATE] = SLOT_ICC_PRESENT | SLOT_ICC_CHANGE; + } + else + { + hccid->UsbIntData[OFFSET_INT_BMSLOTICCSTATE] = SLOT_ICC_CHANGE; + + /* Power OFF the card */ + SC_Itf_IccPowerOff(); + } +} + + +/** + * @brief CCID_UpdSlotStatus + * Updates the variable for the slot status + * @param pdev: device instance + * @param slotStatus : slot status from the calling function + * @retval None + */ +void CCID_UpdSlotStatus(USBD_HandleTypeDef *pdev, uint8_t slotStatus) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + hccid->SlotStatus.SlotStatus = slotStatus; +} + +/** + * @brief CCID_UpdSlotChange + * Updates the variable for the slot change status + * @param pdev: device instance + * @param changeStatus : slot change status from the calling function + * @retval None + */ +void CCID_UpdSlotChange(USBD_HandleTypeDef *pdev, uint8_t changeStatus) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + hccid->SlotStatus.SlotStatusChange = changeStatus; +} + +/** + * @brief CCID_IsSlotStatusChange + * Provides the value of the variable for the slot change status + * @param pdev: device instance + * @retval slot change status + */ +uint8_t CCID_IsSlotStatusChange(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + return hccid->SlotStatus.SlotStatusChange; +} + +/** + * @brief CCID_UpdateCommandStatus + * Updates the variable for the BulkIn status + * @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) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)USBD_Device.pClassData; + hccid->UsbBlkInData.bStatus = (cmd_status | icc_status); +} +/** + * @brief CCID_CheckCommandParams + * Checks the specific parameters requested by the function and update + * status accordingly. This function is called from all + * PC_to_RDR functions + * @param pdev: device instance + * @param param_type : Parameter enum to be checked by calling function + * @retval status + */ +static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param_type) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + uint32_t parameter; + uint8_t GetState = SC_GetState(); + + hccid->UsbBlkInData.bStatus = BM_ICC_PRESENT_ACTIVE | BM_COMMAND_STATUS_NO_ERROR; + + parameter = (uint32_t)param_type; + + if ((parameter & CHK_PARAM_SLOT) != 0U) + { + /* + The slot number (bSlot) identifies which ICC slot is being addressed + by the message*/ + + /* SLOT Number is 0 onwards, so always < CCID_NUMBER_OF_SLOTs */ + /* Error Condition !!! */ + 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)); + return SLOTERROR_BAD_SLOT; + } + } + + if ((parameter & CHK_PARAM_CARD_PRESENT) != 0U) + { + /* Commands Parameters ok, Check the Card Status */ + if (SC_Detect() == 0U) + { + /* Card is Not detected */ + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT)); + return SLOTERROR_ICC_MUTE; + } + } + + /* Check that DwLength is 0 */ + if ((parameter & CHK_PARAM_DWLENGTH) != 0U) + { + if (hccid->UsbBlkOutData.dwLength != 0U) + { + CCID_UpdateCommandStatus((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 ((hccid->UsbBlkOutData.bSpecific_1 != 0U) || (hccid->UsbBlkOutData.bSpecific_2 != 0U)) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE)); + return SLOTERROR_BAD_ABRFU_2B; /* bSpecific_1 */ + } + } + + 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)); + return SLOTERROR_BAD_ABRFU_3B; + } + } + + if ((parameter & CHK_PARAM_ABORT) != 0U) + { + if (hccid->USBD_CCID_Param.bAbortRequestFlag != 0U) + { + CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE)); + return SLOTERROR_CMD_ABORTED; + } + } + + if ((parameter & CHK_ACTIVE_STATE) != 0U) + { + /* Commands Parameters ok, Check the Card Status */ + /* Card is detected */ + + 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)); + return SLOTERROR_HW_ERROR; + } + } + + return 0U; +} diff --git a/Class/CCID/Src/usbd_ccid_if_template.c b/Class/CCID/Src/usbd_ccid_if_template.c new file mode 100644 index 0000000..3592ee9 --- /dev/null +++ b/Class/CCID/Src/usbd_ccid_if_template.c @@ -0,0 +1,254 @@ +/** + ****************************************************************************** + * @file usbd_ccid_if_template.c + * @author MCD Application Team + * @brief This file provides all the functions for USB Interface for CCID + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_ccid.h" +#include "usbd_ccid_if_template.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static REP_Command_t REP_command; + +/* Private function prototypes -----------------------------------------------*/ +static uint8_t CCID_Init(USBD_HandleTypeDef *pdev); +static uint8_t CCID_DeInit(USBD_HandleTypeDef *pdev); +static uint8_t CCID_ControlReq(uint8_t req, uint8_t *pbuf, uint16_t *length); +static uint8_t CCID_Response_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf, uint16_t len); +static uint8_t CCID_Send_Process(uint8_t *Command, uint8_t *Data); +static uint8_t CCID_Response_Process(void); +static uint8_t CCID_SetSlotStatus(USBD_HandleTypeDef *pdev); + +/* Private functions ---------------------------------------------------------*/ + +/** + * @} + */ + +USBD_CCID_ItfTypeDef USBD_CCID_If_fops = +{ + CCID_Init, + CCID_DeInit, + CCID_ControlReq, + CCID_Response_SendData, + CCID_Send_Process, + CCID_SetSlotStatus, +}; + +/** + * @brief CCID_Init + * Initialize the CCID USB Layer + * @param pdev: device instance + * @retval status value + */ +uint8_t CCID_Init(USBD_HandleTypeDef *pdev) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + + /* CCID Related Initialization */ + + hccid->blkt_state = CCID_STATE_IDLE; + + return (uint8_t)USBD_OK; +} + +/** + * @brief CCID_DeInit + * Uninitialize the CCID Machine + * @param pdev: device instance + * @retval status value + */ +uint8_t CCID_DeInit(USBD_HandleTypeDef *pdev) +{ + + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + + hccid->blkt_state = CCID_STATE_IDLE; + + return (uint8_t)USBD_OK; +} + +/** + * @brief CCID_ControlReq + * Manage the CCID class requests + * @param Cmd: Command code + * @param Buf: Buffer containing command data (request parameters) + * @param Len: Number of data to be sent (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static uint8_t CCID_ControlReq(uint8_t req, uint8_t *pbuf, uint16_t *length) +{ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)(USBD_Device.pClassData); + UNUSED(length); + + switch (req) + { + case REQUEST_ABORT: + /* The wValue field contains the slot number (bSlot) in the low byte + and the sequence number (bSeq) in the high byte.*/ + 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 error is returned by lower layer : + Generally Slot# may not have matched */ + return (int8_t)USBD_FAIL; + } + break; + + case REQUEST_GET_CLOCK_FREQUENCIES: + + /* User have to fill the pbuf with the GetClockFrequency data buffer */ + + break; + + case REQUEST_GET_DATA_RATES: + + /* User have to fill the pbuf with the GetDataRates data buffer */ + + break; + + default: + break; + } + + UNUSED(pbuf); + + return ((int8_t)USBD_OK); +} + +/** + * @brief CCID_Response_SendData + * Send the data on bulk-in EP + * @param pdev: device instance + * @param buf: pointer to data buffer + * @param len: Data Length + * @retval status value + */ +uint8_t CCID_Response_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf, uint16_t len) +{ + (void)USBD_LL_Transmit(pdev, CCID_IN_EP, buf, len); + return (uint8_t)USBD_OK; +} + +/** + * @brief CCID_SEND_Process + * @param Command: pointer to a buffer containing command header + * @param Data: pointer to a buffer containing data sent from Host + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static uint8_t CCID_Send_Process(uint8_t *Command, uint8_t *Data) +{ + Command_State_t Command_State = Command_NOT_OK; + + /* Initialize ICC APP header */ + uint8_t SC_Command[5] = {0}; + UNUSED(Data); + UNUSED(Command_State); + UNUSED(SC_Command); + + /* Start SC Demo ---------------------------------------------------------*/ + switch (Command[1]) /* type of instruction */ + { + case SC_ENABLE: + /* Add your code here */ + break; + + case SC_VERIFY: + /* Add your code here */ + break; + + case SC_READ_BINARY : + /* Add your code here */ + break; + + case SC_CHANGE : + /* Add your code here */ + break; + + default: + break; + } + + /* check if Command header is OK */ + (void)CCID_Response_Process(); /* Get ICC response */ + + return ((uint8_t)USBD_OK); +} + +/** + * @brief CCID_Response_Process + * @param None + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static uint8_t CCID_Response_Process(void) +{ + switch (REP_command) + { + case REP_OK: + /* Add your code here */ + break; + + case REP_NOT_OK : + /* Add your code here */ + break; + + case REP_NOT_SUPP : + /* Add your code here */ + break; + + case REP_ENABLED : + /* Add your code here */ + break; + + case REP_CHANGE : + /* Add your code here */ + break; + + default: + break; + } + + return ((uint8_t)USBD_OK); +} + +/** + * @brief CCID_SetSlotStatus + * Set Slot Status of the Interrupt Transfer + * @param pdev: device instance + * @retval status + */ +uint8_t CCID_SetSlotStatus(USBD_HandleTypeDef *pdev) +{ + /* Get the CCID handler pointer */ + USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData; + + if ((hccid->SlotStatus.SlotStatus) == 1U) /* Transfer Complete Status + of previous Interrupt transfer */ + { + /* Add your code here */ + } + else + { + /* Add your code here */ + } + + return (uint8_t)USBD_OK; +} diff --git a/Class/CCID/Src/usbd_ccid_sc_if_template.c b/Class/CCID/Src/usbd_ccid_sc_if_template.c new file mode 100644 index 0000000..d64416e --- /dev/null +++ b/Class/CCID/Src/usbd_ccid_sc_if_template.c @@ -0,0 +1,473 @@ +/** + ****************************************************************************** + * @file usbd_ccid_sc_if_template.c + * @author MCD Application Team + * @brief SmartCard Interface file + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_ccid_sc_if_template.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* State Machine for the SmartCard Interface */ +static SC_State SCState = SC_POWER_OFF; + +/* APDU Transport Structures */ +SC_ADPU_Commands SC_ADPU; +SC_ADPU_Response SC_Response; +SC_Param_t SC_Param; +Protocol_01_DataTypeDef ProtocolData; + +/* Extern variables ----------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +static void SC_SaveVoltage(uint8_t voltage); +static void SC_Itf_UpdateParams(void); + +/* Private functions ---------------------------------------------------------*/ +/** + * @brief SC_Itf_IccPowerOn Manages the Warm and Cold Reset + and get the Answer to Reset from ICC + * @param voltage: required by host + * @retval None + */ +void SC_Itf_IccPowerOn(uint8_t voltage) +{ + SCState = SC_POWER_ON; + SC_ADPU.Header.CLA = 0x00U; + SC_ADPU.Header.INS = SC_GET_A2R; + SC_ADPU.Header.P1 = 0x00U; + SC_ADPU.Header.P2 = 0x00U; + SC_ADPU.Body.LC = 0x00U; + + /* Power ON the card */ + SC_PowerCmd(SC_ENABLED); + + /* Configure the Voltage, Even if IO is still not configured */ + SC_VoltageConfig(voltage); + + while ((SCState != SC_ACTIVE_ON_T0) && (SCState != SC_ACTIVE_ON_T1) + && (SCState != SC_NO_INIT)) + { + /* If Either The Card has become Active or Become De-Active */ + SC_Handler(&SCState, &SC_ADPU, &SC_Response); + } + + if ((SCState == SC_ACTIVE_ON_T0) || (SCState == SC_ACTIVE_ON_T1)) + { + SC_Itf_UpdateParams(); + /* Apply the Procedure Type Selection (PTS) */ + SC_PTSConfig(); + + /* Save Voltage for Future use */ + SC_SaveVoltage(voltage); + } + + return; +} + +/** + * @brief SC_Itf_IccPowerOff Power OFF the card + * @param None + * @retval None + */ +void SC_Itf_IccPowerOff(void) +{ + SC_PowerCmd(SC_DISABLED); + SC_SetState(SC_POWER_OFF); + + return; +} + +/** + * @brief Initialize the parameters structures to the default value + * @param None + * @retval None + */ +void SC_Itf_InitParams(void) +{ + /* + FI, the reference to a clock rate conversion factor + over the bits b8 to b5 + - DI, the reference to a baud rate adjustment factor + over the bits b4 to bl + */ + SC_Param.SC_A2R_FiDi = DEFAULT_FIDI; + SC_Param.SC_hostFiDi = DEFAULT_FIDI; + + ProtocolData.bmFindexDindex = DEFAULT_FIDI; + + /* Placeholder, Ignored */ + /* 0 = Direct, first byte of the ICC ATR data. */ + ProtocolData.bmTCCKST0 = DEFAULT_T01CONVCHECKSUM; + + /* Extra GuardTime = 0 etu */ + ProtocolData.bGuardTimeT0 = DEFAULT_EXTRA_GUARDTIME; + ProtocolData.bWaitingIntegerT0 = DEFAULT_WAITINGINTEGER; + ProtocolData.bClockStop = 0U; /* Stopping the Clock is not allowed */ + + /*T=1 protocol */ + ProtocolData.bIfsc = DEFAULT_IFSC; + ProtocolData.bNad = DEFAULT_NAD; + + return; +} + +/** + * @brief Save the A2R Parameters for further usage + * @param None + * @retval None + */ +static void SC_Itf_UpdateParams(void) +{ + /* + FI, the reference to a clock rate conversion factor + over the bits b8 to b5 + DI, the reference to a baud rate adjustment factor + over the bits b4 to bl + */ + SC_Param.SC_A2R_FiDi = SC_A2R.T[0].InterfaceByte[0].Value; + SC_Param.SC_hostFiDi = SC_A2R.T[0].InterfaceByte[0].Value; + + ProtocolData.bmFindexDindex = SC_A2R.T[0].InterfaceByte[0].Value; + + return; +} + +/** + * @brief SC_Itf_SetParams + * Set the parameters for CCID/USART interface + * @param pPtr: pointer to buffer containing the + * parameters to be set in USART + * @param T_01: type of protocol, T=1 or T=0 + * @retval status value + */ +uint8_t SC_Itf_SetParams(Protocol_01_DataTypeDef *pPtr, uint8_t T_01) +{ + /* uint16_t guardTime; */ /* Keep it 16b for handling 8b additions */ + uint32_t fi_new; + uint32_t di_new; + Protocol_01_DataTypeDef New_DataStructure; + fi_new = pPtr->bmFindexDindex; + di_new = pPtr->bmFindexDindex; + + New_DataStructure.bmTCCKST0 = pPtr->bmTCCKST0; + + New_DataStructure.bGuardTimeT0 = pPtr->bGuardTimeT0; + New_DataStructure.bWaitingIntegerT0 = pPtr->bWaitingIntegerT0; + New_DataStructure.bClockStop = pPtr->bClockStop; + if (T_01 == 0x01U) + { + New_DataStructure.bIfsc = pPtr->bIfsc; + New_DataStructure.bNad = pPtr->bNad; + } + else + { + New_DataStructure.bIfsc = 0x00U; + New_DataStructure.bNad = 0x00U; + } + + /* Check for the FIDI Value set by Host */ + di_new &= (uint8_t)0x0F; + if (SC_GetDTableValue(di_new) == 0U) + { + return SLOTERROR_BAD_FIDI; + } + + fi_new >>= 4U; + fi_new &= 0x0FU; + + if (SC_GetDTableValue(fi_new) == 0U) + { + return SLOTERROR_BAD_FIDI; + } + + if ((T_01 == 0x00U) + && (New_DataStructure.bmTCCKST0 != 0x00U) + && (New_DataStructure.bmTCCKST0 != 0x02U)) + { + return SLOTERROR_BAD_T01CONVCHECKSUM; + } + + if ((T_01 == 0x01U) + && (New_DataStructure.bmTCCKST0 != 0x10U) + && (New_DataStructure.bmTCCKST0 != 0x11U) + && (New_DataStructure.bmTCCKST0 != 0x12U) + && (New_DataStructure.bmTCCKST0 != 0x13U)) + { + return SLOTERROR_BAD_T01CONVCHECKSUM; + } + + if ((New_DataStructure.bWaitingIntegerT0 >= 0xA0U) + && ((New_DataStructure.bmTCCKST0 & 0x10U) == 0x10U)) + { + return SLOTERROR_BAD_WAITINGINTEGER; + } + if ((New_DataStructure.bClockStop != 0x00U) + && (New_DataStructure.bClockStop != 0x03U)) + { + return SLOTERROR_BAD_CLOCKSTOP; + } + if (New_DataStructure.bNad != 0x00U) + { + return SLOTERROR_BAD_NAD; + } + /* Put Total GuardTime in USART Settings */ + /* USART_SetGuardTime(SC_USART, (uint8_t)(guardTime + DEFAULT_EXTRA_GUARDTIME)); */ + + /* Save Extra GuardTime Value */ + ProtocolData.bGuardTimeT0 = New_DataStructure.bGuardTimeT0; + ProtocolData.bmTCCKST0 = New_DataStructure.bmTCCKST0; + ProtocolData.bWaitingIntegerT0 = New_DataStructure.bWaitingIntegerT0; + ProtocolData.bClockStop = New_DataStructure.bClockStop; + ProtocolData.bIfsc = New_DataStructure.bIfsc; + ProtocolData.bNad = New_DataStructure.bNad; + + /* Save New bmFindexDindex */ + SC_Param.SC_hostFiDi = pPtr->bmFindexDindex; + SC_PTSConfig(); + + ProtocolData.bmFindexDindex = pPtr->bmFindexDindex; + + return SLOT_NO_ERROR; +} + +/** + * @brief SC_Itf_Escape function from the host + * This is user implementable + * @param ptrEscape: pointer to buffer containing the Escape data + * @param escapeLen: length of escaped data + * @param responseBuff: pointer containing escape buffer response + * @param responseLen: length of escape response buffer + * @retval status value + */ +uint8_t SC_Itf_Escape(uint8_t *ptrEscape, uint32_t escapeLen, + uint8_t *responseBuff, uint32_t *responseLen) +{ + UNUSED(ptrEscape); + UNUSED(escapeLen); + UNUSED(responseBuff); + UNUSED(responseLen); + + /* Manufacturer specific implementation ... */ + /* + uint32_t idx; + uint8_t *pResBuff = responseBuff; + uint8_t *pEscape = ptrEscape; + + for(idx = 0; idx < escapeLen; idx++) + { + *pResBuff = *pEscape; + pResBuff++; + pEscape++; + } + + *responseLen = escapeLen; + */ + return SLOT_NO_ERROR; +} + +/** + * @brief SC_Itf_SetClock function to define Clock Status request from the host. + * This is user implementable + * @param bClockCommand: Clock status from the host + * @retval status value + */ +uint8_t SC_Itf_SetClock(uint8_t bClockCommand) +{ + /* bClockCommand + 00h restarts Clock + 01h Stops Clock in the state shown in the bClockStop + field of the PC_to_RDR_SetParameters command + and RDR_to_PC_Parameters message.*/ + + if (bClockCommand == 0U) + { + /* 00h restarts Clock : Since Clock is always running, PASS this command */ + return SLOT_NO_ERROR; + } + else + { + if (bClockCommand == 1U) + { + return SLOTERROR_BAD_CLOCKCOMMAND; + } + } + + return SLOTERROR_CMD_NOT_SUPPORTED; +} + +/** + * @brief SC_Itf_XferBlock function from the host. + * This is user implementable + * @param ptrBlock : Pointer containing the data from host + * @param blockLen : length of block data for the data transfer + * @param expectedLen: expected length of data transfer + * @param CCID_BulkIn_Data: Pointer containing the CCID Bulk In Data Structure + * @retval status value + */ +uint8_t SC_Itf_XferBlock(uint8_t *ptrBlock, uint32_t blockLen, uint16_t expectedLen, + USBD_CCID_BulkIn_DataTypeDef *CCID_BulkIn_Data) +{ + uint8_t ErrorCode = SLOT_NO_ERROR; + UNUSED(CCID_BulkIn_Data); + UNUSED(expectedLen); + UNUSED(blockLen); + UNUSED(ptrBlock); + + if (ProtocolNUM_OUT == 0x00U) + { + /* Add your code here */ + } + + if (ProtocolNUM_OUT == 0x01U) + { + /* Add your code here */ + } + + if (ErrorCode != SLOT_NO_ERROR) + { + return ErrorCode; + } + + return ErrorCode; +} + + +/** + * @brief SC_Itf_T0Apdu + Class Specific Request from the host to provide supported data rates + * This is Optional function & user implementable + * @param bmChanges : value specifying which parameter is valid in + * command among next bClassGetResponse, bClassEnvelope + * @param bClassGetResponse : Value to force the class byte of the + * header in a Get Response command. + * @param bClassEnvelope : Value to force the class byte of the header + * in a Envelope command. + * @retval status value + */ +uint8_t SC_Itf_T0Apdu(uint8_t bmChanges, uint8_t bClassGetResponse, + uint8_t bClassEnvelope) +{ + UNUSED(bClassEnvelope); + UNUSED(bClassGetResponse); + + /* User have to fill the pbuf with the GetDataRates data buffer */ + + if (bmChanges == 0U) + { + /* Bit cleared indicates that the associated field is not significant and + that default behaviour defined in CCID class descriptor is selected */ + return SLOT_NO_ERROR; + } + + return SLOTERROR_CMD_NOT_SUPPORTED; +} + +/** + * @brief SC_Itf_Mechanical + Mechanical Function being requested by Host + * This is Optional function & user implementable + * @param bFunction : value corresponds to the mechanical function + * being requested by host + * @retval status value + */ +uint8_t SC_Itf_Mechanical(uint8_t bFunction) +{ + UNUSED(bFunction); + + return SLOTERROR_CMD_NOT_SUPPORTED; +} + +/** + * @brief SC_Itf_SetDataRateAndClockFrequency + * Set the Clock and data Rate of the Interface + * This is Optional function & user implementable + * @param dwClockFrequency : value of clock in kHz requested by host + * @param dwDataRate : value of data rate requested by host + * @retval status value + */ +uint8_t SC_Itf_SetDataRateAndClockFrequency(uint32_t dwClockFrequency, + uint32_t dwDataRate) +{ + /* User have to fill the pbuf with the GetDataRates data buffer */ + + if ((dwDataRate == USBD_CCID_DEFAULT_DATA_RATE) && + (dwClockFrequency == USBD_CCID_DEFAULT_CLOCK_FREQ)) + { + return SLOT_NO_ERROR; + } + + return SLOTERROR_CMD_NOT_SUPPORTED; +} + +/** + * @brief SC_Itf_Secure + * Process the Secure command + * This is Optional function & user implementable + * @param dwLength : length of data from the host + * @param bBWI : Block Waiting Timeout sent by host + * @param wLevelParameter : Parameters sent by host + * @param pbuf : buffer containing the data + * @param returnLen : Length of data expected to return + * @retval status value + */ +uint8_t SC_Itf_Secure(uint32_t dwLength, uint8_t bBWI, uint16_t wLevelParameter, + uint8_t *pbuf, uint32_t *returnLen) +{ + UNUSED(pbuf); + UNUSED(wLevelParameter); + UNUSED(bBWI); + UNUSED(dwLength); + *returnLen = 0U; + + return SLOTERROR_CMD_NOT_SUPPORTED; +} + +/** + * @brief SC_SaveVoltage + Saves the voltage value to be saved for further usage + * @param voltage: voltage value to be saved for further usage + * @retval None + */ +static void SC_SaveVoltage(uint8_t voltage) +{ + SC_Param.voltage = voltage; + + return; +} + +/** + * @brief Provides the value of SCState variable + * @param None + * @retval uint8_t SCState + */ +uint8_t SC_GetState(void) +{ + return (uint8_t)SCState; +} + +/** + * @brief Set the value of SCState variable to Off + * @param scState: value of SCState to be updated + * @retval None + */ +void SC_SetState(SC_State scState) +{ + SCState = scState; + + return; +} diff --git a/Class/CCID/Src/usbd_ccid_smartcard_template.c b/Class/CCID/Src/usbd_ccid_smartcard_template.c new file mode 100644 index 0000000..10b33e0 --- /dev/null +++ b/Class/CCID/Src/usbd_ccid_smartcard_template.c @@ -0,0 +1,482 @@ +/** + ****************************************************************************** + * @file usbd_ccid_smartcard_template.c + * @author MCD Application Team + * @brief This file provides all the Smartcard firmware functions. + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/** @addtogroup usbd_ccid_Smartcard + * @{ + */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_ccid_smartcard_template.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Directories & Files ID */ +/*The following Directories & Files ID can take any of following Values and can + be used in the smartcard application */ +/* +const uint8_t MasterRoot[2] = {0x3F, 0x00}; +const uint8_t GSMDir[2] = {0x7F, 0x20}; +const uint8_t ICCID[2] = {0x2F, 0xE2}; +const uint8_t IMSI[2] = {0x6F, 0x07}; + +__IO uint8_t ICCID_Content[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +uint32_t CHV1Status = 0U; + +uint8_t CHV1[8] = {'0', '0', '0', '0', '0', '0', '0', '0'}; +__IO uint8_t IMSI_Content[9] = {0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +*/ + +/* F Table: Clock Rate Conversion Table from ISO/IEC 7816-3 */ +/* static uint32_t F_Table[16] = {372, 372, 558, 744, 1116, 1488, 1860, 0, 0, 512, 768, + 1024, 1536, 2048, 0, 0 + }; */ + + +/* D Table: Baud Rate Adjustment Factor Table from ISO/IEC 7816-3 */ +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; +uint8_t SC_ATR_Table[40]; +uint8_t ProtocolNUM_OUT; + +/* Private function prototypes -----------------------------------------------*/ +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_Reset(GPIO_PinState ResetState); */ + +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Handles all Smartcard states and serves to send and receive all + * communication data between Smartcard and reader. + * @param SCState: pointer to an SC_State enumeration that will contain the + * Smartcard state. + * @param SC_ADPU: pointer to an SC_ADPU_Commands structure that will be initialized. + * @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) +{ + uint32_t i, j; + + switch (*SCState) + { + case SC_POWER_ON: + if (SC_ADPU->Header.INS == SC_GET_A2R) + { + /* Smartcard initialization */ + SC_Init(); + + /* Reset Data from SC buffer */ + for (i = 0U; i < 40U; i++) + { + SC_ATR_Table[i] = 0; + } + + /* Reset SC_A2R Structure */ + SC_A2R.TS = 0U; + SC_A2R.T0 = 0U; + + for (i = 0U; i < MAX_PROTOCOLLEVEL; i++) + { + for (j = 0U; j < MAX_INTERFACEBYTE; j++) + { + SC_A2R.T[i].InterfaceByte[j].Status = 0U; + SC_A2R.T[i].InterfaceByte[j].Value = 0U; + } + } + + for (i = 0U; i < HIST_LENGTH; i++) + { + SC_A2R.H[i] = 0U; + } + + SC_A2R.Tlength = 0U; + SC_A2R.Hlength = 0U; + + /* Next State */ + *SCState = SC_RESET_LOW; + } + break; + + case SC_RESET_LOW: + if (SC_ADPU->Header.INS == SC_GET_A2R) + { + /* If card is detected then Power ON, Card Reset and wait for an answer) */ + if (SC_Detect() != 0U) + { + while (((*SCState) != SC_POWER_OFF) && ((*SCState) != SC_ACTIVE)) + { + SC_AnswerReq(SCState, &SC_ATR_Table[0], 40U); /* Check for answer to reset */ + } + } + else + { + (*SCState) = SC_POWER_OFF; + } + } + break; + + case SC_ACTIVE: + if (SC_ADPU->Header.INS == SC_GET_A2R) + { + uint8_t protocol = SC_decode_Answer2reset(&SC_ATR_Table[0]); + if (protocol == T0_PROTOCOL) + { + (*SCState) = SC_ACTIVE_ON_T0; + ProtocolNUM_OUT = T0_PROTOCOL; + } + else if (protocol == T1_PROTOCOL) + { + (*SCState) = SC_ACTIVE_ON_T1; + ProtocolNUM_OUT = T1_PROTOCOL; + } + else + { + (*SCState) = SC_POWER_OFF; + } + } + break; + + case SC_ACTIVE_ON_T0: + /* process commands other than ATR */ + SC_SendData(SC_ADPU, SC_Response); + break; + + case SC_ACTIVE_ON_T1: + /* process commands other than ATR */ + SC_SendData(SC_ADPU, SC_Response); + break; + + case SC_POWER_OFF: + SC_DeInit(); /* Disable Smartcard interface */ + break; + + default: + (*SCState) = SC_POWER_OFF; + break; + } +} + +/** + * @brief Enables or disables the power to the Smartcard. + * @param NewState: new state of the Smartcard power supply. + * This parameter can be: SC_ENABLED or SC_DISABLED. + * @retval None + */ +void SC_PowerCmd(SCPowerState NewState) +{ + UNUSED(NewState); + /* enable or disable smartcard pin */ + + return; +} + +/** + * @brief Sets or clears the Smartcard reset pin. + * @param ResetState: this parameter specifies the state of the Smartcard + * reset pin. BitVal must be one of the BitAction enum values: + * @arg Bit_RESET: to clear the port pin. + * @arg Bit_SET: to set the port pin. + * @retval None + */ +/* static void SC_Reset(GPIO_PinState ResetState) +{ + UNUSED(ResetState); + + return; +} +*/ + + +/** + * @brief Resends the byte that failed to be received (by the Smartcard) correctly. + * @param None + * @retval None + */ + +void SC_ParityErrorHandler(void) +{ + /* Add your code here */ + + return; +} + +/** + * @brief Configures the IO speed (BaudRate) communication. + * @param None + * @retval None + */ + +void SC_PTSConfig(void) +{ + /* Add your code here */ + + return; +} + + +/** + * @brief Manages the Smartcard transport layer: send APDU commands and receives + * the APDU response. + * @param SC_ADPU: pointer to a SC_ADPU_Commands structure which will be initialized. + * @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) +{ + uint8_t i; + uint8_t SC_Command[5]; + uint8_t SC_DATA[LC_MAX]; + + UNUSED(SCADPU); + + /* Reset response buffer */ + for (i = 0U; i < LC_MAX; i++) + { + SC_ResponseStatus->Data[i] = 0U; + SC_DATA[i] = 0U; + } + + /* User to add code here */ + + /* send command to ICC and get response status */ + USBD_CCID_If_fops.Send_Process((uint8_t *)&SC_Command, (uint8_t *)&SC_DATA); + +} + +/** + * @brief SC_AnswerReq + Requests the reset answer from card. + * @param SC_state: pointer to an SC_State enumeration that will contain the Smartcard state. + * @param atr_buffer: pointer to a buffer which will contain the card ATR. + * @param length: maximum ATR length + * @retval None + */ +static void SC_AnswerReq(SC_State *SC_state, uint8_t *atr_buffer, uint8_t length) +{ + UNUSED(length); + UNUSED(atr_buffer); + + /* to be implemented by USER */ + switch (*SC_state) + { + case SC_RESET_LOW: + /* Check response with reset low */ + (*SC_state) = SC_ACTIVE; + break; + + case SC_ACTIVE: + break; + case SC_RESET_HIGH: + /* Check response with reset high */ + + break; + + case SC_POWER_OFF: + /* Close Connection if no answer received */ + + break; + + default: + (*SC_state) = SC_RESET_LOW; + break; + } + + return; +} + +/** + * @brief SC_decode_Answer2reset + Decodes the Answer to reset received from card. + * @param card: pointer to the buffer containing the card ATR. + * @retval None + */ +static uint8_t SC_decode_Answer2reset(uint8_t *card) +{ + uint32_t i, flag = 0U, protocol; + uint8_t index = 0U, level = 0U; + + /******************************TS/T0 Decode************************************/ + index++; + SC_A2R.TS = card[index]; /* Initial character */ + + index++; + SC_A2R.T0 = card[index]; /* Format character */ + + /*************************Historical Table Length Decode***********************/ + SC_A2R.Hlength = SC_A2R.T0 & 0x0FU; + + /******************************Protocol Level(1) Decode************************/ + /* Check TD(1) if present */ + if ((SC_A2R.T0 & 0x80U) == 0x80U) + { + flag = 1U; + } + + /* Each bits in the T0 high nibble(b8 to b5) equal to 1 indicates the presence + of a further interface byte */ + for (i = 0U; i < 4U; i++) + { + if ((((SC_A2R.T0 & 0xF0U) >> (4U + i)) & 0x1U) != 0U) + { + SC_A2R.T[level].InterfaceByte[i].Status = 1U; + index++; + SC_A2R.T[level].InterfaceByte[i].Value = card[index]; + SC_A2R.Tlength++; + } + } + + /*****************************T Decode*****************************************/ + if (SC_A2R.T[level].InterfaceByte[3].Status == 1U) + { + /* Only the protocol(parameter T) present in TD(1) is detected + if two or more values of parameter T are present in TD(1), TD(2)..., so the + firmware should be updated to support them */ + protocol = (uint8_t)(SC_A2R.T[level].InterfaceByte[SC_INTERFACEBYTE_TD].Value & 0x0FU); + } + else + { + protocol = 0U; + } + + /* Protocol Level Increment */ + /******************************Protocol Level(n>1) Decode**********************/ + while (flag != 0U) + { + if ((SC_A2R.T[level].InterfaceByte[SC_INTERFACEBYTE_TD].Value & 0x80U) == 0x80U) + { + flag = 1U; + } + else + { + flag = 0U; + } + /* Each bits in the high nibble(b8 to b5) for the TD(i) equal to 1 indicates + the presence of a further interface byte */ + for (i = 0U; i < 4U; i++) + { + if ((((SC_A2R.T[level].InterfaceByte[SC_INTERFACEBYTE_TD].Value & 0xF0U) >> (4U + i)) & 0x1U) != 0U) + { + SC_A2R.T[level + 1U].InterfaceByte[i].Status = 1U; + index++; + SC_A2R.T[level + 1U].InterfaceByte[i].Value = card[index]; + SC_A2R.Tlength++; + } + } + level++; + } + + for (i = 0U; i < SC_A2R.Hlength; i++) + { + SC_A2R.H[i] = card[i + 2U + SC_A2R.Tlength]; + } + /*************************************TCK Decode*******************************/ + SC_A2R.TCK = card[SC_A2R.Hlength + 2U + SC_A2R.Tlength]; + + return (uint8_t)protocol; +} + +/** + * @brief Initializes all peripheral used for Smartcard interface. + * @param None + * @retval None + */ +static void SC_Init(void) +{ + /* + Add your initialization code here + */ + + return; +} + + +/** + * @brief Deinitializes all resources used by the Smartcard interface. + * @param None + * @retval None + */ +static void SC_DeInit(void) +{ + /* + Add your deinitialization code here + */ + + return; +} + +/** + * @brief Configures the card power voltage. + * @param SC_Voltage: specifies the card power voltage. + * This parameter can be one of the following values: + * @arg SC_VOLTAGE_5V: 5V cards. + * @arg SC_VOLTAGE_3V: 3V cards. + * @retval None + */ +void SC_VoltageConfig(uint32_t SC_Voltage) +{ + UNUSED(SC_Voltage); + /* Add your code here */ + + return; +} + +/** + * @brief Configures GPIO hardware resources used for Samrtcard. + * @param None + * @retval None + */ +void SC_IOConfig(void) +{ + /* Add your code here */ + + return; +} + +/** + * @brief Detects whether the Smartcard is present or not. + * @param None. + * @retval 1 - Smartcard inserted + * 0 - Smartcard not inserted + */ +uint8_t SC_Detect(void) +{ + uint8_t PIN_State = 0U; + + /* Add your code here */ + + return PIN_State; +} + +/** + * @brief Get the Right Value from the D_Table Index + * @param idx : Index to Read from the Table + * @retval Value read from the Table + */ +uint32_t SC_GetDTableValue(uint32_t idx) +{ + return D_Table[idx]; +} diff --git a/Class/CDC/Inc/usbd_cdc.h b/Class/CDC/Inc/usbd_cdc.h index cb5c6d8..36348c8 100644 --- a/Class/CDC/Inc/usbd_cdc.h +++ b/Class/CDC/Inc/usbd_cdc.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -172,4 +171,3 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev); * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CDC/Inc/usbd_cdc_if_template.h b/Class/CDC/Inc/usbd_cdc_if_template.h index 158ad40..6a1c0ab 100644 --- a/Class/CDC/Inc/usbd_cdc_if_template.h +++ b/Class/CDC/Inc/usbd_cdc_if_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -42,4 +41,3 @@ extern USBD_CDC_ItfTypeDef USBD_CDC_Template_fops; #endif /* __USBD_CDC_IF_TEMPLATE_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CDC/Src/usbd_cdc.c b/Class/CDC/Src/usbd_cdc.c index d6ed6ce..fb985c5 100644 --- a/Class/CDC/Src/usbd_cdc.c +++ b/Class/CDC/Src/usbd_cdc.c @@ -10,6 +10,17 @@ * - Command IN transfer (class requests management) * - Error management * + ****************************************************************************** + * @attention + * + * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** * @verbatim * * =================================================================== @@ -37,17 +48,6 @@ * @endverbatim * ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** */ /* BSPDependencies @@ -690,7 +690,7 @@ static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev, static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) { USBD_CDC_HandleTypeDef *hcdc; - PCD_HandleTypeDef *hpcd = pdev->pData; + PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData; if (pdev->pClassData == NULL) { @@ -777,7 +777,6 @@ static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev) /** * @brief USBD_CDC_GetFSCfgDesc * Return configuration descriptor - * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ @@ -791,7 +790,6 @@ static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length) /** * @brief USBD_CDC_GetHSCfgDesc * Return configuration descriptor - * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ @@ -805,7 +803,6 @@ static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length) /** * @brief USBD_CDC_GetOtherSpeedCfgDesc * Return configuration descriptor - * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ @@ -852,6 +849,7 @@ uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev, * @brief USBD_CDC_SetTxBuffer * @param pdev: device instance * @param pbuff: Tx Buffer + * @param length: Tx Buffer length * @retval status */ uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, @@ -965,4 +963,3 @@ uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev) * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CDC/Src/usbd_cdc_if_template.c b/Class/CDC/Src/usbd_cdc_if_template.c index f863ce1..301cf20 100644 --- a/Class/CDC/Src/usbd_cdc_if_template.c +++ b/Class/CDC/Src/usbd_cdc_if_template.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -244,5 +243,3 @@ static int8_t TEMPLATE_TransmitCplt(uint8_t *Buf, uint32_t *Len, uint8_t epnum) * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/Class/CDC_ECM/Inc/usbd_cdc_ecm.h b/Class/CDC_ECM/Inc/usbd_cdc_ecm.h index 1cd71fa..36b34b9 100644 --- a/Class/CDC_ECM/Inc/usbd_cdc_ecm.h +++ b/Class/CDC_ECM/Inc/usbd_cdc_ecm.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -254,4 +253,3 @@ uint8_t USBD_CDC_ECM_SendNotification(USBD_HandleTypeDef *pdev, * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CDC_ECM/Inc/usbd_cdc_ecm_if_template.h b/Class/CDC_ECM/Inc/usbd_cdc_ecm_if_template.h index 7ce8714..c08f0f3 100644 --- a/Class/CDC_ECM/Inc/usbd_cdc_ecm_if_template.h +++ b/Class/CDC_ECM/Inc/usbd_cdc_ecm_if_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -79,4 +78,3 @@ extern USBD_CDC_ECM_ItfTypeDef USBD_CDC_ECM_fops; /* Exported functions ------------------------------------------------------- */ #endif /* __USBD_CDC_ECM_IF_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CDC_ECM/Src/usbd_cdc_ecm.c b/Class/CDC_ECM/Src/usbd_cdc_ecm.c index 4b34d7c..d26f8a7 100644 --- a/Class/CDC_ECM/Src/usbd_cdc_ecm.c +++ b/Class/CDC_ECM/Src/usbd_cdc_ecm.c @@ -13,13 +13,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -715,7 +714,7 @@ static uint8_t USBD_CDC_ECM_Setup(USBD_HandleTypeDef *pdev, static uint8_t USBD_CDC_ECM_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) { USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassData; - PCD_HandleTypeDef *hpcd = pdev->pData; + PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData; if (pdev->pClassData == NULL) { @@ -840,7 +839,6 @@ static uint8_t USBD_CDC_ECM_EP0_RxReady(USBD_HandleTypeDef *pdev) /** * @brief USBD_CDC_ECM_GetFSCfgDesc * Return configuration descriptor - * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ @@ -854,7 +852,6 @@ static uint8_t *USBD_CDC_ECM_GetFSCfgDesc(uint16_t *length) /** * @brief USBD_CDC_ECM_GetHSCfgDesc * Return configuration descriptor - * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ @@ -868,7 +865,6 @@ static uint8_t *USBD_CDC_ECM_GetHSCfgDesc(uint16_t *length) /** * @brief USBD_CDC_ECM_GetCfgDesc * Return configuration descriptor - * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ @@ -915,7 +911,7 @@ uint8_t USBD_CDC_ECM_RegisterInterface(USBD_HandleTypeDef *pdev, /** * @brief USBD_CDC_ECM_USRStringDescriptor * Manages the transfer of user string descriptors. - * @param speed : current device speed + * @param pdev: device instance * @param index: descriptor index * @param length : pointer data length * @retval pointer to the descriptor table or NULL if the descriptor is not supported. @@ -943,6 +939,7 @@ static uint8_t *USBD_CDC_ECM_USRStringDescriptor(USBD_HandleTypeDef *pdev, uint8 * @brief USBD_CDC_ECM_SetTxBuffer * @param pdev: device instance * @param pbuff: Tx Buffer + * @param length: Tx Buffer length * @retval status */ uint8_t USBD_CDC_ECM_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint32_t length) @@ -1112,7 +1109,7 @@ uint8_t USBD_CDC_ECM_SendNotification(USBD_HandleTypeDef *pdev, /* Transmit notification packet */ if (ReqSize != 0U) { - (void)USBD_LL_Transmit(pdev, CDC_ECM_CMD_EP, (uint8_t *) &(hcdc->Req), ReqSize); + (void)USBD_LL_Transmit(pdev, CDC_ECM_CMD_EP, (uint8_t *)&hcdc->Req, ReqSize); } return (uint8_t)ret; @@ -1131,4 +1128,3 @@ uint8_t USBD_CDC_ECM_SendNotification(USBD_HandleTypeDef *pdev, * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c b/Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c index cab0056..9c28c63 100644 --- a/Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c +++ b/Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -30,16 +29,17 @@ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ - +/* Received Data over USB are stored in this buffer */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif -__ALIGN_BEGIN static uint8_t UserRxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END; /* Received Data over USB are stored in this buffer */ +__ALIGN_BEGIN static uint8_t UserRxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END; +/* Transmitted Data over CDC_ECM (CDC_ECM interface) are stored in this buffer */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif -__ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END; /* Received Data over CDC_ECM (CDC_ECM interface) are stored in this buffer */ +__ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END; static uint8_t CDC_ECMInitialized = 0U; @@ -244,4 +244,3 @@ static int8_t CDC_ECM_Itf_Process(USBD_HandleTypeDef *pdev) return (0); } -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CDC_RNDIS/Inc/usbd_cdc_rndis.h b/Class/CDC_RNDIS/Inc/usbd_cdc_rndis.h index a2fb432..f294c01 100644 --- a/Class/CDC_RNDIS/Inc/usbd_cdc_rndis.h +++ b/Class/CDC_RNDIS/Inc/usbd_cdc_rndis.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -526,4 +525,3 @@ uint8_t USBD_CDC_RNDIS_SendNotification(USBD_HandleTypeDef *pdev, * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CDC_RNDIS/Inc/usbd_cdc_rndis_if_template.h b/Class/CDC_RNDIS/Inc/usbd_cdc_rndis_if_template.h index 3cf0271..14474c6 100644 --- a/Class/CDC_RNDIS/Inc/usbd_cdc_rndis_if_template.h +++ b/Class/CDC_RNDIS/Inc/usbd_cdc_rndis_if_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -57,4 +56,3 @@ extern USBD_CDC_RNDIS_ItfTypeDef USBD_CDC_RNDIS_fops; #endif /* __USBD_CDC_RNDIS_IF_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CDC_RNDIS/Src/usbd_cdc_rndis.c b/Class/CDC_RNDIS/Src/usbd_cdc_rndis.c index a7c2cbc..b7f064f 100644 --- a/Class/CDC_RNDIS/Src/usbd_cdc_rndis.c +++ b/Class/CDC_RNDIS/Src/usbd_cdc_rndis.c @@ -10,6 +10,17 @@ * - Command IN transfer (class requests management) * - Error management * + ****************************************************************************** + * @attention + * + * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** * @verbatim * * =================================================================== @@ -37,17 +48,6 @@ * @endverbatim * ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ @@ -729,7 +729,7 @@ static uint8_t USBD_CDC_RNDIS_Setup(USBD_HandleTypeDef *pdev, else { hcdc->CmdOpCode = req->bRequest; - hcdc->CmdLength = (uint8_t)MIN(CDC_RNDIS_CMD_PACKET_SIZE, req->wLength); + hcdc->CmdLength = (uint8_t)MIN(CDC_RNDIS_MAX_INFO_BUFF_SZ, req->wLength); (void)USBD_CtlPrepareRx(pdev, (uint8_t *)hcdc->data, hcdc->CmdLength); } @@ -807,7 +807,7 @@ static uint8_t USBD_CDC_RNDIS_Setup(USBD_HandleTypeDef *pdev, static uint8_t USBD_CDC_RNDIS_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) { USBD_CDC_RNDIS_HandleTypeDef *hcdc; - PCD_HandleTypeDef *hpcd = pdev->pData; + PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData; if (pdev->pClassData == NULL) { @@ -950,7 +950,6 @@ static uint8_t USBD_CDC_RNDIS_EP0_RxReady(USBD_HandleTypeDef *pdev) /** * @brief USBD_CDC_RNDIS_GetFSCfgDesc * Return configuration descriptor - * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ @@ -964,7 +963,6 @@ static uint8_t *USBD_CDC_RNDIS_GetFSCfgDesc(uint16_t *length) /** * @brief USBD_CDC_RNDIS_GetHSCfgDesc * Return configuration descriptor - * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ @@ -978,7 +976,6 @@ static uint8_t *USBD_CDC_RNDIS_GetHSCfgDesc(uint16_t *length) /** * @brief USBD_CDC_RNDIS_GetOtherSpeedCfgDesc * Return configuration descriptor - * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ @@ -1025,7 +1022,7 @@ uint8_t USBD_CDC_RNDIS_RegisterInterface(USBD_HandleTypeDef *pdev, /** * @brief USBD_CDC_RNDIS_USRStringDescriptor * Manages the transfer of user string descriptors. - * @param speed : current device speed + * @param pdev: device instance * @param index: descriptor index * @param length : pointer data length * @retval pointer to the descriptor table or NULL if the descriptor is not supported. @@ -1053,6 +1050,7 @@ static uint8_t *USBD_CDC_RNDIS_USRStringDescriptor(USBD_HandleTypeDef *pdev, uin * @brief USBD_CDC_RNDIS_SetTxBuffer * @param pdev: device instance * @param pbuff: Tx Buffer + * @param length: Tx Buffer length * @retval status */ uint8_t USBD_CDC_RNDIS_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint32_t length) @@ -1221,7 +1219,7 @@ uint8_t USBD_CDC_RNDIS_SendNotification(USBD_HandleTypeDef *pdev, /* Transmit notification packet */ if (ReqSize != 0U) { - (void)USBD_LL_Transmit(pdev, CDC_RNDIS_CMD_EP, (uint8_t *) &(hcdc->Req), ReqSize); + (void)USBD_LL_Transmit(pdev, CDC_RNDIS_CMD_EP, (uint8_t *)&hcdc->Req, ReqSize); } return (uint8_t)ret; @@ -1780,5 +1778,3 @@ static uint8_t USBD_CDC_RNDIS_ProcessUnsupportedMsg(USBD_HandleTypeDef *pdev, /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CDC_RNDIS/Src/usbd_cdc_rndis_if_template.c b/Class/CDC_RNDIS/Src/usbd_cdc_rndis_if_template.c index ad88c32..f59c0b7 100644 --- a/Class/CDC_RNDIS/Src/usbd_cdc_rndis_if_template.c +++ b/Class/CDC_RNDIS/Src/usbd_cdc_rndis_if_template.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -37,15 +36,17 @@ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ +/* Received Data over USB are stored in this buffer */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif -__ALIGN_BEGIN uint8_t UserRxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END; /* Received Data over USB are stored in this buffer */ +__ALIGN_BEGIN uint8_t UserRxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END; +/* Transmitted Data over CDC_RNDIS (CDC_RNDIS interface) are stored in this buffer */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif -__ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END; /* Received Data over CDC_RNDIS (CDC_RNDIS interface) are stored in this buffer */ +__ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END; static uint8_t CDC_RNDISInitialized = 0U; @@ -230,4 +231,3 @@ static int8_t CDC_RNDIS_Itf_Process(USBD_HandleTypeDef *pdev) return (0); } -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CustomHID/Inc/usbd_customhid.h b/Class/CustomHID/Inc/usbd_customhid.h index da01685..3276fac 100644 --- a/Class/CustomHID/Inc/usbd_customhid.h +++ b/Class/CustomHID/Inc/usbd_customhid.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -167,4 +166,3 @@ uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev, * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CustomHID/Inc/usbd_customhid_if_template.h b/Class/CustomHID/Inc/usbd_customhid_if_template.h index e390693..e2a04af 100644 --- a/Class/CustomHID/Inc/usbd_customhid_if_template.h +++ b/Class/CustomHID/Inc/usbd_customhid_if_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -40,4 +39,3 @@ extern USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops; #endif /* __USBD_CUSTOMHID_IF_TEMPLATE_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CustomHID/Src/usbd_customhid.c b/Class/CustomHID/Src/usbd_customhid.c index 2fbc057..7a9ca65 100644 --- a/Class/CustomHID/Src/usbd_customhid.c +++ b/Class/CustomHID/Src/usbd_customhid.c @@ -4,6 +4,17 @@ * @author MCD Application Team * @brief This file provides the CUSTOM_HID core functions. * + ****************************************************************************** + * @attention + * + * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** * @verbatim * * =================================================================== @@ -24,17 +35,6 @@ * @endverbatim * ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** */ /* BSPDependencies @@ -779,4 +779,3 @@ uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev, * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/CustomHID/Src/usbd_customhid_if_template.c b/Class/CustomHID/Src/usbd_customhid_if_template.c index 97e4337..678da92 100644 --- a/Class/CustomHID/Src/usbd_customhid_if_template.c +++ b/Class/CustomHID/Src/usbd_customhid_if_template.c @@ -8,13 +8,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -88,4 +87,4 @@ static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state) return (0); } -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/Class/DFU/Inc/usbd_dfu.h b/Class/DFU/Inc/usbd_dfu.h index 307c96d..e91605a 100644 --- a/Class/DFU/Inc/usbd_dfu.h +++ b/Class/DFU/Inc/usbd_dfu.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -133,20 +132,20 @@ typedef void (*pFunction)(void); /********** Descriptor of DFU interface 0 Alternate setting n ****************/ -#define USBD_DFU_IF_DESC(n) 0x09, /* bLength: Interface Descriptor size */ \ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType */ \ - 0x00, /* bInterfaceNumber: Number of Interface */ \ - (n), /* bAlternateSetting: Alternate setting */ \ - 0x00, /* bNumEndpoints*/ \ - 0xFE, /* bInterfaceClass: Application Specific Class Code */ \ - 0x01, /* bInterfaceSubClass : Device Firmware Upgrade Code */ \ - 0x02, /* nInterfaceProtocol: DFU mode protocol */ \ - USBD_IDX_INTERFACE_STR + (n) + 1U /* iInterface: Index of string descriptor */ \ +#define USBD_DFU_IF_DESC(n) \ + 0x09, /* bLength: Interface Descriptor size */ \ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType */ \ + 0x00, /* bInterfaceNumber: Number of Interface */ \ + (n), /* bAlternateSetting: Alternate setting */ \ + 0x00, /* bNumEndpoints*/ \ + 0xFE, /* bInterfaceClass: Application Specific Class Code */ \ + 0x01, /* bInterfaceSubClass : Device Firmware Upgrade Code */ \ + 0x02, /* nInterfaceProtocol: DFU mode protocol */ \ + USBD_IDX_INTERFACE_STR + (n) + 1U /* iInterface: Index of string descriptor */ -#define TRANSFER_SIZE_BYTES(size) ((uint8_t)(size)), /* XFERSIZEB0 */\ - ((uint8_t)((size) >> 8)) /* XFERSIZEB1 */ +#define TRANSFER_SIZE_BYTES(size) ((uint8_t)(size)), ((uint8_t)((size) >> 8)) -#define IS_PROTECTED_AREA(add) (uint8_t)((((add) >= 0x08000000) && ((add) < (APP_DEFAULT_ADD)))? 1:0) +#define IS_PROTECTED_AREA(add) (uint8_t)((((add) >= 0x08000000) && ((add) < (APP_DEFAULT_ADD))) ? 1 : 0) /** * @} @@ -231,5 +230,3 @@ uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev, /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/DFU/Inc/usbd_dfu_media_template.h b/Class/DFU/Inc/usbd_dfu_media_template.h index 25efe52..7be25d4 100644 --- a/Class/DFU/Inc/usbd_dfu_media_template.h +++ b/Class/DFU/Inc/usbd_dfu_media_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -94,4 +93,3 @@ extern USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops; /** * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/DFU/Src/usbd_dfu.c b/Class/DFU/Src/usbd_dfu.c index fc942a7..effc85d 100644 --- a/Class/DFU/Src/usbd_dfu.c +++ b/Class/DFU/Src/usbd_dfu.c @@ -4,6 +4,17 @@ * @author MCD Application Team * @brief This file provides the DFU core functions. * + ****************************************************************************** + * @attention + * + * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** * @verbatim * * =================================================================== @@ -34,17 +45,6 @@ * @endverbatim * ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** */ /* BSPDependencies @@ -466,7 +466,6 @@ static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re /** * @brief USBD_DFU_GetCfgDesc * return configuration descriptor - * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer */ @@ -627,7 +626,7 @@ static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length) /** * @brief USBD_DFU_GetUsrStringDesc * Manages the transfer of memory interfaces string descriptors. - * @param speed : current device speed + * @param pdev: device instance * @param index: descriptor index * @param length : pointer data length * @retval pointer to the descriptor table or NULL if the descriptor is not supported. @@ -654,6 +653,7 @@ static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t inde /** * @brief USBD_MSC_RegisterStorage + * @param pdev: device instance * @param fops: storage callback * @retval status */ @@ -1112,4 +1112,3 @@ static void DFU_Leave(USBD_HandleTypeDef *pdev) * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/DFU/Src/usbd_dfu_media_template.c b/Class/DFU/Src/usbd_dfu_media_template.c index b40a10c..f2f55d0 100644 --- a/Class/DFU/Src/usbd_dfu_media_template.c +++ b/Class/DFU/Src/usbd_dfu_media_template.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -131,5 +130,4 @@ uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer) } return (0); } -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/HID/Inc/usbd_hid.h b/Class/HID/Inc/usbd_hid.h index 76fcdc7..4b9a0ca 100644 --- a/Class/HID/Inc/usbd_hid.h +++ b/Class/HID/Inc/usbd_hid.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -136,4 +135,3 @@ uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev); * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/HID/Src/usbd_hid.c b/Class/HID/Src/usbd_hid.c index 75256d2..9da7650 100644 --- a/Class/HID/Src/usbd_hid.c +++ b/Class/HID/Src/usbd_hid.c @@ -4,6 +4,17 @@ * @author MCD Application Team * @brief This file provides the HID core functions. * + ****************************************************************************** + * @attention + * + * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** * @verbatim * * =================================================================== @@ -25,17 +36,6 @@ * @endverbatim * ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** */ /* BSPDependencies @@ -695,4 +695,3 @@ static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length) * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Inc/usbd_msc.h b/Class/MSC/Inc/usbd_msc.h index a0bbab9..56e6c79 100644 --- a/Class/MSC/Inc/usbd_msc.h +++ b/Class/MSC/Inc/usbd_msc.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -126,5 +125,3 @@ uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Inc/usbd_msc_bot.h b/Class/MSC/Inc/usbd_msc_bot.h index fb99095..f8b667f 100644 --- a/Class/MSC/Inc/usbd_msc_bot.h +++ b/Class/MSC/Inc/usbd_msc_bot.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -146,5 +145,4 @@ void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, /** * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Inc/usbd_msc_data.h b/Class/MSC/Inc/usbd_msc_data.h index 3aacf04..f946b95 100644 --- a/Class/MSC/Inc/usbd_msc_data.h +++ b/Class/MSC/Inc/usbd_msc_data.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -101,5 +100,3 @@ extern uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN]; /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Inc/usbd_msc_scsi.h b/Class/MSC/Inc/usbd_msc_scsi.h index 9bf10a9..0d0bbc5 100644 --- a/Class/MSC/Inc/usbd_msc_scsi.h +++ b/Class/MSC/Inc/usbd_msc_scsi.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -181,5 +180,3 @@ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/Class/MSC/Inc/usbd_msc_storage_template.h b/Class/MSC/Inc/usbd_msc_storage_template.h index 9591a3b..cb8b89a 100644 --- a/Class/MSC/Inc/usbd_msc_storage_template.h +++ b/Class/MSC/Inc/usbd_msc_storage_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -94,4 +93,4 @@ extern USBD_StorageTypeDef USBD_MSC_Template_fops; /** * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/Class/MSC/Src/usbd_msc.c b/Class/MSC/Src/usbd_msc.c index 09a61a6..9a80df4 100644 --- a/Class/MSC/Src/usbd_msc.c +++ b/Class/MSC/Src/usbd_msc.c @@ -4,6 +4,17 @@ * @author MCD Application Team * @brief This file provides all the MSC core functions. * + ****************************************************************************** + * @attention + * + * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** * @verbatim * * =================================================================== @@ -19,17 +30,6 @@ * @endverbatim * ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** */ /* BSPDependencies @@ -598,4 +598,3 @@ uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, USBD_StorageTypeDef * * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Src/usbd_msc_bot.c b/Class/MSC/Src/usbd_msc_bot.c index bbe9430..e67c5af 100644 --- a/Class/MSC/Src/usbd_msc_bot.c +++ b/Class/MSC/Src/usbd_msc_bot.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -432,4 +431,3 @@ void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, uint8_t epnum) * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Src/usbd_msc_data.c b/Class/MSC/Src/usbd_msc_data.c index 34ef443..fabd835 100644 --- a/Class/MSC/Src/usbd_msc_data.c +++ b/Class/MSC/Src/usbd_msc_data.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -180,4 +179,3 @@ uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN] = * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Src/usbd_msc_scsi.c b/Class/MSC/Src/usbd_msc_scsi.c index 02fdc83..f482e3d 100644 --- a/Class/MSC/Src/usbd_msc_scsi.c +++ b/Class/MSC/Src/usbd_msc_scsi.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -290,7 +289,7 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param } else { - pPage = (uint8_t *) &((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN]; + pPage = (uint8_t *) & ((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN]; len = (uint16_t)pPage[4] + 5U; if (params[4] <= len) @@ -1177,4 +1176,3 @@ static int8_t SCSI_UpdateBotData(USBD_MSC_BOT_HandleTypeDef *hmsc, * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MSC/Src/usbd_msc_storage_template.c b/Class/MSC/Src/usbd_msc_storage_template.c index 875c1f9..bc0ac3a 100644 --- a/Class/MSC/Src/usbd_msc_storage_template.c +++ b/Class/MSC/Src/usbd_msc_storage_template.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -173,5 +172,4 @@ int8_t STORAGE_GetMaxLun(void) return (STORAGE_LUN_NBR - 1); } -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/MTP/Inc/usbd_mtp.h b/Class/MTP/Inc/usbd_mtp.h new file mode 100644 index 0000000..0732863 --- /dev/null +++ b/Class/MTP/Inc/usbd_mtp.h @@ -0,0 +1,348 @@ +/** + ****************************************************************************** + * @file usbd_mtp.h + * @author MCD Application Team + * @brief header file for the usbd_mtp.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USB_MTP_H +#define __USB_MTP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_ioreq.h" +#include "usbd_ctlreq.h" + +/** @addtogroup STM32_USB_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_MTP + * @brief This file is the header file for usbd_mtp.c + * @{ + */ + + +/** @defgroup USBD_MTP_Exported_Defines + * @{ + */ + +#define MTP_IN_EP 0x81U /* EP1 for data IN */ +#define MTP_OUT_EP 0x01U /* EP1 for data OUT */ +#define MTP_CMD_EP 0x82U /* EP2 for MTP commands */ + +#ifndef MTP_CMD_ITF_NBR +#define MTP_CMD_ITF_NBR 0x00U /* Command Interface Number 0 */ +#endif /* MTP_CMD_ITF_NBR */ + +#ifndef MTP_COM_ITF_NBR +#define MTP_COM_ITF_NBR 0x01U /* Communication Interface Number 0 */ +#endif /* MTP_CMD_ITF_NBR */ + +#ifndef MTP_HS_BINTERVAL +#define MTP_HS_BINTERVAL 0x10U +#endif /* MTP_HS_BINTERVAL */ + +#ifndef MTP_FS_BINTERVAL +#define MTP_FS_BINTERVAL 0x10U +#endif /* MTP_FS_BINTERVAL */ + +#define MTP_DATA_MAX_HS_PACKET_SIZE 512U +#define MTP_DATA_MAX_FS_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */ +#define MTP_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */ + +#define MTP_MEDIA_PACKET 512U +#define MTP_CONT_HEADER_SIZE 12U + +#define MTP_CONFIG_DESC_SIZ 39U +#define MTP_INTERFACE_DESC_SIZE 0x09U +#define USB_MTP_INTRERFACE_CLASS 0x06U +#define USB_MTP_INTRERFACE_SUB_CLASS 0x01U +#define USB_MTP_INTRERFACE_PROTOCOL 0x01U +#define MTP_ENDPOINT_DESC_SIZE 0x07U + +/*---------------------------------------------------------------------*/ +/* MTP definitions */ +/*---------------------------------------------------------------------*/ + +/* MTP class requests */ +#define MTP_REQ_CANCEL 0x64U +#define MTP_REQ_GET_EXT_EVENT_DATA 0x65U +#define MTP_REQ_RESET 0x66U +#define MTP_REQ_GET_DEVICE_STATUS 0x67U + + +/* Max info items size */ +#define MTP_SUPPORTED_OPERATIONS_NBR 100U +#define MTP_SUPPORTED_EVENTS_NBR 100U +#define MTP_SUPPORTED_PROPRIETIES_NBR 100U +#define MTP_CAPTURE_FORMATS_NBR 100U +#define MTP_IMAGE_FORMATS_NBR 100U +#define MTP_MAX_STR_SIZE 255U + +/* MTP response code */ +#define MTP_RESPONSE_OK 0x2001U +#define MTP_RESPONSE_GENERAL_ERROR 0x2002U +#define MTP_RESPONSE_PARAMETER_NOT_SUPPORTED 0x2006U +#define MTP_RESPONSE_INCOMPLETE_TRANSFER 0x2007U +#define MTP_RESPONSE_INVALID_STORAGE_ID 0x2008U +#define MTP_RESPONSE_INVALID_OBJECT_HANDLE 0x2009U +#define MTP_RESPONSE_DEVICEPROP_NOT_SUPPORTED 0x200AU +#define MTP_RESPONSE_STORE_FULL 0x200CU +#define MTP_RESPONSE_ACCESS_DENIED 0x200FU +#define MTP_RESPONSE_STORE_NOT_AVAILABLE 0x2013U +#define MTP_RESPONSE_SPECIFICATION_BY_FORMAT_NOT_SUPPORTED 0x2014U +#define MTP_RESPONSE_NO_VALID_OBJECT_INFO 0x2015U +#define MTP_RESPONSE_DEVICE_BUSY 0x2019U +#define MTP_RESPONSE_INVALID_PARENT_OBJECT 0x201AU +#define MTP_RESPONSE_INVALID_PARAMETER 0x201DU +#define MTP_RESPONSE_SESSION_ALREADY_OPEN 0x201EU +#define MTP_RESPONSE_TRANSACTION_CANCELLED 0x201FU +#define MTP_RESPONSE_INVALID_OBJECT_PROP_CODE 0xA801U +#define MTP_RESPONSE_SPECIFICATION_BY_GROUP_UNSUPPORTED 0xA807U +#define MTP_RESPONSE_OBJECT_PROP_NOT_SUPPORTED 0xA80AU + +/* MTP Object format codes */ +#define MTP_OBJ_FORMAT_UNDEFINED 0x3000U +#define MTP_OBJ_FORMAT_ASSOCIATION 0x3001U +#define MTP_OBJ_FORMAT_SCRIPT 0x3002U +#define MTP_OBJ_FORMAT_EXECUTABLE 0x3003U +#define MTP_OBJ_FORMAT_TEXT 0x3004U +#define MTP_OBJ_FORMAT_HTML 0x3005U +#define MTP_OBJ_FORMAT_DPOF 0x3006U +#define MTP_OBJ_FORMAT_AIFF 0x3007U +#define MTP_OBJ_FORMAT_WAV 0x3008U +#define MTP_OBJ_FORMAT_MP3 0x3009U +#define MTP_OBJ_FORMAT_AVI 0x300AU +#define MTP_OBJ_FORMAT_MPEG 0x300BU +#define MTP_OBJ_FORMAT_ASF 0x300CU +#define MTP_OBJ_FORMAT_DEFINED 0x3800U +#define MTP_OBJ_FORMAT_EXIF_JPEG 0x3801U +#define MTP_OBJ_FORMAT_TIFF_EP 0x3802U +#define MTP_OBJ_FORMAT_FLASHPIX 0x3803U +#define MTP_OBJ_FORMAT_BMP 0x3804U +#define MTP_OBJ_FORMAT_CIFF 0x3805U +#define MTP_OBJ_FORMAT_UNDEFINED_RESERVED0 0x3806U +#define MTP_OBJ_FORMAT_GIF 0x3807U +#define MTP_OBJ_FORMAT_JFIF 0x3808U +#define MTP_OBJ_FORMAT_CD 0x3809U +#define MTP_OBJ_FORMAT_PICT 0x380AU +#define MTP_OBJ_FORMAT_PNG 0x380BU +#define MTP_OBJ_FORMAT_UNDEFINED_RESERVED1 0x380CU +#define MTP_OBJ_FORMAT_TIFF 0x380DU +#define MTP_OBJ_FORMAT_TIFF_IT 0x380EU +#define MTP_OBJ_FORMAT_JP2 0x380FU +#define MTP_OBJ_FORMAT_JPX 0x3810U +#define MTP_OBJ_FORMAT_UNDEFINED_FIRMWARE 0xB802U +#define MTP_OBJ_FORMAT_WINDOWS_IMAGE_FORMAT 0xB881U +#define MTP_OBJ_FORMAT_UNDEFINED_AUDIO 0xB900U +#define MTP_OBJ_FORMAT_WMA 0xB901U +#define MTP_OBJ_FORMAT_OGG 0xB902U +#define MTP_OBJ_FORMAT_AAC 0xB903U +#define MTP_OBJ_FORMAT_AUDIBLE 0xB904U +#define MTP_OBJ_FORMAT_FLAC 0xB906U +#define MTP_OBJ_FORMAT_UNDEFINED_VIDEO 0xB980U +#define MTP_OBJ_FORMAT_WMV 0xB981U +#define MTP_OBJ_FORMAT_MP4_CONTAINER 0xB982U +#define MTP_OBJ_FORMAT_MP2 0xB983U +#define MTP_OBJ_FORMAT_3GP_CONTAINER 0xB984U +/** + * @} + */ + + +/** @defgroup USBD_CORE_Exported_TypesDefinitions + * @{ + */ + +/** + * @} + */ + + +/* MTP Session state */ +typedef enum +{ + MTP_SESSION_NOT_OPENED = 0x00, + MTP_SESSION_OPENED = 0x01, +} MTP_SessionStateTypeDef; + +/* MTP response phases */ +typedef enum +{ + MTP_PHASE_IDLE = 0x00, + MTP_RESPONSE_PHASE = 0x01, + MTP_READ_DATA = 0x02, + MTP_RECEIVE_DATA = 0x03, +} MTP_ResponsePhaseTypeDef; + +typedef struct +{ + uint32_t temp_length; + uint32_t prv_len; + uint32_t totallen; + uint32_t rx_length; + uint32_t readbytes; /* File write/read counts */ +} MTP_DataLengthTypeDef; + +typedef enum +{ + RECEIVE_IDLE_STATE = 0x00U, + RECEIVE_COMMAND_DATA = 0x01U, + RECEIVE_FIRST_DATA = 0x02U, + RECEIVE_REST_OF_DATA = 0x03U, + SEND_RESPONSE = 0x04U, +} MTP_RECEIVE_DATA_STATUS; + +typedef struct +{ + uint32_t length; + uint16_t type; + uint16_t code; + uint32_t trans_id; + uint32_t Param1; + uint32_t Param2; + uint32_t Param3; + uint32_t Param4; + uint32_t Param5; +} MTP_OperationsTypedef; + +typedef struct +{ + uint32_t length; + uint16_t type; + uint16_t code; + uint32_t trans_id; + uint8_t data[MTP_MEDIA_PACKET]; +} MTP_GenericContainerTypeDef; + +#if defined ( __GNUC__ ) +typedef __PACKED_STRUCT +#else +__packed typedef struct +#endif +{ + uint32_t Storage_id; + uint16_t ObjectFormat; + uint16_t ProtectionStatus; + uint32_t ObjectCompressedSize; + uint16_t ThumbFormat; + uint32_t ThumbCompressedSize; + uint32_t ThumbPixWidth; + uint32_t ThumbPixHeight; + uint32_t ImagePixWidth; + uint32_t ImagePixHeight; + uint32_t ImageBitDepth; + uint32_t ParentObject; + uint16_t AssociationType; + uint32_t AssociationDesc; + uint32_t SequenceNumber; + uint8_t Filename_len; + uint16_t Filename[255]; + uint32_t CaptureDate; + uint32_t ModificationDate; + uint8_t Keywords; +} MTP_ObjectInfoTypeDef; + +typedef struct +{ + uint32_t alt_setting; + uint32_t dev_status; + uint32_t ResponseLength; + uint32_t ResponseCode; + __IO uint16_t MaxPcktLen; + uint32_t rx_buff[MTP_MEDIA_PACKET / 4U]; /* Force 32-bit alignment */ + MTP_ResponsePhaseTypeDef MTP_ResponsePhase; + MTP_SessionStateTypeDef MTP_SessionState; + MTP_RECEIVE_DATA_STATUS RECEIVE_DATA_STATUS; + MTP_OperationsTypedef OperationsContainer; + MTP_GenericContainerTypeDef GenericContainer; +} USBD_MTP_HandleTypeDef; + +/** @defgroup USBD_CORE_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_CORE_Exported_Variables + * @{ + */ + +extern USBD_ClassTypeDef USBD_MTP; +#define USBD_MTP_CLASS &USBD_MTP + +/** + * @} + */ + +/** @defgroup USB_CORE_Exported_Functions + * @{ + */ + +typedef struct _USBD_MTP_ItfTypeDef +{ + uint8_t (*Init)(void); + uint8_t (*DeInit)(void); + uint32_t (*ReadData)(uint32_t Param1, uint8_t *buff, MTP_DataLengthTypeDef *data_length); + uint16_t (*Create_NewObject)(MTP_ObjectInfoTypeDef ObjectInfo, uint32_t objhandle); + + uint32_t (*GetIdx)(uint32_t Param3, uint32_t *obj_handle); + uint32_t (*GetParentObject)(uint32_t Param); + uint16_t (*GetObjectFormat)(uint32_t Param); + uint8_t (*GetObjectName_len)(uint32_t Param); + void (*GetObjectName)(uint32_t Param, uint8_t obj_len, uint16_t *buf); + uint32_t (*GetObjectSize)(uint32_t Param); + uint64_t (*GetMaxCapability)(void); + uint64_t (*GetFreeSpaceInBytes)(void); + uint32_t (*GetNewIndex)(uint16_t objformat); + void (*WriteData)(uint16_t len, uint8_t buff[]); + uint32_t (*GetContainerLength)(uint32_t Param1); + uint16_t (*DeleteObject)(uint32_t Param1); + void (*Cancel)(uint32_t Phase); + uint32_t *ScratchBuff; + uint32_t ScratchBuffSze; +} USBD_MTP_ItfTypeDef; + +/** + * @} + */ +/** @defgroup USB_CORE_Exported_Functions + * @{ + */ +uint8_t USBD_MTP_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_MTP_ItfTypeDef *fops); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USB_MTP_H */ +/** + * @} + */ + +/** + * @} + */ diff --git a/Class/MTP/Inc/usbd_mtp_if_template.h b/Class/MTP/Inc/usbd_mtp_if_template.h new file mode 100644 index 0000000..bfdcad0 --- /dev/null +++ b/Class/MTP/Inc/usbd_mtp_if_template.h @@ -0,0 +1,95 @@ +/** + ****************************************************************************** + * @file usbd_mtp_if_template.h + * @author MCD Application Team + * @brief Header file for the usbd_mtp_if_template.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_MTP_IF_TEMPLATE_H +#define __USBD_MTP_IF_TEMPLATE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_mtp.h" + +/* Exported Define -----------------------------------------------------------*/ +#define USBD_MTP_DEVICE_PROP_SUPPORTED 1U +#define USBD_MTP_CAPTURE_FORMAT_SUPPORTED 1U +#define USBD_MTP_VEND_EXT_DESC_SUPPORTED 1U +#define USBD_MTP_EVENTS_SUPPORTED 1U + +#if USBD_MTP_EVENTS_SUPPORTED == 1 +#define SUPP_EVENTS_LEN (uint8_t)((uint8_t)sizeof(SuppEvents) / 2U) +#else +#define SUPP_EVENTS_LEN 0U +#endif + +#if USBD_MTP_VEND_EXT_DESC_SUPPORTED == 1 +#define VEND_EXT_DESC_LEN (sizeof(VendExtDesc) / 2U) +#else +#define VEND_EXT_DESC_LEN 0U +#endif + +#if USBD_MTP_CAPTURE_FORMAT_SUPPORTED == 1 +#define SUPP_CAPT_FORMAT_LEN (uint8_t)((uint8_t)sizeof(SuppCaptFormat) / 2U) +#else +#define SUPP_CAPT_FORMAT_LEN 0U +#endif + +#if USBD_MTP_DEVICE_PROP_SUPPORTED == 1 +#define SUPP_DEVICE_PROP_LEN (uint8_t)((uint8_t)sizeof(DevicePropSupp) / 2U) +#else +#define SUPP_DEVICE_PROP_LEN 0U +#endif + +#define MTP_IF_SCRATCH_BUFF_SZE 1024U + +/* Exported types ------------------------------------------------------------*/ +extern USBD_MTP_ItfTypeDef USBD_MTP_fops; + +/* Exported macros -----------------------------------------------------------*/ +/* Exported variables --------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ + +static const uint16_t Manuf[] = {'S', 'T', 'M', 0}; /* last 2 bytes must be 0*/ +static const uint16_t Model[] = {'S', 'T', 'M', '3', '2', 0}; /* last 2 bytes must be 0*/ +static const uint16_t VendExtDesc[] = {'m', 'i', 'c', 'r', 'o', 's', 'o', 'f', 't', '.', + 'c', 'o', 'm', ':', ' ', '1', '.', '0', ';', ' ', 0 + }; /* last 2 bytes must be 0*/ +/*SerialNbr shall be 32 character hexadecimal string for legacy compatibility reasons */ +static const uint16_t SerialNbr[] = {'0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0', + '1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', 0 + }; /* last 2 bytes must be 0*/ +static const uint16_t DeviceVers[] = {'V', '1', '.', '0', '0', 0}; /* last 2 bytes must be 0*/ + +static const uint16_t DefaultFileName[] = {'N', 'e', 'w', ' ', 'F', 'o', 'l', 'd', 'e', 'r', 0}; + +static const uint16_t DevicePropDefVal[] = {'S', 'T', 'M', '3', '2', 0}; /* last 2 bytes must be 0*/ +static const uint16_t DevicePropCurDefVal[] = {'S', 'T', 'M', '3', '2', ' ', 'V', '1', '.', '0', 0}; + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_MTP_IF_TEMPLATE_H */ + diff --git a/Class/MTP/Inc/usbd_mtp_opt.h b/Class/MTP/Inc/usbd_mtp_opt.h new file mode 100644 index 0000000..73498ab --- /dev/null +++ b/Class/MTP/Inc/usbd_mtp_opt.h @@ -0,0 +1,658 @@ +/** + ****************************************************************************** + * @file usbd_mtp_opt.h + * @author MCD Application Team + * @brief header file for the usbd_mtp_opt.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_MTP_OPT_H__ +#define __USBD_MTP_OPT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#ifndef __USBD_MTP_IF_H +#include "usbd_mtp_if_template.h" +#endif +#include "usbd_mtp.h" + +/** @addtogroup STM32_USB_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_MTP_OPT + * @brief This file is the header file for usbd_mtp_opt.c + * @{ + */ + + +/** @defgroup USBD_MTP_OPT_Exported_Defines + * @{ + */ +/* MTP OBJECT PROPERTIES supported*/ +#define MTP_OB_PROP_STORAGE_ID 0xDC01U +#define MTP_OB_PROP_OBJECT_FORMAT 0xDC02U +#define MTP_OB_PROP_PROTECTION_STATUS 0xDC03U +#define MTP_OB_PROP_OBJECT_SIZE 0xDC04U +#define MTP_OB_PROP_ASSOC_TYPE 0xDC05U +#define MTP_OB_PROP_ASSOC_DESC 0xDC06U +#define MTP_OB_PROP_OBJ_FILE_NAME 0xDC07U +#define MTP_OB_PROP_DATE_CREATED 0xDC08U +#define MTP_OB_PROP_DATE_MODIFIED 0xDC09U +#define MTP_OB_PROP_KEYWORDS 0xDC0AU +#define MTP_OB_PROP_PARENT_OBJECT 0xDC0BU +#define MTP_OB_PROP_ALLOWED_FOLD_CONTENTS 0xDC0CU +#define MTP_OB_PROP_HIDDEN 0xDC0DU +#define MTP_OB_PROP_SYSTEM_OBJECT 0xDC0EU +#define MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN 0xDC41U +#define MTP_OB_PROP_SYNCID 0xDC42U +#define MTP_OB_PROP_PROPERTY_BAG 0xDC43U +#define MTP_OB_PROP_NAME 0xDC44U +#define MTP_OB_PROP_CREATED_BY 0xDC45U +#define MTP_OB_PROP_ARTIST 0xDC46U +#define MTP_OB_PROP_DATE_AUTHORED 0xDC47U +#define MTP_OB_PROP_DESCRIPTION 0xDC48U +#define MTP_OB_PROP_URL_REFERENCE 0xDC49U +#define MTP_OB_PROP_LANGUAGELOCALE 0xDC4AU +#define MTP_OB_PROP_COPYRIGHT_INFORMATION 0xDC4BU +#define MTP_OB_PROP_SOURCE 0xDC4CU +#define MTP_OB_PROP_ORIGIN_LOCATION 0xDC4DU +#define MTP_OB_PROP_DATE_ADDED 0xDC4EU +#define MTP_OB_PROP_NON_CONSUMABLE 0xDC4FU +#define MTP_OB_PROP_CORRUPTUNPLAYABLE 0xDC50U +#define MTP_OB_PROP_PRODUCERSERIALNUMBER 0xDC51U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_FORMAT 0xDC81U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_SIZE 0xDC82U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_HEIGHT 0xDC83U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_WIDTH 0xDC84U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_DURATION 0xDC85U +#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_DATA 0xDC86U +#define MTP_OB_PROP_WIDTH 0xDC87U +#define MTP_OB_PROP_HEIGHT 0xDC88U +#define MTP_OB_PROP_DURATION 0xDC89U +#define MTP_OB_PROP_RATING 0xDC8AU +#define MTP_OB_PROP_TRACK 0xDC8BU +#define MTP_OB_PROP_GENRE 0xDC8CU +#define MTP_OB_PROP_CREDITS 0xDC8DU +#define MTP_OB_PROP_LYRICS 0xDC8EU +#define MTP_OB_PROP_SUBSCRIPTION_CONTENT_ID 0xDC8FU +#define MTP_OB_PROP_PRODUCED_BY 0xDC90U +#define MTP_OB_PROP_USE_COUNT 0xDC91U +#define MTP_OB_PROP_SKIP_COUNT 0xDC92U +#define MTP_OB_PROP_LAST_ACCESSED 0xDC93U +#define MTP_OB_PROP_PARENTAL_RATING 0xDC94U +#define MTP_OB_PROP_META_GENRE 0xDC95U +#define MTP_OB_PROP_COMPOSER 0xDC96U +#define MTP_OB_PROP_EFFECTIVE_RATING 0xDC97U +#define MTP_OB_PROP_SUBTITLE 0xDC98U +#define MTP_OB_PROP_ORIGINAL_RELEASE_DATE 0xDC99U +#define MTP_OB_PROP_ALBUM_NAME 0xDC9AU +#define MTP_OB_PROP_ALBUM_ARTIST 0xDC9BU +#define MTP_OB_PROP_MOOD 0xDC9CU +#define MTP_OB_PROP_DRM_STATUS 0xDC9DU +#define MTP_OB_PROP_SUB_DESCRIPTION 0xDC9EU +#define MTP_OB_PROP_IS_CROPPED 0xDCD1U +#define MTP_OB_PROP_IS_COLOUR_CORRECTED 0xDCD2U +#define MTP_OB_PROP_IMAGE_BIT_DEPTH 0xDCD3U +#define MTP_OB_PROP_FNUMBER 0xDCD4U +#define MTP_OB_PROP_EXPOSURE_TIME 0xDCD5U +#define MTP_OB_PROP_EXPOSURE_INDEX 0xDCD6U +#define MTP_OB_PROP_TOTAL_BITRATE 0xDE91U +#define MTP_OB_PROP_BITRATE_TYPE 0xDE92U +#define MTP_OB_PROP_SAMPLE_RATE 0xDE93U +#define MTP_OB_PROP_NUMBER_OF_CHANNELS 0xDE94U +#define MTP_OB_PROP_AUDIO_BITDEPTH 0xDE95U +#define MTP_OB_PROP_SCAN_TYPE 0xDE97U +#define MTP_OB_PROP_AUDIO_WAVE_CODEC 0xDE99U +#define MTP_OB_PROP_AUDIO_BITRATE 0xDE9AU +#define MTP_OB_PROP_VIDEO_FOURCC_CODEC 0xDE9BU +#define MTP_OB_PROP_VIDEO_BITRATE 0xDE9CU +#define MTP_OB_PROP_FRAMES_PER_THOUSAND_SECONDS 0xDE9DU +#define MTP_OB_PROP_KEYFRAME_DISTANCE 0xDE9EU +#define MTP_OB_PROP_BUFFER_SIZE 0xDE9FU +#define MTP_OB_PROP_ENCODING_QUALITY 0xDEA0U +#define MTP_OB_PROP_ENCODING_PROFILE 0xDEA1U +#define MTP_OB_PROP_DISPLAY_NAME 0xDCE0U +#define MTP_OB_PROP_BODY_TEXT 0xDCE1U +#define MTP_OB_PROP_SUBJECT 0xDCE2U +#define MTP_OB_PROP_PRIORITY 0xDCE3U +#define MTP_OB_PROP_GIVEN_NAME 0xDD00U +#define MTP_OB_PROP_MIDDLE_NAMES 0xDD01U +#define MTP_OB_PROP_FAMILY_NAME 0xDD02U +#define MTP_OB_PROP_PREFIX 0xDD03U +#define MTP_OB_PROP_SUFFIX 0xDD04U +#define MTP_OB_PROP_PHONETIC_GIVEN_NAME 0xDD05U +#define MTP_OB_PROP_PHONETIC_FAMILY_NAME 0xDD06U +#define MTP_OB_PROP_EMAIL_PRIMARY 0xDD07U +#define MTP_OB_PROP_EMAIL_PERSONAL_1 0xDD08U +#define MTP_OB_PROP_EMAIL_PERSONAL_2 0xDD09U +#define MTP_OB_PROP_EMAIL_BUSINESS_1 0xDD0AU +#define MTP_OB_PROP_EMAIL_BUSINESS_2 0xDD0BU +#define MTP_OB_PROP_EMAIL_OTHERS 0xDD0CU +#define MTP_OB_PROP_PHONE_NUMBER_PRIMARY 0xDD0DU +#define MTP_OB_PROP_PHONE_NUMBER_PERSONAL 0xDD0EU +#define MTP_OB_PROP_PHONE_NUMBER_PERSONAL_2 0xDD0FU +#define MTP_OB_PROP_PHONE_NUMBER_BUSINESS 0xDD10U +#define MTP_OB_PROP_PHONE_NUMBER_BUSINESS_2 0xDD11U +#define MTP_OB_PROP_PHONE_NUMBER_MOBILE 0xDD12U +#define MTP_OB_PROP_PHONE_NUMBER_MOBILE_2 0xDD13U +#define MTP_OB_PROP_FAX_NUMBER_PRIMARY 0xDD14U +#define MTP_OB_PROP_FAX_NUMBER_PERSONAL 0xDD15U +#define MTP_OB_PROP_FAX_NUMBER_BUSINESS 0xDD16U +#define MTP_OB_PROP_PAGER_NUMBER 0xDD17U +#define MTP_OB_PROP_PHONE_NUMBER_OTHERS 0xDD18U +#define MTP_OB_PROP_PRIMARY_WEB_ADDRESS 0xDD19U +#define MTP_OB_PROP_PERSONAL_WEB_ADDRESS 0xDD1AU +#define MTP_OB_PROP_BUSINESS_WEB_ADDRESS 0xDD1BU +#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS 0xDD1CU +#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS_2 0xDD1DU +#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS_3 0xDD1EU +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_FULL 0xDD1FU +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_LINE_1 0xDD20U +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_LINE_2 0xDD21U +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_CITY 0xDD22U +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_REGION 0xDD23U +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_POSTAL_CODE 0xDD24U +#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_COUNTRY 0xDD25U +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_FULL 0xDD26U +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_LINE_1 0xDD27U +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_LINE_2 0xDD28U +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_CITY 0xDD29U +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_REGION 0xDD2AU +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_POSTAL_CODE 0xDD2BU +#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_COUNTRY 0xDD2CU +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_FULL 0xDD2DU +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_LINE_1 0xDD2EU +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_LINE_2 0xDD2FU +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_CITY 0xDD30U +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_REGION 0xDD31U +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_POSTAL_CODE 0xDD32U +#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_COUNTRY 0xDD33U +#define MTP_OB_PROP_ORGANIZATION_NAME 0xDD34U +#define MTP_OB_PROP_PHONETIC_ORGANIZATION_NAME 0xDD35U +#define MTP_OB_PROP_ROLE 0xDD36U +#define MTP_OB_PROP_BIRTHDATE 0xDD37U +#define MTP_OB_PROP_MESSAGE_TO 0xDD40U +#define MTP_OB_PROP_MESSAGE_CC 0xDD41U +#define MTP_OB_PROP_MESSAGE_BCC 0xDD42U +#define MTP_OB_PROP_MESSAGE_READ 0xDD43U +#define MTP_OB_PROP_MESSAGE_RECEIVED_TIME 0xDD44U +#define MTP_OB_PROP_MESSAGE_SENDER 0xDD45U +#define MTP_OB_PROP_ACT_BEGIN_TIME 0xDD50U +#define MTP_OB_PROP_ACT_END_TIME 0xDD51U +#define MTP_OB_PROP_ACT_LOCATION 0xDD52U +#define MTP_OB_PROP_ACT_REQUIRED_ATTENDEES 0xDD54U +#define MTP_OB_PROP_ACT_OPTIONAL_ATTENDEES 0xDD55U +#define MTP_OB_PROP_ACT_RESOURCES 0xDD56U +#define MTP_OB_PROP_ACT_ACCEPTED 0xDD57U +#define MTP_OB_PROP_OWNER 0xDD5DU +#define MTP_OB_PROP_EDITOR 0xDD5EU +#define MTP_OB_PROP_WEBMASTER 0xDD5FU +#define MTP_OB_PROP_URL_SOURCE 0xDD60U +#define MTP_OB_PROP_URL_DESTINATION 0xDD61U +#define MTP_OB_PROP_TIME_BOOKMARK 0xDD62U +#define MTP_OB_PROP_OBJECT_BOOKMARK 0xDD63U +#define MTP_OB_PROP_BYTE_BOOKMARK 0xDD64U +#define MTP_OB_PROP_LAST_BUILD_DATE 0xDD70U +#define MTP_OB_PROP_TIME_TO_LIVE 0xDD71U +#define MTP_OB_PROP_MEDIA_GUID 0xDD72U + +/* MTP event codes*/ +#define MTP_EVENT_UNDEFINED 0x4000U +#define MTP_EVENT_CANCELTRANSACTION 0x4001U +#define MTP_EVENT_OBJECTADDED 0x4002U +#define MTP_EVENT_OBJECTREMOVED 0x4003U +#define MTP_EVENT_STOREADDED 0x4004U +#define MTP_EVENT_STOREREMOVED 0x4005U +#define MTP_EVENT_DEVICEPROPCHANGED 0x4006U +#define MTP_EVENT_OBJECTINFOCHANGED 0x4007U +#define MTP_EVENT_DEVICEINFOCHANGED 0x4008U +#define MTP_EVENT_REQUESTOBJECTTRANSFER 0x4009U +#define MTP_EVENT_STOREFULL 0x400AU +#define MTP_EVENT_DEVICERESET 0x400BU +#define MTP_EVENT_STORAGEINFOCHANGED 0x400CU +#define MTP_EVENT_CAPTURECOMPLETE 0x400DU +#define MTP_EVENT_UNREPORTEDSTATUS 0x400EU +#define MTP_EVENT_OBJECTPROPCHANGED 0xC801U +#define MTP_EVENT_OBJECTPROPDESCCHANGED 0xC802U +#define MTP_EVENT_OBJECTREFERENCESCHANGED 0xC803U + +/* Operations code */ +#define MTP_OP_GET_DEVICE_INFO 0x1001U +#define MTP_OP_OPEN_SESSION 0x1002U +#define MTP_OP_CLOSE_SESSION 0x1003U +#define MTP_OP_GET_STORAGE_IDS 0x1004U +#define MTP_OP_GET_STORAGE_INFO 0x1005U +#define MTP_OP_GET_NUM_OBJECTS 0x1006U +#define MTP_OP_GET_OBJECT_HANDLES 0x1007U +#define MTP_OP_GET_OBJECT_INFO 0x1008U +#define MTP_OP_GET_OBJECT 0x1009U +#define MTP_OP_GET_THUMB 0x100AU +#define MTP_OP_DELETE_OBJECT 0x100BU +#define MTP_OP_SEND_OBJECT_INFO 0x100CU +#define MTP_OP_SEND_OBJECT 0x100DU +#define MTP_OP_FORMAT_STORE 0x100FU +#define MTP_OP_RESET_DEVICE 0x1010U +#define MTP_OP_GET_DEVICE_PROP_DESC 0x1014U +#define MTP_OP_GET_DEVICE_PROP_VALUE 0x1015U +#define MTP_OP_SET_DEVICE_PROP_VALUE 0x1016U +#define MTP_OP_RESET_DEVICE_PROP_VALUE 0x1017U +#define MTP_OP_TERMINATE_OPEN_CAPTURE 0x1018U +#define MTP_OP_MOVE_OBJECT 0x1019U +#define MTP_OP_COPY_OBJECT 0x101AU +#define MTP_OP_GET_PARTIAL_OBJECT 0x101BU +#define MTP_OP_INITIATE_OPEN_CAPTURE 0x101CU +#define MTP_OP_GET_OBJECT_PROPS_SUPPORTED 0x9801U +#define MTP_OP_GET_OBJECT_PROP_DESC 0x9802U +#define MTP_OP_GET_OBJECT_PROP_VALUE 0x9803U +#define MTP_OP_SET_OBJECT_PROP_VALUE 0x9804U +#define MTP_OP_GET_OBJECT_PROPLIST 0x9805U +#define MTP_OP_GET_OBJECT_PROP_REFERENCES 0x9810U +#define MTP_OP_GETSERVICEIDS 0x9301U +#define MTP_OP_GETSERVICEINFO 0x9302U +#define MTP_OP_GETSERVICECAPABILITIES 0x9303U +#define MTP_OP_GETSERVICEPROPDESC 0x9304U + +/* MTP device properties code*/ +#define MTP_DEV_PROP_UNDEFINED 0x5000U +#define MTP_DEV_PROP_BATTERY_LEVEL 0x5001U +#define MTP_DEV_PROP_FUNCTIONAL_MODE 0x5002U +#define MTP_DEV_PROP_IMAGE_SIZE 0x5003U +#define MTP_DEV_PROP_COMPRESSION_SETTING 0x5004U +#define MTP_DEV_PROP_WHITE_BALANCE 0x5005U +#define MTP_DEV_PROP_RGB_GAIN 0x5006U +#define MTP_DEV_PROP_F_NUMBER 0x5007U +#define MTP_DEV_PROP_FOCAL_LENGTH 0x5008U +#define MTP_DEV_PROP_FOCUS_DISTANCE 0x5009U +#define MTP_DEV_PROP_FOCUS_MODE 0x500AU +#define MTP_DEV_PROP_EXPOSURE_METERING_MODE 0x500BU +#define MTP_DEV_PROP_FLASH_MODE 0x500CU +#define MTP_DEV_PROP_EXPOSURE_TIME 0x500DU +#define MTP_DEV_PROP_EXPOSURE_PROGRAM_MODE 0x500EU +#define MTP_DEV_PROP_EXPOSURE_INDEX 0x500FU +#define MTP_DEV_PROP_EXPOSURE_BIAS_COMPENSATION 0x5010U +#define MTP_DEV_PROP_DATETIME 0x5011U +#define MTP_DEV_PROP_CAPTURE_DELAY 0x5012U +#define MTP_DEV_PROP_STILL_CAPTURE_MODE 0x5013U +#define MTP_DEV_PROP_CONTRAST 0x5014U +#define MTP_DEV_PROP_SHARPNESS 0x5015U +#define MTP_DEV_PROP_DIGITAL_ZOOM 0x5016U +#define MTP_DEV_PROP_EFFECT_MODE 0x5017U +#define MTP_DEV_PROP_BURST_NUMBER 0x5018U +#define MTP_DEV_PROP_BURST_INTERVAL 0x5019U +#define MTP_DEV_PROP_TIMELAPSE_NUMBER 0x501AU +#define MTP_DEV_PROP_TIMELAPSE_INTERVAL 0x501BU +#define MTP_DEV_PROP_FOCUS_METERING_MODE 0x501CU +#define MTP_DEV_PROP_UPLOAD_URL 0x501DU +#define MTP_DEV_PROP_ARTIST 0x501EU +#define MTP_DEV_PROP_COPYRIGHT_INFO 0x501FU +#define MTP_DEV_PROP_SYNCHRONIZATION_PARTNER 0xD401U +#define MTP_DEV_PROP_DEVICE_FRIENDLY_NAME 0xD402U +#define MTP_DEV_PROP_VOLUME 0xD403U +#define MTP_DEV_PROP_SUPPORTEDFORMATSORDERED 0xD404U +#define MTP_DEV_PROP_DEVICEICON 0xD405U +#define MTP_DEV_PROP_PLAYBACK_RATE 0xD410U +#define MTP_DEV_PROP_PLAYBACK_OBJECT 0xD411U +#define MTP_DEV_PROP_PLAYBACK_CONTAINER 0xD412U +#define MTP_DEV_PROP_SESSION_INITIATOR_VERSION_INFO 0xD406U +#define MTP_DEV_PROP_PERCEIVED_DEVICE_TYPE 0xD407U + + +/* Container Types */ +#define MTP_CONT_TYPE_UNDEFINED 0U +#define MTP_CONT_TYPE_COMMAND 1U +#define MTP_CONT_TYPE_DATA 2U +#define MTP_CONT_TYPE_RESPONSE 3U +#define MTP_CONT_TYPE_EVENT 4U + +#ifndef MTP_STORAGE_ID +#define MTP_STORAGE_ID 0x00010001U /* SD card is inserted*/ +#endif /* MTP_STORAGE_ID */ + +#define MTP_NBR_STORAGE_ID 1U +#define FREE_SPACE_IN_OBJ_NOT_USED 0xFFFFFFFFU + +/* MTP storage type */ +#define MTP_STORAGE_UNDEFINED 0U +#define MTP_STORAGE_FIXED_ROM 0x0001U +#define MTP_STORAGE_REMOVABLE_ROM 0x0002U +#define MTP_STORAGE_FIXED_RAM 0x0003U +#define MTP_STORAGE_REMOVABLE_RAM 0x0004U + +/* MTP file system type */ +#define MTP_FILESYSTEM_UNDEFINED 0U +#define MTP_FILESYSTEM_GENERIC_FLAT 0x0001U +#define MTP_FILESYSTEM_GENERIC_HIERARCH 0x0002U +#define MTP_FILESYSTEM_DCF 0x0003U + +/* MTP access capability */ +#define MTP_ACCESS_CAP_RW 0U /* read write */ +#define MTP_ACCESS_CAP_RO_WITHOUT_DEL 0x0001U +#define MTP_ACCESS_CAP_RO_WITH_DEL 0x0002U + +/* MTP standard data types supported */ +#define MTP_DATATYPE_INT8 0x0001U +#define MTP_DATATYPE_UINT8 0x0002U +#define MTP_DATATYPE_INT16 0x0003U +#define MTP_DATATYPE_UINT16 0x0004U +#define MTP_DATATYPE_INT32 0x0005U +#define MTP_DATATYPE_UINT32 0x0006U +#define MTP_DATATYPE_INT64 0x0007U +#define MTP_DATATYPE_UINT64 0x0008U +#define MTP_DATATYPE_UINT128 0x000AU +#define MTP_DATATYPE_STR 0xFFFFU + +/* MTP reading only or reading/writing */ +#define MTP_PROP_GET 0x00U +#define MTP_PROP_GET_SET 0x01U + + +/* MTP functional mode */ +#define STANDARD_MODE 0U +#define SLEEP_STATE 1U +#define FUNCTIONAL_MODE STANDARD_MODE + +/* MTP device info */ +#define STANDARD_VERSION 100U +#define VEND_EXT_ID 0x06U +#define VEND_EXT_VERSION 100U +#define MANUF_LEN (sizeof(Manuf) / 2U) +#define MODEL_LEN (sizeof(Model) / 2U) +#define SUPP_OP_LEN (sizeof(SuppOP) / 2U) +#define SERIAL_NBR_LEN (sizeof(SerialNbr) / 2U) +#define DEVICE_VERSION_LEN (sizeof(DeviceVers) / 2U) +#define SUPP_IMG_FORMAT_LEN (sizeof(SuppImgFormat) / 2U) +#define SUPP_OBJ_PROP_LEN (sizeof(ObjectPropSupp) / 2U) + +#ifndef MAX_FILE_NAME +#define MAX_FILE_NAME 255U +#endif /* MAX_FILE_NAME */ + +#ifndef MAX_OBJECT_HANDLE_LEN +#define MAX_OBJECT_HANDLE_LEN 100U +#endif /* MAX_OBJECT_HANDLE_LEN */ + +#ifndef DEVICE_PROP_DESC_DEF_LEN +#define DEVICE_PROP_DESC_DEF_LEN (uint8_t)(sizeof(DevicePropDefVal) / 2U) +#endif /* DEVICE_PROP_DESC_DEF_LEN */ + +#ifndef DEVICE_PROP_DESC_CUR_LEN +#define DEVICE_PROP_DESC_CUR_LEN (uint8_t)(sizeof(DevicePropCurDefVal) / 2U) +#endif /* DEVICE_PROP_DESC_CUR_LEN */ + +#ifndef DEFAULT_FILE_NAME_LEN +#define DEFAULT_FILE_NAME_LEN (uint8_t)(sizeof(DefaultFileName) / 2U) +#endif /* DEFAULT_FILE_NAME_LEN */ + +/** + * @} + */ + + +/** @defgroup USBD_MTP_OPT_Exported_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +static const uint16_t SuppOP[] = { MTP_OP_GET_DEVICE_INFO, MTP_OP_OPEN_SESSION, MTP_OP_CLOSE_SESSION, MTP_OP_GET_STORAGE_IDS, MTP_OP_GET_STORAGE_INFO, + MTP_OP_GET_NUM_OBJECTS, MTP_OP_GET_OBJECT_HANDLES, MTP_OP_GET_OBJECT_INFO, MTP_OP_GET_OBJECT, MTP_OP_DELETE_OBJECT, + MTP_OP_SEND_OBJECT_INFO, MTP_OP_SEND_OBJECT, MTP_OP_GET_DEVICE_PROP_DESC, MTP_OP_GET_DEVICE_PROP_VALUE, + MTP_OP_SET_OBJECT_PROP_VALUE, MTP_OP_GET_OBJECT_PROP_VALUE, MTP_OP_GET_OBJECT_PROPS_SUPPORTED, MTP_OP_GET_OBJECT_PROPLIST, + MTP_OP_GET_OBJECT_PROP_DESC, MTP_OP_GET_OBJECT_PROP_REFERENCES + }; + +static const uint16_t SuppEvents[] = {MTP_EVENT_OBJECTADDED}; +static const uint16_t SuppImgFormat[] = {MTP_OBJ_FORMAT_UNDEFINED, MTP_OBJ_FORMAT_TEXT, MTP_OBJ_FORMAT_ASSOCIATION, MTP_OBJ_FORMAT_EXECUTABLE, MTP_OBJ_FORMAT_WAV, + MTP_OBJ_FORMAT_MP3, MTP_OBJ_FORMAT_EXIF_JPEG, MTP_OBJ_FORMAT_MPEG, MTP_OBJ_FORMAT_MP4_CONTAINER, + MTP_OBJ_FORMAT_WINDOWS_IMAGE_FORMAT, MTP_OBJ_FORMAT_PNG, MTP_OBJ_FORMAT_WMA, MTP_OBJ_FORMAT_WMV + }; + +static const uint16_t SuppCaptFormat[] = {MTP_OBJ_FORMAT_UNDEFINED, MTP_OBJ_FORMAT_ASSOCIATION, MTP_OBJ_FORMAT_TEXT}; + +/* required for all object format : storageID, objectFormat, ObjectCompressedSize, persistent unique object identifier, name*/ +static const uint16_t ObjectPropSupp[] = {MTP_OB_PROP_STORAGE_ID, MTP_OB_PROP_OBJECT_FORMAT, MTP_OB_PROP_OBJECT_SIZE, MTP_OB_PROP_OBJ_FILE_NAME, + MTP_OB_PROP_PARENT_OBJECT, MTP_OB_PROP_NAME, MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN, MTP_OB_PROP_PROTECTION_STATUS + }; + +static const uint16_t DevicePropSupp[] = {MTP_DEV_PROP_DEVICE_FRIENDLY_NAME, MTP_DEV_PROP_BATTERY_LEVEL}; + +/* for all mtp struct */ +typedef struct +{ + uint32_t StorageIDS_len; + uint32_t StorageIDS[MTP_NBR_STORAGE_ID]; +} MTP_StorageIDSTypeDef; + +#if defined ( __GNUC__ ) +typedef __PACKED_STRUCT +#else +__packed typedef struct +#endif +{ + uint8_t FileName_len; + uint16_t FileName[MAX_FILE_NAME]; +} MTP_FileNameTypeDef; + + +typedef struct +{ + uint32_t ObjectHandle_len; + uint32_t ObjectHandle[MAX_OBJECT_HANDLE_LEN]; +} MTP_ObjectHandleTypeDef; + +#if defined ( __GNUC__ ) +typedef __PACKED_STRUCT +#else +__packed typedef struct +#endif +{ + uint32_t ObjectPropSupp_len; + uint16_t ObjectPropSupp[SUPP_OBJ_PROP_LEN]; +} MTP_ObjectPropSuppTypeDef; + + +#if defined ( __GNUC__ ) +typedef __PACKED_STRUCT +#else +__packed typedef struct +#endif +{ + uint16_t StorageType; + uint16_t FilesystemType; + uint16_t AccessCapability; + uint64_t MaxCapability; + uint64_t FreeSpaceInBytes; + uint32_t FreeSpaceInObjects; + uint8_t StorageDescription; + uint8_t VolumeLabel; +} MTP_StorageInfoTypedef; + +typedef union +{ + uint16_t str[100]; + uint8_t u8; + int8_t i8; + uint16_t u16; + int16_t i16; + uint32_t u32; + int32_t i32; + uint64_t u64; + int64_t i64; +} MTP_PropertyValueTypedef; + +#if defined ( __GNUC__ ) +typedef __PACKED_STRUCT +#else +__packed typedef struct +#endif +{ + uint16_t ObjectPropertyCode; + uint16_t DataType; + uint8_t GetSet; + uint8_t *DefValue; + uint32_t GroupCode; + uint8_t FormFlag; +} MTP_ObjectPropDescTypeDef; + + +#if defined ( __GNUC__ ) +typedef __PACKED_STRUCT +#else +__packed typedef struct +#endif +{ + uint32_t ObjectHandle; + uint16_t PropertyCode; + uint16_t Datatype; + uint8_t *propval; +} MTP_PropertiesTypedef; + +#if defined ( __GNUC__ ) +typedef __PACKED_STRUCT +#else +__packed typedef struct +#endif +{ + uint32_t MTP_Properties_len; + MTP_PropertiesTypedef MTP_Properties[SUPP_OBJ_PROP_LEN]; +} MTP_PropertiesListTypedef; + + +#if defined ( __GNUC__ ) +typedef __PACKED_STRUCT +#else +__packed typedef struct +#endif +{ + uint32_t ref_len; + uint32_t ref[1]; +} MTP_RefTypeDef; + +#if defined ( __GNUC__ ) +typedef __PACKED_STRUCT +#else +__packed typedef struct +#endif +{ + uint16_t DevicePropertyCode; + uint16_t DataType; + uint8_t GetSet; + uint8_t DefValue_len; + uint16_t DefValue[DEVICE_PROP_DESC_DEF_LEN]; + uint8_t curDefValue_len; + uint16_t curDefValue[DEVICE_PROP_DESC_CUR_LEN]; + uint8_t FormFlag; +} MTP_DevicePropDescTypeDef; + +/* MTP device info structure */ +#if defined ( __GNUC__ ) +typedef __PACKED_STRUCT +#else +__packed typedef struct +#endif +{ + uint16_t StandardVersion; + uint32_t VendorExtensionID; + uint16_t VendorExtensionVersion; + uint8_t VendorExtensionDesc_len; +#if USBD_MTP_VEND_EXT_DESC_SUPPORTED == 1 + uint16_t VendorExtensionDesc[VEND_EXT_DESC_LEN]; +#endif + uint16_t FunctionalMode; + uint32_t OperationsSupported_len; + uint16_t OperationsSupported[SUPP_OP_LEN]; + uint32_t EventsSupported_len; +#if USBD_MTP_EVENTS_SUPPORTED == 1 + uint16_t EventsSupported[SUPP_EVENTS_LEN]; +#endif + uint32_t DevicePropertiesSupported_len; +#if USBD_MTP_DEVICE_PROP_SUPPORTED == 1 + uint16_t DevicePropertiesSupported[SUPP_DEVICE_PROP_LEN]; +#endif + uint32_t CaptureFormats_len; +#if USBD_MTP_CAPTURE_FORMAT_SUPPORTED == 1 + uint16_t CaptureFormats[SUPP_CAPT_FORMAT_LEN]; +#endif + uint32_t ImageFormats_len; + uint16_t ImageFormats[SUPP_IMG_FORMAT_LEN]; + uint8_t Manufacturer_len; + uint16_t Manufacturer[MANUF_LEN]; + uint8_t Model_len; + uint16_t Model[MODEL_LEN]; + uint8_t DeviceVersion_len; + uint16_t DeviceVersion[DEVICE_VERSION_LEN]; + uint8_t SerialNumber_len; + uint16_t SerialNumber[SERIAL_NBR_LEN]; +} MTP_DeviceInfoTypedef; + +/** @defgroup USBD_MTP_OPT_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_MTP_OPT_Exported_Variables + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_MTP_OPT_Exported_Functions + * @{ + */ + +void USBD_MTP_OPT_CreateObjectHandle(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_GetDeviceInfo(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_GetStorageIDS(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_GetStorageInfo(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_GetObjectHandle(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_GetObjectInfo(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_GetObjectReferences(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_GetObjectPropSupp(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_GetObjectPropDesc(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_GetObjectPropValue(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_GetObjectPropList(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_GetDevicePropDesc(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_SendObjectInfo(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len); +void USBD_MTP_OPT_SendObject(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len); +void USBD_MTP_OPT_GetObject(USBD_HandleTypeDef *pdev); +void USBD_MTP_OPT_DeleteObject(USBD_HandleTypeDef *pdev); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_MTP_OPT_H__ */ +/** + * @} + */ + +/** + * @} + */ diff --git a/Class/MTP/Inc/usbd_mtp_storage.h b/Class/MTP/Inc/usbd_mtp_storage.h new file mode 100644 index 0000000..ba01901 --- /dev/null +++ b/Class/MTP/Inc/usbd_mtp_storage.h @@ -0,0 +1,118 @@ +/** + ****************************************************************************** + * @file usbd_mtp_storage.h + * @author MCD Application Team + * @brief header file for the usbd_mtp_storage.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_MTP_STORAGE_H__ +#define __USBD_MTP_STORAGE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_ctlreq.h" +#include "usbd_mtp_opt.h" + +/** @addtogroup STM32_USB_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_MTP_STORAGE + * @brief This file is the header file for usbd_template_core.c + * @{ + */ + + +/** @defgroup USBD_MTP_STORAGE_Exported_Defines + * @{ + */ + +/** + * @} + */ + + +/** @defgroup USBD_MTP_STORAGE_Exported_TypesDefinitions + * @{ + */ + +typedef enum +{ + DATA_TYPE = 0x00, + REP_TYPE = 0x01, +} MTP_CONTAINER_TYPE; + + +typedef enum +{ + READ_FIRST_DATA = 0x00, + READ_REST_OF_DATA = 0x01, +} MTP_READ_DATA_STATUS; + + +/** + * @} + */ + + + +/** @defgroup USBD_MTP_STORAGE_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_MTP_STORAGE_Exported_Variables + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_MTP_STORAGE_Exported_Functions + * @{ + */ + +uint8_t USBD_MTP_STORAGE_Init(USBD_HandleTypeDef *pdev); +uint8_t USBD_MTP_STORAGE_DeInit(USBD_HandleTypeDef *pdev); +void USBD_MTP_STORAGE_Cancel(USBD_HandleTypeDef *pdev, MTP_ResponsePhaseTypeDef MTP_ResponsePhase); +uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev); +uint8_t USBD_MTP_STORAGE_SendContainer(USBD_HandleTypeDef *pdev, MTP_CONTAINER_TYPE CONT_TYPE); +uint8_t USBD_MTP_STORAGE_ReceiveOpt(USBD_HandleTypeDef *pdev); +uint8_t USBD_MTP_STORAGE_ReceiveData(USBD_HandleTypeDef *pdev); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_MTP_STORAGE_H */ +/** + * @} + */ + +/** + * @} + */ diff --git a/Class/MTP/Src/usbd_mtp.c b/Class/MTP/Src/usbd_mtp.c new file mode 100644 index 0000000..1407b4a --- /dev/null +++ b/Class/MTP/Src/usbd_mtp.c @@ -0,0 +1,639 @@ +/** + ****************************************************************************** + * @file usbd_mtp.c + * @author MCD Application Team + * @brief This file provides the high layer firmware functions to manage the + * following functionalities of the USB MTP Class: + * - Initialization and Configuration of high and low layer + * - Enumeration as MTP Device (and enumeration for each implemented memory interface) + * - OUT/IN data transfer + * - Command IN transfer (class requests management) + * - Error management + * + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + * @verbatim + * + * =================================================================== + * MTP Class Driver Description + * =================================================================== + * This driver manages the "Universal Serial Bus Class Definitions for Media Transfer Protocol + * Revision 1.1 April 6, 2011" + * This driver implements the following aspects of the specification: + * - Device descriptor management + * - Configuration descriptor management + * - Enumeration as MTP device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN) + * - Requests management + * + * + * @endverbatim + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_mtp.h" +#include "usbd_mtp_storage.h" + +/** @addtogroup STM32_USB_DEVICE_LIBRARY + * @{ + */ + + +/** @defgroup USBD_MTP + * @brief usbd core module + * @{ + */ + +/** @defgroup USBD_MTP_Private_TypesDefinitions + * @{ + */ +/** + * @} + */ + + +/** @defgroup USBD_MTP_Private_Defines + * @{ + */ +/** + * @} + */ + + +/** @defgroup USBD_MTP_Private_Macros + * @{ + */ + +/** + * @} + */ + + +/** @defgroup USBD_MTP_Private_FunctionPrototypes + * @{ + */ +static uint8_t USBD_MTP_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx); +static uint8_t USBD_MTP_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx); +static uint8_t USBD_MTP_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); +static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t *USBD_MTP_GetHSCfgDesc(uint16_t *length); +static uint8_t *USBD_MTP_GetFSCfgDesc(uint16_t *length); +static uint8_t *USBD_MTP_GetOtherSpeedCfgDesc(uint16_t *length); +static uint8_t *USBD_MTP_GetDeviceQualifierDescriptor(uint16_t *length); + + +/** + * @} + */ + +/** @defgroup USBD_MTP_Private_Variables + * @{ + */ + + +/* MTP interface class callbacks structure */ +USBD_ClassTypeDef USBD_MTP = +{ + USBD_MTP_Init, + USBD_MTP_DeInit, + USBD_MTP_Setup, + NULL, /*EP0_TxSent*/ + NULL, /*EP0_RxReady*/ + USBD_MTP_DataIn, + USBD_MTP_DataOut, + NULL, /*SOF */ + NULL, /*ISOIn*/ + NULL, /*ISOOut*/ + USBD_MTP_GetHSCfgDesc, + USBD_MTP_GetFSCfgDesc, + USBD_MTP_GetOtherSpeedCfgDesc, + USBD_MTP_GetDeviceQualifierDescriptor, +}; + +/* USB MTP device Configuration Descriptor */ +__ALIGN_BEGIN static uint8_t USBD_MTP_CfgHSDesc[MTP_CONFIG_DESC_SIZ] __ALIGN_END = +{ + /* Configuration Descriptor */ + 0x09, /* bLength: Configuration Descriptor size */ + USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ + LOBYTE(MTP_CONFIG_DESC_SIZ), /* wTotalLength: Total size of the Config descriptor */ + HIBYTE(MTP_CONFIG_DESC_SIZ), + 0x01, /* bNumInterfaces: 1 interface */ + 0x01, /* bConfigurationValue: Configuration value */ + 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ +#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) */ + + /******************** MTP **** interface ********************/ + MTP_INTERFACE_DESC_SIZE, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */ + MTP_CMD_ITF_NBR, /* bInterfaceNumber: Number of Interface */ + 0x00, /* bAlternateSetting: Alternate setting */ + 0x03, /* bNumEndpoints: */ + USB_MTP_INTRERFACE_CLASS, /* bInterfaceClass: bInterfaceClass: user's interface for MTP */ + USB_MTP_INTRERFACE_SUB_CLASS, /* bInterfaceSubClass:Abstract Control Model */ + USB_MTP_INTRERFACE_PROTOCOL, /* bInterfaceProtocol: Common AT commands */ + 0x00, /* iInterface: */ + + /******************** MTP Endpoints ********************/ + MTP_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */ + USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */ + MTP_IN_EP, /* Endpoint address (IN, address 1) */ + USBD_EP_TYPE_BULK, /* Bulk endpoint type */ + LOBYTE(MTP_DATA_MAX_HS_PACKET_SIZE), + HIBYTE(MTP_DATA_MAX_HS_PACKET_SIZE), + 0x00, /* Polling interval in milliseconds */ + + MTP_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */ + USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */ + MTP_OUT_EP, /* Endpoint address (OUT, address 1) */ + USBD_EP_TYPE_BULK, /* Bulk endpoint type */ + LOBYTE(MTP_DATA_MAX_HS_PACKET_SIZE), + HIBYTE(MTP_DATA_MAX_HS_PACKET_SIZE), + 0x00, /* Polling interval in milliseconds */ + + MTP_ENDPOINT_DESC_SIZE, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType:*/ + MTP_CMD_EP, /* bEndpointAddress: Endpoint Address (IN) */ + USBD_EP_TYPE_INTR, /* bmAttributes: Interrupt endpoint */ + LOBYTE(MTP_CMD_PACKET_SIZE), + HIBYTE(MTP_CMD_PACKET_SIZE), + MTP_HS_BINTERVAL /* Polling interval in milliseconds */ +}; + +/* USB MTP device Configuration Descriptor */ +__ALIGN_BEGIN static uint8_t USBD_MTP_CfgFSDesc[MTP_CONFIG_DESC_SIZ] __ALIGN_END = +{ + /* Configuration Descriptor */ + 0x09, /* bLength: Configuration Descriptor size */ + USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ + LOBYTE(MTP_CONFIG_DESC_SIZ), /* wTotalLength: Total size of the Config descriptor */ + HIBYTE(MTP_CONFIG_DESC_SIZ), + 0x01, /* bNumInterfaces: 1 interface */ + 0x01, /* bConfigurationValue: Configuration value */ + 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ +#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) */ + + /******************** MTP **** interface ********************/ + MTP_INTERFACE_DESC_SIZE, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */ + MTP_CMD_ITF_NBR, /* bInterfaceNumber: Number of Interface */ + 0x00, /* bAlternateSetting: Alternate setting */ + 0x03, /* bNumEndpoints: */ + USB_MTP_INTRERFACE_CLASS, /* bInterfaceClass: bInterfaceClass: user's interface for MTP */ + USB_MTP_INTRERFACE_SUB_CLASS, /* bInterfaceSubClass:Abstract Control Model */ + USB_MTP_INTRERFACE_PROTOCOL, /* bInterfaceProtocol: Common AT commands */ + 0x00, /* iInterface: */ + + /******************** MTP Endpoints ********************/ + MTP_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */ + USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */ + MTP_IN_EP, /* Endpoint address (IN, address 1) */ + USBD_EP_TYPE_BULK, /* Bulk endpoint type */ + LOBYTE(MTP_DATA_MAX_FS_PACKET_SIZE), + HIBYTE(MTP_DATA_MAX_FS_PACKET_SIZE), + 0x00, /* Polling interval in milliseconds */ + + MTP_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */ + USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */ + MTP_OUT_EP, /* Endpoint address (OUT, address 1) */ + USBD_EP_TYPE_BULK, /* Bulk endpoint type */ + LOBYTE(MTP_DATA_MAX_FS_PACKET_SIZE), + HIBYTE(MTP_DATA_MAX_FS_PACKET_SIZE), + 0x00, /* Polling interval in milliseconds */ + + MTP_ENDPOINT_DESC_SIZE, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType:*/ + MTP_CMD_EP, /* bEndpointAddress: Endpoint Address (IN) */ + USBD_EP_TYPE_INTR, /* bmAttributes: Interrupt endpoint */ + LOBYTE(MTP_CMD_PACKET_SIZE), + HIBYTE(MTP_CMD_PACKET_SIZE), + MTP_FS_BINTERVAL /* Polling interval in milliseconds */ +}; + +/* USB Standard Device Descriptor */ +__ALIGN_BEGIN static uint8_t USBD_MTP_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = +{ + USB_LEN_DEV_QUALIFIER_DESC, + USB_DESC_TYPE_DEVICE_QUALIFIER, + 0x00, + 0x02, + 0x00, + 0x00, + 0x00, + 0x40, + 0x01, + 0x00, +}; + +/** + * @} + */ + +/** @defgroup USBD_MTP_Private_Functions + * @{ + */ + +/** + * @brief USBD_MTP_Init + * Initialize the MTP interface + * @param pdev: device instance + * @param cfgidx: Configuration index + * @retval status + */ +static uint8_t USBD_MTP_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) +{ + UNUSED(cfgidx); + USBD_MTP_HandleTypeDef *hmtp; + + hmtp = (USBD_MTP_HandleTypeDef *)USBD_malloc(sizeof(USBD_MTP_HandleTypeDef)); + + if (hmtp == NULL) + { + pdev->pClassData = NULL; + return (uint8_t)USBD_EMEM; + } + + /* Setup the pClassData pointer */ + pdev->pClassData = (void *)hmtp; + + /* Initialize all variables */ + (void)USBD_memset(hmtp, 0, sizeof(USBD_MTP_HandleTypeDef)); + + /* Setup the max packet size according to selected speed */ + hmtp->MaxPcktLen = (pdev->dev_speed == USBD_SPEED_HIGH) ? MTP_DATA_MAX_HS_PACKET_SIZE : MTP_DATA_MAX_FS_PACKET_SIZE; + + /* Open EP IN */ + (void)USBD_LL_OpenEP(pdev, MTP_IN_EP, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen); + pdev->ep_in[MTP_IN_EP & 0xFU].is_used = 1U; + + /* Open EP OUT */ + (void)USBD_LL_OpenEP(pdev, MTP_OUT_EP, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen); + pdev->ep_out[MTP_OUT_EP & 0xFU].is_used = 1U; + + /* Open INTR EP IN */ + (void)USBD_LL_OpenEP(pdev, MTP_CMD_EP, USBD_EP_TYPE_INTR, MTP_CMD_PACKET_SIZE); + pdev->ep_in[MTP_CMD_EP & 0xFU].is_used = 1U; + + /* Init the MTP layer */ + (void)USBD_MTP_STORAGE_Init(pdev); + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_MTP_DeInit + * DeInitialize the MTP layer + * @param pdev: device instance + * @param cfgidx: Configuration index + * @retval status + */ +static uint8_t USBD_MTP_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) +{ + UNUSED(cfgidx); + + /* Close EP IN */ + (void)USBD_LL_CloseEP(pdev, MTP_IN_EP); + pdev->ep_in[MTP_IN_EP & 0xFU].is_used = 0U; + + /* Close EP OUT */ + (void)USBD_LL_CloseEP(pdev, MTP_OUT_EP); + pdev->ep_out[MTP_OUT_EP & 0xFU].is_used = 0U; + + /* Close EP Command */ + (void)USBD_LL_CloseEP(pdev, MTP_CMD_EP); + pdev->ep_in[MTP_CMD_EP & 0xFU].is_used = 0U; + + /* De-Init the MTP layer */ + (void)USBD_MTP_STORAGE_DeInit(pdev); + + /* Free MTP Class Resources */ + if (pdev->pClassData != NULL) + { + (void)USBD_free(pdev->pClassData); + pdev->pClassData = NULL; + } + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_MTP_Setup + * Handle the MTP specific requests + * @param pdev: instance + * @param req: usb requests + * @retval status + */ +static uint8_t USBD_MTP_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + USBD_StatusTypeDef ret = USBD_OK; + uint16_t len = 0U; + + if (hmtp == NULL) + { + return (uint8_t)USBD_FAIL; + } + + switch (req->bmRequest & USB_REQ_TYPE_MASK) + { + /* Class request */ + case USB_REQ_TYPE_CLASS : + switch (req->bRequest) + { + case MTP_REQ_CANCEL: + len = MIN(hmtp->MaxPcktLen, req->wLength); + (void)USBD_CtlPrepareRx(pdev, (uint8_t *)(hmtp->rx_buff), len); + break; + + case MTP_REQ_GET_EXT_EVENT_DATA: + break; + + case MTP_REQ_RESET: + /* Stop low layer file system operations if any */ + USBD_MTP_STORAGE_Cancel(pdev, MTP_PHASE_IDLE); + + (void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, hmtp->MaxPcktLen); + break; + + case MTP_REQ_GET_DEVICE_STATUS: + switch (hmtp->MTP_ResponsePhase) + { + case MTP_READ_DATA : + len = 4U; + hmtp->dev_status = ((uint32_t)MTP_RESPONSE_DEVICE_BUSY << 16) | len; + break; + + case MTP_RECEIVE_DATA : + len = 4U; + hmtp->dev_status = ((uint32_t)MTP_RESPONSE_TRANSACTION_CANCELLED << 16) | len; + break; + + case MTP_PHASE_IDLE : + len = 4U; + hmtp->dev_status = ((uint32_t)MTP_RESPONSE_OK << 16) | len; + break; + + default: + break; + } + (void)USBD_CtlSendData(pdev, (uint8_t *)&hmtp->dev_status, len); + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } + break; + + /* Interface & Endpoint request */ + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) + { + case USB_REQ_GET_INTERFACE : + + if (pdev->dev_state == USBD_STATE_CONFIGURED) + { + hmtp->alt_setting = 0U; + (void)USBD_CtlSendData(pdev, (uint8_t *)&hmtp->alt_setting, 1U); + } + break; + + case USB_REQ_SET_INTERFACE : + if (pdev->dev_state != USBD_STATE_CONFIGURED) + { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_CLEAR_FEATURE: + + /* Re-activate the EP */ + (void)USBD_LL_CloseEP(pdev, (uint8_t)req->wIndex); + + if ((((uint8_t)req->wIndex) & 0x80U) == 0x80U) + { + (void)USBD_LL_OpenEP(pdev, ((uint8_t)req->wIndex), USBD_EP_TYPE_BULK, hmtp->MaxPcktLen); + } + else + { + (void)USBD_LL_OpenEP(pdev, ((uint8_t)req->wIndex), USBD_EP_TYPE_BULK, hmtp->MaxPcktLen); + } + break; + + default: + break; + } + break; + + default: + break; + } + return (uint8_t)ret; +} + +/** + * @brief USBD_MTP_DataIn + * Data sent on non-control IN endpoint + * @param pdev: device instance + * @param epnum: endpoint number + * @retval status + */ +static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) +{ + UNUSED(epnum); + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + uint16_t len; + + if (epnum == (MTP_IN_EP & 0x7FU)) + { + switch (hmtp->MTP_ResponsePhase) + { + case MTP_RESPONSE_PHASE : + (void)USBD_MTP_STORAGE_SendContainer(pdev, REP_TYPE); + + /* prepare to receive next operation */ + len = MIN(hmtp->MaxPcktLen, pdev->request.wLength); + + (void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len); + hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE; + break; + case MTP_READ_DATA : + (void)USBD_MTP_STORAGE_ReadData(pdev); + + /* prepare to receive next operation */ + len = MIN(hmtp->MaxPcktLen, pdev->request.wLength); + + (void)USBD_LL_PrepareReceive(pdev, MTP_IN_EP, (uint8_t *)&hmtp->rx_buff, len); + break; + case MTP_PHASE_IDLE : + /* prepare to receive next operation */ + len = MIN(hmtp->MaxPcktLen, pdev->request.wLength); + + (void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len); + + break; + default: + break; + } + } + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_MTP_DataOut + * Data received on non-control Out endpoint + * @param pdev: device instance + * @param epnum: endpoint number + * @retval status + */ +static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) +{ + UNUSED(epnum); + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + uint16_t len; + + (void)USBD_MTP_STORAGE_ReceiveOpt(pdev); + + switch (hmtp->MTP_ResponsePhase) + { + case MTP_RESPONSE_PHASE : + + if (hmtp->ResponseLength == MTP_CONT_HEADER_SIZE) + { + (void)USBD_MTP_STORAGE_SendContainer(pdev, REP_TYPE); + hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE; + } + else + { + (void)USBD_MTP_STORAGE_SendContainer(pdev, DATA_TYPE); + } + break; + + case MTP_READ_DATA : + (void)USBD_MTP_STORAGE_ReadData(pdev); + break; + + case MTP_RECEIVE_DATA : + (void)USBD_MTP_STORAGE_ReceiveData(pdev); + + /* prepare endpoint to receive operations */ + len = MIN(hmtp->MaxPcktLen, pdev->request.wLength); + + (void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len); + break; + + case MTP_PHASE_IDLE : + /* prepare to receive next operation */ + len = MIN(hmtp->MaxPcktLen, pdev->request.wLength); + + (void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len); + break; + + default: + break; + } + + return (uint8_t)USBD_OK; +} + + +/** + * @brief USBD_MTP_GetHSCfgDesc + * Return configuration descriptor + * @param speed : current device speed + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t *USBD_MTP_GetHSCfgDesc(uint16_t *length) +{ + *length = (uint16_t)sizeof(USBD_MTP_CfgHSDesc); + return USBD_MTP_CfgHSDesc; +} + +/** + * @brief USBD_MTP_GetFSCfgDesc + * Return configuration descriptor + * @param speed : current device speed + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t *USBD_MTP_GetFSCfgDesc(uint16_t *length) +{ + *length = (uint16_t)sizeof(USBD_MTP_CfgFSDesc); + return USBD_MTP_CfgFSDesc; +} + +/** + * @brief USBD_MTP_GetOtherSpeedCfgDesc + * Return configuration descriptor + * @param speed : current device speed + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t *USBD_MTP_GetOtherSpeedCfgDesc(uint16_t *length) +{ + *length = (uint16_t)sizeof(USBD_MTP_CfgFSDesc); + return USBD_MTP_CfgFSDesc; +} + +/** + * @brief USBD_MTP_GetDeviceQualifierDescriptor + * return Device Qualifier descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t *USBD_MTP_GetDeviceQualifierDescriptor(uint16_t *length) +{ + *length = (uint16_t)(sizeof(USBD_MTP_DeviceQualifierDesc)); + return USBD_MTP_DeviceQualifierDesc; +} + +/** + * @brief USBD_MTP_RegisterInterface + * @param pdev: device instance + * @param fops: CD Interface callback + * @retval status + */ +uint8_t USBD_MTP_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_MTP_ItfTypeDef *fops) +{ + if (fops == NULL) + { + return (uint8_t)USBD_FAIL; + } + + pdev->pUserData = fops; + + return (uint8_t)USBD_OK; +} + +/** + * @} + */ + +/** + * @} + */ + diff --git a/Class/MTP/Src/usbd_mtp_if_template.c b/Class/MTP/Src/usbd_mtp_if_template.c new file mode 100644 index 0000000..baeb9ca --- /dev/null +++ b/Class/MTP/Src/usbd_mtp_if_template.c @@ -0,0 +1,347 @@ +/** + ****************************************************************************** + * @file usbd_mtp_if.c + * @author MCD Application Team + * @brief Source file for USBD MTP file list_files. + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_mtp_if_template.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* +static FILE MyFile; +static FATFS SDFatFs; +static char SDPath[4]; +static FolderLevel Fold_Lvl; +static FOLD_INFTypeDef FoldStruct; +static FILE_INFTypeDef FileStruct; +static SD_Object_TypeDef sd_object; +*/ +extern USBD_HandleTypeDef USBD_Device; + +uint32_t idx[200]; +uint32_t parent; +/* static char path[255]; */ +uint32_t sc_buff[MTP_IF_SCRATCH_BUFF_SZE / 4U]; +uint32_t sc_len = 0U; +uint32_t pckt_cnt = 1U; +uint32_t foldsize; + +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +static uint8_t USBD_MTP_Itf_Init(void); +static uint8_t USBD_MTP_Itf_DeInit(void); +static uint32_t USBD_MTP_Itf_ReadData(uint32_t Param1, uint8_t *buff, MTP_DataLengthTypeDef *data_length); +static uint16_t USBD_MTP_Itf_Create_NewObject(MTP_ObjectInfoTypeDef ObjectInfo, uint32_t objhandle); + +static uint32_t USBD_MTP_Itf_GetIdx(uint32_t Param3, uint32_t *obj_handle); +static uint32_t USBD_MTP_Itf_GetParentObject(uint32_t Param); +static uint16_t USBD_MTP_Itf_GetObjectFormat(uint32_t Param); +static uint8_t USBD_MTP_Itf_GetObjectName_len(uint32_t Param); +static void USBD_MTP_Itf_GetObjectName(uint32_t Param, uint8_t obj_len, uint16_t *buf); +static uint32_t USBD_MTP_Itf_GetObjectSize(uint32_t Param); +static uint64_t USBD_MTP_Itf_GetMaxCapability(void); +static uint64_t USBD_MTP_Itf_GetFreeSpaceInBytes(void); +static uint32_t USBD_MTP_Itf_GetNewIndex(uint16_t objformat); +static void USBD_MTP_Itf_WriteData(uint16_t len, uint8_t *buff); +static uint32_t USBD_MTP_Itf_GetContainerLength(uint32_t Param1); +static uint16_t USBD_MTP_Itf_DeleteObject(uint32_t Param1); + +static void USBD_MTP_Itf_Cancel(uint32_t Phase); +/* static uint32_t USBD_MTP_Get_idx_to_delete(uint32_t Param, uint8_t *tab); */ + +USBD_MTP_ItfTypeDef USBD_MTP_fops = +{ + USBD_MTP_Itf_Init, + USBD_MTP_Itf_DeInit, + USBD_MTP_Itf_ReadData, + USBD_MTP_Itf_Create_NewObject, + USBD_MTP_Itf_GetIdx, + USBD_MTP_Itf_GetParentObject, + USBD_MTP_Itf_GetObjectFormat, + USBD_MTP_Itf_GetObjectName_len, + USBD_MTP_Itf_GetObjectName, + USBD_MTP_Itf_GetObjectSize, + USBD_MTP_Itf_GetMaxCapability, + USBD_MTP_Itf_GetFreeSpaceInBytes, + USBD_MTP_Itf_GetNewIndex, + USBD_MTP_Itf_WriteData, + USBD_MTP_Itf_GetContainerLength, + USBD_MTP_Itf_DeleteObject, + USBD_MTP_Itf_Cancel, + sc_buff, + MTP_IF_SCRATCH_BUFF_SZE, +}; + +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief USBD_MTP_Itf_Init + * Initialize the file system Layer + * @param None + * @retval status value + */ +static uint8_t USBD_MTP_Itf_Init(void) +{ + return 0; +} + +/** + * @brief USBD_MTP_Itf_DeInit + * Uninitialize the file system Layer + * @param None + * @retval status value + */ +static uint8_t USBD_MTP_Itf_DeInit(void) +{ + return 0; +} + +/** + * @brief USBD_MTP_Itf_GetIdx + * Get all object handle + * @param Param3: current object handle + * @param obj_handle: all objects handle (subfolders/files) in current object + * @retval number of object handle in current object + */ +static uint32_t USBD_MTP_Itf_GetIdx(uint32_t Param3, uint32_t *obj_handle) +{ + uint32_t count = 0U; + UNUSED(Param3); + UNUSED(obj_handle); + + return count; +} + +/** + * @brief USBD_MTP_Itf_GetParentObject + * Get parent object + * @param Param: object handle (object index) + * @retval parent object + */ +static uint32_t USBD_MTP_Itf_GetParentObject(uint32_t Param) +{ + uint32_t parentobj = 0U; + UNUSED(Param); + + return parentobj; +} + +/** + * @brief USBD_MTP_Itf_GetObjectFormat + * Get object format + * @param Param: object handle (object index) + * @retval object format + */ +static uint16_t USBD_MTP_Itf_GetObjectFormat(uint32_t Param) +{ + uint16_t objformat = 0U; + UNUSED(Param); + + return objformat; +} + +/** + * @brief USBD_MTP_Itf_GetObjectName_len + * Get object name length + * @param Param: object handle (object index) + * @retval object name length + */ +static uint8_t USBD_MTP_Itf_GetObjectName_len(uint32_t Param) +{ + uint8_t obj_len = 0U; + UNUSED(Param); + + return obj_len; +} + +/** + * @brief USBD_MTP_Itf_GetObjectName + * Get object name + * @param Param: object handle (object index) + * @param obj_len: length of object name + * @param buf: pointer to object name + * @retval object size in SD card + */ +static void USBD_MTP_Itf_GetObjectName(uint32_t Param, uint8_t obj_len, uint16_t *buf) +{ + UNUSED(Param); + UNUSED(obj_len); + UNUSED(buf); + + return; +} + +/** + * @brief USBD_MTP_Itf_GetObjectSize + * Get size of current object + * @param Param: object handle (object index) + * @retval object size in SD card + */ +static uint32_t USBD_MTP_Itf_GetObjectSize(uint32_t Param) +{ + uint32_t ObjCompSize = 0U; + UNUSED(Param); + + return ObjCompSize; +} + +/** + * @brief USBD_MTP_Itf_Create_NewObject + * Create new object in SD card and store necessary information for future use + * @param ObjectInfo: object information to use + * @param objhandle: object handle (object index) + * @retval None + */ +static uint16_t USBD_MTP_Itf_Create_NewObject(MTP_ObjectInfoTypeDef ObjectInfo, uint32_t objhandle) +{ + uint16_t rep_code = 0U; + UNUSED(ObjectInfo); + UNUSED(objhandle); + + return rep_code; +} + +/** + * @brief USBD_MTP_Itf_GetMaxCapability + * Get max capability in SD card + * @param None + * @retval max capability + */ +static uint64_t USBD_MTP_Itf_GetMaxCapability(void) +{ + uint64_t max_cap = 0U; + + return max_cap; +} + +/** + * @brief USBD_MTP_Itf_GetFreeSpaceInBytes + * Get free space in bytes in SD card + * @param None + * @retval free space in bytes + */ +static uint64_t USBD_MTP_Itf_GetFreeSpaceInBytes(void) +{ + uint64_t f_space_inbytes = 0U; + + return f_space_inbytes; +} + +/** + * @brief USBD_MTP_Itf_GetNewIndex + * Create new object handle + * @param objformat: object format + * @retval object handle + */ +static uint32_t USBD_MTP_Itf_GetNewIndex(uint16_t objformat) +{ + uint32_t n_index = 0U; + UNUSED(objformat); + + return n_index; +} + +/** + * @brief USBD_MTP_Itf_WriteData + * Write file data to SD card + * @param len: size of data to write + * @param buff: data to write in SD card + * @retval None + */ +static void USBD_MTP_Itf_WriteData(uint16_t len, uint8_t *buff) +{ + UNUSED(len); + UNUSED(buff); + + return; +} + +/** + * @brief USBD_MTP_Itf_GetContainerLength + * Get length of generic container + * @param Param1: object handle + * @retval length of generic container + */ +static uint32_t USBD_MTP_Itf_GetContainerLength(uint32_t Param1) +{ + uint32_t length = 0U; + UNUSED(Param1); + + return length; +} + +/** + * @brief USBD_MTP_Itf_DeleteObject + * delete object from SD card + * @param Param1: object handle (file/folder index) + * @retval response code + */ +static uint16_t USBD_MTP_Itf_DeleteObject(uint32_t Param1) +{ + uint16_t rep_code = 0U; + UNUSED(Param1); + + return rep_code; +} + +/** + * @brief USBD_MTP_Get_idx_to_delete + * Get all files/foldres index to delete with descending order ( max depth) + * @param Param: object handle (file/folder index) + * @param tab: pointer to list of files/folders to delete + * @retval Number of files/folders to delete + */ +/* static uint32_t USBD_MTP_Get_idx_to_delete(uint32_t Param, uint8_t *tab) +{ + uint32_t cnt = 0U; + + return cnt; +} +*/ + +/** + * @brief USBD_MTP_Itf_ReadData + * Read data from SD card + * @param Param1: object handle + * @param buff: pointer to data to be read + * @param temp_length: current data size read + * @retval necessary information for next read/finish reading + */ +static uint32_t USBD_MTP_Itf_ReadData(uint32_t Param1, uint8_t *buff, MTP_DataLengthTypeDef *data_length) +{ + UNUSED(Param1); + UNUSED(buff); + UNUSED(data_length); + + return 0U; +} + +/** + * @brief USBD_MTP_Itf_Cancel + * Close opened folder/file while cancelling transaction + * @param MTP_ResponsePhase: MTP current state + * @retval None + */ +static void USBD_MTP_Itf_Cancel(uint32_t Phase) +{ + UNUSED(Phase); + + /* Make sure to close open file while canceling transaction */ + + return; +} diff --git a/Class/MTP/Src/usbd_mtp_opt.c b/Class/MTP/Src/usbd_mtp_opt.c new file mode 100644 index 0000000..b5090eb --- /dev/null +++ b/Class/MTP/Src/usbd_mtp_opt.c @@ -0,0 +1,1266 @@ +/** + ****************************************************************************** + * @file usbd_mtp_opt.c + * @author MCD Application Team + * @brief This file includes the PTP operations layer + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_mtp_opt.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static uint8_t ObjInfo_buff[255]; +static uint32_t objhandle; +static uint16_t obj_format; +static uint32_t storage_id; + +static MTP_DeviceInfoTypedef MTP_DeviceInfo; +static MTP_StorageIDSTypeDef MTP_StorageIDS; +static MTP_StorageInfoTypedef MTP_StorageInfo; +static MTP_ObjectHandleTypeDef MTP_ObjectHandle; +static MTP_ObjectInfoTypeDef MTP_ObjectInfo; +static MTP_ObjectPropSuppTypeDef MTP_ObjectPropSupp; +static MTP_ObjectPropDescTypeDef MTP_ObjectPropDesc; +static MTP_PropertiesListTypedef MTP_PropertiesList; +static MTP_RefTypeDef MTP_Ref; +static MTP_PropertyValueTypedef MTP_PropertyValue; +static MTP_FileNameTypeDef MTP_FileName; +static MTP_DevicePropDescTypeDef MTP_DevicePropDesc; + +/* Private function prototypes -----------------------------------------------*/ +static void MTP_Get_DeviceInfo(void); +static void MTP_Get_StorageIDS(void); +static void MTP_Get_PayloadContent(USBD_HandleTypeDef *pdev); +static void MTP_Get_ObjectInfo(USBD_HandleTypeDef *pdev); +static void MTP_Get_StorageInfo(USBD_HandleTypeDef *pdev); +static void MTP_Get_ObjectHandle(USBD_HandleTypeDef *pdev); +static void MTP_Get_ObjectPropSupp(void); +static void MTP_Get_ObjectPropDesc(USBD_HandleTypeDef *pdev); +static void MTP_Get_ObjectPropList(USBD_HandleTypeDef *pdev); +static void MTP_Get_DevicePropDesc(void); +static uint8_t *MTP_Get_ObjectPropValue(USBD_HandleTypeDef *pdev); +static uint32_t MTP_build_data_propdesc(USBD_HandleTypeDef *pdev, MTP_ObjectPropDescTypeDef def); +static uint32_t MTP_build_data_ObjInfo(USBD_HandleTypeDef *pdev, MTP_ObjectInfoTypeDef objinfo); +static uint32_t MTP_build_data_proplist(USBD_HandleTypeDef *pdev, + MTP_PropertiesListTypedef proplist, uint32_t idx); + +/* Private functions ---------------------------------------------------------*/ + +/** + * @} + */ + + +/** + * @brief USBD_MTP_OPT_CreateObjectHandle + * Open a new session + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_CreateObjectHandle(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + if (hmtp->OperationsContainer.Param1 == 0U) /* Param1 == Session ID*/ + { + hmtp->ResponseCode = MTP_RESPONSE_INVALID_PARAMETER; + } + /* driver supports single session */ + else if (hmtp->MTP_SessionState == MTP_SESSION_OPENED) + { + hmtp->ResponseCode = MTP_RESPONSE_SESSION_ALREADY_OPEN; + } + else + { + hmtp->ResponseCode = MTP_RESPONSE_OK; + hmtp->MTP_SessionState = MTP_SESSION_OPENED; + } + + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE; + hmtp->ResponseLength = MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; +} + +/** + * @brief USBD_MTP_OPT_GetDeviceInfo + * Get all device information + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetDeviceInfo(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + if (hmtp->MTP_SessionState == MTP_SESSION_NOT_OPENED) /* no session opened */ + { + /* if GetDevice Info called outside a session then SessionID and Transaction_ID shall be 0x00000000*/ + if ((hmtp->OperationsContainer.Param1 == 0U) && (hmtp->OperationsContainer.trans_id == 0U)) /* Param1 == session ID*/ + { + hmtp->ResponseCode = MTP_RESPONSE_OK; + } + else + { + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE; + hmtp->ResponseCode = MTP_RESPONSE_INVALID_PARAMETER; + hmtp->GenericContainer.length = MTP_CONT_HEADER_SIZE; + } + } + else + { + hmtp->ResponseCode = MTP_RESPONSE_OK; + } + + if (hmtp->ResponseCode == MTP_RESPONSE_OK) + { + hmtp->GenericContainer.code = MTP_OP_GET_DEVICE_INFO; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->ResponseLength = sizeof(MTP_DeviceInfo) + MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + } +} + +/** + * @brief USBD_MTP_OPT_GetStorageIDS + * Get Storage IDs + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetStorageIDS(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + hmtp->GenericContainer.code = MTP_OP_GET_STORAGE_IDS; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->ResponseLength = sizeof(MTP_StorageIDS) + MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_GetStorageInfo + * Get Storage information + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetStorageInfo(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + hmtp->GenericContainer.code = MTP_OP_GET_STORAGE_INFO; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->ResponseLength = sizeof(MTP_StorageInfo) + MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_GetObjectHandle + * Get all object handles + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetObjectHandle(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_HANDLES; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->ResponseLength = hmtp->ResponseLength + MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_GetObjectInfo + * Get all information about the object + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetObjectInfo(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_INFO; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->ResponseLength = hmtp->ResponseLength + MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_GetObjectReferences + * Get object references + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetObjectReferences(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROP_REFERENCES; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->ResponseLength = sizeof(MTP_Ref) + MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_GetObjectPropSupp + * Get all object properties supported + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetObjectPropSupp(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROPS_SUPPORTED; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->ResponseLength = sizeof(MTP_ObjectPropSupp) + MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_GetObjectPropDesc + * Get all descriptions about object properties + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetObjectPropDesc(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROP_DESC; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->ResponseLength = hmtp->ResponseLength + MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_GetObjectPropList + * Get the list of object properties + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetObjectPropList(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROPLIST; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->ResponseLength = hmtp->ResponseLength + MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_GetObjectPropValue + * Get current value of the object property + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetObjectPropValue(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROP_VALUE; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->ResponseLength = hmtp->ResponseLength + MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_GetObject + * Get binary data from an object + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetObject(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData; + + hmtp->GenericContainer.length = hmtpif->GetContainerLength(hmtp->OperationsContainer.Param1); + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_GetDevicePropDesc + * Get The DevicePropDesc dataset + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_GetDevicePropDesc(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + hmtp->GenericContainer.code = MTP_OP_GET_DEVICE_PROP_DESC; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->ResponseLength = sizeof(MTP_DevicePropDesc) + MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_SendObject + * Send object from host to MTP device + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_SendObject(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData; + static uint32_t tmp = 0U; + + switch (hmtp->RECEIVE_DATA_STATUS) + { + case RECEIVE_IDLE_STATE: + hmtp->RECEIVE_DATA_STATUS = RECEIVE_COMMAND_DATA; + break; + case RECEIVE_COMMAND_DATA: + hmtp->RECEIVE_DATA_STATUS = RECEIVE_FIRST_DATA; + break; + case RECEIVE_FIRST_DATA: + if ((uint16_t)len < (hmtp->MaxPcktLen - MTP_CONT_HEADER_SIZE)) + { + hmtp->GenericContainer.code = MTP_RESPONSE_OK; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE; + hmtp->ResponseLength = MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->RECEIVE_DATA_STATUS = RECEIVE_IDLE_STATE; + } + else + { + hmtp->RECEIVE_DATA_STATUS = RECEIVE_REST_OF_DATA; + } + tmp = (uint32_t)buff; + hmtpif->WriteData(len, (uint8_t *)(tmp + 12U)); + break; + + case RECEIVE_REST_OF_DATA: + hmtpif->WriteData(len, buff); + break; + + case SEND_RESPONSE: + hmtpif->WriteData(0, buff); /* send 0 length to stop write process */ + hmtp->GenericContainer.code = MTP_RESPONSE_OK; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE; + hmtp->ResponseLength = MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + + hmtp->RECEIVE_DATA_STATUS = RECEIVE_IDLE_STATE; + break; + + default: + break; + } + + hmtp->ResponseCode = MTP_RESPONSE_OK; +} + +/** + * @brief USBD_MTP_OPT_SendObjectInfo + * Send the object information from host to MTP device + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_SendObjectInfo(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData; + MTP_ObjectInfoTypeDef ObjectInfo; + uint8_t dataLength = offsetof(MTP_ObjectInfoTypeDef, Filename); + uint8_t *tmp; + + switch (hmtp->RECEIVE_DATA_STATUS) + { + case RECEIVE_IDLE_STATE: + hmtp->RECEIVE_DATA_STATUS = RECEIVE_COMMAND_DATA; + break; + + case RECEIVE_COMMAND_DATA: + /* store object handle and storage id for future use */ + if (hmtp->OperationsContainer.Param2 == 0xFFFFFFFFU) + { + objhandle = 0U; + } + else + { + objhandle = hmtp->OperationsContainer.Param2; + } + storage_id = hmtp->OperationsContainer.Param1; + hmtp->RECEIVE_DATA_STATUS = RECEIVE_FIRST_DATA; + break; + + case RECEIVE_FIRST_DATA: + tmp = buff; + + (void)USBD_memcpy(ObjInfo_buff, tmp + 12U, + (uint16_t)(hmtp->MaxPcktLen - MTP_CONT_HEADER_SIZE)); + + hmtp->RECEIVE_DATA_STATUS = RECEIVE_REST_OF_DATA; + break; + + case RECEIVE_REST_OF_DATA: + + (void)USBD_memcpy(ObjInfo_buff + len, buff, hmtp->MaxPcktLen); + + break; + + case SEND_RESPONSE: + (void)USBD_memcpy((uint8_t *)&ObjectInfo, ObjInfo_buff, dataLength); + (void)USBD_memcpy((uint8_t *)&ObjectInfo.Filename, (ObjInfo_buff + dataLength), + ((uint32_t)(ObjectInfo.Filename_len) * 2U)); + + obj_format = ObjectInfo.ObjectFormat; + + hmtp->ResponseCode = hmtpif->Create_NewObject(ObjectInfo, objhandle); + hmtp->GenericContainer.code = (uint16_t)hmtp->ResponseCode; + hmtp->ResponseLength = MTP_CONT_HEADER_SIZE + (sizeof(uint32_t) * 3U); /* Header + 3 Param */ + hmtp->GenericContainer.length = hmtp->ResponseLength; + hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE; + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + + (void)MTP_Get_PayloadContent(pdev); + + hmtp->RECEIVE_DATA_STATUS = RECEIVE_IDLE_STATE; + break; + + default: + break; + } +} + +/** + * @brief USBD_MTP_OPT_DeleteObject + * Delete the object from the device + * @param pdev: device instance + * @retval None + */ +void USBD_MTP_OPT_DeleteObject(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData; + + hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id; + hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE; + hmtp->ResponseLength = MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + hmtp->ResponseCode = hmtpif->DeleteObject(hmtp->OperationsContainer.Param1); +} + +/** + * @brief MTP_Get_PayloadContent + * Get the payload data of generic container + * @param pdev: device instance + * @retval None + */ +static void MTP_Get_PayloadContent(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData; + uint8_t *buffer = hmtp->GenericContainer.data; + uint32_t i; + uint32_t n_idx; + + switch (hmtp->OperationsContainer.code) + { + case MTP_OP_GET_DEVICE_INFO: + (void)MTP_Get_DeviceInfo(); + (void)USBD_memcpy(buffer, (const uint8_t *)&MTP_DeviceInfo, sizeof(MTP_DeviceInfo)); + + for (i = 0U; i < sizeof(MTP_StorageIDS); i++) + { + hmtp->GenericContainer.data[i] = buffer[i]; + } + break; + + case MTP_OP_GET_STORAGE_IDS: + (void)MTP_Get_StorageIDS(); + (void)USBD_memcpy(buffer, (const uint8_t *)&MTP_StorageIDS, sizeof(MTP_StorageIDS)); + + for (i = 0U; i < sizeof(MTP_StorageIDS); i++) + { + hmtp->GenericContainer.data[i] = buffer[i]; + } + break; + + case MTP_OP_GET_STORAGE_INFO: + (void)MTP_Get_StorageInfo(pdev); + (void)USBD_memcpy(buffer, (const uint8_t *)&MTP_StorageInfo, sizeof(MTP_StorageInfo)); + + for (i = 0U; i < sizeof(MTP_StorageInfo); i++) + { + hmtp->GenericContainer.data[i] = buffer[i]; + } + break; + + case MTP_OP_GET_OBJECT_HANDLES: + (void)MTP_Get_ObjectHandle(pdev); + (void)USBD_memcpy(buffer, (const uint8_t *)&MTP_ObjectHandle, hmtp->ResponseLength); + + for (i = 0U; i < hmtp->ResponseLength; i++) + { + hmtp->GenericContainer.data[i] = buffer[i]; + } + break; + + case MTP_OP_GET_OBJECT_INFO: + (void)MTP_Get_ObjectInfo(pdev); + break; + + case MTP_OP_GET_OBJECT_PROPS_SUPPORTED: + (void)MTP_Get_ObjectPropSupp(); + (void)USBD_memcpy(buffer, (const uint8_t *)&MTP_ObjectPropSupp, sizeof(MTP_ObjectPropSupp)); + + for (i = 0U; i < sizeof(MTP_ObjectPropSupp); i++) + { + hmtp->GenericContainer.data[i] = buffer[i]; + } + break; + + case MTP_OP_GET_OBJECT_PROP_DESC: + (void)MTP_Get_ObjectPropDesc(pdev); + hmtp->ResponseLength = MTP_build_data_propdesc(pdev, MTP_ObjectPropDesc); + break; + + case MTP_OP_GET_OBJECT_PROP_REFERENCES: + MTP_Ref.ref_len = 0U; + (void)USBD_memcpy(buffer, (const uint8_t *)&MTP_Ref.ref_len, sizeof(MTP_Ref.ref_len)); + + for (i = 0U; i < sizeof(MTP_Ref.ref_len); i++) + { + hmtp->GenericContainer.data[i] = buffer[i]; + } + break; + + case MTP_OP_GET_OBJECT_PROPLIST: + (void)MTP_Get_ObjectPropList(pdev); + break; + + case MTP_OP_GET_OBJECT_PROP_VALUE: + buffer = MTP_Get_ObjectPropValue(pdev); + for (i = 0U; i < hmtp->ResponseLength; i++) + { + hmtp->GenericContainer.data[i] = buffer[i]; + } + + break; + + case MTP_OP_GET_DEVICE_PROP_DESC: + (void)MTP_Get_DevicePropDesc(); + (void)USBD_memcpy(buffer, (const uint8_t *)&MTP_DevicePropDesc, sizeof(MTP_DevicePropDesc)); + for (i = 0U; i < sizeof(MTP_DevicePropDesc); i++) + { + hmtp->GenericContainer.data[i] = buffer[i]; + } + break; + + case MTP_OP_SEND_OBJECT_INFO: + n_idx = hmtpif->GetNewIndex(obj_format); + (void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&storage_id, sizeof(uint32_t)); + (void)USBD_memcpy(hmtp->GenericContainer.data + 4U, (const uint8_t *)&objhandle, sizeof(uint32_t)); + (void)USBD_memcpy(hmtp->GenericContainer.data + 8U, (const uint8_t *)&n_idx, sizeof(uint32_t)); + break; + + case MTP_OP_GET_OBJECT: + break; + + default: + break; + } +} + +/** + * @brief MTP_Get_DeviceInfo + * Fill the MTP_DeviceInfo struct + * @param pdev: device instance + * @retval None + */ +static void MTP_Get_DeviceInfo(void) +{ + MTP_DeviceInfo.StandardVersion = STANDARD_VERSION; + MTP_DeviceInfo.VendorExtensionID = VEND_EXT_ID; + MTP_DeviceInfo.VendorExtensionVersion = VEND_EXT_VERSION; + MTP_DeviceInfo.VendorExtensionDesc_len = (uint8_t)VEND_EXT_DESC_LEN; + uint32_t i; + +#if USBD_MTP_VEND_EXT_DESC_SUPPORTED == 1 + for (i = 0U; i < VEND_EXT_DESC_LEN; i++) + { + MTP_DeviceInfo.VendorExtensionDesc[i] = VendExtDesc[i]; + } +#endif /* USBD_MTP_VEND_EXT_DESC_SUPPORTED */ + + MTP_DeviceInfo.FunctionalMode = FUNCTIONAL_MODE; /* device supports one mode , standard mode */ + + /* All supported operation */ + MTP_DeviceInfo.OperationsSupported_len = SUPP_OP_LEN; + for (i = 0U; i < SUPP_OP_LEN; i++) + { + MTP_DeviceInfo.OperationsSupported[i] = SuppOP[i]; + } + + MTP_DeviceInfo.EventsSupported_len = SUPP_EVENTS_LEN; /* event that are currently generated by the device*/ + +#if USBD_MTP_EVENTS_SUPPORTED == 1 + for (i = 0U; i < SUPP_EVENTS_LEN; i++) + { + MTP_DeviceInfo.EventsSupported[i] = SuppEvents[i]; + } +#endif /* USBD_MTP_EVENTS_SUPPORTED */ + + MTP_DeviceInfo.DevicePropertiesSupported_len = SUPP_DEVICE_PROP_LEN; + +#if USBD_MTP_DEVICE_PROP_SUPPORTED == 1 + for (i = 0U; i < SUPP_DEVICE_PROP_LEN; i++) + { + MTP_DeviceInfo.DevicePropertiesSupported[i] = DevicePropSupp[i]; + } +#endif /* USBD_MTP_DEVICE_PROP_SUPPORTED */ + + MTP_DeviceInfo.CaptureFormats_len = SUPP_CAPT_FORMAT_LEN; + +#if USBD_MTP_CAPTURE_FORMAT_SUPPORTED == 1 + for (i = 0U; i < SUPP_CAPT_FORMAT_LEN; i++) + { + MTP_DeviceInfo.CaptureFormats[i] = SuppCaptFormat[i]; + } +#endif /* USBD_MTP_CAPTURE_FORMAT_SUPPORTED */ + + MTP_DeviceInfo.ImageFormats_len = SUPP_IMG_FORMAT_LEN; /* number of image formats that are supported by the device*/ + for (i = 0U; i < SUPP_IMG_FORMAT_LEN; i++) + { + MTP_DeviceInfo.ImageFormats[i] = SuppImgFormat[i]; + } + + MTP_DeviceInfo.Manufacturer_len = (uint8_t)MANUF_LEN; + for (i = 0U; i < MANUF_LEN; i++) + { + MTP_DeviceInfo.Manufacturer[i] = Manuf[i]; + } + + MTP_DeviceInfo.Model_len = (uint8_t)MODEL_LEN; + for (i = 0U; i < MODEL_LEN; i++) + { + MTP_DeviceInfo.Model[i] = Model[i]; + } + + MTP_DeviceInfo.DeviceVersion_len = (uint8_t)DEVICE_VERSION_LEN; + for (i = 0U; i < DEVICE_VERSION_LEN; i++) + { + MTP_DeviceInfo.DeviceVersion[i] = DeviceVers[i]; + } + + MTP_DeviceInfo.SerialNumber_len = (uint8_t)SERIAL_NBR_LEN; + for (i = 0U; i < SERIAL_NBR_LEN; i++) + { + MTP_DeviceInfo.SerialNumber[i] = SerialNbr[i]; + } +} + +/** + * @brief MTP_Get_StorageInfo + * Fill the MTP_StorageInfo struct + * @param pdev: device instance + * @retval None + */ +static void MTP_Get_StorageInfo(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData; + + MTP_StorageInfo.StorageType = MTP_STORAGE_REMOVABLE_RAM; + MTP_StorageInfo.FilesystemType = MTP_FILESYSTEM_GENERIC_FLAT; + MTP_StorageInfo.AccessCapability = MTP_ACCESS_CAP_RW; + MTP_StorageInfo.MaxCapability = hmtpif->GetMaxCapability(); + MTP_StorageInfo.FreeSpaceInBytes = hmtpif->GetFreeSpaceInBytes(); + MTP_StorageInfo.FreeSpaceInObjects = FREE_SPACE_IN_OBJ_NOT_USED; /* not used */ + MTP_StorageInfo.StorageDescription = 0U; + MTP_StorageInfo.VolumeLabel = 0U; +} + +/** + * @brief MTP_Get_ObjectHandle + * Fill the MTP_ObjectHandle struct + * @param pdev: device instance + * @retval None + */ +static void MTP_Get_ObjectHandle(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData; + + MTP_ObjectHandle.ObjectHandle_len = (uint32_t)(hmtpif->GetIdx(hmtp->OperationsContainer.Param3, + MTP_ObjectHandle.ObjectHandle)); + + hmtp->ResponseLength = (MTP_ObjectHandle.ObjectHandle_len * sizeof(uint32_t)) + sizeof(uint32_t); +} + +/** + * @brief MTP_Get_ObjectPropSupp + * Fill the MTP_ObjectPropSupp struct + * @param pdev: device instance + * @retval None + */ +static void MTP_Get_ObjectPropSupp(void) +{ + uint32_t i; + + MTP_ObjectPropSupp.ObjectPropSupp_len = SUPP_OBJ_PROP_LEN; + + for (i = 0U; i < SUPP_OBJ_PROP_LEN; i++) + { + MTP_ObjectPropSupp.ObjectPropSupp[i] = ObjectPropSupp[i]; + } +} + +/** + * @brief MTP_Get_ObjectPropDesc + * Fill the MTP_ObjectPropDesc struct + * @param pdev: device instance + * @retval None + */ +static void MTP_Get_ObjectPropDesc(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + uint16_t undef_format = MTP_OBJ_FORMAT_UNDEFINED; + uint32_t storageid = MTP_STORAGE_ID; + + switch (hmtp->OperationsContainer.Param1) /* switch obj prop code */ + { + case MTP_OB_PROP_OBJECT_FORMAT : + MTP_ObjectPropDesc.ObjectPropertyCode = (uint16_t)(hmtp->OperationsContainer.Param1); + MTP_ObjectPropDesc.DataType = MTP_DATATYPE_UINT16; + MTP_ObjectPropDesc.GetSet = MTP_PROP_GET; + MTP_ObjectPropDesc.DefValue = (uint8_t *)&undef_format; + MTP_ObjectPropDesc.GroupCode = 0U; + MTP_ObjectPropDesc.FormFlag = 0U; + break; + + case MTP_OB_PROP_STORAGE_ID : + MTP_ObjectPropDesc.ObjectPropertyCode = (uint16_t)(hmtp->OperationsContainer.Param1); + MTP_ObjectPropDesc.DataType = MTP_DATATYPE_UINT32; + MTP_ObjectPropDesc.GetSet = MTP_PROP_GET; + MTP_ObjectPropDesc.DefValue = (uint8_t *)&storageid; + MTP_ObjectPropDesc.GroupCode = 0U; + MTP_ObjectPropDesc.FormFlag = 0U; + break; + + case MTP_OB_PROP_OBJ_FILE_NAME : + MTP_ObjectPropDesc.ObjectPropertyCode = (uint16_t)(hmtp->OperationsContainer.Param1); + MTP_ObjectPropDesc.DataType = MTP_DATATYPE_STR; + MTP_ObjectPropDesc.GetSet = MTP_PROP_GET; + MTP_FileName.FileName_len = DEFAULT_FILE_NAME_LEN; + (void)USBD_memcpy((void *) & (MTP_FileName.FileName), (const void *)DefaultFileName, sizeof(DefaultFileName)); + MTP_ObjectPropDesc.DefValue = (uint8_t *)&MTP_FileName; + MTP_ObjectPropDesc.GroupCode = 0U; + MTP_ObjectPropDesc.FormFlag = 0U; + break; + + case MTP_OB_PROP_PARENT_OBJECT : + MTP_ObjectPropDesc.ObjectPropertyCode = (uint16_t)(hmtp->OperationsContainer.Param1); + MTP_ObjectPropDesc.DataType = MTP_DATATYPE_STR; + MTP_ObjectPropDesc.GetSet = MTP_PROP_GET; + MTP_ObjectPropDesc.DefValue = 0U; + MTP_ObjectPropDesc.GroupCode = 0U; + MTP_ObjectPropDesc.FormFlag = 0U; + break; + + case MTP_OB_PROP_OBJECT_SIZE : + MTP_ObjectPropDesc.ObjectPropertyCode = (uint16_t)(hmtp->OperationsContainer.Param1); + MTP_ObjectPropDesc.DataType = MTP_DATATYPE_UINT64; + MTP_ObjectPropDesc.GetSet = MTP_PROP_GET; + MTP_ObjectPropDesc.DefValue = 0U; + MTP_ObjectPropDesc.GroupCode = 0U; + MTP_ObjectPropDesc.FormFlag = 0U; + break; + + case MTP_OB_PROP_NAME : + MTP_ObjectPropDesc.ObjectPropertyCode = (uint16_t)(hmtp->OperationsContainer.Param1); + MTP_ObjectPropDesc.DataType = MTP_DATATYPE_STR; + MTP_ObjectPropDesc.GetSet = MTP_PROP_GET; + MTP_FileName.FileName_len = DEFAULT_FILE_NAME_LEN; + (void)USBD_memcpy((void *) & (MTP_FileName.FileName), + (const void *)DefaultFileName, sizeof(DefaultFileName)); + + MTP_ObjectPropDesc.DefValue = (uint8_t *)&MTP_FileName; + MTP_ObjectPropDesc.GroupCode = 0U; + MTP_ObjectPropDesc.FormFlag = 0U; + break; + + case MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN : + MTP_ObjectPropDesc.ObjectPropertyCode = (uint16_t)(hmtp->OperationsContainer.Param1); + MTP_ObjectPropDesc.DataType = MTP_DATATYPE_UINT128; + MTP_ObjectPropDesc.GetSet = MTP_PROP_GET; + MTP_ObjectPropDesc.DefValue = 0U; + MTP_ObjectPropDesc.GroupCode = 0U; + MTP_ObjectPropDesc.FormFlag = 0U; + break; + + case MTP_OB_PROP_PROTECTION_STATUS : + MTP_ObjectPropDesc.ObjectPropertyCode = (uint16_t)(hmtp->OperationsContainer.Param1); + MTP_ObjectPropDesc.DataType = MTP_DATATYPE_UINT16; + MTP_ObjectPropDesc.GetSet = MTP_PROP_GET_SET; + MTP_ObjectPropDesc.DefValue = 0U; + MTP_ObjectPropDesc.GroupCode = 0U; + MTP_ObjectPropDesc.FormFlag = 0U; + break; + + default: + break; + } +} + +/** + * @brief MTP_Get_ObjectPropValue + * Get the property value + * @param pdev: device instance + * @retval None + */ +static uint8_t *MTP_Get_ObjectPropValue(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData; + static uint8_t buf[512]; + + /* Add all other supported object properties */ + switch (hmtp->OperationsContainer.Param2) + { + case MTP_OB_PROP_STORAGE_ID: + MTP_PropertyValue.u32 = MTP_STORAGE_ID; + (void)USBD_memcpy(buf, (const uint8_t *)&MTP_PropertyValue, sizeof(uint32_t)); + hmtp->ResponseLength = sizeof(uint32_t); + break; + + case MTP_OB_PROP_OBJECT_FORMAT: + MTP_PropertyValue.u16 = hmtpif->GetObjectFormat(hmtp->OperationsContainer.Param1); + (void)USBD_memcpy(buf, (const uint8_t *)&MTP_PropertyValue, sizeof(uint16_t)); + hmtp->ResponseLength = sizeof(uint16_t); + break; + + case MTP_OB_PROP_OBJ_FILE_NAME: + MTP_FileName.FileName_len = hmtpif->GetObjectName_len(hmtp->OperationsContainer.Param1); + hmtpif->GetObjectName(hmtp->OperationsContainer.Param1, MTP_FileName.FileName_len, (uint16_t *)buf); + (void)USBD_memcpy(MTP_FileName.FileName, (uint16_t *)buf, ((uint32_t)MTP_FileName.FileName_len * 2U) + 1U); + + hmtp->ResponseLength = ((uint32_t)MTP_FileName.FileName_len * 2U) + 1U; + break; + + case MTP_OB_PROP_PARENT_OBJECT : + MTP_PropertyValue.u32 = hmtpif->GetParentObject(hmtp->OperationsContainer.Param1); + (void)USBD_memcpy(buf, (const uint8_t *)&MTP_PropertyValue, sizeof(uint32_t)); + hmtp->ResponseLength = sizeof(uint32_t); + break; + + case MTP_OB_PROP_OBJECT_SIZE : + MTP_PropertyValue.u64 = hmtpif->GetObjectSize(hmtp->OperationsContainer.Param1); + (void)USBD_memcpy(buf, (const uint8_t *)&MTP_PropertyValue, sizeof(uint64_t)); + hmtp->ResponseLength = sizeof(uint64_t); + break; + + default: + break; + } + + return buf; +} + +/** + * @brief MTP_Get_ObjectPropList + * Get the object property list data to be transmitted + * @param pdev: device instance + * @retval None + */ +static void MTP_Get_ObjectPropList(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData; + uint16_t filename[255]; + uint32_t storageid = MTP_STORAGE_ID; + uint32_t default_val = 0U; + uint32_t i; + uint16_t format; + uint64_t objsize; + uint32_t parent_proval; + + MTP_PropertiesList.MTP_Properties_len = SUPP_OBJ_PROP_LEN; + hmtp->ResponseLength = 4U; /* size of MTP_PropertiesList.MTP_Properties_len */ + (void)USBD_memcpy(hmtp->GenericContainer.data, + (const uint8_t *)&MTP_PropertiesList.MTP_Properties_len, hmtp->ResponseLength); + + for (i = 0U; i < SUPP_OBJ_PROP_LEN; i++) + { + MTP_PropertiesList.MTP_Properties[i].ObjectHandle = hmtp->OperationsContainer.Param1; + + switch (ObjectPropSupp[i]) + { + case MTP_OB_PROP_STORAGE_ID : + MTP_PropertiesList.MTP_Properties[i].PropertyCode = MTP_OB_PROP_STORAGE_ID; + MTP_PropertiesList.MTP_Properties[i].Datatype = MTP_DATATYPE_UINT32; + MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&storageid; + break; + + case MTP_OB_PROP_OBJECT_FORMAT : + MTP_PropertiesList.MTP_Properties[i].PropertyCode = MTP_OB_PROP_OBJECT_FORMAT; + MTP_PropertiesList.MTP_Properties[i].Datatype = MTP_DATATYPE_UINT16; + format = hmtpif->GetObjectFormat(hmtp->OperationsContainer.Param1); + MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&format; + break; + + case MTP_OB_PROP_OBJ_FILE_NAME: + MTP_PropertiesList.MTP_Properties[i].PropertyCode = MTP_OB_PROP_OBJ_FILE_NAME; + MTP_PropertiesList.MTP_Properties[i].Datatype = MTP_DATATYPE_STR; + /* MTP_FileName.FileName_len value shall be set before USBD_MTP_FS_GetObjectName */ + MTP_FileName.FileName_len = hmtpif->GetObjectName_len(hmtp->OperationsContainer.Param1); + hmtpif->GetObjectName(hmtp->OperationsContainer.Param1, MTP_FileName.FileName_len, filename); + (void)USBD_memcpy(MTP_FileName.FileName, filename, ((uint32_t)MTP_FileName.FileName_len * 2U) + 1U ); + MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&MTP_FileName; + break; + + case MTP_OB_PROP_PARENT_OBJECT : + MTP_PropertiesList.MTP_Properties[i].PropertyCode = MTP_OB_PROP_PARENT_OBJECT; + MTP_PropertiesList.MTP_Properties[i].Datatype = MTP_DATATYPE_UINT32; + parent_proval = hmtpif->GetParentObject(hmtp->OperationsContainer.Param1); + MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&parent_proval; + break; + + case MTP_OB_PROP_OBJECT_SIZE : + MTP_PropertiesList.MTP_Properties[i].PropertyCode = MTP_OB_PROP_OBJECT_SIZE; + MTP_PropertiesList.MTP_Properties[i].Datatype = MTP_DATATYPE_UINT64; + objsize = hmtpif->GetObjectSize(hmtp->OperationsContainer.Param1); + MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&objsize; + break; + + case MTP_OB_PROP_NAME : + MTP_PropertiesList.MTP_Properties[i].PropertyCode = MTP_OB_PROP_NAME; + MTP_PropertiesList.MTP_Properties[i].Datatype = MTP_DATATYPE_STR; + /* MTP_FileName.FileName_len value shall be set before USBD_MTP_FS_GetObjectName */ + MTP_FileName.FileName_len = hmtpif->GetObjectName_len(hmtp->OperationsContainer.Param1); + hmtpif->GetObjectName(hmtp->OperationsContainer.Param1, MTP_FileName.FileName_len, filename); + (void)USBD_memcpy(MTP_FileName.FileName, filename, ((uint32_t)MTP_FileName.FileName_len * 2U) + 1U ); + MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&MTP_FileName; + break; + + case MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN : + MTP_PropertiesList.MTP_Properties[i].PropertyCode = MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN; + MTP_PropertiesList.MTP_Properties[i].Datatype = MTP_DATATYPE_UINT128; + MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&hmtp->OperationsContainer.Param1; + break; + + case MTP_OB_PROP_PROTECTION_STATUS : + MTP_PropertiesList.MTP_Properties[i].PropertyCode = MTP_OB_PROP_PROTECTION_STATUS; + MTP_PropertiesList.MTP_Properties[i].Datatype = MTP_DATATYPE_UINT16; + MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&default_val; + break; + + default: + break; + } + + hmtp->ResponseLength = MTP_build_data_proplist(pdev, MTP_PropertiesList, i); + } +} + +/** + * @brief MTP_Get_DevicePropDesc + * Fill the MTP_DevicePropDesc struct + * @param pdev: device instance + * @retval None + */ +static void MTP_Get_DevicePropDesc(void) +{ + MTP_DevicePropDesc.DevicePropertyCode = MTP_DEV_PROP_DEVICE_FRIENDLY_NAME; + MTP_DevicePropDesc.DataType = MTP_DATATYPE_STR; + MTP_DevicePropDesc.GetSet = MTP_PROP_GET_SET; + MTP_DevicePropDesc.DefValue_len = DEVICE_PROP_DESC_DEF_LEN; + uint32_t i; + + for (i = 0U; i < (sizeof(DevicePropDefVal) / 2U); i++) + { + MTP_DevicePropDesc.DefValue[i] = DevicePropDefVal[i]; + } + + MTP_DevicePropDesc.curDefValue_len = DEVICE_PROP_DESC_CUR_LEN; + + for (i = 0U; i < (sizeof(DevicePropCurDefVal) / 2U); i++) + { + MTP_DevicePropDesc.curDefValue[i] = DevicePropCurDefVal[i]; + } + + MTP_DevicePropDesc.FormFlag = 0U; +} + +/** + * @brief MTP_Get_ObjectInfo + * Fill the MTP_ObjectInfo struct + * @param pdev: device instance + * @retval None + */ +static void MTP_Get_ObjectInfo(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData; + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + uint16_t filename[255]; + + MTP_ObjectInfo.Storage_id = MTP_STORAGE_ID; + MTP_ObjectInfo.ObjectFormat = hmtpif->GetObjectFormat(hmtp->OperationsContainer.Param1); + MTP_ObjectInfo.ObjectCompressedSize = hmtpif->GetObjectSize(hmtp->OperationsContainer.Param1); + MTP_ObjectInfo.ProtectionStatus = 0U; + MTP_ObjectInfo.ThumbFormat = MTP_OBJ_FORMAT_UNDEFINED; + MTP_ObjectInfo.ThumbCompressedSize = 0U; + MTP_ObjectInfo.ThumbPixWidth = 0U; /* not supported or not an image */ + MTP_ObjectInfo.ThumbPixHeight = 0U; + MTP_ObjectInfo.ImagePixWidth = 0U; + MTP_ObjectInfo.ImagePixHeight = 0U; + MTP_ObjectInfo.ImageBitDepth = 0U; + MTP_ObjectInfo.ParentObject = hmtpif->GetParentObject(hmtp->OperationsContainer.Param1); + MTP_ObjectInfo.AssociationType = 0U; + MTP_ObjectInfo.AssociationDesc = 0U; + MTP_ObjectInfo.SequenceNumber = 0U; + + /* we have to get this value before MTP_ObjectInfo.Filename */ + MTP_ObjectInfo.Filename_len = hmtpif->GetObjectName_len(hmtp->OperationsContainer.Param1); + hmtpif->GetObjectName(hmtp->OperationsContainer.Param1, MTP_ObjectInfo.Filename_len, filename); + (void)USBD_memcpy(MTP_ObjectInfo.Filename, filename, ((uint32_t)MTP_FileName.FileName_len * 2U) + 1U); + + MTP_ObjectInfo.CaptureDate = 0U; + MTP_ObjectInfo.ModificationDate = 0U; + MTP_ObjectInfo.Keywords = 0U; + hmtp->ResponseLength = MTP_build_data_ObjInfo(pdev, MTP_ObjectInfo); +} + +/** + * @brief MTP_Get_StorageIDS + * Fill the MTP_StorageIDS struct + * @param pdev: device instance + * @retval None + */ +static void MTP_Get_StorageIDS(void) +{ + MTP_StorageIDS.StorageIDS_len = MTP_NBR_STORAGE_ID; + MTP_StorageIDS.StorageIDS[0] = MTP_STORAGE_ID; +} + +/** + * @brief MTP_build_data_propdesc + * Copy the MTP_ObjectPropDesc dataset to the payload data + * @param pdev: device instance + * @retval None + */ +static uint32_t MTP_build_data_propdesc(USBD_HandleTypeDef *pdev, MTP_ObjectPropDescTypeDef def) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + uint8_t DefValue_size = (MTP_FileName.FileName_len * 2U) + 1U; + uint32_t dataLength = offsetof(MTP_ObjectPropDescTypeDef, DefValue); + + (void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&def, dataLength); + + switch (def.DataType) + { + case MTP_DATATYPE_UINT16: + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, def.DefValue, sizeof(uint16_t)); + dataLength += sizeof(uint16_t); + break; + + case MTP_DATATYPE_UINT32: + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, def.DefValue, sizeof(uint32_t)); + dataLength += sizeof(uint32_t); + break; + + case MTP_DATATYPE_UINT64: + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, def.DefValue, sizeof(uint64_t)); + dataLength += sizeof(uint64_t); + break; + + case MTP_DATATYPE_STR: + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, def.DefValue, DefValue_size); + dataLength += DefValue_size; + break; + + case MTP_DATATYPE_UINT128: + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, def.DefValue, (sizeof(uint64_t) * 2U)); + dataLength += (sizeof(uint64_t) * 2U); + break; + + default: + break; + } + + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, + (const uint8_t *)&MTP_ObjectPropDesc.GroupCode, sizeof(MTP_ObjectPropDesc.GroupCode)); + + dataLength += sizeof(MTP_ObjectPropDesc.GroupCode); + + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, + (const uint8_t *)&MTP_ObjectPropDesc.FormFlag, sizeof(MTP_ObjectPropDesc.FormFlag)); + + dataLength += sizeof(MTP_ObjectPropDesc.FormFlag); + + return dataLength; +} + +/** + * @brief MTP_build_data_proplist + * Copy the MTP_PropertiesList dataset to the payload data + * @param pdev: device instance + * @retval None + */ +static uint32_t MTP_build_data_proplist(USBD_HandleTypeDef *pdev, + MTP_PropertiesListTypedef proplist, uint32_t idx) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + uint8_t propval_size = (MTP_FileName.FileName_len * 2U) + 1U; + uint32_t dataLength; + + dataLength = offsetof(MTP_PropertiesTypedef, propval); + + (void)USBD_memcpy(hmtp->GenericContainer.data + hmtp->ResponseLength, + (const uint8_t *)&proplist.MTP_Properties[idx], dataLength); + + dataLength += hmtp->ResponseLength; + + switch (proplist.MTP_Properties[idx].Datatype) + { + case MTP_DATATYPE_UINT16: + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, + proplist.MTP_Properties[idx].propval, sizeof(uint16_t)); + + dataLength += sizeof(uint16_t); + break; + + case MTP_DATATYPE_UINT32: + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, + proplist.MTP_Properties[idx].propval, sizeof(uint32_t)); + + dataLength += sizeof(uint32_t); + break; + + case MTP_DATATYPE_STR: + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, + proplist.MTP_Properties[idx].propval, propval_size); + + dataLength += propval_size; + break; + + case MTP_DATATYPE_UINT64: + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, + proplist.MTP_Properties[idx].propval, sizeof(uint64_t)); + + dataLength += sizeof(uint64_t); + break; + + case MTP_DATATYPE_UINT128: + (void)USBD_memcpy(hmtp->GenericContainer.data + dataLength, + proplist.MTP_Properties[idx].propval, (sizeof(uint64_t) * 2U)); + + dataLength += (sizeof(uint64_t) * 2U); + break; + + default: + break; + } + + return dataLength; +} + +/** + * @brief MTP_build_data_ObjInfo + * Copy the MTP_ObjectInfo dataset to the payload data + * @param pdev: device instance + * @retval None + */ +static uint32_t MTP_build_data_ObjInfo(USBD_HandleTypeDef *pdev, MTP_ObjectInfoTypeDef objinfo) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + uint32_t ObjInfo_len = offsetof(MTP_ObjectInfoTypeDef, Filename); + + (void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&objinfo, ObjInfo_len); + (void)USBD_memcpy(hmtp->GenericContainer.data + ObjInfo_len, + (const uint8_t *)&objinfo.Filename, objinfo.Filename_len * sizeof(uint16_t)); + + ObjInfo_len = ObjInfo_len + (objinfo.Filename_len * sizeof(uint16_t)); + + (void)USBD_memcpy(hmtp->GenericContainer.data + ObjInfo_len, + (const uint8_t *)&objinfo.CaptureDate, sizeof(objinfo.CaptureDate)); + + ObjInfo_len = ObjInfo_len + sizeof(objinfo.CaptureDate); + + return ObjInfo_len; +} diff --git a/Class/MTP/Src/usbd_mtp_storage.c b/Class/MTP/Src/usbd_mtp_storage.c new file mode 100644 index 0000000..bfbcc32 --- /dev/null +++ b/Class/MTP/Src/usbd_mtp_storage.c @@ -0,0 +1,456 @@ +/** + ****************************************************************************** + * @file usbd_mtp_storage.c + * @author MCD Application Team + * @brief This file provides all the transfer command functions for MTP + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_mtp_storage.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static MTP_DataLengthTypeDef MTP_DataLength; +static MTP_READ_DATA_STATUS ReadDataStatus; + +/* Private function prototypes -----------------------------------------------*/ +static uint8_t USBD_MTP_STORAGE_DecodeOperations(USBD_HandleTypeDef *pdev); +static uint8_t USBD_MTP_STORAGE_ReceiveContainer(USBD_HandleTypeDef *pdev, uint32_t *pDst, uint32_t len); +static uint8_t USBD_MTP_STORAGE_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf, uint32_t len); + +/* Private functions ---------------------------------------------------------*/ +/** + * @} + */ + +/** + * @brief USBD_MTP_STORAGE_Init + * Initialize the MTP USB Layer + * @param pdev: device instance + * @retval status value + */ +uint8_t USBD_MTP_STORAGE_Init(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + /* Initialize the HW layyer of the file system */ + (void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Init(); + + /* Prepare EP to Receive First Operation */ + (void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, + hmtp->MaxPcktLen); + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_MTP_STORAGE_DeInit + * Uninitialize the MTP Machine + * @param pdev: device instance + * @retval status value + */ +uint8_t USBD_MTP_STORAGE_DeInit(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + /* DeInit physical Interface components */ + hmtp->MTP_SessionState = MTP_SESSION_NOT_OPENED; + + /* Stop low layer file system operations if any */ + USBD_MTP_STORAGE_Cancel(pdev, MTP_PHASE_IDLE); + + /* Free low layer file system resources */ + (void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->DeInit(); + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_MTP_STORAGE_ReadData + * Read data from device objects and send it to the host + * @param pdev: device instance + * @retval status value + */ +uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + uint32_t *data_buff; + + /* Get the data buffer pointer from the low layer interface */ + data_buff = ((USBD_MTP_ItfTypeDef *)pdev->pUserData)->ScratchBuff; + + switch (ReadDataStatus) + { + case READ_FIRST_DATA: + /* Reset the data length */ + MTP_DataLength.temp_length = 0U; + + /* Perform the low layer read operation on the scratch buffer */ + (void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->ReadData(hmtp->OperationsContainer.Param1, + (uint8_t *)data_buff, &MTP_DataLength); + + /* Add the container header to the data buffer */ + (void)USBD_memcpy((uint8_t *)data_buff, (uint8_t *)&hmtp->GenericContainer, MTP_CONT_HEADER_SIZE); + + /* Start USB data transmission to the host */ + (void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, + MTP_DataLength.readbytes + MTP_CONT_HEADER_SIZE); + + /* Check if this will be the last packet to send ? */ + if (MTP_DataLength.readbytes < ((uint32_t)hmtp->MaxPcktLen - MTP_CONT_HEADER_SIZE)) + { + /* Move to response phase */ + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + } + else + { + /* Continue to the next packets sending */ + ReadDataStatus = READ_REST_OF_DATA; + } + break; + + case READ_REST_OF_DATA: + /* Perform the low layer read operation on the scratch buffer */ + (void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->ReadData(hmtp->OperationsContainer.Param1, + (uint8_t *)data_buff, &MTP_DataLength); + + /* Check if more data need to be sent */ + if (MTP_DataLength.temp_length == MTP_DataLength.totallen) + { + /* Start USB data transmission to the host */ + (void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, MTP_DataLength.readbytes); + + /* Move to response phase */ + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + + /* Reset the stat machine */ + ReadDataStatus = READ_FIRST_DATA; + } + else + { + /* Start USB data transmission to the host */ + (void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, MTP_DataLength.readbytes); + + /* Keep the state machine into sending next packet of data */ + ReadDataStatus = READ_REST_OF_DATA; + } + break; + + default: + break; + } + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_MTP_STORAGE_SendContainer + * Send generic container to the host + * @param pdev: device instance + * @retval status value + */ +uint8_t USBD_MTP_STORAGE_SendContainer(USBD_HandleTypeDef *pdev, MTP_CONTAINER_TYPE CONT_TYPE) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + switch (CONT_TYPE) + { + case DATA_TYPE: + /* send header + data : hmtp->ResponseLength = header size + data size */ + (void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)&hmtp->GenericContainer, hmtp->ResponseLength); + break; + case REP_TYPE: + /* send header without data */ + hmtp->GenericContainer.code = (uint16_t)hmtp->ResponseCode; + hmtp->ResponseLength = MTP_CONT_HEADER_SIZE; + hmtp->GenericContainer.length = hmtp->ResponseLength; + hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE; + + (void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)&hmtp->GenericContainer, hmtp->ResponseLength); + break; + default: + break; + } + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_MTP_STORAGE_ReceiveOpt + * Data length Packet Received from host + * @param pdev: device instance + * @retval status value + */ +uint8_t USBD_MTP_STORAGE_ReceiveOpt(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + uint32_t *pMsgBuffer; + MTP_DataLength.rx_length = USBD_GetRxCount(pdev, MTP_OUT_EP); + switch (hmtp->RECEIVE_DATA_STATUS) + { + case RECEIVE_REST_OF_DATA: + /* we don't need to do anything here because we receive only data without operation header*/ + break; + + case RECEIVE_FIRST_DATA: + /* Expected Data Length Packet Received */ + pMsgBuffer = (uint32_t *) &hmtp->OperationsContainer; + + /* Fill hmtp->OperationsContainer Data Buffer from USB Buffer */ + (void)USBD_MTP_STORAGE_ReceiveContainer(pdev, pMsgBuffer, MTP_DataLength.rx_length); + break; + + default: + /* Expected Data Length Packet Received */ + pMsgBuffer = (uint32_t *) &hmtp->OperationsContainer; + + /* Fill hmtp->OperationsContainer Data Buffer from USB Buffer */ + (void)USBD_MTP_STORAGE_ReceiveContainer(pdev, pMsgBuffer, MTP_DataLength.rx_length); + (void)USBD_MTP_STORAGE_DecodeOperations(pdev); + break; + + } + return (uint8_t)USBD_OK; +} + + +/** + * @brief USBD_MTP_STORAGE_ReceiveData + * Receive objects or object info from host + * @param pdev: device instance + * @retval status value + */ +uint8_t USBD_MTP_STORAGE_ReceiveData(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + switch (hmtp->RECEIVE_DATA_STATUS) + { + case RECEIVE_COMMAND_DATA : + if (hmtp->OperationsContainer.type == MTP_CONT_TYPE_COMMAND) + { + MTP_DataLength.temp_length = 0; + MTP_DataLength.prv_len = 0; + (void)USBD_MTP_STORAGE_DecodeOperations(pdev); + + } + break; + + case RECEIVE_FIRST_DATA : + if (hmtp->OperationsContainer.type == MTP_CONT_TYPE_DATA) + { + MTP_DataLength.totallen = hmtp->OperationsContainer.length; + MTP_DataLength.temp_length = MTP_DataLength.rx_length; + MTP_DataLength.rx_length = MTP_DataLength.temp_length - MTP_CONT_HEADER_SIZE; + (void)USBD_MTP_STORAGE_DecodeOperations(pdev); + + if (MTP_DataLength.temp_length < hmtp->MaxPcktLen) /* we received all data, we don't need to go to next state */ + { + hmtp->RECEIVE_DATA_STATUS = SEND_RESPONSE; + (void)USBD_MTP_STORAGE_DecodeOperations(pdev); + + /* send response header after receiving all data successfully */ + (void)USBD_MTP_STORAGE_SendContainer(pdev, DATA_TYPE); + } + } + + break; + + case RECEIVE_REST_OF_DATA : + MTP_DataLength.prv_len = MTP_DataLength.temp_length - MTP_CONT_HEADER_SIZE; + (void)USBD_MTP_STORAGE_DecodeOperations(pdev); + MTP_DataLength.temp_length = MTP_DataLength.temp_length + MTP_DataLength.rx_length; + + if (MTP_DataLength.temp_length == MTP_DataLength.totallen) /* we received all data*/ + { + hmtp->RECEIVE_DATA_STATUS = SEND_RESPONSE; + (void)USBD_MTP_STORAGE_DecodeOperations(pdev); + + /* send response header after receiving all data successfully */ + (void)USBD_MTP_STORAGE_SendContainer(pdev, DATA_TYPE); + } + break; + + default : + break; + } + + return (uint8_t)USBD_OK; +} + + +/** + * @brief USBD_MTP_STORAGE_DecodeOperations + * Parse the operations and Process operations + * @param pdev: device instance + * @retval status value + */ +static uint8_t USBD_MTP_STORAGE_DecodeOperations(USBD_HandleTypeDef *pdev) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + switch (hmtp->OperationsContainer.code) + { + case MTP_OP_GET_DEVICE_INFO: + USBD_MTP_OPT_GetDeviceInfo(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_OPEN_SESSION: + USBD_MTP_OPT_CreateObjectHandle(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_GET_STORAGE_IDS: + USBD_MTP_OPT_GetStorageIDS(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_GET_STORAGE_INFO: + USBD_MTP_OPT_GetStorageInfo(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_GET_OBJECT_HANDLES: + USBD_MTP_OPT_GetObjectHandle(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_GET_OBJECT_INFO: + USBD_MTP_OPT_GetObjectInfo(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_GET_OBJECT_PROP_REFERENCES: + USBD_MTP_OPT_GetObjectReferences(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_GET_OBJECT_PROPS_SUPPORTED: + USBD_MTP_OPT_GetObjectPropSupp(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_GET_OBJECT_PROP_DESC: + USBD_MTP_OPT_GetObjectPropDesc(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_GET_OBJECT_PROPLIST: + USBD_MTP_OPT_GetObjectPropList(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_GET_OBJECT_PROP_VALUE: + USBD_MTP_OPT_GetObjectPropValue(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_GET_DEVICE_PROP_DESC: + USBD_MTP_OPT_GetDevicePropDesc(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + case MTP_OP_GET_OBJECT: + USBD_MTP_OPT_GetObject(pdev); + hmtp->MTP_ResponsePhase = MTP_READ_DATA; + break; + + case MTP_OP_SEND_OBJECT_INFO: + USBD_MTP_OPT_SendObjectInfo(pdev, (uint8_t *)(hmtp->rx_buff), MTP_DataLength.prv_len); + hmtp->MTP_ResponsePhase = MTP_RECEIVE_DATA; + break; + + case MTP_OP_SEND_OBJECT: + USBD_MTP_OPT_SendObject(pdev, (uint8_t *)(hmtp->rx_buff), MTP_DataLength.rx_length); + hmtp->MTP_ResponsePhase = MTP_RECEIVE_DATA; + break; + + case MTP_OP_DELETE_OBJECT: + USBD_MTP_OPT_DeleteObject(pdev); + hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE; + break; + + default: + break; + } + + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_MTP_STORAGE_ReceiveContainer + * Receive the Data from USB BulkOut Buffer to Pointer + * @param pdev: device instance + * @param pDst: destination address to copy the buffer + * @param len: length of data to copy + * @retval status value + */ +static uint8_t USBD_MTP_STORAGE_ReceiveContainer(USBD_HandleTypeDef *pdev, + uint32_t *pDst, uint32_t len) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + uint32_t Counter; + uint32_t *pdst = pDst; + + for (Counter = 0; Counter < len; Counter++) + { + *pdst = (hmtp->rx_buff[Counter]); + pdst++; + } + return (uint8_t)USBD_OK; +} + +/** + * @brief USBD_MTP_STORAGE_Cancel + * Reinitialize all states and cancel transfer through Bulk transfer + * @param pdev: device instance + * @param MTP_ResponsePhase: MTP current state + * @retval None + */ +void USBD_MTP_STORAGE_Cancel(USBD_HandleTypeDef *pdev, + MTP_ResponsePhaseTypeDef MTP_ResponsePhase) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + + hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE; + ReadDataStatus = READ_FIRST_DATA; + hmtp->RECEIVE_DATA_STATUS = RECEIVE_IDLE_STATE; + + if (MTP_ResponsePhase == MTP_RECEIVE_DATA) + { + ((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Cancel(1U); + } + else + { + ((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Cancel(0U); + } +} + +/** + * @brief USBD_MTP_STORAGE_SendData + * Send the data on bulk-in EP + * @param pdev: device instance + * @param buf: pointer to data buffer + * @param len: Data Length + * @retval status value + */ +static uint8_t USBD_MTP_STORAGE_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf, + uint32_t len) +{ + USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData; + uint32_t length = MIN(hmtp->GenericContainer.length, len); + + (void)USBD_LL_Transmit(pdev, MTP_IN_EP, buf, length); + + return (uint8_t)USBD_OK; +} diff --git a/Class/Printer/Inc/usbd_printer.h b/Class/Printer/Inc/usbd_printer.h index ec73edc..b93cda7 100644 --- a/Class/Printer/Inc/usbd_printer.h +++ b/Class/Printer/Inc/usbd_printer.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -161,4 +160,3 @@ uint8_t USBD_PRNT_ReceivePacket(USBD_HandleTypeDef *pdev); * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/Printer/Inc/usbd_printer_if_template.h b/Class/Printer/Inc/usbd_printer_if_template.h index 7037afa..7765eed 100644 --- a/Class/Printer/Inc/usbd_printer_if_template.h +++ b/Class/Printer/Inc/usbd_printer_if_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * http://www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -42,4 +41,3 @@ extern USBD_PRNT_ItfTypeDef USBD_PRNT_Template_fops; #endif /* __USBD_PRNT_IF_TEMPLATE_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/Printer/Src/usbd_printer.c b/Class/Printer/Src/usbd_printer.c index 246674f..25a7433 100644 --- a/Class/Printer/Src/usbd_printer.c +++ b/Class/Printer/Src/usbd_printer.c @@ -10,6 +10,17 @@ * - Command OUT transfer (class requests management) * - Error management * + ****************************************************************************** + * @attention + * + * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** * @verbatim * * =================================================================== @@ -37,17 +48,6 @@ * @endverbatim * ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** */ /* BSPDependencies @@ -669,5 +669,3 @@ uint8_t USBD_PRNT_ReceivePacket(USBD_HandleTypeDef *pdev) /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/Printer/Src/usbd_printer_if_template.c b/Class/Printer/Src/usbd_printer_if_template.c index 064c41e..8b63db0 100644 --- a/Class/Printer/Src/usbd_printer_if_template.c +++ b/Class/Printer/Src/usbd_printer_if_template.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2021 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * http://www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -71,11 +70,11 @@ USBD_PRNT_ItfTypeDef USBD_PRNT_Template_fops = { TEMPLATE_Init, TEMPLATE_DeInit, - TEMPLATE_Control_req + TEMPLATE_Control_req, TEMPLATE_Receive }; -static uint8_t PRNT_DEVICE_ID[DEVICE_ID_LEN] = +static uint8_t PRNT_DEVICE_ID[] = { 0x00, 0x6D, 'M', 'A', 'N', 'U', 'F', 'A', 'C', 'T', 'U', 'R', 'E', 'R', ':', @@ -128,7 +127,7 @@ static int8_t TEMPLATE_DeInit(void) * * @note * This function will issue a NAK packet on any OUT packet received on - * USB endpoint untill exiting this function. If you exit this function + * USB endpoint until exiting this function. If you exit this function * before transfer is complete on PRNT interface (ie. using DMA controller) * it will result in receiving more data while previous ones are still * not sent. @@ -147,16 +146,16 @@ static int8_t TEMPLATE_Receive(uint8_t *Buf, uint32_t *Len) /** - * @brief TEMPLATE_PRNT_Itf_Control_req + * @brief TEMPLATE_Control_req * Manage the PRNT class requests * @param req: Command code * @param pbuf: Buffer containing command data (request parameters) * @param length: Number of data to be sent (in bytes) * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ -static int8_t TEMPLATE_PRNT_Itf_Control_req(uint8_t req, uint8_t *pbuf, uint16_t *length) +static int8_t TEMPLATE_Control_req(uint8_t req, uint8_t *pbuf, uint16_t *length) { - uint32_t i = 0; + uint32_t i = 0U; /* Check on the setup request value */ switch (req) @@ -169,7 +168,7 @@ static int8_t TEMPLATE_PRNT_Itf_Control_req(uint8_t req, uint8_t *pbuf, uint16_t pbuf[i] = PRNT_DEVICE_ID[i]; i++; } - *length = i; + *length = (uint16_t)i; break; /* Get Printer current status */ @@ -183,25 +182,16 @@ static int8_t TEMPLATE_PRNT_Itf_Control_req(uint8_t req, uint8_t *pbuf, uint16_t /* Printer SOFT RESET request: cleanup pending tasks */ case PRNT_SOFT_RESET: - (void)f_close(&hSD.MyFile); break; default: - /* Unkown commands are not managed */ + /* Unknown commands are not managed */ break; + } + + return (0); } -/** -* @brief TEMPLATE_PRNT_PageEndManager, defined by user -* Call this function frequently to check if data is received. -* @param Buf: Buffer of data to be received -* @param Len: Number of data received (in bytes) -*/ -void TEMPLATE_PRNT_PageEndManager(uint8_t *Buf, uint32_t Len) -{ - UNUSED(Buf); - UNUSED(Len); -} /** * @} */ @@ -214,5 +204,3 @@ void TEMPLATE_PRNT_PageEndManager(uint8_t *Buf, uint32_t Len) * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/Class/Template/Inc/usbd_template.h b/Class/Template/Inc/usbd_template.h index 8e9163b..be31437 100644 --- a/Class/Template/Inc/usbd_template.h +++ b/Class/Template/Inc/usbd_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -97,5 +96,3 @@ extern USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver; /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/Template/Src/usbd_template.c b/Class/Template/Src/usbd_template.c index 10ced3f..4075334 100644 --- a/Class/Template/Src/usbd_template.c +++ b/Class/Template/Src/usbd_template.c @@ -4,6 +4,17 @@ * @author MCD Application Team * @brief This file provides the HID core functions. * + ****************************************************************************** + * @attention + * + * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** * @verbatim * * =================================================================== @@ -22,17 +33,6 @@ * @endverbatim * ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ @@ -376,5 +376,3 @@ uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length) /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Class/VIDEO/Inc/usbd_video.h b/Class/VIDEO/Inc/usbd_video.h index c92ff76..64826ff 100644 --- a/Class/VIDEO/Inc/usbd_video.h +++ b/Class/VIDEO/Inc/usbd_video.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2020 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -413,7 +412,6 @@ typedef struct int8_t (* DeInit)(void); int8_t (* Control)(uint8_t, uint8_t *, uint16_t); int8_t (* Data)(uint8_t **, uint16_t *, uint16_t *); - uint8_t *pStrDesc; } USBD_VIDEO_ItfTypeDef; /* UVC uses only 26 first bytes */ diff --git a/Class/VIDEO/Inc/usbd_video_if_template.h b/Class/VIDEO/Inc/usbd_video_if_template.h index 036c7aa..bc5b8fa 100644 --- a/Class/VIDEO/Inc/usbd_video_if_template.h +++ b/Class/VIDEO/Inc/usbd_video_if_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2020 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -114,6 +113,25 @@ void TransferComplete_CallBack_FS(void); */ void HalfTransfer_CallBack_FS(void); + + +#define IMG_NBR 1U +#define IMAGE_SIZE 0x1U + +const uint8_t image[] = {0x00}; +const uint8_t *tImagesList[] = {image}; +uint16_t tImagesSizes[] = {IMAGE_SIZE}; + +/* Time laps between video frames in ms. + Please adjust this value depending on required speed. + Please note that this define uses the system HAL_Delay() which uses the systick. + In case of changes on HAL_Delay, please ensure the values in ms correspond. */ +#ifdef USE_USB_HS +#define USBD_VIDEO_IMAGE_LAPS 160U +#else +#define USBD_VIDEO_IMAGE_LAPS 80U +#endif /* USE_USB_HS */ + /* USER CODE BEGIN EXPORTED_FUNCTIONS */ /* USER CODE END EXPORTED_FUNCTIONS */ @@ -136,7 +154,3 @@ void HalfTransfer_CallBack_FS(void); #endif /* USBD_VIDEO_IF_H_ */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - - - diff --git a/Class/VIDEO/Src/usbd_video.c b/Class/VIDEO/Src/usbd_video.c index a414ed6..6a782ef 100644 --- a/Class/VIDEO/Src/usbd_video.c +++ b/Class/VIDEO/Src/usbd_video.c @@ -4,6 +4,17 @@ * @author MCD Application Team * @brief This file provides the Video core functions. * + ****************************************************************************** + * @attention + * + * Copyright (c) 2020 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** * @verbatim * * =================================================================== @@ -35,17 +46,6 @@ * @endverbatim * ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ @@ -757,7 +757,7 @@ static void VIDEO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef /* Probe Request */ (void)USBD_CtlSendData(pdev, (uint8_t *)&video_Probe_Control, - MIN(req->wLength, sizeof(USBD_VideoControlTypeDef))); + MIN(req->wLength, sizeof(USBD_VideoControlTypeDef))); } else if (LOBYTE(req->wValue) == (uint8_t)VS_COMMIT_CONTROL) { @@ -774,7 +774,7 @@ static void VIDEO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef /* Commit Request */ (void)USBD_CtlSendData(pdev, (uint8_t *)&video_Commit_Control, - MIN(req->wLength, sizeof(USBD_VideoControlTypeDef))); + MIN(req->wLength, sizeof(USBD_VideoControlTypeDef))); } else { @@ -957,7 +957,7 @@ static void *USBD_VIDEO_GetVSFrameDesc(uint8_t *pConfDesc) pdesc = USBD_VIDEO_GetNextDesc((uint8_t *)pdesc, &ptr); if (((pdesc->bDescriptorSubType == VS_FRAME_MJPEG) || - (pdesc->bDescriptorSubType == VS_FRAME_UNCOMPRESSED)) && + (pdesc->bDescriptorSubType == VS_FRAME_UNCOMPRESSED)) && (pdesc->bLength == VS_FRAME_DESC_SIZE)) { pVSFrameDesc = (USBD_VIDEO_VSFrameDescTypeDef *)(void *)pdesc; @@ -1045,7 +1045,3 @@ uint8_t USBD_VIDEO_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_VIDEO_ItfT /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - - diff --git a/Class/VIDEO/Src/usbd_video_if_template.c b/Class/VIDEO/Src/usbd_video_if_template.c index 70b8d3a..297beb6 100644 --- a/Class/VIDEO/Src/usbd_video_if_template.c +++ b/Class/VIDEO/Src/usbd_video_if_template.c @@ -6,19 +6,18 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2020 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ -#include "usbd_video_if.h" +#include "usbd_video_if_template.h" /* Include you image binary file here Binary image template shall provide: @@ -41,7 +40,7 @@ /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ - +uint8_t img_count; /* USER CODE END PV */ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY @@ -189,6 +188,9 @@ static int8_t VIDEO_Itf_DeInit(void) */ static int8_t VIDEO_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length) { + UNUSED(cmd); + UNUSED(pbuf); + UNUSED(length); return (0); } @@ -221,9 +223,9 @@ static int8_t VIDEO_Itf_Data(uint8_t **pbuf, uint16_t *psize, uint16_t *pcktidx) */ const uint8_t *(*ImagePtr) = tImagesList; - uint32_t packet_count = (tImagesSizes[img_count]) / ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U))); - uint32_t packet_remainder = (tImagesSizes[img_count]) % ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U))); - static uint8_t packet_index = 0; + uint32_t packet_count = (tImagesSizes[img_count]) / ((UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U))); + uint32_t packet_remainder = (tImagesSizes[img_count]) % ((UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U))); + static uint8_t packet_index = 0U; /* Check if end of current image has been reached */ if (packet_index < packet_count) @@ -232,17 +234,17 @@ static int8_t VIDEO_Itf_Data(uint8_t **pbuf, uint16_t *psize, uint16_t *pcktidx) *psize = (uint16_t)UVC_PACKET_SIZE; /* Get the pointer to the next packet to be transmitted */ - *pbuf = (uint8_t *)(*(ImagePtr + img_count) + packet_index * ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U)))); + *pbuf = (uint8_t *)(*(ImagePtr + img_count) + (packet_index * ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U))))); } else if ((packet_index == packet_count)) { if (packet_remainder != 0U) { /* Get the pointer to the next packet to be transmitted */ - *pbuf = (uint8_t *)(*(ImagePtr + img_count) + packet_index * ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U)))); + *pbuf = (uint8_t *)(*(ImagePtr + img_count) + (packet_index * ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U))))); /* Set the current packet size */ - *psize = packet_remainder + (UVC_HEADER_PACKET_CNT * 2U); + *psize = (uint16_t)(packet_remainder + (UVC_HEADER_PACKET_CNT * 2U)); } else { @@ -262,7 +264,7 @@ static int8_t VIDEO_Itf_Data(uint8_t **pbuf, uint16_t *psize, uint16_t *pcktidx) *pcktidx = packet_index; /* Increment the packet count and check if it reached the end of current image buffer */ - if (packet_index++ >= (packet_count + 1)) + if (packet_index++ >= (packet_count + 1U)) { /* Reset the packet count to zero */ packet_index = 0U; @@ -270,7 +272,7 @@ static int8_t VIDEO_Itf_Data(uint8_t **pbuf, uint16_t *psize, uint16_t *pcktidx) /* Move to the next image in the images table */ img_count++; - HAL_Delay(USBD_VIDEO_IMAGE_LAPS); + USBD_Delay(USBD_VIDEO_IMAGE_LAPS); /* Check if images count has been reached, then reset to zero (go back to first image in circular loop) */ if (img_count == IMG_NBR) { @@ -292,5 +294,3 @@ static int8_t VIDEO_Itf_Data(uint8_t **pbuf, uint16_t *psize, uint16_t *pcktidx) /** * @} */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Core/Inc/usbd_conf_template.h b/Core/Inc/usbd_conf_template.h index 0527cf2..b502071 100644 --- a/Core/Inc/usbd_conf_template.h +++ b/Core/Inc/usbd_conf_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -221,4 +220,3 @@ void USBD_static_free(void *p); /** * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Core/Inc/usbd_core.h b/Core/Inc/usbd_core.h index 92f7270..360561d 100644 --- a/Core/Inc/usbd_core.h +++ b/Core/Inc/usbd_core.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -152,7 +151,4 @@ void USBD_LL_Delay(uint32_t Delay); * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - - diff --git a/Core/Inc/usbd_ctlreq.h b/Core/Inc/usbd_ctlreq.h index 3495a97..6c45d6c 100644 --- a/Core/Inc/usbd_ctlreq.h +++ b/Core/Inc/usbd_ctlreq.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -100,4 +99,3 @@ void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Core/Inc/usbd_def.h b/Core/Inc/usbd_def.h index 4c4de68..53f831d 100644 --- a/Core/Inc/usbd_def.h +++ b/Core/Inc/usbd_def.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -206,7 +205,7 @@ typedef struct uint8_t bmAttributes; uint16_t wMaxPacketSize; uint8_t bInterval; -} USBD_EpDescTypedef; +} __PACKED USBD_EpDescTypedef; struct _USBD_HandleTypeDef; @@ -417,4 +416,4 @@ __STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr) /** * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/Core/Inc/usbd_desc_template.h b/Core/Inc/usbd_desc_template.h index 8fbbfaa..0e5e3d6 100644 --- a/Core/Inc/usbd_desc_template.h +++ b/Core/Inc/usbd_desc_template.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -60,4 +59,3 @@ extern USBD_DescriptorsTypeDef XXX_Desc; /* Replace 'XXX_Desc' with your active #endif /* __USBD_DESC_TEMPLATE_H*/ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Core/Inc/usbd_ioreq.h b/Core/Inc/usbd_ioreq.h index c896b5a..15197b9 100644 --- a/Core/Inc/usbd_ioreq.h +++ b/Core/Inc/usbd_ioreq.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -111,4 +110,4 @@ uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr); /** * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/Core/Src/usbd_conf_template.c b/Core/Src/usbd_conf_template.c index 381988b..3cd06f1 100644 --- a/Core/Src/usbd_conf_template.c +++ b/Core/Src/usbd_conf_template.c @@ -8,13 +8,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -264,5 +263,4 @@ void USBD_LL_Delay(uint32_t Delay) { UNUSED(Delay); } -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Core/Src/usbd_core.c b/Core/Src/usbd_core.c index fcca9af..772a819 100644 --- a/Core/Src/usbd_core.c +++ b/Core/Src/usbd_core.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -690,5 +689,3 @@ USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev) * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/Core/Src/usbd_ctlreq.c b/Core/Src/usbd_ctlreq.c index b709854..8054d27 100644 --- a/Core/Src/usbd_ctlreq.c +++ b/Core/Src/usbd_ctlreq.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -945,4 +944,3 @@ static uint8_t USBD_GetLen(uint8_t *buf) * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Core/Src/usbd_desc_template.c b/Core/Src/usbd_desc_template.c index 8558ebd..94564be 100644 --- a/Core/Src/usbd_desc_template.c +++ b/Core/Src/usbd_desc_template.c @@ -8,13 +8,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -28,7 +27,7 @@ /* Private define ------------------------------------------------------------*/ #define USBD_VID 0x0483 #define USBD_PID 0xaaaa /* Replace '0xaaaa' with your device product ID */ -#define USBD_LANGID_STRING 0xbbb /* Replace '0xbbb' with your device language ID */ +#define USBD_LANGID_STRING 0xbbb /* Replace '0xbbb' with your device language ID */ #define USBD_MANUFACTURER_STRING "xxxxx" /* Add your manufacturer string */ #define USBD_PRODUCT_HS_STRING "xxxxx" /* Add your product High Speed string */ #define USBD_PRODUCT_FS_STRING "xxxxx" /* Add your product Full Speed string */ @@ -184,8 +183,8 @@ __ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END = 0x00, /* bAlternateMode[0] Index of the Alternate Mode within the SVID as returned in response to a Discover Modes command. Example: - 0 – first Mode entry - 1 – second mode entry */ + 0 first Mode entry + 1 second mode entry */ USBD_BB_ALTMODE0_STRING_INDEX, /* iAlternateModeString[0]: Index of string descriptor describing protocol. It is optional to support this string. */ @@ -195,10 +194,10 @@ __ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END = 0x01, /* bAlternateMode[1] Index of the Alternate Mode within the SVID as returned in response to a Discover Modes command. Example: - 0 – first Mode entry - 1 – second Mode entry */ + 0 first Mode entry + 1 second Mode entry */ - USBD_BB_ALTMODE1_STRING_INDEX, /* iAlternateModeString[1]: Index of string descriptor describing protocol. + USBD_BB_ALTMODE1_STRING_INDEX, /* iAlternateModeString[1]: Index of string descriptor describing protocol. It is optional to support this string. */ /* Alternate Mode Desc */ /* ----------- Device Capability Descriptor: BillBoard Alternate Mode Desc ---------- */ @@ -447,5 +446,3 @@ static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len) pbuf[2U * idx + 1] = 0U; } } - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Core/Src/usbd_ioreq.c b/Core/Src/usbd_ioreq.c index 1e7e62d..c4021ec 100644 --- a/Core/Src/usbd_ioreq.c +++ b/Core/Src/usbd_ioreq.c @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

+ * Copyright (c) 2015 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -223,4 +222,3 @@ uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr) * @} */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..e66295c --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,86 @@ +This software component is provided to you as part of a software package and +applicable license terms are in the Package_license file. If you received this +software component outside of a package or without applicable license terms, +the terms of the SLA0044 license shall apply and are fully reproduced below: + +SLA0044 Rev5/February 2018 + +Software license agreement + +ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT + +BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE +OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS +INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES +(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON +BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES +TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT. + +Under STMicroelectronics’ intellectual property rights, the redistribution, +reproduction and use in source and binary forms of the software or any part +thereof, with or without modification, are permitted provided that the following +conditions are met: + +1. Redistribution of source code (modified or not) must retain any copyright +notice, this list of conditions and the disclaimer set forth below as items 10 +and 11. + +2. Redistributions in binary form, except as embedded into microcontroller or +microprocessor device manufactured by or for STMicroelectronics or a software +update for such device, must reproduce any copyright notice provided with the +binary code, this list of conditions, and the disclaimer set forth below as +items 10 and 11, in documentation and/or other materials provided with the +distribution. + +3. Neither the name of STMicroelectronics nor the names of other contributors to +this software may be used to endorse or promote products derived from this +software or part thereof without specific written permission. + +4. This software or any part thereof, including modifications and/or derivative +works of this software, must be used and execute solely and exclusively on or in +combination with a microcontroller or microprocessor device manufactured by or +for STMicroelectronics. + +5. No use, reproduction or redistribution of this software partially or totally +may be done in any manner that would subject this software to any Open Source +Terms. “Open Source Terms†shall mean any open source license which requires as +part of distribution of software that the source code of such software is +distributed therewith or otherwise made available, or open source license that +substantially complies with the Open Source definition specified at +www.opensource.org and any other comparable open source license such as for +example GNU General Public License (GPL), Eclipse Public License (EPL), Apache +Software License, BSD license or MIT license. + +6. STMicroelectronics has no obligation to provide any maintenance, support or +updates for the software. + +7. The software is and will remain the exclusive property of STMicroelectronics +and its licensors. The recipient will not take any action that jeopardizes +STMicroelectronics and its licensors' proprietary rights or acquire any rights +in the software, except the limited rights specified hereunder. + +8. The recipient shall comply with all applicable laws and regulations affecting +the use of the software or any part thereof including any applicable export +control law or regulation. + +9. Redistribution and use of this software or any part thereof other than as +permitted under this license is void and will automatically terminate your +rights under this license. + +10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE +DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL +STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER +EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY +RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY. + diff --git a/License.md b/License.md index c2c31dd..1af5233 100644 --- a/License.md +++ b/License.md @@ -1,3 +1,80 @@ -# Copyright (c) 2015 STMicroelectronics. +SLA0044 Rev5/February 2018 -This software component is licensed by ST under Ultimate Liberty license SLA0044, the "License". You may not use this file except in compliance with this license. You may obtain a copy of the license [here](https://www.st.com/SLA0044). +## Software license agreement + +### __ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT__ + +BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE +OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS +INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES +(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON +BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES +TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT. + +Under STMicroelectronics’ intellectual property rights, the redistribution, +reproduction and use in source and binary forms of the software or any part +thereof, with or without modification, are permitted provided that the following +conditions are met: + +1. Redistribution of source code (modified or not) must retain any copyright +notice, this list of conditions and the disclaimer set forth below as items 10 +and 11. + +2. Redistributions in binary form, except as embedded into microcontroller or +microprocessor device manufactured by or for STMicroelectronics or a software +update for such device, must reproduce any copyright notice provided with the +binary code, this list of conditions, and the disclaimer set forth below as +items 10 and 11, in documentation and/or other materials provided with the +distribution. + +3. Neither the name of STMicroelectronics nor the names of other contributors to +this software may be used to endorse or promote products derived from this +software or part thereof without specific written permission. + +4. This software or any part thereof, including modifications and/or derivative +works of this software, must be used and execute solely and exclusively on or in +combination with a microcontroller or microprocessor device manufactured by or +for STMicroelectronics. + +5. No use, reproduction or redistribution of this software partially or totally +may be done in any manner that would subject this software to any Open Source +Terms. “Open Source Terms†shall mean any open source license which requires as +part of distribution of software that the source code of such software is +distributed therewith or otherwise made available, or open source license that +substantially complies with the Open Source definition specified at +www.opensource.org and any other comparable open source license such as for +example GNU General Public License (GPL), Eclipse Public License (EPL), Apache +Software License, BSD license or MIT license. + +6. STMicroelectronics has no obligation to provide any maintenance, support or +updates for the software. + +7. The software is and will remain the exclusive property of STMicroelectronics +and its licensors. The recipient will not take any action that jeopardizes +STMicroelectronics and its licensors' proprietary rights or acquire any rights +in the software, except the limited rights specified hereunder. + +8. The recipient shall comply with all applicable laws and regulations affecting +the use of the software or any part thereof including any applicable export +control law or regulation. + +9. Redistribution and use of this software or any part thereof other than as +permitted under this license is void and will automatically terminate your +rights under this license. + +10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE +DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL +STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER +EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY +RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY. diff --git a/Release_Notes.html b/Release_Notes.html index cf3544b..bda657f 100644 --- a/Release_Notes.html +++ b/Release_Notes.html @@ -1,1517 +1,1477 @@ - - - - - - - - - - - - - - - - - - - - -Release Notes for STM32 USB Device Library - - - - - - - - - -
- -

 

- -
- - - - - -
- - - - - - - -
-

Back to Release page

-
-

Release Notes for STM32 USB Device Library

-

Copyright - 2015 STMicroelectronics

-

-
-

 

- - - - -
-

Update History

- -

V2.8.0 / 10-Mars-2021

Main -Changes

  • Integration of  new USB device Class driver:
    • USB Printer Class driver based on Universal Serial Bus -Device Class Definition -for -Printing Devices Version 1.1
  • USB All Classes:
    • Fix USB buffer overflow vulnerability for CDC, CDC-ECM, CDC-RNDIS, DFU, AUDIO, CustomHID, and Video Classes
    • fix compilation warning with C++ due to missing casting during class handler allocation
    • Enhance comments of USB configuration descriptors fields
  • USB Video Class:
    • fix missing closing bracket for extern "C" in usbd_video.h
    • fix USBCV test with Uncompressed video format support

V2.7.1 / 18-August-2020

-

Main -Changes

-
    -
  • USB All Class:
  • -
      -
    • Add NULL pointer access check to Class handler
      -
    • -
    -
- -

V2.7.0 / 12-August-2020

-

Main -Changes

  • Integration of  new USB device Class driver:
    • USB video Class driver based on USB-IF video class definition version 1.1
- - - - - - - - - - - - - - - - - - - - - - - -
  • USB Core:
    • Enhance NULL pointer check in Core APIs
    • Allow supporting both USER and USER Class string desc
    • Add support of USB controller which handles packet-size splitting by hardware
    • Avoid compilation warning due macro redefinition
    • change -added to USBD_HandleTypeDef structure: dev_state, old_dev_state and -ep0_state declaration become volatile to disable compiler optimization
    • Word spelling correction and file indentation improved
    • usbd_conf.h/c Template file updated to suggest using by default a static memory allocation for Class handler
  • USB All Classes
    • Word spelling correction and file indentation improved
    • Allow updating device config descriptor Max power from user code usbd_conf.h using USBD_MAX_POWER define
    • Fix device config descriptor bmAttributes value which depends on user code define USBD_SELF_POWERED
  • USB CDC Class:
    • Class specific request, add protection to limit the maximum data length to be sent by the CDC device
  • USB CustomHID Class:
    • Allow changing CustomHID data EP size from user code
-

V2.6.1 / 05-June-2020

- - - -

Main -Changes

- - - - - - - - - - - - - - - - - - - - - - - -
    -
  • USB Core:
  • -
      -
    • minor rework on USBD_Init() USBD_DeInit()
    • -
    • Fix warning issue with Keil due to missing return value of setup API
      -
    • -
    -
  • USB CDC Class:
  • -
      -
    • Fix file indentation
    • -
    • Avoid accessing to NULL pointer in case -TransmitCplt() user fops is not defined to allow application -compatibility with device library version below v2.6.0
      -
    • -
    -
-
-
    -
  • Fix minor misra-c 2012 violations
  • -
-

V2.6.0 / 27-December-2019

-

Main -Changes

- - - - - - - - - - - - - - - - - - - - - -
  • Integration of three new USB device Class drivers:
    • USB CDC ECM Class driver
    • USB CDC RNDIS Microsoft Class driver
    • USB Billboard Class driver
  • Fix mandatory misra-c 2012 violations
  • update user core and class template files
  • USB Core:
    • Fix unexpected EP0 stall during enumeration phase 
    • Improve APIs error management and prevent accessing NULL pointers
  • USB MSC Class:
    • Fix USBCV specific class tests
    • Fix multiple error with SCSI commands handling
    • Protect medium access when host ask for medium ejection
  • USB CDC Class:
    • Add new function to inform user that current IN transfer is completed
    • update transmit and receive APIs to transfer up to 64KB
  • USB AUDIO Class:
    • Fix audio sync start buffer size
    • update user callback periodicTC args by adding pointer to user buffer and size
  • USB CustomHID Class:
    • Rework the OUT transfer complete and prevent automatically re-enabling the OUT EP 
    • Add new user API to restart the OUT transfer: USBD_CUSTOM_HID_ReceivePacket()

V2.5.3 / 30-April-2019

Main -Changes

- - - - - - - - - - - - - - - - - - - - - -
  • Fix misra-c 2012 high severity violations
  • Core driver:
    • protect shared macros __ALIGN_BEGIN, __ALIGN_END with C directive #ifndef
    • update Core driver and DFU Class driver to use USBD_SUPPORT_USER_STRING_DESC instead of  USBD_SUPPORT_USER_STRING
    •  prevent accessing to NULL pointer if the get descriptor functions are not defined
    • Update on USBD_LL_Resume(),  restore the device state only if the current state is USBD_STATE_SUSPENDED

V2.5.2 / 27-Mars-2019

Main -Changes

- - - - - - - - - - - - - - - - - - - - - -
  • DFU Class:
    • fix compilation warning due to unreachable - instruction code introduced with CMSIS V5.4.0 NVIC_SystemReset() prototype change

V2.5.1 / 03-August-2018
-

- - - - - - - - - - - - - - - - - -

Main -Changes

- - - - - - - - - - - - - - - - - - - - - -
  • Update license section by adding path to get copy of ST Ultimate Liberty license
  • Core: Fix unexpected stall during status OUT phase
  • DFU Class:
    • rework hdfu struct to prevent unaligned addresses
  • MSC Class:
    • fix lba address overflow during large file transfers > 4Go
  • Template Class:
    • add missing Switch case Break on USBD_Template_Setup API

V2.5.0 / 15-December-2017
-

- - - - - - - - - - - - - - - - - -

Main -Changes

- - - - - - - - - - - - - - - - - - - - - -
  • Update license section
  • Update some functions to be MISRAC 2004 compliant
  • Add HS and OtherSpeed configuration descriptor for HID and CustomHID classes
  • Correct error handling in all class setup function
  • Add usbd_desc_template.c/ usbd_desc_template.h templates files
  • Add support of class and vendor request
  • CDC Class: fix zero-length packet issue in bulk IN transfer
  • Fix compilation warning with unused arguments for some functions
  • Improve USB Core enumeration state machine

V2.4.2 / 11-December-2015
-

- - - - - - - - - - - - - - - - - -

Main -Changes

- - - - - - - - - - - - - - - - - - - - - -
    -
  • CDC Class
    • usbd_cdc.c: change #include "USBD_CDC.h" by #include "usbd_cdc.h"
    -
-
- -

V2.4.1 / 19-June-2015
-

- - - - - - - - - - - - - - - -

Main -Changes

- - - - - - - - - - - - - - - - - - - -
    -
  • CDC Class
  • -
      -
    • usbd_cdc.c: comments update
    • -
    -
  • MSC Class
  • -
      -
    • usbd_msc_bot.h: update to be C++ compliant
    • -
    -
  • AUDIO Class
  • -
      -
    • usbd_audio.c: fix issue when Host sends GetInterface command it gets a wrong value
    • -
    -
      -
    • usbd_audio.c: remove useless management of DMA half transfer
      -
    • -
    -
- - - -

V2.4.0 / 28-February-2015
-

- - - - - - - - - - - - - -

Main -Changes

- - - - - - - - - - - - - - - - - -
    -
  • Core Driver
  • -
      -
    • Add support of Link Power Management (LPM): add new API GetBOSDescriptor(), that is used only if USBD_LPM_ENABLED switch is enabled in usbd_conf.h file
    • usbd_core.c: -Fix bug of unsupported premature Host Out stage during data In stage -(ie. when endpoint 0 maximum data size is 8 and Host requests -GetDeviceDescriptor for the first time)
    • usbd_ctlreq.c: Fix bug of unsupported Endpoint Class requests (ie. Audio SetCurrent request for endpoint sampling rate setting)
    • -
    -
  • HID Class
  • -
      -
    • Updating Polling time API USBD_HID_GetPollingInterval() to query this period for HS and FS
    • usbd_hid.c: Fix USBD_LL_CloseEP() function call in USBD_HID_DeInit() replacing endpoint size by endpoint address.
    • -
  • CDC Class
    • usbd_cdc.c: 
      • Add missing GetInterface request management in USBD_CDC_Setup() function
      • Update -USBD_CDC_Setup() function to allow correct user implementation of -CDC_SET_CONTROL_LINE_STATE and similar no-data setup requests.
    -
- -

V2.3.0 / 04-November-2014
-

- - - - - - - - - - - -

Main -Changes

- - - - - - - - - - - - - - - -
    -
  • Update all drivers to be C++ compliant
    -
  • -
  • CDC Class
  • -
      -
    • usbd_cdc.c: fix clear flag issue in USBD_CDC_TransmitPacket() function
    • -
    -
      -
    • usbd_cdc_if_template.c: update TEMPLATE_Receive() function header comment
      -
    • -
    -
  • Miscellaneous source code comments update
  • -
-

V2.2.0 / 13-June-2014

- - - - - - - - - -

Main -Changes

- - - - - - - - - - - - - -
    -
  • Source code comments review and update
  • -
  • HID class
  • -
      -
    • Remove unused API USBD_HID_DeviceQualifierDescriptor()
    • -
    • Add a new API in the HID class to query the poll time USBD_HID_GetPollingInterval()
      -
    • -
    - -
  • CDC class
  • -
      -
    • Bug fix: missing handling ZeroLength Setup request
    • -
    -
  • All classes
    -
  • - -
      -
    • Add alias for the class definition, it's defined as macro with capital letter
    • -
    -
-
ex. for the HID, the USBD_HID_CLASS macro is defined this way #define USBD_HID_CLASS  &USBD_HID
  and the application code can use the previous definition: &USBD_HID ex. USBD_RegisterClass(&USBD_Device, &USBD_HID) or the new USBD_HID_CLASS ex. USBD_RegisterClass(&USBD_Device, USBD_HID_CLASS)
-

V2.1.0 / 22-April-2014

- - - - - - - - -

Main -Changes

- - - - - - - - - - - -
    -
  • usbd_conf_template.c: update file with the right content (it was using MSC memory management layer)
    -
  • -
  • usbd_conf_template.h: change include of stm32f4xx.h by stm32xxx.h and add comment to inform user to adapt it to the device used
  • -
  • Several enhancements in CustomHID class
  • -
      -
    • Update the Custom HID class driver to simplify the link with user processes
    • -
    • Optimize the Custom HID class driver and reduce footprint
    • -
    • Add USBD_CUSTOM_HID_RegisterInterface() API to link user process to custom HID class
    • -
    • Add Custom HID interface template file usbd_customhid_if_template.c/h
    • -
    -
  • Miscellaneous comments update
    -
  • - -
- -

V2.0.0 / 18-February-2014

- - - - - -

Main -Changes

- - - - - - - - - -
    -
  • Major update -based on STM32Cube specification: Library Core, Classes architecture and APIs -modified vs. V1.1.0, and thus the 2 versions are not compatible.
    -
  • This version has to be used only with STM32Cube based development
  • -
- - -

V1.1.0 / 19-March-2012

-

Main -Changes

- -
  • Official support of STM32F4xx devices
  • All source files: license disclaimer text update and add link to the License file on ST Internet.
  • Handle test mode in the set feature request
  • Handle dynamically the USB SELF POWERED feature
  • Handle correctly the USBD_CtlError process to take into account error during Control OUT stage
  • Miscellaneous bug fix

V1.0.0 / 22-July-2011

Main -Changes

-
  • First official version for STM32F105/7xx and STM32F2xx devices

-

License

This -software component is licensed by ST under Ultimate Liberty license -SLA0044, the "License"; You may not use this component except in -compliance with the License. You may obtain a copy of the License at:

http://www.st.com/SLA0044

- -
-
-
-

For - complete documentation on STM32 - Microcontrollers visit www.st.com/STM32

-
-

-
- -
- -

 

- -
- - \ No newline at end of file + + + + + + + + Release Notes for STM32 USB Device Library + + + + + + + + +
+

 

+
+ + + + + + +
+ + + + + + + + + +
+

Back to Release + page

+
+

Release + Notes for STM32 USB Device Library

+

Copyright + 2015 STMicroelectronics

+

+
+

 

+ + + + + + + + + +
+

Update + History

+

V2.9.0 + / 06-July-2021

+

Main + Changes

+
    +
  • Integration of  new USB device Class driver:
  • +
      +
    • USB CCID Class driver based on Universal + Serial Bus + Device Class Definition for Integrated Circuit(s) + Cards Interface + Devices Revision 1.1
    • +
    • USB MTP Class driver based on Universal Serial + Bus + Device Class Media Transfer Protocol Revision 1.1
    • +
    +
  • USB All Classes:
  • +
      +
    • Fix Code Spelling and improve Code Style
    • +
    • Update the way to declare licenses
    • +
    +
  • USB CDC/RNDIS/ECM Classes:
  • +
      +
    • Fix compilation warning with C++ due to missing + casting during class handler allocation
    • +
    +
+

V2.8.0 + / 10-Mars-2021

+

Main + Changes

+
    +
  • Integration of  new USB device Class driver:
  • +
      +
    • USB Printer Class driver based on Universal + Serial Bus + Device Class Definition + for + Printing Devices Version 1.1
    • +
    +
  • USB All Classes:
  • +
      +
    • Fix USB buffer overflow vulnerability for CDC, + CDC-ECM, CDC-RNDIS, DFU, AUDIO, CustomHID, and + Video Classes
    • +
    • fix compilation warning with C++ due to missing + casting during class handler allocation
    • +
    • Enhance comments of USB configuration + descriptors fields
    • +
    +
  • USB Video Class:
  • +
      +
    • fix missing closing bracket for extern "C" in + usbd_video.h
    • +
    • fix USBCV test with Uncompressed video format + support
    • +
    +
+

V2.7.1 + / 18-August-2020

+ +

Main + Changes

+
    +
  • USB All Class:
  • +
      +
    • Add NULL pointer access check to Class handler
      +
    • +
    +
+

V2.7.0 + / 12-August-2020

+

Main + Changes

+
    +
  • Integration of  new USB device Class driver:
  • +
      +
    • USB video Class driver based on USB-IF video + class definition version 1.1
    • +
    +
+
    +
  • USB Core:
  • +
      +
    • Enhance NULL pointer check in Core APIs
    • +
    • Allow supporting both USER and USER Class string + desc
    • +
    • Add support of USB controller which handles + packet-size splitting by hardware
    • +
    • Avoid compilation warning due macro redefinition
    • +
    • change + added to USBD_HandleTypeDef structure: dev_state, + old_dev_state and + ep0_state declaration become volatile to disable + compiler optimization
    • +
    • Word spelling correction and file indentation + improved
    • +
    • usbd_conf.h/c Template file updated to suggest + using by default a static memory allocation for + Class handler
    • +
    +
+
    +
  • USB All Classes
  • +
      +
    • Word spelling correction and file indentation + improved
    • +
    • Allow updating device config descriptor Max + power from user code usbd_conf.h using + USBD_MAX_POWER define
    • +
    • Fix device config descriptor bmAttributes value + which depends on user code define + USBD_SELF_POWERED
    • +
    +
+
    +
  • USB CDC Class:
  • +
      +
    • Class specific request, add protection to limit + the maximum data length to be sent by the CDC + device
    • +
    +
+
    +
  • USB CustomHID Class:
  • +
      +
    • Allow changing CustomHID data EP size from user + code
    • +
    +
+
+

V2.6.1 + / 05-June-2020

+

Main + Changes

+
    +
  • USB Core:
  • +
      +
    • minor rework on USBD_Init() USBD_DeInit()
    • +
    • Fix warning issue with Keil due to missing + return value of setup API
      +
    • +
    +
  • USB CDC Class:
  • +
      +
    • Fix file indentation
    • +
    • Avoid accessing to NULL pointer in case + TransmitCplt() user fops is not defined to allow + application + compatibility with device library version below + v2.6.0
      +
    • +
    +
+
+
    +
  • Fix minor misra-c 2012 violations
  • +
+

V2.6.0 + / 27-December-2019

+

Main + Changes

+
    +
  • Integration of three new USB device Class drivers:
  • +
      +
    • USB CDC ECM Class driver
    • +
    • USB CDC RNDIS Microsoft Class driver
    • +
    • USB Billboard Class driver
    • +
    +
  • Fix mandatory misra-c 2012 violations
  • +
  • update user core and class template files
  • +
  • USB Core:
  • +
      +
    • Fix unexpected EP0 stall during enumeration + phase 
    • +
    • Improve APIs error management and prevent + accessing NULL pointers
    • +
    +
  • USB MSC Class:
  • +
      +
    • Fix USBCV specific class tests
    • +
    • Fix multiple error with SCSI commands handling
    • +
    • Protect medium access when host ask for medium + ejection
    • +
    +
  • USB CDC Class:
  • +
      +
    • Add new function to inform user that current IN + transfer is completed
    • +
    • update transmit and receive APIs to transfer up + to 64KB
    • +
    +
+
    +
  • USB AUDIO Class:
  • +
      +
    • Fix audio sync start buffer size
    • +
    • update user callback periodicTC args by adding + pointer to user buffer and size
    • +
    +
  • USB CustomHID Class:
  • +
      +
    • Rework the OUT transfer complete and prevent + automatically re-enabling the OUT EP 
    • +
    • Add new user API to restart the OUT transfer: + USBD_CUSTOM_HID_ReceivePacket()
    • +
    +
+

V2.5.3 + / 30-April-2019

+

Main + Changes

+
    +
  • Fix misra-c 2012 high severity violations
  • +
  • Core driver:
  • +
      +
    • protect shared macros __ALIGN_BEGIN, __ALIGN_END + with C directive #ifndef
    • +
    • update Core driver and DFU Class driver to + use USBD_SUPPORT_USER_STRING_DESC instead of +  USBD_SUPPORT_USER_STRING
    • +
    •  prevent accessing to NULL pointer if the + get descriptor functions are not defined
    • +
    • Update on USBD_LL_Resume(),  restore the + device state only if the current state is + USBD_STATE_SUSPENDED
    • +
    +
+

V2.5.2 + / 27-Mars-2019

+

Main + Changes

+
    +
  • DFU + Class:
  • +
      +
    • fix + compilation warning due to unreachable + instruction code introduced with CMSIS + V5.4.0 NVIC_SystemReset() prototype change
    • +
    +
+

V2.5.1 + / 03-August-2018
+

+

Main + Changes

+
    +
  • Update + license section by adding path to get copy of ST + Ultimate Liberty license
  • +
  • Core: + Fix unexpected stall during status OUT phase
  • +
  • DFU + Class:
  • +
      +
    • rework + hdfu struct to prevent unaligned + addresses
    • +
    +
  • MSC Class:
  • +
      +
    • fix lba address overflow during large file + transfers > 4Go
    • +
    +
  • Template Class:
  • +
      +
    • add missing Switch case Break on + USBD_Template_Setup API
    • +
    +
+

V2.5.0 + / 15-December-2017
+

+

Main + Changes

+
    +
  • Update + license section
  • +
  • Update some + functions to be MISRAC + 2004 + compliant
  • +
  • Add + HS and OtherSpeed configuration descriptor for HID + and CustomHID classes
  • +
  • Correct + error handling in all class setup function
  • +
  • Add + usbd_desc_template.c/ usbd_desc_template.h + templates files
  • +
  • Add + support of class and vendor request
    +
  • +
  • CDC + Class: fix + zero-length packet issue in bulk IN transfer
  • +
  • Fix + compilation warning with unused arguments for some + functions
  • +
  • Improve + USB Core enumeration state machine
    +
  • +
+

V2.4.2 + / 11-December-2015
+

+

Main + Changes

+
    +
  • CDC + Class
  • +
      +
    • usbd_cdc.c: + change #include + "USBD_CDC.h" by #include + "usbd_cdc.h"
    • +
    +
+
+

V2.4.1 + / 19-June-2015
+

+

Main + Changes

+
    +
  • CDC + Class
  • +
      +
    • usbd_cdc.c: + comments update
    • +
    +
  • MSC + Class
  • +
      +
    • usbd_msc_bot.h: + update to be + C++ compliant
    • +
    +
  • AUDIO + Class
  • +
      +
    • usbd_audio.c: + fix issue when Host sends GetInterface command + it gets a wrong value
    • +
    +
      +
    • usbd_audio.c: + remove useless management of DMA half transfer
      +
    • +
    +
+

V2.4.0 + / 28-February-2015
+

+

Main + Changes

+
    +
  • Core + Driver
  • +
      +
    • Add + support of Link + Power Management (LPM): add + new API GetBOSDescriptor(), + that is used only if USBD_LPM_ENABLED + switch is enabled in usbd_conf.h file
    • +
    • usbd_core.c: +Fix + bug of unsupported premature Host Out stage + during data In stage + (ie. when endpoint 0 maximum data size is 8 and + Host requests + GetDeviceDescriptor for the first time)
    • +
    • usbd_ctlreq.c: + Fix bug of unsupported Endpoint Class requests + (ie. Audio SetCurrent request for endpoint + sampling rate setting)
    • +
    +
  • HID + Class
  • +
      +
    • Updating + Polling time API USBD_HID_GetPollingInterval() + to query this period for HS and FS
    • +
    • usbd_hid.c: + Fix USBD_LL_CloseEP() function call in + USBD_HID_DeInit() replacing endpoint size by + endpoint address.
    • +
    +
  • CDC + Class
  • +
      +
    • usbd_cdc.c: 
    • +
        +
      • Add + missing GetInterface request management in + USBD_CDC_Setup() function
      • +
      +
        +
      • Update +USBD_CDC_Setup() + function to allow correct user implementation + of + CDC_SET_CONTROL_LINE_STATE and similar no-data + setup requests.
        +
      • +
      +
    +
+

V2.3.0 + / 04-November-2014
+

+

Main + Changes

+
    +
  • Update + all drivers to be C++ compliant
    +
  • +
  • CDC + Class
  • +
      +
    • usbd_cdc.c: + fix clear flag issue in USBD_CDC_TransmitPacket() + function
    • +
    +
      +
    • usbd_cdc_if_template.c: + update + TEMPLATE_Receive() + function header comment
      +
    • +
    +
  • Miscellaneous + source code comments update
  • +
+

V2.2.0 + / 13-June-2014

+

Main + Changes

+
    +
  • Source + code comments review and update
  • +
  • HID + class
  • +
      +
    • Remove + unused API USBD_HID_DeviceQualifierDescriptor()
    • +
    • Add + a new API in the HID class to query the poll + time USBD_HID_GetPollingInterval()
      +
    • +
    +
  • CDC + class
  • +
      +
    • Bug + fix: missing handling ZeroLength Setup request
    • +
    +
  • All + classes
    +
  • +
      +
    • Add + alias for the class definition, it's defined as + macro with capital letter
    • +
    +
+
ex. + for the HID, the USBD_HID_CLASS + macro is defined this way #define + USBD_HID_CLASS  &USBD_HID
+   and + the application code can use the previous + definition: &USBD_HID + ex. USBD_RegisterClass(&USBD_Device, + &USBD_HID) or the new USBD_HID_CLASS + ex. USBD_RegisterClass(&USBD_Device, + USBD_HID_CLASS)
+

V2.1.0 + / 22-April-2014

+

Main + Changes

+
    +
  • usbd_conf_template.c: + update file with the right content (it was using + MSC memory management layer)
    +
  • +
  • usbd_conf_template.h: + change include of stm32f4xx.h + by stm32xxx.h + and add comment to inform user to adapt it to the + device used
  • +
  • Several + enhancements in CustomHID class
  • +
      +
    • Update + the Custom HID class driver to simplify the link + with user processes
    • +
    • Optimize + the Custom HID class driver and reduce footprint
    • +
    • Add + USBD_CUSTOM_HID_RegisterInterface() + API to link user process to custom HID + class
    • +
    • Add + Custom HID interface template file usbd_customhid_if_template.c/h
    • +
    +
  • Miscellaneous + comments update
    +
  • +
+

V2.0.0 + / 18-February-2014

+

Main + Changes

+
    +
  • Major + update + based on STM32Cube specification: Library Core, + Classes architecture and APIs + modified vs. V1.1.0, and thus the 2 versions are + not compatible.
    +
  • +
  • This + version has to be used only with STM32Cube + based development
  • +
+

V1.1.0 + / 19-March-2012

+

Main + Changes

+
    +
  • Official + support of STM32F4xx + devices
  • +
  • All + source files: license disclaimer text update and + add link to the License file on ST Internet.
    +
  • +
  • Handle + test mode in the set feature request
  • +
  • Handle + dynamically the USB SELF POWERED feature
  • +
  • Handle + correctly the USBD_CtlError process to take into + account error during Control OUT stage
  • +
  • Miscellaneous + bug fix
  • +
+

V1.0.0 + / 22-July-2011

+

Main + Changes

+
    +
  • First + official version for STM32F105/7xx + and STM32F2xx + devices
  • +
+
+ +

License

+

This + software component is licensed by ST under Ultimate + Liberty license + SLA0044, the "License"; You may not use this + component except in + compliance with the License. You may obtain a copy of + the License at:

+

http://www.st.com/SLA0044

+

+ +
+
+

For + complete documentation on STM32 Microcontrollers visit www.st.com/STM32

+

+
+

+
+
+

 

+
+ +