]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
lf cleaning
authormarshmellow42 <marshmellowrf@gmail.com>
Sun, 5 Apr 2015 04:58:57 +0000 (00:58 -0400)
committermarshmellow42 <marshmellowrf@gmail.com>
Sun, 5 Apr 2015 04:58:57 +0000 (00:58 -0400)
remove unneeded code/functions
fix lfdemod askmandemod bug with maxErr=0
silence output for getting samples in lf search

13 files changed:
client/cmddata.c
client/cmddata.h
client/cmdlf.c
client/cmdlf.h
client/cmdlfem4x.c
client/cmdlfhid.c
client/cmdlfhid.h
client/cmdlfio.c
client/cmdlft55xx.c
client/graph.c
client/util.c
client/util.h
common/lfdemod.c

index 84a450f8fc1148775d17b7c3c504ad44931f3109..e2e2ca6dd30d763a279cbf1746651300fd640762 100644 (file)
@@ -58,37 +58,16 @@ int CmdSetDebugMode(const char *Cmd)
 //by marshmellow
 void printDemodBuff(void)
 {
-       uint32_t i = 0;
        int bitLen = DemodBufferLen;
-       if (bitLen<16) {
+       if (bitLen<1) {
                PrintAndLog("no bits found in demod buffer");
                return;
        }
        if (bitLen>512) bitLen=512; //max output to 512 bits if we have more - should be plenty
 
-       // ensure equally divided by 16
-       bitLen &= 0xfff0;
-
-       for (i = 0; i <= (bitLen-16); i+=16) {
-               PrintAndLog("%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i",
-                   DemodBuffer[i],
-                   DemodBuffer[i+1],
-                   DemodBuffer[i+2],
-                   DemodBuffer[i+3],
-                   DemodBuffer[i+4],
-                   DemodBuffer[i+5],
-                   DemodBuffer[i+6],
-                   DemodBuffer[i+7],
-                   DemodBuffer[i+8],
-                   DemodBuffer[i+9],
-                   DemodBuffer[i+10],
-                   DemodBuffer[i+11],
-                   DemodBuffer[i+12],
-                   DemodBuffer[i+13],
-                   DemodBuffer[i+14],
-                   DemodBuffer[i+15]
-               );
-       }
+       char *bin = sprint_bin_break(DemodBuffer,bitLen,16);
+       PrintAndLog("%s",bin);
+
        return;
 }
 
@@ -114,105 +93,8 @@ int CmdPrintDemodBuff(const char *Cmd)
        }
        return 1;
 }
-int CmdAmp(const char *Cmd)
-{
-       int i, rising, falling;
-       int max = INT_MIN, min = INT_MAX;
-
-       for (i = 10; i < GraphTraceLen; ++i) {
-               if (GraphBuffer[i] > max)
-                       max = GraphBuffer[i];
-               if (GraphBuffer[i] < min)
-                       min = GraphBuffer[i];
-       }
-
-       if (max != min) {
-               rising = falling= 0;
-               for (i = 0; i < GraphTraceLen; ++i) {
-                       if (GraphBuffer[i + 1] < GraphBuffer[i]) {
-                               if (rising) {
-                                       GraphBuffer[i] = max;
-                                       rising = 0;
-                               }
-                               falling = 1;
-                       }
-                       if (GraphBuffer[i + 1] > GraphBuffer[i]) {
-                               if (falling) {
-                                       GraphBuffer[i] = min;
-                                       falling = 0;
-                               }
-                               rising= 1;
-                       }
-               }
-       }
-       RepaintGraphWindow();
-       return 0;
-}
-
-/*
- * Generic command to demodulate ASK.
- *
- * Argument is convention: positive or negative (High mod means zero
- * or high mod means one)
- *
- * Updates the Graph trace with 0/1 values
- *
- * Arguments:
- * c : 0 or 1  (or invert)
- */
- //this method ignores the clock
-
- //this function strictly converts highs and lows to 1s and 0s for each sample in the graphbuffer
-int Cmdaskdemod(const char *Cmd)
-{
-       int i;
-       int c, high = 0, low = 0;
-
-       sscanf(Cmd, "%i", &c);
-
-       /* Detect high and lows */
-       for (i = 0; i < GraphTraceLen; ++i)
-       {
-               if (GraphBuffer[i] > high)
-                       high = GraphBuffer[i];
-               else if (GraphBuffer[i] < low)
-                       low = GraphBuffer[i];
-       }
-       high=abs(high*.75);
-       low=abs(low*.75);
-       if (c != 0 && c != 1) {
-               PrintAndLog("Invalid argument: %s", Cmd);
-               return 0;
-       }
-       //prime loop
-       if (GraphBuffer[0] > 0) {
-               GraphBuffer[0] = 1-c;
-       } else {
-               GraphBuffer[0] = c;
-       }
-       for (i = 1; i < GraphTraceLen; ++i) {
-               /* Transitions are detected at each peak
-                * Transitions are either:
-                * - we're low: transition if we hit a high
-                * - we're high: transition if we hit a low
-                * (we need to do it this way because some tags keep high or
-                * low for long periods, others just reach the peak and go
-                * down)
-                */
-               //[marhsmellow] change == to >= for high and <= for low for fuzz
-               if ((GraphBuffer[i] >= high) && (GraphBuffer[i - 1] == c)) {
-                       GraphBuffer[i] = 1 - c;
-               } else if ((GraphBuffer[i] <= low) && (GraphBuffer[i - 1] == (1 - c))){
-                       GraphBuffer[i] = c;
-               } else {
-                       /* No transition */
-                       GraphBuffer[i] = GraphBuffer[i - 1];
-               }
-       }
-       RepaintGraphWindow();
-       return 0;
-}
 
+//by marshmellow
 //this function strictly converts >1 to 1 and <1 to 0 for each sample in the graphbuffer
 int CmdGetBitStream(const char *Cmd)
 {
@@ -229,43 +111,6 @@ int CmdGetBitStream(const char *Cmd)
        return 0;
 }
 
-
-//by marshmellow
-void printBitStream(uint8_t BitStream[], uint32_t bitLen)
-{
-       uint32_t i = 0;
-       if (bitLen<16) {
-               PrintAndLog("Too few bits found: %d",bitLen);
-               return;
-       }
-       if (bitLen>512) bitLen=512;
-
-               // ensure equally divided by 16
-       bitLen &= 0xfff0;
-
-
-       for (i = 0; i <= (bitLen-16); i+=16) {
-               PrintAndLog("%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i",
-                   BitStream[i],
-                   BitStream[i+1],
-                   BitStream[i+2],
-                   BitStream[i+3],
-                   BitStream[i+4],
-                   BitStream[i+5],
-                   BitStream[i+6],
-                   BitStream[i+7],
-                   BitStream[i+8],
-                   BitStream[i+9],
-                   BitStream[i+10],
-                   BitStream[i+11],
-                   BitStream[i+12],
-                   BitStream[i+13],
-                   BitStream[i+14],
-                   BitStream[i+15]
-               );
-       }
-       return;
-}
 //by marshmellow
 //print 64 bit EM410x ID in multiple formats
 void printEM410x(uint32_t hi, uint64_t id)
@@ -282,11 +127,11 @@ void printEM410x(uint32_t hi, uint64_t id)
                }
                if (hi){
                        //output 88 bit em id
-                       PrintAndLog("\nEM TAG ID      : %06x%016llx", hi, id);
+                       PrintAndLog("\nEM TAG ID      : %06X%016llX", hi, id);
                } else{
                        //output 40 bit em id
-                       PrintAndLog("\nEM TAG ID      : %010llx", id);
-                       PrintAndLog("Unique TAG ID  : %010llx",  id2lo);
+                       PrintAndLog("\nEM TAG ID      : %010llX", id);
+                       PrintAndLog("Unique TAG ID  : %010llX",  id2lo);
                        PrintAndLog("\nPossible de-scramble patterns");
                        PrintAndLog("HoneyWell IdentKey {");
                        PrintAndLog("DEZ 8          : %08lld",id & 0xFFFFFF);
@@ -311,7 +156,7 @@ void printEM410x(uint32_t hi, uint64_t id)
                        );
                        uint64_t paxton = (((id>>32) << 24) | (id & 0xffffff))  + 0x143e00;
                        PrintAndLog("}\nOther          : %05lld_%03lld_%08lld",(id&0xFFFF),((id>>16LL) & 0xFF),(id & 0xFFFFFF));  
-                       PrintAndLog("Pattern Paxton : %0d", paxton);
+                       PrintAndLog("Pattern Paxton : %lld [0x%llX]", paxton, paxton);
 
                        uint32_t p1id = (id & 0xFFFFFF);
                        uint8_t arr[32] = {0x00};
@@ -352,12 +197,12 @@ void printEM410x(uint32_t hi, uint64_t id)
                        p1 |= arr[2]  << 4;
                        p1 |= arr[1]  << 5;
                        p1 |= arr[0]  << 9;
-                       PrintAndLog("Pattern 1      : 0x%X - %d", p1, p1);
+                       PrintAndLog("Pattern 1      : %d [0x%X]", p1, p1);
 
                        uint16_t sebury1 = id & 0xFFFF;
                        uint8_t  sebury2 = (id >> 16) & 0x7F;
                        uint32_t sebury3 = id & 0x7FFFFF;
-                       PrintAndLog("Pattern Sebury : %d %d %d  (hex: %X %X %X)", sebury1, sebury2, sebury3, sebury1, sebury2, sebury3);
+                       PrintAndLog("Pattern Sebury : %d %d %d  [0x%X 0x%X 0x%X]", sebury1, sebury2, sebury3, sebury1, sebury2, sebury3);
                }
        }
        return;
@@ -430,20 +275,23 @@ int ASKmanDemod(const char *Cmd, bool verbose, bool emSearch)
                clk=0;
        }
        size_t BitLen = getFromGraphBuf(BitStream);
