An open API service indexing awesome lists of open source software.

https://github.com/shadowblip/virtual-usb-rs


https://github.com/shadowblip/virtual-usb-rs

Last synced: 9 months ago
JSON representation

Awesome Lists containing this project

README

          

# virtual-usb-rs

Rust crate for emulating a USB device using the [vhci_hcd]("https://github.com/torvalds/linux/blob/master/drivers/usb/usbip/vhci_hcd.c")
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](examples) folder.

## References

This crate is heavily based off the great work of [davetoaster](https://github.com/davetoaster)
and the [VirtualUSBDevice]("https://github.com/toasterllc/VirtualUSBDevice")
project licensed under public domain.