Skip to content

Add HID proxy device and let devices opt out of IN report repeat - #44

Open
jc-sw-git wants to merge 3 commits into
Alia5:mainfrom
jc-sw-git:feat/hidproxy-device
Open

jc-sw-git wants to merge 3 commits into
Alia5:mainfrom
jc-sw-git:feat/hidproxy-device

Conversation

@jc-sw-git

Copy link
Copy Markdown

Requested by jc-sw-git · project thread

Description

Two commits:

  1. Let a device opt out of repeating its last IN report (usb/device.go, internal/server/usb/server.go): a new optional interface usb.NoInRepeatDevice. When a device implements it and returns true, the server doesn't resend its last report on an interrupt IN poll; the poll waits for a new one. Devices that don't implement it behave as before.
  2. Add HID proxy device (device/hidproxy): a device type that enumerates with descriptors the client supplies and passes reports between the host and the client.
    • Create options (deviceSpecific): device, configuration, string and HID report descriptors as hex, plus the speed. USB 2.01 is served as 2.00 so Windows doesn't ask for a BOS descriptor.
    • Stream frames both ways: input reports (client → VIIPER), output reports and control requests (VIIPER → client), control replies (client → VIIPER).
    • Standard requests stay with VIIPER's server; HID idle/protocol and CDC line coding/control line state are answered by the device; every other class, vendor or unknown request goes to the client, which answers within 1 s (no answer or a refusal gives an empty, successful data stage, as the server can't stall).
    • One client per device at a time; the serial number isn't echoed in API responses or logs.
    • Registered in internal/registry, docs in docs/devices/hidproxy.md, listed in the README, docs/index.md and mkdocs.yml.

Not included: a libVIIPER wrapper (lib/viiper) and client-library bindings for the new device. I can add them if you want them in this PR.

Related Issue

Closes #43

Motivation and Context

See the issue: a launcher hides a real HID device (here the Steam Controller puck) from Steam with HidHide and shows Steam a copy, so it decides what passes between Steam and the real device. Beyond that case, the device is generic: any HID-style USB device the client describes (wheels, flight sticks, other pads, dongles) can be served without a new device type in VIIPER; the issue lists the limits (no isochronous, SuperSpeed or bulk-heavy devices). The no-repeat interface is needed because the copy forwards another device's reports, some of which are events, not state.

How Has This Been Tested?

  • Tested with hardware (Steam Controller)
  • Unit tests
  • Code review only

go vet ./... and go test ./... pass on Linux (Go 1.27.2). New tests: device/hidproxy (enumeration with the descriptors of a real Steam Controller puck, frame round trips, routing of control requests, timeouts, late and foreign replies, one client at a time) and TestTheHostReadsEachReportOnce through the real server; the device is also in TestDeviceAttach. A run on Windows with a real puck is still pending on our side; I'll report the result here.

Type of Change

  • Bug fix (non-breaking change addressing an issue)
  • New feature (non-breaking change adding functionality)
  • Breaking change (fix or feature causing existing functionality to change)
  • Documentation update

Checklist

  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have made sure my commit messages are changelog compatible

🤖 Generated with Claude Code

https://claude.ai/code/session_016H3ByhXeSc7eq3UDmPXo8s

The server answers an interrupt IN poll with the device's last report when no
new one arrived within bInterval. That is right for devices that report state,
but wrong for a device that forwards another device's reports: some of those
are one-shot events, and repeating them invents input. A device can now
implement usb.NoInRepeatDevice to have its IN polls wait for a new report.

Claude-Session: https://claude.ai/code/session_016H3ByhXeSc7eq3UDmPXo8s
New device type `hidproxy`: it enumerates with the descriptors the client
supplies (device, configuration, strings, HID report descriptors) and passes
reports between the host and the client. The client reads and writes the real
device itself and decides what passes; VIIPER never talks to the real device.

- Input reports come from the client and are not repeated (NoInRepeatDevice).
- OUT transfers, HID GET/SET_REPORT, vendor and unknown class requests go to
  the client, which answers control requests within 1 s.
- HID idle/protocol and CDC line coding/control line state are answered by
  the device itself.

Docs: docs/devices/hidproxy.md. Tests: unit tests with the descriptors of a
Steam Controller puck, an end-to-end test over the API, and the device in
TestDeviceAttach.

Claude-Session: https://claude.ai/code/session_016H3ByhXeSc7eq3UDmPXo8s

Changelog(feat)
@TitanCSA

Copy link
Copy Markdown

Could the reconnect test also cover input already queued by the previous client? TestAClientCanAttachAgainAfterADisconnect currently starts the second connection with an empty input queue.

At this revision, Serve cleanup clears the client and pending control replies, while inQueues survives. From reading that path, if client A queues report X, disconnects before a host read, and client B attaches and queues Y, the next HandleTransfer can still return X first.

Given the one-shot-event motivation for no-repeat, it would help to define and test whether that backlog intentionally survives a stream reconnection, or whether a new owner requires a new device/queue lifecycle. Keeping or discarding queued key/button transitions can each affect state, so an explicit documented policy seems useful here.

Disclosure: I maintain Windows HID/QA tools. This is AI-assisted source-review feedback; I haven't executed this case or tested the PR on hardware.

A client that leaves could leave reports the host hadn't read yet in the
IN queues, and the next client's input came after them. Those reports may
be one-shot events (a press without its release), so a later client now
starts with empty queues and is expected to send the current state first.
Documented in docs/devices/hidproxy.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016H3BygJUeQxU6epov8YidF

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] HID proxy device: a copy of a real USB HID device, fed by the client

3 participants