-       if (g_debugMode==1) PrintAndLog("DEBUG: Bitlen from grphbuff: %d",BitLen);
-       if (BitLen==0) return 0;
-       int errCnt=0;
+       if (g_debugMode) PrintAndLog("DEBUG: Bitlen from grphbuff: %d",BitLen);
+       if (!BitLen) return 0;
        if (maxLen<BitLen && maxLen != 0) BitLen = maxLen;
-       errCnt = askmandemod(BitStream, &BitLen, &clk, &invert, maxErr);
+       int errCnt = askmandemod(BitStream, &BitLen, &clk, &invert, maxErr);
        if (errCnt<0||BitLen<16){  //if fatal error (or -1)
-               if (g_debugMode==1) PrintAndLog("no data found %d, errors:%d, bitlen:%d, clock:%d",errCnt,invert,BitLen,clk);
+               if (g_debugMode) PrintAndLog("DEBUG: no data found %d, errors:%d, bitlen:%d, clock:%d",errCnt,invert,BitLen,clk);
                return 0;
        }
-       if (verbose || g_debugMode) PrintAndLog("\nUsing Clock: %d - Invert: %d - Bits Found: %d",clk,invert,BitLen);
+       if (errCnt>maxErr){
+               if (g_debugMode) PrintAndLog("DEBUG: Too many errors found, errors:%d, bits:%d, clock:%d",errCnt, BitLen, clk);
+               return 0;
+       }
+       if (verbose || g_debugMode) PrintAndLog("\nUsing Clock:%d, Invert:%d, Bits Found:%d",clk,invert,BitLen);
 
        //output
        if (errCnt>0){
-               if (verbose || g_debugMode) PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt);
+               if (verbose || g_debugMode) PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt);
        }
        if (verbose || g_debugMode) PrintAndLog("ASK/Manchester decoded bitstream:");
        // Now output the bitstream to the scrollback by line of 16 bits
@@ -519,7 +367,7 @@ int Cmdmandecoderaw(const char *Cmd)
                BitStream[i]=DemodBuffer[i];
        }
        if (high>1 || low <0 ){
-               PrintAndLog("Error: please raw demod the wave first then mancheseter raw decode");
+               PrintAndLog("Error: please raw demod the wave first then manchester raw decode");
                return 0;
        }
        size=i;
@@ -529,7 +377,7 @@ int Cmdmandecoderaw(const char *Cmd)
                return 0;
        }
        PrintAndLog("Manchester Decoded - # errors:%d - data:",errCnt);
-       printBitStream(BitStream, size);
+       PrintAndLog("%s", sprint_bin_break(BitStream, size, 16));
        if (errCnt==0){
                uint64_t id = 0;
                uint32_t hi = 0;
@@ -549,11 +397,7 @@ int Cmdmandecoderaw(const char *Cmd)
 //take 01 or 10 = 0 and 11 or 00 = 1
 //takes 2 arguments "offset" default = 0 if 1 it will shift the decode by one bit
 // and "invert" default = 0 if 1 it will invert output
-//  since it is not like manchester and doesn't have an incorrect bit pattern we
-//  cannot determine if our decode is correct or if it should be shifted by one bit
-//  the argument offset allows us to manually shift if the output is incorrect
-//  (better would be to demod and decode at the same time so we can distinguish large
-//    width waves vs small width waves to help the decode positioning) or askbiphdemod
+//  the argument offset allows us to manually shift if the output is incorrect - [EDIT: now auto detects]
 int CmdBiphaseDecodeRaw(const char *Cmd)
 {
        size_t size=0;
@@ -592,39 +436,15 @@ int CmdBiphaseDecodeRaw(const char *Cmd)
        }
 
        if (errCnt>0){
-               PrintAndLog("# Errors found during Demod (shown as 77 in bit stream): %d",errCnt);
+               PrintAndLog("# Errors found during Demod (shown as 7 in bit stream): %d",errCnt);
        }
        PrintAndLog("Biphase Decoded using offset: %d - # invert:%d - data:",offset,invert);
-       printBitStream(BitStream, size);
+       PrintAndLog("%s", sprint_bin_break(BitStream, size, 16));
        
        if (offset) setDemodBuf(DemodBuffer,DemodBufferLen-offset, offset);  //remove first bit from raw demod
        return 1;
 }
 
-// set demod buffer back to raw after biphase demod
-void setBiphasetoRawDemodBuf(uint8_t *BitStream, size_t size)
-{
-       uint8_t rawStream[512]={0x00};
-       size_t i=0;
-       uint8_t curPhase=0;
-       if (size > 256) {
-               PrintAndLog("ERROR - Biphase Demod Buffer overrun");
-               return;
-       }
-       for (size_t idx=0; idx<size; idx++){
-               if(!BitStream[idx]){
-                       rawStream[i++] = curPhase;
-                       rawStream[i++] = curPhase;
-                       curPhase ^= 1; 
-               } else {
-                       rawStream[i++] = curPhase;
-                       rawStream[i++] = curPhase ^ 1;
-               }
-       }
-       setDemodBuf(rawStream,i,0);
-       return;
-}
-
 //by marshmellow
 //takes 4 arguments - clock, invert, maxErr as integers and amplify as char
 //attempts to demodulate ask only
@@ -649,26 +469,31 @@ int ASKrawDemod(const char *Cmd, bool verbose)
        if (amp == 'a' || amp == 'A') askAmp=1; 
        size_t BitLen = getFromGraphBuf(BitStream);
        if (BitLen==0) return 0;
-       int errCnt=0;
-       errCnt = askrawdemod(BitStream, &BitLen, &clk, &invert, maxErr, askAmp);
+       int errCnt = askrawdemod(BitStream, &BitLen, &clk, &invert, maxErr, askAmp);
        if (errCnt==-1||BitLen<16){  //throw away static - allow 1 and -1 (in case of threshold command first)
                if (verbose || g_debugMode) PrintAndLog("no data found");
                if (g_debugMode) PrintAndLog("errCnt: %d, BitLen: %d, clk: %d, invert: %d", errCnt, BitLen, clk, invert);
                return 0;
        }
-       if (verbose || g_debugMode) PrintAndLog("Using Clock: %d - invert: %d - Bits Found: %d", clk, invert, BitLen);
+       if (errCnt>maxErr) {
+               if (g_debugMode) 
+                       PrintAndLog("Too many errors found, errCnt: %d, BitLen: %d, clk: %d, invert: %d", errCnt, BitLen, clk, invert);
+               return 0;
+       }
+       if (verbose || g_debugMode) 
+               PrintAndLog("Using Clock: %d - invert: %d - Bits Found: %d", clk, invert, BitLen);
        
        //move BitStream back to DemodBuffer
        setDemodBuf(BitStream,BitLen,0);
 
        //output
        if (errCnt>0 && (verbose || g_debugMode)){
-               PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d", errCnt);
+               PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d", errCnt);
        }
        if (verbose || g_debugMode){
                PrintAndLog("ASK demoded bitstream:");
                // Now output the bitstream to the scrollback by line of 16 bits
-               printBitStream(BitStream,BitLen);
+               printDemodBuff();
        } 
        return 1;
 }
@@ -937,67 +762,6 @@ int CmdBitsamples(const char *Cmd)
        return 0;
 }
 
-/*
- * Convert to a bitstream
- */
-int CmdBitstream(const char *Cmd)
-{
-       int i, j;
-       int bit;
-       int gtl;
-       int clock;
-       int low = 0;
-       int high = 0;
-       int hithigh, hitlow, first;
-
-       /* Detect high and lows and clock */
-       for (i = 0; i < GraphTraceLen; ++i)
-       {
-               if (GraphBuffer[i] > high)
-                       high = GraphBuffer[i];
-               else if (GraphBuffer[i] < low)
-                       low = GraphBuffer[i];
-       }
-
-       /* Get our clock */
-       clock = GetAskClock(Cmd, high, 1);
-       gtl = ClearGraph(0);
-
-       bit = 0;
-       for (i = 0; i < (int)(gtl / clock); ++i)
-       {
-               hithigh = 0;
-               hitlow = 0;
-               first = 1;
-               /* Find out if we hit both high and low peaks */
-               for (j = 0; j < clock; ++j)
-               {
-                       if (GraphBuffer[(i * clock) + j] == high)
-                               hithigh = 1;
-                       else if (GraphBuffer[(i * clock) + j] == low)
-                               hitlow = 1;
-                       /* it doesn't count if it's the first part of our read
-                                because it's really just trailing from the last sequence */
-                       if (first && (hithigh || hitlow))
-                               hithigh = hitlow = 0;
-                       else
-                               first = 0;
-
-                       if (hithigh && hitlow)
-                               break;
-               }
-
-               /* If we didn't hit both high and low peaks, we had a bit transition */
-               if (!hithigh || !hitlow)
-                       bit ^= 1;
-
-               AppendGraph(0, clock, bit);
-       }
-
-       RepaintGraphWindow();
-       return 0;
-}
-
 int CmdBuffClear(const char *Cmd)
 {
        UsbCommand c = {CMD_BUFF_CLEAR};
@@ -1076,7 +840,7 @@ int CmdGraphShiftZero(const char *Cmd)
 
 //by marshmellow
 //use large jumps in read samples to identify edges of waves and then amplify that wave to max
-//similar to dirtheshold, threshold, and askdemod commands 
+//similar to dirtheshold, threshold commands 
 //takes a threshold length which is the measured length between two samples then determines an edge
 int CmdAskEdgeDetect(const char *Cmd)
 {
@@ -1134,6 +898,25 @@ int CmdDetectClockRate(const char *Cmd)
        return ans;
 }
 
+char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert)
+{
+       char *fskType;
+       if (fchigh==10 && fclow==8){
+               if (invert) //fsk2a
+                       fskType = "FSK2a";
+               else //fsk2
+                       fskType = "FSK2";
+       } else if (fchigh == 8 && fclow == 5) {
+               if (invert)
+                       fskType = "FSK1";
+               else
+                       fskType = "FSK1a";
+       } else {
+               fskType = "FSK??";
+       }
+       return fskType;
+}
+
 //by marshmellow
 //fsk raw demod and print binary
 //takes 4 arguments - Clock, invert, fchigh, fclow
