From cb991b4d2cb9997376c3538bddd028427135c786 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 7 May 2019 17:31:07 +0200 Subject: [PATCH] make sure CloseProxmark sets pm3_present. --- client/cmdhw.c | 9 ++++----- client/comms.c | 2 ++ client/proxmark3.c | 10 +++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index 3334fbfe8..27235c10a 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -515,19 +515,18 @@ static int CmdConnect(const char *Cmd) { port = (char *)Cmd; } - if ( port == NULL ) { + if ( port == NULL ) return usage_hw_connect(); - } - PrintAndLogEx(INFO, "Disconnecting from current serial port"); - CloseProxmark(); + if ( session.pm3_present ) { + CloseProxmark(); + } 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; } return PM3_SUCCESS; } diff --git a/client/comms.c b/client/comms.c index 939df553d..69c932590 100644 --- a/client/comms.c +++ b/client/comms.c @@ -657,6 +657,8 @@ void CloseProxmark(void) { // Clean up our state sp = NULL; memset(&communication_thread, 0, sizeof(pthread_t)); + + session.pm3_present = false; } // Gives a rough estimate of the communication delay based on channel & baudrate diff --git a/client/proxmark3.c b/client/proxmark3.c index 4d185afb2..92cefa60c 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -56,9 +56,9 @@ int check_comm(void) { // If communications thread goes down. Device disconnected then this should hook up PM3 again. if ( IsCommunicationThreadDead() && session.pm3_present) { rl_set_prompt("[offline] "PROXPROMPT); - session.pm3_present = false; - PrintAndLogEx(INFO, "\nRunning in " _YELLOW_("OFFLINE") "mode. Use \"hw connect\" to reconnect\n"); - + rl_forced_update_display (); + CloseProxmark(); + PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") "mode. Use \"hw connect\" to reconnect\n"); } return 0; } @@ -487,13 +487,13 @@ int main(int argc, char *argv[]) { set_my_executable_path(); // try to open USB connection to Proxmark - if (port != NULL) + if (port != NULL) { session.pm3_present = OpenProxmark(port, waitCOMPort, 20, false, speed); + } if (session.pm3_present && (TestProxmark() != PM3_SUCCESS)) { PrintAndLogEx(ERR, _RED_("ERROR:") "cannot communicate with the Proxmark\n"); CloseProxmark(); - session.pm3_present = false; } if (!session.pm3_present)