]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlft55xx.c
Add smartcard protocol T=0 (RRG repository PRs 71,72,74,75 by @merlokk) (#757)
[proxmark3-svn] / client / cmdlft55xx.c
index 8ab1892daf715ad18c64a01e0991c64d781c916d..2a096cd0e9e543be7e61895d2e8801ba96b5ec3b 100644 (file)
@@ -7,21 +7,21 @@
 // Low frequency T55xx commands\r
 //-----------------------------------------------------------------------------\r
 \r
 // Low frequency T55xx commands\r
 //-----------------------------------------------------------------------------\r
 \r
+#include "cmdlft55xx.h"\r
+\r
 #include <stdio.h>\r
 #include <string.h>\r
 #include <inttypes.h>\r
 #include <ctype.h>\r
 #include <time.h>\r
 #include <stdio.h>\r
 #include <string.h>\r
 #include <inttypes.h>\r
 #include <ctype.h>\r
 #include <time.h>\r
-#include "proxmark3.h"\r
+#include "comms.h"\r
 #include "ui.h"\r
 #include "graph.h"\r
 #include "cmdmain.h"\r
 #include "cmdparser.h"\r
 #include "cmddata.h"\r
 #include "cmdlf.h"\r
 #include "ui.h"\r
 #include "graph.h"\r
 #include "cmdmain.h"\r
 #include "cmdparser.h"\r
 #include "cmddata.h"\r
 #include "cmdlf.h"\r
-#include "cmdlft55xx.h"\r
 #include "util.h"\r
 #include "util.h"\r
-#include "data.h"\r
 #include "lfdemod.h"\r
 #include "cmdhf14a.h" //for getTagInfo\r
 #include "protocols.h"\r
 #include "lfdemod.h"\r
 #include "cmdhf14a.h" //for getTagInfo\r
 #include "protocols.h"\r
@@ -207,7 +207,7 @@ void printT5xxHeader(uint8_t page){
 int CmdT55xxSetConfig(const char *Cmd) {\r
 \r
        uint8_t offset = 0;\r
 int CmdT55xxSetConfig(const char *Cmd) {\r
 \r
        uint8_t offset = 0;\r
-       char modulation[5] = {0x00};\r
+       char modulation[6] = {0x00};\r
        char tmp = 0x00;\r
        uint8_t bitRate = 0;\r
        uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};\r
        char tmp = 0x00;\r
        uint8_t bitRate = 0;\r
        uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};\r
@@ -236,7 +236,7 @@ int CmdT55xxSetConfig(const char *Cmd) {
                        cmdp+=2;\r
                        break;\r
                case 'd':\r
                        cmdp+=2;\r
                        break;\r
                case 'd':\r
-                       param_getstr(Cmd, cmdp+1, modulation);\r
+                       param_getstr(Cmd, cmdp+1, modulation, sizeof(modulation));\r
                        cmdp += 2;\r
 \r
                        if ( strcmp(modulation, "FSK" ) == 0) {\r
                        cmdp += 2;\r
 \r
                        if ( strcmp(modulation, "FSK" ) == 0) {\r
@@ -419,23 +419,23 @@ bool DecodeT55xxBlock(){
                        break;\r
                case DEMOD_PSK1:\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
                        break;\r
                case DEMOD_PSK1:\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
-                       save_restoreGB(1);\r
+                       save_restoreGB(GRAPH_SAVE);\r
                        CmdLtrim("160");\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );\r
                        ans = PSKDemod(cmdStr, false);\r
                        //undo trim samples\r
                        CmdLtrim("160");\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );\r
                        ans = PSKDemod(cmdStr, false);\r
                        //undo trim samples\r
-                       save_restoreGB(0);\r
+                       save_restoreGB(GRAPH_RESTORE);\r
                        break;\r
                case DEMOD_PSK2: //inverted won't affect this\r
                case DEMOD_PSK3: //not fully implemented\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
                        break;\r
                case DEMOD_PSK2: //inverted won't affect this\r
                case DEMOD_PSK3: //not fully implemented\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
-                       save_restoreGB(1);\r
+                       save_restoreGB(GRAPH_SAVE);\r
                        CmdLtrim("160");\r
                        snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );\r
                        ans = PSKDemod(cmdStr, false);\r
                        psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                        //undo trim samples\r
                        CmdLtrim("160");\r
                        snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );\r
                        ans = PSKDemod(cmdStr, false);\r
                        psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                        //undo trim samples\r
-                       save_restoreGB(0);\r
+                       save_restoreGB(GRAPH_RESTORE);\r
                        break;\r
                case DEMOD_NRZ:\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
                        break;\r
                case DEMOD_NRZ:\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
@@ -507,8 +507,8 @@ bool tryDetectModulation(){
        t55xx_conf_block_t tests[15];\r
        int bitRate=0;\r
        uint8_t fc1 = 0, fc2 = 0, ans = 0;\r
        t55xx_conf_block_t tests[15];\r
        int bitRate=0;\r
        uint8_t fc1 = 0, fc2 = 0, ans = 0;\r
-       int clk=0;\r
-       ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false);\r
+       int clk = 0, firstClockEdge = 0;\r
+       ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false, &firstClockEdge);\r
        if (ans && ((fc1==10 && fc2==8) || (fc1==8 && fc2==5))) {\r
                if ( FSKrawDemod("0 0", false) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
                        tests[hits].modulation = DEMOD_FSK;\r
        if (ans && ((fc1==10 && fc2==8) || (fc1==8 && fc2==5))) {\r
                if ( FSKrawDemod("0 0", false) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
                        tests[hits].modulation = DEMOD_FSK;\r
@@ -594,7 +594,7 @@ bool tryDetectModulation(){
                clk = GetPskClock("", false, false);\r
                if (clk>0) {\r
                        // allow undo\r
                clk = GetPskClock("", false, false);\r
                if (clk>0) {\r
                        // allow undo\r
-                       save_restoreGB(1);\r
+                       save_restoreGB(GRAPH_SAVE);\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
                        CmdLtrim("160");\r
                        if ( PSKDemod("0 0 6", false) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
                        // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
                        CmdLtrim("160");\r
                        if ( PSKDemod("0 0 6", false) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
@@ -638,7 +638,7 @@ bool tryDetectModulation(){
                                }\r
                        } // inverse waves does not affect this demod\r
                        //undo trim samples\r
                                }\r
                        } // inverse waves does not affect this demod\r
                        //undo trim samples\r
-                       save_restoreGB(0);\r
+                       save_restoreGB(GRAPH_RESTORE);\r
                }\r
        }       \r
        if ( hits == 1) {\r
                }\r
        }       \r
        if ( hits == 1) {\r
@@ -1355,8 +1355,7 @@ int CmdResetRead(const char *Cmd) {
        }\r
 \r
        uint8_t got[BIGBUF_SIZE-1];\r
        }\r
 \r
        uint8_t got[BIGBUF_SIZE-1];\r
-       GetFromBigBuf(got,sizeof(got),0);\r
-       WaitForResponse(CMD_ACK,NULL);\r
+       GetFromBigBuf(got, sizeof(got), 0, NULL, -1 , 0);\r
        setGraphBuf(got, sizeof(got));\r
        return 1;\r
 }\r
        setGraphBuf(got, sizeof(got));\r
        return 1;\r
 }\r
@@ -1433,7 +1432,7 @@ int CmdT55xxBruteForce(const char *Cmd) {
                        //The line start with # is comment, skip\r
                        if( buf[0]=='#' ) continue;\r
 \r
                        //The line start with # is comment, skip\r
                        if( buf[0]=='#' ) continue;\r
 \r
-                       if (!isxdigit(buf[0])) {\r
+                       if (!isxdigit((unsigned char)buf[0])) {\r
                                PrintAndLog("File content error. '%s' must include 8 HEX symbols", buf);\r
                                continue;\r
                        }\r
                                PrintAndLog("File content error. '%s' must include 8 HEX symbols", buf);\r
                                continue;\r
                        }\r
@@ -1555,7 +1554,7 @@ bool tryDetectP1(bool getData) {
        uint8_t preamble[] = {1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,1};\r
        size_t startIdx = 0;\r
        uint8_t fc1 = 0, fc2 = 0, ans = 0;\r
        uint8_t preamble[] = {1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,1};\r
        size_t startIdx = 0;\r
        uint8_t fc1 = 0, fc2 = 0, ans = 0;\r
-       int clk = 0;\r
+       int clk = 0, firstClockEdge = 0;\r
        bool st = true;\r
 \r
        if ( getData ) {\r
        bool st = true;\r
 \r
        if ( getData ) {\r
@@ -1564,7 +1563,7 @@ bool tryDetectP1(bool getData) {
        }\r
 \r
        // try fsk clock detect. if successful it cannot be any other type of modulation...  (in theory...)\r
        }\r
 \r
        // try fsk clock detect. if successful it cannot be any other type of modulation...  (in theory...)\r
-       ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false);\r
+       ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false, &firstClockEdge);\r
        if (ans && ((fc1==10 && fc2==8) || (fc1==8 && fc2==5))) {\r
                if ( FSKrawDemod("0 0", false) && \r
                          preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
        if (ans && ((fc1==10 && fc2==8) || (fc1==8 && fc2==5))) {\r
                if ( FSKrawDemod("0 0", false) && \r
                          preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
Impressum, Datenschutz