@@ -1177,21 +960,20 @@ int FSKrawDemod(const char *Cmd, bool verbose)
                rfLen = detectFSKClk(BitStream, BitLen, fchigh, fclow);
                if (rfLen == 0) rfLen = 50;
        }
-       if (verbose) 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){
                setDemodBuf(BitStream,size,0);
 
                // Now output the bitstream to the scrollback by line of 16 bits
-               if(size > (8*32)+2) size = (8*32)+2; //only output a max of 8 blocks of 32 bits  most tags will have full bit stream inside that sample size
-               if (verbose) {
-                       PrintAndLog("FSK decoded bitstream:");
-                       printBitStream(BitStream,size);
+               if (verbose || g_debugMode) {
+                       PrintAndLog("\nUsing Clock:%d, invert:%d, fchigh:%d, fclow:%d", rfLen, invert, fchigh, fclow);
+                       PrintAndLog("%s decoded bitstream:",GetFSKType(fchigh,fclow,invert));
+                       printDemodBuff();
                }
 
                return 1;
        } else{
-               if (verbose) PrintAndLog("no FSK data found");
+               if (g_debugMode) PrintAndLog("no FSK data found");
        }
        return 0;
 }
@@ -1395,9 +1177,9 @@ int CmdFSKdemodIO(const char *Cmd)
                return 0;
        }
        if (idx==0){
-               if (g_debugMode==1){
+               if (g_debugMode){
                        PrintAndLog("DEBUG: IO Prox Data not found - FSK Bits: %d",BitLen);
-                       if (BitLen > 92) printBitStream(BitStream,92);
+                       if (BitLen > 92) PrintAndLog("%s", sprint_bin_break(BitStream,92,16));
                } 
                return 0;
        }
@@ -1411,7 +1193,7 @@ int CmdFSKdemodIO(const char *Cmd)
                //XSF(version)facility:codeone+codetwo (raw)
                //Handle the data
        if (idx+64>BitLen) {
-               if (g_debugMode==1) PrintAndLog("not enough bits found - bitlen: %d",BitLen);
+               if (g_debugMode) PrintAndLog("not enough bits found - bitlen: %d",BitLen);
                return 0;
        }
        PrintAndLog("%d%d%d%d%d%d%d%d %d",BitStream[idx],    BitStream[idx+1],  BitStream[idx+2], BitStream[idx+3], BitStream[idx+4], BitStream[idx+5], BitStream[idx+6], BitStream[idx+7], BitStream[idx+8]);
@@ -1432,7 +1214,6 @@ int CmdFSKdemodIO(const char *Cmd)
 
        for (uint8_t i=1; i<6; ++i){
                calccrc += bytebits_to_byte(BitStream+idx+9*i,8);
-               //PrintAndLog("%d", calccrc);
        }
        calccrc &= 0xff;
        calccrc = 0xff - calccrc;
@@ -1690,124 +1471,6 @@ int CmdFSKdemodPyramid(const char *Cmd)
        return 1;
 }
 
-int CmdFSKdemod(const char *Cmd) //old CmdFSKdemod needs updating
-{
-       static const int LowTone[]  = {
-               1,  1,  1,  1,  1, -1, -1, -1, -1, -1,
-               1,  1,  1,  1,  1, -1, -1, -1, -1, -1,
-               1,  1,  1,  1,  1, -1, -1, -1, -1, -1,
-               1,  1,  1,  1,  1, -1, -1, -1, -1, -1,
-               1,  1,  1,  1,  1, -1, -1, -1, -1, -1
-       };
-       static const int HighTone[] = {
-               1,  1,  1,  1,  1,     -1, -1, -1, -1,
-               1,  1,  1,  1,         -1, -1, -1, -1,
-               1,  1,  1,  1,         -1, -1, -1, -1,
-               1,  1,  1,  1,         -1, -1, -1, -1,
-               1,  1,  1,  1,         -1, -1, -1, -1,
-               1,  1,  1,  1,     -1, -1, -1, -1, -1,
-       };
-
-       int lowLen = sizeof (LowTone) / sizeof (int);
-       int highLen = sizeof (HighTone) / sizeof (int);
-       int convLen = (highLen > lowLen) ? highLen : lowLen;
-       uint32_t hi = 0, lo = 0;
-
-       int i, j;
-       int minMark = 0, maxMark = 0;
-
-       for (i = 0; i < GraphTraceLen - convLen; ++i) {
-               int lowSum = 0, highSum = 0;
-
-               for (j = 0; j < lowLen; ++j) {
-                       lowSum += LowTone[j]*GraphBuffer[i+j];
-               }
-               for (j = 0; j < highLen; ++j) {
-                       highSum += HighTone[j] * GraphBuffer[i + j];
-               }
-               lowSum = abs(100 * lowSum / lowLen);
-               highSum = abs(100 * highSum / highLen);
-               GraphBuffer[i] = (highSum << 16) | lowSum;
-       }
-
-       for(i = 0; i < GraphTraceLen - convLen - 16; ++i) {
-               int lowTot = 0, highTot = 0;
-               // 10 and 8 are f_s divided by f_l and f_h, rounded
-               for (j = 0; j < 10; ++j) {
-                       lowTot += (GraphBuffer[i+j] & 0xffff);
-               }
-               for (j = 0; j < 8; j++) {
-                       highTot += (GraphBuffer[i + j] >> 16);
-               }
-               GraphBuffer[i] = lowTot - highTot;
-               if (GraphBuffer[i] > maxMark) maxMark = GraphBuffer[i];
-               if (GraphBuffer[i] < minMark) minMark = GraphBuffer[i];
-       }
-
-       GraphTraceLen -= (convLen + 16);
-       RepaintGraphWindow();
-
-       // Find bit-sync (3 lo followed by 3 high) (HID ONLY)
-       int max = 0, maxPos = 0;
-       for (i = 0; i < 6000; ++i) {
-               int dec = 0;
-               for (j = 0; j < 3 * lowLen; ++j) {
-                       dec -= GraphBuffer[i + j];
-               }
-               for (; j < 3 * (lowLen + highLen ); ++j) {
-                       dec += GraphBuffer[i + j];
-               }
-               if (dec > max) {
-                       max = dec;
-                       maxPos = i;
-               }
-       }
-
-       // place start of bit sync marker in graph
-       GraphBuffer[maxPos] = maxMark;
-       GraphBuffer[maxPos + 1] = minMark;
-
-       maxPos += j;
-
-       // place end of bit sync marker in graph
-       GraphBuffer[maxPos] = maxMark;
-       GraphBuffer[maxPos+1] = minMark;
-
-       PrintAndLog("actual data bits start at sample %d", maxPos);
-       PrintAndLog("length %d/%d", highLen, lowLen);
-
-       uint8_t bits[46] = {0x00};
-
-       // find bit pairs and manchester decode them
-       for (i = 0; i < arraylen(bits) - 1; ++i) {
-               int dec = 0;
-               for (j = 0; j < lowLen; ++j) {
-                       dec -= GraphBuffer[maxPos + j];
-               }
-               for (; j < lowLen + highLen; ++j) {
-                       dec += GraphBuffer[maxPos + j];
-               }
-               maxPos += j;
-               // place inter bit marker in graph
-               GraphBuffer[maxPos] = maxMark;
-               GraphBuffer[maxPos + 1] = minMark;
-
-               // hi and lo form a 64 bit pair
-               hi = (hi << 1) | (lo >> 31);
-               lo = (lo << 1);
-               // store decoded bit as binary (in hi/lo) and text (in bits[])
-               if(dec < 0) {
-                       bits[i] = '1';
-                       lo |= 1;
-               } else {
-                       bits[i] = '0';
-               }
-       }
-       PrintAndLog("bits: '%s'", bits);
-       PrintAndLog("hex: %08x %08x", hi, lo);
-       return 0;
-}
-
 //by marshmellow
 //attempt to psk1 demod graph buffer
 int PSKDemod(const char *Cmd, bool verbose)
@@ -1835,17 +1498,17 @@ int PSKDemod(const char *Cmd, bool verbose)
        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);
+               if (g_debugMode || verbose) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
                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);
+               if (g_debugMode || verbose) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
                return 0;
        }
-       if (verbose){
-               PrintAndLog("Tried PSK Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen);
+       if (verbose || g_debugMode){
+               PrintAndLog("\nUsing 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);
+                       PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt);
                }
        }
        //prime demod buffer for output
@@ -1970,7 +1633,7 @@ int NRZrawDemod(const char *Cmd, bool verbose)
        //prime demod buffer for output
        setDemodBuf(BitStream,BitLen,0);
 
-       if (errCnt>0 && (verbose || g_debugMode)) PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt);
+       if (errCnt>0 && (verbose || g_debugMode)) PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt);
        if (verbose || g_debugMode) {
                PrintAndLog("NRZ demoded bitstream:");
                // Now output the bitstream to the scrollback by line of 16 bits
@@ -2026,7 +1689,7 @@ int CmdPSK1rawDemod(const char *Cmd)
                return 0;
        }
  
-       PrintAndLog("PSK demoded bitstream:");
+       PrintAndLog("PSK1 demoded bitstream:");
        // Now output the bitstream to the scrollback by line of 16 bits
        printDemodBuff();
        return 1;
@@ -2295,10 +1958,10 @@ int CmdTuneSamples(const char *Cmd)
        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);
 
-#define LF_UNUSABLE_V          2948            // was 2000. Changed due to bugfix in voltage measurements. LF results are now 47% higher.
-#define LF_MARGINAL_V          14739           // was 10000. Changed due to bugfix bug in voltage measurements. LF results are now 47% higher.
-#define HF_UNUSABLE_V          3167            // was 2000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
-#define HF_MARGINAL_V          7917            // was 5000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
+ #define LF_UNUSABLE_V         2948            // was 2000. Changed due to bugfix in voltage measurements. LF results are now 47% higher.
+ #define LF_MARGINAL_V         14739           // was 10000. Changed due to bugfix bug in voltage measurements. LF results are now 47% higher.
+ #define HF_UNUSABLE_V         3167            // was 2000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
+ #define HF_MARGINAL_V         7917            // was 5000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
 
        if (peakv < LF_UNUSABLE_V)
                PrintAndLog("# Your LF antenna is unusable.");
