+ uint8_t card_data[6 * 8] = {0};
+ memset(card_data, 0xFF, sizeof(card_data));
+ uint8_t resp[ICLASS_BUFFER_SIZE];
+ //Read conf block CRC(0x01) => 0xfa 0x22
+ uint8_t readConf[] = {ICLASS_CMD_READ_OR_IDENTIFY, 0x01, 0xfa, 0x22};
+ //Read e-purse block CRC(0x02) => 0x61 0x10
+ uint8_t readEpurse[] = {ICLASS_CMD_READ_OR_IDENTIFY, 0x02, 0x61, 0x10};
+ //Read App Issuer Area block CRC(0x05) => 0xde 0x64
+ uint8_t readAA[] = {ICLASS_CMD_READ_OR_IDENTIFY, 0x05, 0xde, 0x64};
+
+ uint8_t result_status = 0;
+
+ // test flags for what blocks to be sure to read
+ uint8_t flagReadConfig = arg0 & FLAG_ICLASS_READER_CONF;
+ uint8_t flagReadCC = arg0 & FLAG_ICLASS_READER_CC;
+ uint8_t flagReadAA = arg0 & FLAG_ICLASS_READER_AA;
+
+ set_tracing(true);
+ clear_trace();
+ Iso15693InitReader();
+
+ StartCountSspClk();
+ uint32_t start_time = 0;
+ uint32_t eof_time = 0;
+
+ if (selectIclassTag(resp, &eof_time)) {
+ result_status = FLAG_ICLASS_READER_CSN;
+ memcpy(card_data, resp, 8);
+ }
+
+ start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
+
+ //Read block 1, config
+ if (flagReadConfig) {
+ if (sendCmdGetResponseWithRetries(readConf, sizeof(readConf), resp, sizeof(resp), 10, 10, start_time, &eof_time)) {
+ result_status |= FLAG_ICLASS_READER_CONF;
+ memcpy(card_data+8, resp, 8);
+ } else {
+ Dbprintf("Failed to read config block");
+ }
+ start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
+ }
+
+ //Read block 2, e-purse
+ if (flagReadCC) {
+ if (sendCmdGetResponseWithRetries(readEpurse, sizeof(readEpurse), resp, sizeof(resp), 10, 10, start_time, &eof_time)) {
+ result_status |= FLAG_ICLASS_READER_CC;
+ memcpy(card_data + (8*2), resp, 8);
+ } else {
+ Dbprintf("Failed to read e-purse");
+ }
+ start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
+ }
+
+ //Read block 5, AA
+ if (flagReadAA) {
+ if (sendCmdGetResponseWithRetries(readAA, sizeof(readAA), resp, sizeof(resp), 10, 10, start_time, &eof_time)) {
+ result_status |= FLAG_ICLASS_READER_AA;
+ memcpy(card_data + (8*5), resp, 8);
+ } else {
+ Dbprintf("Failed to read AA block");
+ }
+ }
+
+ cmd_send(CMD_ACK, result_status, 0, 0, card_data, sizeof(card_data));
+
+ LED_A_OFF();