Chaka 2 лет назад
Родитель
Сommit
abeac4a69b
16 измененных файлов с 394 добавлено и 554 удалено
  1. 7 7
      scenes/uhf_scene_device_info.c
  2. 23 8
      scenes/uhf_scene_read_tag_success.c
  3. 5 15
      scenes/uhf_scene_verify.c
  4. 3 3
      uhf_app.c
  5. 2 2
      uhf_app_i.h
  6. 3 1
      uhf_buffer.c
  7. 0 1
      uhf_buffer.h
  8. 69 69
      uhf_cmd.h
  9. 0 148
      uhf_data.c
  10. 0 64
      uhf_data.h
  11. 19 15
      uhf_device.c
  12. 57 16
      uhf_module.c
  13. 12 11
      uhf_module.h
  14. 32 10
      uhf_tag.c
  15. 6 2
      uhf_tag.h
  16. 156 182
      uhf_worker.c

+ 7 - 7
scenes/uhf_scene_device_info.c

@@ -40,7 +40,7 @@ void uhf_scene_device_info_widget_callback(GuiButtonType result, InputType type,
 }
 
 void change_view_on_event(UHFApp* uhf_app) {
-    UHFTag* uhf_tag = uhf_app->uhf_device->uhf_tag;
+    UHFTag* uhf_tag = uhf_app->uhf_device->uhf_tag_wrapper->uhf_tag;
     FuriString* furi_temp_str;
     furi_temp_str = furi_string_alloc();
     char* temp_str;
@@ -52,16 +52,16 @@ void change_view_on_event(UHFApp* uhf_app) {
 
     switch(current_info) {
     case EPC_INFO:
-        temp_str = convertToHexString(uhf_tag->epc, uhf_tag->epc_length);
-        length = uhf_tag->epc_length;
+        temp_str = convertToHexString(uhf_tag->epc->data, uhf_tag->epc->size);
+        length = uhf_tag->epc->size;
         break;
     case TID_INFO:
-        temp_str = convertToHexString(uhf_tag->tid, uhf_tag->tid_length);
-        length = uhf_tag->tid_length;
+        temp_str = convertToHexString(uhf_tag->tid->data, uhf_tag->tid->size);
+        length = uhf_tag->tid->size;
         break;
     case USER_INFO:
-        temp_str = convertToHexString(uhf_tag->user, uhf_tag->user_length);
-        length = uhf_tag->user_length;
+        temp_str = convertToHexString(uhf_tag->user->data, uhf_tag->user->size);
+        length = uhf_tag->user->size;
         break;
     default:
         temp_str = NULL;

+ 23 - 8
scenes/uhf_scene_read_tag_success.c

@@ -17,7 +17,8 @@ void uhf_scene_read_card_success_widget_callback(GuiButtonType result, InputType
 
 void uhf_scene_read_tag_success_on_enter(void* ctx) {
     UHFApp* uhf_app = ctx;
-    UHFTag* uhf_tag = uhf_app->worker->uhf_tag;
+    UHFTag* uhf_tag = uhf_app->worker->uhf_tag_wrapper->uhf_tag;
+    FuriString* temp_str = furi_string_alloc();
 
     dolphin_deed(DolphinDeedNfcReadSuccess);
 
@@ -35,11 +36,26 @@ void uhf_scene_read_tag_success_on_enter(void* ctx) {
     widget_add_string_element(
         uhf_app->widget, 3, 32, AlignLeft, AlignCenter, FontPrimary, "EPC :");
 
-    char* pc = convertToHexString(uhf_tag->pc, 2);
-    widget_add_string_element(uhf_app->widget, 26, 19, AlignLeft, AlignCenter, FontKeyboard, pc);
-    char* crc = convertToHexString(uhf_tag->crc, 2);
-    widget_add_string_element(uhf_app->widget, 96, 19, AlignLeft, AlignCenter, FontKeyboard, crc);
-    char* epc = convertToHexString(uhf_tag->epc + 2, uhf_tag->epc_length - 2);
+    furi_string_cat_printf(temp_str, "%04X", uhf_tag->epc->pc);
+    widget_add_string_element(
+        uhf_app->widget,
+        26,
+        19,
+        AlignLeft,
+        AlignCenter,
+        FontKeyboard,
+        furi_string_get_cstr(temp_str));
+    furi_string_reset(temp_str);
+    furi_string_cat_printf(temp_str, "%04X", uhf_tag->epc->crc);
+    widget_add_string_element(
+        uhf_app->widget,
+        96,
+        19,
+        AlignLeft,
+        AlignCenter,
+        FontKeyboard,
+        furi_string_get_cstr(temp_str));
+    char* epc = convertToHexString(uhf_tag->epc->data, uhf_tag->epc->size);
     widget_add_string_multiline_element(
         uhf_app->widget, 34, 29, AlignLeft, AlignTop, FontKeyboard, epc);
     widget_add_button_element(
@@ -55,9 +71,8 @@ void uhf_scene_read_tag_success_on_enter(void* ctx) {
         uhf_scene_read_card_success_widget_callback,
         uhf_app);
     view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewWidget);
-    free(pc);
-    free(crc);
     free(epc);
+    furi_string_free(temp_str);
 }
 
 bool uhf_scene_read_tag_success_on_event(void* ctx, SceneManagerEvent event) {

+ 5 - 15
scenes/uhf_scene_verify.c

@@ -52,18 +52,12 @@ bool uhf_scene_verify_on_event(void* ctx, SceneManagerEvent event) {
             if(verify_success) {
                 widget_reset(uhf_app->widget);
                 furi_string_reset(temp_str);
-                UHFResponseData* uhf_response_data = uhf_app->worker->response_data;
-                UHFData* hardware_version = uhf_response_data_get_uhf_data(uhf_response_data, 0);
-                UHFData* software_version = uhf_response_data_get_uhf_data(uhf_response_data, 1);
-                UHFData* manufacturer = uhf_response_data_get_uhf_data(uhf_response_data, 2);
-                uint offset = 6;
+                M100Module* module = uhf_app->worker->module;
                 widget_add_string_element(
                     uhf_app->widget, 64, 5, AlignCenter, AlignCenter, FontPrimary, "Module Info");
                 // hardware info
                 furi_string_cat_str(temp_str, "HW Version: ");
-                for(int i = 0; i < (int)hardware_version->data[4]; i++) {
-                    furi_string_cat_printf(temp_str, "%c", hardware_version->data[offset + i]);
-                }
+                furi_string_cat_str(temp_str, module->info->hw_version);
                 widget_add_string_element(
                     uhf_app->widget,
                     1,
@@ -75,9 +69,7 @@ bool uhf_scene_verify_on_event(void* ctx, SceneManagerEvent event) {
                 furi_string_reset(temp_str);
                 // software info
                 furi_string_cat_str(temp_str, "SW Version: ");
-                for(int i = 0; i < (int)software_version->data[4]; i++) {
-                    furi_string_cat_printf(temp_str, "%c", software_version->data[offset + i]);
-                }
+                furi_string_cat_str(temp_str, module->info->sw_version);
                 widget_add_string_element(
                     uhf_app->widget,
                     1,
@@ -89,9 +81,7 @@ bool uhf_scene_verify_on_event(void* ctx, SceneManagerEvent event) {
                 furi_string_reset(temp_str);
                 // manufacturer info
                 furi_string_cat_str(temp_str, "Manufacturer: ");
-                for(int i = 0; i < (int)manufacturer->data[4]; i++) {
-                    furi_string_cat_printf(temp_str, "%c", manufacturer->data[offset + i]);
-                }
+                furi_string_cat_str(temp_str, module->info->manufacturer);
                 widget_add_string_element(
                     uhf_app->widget,
                     1,
@@ -123,7 +113,7 @@ bool uhf_scene_verify_on_event(void* ctx, SceneManagerEvent event) {
                     AlignCenter,
                     AlignCenter,
                     FontSecondary,
-                    "Please connect your module.\nPlease refer to the frux-c/uhf_rfid for help.");
+                    "Please connect your module.\nPlease refer to the git@frux-c/uhf_rfid for help.");
                 widget_add_button_element(
                     uhf_app->widget,
                     GuiButtonTypeLeft,

+ 3 - 3
uhf_app.c

@@ -1,6 +1,6 @@
 #include "uhf_app_i.h"
 
-char* convertToHexString(const uint8_t* array, size_t length) {
+char* convertToHexString(uint8_t* array, size_t length) {
     if(array == NULL || length == 0) {
         return " ";
     }
@@ -62,8 +62,8 @@ UHFApp* uhf_alloc() {
 
     UHFTagWrapper* uhf_tag_wrapper = uhf_tag_wrapper_alloc();
     // point tag object to worker
-    uhf_app->worker->uhf_tag = uhf_tag_wrapper;
-    uhf_app->uhf_device->uhf_tag = uhf_tag_wrapper;
+    uhf_app->worker->uhf_tag_wrapper = uhf_tag_wrapper;
+    uhf_app->uhf_device->uhf_tag_wrapper = uhf_tag_wrapper;
 
     // Open Notification record
     uhf_app->notifications = furi_record_open(RECORD_NOTIFICATION);

+ 2 - 2
uhf_app_i.h

@@ -99,6 +99,6 @@ void uhf_show_loading_popup(void* context, bool show);
  */
 bool uhf_is_memset(const uint8_t* data, const uint8_t pattern, size_t size);
 
-char* convertToHexString(const uint8_t* array, size_t length);
+char* convertToHexString(uint8_t* array, size_t length);
 
-bool uhf_save_read_data(UHFResponseData* uhf_response_data, Storage* storage, const char* filename);
+// bool uhf_save_read_data(UHFResponseData* uhf_response_data, Storage* storage, const char* filename);

+ 3 - 1
uhf_buffer.c

@@ -1,4 +1,6 @@
 #include "uhf_buffer.h"
+#include <stdlib.h>
+#include <string.h>
 
 Buffer* buffer_alloc(size_t initial_capacity) {
     Buffer* buf = (Buffer*)malloc(sizeof(Buffer));
@@ -39,7 +41,7 @@ bool buffer_append(Buffer* buf, uint8_t* data, size_t data_size) {
         buf->capacity = new_capacity;
     }
 
-    memcpy(buf->data + buf->size, data, data_size);
+    memcpy((void*)&buf->data[buf->size], data, data_size);
     buf->size += data_size;
     return true;
 }

+ 0 - 1
uhf_buffer.h

@@ -1,5 +1,4 @@
 #pragma once
-
 #include <stdint.h>
 #include <stdbool.h>
 #include <stddef.h>

+ 69 - 69
uhf_cmd.h

@@ -1,114 +1,114 @@
-#ifndef UHF_CMD_H
-#define UHF_CMD_H
+// #ifndef UHF_CMD_H
+// #define UHF_CMD_H
 
-#include <stdint.h>
-#include <stdlib.h>
+// #include <stdint.h>
+// #include <stdlib.h>
 
-typedef struct UHF_RFID_CMD {
-    uint8_t* cmd;
-    size_t length;
-}UHF_RFID_CMD;
+// typedef struct UHF_RFID_CMD {
+//     uint8_t* cmd;
+//     size_t length;
+// }UHF_RFID_CMD;
 
-typedef enum{
-    COMMAND_FRAME = 0x00,
-    RESPONSE_FRAME,
-    NOTIFICATION_FRAME
-}UHFFrameType;
+// typedef enum{
+//     COMMAND_FRAME = 0x00,
+//     RESPONSE_FRAME,
+//     NOTIFICATION_FRAME
+// }UHFFrameType;
 
-typedef enum{
-    RFU_BANK,
-    EPC_BANK,
-    TID_BANK,
-    USER_BANK
-}UHFBank;
+// typedef enum{
+//     RFU_BANK,
+//     EPC_BANK,
+//     TID_BANK,
+//     USER_BANK
+// }UHFBank;
 
-typedef enum{
-    CHINA_900MHZ = 1,
-    CHINA_800MHZ = 4,
-    US = 2,
-    EU = 3,
-    KOREA = 6
-}UHFWorkArea;
+// typedef enum{
+//     CHINA_900MHZ = 1,
+//     CHINA_800MHZ = 4,
+//     US = 2,
+//     EU = 3,
+//     KOREA = 6
+// }UHFWorkArea;
 
-#define DEFAULT_BAUD_RATE 115200
-#define FRAME_START 0xBB
-#define FRAME_END 0x7E
-#define ERROR 0x15
+// #define DEFAULT_BAUD_RATE 115200
+// #define FRAME_START 0xBB
+// #define FRAME_END 0x7E
+// #define ERROR 0x15
 
-UHF_RFID_CMD CMD_HARDWARE_VERSION = {.cmd = (uint8_t[]){0xBB, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x7E}, .length = 8};
+// UHF_RFID_CMD CMD_HARDWARE_VERSION = {.cmd = (uint8_t[]){0xBB, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x7E}, .length = 8};
 
-UHF_RFID_CMD CMD_SOFTWARE_VERSION = {.cmd = (uint8_t[]){0xBB, 0x00, 0x03, 0x00, 0x01, 0x01, 0x05, 0x7E}, .length = 8};
+// UHF_RFID_CMD CMD_SOFTWARE_VERSION = {.cmd = (uint8_t[]){0xBB, 0x00, 0x03, 0x00, 0x01, 0x01, 0x05, 0x7E}, .length = 8};
 
-UHF_RFID_CMD CMD_MANUFACTURERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0x03, 0x00, 0x01, 0x02, 0x06, 0x7E}, .length = 8};
+// UHF_RFID_CMD CMD_MANUFACTURERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0x03, 0x00, 0x01, 0x02, 0x06, 0x7E}, .length = 8};
 
-UHF_RFID_CMD CMD_SINGLE_POLLING = {.cmd = (uint8_t[]){0xBB, 0x00, 0x22, 0x00, 0x00, 0x22, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_SINGLE_POLLING = {.cmd = (uint8_t[]){0xBB, 0x00, 0x22, 0x00, 0x00, 0x22, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_MULTIPLE_POLLING = {.cmd = (uint8_t[]){0xBB, 0x00, 0x27, 0x00, 0x03, 0x22, 0x27, 0x10, 0x83, 0x7E}, .length = 10};
+// UHF_RFID_CMD CMD_MULTIPLE_POLLING = {.cmd = (uint8_t[]){0xBB, 0x00, 0x27, 0x00, 0x03, 0x22, 0x27, 0x10, 0x83, 0x7E}, .length = 10};
 
-UHF_RFID_CMD CMD_STOP_MULTIPLE_POLLING = {.cmd = (uint8_t[]){0xBB, 0x00, 0x28, 0x00, 0x00, 0x28, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_STOP_MULTIPLE_POLLING = {.cmd = (uint8_t[]){0xBB, 0x00, 0x28, 0x00, 0x00, 0x28, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_SET_SELECT_PARAMETER = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0C, 0x00, 0x13, 0x01, 0x00, 0x00, 0x00, 0x20, 0x60, 0x00, 0x30, 0x75, 0x1F, 0xEB, 0x70, 0x5C, 0x59, 0x04, 0xE3, 0xD5, 0x0D, 0x70, 0xAD, 0x7E }, .length = 26};
+// UHF_RFID_CMD CMD_SET_SELECT_PARAMETER = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0C, 0x00, 0x13, 0x01, 0x00, 0x00, 0x00, 0x20, 0x60, 0x00, 0x30, 0x75, 0x1F, 0xEB, 0x70, 0x5C, 0x59, 0x04, 0xE3, 0xD5, 0x0D, 0x70, 0xAD, 0x7E }, .length = 26};
 
-UHF_RFID_CMD CMD_GET_SELECT_PARAMETER = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0B, 0x00, 0x00, 0x0B, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_GET_SELECT_PARAMETER = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0B, 0x00, 0x00, 0x0B, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_SET_SELECT_MODE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x12, 0x00, 0x01, 0x01, 0x14, 0x7E}, .length = 8};
+// UHF_RFID_CMD CMD_SET_SELECT_MODE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x12, 0x00, 0x01, 0x01, 0x14, 0x7E}, .length = 8};
 
-UHF_RFID_CMD CMD_READ_LABEL_DATA_STORAGE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x39, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x4D, 0x7E}, .length = 16};
+// UHF_RFID_CMD CMD_READ_LABEL_DATA_STORAGE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x39, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x4D, 0x7E}, .length = 16};
 
-UHF_RFID_CMD CMD_WRITE_LABEL_DATA_STORAGE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x71, 0x7E}, .length = 24};
+// UHF_RFID_CMD CMD_WRITE_LABEL_DATA_STORAGE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x71, 0x7E}, .length = 24};
 
-UHF_RFID_CMD CMD_LOCK_LABEL_DATA_STORAGE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x82, 0x00, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x02, 0x00, 0x80, 0x09, 0x7E}, .length = 13};
+// UHF_RFID_CMD CMD_LOCK_LABEL_DATA_STORAGE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x82, 0x00, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x02, 0x00, 0x80, 0x09, 0x7E}, .length = 13};
 
-UHF_RFID_CMD CMD_INACTIVATE_KILL_TAG = {.cmd = (uint8_t[]){0xBB, 0x00, 0x65, 0x00, 0x04, 0x00, 0x00, 0xFF, 0xFF, 0x67, 0x7E}, .length = 11};
+// UHF_RFID_CMD CMD_INACTIVATE_KILL_TAG = {.cmd = (uint8_t[]){0xBB, 0x00, 0x65, 0x00, 0x04, 0x00, 0x00, 0xFF, 0xFF, 0x67, 0x7E}, .length = 11};
 
-UHF_RFID_CMD CMD_SET_COMMUNICATION_BAUD_RATE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x11, 0x00, 0x02, 0x00, 0xC0, 0xD3, 0x7E}, .length = 9};
+// UHF_RFID_CMD CMD_SET_COMMUNICATION_BAUD_RATE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x11, 0x00, 0x02, 0x00, 0xC0, 0xD3, 0x7E}, .length = 9};
 
-UHF_RFID_CMD CMD_GET_QUERY_PARAMETERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0D, 0x00, 0x00, 0x0D, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_GET_QUERY_PARAMETERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0D, 0x00, 0x00, 0x0D, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_SET_QUERY_PARAMETER = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0E, 0x00, 0x02, 0x10, 0x20, 0x40, 0x7E}, .length = 9};
+// UHF_RFID_CMD CMD_SET_QUERY_PARAMETER = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0E, 0x00, 0x02, 0x10, 0x20, 0x40, 0x7E}, .length = 9};
 
-UHF_RFID_CMD CMD_SETUP_WORK_AREA = {.cmd = (uint8_t[]){0xBB, 0x00, 0x07, 0x00, 0x01, 0x01, 0x09, 0x7E}, .length = 8};
+// UHF_RFID_CMD CMD_SETUP_WORK_AREA = {.cmd = (uint8_t[]){0xBB, 0x00, 0x07, 0x00, 0x01, 0x01, 0x09, 0x7E}, .length = 8};
 
-UHF_RFID_CMD CMD_ACQUIRE_WORK_LOCATIONS = {.cmd = (uint8_t[]){0xBB, 0x00, 0x08, 0x00, 0x00, 0x08, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_ACQUIRE_WORK_LOCATIONS = {.cmd = (uint8_t[]){0xBB, 0x00, 0x08, 0x00, 0x00, 0x08, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_SETUP_WORKING_CHANNEL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xAB, 0x00, 0x01, 0x01, 0xAC, 0x7E}, .length = 8};
+// UHF_RFID_CMD CMD_SETUP_WORKING_CHANNEL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xAB, 0x00, 0x01, 0x01, 0xAC, 0x7E}, .length = 8};
 
-UHF_RFID_CMD CMD_GET_WORKING_CHANNEL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xAA, 0x00, 0x00, 0xAA, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_GET_WORKING_CHANNEL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xAA, 0x00, 0x00, 0xAA, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_SET_AUTO_FREQUENCY_HOPPING = {.cmd = (uint8_t[]){0xBB, 0x00, 0xAD, 0x00, 0x01, 0xFF, 0xAD, 0x7E}, .length = 8};
+// UHF_RFID_CMD CMD_SET_AUTO_FREQUENCY_HOPPING = {.cmd = (uint8_t[]){0xBB, 0x00, 0xAD, 0x00, 0x01, 0xFF, 0xAD, 0x7E}, .length = 8};
 
-UHF_RFID_CMD CMD_INSERT_WORKING_CHANNEL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xA9, 0x00, 0x06, 0x05, 0x01, 0x02,0x03, 0x04, 0x05, 0xC3, 0x7E}, .length = 13};
+// UHF_RFID_CMD CMD_INSERT_WORKING_CHANNEL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xA9, 0x00, 0x06, 0x05, 0x01, 0x02,0x03, 0x04, 0x05, 0xC3, 0x7E}, .length = 13};
 
-UHF_RFID_CMD CMD_ACQUIRE_TRANSMITTING_POWER = {.cmd = (uint8_t[]){0xBB, 0x00, 0xB7, 0x00, 0x00, 0xB7, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_ACQUIRE_TRANSMITTING_POWER = {.cmd = (uint8_t[]){0xBB, 0x00, 0xB7, 0x00, 0x00, 0xB7, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_SET_TRANSMITTING_POWER = {.cmd = (uint8_t[]){0xBB, 0x00, 0xB6, 0x00, 0x02, 0x07, 0xD0, 0x8F, 0x7E}, .length = 9};
+// UHF_RFID_CMD CMD_SET_TRANSMITTING_POWER = {.cmd = (uint8_t[]){0xBB, 0x00, 0xB6, 0x00, 0x02, 0x07, 0xD0, 0x8F, 0x7E}, .length = 9};
 
-UHF_RFID_CMD CMD_SET_CONTINUOUS_CARRIER = {.cmd = (uint8_t[]){0xBB, 0x00, 0xB0, 0x00, 0x01, 0xFF, 0xB0, 0x7E}, .length = 8};
+// UHF_RFID_CMD CMD_SET_CONTINUOUS_CARRIER = {.cmd = (uint8_t[]){0xBB, 0x00, 0xB0, 0x00, 0x01, 0xFF, 0xB0, 0x7E}, .length = 8};
 
-UHF_RFID_CMD CMD_GET_DEMODULATOR_PARAMETERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF1, 0x00, 0x00, 0xF1, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_GET_DEMODULATOR_PARAMETERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF1, 0x00, 0x00, 0xF1, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_SET_DEMODULATOR_PARAMETERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF0, 0x00, 0x04, 0x03, 0x06, 0x01, 0xB0, 0xAE, 0x7E}, .length = 11};
+// UHF_RFID_CMD CMD_SET_DEMODULATOR_PARAMETERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF0, 0x00, 0x04, 0x03, 0x06, 0x01, 0xB0, 0xAE, 0x7E}, .length = 11};
 
-UHF_RFID_CMD CMD_TEST_RF_INPUT_BLOCK_SIGNAL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF2, 0x00, 0x00, 0xF2, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_TEST_RF_INPUT_BLOCK_SIGNAL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF2, 0x00, 0x00, 0xF2, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_TEST_RSSI_SIGNAL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF3, 0x00, 0x00, 0xF3, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_TEST_RSSI_SIGNAL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF3, 0x00, 0x00, 0xF3, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_MODULE_HIBERNATION = {.cmd = (uint8_t[]){0xBB, 0x00, 0x17, 0x00, 0x00, 0x17, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_MODULE_HIBERNATION = {.cmd = (uint8_t[]){0xBB, 0x00, 0x17, 0x00, 0x00, 0x17, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_IDLE_HIBERNATION_TIME = {.cmd = (uint8_t[]){0xBB, 0x00, 0x1D, 0x00, 0x01, 0x02, 0x20, 0x7E}, .length = 8};
+// UHF_RFID_CMD CMD_IDLE_HIBERNATION_TIME = {.cmd = (uint8_t[]){0xBB, 0x00, 0x1D, 0x00, 0x01, 0x02, 0x20, 0x7E}, .length = 8};
 
-UHF_RFID_CMD CMD_IDLE_MODE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x04, 0x00, 0x03, 0x01, 0x01, 0x03, 0x0C, 0x7E}, .length = 10};
+// UHF_RFID_CMD CMD_IDLE_MODE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x04, 0x00, 0x03, 0x01, 0x01, 0x03, 0x0C, 0x7E}, .length = 10};
 
-UHF_RFID_CMD CMD_NXP_READPROTECT = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE1, 0x00, 0x05, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xE4, 0x7E}, .length = 12};
+// UHF_RFID_CMD CMD_NXP_READPROTECT = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE1, 0x00, 0x05, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xE4, 0x7E}, .length = 12};
 
-UHF_RFID_CMD CMD_NXP_CHANGE_EAS = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE3, 0x00, 0x05, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0xE7, 0x7E}, .length = 12};
+// UHF_RFID_CMD CMD_NXP_CHANGE_EAS = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE3, 0x00, 0x05, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0xE7, 0x7E}, .length = 12};
 
-UHF_RFID_CMD CMD_NXP_EAS_ALARM = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE4, 0x00, 0x00, 0xE4, 0x7E}, .length = 7};
+// UHF_RFID_CMD CMD_NXP_EAS_ALARM = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE4, 0x00, 0x00, 0xE4, 0x7E}, .length = 7};
 
-UHF_RFID_CMD CMD_NXP_CONFIG_WORD = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE0, 0x00, 0x06, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xE4, 0x7E}, .length = 13};
+// UHF_RFID_CMD CMD_NXP_CONFIG_WORD = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE0, 0x00, 0x06, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xE4, 0x7E}, .length = 13};
 
-UHF_RFID_CMD CMD_IMPINJ_MONZA4_QT = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE5, 0x00, 0x08, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0x01, 0x40, 0x00, 0x2D, 0x7E}, .length = 15};
+// UHF_RFID_CMD CMD_IMPINJ_MONZA4_QT = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE5, 0x00, 0x08, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0x01, 0x40, 0x00, 0x2D, 0x7E}, .length = 15};
 
-UHF_RFID_CMD CMD_BLOCK_PERMALOCK = {.cmd = (uint8_t[]){0xBB, 0x00, 0xD3, 0x00, 0x0B, 0x00, 0x00, 0xFF,0xFF, 0x01, 0x03, 0x00, 0x00, 0x01, 0x07, 0x00, 0xE8, 0x7E}, .length = 18};
+// UHF_RFID_CMD CMD_BLOCK_PERMALOCK = {.cmd = (uint8_t[]){0xBB, 0x00, 0xD3, 0x00, 0x0B, 0x00, 0x00, 0xFF,0xFF, 0x01, 0x03, 0x00, 0x00, 0x01, 0x07, 0x00, 0xE8, 0x7E}, .length = 18};
 
-#endif /* UHF_CMD_H */
+// #endif /* UHF_CMD_H */

+ 0 - 148
uhf_data.c

@@ -1,148 +0,0 @@
-#include "uhf_data.h"
-
-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;
-    uhf_data->next = NULL;
-    return uhf_data;
-}
-
-int uhf_data_append(UHFData* uhf_data, uint8_t data) {
-    if(data == 0xBB) {
-        uhf_data->start = true;
-    }
-    if(!uhf_data->start) return 0;
-    if(uhf_data->end) return 0;
-    if(uhf_data->length >= MAX_DATA_SIZE) return 0;
-    if(data == 0x7E) {
-        uhf_data->end = true;
-    }
-    uhf_data->data[uhf_data->length++] = data;
-    return 1;
-}
-
-void uhf_data_reset(UHFData* uhf_data) {
-    for(size_t i = 0; i < uhf_data->length; i++) {
-        uhf_data->data[i] = 0x00;
-    }
-    uhf_data->start = false;
-    uhf_data->end = false;
-    uhf_data->length = 0;
-    uhf_data->next = NULL;
-}
-
-uint8_t uhf_data_calculate_checksum(UHFData* uhf_data) {
-    // CheckSum8 Modulo 256
-    // Sum of Bytes % 256
-    uint8_t sum_val = 0x00;
-    size_t length = uhf_data->length - 2;
-    for(size_t i = 1; i < length; i++) {
-        sum_val += uhf_data->data[i];
-    }
-    return sum_val % 256;
-}
-
-bool uhf_data_verfiy_checksum(UHFData* uhf_data) {
-    uint8_t data_checksum = uhf_data->data[uhf_data->length - 2];
-    uint8_t actual_checksum = uhf_data_calculate_checksum(uhf_data);
-    return data_checksum == actual_checksum;
-}
-
-void uhf_data_free(UHFData* uhf_data) {
-    if(uhf_data == NULL) return;
-    while(uhf_data != NULL) {
-        UHFData* next = uhf_data->next;
-        free(uhf_data);
-        uhf_data = next;
-    }
-}
-
-UHFResponseData* uhf_response_data_alloc() {
-    UHFResponseData* uhf_response_data = (UHFResponseData*)malloc(sizeof(UHFResponseData));
-    uhf_response_data->head = uhf_data_alloc();
-    uhf_response_data->tail = uhf_response_data->head;
-    uhf_response_data->size = 1;
-    return uhf_response_data;
-}
-
-UHFData* uhf_response_data_add_new_uhf_data(UHFResponseData* uhf_response_data) {
-    UHFData* temp = uhf_response_data->head;
-    while(temp->next != NULL) {
-        temp = temp->next;
-    }
-    temp->next = uhf_data_alloc();
-    uhf_response_data->size++;
-    uhf_response_data->tail = temp->next;
-    return temp->next;
-}
-
-UHFData* uhf_response_data_get_uhf_data(UHFResponseData* uhf_response_data, uint index) {
-    if(uhf_response_data == NULL || uhf_response_data->size <= index) return NULL;
-    UHFData* uhf_data = uhf_response_data->head;
-    if(index == 0) return uhf_data;
-    while(uhf_data != NULL && index >= 1) {
-        uhf_data = uhf_data->next;
-        index--;
-    }
-    return uhf_data;
-}
-
-void uhf_response_data_reset(UHFResponseData* uhf_response_data) {
-    uhf_data_reset(uhf_response_data->head);
-    if(uhf_response_data->size == 1) {
-        return;
-    }
-    uhf_data_free(uhf_response_data->head->next);
-    uhf_response_data->size = 1;
-}
-
-void uhf_response_data_free(UHFResponseData* uhf_response_data) {
-    uhf_data_free(uhf_response_data->head);
-    free(uhf_response_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, size_t length) {
-    memcpy(uhf_tag->crc, data, 2);
-    data += 2;
-    memcpy(uhf_tag->pc, data, 2);
-    memcpy(uhf_tag->epc, data, length);
-    uhf_tag->epc_length = length;
-}
-
-void uhf_tag_reset(UHFTag* uhf_tag) {
-    for(int i = 0; i < 2; i++) {
-        uhf_tag->crc[i] = 0;
-        uhf_tag->pc[i] = 0;
-        uhf_tag->xpc[i] = 0;
-    }
-    for(int i = 0; i < MAX_BANK_SIZE; i++) {
-        uhf_tag->epc[i] = 0;
-        uhf_tag->tid[i] = 0;
-        uhf_tag->user[i] = 0;
-    }
-    uhf_tag->epc_length = 0;
-    uhf_tag->tid_length = 0;
-    uhf_tag->user_length = 0;
-}
-
-void uhf_tag_set_tid(UHFTag* uhf_tag, uint8_t* data, size_t length) {
-    memcpy(uhf_tag->tid, data, length);
-    uhf_tag->tid_length = length;
-}
-
-void uhf_tag_set_user(UHFTag* uhf_tag, uint8_t* data, size_t length) {
-    memcpy(uhf_tag->user, data, length);
-    uhf_tag->user_length = length;
-}
-
-void uhf_tag_free(UHFTag* uhf_tag) {
-    free(uhf_tag);
-}

+ 0 - 64
uhf_data.h

@@ -1,64 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
-
-#define MAX_DATA_SIZE 128
-#define MAX_BANK_SIZE 64
-typedef unsigned int uint;
-
-typedef struct UHFData {
-    uint8_t data[MAX_DATA_SIZE];
-    size_t word_length;
-    size_t length;
-    bool start;
-    bool end;
-    struct UHFData* next;
-} UHFData;
-
-typedef struct UHFResponseData {
-    UHFData* head;
-    UHFData* tail;
-    size_t size;
-} 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);
-uint8_t uhf_data_calculate_checksum(UHFData* uhf_data);
-bool uhf_data_verfiy_checksum(UHFData* uhf_data);
-void uhf_data_free(UHFData* uhf_data);
-
-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);
-
-UHFTag* uhf_tag_alloc();
-void uhf_tag_reset(UHFTag* uhf_tag);
-void uhf_tag_set_epc(UHFTag* uhf_tag, uint8_t* data, size_t length);
-void uhf_tag_set_tid(UHFTag* uhf_tag, uint8_t* data, size_t length);
-void uhf_tag_set_user(UHFTag* uhf_tag, uint8_t* data, size_t length);
-void uhf_tag_free(UHFTag* uhf_tag);

