chg: save serial port name as copy.

This commit is contained in:
iceman1001 2019-05-07 15:40:01 +02:00
commit f2a954b422
3 changed files with 29 additions and 27 deletions

View file

@ -503,22 +503,29 @@ static int CmdConnect(const char *Cmd) {
return usage_hw_connect(); return usage_hw_connect();
char *port = NULL; char *port = NULL;
port = (char *)Cmd; bool shall_free = false;
// default back to previous used serial port // default back to previous used serial port
if (strlen(port) == 0 ) if (strlen(Cmd) == 0 ) {
GetSavedSerialPortName( &port ); 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 ) { if ( port == NULL ) {
return usage_hw_connect(); return usage_hw_connect();
} }
// if we were already connected, disconnect first. // always disconnect first.
//if (session.pm3_present) { PrintAndLogEx(INFO, "Disconnecting from current serial port");
PrintAndLogEx(INFO, "Disconnecting from current serial port"); CloseProxmark();
CloseProxmark(); session.pm3_present = false;
session.pm3_present = false;
//}
// try to open serial port // try to open serial port
session.pm3_present = OpenProxmark(port, false, 20, false, USART_BAUD_RATE); session.pm3_present = OpenProxmark(port, false, 20, false, USART_BAUD_RATE);
@ -528,6 +535,10 @@ static int CmdConnect(const char *Cmd) {
CloseProxmark(); CloseProxmark();
session.pm3_present = false; session.pm3_present = false;
} }
if ( shall_free )
free(port);
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -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); 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) { void SendCommand(PacketCommandOLD *c) {
#ifdef COMMS_DEBUG #ifdef COMMS_DEBUG
@ -560,7 +556,9 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode,
return false; return false;
} else { } else {
// start the communication thread // 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.run = true;
conn.block_after_ACK = flash_mode; conn.block_after_ACK = flash_mode;
// Flags to tell where to add CRC on sent replies // Flags to tell where to add CRC on sent replies
@ -655,12 +653,6 @@ void CloseProxmark(void) {
uart_close(sp); 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 // Clean up our state
sp = NULL; sp = NULL;
memset(&communication_thread, 0, sizeof(pthread_t)); 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) { switch (memtype) {
case BIG_BUF: { 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); return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_BIGBUF);
} }
case BIG_BUF_EML: { 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); return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF);
} }
case FLASH_MEM: { 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); return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_FLASHMEM_DOWNLOADED);
} }
case SIM_MEM: { 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 dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_SIMMEM);
return false; return false;
} }

View file

@ -50,7 +50,7 @@ typedef struct {
// To memorise baudrate // To memorise baudrate
uint32_t uart_speed; uint32_t uart_speed;
uint16_t last_command; uint16_t last_command;
uint8_t *serial_port_name; uint8_t serial_port_name[FILE_PATH_SIZE];
} communication_arg_t; } communication_arg_t;
extern communication_arg_t conn; 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); void clearCommandBuffer(void);
#define FLASHMODE_SPEED 460800 #define FLASHMODE_SPEED 460800
void GetSavedSerialPortName( char **dest );
bool IsCommunicationThreadDead(void); bool IsCommunicationThreadDead(void);
bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed); bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed);
int TestProxmark(void); int TestProxmark(void);