blob: cbbd948c626f257486ff2af6cad317e77a107c0e [file] [log] [blame]
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -03001==============
2Gadget Testing
3==============
4
Andrzej Pietrasiewicze38eb2c2014-12-16 14:56:25 +01005This file summarizes information on basic testing of USB functions
6provided by gadgets.
7
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -03008.. contents
9
10 1. ACM function
11 2. ECM function
12 3. ECM subset function
13 4. EEM function
14 5. FFS function
15 6. HID function
16 7. LOOPBACK function
17 8. MASS STORAGE function
18 9. MIDI function
19 10. NCM function
20 11. OBEX function
21 12. PHONET function
22 13. RNDIS function
23 14. SERIAL function
24 15. SOURCESINK function
25 16. UAC1 function (legacy implementation)
26 17. UAC2 function
27 18. UVC function
28 19. PRINTER function
29 20. UAC1 function (new API)
Andrzej Pietrasiewicze38eb2c2014-12-16 14:56:25 +010030
31
321. ACM function
33===============
34
35The function is provided by usb_f_acm.ko module.
36
37Function-specific configfs interface
38------------------------------------
39
40The function name to use when creating the function directory is "acm".
41The ACM function provides just one attribute in its function directory:
42
43 port_num
44
45The attribute is read-only.
46
47There can be at most 4 ACM/generic serial/OBEX ports in the system.
48
49
50Testing the ACM function
51------------------------
52
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -030053On the host::
54
55 cat > /dev/ttyACM<X>
56
57On the device::
58
59 cat /dev/ttyGS<Y>
Andrzej Pietrasiewicze38eb2c2014-12-16 14:56:25 +010060
61then the other way round
62
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -030063On the device::
64
65 cat > /dev/ttyGS<Y>
66
67On the host::
68
69 cat /dev/ttyACM<X>
Andrzej Pietrasiewiczd5862ca2014-12-16 14:56:26 +010070
712. ECM function
72===============
73
74The function is provided by usb_f_ecm.ko module.
75
76Function-specific configfs interface
77------------------------------------
78
79The function name to use when creating the function directory is "ecm".
80The ECM function provides these attributes in its function directory:
81
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -030082 =============== ==================================================
83 ifname network device interface name associated with this
Andrzej Pietrasiewiczd5862ca2014-12-16 14:56:26 +010084 function instance
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -030085 qmult queue length multiplier for high and super speed
86 host_addr MAC address of host's end of this
Andrzej Pietrasiewiczd5862ca2014-12-16 14:56:26 +010087 Ethernet over USB link
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -030088 dev_addr MAC address of device's end of this
Andrzej Pietrasiewiczd5862ca2014-12-16 14:56:26 +010089 Ethernet over USB link
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -030090 =============== ==================================================
Andrzej Pietrasiewiczd5862ca2014-12-16 14:56:26 +010091
92and after creating the functions/ecm.<instance name> they contain default
93values: qmult is 5, dev_addr and host_addr are randomly selected.
Lorenzo Colitti63d15212021-01-14 08:42:22 +090094The ifname can be written to if the function is not bound. A write must be an
95interface pattern such as "usb%d", which will cause the net core to choose the
96next free usbX interface. By default, it is set to "usb%d".
Andrzej Pietrasiewiczd5862ca2014-12-16 14:56:26 +010097
98Testing the ECM function
99------------------------
100
101Configure IP addresses of the device and the host. Then:
102
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300103On the device::
104
105 ping <host's IP>
106
107On the host::
108
109 ping <device's IP>
Andrzej Pietrasiewicz7bfbc6e2014-12-16 14:56:27 +0100110
1113. ECM subset function
112======================
113
114The function is provided by usb_f_ecm_subset.ko module.
115
116Function-specific configfs interface
117------------------------------------
118
119The function name to use when creating the function directory is "geth".
120The ECM subset function provides these attributes in its function directory:
121
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300122 =============== ==================================================
123 ifname network device interface name associated with this
Andrzej Pietrasiewicz7bfbc6e2014-12-16 14:56:27 +0100124 function instance
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300125 qmult queue length multiplier for high and super speed
126 host_addr MAC address of host's end of this
Andrzej Pietrasiewicz7bfbc6e2014-12-16 14:56:27 +0100127 Ethernet over USB link
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300128 dev_addr MAC address of device's end of this
Andrzej Pietrasiewicz7bfbc6e2014-12-16 14:56:27 +0100129 Ethernet over USB link
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300130 =============== ==================================================
Andrzej Pietrasiewicz7bfbc6e2014-12-16 14:56:27 +0100131
132and after creating the functions/ecm.<instance name> they contain default
133values: qmult is 5, dev_addr and host_addr are randomly selected.
Lorenzo Colitti63d15212021-01-14 08:42:22 +0900134The ifname can be written to if the function is not bound. A write must be an
135interface pattern such as "usb%d", which will cause the net core to choose the
136next free usbX interface. By default, it is set to "usb%d".
Andrzej Pietrasiewicz7bfbc6e2014-12-16 14:56:27 +0100137
138Testing the ECM subset function
139-------------------------------
140
141Configure IP addresses of the device and the host. Then:
142
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300143On the device::
144
145 ping <host's IP>
146
147On the host::
148
149 ping <device's IP>
Andrzej Pietrasiewicz4ca560a2014-12-16 14:56:28 +0100150
1514. EEM function
152===============
153
154The function is provided by usb_f_eem.ko module.
155
156Function-specific configfs interface
157------------------------------------
158
159The function name to use when creating the function directory is "eem".
160The EEM function provides these attributes in its function directory:
161
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300162 =============== ==================================================
163 ifname network device interface name associated with this
Andrzej Pietrasiewicz4ca560a2014-12-16 14:56:28 +0100164 function instance
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300165 qmult queue length multiplier for high and super speed
166 host_addr MAC address of host's end of this
Andrzej Pietrasiewicz4ca560a2014-12-16 14:56:28 +0100167 Ethernet over USB link
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300168 dev_addr MAC address of device's end of this
Andrzej Pietrasiewicz4ca560a2014-12-16 14:56:28 +0100169 Ethernet over USB link
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300170 =============== ==================================================
Andrzej Pietrasiewicz4ca560a2014-12-16 14:56:28 +0100171
172and after creating the functions/eem.<instance name> they contain default
173values: qmult is 5, dev_addr and host_addr are randomly selected.
Lorenzo Colitti63d15212021-01-14 08:42:22 +0900174The ifname can be written to if the function is not bound. A write must be an
175interface pattern such as "usb%d", which will cause the net core to choose the
176next free usbX interface. By default, it is set to "usb%d".
Andrzej Pietrasiewicz4ca560a2014-12-16 14:56:28 +0100177
178Testing the EEM function
179------------------------
180
181Configure IP addresses of the device and the host. Then:
182
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300183On the device::
184
185 ping <host's IP>
186
187On the host::
188
189 ping <device's IP>
Andrzej Pietrasiewicz2c0f62f2014-12-16 14:56:29 +0100190
1915. FFS function
192===============
193
194The function is provided by usb_f_fs.ko module.
195
196Function-specific configfs interface
197------------------------------------
198
199The function name to use when creating the function directory is "ffs".
200The function directory is intentionally empty and not modifiable.
201
202After creating the directory there is a new instance (a "device") of FunctionFS
203available in the system. Once a "device" is available, the user should follow
204the standard procedure for using FunctionFS (mount it, run the userspace
205process which implements the function proper). The gadget should be enabled
206by writing a suitable string to usb_gadget/<gadget>/UDC.
207
208Testing the FFS function
209------------------------
210
211On the device: start the function's userspace daemon, enable the gadget
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300212
Andrzej Pietrasiewicz2c0f62f2014-12-16 14:56:29 +0100213On the host: use the USB function provided by the device
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100214
2156. HID function
216===============
217
218The function is provided by usb_f_hid.ko module.
219
220Function-specific configfs interface
221------------------------------------
222
223The function name to use when creating the function directory is "hid".
224The HID function provides these attributes in its function directory:
225
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300226 =============== ===========================================
227 protocol HID protocol to use
228 report_desc data to be used in HID reports, except data
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100229 passed with /dev/hidg<X>
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300230 report_length HID report length
231 subclass HID subclass to use
232 =============== ===========================================
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100233
234For a keyboard the protocol and the subclass are 1, the report_length is 8,
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300235while the report_desc is::
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100236
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300237 $ hd my_report_desc
238 00000000 05 01 09 06 a1 01 05 07 19 e0 29 e7 15 00 25 01 |..........)...%.|
239 00000010 75 01 95 08 81 02 95 01 75 08 81 03 95 05 75 01 |u.......u.....u.|
240 00000020 05 08 19 01 29 05 91 02 95 01 75 03 91 03 95 06 |....).....u.....|
241 00000030 75 08 15 00 25 65 05 07 19 00 29 65 81 00 c0 |u...%e....)e...|
242 0000003f
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100243
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300244Such a sequence of bytes can be stored to the attribute with echo::
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100245
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300246 $ echo -ne \\x05\\x01\\x09\\x06\\xa1.....
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100247
248Testing the HID function
249------------------------
250
251Device:
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300252
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100253- create the gadget
254- connect the gadget to a host, preferably not the one used
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300255 to control the gadget
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100256- run a program which writes to /dev/hidg<N>, e.g.
Mauro Carvalho Chehabecefae62019-06-18 18:05:38 -0300257 a userspace program found in Documentation/usb/gadget_hid.rst::
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100258
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300259 $ ./hid_gadget_test /dev/hidg0 keyboard
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100260
261Host:
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300262
Andrzej Pietrasiewiczf7e3c3c2014-12-16 14:56:30 +0100263- observe the keystrokes from the gadget
Andrzej Pietrasiewiczec91aff2014-12-16 14:56:31 +0100264
2657. LOOPBACK function
266====================
267
268The function is provided by usb_f_ss_lb.ko module.
269
270Function-specific configfs interface
271------------------------------------
272
273The function name to use when creating the function directory is "Loopback".
274The LOOPBACK function provides these attributes in its function directory:
275
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300276 =============== =======================
277 qlen depth of loopback queue
278 bulk_buflen buffer length
279 =============== =======================
Andrzej Pietrasiewiczec91aff2014-12-16 14:56:31 +0100280
281Testing the LOOPBACK function
282-----------------------------
283
284device: run the gadget
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300285
Peter Chenf811a382015-07-31 16:36:30 +0800286host: test-usb (tools/usb/testusb.c)
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100287
2888. MASS STORAGE function
289========================
290
291The function is provided by usb_f_mass_storage.ko module.
292
293Function-specific configfs interface
294------------------------------------
295
296The function name to use when creating the function directory is "mass_storage".
297The MASS STORAGE function provides these attributes in its directory:
298files:
299
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300300 =============== ==============================================
301 stall Set to permit function to halt bulk endpoints.
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100302 Disabled on some USB devices known not to work
303 correctly. You should set it to true.
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300304 num_buffers Number of pipeline buffers. Valid numbers
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100305 are 2..4. Available only if
306 CONFIG_USB_GADGET_DEBUG_FILES is set.
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300307 =============== ==============================================
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100308
309and a default lun.0 directory corresponding to SCSI LUN #0.
310
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300311A new lun can be added with mkdir::
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100312
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300313 $ mkdir functions/mass_storage.0/partition.5
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100314
315Lun numbering does not have to be continuous, except for lun #0 which is
316created by default. A maximum of 8 luns can be specified and they all must be
317named following the <name>.<number> scheme. The numbers can be 0..8.
318Probably a good convention is to name the luns "lun.<number>",
319although it is not mandatory.
320
321In each lun directory there are the following attribute files:
322
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300323 =============== ==============================================
324 file The path to the backing file for the LUN.
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100325 Required if LUN is not marked as removable.
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300326 ro Flag specifying access to the LUN shall be
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100327 read-only. This is implied if CD-ROM emulation
328 is enabled as well as when it was impossible
329 to open "filename" in R/W mode.
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300330 removable Flag specifying that LUN shall be indicated as
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100331 being removable.
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300332 cdrom Flag specifying that LUN shall be reported as
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100333 being a CD-ROM.
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300334 nofua Flag specifying that FUA flag
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100335 in SCSI WRITE(10,12)
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300336 =============== ==============================================
Andrzej Pietrasiewiczcdbe2872014-12-16 14:56:32 +0100337
338Testing the MASS STORAGE function
339---------------------------------
340
341device: connect the gadget, enable it
342host: dmesg, see the USB drives appear (if system configured to automatically
343mount)
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100344
3459. MIDI function
346================
347
348The function is provided by usb_f_midi.ko module.
349
350Function-specific configfs interface
351------------------------------------
352
353The function name to use when creating the function directory is "midi".
354The MIDI function provides these attributes in its function directory:
355
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300356 =============== ====================================
357 buflen MIDI buffer length
358 id ID string for the USB MIDI adapter
359 in_ports number of MIDI input ports
360 index index value for the USB MIDI adapter
361 out_ports number of MIDI output ports
362 qlen USB read request queue length
363 =============== ====================================
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100364
365Testing the MIDI function
366-------------------------
367
368There are two cases: playing a mid from the gadget to
369the host and playing a mid from the host to the gadget.
370
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -03003711) Playing a mid from the gadget to the host:
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100372
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300373host::
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100374
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300375 $ arecordmidi -l
376 Port Client name Port name
377 14:0 Midi Through Midi Through Port-0
378 24:0 MIDI Gadget MIDI Gadget MIDI 1
379 $ arecordmidi -p 24:0 from_gadget.mid
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100380
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300381gadget::
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100382
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300383 $ aplaymidi -l
384 Port Client name Port name
385 20:0 f_midi f_midi
386
387 $ aplaymidi -p 20:0 to_host.mid
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100388
3892) Playing a mid from the host to the gadget
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100390
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300391gadget::
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100392
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300393 $ arecordmidi -l
394 Port Client name Port name
395 20:0 f_midi f_midi
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100396
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300397 $ arecordmidi -p 20:0 from_host.mid
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100398
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300399host::
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100400
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300401 $ aplaymidi -l
402 Port Client name Port name
403 14:0 Midi Through Midi Through Port-0
404 24:0 MIDI Gadget MIDI Gadget MIDI 1
405
406 $ aplaymidi -p24:0 to_gadget.mid
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100407
408The from_gadget.mid should sound identical to the to_host.mid.
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300409
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100410The from_host.id should sound identical to the to_gadget.mid.
411
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300412MIDI files can be played to speakers/headphones with e.g. timidity installed::
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100413
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300414 $ aplaymidi -l
415 Port Client name Port name
416 14:0 Midi Through Midi Through Port-0
417 24:0 MIDI Gadget MIDI Gadget MIDI 1
418 128:0 TiMidity TiMidity port 0
419 128:1 TiMidity TiMidity port 1
420 128:2 TiMidity TiMidity port 2
421 128:3 TiMidity TiMidity port 3
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100422
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300423 $ aplaymidi -p 128:0 file.mid
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100424
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300425MIDI ports can be logically connected using the aconnect utility, e.g.::
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100426
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300427 $ aconnect 24:0 128:0 # try it on the host
Andrzej Pietrasiewicz0d6be592014-12-16 14:56:33 +0100428
429After the gadget's MIDI port is connected to timidity's MIDI port,
430whatever is played at the gadget side with aplaymidi -l is audible
431in host's speakers/headphones.
Andrzej Pietrasiewicz4d0fa792014-12-16 14:56:34 +0100432
43310. NCM function
434================
435
436The function is provided by usb_f_ncm.ko module.
437
438Function-specific configfs interface
439------------------------------------
440
441The function name to use when creating the function directory is "ncm".
442The NCM function provides these attributes in its function directory:
443
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300444 =============== ==================================================
445 ifname network device interface name associated with this
Andrzej Pietrasiewicz4d0fa792014-12-16 14:56:34 +0100446 function instance
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300447 qmult queue length multiplier for high and super speed
448 host_addr MAC address of host's end of this
Andrzej Pietrasiewicz4d0fa792014-12-16 14:56:34 +0100449 Ethernet over USB link
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300450 dev_addr MAC address of device's end of this
Andrzej Pietrasiewicz4d0fa792014-12-16 14:56:34 +0100451 Ethernet over USB link
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300452 =============== ==================================================
Andrzej Pietrasiewicz4d0fa792014-12-16 14:56:34 +0100453
454and after creating the functions/ncm.<instance name> they contain default
455values: qmult is 5, dev_addr and host_addr are randomly selected.
Lorenzo Colitti63d15212021-01-14 08:42:22 +0900456The ifname can be written to if the function is not bound. A write must be an
457interface pattern such as "usb%d", which will cause the net core to choose the
458next free usbX interface. By default, it is set to "usb%d".
Andrzej Pietrasiewicz4d0fa792014-12-16 14:56:34 +0100459
460Testing the NCM function
461------------------------
462
463Configure IP addresses of the device and the host. Then:
464
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300465On the device::
466
467 ping <host's IP>
468
469On the host::
470
471 ping <device's IP>
Andrzej Pietrasiewiczd81b85d2014-12-16 14:56:35 +0100472
47311. OBEX function
474=================
475
476The function is provided by usb_f_obex.ko module.
477
478Function-specific configfs interface
479------------------------------------
480
481The function name to use when creating the function directory is "obex".
482The OBEX function provides just one attribute in its function directory:
483
484 port_num
485
486The attribute is read-only.
487
488There can be at most 4 ACM/generic serial/OBEX ports in the system.
489
490Testing the OBEX function
491-------------------------
492
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300493On device::
494
495 seriald -f /dev/ttyGS<Y> -s 1024
496
497On host::
498
499 serialc -v <vendorID> -p <productID> -i<interface#> -a1 -s1024 \
500 -t<out endpoint addr> -r<in endpoint addr>
Andrzej Pietrasiewiczd81b85d2014-12-16 14:56:35 +0100501
502where seriald and serialc are Felipe's utilities found here:
503
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300504 https://github.com/felipebalbi/usb-tools.git master
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100505
50612. PHONET function
507===================
508
509The function is provided by usb_f_phonet.ko module.
510
511Function-specific configfs interface
512------------------------------------
513
514The function name to use when creating the function directory is "phonet".
515The PHONET function provides just one attribute in its function directory:
516
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300517 =============== ==================================================
518 ifname network device interface name associated with this
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100519 function instance
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300520 =============== ==================================================
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100521
522Testing the PHONET function
523---------------------------
524
525It is not possible to test the SOCK_STREAM protocol without a specific piece
526of hardware, so only SOCK_DGRAM has been tested. For the latter to work,
527in the past I had to apply the patch mentioned here:
528
529http://www.spinics.net/lists/linux-usb/msg85689.html
530
531These tools are required:
532
533git://git.gitorious.org/meego-cellular/phonet-utils.git
534
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300535On the host::
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100536
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300537 $ ./phonet -a 0x10 -i usbpn0
538 $ ./pnroute add 0x6c usbpn0
539 $./pnroute add 0x10 usbpn0
540 $ ifconfig usbpn0 up
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100541
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300542On the device::
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100543
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300544 $ ./phonet -a 0x6c -i upnlink0
545 $ ./pnroute add 0x10 upnlink0
546 $ ifconfig upnlink0 up
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100547
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300548Then a test program can be used::
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100549
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300550 http://www.spinics.net/lists/linux-usb/msg85690.html
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100551
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300552On the device::
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100553
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300554 $ ./pnxmit -a 0x6c -r
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100555
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300556On the host::
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100557
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300558 $ ./pnxmit -a 0x10 -s 0x6c
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100559
560As a result some data should be sent from host to device.
561Then the other way round:
562
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300563On the host::
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100564
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300565 $ ./pnxmit -a 0x10 -r
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100566
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300567On the device::
Andrzej Pietrasiewiczda2907d2014-12-16 14:56:36 +0100568
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300569 $ ./pnxmit -a 0x6c -s 0x10
Andrzej Pietrasiewiczddb72242014-12-16 14:56:37 +0100570
57113. RNDIS function
572==================
573
574The function is provided by usb_f_rndis.ko module.
575
576Function-specific configfs interface
577------------------------------------
578
579The function name to use when creating the function directory is "rndis".
580The RNDIS function provides these attributes in its function directory:
581
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300582 =============== ==================================================
583 ifname network device interface name associated with this
Andrzej Pietrasiewiczddb72242014-12-16 14:56:37 +0100584 function instance
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300585 qmult queue length multiplier for high and super speed
586 host_addr MAC address of host's end of this
Andrzej Pietrasiewiczddb72242014-12-16 14:56:37 +0100587 Ethernet over USB link
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300588 dev_addr MAC address of device's end of this
Andrzej Pietrasiewiczddb72242014-12-16 14:56:37 +0100589 Ethernet over USB link
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300590 =============== ==================================================
Andrzej Pietrasiewiczddb72242014-12-16 14:56:37 +0100591
592and after creating the functions/rndis.<instance name> they contain default
593values: qmult is 5, dev_addr and host_addr are randomly selected.
Lorenzo Colitti63d15212021-01-14 08:42:22 +0900594The ifname can be written to if the function is not bound. A write must be an
595interface pattern such as "usb%d", which will cause the net core to choose the
596next free usbX interface. By default, it is set to "usb%d".
Andrzej Pietrasiewiczddb72242014-12-16 14:56:37 +0100597
Andrzej Pietrasiewiczddb72242014-12-16 14:56:37 +0100598Testing the RNDIS function
599--------------------------
600
601Configure IP addresses of the device and the host. Then:
602
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300603On the device::
604
605 ping <host's IP>
606
607On the host::
608
609 ping <device's IP>
Andrzej Pietrasiewicz4dfcec82014-12-16 14:56:38 +0100610
61114. SERIAL function
612===================
613
614The function is provided by usb_f_gser.ko module.
615
616Function-specific configfs interface
617------------------------------------
618
619The function name to use when creating the function directory is "gser".
620The SERIAL function provides just one attribute in its function directory:
621
622 port_num
623
624The attribute is read-only.
625
626There can be at most 4 ACM/generic serial/OBEX ports in the system.
627
628Testing the SERIAL function
629---------------------------
630
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300631On host::
632
633 insmod usbserial
634 echo VID PID >/sys/bus/usb-serial/drivers/generic/new_id
635
636On host::
637
638 cat > /dev/ttyUSB<X>
639
640On target::
641
642 cat /dev/ttyGS<Y>
Andrzej Pietrasiewicz4dfcec82014-12-16 14:56:38 +0100643
644then the other way round
645
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300646On target::
647
648 cat > /dev/ttyGS<Y>
649
650On host::
651
652 cat /dev/ttyUSB<X>
Andrzej Pietrasiewicz480a9122014-12-16 14:56:39 +0100653
65415. SOURCESINK function
655=======================
656
657The function is provided by usb_f_ss_lb.ko module.
658
659Function-specific configfs interface
660------------------------------------
661
662The function name to use when creating the function directory is "SourceSink".
663The SOURCESINK function provides these attributes in its function directory:
664
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300665 =============== ==================================
666 pattern 0 (all zeros), 1 (mod63), 2 (none)
667 isoc_interval 1..16
668 isoc_maxpacket 0 - 1023 (fs), 0 - 1024 (hs/ss)
669 isoc_mult 0..2 (hs/ss only)
670 isoc_maxburst 0..15 (ss only)
671 bulk_buflen buffer length
672 bulk_qlen depth of queue for bulk
673 iso_qlen depth of queue for iso
674 =============== ==================================
Andrzej Pietrasiewicz480a9122014-12-16 14:56:39 +0100675
676Testing the SOURCESINK function
677-------------------------------
678
679device: run the gadget
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300680
Peter Chenf811a382015-07-31 16:36:30 +0800681host: test-usb (tools/usb/testusb.c)
Andrzej Pietrasiewicz480a9122014-12-16 14:56:39 +0100682
Andrzej Pietrasiewiczdae03582014-12-16 14:56:40 +0100683
Ruslan Bilovold3553392017-06-18 16:23:53 +030068416. UAC1 function (legacy implementation)
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300685=========================================
Andrzej Pietrasiewiczdae03582014-12-16 14:56:40 +0100686
Ruslan Bilovold3553392017-06-18 16:23:53 +0300687The function is provided by usb_f_uac1_legacy.ko module.
Andrzej Pietrasiewiczdae03582014-12-16 14:56:40 +0100688
689Function-specific configfs interface
690------------------------------------
691
Ruslan Bilovold3553392017-06-18 16:23:53 +0300692The function name to use when creating the function directory
693is "uac1_legacy".
Andrzej Pietrasiewiczdae03582014-12-16 14:56:40 +0100694The uac1 function provides these attributes in its function directory:
695
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300696 =============== ====================================
697 audio_buf_size audio buffer size
698 fn_cap capture pcm device file name
699 fn_cntl control device file name
700 fn_play playback pcm device file name
701 req_buf_size ISO OUT endpoint request buffer size
702 req_count ISO OUT endpoint request count
703 =============== ====================================
Andrzej Pietrasiewiczdae03582014-12-16 14:56:40 +0100704
705The attributes have sane default values.
706
707Testing the UAC1 function
708-------------------------
709
710device: run the gadget
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300711
712host::
713
714 aplay -l # should list our USB Audio Gadget
Andrzej Pietrasiewicz020c6f92014-12-16 14:56:41 +0100715
71617. UAC2 function
717=================
718
719The function is provided by usb_f_uac2.ko module.
720
721Function-specific configfs interface
722------------------------------------
723
724The function name to use when creating the function directory is "uac2".
725The uac2 function provides these attributes in its function directory:
726
Hu Haowen9c0edd52021-08-05 12:01:46 +0800727 ================ ====================================================
728 c_chmask capture channel mask
729 c_srate capture sampling rate
730 c_ssize capture sample size (bytes)
731 c_sync capture synchronization type (async/adaptive)
732 c_mute_present capture mute control enable
733 c_volume_present capture volume control enable
734 c_volume_min capture volume control min value (in 1/256 dB)
735 c_volume_max capture volume control max value (in 1/256 dB)
736 c_volume_res capture volume control resolution (in 1/256 dB)
737 fb_max maximum extra bandwidth in async mode
738 p_chmask playback channel mask
739 p_srate playback sampling rate
740 p_ssize playback sample size (bytes)
741 p_mute_present playback mute control enable
742 p_volume_present playback volume control enable
743 p_volume_min playback volume control min value (in 1/256 dB)
744 p_volume_max playback volume control max value (in 1/256 dB)
745 p_volume_res playback volume control resolution (in 1/256 dB)
746 req_number the number of pre-allocated request for both capture
747 and playback
748 ================ ====================================================
Andrzej Pietrasiewicz020c6f92014-12-16 14:56:41 +0100749
750The attributes have sane default values.
751
752Testing the UAC2 function
753-------------------------
754
755device: run the gadget
756host: aplay -l # should list our USB Audio Gadget
757
758This function does not require real hardware support, it just
759sends a stream of audio data to/from the host. In order to
760actually hear something at the device side, a command similar
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300761to this must be used at the device side::
Andrzej Pietrasiewicz020c6f92014-12-16 14:56:41 +0100762
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300763 $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
Andrzej Pietrasiewicz020c6f92014-12-16 14:56:41 +0100764
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300765e.g.::
Andrzej Pietrasiewicz020c6f92014-12-16 14:56:41 +0100766
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300767 $ arecord -f dat -t wav -D hw:CARD=UAC2Gadget,DEV=0 | \
768 aplay -D default:CARD=OdroidU3
Andrzej Pietrasiewicz9c4f5382014-12-16 14:56:42 +0100769
77018. UVC function
771================
772
773The function is provided by usb_f_uvc.ko module.
774
775Function-specific configfs interface
776------------------------------------
777
778The function name to use when creating the function directory is "uvc".
779The uvc function provides these attributes in its function directory:
780
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300781 =================== ================================================
782 streaming_interval interval for polling endpoint for data transfers
783 streaming_maxburst bMaxBurst for super speed companion descriptor
784 streaming_maxpacket maximum packet size this endpoint is capable of
785 sending or receiving when this configuration is
786 selected
787 =================== ================================================
Andrzej Pietrasiewicz9c4f5382014-12-16 14:56:42 +0100788
789There are also "control" and "streaming" subdirectories, each of which contain
790a number of their subdirectories. There are some sane defaults provided, but
791the user must provide the following:
792
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300793 ================== ====================================================
794 control header create in control/header, link from control/class/fs
795 and/or control/class/ss
796 streaming header create in streaming/header, link from
797 streaming/class/fs and/or streaming/class/hs and/or
798 streaming/class/ss
799 format description create in streaming/mjpeg and/or
800 streaming/uncompressed
801 frame description create in streaming/mjpeg/<format> and/or in
802 streaming/uncompressed/<format>
803 ================== ====================================================
Andrzej Pietrasiewicz9c4f5382014-12-16 14:56:42 +0100804
805Each frame description contains frame interval specification, and each
806such specification consists of a number of lines with an inverval value
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300807in each line. The rules stated above are best illustrated with an example::
Andrzej Pietrasiewicz9c4f5382014-12-16 14:56:42 +0100808
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300809 # mkdir functions/uvc.usb0/control/header/h
810 # cd functions/uvc.usb0/control/
811 # ln -s header/h class/fs
812 # ln -s header/h class/ss
813 # mkdir -p functions/uvc.usb0/streaming/uncompressed/u/360p
814 # cat <<EOF > functions/uvc.usb0/streaming/uncompressed/u/360p/dwFrameInterval
815 666666
816 1000000
817 5000000
818 EOF
819 # cd $GADGET_CONFIGFS_ROOT
820 # mkdir functions/uvc.usb0/streaming/header/h
821 # cd functions/uvc.usb0/streaming/header/h
822 # ln -s ../../uncompressed/u
823 # cd ../../class/fs
824 # ln -s ../../header/h
825 # cd ../../class/hs
826 # ln -s ../../header/h
827 # cd ../../class/ss
828 # ln -s ../../header/h
Andrzej Pietrasiewicz9c4f5382014-12-16 14:56:42 +0100829
830
831Testing the UVC function
832------------------------
833
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300834device: run the gadget, modprobe vivid::
Andrzej Pietrasiewicz9c4f5382014-12-16 14:56:42 +0100835
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300836 # uvc-gadget -u /dev/video<uvc video node #> -v /dev/video<vivid video node #>
Andrzej Pietrasiewicz9c4f5382014-12-16 14:56:42 +0100837
838where uvc-gadget is this program:
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300839 http://git.ideasonboard.org/uvc-gadget.git
Andrzej Pietrasiewicz9c4f5382014-12-16 14:56:42 +0100840
841with these patches:
Andrzej Pietrasiewicz9c4f5382014-12-16 14:56:42 +0100842
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300843 http://www.spinics.net/lists/linux-usb/msg99220.html
844
845host::
846
847 luvcview -f yuv
Andrzej Pietrasiewiczee1cd512015-03-03 10:52:32 +0100848
84919. PRINTER function
850====================
851
852The function is provided by usb_f_printer.ko module.
853
854Function-specific configfs interface
855------------------------------------
856
857The function name to use when creating the function directory is "printer".
858The printer function provides these attributes in its function directory:
859
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300860 ========== ===========================================
861 pnp_string Data to be passed to the host in pnp string
862 q_len Number of requests per endpoint
863 ========== ===========================================
Andrzej Pietrasiewiczee1cd512015-03-03 10:52:32 +0100864
865Testing the PRINTER function
866----------------------------
867
868The most basic testing:
869
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300870device: run the gadget::
871
872 # ls -l /devices/virtual/usb_printer_gadget/
Andrzej Pietrasiewiczee1cd512015-03-03 10:52:32 +0100873
874should show g_printer<number>.
875
876If udev is active, then /dev/g_printer<number> should appear automatically.
877
878host:
879
880If udev is active, then e.g. /dev/usb/lp0 should appear.
881
882host->device transmission:
883
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300884device::
Andrzej Pietrasiewiczee1cd512015-03-03 10:52:32 +0100885
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300886 # cat /dev/g_printer<number>
Andrzej Pietrasiewiczee1cd512015-03-03 10:52:32 +0100887
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300888host::
889
890 # cat > /dev/usb/lp0
891
892device->host transmission::
893
894 # cat > /dev/g_printer<number>
895
896host::
897
898 # cat /dev/usb/lp0
Andrzej Pietrasiewiczee1cd512015-03-03 10:52:32 +0100899
900More advanced testing can be done with the prn_example
Mauro Carvalho Chehabecefae62019-06-18 18:05:38 -0300901described in Documentation/usb/gadget_printer.rst.
Ruslan Bilovol0591bc22017-06-18 16:23:54 +0300902
903
90420. UAC1 function (virtual ALSA card, using u_audio API)
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300905========================================================
Ruslan Bilovol0591bc22017-06-18 16:23:54 +0300906
907The function is provided by usb_f_uac1.ko module.
908It will create a virtual ALSA card and the audio streams are simply
909sinked to and sourced from it.
910
911Function-specific configfs interface
912------------------------------------
913
914The function name to use when creating the function directory is "uac1".
915The uac1 function provides these attributes in its function directory:
916
Hu Haowen9c0edd52021-08-05 12:01:46 +0800917 ================ ====================================================
918 c_chmask capture channel mask
919 c_srate capture sampling rate
920 c_ssize capture sample size (bytes)
921 c_mute_present capture mute control enable
922 c_volume_present capture volume control enable
923 c_volume_min capture volume control min value (in 1/256 dB)
924 c_volume_max capture volume control max value (in 1/256 dB)
925 c_volume_res capture volume control resolution (in 1/256 dB)
926 p_chmask playback channel mask
927 p_srate playback sampling rate
928 p_ssize playback sample size (bytes)
929 p_mute_present playback mute control enable
930 p_volume_present playback volume control enable
931 p_volume_min playback volume control min value (in 1/256 dB)
932 p_volume_max playback volume control max value (in 1/256 dB)
933 p_volume_res playback volume control resolution (in 1/256 dB)
Pavel Hofmana8cf0512021-12-25 14:09:29 +0100934 req_number the number of pre-allocated requests for both capture
Hu Haowen9c0edd52021-08-05 12:01:46 +0800935 and playback
936 ================ ====================================================
Ruslan Bilovol0591bc22017-06-18 16:23:54 +0300937
938The attributes have sane default values.
939
940Testing the UAC1 function
941-------------------------
942
943device: run the gadget
944host: aplay -l # should list our USB Audio Gadget
945
946This function does not require real hardware support, it just
947sends a stream of audio data to/from the host. In order to
948actually hear something at the device side, a command similar
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300949to this must be used at the device side::
Ruslan Bilovol0591bc22017-06-18 16:23:54 +0300950
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300951 $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
Ruslan Bilovol0591bc22017-06-18 16:23:54 +0300952
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300953e.g.::
Ruslan Bilovol0591bc22017-06-18 16:23:54 +0300954
Mauro Carvalho Chehabd80b5002019-04-15 23:56:01 -0300955 $ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \
956 aplay -D default:CARD=OdroidU3