Android USB Gadget » History » Version 2
laforge, 12/17/2016 06:12 PM
1 | 1 | laforge | h1. Android USB Gadget |
---|---|---|---|
2 | |||
3 | 2 | laforge | The Android Linux kernel has an incredibly versatile USB gadget that is not present in mainline linux. |
4 | |||
5 | Using sysfs, you can configure a USB device that has a large number of interfaces, each exposing one particular function. |
||
6 | |||
7 | 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@ |
||
8 | |||
9 | h2. Using sysfs to configure |
||
10 | |||
11 | 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. |
||
12 | |||
13 | 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 |
||
14 | <pre> |
||
15 | echo 0 > sys/devices/virtual/android_usb/android0/enable |
||
16 | </pre> |
||
17 | It will disconnect from the USB host at this point. |
||
18 | |||
19 | After modifying what you want to modify, you can use |
||
20 | <pre> |
||
21 | echo 1 > sys/devices/virtual/android_usb/android0/enable |
||
22 | </pre> |
||
23 | to re-enable the USB port. It will re-enumerate to the host at this point. |
||
24 | |||
25 | h3. /sys/devices/virtual/android_usb/androidX/functions |
||
26 | |||
27 | h3. /sys/devices/virtual/android_usb/androidX/idVendor |
||
28 | |||
29 | Allows you to set the USB Vendor ID |
||
30 | |||
31 | h3. /sys/devices/virtual/android_usb/androidX/idProduct |
||
32 | |||
33 | Allows you to set the USB Device ID |
||
34 | |||
35 | h3. |
||
36 | |||
37 | |||
38 | |||
39 | |||
40 | |||
41 | 1 | laforge | 'struct android_usb_function' implements a given function |
42 | |||
43 | h2. Gadgets |
||
44 | |||
45 | h3. ffs (function FS) |
||
46 | |||
47 | * userspace process can implement USB functions |
||
48 | * used e.g. by adbd |
||
49 | |||
50 | h3. acm (CDC "astract control model") |
||
51 | |||
52 | * USB-IF standardized version of serial-type ports |
||
53 | * exposed via /dev/ttyGS* device |
||
54 | |||
55 | h3. rmnet |
||
56 | |||
57 | usb gadget driver to implement a rmnet gadget, f_rmnet.c |
||
58 | Documentation/usb/gadget_rmnet.txt |
||
59 | |||
60 | * drivers/net/ethernet/msm/msm_rmnet_mhi.c |
||
61 | * interface descriptor: class/subclass/proto = 0xff, numEP=3 |
||
62 | ** stringdescriptor en-us, string 0 == "RmNet" |
||
63 | ** full speed descriptors (notify/in/out) |
||
64 | ** high speed descriptors (notify/in/out) |
||
65 | ** super speed descriptors (notify/in/out + comp) |
||
66 | |||
67 | * rmnet has ports |
||
68 | * control ports can map to SMD, QTY, HSIC,HSUART |
||
69 | * data ports can map to BAM2BAM, BAM_DMUX, BAM2BAM_IPA, HSIC, HSUART, ETHER |
||
70 | ** BAM2BAM is normal case? |
||
71 | ** ETHER exposes the data pipe as usb_rmnet%d device on Linux (EC25 only) |
||
72 | * frmnet_init_port() establishes connections |
||
73 | |||
74 | |||
75 | h3. gps |
||
76 | |||
77 | * IF class/sub/proto = 0xff |
||
78 | * only one endpoint (notify) |
||
79 | * string[0] (en-us) is "GPS" |
||
80 | |||
81 | h3. ncm (CDC Netowrk (NCM) link function) |
||
82 | |||
83 | h3. ecm_qc (CDC Ethernet) |
||
84 | |||
85 | h3. usb_mbim (Mobile Broadband Interface Model) |
||
86 | |||
87 | h3. audio (uac1?) |
||
88 | |||
89 | h3. diag |
||
90 | |||
91 | * class/sub/proto = 0xff |
||
92 | * num-ep 2 |
||
93 | * max-packet 512 |
||
94 | * some special assumption only if bInterfaceNumber==0 |
||
95 | |||
96 | h3. qdss (Qualcomm Debug Sub-System) |
||
97 | |||
98 | * has QDSS DATA / QDSS CTRL string descriptor |
||
99 | * somehow connects to BAM |
||
100 | |||
101 | h3. serial |
||
102 | |||
103 | * class=0xff, sub/proto = 0 |
||
104 | * num_endpoints = 3 |
||
105 | * string descroptor "Generic Serial" |
||
106 | * transports |
||
107 | ** tty (-> gserial) |
||
108 | ** smd (shared memory) |
||
109 | ** char_bridge (?) |
||
110 | ** hsic |
||
111 | |||
112 | h3. ccid (chipcard reader) |
||
113 | |||
114 | * /dev/ccid_ctrl |
||
115 | * /dev/ccid_bulk |
||
116 | * probably intended to be used with userspace progam translating USB CCID requests into QMI requests to access SIM card(s) |
||
117 | |||
118 | h3. charging |
||
119 | |||
120 | * usb charger support |
||
121 | |||
122 | h3. mtp |
||
123 | |||
124 | h3. ptp |
||
125 | |||
126 | h3. rndis |
||
127 | |||
128 | h3. rndis_qc |
||
129 | |||
130 | h3. ecm |
||
131 | |||
132 | h3. mass_storage |
||
133 | |||
134 | h3. accessory |
||
135 | |||
136 | h3. audio_source |
||
137 | |||
138 | h3. midi |
||
139 | |||
140 | h3. rndis_gsi |
||
141 | |||
142 | h3. rmnet_gsi |
||
143 | |||
144 | h3. ecm_gsi |
||
145 | |||
146 | h3. mbim_gsi |
||
147 | |||
148 | h3. dpl_gsi |
||
149 | |||
150 | |||
151 | h2. modem detection / EC20 re-using same usb device id / interface numbers |
||
152 | |||
153 | The idea here is to dynamically detect which interface number exposes a certain interface, |
||
154 | regardless what order / qty / interface number |
||
155 | |||
156 | * ADB: 255/66/1, 2 EP |
||
157 | * Diag: 255/255/255, 2 EP |
||
158 | * TTY: 255/0/0, 3 EP, unrecognized descriptors |
||
159 | * RMNET: 255/255/255, 3EP |