Просмотр исходного кода

NFC Magic: update with latest API (#167)

Co-authored-by: あく <alleteam@gmail.com>
gornekich 1 год назад
Родитель
Сommit
15c7c2d66e

+ 3 - 2
.catalog/changelog.md

@@ -1,9 +1,10 @@
-## 1.4 
+## 1.6
+ - Rework with new bit lib API
 
 
+## 1.5
  - Fix incorrect max sector configuration
  - Fix incorrect max sector configuration
 
 
 ## 1.4 
 ## 1.4 
-
  - Auth with password option moved into new submenu "Gen4 actions"
  - Auth with password option moved into new submenu "Gen4 actions"
  - New function: Get gen4 card revision
  - New function: Get gen4 card revision
  - New function: Get gen4 card config (shows only when debug ON)
  - New function: Get gen4 card config (shows only when debug ON)

+ 1 - 1
application.fam

@@ -10,7 +10,7 @@ App(
     ],
     ],
     stack_size=4 * 1024,
     stack_size=4 * 1024,
     fap_description="Application for writing to NFC tags with modifiable sector 0",
     fap_description="Application for writing to NFC tags with modifiable sector 0",
-    fap_version="1.5",
+    fap_version="1.6",
     fap_icon="assets/125_10px.png",
     fap_icon="assets/125_10px.png",
     fap_category="NFC",
     fap_category="NFC",
     fap_private_libs=[
     fap_private_libs=[

+ 2 - 2
lib/magic/protocols/gen4/gen4_poller.c

@@ -91,7 +91,7 @@ NfcCommand gen4_poller_detect_callback(NfcGenericEvent event, void* context) {
         do {
         do {
             bit_buffer_append_byte(gen4_poller_detect_ctx->tx_buffer, GEN4_CMD_PREFIX);
             bit_buffer_append_byte(gen4_poller_detect_ctx->tx_buffer, GEN4_CMD_PREFIX);
             uint8_t pwd_arr[4] = {};
             uint8_t pwd_arr[4] = {};
-            nfc_util_num2bytes(gen4_poller_detect_ctx->password, COUNT_OF(pwd_arr), pwd_arr);
+            bit_lib_num_to_bytes_be(gen4_poller_detect_ctx->password, COUNT_OF(pwd_arr), pwd_arr);
             bit_buffer_append_bytes(gen4_poller_detect_ctx->tx_buffer, pwd_arr, COUNT_OF(pwd_arr));
             bit_buffer_append_bytes(gen4_poller_detect_ctx->tx_buffer, pwd_arr, COUNT_OF(pwd_arr));
             bit_buffer_append_byte(gen4_poller_detect_ctx->tx_buffer, GEN4_CMD_GET_CFG);
             bit_buffer_append_byte(gen4_poller_detect_ctx->tx_buffer, GEN4_CMD_GET_CFG);
 
 
@@ -432,7 +432,7 @@ NfcCommand gen4_poller_write_handler(Gen4Poller* instance) {
 
 
     memcpy(instance->config, gen4_poller_default_config, sizeof(gen4_poller_default_config));
     memcpy(instance->config, gen4_poller_default_config, sizeof(gen4_poller_default_config));
     uint8_t password_arr[4] = {};
     uint8_t password_arr[4] = {};
-    nfc_util_num2bytes(instance->password, sizeof(password_arr), password_arr);
+    bit_lib_num_to_bytes_be(instance->password, sizeof(password_arr), password_arr);
     memcpy(&instance->config[2], password_arr, sizeof(password_arr));
     memcpy(&instance->config[2], password_arr, sizeof(password_arr));
     memset(&instance->config[7], 0, 17);
     memset(&instance->config[7], 0, 17);
     if(instance->protocol == NfcProtocolMfClassic) {
     if(instance->protocol == NfcProtocolMfClassic) {

+ 6 - 7
lib/magic/protocols/gen4/gen4_poller_i.c

@@ -3,7 +3,6 @@
 #include "bit_buffer.h"
 #include "bit_buffer.h"
 #include "core/log.h"
 #include "core/log.h"
 #include <nfc/protocols/iso14443_3a/iso14443_3a_poller.h>
 #include <nfc/protocols/iso14443_3a/iso14443_3a_poller.h>
-#include <nfc/helpers/nfc_util.h>
 
 
 #define GEN4_CMD_PREFIX (0xCF)
 #define GEN4_CMD_PREFIX (0xCF)
 
 
@@ -37,7 +36,7 @@ Gen4PollerError
 
 
     do {
     do {
         uint8_t password_arr[4] = {};
         uint8_t password_arr[4] = {};
-        nfc_util_num2bytes(password, COUNT_OF(password_arr), password_arr);
+        bit_lib_num_to_bytes_be(password, COUNT_OF(password_arr), password_arr);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_GET_CFG);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_GET_CFG);
@@ -69,7 +68,7 @@ Gen4PollerError
 
 
     do {
     do {
         uint8_t password_arr[4] = {};
         uint8_t password_arr[4] = {};
-        nfc_util_num2bytes(password, COUNT_OF(password_arr), password_arr);
+        bit_lib_num_to_bytes_be(password, COUNT_OF(password_arr), password_arr);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_GET_REVISION);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_GET_REVISION);
@@ -104,7 +103,7 @@ Gen4PollerError gen4_poller_set_config(
 
 
     do {
     do {
         uint8_t password_arr[4] = {};
         uint8_t password_arr[4] = {};
-        nfc_util_num2bytes(password, COUNT_OF(password_arr), password_arr);
+        bit_lib_num_to_bytes_be(password, COUNT_OF(password_arr), password_arr);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         uint8_t fuse_config = fuse ? GEN4_CMD_FUSE_CFG : GEN4_CMD_SET_CFG;
         uint8_t fuse_config = fuse ? GEN4_CMD_FUSE_CFG : GEN4_CMD_SET_CFG;
@@ -139,7 +138,7 @@ Gen4PollerError gen4_poller_write_block(
 
 
     do {
     do {
         uint8_t password_arr[4] = {};
         uint8_t password_arr[4] = {};
-        nfc_util_num2bytes(password, COUNT_OF(password_arr), password_arr);
+        bit_lib_num_to_bytes_be(password, COUNT_OF(password_arr), password_arr);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_WRITE);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_WRITE);
@@ -171,12 +170,12 @@ Gen4PollerError
 
 
     do {
     do {
         uint8_t password_arr[4] = {};
         uint8_t password_arr[4] = {};
-        nfc_util_num2bytes(pwd_current, COUNT_OF(password_arr), password_arr);
+        bit_lib_num_to_bytes_be(pwd_current, COUNT_OF(password_arr), password_arr);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
 
 
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_SET_PWD);
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_SET_PWD);
-        nfc_util_num2bytes(pwd_new, COUNT_OF(password_arr), password_arr);
+        bit_lib_num_to_bytes_be(pwd_new, COUNT_OF(password_arr), password_arr);
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
 
 
         Iso14443_3aError error = iso14443_3a_poller_send_standard_frame(
         Iso14443_3aError error = iso14443_3a_poller_send_standard_frame(

+ 1 - 0
lib/magic/protocols/gen4/gen4_poller_i.h

@@ -3,6 +3,7 @@
 #include "gen4_poller.h"
 #include "gen4_poller.h"
 #include <nfc/nfc_poller.h>
 #include <nfc/nfc_poller.h>
 #include <nfc/protocols/iso14443_3a/iso14443_3a_poller.h>
 #include <nfc/protocols/iso14443_3a/iso14443_3a_poller.h>
+#include <bit_lib/bit_lib.h>
 
 
 #define TAG "Gen4Poller"
 #define TAG "Gen4Poller"
 
 

+ 3 - 3
scenes/nfc_magic_scene_key_input.c

@@ -1,6 +1,6 @@
 #include "../nfc_magic_app_i.h"
 #include "../nfc_magic_app_i.h"
 
 
-#include <nfc/helpers/nfc_util.h>
+#include <bit_lib/bit_lib.h>
 
 
 void nfc_magic_scene_key_input_byte_input_callback(void* context) {
 void nfc_magic_scene_key_input_byte_input_callback(void* context) {
     NfcMagicApp* instance = context;
     NfcMagicApp* instance = context;
@@ -32,11 +32,11 @@ bool nfc_magic_scene_key_input_on_event(void* context, SceneManagerEvent event)
     if(event.type == SceneManagerEventTypeCustom) {
     if(event.type == SceneManagerEventTypeCustom) {
         if(event.event == NfcMagicAppCustomEventByteInputDone) {
         if(event.event == NfcMagicAppCustomEventByteInputDone) {
             if(scene_manager_has_previous_scene(instance->scene_manager, NfcMagicSceneGen4Menu)) {
             if(scene_manager_has_previous_scene(instance->scene_manager, NfcMagicSceneGen4Menu)) {
-                instance->gen4_password_new = nfc_util_bytes2num(
+                instance->gen4_password_new = bit_lib_bytes_to_num_be(
                     instance->byte_input_store, NFC_MAGIC_APP_BYTE_INPUT_STORE_SIZE);
                     instance->byte_input_store, NFC_MAGIC_APP_BYTE_INPUT_STORE_SIZE);
                 scene_manager_next_scene(instance->scene_manager, NfcMagicSceneChangeKey);
                 scene_manager_next_scene(instance->scene_manager, NfcMagicSceneChangeKey);
             } else {
             } else {
-                instance->gen4_password = nfc_util_bytes2num(
+                instance->gen4_password = bit_lib_bytes_to_num_be(
                     instance->byte_input_store, NFC_MAGIC_APP_BYTE_INPUT_STORE_SIZE);
                     instance->byte_input_store, NFC_MAGIC_APP_BYTE_INPUT_STORE_SIZE);
                 scene_manager_next_scene(instance->scene_manager, NfcMagicSceneCheck);
                 scene_manager_next_scene(instance->scene_manager, NfcMagicSceneCheck);
             }
             }

+ 7 - 1
scenes/nfc_magic_scene_not_magic.c

@@ -16,7 +16,13 @@ void nfc_magic_scene_not_magic_on_enter(void* context) {
     widget_add_string_element(
     widget_add_string_element(
         widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "This is wrong card");
         widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "This is wrong card");
     widget_add_string_multiline_element(
     widget_add_string_multiline_element(
-        widget, 4, 17, AlignLeft, AlignTop, FontSecondary, "Not magic or unsupported\ncard. Only Gen1 and \nGen4 UMC cards supported.");
+        widget,
+        4,
+        17,
+        AlignLeft,
+        AlignTop,
+        FontSecondary,
+        "Not magic or unsupported\ncard. Only Gen1 and \nGen4 UMC cards supported.");
     widget_add_button_element(
     widget_add_button_element(
         widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_not_magic_widget_callback, instance);
         widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_not_magic_widget_callback, instance);