Skip to content

Commit

Permalink
Merge pull request #771 from Willy-JL/emv-transactions-restructure
Browse files Browse the repository at this point in the history
NFC: EMV Transactions less nested, hide if unavailable
  • Loading branch information
xMasterX committed Jun 27, 2024
2 parents c93eb07 + 1d41944 commit 2b25c14
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 86 deletions.
44 changes: 35 additions & 9 deletions applications/main/nfc/helpers/protocol_support/emv/emv.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "../nfc_protocol_support_gui_common.h"
#include "../iso14443_4a/iso14443_4a_i.h"

enum {
SubmenuIndexTransactions = SubmenuIndexCommonMax,
};

static void nfc_scene_info_on_enter_emv(NfcApp* instance) {
const NfcDevice* device = instance->nfc_device;
const EmvData* data = nfc_device_get_data(device, NfcProtocolEmv);
Expand All @@ -24,11 +28,6 @@ static void nfc_scene_info_on_enter_emv(NfcApp* instance) {
furi_string_free(temp_str);
}

static void nfc_scene_more_info_on_enter_emv(NfcApp* instance) {
// Jump to advanced scene right away
scene_manager_next_scene(instance->scene_manager, NfcSceneEmvMoreInfo);
}

static NfcCommand nfc_scene_read_poller_callback_emv(NfcGenericEvent event, void* context) {
furi_assert(event.protocol == NfcProtocolEmv);

Expand All @@ -49,6 +48,20 @@ static void nfc_scene_read_on_enter_emv(NfcApp* instance) {
nfc_poller_start(instance->poller, nfc_scene_read_poller_callback_emv, instance);
}

static void nfc_scene_read_menu_on_enter_emv(NfcApp* instance) {
Submenu* submenu = instance->submenu;
const EmvData* data = nfc_device_get_data(instance->nfc_device, NfcProtocolEmv);

if(data->emv_application.active_tr > 0) {
submenu_add_item(
submenu,
"Transactions",
SubmenuIndexTransactions,
nfc_protocol_support_common_submenu_callback,
instance);
}
}

static void nfc_scene_read_success_on_enter_emv(NfcApp* instance) {
const NfcDevice* device = instance->nfc_device;
const EmvData* data = nfc_device_get_data(device, NfcProtocolEmv);
Expand All @@ -64,8 +77,21 @@ static void nfc_scene_read_success_on_enter_emv(NfcApp* instance) {
furi_string_free(temp_str);
}

static bool nfc_scene_read_menu_on_event_emv(NfcApp* instance, SceneManagerEvent event) {
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexTransactions) {
scene_manager_next_scene(instance->scene_manager, NfcSceneEmvTransactions);
consumed = true;
}
}

return consumed;
}

const NfcProtocolSupportBase nfc_protocol_support_emv = {
.features = NfcProtocolFeatureMoreInfo,
.features = NfcProtocolFeatureNone,

.scene_info =
{
Expand All @@ -74,7 +100,7 @@ const NfcProtocolSupportBase nfc_protocol_support_emv = {
},
.scene_more_info =
{
.on_enter = nfc_scene_more_info_on_enter_emv,
.on_enter = nfc_protocol_support_common_on_enter_empty,
.on_event = nfc_protocol_support_common_on_event_empty,
},
.scene_read =
Expand All @@ -84,8 +110,8 @@ const NfcProtocolSupportBase nfc_protocol_support_emv = {
},
.scene_read_menu =
{
.on_enter = nfc_protocol_support_common_on_enter_empty,
.on_event = nfc_protocol_support_common_on_event_empty,
.on_enter = nfc_scene_read_menu_on_enter_emv,
.on_event = nfc_scene_read_menu_on_event_emv,
},
.scene_read_success =
{
Expand Down
2 changes: 1 addition & 1 deletion applications/main/nfc/scenes/nfc_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ADD_SCENE(nfc, felica_unlock_warn, FelicaUnlockWarn)
ADD_SCENE(nfc, mf_desfire_more_info, MfDesfireMoreInfo)
ADD_SCENE(nfc, mf_desfire_app, MfDesfireApp)

ADD_SCENE(nfc, emv_more_info, EmvMoreInfo)
ADD_SCENE(nfc, emv_transactions, EmvTransactions)

ADD_SCENE(nfc, mf_classic_dict_attack, MfClassicDictAttack)
ADD_SCENE(nfc, mf_classic_detect_reader, MfClassicDetectReader)
Expand Down
76 changes: 0 additions & 76 deletions applications/main/nfc/scenes/nfc_scene_emv_more_info.c

This file was deleted.

31 changes: 31 additions & 0 deletions applications/main/nfc/scenes/nfc_scene_emv_transactions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "../nfc_app_i.h"

#include "../helpers/protocol_support/nfc_protocol_support_gui_common.h"
#include "../helpers/protocol_support/emv/emv_render.h"

void nfc_scene_emv_transactions_on_enter(void* context) {
NfcApp* nfc = context;
Widget* widget = nfc->widget;
const EmvData* data = nfc_device_get_data(nfc->nfc_device, NfcProtocolEmv);

FuriString* temp_str = furi_string_alloc();
nfc_render_emv_transactions(&data->emv_application, temp_str);

widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));

furi_string_free(temp_str);

view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
}

bool nfc_scene_emv_transactions_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
UNUSED(event);
return false;
}

void nfc_scene_emv_transactions_on_exit(void* context) {
NfcApp* nfc = context;

widget_reset(nfc->widget);
}

0 comments on commit 2b25c14

Please sign in to comment.