Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ unitdir=$(sysconfdir)/systemd/system

UNITS = \
usbipd.service \
usbip-device@.service
usbip-device@.service \
usbip-import@.service

SCRIPTS = \
configure-usbip-device.sh \
remove-usbip-device.sh
remove-usbip-device.sh \
attach-usbip-device.sh \
detach-usbip-device.sh

all:

Expand Down
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ To install the systemd unit, run `make install` in the source
directory, which will place the support scripts into `/sbin` and the
systemd unit into `/etc/systemd/system`.

## Configuration
## Server Configuration

Create one or files in `/etc/usbip-device` named `<device_name>.conf`.
These files **must** contain the following configuration keys:


- `USB_IDVENDOR` -- Vendor ID.
- `USB_IDPRODUCT` -- Product ID.
- `USB_IDVENDOR` -- Vendor ID.
- `USB_IDPRODUCT` -- Product ID.

For example, to share a device with vendor:product 03f0:8607, create a file
called /etc/usbip_devices/mouse.conf
Expand All @@ -34,3 +34,36 @@ To share the device immediately:
To stop sharing it:

systemctl stop usbip-device@mouse


## Client Configuration

Client part is configured very similar to server one, with a few additions:

* files in `/etc/usbip-devices` must be named `<device_name>.import.conf`
* besides `USB_IDVENDOR` and `USB_IDPRODUCT` there should also be `HOST` key, identifying hostname or IP address of the server that shares USB device

Example:
```
USB_IDVENDOR=03f0
USB_IDPRODUCT=8607
HOST=192.168.1.54
```

To enable attaching to remote device at boot, run:

```
systemctl enable usbip-import@mouse
```

To attach device:

```
systemctl start usbip-import@mouse
```

To detach device:

```
systemctl stop usbip-import@mouse
```
3 changes: 3 additions & 0 deletions attach-usbip-device.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e
BUS_ID=`usbip list -r ${HOST}|grep ${USB_IDVENDOR}:${USB_IDPRODUCT}|cut -d\: -f 1|xargs`
[[ -z "$BUS_ID" ]] || /usr/bin/usbip attach -r ${HOST} -b $BUS_ID
3 changes: 3 additions & 0 deletions detach-usbip-device.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e
PORT_ID=`usbip port |awk -F'[ /]+' '/^Port/ { printf $2 } /\(.+:.+\)$/ {printf $NF"#"} /usbip:/ { print $NF}'|grep ${USB_IDVENDOR}:${USB_IDPRODUCT}|cut -d\: -f1`
[[ -z "$PORT_ID" ]] || /usr/bin/usbip detach -p $PORT_ID
2 changes: 1 addition & 1 deletion remove-usbip-device.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash -e
BUS_ID=`/usr/sbin/usbip list -p -l | grep -i "#usbid=${USB_IDVENDOR}:${USB_IDPRODUCT}#" | cut '-d#' -f1`
[[ -z "$BUS_ID" ]] || /usr/sbin/usbip unbind --$BUS_ID

12 changes: 12 additions & 0 deletions usbip-import@.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=USB/IP Device import %I

[Service]
EnvironmentFile=/etc/usbip-devices/%i.import.conf
RemainAfterExit=yes
ExecStartPre=/sbin/modprobe vhci_hcd
ExecStart=/usr/sbin/attach-usbip-device %i
ExecStop=/usr/sbin/detach-usbip-device %i

[Install]
WantedBy=multi-user.target