]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/prox.c
mifare usb update
[proxmark3-svn] / client / prox.c
index b284e0f7a3be7d28a1b197893f00471e333819fb..58704494f5b076352b1ef1b9b9a86acd52b2f93c 100644 (file)
@@ -17,6 +17,7 @@
 \r
 int offline = 0;\r
 HANDLE UsbHandle;\r
+extern unsigned int current_command;\r
 \r
 static void ShowError(void)\r
 {\r
@@ -188,7 +189,7 @@ void ReceiveCommand(UsbCommand *c)
        }\r
 }\r
 \r
-void SendCommand(UsbCommand *c, bool wantAck)\r
+void SendCommand(UsbCommand *c)\r
 {\r
        BYTE buf[65];\r
        buf[0] = 0;\r
@@ -212,14 +213,15 @@ void SendCommand(UsbCommand *c, bool wantAck)
                ShowError();\r
                exit(-1);\r
        }\r
+       current_command = c->cmd;\r
+}\r
 \r
-       if(wantAck) {\r
-               UsbCommand ack;\r
-               ReceiveCommand(&ack);\r
-               if(ack.cmd != CMD_ACK) {\r
-                       printf("bad ACK\n");\r
-                       exit(-1);\r
-               }\r
+void WaitForAck(void) {\r
+       UsbCommand ack;\r
+       ReceiveCommand(&ack);\r
+       if(ack.cmd != CMD_ACK) {\r
+               printf("bad ACK\n");\r
+               exit(-1);\r
        }\r
 }\r
 \r
@@ -255,7 +257,8 @@ static void FlushPrevious(int translate)
                c.cmd = CMD_SETUP_WRITE;\r
                memcpy(c.d.asBytes, QueuedToSend+i, 48);\r
                c.arg[0] = (i/4);\r
-               SendCommand(&c, TRUE);\r
+               SendCommand(&c);\r
+               WaitForAck();\r
        }\r
 \r
        c.cmd = CMD_FINISH_WRITE;\r
@@ -265,8 +268,9 @@ static void FlushPrevious(int translate)
        }\r
        printf("Flashing address: %08x\r", c.arg[0]);\r
        memcpy(c.d.asBytes, QueuedToSend+240, 16);\r
-       SendCommand(&c, TRUE);\r
-\r
+       SendCommand(&c);\r
+       WaitForAck();\r
+       \r
        AllWritten = TRUE;\r
 }\r
 \r
@@ -372,7 +376,8 @@ static int PrepareFlash(struct partition *p, const char *filename, unsigned int
                } else {\r
                        c.arg[2] = 0;\r
                }\r
-               SendCommand(&c, TRUE);\r
+               SendCommand(&c);\r
+               WaitForAck();\r
                translate = 0;\r
        } else {\r
                fprintf(stderr, "Warning: Your bootloader does not understand the new START_FLASH command\n");\r
@@ -390,7 +395,7 @@ static unsigned int GetProxmarkState(void)
 \r
        UsbCommand c;\r
        c.cmd = CMD_DEVICE_INFO;\r
-       SendCommand(&c, FALSE);\r
+       SendCommand(&c);\r
 \r
        UsbCommand resp;\r
        ReceiveCommand(&resp);\r
@@ -445,13 +450,13 @@ static unsigned int EnterFlashState(void)
                         * enter the bootrom on the next boot.\r
                         */\r
                        c.cmd = CMD_START_FLASH;\r
-                       SendCommand(&c, FALSE);\r
+                       SendCommand(&c);\r
                        fprintf(stderr,"(You don't have to do anything. Press and release the button only if you want to abort)\n");\r
                        fprintf(stderr,"Waiting for Proxmark to reappear on USB... ");\r
                } else {\r
                        /* Old style handover: Ask the user to press the button, then reset the board */\r
                        c.cmd = CMD_HARDWARE_RESET;\r
-                       SendCommand(&c, FALSE);\r
+                       SendCommand(&c);\r
                        fprintf(stderr,"(Press and hold down button NOW if your bootloader requires it)\n");\r
                        fprintf(stderr,"Waiting for Proxmark to reappear on USB... ");\r
                }\r
Impressum, Datenschutz