@siwats/usbip-supervisor
v0.1.3
Published
USB/IP supervisor system for automatic device management between client and server
Maintainers
Readme
USB/IP Supervisor
A comprehensive USB/IP supervisor system for automatic device management between remote systems. Automatically monitors USB devices, handles hot-plugging, and maintains connections with automatic recovery.
Features
- Automatic Device Management: Automatically bind/unbind USB devices based on physical presence
- Hot-Plug Support: Detects device connection/disconnection via udev monitoring
- Network Recovery: Automatic reconnection on network dropouts
- Access Control: Per-device client authorization on server
- TUI Configuration: Interactive terminal-based configuration wizard
- systemd Integration: Run as system services with automatic startup
- Health Monitoring: Periodic device state verification and recovery
Requirements
- Operating System: Linux only
- Runtime: Bun >= 1.0
- System Packages:
usbip(usbip-utils package)- Kernel modules:
vhci-hcd,usbip-core
- Permissions: Root/sudo access for:
- Installing udev rules
- Running usbip commands
- Installing systemd services
Installation
Install via npm
# Install globally
npm install -g @siwats/usbip-supervisor
# Or use with bunx (no installation needed)
bunx @siwats/usbip-supervisor --helpInstall usbip
# Ubuntu/Debian
sudo apt install linux-tools-generic usbip
# Fedora/RHEL
sudo dnf install usbip-utils
# Arch Linux
sudo pacman -S usbipQuick Start
Server Setup
- Configure the server:
bunx @siwats/usbip-supervisor server --configureFollow the prompts to:
- Set listen address (default: 0.0.0.0)
- Set listen port (default: 3240)
- Add USB devices by vendor:product ID
- Specify allowed client IDs (optional)
- Start the server:
bunx @siwats/usbip-supervisor server- Install as systemd service (optional):
sudo bunx @siwats/usbip-supervisor server --install-systemd
sudo systemctl start usbip-supervisor-serverClient Setup
- Configure the client:
bunx @siwats/usbip-supervisor client --configureFollow the prompts to:
- Set client ID (unique identifier)
- Set server address and port
- Add USB devices to attach
- Start the client:
bunx @siwats/usbip-supervisor client- Install as systemd service (optional):
sudo bunx @siwats/usbip-supervisor client --install-systemd
sudo systemctl start usbip-supervisor-clientConfiguration
Configuration files are stored in ~/.config/usbip-supervisor/:
server.yaml- Server configurationclient.yaml- Client configuration
Server Configuration Example
listenAddress: 0.0.0.0
listenPort: 3240
logLevel: info
devices:
- path: "pci-0000:00:14.0-usb-0:1:1.0"
description: "USB Dongle on Port 1"
allowedClients:
- client1
- client2
- path: "pci-0000:00:14.0-usb-0:2:1.0"
description: "USB Dongle on Port 2"
allowedClients: [] # Allow all clientsClient Configuration Example
clientId: client1
serverAddress: 192.168.1.100
serverPort: 3240
logLevel: info
devices:
- path: "pci-0000:00:14.0-usb-0:1:1.0"
description: "USB Dongle from Server Port 1"Finding USB Device Paths
The supervisor uses USB by-path for device identification to uniquely identify each physical USB port. This allows you to use multiple identical USB devices.
Method 1: Using the Configuration Wizard (Recommended)
The easiest way is to use the interactive configuration wizard, which automatically detects and displays available USB devices with their paths:
# Server
bunx @siwats/usbip-supervisor server --configure
# Client
bunx @siwats/usbip-supervisor client --configureThe wizard will show all connected USB devices with their paths and allow you to select them by index number.
Method 2: Manual Discovery
You can manually find USB device paths using udevadm:
# List all USB devices with their paths
for dev in /dev/bus/usb/*/*; do
echo "Device: $dev"
udevadm info -q property $dev | grep -E "ID_PATH=|ID_VENDOR_ID=|ID_MODEL_ID=|ID_SERIAL="
echo
doneExample output:
Device: /dev/bus/usb/001/002
ID_PATH=pci-0000:00:14.0-usb-0:1:1.0
ID_VENDOR_ID=1234
ID_MODEL_ID=5678
ID_SERIAL=ABC123Understanding USB By-Path
USB by-path follows the physical topology of your USB bus:
- Format:
pci-<PCI_address>-usb-<port_chain> - Example:
pci-0000:00:14.0-usb-0:1:1.0pci-0000:00:14.0= PCI address of the USB controllerusb-0:1:1.0= USB port chain (bus:port.subport...)
Benefits:
- Uniquely identifies each physical USB port
- Stays consistent across reboots
- Allows multiple identical devices to be distinguished
- More reliable than vendor/product ID alone
Usage
Server Commands
# Start server with default config
bunx @siwats/usbip-supervisor server
# Start with custom config file
bunx @siwats/usbip-supervisor server --config /path/to/config.yaml
# Run configuration wizard
bunx @siwats/usbip-supervisor server --configure
# Install systemd service
sudo bunx @siwats/usbip-supervisor server --install-systemdClient Commands
# Start client with default config
bunx @siwats/usbip-supervisor client
# Start with custom config file
bunx @siwats/usbip-supervisor client --config /path/to/config.yaml
# Run configuration wizard
bunx @siwats/usbip-supervisor client --configure
# Install systemd service
sudo bunx @siwats/usbip-supervisor client --install-systemdsystemd Service Management
After installing the systemd service:
# Start service
sudo systemctl start usbip-supervisor-server # or -client
# Stop service
sudo systemctl stop usbip-supervisor-server
# Check status
sudo systemctl status usbip-supervisor-server
# View logs
sudo journalctl -u usbip-supervisor-server -f
# Enable auto-start on boot
sudo systemctl enable usbip-supervisor-serverHow It Works
Server
- Monitors configured USB devices via udev
- Automatically binds devices when they're plugged in
- Accepts client connections via TCP
- Notifies authorized clients when devices become available/unavailable
- Periodically verifies device states
Client
- Connects to server via TCP
- Receives notifications about device availability
- Automatically attaches remote devices
- Detects network dropouts and reconnects
- Periodically verifies device states and recovers if needed
Communication Protocol
- Length-prefixed JSON messages over TCP
- Automatic reconnection with exponential backoff
- Heartbeat mechanism to detect connection loss
- Message types:
DEVICE_BIND- Server tells client to attach deviceDEVICE_UNBIND- Server tells client to detach deviceDEVICE_STATUS_QUERY- Client queries device availabilityCONNECTION_STATUS_QUERY- Client requests available devices list
Troubleshooting
"usbip is not installed"
Install the usbip-utils package for your distribution (see Installation section).
"Failed to load USBIP modules"
Load the kernel modules manually:
sudo modprobe vhci-hcd
sudo modprobe usbip-core"Permission denied" errors
Some operations require root privileges. Either:
- Run with
sudo - Install the systemd service (runs as root)
- Add your user to appropriate groups
Device not appearing on client
- Check server logs:
sudo journalctl -u usbip-supervisor-server -f - Verify device is bound on server:
usbip list -l - Check client is authorized in server config
- Verify network connectivity between client and server
- Check client logs:
sudo journalctl -u usbip-supervisor-client -f
Connection keeps dropping
- Check network stability
- Verify firewall rules allow TCP traffic on configured port
- Check server logs for errors
Development
Build from source
git clone https://github.com/siwats/usbip-supervisor
cd usbip-supervisor
bun install
bun run devRun tests
bun testLicense
MIT
Author
Siwat
