From 9caa6d61173d4b334d46634fbccd52098848615e Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 14 Sep 2026 12:16:51 +0200 Subject: [PATCH] minor change we device now reports back EMULATOR memory size to the client. Had to bump capability version number to 11. --- CHANGELOG.md | 1 + armsrc/BigBuf.c | 15 +++++++++++++-- armsrc/BigBuf.h | 2 ++ armsrc/appmain.c | 2 ++ client/src/cmdhf15.c | 1 - client/src/comms.c | 4 ++++ client/src/comms.h | 1 + include/pm3_cmd.h | 11 ++++++++++- 8 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b7ea9403..e1d0e51bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Changed `hw status` - now reports EMULATOR memory (@iceman1001) - Changed `hf mf view` - Urmet Captiv cards now decode their number field and data regions (@iceman1001) - Changed `hf mf view --selftest` - now also checks the Hexact payload decoder, both ways (@iceman1001) - Changed `hf mf view` - Hexact sector 9,11 payload is now decoded and cross checked against sector 0,15 and UID (@iceman1001) diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c index cfd495c5d..bbdd0e93b 100644 --- a/armsrc/BigBuf.c +++ b/armsrc/BigBuf.c @@ -113,11 +113,18 @@ uint32_t BigBuf_get_hi(void) { return s_bigbuf_hi; } -/* +// how much emulator memory a card image may use. Reported to the client in +// capabilities_t so it sizes eload / esave from what the device actually has, +// instead of hardcoding a copy of CARD_MEMORY_SIZE uint32_t BigBuf_get_EM_size(void) { return CARD_MEMORY_SIZE; } -*/ + +// has the emulator memory been handed out yet? It is allocated lazily on the +// first BigBuf_get_EM_addr(), so "not allocated" means no card image is loaded +bool BigBuf_is_EM_allocated(void) { + return (s_emulator_memory != NULL); +} // clear ALL of BigBuf void BigBuf_Clear(void) { @@ -192,6 +199,10 @@ void BigBuf_print_status(void) { DbpString(_CYAN_("Memory")); Dbprintf(" BigBuf_size............. %d", s_bigbuf_size); Dbprintf(" Available memory........ %d", s_bigbuf_hi); + Dbprintf(" Emulator memory......... %d ( %s )" + , CARD_MEMORY_SIZE + , (s_emulator_memory != NULL) ? "in use" : "not allocated" + ); DbpString(_CYAN_("Tracing")); Dbprintf(" tracing ................ %d", s_tracing); Dbprintf(" traceLen ............... %d", s_trace_len); diff --git a/armsrc/BigBuf.h b/armsrc/BigBuf.h index d690b4cd5..63bf4bb77 100644 --- a/armsrc/BigBuf.h +++ b/armsrc/BigBuf.h @@ -42,6 +42,8 @@ uint8_t *BigBuf_get_addr(void); uint32_t BigBuf_get_size(void); uint8_t *BigBuf_get_EM_addr(void); +uint32_t BigBuf_get_EM_size(void); +bool BigBuf_is_EM_allocated(void); uint16_t BigBuf_max_traceLen(void); uint32_t BigBuf_get_hi(void); diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 43250a368..2f5d5476d 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -712,6 +712,8 @@ static void SendCapabilities(void) { capabilities.via_fpc = g_reply_via_fpc; capabilities.via_usb = g_reply_via_usb; capabilities.bigbuf_size = BigBuf_get_size(); + capabilities.em_size = BigBuf_get_EM_size(); + capabilities.em_allocated = BigBuf_is_EM_allocated(); capabilities.baudrate = 0; // no real baudrate for USB-CDC #ifdef WITH_FPC_USART if (g_reply_via_fpc) diff --git a/client/src/cmdhf15.c b/client/src/cmdhf15.c index fa69da62e..ff05ec5d3 100644 --- a/client/src/cmdhf15.c +++ b/client/src/cmdhf15.c @@ -49,7 +49,6 @@ #define Logic0 Iso15693Logic0 #define Logic1 Iso15693Logic1 #define FrameEOF Iso15693FrameEOF -#define CARD_MEMORY_SIZE 4096 #ifndef ISO15_ERROR_HANDLING_RESPONSE #define ISO15_ERROR_HANDLING_RESPONSE { \ diff --git a/client/src/comms.c b/client/src/comms.c index 7c54e17bf..193c4346d 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -952,6 +952,7 @@ int TestProxmark(pm3_device_t *dev) { g_conn.send_via_fpc_usart = g_pm3_capabilities.via_fpc; g_conn.uart_speed = g_pm3_capabilities.baudrate; g_conn.max_cmd_data_size = MIN(g_pm3_capabilities.max_cmd_data_size, (uint16_t)PM3_CMD_DATA_SIZE); + g_conn.em_size = g_pm3_capabilities.em_size; bool is_tcp_conn = (g_conn.send_via_ip == PM3_TCPv4 || g_conn.send_via_ip == PM3_TCPv6); bool is_bt_conn = (memcmp(g_conn.serial_port_name, "bt:", 3) == 0); @@ -965,6 +966,9 @@ int TestProxmark(pm3_device_t *dev) { ); PrintAndLogEx(SUCCESS, "Max frame size: " _GREEN_("%u") " bytes", g_conn.max_cmd_data_size); + PrintAndLogEx(SUCCESS, "Emulator memory: " _GREEN_("%u") " bytes%s", + g_conn.em_size, + (g_pm3_capabilities.em_allocated) ? " ( in use )" : ""); if (g_conn.send_via_fpc_usart) { PrintAndLogEx(SUCCESS, "PM3 UART serial baudrate: " _GREEN_("%u") "\n", g_conn.uart_speed); } else { diff --git a/client/src/comms.h b/client/src/comms.h index 4eba1b0c5..08fddfb20 100644 --- a/client/src/comms.h +++ b/client/src/comms.h @@ -78,6 +78,7 @@ typedef struct { bool listen_for_incoming; char serial_port_name[FILE_PATH_SIZE]; uint16_t max_cmd_data_size; + uint16_t em_size; // device side CARD_MEMORY_SIZE } communication_arg_t; extern communication_arg_t g_conn; diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 9fafe84f3..8874eb1db 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -276,11 +276,20 @@ typedef struct { // the client accepts a shorter struct from older firmware // PM5 can use this to inform which size they support oo. uint16_t max_cmd_data_size; // device side PM3_CMD_DATA_SIZE + + // Appended in version 11. + // How much emulator memory a card image may use, device side + // CARD_MEMORY_SIZE. The client sizes eload / esave from this instead of + // carrying its own copy of the constant, so a PM5 reporting a larger + // emulator memory needs no client change. + uint16_t em_size; + bool em_allocated : 1; // is a card image resident right now } PACKED capabilities_t; // Bump this whenever a command payload changes shape, so a mismatched client and // firmware refuse to talk instead of misparsing each other. // 10: CMD_HF_MIFARE_EML_MEMSET gained a flags byte -#define CAPABILITIES_VERSION 10 +// 11: capabilities_t gained em_size / em_allocated +#define CAPABILITIES_VERSION 11 // what a pre-v9 device would have used, it could not tell us #define CAPABILITIES_LEGACY_CMD_DATA_SIZE 512 extern capabilities_t g_pm3_capabilities;