Skip to content

subsys: usb: host: Add USB Host Class Support#99334

Closed
santhosh-c-c wants to merge 8 commits intozephyrproject-rtos:mainfrom
linumiz:upstream/subsys-usbh-class-support
Closed

subsys: usb: host: Add USB Host Class Support#99334
santhosh-c-c wants to merge 8 commits intozephyrproject-rtos:mainfrom
linumiz:upstream/subsys-usbh-class-support

Conversation

@santhosh-c-c
Copy link
Copy Markdown
Contributor

@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>
@sonarqubecloud
Copy link
Copy Markdown

@josuah
Copy link
Copy Markdown
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
Copy Markdown
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.

@santhosh-c-c
Copy link
Copy Markdown
Contributor Author

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.

Hello @josuah
I’ll re-test with the integrated changes and share feedback soon regarding the class behavior and API flow.

@github-actions
Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the Stale label Jan 16, 2026
@github-actions github-actions Bot closed this Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants