From 9b8cf1e323b7bf1c9a051c087cccaa184b87854b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 7 Apr 2024 23:50:58 +0200 Subject: [PATCH] the waitforResponseTimeoutW fct will lock the client in situations like sniffing and if the device locks up there is no way to exit nice. This fix will look for life signs from the device. if lost, we will break. Allowing for the client to handle it better --- CHANGELOG.md | 1 + client/src/comms.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06b754349..3efb9f1f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 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] +- Changed waiting for device loops. More stable experience (@iceman1001) - Changed client now handles CTRL-C and saves history if using READLINE (@iceman1001) - Changed `hf mf *` - printing of keys if MFC EV1 added extra explaination (@iceman1001) - Changed `hf mf ginfo - now supports decoding of user supplied configuration block (@iceman1001) diff --git a/client/src/comms.c b/client/src/comms.c index 7471db747..cc506f77d 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -1038,21 +1038,29 @@ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms // Wait until the command is received while (true) { + // if device gets disconnected or resets, break out of this loop + if (IsCommunicationThreadDead()) { + break; + } + while (getReply(response)) { 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) + if (ms_timeout != (size_t) - 1) { ms_timeout += wtx; + } } } uint64_t tmp_clk = __atomic_load_n(&timeout_start_time, __ATOMIC_SEQ_CST); - if ((ms_timeout != (size_t) - 1) && (msclock() - tmp_clk > ms_timeout)) + if ((ms_timeout != (size_t) - 1) && (msclock() - tmp_clk > ms_timeout)) { break; + } if (msclock() - tmp_clk > 3000 && show_warning) { // 3 seconds elapsed (but this doesn't mean the timeout was exceeded)