feat(libSceUsbd): pass configuration and descriptor queries through to libusb #9190

Merged
simnJS merged 1 commit from upstream-pr/9190 into main 2026-10-24 11:22:22 +00:00
simnJS commented 2026-10-21 14:48:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simnJS on 2026-10-21T14:48:22Z.


What

Implement sceUsbdGetConfiguration, sceUsbdGetConfigDescriptorByValue, sceUsbdGetDescriptor and sceUsbdGetStringDescriptorAscii over the host libusb, with the argument checks of FreeBSD 11.4 libusb (libusb10.c, libusb10_desc.c). Null arguments and a length below 1 return 0x80240002 before the buffer is written; a handle or device this library did not return throws, as in the other calls.

sceUsbdGetStringDescriptorAscii rebuilds FreeBSD's libusb20_dev_req_string_simple_sync (libusb20.c) over host control transfers instead of calling the host libusb_get_string_descriptor_ascii, whose result differs (index 0 rejected, ? for non-ASCII characters, specific error codes). It reads each string with FreeBSD's single 255-byte request and skips the 4-byte header read that FreeBSD tries first: libusb's Windows HID backend (_hid_get_string_descriptor in windows_winusb.c) reports the requested length as bLength, so the two-step read cut the string to its first character (M for MYSTIC LIGHT ). The differences and the unverified console behaviour are recorded in docs/dev/debt/libSceUsbd.md.

Tested

