git: 9front

Download patch

ref: fccd42e65dc4c9f0b0ac212a02e1e49328540dcd
parent: 9cef0c457a201d212583c341376c1b4e5fc29930
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Mon Dec 10 05:36:53 EST 2012

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

--- a/sys/src/cmd/nusb/lib/dev.c
+++ b/sys/src/cmd/nusb/lib/dev.c
@@ -205,6 +205,7 @@
 loaddevstr(Dev *d, int sid)
 {
 	uchar buf[128];
+	int langid;
 	int type;
 	int nr;
 
@@ -211,7 +212,19 @@
 	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);
 }
 
--