From cf0d72e1723977c3b65b29cb7557f0bcd431feb1 Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Sun, 29 Sep 2019 10:43:01 +1000 Subject: [PATCH 1/5] lf sniff offset Added samples to skip to lf config --- armsrc/lfsampling.c | 19 +++++++++++++++---- client/cmdlf.c | 25 ++++++++++++++++--------- include/pm3_cmd.h | 1 + 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index 498d8f747..eea2a4c86 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -33,6 +33,7 @@ void printConfig() { Dbprintf(" [d] decimation..........%d", config.decimation); Dbprintf(" [a] averaging...........%s", (config.averaging) ? "Yes" : "No"); Dbprintf(" [t] trigger threshold...%d", config.trigger_threshold); + Dbprintf(" [s] samples to skip.....%d ", config.samples_to_skip); } /** @@ -50,6 +51,7 @@ void setSamplingConfig(sample_config *sc) { if (sc->divisor != 0) config.divisor = sc->divisor; if (sc->bits_per_sample != 0) config.bits_per_sample = sc->bits_per_sample; if (sc->trigger_threshold != -1) config.trigger_threshold = sc->trigger_threshold; + if (sc->samples_to_skip != -1) config.samples_to_skip = sc->samples_to_skip; config.decimation = (sc->decimation != 0) ? sc->decimation : 1; config.averaging = sc->averaging; @@ -124,7 +126,7 @@ void LFSetupFPGAForADC(int divisor, bool lf_field) { * @param silent - is true, now outputs are made. If false, dbprints the status * @return the number of bits occupied by the samples. */ -uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent, int bufsize, uint32_t cancel_after) { +uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent, int bufsize, uint32_t cancel_after, int samples_to_skip) { uint8_t *dest = BigBuf_get_addr(); bufsize = (bufsize > 0 && bufsize < BigBuf_max_traceLen()) ? bufsize : BigBuf_max_traceLen(); @@ -144,6 +146,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag uint32_t sample_total_numbers = 0; uint32_t sample_total_saved = 0; uint32_t cancel_counter = 0; + uint32_t samples_skipped = 0; uint16_t checker = 0; @@ -176,6 +179,12 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag } trigger_threshold = 0; + + if (samples_to_skip > samples_skipped) { + samples_skipped++; + continue; + } + sample_total_numbers++; if (averaging) @@ -196,6 +205,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag // store the sample sample_total_saved ++; + if (bits_per_sample == 8) { dest[sample_total_saved - 1] = sample; @@ -238,7 +248,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag * @return number of bits sampled */ uint32_t DoAcquisition_default(int trigger_threshold, bool silent) { - return DoAcquisition(1, 8, 0, trigger_threshold, silent, 0, 0); + return DoAcquisition(1, 8, 0, trigger_threshold, silent, 0, 0,0); } uint32_t DoAcquisition_config(bool silent, int sample_size) { return DoAcquisition(config.decimation @@ -247,11 +257,12 @@ uint32_t DoAcquisition_config(bool silent, int sample_size) { , config.trigger_threshold , silent , sample_size - , 0); + , 0 + , config.samples_to_skip); } uint32_t DoPartialAcquisition(int trigger_threshold, bool silent, int sample_size, uint32_t cancel_after) { - return DoAcquisition(1, 8, 0, trigger_threshold, silent, sample_size, cancel_after); + return DoAcquisition(1, 8, 0, trigger_threshold, silent, sample_size, cancel_after,0); } uint32_t ReadLF(bool activeField, bool silent, int sample_size) { diff --git a/client/cmdlf.c b/client/cmdlf.c index ee4302e82..16e8a64d5 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -105,14 +105,15 @@ static int usage_lf_sniff(void) { static int usage_lf_config(void) { PrintAndLogEx(NORMAL, "Usage: lf config [h] [H|] [b ] [d ] [a 0|1]"); PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h This help"); - PrintAndLogEx(NORMAL, " L Low frequency (125 kHz)"); - PrintAndLogEx(NORMAL, " H High frequency (134 kHz)"); - PrintAndLogEx(NORMAL, " q Manually set divisor. 88-> 134 kHz, 95-> 125 kHz"); - PrintAndLogEx(NORMAL, " b Sets resolution of bits per sample. Default (max): 8"); - PrintAndLogEx(NORMAL, " d Sets decimation. A value of N saves only 1 in N samples. Default: 1"); - PrintAndLogEx(NORMAL, " a [0|1] Averaging - if set, will average the stored sample value when decimating. Default: 1"); - PrintAndLogEx(NORMAL, " t Sets trigger threshold. 0 means no threshold (range: 0-128)"); + PrintAndLogEx(NORMAL, " h This help"); + PrintAndLogEx(NORMAL, " L Low frequency (125 kHz)"); + PrintAndLogEx(NORMAL, " H High frequency (134 kHz)"); + PrintAndLogEx(NORMAL, " q Manually set divisor. 88-> 134 kHz, 95-> 125 kHz"); + PrintAndLogEx(NORMAL, " b Sets resolution of bits per sample. Default (max): 8"); + PrintAndLogEx(NORMAL, " d Sets decimation. A value of N saves only 1 in N samples. Default: 1"); + PrintAndLogEx(NORMAL, " a [0|1] Averaging - if set, will average the stored sample value when decimating. Default: 1"); + PrintAndLogEx(NORMAL, " t Sets trigger threshold. 0 means no threshold (range: 0-128)"); + PrintAndLogEx(NORMAL, " s Sets a number of samples to skip before capture. Default: 0"); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf config b 8 L"); PrintAndLogEx(NORMAL, " Samples at 125 kHz, 8bps."); @@ -399,6 +400,8 @@ int CmdLFSetConfig(const char *Cmd) { bool errors = false; int trigger_threshold = -1;//Means no change uint8_t unsigned_trigg = 0; + int samples_to_skip = -1; + uint8_t cmdp = 0; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { @@ -437,6 +440,10 @@ int CmdLFSetConfig(const char *Cmd) { averaging = param_getchar(Cmd, cmdp + 1) == '1'; cmdp += 2; break; + case 's': + samples_to_skip = param_get32ex(Cmd,cmdp+1,0,10); + cmdp+=2; + break; default: PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); errors = 1; @@ -450,7 +457,7 @@ int CmdLFSetConfig(const char *Cmd) { //Bps is limited to 8 if (bps >> 4) bps = 8; - sample_config config = { decimation, bps, averaging, divisor, trigger_threshold }; + sample_config config = { decimation, bps, averaging, divisor, trigger_threshold,samples_to_skip }; clearCommandBuffer(); SendCommandNG(CMD_LF_SAMPLING_SET_CONFIG, (uint8_t *)&config, sizeof(sample_config)); diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 1628c558d..a8ef019d7 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -118,6 +118,7 @@ typedef struct { bool averaging; int divisor; int trigger_threshold; + int samples_to_skip; } PACKED sample_config; /* typedef struct { From c7b36207542648a65fa79d13cfa15d7dc9c1193f Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Sun, 29 Sep 2019 11:10:07 +1000 Subject: [PATCH 2/5] Update lfsampling.c Set default for samples to skip --- armsrc/lfsampling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index eea2a4c86..0926cca04 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -24,7 +24,7 @@ Default LF config is set to: divisor = 95 (125kHz) trigger_threshold = 0 */ -sample_config config = { 1, 8, 1, 95, 0 } ; +sample_config config = { 1, 8, 1, 95, 0, 0 } ; void printConfig() { DbpString(_BLUE_("LF Sampling config")); From 40b1d3bea7004dd44604a2c580d7206858181caf Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Mon, 30 Sep 2019 19:22:26 +1000 Subject: [PATCH 3/5] samples to skip (unint32_t) Use unit32_t for all samples to skip --- CHANGELOG.md | 3 ++- armsrc/lfsampling.c | 5 +++-- client/cmdlf.c | 2 +- include/pm3_cmd.h | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32a317320..78a0d48d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -357,7 +357,8 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Fix T55xx config getting displayed when using password when no password needed on read. (@mwalker33) - Fix `em 4x05_dump` to print all blocks read (@mwalker33) - Added save to .eml and .bin for `em 4x05_dump` (@mwalker33) - + - Added `s` to `lf config` / `lf sniff` to skip samples when sniffing (@mwalker33) + ### Fixed - Changed driver file proxmark3.inf to support both old and new Product/Vendor IDs (@pwpiwi) - Changed start sequence in Qt mode (fix: short commands hangs main Qt thread) (@merlokk) diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index 0926cca04..97951ef37 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -51,8 +51,9 @@ void setSamplingConfig(sample_config *sc) { if (sc->divisor != 0) config.divisor = sc->divisor; if (sc->bits_per_sample != 0) config.bits_per_sample = sc->bits_per_sample; if (sc->trigger_threshold != -1) config.trigger_threshold = sc->trigger_threshold; - if (sc->samples_to_skip != -1) config.samples_to_skip = sc->samples_to_skip; +// if (sc->samples_to_skip == 0xffffffff) // if needed to not update if not supplied + config.samples_to_skip = sc->samples_to_skip; config.decimation = (sc->decimation != 0) ? sc->decimation : 1; config.averaging = sc->averaging; if (config.bits_per_sample > 8) config.bits_per_sample = 8; @@ -126,7 +127,7 @@ void LFSetupFPGAForADC(int divisor, bool lf_field) { * @param silent - is true, now outputs are made. If false, dbprints the status * @return the number of bits occupied by the samples. */ -uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent, int bufsize, uint32_t cancel_after, int samples_to_skip) { +uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent, int bufsize, uint32_t cancel_after, uint32_t samples_to_skip) { uint8_t *dest = BigBuf_get_addr(); bufsize = (bufsize > 0 && bufsize < BigBuf_max_traceLen()) ? bufsize : BigBuf_max_traceLen(); diff --git a/client/cmdlf.c b/client/cmdlf.c index 16e8a64d5..8f540310f 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -400,7 +400,7 @@ int CmdLFSetConfig(const char *Cmd) { bool errors = false; int trigger_threshold = -1;//Means no change uint8_t unsigned_trigg = 0; - int samples_to_skip = -1; + uint32_t samples_to_skip = 0; // will return offset to 0 if not supplied. Could set to 0xffffffff if needed to not update uint8_t cmdp = 0; diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index a8ef019d7..010e46728 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -118,7 +118,7 @@ typedef struct { bool averaging; int divisor; int trigger_threshold; - int samples_to_skip; + uint32_t samples_to_skip; } PACKED sample_config; /* typedef struct { From f5d7963780c2a7a7e4b9ada1bfe366e5ab23c8c0 Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Mon, 30 Sep 2019 19:41:25 +1000 Subject: [PATCH 4/5] lf config s update --- armsrc/lfsampling.c | 9 ++++----- client/cmdlf.c | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index 97951ef37..f1cea2aea 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -147,7 +147,6 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag uint32_t sample_total_numbers = 0; uint32_t sample_total_saved = 0; uint32_t cancel_counter = 0; - uint32_t samples_skipped = 0; uint16_t checker = 0; @@ -181,8 +180,8 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag trigger_threshold = 0; - if (samples_to_skip > samples_skipped) { - samples_skipped++; + if (samples_to_skip > 0) { + samples_to_skip--; continue; } @@ -249,7 +248,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag * @return number of bits sampled */ uint32_t DoAcquisition_default(int trigger_threshold, bool silent) { - return DoAcquisition(1, 8, 0, trigger_threshold, silent, 0, 0,0); + return DoAcquisition(1, 8, 0, trigger_threshold, silent, 0, 0, 0); } uint32_t DoAcquisition_config(bool silent, int sample_size) { return DoAcquisition(config.decimation @@ -263,7 +262,7 @@ uint32_t DoAcquisition_config(bool silent, int sample_size) { } uint32_t DoPartialAcquisition(int trigger_threshold, bool silent, int sample_size, uint32_t cancel_after) { - return DoAcquisition(1, 8, 0, trigger_threshold, silent, sample_size, cancel_after,0); + return DoAcquisition(1, 8, 0, trigger_threshold, silent, sample_size, cancel_after, 0); } uint32_t ReadLF(bool activeField, bool silent, int sample_size) { diff --git a/client/cmdlf.c b/client/cmdlf.c index 8f540310f..08f93608b 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -441,7 +441,7 @@ int CmdLFSetConfig(const char *Cmd) { cmdp += 2; break; case 's': - samples_to_skip = param_get32ex(Cmd,cmdp+1,0,10); + samples_to_skip = param_get32ex(Cmd, cmdp + 1, 0, 10); cmdp+=2; break; default: @@ -457,7 +457,7 @@ int CmdLFSetConfig(const char *Cmd) { //Bps is limited to 8 if (bps >> 4) bps = 8; - sample_config config = { decimation, bps, averaging, divisor, trigger_threshold,samples_to_skip }; + sample_config config = { decimation, bps, averaging, divisor, trigger_threshold, samples_to_skip }; clearCommandBuffer(); SendCommandNG(CMD_LF_SAMPLING_SET_CONFIG, (uint8_t *)&config, sizeof(sample_config)); From 102d8221025dd9e9e7efc0793983e1be125bafa5 Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Mon, 30 Sep 2019 21:06:22 +1000 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78a0d48d2..563873a8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -357,7 +357,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Fix T55xx config getting displayed when using password when no password needed on read. (@mwalker33) - Fix `em 4x05_dump` to print all blocks read (@mwalker33) - Added save to .eml and .bin for `em 4x05_dump` (@mwalker33) - - Added `s` to `lf config` / `lf sniff` to skip samples when sniffing (@mwalker33) + - Added `s` to `lf config` / `lf sniff` to skip samples when sniffing based on same option in Proxmark/proxmark3 by @marshmellow42. (@mwalker33) ### Fixed - Changed driver file proxmark3.inf to support both old and new Product/Vendor IDs (@pwpiwi)