Browse Source

Plan 9 from Bell Labs 2006-11-17

David du Colombier 14 years ago
parent
commit
4257aac03b

+ 3 - 3
dist/replica/_plan9.db

@@ -14104,15 +14104,15 @@ sys/src/cmd/usb/audio/usbaudioctl.c - 664 sys sys 1140695062 18245
 sys/src/cmd/usb/audio/usbaudioctl.h - 664 sys sys 1140695062 618
 sys/src/cmd/usb/lib - 20000000775 sys sys 1018369393 0
 sys/src/cmd/usb/lib/device.c - 664 sys sys 1144905083 3073
-sys/src/cmd/usb/lib/dump.c - 664 sys sys 1161484018 13032
+sys/src/cmd/usb/lib/dump.c - 664 sys sys 1163722010 12983
 sys/src/cmd/usb/lib/fmt.c - 664 sys sys 1091204978 291
 sys/src/cmd/usb/lib/mkfile - 664 sys sys 1091204979 204
 sys/src/cmd/usb/lib/setup.c - 664 sys sys 1091204978 1953
-sys/src/cmd/usb/lib/usb.h - 664 sys sys 1161484039 7123
+sys/src/cmd/usb/lib/usb.h - 664 sys sys 1163721974 7129
 sys/src/cmd/usb/lib/util.c - 664 sys sys 1091204978 523
 sys/src/cmd/usb/misc - 20000000775 sys sys 1091205037 0
 sys/src/cmd/usb/misc/mkfile - 664 sys sys 1091205037 274
-sys/src/cmd/usb/misc/usbmouse.c - 664 sys sys 1138027028 3475
+sys/src/cmd/usb/misc/usbmouse.c - 664 sys sys 1163722035 3603
 sys/src/cmd/usb/misc/usbprint - 775 sys sys 1101830683 256
 sys/src/cmd/usb/mkfile - 664 sys sys 1091327562 354
 sys/src/cmd/usb/mouse - 20000000775 sys sys 1017802022 0

+ 3 - 3
dist/replica/plan9.db

@@ -14104,15 +14104,15 @@ sys/src/cmd/usb/audio/usbaudioctl.c - 664 sys sys 1140695062 18245
 sys/src/cmd/usb/audio/usbaudioctl.h - 664 sys sys 1140695062 618
 sys/src/cmd/usb/lib - 20000000775 sys sys 1018369393 0
 sys/src/cmd/usb/lib/device.c - 664 sys sys 1144905083 3073
-sys/src/cmd/usb/lib/dump.c - 664 sys sys 1161484018 13032
+sys/src/cmd/usb/lib/dump.c - 664 sys sys 1163722010 12983
 sys/src/cmd/usb/lib/fmt.c - 664 sys sys 1091204978 291
 sys/src/cmd/usb/lib/mkfile - 664 sys sys 1091204979 204
 sys/src/cmd/usb/lib/setup.c - 664 sys sys 1091204978 1953
-sys/src/cmd/usb/lib/usb.h - 664 sys sys 1161484039 7123
+sys/src/cmd/usb/lib/usb.h - 664 sys sys 1163721974 7129
 sys/src/cmd/usb/lib/util.c - 664 sys sys 1091204978 523
 sys/src/cmd/usb/misc - 20000000775 sys sys 1091205037 0
 sys/src/cmd/usb/misc/mkfile - 664 sys sys 1091205037 274
-sys/src/cmd/usb/misc/usbmouse.c - 664 sys sys 1138027028 3475
+sys/src/cmd/usb/misc/usbmouse.c - 664 sys sys 1163722035 3603
 sys/src/cmd/usb/misc/usbprint - 775 sys sys 1101830683 256
 sys/src/cmd/usb/mkfile - 664 sys sys 1091327562 354
 sys/src/cmd/usb/mouse - 20000000775 sys sys 1017802022 0

+ 3 - 0
dist/replica/plan9.log

@@ -31735,3 +31735,6 @@
 1163343605 0 c sys/src/cmd/ls.c - 664 sys sys 1163342173 5715
 1163363406 0 c 386/bin/ls - 775 sys sys 1163362937 82624
 1163475006 0 c sys/src/libc/port/pool.c - 664 sys sys 1143695534 31040
+1163723406 0 c sys/src/cmd/usb/lib/dump.c - 664 sys sys 1163722010 12983
+1163723406 1 c sys/src/cmd/usb/lib/usb.h - 664 sys sys 1163721974 7129
+1163723406 2 c sys/src/cmd/usb/misc/usbmouse.c - 664 sys sys 1163722035 3603

