diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bfc7c134..df3601ba1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] - - Fixed timeout of TCP connections (@wh201906) + - Fixed the timeout of TCP connections (@wh201906) + - Made the connection timeout configurable (@wh201906) ## [Seven.4.16717][2023-06-25] - Change `hf 14a info` - now identifes QL88 tags (@iceman1001) diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 3ddd98189..c685b83f2 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -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", "", "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} diff --git a/client/src/uart/uart.h b/client/src/uart/uart.h index ba4537769..ae3896f73 100644 --- a/client/src/uart/uart.h +++ b/client/src/uart/uart.h @@ -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_ diff --git a/client/src/uart/uart_posix.c b/client/src/uart/uart_posix.c index c64d85db6..106c8d209 100644 --- a/client/src/uart/uart_posix.c +++ b/client/src/uart/uart_posix.c @@ -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)); diff --git a/client/src/uart/uart_win32.c b/client/src/uart/uart_win32.c index cb8b92a73..541804a24 100644 --- a/client/src/uart/uart_win32.c +++ b/client/src/uart/uart_win32.c @@ -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;