proxmark3/client/comms.h

82 lines
2.9 KiB
C
Raw Normal View History

//-----------------------------------------------------------------------------
// Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
2019-05-18 23:53:08 +08:00
// Code for communicating with the Proxmark3 hardware.
//-----------------------------------------------------------------------------
#ifndef COMMS_H_
#define COMMS_H_
#include <stdbool.h>
#include <pthread.h>
#include "pm3_cmd.h"
#include "uart.h"
#include "ui.h"
#include "common.h"
#include "util_posix.h"
#include "util.h"
#include "util_darwin.h"
#if defined(__linux__) && !defined(NO_UNLINK)
2019-03-10 06:35:06 +08:00
#include <unistd.h> // for unlink()
#endif
//For storing command that are received from the device
#ifndef CMD_BUFFER_SIZE
#define CMD_BUFFER_SIZE 100
#endif
typedef enum {
2019-03-10 06:35:06 +08:00
BIG_BUF,
BIG_BUF_EML,
FLASH_MEM,
SIM_MEM,
SPIFFS
2019-03-10 07:00:59 +08:00
} DeviceMemType_t;
typedef struct {
2019-03-10 06:35:06 +08:00
bool run; // If TRUE, continue running the uart_communication thread
bool block_after_ACK; // if true, block after receiving an ACK package
// Flags to tell where to add CRC on sent replies
bool send_with_crc_on_usb;
bool send_with_crc_on_fpc;
// "Session" flag, to tell via which interface next msgs are sent: USB or FPC USART
bool send_via_fpc_usart;
// To memorise baudrate
uint32_t uart_speed;
2019-05-06 04:34:22 +08:00
uint16_t last_command;
2019-05-07 21:40:01 +08:00
uint8_t serial_port_name[FILE_PATH_SIZE];
} communication_arg_t;
2019-04-26 19:53:11 +08:00
extern communication_arg_t conn;
void *uart_receiver(void *targ);
2019-05-08 19:31:58 +08:00
void SendCommandBL(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
2019-04-19 04:19:28 +08:00
void SendCommandOLD(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
2019-04-17 02:49:32 +08:00
void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len);
void SendCommandMIX(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
2019-04-10 04:42:23 +08:00
void clearCommandBuffer(void);
#define FLASHMODE_SPEED 460800
bool IsCommunicationThreadDead(void);
bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed);
2019-04-14 23:25:17 +08:00
int TestProxmark(void);
void CloseProxmark(void);
2019-04-18 18:43:35 +08:00
bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms_timeout, bool show_warning);
bool WaitForResponseTimeout(uint32_t cmd, PacketResponseNG *response, size_t ms_timeout);
bool WaitForResponse(uint32_t cmd, PacketResponseNG *response);
//bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketResponseNG *response, size_t ms_timeout, bool show_warning);
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);
#endif