]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/usb.c
fix OS detection, libgcc detection
[proxmark3-svn] / client / usb.c
index c326aeca76327de4493bfc06795078e657f374cc..4f4bd2cadb53a2db9a3ba6f81fc4476b92b1d848 100644 (file)
@@ -1,25 +1,27 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <unistd.h>
 #include <usb.h>
 #include <strings.h>
 #include <errno.h>
 
-#include "translate.h"
 #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;
@@ -39,18 +41,22 @@ void SendCommand(UsbCommand *c, BOOL wantAck) {
                
                return;
        }
-
+/*
        if(wantAck) {
                UsbCommand ack;
+               printf("waiting for ack\n");
                ReceiveCommand(&ack);
                if(ack.cmd != CMD_ACK) {
                        printf("bad ACK\n");
                        exit(-1);
                }
+       } else {
+               printf("not waiting for ack\n");
        }
+*/
 }
 
-int ReceiveCommandP(UsbCommand *c) {
+bool ReceiveCommandPoll(UsbCommand *c) {
        int ret;
 
        bzero(c, sizeof(UsbCommand));
@@ -59,7 +65,7 @@ int ReceiveCommandP(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);
@@ -72,7 +78,7 @@ int ReceiveCommandP(UsbCommand *c) {
                        printf(PROXPROMPT);
                        fflush(NULL);
 
-                       return 0;
+                       return false;
                }
        } else {
                if (ret && (ret < sizeof(UsbCommand))) {
@@ -95,11 +101,17 @@ int ReceiveCommandP(UsbCommand *c) {
 #endif
        }
 
-       return ret;
+       return ret != 0;
 }
 
 void ReceiveCommand(UsbCommand *c) {
-       while(ReceiveCommandP(c)<0) {}
+//     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) {
Impressum, Datenschutz