From 246ee8b2d7d1c0056ba26cd4df1553c3d5cc97e4 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 21 Dec 2020 02:06:43 +0100 Subject: [PATCH] hf tune - now uses the barmode --- client/src/cmdhf.c | 115 +++++++++++++++++++++++++-------------- client/src/cmdlf.c | 7 ++- client/src/preferences.c | 8 +-- 3 files changed, 81 insertions(+), 49 deletions(-) diff --git a/client/src/cmdhf.c b/client/src/cmdhf.c index 94985579e..41f3d0814 100644 --- a/client/src/cmdhf.c +++ b/client/src/cmdhf.c @@ -14,9 +14,8 @@ #include "cmdhf.h" #include // tolower - #include "cmdparser.h" // command_t -#include "cliparser.h" // parse +#include "cliparser.h" // parse #include "comms.h" // clearCommandBuffer #include "lfdemod.h" // computeSignalProperties #include "cmdhf14a.h" // ISO14443-A @@ -57,36 +56,6 @@ static int usage_hf_search(void) { return PM3_SUCCESS; } -static int usage_hf_sniff(void) { - PrintAndLogEx(NORMAL, "The high frequency sniffer will assign all available memory on device for sniffed data"); - PrintAndLogEx(NORMAL, "Use " _YELLOW_("'data samples'")" command to download from device, and " _YELLOW_("'data plot'")" to look at it"); - PrintAndLogEx(NORMAL, "Press button to quit the sniffing.\n"); - PrintAndLogEx(NORMAL, "Usage: hf sniff "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h - This help"); - PrintAndLogEx(NORMAL, " - skip sample pairs"); - PrintAndLogEx(NORMAL, " - skip number of triggers"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf sniff")); - PrintAndLogEx(NORMAL, _YELLOW_(" hf sniff 1000 0")); - PrintAndLogEx(NORMAL, ""); - return PM3_SUCCESS; -} - -static int usage_hf_tune(void) { - PrintAndLogEx(NORMAL, "Continuously measure HF antenna tuning."); - PrintAndLogEx(NORMAL, "Press button or `enter` to interrupt."); - PrintAndLogEx(NORMAL, "Usage: hf tune [h] []"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h - This help"); - PrintAndLogEx(NORMAL, " - number of iterations (default: 0=infinite)"); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf tune 1")); - PrintAndLogEx(NORMAL, ""); - return PM3_SUCCESS; -} - int CmdHFSearch(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); @@ -199,9 +168,42 @@ int CmdHFSearch(const char *Cmd) { } int CmdHFTune(const char *Cmd) { - char cmdp = tolower(param_getchar(Cmd, 0)); - if (cmdp == 'h') return usage_hf_tune(); - int iter = param_get32ex(Cmd, 0, 0, 10); + + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf tune", + "Continuously measure HF antenna tuning.\n" + "Press button or to interrupt.", + "hf tune\n" + "hf tune --mixed" + ); + + void *argtable[] = { + arg_param_begin, + arg_u64_0("n", "iter", "", "number of iterations (default: 0=infinite)"), + arg_lit0(NULL, "bar", "bar style"), + arg_lit0(NULL, "mix", "mixed style"), + arg_lit0(NULL, "value", "values style"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + uint32_t iter = arg_get_u32_def(ctx, 1, 0); + bool is_bar = arg_get_lit(ctx, 2); + bool is_mix = arg_get_lit(ctx, 3); + bool is_value = arg_get_lit(ctx, 4); + CLIParserFree(ctx); + + if ((is_bar + is_mix + is_value) > 1) { + PrintAndLogEx(ERR, "Select only one output style"); + return PM3_EINVARG; + } + + barMode_t style = session.bar_mode; + if (is_bar) + style = STYLE_BAR; + if (is_mix) + style = STYLE_MIXED; + if (is_value) + style = STYLE_VALUE; PrintAndLogEx(INFO, "Measuring HF antenna, click " _GREEN_("pm3 button") " or press " _GREEN_("Enter") " to exit"); PacketResponseNG resp; @@ -215,6 +217,12 @@ int CmdHFTune(const char *Cmd) { } mode[0] = 2; + + uint32_t max = 0xFFFF; + bool first = true; + + print_progress(0, max, style); + // loop forever (till button pressed) if iter = 0 (default) for (uint8_t i = 0; iter == 0 || i < iter; i++) { if (kbd_enter_pressed()) { @@ -225,15 +233,23 @@ int CmdHFTune(const char *Cmd) { if (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF, &resp, 1000)) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF measure, aborting"); - return PM3_ETIMEOUT; + break; } if ((resp.status == PM3_EOPABORTED) || (resp.length != sizeof(uint16_t))) { + PrintAndLogEx(NORMAL, ""); break; } uint16_t volt = resp.data.asDwords[0] & 0xFFFF; - PrintAndLogEx(INPLACE, " %u mV / %2u V", volt, (uint16_t)(volt / 1000)); + if (first) { + max = (volt * 1.03); + first = false; + } + if ( volt > max) { + max = (volt * 1.03); + } + print_progress(volt, max, style); } mode[0] = 3; @@ -242,7 +258,7 @@ int CmdHFTune(const char *Cmd) { PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF shutdown, aborting"); return PM3_ETIMEOUT; } - PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "\x1b%c[2K\r", 30); PrintAndLogEx(INFO, "Done."); return PM3_SUCCESS; } @@ -252,16 +268,31 @@ int CmdHFTune(const char *Cmd) { // Takes all available bigbuff memory // data sample to download? Not sure what we can do with the data. int CmdHFSniff(const char *Cmd) { - char cmdp = tolower(param_getchar(Cmd, 0)); - if (cmdp == 'h') return usage_hf_sniff(); + + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf sniff", + "The high frequency sniffer will assign all available memory on device for sniffed data.s\n" + "Use `data samples` to download from device and `data plot` to visualize it.\n" + "Press button to quit the sniffing.", + "hf sniff\n" + "hf sniff --sp 1000 --st 0 -> skip 1000 pairs, skip 0 triggers" + ); + void *argtable[] = { + arg_param_begin, + arg_u64_0(NULL, "sp", "", "skip sample pairs"), + arg_u64_0(NULL, "st", "", "skip number of triggers"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); struct { uint32_t samplesToSkip; uint32_t triggersToSkip; } PACKED params; - params.samplesToSkip = param_get32ex(Cmd, 0, 0, 10); - params.triggersToSkip = param_get32ex(Cmd, 1, 0, 10); + params.samplesToSkip = arg_get_u32_def(ctx, 1, 0); + params.triggersToSkip = arg_get_u32_def(ctx, 2, 0); + CLIParserFree(ctx); clearCommandBuffer(); SendCommandNG(CMD_HF_SNIFF, (uint8_t *)¶ms, sizeof(params)); diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 4cc303f19..bd99f648e 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -237,14 +237,15 @@ static int CmdLFTune(const char *Cmd) { CLIParserInit(&ctx, "lf tune", "Continuously measure LF antenna tuning.\n" "Press button or to interrupt.", - "lf tune" + "lf tune\n" + "lf tune --mixed" ); char q_str[60]; snprintf(q_str, sizeof(q_str), "Frequency divisor. %d -> 134 kHz, %d -> 125 kHz", LF_DIVISOR_134, LF_DIVISOR_125); void *argtable[] = { arg_param_begin, - arg_u64_0("n", "iteration", "", "number of iterations (default: 0=infinite)"), + arg_u64_0("n", "iter", "", "number of iterations (default: 0=infinite)"), arg_u64_0("q", "divisor", "", q_str), arg_dbl0("f", "freq", "", "Frequency in kHz"), arg_lit0(NULL, "bar", "bar style"), @@ -301,7 +302,7 @@ static int CmdLFTune(const char *Cmd) { params[0] = 2; - #define MAX_ADC_LF_VOLTAGE 140800 +// #define MAX_ADC_LF_VOLTAGE 140800 uint32_t max = 71000; bool first = true; diff --git a/client/src/preferences.c b/client/src/preferences.c index b6b1eddd3..c80e24e3a 100644 --- a/client/src/preferences.c +++ b/client/src/preferences.c @@ -561,16 +561,16 @@ static void showBarModeState(prefShowOpt_t opt) { switch (session.bar_mode) { case STYLE_BAR: - PrintAndLogEx(INFO, " %s mode................... "_GREEN_("bar"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s barmode................ "_GREEN_("bar"), prefShowMsg(opt)); break; case STYLE_MIXED: - PrintAndLogEx(INFO, " %s mode................... "_GREEN_("mixed"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s barmode................ "_GREEN_("mixed"), prefShowMsg(opt)); break; case STYLE_VALUE: - PrintAndLogEx(INFO, " %s mode................... "_GREEN_("value"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s barmode................ "_GREEN_("value"), prefShowMsg(opt)); break; default: - PrintAndLogEx(INFO, " %s mode.................. "_RED_("unknown"), prefShowMsg(opt)); + PrintAndLogEx(INFO, " %s barmode............... "_RED_("unknown"), prefShowMsg(opt)); } }