Merge pull request #131 from holiman/master

Fixes to PR #129
This commit is contained in:
Martin Holst Swende 2015-07-20 23:22:53 +02:00
commit 1adb2023ce
7 changed files with 214 additions and 194 deletions

View file

@ -667,6 +667,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
break; break;
case CMD_T55XX_WRITE_BLOCK: case CMD_T55XX_WRITE_BLOCK:
T55xxWriteBlock(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes[0]); T55xxWriteBlock(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes[0]);
cmd_send(CMD_ACK,0,0,0,0,0);
break; break;
case CMD_T55XX_READ_TRACE: case CMD_T55XX_READ_TRACE:
T55xxReadTrace(); T55xxReadTrace();

View file

@ -399,14 +399,10 @@ void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
#define OPEN_COIL() HIGH(GPIO_SSC_DOUT) #define OPEN_COIL() HIGH(GPIO_SSC_DOUT)
i = 0; i = 0;
byte_t rx[sizeof(UsbCommand)]; // Storage for usb_read call in loop
for(;;) { for(;;) {
//wait until SSC_CLK goes HIGH //wait until SSC_CLK goes HIGH
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) { while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) {
// Craig Young - Adding a usb_read() here to avoid abort on empty UsbCommand if(BUTTON_PRESS() || (usb_poll_validate_length() )) {
// 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)))) {
DbpString("Stopped"); DbpString("Stopped");
return; return;
} }

View file

@ -406,16 +406,10 @@ int CmdVersion(const char *Cmd)
{ {
UsbCommand c = {CMD_VERSION}; UsbCommand c = {CMD_VERSION};
static UsbCommand resp = {0, {0, 0, 0}}; UsbCommand resp = {0, {0, 0, 0}};
if (resp.arg[0] == 0 && resp.arg[1] == 0) { // no cached information available
SendCommand(&c); SendCommand(&c);
if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && Cmd != NULL) { if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
PrintAndLog("Prox/RFID mark3 RFID instrument");
PrintAndLog((char*)resp.d.asBytes);
lookupChipID(resp.arg[0], resp.arg[1]);
}
} else if (Cmd != NULL) {
PrintAndLog("Prox/RFID mark3 RFID instrument"); PrintAndLog("Prox/RFID mark3 RFID instrument");
PrintAndLog((char*)resp.d.asBytes); PrintAndLog((char*)resp.d.asBytes);
lookupChipID(resp.arg[0], resp.arg[1]); lookupChipID(resp.arg[0], resp.arg[1]);

View file

@ -16,7 +16,7 @@
#include "cmdparser.h" // CmdsParse, CmdsHelp #include "cmdparser.h" // CmdsParse, CmdsHelp
#include "cmdlfawid.h" // AWID function declarations #include "cmdlfawid.h" // AWID function declarations
#include "lfdemod.h" // parityTest #include "lfdemod.h" // parityTest
#include "cmdmain.h"
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
@ -176,8 +176,7 @@ int CmdAWIDClone(const char *Cmd)
uint32_t fc=0,cn=0,blocks[4] = {0x00107060, 0, 0, 0x11111111}, i=0; uint32_t fc=0,cn=0,blocks[4] = {0x00107060, 0, 0, 0x11111111}, i=0;
uint8_t BitStream[12]; uint8_t BitStream[12];
uint8_t *BS=BitStream; uint8_t *BS=BitStream;
UsbCommand c; UsbCommand c, resp;
if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) { if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) {
return usage_lf_awid_clone(); return usage_lf_awid_clone();
@ -206,6 +205,11 @@ int CmdAWIDClone(const char *Cmd)
c.arg[1] = i; c.arg[1] = i;
c.arg[2] = 0; c.arg[2] = 0;
SendCommand(&c); SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
PrintAndLog("Error occurred, device did not respond during write operation.");
return -1;
}
} }
} }
return 0; return 0;

View file

@ -242,6 +242,7 @@ int CmdT55xxReadBlock(const char *Cmd) {
c.d.asBytes[0] = 0x1; c.d.asBytes[0] = 0x1;
} }
clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) { if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
PrintAndLog("command execution time out"); PrintAndLog("command execution time out");
@ -670,6 +671,7 @@ int CmdT55xxWriteBlock(const char *Cmd)
} }
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}}; UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};
UsbCommand resp;
c.d.asBytes[0] = 0x0; c.d.asBytes[0] = 0x0;
PrintAndLog("Writing to block: %d data : 0x%08X", block, data); PrintAndLog("Writing to block: %d data : 0x%08X", block, data);
@ -680,7 +682,12 @@ int CmdT55xxWriteBlock(const char *Cmd)
c.d.asBytes[0] = 0x1; c.d.asBytes[0] = 0x1;
PrintAndLog("pwd : 0x%08X", password); PrintAndLog("pwd : 0x%08X", password);
} }
clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)");
return -1;
}
return 0; return 0;
} }
@ -878,6 +885,7 @@ int AquireData( uint8_t block ){
// c.d.asBytes[0] = 0x1; // c.d.asBytes[0] = 0x1;
// } // }
clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) { if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
PrintAndLog("command execution time out"); PrintAndLog("command execution time out");

View file

@ -293,6 +293,22 @@ bool usb_poll()
return (pUdp->UDP_CSR[AT91C_EP_OUT] & btReceiveBank); 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 //* \fn usb_read
//* \brief Read available data from Endpoint OUT //* \brief Read available data from Endpoint OUT

View file

@ -41,6 +41,7 @@ void usb_disable();
void usb_enable(); void usb_enable();
bool usb_check(); bool usb_check();
bool usb_poll(); bool usb_poll();
bool usb_poll_validate_length();
uint32_t usb_read(byte_t* data, size_t len); uint32_t usb_read(byte_t* data, size_t len);
uint32_t usb_write(const byte_t* data, const size_t len); uint32_t usb_write(const byte_t* data, const size_t len);