From 4e10c9ec0a5f469c586951a04b3298c8d267a9e5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 28 Sep 2020 21:09:26 +0200 Subject: [PATCH] move idteck to its own file --- client/CMakeLists.txt | 1 + client/Makefile | 1 + client/android/CMakeLists.txt | 3 +- client/src/cmddata.c | 67 ----------------- client/src/cmddata.h | 1 - client/src/cmdlf.c | 36 ++++----- client/src/cmdlfidteck.c | 136 ++++++++++++++++++++++++++++++++++ client/src/cmdlfidteck.h | 19 +++++ common/lfdemod.c | 20 ----- common/lfdemod.h | 1 - 10 files changed, 178 insertions(+), 107 deletions(-) create mode 100644 client/src/cmdlfidteck.c create mode 100644 client/src/cmdlfidteck.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index fc56b594a..dd4811435 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -253,6 +253,7 @@ set (TARGET_SOURCES ${PM3_ROOT}/client/src/cmdlfguard.c ${PM3_ROOT}/client/src/cmdlfhid.c ${PM3_ROOT}/client/src/cmdlfhitag.c + ${PM3_ROOT}/client/src/cmdlfidteck.c ${PM3_ROOT}/client/src/cmdlfindala.c ${PM3_ROOT}/client/src/cmdlfio.c ${PM3_ROOT}/client/src/cmdlfjablotron.c diff --git a/client/Makefile b/client/Makefile index f3569e037..29fb4462e 100644 --- a/client/Makefile +++ b/client/Makefile @@ -447,6 +447,7 @@ SRCS = aidsearch.c \ cmdlfgallagher.c \ cmdlfhid.c \ cmdlfhitag.c \ + cmdlfidteck.c \ cmdlfindala.c \ cmdlfio.c \ cmdlfjablotron.c \ diff --git a/client/android/CMakeLists.txt b/client/android/CMakeLists.txt index 28fc2021c..7b7335071 100644 --- a/client/android/CMakeLists.txt +++ b/client/android/CMakeLists.txt @@ -132,6 +132,7 @@ add_library(pm3rrg_rdv4 SHARED ${PM3_ROOT}/client/src/cmdlfguard.c ${PM3_ROOT}/client/src/cmdlfhid.c ${PM3_ROOT}/client/src/cmdlfhitag.c + ${PM3_ROOT}/client/src/cmdlfidteck.c ${PM3_ROOT}/client/src/cmdlfindala.c ${PM3_ROOT}/client/src/cmdlfio.c ${PM3_ROOT}/client/src/cmdlfjablotron.c @@ -209,4 +210,4 @@ target_link_libraries(pm3rrg_rdv4 pm3rrg_rdv4_reveng pm3rrg_rdv4_whereami android - log) \ No newline at end of file + log) diff --git a/client/src/cmddata.c b/client/src/cmddata.c index ffeb7f965..de0e4a78a 100644 --- a/client/src/cmddata.c +++ b/client/src/cmddata.c @@ -1277,73 +1277,6 @@ int PSKDemod(int clk, int invert, int maxErr, bool verbose) { return PM3_SUCCESS; } -int demodIdteck(bool verbose) { - (void) verbose; // unused so far - if (PSKDemod(0, 0, 100, false) != PM3_SUCCESS) { - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck PSKDemod failed"); - return PM3_ESOFT; - } - size_t size = DemodBufferLen; - - //get binary from PSK1 wave - int idx = detectIdteck(DemodBuffer, &size); - if (idx < 0) { - - if (idx == -1) - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: not enough samples"); - else if (idx == -2) - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: just noise"); - else if (idx == -3) - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: preamble not found"); - else if (idx == -4) - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: size not correct: %zu", size); - else - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: idx: %d", idx); - - // if didn't find preamble try again inverting - if (PSKDemod(0, 1, 100, false) != PM3_SUCCESS) { - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck PSKDemod failed"); - return PM3_ESOFT; - } - idx = detectIdteck(DemodBuffer, &size); - if (idx < 0) { - - if (idx == -1) - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: not enough samples"); - else if (idx == -2) - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: just noise"); - else if (idx == -3) - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: preamble not found"); - else if (idx == -4) - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: size not correct: %zu", size); - else - PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: idx: %d", idx); - - return PM3_ESOFT; - } - } - setDemodBuff(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 - PrintAndLogEx(SUCCESS, "IDTECK Tag Found: Card ID %u , Raw: %08X%08X", id, raw1, raw2); - return PM3_SUCCESS; -} - -/* -static int CmdIdteckDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far - return demodIdteck(); -} -*/ - // by marshmellow // takes 3 arguments - clock, invert, maxErr as integers // attempts to demodulate nrz only diff --git a/client/src/cmddata.h b/client/src/cmddata.h index aecce229a..86a60a9bb 100644 --- a/client/src/cmddata.h +++ b/client/src/cmddata.h @@ -80,7 +80,6 @@ int getSamplesEx(uint32_t start, uint32_t end, bool verbose); void setClockGrid(uint32_t clk, int offset); int directionalThreshold(const int *in, int *out, size_t len, int8_t up, int8_t down); int AskEdgeDetect(const int *in, int *out, int len, int threshold); -int demodIdteck(bool verbose); #define MAX_DEMOD_BUF_LEN (1024*128) extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 113ca90be..8890fd8e7 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -33,28 +33,29 @@ #include "cmdlfem4x50.h" // for em4x50 #include "cmdlfhid.h" // for hid menu #include "cmdlfhitag.h" // for hitag menu +#include "cmdlfidteck.h" // for idteck menu #include "cmdlfio.h" // for ioprox menu -#include "cmdlft55xx.h" // for t55xx menu -#include "cmdlfti.h" // for ti menu -#include "cmdlfpresco.h" // for presco menu -#include "cmdlfpcf7931.h" // for pcf7931 menu -#include "cmdlfpyramid.h" // for pyramid menu -#include "cmdlfviking.h" // for viking menu -#include "cmdlfnedap.h" // for NEDAP menu -#include "cmdlfjablotron.h" // for JABLOTRON menu -#include "cmdlfvisa2000.h" // for VISA2000 menu -#include "cmdlfnoralsy.h" // for NORALSY meny #include "cmdlfcotag.h" // for COTAG meny -#include "cmdlfindala.h" // for indala menu -#include "cmdlfguard.h" // for gproxii menu #include "cmdlffdx.h" // for fdx-b menu -#include "cmdlfparadox.h" // for paradox menu -#include "cmdlfnexwatch.h" // for nexwatch menu -#include "cmdlfsecurakey.h" // for securakey menu -#include "cmdlfpac.h" // for pac menu +#include "cmdlfgallagher.h" // for GALLAGHER menu +#include "cmdlfguard.h" // for gproxii menu +#include "cmdlfindala.h" // for indala menu +#include "cmdlfjablotron.h" // for JABLOTRON menu #include "cmdlfkeri.h" // for keri menu #include "cmdlfmotorola.h" // for Motorola menu -#include "cmdlfgallagher.h" // for GALLAGHER menu +#include "cmdlfnedap.h" // for NEDAP menu +#include "cmdlfnexwatch.h" // for nexwatch menu +#include "cmdlfnoralsy.h" // for NORALSY meny +#include "cmdlfpac.h" // for pac menu +#include "cmdlfparadox.h" // for paradox menu +#include "cmdlfpcf7931.h" // for pcf7931 menu +#include "cmdlfpresco.h" // for presco menu +#include "cmdlfpyramid.h" // for pyramid menu +#include "cmdlfsecurakey.h" // for securakey menu +#include "cmdlft55xx.h" // for t55xx menu +#include "cmdlfti.h" // for ti menu +#include "cmdlfviking.h" // for viking menu +#include "cmdlfvisa2000.h" // for VISA2000 menu #define LF_CMDREAD_MAX_EXTRA_SYMBOLS 4 static bool g_lf_threshold_set = false; @@ -1531,6 +1532,7 @@ static command_t CommandTable[] = { {"gproxii", CmdLFGuard, AlwaysAvailable, "{ Guardall Prox II RFIDs... }"}, {"hid", CmdLFHID, AlwaysAvailable, "{ HID Prox RFIDs... }"}, {"hitag", CmdLFHitag, AlwaysAvailable, "{ Hitag CHIPs... }"}, + {"idteck", CmdLFIdteck, AlwaysAvailable, "{ Idteck RFIDs... }"}, {"indala", CmdLFINDALA, AlwaysAvailable, "{ Indala RFIDs... }"}, {"io", CmdLFIO, AlwaysAvailable, "{ ioProx RFIDs... }"}, {"jablotron", CmdLFJablotron, AlwaysAvailable, "{ Jablotron RFIDs... }"}, diff --git a/client/src/cmdlfidteck.c b/client/src/cmdlfidteck.c new file mode 100644 index 000000000..1499aa7c9 --- /dev/null +++ b/client/src/cmdlfidteck.c @@ -0,0 +1,136 @@ +//----------------------------------------------------------------------------- +// Iceman, +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// Low frequency Idteck tag commands +// PSK +//----------------------------------------------------------------------------- +#include "cmdlfidteck.h" + +#include +#include +#include + +#include "common.h" + +#include "cmdparser.h" // command_t +#include "comms.h" +#include "ui.h" +#include "cmddata.h" +#include "cmdlf.h" +#include "lfdemod.h" +#include "commonutil.h" // num_to_bytes + +static int CmdHelp(const char *Cmd); + +int demodIdteck(bool verbose) { + (void) verbose; // unused so far + if (PSKDemod(0, 0, 100, false) != PM3_SUCCESS) { + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck PSKDemod failed"); + return PM3_ESOFT; + } + size_t size = DemodBufferLen; + + //get binary from PSK1 wave + int idx = detectIdteck(DemodBuffer, &size); + if (idx < 0) { + + if (idx == -1) + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: not enough samples"); + else if (idx == -2) + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: just noise"); + else if (idx == -3) + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: preamble not found"); + else if (idx == -4) + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: size not correct: %zu", size); + else + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: idx: %d", idx); + + // if didn't find preamble try again inverting + if (PSKDemod(0, 1, 100, false) != PM3_SUCCESS) { + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck PSKDemod failed"); + return PM3_ESOFT; + } + idx = detectIdteck(DemodBuffer, &size); + if (idx < 0) { + + if (idx == -1) + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: not enough samples"); + else if (idx == -2) + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: just noise"); + else if (idx == -3) + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: preamble not found"); + else if (idx == -4) + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: size not correct: %zu", size); + else + PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck: idx: %d", idx); + + return PM3_ESOFT; + } + } + setDemodBuff(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 + PrintAndLogEx(SUCCESS, "IDTECK Tag Found: Card ID %u , Raw: %08X%08X", id, raw1, raw2); + return PM3_SUCCESS; +} + +static int CmdIdteckDemod(const char *Cmd) { + (void)Cmd; // Cmd is not used so far + return demodIdteck(true); +} + +static int CmdIdteckRead(const char *Cmd) { + (void)Cmd; + lf_read(false, 5000); + return demodIdteck(true); +} + +static command_t CommandTable[] = { + {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"demod", CmdIdteckDemod, AlwaysAvailable, "Demodulate an Idteck tag from the GraphBuffer"}, + {"read", CmdIdteckRead, IfPm3Lf, "Attempt to read and Extract tag data from the antenna"}, + {NULL, NULL, NULL, NULL} +}; + +static int CmdHelp(const char *Cmd) { + (void)Cmd; // Cmd is not used so far + CmdsHelp(CommandTable); + return PM3_SUCCESS; +} + +int CmdLFIdteck(const char *Cmd) { + clearCommandBuffer(); + return CmdsParse(CommandTable, Cmd); +} + +// Find IDTEC PSK1, RF Preamble == 0x4944544B, Demodsize 64bits +// by iceman +int detectIdteck(uint8_t *dest, size_t *size) { + //make sure buffer has data + if (*size < 64 * 2) return -1; + + if (getSignalProperties()->isnoise) return -2; + + size_t start_idx = 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}; + + //preamble not found + if (!preambleSearch(dest, preamble, sizeof(preamble), size, &start_idx)) + return -3; + + // wrong demoded size + if (*size != 64) return -4; + return (int)start_idx; +} diff --git a/client/src/cmdlfidteck.h b/client/src/cmdlfidteck.h new file mode 100644 index 000000000..aefa9f5d4 --- /dev/null +++ b/client/src/cmdlfidteck.h @@ -0,0 +1,19 @@ +//----------------------------------------------------------------------------- +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// Low frequency Idteck tag commands +//----------------------------------------------------------------------------- +#ifndef CMDLFIDTECK_H__ +#define CMDLFIDTECK_H__ + +#include "common.h" + +int CmdLFIdteck(const char *Cmd); + +int demodIdteck(bool verbose); +int detectIdteck(uint8_t *dest, size_t *size); + +#endif diff --git a/common/lfdemod.c b/common/lfdemod.c index e952ed59c..7b899e99e 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -2168,26 +2168,6 @@ int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32 return (int)start_idx; } -// Find IDTEC PSK1, RF Preamble == 0x4944544B, Demodsize 64bits -// by iceman -int detectIdteck(uint8_t *dest, size_t *size) { - //make sure buffer has data - if (*size < 64 * 2) return -1; - - if (signalprop.isnoise) return -2; - - size_t start_idx = 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}; - - //preamble not found - if (!preambleSearch(dest, preamble, sizeof(preamble), size, &start_idx)) - return -3; - - // wrong demoded size - if (*size != 64) return -4; - return (int)start_idx; -} - int detectIOProx(uint8_t *dest, size_t *size, int *waveStartIdx) { //make sure buffer has data if (*size < 66 * 64) return -1; diff --git a/common/lfdemod.h b/common/lfdemod.h index 58ebd72c9..e8d516604 100644 --- a/common/lfdemod.h +++ b/common/lfdemod.h @@ -78,7 +78,6 @@ size_t removeParity(uint8_t *bits, size_t startIdx, uint8_t pLen, uint8_t pTyp int detectAWID(uint8_t *dest, size_t *size, int *waveStartIdx); int Em410xDecode(uint8_t *bits, size_t *size, size_t *start_idx, uint32_t *hi, uint64_t *lo); int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx); -int detectIdteck(uint8_t *dest, size_t *size); int detectIOProx(uint8_t *dest, size_t *size, int *waveStartIdx); #endif