mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-21 04:11:48 +03:00
9e62f08e4d
* U2F implementation prototype * U2F data encryption and store, user confirmation request * remove debug prints * fix notification bug in chrome * split u2f_alloc into u2f_init and u2f_alloc * typo fix, furi-hal-trng -> furi-hal-random * rand/srand redefinition * SubGhz: a little bit of Dante. * u2f_data naming fix Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
93 lines
3.4 KiB
C
93 lines
3.4 KiB
C
#include "../u2f_app_i.h"
|
|
#include "../views/u2f_view.h"
|
|
#include "furi-hal.h"
|
|
#include "../u2f.h"
|
|
|
|
#define U2F_EVENT_TIMEOUT 500
|
|
|
|
static void u2f_scene_main_ok_callback(InputType type, void* context) {
|
|
furi_assert(context);
|
|
U2fApp* app = context;
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventConfirm);
|
|
}
|
|
|
|
static void u2f_scene_main_event_callback(U2fNotifyEvent evt, void* context) {
|
|
furi_assert(context);
|
|
U2fApp* app = context;
|
|
if(evt == U2fNotifyRegister)
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventRegister);
|
|
else if(evt == U2fNotifyAuth)
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventAuth);
|
|
else if(evt == U2fNotifyWink)
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventWink);
|
|
}
|
|
|
|
static void u2f_scene_main_timer_callback(void* context) {
|
|
furi_assert(context);
|
|
U2fApp* app = context;
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventTimeout);
|
|
}
|
|
|
|
bool u2f_scene_main_on_event(void* context, SceneManagerEvent event) {
|
|
furi_assert(context);
|
|
U2fApp* app = context;
|
|
bool consumed = false;
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
if((event.event == U2fCustomEventRegister) || (event.event == U2fCustomEventAuth)) {
|
|
osTimerStart(app->timer, U2F_EVENT_TIMEOUT);
|
|
if(app->event_cur == U2fCustomEventNone) {
|
|
app->event_cur = event.event;
|
|
if(event.event == U2fCustomEventRegister)
|
|
u2f_view_set_state(app->u2f_view, U2fMsgRegister);
|
|
else if(event.event == U2fCustomEventAuth)
|
|
u2f_view_set_state(app->u2f_view, U2fMsgAuth);
|
|
notification_message(app->notifications, &sequence_success);
|
|
}
|
|
notification_message(app->notifications, &sequence_blink_blue_10);
|
|
} else if(event.event == U2fCustomEventWink) {
|
|
notification_message(app->notifications, &sequence_blink_green_10);
|
|
} else if(event.event == U2fCustomEventTimeout) {
|
|
app->event_cur = U2fCustomEventNone;
|
|
u2f_view_set_state(app->u2f_view, U2fMsgNone);
|
|
} else if(event.event == U2fCustomEventConfirm) {
|
|
if(app->event_cur != U2fCustomEventNone) {
|
|
u2f_confirm_user_present(app->u2f_instance);
|
|
}
|
|
}
|
|
|
|
consumed = true;
|
|
} else if(event.type == SceneManagerEventTypeTick) {
|
|
}
|
|
return consumed;
|
|
}
|
|
|
|
void u2f_scene_main_on_enter(void* context) {
|
|
U2fApp* app = context;
|
|
|
|
app->timer = osTimerNew(u2f_scene_main_timer_callback, osTimerOnce, app, NULL);
|
|
|
|
app->u2f_instance = u2f_alloc();
|
|
app->u2f_ready = u2f_init(app->u2f_instance);
|
|
if(app->u2f_ready == true) {
|
|
u2f_set_event_callback(app->u2f_instance, u2f_scene_main_event_callback, app);
|
|
app->u2f_hid = u2f_hid_start(app->u2f_instance);
|
|
u2f_view_set_ok_callback(app->u2f_view, u2f_scene_main_ok_callback, app);
|
|
} else {
|
|
u2f_free(app->u2f_instance);
|
|
u2f_view_set_state(app->u2f_view, U2fMsgError);
|
|
}
|
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, U2fAppViewMain);
|
|
}
|
|
|
|
void u2f_scene_main_on_exit(void* context) {
|
|
U2fApp* app = context;
|
|
osTimerStop(app->timer);
|
|
osTimerDelete(app->timer);
|
|
if(app->u2f_ready == true) {
|
|
u2f_hid_stop(app->u2f_hid);
|
|
u2f_free(app->u2f_instance);
|
|
}
|
|
}
|