mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-09 09:39:16 +08:00
chg: leanient parsing of tcp:/bt:/socket: vars
This commit is contained in:
parent
c05e1d8beb
commit
96f03b4933
1 changed files with 32 additions and 11 deletions
|
@ -93,12 +93,27 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||||
// init timeouts
|
// init timeouts
|
||||||
timeout.tv_usec = UART_FPC_CLIENT_RX_TIMEOUT_MS * 1000;
|
timeout.tv_usec = UART_FPC_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||||
|
|
||||||
if (memcmp(pcPortName, "tcp:", 4) == 0) {
|
char *prefix = strdup(pcPortName);
|
||||||
struct addrinfo *addr = NULL, *rp;
|
if (prefix == NULL) {
|
||||||
char *addrstr = strdup(pcPortName + 4);
|
PrintAndLogEx(ERR, "error: malloc");
|
||||||
|
free(sp);
|
||||||
|
return INVALID_SERIAL_PORT;
|
||||||
|
}
|
||||||
|
str_lower(prefix);
|
||||||
|
|
||||||
|
if (memcmp(prefix, "tcp:", 4) == 0) {
|
||||||
|
free(prefix);
|
||||||
|
|
||||||
|
if (strlen(pcPortName) <= 4) {
|
||||||
|
free(sp);
|
||||||
|
return INVALID_SERIAL_PORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct addrinfo *addr = NULL, *rp;
|
||||||
|
|
||||||
|
char *addrstr = strdup(pcPortName + 4);
|
||||||
if (addrstr == NULL) {
|
if (addrstr == NULL) {
|
||||||
printf("Error: strdup\n");
|
PrintAndLogEx(ERR, "error: malloc");
|
||||||
free(sp);
|
free(sp);
|
||||||
return INVALID_SERIAL_PORT;
|
return INVALID_SERIAL_PORT;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +137,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||||
|
|
||||||
int s = getaddrinfo(addrstr, portstr, &info, &addr);
|
int s = getaddrinfo(addrstr, portstr, &info, &addr);
|
||||||
if (s != 0) {
|
if (s != 0) {
|
||||||
printf("Error: getaddrinfo: %s\n", gai_strerror(s));
|
PrintAndLogEx(ERR, "error: getaddrinfo: %s", gai_strerror(s));
|
||||||
freeaddrinfo(addr);
|
freeaddrinfo(addr);
|
||||||
free(addrstr);
|
free(addrstr);
|
||||||
free(sp);
|
free(sp);
|
||||||
|
@ -143,7 +158,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rp == NULL) { /* No address succeeded */
|
if (rp == NULL) { /* No address succeeded */
|
||||||
printf("Error: Could not connect\n");
|
PrintAndLogEx(ERR, "error: Could not connect");
|
||||||
freeaddrinfo(addr);
|
freeaddrinfo(addr);
|
||||||
free(addrstr);
|
free(addrstr);
|
||||||
free(sp);
|
free(sp);
|
||||||
|
@ -164,16 +179,18 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(pcPortName, "bt:", 3) == 0) {
|
if (memcmp(prefix, "bt:", 3) == 0) {
|
||||||
|
free(prefix);
|
||||||
|
|
||||||
#ifdef HAVE_BLUEZ
|
#ifdef HAVE_BLUEZ
|
||||||
if (strlen(pcPortName) != 20) {
|
if (strlen(pcPortName) != 20) {
|
||||||
free(sp);
|
free(sp);
|
||||||
return INVALID_SERIAL_PORT;
|
return INVALID_SERIAL_PORT;
|
||||||
}
|
}
|
||||||
char *addrstr = strndup(pcPortName + 3, 17);
|
|
||||||
|
|
||||||
|
char *addrstr = strndup(pcPortName + 3, 17);
|
||||||
if (addrstr == NULL) {
|
if (addrstr == NULL) {
|
||||||
printf("Error: malloc\n");
|
PrintAndLogEx(ERR, "error: malloc");
|
||||||
free(sp);
|
free(sp);
|
||||||
return INVALID_SERIAL_PORT;
|
return INVALID_SERIAL_PORT;
|
||||||
}
|
}
|
||||||
|
@ -214,7 +231,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||||
// Is local socket buffer, not a TCP or any net connection!
|
// Is local socket buffer, not a TCP or any net connection!
|
||||||
// so, you can't connect with address like: 127.0.0.1, or any IP
|
// so, you can't connect with address like: 127.0.0.1, or any IP
|
||||||
// see http://man7.org/linux/man-pages/man7/unix.7.html
|
// see http://man7.org/linux/man-pages/man7/unix.7.html
|
||||||
if (memcmp(pcPortName, "socket:", 7) == 0) {
|
if (memcmp(prefix, "socket:", 7) == 0) {
|
||||||
|
free(prefix);
|
||||||
|
|
||||||
if (strlen(pcPortName) <= 7) {
|
if (strlen(pcPortName) <= 7) {
|
||||||
free(sp);
|
free(sp);
|
||||||
return INVALID_SERIAL_PORT;
|
return INVALID_SERIAL_PORT;
|
||||||
|
@ -255,6 +274,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(prefix);
|
||||||
|
|
||||||
sp->fd = open(pcPortName, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
|
sp->fd = open(pcPortName, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
|
||||||
if (sp->fd == -1) {
|
if (sp->fd == -1) {
|
||||||
uart_close(sp);
|
uart_close(sp);
|
||||||
|
@ -311,7 +332,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||||
speed = 115200;
|
speed = 115200;
|
||||||
if (!uart_set_speed(sp, speed)) {
|
if (!uart_set_speed(sp, speed)) {
|
||||||
uart_close(sp);
|
uart_close(sp);
|
||||||
printf("[!] UART error while setting baudrate\n");
|
PrintAndLogEx(ERR, "UART error while setting baudrate");
|
||||||
return INVALID_SERIAL_PORT;
|
return INVALID_SERIAL_PORT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue