X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/ec75f5c10a91211e50b74af181b827fc93a6dcd5..04d2721b3c7c4113e627d3f953835bde932065db:/client/cmddata.c diff --git a/client/cmddata.c b/client/cmddata.c index 578587bc..0c6cd72c 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -537,10 +537,6 @@ int CmdBitstream(const char *Cmd) bit ^= 1; AppendGraph(0, clock, bit); - // for (j = 0; j < (int)(clock/2); j++) - // GraphBuffer[(i * clock) + j] = bit ^ 1; - // for (j = (int)(clock/2); j < clock; j++) - // GraphBuffer[(i * clock) + j] = bit; } RepaintGraphWindow(); @@ -604,22 +600,40 @@ int CmdFSKrawdemod(const char *Cmd) { //raw fsk demod no manchester decoding no start bit finding just get binary from wave //set defaults - int rfLen = 50; + int rfLen = 0; int invert=0; - int fchigh=10; - int fclow=8; + int fchigh=0; + int fclow=0; //set options from parameters entered with the command sscanf(Cmd, "%i %i %i %i", &rfLen, &invert, &fchigh, &fclow); if (strlen(Cmd)>0 && strlen(Cmd)<=2) { if (rfLen==1){ invert=1; //if invert option only is used - rfLen = 50; - } else if(rfLen==0) rfLen=50; + rfLen = 0; + } } - PrintAndLog("Args invert: %d - Clock:%d - fchigh:%d - fclow: %d",invert,rfLen,fchigh, fclow); + uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; size_t BitLen = getFromGraphBuf(BitStream); + //get field clock lengths + uint16_t fcs=0; + if (fchigh==0 || fclow == 0){ + fcs=countFC(BitStream, BitLen); + if (fcs==0){ + fchigh=10; + fclow=8; + }else{ + fchigh = (fcs >> 8) & 0xFF; + fclow = fcs & 0xFF; + } + } + //get bit clock length + if (rfLen==0){ + rfLen = detectFSKClk(BitStream, BitLen, fchigh, fclow); + if (rfLen == 0) rfLen = 50; + } + PrintAndLog("Args invert: %d - Clock:%d - fchigh:%d - fclow: %d",invert,rfLen,fchigh, fclow); int size = fskdemod(BitStream,BitLen,(uint8_t)rfLen,(uint8_t)invert,(uint8_t)fchigh,(uint8_t)fclow); if (size>0){ PrintAndLog("FSK decoded bitstream:"); @@ -707,8 +721,8 @@ int CmdFSKdemodHID(const char *Cmd) return 1; } -//by marshmellow (based on existing demod + holiman's refactor) -//Paradox Prox demod - FSK RF/50 with preamble of 00011101 (then manchester encoded) +//by marshmellow +//Paradox Prox demod - FSK RF/50 with preamble of 00001111 (then manchester encoded) //print full Paradox Prox ID and some bit format details if found int CmdFSKdemodParadox(const char *Cmd) { @@ -1119,8 +1133,7 @@ int CmdFSKdemod(const char *Cmd) //old CmdFSKdemod needs updating PrintAndLog("actual data bits start at sample %d", maxPos); PrintAndLog("length %d/%d", highLen, lowLen); - uint8_t bits[46]; - bits[sizeof(bits)-1] = '\0'; + uint8_t bits[46] = {0x00}; // find bit pairs and manchester decode them for (i = 0; i < arraylen(bits) - 1; ++i) { @@ -1159,12 +1172,20 @@ int CmdFSKfcDetect(const char *Cmd) uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; size_t size = getFromGraphBuf(BitStream); - - uint32_t ans = countFC(BitStream, size); - int fc1, fc2, rf1; + uint16_t ans = countFC(BitStream, size); + if (ans==0) { + if (g_debugMode) PrintAndLog("DEBUG: No data found"); + return 0; + } + uint8_t fc1, fc2; fc1 = (ans >> 8) & 0xFF; fc2 = ans & 0xFF; - rf1 = (ans >>16) & 0xFF; + + uint8_t rf1 = detectFSKClk(BitStream, size, fc1, fc2); + if (rf1==0) { + if (g_debugMode) PrintAndLog("DEBUG: Clock detect error"); + return 0; + } PrintAndLog("Detected Field Clocks: FC/%d, FC/%d - Bit Clock: RF/%d", fc1, fc2, rf1); return 1; } @@ -1175,7 +1196,7 @@ int CmdDetectNRZpskClockRate(const char *Cmd) return 0; } -int PSKnrzDemod(const char *Cmd) +int PSKnrzDemod(const char *Cmd, uint8_t verbose) { int invert=0; int clk=0; @@ -1192,7 +1213,7 @@ int PSKnrzDemod(const char *Cmd) if (g_debugMode==1) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt); return -1; } - PrintAndLog("Tried PSK/NRZ Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen); + if (verbose) PrintAndLog("Tried PSK/NRZ Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen); //prime demod buffer for output setDemodBuf(BitStream,BitLen,0); @@ -1205,9 +1226,9 @@ int CmdIndalaDecode(const char *Cmd) { int ans; if (strlen(Cmd)>0){ - ans = PSKnrzDemod(Cmd); + ans = PSKnrzDemod(Cmd, 0); } else{ //default to RF/32 - ans = PSKnrzDemod("32"); + ans = PSKnrzDemod("32", 0); } if (ans < 0){ @@ -1284,15 +1305,15 @@ int CmdPskClean(const char *Cmd) return 0; } -//by marshmellow -//takes 2 arguments - clock and invert both as integers -//attempts to demodulate ask only -//prints binary found and saves in graphbuffer for further commands +// by marshmellow +// takes 2 arguments - clock and invert both as integers +// attempts to demodulate psk only +// prints binary found and saves in demodbuffer for further commands int CmdpskNRZrawDemod(const char *Cmd) { int errCnt; - errCnt = PSKnrzDemod(Cmd); + errCnt = PSKnrzDemod(Cmd, 1); //output if (errCnt<0){ if (g_debugMode) PrintAndLog("Error demoding: %d",errCnt); @@ -1314,6 +1335,32 @@ int CmdpskNRZrawDemod(const char *Cmd) return 0; } +// by marshmellow +// takes same args as cmdpsknrzrawdemod +int CmdPSK2rawDemod(const char *Cmd) +{ + int errCnt=0; + errCnt=PSKnrzDemod(Cmd, 1); + if (errCnt<0){ + if (g_debugMode) PrintAndLog("Error demoding: %d",errCnt); + 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(); + } + return 1; +} + int CmdGrid(const char *Cmd) { sscanf(Cmd, "%i %i", &PlotGridX, &PlotGridY); @@ -1389,7 +1436,7 @@ int CmdHpf(const char *Cmd) int CmdSamples(const char *Cmd) { - uint8_t got[40000]; + uint8_t got[40000] = {0x00}; int n = strtol(Cmd, NULL, 0); if (n == 0) @@ -1928,8 +1975,9 @@ static command_t CommandTable[] = {"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"}, {"pskclean", CmdPskClean, 1, "Attempt to clean psk wave"}, {"pskdetectclock",CmdDetectNRZpskClockRate, 1, "Detect ASK, PSK, or NRZ clock rate"}, - {"pskindalademod",CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk indala tags and output ID binary & hex (args optional)"}, - {"psknrzrawdemod",CmdpskNRZrawDemod, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk or nrz tags and output binary (args optional)"}, + {"pskindalademod",CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk1 indala tags and output ID binary & hex (args optional)"}, + {"psk1nrzrawdemod",CmdpskNRZrawDemod, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk1 or nrz tags and output binary (args optional)"}, + {"psk2rawdemod", CmdPSK2rawDemod, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk2 tags and output binary (args optional)"}, {"samples", CmdSamples, 0, "[512 - 40000] -- Get raw samples for graph window"}, {"save", CmdSave, 1, " -- Save trace (from graph window)"}, {"scale", CmdScale, 1, " -- Set cursor display scale"},