From e800ec1cf39051d3e60a516bc7b47b25fd1f034b Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 19 Jan 2021 15:41:18 +0100 Subject: [PATCH] Bluetooth: host: Add options to control behavior of the init command Add options to control the behavior of the init command. Option no-settings-load allows the user to create identities with the id-create command after bt_enable() but before settings_load(). Option no-ready-cb allows the user to test using synchronous enable, since this sometimes leads to different behavior of the stack. Signed-off-by: Joakim Andersson --- subsys/bluetooth/shell/bt.c | 55 +++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index a10b25a9e36..10f54b6de39 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -39,6 +39,8 @@ #define DEVICE_NAME CONFIG_BT_DEVICE_NAME #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) +static bool no_settings_load; + uint8_t selected_id = BT_ID_DEFAULT; const struct shell *ctx_shell; @@ -511,8 +513,9 @@ static void bt_ready(int err) shell_print(ctx_shell, "Bluetooth initialized"); - if (IS_ENABLED(CONFIG_SETTINGS)) { + if (IS_ENABLED(CONFIG_SETTINGS) && !no_settings_load) { settings_load(); + shell_print(ctx_shell, "Settings Loaded"); } if (IS_ENABLED(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY)) { @@ -537,17 +540,55 @@ static void bt_ready(int err) static int cmd_init(const struct shell *shell, size_t argc, char *argv[]) { int err; + bool no_ready_cb = false; ctx_shell = shell; - err = bt_enable(bt_ready); - if (err) { - shell_error(shell, "Bluetooth init failed (err %d)", err); + for (size_t argn = 1; argn < argc; argn++) { + const char *arg = argv[argn]; + + if (!strcmp(arg, "no-settings-load")) { + no_settings_load = true; + } else if (!strcmp(arg, "sync")) { + no_ready_cb = true; + } else { + shell_help(shell); + return SHELL_CMD_HELP_PRINTED; + } + } + + if (no_ready_cb) { + err = bt_enable(bt_ready); + if (err) { + shell_error(shell, "Bluetooth init failed (err %d)", + err); + } + + } else { + err = bt_enable(NULL); + bt_ready(err); } return err; } +#ifdef CONFIG_SETTINGS +static int cmd_settings_load(const struct shell *shell, size_t argc, + char *argv[]) +{ + int err; + + err = settings_load(); + if (err) { + shell_error(shell, "Settings load failed (err %d)", err); + return err; + } + + shell_print(shell, "Settings loaded"); + return 0; +} +#endif + #if defined(CONFIG_BT_HCI) static int cmd_hci_cmd(const struct shell *shell, size_t argc, char *argv[]) { @@ -2881,7 +2922,11 @@ static int cmd_auth_oob_tk(const struct shell *shell, size_t argc, char *argv[]) #endif /* defined(CONFIG_BT_EXT_ADV) */ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds, - SHELL_CMD_ARG(init, NULL, HELP_NONE, cmd_init, 1, 0), + SHELL_CMD_ARG(init, NULL, "[no-settings-load], [sync]", + cmd_init, 1, 2), +#if defined(CONFIG_SETTINGS) + SHELL_CMD_ARG(settings-load, NULL, HELP_NONE, cmd_settings_load, 1, 0), +#endif #if defined(CONFIG_BT_HCI) SHELL_CMD_ARG(hci-cmd, NULL, " [data]", cmd_hci_cmd, 3, 1), #endif