Skip to content

feat(libSceUsbd): pass the device, packet size, alternate setting and halt calls through to libusb - #9338

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
MaxLikesCode:feat/usbd-device-calls
Oct 25, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
MaxLikesCode:feat/usbd-device-calls

Conversation

@MaxLikesCode

@MaxLikesCode MaxLikesCode commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements eight more sceUsbd calls over the host libusb, with the argument checks and results of FreeBSD 11.4 libusb10.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.

Call Result
sceUsbdGetDevice the device of the handle; null for a null handle
sceUsbdGetDeviceSpeed libusb's speed, 0 to 4; a host SuperSpeed+ device reports SuperSpeed, the fastest speed FreeBSD 11.4 has; 0 for a null device
sceUsbdGetMaxPacketSize wMaxPacketSize of the first endpoint with that address in any interface and alternate setting of the active configuration, 0x80240005 if there is none, 0x80240004 for a null device
sceUsbdGetMaxIsoPacketSize the same, and above full speed (size & 0x7FF) * min(1 + ((size >> 11) & 3), 3)
sceUsbdOpenDeviceWithVidPid a handle to the first listed device with that vendor and product, or null
sceUsbdSetInterfaceAltSetting 0x80240002 for an interface outside 0 to 31, 0x80240005 for an interface the handle has not claimed, 0x802400FF for any other failure; the alternate setting is taken as 8 bits
sceUsbdClearHalt 0, or 0x802400FF for an endpoint the host does not find
sceUsbdDetachKernelDriver 0, or 0x802400FF for any failure; on Windows libusb cannot detach drivers, so it always returns 0x802400FF there

The two packet sizes are computed as FreeBSD computes them, not through the host's libusb_get_max_packet_size and libusb_get_max_iso_packet_size, which return LIBUSB_ERROR_OTHER for 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 by sceUsbdGetDevice for a handle from sceUsbdOpenDeviceWithVidPid can be used (and referenced) until that handle is closed.

These throw:

  • sceUsbdSetInterfaceAltSetting while the device has transfers in flight, which FreeBSD cancels first;
  • sceUsbdClearHalt for 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;
  • sceUsbdGetMaxIsoPacketSize for a null device, which FreeBSD dereferences;
  • like the other calls, any handle or device this library did not return.

docs/dev/debt/libSceUsbd.md moves 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, on main b4d1058 with #9190; this branch, which sits on #9190's commit, was rechecked merged onto main b00235d (guest_usbd 3 of 3, device run 2 of 2, conventions).

Checklist

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Progress report (cf528e7 → 64ae578)

📈 System libraries: 48.86% (+0.06%, +8 implemented functions)

✅ 8 implemented
Library Name
libSceUsbd sceUsbdClearHalt
libSceUsbd sceUsbdDetachKernelDriver
libSceUsbd sceUsbdGetDevice
libSceUsbd sceUsbdGetDeviceSpeed
libSceUsbd sceUsbdGetMaxIsoPacketSize
libSceUsbd sceUsbdGetMaxPacketSize
libSceUsbd sceUsbdOpenDeviceWithVidPid
libSceUsbd sceUsbdSetInterfaceAltSetting

Changed libraries (implemented exports)

Library Before After Change
libSceUsbd 44/61 (72.13%) 52/61 (85.25%) +13.11 pp

@xXPBSXx

xXPBSXx commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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 onto main df2569d2c5 (clean merge). I built guest_usbd_tests and ran the executable directly (exit code, not through ctest):

AI-assisted (Claude Code).

… halt calls through to libusb

sceUsbdGetDevice, sceUsbdGetDeviceSpeed, sceUsbdGetMaxPacketSize,
sceUsbdGetMaxIsoPacketSize, sceUsbdOpenDeviceWithVidPid,
sceUsbdSetInterfaceAltSetting, sceUsbdClearHalt and
sceUsbdDetachKernelDriver follow FreeBSD 11.4 libusb10.c over the host
libusb. The packet sizes and the alternate setting checks are done as
FreeBSD does them, so the library records which interfaces are claimed,
and a device stays known while a handle to it is open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxLikesCode
MaxLikesCode force-pushed the feat/usbd-device-calls branch from b77a110 to 64ae578 Compare October 25, 2026 00:19
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 25, 2026
@oneandonlydean
oneandonlydean merged commit 3f97477 into boykopovar:main Oct 25, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants