diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 591b67334..8f65bc892 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -59,6 +59,7 @@ int ToSendMax = -1; static int ToSendBit; struct common_area common_area __attribute__((section(".commonarea"))); int button_status = BUTTON_NO_CLICK; +bool allow_send_wtx = false; void ToSendReset(void) { ToSendMax = -1; @@ -118,6 +119,12 @@ void print_result(char *name, uint8_t *buf, size_t len) { // Debug print functions, to go out over USB, to the usual PC-side client. //============================================================================= +inline void send_wtx(uint16_t wtx) { + if (allow_send_wtx) { + reply_ng(CMD_WTX, PM3_SUCCESS, (uint8_t *)&wtx, sizeof(wtx)); + } +} + void DbpStringEx(uint32_t flags, char *str) { #if DEBUG struct { @@ -1994,6 +2001,7 @@ void __attribute__((noreturn)) AppMain(void) { // against device such as http://www.hobbytronics.co.uk/usb-host-board-v2 usb_disable(); usb_enable(); + allow_send_wtx = true; #ifdef WITH_FLASH // If flash is not present, BUSY_TIMEOUT kicks in, let's do it after USB @@ -2023,7 +2031,9 @@ void __attribute__((noreturn)) AppMain(void) { * So this is the trigger to execute a standalone mod. Generic entrypoint by following the standalone/standalone.h headerfile * All standalone mod "main loop" should be the RunMod() function. */ + allow_send_wtx = false; RunMod(); + allow_send_wtx = true; } } } diff --git a/armsrc/apps.h b/armsrc/apps.h index d3fa44429..7cc401857 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -43,6 +43,7 @@ extern uint8_t trigger; /// appmain.h void ReadMem(int addr); void __attribute__((noreturn)) AppMain(void); +void send_wtx(uint16_t wtx); //void DbpIntegers(int a, int b, int c); void DbpString(char *str); void DbpStringEx(uint32_t flags, char *str); diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index 5b55325d7..b5543a7d2 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -395,6 +395,8 @@ void FpgaDownloadAndGo(int bitstream_version) { if (downloaded_bitstream == bitstream_version) return; + // Send waiting time extension request as this will take a while + send_wtx(1500); z_stream compressed_fpga_stream; uint8_t output_buffer[OUTPUT_BUFFER_LEN] = {0x00}; diff --git a/client/cmdhf.c b/client/cmdhf.c index 4e88f19f6..36c6d2e18 100644 --- a/client/cmdhf.c +++ b/client/cmdhf.c @@ -125,7 +125,7 @@ int CmdHFTune(const char *Cmd) { clearCommandBuffer(); uint8_t mode[] = {1}; SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF, mode, sizeof(mode)); - if (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF, &resp, 2000)) { + if (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF, &resp, 1000)) { PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF initialization, aborting"); return PM3_ETIMEOUT; } @@ -136,7 +136,7 @@ int CmdHFTune(const char *Cmd) { break; } SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF, mode, sizeof(mode)); - if (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF, &resp, 2000)) { + if (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF, &resp, 1000)) { PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF measure, aborting"); return PM3_ETIMEOUT; } @@ -147,7 +147,7 @@ int CmdHFTune(const char *Cmd) { } mode[0] = 3; SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF, mode, sizeof(mode)); - if (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF, &resp, 2000)) { + if (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF, &resp, 1000)) { PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF shutdown, aborting"); return PM3_ETIMEOUT; } diff --git a/client/comms.c b/client/comms.c index 21c469adc..22e5c7fa1 100644 --- a/client/comms.c +++ b/client/comms.c @@ -710,6 +710,12 @@ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms if (cmd == CMD_UNKNOWN || response->cmd == cmd) { return true; } + if (response->cmd == CMD_WTX && response->length == sizeof(uint16_t)) { + uint16_t wtx = response->data.asDwords[0] & 0xFFFF; + PrintAndLogEx(DEBUG, "Got Waiting Time eXtension request %i ms", wtx); + if (ms_timeout != (size_t) - 1) + ms_timeout += wtx; + } } uint64_t tmp_clk = __atomic_load_n(&timeout_start_time, __ATOMIC_SEQ_CST); @@ -824,6 +830,11 @@ static bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketRes bytes_completed += copy_bytes; } else if (response->cmd == CMD_ACK) { return true; + } else if (response->cmd == CMD_WTX && response->length == sizeof(uint16_t)) { + uint16_t wtx = response->data.asDwords[0] & 0xFFFF; + PrintAndLogEx(DEBUG, "Got Waiting Time eXtension request %i ms", wtx); + if (ms_timeout != (size_t) - 1) + ms_timeout += wtx; } } diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 756e216e8..3d7b156bd 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -258,6 +258,7 @@ typedef struct { #define CMD_QUIT_SESSION 0x0113 #define CMD_SET_DBGMODE 0x0114 #define CMD_STANDALONE 0x0115 +#define CMD_WTX 0x0116 // RDV40, Flash memory operations #define CMD_FLASHMEM_WRITE 0x0121