MX 1 год назад
Родитель
Сommit
fa7e0e1c9b

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

@@ -2,8 +2,8 @@
 #include "protocols/gen4/gen4_poller.h"
 #include <nfc/protocols/iso14443_3a/iso14443_3a.h>
 #include <nfc/protocols/iso14443_3a/iso14443_3a_poller.h>
-#include <nfc/helpers/nfc_util.h>
 #include <nfc/nfc_poller.h>
+#include <bit_lib.h>
 
 #define GEN4_POLLER_THREAD_FLAG_DETECTED (1U << 0)
 
@@ -89,7 +89,7 @@ NfcCommand gen4_poller_detect_callback(NfcGenericEvent event, void* context) {
         do {
             bit_buffer_append_byte(gen4_poller_detect_ctx->tx_buffer, GEN4_CMD_PREFIX);
             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_byte(gen4_poller_detect_ctx->tx_buffer, GEN4_CMD_GET_CFG);
 
@@ -434,7 +434,7 @@ NfcCommand gen4_poller_write_handler(Gen4Poller* instance) {
 
     memcpy(instance->config, gen4_poller_default_config, sizeof(gen4_poller_default_config));
     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));
     memset(&instance->config[7], 0, 17);
     if(instance->protocol == NfcProtocolMfClassic) {

+ 14 - 14
lib/magic/protocols/gen4/gen4_poller_i.c

@@ -3,7 +3,7 @@
 #include "bit_buffer.h"
 #include "protocols/gen4/gen4_poller.h"
 #include <nfc/protocols/iso14443_3a/iso14443_3a_poller.h>
-#include <nfc/helpers/nfc_util.h>
+#include <bit_lib.h>
 
 #define GEN4_CMD_PREFIX (0xCF)
 
@@ -44,7 +44,7 @@ Gen4PollerError gen4_poller_set_shadow_mode(
 
     do {
         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_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_SET_SHD_MODE);
@@ -58,7 +58,7 @@ Gen4PollerError gen4_poller_set_shadow_mode(
             break;
         }
 
-        uint16_t response = bit_buffer_get_size_bytes(instance->rx_buffer);
+        size_t response = bit_buffer_get_size_bytes(instance->rx_buffer);
 
         FURI_LOG_D(TAG, "Card response: 0x%02X, Shadow mode set: 0x%02X", response, mode);
 
@@ -81,7 +81,7 @@ Gen4PollerError gen4_poller_set_direct_write_block_0_mode(
 
     do {
         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_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_SET_DW_BLOCK_0);
@@ -94,7 +94,7 @@ Gen4PollerError gen4_poller_set_direct_write_block_0_mode(
             ret = gen4_poller_process_error(error);
             break;
         }
-        uint16_t response = bit_buffer_get_size_bytes(instance->rx_buffer);
+        size_t response = bit_buffer_get_size_bytes(instance->rx_buffer);
 
         FURI_LOG_D(
             TAG, "Card response: 0x%02X, Direct write to block 0 mode set: 0x%02X", response, mode);
@@ -116,7 +116,7 @@ Gen4PollerError
 
     do {
         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_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_GET_CFG);
@@ -131,7 +131,7 @@ Gen4PollerError
 
         size_t rx_bytes = bit_buffer_get_size_bytes(instance->rx_buffer);
 
-        if(rx_bytes != CONFIG_SIZE_MAX || rx_bytes != CONFIG_SIZE_MIN) {
+        if((rx_bytes != CONFIG_SIZE_MAX) && (rx_bytes != CONFIG_SIZE_MIN)) {
             ret = Gen4PollerErrorProtocol;
             break;
         }
@@ -148,7 +148,7 @@ Gen4PollerError
 
     do {
         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_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_GET_REVISION);
@@ -183,7 +183,7 @@ Gen4PollerError gen4_poller_set_config(
 
     do {
         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_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         uint8_t fuse_config = fuse ? GEN4_CMD_FUSE_CFG : GEN4_CMD_SET_CFG;
@@ -198,7 +198,7 @@ Gen4PollerError gen4_poller_set_config(
             break;
         }
 
-        uint16_t response = bit_buffer_get_size_bytes(instance->rx_buffer);
+        size_t response = bit_buffer_get_size_bytes(instance->rx_buffer);
 
         FURI_LOG_D(TAG, "Card response to set default config command: 0x%02X", response);
 
@@ -221,7 +221,7 @@ Gen4PollerError gen4_poller_write_block(
 
     do {
         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_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
         bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_WRITE);
@@ -253,12 +253,12 @@ Gen4PollerError
 
     do {
         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_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
 
         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));
 
         Iso14443_3aError error = iso14443_3a_poller_send_standard_frame(
@@ -269,7 +269,7 @@ Gen4PollerError
             break;
         }
 
-        uint16_t response = bit_buffer_get_size_bytes(instance->rx_buffer);
+        size_t response = bit_buffer_get_size_bytes(instance->rx_buffer);
 
         FURI_LOG_D(
             TAG,

+ 3 - 3
scenes/nfc_magic_scene_key_input.c

@@ -1,6 +1,6 @@
 #include "../nfc_magic_app_i.h"
 
-#include <nfc/helpers/nfc_util.h>
+#include <bit_lib.h>
 
 void nfc_magic_scene_key_input_byte_input_callback(void* 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.event == NfcMagicAppCustomEventByteInputDone) {
             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);
                 scene_manager_next_scene(instance->scene_manager, NfcMagicSceneChangeKey);
             } 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);
                 scene_manager_next_scene(instance->scene_manager, NfcMagicSceneCheck);
             }