From 0b95c519ff4a034dba64a8340cb63a08dcc39f38 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Sat, 9 Jul 2022 16:45:08 +0300 Subject: [PATCH] sh sniff skip some bytes from data - arm side --- armsrc/appmain.c | 4 +++- armsrc/hfsnoop.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- armsrc/hfsnoop.h | 9 ++++++++- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 106fe3903..330bf2c48 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1784,11 +1784,13 @@ static void PacketReceived(PacketCommandNG *packet) { struct p { uint32_t samplesToSkip; uint32_t triggersToSkip; + uint8_t skipMode; + uint8_t skipRatio; } PACKED; struct p *payload = (struct p *)packet->data.asBytes; uint16_t len = 0; - int res = HfSniff(payload->samplesToSkip, payload->triggersToSkip, &len); + int res = HfSniff(payload->samplesToSkip, payload->triggersToSkip, &len, payload->skipMode, payload->skipRatio); struct { uint16_t len; diff --git a/armsrc/hfsnoop.c b/armsrc/hfsnoop.c index ba9ef0740..f12b4863b 100644 --- a/armsrc/hfsnoop.c +++ b/armsrc/hfsnoop.c @@ -36,7 +36,46 @@ static void RAMFUNC optimizedSniff(uint16_t *dest, uint16_t dsize) { } } -int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len) { +static void RAMFUNC skipSniff(uint8_t *dest, uint16_t dsize, uint8_t skipMode, uint8_t skipRatio) { + uint32_t accum = (skipMode == HF_SNOOP_SKIP_MIN) ? 0xffffffff : 0; + uint8_t ratioindx = 0; + while (dsize > 0) { + if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) { + volatile uint16_t val = (uint16_t)(AT91C_BASE_SSC->SSC_RHR); + switch (skipMode) { + case HF_SNOOP_SKIP_MAX: + if (accum < (val & 0xff)) + accum = val & 0xff; + if (accum < (val << 8)) + accum = val << 8; + case HF_SNOOP_SKIP_MIN: + if (accum > (val & 0xff)) + accum = val & 0xff; + if (accum > (val << 8)) + accum = val << 8; + case HF_SNOOP_SKIP_AVG: + accum += (val & 0xff) + (val << 8); + default: { // HF_SNOOP_SKIP_DROP and the rest + if (ratioindx == 0) + accum = val & 0xff; + } + } + + ratioindx++; + if (ratioindx >= skipRatio) { + ratioindx = 0; + if (skipMode == HF_SNOOP_SKIP_AVG) + *dest = accum / (skipRatio * 2); + else + *dest = accum; + dest++; + dsize --; + } + } + } +} + +int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len, uint8_t skipMode, uint8_t skipRatio) { BigBuf_free(); BigBuf_Clear_ext(false); @@ -105,7 +144,10 @@ int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len) { } } - optimizedSniff((uint16_t *)mem, *len); + if (skipMode == 0) + optimizedSniff((uint16_t *)mem, *len); + else + skipSniff(mem, *len, skipMode, skipRatio); if (g_dbglevel >= DBG_INFO) { Dbprintf("Trigger kicked in (%d >= 180)", r); diff --git a/armsrc/hfsnoop.h b/armsrc/hfsnoop.h index 4b715753d..a68d28a79 100644 --- a/armsrc/hfsnoop.h +++ b/armsrc/hfsnoop.h @@ -18,6 +18,13 @@ #include "proxmark3_arm.h" -int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len); +// what to do with skipped data +#define HF_SNOOP_SKIP_NONE (0) +#define HF_SNOOP_SKIP_DROP (1) +#define HF_SNOOP_SKIP_MAX (2) +#define HF_SNOOP_SKIP_MIN (3) +#define HF_SNOOP_SKIP_AVG (4) + +int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len, uint8_t skipMode, uint8_t skipRatio); void HfPlotDownload(void); #endif