From 2065d7a2c64d554ad7c6599f438593ad792f26db Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 9 Oct 2020 17:02:28 +0200 Subject: [PATCH] sub carrier and fsk clock --- client/src/cmddata.c | 43 ++++++++++++++++++++++++++++++++++++------- client/src/graph.c | 22 +++++++++++----------- client/src/graph.h | 10 +++++----- 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/client/src/cmddata.c b/client/src/cmddata.c index 9c7db0345..a7575f590 100644 --- a/client/src/cmddata.c +++ b/client/src/cmddata.c @@ -2313,11 +2313,34 @@ static int CmdDataNDEF(const char *Cmd) { typedef struct { t55xx_modulation modulation; int bitrate; + int carrier; + uint8_t fc1; + uint8_t fc2; } lf_modulation_t; static int print_modulation(lf_modulation_t b) { - PrintAndLogEx(INFO, " Modulation... " _GREEN_("%s"), GetSelectedModulationStr(b.modulation)); - PrintAndLogEx(INFO, " Bit Rate..... " _GREEN_("RF/%u"), b.bitrate); + PrintAndLogEx(INFO, " Modulation.... " _GREEN_("%s"), GetSelectedModulationStr(b.modulation)); + PrintAndLogEx(INFO, " Bit clock..... " _GREEN_("RF/%d"), b.bitrate); + switch (b.modulation) { + case DEMOD_PSK1: + case DEMOD_PSK2: + case DEMOD_PSK3: + PrintAndLogEx(SUCCESS, " Carrier rate.. %d", b.carrier); + break; + case DEMOD_FSK: + case DEMOD_FSK1: + case DEMOD_FSK1a: + case DEMOD_FSK2: + case DEMOD_FSK2a: + PrintAndLogEx(SUCCESS, " Field Clocks.. FC/%u, FC/%u", b.fc1, b.fc2); + break; + case DEMOD_NRZ: + case DEMOD_ASK: + case DEMOD_BI: + case DEMOD_BIa: + default: + break; + } PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -2326,7 +2349,8 @@ static int try_detect_modulation(void) { lf_modulation_t tests[6]; int clk = 0, firstClockEdge = 0; - uint8_t hits = 0, fc1 = 0, fc2 = 0, ans = 0; + uint8_t hits = 0, ans = 0; + uint8_t fc1 = 0, fc2 = 0; bool st = false; ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, &firstClockEdge); @@ -2335,11 +2359,15 @@ static int try_detect_modulation(void) { if ((FSKrawDemod(0, 0, 0, 0, false) == PM3_SUCCESS)) { tests[hits].modulation = DEMOD_FSK; - if (fc1 == 8 && fc2 == 5) + if (fc1 == 8 && fc2 == 5) { tests[hits].modulation = DEMOD_FSK1a; - else if (fc1 == 10 && fc2 == 8) + } else if (fc1 == 10 && fc2 == 8) { tests[hits].modulation = DEMOD_FSK2; + } + tests[hits].bitrate = clk; + tests[hits].fc1 = fc1; + tests[hits].fc2 = fc2; ++hits; } @@ -2380,13 +2408,11 @@ static int try_detect_modulation(void) { } } clk = GetNrzClock("", false); - if (clk > 8) { //clock of rf/8 is likely a false positive, so don't use it. if ((NRZrawDemod(0, 0, 1, false) == PM3_SUCCESS)) { tests[hits].modulation = DEMOD_NRZ; tests[hits].bitrate = clk; ++hits; } - } clk = GetPskClock("", false); if (clk > 0) { @@ -2398,6 +2424,9 @@ static int try_detect_modulation(void) { tests[hits].modulation = DEMOD_PSK1; tests[hits].bitrate = clk; ++hits; + + // get psk carrier + tests[hits].carrier = GetPskCarrier(false); } //undo trim samples save_restoreGB(GRAPH_RESTORE); diff --git a/client/src/graph.c b/client/src/graph.c index 3cb253b2c..21b77e427 100644 --- a/client/src/graph.c +++ b/client/src/graph.c @@ -190,12 +190,10 @@ int GetAskClock(const char *str, bool printAns) { return clock1; } -uint8_t GetPskCarrier(const char *str, bool printAns) { +int GetPskCarrier(bool verbose) { if (getSignalProperties()->isnoise) return -1; - uint8_t carrier = 0; - uint8_t *bits = calloc(MAX_GRAPH_TRACE_LEN, sizeof(uint8_t)); if (bits == NULL) { PrintAndLogEx(WARNING, "Failed to allocate memory"); @@ -211,16 +209,18 @@ uint8_t GetPskCarrier(const char *str, bool printAns) { uint16_t fc = countFC(bits, size, false); free(bits); - carrier = fc & 0xFF; + + uint8_t carrier = fc & 0xFF; if (carrier != 2 && carrier != 4 && carrier != 8) return 0; if ((fc >> 8) == 10 && carrier == 8) return 0; // Only print this message if we're not looping something - if (printAns) + if (verbose) PrintAndLogEx(SUCCESS, "Auto-detected PSK carrier rate: %d", carrier); + return carrier; } -int GetPskClock(const char *str, bool printAns) { +int GetPskClock(const char *str, bool verbose) { if (getSignalProperties()->isnoise) return -1; @@ -251,14 +251,14 @@ int GetPskClock(const char *str, bool printAns) { setClockGrid(clock1, firstPhaseShiftLoc); // Only print this message if we're not looping something - if (printAns) + if (verbose) PrintAndLogEx(SUCCESS, "Auto-detected clock rate: %d", clock1); free(bits); return clock1; } -int GetNrzClock(const char *str, bool printAns) { +int GetNrzClock(const char *str, bool verbose) { if (getSignalProperties()->isnoise) return -1; @@ -285,7 +285,7 @@ int GetNrzClock(const char *str, bool printAns) { clock1 = DetectNRZClock(bits, size, 0, &clkStartIdx); setClockGrid(clock1, clkStartIdx); // Only print this message if we're not looping something - if (printAns) + if (verbose) PrintAndLogEx(SUCCESS, "Auto-detected clock rate: %d", clock1); free(bits); @@ -294,7 +294,7 @@ int GetNrzClock(const char *str, bool printAns) { //by marshmellow //attempt to detect the field clock and bit clock for FSK -int GetFskClock(const char *str, bool printAns) { +int GetFskClock(const char *str, bool verbose) { int clock1 = param_get32ex(str, 0, 0, 10); if (clock1 != 0) @@ -307,7 +307,7 @@ int GetFskClock(const char *str, bool printAns) { return 0; if ((fc1 == 10 && fc2 == 8) || (fc1 == 8 && fc2 == 5)) { - if (printAns) + if (verbose) PrintAndLogEx(SUCCESS, "Detected Field Clocks: FC/%d, FC/%d - Bit Clock: RF/%d", fc1, fc2, rf1); setClockGrid(rf1, firstClockEdge); diff --git a/client/src/graph.h b/client/src/graph.h index deb51a31b..fa99b336f 100644 --- a/client/src/graph.h +++ b/client/src/graph.h @@ -27,11 +27,11 @@ void convertGraphFromBitstream(void); void convertGraphFromBitstreamEx(int hi, int low); bool isGraphBitstream(void); -int GetAskClock(const char *str, bool printAns); -int GetPskClock(const char *str, bool printAns); -uint8_t GetPskCarrier(const char *str, bool printAns); -int GetNrzClock(const char *str, bool printAns); -int GetFskClock(const char *str, bool printAns); +int GetAskClock(const char *str, bool verbose); +int GetPskClock(const char *str, bool verbose); +int GetPskCarrier(bool verbose); +int GetNrzClock(const char *str, bool verbose); +int GetFskClock(const char *str, bool verbose); bool fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, int *firstClockEdge); #define MAX_GRAPH_TRACE_LEN (40000 * 8)