+ 53 - 38
sys/src/cmd/usb/lib/dump.c

@@ -24,12 +24,12 @@ struct Classes {
 };
 
 static Classes	classname[] = {
-	[CL_AUDIO]		{"audio", {[1] {"control"}, [2] {"stream"}, [3]{"midi"}}},
-	[CL_COMMS]		{"comms", {[1] {"abstract", {[1]"AT"}}}},
-	[CL_HID]		{"hid", {[1]{"boot", {[1]"kbd", [2]"mouse"}}}},
-	[CL_PRINTER]	{"printer", {[1]"printer", {[1] "uni", [2]"bi"}}},
-	[CL_HUB]		{"hub", {[1]{"hub"}}},
-	[CL_DATA]		{"data"},
+	[CL_AUDIO]	{"audio",	{[1]{"control"}, [2]{"stream"}, [3]{"midi"}}},
+	[CL_COMMS]	{"comms",	{[1] {"abstract", {[1]"AT"}}}},
+	[CL_HID]	{"hid",		{[1] {"boot", {[1]"kbd", [2]"mouse"}}}},
+	[CL_PRINTER]	{"printer",	{[1]"printer", {[1]"uni", [2]"bi"}}},
+	[CL_HUB]	{"hub",		{[1]{"hub"}}},
+	[CL_DATA]	{"data"},
 };
 
 static	void	pflag(Flags*, uint);
@@ -94,7 +94,7 @@ phid(Device *, int, ulong, void *b, int n)
 	DHid *d;
 
 	if(n < DHIDLEN){
-		fprint(2, "hid too short\n");
+		fprint(2, "%s: hid too short\n", argv0);
 		return;
 	}
 	d = b;
@@ -382,12 +382,13 @@ pdesc(Device *d, int c, ulong csp, byte *b, int n)
 	void (*f)(Device *, int, ulong, void*, int);
 	int ifc = -1;
 	int dalt = -1;
-	int ep;
+	int i, ep;
 	int class, subclass, proto;
 	DConfig *dc;
 	DInterface *di;
 	DEndpoint *de;
-	int i;
+	Endpt *dep;
+	Dinf *dif;
 
 	class = Class(csp);
 
@@ -448,11 +449,13 @@ pdesc(Device *d, int c, ulong csp, byte *b, int n)
 					d->ep[0]->csp = csp;
 				d->config[c]->csp = csp;
 			}
-			if (d->config[c]->iface[ifc] == nil) {
-				d->config[c]->iface[ifc] = mallocz(sizeof(Dinf), 1);
-				d->config[c]->iface[ifc]->csp = csp;
+			dif = d->config[c]->iface[ifc];
+			if (dif == nil) {
+				d->config[c]->iface[ifc] = dif =
+					mallocz(sizeof(Dinf), 1);
+				dif->csp = csp;
 			}
-			d->config[c]->iface[ifc]->interface = di->bInterfaceNumber;
+			dif->interface = di->bInterfaceNumber;
 			break;
 		case ENDPOINT:
 			if(n < DENDPLEN)
@@ -486,41 +489,53 @@ pdesc(Device *d, int c, ulong csp, byte *b, int n)
 				fprint(2, "Unexpected ENDPOINT message\n");
 				return;
 			}
-			if (d->config[c]->iface[ifc] == nil)
-				sysfatal("d->config[c]->iface[ifc] == nil");
-			if (d->config[c]->iface[ifc]->dalt[dalt] == nil)
-				d->config[c]->iface[ifc]->dalt[dalt] = mallocz(sizeof(Dalt),1);
-			d->config[c]->iface[ifc]->dalt[dalt]->attrib = de->bmAttributes;
-			d->config[c]->iface[ifc]->dalt[dalt]->interval = de->bInterval;
+			dif = d->config[c]->iface[ifc];
+			if (dif == nil)
+				sysfatal("d->config[%d]->iface[%d] == nil",
+					c, ifc);
+			if (dif->dalt[dalt] == nil)
+				dif->dalt[dalt] = mallocz(sizeof(Dalt),1);
+			dif->dalt[dalt]->attrib = de->bmAttributes;
+			dif->dalt[dalt]->interval = de->bInterval;
 			ep = de->bEndpointAddress & 0xf;