+ 19 - 15
uhf_device.c

@@ -1,5 +1,4 @@
 #include "uhf_device.h"
-
 #include <toolbox/path.h>
 #include <flipper_format/flipper_format.h>
 #include <uhf_rfid_icons.h>
@@ -33,7 +32,7 @@ static bool uhf_device_save_file(
     bool use_load_path) {
     furi_assert(dev);
 
-    UHFTag* uhf_tag = dev->uhf_tag;
+    UHFTag* uhf_tag = dev->uhf_tag_wrapper->uhf_tag;
     bool saved = false;
     FlipperFormat* file = flipper_format_file_alloc(dev->storage);
     FuriString* temp_str;
@@ -58,20 +57,22 @@ static bool uhf_device_save_file(
         // todo : maybe
         uint32_t temp_arr[1];
         // write epc
-        temp_arr[0] = uhf_tag->epc_length;
+        temp_arr[0] = uhf_tag->epc->size;
         if(!flipper_format_write_uint32(file, UHF_EPC_BANK_LENGTH_LABEL, temp_arr, 1)) break;
-        if(!flipper_format_write_hex(file, UHF_EPC_BANK_LABEL, uhf_tag->epc, uhf_tag->epc_length))
+        if(!flipper_format_write_hex(
+               file, UHF_EPC_BANK_LABEL, uhf_tag->epc->data, uhf_tag->epc->size))
             break;
         // write tid
-        temp_arr[0] = uhf_tag->tid_length;
+        temp_arr[0] = uhf_tag->tid->size;
         if(!flipper_format_write_uint32(file, UHF_TID_BANK_LENGTH_LABEL, temp_arr, 1)) break;
-        if(!flipper_format_write_hex(file, UHF_TID_BANK_LABEL, uhf_tag->tid, uhf_tag->tid_length))
+        if(!flipper_format_write_hex(
+               file, UHF_TID_BANK_LABEL, uhf_tag->tid->data, uhf_tag->tid->size))
             break;
         // write user
-        temp_arr[0] = uhf_tag->user_length;
+        temp_arr[0] = uhf_tag->user->size;
         if(!flipper_format_write_uint32(file, UHF_USER_BANK_LENGTH_LABEL, temp_arr, 1)) break;
         if(!flipper_format_write_hex(
-               file, UHF_USER_BANK_LABEL, uhf_tag->user, uhf_tag->user_length))
+               file, UHF_USER_BANK_LABEL, uhf_tag->user->data, uhf_tag->user->size))
             break;
         saved = true;
     } while(0);
