NEW lf simpsk

This commit is contained in:
marshmellow42 2015-02-21 21:36:02 -05:00
parent b4a2fcf676
commit 872e3d4d6f
11 changed files with 216 additions and 13 deletions

View file

@ -668,7 +668,10 @@ void UsbPacketReceived(uint8_t *packet, int len)
case CMD_ASK_SIM_TAG: case CMD_ASK_SIM_TAG:
CmdASKsimTag(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes); CmdASKsimTag(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
break; 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]); CopyHIDtoT55x7(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes[0]);
break; break;
case CMD_IO_DEMOD_FSK: case CMD_IO_DEMOD_FSK:

View file

@ -120,6 +120,7 @@ void SimulateTagLowFrequency(int period, int gap, int ledcontrol);
void CmdHIDsimTAG(int hi, int lo, 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 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 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 CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol);
void CmdEM410xdemod(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); void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol);

View file

@ -594,7 +594,6 @@ void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
WDT_HIT(); WDT_HIT();
for (i=0; i<size; i++){ for (i=0; i<size; i++){
//if ((i%4==3) fcAll(0,&n));
if (BitStream[i] == invert){ if (BitStream[i] == invert){
fcAll(fcLow, &n, clk); fcAll(fcLow, &n, clk);
} else { } else {
@ -686,6 +685,72 @@ void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
LED_A_OFF(); LED_A_OFF();
} }
//carrier can be 2,4 or 8
static void pskSimBit(uint8_t waveLen, int *n, uint8_t clk, uint8_t *curPhase, bool phaseChg)
{
uint8_t *dest = BigBuf_get_addr();
uint8_t idx;
int i = 0;
if (phaseChg){
// write phase change
for (i=0; i < waveLen/2; i++){
dest[((*n)++)] = *curPhase^1;
}
for (i=0; i < waveLen/2; i++){
dest[((*n)++)] = *curPhase;
}
*curPhase ^= 1;
}
//write each normal clock wave for the clock duration
for (; i < clk; i+=waveLen){
for (idx=0; idx<waveLen/2; idx++){
dest[((*n)++)] = *curPhase;
}
for (idx=0; idx<waveLen/2; idx++){
dest[((*n)++)] = *curPhase^1;
}
}
}
// args clock, carrier, invert,
void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
{
int ledcontrol=1;
int n=0, i=0;
uint8_t clk = arg1 >> 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<size; i++){
if (BitStream[i] == curPhase){
pskSimBit(carrier, &n, clk, &curPhase, FALSE);
} else {
pskSimBit(phase, &n, clk, &curPhase, TRUE);
}
}
Dbprintf("Simulating with Carrier: %d, clk: %d, invert: %d, n: %d",carrier, clk, invert, n);
Dbprintf("First 64:");
uint8_t *dest = BigBuf_get_addr();
i=0;
Dbprintf("%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", dest[i],dest[i+1],dest[i+2],dest[i+3],dest[i+4],dest[i+5],dest[i+6],dest[i+7],dest[i+8],dest[i+9],dest[i+10],dest[i+11],dest[i+12],dest[i+13],dest[i+14],dest[i+15]);
i+=16;
Dbprintf("%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", dest[i],dest[i+1],dest[i+2],dest[i+3],dest[i+4],dest[i+5],dest[i+6],dest[i+7],dest[i+8],dest[i+9],dest[i+10],dest[i+11],dest[i+12],dest[i+13],dest[i+14],dest[i+15]);
i+=16;
Dbprintf("%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", dest[i],dest[i+1],dest[i+2],dest[i+3],dest[i+4],dest[i+5],dest[i+6],dest[i+7],dest[i+8],dest[i+9],dest[i+10],dest[i+11],dest[i+12],dest[i+13],dest[i+14],dest[i+15]);
i+=16;
Dbprintf("%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", dest[i],dest[i+1],dest[i+2],dest[i+3],dest[i+4],dest[i+5],dest[i+6],dest[i+7],dest[i+8],dest[i+9],dest[i+10],dest[i+11],dest[i+12],dest[i+13],dest[i+14],dest[i+15]);
if (ledcontrol)
LED_A_ON();
SimulateTagLowFrequency(n, 0, ledcontrol);
if (ledcontrol)
LED_A_OFF();
}
// loop to get raw HID waveform then FSK demodulate the TAG ID from it // loop to get raw HID waveform then FSK demodulate the TAG ID from it
void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol) void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
{ {

View file

@ -561,6 +561,7 @@ int usage_lf_simfsk(void)
PrintAndLog(" L <fcLow> Manually set the smaller Field Clock"); PrintAndLog(" L <fcLow> Manually set the smaller Field Clock");
//PrintAndLog(" s TBD- -to enable a gap between playback repetitions - default: no gap"); //PrintAndLog(" s TBD- -to enable a gap between playback repetitions - default: no gap");
PrintAndLog(" d <hexdata> Data to sim as hex - omit to sim from DemodBuffer"); PrintAndLog(" d <hexdata> 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; return 0;
} }
@ -579,11 +580,25 @@ int usage_lf_simask(void)
return 0; return 0;
} }
int usage_lf_simpsk(void)
{
//print help
PrintAndLog("Usage: lf simpsk [1|2|3] [c <clock>] [i] [r <carrier>] [d <raw hex to sim>]");
PrintAndLog("Options: ");
PrintAndLog(" h This help");
PrintAndLog(" c <clock> 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 <carrier> 2|4|8 are valid carriers: default = 2");
PrintAndLog(" d <hexdata> Data to sim as hex - omit to sim from DemodBuffer");
return 0;
}
// by marshmellow - sim ask data given clock, fcHigh, fcLow, invert // by marshmellow - sim ask data given clock, fcHigh, fcLow, invert
// - allow pull data from DemodBuffer // - allow pull data from DemodBuffer
int CmdLFfskSim(const char *Cmd) 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 //might be able to autodetect FC and clock from Graphbuffer if using demod buffer
//will need FChigh, FClow, Clock, and bitstream //will need FChigh, FClow, Clock, and bitstream
uint8_t fcHigh=0, fcLow=0, clk=0; uint8_t fcHigh=0, fcLow=0, clk=0;
@ -625,7 +640,8 @@ int CmdLFfskSim(const char *Cmd)
errors=TRUE; errors=TRUE;
} else { } else {
dataLen = hextobinarray((char *)data, hexData); dataLen = hextobinarray((char *)data, hexData);
} if (dataLen==0) errors=TRUE; }
if (dataLen==0) errors=TRUE;
if (errors) PrintAndLog ("Error getting hex data"); if (errors) PrintAndLog ("Error getting hex data");
cmdp+=2; cmdp+=2;
break; break;
@ -646,13 +662,14 @@ int CmdLFfskSim(const char *Cmd)
{ {
return usage_lf_simfsk(); 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); uint8_t ans = fskClocks(&fcHigh, &fcLow, &clk, 0);
if (ans==0){ if (ans==0){
fcHigh=10; if (!fcHigh) fcHigh=10;
fcLow=8; if (!fcLow) fcLow=8;
clk=50; if (!clk) clk=50;
} }
} }
} else { } else {
@ -678,7 +695,6 @@ int CmdLFfskSim(const char *Cmd)
// - allow pull data from DemodBuffer // - allow pull data from DemodBuffer
int CmdLFaskSim(const char *Cmd) int CmdLFaskSim(const char *Cmd)
{ {
//todo - allow data from demodbuffer or parameters
//autodetect clock from Graphbuffer if using demod buffer //autodetect clock from Graphbuffer if using demod buffer
//will need clock, invert, manchester/raw as m or r, separator as s, and bitstream //will need clock, invert, manchester/raw as m or r, separator as s, and bitstream
uint8_t manchester = 1, separator = 0; uint8_t manchester = 1, separator = 0;
@ -763,6 +779,98 @@ int CmdLFaskSim(const char *Cmd)
return 0; 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) 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"}, {"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"}, {"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)"}, {"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"}, {"simask", CmdLFaskSim, 0, "[clock] [invert <1|0>] [manchester/raw <'m'|'r'>] [trs separator 's'] [d <hexdata>] -- Simulate LF ASK tag from demodbuffer or input"},
{"simfsk", CmdLFfskSim, 0, "[invert <1|0>] -- Simulate LF FSK tag from demodbuffer"}, {"simfsk", CmdLFfskSim, 0, "[c <clock>] [i] [H <fcHigh>] [L <fcLow>] [d <hexdata>] -- Simulate LF FSK tag from demodbuffer or input"},
{"simpsk", CmdLFpskSim, 0, "[1|2|3] [c <clock>] [i] [r <carrier>] [d <raw hex to sim>] -- Simulate LF PSK tag from demodbuffer or input"},
{"simbidir", CmdLFSimBidir, 0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"}, {"simbidir", CmdLFSimBidir, 0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"},
{"simman", CmdLFSimManchester, 0, "<Clock> <Bitstream> [GAP] Simulate arbitrary Manchester LF tag"}, {"simman", CmdLFSimManchester, 0, "<Clock> <Bitstream> [GAP] Simulate arbitrary Manchester LF tag"},
{"snoop", CmdLFSnoop, 0, "['l'|'h'|<divisor>] [trigger threshold]-- Snoop LF (l:125khz, h:134khz)"}, {"snoop", CmdLFSnoop, 0, "['l'|'h'|<divisor>] [trigger threshold]-- Snoop LF (l:125khz, h:134khz)"},

View file

@ -21,6 +21,7 @@ int CmdLFRead(const char *Cmd);
int CmdLFSim(const char *Cmd); int CmdLFSim(const char *Cmd);
int CmdLFaskSim(const char *Cmd); int CmdLFaskSim(const char *Cmd);
int CmdLFfskSim(const char *Cmd); int CmdLFfskSim(const char *Cmd);
int CmdLFpskSim(const char *Cmd);
int CmdLFSimBidir(const char *Cmd); int CmdLFSimBidir(const char *Cmd);
int CmdLFSimManchester(const char *Cmd); int CmdLFSimManchester(const char *Cmd);
int CmdLFSnoop(const char *Cmd); int CmdLFSnoop(const char *Cmd);

View file

@ -134,6 +134,26 @@ int GetAskClock(const char str[], bool printAns, bool verbose)
return clock; 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 GetPskClock(const char str[], bool printAns, bool verbose)
{ {
int clock; int clock;

View file

@ -18,6 +18,7 @@ int ClearGraph(int redraw);
size_t getFromGraphBuf(uint8_t *buff); size_t getFromGraphBuf(uint8_t *buff);
int GetAskClock(const char str[], bool printAns, bool verbose); int GetAskClock(const char str[], bool printAns, bool verbose);
int GetPskClock(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 GetNrzClock(const char str[], bool printAns, bool verbose);
uint8_t GetFskClock(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); uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose);

View file

@ -83,6 +83,7 @@ typedef struct {
#define CMD_SET_LF_SAMPLING_CONFIG 0x021d #define CMD_SET_LF_SAMPLING_CONFIG 0x021d
#define CMD_FSK_SIM_TAG 0x021E #define CMD_FSK_SIM_TAG 0x021E
#define CMD_ASK_SIM_TAG 0x021F #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 */ /* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */

View file

@ -53,6 +53,7 @@ local _commands = {
CMD_SET_LF_SAMPLING_CONFIG = 0x021d, CMD_SET_LF_SAMPLING_CONFIG = 0x021d,
CMD_FSK_SIM_TAG = 0x021E, CMD_FSK_SIM_TAG = 0x021E,
CMD_ASK_SIM_TAG = 0x021F, 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 */ --/* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */

View file

@ -25,7 +25,7 @@ uint8_t justNoise(uint8_t *BitStream, size_t size)
} }
//by marshmellow //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) int getHiLo(uint8_t *BitStream, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo)
{ {
*high=0; *high=0;

View file

@ -94,6 +94,7 @@ typedef struct{
#define CMD_SET_LF_SAMPLING_CONFIG 0x021d #define CMD_SET_LF_SAMPLING_CONFIG 0x021d
#define CMD_FSK_SIM_TAG 0x021E #define CMD_FSK_SIM_TAG 0x021E
#define CMD_ASK_SIM_TAG 0x021F #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 */ /* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */