summaryrefslogtreecommitdiff
path: root/sys/src/cmd/nusb/lib
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2012-12-10 10:36:53 +0100
committercinap_lenrek <cinap_lenrek@gmx.de>2012-12-10 10:36:53 +0100
commit3971337d1396ee1bca891b071222b9ca46b55190 (patch)
tree6b61a739da0ec196039b55881bdfeeeb5237487a /sys/src/cmd/nusb/lib
parent8f0ed004208ea8ed438dad308137e40eb1188549 (diff)
nusb: provide language id when reading string descriptors (thanks ftrvxmtrx)
there are devices which do not return a string if used with invalid language id, so at least try to use the first one and choose english if failed. this fixes CDC ethernet for N900
Diffstat (limited to 'sys/src/cmd/nusb/lib')
-rw-r--r--sys/src/cmd/nusb/lib/dev.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/sys/src/cmd/nusb/lib/dev.c b/sys/src/cmd/nusb/lib/dev.c
index 2748dd4a2..f7f57266f 100644
--- a/sys/src/cmd/nusb/lib/dev.c
+++ b/sys/src/cmd/nusb/lib/dev.c
@@ -205,13 +205,26 @@ char*
loaddevstr(Dev *d, int sid)
{
uchar buf[128];
+ int langid;
int type;
int nr;
if(sid == 0)
return estrdup("none");
type = Rd2h|Rstd|Rdev;
- nr=usbcmd(d, type, Rgetdesc, Dstr<<8|sid, 0, buf, sizeof(buf));
+
+ /*
+ * there are devices which do not return a string if used
+ * with invalid language id, so at least try to use the first
+ * one and choose english if failed
+ */
+ nr=usbcmd(d, type, Rgetdesc, Dstr<<8, 0, buf, sizeof(buf));
+ if(nr < 4)
+ langid = 0x0409; // english
+ else
+ langid = buf[3]<<8|buf[2];
+
+ nr=usbcmd(d, type, Rgetdesc, Dstr<<8|sid, langid, buf, sizeof(buf));
return mkstr(buf, nr);
}