@@ -99,7 +100,7 @@ static bool uhf_device_load_data(UHFDevice* dev, FuriString* path, bool show_dia
     FuriString* temp_str;
     temp_str = furi_string_alloc();
     bool deprecated_version = false;
-    UHFTag* uhf_tag = dev->uhf_tag;
+    UHFTag* uhf_tag = dev->uhf_tag_wrapper->uhf_tag;
     uhf_tag_reset(uhf_tag);
     uint32_t temp_arr[1];
     if(dev->loading_cb) {
@@ -118,20 +119,23 @@ static bool uhf_device_load_data(UHFDevice* dev, FuriString* path, bool show_dia
         }
         // read epc
         if(!flipper_format_read_uint32(file, UHF_EPC_BANK_LENGTH_LABEL, temp_arr, 1)) break;
-        uhf_tag->epc_length = temp_arr[0];
-        if(!flipper_format_read_hex(file, UHF_EPC_BANK_LABEL, uhf_tag->epc, uhf_tag->epc_length))
+        uhf_tag->epc->size = temp_arr[0];
+        if(!flipper_format_read_hex(
+               file, UHF_EPC_BANK_LABEL, uhf_tag->epc->data, uhf_tag->epc->size))
             break;
 
         // read tid
         if(!flipper_format_read_uint32(file, UHF_TID_BANK_LENGTH_LABEL, temp_arr, 1)) break;
-        uhf_tag->tid_length = temp_arr[0];
-        if(!flipper_format_read_hex(file, UHF_TID_BANK_LABEL, uhf_tag->tid, uhf_tag->tid_length))
+        uhf_tag->tid->size = temp_arr[0];
+        if(!flipper_format_read_hex(
+               file, UHF_TID_BANK_LABEL, uhf_tag->tid->data, uhf_tag->tid->size))
             break;
 
         // read user
         if(!flipper_format_read_uint32(file, UHF_USER_BANK_LENGTH_LABEL, temp_arr, 1)) break;
-        uhf_tag->user_length = temp_arr[0];
-        if(!flipper_format_read_hex(file, UHF_USER_BANK_LABEL, uhf_tag->user, uhf_tag->user_length))
+        uhf_tag->user->size = temp_arr[0];
+        if(!flipper_format_read_hex(
+               file, UHF_USER_BANK_LABEL, uhf_tag->user->data, uhf_tag->user->size))
             break;
 
         parsed = true;

+ 57 - 16
uhf_module.c

@@ -6,10 +6,7 @@
 static void rx_callback(UartIrqEvent event, uint8_t data, void* ctx) {
     UNUSED(event);
     Buffer* buf = ctx;
-    if(data == FRAME_END) {
-        buffer_append_single(buf, data);
-        buffer_close(buf);
-    }
+    if(data == FRAME_END) buffer_close(buf);
     buffer_append_single(buf, data);
 }
 
@@ -31,6 +28,7 @@ M100Module* m100_module_alloc() {
     M100Module* module = (M100Module*)malloc(sizeof(M100Module));
     module->info = m100_module_info_alloc();
     module->buf = buffer_alloc(128);
+    return module;
 }
 
 void m100_module_free(M100Module* module) {
@@ -68,10 +66,10 @@ uint16_t crc16_genibus(const uint8_t* data, size_t length) {
 }
 
 char* m100_get_hardware_version(M100Module* module) {
-    if(!module->info->hw_version == NULL) return module->info->hw_version;
+    if(!(((void*)module->info->sw_version) == NULL)) return module->info->hw_version;
     buffer_reset(module->buf);
     furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, rx_callback, module->buf);
-    furi_hal_uart_tx(FuriHalUartIdUSART1, CMD_HW_VERSION.cmd, CMD_HW_VERSION.length);
+    furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)&CMD_HW_VERSION.cmd[0], CMD_HW_VERSION.length);
     furi_delay_ms(DELAY_MS);
     if(!buffer_get_size(module->buf)) return NULL;
     uint8_t* data = buffer_get_data(module->buf);
@@ -80,13 +78,14 @@ char* m100_get_hardware_version(M100Module* module) {
     char hw_version[payload_len];
     memcpy(hw_version, data + 6, (size_t)payload_len);
     module->info->hw_version = hw_version;
-    return hw_version;
+    free(hw_version);
+    return module->info->hw_version;
 }
 char* m100_get_software_version(M100Module* module) {
-    if(!module->info->sw_version == NULL) return module->info->hw_version;
+    if(!(((void*)module->info->hw_version) == NULL)) return module->info->hw_version;
     buffer_reset(module->buf);
     furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, rx_callback, module->buf);
-    furi_hal_uart_tx(FuriHalUartIdUSART1, CMD_SW_VERSION.cmd, CMD_SW_VERSION.length);
+    furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)&CMD_SW_VERSION.cmd[0], CMD_SW_VERSION.length);
     furi_delay_ms(DELAY_MS);
     if(!buffer_get_size(module->buf)) return NULL;
     uint8_t* data = buffer_get_data(module->buf);
