mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-27 09:37:15 +08:00
chg: save serial port name as copy.
This commit is contained in:
parent
43db2a50e2
commit
f2a954b422
3 changed files with 29 additions and 27 deletions
|
@ -503,22 +503,29 @@ static int CmdConnect(const char *Cmd) {
|
|||
return usage_hw_connect();
|
||||
|
||||
char *port = NULL;
|
||||
port = (char *)Cmd;
|
||||
|
||||
bool shall_free = false;
|
||||
|
||||
// default back to previous used serial port
|
||||
if (strlen(port) == 0 )
|
||||
GetSavedSerialPortName( &port );
|
||||
if (strlen(Cmd) == 0 ) {
|
||||
int len = strlen((char *)conn.serial_port_name);
|
||||
if ( len == 0 ) {
|
||||
return usage_hw_connect();
|
||||
}
|
||||
port = calloc(len + 1, sizeof(uint8_t));
|
||||
memcpy(port, conn.serial_port_name, len);
|
||||
shall_free = true;
|
||||
} else {
|
||||
port = (char *)Cmd;
|
||||
}
|
||||
|
||||
if ( port == NULL ) {
|
||||
return usage_hw_connect();
|
||||
}
|
||||
|
||||
// if we were already connected, disconnect first.
|
||||
//if (session.pm3_present) {
|
||||
PrintAndLogEx(INFO, "Disconnecting from current serial port");
|
||||
CloseProxmark();
|
||||
session.pm3_present = false;
|
||||
//}
|
||||
// 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);
|
||||
|
@ -528,6 +535,10 @@ static int CmdConnect(const char *Cmd) {
|
|||
CloseProxmark();
|
||||
session.pm3_present = false;
|
||||
}
|
||||
|
||||
if ( shall_free )
|
||||
free(port);
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,10 +57,6 @@ 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 = conn.serial_port_name;
|
||||
}
|
||||
|
||||
void SendCommand(PacketCommandOLD *c) {
|
||||
|
||||
#ifdef COMMS_DEBUG
|
||||
|
@ -560,7 +556,9 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode,
|
|||
return false;
|
||||
} else {
|
||||
// start the communication thread
|
||||
conn.serial_port_name = portname;
|
||||
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
|
||||
|
@ -655,12 +653,6 @@ void CloseProxmark(void) {
|
|||
uart_close(sp);
|
||||
}
|
||||
|
||||
#if defined(__linux__) && !defined(NO_UNLINK)
|
||||
// Fix for linux, it seems that it is extremely slow to release the serial port file descriptor /dev/*
|
||||
//
|
||||
// This may be disabled at compile-time with -DNO_UNLINK (used for a JNI-based serial port on Android).
|
||||
#endif
|
||||
|
||||
// Clean up our state
|
||||
sp = NULL;
|
||||
memset(&communication_thread, 0, sizeof(pthread_t));
|
||||
|
@ -763,19 +755,19 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3
|
|||
|
||||
switch (memtype) {
|
||||
case BIG_BUF: {
|
||||
SendCommandOLD(CMD_DOWNLOAD_BIGBUF, start_index, bytes, 0, NULL, 0);
|
||||
SendCommandMIX(CMD_DOWNLOAD_BIGBUF, start_index, bytes, 0, NULL, 0);
|
||||
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_BIGBUF);
|
||||
}
|
||||
case BIG_BUF_EML: {
|
||||
SendCommandOLD(CMD_DOWNLOAD_EML_BIGBUF, start_index, bytes, 0, NULL, 0);
|
||||
SendCommandMIX(CMD_DOWNLOAD_EML_BIGBUF, start_index, bytes, 0, NULL, 0);
|
||||
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF);
|
||||
}
|
||||
case FLASH_MEM: {
|
||||
SendCommandOLD(CMD_FLASHMEM_DOWNLOAD, start_index, bytes, 0, NULL, 0);
|
||||
SendCommandMIX(CMD_FLASHMEM_DOWNLOAD, start_index, bytes, 0, NULL, 0);
|
||||
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_FLASHMEM_DOWNLOADED);
|
||||
}
|
||||
case SIM_MEM: {
|
||||
//SendCommandOLD(CMD_DOWNLOAD_SIM_MEM, start_index, bytes, 0, NULL, 0);
|
||||
//SendCommandMIX(CMD_DOWNLOAD_SIM_MEM, start_index, bytes, 0, NULL, 0);
|
||||
//return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_SIMMEM);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ typedef struct {
|
|||
// To memorise baudrate
|
||||
uint32_t uart_speed;
|
||||
uint16_t last_command;
|
||||
uint8_t *serial_port_name;
|
||||
uint8_t serial_port_name[FILE_PATH_SIZE];
|
||||
} communication_arg_t;
|
||||
|
||||
extern communication_arg_t conn;
|
||||
|
@ -63,7 +63,6 @@ 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 OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed);
|
||||
int TestProxmark(void);
|
||||
|
|
Loading…
Reference in a new issue