[FL-2315] USB Mode switch lock (#1036)

* usb mode switch lock
* lock_mutex removed
* Wait for session termination in rpc_cli, lock badusb and u2f if rpc session is opened

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Nikolay Minaylov
2022-03-24 18:45:03 +03:00
committed by GitHub
parent eafeefb843
commit 38e92cf789
20 changed files with 216 additions and 43 deletions

View File

@@ -12,16 +12,26 @@ static void u2f_scene_error_event_callback(GuiButtonType result, InputType type,
void u2f_scene_error_on_enter(void* context) {
U2fApp* app = context;
widget_add_icon_element(app->widget, 0, 0, &I_SDQuestion_35x43);
widget_add_string_multiline_element(
app->widget,
81,
4,
AlignCenter,
AlignTop,
FontSecondary,
"No SD card or\napp data found.\nThis app will not\nwork without\nrequired files.");
if(app->error == U2fAppErrorNoFiles) {
widget_add_icon_element(app->widget, 0, 0, &I_SDQuestion_35x43);
widget_add_string_multiline_element(
app->widget,
81,
4,
AlignCenter,
AlignTop,
FontSecondary,
"No SD card or\napp data found.\nThis app will not\nwork without\nrequired files.");
} else if(app->error == U2fAppErrorCloseRpc) {
widget_add_string_multiline_element(
app->widget,
63,
10,
AlignCenter,
AlignTop,
FontSecondary,
"Disconnect from\ncompanion app\nto use this function");
}
widget_add_button_element(
app->widget, GuiButtonTypeLeft, "Back", u2f_scene_error_event_callback, app);

View File

@@ -48,10 +48,16 @@ U2fApp* u2f_app_alloc() {
view_dispatcher_add_view(
app->view_dispatcher, U2fAppViewMain, u2f_view_get_view(app->u2f_view));
if(u2f_data_check(true)) {
scene_manager_next_scene(app->scene_manager, U2fSceneMain);
} else {
if(furi_hal_usb_is_locked()) {
app->error = U2fAppErrorCloseRpc;
scene_manager_next_scene(app->scene_manager, U2fSceneError);
} else {
if(u2f_data_check(true)) {
scene_manager_next_scene(app->scene_manager, U2fSceneMain);
} else {
app->error = U2fAppErrorNoFiles;
scene_manager_next_scene(app->scene_manager, U2fSceneError);
}
}
return app;

View File

@@ -15,6 +15,11 @@
#include "u2f_hid.h"
#include "u2f.h"
typedef enum {
U2fAppErrorNoFiles,
U2fAppErrorCloseRpc,
} U2fAppError;
typedef enum {
U2fCustomEventNone,
@@ -52,4 +57,5 @@ struct U2fApp {
U2fData* u2f_instance;
GpioCustomEvent event_cur;
bool u2f_ready;
U2fAppError error;
};

View File

@@ -191,7 +191,7 @@ static int32_t u2f_hid_worker(void* context) {
FURI_LOG_D(WORKER_TAG, "Init");
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
furi_hal_usb_set_config(&usb_hid_u2f, NULL);
furi_check(furi_hal_usb_set_config(&usb_hid_u2f, NULL) == true);
u2f_hid->lock_timer = osTimerNew(u2f_hid_lock_timeout_callback, osTimerOnce, u2f_hid, NULL);