]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - Documentation/usb/gadget-testing.rst
Merge tag 'timers-core-2020-08-14' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-hirsute-kernel.git] / Documentation / usb / gadget-testing.rst
CommitLineData
d80b5005
MCC
1==============
2Gadget Testing
3==============
4
e38eb2c8
AP
5This file summarizes information on basic testing of USB functions
6provided by gadgets.
7
d80b5005
MCC
8.. 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)
e38eb2c8
AP
30
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
d80b5005
MCC
53On the host::
54
55 cat > /dev/ttyACM<X>
56
57On the device::
58
59 cat /dev/ttyGS<Y>
e38eb2c8
AP
60
61then the other way round
62
d80b5005
MCC
63On the device::
64
65 cat > /dev/ttyGS<Y>
66
67On the host::
68
69 cat /dev/ttyACM<X>
d5862ca6
AP
70
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
d80b5005
MCC
82 =============== ==================================================
83 ifname network device interface name associated with this
d5862ca6 84 function instance
d80b5005
MCC
85 qmult queue length multiplier for high and super speed
86 host_addr MAC address of host's end of this
d5862ca6 87 Ethernet over USB link
d80b5005 88 dev_addr MAC address of device's end of this
d5862ca6 89 Ethernet over USB link
d80b5005 90 =============== ==================================================
d5862ca6
AP
91
92and after creating the functions/ecm.<instance name> they contain default
93values: qmult is 5, dev_addr and host_addr are randomly selected.
94Except for ifname they can be written to until the function is linked to a
95configuration. The ifname is read-only and contains the name of the interface
96which was assigned by the net core, e. g. usb0.
97
98Testing the ECM function
99------------------------
100
101Configure IP addresses of the device and the host. Then:
102
d80b5005
MCC
103On the device::
104
105 ping <host's IP>
106
107On the host::
108
109 ping <device's IP>
7bfbc6e3
AP
110
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
d80b5005
MCC
122 =============== ==================================================
123 ifname network device interface name associated with this
7bfbc6e3 124 function instance
d80b5005
MCC
125 qmult queue length multiplier for high and super speed
126 host_addr MAC address of host's end of this
7bfbc6e3 127 Ethernet over USB link
d80b5005 128 dev_addr MAC address of device's end of this
7bfbc6e3 129 Ethernet over USB link
d80b5005 130 =============== ==================================================
7bfbc6e3
AP
131
132and after creating the functions/ecm.<instance name> they contain default
133values: qmult is 5, dev_addr and host_addr are randomly selected.
134Except for ifname they can be written to until the function is linked to a
135configuration. The ifname is read-only and contains the name of the interface
136which was assigned by the net core, e. g. usb0.
137
138Testing the ECM subset function
139-------------------------------
140
141Configure IP addresses of the device and the host. Then:
142
d80b5005
MCC
143On the device::
144
145 ping <host's IP>
146
147On the host::
148
149 ping <device's IP>
4ca560a6
AP
150
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
d80b5005
MCC
162 =============== ==================================================
163 ifname network device interface name associated with this
4ca560a6 164 function instance
d80b5005
MCC
165 qmult queue length multiplier for high and super speed
166 host_addr MAC address of host's end of this
4ca560a6 167 Ethernet over USB link
d80b5005 168 dev_addr MAC address of device's end of this
4ca560a6 169 Ethernet over USB link
d80b5005 170 =============== ==================================================
4ca560a6
AP
171
172and after creating the functions/eem.<instance name> they contain default
173values: qmult is 5, dev_addr and host_addr are randomly selected.
174Except for ifname they can be written to until the function is linked to a
175configuration. The ifname is read-only and contains the name of the interface
176which was assigned by the net core, e. g. usb0.
177
178Testing the EEM function
179------------------------
180
181Configure IP addresses of the device and the host. Then:
182
d80b5005
MCC
183On the device::
184
185 ping <host's IP>
186
187On the host::
188
189 ping <device's IP>
2c0f62f9
AP
190
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
d80b5005 212
2c0f62f9 213On the host: use the USB function provided by the device
f7e3c3cd
AP
214
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
d80b5005
MCC
226 =============== ===========================================
227 protocol HID protocol to use
228 report_desc data to be used in HID reports, except data
f7e3c3cd 229 passed with /dev/hidg<X>
d80b5005
MCC
230 report_length HID report length
231 subclass HID subclass to use
232 =============== ===========================================
f7e3c3cd
AP
233
234For a keyboard the protocol and the subclass are 1, the report_length is 8,
d80b5005 235while the report_desc is::
f7e3c3cd 236
d80b5005
MCC
237 $ 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
f7e3c3cd 243
d80b5005 244Such a sequence of bytes can be stored to the attribute with echo::
f7e3c3cd 245
d80b5005 246 $ echo -ne \\x05\\x01\\x09\\x06\\xa1.....
f7e3c3cd
AP
247
248Testing the HID function
249------------------------
250
251Device:
d80b5005 252
f7e3c3cd
AP
253- create the gadget
254- connect the gadget to a host, preferably not the one used
d80b5005 255 to control the gadget
f7e3c3cd 256- run a program which writes to /dev/hidg<N>, e.g.
ecefae6d 257 a userspace program found in Documentation/usb/gadget_hid.rst::
f7e3c3cd 258
d80b5005 259 $ ./hid_gadget_test /dev/hidg0 keyboard
f7e3c3cd
AP
260
261Host:
d80b5005 262
f7e3c3cd 263- observe the keystrokes from the gadget
ec91aff7
AP
264
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
d80b5005
MCC
276 =============== =======================
277 qlen depth of loopback queue
278 bulk_buflen buffer length
279 =============== =======================
ec91aff7
AP
280
281Testing the LOOPBACK function
282-----------------------------
283
284device: run the gadget
d80b5005 285
f811a383 286host: test-usb (tools/usb/testusb.c)
cdbe287d
AP
287
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
d80b5005
MCC
300 =============== ==============================================
301 stall Set to permit function to halt bulk endpoints.
cdbe287d
AP
302 Disabled on some USB devices known not to work
303 correctly. You should set it to true.
d80b5005 304 num_buffers Number of pipeline buffers. Valid numbers
cdbe287d
AP
305 are 2..4. Available only if
306 CONFIG_USB_GADGET_DEBUG_FILES is set.
d80b5005 307 =============== ==============================================
cdbe287d
AP
308
309and a default lun.0 directory corresponding to SCSI LUN #0.
310
d80b5005 311A new lun can be added with mkdir::
cdbe287d 312
d80b5005 313 $ mkdir functions/mass_storage.0/partition.5
cdbe287d
AP
314
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
d80b5005
MCC
323 =============== ==============================================
324 file The path to the backing file for the LUN.
cdbe287d 325 Required if LUN is not marked as removable.
d80b5005 326 ro Flag specifying access to the LUN shall be
cdbe287d
AP
327 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.
d80b5005 330 removable Flag specifying that LUN shall be indicated as
cdbe287d 331 being removable.
d80b5005 332 cdrom Flag specifying that LUN shall be reported as
cdbe287d 333 being a CD-ROM.
d80b5005 334 nofua Flag specifying that FUA flag
cdbe287d 335 in SCSI WRITE(10,12)
d80b5005 336 =============== ==============================================
cdbe287d
AP
337
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)
0d6be59a
AP
344
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
d80b5005
MCC
356 =============== ====================================
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 =============== ====================================
0d6be59a
AP
364
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
d80b5005
MCC
3711) Playing a mid from the gadget to the host:
372
373host::
0d6be59a 374
d80b5005
MCC
375 $ 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
0d6be59a 380
d80b5005 381gadget::
0d6be59a 382
d80b5005
MCC
383 $ aplaymidi -l
384 Port Client name Port name
385 20:0 f_midi f_midi
0d6be59a 386
d80b5005 387 $ aplaymidi -p 20:0 to_host.mid
0d6be59a
AP
388
3892) Playing a mid from the host to the gadget
0d6be59a 390
d80b5005
MCC
391gadget::
392
393 $ arecordmidi -l
394 Port Client name Port name
395 20:0 f_midi f_midi
0d6be59a 396
d80b5005 397 $ arecordmidi -p 20:0 from_host.mid
0d6be59a 398
d80b5005 399host::
0d6be59a 400
d80b5005
MCC
401 $ 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
0d6be59a 405
d80b5005 406 $ aplaymidi -p24:0 to_gadget.mid
0d6be59a
AP
407
408The from_gadget.mid should sound identical to the to_host.mid.
d80b5005 409
0d6be59a
AP
410The from_host.id should sound identical to the to_gadget.mid.
411
d80b5005 412MIDI files can be played to speakers/headphones with e.g. timidity installed::
0d6be59a 413
d80b5005
MCC
414 $ 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
0d6be59a 422
d80b5005 423 $ aplaymidi -p 128:0 file.mid
0d6be59a 424
d80b5005 425MIDI ports can be logically connected using the aconnect utility, e.g.::
0d6be59a 426
d80b5005 427 $ aconnect 24:0 128:0 # try it on the host
0d6be59a
AP
428
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.
4d0fa79e
AP
432
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
d80b5005
MCC
444 =============== ==================================================
445 ifname network device interface name associated with this
4d0fa79e 446 function instance
d80b5005
MCC
447 qmult queue length multiplier for high and super speed
448 host_addr MAC address of host's end of this
4d0fa79e 449 Ethernet over USB link
d80b5005 450 dev_addr MAC address of device's end of this
4d0fa79e 451 Ethernet over USB link
d80b5005 452 =============== ==================================================
4d0fa79e
AP
453
454and after creating the functions/ncm.<instance name> they contain default
455values: qmult is 5, dev_addr and host_addr are randomly selected.
456Except for ifname they can be written to until the function is linked to a
457configuration. The ifname is read-only and contains the name of the interface
458which was assigned by the net core, e. g. usb0.
459
460Testing the NCM function
461------------------------
462
463Configure IP addresses of the device and the host. Then:
464
d80b5005
MCC
465On the device::
466
467 ping <host's IP>
468
469On the host::
470
471 ping <device's IP>
d81b85dc
AP
472
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
d80b5005
MCC
493On 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>
d81b85dc
AP
501
502where seriald and serialc are Felipe's utilities found here:
503
d80b5005 504 https://github.com/felipebalbi/usb-tools.git master
da2907d2
AP
505
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
d80b5005
MCC
517 =============== ==================================================
518 ifname network device interface name associated with this
da2907d2 519 function instance
d80b5005 520 =============== ==================================================
da2907d2
AP
521
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
d80b5005 535On the host::
da2907d2 536
d80b5005
MCC
537 $ ./phonet -a 0x10 -i usbpn0
538 $ ./pnroute add 0x6c usbpn0
539 $./pnroute add 0x10 usbpn0
540 $ ifconfig usbpn0 up
da2907d2 541
d80b5005 542On the device::
da2907d2 543
d80b5005
MCC
544 $ ./phonet -a 0x6c -i upnlink0
545 $ ./pnroute add 0x10 upnlink0
546 $ ifconfig upnlink0 up
da2907d2 547
d80b5005 548Then a test program can be used::
da2907d2 549
d80b5005 550 http://www.spinics.net/lists/linux-usb/msg85690.html
da2907d2 551
d80b5005 552On the device::
da2907d2 553
d80b5005 554 $ ./pnxmit -a 0x6c -r
da2907d2 555
d80b5005 556On the host::
da2907d2 557
d80b5005 558 $ ./pnxmit -a 0x10 -s 0x6c
da2907d2
AP
559
560As a result some data should be sent from host to device.
561Then the other way round:
562
d80b5005 563On the host::
da2907d2 564
d80b5005 565 $ ./pnxmit -a 0x10 -r
da2907d2 566
d80b5005 567On the device::
da2907d2 568
d80b5005 569 $ ./pnxmit -a 0x6c -s 0x10
ddb72244
AP
570
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
d80b5005
MCC
582 =============== ==================================================
583 ifname network device interface name associated with this
ddb72244 584 function instance
d80b5005
MCC
585 qmult queue length multiplier for high and super speed
586 host_addr MAC address of host's end of this
ddb72244 587 Ethernet over USB link
d80b5005 588 dev_addr MAC address of device's end of this
ddb72244 589 Ethernet over USB link
d80b5005 590 =============== ==================================================
ddb72244
AP
591
592and after creating the functions/rndis.<instance name> they contain default
593values: qmult is 5, dev_addr and host_addr are randomly selected.
594Except for ifname they can be written to until the function is linked to a
595configuration. The ifname is read-only and contains the name of the interface
596which was assigned by the net core, e. g. usb0.
597
ddb72244
AP
598Testing the RNDIS function
599--------------------------
600
601Configure IP addresses of the device and the host. Then:
602
d80b5005
MCC
603On the device::
604
605 ping <host's IP>
606
607On the host::
608
609 ping <device's IP>
4dfcec8a
AP
610
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
d80b5005
MCC
631On 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>
4dfcec8a
AP
643
644then the other way round
645
d80b5005
MCC
646On target::
647
648 cat > /dev/ttyGS<Y>
649
650On host::
651
652 cat /dev/ttyUSB<X>
480a912b
AP
653
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
d80b5005
MCC
665 =============== ==================================
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 =============== ==================================
480a912b
AP
675
676Testing the SOURCESINK function
677-------------------------------
678
679device: run the gadget
d80b5005 680
f811a383 681host: test-usb (tools/usb/testusb.c)
480a912b 682
dae03586 683
d355339e 68416. UAC1 function (legacy implementation)
d80b5005 685=========================================
dae03586 686
d355339e 687The function is provided by usb_f_uac1_legacy.ko module.
dae03586
AP
688
689Function-specific configfs interface
690------------------------------------
691
d355339e
RB
692The function name to use when creating the function directory
693is "uac1_legacy".
dae03586
AP
694The uac1 function provides these attributes in its function directory:
695
d80b5005
MCC
696 =============== ====================================
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 =============== ====================================
dae03586
AP
704
705The attributes have sane default values.
706
707Testing the UAC1 function
708-------------------------
709
710device: run the gadget
d80b5005
MCC
711
712host::
713
714 aplay -l # should list our USB Audio Gadget
020c6f93
AP
715
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
d80b5005
MCC
727 =============== ====================================================
728 c_chmask capture channel mask
729 c_srate capture sampling rate
730 c_ssize capture sample size (bytes)
731 p_chmask playback channel mask
732 p_srate playback sampling rate
733 p_ssize playback sample size (bytes)
734 req_number the number of pre-allocated request for both capture
735 and playback
736 =============== ====================================================
020c6f93
AP
737
738The attributes have sane default values.
739
740Testing the UAC2 function
741-------------------------
742
743device: run the gadget
744host: aplay -l # should list our USB Audio Gadget
745
746This function does not require real hardware support, it just
747sends a stream of audio data to/from the host. In order to
748actually hear something at the device side, a command similar
d80b5005 749to this must be used at the device side::
020c6f93 750
d80b5005 751 $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
020c6f93 752
d80b5005 753e.g.::
020c6f93 754
d80b5005
MCC
755 $ arecord -f dat -t wav -D hw:CARD=UAC2Gadget,DEV=0 | \
756 aplay -D default:CARD=OdroidU3
9c4f538b
AP
757
75818. UVC function
759================
760
761The function is provided by usb_f_uvc.ko module.
762
763Function-specific configfs interface
764------------------------------------
765
766The function name to use when creating the function directory is "uvc".
767The uvc function provides these attributes in its function directory:
768
d80b5005
MCC
769 =================== ================================================
770 streaming_interval interval for polling endpoint for data transfers
771 streaming_maxburst bMaxBurst for super speed companion descriptor
772 streaming_maxpacket maximum packet size this endpoint is capable of
773 sending or receiving when this configuration is
774 selected
775 =================== ================================================
9c4f538b
AP
776
777There are also "control" and "streaming" subdirectories, each of which contain
778a number of their subdirectories. There are some sane defaults provided, but
779the user must provide the following:
780
d80b5005
MCC
781 ================== ====================================================
782 control header create in control/header, link from control/class/fs
783 and/or control/class/ss
784 streaming header create in streaming/header, link from
785 streaming/class/fs and/or streaming/class/hs and/or
786 streaming/class/ss
787 format description create in streaming/mjpeg and/or
788 streaming/uncompressed
789 frame description create in streaming/mjpeg/<format> and/or in
790 streaming/uncompressed/<format>
791 ================== ====================================================
9c4f538b
AP
792
793Each frame description contains frame interval specification, and each
794such specification consists of a number of lines with an inverval value
d80b5005
MCC
795in each line. The rules stated above are best illustrated with an example::
796
797 # mkdir functions/uvc.usb0/control/header/h
798 # cd functions/uvc.usb0/control/
799 # ln -s header/h class/fs
800 # ln -s header/h class/ss
801 # mkdir -p functions/uvc.usb0/streaming/uncompressed/u/360p
802 # cat <<EOF > functions/uvc.usb0/streaming/uncompressed/u/360p/dwFrameInterval
803 666666
804 1000000
805 5000000
806 EOF
807 # cd $GADGET_CONFIGFS_ROOT
808 # mkdir functions/uvc.usb0/streaming/header/h
809 # cd functions/uvc.usb0/streaming/header/h
810 # ln -s ../../uncompressed/u
811 # cd ../../class/fs
812 # ln -s ../../header/h
813 # cd ../../class/hs
814 # ln -s ../../header/h
815 # cd ../../class/ss
816 # ln -s ../../header/h
9c4f538b
AP
817
818
819Testing the UVC function
820------------------------
821
d80b5005 822device: run the gadget, modprobe vivid::
9c4f538b 823
d80b5005 824 # uvc-gadget -u /dev/video<uvc video node #> -v /dev/video<vivid video node #>
9c4f538b
AP
825
826where uvc-gadget is this program:
d80b5005 827 http://git.ideasonboard.org/uvc-gadget.git
9c4f538b
AP
828
829with these patches:
9c4f538b 830
d80b5005
MCC
831 http://www.spinics.net/lists/linux-usb/msg99220.html
832
833host::
834
835 luvcview -f yuv
ee1cd515
AP
836
83719. PRINTER function
838====================
839
840The function is provided by usb_f_printer.ko module.
841
842Function-specific configfs interface
843------------------------------------
844
845The function name to use when creating the function directory is "printer".
846The printer function provides these attributes in its function directory:
847
d80b5005
MCC
848 ========== ===========================================
849 pnp_string Data to be passed to the host in pnp string
850 q_len Number of requests per endpoint
851 ========== ===========================================
ee1cd515
AP
852
853Testing the PRINTER function
854----------------------------
855
856The most basic testing:
857
d80b5005
MCC
858device: run the gadget::
859
860 # ls -l /devices/virtual/usb_printer_gadget/
ee1cd515
AP
861
862should show g_printer<number>.
863
864If udev is active, then /dev/g_printer<number> should appear automatically.
865
866host:
867
868If udev is active, then e.g. /dev/usb/lp0 should appear.
869
870host->device transmission:
871
d80b5005 872device::
ee1cd515 873
d80b5005 874 # cat /dev/g_printer<number>
ee1cd515 875
d80b5005
MCC
876host::
877
878 # cat > /dev/usb/lp0
879
880device->host transmission::
881
882 # cat > /dev/g_printer<number>
883
884host::
885
886 # cat /dev/usb/lp0
ee1cd515
AP
887
888More advanced testing can be done with the prn_example
ecefae6d 889described in Documentation/usb/gadget_printer.rst.
0591bc23
RB
890
891
89220. UAC1 function (virtual ALSA card, using u_audio API)
d80b5005 893========================================================
0591bc23
RB
894
895The function is provided by usb_f_uac1.ko module.
896It will create a virtual ALSA card and the audio streams are simply
897sinked to and sourced from it.
898
899Function-specific configfs interface
900------------------------------------
901
902The function name to use when creating the function directory is "uac1".
903The uac1 function provides these attributes in its function directory:
904
d80b5005
MCC
905 ========== ====================================================
906 c_chmask capture channel mask
907 c_srate capture sampling rate
908 c_ssize capture sample size (bytes)
909 p_chmask playback channel mask
910 p_srate playback sampling rate
911 p_ssize playback sample size (bytes)
912 req_number the number of pre-allocated request for both capture
913 and playback
914 ========== ====================================================
0591bc23
RB
915
916The attributes have sane default values.
917
918Testing the UAC1 function
919-------------------------
920
921device: run the gadget
922host: aplay -l # should list our USB Audio Gadget
923
924This function does not require real hardware support, it just
925sends a stream of audio data to/from the host. In order to
926actually hear something at the device side, a command similar
d80b5005 927to this must be used at the device side::
0591bc23 928
d80b5005 929 $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
0591bc23 930
d80b5005 931e.g.::
0591bc23 932
d80b5005
MCC
933 $ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \
934 aplay -D default:CARD=OdroidU3