Skip to content

usb: host: ch9: Add string descriptor request helper function#102941

Open
D-Veda wants to merge 2 commits intozephyrproject-rtos:mainfrom
nxp-upstream:usbh_add_str_desc_helper_func
Open

usb: host: ch9: Add string descriptor request helper function#102941
D-Veda wants to merge 2 commits intozephyrproject-rtos:mainfrom
nxp-upstream:usbh_add_str_desc_helper_func

Conversation

@D-Veda
Copy link
Copy Markdown

@D-Veda D-Veda commented Jan 27, 2026

Add 4 functions to handle USB string descriptor operations:

  • usbh_req_desc_str() to retrieve USB string descriptors from device
  • usbh_desc_is_valid_string() to validate string descriptor type
  • usbh_desc_get_supported_langs() to get supported languages list
  • usbh_desc_str_utf16le_to_ascii() to convert UTF-16LE string to ASCII

Copy link
Copy Markdown
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an utility missing so thank you.

Some question about what should be done in this function, and what should be done by the user.

Comment thread subsys/usb/host/usbh_ch9.c Outdated
Comment thread subsys/usb/host/usbh_ch9.c Outdated
Comment thread subsys/usb/host/usbh_ch9.c Outdated
Comment thread subsys/usb/host/usbh_ch9.c Outdated
Comment thread subsys/usb/host/usbh_ch9.c Outdated
@D-Veda D-Veda force-pushed the usbh_add_str_desc_helper_func branch from 97be2a3 to 6c146e2 Compare January 28, 2026 03:18
@D-Veda D-Veda requested review from jfischer-no and josuah January 28, 2026 03:21
@D-Veda D-Veda force-pushed the usbh_add_str_desc_helper_func branch from 6c146e2 to 8cda99d Compare February 6, 2026 09:03
Comment thread subsys/usb/host/usbh_ch9.c
@D-Veda D-Veda force-pushed the usbh_add_str_desc_helper_func branch from 8cda99d to 96c0c49 Compare February 12, 2026 03:34
@D-Veda D-Veda requested review from josuah February 12, 2026 03:34
Copy link
Copy Markdown
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more suggestion for polishing things.

I think closer to completion now.

Thank you!

Comment thread subsys/usb/host/usbh_ch9.c Outdated
Comment thread subsys/usb/host/usbh_ch9.c Outdated
Comment thread subsys/usb/host/usbh_desc.c Outdated
Comment thread subsys/usb/host/usbh_desc.c Outdated
Comment thread subsys/usb/host/usbh_desc.c Outdated
Comment thread subsys/usb/host/usbh_desc.h Outdated
Comment thread subsys/usb/host/usbh_desc.c Outdated
Comment thread subsys/usb/host/usbh_desc.h Outdated
@D-Veda D-Veda force-pushed the usbh_add_str_desc_helper_func branch from 96c0c49 to e7c8c46 Compare February 13, 2026 08:20
josuah
josuah previously approved these changes Feb 13, 2026
@josuah
Copy link
Copy Markdown
Contributor

josuah commented Feb 13, 2026

Letting some threads open but issues are addressed, thank you for the changes.

tmon-nordic
tmon-nordic previously approved these changes Feb 18, 2026
Comment thread subsys/usb/host/usbh_desc.h Outdated
@D-Veda D-Veda dismissed stale reviews from tmon-nordic and josuah via efd5bd7 March 2, 2026 09:29
@D-Veda D-Veda force-pushed the usbh_add_str_desc_helper_func branch from e7c8c46 to efd5bd7 Compare March 2, 2026 09:29
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 2, 2026

@D-Veda D-Veda requested review from josuah and tmon-nordic March 3, 2026 05:36
josuah
josuah previously approved these changes Mar 3, 2026
tmon-nordic
tmon-nordic previously approved these changes Mar 16, 2026
@mmahadevan108
Copy link
Copy Markdown
Contributor

@jfischer-no , can you revisit this PR.

Comment thread subsys/usb/host/usbh_ch9.c Outdated
Comment thread subsys/usb/host/usbh_desc.c Outdated

bool usbh_desc_is_valid_string(const void *const desc)
{
return usbh_desc_is_valid(desc, sizeof(struct usb_string_descriptor), USB_DESC_STRING);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering how net_buf are typically used, I have doubts how useful this helper is.

Comment thread subsys/usb/host/usbh_desc.c Outdated
uint8_t langs;
int ret;

if (lang_ids == NULL) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would it be used this way? This seems too complicated just to get a list of supported LANGIDs.

Comment thread subsys/usb/host/usbh_desc.c Outdated
Comment thread subsys/usb/host/usbh_desc.c Outdated
Comment thread subsys/usb/host/usbh_desc.c Outdated
Comment thread subsys/usb/host/usbh_desc.c Outdated
Comment on lines +297 to +299
if (desc_buf->frags != NULL) {
return -EINVAL;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would there by any?

Comment thread subsys/usb/host/usbh_desc.c Outdated
has_non_ascii = false;
utf16le_byte = (const uint8_t *)&str_desc->bString;
for (copy_idx = 0; copy_idx < MIN(utf16le_str_len, len - 1); copy_idx++) {
utf16le_code = sys_get_le16(&utf16le_byte[copy_idx * 2]);
Copy link
Copy Markdown
Contributor

@jfischer-no jfischer-no Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not how we use net_buf. This PR needs complete rework. We have tests for the device string descriptor, so that is roughly what we need. I will open a pull request against your branch (nxp-upstream#21).

Comment thread subsys/usb/host/usbh_desc.c Outdated
Comment thread subsys/usb/host/usbh_desc.c Outdated
@D-Veda D-Veda dismissed stale reviews from tmon-nordic and josuah via b86fe4b April 9, 2026 02:29
@D-Veda D-Veda force-pushed the usbh_add_str_desc_helper_func branch from efd5bd7 to b86fe4b Compare April 9, 2026 02:29
@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Apr 9, 2026
@zephyrbot zephyrbot requested a review from nashif April 9, 2026 02:31
Comment thread subsys/usb/host/usbh_desc.c Outdated
Comment thread subsys/usb/host/usbh_desc.c Outdated
return -EINVAL;
}

net_buf_simple_clone(&buf->b, &tmp_buf);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to clone the buffer?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of net_buf_simple_clone() here to perform a shallow copy is solely to prevent modification of the original data. If net_buf_pull_u8() were used directly to retrieve the data, the header of the original string descriptor would be modified, posing a risk if the caller intends to reuse that descriptor.

Comment thread subsys/usb/host/usbh_desc.c
Comment thread subsys/usb/host/usbh_desc.c Outdated
D-Veda and others added 2 commits April 20, 2026 13:00
Add 4 functions to handle USB string descriptor operations:
- usbh_req_desc_str() to retrieve USB string descriptors from device
- usbh_desc_is_valid_string() to validate string descriptor type
- usbh_desc_get_supported_langs() to get supported languages list
- usbh_desc_str_utfle16_to_ascii() to convert UTF-16LE string to ASCII

Co-authored-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Dv Alan <zhangyang.shen@nxp.com>
Use the recently introduced descriptor helper in the device stack tests.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
@D-Veda D-Veda force-pushed the usbh_add_str_desc_helper_func branch from b86fe4b to 3c50964 Compare April 20, 2026 05:01
@D-Veda D-Veda requested a review from jfischer-no April 20, 2026 05:03
@sonarqubecloud
Copy link
Copy Markdown

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

Labels

area: Tests Issues related to a particular existing or missing test area: USB Universal Serial Bus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants