diff --git a/components/bt/host/bluedroid/api/esp_bt_device.c b/components/bt/host/bluedroid/api/esp_bt_device.c index 0a323cfe29..c37b9adb61 100644 --- a/components/bt/host/bluedroid/api/esp_bt_device.c +++ b/components/bt/host/bluedroid/api/esp_bt_device.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -11,6 +11,7 @@ #include "device/controller.h" #include "btc/btc_task.h" #include "btc/btc_dev.h" +#include "btc/btc_config.h" const uint8_t *esp_bt_dev_get_address(void) { @@ -68,3 +69,10 @@ esp_err_t esp_bt_dev_coex_status_config(esp_bt_dev_coex_type_t type, esp_bt_dev_ return (btc_transfer_context(&msg, &arg, sizeof(btc_dev_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } #endif + +esp_err_t esp_bt_config_file_path_update(const char *file_path) +{ + ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_UNINITIALIZED); + + return btc_config_file_path_update(file_path); +} diff --git a/components/bt/host/bluedroid/api/esp_gatt_common_api.c b/components/bt/host/bluedroid/api/esp_gatt_common_api.c index a6a52bf2e2..d0f3b0e02a 100644 --- a/components/bt/host/bluedroid/api/esp_gatt_common_api.c +++ b/components/bt/host/bluedroid/api/esp_gatt_common_api.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/bt/host/bluedroid/api/include/api/esp_bt_device.h b/components/bt/host/bluedroid/api/include/api/esp_bt_device.h index 997d827f65..5c00c45616 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_bt_device.h +++ b/components/bt/host/bluedroid/api/include/api/esp_bt_device.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -79,6 +79,18 @@ esp_err_t esp_bt_dev_set_device_name(const char *name); */ esp_err_t esp_bt_dev_coex_status_config(esp_bt_dev_coex_type_t type, esp_bt_dev_coex_op_t op, uint8_t status); +/** + * @brief This function is used to update the path name of bluetooth bond keys saved in the NVS module + * and need to be called before esp_bluedroid_init(). + * @param[in] file_path: the name of config file path, the length of file_path should be less than NVS_NS_NAME_MAX_SIZE + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_bt_config_file_path_update(const char *file_path); + #ifdef __cplusplus } #endif diff --git a/components/bt/host/bluedroid/btc/core/btc_config.c b/components/bt/host/bluedroid/btc/core/btc_config.c index 32393636e7..955d3d266f 100644 --- a/components/bt/host/bluedroid/btc/core/btc_config.c +++ b/components/bt/host/bluedroid/btc/core/btc_config.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -20,14 +20,26 @@ #include "osi/mutex.h" #include "stack/bt_types.h" +#include "nvs.h" -static const char *CONFIG_FILE_PATH = "bt_config.conf"; +static char CONFIG_FILE_PATH[NVS_NS_NAME_MAX_SIZE] = "bt_config.conf"; static const period_ms_t CONFIG_SETTLE_PERIOD_MS = 3000; static void btc_key_value_to_string(uint8_t *key_value, char *value_str, int key_length); static osi_mutex_t lock; // protects operations on |config|. static config_t *config; +int btc_config_file_path_update(const char *file_path) +{ + if (file_path != NULL && strlen(file_path) < NVS_NS_NAME_MAX_SIZE) { + memcpy(CONFIG_FILE_PATH, file_path, strlen(file_path)); + CONFIG_FILE_PATH[strlen(file_path)] = '\0'; + return 0; + } + BTC_TRACE_ERROR("Update failed, file_path is NULL or length should be less than %d\n", NVS_NS_NAME_MAX_SIZE); + return -1; +} + bool btc_compare_address_key_value(const char *section, const char *key_type, void *key_value, int key_length) { assert(key_value != NULL); diff --git a/components/bt/host/bluedroid/btc/include/btc/btc_config.h b/components/bt/host/bluedroid/btc/include/btc/btc_config.h index 731859a8cb..eb3c89d54d 100644 --- a/components/bt/host/bluedroid/btc/include/btc/btc_config.h +++ b/components/bt/host/bluedroid/btc/include/btc/btc_config.h @@ -47,4 +47,5 @@ bool btc_get_device_type(const BD_ADDR bd_addr, int *p_device_type); void btc_config_lock(void); void btc_config_unlock(void); +int btc_config_file_path_update(const char *file_path); #endif