]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlft55xx.c
include cmdlfviking.c in makefile and cmdlf
[proxmark3-svn] / client / cmdlft55xx.c
index 04931dfe80a90e0e70f1a11eeac5b1b18017c094..490850f86125c7bcd4e60eaaec070c39393226db 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
@@ -124,13 +125,15 @@ int usage_t55xx_dump(){
        return 0;\r
 }\r
 int usage_t55xx_detect(){\r
-       PrintAndLog("Usage:  lf t55xx detect [1]");\r
+       PrintAndLog("Usage:  lf t55xx detect [1] [p <password>]");\r
        PrintAndLog("Options:");\r
-       PrintAndLog("     [graph buffer data]  - if set, use Graphbuffer otherwise read data from tag.");\r
+       PrintAndLog("     1             - if set, use Graphbuffer otherwise read data from tag.");\r
+       PrintAndLog("     p <password>  - OPTIONAL password (8 hex characters)");\r
        PrintAndLog("");\r
        PrintAndLog("Examples:");\r
        PrintAndLog("      lf t55xx detect");\r
        PrintAndLog("      lf t55xx detect 1");\r
+       PrintAndLog("      lf t55xx detect p 11223344");\r
        PrintAndLog("");\r
        return 0;\r
 }\r
@@ -148,6 +151,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 +265,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 +333,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
@@ -386,15 +395,41 @@ bool DecodeT55xxBlock(){
 }\r
 \r
 int CmdT55xxDetect(const char *Cmd){\r
+       bool errors = FALSE;\r
+       bool useGB = FALSE;\r
+       bool usepwd = FALSE;\r
+       uint32_t password = 0;\r
+       uint8_t cmdp = 0;\r
 \r
-       char cmdp = param_getchar(Cmd, 0);\r
-       if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H')\r
-               return usage_t55xx_detect();\r
+       while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r
+               switch(param_getchar(Cmd, cmdp)) {\r
+               case 'h':\r
+               case 'H':\r
+                       return usage_t55xx_detect();\r
+               case 'p':\r
+               case 'P':\r
+                       password = param_get32ex(Cmd, cmdp+1, 0, 16);\r
+                       usepwd = TRUE;\r
+                       cmdp += 2;\r
+                       break;\r
+               case '1':\r
+                       // use Graphbuffer data\r
+                       useGB = TRUE;\r
+                       cmdp++;\r
+                       break;\r
+               default:\r
+                       PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
+                       errors = true;\r
+                       break;\r
+               }\r
+       }\r
+       if (errors) return usage_t55xx_detect();\r
        \r
-       if (strlen(Cmd)==0)\r
-               if ( !AquireData(0, CONFIGURATION_BLOCK, false, 0) )\r
+       if ( !useGB) {\r
+               if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password) )\r
                        return 0;\r
-\r
+       }\r
+       \r
        if ( !tryDetectModulation() )\r
                PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");\r
 \r
@@ -408,6 +443,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
@@ -529,7 +565,8 @@ bool tryDetectModulation(){
                                }\r
                        } // inverse waves does not affect this demod\r
                }\r
-       }               \r
+       }       \r
+       save_restoreGB(0);      \r
        if ( hits == 1) {\r
                config.modulation = tests[0].modulation;\r
                config.bitrate = tests[0].bitrate;\r
@@ -718,7 +755,7 @@ void printT55xxBlock(const char *blockNum){
 \r
        for (; i < endpos; ++i)\r
                bits[i - config.offset]=DemodBuffer[i];\r
-       //print second round of read data (more accurate due to antenna settling)\r
+\r
        blockData = PackBits(0, 32, bits);\r
 \r
        PrintAndLog("  %s | %08X | %s", blockNum, blockData, sprint_bin(bits,32));\r
@@ -786,8 +823,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
@@ -836,13 +873,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
@@ -861,7 +900,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
@@ -950,7 +989,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
@@ -1014,32 +1053,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
@@ -1250,33 +1278,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
@@ -1284,14 +1313,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