Android USB Gadget » History » Revision 2
« Previous |
Revision 2/7
(diff)
| Next »
laforge, 12/17/2016 06:12 PM
Android USB Gadget¶
The Android Linux kernel has an incredibly versatile USB gadget that is not present in mainline linux.
Using sysfs, you can configure a USB device that has a large number of interfaces, each exposing one particular function.
Each function (class) is implemented by a gadget driver. In the source code they are prefixed with "f_", so the serial function is called f_serial
Using sysfs to configure¶
Each USB device is exposed as a /sys/devices/virtual/android_usb/androidX
interface where X
corresponds to the logical number. Most devices these days have only one or two USB ports, so it is mostly android0
or android1
that you will see.
Below this sysfs directory ad a number of different files. They can only be modified/written to if the USB port is disabled by means of
echo 0 > sys/devices/virtual/android_usb/android0/enable
It will disconnect from the USB host at this point.
After modifying what you want to modify, you can use
echo 1 > sys/devices/virtual/android_usb/android0/enable
to re-enable the USB port. It will re-enumerate to the host at this point.
/sys/devices/virtual/android_usb/androidX/functions¶
/sys/devices/virtual/android_usb/androidX/idVendor¶
Allows you to set the USB Vendor ID
/sys/devices/virtual/android_usb/androidX/idProduct¶
Allows you to set the USB Device ID
h3.
'struct android_usb_function' implements a given function
Gadgets¶
ffs (function FS)¶
- userspace process can implement USB functions
- used e.g. by adbd
acm (CDC "astract control model")¶
- USB-IF standardized version of serial-type ports
- exposed via /dev/ttyGS* device
rmnet¶
usb gadget driver to implement a rmnet gadget, f_rmnet.c
Documentation/usb/gadget_rmnet.txt
- drivers/net/ethernet/msm/msm_rmnet_mhi.c
- interface descriptor: class/subclass/proto = 0xff, numEP=3
- stringdescriptor en-us, string 0 == "RmNet"
- full speed descriptors (notify/in/out)
- high speed descriptors (notify/in/out)
- super speed descriptors (notify/in/out + comp)
- rmnet has ports
- control ports can map to SMD, QTY, HSIC,HSUART
- data ports can map to BAM2BAM, BAM_DMUX, BAM2BAM_IPA, HSIC, HSUART, ETHER
- BAM2BAM is normal case?
- ETHER exposes the data pipe as usb_rmnet%d device on Linux (EC25 only)
- frmnet_init_port() establishes connections
gps¶
- IF class/sub/proto = 0xff
- only one endpoint (notify)
- string0 (en-us) is "GPS"
ncm (CDC Netowrk (NCM) link function)¶
ecm_qc (CDC Ethernet)¶
usb_mbim (Mobile Broadband Interface Model)¶
audio (uac1?)¶
diag¶
- class/sub/proto = 0xff
- num-ep 2
- max-packet 512
- some special assumption only if bInterfaceNumber==0
qdss (Qualcomm Debug Sub-System)¶
- has QDSS DATA / QDSS CTRL string descriptor
- somehow connects to BAM
serial¶
- class=0xff, sub/proto = 0
- num_endpoints = 3
- string descroptor "Generic Serial"
- transports
- tty (-> gserial)
- smd (shared memory)
- char_bridge (?)
- hsic
ccid (chipcard reader)¶
- /dev/ccid_ctrl
- /dev/ccid_bulk
- probably intended to be used with userspace progam translating USB CCID requests into QMI requests to access SIM card(s)
charging¶
- usb charger support
mtp¶
ptp¶
rndis¶
rndis_qc¶
ecm¶
mass_storage¶
accessory¶
audio_source¶
midi¶
rndis_gsi¶
rmnet_gsi¶
ecm_gsi¶
mbim_gsi¶
dpl_gsi¶
modem detection / EC20 re-using same usb device id / interface numbers¶
The idea here is to dynamically detect which interface number exposes a certain interface,
regardless what order / qty / interface number
- ADB: 255/66/1, 2 EP
- Diag: 255/255/255, 2 EP
- TTY: 255/0/0, 3 EP, unrecognized descriptors
- RMNET: 255/255/255, 3EP
Updated by laforge over 7 years ago · 2 revisions