]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/flasher.c
mifare client update
[proxmark3-svn] / client / flasher.c
index e3043fa33363ea2bf6d01846111d0d5f4177db6c..ebcd3391880e0323750a3e584535854c5a13e5d7 100644 (file)
@@ -2,19 +2,30 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
 #include <strings.h>
 #include <string.h>
 #include <errno.h>
 #include <ctype.h>
 
 #include <strings.h>
 #include <string.h>
 #include <errno.h>
 #include <ctype.h>
 
-#include "translate.h"
 #include "prox.h"
 #include "proxmark3.h"
 
 #include "prox.h"
 #include "proxmark3.h"
 
-static DWORD ExpectedAddr;
-static BYTE QueuedToSend[256];
-static BOOL AllWritten;
+static uint32_t ExpectedAddr;
+static uint8_t QueuedToSend[256];
+static bool AllWritten;
 #define PHYSICAL_FLASH_START 0x100000
 #define PHYSICAL_FLASH_START 0x100000
+unsigned int current_command = CMD_UNKNOWN;
+
+void WaitForAck(void) {
+       UsbCommand ack;
+       ReceiveCommand(&ack);
+       if(ack.cmd != CMD_ACK) {
+               printf("bad ACK\n");
+               exit(-1);
+       }
+}
 
 struct partition {
        int start;
 
 struct partition {
        int start;
@@ -42,27 +53,29 @@ static void FlushPrevious(int translate)
        for(i = 0; i < 240; i += 48) {
                c.cmd = CMD_SETUP_WRITE;
                memcpy(c.d.asBytes, QueuedToSend+i, 48);
        for(i = 0; i < 240; i += 48) {
                c.cmd = CMD_SETUP_WRITE;
                memcpy(c.d.asBytes, QueuedToSend+i, 48);
-               c.ext1 = (i/4);
-               SendCommand(&c, TRUE);
+               c.arg[0] = (i/4);
+               SendCommand(&c);
+               WaitForAck();
        }
 
        c.cmd = CMD_FINISH_WRITE;
        }
 
        c.cmd = CMD_FINISH_WRITE;
-       c.ext1 = (ExpectedAddr-1) & (~255);
+       c.arg[0] = (ExpectedAddr-1) & (~255);
        if(translate) {
        if(translate) {
-               c.ext1 -= PHYSICAL_FLASH_START;
+               c.arg[0] -= PHYSICAL_FLASH_START;
        }
        }
-       printf("c.ext1 = %08x\r", c.ext1);
+       printf("c.arg[0] = %08x\r", c.arg[0]);
        memcpy(c.d.asBytes, QueuedToSend+240, 16);
        memcpy(c.d.asBytes, QueuedToSend+240, 16);
-       SendCommand(&c, TRUE);
+       SendCommand(&c);
+       WaitForAck();
 
 
-       AllWritten = TRUE;
+       AllWritten = true;
 }
 
 /* Where must be between start_addr (inclusive) and end_addr (exclusive).
  */
 }
 
 /* Where must be between start_addr (inclusive) and end_addr (exclusive).
  */
-static void GotByte(DWORD where, BYTE which, int start_addr, int end_addr, int translate)
+static void GotByte(uint32_t where, uint8_t which, int start_addr, int end_addr, int translate)
 {
 {
-       AllWritten = FALSE;
+       AllWritten = false;
        
        if(where < start_addr || where >= end_addr) {
                printf("bad: got byte at %08x, outside of range %08x-%08x\n", where, start_addr, end_addr);
        
        if(where < start_addr || where >= end_addr) {
                printf("bad: got byte at %08x, outside of range %08x-%08x\n", where, start_addr, end_addr);
@@ -95,7 +108,7 @@ static int HexVal(int c)
        }
 }
 
        }
 }
 
-static BYTE HexByte(char *s)
+static uint8_t HexByte(char *s)
 {
        return (HexVal(s[0]) << 4) | HexVal(s[1]);
 }
 {
        return (HexVal(s[0]) << 4) | HexVal(s[1]);
 }
