2021-12-22 23:04:08 +03: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 12:20:41 +03:00
|
|
|
#include <dolphin/dolphin.h>
|
2022-01-05 19:10:18 +03:00
|
|
|
#include "furi_hal.h"
|
2021-12-22 23:04:08 +03:00
|
|
|
#include "../u2f.h"
|
|
|
|
|
2022-01-03 02:33:28 +03:00
|
|
|
#define U2F_REQUEST_TIMEOUT 500
|
|
|
|
#define U2F_SUCCESS_TIMEOUT 3000
|
2021-12-22 23:04:08 +03:00
|
|
|
|
|
|
|
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);
|
2022-01-03 02:33:28 +03:00
|
|
|
else if(evt == U2fNotifyAuthSuccess)
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventAuthSuccess);
|
2021-12-22 23:04:08 +03:00
|
|
|
else if(evt == U2fNotifyWink)
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventWink);
|
2022-01-03 02:33:28 +03: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 16:34:09 +03:00
|
|
|
else if(evt == U2fNotifyError)
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventDataError);
|
2021-12-22 23:04:08 +03: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-03 02:33:28 +03:00
|
|
|
if(event.event == U2fCustomEventConnect) {
|
|
|
|
osTimerStop(app->timer);
|
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgIdle);
|
|
|
|
} else if(event.event == U2fCustomEventDisconnect) {
|
|
|
|
osTimerStop(app->timer);
|
|
|
|
app->event_cur = U2fCustomEventNone;
|
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgNotConnected);
|
|
|
|
} else if((event.event == U2fCustomEventRegister) || (event.event == U2fCustomEventAuth)) {
|
|
|
|
osTimerStart(app->timer, U2F_REQUEST_TIMEOUT);
|
2021-12-22 23:04:08 +03:00
|
|
|
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);
|
2022-01-03 02:33:28 +03:00
|
|
|
notification_message(app->notifications, &sequence_display_on);
|
|
|
|
notification_message(app->notifications, &sequence_single_vibro);
|
2021-12-22 23:04:08 +03:00
|
|
|
}
|
|
|
|
notification_message(app->notifications, &sequence_blink_blue_10);
|
|
|
|
} else if(event.event == U2fCustomEventWink) {
|
|
|
|
notification_message(app->notifications, &sequence_blink_green_10);
|
2022-01-03 02:33:28 +03:00
|
|
|
} else if(event.event == U2fCustomEventAuthSuccess) {
|
[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 12:20:41 +03:00
|
|
|
DOLPHIN_DEED(DolphinDeedU2fAuthorized);
|
2022-01-03 02:33:28 +03:00
|
|
|
osTimerStart(app->timer, U2F_SUCCESS_TIMEOUT);
|
|
|
|
app->event_cur = U2fCustomEventNone;
|
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgSuccess);
|
2021-12-22 23:04:08 +03:00
|
|
|
} else if(event.event == U2fCustomEventTimeout) {
|
|
|
|
app->event_cur = U2fCustomEventNone;
|
2022-01-03 02:33:28 +03:00
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgIdle);
|
2021-12-22 23:04:08 +03:00
|
|
|
} else if(event.event == U2fCustomEventConfirm) {
|
|
|
|
if(app->event_cur != U2fCustomEventNone) {
|
|
|
|
u2f_confirm_user_present(app->u2f_instance);
|
|
|
|
}
|
2022-02-07 16:34:09 +03:00
|
|
|
} else if(event.event == U2fCustomEventDataError) {
|
|
|
|
osTimerStop(app->timer);
|
|
|
|
u2f_view_set_state(app->u2f_view, U2fMsgError);
|
2021-12-22 23:04:08 +03:00
|
|
|
}
|
|
|
|
consumed = true;
|
|
|
|
}
|
2022-02-07 16:34:09 +03:00
|
|
|
|
2021-12-22 23:04:08 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|