From bf1c94092dfee7d8b743f386befa5d5d2d19b85c Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 13 Dec 2017 22:21:13 +0100 Subject: [PATCH] Also set the serial port as blocking --- client/flasher.c | 2 +- client/proxmark3.c | 2 +- uart/uart.h | 4 ++++ uart/uart_posix.c | 7 +++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/client/flasher.c b/client/flasher.c index f257d99..acaa56b 100644 --- a/client/flasher.c +++ b/client/flasher.c @@ -72,7 +72,7 @@ void CloseProxmark() { int OpenProxmark(size_t i) { sp = uart_open(serial_port_name); - if (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT) { + if (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT || sp == NONBLOCKING_SERIAL_PORT) { //poll once a second return 0; } diff --git a/client/proxmark3.c b/client/proxmark3.c index 99ba9fb..417e474 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -362,7 +362,7 @@ int main(int argc, char* argv[]) { msleep(1000); printf("."); fflush(stdout); - } while(++openCount < 20 && (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT)); + } while(++openCount < 20 && (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT || sp == NONBLOCKING_SERIAL_PORT)); printf("\n"); } diff --git a/uart/uart.h b/uart/uart.h index fe75a68..0957ea3 100644 --- a/uart/uart.h +++ b/uart/uart.h @@ -56,6 +56,10 @@ typedef void* serial_port; */ #define CLAIMED_SERIAL_PORT (void*)(~2) +/* Returned by uart_open if the serial port specified is in non-blocking mode. + */ +#define NONBLOCKING_SERIAL_PORT (void*)(~4) + /* Given a user-specified port name, connect to the port and return a structure * used for future references to that port. * diff --git a/uart/uart_posix.c b/uart/uart_posix.c index 45e0d3d..3c1afe2 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -86,6 +86,13 @@ serial_port uart_open(const char* pcPortName) return CLAIMED_SERIAL_PORT; } + int i; + i = fcntl(sp->fd, F_GETFL, 0); + if((i & ~O_NONBLOCK) != i && fcntl(sp->fd, F_SETFL, i & ~O_NONBLOCK) != 0) { + free(sp); + return NONBLOCKING_SERIAL_PORT; + } + // Try to retrieve the old (current) terminal info struct if(tcgetattr(sp->fd,&sp->tiOld) == -1) { uart_close(sp);