mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-14 19:24:10 +08:00
Several changes in the initial connection, see details:
* TestProxmark uses pingng * New command CMD_CAPABILITIES to transmit capabilities from pm3 to host * Use TestProxmark to retrieve capabilities with that new command * CloseProxmark if TestProxmark fails * Hide baudrate for USB and retrieve real baudrate from pm3 for BT
This commit is contained in:
parent
7d1161d7d8
commit
e2e0b704c5
5 changed files with 54 additions and 15 deletions
|
@ -429,6 +429,16 @@ void SendStatus(void) {
|
|||
reply_old(CMD_ACK, 1, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void SendCapabilities(void) {
|
||||
capabilities_t capabilities;
|
||||
capabilities.via_fpc = reply_via_fpc;
|
||||
if (reply_via_fpc)
|
||||
capabilities.baudrate = USART_BAUD_RATE;
|
||||
else
|
||||
capabilities.baudrate = 0; // no real baudrate for USB-CDC
|
||||
reply_ng(CMD_CAPABILITIES, PM3_SUCCESS, (uint8_t *)&capabilities, sizeof(capabilities));
|
||||
}
|
||||
|
||||
// Show some leds in a pattern to identify StandAlone mod is running
|
||||
void StandAloneMode(void) {
|
||||
|
||||
|
@ -1439,6 +1449,8 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
case CMD_STATUS:
|
||||
SendStatus();
|
||||
break;
|
||||
case CMD_CAPABILITIES:
|
||||
SendCapabilities();
|
||||
case CMD_PING:
|
||||
if (packet->ng) {
|
||||
reply_ng(CMD_PING, PM3_SUCCESS, packet->data.asBytes, packet->length);
|
||||
|
|
|
@ -20,6 +20,7 @@ static char *serial_port_name = NULL;
|
|||
static bool offline;
|
||||
|
||||
communication_arg_t conn;
|
||||
capabilities_t pm3_capabilities;
|
||||
|
||||
static pthread_t USB_communication_thread;
|
||||
//static pthread_t FPC_communication_thread;
|
||||
|
@ -567,22 +568,40 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode,
|
|||
int TestProxmark(void) {
|
||||
clearCommandBuffer();
|
||||
PacketResponseNG resp;
|
||||
SendCommandOLD(CMD_PING, 0, 0, 0, NULL, 0);
|
||||
uint16_t len = 32;
|
||||
uint8_t data[len];
|
||||
for (uint16_t i = 0; i < len; i++)
|
||||
data[i] = i & 0xFF;
|
||||
SendCommandNG(CMD_PING, data, len);
|
||||
#ifdef USART_SLOW_LINK
|
||||
// 10s timeout for slow FPC, e.g. over BT
|
||||
// as this is the very first command sent to the pm3
|
||||
// that initiates the BT connection
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 10000)) {
|
||||
if (WaitForResponseTimeoutW(CMD_PING, &resp, 10000, false)) {
|
||||
#else
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
|
||||
if (WaitForResponseTimeoutW(CMD_PING, &resp, 1000, false)) {
|
||||
#endif
|
||||
conn.send_via_fpc = resp.oldarg[0] == 1;
|
||||
PrintAndLogEx(INFO, "Communicating with PM3 over %s.", conn.send_via_fpc ? _YELLOW_("FPC") : _YELLOW_("USB-CDC"));
|
||||
if (conn.send_via_fpc)
|
||||
PrintAndLogEx(INFO, "UART Serial baudrate: " _YELLOW_("%u") "\n", conn.uart_speed);
|
||||
return 1;
|
||||
|
||||
bool error = false;
|
||||
if (len)
|
||||
error = memcmp(data, resp.data.asBytes, len) != 0;
|
||||
if (error)
|
||||
return PM3_EIO;
|
||||
|
||||
SendCommandNG(CMD_CAPABILITIES, NULL, 0);
|
||||
if (WaitForResponseTimeoutW(CMD_PING, &resp, 1000, false)) {
|
||||
memcpy(&pm3_capabilities, resp.data.asBytes, resp.length);
|
||||
conn.send_via_fpc = pm3_capabilities.via_fpc;
|
||||
conn.uart_speed = pm3_capabilities.baudrate;
|
||||
PrintAndLogEx(INFO, "Communicating with PM3 over %s", conn.send_via_fpc ? _YELLOW_("FPC UART") : _YELLOW_("USB-CDC"));
|
||||
if (conn.send_via_fpc)
|
||||
PrintAndLogEx(INFO, "UART Serial baudrate: " _YELLOW_("%u") "\n", conn.uart_speed);
|
||||
return PM3_SUCCESS;
|
||||
} else {
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ typedef struct {
|
|||
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;
|
||||
// To memorise baudrate, we don't want to call get_speed systematically
|
||||
// To memorise baudrate
|
||||
uint32_t uart_speed;
|
||||
} communication_arg_t;
|
||||
|
||||
|
|
|
@ -468,8 +468,11 @@ int main(int argc, char *argv[]) {
|
|||
if (port != NULL)
|
||||
pm3_present = OpenProxmark(port, waitCOMPort, 20, false, speed);
|
||||
|
||||
if (pm3_present && (TestProxmark() == 0))
|
||||
if (pm3_present && (TestProxmark() != PM3_SUCCESS)) {
|
||||
PrintAndLogEx(ERR, _RED_("ERROR:") "cannot communicate with the Proxmark\n");
|
||||
CloseProxmark();
|
||||
pm3_present = false;
|
||||
}
|
||||
if (!pm3_present)
|
||||
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") "mode. Check \"%s -h\" if it's not what you want.\n", exec_name);
|
||||
|
||||
|
|
|
@ -136,6 +136,14 @@ typedef struct {
|
|||
uint16_t read_gap;
|
||||
} t55xx_config;
|
||||
|
||||
// TODO add more fields to report all hw & sw capabilities of pm3
|
||||
typedef struct {
|
||||
uint32_t baudrate;
|
||||
bool via_fpc;
|
||||
} PACKED capabilities_t;
|
||||
|
||||
extern capabilities_t pm3_capabilities;
|
||||
|
||||
// For the bootloader
|
||||
#define CMD_DEVICE_INFO 0x0000
|
||||
#define CMD_SETUP_WRITE 0x0001
|
||||
|
@ -156,12 +164,9 @@ typedef struct {
|
|||
#define CMD_VERSION 0x0107
|
||||
#define CMD_STATUS 0x0108
|
||||
#define CMD_PING 0x0109
|
||||
|
||||
#define CMD_DOWNLOAD_EML_BIGBUF 0x0110
|
||||
#define CMD_DOWNLOADED_EML_BIGBUF 0x0111
|
||||
|
||||
|
||||
|
||||
#define CMD_CAPABILITIES 0x0112
|
||||
|
||||
// RDV40, Flash memory operations
|
||||
#define CMD_FLASHMEM_READ 0x0120
|
||||
|
|
Loading…
Reference in a new issue