+// read a block (8 Bytes) of a selected Topaz tag.
+static int topaz_read_block(uint8_t *uid, uint8_t blockno, uint8_t *block_data)
+{
+ uint8_t read8_cmd[] = {TOPAZ_READ8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ uint8_t read8_response[11];
+
+ read8_cmd[1] = blockno;
+ memcpy(&read8_cmd[10], uid, 4);
+ if (!topaz_send_cmd(read8_cmd, sizeof(read8_cmd), read8_response)) {
+ topaz_switch_off_field();
+ return -1; // READ8 failed
+ }
+
+ memcpy(block_data, &read8_response[1], 8);
+
+ return 0;
+}
+
+
+// read a segment (16 blocks = 128 Bytes) of a selected Topaz tag. Works only for tags with dynamic memory.
+static int topaz_read_segment(uint8_t *uid, uint8_t segno, uint8_t *segment_data)
+{
+ uint8_t rseg_cmd[] = {TOPAZ_RSEG, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ uint8_t rseg_response[131];
+
+ rseg_cmd[1] = segno << 4;
+ memcpy(&rseg_cmd[10], uid, 4);
+ if (!topaz_send_cmd(rseg_cmd, sizeof(rseg_cmd), rseg_response)) {
+ topaz_switch_off_field();
+ return -1; // RSEG failed
+ }
+
+ memcpy(segment_data, &rseg_response[1], 128);
+
+ return 0;
+}
+
+
+// search for the lock area descriptor for the lockable area including byteno
+static dynamic_lock_area_t *get_dynamic_lock_area(uint16_t byteno)
+{
+ dynamic_lock_area_t *lock_area;
+
+ lock_area = topaz_tag.dynamic_lock_areas;
+
+ while (lock_area != NULL) {
+ if (byteno < lock_area->first_locked_byte) {
+ lock_area = lock_area->next;
+ } else {
+ return lock_area;
+ }
+ }
+
+ return NULL;
+}
+
+
+// check if a memory byte is locked.
+static bool topaz_byte_is_locked(uint16_t byteno)