https://github.com/shadowblip/virtual-usb-rs
https://github.com/shadowblip/virtual-usb-rs
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/shadowblip/virtual-usb-rs
- Owner: ShadowBlip
- Created: 2024-03-24T22:01:41.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-13T00:43:26.000Z (over 1 year ago)
- Last Synced: 2025-04-01T19:14:54.983Z (about 1 year ago)
- Language: Rust
- Size: 122 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.