#usb #gadget #peripheral #linux-kernel #networking #configfs #functionfs

usb-gadget

Expose standard or fully custom USB peripherals (gadgets) through a USB device controller (UDC) on Linux

11 releases (6 breaking)

new 0.7.1 Apr 22, 2024
0.7.0 Mar 14, 2024
0.6.0 Nov 11, 2023
0.5.2 Nov 9, 2023
0.1.0 Sep 29, 2023

#160 in Unix APIs

Download history 1/week @ 2024-01-03 2/week @ 2024-01-10 4/week @ 2024-01-17 4/week @ 2024-01-24 38/week @ 2024-01-31 7/week @ 2024-02-07 4/week @ 2024-02-14 20/week @ 2024-02-21 34/week @ 2024-02-28 17/week @ 2024-03-06 155/week @ 2024-03-13 29/week @ 2024-03-20 14/week @ 2024-03-27 27/week @ 2024-04-03 24/week @ 2024-04-10 157/week @ 2024-04-17

231 downloads per month
Used in 3 crates

Apache-2.0

180KB
4K SLoC

usb-gadget

crates.io page docs.rs page Apache 2.0 license

This library allows implementation of USB peripherals, so called USB gadgets, on Linux devices that have a USB device controller (UDC). Both, pre-defined USB functions and fully custom implementations of the USB interface are supported.

The following pre-defined USB functions, implemented by kernel drivers, are available:

  • network interface
    • CDC ECM
    • CDC ECM (subset)
    • CDC EEM
    • CDC NCM
    • RNDIS
  • serial port
    • CDC ACM
    • generic
  • human interface device (HID)
  • mass-storage device (MSD)

In addition fully custom USB functions can be implemented in user-mode Rust code.

Support for OS-specific descriptors and WebUSB is also provided.

Features

This crate provides the following optional features:

  • tokio: enables async support for custom USB functions on top of the Tokio runtime.

Requirements

The minimum support Rust version (MSRV) is 1.73.

A USB device controller (UDC) supported by Linux is required. Normally, standard PCs do not include an UDC. A Raspberry Pi 4 contains an UDC, which is connected to its USB-C port.

The following Linux kernel configuration options should be enabled for full functionality:

  • CONFIG_USB_GADGET
  • CONFIG_USB_CONFIGFS
  • CONFIG_USB_CONFIGFS_SERIAL
  • CONFIG_USB_CONFIGFS_ACM
  • CONFIG_USB_CONFIGFS_NCM
  • CONFIG_USB_CONFIGFS_ECM
  • CONFIG_USB_CONFIGFS_ECM_SUBSET
  • CONFIG_USB_CONFIGFS_RNDIS
  • CONFIG_USB_CONFIGFS_EEM
  • CONFIG_USB_CONFIGFS_MASS_STORAGE
  • CONFIG_USB_CONFIGFS_F_FS
  • CONFIG_USB_CONFIGFS_F_HID

root permissions are required to configure USB gadgets on Linux and the configfs filesystem needs to be mounted.

License

usb-gadget is licensed under the Apache 2.0 license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in usb-gadget by you, shall be licensed as Apache 2.0, without any additional terms or conditions.

Dependencies

~2–13MB
~127K SLoC