From 3b6a249646d64446b24d383da8139d7ae03e47fd Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 26 Apr 2019 23:16:24 +0200 Subject: [PATCH] move global connection flags to cnn struct --- client/comms.c | 19 ++++++++++--------- client/comms.h | 10 +++++----- doc/new_frame_format.txt | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/client/comms.c b/client/comms.c index 4ae05fc82..7c349c908 100644 --- a/client/comms.c +++ b/client/comms.c @@ -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; } diff --git a/client/comms.h b/client/comms.h index b3be16b1a..8ddbcd271 100644 --- a/client/comms.h +++ b/client/comms.h @@ -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); diff --git a/doc/new_frame_format.txt b/doc/new_frame_format.txt index c42591f62..e6e3e0f69 100644 --- a/doc/new_frame_format.txt +++ b/doc/new_frame_format.txt @@ -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; }