Skip to content

Commit 59fe896

Browse files
GMManskotopes
andauthored
nfc: Enable MFUL sync poller to be provided with passwords (#4050)
* nfc: Enable MFUL sync poller to be provided with passwords * Sync targret api versions Co-authored-by: あく <alleteam@gmail.com>
1 parent de85cc7 commit 59fe896

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

applications/debug/unit_tests/tests/nfc/nfc_test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static void mf_ultralight_reader_test(const char* path) {
262262
nfc_listener_start(mfu_listener, NULL, NULL);
263263

264264
MfUltralightData* mfu_data = mf_ultralight_alloc();
265-
MfUltralightError error = mf_ultralight_poller_sync_read_card(poller, mfu_data);
265+
MfUltralightError error = mf_ultralight_poller_sync_read_card(poller, mfu_data, NULL);
266266
mu_assert(error == MfUltralightErrorNone, "mf_ultralight_poller_sync_read_card() failed");
267267

268268
nfc_listener_stop(mfu_listener);
@@ -315,7 +315,7 @@ MU_TEST(ntag_213_locked_reader) {
315315
nfc_listener_start(mfu_listener, NULL, NULL);
316316

317317
MfUltralightData* mfu_data = mf_ultralight_alloc();
318-
MfUltralightError error = mf_ultralight_poller_sync_read_card(poller, mfu_data);
318+
MfUltralightError error = mf_ultralight_poller_sync_read_card(poller, mfu_data, NULL);
319319
mu_assert(error == MfUltralightErrorNone, "mf_ultralight_poller_sync_read_card() failed");
320320

321321
nfc_listener_stop(mfu_listener);
@@ -353,7 +353,7 @@ static void mf_ultralight_write(void) {
353353
MfUltralightData* mfu_data = mf_ultralight_alloc();
354354

355355
// Initial read
356-
MfUltralightError error = mf_ultralight_poller_sync_read_card(poller, mfu_data);
356+
MfUltralightError error = mf_ultralight_poller_sync_read_card(poller, mfu_data, NULL);
357357
mu_assert(error == MfUltralightErrorNone, "mf_ultralight_poller_sync_read_card() failed");
358358

359359
mu_assert(
@@ -371,7 +371,7 @@ static void mf_ultralight_write(void) {
371371
}
372372

373373
// Verification read
374-
error = mf_ultralight_poller_sync_read_card(poller, mfu_data);
374+
error = mf_ultralight_poller_sync_read_card(poller, mfu_data, NULL);
375375
mu_assert(error == MfUltralightErrorNone, "mf_ultralight_poller_sync_read_card() failed");
376376

377377
nfc_listener_stop(mfu_listener);

lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_sync.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef struct {
2323
FuriThreadId thread_id;
2424
MfUltralightError error;
2525
MfUltralightPollerContextData data;
26+
const MfUltralightPollerAuthContext* auth_context;
2627
} MfUltralightPollerContext;
2728

2829
typedef MfUltralightError (*MfUltralightPollerCmdHandler)(
@@ -250,12 +251,17 @@ static NfcCommand mf_ultralight_poller_read_callback(NfcGenericEvent event, void
250251
poller_context->error = mfu_event->data->error;
251252
command = NfcCommandStop;
252253
} else if(mfu_event->type == MfUltralightPollerEventTypeAuthRequest) {
253-
mfu_event->data->auth_context.skip_auth = true;
254-
if(mf_ultralight_support_feature(
255-
mfu_poller->feature_set, MfUltralightFeatureSupportAuthenticate)) {
256-
mfu_event->data->auth_context.skip_auth = false;
257-
memset(
258-
mfu_poller->auth_context.tdes_key.data, 0x00, MF_ULTRALIGHT_C_AUTH_DES_KEY_SIZE);
254+
if(poller_context->auth_context != NULL) {
255+
mfu_event->data->auth_context = *poller_context->auth_context;
256+
} else {
257+
mfu_event->data->auth_context.skip_auth = true;
258+
if(mfu_poller->data->type == MfUltralightTypeMfulC) {
259+
mfu_event->data->auth_context.skip_auth = false;
260+
memset(
261+
mfu_poller->auth_context.tdes_key.data,
262+
0x00,
263+
MF_ULTRALIGHT_C_AUTH_DES_KEY_SIZE);
264+
}
259265
}
260266
}
261267

@@ -266,13 +272,17 @@ static NfcCommand mf_ultralight_poller_read_callback(NfcGenericEvent event, void
266272
return command;
267273
}
268274

269-
MfUltralightError mf_ultralight_poller_sync_read_card(Nfc* nfc, MfUltralightData* data) {
275+
MfUltralightError mf_ultralight_poller_sync_read_card(
276+
Nfc* nfc,
277+
MfUltralightData* data,
278+
const MfUltralightPollerAuthContext* auth_context) {
270279
furi_check(nfc);
271280
furi_check(data);
272281

273282
MfUltralightPollerContext poller_context = {};
274283
poller_context.thread_id = furi_thread_get_current_id();
275284
poller_context.data.data = mf_ultralight_alloc();
285+
poller_context.auth_context = auth_context;
276286

277287
NfcPoller* poller = nfc_poller_alloc(nfc, NfcProtocolMfUltralight);
278288
nfc_poller_start(poller, mf_ultralight_poller_read_callback, &poller_context);

lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_sync.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "mf_ultralight.h"
4+
#include "mf_ultralight_poller.h"
45
#include <nfc/nfc.h>
56

67
#ifdef __cplusplus
@@ -27,7 +28,10 @@ MfUltralightError mf_ultralight_poller_sync_read_tearing_flag(
2728
uint8_t flag_num,
2829
MfUltralightTearingFlag* data);
2930

30-
MfUltralightError mf_ultralight_poller_sync_read_card(Nfc* nfc, MfUltralightData* data);
31+
MfUltralightError mf_ultralight_poller_sync_read_card(
32+
Nfc* nfc,
33+
MfUltralightData* data,
34+
const MfUltralightPollerAuthContext* auth_context);
3135

3236
#ifdef __cplusplus
3337
}

targets/f18/api_symbols.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
entry,status,name,type,params
2-
Version,+,79.3,,
2+
Version,+,80.1,,
33
Header,+,applications/services/bt/bt_service/bt.h,,
44
Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,
55
Header,+,applications/services/cli/cli.h,,

targets/f7/api_symbols.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
entry,status,name,type,params
2-
Version,+,79.3,,
2+
Version,+,80.1,,
33
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
44
Header,+,applications/services/bt/bt_service/bt.h,,
55
Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,
@@ -2681,7 +2681,7 @@ Function,+,mf_ultralight_poller_read_page_from_sector,MfUltralightError,"MfUltra
26812681
Function,+,mf_ultralight_poller_read_signature,MfUltralightError,"MfUltralightPoller*, MfUltralightSignature*"
26822682
Function,+,mf_ultralight_poller_read_tearing_flag,MfUltralightError,"MfUltralightPoller*, uint8_t, MfUltralightTearingFlag*"
26832683
Function,+,mf_ultralight_poller_read_version,MfUltralightError,"MfUltralightPoller*, MfUltralightVersion*"
2684-
Function,+,mf_ultralight_poller_sync_read_card,MfUltralightError,"Nfc*, MfUltralightData*"
2684+
Function,+,mf_ultralight_poller_sync_read_card,MfUltralightError,"Nfc*, MfUltralightData*, const MfUltralightPollerAuthContext*"
26852685
Function,+,mf_ultralight_poller_sync_read_counter,MfUltralightError,"Nfc*, uint8_t, MfUltralightCounter*"
26862686
Function,+,mf_ultralight_poller_sync_read_page,MfUltralightError,"Nfc*, uint16_t, MfUltralightPage*"
26872687
Function,+,mf_ultralight_poller_sync_read_signature,MfUltralightError,"Nfc*, MfUltralightSignature*"

0 commit comments

Comments
 (0)