@@ -2374,245 +2037,6 @@ int CmdRtrim(const char *Cmd)
        return 0;
 }
 
-/*
- * Manchester demodulate a bitstream. The bitstream needs to be already in
- * the GraphBuffer as 0 and 1 values
- *
- * Give the clock rate as argument in order to help the sync - the algorithm
- * resyncs at each pulse anyway.
- *
- * Not optimized by any means, this is the 1st time I'm writing this type of
- * routine, feel free to improve...
- *
- * 1st argument: clock rate (as number of samples per clock rate)
- *               Typical values can be 64, 32, 128...
- */
-int CmdManchesterDemod(const char *Cmd)
-{
-       int i, j, invert= 0;
-       int bit;
-       int clock;
-       int lastval = 0;
-       int low = 0;
-       int high = 0;
-       int hithigh, hitlow, first;
-       int lc = 0;
-       int bitidx = 0;
-       int bit2idx = 0;
-       int warnings = 0;
-
-       /* check if we're inverting output */
-       if (*Cmd == 'i')
-       {
-               PrintAndLog("Inverting output");
-               invert = 1;
-               ++Cmd;
-               do
-                       ++Cmd;
-               while(*Cmd == ' '); // in case a 2nd argument was given
-       }
-
-       /* Holds the decoded bitstream: each clock period contains 2 bits       */
-       /* later simplified to 1 bit after manchester decoding.                 */
-       /* Add 10 bits to allow for noisy / uncertain traces without aborting   */
-       /* int BitStream[GraphTraceLen*2/clock+10]; */
-
-       /* But it does not work if compiling on WIndows: therefore we just allocate a */
-       /* large array */
-       uint8_t BitStream[MAX_GRAPH_TRACE_LEN] = {0};
-
-       /* Detect high and lows */
-       for (i = 0; i < GraphTraceLen; i++)
-       {
-               if (GraphBuffer[i] > high)
-                       high = GraphBuffer[i];
-               else if (GraphBuffer[i] < low)
-                       low = GraphBuffer[i];
-       }
-
-       /* Get our clock */
-       clock = GetAskClock(Cmd, high, 1);
-
-       int tolerance = clock/4;
-
-       /* Detect first transition */
-       /* Lo-Hi (arbitrary)       */
-       /* skip to the first high */
-       for (i= 0; i < GraphTraceLen; i++)
-               if (GraphBuffer[i] == high)
-                       break;
-       /* now look for the first low */
-       for (; i < GraphTraceLen; i++)
-       {
-               if (GraphBuffer[i] == low)
-               {
-                       lastval = i;
-                       break;
-               }
-       }
-
-       /* If we're not working with 1/0s, demod based off clock */
-       if (high != 1)
-       {
-               bit = 0; /* We assume the 1st bit is zero, it may not be
-                                                       * the case: this routine (I think) has an init problem.
-                                                       * Ed.
-                                                       */
-               for (; i < (int)(GraphTraceLen / clock); i++)
-               {
-                       hithigh = 0;
-                       hitlow = 0;
-                       first = 1;
-
-                       /* Find out if we hit both high and low peaks */
-                       for (j = 0; j < clock; j++)
-                       {
-                               if (GraphBuffer[(i * clock) + j] == high)
-                                       hithigh = 1;
-                               else if (GraphBuffer[(i * clock) + j] == low)
-                                       hitlow = 1;
-
-                               /* it doesn't count if it's the first part of our read
-                                        because it's really just trailing from the last sequence */
-                               if (first && (hithigh || hitlow))
-                                       hithigh = hitlow = 0;
-                               else
-                                       first = 0;
-
-                               if (hithigh && hitlow)
-                                       break;
-                       }
-
-                       /* If we didn't hit both high and low peaks, we had a bit transition */
-                       if (!hithigh || !hitlow)
-                               bit ^= 1;
-
-                       BitStream[bit2idx++] = bit ^ invert;
-               }
-       }
-
-       /* standard 1/0 bitstream */
-       else
-       {
-
-               /* Then detect duration between 2 successive transitions */
-               for (bitidx = 1; i < GraphTraceLen; i++)
-               {
-                       if (GraphBuffer[i-1] != GraphBuffer[i])
-                       {
-                               lc = i-lastval;
-                               lastval = i;
-
-                               // Error check: if bitidx becomes too large, we do not
-                               // have a Manchester encoded bitstream or the clock is really
-                               // wrong!
-                               if (bitidx > (GraphTraceLen*2/clock+8) ) {
-                                       PrintAndLog("Error: the clock you gave is probably wrong, aborting.");
-                                       return 0;
-                               }
-                               // Then switch depending on lc length:
-                               // Tolerance is 1/4 of clock rate (arbitrary)
-                               if (abs(lc-clock/2) < tolerance) {
-                                       // Short pulse : either "1" or "0"
-                                       BitStream[bitidx++]=GraphBuffer[i-1];
-                               } else if (abs(lc-clock) < tolerance) {
-                                       // Long pulse: either "11" or "00"
-                                       BitStream[bitidx++]=GraphBuffer[i-1];
-                                       BitStream[bitidx++]=GraphBuffer[i-1];
-                               } else {
-                               // Error
-                                       warnings++;
-                                       PrintAndLog("Warning: Manchester decode error for pulse width detection.");
-                                       PrintAndLog("(too many of those messages mean either the stream is not Manchester encoded, or clock is wrong)");
-
-                                       if (warnings > 10)
-                                       {
-                                               PrintAndLog("Error: too many detection errors, aborting.");
-                                               return 0;
-                                       }
-                               }
-                       }
-               }
-
-               // At this stage, we now have a bitstream of "01" ("1") or "10" ("0"), parse it into final decoded bitstream
-               // Actually, we overwrite BitStream with the new decoded bitstream, we just need to be careful
-               // to stop output at the final bitidx2 value, not bitidx
-               for (i = 0; i < bitidx; i += 2) {
-                       if ((BitStream[i] == 0) && (BitStream[i+1] == 1)) {
-                               BitStream[bit2idx++] = 1 ^ invert;
-                       } else if ((BitStream[i] == 1) && (BitStream[i+1] == 0)) {
-                               BitStream[bit2idx++] = 0 ^ invert;
-                       } else {
-                               // We cannot end up in this state, this means we are unsynchronized,
-                               // move up 1 bit:
-                               i++;
-                               warnings++;
-                               PrintAndLog("Unsynchronized, resync...");
-                               PrintAndLog("(too many of those messages mean the stream is not Manchester encoded)");
-
-                               if (warnings > 10)
-                               {
-                                       PrintAndLog("Error: too many decode errors, aborting.");
-                                       return 0;
-                               }
-                       }
-               }
-       }
-
-       PrintAndLog("Manchester decoded bitstream");
-       // Now output the bitstream to the scrollback by line of 16 bits
-       for (i = 0; i < (bit2idx-16); i+=16) {
-               PrintAndLog("%i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i",
-                       BitStream[i],
-                       BitStream[i+1],
-                       BitStream[i+2],
-                       BitStream[i+3],
-                       BitStream[i+4],
-                       BitStream[i+5],
-                       BitStream[i+6],
-                       BitStream[i+7],
-                       BitStream[i+8],
-                       BitStream[i+9],
-                       BitStream[i+10],
-                       BitStream[i+11],
-                       BitStream[i+12],
-                       BitStream[i+13],
-                       BitStream[i+14],
-                       BitStream[i+15]);
-       }
-       return 0;
-}
-
-/* Modulate our data into manchester */
-int CmdManchesterMod(const char *Cmd)
-{
-       int i, j;
-       int clock;
-       int bit, lastbit, wave;
-
-       /* Get our clock */
-       clock = GetAskClock(Cmd, 0, 1);
-
-       wave = 0;
-       lastbit = 1;
-       for (i = 0; i < (int)(GraphTraceLen / clock); i++)
-       {
-               bit = GraphBuffer[i * clock] ^ 1;
-
-               for (j = 0; j < (int)(clock/2); j++)
-                       GraphBuffer[(i * clock) + j] = bit ^ lastbit ^ wave;
-               for (j = (int)(clock/2); j < clock; j++)
-                       GraphBuffer[(i * clock) + j] = bit ^ lastbit ^ wave ^ 1;
-
-               /* Keep track of how we start our wave and if we changed or not this time */
-               wave ^= bit ^ lastbit;
-               lastbit = bit;
-       }
-
-       RepaintGraphWindow();
-       return 0;
-}
-
 int CmdNorm(const char *Cmd)
 {
        int i;
@@ -2677,20 +2101,6 @@ int CmdScale(const char *Cmd)
        return 0;
 }
 
