]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
Client code cleanup: 227/head
authorpwpiwi <pwpiwi@users.noreply.github.com>
Mon, 6 Mar 2017 19:07:02 +0000 (20:07 +0100)
committerpwpiwi <pwpiwi@users.noreply.github.com>
Mon, 6 Mar 2017 20:03:13 +0000 (21:03 +0100)
- cleanup some header files and respective #includes
- rearrange functions (definition before first use)
- use SCNxxx instead of PRIxxx macros in scanf()
- use stdbool true/false instead of self defined TRUE/FALSE

16 files changed:
client/cmddata.c
client/cmdhf.c
client/cmdhf14a.c
client/cmdhfmf.c
client/cmdhfmf.h
client/cmdhfmfu.c
client/cmdlf.c
client/cmdlfcotag.c
client/cmdlfcotag.h
client/cmdlft55xx.c
client/cmdmain.h
client/mifarehost.c
client/mifarehost.h
client/nonce2key/nonce2key.c
client/util.h
client/whereami.c

index 2a83a4d49c376ec9f010e2d5d358971947c453ee..e07e72235a8c624d22880372e67c8468bb20bd92 100644 (file)
@@ -277,8 +277,8 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo )
 
 int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose)
 {
-       bool st = TRUE;
-       if (!ASKDemod_ext(Cmd, FALSE, FALSE, 1, &st)) return 0;
+       bool st = true;
+       if (!ASKDemod_ext(Cmd, false, false, 1, &st)) return 0;
        return AskEm410xDecode(verbose, hi, lo);
 }
 
@@ -406,13 +406,13 @@ int Cmdaskmandemod(const char *Cmd)
                PrintAndLog("          : data rawdemod am 64 1 0 = demod an ask/manchester tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors");
                return 0;
        }
-       bool st = TRUE;
+       bool st = true;
        if (Cmd[0]=='s') 
-               return ASKDemod_ext(Cmd++, TRUE, TRUE, 1, &st);
+               return ASKDemod_ext(Cmd++, true, true, 1, &st);
        else if (Cmd[1] == 's')
-               return ASKDemod_ext(Cmd+=2, TRUE, TRUE, 1, &st);
+               return ASKDemod_ext(Cmd+=2, true, true, 1, &st);
        else
-               return ASKDemod(Cmd, TRUE, TRUE, 1);
+               return ASKDemod(Cmd, true, true, 1);
 }
 
 //by marshmellow
@@ -587,7 +587,7 @@ int Cmdaskbiphdemod(const char *Cmd)
                PrintAndLog("          : data rawdemod ab 0 64 1 0 0 a = demod an ask/biph tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors, and amp");
                return 0;
        }
-       return ASKbiphaseDemod(Cmd, TRUE);
+       return ASKbiphaseDemod(Cmd, true);
 }
 
 //by marshmellow
@@ -597,7 +597,7 @@ int Cmdaskbiphdemod(const char *Cmd)
 //if successful it will push askraw data back to demod buffer ready for emulation
 int CmdG_Prox_II_Demod(const char *Cmd)
 {
-       if (!ASKbiphaseDemod(Cmd, FALSE)){
+       if (!ASKbiphaseDemod(Cmd, false)){
                if (g_debugMode) PrintAndLog("Error gProxII: ASKbiphaseDemod failed 1st try");
                return 0;
        }
@@ -702,7 +702,7 @@ int Cmdaskrawdemod(const char *Cmd)
                PrintAndLog("          : data rawdemod ar 64 1 0 0 a = demod an ask tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors, and amp");
                return 0;
        }
-       return ASKDemod(Cmd, TRUE, FALSE, 0);
+       return ASKDemod(Cmd, true, false, 0);
 }
 
 int AutoCorrelate(int window, bool SaveGrph, bool verbose)
@@ -767,7 +767,7 @@ int CmdAutoCorr(const char *Cmd)
                return usage_data_autocorr();
        int window = 4000; //set default
        char grph=0;
-       bool updateGrph = FALSE;
+       bool updateGrph = false;
        sscanf(Cmd, "%i %c", &window, &grph);
 
        if (window >= GraphTraceLen) {
@@ -775,8 +775,8 @@ int CmdAutoCorr(const char *Cmd)
                        GraphTraceLen);
                return 0;
        }
-       if (grph == 'g') updateGrph=TRUE;
-       return AutoCorrelate(window, updateGrph, TRUE);
+       if (grph == 'g') updateGrph=true;
+       return AutoCorrelate(window, updateGrph, true);
 }
 
 int CmdBitsamples(const char *Cmd)
@@ -1035,7 +1035,7 @@ int CmdFSKrawdemod(const char *Cmd)
                PrintAndLog("          : data rawdemod fs 50 1 10 8 = demod an fsk2a RF/50 tag from GraphBuffer");
                return 0;
        }
-       return FSKrawDemod(Cmd, TRUE);
+       return FSKrawDemod(Cmd, true);
 }
 
 //by marshmellow (based on existing demod + holiman's refactor)
@@ -1789,7 +1789,7 @@ int CmdNRZrawDemod(const char *Cmd)
                PrintAndLog("          : data rawdemod nr 64 1 0 = demod a nrz/direct tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors");
                return 0;
        }
-       return NRZrawDemod(Cmd, TRUE);
+       return NRZrawDemod(Cmd, true);
 }
 
 // by marshmellow
@@ -1813,7 +1813,7 @@ int CmdPSK1rawDemod(const char *Cmd)
                PrintAndLog("          : data rawdemod p1 64 1 0 = demod a psk1 tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors");
                return 0;
        }
-       ans = PSKDemod(Cmd, TRUE);
+       ans = PSKDemod(Cmd, true);
        //output
        if (!ans){
                if (g_debugMode) PrintAndLog("Error demoding: %d",ans); 
@@ -1845,7 +1845,7 @@ int CmdPSK2rawDemod(const char *Cmd)
                PrintAndLog("          : data rawdemod p2 64 1 0  = demod a psk2 tag from GraphBuffer using a clock of RF/64, inverting output and allowing 0 demod errors");
                return 0;
        }
