[FL-2580] FuriHal: add more supported radio stacks (#1301)

* FuriHal: add more supported radio stacks
* Bt: correct ble stack enum value
* Bt: update cli testing commands implementation
* Scripts: always emitting ob data to update manifest; added ob_custradio.data for non-light radio stacks
* Scripts: added stack type whitelist & disclaimer message
* ble: remove scanner
* ble: remove HCI and advances ble stacks support
* bt: correctly close RPC session before bt reinit
* Scripts: update bundler: estimating flash layout & refusing to build dangerous packages; app frame: not adding redundant log handlers
* Docs: additional details on bundling updates; fixed updater error codes
* Docs: wording fixes for OTA.md

Co-authored-by: hedger <hedger@nanode.su>
Co-authored-by: gornekich <n.gorbadey@gmail.com>
Co-authored-by: SG <who.just.the.doctor@gmail.com>
This commit is contained in:
あく
2022-06-09 18:07:42 +09:00
committed by GitHub
parent 2bd4efd044
commit 936a2f64b2
18 changed files with 280 additions and 192 deletions

View File

@@ -293,17 +293,20 @@ 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");
osEventFlagsSet(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) {
FuriHalBtStack stack = furi_hal_bt_get_radio_stack();
if(stack == FuriHalBtStackLight) {
if(furi_hal_bt_is_ble_gatt_gap_supported()) {
bt_settings_load(&bt->bt_settings);
if(bt->profile == BtProfileSerial && bt->rpc_session) {
FURI_LOG_I(TAG, "Close RPC connection");
osEventFlagsSet(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;
}
bt_close_rpc_connection(bt);
FuriHalBtProfile furi_profile;
if(message->data.profile == BtProfileHidKeyboard) {
@@ -331,6 +334,11 @@ static void bt_change_profile(Bt* bt, BtMessage* message) {
osEventFlagsSet(bt->api_event, BT_API_UNLOCK_EVENT);
}
static void bt_close_connection(Bt* bt) {
bt_close_rpc_connection(bt);
osEventFlagsSet(bt->api_event, BT_API_UNLOCK_EVENT);
}
int32_t bt_srv() {
Bt* bt = bt_alloc();
@@ -350,14 +358,8 @@ int32_t bt_srv() {
if(!furi_hal_bt_start_radio_stack()) {
FURI_LOG_E(TAG, "Radio stack start failed");
}
FuriHalBtStack stack_type = furi_hal_bt_get_radio_stack();
if(stack_type == FuriHalBtStackUnknown) {
bt_show_warning(bt, "Unsupported radio stack");
bt->status = BtStatusUnavailable;
} else if(stack_type == FuriHalBtStackHciLayer) {
bt->status = BtStatusUnavailable;
} else if(stack_type == FuriHalBtStackLight) {
if(furi_hal_bt_is_ble_gatt_gap_supported()) {
if(!furi_hal_bt_start_app(FuriHalBtProfileSerial, bt_on_gap_event_callback, bt)) {
FURI_LOG_E(TAG, "BLE App start failed");
} else {
@@ -366,6 +368,9 @@ int32_t bt_srv() {
}
furi_hal_bt_set_key_storage_change_callback(bt_on_key_storage_change_callback, bt);
}
} else {
bt_show_warning(bt, "Unsupported radio stack");
bt->status = BtStatusUnavailable;
}
furi_record_create("bt", bt);
@@ -392,6 +397,8 @@ int32_t bt_srv() {
bt_keys_storage_save(bt);
} else if(message.type == BtMessageTypeSetProfile) {
bt_change_profile(bt, &message);
} else if(message.type == BtMessageTypeDisconnect) {
bt_close_connection(bt);
} else if(message.type == BtMessageTypeForgetBondedDevices) {
bt_keys_storage_delete(bt);
}

View File

@@ -33,6 +33,12 @@ typedef void (*BtStatusChangedCallback)(BtStatus status, void* context);
*/
bool bt_set_profile(Bt* bt, BtProfile profile);
/** Disconnect from Central
*
* @param bt Bt instance
*/
void bt_disconnect(Bt* bt);
/** Set callback for Bluetooth status change notification
*
* @param bt Bt instance

View File

@@ -14,6 +14,16 @@ bool bt_set_profile(Bt* bt, BtProfile profile) {
return result;
}
void bt_disconnect(Bt* bt) {
furi_assert(bt);
// Send message
BtMessage message = {.type = BtMessageTypeDisconnect};
furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK);
// Wait for unlock
osEventFlagsWait(bt->api_event, BT_API_UNLOCK_EVENT, osFlagsWaitAny, osWaitForever);
}
void bt_set_status_changed_callback(Bt* bt, BtStatusChangedCallback callback, void* context) {
furi_assert(bt);

View File

@@ -25,6 +25,7 @@ typedef enum {
BtMessageTypePinCodeShow,
BtMessageTypeKeysStorageUpdated,
BtMessageTypeSetProfile,
BtMessageTypeDisconnect,
BtMessageTypeForgetBondedDevices,
} BtMessageType;