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
|
|
|
#include "nfc_worker_i.h"
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal.h>
|
2022-03-23 22:14:34 +00:00
|
|
|
|
|
|
|
#include <lib/nfc_protocols/nfc_util.h>
|
2022-04-19 15:23:58 +00:00
|
|
|
#include <lib/nfc_protocols/emv.h>
|
|
|
|
#include <lib/nfc_protocols/mifare_common.h>
|
2022-03-23 22:14:34 +00:00
|
|
|
#include <lib/nfc_protocols/mifare_ultralight.h>
|
|
|
|
#include <lib/nfc_protocols/mifare_classic.h>
|
|
|
|
#include <lib/nfc_protocols/mifare_desfire.h>
|
2022-05-24 14:00:15 +00:00
|
|
|
#include <lib/nfc_protocols/nfca.h>
|
2022-03-23 22:14:34 +00:00
|
|
|
|
|
|
|
#include "helpers/nfc_mf_classic_dict.h"
|
2021-05-18 18:12:01 +00:00
|
|
|
|
2021-11-12 13:04:35 +00:00
|
|
|
#define TAG "NfcWorker"
|
2020-11-12 09:44:35 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
/***************************** NFC Worker API *******************************/
|
|
|
|
|
2021-06-30 17:43:29 +00:00
|
|
|
NfcWorker* nfc_worker_alloc() {
|
2022-02-18 19:53:46 +00:00
|
|
|
NfcWorker* nfc_worker = malloc(sizeof(NfcWorker));
|
2022-02-18 23:38:44 +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
|
|
|
// Worker thread attributes
|
2022-02-18 23:38:44 +00:00
|
|
|
nfc_worker->thread = furi_thread_alloc();
|
|
|
|
furi_thread_set_name(nfc_worker->thread, "NfcWorker");
|
|
|
|
furi_thread_set_stack_size(nfc_worker->thread, 8192);
|
|
|
|
furi_thread_set_callback(nfc_worker->thread, nfc_worker_task);
|
|
|
|
furi_thread_set_context(nfc_worker->thread, nfc_worker);
|
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
nfc_worker->callback = NULL;
|
|
|
|
nfc_worker->context = NULL;
|
2022-03-23 22:14:34 +00:00
|
|
|
nfc_worker->storage = furi_record_open("storage");
|
2022-02-18 23:38:44 +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
|
|
|
// Initialize rfal
|
2022-02-18 19:53:46 +00:00
|
|
|
while(furi_hal_nfc_is_busy()) {
|
|
|
|
osDelay(10);
|
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
|
|
|
}
|
2022-02-18 19:53:46 +00:00
|
|
|
nfc_worker_change_state(nfc_worker, NfcWorkerStateReady);
|
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_worker;
|
|
|
|
}
|
|
|
|
|
2021-05-06 19:51:20 +00:00
|
|
|
void nfc_worker_free(NfcWorker* nfc_worker) {
|
|
|
|
furi_assert(nfc_worker);
|
2022-02-18 23:38:44 +00:00
|
|
|
furi_thread_free(nfc_worker->thread);
|
2022-03-23 22:14:34 +00:00
|
|
|
furi_record_close("storage");
|
2021-05-06 19:51:20 +00:00
|
|
|
free(nfc_worker);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
NfcWorkerState nfc_worker_get_state(NfcWorker* nfc_worker) {
|
|
|
|
return nfc_worker->state;
|
|
|
|
}
|
2020-11-12 09:44:35 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
void nfc_worker_start(
|
|
|
|
NfcWorker* nfc_worker,
|
|
|
|
NfcWorkerState state,
|
2021-07-22 06:05:07 +00:00
|
|
|
NfcDeviceData* dev_data,
|
2021-06-24 08:46:37 +00:00
|
|
|
NfcWorkerCallback callback,
|
|
|
|
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
|
|
|
furi_assert(nfc_worker);
|
2021-07-22 06:05:07 +00:00
|
|
|
furi_assert(dev_data);
|
2022-02-18 19:53:46 +00:00
|
|
|
while(furi_hal_nfc_is_busy()) {
|
2021-07-22 06:05:07 +00:00
|
|
|
osDelay(10);
|
|
|
|
}
|
2021-06-24 08:46:37 +00:00
|
|
|
|
|
|
|
nfc_worker->callback = callback;
|
|
|
|
nfc_worker->context = context;
|
2021-07-22 06:05:07 +00:00
|
|
|
nfc_worker->dev_data = dev_data;
|
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_worker_change_state(nfc_worker, state);
|
2022-02-18 23:38:44 +00:00
|
|
|
furi_thread_start(nfc_worker->thread);
|
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
|
|
|
}
|
2020-11-12 09:44:35 +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
|
|
|
void nfc_worker_stop(NfcWorker* nfc_worker) {
|
|
|
|
furi_assert(nfc_worker);
|
2021-06-30 17:43:29 +00:00
|
|
|
if(nfc_worker->state == NfcWorkerStateBroken || nfc_worker->state == NfcWorkerStateReady) {
|
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;
|
2020-11-12 09:44:35 +00:00
|
|
|
}
|
2022-02-02 19:59:28 +00:00
|
|
|
furi_hal_nfc_stop();
|
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_worker_change_state(nfc_worker, NfcWorkerStateStop);
|
2022-02-18 23:38:44 +00:00
|
|
|
furi_thread_join(nfc_worker->thread);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_worker_change_state(NfcWorker* nfc_worker, NfcWorkerState state) {
|
|
|
|
nfc_worker->state = state;
|
2020-11-12 09:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
/***************************** NFC Worker Thread *******************************/
|
|
|
|
|
2022-02-18 23:38:44 +00:00
|
|
|
int32_t nfc_worker_task(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
|
|
|
NfcWorker* nfc_worker = context;
|
2020-11-12 09:44:35 +00:00
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_exit_sleep();
|
2021-01-18 15:08:58 +00:00
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
if(nfc_worker->state == NfcWorkerStateDetect) {
|
|
|
|
nfc_worker_detect(nfc_worker);
|
|
|
|
} else if(nfc_worker->state == NfcWorkerStateEmulate) {
|
|
|
|
nfc_worker_emulate(nfc_worker);
|
2021-07-22 06:05:07 +00:00
|
|
|
} else if(nfc_worker->state == NfcWorkerStateReadEMVApp) {
|
|
|
|
nfc_worker_read_emv_app(nfc_worker);
|
2022-04-19 15:23:58 +00:00
|
|
|
} else if(nfc_worker->state == NfcWorkerStateReadEMVData) {
|
2021-05-18 18:12:01 +00:00
|
|
|
nfc_worker_read_emv(nfc_worker);
|
2021-08-04 18:58:11 +00:00
|
|
|
} else if(nfc_worker->state == NfcWorkerStateEmulateApdu) {
|
|
|
|
nfc_worker_emulate_apdu(nfc_worker);
|
2022-04-19 15:23:58 +00:00
|
|
|
} else if(nfc_worker->state == NfcWorkerStateReadMifareUltralight) {
|
|
|
|
nfc_worker_read_mifare_ultralight(nfc_worker);
|
|
|
|
} else if(nfc_worker->state == NfcWorkerStateEmulateMifareUltralight) {
|
2021-07-22 06:05:07 +00:00
|
|
|
nfc_worker_emulate_mifare_ul(nfc_worker);
|
2022-03-23 22:14:34 +00:00
|
|
|
} else if(nfc_worker->state == NfcWorkerStateReadMifareClassic) {
|
|
|
|
nfc_worker_mifare_classic_dict_attack(nfc_worker);
|
2022-05-24 14:00:15 +00:00
|
|
|
} else if(nfc_worker->state == NfcWorkerStateEmulateMifareClassic) {
|
|
|
|
nfc_worker_emulate_mifare_classic(nfc_worker);
|
2022-03-23 13:45:37 +00:00
|
|
|
} else if(nfc_worker->state == NfcWorkerStateReadMifareDesfire) {
|
|
|
|
nfc_worker_read_mifare_desfire(nfc_worker);
|
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
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
furi_hal_nfc_sleep();
|
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_worker_change_state(nfc_worker, NfcWorkerStateReady);
|
2022-02-18 23:38:44 +00:00
|
|
|
|
|
|
|
return 0;
|
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
|
|
|
}
|
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
void nfc_worker_detect(NfcWorker* nfc_worker) {
|
2022-03-23 13:45:37 +00:00
|
|
|
nfc_device_data_clear(nfc_worker->dev_data);
|
2022-04-19 15:23:58 +00:00
|
|
|
NfcDeviceData* dev_data = nfc_worker->dev_data;
|
|
|
|
FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data;
|
2021-06-24 08:46:37 +00:00
|
|
|
|
|
|
|
while(nfc_worker->state == NfcWorkerStateDetect) {
|
2022-04-19 15:23:58 +00:00
|
|
|
if(furi_hal_nfc_detect(nfc_data, 1000)) {
|
2021-06-24 08:46:37 +00:00
|
|
|
// Process first found device
|
2022-04-19 15:23:58 +00:00
|
|
|
if(nfc_data->type == FuriHalNfcTypeA) {
|
|
|
|
if(mf_ul_check_card_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak)) {
|
|
|
|
dev_data->protocol = NfcDeviceProtocolMifareUl;
|
2022-03-23 22:14:34 +00:00
|
|
|
} else if(mf_classic_check_card_type(
|
2022-04-19 15:23:58 +00:00
|
|
|
nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak)) {
|
|
|
|
dev_data->protocol = NfcDeviceProtocolMifareClassic;
|
2022-03-23 13:45:37 +00:00
|
|
|
} else if(mf_df_check_card_type(
|
2022-04-19 15:23:58 +00:00
|
|
|
nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak)) {
|
|
|
|
dev_data->protocol = NfcDeviceProtocolMifareDesfire;
|
|
|
|
} else if(nfc_data->interface == FuriHalNfcInterfaceIsoDep) {
|
|
|
|
dev_data->protocol = NfcDeviceProtocolEMV;
|
2021-06-30 17:43:29 +00:00
|
|
|
} else {
|
2022-04-19 15:23:58 +00:00
|
|
|
dev_data->protocol = NfcDeviceProtocolUnknown;
|
2021-06-30 17:43:29 +00:00
|
|
|
}
|
2021-06-24 08:46:37 +00:00
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
|
2021-06-30 17:43:29 +00:00
|
|
|
// Notify caller and exit
|
|
|
|
if(nfc_worker->callback) {
|
2022-03-23 22:14:34 +00:00
|
|
|
nfc_worker->callback(NfcWorkerEventSuccess, nfc_worker->context);
|
2021-06-30 17:43:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2021-06-24 08:46:37 +00:00
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
furi_hal_nfc_sleep();
|
2021-06-24 08:46:37 +00:00
|
|
|
osDelay(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-19 15:23:58 +00:00
|
|
|
void nfc_worker_emulate(NfcWorker* nfc_worker) {
|
|
|
|
FuriHalNfcTxRxContext tx_rx = {};
|
|
|
|
FuriHalNfcDevData* data = &nfc_worker->dev_data->nfc_data;
|
2022-02-02 19:59:28 +00:00
|
|
|
NfcReaderRequestData* reader_data = &nfc_worker->dev_data->reader_data;
|
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
while(nfc_worker->state == NfcWorkerStateEmulate) {
|
2022-04-19 15:23:58 +00:00
|
|
|
if(furi_hal_nfc_listen(data->uid, data->uid_len, data->atqa, data->sak, true, 100)) {
|
|
|
|
if(furi_hal_nfc_tx_rx(&tx_rx, 100)) {
|
|
|
|
reader_data->size = tx_rx.rx_bits / 8;
|
|
|
|
if(reader_data->size > 0) {
|
|
|
|
memcpy(reader_data->data, tx_rx.rx_data, reader_data->size);
|
|
|
|
if(nfc_worker->callback) {
|
|
|
|
nfc_worker->callback(NfcWorkerEventSuccess, nfc_worker->context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
FURI_LOG_E(TAG, "Failed to get reader commands");
|
|
|
|
}
|
|
|
|
}
|
2021-06-24 08:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 06:05:07 +00:00
|
|
|
void nfc_worker_read_emv_app(NfcWorker* nfc_worker) {
|
2022-04-19 15:23:58 +00:00
|
|
|
FuriHalNfcTxRxContext tx_rx = {};
|
2021-07-22 06:05:07 +00:00
|
|
|
EmvApplication emv_app = {};
|
|
|
|
NfcDeviceData* result = nfc_worker->dev_data;
|
2022-04-19 15:23:58 +00:00
|
|
|
FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data;
|
2022-03-23 13:45:37 +00:00
|
|
|
nfc_device_data_clear(result);
|
2021-07-22 06:05:07 +00:00
|
|
|
|
|
|
|
while(nfc_worker->state == NfcWorkerStateReadEMVApp) {
|
2022-04-19 15:23:58 +00:00
|
|
|
if(furi_hal_nfc_detect(nfc_data, 1000)) {
|
2021-07-22 06:05:07 +00:00
|
|
|
// Card was found. Check that it supports EMV
|
2022-04-19 15:23:58 +00:00
|
|
|
if(nfc_data->interface == FuriHalNfcInterfaceIsoDep) {
|
|
|
|
result->protocol = NfcDeviceProtocolEMV;
|
|
|
|
if(emv_search_application(&tx_rx, &emv_app)) {
|
2021-07-22 06:05:07 +00:00
|
|
|
// Notify caller and exit
|
|
|
|
result->emv_data.aid_len = emv_app.aid_len;
|
|
|
|
memcpy(result->emv_data.aid, emv_app.aid, emv_app.aid_len);
|
|
|
|
if(nfc_worker->callback) {
|
2022-03-23 22:14:34 +00:00
|
|
|
nfc_worker->callback(NfcWorkerEventSuccess, nfc_worker->context);
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2021-11-12 13:04:35 +00:00
|
|
|
FURI_LOG_W(TAG, "Card doesn't support EMV");
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't find any cards");
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
furi_hal_nfc_sleep();
|
2021-07-22 06:05:07 +00:00
|
|
|
osDelay(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-18 18:12:01 +00:00
|
|
|
void nfc_worker_read_emv(NfcWorker* nfc_worker) {
|
2022-04-19 15:23:58 +00:00
|
|
|
FuriHalNfcTxRxContext tx_rx = {};
|
2021-05-18 18:12:01 +00:00
|
|
|
EmvApplication emv_app = {};
|
2021-07-22 06:05:07 +00:00
|
|
|
NfcDeviceData* result = nfc_worker->dev_data;
|
2022-04-19 15:23:58 +00:00
|
|
|
FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data;
|
2022-03-23 13:45:37 +00:00
|
|
|
nfc_device_data_clear(result);
|
2021-05-18 18:12:01 +00:00
|
|
|
|
2022-04-19 15:23:58 +00:00
|
|
|
while(nfc_worker->state == NfcWorkerStateReadEMVData) {
|
|
|
|
if(furi_hal_nfc_detect(nfc_data, 1000)) {
|
2021-05-18 18:12:01 +00:00
|
|
|
// Card was found. Check that it supports EMV
|
2022-04-19 15:23:58 +00:00
|
|
|
if(nfc_data->interface == FuriHalNfcInterfaceIsoDep) {
|
|
|
|
result->protocol = NfcDeviceProtocolEMV;
|
|
|
|
if(emv_read_bank_card(&tx_rx, &emv_app)) {
|
|
|
|
result->emv_data.number_len = emv_app.card_number_len;
|
|
|
|
memcpy(
|
|
|
|
result->emv_data.number, emv_app.card_number, result->emv_data.number_len);
|
2021-11-08 21:55:06 +00:00
|
|
|
result->emv_data.aid_len = emv_app.aid_len;
|
|
|
|
memcpy(result->emv_data.aid, emv_app.aid, emv_app.aid_len);
|
2022-04-19 15:23:58 +00:00
|
|
|
if(emv_app.name_found) {
|
|
|
|
memcpy(result->emv_data.name, emv_app.name, sizeof(emv_app.name));
|
|
|
|
}
|
|
|
|
if(emv_app.exp_month) {
|
|
|
|
result->emv_data.exp_mon = emv_app.exp_month;
|
|
|
|
result->emv_data.exp_year = emv_app.exp_year;
|
|
|
|
}
|
|
|
|
if(emv_app.country_code) {
|
|
|
|
result->emv_data.country_code = emv_app.country_code;
|
|
|
|
}
|
|
|
|
if(emv_app.currency_code) {
|
|
|
|
result->emv_data.currency_code = emv_app.currency_code;
|
|
|
|
}
|
2021-06-30 17:43:29 +00:00
|
|
|
// Notify caller and exit
|
|
|
|
if(nfc_worker->callback) {
|
2022-03-23 22:14:34 +00:00
|
|
|
nfc_worker->callback(NfcWorkerEventSuccess, nfc_worker->context);
|
2021-06-30 17:43:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2021-05-18 18:12:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-11-12 13:04:35 +00:00
|
|
|
FURI_LOG_W(TAG, "Card doesn't support EMV");
|
2021-05-18 18:12:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't find any cards");
|
2021-05-18 18:12:01 +00:00
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
furi_hal_nfc_sleep();
|
2021-05-18 18:12:01 +00:00
|
|
|
osDelay(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 18:58:11 +00:00
|
|
|
void nfc_worker_emulate_apdu(NfcWorker* nfc_worker) {
|
2022-04-19 15:23:58 +00:00
|
|
|
FuriHalNfcTxRxContext tx_rx = {};
|
|
|
|
FuriHalNfcDevData params = {
|
2021-06-30 17:43:29 +00:00
|
|
|
.uid = {0xCF, 0x72, 0xd4, 0x40},
|
|
|
|
.uid_len = 4,
|
|
|
|
.atqa = {0x00, 0x04},
|
|
|
|
.sak = 0x20,
|
2022-04-19 15:23:58 +00:00
|
|
|
.type = FuriHalNfcTypeA,
|
2021-06-30 17:43:29 +00:00
|
|
|
};
|
2021-05-25 23:54:44 +00:00
|
|
|
|
2021-08-04 18:58:11 +00:00
|
|
|
while(nfc_worker->state == NfcWorkerStateEmulateApdu) {
|
2021-08-16 21:45:04 +00:00
|
|
|
if(furi_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, false, 300)) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "POS terminal detected");
|
2022-04-19 15:23:58 +00:00
|
|
|
if(emv_card_emulation(&tx_rx)) {
|
|
|
|
FURI_LOG_D(TAG, "EMV card emulated");
|
2021-05-25 23:54:44 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't find reader");
|
2021-05-25 23:54:44 +00:00
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
furi_hal_nfc_sleep();
|
2021-05-25 23:54:44 +00:00
|
|
|
osDelay(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-19 15:23:58 +00:00
|
|
|
void nfc_worker_read_mifare_ultralight(NfcWorker* nfc_worker) {
|
|
|
|
FuriHalNfcTxRxContext tx_rx = {};
|
|
|
|
MfUltralightReader reader = {};
|
|
|
|
MfUltralightData data = {};
|
2021-07-22 06:05:07 +00:00
|
|
|
NfcDeviceData* result = nfc_worker->dev_data;
|
2022-04-19 15:23:58 +00:00
|
|
|
FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data;
|
|
|
|
|
|
|
|
while(nfc_worker->state == NfcWorkerStateReadMifareUltralight) {
|
|
|
|
if(furi_hal_nfc_detect(nfc_data, 300)) {
|
|
|
|
if(nfc_data->type == FuriHalNfcTypeA &&
|
|
|
|
mf_ul_check_card_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak)) {
|
|
|
|
FURI_LOG_D(TAG, "Found Mifare Ultralight tag. Start reading");
|
|
|
|
if(mf_ul_read_card(&tx_rx, &reader, &data)) {
|
|
|
|
result->protocol = NfcDeviceProtocolMifareUl;
|
|
|
|
result->mf_ul_data = data;
|
|
|
|
// Notify caller and exit
|
|
|
|
if(nfc_worker->callback) {
|
|
|
|
nfc_worker->callback(NfcWorkerEventSuccess, nfc_worker->context);
|
2021-06-15 14:54:09 +00:00
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
break;
|
2021-06-15 14:54:09 +00:00
|
|
|
} else {
|
2022-04-19 15:23:58 +00:00
|
|
|
FURI_LOG_D(TAG, "Failed reading Mifare Ultralight");
|
2021-06-15 14:54:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-04-19 15:23:58 +00:00
|
|
|
FURI_LOG_W(TAG, "Tag is not Mifare Ultralight");
|
2021-06-15 14:54:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't find any tags");
|
2021-06-15 14:54:09 +00:00
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
furi_hal_nfc_sleep();
|
2021-06-15 14:54:09 +00:00
|
|
|
osDelay(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 06:05:07 +00:00
|
|
|
void nfc_worker_emulate_mifare_ul(NfcWorker* nfc_worker) {
|
2022-04-19 15:23:58 +00:00
|
|
|
FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data;
|
|
|
|
MfUltralightEmulator emulator = {};
|
|
|
|
mf_ul_prepare_emulation(&emulator, &nfc_worker->dev_data->mf_ul_data);
|
|
|
|
while(nfc_worker->state == NfcWorkerStateEmulateMifareUltralight) {
|
2022-02-02 19:59:28 +00:00
|
|
|
furi_hal_nfc_emulate_nfca(
|
2022-04-19 15:23:58 +00:00
|
|
|
nfc_data->uid,
|
|
|
|
nfc_data->uid_len,
|
|
|
|
nfc_data->atqa,
|
|
|
|
nfc_data->sak,
|
2022-02-02 19:59:28 +00:00
|
|
|
mf_ul_prepare_emulation_response,
|
2022-04-19 15:23:58 +00:00
|
|
|
&emulator,
|
2022-02-02 19:59:28 +00:00
|
|
|
5000);
|
2021-08-16 21:45:04 +00:00
|
|
|
// Check if data was modified
|
2022-04-19 15:23:58 +00:00
|
|
|
if(emulator.data_changed) {
|
|
|
|
nfc_worker->dev_data->mf_ul_data = emulator.data;
|
2021-08-16 21:45:04 +00:00
|
|
|
if(nfc_worker->callback) {
|
2022-03-23 22:14:34 +00:00
|
|
|
nfc_worker->callback(NfcWorkerEventSuccess, nfc_worker->context);
|
2021-08-16 21:45:04 +00:00
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
emulator.data_changed = false;
|
2021-08-16 21:45:04 +00:00
|
|
|
}
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 22:14:34 +00:00
|
|
|
void nfc_worker_mifare_classic_dict_attack(NfcWorker* nfc_worker) {
|
|
|
|
furi_assert(nfc_worker->callback);
|
|
|
|
FuriHalNfcTxRxContext tx_rx_ctx = {};
|
|
|
|
MfClassicAuthContext auth_ctx = {};
|
|
|
|
MfClassicReader reader = {};
|
|
|
|
uint64_t curr_key = 0;
|
|
|
|
uint16_t curr_sector = 0;
|
|
|
|
uint8_t total_sectors = 0;
|
|
|
|
NfcWorkerEvent event;
|
2022-04-19 15:23:58 +00:00
|
|
|
FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data;
|
2022-03-23 22:14:34 +00:00
|
|
|
|
|
|
|
// Open dictionary
|
|
|
|
nfc_worker->dict_stream = file_stream_alloc(nfc_worker->storage);
|
|
|
|
if(!nfc_mf_classic_dict_open_file(nfc_worker->dict_stream)) {
|
|
|
|
event = NfcWorkerEventNoDictFound;
|
|
|
|
nfc_worker->callback(event, nfc_worker->context);
|
|
|
|
nfc_mf_classic_dict_close_file(nfc_worker->dict_stream);
|
|
|
|
stream_free(nfc_worker->dict_stream);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Detect Mifare Classic card
|
|
|
|
while(nfc_worker->state == NfcWorkerStateReadMifareClassic) {
|
2022-04-19 15:23:58 +00:00
|
|
|
if(furi_hal_nfc_detect(nfc_data, 300)) {
|
2022-03-23 22:14:34 +00:00
|
|
|
if(mf_classic_get_type(
|
2022-04-19 15:23:58 +00:00
|
|
|
nfc_data->uid,
|
|
|
|
nfc_data->uid_len,
|
|
|
|
nfc_data->atqa[0],
|
|
|
|
nfc_data->atqa[1],
|
|
|
|
nfc_data->sak,
|
2022-03-23 22:14:34 +00:00
|
|
|
&reader)) {
|
|
|
|
total_sectors = mf_classic_get_total_sectors_num(&reader);
|
|
|
|
if(reader.type == MfClassicType1k) {
|
|
|
|
event = NfcWorkerEventDetectedClassic1k;
|
|
|
|
} else {
|
|
|
|
event = NfcWorkerEventDetectedClassic4k;
|
|
|
|
}
|
|
|
|
nfc_worker->callback(event, nfc_worker->context);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
event = NfcWorkerEventNoCardDetected;
|
|
|
|
nfc_worker->callback(event, nfc_worker->context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nfc_worker->state == NfcWorkerStateReadMifareClassic) {
|
|
|
|
bool card_removed_notified = false;
|
|
|
|
bool card_found_notified = false;
|
|
|
|
// Seek for mifare classic keys
|
|
|
|
for(curr_sector = 0; curr_sector < total_sectors; curr_sector++) {
|
|
|
|
FURI_LOG_I(TAG, "Sector: %d ...", curr_sector);
|
|
|
|
event = NfcWorkerEventNewSector;
|
|
|
|
nfc_worker->callback(event, nfc_worker->context);
|
|
|
|
mf_classic_auth_init_context(&auth_ctx, reader.cuid, curr_sector);
|
|
|
|
bool sector_key_found = false;
|
|
|
|
while(nfc_mf_classic_dict_get_next_key(nfc_worker->dict_stream, &curr_key)) {
|
2022-04-19 15:23:58 +00:00
|
|
|
furi_hal_nfc_sleep();
|
2022-03-23 22:14:34 +00:00
|
|
|
if(furi_hal_nfc_activate_nfca(300, &reader.cuid)) {
|
|
|
|
if(!card_found_notified) {
|
|
|
|
if(reader.type == MfClassicType1k) {
|
|
|
|
event = NfcWorkerEventDetectedClassic1k;
|
|
|
|
} else {
|
|
|
|
event = NfcWorkerEventDetectedClassic4k;
|
|
|
|
}
|
|
|
|
nfc_worker->callback(event, nfc_worker->context);
|
|
|
|
card_found_notified = true;
|
|
|
|
card_removed_notified = false;
|
|
|
|
}
|
|
|
|
FURI_LOG_D(
|
|
|
|
TAG,
|
|
|
|
"Try to auth to sector %d with key %04lx%08lx",
|
|
|
|
curr_sector,
|
|
|
|
(uint32_t)(curr_key >> 32),
|
|
|
|
(uint32_t)curr_key);
|
|
|
|
if(mf_classic_auth_attempt(&tx_rx_ctx, &auth_ctx, curr_key)) {
|
|
|
|
sector_key_found = true;
|
|
|
|
if((auth_ctx.key_a != MF_CLASSIC_NO_KEY) &&
|
|
|
|
(auth_ctx.key_b != MF_CLASSIC_NO_KEY))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Notify that no tag is availalble
|
|
|
|
FURI_LOG_D(TAG, "Can't find tags");
|
|
|
|
if(!card_removed_notified) {
|
|
|
|
event = NfcWorkerEventNoCardDetected;
|
|
|
|
nfc_worker->callback(event, nfc_worker->context);
|
|
|
|
card_removed_notified = true;
|
|
|
|
card_found_notified = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(nfc_worker->state != NfcWorkerStateReadMifareClassic) break;
|
2022-03-31 14:57:23 +00:00
|
|
|
osDelay(1);
|
2022-03-23 22:14:34 +00:00
|
|
|
}
|
|
|
|
if(nfc_worker->state != NfcWorkerStateReadMifareClassic) break;
|
|
|
|
if(sector_key_found) {
|
|
|
|
// Notify that keys were found
|
|
|
|
if(auth_ctx.key_a != MF_CLASSIC_NO_KEY) {
|
|
|
|
FURI_LOG_I(
|
|
|
|
TAG,
|
|
|
|
"Sector %d key A: %04lx%08lx",
|
|
|
|
curr_sector,
|
|
|
|
(uint32_t)(auth_ctx.key_a >> 32),
|
|
|
|
(uint32_t)auth_ctx.key_a);
|
|
|
|
event = NfcWorkerEventFoundKeyA;
|
|
|
|
nfc_worker->callback(event, nfc_worker->context);
|
|
|
|
}
|
|
|
|
if(auth_ctx.key_b != MF_CLASSIC_NO_KEY) {
|
|
|
|
FURI_LOG_I(
|
|
|
|
TAG,
|
|
|
|
"Sector %d key B: %04lx%08lx",
|
|
|
|
curr_sector,
|
|
|
|
(uint32_t)(auth_ctx.key_b >> 32),
|
|
|
|
(uint32_t)auth_ctx.key_b);
|
|
|
|
event = NfcWorkerEventFoundKeyB;
|
|
|
|
nfc_worker->callback(event, nfc_worker->context);
|
|
|
|
}
|
|
|
|
// Add sectors to read sequence
|
|
|
|
mf_classic_reader_add_sector(&reader, curr_sector, auth_ctx.key_a, auth_ctx.key_b);
|
|
|
|
}
|
|
|
|
nfc_mf_classic_dict_reset(nfc_worker->dict_stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nfc_worker->state == NfcWorkerStateReadMifareClassic) {
|
|
|
|
FURI_LOG_I(TAG, "Found keys to %d sectors. Start reading sectors", reader.sectors_to_read);
|
|
|
|
uint8_t sectors_read =
|
|
|
|
mf_classic_read_card(&tx_rx_ctx, &reader, &nfc_worker->dev_data->mf_classic_data);
|
|
|
|
if(sectors_read) {
|
|
|
|
event = NfcWorkerEventSuccess;
|
2022-04-19 15:23:58 +00:00
|
|
|
nfc_worker->dev_data->protocol = NfcDeviceProtocolMifareClassic;
|
2022-03-23 22:14:34 +00:00
|
|
|
FURI_LOG_I(TAG, "Successfully read %d sectors", sectors_read);
|
|
|
|
} else {
|
|
|
|
event = NfcWorkerEventFail;
|
|
|
|
FURI_LOG_W(TAG, "Failed to read any sector");
|
|
|
|
}
|
|
|
|
nfc_worker->callback(event, nfc_worker->context);
|
|
|
|
}
|
|
|
|
|
|
|
|
nfc_mf_classic_dict_close_file(nfc_worker->dict_stream);
|
|
|
|
stream_free(nfc_worker->dict_stream);
|
|
|
|
}
|
|
|
|
|
2022-05-24 14:00:15 +00:00
|
|
|
void nfc_worker_emulate_mifare_classic(NfcWorker* nfc_worker) {
|
|
|
|
FuriHalNfcTxRxContext tx_rx;
|
|
|
|
FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data;
|
|
|
|
MfClassicEmulator emulator = {
|
|
|
|
.cuid = nfc_util_bytes2num(&nfc_data->uid[nfc_data->uid_len - 4], 4),
|
|
|
|
.data = nfc_worker->dev_data->mf_classic_data,
|
|
|
|
.data_changed = false,
|
|
|
|
};
|
|
|
|
NfcaSignal* nfca_signal = nfca_signal_alloc();
|
|
|
|
tx_rx.nfca_signal = nfca_signal;
|
|
|
|
|
|
|
|
while(nfc_worker->state == NfcWorkerStateEmulateMifareClassic) {
|
|
|
|
if(furi_hal_nfc_listen(
|
|
|
|
nfc_data->uid, nfc_data->uid_len, nfc_data->atqa, nfc_data->sak, true, 300)) {
|
|
|
|
mf_classic_emulator(&emulator, &tx_rx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(emulator.data_changed) {
|
|
|
|
nfc_worker->dev_data->mf_classic_data = emulator.data;
|
|
|
|
if(nfc_worker->callback) {
|
|
|
|
nfc_worker->callback(NfcWorkerEventSuccess, nfc_worker->context);
|
|
|
|
}
|
|
|
|
emulator.data_changed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nfca_signal_free(nfca_signal);
|
|
|
|
}
|
|
|
|
|
2022-03-23 13:45:37 +00:00
|
|
|
void nfc_worker_read_mifare_desfire(NfcWorker* nfc_worker) {
|
|
|
|
ReturnCode err;
|
|
|
|
uint8_t tx_buff[64] = {};
|
|
|
|
uint16_t tx_len = 0;
|
|
|
|
uint8_t rx_buff[512] = {};
|
|
|
|
uint16_t rx_len;
|
|
|
|
NfcDeviceData* result = nfc_worker->dev_data;
|
|
|
|
nfc_device_data_clear(result);
|
|
|
|
MifareDesfireData* data = &result->mf_df_data;
|
2022-04-19 15:23:58 +00:00
|
|
|
FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data;
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
while(nfc_worker->state == NfcWorkerStateReadMifareDesfire) {
|
2022-04-19 15:23:58 +00:00
|
|
|
furi_hal_nfc_sleep();
|
|
|
|
if(!furi_hal_nfc_detect(nfc_data, 300)) {
|
2022-03-23 13:45:37 +00:00
|
|
|
osDelay(100);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
memset(data, 0, sizeof(MifareDesfireData));
|
2022-04-19 15:23:58 +00:00
|
|
|
if(nfc_data->type != FuriHalNfcTypeA ||
|
|
|
|
!mf_df_check_card_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak)) {
|
2022-03-23 13:45:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Tag is not DESFire");
|
|
|
|
osDelay(100);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
FURI_LOG_D(TAG, "Found DESFire tag");
|
|
|
|
|
2022-04-19 15:23:58 +00:00
|
|
|
result->protocol = NfcDeviceProtocolMifareDesfire;
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
// Get DESFire version
|
|
|
|
tx_len = mf_df_prepare_get_version(tx_buff);
|
2022-04-19 15:23:58 +00:00
|
|
|
err = furi_hal_nfc_exchange_full(tx_buff, tx_len, rx_buff, sizeof(rx_buff), &rx_len);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(err != ERR_NONE) {
|
|
|
|
FURI_LOG_W(TAG, "Bad exchange getting version, err: %d", err);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(!mf_df_parse_get_version_response(rx_buff, rx_len, &data->version)) {
|
|
|
|
FURI_LOG_W(TAG, "Bad DESFire GET_VERSION response");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_len = mf_df_prepare_get_free_memory(tx_buff);
|
2022-04-19 15:23:58 +00:00
|
|
|
err = furi_hal_nfc_exchange_full(tx_buff, tx_len, rx_buff, sizeof(rx_buff), &rx_len);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(err == ERR_NONE) {
|
|
|
|
data->free_memory = malloc(sizeof(MifareDesfireFreeMemory));
|
|
|
|
memset(data->free_memory, 0, sizeof(MifareDesfireFreeMemory));
|
|
|
|
if(!mf_df_parse_get_free_memory_response(rx_buff, rx_len, data->free_memory)) {
|
|
|
|
FURI_LOG_D(TAG, "Bad DESFire GET_FREE_MEMORY response (normal for pre-EV1 cards)");
|
|
|
|
free(data->free_memory);
|
|
|
|
data->free_memory = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_len = mf_df_prepare_get_key_settings(tx_buff);
|
2022-04-19 15:23:58 +00:00
|
|
|
err = furi_hal_nfc_exchange_full(tx_buff, tx_len, rx_buff, sizeof(rx_buff), &rx_len);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(err != ERR_NONE) {
|
|
|
|
FURI_LOG_D(TAG, "Bad exchange getting key settings, err: %d", err);
|
|
|
|
} else {
|
|
|
|
data->master_key_settings = malloc(sizeof(MifareDesfireKeySettings));
|
|
|
|
memset(data->master_key_settings, 0, sizeof(MifareDesfireKeySettings));
|
|
|
|
if(!mf_df_parse_get_key_settings_response(rx_buff, rx_len, data->master_key_settings)) {
|
|
|
|
FURI_LOG_W(TAG, "Bad DESFire GET_KEY_SETTINGS response");
|
|
|
|
free(data->master_key_settings);
|
|
|
|
data->master_key_settings = NULL;
|
2022-04-25 14:59:48 +00:00
|
|
|
continue;
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MifareDesfireKeyVersion** key_version_head =
|
|
|
|
&data->master_key_settings->key_version_head;
|
|
|
|
for(uint8_t key_id = 0; key_id < data->master_key_settings->max_keys; key_id++) {
|
|
|
|
tx_len = mf_df_prepare_get_key_version(tx_buff, key_id);
|
2022-04-19 15:23:58 +00:00
|
|
|
err =
|
|
|
|
furi_hal_nfc_exchange_full(tx_buff, tx_len, rx_buff, sizeof(rx_buff), &rx_len);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(err != ERR_NONE) {
|
|
|
|
FURI_LOG_W(TAG, "Bad exchange getting key version, err: %d", err);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MifareDesfireKeyVersion* key_version = malloc(sizeof(MifareDesfireKeyVersion));
|
|
|
|
memset(key_version, 0, sizeof(MifareDesfireKeyVersion));
|
|
|
|
key_version->id = key_id;
|
|
|
|
if(!mf_df_parse_get_key_version_response(rx_buff, rx_len, key_version)) {
|
|
|
|
FURI_LOG_W(TAG, "Bad DESFire GET_KEY_VERSION response");
|
|
|
|
free(key_version);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*key_version_head = key_version;
|
|
|
|
key_version_head = &key_version->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_len = mf_df_prepare_get_application_ids(tx_buff);
|
2022-04-19 15:23:58 +00:00
|
|
|
err = furi_hal_nfc_exchange_full(tx_buff, tx_len, rx_buff, sizeof(rx_buff), &rx_len);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(err != ERR_NONE) {
|
|
|
|
FURI_LOG_W(TAG, "Bad exchange getting application IDs, err: %d", err);
|
|
|
|
} else {
|
|
|
|
if(!mf_df_parse_get_application_ids_response(rx_buff, rx_len, &data->app_head)) {
|
|
|
|
FURI_LOG_W(TAG, "Bad DESFire GET_APPLICATION_IDS response");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
|
|
|
|
tx_len = mf_df_prepare_select_application(tx_buff, app->id);
|
2022-04-19 15:23:58 +00:00
|
|
|
err = furi_hal_nfc_exchange_full(tx_buff, tx_len, rx_buff, sizeof(rx_buff), &rx_len);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(!mf_df_parse_select_application_response(rx_buff, rx_len)) {
|
|
|
|
FURI_LOG_W(TAG, "Bad exchange selecting application, err: %d", err);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
tx_len = mf_df_prepare_get_key_settings(tx_buff);
|
2022-04-19 15:23:58 +00:00
|
|
|
err = furi_hal_nfc_exchange_full(tx_buff, tx_len, rx_buff, sizeof(rx_buff), &rx_len);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(err != ERR_NONE) {
|
|
|
|
FURI_LOG_W(TAG, "Bad exchange getting key settings, err: %d", err);
|
|
|
|
} else {
|
|
|
|
app->key_settings = malloc(sizeof(MifareDesfireKeySettings));
|
|
|
|
memset(app->key_settings, 0, sizeof(MifareDesfireKeySettings));
|
|
|
|
if(!mf_df_parse_get_key_settings_response(rx_buff, rx_len, app->key_settings)) {
|
|
|
|
FURI_LOG_W(TAG, "Bad DESFire GET_KEY_SETTINGS response");
|
|
|
|
free(app->key_settings);
|
|
|
|
app->key_settings = NULL;
|
2022-04-25 14:59:48 +00:00
|
|
|
continue;
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MifareDesfireKeyVersion** key_version_head = &app->key_settings->key_version_head;
|
|
|
|
for(uint8_t key_id = 0; key_id < app->key_settings->max_keys; key_id++) {
|
|
|
|
tx_len = mf_df_prepare_get_key_version(tx_buff, key_id);
|
2022-04-19 15:23:58 +00:00
|
|
|
err = furi_hal_nfc_exchange_full(
|
|
|
|
tx_buff, tx_len, rx_buff, sizeof(rx_buff), &rx_len);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(err != ERR_NONE) {
|
|
|
|
FURI_LOG_W(TAG, "Bad exchange getting key version, err: %d", err);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MifareDesfireKeyVersion* key_version = malloc(sizeof(MifareDesfireKeyVersion));
|
|
|
|
memset(key_version, 0, sizeof(MifareDesfireKeyVersion));
|
|
|
|
key_version->id = key_id;
|
|
|
|
if(!mf_df_parse_get_key_version_response(rx_buff, rx_len, key_version)) {
|
|
|
|
FURI_LOG_W(TAG, "Bad DESFire GET_KEY_VERSION response");
|
|
|
|
free(key_version);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*key_version_head = key_version;
|
|
|
|
key_version_head = &key_version->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_len = mf_df_prepare_get_file_ids(tx_buff);
|
2022-04-19 15:23:58 +00:00
|
|
|
err = furi_hal_nfc_exchange_full(tx_buff, tx_len, rx_buff, sizeof(rx_buff), &rx_len);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(err != ERR_NONE) {
|
|
|
|
FURI_LOG_W(TAG, "Bad exchange getting file IDs, err: %d", err);
|
|
|
|
} else {
|
|
|
|
if(!mf_df_parse_get_file_ids_response(rx_buff, rx_len, &app->file_head)) {
|
|
|
|
FURI_LOG_W(TAG, "Bad DESFire GET_FILE_IDS response");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(MifareDesfireFile* file = app->file_head; file; file = file->next) {
|
|
|
|
tx_len = mf_df_prepare_get_file_settings(tx_buff, file->id);
|
2022-04-19 15:23:58 +00:00
|
|
|
err =
|
|
|
|
furi_hal_nfc_exchange_full(tx_buff, tx_len, rx_buff, sizeof(rx_buff), &rx_len);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(err != ERR_NONE) {
|
|
|
|
FURI_LOG_W(TAG, "Bad exchange getting file settings, err: %d", err);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(!mf_df_parse_get_file_settings_response(rx_buff, rx_len, file)) {
|
|
|
|
FURI_LOG_W(TAG, "Bad DESFire GET_FILE_SETTINGS response");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch(file->type) {
|
|
|
|
case MifareDesfireFileTypeStandard:
|
|
|
|
case MifareDesfireFileTypeBackup:
|
|
|
|
tx_len = mf_df_prepare_read_data(tx_buff, file->id, 0, 0);
|
|
|
|
break;
|
|
|
|
case MifareDesfireFileTypeValue:
|
|
|
|
tx_len = mf_df_prepare_get_value(tx_buff, file->id);
|
|
|
|
break;
|
|
|
|
case MifareDesfireFileTypeLinearRecord:
|
|
|
|
case MifareDesfireFileTypeCyclicRecord:
|
|
|
|
tx_len = mf_df_prepare_read_records(tx_buff, file->id, 0, 0);
|
|
|
|
break;
|
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
err =
|
|
|
|
furi_hal_nfc_exchange_full(tx_buff, tx_len, rx_buff, sizeof(rx_buff), &rx_len);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(err != ERR_NONE) {
|
|
|
|
FURI_LOG_W(TAG, "Bad exchange reading file %d, err: %d", file->id, err);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(!mf_df_parse_read_data_response(rx_buff, rx_len, file)) {
|
|
|
|
FURI_LOG_W(TAG, "Bad response reading file %d", file->id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify caller and exit
|
|
|
|
if(nfc_worker->callback) {
|
2022-03-23 22:14:34 +00:00
|
|
|
nfc_worker->callback(NfcWorkerEventSuccess, nfc_worker->context);
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|