userspace_interface

file: /proc/sys/kernel/userspace_interface
variable: kernel.userspace_interface
Official reference

The user can interact with Raw Gadget by opening /dev/raw-gadget and issuing ioctl calls; see the comments in include/uapi/linux/usb/raw_gadget.h for details. Multiple Raw Gadget instances (bound to different UDCs) can be used at the same time.

A typical usage scenario of Raw Gadget:

  1. Create a Raw Gadget instance by opening /dev/raw-gadget.
  2. Initialize the instance via USB_RAW_IOCTL_INIT.
  3. Launch the instance with USB_RAW_IOCTL_RUN.
  4. In a loop issue USB_RAW_IOCTL_EVENT_FETCH to receive events from Raw Gadget and react to those depending on what kind of USB gadget must be implemented.

Note that some UDC drivers have fixed addresses assigned to endpoints, and therefore arbitrary endpoint addresses cannot be used in the descriptors. Nevertheless, Raw Gadget provides a UDC-agnostic way to write USB gadgets. Once USB_RAW_EVENT_CONNECT is received via USB_RAW_IOCTL_EVENT_FETCH, USB_RAW_IOCTL_EPS_INFO can be used to find out information about the endpoints that the UDC driver has. Based on that, userspace must choose UDC endpoints for the gadget and assign addresses in the endpoint descriptors correspondingly.

Raw Gadget usage examples and a test suite:

https://github.com/xairy/raw-gadget