{{{#!html

  1. USB On-The-Go (OTG)
    1. USB Host Mode
    2. USB Device Mode (UDC)
      1. g_ether Gadget
      2. g_mass_storage - USB Mass Storage Device
      3. g_file_storage - USB Mass Storage Device
      4. g_serial - Serial Device Gadget
      5. g_cdc - Composite Ethernet + Serial Gadget
      6. g_multi - Composite Ethernet + Serial + Mass Storage Gadget
      7. g_hid - Human Interface Device (HID) Gadget
      8. g_webcam - Composite USB Audio and Video Class Gadget
      9. g_ncm - USB CDC NCM subclass Ethernet Gadget
      10. ConfigFs
  2. OpenWrt OTG

USB On-The-Go (OTG)

See OTG for more info.

USB Host Mode

A Host mode cable allows connecting to a USB device. No special configuration is necessary for this.

USB Device Mode (UDC)

A Device mode cable allows connection to a USB host such as a PC.

When used in this mode, the device needs to have a 'Gadget driver' loaded which implements the personality of the device type you want.

There are several Linux gadget drivers in today's linux kernel. These can be found under the Device Drivers -> USB support -> USB Gadget Support menu:

Additionally The Linux Configfs (CONFIG_CONFIGFS_FS) support allows complete dynamic configuration of gadget devices from userspace in which case you can create a single configuration or multi-configuration composite device with one or more of the functions available from drivers/usb/gadget/udc/functions. See below for more details on how to use this.

Note that only one gadget driver (device personality) can be loaded at a time but there are some 'composite' gadget drivers that behave as 'composite devices' meaning they have multiple endpoints per USB device. This will seem familiar if you think of how a modern smart-phone works. Take an Android phone for example: When plugged into a host PC via micro-USB OTG, it will behave as a storage device (MTP), however if you want to have it behave as a serial debug device you have to go into the developer menu and select this option. Note that modern smartphones no longer behave as 'USB Mass Storage' devices as this protocol does not allow the device OS to access the filesystem at the same time the host PC does - instead these devices act as an MTP (Media Transfer Protocol) device.

Note that the Vendor ID (VID) and Device ID (DID) that is presented to the USB host is configuable (see here for details)

g_ether Gadget

The g_ether gadget driver behaves as a USB-to-Ethernet dongle. Once loaded the device-mode system will add a 'usb<n>' network device which can be used the same as any other network device. On the USB host system, a similar network device will appear as long as a driver supporting the 'CDC Ethernet' standard is available.

This module can be built with additional support:

Example:

Linux Host Notes:

Windows Host Notes:

Reference:

g_mass_storage - USB Mass Storage Device

The g_file_storage driver behaves as a USB Mass Storage device such as a USB hard-disk or USB flash drive. You can decide whether to use a 'file' as a backing store, or a block device (ie a flash partition, or a physical disk). The file/device is provided to the module via the 'file' module parameter.

If using a backing storage 'file' you must create it beforehand with its desired size. For example to create a 64MB backing store:

dd bs=1M count=64 if=/dev/zero of=/backing_file

To use this as a backing store:

modprobe g_mass_storage file=/backing_file

References:

g_file_storage - USB Mass Storage Device

The g_file_storage driver behaves as a USB Mass Storage device such as a USB hard-disk or USB flash drive. You can decide whether to use a 'file' as a backing store, or a block device (ie a flash partition, or a physical disk). The file/device is provided to the module via the 'file' module parameter.

This gadget driver was repaced with g_mass_storage in Linux 3.8

Example (using the first physical disk (/dev/sda) as a backing store):

Using a file as a backing store:

Reference:

g_serial - Serial Device Gadget

The Serial Gadget supports CDC-ACM and CDC-OBEX which can inter-operate with the MS-Windows hosts or with Linux hosts using the 'cdc-acm' driver to create a 'USB-to-Serial' connection.

Example:

Linux USB Host notes:

Windows USB Host notes:

Reference:

g_cdc - Composite Ethernet + Serial Gadget

The g_cdc gadget supports two functions in one configuration:

Example:

Linux USB Host notes:

Windows USB Host notes:

g_multi - Composite Ethernet + Serial + Mass Storage Gadget

The g_multi gadget supports multiple functions in one configuration:

Example:

Linux USB Host notes:

Windows USB Host notes:

References:

g_hid - Human Interface Device (HID) Gadget

The HID gadget driver provides generic emulation of USB Human Interface Devices (HID), for example keyboards, mice, touchscreens, etc

Example:

References:

g_webcam - Composite USB Audio and Video Class Gadget

The g_webcam gadget driver provides a Composite USB Audio and Video Class device.

Example:

Linux USB Host notes:

Windows USB Host notes:

g_ncm - USB CDC NCM subclass Ethernet Gadget

The g_ncm gadget driver provides a a USB CDC NCM subclass. NCM is an advanced protocol for Ethernet encapsulation, allowing grouping of several ethernet frames into one USB transfer with various alignment possibilities.

Example:

Linux USB Host notes:

Windows USB Host notes:

ConfigFs

The Linux Configfs (CONFIG_CONFIGFS_FS) support allows complete dynamic configuration of gadget devices from userspace in which case you can create a single configuration or multi-configuration composite device with one or more of the functions available from drivers/usb/gadget/udc/functions:

Note that not all of the above kernel modules may be available depending on your kernel configuration or BSP.

Examples:

References:

OpenWrt OTG

OpenWrt packages several of the above Linux kernel modules as packages:

You must have gadget support enabled:

Note that all of these packages will attempt to autoload their respective kernel module so whichever one is alphabetically first will be loaded. You can see what is loaded by looking at the current modules:

lsmod | grep g_*