Skip to content

Commit

Permalink
Merge pull request RfidResearchGroup#2225 from wh201906/reconnect
Browse files Browse the repository at this point in the history
Some fixes for the reconnect feature
  • Loading branch information
iceman1001 committed Jan 1, 2024
2 parents d99fbfc + b414081 commit 722b5cc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
8 changes: 5 additions & 3 deletions client/src/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ void *uart_reconnect(void *targ) {
}

while (1) {
// throttle
msleep(200);
if (OpenProxmarkSilent(&g_session.current_device, connection->serial_port_name, speed) == false) {
continue;
}
Expand Down Expand Up @@ -699,7 +701,7 @@ size_t GetCommunicationRawReceiveNum(void) {

bool OpenProxmarkSilent(pm3_device_t **dev, const char *port, uint32_t speed) {

sp = uart_open(port, speed);
sp = uart_open(port, speed, true);

// check result of uart opening
if (sp == INVALID_SERIAL_PORT) {
Expand Down Expand Up @@ -742,14 +744,14 @@ bool OpenProxmark(pm3_device_t **dev, const char *port, bool wait_for_port, int

if (!wait_for_port) {
PrintAndLogEx(INFO, "Using UART port " _YELLOW_("%s"), port);
sp = uart_open(port, speed);
sp = uart_open(port, speed, false);
} else {
PrintAndLogEx(SUCCESS, "Waiting for Proxmark3 to appear on " _YELLOW_("%s"), port);
fflush(stdout);
int openCount = 0;
PrintAndLogEx(INPLACE, "% 3i", timeout);
do {
sp = uart_open(port, speed);
sp = uart_open(port, speed, false);
msleep(500);
PrintAndLogEx(INPLACE, "% 3i", timeout - openCount - 1);

Expand Down
4 changes: 3 additions & 1 deletion client/src/uart/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ typedef void *serial_port;
* used for future references to that port.
*
* On errors, this method returns INVALID_SERIAL_PORT or CLAIMED_SERIAL_PORT.
* If slient is set to false, this function will print the error information
* when error occurs.
*/
serial_port uart_open(const char *pcPortName, uint32_t speed);
serial_port uart_open(const char *pcPortName, uint32_t speed, bool slient);

/* Closes the given port.
*/
Expand Down
12 changes: 8 additions & 4 deletions client/src/uart/uart_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ uint32_t uart_get_timeouts(void) {
return newtimeout_value;
}

serial_port uart_open(const char *pcPortName, uint32_t speed) {
serial_port uart_open(const char *pcPortName, uint32_t speed, bool slient) {
serial_port_unix_t_t *sp = calloc(sizeof(serial_port_unix_t_t), sizeof(uint8_t));

if (sp == 0) {
Expand All @@ -98,7 +98,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {

char *prefix = str_dup(pcPortName);
if (prefix == NULL) {
PrintAndLogEx(ERR, "error: string duplication");
PrintAndLogEx(ERR, "error: string duplication");
free(sp);
return INVALID_SERIAL_PORT;
}
Expand Down Expand Up @@ -235,7 +235,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
free(addrPortStr);

if (rp == NULL) { /* No address succeeded */
PrintAndLogEx(ERR, "error: Could not connect");
if (slient == false) {
PrintAndLogEx(ERR, "error: Could not connect");
}
free(sp);
return INVALID_SERIAL_PORT;
}
Expand Down Expand Up @@ -292,7 +294,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
}

if (connect(sfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
PrintAndLogEx(ERR, "Error: cannot connect device " _YELLOW_("%s") " over Bluetooth", addrstr);
if (slient == false) {
PrintAndLogEx(ERR, "Error: cannot connect device " _YELLOW_("%s") " over Bluetooth", addrstr);
}
close(sfd);
free(addrstr);
free(sp);
Expand Down
8 changes: 5 additions & 3 deletions client/src/uart/uart_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static int uart_reconfigure_timeouts_polling(serial_port sp) {
return PM3_SUCCESS;
}

serial_port uart_open(const char *pcPortName, uint32_t speed) {
serial_port uart_open(const char *pcPortName, uint32_t speed, bool slient) {
char acPortName[255] = {0};
serial_port_windows_t *sp = calloc(sizeof(serial_port_windows_t), sizeof(uint8_t));
sp->hSocket = INVALID_SOCKET; // default: serial port
Expand All @@ -99,7 +99,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {

char *prefix = str_dup(pcPortName);
if (prefix == NULL) {
PrintAndLogEx(ERR, "error: string duplication");
PrintAndLogEx(ERR, "error: string duplication");
free(sp);
return INVALID_SERIAL_PORT;
}
Expand Down Expand Up @@ -241,7 +241,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
free(addrPortStr);

if (rp == NULL) { /* No address succeeded */
PrintAndLogEx(ERR, "error: Could not connect");
if (slient == false) {
PrintAndLogEx(ERR, "error: Could not connect");
}
WSACleanup();
free(sp);
return INVALID_SERIAL_PORT;
Expand Down

0 comments on commit 722b5cc

Please sign in to comment.