diff --git a/armsrc/appmain.c b/armsrc/appmain.c index bfb4078dc..3e670f0be 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -668,7 +668,10 @@ void UsbPacketReceived(uint8_t *packet, int len) case CMD_ASK_SIM_TAG: CmdASKsimTag(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes); break; - case CMD_HID_CLONE_TAG: + case CMD_PSK_SIM_TAG: + CmdPSKsimTag(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes); + break; + case CMD_HID_CLONE_TAG: CopyHIDtoT55x7(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes[0]); break; case CMD_IO_DEMOD_FSK: diff --git a/armsrc/apps.h b/armsrc/apps.h index 8e79a03a2..928a3075f 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -120,6 +120,7 @@ void SimulateTagLowFrequency(int period, int gap, int ledcontrol); void CmdHIDsimTAG(int hi, int lo, int ledcontrol); void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream); void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream); +void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream); void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol); void CmdEM410xdemod(int findone, int *high, int *low, int ledcontrol); void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol); diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 780af1994..ea36cdec8 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -594,7 +594,6 @@ void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream) WDT_HIT(); for (i=0; i> 8; + uint8_t carrier = arg1 & 0xFF; + uint8_t invert = arg2 & 0xFF; + uint8_t phase = carrier/2; //extra phase changing bits = 1/2 a carrier wave to change the phase + //uint8_t invert = (arg2 >> 8) & 1; + uint8_t curPhase = 0; + WDT_HIT(); + for (i=0; i Manually set the smaller Field Clock"); //PrintAndLog(" s TBD- -to enable a gap between playback repetitions - default: no gap"); PrintAndLog(" d Data to sim as hex - omit to sim from DemodBuffer"); + PrintAndLog("\n NOTE: if you set one clock manually set them all manually"); return 0; } @@ -579,11 +580,25 @@ int usage_lf_simask(void) return 0; } +int usage_lf_simpsk(void) +{ + //print help + PrintAndLog("Usage: lf simpsk [1|2|3] [c ] [i] [r ] [d ]"); + PrintAndLog("Options: "); + PrintAndLog(" h This help"); + PrintAndLog(" c Manually set clock - can autodetect if using DemodBuffer"); + PrintAndLog(" i invert data"); + PrintAndLog(" 1 set PSK1 (default)"); + PrintAndLog(" 2 set PSK2"); + PrintAndLog(" 3 set PSK3"); + PrintAndLog(" r 2|4|8 are valid carriers: default = 2"); + PrintAndLog(" d Data to sim as hex - omit to sim from DemodBuffer"); + return 0; +} // by marshmellow - sim ask data given clock, fcHigh, fcLow, invert // - allow pull data from DemodBuffer int CmdLFfskSim(const char *Cmd) { - //todo - allow data from demodbuffer or parameters //might be able to autodetect FC and clock from Graphbuffer if using demod buffer //will need FChigh, FClow, Clock, and bitstream uint8_t fcHigh=0, fcLow=0, clk=0; @@ -625,7 +640,8 @@ int CmdLFfskSim(const char *Cmd) errors=TRUE; } else { dataLen = hextobinarray((char *)data, hexData); - } if (dataLen==0) errors=TRUE; + } + if (dataLen==0) errors=TRUE; if (errors) PrintAndLog ("Error getting hex data"); cmdp+=2; break; @@ -646,13 +662,14 @@ int CmdLFfskSim(const char *Cmd) { return usage_lf_simfsk(); } - if (dataLen == 0){ //using DemodBuffer - if (clk==0 || fcHigh==0 || fcLow==0){ + + if (dataLen == 0){ //using DemodBuffer + if (clk==0 || fcHigh==0 || fcLow==0){ //manual settings must set them all uint8_t ans = fskClocks(&fcHigh, &fcLow, &clk, 0); if (ans==0){ - fcHigh=10; - fcLow=8; - clk=50; + if (!fcHigh) fcHigh=10; + if (!fcLow) fcLow=8; + if (!clk) clk=50; } } } else { @@ -678,7 +695,6 @@ int CmdLFfskSim(const char *Cmd) // - allow pull data from DemodBuffer int CmdLFaskSim(const char *Cmd) { - //todo - allow data from demodbuffer or parameters //autodetect clock from Graphbuffer if using demod buffer //will need clock, invert, manchester/raw as m or r, separator as s, and bitstream uint8_t manchester = 1, separator = 0; @@ -763,6 +779,98 @@ int CmdLFaskSim(const char *Cmd) return 0; } +// by marshmellow - sim psk data given carrier, clock, invert +// - allow pull data from DemodBuffer or parameters +int CmdLFpskSim(const char *Cmd) +{ + //might be able to autodetect FC and clock from Graphbuffer if using demod buffer + //will need carrier, Clock, and bitstream + uint8_t carrier=0, clk=0; + uint8_t invert=0; + bool errors = FALSE; + char hexData[32] = {0x00}; // store entered hex data + uint8_t data[255] = {0x00}; + int dataLen = 0; + uint8_t cmdp = 0; + uint8_t pskType = 1; + while(param_getchar(Cmd, cmdp) != 0x00) + { + switch(param_getchar(Cmd, cmdp)) + { + case 'h': + return usage_lf_simpsk(); + case 'i': + invert = 1; + cmdp++; + break; + case 'c': + errors |= param_getdec(Cmd,cmdp+1,&clk); + cmdp+=2; + break; + case 'r': + errors |= param_getdec(Cmd,cmdp+1,&carrier); + cmdp+=2; + break; + case '1': + pskType=1; + cmdp++; + break; + case '2': + pskType=2; + cmdp++; + break; + case '3': + pskType=3; + cmdp++; + break; + case 'd': + dataLen = param_getstr(Cmd, cmdp+1, hexData); + if (dataLen==0) { + errors=TRUE; + } else { + dataLen = hextobinarray((char *)data, hexData); + } + if (dataLen==0) errors=TRUE; + if (errors) PrintAndLog ("Error getting hex data"); + cmdp+=2; + break; + default: + PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + errors = TRUE; + break; + } + if (errors) break; + } + if (cmdp == 0 && DemodBufferLen == 0) + { + errors = TRUE;// No args + } + + //Validations + if (errors) + { + return usage_lf_simpsk(); + } + if (dataLen == 0){ //using DemodBuffer + if (clk==0) clk = GetPskClock(NULL, FALSE, FALSE); + if (!carrier) carrier = GetPskCarrier(NULL, FALSE, FALSE); + } else { + setDemodBuf(data, dataLen, 0); + } + if (clk <= 0) clk = 32; + if (carrier == 0) carrier = 2; + + uint16_t arg1, arg2; + arg1 = clk << 8 | carrier; + arg2 = invert; + UsbCommand c = {CMD_PSK_SIM_TAG, {arg1, arg2, DemodBufferLen}}; + if (DemodBufferLen > USB_CMD_DATA_SIZE) { + PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", DemodBufferLen, USB_CMD_DATA_SIZE); + } + memcpy(c.d.asBytes, DemodBuffer, DemodBufferLen); + SendCommand(&c); + return 0; +} int CmdLFSimBidir(const char *Cmd) { @@ -982,8 +1090,9 @@ static command_t CommandTable[] = {"read", CmdLFRead, 0, "Read 125/134 kHz LF ID-only tag. Do 'lf read h' for help"}, {"search", CmdLFfind, 1, "[offline] ['u'] Read and Search for valid known tag (in offline mode it you can load first then search) - 'u' to search for unknown tags"}, {"sim", CmdLFSim, 0, "[GAP] -- Simulate LF tag from buffer with optional GAP (in microseconds)"}, - {"simask", CmdLFaskSim, 0, "[clock] [invert <1|0>] [manchester/raw <'m'|'r'>] [trs separator 's'] -- Simulate LF ASK tag from demodbuffer"}, - {"simfsk", CmdLFfskSim, 0, "[invert <1|0>] -- Simulate LF FSK tag from demodbuffer"}, + {"simask", CmdLFaskSim, 0, "[clock] [invert <1|0>] [manchester/raw <'m'|'r'>] [trs separator 's'] [d ] -- Simulate LF ASK tag from demodbuffer or input"}, + {"simfsk", CmdLFfskSim, 0, "[c ] [i] [H ] [L ] [d ] -- Simulate LF FSK tag from demodbuffer or input"}, + {"simpsk", CmdLFpskSim, 0, "[1|2|3] [c ] [i] [r ] [d ] -- Simulate LF PSK tag from demodbuffer or input"}, {"simbidir", CmdLFSimBidir, 0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"}, {"simman", CmdLFSimManchester, 0, " [GAP] Simulate arbitrary Manchester LF tag"}, {"snoop", CmdLFSnoop, 0, "['l'|'h'|] [trigger threshold]-- Snoop LF (l:125khz, h:134khz)"}, diff --git a/client/cmdlf.h b/client/cmdlf.h index 22f7f8182..18a28b10b 100644 --- a/client/cmdlf.h +++ b/client/cmdlf.h @@ -21,6 +21,7 @@ int CmdLFRead(const char *Cmd); int CmdLFSim(const char *Cmd); int CmdLFaskSim(const char *Cmd); int CmdLFfskSim(const char *Cmd); +int CmdLFpskSim(const char *Cmd); int CmdLFSimBidir(const char *Cmd); int CmdLFSimManchester(const char *Cmd); int CmdLFSnoop(const char *Cmd); diff --git a/client/graph.c b/client/graph.c index c9457ff1a..243da4664 100644 --- a/client/graph.c +++ b/client/graph.c @@ -134,6 +134,26 @@ int GetAskClock(const char str[], bool printAns, bool verbose) return clock; } +uint8_t GetPskCarrier(const char str[], bool printAns, bool verbose) +{ + uint8_t carrier=0; + uint8_t grph[MAX_GRAPH_TRACE_LEN]={0}; + size_t size = getFromGraphBuf(grph); + if ( size == 0 ) { + if (verbose) + PrintAndLog("Failed to copy from graphbuffer"); + return 0; + } + //uint8_t countPSK_FC(uint8_t *BitStream, size_t size) + + carrier = countPSK_FC(grph,size); + // Only print this message if we're not looping something + if (printAns){ + PrintAndLog("Auto-detected PSK carrier rate: %d", carrier); + } + return carrier; +} + int GetPskClock(const char str[], bool printAns, bool verbose) { int clock; diff --git a/client/graph.h b/client/graph.h index 3c6de0149..8f810669b 100644 --- a/client/graph.h +++ b/client/graph.h @@ -18,6 +18,7 @@ int ClearGraph(int redraw); size_t getFromGraphBuf(uint8_t *buff); int GetAskClock(const char str[], bool printAns, bool verbose); int GetPskClock(const char str[], bool printAns, bool verbose); +uint8_t GetPskCarrier(const char str[], bool printAns, bool verbose); uint8_t GetNrzClock(const char str[], bool printAns, bool verbose); uint8_t GetFskClock(const char str[], bool printAns, bool verbose); uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose); diff --git a/client/hid-flasher/usb_cmd.h b/client/hid-flasher/usb_cmd.h index 53c4dffef..c5b91f997 100644 --- a/client/hid-flasher/usb_cmd.h +++ b/client/hid-flasher/usb_cmd.h @@ -83,6 +83,7 @@ typedef struct { #define CMD_SET_LF_SAMPLING_CONFIG 0x021d #define CMD_FSK_SIM_TAG 0x021E #define CMD_ASK_SIM_TAG 0x021F +#define CMD_PSK_SIM_TAG 0x0220 /* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */ diff --git a/client/lualibs/commands.lua b/client/lualibs/commands.lua index 9b47a9949..ad8f6e00c 100644 --- a/client/lualibs/commands.lua +++ b/client/lualibs/commands.lua @@ -53,6 +53,7 @@ local _commands = { CMD_SET_LF_SAMPLING_CONFIG = 0x021d, CMD_FSK_SIM_TAG = 0x021E, CMD_ASK_SIM_TAG = 0x021F, + CMD_PSK_SIM_TAG = 0x0220, --/* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */ diff --git a/common/lfdemod.c b/common/lfdemod.c index 96b187b76..79252dd98 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -25,7 +25,7 @@ uint8_t justNoise(uint8_t *BitStream, size_t size) } //by marshmellow -//get high and low with passed in fuzz factor. also return noise test = 1 for passed or 0 for only noise +//get high and low values of a wave with passed in fuzz factor. also return noise test = 1 for passed or 0 for only noise int getHiLo(uint8_t *BitStream, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo) { *high=0; diff --git a/include/usb_cmd.h b/include/usb_cmd.h index d73fac542..aab631dae 100644 --- a/include/usb_cmd.h +++ b/include/usb_cmd.h @@ -94,6 +94,7 @@ typedef struct{ #define CMD_SET_LF_SAMPLING_CONFIG 0x021d #define CMD_FSK_SIM_TAG 0x021E #define CMD_ASK_SIM_TAG 0x021F +#define CMD_PSK_SIM_TAG 0x0220 /* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */