Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into mntm-dev
  • Loading branch information
Willy-JL committed May 1, 2024
2 parents 37e664c + 75ece9b commit 9d2b4d1
Show file tree
Hide file tree
Showing 23 changed files with 1,359 additions and 2 deletions.
121 changes: 121 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,121 @@
#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, 52, 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(event.protocol == NfcProtocolMfPlus);

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

if(mf_plus_event->type == MfPlusPollerEventTypeReadSuccess) {
nfc_device_set_data(
instance->nfc_device, NfcProtocolMfPlus, nfc_poller_get_data(instance->poller));
FURI_LOG_D(
"MFP",
"Read success: %s",
nfc_device_get_name(instance->nfc_device, NfcDeviceNameTypeFull));
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerSuccess);
return NfcCommandStop;
}

return NfcCommandContinue;
}

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 = NfcProtocolFeatureMoreInfo,

.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 "emv/emv.h"
#include "slix/slix.h"
Expand All @@ -39,6 +40,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
10 changes: 10 additions & 0 deletions lib/ibutton/protocols/dallas/protocol_ds1420.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static bool dallas_ds1420_write_blank(OneWireHost*, iButtonProtocolData*);
static void dallas_ds1420_emulate(OneWireSlave*, iButtonProtocolData*);
static bool dallas_ds1420_load(FlipperFormat*, uint32_t, iButtonProtocolData*);
static bool dallas_ds1420_save(FlipperFormat*, const iButtonProtocolData*);
static void dallas_ds1420_render_uid(FuriString*, const iButtonProtocolData*);
static void dallas_ds1420_render_brief_data(FuriString*, const iButtonProtocolData*);
static void dallas_ds1420_render_error(FuriString*, const iButtonProtocolData*);
static bool dallas_ds1420_is_data_valid(const iButtonProtocolData*);
Expand All @@ -46,6 +47,7 @@ const iButtonProtocolDallasBase ibutton_protocol_ds1420 = {
.emulate = dallas_ds1420_emulate,
.save = dallas_ds1420_save,
.load = dallas_ds1420_load,
.render_uid = dallas_ds1420_render_uid,
.render_data = NULL, /* No data to render */
.render_brief_data = dallas_ds1420_render_brief_data,
.render_error = dallas_ds1420_render_error,
Expand Down Expand Up @@ -117,12 +119,20 @@ bool dallas_ds1420_load(
return dallas_common_load_rom_data(ff, format_version, &data->rom_data);
}

void dallas_ds1420_render_uid(FuriString* result, const iButtonProtocolData* protocol_data) {
const DS1420ProtocolData* data = protocol_data;

dallas_common_render_uid(result, &data->rom_data);
}

void dallas_ds1420_render_brief_data(FuriString* result, const iButtonProtocolData* protocol_data) {
const DS1420ProtocolData* data = protocol_data;

furi_string_cat_printf(result, "ID: ");
for(size_t i = 0; i < sizeof(DallasCommonRomData); ++i) {
furi_string_cat_printf(result, "%02X ", data->rom_data.bytes[i]);
}
furi_string_cat_printf(result, "\nFamily Code: %02X\n", data->rom_data.bytes[0]);
}

void dallas_ds1420_render_error(FuriString* result, const iButtonProtocolData* protocol_data) {
Expand Down
2 changes: 2 additions & 0 deletions lib/nfc/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ env.Append(
File("protocols/iso14443_4b/iso14443_4b.h"),
File("protocols/mf_ultralight/mf_ultralight.h"),
File("protocols/mf_classic/mf_classic.h"),
File("protocols/mf_plus/mf_plus.h"),
File("protocols/mf_desfire/mf_desfire.h"),
File("protocols/emv/emv.h"),
File("protocols/slix/slix.h"),
Expand All @@ -33,6 +34,7 @@ env.Append(
File("protocols/iso14443_4b/iso14443_4b_poller.h"),
File("protocols/mf_ultralight/mf_ultralight_poller.h"),
File("protocols/mf_classic/mf_classic_poller.h"),
File("protocols/mf_plus/mf_plus_poller.h"),
File("protocols/mf_desfire/mf_desfire_poller.h"),
File("protocols/emv/emv_poller.h"),
File("protocols/st25tb/st25tb_poller.h"),
Expand Down
6 changes: 5 additions & 1 deletion lib/nfc/helpers/iso14443_4_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ bool iso14443_4_layer_decode_block(

bool ret = false;

// TODO: Fix properly! this is a very big kostyl na velosipede
// (bit_buffer_copy_right are called to copy bigger buffer into smaller buffer causing crash on furi check) issue comes iso14443_4a_poller_send_block at line 109
if(bit_buffer_get_size_bytes(output_data) < bit_buffer_get_size_bytes(output_data) - 1)
return ret;

do {
if(!bit_buffer_starts_with_byte(block_data, instance->pcb_prev)) break;
// TODO: Fix crash
bit_buffer_copy_right(output_data, block_data, 1);
ret = true;
} while(false);
Expand Down
Loading

0 comments on commit 9d2b4d1

Please sign in to comment.