mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 04:28:36 -07:00
Deny BT-RPC commands when locked (Toggle)
This commit is contained in:
@@ -216,19 +216,9 @@ static void bt_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t byt
|
||||
}
|
||||
}
|
||||
|
||||
// Called from GAP thread
|
||||
static bool bt_on_gap_event_callback(GapEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
Bt* bt = context;
|
||||
bool ret = false;
|
||||
bt->pin = 0;
|
||||
|
||||
if(event.type == GapEventTypeConnected) {
|
||||
// Update status bar
|
||||
bt->status = BtStatusConnected;
|
||||
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
||||
furi_check(
|
||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
// Open BT Connection
|
||||
void bt_open_rpc_connection(Bt* bt) {
|
||||
if(!bt->rpc_session) {
|
||||
// Clear BT_RPC_EVENT_DISCONNECTED because it might be set from previous session
|
||||
furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||
if(bt->profile == BtProfileSerial) {
|
||||
@@ -247,6 +237,34 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
|
||||
FURI_LOG_W(TAG, "RPC is busy, failed to open new session");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bt_close_rpc_connection(Bt* bt) {
|
||||
if(bt->profile == BtProfileSerial && bt->rpc_session) {
|
||||
FURI_LOG_I(TAG, "Close RPC connection");
|
||||
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||
rpc_session_close(bt->rpc_session);
|
||||
furi_hal_bt_serial_set_event_callback(0, NULL, NULL);
|
||||
bt->rpc_session = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Called from GAP thread
|
||||
static bool bt_on_gap_event_callback(GapEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
Bt* bt = context;
|
||||
bool ret = false;
|
||||
bt->pin = 0;
|
||||
|
||||
if(event.type == GapEventTypeConnected) {
|
||||
// Update status bar
|
||||
bt->status = BtStatusConnected;
|
||||
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
||||
furi_check(
|
||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||
bt_open_rpc_connection(bt);
|
||||
// Update battery level
|
||||
PowerInfo info;
|
||||
power_get_info(bt->power, &info);
|
||||
@@ -323,16 +341,6 @@ static void bt_show_warning(Bt* bt, const char* text) {
|
||||
dialog_message_show(bt->dialogs, bt->dialog_message);
|
||||
}
|
||||
|
||||
static void bt_close_rpc_connection(Bt* bt) {
|
||||
if(bt->profile == BtProfileSerial && bt->rpc_session) {
|
||||
FURI_LOG_I(TAG, "Close RPC connection");
|
||||
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||
rpc_session_close(bt->rpc_session);
|
||||
furi_hal_bt_serial_set_event_callback(0, NULL, NULL);
|
||||
bt->rpc_session = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_change_profile(Bt* bt, BtMessage* message) {
|
||||
if(furi_hal_bt_is_ble_gatt_gap_supported()) {
|
||||
bt_settings_load(&bt->bt_settings);
|
||||
|
||||
@@ -99,6 +99,19 @@ void bt_disable_peer_key_update(Bt* bt);
|
||||
*/
|
||||
void bt_enable_peer_key_update(Bt* bt);
|
||||
|
||||
/**
|
||||
*
|
||||
* (Probably bad) way of opening the RPC connection, everywhereTM
|
||||
*/
|
||||
|
||||
void bt_open_rpc_connection(Bt* bt);
|
||||
|
||||
/**
|
||||
*
|
||||
* Closing the RPC connection, everywhereTM
|
||||
*/
|
||||
void bt_close_rpc_connection(Bt* bt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -242,6 +242,11 @@ void desktop_lock(Desktop* desktop, bool pin_lock) {
|
||||
Cli* cli = furi_record_open(RECORD_CLI);
|
||||
cli_session_close(cli);
|
||||
furi_record_close(RECORD_CLI);
|
||||
if (!XTREME_SETTINGS()->allow_locked_rpc_commands) {
|
||||
Bt* bt = furi_record_open(RECORD_BT);
|
||||
bt_close_rpc_connection(bt);
|
||||
furi_record_close(RECORD_BT);
|
||||
}
|
||||
}
|
||||
|
||||
desktop_auto_lock_inhibit(desktop);
|
||||
@@ -270,6 +275,10 @@ void desktop_unlock(Desktop* desktop) {
|
||||
furi_record_close(RECORD_CLI);
|
||||
}
|
||||
|
||||
Bt* bt = furi_record_open(RECORD_BT);
|
||||
bt_open_rpc_connection(bt);
|
||||
furi_record_close(RECORD_BT);
|
||||
|
||||
DesktopStatus status = {.locked = false};
|
||||
furi_pubsub_publish(desktop->status_pubsub, &status);
|
||||
}
|
||||
@@ -435,9 +444,7 @@ bool desktop_api_is_locked(Desktop* instance) {
|
||||
|
||||
void desktop_api_unlock(Desktop* instance) {
|
||||
furi_assert(instance);
|
||||
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock) || XTREME_SETTINGS()->pin_unlock_from_app) {
|
||||
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopLockedEventUnlocked);
|
||||
}
|
||||
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopLockedEventUnlocked);
|
||||
}
|
||||
|
||||
FuriPubSub* desktop_api_get_status_pubsub(Desktop* instance) {
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
#include <portmacro.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <m-dict.h>
|
||||
#include <xtreme.h>
|
||||
|
||||
#define TAG "RpcSrv"
|
||||
|
||||
@@ -363,41 +365,46 @@ static void rpc_session_thread_state_callback(FuriThreadState thread_state, void
|
||||
}
|
||||
|
||||
RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner) {
|
||||
furi_assert(rpc);
|
||||
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock) || XTREME_SETTINGS()->allow_locked_rpc_commands) {
|
||||
furi_assert(rpc);
|
||||
|
||||
RpcSession* session = malloc(sizeof(RpcSession));
|
||||
session->callbacks_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
session->stream = furi_stream_buffer_alloc(RPC_BUFFER_SIZE, 1);
|
||||
session->rpc = rpc;
|
||||
session->terminate = false;
|
||||
session->decode_error = false;
|
||||
session->owner = owner;
|
||||
RpcHandlerDict_init(session->handlers);
|
||||
RpcSession* session = malloc(sizeof(RpcSession));
|
||||
session->callbacks_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
session->stream = furi_stream_buffer_alloc(RPC_BUFFER_SIZE, 1);
|
||||
session->rpc = rpc;
|
||||
session->terminate = false;
|
||||
session->decode_error = false;
|
||||
session->owner = owner;
|
||||
RpcHandlerDict_init(session->handlers);
|
||||
|
||||
session->decoded_message = malloc(sizeof(PB_Main));
|
||||
session->decoded_message->cb_content.funcs.decode = rpc_pb_content_callback;
|
||||
session->decoded_message->cb_content.arg = session;
|
||||
session->decoded_message = malloc(sizeof(PB_Main));
|
||||
session->decoded_message->cb_content.funcs.decode = rpc_pb_content_callback;
|
||||
session->decoded_message->cb_content.arg = session;
|
||||
|
||||
session->system_contexts = malloc(COUNT_OF(rpc_systems) * sizeof(void*));
|
||||
for(size_t i = 0; i < COUNT_OF(rpc_systems); ++i) {
|
||||
session->system_contexts[i] = rpc_systems[i].alloc(session);
|
||||
session->system_contexts = malloc(COUNT_OF(rpc_systems) * sizeof(void*));
|
||||
for(size_t i = 0; i < COUNT_OF(rpc_systems); ++i) {
|
||||
session->system_contexts[i] = rpc_systems[i].alloc(session);
|
||||
}
|
||||
|
||||
RpcHandler rpc_handler = {
|
||||
.message_handler = rpc_close_session_process,
|
||||
.decode_submessage = NULL,
|
||||
.context = session,
|
||||
};
|
||||
rpc_add_handler(session, PB_Main_stop_session_tag, &rpc_handler);
|
||||
|
||||
session->thread =
|
||||
furi_thread_alloc_ex("RpcSessionWorker", 3072, rpc_session_worker, session);
|
||||
|
||||
furi_thread_set_state_context(session->thread, session);
|
||||
furi_thread_set_state_callback(session->thread, rpc_session_thread_state_callback);
|
||||
|
||||
furi_thread_start(session->thread);
|
||||
|
||||
return session;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RpcHandler rpc_handler = {
|
||||
.message_handler = rpc_close_session_process,
|
||||
.decode_submessage = NULL,
|
||||
.context = session,
|
||||
};
|
||||
rpc_add_handler(session, PB_Main_stop_session_tag, &rpc_handler);
|
||||
|
||||
session->thread = furi_thread_alloc_ex("RpcSessionWorker", 3072, rpc_session_worker, session);
|
||||
|
||||
furi_thread_set_state_context(session->thread, session);
|
||||
furi_thread_set_state_callback(session->thread, rpc_session_thread_state_callback);
|
||||
|
||||
furi_thread_start(session->thread);
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
void rpc_session_close(RpcSession* session) {
|
||||
|
||||
Reference in New Issue
Block a user