Skip to content

Latest commit

 

History

History
47 lines (31 loc) · 1.59 KB

README.md

File metadata and controls

47 lines (31 loc) · 1.59 KB

virtual-usb-rs

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.

Usage

Creation

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.

Handling Transfers

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 endpoint
  • setupReq: the Setup packet
  • data: the payload data

Sending Data

To write data to an IN endpoint, call write() with the endpoint and data.

Stopping

To tear down the virtual USB device, call stop().

Example

Example implementations can be found in the examples folder.

References

This crate is heavily based off the great work of davetoaster and the VirtualUSBDevice project licensed under public domain.