1============== 2USB Raw Gadget 3============== 4 5USB Raw Gadget is a kernel module that provides a userspace interface for 6the USB Gadget subsystem. Essentially it allows to emulate USB devices 7from userspace. Enabled with CONFIG_USB_RAW_GADGET. Raw Gadget is 8currently a strictly debugging feature and shouldn't be used in 9production, use GadgetFS instead. 10 11Comparison to GadgetFS 12~~~~~~~~~~~~~~~~~~~~~~ 13 14Raw Gadget is similar to GadgetFS, but provides a more low-level and 15direct access to the USB Gadget layer for the userspace. The key 16differences are: 17 181. Every USB request is passed to the userspace to get a response, while 19 GadgetFS responds to some USB requests internally based on the provided 20 descriptors. However note, that the UDC driver might respond to some 21 requests on its own and never forward them to the Gadget layer. 22 232. GadgetFS performs some sanity checks on the provided USB descriptors, 24 while Raw Gadget allows you to provide arbitrary data as responses to 25 USB requests. 26 273. Raw Gadget provides a way to select a UDC device/driver to bind to, 28 while GadgetFS currently binds to the first available UDC. 29 304. Raw Gadget uses predictable endpoint names (handles) across different 31 UDCs (as long as UDCs have enough endpoints of each required transfer 32 type). 33 345. Raw Gadget has ioctl-based interface instead of a filesystem-based one. 35 36Userspace interface 37~~~~~~~~~~~~~~~~~~~ 38 39To create a Raw Gadget instance open /dev/raw-gadget. Multiple raw-gadget 40instances (bound to different UDCs) can be used at the same time. The 41interaction with the opened file happens through the ioctl() calls, see 42comments in include/uapi/linux/usb/raw_gadget.h for details. 43 44The typical usage of Raw Gadget looks like: 45 461. Open Raw Gadget instance via /dev/raw-gadget. 472. Initialize the instance via USB_RAW_IOCTL_INIT. 483. Launch the instance with USB_RAW_IOCTL_RUN. 494. In a loop issue USB_RAW_IOCTL_EVENT_FETCH calls to receive events from 50 Raw Gadget and react to those depending on what kind of USB device 51 needs to be emulated. 52 53Potential future improvements 54~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 55 56- Implement ioctl's for setting/clearing halt status on endpoints. 57 58- Reporting more events (suspend, resume, etc.) through 59 USB_RAW_IOCTL_EVENT_FETCH. 60 61- Support O_NONBLOCK I/O. 62