gadget-testing.rst 28 KB

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