diff --git a/client/comms.c b/client/comms.c index d6bf91d7c..74ff518de 100644 --- a/client/comms.c +++ b/client/comms.c @@ -623,16 +623,13 @@ int TestProxmark(void) { PrintAndLogEx(INFO, "Communicating with PM3 over %s", conn.send_via_fpc_usart ? _YELLOW_("FPC UART") : _YELLOW_("USB-CDC")); - int res; if (conn.send_via_fpc_usart) { PrintAndLogEx(INFO, "UART Serial baudrate: " _YELLOW_("%u") "\n", conn.uart_speed); - res = uart_reconfigure_timeouts(UART_FPC_CLIENT_RX_TIMEOUT_MS); } else { - res = uart_reconfigure_timeouts(UART_USB_CLIENT_RX_TIMEOUT_MS); - } - - if (res != PM3_SUCCESS) { - return res; + int res = uart_reconfigure_timeouts(UART_USB_CLIENT_RX_TIMEOUT_MS); + if (res != PM3_SUCCESS) { + return res; + } } return PM3_SUCCESS; } diff --git a/uart/uart_posix.c b/uart/uart_posix.c index 52f57a05d..0f8e88c13 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -78,7 +78,7 @@ bool newtimeout_pending = false; int uart_reconfigure_timeouts(uint32_t value) { newtimeout_value = value; - __atomic_test_and_set(&newtimeout_pending, __ATOMIC_SEQ_CST); + newtimeout_pending = true; return PM3_SUCCESS; } @@ -243,6 +243,10 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin fd_set rfds; struct timeval tv; + if ( newtimeout_pending ) { + timeout.tv_usec = newtimeout_value * 1000; + newtimeout_pending = false; + } // Reset the output count *pszRxLen = 0; do { @@ -303,10 +307,6 @@ int uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len) { fd_set rfds; struct timeval tv; - bool shall_update = __atomic_load_n(&newtimeout_pending, __ATOMIC_SEQ_CST); - if ( shall_update ) - timeout.tv_usec = newtimeout_value * 1000; - while (pos < len) { // Reset file descriptor FD_ZERO(&rfds); diff --git a/uart/uart_win32.c b/uart/uart_win32.c index 4f9515dcb..ba1d0de89 100644 --- a/uart/uart_win32.c +++ b/uart/uart_win32.c @@ -49,18 +49,18 @@ typedef struct { } serial_port_windows; uint32_t newtimeout_value = 0; -bool newtimeout_pending = true; +bool newtimeout_pending = false; int uart_reconfigure_timeouts(uint32_t value) { newtimeout_value = value; - __atomic_test_and_set(&newtimeout_pending, __ATOMIC_SEQ_CST); + newtimeout_pending = true; return PM3_SUCCESS; } static int uart_reconfigure_timeouts_polling(serial_port sp) { - bool shall_update = __atomic_load_n(&newtimeout_pending, __ATOMIC_SEQ_CST); - if ( shall_update == false ) + if ( newtimeout_pending == false ) return PM3_SUCCESS; + newtimeout_pending = false; serial_port_windows *spw; spw = (serial_port_windows *)sp; @@ -174,6 +174,7 @@ uint32_t uart_get_speed(const serial_port sp) { } int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen) { + uart_reconfigure_timeouts_polling(sp); int res = ReadFile(((serial_port_windows *)sp)->hPort, pbtRx, pszMaxRxLen, (LPDWORD)pszRxLen, NULL); if (res) return PM3_SUCCESS; @@ -190,7 +191,6 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin } int uart_send(const serial_port sp, const uint8_t *p_tx, const uint32_t len) { - uart_reconfigure_timeouts_polling(sp); DWORD txlen = 0; int res = WriteFile(((serial_port_windows *)sp)->hPort, p_tx, len, &txlen, NULL); if (res)