FIX: Found a minor bug in 'LF CMDREAD' where it on device side didn't compare with the right char 'h' instead of 'H'. Re-wrote that whole part anyway, I changed periods to be max 0xFFFF in length, doubtful that a zero or one delay will be bigger than 65535...

This commit is contained in:
iceman1001 2016-07-30 19:30:53 +02:00
commit d0724780ab
3 changed files with 54 additions and 50 deletions

View file

@ -26,29 +26,28 @@
* @param period_1 * @param period_1
* @param command * @param command
*/ */
void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command) void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t periods, uint32_t useHighFreq, uint8_t *command)
{ {
int divisor_used = 95; // 125 KHz
// see if 'h' was specified
if (command[strlen((char *) command) - 1] == 'h')
divisor_used = 88; // 134.8 KHz
sample_config sc = { 0,0,1, divisor_used, 0};
setSamplingConfig(&sc);
//clear read buffer
BigBuf_Clear_keep_EM();
/* Make sure the tag is reset */ /* Make sure the tag is reset */
FpgaDownloadAndGo(FPGA_BITSTREAM_LF); FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
SpinDelay(2500); SpinDelay(200);
uint16_t period_0 = periods >> 16;
uint16_t period_1 = periods & 0xFFFF;
// 95 == 125 KHz 88 == 124.8 KHz
int divisor_used = (useHighFreq) ? 88 : 95 ; // 125 KHz
sample_config sc = { 0,0,1, divisor_used, 0};
setSamplingConfig(&sc);
//clear read buffer
BigBuf_Clear_keep_EM();
LFSetupFPGAForADC(sc.divisor, 1); LFSetupFPGAForADC(sc.divisor, 1);
// And a little more time for the tag to fully power up // And a little more time for the tag to fully power up
SpinDelay(2000); SpinDelay(50);
// now modulate the reader field // now modulate the reader field
while(*command != '\0' && *command != ' ') { while(*command != '\0' && *command != ' ') {
@ -68,7 +67,6 @@ void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint
LED_D_OFF(); LED_D_OFF();
SpinDelayUs(delay_off); SpinDelayUs(delay_off);
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, sc.divisor); FpgaSendCommand(FPGA_CMD_SET_DIVISOR, sc.divisor);
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD); FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
// now do the read // now do the read

View file

@ -16,10 +16,10 @@ int usage_lf_cmdread(void) {
PrintAndLog(" h This help"); PrintAndLog(" h This help");
PrintAndLog(" L Low frequency (125 KHz)"); PrintAndLog(" L Low frequency (125 KHz)");
PrintAndLog(" H High frequency (134 KHz)"); PrintAndLog(" H High frequency (134 KHz)");
PrintAndLog(" d <delay> delay OFF period, (dec)"); PrintAndLog(" d <delay> delay OFF period, (decimal)");
PrintAndLog(" z <zero> time period ZERO, (dec)"); PrintAndLog(" z <zero> time period ZERO, (decimal)");
PrintAndLog(" o <one> time period ONE, (dec)"); PrintAndLog(" o <one> time period ONE, (decimal)");
PrintAndLog(" c <cmd> Command bytes"); PrintAndLog(" c <cmd> Command bytes (in ones and zeros)");
PrintAndLog(" ************* All periods in microseconds (ms)"); PrintAndLog(" ************* All periods in microseconds (ms)");
PrintAndLog("Examples:"); PrintAndLog("Examples:");
PrintAndLog(" lf cmdread d 80 z 100 o 200 c 11000"); PrintAndLog(" lf cmdread d 80 z 100 o 200 c 11000");
@ -44,7 +44,7 @@ int usage_lf_snoop(void) {
return 0; return 0;
} }
int usage_lf_config(void) { int usage_lf_config(void) {
PrintAndLog("Usage: lf config [H|<divisor>] [b <bps>] [d <decim>] [a 0|1]"); PrintAndLog("Usage: lf config [h] [H|<divisor>] [b <bps>] [d <decim>] [a 0|1]");
PrintAndLog("Options:"); PrintAndLog("Options:");
PrintAndLog(" h This help"); PrintAndLog(" h This help");
PrintAndLog(" L Low frequency (125 KHz)"); PrintAndLog(" L Low frequency (125 KHz)");
@ -106,35 +106,38 @@ int usage_lf_simpsk(void) {
return 0; return 0;
} }
int usage_lf_find(void){ int usage_lf_find(void){
PrintAndLog("Usage: lf search <0|1> [u]"); PrintAndLog("Usage: lf search [h] <0|1> [u]");
PrintAndLog(" <use data from Graphbuffer> , if not set, try reading data from tag.");
PrintAndLog(" [Search for Unknown tags] , if not set, reads only known tags.");
PrintAndLog(""); PrintAndLog("");
PrintAndLog(" sample: lf search = try reading data from tag & search for known tags"); PrintAndLog("Options:");
PrintAndLog(" : lf search 1 = use data from GraphBuffer & search for known tags"); PrintAndLog(" h This help");
PrintAndLog(" : lf search u = try reading data from tag & search for known and unknown tags"); PrintAndLog(" <0|1> Use data from Graphbuffer, if not set, try reading data from tag.");
PrintAndLog(" : lf search 1 u = use data from GraphBuffer & search for known and unknown tags"); PrintAndLog(" u Search for Unknown tags, if not set, reads only known tags.");
PrintAndLog("Examples:");
PrintAndLog(" lf search = try reading data from tag & search for known tags");
PrintAndLog(" lf search 1 = use data from GraphBuffer & search for known tags");
PrintAndLog(" lf search u = try reading data from tag & search for known and unknown tags");
PrintAndLog(" lf search 1 u = use data from GraphBuffer & search for known and unknown tags");
return 0; return 0;
} }
/* send a LF command before reading */ /* send a LF command before reading */
int CmdLFCommandRead(const char *Cmd) int CmdLFCommandRead(const char *Cmd) {
{ // static char dummy[3] = {0x20,0x00,0x00};
static char dummy[3] = {0x20,0x00,0x00};
UsbCommand c = {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K};
bool errors = FALSE; bool errors = FALSE;
bool useHighFreq = FALSE;
uint16_t one = 0, zero = 0;
uint8_t cmdp = 0; uint8_t cmdp = 0;
int strLength = 0; int strLength = 0;
UsbCommand c = {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K, {0,0,0}};
while(param_getchar(Cmd, cmdp) != 0x00) { while(param_getchar(Cmd, cmdp) != 0x00) {
switch(param_getchar(Cmd, cmdp)) switch(param_getchar(Cmd, cmdp)) {
{
case 'h': case 'h':
return usage_lf_cmdread(); return usage_lf_cmdread();
case 'H': case 'H':
dummy[1]='h'; //dummy[1]='h';
useHighFreq = TRUE;
cmdp++; cmdp++;
break; break;
case 'L': case 'L':
@ -149,11 +152,11 @@ int CmdLFCommandRead(const char *Cmd)
cmdp+=2; cmdp+=2;
break; break;
case 'z': case 'z':
c.arg[1] = param_get32ex(Cmd, cmdp+1, 0, 10); zero = param_get32ex(Cmd, cmdp+1, 0, 10) & 0xFFFF;
cmdp+=2; cmdp+=2;
break; break;
case 'o': case 'o':
c.arg[2] = param_get32ex(Cmd, cmdp+1, 0, 10); one = param_get32ex(Cmd, cmdp+1, 0, 10) & 0xFFFF;
cmdp+=2; cmdp+=2;
break; break;
default: default:
@ -164,13 +167,16 @@ int CmdLFCommandRead(const char *Cmd)
if(errors) break; if(errors) break;
} }
// No args // No args
if (cmdp == 0) errors = 1; if (cmdp == 0) errors = TRUE;
//Validations //Validations
if (errors) return usage_lf_cmdread(); if (errors) return usage_lf_cmdread();
// in case they specified 'H' // zero and one lengths
strcpy((char *)&c.d.asBytes + strLength, dummy); c.arg[1] = zero << 16 | one;
// add frequency 125 or 134
c.arg[2] = useHighFreq;
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);