chg: lf fsksim - uses NG

This commit is contained in:
iceman1001 2019-05-23 13:16:06 -04:00
commit 263d662783
5 changed files with 79 additions and 43 deletions

View file

@ -754,8 +754,7 @@ static void PacketReceived(PacketCommandNG *packet) {
uint8_t silent; uint8_t silent;
uint32_t samples; uint32_t samples;
} PACKED; } PACKED;
struct p *payload; struct p *payload = (struct p*)packet->data.asBytes;
payload = (struct p*)packet->data.asBytes;
uint32_t bits = SampleLF(payload->silent, payload->samples); uint32_t bits = SampleLF(payload->silent, payload->samples);
reply_ng(CMD_ACQUIRE_RAW_ADC_SAMPLES_125K, PM3_SUCCESS, (uint8_t *)&bits, sizeof(bits)); reply_ng(CMD_ACQUIRE_RAW_ADC_SAMPLES_125K, PM3_SUCCESS, (uint8_t *)&bits, sizeof(bits));
break; break;
@ -766,8 +765,7 @@ static void PacketReceived(PacketCommandNG *packet) {
uint16_t ones; uint16_t ones;
uint16_t zeros; uint16_t zeros;
} PACKED; } PACKED;
struct p *payload; struct p *payload = (struct p*)packet->data.asBytes;
payload = (struct p*)packet->data.asBytes;
ModThenAcquireRawAdcSamples125k(payload->delay, payload->zeros, payload->ones, packet->data.asBytes+8); ModThenAcquireRawAdcSamples125k(payload->delay, payload->zeros, payload->ones, packet->data.asBytes+8);
break; break;
} }
@ -784,9 +782,19 @@ static void PacketReceived(PacketCommandNG *packet) {
case CMD_HID_SIM_TAG: case CMD_HID_SIM_TAG:
CmdHIDsimTAG(packet->oldarg[0], packet->oldarg[1], 1); CmdHIDsimTAG(packet->oldarg[0], packet->oldarg[1], 1);
break; break;
case CMD_FSK_SIM_TAG: case CMD_FSK_SIM_TAG: {
CmdFSKsimTAG(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes, 1); struct p {
uint8_t fchigh;
uint8_t fclow;
uint8_t separator;
uint8_t clock;
uint16_t datalen;
} PACKED;
struct p *payload = (struct p*)packet->data.asBytes;
CmdFSKsimTAG(payload->fchigh, payload->fclow, payload->separator, payload->clock, payload->datalen, packet->data.asBytes + 6, 1);
break; break;
}
case CMD_ASK_SIM_TAG: case CMD_ASK_SIM_TAG:
CmdASKsimTag(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes, 1); CmdASKsimTag(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes, 1);
break; break;

View file

@ -86,7 +86,9 @@ void SimulateTagLowFrequency(int period, int gap, int ledcontrol);
void SimulateTagLowFrequencyBidir(int divisor, int max_bitlen); void SimulateTagLowFrequencyBidir(int divisor, int max_bitlen);
void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, int ledcontrol, int numcycles); void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, int ledcontrol, int numcycles);
void CmdHIDsimTAG(uint32_t hi, uint32_t lo, int ledcontrol); void CmdHIDsimTAG(uint32_t hi, uint32_t lo, int ledcontrol);
void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits, int ledcontrol);
void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clock, uint16_t bitslen, uint8_t *bits, int ledcontrol);
void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits, int ledcontrol); void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits, int ledcontrol);
void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits, int ledcontrol); void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits, int ledcontrol);
void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol);

View file