-int CmdThreshold(const char *Cmd)
-{
-       int threshold = atoi(Cmd);
-
-       for (int i = 0; i < GraphTraceLen; ++i) {
-               if (GraphBuffer[i] >= threshold)
-                       GraphBuffer[i] = 1;
-               else
-                       GraphBuffer[i] = -1;
-       }
-       RepaintGraphWindow();
-       return 0;
-}
-
 int CmdDirectionalThreshold(const char *Cmd)
 {
        int8_t upThres = param_get8(Cmd, 0);
@@ -2758,19 +2168,15 @@ int CmdZerocrossings(const char *Cmd)
 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"},
        {"askedgedetect",   CmdAskEdgeDetect,   1, "[threshold] Adjust Graph for manual ask demod using length of sample differences to detect the edge of a wave (default = 25)"},
        {"askem410xdemod",  CmdAskEM410xDemod,  1, "[clock] [invert<0|1>] [maxErr] -- Demodulate an EM410x tag from GraphBuffer (args optional)"},
        {"askgproxiidemod", CmdG_Prox_II_Demod, 1, "Demodulate a G Prox II tag from GraphBuffer"},
        {"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"},
        {"buffclear",       CmdBuffClear,       1, "Clear sample buffer and graph window"},
        {"dec",             CmdDec,             1, "Decimate samples"},
        {"detectclock",     CmdDetectClockRate, 1, "[modulation] Detect clock rate of wave in GraphBuffer (options: 'a','f','n','p' for ask, fsk, nrz, psk respectively)"},
-       //{"fskdemod",      CmdFSKdemod,        1, "Demodulate graph window as a HID FSK"},
        {"fskawiddemod",    CmdFSKdemodAWID,    1, "Demodulate an AWID FSK tag from GraphBuffer"},
        //{"fskfcdetect",   CmdFSKfcDetect,     1, "Try to detect the Field Clock of an FSK wave"},
        {"fskhiddemod",     CmdFSKdemodHID,     1, "Demodulate a HID FSK tag from GraphBuffer"},
@@ -2785,9 +2191,7 @@ static command_t CommandTable[] =
        {"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 in DemodBuffer"},
-       {"manmod",          CmdManchesterMod,   1, "[clock rate] -- Manchester modulate a binary stream"},
        {"norm",            CmdNorm,            1, "Normalize max/min to +/-128"},
        {"plot",            CmdPlot,            1, "Show graph window (hit 'h' in window for keystroke help)"},
        {"printdemodbuffer",CmdPrintDemodBuff,  1, "[x] -- print the data in the DemodBuffer - 'x' for hex output"},
@@ -2798,7 +2202,6 @@ static command_t CommandTable[] =
        {"scale",           CmdScale,           1, "<int> -- Set cursor display scale"},
        {"setdebugmode",    CmdSetDebugMode,    1, "<0|1> -- Turn on or off Debugging Mode for demods"},
        {"shiftgraphzero",  CmdGraphShiftZero,  1, "<shift> -- Shift 0 for Graphed wave + or - shift value"},
-       //{"threshold",     CmdThreshold,       1, "<threshold> -- Maximize/minimize every value in the graph window depending on threshold"},
        {"dirthreshold",    CmdDirectionalThreshold,   1, "<thres up> <thres down> -- Max rising higher up-thres/ Min falling lower down-thres, keep rest as prev."},
        {"tune",            CmdTuneSamples,     0, "Get hw tune samples for graph window"},
        {"undec",           CmdUndec,           1, "Un-decimate samples by 2"},
index 97bfdbcc1a99d8b64dbd366b9e3280cc875cb828..0d2e32d6556c848ef4c96b5ad804e817b331da0c 100644 (file)
@@ -15,10 +15,7 @@ command_t * CmdDataCommands();
 
 int CmdData(const char *Cmd);
 void printDemodBuff(void);
-void printBitStream(uint8_t BitStream[], uint32_t bitLen);
 void setDemodBuf(uint8_t *buff, size_t size, size_t startIdx);
-int CmdAmp(const char *Cmd);
-int Cmdaskdemod(const char *Cmd);
 int CmdAskEM410xDemod(const char *Cmd);
 int CmdG_Prox_II_Demod(const char *Cmd);
 int Cmdaskrawdemod(const char *Cmd);
@@ -27,12 +24,10 @@ int AutoCorrelate(int window, bool SaveGrph, bool verbose);
 int CmdAutoCorr(const char *Cmd);
 int CmdBiphaseDecodeRaw(const char *Cmd);
 int CmdBitsamples(const char *Cmd);
-int CmdBitstream(const char *Cmd);
 int CmdBuffClear(const char *Cmd);
 int CmdDec(const char *Cmd);
 int CmdDetectClockRate(const char *Cmd);
 int CmdFSKdemodAWID(const char *Cmd);
-int CmdFSKdemod(const char *Cmd);
 int CmdFSKdemodHID(const char *Cmd);
 int CmdFSKdemodIO(const char *Cmd);
 int CmdFSKdemodParadox(const char *Cmd);
@@ -49,8 +44,6 @@ int CmdLoad(const char *Cmd);
 int CmdLtrim(const char *Cmd);
 int CmdRtrim(const char *Cmd);
 int Cmdmandecoderaw(const char *Cmd);
-int CmdManchesterDemod(const char *Cmd);
-int CmdManchesterMod(const char *Cmd);
 int CmdNorm(const char *Cmd);
 int CmdNRZrawDemod(const char *Cmd);
 int CmdPlot(const char *Cmd);
@@ -60,7 +53,6 @@ int CmdSamples(const char *Cmd);
 int CmdTuneSamples(const char *Cmd);
 int CmdSave(const char *Cmd);
 int CmdScale(const char *Cmd);
-int CmdThreshold(const char *Cmd);
 int CmdDirectionalThreshold(const char *Cmd);
 int CmdZerocrossings(const char *Cmd);
 int CmdIndalaDecode(const char *Cmd);
index 3d29fc071426f3e8cbc1b98f3722dfd1160d0395..a52e142380f4c41505615b917a33ad68f9d02768 100644 (file)
@@ -522,7 +522,8 @@ static void ChkBitstream(const char *str)
                }
        }
 }
-//appears to attempt to simulate manchester
+//Attempt to simulate any wave in buffer (one bit per output sample)
+// converts GraphBuffer to bitstream (based on zero crossings) if needed.
 int CmdLFSim(const char *Cmd)
 {
        int i,j;
@@ -530,11 +531,11 @@ int CmdLFSim(const char *Cmd)
 
        sscanf(Cmd, "%i", &gap);
 
-       /* convert to bitstream if necessary */
+       // convert to bitstream if necessary 
 
        ChkBitstream(Cmd);
 
-       //can send 512 bits at a time (1 byte sent per bit...)
+       //can send only 512 bits at a time (1 byte sent per bit...)
        printf("Sending [%d bytes]", GraphTraceLen);
        for (i = 0; i < GraphTraceLen; i += USB_CMD_DATA_SIZE) {
                UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}};
@@ -606,8 +607,8 @@ int usage_lf_simpsk(void)
 // - allow pull data from DemodBuffer
 int CmdLFfskSim(const char *Cmd)
 {
-       //might be able to autodetect FC and clock from Graphbuffer if using demod buffer
-       //will need FChigh, FClow, Clock, and bitstream
+       //might be able to autodetect FCs and clock from Graphbuffer if using demod buffer
+       // otherwise will need FChigh, FClow, Clock, and bitstream
        uint8_t fcHigh=0, fcLow=0, clk=0;
        uint8_t invert=0;
        bool errors = FALSE;
@@ -682,6 +683,8 @@ int CmdLFfskSim(const char *Cmd)
        } else {
                setDemodBuf(data, dataLen, 0);
        }
+
+       //default if not found
        if (clk == 0) clk = 50;
        if (fcHigh == 0) fcHigh = 10;
        if (fcLow == 0) fcLow = 8;
@@ -706,9 +709,8 @@ int CmdLFfskSim(const char *Cmd)
 int CmdLFaskSim(const char *Cmd)
 {
        //autodetect clock from Graphbuffer if using demod buffer
-       //will need clock, invert, manchester/raw as m or r, separator as s, and bitstream
+       // needs clock, invert, manchester/raw as m or r, separator as s, and bitstream
        uint8_t encoding = 1, separator = 0;
-       //char cmdp = Cmd[0], par3='m', par4=0;
        uint8_t clk=0, invert=0;
        bool errors = FALSE;
        char hexData[32] = {0x00}; 
@@ -913,30 +915,6 @@ int CmdLFSimBidir(const char *Cmd)
        return 0;
 }
 
-/* simulate an LF Manchester encoded tag with specified bitstream, clock rate and inter-id gap */
-/*
-int CmdLFSimManchester(const char *Cmd)
-{
-       static int clock, gap;
-       static char data[1024], gapstring[8];
-
-       sscanf(Cmd, "%i %s %i", &clock, &data[0], &gap);
-
-       ClearGraph(0);
-
-       for (int i = 0; i < strlen(data) ; ++i)
-               AppendGraph(0, clock, data[i]- '0');
-
-       CmdManchesterMod("");
-
-       RepaintGraphWindow();
-
-       sprintf(&gapstring[0], "%i", gap);
-       CmdLFSim(gapstring);
-       return 0;
-}
-*/
-
 int CmdVchDemod(const char *Cmd)
 {
        // Is this the entire sync pattern, or does this also include some
@@ -1033,8 +1011,8 @@ int CmdLFfind(const char *Cmd)
        }
 
        if (!offline && (cmdp != '1')){
-               ans=CmdLFRead("");
-               ans=CmdSamples("20000");
+               CmdLFRead("s");
+               getSamples("30000",false);
        } else if (GraphTraceLen < 1000) {
                PrintAndLog("Data in Graphbuffer was too small.");
                return 0;
@@ -1105,20 +1083,18 @@ int CmdLFfind(const char *Cmd)
                PrintAndLog("\nChecking for Unknown tags:\n");
                ans=AutoCorrelate(4000, FALSE, FALSE);
                if (ans > 0) PrintAndLog("Possible Auto Correlation of %d repeating samples",ans);
-               ans=GetFskClock("",FALSE,FALSE); //CmdDetectClockRate("F"); //
+               ans=GetFskClock("",FALSE,FALSE); 
                if (ans != 0){ //fsk
-                       ans=FSKrawDemod("",FALSE);
+                       ans=FSKrawDemod("",TRUE);
                        if (ans>0) {
                                PrintAndLog("\nUnknown FSK Modulated Tag Found!");
-                               printDemodBuff();
                                return 1;
                        }
                }
-               ans=ASKmanDemod("",FALSE,FALSE);
+               ans=ASKmanDemod("0 0 0",TRUE,FALSE);
                if (ans>0) {
                        PrintAndLog("\nUnknown ASK Modulated and Manchester encoded Tag Found!");
                        PrintAndLog("\nif it does not look right it could instead be ASK/Biphase - try 'data rawdemod ab'");
-                       printDemodBuff();
                        return 1;
                }
                ans=CmdPSK1rawDemod("");
@@ -1126,7 +1102,6 @@ int CmdLFfind(const char *Cmd)
                        PrintAndLog("Possible unknown PSK1 Modulated Tag Found above!\n\nCould also be PSK2 - try 'data rawdemod p2'");
                        PrintAndLog("\nCould also be PSK3 - [currently not supported]");
                        PrintAndLog("\nCould also be NRZ - try 'data nrzrawdemod");
-                       printDemodBuff();
                        return 1;
                }
                PrintAndLog("\nNo Data Found!\n");
