simpler debug printing

This commit is contained in:
iceman1001 2018-02-21 16:36:40 +01:00
commit 555b261eab
4 changed files with 72 additions and 75 deletions

View file

@ -250,20 +250,20 @@ int CmdAWIDDemod(const char *Cmd) {
int waveIdx = 0; int waveIdx = 0;
int idx = detectAWID(bits, &size, &waveIdx); int idx = detectAWID(bits, &size, &waveIdx);
if (idx <= 0){ if (idx <= 0){
if (g_debugMode){
if (idx == -1) if (idx == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID not enough samples"); PrintAndLogEx(DEBUG, "DEBUG: Error - AWID not enough samples");
else if (idx == -2) else if (idx == -2)
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID only noise found"); PrintAndLogEx(DEBUG, "DEBUG: Error - AWID only noise found");
else if (idx == -3) else if (idx == -3)
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID problem during FSK demod"); PrintAndLogEx(DEBUG, "DEBUG: Error - AWID problem during FSK demod");
else if (idx == -4) else if (idx == -4)
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID preamble not found"); PrintAndLogEx(DEBUG, "DEBUG: Error - AWID preamble not found");
else if (idx == -5) else if (idx == -5)
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID size not correct, size %d", size); PrintAndLogEx(DEBUG, "DEBUG: Error - AWID size not correct, size %d", size);
else else
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID error demoding fsk %d",idx); PrintAndLogEx(DEBUG, "DEBUG: Error - AWID error demoding fsk %d",idx);
}
return 0; return 0;
} }

View file

@ -363,18 +363,18 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) {
int ans = Em410xDecode(bits, &size, &idx, hi, lo); int ans = Em410xDecode(bits, &size, &idx, hi, lo);
if ( ans < 0){ if ( ans < 0){
if (g_debugMode){
if (ans == -1) if (ans == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x not only 0|1 in decoded bitstream"); PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x not only 0|1 in decoded bitstream");
else if (ans == -2) else if (ans == -2)
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x not enough samples after demod"); PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x not enough samples after demod");
else if (ans == -4) else if (ans == -4)
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x preamble not found"); PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x preamble not found");
else if (ans == -5) else if (ans == -5)
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x Size not correct: %d", size); PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x Size not correct: %d", size);
else if (ans == -6) else if (ans == -6)
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x parity failed"); PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x parity failed");
}
return 0; return 0;
} }
if (!lo && !hi) { if (!lo && !hi) {
@ -385,10 +385,10 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) {
//set GraphBuffer for clone or sim command //set GraphBuffer for clone or sim command
setDemodBuf(DemodBuffer, (size==40) ? 64 : 128, idx+1); setDemodBuf(DemodBuffer, (size==40) ? 64 : 128, idx+1);
setClockGrid(g_DemodClock, g_DemodStartIdx + ((idx+1)*g_DemodClock)); 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(); printDemodBuff();
}
if (verbose) if (verbose)
printEM410x(*hi, *lo); printEM410x(*hi, *lo);
@ -1009,7 +1009,7 @@ bool doPreambleSearch(size_t *startIdx){
// sanity check // sanity check
if ( DemodBufferLen < EM_PREAMBLE_LEN) { 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; return false;
} }
@ -1020,7 +1020,7 @@ bool doPreambleSearch(size_t *startIdx){
uint8_t preamble[EM_PREAMBLE_LEN] = {0,0,1,0,1,0}; uint8_t preamble[EM_PREAMBLE_LEN] = {0,0,1,0,1,0};
if ( !preambleSearchEx(DemodBuffer, preamble, EM_PREAMBLE_LEN, &size, startIdx, true)) { 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 false;
} }
return true; return true;
@ -1029,13 +1029,13 @@ bool doPreambleSearch(size_t *startIdx){
bool detectFSK(){ bool detectFSK(){
// detect fsk clock // detect fsk clock
if (!GetFskClock("", false)) { if (!GetFskClock("", false)) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK clock failed"); PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK clock failed");
return false; return false;
} }
// demod // demod
int ans = FSKrawDemod("0 0", false); int ans = FSKrawDemod("0 0", false);
if (!ans) { if (!ans) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK Demod failed"); PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK Demod failed");
return false; return false;
} }
return true; return true;
@ -1044,19 +1044,19 @@ bool detectFSK(){
bool detectPSK(){ bool detectPSK(){
int ans = GetPskClock("", false); int ans = GetPskClock("", false);
if (ans <= 0) { if (ans <= 0) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK clock failed"); PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK clock failed");
return false; return false;
} }
//demod //demod
//try psk1 -- 0 0 6 (six errors?!?) //try psk1 -- 0 0 6 (six errors?!?)
ans = PSKDemod("0 0 6", false); ans = PSKDemod("0 0 6", false);
if (!ans) { if (!ans) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK1 Demod failed"); PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK1 Demod failed");
//try psk1 inverted //try psk1 inverted
ans = PSKDemod("0 1 6", false); ans = PSKDemod("0 1 6", false);
if (!ans) { 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; return false;
} }
} }
@ -1068,7 +1068,7 @@ bool detectPSK(){
bool detectASK_MAN(){ bool detectASK_MAN(){
bool stcheck = false; bool stcheck = false;
if ( !ASKDemod_ext("0 0 0", false, false, 1, &stcheck) ) { 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 false;
} }
return true; return true;
@ -1094,13 +1094,13 @@ bool setDemodBufferEM(uint32_t *word, size_t idx){
uint8_t parity[45] = {0}; uint8_t parity[45] = {0};
memcpy( parity, DemodBuffer, 45); memcpy( parity, DemodBuffer, 45);
if (!EMwordparitytest(parity) ){ if (!EMwordparitytest(parity) ){
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - EM Parity tests failed"); PrintAndLogEx(DEBUG, "DEBUG: Error - EM Parity tests failed");
return false; return false;
} }
// test for even parity bits and remove them. (leave out the end row of parities so 36 bits) // 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 (!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; return false;
} }
setDemodBuf(DemodBuffer, 32, 0); setDemodBuf(DemodBuffer, 32, 0);

View file

@ -168,23 +168,23 @@ int CmdFDXBdemodBI(const char *Cmd){
errCnt = askdemod(BitStream, &size, &clk, &invert, maxErr, 0, 0); errCnt = askdemod(BitStream, &size, &clk, &invert, maxErr, 0, 0);
if ( errCnt < 0 || errCnt > maxErr ) { 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; return 0;
} }
errCnt = BiphaseRawDecode(BitStream, &size, &offset, 1); errCnt = BiphaseRawDecode(BitStream, &size, &offset, 1);
if (errCnt < 0 || errCnt > maxErr ) { 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; return 0;
} }
int preambleIndex = detectFDXB(BitStream, &size); int preambleIndex = detectFDXB(BitStream, &size);
if (preambleIndex < 0){ 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; return 0;
} }
if (size != 128) { 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; return 0;
} }
@ -193,7 +193,7 @@ int CmdFDXBdemodBI(const char *Cmd){
// remove marker bits (1's every 9th digit after preamble) (pType = 2) // remove marker bits (1's every 9th digit after preamble) (pType = 2)
size = removeParity(BitStream, preambleIndex + 11, 9, 2, 117); size = removeParity(BitStream, preambleIndex + 11, 9, 2, 117);
if ( size != 104 ) { 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; return 0;
} }
PrintAndLogEx(NORMAL, "\nFDX-B / ISO 11784/5 Animal Tag ID Found:"); PrintAndLogEx(NORMAL, "\nFDX-B / ISO 11784/5 Animal Tag ID Found:");
@ -211,7 +211,7 @@ int CmdFDXBdemodBI(const char *Cmd){
uint8_t raw[8]; uint8_t raw[8];
num_to_bytes(rawid, 8, raw); 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); uint16_t calcCrc = crc16_kermit(raw, 8);
PrintAndLogEx(NORMAL, "Animal ID: %04u-%012" PRIu64, countryCode, NationalCode); 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"); PrintAndLogEx(NORMAL, "CRC: 0x%04X - [%04X] - %s", crc16, calcCrc, (calcCrc == crc16) ? "Passed" : "Failed");
if (g_debugMode) { 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); char *bin = sprint_bin_break(BitStream,size,16);
PrintAndLogEx(DEBUG, "DEBUG BinStream:\n%s",bin); PrintAndLogEx(DEBUG, "DEBUG BinStream:\n%s",bin);
} }
@ -239,22 +239,21 @@ int CmdFdxDemod(const char *Cmd) {
//Differential Biphase / di-phase (inverted biphase) //Differential Biphase / di-phase (inverted biphase)
//get binary from ask wave //get binary from ask wave
if (!ASKbiphaseDemod("0 32 1 0", false)) { 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; return 0;
} }
size_t size = DemodBufferLen; size_t size = DemodBufferLen;
int preambleIndex = detectFDXB(DemodBuffer, &size); int preambleIndex = detectFDXB(DemodBuffer, &size);
if (preambleIndex < 0){ if (preambleIndex < 0){
if (g_debugMode){
if (preambleIndex == -1) if (preambleIndex == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B too few bits found"); PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B too few bits found");
else if (preambleIndex == -2) else if (preambleIndex == -2)
PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B preamble not found"); PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B preamble not found");
else if (preambleIndex == -3) else if (preambleIndex == -3)
PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B Size not correct: %d", size); PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B Size not correct: %d", size);
else else
PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B ans: %d", preambleIndex); PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B ans: %d", preambleIndex);
}
return 0; return 0;
} }
@ -264,7 +263,7 @@ int CmdFdxDemod(const char *Cmd) {
// remove marker bits (1's every 9th digit after preamble) (pType = 2) // remove marker bits (1's every 9th digit after preamble) (pType = 2)
size = removeParity(DemodBuffer, 11, 9, 2, 117); size = removeParity(DemodBuffer, 11, 9, 2, 117);
if ( size != 104 ) { 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; 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"); PrintAndLogEx(NORMAL, "CRC-16 0x%04X - 0x%04X [%s]", crc16, calcCrc, (calcCrc == crc16) ? "Ok" : "Failed");
if (g_debugMode) { 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); char *bin = sprint_bin_break(DemodBuffer, size, 16);
PrintAndLogEx(DEBUG, "DEBUG bin stream:\n%s", bin); PrintAndLogEx(DEBUG, "DEBUG bin stream:\n%s", bin);
} }

