]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
Change in progress, the adjustments to use Marshmellow's new demod for T55XX commands.
authoriceman1001 <iceman@iuse.se>
Fri, 30 Jan 2015 14:45:56 +0000 (15:45 +0100)
committericeman1001 <iceman@iuse.se>
Fri, 30 Jan 2015 14:45:56 +0000 (15:45 +0100)
client/cmdlft55xx.c

index 1e2f7837ac81248c3842b606b9a3699f62b93e53..f35edaa4669fe23e9c2257bbb145ebf79fa7929a 100644 (file)
 #include "cmdlft55xx.h"\r
 #include "util.h"\r
 #include "data.h"\r
+#include "lfdemod.h"\r
 \r
 \r
 #define LF_TRACE_BUFF_SIZE 20000 // 32 x 32 x 10  (32 bit times numofblock (7), times clock skip..)\r
 #define LF_BITSSTREAM_LEN 1000 // more then 1000 bits shouldn't happend..  8block * 4 bytes * 8bits = \r
 static int CmdHelp(const char *Cmd);\r
 \r
+// int CmdReadBlk(const char *Cmd)\r
+// {\r
+       // int block = -1;\r
+       // sscanf(Cmd, "%d", &block);\r
+\r
+       // if ((block > 7) | (block < 0)) {\r
+               // PrintAndLog("Block must be between 0 and 7");\r
+               // return 1;\r
+       // }    \r
+\r
+       // UsbCommand c;\r
+       // c.cmd = CMD_T55XX_READ_BLOCK;\r
+       // c.d.asBytes[0] = 0x00;\r
+       // c.arg[0] = 0;\r
+       // c.arg[1] = block;\r
+       // c.arg[2] = 0;\r
+       // SendCommand(&c);\r
+       // WaitForResponse(CMD_ACK, NULL);\r
+       \r
+       // uint8_t data[LF_TRACE_BUFF_SIZE] = {0x00};\r
+       \r
+       // GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,0);  //3560 -- should be offset..\r
+       // WaitForResponseTimeout(CMD_ACK,NULL, 1500);\r
+\r
+       // for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {\r
+               // GraphBuffer[j] = (int)data[j];\r
+       // }\r
+       // GraphTraceLen = LF_TRACE_BUFF_SIZE;\r
+       // ManchesterDemod(block);\r
+       // RepaintGraphWindow();\r
+  // return 0;\r
+// }\r
+\r
 int CmdReadBlk(const char *Cmd)\r
 {\r
+       int invert = 0;\r
+       int clk = 0;\r
        int block = -1;\r
-       sscanf(Cmd, "%d", &block);\r
+       uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0x00};\r
 \r
+       sscanf(Cmd, "%d", &block);\r
+       \r
        if ((block > 7) | (block < 0)) {\r
                PrintAndLog("Block must be between 0 and 7");\r
                return 1;\r
-       }       \r
+       }\r
 \r
-       UsbCommand c;\r
-       c.cmd = CMD_T55XX_READ_BLOCK;\r
-       c.d.asBytes[0] = 0x00;\r
-       c.arg[0] = 0;\r
-       c.arg[1] = block;\r
-       c.arg[2] = 0;\r
+       UsbCommand c = { CMD_T55XX_READ_BLOCK, { 0, block, 0 } };\r
        SendCommand(&c);\r
-       WaitForResponse(CMD_ACK, NULL);\r
-       \r
-       uint8_t data[LF_TRACE_BUFF_SIZE] = {0x00};\r
+       if ( !WaitForResponseTimeout(CMD_ACK,NULL,1500) ) {\r
+               PrintAndLog("command execution time out");\r
+               return 1;\r
+       }\r
        \r
-       GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,0);  //3560 -- should be offset..\r
-       WaitForResponseTimeout(CMD_ACK,NULL, 1500);\r
+       CmdSamples("");\r
 \r
-       for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {\r
-               GraphBuffer[j] = (int)data[j];\r
+       size_t bitlen = getFromGraphBuf(bits);\r
+       \r
+       int errCnt = askrawdemod(bits, &bitlen, &clk, &invert);\r
+       \r
+       //throw away static - allow 1 and -1 (in case of threshold command first)\r
+       if ( errCnt == -1 || bitlen < 16 ){  \r
+               PrintAndLog("no data found");\r
+               if (g_debugMode) \r
+                       PrintAndLog("errCnt: %d, bitlen: %d, clk: %d, invert: %d", errCnt, bitlen, clk, invert);\r
+               return 0;\r
        }\r
-       GraphTraceLen = LF_TRACE_BUFF_SIZE;\r
-       ManchesterDemod(block);\r
-       RepaintGraphWindow();\r
-  return 0;\r
+       if (g_debugMode) \r
+               PrintAndLog("Using Clock: %d - invert: %d - Bits Found: %d", clk, invert, bitlen);\r
+\r
+       //move bits back to DemodBuffer\r
+       setDemodBuf(bits, bitlen, 0);\r
+       printBitStream(bits,bitlen);\r
+       return 0;\r
 }\r
 \r
 int CmdReadBlkPWD(const char *Cmd)\r
 {\r
        int Block = -1; //default to invalid block\r
        int Password = 0xFFFFFFFF; //default to blank Block 7\r
-       UsbCommand c;\r
+\r
 \r
        sscanf(Cmd, "%d %x", &Block, &Password);\r
 \r
@@ -74,17 +118,14 @@ int CmdReadBlkPWD(const char *Cmd)
 \r
        PrintAndLog("Reading page 0 block %d pwd %08X", Block, Password);\r
 \r
-       c.cmd = CMD_T55XX_READ_BLOCK;\r
+       UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, Block, Password} };\r
        c.d.asBytes[0] = 0x1; //Password mode\r
