gadget-testing.rst 35 KB

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