Documentation: usb: SOURCESINK function testing
[deliverable/linux.git] / Documentation / usb / gadget-testing.txt
CommitLineData
e38eb2c8
AP
1This file summarizes information on basic testing of USB functions
2provided by gadgets.
3
41. ACM function
d5862ca6 52. ECM function
7bfbc6e3 63. ECM subset function
4ca560a6 74. EEM function
2c0f62f9 85. FFS function
f7e3c3cd 96. HID function
ec91aff7 107. LOOPBACK function
cdbe287d 118. MASS STORAGE function
0d6be59a 129. MIDI function
4d0fa79e 1310. NCM function
d81b85dc 1411. OBEX function
da2907d2 1512. PHONET function
ddb72244 1613. RNDIS function
4dfcec8a 1714. SERIAL function
480a912b 1815. SOURCESINK function
e38eb2c8
AP
19
20
211. ACM function
22===============
23
24The function is provided by usb_f_acm.ko module.
25
26Function-specific configfs interface
27------------------------------------
28
29The function name to use when creating the function directory is "acm".
30The ACM function provides just one attribute in its function directory:
31
32 port_num
33
34The attribute is read-only.
35
36There can be at most 4 ACM/generic serial/OBEX ports in the system.
37
38
39Testing the ACM function
40------------------------
41
42On the host: cat > /dev/ttyACM<X>
43On the device : cat /dev/ttyGS<Y>
44
45then the other way round
46
47On the device: cat > /dev/ttyGS<Y>
48On the host: cat /dev/ttyACM<X>
d5862ca6
AP
49
502. ECM function
51===============
52
53The function is provided by usb_f_ecm.ko module.
54
55Function-specific configfs interface
56------------------------------------
57
58The function name to use when creating the function directory is "ecm".
59The ECM function provides these attributes in its function directory:
60
61 ifname - network device interface name associated with this
62 function instance
63 qmult - queue length multiplier for high and super speed
64 host_addr - MAC address of host's end of this
65 Ethernet over USB link
66 dev_addr - MAC address of device's end of this
67 Ethernet over USB link
68
69and after creating the functions/ecm.<instance name> they contain default
70values: qmult is 5, dev_addr and host_addr are randomly selected.
71Except for ifname they can be written to until the function is linked to a
72configuration. The ifname is read-only and contains the name of the interface
73which was assigned by the net core, e. g. usb0.
74
75Testing the ECM function
76------------------------
77
78Configure IP addresses of the device and the host. Then:
79
80On the device: ping <host's IP>
81On the host: ping <device's IP>
7bfbc6e3
AP
82
833. ECM subset function
84======================
85
86The function is provided by usb_f_ecm_subset.ko module.
87
88Function-specific configfs interface
89------------------------------------
90
91The function name to use when creating the function directory is "geth".
92The ECM subset function provides these attributes in its function directory:
93
94 ifname - network device interface name associated with this
95 function instance
96 qmult - queue length multiplier for high and super speed
97 host_addr - MAC address of host's end of this
98 Ethernet over USB link
99 dev_addr - MAC address of device's end of this
100 Ethernet over USB link
101
102and after creating the functions/ecm.<instance name> they contain default
103values: qmult is 5, dev_addr and host_addr are randomly selected.
104Except for ifname they can be written to until the function is linked to a
105configuration. The ifname is read-only and contains the name of the interface
106which was assigned by the net core, e. g. usb0.
107
108Testing the ECM subset function
109-------------------------------
110
111Configure IP addresses of the device and the host. Then:
112
113On the device: ping <host's IP>
114On the host: ping <device's IP>
4ca560a6
AP
115
1164. EEM function
117===============
118
119The function is provided by usb_f_eem.ko module.
120
121Function-specific configfs interface
122------------------------------------
123
124The function name to use when creating the function directory is "eem".
125The EEM function provides these attributes in its function directory:
126
127 ifname - network device interface name associated with this
128 function instance
129 qmult - queue length multiplier for high and super speed
130 host_addr - MAC address of host's end of this
131 Ethernet over USB link
132 dev_addr - MAC address of device's end of this
133 Ethernet over USB link
134
135and after creating the functions/eem.<instance name> they contain default
136values: qmult is 5, dev_addr and host_addr are randomly selected.
137Except for ifname they can be written to until the function is linked to a
138configuration. The ifname is read-only and contains the name of the interface
139which was assigned by the net core, e. g. usb0.
140
141Testing the EEM function
142------------------------
143
144Configure IP addresses of the device and the host. Then:
145
146On the device: ping <host's IP>
147On the host: ping <device's IP>
2c0f62f9
AP
148
1495. FFS function
150===============
151
152The function is provided by usb_f_fs.ko module.
153
154Function-specific configfs interface
155------------------------------------
156
157The function name to use when creating the function directory is "ffs".
158The function directory is intentionally empty and not modifiable.
159
160After creating the directory there is a new instance (a "device") of FunctionFS
161available in the system. Once a "device" is available, the user should follow
162the standard procedure for using FunctionFS (mount it, run the userspace
163process which implements the function proper). The gadget should be enabled
164by writing a suitable string to usb_gadget/<gadget>/UDC.
165
166Testing the FFS function
167------------------------
168
169On the device: start the function's userspace daemon, enable the gadget
170On the host: use the USB function provided by the device
f7e3c3cd
AP
171
1726. HID function
173===============
174
175The function is provided by usb_f_hid.ko module.
176
177Function-specific configfs interface
178------------------------------------
179
180The function name to use when creating the function directory is "hid".
181The HID function provides these attributes in its function directory:
182
183 protocol - HID protocol to use
184 report_desc - data to be used in HID reports, except data
185 passed with /dev/hidg<X>
186 report_length - HID report length
187 subclass - HID subclass to use
188
189For a keyboard the protocol and the subclass are 1, the report_length is 8,
190while the report_desc is:
191
192$ hd my_report_desc
19300000000 05 01 09 06 a1 01 05 07 19 e0 29 e7 15 00 25 01 |..........)...%.|
19400000010 75 01 95 08 81 02 95 01 75 08 81 03 95 05 75 01 |u.......u.....u.|
19500000020 05 08 19 01 29 05 91 02 95 01 75 03 91 03 95 06 |....).....u.....|
19600000030 75 08 15 00 25 65 05 07 19 00 29 65 81 00 c0 |u...%e....)e...|
1970000003f
198
199Such a sequence of bytes can be stored to the attribute with echo:
200
201$ echo -ne \\x05\\x01\\x09\\x06\\xa1.....
202
203Testing the HID function
204------------------------
205
206Device:
207- create the gadget
208- connect the gadget to a host, preferably not the one used
209to control the gadget
210- run a program which writes to /dev/hidg<N>, e.g.
211a userspace program found in Documentation/usb/gadget_hid.txt:
212
213$ ./hid_gadget_test /dev/hidg0 keyboard
214
215Host:
216- observe the keystrokes from the gadget
ec91aff7
AP
217
2187. LOOPBACK function
219====================
220
221The function is provided by usb_f_ss_lb.ko module.
222
223Function-specific configfs interface
224------------------------------------
225
226The function name to use when creating the function directory is "Loopback".
227The LOOPBACK function provides these attributes in its function directory:
228
229 qlen - depth of loopback queue
230 bulk_buflen - buffer length
231
232Testing the LOOPBACK function
233-----------------------------
234
235device: run the gadget
236host: test-usb
237
238http://www.linux-usb.org/usbtest/testusb.c
cdbe287d
AP
239
2408. MASS STORAGE function
241========================
242
243The function is provided by usb_f_mass_storage.ko module.
244
245Function-specific configfs interface
246------------------------------------
247
248The function name to use when creating the function directory is "mass_storage".
249The MASS STORAGE function provides these attributes in its directory:
250files:
251
252 stall - Set to permit function to halt bulk endpoints.
253 Disabled on some USB devices known not to work
254 correctly. You should set it to true.
255 num_buffers - Number of pipeline buffers. Valid numbers
256 are 2..4. Available only if
257 CONFIG_USB_GADGET_DEBUG_FILES is set.
258
259and a default lun.0 directory corresponding to SCSI LUN #0.
260
261A new lun can be added with mkdir:
262
263$ mkdir functions/mass_storage.0/partition.5
264
265Lun numbering does not have to be continuous, except for lun #0 which is
266created by default. A maximum of 8 luns can be specified and they all must be
267named following the <name>.<number> scheme. The numbers can be 0..8.
268Probably a good convention is to name the luns "lun.<number>",
269although it is not mandatory.
270
271In each lun directory there are the following attribute files:
272
273 file - The path to the backing file for the LUN.
274 Required if LUN is not marked as removable.
275 ro - Flag specifying access to the LUN shall be
276 read-only. This is implied if CD-ROM emulation
277 is enabled as well as when it was impossible
278 to open "filename" in R/W mode.
279 removable - Flag specifying that LUN shall be indicated as
280 being removable.
281 cdrom - Flag specifying that LUN shall be reported as
282 being a CD-ROM.
283 nofua - Flag specifying that FUA flag
284 in SCSI WRITE(10,12)
285
286Testing the MASS STORAGE function
287---------------------------------
288
289device: connect the gadget, enable it
290host: dmesg, see the USB drives appear (if system configured to automatically
291mount)
0d6be59a
AP
292
2939. MIDI function
294================
295
296The function is provided by usb_f_midi.ko module.
297
298Function-specific configfs interface
299------------------------------------
300
301The function name to use when creating the function directory is "midi".
302The MIDI function provides these attributes in its function directory:
303
304 buflen - MIDI buffer length
305 id - ID string for the USB MIDI adapter
306 in_ports - number of MIDI input ports
307 index - index value for the USB MIDI adapter
308 out_ports - number of MIDI output ports
309 qlen - USB read request queue length
310
311Testing the MIDI function
312-------------------------
313
314There are two cases: playing a mid from the gadget to
315the host and playing a mid from the host to the gadget.
316
3171) Playing a mid from the gadget to the host
318host)
319
320$ arecordmidi -l
321 Port Client name Port name
322 14:0 Midi Through Midi Through Port-0
323 24:0 MIDI Gadget MIDI Gadget MIDI 1
324$ arecordmidi -p 24:0 from_gadget.mid
325
326gadget)
327
328$ aplaymidi -l
329 Port Client name Port name
330 20:0 f_midi f_midi
331
332$ aplaymidi -p 20:0 to_host.mid
333
3342) Playing a mid from the host to the gadget
335gadget)
336
337$ arecordmidi -l
338 Port Client name Port name
339 20:0 f_midi f_midi
340
341$ arecordmidi -p 20:0 from_host.mid
342
343host)
344
345$ aplaymidi -l
346 Port Client name Port name
347 14:0 Midi Through Midi Through Port-0
348 24:0 MIDI Gadget MIDI Gadget MIDI 1
349
350$ aplaymidi -p24:0 to_gadget.mid
351
352The from_gadget.mid should sound identical to the to_host.mid.
353The from_host.id should sound identical to the to_gadget.mid.
354
355MIDI files can be played to speakers/headphones with e.g. timidity installed
356
357$ aplaymidi -l
358 Port Client name Port name
359 14:0 Midi Through Midi Through Port-0
360 24:0 MIDI Gadget MIDI Gadget MIDI 1
361128:0 TiMidity TiMidity port 0
362128:1 TiMidity TiMidity port 1
363128:2 TiMidity TiMidity port 2
364128:3 TiMidity TiMidity port 3
365
366$ aplaymidi -p 128:0 file.mid
367
368MIDI ports can be logically connected using the aconnect utility, e.g.:
369
370$ aconnect 24:0 128:0 # try it on the host
371
372After the gadget's MIDI port is connected to timidity's MIDI port,
373whatever is played at the gadget side with aplaymidi -l is audible
374in host's speakers/headphones.
4d0fa79e
AP
375
37610. NCM function
377================
378
379The function is provided by usb_f_ncm.ko module.
380
381Function-specific configfs interface
382------------------------------------
383
384The function name to use when creating the function directory is "ncm".
385The NCM function provides these attributes in its function directory:
386
387 ifname - network device interface name associated with this
388 function instance
389 qmult - queue length multiplier for high and super speed
390 host_addr - MAC address of host's end of this
391 Ethernet over USB link
392 dev_addr - MAC address of device's end of this
393 Ethernet over USB link
394
395and after creating the functions/ncm.<instance name> they contain default
396values: qmult is 5, dev_addr and host_addr are randomly selected.
397Except for ifname they can be written to until the function is linked to a
398configuration. The ifname is read-only and contains the name of the interface
399which was assigned by the net core, e. g. usb0.
400
401Testing the NCM function
402------------------------
403
404Configure IP addresses of the device and the host. Then:
405
406On the device: ping <host's IP>
407On the host: ping <device's IP>
d81b85dc
AP
408
40911. OBEX function
410=================
411
412The function is provided by usb_f_obex.ko module.
413
414Function-specific configfs interface
415------------------------------------
416
417The function name to use when creating the function directory is "obex".
418The OBEX function provides just one attribute in its function directory:
419
420 port_num
421
422The attribute is read-only.
423
424There can be at most 4 ACM/generic serial/OBEX ports in the system.
425
426Testing the OBEX function
427-------------------------
428
429On device: seriald -f /dev/ttyGS<Y> -s 1024
430On host: serialc -v <vendorID> -p <productID> -i<interface#> -a1 -s1024 \
431 -t<out endpoint addr> -r<in endpoint addr>
432
433where seriald and serialc are Felipe's utilities found here:
434
435https://git.gitorious.org/usb/usb-tools.git master
da2907d2
AP
436
43712. PHONET function
438===================
439
440The function is provided by usb_f_phonet.ko module.
441
442Function-specific configfs interface
443------------------------------------
444
445The function name to use when creating the function directory is "phonet".
446The PHONET function provides just one attribute in its function directory:
447
448 ifname - network device interface name associated with this
449 function instance
450
451Testing the PHONET function
452---------------------------
453
454It is not possible to test the SOCK_STREAM protocol without a specific piece
455of hardware, so only SOCK_DGRAM has been tested. For the latter to work,
456in the past I had to apply the patch mentioned here:
457
458http://www.spinics.net/lists/linux-usb/msg85689.html
459
460These tools are required:
461
462git://git.gitorious.org/meego-cellular/phonet-utils.git
463
464On the host:
465
466$ ./phonet -a 0x10 -i usbpn0
467$ ./pnroute add 0x6c usbpn0
468$./pnroute add 0x10 usbpn0
469$ ifconfig usbpn0 up
470
471On the device:
472
473$ ./phonet -a 0x6c -i upnlink0
474$ ./pnroute add 0x10 upnlink0
475$ ifconfig upnlink0 up
476
477Then a test program can be used:
478
479http://www.spinics.net/lists/linux-usb/msg85690.html
480
481On the device:
482
483$ ./pnxmit -a 0x6c -r
484
485On the host:
486
487$ ./pnxmit -a 0x10 -s 0x6c
488
489As a result some data should be sent from host to device.
490Then the other way round:
491
492On the host:
493
494$ ./pnxmit -a 0x10 -r
495
496On the device:
497
498$ ./pnxmit -a 0x6c -s 0x10
ddb72244
AP
499
50013. RNDIS function
501==================
502
503The function is provided by usb_f_rndis.ko module.
504
505Function-specific configfs interface
506------------------------------------
507
508The function name to use when creating the function directory is "rndis".
509The RNDIS function provides these attributes in its function directory:
510
511 ifname - network device interface name associated with this
512 function instance
513 qmult - queue length multiplier for high and super speed
514 host_addr - MAC address of host's end of this
515 Ethernet over USB link
516 dev_addr - MAC address of device's end of this
517 Ethernet over USB link
518
519and after creating the functions/rndis.<instance name> they contain default
520values: qmult is 5, dev_addr and host_addr are randomly selected.
521Except for ifname they can be written to until the function is linked to a
522configuration. The ifname is read-only and contains the name of the interface
523which was assigned by the net core, e. g. usb0.
524
525By default there can be only 1 RNDIS interface in the system.
526
527Testing the RNDIS function
528--------------------------
529
530Configure IP addresses of the device and the host. Then:
531
532On the device: ping <host's IP>
533On the host: ping <device's IP>
4dfcec8a
AP
534
53514. SERIAL function
536===================
537
538The function is provided by usb_f_gser.ko module.
539
540Function-specific configfs interface
541------------------------------------
542
543The function name to use when creating the function directory is "gser".
544The SERIAL function provides just one attribute in its function directory:
545
546 port_num
547
548The attribute is read-only.
549
550There can be at most 4 ACM/generic serial/OBEX ports in the system.
551
552Testing the SERIAL function
553---------------------------
554
555On host: insmod usbserial
556 echo VID PID >/sys/bus/usb-serial/drivers/generic/new_id
557On host: cat > /dev/ttyUSB<X>
558On target: cat /dev/ttyGS<Y>
559
560then the other way round
561
562On target: cat > /dev/ttyGS<Y>
563On host: cat /dev/ttyUSB<X>
480a912b
AP
564
56515. SOURCESINK function
566=======================
567
568The function is provided by usb_f_ss_lb.ko module.
569
570Function-specific configfs interface
571------------------------------------
572
573The function name to use when creating the function directory is "SourceSink".
574The SOURCESINK function provides these attributes in its function directory:
575
576 pattern - 0 (all zeros), 1 (mod63), 2 (none)
577 isoc_interval - 1..16
578 isoc_maxpacket - 0 - 1023 (fs), 0 - 1024 (hs/ss)
579 isoc_mult - 0..2 (hs/ss only)
580 isoc_maxburst - 0..15 (ss only)
581 bulk_buflen - buffer length
582
583Testing the SOURCESINK function
584-------------------------------
585
586device: run the gadget
587host: test-usb
588
589http://www.linux-usb.org/usbtest/testusb.c
This page took 0.048168 seconds and 5 git commands to generate.