Release v2.11.5

This commit is contained in:
Ali Labbene
2025-11-25 11:46:41 +01:00
parent d6e6bd2c66
commit 947131e000
20 changed files with 295 additions and 176 deletions

View File

@@ -283,7 +283,7 @@ extern "C" {
* Appendix C. Device Properties
*/
/* MTP device properties code*/
/* MTP device properties code */
#define MTP_DEV_PROP_UNDEFINED 0x5000U
#define MTP_DEV_PROP_BATTERY_LEVEL 0x5001U
#define MTP_DEV_PROP_FUNCTIONAL_MODE 0x5002U
@@ -336,7 +336,7 @@ extern "C" {
#define MTP_CONT_TYPE_EVENT 4U
#ifndef MTP_STORAGE_ID
#define MTP_STORAGE_ID 0x00010001U /* SD card is inserted*/
#define MTP_STORAGE_ID 0x00010001U /* SD card is inserted */
#endif /* MTP_STORAGE_ID */
#define MTP_NBR_STORAGE_ID 1U

View File

@@ -53,15 +53,16 @@ extern "C" {
typedef enum
{
DATA_TYPE = 0x00,
REP_TYPE = 0x01,
DATA_TYPE = 0x00U,
REP_TYPE = 0x01U,
} MTP_CONTAINER_TYPE;
typedef enum
{
READ_FIRST_DATA = 0x00,
READ_REST_OF_DATA = 0x01,
READ_FIRST_DATA = 0x00U,
READ_REST_OF_DATA = 0x01U,
READ_SEND_ZLP_DATA = 0x02U
} MTP_READ_DATA_STATUS;

View File

@@ -128,6 +128,9 @@ USBD_ClassTypeDef USBD_MTP =
USBD_MTP_GetOtherSpeedCfgDesc,
USBD_MTP_GetDeviceQualifierDescriptor,
#endif /* USE_USBD_COMPOSITE */
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
NULL,
#endif /* USBD_SUPPORT_USER_STRING_DESC */
};
#ifndef USE_USBD_COMPOSITE

View File

@@ -537,50 +537,30 @@ static void MTP_Get_PayloadContent(USBD_HandleTypeDef *pdev)
{
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
uint8_t *buffer = hmtp->GenericContainer.data;
uint32_t i;
uint8_t *buffer;
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];
}
(void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&MTP_DeviceInfo,
MIN(sizeof(MTP_DeviceInfo), MTP_MEDIA_PACKET));
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];
}
(void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&MTP_StorageIDS, sizeof(MTP_StorageIDS));
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];
}
(void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&MTP_StorageInfo, sizeof(MTP_StorageInfo));
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];
}
(void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&MTP_ObjectHandle, hmtp->ResponseLength);
break;
case MTP_OP_GET_OBJECT_INFO:
@@ -589,12 +569,7 @@ static void MTP_Get_PayloadContent(USBD_HandleTypeDef *pdev)
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];
}
(void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&MTP_ObjectPropSupp, sizeof(MTP_ObjectPropSupp));
break;
case MTP_OP_GET_OBJECT_PROP_DESC:
@@ -604,12 +579,7 @@ static void MTP_Get_PayloadContent(USBD_HandleTypeDef *pdev)
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];
}
(void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&MTP_Ref.ref_len, sizeof(MTP_Ref.ref_len));
break;
case MTP_OP_GET_OBJECT_PROPLIST:
@@ -618,20 +588,13 @@ static void MTP_Get_PayloadContent(USBD_HandleTypeDef *pdev)
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];
}
(void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)buffer, hmtp->ResponseLength);
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];
}
(void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&MTP_DevicePropDesc,
MIN(sizeof(MTP_DevicePropDesc), MTP_MEDIA_PACKET));
break;
case MTP_OP_SEND_OBJECT_INFO:
@@ -837,7 +800,7 @@ static void MTP_Get_ObjectPropDesc(USBD_HandleTypeDef *pdev)
case MTP_OB_PROP_PARENT_OBJECT :
MTP_ObjectPropDesc.ObjectPropertyCode = (uint16_t)(hmtp->OperationsContainer.Param1);
MTP_ObjectPropDesc.DataType = MTP_DATATYPE_STR;
MTP_ObjectPropDesc.DataType = MTP_DATATYPE_UINT32;
MTP_ObjectPropDesc.GetSet = MTP_PROP_GET;
MTP_ObjectPropDesc.DefValue = 0U;
MTP_ObjectPropDesc.GroupCode = 0U;
@@ -951,8 +914,8 @@ static uint8_t *MTP_Get_ObjectPropValue(USBD_HandleTypeDef *pdev)
*/
static void MTP_Get_ObjectPropList(USBD_HandleTypeDef *pdev)
{
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
uint16_t filename[255];
uint32_t storageid = MTP_STORAGE_ID;
uint32_t default_val = 0U;
@@ -960,6 +923,7 @@ static void MTP_Get_ObjectPropList(USBD_HandleTypeDef *pdev)
uint16_t format;
uint64_t objsize;
uint32_t parent_proval;
uint8_t mtp_pers_uniq_obj_id[16] = {0};
MTP_PropertiesList.MTP_Properties_len = SUPP_OBJ_PROP_LEN;
hmtp->ResponseLength = 4U; /* size of MTP_PropertiesList.MTP_Properties_len */
@@ -1020,9 +984,13 @@ static void MTP_Get_ObjectPropList(USBD_HandleTypeDef *pdev)
break;
case MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN :
/* Fill in the first 4 bytes with Param1 (Object ID) */
(void)USBD_memcpy(mtp_pers_uniq_obj_id, &hmtp->OperationsContainer.Param1,
sizeof(hmtp->OperationsContainer.Param1));
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;
MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)mtp_pers_uniq_obj_id;
break;
case MTP_OB_PROP_PROTECTION_STATUS :
@@ -1187,7 +1155,8 @@ static uint32_t MTP_build_data_proplist(USBD_HandleTypeDef *pdev,
MTP_PropertiesListTypedef proplist, uint32_t idx)
{
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
uint8_t propval_size = (MTP_FileName.FileName_len * 2U) + 1U;
uint8_t *propval = proplist.MTP_Properties[idx].propval;
uint8_t propval_size = (propval[0] * 2U) + 1U;
uint32_t dataLength;
dataLength = offsetof(MTP_PropertiesTypedef, propval);

View File

@@ -152,11 +152,19 @@ uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev)
/* Start USB data transmission to the host */
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, MIN(MTP_DataLength.readbytes, buffer_size));
/* Move to response phase */
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
if (((MTP_DataLength.totallen + MTP_CONT_HEADER_SIZE) % hmtp->MaxPcktLen) == 0U)
{
/* Send ZLP Packet */
ReadDataStatus = READ_SEND_ZLP_DATA;
}
else
{
/* Move to response phase */
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
/* Reset the state machine */
ReadDataStatus = READ_FIRST_DATA;
/* Reset the state machine */
ReadDataStatus = READ_FIRST_DATA;
}
}
else
{
@@ -168,6 +176,19 @@ uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev)
}
break;
case READ_SEND_ZLP_DATA:
/* Send ZLP to the host */
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, 0U);
/* Move to response phase */
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
/* Reset the state machine */
ReadDataStatus = READ_FIRST_DATA;
break;
default:
break;
}