Some USB devices are not prepared to deal with a single byte string

descriptor request, which usbd_get_string_desc() uses to get the
length of a descriptor.  One device for instance returns a full 8
byte long packet instead which confuses the rest of the stack and
leads to the USB port being reset.  The fix is to instead request
two bytes, but not to complain if we only get one.

Submitted by:	kan
MFC after:	3 days
This commit is contained in:
joe 2003-01-14 23:07:43 +00:00
parent e9184d11f9
commit 519d68956b

View File

@ -153,15 +153,21 @@ usbd_get_string_desc(usbd_device_handle dev, int sindex, int langid,
{
usb_device_request_t req;
usbd_status err;
int actlen;
req.bmRequestType = UT_READ_DEVICE;
req.bRequest = UR_GET_DESCRIPTOR;
USETW2(req.wValue, UDESC_STRING, sindex);
USETW(req.wIndex, langid);
USETW(req.wLength, 1); /* only size byte first */
err = usbd_do_request(dev, &req, sdesc);
USETW(req.wLength, 2); /* only size byte first */
err = usbd_do_request_flags(dev, &req, sdesc, USBD_SHORT_XFER_OK,
&actlen, USBD_DEFAULT_TIMEOUT);
if (err)
return (err);
if (actlen < 1)
return (USBD_SHORT_XFER);
USETW(req.wLength, sdesc->bLength); /* the whole string */
return (usbd_do_request(dev, &req, sdesc));
}