mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-10 18:24:27 +08:00
FIX: slow reconfigure on mingw of serial port
This commit is contained in:
parent
ed1950a0f5
commit
a49ae2d0ce
3 changed files with 21 additions and 5 deletions
|
@ -49,6 +49,8 @@ static int cmd_tail = 0;
|
||||||
|
|
||||||
// to lock rxBuffer operations from different threads
|
// to lock rxBuffer operations from different threads
|
||||||
static pthread_mutex_t rxBufferMutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t rxBufferMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
// serial port access from different threads
|
||||||
|
static pthread_mutex_t spMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
// Global start time for WaitForResponseTimeout & dl_it, so we can reset timeout when we get packets
|
// Global start time for WaitForResponseTimeout & dl_it, so we can reset timeout when we get packets
|
||||||
// as sending lot of these packets can slow down things wuite a lot on slow links (e.g. hw status or lf read at 9600)
|
// as sending lot of these packets can slow down things wuite a lot on slow links (e.g. hw status or lf read at 9600)
|
||||||
|
@ -352,6 +354,10 @@ __attribute__((force_align_arg_pointer))
|
||||||
rxlen = 0;
|
rxlen = 0;
|
||||||
bool ACK_received = false;
|
bool ACK_received = false;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
|
|
||||||
|
|
||||||
|
pthread_mutex_lock(&spMutex);
|
||||||
|
|
||||||
if (uart_receive(sp, (uint8_t *)&rx_raw.pre, sizeof(PacketResponseNGPreamble), &rxlen) && (rxlen == sizeof(PacketResponseNGPreamble))) {
|
if (uart_receive(sp, (uint8_t *)&rx_raw.pre, sizeof(PacketResponseNGPreamble), &rxlen) && (rxlen == sizeof(PacketResponseNGPreamble))) {
|
||||||
rx.magic = rx_raw.pre.magic;
|
rx.magic = rx_raw.pre.magic;
|
||||||
uint16_t length = rx_raw.pre.length;
|
uint16_t length = rx_raw.pre.length;
|
||||||
|
@ -459,6 +465,9 @@ __attribute__((force_align_arg_pointer))
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&spMutex);
|
||||||
|
|
||||||
// TODO if error, shall we resync ?
|
// TODO if error, shall we resync ?
|
||||||
|
|
||||||
pthread_mutex_lock(&txBufferMutex);
|
pthread_mutex_lock(&txBufferMutex);
|
||||||
|
@ -595,9 +604,17 @@ int TestProxmark(void) {
|
||||||
|
|
||||||
// reconfigure.
|
// reconfigure.
|
||||||
if (conn.send_via_fpc == false) {
|
if (conn.send_via_fpc == false) {
|
||||||
uart_reconfigure_timeouts(sp, UART_USB_CLIENT_RX_TIMEOUT_MS);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
pthread_mutex_lock(&spMutex);
|
||||||
|
int res = uart_reconfigure_timeouts(sp, UART_USB_CLIENT_RX_TIMEOUT_MS);
|
||||||
|
pthread_mutex_unlock(&spMutex);
|
||||||
|
|
||||||
|
if ( res != PM3_SUCCESS ) {
|
||||||
|
PrintAndLogEx(ERR, "UART reconfigure failed");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
|
|
|
@ -496,6 +496,7 @@ int main(int argc, char *argv[]) {
|
||||||
CloseProxmark();
|
CloseProxmark();
|
||||||
session.pm3_present = false;
|
session.pm3_present = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session.pm3_present)
|
if (!session.pm3_present)
|
||||||
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") "mode. Check \"%s -h\" if it's not what you want.\n", exec_name);
|
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") "mode. Check \"%s -h\" if it's not what you want.\n", exec_name);
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,6 @@ typedef struct {
|
||||||
} serial_port_windows;
|
} serial_port_windows;
|
||||||
|
|
||||||
int uart_reconfigure_timeouts(serial_port sp, uint32_t value) {
|
int uart_reconfigure_timeouts(serial_port sp, uint32_t value) {
|
||||||
|
|
||||||
serial_port_windows *spw;
|
serial_port_windows *spw;
|
||||||
spw = (serial_port_windows *)sp;
|
spw = (serial_port_windows *)sp;
|
||||||
spw->ct.ReadIntervalTimeout = value;
|
spw->ct.ReadIntervalTimeout = value;
|
||||||
|
@ -60,7 +59,6 @@ int uart_reconfigure_timeouts(serial_port sp, uint32_t value) {
|
||||||
|
|
||||||
if (!SetCommTimeouts(spw->hPort, &spw->ct)) {
|
if (!SetCommTimeouts(spw->hPort, &spw->ct)) {
|
||||||
uart_close(spw);
|
uart_close(spw);
|
||||||
printf("[!] UART error while setting comm time outs\n");
|
|
||||||
return PM3_EIO;
|
return PM3_EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue