From: marshmellow42 Date: Sat, 15 Apr 2017 20:18:54 +0000 (-0400) Subject: finish FSK graph index changes X-Git-Tag: v3.0.0~12^2~6 X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/1c70664ae75332e17466e8d7bcba718e406da36c?ds=inline;hp=-c finish FSK graph index changes --- 1c70664ae75332e17466e8d7bcba718e406da36c diff --git a/armsrc/lfops.c b/armsrc/lfops.c index a3f7a02f..566ba1d4 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -769,6 +769,7 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol) size_t size; uint32_t hi2=0, hi=0, lo=0; int idx=0; + int dummyIdx = 0; // Configure to go in 125Khz listen mode LFSetupFPGAForADC(95, true); @@ -784,7 +785,7 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol) // FSK demodulator //size = sizeOfBigBuff; //variable size will change after demod so re initialize it before use size = 50*128*2; //big enough to catch 2 sequences of largest format - idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo); + idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo, &dummyIdx); if (idx>0 && lo>0 && (size==96 || size==192)){ // go over previously decoded manchester data and decode into usable tag ID @@ -861,7 +862,7 @@ void CmdAWIDdemodFSK(int findone, int *high, int *low, int ledcontrol) { uint8_t *dest = BigBuf_get_addr(); size_t size; - int idx=0; + int idx=0, dummyIdx=0; //clear read buffer BigBuf_Clear_keep_EM(); // Configure to go in 125Khz listen mode @@ -875,7 +876,7 @@ void CmdAWIDdemodFSK(int findone, int *high, int *low, int ledcontrol) DoAcquisition_default(-1,true); // FSK demodulator size = 50*128*2; //big enough to catch 2 sequences of largest format - idx = AWIDdemodFSK(dest, &size); + idx = AWIDdemodFSK(dest, &size, &dummyIdx); if (idx<=0 || size!=96) continue; // Index map @@ -1017,6 +1018,7 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol) uint8_t version=0; uint8_t facilitycode=0; uint16_t number=0; + int dummyIdx=0; //clear read buffer BigBuf_Clear_keep_EM(); // Configure to go in 125Khz listen mode @@ -1028,7 +1030,7 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol) DoAcquisition_default(-1,true); //fskdemod and get start index WDT_HIT(); - idx = IOdemodFSK(dest, BigBuf_max_traceLen()); + idx = IOdemodFSK(dest, BigBuf_max_traceLen(), &dummyIdx); if (idx<0) continue; //valid tag found diff --git a/client/cmddata.c b/client/cmddata.c index e291c924..87c54231 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -68,15 +68,21 @@ void save_restoreDB(uint8_t saveOpt) static uint8_t SavedDB[MAX_DEMOD_BUF_LEN]; static size_t SavedDBlen; static bool DB_Saved = false; + static int savedDemodStartIdx = 0; + static int savedDemodClock = 0; if (saveOpt==1) { //save memcpy(SavedDB, DemodBuffer, sizeof(DemodBuffer)); SavedDBlen = DemodBufferLen; DB_Saved=true; + savedDemodStartIdx = g_DemodStartIdx; + savedDemodClock = g_DemodClock; } else if (DB_Saved) { //restore memcpy(DemodBuffer, SavedDB, sizeof(DemodBuffer)); DemodBufferLen = SavedDBlen; + g_DemodClock = savedDemodClock; + g_DemodStartIdx = savedDemodStartIdx; } return; } @@ -803,7 +809,7 @@ int FSKrawDemod(const char *Cmd, bool verbose) if (!rfLen) rfLen = 50; } int startIdx = 0; - int size = fskdemod_ext(BitStream, BitLen, rfLen, invert, fchigh, fclow, &startIdx); + int size = fskdemod(BitStream, BitLen, rfLen, invert, fchigh, fclow, &startIdx); if (size > 0) { setDemodBuf(BitStream,size,0); setClockGrid(rfLen, startIdx); diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 7f0b9910..141ba172 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -88,8 +88,9 @@ int CmdFSKdemodAWID(const char *Cmd) size_t size = getFromGraphBuf(BitStream); if (size==0) return 0; + int waveIdx = 0; //get binary from fsk wave - int idx = AWIDdemodFSK(BitStream, &size); + int idx = AWIDdemodFSK(BitStream, &size, &waveIdx); if (idx<=0){ if (g_debugMode){ if (idx == -1) @@ -126,7 +127,7 @@ int CmdFSKdemodAWID(const char *Cmd) uint32_t rawHi = bytebits_to_byte(BitStream+idx+32,32); uint32_t rawHi2 = bytebits_to_byte(BitStream+idx,32); setDemodBuf(BitStream,96,idx); - setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + setClockGrid(50, waveIdx + (idx*50)); size = removeParity(BitStream, idx+8, 4, 1, 88); if (size != 66){ diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index a9693fb2..fd8e2148 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -32,7 +32,8 @@ int CmdFSKdemodHID(const char *Cmd) size_t BitLen = getFromGraphBuf(BitStream); if (BitLen==0) return 0; //get binary from fsk wave - int idx = HIDdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo); + int waveIdx = 0; + int idx = HIDdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo, &waveIdx); if (idx<0){ if (g_debugMode){ if (idx==-1){ @@ -99,7 +100,7 @@ int CmdFSKdemodHID(const char *Cmd) (unsigned int) fmtLen, (unsigned int) fc, (unsigned int) cardnum); } setDemodBuf(BitStream,BitLen,idx); - setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + setClockGrid(50, waveIdx + (idx*50)); if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); diff --git a/client/cmdlfio.c b/client/cmdlfio.c index be8cf25e..c71928ec 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -53,8 +53,9 @@ int CmdFSKdemodIO(const char *Cmd) size_t BitLen = getFromGraphBuf(BitStream); if (BitLen==0) return 0; + int waveIdx = 0; //get binary from fsk wave - idx = IOdemodFSK(BitStream,BitLen); + idx = IOdemodFSK(BitStream,BitLen, &waveIdx); if (idx<0){ if (g_debugMode){ if (idx==-1){ @@ -119,7 +120,7 @@ int CmdFSKdemodIO(const char *Cmd) PrintAndLog("IO Prox XSF(%02d)%02x:%05d (%08x%08x) [%02x %s]",version,facilitycode,number,code,code2, crc, crcStr); setDemodBuf(BitStream,64,idx); - setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + setClockGrid(64, waveIdx + (idx*64)); if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, Len: %d, Printing demod buffer:",idx,64); diff --git a/client/cmdlfparadox.c b/client/cmdlfparadox.c index 6582eb35..e918c7fe 100644 --- a/client/cmdlfparadox.c +++ b/client/cmdlfparadox.c @@ -32,8 +32,9 @@ int CmdFSKdemodParadox(const char *Cmd) uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; size_t BitLen = getFromGraphBuf(BitStream); if (BitLen==0) return 0; + int waveIdx=0; //get binary from fsk wave - int idx = ParadoxdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo); + int idx = ParadoxdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo,&waveIdx); if (idx<0){ if (g_debugMode){ if (idx==-1){ @@ -63,7 +64,7 @@ int CmdFSKdemodParadox(const char *Cmd) PrintAndLog("Paradox TAG ID: %x%08x - FC: %d - Card: %d - Checksum: %02x - RAW: %08x%08x%08x", hi>>10, (hi & 0x3)<<26 | (lo>>10), fc, cardnum, (lo>>2) & 0xFF, rawHi2, rawHi, rawLo); setDemodBuf(BitStream,BitLen,idx); - setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + setClockGrid(50, waveIdx + (idx*50)); if (g_debugMode){ PrintAndLog("DEBUG: idx: %d, len: %d, Printing Demod Buffer:", idx, BitLen); printDemodBuff(); diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index c7a6cb93..366889f3 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -96,8 +96,9 @@ int CmdFSKdemodPyramid(const char *Cmd) size_t size = getFromGraphBuf(BitStream); if (size==0) return 0; + int waveIdx=0; //get binary from fsk wave - int idx = PyramiddemodFSK(BitStream, &size); + int idx = PyramiddemodFSK(BitStream, &size, &waveIdx); if (idx < 0){ if (g_debugMode){ if (idx == -5) @@ -152,7 +153,7 @@ int CmdFSKdemodPyramid(const char *Cmd) uint32_t rawHi2 = bytebits_to_byte(BitStream+idx+32,32); uint32_t rawHi3 = bytebits_to_byte(BitStream+idx,32); setDemodBuf(BitStream,128,idx); - setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); + setClockGrid(50, waveIdx + (idx*50)); size = removeParity(BitStream, idx+8, 8, 1, 120); if (size != 105){ diff --git a/common/lfdemod.c b/common/lfdemod.c index be9d3613..d2e0fca4 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -1489,7 +1489,7 @@ size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, //by marshmellow (from holiman's base) // full fsk demod from GraphBuffer wave to decoded 1s and 0s (no mandemod) -int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) { +int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) { if (justNoise(dest, size)) return 0; // FSK demodulator size = fsk_wave_demod(dest, size, fchigh, fclow, startIdx); @@ -1497,11 +1497,6 @@ int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint return size; } -int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow) { - int startIdx=0; - return fskdemod_ext(dest, size, rfLen, invert, fchigh, fclow, &startIdx); -} - // by marshmellow // convert psk1 demod to psk2 demod // only transition waves are 1s @@ -1628,12 +1623,12 @@ int pskRawDemod(uint8_t dest[], size_t *size, int *clock, int *invert) { // by marshmellow // FSK Demod then try to locate an AWID ID -int AWIDdemodFSK(uint8_t *dest, size_t *size) { +int AWIDdemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx) { //make sure buffer has enough data if (*size < 96*50) return -1; // FSK demodulator - *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50 + *size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // fsk2a RF/50 if (*size < 96) return -3; //did we get a good demod? uint8_t preamble[] = {0,0,0,0,0,0,0,1}; @@ -1715,10 +1710,10 @@ int gProxII_Demod(uint8_t BitStream[], size_t *size) { } // loop to get raw HID waveform then FSK demodulate the TAG ID from it -int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo) { +int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) { size_t numStart=0, size2=*size, startIdx=0; - // FSK demodulator - *size = fskdemod(dest, size2,50,1,10,8); //fsk2a + // FSK demodulator fsk2a so invert and fc/10/8 + *size = fskdemod(dest, size2, 50, 1, 10, 8, waveStartIdx); if (*size < 96*2) return -2; // 00011101 bit pattern represent start of frame, 01 pattern represents a 0 and 10 represents a 1 uint8_t preamble[] = {0,0,0,1,1,1,0,1}; @@ -1743,11 +1738,11 @@ int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32 return (int)startIdx; } -int IOdemodFSK(uint8_t *dest, size_t size) { +int IOdemodFSK(uint8_t *dest, size_t size, int *waveStartIdx) { //make sure buffer has data if (size < 66*64) return -2; - // FSK demodulator - size = fskdemod(dest, size, 64, 1, 10, 8); // FSK2a RF/64 + // FSK demodulator RF/64, fsk2a so invert, and fc/10/8 + size = fskdemod(dest, size, 64, 1, 10, 8, waveStartIdx); if (size < 65) return -3; //did we get a good demod? //Index map //0 10 20 30 40 50 60 @@ -1792,10 +1787,10 @@ int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert) { } // loop to get raw paradox waveform then FSK demodulate the TAG ID from it -int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo) { +int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) { size_t numStart=0, size2=*size, startIdx=0; // FSK demodulator - *size = fskdemod(dest, size2,50,1,10,8); //fsk2a + *size = fskdemod(dest, size2,50,1,10,8,waveStartIdx); //fsk2a if (*size < 96) return -2; // 00001111 bit pattern represent start of frame, 01 pattern represents a 0 and 10 represents a 1 @@ -1835,12 +1830,12 @@ int PrescoDemod(uint8_t *dest, size_t *size) { // by marshmellow // FSK Demod then try to locate a Farpointe Data (pyramid) ID -int PyramiddemodFSK(uint8_t *dest, size_t *size) { +int PyramiddemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx) { //make sure buffer has data if (*size < 128*50) return -5; // FSK demodulator - *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50 + *size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // fsk2a RF/50 if (*size < 128) return -2; //did we get a good demod? uint8_t preamble[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; diff --git a/common/lfdemod.h b/common/lfdemod.h index 56e07e56..c926a8a4 100644 --- a/common/lfdemod.h +++ b/common/lfdemod.h @@ -32,8 +32,7 @@ extern int DetectNRZClock(uint8_t dest[], size_t size, int clock, size_t *c extern int DetectPSKClock(uint8_t dest[], size_t size, int clock, size_t *firstPhaseShift, uint8_t *curPhase, uint8_t *fc); extern int DetectStrongAskClock(uint8_t dest[], size_t size, int high, int low, int *clock); extern bool DetectST(uint8_t buffer[], size_t *size, int *foundclock, size_t *ststart, size_t *stend); -extern int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow); -extern int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx); +extern int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx); extern int getHiLo(uint8_t *BitStream, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo); extern uint32_t manchesterEncode2Bytes(uint16_t datain); extern int ManchesterEncode(uint8_t *BitStream, size_t size); @@ -49,16 +48,16 @@ extern void psk1TOpsk2(uint8_t *BitStream, size_t size); extern size_t removeParity(uint8_t *BitStream, size_t startIdx, uint8_t pLen, uint8_t pType, size_t bLen); //tag specific -extern int AWIDdemodFSK(uint8_t *dest, size_t *size); +extern int AWIDdemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx); extern uint8_t Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_t *hi, uint64_t *lo); extern int FDXBdemodBI(uint8_t *dest, size_t *size); extern int gProxII_Demod(uint8_t BitStream[], size_t *size); -extern int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo); -extern int IOdemodFSK(uint8_t *dest, size_t size); +extern int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx); +extern int IOdemodFSK(uint8_t *dest, size_t size, int *waveStartIdx); extern int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert); -extern int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo); +extern int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx); extern int PrescoDemod(uint8_t *dest, size_t *size); -extern int PyramiddemodFSK(uint8_t *dest, size_t *size); +extern int PyramiddemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx); extern int VikingDemod_AM(uint8_t *dest, size_t *size); extern int Visa2kDemod_AM(uint8_t *dest, size_t *size);