@ -828,7 +828,8 @@ void CmdHIDsimTAG(uint32_t hi, uint32_t lo, int ledcontrol) {
// prepare a waveform pattern in the buffer based on the ID given then // prepare a waveform pattern in the buffer based on the ID given then
// simulate a FSK tag until the button is pressed // simulate a FSK tag until the button is pressed
// arg1 contains fcHigh and fcLow, arg2 contains STT marker and clock // arg1 contains fcHigh and fcLow, arg2 contains STT marker and clock
void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits, int ledcontrol) { void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clock, uint16_t bitslen, uint8_t *bits, int ledcontrol) {
//void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits, int ledcontrol) {
FpgaDownloadAndGo(FPGA_BITSTREAM_LF); FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
// free eventually allocated BigBuf memory // free eventually allocated BigBuf memory
@ -838,27 +839,23 @@ void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits, int
set_tracing(false); set_tracing(false);
int n = 0, i = 0; int n = 0, i = 0;
uint8_t fcHigh = arg1 >> 8;
uint8_t fcLow = arg1 & 0xFF;
uint16_t modCnt = 0; uint16_t modCnt = 0;
uint8_t clk = arg2 & 0xFF;
uint8_t stt = (arg2 >> 8) & 1;
if (stt) { if (separator) {
//int fsktype = ( fcHigh == 8 && fcLow == 5) ? 1 : 2; //int fsktype = ( fchigh == 8 && fclow == 5) ? 1 : 2;
//fcSTT(&n); //fcSTT(&n);
} }
for (i = 0; i < size; i++) { for (i = 0; i < bitslen; i++) {
if (bits[i]) if (bits[i])
fcAll(fcLow, &n, clk, &modCnt); fcAll(fclow, &n, clock, &modCnt);
else else
fcAll(fcHigh, &n, clk, &modCnt); fcAll(fchigh, &n, clock, &modCnt);
} }
WDT_HIT(); WDT_HIT();
Dbprintf("Simulating with fcHigh: %d, fcLow: %d, clk: %d, STT: %d, n: %d", fcHigh, fcLow, clk, stt, n); Dbprintf("Simulating with fcHigh: %d, fcLow: %d, clk: %d, STT: %d, n: %d", fchigh, fclow, clock, separator, n);
if (ledcontrol) LED_A_ON(); if (ledcontrol) LED_A_ON();
SimulateTagLowFrequency(n, 0, ledcontrol); SimulateTagLowFrequency(n, 0, ledcontrol);

View file

@ -42,12 +42,12 @@ static int usage_lf_read(void) {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int usage_lf_sim(void) { static int usage_lf_sim(void) {
PrintAndLogEx(NORMAL, "Simulate low frequence signal."); PrintAndLogEx(NORMAL, "Simulate low frequence tag from graphbuffer.");
PrintAndLogEx(NORMAL, "Use " _YELLOW_("'lf config'")" to set parameters."); PrintAndLogEx(NORMAL, "Use " _YELLOW_("'lf config'")" to set parameters.");
PrintAndLogEx(NORMAL, "Usage: lf sim [h] <startgap>"); PrintAndLogEx(NORMAL, "Usage: lf sim [h] <gap>");
PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help"); PrintAndLogEx(NORMAL, " h This help");
PrintAndLogEx(NORMAL, " <startgap> This help"); PrintAndLogEx(NORMAL, " <gap> Start gap (in microseconds)");
PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " lf sim 240 - start simulating with 240ms gap"); PrintAndLogEx(NORMAL, " lf sim 240 - start simulating with 240ms gap");
PrintAndLogEx(NORMAL, " lf sim"); PrintAndLogEx(NORMAL, " lf sim");
@ -156,6 +156,8 @@ static int usage_lf_find(void) {
/* send a LF command before reading */ /* send a LF command before reading */
int CmdLFCommandRead(const char *Cmd) { int CmdLFCommandRead(const char *Cmd) {
if (!session.pm3_present) return PM3_ENOTTY;
bool errors = false; bool errors = false;
uint16_t datalen = 0; uint16_t datalen = 0;
@ -164,10 +166,7 @@ int CmdLFCommandRead(const char *Cmd) {
uint16_t ones; uint16_t ones;
uint16_t zeros; uint16_t zeros;
uint8_t data[PM3_CMD_DATA_SIZE - 8]; uint8_t data[PM3_CMD_DATA_SIZE - 8];
} PACKED; } PACKED payload;
struct p payload;
uint8_t cmdp = 0; uint8_t cmdp = 0;
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
@ -251,7 +250,7 @@ int CmdFlexdemod(const char *Cmd) {
if (start == size - LONG_WAIT) { if (start == size - LONG_WAIT) {
PrintAndLogEx(WARNING, "nothing to wait for"); PrintAndLogEx(WARNING, "nothing to wait for");
return 0; return PM3_ENODATA;
} }
data[start] = 4; data[start] = 4;
@ -294,10 +293,13 @@ int CmdFlexdemod(const char *Cmd) {
} }
} }
RepaintGraphWindow(); RepaintGraphWindow();
return 0; return PM3_SUCCESS;
} }
int CmdLFSetConfig(const char *Cmd) { int CmdLFSetConfig(const char *Cmd) {
if (!session.pm3_present) return PM3_ENOTTY;
uint8_t divisor = 0;//Frequency divisor uint8_t divisor = 0;//Frequency divisor
uint8_t bps = 0; // Bits per sample uint8_t bps = 0; // Bits per sample
uint8_t decimation = 0; //How many to keep uint8_t decimation = 0; //How many to keep
@ -360,11 +362,11 @@ int CmdLFSetConfig(const char *Cmd) {
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_SET_LF_SAMPLING_CONFIG, (uint8_t *)&config, sizeof(sample_config)); SendCommandNG(CMD_SET_LF_SAMPLING_CONFIG, (uint8_t *)&config, sizeof(sample_config));
return 0; return PM3_SUCCESS;
} }
bool lf_read(bool silent, uint32_t samples) { int lf_read(bool silent, uint32_t samples) {
if (!session.pm3_present) return false; if (!session.pm3_present) return PM3_ENOTTY;
struct p { struct p {
uint8_t silent; uint8_t silent;
@ -397,7 +399,7 @@ bool lf_read(bool silent, uint32_t samples) {
int CmdLFRead(const char *Cmd) { int CmdLFRead(const char *Cmd) {
if (!session.pm3_present) return 0; if (!session.pm3_present) return PM3_ENOTTY;
bool errors = false; bool errors = false;
bool silent = false; bool silent = false;
@ -429,6 +431,9 @@ int CmdLFRead(const char *Cmd) {
} }
int CmdLFSniff(const char *Cmd) { int CmdLFSniff(const char *Cmd) {
if (!session.pm3_present) return PM3_ENOTTY;
uint8_t cmdp = tolower(param_getchar(Cmd, 0)); uint8_t cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_lf_sniff(); if (cmdp == 'h') return usage_lf_sniff();
@ -436,7 +441,7 @@ int CmdLFSniff(const char *Cmd) {
SendCommandNG(CMD_LF_SNIFF_RAW_ADC_SAMPLES, NULL, 0); SendCommandNG(CMD_LF_SNIFF_RAW_ADC_SAMPLES, NULL, 0);
WaitForResponse(CMD_ACK, NULL); WaitForResponse(CMD_ACK, NULL);
getSamples(0, false); getSamples(0, false);
return 0; return PM3_SUCCESS;
} }
static void ChkBitstream() { static void ChkBitstream() {
@ -444,7 +449,7 @@ static void ChkBitstream() {
for (int i = 0; i < (int)(GraphTraceLen / 2); i++) { for (int i = 0; i < (int)(GraphTraceLen / 2); i++) {
if (GraphBuffer[i] > 1 || GraphBuffer[i] < 0) { if (GraphBuffer[i] > 1 || GraphBuffer[i] < 0) {
CmdGetBitStream(""); CmdGetBitStream("");
PrintAndLogEx(INFO, " called cmdgetbitstream"); PrintAndLogEx(INFO, "Converted to bitstream");
break; break;
} }
} }
@ -453,8 +458,7 @@ static void ChkBitstream() {
// converts GraphBuffer to bitstream (based on zero crossings) if needed. // converts GraphBuffer to bitstream (based on zero crossings) if needed.
int CmdLFSim(const char *Cmd) { int CmdLFSim(const char *Cmd) {
uint8_t cmdp = tolower(param_getchar(Cmd, 0)); if (!session.pm3_present) return PM3_ENOTTY;
if (cmdp == 'h') return usage_lf_sim();
// sanity check // sanity check
if ( GraphTraceLen < 20 ) { if ( GraphTraceLen < 20 ) {
@ -462,6 +466,9 @@ int CmdLFSim(const char *Cmd) {
return PM3_ENODATA; return PM3_ENODATA;
} }
uint8_t cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_lf_sim();
uint16_t gap = param_get32ex(Cmd, 0, 0, 10) & 0xFFFF; uint16_t gap = param_get32ex(Cmd, 0, 0, 10) & 0xFFFF;
// convert to bitstream if necessary // convert to bitstream if necessary
@ -601,17 +608,39 @@ int CmdLFfskSim(const char *Cmd) {
if (fcHigh == 0) fcHigh = 10; if (fcHigh == 0) fcHigh = 10;
if (fcLow == 0) fcLow = 8; if (fcLow == 0) fcLow = 8;
struct {
uint8_t fchigh;
uint8_t fclow;
uint8_t separator;
uint8_t clock;
uint16_t datalen;
uint8_t data[PM3_CMD_DATA_SIZE - 6];
} PACKED payload;
payload.fchigh = fcHigh;
payload.fclow = fcLow;
payload.separator = separator;
payload.clock = clk;
size_t size = DemodBufferLen; size_t size = DemodBufferLen;
if (size > PM3_CMD_DATA_SIZE) { if (size > sizeof(payload.data)) {
PrintAndLogEx(NORMAL, "DemodBuffer too long for current implementation - length: %d - max: %d", size, PM3_CMD_DATA_SIZE); PrintAndLogEx(NORMAL, "DemodBuffer too long for current implementation - length: %d - max: %d", size, sizeof(payload.data));
size = PM3_CMD_DATA_SIZE; size = sizeof(payload.data);
} }
payload.datalen = (uint16_t)size;
memcpy(payload.data, DemodBuffer, size);
PrintAndLogEx(INFO, "Simulating");
clearCommandBuffer(); clearCommandBuffer();
SendCommandOLD(CMD_FSK_SIM_TAG, fcHigh << 8 | fcLow, (separator << 8) | clk, size, DemodBuffer, size); SendCommandNG(CMD_FSK_SIM_TAG, (uint8_t *)&payload, 6 + payload.datalen);
setClockGrid(clk, 0); setClockGrid(clk, 0);
PacketResponseNG resp; PacketResponseNG resp;
WaitForResponse(CMD_FSK_SIM_TAG, &resp); WaitForResponse(CMD_FSK_SIM_TAG, &resp);
PrintAndLogEx(INFO, "Done");
if (resp.status != PM3_EOPABORTED) if (resp.status != PM3_EOPABORTED)
return resp.status; return resp.status;
return PM3_SUCCESS; return PM3_SUCCESS;
@ -819,7 +848,7 @@ int CmdLFSimBidir(const char *Cmd) {
// HACK: not implemented in ARMSRC. // HACK: not implemented in ARMSRC.
PrintAndLogEx(INFO, "Not implemented yet."); PrintAndLogEx(INFO, "Not implemented yet.");
SendCommandMIX(CMD_LF_SIMULATE_BIDIR, 47, 384, 0, NULL, 0); SendCommandMIX(CMD_LF_SIMULATE_BIDIR, 47, 384, 0, NULL, 0);
return 0; return PM3_SUCCESS;
} }
// ICEMAN, todo, swap from Graphbuffer. // ICEMAN, todo, swap from Graphbuffer.
@ -892,7 +921,7 @@ int CmdVchDemod(const char *Cmd) {
} }
RepaintGraphWindow(); RepaintGraphWindow();
} }
return 0; return PM3_SUCCESS;
} }
//by marshmellow //by marshmellow

View file

@ -69,6 +69,6 @@ int CmdLFSniff(const char *Cmd);
int CmdVchDemod(const char *Cmd); int CmdVchDemod(const char *Cmd);
int CmdLFfind(const char *Cmd); int CmdLFfind(const char *Cmd);
bool lf_read(bool silent, uint32_t samples); int lf_read(bool silent, uint32_t samples);
#endif #endif