xref: /OK3568_Linux_fs/kernel/Documentation/usb/gadget-testing.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun==============
2*4882a593SmuzhiyunGadget Testing
3*4882a593Smuzhiyun==============
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunThis file summarizes information on basic testing of USB functions
6*4882a593Smuzhiyunprovided by gadgets.
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun.. contents
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun   1. ACM function
11*4882a593Smuzhiyun   2. ECM function
12*4882a593Smuzhiyun   3. ECM subset function
13*4882a593Smuzhiyun   4. EEM function
14*4882a593Smuzhiyun   5. FFS function
15*4882a593Smuzhiyun   6. HID function
16*4882a593Smuzhiyun   7. LOOPBACK function
17*4882a593Smuzhiyun   8. MASS STORAGE function
18*4882a593Smuzhiyun   9. MIDI function
19*4882a593Smuzhiyun   10. NCM function
20*4882a593Smuzhiyun   11. OBEX function
21*4882a593Smuzhiyun   12. PHONET function
22*4882a593Smuzhiyun   13. RNDIS function
23*4882a593Smuzhiyun   14. SERIAL function
24*4882a593Smuzhiyun   15. SOURCESINK function
25*4882a593Smuzhiyun   16. UAC1 function (legacy implementation)
26*4882a593Smuzhiyun   17. UAC2 function
27*4882a593Smuzhiyun   18. UVC function
28*4882a593Smuzhiyun   19. PRINTER function
29*4882a593Smuzhiyun   20. UAC1 function (new API)
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun1. ACM function
33*4882a593Smuzhiyun===============
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunThe function is provided by usb_f_acm.ko module.
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunFunction-specific configfs interface
38*4882a593Smuzhiyun------------------------------------
39*4882a593Smuzhiyun
40*4882a593SmuzhiyunThe function name to use when creating the function directory is "acm".
41*4882a593SmuzhiyunThe ACM function provides just one attribute in its function directory:
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun	port_num
44*4882a593Smuzhiyun
45*4882a593SmuzhiyunThe attribute is read-only.
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunThere can be at most 4 ACM/generic serial/OBEX ports in the system.
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun
50*4882a593SmuzhiyunTesting the ACM function
51*4882a593Smuzhiyun------------------------
52*4882a593Smuzhiyun
53*4882a593SmuzhiyunOn the host::
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun	cat > /dev/ttyACM<X>
56*4882a593Smuzhiyun
57*4882a593SmuzhiyunOn the device::
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun	cat /dev/ttyGS<Y>
60*4882a593Smuzhiyun
61*4882a593Smuzhiyunthen the other way round
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunOn the device::
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun	cat > /dev/ttyGS<Y>
66*4882a593Smuzhiyun
67*4882a593SmuzhiyunOn the host::
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun	cat /dev/ttyACM<X>
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun2. ECM function
72*4882a593Smuzhiyun===============
73*4882a593Smuzhiyun
74*4882a593SmuzhiyunThe function is provided by usb_f_ecm.ko module.
75*4882a593Smuzhiyun
76*4882a593SmuzhiyunFunction-specific configfs interface
77*4882a593Smuzhiyun------------------------------------
78*4882a593Smuzhiyun
79*4882a593SmuzhiyunThe function name to use when creating the function directory is "ecm".
80*4882a593SmuzhiyunThe ECM function provides these attributes in its function directory:
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun	=============== ==================================================
83*4882a593Smuzhiyun	ifname		network device interface name associated with this
84*4882a593Smuzhiyun			function instance
85*4882a593Smuzhiyun	qmult		queue length multiplier for high and super speed
86*4882a593Smuzhiyun	host_addr	MAC address of host's end of this
87*4882a593Smuzhiyun			Ethernet over USB link
88*4882a593Smuzhiyun	dev_addr	MAC address of device's end of this
89*4882a593Smuzhiyun			Ethernet over USB link
90*4882a593Smuzhiyun	=============== ==================================================
91*4882a593Smuzhiyun
92*4882a593Smuzhiyunand after creating the functions/ecm.<instance name> they contain default
93*4882a593Smuzhiyunvalues: qmult is 5, dev_addr and host_addr are randomly selected.
94*4882a593SmuzhiyunThe ifname can be written to if the function is not bound. A write must be an
95*4882a593Smuzhiyuninterface pattern such as "usb%d", which will cause the net core to choose the
96*4882a593Smuzhiyunnext free usbX interface. By default, it is set to "usb%d".
97*4882a593Smuzhiyun
98*4882a593SmuzhiyunTesting the ECM function
99*4882a593Smuzhiyun------------------------
100*4882a593Smuzhiyun
101*4882a593SmuzhiyunConfigure IP addresses of the device and the host. Then:
102*4882a593Smuzhiyun
103*4882a593SmuzhiyunOn the device::
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun	ping <host's IP>
106*4882a593Smuzhiyun
107*4882a593SmuzhiyunOn the host::
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun	ping <device's IP>
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun3. ECM subset function
112*4882a593Smuzhiyun======================
113*4882a593Smuzhiyun
114*4882a593SmuzhiyunThe function is provided by usb_f_ecm_subset.ko module.
115*4882a593Smuzhiyun
116*4882a593SmuzhiyunFunction-specific configfs interface
117*4882a593Smuzhiyun------------------------------------
118*4882a593Smuzhiyun
119*4882a593SmuzhiyunThe function name to use when creating the function directory is "geth".
120*4882a593SmuzhiyunThe ECM subset function provides these attributes in its function directory:
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun	=============== ==================================================
123*4882a593Smuzhiyun	ifname		network device interface name associated with this
124*4882a593Smuzhiyun			function instance
125*4882a593Smuzhiyun	qmult		queue length multiplier for high and super speed
126*4882a593Smuzhiyun	host_addr	MAC address of host's end of this
127*4882a593Smuzhiyun			Ethernet over USB link
128*4882a593Smuzhiyun	dev_addr	MAC address of device's end of this
129*4882a593Smuzhiyun			Ethernet over USB link
130*4882a593Smuzhiyun	=============== ==================================================
131*4882a593Smuzhiyun
132*4882a593Smuzhiyunand after creating the functions/ecm.<instance name> they contain default
133*4882a593Smuzhiyunvalues: qmult is 5, dev_addr and host_addr are randomly selected.
134*4882a593SmuzhiyunThe ifname can be written to if the function is not bound. A write must be an
135*4882a593Smuzhiyuninterface pattern such as "usb%d", which will cause the net core to choose the
136*4882a593Smuzhiyunnext free usbX interface. By default, it is set to "usb%d".
137*4882a593Smuzhiyun
138*4882a593SmuzhiyunTesting the ECM subset function
139*4882a593Smuzhiyun-------------------------------
140*4882a593Smuzhiyun
141*4882a593SmuzhiyunConfigure IP addresses of the device and the host. Then:
142*4882a593Smuzhiyun
143*4882a593SmuzhiyunOn the device::
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun	ping <host's IP>
146*4882a593Smuzhiyun
147*4882a593SmuzhiyunOn the host::
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun	ping <device's IP>
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun4. EEM function
152*4882a593Smuzhiyun===============
153*4882a593Smuzhiyun
154*4882a593SmuzhiyunThe function is provided by usb_f_eem.ko module.
155*4882a593Smuzhiyun
156*4882a593SmuzhiyunFunction-specific configfs interface
157*4882a593Smuzhiyun------------------------------------
158*4882a593Smuzhiyun
159*4882a593SmuzhiyunThe function name to use when creating the function directory is "eem".
160*4882a593SmuzhiyunThe EEM function provides these attributes in its function directory:
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun	=============== ==================================================
163*4882a593Smuzhiyun	ifname		network device interface name associated with this
164*4882a593Smuzhiyun			function instance
165*4882a593Smuzhiyun	qmult		queue length multiplier for high and super speed
166*4882a593Smuzhiyun	host_addr	MAC address of host's end of this
167*4882a593Smuzhiyun			Ethernet over USB link
168*4882a593Smuzhiyun	dev_addr	MAC address of device's end of this
169*4882a593Smuzhiyun			Ethernet over USB link
170*4882a593Smuzhiyun	=============== ==================================================
171*4882a593Smuzhiyun
172*4882a593Smuzhiyunand after creating the functions/eem.<instance name> they contain default
173*4882a593Smuzhiyunvalues: qmult is 5, dev_addr and host_addr are randomly selected.
174*4882a593SmuzhiyunThe ifname can be written to if the function is not bound. A write must be an
175*4882a593Smuzhiyuninterface pattern such as "usb%d", which will cause the net core to choose the
176*4882a593Smuzhiyunnext free usbX interface. By default, it is set to "usb%d".
177*4882a593Smuzhiyun
178*4882a593SmuzhiyunTesting the EEM function
179*4882a593Smuzhiyun------------------------
180*4882a593Smuzhiyun
181*4882a593SmuzhiyunConfigure IP addresses of the device and the host. Then:
182*4882a593Smuzhiyun
183*4882a593SmuzhiyunOn the device::
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun	ping <host's IP>
186*4882a593Smuzhiyun
187*4882a593SmuzhiyunOn the host::
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun	ping <device's IP>
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun5. FFS function
192*4882a593Smuzhiyun===============
193*4882a593Smuzhiyun
194*4882a593SmuzhiyunThe function is provided by usb_f_fs.ko module.
195*4882a593Smuzhiyun
196*4882a593SmuzhiyunFunction-specific configfs interface
197*4882a593Smuzhiyun------------------------------------
198*4882a593Smuzhiyun
199*4882a593SmuzhiyunThe function name to use when creating the function directory is "ffs".
200*4882a593SmuzhiyunThe function directory is intentionally empty and not modifiable.
201*4882a593Smuzhiyun
202*4882a593SmuzhiyunAfter creating the directory there is a new instance (a "device") of FunctionFS
203*4882a593Smuzhiyunavailable in the system. Once a "device" is available, the user should follow
204*4882a593Smuzhiyunthe standard procedure for using FunctionFS (mount it, run the userspace
205*4882a593Smuzhiyunprocess which implements the function proper). The gadget should be enabled
206*4882a593Smuzhiyunby writing a suitable string to usb_gadget/<gadget>/UDC.
207*4882a593Smuzhiyun
208*4882a593SmuzhiyunTesting the FFS function
209*4882a593Smuzhiyun------------------------
210*4882a593Smuzhiyun
211*4882a593SmuzhiyunOn the device: start the function's userspace daemon, enable the gadget
212*4882a593Smuzhiyun
213*4882a593SmuzhiyunOn the host: use the USB function provided by the device
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun6. HID function
216*4882a593Smuzhiyun===============
217*4882a593Smuzhiyun
218*4882a593SmuzhiyunThe function is provided by usb_f_hid.ko module.
219*4882a593Smuzhiyun
220*4882a593SmuzhiyunFunction-specific configfs interface
221*4882a593Smuzhiyun------------------------------------
222*4882a593Smuzhiyun
223*4882a593SmuzhiyunThe function name to use when creating the function directory is "hid".
224*4882a593SmuzhiyunThe HID function provides these attributes in its function directory:
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun	=============== ===========================================
227*4882a593Smuzhiyun	protocol	HID protocol to use
228*4882a593Smuzhiyun	report_desc	data to be used in HID reports, except data
229*4882a593Smuzhiyun			passed with /dev/hidg<X>
230*4882a593Smuzhiyun	report_length	HID report length
231*4882a593Smuzhiyun	subclass	HID subclass to use
232*4882a593Smuzhiyun	=============== ===========================================
233*4882a593Smuzhiyun
234*4882a593SmuzhiyunFor a keyboard the protocol and the subclass are 1, the report_length is 8,
235*4882a593Smuzhiyunwhile the report_desc is::
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun  $ hd my_report_desc
238*4882a593Smuzhiyun  00000000  05 01 09 06 a1 01 05 07  19 e0 29 e7 15 00 25 01  |..........)...%.|
239*4882a593Smuzhiyun  00000010  75 01 95 08 81 02 95 01  75 08 81 03 95 05 75 01  |u.......u.....u.|
240*4882a593Smuzhiyun  00000020  05 08 19 01 29 05 91 02  95 01 75 03 91 03 95 06  |....).....u.....|
241*4882a593Smuzhiyun  00000030  75 08 15 00 25 65 05 07  19 00 29 65 81 00 c0     |u...%e....)e...|
242*4882a593Smuzhiyun  0000003f
243*4882a593Smuzhiyun
244*4882a593SmuzhiyunSuch a sequence of bytes can be stored to the attribute with echo::
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun  $ echo -ne \\x05\\x01\\x09\\x06\\xa1.....
247*4882a593Smuzhiyun
248*4882a593SmuzhiyunTesting the HID function
249*4882a593Smuzhiyun------------------------
250*4882a593Smuzhiyun
251*4882a593SmuzhiyunDevice:
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun- create the gadget
254*4882a593Smuzhiyun- connect the gadget to a host, preferably not the one used
255*4882a593Smuzhiyun  to control the gadget
256*4882a593Smuzhiyun- run a program which writes to /dev/hidg<N>, e.g.
257*4882a593Smuzhiyun  a userspace program found in Documentation/usb/gadget_hid.rst::
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun	$ ./hid_gadget_test /dev/hidg0 keyboard
260*4882a593Smuzhiyun
261*4882a593SmuzhiyunHost:
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun- observe the keystrokes from the gadget
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun7. LOOPBACK function
266*4882a593Smuzhiyun====================
267*4882a593Smuzhiyun
268*4882a593SmuzhiyunThe function is provided by usb_f_ss_lb.ko module.
269*4882a593Smuzhiyun
270*4882a593SmuzhiyunFunction-specific configfs interface
271*4882a593Smuzhiyun------------------------------------
272*4882a593Smuzhiyun
273*4882a593SmuzhiyunThe function name to use when creating the function directory is "Loopback".
274*4882a593SmuzhiyunThe LOOPBACK function provides these attributes in its function directory:
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun	=============== =======================
277*4882a593Smuzhiyun	qlen		depth of loopback queue
278*4882a593Smuzhiyun	bulk_buflen	buffer length
279*4882a593Smuzhiyun	=============== =======================
280*4882a593Smuzhiyun
281*4882a593SmuzhiyunTesting the LOOPBACK function
282*4882a593Smuzhiyun-----------------------------
283*4882a593Smuzhiyun
284*4882a593Smuzhiyundevice: run the gadget
285*4882a593Smuzhiyun
286*4882a593Smuzhiyunhost: test-usb (tools/usb/testusb.c)
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun8. MASS STORAGE function
289*4882a593Smuzhiyun========================
290*4882a593Smuzhiyun
291*4882a593SmuzhiyunThe function is provided by usb_f_mass_storage.ko module.
292*4882a593Smuzhiyun
293*4882a593SmuzhiyunFunction-specific configfs interface
294*4882a593Smuzhiyun------------------------------------
295*4882a593Smuzhiyun
296*4882a593SmuzhiyunThe function name to use when creating the function directory is "mass_storage".
297*4882a593SmuzhiyunThe MASS STORAGE function provides these attributes in its directory:
298*4882a593Smuzhiyunfiles:
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun	=============== ==============================================
301*4882a593Smuzhiyun	stall		Set to permit function to halt bulk endpoints.
302*4882a593Smuzhiyun			Disabled on some USB devices known not to work
303*4882a593Smuzhiyun			correctly. You should set it to true.
304*4882a593Smuzhiyun	num_buffers	Number of pipeline buffers. Valid numbers
305*4882a593Smuzhiyun			are 2..4. Available only if
306*4882a593Smuzhiyun			CONFIG_USB_GADGET_DEBUG_FILES is set.
307*4882a593Smuzhiyun	=============== ==============================================
308*4882a593Smuzhiyun
309*4882a593Smuzhiyunand a default lun.0 directory corresponding to SCSI LUN #0.
310*4882a593Smuzhiyun
311*4882a593SmuzhiyunA new lun can be added with mkdir::
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun	$ mkdir functions/mass_storage.0/partition.5
314*4882a593Smuzhiyun
315*4882a593SmuzhiyunLun numbering does not have to be continuous, except for lun #0 which is
316*4882a593Smuzhiyuncreated by default. A maximum of 8 luns can be specified and they all must be
317*4882a593Smuzhiyunnamed following the <name>.<number> scheme. The numbers can be 0..8.
318*4882a593SmuzhiyunProbably a good convention is to name the luns "lun.<number>",
319*4882a593Smuzhiyunalthough it is not mandatory.
320*4882a593Smuzhiyun
321*4882a593SmuzhiyunIn each lun directory there are the following attribute files:
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun	=============== ==============================================
324*4882a593Smuzhiyun	file		The path to the backing file for the LUN.
325*4882a593Smuzhiyun			Required if LUN is not marked as removable.
326*4882a593Smuzhiyun	ro		Flag specifying access to the LUN shall be
327*4882a593Smuzhiyun			read-only. This is implied if CD-ROM emulation
328*4882a593Smuzhiyun			is enabled as well as when it was impossible
329*4882a593Smuzhiyun			to open "filename" in R/W mode.
330*4882a593Smuzhiyun	removable	Flag specifying that LUN shall be indicated as
331*4882a593Smuzhiyun			being removable.
332*4882a593Smuzhiyun	cdrom		Flag specifying that LUN shall be reported as
333*4882a593Smuzhiyun			being a CD-ROM.
334*4882a593Smuzhiyun	nofua		Flag specifying that FUA flag
335*4882a593Smuzhiyun			in SCSI WRITE(10,12)
336*4882a593Smuzhiyun	=============== ==============================================
337*4882a593Smuzhiyun
338*4882a593SmuzhiyunTesting the MASS STORAGE function
339*4882a593Smuzhiyun---------------------------------
340*4882a593Smuzhiyun
341*4882a593Smuzhiyundevice: connect the gadget, enable it
342*4882a593Smuzhiyunhost: dmesg, see the USB drives appear (if system configured to automatically
343*4882a593Smuzhiyunmount)
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun9. MIDI function
346*4882a593Smuzhiyun================
347*4882a593Smuzhiyun
348*4882a593SmuzhiyunThe function is provided by usb_f_midi.ko module.
349*4882a593Smuzhiyun
350*4882a593SmuzhiyunFunction-specific configfs interface
351*4882a593Smuzhiyun------------------------------------
352*4882a593Smuzhiyun
353*4882a593SmuzhiyunThe function name to use when creating the function directory is "midi".
354*4882a593SmuzhiyunThe MIDI function provides these attributes in its function directory:
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun	=============== ====================================
357*4882a593Smuzhiyun	buflen		MIDI buffer length
358*4882a593Smuzhiyun	id		ID string for the USB MIDI adapter
359*4882a593Smuzhiyun	in_ports	number of MIDI input ports
360*4882a593Smuzhiyun	index		index value for the USB MIDI adapter
361*4882a593Smuzhiyun	out_ports	number of MIDI output ports
362*4882a593Smuzhiyun	qlen		USB read request queue length
363*4882a593Smuzhiyun	=============== ====================================
364*4882a593Smuzhiyun
365*4882a593SmuzhiyunTesting the MIDI function
366*4882a593Smuzhiyun-------------------------
367*4882a593Smuzhiyun
368*4882a593SmuzhiyunThere are two cases: playing a mid from the gadget to
369*4882a593Smuzhiyunthe host and playing a mid from the host to the gadget.
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun1) Playing a mid from the gadget to the host:
372*4882a593Smuzhiyun
373*4882a593Smuzhiyunhost::
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun  $ arecordmidi -l
376*4882a593Smuzhiyun   Port    Client name                      Port name
377*4882a593Smuzhiyun   14:0    Midi Through                     Midi Through Port-0
378*4882a593Smuzhiyun   24:0    MIDI Gadget                      MIDI Gadget MIDI 1
379*4882a593Smuzhiyun  $ arecordmidi -p 24:0 from_gadget.mid
380*4882a593Smuzhiyun
381*4882a593Smuzhiyungadget::
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun  $ aplaymidi -l
384*4882a593Smuzhiyun   Port    Client name                      Port name
385*4882a593Smuzhiyun   20:0    f_midi                           f_midi
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun  $ aplaymidi -p 20:0 to_host.mid
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun2) Playing a mid from the host to the gadget
390*4882a593Smuzhiyun
391*4882a593Smuzhiyungadget::
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun  $ arecordmidi -l
394*4882a593Smuzhiyun   Port    Client name                      Port name
395*4882a593Smuzhiyun   20:0    f_midi                           f_midi
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun  $ arecordmidi -p 20:0 from_host.mid
398*4882a593Smuzhiyun
399*4882a593Smuzhiyunhost::
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun  $ aplaymidi -l
402*4882a593Smuzhiyun   Port    Client name                      Port name
403*4882a593Smuzhiyun   14:0    Midi Through                     Midi Through Port-0
404*4882a593Smuzhiyun   24:0    MIDI Gadget                      MIDI Gadget MIDI 1
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun  $ aplaymidi -p24:0 to_gadget.mid
407*4882a593Smuzhiyun
408*4882a593SmuzhiyunThe from_gadget.mid should sound identical to the to_host.mid.
409*4882a593Smuzhiyun
410*4882a593SmuzhiyunThe from_host.id should sound identical to the to_gadget.mid.
411*4882a593Smuzhiyun
412*4882a593SmuzhiyunMIDI files can be played to speakers/headphones with e.g. timidity installed::
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun  $ aplaymidi -l
415*4882a593Smuzhiyun   Port    Client name                      Port name
416*4882a593Smuzhiyun   14:0    Midi Through                     Midi Through Port-0
417*4882a593Smuzhiyun   24:0    MIDI Gadget                      MIDI Gadget MIDI 1
418*4882a593Smuzhiyun  128:0    TiMidity                         TiMidity port 0
419*4882a593Smuzhiyun  128:1    TiMidity                         TiMidity port 1
420*4882a593Smuzhiyun  128:2    TiMidity                         TiMidity port 2
421*4882a593Smuzhiyun  128:3    TiMidity                         TiMidity port 3
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun  $ aplaymidi -p 128:0 file.mid
424*4882a593Smuzhiyun
425*4882a593SmuzhiyunMIDI ports can be logically connected using the aconnect utility, e.g.::
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun  $ aconnect 24:0 128:0 # try it on the host
428*4882a593Smuzhiyun
429*4882a593SmuzhiyunAfter the gadget's MIDI port is connected to timidity's MIDI port,
430*4882a593Smuzhiyunwhatever is played at the gadget side with aplaymidi -l is audible
431*4882a593Smuzhiyunin host's speakers/headphones.
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun10. NCM function
434*4882a593Smuzhiyun================
435*4882a593Smuzhiyun
436*4882a593SmuzhiyunThe function is provided by usb_f_ncm.ko module.
437*4882a593Smuzhiyun
438*4882a593SmuzhiyunFunction-specific configfs interface
439*4882a593Smuzhiyun------------------------------------
440*4882a593Smuzhiyun
441*4882a593SmuzhiyunThe function name to use when creating the function directory is "ncm".
442*4882a593SmuzhiyunThe NCM function provides these attributes in its function directory:
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun	=============== ==================================================
445*4882a593Smuzhiyun	ifname		network device interface name associated with this
446*4882a593Smuzhiyun			function instance
447*4882a593Smuzhiyun	qmult		queue length multiplier for high and super speed
448*4882a593Smuzhiyun	host_addr	MAC address of host's end of this
449*4882a593Smuzhiyun			Ethernet over USB link
450*4882a593Smuzhiyun	dev_addr	MAC address of device's end of this
451*4882a593Smuzhiyun			Ethernet over USB link
452*4882a593Smuzhiyun	=============== ==================================================
453*4882a593Smuzhiyun
454*4882a593Smuzhiyunand after creating the functions/ncm.<instance name> they contain default
455*4882a593Smuzhiyunvalues: qmult is 5, dev_addr and host_addr are randomly selected.
456*4882a593SmuzhiyunThe ifname can be written to if the function is not bound. A write must be an
457*4882a593Smuzhiyuninterface pattern such as "usb%d", which will cause the net core to choose the
458*4882a593Smuzhiyunnext free usbX interface. By default, it is set to "usb%d".
459*4882a593Smuzhiyun
460*4882a593SmuzhiyunTesting the NCM function
461*4882a593Smuzhiyun------------------------
462*4882a593Smuzhiyun
463*4882a593SmuzhiyunConfigure IP addresses of the device and the host. Then:
464*4882a593Smuzhiyun
465*4882a593SmuzhiyunOn the device::
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun	ping <host's IP>
468*4882a593Smuzhiyun
469*4882a593SmuzhiyunOn the host::
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun	ping <device's IP>
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun11. OBEX function
474*4882a593Smuzhiyun=================
475*4882a593Smuzhiyun
476*4882a593SmuzhiyunThe function is provided by usb_f_obex.ko module.
477*4882a593Smuzhiyun
478*4882a593SmuzhiyunFunction-specific configfs interface
479*4882a593Smuzhiyun------------------------------------
480*4882a593Smuzhiyun
481*4882a593SmuzhiyunThe function name to use when creating the function directory is "obex".
482*4882a593SmuzhiyunThe OBEX function provides just one attribute in its function directory:
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun	port_num
485*4882a593Smuzhiyun
486*4882a593SmuzhiyunThe attribute is read-only.
487*4882a593Smuzhiyun
488*4882a593SmuzhiyunThere can be at most 4 ACM/generic serial/OBEX ports in the system.
489*4882a593Smuzhiyun
490*4882a593SmuzhiyunTesting the OBEX function
491*4882a593Smuzhiyun-------------------------
492*4882a593Smuzhiyun
493*4882a593SmuzhiyunOn device::
494*4882a593Smuzhiyun
495*4882a593Smuzhiyun	seriald -f /dev/ttyGS<Y> -s 1024
496*4882a593Smuzhiyun
497*4882a593SmuzhiyunOn host::
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun	serialc -v <vendorID> -p <productID> -i<interface#> -a1 -s1024 \
500*4882a593Smuzhiyun                -t<out endpoint addr> -r<in endpoint addr>
501*4882a593Smuzhiyun
502*4882a593Smuzhiyunwhere seriald and serialc are Felipe's utilities found here:
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun	https://github.com/felipebalbi/usb-tools.git master
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun12. PHONET function
507*4882a593Smuzhiyun===================
508*4882a593Smuzhiyun
509*4882a593SmuzhiyunThe function is provided by usb_f_phonet.ko module.
510*4882a593Smuzhiyun
511*4882a593SmuzhiyunFunction-specific configfs interface
512*4882a593Smuzhiyun------------------------------------
513*4882a593Smuzhiyun
514*4882a593SmuzhiyunThe function name to use when creating the function directory is "phonet".
515*4882a593SmuzhiyunThe PHONET function provides just one attribute in its function directory:
516*4882a593Smuzhiyun
517*4882a593Smuzhiyun	=============== ==================================================
518*4882a593Smuzhiyun	ifname		network device interface name associated with this
519*4882a593Smuzhiyun			function instance
520*4882a593Smuzhiyun	=============== ==================================================
521*4882a593Smuzhiyun
522*4882a593SmuzhiyunTesting the PHONET function
523*4882a593Smuzhiyun---------------------------
524*4882a593Smuzhiyun
525*4882a593SmuzhiyunIt is not possible to test the SOCK_STREAM protocol without a specific piece
526*4882a593Smuzhiyunof hardware, so only SOCK_DGRAM has been tested. For the latter to work,
527*4882a593Smuzhiyunin the past I had to apply the patch mentioned here:
528*4882a593Smuzhiyun
529*4882a593Smuzhiyunhttp://www.spinics.net/lists/linux-usb/msg85689.html
530*4882a593Smuzhiyun
531*4882a593SmuzhiyunThese tools are required:
532*4882a593Smuzhiyun
533*4882a593Smuzhiyungit://git.gitorious.org/meego-cellular/phonet-utils.git
534*4882a593Smuzhiyun
535*4882a593SmuzhiyunOn the host::
536*4882a593Smuzhiyun
537*4882a593Smuzhiyun	$ ./phonet -a 0x10 -i usbpn0
538*4882a593Smuzhiyun	$ ./pnroute add 0x6c usbpn0
539*4882a593Smuzhiyun	$./pnroute add 0x10 usbpn0
540*4882a593Smuzhiyun	$ ifconfig usbpn0 up
541*4882a593Smuzhiyun
542*4882a593SmuzhiyunOn the device::
543*4882a593Smuzhiyun
544*4882a593Smuzhiyun	$ ./phonet -a 0x6c -i upnlink0
545*4882a593Smuzhiyun	$ ./pnroute add 0x10 upnlink0
546*4882a593Smuzhiyun	$ ifconfig upnlink0 up
547*4882a593Smuzhiyun
548*4882a593SmuzhiyunThen a test program can be used::
549*4882a593Smuzhiyun
550*4882a593Smuzhiyun	http://www.spinics.net/lists/linux-usb/msg85690.html
551*4882a593Smuzhiyun
552*4882a593SmuzhiyunOn the device::
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun	$ ./pnxmit -a 0x6c -r
555*4882a593Smuzhiyun
556*4882a593SmuzhiyunOn the host::
557*4882a593Smuzhiyun
558*4882a593Smuzhiyun	$ ./pnxmit -a 0x10 -s 0x6c
559*4882a593Smuzhiyun
560*4882a593SmuzhiyunAs a result some data should be sent from host to device.
561*4882a593SmuzhiyunThen the other way round:
562*4882a593Smuzhiyun
563*4882a593SmuzhiyunOn the host::
564*4882a593Smuzhiyun
565*4882a593Smuzhiyun	$ ./pnxmit -a 0x10 -r
566*4882a593Smuzhiyun
567*4882a593SmuzhiyunOn the device::
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun	$ ./pnxmit -a 0x6c -s 0x10
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun13. RNDIS function
572*4882a593Smuzhiyun==================
573*4882a593Smuzhiyun
574*4882a593SmuzhiyunThe function is provided by usb_f_rndis.ko module.
575*4882a593Smuzhiyun
576*4882a593SmuzhiyunFunction-specific configfs interface
577*4882a593Smuzhiyun------------------------------------
578*4882a593Smuzhiyun
579*4882a593SmuzhiyunThe function name to use when creating the function directory is "rndis".
580*4882a593SmuzhiyunThe RNDIS function provides these attributes in its function directory:
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun	=============== ==================================================
583*4882a593Smuzhiyun	ifname		network device interface name associated with this
584*4882a593Smuzhiyun			function instance
585*4882a593Smuzhiyun	qmult		queue length multiplier for high and super speed
586*4882a593Smuzhiyun	host_addr	MAC address of host's end of this
587*4882a593Smuzhiyun			Ethernet over USB link
588*4882a593Smuzhiyun	dev_addr	MAC address of device's end of this
589*4882a593Smuzhiyun			Ethernet over USB link
590*4882a593Smuzhiyun	=============== ==================================================
591*4882a593Smuzhiyun
592*4882a593Smuzhiyunand after creating the functions/rndis.<instance name> they contain default
593*4882a593Smuzhiyunvalues: qmult is 5, dev_addr and host_addr are randomly selected.
594*4882a593SmuzhiyunThe ifname can be written to if the function is not bound. A write must be an
595*4882a593Smuzhiyuninterface pattern such as "usb%d", which will cause the net core to choose the
596*4882a593Smuzhiyunnext free usbX interface. By default, it is set to "usb%d".
597*4882a593Smuzhiyun
598*4882a593SmuzhiyunTesting the RNDIS function
599*4882a593Smuzhiyun--------------------------
600*4882a593Smuzhiyun
601*4882a593SmuzhiyunConfigure IP addresses of the device and the host. Then:
602*4882a593Smuzhiyun
603*4882a593SmuzhiyunOn the device::
604*4882a593Smuzhiyun
605*4882a593Smuzhiyun	ping <host's IP>
606*4882a593Smuzhiyun
607*4882a593SmuzhiyunOn the host::
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun	ping <device's IP>
610*4882a593Smuzhiyun
611*4882a593Smuzhiyun14. SERIAL function
612*4882a593Smuzhiyun===================
613*4882a593Smuzhiyun
614*4882a593SmuzhiyunThe function is provided by usb_f_gser.ko module.
615*4882a593Smuzhiyun
616*4882a593SmuzhiyunFunction-specific configfs interface
617*4882a593Smuzhiyun------------------------------------
618*4882a593Smuzhiyun
619*4882a593SmuzhiyunThe function name to use when creating the function directory is "gser".
620*4882a593SmuzhiyunThe SERIAL function provides just one attribute in its function directory:
621*4882a593Smuzhiyun
622*4882a593Smuzhiyun	port_num
623*4882a593Smuzhiyun
624*4882a593SmuzhiyunThe attribute is read-only.
625*4882a593Smuzhiyun
626*4882a593SmuzhiyunThere can be at most 4 ACM/generic serial/OBEX ports in the system.
627*4882a593Smuzhiyun
628*4882a593SmuzhiyunTesting the SERIAL function
629*4882a593Smuzhiyun---------------------------
630*4882a593Smuzhiyun
631*4882a593SmuzhiyunOn host::
632*4882a593Smuzhiyun
633*4882a593Smuzhiyun	insmod usbserial
634*4882a593Smuzhiyun	echo VID PID >/sys/bus/usb-serial/drivers/generic/new_id
635*4882a593Smuzhiyun
636*4882a593SmuzhiyunOn host::
637*4882a593Smuzhiyun
638*4882a593Smuzhiyun	cat > /dev/ttyUSB<X>
639*4882a593Smuzhiyun
640*4882a593SmuzhiyunOn target::
641*4882a593Smuzhiyun
642*4882a593Smuzhiyun	cat /dev/ttyGS<Y>
643*4882a593Smuzhiyun
644*4882a593Smuzhiyunthen the other way round
645*4882a593Smuzhiyun
646*4882a593SmuzhiyunOn target::
647*4882a593Smuzhiyun
648*4882a593Smuzhiyun	cat > /dev/ttyGS<Y>
649*4882a593Smuzhiyun
650*4882a593SmuzhiyunOn host::
651*4882a593Smuzhiyun
652*4882a593Smuzhiyun	cat /dev/ttyUSB<X>
653*4882a593Smuzhiyun
654*4882a593Smuzhiyun15. SOURCESINK function
655*4882a593Smuzhiyun=======================
656*4882a593Smuzhiyun
657*4882a593SmuzhiyunThe function is provided by usb_f_ss_lb.ko module.
658*4882a593Smuzhiyun
659*4882a593SmuzhiyunFunction-specific configfs interface
660*4882a593Smuzhiyun------------------------------------
661*4882a593Smuzhiyun
662*4882a593SmuzhiyunThe function name to use when creating the function directory is "SourceSink".
663*4882a593SmuzhiyunThe SOURCESINK function provides these attributes in its function directory:
664*4882a593Smuzhiyun
665*4882a593Smuzhiyun	=============== ==================================
666*4882a593Smuzhiyun	pattern		0 (all zeros), 1 (mod63), 2 (none)
667*4882a593Smuzhiyun	isoc_interval	1..16
668*4882a593Smuzhiyun	isoc_maxpacket	0 - 1023 (fs), 0 - 1024 (hs/ss)
669*4882a593Smuzhiyun	isoc_mult	0..2 (hs/ss only)
670*4882a593Smuzhiyun	isoc_maxburst	0..15 (ss only)
671*4882a593Smuzhiyun	bulk_buflen	buffer length
672*4882a593Smuzhiyun	bulk_qlen	depth of queue for bulk
673*4882a593Smuzhiyun	iso_qlen	depth of queue for iso
674*4882a593Smuzhiyun	=============== ==================================
675*4882a593Smuzhiyun
676*4882a593SmuzhiyunTesting the SOURCESINK function
677*4882a593Smuzhiyun-------------------------------
678*4882a593Smuzhiyun
679*4882a593Smuzhiyundevice: run the gadget
680*4882a593Smuzhiyun
681*4882a593Smuzhiyunhost: test-usb (tools/usb/testusb.c)
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun
684*4882a593Smuzhiyun16. UAC1 function (legacy implementation)
685*4882a593Smuzhiyun=========================================
686*4882a593Smuzhiyun
687*4882a593SmuzhiyunThe function is provided by usb_f_uac1_legacy.ko module.
688*4882a593Smuzhiyun
689*4882a593SmuzhiyunFunction-specific configfs interface
690*4882a593Smuzhiyun------------------------------------
691*4882a593Smuzhiyun
692*4882a593SmuzhiyunThe function name to use when creating the function directory
693*4882a593Smuzhiyunis "uac1_legacy".
694*4882a593SmuzhiyunThe uac1 function provides these attributes in its function directory:
695*4882a593Smuzhiyun
696*4882a593Smuzhiyun	=============== ====================================
697*4882a593Smuzhiyun	audio_buf_size	audio buffer size
698*4882a593Smuzhiyun	fn_cap		capture pcm device file name
699*4882a593Smuzhiyun	fn_cntl		control device file name
700*4882a593Smuzhiyun	fn_play		playback pcm device file name
701*4882a593Smuzhiyun	req_buf_size	ISO OUT endpoint request buffer size
702*4882a593Smuzhiyun	req_count	ISO OUT endpoint request count
703*4882a593Smuzhiyun	=============== ====================================
704*4882a593Smuzhiyun
705*4882a593SmuzhiyunThe attributes have sane default values.
706*4882a593Smuzhiyun
707*4882a593SmuzhiyunTesting the UAC1 function
708*4882a593Smuzhiyun-------------------------
709*4882a593Smuzhiyun
710*4882a593Smuzhiyundevice: run the gadget
711*4882a593Smuzhiyun
712*4882a593Smuzhiyunhost::
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun	aplay -l # should list our USB Audio Gadget
715*4882a593Smuzhiyun
716*4882a593Smuzhiyun17. UAC2 function
717*4882a593Smuzhiyun=================
718*4882a593Smuzhiyun
719*4882a593SmuzhiyunThe function is provided by usb_f_uac2.ko module.
720*4882a593Smuzhiyun
721*4882a593SmuzhiyunFunction-specific configfs interface
722*4882a593Smuzhiyun------------------------------------
723*4882a593Smuzhiyun
724*4882a593SmuzhiyunThe function name to use when creating the function directory is "uac2".
725*4882a593SmuzhiyunThe uac2 function provides these attributes in its function directory:
726*4882a593Smuzhiyun
727*4882a593Smuzhiyun	================ ====================================================
728*4882a593Smuzhiyun	c_chmask         capture channel mask
729*4882a593Smuzhiyun	c_srate          list of capture sampling rates (comma-separated)
730*4882a593Smuzhiyun	c_ssize          capture sample size (bytes)
731*4882a593Smuzhiyun	c_sync           capture synchronization type (async/adaptive)
732*4882a593Smuzhiyun	c_mute_present   capture mute control enable
733*4882a593Smuzhiyun	c_volume_present capture volume control enable
734*4882a593Smuzhiyun	c_volume_min     capture volume control min value (in 1/256 dB)
735*4882a593Smuzhiyun	c_volume_max     capture volume control max value (in 1/256 dB)
736*4882a593Smuzhiyun	c_volume_res     capture volume control resolution (in 1/256 dB)
737*4882a593Smuzhiyun	c_hs_bint        capture bInterval for HS/SS (1-4: fixed, 0: auto)
738*4882a593Smuzhiyun	fb_max           maximum extra bandwidth in async mode
739*4882a593Smuzhiyun	p_chmask         playback channel mask
740*4882a593Smuzhiyun	p_srate          list of playback sampling rates (comma-separated)
741*4882a593Smuzhiyun	p_ssize          playback sample size (bytes)
742*4882a593Smuzhiyun	p_mute_present   playback mute control enable
743*4882a593Smuzhiyun	p_volume_present playback volume control enable
744*4882a593Smuzhiyun	p_volume_min     playback volume control min value (in 1/256 dB)
745*4882a593Smuzhiyun	p_volume_max     playback volume control max value (in 1/256 dB)
746*4882a593Smuzhiyun	p_volume_res     playback volume control resolution (in 1/256 dB)
747*4882a593Smuzhiyun	p_hs_bint        playback bInterval for HS/SS (1-4: fixed, 0: auto)
748*4882a593Smuzhiyun	req_number       the number of pre-allocated request for both capture
749*4882a593Smuzhiyun	                 and playback
750*4882a593Smuzhiyun	function_name    name of the interface
751*4882a593Smuzhiyun	================ ====================================================
752*4882a593Smuzhiyun
753*4882a593SmuzhiyunThe attributes have sane default values.
754*4882a593Smuzhiyun
755*4882a593SmuzhiyunTesting the UAC2 function
756*4882a593Smuzhiyun-------------------------
757*4882a593Smuzhiyun
758*4882a593Smuzhiyundevice: run the gadget
759*4882a593Smuzhiyunhost: aplay -l # should list our USB Audio Gadget
760*4882a593Smuzhiyun
761*4882a593SmuzhiyunThis function does not require real hardware support, it just
762*4882a593Smuzhiyunsends a stream of audio data to/from the host. In order to
763*4882a593Smuzhiyunactually hear something at the device side, a command similar
764*4882a593Smuzhiyunto this must be used at the device side::
765*4882a593Smuzhiyun
766*4882a593Smuzhiyun	$ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
767*4882a593Smuzhiyun
768*4882a593Smuzhiyune.g.::
769*4882a593Smuzhiyun
770*4882a593Smuzhiyun	$ arecord -f dat -t wav -D hw:CARD=UAC2Gadget,DEV=0 | \
771*4882a593Smuzhiyun	  aplay -D default:CARD=OdroidU3
772*4882a593Smuzhiyun
773*4882a593Smuzhiyun18. UVC function
774*4882a593Smuzhiyun================
775*4882a593Smuzhiyun
776*4882a593SmuzhiyunThe function is provided by usb_f_uvc.ko module.
777*4882a593Smuzhiyun
778*4882a593SmuzhiyunFunction-specific configfs interface
779*4882a593Smuzhiyun------------------------------------
780*4882a593Smuzhiyun
781*4882a593SmuzhiyunThe function name to use when creating the function directory is "uvc".
782*4882a593SmuzhiyunThe uvc function provides these attributes in its function directory:
783*4882a593Smuzhiyun
784*4882a593Smuzhiyun	=================== ================================================
785*4882a593Smuzhiyun	streaming_interval  interval for polling endpoint for data transfers
786*4882a593Smuzhiyun	streaming_maxburst  bMaxBurst for super speed companion descriptor
787*4882a593Smuzhiyun	streaming_maxpacket maximum packet size this endpoint is capable of
788*4882a593Smuzhiyun			    sending or receiving when this configuration is
789*4882a593Smuzhiyun			    selected
790*4882a593Smuzhiyun	function_name       name of the interface
791*4882a593Smuzhiyun	=================== ================================================
792*4882a593Smuzhiyun
793*4882a593SmuzhiyunThere are also "control" and "streaming" subdirectories, each of which contain
794*4882a593Smuzhiyuna number of their subdirectories. There are some sane defaults provided, but
795*4882a593Smuzhiyunthe user must provide the following:
796*4882a593Smuzhiyun
797*4882a593Smuzhiyun	================== ====================================================
798*4882a593Smuzhiyun	control header     create in control/header, link from control/class/fs
799*4882a593Smuzhiyun			   and/or control/class/ss
800*4882a593Smuzhiyun	streaming header   create in streaming/header, link from
801*4882a593Smuzhiyun			   streaming/class/fs and/or streaming/class/hs and/or
802*4882a593Smuzhiyun			   streaming/class/ss
803*4882a593Smuzhiyun	format description create in streaming/mjpeg and/or
804*4882a593Smuzhiyun			   streaming/uncompressed
805*4882a593Smuzhiyun	frame description  create in streaming/mjpeg/<format> and/or in
806*4882a593Smuzhiyun			   streaming/uncompressed/<format>
807*4882a593Smuzhiyun	================== ====================================================
808*4882a593Smuzhiyun
809*4882a593SmuzhiyunEach frame description contains frame interval specification, and each
810*4882a593Smuzhiyunsuch specification consists of a number of lines with an inverval value
811*4882a593Smuzhiyunin each line. The rules stated above are best illustrated with an example::
812*4882a593Smuzhiyun
813*4882a593Smuzhiyun  # mkdir functions/uvc.usb0/control/header/h
814*4882a593Smuzhiyun  # cd functions/uvc.usb0/control/
815*4882a593Smuzhiyun  # ln -s header/h class/fs
816*4882a593Smuzhiyun  # ln -s header/h class/ss
817*4882a593Smuzhiyun  # mkdir -p functions/uvc.usb0/streaming/uncompressed/u/360p
818*4882a593Smuzhiyun  # cat <<EOF > functions/uvc.usb0/streaming/uncompressed/u/360p/dwFrameInterval
819*4882a593Smuzhiyun  666666
820*4882a593Smuzhiyun  1000000
821*4882a593Smuzhiyun  5000000
822*4882a593Smuzhiyun  EOF
823*4882a593Smuzhiyun  # cd $GADGET_CONFIGFS_ROOT
824*4882a593Smuzhiyun  # mkdir functions/uvc.usb0/streaming/header/h
825*4882a593Smuzhiyun  # cd functions/uvc.usb0/streaming/header/h
826*4882a593Smuzhiyun  # ln -s ../../uncompressed/u
827*4882a593Smuzhiyun  # cd ../../class/fs
828*4882a593Smuzhiyun  # ln -s ../../header/h
829*4882a593Smuzhiyun  # cd ../../class/hs
830*4882a593Smuzhiyun  # ln -s ../../header/h
831*4882a593Smuzhiyun  # cd ../../class/ss
832*4882a593Smuzhiyun  # ln -s ../../header/h
833*4882a593Smuzhiyun
834*4882a593Smuzhiyun
835*4882a593SmuzhiyunTesting the UVC function
836*4882a593Smuzhiyun------------------------
837*4882a593Smuzhiyun
838*4882a593Smuzhiyundevice: run the gadget, modprobe vivid::
839*4882a593Smuzhiyun
840*4882a593Smuzhiyun  # uvc-gadget -u /dev/video<uvc video node #> -v /dev/video<vivid video node #>
841*4882a593Smuzhiyun
842*4882a593Smuzhiyunwhere uvc-gadget is this program:
843*4882a593Smuzhiyun	http://git.ideasonboard.org/uvc-gadget.git
844*4882a593Smuzhiyun
845*4882a593Smuzhiyunwith these patches:
846*4882a593Smuzhiyun
847*4882a593Smuzhiyun	http://www.spinics.net/lists/linux-usb/msg99220.html
848*4882a593Smuzhiyun
849*4882a593Smuzhiyunhost::
850*4882a593Smuzhiyun
851*4882a593Smuzhiyun	luvcview -f yuv
852*4882a593Smuzhiyun
853*4882a593Smuzhiyun19. PRINTER function
854*4882a593Smuzhiyun====================
855*4882a593Smuzhiyun
856*4882a593SmuzhiyunThe function is provided by usb_f_printer.ko module.
857*4882a593Smuzhiyun
858*4882a593SmuzhiyunFunction-specific configfs interface
859*4882a593Smuzhiyun------------------------------------
860*4882a593Smuzhiyun
861*4882a593SmuzhiyunThe function name to use when creating the function directory is "printer".
862*4882a593SmuzhiyunThe printer function provides these attributes in its function directory:
863*4882a593Smuzhiyun
864*4882a593Smuzhiyun	==========	===========================================
865*4882a593Smuzhiyun	pnp_string	Data to be passed to the host in pnp string
866*4882a593Smuzhiyun	q_len		Number of requests per endpoint
867*4882a593Smuzhiyun	==========	===========================================
868*4882a593Smuzhiyun
869*4882a593SmuzhiyunTesting the PRINTER function
870*4882a593Smuzhiyun----------------------------
871*4882a593Smuzhiyun
872*4882a593SmuzhiyunThe most basic testing:
873*4882a593Smuzhiyun
874*4882a593Smuzhiyundevice: run the gadget::
875*4882a593Smuzhiyun
876*4882a593Smuzhiyun	# ls -l /devices/virtual/usb_printer_gadget/
877*4882a593Smuzhiyun
878*4882a593Smuzhiyunshould show g_printer<number>.
879*4882a593Smuzhiyun
880*4882a593SmuzhiyunIf udev is active, then /dev/g_printer<number> should appear automatically.
881*4882a593Smuzhiyun
882*4882a593Smuzhiyunhost:
883*4882a593Smuzhiyun
884*4882a593SmuzhiyunIf udev is active, then e.g. /dev/usb/lp0 should appear.
885*4882a593Smuzhiyun
886*4882a593Smuzhiyunhost->device transmission:
887*4882a593Smuzhiyun
888*4882a593Smuzhiyundevice::
889*4882a593Smuzhiyun
890*4882a593Smuzhiyun	# cat /dev/g_printer<number>
891*4882a593Smuzhiyun
892*4882a593Smuzhiyunhost::
893*4882a593Smuzhiyun
894*4882a593Smuzhiyun	# cat > /dev/usb/lp0
895*4882a593Smuzhiyun
896*4882a593Smuzhiyundevice->host transmission::
897*4882a593Smuzhiyun
898*4882a593Smuzhiyun	# cat > /dev/g_printer<number>
899*4882a593Smuzhiyun
900*4882a593Smuzhiyunhost::
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun	# cat /dev/usb/lp0
903*4882a593Smuzhiyun
904*4882a593SmuzhiyunMore advanced testing can be done with the prn_example
905*4882a593Smuzhiyundescribed in Documentation/usb/gadget_printer.rst.
906*4882a593Smuzhiyun
907*4882a593Smuzhiyun
908*4882a593Smuzhiyun20. UAC1 function (virtual ALSA card, using u_audio API)
909*4882a593Smuzhiyun========================================================
910*4882a593Smuzhiyun
911*4882a593SmuzhiyunThe function is provided by usb_f_uac1.ko module.
912*4882a593SmuzhiyunIt will create a virtual ALSA card and the audio streams are simply
913*4882a593Smuzhiyunsinked to and sourced from it.
914*4882a593Smuzhiyun
915*4882a593SmuzhiyunFunction-specific configfs interface
916*4882a593Smuzhiyun------------------------------------
917*4882a593Smuzhiyun
918*4882a593SmuzhiyunThe function name to use when creating the function directory is "uac1".
919*4882a593SmuzhiyunThe uac1 function provides these attributes in its function directory:
920*4882a593Smuzhiyun
921*4882a593Smuzhiyun	================ ====================================================
922*4882a593Smuzhiyun	c_chmask         capture channel mask
923*4882a593Smuzhiyun	c_srate          list of capture sampling rates (comma-separated)
924*4882a593Smuzhiyun	c_ssize          capture sample size (bytes)
925*4882a593Smuzhiyun	c_mute_present   capture mute control enable
926*4882a593Smuzhiyun	c_volume_present capture volume control enable
927*4882a593Smuzhiyun	c_volume_min     capture volume control min value (in 1/256 dB)
928*4882a593Smuzhiyun	c_volume_max     capture volume control max value (in 1/256 dB)
929*4882a593Smuzhiyun	c_volume_res     capture volume control resolution (in 1/256 dB)
930*4882a593Smuzhiyun	p_chmask         playback channel mask
931*4882a593Smuzhiyun	p_srate          list of playback sampling rates (comma-separated)
932*4882a593Smuzhiyun	p_ssize          playback sample size (bytes)
933*4882a593Smuzhiyun	p_mute_present   playback mute control enable
934*4882a593Smuzhiyun	p_volume_present playback volume control enable
935*4882a593Smuzhiyun	p_volume_min     playback volume control min value (in 1/256 dB)
936*4882a593Smuzhiyun	p_volume_max     playback volume control max value (in 1/256 dB)
937*4882a593Smuzhiyun	p_volume_res     playback volume control resolution (in 1/256 dB)
938*4882a593Smuzhiyun	req_number       the number of pre-allocated requests for both capture
939*4882a593Smuzhiyun	                 and playback
940*4882a593Smuzhiyun	function_name    name of the interface
941*4882a593Smuzhiyun	================ ====================================================
942*4882a593Smuzhiyun
943*4882a593SmuzhiyunThe attributes have sane default values.
944*4882a593Smuzhiyun
945*4882a593SmuzhiyunTesting the UAC1 function
946*4882a593Smuzhiyun-------------------------
947*4882a593Smuzhiyun
948*4882a593Smuzhiyundevice: run the gadget
949*4882a593Smuzhiyunhost: aplay -l # should list our USB Audio Gadget
950*4882a593Smuzhiyun
951*4882a593SmuzhiyunThis function does not require real hardware support, it just
952*4882a593Smuzhiyunsends a stream of audio data to/from the host. In order to
953*4882a593Smuzhiyunactually hear something at the device side, a command similar
954*4882a593Smuzhiyunto this must be used at the device side::
955*4882a593Smuzhiyun
956*4882a593Smuzhiyun	$ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
957*4882a593Smuzhiyun
958*4882a593Smuzhiyune.g.::
959*4882a593Smuzhiyun
960*4882a593Smuzhiyun	$ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \
961*4882a593Smuzhiyun	  aplay -D default:CARD=OdroidU3
962