From 3a4a3faf291b21624a4521fe1e22aec5bec7843d Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 7 May 2019 09:19:53 +0200 Subject: nusb/usbd: work around devices that ignore the high byte of wLength in control transfer reads there appear to be devices out there such as Realtek RTL2838UHIDIR SDR that do not process control transfers correctly, ignoring the high byte of the wLength field. to work around this, we specify an odd number of bytes for read sizes >= 256 which keeps the low byte 0xFF. --- sys/src/cmd/nusb/kb/kb.c | 7 ++++++- sys/src/cmd/nusb/lib/dev.c | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/sys/src/cmd/nusb/kb/kb.c b/sys/src/cmd/nusb/kb/kb.c index ccc8b3058..8d481aaee 100644 --- a/sys/src/cmd/nusb/kb/kb.c +++ b/sys/src/cmd/nusb/kb/kb.c @@ -42,7 +42,12 @@ struct Hiddev /* report descriptor */ int nrep; - uchar rep[512]; + + /* + * use odd size as some devices ignore the high byte of + * wLength in control transfer reads. + */ + uchar rep[512-1]; }; typedef struct Hidreport Hidreport; diff --git a/sys/src/cmd/nusb/lib/dev.c b/sys/src/cmd/nusb/lib/dev.c index cb79e1582..07e547799 100644 --- a/sys/src/cmd/nusb/lib/dev.c +++ b/sys/src/cmd/nusb/lib/dev.c @@ -136,8 +136,10 @@ enum /* * Max device conf is also limited by max control request size as * limited by Maxctllen in the kernel usb.h (both limits are arbitrary). + * Some devices ignore the high byte of control transfer reads so keep + * the low byte all ones. asking for 16K kills Newsham's disk. */ - Maxdevconf = 4 * 1024, /* asking for 16K kills Newsham's disk */ + Maxdevconf = 4*1024 - 1, }; int @@ -201,7 +203,7 @@ mkstr(uchar *b, int n) char* loaddevstr(Dev *d, int sid) { - uchar buf[256]; + uchar buf[256-2]; /* keep size < 256 */ int langid; int type; int nr; -- cgit v1.2.3