Skip to content

Conversation

@santhosh-c-c
Copy link

@santhosh-c-c santhosh-c-c commented Nov 13, 2025

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

Josuah Demangeon and others added 8 commits November 13, 2025 23:29
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>
@josuah
Copy link
Contributor

josuah commented Nov 16, 2025

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.

@josuah
Copy link
Contributor

josuah commented Nov 16, 2025

I updated your message to point at the downstream PRs that rely on this, to help people navigate the tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants