Rust crate for emulating a USB device using the vhci_hcd kernel module on Linux, allowing the creation of virtual USB devices that are visible to the system just like a real USB device is.
To create a virtual USB device, instantiate a VirtualUSBDevice (supplying
standard USB descriptors to the constructor), and call start()
.
To aid in creation of a new VirtualUSBDevice, the VirtualUSBDeviceBuilder can be used to correctly build a working USB device with the appropriate USB descriptors.
To handle USB transfers, call read()
. Before read()
returns, VirtualUSBDevice
will automatically handle standard USB requests (such as GET_STATUS
,
GET_DESCRIPTOR
, SET_CONFIGURATION
requests, and all IN transfers), and will
only return from read()
when there's an OUT transfer that it can't handle
itself. The returned Xfer
object represents the USB OUT transfer to be
performed, and contains these fields:
ep
: the transfer's endpointsetupReq
: the Setup packetdata
: the payload data
To write data to an IN endpoint, call write()
with the endpoint and data.
To tear down the virtual USB device, call stop()
.
Example implementations can be found in the examples folder.
This crate is heavily based off the great work of davetoaster and the VirtualUSBDevice project licensed under public domain.