From d8d26c7001d63537be2d4bf6c39778ad07e32e3a Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Wed, 13 Aug 2014 01:10:59 +0200 Subject: 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. --- sys/src/cmd/nusb/ptp/ptp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sys/src/cmd/nusb/ptp/ptp.c b/sys/src/cmd/nusb/ptp/ptp.c index aae70d984..872773a03 100644 --- a/sys/src/cmd/nusb/ptp/ptp.c +++ b/sys/src/cmd/nusb/ptp/ptp.c @@ -45,7 +45,7 @@ struct Ptprpc uchar type[2]; uchar code[2]; uchar transid[4]; - uchar d[52]; + uchar d[500]; }; struct Node @@ -281,7 +281,7 @@ vptprpc(Ioproc *io, int code, int flags, va_list a) *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 @@ vptprpc(Ioproc *io, int code, int flags, va_list a) } } - 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 @@ threadmain(int argc, char **argv) } 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()); -- cgit v1.2.3