move global connection flags to cnn struct

This commit is contained in:
Philippe Teuwen 2019-04-26 23:16:24 +02:00
parent 01b31c742b
commit 3b6a249646
3 changed files with 16 additions and 15 deletions

View file

@ -18,11 +18,6 @@ static char *serial_port_name = NULL;
// If TRUE, then there is no active connection to the PM3, and we will drop commands sent.
static bool offline;
// Flags to tell where to add CRC on sent replies
bool send_with_crc_on_usb = false;
bool send_with_crc_on_fpc = true;
// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART
bool send_via_fpc = false;
communication_arg_t conn;
@ -142,7 +137,7 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool
txBufferNG.pre.cmd = cmd;
memcpy(&txBufferNG.data, data, len);
if ((send_via_fpc && send_with_crc_on_fpc) || ((!send_via_fpc) && send_with_crc_on_usb)) {
if ((conn.send_via_fpc && conn.send_with_crc_on_fpc) || ((!conn.send_via_fpc) && conn.send_with_crc_on_usb)) {
uint8_t first, second;
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(PacketCommandNGPreamble) + len, &first, &second);
tx_post->crc = (first << 8) + second;
@ -553,6 +548,12 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode,
serial_port_name = portname;
conn.run = true;
conn.block_after_ACK = flash_mode;
// Flags to tell where to add CRC on sent replies
conn.send_with_crc_on_usb = false;
conn.send_with_crc_on_fpc = true;
// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART
conn.send_via_fpc = false;
pthread_create(&USB_communication_thread, NULL, &uart_communication, &conn);
//pthread_create(&FPC_communication_thread, NULL, &uart_communication, &conn);
fflush(stdout);
@ -568,8 +569,8 @@ int TestProxmark(void) {
PacketResponseNG resp;
SendCommandOLD(CMD_PING, 0, 0, 0, NULL, 0);
if (WaitForResponseTimeout(CMD_ACK, &resp, 5000)) {
send_via_fpc = resp.oldarg[0] == 1;
PrintAndLogEx(INFO, "Communicating with PM3 over %s.", send_via_fpc ? "FPC" : "USB");
conn.send_via_fpc = resp.oldarg[0] == 1;
PrintAndLogEx(INFO, "Communicating with PM3 over %s.", conn.send_via_fpc ? "FPC" : "USB");
return 1;
} else {
return 0;
@ -617,7 +618,7 @@ void CloseProxmark(void) {
// ~ = 12000000 / USART_BAUD_RATE
// Let's take 2x (maybe we need more for BT link?)
static size_t communication_delay(void) {
if (send_via_fpc) // needed also for Windows USB USART??
if (conn.send_via_fpc) // needed also for Windows USB USART??
return 2 * (12000000 / uart_speed);
return 100;
}

View file

@ -42,13 +42,13 @@ typedef enum {
typedef struct {
bool run; // If TRUE, continue running the uart_communication thread
bool block_after_ACK; // if true, block after receiving an ACK package
// Flags to tell where to add CRC on sent replies
bool send_with_crc_on_usb;
bool send_with_crc_on_fpc;
// "Session" flag, to tell via which interface next msgs are sent: USB or FPC USART
bool send_via_fpc;
} communication_arg_t;
// Flags to tell where to add CRC on sent replies
extern bool send_with_crc_on_usb;
extern bool send_with_crc_on_fpc;
// "Session" flag, to tell via which interface next msgs are sent: USB or FPC USART
extern bool send_via_fpc;
extern communication_arg_t conn;
void SetOffline(bool value);

View file

@ -293,7 +293,7 @@ Empirically measured delay (FTDI cable) with "hw pingng 512" :
9600 -> 1100..1150ms
(client/comms.c)
static size_t communication_delay(void) {
if (send_via_fpc) // needed also for Windows USB USART??
if (conn.send_via_fpc) // needed also for Windows USB USART??
return 2 * (12000000 / uart_speed);
return 100;
}