From fb7445a027776ad08b5ede5f488f5f5dedf3e272 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 7 May 2019 11:42:36 +0200 Subject: [PATCH] chg: 'hw connect' - make port optional. Reused previous serial port --- client/cmdhw.c | 36 +++++++++++++++++------------------- client/comms.c | 4 ++++ client/comms.h | 1 + 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index 01c9cf350..616237063 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -6,6 +6,7 @@ // the license. //----------------------------------------------------------------------------- // Hardware commands +// low-level hardware control //----------------------------------------------------------------------------- #include @@ -19,8 +20,6 @@ #include "cmdmain.h" #include "cmddata.h" -/* low-level hardware control */ - static int CmdHelp(const char *Cmd); static int usage_hw_detectreader(void) { @@ -58,8 +57,7 @@ static int usage_hw_connect(void) { PrintAndLogEx(NORMAL, " serial port to connect to"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hw connect /dev/ttyACM0 -- *nix "); - PrintAndLogEx(NORMAL, " hw connect com3 -- windows"); + PrintAndLogEx(NORMAL, " hw connect "SERIAL_PORT_H); return PM3_SUCCESS; } @@ -507,24 +505,24 @@ static int CmdConnect(const char *Cmd) { char *port = NULL; port = (char *)Cmd; - if (port != NULL) { + // default back to previous used serial port + if (strlen(port) == 0 ) + GetSavedSerialPortName( &port ); - // if we were already connected, disconnect first. - if (session.pm3_present) { - PrintAndLogEx(INFO, "Disconnecting from current serial port"); - CloseProxmark(); - session.pm3_present = false; - } + // if we were already connected, disconnect first. + if (session.pm3_present) { + 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); + // try to open serial port + session.pm3_present = OpenProxmark(port, false, 20, false, USART_BAUD_RATE); - if (session.pm3_present && (TestProxmark() != PM3_SUCCESS)) { - PrintAndLogEx(ERR, _RED_("ERROR:") "cannot communicate with the Proxmark\n"); - CloseProxmark(); - session.pm3_present = false; - } else { - } + if (session.pm3_present && (TestProxmark() != PM3_SUCCESS)) { + PrintAndLogEx(ERR, _RED_("ERROR:") "cannot communicate with the Proxmark\n"); + CloseProxmark(); + session.pm3_present = false; } return PM3_SUCCESS; } diff --git a/client/comms.c b/client/comms.c index dafc24709..c28aef238 100644 --- a/client/comms.c +++ b/client/comms.c @@ -59,6 +59,10 @@ static uint64_t timeout_start_time; static bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketResponseNG *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd); +void GetSavedSerialPortName( char **dest ) { + *dest = serial_port_name; +} + void SendCommand(PacketCommandOLD *c) { #ifdef COMMS_DEBUG diff --git a/client/comms.h b/client/comms.h index 70c0526bf..7eb3345c5 100644 --- a/client/comms.h +++ b/client/comms.h @@ -62,6 +62,7 @@ void SendCommandMIX(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, v void clearCommandBuffer(void); #define FLASHMODE_SPEED 460800 +void GetSavedSerialPortName( char **dest ); bool IsCommunicationThreadDead(void); bool ReConnectProxmark(void); bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed);