Unix Technical Forum

usb string length

This is a discussion on usb string length within the mailing.openbsd.tech forums, part of the OpenBSD category; --> bLength can only have values up to 255. bLength and bDescriptorType takes 2 bytes. So there are (255 - ...


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > mailing.openbsd.tech

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-18-2008, 09:30 AM
Marc Winiger
 
Posts: n/a
Default usb string length

bLength can only have values up to 255. bLength and bDescriptorType
takes 2 bytes. So there are (255 - 2) / 2 = 126.5 words for bString

strlen(string) is the lenghts without terminating NUL,
USB_MAX_STRING_LEN includes it.

I am wrong?


Index: usb.h
================================================== =================
RCS file: /var/cvs/src/sys/dev/usb/usb.h,v
retrieving revision 1.28
diff -u -r1.28 usb.h
--- usb.h 17 Jun 2007 07:53:11 -0000 1.28
+++ usb.h 22 Jul 2007 16:06:08 -0000
@@ -254,9 +254,9 @@
typedef struct {
uByte bLength;
uByte bDescriptorType;
- uWord bString[127];
+ uWord bString[126];
} __packed usb_string_descriptor_t;
-#define USB_MAX_STRING_LEN 128
+#define USB_MAX_STRING_LEN 127
#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */

/* Hub specific request */
Index: usbf_subr.c
================================================== =================
RCS file: /var/cvs/src/sys/dev/usb/usbf_subr.c,v
retrieving revision 1.9
diff -u -r1.9 usbf_subr.c
--- usbf_subr.c 15 Jun 2007 11:41:48 -0000 1.9
+++ usbf_subr.c 22 Jul 2007 16:06:08 -0000
@@ -308,8 +308,8 @@
dev->string_id == USBF_STRING_ID_MAX)
return USBF_EMPTY_STRING_ID;

- if ((len = strlen(string)) > USB_MAX_STRING_LEN)
- len = USB_MAX_STRING_LEN;
+ if ((len = strlen(string)) >= USB_MAX_STRING_LEN)
+ len = USB_MAX_STRING_LEN - 1;

oldsize = dev->sdesc_size;
newsize = oldsize + 2 + 2 * len;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:36 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com