Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FL-3746] Mifare Plus detection support #3607

Merged
merged 34 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7189026
Initial MFPlus draft
Astrrra Apr 17, 2024
9042009
Proper detection (WIP)
Astrrra Apr 19, 2024
83ff6fb
Mifare Plus detection done
Astrrra Apr 22, 2024
85fc0a2
Merge branch 'dev' into astra/3746-mfp-detect
Astrrra Apr 23, 2024
fb018ec
Bump F18 API
Astrrra Apr 23, 2024
2987a46
Alloc takes no arguments
Astrrra Apr 23, 2024
988b9cf
Merge branch 'dev' into astra/3746-mfp-detect
gornekich May 14, 2024
54f63e0
Fixes from code review
Astrrra May 20, 2024
cf9b090
Remove leftover logging
Astrrra May 20, 2024
915304b
Merge branch 'dev' into astra/3746-mfp-detect
Astrrra May 20, 2024
2929955
Remove stray reminder comment
Astrrra May 20, 2024
68eb196
Merge branch 'astra/3746-mfp-detect' of https://github.com/flipperdev…
Astrrra May 20, 2024
d638b9b
Merge branch 'dev' into astra/3746-mfp-detect
gornekich May 20, 2024
c8a779d
Review changes and extra logging
Astrrra May 21, 2024
514fd24
Fix atqa detection
Astrrra May 22, 2024
d3d483e
Fix incorrect comparison
Astrrra May 22, 2024
060a488
ATQA byte swap fix
Astrrra May 22, 2024
8cdb8aa
Merge branch 'dev' into astra/3746-mfp-detect
gornekich May 28, 2024
6ccbc16
mf plus: code clean up
gornekich May 29, 2024
ba00519
mf plus: remove unused code
gornekich May 29, 2024
bf41cc4
mf plus: fix read fail event handling
gornekich May 29, 2024
5f7a139
mf plus: fix return error codes
gornekich May 30, 2024
cdcff2f
Merge branch 'dev' into astra/3746-mfp-detect
gornekich May 30, 2024
fd90567
mf plus: handle load and save errors
gornekich May 30, 2024
03f2426
mf plus: assert -> check in public API funxtion
gornekich May 30, 2024
1d3ee57
Merge branch 'dev' into astra/3746-mfp-detect
skotopes Jun 1, 2024
ed05759
Bump API Symbols version
skotopes Jun 1, 2024
8decc80
Fix wrong feature mask
Astrrra Jun 3, 2024
4357a1e
Skylanders plugin separation
Astrrra Jun 5, 2024
9bcd2ec
Fix navigation
Astrrra Jun 5, 2024
6db3c0c
Merge branch 'dev' into astra/3746-mfp-detect
Astrrra Jun 5, 2024
10a6557
Merge remote-tracking branch 'origin/dev' into astra/3746-mfp-detect
skotopes Jun 8, 2024
1ad552a
Fix info box size
Astrrra Jun 10, 2024
07efa30
Merge branch 'dev' into astra/3746-mfp-detect
skotopes Jun 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include "mf_plus.h"
#include "mf_plus_render.h"

#include <nfc/protocols/mf_plus/mf_plus_poller.h>

#include "nfc/nfc_app_i.h"

#include "../nfc_protocol_support_common.h"
#include "../nfc_protocol_support_gui_common.h"
#include "../iso14443_4a/iso14443_4a_i.h"

static void nfc_scene_info_on_enter_mf_plus(NfcApp* instance) {
const NfcDevice* device = instance->nfc_device;
const MfPlusData* data = nfc_device_get_data(device, NfcProtocolMfPlus);

FuriString* temp_str = furi_string_alloc();
nfc_append_filename_string_when_present(instance, temp_str);
furi_string_cat_printf(
temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
furi_string_replace(temp_str, "Mifare", "MIFARE");
nfc_render_mf_plus_info(data, NfcProtocolFormatTypeFull, temp_str);

widget_add_text_scroll_element(
instance->widget, 0, 0, 128, 64, furi_string_get_cstr(temp_str));

furi_string_free(temp_str);
}
static NfcCommand nfc_scene_read_poller_callback_mf_plus(NfcGenericEvent event, void* context) {
furi_assert(context);
furi_assert(event.protocol == NfcProtocolMfPlus);
furi_assert(event.event_data);

NfcApp* instance = context;
const MfPlusPollerEvent* mf_plus_event = event.event_data;

NfcCommand command = NfcCommandContinue;

if(mf_plus_event->type == MfPlusPollerEventTypeReadSuccess) {
nfc_device_set_data(
instance->nfc_device, NfcProtocolMfPlus, nfc_poller_get_data(instance->poller));
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerSuccess);
command = NfcCommandStop;
} else if(mf_plus_event->type == MfPlusPollerEventTypeReadFailed) {
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerFailure);
command = NfcCommandStop;
}

return command;
}

static void nfc_scene_read_on_enter_mf_plus(NfcApp* instance) {
nfc_poller_start(instance->poller, nfc_scene_read_poller_callback_mf_plus, instance);
}

static void nfc_scene_read_success_on_enter_mf_plus(NfcApp* instance) {
const NfcDevice* device = instance->nfc_device;
const MfPlusData* data = nfc_device_get_data(device, NfcProtocolMfPlus);

FuriString* temp_str = furi_string_alloc();
furi_string_cat_printf(
temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
furi_string_replace(temp_str, "Mifare", "MIFARE");
nfc_render_mf_plus_info(data, NfcProtocolFormatTypeShort, temp_str);

widget_add_text_scroll_element(
instance->widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));

furi_string_free(temp_str);
}

