X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/73d04bb417f52be89450e851deebcbd6ae125952..7a8a982bde66f752d8aa28423d70487d04f7572c:/client/cmddata.c diff --git a/client/cmddata.c b/client/cmddata.c index 6d85cf68..356bfab3 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -623,13 +623,13 @@ int CmdG_Prox_II_Demod(const char *Cmd) int ans = ASKrawDemod(Cmd, FALSE); if (ans <= 0) { if (g_debugMode) PrintAndLog("Error AskrawDemod: %d",ans); - return ans; + return 0; //ans; } size_t size = DemodBufferLen; ans = BiphaseRawDecode(DemodBuffer, &size, 0, 0); if (ans !=0) { if (g_debugMode) PrintAndLog("Error BiphaseRawDecode: %d",ans); - return ans; + return 0; //ans; } //call lfdemod.c demod for gProxII ans = gProxII_Demod(DemodBuffer, &size); @@ -639,7 +639,7 @@ int CmdG_Prox_II_Demod(const char *Cmd) ans = BiphaseRawDecode(DemodBuffer, &size, 1, 0); if (ans != 0) { if (g_debugMode) PrintAndLog("Error BiphaseRawDecode: %d",ans); - return ans; + return 0;//ans; } ans = gProxII_Demod(DemodBuffer, &size); if (ans < 0) { @@ -774,20 +774,34 @@ int AutoCorrelate(int window, bool SaveGrph, bool verbose) return Correlation; } +int usage_data_autocorr(void) +{ + //print help + PrintAndLog("Usage: data autocorr [window] [g]"); + PrintAndLog("Options: "); + PrintAndLog(" h This help"); + PrintAndLog(" [window] window length for correlation - default = 4000"); + PrintAndLog(" g save back to GraphBuffer (overwrite)"); + return 0; +} + int CmdAutoCorr(const char *Cmd) { - int window = atoi(Cmd); + char cmdp = param_getchar(Cmd, 0); + if (cmdp == 'h' || cmdp == 'H') + return usage_data_autocorr(); + int window = 4000; //set default + char grph=0; + bool updateGrph = FALSE; + sscanf(Cmd, "%i %c", &window, &grph); - if (window == 0) { - PrintAndLog("needs a window"); - return 0; - } if (window >= GraphTraceLen) { PrintAndLog("window must be smaller than trace (%d samples)", GraphTraceLen); return 0; } - return AutoCorrelate(window, TRUE, TRUE); + if (grph == 'g') updateGrph=TRUE; + return AutoCorrelate(window, updateGrph, TRUE); } int CmdBitsamples(const char *Cmd) @@ -1471,7 +1485,8 @@ int CmdFSKdemodPyramid(const char *Cmd) csBuff[i] = bytebits_to_byte(BitStream + idx + 16 + (i*8), 8); } //check checksum calc - int checkCS = CRC8Maxim(csBuff,13); + //checksum calc thanks to ICEMAN!! + uint32_t checkCS = CRC8Maxim(csBuff,13); //get raw ID before removing parities uint32_t rawLo = bytebits_to_byte(BitStream+idx+96,32); @@ -1685,7 +1700,7 @@ int PSKDemod(const char *Cmd, bool verbose) } if (invert != 0 && invert != 1) { if (verbose) PrintAndLog("Invalid argument: %s", Cmd); - return -1; + return 0; } uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; size_t BitLen = getFromGraphBuf(BitStream); @@ -1693,22 +1708,27 @@ int PSKDemod(const char *Cmd, bool verbose) uint8_t carrier=countPSK_FC(BitStream, BitLen); if (carrier!=2 && carrier!=4 && carrier!=8){ //invalid carrier - return -1; + return 0; } int errCnt=0; errCnt = pskRawDemod(BitStream, &BitLen, &clk, &invert); if (errCnt > maxErr){ if (g_debugMode==1 && verbose) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt); - return -1; + return 0; } if (errCnt<0|| BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first) if (g_debugMode==1 && verbose) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt); - return -1; + return 0; + } + if (verbose){ + PrintAndLog("Tried PSK Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen); + if (errCnt>0){ + PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt); + } } - if (verbose) PrintAndLog("Tried PSK Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen); //prime demod buffer for output setDemodBuf(BitStream,BitLen,0); - return errCnt; + return 1; } // Indala 26 bit decode @@ -1723,7 +1743,7 @@ int CmdIndalaDecode(const char *Cmd) ans = PSKDemod("32", 0); } - if (ans < 0){ + if (!ans){ if (g_debugMode==1) PrintAndLog("Error1: %d",ans); return 0; @@ -1864,7 +1884,7 @@ int CmdNRZrawDemod(const char *Cmd) // prints binary found and saves in demodbuffer for further commands int CmdPSK1rawDemod(const char *Cmd) { - int errCnt; + int ans; char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) > 10 || cmdp == 'h' || cmdp == 'H') { PrintAndLog("Usage: data rawdemod p1 [clock] <0|1> [maxError]"); @@ -1879,15 +1899,13 @@ 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; } - errCnt = PSKDemod(Cmd, TRUE); + ans = PSKDemod(Cmd, TRUE); //output - if (errCnt<0){ - if (g_debugMode) PrintAndLog("Error demoding: %d",errCnt); + if (!ans){ + if (g_debugMode) PrintAndLog("Error demoding: %d",ans); return 0; } - if (errCnt>0){ - PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt); - } + PrintAndLog("PSK demoded bitstream:"); // Now output the bitstream to the scrollback by line of 16 bits printDemodBuff(); @@ -1898,7 +1916,7 @@ int CmdPSK1rawDemod(const char *Cmd) // takes same args as cmdpsk1rawdemod int CmdPSK2rawDemod(const char *Cmd) { - int errCnt=0; + int ans=0; char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) > 10 || cmdp == 'h' || cmdp == 'H') { PrintAndLog("Usage: data rawdemod p2 [clock] <0|1> [maxError]"); @@ -1913,24 +1931,15 @@ 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; } - errCnt=PSKDemod(Cmd, TRUE); - if (errCnt<0){ - if (g_debugMode) PrintAndLog("Error demoding: %d",errCnt); + ans=PSKDemod(Cmd, TRUE); + if (!ans){ + if (g_debugMode) PrintAndLog("Error demoding: %d",ans); return 0; } psk1TOpsk2(DemodBuffer, DemodBufferLen); - if (errCnt>0){ - if (g_debugMode){ - PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt); - PrintAndLog("PSK2 demoded bitstream:"); - // Now output the bitstream to the scrollback by line of 16 bits - printDemodBuff(); - } - }else{ - PrintAndLog("PSK2 demoded bitstream:"); - // Now output the bitstream to the scrollback by line of 16 bits - printDemodBuff(); - } + PrintAndLog("PSK2 demoded bitstream:"); + // Now output the bitstream to the scrollback by line of 16 bits + printDemodBuff(); return 1; } @@ -2625,7 +2634,7 @@ static command_t CommandTable[] = {"askgproxiidemod",CmdG_Prox_II_Demod,1, "Demodulate a G Prox II tag from GraphBuffer"}, //{"askmandemod", Cmdaskmandemod, 1, "[clock] [invert<0|1>] [maxErr] -- Attempt to demodulate ASK/Manchester tags and output binary (args optional)"}, //{"askrawdemod", Cmdaskrawdemod, 1, "[clock] [invert<0|1>] -- Attempt to demodulate ASK tags and output bin (args optional)"}, - {"autocorr", CmdAutoCorr, 1, " -- Autocorrelation over window"}, + {"autocorr", CmdAutoCorr, 1, "[window length] [g] -- Autocorrelation over window - g to save back to GraphBuffer (overwrite)"}, {"biphaserawdecode",CmdBiphaseDecodeRaw,1,"[offset] [invert<0|1>] Biphase decode bin stream in DemodBuffer (offset = 0|1 bits to shift the decode start)"}, {"bitsamples", CmdBitsamples, 0, "Get raw samples as bitstring"}, //{"bitstream", CmdBitstream, 1, "[clock rate] -- Convert waveform into a bitstream"},