make sure CloseProxmark sets pm3_present.

This commit is contained in:
iceman1001 2019-05-07 17:31:07 +02:00
commit cb991b4d2c
3 changed files with 11 additions and 10 deletions

View file

@ -515,19 +515,18 @@ static int CmdConnect(const char *Cmd) {
port = (char *)Cmd; port = (char *)Cmd;
} }
if ( port == NULL ) { if ( port == NULL )
return usage_hw_connect(); return usage_hw_connect();
}
PrintAndLogEx(INFO, "Disconnecting from current serial port"); if ( session.pm3_present ) {
CloseProxmark(); CloseProxmark();
}
session.pm3_present = OpenProxmark(port, false, 20, false, USART_BAUD_RATE); session.pm3_present = OpenProxmark(port, false, 20, false, USART_BAUD_RATE);
if (session.pm3_present && (TestProxmark() != PM3_SUCCESS)) { if (session.pm3_present && (TestProxmark() != PM3_SUCCESS)) {
PrintAndLogEx(ERR, _RED_("ERROR:") "cannot communicate with the Proxmark\n"); PrintAndLogEx(ERR, _RED_("ERROR:") "cannot communicate with the Proxmark\n");
CloseProxmark(); CloseProxmark();
session.pm3_present = false;
} }
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -657,6 +657,8 @@ void CloseProxmark(void) {
// Clean up our state // Clean up our state
sp = NULL; sp = NULL;
memset(&communication_thread, 0, sizeof(pthread_t)); memset(&communication_thread, 0, sizeof(pthread_t));
session.pm3_present = false;
} }
// Gives a rough estimate of the communication delay based on channel & baudrate // Gives a rough estimate of the communication delay based on channel & baudrate

View file

@ -56,9 +56,9 @@ int check_comm(void) {
// If communications thread goes down. Device disconnected then this should hook up PM3 again. // If communications thread goes down. Device disconnected then this should hook up PM3 again.
if ( IsCommunicationThreadDead() && session.pm3_present) { if ( IsCommunicationThreadDead() && session.pm3_present) {
rl_set_prompt("[offline] "PROXPROMPT); rl_set_prompt("[offline] "PROXPROMPT);
session.pm3_present = false; rl_forced_update_display ();
PrintAndLogEx(INFO, "\nRunning in " _YELLOW_("OFFLINE") "mode. Use \"hw connect\" to reconnect\n"); CloseProxmark();
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") "mode. Use \"hw connect\" to reconnect\n");
} }
return 0; return 0;
} }
@ -487,13 +487,13 @@ int main(int argc, char *argv[]) {
set_my_executable_path(); set_my_executable_path();
// try to open USB connection to Proxmark // try to open USB connection to Proxmark
if (port != NULL) if (port != NULL) {
session.pm3_present = OpenProxmark(port, waitCOMPort, 20, false, speed); session.pm3_present = OpenProxmark(port, waitCOMPort, 20, false, speed);
}
if (session.pm3_present && (TestProxmark() != PM3_SUCCESS)) { if (session.pm3_present && (TestProxmark() != PM3_SUCCESS)) {
PrintAndLogEx(ERR, _RED_("ERROR:") "cannot communicate with the Proxmark\n"); PrintAndLogEx(ERR, _RED_("ERROR:") "cannot communicate with the Proxmark\n");
CloseProxmark(); CloseProxmark();
session.pm3_present = false;
} }
if (!session.pm3_present) if (!session.pm3_present)