@@ -120,7 +133,7 @@ static void LoadFlashFromSRecords(const char *file, int start_addr, int end_addr
                        char addrStr[9];
                        memcpy(addrStr, s, 8);
                        addrStr[8] = '\0';
                        char addrStr[9];
                        memcpy(addrStr, s, 8);
                        addrStr[8] = '\0';
-                       DWORD addr;
+                       uint32_t addr;
                        sscanf(addrStr, "%x", &addr);
                        s += 8;
                        
                        sscanf(addrStr, "%x", &addr);
                        s += 8;
                        
@@ -151,16 +164,17 @@ static int PrepareFlash(struct partition *p, const char *filename, unsigned int
        if(state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) {
                UsbCommand c;
                c.cmd = CMD_START_FLASH;
        if(state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) {
                UsbCommand c;
                c.cmd = CMD_START_FLASH;
-               c.ext1 = p->start;
-               c.ext2 = p->end;
+               c.arg[0] = p->start;
+               c.arg[1] = p->end;
                
                /* Only send magic when flashing bootrom */
                if(p->precious) {
                
                /* Only send magic when flashing bootrom */
                if(p->precious) {
-                       c.ext3 = START_FLASH_MAGIC;
+                       c.arg[2] = START_FLASH_MAGIC;
                } else {
                } else {
-                       c.ext3 = 0;
+                       c.arg[2] = 0;
                }
                }
-               SendCommand(&c, TRUE);
+               SendCommand(&c);
+               WaitForAck();
                translate = 0;
        } else {
                fprintf(stderr, "Warning: Your bootloader does not understand the new START_FLASH command\n");
                translate = 0;
        } else {
                fprintf(stderr, "Warning: Your bootloader does not understand the new START_FLASH command\n");
@@ -178,7 +192,7 @@ static unsigned int GetProxmarkState(void)
        
        UsbCommand c;
        c.cmd = CMD_DEVICE_INFO;
        
        UsbCommand c;
        c.cmd = CMD_DEVICE_INFO;
-       SendCommand(&c, FALSE);
+       SendCommand(&c);
        
        UsbCommand resp;
        ReceiveCommand(&resp);
        
        UsbCommand resp;
        ReceiveCommand(&resp);
@@ -196,7 +210,7 @@ static unsigned int GetProxmarkState(void)
                state = DEVICE_INFO_FLAG_CURRENT_MODE_OS;
                break;
        case CMD_DEVICE_INFO:
                state = DEVICE_INFO_FLAG_CURRENT_MODE_OS;
                break;
        case CMD_DEVICE_INFO:
-               state = resp.ext1;
+               state = resp.arg[0];
                break;
        default:
                fprintf(stderr, "Couldn't get proxmark state, bad response type: 0x%04X\n", resp.cmd);
                break;
        default:
                fprintf(stderr, "Couldn't get proxmark state, bad response type: 0x%04X\n", resp.cmd);
@@ -233,13 +247,13 @@ static unsigned int EnterFlashState(void)
                         * enter the bootrom on the next boot.
                         */
                        c.cmd = CMD_START_FLASH;
                         * enter the bootrom on the next boot.
                         */
                        c.cmd = CMD_START_FLASH;
-                       SendCommand(&c, FALSE);
+                       SendCommand(&c);
                        fprintf(stderr,"(You don't have to do anything. Press and release the button only if you want to abort)\n");
                        fprintf(stderr,"Waiting for Proxmark to reappear on USB... ");
                } else {
                        /* Old style handover: Ask the user to press the button, then reset the board */
                        c.cmd = CMD_HARDWARE_RESET;
                        fprintf(stderr,"(You don't have to do anything. Press and release the button only if you want to abort)\n");
                        fprintf(stderr,"Waiting for Proxmark to reappear on USB... ");
                } else {
                        /* Old style handover: Ask the user to press the button, then reset the board */
                        c.cmd = CMD_HARDWARE_RESET;
-                       SendCommand(&c, FALSE);
+                       SendCommand(&c);
                        fprintf(stderr,"(Press and hold down button NOW if your bootloader requires it)\n");
                        fprintf(stderr,"Waiting for Proxmark to reappear on USB... ");
                }
                        fprintf(stderr,"(Press and hold down button NOW if your bootloader requires it)\n");
                        fprintf(stderr,"Waiting for Proxmark to reappear on USB... ");
                }
@@ -345,7 +359,7 @@ int main(int argc, char **argv) {
        UsbCommand c;
        bzero(&c, sizeof(c));
        c.cmd = CMD_HARDWARE_RESET;
        UsbCommand c;
        bzero(&c, sizeof(c));
        c.cmd = CMD_HARDWARE_RESET;
-       SendCommand(&c, FALSE);
+       SendCommand(&c);
 
        CloseProxmark();
 
 
        CloseProxmark();
 
Impressum, Datenschutz