From f304528fc0fe54ec45166a71112e560ee8fa18d9 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 4 Jan 2020 20:00:37 +0100 Subject: [PATCH] add: added nrz simulation for lf. *wip* needs pattern for nrz. --- armsrc/lfops.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++- armsrc/lfops.h | 3 ++- include/pm3_cmd.h | 13 ++++++++++-- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/armsrc/lfops.c b/armsrc/lfops.c index c4cd6eaa4..12cd82e43 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -1149,7 +1149,7 @@ static void pskSimBit(uint8_t waveLen, int *n, uint8_t clk, uint8_t *curPhase, b } // args clock, carrier, invert, -void CmdPSKsimTag(uint8_t carrier, uint8_t invert, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol) { +void CmdPSKsimTAG(uint8_t carrier, uint8_t invert, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol) { FpgaDownloadAndGo(FPGA_BITSTREAM_LF); set_tracing(false); @@ -1173,6 +1173,55 @@ void CmdPSKsimTag(uint8_t carrier, uint8_t invert, uint8_t clk, uint16_t size, u reply_ng(CMD_LF_PSK_SIMULATE, PM3_EOPABORTED, NULL, 0); } +// compose nrz waveform for one bit(NRZ) +static void nrzSimBit(uint8_t c, int *n, uint8_t clock) { + uint8_t *dest = BigBuf_get_addr(); +// uint8_t halfClk = clock / 2; + // c = current bit 1 or 0 + memset(dest + (*n), c, clock); + *n += clock; +} + +// args clock, +void CmdNRZsimTAG(uint8_t invert, uint8_t separator, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol) { + + FpgaDownloadAndGo(FPGA_BITSTREAM_LF); + set_tracing(false); + + int n = 0, i = 0; + + // NRZ + + leadingZeroAskSimBits(&n, clk); + + for (i = 0; i < size; i++) { + nrzSimBit(bits[i] ^ invert, &n, clk); + } + + if (bits[0] == bits[size - 1]) { //run a second set inverted (for ask/raw || biphase phase) + for (i = 0; i < size; i++) { + nrzSimBit(bits[i] ^ invert ^ 1, &n, clk); + } + } + + if (separator == 1) + Dbprintf("sorry but separator option not yet available"); + + WDT_HIT(); + + Dbprintf("Simulating with clk: %d, invert: %d, separator: %d, n: %d" + , clk + , invert + , separator + , n + ); + + if (ledcontrol) LED_A_ON(); + SimulateTagLowFrequency(n, 0, ledcontrol); + if (ledcontrol) LED_A_OFF(); + reply_ng(CMD_LF_NRZ_SIMULATE, PM3_EOPABORTED, NULL, 0); +} + // loop to get raw HID waveform then FSK demodulate the TAG ID from it void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) { uint8_t *dest = BigBuf_get_addr(); diff --git a/armsrc/lfops.h b/armsrc/lfops.h index f81d1e7ab..b697cffd1 100644 --- a/armsrc/lfops.h +++ b/armsrc/lfops.h @@ -36,7 +36,8 @@ void CmdHIDsimTAG(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT, bool void CmdFSKsimTAGEx(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk, uint16_t bitslen, uint8_t *bits, bool ledcontrol, int numcycles); void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk, uint16_t bitslen, uint8_t *bits, bool ledcontrol); void CmdASKsimTAG(uint8_t encoding, uint8_t invert, uint8_t separator, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol); -void CmdPSKsimTag(uint8_t carrier, uint8_t invert, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol); +void CmdPSKsimTAG(uint8_t carrier, uint8_t invert, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol); +void CmdNRZsimTAG(uint8_t invert, uint8_t separator, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol); void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); // Realtime demodulation mode for AWID26 diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 64a0c5fd1..44747b1ea 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -239,6 +239,14 @@ typedef struct { uint8_t data[]; } PACKED lf_psksim_t; +// For CMD_LF_NRZ_SIMULATE (NRZ) +typedef struct { + uint8_t invert; + uint8_t separator; + uint8_t clock; + uint8_t data[]; +} PACKED lf_nrzsim_t; + typedef struct { uint8_t blockno; uint8_t keytype; @@ -371,12 +379,13 @@ typedef struct { #define CMD_LF_EM4X_READWORD 0x0218 #define CMD_LF_EM4X_WRITEWORD 0x0219 #define CMD_LF_IO_DEMOD 0x021A -#define CMD_LF_EM410X_DEMOD 0x021c +#define CMD_LF_EM410X_DEMOD 0x021C // Sampling configuration for LF reader/sniffer -#define CMD_LF_SAMPLING_SET_CONFIG 0x021d +#define CMD_LF_SAMPLING_SET_CONFIG 0x021D #define CMD_LF_FSK_SIMULATE 0x021E #define CMD_LF_ASK_SIMULATE 0x021F #define CMD_LF_PSK_SIMULATE 0x0220 +#define CMD_LF_NRZ_SIMULATE 0x0232 #define CMD_LF_AWID_DEMOD 0x0221 #define CMD_LF_VIKING_CLONE 0x0222 #define CMD_LF_T55XX_WAKEUP 0x0224