2022-07-26 18:30:49 +03:00
|
|
|
#include "../nfc_i.h"
|
|
|
|
|
2022-10-06 19:58:17 +03:00
|
|
|
#define NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX (10U)
|
|
|
|
|
|
|
|
static const NotificationSequence sequence_detect_reader = {
|
|
|
|
&message_green_255,
|
|
|
|
&message_blue_255,
|
|
|
|
&message_do_not_reset,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2022-07-26 18:30:49 +03:00
|
|
|
bool nfc_detect_reader_worker_callback(NfcWorkerEvent event, void* context) {
|
|
|
|
UNUSED(event);
|
|
|
|
furi_assert(context);
|
|
|
|
Nfc* nfc = context;
|
2022-09-03 15:25:36 +03:00
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, event);
|
2022-07-26 18:30:49 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-03 15:25:36 +03:00
|
|
|
void nfc_scene_detect_reader_callback(void* context) {
|
2022-07-26 18:30:49 +03:00
|
|
|
furi_assert(context);
|
|
|
|
Nfc* nfc = context;
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventViewExit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_scene_detect_reader_on_enter(void* context) {
|
|
|
|
Nfc* nfc = context;
|
|
|
|
|
2022-09-03 15:25:36 +03:00
|
|
|
detect_reader_set_callback(nfc->detect_reader, nfc_scene_detect_reader_callback, nfc);
|
2022-10-06 19:58:17 +03:00
|
|
|
detect_reader_set_nonces_max(nfc->detect_reader, NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX);
|
2022-10-28 19:10:16 +03:00
|
|
|
NfcDeviceData* dev_data = &nfc->dev->dev_data;
|
|
|
|
if(dev_data->nfc_data.uid_len) {
|
|
|
|
detect_reader_set_uid(
|
|
|
|
nfc->detect_reader, dev_data->nfc_data.uid, dev_data->nfc_data.uid_len);
|
|
|
|
}
|
2022-10-06 19:58:17 +03:00
|
|
|
|
|
|
|
// Store number of collected nonces in scene state
|
|
|
|
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneDetectReader, 0);
|
|
|
|
notification_message(nfc->notifications, &sequence_detect_reader);
|
|
|
|
|
2022-07-26 18:30:49 +03:00
|
|
|
nfc_worker_start(
|
|
|
|
nfc->worker,
|
2022-09-03 15:25:36 +03:00
|
|
|
NfcWorkerStateAnalyzeReader,
|
2022-07-26 18:30:49 +03:00
|
|
|
&nfc->dev->dev_data,
|
|
|
|
nfc_detect_reader_worker_callback,
|
|
|
|
nfc);
|
2022-09-03 15:25:36 +03:00
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDetectReader);
|
2022-07-26 18:30:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool nfc_scene_detect_reader_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
Nfc* nfc = context;
|
|
|
|
bool consumed = false;
|
2022-10-06 19:58:17 +03:00
|
|
|
uint32_t nonces_collected =
|
|
|
|
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneDetectReader);
|
2022-07-26 18:30:49 +03:00
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-09-03 15:25:36 +03:00
|
|
|
if(event.event == NfcCustomEventViewExit) {
|
|
|
|
nfc_worker_stop(nfc->worker);
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfkeyNoncesInfo);
|
2022-07-26 18:30:49 +03:00
|
|
|
consumed = true;
|
2022-09-03 15:25:36 +03:00
|
|
|
} else if(event.event == NfcWorkerEventDetectReaderMfkeyCollected) {
|
2022-10-06 19:58:17 +03:00
|
|
|
nonces_collected += 2;
|
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager, NfcSceneDetectReader, nonces_collected);
|
|
|
|
detect_reader_set_nonces_collected(nfc->detect_reader, nonces_collected);
|
|
|
|
if(nonces_collected >= NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX) {
|
|
|
|
detect_reader_set_state(nfc->detect_reader, DetectReaderStateDone);
|
|
|
|
nfc_blink_stop(nfc);
|
|
|
|
notification_message(nfc->notifications, &sequence_single_vibro);
|
|
|
|
notification_message(nfc->notifications, &sequence_set_green_255);
|
|
|
|
nfc_worker_stop(nfc->worker);
|
|
|
|
}
|
2022-07-26 18:30:49 +03:00
|
|
|
consumed = true;
|
2022-10-06 19:58:17 +03:00
|
|
|
} else if(event.event == NfcWorkerEventDetectReaderDetected) {
|
|
|
|
if(nonces_collected < NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX) {
|
|
|
|
notification_message(nfc->notifications, &sequence_blink_start_cyan);
|
|
|
|
detect_reader_set_state(nfc->detect_reader, DetectReaderStateReaderDetected);
|
|
|
|
}
|
|
|
|
} else if(event.event == NfcWorkerEventDetectReaderLost) {
|
|
|
|
if(nonces_collected < NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX) {
|
|
|
|
nfc_blink_stop(nfc);
|
|
|
|
notification_message(nfc->notifications, &sequence_detect_reader);
|
|
|
|
detect_reader_set_state(nfc->detect_reader, DetectReaderStateReaderLost);
|
|
|
|
}
|
2022-07-26 18:30:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_scene_detect_reader_on_exit(void* context) {
|
|
|
|
Nfc* nfc = context;
|
|
|
|
|
|
|
|
// Stop worker
|
|
|
|
nfc_worker_stop(nfc->worker);
|
|
|
|
|
|
|
|
// Clear view
|
2022-09-03 15:25:36 +03:00
|
|
|
detect_reader_reset(nfc->detect_reader);
|
2022-07-26 18:30:49 +03:00
|
|
|
|
2022-10-06 19:58:17 +03:00
|
|
|
// Stop notifications
|
2022-07-26 18:30:49 +03:00
|
|
|
nfc_blink_stop(nfc);
|
2022-10-06 19:58:17 +03:00
|
|
|
notification_message(nfc->notifications, &sequence_reset_green);
|
2022-07-26 18:30:49 +03:00
|
|
|
}
|