Skip to content

USB MTP driver. Multiple bugs #180

Open
Open
@Kun-Kun

Description

@Kun-Kun

Certainly a bug:

uint32_t length = MIN(hmtp->GenericContainer.length, len);

At the file transfer such statement calculates buffer size in a wrong way. It always 12 bytes since the header is always less than Header+data.
I offer to remove this line and to invoke as
(void)USBD_LL_Transmit(pdev, MTPInEpAdd, buf, len);
Because at file transfer there might be a situation when there is no header and the last packet of data has length 0-12 bytes.

The second bug is on the:

(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId])->ReadData(hmtp->OperationsContainer.Param1,

It invokes the function that writes into buffer and sets it size.
But at line:
(void)USBD_memcpy((uint8_t *)data_buff, (uint8_t *)&hmtp->GenericContainer, MTP_CONT_HEADER_SIZE);

We overwrite this buffer with 12 byte header at the start of the file transfer thus corrupts 12 bytes of provided data in the buffer.
I offer to change line 109 with:
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId])->ReadData(hmtp->OperationsContainer.Param1, (uint8_t *)data_buff+MTP_CONT_HEADER_SIZE, &MTP_DataLength);
As a result move the pointer by 12 bytes and write buffer in the right section
And it is good to notice in ReadData comments that it should return buffer with size 52 at the first invocation,should return 64 bytes at intermediate, and 0-63bytes meaning the last transfer

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinginternal bug trackerIssue confirmed and logged into the internal bug tracking systemmwMiddleware-related issue or pull-request.usbUniversal Serial Bus

Type

Projects

Status

To release

Relationships

None yet

Development

No branches or pull requests

Issue actions