+ int status;
+ uint8_t atqa[2];
+ uint8_t rid_response[8];
+ uint8_t *uid_echo = &rid_response[2];
+ union {
+ uint8_t raw_content[124];
+ struct {
+ uint8_t HR[2];
+ uint8_t data_block[15][8];
+ uint8_t CRC[2];
+ } static_memory;
+ } rall_response;
+ uint8_t *static_lock_bytes = rall_response.static_memory.data_block[0x0e];
+
+ status = topaz_select(atqa, rid_response);
+
+ if (status == -1) {
+ PrintAndLog("Error: couldn't receive ATQA");
+ return -1;
+ }
+
+ PrintAndLog("ATQA : %02x %02x", atqa[1], atqa[0]);
+ if (atqa[1] != 0x0c && atqa[0] != 0x00) {
+ PrintAndLog("Tag doesn't support the Topaz protocol.");
+ topaz_switch_off_field();
+ return -1;
+ }
+
+ if (status == -2) {
+ PrintAndLog("Error: tag didn't answer to RID");
+ topaz_switch_off_field();
+ return -1;
+ }
+
+ // ToDo: CRC check
+ PrintAndLog("HR0 : %02x (%sa Topaz tag (%scapable of carrying a NDEF message), %s memory map)", rid_response[0],
+ (rid_response[0] & 0xF0) == 0x10 ? "" : "not ",
+ (rid_response[0] & 0xF0) == 0x10 ? "" : "not ",
+ (rid_response[0] & 0x0F) == 0x10 ? "static" : "dynamic");
+ PrintAndLog("HR1 : %02x", rid_response[1]);
+
+ status = topaz_rall(uid_echo, rall_response.raw_content);
+
+ if(status == -1) {
+ PrintAndLog("Error: tag didn't answer to RALL");
+ topaz_switch_off_field();
+ return -1;
+ }
+
+ PrintAndLog("UID : %02x %02x %02x %02x %02x %02x %02x",
+ rall_response.static_memory.data_block[0][6],
+ rall_response.static_memory.data_block[0][5],
+ rall_response.static_memory.data_block[0][4],
+ rall_response.static_memory.data_block[0][3],
+ rall_response.static_memory.data_block[0][2],
+ rall_response.static_memory.data_block[0][1],
+ rall_response.static_memory.data_block[0][0]);
+ PrintAndLog(" UID[6] (Manufacturer Byte) = %02x, Manufacturer: %s",
+ rall_response.static_memory.data_block[0][6],
+ getTagInfo(rall_response.static_memory.data_block[0][6]));
+
+ PrintAndLog("");
+ PrintAndLog("Static Data blocks 00 to 0c:");
+ PrintAndLog("block# | offset | Data | Locked?");
+ char line[80];
+ for (uint16_t i = 0; i <= 0x0c; i++) {
+ for (uint16_t j = 0; j < 8; j++) {
+ sprintf(&line[3*j], "%02x ", rall_response.static_memory.data_block[i][j] /*rall_response[2 + 8*i + j]*/);
+ }
+ PrintAndLog(" 0x%02x | 0x%02x | %s| %-3s", i, i*8, line, topaz_block_is_locked(i, static_lock_bytes) ? "yes" : "no");
+ }
+
+ PrintAndLog("");
+ PrintAndLog("Static Reserved block 0d:");
+ for (uint16_t j = 0; j < 8; j++) {
+ sprintf(&line[3*j], "%02x ", rall_response.static_memory.data_block[0x0d][j]);
+ }
+ PrintAndLog(" 0x%02x | 0x%02x | %s| %-3s", 0x0d, 0x0d*8, line, "n/a");
+
+ PrintAndLog("");
+ PrintAndLog("Static Lockbits / OTP block 0e:");
+ for (uint16_t j = 0; j < 8; j++) {
+ sprintf(&line[3*j], "%02x ", static_lock_bytes[j]);
+ }
+ PrintAndLog(" 0x%02x | 0x%02x | %s| %-3s", 0x0e, 0x0e*8, line, "n/a");
+
+ PrintAndLog("");
+
+ status = topaz_print_CC(&rall_response.static_memory.data_block[1][0]);
+
+ if (status == -1) {
+ PrintAndLog("No NDEF message present");
+ topaz_switch_off_field();
+ return 0;
+ }
+
+ PrintAndLog("");
+ bool lock_TLV_present = topaz_print_lock_control_TLVs(&rall_response.static_memory.data_block[1][4]);
+
+ PrintAndLog("");
+ bool reserved_mem_present = topaz_print_reserved_memory_control_TLVs(&rall_response.static_memory.data_block[1][4]);
+
+ topaz_print_lifecycle_state(&rall_response.static_memory.data_block[1][0]);
+
+ topaz_print_NDEF(&rall_response.static_memory.data_block[1][0]);
+
+ topaz_switch_off_field();