git: 9front

Download patch

ref: 7a7862cb575d925e29f97f916a88448e7045f0c6
parent: 4d7df47019bebd1a1fd0b58505fc838cd2a8cb2d
author: ftrvxmtrx <devnull@localhost>
date: Wed Apr 23 19:45:00 EDT 2014

nusb: workaround for endpoints with same index but different types

nusb code assumes endpoint numbers are unique.  It's true in general
case, but it becomes false once the direction bit is ignored.  The
commit adds a check so that two endpoints of different types are not
merged into one with Eboth direction.  It does overwrite endpoint
though, so it shouldn't be considered as a full fix.

--- a/sys/src/cmd/nusb/lib/parse.c
+++ b/sys/src/cmd/nusb/lib/parse.c
@@ -96,7 +96,7 @@
 static int
 parseendpt(Usbdev *d, Conf *c, Iface *ip, Altc *altc, uchar *b, int n, Ep **epp)
 {
-	int i, dir, epid;
+	int i, dir, epid, type;
 	Ep *ep;
 	DEp *dep;
 
@@ -115,17 +115,20 @@
 		dir = Ein;
 	else
 		dir = Eout;
+	type = dep->bmAttributes & 0x03;
 	ep = d->ep[epid];
 	if(ep == nil){
 		ep = mkep(d, epid);
 		ep->dir = dir;
-	}else if((ep->addr & 0x80) != (dep->bEndpointAddress & 0x80))
+	}else if((ep->addr & 0x80) != (dep->bEndpointAddress & 0x80) && ep->type == type)
 		ep->dir = Eboth;
+	else
+		ep->dir = dir;
 	ep->maxpkt = GET2(dep->wMaxPacketSize);
 	ep->ntds = 1 + ((ep->maxpkt >> 11) & 3);
 	ep->maxpkt &= 0x7FF;
 	ep->addr = dep->bEndpointAddress;
-	ep->type = dep->bmAttributes & 0x03;
+	ep->type = type;
 	ep->isotype = (dep->bmAttributes>>2) & 0x03;
 	ep->conf = c;
 	ep->iface = ip;
--