Documentation: usb: MIDI function testing
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / Documentation / usb / gadget-testing.txt
CommitLineData
e38eb2c8
AP
1This file summarizes information on basic testing of USB functions
2provided by gadgets.
3
41. ACM function
d5862ca6 52. ECM function
7bfbc6e3 63. ECM subset function
4ca560a6 74. EEM function
2c0f62f9 85. FFS function
f7e3c3cd 96. HID function
ec91aff7 107. LOOPBACK function
cdbe287d 118. MASS STORAGE function
0d6be59a 129. MIDI function
e38eb2c8
AP
13
14
151. ACM function
16===============
17
18The function is provided by usb_f_acm.ko module.
19
20Function-specific configfs interface
21------------------------------------
22
23The function name to use when creating the function directory is "acm".
24The ACM function provides just one attribute in its function directory:
25
26 port_num
27
28The attribute is read-only.
29
30There can be at most 4 ACM/generic serial/OBEX ports in the system.
31
32
33Testing the ACM function
34------------------------
35
36On the host: cat > /dev/ttyACM<X>
37On the device : cat /dev/ttyGS<Y>
38
39then the other way round
40
41On the device: cat > /dev/ttyGS<Y>
42On the host: cat /dev/ttyACM<X>
d5862ca6
AP
43
442. ECM function
45===============
46
47The function is provided by usb_f_ecm.ko module.
48
49Function-specific configfs interface
50------------------------------------
51
52The function name to use when creating the function directory is "ecm".
53The ECM function provides these attributes in its function directory:
54
55 ifname - network device interface name associated with this
56 function instance
57 qmult - queue length multiplier for high and super speed
58 host_addr - MAC address of host's end of this
59 Ethernet over USB link
60 dev_addr - MAC address of device's end of this
61 Ethernet over USB link
62
63and after creating the functions/ecm.<instance name> they contain default
64values: qmult is 5, dev_addr and host_addr are randomly selected.
65Except for ifname they can be written to until the function is linked to a
66configuration. The ifname is read-only and contains the name of the interface
67which was assigned by the net core, e. g. usb0.
68
69Testing the ECM function
70------------------------
71
72Configure IP addresses of the device and the host. Then:
73
74On the device: ping <host's IP>
75On the host: ping <device's IP>
7bfbc6e3
AP
76
773. ECM subset function
78======================
79
80The function is provided by usb_f_ecm_subset.ko module.
81
82Function-specific configfs interface
83------------------------------------
84
85The function name to use when creating the function directory is "geth".
86The ECM subset function provides these attributes in its function directory:
87
88 ifname - network device interface name associated with this
89 function instance
90 qmult - queue length multiplier for high and super speed
91 host_addr - MAC address of host's end of this
92 Ethernet over USB link
93 dev_addr - MAC address of device's end of this
94 Ethernet over USB link
95
96and after creating the functions/ecm.<instance name> they contain default
97values: qmult is 5, dev_addr and host_addr are randomly selected.
98Except for ifname they can be written to until the function is linked to a
99configuration. The ifname is read-only and contains the name of the interface
100which was assigned by the net core, e. g. usb0.
101
102Testing the ECM subset function
103-------------------------------
104
105Configure IP addresses of the device and the host. Then:
106
107On the device: ping <host's IP>
108On the host: ping <device's IP>
4ca560a6
AP
109
1104. EEM function
111===============
112
113The function is provided by usb_f_eem.ko module.
114
115Function-specific configfs interface
116------------------------------------
117
118The function name to use when creating the function directory is "eem".
119The EEM function provides these attributes in its function directory:
120
121 ifname - network device interface name associated with this
122 function instance
123 qmult - queue length multiplier for high and super speed
124 host_addr - MAC address of host's end of this
125 Ethernet over USB link
126 dev_addr - MAC address of device's end of this
127 Ethernet over USB link
128
129and after creating the functions/eem.<instance name> they contain default
130values: qmult is 5, dev_addr and host_addr are randomly selected.
131Except for ifname they can be written to until the function is linked to a
132configuration. The ifname is read-only and contains the name of the interface
133which was assigned by the net core, e. g. usb0.
134
135Testing the EEM function
136------------------------
137
138Configure IP addresses of the device and the host. Then:
139
140On the device: ping <host's IP>
141On the host: ping <device's IP>
2c0f62f9
AP
142
1435. FFS function
144===============
145
146The function is provided by usb_f_fs.ko module.
147
148Function-specific configfs interface
149------------------------------------
150
151The function name to use when creating the function directory is "ffs".
152The function directory is intentionally empty and not modifiable.
153
154After creating the directory there is a new instance (a "device") of FunctionFS
155available in the system. Once a "device" is available, the user should follow
156the standard procedure for using FunctionFS (mount it, run the userspace
157process which implements the function proper). The gadget should be enabled
158by writing a suitable string to usb_gadget/<gadget>/UDC.
159
160Testing the FFS function
161------------------------
162
163On the device: start the function's userspace daemon, enable the gadget
164On the host: use the USB function provided by the device
f7e3c3cd
AP
165
1666. HID function
167===============
168
169The function is provided by usb_f_hid.ko module.
170
171Function-specific configfs interface
172------------------------------------
173
174The function name to use when creating the function directory is "hid".
175The HID function provides these attributes in its function directory:
176
177 protocol - HID protocol to use
178 report_desc - data to be used in HID reports, except data
179 passed with /dev/hidg<X>
180 report_length - HID report length
181 subclass - HID subclass to use
182
183For a keyboard the protocol and the subclass are 1, the report_length is 8,
184while the report_desc is:
185
186$ hd my_report_desc
18700000000 05 01 09 06 a1 01 05 07 19 e0 29 e7 15 00 25 01 |..........)...%.|
18800000010 75 01 95 08 81 02 95 01 75 08 81 03 95 05 75 01 |u.......u.....u.|
18900000020 05 08 19 01 29 05 91 02 95 01 75 03 91 03 95 06 |....).....u.....|
19000000030 75 08 15 00 25 65 05 07 19 00 29 65 81 00 c0 |u...%e....)e...|
1910000003f
192
193Such a sequence of bytes can be stored to the attribute with echo:
194
195$ echo -ne \\x05\\x01\\x09\\x06\\xa1.....
196
197Testing the HID function
198------------------------
199
200Device:
201- create the gadget
202- connect the gadget to a host, preferably not the one used
203to control the gadget
204- run a program which writes to /dev/hidg<N>, e.g.
205a userspace program found in Documentation/usb/gadget_hid.txt:
206
207$ ./hid_gadget_test /dev/hidg0 keyboard
208
209Host:
210- observe the keystrokes from the gadget
ec91aff7
AP
211
2127. LOOPBACK function
213====================
214
215The function is provided by usb_f_ss_lb.ko module.
216
217Function-specific configfs interface
218------------------------------------
219
220The function name to use when creating the function directory is "Loopback".
221The LOOPBACK function provides these attributes in its function directory:
222
223 qlen - depth of loopback queue
224 bulk_buflen - buffer length
225
226Testing the LOOPBACK function
227-----------------------------
228
229device: run the gadget
230host: test-usb
231
232http://www.linux-usb.org/usbtest/testusb.c
cdbe287d
AP
233
2348. MASS STORAGE function
235========================
236
237The function is provided by usb_f_mass_storage.ko module.
238
239Function-specific configfs interface
240------------------------------------
241
242The function name to use when creating the function directory is "mass_storage".
243The MASS STORAGE function provides these attributes in its directory:
244files:
245
246 stall - Set to permit function to halt bulk endpoints.
247 Disabled on some USB devices known not to work
248 correctly. You should set it to true.
249 num_buffers - Number of pipeline buffers. Valid numbers
250 are 2..4. Available only if
251 CONFIG_USB_GADGET_DEBUG_FILES is set.
252
253and a default lun.0 directory corresponding to SCSI LUN #0.
254
255A new lun can be added with mkdir:
256
257$ mkdir functions/mass_storage.0/partition.5
258
259Lun numbering does not have to be continuous, except for lun #0 which is
260created by default. A maximum of 8 luns can be specified and they all must be
261named following the <name>.<number> scheme. The numbers can be 0..8.
262Probably a good convention is to name the luns "lun.<number>",
263although it is not mandatory.
264
265In each lun directory there are the following attribute files:
266
267 file - The path to the backing file for the LUN.
268 Required if LUN is not marked as removable.
269 ro - Flag specifying access to the LUN shall be
270 read-only. This is implied if CD-ROM emulation
271 is enabled as well as when it was impossible
272 to open "filename" in R/W mode.
273 removable - Flag specifying that LUN shall be indicated as
274 being removable.
275 cdrom - Flag specifying that LUN shall be reported as
276 being a CD-ROM.
277 nofua - Flag specifying that FUA flag
278 in SCSI WRITE(10,12)
279
280Testing the MASS STORAGE function
281---------------------------------
282
283device: connect the gadget, enable it
284host: dmesg, see the USB drives appear (if system configured to automatically
285mount)
0d6be59a
AP
286
2879. MIDI function
288================
289
290The function is provided by usb_f_midi.ko module.
291
292Function-specific configfs interface
293------------------------------------
294
295The function name to use when creating the function directory is "midi".
296The MIDI function provides these attributes in its function directory:
297
298 buflen - MIDI buffer length
299 id - ID string for the USB MIDI adapter
300 in_ports - number of MIDI input ports
301 index - index value for the USB MIDI adapter
302 out_ports - number of MIDI output ports
303 qlen - USB read request queue length
304
305Testing the MIDI function
306-------------------------
307
308There are two cases: playing a mid from the gadget to
309the host and playing a mid from the host to the gadget.
310
3111) Playing a mid from the gadget to the host
312host)
313
314$ arecordmidi -l
315 Port Client name Port name
316 14:0 Midi Through Midi Through Port-0
317 24:0 MIDI Gadget MIDI Gadget MIDI 1
318$ arecordmidi -p 24:0 from_gadget.mid
319
320gadget)
321
322$ aplaymidi -l
323 Port Client name Port name
324 20:0 f_midi f_midi
325
326$ aplaymidi -p 20:0 to_host.mid
327
3282) Playing a mid from the host to the gadget
329gadget)
330
331$ arecordmidi -l
332 Port Client name Port name
333 20:0 f_midi f_midi
334
335$ arecordmidi -p 20:0 from_host.mid
336
337host)
338
339$ aplaymidi -l
340 Port Client name Port name
341 14:0 Midi Through Midi Through Port-0
342 24:0 MIDI Gadget MIDI Gadget MIDI 1
343
344$ aplaymidi -p24:0 to_gadget.mid
345
346The from_gadget.mid should sound identical to the to_host.mid.
347The from_host.id should sound identical to the to_gadget.mid.
348
349MIDI files can be played to speakers/headphones with e.g. timidity installed
350
351$ aplaymidi -l
352 Port Client name Port name
353 14:0 Midi Through Midi Through Port-0
354 24:0 MIDI Gadget MIDI Gadget MIDI 1
355128:0 TiMidity TiMidity port 0
356128:1 TiMidity TiMidity port 1
357128:2 TiMidity TiMidity port 2
358128:3 TiMidity TiMidity port 3
359
360$ aplaymidi -p 128:0 file.mid
361
362MIDI ports can be logically connected using the aconnect utility, e.g.:
363
364$ aconnect 24:0 128:0 # try it on the host
365
366After the gadget's MIDI port is connected to timidity's MIDI port,
367whatever is played at the gadget side with aplaymidi -l is audible
368in host's speakers/headphones.