GameInput: DualShock 4 over Bluetooth fails immediately on ReadFile (128-byte buffer < 547-byte HIDP_CAPS.InputReportByteLength) #2465

Open
opened 2026-11-26 05:31:21 +00:00 by github-bot · 0 comments
Owner

@⁠microwave805 on GitHub · 2026-11-25 19:30 UTC · original

Static audit on main @ c7e1799 found that crates/xcl/src/hle/playstation.rs fails immediately on every ReadFile call for DualShock 4 controllers connected over Bluetooth on Windows.

Where

  • crates/xcl/src/hle/playstation.rs:111-116 (read_until_gone)
  • crates/xcl/src/hle/playstation.rs:4, 50-56, 86-97 (Bluetooth DS4 matching & 1 s reconnect loop)

Root cause

playstation.rs explicitly matches DualShock 4 controllers over Bluetooth (vid&0002054c, service 00001124-0000-1000-8000-00805f9b34fb, PIDs 05c4/09cc), then opens the HID handle and reads into a hardcoded 128-byte buffer:

let mut buf = [0u8; 128];
...
if unsafe { ReadFile(h, buf.as_mut_ptr(), buf.len() as u32, &mut n, std::ptr::null_mut()) } == 0 {
    break;
}

The DualShock 4 Bluetooth HID report descriptor declares input report 0x19 (Report Size 8, Report Count 546 → HIDP_CAPS.InputReportByteLength = 547). On Windows, hidclass.sys strictly requires ReadFile's nNumberOfBytesToRead >= HIDP_CAPS.InputReportByteLength on every read, even when the controller is sending 10-byte 0x01 or 78-byte 0x11 input reports. Because 128 < 547, ReadFile fails immediately on the first call with ERROR_INVALID_USER_BUFFER (1784).

Trigger

Connect any DualShock 4 (05c4 or 09cc) over Bluetooth on Windows. read_until_gone opens the device, logs "is read as the title's gamepad", fails ReadFile on call 1, closes the handle, logs "was disconnected", sleeps 1 s in reader() (playstation.rs:55), and loops forever without ever reading gamepad input.

Fix direction

Query HIDP_CAPS.InputReportByteLength via HidD_GetPreparsedData / HidP_GetCaps (or increase buf to at least 547 bytes, e.g. [0u8; 1024], since hidclass.sys accepts any buffer length >= InputReportByteLength).

AI use

  • Antigravity (Gemini 4 Neon): static code audit on main @ c7e1799 and issue drafting.
**@⁠microwave805** on GitHub · 2026-11-25 19:30 UTC · [original](https://github.com/xcl-dev/xcl/issues/2465) Static audit on `main @ c7e1799` found that `crates/xcl/src/hle/playstation.rs` fails immediately on every `ReadFile` call for DualShock 4 controllers connected over Bluetooth on Windows. ### Where - `crates/xcl/src/hle/playstation.rs:111-116` (`read_until_gone`) - `crates/xcl/src/hle/playstation.rs:4, 50-56, 86-97` (Bluetooth DS4 matching & 1 s reconnect loop) ### Root cause `playstation.rs` explicitly matches DualShock 4 controllers over Bluetooth (`vid&0002054c`, service `00001124-0000-1000-8000-00805f9b34fb`, PIDs `05c4`/`09cc`), then opens the HID handle and reads into a hardcoded 128-byte buffer: ```rust let mut buf = [0u8; 128]; ... if unsafe { ReadFile(h, buf.as_mut_ptr(), buf.len() as u32, &mut n, std::ptr::null_mut()) } == 0 { break; } ``` The DualShock 4 Bluetooth HID report descriptor declares input report `0x19` (Report Size 8, Report Count 546 → `HIDP_CAPS.InputReportByteLength = 547`). On Windows, `hidclass.sys` strictly requires `ReadFile`'s `nNumberOfBytesToRead >= HIDP_CAPS.InputReportByteLength` on every read, even when the controller is sending 10-byte `0x01` or 78-byte `0x11` input reports. Because `128 < 547`, `ReadFile` fails immediately on the first call with `ERROR_INVALID_USER_BUFFER` (1784). ### Trigger Connect any DualShock 4 (`05c4` or `09cc`) over Bluetooth on Windows. `read_until_gone` opens the device, logs `"is read as the title's gamepad"`, fails `ReadFile` on call 1, closes the handle, logs `"was disconnected"`, sleeps 1 s in `reader()` (`playstation.rs:55`), and loops forever without ever reading gamepad input. ### Fix direction Query `HIDP_CAPS.InputReportByteLength` via `HidD_GetPreparsedData` / `HidP_GetCaps` (or increase `buf` to at least 547 bytes, e.g. `[0u8; 1024]`, since `hidclass.sys` accepts any buffer length `>= InputReportByteLength`). ### AI use - Antigravity (Gemini 4 Neon): static code audit on `main @ c7e1799` and issue drafting.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:31:21 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.