mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
hw connect, ping, version, standalone, tune etc - now uses cliparser
This commit is contained in:
parent
23df29fe32
commit
9a0165f4ca
2 changed files with 140 additions and 80 deletions
|
@ -26,35 +26,6 @@
|
||||||
|
|
||||||
static int CmdHelp(const char *Cmd);
|
static int CmdHelp(const char *Cmd);
|
||||||
|
|
||||||
static int usage_hw_setmux(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Set the ADC mux to a specific value");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: hw setmux [h] <lopkd | loraw | hipkd | hiraw>");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " h This help");
|
|
||||||
PrintAndLogEx(NORMAL, " <type> Low peak, Low raw, Hi peak, Hi raw");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hw setmux lopkd"));
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int usage_hw_connect(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Connects to a Proxmark3 device via specified serial port");
|
|
||||||
PrintAndLogEx(NORMAL, "Baudrate here is only for physical UART or UART-BT, " _YELLOW_("not")" for USB-CDC or blue shark add-on");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: hw connect [h] [p <port>] [b <baudrate>]");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " h This help");
|
|
||||||
PrintAndLogEx(NORMAL, " p <port> Serial port to connect to, else retry the last used one");
|
|
||||||
PrintAndLogEx(NORMAL, " b <baudrate> Baudrate");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hw connect p "SERIAL_PORT_EXAMPLE_H));
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hw connect p "SERIAL_PORT_EXAMPLE_H" b 115200"));
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void lookupChipID(uint32_t iChipID, uint32_t mem_used) {
|
static void lookupChipID(uint32_t iChipID, uint32_t mem_used) {
|
||||||
char asBuff[120];
|
char asBuff[120];
|
||||||
memset(asBuff, 0, sizeof(asBuff));
|
memset(asBuff, 0, sizeof(asBuff));
|
||||||
|
@ -564,51 +535,114 @@ static int CmdSetDivisor(const char *Cmd) {
|
||||||
|
|
||||||
static int CmdSetMux(const char *Cmd) {
|
static int CmdSetMux(const char *Cmd) {
|
||||||
|
|
||||||
if (strlen(Cmd) < 5) {
|
CLIParserContext *ctx;
|
||||||
usage_hw_setmux();
|
CLIParserInit(&ctx, "hw setmux",
|
||||||
|
"Set the ADC mux to a specific value",
|
||||||
|
"hw setmux --hiraw -> set HIGH RAW"
|
||||||
|
);
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_lit0(NULL, "lopkd", "low peak"),
|
||||||
|
arg_lit0(NULL, "loraw", "low raw"),
|
||||||
|
arg_lit0(NULL, "hipkd", "high peak"),
|
||||||
|
arg_lit0(NULL, "hiraw", "high raw"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
bool lopkd = arg_get_lit(ctx, 1);
|
||||||
|
bool loraw = arg_get_lit(ctx, 2);
|
||||||
|
bool hipkd = arg_get_lit(ctx, 3);
|
||||||
|
bool hiraw = arg_get_lit(ctx, 4);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
|
if ((lopkd + loraw + hipkd + hiraw) > 1) {
|
||||||
|
PrintAndLogEx(INFO, "Can only set one mux");
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
str_lower((char *)Cmd);
|
|
||||||
|
|
||||||
uint8_t arg = 0;
|
uint8_t arg = 0;
|
||||||
if (strcmp(Cmd, "lopkd") == 0)
|
if (lopkd)
|
||||||
arg = 0;
|
arg = 0;
|
||||||
else if (strcmp(Cmd, "loraw") == 0)
|
else if (loraw)
|
||||||
arg = 1;
|
arg = 1;
|
||||||
else if (strcmp(Cmd, "hipkd") == 0)
|
else if (hipkd)
|
||||||
arg = 2;
|
arg = 2;
|
||||||
else if (strcmp(Cmd, "hiraw") == 0)
|
else if (hiraw)
|
||||||
arg = 3;
|
arg = 3;
|
||||||
else {
|
|
||||||
usage_hw_setmux();
|
|
||||||
return PM3_EINVARG;
|
|
||||||
}
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandNG(CMD_SET_ADC_MUX, (uint8_t *)&arg, sizeof(arg));
|
SendCommandNG(CMD_SET_ADC_MUX, (uint8_t *)&arg, sizeof(arg));
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdStandalone(const char *Cmd) {
|
static int CmdStandalone(const char *Cmd) {
|
||||||
// (void)Cmd; // Cmd is not used so far
|
CLIParserContext *ctx;
|
||||||
uint8_t arg = param_get8ex(Cmd, 0, 0, 10);
|
CLIParserInit(&ctx, "hw standalone",
|
||||||
|
"Start standalone mode",
|
||||||
|
"hw standalone -> start \n"
|
||||||
|
"hw standalone -a 1 -> start and send arg 1"
|
||||||
|
);
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_u64_0("a", "arg", "<dec>", "argument byte"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
uint8_t arg = arg_get_u32(ctx, 1);
|
||||||
|
CLIParserFree(ctx);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandNG(CMD_STANDALONE, (uint8_t *)&arg, sizeof(arg));
|
SendCommandNG(CMD_STANDALONE, (uint8_t *)&arg, sizeof(arg));
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdTune(const char *Cmd) {
|
static int CmdTune(const char *Cmd) {
|
||||||
|
CLIParserContext *ctx;
|
||||||
|
CLIParserInit(&ctx, "hw tune",
|
||||||
|
"Measure antenna tuning",
|
||||||
|
"hw tune"
|
||||||
|
);
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
CLIParserFree(ctx);
|
||||||
return CmdTuneSamples(Cmd);
|
return CmdTuneSamples(Cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdVersion(const char *Cmd) {
|
static int CmdVersion(const char *Cmd) {
|
||||||
(void)Cmd; // Cmd is not used so far
|
CLIParserContext *ctx;
|
||||||
|
CLIParserInit(&ctx, "hw version",
|
||||||
|
"Show version information about the connected Proxmark3",
|
||||||
|
"hw version"
|
||||||
|
);
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
CLIParserFree(ctx);
|
||||||
pm3_version(true, false);
|
pm3_version(true, false);
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdStatus(const char *Cmd) {
|
static int CmdStatus(const char *Cmd) {
|
||||||
(void)Cmd; // Cmd is not used so far
|
CLIParserContext *ctx;
|
||||||
|
CLIParserInit(&ctx, "hw status",
|
||||||
|
"Show runtime status information about the connected Proxmark3",
|
||||||
|
"hw status"
|
||||||
|
);
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
CLIParserFree(ctx);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
SendCommandNG(CMD_STATUS, NULL, 0);
|
SendCommandNG(CMD_STATUS, NULL, 0);
|
||||||
|
@ -692,7 +726,19 @@ static int CmdTearoff(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdTia(const char *Cmd) {
|
static int CmdTia(const char *Cmd) {
|
||||||
(void)Cmd; // Cmd is not used so far
|
CLIParserContext *ctx;
|
||||||
|
CLIParserInit(&ctx, "hw tia",
|
||||||
|
"Trigger a Timing Interval Acquisition to re-adjust the RealTimeCounter divider",
|
||||||
|
"hw tia"
|
||||||
|
);
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "Triggering new Timing Interval Acquisition (TIA)...");
|
PrintAndLogEx(INFO, "Triggering new Timing Interval Acquisition (TIA)...");
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandNG(CMD_TIA, NULL, 0);
|
SendCommandNG(CMD_TIA, NULL, 0);
|
||||||
|
@ -706,19 +752,38 @@ static int CmdTia(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdPing(const char *Cmd) {
|
static int CmdPing(const char *Cmd) {
|
||||||
uint32_t len = strtol(Cmd, NULL, 0);
|
CLIParserContext *ctx;
|
||||||
|
CLIParserInit(&ctx, "hw ping",
|
||||||
|
"Test if the Proxmark3 is responsive",
|
||||||
|
"hw ping\n"
|
||||||
|
"hw ping --len 32"
|
||||||
|
);
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_u64_0("l", "len", "<dec>", "length of payload to send"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
uint32_t len = arg_get_u32(ctx, 1);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
if (len > PM3_CMD_DATA_SIZE)
|
if (len > PM3_CMD_DATA_SIZE)
|
||||||
len = PM3_CMD_DATA_SIZE;
|
len = PM3_CMD_DATA_SIZE;
|
||||||
|
|
||||||
if (len) {
|
if (len) {
|
||||||
PrintAndLogEx(INFO, "Ping sent with payload len = %d", len);
|
PrintAndLogEx(INFO, "Ping sent with payload len " _YELLOW_("%d"), len);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(INFO, "Ping sent");
|
PrintAndLogEx(INFO, "Ping sent");
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
uint8_t data[PM3_CMD_DATA_SIZE] = {0};
|
uint8_t data[PM3_CMD_DATA_SIZE] = {0};
|
||||||
|
|
||||||
for (uint16_t i = 0; i < len; i++)
|
for (uint16_t i = 0; i < len; i++)
|
||||||
data[i] = i & 0xFF;
|
data[i] = i & 0xFF;
|
||||||
|
|
||||||
SendCommandNG(CMD_PING, data, len);
|
SendCommandNG(CMD_PING, data, len);
|
||||||
if (WaitForResponseTimeout(CMD_PING, &resp, 1000)) {
|
if (WaitForResponseTimeout(CMD_PING, &resp, 1000)) {
|
||||||
if (len) {
|
if (len) {
|
||||||
|
@ -734,35 +799,38 @@ static int CmdPing(const char *Cmd) {
|
||||||
|
|
||||||
static int CmdConnect(const char *Cmd) {
|
static int CmdConnect(const char *Cmd) {
|
||||||
|
|
||||||
uint32_t baudrate = USART_BAUD_RATE;
|
CLIParserContext *ctx;
|
||||||
uint8_t cmdp = 0;
|
CLIParserInit(&ctx, "hw connect",
|
||||||
char port[FILE_PATH_SIZE] = {0};
|
"Connects to a Proxmark3 device via specified serial port.\n"
|
||||||
|
"Baudrate here is only for physical UART or UART-BT, NOT for USB-CDC or blue shark add-on",
|
||||||
|
"hw connect -p "SERIAL_PORT_EXAMPLE_H"\n"
|
||||||
|
"hw connect -p "SERIAL_PORT_EXAMPLE_H" -b 115200"
|
||||||
|
);
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00) {
|
void *argtable[] = {
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
arg_param_begin,
|
||||||
case 'h':
|
arg_str0("p", "port", NULL, "Serial port to connect to, else retry the last used one"),
|
||||||
return usage_hw_connect();
|
arg_u64_0("b", "baud", "<dec>", "Baudrate"),
|
||||||
case 'p': {
|
arg_param_end
|
||||||
param_getstr(Cmd, cmdp + 1, port, sizeof(port));
|
};
|
||||||
cmdp += 2;
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
break;
|
|
||||||
}
|
int p_len = FILE_PATH_SIZE;
|
||||||
case 'b':
|
char port[FILE_PATH_SIZE] = {0};
|
||||||
baudrate = param_get32ex(Cmd, cmdp + 1, USART_BAUD_RATE, 10);
|
CLIGetStrWithReturn(ctx, 1, (uint8_t*)port, &p_len);
|
||||||
if (baudrate == 0)
|
uint32_t baudrate = arg_get_u32_def(ctx, 2, USART_BAUD_RATE);
|
||||||
return usage_hw_connect();
|
CLIParserFree(ctx);
|
||||||
cmdp += 2;
|
|
||||||
break;
|
if (baudrate == 0) {
|
||||||
default:
|
PrintAndLogEx(WARNING, "Baudrate can't be zero");
|
||||||
usage_hw_connect();
|
return PM3_EINVARG;
|
||||||
return PM3_EINVARG;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// default back to previous used serial port
|
// default back to previous used serial port
|
||||||
if (strlen(port) == 0) {
|
if (strlen(port) == 0) {
|
||||||
if (strlen(conn.serial_port_name) == 0) {
|
if (strlen(conn.serial_port_name) == 0) {
|
||||||
return usage_hw_connect();
|
PrintAndLogEx(WARNING, "Must specify a serial port");
|
||||||
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
memcpy(port, conn.serial_port_name, sizeof(port));
|
memcpy(port, conn.serial_port_name, sizeof(port));
|
||||||
}
|
}
|
||||||
|
@ -794,7 +862,7 @@ static command_t CommandTable[] = {
|
||||||
{"ping", CmdPing, IfPm3Present, "Test if the Proxmark3 is responsive"},
|
{"ping", CmdPing, IfPm3Present, "Test if the Proxmark3 is responsive"},
|
||||||
{"readmem", CmdReadmem, IfPm3Present, "Read memory at decimal address from flash"},
|
{"readmem", CmdReadmem, IfPm3Present, "Read memory at decimal address from flash"},
|
||||||
{"reset", CmdReset, IfPm3Present, "Reset the Proxmark3"},
|
{"reset", CmdReset, IfPm3Present, "Reset the Proxmark3"},
|
||||||
{"setlfdivisor", CmdSetDivisor, IfPm3Present, "<19 - 255> -- Drive LF antenna at 12MHz/(divisor+1)"},
|
{"setlfdivisor", CmdSetDivisor, IfPm3Present, "Drive LF antenna at 12MHz / (divisor + 1)"},
|
||||||
{"setmux", CmdSetMux, IfPm3Present, "Set the ADC mux to a specific value"},
|
{"setmux", CmdSetMux, IfPm3Present, "Set the ADC mux to a specific value"},
|
||||||
{"standalone", CmdStandalone, IfPm3Present, "Jump to the standalone mode"},
|
{"standalone", CmdStandalone, IfPm3Present, "Jump to the standalone mode"},
|
||||||
{"status", CmdStatus, IfPm3Present, "Show runtime status information about the connected Proxmark3"},
|
{"status", CmdStatus, IfPm3Present, "Show runtime status information about the connected Proxmark3"},
|
||||||
|
|
|
@ -103,15 +103,7 @@ hf mf gen3blk
|
||||||
hf mf gen3freeze
|
hf mf gen3freeze
|
||||||
hf mf ice
|
hf mf ice
|
||||||
hf mfdes getuid
|
hf mfdes getuid
|
||||||
hw connect
|
|
||||||
hw ping
|
|
||||||
hw setlfdivisor
|
hw setlfdivisor
|
||||||
hw setmux
|
|
||||||
hw standalone
|
|
||||||
hw status
|
|
||||||
hw tia
|
|
||||||
hw tune
|
|
||||||
hw version
|
|
||||||
lf config
|
lf config
|
||||||
lf cmdread
|
lf cmdread
|
||||||
lf read
|
lf read
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue