Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[cascardo/linux.git] / Documentation / usb / gadget-testing.txt
1 This file summarizes information on basic testing of USB functions
2 provided by gadgets.
3
4 1. ACM function
5 2. ECM function
6 3. ECM subset function
7 4. EEM function
8 5. FFS function
9 6. HID function
10 7. LOOPBACK function
11 8. MASS STORAGE function
12 9. MIDI function
13 10. NCM function
14 11. OBEX function
15 12. PHONET function
16 13. RNDIS function
17 14. SERIAL function
18 15. SOURCESINK function
19 16. UAC1 function
20 17. UAC2 function
21 18. UVC function
22 19. PRINTER function
23
24
25 1. ACM function
26 ===============
27
28 The function is provided by usb_f_acm.ko module.
29
30 Function-specific configfs interface
31 ------------------------------------
32
33 The function name to use when creating the function directory is "acm".
34 The ACM function provides just one attribute in its function directory:
35
36         port_num
37
38 The attribute is read-only.
39
40 There can be at most 4 ACM/generic serial/OBEX ports in the system.
41
42
43 Testing the ACM function
44 ------------------------
45
46 On the host: cat > /dev/ttyACM<X>
47 On the device : cat /dev/ttyGS<Y>
48
49 then the other way round
50
51 On the device: cat > /dev/ttyGS<Y>
52 On the host: cat /dev/ttyACM<X>
53
54 2. ECM function
55 ===============
56
57 The function is provided by usb_f_ecm.ko module.
58
59 Function-specific configfs interface
60 ------------------------------------
61
62 The function name to use when creating the function directory is "ecm".
63 The ECM function provides these attributes in its function directory:
64
65         ifname          - network device interface name associated with this
66                         function instance
67         qmult           - queue length multiplier for high and super speed
68         host_addr       - MAC address of host's end of this
69                         Ethernet over USB link
70         dev_addr        - MAC address of device's end of this
71                         Ethernet over USB link
72
73 and after creating the functions/ecm.<instance name> they contain default
74 values: qmult is 5, dev_addr and host_addr are randomly selected.
75 Except for ifname they can be written to until the function is linked to a
76 configuration. The ifname is read-only and contains the name of the interface
77 which was assigned by the net core, e. g. usb0.
78
79 Testing the ECM function
80 ------------------------
81
82 Configure IP addresses of the device and the host. Then:
83
84 On the device: ping <host's IP>
85 On the host: ping <device's IP>
86
87 3. ECM subset function
88 ======================
89
90 The function is provided by usb_f_ecm_subset.ko module.
91
92 Function-specific configfs interface
93 ------------------------------------
94
95 The function name to use when creating the function directory is "geth".
96 The ECM subset function provides these attributes in its function directory:
97
98         ifname          - network device interface name associated with this
99                         function instance
100         qmult           - queue length multiplier for high and super speed
101         host_addr       - MAC address of host's end of this
102                         Ethernet over USB link
103         dev_addr        - MAC address of device's end of this
104                         Ethernet over USB link
105
106 and after creating the functions/ecm.<instance name> they contain default
107 values: qmult is 5, dev_addr and host_addr are randomly selected.
108 Except for ifname they can be written to until the function is linked to a
109 configuration. The ifname is read-only and contains the name of the interface
110 which was assigned by the net core, e. g. usb0.
111
112 Testing the ECM subset function
113 -------------------------------
114
115 Configure IP addresses of the device and the host. Then:
116
117 On the device: ping <host's IP>
118 On the host: ping <device's IP>
119
120 4. EEM function
121 ===============
122
123 The function is provided by usb_f_eem.ko module.
124
125 Function-specific configfs interface
126 ------------------------------------
127
128 The function name to use when creating the function directory is "eem".
129 The EEM function provides these attributes in its function directory:
130
131         ifname          - network device interface name associated with this
132                         function instance
133         qmult           - queue length multiplier for high and super speed
134         host_addr       - MAC address of host's end of this
135                         Ethernet over USB link
136         dev_addr        - MAC address of device's end of this
137                         Ethernet over USB link
138
139 and after creating the functions/eem.<instance name> they contain default
140 values: qmult is 5, dev_addr and host_addr are randomly selected.
141 Except for ifname they can be written to until the function is linked to a
142 configuration. The ifname is read-only and contains the name of the interface
143 which was assigned by the net core, e. g. usb0.
144
145 Testing the EEM function
146 ------------------------
147
148 Configure IP addresses of the device and the host. Then:
149
150 On the device: ping <host's IP>
151 On the host: ping <device's IP>
152
153 5. FFS function
154 ===============
155
156 The function is provided by usb_f_fs.ko module.
157
158 Function-specific configfs interface
159 ------------------------------------
160
161 The function name to use when creating the function directory is "ffs".
162 The function directory is intentionally empty and not modifiable.
163
164 After creating the directory there is a new instance (a "device") of FunctionFS
165 available in the system. Once a "device" is available, the user should follow
166 the standard procedure for using FunctionFS (mount it, run the userspace
167 process which implements the function proper). The gadget should be enabled
168 by writing a suitable string to usb_gadget/<gadget>/UDC.
169
170 Testing the FFS function
171 ------------------------
172
173 On the device: start the function's userspace daemon, enable the gadget
174 On the host: use the USB function provided by the device
175
176 6. HID function
177 ===============
178
179 The function is provided by usb_f_hid.ko module.
180
181 Function-specific configfs interface
182 ------------------------------------
183
184 The function name to use when creating the function directory is "hid".
185 The HID function provides these attributes in its function directory:
186
187         protocol        - HID protocol to use
188         report_desc     - data to be used in HID reports, except data
189                         passed with /dev/hidg<X>
190         report_length   - HID report length
191         subclass        - HID subclass to use
192
193 For a keyboard the protocol and the subclass are 1, the report_length is 8,
194 while the report_desc is:
195
196 $ hd my_report_desc
197 00000000  05 01 09 06 a1 01 05 07  19 e0 29 e7 15 00 25 01  |..........)...%.|
198 00000010  75 01 95 08 81 02 95 01  75 08 81 03 95 05 75 01  |u.......u.....u.|
199 00000020  05 08 19 01 29 05 91 02  95 01 75 03 91 03 95 06  |....).....u.....|
200 00000030  75 08 15 00 25 65 05 07  19 00 29 65 81 00 c0     |u...%e....)e...|
201 0000003f
202
203 Such a sequence of bytes can be stored to the attribute with echo:
204
205 $ echo -ne \\x05\\x01\\x09\\x06\\xa1.....
206
207 Testing the HID function
208 ------------------------
209
210 Device:
211 - create the gadget
212 - connect the gadget to a host, preferably not the one used
213 to control the gadget
214 - run a program which writes to /dev/hidg<N>, e.g.
215 a userspace program found in Documentation/usb/gadget_hid.txt:
216
217 $ ./hid_gadget_test /dev/hidg0 keyboard
218
219 Host:
220 - observe the keystrokes from the gadget
221
222 7. LOOPBACK function
223 ====================
224
225 The function is provided by usb_f_ss_lb.ko module.
226
227 Function-specific configfs interface
228 ------------------------------------
229
230 The function name to use when creating the function directory is "Loopback".
231 The LOOPBACK function provides these attributes in its function directory:
232
233         qlen            - depth of loopback queue
234         bulk_buflen     - buffer length
235
236 Testing the LOOPBACK function
237 -----------------------------
238
239 device: run the gadget
240 host: test-usb
241
242 http://www.linux-usb.org/usbtest/testusb.c
243
244 8. MASS STORAGE function
245 ========================
246
247 The function is provided by usb_f_mass_storage.ko module.
248
249 Function-specific configfs interface
250 ------------------------------------
251
252 The function name to use when creating the function directory is "mass_storage".
253 The MASS STORAGE function provides these attributes in its directory:
254 files:
255
256         stall           - Set to permit function to halt bulk endpoints.
257                         Disabled on some USB devices known not to work
258                         correctly. You should set it to true.
259         num_buffers     - Number of pipeline buffers. Valid numbers
260                         are 2..4. Available only if
261                         CONFIG_USB_GADGET_DEBUG_FILES is set.
262
263 and a default lun.0 directory corresponding to SCSI LUN #0.
264
265 A new lun can be added with mkdir:
266
267 $ mkdir functions/mass_storage.0/partition.5
268
269 Lun numbering does not have to be continuous, except for lun #0 which is
270 created by default. A maximum of 8 luns can be specified and they all must be
271 named following the <name>.<number> scheme. The numbers can be 0..8.
272 Probably a good convention is to name the luns "lun.<number>",
273 although it is not mandatory.
274
275 In each lun directory there are the following attribute files:
276
277         file            - The path to the backing file for the LUN.
278                         Required if LUN is not marked as removable.
279         ro              - Flag specifying access to the LUN shall be
280                         read-only. This is implied if CD-ROM emulation
281                         is enabled as well as when it was impossible
282                         to open "filename" in R/W mode.
283         removable       - Flag specifying that LUN shall be indicated as
284                         being removable.
285         cdrom           - Flag specifying that LUN shall be reported as
286                         being a CD-ROM.
287         nofua           - Flag specifying that FUA flag
288                         in SCSI WRITE(10,12)
289
290 Testing the MASS STORAGE function
291 ---------------------------------
292
293 device: connect the gadget, enable it
294 host: dmesg, see the USB drives appear (if system configured to automatically
295 mount)
296
297 9. MIDI function
298 ================
299
300 The function is provided by usb_f_midi.ko module.
301
302 Function-specific configfs interface
303 ------------------------------------
304
305 The function name to use when creating the function directory is "midi".
306 The MIDI function provides these attributes in its function directory:
307
308         buflen          - MIDI buffer length
309         id              - ID string for the USB MIDI adapter
310         in_ports        - number of MIDI input ports
311         index           - index value for the USB MIDI adapter
312         out_ports       - number of MIDI output ports
313         qlen            - USB read request queue length
314
315 Testing the MIDI function
316 -------------------------
317
318 There are two cases: playing a mid from the gadget to
319 the host and playing a mid from the host to the gadget.
320
321 1) Playing a mid from the gadget to the host
322 host)
323
324 $ arecordmidi -l
325  Port    Client name                      Port name
326  14:0    Midi Through                     Midi Through Port-0
327  24:0    MIDI Gadget                      MIDI Gadget MIDI 1
328 $ arecordmidi -p 24:0 from_gadget.mid
329
330 gadget)
331
332 $ aplaymidi -l
333  Port    Client name                      Port name
334  20:0    f_midi                           f_midi
335
336 $ aplaymidi -p 20:0 to_host.mid
337
338 2) Playing a mid from the host to the gadget
339 gadget)
340
341 $ arecordmidi -l
342  Port    Client name                      Port name
343  20:0    f_midi                           f_midi
344
345 $ arecordmidi -p 20:0 from_host.mid
346
347 host)
348
349 $ aplaymidi -l
350  Port    Client name                      Port name
351  14:0    Midi Through                     Midi Through Port-0
352  24:0    MIDI Gadget                      MIDI Gadget MIDI 1
353
354 $ aplaymidi -p24:0 to_gadget.mid
355
356 The from_gadget.mid should sound identical to the to_host.mid.
357 The from_host.id should sound identical to the to_gadget.mid.
358
359 MIDI files can be played to speakers/headphones with e.g. timidity installed
360
361 $ aplaymidi -l
362  Port    Client name                      Port name
363  14:0    Midi Through                     Midi Through Port-0
364  24:0    MIDI Gadget                      MIDI Gadget MIDI 1
365 128:0    TiMidity                         TiMidity port 0
366 128:1    TiMidity                         TiMidity port 1
367 128:2    TiMidity                         TiMidity port 2
368 128:3    TiMidity                         TiMidity port 3
369
370 $ aplaymidi -p 128:0 file.mid
371
372 MIDI ports can be logically connected using the aconnect utility, e.g.:
373
374 $ aconnect 24:0 128:0 # try it on the host
375
376 After the gadget's MIDI port is connected to timidity's MIDI port,
377 whatever is played at the gadget side with aplaymidi -l is audible
378 in host's speakers/headphones.
379
380 10. NCM function
381 ================
382
383 The function is provided by usb_f_ncm.ko module.
384
385 Function-specific configfs interface
386 ------------------------------------
387
388 The function name to use when creating the function directory is "ncm".
389 The NCM function provides these attributes in its function directory:
390
391         ifname          - network device interface name associated with this
392                         function instance
393         qmult           - queue length multiplier for high and super speed
394         host_addr       - MAC address of host's end of this
395                         Ethernet over USB link
396         dev_addr        - MAC address of device's end of this
397                         Ethernet over USB link
398
399 and after creating the functions/ncm.<instance name> they contain default
400 values: qmult is 5, dev_addr and host_addr are randomly selected.
401 Except for ifname they can be written to until the function is linked to a
402 configuration. The ifname is read-only and contains the name of the interface
403 which was assigned by the net core, e. g. usb0.
404
405 Testing the NCM function
406 ------------------------
407
408 Configure IP addresses of the device and the host. Then:
409
410 On the device: ping <host's IP>
411 On the host: ping <device's IP>
412
413 11. OBEX function
414 =================
415
416 The function is provided by usb_f_obex.ko module.
417
418 Function-specific configfs interface
419 ------------------------------------
420
421 The function name to use when creating the function directory is "obex".
422 The OBEX function provides just one attribute in its function directory:
423
424         port_num
425
426 The attribute is read-only.
427
428 There can be at most 4 ACM/generic serial/OBEX ports in the system.
429
430 Testing the OBEX function
431 -------------------------
432
433 On device: seriald -f /dev/ttyGS<Y> -s 1024
434 On host: serialc -v <vendorID> -p <productID> -i<interface#> -a1 -s1024 \
435              -t<out endpoint addr> -r<in endpoint addr>
436
437 where seriald and serialc are Felipe's utilities found here:
438
439 https://git.gitorious.org/usb/usb-tools.git master
440
441 12. PHONET function
442 ===================
443
444 The function is provided by usb_f_phonet.ko module.
445
446 Function-specific configfs interface
447 ------------------------------------
448
449 The function name to use when creating the function directory is "phonet".
450 The PHONET function provides just one attribute in its function directory:
451
452         ifname          - network device interface name associated with this
453                         function instance
454
455 Testing the PHONET function
456 ---------------------------
457
458 It is not possible to test the SOCK_STREAM protocol without a specific piece
459 of hardware, so only SOCK_DGRAM has been tested. For the latter to work,
460 in the past I had to apply the patch mentioned here:
461
462 http://www.spinics.net/lists/linux-usb/msg85689.html
463
464 These tools are required:
465
466 git://git.gitorious.org/meego-cellular/phonet-utils.git
467
468 On the host:
469
470 $ ./phonet -a 0x10 -i usbpn0
471 $ ./pnroute add 0x6c usbpn0
472 $./pnroute add 0x10 usbpn0
473 $ ifconfig usbpn0 up
474
475 On the device:
476
477 $ ./phonet -a 0x6c -i upnlink0
478 $ ./pnroute add 0x10 upnlink0
479 $ ifconfig upnlink0 up
480
481 Then a test program can be used:
482
483 http://www.spinics.net/lists/linux-usb/msg85690.html
484
485 On the device:
486
487 $ ./pnxmit -a 0x6c -r
488
489 On the host:
490
491 $ ./pnxmit -a 0x10 -s 0x6c
492
493 As a result some data should be sent from host to device.
494 Then the other way round:
495
496 On the host:
497
498 $ ./pnxmit -a 0x10 -r
499
500 On the device:
501
502 $ ./pnxmit -a 0x6c -s 0x10
503
504 13. RNDIS function
505 ==================
506
507 The function is provided by usb_f_rndis.ko module.
508
509 Function-specific configfs interface
510 ------------------------------------
511
512 The function name to use when creating the function directory is "rndis".
513 The RNDIS function provides these attributes in its function directory:
514
515         ifname          - network device interface name associated with this
516                         function instance
517         qmult           - queue length multiplier for high and super speed
518         host_addr       - MAC address of host's end of this
519                         Ethernet over USB link
520         dev_addr        - MAC address of device's end of this
521                         Ethernet over USB link
522
523 and after creating the functions/rndis.<instance name> they contain default
524 values: qmult is 5, dev_addr and host_addr are randomly selected.
525 Except for ifname they can be written to until the function is linked to a
526 configuration. The ifname is read-only and contains the name of the interface
527 which was assigned by the net core, e. g. usb0.
528
529 Testing the RNDIS function
530 --------------------------
531
532 Configure IP addresses of the device and the host. Then:
533
534 On the device: ping <host's IP>
535 On the host: ping <device's IP>
536
537 14. SERIAL function
538 ===================
539
540 The function is provided by usb_f_gser.ko module.
541
542 Function-specific configfs interface
543 ------------------------------------
544
545 The function name to use when creating the function directory is "gser".
546 The SERIAL function provides just one attribute in its function directory:
547
548         port_num
549
550 The attribute is read-only.
551
552 There can be at most 4 ACM/generic serial/OBEX ports in the system.
553
554 Testing the SERIAL function
555 ---------------------------
556
557 On host: insmod usbserial
558          echo VID PID >/sys/bus/usb-serial/drivers/generic/new_id
559 On host: cat > /dev/ttyUSB<X>
560 On target: cat /dev/ttyGS<Y>
561
562 then the other way round
563
564 On target: cat > /dev/ttyGS<Y>
565 On host: cat /dev/ttyUSB<X>
566
567 15. SOURCESINK function
568 =======================
569
570 The function is provided by usb_f_ss_lb.ko module.
571
572 Function-specific configfs interface
573 ------------------------------------
574
575 The function name to use when creating the function directory is "SourceSink".
576 The SOURCESINK function provides these attributes in its function directory:
577
578         pattern         - 0 (all zeros), 1 (mod63), 2 (none)
579         isoc_interval   - 1..16
580         isoc_maxpacket  - 0 - 1023 (fs), 0 - 1024 (hs/ss)
581         isoc_mult       - 0..2 (hs/ss only)
582         isoc_maxburst   - 0..15 (ss only)
583         bulk_buflen     - buffer length
584
585 Testing the SOURCESINK function
586 -------------------------------
587
588 device: run the gadget
589 host: test-usb
590
591 http://www.linux-usb.org/usbtest/testusb.c
592
593 16. UAC1 function
594 =================
595
596 The function is provided by usb_f_uac1.ko module.
597
598 Function-specific configfs interface
599 ------------------------------------
600
601 The function name to use when creating the function directory is "uac1".
602 The uac1 function provides these attributes in its function directory:
603
604         audio_buf_size - audio buffer size
605         fn_cap - capture pcm device file name
606         fn_cntl - control device file name
607         fn_play - playback pcm device file name
608         req_buf_size - ISO OUT endpoint request buffer size
609         req_count - ISO OUT endpoint request count
610
611 The attributes have sane default values.
612
613 Testing the UAC1 function
614 -------------------------
615
616 device: run the gadget
617 host: aplay -l # should list our USB Audio Gadget
618
619 17. UAC2 function
620 =================
621
622 The function is provided by usb_f_uac2.ko module.
623
624 Function-specific configfs interface
625 ------------------------------------
626
627 The function name to use when creating the function directory is "uac2".
628 The uac2 function provides these attributes in its function directory:
629
630         c_chmask - capture channel mask
631         c_srate - capture sampling rate
632         c_ssize - capture sample size (bytes)
633         p_chmask - playback channel mask
634         p_srate - playback sampling rate
635         p_ssize - playback sample size (bytes)
636
637 The attributes have sane default values.
638
639 Testing the UAC2 function
640 -------------------------
641
642 device: run the gadget
643 host: aplay -l # should list our USB Audio Gadget
644
645 This function does not require real hardware support, it just
646 sends a stream of audio data to/from the host. In order to
647 actually hear something at the device side, a command similar
648 to this must be used at the device side:
649
650 $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
651
652 e.g.:
653
654 $ arecord -f dat -t wav -D hw:CARD=UAC2Gadget,DEV=0 | \
655 aplay -D default:CARD=OdroidU3
656
657 18. UVC function
658 ================
659
660 The function is provided by usb_f_uvc.ko module.
661
662 Function-specific configfs interface
663 ------------------------------------
664
665 The function name to use when creating the function directory is "uvc".
666 The uvc function provides these attributes in its function directory:
667
668         streaming_interval - interval for polling endpoint for data transfers
669         streaming_maxburst - bMaxBurst for super speed companion descriptor
670         streaming_maxpacket - maximum packet size this endpoint is capable of
671                               sending or receiving when this configuration is
672                               selected
673
674 There are also "control" and "streaming" subdirectories, each of which contain
675 a number of their subdirectories. There are some sane defaults provided, but
676 the user must provide the following:
677
678         control header - create in control/header, link from control/class/fs
679                         and/or control/class/ss
680         streaming header - create in streaming/header, link from
681                         streaming/class/fs and/or streaming/class/hs and/or
682                         streaming/class/ss
683         format description - create in streaming/mjpeg and/or
684                         streaming/uncompressed
685         frame description - create in streaming/mjpeg/<format> and/or in
686                         streaming/uncompressed/<format>
687
688 Each frame description contains frame interval specification, and each
689 such specification consists of a number of lines with an inverval value
690 in each line. The rules stated above are best illustrated with an example:
691
692 # mkdir functions/uvc.usb0/control/header/h
693 # cd functions/uvc.usb0/control/header/h
694 # ln -s header/h class/fs
695 # ln -s header/h class/ss
696 # mkdir -p functions/uvc.usb0/streaming/uncompressed/u/360p
697 # cat <<EOF > functions/uvc.usb0/streaming/uncompressed/u/360p/dwFrameInterval
698 666666
699 1000000
700 5000000
701 EOF
702 # cd $GADGET_CONFIGFS_ROOT
703 # mkdir functions/uvc.usb0/streaming/header/h
704 # cd functions/uvc.usb0/streaming/header/h
705 # ln -s ../../uncompressed/u
706 # cd ../../class/fs
707 # ln -s ../../header/h
708 # cd ../../class/hs
709 # ln -s ../../header/h
710 # cd ../../class/ss
711 # ln -s ../../header/h
712
713
714 Testing the UVC function
715 ------------------------
716
717 device: run the gadget, modprobe vivid
718
719 # uvc-gadget -u /dev/video<uvc video node #> -v /dev/video<vivid video node #>
720
721 where uvc-gadget is this program:
722 http://git.ideasonboard.org/uvc-gadget.git
723
724 with these patches:
725 http://www.spinics.net/lists/linux-usb/msg99220.html
726
727 host: luvcview -f yuv
728
729 19. PRINTER function
730 ====================
731
732 The function is provided by usb_f_printer.ko module.
733
734 Function-specific configfs interface
735 ------------------------------------
736
737 The function name to use when creating the function directory is "printer".
738 The printer function provides these attributes in its function directory:
739
740         pnp_string      - Data to be passed to the host in pnp string
741         q_len           - Number of requests per endpoint
742
743 Testing the PRINTER function
744 ----------------------------
745
746 The most basic testing:
747
748 device: run the gadget
749 # ls -l /devices/virtual/usb_printer_gadget/
750
751 should show g_printer<number>.
752
753 If udev is active, then /dev/g_printer<number> should appear automatically.
754
755 host:
756
757 If udev is active, then e.g. /dev/usb/lp0 should appear.
758
759 host->device transmission:
760
761 device:
762 # cat /dev/g_printer<number>
763 host:
764 # cat > /dev/usb/lp0
765
766 device->host transmission:
767
768 # cat > /dev/g_printer<number>
769 host:
770 # cat /dev/usb/lp0
771
772 More advanced testing can be done with the prn_example
773 described in Documentation/usb/gadget-printer.txt.