diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 774cdf58d..c0e465653 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -250,20 +250,20 @@ int CmdAWIDDemod(const char *Cmd) { int waveIdx = 0; int idx = detectAWID(bits, &size, &waveIdx); if (idx <= 0){ - if (g_debugMode){ - if (idx == -1) - PrintAndLogEx(DEBUG, "DEBUG: Error - AWID not enough samples"); - else if (idx == -2) - PrintAndLogEx(DEBUG, "DEBUG: Error - AWID only noise found"); - else if (idx == -3) - PrintAndLogEx(DEBUG, "DEBUG: Error - AWID problem during FSK demod"); - else if (idx == -4) - PrintAndLogEx(DEBUG, "DEBUG: Error - AWID preamble not found"); - else if (idx == -5) - PrintAndLogEx(DEBUG, "DEBUG: Error - AWID size not correct, size %d", size); - else - PrintAndLogEx(DEBUG, "DEBUG: Error - AWID error demoding fsk %d",idx); - } + + if (idx == -1) + PrintAndLogEx(DEBUG, "DEBUG: Error - AWID not enough samples"); + else if (idx == -2) + PrintAndLogEx(DEBUG, "DEBUG: Error - AWID only noise found"); + else if (idx == -3) + PrintAndLogEx(DEBUG, "DEBUG: Error - AWID problem during FSK demod"); + else if (idx == -4) + PrintAndLogEx(DEBUG, "DEBUG: Error - AWID preamble not found"); + else if (idx == -5) + PrintAndLogEx(DEBUG, "DEBUG: Error - AWID size not correct, size %d", size); + else + PrintAndLogEx(DEBUG, "DEBUG: Error - AWID error demoding fsk %d",idx); + return 0; } diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index b4af9be7b..d19e09d34 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -363,18 +363,18 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) { int ans = Em410xDecode(bits, &size, &idx, hi, lo); if ( ans < 0){ - if (g_debugMode){ - if (ans == -1) - PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x not only 0|1 in decoded bitstream"); - else if (ans == -2) - PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x not enough samples after demod"); - else if (ans == -4) - PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x preamble not found"); - else if (ans == -5) - PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x Size not correct: %d", size); - else if (ans == -6) - PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x parity failed"); - } + + if (ans == -1) + PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x not only 0|1 in decoded bitstream"); + else if (ans == -2) + PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x not enough samples after demod"); + else if (ans == -4) + PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x preamble not found"); + else if (ans == -5) + PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x Size not correct: %d", size); + else if (ans == -6) + PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x parity failed"); + return 0; } if (!lo && !hi) { @@ -385,10 +385,10 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) { //set GraphBuffer for clone or sim command setDemodBuf(DemodBuffer, (size==40) ? 64 : 128, idx+1); setClockGrid(g_DemodClock, g_DemodStartIdx + ((idx+1)*g_DemodClock)); - if (g_debugMode){ - PrintAndLogEx(DEBUG, "DEBUG: Em410x idx: %d, Len: %d, Printing Demod Buffer:", idx, size); + + PrintAndLogEx(DEBUG, "DEBUG: Em410x idx: %d, Len: %d, Printing Demod Buffer:", idx, size); + if (g_debugMode) printDemodBuff(); - } if (verbose) printEM410x(*hi, *lo); @@ -1009,7 +1009,7 @@ bool doPreambleSearch(size_t *startIdx){ // sanity check if ( DemodBufferLen < EM_PREAMBLE_LEN) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM4305 demodbuffer too small"); + PrintAndLogEx(DEBUG, "DEBUG: Error - EM4305 demodbuffer too small"); return false; } @@ -1020,7 +1020,7 @@ bool doPreambleSearch(size_t *startIdx){ uint8_t preamble[EM_PREAMBLE_LEN] = {0,0,1,0,1,0}; if ( !preambleSearchEx(DemodBuffer, preamble, EM_PREAMBLE_LEN, &size, startIdx, true)) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM4305 preamble not found :: %d", *startIdx); + PrintAndLogEx(DEBUG, "DEBUG: Error - EM4305 preamble not found :: %d", *startIdx); return false; } return true; @@ -1029,13 +1029,13 @@ bool doPreambleSearch(size_t *startIdx){ bool detectFSK(){ // detect fsk clock if (!GetFskClock("", false)) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK clock failed"); + PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK clock failed"); return false; } // demod int ans = FSKrawDemod("0 0", false); if (!ans) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK Demod failed"); + PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK Demod failed"); return false; } return true; @@ -1044,19 +1044,19 @@ bool detectFSK(){ bool detectPSK(){ int ans = GetPskClock("", false); if (ans <= 0) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK clock failed"); + PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK clock failed"); return false; } //demod //try psk1 -- 0 0 6 (six errors?!?) ans = PSKDemod("0 0 6", false); if (!ans) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK1 Demod failed"); + PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK1 Demod failed"); //try psk1 inverted ans = PSKDemod("0 1 6", false); if (!ans) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK1 inverted Demod failed"); + PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK1 inverted Demod failed"); return false; } } @@ -1068,7 +1068,7 @@ bool detectPSK(){ bool detectASK_MAN(){ bool stcheck = false; if ( !ASKDemod_ext("0 0 0", false, false, 1, &stcheck) ) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: ASK/Manchester Demod failed"); + PrintAndLogEx(DEBUG, "DEBUG: Error - EM: ASK/Manchester Demod failed"); return false; } return true; @@ -1094,13 +1094,13 @@ bool setDemodBufferEM(uint32_t *word, size_t idx){ uint8_t parity[45] = {0}; memcpy( parity, DemodBuffer, 45); if (!EMwordparitytest(parity) ){ - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM Parity tests failed"); + PrintAndLogEx(DEBUG, "DEBUG: Error - EM Parity tests failed"); return false; } // test for even parity bits and remove them. (leave out the end row of parities so 36 bits) if (!removeParity(DemodBuffer, idx + EM_PREAMBLE_LEN, 9, 0, 36)) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM, failed removing parity"); + PrintAndLogEx(DEBUG, "DEBUG: Error - EM, failed removing parity"); return false; } setDemodBuf(DemodBuffer, 32, 0); diff --git a/client/cmdlffdx.c b/client/cmdlffdx.c index 8686c747d..c2b54b497 100644 --- a/client/cmdlffdx.c +++ b/client/cmdlffdx.c @@ -168,23 +168,23 @@ int CmdFDXBdemodBI(const char *Cmd){ errCnt = askdemod(BitStream, &size, &clk, &invert, maxErr, 0, 0); if ( errCnt < 0 || errCnt > maxErr ) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB no data or error found %d, clock: %d", errCnt, clk); + PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB no data or error found %d, clock: %d", errCnt, clk); return 0; } errCnt = BiphaseRawDecode(BitStream, &size, &offset, 1); if (errCnt < 0 || errCnt > maxErr ) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB BiphaseRawDecode: %d", errCnt); + PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB BiphaseRawDecode: %d", errCnt); return 0; } int preambleIndex = detectFDXB(BitStream, &size); if (preambleIndex < 0){ - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB preamble not found :: %d",preambleIndex); + PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB preamble not found :: %d",preambleIndex); return 0; } if (size != 128) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB incorrect data length found"); + PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB incorrect data length found"); return 0; } @@ -193,7 +193,7 @@ int CmdFDXBdemodBI(const char *Cmd){ // remove marker bits (1's every 9th digit after preamble) (pType = 2) size = removeParity(BitStream, preambleIndex + 11, 9, 2, 117); if ( size != 104 ) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB error removeParity:: %d", size); + PrintAndLogEx(DEBUG, "DEBUG: Error - FDXB error removeParity:: %d", size); return 0; } PrintAndLogEx(NORMAL, "\nFDX-B / ISO 11784/5 Animal Tag ID Found:"); @@ -211,7 +211,7 @@ int CmdFDXBdemodBI(const char *Cmd){ uint8_t raw[8]; num_to_bytes(rawid, 8, raw); - if (g_debugMode) PrintAndLogEx(NORMAL, "Raw ID Hex: %s", sprint_hex(raw,8)); + PrintAndLogEx(NORMAL, "Raw ID Hex: %s", sprint_hex(raw,8)); uint16_t calcCrc = crc16_kermit(raw, 8); PrintAndLogEx(NORMAL, "Animal ID: %04u-%012" PRIu64, countryCode, NationalCode); @@ -224,7 +224,7 @@ int CmdFDXBdemodBI(const char *Cmd){ PrintAndLogEx(NORMAL, "CRC: 0x%04X - [%04X] - %s", crc16, calcCrc, (calcCrc == crc16) ? "Passed" : "Failed"); if (g_debugMode) { - PrintAndLogEx(NORMAL, "Start marker %d; Size %d", preambleIndex, size); + PrintAndLogEx(DEBUG, "Start marker %d; Size %d", preambleIndex, size); char *bin = sprint_bin_break(BitStream,size,16); PrintAndLogEx(DEBUG, "DEBUG BinStream:\n%s",bin); } @@ -239,22 +239,21 @@ int CmdFdxDemod(const char *Cmd) { //Differential Biphase / di-phase (inverted biphase) //get binary from ask wave if (!ASKbiphaseDemod("0 32 1 0", false)) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B ASKbiphaseDemod failed"); + PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B ASKbiphaseDemod failed"); return 0; } size_t size = DemodBufferLen; int preambleIndex = detectFDXB(DemodBuffer, &size); if (preambleIndex < 0){ - if (g_debugMode){ - if (preambleIndex == -1) - PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B too few bits found"); - else if (preambleIndex == -2) - PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B preamble not found"); - else if (preambleIndex == -3) - PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B Size not correct: %d", size); - else - PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B ans: %d", preambleIndex); - } + + if (preambleIndex == -1) + PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B too few bits found"); + else if (preambleIndex == -2) + PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B preamble not found"); + else if (preambleIndex == -3) + PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B Size not correct: %d", size); + else + PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B ans: %d", preambleIndex); return 0; } @@ -264,7 +263,7 @@ int CmdFdxDemod(const char *Cmd) { // remove marker bits (1's every 9th digit after preamble) (pType = 2) size = removeParity(DemodBuffer, 11, 9, 2, 117); if ( size != 104 ) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B error removeParity: %d", size); + PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B error removeParity: %d", size); return 0; } @@ -293,7 +292,7 @@ int CmdFdxDemod(const char *Cmd) { PrintAndLogEx(NORMAL, "CRC-16 0x%04X - 0x%04X [%s]", crc16, calcCrc, (calcCrc == crc16) ? "Ok" : "Failed"); if (g_debugMode) { - PrintAndLogEx(NORMAL, "Start marker %d; Size %d", preambleIndex, size); + PrintAndLogEx(DEBUG, "Start marker %d; Size %d", preambleIndex, size); char *bin = sprint_bin_break(DemodBuffer, size, 16); PrintAndLogEx(DEBUG, "DEBUG bin stream:\n%s", bin); } diff --git a/client/cmdlfguard.c b/client/cmdlfguard.c index 2bdd6f398..ea97d6f77 100644 --- a/client/cmdlfguard.c +++ b/client/cmdlfguard.c @@ -177,7 +177,7 @@ int CmdGuardDemod(const char *Cmd) { //Differential Biphase //get binary from ask wave if (!ASKbiphaseDemod("0 64 0 0", false)) { - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII ASKbiphaseDemod failed"); + PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII ASKbiphaseDemod failed"); return 0; } @@ -185,18 +185,17 @@ int CmdGuardDemod(const char *Cmd) { int preambleIndex = detectGProxII(DemodBuffer, &size); if (preambleIndex < 0){ - if (g_debugMode){ - if (preambleIndex == -1) - PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII too few bits found"); - else if (preambleIndex == -2) - PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII preamble not found"); - else if (preambleIndex == -3) - PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII size not correct: %d", size); - else if (preambleIndex == -3) - PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII wrong spacerbits"); - else - PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII ans: %d", preambleIndex); - } + + if (preambleIndex == -1) + PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII too few bits found"); + else if (preambleIndex == -2) + PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII preamble not found"); + else if (preambleIndex == -3) + PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII size not correct: %d", size); + else if (preambleIndex == -3) + PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII wrong spacerbits"); + else + PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII ans: %d", preambleIndex); return 0; } @@ -211,15 +210,14 @@ int CmdGuardDemod(const char *Cmd) { // remove the 18 (90/5=18) parity bits (down to 72 bits (96-6-18=72)) size_t len = removeParity(bits_no_spacer, 0, 5, 3, 90); //source, startloc, paritylen, ptype, length_to_run if (len != 72) { - if (g_debugMode) - PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII spacer removal did not produce 72 bits: %u, start: %u", len, startIdx); + PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII spacer removal did not produce 72 bits: %u, start: %u", len, startIdx); return 0; } // get key and then get all 8 bytes of payload decoded xorKey = (uint8_t)bytebits_to_byteLSBF(bits_no_spacer, 8); for (size_t idx = 0; idx < 8; idx++) { ByteStream[idx] = ((uint8_t)bytebits_to_byteLSBF(bits_no_spacer+8 + (idx*8),8)) ^ xorKey; - if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: gProxII byte %u after xor: %02x", (unsigned int)idx, ByteStream[idx]); + PrintAndLogEx(DEBUG, "DEBUG: gProxII byte %u after xor: %02x", (unsigned int)idx, ByteStream[idx]); } setDemodBuf(DemodBuffer, 96, preambleIndex);