-       ans=PSKDemod(Cmd, TRUE);
+       ans=PSKDemod(Cmd, true);
        if (!ans){
                if (g_debugMode) PrintAndLog("Error demoding: %d",ans);  
                return 0;
index e3671a4267fa1c7cb0a2710d48ddc960f7f0badf..17353fb66288ad6d61e4b7b8d68a1e88a7de8f35 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include "proxmark3.h"
-#include "graph.h"
+#include "util.h"
 #include "ui.h"
+#include "iso14443crc.h"
+#include "cmdmain.h"
 #include "cmdparser.h"
 #include "cmdhf.h"
 #include "cmdhf14a.h"
index e64df7d35548b9a309207a1854c7ad251f7fd601..3dc501d479f6baa9314e3765afa1f3a253d2a759 100644 (file)
@@ -570,14 +570,14 @@ int CmdHF14ASnoop(const char *Cmd) {
 int CmdHF14ACmdRaw(const char *cmd) {
     UsbCommand c = {CMD_READER_ISO_14443a, {0, 0, 0}};
     bool reply=1;
-    bool crc = FALSE;
-    bool power = FALSE;
-    bool active = FALSE;
-    bool active_select = FALSE;
+    bool crc = false;
+    bool power = false;
+    bool active = false;
+    bool active_select = false;
     uint16_t numbits = 0;
-       bool bTimeout = FALSE;
+       bool bTimeout = false;
        uint32_t timeout = 0;
-       bool topazmode = FALSE;
+       bool topazmode = false;
     char buf[5]="";
     int i = 0;
     uint8_t data[USB_CMD_DATA_SIZE];
@@ -606,19 +606,19 @@ int CmdHF14ACmdRaw(const char *cmd) {
         if (cmd[i]=='-') {
             switch (cmd[i+1]) {
                 case 'r': 
-                    reply = FALSE;
+                    reply = false;
                     break;
                 case 'c':
-                    crc = TRUE;
+                    crc = true;
                     break;
                 case 'p':
-                    power = TRUE;
+                    power = true;
                     break;
                 case 'a':
-                    active = TRUE;
+                    active = true;
                     break;
                 case 's':
-                    active_select = TRUE;
+                    active_select = true;
                     break;
                 case 'b': 
                     sscanf(cmd+i+2,"%d",&temp);
@@ -628,7 +628,7 @@ int CmdHF14ACmdRaw(const char *cmd) {
                     i-=2;
                     break;
                                case 't':
-                                       bTimeout = TRUE;
+                                       bTimeout = true;
                                        sscanf(cmd+i+2,"%d",&temp);
                                        timeout = temp;
                                        i+=3;
@@ -636,7 +636,7 @@ int CmdHF14ACmdRaw(const char *cmd) {
                                        i-=2;
                                        break;
                 case 'T':
-                                       topazmode = TRUE;
+                                       topazmode = true;
                                        break;
                 default:
                     PrintAndLog("Invalid option");
index d5ce118b52d70452ae36b719feefe4a4e40585dd..eb3dc878f15adc79fcd3349d96ef00824b2e0916 100644 (file)
@@ -9,8 +9,18 @@
 //-----------------------------------------------------------------------------\r
 \r
 #include <inttypes.h>\r
-#include "cmdhfmf.h"\r
-#include "./nonce2key/nonce2key.h"\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "proxmark3.h"\r
+#include "cmdmain.h"\r
+#include "util.h"\r
+#include "ui.h"\r
+#include "mifarehost.h"\r
+#include "mifare.h"\r
+#include "nonce2key/nonce2key.h"\r
+\r
+#define NESTED_SECTOR_RETRY     10                     // how often we try mfested() until we give up\r
+\r
 \r
 static int CmdHelp(const char *Cmd);\r
 \r
@@ -551,10 +561,17 @@ int CmdHF14AMfRestore(const char *Cmd)
        return 0;\r
 }\r
 \r
+\r
+typedef struct {\r
+       uint64_t Key[2];\r
+       int foundKey[2];\r
+} sector_t;\r
+\r
+\r
 int CmdHF14AMfNested(const char *Cmd)\r
 {\r
        int i, j, res, iterations;\r
-       sector *e_sector = NULL;\r
+       sector_t *e_sector = NULL;\r
        uint8_t blockNo = 0;\r
        uint8_t keyType = 0;\r
        uint8_t trgBlockNo = 0;\r
@@ -674,7 +691,7 @@ int CmdHF14AMfNested(const char *Cmd)
                clock_t time1;\r
                time1 = clock();\r
 \r
-               e_sector = calloc(SectorsCnt, sizeof(sector));\r
+               e_sector = calloc(SectorsCnt, sizeof(sector_t));\r
                if (e_sector == NULL) return 1;\r
                \r
                //test current key and additional standard keys first\r
@@ -1768,7 +1785,7 @@ int CmdHF14AMfCSetBlk(const char *Cmd)
 {\r
        uint8_t memBlock[16] = {0x00};\r
        uint8_t blockNo = 0;\r
-       bool wipeCard = FALSE;\r
+       bool wipeCard = false;\r
        int res;\r
 \r
        if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r
index 22dfd4de5071b709d8f10f06ae3c36fd51030a28..fc87b228b2eb2deb336c09347ac2b36c3163f08d 100644 (file)
 #ifndef CMDHFMF_H__\r
 #define CMDHFMF_H__\r
 \r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <ctype.h>\r
-#include "proxmark3.h"\r
-#include "iso14443crc.h"\r
-#include "data.h"\r
-#include "ui.h"\r
-#include "cmdparser.h"\r
-#include "common.h"\r
-#include "util.h"\r
-#include "mifarehost.h"\r
-\r
-int CmdHFMF(const char *Cmd);\r
+extern int CmdHFMF(const char *Cmd);\r
 
-int CmdHF14AMfDbg(const char* cmd);
-int CmdHF14AMfRdBl(const char* cmd);
-int CmdHF14AMfURdBl(const char* cmd);
-int CmdHF14AMfRdSc(const char* cmd);
-int CmdHF14SMfURdCard(const char* cmd);
-int CmdHF14AMfDump(const char* cmd);
-int CmdHF14AMfRestore(const char* cmd);
-int CmdHF14AMfWrBl(const char* cmd);
-int CmdHF14AMfUWrBl(const char* cmd);
-int CmdHF14AMfChk(const char* cmd);
-int CmdHF14AMifare(const char* cmd);
-int CmdHF14AMfNested(const char* cmd);
-int CmdHF14AMfSniff(const char* cmd);\r
-int CmdHF14AMf1kSim(const char* cmd);\r
-int CmdHF14AMfEClear(const char* cmd);\r
-int CmdHF14AMfEGet(const char* cmd);\r
-int CmdHF14AMfESet(const char* cmd);\r
-int CmdHF14AMfELoad(const char* cmd);\r
-int CmdHF14AMfESave(const char* cmd);\r
-int CmdHF14AMfECFill(const char* cmd);\r
-int CmdHF14AMfEKeyPrn(const char* cmd);\r
-int CmdHF14AMfCSetUID(const char* cmd);\r
-int CmdHF14AMfCSetBlk(const char* cmd);\r
-int CmdHF14AMfCGetBlk(const char* cmd);\r
-int CmdHF14AMfCGetSc(const char* cmd);\r
-int CmdHF14AMfCLoad(const char* cmd);\r
-int CmdHF14AMfCSave(const char* cmd);\r
+extern int CmdHF14AMfDbg(const char* cmd);
+extern int CmdHF14AMfRdBl(const char* cmd);
+extern int CmdHF14AMfURdBl(const char* cmd);
+extern int CmdHF14AMfRdSc(const char* cmd);
+extern int CmdHF14SMfURdCard(const char* cmd);
+extern int CmdHF14AMfDump(const char* cmd);
+extern int CmdHF14AMfRestore(const char* cmd);
+extern int CmdHF14AMfWrBl(const char* cmd);
+extern int CmdHF14AMfUWrBl(const char* cmd);
+extern int CmdHF14AMfChk(const char* cmd);
+extern int CmdHF14AMifare(const char* cmd);
+extern int CmdHF14AMfNested(const char* cmd);
+extern int CmdHF14AMfSniff(const char* cmd);\r
+extern int CmdHF14AMf1kSim(const char* cmd);\r
+extern int CmdHF14AMfEClear(const char* cmd);\r
+extern int CmdHF14AMfEGet(const char* cmd);\r
+extern int CmdHF14AMfESet(const char* cmd);\r
+extern int CmdHF14AMfELoad(const char* cmd);\r
+extern int CmdHF14AMfESave(const char* cmd);\r
+extern int CmdHF14AMfECFill(const char* cmd);\r
+extern int CmdHF14AMfEKeyPrn(const char* cmd);\r
+extern int CmdHF14AMfCSetUID(const char* cmd);\r
+extern int CmdHF14AMfCSetBlk(const char* cmd);\r
+extern int CmdHF14AMfCGetBlk(const char* cmd);\r
+extern int CmdHF14AMfCGetSc(const char* cmd);\r
+extern int CmdHF14AMfCLoad(const char* cmd);\r
+extern int CmdHF14AMfCSave(const char* cmd);\r
 \r
 #endif\r
index b7cf0fcd6a00e5bec876a00a932839a1e711f124..b3912023a2a769ace2926376894ba93020218873 100644 (file)
@@ -7,7 +7,11 @@
 //-----------------------------------------------------------------------------
 // High frequency MIFARE ULTRALIGHT (C) commands
 //-----------------------------------------------------------------------------
-#include <ctype.h>
+
+#include "proxmark3.h"
+#include "usb_cmd.h"
+#include "cmdmain.h"
+#include "ui.h"
 #include "loclass/des.h"
 #include "cmdhfmfu.h"
 #include "cmdhfmf.h"
index 2e786943e6db6e474cdc263d38ab56032567fafe..dcc6cfae97e01209edaaf408514de4835fb2543b 100644 (file)
@@ -63,7 +63,7 @@ int CmdLFCommandRead(const char *Cmd)
 {
        static char dummy[3] = {0x20,0x00,0x00};
        UsbCommand c = {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K};
-       bool errors = FALSE;
+       bool errors = false;
        //uint8_t divisor = 95; //125khz
        uint8_t cmdp = 0;
        while(param_getchar(Cmd, cmdp) != 0x00)
@@ -484,7 +484,7 @@ int CmdLFSetConfig(const char *Cmd)
        uint8_t bps = 0; // Bits per sample
        uint8_t decimation = 0; //How many to keep
        bool averaging = 1; // Defaults to true
-       bool errors = FALSE;
+       bool errors = false;
        int trigger_threshold =-1;//Means no change
        uint8_t unsigned_trigg = 0;
 
@@ -700,7 +700,7 @@ int CmdLFfskSim(const char *Cmd)
        // otherwise will need FChigh, FClow, Clock, and bitstream
        uint8_t fcHigh=0, fcLow=0, clk=0;
        uint8_t invert=0;
-       bool errors = FALSE;
+       bool errors = false;
        char hexData[32] = {0x00}; // store entered hex data
        uint8_t data[255] = {0x00}; 
        int dataLen = 0;
@@ -734,24 +734,24 @@ int CmdLFfskSim(const char *Cmd)
                case 'd':
                        dataLen = param_getstr(Cmd, cmdp+1, hexData);
                        if (dataLen==0) {
-                               errors=TRUE
+                               errors=true
                        } else {
                                dataLen = hextobinarray((char *)data, hexData);
                        }   
-                       if (dataLen==0) errors=TRUE
+                       if (dataLen==0) errors=true
                        if (errors) PrintAndLog ("Error getting hex data");
                        cmdp+=2;
                        break;
                default:
                        PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
-                       errors = TRUE;
+                       errors = true;
                        break;
                }
                if(errors) break;
        }
        if(cmdp == 0 && DemodBufferLen == 0)
        {
-               errors = TRUE;// No args
+               errors = true;// No args
        }
 
        //Validations
@@ -802,7 +802,7 @@ int CmdLFaskSim(const char *Cmd)
        // needs clock, invert, manchester/raw as m or r, separator as s, and bitstream
        uint8_t encoding = 1, separator = 0;
        uint8_t clk=0, invert=0;
-       bool errors = FALSE;
+       bool errors = false;
        char hexData[32] = {0x00}; 
        uint8_t data[255]= {0x00}; // store entered hex data
        int dataLen = 0;
@@ -840,24 +840,24 @@ int CmdLFaskSim(const char *Cmd)
                case 'd':
                        dataLen = param_getstr(Cmd, cmdp+1, hexData);
                        if (dataLen==0) {
-                               errors=TRUE
+                               errors=true
                        } else {
                                dataLen = hextobinarray((char *)data, hexData);
                        }
-                       if (dataLen==0) errors=TRUE
+                       if (dataLen==0) errors=true
                        if (errors) PrintAndLog ("Error getting hex data, datalen: %d",dataLen);
                                cmdp+=2;
                        break;
                default:
                        PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
-                       errors = TRUE;
+                       errors = true;
                        break;
                }
                if(errors) break;
        }
        if(cmdp == 0 && DemodBufferLen == 0)
        {
-               errors = TRUE;// No args
+               errors = true;// No args
        }
 
        //Validations
@@ -896,7 +896,7 @@ int CmdLFpskSim(const char *Cmd)
        //will need carrier, Clock, and bitstream
        uint8_t carrier=0, clk=0;
        uint8_t invert=0;
-       bool errors = FALSE;
+       bool errors = false;
        char hexData[32] = {0x00}; // store entered hex data
        uint8_t data[255] = {0x00}; 
        int dataLen = 0;
@@ -935,24 +935,24 @@ int CmdLFpskSim(const char *Cmd)
                case 'd':
                        dataLen = param_getstr(Cmd, cmdp+1, hexData);
                        if (dataLen==0) {
-                               errors=TRUE
+                               errors=true
                        } else {
                                dataLen = hextobinarray((char *)data, hexData);
                        }    
-                       if (dataLen==0) errors=TRUE
+                       if (dataLen==0) errors=true
                        if (errors) PrintAndLog ("Error getting hex data");
                        cmdp+=2;
                        break;
                default:
                        PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
-                       errors = TRUE;
+                       errors = true;
                        break;
                }
                if (errors) break;
        }
        if (cmdp == 0 && DemodBufferLen == 0)
        {
-               errors = TRUE;// No args
+               errors = true;// No args
        }
 
        //Validations
@@ -962,9 +962,9 @@ int CmdLFpskSim(const char *Cmd)
        }
        if (dataLen == 0){ //using DemodBuffer
                PrintAndLog("Getting Clocks");
-               if (clk==0) clk = GetPskClock("", FALSE, FALSE);
+               if (clk==0) clk = GetPskClock("", false, false);
                PrintAndLog("clk: %d",clk);
-               if (!carrier) carrier = GetPskCarrier("", FALSE, FALSE); 
+               if (!carrier) carrier = GetPskCarrier("", false, false); 
                PrintAndLog("carrier: %d", carrier);
        } else {
                setDemodBuf(data, dataLen, 0);
@@ -1236,18 +1236,18 @@ int CmdLFfind(const char *Cmd)
                ans=CheckChipType(cmdp);
                //test unknown tag formats (raw mode)0
                PrintAndLog("\nChecking for Unknown tags:\n");
-               ans=AutoCorrelate(4000, FALSE, FALSE);
+               ans=AutoCorrelate(4000, false, false);
                if (ans > 0) PrintAndLog("Possible Auto Correlation of %d repeating samples",ans);
-               ans=GetFskClock("",FALSE,FALSE); 
+               ans=GetFskClock("",false,false); 
                if (ans != 0){ //fsk
-                       ans=FSKrawDemod("",TRUE);
+                       ans=FSKrawDemod("",true);
                        if (ans>0) {
                                PrintAndLog("\nUnknown FSK Modulated Tag Found!");
                                return 1;
                        }
                }
-               bool st = TRUE;
-               ans=ASKDemod_ext("0 0 0",TRUE,FALSE,1,&st);
+               bool st = true;
+               ans=ASKDemod_ext("0 0 0",true,false,1,&st);
                if (ans>0) {
                        PrintAndLog("\nUnknown ASK Modulated and Manchester encoded Tag Found!");
                        PrintAndLog("\nif it does not look right it could instead be ASK/Biphase - try 'data rawdemod ab'");
index f10516a61053c3e7974308cf2b7ac68dba99ad8e..0f68064e55e83063af045d603db51113c284cc9b 100644 (file)
@@ -7,7 +7,17 @@
 //-----------------------------------------------------------------------------
 // Low frequency COTAG commands
 //-----------------------------------------------------------------------------
-#include "cmdlfcotag.h"  // COTAG function declarations
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include "proxmark3.h"
+#include "ui.h"
+#include "cmddata.h"
+#include "data.h"
+#include "cmdlfcotag.h"
+#include "lfdemod.h"
+#include "usb_cmd.h"
+#include "cmdmain.h"
 
 static int CmdHelp(const char *Cmd);
 
index c46348e471bf562d93dd1f43aec2cb3ee2de5668..f0d0e75fff86000e8d58e0b5fdb3c6e6bd2f8c7f 100644 (file)
 #ifndef CMDLFCOTAG_H__
 #define CMDLFCOTAG_H__
 
-#include "proxmark3.h"// Definitions, USB controls, COTAG_BITS
-#include "util.h"     // FALSE / TRUE
-#include "cmddata.h"  // getSamples
-#include "cmdparser.h"// CmdsParse, CmdsHelp
-#include "cmdmain.h"
-#include "ui.h"       // PrintAndLog
-#include "cmdlf.h"    // Setconfig 
-#include "lfdemod.h"  // manrawdecode, bytebits_tobyteLSBF
-
 #ifndef COTAG_BITS
 #define COTAG_BITS 264
 #endif
index 9e4883c759b55240b8ce052baf6f150271dbecf4..27c84efa536efc80dbcd95c35ac03f0e57ef266e 100644 (file)
@@ -30,7 +30,7 @@
 #define REGULAR_READ_MODE_BLOCK 0xFF\r
 \r
 // Default configuration\r
-t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = FALSE, .offset = 0x00, .block0 = 0x00, .Q5 = FALSE };\r
+t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = false, .offset = 0x00, .block0 = 0x00, .Q5 = false };\r
 \r
 t55xx_conf_block_t Get_t55xx_Config(){\r
        return config;\r
@@ -194,7 +194,7 @@ int CmdT55xxSetConfig(const char *Cmd) {
        uint8_t bitRate = 0;\r
        uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};\r
        uint8_t cmdp = 0;\r
-       bool errors = FALSE;\r
+       bool errors = false;\r
        while(param_getchar(Cmd, cmdp) != 0x00 && !errors)\r
        {\r
                tmp = param_getchar(Cmd, cmdp);\r
@@ -213,7 +213,7 @@ int CmdT55xxSetConfig(const char *Cmd) {
                                                break;\r
                                        }\r
                                }\r
-                               if (i==9) errors = TRUE;\r
+                               if (i==9) errors = true;\r
                        }\r
                        cmdp+=2;\r
                        break;\r
@@ -253,7 +253,7 @@ int CmdT55xxSetConfig(const char *Cmd) {
                                config.inverted=0;\r
                        } else {\r
                                PrintAndLog("Unknown modulation '%s'", modulation);\r
-                               errors = TRUE;\r
+                               errors = true;\r
                        }\r
                        break;\r
                case 'i':\r
@@ -268,17 +268,17 @@ int CmdT55xxSetConfig(const char *Cmd) {
                        break;\r
                case 'Q':\r
                case 'q':               \r
-                       config.Q5 = TRUE;\r
+                       config.Q5 = true;\r
                        cmdp++;\r
                        break;\r
                case 'S':\r
                case 's':               \r
-                       config.ST = TRUE;\r
+                       config.ST = true;\r
                        cmdp++;\r
                        break;\r
                default:\r
                        PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
-                       errors = TRUE;\r
+                       errors = true;\r
                        break;\r
                }\r
        }\r
@@ -383,28 +383,28 @@ bool DecodeT55xxBlock(){
        switch( config.modulation ){\r
                case DEMOD_FSK:\r
                        snprintf(cmdStr, sizeof(buf),"%d %d", bitRate[config.bitrate], config.inverted );\r
-                       ans = FSKrawDemod(cmdStr, FALSE);\r
+                       ans = FSKrawDemod(cmdStr, false);\r
                        break;\r
                case DEMOD_FSK1:\r
                case DEMOD_FSK1a:\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 8 5", bitRate[config.bitrate], config.inverted );\r
-                       ans = FSKrawDemod(cmdStr, FALSE);\r
+                       ans = FSKrawDemod(cmdStr, false);\r
                        break;\r
                case DEMOD_FSK2:\r
                case DEMOD_FSK2a:\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 10 8", bitRate[config.bitrate], config.inverted );\r
-                       ans = FSKrawDemod(cmdStr, FALSE);\r
+                       ans = FSKrawDemod(cmdStr, false);\r
                        break;\r
                case DEMOD_ASK:\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
-                       ans = ASKDemod_ext(cmdStr, FALSE, FALSE, 1, &ST);\r
+                       ans = ASKDemod_ext(cmdStr, false, false, 1, &ST);\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
                        CmdLtrim("160");\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );\r
-                       ans = PSKDemod(cmdStr, FALSE);\r
+                       ans = PSKDemod(cmdStr, false);\r
                        //undo trim samples\r
                        save_restoreGB(0);\r
                        break;\r
@@ -414,22 +414,22 @@ bool DecodeT55xxBlock(){
                        save_restoreGB(1);\r
                        CmdLtrim("160");\r
                        snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );\r
-                       ans = PSKDemod(cmdStr, FALSE);\r
+                       ans = PSKDemod(cmdStr, false);\r
                        psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                        //undo trim samples\r
                        save_restoreGB(0);\r
                        break;\r
                case DEMOD_NRZ:\r
                        snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
-                       ans = NRZrawDemod(cmdStr, FALSE);\r
+                       ans = NRZrawDemod(cmdStr, false);\r
                        break;\r
                case DEMOD_BI:\r
                case DEMOD_BIa:\r
                        snprintf(cmdStr, sizeof(buf),"0 %d %d 1", bitRate[config.bitrate], config.inverted );\r
-                       ans = ASKbiphaseDemod(cmdStr, FALSE);\r
+                       ans = ASKbiphaseDemod(cmdStr, false);\r
                        break;\r
                default:\r
-                       return FALSE;\r
+                       return false;\r
        }\r
        return (bool) ans;\r
 }\r
@@ -438,13 +438,13 @@ bool DecodeT5555TraceBlock() {
        DemodBufferLen = 0x00;\r
        \r
        // According to datasheet. Always: RF/64, not inverted, Manchester\r
-       return (bool) ASKDemod("64 0 1", FALSE, FALSE, 1);\r
+       return (bool) ASKDemod("64 0 1", false, false, 1);\r
 }\r
 \r
 int CmdT55xxDetect(const char *Cmd){\r
-       bool errors = FALSE;\r
-       bool useGB = FALSE;\r
-       bool usepwd = FALSE;\r
+       bool errors = false;\r
+       bool useGB = false;\r
+       bool usepwd = false;\r
        uint32_t password = 0;\r
        uint8_t cmdp = 0;\r
 \r
@@ -456,12 +456,12 @@ int CmdT55xxDetect(const char *Cmd){
                case 'p':\r
                case 'P':\r
                        password = param_get32ex(Cmd, cmdp+1, 0, 16);\r
-                       usepwd = TRUE;\r
+                       usepwd = true;\r
                        cmdp += 2;\r
                        break;\r
                case '1':\r
                        // use Graphbuffer data\r
-                       useGB = TRUE;\r
+                       useGB = true;\r
                        cmdp++;\r
                        break;\r
                default:\r
@@ -489,87 +489,87 @@ bool tryDetectModulation(){
        t55xx_conf_block_t tests[15];\r
        int bitRate=0;\r
        uint8_t fc1 = 0, fc2 = 0, clk=0;\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
+       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
                        tests[hits].modulation = DEMOD_FSK;\r
                        if (fc1==8 && fc2 == 5)\r
                                tests[hits].modulation = DEMOD_FSK1a;\r
                        else if (fc1==10 && fc2 == 8)\r
                                tests[hits].modulation = DEMOD_FSK2;\r
                        tests[hits].bitrate = bitRate;\r
-                       tests[hits].inverted = FALSE;\r
+                       tests[hits].inverted = false;\r
                        tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
-                       tests[hits].ST = FALSE;\r
+                       tests[hits].ST = false;\r
                        ++hits;\r
                }\r
-               if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+               if ( FSKrawDemod("0 1", false) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
                        tests[hits].modulation = DEMOD_FSK;\r
                        if (fc1 == 8 && fc2 == 5)\r
                                tests[hits].modulation = DEMOD_FSK1;\r
                        else if (fc1 == 10 && fc2 == 8)\r
                                tests[hits].modulation = DEMOD_FSK2a;\r
                        tests[hits].bitrate = bitRate;\r
-                       tests[hits].inverted = TRUE;\r
+                       tests[hits].inverted = true;\r
                        tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
-                       tests[hits].ST = FALSE;\r
+                       tests[hits].ST = false;\r
                        ++hits;\r
                }\r
        } else {\r
-               clk = GetAskClock("", FALSE, FALSE);\r
+               clk = GetAskClock("", false, false);\r
                if (clk>0) {\r
-                       tests[hits].ST = TRUE;\r
-                       if ( ASKDemod_ext("0 0 1", FALSE, FALSE, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+                       tests[hits].ST = true;\r
+                       if ( ASKDemod_ext("0 0 1", false, false, 1, &tests[hits].ST) && 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].inverted = false;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
                                ++hits;\r
                        }\r
-                       tests[hits].ST = TRUE;\r
-                       if ( ASKDemod_ext("0 1 1", FALSE, FALSE, 1, &tests[hits].ST)  && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+                       tests[hits].ST = true;\r
+                       if ( ASKDemod_ext("0 1 1", false, false, 1, &tests[hits].ST)  && 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].inverted = true;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
                                ++hits;\r
                        }\r
-                       if ( ASKbiphaseDemod("0 0 0 2", 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].inverted = false;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
-                               tests[hits].ST = FALSE;\r
+                               tests[hits].ST = false;\r
                                ++hits;\r
                        }\r
-                       if ( ASKbiphaseDemod("0 0 1 2", 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].inverted = true;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
-                               tests[hits].ST = FALSE;\r
+                               tests[hits].ST = false;\r
                                ++hits;\r
                        }\r
                }\r
                //undo trim from ask\r
                //save_restoreGB(0);\r
-               clk = GetNrzClock("", FALSE, FALSE);\r
+               clk = GetNrzClock("", false, false);\r
                if (clk>0) {\r
-                       if ( NRZrawDemod("0 0 1", FALSE)  && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+                       if ( NRZrawDemod("0 0 1", false)  && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
                                tests[hits].modulation = DEMOD_NRZ;\r
                                tests[hits].bitrate = bitRate;\r
-                               tests[hits].inverted = FALSE;\r
+                               tests[hits].inverted = false;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
-                               tests[hits].ST = FALSE;\r
+                               tests[hits].ST = false;\r
                                ++hits;\r
                        }\r
 \r
-                       if ( NRZrawDemod("0 1 1", FALSE)  && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+                       if ( NRZrawDemod("0 1 1", false)  && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
                                tests[hits].modulation = DEMOD_NRZ;\r
                                tests[hits].bitrate = bitRate;\r
-                               tests[hits].inverted = TRUE;\r
+                               tests[hits].inverted = true;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
-                               tests[hits].ST = FALSE;\r
+                               tests[hits].ST = false;\r
                                ++hits;\r
                        }\r
                }\r
@@ -578,45 +578,45 @@ bool tryDetectModulation(){
                // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
                save_restoreGB(1);\r
                CmdLtrim("160");\r
-               clk = GetPskClock("", FALSE, FALSE);\r
+               clk = GetPskClock("", false, false);\r
                if (clk>0) {\r
-                       if ( PSKDemod("0 0 6", 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].inverted = false;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
-                               tests[hits].ST = FALSE;\r
+                               tests[hits].ST = false;\r
                                ++hits;\r
                        }\r
-                       if ( PSKDemod("0 1 6", 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].inverted = true;\r
                                tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
-                               tests[hits].ST = FALSE;\r
+                               tests[hits].ST = false;\r
                                ++hits;\r
                        }\r
                        // PSK2 - needs a call to psk1TOpsk2.\r
-                       if ( PSKDemod("0 0 6", 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
                                        tests[hits].bitrate = bitRate;\r
-                                       tests[hits].inverted = FALSE;\r
+                                       tests[hits].inverted = false;\r
                                        tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
-                                       tests[hits].ST = FALSE;\r
+                                       tests[hits].ST = false;\r
                                        ++hits;\r
                                }\r
                        } // inverse waves does not affect this demod\r
                        // PSK3 - needs a call to psk1TOpsk2.\r
-                       if ( PSKDemod("0 0 6", 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
                                        tests[hits].bitrate = bitRate;\r
-                                       tests[hits].inverted = FALSE;\r
+                                       tests[hits].inverted = false;\r
                                        tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
-                                       tests[hits].ST = FALSE;\r
+                                       tests[hits].ST = false;\r
                                        ++hits;\r
                                }\r
                        } // inverse waves does not affect this demod\r
@@ -633,7 +633,7 @@ bool tryDetectModulation(){
                config.Q5 = tests[0].Q5;\r
                config.ST = tests[0].ST;\r
                printConfiguration( config );\r
-               return TRUE;\r
+               return true;\r
        }\r
        \r
        if ( hits > 1) {\r
@@ -643,68 +643,68 @@ bool tryDetectModulation(){
                        printConfiguration( tests[i] );\r
                }\r
        }\r
-       return FALSE;\r
+       return false;\r
 }\r
 \r
 bool testModulation(uint8_t mode, uint8_t modread){\r
        switch( mode ){\r
                case DEMOD_FSK:\r
-                       if (modread >= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return TRUE;\r
+                       if (modread >= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return true;\r
                        break;\r
                case DEMOD_ASK:\r
-                       if (modread == DEMOD_ASK) return TRUE;\r
+                       if (modread == DEMOD_ASK) return true;\r
                        break;\r
                case DEMOD_PSK1:\r
-                       if (modread == DEMOD_PSK1) return TRUE;\r
+                       if (modread == DEMOD_PSK1) return true;\r
                        break;\r
                case DEMOD_PSK2:\r
-                       if (modread == DEMOD_PSK2) return TRUE;\r
+                       if (modread == DEMOD_PSK2) return true;\r
                        break;\r
                case DEMOD_PSK3:\r
-                       if (modread == DEMOD_PSK3) return TRUE;\r
+                       if (modread == DEMOD_PSK3) return true;\r
                        break;\r
                case DEMOD_NRZ:\r
-                       if (modread == DEMOD_NRZ) return TRUE;\r
+                       if (modread == DEMOD_NRZ) return true;\r
                        break;\r
                case DEMOD_BI:\r
-                       if (modread == DEMOD_BI) return TRUE;\r
+                       if (modread == DEMOD_BI) return true;\r
                        break;\r
                case DEMOD_BIa:\r
-                       if (modread == DEMOD_BIa) return TRUE;\r
+                       if (modread == DEMOD_BIa) return true;\r
                        break;          \r
                default:\r
-                       return FALSE;\r
+                       return false;\r
        }\r
-       return FALSE;\r
+       return false;\r
 }\r
 \r
 bool testQ5Modulation(uint8_t  mode, uint8_t   modread){\r
        switch( mode ){\r
                case DEMOD_FSK:\r
-                       if (modread >= 4 && modread <= 5) return TRUE;\r
+                       if (modread >= 4 && modread <= 5) return true;\r
                        break;\r
                case DEMOD_ASK:\r
-                       if (modread == 0) return TRUE;\r
+                       if (modread == 0) return true;\r
                        break;\r
                case DEMOD_PSK1:\r
-                       if (modread == 1) return TRUE;\r
+                       if (modread == 1) return true;\r
                        break;\r
                case DEMOD_PSK2:\r
-                       if (modread == 2) return TRUE;\r
+                       if (modread == 2) return true;\r
                        break;\r
                case DEMOD_PSK3:\r
-                       if (modread == 3) return TRUE;\r
+                       if (modread == 3) return true;\r
                        break;\r
                case DEMOD_NRZ:\r
-                       if (modread == 7) return TRUE;\r
+                       if (modread == 7) return true;\r
                        break;\r
                case DEMOD_BI:\r
-                       if (modread == 6) return TRUE;\r
+                       if (modread == 6) return true;\r
                        break;\r
                default:\r
-                       return FALSE;\r
+                       return false;\r
        }\r
-       return FALSE;\r
+       return false;\r
 }\r
 \r
 int convertQ5bitRate(uint8_t bitRateRead) {\r
@@ -718,7 +718,7 @@ int convertQ5bitRate(uint8_t bitRateRead) {
 \r
 bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t    clk){\r
 \r
-       if ( DemodBufferLen < 64 ) return FALSE;\r
+       if ( DemodBufferLen < 64 ) return false;\r
        uint8_t si = 0;\r
        for (uint8_t idx = 28; idx < 64; idx++){\r
                si = idx;\r
@@ -751,9 +751,9 @@ bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){
                if (*fndBitRate < 0) continue;\r
                *offset = idx;\r
 \r
-               return TRUE;\r
+               return true;\r
        }\r
-       return FALSE;\r
+       return false;\r
 }\r
 \r
 bool testBitRate(uint8_t readRate, uint8_t clk){\r
@@ -766,7 +766,7 @@ bool testBitRate(uint8_t readRate, uint8_t clk){
 \r
 bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5){\r
 \r
-       if ( DemodBufferLen < 64 ) return FALSE;\r
+       if ( DemodBufferLen < 64 ) return false;\r
        uint8_t si = 0;\r
        for (uint8_t idx = 28; idx < 64; idx++){\r
                si = idx;\r
@@ -788,7 +788,7 @@ bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5)
                //uint8_t nml02    = PackBits(si, 2, DemodBuffer); si += 2;\r
                \r
                //if extended mode\r
-               bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? TRUE : FALSE;\r
+               bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? true : false;\r
 \r
                if (!extMode){\r
                        if (xtRate) continue;  //nml01 || nml02 ||  caused issues on noralys tags\r
@@ -798,14 +798,14 @@ bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5)
                if (!testBitRate(bitRate, clk)) continue;\r
                *fndBitRate = bitRate;\r
                *offset = idx;\r
-               *Q5 = FALSE;\r
-               return TRUE;\r
+               *Q5 = false;\r
+               return true;\r
        }\r
        if (testQ5(mode, offset, fndBitRate, clk)) {\r
-               *Q5 = TRUE;\r
-               return TRUE;\r
+               *Q5 = true;\r
+               return true;\r
        }\r
-       return FALSE;\r
+       return false;\r
 }\r
 \r
 void printT55xxBlock(const char *blockNum){\r
@@ -1471,7 +1471,7 @@ int CmdT55xxBruteForce(const char *Cmd) {
 \r
                        PrintAndLog("Testing %08X", testpwd);\r
 \r
-                       if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, testpwd)) {\r
+                       if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, testpwd)) {\r
                                PrintAndLog("Aquireing data from device failed. Quitting");\r
                                free(keyBlock);\r
                                return 0;\r
@@ -1516,7 +1516,7 @@ int CmdT55xxBruteForce(const char *Cmd) {
                        return 0;\r
                }\r
 \r
-               if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, i)) {\r
+               if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, i)) {\r
                        PrintAndLog("Aquireing data from device failed. Quitting");\r
                        free(keyBlock);\r
                        return 0;\r
index 500320ee4fd474ab486dd3429e57868f77adcdb1..0de3f39224ce898d172486c746f0089403081fdf 100644 (file)
 #ifndef CMDMAIN_H__
 #define CMDMAIN_H__
 
+#include <stdint.h>
+#include <stddef.h>
 #include "usb_cmd.h"
 #include "cmdparser.h"
-void UsbCommandReceived(UsbCommand *UC);
-int CommandReceived(char *Cmd);
-bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout);
-bool WaitForResponse(uint32_t cmd, UsbCommand* response);
-void clearCommandBuffer();
-command_t* getTopLevelCommandTable();
+
+extern void UsbCommandReceived(UsbCommand *UC);
+extern int CommandReceived(char *Cmd);
+extern bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout);
+extern bool WaitForResponse(uint32_t cmd, UsbCommand* response);
+extern void clearCommandBuffer();
+extern command_t* getTopLevelCommandTable();
+
 #endif
index 4abb1137c41d0baf045f2d5e8fed9109cedb7873..5e0f47603f2498521b1cad4ab7e0aebb2f2522d7 100644 (file)
 #include <stdlib.h> \r
 #include <string.h>\r
 #include <pthread.h>\r
-#include "mifarehost.h"\r
+\r
+#include "nonce2key/crapto1.h"\r
 #include "proxmark3.h"\r
+#include "usb_cmd.h"\r
+#include "cmdmain.h"\r
+#include "ui.h"\r
+#include "util.h"\r
+#include "iso14443crc.h"\r
+#include "mifarehost.h"\r
+\r
+// mifare tracer flags used in mfTraceDecode()\r
+#define TRACE_IDLE                                             0x00\r
+#define TRACE_AUTH1                                            0x01\r
+#define TRACE_AUTH2                                            0x02\r
+#define TRACE_AUTH_OK                                  0x03\r
+#define TRACE_READ_DATA                                0x04\r
+#define TRACE_WRITE_OK                                 0x05\r
+#define TRACE_WRITE_DATA                               0x06\r
+#define TRACE_ERROR                                            0xFF\r
+\r
 \r
 // MIFARE\r
+int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){\r
+\r
+       *key = 0;\r
+\r
+       UsbCommand c = {CMD_MIFARE_CHKKEYS, {((blockNo & 0xff) | ((keyType&0xff)<<8)), clear_trace, keycnt}};\r
+       memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
+       SendCommand(&c);\r
+\r
+       UsbCommand resp;\r
+       if (!WaitForResponseTimeout(CMD_ACK,&resp,3000)) return 1;\r
+       if ((resp.arg[0] & 0xff) != 0x01) return 2;\r
+       *key = bytes_to_num(resp.d.asBytes, 6);\r
+       return 0;\r
+}\r
+\r
 int compar_int(const void * a, const void * b) {\r
        // didn't work: (the result is truncated to 32 bits)\r
        //return (*(uint64_t*)b - *(uint64_t*)a);\r
@@ -193,21 +226,6 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo
        return 0;\r
 }\r
 \r
-int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){\r
-\r
-       *key = 0;\r
-\r
-       UsbCommand c = {CMD_MIFARE_CHKKEYS, {((blockNo & 0xff) | ((keyType&0xff)<<8)), clear_trace, keycnt}};\r
-       memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
-       SendCommand(&c);\r
-\r
-       UsbCommand resp;\r
-       if (!WaitForResponseTimeout(CMD_ACK,&resp,3000)) return 1;\r
-       if ((resp.arg[0] & 0xff) != 0x01) return 2;\r
-       *key = bytes_to_num(resp.d.asBytes, 6);\r
-       return 0;\r
-}\r
-\r
 // EMULATOR\r
 \r
 int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {\r
@@ -229,32 +247,22 @@ int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount) {
 \r
 // "MAGIC" CARD\r
 \r
-int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, bool wantWipe) {\r
-       uint8_t oldblock0[16] = {0x00};\r
-       uint8_t block0[16] = {0x00};\r
+int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {\r
+       uint8_t isOK = 0;\r
 \r
-       int old = mfCGetBlock(0, oldblock0, CSETBLOCK_SINGLE_OPER);\r
-       if (old == 0) {\r
-               memcpy(block0, oldblock0, 16);\r
-               PrintAndLog("old block 0:  %s", sprint_hex(block0,16));\r
-       } else {\r
-               PrintAndLog("Couldn't get old data. Will write over the last bytes of Block 0.");\r
-       }\r
+       UsbCommand c = {CMD_MIFARE_CGETBLOCK, {params, 0, blockNo}};\r
+       SendCommand(&c);\r
 \r
-       // fill in the new values\r
-       // UID\r
-       memcpy(block0, uid, 4); \r
-       // Mifare UID BCC\r
-       block0[4] = block0[0]^block0[1]^block0[2]^block0[3];\r
-       // mifare classic SAK(byte 5) and ATQA(byte 6 and 7, reversed)\r
-       if (sak!=NULL)\r
-               block0[5]=sak[0];\r
-       if (atqa!=NULL) {\r
-               block0[6]=atqa[1];\r
-               block0[7]=atqa[0];\r
+  UsbCommand resp;\r
+       if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
+               isOK  = resp.arg[0] & 0xff;\r
+               memcpy(data, resp.d.asBytes, 16);\r
+               if (!isOK) return 2;\r
+       } else {\r
+               PrintAndLog("Command execute timeout");\r
+               return 1;\r
        }\r
-       PrintAndLog("new block 0:  %s", sprint_hex(block0,16));\r
-       return mfCSetBlock(0, block0, oldUID, wantWipe, CSETBLOCK_SINGLE_OPER);\r
+       return 0;\r
 }\r
 \r
 int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uint8_t params) {\r
@@ -278,22 +286,32 @@ int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uin
        return 0;\r
 }\r
 \r
-int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {\r
-       uint8_t isOK = 0;\r
-\r
-       UsbCommand c = {CMD_MIFARE_CGETBLOCK, {params, 0, blockNo}};\r
-       SendCommand(&c);\r
+int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, bool wantWipe) {\r
+       uint8_t oldblock0[16] = {0x00};\r
+       uint8_t block0[16] = {0x00};\r
 \r
-  UsbCommand resp;\r
-       if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
-               isOK  = resp.arg[0] & 0xff;\r
-               memcpy(data, resp.d.asBytes, 16);\r
-               if (!isOK) return 2;\r
+       int old = mfCGetBlock(0, oldblock0, CSETBLOCK_SINGLE_OPER);\r
+       if (old == 0) {\r
+               memcpy(block0, oldblock0, 16);\r
+               PrintAndLog("old block 0:  %s", sprint_hex(block0,16));\r
        } else {\r
-               PrintAndLog("Command execute timeout");\r
-               return 1;\r
+               PrintAndLog("Couldn't get old data. Will write over the last bytes of Block 0.");\r
        }\r
-       return 0;\r
+\r
+       // fill in the new values\r
+       // UID\r
+       memcpy(block0, uid, 4); \r
+       // Mifare UID BCC\r
+       block0[4] = block0[0]^block0[1]^block0[2]^block0[3];\r
+       // mifare classic SAK(byte 5) and ATQA(byte 6 and 7, reversed)\r
+       if (sak!=NULL)\r
+               block0[5]=sak[0];\r
+       if (atqa!=NULL) {\r
+               block0[6]=atqa[1];\r
+               block0[7]=atqa[0];\r
+       }\r
+       PrintAndLog("new block 0:  %s", sprint_hex(block0,16));\r
+       return mfCSetBlock(0, block0, oldUID, wantWipe, CSETBLOCK_SINGLE_OPER);\r
 }\r
 \r
 // SNIFFER\r
@@ -337,6 +355,23 @@ int isBlockTrailer(int blockN) {
  return ((blockN & 0x03) == 0x03);\r
 }\r
 \r
+int saveTraceCard(void) {\r
+       FILE * f;\r
+       \r
+       if ((!strlen(traceFileName)) || (isTraceCardEmpty())) return 0;\r
+       \r
+       f = fopen(traceFileName, "w+");\r
+       if ( !f ) return 1;\r
+       \r
+       for (int i = 0; i < 64; i++) {  // blocks\r
+               for (int j = 0; j < 16; j++)  // bytes\r
+                       fprintf(f, "%02x", *(traceCard + i * 16 + j)); \r
+               fprintf(f,"\n");\r
+       }\r
+       fclose(f);\r
+       return 0;\r
+}\r
+\r
 int loadTraceCard(uint8_t *tuid) {\r
        FILE * f;\r
        char buf[64] = {0x00};\r
@@ -383,23 +418,6 @@ int loadTraceCard(uint8_t *tuid) {
        return 0;\r
 }\r
 \r
-int saveTraceCard(void) {\r
-       FILE * f;\r
-       \r
-       if ((!strlen(traceFileName)) || (isTraceCardEmpty())) return 0;\r
-       \r
-       f = fopen(traceFileName, "w+");\r
-       if ( !f ) return 1;\r
-       \r
-       for (int i = 0; i < 64; i++) {  // blocks\r
-               for (int j = 0; j < 16; j++)  // bytes\r
-                       fprintf(f, "%02x", *(traceCard + i * 16 + j)); \r
-               fprintf(f,"\n");\r
-       }\r
-       fclose(f);\r
-       return 0;\r
-}\r
-\r
 int mfTraceInit(uint8_t *tuid, uint8_t *atqa, uint8_t sak, bool wantSaveToEmlFile) {\r
 \r
        if (traceCrypto1) \r
index 9ccb8960ffb0cfb353caa6998ef376010739f108..e628ba3ab0ba9d2c51abf9ca3004e8acdc848d32 100644 (file)
@@ -8,63 +8,36 @@
 // High frequency ISO14443A commands\r
 //-----------------------------------------------------------------------------\r
 \r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <unistd.h>\r
-#include "common.h"\r
-#include "cmdmain.h"\r
-#include "ui.h"\r
+#include <stdint.h>\r
+#include <stdbool.h>\r
 #include "data.h"\r
-#include "util.h"\r
-#include "nonce2key/nonce2key.h"\r
-#include "nonce2key/crapto1.h"\r
-#include "iso14443crc.h"\r
-\r
-#define MEM_CHUNK               1000000\r
-#define NESTED_SECTOR_RETRY     10\r
 \r
 // mfCSetBlock work flags\r
 #define CSETBLOCK_UID                                  0x01\r
 #define CSETBLOCK_WUPC                                 0x02\r
 #define CSETBLOCK_HALT                                 0x04\r
-#define CSETBLOCK_INIT_FIELD           0x08\r
-#define CSETBLOCK_RESET_FIELD          0x10\r
-#define CSETBLOCK_SINGLE_OPER          0x1F\r
-\r
-// mifare tracer flags\r
-#define TRACE_IDLE                                                     0x00\r
-#define TRACE_AUTH1                                                    0x01\r
-#define TRACE_AUTH2                                                    0x02\r
-#define TRACE_AUTH_OK                                          0x03\r
-#define TRACE_READ_DATA                                0x04\r
-#define TRACE_WRITE_OK                                 0x05\r
-#define TRACE_WRITE_DATA                               0x06\r
-\r
-#define TRACE_ERROR                                                    0xFF\r
+#define CSETBLOCK_INIT_FIELD                   0x08\r
+#define CSETBLOCK_RESET_FIELD                  0x10\r
+#define CSETBLOCK_SINGLE_OPER                  0x1F\r
 \r
-typedef struct {\r
-       uint64_t Key[2];\r
-       int foundKey[2];\r
-} sector;\r
\r
 extern char logHexFileName[FILE_PATH_SIZE];\r
 \r
-int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t * ResultKeys, bool calibrate);\r
-int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key);\r
+extern int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t * ResultKeys, bool calibrate);\r
+extern int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key);\r
 \r
-int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount);\r
-int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount);\r
+extern int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount);\r
+extern int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount);\r
 \r
