Skip to content

Commit ac72f33

Browse files
gornekichskotopes
andauthored
NFC Magic: update with latest API (#167)
Co-authored-by: あく <alleteam@gmail.com>
1 parent 46f6b2f commit ac72f33

File tree

7 files changed

+23
-16
lines changed

7 files changed

+23
-16
lines changed

nfc_magic/.catalog/changelog.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
## 1.4
1+
## 1.6
2+
- Rework with new bit lib API
23

4+
## 1.5
35
- Fix incorrect max sector configuration
46

57
## 1.4
6-
78
- Auth with password option moved into new submenu "Gen4 actions"
89
- New function: Get gen4 card revision
910
- New function: Get gen4 card config (shows only when debug ON)

nfc_magic/application.fam

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ App(
1010
],
1111
stack_size=4 * 1024,
1212
fap_description="Application for writing to NFC tags with modifiable sector 0",
13-
fap_version="1.5",
13+
fap_version="1.6",
1414
fap_icon="assets/125_10px.png",
1515
fap_category="NFC",
1616
fap_private_libs=[

nfc_magic/lib/magic/protocols/gen4/gen4_poller.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ NfcCommand gen4_poller_detect_callback(NfcGenericEvent event, void* context) {
9191
do {
9292
bit_buffer_append_byte(gen4_poller_detect_ctx->tx_buffer, GEN4_CMD_PREFIX);
9393
uint8_t pwd_arr[4] = {};
94-
nfc_util_num2bytes(gen4_poller_detect_ctx->password, COUNT_OF(pwd_arr), pwd_arr);
94+
bit_lib_num_to_bytes_be(gen4_poller_detect_ctx->password, COUNT_OF(pwd_arr), pwd_arr);
9595
bit_buffer_append_bytes(gen4_poller_detect_ctx->tx_buffer, pwd_arr, COUNT_OF(pwd_arr));
9696
bit_buffer_append_byte(gen4_poller_detect_ctx->tx_buffer, GEN4_CMD_GET_CFG);
9797

@@ -432,7 +432,7 @@ NfcCommand gen4_poller_write_handler(Gen4Poller* instance) {
432432

433433
memcpy(instance->config, gen4_poller_default_config, sizeof(gen4_poller_default_config));
434434
uint8_t password_arr[4] = {};
435-
nfc_util_num2bytes(instance->password, sizeof(password_arr), password_arr);
435+
bit_lib_num_to_bytes_be(instance->password, sizeof(password_arr), password_arr);
436436
memcpy(&instance->config[2], password_arr, sizeof(password_arr));
437437
memset(&instance->config[7], 0, 17);
438438
if(instance->protocol == NfcProtocolMfClassic) {

nfc_magic/lib/magic/protocols/gen4/gen4_poller_i.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "bit_buffer.h"
44
#include "core/log.h"
55
#include <nfc/protocols/iso14443_3a/iso14443_3a_poller.h>
6-
#include <nfc/helpers/nfc_util.h>
76

87
#define GEN4_CMD_PREFIX (0xCF)
98

@@ -37,7 +36,7 @@ Gen4PollerError
3736

3837
do {
3938
uint8_t password_arr[4] = {};
40-
nfc_util_num2bytes(password, COUNT_OF(password_arr), password_arr);
39+
bit_lib_num_to_bytes_be(password, COUNT_OF(password_arr), password_arr);
4140
bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
4241
bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
4342
bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_GET_CFG);
@@ -69,7 +68,7 @@ Gen4PollerError
6968

7069
do {
7170
uint8_t password_arr[4] = {};
72-
nfc_util_num2bytes(password, COUNT_OF(password_arr), password_arr);
71+
bit_lib_num_to_bytes_be(password, COUNT_OF(password_arr), password_arr);
7372
bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
7473
bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
7574
bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_GET_REVISION);
@@ -104,7 +103,7 @@ Gen4PollerError gen4_poller_set_config(
104103

105104
do {
106105
uint8_t password_arr[4] = {};
107-
nfc_util_num2bytes(password, COUNT_OF(password_arr), password_arr);
106+
bit_lib_num_to_bytes_be(password, COUNT_OF(password_arr), password_arr);
108107
bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
109108
bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
110109
uint8_t fuse_config = fuse ? GEN4_CMD_FUSE_CFG : GEN4_CMD_SET_CFG;
@@ -139,7 +138,7 @@ Gen4PollerError gen4_poller_write_block(
139138

140139
do {
141140
uint8_t password_arr[4] = {};
142-
nfc_util_num2bytes(password, COUNT_OF(password_arr), password_arr);
141+
bit_lib_num_to_bytes_be(password, COUNT_OF(password_arr), password_arr);
143142
bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
144143
bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
145144
bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_WRITE);
@@ -171,12 +170,12 @@ Gen4PollerError
171170

172171
do {
173172
uint8_t password_arr[4] = {};
174-
nfc_util_num2bytes(pwd_current, COUNT_OF(password_arr), password_arr);
173+
bit_lib_num_to_bytes_be(pwd_current, COUNT_OF(password_arr), password_arr);
175174
bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_PREFIX);
176175
bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
177176

178177
bit_buffer_append_byte(instance->tx_buffer, GEN4_CMD_SET_PWD);
179-
nfc_util_num2bytes(pwd_new, COUNT_OF(password_arr), password_arr);
178+
bit_lib_num_to_bytes_be(pwd_new, COUNT_OF(password_arr), password_arr);
180179
bit_buffer_append_bytes(instance->tx_buffer, password_arr, COUNT_OF(password_arr));
181180

182181
Iso14443_3aError error = iso14443_3a_poller_send_standard_frame(

nfc_magic/lib/magic/protocols/gen4/gen4_poller_i.h

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "gen4_poller.h"
44
#include <nfc/nfc_poller.h>
55
#include <nfc/protocols/iso14443_3a/iso14443_3a_poller.h>
6+
#include <bit_lib/bit_lib.h>
67

78
#define TAG "Gen4Poller"
89

nfc_magic/scenes/nfc_magic_scene_key_input.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "../nfc_magic_app_i.h"
22

3-
#include <nfc/helpers/nfc_util.h>
3+
#include <bit_lib/bit_lib.h>
44

55
void nfc_magic_scene_key_input_byte_input_callback(void* context) {
66
NfcMagicApp* instance = context;
@@ -32,11 +32,11 @@ bool nfc_magic_scene_key_input_on_event(void* context, SceneManagerEvent event)
3232
if(event.type == SceneManagerEventTypeCustom) {
3333
if(event.event == NfcMagicAppCustomEventByteInputDone) {
3434
if(scene_manager_has_previous_scene(instance->scene_manager, NfcMagicSceneGen4Menu)) {
35-
instance->gen4_password_new = nfc_util_bytes2num(
35+
instance->gen4_password_new = bit_lib_bytes_to_num_be(
3636
instance->byte_input_store, NFC_MAGIC_APP_BYTE_INPUT_STORE_SIZE);
3737
scene_manager_next_scene(instance->scene_manager, NfcMagicSceneChangeKey);
3838
} else {
39-
instance->gen4_password = nfc_util_bytes2num(
39+
instance->gen4_password = bit_lib_bytes_to_num_be(
4040
instance->byte_input_store, NFC_MAGIC_APP_BYTE_INPUT_STORE_SIZE);
4141
scene_manager_next_scene(instance->scene_manager, NfcMagicSceneCheck);
4242
}

nfc_magic/scenes/nfc_magic_scene_not_magic.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ void nfc_magic_scene_not_magic_on_enter(void* context) {
1616
widget_add_string_element(
1717
widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "This is wrong card");
1818
widget_add_string_multiline_element(
19-
widget, 4, 17, AlignLeft, AlignTop, FontSecondary, "Not magic or unsupported\ncard. Only Gen1 and \nGen4 UMC cards supported.");
19+
widget,
20+
4,
21+
17,
22+
AlignLeft,
23+
AlignTop,
24+
FontSecondary,
25+
"Not magic or unsupported\ncard. Only Gen1 and \nGen4 UMC cards supported.");
2026
widget_add_button_element(
2127
widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_not_magic_widget_callback, instance);
2228

0 commit comments

Comments
 (0)