@@ -1152,7 +1127,6 @@ static command_t CommandTable[] =
        {"simfsk",      CmdLFfskSim,        0, "[c <clock>] [i] [H <fcHigh>] [L <fcLow>] [d <hexdata>] -- Simulate LF FSK tag from demodbuffer or input"},
        {"simpsk",      CmdLFpskSim,        0, "[1|2|3] [c <clock>] [i] [r <carrier>] [d <raw hex to sim>] -- Simulate LF PSK tag from demodbuffer or input"},
        {"simbidir",    CmdLFSimBidir,      0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"},
-       //{"simman",      CmdLFSimManchester, 0, "<Clock> <Bitstream> [GAP] Simulate arbitrary Manchester LF tag"},
        {"snoop",       CmdLFSnoop,         0, "['l'|'h'|<divisor>] [trigger threshold]-- Snoop LF (l:125khz, h:134khz)"},
        {"ti",          CmdLFTI,            1, "{ TI RFIDs... }"},
        {"hitag",       CmdLFHitag,         1, "{ Hitag tags and transponders... }"},
index 254d8807b5aef5f40870910fc19239b93fda0510..7dd1b044ddd07b884d4eb54db34e76a61e280d89 100644 (file)
@@ -23,7 +23,6 @@ int CmdLFaskSim(const char *Cmd);
 int CmdLFfskSim(const char *Cmd);
 int CmdLFpskSim(const char *Cmd);
 int CmdLFSimBidir(const char *Cmd);
-//int CmdLFSimManchester(const char *Cmd);
 int CmdLFSnoop(const char *Cmd);
 int CmdVchDemod(const char *Cmd);
 int CmdLFfind(const char *Cmd);
index 47a5ac3e7b8b4647967270c69b0a7110c06842e5..552c256e1416f42efe7ce7c94e43b1a3718d22c9 100644 (file)
@@ -140,7 +140,6 @@ int CmdEM410xSim(const char *Cmd)
  *       rate gets lower, then grow the number of samples
  *  Changed by martin, 4000 x 4 = 16000, 
  *  see http://www.proxmark.org/forum/viewtopic.php?pid=7235#p7235
-
 */
 int CmdEM410xWatch(const char *Cmd)
 {
@@ -151,7 +150,7 @@ int CmdEM410xWatch(const char *Cmd)
                }
                
                CmdLFRead("s");
-               getSamples("8192",true); //capture enough to get 2 full messages                
+               getSamples("8201",true); //capture enough to get 2 complete preambles (4096*2+9)        
        } while (!CmdEM410xRead(""));
 
        return 0;
index c6d54e78e24bbbbbf44f9342cdbb7c6567f278d6..4e103f1ad468e5555916330603c8758566f78fbf 100644 (file)
@@ -17,7 +17,7 @@
 #include "cmdlfhid.h"
 
 static int CmdHelp(const char *Cmd);
