[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:
@@ -3,14 +3,9 @@
|
||||
#include <applications/cli/cli.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
|
||||
#include "ble.h"
|
||||
#include "bt_settings.h"
|
||||
|
||||
static const char* bt_cli_address_types[] = {
|
||||
"Public Device Address",
|
||||
"Random Device Address",
|
||||
"Public Identity Address",
|
||||
"Random (Static) Identity Address",
|
||||
};
|
||||
#include "bt_service/bt.h"
|
||||
|
||||
static void bt_cli_command_hci_info(Cli* cli, string_t args, void* context) {
|
||||
UNUSED(cli);
|
||||
@@ -38,7 +33,9 @@ static void bt_cli_command_carrier_tx(Cli* cli, string_t args, void* context) {
|
||||
break;
|
||||
}
|
||||
|
||||
furi_hal_bt_stop_advertising();
|
||||
Bt* bt = furi_record_open("bt");
|
||||
bt_disconnect(bt);
|
||||
furi_hal_bt_reinit();
|
||||
printf("Transmitting carrier at %d channel at %d dB power\r\n", channel, power);
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
furi_hal_bt_start_tone_tx(channel, 0x19 + power);
|
||||
@@ -47,6 +44,9 @@ static void bt_cli_command_carrier_tx(Cli* cli, string_t args, void* context) {
|
||||
osDelay(250);
|
||||
}
|
||||
furi_hal_bt_stop_tone_tx();
|
||||
|
||||
bt_set_profile(bt, BtProfileSerial);
|
||||
furi_record_close("bt");
|
||||
} while(false);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,9 @@ static void bt_cli_command_carrier_rx(Cli* cli, string_t args, void* context) {
|
||||
break;
|
||||
}
|
||||
|
||||
furi_hal_bt_stop_advertising();
|
||||
Bt* bt = furi_record_open("bt");
|
||||
bt_disconnect(bt);
|
||||
furi_hal_bt_reinit();
|
||||
printf("Receiving carrier at %d channel\r\n", channel);
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
|
||||
@@ -73,6 +75,9 @@ static void bt_cli_command_carrier_rx(Cli* cli, string_t args, void* context) {
|
||||
}
|
||||
|
||||
furi_hal_bt_stop_packet_test();
|
||||
|
||||
bt_set_profile(bt, BtProfileSerial);
|
||||
furi_record_close("bt");
|
||||
} while(false);
|
||||
}
|
||||
|
||||
@@ -102,7 +107,9 @@ static void bt_cli_command_packet_tx(Cli* cli, string_t args, void* context) {
|
||||
break;
|
||||
}
|
||||
|
||||
furi_hal_bt_stop_advertising();
|
||||
Bt* bt = furi_record_open("bt");
|
||||
bt_disconnect(bt);
|
||||
furi_hal_bt_reinit();
|
||||
printf(
|
||||
"Transmitting %d pattern packet at %d channel at %d M datarate\r\n",
|
||||
pattern,
|
||||
@@ -117,6 +124,8 @@ static void bt_cli_command_packet_tx(Cli* cli, string_t args, void* context) {
|
||||
furi_hal_bt_stop_packet_test();
|
||||
printf("Transmitted %lu packets", furi_hal_bt_get_transmitted_packets());
|
||||
|
||||
bt_set_profile(bt, BtProfileSerial);
|
||||
furi_record_close("bt");
|
||||
} while(false);
|
||||
}
|
||||
|
||||
@@ -135,7 +144,9 @@ static void bt_cli_command_packet_rx(Cli* cli, string_t args, void* context) {
|
||||
break;
|
||||
}
|
||||
|
||||
furi_hal_bt_stop_advertising();
|
||||
Bt* bt = furi_record_open("bt");
|
||||
bt_disconnect(bt);
|
||||
furi_hal_bt_reinit();
|
||||
printf("Receiving packets at %d channel at %d M datarate\r\n", channel, datarate);
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
furi_hal_bt_start_packet_rx(channel, datarate);
|
||||
@@ -147,51 +158,23 @@ static void bt_cli_command_packet_rx(Cli* cli, string_t args, void* context) {
|
||||
}
|
||||
uint16_t packets_received = furi_hal_bt_stop_packet_test();
|
||||
printf("Received %hu packets", packets_received);
|
||||
|
||||
bt_set_profile(bt, BtProfileSerial);
|
||||
furi_record_close("bt");
|
||||
} while(false);
|
||||
}
|
||||
|
||||
static void bt_cli_scan_callback(GapAddress address, void* context) {
|
||||
furi_assert(context);
|
||||
osMessageQueueId_t queue = context;
|
||||
osMessageQueuePut(queue, &address, 0, 250);
|
||||
}
|
||||
|
||||
static void bt_cli_command_scan(Cli* cli, string_t args, void* context) {
|
||||
UNUSED(context);
|
||||
UNUSED(args);
|
||||
osMessageQueueId_t queue = osMessageQueueNew(20, sizeof(GapAddress), NULL);
|
||||
furi_hal_bt_start_scan(bt_cli_scan_callback, queue);
|
||||
|
||||
GapAddress address = {};
|
||||
bool exit = false;
|
||||
while(!exit) {
|
||||
if(osMessageQueueGet(queue, &address, NULL, 250) == osOK) {
|
||||
if(address.type < sizeof(bt_cli_address_types)) {
|
||||
printf("Found new device. Type: %s, MAC: ", bt_cli_address_types[address.type]);
|
||||
for(uint8_t i = 0; i < sizeof(address.mac) - 1; i++) {
|
||||
printf("%02X:", address.mac[i]);
|
||||
}
|
||||
printf("%02X\r\n", address.mac[sizeof(address.mac) - 1]);
|
||||
}
|
||||
}
|
||||
exit = cli_cmd_interrupt_received(cli);
|
||||
}
|
||||
furi_hal_bt_stop_scan();
|
||||
osMessageQueueDelete(queue);
|
||||
}
|
||||
|
||||
static void bt_cli_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("bt <cmd> <args>\r\n");
|
||||
printf("Cmd list:\r\n");
|
||||
printf("\thci_info\t - HCI info\r\n");
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) &&
|
||||
furi_hal_bt_get_radio_stack() == FuriHalBtStackHciLayer) {
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) && furi_hal_bt_is_testing_supported()) {
|
||||
printf("\ttx_carrier <channel:0-39> <power:0-6>\t - start tx carrier test\r\n");
|
||||
printf("\trx_carrier <channel:0-39>\t - start rx carrier test\r\n");
|
||||
printf("\ttx_pt <channel:0-39> <pattern:0-5> <datarate:1-2>\t - start tx packet test\r\n");
|
||||
printf("\trx_pt <channel:0-39> <datarate:1-2>\t - start rx packer test\r\n");
|
||||
printf("\tscan\t - start scanner\r\n");
|
||||
printf(
|
||||
"\ttx_packet <channel:0-39> <pattern:0-5> <datarate:1-2>\t - start tx packet test\r\n");
|
||||
printf("\trx_packet <channel:0-39> <datarate:1-2>\t - start rx packer test\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,28 +196,23 @@ static void bt_cli(Cli* cli, string_t args, void* context) {
|
||||
bt_cli_command_hci_info(cli, args, NULL);
|
||||
break;
|
||||
}
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) &&
|
||||
furi_hal_bt_get_radio_stack() == FuriHalBtStackHciLayer) {
|
||||
if(string_cmp_str(cmd, "carrier_tx") == 0) {
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) && furi_hal_bt_is_testing_supported()) {
|
||||
if(string_cmp_str(cmd, "tx_carrier") == 0) {
|
||||
bt_cli_command_carrier_tx(cli, args, NULL);
|
||||
break;
|
||||
}
|
||||
if(string_cmp_str(cmd, "carrier_rx") == 0) {
|
||||
if(string_cmp_str(cmd, "rx_carrier") == 0) {
|
||||
bt_cli_command_carrier_rx(cli, args, NULL);
|
||||
break;
|
||||
}
|
||||
if(string_cmp_str(cmd, "packet_tx") == 0) {
|
||||
if(string_cmp_str(cmd, "tx_packet") == 0) {
|
||||
bt_cli_command_packet_tx(cli, args, NULL);
|
||||
break;
|
||||
}
|
||||
if(string_cmp_str(cmd, "packet_rx") == 0) {
|
||||
if(string_cmp_str(cmd, "rx_packet") == 0) {
|
||||
bt_cli_command_packet_rx(cli, args, NULL);
|
||||
break;
|
||||
}
|
||||
if(string_cmp_str(cmd, "scan") == 0) {
|
||||
bt_cli_command_scan(cli, args, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bt_cli_print_usage();
|
||||
|
@@ -97,8 +97,8 @@ void bt_debug_app_free(BtDebugApp* app) {
|
||||
|
||||
int32_t bt_debug_app(void* p) {
|
||||
UNUSED(p);
|
||||
if(furi_hal_bt_get_radio_stack() != FuriHalBtStackHciLayer) {
|
||||
FURI_LOG_E(TAG, "Incorrect radio stack, replace with HciLayer for tests.");
|
||||
if(!furi_hal_bt_is_testing_supported()) {
|
||||
FURI_LOG_E(TAG, "Incorrect radio stack: radio testing fetures are absent.");
|
||||
DialogsApp* dialogs = furi_record_open("dialogs");
|
||||
dialog_message_show_storage_error(dialogs, "Incorrect\nRadioStack");
|
||||
return 255;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -25,6 +25,7 @@ typedef enum {
|
||||
BtMessageTypePinCodeShow,
|
||||
BtMessageTypeKeysStorageUpdated,
|
||||
BtMessageTypeSetProfile,
|
||||
BtMessageTypeDisconnect,
|
||||
BtMessageTypeForgetBondedDevices,
|
||||
} BtMessageType;
|
||||
|
||||
|
@@ -39,8 +39,7 @@ void bt_settings_scene_start_on_enter(void* context) {
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
VariableItem* item;
|
||||
|
||||
FuriHalBtStack stack_type = furi_hal_bt_get_radio_stack();
|
||||
if(stack_type == FuriHalBtStackLight) {
|
||||
if(furi_hal_bt_is_ble_gatt_gap_supported()) {
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Bluetooth",
|
||||
|
@@ -26,7 +26,7 @@ static const char* update_task_stage_descr[] = {
|
||||
[UpdateTaskStageResourcesUpdate] = "Updating resources",
|
||||
[UpdateTaskStageCompleted] = "Restarting...",
|
||||
[UpdateTaskStageError] = "Error",
|
||||
[UpdateTaskStageOBError] = "OB Err, report",
|
||||
[UpdateTaskStageOBError] = "OB, report",
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
Reference in New Issue
Block a user