From: Martin Holst Swende Date: Thu, 16 Jul 2015 22:01:58 +0000 (+0200) Subject: Potential fix for 0-length usb packets seen on OSX X-Git-Tag: v2.3.0~36^2~4 X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/83f3f8ac40b47e220954e620a5ecbe41f54f4dc7 Potential fix for 0-length usb packets seen on OSX --- diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 188d7280..733bc953 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -399,14 +399,10 @@ void SimulateTagLowFrequency(int period, int gap, int ledcontrol) #define OPEN_COIL() HIGH(GPIO_SSC_DOUT) i = 0; - byte_t rx[sizeof(UsbCommand)]; // Storage for usb_read call in loop for(;;) { //wait until SSC_CLK goes HIGH while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) { - // Craig Young - Adding a usb_read() here to avoid abort on empty UsbCommand - // My OS X client does this preventing simulation. - // Performance hit should be non-existent since the read is only performed if usb_poll is true - if(BUTTON_PRESS() || (usb_poll() && usb_read(rx,sizeof(UsbCommand)))) { + if(BUTTON_PRESS() || (usb_poll_validate_length() )) { DbpString("Stopped"); return; } diff --git a/common/usb_cdc.c b/common/usb_cdc.c index ccbb3c50..3c6e9282 100644 --- a/common/usb_cdc.c +++ b/common/usb_cdc.c @@ -293,6 +293,22 @@ bool usb_poll() return (pUdp->UDP_CSR[AT91C_EP_OUT] & btReceiveBank); } +/** + In github PR #129, some users appears to get a false positive from + usb_poll, which returns true, but the usb_read operation + still returns 0. + This check is basically the same as above, but also checks + that the length available to read is non-zero, thus hopefully fixes the + bug. +**/ +bool usb_poll_validate_length() +{ + + if (!usb_check()) return false; + if (!(pUdp->UDP_CSR[AT91C_EP_OUT] & btReceiveBank)) return false; + return (pUdp->UDP_CSR[AT91C_EP_OUT] >> 16) > 0; +} + //*---------------------------------------------------------------------------- //* \fn usb_read //* \brief Read available data from Endpoint OUT diff --git a/common/usb_cdc.h b/common/usb_cdc.h index 59e73a47..c42da8db 100644 --- a/common/usb_cdc.h +++ b/common/usb_cdc.h @@ -41,6 +41,7 @@ void usb_disable(); void usb_enable(); bool usb_check(); bool usb_poll(); +bool usb_poll_validate_length(); uint32_t usb_read(byte_t* data, size_t len); uint32_t usb_write(const byte_t* data, const size_t len);