static void nfc_scene_emulate_on_enter_mf_plus(NfcApp* instance) {
const Iso14443_4aData* iso14443_4a_data =
nfc_device_get_data(instance->nfc_device, NfcProtocolIso14443_4a);

instance->listener =
nfc_listener_alloc(instance->nfc, NfcProtocolIso14443_4a, iso14443_4a_data);
nfc_listener_start(
instance->listener, nfc_scene_emulate_listener_callback_iso14443_4a, instance);
}

const NfcProtocolSupportBase nfc_protocol_support_mf_plus = {
.features = NfcProtocolFeatureEmulateUid,

.scene_info =
{
.on_enter = nfc_scene_info_on_enter_mf_plus,
.on_event = nfc_protocol_support_common_on_event_empty,
},
.scene_more_info =
{
.on_enter = nfc_protocol_support_common_on_enter_empty,
.on_event = nfc_protocol_support_common_on_event_empty,
},
.scene_read =
{
.on_enter = nfc_scene_read_on_enter_mf_plus,
.on_event = nfc_protocol_support_common_on_event_empty,
},
.scene_read_menu =
{
.on_enter = nfc_protocol_support_common_on_enter_empty,
.on_event = nfc_protocol_support_common_on_event_empty,
},
.scene_read_success =
{
.on_enter = nfc_scene_read_success_on_enter_mf_plus,
.on_event = nfc_protocol_support_common_on_event_empty,
},
.scene_saved_menu =
{
.on_enter = nfc_protocol_support_common_on_enter_empty,
.on_event = nfc_protocol_support_common_on_event_empty,
},
.scene_save_name =
{
.on_enter = nfc_protocol_support_common_on_enter_empty,
.on_event = nfc_protocol_support_common_on_event_empty,
},
.scene_emulate =
{
.on_enter = nfc_scene_emulate_on_enter_mf_plus,
.on_event = nfc_protocol_support_common_on_event_empty,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include "../nfc_protocol_support_base.h"

extern const NfcProtocolSupportBase nfc_protocol_support_mf_plus;
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "mf_plus_render.h"

#include "../iso14443_4a/iso14443_4a_render.h"

void nfc_render_mf_plus_info(
const MfPlusData* data,
NfcProtocolFormatType format_type,
FuriString* str) {
nfc_render_iso14443_4a_brief(mf_plus_get_base_data(data), str);

if(format_type != NfcProtocolFormatTypeFull) return;

furi_string_cat(str, "\n\e#ISO14443-4 data");
nfc_render_iso14443_4a_extra(mf_plus_get_base_data(data), str);
}

void nfc_render_mf_plus_data(const MfPlusData* data, FuriString* str) {
nfc_render_mf_plus_version(&data->version, str);
}

void nfc_render_mf_plus_version(const MfPlusVersion* data, FuriString* str) {
furi_string_cat_printf(
str,
"%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
data->uid[0],
data->uid[1],
data->uid[2],
data->uid[3],
data->uid[4],
data->uid[5],
data->uid[6]);
furi_string_cat_printf(
str,
"hw %02x type %02x sub %02x\n"
" maj %02x min %02x\n"
" size %02x proto %02x\n",
data->hw_vendor,
data->hw_type,
data->hw_subtype,
data->hw_major,
data->hw_minor,
data->hw_storage,
data->hw_proto);
furi_string_cat_printf(
str,
"sw %02x type %02x sub %02x\n"
" maj %02x min %02x\n"
" size %02x proto %02x\n",
data->sw_vendor,
data->sw_type,
data->sw_subtype,
data->sw_major,
data->sw_minor,
data->sw_storage,
data->sw_proto);
furi_string_cat_printf(
str,
"batch %02x:%02x:%02x:%02x:%02x\n"
"week %d year %d\n",
data->batch[0],
data->batch[1],
data->batch[2],
data->batch[3],
data->batch[4],
data->prod_week,
data->prod_year);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <nfc/protocols/mf_plus/mf_plus.h>

#include "../nfc_protocol_support_render_common.h"

void nfc_render_mf_plus_info(
const MfPlusData* data,
NfcProtocolFormatType format_type,
FuriString* str);

void nfc_render_mf_plus_data(const MfPlusData* data, FuriString* str);

void nfc_render_mf_plus_version(const MfPlusVersion* data, FuriString* str);
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "felica/felica.h"
#include "mf_ultralight/mf_ultralight.h"
#include "mf_classic/mf_classic.h"
#include "mf_plus/mf_plus.h"
#include "mf_desfire/mf_desfire.h"
#include "slix/slix.h"
#include "st25tb/st25tb.h"
Expand All @@ -38,6 +39,7 @@ const NfcProtocolSupportBase* nfc_protocol_support[NfcProtocolNum] = {
[NfcProtocolFelica] = &nfc_protocol_support_felica,
[NfcProtocolMfUltralight] = &nfc_protocol_support_mf_ultralight,
[NfcProtocolMfClassic] = &nfc_protocol_support_mf_classic,
[NfcProtocolMfPlus] = &nfc_protocol_support_mf_plus,
[NfcProtocolMfDesfire] = &nfc_protocol_support_mf_desfire,
[NfcProtocolSlix] = &nfc_protocol_support_slix,
[NfcProtocolSt25tb] = &nfc_protocol_support_st25tb,
Expand Down
Loading
Loading