diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 7611761bb4537..02528a5e3e2a1 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -278,6 +278,15 @@ config BT_SETTINGS_CCC_STORE_MAX Defines the max number of Client Characteristic Configuration (CCC) that the stack can handle +config BT_SETTINGS_BT_NAME_STORE + bool "Store the BT name as setting" + depends on BT_DEVICE_NAME_DYNAMIC + default y + help + When selected, the name that is set when calling @ref bt_set_name + will be stored persistently and automatically set as BT name at + each boot + endif # BT_SETTINGS config BT_FILTER_ACCEPT_LIST diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 8f742ee56b5f3..b97175a32bd16 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -4563,7 +4563,7 @@ int bt_set_name(const char *name) memcpy(bt_dev.name, name, len); bt_dev.name[len] = '\0'; - if (IS_ENABLED(CONFIG_BT_SETTINGS)) { + if (IS_ENABLED(CONFIG_BT_SETTINGS_BT_NAME_STORE)) { err = bt_settings_store_name(bt_dev.name, len); if (err) { LOG_WRN("Unable to store name"); diff --git a/subsys/bluetooth/host/settings.c b/subsys/bluetooth/host/settings.c index 84b4f1eb4b6a8..0b1c6c00d6ffb 100644 --- a/subsys/bluetooth/host/settings.c +++ b/subsys/bluetooth/host/settings.c @@ -180,7 +180,7 @@ static int set_setting(const char *name, size_t len_rd, settings_read_cb read_cb return 0; } -#if defined(CONFIG_BT_DEVICE_NAME_DYNAMIC) +#if defined(CONFIG_BT_SETTINGS_BT_NAME_STORE) if (!strncmp(name, "name", len)) { len = read_cb(cb_arg, &bt_dev.name, sizeof(bt_dev.name) - 1); if (len < 0) { @@ -414,10 +414,12 @@ int bt_settings_delete_hash(void) return bt_settings_delete("hash", 0, NULL); } +#if defined(CONFIG_BT_SETTINGS_BT_NAME_STORE) int bt_settings_store_name(const void *value, size_t val_len) { return bt_settings_store("name", 0, NULL, value, val_len); } +#endif int bt_settings_delete_name(void) {