Commit 728af7c
committed
feat: implement native USB passthrough using Hyper-V sockets
Implements a robust USB device passthrough solution for WSL2 that uses
Hyper-V sockets instead of IP networking, eliminating issues with VPNs,
network configuration changes, and gateway instability.
This solution provides three main components:
1. Windows USB Service (usbservice.cpp/hpp)
- Enumerates USB devices using Windows Setup API
- Manages device attachment/detachment over Hyper-V socket
- Forwards USB Request Blocks (URBs) between host and guest
2. Linux Kernel Module (wsl_usb.c)
- Implements USB Host Controller Driver (HCD) interface
- Receives USB traffic over AF_VSOCK
- Emulates USB devices in Linux guest
3. WSL CLI Commands (usbclient.cpp/hpp)
- wsl --usb-list: List available USB devices
- wsl --usb-attach <device>: Attach USB device to WSL
- wsl --usb-detach <device>: Detach USB device from WSL
The implementation uses a binary protocol over Hyper-V sockets (port
0x5553422) with message types for device enumeration, attachment,
detachment, and URB forwarding. This provides network-independent USB
passthrough that works reliably with any host networking configuration.
Benefits:
- No dependency on IP networking or gateway addresses
- Works with VPNs and complex network configurations
- Native WSL integration, no third-party tools required
- Simple user experience with intuitive CLI commands
- Better performance without IP stack overhead
Closes [#13421](https://github.com/obrobrio2000/WSL/issues/13421)
Signed-off-by: Giovanni Magliocchetti <[email protected]>1 parent 427645e commit 728af7c
5 files changed
+507
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
112 | 114 | | |
113 | 115 | | |
114 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
0 commit comments