From f82894ba6918823a64f2fc3da1b83cfdb9c19ceb Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 21 Oct 2015 09:07:36 +0200 Subject: [PATCH] CHG: move some methods, its easier to read now. Cosmetic change. --- client/cmdlf.c | 244 +++++++++++++++++++++++-------------------------- client/cmdlf.h | 8 ++ 2 files changed, 120 insertions(+), 132 deletions(-) diff --git a/client/cmdlf.c b/client/cmdlf.c index f04feb97..c638bb93 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -33,9 +33,7 @@ #include "cmdlfviking.h" static int CmdHelp(const char *Cmd); - -int usage_lf_cmdread() -{ +int usage_lf_cmdread(void) { PrintAndLog("Usage: lf cmdread d z o c [H]"); PrintAndLog("Options: "); PrintAndLog(" h This help"); @@ -50,6 +48,85 @@ int usage_lf_cmdread() PrintAndLog(" lf cmdread d 80 z 100 o 100 c 11000 H"); return 0; } +int usage_lf_read(void){ + PrintAndLog("Usage: lf read [h] [s]"); + PrintAndLog("Options: "); + PrintAndLog(" h This help"); + PrintAndLog(" s silent run no printout"); + PrintAndLog("This function takes no arguments. "); + PrintAndLog("Use 'lf config' to set parameters."); + return 0; +} +int usage_lf_snoop(void) { + PrintAndLog("Usage: lf snoop"); + PrintAndLog("Options: "); + PrintAndLog(" h This help"); + PrintAndLog("This function takes no arguments. "); + PrintAndLog("Use 'lf config' to set parameters."); + return 0; +} +int usage_lf_config(void) { + PrintAndLog("Usage: lf config [H|] [b ] [d ] [a 0|1]"); + PrintAndLog("Options: "); + PrintAndLog(" h This help"); + PrintAndLog(" L Low frequency (125 KHz)"); + PrintAndLog(" H High frequency (134 KHz)"); + PrintAndLog(" q Manually set divisor. 88-> 134KHz, 95-> 125 Hz"); + PrintAndLog(" b Sets resolution of bits per sample. Default (max): 8"); + PrintAndLog(" d Sets decimation. A value of N saves only 1 in N samples. Default: 1"); + PrintAndLog(" a [0|1] Averaging - if set, will average the stored sample value when decimating. Default: 1"); + PrintAndLog(" t Sets trigger threshold. 0 means no threshold (range: 0-128)"); + PrintAndLog("Examples:"); + PrintAndLog(" lf config b 8 L"); + PrintAndLog(" Samples at 125KHz, 8bps."); + PrintAndLog(" lf config H b 4 d 3"); + PrintAndLog(" Samples at 134KHz, averages three samples into one, stored with "); + PrintAndLog(" a resolution of 4 bits per sample."); + PrintAndLog(" lf read"); + PrintAndLog(" Performs a read (active field)"); + PrintAndLog(" lf snoop"); + PrintAndLog(" Performs a snoop (no active field)"); + return 0; +} +int usage_lf_simfsk(void) { + PrintAndLog("Usage: lf simfsk [c ] [i] [H ] [L ] [d ]"); + PrintAndLog("Options: "); + PrintAndLog(" h This help"); + PrintAndLog(" c Manually set clock - can autodetect if using DemodBuffer"); + PrintAndLog(" i invert data"); + PrintAndLog(" H Manually set the larger Field Clock"); + PrintAndLog(" L 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; +} +int usage_lf_simask(void) { + PrintAndLog("Usage: lf simask [c ] [i] [b|m|r] [s] [d ]"); + PrintAndLog("Options: "); + PrintAndLog(" h This help"); + PrintAndLog(" c Manually set clock - can autodetect if using DemodBuffer"); + PrintAndLog(" i invert data"); + PrintAndLog(" b sim ask/biphase"); + PrintAndLog(" m sim ask/manchester - Default"); + PrintAndLog(" r sim ask/raw"); + 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"); + return 0; +} +int usage_lf_simpsk(void) { + 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; +} /* send a LF command before reading */ int CmdLFCommandRead(const char *Cmd) @@ -421,51 +498,6 @@ int CmdIndalaClone(const char *Cmd) return 0; } -int usage_lf_read() -{ - PrintAndLog("Usage: lf read"); - PrintAndLog("Options: "); - PrintAndLog(" h This help"); - PrintAndLog(" s silent run no printout"); - PrintAndLog("This function takes no arguments. "); - PrintAndLog("Use 'lf config' to set parameters."); - return 0; -} -int usage_lf_snoop() -{ - PrintAndLog("Usage: lf snoop"); - PrintAndLog("Options: "); - PrintAndLog(" h This help"); - PrintAndLog("This function takes no arguments. "); - PrintAndLog("Use 'lf config' to set parameters."); - return 0; -} - -int usage_lf_config() -{ - PrintAndLog("Usage: lf config [H|] [b ] [d ] [a 0|1]"); - PrintAndLog("Options: "); - PrintAndLog(" h This help"); - PrintAndLog(" L Low frequency (125 KHz)"); - PrintAndLog(" H High frequency (134 KHz)"); - PrintAndLog(" q Manually set divisor. 88-> 134KHz, 95-> 125 Hz"); - PrintAndLog(" b Sets resolution of bits per sample. Default (max): 8"); - PrintAndLog(" d Sets decimation. A value of N saves only 1 in N samples. Default: 1"); - PrintAndLog(" a [0|1] Averaging - if set, will average the stored sample value when decimating. Default: 1"); - PrintAndLog(" t Sets trigger threshold. 0 means no threshold (range: 0-128)"); - PrintAndLog("Examples:"); - PrintAndLog(" lf config b 8 L"); - PrintAndLog(" Samples at 125KHz, 8bps."); - PrintAndLog(" lf config H b 4 d 3"); - PrintAndLog(" Samples at 134KHz, averages three samples into one, stored with "); - PrintAndLog(" a resolution of 4 bits per sample."); - PrintAndLog(" lf read"); - PrintAndLog(" Performs a read (active field)"); - PrintAndLog(" lf snoop"); - PrintAndLog(" Performs a snoop (no active field)"); - return 0; -} - int CmdLFSetConfig(const char *Cmd) { @@ -545,35 +577,31 @@ int CmdLFSetConfig(const char *Cmd) int CmdLFRead(const char *Cmd) { - - uint8_t cmdp = 0; bool arg1 = false; - if (param_getchar(Cmd, cmdp) == 'h') - { - return usage_lf_read(); - } - if (param_getchar(Cmd, cmdp) == 's') arg1 = true; //suppress print - //And ship it to device + uint8_t cmdp = param_getchar(Cmd, 0); + + if ( cmdp == 'h' || cmdp == 'H') return usage_lf_read(); + + //suppress print + if ( cmdp == 's' || cmdp == 'S') arg1 = true; + UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_125K, {arg1,0,0}}; + clearCommandBuffer(); SendCommand(&c); - //WaitForResponse(CMD_ACK,NULL); if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) { PrintAndLog("command execution time out"); return 1; } - return 0; } int CmdLFSnoop(const char *Cmd) { - uint8_t cmdp =0; - if(param_getchar(Cmd, cmdp) == 'h') - { - return usage_lf_snoop(); - } - + uint8_t cmdp = param_getchar(Cmd, 0); + if(cmdp == 'h' || cmdp == 'H') return usage_lf_snoop(); + UsbCommand c = {CMD_LF_SNOOP_RAW_ADC_SAMPLES}; + clearCommandBuffer(); SendCommand(&c); WaitForResponse(CMD_ACK,NULL); return 0; @@ -595,81 +623,33 @@ static void ChkBitstream(const char *str) // converts GraphBuffer to bitstream (based on zero crossings) if needed. int CmdLFSim(const char *Cmd) { - int i,j; - static int gap; + int i,j; + static int gap; - sscanf(Cmd, "%i", &gap); + sscanf(Cmd, "%i", &gap); // convert to bitstream if necessary - - ChkBitstream(Cmd); + ChkBitstream(Cmd); //can send only 512 bits at a time (1 byte sent per bit...) - printf("Sending [%d bytes]", GraphTraceLen); - for (i = 0; i < GraphTraceLen; i += USB_CMD_DATA_SIZE) { - UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}}; - - for (j = 0; j < USB_CMD_DATA_SIZE; j++) { - c.d.asBytes[j] = GraphBuffer[i+j]; - } - SendCommand(&c); - WaitForResponse(CMD_ACK,NULL); - printf("."); - } - - printf("\n"); - PrintAndLog("Starting to simulate"); - UsbCommand c = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}}; - SendCommand(&c); - return 0; -} + printf("Sending [%d bytes]", GraphTraceLen); + for (i = 0; i < GraphTraceLen; i += USB_CMD_DATA_SIZE) { + UsbCommand c = {CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}}; -int usage_lf_simfsk(void) -{ - //print help - PrintAndLog("Usage: lf simfsk [c ] [i] [H ] [L ] [d ]"); - PrintAndLog("Options: "); - PrintAndLog(" h This help"); - PrintAndLog(" c Manually set clock - can autodetect if using DemodBuffer"); - PrintAndLog(" i invert data"); - PrintAndLog(" H Manually set the larger Field Clock"); - PrintAndLog(" L 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; -} - -int usage_lf_simask(void) -{ - //print help - PrintAndLog("Usage: lf simask [c ] [i] [b|m|r] [s] [d ]"); - PrintAndLog("Options: "); - PrintAndLog(" h This help"); - PrintAndLog(" c Manually set clock - can autodetect if using DemodBuffer"); - PrintAndLog(" i invert data"); - PrintAndLog(" b sim ask/biphase"); - PrintAndLog(" m sim ask/manchester - Default"); - PrintAndLog(" r sim ask/raw"); - 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"); - return 0; -} + for (j = 0; j < USB_CMD_DATA_SIZE; j++) { + c.d.asBytes[j] = GraphBuffer[i+j]; + } + clearCommandBuffer(); + SendCommand(&c); + WaitForResponse(CMD_ACK,NULL); + printf("."); + } -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; + PrintAndLog("\nStarting to simulate"); + UsbCommand c = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}}; + clearCommandBuffer(); + SendCommand(&c); + return 0; } // by marshmellow - sim ask data given clock, fcHigh, fcLow, invert diff --git a/client/cmdlf.h b/client/cmdlf.h index 7dd1b044..5dbb9b6e 100644 --- a/client/cmdlf.h +++ b/client/cmdlf.h @@ -27,4 +27,12 @@ int CmdLFSnoop(const char *Cmd); int CmdVchDemod(const char *Cmd); int CmdLFfind(const char *Cmd); +// usages helptext +int usage_lf_cmdread(void); +int usage_lf_read(void); +int usage_lf_snoop(void); +int usage_lf_config(void); +int usage_lf_simfsk(void); +int usage_lf_simask(void); +int usage_lf_simpsk(void); #endif -- 2.39.2