Make communication timeout configurable

This commit is contained in:
wh201906 2023-07-05 22:12:11 +08:00
commit b74c5db4f9
No known key found for this signature in database
4 changed files with 57 additions and 2 deletions

View file

@ -33,6 +33,7 @@
#include "pm3_cmd.h"
#include "pmflash.h" // rdv40validation_t
#include "cmdflashmem.h" // get_signature..
#include "uart/uart.h" // configure timeout
static int CmdHelp(const char *Cmd);
@ -924,6 +925,47 @@ static int CmdTia(const char *Cmd) {
return PM3_SUCCESS;
}
static int CmdTimeout(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw timeout",
"Set the communication timeout on the client side",
"hw timeout --> Show current timeout\n"
"hw timeout -t 20 --> Set the timeout to 20ms\n"
"hw timeout -t 500 --> Set the timeout to 500ms\n"
);
void *argtable[] = {
arg_param_begin,
arg_int0("t", "timeout", "<dec>", "timeout in ms"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
int32_t arg = arg_get_int_def(ctx, 1, -1);
CLIParserFree(ctx);
uint32_t oldTimeout = uart_get_timeouts();
// timeout is not given/invalid, just show the current timeout then return
if(arg < 0) {
PrintAndLogEx(INFO, "Current communication timeout: %ums", oldTimeout);
return PM3_SUCCESS;
}
uint32_t newTimeout = arg;
// UART_USB_CLIENT_RX_TIMEOUT_MS is considered as the minimum required timeout.
if (newTimeout < UART_USB_CLIENT_RX_TIMEOUT_MS) {
PrintAndLogEx(WARNING, "Timeout less than %ums might cause errors.", UART_USB_CLIENT_RX_TIMEOUT_MS);
}
else if(newTimeout > 5000) {
PrintAndLogEx(WARNING, "Timeout greater than 5000ms makes the client unresponsive.");
}
uart_reconfigure_timeouts(newTimeout);
PrintAndLogEx(INFO, "Old communication timeout: %ums", oldTimeout);
PrintAndLogEx(INFO, "New communication timeout: %ums", newTimeout);
return PM3_SUCCESS;
}
static int CmdPing(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw ping",
@ -1062,6 +1104,7 @@ static command_t CommandTable[] = {
{"status", CmdStatus, IfPm3Present, "Show runtime status information about the connected Proxmark3"},
{"tearoff", CmdTearoff, IfPm3Present, "Program a tearoff hook for the next command supporting tearoff"},
{"tia", CmdTia, IfPm3Present, "Trigger a Timing Interval Acquisition to re-adjust the RealTimeCounter divider"},
{"timeout", CmdTimeout, AlwaysAvailable, "Set the communication timeout on the client side"},
{"tune", CmdTune, IfPm3Present, "Measure antenna tuning"},
{"version", CmdVersion, AlwaysAvailable, "Show version information about the client and the connected Proxmark3, if any"},
{NULL, NULL, NULL, NULL}

View file

@ -74,8 +74,12 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed);
*/
uint32_t uart_get_speed(const serial_port sp);
/* Reconfigure timeouts
/* Reconfigure timeouts (ms)
*/
int uart_reconfigure_timeouts(uint32_t value);
#endif // _UART_H_
/* Get timeouts (ms)
*/
uint32_t uart_get_timeouts(void);
#endif // _UART_H_

View file

@ -69,6 +69,10 @@ int uart_reconfigure_timeouts(uint32_t value) {
return PM3_SUCCESS;
}
uint32_t uart_get_timeouts(void) {
return newtimeout_value;
}
serial_port uart_open(const char *pcPortName, uint32_t speed) {
serial_port_unix_t_t *sp = calloc(sizeof(serial_port_unix_t_t), sizeof(uint8_t));

View file

@ -54,6 +54,10 @@ int uart_reconfigure_timeouts(uint32_t value) {
return PM3_SUCCESS;
}
uint32_t uart_get_timeouts(void) {
return newtimeout_value;
}
static int uart_reconfigure_timeouts_polling(serial_port sp) {
if (newtimeout_pending == false)
return PM3_SUCCESS;