X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/ac914e56dba0fc9d164bed802b61055b90c7506e..c3bfb9c76bf147c39d4d94bd41d20f2a20b310e8:/client/cmddata.c?ds=inline diff --git a/client/cmddata.c b/client/cmddata.c index d8a0fcf6..d05f3fa1 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -329,7 +329,7 @@ int CmdBiphaseDecodeRaw(const char *Cmd) //prints binary found and saves in graphbuffer for further commands int Cmdaskrawdemod(const char *Cmd) { - uint32_t i; + int invert=0; int clk=0; uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; @@ -340,7 +340,7 @@ int Cmdaskrawdemod(const char *Cmd) } int BitLen = getFromGraphBuf(BitStream); int errCnt=0; - errCnt = askrawdemod(BitStream, &BitLen,&clk,&invert); + errCnt = askrawdemod(BitStream, &BitLen, &clk, &invert); if (errCnt==-1){ //throw away static - allow 1 and -1 (in case of threshold command first) PrintAndLog("no data found"); return 0; @@ -349,19 +349,14 @@ int Cmdaskrawdemod(const char *Cmd) PrintAndLog("Using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen); //PrintAndLog("Data start pos:%d, lastBit:%d, stop pos:%d, numBits:%d",iii,lastBit,i,bitnum); //move BitStream back to GraphBuffer - - ClearGraph(0); - for (i=0; i < BitLen; ++i){ - GraphBuffer[i]=BitStream[i]; - } - GraphTraceLen=BitLen; - RepaintGraphWindow(); - - //output + setGraphBuf(BitStream, BitLen); + if (errCnt>0){ PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt); } + PrintAndLog("ASK demoded bitstream:"); + // Now output the bitstream to the scrollback by line of 16 bits printBitStream(BitStream,BitLen); @@ -477,10 +472,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(); @@ -510,8 +501,6 @@ int CmdDec(const char *Cmd) int CmdDetectClockRate(const char *Cmd) { GetClock("",0,0); - //int clock = DetectASKClock(0); - //PrintAndLog("Auto-detected clock rate: %d", clock); return 0; } @@ -707,7 +696,7 @@ int CmdFSKdemod(const char *Cmd) //old CmdFSKdemod needs updating int lowLen = sizeof (LowTone) / sizeof (int); int highLen = sizeof (HighTone) / sizeof (int); - int convLen = (highLen > lowLen) ? highLen : lowLen; //if highlen > lowLen then highlen else lowlen + int convLen = (highLen > lowLen) ? highLen : lowLen; uint32_t hi = 0, lo = 0; int i, j; @@ -773,8 +762,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) { @@ -881,22 +869,21 @@ int CmdHpf(const char *Cmd) int CmdSamples(const char *Cmd) { - int cnt = 0; - int n; - uint8_t got[40000]; - - n = strtol(Cmd, NULL, 0); - if (n == 0) n = 6000; - if (n > sizeof(got)) n = sizeof(got); + uint8_t got[40000] = {0x00}; + + int n = strtol(Cmd, NULL, 0); + if (n == 0) + n = 20000; + + if (n > sizeof(got)) + n = sizeof(got); - PrintAndLog("Reading %d samples\n", n); + PrintAndLog("Reading %d samples from device memory\n", n); GetFromBigBuf(got,n,0); WaitForResponse(CMD_ACK,NULL); - for (int j = 0; j < n; j++) { - GraphBuffer[cnt++] = ((int)got[j]) - 128; + for (int j = 0; j < n; ++j) { + GraphBuffer[j] = ((int)got[j]) - 128; } - - PrintAndLog("Done!\n"); GraphTraceLen = n; RepaintGraphWindow(); return 0; @@ -904,29 +891,67 @@ int CmdSamples(const char *Cmd) int CmdTuneSamples(const char *Cmd) { - int cnt = 0; - int n = 255; - uint8_t got[255]; - - PrintAndLog("Reading %d samples\n", n); - GetFromBigBuf(got,n,7256); // armsrc/apps.h: #define FREE_BUFFER_OFFSET 7256 - WaitForResponse(CMD_ACK,NULL); - for (int j = 0; j < n; j++) { - GraphBuffer[cnt++] = ((int)got[j]) - 128; + int timeout = 0; + printf("\nMeasuring antenna characteristics, please wait..."); + + UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING}; + SendCommand(&c); + + UsbCommand resp; + while(!WaitForResponseTimeout(CMD_MEASURED_ANTENNA_TUNING,&resp,1000)) { + timeout++; + printf("."); + if (timeout > 7) { + PrintAndLog("\nNo response from Proxmark. Aborting..."); + return 1; + } + } + + int peakv, peakf; + int vLf125, vLf134, vHf; + vLf125 = resp.arg[0] & 0xffff; + vLf134 = resp.arg[0] >> 16; + vHf = resp.arg[1] & 0xffff;; + peakf = resp.arg[2] & 0xffff; + peakv = resp.arg[2] >> 16; + PrintAndLog(""); + PrintAndLog("# LF antenna: %5.2f V @ 125.00 kHz", vLf125/1000.0); + PrintAndLog("# LF antenna: %5.2f V @ 134.00 kHz", vLf134/1000.0); + PrintAndLog("# LF optimal: %5.2f V @%9.2f kHz", peakv/1000.0, 12000.0/(peakf+1)); + PrintAndLog("# HF antenna: %5.2f V @ 13.56 MHz", vHf/1000.0); + if (peakv<2000) + PrintAndLog("# Your LF antenna is unusable."); + else if (peakv<10000) + PrintAndLog("# Your LF antenna is marginal."); + if (vHf<2000) + PrintAndLog("# Your HF antenna is unusable."); + else if (vHf<5000) + PrintAndLog("# Your HF antenna is marginal."); + + for (int i = 0; i < 256; i++) { + GraphBuffer[i] = resp.d.asBytes[i] - 128; } PrintAndLog("Done! Divisor 89 is 134khz, 95 is 125khz.\n"); PrintAndLog("\n"); - GraphTraceLen = n; - RepaintGraphWindow(); + GraphTraceLen = 256; + ShowGraphWindow(); + return 0; } int CmdLoad(const char *Cmd) { - FILE *f = fopen(Cmd, "r"); + char filename[FILE_PATH_SIZE] = {0x00}; + int len = 0; + + len = strlen(Cmd); + if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE; + memcpy(filename, Cmd, len); + + FILE *f = fopen(filename, "r"); if (!f) { - PrintAndLog("couldn't open '%s'", Cmd); + PrintAndLog("couldn't open '%s'", filename); return 0; } @@ -1232,9 +1257,17 @@ int CmdPlot(const char *Cmd) int CmdSave(const char *Cmd) { - FILE *f = fopen(Cmd, "w"); + char filename[FILE_PATH_SIZE] = {0x00}; + int len = 0; + + len = strlen(Cmd); + if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE; + memcpy(filename, Cmd, len); + + + FILE *f = fopen(filename, "w"); if(!f) { - PrintAndLog("couldn't open '%s'", Cmd); + PrintAndLog("couldn't open '%s'", filename); return 0; } int i; @@ -1340,8 +1373,8 @@ static command_t CommandTable[] = {"help", CmdHelp, 1, "This help"}, {"amp", CmdAmp, 1, "Amplify peaks"}, {"askdemod", Cmdaskdemod, 1, "<0 or 1> -- Attempt to demodulate simple ASK tags"}, - {"askmandemod", Cmdaskmandemod, 1, "[clock] [invert<0 or 1>] -- Attempt to demodulate ASK/Manchester tags and output binary (args optional[clock will try Auto-detect])"}, - {"askrawdemod", Cmdaskrawdemod, 1, "[clock] [invert<0 or 1>] -- Attempt to demodulate ASK tags and output binary (args optional[clock will try Auto-detect])"}, + {"askmandemod", Cmdaskmandemod, 1, "[clock] [invert <0|1>] -- Attempt to demodulate ASK/Manchester tags and output binary"}, + {"askrawdemod", Cmdaskrawdemod, 1, "[clock] [invert <0|1>] -- Attempt to demodulate ASK tags and output binary"}, {"autocorr", CmdAutoCorr, 1, " -- Autocorrelation over window"}, {"biphaserawdecode",CmdBiphaseDecodeRaw,1,"[offset] Biphase decode binary stream already in graph buffer (offset = bit to start decode from)"}, {"bitsamples", CmdBitsamples, 0, "Get raw samples as bitstring"},