-
+/*
 int CmdHIDDemod(const char *Cmd)
 {
   if (GraphTraceLen < 4800) {
@@ -36,7 +36,7 @@ int CmdHIDDemod(const char *Cmd)
   RepaintGraphWindow();
   return 0;
 }
-
+*/
 int CmdHIDDemodFSK(const char *Cmd)
 {
   int findone=0;
@@ -106,7 +106,7 @@ int CmdHIDClone(const char *Cmd)
 static command_t CommandTable[] = 
 {
   {"help",      CmdHelp,        1, "This help"},
-  {"demod",     CmdHIDDemod,    1, "Demodulate HID Prox Card II (not optimal)"},
+  //{"demod",     CmdHIDDemod,    1, "Demodulate HID Prox Card II (not optimal)"},
   {"fskdemod",  CmdHIDDemodFSK, 0, "['1'] Realtime HID FSK demodulator (option '1' for one tag only)"},
   {"sim",       CmdHIDSim,      0, "<ID> -- HID tag simulator"},
   {"clone",     CmdHIDClone,    0, "<ID> ['l'] -- Clone HID to T55x7 (tag must be in antenna)(option 'l' for 84bit ID)"},
index 328f3b1326153f22f94dbdb90d64e201ee8d2745..7021492b862da411abd99ca9112667999307fc6c 100644 (file)
@@ -12,9 +12,9 @@
 #define CMDLFHID_H__
 
 int CmdLFHID(const char *Cmd);
-
-int CmdHIDDemod(const char *Cmd);
+//int CmdHIDDemod(const char *Cmd);
 int CmdHIDDemodFSK(const char *Cmd);
 int CmdHIDSim(const char *Cmd);
+int CmdHIDClone(const char *Cmd);
 
 #endif
index 14ce5498dc3f16752410019f2f652f5c38520f85..aa21c44babed25eaf079db697c7351afcb7fcc84 100644 (file)
@@ -24,7 +24,7 @@ int CmdIODemodFSK(const char *Cmd)
   SendCommand(&c);
   return 0;
 }
-
+/*
 int CmdIOProxDemod(const char *Cmd){
   if (GraphTraceLen < 4800) {
     PrintAndLog("too short; need at least 4800 samples");
@@ -37,7 +37,7 @@ int CmdIOProxDemod(const char *Cmd){
   RepaintGraphWindow();
   return 0;
 }  
-
+*/
 int CmdIOClone(const char *Cmd)
 {
   unsigned int hi = 0, lo = 0;
@@ -67,7 +67,7 @@ int CmdIOClone(const char *Cmd)
 static command_t CommandTable[] = 
 {
   {"help",        CmdHelp,            1, "This help"},
-  {"demod",      CmdIOProxDemod,     1, "Demodulate Stream"},
+  //{"demod",    CmdIOProxDemod,     1, "Demodulate Stream"},
   {"fskdemod",    CmdIODemodFSK,      0, "['1'] Realtime IO FSK demodulator (option '1' for one tag only)"},
   {"clone",      CmdIOClone,         0, "Clone ioProx Tag"},
   {NULL, NULL, 0, NULL}
@@ -83,4 +83,4 @@ int CmdHelp(const char *Cmd)
 {
   CmdsHelp(CommandTable);
   return 0;
-}
\ No newline at end of file
+}
index b6b29c053240496b512951d4188f37c23997da29..64c999d679427e62f4fb46a54b27f289aa6a5413 100644 (file)
@@ -147,31 +147,37 @@ int CmdT55xxSetConfig(const char *Cmd) {
                        param_getstr(Cmd, cmdp+1, modulation);\r
                        cmdp += 2;\r
 \r
-                       if ( strcmp(modulation, "FSK" ) == 0)\r
+                       if ( strcmp(modulation, "FSK" ) == 0) {\r
                                config.modulation = DEMOD_FSK;\r
-                       else if ( strcmp(modulation, "FSK1" ) == 0)\r
+                       } else if ( strcmp(modulation, "FSK1" ) == 0) {\r
                                config.modulation = DEMOD_FSK1;\r
-                       else if ( strcmp(modulation, "FSK1a" ) == 0)\r
+                               config.inverted=1;\r
+                       } else if ( strcmp(modulation, "FSK1a" ) == 0) {\r
                                config.modulation = DEMOD_FSK1a;\r
-                       else if ( strcmp(modulation, "FSK2" ) == 0)\r
+                               config.inverted=0;\r
+                       } else if ( strcmp(modulation, "FSK2" ) == 0) {\r
                                config.modulation = DEMOD_FSK2;\r
-                       else if ( strcmp(modulation, "FSK2a" ) == 0)\r
+                               config.inverted=0;\r
+                       } else if ( strcmp(modulation, "FSK2a" ) == 0) {\r
                                config.modulation = DEMOD_FSK2a;\r
-                       else if ( strcmp(modulation, "ASK" ) == 0)\r
+                               config.inverted=1;\r
+                       } else if ( strcmp(modulation, "ASK" ) == 0) {\r
                                config.modulation = DEMOD_ASK;\r
-                       else if ( strcmp(modulation, "NRZ" ) == 0)\r
+                       } else if ( strcmp(modulation, "NRZ" ) == 0) {\r
                                config.modulation = DEMOD_NRZ;\r
-                       else if ( strcmp(modulation, "PSK1" ) == 0)\r
+                       } else if ( strcmp(modulation, "PSK1" ) == 0) {\r
                                config.modulation = DEMOD_PSK1;\r
-                       else if ( strcmp(modulation, "PSK2" ) == 0)\r
+                       } else if ( strcmp(modulation, "PSK2" ) == 0) {\r
                                config.modulation = DEMOD_PSK2;\r
-                       else if ( strcmp(modulation, "PSK3" ) == 0)\r
+                       } else if ( strcmp(modulation, "PSK3" ) == 0) {\r
                                config.modulation = DEMOD_PSK3;\r
-                       else if ( strcmp(modulation, "BIa" ) == 0)\r
+                       } else if ( strcmp(modulation, "BIa" ) == 0) {\r
                                config.modulation = DEMOD_BIa;\r
-                       else if ( strcmp(modulation, "BI" ) == 0)\r
+                               config.inverted=1;\r
+                       } else if ( strcmp(modulation, "BI" ) == 0) {\r
                                config.modulation = DEMOD_BI;\r
-                       else {\r
+                               config.inverted=0;\r
+                       } else {\r
                                PrintAndLog("Unknown modulation '%s'", modulation);\r
                                errors = TRUE;\r
                        }\r
@@ -264,55 +270,36 @@ bool DecodeT55xxBlock(){
 \r
        switch( config.modulation ){\r
                case DEMOD_FSK:\r
-                       //CmdLtrim("26");\r
                        sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
                        CmdLtrim(cmdStr);                       \r
                        sprintf(cmdStr,"%d %d", bitRate[config.bitrate], config.inverted );\r
                        ans = FSKrawDemod(cmdStr, FALSE);\r
                        break;\r
                case DEMOD_FSK1:\r
-                       //CmdLtrim("26");\r
-                       sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
-                       CmdLtrim(cmdStr);                       \r
-                       sprintf(cmdStr,"%d 1 8 5", bitRate[config.bitrate] );\r
-                       ans = FSKrawDemod(cmdStr, FALSE);\r
-                       break;\r
                case DEMOD_FSK1a:\r
-                       //CmdLtrim("26");\r
                        sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
                        CmdLtrim(cmdStr);                       \r
-                       sprintf(cmdStr,"%d 0 8 5", bitRate[config.bitrate] );\r
+                       sprintf(cmdStr,"%d %d 8 5", bitRate[config.bitrate], config.inverted );\r
                        ans = FSKrawDemod(cmdStr, FALSE);\r
                        break;\r
                case DEMOD_FSK2:\r
-                       //CmdLtrim("26");\r
-                       sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
-                       CmdLtrim(cmdStr);                       \r
-                       sprintf(cmdStr,"%d 0 10 8", bitRate[config.bitrate] );\r
-                       ans = FSKrawDemod(cmdStr, FALSE);\r
-                       break;\r
                case DEMOD_FSK2a:\r
-                       //CmdLtrim("26");\r
                        sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
                        CmdLtrim(cmdStr);                       \r
-                       sprintf(cmdStr,"%d 1 10 8", bitRate[config.bitrate] );\r
+                       sprintf(cmdStr,"%d %d 10 8", bitRate[config.bitrate], config.inverted );\r
                        ans = FSKrawDemod(cmdStr, FALSE);\r
                        break;\r
                case DEMOD_ASK:\r
-                       sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted );\r
+                       sprintf(cmdStr,"%d %d 0", bitRate[config.bitrate], config.inverted );\r
                        ans = ASKmanDemod(cmdStr, FALSE, FALSE);\r
                        break;\r
                case DEMOD_PSK1:\r
-                       sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted );\r
-                       ans = PSKDemod(cmdStr, FALSE);\r
-                       break;\r
-               case DEMOD_PSK2:\r
-                       sprintf(cmdStr,"%d 1", bitRate[config.bitrate] );\r
+                       sprintf(cmdStr,"%d %d 0", bitRate[config.bitrate], config.inverted );\r
                        ans = PSKDemod(cmdStr, FALSE);\r
-                       psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                        break;\r
-               case DEMOD_PSK3:\r
-                       sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted );\r
+               case DEMOD_PSK2: //inverted won't affect this\r
+               case DEMOD_PSK3: //not fully implemented\r
+                       sprintf(cmdStr,"%d 0 1", bitRate[config.bitrate] );\r
                        ans = PSKDemod(cmdStr, FALSE);\r
                        psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
                        break;\r
@@ -321,11 +308,8 @@ bool DecodeT55xxBlock(){
                        ans = NRZrawDemod(cmdStr, FALSE);\r
                        break;\r
                case DEMOD_BI:\r
-                       sprintf(cmdStr,"0 %d 0 1", bitRate[config.bitrate] );\r
-                       ans = ASKbiphaseDemod(cmdStr, FALSE);\r
-                       break;\r
                case DEMOD_BIa:\r
-                       sprintf(cmdStr,"0 %d 1 1", bitRate[config.bitrate] );\r
+                       sprintf(cmdStr,"0 %d %d 0", bitRate[config.bitrate], config.inverted );\r
                        ans = ASKbiphaseDemod(cmdStr, FALSE);\r
                        break;\r
                default:\r
@@ -516,33 +500,9 @@ bool testBitRate(uint8_t readRate, uint8_t mod){
        uint8_t detRate = 0;\r
        switch( mod ){\r
                case DEMOD_FSK:\r
-                       detRate = GetFskClock("",FALSE, FALSE); \r
-                       if (expected[readRate] == detRate) {\r
-                               config.bitrate = readRate;\r
-                               return TRUE;\r
-                       }\r
-                       break;\r
                case DEMOD_FSK1:\r
-                       detRate = GetFskClock("",FALSE, FALSE); \r
-                       if (expected[readRate] == detRate) {\r
-                               config.bitrate = readRate;\r
-                               return TRUE;\r
-                       }\r
-                       break;\r
                case DEMOD_FSK1a:\r
-                       detRate = GetFskClock("",FALSE, FALSE); \r
-                       if (expected[readRate] == detRate) {\r
-                               config.bitrate = readRate;\r
-                               return TRUE;\r
-                       }\r
-                       break;\r
                case DEMOD_FSK2:\r
-                       detRate = GetFskClock("",FALSE, FALSE); \r
-                       if (expected[readRate] == detRate) {\r
-                               config.bitrate = readRate;\r
-                               return TRUE;\r
-                       }\r
-                       break;\r
                case DEMOD_FSK2a:\r
                        detRate = GetFskClock("",FALSE, FALSE); \r
                        if (expected[readRate] == detRate) {\r
@@ -551,6 +511,8 @@ bool testBitRate(uint8_t readRate, uint8_t mod){
                        }\r
                        break;\r
                case DEMOD_ASK:\r
+               case DEMOD_BI:\r
+               case DEMOD_BIa:\r
                        detRate = GetAskClock("",FALSE, FALSE); \r
                        if (expected[readRate] == detRate) {\r
                                config.bitrate = readRate;\r
@@ -558,19 +520,7 @@ bool testBitRate(uint8_t readRate, uint8_t mod){
                        }\r
                        break;\r
                case DEMOD_PSK1:\r
-                       detRate = GetPskClock("",FALSE, FALSE); \r
-                       if (expected[readRate] == detRate) {\r
-                               config.bitrate = readRate;\r
-                               return TRUE;\r
-                       }\r
-                       break;\r
                case DEMOD_PSK2:\r
-                       detRate = GetPskClock("",FALSE, FALSE); \r
-                       if (expected[readRate] == detRate) {\r
-                               config.bitrate = readRate;\r
-                               return TRUE;\r
-                       }\r
-                       break;\r
                case DEMOD_PSK3:\r
                        detRate = GetPskClock("",FALSE, FALSE); \r
                        if (expected[readRate] == detRate) {\r
@@ -585,13 +535,6 @@ bool testBitRate(uint8_t readRate, uint8_t mod){
                                return TRUE;\r
                        }\r
                        break;\r
-               case DEMOD_BI:\r
-                       detRate = GetAskClock("",FALSE, FALSE); \r
-                       if (expected[readRate] == detRate) {\r
-                               config.bitrate = readRate;\r
-                               return TRUE;\r
-                       }\r
-                       break;\r
                default:\r
                        return FALSE;\r
        }\r
@@ -606,18 +549,18 @@ bool test(uint8_t mode, uint8_t *offset){
                si = idx;\r
                if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue;\r
 \r
-               uint8_t safer    = PackBits(si, 4, DemodBuffer); si += 4;           //master key\r
+               uint8_t safer    = PackBits(si, 4, DemodBuffer); si += 4;     //master key\r
                uint8_t resv     = PackBits(si, 4, DemodBuffer); si += 4;     //was 7 & +=7+3 //should be only 4 bits if extended mode\r
                // 2nibble must be zeroed.\r
                // moved test to here, since this gets most faults first.\r
                if ( resv > 0x00) continue;\r
 \r
-               uint8_t xtRate   = PackBits(si, 3, DemodBuffer); si += 3;   //new\r
-               uint8_t bitRate  = PackBits(si, 3, DemodBuffer); si += 3;   //new  could check bit rate\r
+               uint8_t xtRate   = PackBits(si, 3, DemodBuffer); si += 3;     //extended mode part of rate\r
+               uint8_t bitRate  = PackBits(si, 3, DemodBuffer); si += 3;     //bit rate\r
                uint8_t extend   = PackBits(si, 1, DemodBuffer); si += 1;     //bit 15 extended mode\r
-               uint8_t modread  = PackBits(si, 5, DemodBuffer); si += 5+2+1; //new\r
-               //uint8_t pskcr   = PackBits(si, 2, DemodBuffer); si += 2+1;  //new  could check psk cr\r
-               uint8_t nml01    = PackBits(si, 1, DemodBuffer); si += 1+5;   //bit 24 , 30, 31 could be tested for 0 if not extended mode\r
+               uint8_t modread  = PackBits(si, 5, DemodBuffer); si += 5+2+1; \r
+               //uint8_t pskcr   = PackBits(si, 2, DemodBuffer); si += 2+1;  //could check psk cr\r
+               uint8_t nml01    = PackBits(si, 1, DemodBuffer); si += 1+5;   //bit 24, 30, 31 could be tested for 0 if not extended mode\r
                uint8_t nml02    = PackBits(si, 2, DemodBuffer); si += 2;\r
                \r
                //if extended mode\r
@@ -628,9 +571,8 @@ bool test(uint8_t mode, uint8_t *offset){
                }\r
                //test modulation\r
                if (!testModulation(mode, modread)) continue;\r
-\r
-               *offset = idx;\r
                if (!testBitRate(bitRate, mode)) continue;\r
+               *offset = idx;\r
                return TRUE;\r
        }\r
        return FALSE;\r
@@ -922,7 +864,7 @@ int AquireData( uint8_t block ){
 }\r
 \r
 char * GetBitRateStr(uint32_t id){\r
-       static char buf[40];\r
+       static char buf[20];\r
        char *retStr = buf;\r
                switch (id){\r
                case 0: \r
@@ -957,7 +899,6 @@ char * GetBitRateStr(uint32_t id){
        return buf;\r
 }\r
 \r
-\r
 char * GetSaferStr(uint32_t id){\r
        static char buf[40];\r
        char *retStr = buf;\r
@@ -974,7 +915,7 @@ char * GetSaferStr(uint32_t id){
 }\r
 \r
 char * GetModulationStr( uint32_t id){\r
-       static char buf[40];\r
+       static char buf[60];\r
        char *retStr = buf;\r
        \r
        switch (id){\r
index ae318ddf4334d3890ed41ad245d2655b7d104c3c..089119d9482fb163490962ab7489142b308f3161 100644 (file)
@@ -53,11 +53,11 @@ void save_restoreGB(uint8_t saveOpt)
        static bool GB_Saved = false;
 
        if (saveOpt==1) { //save
-               memcpy(SavedGB,GraphBuffer, sizeof(GraphBuffer));
+               memcpy(SavedGB, GraphBuffer, sizeof(GraphBuffer));
                SavedGBlen = GraphTraceLen;
                GB_Saved=true;
        } else if (GB_Saved){
-               memcpy(GraphBuffer,SavedGB, sizeof(GraphBuffer));
+               memcpy(GraphBuffer, SavedGB, sizeof(GraphBuffer));
                GraphTraceLen = SavedGBlen;
        }
        return;
index edd9aebce96dec0a3de08dc7ad68798a9a8a0aaf..709e2014911205631f689f1970f19594573d1930 100644 (file)
@@ -121,19 +121,24 @@ char * sprint_hex(const uint8_t * data, const size_t len) {
        return buf;
 }
 
-char * sprint_bin(const uint8_t * data, const size_t len) {
+char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks) {
        
        int maxLen = ( len > 1024) ? 1024 : len;
        static char buf[1024];
-       char * tmp = buf;
-       size_t i;
+       char *tmp = buf;
 
-       for (i=0; i < maxLen; ++i, ++tmp)
-               sprintf(tmp, "%u", data[i]);
+       for (size_t i=0; i < maxLen; ++i){
+               sprintf(tmp++, "%u", data[i]);
+               if (breaks > 0 && !((i+1) % breaks))
+                       sprintf(tmp++, "%s","\n");
+       }
 
        return buf;
 }
 
+char *sprint_bin(const uint8_t *data, const size_t len) {
+       return sprint_bin_break(data, len, 0);
+}
 void num_to_bytes(uint64_t n, size_t len, uint8_t* dest)
 {
        while (len--) {
index 5001acdcb36b382649740fa99245e2c8fd943338..a6d0f49f206db2483dd656b8f431689917e0c2c7 100644 (file)
@@ -39,6 +39,7 @@ void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount);
 void print_hex(const uint8_t * data, const size_t len);
 char * sprint_hex(const uint8_t * data, const size_t len);
 char * sprint_bin(const uint8_t * data, const size_t len);
+char * sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks);
 
 void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
 uint64_t bytes_to_num(uint8_t* src, size_t len);
index c00222b3b69ca23a277f041a027c14a02d2e0feb..58221546b24da9ce67c6aa60495f325d6a911ec1 100644 (file)
@@ -81,10 +81,8 @@ uint8_t Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_
        //  otherwise could be a void with no arguments
        //set defaults
        uint32_t i = 0;
-       if (BitStream[1]>1){  //allow only 1s and 0s
-               // PrintAndLog("no data found");
-               return 0;
-       }
+       if (BitStream[1]>1) return 0;  //allow only 1s and 0s
+
        // 111111111 bit pattern represent start of frame
        //  include 0 in front to help get start pos
        uint8_t preamble[] = {0,1,1,1,1,1,1,1,1,1};
@@ -130,7 +128,7 @@ int cleanAskRawDemod(uint8_t *BinStream, size_t *size, int clk, int invert, int
                                if (smplCnt > clk-(clk/4)-1) { //full clock
                                        if (smplCnt > clk + (clk/4)+1) { //too many samples
                                                errCnt++;
-                                               BinStream[bitCnt++]=77;
+                                               BinStream[bitCnt++]=7;
                                        } else if (waveHigh) {
                                                BinStream[bitCnt++] = invert;
                                                BinStream[bitCnt++] = invert;
@@ -208,7 +206,7 @@ int askmandemod(uint8_t *BinStream, size_t *size, int *clk, int *invert, int max
                        //should have hit a high or low based on clock!!
                        //PrintAndLog("DEBUG - no wave in expected area - location: %d, expected: %d-%d, lastBit: %d - resetting search",i,(lastBit+(clk-((int)(tol)))),(lastBit+(clk+((int)(tol)))),lastBit);
                        if (bitnum > 0) {
-                               BinStream[bitnum++] = 77;
+                               BinStream[bitnum++] = 7;
                                errCnt++;
                        }               
                        lastBit += *clk;//skip over error
@@ -244,6 +242,7 @@ int manrawdecode(uint8_t * BitStream, size_t *size)
        size_t i, ii;
        uint16_t bestErr = 1000, bestRun = 0;
        if (size == 0) return -1;
+       //find correct start position [alignment]
        for (ii=0;ii<2;++ii){
                for (i=ii; i<*size-2; i+=2)
                        if (BitStream[i]==BitStream[i+1])
@@ -255,13 +254,14 @@ int manrawdecode(uint8_t * BitStream, size_t *size)
                }
                errCnt=0;
        }
+       //decode
        for (i=bestRun; i < *size-2; i+=2){
                if(BitStream[i] == 1 && (BitStream[i+1] == 0)){
                        BitStream[bitnum++]=0;
                } else if((BitStream[i] == 0) && BitStream[i+1] == 1){
                        BitStream[bitnum++]=1;
                } else {
-                       BitStream[bitnum++]=77;
+                       BitStream[bitnum++]=7;
                }
                if(bitnum>MaxBits) break;
        }
@@ -291,7 +291,7 @@ int BiphaseRawDecode(uint8_t *BitStream, size_t *size, int offset, int invert)
        for (i=offset; i<*size-3; i+=2){
                //check for phase error
                if (BitStream[i+1]==BitStream[i+2]) {
-                       BitStream[bitnum++]=77;
+                       BitStream[bitnum++]=7;
                        errCnt++;
                }
                if((BitStream[i]==1 && BitStream[i+1]==0) || (BitStream[i]==0 && BitStream[i+1]==1)){
@@ -299,7 +299,7 @@ int BiphaseRawDecode(uint8_t *BitStream, size_t *size, int offset, int invert)
                } else if((BitStream[i]==0 && BitStream[i+1]==0) || (BitStream[i]==1 && BitStream[i+1]==1)){
                        BitStream[bitnum++]=invert;
                } else {
-                       BitStream[bitnum++]=77;
+                       BitStream[bitnum++]=7;
                        errCnt++;
                }
                if(bitnum>MaxBits) break;
@@ -367,7 +367,7 @@ int askrawdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert, int max
                                BinStream[bitnum++] = *invert ^ 1;
                        } else {
                                if (bitnum > 0) {
-                                       BinStream[bitnum++]=77;
+                                       BinStream[bitnum++]=7;
                                        errCnt++;                                               
                                } 
                        }
@@ -784,8 +784,9 @@ int DetectASKClock(uint8_t dest[], size_t size, int *clock, int maxErr)
                for (i=8; i>1; i--){
                        if (clk[i] == ans) {
                                *clock = ans;
-                               clockFnd = i;
-                               break; //clock found but continue to find best startpos
+                               //clockFnd = i;
+                               return 0;  // for strong waves i don't use the 'best start position' yet...
+                               //break; //clock found but continue to find best startpos [not yet]
                        }
                }
        }
@@ -806,10 +807,11 @@ int DetectASKClock(uint8_t dest[], size_t size, int *clock, int maxErr)
                }else{
                        tol=0;
                }
-               if (!maxErr && loopCnt>clk[clkCnt]*3) loopCnt=clk[clkCnt]*3;
+               //if no errors allowed - keep start within the first clock
+               if (!maxErr && size > clk[clkCnt]*3 + tol) loopCnt=clk[clkCnt]*2;
                bestErr[clkCnt]=1000;
                //try lining up the peaks by moving starting point (try first few clocks)
-               for (ii=0; ii < loopCnt-tol-clk[clkCnt]; ii++){
+               for (ii=0; ii < loopCnt-clk[clkCnt]; ii++){
                        if (dest[ii] < peak && dest[ii] > low) continue;
 
                        errCnt=0;
@@ -849,7 +851,7 @@ int DetectASKClock(uint8_t dest[], size_t size, int *clock, int maxErr)
                        }
                }
        }
-       if (bestErr[best] > maxErr) return -1;
+       //if (bestErr[best] > maxErr) return -1;
        *clock = clk[best];
        return bestStart[best];
 }
@@ -1029,7 +1031,7 @@ void psk1TOpsk2(uint8_t *BitStream, size_t size)
        size_t i=1;
        uint8_t lastBit=BitStream[0];
        for (; i<size; i++){
-               if (BitStream[i]==77){
+               if (BitStream[i]==7){
                        //ignore errors
                } else if (lastBit!=BitStream[i]){
                        lastBit=BitStream[i];
@@ -1222,7 +1224,7 @@ int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert, int maxErr)
                        if (ignoreCnt == 0){
                                bitHigh = 0;
                                if (errBitHigh == 1){
-                                       dest[bitnum++] = 77;
+                                       dest[bitnum++] = 7;
                                        errCnt++;
                                }
                                errBitHigh=0;
@@ -1497,7 +1499,7 @@ int pskRawDemod(uint8_t dest[], size_t *size, int *clock, int *invert)
                                                //noise after a phase shift - ignore
                                        } else { //phase shift before supposed to based on clock
                                                errCnt++;
-                                               dest[numBits++] = 77;
+                                               dest[numBits++] = 7;
                                        }
                                } else if (i+1 > lastClkBit + *clock + tol + fc){
                                        lastClkBit += *clock; //no phase shift but clock bit
Impressum, Datenschutz