]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlft55xx.c
lf t55xx and some lf demod fixes/adjustments
[proxmark3-svn] / client / cmdlft55xx.c
index 37f332be5a198984c9ad49db1d3e982572662c9a..04931dfe80a90e0e70f1a11eeac5b1b18017c094 100644 (file)
@@ -353,16 +353,20 @@ bool DecodeT55xxBlock(){
                        ans = FSKrawDemod(cmdStr, FALSE);\r
                        break;\r
                case DEMOD_ASK:\r
                        ans = FSKrawDemod(cmdStr, FALSE);\r
                        break;\r
                case DEMOD_ASK:\r
-                       snprintf(cmdStr, sizeof(buf),"%d %d 0", bitRate[config.bitrate], config.inverted );\r
+                       snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
                        ans = ASKDemod(cmdStr, FALSE, FALSE, 1);\r
                        break;\r
                case DEMOD_PSK1:\r
                        ans = ASKDemod(cmdStr, FALSE, FALSE, 1);\r
                        break;\r
                case DEMOD_PSK1:\r
-                       snprintf(cmdStr, sizeof(buf),"%d %d 0", bitRate[config.bitrate], config.inverted );\r
+                       // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
+                       CmdLtrim("160");\r
+                       snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );\r
                        ans = PSKDemod(cmdStr, FALSE);\r
                        break;\r
                case DEMOD_PSK2: //inverted won't affect this\r
                case DEMOD_PSK3: //not fully implemented\r
                        ans = PSKDemod(cmdStr, FALSE);\r
                        break;\r
                case DEMOD_PSK2: //inverted won't affect this\r
                case DEMOD_PSK3: //not fully implemented\r
-                       snprintf(cmdStr, sizeof(buf),"%d 0 1", bitRate[config.bitrate] );\r
+                       // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
+                       CmdLtrim("160");\r
+                       snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );\r
                        ans = PSKDemod(cmdStr, FALSE);\r
                        psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                        break;\r
                        ans = PSKDemod(cmdStr, FALSE);\r
                        psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                        break;\r
