From 6e7ee5d7b276bb7e9a6dabf1599b399fa70244d1 Mon Sep 17 00:00:00 2001 From: Yukai Li Date: Mon, 30 Dec 2024 19:01:14 -0700 Subject: [PATCH] nfc: Attempt to detect MFP 2k in MFC mode --- lib/nfc/protocols/mf_classic/mf_classic.c | 8 ++++++++ lib/nfc/protocols/mf_classic/mf_classic.h | 1 + lib/nfc/protocols/mf_classic/mf_classic_poller.c | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/lib/nfc/protocols/mf_classic/mf_classic.c b/lib/nfc/protocols/mf_classic/mf_classic.c index b1c5c20c9bc..682f51799b6 100644 --- a/lib/nfc/protocols/mf_classic/mf_classic.c +++ b/lib/nfc/protocols/mf_classic/mf_classic.c @@ -38,6 +38,14 @@ static const MfClassicFeatures mf_classic_features[MfClassicTypeNum] = { .full_name = "Mifare Classic 4K", .type_name = "4K", }, + [MfClassicTypePlus2k] = + { + // TODO: need to validate whether 17 or 18 sectors are accessible + .sectors_total = 17, + .blocks_total = 544, + .full_name = "Mifare Plus 2K", + .type_name = "Plus 2K", + }, }; const NfcDeviceBase nfc_device_mf_classic = { diff --git a/lib/nfc/protocols/mf_classic/mf_classic.h b/lib/nfc/protocols/mf_classic/mf_classic.h index 6ae7a623e0b..89113d8f3d7 100644 --- a/lib/nfc/protocols/mf_classic/mf_classic.h +++ b/lib/nfc/protocols/mf_classic/mf_classic.h @@ -49,6 +49,7 @@ typedef enum { MfClassicTypeMini, MfClassicType1k, MfClassicType4k, + MfClassicTypePlus2k, MfClassicTypeNum, } MfClassicType; diff --git a/lib/nfc/protocols/mf_classic/mf_classic_poller.c b/lib/nfc/protocols/mf_classic/mf_classic_poller.c index ec37c80150e..325c8903dd5 100644 --- a/lib/nfc/protocols/mf_classic/mf_classic_poller.c +++ b/lib/nfc/protocols/mf_classic/mf_classic_poller.c @@ -134,6 +134,18 @@ NfcCommand mf_classic_poller_handler_detect_type(MfClassicPoller* instance) { instance->state = MfClassicPollerStateStart; instance->current_type_check = MfClassicType4k; FURI_LOG_D(TAG, "4K detected"); + } else { + instance->current_type_check = MfClassicTypePlus2k; + } + } else if(instance->current_type_check == MfClassicTypePlus2k) { + // Second-last block in sector 16, which may exist if said sector is not in SL3 mode + MfClassicError error = + mf_classic_poller_get_nt(instance, 66, MfClassicKeyTypeA, NULL, false); + if(error == MfClassicErrorNone) { + instance->data->type = MfClassicTypePlus2k; + instance->state = MfClassicPollerStateStart; + instance->current_type_check = MfClassicType4k; + FURI_LOG_D(TAG, "Plus 2K detected"); } else { instance->current_type_check = MfClassicType1k; }