2021-12-22 20:04:08 +00:00
|
|
|
#include "../u2f_app_i.h"
|
|
|
|
#include "../views/u2f_view.h"
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 09:20:41 +00:00
|
|
|
#include <dolphin/dolphin.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include "furi_hal.h"
|
2021-12-22 20:04:08 +00:00
|
|
|
#include "../u2f.h"
|
|
|
|
|
2022-01-02 23:33:28 +00:00
|
|
|
#define U2F_REQUEST_TIMEOUT 500
|
|
|
|
#define U2F_SUCCESS_TIMEOUT 3000
|
2021-12-22 20:04:08 +00:00
|
|
|
|
|
|
|
static void u2f_scene_main_ok_callback(InputType type, void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(type);
|
2021-12-22 20:04:08 +00:00
|
|
|
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);
|
2022-01-02 23:33:28 +00:00
|
|
|
else if(evt == U2fNotifyAuthSuccess)
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventAuthSuccess);
|
2021-12-22 20:04:08 +00:00
|
|
|
else if(evt == U2fNotifyWink)
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventWink);
|
2022-01-02 23:33:28 +00:00
|
|
|
else if(evt == U2fNotifyConnect)
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventConnect);
|
|
|
|
else if(evt == U2fNotifyDisconnect)
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventDisconnect);
|
2022-02-07 13:34:09 +00:00
|
|
|
else if(evt == U2fNotifyError)
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventDataError);
|
2021-12-22 20:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2022-01-02 23:33:28 +00:00
|
|
|
if(event.event == U2fCustomEventConnect) {
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_timer_stop(app->timer);
|
2022-01-02 23:33:28 +00:00
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgIdle);
|
|
|
|
} else if(event.event == U2fCustomEventDisconnect) {
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_timer_stop(app->timer);
|
2022-01-02 23:33:28 +00:00
|
|
|
app->event_cur = U2fCustomEventNone;
|
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgNotConnected);
|
|
|
|
} else if((event.event == U2fCustomEventRegister) || (event.event == U2fCustomEventAuth)) {
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_timer_start(app->timer, U2F_REQUEST_TIMEOUT);
|
2021-12-22 20:04:08 +00:00
|
|
|
if(app->event_cur == U2fCustomEventNone) {
|
|
|
|
app->event_cur = event.event;
|
|
|
|
if(event.event == U2fCustomEventRegister)
|
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgRegister);
|
2022-12-26 12:13:30 +00:00
|
|
|
else if(event.event == U2fCustomEventAuth) //-V547
|
2021-12-22 20:04:08 +00:00
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgAuth);
|
2022-04-29 14:21:12 +00:00
|
|
|
notification_message(app->notifications, &sequence_display_backlight_on);
|
2022-01-02 23:33:28 +00:00
|
|
|
notification_message(app->notifications, &sequence_single_vibro);
|
2021-12-22 20:04:08 +00:00
|
|
|
}
|
2022-04-28 17:20:59 +00:00
|
|
|
notification_message(app->notifications, &sequence_blink_magenta_10);
|
2021-12-22 20:04:08 +00:00
|
|
|
} else if(event.event == U2fCustomEventWink) {
|
2022-04-28 17:20:59 +00:00
|
|
|
notification_message(app->notifications, &sequence_blink_magenta_10);
|
2022-01-02 23:33:28 +00:00
|
|
|
} else if(event.event == U2fCustomEventAuthSuccess) {
|
2022-04-28 17:20:59 +00:00
|
|
|
notification_message_block(app->notifications, &sequence_set_green_255);
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 09:20:41 +00:00
|
|
|
DOLPHIN_DEED(DolphinDeedU2fAuthorized);
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_timer_start(app->timer, U2F_SUCCESS_TIMEOUT);
|
2022-01-02 23:33:28 +00:00
|
|
|
app->event_cur = U2fCustomEventNone;
|
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgSuccess);
|
2021-12-22 20:04:08 +00:00
|
|
|
} else if(event.event == U2fCustomEventTimeout) {
|
2022-04-28 17:20:59 +00:00
|
|
|
notification_message_block(app->notifications, &sequence_reset_rgb);
|
2021-12-22 20:04:08 +00:00
|
|
|
app->event_cur = U2fCustomEventNone;
|
2022-01-02 23:33:28 +00:00
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgIdle);
|
2021-12-22 20:04:08 +00:00
|
|
|
} else if(event.event == U2fCustomEventConfirm) {
|
|
|
|
if(app->event_cur != U2fCustomEventNone) {
|
|
|
|
u2f_confirm_user_present(app->u2f_instance);
|
|
|
|
}
|
2022-02-07 13:34:09 +00:00
|
|
|
} else if(event.event == U2fCustomEventDataError) {
|
2022-04-28 17:20:59 +00:00
|
|
|
notification_message(app->notifications, &sequence_set_red_255);
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_timer_stop(app->timer);
|
2022-02-07 13:34:09 +00:00
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgError);
|
2021-12-22 20:04:08 +00:00
|
|
|
}
|
|
|
|
consumed = true;
|
|
|
|
}
|
2022-02-07 13:34:09 +00:00
|
|
|
|
2021-12-22 20:04:08 +00:00
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void u2f_scene_main_on_enter(void* context) {
|
|
|
|
U2fApp* app = context;
|
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
app->timer = furi_timer_alloc(u2f_scene_main_timer_callback, FuriTimerTypeOnce, app);
|
2021-12-22 20:04:08 +00:00
|
|
|
|
|
|
|
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;
|
2022-04-28 17:20:59 +00:00
|
|
|
notification_message_block(app->notifications, &sequence_reset_rgb);
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_timer_stop(app->timer);
|
|
|
|
furi_timer_free(app->timer);
|
2021-12-22 20:04:08 +00:00
|
|
|
if(app->u2f_ready == true) {
|
|
|
|
u2f_hid_stop(app->u2f_hid);
|
|
|
|
u2f_free(app->u2f_instance);
|
|
|
|
}
|
|
|
|
}
|