Yifan-Liu1 opened a new pull request, #21443:
URL: https://github.com/apache/nuttx/pull/21443
## Summary
Two fixes that a class driver relying on the simulated host and on composite
devices needs before it can work; they are not specific to any one driver, but
only the USB video class exercises both paths today.
`arch/sim`: the libusb bridge dropped every class and vendor control
request, so a device that is configured through SET_CUR (a camera negotiating
its format, for instance) silently kept its defaults. It also freed an
isochronous completion with the host allocator although the request lives on
the NuttX heap, which corrupted the heap as soon as ISO streaming started, and
it handed the enumeration code a 256 byte buffer while the configuration
descriptor of a composite device can be several
hundred bytes. Forward class and vendor requests with
`libusb_control_transfer()`, hand the completed request back to the host
thread that owns it, and size the buffer from what such a device may report.
`SET_INTERFACE` was a TODO and only interface 0 was claimed, so a driver that
switches alternate settings elsewhere got `LIBUSB_ERROR_NOT_FOUND`; claim every
interface and forward the request.
`drivers/usbhost`: the composite builder skipped interfaces without
endpoints and stopped after the first alternate setting that had some. A device
that spreads one interface over several alternate settings — a camera keeps its
format and frame descriptors in the setting without endpoints and its
isochronous endpoint in the others — therefore lost the endpoint and its class
driver refused to connect. Walk the whole configuration and copy every
matching interface descriptor with the class specific descriptors and endpoints
that belong to it.
## Impact
- `arch/sim/src/sim/posix/sim_libusb.c`: class and vendor control requests
are forwarded instead of being acknowledged locally;
`SET_INTERFACE` is implemented and every interface of the active
configuration is claimed. Devices that only use standard requests and
never switch alternate settings behave as before.
- `arch/sim/src/sim/sim_usbhost.c`: the allocation handed to the enumeration
code grows from 256 bytes to 4 KiB.
- `drivers/usbhost/usbhost_composite.c`: zero-endpoint interfaces and all
alternate settings of an interface are copied; the scratch buffer is sized
from the configuration descriptor instead of a fixed estimate. Composite
devices whose interfaces have a single alternate setting keep the same
synthesized descriptor as before.
- No public API change.
## Testing
Build (simulator, gcc 13.4, libusb 1.0.25):
./tools/configure.sh sim:usbhost
# enable CONFIG_DRIVERS_VIDEO, CONFIG_VIDEO_STREAM, CONFIG_USBHOST_UVC
make -j$(nproc)
`tools/checkpatch.sh -c -u -m -g` is clean for both commits.
With a UVC camera (32e6:d412) passed through to the simulator, using the USB
video class host driver from the follow-up pull request, the camera now
enumerates and streams:
usbhost_enumerate: sizeof config data: 703
uvc_parse_cfgdesc: UVC: cfgdesc OK stream=1 fmts=2
uvc_register: UVC: register devpath=/dev/video0
uvc_execute_probe_commit: UVC: probe verified OK
uvc_execute_probe_commit: UVC: commit OK
uvc_set_interface_alt: UVC: selected alt=5 payload=1024
uvc_iso_pipe_init: UVC: pipe init slots=2 pkts=32 maxpkt=1024
captured 10 frames, 433622 bytes in 599 ms (16 fps)
Before this change the same setup stopped earlier: `Configuration doesn't
fit in buffer, length=703, maxlen=256`, `Unsupported standard request` for the
class requests, and `free(): invalid size` when streaming began.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]