Files
kinect/attach/windows/docs/approach.md
T
kinect-bot 9b5a0255e2
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python root tests (pytest, no tracker deps) (push) Canceled after 0s
ci / Python tracker (pytest, tracker/.venv) (push) Canceled after 0s
feat(windows): usbip-win runbook ([~]) + clean-room Kinect10.dll NUI shim (x86+x64 export-verified) (wave 9; todo 14 done, 12/13 blocked)
2026-11-25 06:00:12 -05:00

145 lines
10 KiB
Markdown

# attach/windows/ — approach & architecture (todo 12)
> **STATUS in this build environment: `[~]` BLOCKED.** This directory was authored on a
> Linux/WSL2 host with **no Windows and no Windows Driver Kit (WDK)**. A Windows virtual USB
> bus driver (KMDF/UMDF) and the `usbip-win` VHCI driver both require the WDK + MSVC and can
> only be built on Windows; mingw cannot build Windows kernel-mode drivers. **Nothing here was
> built or run.** Every build/attach/verify step below executes on the user's Windows box.
> The runbook that drives these steps is [`../README.md`](../README.md).
## 1. What this todo must achieve
Present the OS-agnostic virtual Kinect v1 device — `nui::protocol::KinectV1Device` in
`core/protocol/` — to Windows so that the **real Microsoft Kinect for Windows driver**
(`kinect*.inf` / the 1.8 runtime's USB function driver) binds to it and the real
`Kinect10.dll` NUI runtime enumerates and opens it as if a physical Kinect were plugged in.
Once that holds, plan todo 13 proves the crux (the MS NUI skeletonizer tracking synthetic
depth) and DanceEvolution Arcade plays.
This closes plan **GAP-3 (Windows half)**: the Windows per-OS USB-attach shim. It is the
Windows sibling of the already-built, socket-verified `attach/linux/` lane.
## 2. The decision: reuse the Linux USB/IP server, do not write a bespoke bus driver
The plan phrased todo 12 as "usbip-win (or a UMDF/KMDF virtual USB bus driver)". Those are two
genuinely different mechanisms. The decision taken here is **usbip-win VHCI client against the
existing `attach/linux` USB/IP server**, with a from-scratch KMDF/UMDF bus driver recorded as
the rejected alternative.
**Why the USB/IP path wins:**
- **The wire protocol is OS-agnostic and already built + verified.** `attach/linux/` implements
a complete userspace USB/IP **server** (`UsbipServer`) speaking protocol version `0x0111`
(v1.1.1) — the exact protocol the kernel documents at
<https://www.kernel.org/doc/html/latest/usb/usbip_protocol.html> and the exact protocol
`usbip-win`/`usbip-win2` implement on the Windows client side. The server answers
`OP_REQ_DEVLIST`/`OP_REQ_IMPORT` and relays `USBIP_CMD_SUBMIT`/`USBIP_CMD_UNLINK` URB traffic
into the shared `core/protocol` `KinectV1Device`. A USB/IP client on **any** OS — the Linux
`vhci-hcd` kernel driver, or the Windows `usbip-win` VHCI driver — attaches to that same
server over TCP. **The Windows side needs zero new device logic**; it reuses the Linux
server byte-for-byte. Only the client (the VHCI driver) and the INF binding differ per OS.
- **No kernel driver to author, debug, or crash-test.** A bespoke KMDF/UMDF virtual USB bus
driver is a multi-month kernel project (PnP, power, URB translation, BSOD risk, WHQL/signing).
`usbip-win2`'s UDE driver is an existing, **attestation/WHLK-signed** implementation of exactly
that translation layer. Writing our own duplicates it with strictly more risk.
- **One device core, two attach shims — matches plan IS-5.** The architecture goal is an
OS-agnostic core with a thin per-OS attach shim. USB/IP realizes that literally: the shim on
each OS is "install a VHCI client and `attach` three busids".
**The rejected alternative — bespoke KMDF/UMDF virtual USB bus driver:** this would enumerate a
root-hub-like bus with the three Kinect child devices directly in kernel/user mode on Windows,
with no TCP server. It is the only option if USB/IP proves unworkable for the Kinect's
isochronous camera endpoints under the MS driver (see §5, the one real risk). It is **not**
built here because (a) it needs the WDK (unavailable), (b) it duplicates `usbip-win2`'s UDE
driver, and (c) it cannot reuse the already-verified Linux wire code. If §5's ISO risk
materializes on Windows, the smaller fix is to extend the **shared** server's ISO framing (a
cross-lane change in `core/`+`attach/linux/`, owned by todos 8/9), not to write a Windows driver.
## 3. The topology the MS Kinect driver expects
The real Kinect v1 is a **composite set of three sibling USB devices** behind the sensor's
internal hub, each with its own VID/PID — not three interfaces of one device. `core/protocol`
and `attach/linux` already commit to the exact identities (from libfreenect, transcribed in
`core/protocol/descriptors.cpp` and `attach/linux/src/kinect_export.cpp`):
| busid | Function | VID:PID | bcdDevice | What binds it on Windows |
| --- | --- | --- | --- | --- |
| `1-1` | NUI Camera (depth + color/IR iso IN endpoints `0x82`/`0x81`) | `045E:02AE` | `0x010B` (1414) | the MS Kinect **camera** driver/INF; the stream source `Kinect10.dll` opens |
| `1-2` | NUI Audio (2 interfaces → host reads it as firmware-loaded, skips bootloader) | `045E:02AD` | `0x010B` | the MS Kinect **audio** driver/INF (NUI audio-source enumeration) |
| `1-3` | NUI Motor (tilt/LED/accelerometer) | `045E:02B0` | `0x010B` | the MS Kinect **motor** driver/INF |
All three must be attached for the NUI runtime to treat the set as a complete Kinect. The MS
driver binds **per device PID**; attaching only the camera leaves an incomplete sensor that
`NuiCreateSensorByIndex` may reject. The Windows attach therefore runs **three**
`usbip attach` calls, one per busid, against the one running server — exactly what the Linux
runbook does with `--busid 1-1 / 1-2 / 1-3`.
## 4. End-to-end wiring on Windows
```
webcam ─► tracker/synth (todos 5/7) ─► core/protocol KinectV1Device (FrameSource)
│
▼
attach/linux UsbipServer (TCP :3240) ◄── runs on Linux host,
(OS-agnostic USB/IP server, already built) a Linux VM/WSL2, or any
▲ reachable box; it is the
USB/IP wire protocol v1.1.1 over TCP SAME binary for both OSes
│
┌──────────────────────────────────────┴───────────────────────────────┐
│ Windows box │
│ usbip-win / usbip-win2 VHCI (UDE) driver ── usbip.exe attach ─┐ │
│ ▼ │
│ virtual USB tree: 045E:02AE (1-1) 045E:02AD (1-2) 045E:02B0 (1-3) │
│ │ │
│ MS Kinect driver (kinect*.inf) binds per PID │
│ │ │
│ Kinect10.dll NuiGetSensorCount ≥ 1 ───► DEA / SDK │
└───────────────────────────────────────────────────────────────────────┘
```
The server can run on the same Windows box only if a Windows-local USB/IP **stub server** is
used; the simplest, already-verified configuration is the `attach/linux` server on a Linux host
or WSL2 instance reachable over TCP, with the Windows VHCI client attaching across the network
(loopback if co-located). Either way the server code is identical.
## 5. The one real risk: isochronous camera framing (same gap in both lanes, not Windows-specific)
The Kinect camera's depth/color endpoints are **isochronous IN** (`0x82`/`0x81`, advertised in
`core/protocol/descriptors.cpp`). The USB/IP protocol carries ISO transfers with a trailing
`iso_packet_descriptor` array and a non-`0xffffffff` `number_of_packets`
(kernel spec, `USBIP_CMD_SUBMIT`/`USBIP_RET_SUBMIT`). The shared server today answers each
`CMD_SUBMIT` as a single packet with **no ISO descriptor array modelled** — a documented
simplification in `attach/linux/` (correct for read-only IN endpoints where the client sends no
ISO descriptors, and validated for the Linux `vhci-hcd` client over sockets).
Whether the Windows `usbip-win` VHCI driver and, above it, the MS Kinect camera driver accept
that simplified ISO framing — or demand true per-ISO-packet descriptors — is **the open question
todo 13 resolves on Windows** (spike-windows.md Step 4c explicitly says to capture, via
Wireshark+USBPcap, every transfer the MS driver initiates that the Linux init did not). If the
MS driver rejects the simplified framing:
- The fix is to extend the **shared** server's ISO handling (emit `number_of_packets`
`iso_packet_descriptor` entries in `RET_SUBMIT`, split the frame across them). That is a
change in `core/protocol` + `attach/linux/` (todos 8/9), **reused by Windows for free** — not a
Windows-only code path. This todo's Windows artifacts do not change.
- Only if USB/IP itself cannot carry the Kinect ISO streams under the MS driver at all does the
bespoke KMDF/UMDF bus driver (§2 rejected alternative) become necessary; that is the documented
fallback-within-a-fallback and would be re-planned, not silently attempted.
The **NUI-shim fallback (todo 14, `fallback/windows-nui/`)** is the independent escape hatch if
the device-level Windows path (this todo + todo 13) is impractical for any reason: a clean-room
`Kinect10.dll` injecting skeleton/depth directly, which proves playability (IS-3/IS-4) but — per
the plan — does **not** satisfy IS-1/IS-2. The README documents when to drop to it.
## 6. What "done" means for this todo in each environment
| Claim | Where provable | Status |
| --- | --- | --- |
| Reusable OS-agnostic USB/IP server exists and is socket-verified | Linux (this lane + `attach/linux`) | **DONE** (see `attach/linux/`) |
| Windows attach method, topology, binding, signing fully specified | here (docs + scripts + README) | **DONE** (this deliverable) |
| `usbip-win` VHCI driver installs; three busids attach; Device Manager shows the sensor under the MS Kinect driver; `NuiGetSensorCount ≥ 1` | **user's Windows box** | **`[~]` BLOCKED** — no Windows/WDK here |
| DEA plays via the device path | user's Windows box (todo 13) | out of scope for todo 12 |
Everything in the first two rows is delivered in this directory. Everything in the last two rows
is the user's Windows-box work, scripted and documented so it is mechanical, not open-ended.