diff --git a/armsrc/Standalone/hf_reblay.c b/armsrc/Standalone/hf_reblay.c index 484c2f596..dd839380d 100644 --- a/armsrc/Standalone/hf_reblay.c +++ b/armsrc/Standalone/hf_reblay.c @@ -85,7 +85,10 @@ void RunMod() { uint8_t flags = 0; FLAG_SET_UID_IN_DATA(flags, 4); // in case there is a read command received we shouldn't break - uint8_t data[PM3_CMD_DATA_SIZE] = {0x00}; + // only the UID is ever read out of this by SimulateIso14443aInit(), at most + // 10 bytes for a triple-cascade UID. It used to be PM3_CMD_DATA_SIZE, which + // put 624 bytes on the stack for nothing. + uint8_t data[10] = {0x00}; uint8_t visauid[7] = {0xE9, 0x66, 0x5D, 0x20}; memcpy(data, visauid, 4); @@ -130,14 +133,18 @@ void RunMod() { #define DYNAMIC_RESPONSE_BUFFER_SIZE 512 #define DYNAMIC_MODULATION_BUFFER_SIZE 1024 - uint8_t dynamic_response_buffer[DYNAMIC_RESPONSE_BUFFER_SIZE] = {0}; - uint8_t dynamic_modulation_buffer[DYNAMIC_MODULATION_BUFFER_SIZE] = {0}; + // These live in BigBuf, not on the stack - together they are 1536 bytes, and + // RunMod() already carries the deepest frame in the firmware. Same pattern as + // SimulateIso14443aTagEx() in iso14443a.c. Filled in after the emulator is + // initialized, because SimulateIso14443aInit() allocates from BigBuf too. + uint8_t *dynamic_response_buffer = NULL; + uint8_t *dynamic_modulation_buffer = NULL; // Command response - handler tag_response_info_t dynamic_response_info = { - .response = dynamic_response_buffer, + .response = NULL, .response_n = 0, - .modulation = dynamic_modulation_buffer, + .modulation = NULL, .modulation_n = 0 }; @@ -279,6 +286,20 @@ void RunMod() { continue; } + dynamic_response_buffer = BigBuf_calloc(DYNAMIC_RESPONSE_BUFFER_SIZE); + dynamic_modulation_buffer = BigBuf_calloc(DYNAMIC_MODULATION_BUFFER_SIZE); + if (dynamic_response_buffer == NULL || dynamic_modulation_buffer == NULL) { + BigBuf_free_keep_EM(); + reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EMALLOC, NULL, 0); + DbpString(_RED_("Cannot allocate the response buffers!")); + SpinDelay(500); + state = STATE_READ; + DbpString("Initialized [ "_YELLOW_("reading mode") " ]"); + continue; + } + dynamic_response_info.response = dynamic_response_buffer; + dynamic_response_info.modulation = dynamic_modulation_buffer; + // We need to listen to the high-frequency, peak-detected path. iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN);