androidusb-otgandroid-kernel

Is it possible to use OTG Host Negotiation Protocol to change modes while connecting two devices?


I have two android phones connected with an OTG cable. Obviously, the cable forces once phone into host mode and the other becomes the peripheral. I would like to be able to dynamically alternate the host/peripheral status of the devices without switching the cable around and the OTG HNP spec seems to indicate that is possible. I found some further information on it here but I'm not sure where to go with it - https://android.googlesource.com/kernel/msm/+/android-msm-bullhead-3.10-marshmallow-dr/Documentation/usb/msm_otg.txt


Solution

  • Yes, it is possible. Good find on the very technical documentation. However the Developer.android.com site and the USB.org has more information regarding implementation:

    USB accessory and host modes are directly supported in Android 3.1 (API level 12) or newer platforms. USB accessory mode is also backported to Android 2.3.4 (API level 10) as an add-on library to support a broader range of devices. Device manufacturers can choose whether or not to include the add-on library on the device's system image. Link

    As far as I can tell Host negotiation always favors traditional Host controllers like computers. Android devices have traditionally been USB accessories. However a very complicated situation arises when you have a hub with a host (like a PC) and another accessory plugged in. It seems like there is no way to settle the dispute about which device should be a host the Android or the PC. For instance I plugged in a host PC to a Android device with a HUB attached and a gigabit ethernet dongle. I could never establish a connection with the dongle. In fact the HNP never seemed to take place.

    Finally, the documentation seems to suggest that the Host is responsible for operating the USB Stream. What seems most promising is the documentation Here which establishes the direction of a USBEndpoint.