From 3412e9d8c55eae57b0366a393b1aa6c84b642499 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 10 May 2019 19:00:18 +0200 Subject: [PATCH] Capabilities versionning, would also detect platform struct pack issues --- armsrc/appmain.c | 1 + client/comms.c | 5 +++++ include/pm3_cmd.h | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index ef3d099d0..6b9bfaf6f 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -428,6 +428,7 @@ void SendStatus(void) { void SendCapabilities(void) { capabilities_t capabilities; + capabilities.version = CAPABILITIES_VERSION; capabilities.via_fpc = reply_via_fpc; if (reply_via_fpc) capabilities.baudrate = USART_BAUD_RATE; diff --git a/client/comms.c b/client/comms.c index 187761ae0..ab5ab27ab 100644 --- a/client/comms.c +++ b/client/comms.c @@ -613,6 +613,11 @@ int TestProxmark(void) { SendCommandNG(CMD_CAPABILITIES, NULL, 0); if (WaitForResponseTimeoutW(CMD_CAPABILITIES, &resp, 1000, false)) { + if ((resp.length != sizeof(pm3_capabilities)) || (resp.data.asBytes[0] != CAPABILITIES_VERSION)) { + PrintAndLogEx(ERR, _RED_("Capabilities structure version sent by Proxmark3 is not the same as the one used by the client!")); + PrintAndLogEx(ERR, _RED_("Please flash the Proxmark with the same version as the client.")); + return PM3_EDEVNOTSUPP; + } memcpy(&pm3_capabilities, resp.data.asBytes, MIN(sizeof(capabilities_t), resp.length)); conn.send_via_fpc_usart = pm3_capabilities.via_fpc; conn.uart_speed = pm3_capabilities.baudrate; diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 102b87b82..ae576e087 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -138,6 +138,7 @@ typedef struct { } t55xx_config; typedef struct { + uint8_t version; uint32_t baudrate; bool via_fpc : 1; // rdv4 @@ -164,7 +165,7 @@ typedef struct { bool hw_available_flash : 1; bool hw_available_smartcard : 1; } PACKED capabilities_t; - +#define CAPABILITIES_VERSION 1 extern capabilities_t pm3_capabilities; // For the bootloader