Windows 11 Pro 10.0.26200, MinGW-w64 GCC 15.2.0 (WinLibs x86_64-ucrt-posix-seh r7), Release build.

  • ctest --test-dir build -R guest_usbd: passed. It covers null arguments, a zero length, and handles or devices this library did not return for the four calls, and checks that a rejected call leaves the buffer or output untouched.
  • guest_usbd_tests device with APS5_USBD_DEVICE set: passed on an MSI Mystic Light HID controller (1462:7D75) and a Wooting 80HE keyboard (31E3:1402). The configuration value matches the active config descriptor, the config descriptor found by that value has the same value, value 0 is not found, sceUsbdGetDescriptor returns the cached device descriptor, and the ASCII product string equals the printable characters of the product string in the device's first language (MYSTIC LIGHT , Wooting 80HE). A 4-byte buffer gets a terminated prefix.
  • On a Logitech LIGHTSPEED receiver (046D:C54D), the device run stops at the existing the cancel race failed check, after the new checks. main at 2c4b116da fails the same way on this receiver, so this change does not cause it.
  • Not tested on a PS5 or with a title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4953526928 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9190). Originally posted by [simnJS](https://github.com/simnJS) on 2026-10-21T14:48:22Z. --- ### What Implement `sceUsbdGetConfiguration`, `sceUsbdGetConfigDescriptorByValue`, `sceUsbdGetDescriptor` and `sceUsbdGetStringDescriptorAscii` over the host libusb, with the argument checks of FreeBSD 11.4 libusb (`libusb10.c`, `libusb10_desc.c`). Null arguments and a length below 1 return `0x80240002` before the buffer is written; a handle or device this library did not return throws, as in the other calls. `sceUsbdGetStringDescriptorAscii` rebuilds FreeBSD's `libusb20_dev_req_string_simple_sync` (`libusb20.c`) over host control transfers instead of calling the host `libusb_get_string_descriptor_ascii`, whose result differs (index 0 rejected, `?` for non-ASCII characters, specific error codes). It reads each string with FreeBSD's single 255-byte request and skips the 4-byte header read that FreeBSD tries first: libusb's Windows HID backend (`_hid_get_string_descriptor` in `windows_winusb.c`) reports the requested length as `bLength`, so the two-step read cut the string to its first character (`M` for `MYSTIC LIGHT `). The differences and the unverified console behaviour are recorded in `docs/dev/debt/libSceUsbd.md`. ### Tested Windows 11 Pro 10.0.26200, MinGW-w64 GCC 15.2.0 (WinLibs `x86_64-ucrt-posix-seh` r7), Release build. - `ctest --test-dir build -R guest_usbd`: passed. It covers null arguments, a zero length, and handles or devices this library did not return for the four calls, and checks that a rejected call leaves the buffer or output untouched. - `guest_usbd_tests device` with `APS5_USBD_DEVICE` set: passed on an MSI Mystic Light HID controller (`1462:7D75`) and a Wooting 80HE keyboard (`31E3:1402`). The configuration value matches the active config descriptor, the config descriptor found by that value has the same value, value 0 is not found, `sceUsbdGetDescriptor` returns the cached device descriptor, and the ASCII product string equals the printable characters of the product string in the device's first language (`MYSTIC LIGHT `, `Wooting 80HE`). A 4-byte buffer gets a terminated prefix. - On a Logitech LIGHTSPEED receiver (`046D:C54D`), the device run stops at the existing `the cancel race failed` check, after the new checks. `main` at 2c4b116da fails the same way on this receiver, so this change does not cause it. - Not tested on a PS5 or with a title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-21 15:42:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T15:42:17Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6044 core/libs/tests/GuestUsbd.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6320037169 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9190#issuecomment-6320037169). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T15:42:17Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestUsbd.cpp` |
MaxLikesCode commented 2026-10-21 18:11:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MaxLikesCode on 2026-10-21T18:11:45Z.


@simnJS I'd like to take the remaining sceUsbd placeholders over libusb with FreeBSD 11.4's checks, the way you did here: ClearHalt, SetInterfaceAltSetting, GetDevice, GetDeviceSpeed, GetMaxPacketSize, GetMaxIsoPacketSize, OpenDeviceWithVidPid and DetachKernelDriver first, then the event-handling calls. Are you already working on any of these? If not, I'll base mine on this PR so the two don't collide.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6323146730 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9190#issuecomment-6323146730). Originally posted by [MaxLikesCode](https://github.com/MaxLikesCode) on 2026-10-21T18:11:45Z. --- @simnJS I'd like to take the remaining `sceUsbd` placeholders over libusb with FreeBSD 11.4's checks, the way you did here: `ClearHalt`, `SetInterfaceAltSetting`, `GetDevice`, `GetDeviceSpeed`, `GetMaxPacketSize`, `GetMaxIsoPacketSize`, `OpenDeviceWithVidPid` and `DetachKernelDriver` first, then the event-handling calls. Are you already working on any of these? If not, I'll base mine on this PR so the two don't collide. AI-assisted: yes (Claude Code)
simnJS commented 2026-10-21 18:34:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simnJS on 2026-10-21T18:34:33Z.


@MaxLikesCode I'm not working on any of them, go ahead. Two things I hit while testing this PR on Windows:

  • libusb's Windows HID backend (_hid_get_string_descriptor in windows_winusb.c) reports the requested length as bLength, so a FreeBSD-style two-step read (4-byte header, then bLength bytes) cuts a string descriptor to its first character. Anything you port that reads a descriptor's length from a short first request will hit the same thing on HID devices.
  • The existing guest_usbd_tests device run fails at the cancel race failed on a Logitech LIGHTSPEED receiver (046D:C54D) on main too, so don't use that device to judge your changes.

I can run your branch's device tests on an MSI Mystic Light HID controller (1462:7D75) and a Wooting 80HE keyboard (31E3:1402) on Windows 11 once it's up.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6323600178 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9190#issuecomment-6323600178). Originally posted by [simnJS](https://github.com/simnJS) on 2026-10-21T18:34:33Z. --- @MaxLikesCode I'm not working on any of them, go ahead. Two things I hit while testing this PR on Windows: - libusb's Windows HID backend (`_hid_get_string_descriptor` in `windows_winusb.c`) reports the requested length as `bLength`, so a FreeBSD-style two-step read (4-byte header, then `bLength` bytes) cuts a string descriptor to its first character. Anything you port that reads a descriptor's length from a short first request will hit the same thing on HID devices. - The existing `guest_usbd_tests device` run fails at `the cancel race failed` on a Logitech LIGHTSPEED receiver (`046D:C54D`) on `main` too, so don't use that device to judge your changes. I can run your branch's device tests on an MSI Mystic Light HID controller (`1462:7D75`) and a Wooting 80HE keyboard (`31E3:1402`) on Windows 11 once it's up. AI-assisted: yes
MaxLikesCode commented 2026-10-21 18:50:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MaxLikesCode on 2026-10-21T18:50:19Z.


Thanks @simnJS. None of the new calls reads a descriptor's length from a short first request: the packet sizes come from libusb's parsed active configuration and sceUsbdOpenDeviceWithVidPid matches the cached device descriptor, so the HID length quirk doesn't apply. I ran the device tests on a CORSAIR Lighting Node CORE (1b1c:0c1a) and kept away from the LIGHTSPEED receiver.

They're up as #9338 (the eight device calls, on this PR) and #9339 (the event calls, on #9338). A run of guest_usbd_tests device from #9339's branch on your MSI and Wooting devices would be very welcome, since it covers both.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6323911362 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9190#issuecomment-6323911362). Originally posted by [MaxLikesCode](https://github.com/MaxLikesCode) on 2026-10-21T18:50:19Z. --- Thanks @simnJS. None of the new calls reads a descriptor's length from a short first request: the packet sizes come from libusb's parsed active configuration and `sceUsbdOpenDeviceWithVidPid` matches the cached device descriptor, so the HID length quirk doesn't apply. I ran the device tests on a CORSAIR Lighting Node CORE (`1b1c:0c1a`) and kept away from the LIGHTSPEED receiver. They're up as #9338 (the eight device calls, on this PR) and #9339 (the event calls, on #9338). A run of `guest_usbd_tests device` from #9339's branch on your MSI and Wooting devices would be very welcome, since it covers both. AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9190
No description provided.