flipperzero-firmware/applications/main/u2f/scenes/u2f_scene_main.c
hedger 224d0aefe4
[FL-2733] multitarget support for fbt (#2209)
* First part of multitarget porting
* Delete firmware/targets/f7/Inc directory
* Delete firmware/targets/f7/Src directory
* gpio: cli fixes; about: using version from HAL
* sdk: path fixes
* gui: include fixes
* applications: more include fixes
* gpio: ported to new apis
* hal: introduced furi_hal_target_hw.h; libs: added one_wire
* hal: f18 target
* github: also build f18 by default
* typo fix
* fbt: removed extra checks on app list
* api: explicitly bundling select mlib headers with sdk
* hal: f18: changed INPUT_DEBOUNCE_TICKS to match f7
* cleaned up commented out code
* docs: added info on hw targets
* docs: targets: formatting fixes
* f18: fixed link error
* f18: fixed API version to match f7
* docs: hardware: minor wording fixes
* faploader: added fw target check
* docs: typo fixes
* github: not building komi target by default
* fbt: support for `targets` field for built-in apps
* github: reworked build flow to exclude app_set; fbt: removed komi-specific appset; added additional target buildset check
* github: fixed build; nfc: fixed pvs warnings
* attempt to fix target id
* f7, f18: removed certain HAL function from public API
* apps: debug: enabled bt_debug_app for f18
* Targets: backport input pins configuration routine from F7 to F18

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2023-02-08 01:33:05 +09:00

123 lines
5.2 KiB
C

#include "../u2f_app_i.h"
#include "../views/u2f_view.h"
#include <dolphin/dolphin.h>
#include <furi_hal.h>
#include "../u2f.h"
#define U2F_REQUEST_TIMEOUT 500
#define U2F_SUCCESS_TIMEOUT 3000
static void u2f_scene_main_ok_callback(InputType type, void* context) {
UNUSED(type);
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 == U2fNotifyAuthSuccess)
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventAuthSuccess);
else if(evt == U2fNotifyWink)
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventWink);
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);
else if(evt == U2fNotifyError)
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventDataError);
}
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 == U2fCustomEventConnect) {
furi_timer_stop(app->timer);
u2f_view_set_state(app->u2f_view, U2fMsgIdle);
} else if(event.event == U2fCustomEventDisconnect) {
furi_timer_stop(app->timer);
app->event_cur = U2fCustomEventNone;
u2f_view_set_state(app->u2f_view, U2fMsgNotConnected);
} else if((event.event == U2fCustomEventRegister) || (event.event == U2fCustomEventAuth)) {
furi_timer_start(app->timer, U2F_REQUEST_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) //-V547
u2f_view_set_state(app->u2f_view, U2fMsgAuth);
notification_message(app->notifications, &sequence_display_backlight_on);
notification_message(app->notifications, &sequence_single_vibro);
}
notification_message(app->notifications, &sequence_blink_magenta_10);
} else if(event.event == U2fCustomEventWink) {
notification_message(app->notifications, &sequence_blink_magenta_10);
} else if(event.event == U2fCustomEventAuthSuccess) {
notification_message_block(app->notifications, &sequence_set_green_255);
DOLPHIN_DEED(DolphinDeedU2fAuthorized);
furi_timer_start(app->timer, U2F_SUCCESS_TIMEOUT);
app->event_cur = U2fCustomEventNone;
u2f_view_set_state(app->u2f_view, U2fMsgSuccess);
} else if(event.event == U2fCustomEventTimeout) {
notification_message_block(app->notifications, &sequence_reset_rgb);
app->event_cur = U2fCustomEventNone;
u2f_view_set_state(app->u2f_view, U2fMsgIdle);
} else if(event.event == U2fCustomEventConfirm) {
if(app->event_cur != U2fCustomEventNone) {
u2f_confirm_user_present(app->u2f_instance);
}
} else if(event.event == U2fCustomEventDataError) {
notification_message(app->notifications, &sequence_set_red_255);
furi_timer_stop(app->timer);
u2f_view_set_state(app->u2f_view, U2fMsgError);
}
consumed = true;
}
return consumed;
}
void u2f_scene_main_on_enter(void* context) {
U2fApp* app = context;
app->timer = furi_timer_alloc(u2f_scene_main_timer_callback, FuriTimerTypeOnce, app);
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;
notification_message_block(app->notifications, &sequence_reset_rgb);
furi_timer_stop(app->timer);
furi_timer_free(app->timer);
if(app->u2f_ready == true) {
u2f_hid_stop(app->u2f_hid);
u2f_free(app->u2f_instance);
}
}