-       c.arg[0] = 0;\r
-       c.arg[1] = Block;\r
-       c.arg[2] = Password;\r
        SendCommand(&c);\r
        WaitForResponse(CMD_ACK, NULL);\r
                \r
        uint8_t data[LF_TRACE_BUFF_SIZE] = {0x00};\r
 \r
-       GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,0);  //3560 -- should be offset..\r
+       GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,0);\r
        WaitForResponseTimeout(CMD_ACK,NULL, 1500);\r
 \r
        for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {\r
@@ -92,6 +133,7 @@ int CmdReadBlkPWD(const char *Cmd)
        }\r
        GraphTraceLen = LF_TRACE_BUFF_SIZE;\r
        ManchesterDemod(Block); \r
+\r
        RepaintGraphWindow();\r
   return 0;\r
 }\r
@@ -100,22 +142,18 @@ int CmdWriteBlk(const char *Cmd)
 {\r
   int Block = 8; //default to invalid block\r
   int Data = 0xFFFFFFFF; //default to blank Block \r
-  UsbCommand c;\r
 \r
-  sscanf(Cmd, "%x %d", &Data, &Block);\r
+       sscanf(Cmd, "%d %x", &Block, &Data);\r
 \r
   if (Block > 7) {\r
        PrintAndLog("Block must be between 0 and 7");\r
        return 1;\r
   }    \r
 \r
-  PrintAndLog("Writting block %d with data %08X", Block, Data);\r
+       PrintAndLog("Writing block %d  data %08X", Block, Data);\r
 \r
-  c.cmd = CMD_T55XX_WRITE_BLOCK;\r
+       UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {Data, Block, 0}};\r
   c.d.asBytes[0] = 0x0; //Normal mode\r
-  c.arg[0] = Data;\r
-  c.arg[1] = Block;\r
-  c.arg[2] = 0;\r
   SendCommand(&c);\r
   return 0;\r
 }\r
@@ -125,22 +163,19 @@ int CmdWriteBlkPWD(const char *Cmd)
   int Block = 8; //default to invalid block\r
   int Data = 0xFFFFFFFF; //default to blank Block \r
   int Password = 0xFFFFFFFF; //default to blank Block 7\r
-  UsbCommand c;\r
 \r
-  sscanf(Cmd, "%x %d %x", &Data, &Block, &Password);\r
+\r
+       sscanf(Cmd, "%d %x %x",&Block, &Data, &Password);\r
 \r
   if (Block > 7) {\r
        PrintAndLog("Block must be between 0 and 7");\r
        return 1;\r
   }    \r
 \r
-  PrintAndLog("Writting block %d with data %08X and password %08X", Block, Data, Password);\r
+       PrintAndLog("Writing block %d  data %08X  password %08X", Block, Data, Password);\r
 \r
-  c.cmd = CMD_T55XX_WRITE_BLOCK;\r
+       UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {Data, Block, Password}};\r
   c.d.asBytes[0] = 0x1; //Password mode\r
-  c.arg[0] = Data;\r
-  c.arg[1] = Block;\r
-  c.arg[2] = Password;\r
   SendCommand(&c);\r
   return 0;\r
 }\r
@@ -154,11 +189,12 @@ int CmdReadTrace(const char *Cmd)
                PrintAndLog("     [use data from Graphbuffer], if not set, try reading data from tag.");\r
                PrintAndLog("");\r
                PrintAndLog("     sample: lf t55xx trace");\r
-               PrintAndLog("     sample: lf t55xx trace 1");\r
+               PrintAndLog("           : lf t55xx trace 1");\r
                return 0;\r
        }\r
 \r
        if ( strlen(Cmd)==0){\r
+       \r
                UsbCommand c = {CMD_T55XX_READ_TRACE, {0, 0, 0}};\r
                SendCommand(&c);\r
                WaitForResponse(CMD_ACK, NULL);\r
@@ -315,7 +351,7 @@ int CmdDump(const char *Cmd){
        if ( hasPwd ){\r
                if (param_gethex(Cmd, 0, pwd, 8)) {\r
                        PrintAndLog("password must include 8 HEX symbols");\r
-                       return 0;\r
+                       return 1;\r
                }\r
        }\r
        \r
@@ -483,8 +519,8 @@ static command_t CommandTable[] =
   {"help",   CmdHelp,        1, "This help"},\r
   {"rd",     CmdReadBlk,     0, "<block> -- Read T55xx block data (page 0)"},\r
   {"rdpwd",  CmdReadBlkPWD,  0, "<block> <password> -- Read T55xx block data with password mode"},\r
-  {"wr",     CmdWriteBlk,    0, "<data> <block> -- Write T55xx block data (page 0)"},\r
-  {"wrpwd",  CmdWriteBlkPWD, 0, "<data> <block> <password> -- Write T55xx block data with password"},\r
+  {"wr",     CmdWriteBlk,    0, "<block> <data> -- Write T55xx block data (page 0)"},\r
+  {"wrpwd",  CmdWriteBlkPWD, 0, "<block> <password> <data> -- Write T55xx block data with password"},\r
   {"trace",  CmdReadTrace,   0, "[1] Read T55xx traceability data (page 1/ blk 0-1)"},\r
   {"info",   CmdInfo,        0, "[1] Read T55xx configuration data (page 0/ blk 0)"},\r
   {"dump",   CmdDump,        0, "[password] Dump T55xx card block 0-7. optional with password"},\r
Impressum, Datenschutz