gadget-testing.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  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. =============== ==============================================
  237. Testing the MASS STORAGE function
  238. ---------------------------------
  239. device: connect the gadget, enable it
  240. host: dmesg, see the USB drives appear (if system configured to automatically
  241. mount)
  242. 9. MIDI function
  243. ================
  244. The function is provided by usb_f_midi.ko module.
  245. Function-specific configfs interface
  246. ------------------------------------
  247. The function name to use when creating the function directory is "midi".
  248. The MIDI function provides these attributes in its function directory:
  249. =============== ====================================
  250. buflen MIDI buffer length
  251. id ID string for the USB MIDI adapter
  252. in_ports number of MIDI input ports
  253. index index value for the USB MIDI adapter
  254. out_ports number of MIDI output ports
  255. qlen USB read request queue length
  256. =============== ====================================
  257. Testing the MIDI function
  258. -------------------------
  259. There are two cases: playing a mid from the gadget to
  260. the host and playing a mid from the host to the gadget.
  261. 1) Playing a mid from the gadget to the host:
  262. host::
  263. $ arecordmidi -l
  264. Port Client name Port name
  265. 14:0 Midi Through Midi Through Port-0
  266. 24:0 MIDI Gadget MIDI Gadget MIDI 1
  267. $ arecordmidi -p 24:0 from_gadget.mid
  268. gadget::
  269. $ aplaymidi -l
  270. Port Client name Port name
  271. 20:0 f_midi f_midi
  272. $ aplaymidi -p 20:0 to_host.mid
  273. 2) Playing a mid from the host to the gadget
  274. gadget::
  275. $ arecordmidi -l
  276. Port Client name Port name
  277. 20:0 f_midi f_midi
  278. $ arecordmidi -p 20:0 from_host.mid
  279. host::
  280. $ aplaymidi -l
  281. Port Client name Port name
  282. 14:0 Midi Through Midi Through Port-0
  283. 24:0 MIDI Gadget MIDI Gadget MIDI 1
  284. $ aplaymidi -p24:0 to_gadget.mid
  285. The from_gadget.mid should sound identical to the to_host.mid.
  286. The from_host.id should sound identical to the to_gadget.mid.
  287. MIDI files can be played to speakers/headphones with e.g. timidity installed::
  288. $ aplaymidi -l
  289. Port Client name Port name
  290. 14:0 Midi Through Midi Through Port-0
  291. 24:0 MIDI Gadget MIDI Gadget MIDI 1
  292. 128:0 TiMidity TiMidity port 0
  293. 128:1 TiMidity TiMidity port 1
  294. 128:2 TiMidity TiMidity port 2
  295. 128:3 TiMidity TiMidity port 3
  296. $ aplaymidi -p 128:0 file.mid
  297. MIDI ports can be logically connected using the aconnect utility, e.g.::
  298. $ aconnect 24:0 128:0 # try it on the host
  299. After the gadget's MIDI port is connected to timidity's MIDI port,
  300. whatever is played at the gadget side with aplaymidi -l is audible
  301. in host's speakers/headphones.
  302. 10. NCM function
  303. ================
  304. The function is provided by usb_f_ncm.ko module.
  305. Function-specific configfs interface
  306. ------------------------------------
  307. The function name to use when creating the function directory is "ncm".
  308. The NCM function provides these attributes in its function directory:
  309. =============== ==================================================
  310. ifname network device interface name associated with this
  311. function instance
  312. qmult queue length multiplier for high and super speed
  313. host_addr MAC address of host's end of this
  314. Ethernet over USB link
  315. dev_addr MAC address of device's end of this
  316. Ethernet over USB link
  317. =============== ==================================================
  318. and after creating the functions/ncm.<instance name> they contain default
  319. values: qmult is 5, dev_addr and host_addr are randomly selected.
  320. The ifname can be written to if the function is not bound. A write must be an
  321. interface pattern such as "usb%d", which will cause the net core to choose the
  322. next free usbX interface. By default, it is set to "usb%d".
  323. Testing the NCM function
  324. ------------------------
  325. Configure IP addresses of the device and the host. Then:
  326. On the device::
  327. ping <host's IP>
  328. On the host::
  329. ping <device's IP>
  330. 11. OBEX function
  331. =================
  332. The function is provided by usb_f_obex.ko module.
  333. Function-specific configfs interface
  334. ------------------------------------
  335. The function name to use when creating the function directory is "obex".
  336. The OBEX function provides just one attribute in its function directory:
  337. port_num
  338. The attribute is read-only.
  339. There can be at most 4 ACM/generic serial/OBEX ports in the system.
  340. Testing the OBEX function
  341. -------------------------
  342. On device::
  343. seriald -f /dev/ttyGS<Y> -s 1024
  344. On host::
  345. serialc -v <vendorID> -p <productID> -i<interface#> -a1 -s1024 \
  346. -t<out endpoint addr> -r<in endpoint addr>
  347. where seriald and serialc are Felipe's utilities found here:
  348. https://github.com/felipebalbi/usb-tools.git master
  349. 12. PHONET function
  350. ===================
  351. The function is provided by usb_f_phonet.ko module.
  352. Function-specific configfs interface
  353. ------------------------------------
  354. The function name to use when creating the function directory is "phonet".
  355. The PHONET function provides just one attribute in its function directory:
  356. =============== ==================================================
  357. ifname network device interface name associated with this
  358. function instance
  359. =============== ==================================================
  360. Testing the PHONET function
  361. ---------------------------
  362. It is not possible to test the SOCK_STREAM protocol without a specific piece
  363. of hardware, so only SOCK_DGRAM has been tested. For the latter to work,
  364. in the past I had to apply the patch mentioned here:
  365. http://www.spinics.net/lists/linux-usb/msg85689.html
  366. These tools are required:
  367. git://git.gitorious.org/meego-cellular/phonet-utils.git
  368. On the host::
  369. $ ./phonet -a 0x10 -i usbpn0
  370. $ ./pnroute add 0x6c usbpn0
  371. $./pnroute add 0x10 usbpn0
  372. $ ifconfig usbpn0 up
  373. On the device::
  374. $ ./phonet -a 0x6c -i upnlink0
  375. $ ./pnroute add 0x10 upnlink0
  376. $ ifconfig upnlink0 up
  377. Then a test program can be used::
  378. http://www.spinics.net/lists/linux-usb/msg85690.html
  379. On the device::
  380. $ ./pnxmit -a 0x6c -r
  381. On the host::
  382. $ ./pnxmit -a 0x10 -s 0x6c
  383. As a result some data should be sent from host to device.
  384. Then the other way round:
  385. On the host::
  386. $ ./pnxmit -a 0x10 -r
  387. On the device::
  388. $ ./pnxmit -a 0x6c -s 0x10
  389. 13. RNDIS function
  390. ==================
  391. The function is provided by usb_f_rndis.ko module.
  392. Function-specific configfs interface
  393. ------------------------------------
  394. The function name to use when creating the function directory is "rndis".
  395. The RNDIS function provides these attributes in its function directory:
  396. =============== ==================================================
  397. ifname network device interface name associated with this
  398. function instance
  399. qmult queue length multiplier for high and super speed
  400. host_addr MAC address of host's end of this
  401. Ethernet over USB link
  402. dev_addr MAC address of device's end of this
  403. Ethernet over USB link
  404. =============== ==================================================
  405. and after creating the functions/rndis.<instance name> they contain default
  406. values: qmult is 5, dev_addr and host_addr are randomly selected.
  407. The ifname can be written to if the function is not bound. A write must be an
  408. interface pattern such as "usb%d", which will cause the net core to choose the
  409. next free usbX interface. By default, it is set to "usb%d".
  410. Testing the RNDIS function
  411. --------------------------
  412. Configure IP addresses of the device and the host. Then:
  413. On the device::
  414. ping <host's IP>
  415. On the host::
  416. ping <device's IP>
  417. 14. SERIAL function
  418. ===================
  419. The function is provided by usb_f_gser.ko module.
  420. Function-specific configfs interface
  421. ------------------------------------
  422. The function name to use when creating the function directory is "gser".
  423. The SERIAL function provides just one attribute in its function directory:
  424. port_num
  425. The attribute is read-only.
  426. There can be at most 4 ACM/generic serial/OBEX ports in the system.
  427. Testing the SERIAL function
  428. ---------------------------
  429. On host::
  430. insmod usbserial
  431. echo VID PID >/sys/bus/usb-serial/drivers/generic/new_id
  432. On host::
  433. cat > /dev/ttyUSB<X>
  434. On target::
  435. cat /dev/ttyGS<Y>
  436. then the other way round
  437. On target::
  438. cat > /dev/ttyGS<Y>
  439. On host::
  440. cat /dev/ttyUSB<X>
  441. 15. SOURCESINK function
  442. =======================
  443. The function is provided by usb_f_ss_lb.ko module.
  444. Function-specific configfs interface
  445. ------------------------------------
  446. The function name to use when creating the function directory is "SourceSink".
  447. The SOURCESINK function provides these attributes in its function directory:
  448. =============== ==================================
  449. pattern 0 (all zeros), 1 (mod63), 2 (none)
  450. isoc_interval 1..16
  451. isoc_maxpacket 0 - 1023 (fs), 0 - 1024 (hs/ss)
  452. isoc_mult 0..2 (hs/ss only)
  453. isoc_maxburst 0..15 (ss only)
  454. bulk_buflen buffer length
  455. bulk_qlen depth of queue for bulk
  456. iso_qlen depth of queue for iso
  457. =============== ==================================
  458. Testing the SOURCESINK function
  459. -------------------------------
  460. device: run the gadget
  461. host: test-usb (tools/usb/testusb.c)
  462. 16. UAC1 function (legacy implementation)
  463. =========================================
  464. The function is provided by usb_f_uac1_legacy.ko module.
  465. Function-specific configfs interface
  466. ------------------------------------
  467. The function name to use when creating the function directory
  468. is "uac1_legacy".
  469. The uac1 function provides these attributes in its function directory:
  470. =============== ====================================
  471. audio_buf_size audio buffer size
  472. fn_cap capture pcm device file name
  473. fn_cntl control device file name
  474. fn_play playback pcm device file name
  475. req_buf_size ISO OUT endpoint request buffer size
  476. req_count ISO OUT endpoint request count
  477. =============== ====================================
  478. The attributes have sane default values.
  479. Testing the UAC1 function
  480. -------------------------
  481. device: run the gadget
  482. host::
  483. aplay -l # should list our USB Audio Gadget
  484. 17. UAC2 function
  485. =================
  486. The function is provided by usb_f_uac2.ko module.
  487. Function-specific configfs interface
  488. ------------------------------------
  489. The function name to use when creating the function directory is "uac2".
  490. The uac2 function provides these attributes in its function directory:
  491. =============== ====================================================
  492. c_chmask capture channel mask
  493. c_srate capture sampling rate
  494. c_ssize capture sample size (bytes)
  495. c_sync capture synchronization type (async/adaptive)
  496. fb_max maximum extra bandwidth in async mode
  497. p_chmask playback channel mask
  498. p_srate playback sampling rate
  499. p_ssize playback sample size (bytes)
  500. req_number the number of pre-allocated request for both capture
  501. and playback
  502. =============== ====================================================
  503. The attributes have sane default values.
  504. Testing the UAC2 function
  505. -------------------------
  506. device: run the gadget
  507. host: aplay -l # should list our USB Audio Gadget
  508. This function does not require real hardware support, it just
  509. sends a stream of audio data to/from the host. In order to
  510. actually hear something at the device side, a command similar
  511. to this must be used at the device side::
  512. $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
  513. e.g.::
  514. $ arecord -f dat -t wav -D hw:CARD=UAC2Gadget,DEV=0 | \
  515. aplay -D default:CARD=OdroidU3
  516. 18. UVC function
  517. ================
  518. The function is provided by usb_f_uvc.ko module.
  519. Function-specific configfs interface
  520. ------------------------------------
  521. The function name to use when creating the function directory is "uvc".
  522. The uvc function provides these attributes in its function directory:
  523. =================== ================================================
  524. streaming_interval interval for polling endpoint for data transfers
  525. streaming_maxburst bMaxBurst for super speed companion descriptor
  526. streaming_maxpacket maximum packet size this endpoint is capable of
  527. sending or receiving when this configuration is
  528. selected
  529. function_name name of the interface
  530. =================== ================================================
  531. There are also "control" and "streaming" subdirectories, each of which contain
  532. a number of their subdirectories. There are some sane defaults provided, but
  533. the user must provide the following:
  534. ================== ====================================================
  535. control header create in control/header, link from control/class/fs
  536. and/or control/class/ss
  537. streaming header create in streaming/header, link from
  538. streaming/class/fs and/or streaming/class/hs and/or
  539. streaming/class/ss
  540. format description create in streaming/mjpeg and/or
  541. streaming/uncompressed
  542. frame description create in streaming/mjpeg/<format> and/or in
  543. streaming/uncompressed/<format>
  544. ================== ====================================================
  545. Each frame description contains frame interval specification, and each
  546. such specification consists of a number of lines with an inverval value
  547. in each line. The rules stated above are best illustrated with an example::
  548. # mkdir functions/uvc.usb0/control/header/h
  549. # cd functions/uvc.usb0/control/
  550. # ln -s header/h class/fs
  551. # ln -s header/h class/ss
  552. # mkdir -p functions/uvc.usb0/streaming/uncompressed/u/360p
  553. # cat <<EOF > functions/uvc.usb0/streaming/uncompressed/u/360p/dwFrameInterval
  554. 666666
  555. 1000000
  556. 5000000
  557. EOF
  558. # cd $GADGET_CONFIGFS_ROOT
  559. # mkdir functions/uvc.usb0/streaming/header/h
  560. # cd functions/uvc.usb0/streaming/header/h
  561. # ln -s ../../uncompressed/u
  562. # cd ../../class/fs
  563. # ln -s ../../header/h
  564. # cd ../../class/hs
  565. # ln -s ../../header/h
  566. # cd ../../class/ss
  567. # ln -s ../../header/h
  568. Testing the UVC function
  569. ------------------------
  570. device: run the gadget, modprobe vivid::
  571. # uvc-gadget -u /dev/video<uvc video node #> -v /dev/video<vivid video node #>
  572. where uvc-gadget is this program:
  573. http://git.ideasonboard.org/uvc-gadget.git
  574. with these patches:
  575. http://www.spinics.net/lists/linux-usb/msg99220.html
  576. host::
  577. luvcview -f yuv
  578. 19. PRINTER function
  579. ====================
  580. The function is provided by usb_f_printer.ko module.
  581. Function-specific configfs interface
  582. ------------------------------------
  583. The function name to use when creating the function directory is "printer".
  584. The printer function provides these attributes in its function directory:
  585. ========== ===========================================
  586. pnp_string Data to be passed to the host in pnp string
  587. q_len Number of requests per endpoint
  588. ========== ===========================================
  589. Testing the PRINTER function
  590. ----------------------------
  591. The most basic testing:
  592. device: run the gadget::
  593. # ls -l /devices/virtual/usb_printer_gadget/
  594. should show g_printer<number>.
  595. If udev is active, then /dev/g_printer<number> should appear automatically.
  596. host:
  597. If udev is active, then e.g. /dev/usb/lp0 should appear.
  598. host->device transmission:
  599. device::
  600. # cat /dev/g_printer<number>
  601. host::
  602. # cat > /dev/usb/lp0
  603. device->host transmission::
  604. # cat > /dev/g_printer<number>
  605. host::
  606. # cat /dev/usb/lp0
  607. More advanced testing can be done with the prn_example
  608. described in Documentation/usb/gadget_printer.rst.
  609. 20. UAC1 function (virtual ALSA card, using u_audio API)
  610. ========================================================
  611. The function is provided by usb_f_uac1.ko module.
  612. It will create a virtual ALSA card and the audio streams are simply
  613. sinked to and sourced from it.
  614. Function-specific configfs interface
  615. ------------------------------------
  616. The function name to use when creating the function directory is "uac1".
  617. The uac1 function provides these attributes in its function directory:
  618. ========== ====================================================
  619. c_chmask capture channel mask
  620. c_srate capture sampling rate
  621. c_ssize capture sample size (bytes)
  622. p_chmask playback channel mask
  623. p_srate playback sampling rate
  624. p_ssize playback sample size (bytes)
  625. req_number the number of pre-allocated request for both capture
  626. and playback
  627. ========== ====================================================
  628. The attributes have sane default values.
  629. Testing the UAC1 function
  630. -------------------------
  631. device: run the gadget
  632. host: aplay -l # should list our USB Audio Gadget
  633. This function does not require real hardware support, it just
  634. sends a stream of audio data to/from the host. In order to
  635. actually hear something at the device side, a command similar
  636. to this must be used at the device side::
  637. $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
  638. e.g.::
  639. $ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \
  640. aplay -D default:CARD=OdroidU3