X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/902cb3c00b49535f0de9a3b6d5ba0c54260ccac1..125a98a1102cc27cefeba77f6d37542c1c475c52:/client/cmdmain.c diff --git a/client/cmdmain.c b/client/cmdmain.c index edff9f8e..a9a37ad1 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -23,6 +23,7 @@ #include "cmdhw.h" #include "cmdlf.h" #include "cmdmain.h" +#include "util.h" unsigned int current_command = CMD_UNKNOWN; unsigned int received_command = CMD_UNKNOWN; @@ -59,9 +60,9 @@ int CmdQuit(const char *Cmd) bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout) { // Wait until the command is received - for(size_t i=0; received_command != cmd && i < ms_timeout; i++) { - msleep(1); // XXX ugh - if (i == 2000) { + for(size_t i=0; received_command != cmd && i < ms_timeout/10; i++) { + msleep(10); // XXX ugh + if (i == 200) { // Two seconds elapsed PrintAndLog("Waiting for a response from the proxmark..."); PrintAndLog("Don't forget to cancel its operation first by pressing on the button"); } @@ -99,17 +100,25 @@ void CommandReceived(char *Cmd) { //----------------------------------------------------------------------------- void UsbCommandReceived(UsbCommand *UC) { + /* + // Debug + printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand)); + printf(" cmd[len=%zd]: %"llx"\n",sizeof(UC->cmd),UC->cmd); + printf(" arg0[len=%zd]: %"llx"\n",sizeof(UC->arg[0]),UC->arg[0]); + printf(" arg1[len=%zd]: %"llx"\n",sizeof(UC->arg[1]),UC->arg[1]); + printf(" arg2[len=%zd]: %"llx"\n",sizeof(UC->arg[2]),UC->arg[2]); + printf(" data[len=%zd]: %02x%02x%02x...\n",sizeof(UC->d.asBytes),UC->d.asBytes[0],UC->d.asBytes[1],UC->d.asBytes[2]); + */ + // printf("%s(%x) current cmd = %x\n", __FUNCTION__, c->cmd, current_command); - /* If we recognize a response, return to avoid further processing */ + // If we recognize a response, return to avoid further processing switch(UC->cmd) { - // First check if we are handling a debug message + // First check if we are handling a debug message case CMD_DEBUG_PRINT_STRING: { - char s[100]; - if(UC->arg[0] > 70 || UC->arg[0] < 0) { - UC->arg[0] = 0; - } - memcpy(s, UC->d.asBytes, UC->arg[0]); - s[UC->arg[0]] = '\0'; + char s[USB_CMD_DATA_SIZE+1]; + size_t len = MIN(UC->arg[0],USB_CMD_DATA_SIZE); + memcpy(s,UC->d.asBytes,len); + s[len] = 0x00; PrintAndLog("#db# %s ", s); return; } break;