+ }
+
+ int exitLoop = 0;
+ // Reader 0a
+ // Tag 0f
+ // Reader 0c
+ // Tag anticoll. CSN
+ // Reader 81 anticoll. CSN
+ // Tag CSN
+
+ uint8_t *modulated_response;
+ int modulated_response_size = 0;
+ uint8_t *trace_data = NULL;
+ int trace_data_size = 0;
+
+ // Respond SOF -- takes 1 bytes
+ uint8_t *resp_sof = BigBuf_malloc(1);
+ int resp_sof_Len;
+
+ // Anticollision CSN (rotated CSN)
+ // 22: Takes 2 bytes for SOF/EOF and 10 * 2 = 20 bytes (2 bytes/byte)
+ uint8_t *resp_anticoll = BigBuf_malloc(22);
+ int resp_anticoll_len;
+
+ // CSN (block 0)
+ // 22: Takes 2 bytes for SOF/EOF and 10 * 2 = 20 bytes (2 bytes/byte)
+ uint8_t *resp_csn = BigBuf_malloc(22);
+ int resp_csn_len;
+
+ // configuration (block 1) picopass 2ks
+ uint8_t *resp_conf = BigBuf_malloc(22);
+ int resp_conf_len;
+
+ // e-Purse (block 2)
+ // 18: Takes 2 bytes for SOF/EOF and 8 * 2 = 16 bytes (2 bytes/bit)
+ uint8_t *resp_cc = BigBuf_malloc(18);
+ int resp_cc_len;
+
+ // Kd, Kc (blocks 3 and 4). Cannot be read. Always respond with 0xff bytes only
+ uint8_t *resp_ff = BigBuf_malloc(22);
+ int resp_ff_len;
+ uint8_t ff_data[10] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00};
+ AppendCrc(ff_data, 8);
+
+ // Application Issuer Area (block 5)
+ uint8_t *resp_aia = BigBuf_malloc(22);
+ int resp_aia_len;
+ uint8_t aia_data[10] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00};
+ AppendCrc(aia_data, 8);
+
+ uint8_t *receivedCmd = BigBuf_malloc(MAX_FRAME_SIZE);
+ int len;
+
+ // Prepare card messages
+
+ // First card answer: SOF only
+ CodeIClassTagSOF();
+ memcpy(resp_sof, ToSend, ToSendMax);
+ resp_sof_Len = ToSendMax;
+
+ // Anticollision CSN
+ CodeIso15693AsTag(anticoll_data, sizeof(anticoll_data));
+ memcpy(resp_anticoll, ToSend, ToSendMax);
+ resp_anticoll_len = ToSendMax;
+
+ // CSN (block 0)
+ CodeIso15693AsTag(csn_data, sizeof(csn_data));
+ memcpy(resp_csn, ToSend, ToSendMax);
+ resp_csn_len = ToSendMax;
+
+ // Configuration (block 1)
+ CodeIso15693AsTag(conf_block, sizeof(conf_block));
+ memcpy(resp_conf, ToSend, ToSendMax);
+ resp_conf_len = ToSendMax;
+
+ // e-Purse (block 2)
+ CodeIso15693AsTag(card_challenge_data, sizeof(card_challenge_data));
+ memcpy(resp_cc, ToSend, ToSendMax);
+ resp_cc_len = ToSendMax;
+
+ // Kd, Kc (blocks 3 and 4)
+ CodeIso15693AsTag(ff_data, sizeof(ff_data));
+ memcpy(resp_ff, ToSend, ToSendMax);
+ resp_ff_len = ToSendMax;
+
+ // Application Issuer Area (block 5)
+ CodeIso15693AsTag(aia_data, sizeof(aia_data));
+ memcpy(resp_aia, ToSend, ToSendMax);
+ resp_aia_len = ToSendMax;
+
+ //This is used for responding to READ-block commands or other data which is dynamically generated
+ uint8_t *data_generic_trace = BigBuf_malloc(32 + 2); // 32 bytes data + 2byte CRC is max tag answer
+ uint8_t *data_response = BigBuf_malloc( (32 + 2) * 2 + 2);
+
+ bool buttonPressed = false;
+ enum { IDLE, ACTIVATED, SELECTED, HALTED } chip_state = IDLE;
+
+ while (!exitLoop) {
+ WDT_HIT();
+
+ uint32_t reader_eof_time = 0;
+ len = GetIso15693CommandFromReader(receivedCmd, MAX_FRAME_SIZE, &reader_eof_time);
+ if (len < 0) {
+ buttonPressed = true;
+ break;