Skip to content

Commit

Permalink
[FL-3857] NFC Ultralight Original write support (#3718)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gornekich authored Jun 17, 2024
1 parent 039faf0 commit 729db7f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lib/nfc/helpers/nfc_data_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
10 changes: 6 additions & 4 deletions lib/nfc/protocols/mf_ultralight/mf_ultralight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/nfc/protocols/mf_ultralight/mf_ultralight.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef enum {
} MfUltralightError;

typedef enum {
MfUltralightTypeUnknown,
MfUltralightTypeOrigin,
MfUltralightTypeNTAG203,
MfUltralightTypeMfulC,
MfUltralightTypeUL11,
Expand Down
17 changes: 7 additions & 10 deletions lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion targets/f18/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -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,,
Expand Down
2 changes: 1 addition & 1 deletion targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -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,,
Expand Down

0 comments on commit 729db7f

Please sign in to comment.