-int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, bool wantWipe);\r
-int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uint8_t params);\r
-int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params);\r
+extern int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, bool wantWipe);\r
+extern int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uint8_t params);\r
+extern int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params);\r
 \r
-int mfTraceInit(uint8_t *tuid, uint8_t *atqa, uint8_t sak, bool wantSaveToEmlFile);\r
-int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile);\r
+extern int mfTraceInit(uint8_t *tuid, uint8_t *atqa, uint8_t sak, bool wantSaveToEmlFile);\r
+extern int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile);\r
 \r
-int isTraceCardEmpty(void);\r
-int isBlockEmpty(int blockN);\r
-int isBlockTrailer(int blockN);\r
-int loadTraceCard(uint8_t *tuid);\r
-int saveTraceCard(void);\r
-int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data, int len);\r
+extern int isTraceCardEmpty(void);\r
+extern int isBlockEmpty(int blockN);\r
+extern int isBlockTrailer(int blockN);\r
+extern int loadTraceCard(uint8_t *tuid);\r
+extern int saveTraceCard(void);\r
+extern int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data, int len);\r
index 2c47bc50213dcf767f9d12d342df1c0945082e62..a6b33e9360d3c705b7790c30d3573f4f8090f020 100644 (file)
 // MIFARE Darkside hack
 //-----------------------------------------------------------------------------
 
