- loaddevdesc() should request 18 bytes as per the spec. this avoids the problem of getting just a 17 byte descriptor. - loaddevstr() should request 256 bytes, as per standard. respect the length embedded in the string. - loaddevstr() should set a language id. this is important for some devices. Reference: /n/atom/patch/applied/usbshortdesc2 Date: Wed Mar 5 14:59:29 CET 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/usb/lib/dev.c Wed Mar 5 14:59:22 2014 +++ /sys/src/cmd/usb/lib/dev.c Wed Mar 5 14:59:23 2014 @@ -181,16 +181,16 @@ } static char* -mkstr(uchar *b) +mkstr(uchar *b, int n) { Rune r; char *us; char *s; char *e; - int n; - n = b[0]+2; - if((n & 1) != 0) + if(n > b[0]) + n = b[0]; + if(n <= 2 || (n & 1) != 0) return strdup("none"); n = (n - 2)/2; b += 2; @@ -218,10 +218,8 @@ else langid = buf[3]<<8 | buf[2]; nr = usbcmd(d, type, Rgetdesc, Dstr<<8|sid, langid, buf, sizeof(buf)); - if(nr < 2) - return estrdup("none"); - return mkstr(buf); + return mkstr(buf, nr); } int @@ -233,7 +231,6 @@ Ep *ep0; type = Rd2h|Rstd|Rdev; - nr = sizeof(buf); memset(buf, 0, Ddevlen); if((nr = usbcmd(d, type, Rgetdesc, Ddev<<8|0, 0, buf, Ddevlen)) < 0) return -1;