From 7eb76855591a4e2d5401789fb7ec17ae3372f552 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 7 May 2019 15:57:22 +0200 Subject: [PATCH] cleaning up, simplify --- client/cmdhw.c | 16 +++------------- client/comms.c | 11 ++++++----- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index 51ab755b8..3334fbfe8 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -503,7 +503,6 @@ static int CmdConnect(const char *Cmd) { return usage_hw_connect(); char *port = NULL; - bool shall_free = false; // default back to previous used serial port if (strlen(Cmd) == 0 ) { @@ -511,9 +510,7 @@ static int CmdConnect(const char *Cmd) { if ( len == 0 ) { return usage_hw_connect(); } - port = calloc(len + 1, sizeof(uint8_t)); - memcpy(port, conn.serial_port_name, len); - shall_free = true; + port = (char *)conn.serial_port_name; } else { port = (char *)Cmd; } @@ -521,13 +518,10 @@ static int CmdConnect(const char *Cmd) { if ( port == NULL ) { return usage_hw_connect(); } - - // always disconnect first. + PrintAndLogEx(INFO, "Disconnecting from current serial port"); CloseProxmark(); - session.pm3_present = false; - - // try to open serial port + session.pm3_present = OpenProxmark(port, false, 20, false, USART_BAUD_RATE); if (session.pm3_present && (TestProxmark() != PM3_SUCCESS)) { @@ -535,10 +529,6 @@ static int CmdConnect(const char *Cmd) { CloseProxmark(); session.pm3_present = false; } - - if ( shall_free ) - free(port); - return PM3_SUCCESS; } diff --git a/client/comms.c b/client/comms.c index 53315c160..939df553d 100644 --- a/client/comms.c +++ b/client/comms.c @@ -556,9 +556,11 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, return false; } else { // start the communication thread - uint16_t len = MIN( strlen(portname), FILE_PATH_SIZE - 1); - memset(conn.serial_port_name, 0, FILE_PATH_SIZE); - memcpy(conn.serial_port_name, portname, len); + if ( portname != (char*)conn.serial_port_name) { + uint16_t len = MIN( strlen(portname), FILE_PATH_SIZE - 1); + memset(conn.serial_port_name, 0, FILE_PATH_SIZE); + memcpy(conn.serial_port_name, portname, len); + } conn.run = true; conn.block_after_ACK = flash_mode; // Flags to tell where to add CRC on sent replies @@ -571,8 +573,7 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, __atomic_clear(&comm_thread_dead, __ATOMIC_SEQ_CST); fflush(stdout); - // create a mutex to avoid interlacing print commands from our different threads - //pthread_mutex_init(&print_lock, NULL); + return true; } }