X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/aa81a8d3f11255c86b1de9e77c65ce700fb3a79e..107ec6e4b5d76a62533cce020f139c20e1eda59e:/client/usb.c?ds=sidebyside diff --git a/client/usb.c b/client/usb.c index e7573fea..e0836b82 100644 --- a/client/usb.c +++ b/client/usb.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -9,18 +8,20 @@ #include "prox.h" #include "proxmark3.h" - +#include "../include/usb_cmd.h" usb_dev_handle *devh = NULL; static unsigned int claimed_iface = 0; unsigned char return_on_error = 0; unsigned char error_occured = 0; +extern unsigned int current_command; -void SendCommand(UsbCommand *c, bool wantAck) { +void SendCommand(UsbCommand *c) { int ret; #if 0 printf("Sending %d bytes\n", sizeof(UsbCommand)); #endif + current_command = c->cmd; ret = usb_bulk_write(devh, 0x01, (char*)c, sizeof(UsbCommand), 1000); if (ret<0) { error_occured = 1; @@ -40,15 +41,6 @@ void SendCommand(UsbCommand *c, bool wantAck) { return; } - - if(wantAck) { - UsbCommand ack; - ReceiveCommand(&ack); - if(ack.cmd != CMD_ACK) { - printf("bad ACK\n"); - exit(-1); - } - } } bool ReceiveCommandPoll(UsbCommand *c) { @@ -60,7 +52,7 @@ bool ReceiveCommandPoll(UsbCommand *c) { if (ret != -ETIMEDOUT) { error_occured = 1; if (return_on_error) - return 0; + return false; fprintf(stderr, "read failed: %s(%d)!\nTrying to reopen device...\n", usb_strerror(), ret); @@ -73,34 +65,26 @@ bool ReceiveCommandPoll(UsbCommand *c) { printf(PROXPROMPT); fflush(NULL); - return 0; + return false; } } else { if (ret && (ret < sizeof(UsbCommand))) { fprintf(stderr, "Read only %d instead of requested %d bytes!\n", ret, (int)sizeof(UsbCommand)); } - -#if 0 - { - int i; - - printf("Read %d bytes\n", ret); - for (i = 0; i < ret; i++) { - printf("0x%02X ", ((unsigned char*)c)[i]); - if (!((i+1)%8)) - printf("\n"); - } - printf("\n"); - } -#endif } return ret > 0; } void ReceiveCommand(UsbCommand *c) { - while(!ReceiveCommandPoll(c)) {} +// printf("%s()\n", __FUNCTION__); + int retval = 0; + do { + retval = ReceiveCommandPoll(c); + if (retval != 1) printf("ReceiveCommandPoll returned %d\n", retval); + } while(retval<0); +// printf("recv %x\n", c->cmd); } usb_dev_handle* findProxmark(int verbose, unsigned int *iface) {