Deny BT-RPC commands when locked (Toggle)

This commit is contained in:
ClaraCrazy
2023-07-23 19:26:36 +02:00
parent 7152846c08
commit a7151dc46b
8 changed files with 106 additions and 69 deletions

View File

@@ -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);

View File

@@ -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