Merge pull request #2654 from Antiklesys/master
[RRG-proxmark3.git] / client / src / comms.h
blob133474e5e17229e4edca28959f5401a3903677bf
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 // Code for communicating with the Proxmark3 hardware.
17 //-----------------------------------------------------------------------------
19 #ifndef COMMS_H_
20 #define COMMS_H_
22 #include "common.h"
23 #include "pm3_cmd.h" // Packet structs
24 #include "util.h" // FILE_PATH_SIZE
25 #include "iso7816/iso7816core.h" // SetISODEPState
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
31 #ifndef DropField
32 #define DropField() { clearCommandBuffer(); SetISODEPState(ISODEP_INACTIVE); SendCommandNG(CMD_HF_DROPFIELD, NULL, 0); }
33 #endif
35 #ifndef DropFieldEx
36 #define DropFieldEx(x) { \
37 if ( (x) == CC_CONTACTLESS) { \
38 DropField(); \
39 } \
41 #endif
43 //For storing command that are received from the device
44 #ifndef CMD_BUFFER_SIZE
45 #define CMD_BUFFER_SIZE 100
46 #endif
48 #define COMM_RAW_RECEIVE_LEN (1024)
50 typedef enum {
51 BIG_BUF,
52 BIG_BUF_EML,
53 FLASH_MEM,
54 SIM_MEM,
55 SPIFFS,
56 FPGA_MEM,
57 MCU_FLASH,
58 MCU_MEM,
59 } DeviceMemType_t;
61 typedef enum {
62 PM3_TCPv4,
63 PM3_TCPv6,
64 PM3_UDPv4,
65 PM3_UDPv6,
66 PM3_NONE,
67 } CommunicationProtocol_t;
69 typedef struct {
70 bool run; // If TRUE, continue running the uart_communication thread
71 bool block_after_ACK; // if true, block after receiving an ACK package
72 // Flags to tell where to add CRC on sent replies
73 bool send_with_crc_on_usb;
74 bool send_with_crc_on_fpc;
75 // "Session" flag, to tell via which interface next msgs are sent: USB or FPC USART
76 bool send_via_fpc_usart;
77 // to tell if we are using TCP/UDP/TCP(IPv6)/UDP(IPv6)
78 CommunicationProtocol_t send_via_ip;
79 // to tell if the target address is local address(127.0.0.1/localhost/::1)
80 bool send_via_local_ip;
81 // To memorise baudrate
82 uint32_t uart_speed;
83 uint16_t last_command;
84 char serial_port_name[FILE_PATH_SIZE];
85 } communication_arg_t;
87 extern communication_arg_t g_conn;
89 typedef struct pm3_device {
90 communication_arg_t *g_conn;
91 int script_embedded;
92 } pm3_device_t;
95 void *uart_reconnect(void *targ);
97 void *uart_receiver(void *targ);
98 void SendCommandBL(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
99 void SendCommandOLD(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len);
100 void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len);
101 void SendCommandMIX(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len);
102 void clearCommandBuffer(void);
104 #define FLASHMODE_SPEED 460800
106 bool IsReconnectedOk(void);
107 bool IsCommunicationThreadDead(void);
108 bool SetCommunicationReceiveMode(bool isRawMode);
109 void SetCommunicationRawReceiveBuffer(uint8_t *buffer, size_t len);
110 size_t GetCommunicationRawReceiveNum(void);
112 bool OpenProxmarkSilent(pm3_device_t **dev, const char *port, uint32_t speed);
113 bool OpenProxmark(pm3_device_t **dev, const char *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed);
114 int TestProxmark(pm3_device_t *dev);
115 void CloseProxmark(pm3_device_t *dev);
116 void StartReconnectProxmark(void);
118 size_t WaitForRawDataTimeout(uint8_t *buffer, size_t len, size_t ms_timeout, bool show_process);
119 bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms_timeout, bool show_warning);
120 bool WaitForResponseTimeout(uint32_t cmd, PacketResponseNG *response, size_t ms_timeout);
121 bool WaitForResponse(uint32_t cmd, PacketResponseNG *response);
123 //bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketResponseNG *response, size_t ms_timeout, bool show_warning);
124 bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint32_t start_index, uint8_t *data, uint32_t datalen, PacketResponseNG *response, size_t ms_timeout, bool show_warning);
126 #ifdef __cplusplus
128 #endif
129 #endif