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 - ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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; |