From 3acac886bc2e0b89723673968af21984aa15a073 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 12 Jan 2017 00:04:36 +0100 Subject: [PATCH] ADD: 'lf search' - added a rudimentary identification of IDTECK tags, will demod to PSK1, if fails it tries to PSK1 inverted demod. --- client/cmddata.c | 57 ++++++++++++++++++++++++++++++++++++++++++ client/cmddata.h | 1 + client/cmdlf.c | 5 ++++ client/cmdlfpresco.c | 2 +- client/cmdlfvisa2000.c | 4 +-- common/lfdemod.c | 13 ++++++++++ common/lfdemod.h | 1 + 7 files changed, 80 insertions(+), 3 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 1e7947ff..f1e89f63 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -1889,6 +1889,63 @@ int CmdPSKNexWatch(const char *Cmd) return 1; } +int CmdPSKIdteck(const char *Cmd) { + + if (!PSKDemod("", false)) { + if (g_debugMode) PrintAndLog("DEBUG: Error - Idteck PSKDemod failed"); + return 0; + } + size_t size = DemodBufferLen; + + //get binary from PSK1 wave + int idx = IdteckDemodPSK(DemodBuffer, &size); + if (idx < 0){ + if (g_debugMode){ + if (idx == -1) + PrintAndLog("DEBUG: Error - Idteck: not enough samples"); + else if (idx == -2) + PrintAndLog("DEBUG: Error - Idteck: preamble not found"); + else if (idx == -3) + PrintAndLog("DEBUG: Error - Idteck: size not correct: %d", size); + else + PrintAndLog("DEBUG: Error - Idteck: idx: %d",idx); + } + + // if didn't find preamble try again inverting + if (!PSKDemod("1", false)) { + if (g_debugMode) PrintAndLog("DEBUG: Error - Idteck PSKDemod failed"); + return 0; + } + idx = IdteckDemodPSK(DemodBuffer, &size); + if (idx < 0){ + if (g_debugMode){ + if (idx == -1) + PrintAndLog("DEBUG: Error - Idteck: not enough samples"); + else if (idx == -2) + PrintAndLog("DEBUG: Error - Idteck: preamble not found"); + else if (idx == -3) + PrintAndLog("DEBUG: Error - Idteck: size not correct: %d", size); + else + PrintAndLog("DEBUG: Error - Idteck: idx: %d",idx); + } + return 0; + } + } + setDemodBuf(DemodBuffer, 64, idx); + + //got a good demod + uint32_t id = 0; + uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32); + uint32_t raw2 = bytebits_to_byte(DemodBuffer+32, 32); + + //parity check (TBD) + //checksum check (TBD) + + //output + PrintAndLog("IDTECK Tag Found: Card ID %u , Raw: %08X%08X", id, raw1, raw2); + return 1; +} + // by marshmellow // takes 3 arguments - clock, invert, maxErr as integers // attempts to demodulate nrz only diff --git a/client/cmddata.h b/client/cmddata.h index 67bf3316..b0ff5bd0 100644 --- a/client/cmddata.h +++ b/client/cmddata.h @@ -47,6 +47,7 @@ int CmdFSKrawdemod(const char *Cmd); int CmdPSK1rawDemod(const char *Cmd); int CmdPSK2rawDemod(const char *Cmd); int CmdPSKNexWatch(const char *Cmd); +int CmdPSKIdteck(const char *Cmd); int CmdGrid(const char *Cmd); int CmdGetBitStream(const char *Cmd); int CmdHexsamples(const char *Cmd); diff --git a/client/cmdlf.c b/client/cmdlf.c index e1cb1bdf..fdf454c5 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -1087,6 +1087,11 @@ int CmdLFfind(const char *Cmd) { PrintAndLog("\nValid NexWatch ID Found!"); return 1; } + ans=CmdPSKIdteck(""); + if (ans>0) { + PrintAndLog("\nValid Idteck ID Found!"); + return 1; + } ans=CmdJablotronDemod(""); if (ans>0) { PrintAndLog("\nValid Jablotron ID Found!"); diff --git a/client/cmdlfpresco.c b/client/cmdlfpresco.c index 8a9f8c5d..36f99107 100644 --- a/client/cmdlfpresco.c +++ b/client/cmdlfpresco.c @@ -116,7 +116,7 @@ int GetPrescoBits(uint32_t fullcode, uint8_t *prescoBits) { //see ASKDemod for what args are accepted int CmdPrescoDemod(const char *Cmd) { bool st = true; - //if (!ASKDemod(Cmd, false, false, 1)) { + if (!ASKDemod_ext("32 0 0", FALSE, FALSE, 1, &st)) { if (g_debugMode) PrintAndLog("DEBUG: Error Presco ASKDemod failed"); return 0; diff --git a/client/cmdlfvisa2000.c b/client/cmdlfvisa2000.c index b74a318a..9eca4052 100644 --- a/client/cmdlfvisa2000.c +++ b/client/cmdlfvisa2000.c @@ -121,13 +121,13 @@ int CmdVisa2kClone(const char *Cmd) { // blocks[2] = id; - blocks[3] = visa_chksum( id); + blocks[3] = visa_chksum(id); PrintAndLog("Preparing to clone Visa2000 to T55x7 with CardId: %u", id); PrintAndLog("Blk | Data "); PrintAndLog("----+------------"); for(int i = 0; i<4; ++i) - PrintAndLog(" %02d | 0x%08x", i , blocks[i]); + PrintAndLog(" %02d | 0x%08x", i , blocks[i]); UsbCommand resp; UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}}; diff --git a/common/lfdemod.c b/common/lfdemod.c index c35ce561..46132703 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -822,6 +822,19 @@ int NedapDemod(uint8_t *dest, size_t *size) { return (int) startIdx; } +// Find IDTEC PSK1, RF Preamble == 0x4944544B, Demodsize 64bits +// by iceman +int IdteckDemodPSK(uint8_t *dest, size_t *size) { + //make sure buffer has data + if (*size < 64*2) return -1; + size_t startIdx = 0; + uint8_t preamble[] = {0,1,0,0,1,0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0,0,1,0,1,1}; + uint8_t errChk = preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx); + if (errChk == 0) return -2; //preamble not found + if (*size != 64) return -3; // wrong demoded size + return (int) startIdx; +} + // by marshmellow // to detect a wave that has heavily clipped (clean) samples uint8_t DetectCleanAskWave(uint8_t dest[], size_t size, uint8_t high, uint8_t low) diff --git a/common/lfdemod.h b/common/lfdemod.h index 11634d00..7bd3ce40 100644 --- a/common/lfdemod.h +++ b/common/lfdemod.h @@ -60,4 +60,5 @@ int NedapDemod(uint8_t *dest, size_t *size); int JablotronDemod(uint8_t *dest, size_t *size); int Visa2kDemod_AM(uint8_t *dest, size_t *size); int NoralsyDemod_AM(uint8_t *dest, size_t *size); +int IdteckDemodPSK(uint8_t *dest, size_t *size); #endif -- 2.39.2