]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlft55xx.c
lf viking build / lf awid refactor / lfdemod.c debugMode==2
[proxmark3-svn] / client / cmdlft55xx.c
index d3d78c22c612b0b6d844737a24b92bbcfd20ff64..0e8043a95e7915c57fffa99a763b817d15e5e9bf 100644 (file)
@@ -26,8 +26,9 @@
 #include "../common/iso14443crc.h"\r
 #include "cmdhf14a.h"\r
 \r
-#define CONFIGURATION_BLOCK 0x00\r
-#define TRACE_BLOCK 0x01\r
+#define T55x7_CONFIGURATION_BLOCK 0x00\r
+#define T55x7_PAGE0 0x00\r
+#define T55x7_PAGE1 0x01\r
 #define REGULAR_READ_MODE_BLOCK 0xFF\r
 \r
 // Default configuration\r
@@ -148,6 +149,12 @@ int usage_t55xx_wakup(){
 \r
 static int CmdHelp(const char *Cmd);\r
 \r
+void printT5xxHeader(uint8_t page){\r
+       PrintAndLog("Reading Page %d:", page);  \r
+       PrintAndLog("blk | hex data | binary");\r
+       PrintAndLog("----+----------+---------------------------------");       \r
+}\r
+\r
 int CmdT55xxSetConfig(const char *Cmd) {\r
 \r
        uint8_t offset = 0;\r
@@ -256,7 +263,7 @@ int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, bool override, uint32
        if ( usepwd ) {\r
                // try reading the config block and verify that PWD bit is set before doing this!\r
                if ( !override ) {\r
-                       if ( !AquireData(0, CONFIGURATION_BLOCK, false, 0 ) ) return 0;\r
+                       if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, false, 0 ) ) return 0;\r
                        if ( !tryDetectModulation() ) {\r
                                PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits.");\r
                                return 0;\r
@@ -324,8 +331,8 @@ int CmdT55xxReadBlock(const char *Cmd) {
                PrintAndLog("Block must be between 0 and 7");\r
                return 0;\r
        }\r
-       PrintAndLog("Reading Page %d:", page1); \r
-       PrintAndLog("blk | hex data | binary");\r
+\r
+       printT5xxHeader(page1);\r
        return T55xxReadBlock(block, page1, usepwd, override, password);\r
 }\r
 \r
@@ -387,14 +394,27 @@ bool DecodeT55xxBlock(){
 \r
 int CmdT55xxDetect(const char *Cmd){\r
 \r
+       uint32_t password = 0; //default to blank Block 7\r
+\r
        char cmdp = param_getchar(Cmd, 0);\r
-       if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H')\r
-               return usage_t55xx_detect();\r
+       if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') return usage_t55xx_detect();\r
+\r
+       bool usepwd = ( strlen(Cmd) > 0);       \r
+       if ( usepwd ){\r
+               password = param_get32ex(Cmd, 0, 0, 16);\r
+               // if (param_getchar(Cmd, 1) =='o' )\r
+                       // override = true;\r
+       }\r
+\r
        \r
-       if (strlen(Cmd)==0)\r
-               if ( !AquireData(0, CONFIGURATION_BLOCK, false, 0) )\r
-                       return 0;\r
+       if (strlen(Cmd)==1) {\r
+               password = param_get32ex(Cmd, 0, 0, 16);\r
+               //if (param_getchar(Cmd, 1) =='o' ) override = true;\r
+       }\r
 \r
+       if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password) )\r
+               return 0;\r
+               \r
        if ( !tryDetectModulation() )\r
                PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");\r
 \r
@@ -408,6 +428,7 @@ bool tryDetectModulation(){
        int bitRate=0;\r
        uint8_t fc1 = 0, fc2 = 0, clk=0;\r
        save_restoreGB(1);\r
+\r
        if (GetFskClock("", FALSE, FALSE)){ \r
                fskClocks(&fc1, &fc2, &clk, FALSE);\r
                if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
@@ -787,8 +808,8 @@ int CmdT55xxWakeUp(const char *Cmd) {
 \r
 int CmdT55xxWriteBlock(const char *Cmd) {\r
        uint8_t block = 0xFF; //default to invalid block\r
-       uint32_t data = 0xFFFFFFFF; //default to blank Block \r
-       uint32_t password = 0xFFFFFFFF; //default to blank Block 7\r
+       uint32_t data = 0; //default to blank Block \r
+       uint32_t password = 0; //default to blank Block 7\r
        bool usepwd = false;\r
        bool page1 = false;     \r
        bool gotdata = false;\r
@@ -837,13 +858,15 @@ int CmdT55xxWriteBlock(const char *Cmd) {
        UsbCommand resp;\r
        c.d.asBytes[0] = (page1) ? 0x2 : 0; \r
 \r
-       PrintAndLog("Writing to page: %d  block: %d  data : 0x%08X", page1, block, data);\r
+       char pwdStr[16] = {0};\r
+       snprintf(pwdStr, sizeof(pwdStr), "pwd: 0x%08X", password);\r
+\r
+       PrintAndLog("Writing page %d  block: %02d  data: 0x%08X %s", page1, block, data,  (usepwd) ? pwdStr : "" );\r
 \r
        //Password mode\r
        if (usepwd) {\r
                c.arg[2] = password;\r
                c.d.asBytes[0] |= 0x1; \r
-               PrintAndLog("pwd   : 0x%08X", password);\r
        }\r
        clearCommandBuffer();\r
        SendCommand(&c);\r
@@ -862,7 +885,7 @@ int CmdT55xxReadTrace(const char *Cmd) {
                return usage_t55xx_trace();\r
 \r
        if (strlen(Cmd)==0)\r
-               if ( !AquireData( TRACE_BLOCK, REGULAR_READ_MODE_BLOCK, pwdmode, password ) )\r
+               if ( !AquireData( T55x7_PAGE1, REGULAR_READ_MODE_BLOCK, pwdmode, password ) )\r
                        return 0;\r
        \r
        if (!DecodeT55xxBlock()) return 0;\r
@@ -951,7 +974,7 @@ int CmdT55xxInfo(const char *Cmd){
                return usage_t55xx_info();\r
        \r
        if (strlen(Cmd)==0)\r
-               if ( !AquireData( 0, CONFIGURATION_BLOCK, pwdmode, password ) )\r
+               if ( !AquireData( T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, pwdmode, password ) )\r
                        return 1;\r
 \r
        if (!DecodeT55xxBlock()) return 1;\r
@@ -1015,32 +1038,21 @@ int CmdT55xxDump(const char *Cmd){
                        override = true;\r
        }\r
        \r
-       PrintAndLog("Reading Page 0:"); \r
-       PrintAndLog("blk | hex data | binary");\r
-       for ( uint8_t i = 0; i <8; ++i){\r
+       printT5xxHeader(0);\r
+       for ( uint8_t i = 0; i <8; ++i)\r
                T55xxReadBlock(i, 0, usepwd, override, password);\r
-               /*memset(s,0,sizeof(s));\r
-               if ( hasPwd ) {\r
-                       if ( override ) {\r
-                               sprintf(s,"b %d p %02x%02x%02x%02x o", i, pwd[0],pwd[1],pwd[2],pwd[3]);                         \r
-                       } else {\r
-                               sprintf(s,"b %d p %02x%02x%02x%02x", i, pwd[0],pwd[1],pwd[2],pwd[3]);                           \r
-                       }\r
-               } else {\r
-                       sprintf(s,"b %d", i);\r
-               }\r
-               CmdT55xxReadBlock(s);*/\r
-       }\r
-       PrintAndLog("Reading Page 1:"); \r
-       PrintAndLog("blk | hex data | binary");\r
-       for ( uint8_t   i = 0; i<4; i++){\r
+\r
+       printT5xxHeader(1);\r
+       for ( uint8_t   i = 0; i<4; i++)\r
                T55xxReadBlock(i, 1, usepwd, override, password);               \r
-       }\r
+\r
        return 1;\r
 }\r
 \r
 int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){\r
-\r
+       // arg0 bitmodes:\r
+       // bit0 = pwdmode\r
+       // bit1 = page to read from\r
        uint8_t arg0 = (page<<1) | pwdmode;\r
        UsbCommand c = {CMD_T55XX_READ_BLOCK, {arg0, block, password}};\r
 \r
@@ -1251,33 +1263,34 @@ int CmdResetRead(const char *Cmd) {
 int CmdT55xxWipe(const char *Cmd) {\r
        char writeData[20] = {0};\r
        char *ptrData = writeData;\r
-       uint8_t blk = 0;\r
+\r
        PrintAndLog("\nBeginning Wipe of a T55xx tag (assuming the tag is not password protected)\n");\r
+\r
        //try with the default password to reset block 0  (with a pwd should work even if pwd bit not set)\r
-       snprintf(ptrData,sizeof(writeData),"b %d d 00088040 p 0", blk);\r
-       if (!CmdT55xxWriteBlock(ptrData)){\r
-               PrintAndLog("Error writing blk %d", blk);\r
-       }\r
-       blk = 1;\r
-       for (; blk<8; blk++) {\r
+       snprintf(ptrData,sizeof(writeData),"b 0 d 00088040 p 0");\r
+\r
+       if (!CmdT55xxWriteBlock(ptrData))\r
+               PrintAndLog("Error writing blk 0");\r
+\r
+       for (uint8_t blk = 1; blk<8; blk++) {\r
                snprintf(ptrData,sizeof(writeData),"b %d d 0", blk);\r
-               if (!CmdT55xxWriteBlock(ptrData)){\r
+               if (!CmdT55xxWriteBlock(ptrData))\r
                        PrintAndLog("Error writing blk %d", blk);\r
-               }\r
+\r
+               memset(writeData, sizeof(writeData), 0x00);\r
        }\r
        return 0;\r
 }\r
 \r
-static command_t CommandTable[] =\r
-{\r
+static command_t CommandTable[] = {\r
   {"help",     CmdHelp,           1, "This help"},\r
   {"config",   CmdT55xxSetConfig, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},\r
-  {"detect",   CmdT55xxDetect,    0, "[1] Try detecting the tag modulation from reading the configuration block."},\r
+  {"detect",   CmdT55xxDetect,    1, "[1] Try detecting the tag modulation from reading the configuration block."},\r
   {"read",     CmdT55xxReadBlock, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},\r
   {"resetread",CmdResetRead,      0, "Send Reset Cmd then lf read the stream to attempt to identify the start of it (needs a demod and/or plot after)"},\r
   {"write",    CmdT55xxWriteBlock,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"},\r
-  {"trace",    CmdT55xxReadTrace, 0, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"},\r
-  {"info",     CmdT55xxInfo,      0, "[1] Show T55x7 configuration data (page 0/ blk 0)"},\r
+  {"trace",    CmdT55xxReadTrace, 1, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"},\r
+  {"info",     CmdT55xxInfo,      1, "[1] Show T55x7 configuration data (page 0/ blk 0)"},\r
   {"dump",     CmdT55xxDump,      0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"},\r
   {"special",  special,           0, "Show block changes with 64 different offsets"},\r
   {"wakeup",   CmdT55xxWakeUp,    0, "Send AOR wakeup command"},\r
@@ -1285,14 +1298,12 @@ static command_t CommandTable[] =
   {NULL, NULL, 0, NULL}\r
 };\r
 \r
-int CmdLFT55XX(const char *Cmd)\r
-{\r
+int CmdLFT55XX(const char *Cmd) {\r
   CmdsParse(CommandTable, Cmd);\r
   return 0;\r
 }\r
 \r
-int CmdHelp(const char *Cmd)\r
-{\r
+int CmdHelp(const char *Cmd) {\r
   CmdsHelp(CommandTable);\r
   return 0;\r
 }\r
Impressum, Datenschutz