View file

@ -177,7 +177,7 @@ int CmdGuardDemod(const char *Cmd) {
//Differential Biphase //Differential Biphase
//get binary from ask wave //get binary from ask wave
if (!ASKbiphaseDemod("0 64 0 0", false)) { 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; return 0;
} }
@ -185,18 +185,17 @@ int CmdGuardDemod(const char *Cmd) {
int preambleIndex = detectGProxII(DemodBuffer, &size); int preambleIndex = detectGProxII(DemodBuffer, &size);
if (preambleIndex < 0){ if (preambleIndex < 0){
if (g_debugMode){
if (preambleIndex == -1) if (preambleIndex == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII too few bits found"); PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII too few bits found");
else if (preambleIndex == -2) else if (preambleIndex == -2)
PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII preamble not found"); PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII preamble not found");
else if (preambleIndex == -3) else if (preambleIndex == -3)
PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII size not correct: %d", size); PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII size not correct: %d", size);
else if (preambleIndex == -3) else if (preambleIndex == -3)
PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII wrong spacerbits"); PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII wrong spacerbits");
else else
PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII ans: %d", preambleIndex); PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII ans: %d", preambleIndex);
}
return 0; 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)) // 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 size_t len = removeParity(bits_no_spacer, 0, 5, 3, 90); //source, startloc, paritylen, ptype, length_to_run
if (len != 72) { 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; return 0;
} }
// get key and then get all 8 bytes of payload decoded // get key and then get all 8 bytes of payload decoded
xorKey = (uint8_t)bytebits_to_byteLSBF(bits_no_spacer, 8); xorKey = (uint8_t)bytebits_to_byteLSBF(bits_no_spacer, 8);
for (size_t idx = 0; idx < 8; idx++) { for (size_t idx = 0; idx < 8; idx++) {
ByteStream[idx] = ((uint8_t)bytebits_to_byteLSBF(bits_no_spacer+8 + (idx*8),8)) ^ xorKey; 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); setDemodBuf(DemodBuffer, 96, preambleIndex);