Explorar o código

experimental changes, might roll back or not

frux-c %!s(int64=2) %!d(string=hai) anos
pai
achega
ef38b1eec8
Modificáronse 4 ficheiros con 100 adicións e 32 borrados
  1. BIN=BIN
      assets/res/TDS_1_9_Standard.pdf
  2. 36 0
      uhf_data.c
  3. 26 2
      uhf_data.h
  4. 38 30
      uhf_worker.c

BIN=BIN
assets/res/TDS_1_9_Standard.pdf


+ 36 - 0
uhf_data.c

@@ -3,6 +3,7 @@
 
 UHFData* uhf_data_alloc() {
     UHFData* uhf_data = (UHFData*)malloc(sizeof(UHFData));
+    uhf_data->word_length = 0;
     uhf_data->length = 0;
     uhf_data->start = false;
     uhf_data->end = false;
@@ -60,6 +61,41 @@ void uhf_data_free(UHFData* uhf_data) {
     }
 }
 
+UHFTag* uhf_tag_alloc() {
+    UHFTag* uhf_tag = (UHFTag*)malloc(sizeof(UHFTag));
+    return uhf_tag;
+}
+
+void uhf_tag_set_epc(UHFTag* uhf_tag, uint8_t* data) {
+    // ED 1A 34 00 22 11 22 11 22 11 22 11 22 11 22 11
+    // memcpy((void*)&select_cmd->data, (void*)&CMD_SET_SELECT_PARAMETER.cmd[0], select_cmd->length);
+    memcpy(&uhf_tag->CRC, &data, 2);
+    data += 2;
+    memcpy(&uhf_tag->PC, data, 2);
+    uint16_t epc_length = uhf_tag->PC[0];
+    epc_length <<= 1;
+    epc_length += uhf_tag->PC[1] & 0x08;
+    epc_length *= 2;
+    uhf_tag->epc_length = epc_length;
+    memcpy(&uhf_tag->EPC, &data, (size_t)epc_length);
+}
+
+void uhf_tag_set_tid(UHFTag* uhf_tag, uint8_t* data) {
+    memcpy(&uhf_tag->CRC, &data, 2);
+    data += 2;
+    memcpy(&uhf_tag->PC, data, 2);
+    uint16_t epc_length = uhf_tag->PC[0];
+    epc_length <<= 1;
+    epc_length += uhf_tag->PC[1] & 0x08;
+    epc_length *= 2;
+    uhf_tag->epc_length = epc_length;
+    memcpy(&uhf_tag->EPC, &data, (size_t)epc_length);
+}
+
+void uhf_tag_free(UHFTag* uhf_tag) {
+    free(uhf_tag);
+}
+
 UHFResponseData* uhf_response_data_alloc() {
     UHFResponseData* uhf_response_data = (UHFResponseData*)malloc(sizeof(UHFResponseData));
     uhf_response_data->head = uhf_data_alloc();

+ 26 - 2
uhf_data.h

@@ -3,10 +3,12 @@
 #include <stdint.h>
 #include <stdlib.h>
 
-#define MAX_DATA_SIZE 64
+#define MAX_DATA_SIZE 128
+#define MAX_BANK_SIZE 64
 
 typedef struct UHFData {
     uint8_t data[MAX_DATA_SIZE];
+    size_t word_length;
     size_t length;
     bool start;
     bool end;
@@ -20,6 +22,25 @@ typedef struct UHFResponseData {
 
 } UHFResponseData;
 
+typedef struct UHFTag {
+    // RESERVED BANK (RFU) (00)
+    uint8_t KILL_PWD[2]; // 0x00-0x10
+    uint8_t ACCESS_PWD[2]; // 0x10-0x20
+    // EPC Bank
+    uint8_t CRC[2]; // 0x00-0x10
+    uint8_t PC[2]; // 0x10-0x20
+    uint8_t EPC[MAX_BANK_SIZE]; // 0x20-0x210
+    size_t epc_length;
+    uint8_t XPC[2]; // 0x210-0x21F
+    size_t xpc_length;
+    // TID Bank
+    uint8_t TID[MAX_BANK_SIZE]; // 0x00-END
+    size_t tid_length;
+    // USER Bank
+    uint8_t USER[MAX_BANK_SIZE]; // 0x00-END
+    size_t user_length;
+} UHFTag;
+
 UHFData* uhf_data_alloc();
 int uhf_data_append(UHFData* uhf_data, uint8_t data);
 void uhf_data_reset(UHFData* uhf_data);
@@ -31,4 +52,7 @@ UHFResponseData* uhf_response_data_alloc();
 UHFData* uhf_response_data_add_new_uhf_data(UHFResponseData* uhf_response_data);
 UHFData* uhf_response_data_get_uhf_data(UHFResponseData* uhf_response_data, uint index);
 void uhf_response_data_reset(UHFResponseData* uhf_response_data);
-void uhf_response_data_free(UHFResponseData* uhf_response_data);
+void uhf_response_data_free(UHFResponseData* uhf_response_data);
+
+UHFBank* uhf_tag_alloc();
+void uhf_tag_free(UHFTag* uhf_tag);

+ 38 - 30
uhf_worker.c

@@ -86,7 +86,7 @@ static bool send_set_select_command(UHFData* selected_tag) {
     furi_hal_uart_tx(FuriHalUartIdUSART1, select_cmd->data, select_cmd->length);
     furi_delay_ms(CB_DELAY);
 
-    success = select_response->data[5] != 0x00;
+    success = select_response->data[5] == 0x00;
 
     uhf_data_free(select_cmd);
     uhf_data_free(select_response);
@@ -105,6 +105,8 @@ static bool read_bank(UHFData* read_bank_cmd, UHFData* response_bank, UHFBank ba
 }
 
 UHFWorkerEvent read_single_card(UHFWorker* uhf_worker) {
+    FuriString* temp_str;
+    temp_str = furi_string_alloc();
     UHFResponseData* uhf_response_data = uhf_worker->response_data;
     uhf_response_data_reset(uhf_response_data);
     UHFData* raw_read_data = uhf_response_data_get_uhf_data(uhf_response_data, 0);
@@ -119,6 +121,11 @@ UHFWorkerEvent read_single_card(UHFWorker* uhf_worker) {
             return UHFWorkerEventAborted;
         }
         if(raw_read_data->end) {
+            for(size_t i = 0; i < raw_read_data->length; i++) {
+                furi_string_cat_printf(temp_str, "%02x ", raw_read_data->data[i]);
+            }
+            FURI_LOG_E("TAG", furi_string_get_cstr(temp_str));
+            furi_string_reset(temp_str);
             if(raw_read_data->data[1] == 0x01 && raw_read_data->data[5] == 0x15) {
                 uhf_data_reset(raw_read_data);
                 continue;
@@ -127,7 +134,7 @@ UHFWorkerEvent read_single_card(UHFWorker* uhf_worker) {
         }
     }
 
-    if(send_set_select_command(raw_read_data)) return UHFWorkerEventFail;
+    if(!send_set_select_command(raw_read_data)) return UHFWorkerEventFail;
 
     UHFData* read_bank_cmd = uhf_data_alloc();
     read_bank_cmd->length = CMD_READ_LABEL_DATA_STORAGE.length;
@@ -160,34 +167,35 @@ UHFWorkerEvent read_single_card(UHFWorker* uhf_worker) {
     if(!read_bank(read_bank_cmd, user_bank, USER_BANK)) {
         uhf_data_reset(user_bank);
     }
-    FuriString* str;
-    str = furi_string_alloc();
-    furi_string_cat(str, "RFU : ");
-    for(int i = 0; i < (int)rfu_bank->length; i++) {
-        furi_string_cat_printf(str, "%02x ", rfu_bank->data[i]);
-    }
-    FURI_LOG_E("TAG", furi_string_get_cstr(str));
-    furi_string_reset(str);
-    furi_string_cat(str, "EPC : ");
-    for(int i = 0; i < (int)epc_bank->length; i++) {
-        furi_string_cat_printf(str, "%02x ", epc_bank->data[i]);
-    }
-    FURI_LOG_E("TAG", furi_string_get_cstr(str));
-    furi_string_reset(str);
-    furi_string_cat(str, "TID : ");
-    for(int i = 0; i < (int)tid_bank->length; i++) {
-        furi_string_cat_printf(str, "%02x ", tid_bank->data[i]);
-    }
-    FURI_LOG_E("TAG", furi_string_get_cstr(str));
-    furi_string_reset(str);
-    furi_string_cat(str, "USER : ");
-    for(int i = 0; i < (int)user_bank->length; i++) {
-        furi_string_cat_printf(str, "%02x ", user_bank->data[i]);
-    }
-    FURI_LOG_E("TAG", furi_string_get_cstr(str));
-    furi_string_reset(str);
-    furi_string_free(str);
-    // uhf_data_free(select);
+
+    // FuriString* str;
+    // str = furi_string_alloc();
+    // furi_string_cat(str, "RFU : ");
+    // for(int i = 0; i < (int)rfu_bank->length; i++) {
+    //     furi_string_cat_printf(str, "%02x ", rfu_bank->data[i]);
+    // }
+    // FURI_LOG_E("TAG", furi_string_get_cstr(str));
+    // furi_string_reset(str);
+    // furi_string_cat(str, "EPC : ");
+    // for(int i = 0; i < (int)epc_bank->length; i++) {
+    //     furi_string_cat_printf(str, "%02x ", epc_bank->data[i]);
+    // }
+    // FURI_LOG_E("TAG", furi_string_get_cstr(str));
+    // furi_string_reset(str);
+    // furi_string_cat(str, "TID : ");
+    // for(int i = 0; i < (int)tid_bank->length; i++) {
+    //     furi_string_cat_printf(str, "%02x ", tid_bank->data[i]);
+    // }
+    // FURI_LOG_E("TAG", furi_string_get_cstr(str));
+    // furi_string_reset(str);
+    // furi_string_cat(str, "USER : ");
+    // for(int i = 0; i < (int)user_bank->length; i++) {
+    //     furi_string_cat_printf(str, "%02x ", user_bank->data[i]);
+    // }
+    // FURI_LOG_E("TAG", furi_string_get_cstr(str));
+    // furi_string_reset(str);
+    furi_string_free(temp_str);
+
     uhf_data_free(read_bank_cmd);
     return UHFWorkerEventSuccess;
 }