git: 9front

Download patch

ref: 517ede7fb709400cc8497619a6cf8c8f4e1fe5fe
parent: 7455b8ffaf6fad8a872581de346064e590fa35dc
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Aug 12 21:10:59 EDT 2014

nusb/ptp: do maxpkt reads to avoid babble error with usb 2.0 devices (thanks mischief!)

mischief got babble error with his mobile phone as we used to
read at max 64 bytes for the data response phase. his device
has 512 byte packet size.

thans to mischief for the patience.

--- a/sys/src/cmd/nusb/ptp/ptp.c
+++ b/sys/src/cmd/nusb/ptp/ptp.c
@@ -45,7 +45,7 @@
 	uchar	type[2];
 	uchar	code[2];
 	uchar	transid[4];
-	uchar	d[52];
+	uchar	d[500];
 };
 
 struct Node
@@ -281,7 +281,7 @@
 		*prdata = nil;
 		*prdatalen = 0;
 
-		while((n = ioread(io, usbep[In]->dfd, &rpc, sizeof(rpc))) <= 0){
+		while((n = ioread(io, usbep[In]->dfd, &rpc, usbep[In]->maxpkt)) <= 0){
 			if(n < 0){
 				wasinterrupt();
 				return -1;
@@ -334,7 +334,7 @@
 		}
 	}
 
-	while((n = ioread(io, usbep[In]->dfd, &rpc, sizeof(rpc))) <= 0){
+	while((n = ioread(io, usbep[In]->dfd, &rpc, usbep[In]->maxpkt)) <= 0){
 		if(n < 0){
 			wasinterrupt();
 			return -1;
@@ -1028,6 +1028,8 @@
 	}
 	if(usbep[In]->dfd < 0 || usbep[Out]->dfd < 0)
 		sysfatal("open endpoints: %r");
+	if(usbep[In]->maxpkt < 12 || usbep[In]->maxpkt > sizeof(Ptprpc))
+		sysfatal("bad packet size: %d\n", usbep[In]->maxpkt);
 	iochan = chancreate(sizeof(Ioproc*), 1);
 	sendp(iochan, ioproc());
 
--