-			if (debug) print("endpoint addr %d\n", ep); // DEBUG
-			if (d->ep[ep] == nil)
-				d->ep[ep] = newendpt(d, ep, class);
-			else print("endpoint already in use!\n"); // DEBUG
-			if(d->ep[ep]->maxpkt < GET2(de->wMaxPacketSize))
-				d->ep[ep]->maxpkt = GET2(de->wMaxPacketSize);
-			d->ep[ep]->addr = de->bEndpointAddress;
-			d->ep[ep]->dir = (de->bEndpointAddress & 0x80) ? Ein : Eout;
-			d->ep[ep]->type = de->bmAttributes & 0x03;
-			d->ep[ep]->isotype = (de->bmAttributes>>2) & 0x03;
-			d->ep[ep]->csp = csp;
-			d->ep[ep]->conf = d->config[c];
-			d->ep[ep]->iface = d->config[c]->iface[ifc];
-			for(i = 0; i < nelem(d->config[c]->iface[ifc]->endpt); i++){
-				if(d->config[c]->iface[ifc]->endpt[i] == nil){
-					d->config[c]->iface[ifc]->endpt[i] = d->ep[ep];
+			dep = d->ep[ep];
+			if (debug)
+				fprint(2, "%s: endpoint addr %d\n", argv0, ep);
+			if (dep == nil) {
+				d->ep[ep] = dep = newendpt(d, ep, class);
+				dep->dir = (de->bEndpointAddress & 0x80)?
+					Ein: Eout;
+			} else if ((dep->addr&0x80) !=
+			    (de->bEndpointAddress&0x80))
+				dep->dir = Eboth;
+			else
+				fprint(2, "%s: endpoint %d already in use!\n",
+					argv0, ep); // DEBUG
+			if(dep->maxpkt < GET2(de->wMaxPacketSize))
+				dep->maxpkt = GET2(de->wMaxPacketSize);
+			dep->addr = de->bEndpointAddress;
+			dep->type = de->bmAttributes & 0x03;
+			dep->isotype = (de->bmAttributes>>2) & 0x03;
+			dep->csp = csp;
+			dep->conf = d->config[c];
+			dep->iface = dif;
+			for(i = 0; i < nelem(dif->endpt); i++){
+				if(dif->endpt[i] == nil){
+					dif->endpt[i] = dep;
 					break;
 				}
 			}
-			if(i == nelem(d->config[c]->iface[ifc]->endpt))
+			if(i == nelem(dif->endpt))
 				fprint(2, "Too many endpoints\n");
-			if (d->nif <= ep) d->nif = ep+1;
+			if (d->nif <= ep)
+				d->nif = ep+1;
 			break;
 		default:
 			assert(nelem(dprinter) == 0x100);
 			f = dprinter[b[1]];
 			if(f != nil) {
-				(*f)(d, c, (dalt<<24) | (ifc<<16) | (csp&0xffff), b, b[0]);
+				(*f)(d, c, dalt<<24 | ifc<<16 | (csp&0xffff),
+					b, b[0]);
 				if (debug & Dbginfo)
 					fprint(2, "\n");
 			}

+ 3 - 2
sys/src/cmd/usb/lib/usb.h

@@ -169,6 +169,7 @@ enum
 	/* endpoint direction */
 	Ein = 0,
 	Eout,
+	Eboth,
 
 	/* endpoint type */
 	Econtrol = 0,
@@ -362,9 +363,9 @@ typedef struct Drivetab
 	void	(*driver)(Device *d);
 } Drivetab;
 
-#define Class(csp)		((csp)&0xff)
+#define Class(csp)	((csp)&0xff)
 #define Subclass(csp)	(((csp)>>8)&0xff)
-#define Proto(csp)		(((csp)>>16)&0xff)
+#define Proto(csp)	(((csp)>>16)&0xff)
 #define CSP(c, s, p)	((c) | ((s)<<8) | ((p)<<16))
 
 extern void (*dprinter[0x100])(Device *, int, ulong, void *b, int n);

+ 42 - 24
sys/src/cmd/usb/misc/usbmouse.c

@@ -1,16 +1,19 @@
 #include <u.h>
 #include <libc.h>
+#include <bio.h>
 #include <thread.h>
 
 int mousefd, ctlfd, mousein;
 
-char hbm[]		= "Enabled 0x020103";
+char hbm[]		= "0x020103";
 char *mouseinfile	= "/dev/mousein";
+
 char *statfmt		= "/dev/usb%d/%d/status";
 char *ctlfmt		= "/dev/usb%d/%d/ctl";
-char *msefmt		= "/dev/usb%d/%d/ep1data";
-char *ctl3str		= "ep 1 bulk r 3 32";
-char *ctl5str		= "ep 1 bulk r 5 32";
+char *msefmt		= "/dev/usb%d/%d/ep%ddata";
+
+char *ctlmsgfmt		= "ep %d bulk r %d 32";
+
 char ctlfile[32];
 char msefile[32];
 
@@ -20,6 +23,7 @@ int accel;
 int scroll;
 int maxacc = 3;
 int debug;
+int nbuts;
 
 void work(void *);
 
@@ -86,8 +90,10 @@ usage(void)
 void
 threadmain(int argc, char *argv[])
 {
-	int ctlrno, i, sfd;
-	char line[256];
+	int ctlrno, i, ep = 0;
+	char *p, *ctlstr;
+	char buf[256];
+	Biobuf *f;
 
 	ARGBEGIN{
 	case 's':
@@ -109,39 +115,49 @@ threadmain(int argc, char *argv[])
 	switch (argc) {
 	case 0:
 		for (ctlrno = 0; ctlrno < 16; ctlrno++) {
-			for (i = 0; i < 128; i++) {
-				snprint(line, sizeof line, statfmt, ctlrno, i);
-				sfd = open(line, OREAD);
-				if (sfd < 0)
+			sprint(buf, "/dev/usb%d", ctlrno);
+			if (access(buf, AEXIST) < 0)
+				continue;
+			for (i = 1; i < 128; i++) {
+				snprint(buf, sizeof buf, statfmt, ctlrno, i);
+				f = Bopen(buf, OREAD);
+				if (f == nil)
 					break;
-				if (read(sfd, line, strlen(hbm)) && strncmp(hbm, line, strlen(hbm)) == 0) {
-					snprint(ctlfile, sizeof ctlfile, ctlfmt, ctlrno, i);
-					snprint(msefile, sizeof msefile, msefmt, ctlrno, i);
-					close(sfd);
-					goto found;
+				while ((p = Brdline(f, '\n')) != 0) {
+					p[Blinelen(f)-1] = '\0';
+					if (strncmp(p, "Enabled ", 8) == 0)
+						continue;
+					if (strstr(p, hbm) != nil) {
+						ep = atoi(p);
+						goto found;
+					}
 				}
-				close(sfd);
+				Bterm(f);
 			}
 		}
 		threadexitsall("no mouse");
-	found:
-		break;
 	case 2:
 		ctlrno = atoi(argv[0]);
 		i = atoi(argv[1]);
+		ep = 1;			/* a guess */
+	found:
 		snprint(ctlfile, sizeof ctlfile, ctlfmt, ctlrno, i);
-		snprint(msefile, sizeof msefile, msefmt, ctlrno, i);
+		snprint(msefile, sizeof msefile, msefmt, ctlrno, i, ep);
 		break;
 	default:
 		usage();
 	}
 
+	nbuts = (scroll? 5: 3);
+	ctlstr = smprint(ctlmsgfmt, ep, nbuts);
 	if ((ctlfd = open(ctlfile, OWRITE)) < 0)
 		sysfatal("%s: %r", ctlfile);
 	if (verbose)
-		fprint(2, "Send %s to %s\n", scroll?ctl5str:ctl3str, ctlfile);
-	write(ctlfd, scroll?ctl5str:ctl3str, scroll?strlen(ctl5str):strlen(ctl3str));
+		fprint(2, "Send %s to %s\n", ctlstr, ctlfile);
+	write(ctlfd, ctlstr, strlen(ctlstr));
 	close(ctlfd);
+	free(ctlstr);
+
 	if ((mousefd = open(msefile, OREAD)) < 0)
 		sysfatal("%s: %r", msefile);
 	if (verbose)
@@ -157,13 +173,14 @@ threadmain(int argc, char *argv[])
 }
 
 void
-work(void *){
+work(void *)
+{
 	char buf[6];
 	int x, y, buts;
 
 	for (;;) {
 		buts = 0;
-		switch (robustread(mousefd, buf, scroll?5:3)) {
+		switch (robustread(mousefd, buf, nbuts)) {
 		case 4:
 			if(buf[3] == 1)
 				buts |= 0x08;
@@ -184,7 +201,8 @@ work(void *){
 				x = buf[1];
 				y = buf[2];
 			}
-			fprint(mousein, "m%11d %11d %11d", x, y, buts | maptab[buf[0]&0x7]);
+			fprint(mousein, "m%11d %11d %11d",
+				x, y, buts | maptab[buf[0]&0x7]);
 			break;
 		case -1:
 			sysfatal("read error: %r");