-#define __STDC_FORMAT_MACROS
 #include <inttypes.h>
+#include <time.h>
 
 #include "nonce2key.h"
 #include "mifarehost.h"
 #include "ui.h"
+#include "util.h"
 
 int compar_state(const void * a, const void * b) {
        // didn't work: (the result is truncated to 32 bits)
@@ -161,7 +162,7 @@ bool mfkey32(nonces_t data, uint64_t *outputkey) {
        uint32_t nr1_enc = data.nr2; // second encrypted reader challenge
        uint32_t ar1_enc = data.ar2; // second encrypted reader response
        clock_t t1 = clock();
-       bool isSuccess = FALSE;
+       bool isSuccess = false;
        uint8_t counter=0;
 
        s = lfsr_recovery32(ar0_enc ^ prng_successor(nt, 64), 0);
@@ -208,7 +209,7 @@ bool tryMfk32_moebius(nonces_t data, uint64_t *outputkey) {
        uint32_t nt1     = data.nonce2; // second tag challenge (nonce)
        uint32_t nr1_enc = data.nr2; // second encrypted reader challenge
        uint32_t ar1_enc = data.ar2; // second encrypted reader response        
-       bool isSuccess = FALSE;
+       bool isSuccess = false;
        int counter = 0;
        
        //PrintAndLog("Enter mfkey32_moebius");
index fde065400c7c2c3a885a1099cd1c6ccbc20cd1b7..7d9943f0616aa333ff0810ed0666219a74a1c710 100644 (file)
@@ -25,8 +25,6 @@
 #ifndef MAX
 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
 #endif
-#define TRUE                        1
-#define FALSE                       0
 #define EVEN                        0
 #define ODD                         1
 
index 7c09894f512f46e0020d2a2bad247f55968c4bfa..6e5e85f39c52e1e5bc4d8019f6c8519a2862e717 100644 (file)
@@ -261,7 +261,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
       if (!fgets(buffer, sizeof(buffer), maps))
         break;
 
-      if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8)
+      if (sscanf(buffer, "%" SCNx64 "-%" SCNx64 " %s %" SCNx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8)
       {
         uint64_t addr = (uint64_t)(uintptr_t)WAI_RETURN_ADDRESS();
         if (low <= addr && addr <= high)
Impressum, Datenschutz