-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
usb_update_sn_string_descriptor generates only even-length strings #69585
Comments
Hi @datacompboy! We appreciate you submitting your first issue for our open-source project. 🌟 Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙 |
This issue 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 issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time. |
I understand it's low priority, the only question I have: do anyone care (i can send the fix), or it's legacy USB stack that gets phased away anyway (and it'll be removed)? |
@datacompboy What are your thoughts on this one? diff --git a/subsys/usb/device/usb_descriptor.c b/subsys/usb/device/usb_descriptor.c
index 325989dc7fd..a55f621d1b4 100644
--- a/subsys/usb/device/usb_descriptor.c
+++ b/subsys/usb/device/usb_descriptor.c
@@ -347,12 +347,11 @@ static void usb_fix_ascii_sn_string_descriptor(struct usb_sn_descriptor *sn)
default_sn_len = strlen(CONFIG_USB_DEVICE_SN);
if (runtime_sn_len != default_sn_len) {
- LOG_ERR("the new SN descriptor doesn't have the same "
+ LOG_WRN("the new SN descriptor doesn't have the same "
"length as CONFIG_USB_DEVICE_SN");
- return;
}
- memcpy(sn->bString, runtime_sn, runtime_sn_len);
+ memcpy(sn->bString, runtime_sn, MIN(runtime_sn_len, default_sn_len));
} |
Thanks for the update! Yes, that should fix the issue (well, potentially losing the last byte of the random generated). But I gave it a little of thoughts, and actually feel like there little more there than just odd/even case. The Zephyr now have two ways to set the serial:
Right now it looks like as long as the board has uniq entropy source, Which means, what should be intended behaviour? I think the right behaviour should be explicit:
or do you think this is overkill? |
This has historically been the case and is a placeholder. zephyr/subsys/usb/device/Kconfig Lines 43 to 49 in c211cb3
Yes. And I do not want to introduce new Kconfig options or new features for this part. zephyr/subsys/usb/device/usb_descriptor.c Line 304 in c211cb3
|
Thanks, that makes sense now. |
Describe the bug
When CONFIG_USB_DEVICE_SN is set to odd-length string (e.g. "CHANGEMEPLZ" :), which is 11 characters):
To Reproduce
Steps to reproduce the behavior:
0. Take any USB sameple (e.g. samples/subsys/usb/console)
CONFIG_USB_DEVICE_SN="CHANGEMEPLZ"
Expected behavior
It should be some random string by default, e.g "A1B2C3D4E5F".
Impact
Annoyance
Additional context
The easiest fix is to add to the default
usb_update_sn_string_descriptor
implementation line:right before the final return, which will make string length right -- at expense of not using the lowest entropy bits.
Alternate solution is to change the return to:
which will use string of the right length and use the lowest entropy bits, but looks little bit cryptic.
The text was updated successfully, but these errors were encountered: