USB Host: integrate class API [2: helpers]#94590
USB Host: integrate class API [2: helpers]#94590fabiobaltieri merged 13 commits intozephyrproject-rtos:mainfrom
Conversation
e57477d to
b3b4bc4
Compare
e672ee8 to
d04bbfb
Compare
d04bbfb to
7073da8
Compare
f095c02 to
3e111d0
Compare
|
Add API wrappers around the function pointers in struct usbh_class_api, while also documenting the USB host class internal API. Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
In addition to storing the interface pointers, also store the pointers for the interface association. Also add comments to the other fields of the structs to adapt to a new CI check. Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
MarkWangChinese
left a comment
There was a problem hiding this comment.
We do some basic tests with video, hub and ecm PRs, and find the follow two issues. Please check.
|
I am surprised CI did not catch that so will reproduce it on CI shortly and will add the modifications. |
| if ((uint8_t *)dhp + sizeof(struct usb_desc_header) > (uint8_t *)desc_end || | ||
| (uint8_t *)dhp + dhp->bLength > (uint8_t *)desc_end || | ||
| dhp->bLength <= sizeof(struct usb_desc_header)) { | ||
| LOG_ERR("Invalid descriptor size %d.", dhp->bLength); | ||
| return -EINVAL; | ||
| } |
There was a problem hiding this comment.
I think it is good to go as-is for now, but eventually there should be also other sanity checks because descriptors are essentially tainted (coming from untrusted source).
There was a problem hiding this comment.
One pitfall I can see is if dhp + sizeof(struct some_class_specific_descriptor) > desc_end.
It seems like it is up to the classes to verify this given only the classes know sizeof(...)?
There was a problem hiding this comment.
You are right that only classes know the class specific descriptors.
Endpoint descriptor is problematic because it can be 7 (USB specification itself) or 9 (USB Audio 1.0 class). I believe this is the only instance of such thing happening and there was some note that this won't happen again.
Add helpers to parse and validate USB descriptors. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no> Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Add basic functions to initialize and probe class drivers. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no> Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Add functions to probe/remove all classes as part of a new usbh_class.c and a matching usbh_class.h. These functions are called from the function usbh_init_device_intl() in usbh_core.c to initialize every class upon connection of a device. Every class driver provide filters to match the interfaces of the device. Co-authored-by: Aiden Hu <weiwei.hu@nxp.com> Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Move the UVC header with all the definitions from the UVC standard to share it between USB host and device class implementation. Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Make sure that there is at least enough room for the header before dereferencing the fields such as bLength. Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Allocate a larger size to keep room for a nil descriptor at the end of the configuration descriptor. This is used to walk through the list of descriptors until this empty descriptor happens. Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Add tests making sure the USB Host class APIs introduced build and run as expected. Use USB device samples common code for initialization. Co-authored-by: Johann Fischer <johann.fischer@nordicsemi.no> Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no> Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
The USB host will have to select the appropriate size for the configurtion descriptor, and the defaults will not be enough for some classes that encode a lot of information in the configuration descriptor. Add logging to debug this. Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
|
|
heya, spotted this in the main CI run could you folks look into it? |
|
seems to be clang specific, can reproduce locally $ export ZEPHYR_TOOLCHAIN_VARIANT=llvm
$ west build -p -b native_sim/native tests/subsys/usb/device_next
...
zephyrproject/zephyr/subsys/usb/host/usbh_desc.c:16:6: error: conflicting types for 'usbh_desc_is_valid'
16 | bool usbh_desc_is_valid(const void *const desc,
| ^
/home/fabiobaltieri/zephyrproject/zephyr/subsys/usb/host/usbh_desc.h:92:12: note: previous declaration is here
92 | const bool usbh_desc_is_valid(const void *const desc,
| ^ |
|
nvm I'll open the fix myself #103579 |



Main thread:
Downstream:
It contains all the commits of the previous PR, and in addition:
struct usbh_class_dataandusbh_class_apiThis also contains functions imported from #94085 by @AidenHu.
So far, this was only tested with this command to make sure it builds and run, but not in hardware yet:
The PR #94085 got then completely rebased on top of this, available at
josuah:enable_usb_host_video_class_api2, which is meant as a drop-in replacement for #94085.It was also built (but not run) with this command:
All tests are done on top of main...josuah:zephyr:pr_usb_host_class_api2