summaryrefslogtreecommitdiff
path: root/src/class/mtp/mtp_device.h
AgeCommit message (Collapse)Author
2026-08-17class/mtp: correct data phase completion and transaction recoveryhathach
The data-out phase ended before its terminating ZLP and before the application had seen the final payload, and several transaction states had no way back to idle. Reworked as one state machine: - Add MTP_PHASE_DATA_COMPLETE, entered once the data phase has fully finished - for an exact buffer-multiple data-out, only after the host's terminating ZLP - and deliver tud_mtp_data_complete_cb() from there. tud_mtp_response_send() now refuses while the phase is still MTP_PHASE_DATA: ep_out still owes the host a read at that point and re-arming it for a new command would race that read. - Arm the terminating-ZLP read before handing the final payload to the application, as the IN path already does. The 0-length read passes a NULL buffer so the payload is untouched, and claiming ep_out first means a late tud_mtp_data_receive() fails its own claim instead of breaking the driver's next step. - Honor the documented negative return of tud_mtp_data_xfer_cb() and tud_mtp_data_complete_cb() by entering MTP_PHASE_ERROR, which stalls both endpoints. This is the application's way out of a data phase now that a response cannot be sent from one. Their weak stubs return 0 so an application that does not implement them is unaffected. - Take total_len from the container header the host sends on the first OUT packet. The application can only set it up front when it knows the size (SendObject); SendObjectInfo cannot, so total_len kept the 12-byte header default and the phase ended on the first packet. - Reject a runt or misdirected container in both the command and data phases: a short packet was matched against stale buffer contents, and the failed TU_VERIFY left ep_out neither armed nor stalled. The first data-out packet previously underflowed payload_bytes instead. - Restore the previous phase when tud_mtp_data_send()/_receive() cannot claim their endpoint, so the application's fallback response is not refused by a phase the driver never actually entered. - Re-arm ep_out after MTP_REQ_CANCEL of a data phase, and defer the new-command read when ep_out is still busy with the ZLP read of an abandoned transaction: usbd_edpt_xfer() asserts on a busy endpoint, so MTP_REQ_RESET could not recover. The MTP example follows the same contract: a handler error raised mid data phase (fs_send_object_info validates the received ObjectInfo, so STORE_FULL and INVALID_PARENT_OBJECT can only be raised there) is kept and answered from tud_mtp_data_complete_cb() once the phase completes.
2026-07-02license: use SPDX identifiers for src/ headers (#3749)Ha Thach
* license: use SPDX identifiers for src/ headers Replace the full ~20-line MIT license boilerplate on every src/ file with a two-line SPDX tag (SPDX-FileCopyrightText + SPDX-License-Identifier), following the REUSE convention used by CircuitPython and the Linux kernel. Removes ~3500 lines of duplicated boilerplate.
2026-03-25mtp: fix adding empty cstring to mtp_container_infostepan chepushtanov
2026-02-07minor updatehathach
2025-11-05added .clang-formathathach
fix more alerts disable IAR CStat since pvs-studio check is better integrated with clion
2025-09-29refactor mtp examples, add phase and session id to callback datahathach
2025-09-27implement control requesthathach
2025-09-26implement tud_mtp_mounted() and tud_mtp_event_send()hathach
refactor phase state
2025-09-26fix more ci buildhathach
2025-09-25implement send object command, able to create new filehathach
2025-09-25implement MTP_OP_SEND_OBJECT_INFO, refactor fs examplehathach
2025-09-24clean uphathach
2025-09-24unify callback argument. support multiple packet get objecthathach
2025-09-23refactor APIhathach
2025-09-22implement get object, close sessionhathach
2025-09-19rework get storageIDs and get storage infohathach
2025-09-19reworking MTP API, adding callback, getting GetDeviceInfo workinghathach
2025-08-06Add MTP class deviceMaurizio Pesce