2020-11-12 09:44:35 +00:00
|
|
|
#include "nfc_i.h"
|
2021-05-06 19:51:20 +00:00
|
|
|
#include "api-hal-nfc.h"
|
2020-10-18 22:09:48 +00:00
|
|
|
|
2021-05-06 19:51:20 +00:00
|
|
|
uint32_t nfc_view_exit(void* context) {
|
FL-53: new NFC worker, A/B/F/V poll and display. (#283)
* GUI: view. Flooper-blooper fix compilation error.
* GUI: view and viewdispatcher bones
* GUI: view implementation, view models, view dispatcher
* GUI: view navigation, model refinement. Power: use view, view dispatcher.
* HAL Flash: proper page write. Dolphin: views. Power: views
* Dolphin: transition idle scree to Views
* Dolphin: input events on stats view. Format sources.
* HAL: flash erase. Dolphin: permanent state storage.
* Dolphin: first start welcome. HAL: flash operation status, errata 2.2.9 crutch.
* NFC: rewrite worker
* NFC: add support for B,F,V.
* NFC: replace rfal irq hanlder with realtime thread, more details about cards.
* Bootloader: LSE and RTS shenanigans, LED control, morse code for LSE failure error.
* F4: stop in Error_Handler
* BLE: handle working FUS, but empty radio stack.
* HAL: alive FUS is now sufficient for flash controller access
* Dolphin: update model after state load
* NFC: detect navigation
* RFAL: use osPriorityISR for isr thread
* NFC: emulation
* Bootloader: rollback incorrectly merged rename
* Dolphin: rollback incorrectly merged changes
* RFAL: remove volatile from thread attr
* RFAL: do not call platform ErrorHandler, error codes is enough
* NFC: improved error handling
* Format sources
* NFC: reset detect view model on start
* Format sources
* update codeowners
* NFC: hide last info if no card detected
2021-01-11 12:42:25 +00:00
|
|
|
return VIEW_NONE;
|
2020-10-18 22:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 19:51:20 +00:00
|
|
|
void nfc_menu_callback(void* context, uint32_t index) {
|
2021-06-24 08:46:37 +00:00
|
|
|
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;
|
2021-05-06 19:51:20 +00:00
|
|
|
NfcMessage message;
|
2021-06-24 08:46:37 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-05-06 19:51:20 +00:00
|
|
|
}
|
|
|
|
|
FL-53: new NFC worker, A/B/F/V poll and display. (#283)
* GUI: view. Flooper-blooper fix compilation error.
* GUI: view and viewdispatcher bones
* GUI: view implementation, view models, view dispatcher
* GUI: view navigation, model refinement. Power: use view, view dispatcher.
* HAL Flash: proper page write. Dolphin: views. Power: views
* Dolphin: transition idle scree to Views
* Dolphin: input events on stats view. Format sources.
* HAL: flash erase. Dolphin: permanent state storage.
* Dolphin: first start welcome. HAL: flash operation status, errata 2.2.9 crutch.
* NFC: rewrite worker
* NFC: add support for B,F,V.
* NFC: replace rfal irq hanlder with realtime thread, more details about cards.
* Bootloader: LSE and RTS shenanigans, LED control, morse code for LSE failure error.
* F4: stop in Error_Handler
* BLE: handle working FUS, but empty radio stack.
* HAL: alive FUS is now sufficient for flash controller access
* Dolphin: update model after state load
* NFC: detect navigation
* RFAL: use osPriorityISR for isr thread
* NFC: emulation
* Bootloader: rollback incorrectly merged rename
* Dolphin: rollback incorrectly merged changes
* RFAL: remove volatile from thread attr
* RFAL: do not call platform ErrorHandler, error codes is enough
* NFC: improved error handling
* Format sources
* NFC: reset detect view model on start
* Format sources
* update codeowners
* NFC: hide last info if no card detected
2021-01-11 12:42:25 +00:00
|
|
|
Nfc* nfc_alloc() {
|
|
|
|
Nfc* nfc = furi_alloc(sizeof(Nfc));
|
2020-10-18 22:09:48 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
nfc->message_queue = osMessageQueueNew(8, sizeof(NfcMessage), NULL);
|
|
|
|
nfc->nfc_common.worker = nfc_worker_alloc(nfc->message_queue);
|
|
|
|
nfc->nfc_common.view_dispatcher = view_dispatcher_alloc();
|
|
|
|
view_dispatcher_enable_queue(nfc->nfc_common.view_dispatcher);
|
2020-11-16 15:26:34 +00:00
|
|
|
|
2021-05-06 19:51:20 +00:00
|
|
|
// Open GUI record
|
|
|
|
nfc->gui = furi_record_open("gui");
|
2021-06-24 08:46:37 +00:00
|
|
|
view_dispatcher_attach_to_gui(
|
|
|
|
nfc->nfc_common.view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);
|
2021-05-06 19:51:20 +00:00
|
|
|
|
|
|
|
// Menu
|
|
|
|
nfc->submenu = submenu_alloc();
|
2021-06-24 08:46:37 +00:00
|
|
|
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);
|
2021-06-15 14:54:09 +00:00
|
|
|
submenu_add_item(
|
2021-06-24 08:46:37 +00:00
|
|
|
nfc->submenu, "Read Mifare Ultralight", NfcSubmenuMifareUl, nfc_menu_callback, nfc);
|
2021-06-15 14:54:09 +00:00
|
|
|
|
2021-05-06 19:51:20 +00:00
|
|
|
View* submenu_view = submenu_get_view(nfc->submenu);
|
|
|
|
view_set_previous_callback(submenu_view, nfc_view_exit);
|
2021-06-24 08:46:37 +00:00
|
|
|
view_dispatcher_add_view(nfc->nfc_common.view_dispatcher, NfcViewMenu, submenu_view);
|
2021-05-06 19:51:20 +00:00
|
|
|
|
|
|
|
// Detect
|
2021-06-24 08:46:37 +00:00
|
|
|
nfc->nfc_detect = nfc_detect_alloc(&nfc->nfc_common);
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
nfc->nfc_common.view_dispatcher, NfcViewDetect, nfc_detect_get_view(nfc->nfc_detect));
|
2021-05-25 23:54:44 +00:00
|
|
|
|
2021-05-06 19:51:20 +00:00
|
|
|
// Emulate
|
2021-06-24 08:46:37 +00:00
|
|
|
nfc->nfc_emulate = nfc_emulate_alloc(&nfc->nfc_common);
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
nfc->nfc_common.view_dispatcher, NfcViewEmulate, nfc_emulate_get_view(nfc->nfc_emulate));
|
2021-05-06 19:51:20 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
// EMV
|
|
|
|
nfc->nfc_emv = nfc_emv_alloc(&nfc->nfc_common);
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
nfc->nfc_common.view_dispatcher, NfcViewEmv, nfc_emv_get_view(nfc->nfc_emv));
|
2021-05-06 19:51:20 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
// Mifare Ultralight
|
|
|
|
nfc->nfc_mifare_ul = nfc_mifare_ul_alloc(&nfc->nfc_common);
|
2021-06-15 14:54:09 +00:00
|
|
|
view_dispatcher_add_view(
|
2021-06-24 08:46:37 +00:00
|
|
|
nfc->nfc_common.view_dispatcher,
|
|
|
|
NfcViewMifareUl,
|
|
|
|
nfc_mifare_ul_get_view(nfc->nfc_mifare_ul));
|
2021-06-15 14:54:09 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
// Set View Dispatcher custom event callback
|
|
|
|
view_dispatcher_set_custom_callback(
|
|
|
|
nfc->nfc_common.view_dispatcher, nfc_view_dispatcher_callback, nfc);
|
2020-11-16 15:26:34 +00:00
|
|
|
|
2021-05-06 19:51:20 +00:00
|
|
|
// Switch to menu
|
2021-06-24 08:46:37 +00:00
|
|
|
view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
2021-05-06 19:51:20 +00:00
|
|
|
|
FL-53: new NFC worker, A/B/F/V poll and display. (#283)
* GUI: view. Flooper-blooper fix compilation error.
* GUI: view and viewdispatcher bones
* GUI: view implementation, view models, view dispatcher
* GUI: view navigation, model refinement. Power: use view, view dispatcher.
* HAL Flash: proper page write. Dolphin: views. Power: views
* Dolphin: transition idle scree to Views
* Dolphin: input events on stats view. Format sources.
* HAL: flash erase. Dolphin: permanent state storage.
* Dolphin: first start welcome. HAL: flash operation status, errata 2.2.9 crutch.
* NFC: rewrite worker
* NFC: add support for B,F,V.
* NFC: replace rfal irq hanlder with realtime thread, more details about cards.
* Bootloader: LSE and RTS shenanigans, LED control, morse code for LSE failure error.
* F4: stop in Error_Handler
* BLE: handle working FUS, but empty radio stack.
* HAL: alive FUS is now sufficient for flash controller access
* Dolphin: update model after state load
* NFC: detect navigation
* RFAL: use osPriorityISR for isr thread
* NFC: emulation
* Bootloader: rollback incorrectly merged rename
* Dolphin: rollback incorrectly merged changes
* RFAL: remove volatile from thread attr
* RFAL: do not call platform ErrorHandler, error codes is enough
* NFC: improved error handling
* Format sources
* NFC: reset detect view model on start
* Format sources
* update codeowners
* NFC: hide last info if no card detected
2021-01-11 12:42:25 +00:00
|
|
|
return nfc;
|
2020-11-12 09:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 19:51:20 +00:00
|
|
|
void nfc_free(Nfc* nfc) {
|
2021-06-24 08:46:37 +00:00
|
|
|
furi_assert(nfc);
|
2020-11-12 09:44:35 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
// Submenu
|
|
|
|
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewMenu);
|
2021-05-06 19:51:20 +00:00
|
|
|
submenu_free(nfc->submenu);
|
2020-10-18 22:09:48 +00:00
|
|
|
|
2021-05-06 19:51:20 +00:00
|
|
|
// Detect
|
2021-06-24 08:46:37 +00:00
|
|
|
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewDetect);
|
|
|
|
nfc_detect_free(nfc->nfc_detect);
|
2021-05-25 23:54:44 +00:00
|
|
|
|
2021-05-06 19:51:20 +00:00
|
|
|
// Emulate
|
2021-06-24 08:46:37 +00:00
|
|
|
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewEmulate);
|
|
|
|
nfc_emulate_free(nfc->nfc_emulate);
|
2021-05-06 19:51:20 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
// EMV
|
|
|
|
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewEmv);
|
|
|
|
nfc_emv_free(nfc->nfc_emv);
|
2021-05-06 19:51:20 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
// Mifare ultralight
|
|
|
|
view_dispatcher_remove_view(nfc->nfc_common.view_dispatcher, NfcViewMifareUl);
|
|
|
|
nfc_mifare_ul_free(nfc->nfc_mifare_ul);
|
2021-06-15 14:54:09 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
// Worker
|
|
|
|
nfc_worker_stop(nfc->nfc_common.worker);
|
|
|
|
nfc_worker_free(nfc->nfc_common.worker);
|
2021-05-06 19:51:20 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
// View dispatcher
|
|
|
|
view_dispatcher_free(nfc->nfc_common.view_dispatcher);
|
2021-05-06 19:51:20 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
// GUI
|
2021-05-06 19:51:20 +00:00
|
|
|
furi_record_close("gui");
|
|
|
|
nfc->gui = NULL;
|
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
// The rest
|
|
|
|
osMessageQueueDelete(nfc->message_queue);
|
2021-05-06 19:51:20 +00:00
|
|
|
free(nfc);
|
2020-10-18 22:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 17:24:34 +00:00
|
|
|
int32_t nfc_task(void* p) {
|
2020-10-18 22:55:41 +00:00
|
|
|
Nfc* nfc = nfc_alloc();
|
2020-10-18 22:09:48 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
view_dispatcher_run(nfc->nfc_common.view_dispatcher);
|
2021-06-15 14:54:09 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
nfc_free(nfc);
|
2021-02-12 17:24:34 +00:00
|
|
|
|
|
|
|
return 0;
|
2020-10-18 22:09:48 +00:00
|
|
|
}
|