ref: d8d26c7001d63537be2d4bf6c39778ad07e32e3a
parent: bedffdd8c3946a5a13a2ef7015b214ed8f8f5f66
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());
--
⑨