Skip to content

datasets: deviceinfo: clear MTP extension string to avoid libmtp quirks and USB resets#134

Merged
jfdelnero merged 2 commits intoviveris:masterfrom
js731ca:drop-extensions-string
Aug 27, 2025
Merged

datasets: deviceinfo: clear MTP extension string to avoid libmtp quirks and USB resets#134
jfdelnero merged 2 commits intoviveris:masterfrom
js731ca:drop-extensions-string

Conversation

@js731ca
Copy link
Copy Markdown
Contributor

@js731ca js731ca commented Aug 2, 2025

Remove legacy MTP extension string ("microsoft.com: 1.0; android.com: 1.0;") from DevInfos_MTP_Extensions[] and set it to an empty string. These identifiers were originally intended to point to vendor-specific documentation per the MTP spec [1], but no such documentation exists — even the Internet Archive has no record of it.

This string inadvertently triggers libmtp's [2] vendor-specific quirk handling, which includes problematic flags such as:

  • DEVICE_FLAG_UNLOAD_DRIVER
  • DEVICE_FLAG_FORCE_RESET_ON_CLOSE

These flags are applied when libmtp detects an "Android device" and assigns default bug flags [3], causing the USB connection to be reset after each transfer. This behavior is especially disruptive on multi-function USB devices, where the USB-gadget interface also serves as e.g. the primary SSH entry point. Frequent resets during rapid MTP file transfers lead to intermittent network disconnects and test failures.

By clearing the extension string, we prevent libmtp from applying these quirks, improving stability and preserving USB functionality during stress tests. There is no other impact on MTP functionality, as both umpt-responder and libmtp do nothing else with these extension strings; and the supported MTP operations are both listed and handled separately.

Links:
https://www.usb.org/document-library/media-transfer-protocol-v11-spec-and-mtp-v11-adopters-agreement https://libmtp.sourceforge.net/
https://github.com/libmtp/libmtp/blob/master/src/device-flags.h#L320


Tested (so far):

  • linux device with utmp -> linux host, libmtp-tools (raspberry-pi 4, running yocto
  • linux device with umtp -> linux host, gvfs->libmtp (x86-64, gnome/debian)
  • linux device with utmp -> android mobile "host"
  • linux device with umtp -> apple iOS mobile host
  • linux device with umtp -> apple iOS pc host
  • linux device with umtp -> windows pc host
  • linux device with umtp -> windows mobile host

Request for support/testers, since i don't have all combinations at hand :-)


CC @gujie-leica @bith3ad

…ks and USB resets

Remove legacy MTP extension string ("microsoft.com: 1.0; android.com: 1.0;") from DevInfos_MTP_Extensions[] and set it to an empty string. These identifiers were originally intended to point to vendor-specific documentation per the MTP spec [1], but no such documentation exists — even the Internet Archive has no record of it.

This string inadvertently triggers libmtp's [2] vendor-specific quirk handling, which includes problematic flags such as:
- DEVICE_FLAG_UNLOAD_DRIVER
- DEVICE_FLAG_FORCE_RESET_ON_CLOSE

These flags are applied when libmtp detects an "Android device" and assigns default bug flags [3], causing the USB connection to be reset after each transfer. This behavior is especially disruptive on multi-function USB devices, where the USB-gadget interface also serves as e.g. the primary SSH entry point. Frequent resets during rapid MTP file transfers lead to intermittent network disconnects and test failures.

By clearing the extension string, we prevent libmtp from applying these quirks, improving stability and preserving USB functionality during stress tests.
There is no other impact on MTP functionality, as both umpt-responder and libmtp do nothing else with these extension strings; and the supported MTP operations are both listed and handled separately.

Links:
https://www.usb.org/document-library/media-transfer-protocol-v11-spec-and-mtp-v11-adopters-agreement
https://libmtp.sourceforge.net/
https://github.com/libmtp/libmtp/blob/master/src/device-flags.h#L320

Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
@js731ca js731ca force-pushed the drop-extensions-string branch from 45cc28c to 71796ad Compare August 2, 2025 03:37
@jfdelnero
Copy link
Copy Markdown
Member

Maybe this string is worth a new optional parameter in the configuration file?

@js731ca
Copy link
Copy Markdown
Contributor Author

js731ca commented Aug 2, 2025

Maybe this string is worth a new optional parameter in the configuration file?

i've pondered that too... but how would we document on what values to set it to?, apart from this inherited/legacy one - for which finding any actual documentation is already nigh impossible :-S

@js731ca
Copy link
Copy Markdown
Contributor Author

js731ca commented Aug 2, 2025

For reference: the original string seems to have been inherited from cmtp-responder, which in turn just got it from tizen -- with no usefull context or documentation :-|

The later commit hints at things like:

+#define PTP_EVENTCODE_VENDOREXTENTION1         0xC001
+#define PTP_EVENTCODE_VENDOREXTENTION2         0xC002

or things that are potentially part of the microsoft:1.0 extension like:

+/* Operation for Windows Media 10 MTP extension */
+#define        MTP_OPCODE_WMP_UNDEFINED                                0x9200
+#define        MTP_OPCODE_WMP_METADATAROUNDTRIP                        0x9201
+#define        MTP_OPCODE_WMP_REPORTACQUIREDCONTENT                    0x9202

but these look like they are vestiges from back when PTP "evolved" into MTP
(and none of these are implemented in umtp-responder)

Raising the question: does it make sense to advertise extensions that are not actually there?

@js731ca
Copy link
Copy Markdown
Contributor Author

js731ca commented Aug 4, 2025

Update: "tested" the connection to a Windows 11 Enterprise host, looked OK
listing devices (and their properties), copying files around, ...
(disclamer: i'm not a windows native ;-)

Add a configuration option to allow a user to set the mtp extensions
the responder will advertise to the host. This is only provided for
backwards compatibility.

Note that this string is defaulting to empty, and the string inherited
from the tizen code-base mentioned in the example configuration can be
used but can&will cause a hosts MTP implementation to see extensions
that are not backed by any logic - and in the case of libmtp will
trigger vendor specific quirk handling that unloads the hosts usb
driver and resets the usb device.

Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
@js731ca
Copy link
Copy Markdown
Contributor Author

js731ca commented Aug 9, 2025

Maybe this string is worth a new optional parameter in the configuration file?

how about this: 684ff37

I'm still confident though that we could just drop this inherited legacy :-)

@jfdelnero
Copy link
Copy Markdown
Member

It's perfect ! Thanks again !

@jfdelnero jfdelnero merged commit 93cca39 into viveris:master Aug 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants