chg: 'hw connect' - make port optional. Reused previous serial port

This commit is contained in:
iceman1001 2019-05-07 11:42:36 +02:00
parent 61d250a7f8
commit fb7445a027
3 changed files with 22 additions and 19 deletions

View file

@ -6,6 +6,7 @@
// the license.
//-----------------------------------------------------------------------------
// Hardware commands
// low-level hardware control
//-----------------------------------------------------------------------------
#include <stdio.h>
@ -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, " <port> 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;
}

View file

@ -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

View file

@ -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);