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