Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v4.1-rc1 775 lines 23 kB view raw
1This file summarizes information on basic testing of USB functions 2provided by gadgets. 3 41. ACM function 52. ECM function 63. ECM subset function 74. EEM function 85. FFS function 96. HID function 107. LOOPBACK function 118. MASS STORAGE function 129. MIDI function 1310. NCM function 1411. OBEX function 1512. PHONET function 1613. RNDIS function 1714. SERIAL function 1815. SOURCESINK function 1916. UAC1 function 2017. UAC2 function 2118. UVC function 2219. PRINTER function 23 24 251. ACM function 26=============== 27 28The function is provided by usb_f_acm.ko module. 29 30Function-specific configfs interface 31------------------------------------ 32 33The function name to use when creating the function directory is "acm". 34The ACM function provides just one attribute in its function directory: 35 36 port_num 37 38The attribute is read-only. 39 40There can be at most 4 ACM/generic serial/OBEX ports in the system. 41 42 43Testing the ACM function 44------------------------ 45 46On the host: cat > /dev/ttyACM<X> 47On the device : cat /dev/ttyGS<Y> 48 49then the other way round 50 51On the device: cat > /dev/ttyGS<Y> 52On the host: cat /dev/ttyACM<X> 53 542. ECM function 55=============== 56 57The function is provided by usb_f_ecm.ko module. 58 59Function-specific configfs interface 60------------------------------------ 61 62The function name to use when creating the function directory is "ecm". 63The 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 73and after creating the functions/ecm.<instance name> they contain default 74values: qmult is 5, dev_addr and host_addr are randomly selected. 75Except for ifname they can be written to until the function is linked to a 76configuration. The ifname is read-only and contains the name of the interface 77which was assigned by the net core, e. g. usb0. 78 79Testing the ECM function 80------------------------ 81 82Configure IP addresses of the device and the host. Then: 83 84On the device: ping <host's IP> 85On the host: ping <device's IP> 86 873. ECM subset function 88====================== 89 90The function is provided by usb_f_ecm_subset.ko module. 91 92Function-specific configfs interface 93------------------------------------ 94 95The function name to use when creating the function directory is "geth". 96The 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 106and after creating the functions/ecm.<instance name> they contain default 107values: qmult is 5, dev_addr and host_addr are randomly selected. 108Except for ifname they can be written to until the function is linked to a 109configuration. The ifname is read-only and contains the name of the interface 110which was assigned by the net core, e. g. usb0. 111 112Testing the ECM subset function 113------------------------------- 114 115Configure IP addresses of the device and the host. Then: 116 117On the device: ping <host's IP> 118On the host: ping <device's IP> 119 1204. EEM function 121=============== 122 123The function is provided by usb_f_eem.ko module. 124 125Function-specific configfs interface 126------------------------------------ 127 128The function name to use when creating the function directory is "eem". 129The 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 139and after creating the functions/eem.<instance name> they contain default 140values: qmult is 5, dev_addr and host_addr are randomly selected. 141Except for ifname they can be written to until the function is linked to a 142configuration. The ifname is read-only and contains the name of the interface 143which was assigned by the net core, e. g. usb0. 144 145Testing the EEM function 146------------------------ 147 148Configure IP addresses of the device and the host. Then: 149 150On the device: ping <host's IP> 151On the host: ping <device's IP> 152 1535. FFS function 154=============== 155 156The function is provided by usb_f_fs.ko module. 157 158Function-specific configfs interface 159------------------------------------ 160 161The function name to use when creating the function directory is "ffs". 162The function directory is intentionally empty and not modifiable. 163 164After creating the directory there is a new instance (a "device") of FunctionFS 165available in the system. Once a "device" is available, the user should follow 166the standard procedure for using FunctionFS (mount it, run the userspace 167process which implements the function proper). The gadget should be enabled 168by writing a suitable string to usb_gadget/<gadget>/UDC. 169 170Testing the FFS function 171------------------------ 172 173On the device: start the function's userspace daemon, enable the gadget 174On the host: use the USB function provided by the device 175 1766. HID function 177=============== 178 179The function is provided by usb_f_hid.ko module. 180 181Function-specific configfs interface 182------------------------------------ 183 184The function name to use when creating the function directory is "hid". 185The 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 193For a keyboard the protocol and the subclass are 1, the report_length is 8, 194while the report_desc is: 195 196$ hd my_report_desc 19700000000 05 01 09 06 a1 01 05 07 19 e0 29 e7 15 00 25 01 |..........)...%.| 19800000010 75 01 95 08 81 02 95 01 75 08 81 03 95 05 75 01 |u.......u.....u.| 19900000020 05 08 19 01 29 05 91 02 95 01 75 03 91 03 95 06 |....).....u.....| 20000000030 75 08 15 00 25 65 05 07 19 00 29 65 81 00 c0 |u...%e....)e...| 2010000003f 202 203Such a sequence of bytes can be stored to the attribute with echo: 204 205$ echo -ne \\x05\\x01\\x09\\x06\\xa1..... 206 207Testing the HID function 208------------------------ 209 210Device: 211- create the gadget 212- connect the gadget to a host, preferably not the one used 213to control the gadget 214- run a program which writes to /dev/hidg<N>, e.g. 215a userspace program found in Documentation/usb/gadget_hid.txt: 216 217$ ./hid_gadget_test /dev/hidg0 keyboard 218 219Host: 220- observe the keystrokes from the gadget 221 2227. LOOPBACK function 223==================== 224 225The function is provided by usb_f_ss_lb.ko module. 226 227Function-specific configfs interface 228------------------------------------ 229 230The function name to use when creating the function directory is "Loopback". 231The LOOPBACK function provides these attributes in its function directory: 232 233 qlen - depth of loopback queue 234 bulk_buflen - buffer length 235 236Testing the LOOPBACK function 237----------------------------- 238 239device: run the gadget 240host: test-usb 241 242http://www.linux-usb.org/usbtest/testusb.c 243 2448. MASS STORAGE function 245======================== 246 247The function is provided by usb_f_mass_storage.ko module. 248 249Function-specific configfs interface 250------------------------------------ 251 252The function name to use when creating the function directory is "mass_storage". 253The MASS STORAGE function provides these attributes in its directory: 254files: 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 263and a default lun.0 directory corresponding to SCSI LUN #0. 264 265A new lun can be added with mkdir: 266 267$ mkdir functions/mass_storage.0/partition.5 268 269Lun numbering does not have to be continuous, except for lun #0 which is 270created by default. A maximum of 8 luns can be specified and they all must be 271named following the <name>.<number> scheme. The numbers can be 0..8. 272Probably a good convention is to name the luns "lun.<number>", 273although it is not mandatory. 274 275In 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 290Testing the MASS STORAGE function 291--------------------------------- 292 293device: connect the gadget, enable it 294host: dmesg, see the USB drives appear (if system configured to automatically 295mount) 296 2979. MIDI function 298================ 299 300The function is provided by usb_f_midi.ko module. 301 302Function-specific configfs interface 303------------------------------------ 304 305The function name to use when creating the function directory is "midi". 306The 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 315Testing the MIDI function 316------------------------- 317 318There are two cases: playing a mid from the gadget to 319the host and playing a mid from the host to the gadget. 320 3211) Playing a mid from the gadget to the host 322host) 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 330gadget) 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 3382) Playing a mid from the host to the gadget 339gadget) 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 347host) 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 356The from_gadget.mid should sound identical to the to_host.mid. 357The from_host.id should sound identical to the to_gadget.mid. 358 359MIDI 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 365128:0 TiMidity TiMidity port 0 366128:1 TiMidity TiMidity port 1 367128:2 TiMidity TiMidity port 2 368128:3 TiMidity TiMidity port 3 369 370$ aplaymidi -p 128:0 file.mid 371 372MIDI ports can be logically connected using the aconnect utility, e.g.: 373 374$ aconnect 24:0 128:0 # try it on the host 375 376After the gadget's MIDI port is connected to timidity's MIDI port, 377whatever is played at the gadget side with aplaymidi -l is audible 378in host's speakers/headphones. 379 38010. NCM function 381================ 382 383The function is provided by usb_f_ncm.ko module. 384 385Function-specific configfs interface 386------------------------------------ 387 388The function name to use when creating the function directory is "ncm". 389The 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 399and after creating the functions/ncm.<instance name> they contain default 400values: qmult is 5, dev_addr and host_addr are randomly selected. 401Except for ifname they can be written to until the function is linked to a 402configuration. The ifname is read-only and contains the name of the interface 403which was assigned by the net core, e. g. usb0. 404 405Testing the NCM function 406------------------------ 407 408Configure IP addresses of the device and the host. Then: 409 410On the device: ping <host's IP> 411On the host: ping <device's IP> 412 41311. OBEX function 414================= 415 416The function is provided by usb_f_obex.ko module. 417 418Function-specific configfs interface 419------------------------------------ 420 421The function name to use when creating the function directory is "obex". 422The OBEX function provides just one attribute in its function directory: 423 424 port_num 425 426The attribute is read-only. 427 428There can be at most 4 ACM/generic serial/OBEX ports in the system. 429 430Testing the OBEX function 431------------------------- 432 433On device: seriald -f /dev/ttyGS<Y> -s 1024 434On host: serialc -v <vendorID> -p <productID> -i<interface#> -a1 -s1024 \ 435 -t<out endpoint addr> -r<in endpoint addr> 436 437where seriald and serialc are Felipe's utilities found here: 438 439https://git.gitorious.org/usb/usb-tools.git master 440 44112. PHONET function 442=================== 443 444The function is provided by usb_f_phonet.ko module. 445 446Function-specific configfs interface 447------------------------------------ 448 449The function name to use when creating the function directory is "phonet". 450The PHONET function provides just one attribute in its function directory: 451 452 ifname - network device interface name associated with this 453 function instance 454 455Testing the PHONET function 456--------------------------- 457 458It is not possible to test the SOCK_STREAM protocol without a specific piece 459of hardware, so only SOCK_DGRAM has been tested. For the latter to work, 460in the past I had to apply the patch mentioned here: 461 462http://www.spinics.net/lists/linux-usb/msg85689.html 463 464These tools are required: 465 466git://git.gitorious.org/meego-cellular/phonet-utils.git 467 468On the host: 469 470$ ./phonet -a 0x10 -i usbpn0 471$ ./pnroute add 0x6c usbpn0 472$./pnroute add 0x10 usbpn0 473$ ifconfig usbpn0 up 474 475On the device: 476 477$ ./phonet -a 0x6c -i upnlink0 478$ ./pnroute add 0x10 upnlink0 479$ ifconfig upnlink0 up 480 481Then a test program can be used: 482 483http://www.spinics.net/lists/linux-usb/msg85690.html 484 485On the device: 486 487$ ./pnxmit -a 0x6c -r 488 489On the host: 490 491$ ./pnxmit -a 0x10 -s 0x6c 492 493As a result some data should be sent from host to device. 494Then the other way round: 495 496On the host: 497 498$ ./pnxmit -a 0x10 -r 499 500On the device: 501 502$ ./pnxmit -a 0x6c -s 0x10 503 50413. RNDIS function 505================== 506 507The function is provided by usb_f_rndis.ko module. 508 509Function-specific configfs interface 510------------------------------------ 511 512The function name to use when creating the function directory is "rndis". 513The 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 523and after creating the functions/rndis.<instance name> they contain default 524values: qmult is 5, dev_addr and host_addr are randomly selected. 525Except for ifname they can be written to until the function is linked to a 526configuration. The ifname is read-only and contains the name of the interface 527which was assigned by the net core, e. g. usb0. 528 529By default there can be only 1 RNDIS interface in the system. 530 531Testing the RNDIS function 532-------------------------- 533 534Configure IP addresses of the device and the host. Then: 535 536On the device: ping <host's IP> 537On the host: ping <device's IP> 538 53914. SERIAL function 540=================== 541 542The function is provided by usb_f_gser.ko module. 543 544Function-specific configfs interface 545------------------------------------ 546 547The function name to use when creating the function directory is "gser". 548The SERIAL function provides just one attribute in its function directory: 549 550 port_num 551 552The attribute is read-only. 553 554There can be at most 4 ACM/generic serial/OBEX ports in the system. 555 556Testing the SERIAL function 557--------------------------- 558 559On host: insmod usbserial 560 echo VID PID >/sys/bus/usb-serial/drivers/generic/new_id 561On host: cat > /dev/ttyUSB<X> 562On target: cat /dev/ttyGS<Y> 563 564then the other way round 565 566On target: cat > /dev/ttyGS<Y> 567On host: cat /dev/ttyUSB<X> 568 56915. SOURCESINK function 570======================= 571 572The function is provided by usb_f_ss_lb.ko module. 573 574Function-specific configfs interface 575------------------------------------ 576 577The function name to use when creating the function directory is "SourceSink". 578The SOURCESINK function provides these attributes in its function directory: 579 580 pattern - 0 (all zeros), 1 (mod63), 2 (none) 581 isoc_interval - 1..16 582 isoc_maxpacket - 0 - 1023 (fs), 0 - 1024 (hs/ss) 583 isoc_mult - 0..2 (hs/ss only) 584 isoc_maxburst - 0..15 (ss only) 585 bulk_buflen - buffer length 586 587Testing the SOURCESINK function 588------------------------------- 589 590device: run the gadget 591host: test-usb 592 593http://www.linux-usb.org/usbtest/testusb.c 594 59516. UAC1 function 596================= 597 598The function is provided by usb_f_uac1.ko module. 599 600Function-specific configfs interface 601------------------------------------ 602 603The function name to use when creating the function directory is "uac1". 604The uac1 function provides these attributes in its function directory: 605 606 audio_buf_size - audio buffer size 607 fn_cap - capture pcm device file name 608 fn_cntl - control device file name 609 fn_play - playback pcm device file name 610 req_buf_size - ISO OUT endpoint request buffer size 611 req_count - ISO OUT endpoint request count 612 613The attributes have sane default values. 614 615Testing the UAC1 function 616------------------------- 617 618device: run the gadget 619host: aplay -l # should list our USB Audio Gadget 620 62117. UAC2 function 622================= 623 624The function is provided by usb_f_uac2.ko module. 625 626Function-specific configfs interface 627------------------------------------ 628 629The function name to use when creating the function directory is "uac2". 630The uac2 function provides these attributes in its function directory: 631 632 chmask - capture channel mask 633 c_srate - capture sampling rate 634 c_ssize - capture sample size (bytes) 635 p_chmask - playback channel mask 636 p_srate - playback sampling rate 637 p_ssize - playback sample size (bytes) 638 639The attributes have sane default values. 640 641Testing the UAC2 function 642------------------------- 643 644device: run the gadget 645host: aplay -l # should list our USB Audio Gadget 646 647This function does not require real hardware support, it just 648sends a stream of audio data to/from the host. In order to 649actually hear something at the device side, a command similar 650to this must be used at the device side: 651 652$ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 & 653 654e.g.: 655 656$ arecord -f dat -t wav -D hw:CARD=UAC2Gadget,DEV=0 | \ 657aplay -D default:CARD=OdroidU3 658 65918. UVC function 660================ 661 662The function is provided by usb_f_uvc.ko module. 663 664Function-specific configfs interface 665------------------------------------ 666 667The function name to use when creating the function directory is "uvc". 668The uvc function provides these attributes in its function directory: 669 670 streaming_interval - interval for polling endpoint for data transfers 671 streaming_maxburst - bMaxBurst for super speed companion descriptor 672 streaming_maxpacket - maximum packet size this endpoint is capable of 673 sending or receiving when this configuration is 674 selected 675 676There are also "control" and "streaming" subdirectories, each of which contain 677a number of their subdirectories. There are some sane defaults provided, but 678the user must provide the following: 679 680 control header - create in control/header, link from control/class/fs 681 and/or control/class/ss 682 streaming header - create in streaming/header, link from 683 streaming/class/fs and/or streaming/class/hs and/or 684 streaming/class/ss 685 format description - create in streaming/mjpeg and/or 686 streaming/uncompressed 687 frame description - create in streaming/mjpeg/<format> and/or in 688 streaming/uncompressed/<format> 689 690Each frame description contains frame interval specification, and each 691such specification consists of a number of lines with an inverval value 692in each line. The rules stated above are best illustrated with an example: 693 694# mkdir functions/uvc.usb0/control/header/h 695# cd functions/uvc.usb0/control/header/h 696# ln -s header/h class/fs 697# ln -s header/h class/ss 698# mkdir -p functions/uvc.usb0/streaming/uncompressed/u/360p 699# cat <<EOF > functions/uvc.usb0/streaming/uncompressed/u/360p/dwFrameInterval 700666666 7011000000 7025000000 703EOF 704# cd $GADGET_CONFIGFS_ROOT 705# mkdir functions/uvc.usb0/streaming/header/h 706# cd functions/uvc.usb0/streaming/header/h 707# ln -s ../../uncompressed/u 708# cd ../../class/fs 709# ln -s ../../header/h 710# cd ../../class/hs 711# ln -s ../../header/h 712# cd ../../class/ss 713# ln -s ../../header/h 714 715 716Testing the UVC function 717------------------------ 718 719device: run the gadget, modprobe vivid 720 721# uvc-gadget -u /dev/video<uvc video node #> -v /dev/video<vivid video node #> 722 723where uvc-gadget is this program: 724http://git.ideasonboard.org/uvc-gadget.git 725 726with these patches: 727http://www.spinics.net/lists/linux-usb/msg99220.html 728 729host: luvcview -f yuv 730 73119. PRINTER function 732==================== 733 734The function is provided by usb_f_printer.ko module. 735 736Function-specific configfs interface 737------------------------------------ 738 739The function name to use when creating the function directory is "printer". 740The printer function provides these attributes in its function directory: 741 742 pnp_string - Data to be passed to the host in pnp string 743 q_len - Number of requests per endpoint 744 745Testing the PRINTER function 746---------------------------- 747 748The most basic testing: 749 750device: run the gadget 751# ls -l /devices/virtual/usb_printer_gadget/ 752 753should show g_printer<number>. 754 755If udev is active, then /dev/g_printer<number> should appear automatically. 756 757host: 758 759If udev is active, then e.g. /dev/usb/lp0 should appear. 760 761host->device transmission: 762 763device: 764# cat /dev/g_printer<number> 765host: 766# cat > /dev/usb/lp0 767 768device->host transmission: 769 770# cat > /dev/g_printer<number> 771host: 772# cat /dev/usb/lp0 773 774More advanced testing can be done with the prn_example 775described in Documentation/usb/gadget-printer.txt.