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"
|
2021-08-08 18:03:25 +00:00
|
|
|
#include <furi-hal.h>
|
2021-05-18 18:12:01 +00:00
|
|
|
#include "nfc_protocols/emv_decoder.h"
|
2021-06-15 14:54:09 +00:00
|
|
|
#include "nfc_protocols/mifare_ultralight.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() {
|
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 = furi_alloc(sizeof(NfcWorker));
|
|
|
|
// Worker thread attributes
|
2021-11-11 16:17:50 +00:00
|
|
|
nfc_worker->thread_attr.name = "NfcWorker";
|
2021-05-18 18:12:01 +00:00
|
|
|
nfc_worker->thread_attr.stack_size = 8192;
|
2021-06-24 08:46:37 +00:00
|
|
|
nfc_worker->callback = NULL;
|
|
|
|
nfc_worker->context = NULL;
|
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
|
2021-08-08 18:03:25 +00:00
|
|
|
if(!furi_hal_nfc_is_busy()) {
|
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);
|
|
|
|
} else {
|
|
|
|
nfc_worker_change_state(nfc_worker, NfcWorkerStateBroken);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nfc_worker;
|
|
|
|
}
|
|
|
|
|
2021-05-06 19:51:20 +00:00
|
|
|
void nfc_worker_free(NfcWorker* nfc_worker) {
|
|
|
|
furi_assert(nfc_worker);
|
|
|
|
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);
|
|
|
|
while(nfc_worker->state != NfcWorkerStateReady) {
|
|
|
|
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);
|
|
|
|
nfc_worker->thread = osThreadNew(nfc_worker_task, nfc_worker, &nfc_worker->thread_attr);
|
|
|
|
}
|
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
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 *******************************/
|
|
|
|
|
2020-11-12 09:44:35 +00:00
|
|
|
void 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_power_insomnia_enter();
|
|
|
|
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);
|
2021-05-18 18:12:01 +00:00
|
|
|
} else if(nfc_worker->state == NfcWorkerStateReadEMV) {
|
|
|
|
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);
|
2021-07-22 06:05:07 +00:00
|
|
|
} else if(nfc_worker->state == NfcWorkerStateReadMifareUl) {
|
|
|
|
nfc_worker_read_mifare_ul(nfc_worker);
|
|
|
|
} else if(nfc_worker->state == NfcWorkerStateEmulateMifareUl) {
|
|
|
|
nfc_worker_emulate_mifare_ul(nfc_worker);
|
2021-06-24 08:46:37 +00:00
|
|
|
} else if(nfc_worker->state == NfcWorkerStateField) {
|
2021-06-30 17:43:29 +00:00
|
|
|
nfc_worker_field(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
|
|
|
}
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
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);
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_power_insomnia_exit();
|
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
|
|
|
osThreadExit();
|
|
|
|
}
|
|
|
|
|
2021-06-24 08:46:37 +00:00
|
|
|
void nfc_worker_detect(NfcWorker* nfc_worker) {
|
|
|
|
rfalNfcDevice* dev_list;
|
|
|
|
rfalNfcDevice* dev;
|
|
|
|
uint8_t dev_cnt;
|
2021-08-31 23:07:53 +00:00
|
|
|
NfcDeviceCommonData* result = &nfc_worker->dev_data->nfc_data;
|
2021-06-24 08:46:37 +00:00
|
|
|
|
|
|
|
while(nfc_worker->state == NfcWorkerStateDetect) {
|
2021-08-08 18:03:25 +00:00
|
|
|
if(furi_hal_nfc_detect(&dev_list, &dev_cnt, 1000, true)) {
|
2021-06-24 08:46:37 +00:00
|
|
|
// Process first found device
|
|
|
|
dev = &dev_list[0];
|
2021-06-30 17:43:29 +00:00
|
|
|
result->uid_len = dev->nfcidLen;
|
|
|
|
memcpy(result->uid, dev->nfcid, dev->nfcidLen);
|
2021-06-24 08:46:37 +00:00
|
|
|
if(dev->type == RFAL_NFC_LISTEN_TYPE_NFCA) {
|
2021-06-30 17:43:29 +00:00
|
|
|
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)) {
|
2021-07-22 06:05:07 +00:00
|
|
|
result->protocol = NfcDeviceProtocolMifareUl;
|
|
|
|
} else if(dev->rfInterface == RFAL_NFC_INTERFACE_ISODEP) {
|
|
|
|
result->protocol = NfcDeviceProtocolEMV;
|
2021-06-30 17:43:29 +00:00
|
|
|
} else {
|
|
|
|
result->protocol = NfcDeviceProtocolUnknown;
|
|
|
|
}
|
2021-06-24 08:46:37 +00:00
|
|
|
} else if(dev->type == RFAL_NFC_LISTEN_TYPE_NFCB) {
|
2021-06-30 17:43:29 +00:00
|
|
|
result->device = NfcDeviceNfcb;
|
2021-06-24 08:46:37 +00:00
|
|
|
} else if(dev->type == RFAL_NFC_LISTEN_TYPE_NFCF) {
|
2021-06-30 17:43:29 +00:00
|
|
|
result->device = NfcDeviceNfcf;
|
2021-06-24 08:46:37 +00:00
|
|
|
} else if(dev->type == RFAL_NFC_LISTEN_TYPE_NFCV) {
|
2021-06-30 17:43:29 +00:00
|
|
|
result->device = NfcDeviceNfcv;
|
2021-06-24 08:46:37 +00:00
|
|
|
}
|
2021-06-30 17:43:29 +00:00
|
|
|
// Notify caller and exit
|
|
|
|
if(nfc_worker->callback) {
|
|
|
|
nfc_worker->callback(nfc_worker->context);
|
|
|
|
}
|
|
|
|
break;
|
2021-06-24 08:46:37 +00:00
|
|
|
}
|
|
|
|
osDelay(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_worker_emulate(NfcWorker* nfc_worker) {
|
2021-08-31 23:07:53 +00:00
|
|
|
NfcDeviceCommonData* data = &nfc_worker->dev_data->nfc_data;
|
2021-06-24 08:46:37 +00:00
|
|
|
while(nfc_worker->state == NfcWorkerStateEmulate) {
|
2021-08-16 21:45:04 +00:00
|
|
|
if(furi_hal_nfc_listen(data->uid, data->uid_len, data->atqa, data->sak, false, 100)) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Reader detected");
|
2021-06-24 08:46:37 +00:00
|
|
|
}
|
|
|
|
osDelay(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 06:05:07 +00:00
|
|
|
void nfc_worker_read_emv_app(NfcWorker* nfc_worker) {
|
|
|
|
ReturnCode err;
|
|
|
|
rfalNfcDevice* dev_list;
|
|
|
|
EmvApplication emv_app = {};
|
|
|
|
uint8_t dev_cnt = 0;
|
|
|
|
uint8_t tx_buff[255] = {};
|
|
|
|
uint16_t tx_len = 0;
|
|
|
|
uint8_t* rx_buff;
|
|
|
|
uint16_t* rx_len;
|
|
|
|
NfcDeviceData* result = nfc_worker->dev_data;
|
|
|
|
|
|
|
|
while(nfc_worker->state == NfcWorkerStateReadEMVApp) {
|
|
|
|
memset(&emv_app, 0, sizeof(emv_app));
|
2021-08-08 18:03:25 +00:00
|
|
|
if(furi_hal_nfc_detect(&dev_list, &dev_cnt, 1000, false)) {
|
2021-07-22 06:05:07 +00:00
|
|
|
// Card was found. Check that it supports EMV
|
|
|
|
if(dev_list[0].rfInterface == RFAL_NFC_INTERFACE_ISODEP) {
|
|
|
|
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(
|
|
|
|
result->nfc_data.uid, dev_list[0].dev.nfca.nfcId1, result->nfc_data.uid_len);
|
|
|
|
result->nfc_data.protocol = NfcDeviceProtocolEMV;
|
|
|
|
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Send select PPSE command");
|
2021-07-22 06:05:07 +00:00
|
|
|
tx_len = emv_prepare_select_ppse(tx_buff);
|
2021-08-08 18:03:25 +00:00
|
|
|
err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false);
|
2021-07-22 06:05:07 +00:00
|
|
|
if(err != ERR_NONE) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Error during selection PPSE request: %d", err);
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-07-22 06:05:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Select PPSE response received. Start parsing response");
|
2021-07-22 06:05:07 +00:00
|
|
|
if(emv_decode_ppse_response(rx_buff, *rx_len, &emv_app)) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Select PPSE responce parced");
|
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) {
|
|
|
|
nfc_worker->callback(nfc_worker->context);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't find pay application");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-07-22 06:05:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Can't find EMV card
|
2021-11-12 13:04:35 +00:00
|
|
|
FURI_LOG_W(TAG, "Card doesn't support EMV");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Can't find EMV card
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't find any cards");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
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) {
|
|
|
|
ReturnCode err;
|
|
|
|
rfalNfcDevice* dev_list;
|
|
|
|
EmvApplication emv_app = {};
|
|
|
|
uint8_t dev_cnt = 0;
|
|
|
|
uint8_t tx_buff[255] = {};
|
|
|
|
uint16_t tx_len = 0;
|
|
|
|
uint8_t* rx_buff;
|
|
|
|
uint16_t* rx_len;
|
2021-07-22 06:05:07 +00:00
|
|
|
NfcDeviceData* result = nfc_worker->dev_data;
|
2021-05-18 18:12:01 +00:00
|
|
|
|
|
|
|
while(nfc_worker->state == NfcWorkerStateReadEMV) {
|
|
|
|
memset(&emv_app, 0, sizeof(emv_app));
|
2021-08-08 18:03:25 +00:00
|
|
|
if(furi_hal_nfc_detect(&dev_list, &dev_cnt, 1000, false)) {
|
2021-05-18 18:12:01 +00:00
|
|
|
// Card was found. Check that it supports EMV
|
|
|
|
if(dev_list[0].rfInterface == RFAL_NFC_INTERFACE_ISODEP) {
|
2021-07-22 06:05:07 +00:00
|
|
|
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(
|
|
|
|
result->nfc_data.uid, dev_list[0].dev.nfca.nfcId1, result->nfc_data.uid_len);
|
|
|
|
result->nfc_data.protocol = NfcDeviceProtocolEMV;
|
|
|
|
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Send select PPSE command");
|
2021-05-18 18:12:01 +00:00
|
|
|
tx_len = emv_prepare_select_ppse(tx_buff);
|
2021-08-08 18:03:25 +00:00
|
|
|
err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false);
|
2021-05-18 18:12:01 +00:00
|
|
|
if(err != ERR_NONE) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Error during selection PPSE request: %d", err);
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-05-18 18:12:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Select PPSE response received. Start parsing response");
|
2021-05-18 18:12:01 +00:00
|
|
|
if(emv_decode_ppse_response(rx_buff, *rx_len, &emv_app)) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Select PPSE responce parced");
|
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);
|
2021-05-18 18:12:01 +00:00
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't find pay application");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-05-18 18:12:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Starting application ...");
|
2021-05-18 18:12:01 +00:00
|
|
|
tx_len = emv_prepare_select_app(tx_buff, &emv_app);
|
2021-08-08 18:03:25 +00:00
|
|
|
err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false);
|
2021-05-18 18:12:01 +00:00
|
|
|
if(err != ERR_NONE) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Error during application selection request: %d", err);
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-05-18 18:12:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Select application response received. Start parsing response");
|
2021-05-18 18:12:01 +00:00
|
|
|
if(emv_decode_select_app_response(rx_buff, *rx_len, &emv_app)) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Card name: %s", emv_app.name);
|
2021-07-22 06:05:07 +00:00
|
|
|
memcpy(result->emv_data.name, emv_app.name, sizeof(emv_app.name));
|
2021-10-05 05:14:19 +00:00
|
|
|
} else if(emv_app.pdol.size > 0) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't find card name, but PDOL is present.");
|
2021-05-18 18:12:01 +00:00
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't find card name or PDOL");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-05-18 18:12:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Starting Get Processing Options command ...");
|
2021-05-18 18:12:01 +00:00
|
|
|
tx_len = emv_prepare_get_proc_opt(tx_buff, &emv_app);
|
2021-08-08 18:03:25 +00:00
|
|
|
err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false);
|
2021-05-18 18:12:01 +00:00
|
|
|
if(err != ERR_NONE) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Error during Get Processing Options command: %d", err);
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-05-18 18:12:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(emv_decode_get_proc_opt(rx_buff, *rx_len, &emv_app)) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Card number parsed");
|
2021-10-05 05:14:19 +00:00
|
|
|
result->emv_data.number_len = emv_app.card_number_len;
|
|
|
|
memcpy(result->emv_data.number, emv_app.card_number, emv_app.card_number_len);
|
2021-06-30 17:43:29 +00:00
|
|
|
// Notify caller and exit
|
|
|
|
if(nfc_worker->callback) {
|
|
|
|
nfc_worker->callback(nfc_worker->context);
|
|
|
|
}
|
|
|
|
break;
|
2021-05-18 18:12:01 +00:00
|
|
|
} else {
|
|
|
|
// Mastercard doesn't give PAN / card number as GPO response
|
|
|
|
// Iterate over all files found in application
|
|
|
|
bool pan_found = false;
|
|
|
|
for(uint8_t i = 0; (i < emv_app.afl.size) && !pan_found; i += 4) {
|
|
|
|
uint8_t sfi = emv_app.afl.data[i] >> 3;
|
|
|
|
uint8_t record_start = emv_app.afl.data[i + 1];
|
|
|
|
uint8_t record_end = emv_app.afl.data[i + 2];
|
|
|
|
|
|
|
|
// Iterate over all records in file
|
|
|
|
for(uint8_t record = record_start; record <= record_end; ++record) {
|
|
|
|
tx_len = emv_prepare_read_sfi_record(tx_buff, sfi, record);
|
2021-08-08 18:03:25 +00:00
|
|
|
err = furi_hal_nfc_data_exchange(
|
2021-05-25 23:54:44 +00:00
|
|
|
tx_buff, tx_len, &rx_buff, &rx_len, false);
|
2021-05-18 18:12:01 +00:00
|
|
|
if(err != ERR_NONE) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(
|
2021-11-12 13:04:35 +00:00
|
|
|
TAG,
|
2021-05-18 18:12:01 +00:00
|
|
|
"Error reading application sfi %d, record %d",
|
|
|
|
sfi,
|
|
|
|
record);
|
|
|
|
}
|
|
|
|
if(emv_decode_read_sfi_record(rx_buff, *rx_len, &emv_app)) {
|
|
|
|
pan_found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(pan_found) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Card PAN found");
|
2021-10-05 05:14:19 +00:00
|
|
|
result->emv_data.number_len = emv_app.card_number_len;
|
2021-07-22 06:05:07 +00:00
|
|
|
memcpy(
|
|
|
|
result->emv_data.number,
|
|
|
|
emv_app.card_number,
|
2021-10-05 05:14:19 +00:00
|
|
|
result->emv_data.number_len);
|
2021-08-04 18:58:11 +00:00
|
|
|
if(emv_app.exp_month) {
|
|
|
|
result->emv_data.exp_mon = emv_app.exp_month;
|
|
|
|
result->emv_data.exp_year = emv_app.exp_year;
|
|
|
|
}
|
2021-08-20 19:56:43 +00:00
|
|
|
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) {
|
|
|
|
nfc_worker->callback(nfc_worker->context);
|
|
|
|
}
|
|
|
|
break;
|
2021-05-18 18:12:01 +00:00
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't read card number");
|
2021-05-18 18:12:01 +00:00
|
|
|
}
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-05-18 18:12:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Can't find EMV card
|
2021-11-12 13:04:35 +00:00
|
|
|
FURI_LOG_W(TAG, "Card doesn't support EMV");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-05-18 18:12:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Can't find EMV card
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't find any cards");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
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) {
|
2021-05-25 23:54:44 +00:00
|
|
|
ReturnCode err;
|
|
|
|
uint8_t tx_buff[255] = {};
|
|
|
|
uint16_t tx_len = 0;
|
|
|
|
uint8_t* rx_buff;
|
|
|
|
uint16_t* rx_len;
|
2021-08-31 23:07:53 +00:00
|
|
|
NfcDeviceCommonData params = {
|
2021-06-30 17:43:29 +00:00
|
|
|
.uid = {0xCF, 0x72, 0xd4, 0x40},
|
|
|
|
.uid_len = 4,
|
|
|
|
.atqa = {0x00, 0x04},
|
|
|
|
.sak = 0x20,
|
|
|
|
.device = NfcDeviceNfca,
|
|
|
|
.protocol = NfcDeviceProtocolEMV,
|
|
|
|
};
|
2021-08-04 18:58:11 +00:00
|
|
|
// Test RX data
|
|
|
|
const uint8_t debug_rx[] = {
|
|
|
|
0xba, 0x0b, 0xba, 0xba, 0x20, 0x00, 0x02, 0x28, 0xde, 0xad, 0xbe, 0xef, 0x00, 0xca, 0xca,
|
|
|
|
0xca, 0xfe, 0xfa, 0xce, 0x14, 0x88, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
|
|
|
|
0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0xba,
|
|
|
|
0x0b, 0xba, 0xba, 0x20, 0x00, 0x02, 0x28, 0xde, 0xad, 0xbe, 0xef, 0x00, 0xca, 0xca, 0xca,
|
|
|
|
0xfe, 0xfa, 0xce, 0x14, 0x88, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
|
|
|
|
0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0xba, 0x0b,
|
|
|
|
0xba, 0xba, 0x20, 0x00, 0x02, 0x28, 0xde, 0xad, 0xbe, 0xef, 0x00, 0xca, 0xca, 0xca, 0xfe,
|
|
|
|
0xfa, 0xce, 0x14, 0x88, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
|
|
|
|
0xbb, 0xcc, 0xdd, 0xee, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0xba, 0x0b, 0xba,
|
|
|
|
0xba, 0x20, 0x00, 0x02, 0x28, 0xde, 0xad, 0xbe, 0xef, 0x00, 0xca, 0xca, 0xca, 0xfe, 0xfa,
|
|
|
|
0xce, 0x14, 0x88, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
|
|
|
|
0xcc, 0xdd, 0xee, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0xba, 0x0b, 0xba, 0xba,
|
|
|
|
0x20, 0x00, 0x02, 0x28, 0xde, 0xad, 0xbe, 0xef, 0x00, 0xca, 0xca, 0xca, 0xfe, 0xfa, 0xce,
|
|
|
|
0x14, 0x88, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc,
|
|
|
|
0xdd, 0xee, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0xba, 0x0b, 0xba, 0xba, 0x20,
|
|
|
|
0x00, 0x02, 0x28, 0xde, 0xad, 0xbe, 0xef, 0x00, 0xca, 0xca, 0xca, 0xfe, 0xfa, 0xce, 0x14,
|
|
|
|
0x88, 0x00};
|
|
|
|
// Test TX data
|
|
|
|
const uint8_t debug_tx[] = {
|
|
|
|
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32,
|
|
|
|
0x10, 0x14, 0x88, 0x02, 0x28, 0x00, 0x00, 0xca, 0xca, 0x00, 0xc0, 0xc0, 0x00, 0xde, 0xad,
|
|
|
|
0xbe, 0xef, 0xce, 0xee, 0xec, 0xca, 0xfe, 0xba, 0xba, 0xb0, 0xb0, 0xac, 0xdc, 0x11, 0x12,
|
|
|
|
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
|
|
|
|
0x14, 0x88, 0x02, 0x28, 0x00, 0x00, 0xca, 0xca, 0x00, 0xc0, 0xc0, 0x00, 0xde, 0xad, 0xbe,
|
|
|
|
0xef, 0xce, 0xee, 0xec, 0xca, 0xfe, 0xba, 0xba, 0xb0, 0xb0, 0xac, 0xdc, 0x11, 0x12, 0x34,
|
|
|
|
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x14,
|
|
|
|
0x88, 0x02, 0x28, 0x00, 0x00, 0xca, 0xca, 0x00, 0xc0, 0xc0, 0x00, 0xde, 0xad, 0xbe, 0xef,
|
|
|
|
0xce, 0xee, 0xec, 0xca, 0xfe, 0xba, 0xba, 0xb0, 0xb0, 0xac, 0xdc, 0x11, 0x12, 0x34, 0x56,
|
|
|
|
0x78, 0x9a, 0xbc, 0xde, 0xff, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x14, 0x88,
|
|
|
|
0x02, 0x28, 0x00, 0x00, 0xca, 0xca, 0x00, 0xc0, 0xc0, 0x00, 0xde, 0xad, 0xbe, 0xef, 0xce,
|
|
|
|
0xee, 0xec, 0xca, 0xfe, 0xba, 0xba, 0xb0, 0xb0, 0xac, 0xdc, 0x11, 0x12, 0x34, 0x56, 0x78,
|
|
|
|
0x9a, 0xbc, 0xde, 0xff, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x14, 0x88, 0x02,
|
|
|
|
0x28, 0x00, 0x00, 0xca, 0xca, 0x00, 0xc0, 0xc0, 0x00, 0xde, 0xad, 0xbe, 0xef, 0xce, 0xee,
|
|
|
|
0xec, 0xca, 0xfe, 0xba, 0xba, 0xb0, 0xb0, 0xac, 0xdc, 0x11, 0x12, 0x34, 0x56, 0x78, 0x9a,
|
|
|
|
0xbc, 0xde, 0xff, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x14, 0x88, 0x02, 0x28,
|
|
|
|
0x00, 0x00};
|
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");
|
2021-05-25 23:54:44 +00:00
|
|
|
// Read data from POS terminal
|
2021-08-08 18:03:25 +00:00
|
|
|
err = furi_hal_nfc_data_exchange(NULL, 0, &rx_buff, &rx_len, false);
|
2021-05-25 23:54:44 +00:00
|
|
|
if(err == ERR_NONE) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Received Select PPSE");
|
2021-05-25 23:54:44 +00:00
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Error in 1st data exchange: select PPSE");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-05-25 23:54:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Transive SELECT PPSE ANS");
|
2021-05-25 23:54:44 +00:00
|
|
|
tx_len = emv_select_ppse_ans(tx_buff);
|
2021-08-08 18:03:25 +00:00
|
|
|
err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false);
|
2021-05-25 23:54:44 +00:00
|
|
|
if(err == ERR_NONE) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Received Select APP");
|
2021-05-25 23:54:44 +00:00
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Error in 2nd data exchange: select APP");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-05-25 23:54:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Transive SELECT APP ANS");
|
2021-05-25 23:54:44 +00:00
|
|
|
tx_len = emv_select_app_ans(tx_buff);
|
2021-08-08 18:03:25 +00:00
|
|
|
err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false);
|
2021-05-25 23:54:44 +00:00
|
|
|
if(err == ERR_NONE) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Received PDOL");
|
2021-05-25 23:54:44 +00:00
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Error in 3rd data exchange: receive PDOL");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-05-25 23:54:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Transive PDOL ANS");
|
2021-05-25 23:54:44 +00:00
|
|
|
tx_len = emv_get_proc_opt_ans(tx_buff);
|
2021-08-08 18:03:25 +00:00
|
|
|
err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false);
|
2021-05-25 23:54:44 +00:00
|
|
|
if(err == ERR_NONE) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Transive PDOL ANS");
|
2021-08-04 18:58:11 +00:00
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Error in 4rd data exchange: Transive PDOL ANS");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-08-04 18:58:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*rx_len != sizeof(debug_rx) || memcmp(rx_buff, debug_rx, sizeof(debug_rx))) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Failed long message test");
|
2021-08-04 18:58:11 +00:00
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Correct debug message received");
|
2021-08-04 18:58:11 +00:00
|
|
|
tx_len = sizeof(debug_tx);
|
2021-08-08 18:03:25 +00:00
|
|
|
err = furi_hal_nfc_data_exchange(
|
2021-08-04 18:58:11 +00:00
|
|
|
(uint8_t*)debug_tx, tx_len, &rx_buff, &rx_len, false);
|
|
|
|
if(err == ERR_NONE) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Transive Debug message");
|
2021-08-04 18:58:11 +00:00
|
|
|
}
|
2021-05-25 23:54:44 +00:00
|
|
|
}
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
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
|
|
|
}
|
|
|
|
osDelay(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 06:05:07 +00:00
|
|
|
void nfc_worker_read_mifare_ul(NfcWorker* nfc_worker) {
|
2021-06-15 14:54:09 +00:00
|
|
|
ReturnCode err;
|
|
|
|
rfalNfcDevice* dev_list;
|
|
|
|
uint8_t dev_cnt = 0;
|
|
|
|
uint8_t tx_buff[255] = {};
|
|
|
|
uint16_t tx_len = 0;
|
|
|
|
uint8_t* rx_buff;
|
|
|
|
uint16_t* rx_len;
|
2021-07-22 06:05:07 +00:00
|
|
|
MifareUlDevice mf_ul_read;
|
|
|
|
NfcDeviceData* result = nfc_worker->dev_data;
|
2021-06-15 14:54:09 +00:00
|
|
|
|
2021-07-22 06:05:07 +00:00
|
|
|
while(nfc_worker->state == NfcWorkerStateReadMifareUl) {
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-06-15 14:54:09 +00:00
|
|
|
memset(&mf_ul_read, 0, sizeof(mf_ul_read));
|
2021-08-08 18:03:25 +00:00
|
|
|
if(furi_hal_nfc_detect(&dev_list, &dev_cnt, 300, false)) {
|
2021-06-15 14:54:09 +00:00
|
|
|
if(dev_list[0].type == RFAL_NFC_LISTEN_TYPE_NFCA &&
|
|
|
|
mf_ul_check_card_type(
|
|
|
|
dev_list[0].dev.nfca.sensRes.anticollisionInfo,
|
|
|
|
dev_list[0].dev.nfca.sensRes.platformInfo,
|
|
|
|
dev_list[0].dev.nfca.selRes.sak)) {
|
|
|
|
// Get Mifare Ultralight version
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Found Mifare Ultralight tag. Reading tag version");
|
2021-06-15 14:54:09 +00:00
|
|
|
tx_len = mf_ul_prepare_get_version(tx_buff);
|
2021-08-08 18:03:25 +00:00
|
|
|
err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false);
|
2021-06-15 14:54:09 +00:00
|
|
|
if(err == ERR_NONE) {
|
|
|
|
mf_ul_parse_get_version_response(rx_buff, &mf_ul_read);
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(
|
2021-11-12 13:04:35 +00:00
|
|
|
TAG,
|
2021-06-15 14:54:09 +00:00
|
|
|
"Mifare Ultralight Type: %d, Pages: %d",
|
2021-12-21 12:33:17 +00:00
|
|
|
mf_ul_read.data.type,
|
2021-06-15 14:54:09 +00:00
|
|
|
mf_ul_read.pages_to_read);
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Reading signature ...");
|
2021-10-21 12:46:47 +00:00
|
|
|
tx_len = mf_ul_prepare_read_signature(tx_buff);
|
|
|
|
if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Failed reading signature");
|
2021-10-21 12:46:47 +00:00
|
|
|
memset(mf_ul_read.data.signature, 0, sizeof(mf_ul_read.data.signature));
|
|
|
|
} else {
|
|
|
|
mf_ul_parse_read_signature_response(rx_buff, &mf_ul_read);
|
|
|
|
}
|
2021-06-15 14:54:09 +00:00
|
|
|
} else if(err == ERR_TIMEOUT) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(
|
2021-11-12 13:04:35 +00:00
|
|
|
TAG,
|
2021-07-22 06:05:07 +00:00
|
|
|
"Card doesn't respond to GET VERSION command. Setting default read parameters");
|
2021-06-15 14:54:09 +00:00
|
|
|
err = ERR_NONE;
|
|
|
|
mf_ul_set_default_version(&mf_ul_read);
|
|
|
|
// Reinit device
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
|
|
|
if(!furi_hal_nfc_detect(&dev_list, &dev_cnt, 300, false)) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Lost connection. Restarting search");
|
2021-06-15 14:54:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(
|
2021-11-12 13:04:35 +00:00
|
|
|
TAG, "Error getting Mifare Ultralight version. Error code: %d", err);
|
2021-06-15 14:54:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mf_ul_read.support_fast_read) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Reading pages ...");
|
2021-06-15 14:54:09 +00:00
|
|
|
tx_len = mf_ul_prepare_fast_read(tx_buff, 0x00, mf_ul_read.pages_to_read - 1);
|
2021-08-08 18:03:25 +00:00
|
|
|
if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Failed reading pages");
|
2021-06-15 14:54:09 +00:00
|
|
|
continue;
|
2021-07-22 06:05:07 +00:00
|
|
|
} else {
|
|
|
|
mf_ul_parse_fast_read_response(
|
|
|
|
rx_buff, 0x00, mf_ul_read.pages_to_read - 1, &mf_ul_read);
|
|
|
|
}
|
|
|
|
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Reading 3 counters ...");
|
2021-07-22 06:05:07 +00:00
|
|
|
for(uint8_t i = 0; i < 3; i++) {
|
|
|
|
tx_len = mf_ul_prepare_read_cnt(tx_buff, i);
|
2021-08-08 18:03:25 +00:00
|
|
|
if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) {
|
2021-11-12 13:04:35 +00:00
|
|
|
FURI_LOG_W(TAG, "Failed reading Counter %d", i);
|
2021-07-22 06:05:07 +00:00
|
|
|
mf_ul_read.data.counter[i] = 0;
|
|
|
|
} else {
|
|
|
|
mf_ul_parse_read_cnt_response(rx_buff, i, &mf_ul_read);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Checking tearing flags ...");
|
2021-07-22 06:05:07 +00:00
|
|
|
for(uint8_t i = 0; i < 3; i++) {
|
|
|
|
tx_len = mf_ul_prepare_check_tearing(tx_buff, i);
|
2021-08-08 18:03:25 +00:00
|
|
|
if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Error checking tearing flag %d", i);
|
2021-07-22 06:05:07 +00:00
|
|
|
mf_ul_read.data.tearing[i] = MF_UL_TEARING_FLAG_DEFAULT;
|
|
|
|
} else {
|
|
|
|
mf_ul_parse_check_tearing_response(rx_buff, i, &mf_ul_read);
|
|
|
|
}
|
2021-06-15 14:54:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// READ card with READ command (4 pages at a time)
|
|
|
|
for(uint8_t page = 0; page < mf_ul_read.pages_to_read; page += 4) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Reading pages %d - %d ...", page, page + 3);
|
2021-06-15 14:54:09 +00:00
|
|
|
tx_len = mf_ul_prepare_read(tx_buff, page);
|
2021-08-08 18:03:25 +00:00
|
|
|
if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Read pages %d - %d failed", page, page + 3);
|
2021-07-22 06:05:07 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
mf_ul_parse_read_response(rx_buff, page, &mf_ul_read);
|
2021-06-15 14:54:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 17:43:29 +00:00
|
|
|
// 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;
|
2021-07-22 06:05:07 +00:00
|
|
|
result->nfc_data.protocol = NfcDeviceProtocolMifareUl;
|
2021-06-15 14:54:09 +00:00
|
|
|
memcpy(
|
2021-06-30 17:43:29 +00:00
|
|
|
result->nfc_data.uid, dev_list[0].dev.nfca.nfcId1, result->nfc_data.uid_len);
|
2021-07-22 06:05:07 +00:00
|
|
|
result->mf_ul_data = mf_ul_read.data;
|
|
|
|
|
2021-06-30 17:43:29 +00:00
|
|
|
// Notify caller and exit
|
|
|
|
if(nfc_worker->callback) {
|
|
|
|
nfc_worker->callback(nfc_worker->context);
|
|
|
|
}
|
|
|
|
break;
|
2021-06-15 14:54:09 +00:00
|
|
|
} else {
|
2021-11-12 13:04:35 +00:00
|
|
|
FURI_LOG_W(TAG, "Tag does not support 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
|
|
|
}
|
|
|
|
osDelay(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 06:05:07 +00:00
|
|
|
void nfc_worker_emulate_mifare_ul(NfcWorker* nfc_worker) {
|
|
|
|
ReturnCode err;
|
|
|
|
uint8_t tx_buff[255] = {};
|
|
|
|
uint16_t tx_len = 0;
|
|
|
|
uint8_t* rx_buff;
|
|
|
|
uint16_t* rx_len;
|
|
|
|
NfcDeviceData* data = nfc_worker->dev_data;
|
2021-08-16 21:45:04 +00:00
|
|
|
MifareUlDevice mf_ul_emulate;
|
|
|
|
// Setup emulation parameters from mifare ultralight data structure
|
|
|
|
mf_ul_prepare_emulation(&mf_ul_emulate, &data->mf_ul_data);
|
2021-07-22 06:05:07 +00:00
|
|
|
while(nfc_worker->state == NfcWorkerStateEmulateMifareUl) {
|
2021-12-15 18:27:25 +00:00
|
|
|
// WARNING
|
|
|
|
// DO NOT call any blocking functions (e.g. FURI_LOG_*) in this loop,
|
|
|
|
// as any delay will negatively affect the stability of the emulation.
|
2021-08-08 18:03:25 +00:00
|
|
|
if(furi_hal_nfc_listen(
|
2021-07-22 06:05:07 +00:00
|
|
|
data->nfc_data.uid,
|
|
|
|
data->nfc_data.uid_len,
|
|
|
|
data->nfc_data.atqa,
|
|
|
|
data->nfc_data.sak,
|
2021-08-16 21:45:04 +00:00
|
|
|
true,
|
|
|
|
200)) {
|
|
|
|
if(furi_hal_nfc_get_first_frame(&rx_buff, &rx_len)) {
|
|
|
|
// Data exchange loop
|
|
|
|
while(nfc_worker->state == NfcWorkerStateEmulateMifareUl) {
|
|
|
|
tx_len = mf_ul_prepare_emulation_response(
|
|
|
|
rx_buff, *rx_len, tx_buff, &mf_ul_emulate);
|
|
|
|
if(tx_len > 0) {
|
2021-12-21 12:33:17 +00:00
|
|
|
if(tx_len < 8) {
|
|
|
|
err = furi_hal_nfc_raw_bitstream_exchange(
|
|
|
|
tx_buff, tx_len, &rx_buff, &rx_len, false);
|
|
|
|
*rx_len /= 8;
|
|
|
|
} else {
|
|
|
|
err = furi_hal_nfc_data_exchange(
|
|
|
|
tx_buff, tx_len / 8, &rx_buff, &rx_len, false);
|
|
|
|
}
|
2021-08-16 21:45:04 +00:00
|
|
|
if(err == ERR_NONE) {
|
|
|
|
continue;
|
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Communication error: %d", err);
|
2021-08-16 21:45:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
furi_hal_nfc_deactivate();
|
|
|
|
break;
|
|
|
|
}
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Error in 1st data exchange");
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_deactivate();
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-16 21:45:04 +00:00
|
|
|
// Check if data was modified
|
|
|
|
if(mf_ul_emulate.data_changed) {
|
|
|
|
nfc_worker->dev_data->mf_ul_data = mf_ul_emulate.data;
|
|
|
|
if(nfc_worker->callback) {
|
|
|
|
nfc_worker->callback(nfc_worker->context);
|
|
|
|
}
|
|
|
|
}
|
2021-12-15 19:07:37 +00:00
|
|
|
FURI_LOG_D(TAG, "Can't find reader");
|
2021-08-16 21:45:04 +00:00
|
|
|
osThreadYield();
|
2021-07-22 06:05:07 +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_field(NfcWorker* nfc_worker) {
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_field_on();
|
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
|
|
|
while(nfc_worker->state == NfcWorkerStateField) {
|
|
|
|
osDelay(50);
|
|
|
|
}
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_nfc_field_off();
|
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
|
|
|
}
|