attach/linux/ — Linux USB attach via usbip/vhci (todo 9)
Presents the core/protocol emitter (nui::protocol::KinectV1Device, a
UsbDeviceBackend) as a Linux USB/IP-exportable virtual Kinect v1: a
userspace USB/IP server speaking the Kinect's three sibling-device
descriptors (camera 1-1, audio 1-2, motor 1-3 — see
core/protocol/wire.h) plus control transfers and iso-style stream packets,
attachable through the stock vhci-hcd kernel driver + usbip client CLI.
No out-of-tree kernel modules.
Status in THIS environment: runtime attach is [~] BLOCKED
Verified on this box (2026-11-25, same findings as docs/spike-linux.md
todo 3):
| Check | Result |
|---|---|
uname -r |
6.6.87.2-microsoft-standard-WSL2 |
modprobe -n -v vhci-hcd |
resolves the full chain (usb-common → usbcore → usbip-core → vhci-hcd), so the module exists in this kernel |
lsmod | grep vhci |
not loaded (exit 1) |
/sys/devices/platform/vhci_hcd* |
does not exist (module never loaded → no vhci sysfs attach points) |
command -v usbip |
absent (exit 1) — no usbip userspace client is installed |
sudo -n true |
requires interactive auth — no non-interactive sudo available to this session |
Bounded no-sudo installability check (this task's own probe, run before
writing this doc): apt-get download usbip → E: Unable to locate package usbip (no such package name on this Ubuntu release). apt-get download linux-tools-generic succeeds (no sudo needed — apt-get download writes to
the cwd), but extracting it (dpkg-deb -x) shows it is an empty
meta-package: its only payload is usr/share/doc/... (changelog +
copyright), zero binaries. The real usbip binary ships inside a
kernel-version-specific package (linux-tools-<exact-uname-r> /
linux-tools-<flavour>), which does not exist for a custom WSL2 kernel
string (6.6.87.2-microsoft-standard-WSL2 is not an Ubuntu package suffix).
Conclusion: usbip userspace is not installable here even with sudo,
because no matching linux-tools-* package is published for this kernel;
the no-sudo path was checked first and independently fails for the same
underlying reason (no matching package, not merely a permissions problem).
Runtime attach (lsusb showing 045e:02ae/02ad/02b0, or
freenect-glview/an OpenNI viewer opening the device) cannot be exercised
in this environment. The code in this directory is complete and compiles;
only the live USB-level verification is blocked.
What is implemented
include/attach_linux/usbip_protocol.h+src/usbip_protocol.cpp— USB/IP wire protocol encode/decode (OP_REQ_DEVLIST/OP_REP_DEVLIST,OP_REQ_IMPORT/OP_REP_IMPORT,USBIP_CMD_SUBMIT/USBIP_RET_SUBMIT,USBIP_CMD_UNLINK/USBIP_RET_UNLINK), transcribed from https://www.kernel.org/doc/html/latest/usb/usbip_protocol.html (retrieved 2026-11-25; protocol v1.1.1 / wire value0x0111). No sockets — unit-tested as pure byte-buffer transforms.include/attach_linux/usbip_server.h+src/usbip_server.cpp— a POSIX-socketUsbipServerthat answers the device-list/import handshake and then relaysUSBIP_CMD_SUBMIT/USBIP_CMD_UNLINKtraffic into anui::protocol::UsbDeviceBackend&, one control + bulk/iso-style session per connection.include/attach_linux/kinect_export.h+src/kinect_export.cpp— the three exported-device descriptors (camera/audio/motor busids matchingcore/protocol/wire.h's VID/PID/bcdDevice) and a placeholder single-frameFrameSourcefor standalone CLI testing (real frame data comes from the tracker/synth pipeline at a higher integration layer — out of this todo's scope).include/attach_linux/vhci_lifecycle.h+src/vhci_lifecycle.cpp— thin wrappers around the stockusbipclient CLI (usbip attach,usbip detach,usbip port) andmodprobe vhci-hcd; this shim is the server half only, per todo 9's "no out-of-tree kernel modules beyond stock usbip/vhci".src/main.cpp— thekinect_attachCLI:serve,attach,detach,list,--help.tests/test_usbip_protocol.cpp— assert-based round-trip tests for every encode/decode pair above, run viactest.
Build (achievable here)
cmake -S attach/linux -B attach/linux/build
cmake --build attach/linux/build
ctest --test-dir attach/linux/build
This is a standalone CMake project: it does not touch the root
CMakeLists.txt or build/linux. It pulls in core/'s libnui_core via
its own add_subdirectory(../../core) with NUI_CORE_BUILD_TESTS=OFF, so
configuring here never fetches googletest.
Prerequisites to actually attach (once available)
- Install the usbip userspace (needs a kernel whose
linux-tools-*package exists, or a from-source build oftools/usb/usbipagainst this kernel's headers):sudo apt-get install -y usbip # Ubuntu/Debian, if the package exists for your kernel # or, if not packaged for your exact kernel string (WSL2's usual case): # build tools/usb/usbip from a matching Linux kernel source tree - Load vhci-hcd (needs root):
WSL2 caveat: even after a successful
sudo modprobe vhci-hcd ls /sys/devices/platform/vhci_hcd.0 # must now existmodprobe, WSL2's init can lack the udev/sysfs plumbingusbipexpects for hot-plug notification; ifusbip attachhangs or the imported device never appears underlsusb, that plumbing gap — not this shim — is the next thing to debug. A native-Linux host sidesteps it entirely.
Run / attach / detach (once prerequisites are met)
# Terminal 1: start the server (defaults to port 3240, the usbip client's own default).
./attach/linux/build/kinect_attach serve --port 3240
# Terminal 2: attach the camera device through vhci-hcd.
sudo modprobe vhci-hcd
./attach/linux/build/kinect_attach attach --host 127.0.0.1 --port 3240 --busid 1-1
lsusb | grep 045e # expect 045e:02ae
# ... use the device (freenect-glview / an OpenNI2 viewer against it) ...
# Find the vhci port it landed on, then detach.
./attach/linux/build/kinect_attach list
./attach/linux/build/kinect_attach detach --vhci-port <N>
Repeat attach with --busid 1-2 / --busid 1-3 to also attach the audio
and motor sibling devices.
Known simplifications (documented, not hidden)
- The placeholder
FrameSourceinkinect_export.cppalways returns one all-background frame; it is for compiling/smoke-testing this shim only, not a substitute for the tracker/synth pipeline (todos 5/7/10). - Each
USBIP_CMD_SUBMITagainst a camera iso endpoint is answered with oneUsbDeviceBackend::next_packet()call (one USB/IP-tunnelled packet per request), with no ISO packet descriptor array modelled — correct for this server's read-only (IN) iso endpoints, where the client never sends ISO descriptors on the wire it is requesting from (the OUT-direction case, which never applies to these endpoints, is intentionally unhandled).