summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorZixun LI <[email protected]>2026-05-30 13:04:35 +0200
committerGitHub <[email protected]>2026-05-30 13:04:35 +0200
commit26724bfb133671d4a55cb2925c40c5f827aef752 (patch)
tree754e973c21235895173a87cbd44db082861ee685 /src/class
parentd3ae3a02a9a01b2f2a1ed16a463074e044178945 (diff)
parent84e3347badc7f9f5146b5f5eb129900f2fc59389 (diff)
Merge pull request #3658 from wjklimek1/mtp-out-transfer-fix
Fix premature MTP phase change after short MTP OUT transfer
Diffstat (limited to 'src/class')
-rw-r--r--src/class/mtp/mtp_device.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/class/mtp/mtp_device.c b/src/class/mtp/mtp_device.c
index 0da984f4a..fd06b4601 100644
--- a/src/class/mtp/mtp_device.c
+++ b/src/class/mtp/mtp_device.c
@@ -441,9 +441,19 @@ bool mtpd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
threshold = CFG_TUD_MTP_EP_BUFSIZE;
}
- // Check completion: ZLP, short packet, or total length reached
- const bool is_complete =
- (xferred_bytes == 0 || xferred_bytes < threshold || p_mtp->xferred_len >= p_mtp->total_len);
+ // Check completion for IN and OUT separately
+ bool is_complete;
+
+ if (is_data_in)
+ {
+ // IN completion: short packet, ZLP, or reaching total_len
+ is_complete = (xferred_bytes == 0 || xferred_bytes < threshold || p_mtp->xferred_len >= p_mtp->total_len);
+ }
+ else
+ {
+ // OUT completion: reaching total_len or ZLP
+ is_complete = (p_mtp->xferred_len >= p_mtp->total_len) || ((xferred_bytes == 0 && p_mtp->xferred_len > 0));
+ }
TU_LOG_DRV(" MTP Data %s CB: xferred_bytes=%lu, xferred_len/total_len=%lu/%lu, is_complete=%d\r\n",
is_data_in ? "IN" : "OUT", xferred_bytes, p_mtp->xferred_len, p_mtp->total_len, is_complete ? 1 : 0);