Andrzej Pietrasiewicz | e38eb2c | 2014-12-16 14:56:25 +0100 | [diff] [blame] | 1 | This file summarizes information on basic testing of USB functions |
| 2 | provided by gadgets. |
| 3 | |
| 4 | 1. ACM function |
Andrzej Pietrasiewicz | d5862ca | 2014-12-16 14:56:26 +0100 | [diff] [blame] | 5 | 2. ECM function |
Andrzej Pietrasiewicz | 7bfbc6e | 2014-12-16 14:56:27 +0100 | [diff] [blame] | 6 | 3. ECM subset function |
Andrzej Pietrasiewicz | 4ca560a | 2014-12-16 14:56:28 +0100 | [diff] [blame] | 7 | 4. EEM function |
Andrzej Pietrasiewicz | 2c0f62f | 2014-12-16 14:56:29 +0100 | [diff] [blame] | 8 | 5. FFS function |
Andrzej Pietrasiewicz | f7e3c3c | 2014-12-16 14:56:30 +0100 | [diff] [blame] | 9 | 6. HID function |
Andrzej Pietrasiewicz | ec91aff | 2014-12-16 14:56:31 +0100 | [diff] [blame] | 10 | 7. LOOPBACK function |
Andrzej Pietrasiewicz | cdbe287 | 2014-12-16 14:56:32 +0100 | [diff] [blame] | 11 | 8. MASS STORAGE function |
Andrzej Pietrasiewicz | 0d6be59 | 2014-12-16 14:56:33 +0100 | [diff] [blame] | 12 | 9. MIDI function |
Andrzej Pietrasiewicz | 4d0fa79 | 2014-12-16 14:56:34 +0100 | [diff] [blame^] | 13 | 10. NCM function |
Andrzej Pietrasiewicz | e38eb2c | 2014-12-16 14:56:25 +0100 | [diff] [blame] | 14 | |
| 15 | |
| 16 | 1. ACM function |
| 17 | =============== |
| 18 | |
| 19 | The function is provided by usb_f_acm.ko module. |
| 20 | |
| 21 | Function-specific configfs interface |
| 22 | ------------------------------------ |
| 23 | |
| 24 | The function name to use when creating the function directory is "acm". |
| 25 | The ACM function provides just one attribute in its function directory: |
| 26 | |
| 27 | port_num |
| 28 | |
| 29 | The attribute is read-only. |
| 30 | |
| 31 | There can be at most 4 ACM/generic serial/OBEX ports in the system. |
| 32 | |
| 33 | |
| 34 | Testing the ACM function |
| 35 | ------------------------ |
| 36 | |
| 37 | On the host: cat > /dev/ttyACM<X> |
| 38 | On the device : cat /dev/ttyGS<Y> |
| 39 | |
| 40 | then the other way round |
| 41 | |
| 42 | On the device: cat > /dev/ttyGS<Y> |
| 43 | On the host: cat /dev/ttyACM<X> |
Andrzej Pietrasiewicz | d5862ca | 2014-12-16 14:56:26 +0100 | [diff] [blame] | 44 | |
| 45 | 2. ECM function |
| 46 | =============== |
| 47 | |
| 48 | The function is provided by usb_f_ecm.ko module. |
| 49 | |
| 50 | Function-specific configfs interface |
| 51 | ------------------------------------ |
| 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 | Except for ifname they can be written to until the function is linked to a |
| 67 | configuration. The ifname is read-only and contains the name of the interface |
| 68 | which was assigned by the net core, e. g. usb0. |
| 69 | |
| 70 | Testing the ECM function |
| 71 | ------------------------ |
| 72 | |
| 73 | Configure IP addresses of the device and the host. Then: |
| 74 | |
| 75 | On the device: ping <host's IP> |
| 76 | On the host: ping <device's IP> |
Andrzej Pietrasiewicz | 7bfbc6e | 2014-12-16 14:56:27 +0100 | [diff] [blame] | 77 | |
| 78 | 3. ECM subset function |
| 79 | ====================== |
| 80 | |
| 81 | The function is provided by usb_f_ecm_subset.ko module. |
| 82 | |
| 83 | Function-specific configfs interface |
| 84 | ------------------------------------ |
| 85 | |
| 86 | The function name to use when creating the function directory is "geth". |
| 87 | The ECM subset function provides these attributes in its function directory: |
| 88 | |
| 89 | ifname - network device interface name associated with this |
| 90 | function instance |
| 91 | qmult - queue length multiplier for high and super speed |
| 92 | host_addr - MAC address of host's end of this |
| 93 | Ethernet over USB link |
| 94 | dev_addr - MAC address of device's end of this |
| 95 | Ethernet over USB link |
| 96 | |
| 97 | and after creating the functions/ecm.<instance name> they contain default |
| 98 | values: qmult is 5, dev_addr and host_addr are randomly selected. |
| 99 | Except for ifname they can be written to until the function is linked to a |
| 100 | configuration. The ifname is read-only and contains the name of the interface |
| 101 | which was assigned by the net core, e. g. usb0. |
| 102 | |
| 103 | Testing the ECM subset function |
| 104 | ------------------------------- |
| 105 | |
| 106 | Configure IP addresses of the device and the host. Then: |
| 107 | |
| 108 | On the device: ping <host's IP> |
| 109 | On the host: ping <device's IP> |
Andrzej Pietrasiewicz | 4ca560a | 2014-12-16 14:56:28 +0100 | [diff] [blame] | 110 | |
| 111 | 4. EEM function |
| 112 | =============== |
| 113 | |
| 114 | The function is provided by usb_f_eem.ko module. |
| 115 | |
| 116 | Function-specific configfs interface |
| 117 | ------------------------------------ |
| 118 | |
| 119 | The function name to use when creating the function directory is "eem". |
| 120 | The EEM function provides these attributes in its function directory: |
| 121 | |
| 122 | ifname - network device interface name associated with this |
| 123 | function instance |
| 124 | qmult - queue length multiplier for high and super speed |
| 125 | host_addr - MAC address of host's end of this |
| 126 | Ethernet over USB link |
| 127 | dev_addr - MAC address of device's end of this |
| 128 | Ethernet over USB link |
| 129 | |
| 130 | and after creating the functions/eem.<instance name> they contain default |
| 131 | values: qmult is 5, dev_addr and host_addr are randomly selected. |
| 132 | Except for ifname they can be written to until the function is linked to a |
| 133 | configuration. The ifname is read-only and contains the name of the interface |
| 134 | which was assigned by the net core, e. g. usb0. |
| 135 | |
| 136 | Testing the EEM function |
| 137 | ------------------------ |
| 138 | |
| 139 | Configure IP addresses of the device and the host. Then: |
| 140 | |
| 141 | On the device: ping <host's IP> |
| 142 | On the host: ping <device's IP> |
Andrzej Pietrasiewicz | 2c0f62f | 2014-12-16 14:56:29 +0100 | [diff] [blame] | 143 | |
| 144 | 5. FFS function |
| 145 | =============== |
| 146 | |
| 147 | The function is provided by usb_f_fs.ko module. |
| 148 | |
| 149 | Function-specific configfs interface |
| 150 | ------------------------------------ |
| 151 | |
| 152 | The function name to use when creating the function directory is "ffs". |
| 153 | The function directory is intentionally empty and not modifiable. |
| 154 | |
| 155 | After creating the directory there is a new instance (a "device") of FunctionFS |
| 156 | available in the system. Once a "device" is available, the user should follow |
| 157 | the standard procedure for using FunctionFS (mount it, run the userspace |
| 158 | process which implements the function proper). The gadget should be enabled |
| 159 | by writing a suitable string to usb_gadget/<gadget>/UDC. |
| 160 | |
| 161 | Testing the FFS function |
| 162 | ------------------------ |
| 163 | |
| 164 | On the device: start the function's userspace daemon, enable the gadget |
| 165 | On the host: use the USB function provided by the device |
Andrzej Pietrasiewicz | f7e3c3c | 2014-12-16 14:56:30 +0100 | [diff] [blame] | 166 | |
| 167 | 6. HID function |
| 168 | =============== |
| 169 | |
| 170 | The function is provided by usb_f_hid.ko module. |
| 171 | |
| 172 | Function-specific configfs interface |
| 173 | ------------------------------------ |
| 174 | |
| 175 | The function name to use when creating the function directory is "hid". |
| 176 | The HID function provides these attributes in its function directory: |
| 177 | |
| 178 | protocol - HID protocol to use |
| 179 | report_desc - data to be used in HID reports, except data |
| 180 | passed with /dev/hidg<X> |
| 181 | report_length - HID report length |
| 182 | subclass - HID subclass to use |
| 183 | |
| 184 | For a keyboard the protocol and the subclass are 1, the report_length is 8, |
| 185 | while the report_desc is: |
| 186 | |
| 187 | $ hd my_report_desc |
| 188 | 00000000 05 01 09 06 a1 01 05 07 19 e0 29 e7 15 00 25 01 |..........)...%.| |
| 189 | 00000010 75 01 95 08 81 02 95 01 75 08 81 03 95 05 75 01 |u.......u.....u.| |
| 190 | 00000020 05 08 19 01 29 05 91 02 95 01 75 03 91 03 95 06 |....).....u.....| |
| 191 | 00000030 75 08 15 00 25 65 05 07 19 00 29 65 81 00 c0 |u...%e....)e...| |
| 192 | 0000003f |
| 193 | |
| 194 | Such a sequence of bytes can be stored to the attribute with echo: |
| 195 | |
| 196 | $ echo -ne \\x05\\x01\\x09\\x06\\xa1..... |
| 197 | |
| 198 | Testing the HID function |
| 199 | ------------------------ |
| 200 | |
| 201 | Device: |
| 202 | - create the gadget |
| 203 | - connect the gadget to a host, preferably not the one used |
| 204 | to control the gadget |
| 205 | - run a program which writes to /dev/hidg<N>, e.g. |
| 206 | a userspace program found in Documentation/usb/gadget_hid.txt: |
| 207 | |
| 208 | $ ./hid_gadget_test /dev/hidg0 keyboard |
| 209 | |
| 210 | Host: |
| 211 | - observe the keystrokes from the gadget |
Andrzej Pietrasiewicz | ec91aff | 2014-12-16 14:56:31 +0100 | [diff] [blame] | 212 | |
| 213 | 7. LOOPBACK function |
| 214 | ==================== |
| 215 | |
| 216 | The function is provided by usb_f_ss_lb.ko module. |
| 217 | |
| 218 | Function-specific configfs interface |
| 219 | ------------------------------------ |
| 220 | |
| 221 | The function name to use when creating the function directory is "Loopback". |
| 222 | The LOOPBACK function provides these attributes in its function directory: |
| 223 | |
| 224 | qlen - depth of loopback queue |
| 225 | bulk_buflen - buffer length |
| 226 | |
| 227 | Testing the LOOPBACK function |
| 228 | ----------------------------- |
| 229 | |
| 230 | device: run the gadget |
| 231 | host: test-usb |
| 232 | |
| 233 | http://www.linux-usb.org/usbtest/testusb.c |
Andrzej Pietrasiewicz | cdbe287 | 2014-12-16 14:56:32 +0100 | [diff] [blame] | 234 | |
| 235 | 8. MASS STORAGE function |
| 236 | ======================== |
| 237 | |
| 238 | The function is provided by usb_f_mass_storage.ko module. |
| 239 | |
| 240 | Function-specific configfs interface |
| 241 | ------------------------------------ |
| 242 | |
| 243 | The function name to use when creating the function directory is "mass_storage". |
| 244 | The MASS STORAGE function provides these attributes in its directory: |
| 245 | files: |
| 246 | |
| 247 | stall - Set to permit function to halt bulk endpoints. |
| 248 | Disabled on some USB devices known not to work |
| 249 | correctly. You should set it to true. |
| 250 | num_buffers - Number of pipeline buffers. Valid numbers |
| 251 | are 2..4. Available only if |
| 252 | CONFIG_USB_GADGET_DEBUG_FILES is set. |
| 253 | |
| 254 | and a default lun.0 directory corresponding to SCSI LUN #0. |
| 255 | |
| 256 | A new lun can be added with mkdir: |
| 257 | |
| 258 | $ mkdir functions/mass_storage.0/partition.5 |
| 259 | |
| 260 | Lun numbering does not have to be continuous, except for lun #0 which is |
| 261 | created by default. A maximum of 8 luns can be specified and they all must be |
| 262 | named following the <name>.<number> scheme. The numbers can be 0..8. |
| 263 | Probably a good convention is to name the luns "lun.<number>", |
| 264 | although it is not mandatory. |
| 265 | |
| 266 | In each lun directory there are the following attribute files: |
| 267 | |
| 268 | file - The path to the backing file for the LUN. |
| 269 | Required if LUN is not marked as removable. |
| 270 | ro - Flag specifying access to the LUN shall be |
| 271 | read-only. This is implied if CD-ROM emulation |
| 272 | is enabled as well as when it was impossible |
| 273 | to open "filename" in R/W mode. |
| 274 | removable - Flag specifying that LUN shall be indicated as |
| 275 | being removable. |
| 276 | cdrom - Flag specifying that LUN shall be reported as |
| 277 | being a CD-ROM. |
| 278 | nofua - Flag specifying that FUA flag |
| 279 | in SCSI WRITE(10,12) |
| 280 | |
| 281 | Testing the MASS STORAGE function |
| 282 | --------------------------------- |
| 283 | |
| 284 | device: connect the gadget, enable it |
| 285 | host: dmesg, see the USB drives appear (if system configured to automatically |
| 286 | mount) |
Andrzej Pietrasiewicz | 0d6be59 | 2014-12-16 14:56:33 +0100 | [diff] [blame] | 287 | |
| 288 | 9. MIDI function |
| 289 | ================ |
| 290 | |
| 291 | The function is provided by usb_f_midi.ko module. |
| 292 | |
| 293 | Function-specific configfs interface |
| 294 | ------------------------------------ |
| 295 | |
| 296 | The function name to use when creating the function directory is "midi". |
| 297 | The MIDI function provides these attributes in its function directory: |
| 298 | |
| 299 | buflen - MIDI buffer length |
| 300 | id - ID string for the USB MIDI adapter |
| 301 | in_ports - number of MIDI input ports |
| 302 | index - index value for the USB MIDI adapter |
| 303 | out_ports - number of MIDI output ports |
| 304 | qlen - USB read request queue length |
| 305 | |
| 306 | Testing the MIDI function |
| 307 | ------------------------- |
| 308 | |
| 309 | There are two cases: playing a mid from the gadget to |
| 310 | the host and playing a mid from the host to the gadget. |
| 311 | |
| 312 | 1) Playing a mid from the gadget to the host |
| 313 | host) |
| 314 | |
| 315 | $ arecordmidi -l |
| 316 | Port Client name Port name |
| 317 | 14:0 Midi Through Midi Through Port-0 |
| 318 | 24:0 MIDI Gadget MIDI Gadget MIDI 1 |
| 319 | $ arecordmidi -p 24:0 from_gadget.mid |
| 320 | |
| 321 | gadget) |
| 322 | |
| 323 | $ aplaymidi -l |
| 324 | Port Client name Port name |
| 325 | 20:0 f_midi f_midi |
| 326 | |
| 327 | $ aplaymidi -p 20:0 to_host.mid |
| 328 | |
| 329 | 2) Playing a mid from the host to the gadget |
| 330 | gadget) |
| 331 | |
| 332 | $ arecordmidi -l |
| 333 | Port Client name Port name |
| 334 | 20:0 f_midi f_midi |
| 335 | |
| 336 | $ arecordmidi -p 20:0 from_host.mid |
| 337 | |
| 338 | host) |
| 339 | |
| 340 | $ aplaymidi -l |
| 341 | Port Client name Port name |
| 342 | 14:0 Midi Through Midi Through Port-0 |
| 343 | 24:0 MIDI Gadget MIDI Gadget MIDI 1 |
| 344 | |
| 345 | $ aplaymidi -p24:0 to_gadget.mid |
| 346 | |
| 347 | The from_gadget.mid should sound identical to the to_host.mid. |
| 348 | The from_host.id should sound identical to the to_gadget.mid. |
| 349 | |
| 350 | MIDI files can be played to speakers/headphones with e.g. timidity installed |
| 351 | |
| 352 | $ aplaymidi -l |
| 353 | Port Client name Port name |
| 354 | 14:0 Midi Through Midi Through Port-0 |
| 355 | 24:0 MIDI Gadget MIDI Gadget MIDI 1 |
| 356 | 128:0 TiMidity TiMidity port 0 |
| 357 | 128:1 TiMidity TiMidity port 1 |
| 358 | 128:2 TiMidity TiMidity port 2 |
| 359 | 128:3 TiMidity TiMidity port 3 |
| 360 | |
| 361 | $ aplaymidi -p 128:0 file.mid |
| 362 | |
| 363 | MIDI ports can be logically connected using the aconnect utility, e.g.: |
| 364 | |
| 365 | $ aconnect 24:0 128:0 # try it on the host |
| 366 | |
| 367 | After the gadget's MIDI port is connected to timidity's MIDI port, |
| 368 | whatever is played at the gadget side with aplaymidi -l is audible |
| 369 | in host's speakers/headphones. |
Andrzej Pietrasiewicz | 4d0fa79 | 2014-12-16 14:56:34 +0100 | [diff] [blame^] | 370 | |
| 371 | 10. NCM function |
| 372 | ================ |
| 373 | |
| 374 | The function is provided by usb_f_ncm.ko module. |
| 375 | |
| 376 | Function-specific configfs interface |
| 377 | ------------------------------------ |
| 378 | |
| 379 | The function name to use when creating the function directory is "ncm". |
| 380 | The NCM function provides these attributes in its function directory: |
| 381 | |
| 382 | ifname - network device interface name associated with this |
| 383 | function instance |
| 384 | qmult - queue length multiplier for high and super speed |
| 385 | host_addr - MAC address of host's end of this |
| 386 | Ethernet over USB link |
| 387 | dev_addr - MAC address of device's end of this |
| 388 | Ethernet over USB link |
| 389 | |
| 390 | and after creating the functions/ncm.<instance name> they contain default |
| 391 | values: qmult is 5, dev_addr and host_addr are randomly selected. |
| 392 | Except for ifname they can be written to until the function is linked to a |
| 393 | configuration. The ifname is read-only and contains the name of the interface |
| 394 | which was assigned by the net core, e. g. usb0. |
| 395 | |
| 396 | Testing the NCM function |
| 397 | ------------------------ |
| 398 | |
| 399 | Configure IP addresses of the device and the host. Then: |
| 400 | |
| 401 | On the device: ping <host's IP> |
| 402 | On the host: ping <device's IP> |