@@ -95,13 +94,15 @@ char* m100_get_software_version(M100Module* module) {
     char sw_version[payload_len];
     memcpy(sw_version, data + 6, (size_t)payload_len);
     module->info->sw_version = sw_version;
-    return sw_version;
+    free(sw_version);
+    return module->info->sw_version;
 }
 char* m100_get_manufacturers(M100Module* module) {
-    if(!module->info->manufacturer == NULL) return module->info->manufacturer;
+    if(!(((void*)module->info->manufacturer) == NULL)) return module->info->manufacturer;
     buffer_reset(module->buf);
     furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, rx_callback, module->buf);
-    furi_hal_uart_tx(FuriHalUartIdUSART1, CMD_MANUFACTURERS.cmd, CMD_MANUFACTURERS.length);
+    furi_hal_uart_tx(
+        FuriHalUartIdUSART1, (uint8_t*)&CMD_MANUFACTURERS.cmd[0], CMD_MANUFACTURERS.length);
     furi_delay_ms(DELAY_MS);
     if(!buffer_get_size(module->buf)) return NULL;
     uint8_t* data = buffer_get_data(module->buf);
@@ -110,13 +111,15 @@ char* m100_get_manufacturers(M100Module* module) {
     char manufacturer[payload_len];
     memcpy(manufacturer, data + 6, (size_t)payload_len);
     module->info->manufacturer = manufacturer;
-    return manufacturer;
+    free(manufacturer);
+    return module->info->manufacturer;
 }
 
 UHFTag* m100_send_single_poll(M100Module* module) {
     buffer_reset(module->buf);
     furi_hal_uart_set_irq_cb(FuriHalUartIdLPUART1, rx_callback, module->buf);
-    furi_hal_uart_tx(FuriHalUartIdUSART1, CMD_SINGLE_POLLING.cmd, CMD_SINGLE_POLLING.length);
+    furi_hal_uart_tx(
+        FuriHalUartIdUSART1, (uint8_t*)&CMD_SINGLE_POLLING.cmd[0], CMD_SINGLE_POLLING.length);
     furi_delay_ms(DELAY_MS);
     uint8_t* data = buffer_get_data(module->buf);
     size_t length = buffer_get_size(module->buf);
@@ -148,10 +151,10 @@ bool m100_set_select(M100Module* module, UHFTag* uhf_tag) {
     size_t cmd_length = CMD_SET_SELECT_PARAMETER.length;
     size_t mask_length_bytes = uhf_tag->epc->size;
     size_t mask_length_bits = mask_length_bytes * 8;
+    // payload len = sel param len + ptr len + mask len + epc len
     size_t payload_len = 7 + mask_length_bytes;
     memcpy(cmd, CMD_SET_SELECT_PARAMETER.cmd, cmd_length);
     // set payload length
-    // payload len = sel param len + ptr len + mask len + epc len
     cmd[3] = (payload_len >> 8) & 0xFF;
     cmd[4] = payload_len & 0xFF;
     // set select param
@@ -163,7 +166,7 @@ bool m100_set_select(M100Module* module, UHFTag* uhf_tag) {
     // truncate
     cmd[11] = false;
     // set mask
-    memcpy(cmd[12], uhf_tag->epc->data, mask_length_bytes);
+    memcpy((void*)&cmd[12], uhf_tag->epc->data, mask_length_bytes);
     // set checksum
     cmd[12 + mask_length_bytes + 1] = checksum(cmd + 1, 11 + mask_length_bytes);
     // end frame
@@ -179,7 +182,38 @@ bool m100_set_select(M100Module* module, UHFTag* uhf_tag) {
     return true;
 }
 
+UHFTag* m100_get_select_param(M100Module module) {
+    UNUSED(module);
+    return NULL;
+}
+
+bool m100_read_label_data_storage(
+    M100Module* module,
+    UHFTag* uhf_tag,
+    BankType bank,
+    uint32_t access_pwd) {
+    UNUSED(uhf_tag);
+    buffer_reset(module->buf);
+    uint8_t cmd[MAX_BUFFER_SIZE];
+    size_t length = CMD_READ_LABEL_DATA_STORAGE_AREA.length;
+    memcpy(cmd, CMD_READ_LABEL_DATA_STORAGE_AREA.cmd, length);
+    // set access password
+    cmd[5] = (access_pwd >> 24) & 0xFF;
+    cmd[6] = (access_pwd >> 16) & 0xFF;
+    cmd[7] = (access_pwd >> 8) & 0xFF;
+    cmd[8] = access_pwd & 0xFF;
+    // set mem bank
+    cmd[9] = (uint8_t)bank;
+    // recalc checksum
+    cmd[length - 2] = checksum(cmd + 1, length - 3);
+    furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, rx_callback, module->buf);
+    furi_hal_uart_tx(FuriHalUartIdUSART1, cmd, length);
+    furi_delay_ms(DELAY_MS);
+    return true;
+}
+
 void m100_set_baudrate(M100Module* module, uint16_t baudrate) {
+    // M100Module* this_module = module;
     size_t length = CMD_SET_COMMUNICATION_BAUD_RATE.length;
     uint8_t cmd[length];
     memcpy(cmd, CMD_SET_COMMUNICATION_BAUD_RATE.cmd, length);
@@ -199,14 +233,21 @@ bool m100_set_working_area(M100Module* module, WorkingArea area) {
     furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, rx_callback, buf);
     furi_hal_uart_tx(FuriHalUartIdUSART1, cmd, length);
     buffer_free(buf);
+    module->area = area;
     return true;
 }
 bool m100_set_working_channel(M100Module* module, WorkingChannel channel) {
+    UNUSED(module);
+    UNUSED(channel);
     return true;
 }
 bool m100_set_transmitting_power(M100Module* module, uint16_t power) {
+    UNUSED(module);
+    UNUSED(power);
     return true;
 }
 bool m100_set_freq_hopping(M100Module* module, bool hopping) {
+    UNUSED(module);
+    UNUSED(hopping);
     return true;
 }

+ 12 - 11
uhf_module.h

@@ -16,19 +16,19 @@ typedef struct{
 }M100ModuleInfo;
 
 typedef enum{
-    CHINA_900 = 1,  // Freq_CH-920.125M
-    US,             // Freq_CH-902.25M
-    EU,             // Freq_CH-865.1M
-    CHINA_800,      // Freq_CH-840.125M
-    KOREA = 6       // Freq_CH-917.1M
+    WA_CHINA_900 = 1,  // Freq_CH-920.125M
+    WA_US,             // Freq_CH-902.25M
+    WA_EU,             // Freq_CH-865.1M
+    WA_CHINA_800,      // Freq_CH-840.125M
+    WA_KOREA = 6       // Freq_CH-917.1M
 } WorkingArea;
 
 typedef enum{
-    CHINA_900 = 1,  // CH_Index(CN,900MHz) = (Freq_CH-920.125M)/0.25M
-    US,             // CH_Index(US) = (Freq_CH-902.25M)/0.5M
-    EU,             // CH_Index(EU) = (Freq_CH-865.1M)/0.2M
-    CHINA_800,      // CH_Index(CN,800MHz) = (Freq_CH-840.125M)/0.25M
-    KOREA = 6       // CH_Index(Korea) = (Freq_CH-917.1M)/0.2M
+    WC_CHINA_900 = 1,  // CH_Index(CN,900MHz) = (Freq_CH-920.125M)/0.25M
+    WC_US,             // CH_Index(US) = (Freq_CH-902.25M)/0.5M
+    WC_EU,             // CH_Index(EU) = (Freq_CH-865.1M)/0.2M
+    WC_CHINA_800,      // CH_Index(CN,800MHz) = (Freq_CH-840.125M)/0.25M
+    WC_KOREA = 6       // CH_Index(Korea) = (Freq_CH-917.1M)/0.2M
 } WorkingChannel;
 
 typedef struct{
@@ -63,4 +63,5 @@ bool m100_set_freq_hopping(M100Module* module, bool hopping);
 
 // gen2 cmds
 UHFTag* m100_send_single_poll(M100Module* module);
-bool m100_set_select(M100Module* module, UHFTag* uhf_tag);
+bool m100_set_select(M100Module* module, UHFTag* uhf_tag);
+bool m100_read_label_data_storage(M100Module* module, UHFTag* uhf_tag, BankType bank, uint32_t access_pwd);

+ 32 - 10
uhf_tag.c

@@ -1,4 +1,21 @@
 #include "uhf_tag.h"
+#include <stdlib.h>
+#include <string.h>
+
+UHFTagWrapper* uhf_tag_wrapper_alloc() {
+    UHFTagWrapper* uhf_tag_wrapper = (UHFTagWrapper*)malloc(sizeof(UHFTagWrapper));
+    uhf_tag_wrapper->uhf_tag = NULL;
+    return uhf_tag_wrapper;
+}
+
+void uhf_tag_wrapper_set_tag(UHFTagWrapper* uhf_tag_wrapper, UHFTag* uhf_tag) {
+    uhf_tag_wrapper->uhf_tag = uhf_tag;
+}
+
+void uhf_tag_wrapper_free(UHFTagWrapper* uhf_tag_wrapper) {
+    if(uhf_tag_wrapper->uhf_tag != NULL) uhf_tag_free(uhf_tag_wrapper->uhf_tag);
+    free(uhf_tag_wrapper);
+}
 
 UHFTag* uhf_tag_alloc() {
     UHFTag* uhf_tag = (UHFTag*)malloc(sizeof(UHFTag));
@@ -9,6 +26,14 @@ UHFTag* uhf_tag_alloc() {
     return uhf_tag;
 }
 
+void uhf_tag_reset(UHFTag* uhf_tag) {
+    uhf_tag->epc->crc = 0;
+    uhf_tag->epc->pc = 0;
+    uhf_tag->epc->size = 0;
+    uhf_tag->tid->size = 0;
+    uhf_tag->user->size = 0;
+}
+
 void uhf_tag_free(UHFTag* uhf_tag) {
     free(uhf_tag->reserved);
     free(uhf_tag->epc);
@@ -17,18 +42,15 @@ void uhf_tag_free(UHFTag* uhf_tag) {
     free(uhf_tag);
 }
 
-UHFTagWrapper* uhf_tag_wrapper_alloc(){
-    UHFTagWrapper* uhf_tag_wrapper = (UHFTagWrapper*)malloc(sizeof(UHFTagWrapper));
-    uhf_tag_wrapper->uhf_tag = NULL;
-    return uhf_tag_wrapper;
+void uhf_tag_set_epc_pc(UHFTag* uhf_tag, uint16_t pc) {
+    uhf_tag->epc->pc = pc;
 }
 
-void uhf_tag_wrapper_set_tag(UHFTagWrapper* uhf_tag_wrapper, UHFTag* uhf_tag){
-    uhf_tag_wrapper->uhf_tag = uhf_tag;
+void uhf_tag_set_epc_crc(UHFTag* uhf_tag, uint16_t crc) {
+    uhf_tag->epc->crc = crc;
 }
 
-void uhf_tag_wrapper_free(UHFTagWrapper* uhf_tag_wrapper){
-    if(uhf_tag_wrapper->uhf_tag != NULL)
-        uhf_tag_free(uhf_tag_wrapper->uhf_tag);
-    free(uhf_tag_wrapper);
+void uhf_tag_set_epc(UHFTag* uhf_tag, uint8_t* data_in, size_t size) {
+    memcpy(uhf_tag->epc->data, data_in, size);
+    uhf_tag->epc->size = size;
 }

+ 6 - 2
uhf_tag.h

@@ -4,6 +4,9 @@
 #include <stdbool.h>
 #include <stddef.h>
 
+// storage enum
+typedef enum { ReservedBank, EPCBank, TIDBank, UserBank } BankType;
+
 // Reserved Memory Bank
 typedef struct {
     uint8_t kill_password[2]; // 2 bytes (16 bits) for kill password
@@ -38,15 +41,16 @@ typedef struct {
     UserMemoryBank* user;
 } UHFTag;
 
-typedef struct UHFTagWrapper{
+typedef struct UHFTagWrapper {
     UHFTag* uhf_tag;
-}UHFTagWrapper;
+} UHFTagWrapper;
 
 UHFTagWrapper* uhf_tag_wrapper_alloc();
 void uhf_tag_wrapper_set_tag(UHFTagWrapper* uhf_tag_wrapper, UHFTag* uhf_tag);
 void uhf_tag_wrapper_free(UHFTagWrapper* uhf_tag_wrapper);
 
 UHFTag* uhf_tag_alloc();
+void uhf_tag_reset(UHFTag* uhf_tag);
 void uhf_tag_free(UHFTag* uhf_tag);
 
 void uhf_tag_set_kill_pwd(UHFTag* uhf_tag, uint8_t* data_in);

+ 156 - 182
uhf_worker.c

@@ -3,11 +3,15 @@
 
 // yrm100 module commands
 UHFWorkerEvent verify_module_connected(UHFWorker* uhf_worker) {
+    // FuriString* ts = furi_string_alloc();
     char* hw_version = m100_get_hardware_version(uhf_worker->module);
     char* sw_version = m100_get_software_version(uhf_worker->module);
     char* manufacturer = m100_get_manufacturers(uhf_worker->module);
     // verify all data exists
     if(hw_version == NULL || sw_version == NULL || manufacturer == NULL) return UHFWorkerEventFail;
+    FURI_LOG_E("TAG", "hw=%s", hw_version);
+    FURI_LOG_E("TAG", "sw=%s", sw_version);
+    FURI_LOG_E("TAG", "mf=%s", manufacturer);
     return UHFWorkerEventSuccess;
 }
 
@@ -17,82 +21,44 @@ uint8_t get_epc_length_in_bits(uint8_t pc) {
     return (uint8_t)epc_length * 16; // x-words * 16 bits
 }
 
-bool send_set_select_command(UHFData* selected_tag, UHFBank bank) {
-    bool success = false;
-    // Set select
-    UHFData* select_cmd = uhf_data_alloc();
-    select_cmd->start = true;
-    select_cmd->length = CMD_SET_SELECT_PARAMETER.length;
-    memcpy((void*)&select_cmd->data, (void*)&CMD_SET_SELECT_PARAMETER.cmd[0], select_cmd->length);
-    // set select param
-    size_t mask_length_bits = (size_t)get_epc_length_in_bits(selected_tag->data[6]);
-    size_t mask_length_bytes = (size_t)mask_length_bits / 8;
-    select_cmd->data[5] = bank; // 0x00=rfu, 0x01=epc, 0x10=tid, 0x11=user
-    // set ptr
-    select_cmd->data[9] = 0x20; // epc data begins after 0x20
-    // set mask length
-    select_cmd->data[10] = mask_length_bits;
-    // set mask starting position
-    select_cmd->length = 12;
-    // set mask
-    for(size_t i = 0; i < mask_length_bytes; i++) {
-        uhf_data_append(select_cmd, selected_tag->data[8 + i]);
-    }
-    uhf_data_append(select_cmd, 0x00); // add checksum section
-    uhf_data_append(select_cmd, FRAME_END); // command end
-    // add checksum
-    select_cmd->data[select_cmd->length - 2] = uhf_data_calculate_checksum(select_cmd);
-    UHFData* select_response = uhf_data_alloc();
-    furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, module_rx_callback, select_response);
-    furi_hal_uart_tx(FuriHalUartIdUSART1, select_cmd->data, select_cmd->length);
-    furi_delay_ms(CB_DELAY);
-
-    success = select_response->data[5] == 0x00;
-
-    uhf_data_free(select_cmd);
-    uhf_data_free(select_response);
-
-    return success;
-}
-
-bool read_bank(UHFData* read_bank_cmd, UHFData* response_bank, UHFBank bank) {
-    furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, module_rx_callback, response_bank);
-    read_bank_cmd->data[9] = bank;
-    read_bank_cmd->data[read_bank_cmd->length - 2] = uhf_data_calculate_checksum(read_bank_cmd);
-    uhf_data_reset(response_bank);
-    furi_hal_uart_tx(FuriHalUartIdUSART1, read_bank_cmd->data, read_bank_cmd->length);
-    furi_delay_ms(CB_DELAY);
-    return response_bank->data[2] == read_bank_cmd->data[2];
-}
-
-bool write_bank(UHFData* write_bank_cmd, UHFBank bank, uint8_t* bank_data, size_t bank_len) {
-    UHFData* rp_data = uhf_data_alloc();
-    write_bank_cmd->end = false;
-    for(size_t i = 0; i < write_bank_cmd->length; i++) {
-        continue;
-    }
-    furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, module_rx_callback, rp_data);
-    for(int i = 5; i < 9; i++) { // no access password for now
-        write_bank_cmd->data[i] = 0;
-    }
-    write_bank_cmd->data[9] = bank;
-    size_t word_len = bank_len / 2;
-    write_bank_cmd->data[13] = word_len;
-    write_bank_cmd->length = 14;
-    write_bank_cmd->start = true;
-    for(size_t i = 0; i < bank_len; i++) {
-        uhf_data_append(write_bank_cmd, bank_data[i]);
-    }
-    uhf_data_append(write_bank_cmd, 00);
-    uhf_data_append(write_bank_cmd, FRAME_END);
-    write_bank_cmd->data[4] = write_bank_cmd->length - 7;
-    write_bank_cmd->data[write_bank_cmd->length - 2] = uhf_data_calculate_checksum(write_bank_cmd);
-    furi_hal_uart_tx(FuriHalUartIdUSART1, write_bank_cmd->data, write_bank_cmd->length);
-    furi_delay_ms(CB_DELAY);
-    bool success = rp_data->data[2] == write_bank_cmd->data[2];
-    uhf_data_free(rp_data);
-    return success;
-}
+// bool read_bank(UHFData* read_bank_cmd, UHFData* response_bank, UHFBank bank) {
+//     furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, module_rx_callback, response_bank);
+//     read_bank_cmd->data[9] = bank;
+//     read_bank_cmd->data[read_bank_cmd->length - 2] = uhf_data_calculate_checksum(read_bank_cmd);
+//     uhf_data_reset(response_bank);
+//     furi_hal_uart_tx(FuriHalUartIdUSART1, read_bank_cmd->data, read_bank_cmd->length);
+//     furi_delay_ms(CB_DELAY);
+//     return response_bank->data[2] == read_bank_cmd->data[2];
+// }
+
+// bool write_bank(UHFData* write_bank_cmd, UHFBank bank, uint8_t* bank_data, size_t bank_len) {
+//     UHFData* rp_data = uhf_data_alloc();
+//     write_bank_cmd->end = false;
+//     for(size_t i = 0; i < write_bank_cmd->length; i++) {
+//         continue;
+//     }
+//     furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, module_rx_callback, rp_data);
+//     for(int i = 5; i < 9; i++) { // no access password for now
+//         write_bank_cmd->data[i] = 0;
+//     }
+//     write_bank_cmd->data[9] = bank;
+//     size_t word_len = bank_len / 2;
+//     write_bank_cmd->data[13] = word_len;
+//     write_bank_cmd->length = 14;
+//     write_bank_cmd->start = true;
+//     for(size_t i = 0; i < bank_len; i++) {
+//         uhf_data_append(write_bank_cmd, bank_data[i]);
+//     }
+//     uhf_data_append(write_bank_cmd, 00);
+//     uhf_data_append(write_bank_cmd, FRAME_END);
+//     write_bank_cmd->data[4] = write_bank_cmd->length - 7;
+//     write_bank_cmd->data[write_bank_cmd->length - 2] = uhf_data_calculate_checksum(write_bank_cmd);
+//     furi_hal_uart_tx(FuriHalUartIdUSART1, write_bank_cmd->data, write_bank_cmd->length);
+//     furi_delay_ms(CB_DELAY);
+//     bool success = rp_data->data[2] == write_bank_cmd->data[2];
+//     uhf_data_free(rp_data);
+//     return success;
+// }
 
 UHFTag* send_polling_command(UHFWorker* uhf_worker) {
     // read epc bank
@@ -105,121 +71,128 @@ UHFTag* send_polling_command(UHFWorker* uhf_worker) {
         }
         if(uhf_tag != NULL) break;
     }
-
     return uhf_tag;
 }
 
 UHFWorkerEvent read_single_card(UHFWorker* uhf_worker) {
-
-    UHFTag*
-
-    // todo : rfu ?
-    UHFTag* uhf_tag = uhf_worker->uhf_tag;
-    uhf_tag_reset(uhf_tag);
-
+    UHFTag* uhf_tag = send_polling_command(uhf_worker);
+    if(uhf_tag == NULL) return UHFWorkerEventAborted;
+    uhf_tag_wrapper_set_tag(uhf_worker->uhf_tag_wrapper, uhf_tag);
+    // Todo : set select here
+    bool select_success = m100_set_select(uhf_worker->module, uhf_tag);
+    FURI_LOG_E("TAG", "select success = %d", select_success);
+
+    // Todo : read rfu
+    m100_read_label_data_storage(uhf_worker->module, uhf_tag, ReservedBank, 0);
+    // Todo : read epc
+    m100_read_label_data_storage(uhf_worker->module, uhf_tag, EPCBank, 0);
+    // Todo : read tid
+    m100_read_label_data_storage(uhf_worker->module, uhf_tag, TIDBank, 0);
+    // Todo : read user
+    m100_read_label_data_storage(uhf_worker->module, uhf_tag, UserBank, 0);
     // add to tag object
-    UHFData* raw_bank_data = uhf_data_alloc();
-    size_t epc_length = (size_t)get_epc_length_in_bits(raw_read_data->data[6]) / 8;
-    size_t offset = (size_t)(8 + epc_length);
-
-    UHFData* read_bank_cmd = uhf_data_alloc();
-    read_bank_cmd->length = CMD_READ_LABEL_DATA_STORAGE.length;
-    memcpy(
-        (void*)&read_bank_cmd->data[0],
-        (void*)&CMD_READ_LABEL_DATA_STORAGE.cmd[0],
-        read_bank_cmd->length);
-
-    if(!send_set_select_command(raw_read_data, EPC_BANK)) return UHFWorkerEventFail;
-
-    int retry = 3;
-    do {
-        if(read_bank(read_bank_cmd, raw_bank_data, EPC_BANK)) {
-            uhf_tag_set_epc(uhf_tag, raw_bank_data->data + offset, epc_length + 2);
-            break;
-        }
-
-    } while(retry--);
-    // // debug
-    // furi_string_reset(temp_str);
-    // for(size_t i = 0; i < raw_bank_data->length; i++) {
-    //     furi_string_cat_printf(temp_str, "%02x ", raw_bank_data->data[i]);
-    // }
-    // FURI_LOG_E("TAG", "data = %s", furi_string_get_cstr(temp_str));
-    // // e-debug
-    uhf_data_reset(raw_bank_data);
-    retry = 3;
-    do {
-        if(read_bank(read_bank_cmd, raw_bank_data, TID_BANK)) {
-            uhf_tag_set_tid(uhf_tag, raw_bank_data->data + offset, 16);
-            break;
-        }
-    } while(retry--);
-    // // debug
-    // furi_string_reset(temp_str);
-    // for(size_t i = 0; i < raw_bank_data->length; i++) {
-    //     furi_string_cat_printf(temp_str, "%02x ", raw_bank_data->data[i]);
+    // UHFData* raw_bank_data = uhf_data_alloc();
+    // size_t epc_length = (size_t)get_epc_length_in_bits(raw_read_data->data[6]) / 8;
+    // size_t offset = (size_t)(8 + epc_length);
+
+    // UHFData* read_bank_cmd = uhf_data_alloc();
+    // read_bank_cmd->length = CMD_READ_LABEL_DATA_STORAGE.length;
+    // memcpy(
+    //     (void*)&read_bank_cmd->data[0],
+    //     (void*)&CMD_READ_LABEL_DATA_STORAGE.cmd[0],
+    //     read_bank_cmd->length);
+
+    // if(!send_set_select_command(raw_read_data, EPC_BANK)) return UHFWorkerEventFail;
+
+    // int retry = 3;
+    // do {
+    //     if(read_bank(read_bank_cmd, raw_bank_data, EPC_BANK)) {
+    //         uhf_tag_set_epc(uhf_tag, raw_bank_data->data + offset, epc_length + 2);
+    //         break;
+    //     }
+
+    // } while(retry--);
+    // // // debug
+    // // furi_string_reset(temp_str);
+    // // for(size_t i = 0; i < raw_bank_data->length; i++) {
+    // //     furi_string_cat_printf(temp_str, "%02x ", raw_bank_data->data[i]);
+    // // }
+    // // FURI_LOG_E("TAG", "data = %s", furi_string_get_cstr(temp_str));
+    // // // e-debug
+    // uhf_data_reset(raw_bank_data);
+    // retry = 3;
+    // do {
+    //     if(read_bank(read_bank_cmd, raw_bank_data, TID_BANK)) {
+    //         uhf_tag_set_tid(uhf_tag, raw_bank_data->data + offset, 16);
+    //         break;
+    //     }
+    // } while(retry--);
+    // // // debug
+    // // furi_string_reset(temp_str);
+    // // for(size_t i = 0; i < raw_bank_data->length; i++) {
+    // //     furi_string_cat_printf(temp_str, "%02x ", raw_bank_data->data[i]);
+    // // }
+    // // FURI_LOG_E("TAG", "data = %s", furi_string_get_cstr(temp_str));
+    // // // e-debug
+    // uhf_data_reset(raw_bank_data);
+    // retry = 3;
+    // if(raw_read_data->data[6] & 0x04) {
+    //     do {
+    //         if(read_bank(read_bank_cmd, raw_bank_data, USER_BANK)) {
+    //             uhf_tag_set_user(uhf_tag, raw_bank_data->data + offset, 16);
+    //             break;
+    //         }
+    //     } while(retry--);
     // }
-    // FURI_LOG_E("TAG", "data = %s", furi_string_get_cstr(temp_str));
-    // // e-debug
-    uhf_data_reset(raw_bank_data);
-    retry = 3;
-    if(raw_read_data->data[6] & 0x04) {
-        do {
-            if(read_bank(read_bank_cmd, raw_bank_data, USER_BANK)) {
-                uhf_tag_set_user(uhf_tag, raw_bank_data->data + offset, 16);
-                break;
-            }
-        } while(retry--);
-    }
+    // // // debug
+    // // furi_string_reset(temp_str);
+    // // for(size_t i = 0; i < raw_bank_data->length; i++) {
+    // //     furi_string_cat_printf(temp_str, "%02x ", raw_bank_data->data[i]);
+    // // }
+    // // FURI_LOG_E("TAG", "data = %s", furi_string_get_cstr(temp_str));
+    // // // e-debug
+    // uhf_data_reset(raw_bank_data);
+    // uhf_data_free(raw_bank_data);
+    // uhf_data_free(read_bank_cmd);
     // // debug
-    // furi_string_reset(temp_str);
-    // for(size_t i = 0; i < raw_bank_data->length; i++) {
-    //     furi_string_cat_printf(temp_str, "%02x ", raw_bank_data->data[i]);
-    // }
-    // FURI_LOG_E("TAG", "data = %s", furi_string_get_cstr(temp_str));
+    // // furi_string_free(temp_str);
     // // e-debug
-    uhf_data_reset(raw_bank_data);
-    uhf_data_free(raw_bank_data);
-    uhf_data_free(read_bank_cmd);
-    // debug
-    // furi_string_free(temp_str);
-    // e-debug
 
     return UHFWorkerEventSuccess;
 }
 
-UHFWorkerEvent write_single_card(UHFWorker* uhf_worker) {
-    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);
-    furi_hal_uart_set_br(FuriHalUartIdUSART1, DEFAULT_BAUD_RATE);
-
-    send_polling_command(uhf_worker, raw_read_data);
-    // todo : rfu ?
-    UHFTag* uhf_tag = uhf_worker->uhf_tag;
-
-    UHFData* write_bank_cmd = uhf_data_alloc();
-    write_bank_cmd->length = CMD_WRITE_LABEL_DATA_STORAGE.length;
-
-    memcpy(
-        (void*)&write_bank_cmd->data[0],
-        (void*)&CMD_WRITE_LABEL_DATA_STORAGE.cmd[0],
-        write_bank_cmd->length);
-    if(!send_set_select_command(raw_read_data, EPC_BANK)) return UHFWorkerEventFail;
-
-    if(raw_read_data->data[6] & 0x04) {
-        if(!write_bank(write_bank_cmd, USER_BANK, uhf_tag->user, uhf_tag->user_length))
-            return UHFWorkerEventFail;
-    }
-    uint8_t write_data[uhf_tag->epc_length + 2];
-    memcpy(&write_data, &raw_read_data->data[raw_read_data->length - 4], 2);
-    memcpy(&write_data[2], &uhf_tag->epc, uhf_tag->epc_length);
-    write_data[10] = 0xF1;
-    if(!write_bank(write_bank_cmd, EPC_BANK, write_data, uhf_tag->epc_length + 2)) {
-        return UHFWorkerEventFail;
-    }
-    return UHFWorkerEventSuccess;
-}
+// UHFWorkerEvent write_single_card(UHFWorker* uhf_worker) {
+//     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);
+//     furi_hal_uart_set_br(FuriHalUartIdUSART1, DEFAULT_BAUD_RATE);
+
+//     send_polling_command(uhf_worker, raw_read_data);
+//     // todo : rfu ?
+//     UHFTag* uhf_tag = uhf_worker->uhf_tag;
+
+//     UHFData* write_bank_cmd = uhf_data_alloc();
+//     write_bank_cmd->length = CMD_WRITE_LABEL_DATA_STORAGE.length;
+
+//     memcpy(
+//         (void*)&write_bank_cmd->data[0],
+//         (void*)&CMD_WRITE_LABEL_DATA_STORAGE.cmd[0],
+//         write_bank_cmd->length);
+//     if(!send_set_select_command(raw_read_data, EPC_BANK)) return UHFWorkerEventFail;
+
+//     if(raw_read_data->data[6] & 0x04) {
+//         if(!write_bank(write_bank_cmd, USER_BANK, uhf_tag->user, uhf_tag->user_length))
+//             return UHFWorkerEventFail;
+//     }
+//     uint8_t write_data[uhf_tag->epc_length + 2];
+//     memcpy(&write_data, &raw_read_data->data[raw_read_data->length - 4], 2);
+//     memcpy(&write_data[2], &uhf_tag->epc, uhf_tag->epc_length);
+//     write_data[10] = 0xF1;
+//     if(!write_bank(write_bank_cmd, EPC_BANK, write_data, uhf_tag->epc_length + 2)) {
+//         return UHFWorkerEventFail;
+//     }
+//     return UHFWorkerEventSuccess;
+// }
 
 int32_t uhf_worker_task(void* ctx) {
     UHFWorker* uhf_worker = ctx;
@@ -229,10 +202,11 @@ int32_t uhf_worker_task(void* ctx) {
     } else if(uhf_worker->state == UHFWorkerStateDetectSingle) {
         UHFWorkerEvent event = read_single_card(uhf_worker);
         uhf_worker->callback(event, uhf_worker->ctx);
-    } else if(uhf_worker->state == UHFWorkerStateWriteSingle) {
-        UHFWorkerEvent event = write_single_card(uhf_worker);
-        uhf_worker->callback(event, uhf_worker->ctx);
     }
+    // else if(uhf_worker->state == UHFWorkerStateWriteSingle) {
+    //     UHFWorkerEvent event = write_single_card(uhf_worker);
+    //     uhf_worker->callback(event, uhf_worker->ctx);
+    // }
     return 0;
 }