From 6a2f2b3979c3bc09855f771e76d7b788c30d1ff7 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 21 Aug 2021 20:21:08 +0200 Subject: [PATCH] rename global conn --- client/android/pm3_main.c | 6 ++-- client/src/cmdflashmem.c | 8 +++--- client/src/cmdflashmemspiffs.c | 4 +-- client/src/cmdhfcryptorf.c | 2 +- client/src/cmdhfepa.c | 4 +-- client/src/cmdhficlass.c | 8 +++--- client/src/cmdhfjooki.c | 4 +-- client/src/cmdhflegic.c | 12 ++++---- client/src/cmdhfmf.c | 28 +++++++++--------- client/src/cmdhw.c | 4 +-- client/src/cmdlf.c | 4 +-- client/src/cmdlfem4x05.c | 4 +-- client/src/cmdlfem4x50.c | 4 +-- client/src/cmdlft55xx.c | 4 +-- client/src/cmdparser.c | 4 +-- client/src/comms.c | 52 +++++++++++++++++----------------- client/src/comms.h | 4 +-- client/src/pm3.c | 2 +- client/src/proxguiqt.cpp | 4 +-- client/src/proxmark3.c | 2 +- client/src/scripting.c | 2 +- client/src/uart/uart_posix.c | 4 +-- client/src/uart/uart_win32.c | 4 +-- 23 files changed, 87 insertions(+), 87 deletions(-) diff --git a/client/android/pm3_main.c b/client/android/pm3_main.c index 1b40603c7..7c78df203 100644 --- a/client/android/pm3_main.c +++ b/client/android/pm3_main.c @@ -69,7 +69,7 @@ void RepaintPictureWindow(void) {} int push_cmdscriptfile(char *path, bool stayafter) { return PM3_SUCCESS; } static bool OpenPm3(void) { - if (conn.run) { return true; } + if (g_conn.run) { return true; } // Open with LocalSocket. Not a tcp connection! bool ret = OpenProxmark(session.current_device, "socket:"PM3_LOCAL_SOCKET_SERVER, false, 1000, false, 115200); return ret; @@ -80,7 +80,7 @@ static bool OpenPm3(void) { * */ jint Console(JNIEnv *env, jobject instance, jstring cmd_) { - if (!conn.run) { + if (!g_conn.run) { if (OpenPm3() && TestProxmark(session.current_device) == PM3_SUCCESS) { LOGD("Connected to device"); PrintAndLogEx(SUCCESS, "Connected to device"); @@ -109,7 +109,7 @@ jint Console(JNIEnv *env, jobject instance, jstring cmd_) { * Is client running! * */ jboolean IsClientRunning(JNIEnv *env, jobject instance) { - return (jboolean)((jboolean) conn.run); + return (jboolean)((jboolean) g_conn.run); } /* diff --git a/client/src/cmdflashmem.c b/client/src/cmdflashmem.c index 649809283..3a3184f2e 100644 --- a/client/src/cmdflashmem.c +++ b/client/src/cmdflashmem.c @@ -273,7 +273,7 @@ static int CmdFlashMemLoad(const char *Cmd) { // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; while (bytes_remaining > 0) { uint32_t bytes_in_packet = MIN(FLASH_MEM_BLOCK_SIZE, bytes_remaining); @@ -293,20 +293,20 @@ static int CmdFlashMemLoad(const char *Cmd) { PacketResponseNG resp; if (WaitForResponseTimeout(CMD_FLASHMEM_WRITE, &resp, 2000) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply."); - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; free(data); return PM3_ETIMEOUT; } if (resp.status != PM3_SUCCESS) { - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; PrintAndLogEx(FAILED, "Flash write fail [offset %u]", bytes_sent); free(data); return PM3_EFLASH; } } - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; free(data); PrintAndLogEx(SUCCESS, "Wrote "_GREEN_("%zu")" bytes to offset "_GREEN_("%u"), datalen, offset); return PM3_SUCCESS; diff --git a/client/src/cmdflashmemspiffs.c b/client/src/cmdflashmemspiffs.c index 04aa7a93f..684165236 100644 --- a/client/src/cmdflashmemspiffs.c +++ b/client/src/cmdflashmemspiffs.c @@ -30,7 +30,7 @@ int flashmem_spiffs_load(char *destfn, uint8_t *data, size_t datalen) { uint32_t bytes_remaining = datalen; // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; while (bytes_remaining > 0) { @@ -73,7 +73,7 @@ out: clearCommandBuffer(); // turn off fast push mode - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; // We want to unmount after these to set things back to normal but more than this // unmouting ensure that SPIFFS CACHES are all flushed so our file is actually written on memory diff --git a/client/src/cmdhfcryptorf.c b/client/src/cmdhfcryptorf.c index 412fc4421..10f43173c 100644 --- a/client/src/cmdhfcryptorf.c +++ b/client/src/cmdhfcryptorf.c @@ -462,7 +462,7 @@ static int CmdHFCryptoRFELoad(const char *Cmd) { uint32_t bytes_in_packet = MIN(PM3_CMD_DATA_SIZE, bytes_remaining); if (bytes_in_packet == bytes_remaining) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } clearCommandBuffer(); SendCommandMIX(CMD_HF_CRYPTORF_EML_MEMSET, bytes_sent, bytes_in_packet, 0, data + bytes_sent, bytes_in_packet); diff --git a/client/src/cmdhfepa.c b/client/src/cmdhfepa.c index 6c7f48141..acc89d4c4 100644 --- a/client/src/cmdhfepa.c +++ b/client/src/cmdhfepa.c @@ -140,7 +140,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) { // transfer the APDUs to the Proxmark uint8_t data[PM3_CMD_DATA_SIZE]; // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; for (int i = 0; i < ARRAYLEN(apdu_lengths); i++) { // transfer the APDU in several parts if necessary @@ -152,7 +152,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) { } if ((i == ARRAYLEN(apdu_lengths) - 1) && (j * sizeof(data) >= apdu_lengths[i] - 1)) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } memcpy(data, // + (j * sizeof(data)), apdus[i] + (j * sizeof(data)), diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 42269f3a9..3740bfba1 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -126,7 +126,7 @@ static void iclass_upload_emul(uint8_t *d, uint16_t n, uint16_t *bytes_sent) { } PACKED; // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; //Send to device *bytes_sent = 0; @@ -136,7 +136,7 @@ static void iclass_upload_emul(uint8_t *d, uint16_t n, uint16_t *bytes_sent) { uint32_t bytes_in_packet = MIN(PM3_CMD_DATA_SIZE - 4, bytes_remaining); if (bytes_in_packet == bytes_remaining) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } clearCommandBuffer(); @@ -3056,7 +3056,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { max_chunk_size = keycount; // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; // keep track of position of found key uint32_t chunk_offset = 0; @@ -3085,7 +3085,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { // last chunk? if (curr_chunk_cnt == keycount - chunk_offset) { // Disable fast mode on last command - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } uint32_t tmp_plen = sizeof(iclass_chk_t) + (4 * curr_chunk_cnt); diff --git a/client/src/cmdhfjooki.c b/client/src/cmdhfjooki.c index a8ab0d9c8..a789fb762 100644 --- a/client/src/cmdhfjooki.c +++ b/client/src/cmdhfjooki.c @@ -519,12 +519,12 @@ static int CmdHF14AJookiSim(const char *Cmd) { PrintAndLogEx(INFO, "." NOLF); // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; uint8_t blockwidth = 4, counter = 0, blockno = 0; while (datalen) { if (datalen == blockwidth) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } if (mfEmlSetMem_xt(data + counter, blockno, 1, blockwidth) != PM3_SUCCESS) { diff --git a/client/src/cmdhflegic.c b/client/src/cmdhflegic.c index 3e079cbb4..4e06c3191 100644 --- a/client/src/cmdhflegic.c +++ b/client/src/cmdhflegic.c @@ -717,13 +717,13 @@ void legic_chk_iv(uint32_t *iv) { } void legic_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) { // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; for (size_t i = offset; i < numofbytes; i += PM3_CMD_DATA_SIZE) { size_t len = MIN((numofbytes - i), PM3_CMD_DATA_SIZE); if (len == numofbytes - i) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } clearCommandBuffer(); SendCommandOLD(CMD_HF_LEGIC_ESET, i, len, 0, src + i, len); @@ -913,7 +913,7 @@ static int CmdLegicRestore(const char *Cmd) { PrintAndLogEx(SUCCESS, "Restoring to card"); // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; // transfer to device PacketResponseNG resp; @@ -922,7 +922,7 @@ static int CmdLegicRestore(const char *Cmd) { size_t len = MIN((numofbytes - i), PM3_CMD_DATA_SIZE); if (len == numofbytes - i) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } clearCommandBuffer(); SendCommandOLD(CMD_HF_LEGIC_WRITER, i, len, 0x55, data + i, len); @@ -1129,7 +1129,7 @@ static int CmdLegicWipe(const char *Cmd) { PrintAndLogEx(SUCCESS, "Erasing"); // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; // transfer to device PacketResponseNG resp; @@ -1140,7 +1140,7 @@ static int CmdLegicWipe(const char *Cmd) { size_t len = MIN((card.cardsize - i), PM3_CMD_DATA_SIZE); if (len == card.cardsize - i) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } clearCommandBuffer(); SendCommandOLD(CMD_HF_LEGIC_WRITER, i, len, 0x55, data + i, len); diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index a1a3f6f4e..119cb7700 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -1322,7 +1322,7 @@ jumptoend: // transfer them to the emulator if (transferToEml) { // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; for (int i = 0; i < SectorsCnt; i++) { mfEmlGetMem(keyBlock, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1); @@ -1334,7 +1334,7 @@ jumptoend: if (i == SectorsCnt - 1) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } mfEmlSetMem(keyBlock, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1); } @@ -1568,7 +1568,7 @@ jumptoend: // transfer them to the emulator if (transferToEml) { // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; for (int i = 0; i < SectorsCnt; i++) { mfEmlGetMem(keyBlock, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1); @@ -1580,7 +1580,7 @@ jumptoend: if (i == SectorsCnt - 1) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } mfEmlSetMem(keyBlock, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1); } @@ -2818,7 +2818,7 @@ out: if (transferToEml) { // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; uint8_t block[16] = {0x00}; for (i = 0; i < sectorsCnt; ++i) { uint8_t b = FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1; @@ -2832,7 +2832,7 @@ out: if (i == sectorsCnt - 1) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } mfEmlSetMem(block, b, 1); } @@ -3068,7 +3068,7 @@ static int CmdHF14AMfChk(const char *Cmd) { PrintAndLogEx(INFO, "." NOLF); // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; // clear trace log by first check keys call only bool clearLog = true; @@ -3167,7 +3167,7 @@ out: if (transferToEml) { // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; uint8_t block[16] = {0x00}; for (int i = 0; i < SectorsCnt; ++i) { uint8_t blockno = FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1; @@ -3181,7 +3181,7 @@ out: if (i == SectorsCnt - 1) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } mfEmlSetMem(block, blockno, 1); } @@ -3200,7 +3200,7 @@ out: free(e_sector); // Disable fast mode and send a dummy command to make it effective - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; SendCommandNG(CMD_PING, NULL, 0); if (!WaitForResponseTimeout(CMD_PING, NULL, 1000)) { PrintAndLogEx(WARNING, "command execution time out"); @@ -3817,7 +3817,7 @@ int CmdHF14AMfELoad(const char *Cmd) { PrintAndLogEx(INFO, "." NOLF); // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; size_t offset = 0; int cnt = 0; @@ -3825,7 +3825,7 @@ int CmdHF14AMfELoad(const char *Cmd) { while (datalen && cnt < block_cnt) { if (datalen == block_width) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } if (mfEmlSetMem_xt(data + offset, cnt, 1, block_width) != PM3_SUCCESS) { @@ -4746,11 +4746,11 @@ static int CmdHF14AMfCSave(const char *Cmd) { PrintAndLogEx(INFO, "uploading to emulator memory"); PrintAndLogEx(INFO, "." NOLF); // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; for (int i = 0; i < block_cnt; i += 5) { if (i == block_cnt - 1) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } if (mfEmlSetMem(dump + (i * MFBLOCK_SIZE), i, 5) != PM3_SUCCESS) { PrintAndLogEx(WARNING, "Can't set emul block: %d", i); diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 53c029dd9..f657b46c5 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -836,11 +836,11 @@ static int CmdConnect(const char *Cmd) { // default back to previous used serial port if (strlen(port) == 0) { - if (strlen(conn.serial_port_name) == 0) { + if (strlen(g_conn.serial_port_name) == 0) { PrintAndLogEx(WARNING, "Must specify a serial port"); return PM3_EINVARG; } - memcpy(port, conn.serial_port_name, sizeof(port)); + memcpy(port, g_conn.serial_port_name, sizeof(port)); } if (session.pm3_present) { diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index cda0db6af..f1a27089c 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -790,7 +790,7 @@ int lfsim_upload_gb(void) { payload_up.flag = 0x1; // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; PacketResponseNG resp; @@ -818,7 +818,7 @@ int lfsim_upload_gb(void) { PrintAndLogEx(NORMAL, ""); // Disable fast mode before last command - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; return PM3_SUCCESS; } diff --git a/client/src/cmdlfem4x05.c b/client/src/cmdlfem4x05.c index 5bacccf4c..cecfe9a58 100644 --- a/client/src/cmdlfem4x05.c +++ b/client/src/cmdlfem4x05.c @@ -348,13 +348,13 @@ int em4x05_clone_tag(uint32_t *blockdata, uint8_t numblocks, uint32_t pwd, bool return PM3_EINVARG; // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; int res = 0; for (int8_t i = 0; i < numblocks; i++) { // Disable fast mode on last packet if (i == numblocks - 1) { - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } if (i != 0) { diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index 33c447da0..c2cc15b60 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -178,13 +178,13 @@ static int em4x50_load_file(const char *filename, uint8_t *data, size_t data_len static void em4x50_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) { // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; for (size_t i = offset; i < numofbytes; i += PM3_CMD_DATA_SIZE) { size_t len = MIN((numofbytes - i), PM3_CMD_DATA_SIZE); if (len == numofbytes - i) { // Disable fast mode on last packet - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } clearCommandBuffer(); SendCommandOLD(CMD_LF_EM4X50_ESET, i, len, 0, src + i, len); diff --git a/client/src/cmdlft55xx.c b/client/src/cmdlft55xx.c index d0410d698..ad594096f 100644 --- a/client/src/cmdlft55xx.c +++ b/client/src/cmdlft55xx.c @@ -159,13 +159,13 @@ int clone_t55xx_tag(uint32_t *blockdata, uint8_t numblocks) { PacketResponseNG resp; // fast push mode - conn.block_after_ACK = true; + g_conn.block_after_ACK = true; for (int8_t i = 0; i < numblocks; i++) { // Disable fast mode on last packet if (i == numblocks - 1) { - conn.block_after_ACK = false; + g_conn.block_after_ACK = false; } clearCommandBuffer(); diff --git a/client/src/cmdparser.c b/client/src/cmdparser.c index bcc3da294..2f994167b 100644 --- a/client/src/cmdparser.c +++ b/client/src/cmdparser.c @@ -67,7 +67,7 @@ bool IfPm3FpcUsartHostFromUsb(void) { return false; if (!g_pm3_capabilities.compiled_with_fpc_usart_host) return false; - return !conn.send_via_fpc_usart; + return !g_conn.send_via_fpc_usart; } bool IfPm3FpcUsartDevFromUsb(void) { @@ -76,7 +76,7 @@ bool IfPm3FpcUsartDevFromUsb(void) { return false; if (!g_pm3_capabilities.compiled_with_fpc_usart_dev) return false; - return !conn.send_via_fpc_usart; + return !g_conn.send_via_fpc_usart; } bool IfPm3FpcUsartFromUsb(void) { diff --git a/client/src/comms.c b/client/src/comms.c index b3133c383..f32c609fa 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -29,7 +29,7 @@ // Serial port that we are communicating with the PM3 on. static serial_port sp = NULL; -communication_arg_t conn; +communication_arg_t g_conn; capabilities_t g_pm3_capabilities; static pthread_t communication_thread; @@ -148,7 +148,7 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool if (len > 0 && data) memcpy(&txBufferNG.data, data, len); - if ((conn.send_via_fpc_usart && conn.send_with_crc_on_fpc) || ((!conn.send_via_fpc_usart) && conn.send_with_crc_on_usb)) { + if ((g_conn.send_via_fpc_usart && g_conn.send_with_crc_on_fpc) || ((!g_conn.send_via_fpc_usart) && g_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; @@ -354,7 +354,7 @@ __attribute__((force_align_arg_pointer)) // Signal to main thread that communications seems off. // main thread will kill and restart this thread. if (commfailed) { - if (conn.last_command != CMD_HARDWARE_RESET) { + if (g_conn.last_command != CMD_HARDWARE_RESET) { PrintAndLogEx(WARNING, "\nCommunicating with Proxmark3 device " _RED_("failed")); } __atomic_test_and_set(&comm_thread_dead, __ATOMIC_SEQ_CST); @@ -384,7 +384,7 @@ __attribute__((force_align_arg_pointer)) if (rx.ng) { // Received a valid NG frame memcpy(&rx.data, &rx_raw.data, length); rx.length = length; - if ((rx.cmd == conn.last_command) && (rx.status == PM3_SUCCESS)) { + if ((rx.cmd == g_conn.last_command) && (rx.status == PM3_SUCCESS)) { ACK_received = true; } } else { @@ -504,14 +504,14 @@ __attribute__((force_align_arg_pointer)) if (res == PM3_EIO) { commfailed = true; } - conn.last_command = txBufferNG.pre.cmd; + g_conn.last_command = txBufferNG.pre.cmd; txBufferNGLen = 0; } else { res = uart_send(sp, (uint8_t *) &txBuffer, sizeof(PacketCommandOLD)); if (res == PM3_EIO) { commfailed = true; } - conn.last_command = txBuffer.cmd; + g_conn.last_command = txBuffer.cmd; } txBuffer_pending = false; @@ -574,20 +574,20 @@ bool OpenProxmark(pm3_device **dev, char *port, bool wait_for_port, int timeout, return false; } else { // start the communication thread - if (port != conn.serial_port_name) { + if (port != g_conn.serial_port_name) { uint16_t len = MIN(strlen(port), FILE_PATH_SIZE - 1); - memset(conn.serial_port_name, 0, FILE_PATH_SIZE); - memcpy(conn.serial_port_name, port, len); + memset(g_conn.serial_port_name, 0, FILE_PATH_SIZE); + memcpy(g_conn.serial_port_name, port, len); } - conn.run = true; - conn.block_after_ACK = flash_mode; + g_conn.run = true; + g_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; + g_conn.send_with_crc_on_usb = false; + g_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_usart = false; + g_conn.send_via_fpc_usart = false; - pthread_create(&communication_thread, NULL, &uart_communication, &conn); + pthread_create(&communication_thread, NULL, &uart_communication, &g_conn); __atomic_clear(&comm_thread_dead, __ATOMIC_SEQ_CST); session.pm3_present = true; // TODO support for multiple devices @@ -595,7 +595,7 @@ bool OpenProxmark(pm3_device **dev, char *port, bool wait_for_port, int timeout, if (*dev == NULL) { *dev = calloc(sizeof(pm3_device), sizeof(uint8_t)); } - (*dev)->conn = &conn; // TODO conn shouldn't be global + (*dev)->g_conn = &g_conn; // TODO g_conn shouldn't be global return true; } } @@ -645,16 +645,16 @@ int TestProxmark(pm3_device *dev) { } memcpy(&g_pm3_capabilities, resp.data.asBytes, MIN(sizeof(capabilities_t), resp.length)); - conn.send_via_fpc_usart = g_pm3_capabilities.via_fpc; - conn.uart_speed = g_pm3_capabilities.baudrate; + g_conn.send_via_fpc_usart = g_pm3_capabilities.via_fpc; + g_conn.uart_speed = g_pm3_capabilities.baudrate; PrintAndLogEx(INFO, "Communicating with PM3 over %s%s%s", - conn.send_via_fpc_usart ? _YELLOW_("FPC UART") : _YELLOW_("USB-CDC"), - memcmp(conn.serial_port_name, "tcp:", 4) == 0 ? " over " _YELLOW_("TCP") : "", - memcmp(conn.serial_port_name, "bt:", 3) == 0 ? " over " _YELLOW_("BT") : ""); + g_conn.send_via_fpc_usart ? _YELLOW_("FPC UART") : _YELLOW_("USB-CDC"), + memcmp(g_conn.serial_port_name, "tcp:", 4) == 0 ? " over " _YELLOW_("TCP") : "", + memcmp(g_conn.serial_port_name, "bt:", 3) == 0 ? " over " _YELLOW_("BT") : ""); - if (conn.send_via_fpc_usart) { - PrintAndLogEx(INFO, "PM3 UART serial baudrate: " _YELLOW_("%u") "\n", conn.uart_speed); + if (g_conn.send_via_fpc_usart) { + PrintAndLogEx(INFO, "PM3 UART serial baudrate: " _YELLOW_("%u") "\n", g_conn.uart_speed); } else { int res = uart_reconfigure_timeouts(UART_USB_CLIENT_RX_TIMEOUT_MS); if (res != PM3_SUCCESS) { @@ -665,7 +665,7 @@ int TestProxmark(pm3_device *dev) { } void CloseProxmark(pm3_device *dev) { - dev->conn->run = false; + dev->g_conn->run = false; #ifdef __BIONIC__ if (communication_thread != 0) { @@ -702,8 +702,8 @@ void CloseProxmark(pm3_device *dev) { // ~ = 12000000 / USART_BAUD_RATE // Let's take 2x (maybe we need more for BT link?) static size_t communication_delay(void) { - if (conn.send_via_fpc_usart) // needed also for Windows USB USART?? - return 2 * (12000000 / conn.uart_speed); + if (g_conn.send_via_fpc_usart) // needed also for Windows USB USART?? + return 2 * (12000000 / g_conn.uart_speed); return 0; } diff --git a/client/src/comms.h b/client/src/comms.h index ce038a2e2..cbdfb08df 100644 --- a/client/src/comms.h +++ b/client/src/comms.h @@ -61,11 +61,11 @@ typedef struct { char serial_port_name[FILE_PATH_SIZE]; } communication_arg_t; -extern communication_arg_t conn; +extern communication_arg_t g_conn; typedef struct pm3_device pm3_device; struct pm3_device { - communication_arg_t *conn; + communication_arg_t *g_conn; int script_embedded; }; diff --git a/client/src/pm3.c b/client/src/pm3.c index a4c9518c3..3bf33e1a6 100644 --- a/client/src/pm3.c +++ b/client/src/pm3.c @@ -47,7 +47,7 @@ int pm3_console(pm3_device *dev, char *Cmd) { } const char *pm3_name_get(pm3_device *dev) { - return dev->conn->serial_port_name; + return dev->g_conn->serial_port_name; } pm3_device *pm3_get_current_dev(void) { diff --git a/client/src/proxguiqt.cpp b/client/src/proxguiqt.cpp index ff074a27e..7fc37452b 100644 --- a/client/src/proxguiqt.cpp +++ b/client/src/proxguiqt.cpp @@ -366,7 +366,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) { setLayout(layout); // plot window title - QString pt = QString("[*]Plot [ %1 ]").arg(conn.serial_port_name); + QString pt = QString("[*]Plot [ %1 ]").arg(g_conn.serial_port_name); setWindowTitle(pt); // shows plot window on the screen. @@ -380,7 +380,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) { } // Olverlays / slider window title - QString ct = QString("[*]Slider [ %1 ]").arg(conn.serial_port_name); + QString ct = QString("[*]Slider [ %1 ]").arg(g_conn.serial_port_name); controlWidget->setWindowTitle(ct); // The hide/show event functions should take care of this. diff --git a/client/src/proxmark3.c b/client/src/proxmark3.c index 949caf835..9b26a8929 100644 --- a/client/src/proxmark3.c +++ b/client/src/proxmark3.c @@ -301,7 +301,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { bool printprompt = false; if (session.pm3_present) { - if (conn.send_via_fpc_usart == false) + if (g_conn.send_via_fpc_usart == false) prompt_dev = PROXPROMPT_DEV_USB; else prompt_dev = PROXPROMPT_DEV_FPC; diff --git a/client/src/scripting.c b/client/src/scripting.c index 0184c78a5..95b56e0c8 100644 --- a/client/src/scripting.c +++ b/client/src/scripting.c @@ -71,7 +71,7 @@ static int l_fast_push_mode(lua_State *L) { bool enable = lua_toboolean(L, 1); - conn.block_after_ACK = enable; + g_conn.block_after_ACK = enable; // Disable fast mode and send a dummy command to make it effective if (enable == false) { diff --git a/client/src/uart/uart_posix.c b/client/src/uart/uart_posix.c index 4a41b7958..67bf177b7 100644 --- a/client/src/uart/uart_posix.c +++ b/client/src/uart/uart_posix.c @@ -340,7 +340,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { return INVALID_SERIAL_PORT; } } - conn.uart_speed = uart_get_speed(sp); + g_conn.uart_speed = uart_get_speed(sp); return sp; } @@ -558,7 +558,7 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) { cfsetospeed(&ti, stPortSpeed); bool result = tcsetattr(spu->fd, TCSANOW, &ti) != -1; if (result) - conn.uart_speed = uiPortSpeed; + g_conn.uart_speed = uiPortSpeed; return result; } diff --git a/client/src/uart/uart_win32.c b/client/src/uart/uart_win32.c index 93ee2f126..7a95968ec 100644 --- a/client/src/uart/uart_win32.c +++ b/client/src/uart/uart_win32.c @@ -135,7 +135,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { return INVALID_SERIAL_PORT; } } - conn.uart_speed = uart_get_speed(sp); + g_conn.uart_speed = uart_get_speed(sp); return sp; } @@ -169,7 +169,7 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) { bool result = SetCommState(spw->hPort, &spw->dcb); PurgeComm(spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR); if (result) - conn.uart_speed = uiPortSpeed; + g_conn.uart_speed = uiPortSpeed; return result; }