From e3eb8b74015f39dbeaaab02ab81f8021228cbed5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 31 May 2020 23:09:26 +0200 Subject: [PATCH] char* port for OpenProxmark and remove global gui_serial_port_name --- client/src/cmdhw.c | 2 +- client/src/comms.c | 26 ++++++++++---------------- client/src/comms.h | 6 ++---- client/src/proxguiqt.cpp | 4 ++-- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 45e56ba49..487d5eb2b 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -580,7 +580,7 @@ static int CmdConnect(const char *Cmd) { // default back to previous used serial port if (strlen(port) == 0) { - if (strlen((char *)conn.serial_port_name) == 0) { + if (strlen(conn.serial_port_name) == 0) { return usage_hw_connect(); } memcpy(port, conn.serial_port_name, sizeof(port)); diff --git a/client/src/comms.c b/client/src/comms.c index 0a49e1f31..09e39696c 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -24,8 +24,6 @@ //#define COMMS_DEBUG //#define COMMS_DEBUG_RAW -uint8_t gui_serial_port_name[FILE_PATH_SIZE]; - // Serial port that we are communicating with the PM3 on. static serial_port sp = NULL; @@ -537,19 +535,18 @@ bool IsCommunicationThreadDead(void) { return ret; } -bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed) { +bool OpenProxmark(char *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed) { - char *portname = (char *)port; if (!wait_for_port) { - PrintAndLogEx(INFO, "Using UART port " _YELLOW_("%s"), portname); - sp = uart_open(portname, speed); + PrintAndLogEx(INFO, "Using UART port " _YELLOW_("%s"), port); + sp = uart_open(port, speed); } else { - PrintAndLogEx(SUCCESS, "Waiting for Proxmark3 to appear on " _YELLOW_("%s"), portname); + PrintAndLogEx(SUCCESS, "Waiting for Proxmark3 to appear on " _YELLOW_("%s"), port); fflush(stdout); int openCount = 0; PrintAndLogEx(INPLACE, "% 3i", timeout); do { - sp = uart_open(portname, speed); + sp = uart_open(port, speed); msleep(500); PrintAndLogEx(INPLACE, "% 3i", timeout - openCount - 1); @@ -558,22 +555,19 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, // check result of uart opening if (sp == INVALID_SERIAL_PORT) { - PrintAndLogEx(WARNING, "\n" _RED_("ERROR:") " invalid serial port " _YELLOW_("%s"), portname); + PrintAndLogEx(WARNING, "\n" _RED_("ERROR:") " invalid serial port " _YELLOW_("%s"), port); sp = NULL; return false; } else if (sp == CLAIMED_SERIAL_PORT) { - PrintAndLogEx(WARNING, "\n" _RED_("ERROR:") " serial port " _YELLOW_("%s") " is claimed by another process", portname); + PrintAndLogEx(WARNING, "\n" _RED_("ERROR:") " serial port " _YELLOW_("%s") " is claimed by another process", port); sp = NULL; return false; } else { // start the communication thread - if (portname != (char *)conn.serial_port_name) { - uint16_t len = MIN(strlen(portname), FILE_PATH_SIZE - 1); + if (port != conn.serial_port_name) { + uint16_t len = MIN(strlen(port), FILE_PATH_SIZE - 1); memset(conn.serial_port_name, 0, FILE_PATH_SIZE); - memcpy(conn.serial_port_name, portname, len); - - memset(gui_serial_port_name, 0, FILE_PATH_SIZE); - memcpy(gui_serial_port_name, portname, len); + memcpy(conn.serial_port_name, port, len); } conn.run = true; conn.block_after_ACK = flash_mode; diff --git a/client/src/comms.h b/client/src/comms.h index 42f5580a6..9fcf1b7a6 100644 --- a/client/src/comms.h +++ b/client/src/comms.h @@ -60,13 +60,11 @@ typedef struct { // To memorise baudrate uint32_t uart_speed; uint16_t last_command; - uint8_t serial_port_name[FILE_PATH_SIZE]; + char serial_port_name[FILE_PATH_SIZE]; } communication_arg_t; extern communication_arg_t conn; -extern uint8_t gui_serial_port_name[FILE_PATH_SIZE]; - void *uart_receiver(void *targ); void SendCommandBL(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); void SendCommandOLD(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); @@ -76,7 +74,7 @@ void clearCommandBuffer(void); #define FLASHMODE_SPEED 460800 bool IsCommunicationThreadDead(void); -bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed); +bool OpenProxmark(char *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed); int TestProxmark(void); void CloseProxmark(void); diff --git a/client/src/proxguiqt.cpp b/client/src/proxguiqt.cpp index f3f49b9a0..7374982ea 100644 --- a/client/src/proxguiqt.cpp +++ b/client/src/proxguiqt.cpp @@ -233,7 +233,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) { setLayout(layout); // plot window title - QString pt = QString("[*]Plot [ %1 ]").arg((char *)gui_serial_port_name); + QString pt = QString("[*]Plot [ %1 ]").arg(conn.serial_port_name); setWindowTitle(pt); // shows plot window on the screen. @@ -247,7 +247,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) { } // Olverlays / slider window title - QString ct = QString("[*]Slider [ %1 ]").arg((char *)gui_serial_port_name); + QString ct = QString("[*]Slider [ %1 ]").arg(conn.serial_port_name); controlWidget->setWindowTitle(ct); controlWidget->show();