]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmddata.c
CHG: minor code clean up.
[proxmark3-svn] / client / cmddata.c
index f10d7b536703831b66a1ec85d72b4bb13e8f8b25..3ac8db25fb5455e00d4349fc4922d8f7b3239650 100644 (file)
@@ -234,8 +234,9 @@ int Cmdaskmandemod(const char *Cmd)
     setGraphBuf(BitStream,BitLen); 
     PrintAndLog("EM410x pattern found: ");
     printEM410x(lo);
+    return 1;
   }
-  if (BitLen>16) return 1;
+  //if (BitLen>16) return 1;
   return 0;
 }
 
@@ -328,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};
@@ -339,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;
@@ -348,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);
   
@@ -476,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();
@@ -509,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;
 }
 
@@ -772,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) {
@@ -880,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;
@@ -903,21 +891,52 @@ 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;
 }
 
@@ -952,6 +971,15 @@ int CmdLtrim(const char *Cmd)
   RepaintGraphWindow();
   return 0;
 }
+int CmdRtrim(const char *Cmd)
+{
+  int ds = atoi(Cmd);
+
+  GraphTraceLen = ds;
+
+  RepaintGraphWindow();
+  return 0;
+}
 
 /*
  * Manchester demodulate a bitstream. The bitstream needs to be already in
@@ -1330,8 +1358,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, "<window length> -- 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"},
@@ -1342,13 +1370,14 @@ static command_t CommandTable[] =
   {"fskdemod",      CmdFSKdemod,        1, "Demodulate graph window as a HID FSK"},
   {"fskhiddemod",   CmdFSKdemodHID,     1, "Demodulate graph window as a HID FSK using raw"},
   {"fskiodemod",    CmdFSKdemodIO,      1, "Demodulate graph window as an IO Prox FSK using raw"},
-  {"fskrawdemod",   CmdFSKrawdemod,     1, "[clock rate] [invert] Demodulate graph window from FSK to binary (clock = 64 or 50)(invert = 1 or 0)"},
+  {"fskrawdemod",   CmdFSKrawdemod,     1, "[clock rate] [invert] [rchigh] [rclow] Demodulate graph window from FSK to binary (clock = 50)(invert = 1 or 0)(rchigh = 10)(rclow=8)"},
   {"grid",          CmdGrid,            1, "<x> <y> -- overlay grid on graph window, use zero value to turn off either"},
   {"hexsamples",    CmdHexsamples,      0, "<bytes> [<offset>] -- Dump big buffer as hex bytes"},  
   {"hide",          CmdHide,            1, "Hide graph window"},
   {"hpf",           CmdHpf,             1, "Remove DC offset from trace"},
   {"load",          CmdLoad,            1, "<filename> -- Load trace (to graph window"},
   {"ltrim",         CmdLtrim,           1, "<samples> -- Trim samples from left of trace"},
+  {"rtrim",         CmdRtrim,           1, "<location to end trace> -- Trim samples from right of trace"},
   {"mandemod",      CmdManchesterDemod, 1, "[i] [clock rate] -- Manchester demodulate binary stream (option 'i' to invert output)"},
   {"manrawdecode",  Cmdmandecoderaw,    1, "Manchester decode binary stream already in graph buffer"},
   {"manmod",        CmdManchesterMod,   1, "[clock rate] -- Manchester modulate a binary stream"},
Impressum, Datenschutz