+int EmSend4bitEx(uint8_t resp, int correctionNeeded);
+int EmSend4bit(uint8_t resp);
+int EmSendCmdExPar(uint8_t *resp, int respLen, int correctionNeeded, uint32_t par);
+int EmSendCmdExPar(uint8_t *resp, int respLen, int correctionNeeded, uint32_t par);
+int EmSendCmdEx(uint8_t *resp, int respLen, int correctionNeeded);
+int EmSendCmd(uint8_t *resp, int respLen);
+int EmSendCmdPar(uint8_t *resp, int respLen, uint32_t par);
+
+static uint8_t* free_buffer_pointer = (((uint8_t *)BigBuf) + FREE_BUFFER_OFFSET);
+
+typedef struct {
+ uint8_t* response;
+ size_t response_n;
+ uint8_t* modulation;
+ size_t modulation_n;
+} tag_response_info_t;
+
+void reset_free_buffer() {
+ free_buffer_pointer = (((uint8_t *)BigBuf) + FREE_BUFFER_OFFSET);
+}
+
+bool prepare_tag_modulation(tag_response_info_t* response_info, size_t max_buffer_size) {
+ // Exmaple response, answer to MIFARE Classic read block will be 16 bytes + 2 CRC = 18 bytes
+ // This will need the following byte array for a modulation sequence
+ // 144 data bits (18 * 8)
+ // 18 parity bits
+ // 2 Start and stop
+ // 1 Correction bit (Answer in 1172 or 1236 periods, see FPGA)
+ // 1 just for the case
+ // ----------- +
+ // 166 bytes, since every bit that needs to be send costs us a byte
+ //
+
+ // Prepare the tag modulation bits from the message
+ CodeIso14443aAsTag(response_info->response,response_info->response_n);
+
+ // Make sure we do not exceed the free buffer space
+ if (ToSendMax > max_buffer_size) {
+ Dbprintf("Out of memory, when modulating bits for tag answer:");
+ Dbhexdump(response_info->response_n,response_info->response,false);
+ return false;
+ }
+
+ // Copy the byte array, used for this modulation to the buffer position
+ memcpy(response_info->modulation,ToSend,ToSendMax);
+
+ // Store the number of bytes that were used for encoding/modulation
+ response_info->modulation_n = ToSendMax;
+
+ return true;
+}
+
+bool prepare_allocated_tag_modulation(tag_response_info_t* response_info) {
+ // Retrieve and store the current buffer index
+ response_info->modulation = free_buffer_pointer;
+
+ // Determine the maximum size we can use from our buffer
+ size_t max_buffer_size = (((uint8_t *)BigBuf)+FREE_BUFFER_OFFSET+FREE_BUFFER_SIZE)-free_buffer_pointer;
+
+ // Forward the prepare tag modulation function to the inner function
+ if (prepare_tag_modulation(response_info,max_buffer_size)) {
+ // Update the free buffer offset
+ free_buffer_pointer += ToSendMax;
+ return true;
+ } else {
+ return false;
+ }
+}