HID device access and discovery
The HID access layer is the host-side boundary for OpenLogi hardware. It finds supported HID devices, manages the raw transport needed to talk to them, and turns native connection state into stable discovery data and routes. Higher-level device features use these contracts without opening operating-system HID handles themselves. The host API supplies one native backend to discovery, route actions, channel pools, pairing, and hotplug consumers. It also exposes host-bound feature operations through the same public surface as the device layer. See also Device integration, Device domain runtime, Device registry, Logitech HID++ protocol, and Fixture workflows.
System boundary
The HID layer separates system hardware access from product behavior. Platform code supplies reports and connection state. The device layer uses that access to build inventory, routes, and feature operations.
HID abstraction
The abstraction presents one channel for reading and writing reports across supported host systems. It can enumerate HID nodes, open HID++ channels, open raw writers, and observe hotplug changes while keeping native handles and errors inside the host layer.
The shared device layer defines the route and inventory contracts. The HID crate supplies the machine-specific backend and the host entry points that connect those contracts to real hardware. Its public surface re-exports the shared device types while adding wrappers that supply this host's backend. Callers can also pass a backend explicitly to route-addressed operations, which keeps the same API usable with a scripted device tree or another host stack. Operations on a channel that the caller already owns do not need this backend boundary.
References: crates/…/Cargo.toml• L1-27 crates/…/lib.rs• L1-44 crates/…/host.rs• L1-57 crates/…/transport.rs• L160-170
Product boundary
Discovery reports identity, reachability, battery data, model data, and capabilities. Product features use these results to choose controls and routes. They do not open HID nodes directly.
Device kind is an identity hint. Capabilities decide whether a control is safe to offer because firmware support is more precise than a broad device label. This keeps uncertain devices visible without exposing controls that they cannot use.
References: crates/…/device.rs• L89-95 crates/…/device.rs• L324-353 crates/…/lib.rs• L25-44
Lighting transaction boundary
Lighting actions use an owned transaction boundary between a requester and native device I/O. A route-specific worker keeps the write and any recovery step alive after a requester times out or detaches.
This ownership prevents a later lighting action from starting while native cleanup still runs. Work that has not started can be cancelled. Work that has started keeps its route lock until the transaction ends.
References: crates/…/host.rs• L171-205 crates/…/lighting.rs• L17-127 crates/…/lighting.rs• L140-172 crates/…/tests.rs• L19-161
Device discovery
Discovery starts with the operating system's visible HID nodes. It selects supported Logitech HID++ collections and known standalone raw-HID devices, then probes them to produce product inventory.
The discovery paths differ by how the device is reached. A receiver can represent several paired devices. A direct HID++ node represents one device. A standalone raw-HID node uses its own driver-owned address.
This diagram shows how host HID nodes become receiver-backed, direct, or standalone inventory.
flowchart TD
OS[Operating system HID nodes] --> Filter[Supported node selection]
Filter --> Receiver[Receiver node]
Filter --> Direct[Direct HID++ node]
Filter --> Raw[Standalone raw-HID node]
Receiver --> Probe[Receiver and paired-device probe]
Direct --> DirectProbe[Direct-device probe]
Raw --> RawDescribe[Raw-device description]
Probe --> Inventory[Product inventory]
DirectProbe --> Inventory
RawDescribe --> Standalone[Standalone inventory]
HID node selection
The transport selects Logitech vendor collections that carry HID++ reports. It uses the HID usage page and usage pair as the main transport signal, which lets one discovery path cover USB, receiver, Bluetooth, and wired collections. The supported set includes the BLE-direct and wired G-series collections, while a known standalone product is excluded even when it shares a HID++ collection.
Standalone drivers take precedence when a product has its own control model. On Linux, receiver child nodes are excluded because paired devices must use the receiver node.
References: crates/…/transport.rs• L239-293 crates/…/transport.rs• L362-393 crates/…/tests.rs• L3-25
Receiver discovery
Receiver probing identifies the receiver and then checks the pairing slots that it can reach. Bolt uses both arrival events and slot records so a sleeping or offline paired device can keep its identity. Other supported receiver paths use the online devices reported by the receiver.
The resulting inventory keeps receiver identity separate from paired-device state. Each paired device has its slot, identity hints, reachability, and discovered capabilities.
References: crates/…/probe.rs• L53-126 crates/…/probe.rs• L165-267 crates/…/device.rs• L414-430
Direct device discovery
A directly attached HID++ device is reached through its own HID++ index. The probe checks that the node is a controllable peripheral rather than another receiver interface. A successful probe becomes a one-device inventory with a synthetic receiver description.
This path supports direct USB and Bluetooth connections. It prefers the device's model name when available so a generic host label does not replace useful product identity.
References: crates/…/probe.rs• L411-519 crates/…/route.rs• L22-24 crates/…/device.rs• L232-246
Standalone raw-HID discovery
Standalone raw-HID discovery supports devices that do not use receiver pairing or the HID++ channel model. It returns a separate descriptor with a full raw address and a driver-owned capability description.
The layer rejects ambiguous duplicate nodes. A serial number can distinguish identical devices. A temporary host node identity cannot safely do so when two nodes share the same HID tuple.
References: crates/…/standalone.rs• L1-16 crates/…/standalone.rs• L56-92 crates/…/device.rs• L355-411
HID-only discovery
HID-only discovery exposes known products that are visible to the host but do not provide a usable HID++ node. It keeps product presence separate from control access, so higher-level features can show the product without treating it as a controllable HID++ device.
References: crates/…/host.rs• L342-350
Transport lifecycle
The transport moves from node enumeration to channel opening, probing, reuse, and retirement. The stateful lifecycle lets repeated scans reuse live hardware and distinguish a temporary read problem from a real disconnect.
Channel opening
An HID++ route resolves to the node that can reach the device. Receiver routes open the receiver channel and address a pairing slot. Direct routes open the device node and address its own index. Raw-HID routes use a raw writer and do not enter the HID++ path.
Opening a channel verifies that the node can speak the expected HID++ form. Invalid nodes are skipped instead of becoming product devices. Each live HID++ channel receives a fixed software ID for its lifetime so replies map to the correct channel. The ID is leased per node across the process and, when possible, across OpenLogi processes; an exhausted pool refuses a new open instead of sharing an ID.
References: crates/…/transport.rs• L453-511 crates/…/transport.rs• L514-595 crates/…/route.rs• L31-77
Channel reuse
The persistent enumerator keeps one open channel for each operating-system HID node and reuses it across scans. A channel registry publishes current route-to-channel mappings so feature operations use the connection already owned by inventory.
A channel pool supports long-running sessions that share one receiver. This avoids opening a new receiver connection for every feature operation. The host entry points create this pool over the process's native backend.
References: crates/…/host.rs• L313-340 crates/…/inventory.rs• L124-163 crates/…/registry.rs• L157-204 crates/…/pool.rs• L1-45
Probe and cache lifecycle
The first probe reads the information needed for identity and product controls. Later scans reuse stable identity data and refresh values that can change, such as battery state. A persistent cache lets a device keep its identity while a full probe is still in progress after restart.
Cache keys follow transport identity. Receiver-backed devices use receiver or unit identity. Direct devices use the host node identity for that node's lifetime. These keys are not product model identifiers.
The host offers both a memory-only enumerator for one-shot work and a persisted enumerator for warm starts. If no data directory is available, the persisted form falls back to memory-only discovery.
References: crates/…/host.rs• L313-334 crates/…/cache.rs• L8-52 crates/…/cache.rs• L108-199 crates/…/inventory.rs• L410-435
Disconnect and recovery
The watcher combines hotplug events with periodic enumeration. A visible node that does not answer is a failed probe rather than an empty inventory. The ledger replays the last good snapshot for a short grace period, then retires the channel so a later scan can open a fresh one.
A process-wide device-I/O gate can suspend native activity. During suspension, opens and writes stop with a clear backend error. A permanent read failure marks the channel disconnected so inventory can retire it instead of retrying a dead read.
This distinction protects product state. Sleep, host switching, and short report faults do not remove device panels or capture routes. A node that truly disappears is removed from the ledger and no longer receives replayed state.
References: crates/…/host.rs• L46-57 crates/…/host.rs• L352-355 crates/…/hotplug.rs• L8-23 crates/…/ledger.rs• L3-15 crates/…/ledger.rs• L70-132 crates/…/transport.rs• L311-335 crates/…/transport.rs• L742-805
Platform boundary
The common backend contract hides platform-specific HID behavior behind one interface. Platform adapters handle native enumeration, report access, and permission rules so discovery and product code can follow one lifecycle.
Native backend
The native backend connects the operating system HID stack to the device layer. It refreshes the visible node set, retains handles for that set, and opens either an HID++ channel or a raw writer.
The host's backend entry point supplies this native backend to callers that need several operations. The backend and its HID manager are shared by the process. The cached handle includes the selected usage pair as well as the node identity, which matters when one physical node exposes several logical collections. Target-specific dependencies keep Windows and macOS behavior inside this boundary. The shared I/O gate applies before enumeration, open, and report write.
References: crates/…/Cargo.toml• L14-46 crates/…/host.rs• L36-57 crates/…/transport.rs• L116-140 crates/…/transport.rs• L295-321 crates/…/native.rs• L28-94 crates/…/native.rs• L115-177 crates/…/native.rs• L214-253
Cross-platform report transport
Non-Windows systems use the shared async HID reader and writer for the selected node. The channel reports whether short and long HID++ reports are available, so the protocol layer can adapt to direct Bluetooth collections that expose only long reports.
Enumeration and hotplug watching use the same process-wide backend. This keeps the device view aligned with the handles used for route operations.
References: crates/…/transport.rs• L17-27 crates/…/transport.rs• L239-293 crates/…/transport.rs• L323-359 crates/…/transport.rs• L710-814
Windows HID collections
Windows can expose short and long HID++ collections as separate interfaces for one physical device. The Windows adapter joins matching interfaces by their normalized physical path and presents one channel to the protocol layer. Long-only collections do not pair with a short interface.
The adapter reads from both endpoints when both exist and sends each report to the endpoint for its report ID. HID++ short reports use the short collection. Long, very-long, and matched vendor reports use the long collection. Vendor collections that carry reports outside the HID++ short and long pair can also be opened for the direction they declare. If the normal output path cannot write a report, it uses a native Windows fallback while preserving a true disconnect as a disconnect. Both paths apply the host I/O gate before writing, so suspend handling stays outside product features. Collection grouping keeps short, long, and related vendor interfaces from the same physical device together without pairing interfaces from separate receivers.
The native fallback opens the Windows device path with progressively less access when needed. It reads the collection's report lengths and tries supported output and feature-report methods with the lengths accepted by that collection. This gives live devices another write path without changing the channel's disconnect state when the operating system reports a permanent loss.
References: crates/…/windows.rs• L30-88 crates/…/windows.rs• L91-215 crates/…/windows.rs• L218-341 crates/…/windows.rs• L428-599 crates/…/windows_hid.rs• L24-95 crates/…/windows_hid.rs• L112-215 crates/…/windows_hid.rs• L217-319 crates/…/tests.rs• L29-77 crates/…/Cargo.toml• L29-43
macOS access boundary
macOS Input Monitoring permission controls whether the HID-facing process can open HID nodes. The permission check and consent request belong to that process because the grant applies to the process that opens the hardware. Error guidance names the agent when the shipped helper lacks access and names the launching app for a direct command.
The status check does not prompt. A caller requests consent in the agent process and keeps the blocking request off the async runtime.
References: crates/…/permissions.rs• L1-11 crates/…/permissions.rs• L35-57 crates/…/transport.rs• L53-105 crates/…/tests.rs• L119-131 crates/…/Cargo.toml• L45-46
Hardware transport probe
The MX Creative Keypad probe is a direct diagnostic for notification transport. It compares key reports with and without a periodic keepalive, then restores the keypad's native reporting state before it exits. This tool is separate from product discovery and helps confirm device behavior without changing the host abstraction.
References: crates/…/mx_keypad_probe.rs• L1-12 crates/…/mx_keypad_probe.rs• L56-77 crates/…/mx_keypad_probe.rs• L134-189
Native transport recording
Native recording is an optional evidence path for real HID sessions. It observes HID++ exchanges and standalone raw writes at the backend boundary, then groups the evidence by channel or writer lifetime without changing normal device access.
This diagram shows how optional transport evidence becomes either a validated cassette or a rejected candidate.
flowchart LR
Backend[Native HID backend] --> Observe[Optional transport observer]
Backend --> Write[Optional raw writer wrapper]
Observe --> Evidence[Bounded native evidence]
Write --> Evidence
Evidence --> Group[Completed channel or writer lifetime]
Group --> Audit[Protocol and privacy audit]
Audit -->|valid exchanges| Cassette[Validated HID cassette]
Audit -->|unsafe or incomplete evidence| Reject[Rejected candidate]
Evidence capture
The normal backend remains unobserved unless a caller creates a recording backend. The recorder captures both HID++ exchanges and raw output writes, which lets fixture work cover both transport families while hardware access remains in the host layer.
The recorder has a fixed event budget and uses a separate worker to group accepted events. It records request outcomes, unmatched or malformed channel reports, raw-writer write results, cancellation, and channel or writer closure. It fails closed for queue or worker failure, overflow, oversized raw reports, cancelled operations, and finalization while a producer is still live. It does not sanitize, serialize, or write files; a later layer owns cassette decisions.
References: crates/…/recording.rs• L1-83 crates/…/recording.rs• L126-170 crates/…/recording.rs• L181-311 crates/…/recording.rs• L405-515 crates/…/tests.rs• L18-100 crates/…/tests.rs• L102-260
Cassette validation
A completed HID++ channel can be audited and converted into a fixture cassette. The audit accepts a cassette only when every retained request is a complete successful exchange, every HID++ observation is classified, and the final fixture passes schema validation. Foreign protocol reports on the same node are ignored because they are not HID++ evidence.
The audit replaces supported receiver and device identities with length-matched synthetic values while preserving equal-value relationships. A caller can provide preferred synthetic identities from a trusted profile through an identity plan. The plan accepts only canonical values, and the audit rejects a preferred value that matches the captured original. The original captured identities do not leave the audit result.
Requests are ordered by recorder request ID rather than callback timing. This gives repeated normalized requests a stable replay order and keeps capture software-ID leases separate from replay leases. HID++ software IDs are normalized so a cassette can replay through another live channel.
References: crates/…/cassette.rs• L21-120 crates/…/cassette.rs• L123-244 crates/…/cassette.rs• L254-275 crates/…/cassette.rs• L298-377 crates/…/sanitizer.rs• L22-58 crates/…/sanitizer.rs• L62-109 crates/…/sanitizer.rs• L151-288 crates/…/tests.rs• L32-131 crates/…/tests.rs• L337-444
Route and inventory contracts
Routes and inventories are the narrow contracts between hardware discovery and product features. A route says how to reach a device. An inventory says what the current scan knows about it.
Route addressing
Receiver routes contain a receiver identity and pairing slot. Direct routes contain the device vendor and product IDs. Raw-HID routes contain the full HID tuple and an opaque identity. This separation stops a standalone raw interface from entering HID++ code.
Receiver family selection follows protocol behavior. Lightspeed receivers use the Unifying protocol path even when inventory gives them a Lightspeed display name. Unknown non-Unifying receiver IDs use the Bolt path so a future compatible receiver does not silently lose writes.
References: crates/…/route.rs• L31-77 crates/…/route.rs• L103-129 crates/…/route.rs• L169-211
Inventory publication
The agent publishes inventory snapshots and route mappings after each settled scan. Consumers use the snapshot for display and capability choices. Route-addressed operations use the matching live channel.
The inventory model is also an IPC contract. Changes to its serialized shape affect the GUI and other clients, so discovery adapts probe results to the model instead of exposing platform handles or transport objects.
References: crates/…/host.rs• L352-365 crates/…/inventory.rs• L399-435 crates/…/registry.rs• L189-204 crates/…/device.rs• L414-430
Change checklist
When these files or sections are changed, remember to consider these:
- Keep HID collection selection aligned with report transport capabilities when a device uses a new collection.
- Preserve the distinction between receiver child interfaces and the receiver node. A child probe can create timeouts or duplicate inventory.
- Keep route variants aligned with inventory creation and IPC serialization. A route that displays correctly but cannot reopen will fail later during writes or capture.
- Keep cache keys tied to transport identity. Do not replace receiver or unit identity with a slot number or use a temporary node identity as a persistent physical key.
- Preserve probe health and channel retirement when changing probe timing or sources. A failed check must not become a false disconnect.
- Define the full address and duplicate-node rule before exposing a new raw-HID driver as inventory.
- Keep macOS permission requests in the process that opens HID hardware.
- Keep the native handle key aligned with the node's usage pair when one node exposes several collections.
- Keep each HID++ channel's software ID fixed for its lifetime and keep per-node leasing aligned with cross-process locking. Do not fall back to a shared ID when the pool is exhausted.
- Keep Windows short and long collections grouped by physical path. Do not pair by vendor, product, or name because identical devices can share those values.
- Keep report-ID endpoint selection aligned with the set of supported HID++ report widths. Preserve typed disconnect errors when adding write recovery.
- Apply the process-wide device-I/O gate consistently across enumeration, opens, reads, writes, and long-running feature transactions.
- Keep lighting transaction ownership separate from requester lifetime. A timeout must not release the route lock before native cleanup ends.
- Keep recorder lifetime tied to channel and writer lifetime. Finalization must remain an explicit incomplete-capture error when a producer is still live.
- Keep recording limits fail-closed. Partial evidence must not become a fixture that appears complete.
- Keep cassette identity replacement relation-preserving and schema-aware. New identity fields need a sanitizer rule before traffic can become a fixture.
- Keep preferred cassette identities canonical, length-matched, and different from every captured original. Do not expose source identity bytes while producing an audit or rejection.
- Keep foreign-protocol observations out of HID++ audit decisions when they share a native node.
- Keep cassette request order tied to recorder request IDs. Do not use callback completion order as replay order.
- Keep HID++ software-ID leasing separate from cassette replay IDs.
- Keep host entry points on the same native backend when a caller combines enumeration, route operations, pairing, or hotplug observation.
- Keep HID-only product reporting separate from HID++ route creation. A visible product without a controllable node must not become a route that later cannot open.
- Keep diagnostic probes that change device reporting state restoring the original state before exit.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A receiver child node is probed as a device | The probe waits for replies that cannot arrive and may publish a duplicate device | Reject child nodes and use a receiver slot route |
| A visible node stops answering for one scan | The product view can flash to an empty or partial list | Replay the last good inventory during the ledger grace period |
| A channel keeps failing after the grace period | Reads and writes remain attached to a dead connection | Retire the channel and reopen it on a later scan |
| All HID++ software IDs for one node are leased | A new channel cannot safely correlate replies | Refuse the open and let discovery retry after a lease is released |
| Two raw-HID nodes share a tuple without distinct serials | A route can target the wrong physical device | Return an ambiguous-device error instead of publishing both nodes |
| A raw-HID route enters HID++ resolution | A standalone device receives the wrong protocol | Keep raw-HID addressing separate from direct and receiver routes |
| The agent lacks macOS Input Monitoring access | HID nodes do not reach product discovery | Check and request access in the agent process |
| A new HID collection is missing from selection | The host shows the device but OpenLogi ignores it | Add the collection and confirm its report shape |
| A standalone product is accepted by the generic HID++ matcher | The wrong protocol path claims the device | Keep the product-specific exclusion ahead of the generic collection match |
| Several collections share one node but the backend keys only by node | The selected collection can use the wrong handle | Preserve the usage page and usage ID in the handle key |
| Windows short and long collections are paired by shared attributes | One physical device can read from another device's interface | Pair only by the normalized physical path |
| A Windows write fallback hides a permanent disconnect | Inventory keeps a dead channel and retries it | Preserve and classify the typed disconnect before fallback |
| A Windows report is sent to the wrong collection | The OS rejects the report or the device misses the command | Route short report IDs to the short endpoint and other supported reports to the long endpoint |
| A Windows vendor report is sent through the HID++ handle | A keypad or other vendor feature does not receive the report | Open sibling vendor collections and route each vendor report to its declaring collection |
| A Windows collection declares no input or output path | The channel waits on or writes to an unusable handle | Open only the directions the collection declares and skip a collection with neither |
| A native Windows write uses a path with the wrong encoding | The fallback cannot open the device or targets a damaged path | Preserve the device path as UTF-16 and add its terminator without a lossy conversion |
| Host device I/O is suspended during an open or write | Native access fails while higher layers still have inventory | Apply the shared I/O gate at each native boundary |
| A lighting requester times out while native work is active | A successor can race with an unfinished write or recovery step | Keep the worker and route lock alive until the transaction ends |
| Recording ends with a live channel or raw writer | The capture has no trusted end boundary | Return an incomplete-recording error |
| Recording limits or raw-report size are exceeded | Partial evidence may look usable | Fail finalization instead of returning partial evidence |
| Captured traffic contains pairing data or unsupported identity fields | A fixture may expose private data or replay unsafe traffic | Reject the cassette during protocol and privacy audit |
| A preferred synthetic identity matches the captured identity | The audit cannot prove that the cassette is sanitized | Reject the candidate without retaining the original bytes |
| A cassette request is ordered by callback timing | Repeated requests can replay with unstable responses | Order exchanges by recorder request ID |
| HID-only presence is treated as HID++ control access | The product appears in inventory but route operations fail | Publish presence without creating an unsupported HID++ route |
| A keypad probe exits after diverting controls | The device keeps using diverted rather than native reporting | Restore native reporting for each changed control |
Key files
| File | Why to read it |
|---|---|
| crates/…/Cargo.toml | Defines the host crate and its target-specific Windows and macOS access dependencies |
| crates/…/lib.rs | Defines the public surface that combines host HID access with the shared device-layer types |
| crates/…/host.rs | Supplies the native backend to discovery, route actions, pooling, pairing, hotplug, HID-only presence, and host-bound feature operations |
| crates/…/transport.rs | Selects HID nodes and manages channel opening, report transport, software-ID leases, and connection state |
| crates/…/tests.rs | Protects HID++ collection selection, physical collection grouping, receiver-child filtering, and macOS access guidance |
| crates/…/native.rs | Connects the operating system HID manager to shared channels, raw writers, hotplug, and I/O suspension |
| crates/…/inventory.rs | Coordinates stateful scans, channel reuse, probes, and recovery |
| crates/…/probe.rs | Shows receiver, paired-device, and direct-device discovery |
| crates/…/ledger.rs | Defines last-good inventory replay and channel retirement |
| crates/…/standalone.rs | Defines raw-HID discovery and duplicate-device safety |
| crates/…/recording.rs | Defines the optional bounded evidence boundary for native channels and raw writers, including lifetime and finalization rules |
| crates/…/cassette.rs | Converts completed channel evidence into an audited fixture cassette and reports why a candidate is not committable |
| crates/…/sanitizer.rs | Defines protocol classification, identity replacement, and privacy rejection rules for cassette evidence |
| crates/…/tests.rs | Shows the privacy, ordering, replay, foreign-protocol, and rejection guarantees for cassette construction |
| crates/…/tests.rs | Shows channel and raw-writer evidence capture, cancellation, bounded failure, and unobserved default transport |
| crates/…/windows.rs | Handles Windows composite HID collections, report routing, vendor collections, and native write recovery |
| crates/…/windows_hid.rs | Provides the native Windows HID path, collection report lengths, and fallback report-write methods |
| crates/…/mx_keypad_probe.rs | Provides a direct keypad transport probe for notification and keepalive behavior |
| crates/…/permissions.rs | Defines the macOS HID access boundary |
| crates/…/route.rs | Defines serializable route addressing and receiver-family rules |
| crates/…/device.rs | Defines serializable inventory, capability, and standalone-device contracts |