From: marshmellow42 Date: Tue, 14 Mar 2017 17:16:30 +0000 (-0400) Subject: add first attempt at lf miller decoding X-Git-Tag: v3.0.0~45^2~7 X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/127f149075522b280d66dbe3d11130151fd8bdcc add first attempt at lf miller decoding don't have any tags capable to test and not yet hooked up to data rawdemod... --- diff --git a/client/cmddata.c b/client/cmddata.c index e07e7223..f1e6c795 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -29,6 +29,9 @@ uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; uint8_t g_debugMode=0; size_t DemodBufferLen=0; +size_t g_demodStartIdx=0; +uint8_t g_demodClock=0; + static int CmdHelp(const char *Cmd); //set the demod buffer with given array of binary (one bit per byte) @@ -253,6 +256,7 @@ void printEM410x(uint32_t hi, uint64_t id) return; } +//should be moved to cmdlfem4x.c int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) { size_t idx = 0; @@ -274,7 +278,7 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) } return 0; } - +//should be moved to cmdlfem4x.c int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose) { bool st = true; @@ -282,6 +286,7 @@ int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose) return AskEm410xDecode(verbose, hi, lo); } +//should be moved to cmdlfem4x.c //by marshmellow //takes 3 arguments - clock, invert and maxErr as integers //attempts to demodulate ask while decoding manchester @@ -451,7 +456,8 @@ int Cmdmandecoderaw(const char *Cmd) sscanf(Cmd, "%i %i", &invert, &maxErr); size=i; - errCnt=manrawdecode(BitStream, &size, invert); + uint8_t alignPos = 0; + errCnt=manrawdecode(BitStream, &size, invert, &alignPos); if (errCnt>=maxErr){ PrintAndLog("Too many errors: %d",errCnt); return 0; @@ -590,6 +596,7 @@ int Cmdaskbiphdemod(const char *Cmd) return ASKbiphaseDemod(Cmd, true); } +//could be split to a gProxII file //by marshmellow //attempts to demodulate and identify a G_Prox_II verex/chubb card //WARNING: if it fails during some points it will destroy the DemodBuffer data @@ -655,6 +662,7 @@ int CmdG_Prox_II_Demod(const char *Cmd) return 1; } +//could be moved to a viking file //by marshmellow //see ASKDemod for what args are accepted int CmdVikingDemod(const char *Cmd) @@ -1038,6 +1046,7 @@ int CmdFSKrawdemod(const char *Cmd) return FSKrawDemod(Cmd, true); } +//move to cmdlfhid.c //by marshmellow (based on existing demod + holiman's refactor) //HID Prox demod - FSK RF/50 with preamble of 00011101 (then manchester encoded) //print full HID Prox ID and some bit format details if found @@ -1124,6 +1133,7 @@ int CmdFSKdemodHID(const char *Cmd) return 1; } + //by marshmellow //Paradox Prox demod - FSK RF/50 with preamble of 00001111 (then manchester encoded) //print full Paradox Prox ID and some bit format details if found @@ -2264,13 +2274,13 @@ int CmdDirectionalThreshold(const char *Cmd) if (GraphBuffer[i] >= upThres && GraphBuffer[i] > lastValue) { lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. - GraphBuffer[i] = 1; + GraphBuffer[i] = 127; } // Apply second threshold to samples heading down else if (GraphBuffer[i] <= downThres && GraphBuffer[i] < lastValue) { lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. - GraphBuffer[i] = -1; + GraphBuffer[i] = -127; } else { diff --git a/common/lfdemod.c b/common/lfdemod.c index 750dbf1b..fb10f686 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -1074,17 +1074,18 @@ bool DetectST(uint8_t buffer[], size_t *size, int *foundclock) { } //by marshmellow -//take 11 10 01 11 00 and make 01100 ... miller decoding +//take 11 10 01 11 00 and make 01100 ... miller decoding //check for phase errors - should never have half a 1 or 0 by itself and should never exceed 1111 or 0000 in a row //decodes miller encoded binary //NOTE askrawdemod will NOT demod miller encoded ask unless the clock is manually set to 1/2 what it is detected as! -/*int millerRawDecode(uint8_t *BitStream, size_t *size, int invert) { +int millerRawDecode(uint8_t *BitStream, size_t *size, int invert) { if (*size < 16) return -1; - uint16_t MaxBits = 512, errCnt = 0, bestErr = 1000, bestRun = 0; - size_t i, ii, bitCnt=0; - uint8_t alignCnt = 0, curBit = BitStream[0]; + uint16_t MaxBits = 512, errCnt = 0; + size_t i, bitCnt=0; + uint8_t alignCnt = 0, curBit = BitStream[0], alignedIdx = 0; + uint8_t halfClkErr = 0; //find alignment, needs 4 1s or 0s to properly align - for (i=1; i < *size; i++) { + for (i=1; i < *size-1; i++) { alignCnt = (BitStream[i] == curBit) ? alignCnt+1 : 0; curBit = BitStream[i]; if (alignCnt == 4) break; @@ -1094,8 +1095,21 @@ bool DetectST(uint8_t buffer[], size_t *size, int *foundclock) { if (g_debugMode) prnt("ERROR MillerDecode: alignment not found so either your bitstream is not miller or your data does not have a 101 in it"); return -1; } + alignedIdx = (i-1) % 2; + for (i=alignedIdx; i < *size-3; i+=2) { + halfClkErr = (uint8_t)((halfClkErr << 1 | BitStream[i]) & 0xFF); + if ( (halfClkErr & 0x7) == 5 || (halfClkErr & 0x7) == 2 || (i > 2 && (halfClkErr & 0x7) == 0) || (halfClkErr & 0x1F) == 0x1F) { + errCnt++; + BitStream[bitCnt++] = 7; + continue; + } + BitStream[bitCnt++] = BitStream[i] ^ BitStream[i+1] ^ invert; -}*/ + if (bitCnt > MaxBits) break; + } + *size = bitCnt; + return errCnt; +} //by marshmellow //take 01 or 10 = 1 and 11 or 00 = 0 @@ -1876,7 +1890,6 @@ int VikingDemod_AM(uint8_t *dest, size_t *size) { return (int) startIdx; } - // by iceman // find Visa2000 preamble in already demoded data int Visa2kDemod_AM(uint8_t *dest, size_t *size) {