@@ -372,7 +376,7 @@ bool DecodeT55xxBlock(){
                        break;\r
                case DEMOD_BI:\r
                case DEMOD_BIa:\r
                        break;\r
                case DEMOD_BI:\r
                case DEMOD_BIa:\r
-                       snprintf(cmdStr, sizeof(buf),"0 %d %d 0", bitRate[config.bitrate], config.inverted );\r
+                       snprintf(cmdStr, sizeof(buf),"0 %d %d 1", bitRate[config.bitrate], config.inverted );\r
                        ans = ASKbiphaseDemod(cmdStr, FALSE);\r
                        break;\r
                default:\r
                        ans = ASKbiphaseDemod(cmdStr, FALSE);\r
                        break;\r
                default:\r
@@ -432,28 +436,28 @@ bool tryDetectModulation(){
        } else {\r
                clk = GetAskClock("", FALSE, FALSE);\r
                if (clk>0) {\r
        } else {\r
                clk = GetAskClock("", FALSE, FALSE);\r
                if (clk>0) {\r
-                       if ( ASKDemod("0 0 0", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+                       if ( ASKDemod("0 0 1", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
                                tests[hits].modulation = DEMOD_ASK;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = FALSE;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
                                ++hits;\r
                        }\r
                                tests[hits].modulation = DEMOD_ASK;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = FALSE;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
                                ++hits;\r
                        }\r
-                       if ( ASKDemod("0 1 0", FALSE, FALSE, 1)  && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+                       if ( ASKDemod("0 1 1", FALSE, FALSE, 1)  && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
                                tests[hits].modulation = DEMOD_ASK;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = TRUE;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
                                ++hits;\r
                        }\r
                                tests[hits].modulation = DEMOD_ASK;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = TRUE;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
                                ++hits;\r
                        }\r
-                       if ( ASKbiphaseDemod("0 0 0 0", FALSE) && test(DEMOD_BI, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
+                       if ( ASKbiphaseDemod("0 0 0 2", FALSE) && test(DEMOD_BI, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
                                tests[hits].modulation = DEMOD_BI;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = FALSE;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
                                ++hits;\r
                        }\r
                                tests[hits].modulation = DEMOD_BI;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = FALSE;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
                                ++hits;\r
                        }\r
-                       if ( ASKbiphaseDemod("0 0 1 0", FALSE) && test(DEMOD_BIa, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
+                       if ( ASKbiphaseDemod("0 0 1 2", FALSE) && test(DEMOD_BIa, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
                                tests[hits].modulation = DEMOD_BIa;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = TRUE;\r
                                tests[hits].modulation = DEMOD_BIa;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = TRUE;\r
@@ -484,16 +488,18 @@ bool tryDetectModulation(){
                \r
                //undo trim from nrz\r
                save_restoreGB(0);\r
                \r
                //undo trim from nrz\r
                save_restoreGB(0);\r
+               // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
+               CmdLtrim("160");\r
                clk = GetPskClock("", FALSE, FALSE);\r
                if (clk>0) {\r
                clk = GetPskClock("", FALSE, FALSE);\r
                if (clk>0) {\r
-                       if ( PSKDemod("0 0 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+                       if ( PSKDemod("0 0 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
                                tests[hits].modulation = DEMOD_PSK1;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = FALSE;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
                                ++hits;\r
                        }\r
                                tests[hits].modulation = DEMOD_PSK1;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = FALSE;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
                                ++hits;\r
                        }\r
-                       if ( PSKDemod("0 1 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+                       if ( PSKDemod("0 1 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
                                tests[hits].modulation = DEMOD_PSK1;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = TRUE;\r
                                tests[hits].modulation = DEMOD_PSK1;\r
                                tests[hits].bitrate = bitRate;\r
                                tests[hits].inverted = TRUE;\r
@@ -501,7 +507,7 @@ bool tryDetectModulation(){
                                ++hits;\r
                        }\r
                        // PSK2 - needs a call to psk1TOpsk2.\r
                                ++hits;\r
                        }\r
                        // PSK2 - needs a call to psk1TOpsk2.\r
-                       if ( PSKDemod("0 0 1", FALSE)) {\r
+                       if ( PSKDemod("0 0 6", FALSE)) {\r
                                psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                                if (test(DEMOD_PSK2, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
                                        tests[hits].modulation = DEMOD_PSK2;\r
                                psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                                if (test(DEMOD_PSK2, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
                                        tests[hits].modulation = DEMOD_PSK2;\r
@@ -512,7 +518,7 @@ bool tryDetectModulation(){
                                }\r
                        } // inverse waves does not affect this demod\r
                        // PSK3 - needs a call to psk1TOpsk2.\r
                                }\r
                        } // inverse waves does not affect this demod\r
                        // PSK3 - needs a call to psk1TOpsk2.\r
-                       if ( PSKDemod("0 0 1", FALSE)) {\r
+                       if ( PSKDemod("0 0 6", FALSE)) {\r
                                psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                                if (test(DEMOD_PSK3, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
                                        tests[hits].modulation = DEMOD_PSK3;\r
                                psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                                if (test(DEMOD_PSK3, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
                                        tests[hits].modulation = DEMOD_PSK3;\r
@@ -609,31 +615,30 @@ bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t       clk){
 \r
        if ( DemodBufferLen < 64 ) return FALSE;\r
        uint8_t si = 0;\r
 \r
        if ( DemodBufferLen < 64 ) return FALSE;\r
        uint8_t si = 0;\r
-       for (uint8_t idx = 0; idx < 64; idx++){\r
+       for (uint8_t idx = 28; idx < 64; idx++){\r
                si = idx;\r
                si = idx;\r
-               if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue;\r
+               if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;\r
 \r
                uint8_t safer     = PackBits(si, 4, DemodBuffer); si += 4;     //master key\r
                uint8_t resv      = PackBits(si, 8, DemodBuffer); si += 8;\r
                // 2nibble must be zeroed.\r
 \r
                uint8_t safer     = PackBits(si, 4, DemodBuffer); si += 4;     //master key\r
                uint8_t resv      = PackBits(si, 8, DemodBuffer); si += 8;\r
                // 2nibble must be zeroed.\r
-               // moved test to here, since this gets most faults first.\r
                if (safer != 0x6) continue;\r
                if ( resv > 0x00) continue;\r
                //uint8_t       pageSel   = PackBits(si, 1, DemodBuffer); si += 1;\r
                //uint8_t fastWrite = PackBits(si, 1, DemodBuffer); si += 1;\r
                si += 1+1;\r
                int bitRate       = PackBits(si, 5, DemodBuffer)*2 + 2; si += 5;     //bit rate\r
                if (safer != 0x6) continue;\r
                if ( resv > 0x00) continue;\r
                //uint8_t       pageSel   = PackBits(si, 1, DemodBuffer); si += 1;\r
                //uint8_t fastWrite = PackBits(si, 1, DemodBuffer); si += 1;\r
                si += 1+1;\r
                int bitRate       = PackBits(si, 5, DemodBuffer)*2 + 2; si += 5;     //bit rate\r
-               if (bitRate > 128) continue;\r
+               if (bitRate > 128 || bitRate < 8) continue;\r
 \r
 \r
-               si += 1+1+2+1;\r
-               //uint8_t AOR       = PackBits(si, 1, DemodBuffer); si += 1;     //bit 15 extended mode\r
+               //uint8_t AOR       = PackBits(si, 1, DemodBuffer); si += 1;   \r
                //uint8_t PWD       = PackBits(si, 1, DemodBuffer); si += 1; \r
                //uint8_t pskcr     = PackBits(si, 2, DemodBuffer); si += 2;  //could check psk cr\r
                //uint8_t inverse   = PackBits(si, 1, DemodBuffer); si += 1;\r
                //uint8_t PWD       = PackBits(si, 1, DemodBuffer); si += 1; \r
                //uint8_t pskcr     = PackBits(si, 2, DemodBuffer); si += 2;  //could check psk cr\r
                //uint8_t inverse   = PackBits(si, 1, DemodBuffer); si += 1;\r
-               uint8_t modread   = PackBits(si, 3, DemodBuffer); si += 3;   //bit 24, 30, 31 could be tested for 0 if not extended mode\r
-               //uint8_t maxBlk    = PackBits(si, 2, DemodBuffer); si += 2;\r
+               si += 1+1+2+1;\r
+               uint8_t modread   = PackBits(si, 3, DemodBuffer); si += 3;\r
+               uint8_t maxBlk    = PackBits(si, 3, DemodBuffer); si += 3;\r
                //uint8_t ST        = PackBits(si, 1, DemodBuffer); si += 1;\r
                //uint8_t ST        = PackBits(si, 1, DemodBuffer); si += 1;\r
-\r
+               if (maxBlk == 0) continue;\r
                //test modulation\r
                if (!testQ5Modulation(mode, modread)) continue;\r
                if (bitRate != clk) continue;\r
                //test modulation\r
                if (!testQ5Modulation(mode, modread)) continue;\r
                if (bitRate != clk) continue;\r
@@ -646,7 +651,7 @@ bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){
 }\r
 \r
 bool testBitRate(uint8_t readRate, uint8_t clk){\r
 }\r
 \r
 bool testBitRate(uint8_t readRate, uint8_t clk){\r
-       uint8_t expected[8] = {8, 16, 32, 40, 50, 64, 100, 128};\r
+       uint8_t expected[] = {8, 16, 32, 40, 50, 64, 100, 128};\r
        if (expected[readRate] == clk)\r
                return true;\r
 \r
        if (expected[readRate] == clk)\r
                return true;\r
 \r
@@ -657,9 +662,9 @@ bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5)
 \r
        if ( DemodBufferLen < 64 ) return FALSE;\r
        uint8_t si = 0;\r
 \r
        if ( DemodBufferLen < 64 ) return FALSE;\r
        uint8_t si = 0;\r
-       for (uint8_t idx = 0; idx < 64; idx++){\r
+       for (uint8_t idx = 28; idx < 64; idx++){\r
                si = idx;\r
                si = idx;\r
-               if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue;\r
+               if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;\r
 \r
                uint8_t safer    = PackBits(si, 4, DemodBuffer); si += 4;     //master key\r
                uint8_t resv     = PackBits(si, 4, DemodBuffer); si += 4;     //was 7 & +=7+3 //should be only 4 bits if extended mode\r
 \r
                uint8_t safer    = PackBits(si, 4, DemodBuffer); si += 4;     //master key\r
                uint8_t resv     = PackBits(si, 4, DemodBuffer); si += 4;     //was 7 & +=7+3 //should be only 4 bits if extended mode\r
@@ -668,7 +673,7 @@ bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5)
                if ( resv > 0x00) continue;\r
 \r
                uint8_t xtRate   = PackBits(si, 3, DemodBuffer); si += 3;     //extended mode part of rate\r
                if ( resv > 0x00) continue;\r
 \r
                uint8_t xtRate   = PackBits(si, 3, DemodBuffer); si += 3;     //extended mode part of rate\r
-               int bitRate  = PackBits(si, 3, DemodBuffer); si += 3;     //bit rate\r
+               int bitRate      = PackBits(si, 3, DemodBuffer); si += 3;     //bit rate\r
                if (bitRate > 7) continue;\r
                uint8_t extend   = PackBits(si, 1, DemodBuffer); si += 1;     //bit 15 extended mode\r
                uint8_t modread  = PackBits(si, 5, DemodBuffer); si += 5+2+1; \r
                if (bitRate > 7) continue;\r
                uint8_t extend   = PackBits(si, 1, DemodBuffer); si += 1;     //bit 15 extended mode\r
                uint8_t modread  = PackBits(si, 5, DemodBuffer); si += 5+2+1; \r
@@ -713,8 +718,9 @@ void printT55xxBlock(const char *blockNum){
 \r
        for (; i < endpos; ++i)\r
                bits[i - config.offset]=DemodBuffer[i];\r
 \r
        for (; i < endpos; ++i)\r
                bits[i - config.offset]=DemodBuffer[i];\r
-\r
+       //print second round of read data (more accurate due to antenna settling)\r
        blockData = PackBits(0, 32, bits);\r
        blockData = PackBits(0, 32, bits);\r
+\r
        PrintAndLog("  %s | %08X | %s", blockNum, blockData, sprint_bin(bits,32));\r
 }\r
 \r
        PrintAndLog("  %s | %08X | %s", blockNum, blockData, sprint_bin(bits,32));\r
 }\r
 \r
@@ -968,7 +974,7 @@ int CmdT55xxInfo(const char *Cmd){
        uint32_t fw       = PackBits(si, 1, DemodBuffer); si += 1;\r
        uint32_t inv      = PackBits(si, 1, DemodBuffer); si += 1;      \r
        uint32_t por      = PackBits(si, 1, DemodBuffer); si += 1;\r
        uint32_t fw       = PackBits(si, 1, DemodBuffer); si += 1;\r
        uint32_t inv      = PackBits(si, 1, DemodBuffer); si += 1;      \r
        uint32_t por      = PackBits(si, 1, DemodBuffer); si += 1;\r
-       if (config.Q5) PrintAndLog("*** Warning *** Info read off a Q5 will not work as expected");\r
+       if (config.Q5) PrintAndLog("*** Warning *** Config Info read off a Q5 will not display as expected");\r
        PrintAndLog("");\r
        PrintAndLog("-- T55xx Configuration & Tag Information --------------------");\r
        PrintAndLog("-------------------------------------------------------------");\r
        PrintAndLog("");\r
        PrintAndLog("-- T55xx Configuration & Tag Information --------------------");\r
        PrintAndLog("-------------------------------------------------------------");\r
@@ -1269,8 +1275,8 @@ static command_t CommandTable[] =
   {"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
   {"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 T55xx traceability data (page 1/ blk 0-1)"},\r
-  {"info",     CmdT55xxInfo,      0, "[1] Show T55xx configuration data (page 0/ blk 0)"},\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
   {"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
   {"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
Impressum, Datenschutz