[FL-1479] New NFC app (#544)
* view: add custom event callback * nfc: rework nfc worker * gui: introduce view navigator * nfc_scences: introduce nfc scenes * nfc: add start scene * lib: add C application scene template * nfc: move nfc views to separate directory * view_dispatcher: add support for view_navigator * nfc views: rework nfc views * nfc scenes: add nfc application scenes * nfc: rework nfc main thread * view_dispatcher: add separate event for search back scene * nfc: set worker result address at worker start * nfc: update read nfc scenes * view_navigator: rework with M-LIB container * view_dispatcher: check that all views were freed * nfc: add debug menu with all functions * nfc read scene: add notification on success * api-hal-nfc: add API for UID emulation * nfc: add nfc emulation UID scene * assets: add NFC assets * nfc: update read and emulate scenes UI * nfc: fix memory leak * rfal: set custom analog configuration
This commit is contained in:
@@ -1,64 +1,47 @@
|
||||
#include "nfc_i.h"
|
||||
#include "api-hal-nfc.h"
|
||||
|
||||
uint32_t nfc_view_exit(void* context) {
|
||||
return VIEW_NONE;
|
||||
}
|
||||
|
||||
void nfc_menu_callback(void* context, uint32_t index) {
|
||||
furi_assert(context);
|
||||
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
if(index == NfcSubmenuDetect) {
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewDetect);
|
||||
} else if(index == NfcSubmenuEmulate) {
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewEmulate);
|
||||
} else if(index == NfcSubmenuEMV) {
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewEmv);
|
||||
} else if(index == NfcSubmenuMifareUl) {
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMifareUl);
|
||||
}
|
||||
}
|
||||
|
||||
void nfc_view_dispatcher_callback(uint32_t event, void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
NfcMessage message;
|
||||
osMessageQueueGet(nfc->message_queue, &message, NULL, osWaitForever);
|
||||
if(event == NfcEventDetect) {
|
||||
nfc_detect_view_dispatcher_callback(nfc->nfc_detect, &message);
|
||||
} else if(event == NfcEventEmv) {
|
||||
nfc_emv_view_dispatcher_callback(nfc->nfc_emv, &message);
|
||||
} else if(event == NfcEventMifareUl) {
|
||||
nfc_mifare_ul_view_dispatcher_callback(nfc->nfc_mifare_ul, &message);
|
||||
}
|
||||
}
|
||||
#include "app_scene.h"
|
||||
|
||||
Nfc* nfc_alloc() {
|
||||
Nfc* nfc = furi_alloc(sizeof(Nfc));
|
||||
|
||||
nfc->message_queue = osMessageQueueNew(8, sizeof(NfcMessage), NULL);
|
||||
nfc->nfc_common.worker = nfc_worker_alloc(nfc->message_queue);
|
||||
nfc->nfc_common.worker = nfc_worker_alloc();
|
||||
nfc->nfc_common.view_dispatcher = view_dispatcher_alloc();
|
||||
view_dispatcher_enable_queue(nfc->nfc_common.view_dispatcher);
|
||||
view_dispatcher_enable_navigation(nfc->nfc_common.view_dispatcher, nfc);
|
||||
|
||||
// Open GUI record
|
||||
nfc->gui = furi_record_open("gui");
|
||||
view_dispatcher_attach_to_gui(
|
||||
nfc->nfc_common.view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
// Menu
|
||||
nfc->submenu = submenu_alloc();
|
||||
submenu_add_item(nfc->submenu, "Detect", NfcSubmenuDetect, nfc_menu_callback, nfc);
|
||||
submenu_add_item(nfc->submenu, "Emulate", NfcSubmenuEmulate, nfc_menu_callback, nfc);
|
||||
submenu_add_item(nfc->submenu, "Read bank card", NfcSubmenuEMV, nfc_menu_callback, nfc);
|
||||
submenu_add_item(
|
||||
nfc->submenu, "Read Mifare Ultralight", NfcSubmenuMifareUl, nfc_menu_callback, nfc);
|
||||
// Open Notification record
|
||||
nfc->notifications = furi_record_open("notification");
|
||||
|
||||
View* submenu_view = submenu_get_view(nfc->submenu);
|
||||
view_set_previous_callback(submenu_view, nfc_view_exit);
|
||||
view_dispatcher_add_view(nfc->nfc_common.view_dispatcher, NfcViewMenu, submenu_view);
|
||||
// Submenu
|
||||
nfc->submenu = submenu_alloc();
|
||||
view_dispatcher_add_view(
|
||||
nfc->nfc_common.view_dispatcher, NfcViewMenu, submenu_get_view(nfc->submenu));
|
||||
|
||||
// Dialog
|
||||
nfc->dialog_ex = dialog_ex_alloc();
|
||||
view_dispatcher_add_view(
|
||||
nfc->nfc_common.view_dispatcher, NfcViewDialogEx, dialog_ex_get_view(nfc->dialog_ex));
|
||||
|
||||
// Popup
|
||||
nfc->popup = popup_alloc();
|
||||
view_dispatcher_add_view(
|
||||
nfc->nfc_common.view_dispatcher, NfcViewPopup, popup_get_view(nfc->popup));
|
||||
|
||||
// Text Input
|
||||
nfc->text_input = text_input_alloc();
|
||||
view_dispatcher_add_view(
|
||||
nfc->nfc_common.view_dispatcher, NfcViewTextInput, text_input_get_view(nfc->text_input));
|
||||
|
||||
// Byte Input
|
||||
nfc->byte_input = byte_input_alloc();
|
||||
view_dispatcher_add_view(
|
||||
nfc->nfc_common.view_dispatcher, NfcViewByteInput, byte_input_get_view(nfc->byte_input));
|
||||
|
||||
// Detect
|
||||
nfc->nfc_detect = nfc_detect_alloc(&nfc->nfc_common);
|
||||
@@ -82,12 +65,20 @@ Nfc* nfc_alloc() {
|
||||
NfcViewMifareUl,
|
||||
nfc_mifare_ul_get_view(nfc->nfc_mifare_ul));
|
||||
|
||||
// Set View Dispatcher custom event callback
|
||||
view_dispatcher_set_custom_callback(
|
||||
nfc->nfc_common.view_dispatcher, nfc_view_dispatcher_callback, nfc);
|
||||
// Scene allocation
|
||||
nfc->scene_start = nfc_scene_start_alloc();
|
||||
nfc->scene_read_card = nfc_scene_read_card_alloc();
|
||||
nfc->scene_read_card_success = nfc_scene_read_card_success_alloc();
|
||||
nfc->scene_card_menu = nfc_scene_card_menu_alloc();
|
||||
nfc->scene_not_implemented = nfc_scene_not_implemented_alloc();
|
||||
nfc->scene_debug_menu = nfc_scene_debug_menu_alloc();
|
||||
nfc->scene_debug_detect = nfc_scene_debug_detect_alloc();
|
||||
nfc->scene_debug_emulate = nfc_scene_debug_emulate_alloc();
|
||||
nfc->scene_debug_read_emv = nfc_scene_debug_read_emv_alloc();
|
||||
nfc->scene_debug_read_mifare_ul = nfc_scene_debug_read_mifare_ul_alloc();
|
||||
nfc->scene_emulate_uid = nfc_scene_emulate_uid_alloc();
|
||||
|
||||
// Switch to menu
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_start);
|
||||
|
||||
return nfc;
|
||||
}
|
||||
@@ -99,6 +90,22 @@ void nfc_free(Nfc* nfc) {
|
||||
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
||||
submenu_free(nfc->submenu);
|
||||
|
||||
// DialogEx
|
||||
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewDialogEx);
|
||||
dialog_ex_free(nfc->dialog_ex);
|
||||
|
||||
// Popup
|
||||
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
|
||||
popup_free(nfc->popup);
|
||||
|
||||
// TextInput
|
||||
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewTextInput);
|
||||
text_input_free(nfc->text_input);
|
||||
|
||||
// ByteInput
|
||||
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewByteInput);
|
||||
byte_input_free(nfc->byte_input);
|
||||
|
||||
// Detect
|
||||
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewDetect);
|
||||
nfc_detect_free(nfc->nfc_detect);
|
||||
@@ -111,7 +118,7 @@ void nfc_free(Nfc* nfc) {
|
||||
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewEmv);
|
||||
nfc_emv_free(nfc->nfc_emv);
|
||||
|
||||
// Mifare ultralight
|
||||
// Mifare Ultralight
|
||||
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewMifareUl);
|
||||
nfc_mifare_ul_free(nfc->nfc_mifare_ul);
|
||||
|
||||
@@ -119,15 +126,30 @@ void nfc_free(Nfc* nfc) {
|
||||
nfc_worker_stop(nfc->nfc_common.worker);
|
||||
nfc_worker_free(nfc->nfc_common.worker);
|
||||
|
||||
// View dispatcher
|
||||
// Scenes
|
||||
nfc_scene_start_free(nfc->scene_start);
|
||||
nfc_scene_read_card_free(nfc->scene_read_card);
|
||||
nfc_scene_read_card_success_free(nfc->scene_read_card_success);
|
||||
nfc_scene_card_menu_free(nfc->scene_card_menu);
|
||||
nfc_scene_not_implemented_free(nfc->scene_not_implemented);
|
||||
nfc_scene_debug_menu_free(nfc->scene_debug_menu);
|
||||
nfc_scene_debug_detect_free(nfc->scene_debug_detect);
|
||||
nfc_scene_debug_emulate_free(nfc->scene_debug_emulate);
|
||||
nfc_scene_debug_read_emv_free(nfc->scene_debug_read_emv);
|
||||
nfc_scene_debug_read_mifare_ul_free(nfc->scene_debug_read_mifare_ul);
|
||||
nfc_scene_emulate_uid_free(nfc->scene_emulate_uid);
|
||||
|
||||
// View Dispatcher
|
||||
view_dispatcher_free(nfc->nfc_common.view_dispatcher);
|
||||
|
||||
// GUI
|
||||
furi_record_close("gui");
|
||||
nfc->gui = NULL;
|
||||
|
||||
// The rest
|
||||
osMessageQueueDelete(nfc->message_queue);
|
||||
// Notifications
|
||||
furi_record_close("notification");
|
||||
nfc->notifications = NULL;
|
||||
|
||||
free(nfc);
|
||||
}
|
||||
|
||||
@@ -140,3 +162,12 @@ int32_t nfc_task(void* p) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nfc_set_text_store(Nfc* nfc, const char* text, ...) {
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
|
||||
vsnprintf(nfc->text_store, sizeof(nfc->text_store), text, args);
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
@@ -56,8 +56,17 @@ void nfc_cli_emulate(Cli* cli, string_t args, void* context) {
|
||||
printf("Emulating NFC-A Type: T2T UID: CF72D440 SAK: 20 ATQA: 00/04\r\n");
|
||||
printf("Press Ctrl+C to abort\r\n");
|
||||
|
||||
NfcDeviceData params = {
|
||||
.uid = {0x36, 0x9C, 0xe7, 0xb1, 0x0A, 0xC1},
|
||||
.uid_len = 7,
|
||||
.atqa = {0x44, 0x00},
|
||||
.sak = 0x00,
|
||||
.device = NfcDeviceNfca,
|
||||
.protocol = NfcDeviceProtocolMfUltralight,
|
||||
};
|
||||
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
if(api_hal_nfc_listen(ApiHalNfcEmulateParamsMifare, 100)) {
|
||||
if(api_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, 100)) {
|
||||
printf("Reader detected\r\n");
|
||||
api_hal_nfc_deactivate();
|
||||
}
|
||||
|
@@ -10,33 +10,99 @@
|
||||
#include <gui/view.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <cli/cli.h>
|
||||
#include <notification/notification-messages.h>
|
||||
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
#include <gui/modules/popup.h>
|
||||
#include <gui/modules/text_input.h>
|
||||
#include <gui/modules/byte_input.h>
|
||||
|
||||
#include "nfc_detect.h"
|
||||
#include "nfc_emulate.h"
|
||||
#include "nfc_emv.h"
|
||||
#include "nfc_mifare_ul.h"
|
||||
#include "views/nfc_detect.h"
|
||||
#include "views/nfc_emulate.h"
|
||||
#include "views/nfc_emv.h"
|
||||
#include "views/nfc_mifare_ul.h"
|
||||
|
||||
#include "scenes/nfc_scene_start.h"
|
||||
#include "scenes/nfc_scene_read_card.h"
|
||||
#include "scenes/nfc_scene_read_card_success.h"
|
||||
#include "scenes/nfc_scene_card_menu.h"
|
||||
#include "scenes/nfc_scene_emulate_uid.h"
|
||||
#include "scenes/nfc_scene_not_implemented.h"
|
||||
|
||||
// TODO delete debug scenes
|
||||
#include "scenes/nfc_scene_debug_menu.h"
|
||||
#include "scenes/nfc_scene_debug_detect.h"
|
||||
#include "scenes/nfc_scene_debug_emulate.h"
|
||||
#include "scenes/nfc_scene_debug_read_emv.h"
|
||||
#include "scenes/nfc_scene_debug_read_mifare_ul.h"
|
||||
|
||||
#define NFC_TEXT_STORE_SIZE 128
|
||||
|
||||
struct Nfc {
|
||||
NfcCommon nfc_common;
|
||||
osMessageQueueId_t message_queue;
|
||||
Gui* gui;
|
||||
Submenu* submenu;
|
||||
NotificationApp* notifications;
|
||||
|
||||
char text_store[NFC_TEXT_STORE_SIZE + 1];
|
||||
|
||||
// Nfc Views
|
||||
NfcDetect* nfc_detect;
|
||||
NfcEmulate* nfc_emulate;
|
||||
NfcEmv* nfc_emv;
|
||||
NfcMifareUl* nfc_mifare_ul;
|
||||
|
||||
// Common Views
|
||||
Submenu* submenu;
|
||||
DialogEx* dialog_ex;
|
||||
Popup* popup;
|
||||
TextInput* text_input;
|
||||
ByteInput* byte_input;
|
||||
|
||||
// Scenes
|
||||
AppScene* scene_start;
|
||||
AppScene* scene_read_card;
|
||||
AppScene* scene_read_card_success;
|
||||
AppScene* scene_card_menu;
|
||||
AppScene* scene_not_implemented;
|
||||
AppScene* scene_emulate_uid;
|
||||
|
||||
// TODO delete debug scenes
|
||||
AppScene* scene_debug_menu;
|
||||
AppScene* scene_debug_detect;
|
||||
AppScene* scene_debug_emulate;
|
||||
AppScene* scene_debug_read_emv;
|
||||
AppScene* scene_debug_read_mifare_ul;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
NfcViewMenu,
|
||||
NfcViewDialogEx,
|
||||
NfcViewPopup,
|
||||
NfcViewTextInput,
|
||||
NfcViewByteInput,
|
||||
NfcViewDetect,
|
||||
NfcViewEmulate,
|
||||
NfcViewEmv,
|
||||
NfcViewMifareUl,
|
||||
} NfcView;
|
||||
|
||||
typedef enum {
|
||||
NfcSceneStart,
|
||||
NfcSceneReadCard,
|
||||
NfcSceneReadCardSuccess,
|
||||
NfcSceneCardMenu,
|
||||
NfcSceneEmulateUID,
|
||||
NfcSceneNotImplemented,
|
||||
NfcSceneDebugMenu,
|
||||
NfcSceneDebugDetect,
|
||||
NfcSceneDebugEmulate,
|
||||
NfcSceneDebugReadEmv,
|
||||
NfcSceneDebugReadMifareUl,
|
||||
} NfcScene;
|
||||
|
||||
Nfc* nfc_alloc();
|
||||
|
||||
int32_t nfc_task(void* p);
|
||||
|
||||
void nfc_set_text_store(Nfc* nfc, const char* text, ...);
|
||||
|
@@ -9,51 +9,9 @@
|
||||
typedef struct {
|
||||
NfcWorker* worker;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
NfcWorkerResult worker_result;
|
||||
} NfcCommon;
|
||||
|
||||
typedef enum {
|
||||
NfcDeviceNfca,
|
||||
NfcDeviceNfcb,
|
||||
NfcDeviceNfcf,
|
||||
NfcDeviceNfcv,
|
||||
} NfcDeviceType;
|
||||
|
||||
typedef enum {
|
||||
NfcDeviceProtocolUnknown,
|
||||
NfcDeviceProtocolEMV,
|
||||
NfcDeviceProtocolMfUltralight,
|
||||
} NfcProtocol;
|
||||
|
||||
typedef struct {
|
||||
uint8_t uid_len;
|
||||
uint8_t uid[10];
|
||||
uint8_t atqa[2];
|
||||
uint8_t sak;
|
||||
NfcDeviceType device;
|
||||
NfcProtocol protocol;
|
||||
} NfcDeviceData;
|
||||
|
||||
typedef struct {
|
||||
NfcDeviceData nfc_data;
|
||||
char name[32];
|
||||
uint8_t number[8];
|
||||
} NfcEmvData;
|
||||
|
||||
typedef struct {
|
||||
NfcDeviceData nfc_data;
|
||||
uint8_t man_block[12];
|
||||
uint8_t otp[4];
|
||||
} NfcMifareUlData;
|
||||
|
||||
typedef struct {
|
||||
bool found;
|
||||
union {
|
||||
NfcDeviceData nfc_detect_data;
|
||||
NfcEmvData nfc_emv_data;
|
||||
NfcMifareUlData nfc_mifare_ul_data;
|
||||
};
|
||||
} NfcMessage;
|
||||
|
||||
typedef enum {
|
||||
NfcEventDetect,
|
||||
NfcEventEmv,
|
||||
@@ -69,19 +27,17 @@ typedef enum {
|
||||
|
||||
static inline const char* nfc_get_dev_type(rfalNfcDevType type) {
|
||||
if(type == RFAL_NFC_LISTEN_TYPE_NFCA) {
|
||||
return "NFC-A";
|
||||
return "NFC-A may be:";
|
||||
} else if(type == RFAL_NFC_LISTEN_TYPE_NFCB) {
|
||||
return "NFC-B";
|
||||
return "NFC-B may be:";
|
||||
} else if(type == RFAL_NFC_LISTEN_TYPE_NFCF) {
|
||||
return "NFC-F";
|
||||
} else if(type == RFAL_NFC_LISTEN_TYPE_NFCB) {
|
||||
return "NFC-B";
|
||||
return "NFC-F may be:";
|
||||
} else if(type == RFAL_NFC_LISTEN_TYPE_NFCV) {
|
||||
return "NFC-V";
|
||||
return "NFC-V may be:";
|
||||
} else if(type == RFAL_NFC_LISTEN_TYPE_ST25TB) {
|
||||
return "NFC-ST25TB";
|
||||
return "NFC-ST25TB may be:";
|
||||
} else if(type == RFAL_NFC_LISTEN_TYPE_AP2P) {
|
||||
return "NFC-AP2P";
|
||||
return "NFC-AP2P may be:";
|
||||
} else {
|
||||
return "Unknown";
|
||||
}
|
||||
@@ -105,10 +61,10 @@ static inline const char* nfc_get_nfca_type(rfalNfcaListenDeviceType type) {
|
||||
|
||||
static inline const char* nfc_get_protocol(NfcProtocol protocol) {
|
||||
if(protocol == NfcDeviceProtocolEMV) {
|
||||
return "EMV";
|
||||
return "EMV bank card";
|
||||
} else if(protocol == NfcDeviceProtocolMfUltralight) {
|
||||
return "Mifare UL";
|
||||
return "Mifare Ultralight";
|
||||
} else {
|
||||
return "Unknown";
|
||||
return "Unrecognized";
|
||||
}
|
||||
}
|
||||
|
@@ -7,9 +7,8 @@
|
||||
|
||||
/***************************** NFC Worker API *******************************/
|
||||
|
||||
NfcWorker* nfc_worker_alloc(osMessageQueueId_t message_queue) {
|
||||
NfcWorker* nfc_worker_alloc() {
|
||||
NfcWorker* nfc_worker = furi_alloc(sizeof(NfcWorker));
|
||||
nfc_worker->message_queue = message_queue;
|
||||
// Worker thread attributes
|
||||
nfc_worker->thread_attr.name = "nfc_worker";
|
||||
nfc_worker->thread_attr.stack_size = 8192;
|
||||
@@ -40,23 +39,33 @@ ReturnCode nfc_worker_get_error(NfcWorker* nfc_worker) {
|
||||
return nfc_worker->error;
|
||||
}
|
||||
|
||||
void nfc_worker_set_emulation_params(NfcWorker* nfc_worker, NfcDeviceData* data) {
|
||||
furi_assert(nfc_worker);
|
||||
furi_assert(data);
|
||||
|
||||
nfc_worker->emulate_params = *data;
|
||||
}
|
||||
|
||||
void nfc_worker_start(
|
||||
NfcWorker* nfc_worker,
|
||||
NfcWorkerState state,
|
||||
NfcWorkerResult* result_dest,
|
||||
NfcWorkerCallback callback,
|
||||
void* context) {
|
||||
furi_assert(nfc_worker);
|
||||
furi_assert(nfc_worker->state == NfcWorkerStateReady);
|
||||
furi_assert(result_dest);
|
||||
|
||||
nfc_worker->callback = callback;
|
||||
nfc_worker->context = context;
|
||||
nfc_worker->last_result = result_dest;
|
||||
nfc_worker_change_state(nfc_worker, state);
|
||||
nfc_worker->thread = osThreadNew(nfc_worker_task, nfc_worker, &nfc_worker->thread_attr);
|
||||
}
|
||||
|
||||
void nfc_worker_stop(NfcWorker* nfc_worker) {
|
||||
furi_assert(nfc_worker);
|
||||
if(nfc_worker->state == NfcWorkerStateBroken) {
|
||||
if(nfc_worker->state == NfcWorkerStateBroken || nfc_worker->state == NfcWorkerStateReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -82,11 +91,11 @@ void nfc_worker_task(void* context) {
|
||||
} else if(nfc_worker->state == NfcWorkerStateReadEMV) {
|
||||
nfc_worker_read_emv(nfc_worker);
|
||||
} else if(nfc_worker->state == NfcWorkerStateEmulateEMV) {
|
||||
nfc_worker_field(nfc_worker);
|
||||
nfc_worker_emulate_emv(nfc_worker);
|
||||
} else if(nfc_worker->state == NfcWorkerStateReadMfUltralight) {
|
||||
nfc_worker_read_mf_ultralight(nfc_worker);
|
||||
nfc_worker_emulate_emv(nfc_worker);
|
||||
} else if(nfc_worker->state == NfcWorkerStateField) {
|
||||
nfc_worker_field(nfc_worker);
|
||||
}
|
||||
api_hal_nfc_deactivate();
|
||||
nfc_worker_change_state(nfc_worker, NfcWorkerStateReady);
|
||||
@@ -98,46 +107,50 @@ void nfc_worker_detect(NfcWorker* nfc_worker) {
|
||||
rfalNfcDevice* dev_list;
|
||||
rfalNfcDevice* dev;
|
||||
uint8_t dev_cnt;
|
||||
NfcMessage message;
|
||||
NfcDeviceData* result = &nfc_worker->last_result->nfc_detect_data;
|
||||
|
||||
while(nfc_worker->state == NfcWorkerStateDetect) {
|
||||
message.found = false;
|
||||
if(api_hal_nfc_detect(&dev_list, &dev_cnt, 1000, true)) {
|
||||
// Process first found device
|
||||
dev = &dev_list[0];
|
||||
message.found = true;
|
||||
message.nfc_detect_data.uid_len = dev->nfcidLen;
|
||||
memcpy(message.nfc_detect_data.uid, dev->nfcid, dev->nfcidLen);
|
||||
|
||||
result->uid_len = dev->nfcidLen;
|
||||
memcpy(result->uid, dev->nfcid, dev->nfcidLen);
|
||||
if(dev->type == RFAL_NFC_LISTEN_TYPE_NFCA) {
|
||||
message.nfc_detect_data.device = NfcDeviceNfca;
|
||||
message.nfc_detect_data.atqa[0] = dev->dev.nfca.sensRes.anticollisionInfo;
|
||||
message.nfc_detect_data.atqa[1] = dev->dev.nfca.sensRes.platformInfo;
|
||||
message.nfc_detect_data.sak = dev->dev.nfca.selRes.sak;
|
||||
// TODO check protocols
|
||||
result->device = NfcDeviceNfca;
|
||||
result->atqa[0] = dev->dev.nfca.sensRes.anticollisionInfo;
|
||||
result->atqa[1] = dev->dev.nfca.sensRes.platformInfo;
|
||||
result->sak = dev->dev.nfca.selRes.sak;
|
||||
if(mf_ul_check_card_type(
|
||||
dev->dev.nfca.sensRes.anticollisionInfo,
|
||||
dev->dev.nfca.sensRes.platformInfo,
|
||||
dev->dev.nfca.selRes.sak)) {
|
||||
result->protocol = NfcDeviceProtocolMfUltralight;
|
||||
} else {
|
||||
result->protocol = NfcDeviceProtocolUnknown;
|
||||
}
|
||||
|
||||
} else if(dev->type == RFAL_NFC_LISTEN_TYPE_NFCB) {
|
||||
message.nfc_detect_data.device = NfcDeviceNfcb;
|
||||
result->device = NfcDeviceNfcb;
|
||||
} else if(dev->type == RFAL_NFC_LISTEN_TYPE_NFCF) {
|
||||
message.nfc_detect_data.device = NfcDeviceNfcf;
|
||||
result->device = NfcDeviceNfcf;
|
||||
} else if(dev->type == RFAL_NFC_LISTEN_TYPE_NFCV) {
|
||||
message.nfc_detect_data.device = NfcDeviceNfcv;
|
||||
result->device = NfcDeviceNfcv;
|
||||
}
|
||||
// Notify caller and exit
|
||||
if(nfc_worker->callback) {
|
||||
nfc_worker->callback(nfc_worker->context);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(nfc_worker->callback) {
|
||||
nfc_worker->callback(nfc_worker->context);
|
||||
}
|
||||
furi_check(
|
||||
osMessageQueuePut(nfc_worker->message_queue, &message, 0, osWaitForever) == osOK);
|
||||
osDelay(100);
|
||||
}
|
||||
}
|
||||
|
||||
void nfc_worker_emulate(NfcWorker* nfc_worker) {
|
||||
NfcDeviceData* param = &nfc_worker->emulate_params;
|
||||
while(nfc_worker->state == NfcWorkerStateEmulate) {
|
||||
if(api_hal_nfc_listen(ApiHalNfcEmulateParamsMifare, 100)) {
|
||||
if(api_hal_nfc_listen(param->uid, param->uid_len, param->atqa, param->sak, 100)) {
|
||||
FURI_LOG_I(NFC_WORKER_TAG, "Reader detected");
|
||||
api_hal_nfc_deactivate();
|
||||
}
|
||||
osDelay(10);
|
||||
}
|
||||
@@ -152,14 +165,9 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) {
|
||||
uint16_t tx_len = 0;
|
||||
uint8_t* rx_buff;
|
||||
uint16_t* rx_len;
|
||||
NfcEmvData* result = &nfc_worker->last_result->nfc_emv_data;
|
||||
|
||||
NfcMessage message = {.found = false};
|
||||
while(nfc_worker->state == NfcWorkerStateReadEMV) {
|
||||
if(nfc_worker->callback) {
|
||||
nfc_worker->callback(nfc_worker->context);
|
||||
}
|
||||
furi_check(
|
||||
osMessageQueuePut(nfc_worker->message_queue, &message, 0, osWaitForever) == osOK);
|
||||
memset(&emv_app, 0, sizeof(emv_app));
|
||||
if(api_hal_nfc_detect(&dev_list, &dev_cnt, 1000, false)) {
|
||||
// Card was found. Check that it supports EMV
|
||||
@@ -169,7 +177,6 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) {
|
||||
err = api_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false);
|
||||
if(err != ERR_NONE) {
|
||||
FURI_LOG_E(NFC_WORKER_TAG, "Error during selection PPSE request: %d", err);
|
||||
message.found = false;
|
||||
api_hal_nfc_deactivate();
|
||||
continue;
|
||||
}
|
||||
@@ -179,7 +186,6 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) {
|
||||
FURI_LOG_I(NFC_WORKER_TAG, "Select PPSE responce parced");
|
||||
} else {
|
||||
FURI_LOG_E(NFC_WORKER_TAG, "Can't find pay application");
|
||||
message.found = false;
|
||||
api_hal_nfc_deactivate();
|
||||
continue;
|
||||
}
|
||||
@@ -189,7 +195,6 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) {
|
||||
if(err != ERR_NONE) {
|
||||
FURI_LOG_E(
|
||||
NFC_WORKER_TAG, "Error during application selection request: %d", err);
|
||||
message.found = false;
|
||||
api_hal_nfc_deactivate();
|
||||
continue;
|
||||
}
|
||||
@@ -198,10 +203,9 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) {
|
||||
"Select application response received. Start parsing response");
|
||||
if(emv_decode_select_app_response(rx_buff, *rx_len, &emv_app)) {
|
||||
FURI_LOG_I(NFC_WORKER_TAG, "Card name: %s", emv_app.name);
|
||||
memcpy(message.nfc_emv_data.name, emv_app.name, sizeof(emv_app.name));
|
||||
memcpy(result->name, emv_app.name, sizeof(emv_app.name));
|
||||
} else {
|
||||
FURI_LOG_E(NFC_WORKER_TAG, "Can't read card name");
|
||||
message.found = false;
|
||||
api_hal_nfc_deactivate();
|
||||
continue;
|
||||
}
|
||||
@@ -211,19 +215,17 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) {
|
||||
if(err != ERR_NONE) {
|
||||
FURI_LOG_E(
|
||||
NFC_WORKER_TAG, "Error during Get Processing Options command: %d", err);
|
||||
message.found = false;
|
||||
api_hal_nfc_deactivate();
|
||||
continue;
|
||||
}
|
||||
if(emv_decode_get_proc_opt(rx_buff, *rx_len, &emv_app)) {
|
||||
FURI_LOG_I(NFC_WORKER_TAG, "Card number parsed");
|
||||
message.found = true;
|
||||
memcpy(
|
||||
message.nfc_emv_data.number,
|
||||
emv_app.card_number,
|
||||
sizeof(emv_app.card_number));
|
||||
api_hal_nfc_deactivate();
|
||||
continue;
|
||||
memcpy(result->number, emv_app.card_number, sizeof(emv_app.card_number));
|
||||
// Notify caller and exit
|
||||
if(nfc_worker->callback) {
|
||||
nfc_worker->callback(nfc_worker->context);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
// Mastercard doesn't give PAN / card number as GPO response
|
||||
// Iterate over all files found in application
|
||||
@@ -253,27 +255,25 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) {
|
||||
}
|
||||
if(pan_found) {
|
||||
FURI_LOG_I(NFC_WORKER_TAG, "Card PAN found");
|
||||
message.found = true;
|
||||
memcpy(
|
||||
message.nfc_emv_data.number,
|
||||
emv_app.card_number,
|
||||
sizeof(emv_app.card_number));
|
||||
memcpy(result->number, emv_app.card_number, sizeof(emv_app.card_number));
|
||||
// Notify caller and exit
|
||||
if(nfc_worker->callback) {
|
||||
nfc_worker->callback(nfc_worker->context);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
FURI_LOG_E(NFC_WORKER_TAG, "Can't read card number");
|
||||
message.found = false;
|
||||
}
|
||||
api_hal_nfc_deactivate();
|
||||
}
|
||||
} else {
|
||||
// Can't find EMV card
|
||||
FURI_LOG_W(NFC_WORKER_TAG, "Card doesn't support EMV");
|
||||
message.found = false;
|
||||
api_hal_nfc_deactivate();
|
||||
}
|
||||
} else {
|
||||
// Can't find EMV card
|
||||
FURI_LOG_W(NFC_WORKER_TAG, "Can't find any cards");
|
||||
message.found = false;
|
||||
api_hal_nfc_deactivate();
|
||||
}
|
||||
osDelay(20);
|
||||
@@ -286,9 +286,17 @@ void nfc_worker_emulate_emv(NfcWorker* nfc_worker) {
|
||||
uint16_t tx_len = 0;
|
||||
uint8_t* rx_buff;
|
||||
uint16_t* rx_len;
|
||||
NfcDeviceData params = {
|
||||
.uid = {0xCF, 0x72, 0xd4, 0x40},
|
||||
.uid_len = 4,
|
||||
.atqa = {0x00, 0x04},
|
||||
.sak = 0x20,
|
||||
.device = NfcDeviceNfca,
|
||||
.protocol = NfcDeviceProtocolEMV,
|
||||
};
|
||||
|
||||
while(nfc_worker->state == NfcWorkerStateEmulateEMV) {
|
||||
if(api_hal_nfc_listen(ApiHalNfcEmulateParamsEMV, 1000)) {
|
||||
if(api_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, 100)) {
|
||||
FURI_LOG_I(NFC_WORKER_TAG, "POS terminal detected");
|
||||
// Read data from POS terminal
|
||||
err = api_hal_nfc_data_exchange(NULL, 0, &rx_buff, &rx_len, false);
|
||||
@@ -344,15 +352,9 @@ void nfc_worker_read_mf_ultralight(NfcWorker* nfc_worker) {
|
||||
uint8_t* rx_buff;
|
||||
uint16_t* rx_len;
|
||||
MfUltralightRead mf_ul_read;
|
||||
NfcMifareUlData* result = &nfc_worker->last_result->nfc_mifare_ul_data;
|
||||
|
||||
// Update screen before start searching
|
||||
NfcMessage message = {.found = false};
|
||||
while(nfc_worker->state == NfcWorkerStateReadMfUltralight) {
|
||||
if(nfc_worker->callback) {
|
||||
nfc_worker->callback(nfc_worker->context);
|
||||
}
|
||||
furi_check(
|
||||
osMessageQueuePut(nfc_worker->message_queue, &message, 0, osWaitForever) == osOK);
|
||||
api_hal_nfc_deactivate();
|
||||
memset(&mf_ul_read, 0, sizeof(mf_ul_read));
|
||||
if(api_hal_nfc_detect(&dev_list, &dev_cnt, 1000, false)) {
|
||||
@@ -383,7 +385,6 @@ void nfc_worker_read_mf_ultralight(NfcWorker* nfc_worker) {
|
||||
api_hal_nfc_deactivate();
|
||||
if(!api_hal_nfc_detect(&dev_list, &dev_cnt, 1000, false)) {
|
||||
FURI_LOG_E(NFC_WORKER_TAG, "Lost connection. Restarting search");
|
||||
message.found = false;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
@@ -391,7 +392,6 @@ void nfc_worker_read_mf_ultralight(NfcWorker* nfc_worker) {
|
||||
NFC_WORKER_TAG,
|
||||
"Error getting Mifare Ultralight version. Error code: %d",
|
||||
err);
|
||||
message.found = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -411,7 +411,6 @@ void nfc_worker_read_mf_ultralight(NfcWorker* nfc_worker) {
|
||||
mf_ul_read.pages_readed = mf_ul_read.pages_to_read;
|
||||
} else {
|
||||
FURI_LOG_E(NFC_WORKER_TAG, "Fast read failed");
|
||||
message.found = false;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
@@ -431,20 +430,15 @@ void nfc_worker_read_mf_ultralight(NfcWorker* nfc_worker) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fill message for nfc application
|
||||
message.found = true;
|
||||
message.nfc_mifare_ul_data.nfc_data.uid_len = dev_list[0].dev.nfca.nfcId1Len;
|
||||
message.nfc_mifare_ul_data.nfc_data.atqa[0] =
|
||||
dev_list[0].dev.nfca.sensRes.anticollisionInfo;
|
||||
message.nfc_mifare_ul_data.nfc_data.atqa[1] =
|
||||
dev_list[0].dev.nfca.sensRes.platformInfo;
|
||||
message.nfc_mifare_ul_data.nfc_data.sak = dev_list[0].dev.nfca.selRes.sak;
|
||||
// Fill result data
|
||||
result->nfc_data.uid_len = dev_list[0].dev.nfca.nfcId1Len;
|
||||
result->nfc_data.atqa[0] = dev_list[0].dev.nfca.sensRes.anticollisionInfo;
|
||||
result->nfc_data.atqa[1] = dev_list[0].dev.nfca.sensRes.platformInfo;
|
||||
result->nfc_data.sak = dev_list[0].dev.nfca.selRes.sak;
|
||||
memcpy(
|
||||
message.nfc_mifare_ul_data.nfc_data.uid,
|
||||
dev_list[0].dev.nfca.nfcId1,
|
||||
message.nfc_mifare_ul_data.nfc_data.uid_len);
|
||||
memcpy(message.nfc_mifare_ul_data.man_block, mf_ul_read.dump, 4 * 3);
|
||||
memcpy(message.nfc_mifare_ul_data.otp, &mf_ul_read.dump[4 * 3], 4);
|
||||
result->nfc_data.uid, dev_list[0].dev.nfca.nfcId1, result->nfc_data.uid_len);
|
||||
memcpy(result->man_block, mf_ul_read.dump, 4 * 3);
|
||||
memcpy(result->otp, &mf_ul_read.dump[4 * 3], 4);
|
||||
for(uint8_t i = 0; i < mf_ul_read.pages_readed * 4; i += 4) {
|
||||
printf("Page %2d: ", i / 4);
|
||||
for(uint8_t j = 0; j < 4; j++) {
|
||||
@@ -452,12 +446,15 @@ void nfc_worker_read_mf_ultralight(NfcWorker* nfc_worker) {
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
// Notify caller and exit
|
||||
if(nfc_worker->callback) {
|
||||
nfc_worker->callback(nfc_worker->context);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
message.found = false;
|
||||
FURI_LOG_W(NFC_WORKER_TAG, "Tag does not support Mifare Ultralight");
|
||||
}
|
||||
} else {
|
||||
message.found = false;
|
||||
FURI_LOG_W(NFC_WORKER_TAG, "Can't find any tags");
|
||||
}
|
||||
osDelay(100);
|
||||
|
@@ -1,5 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
NfcDeviceNfca,
|
||||
NfcDeviceNfcb,
|
||||
NfcDeviceNfcf,
|
||||
NfcDeviceNfcv,
|
||||
} NfcDeviceType;
|
||||
|
||||
typedef enum {
|
||||
NfcDeviceProtocolUnknown,
|
||||
NfcDeviceProtocolEMV,
|
||||
NfcDeviceProtocolMfUltralight,
|
||||
} NfcProtocol;
|
||||
|
||||
typedef struct {
|
||||
uint8_t uid_len;
|
||||
uint8_t uid[10];
|
||||
uint8_t atqa[2];
|
||||
uint8_t sak;
|
||||
NfcDeviceType device;
|
||||
NfcProtocol protocol;
|
||||
} NfcDeviceData;
|
||||
|
||||
typedef struct {
|
||||
NfcDeviceData nfc_data;
|
||||
char name[32];
|
||||
uint8_t number[8];
|
||||
} NfcEmvData;
|
||||
|
||||
typedef struct {
|
||||
NfcDeviceData nfc_data;
|
||||
uint8_t man_block[12];
|
||||
uint8_t otp[4];
|
||||
} NfcMifareUlData;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
NfcDeviceData nfc_detect_data;
|
||||
NfcEmvData nfc_emv_data;
|
||||
NfcMifareUlData nfc_mifare_ul_data;
|
||||
};
|
||||
} NfcWorkerResult;
|
||||
|
||||
typedef struct NfcWorker NfcWorker;
|
||||
|
||||
typedef enum {
|
||||
@@ -20,17 +62,20 @@ typedef enum {
|
||||
|
||||
typedef void (*NfcWorkerCallback)(void* context);
|
||||
|
||||
NfcWorker* nfc_worker_alloc(osMessageQueueId_t message_queue);
|
||||
NfcWorker* nfc_worker_alloc();
|
||||
|
||||
NfcWorkerState nfc_worker_get_state(NfcWorker* nfc_worker);
|
||||
|
||||
ReturnCode nfc_worker_get_error(NfcWorker* nfc_worker);
|
||||
|
||||
void nfc_worker_set_emulation_params(NfcWorker* nfc_worker, NfcDeviceData* data);
|
||||
|
||||
void nfc_worker_free(NfcWorker* nfc_worker);
|
||||
|
||||
void nfc_worker_start(
|
||||
NfcWorker* nfc_worker,
|
||||
NfcWorkerState state,
|
||||
NfcWorkerResult* result_dest,
|
||||
NfcWorkerCallback callback,
|
||||
void* context);
|
||||
|
||||
|
@@ -20,9 +20,10 @@ struct NfcWorker {
|
||||
osThreadAttr_t thread_attr;
|
||||
osThreadId_t thread;
|
||||
|
||||
osMessageQueueId_t message_queue;
|
||||
NfcWorkerResult* last_result;
|
||||
NfcWorkerCallback callback;
|
||||
void* context;
|
||||
NfcDeviceData emulate_params;
|
||||
|
||||
NfcWorkerState state;
|
||||
ReturnCode error;
|
||||
|
95
applications/nfc/scenes/nfc_scene_card_menu.c
Executable file
95
applications/nfc/scenes/nfc_scene_card_menu.c
Executable file
@@ -0,0 +1,95 @@
|
||||
#include "nfc_scene_card_menu.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexRunApp,
|
||||
SubmenuIndexChooseScript,
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexSave,
|
||||
} SubmenuIndex;
|
||||
|
||||
void nfc_scene_card_menu_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, index);
|
||||
}
|
||||
|
||||
const void nfc_scene_card_menu_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
Submenu* submenu = nfc->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Run compatible app",
|
||||
SubmenuIndexRunApp,
|
||||
nfc_scene_card_menu_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Additional reading scripts",
|
||||
SubmenuIndexChooseScript,
|
||||
nfc_scene_card_menu_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Emulate UID", SubmenuIndexEmulate, nfc_scene_card_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Name and save UID", SubmenuIndexSave, nfc_scene_card_menu_submenu_callback, nfc);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
||||
const bool nfc_scene_card_menu_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SubmenuIndexRunApp) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexChooseScript) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexEmulate) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_emulate_uid);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexSave) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == ViewNavigatorEventBack) {
|
||||
view_dispatcher_send_back_search_scene_event(
|
||||
nfc->nfc_common.view_dispatcher, NfcSceneStart);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_card_menu_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
submenu_clean(nfc->submenu);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_card_menu_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneCardMenu;
|
||||
scene->on_enter = nfc_scene_card_menu_on_enter;
|
||||
scene->on_event = nfc_scene_card_menu_on_event;
|
||||
scene->on_exit = nfc_scene_card_menu_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_card_menu_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_card_menu.h
Normal file
7
applications/nfc/scenes/nfc_scene_card_menu.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_card_menu_alloc();
|
||||
|
||||
void nfc_scene_card_menu_free(AppScene* scene);
|
31
applications/nfc/scenes/nfc_scene_debug_detect.c
Executable file
31
applications/nfc/scenes/nfc_scene_debug_detect.c
Executable file
@@ -0,0 +1,31 @@
|
||||
#include "nfc_scene_debug_detect.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
const void nfc_scene_debug_detect_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewDetect);
|
||||
}
|
||||
|
||||
const bool nfc_scene_debug_detect_on_event(void* context, uint32_t event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_detect_on_exit(void* context) {
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_debug_detect_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneDebugDetect;
|
||||
scene->on_enter = nfc_scene_debug_detect_on_enter;
|
||||
scene->on_event = nfc_scene_debug_detect_on_event;
|
||||
scene->on_exit = nfc_scene_debug_detect_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_debug_detect_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_debug_detect.h
Normal file
7
applications/nfc/scenes/nfc_scene_debug_detect.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_debug_detect_alloc();
|
||||
|
||||
void nfc_scene_debug_detect_free(AppScene* scene);
|
31
applications/nfc/scenes/nfc_scene_debug_emulate.c
Executable file
31
applications/nfc/scenes/nfc_scene_debug_emulate.c
Executable file
@@ -0,0 +1,31 @@
|
||||
#include "nfc_scene_debug_emulate.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
const void nfc_scene_debug_emulate_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewEmulate);
|
||||
}
|
||||
|
||||
const bool nfc_scene_debug_emulate_on_event(void* context, uint32_t event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_emulate_on_exit(void* context) {
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_debug_emulate_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneDebugEmulate;
|
||||
scene->on_enter = nfc_scene_debug_emulate_on_enter;
|
||||
scene->on_event = nfc_scene_debug_emulate_on_event;
|
||||
scene->on_exit = nfc_scene_debug_emulate_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_debug_emulate_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_debug_emulate.h
Normal file
7
applications/nfc/scenes/nfc_scene_debug_emulate.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_debug_emulate_alloc();
|
||||
|
||||
void nfc_scene_debug_emulate_free(AppScene* scene);
|
88
applications/nfc/scenes/nfc_scene_debug_menu.c
Executable file
88
applications/nfc/scenes/nfc_scene_debug_menu.c
Executable file
@@ -0,0 +1,88 @@
|
||||
#include "nfc_scene_debug_menu.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexDetect,
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexReadEmv,
|
||||
SubmenuIndexReadMifareUl,
|
||||
} SubmenuIndex;
|
||||
|
||||
void nfc_scene_debug_menu_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, index);
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_menu_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
Submenu* submenu = nfc->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Detect", SubmenuIndexDetect, nfc_scene_debug_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Emulate", SubmenuIndexEmulate, nfc_scene_debug_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Read EMV", SubmenuIndexReadEmv, nfc_scene_debug_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Read Mifare Ultralight",
|
||||
SubmenuIndexReadMifareUl,
|
||||
nfc_scene_debug_menu_submenu_callback,
|
||||
nfc);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
||||
const bool nfc_scene_debug_menu_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SubmenuIndexDetect) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_debug_detect);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexEmulate) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_debug_emulate);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexReadEmv) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_debug_read_emv);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexReadMifareUl) {
|
||||
view_dispatcher_add_scene(
|
||||
nfc->nfc_common.view_dispatcher, nfc->scene_debug_read_mifare_ul);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_menu_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
submenu_clean(nfc->submenu);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_debug_menu_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneDebugMenu;
|
||||
scene->on_enter = nfc_scene_debug_menu_on_enter;
|
||||
scene->on_event = nfc_scene_debug_menu_on_event;
|
||||
scene->on_exit = nfc_scene_debug_menu_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_debug_menu_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_debug_menu.h
Normal file
7
applications/nfc/scenes/nfc_scene_debug_menu.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_debug_menu_alloc();
|
||||
|
||||
void nfc_scene_debug_menu_free(AppScene* scene);
|
31
applications/nfc/scenes/nfc_scene_debug_read_emv.c
Executable file
31
applications/nfc/scenes/nfc_scene_debug_read_emv.c
Executable file
@@ -0,0 +1,31 @@
|
||||
#include "nfc_scene_debug_read_emv.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
const void nfc_scene_debug_read_emv_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewEmv);
|
||||
}
|
||||
|
||||
const bool nfc_scene_debug_read_emv_on_event(void* context, uint32_t event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_read_emv_on_exit(void* context) {
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_debug_read_emv_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneDebugReadEmv;
|
||||
scene->on_enter = nfc_scene_debug_read_emv_on_enter;
|
||||
scene->on_event = nfc_scene_debug_read_emv_on_event;
|
||||
scene->on_exit = nfc_scene_debug_read_emv_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_debug_read_emv_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_debug_read_emv.h
Normal file
7
applications/nfc/scenes/nfc_scene_debug_read_emv.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_debug_read_emv_alloc();
|
||||
|
||||
void nfc_scene_debug_read_emv_free(AppScene* scene);
|
31
applications/nfc/scenes/nfc_scene_debug_read_mifare_ul.c
Executable file
31
applications/nfc/scenes/nfc_scene_debug_read_mifare_ul.c
Executable file
@@ -0,0 +1,31 @@
|
||||
#include "nfc_scene_debug_read_mifare_ul.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
const void nfc_scene_debug_read_mifare_ul_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMifareUl);
|
||||
}
|
||||
|
||||
const bool nfc_scene_debug_read_mifare_ul_on_event(void* context, uint32_t event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_debug_read_mifare_ul_on_exit(void* context) {
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_debug_read_mifare_ul_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneDebugReadMifareUl;
|
||||
scene->on_enter = nfc_scene_debug_read_mifare_ul_on_enter;
|
||||
scene->on_event = nfc_scene_debug_read_mifare_ul_on_event;
|
||||
scene->on_exit = nfc_scene_debug_read_mifare_ul_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_debug_read_mifare_ul_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_debug_read_mifare_ul.h
Normal file
7
applications/nfc/scenes/nfc_scene_debug_read_mifare_ul.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_debug_read_mifare_ul_alloc();
|
||||
|
||||
void nfc_scene_debug_read_mifare_ul_free(AppScene* scene);
|
70
applications/nfc/scenes/nfc_scene_emulate_uid.c
Executable file
70
applications/nfc/scenes/nfc_scene_emulate_uid.c
Executable file
@@ -0,0 +1,70 @@
|
||||
#include <nfc/scenes/nfc_scene_emulate_uid.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
const void nfc_scene_emulate_uid_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Setup view
|
||||
Popup* popup = nfc->popup;
|
||||
NfcDeviceData* data = &nfc->nfc_common.worker_result.nfc_detect_data;
|
||||
if(data->uid_len == 4) {
|
||||
nfc_set_text_store(
|
||||
nfc, "%02X %02X %02X %02X", data->uid[0], data->uid[1], data->uid[2], data->uid[3]);
|
||||
} else if(data->uid_len == 7) {
|
||||
nfc_set_text_store(
|
||||
nfc,
|
||||
"%02X %02X %02X %02X\n%02X %02X %02X",
|
||||
data->uid[0],
|
||||
data->uid[1],
|
||||
data->uid[2],
|
||||
data->uid[3],
|
||||
data->uid[4],
|
||||
data->uid[5],
|
||||
data->uid[6]);
|
||||
}
|
||||
|
||||
popup_set_icon(popup, 0, 4, I_RFIDDolphinSend_98x60);
|
||||
popup_set_header(popup, "Emulating UID", 56, 31, AlignLeft, AlignTop);
|
||||
popup_set_text(popup, nfc->text_store, 56, 43, AlignLeft, AlignTop);
|
||||
|
||||
// Setup and start worker
|
||||
nfc_worker_set_emulation_params(
|
||||
nfc->nfc_common.worker, &nfc->nfc_common.worker_result.nfc_detect_data);
|
||||
nfc_worker_start(
|
||||
nfc->nfc_common.worker, NfcWorkerStateEmulate, &nfc->nfc_common.worker_result, NULL, nfc);
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
|
||||
}
|
||||
|
||||
const bool nfc_scene_emulate_uid_on_event(void* context, uint32_t event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_emulate_uid_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Stop worker
|
||||
nfc_worker_stop(nfc->nfc_common.worker);
|
||||
|
||||
// Clear view
|
||||
Popup* popup = nfc->popup;
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, I_Empty_1x1);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_emulate_uid_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneEmulateUID;
|
||||
scene->on_enter = nfc_scene_emulate_uid_on_enter;
|
||||
scene->on_event = nfc_scene_emulate_uid_on_event;
|
||||
scene->on_exit = nfc_scene_emulate_uid_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_emulate_uid_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_emulate_uid.h
Normal file
7
applications/nfc/scenes/nfc_scene_emulate_uid.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_emulate_uid_alloc();
|
||||
|
||||
void nfc_scene_emulate_uid_free(AppScene* scene);
|
61
applications/nfc/scenes/nfc_scene_not_implemented.c
Normal file
61
applications/nfc/scenes/nfc_scene_not_implemented.c
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "nfc_scene_not_implemented.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
void nfc_scene_not_implemented_dialog_callback(DialogExResult result, void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, result);
|
||||
}
|
||||
|
||||
const void nfc_scene_not_implemented_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// TODO Set data from worker
|
||||
DialogEx* dialog_ex = nfc->dialog_ex;
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Back");
|
||||
dialog_ex_set_header(dialog_ex, "Not implemented", 60, 24, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_context(dialog_ex, nfc);
|
||||
dialog_ex_set_result_callback(dialog_ex, nfc_scene_not_implemented_dialog_callback);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewDialogEx);
|
||||
}
|
||||
|
||||
const bool nfc_scene_not_implemented_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == DialogExResultLeft) {
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventBack);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_not_implemented_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
DialogEx* dialog_ex = nfc->dialog_ex;
|
||||
dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_result_callback(dialog_ex, NULL);
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_not_implemented_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneReadCardSuccess;
|
||||
scene->on_enter = nfc_scene_not_implemented_on_enter;
|
||||
scene->on_event = nfc_scene_not_implemented_on_event;
|
||||
scene->on_exit = nfc_scene_not_implemented_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_not_implemented_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_not_implemented.h
Normal file
7
applications/nfc/scenes/nfc_scene_not_implemented.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_not_implemented_alloc();
|
||||
|
||||
void nfc_scene_not_implemented_free(AppScene* scene);
|
70
applications/nfc/scenes/nfc_scene_read_card.c
Executable file
70
applications/nfc/scenes/nfc_scene_read_card.c
Executable file
@@ -0,0 +1,70 @@
|
||||
#include <nfc/scenes/nfc_scene_read_card.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
#include "../views/nfc_detect.h"
|
||||
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
void nfc_read_card_worker_callback(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, NfcEventDetect);
|
||||
}
|
||||
|
||||
const void nfc_scene_read_card_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Setup view
|
||||
Popup* popup = nfc->popup;
|
||||
popup_set_header(popup, "Detecting\nNFC card", 70, 34, AlignLeft, AlignTop);
|
||||
popup_set_icon(popup, 0, 4, I_RFIDDolphinReceive_98x60);
|
||||
|
||||
// Start worker
|
||||
nfc_worker_start(
|
||||
nfc->nfc_common.worker,
|
||||
NfcWorkerStateDetect,
|
||||
&nfc->nfc_common.worker_result,
|
||||
nfc_read_card_worker_callback,
|
||||
nfc);
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
|
||||
}
|
||||
|
||||
const bool nfc_scene_read_card_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == NfcEventDetect) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_read_card_success);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_read_card_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Stop worker
|
||||
nfc_worker_stop(nfc->nfc_common.worker);
|
||||
|
||||
// Clear view
|
||||
Popup* popup = nfc->popup;
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, I_Empty_1x1);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_read_card_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneReadCard;
|
||||
scene->on_enter = nfc_scene_read_card_on_enter;
|
||||
scene->on_event = nfc_scene_read_card_on_event;
|
||||
scene->on_exit = nfc_scene_read_card_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_read_card_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_read_card.h
Normal file
7
applications/nfc/scenes/nfc_scene_read_card.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_read_card_alloc();
|
||||
|
||||
void nfc_scene_read_card_free(AppScene* scene);
|
109
applications/nfc/scenes/nfc_scene_read_card_success.c
Executable file
109
applications/nfc/scenes/nfc_scene_read_card_success.c
Executable file
@@ -0,0 +1,109 @@
|
||||
#include "nfc_scene_read_card_success.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
#define NFC_SCENE_READ_SUCCESS_SHIFT " "
|
||||
|
||||
void nfc_scene_read_card_success_dialog_callback(DialogExResult result, void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, result);
|
||||
}
|
||||
|
||||
const void nfc_scene_read_card_success_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
// Send notification
|
||||
notification_message(nfc->notifications, &sequence_success);
|
||||
|
||||
// Setup view
|
||||
NfcDeviceData* data = (NfcDeviceData*)&nfc->nfc_common.worker_result;
|
||||
DialogEx* dialog_ex = nfc->dialog_ex;
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_header(dialog_ex, nfc_get_dev_type(data->device), 36, 8, AlignLeft, AlignCenter);
|
||||
dialog_ex_set_icon(dialog_ex, 8, 13, I_Medium_chip_22x21);
|
||||
// Display UID
|
||||
if(data->uid_len == 4) {
|
||||
nfc_set_text_store(
|
||||
nfc,
|
||||
NFC_SCENE_READ_SUCCESS_SHIFT "%s\n" NFC_SCENE_READ_SUCCESS_SHIFT
|
||||
"ATQA: %02X%02X SAK: %02X\nUID: %02X %02X %02X %02X",
|
||||
nfc_get_protocol(data->protocol),
|
||||
data->atqa[0],
|
||||
data->atqa[1],
|
||||
data->sak,
|
||||
data->uid[0],
|
||||
data->uid[1],
|
||||
data->uid[2],
|
||||
data->uid[3]);
|
||||
} else if(data->uid_len == 7) {
|
||||
nfc_set_text_store(
|
||||
nfc,
|
||||
NFC_SCENE_READ_SUCCESS_SHIFT
|
||||
"%s\n" NFC_SCENE_READ_SUCCESS_SHIFT
|
||||
"ATQA: %02X%02X SAK: %02X\nUID: %02X %02X %02X %02X %02X %02X %02X",
|
||||
nfc_get_protocol(data->protocol),
|
||||
data->atqa[0],
|
||||
data->atqa[1],
|
||||
data->sak,
|
||||
data->uid[0],
|
||||
data->uid[1],
|
||||
data->uid[2],
|
||||
data->uid[3],
|
||||
data->uid[4],
|
||||
data->uid[5],
|
||||
data->uid[6]);
|
||||
}
|
||||
dialog_ex_set_text(dialog_ex, nfc->text_store, 8, 16, AlignLeft, AlignTop);
|
||||
dialog_ex_set_context(dialog_ex, nfc);
|
||||
dialog_ex_set_result_callback(dialog_ex, nfc_scene_read_card_success_dialog_callback);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewDialogEx);
|
||||
}
|
||||
|
||||
const bool nfc_scene_read_card_success_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == DialogExResultLeft) {
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventBack);
|
||||
return true;
|
||||
} else if(event == DialogExResultRight) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_card_menu);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_read_card_success_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
DialogEx* dialog_ex = nfc->dialog_ex;
|
||||
dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
dialog_ex_set_icon(dialog_ex, 0, 0, I_Empty_1x1);
|
||||
dialog_ex_set_left_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_right_button_text(dialog_ex, NULL);
|
||||
dialog_ex_set_result_callback(dialog_ex, NULL);
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_read_card_success_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneReadCardSuccess;
|
||||
scene->on_enter = nfc_scene_read_card_success_on_enter;
|
||||
scene->on_event = nfc_scene_read_card_success_on_event;
|
||||
scene->on_exit = nfc_scene_read_card_success_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_read_card_success_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_read_card_success.h
Normal file
7
applications/nfc/scenes/nfc_scene_read_card_success.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_read_card_success_alloc();
|
||||
|
||||
void nfc_scene_read_card_success_free(AppScene* scene);
|
92
applications/nfc/scenes/nfc_scene_start.c
Normal file
92
applications/nfc/scenes/nfc_scene_start.c
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "nfc_scene_start.h"
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexRead,
|
||||
SubmenuIndexRunScript,
|
||||
SubmenuIndexSaved,
|
||||
SubmenuIndexAddManualy,
|
||||
SubmenuIndexDebug,
|
||||
} SubmenuIndex;
|
||||
|
||||
void nfc_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->nfc_common.view_dispatcher, index);
|
||||
}
|
||||
|
||||
const void nfc_scene_start_on_enter(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
Submenu* submenu = nfc->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Read card", SubmenuIndexRead, nfc_scene_start_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Run special action",
|
||||
SubmenuIndexRunScript,
|
||||
nfc_scene_start_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Saved cards", SubmenuIndexSaved, nfc_scene_start_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Add manualy", SubmenuIndexAddManualy, nfc_scene_start_submenu_callback, nfc);
|
||||
submenu_add_item(submenu, "Debug", SubmenuIndexDebug, nfc_scene_start_submenu_callback, nfc);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
||||
const bool nfc_scene_start_on_event(void* context, uint32_t event) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
if(event == SubmenuIndexRead) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_read_card);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexRunScript) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexSaved) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexAddManualy) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_not_implemented);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
return true;
|
||||
} else if(event == SubmenuIndexDebug) {
|
||||
view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_debug_menu);
|
||||
view_dispatcher_send_navigation_event(
|
||||
nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const void nfc_scene_start_on_exit(void* context) {
|
||||
Nfc* nfc = (Nfc*)context;
|
||||
|
||||
submenu_clean(nfc->submenu);
|
||||
}
|
||||
|
||||
AppScene* nfc_scene_start_alloc() {
|
||||
AppScene* scene = furi_alloc(sizeof(AppScene));
|
||||
scene->id = NfcSceneStart;
|
||||
scene->on_enter = nfc_scene_start_on_enter;
|
||||
scene->on_event = nfc_scene_start_on_event;
|
||||
scene->on_exit = nfc_scene_start_on_exit;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void nfc_scene_start_free(AppScene* scene) {
|
||||
free(scene);
|
||||
}
|
7
applications/nfc/scenes/nfc_scene_start.h
Normal file
7
applications/nfc/scenes/nfc_scene_start.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_scene.h"
|
||||
|
||||
AppScene* nfc_scene_start_alloc();
|
||||
|
||||
void nfc_scene_start_free(AppScene* scene);
|
@@ -1,11 +1,11 @@
|
||||
#include "nfc_detect.h"
|
||||
|
||||
#include "nfc_i.h"
|
||||
#include "nfc_types.h"
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
#include <input/input.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
struct NfcDetect {
|
||||
NfcCommon* nfc_common;
|
||||
View* view;
|
||||
@@ -64,24 +64,24 @@ void nfc_detect_worker_callback(void* context) {
|
||||
view_dispatcher_send_custom_event(nfc_detect->nfc_common->view_dispatcher, NfcEventDetect);
|
||||
}
|
||||
|
||||
void nfc_detect_view_dispatcher_callback(NfcDetect* nfc_detect, NfcMessage* message) {
|
||||
furi_assert(nfc_detect);
|
||||
furi_assert(message);
|
||||
bool nfc_detect_view_custom(uint32_t event, void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcDetect* nfc_detect = (NfcDetect*)context;
|
||||
if(event == NfcEventDetect) {
|
||||
NfcDeviceData* data = (NfcDeviceData*)&nfc_detect->nfc_common->worker_result;
|
||||
|
||||
if(message->found) {
|
||||
with_view_model(
|
||||
nfc_detect->view, (NfcDetectModel * model) {
|
||||
model->found = true;
|
||||
model->data = message->nfc_detect_data;
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
with_view_model(
|
||||
nfc_detect->view, (NfcDetectModel * model) {
|
||||
model->found = false;
|
||||
model->data = *data;
|
||||
return true;
|
||||
});
|
||||
// TODO add and configure next view model
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void nfc_detect_enter(void* context) {
|
||||
@@ -97,6 +97,7 @@ void nfc_detect_enter(void* context) {
|
||||
nfc_worker_start(
|
||||
nfc_detect->nfc_common->worker,
|
||||
NfcWorkerStateDetect,
|
||||
&nfc_detect->nfc_common->worker_result,
|
||||
nfc_detect_worker_callback,
|
||||
nfc_detect);
|
||||
}
|
||||
@@ -108,10 +109,6 @@ void nfc_detect_exit(void* context) {
|
||||
nfc_worker_stop(nfc_detect->nfc_common->worker);
|
||||
}
|
||||
|
||||
uint32_t nfc_detect_back(void* context) {
|
||||
return NfcViewMenu;
|
||||
}
|
||||
|
||||
NfcDetect* nfc_detect_alloc(NfcCommon* nfc_common) {
|
||||
furi_assert(nfc_common);
|
||||
|
||||
@@ -124,9 +121,9 @@ NfcDetect* nfc_detect_alloc(NfcCommon* nfc_common) {
|
||||
view_set_context(nfc_detect->view, nfc_detect);
|
||||
view_set_draw_callback(nfc_detect->view, (ViewDrawCallback)nfc_detect_draw);
|
||||
view_set_input_callback(nfc_detect->view, nfc_detect_input);
|
||||
view_set_custom_callback(nfc_detect->view, nfc_detect_view_custom);
|
||||
view_set_enter_callback(nfc_detect->view, nfc_detect_enter);
|
||||
view_set_exit_callback(nfc_detect->view, nfc_detect_exit);
|
||||
view_set_previous_callback(nfc_detect->view, nfc_detect_back);
|
||||
|
||||
return nfc_detect;
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "nfc_types.h"
|
||||
#include "../nfc_types.h"
|
||||
|
||||
typedef struct NfcDetect NfcDetect;
|
||||
|
||||
@@ -10,5 +10,3 @@ NfcDetect* nfc_detect_alloc(NfcCommon* nfc_common);
|
||||
void nfc_detect_free(NfcDetect* nfc_detect);
|
||||
|
||||
View* nfc_detect_get_view(NfcDetect* nfc_detect);
|
||||
|
||||
void nfc_detect_view_dispatcher_callback(NfcDetect* nfc_detect, NfcMessage* message);
|
16
applications/nfc/nfc_emulate.c → applications/nfc/views/nfc_emulate.c
Normal file → Executable file
16
applications/nfc/nfc_emulate.c → applications/nfc/views/nfc_emulate.c
Normal file → Executable file
@@ -1,11 +1,11 @@
|
||||
#include "nfc_emulate.h"
|
||||
|
||||
#include "nfc_i.h"
|
||||
#include "nfc_types.h"
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
#include <input/input.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
struct NfcEmulate {
|
||||
NfcCommon* nfc_common;
|
||||
View* view;
|
||||
@@ -33,7 +33,12 @@ void nfc_emulate_enter(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcEmulate* nfc_emulate = (NfcEmulate*)context;
|
||||
nfc_worker_start(nfc_emulate->nfc_common->worker, NfcWorkerStateEmulate, NULL, NULL);
|
||||
nfc_worker_start(
|
||||
nfc_emulate->nfc_common->worker,
|
||||
NfcWorkerStateEmulate,
|
||||
&nfc_emulate->nfc_common->worker_result,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void nfc_emulate_exit(void* context) {
|
||||
@@ -43,10 +48,6 @@ void nfc_emulate_exit(void* context) {
|
||||
nfc_worker_stop(nfc_emulate->nfc_common->worker);
|
||||
}
|
||||
|
||||
uint32_t nfc_emulate_back(void* context) {
|
||||
return NfcViewMenu;
|
||||
}
|
||||
|
||||
NfcEmulate* nfc_emulate_alloc(NfcCommon* nfc_common) {
|
||||
furi_assert(nfc_common);
|
||||
|
||||
@@ -60,7 +61,6 @@ NfcEmulate* nfc_emulate_alloc(NfcCommon* nfc_common) {
|
||||
view_set_input_callback(nfc_emulate->view, nfc_emulate_input);
|
||||
view_set_enter_callback(nfc_emulate->view, nfc_emulate_enter);
|
||||
view_set_exit_callback(nfc_emulate->view, nfc_emulate_exit);
|
||||
view_set_previous_callback(nfc_emulate->view, nfc_emulate_back);
|
||||
|
||||
return nfc_emulate;
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "nfc_types.h"
|
||||
#include "../nfc_types.h"
|
||||
|
||||
typedef struct NfcEmulate NfcEmulate;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
#include "nfc_emv.h"
|
||||
|
||||
#include "nfc_i.h"
|
||||
#include "nfc_types.h"
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
#include <input/input.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
struct NfcEmv {
|
||||
NfcCommon* nfc_common;
|
||||
View* view;
|
||||
@@ -56,24 +56,24 @@ void nfc_emv_worker_callback(void* context) {
|
||||
view_dispatcher_send_custom_event(nfc_emv->nfc_common->view_dispatcher, NfcEventEmv);
|
||||
}
|
||||
|
||||
void nfc_emv_view_dispatcher_callback(NfcEmv* nfc_emv, NfcMessage* message) {
|
||||
furi_assert(nfc_emv);
|
||||
furi_assert(message);
|
||||
bool nfc_emv_custom(uint32_t event, void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcEmv* nfc_emv = (NfcEmv*)context;
|
||||
if(event == NfcEventEmv) {
|
||||
NfcEmvData* data = (NfcEmvData*)&nfc_emv->nfc_common->worker_result;
|
||||
|
||||
if(message->found) {
|
||||
with_view_model(
|
||||
nfc_emv->view, (NfcEmvModel * model) {
|
||||
model->found = true;
|
||||
model->emv_data = message->nfc_emv_data;
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
with_view_model(
|
||||
nfc_emv->view, (NfcEmvModel * model) {
|
||||
model->found = false;
|
||||
model->emv_data = *data;
|
||||
return true;
|
||||
});
|
||||
// TODO add and configure next view model
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void nfc_emv_enter(void* context) {
|
||||
@@ -86,7 +86,11 @@ void nfc_emv_enter(void* context) {
|
||||
return true;
|
||||
});
|
||||
nfc_worker_start(
|
||||
nfc_emv->nfc_common->worker, NfcWorkerStateReadEMV, nfc_emv_worker_callback, nfc_emv);
|
||||
nfc_emv->nfc_common->worker,
|
||||
NfcWorkerStateReadEMV,
|
||||
&nfc_emv->nfc_common->worker_result,
|
||||
nfc_emv_worker_callback,
|
||||
nfc_emv);
|
||||
}
|
||||
|
||||
void nfc_emv_exit(void* context) {
|
||||
@@ -96,10 +100,6 @@ void nfc_emv_exit(void* context) {
|
||||
nfc_worker_stop(nfc_emv->nfc_common->worker);
|
||||
}
|
||||
|
||||
uint32_t nfc_emv_back(void* context) {
|
||||
return NfcViewMenu;
|
||||
}
|
||||
|
||||
NfcEmv* nfc_emv_alloc(NfcCommon* nfc_common) {
|
||||
furi_assert(nfc_common);
|
||||
|
||||
@@ -112,9 +112,9 @@ NfcEmv* nfc_emv_alloc(NfcCommon* nfc_common) {
|
||||
view_set_context(nfc_emv->view, nfc_emv);
|
||||
view_set_draw_callback(nfc_emv->view, (ViewDrawCallback)nfc_emv_draw);
|
||||
view_set_input_callback(nfc_emv->view, nfc_emv_input);
|
||||
view_set_custom_callback(nfc_emv->view, nfc_emv_custom);
|
||||
view_set_enter_callback(nfc_emv->view, nfc_emv_enter);
|
||||
view_set_exit_callback(nfc_emv->view, nfc_emv_exit);
|
||||
view_set_previous_callback(nfc_emv->view, nfc_emv_back);
|
||||
|
||||
return nfc_emv;
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "nfc_types.h"
|
||||
#include "../nfc_types.h"
|
||||
|
||||
typedef struct NfcEmv NfcEmv;
|
||||
|
||||
@@ -10,5 +10,3 @@ NfcEmv* nfc_emv_alloc(NfcCommon* nfc_common);
|
||||
void nfc_emv_free(NfcEmv* nfc_emv);
|
||||
|
||||
View* nfc_emv_get_view(NfcEmv* nfc_emv);
|
||||
|
||||
void nfc_emv_view_dispatcher_callback(NfcEmv* nfc_emv, NfcMessage* message);
|
@@ -1,11 +1,11 @@
|
||||
#include "nfc_mifare_ul.h"
|
||||
|
||||
#include "nfc_i.h"
|
||||
#include "nfc_types.h"
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
#include <input/input.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
struct NfcMifareUl {
|
||||
NfcCommon* nfc_common;
|
||||
View* view;
|
||||
@@ -85,24 +85,24 @@ void nfc_mifare_ul_worker_callback(void* context) {
|
||||
nfc_mifare_ul->nfc_common->view_dispatcher, NfcEventMifareUl);
|
||||
}
|
||||
|
||||
void nfc_mifare_ul_view_dispatcher_callback(NfcMifareUl* nfc_mifare_ul, NfcMessage* message) {
|
||||
furi_assert(nfc_mifare_ul);
|
||||
furi_assert(message);
|
||||
bool nfc_mifare_ul_custom(uint32_t event, void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcMifareUl* nfc_mifare_ul = (NfcMifareUl*)context;
|
||||
if(event == NfcEventMifareUl) {
|
||||
NfcMifareUlData* data = (NfcMifareUlData*)&nfc_mifare_ul->nfc_common->worker_result;
|
||||
|
||||
if(message->found) {
|
||||
with_view_model(
|
||||
nfc_mifare_ul->view, (NfcMifareUlModel * model) {
|
||||
model->found = true;
|
||||
model->nfc_mf_ul_data = message->nfc_mifare_ul_data;
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
with_view_model(
|
||||
nfc_mifare_ul->view, (NfcMifareUlModel * model) {
|
||||
model->found = false;
|
||||
model->nfc_mf_ul_data = *data;
|
||||
return true;
|
||||
});
|
||||
// TODO add and configure next view model
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void nfc_mifare_ul_enter(void* context) {
|
||||
@@ -117,6 +117,7 @@ void nfc_mifare_ul_enter(void* context) {
|
||||
nfc_worker_start(
|
||||
nfc_mifare_ul->nfc_common->worker,
|
||||
NfcWorkerStateReadMfUltralight,
|
||||
&nfc_mifare_ul->nfc_common->worker_result,
|
||||
nfc_mifare_ul_worker_callback,
|
||||
nfc_mifare_ul);
|
||||
}
|
||||
@@ -128,10 +129,6 @@ void nfc_mifare_ul_exit(void* context) {
|
||||
nfc_worker_stop(nfc_mifare_ul->nfc_common->worker);
|
||||
}
|
||||
|
||||
uint32_t nfc_mifare_ul_back(void* context) {
|
||||
return NfcViewMenu;
|
||||
}
|
||||
|
||||
NfcMifareUl* nfc_mifare_ul_alloc(NfcCommon* nfc_common) {
|
||||
furi_assert(nfc_common);
|
||||
|
||||
@@ -144,9 +141,9 @@ NfcMifareUl* nfc_mifare_ul_alloc(NfcCommon* nfc_common) {
|
||||
view_set_context(nfc_mifare_ul->view, nfc_mifare_ul);
|
||||
view_set_draw_callback(nfc_mifare_ul->view, (ViewDrawCallback)nfc_mifare_ul_draw);
|
||||
view_set_input_callback(nfc_mifare_ul->view, nfc_mifare_ul_input);
|
||||
view_set_custom_callback(nfc_mifare_ul->view, nfc_mifare_ul_custom);
|
||||
view_set_enter_callback(nfc_mifare_ul->view, nfc_mifare_ul_enter);
|
||||
view_set_exit_callback(nfc_mifare_ul->view, nfc_mifare_ul_exit);
|
||||
view_set_previous_callback(nfc_mifare_ul->view, nfc_mifare_ul_back);
|
||||
|
||||
return nfc_mifare_ul;
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "nfc_types.h"
|
||||
#include "../nfc_types.h"
|
||||
|
||||
typedef struct NfcMifareUl NfcMifareUl;
|
||||
|
||||
@@ -10,5 +10,3 @@ NfcMifareUl* nfc_mifare_ul_alloc(NfcCommon* nfc_common);
|
||||
void nfc_mifare_ul_free(NfcMifareUl* nfc_mifare_ul);
|
||||
|
||||
View* nfc_mifare_ul_get_view(NfcMifareUl* nfc_mifare_ul);
|
||||
|
||||
void nfc_mifare_ul_view_dispatcher_callback(NfcMifareUl* nfc_mifare_ul, NfcMessage* message);
|
Reference in New Issue
Block a user