1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
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.
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 //-----------------------------------------------------------------------------
23 #include "pm3_cmd.h" // Packet structs
24 #include "util.h" // FILE_PATH_SIZE
25 #include "iso7816/iso7816core.h" // SetISODEPState
32 #define DropField() { clearCommandBuffer(); SetISODEPState(ISODEP_INACTIVE); SendCommandNG(CMD_HF_DROPFIELD, NULL, 0); }
36 #define DropFieldEx(x) { \
37 if ( (x) == CC_CONTACTLESS) { \
43 //For storing command that are received from the device
44 #ifndef CMD_BUFFER_SIZE
45 #define CMD_BUFFER_SIZE 100
48 #define COMM_RAW_RECEIVE_LEN (1024)
67 } CommunicationProtocol_t
;
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
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
;
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
);