+static bool sendCmdGetResponseWithRetries(uint8_t* command, size_t cmdsize, uint8_t* resp, size_t max_resp_size,
+ uint8_t expected_size, uint8_t retries, uint32_t start_time, uint32_t *eof_time) {
+ while (retries-- > 0) {
+ ReaderTransmitIClass(command, cmdsize, &start_time);
+ if (expected_size == GetIso15693AnswerFromTag(resp, max_resp_size, ICLASS_READER_TIMEOUT_OTHERS, eof_time)) {
+ return true;
+ }
+ }
+ return false;//Error
+}
+
+/**
+ * @brief Talks to an iclass tag, sends the commands to get CSN and CC.
+ * @param card_data where the CSN and CC are stored for return
+ * @return 0 = fail
+ * 1 = Got CSN
+ * 2 = Got CSN and CC
+ */
+static uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key, uint32_t *eof_time) {
+ uint8_t act_all[] = { 0x0a };
+ uint8_t identify[] = { 0x0c };
+ uint8_t select[] = { 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ uint8_t readcheck_cc[] = { 0x88, 0x02 };
+ if (use_credit_key)
+ readcheck_cc[0] = 0x18;
+ else
+ readcheck_cc[0] = 0x88;
+
+ uint8_t resp[ICLASS_BUFFER_SIZE];
+
+ uint8_t read_status = 0;
+ uint32_t start_time = GetCountSspClk();
+
+ // Send act_all
+ ReaderTransmitIClass(act_all, 1, &start_time);
+ // Card present?
+ if (GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_ACTALL, eof_time) < 0) return read_status;//Fail
+
+ //Send Identify
+ start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
+ ReaderTransmitIClass(identify, 1, &start_time);
+ // FpgaDisableTracing(); // DEBUGGING
+ //We expect a 10-byte response here, 8 byte anticollision-CSN and 2 byte CRC
+ uint8_t len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_OTHERS, eof_time);
+ if (len != 10) return read_status;//Fail
+
+ //Copy the Anti-collision CSN to our select-packet
+ memcpy(&select[1], resp, 8);
+ //Select the card
+ start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
+ ReaderTransmitIClass(select, sizeof(select), &start_time);
+ //We expect a 10-byte response here, 8 byte CSN and 2 byte CRC
+ len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_OTHERS, eof_time);
+ if (len != 10) return read_status;//Fail
+
+ //Success - level 1, we got CSN
+ //Save CSN in response data
+ memcpy(card_data, resp, 8);
+
+ //Flag that we got to at least stage 1, read CSN
+ read_status = 1;
+
+ // Card selected, now read e-purse (cc) (only 8 bytes no CRC)
+ start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
+ ReaderTransmitIClass(readcheck_cc, sizeof(readcheck_cc), &start_time);
+ if (GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_OTHERS, eof_time) == 8) {
+ //Save CC (e-purse) in response data
+ memcpy(card_data+8, resp, 8);
+ read_status++;
+ }