textual
[RRG-proxmark3.git] / client / src / comms.h
blobce038a2e294add648c5de8cfeac3fae445e24324
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
3 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
4 //
5 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
6 // at your option, any later version. See the LICENSE.txt file for the text of
7 // the license.
8 //-----------------------------------------------------------------------------
9 // Code for communicating with the Proxmark3 hardware.
10 //-----------------------------------------------------------------------------
12 #ifndef COMMS_H_
13 #define COMMS_H_
15 #include "common.h"
16 #include "pm3_cmd.h" // Packet structs
17 #include "util.h" // FILE_PATH_SIZE
18 #include "iso7816/iso7816core.h" // SetISODEPState
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
24 #ifndef DropField
25 #define DropField() { clearCommandBuffer(); SetISODEPState(ISODEP_INACTIVE); SendCommandNG(CMD_HF_DROPFIELD, NULL, 0); }
26 #endif
28 #ifndef DropFieldEx
29 #define DropFieldEx(x) { \
30 if ( (x) == CC_CONTACTLESS) { \
31 DropField(); \
32 } \
34 #endif
36 //For storing command that are received from the device
37 #ifndef CMD_BUFFER_SIZE
38 #define CMD_BUFFER_SIZE 100
39 #endif
41 typedef enum {
42 BIG_BUF,
43 BIG_BUF_EML,
44 FLASH_MEM,
45 SIM_MEM,
46 SPIFFS,
47 FPGA_MEM,
48 } DeviceMemType_t;
50 typedef struct {
51 bool run; // If TRUE, continue running the uart_communication thread
52 bool block_after_ACK; // if true, block after receiving an ACK package
53 // Flags to tell where to add CRC on sent replies
54 bool send_with_crc_on_usb;
55 bool send_with_crc_on_fpc;
56 // "Session" flag, to tell via which interface next msgs are sent: USB or FPC USART
57 bool send_via_fpc_usart;
58 // To memorise baudrate
59 uint32_t uart_speed;
60 uint16_t last_command;
61 char serial_port_name[FILE_PATH_SIZE];
62 } communication_arg_t;
64 extern communication_arg_t conn;
66 typedef struct pm3_device pm3_device;
67 struct pm3_device {
68 communication_arg_t *conn;
69 int script_embedded;
72 void *uart_receiver(void *targ);
73 void SendCommandBL(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
74 void SendCommandOLD(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
75 void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len);
76 void SendCommandMIX(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
77 void clearCommandBuffer(void);
79 #define FLASHMODE_SPEED 460800
80 bool IsCommunicationThreadDead(void);
81 typedef struct pm3_device pm3_device;
82 bool OpenProxmark(pm3_device **dev, char *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed);
83 int TestProxmark(pm3_device *dev);
84 void CloseProxmark(pm3_device *dev);
86 bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms_timeout, bool show_warning);
87 bool WaitForResponseTimeout(uint32_t cmd, PacketResponseNG *response, size_t ms_timeout);
88 bool WaitForResponse(uint32_t cmd, PacketResponseNG *response);
90 //bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketResponseNG *response, size_t ms_timeout, bool show_warning);
91 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);
93 #ifdef __cplusplus
95 #endif
96 #endif