Merge remote-tracking branch 'upstream/master' into legic_cliparser

This commit is contained in:
tcprst 2020-12-20 20:07:17 -05:00
commit 640f9fcc02
No known key found for this signature in database
GPG key ID: 9145EAF5121AED25
3 changed files with 81 additions and 49 deletions

View file

@ -14,9 +14,8 @@
#include "cmdhf.h"
#include <ctype.h> // 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 <skip pairs> <skip triggers>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h - This help");
PrintAndLogEx(NORMAL, " <skip pairs> - skip sample pairs");
PrintAndLogEx(NORMAL, " <skip triggers> - 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] [<iter>]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h - This help");
PrintAndLogEx(NORMAL, " <iter> - 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 <Enter> to interrupt.",
"hf tune\n"
"hf tune --mixed"
);
void *argtable[] = {
arg_param_begin,
arg_u64_0("n", "iter", "<dec>", "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", "<dec>", "skip sample pairs"),
arg_u64_0(NULL, "st", "<dec>", "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 *)&params, sizeof(params));

View file

@ -237,14 +237,15 @@ static int CmdLFTune(const char *Cmd) {
CLIParserInit(&ctx, "lf tune",
"Continuously measure LF antenna tuning.\n"
"Press button or <Enter> 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", "<dec>", "number of iterations (default: 0=infinite)"),
arg_u64_0("n", "iter", "<dec>", "number of iterations (default: 0=infinite)"),
arg_u64_0("q", "divisor", "<dec>", q_str),
arg_dbl0("f", "freq", "<float>", "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;

View file

@ -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));
}
}