From 729db7fa98d60f34c805ca3cd3f957ad4fa7a66e Mon Sep 17 00:00:00 2001 From: gornekich Date: Mon, 17 Jun 2024 15:20:35 +0100 Subject: [PATCH] [FL-3857] NFC Ultralight Original write support (#3718) * mf ultralight: rename ultralight unknown to origin * nfc app: add write to origin support for origin ultralights * mf ultralight: add orig write support on lib level * targets: bump major API version --- .../mf_ultralight/mf_ultralight.c | 2 +- lib/nfc/helpers/nfc_data_generator.c | 2 +- lib/nfc/protocols/mf_ultralight/mf_ultralight.c | 10 ++++++---- lib/nfc/protocols/mf_ultralight/mf_ultralight.h | 2 +- .../mf_ultralight/mf_ultralight_poller.c | 17 +++++++---------- targets/f18/api_symbols.csv | 2 +- targets/f7/api_symbols.csv | 2 +- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight.c b/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight.c index a3028905fc1..b55ba130e76 100644 --- a/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight.c +++ b/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight.c @@ -192,7 +192,7 @@ static void nfc_scene_read_and_saved_menu_on_enter_mf_ultralight(NfcApp* instanc } else if( data->type == MfUltralightTypeNTAG213 || data->type == MfUltralightTypeNTAG215 || data->type == MfUltralightTypeNTAG216 || data->type == MfUltralightTypeUL11 || - data->type == MfUltralightTypeUL21) { + data->type == MfUltralightTypeUL21 || data->type == MfUltralightTypeOrigin) { submenu_add_item( submenu, "Write", diff --git a/lib/nfc/helpers/nfc_data_generator.c b/lib/nfc/helpers/nfc_data_generator.c index c10e8fd946d..7914c1f7fd3 100644 --- a/lib/nfc/helpers/nfc_data_generator.c +++ b/lib/nfc/helpers/nfc_data_generator.c @@ -49,7 +49,7 @@ static void nfc_generate_mf_ul_orig(NfcDevice* nfc_device) { MfUltralightData* mfu_data = mf_ultralight_alloc(); nfc_generate_mf_ul_common(mfu_data); - mfu_data->type = MfUltralightTypeUnknown; + mfu_data->type = MfUltralightTypeOrigin; mfu_data->pages_total = 16; mfu_data->pages_read = 16; memset(&mfu_data->page[4], 0xff, sizeof(MfUltralightPage)); diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight.c b/lib/nfc/protocols/mf_ultralight/mf_ultralight.c index 6300801ab8e..1f3481c1786 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight.c +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight.c @@ -26,7 +26,7 @@ typedef struct { static const uint32_t mf_ultralight_data_format_version = 2; static const MfUltralightFeatures mf_ultralight_features[MfUltralightTypeNum] = { - [MfUltralightTypeUnknown] = + [MfUltralightTypeOrigin] = { .device_name = "Mifare Ultralight", .total_pages = 16, @@ -215,7 +215,7 @@ static const char* mf_ultralight_get_device_name_by_type(MfUltralightType type, NfcDeviceNameType name_type) { if(name_type == NfcDeviceNameTypeShort && (type == MfUltralightTypeUL11 || type == MfUltralightTypeUL21)) { - type = MfUltralightTypeUnknown; + type = MfUltralightTypeOrigin; } return mf_ultralight_features[type].device_name; @@ -512,7 +512,7 @@ Iso14443_3aData* mf_ultralight_get_base_data(const MfUltralightData* data) { MfUltralightType mf_ultralight_get_type_by_version(MfUltralightVersion* version) { furi_check(version); - MfUltralightType type = MfUltralightTypeUnknown; + MfUltralightType type = MfUltralightTypeOrigin; if(version->storage_size == 0x0B || version->storage_size == 0x00) { type = MfUltralightTypeUL11; @@ -575,12 +575,14 @@ uint8_t mf_ultralight_get_write_end_page(MfUltralightType type) { furi_assert( type == MfUltralightTypeUL11 || type == MfUltralightTypeUL21 || type == MfUltralightTypeNTAG213 || type == MfUltralightTypeNTAG215 || - type == MfUltralightTypeNTAG216); + type == MfUltralightTypeNTAG216 || type == MfUltralightTypeOrigin); uint8_t end_page = mf_ultralight_get_config_page_num(type); if(type == MfUltralightTypeNTAG213 || type == MfUltralightTypeNTAG215 || type == MfUltralightTypeNTAG216) { end_page -= 1; + } else if(type == MfUltralightTypeOrigin) { + end_page = mf_ultralight_features[type].total_pages; } return end_page; diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight.h b/lib/nfc/protocols/mf_ultralight/mf_ultralight.h index 6c6a83a1702..582e9e0e260 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight.h +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight.h @@ -48,7 +48,7 @@ typedef enum { } MfUltralightError; typedef enum { - MfUltralightTypeUnknown, + MfUltralightTypeOrigin, MfUltralightTypeNTAG203, MfUltralightTypeMfulC, MfUltralightTypeUL11, diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c index bc4ebd51559..52b445859e7 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c @@ -281,12 +281,7 @@ static NfcCommand mf_ultralight_poller_handler_check_ntag_203(MfUltralightPoller } else { FURI_LOG_D(TAG, "Original Ultralight detected"); iso14443_3a_poller_halt(instance->iso14443_3a_poller); - instance->data->type = MfUltralightTypeUnknown; - if(instance->mode == MfUltralightPollerModeWrite) { - instance->mfu_event.type = MfUltralightPollerEventTypeCardMismatch; - instance->callback(instance->general_event, instance->context); - next_state = MfUltralightPollerStateWriteFail; - } + instance->data->type = MfUltralightTypeOrigin; } instance->state = next_state; @@ -575,10 +570,12 @@ static NfcCommand mf_ultralight_poller_handler_request_write_data(MfUltralightPo break; } - if(!instance->auth_context.auth_success) { - FURI_LOG_D(TAG, "Unknown password"); - instance->mfu_event.type = MfUltralightPollerEventTypeCardLocked; - break; + if(mf_ultralight_support_feature(features, MfUltralightFeatureSupportPasswordAuth)) { + if(!instance->auth_context.auth_success) { + FURI_LOG_D(TAG, "Unknown password"); + instance->mfu_event.type = MfUltralightPollerEventTypeCardLocked; + break; + } } const MfUltralightPage staticlock_page = tag_data->page[2]; diff --git a/targets/f18/api_symbols.csv b/targets/f18/api_symbols.csv index 4b40107ce35..99c153c049d 100644 --- a/targets/f18/api_symbols.csv +++ b/targets/f18/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,65.0,, +Version,+,66.0,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt_keys_storage.h,, Header,+,applications/services/cli/cli.h,, diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index d64571963e5..b59453823a1 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,65.0,, +Version,+,66.0,, Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,