1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
3 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
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
8 //-----------------------------------------------------------------------------
9 // Code for communicating with the Proxmark3 hardware.
10 //-----------------------------------------------------------------------------
16 #include "pm3_cmd.h" // Packet structs
17 #include "util.h" // FILE_PATH_SIZE
18 #include "iso7816/iso7816core.h" // SetISODEPState
25 #define DropField() { clearCommandBuffer(); SetISODEPState(ISODEP_INACTIVE); SendCommandNG(CMD_HF_DROPFIELD, NULL, 0); }
29 #define DropFieldEx(x) { \
30 if ( (x) == CC_CONTACTLESS) { \
36 //For storing command that are received from the device
37 #ifndef CMD_BUFFER_SIZE
38 #define CMD_BUFFER_SIZE 100
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
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
;
68 communication_arg_t
*conn
;
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
);