subsys: usb: host: Add USB Host Class Support#99334
subsys: usb: host: Add USB Host Class Support#99334santhosh-c-c wants to merge 8 commits intozephyrproject-rtos:mainfrom
Conversation
Add a "struct usbh_status" that contains a bitmask of flags to keep track of the global state of the host context, like done for the device_next implementation. Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Add a "struct usbh_class_api" for the host implementation, and move all the function poitners to it. Add more fields to "struct usbh_class_data". Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
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>
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>
Allocate extra room at the end of the USB descriptor buffer to ensure that the device ends with `desc->bLength == 0`. For now, validating `desc->bLength` from the device to ensure no access past the buffer is still not done. Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
This commit invokes usbh_class_remove_all() in the device removal handler to clean up USB classes when a device is disconnected. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
This patch adds NULL checks in usbh_desc_get_next_function() to prevent invalid dereferencing. Return the descriptor when the requested interface is found to prevent infinite loop. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
This patch modifies the USB device int sequence to read the device descriptor only after setting a valid device address. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
|
|
Thank you for this PR! I integrated everything into #94590 for convenience. If/once you test, let me know if this did not work for the classes you worked on. Feedback welcome for usability and convenience of the API as well. |
|
I updated your message to point at the downstream PRs that rely on this, to help people navigate the tree. |
Hello @josuah |
|
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |



Dependency:
Downstream:
Upstream Reference:
This implementation contains all commits from #94590 plus the following enhancements:
Invoke usbh_class_remove_all() from dev_remove_handler() to cleanup classes on device removal.
Improve descriptor traversal to prevent infinite loop.
Read device descriptor only after setting a valid device address.
WIP: Currently, this is a draft PR and further changes are planned.
Signed-off-by: Santhosh Charles santhosh@linumiz.com