feat(libSceUsbd): pass the device, packet size, alternate setting and halt calls through to libusb #9338
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9338"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MaxLikesCode on 2026-10-21T18:48:26Z.
What
Implements eight more
sceUsbdcalls over the host libusb, with the argument checks and results of FreeBSD 11.4libusb10.c, as #9190 does for the configuration and descriptor queries. Their signatures were already in the file, from the console type database in orbital; shadPS4 maps each of these calls one-to-one onto libusb.sceUsbdGetDevicesceUsbdGetDeviceSpeedsceUsbdGetMaxPacketSizewMaxPacketSizeof the first endpoint with that address in any interface and alternate setting of the active configuration,0x80240005if there is none,0x80240004for a null devicesceUsbdGetMaxIsoPacketSize(size & 0x7FF) * min(1 + ((size >> 11) & 3), 3)sceUsbdOpenDeviceWithVidPidsceUsbdSetInterfaceAltSetting0x80240002for an interface outside 0 to 31,0x80240005for an interface the handle has not claimed,0x802400FFfor any other failure; the alternate setting is taken as 8 bitssceUsbdClearHalt0x802400FFfor an endpoint the host does not findsceUsbdDetachKernelDriver0x802400FFfor any failure; on Windows libusb cannot detach drivers, so it always returns0x802400FFthereThe two packet sizes are computed as FreeBSD computes them, not through the host's
libusb_get_max_packet_sizeandlibusb_get_max_iso_packet_size, which returnLIBUSB_ERROR_OTHERfor an unreadable configuration and scale SuperSpeed endpoints by their companion descriptor.To make the alternate setting check FreeBSD's, the library now records which interfaces each handle has claimed (
sceUsbdClaimInterface,sceUsbdReleaseInterface,sceUsbdClose,sceUsbdExit). A device also stays known while a handle to it is open, so the device returned bysceUsbdGetDevicefor a handle fromsceUsbdOpenDeviceWithVidPidcan be used (and referenced) until that handle is closed.These throw:
sceUsbdSetInterfaceAltSettingwhile the device has transfers in flight, which FreeBSD cancels first;sceUsbdClearHaltfor host errors other than a missing endpoint, because FreeBSD ignores the result of the clear itself, so they have no known result; and for a null handle, which FreeBSD dereferences;sceUsbdGetMaxIsoPacketSizefor a null device, which FreeBSD dereferences;docs/dev/debt/libSceUsbd.mdmoves the eight calls from the unknown list to two entries that say what follows FreeBSD and what the host cannot do. The event calls (sceUsbdHandleEvents, the event locks,sceUsbdWaitForEvent,sceUsbdEventHandlerActive) are left for a separate change.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, full Release build with
BUILD_TESTING=ON, onmainb4d10586ewith #9190; this branch, which sits on #9190's commit, was rechecked merged ontomainb00235dda(guest_usbd3 of 3, device run 2 of 2, conventions).guest_usbdgains checks for null and unknown handles and devices for all eight calls, and forsceUsbdOpenDeviceWithVidPidwith no matching device, before and aftersceUsbdExit. It passes 3 of 3. WithExport.cppfrom #9190 and the new tests, it fails at the first placeholder (sceUsbdDetachKernelDriver not implemented).guest_usbd_tests devicewithAPS5_USBD_DEVICE=1b1c:0c1a(CORSAIR Lighting Node CORE, full speed, HID) passes 12 of 12 runs and checks:sceUsbdGetDeviceof an open handle is the device it was opened from, and the speed is 1 to 4 (2 here);0x80240005for an absent endpoint;0x80240005before the claim and after the release,0x80240002for interfaces 32 and -1, and 0 for setting 0 of the claimed interface;sceUsbdClearHaltreturns 0 on the interrupt endpoint and0x802400FFfor an absent one;sceUsbdDetachKernelDriverreturns0x802400FF(Windows);sceUsbdOpenDeviceWithVidPidopens it again, its device has the same vendor and product and the same packet size, and that device is unknown again once the handle is closed.0b05:19af), the device run stops at #9190's existingclaiming an interface failed, before the new checks: Windows does not give libusb its non-HID interfaces.python tools/select_tests.py ctest build --output-on-failure --timeout 180 --parallel 8: 1523 of the 1526 selected tests pass. The 3 failures areagc_driver_sample_order,agc_driver_sample_order_grid_referenceandagc_driver_sample_order_recipe_depth_locations, which fail the same way onmainon this RTX 4090 and which #9056 fixes.agc_driver_image_array_window_past_layer_limitis not built: it does not compile with MinGW onmain(#8310).python tools/check_conventions.py --base origin/mainpasses.python tools/pr_overlap.py --branch feat/usbd-device-callsreports only #9190, which this builds on. #9116 adds test lines toGuestUsbd.cpptoo; the two merge cleanly.guest_usbd_tests devicefrom #9339's branch, which contains #9338, on Windows 11 Pro 26200 (comment): an MSI Mystic Light HID controller (1462:7D75, full speed) and a Wooting 80HE keyboard (31E3:1402, high speed) pass 3 of 3 each, andsceUsbdDetachKernelDriverreturns0x802400FFon both. On the Wooting the iso packet size check takes the multiplier path above full speed.guest_usbd_testson Linux (WSL2, Ubuntu 24.04, GCC 13.3, Release) from this head merged ontomaindf2569d2c5(comment): it exits with 0, and withExport.cppreset tomainit aborts (SIGABRT).main38d463a6cfafter #10706 moved the declarations intolibSceUsbd/include/Api.hpp, which already declares the eight calls with these signatures. At64ae578dda,guest_usbdpasses 3 of 3 and fails 3 of 3 withExport.cppfrommain, and the device run withAPS5_USBD_DEVICE=1b1c:0c1apasses 2 of 2.public_headersand the conventions check pass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-22T04:41:26Z.
Linux data point for
b77a110791(WSL2, Ubuntu 24.04, kernel 6.18 - a virtualised kernel, not bare-metal Linux; GCC 13.3, Release,BUILD_TESTING=ON), this head merged ontomaindf2569d2c5(clean merge). I builtguest_usbd_testsand ran the executable directly (exit code, not throughctest):main, withcore/libs/prx/libSceUsbd/Export.cppreset tomain): it aborts (SIGABRT, exit code 134).Note: #9339 changes the same test file (
guest_usbd); this run covers this head only.Not tested: macOS, Windows, the rest of the test suite.
AI-assisted (Claude Code).