diff --git a/components/bt/common/btc/core/btc_task.c b/components/bt/common/btc/core/btc_task.c index 179d501e72..977f19db50 100644 --- a/components/bt/common/btc/core/btc_task.c +++ b/components/bt/common/btc/core/btc_task.c @@ -98,7 +98,7 @@ osi_thread_t *btc_thread; static const btc_func_t profile_tab[BTC_PID_NUM] = { #ifdef CONFIG_BT_BLUEDROID_ENABLED [BTC_PID_MAIN_INIT] = {btc_main_call_handler, NULL }, - [BTC_PID_DEV] = {btc_dev_call_handler, NULL }, + [BTC_PID_DEV] = {btc_dev_call_handler, btc_dev_cb_handler }, #if (GATTS_INCLUDED == TRUE) [BTC_PID_GATTS] = {btc_gatts_call_handler, btc_gatts_cb_handler }, #endif ///GATTS_INCLUDED == TRUE diff --git a/components/bt/common/btc/profile/esp/blufi/bluedroid_host/esp_blufi.c b/components/bt/common/btc/profile/esp/blufi/bluedroid_host/esp_blufi.c index a0da30f43d..4c1dea62eb 100644 --- a/components/bt/common/btc/profile/esp/blufi/bluedroid_host/esp_blufi.c +++ b/components/bt/common/btc/profile/esp/blufi/bluedroid_host/esp_blufi.c @@ -370,7 +370,7 @@ void esp_blufi_deinit(void) void esp_blufi_adv_start(void) { - esp_ble_gap_set_device_name(BLUFI_DEVICE_NAME); + esp_bt_dev_set_device_name(BLUFI_DEVICE_NAME); esp_ble_gap_config_adv_data(&blufi_adv_data); } diff --git a/components/bt/host/bluedroid/api/esp_bt_device.c b/components/bt/host/bluedroid/api/esp_bt_device.c index c37b9adb61..ff5361a2d7 100644 --- a/components/bt/host/bluedroid/api/esp_bt_device.c +++ b/components/bt/host/bluedroid/api/esp_bt_device.c @@ -12,6 +12,21 @@ #include "btc/btc_task.h" #include "btc/btc_dev.h" #include "btc/btc_config.h" +#include "btc/btc_manage.h" + +esp_err_t esp_bt_dev_register_callback(esp_bt_dev_cb_t callback) +{ + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + if (callback == NULL) { + return ESP_ERR_INVALID_ARG; + } + + btc_profile_cb_set(BTC_PID_DEV, callback); + return ESP_OK; +} const uint8_t *esp_bt_dev_get_address(void) { @@ -49,6 +64,21 @@ esp_err_t esp_bt_dev_set_device_name(const char *name) return (btc_transfer_context(&msg, &arg, sizeof(btc_dev_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } +esp_err_t esp_bt_dev_get_device_name(void) +{ + btc_msg_t msg = {0}; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_DEV; + msg.act = BTC_DEV_ACT_GET_DEVICE_NAME; + + return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + #if (ESP_COEX_VSC_INCLUDED == TRUE) 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) { 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 5c00c45616..25da240374 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 @@ -37,6 +37,41 @@ typedef enum { ESP_BT_DEV_COEX_TYPE_BT, } esp_bt_dev_coex_type_t; +/// BT device callback events +typedef enum { + ESP_BT_DEV_NAME_RES_EVT = 0, /*!< Device name result event */ + ESP_BT_DEV_EVT_MAX, +} esp_bt_dev_cb_event_t; + +/// BT device callback parameters +typedef union { + /** + * @brief ESP_BT_DEV_NAME_RES_EVT + */ + struct name_res_param { + esp_bt_status_t status; /*!< Status of getting device name */ + char *name; /*!< Name of Bluetooth device */ + } name_res; /*!< discovery result parameter struct */ +} esp_bt_dev_cb_param_t; + +/** + * @brief bluetooth device callback function type + * + * @param event : Event type + * + * @param param : Pointer to callback parameter + */ +typedef void (* esp_bt_dev_cb_t)(esp_bt_dev_cb_event_t event, esp_bt_dev_cb_param_t *param); + +/** + * @brief register callback function. This function should be called after esp_bluedroid_enable() completes successfully + * + * @return + * - ESP_OK : Succeed + * - ESP_FAIL: others + */ +esp_err_t esp_bt_dev_register_callback(esp_bt_dev_cb_t callback); + /** * * @brief Get bluetooth device address. Must use after "esp_bluedroid_enable". @@ -63,6 +98,20 @@ const uint8_t *esp_bt_dev_get_address(void); */ esp_err_t esp_bt_dev_set_device_name(const char *name); +/** + * @brief Get bluetooth device name. This function should be called after esp_bluedroid_enable() + * completes successfully. + * + * A BR/EDR/LE device type shall have a single Bluetooth device name which shall be + * identical irrespective of the physical channel used to perform the name discovery procedure. + * + * @return + * - ESP_OK : Succeed + * - ESP_ERR_INVALID_STATE : if bluetooth stack is not yet enabled + * - ESP_FAIL : others + */ +esp_err_t esp_bt_dev_get_device_name(void); + /** * @brief Config bluetooth device coexis status. This function should be called after esp_bluedroid_enable() * completes successfully. diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h index c1ea8b3fd9..c993094547 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h @@ -1714,7 +1714,7 @@ esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr, * - other : failed * */ -esp_err_t esp_ble_gap_set_device_name(const char *name); +esp_err_t esp_ble_gap_set_device_name(const char *name) __attribute__((deprecated("Please use esp_bt_dev_set_device_name"))); /** * @brief Get device name of the local device @@ -1724,7 +1724,7 @@ esp_err_t esp_ble_gap_set_device_name(const char *name); * - other : failed * */ -esp_err_t esp_ble_gap_get_device_name(void); +esp_err_t esp_ble_gap_get_device_name(void) __attribute__((deprecated("Please use esp_bt_dev_get_device_name"))); /** * @brief This function is called to get local used address and address type. diff --git a/components/bt/host/bluedroid/btc/core/btc_dev.c b/components/bt/host/bluedroid/btc/core/btc_dev.c index 1aceface6a..a096700da2 100644 --- a/components/bt/host/bluedroid/btc/core/btc_dev.c +++ b/components/bt/host/bluedroid/btc/core/btc_dev.c @@ -1,17 +1,54 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include #include "osi/allocator.h" +#include "stack/bt_types.h" #include "bta/bta_api.h" #include "btc/btc_task.h" #include "btc/btc_manage.h" +#include "btc/btc_util.h" #include "btc/btc_dev.h" -void btc_dev_arg_deep_free(btc_msg_t *msg) +static inline void btc_dev_cb_to_app(esp_bt_dev_cb_event_t event, esp_bt_dev_cb_param_t *param) +{ + esp_bt_dev_cb_t btc_bt_dev_cb = (esp_bt_dev_cb_t)btc_profile_cb_get(BTC_PID_DEV); + if (btc_bt_dev_cb) { + btc_bt_dev_cb(event, param); + } +} + +static void btc_dev_get_dev_name_callback(UINT8 status, char *name) +{ + esp_bt_dev_cb_param_t param; + bt_status_t ret; + btc_msg_t msg = {0}; + + memset(¶m, 0, sizeof(esp_bt_dev_cb_param_t)); + + msg.sig = BTC_SIG_API_CB; + msg.pid = BTC_PID_DEV; + msg.act = ESP_BT_DEV_NAME_RES_EVT; + + param.name_res.status = btc_btm_status_to_esp_status(status); + param.name_res.name = (char *)osi_malloc(BTC_MAX_LOC_BD_NAME_LEN + 1); + if (param.name_res.name) { + BCM_STRNCPY_S(param.name_res.name, name, BTC_MAX_LOC_BD_NAME_LEN); + param.name_res.name[BTC_MAX_LOC_BD_NAME_LEN] = '\0'; + } else { + param.name_res.status = ESP_BT_STATUS_NOMEM; + } + + ret = btc_transfer_context(&msg, ¶m, sizeof(esp_bt_dev_cb_param_t), NULL, NULL); + if (ret != BT_STATUS_SUCCESS) { + BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__); + } +} + +void btc_dev_call_arg_deep_free(btc_msg_t *msg) { BTC_TRACE_DEBUG("%s \n", __func__); @@ -23,10 +60,29 @@ void btc_dev_arg_deep_free(btc_msg_t *msg) } break; } + case BTC_DEV_ACT_GET_DEVICE_NAME: #if (ESP_COEX_VSC_INCLUDED == TRUE) case BTC_DEV_ACT_CFG_COEX_STATUS: - break; #endif + break; + default: + BTC_TRACE_DEBUG("Unhandled deep free %d\n", msg->act); + break; + } +} + +void btc_dev_cb_arg_deep_free(btc_msg_t *msg) +{ + BTC_TRACE_DEBUG("%s \n", __func__); + + switch (msg->act) { + case ESP_BT_DEV_NAME_RES_EVT:{ + char *name = ((esp_bt_dev_cb_param_t *)msg->arg)->name_res.name; + if (name) { + osi_free(name); + } + break; + } default: BTC_TRACE_DEBUG("Unhandled deep free %d\n", msg->act); break; @@ -43,6 +99,9 @@ void btc_dev_call_handler(btc_msg_t *msg) case BTC_DEV_ACT_SET_DEVICE_NAME: BTA_DmSetDeviceName(arg->set_dev_name.device_name); break; + case BTC_DEV_ACT_GET_DEVICE_NAME: + BTA_DmGetDeviceName(btc_dev_get_dev_name_callback); + break; #if (ESP_COEX_VSC_INCLUDED == TRUE) case BTC_DEV_ACT_CFG_COEX_STATUS: BTA_DmCfgCoexStatus(arg->cfg_coex_status.op, @@ -54,5 +113,18 @@ void btc_dev_call_handler(btc_msg_t *msg) break; } - btc_dev_arg_deep_free(msg); + btc_dev_call_arg_deep_free(msg); +} + +void btc_dev_cb_handler(btc_msg_t *msg) +{ + esp_bt_dev_cb_param_t *param = (esp_bt_dev_cb_param_t *)msg->arg; + + if (msg->act < ESP_BT_DEV_EVT_MAX) { + btc_dev_cb_to_app(msg->act, param); + } else { + BTC_TRACE_ERROR("%s, unknow msg->act = %d", __func__, msg->act); + } + + btc_dev_cb_arg_deep_free(msg); } diff --git a/components/bt/host/bluedroid/btc/include/btc/btc_dev.h b/components/bt/host/bluedroid/btc/include/btc/btc_dev.h index 4cf085d7de..4f2978aeec 100644 --- a/components/bt/host/bluedroid/btc/include/btc/btc_dev.h +++ b/components/bt/host/bluedroid/btc/include/btc/btc_dev.h @@ -13,6 +13,7 @@ typedef enum { BTC_DEV_ACT_SET_DEVICE_NAME, + BTC_DEV_ACT_GET_DEVICE_NAME, #if (ESP_COEX_VSC_INCLUDED == TRUE) BTC_DEV_ACT_CFG_COEX_STATUS, #endif @@ -36,5 +37,6 @@ typedef union { } btc_dev_args_t; void btc_dev_call_handler(btc_msg_t *msg); +void btc_dev_cb_handler(btc_msg_t *msg); #endif /* __BTC_DEV_H__ */ diff --git a/components/protocomm/src/simple_ble/simple_ble.c b/components/protocomm/src/simple_ble/simple_ble.c index a4184b5262..76431e23ef 100644 --- a/components/protocomm/src/simple_ble/simple_ble.c +++ b/components/protocomm/src/simple_ble/simple_ble.c @@ -14,6 +14,7 @@ #include #include #include +#include "esp_bt_device.h" #include #include "simple_ble.h" @@ -93,7 +94,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ ESP_LOGE(TAG, "create attr table failed, error code = 0x%x", ret); return; } - ret = esp_ble_gap_set_device_name(g_ble_cfg_p->device_name); + ret = esp_bt_dev_set_device_name(g_ble_cfg_p->device_name); if (ret) { ESP_LOGE(TAG, "set device name failed, error code = 0x%x", ret); return; diff --git a/docs/en/migration-guides/release-5.x/5.3/bluetooth-low-energy.rst b/docs/en/migration-guides/release-5.x/5.3/bluetooth-low-energy.rst new file mode 100644 index 0000000000..9bc6fafe23 --- /dev/null +++ b/docs/en/migration-guides/release-5.x/5.3/bluetooth-low-energy.rst @@ -0,0 +1,19 @@ +Bluetooth Low Energy +==================== + +:link_to_translation:`zh_CN:[中文]` + +Bluedroid +--------- + + The following Bluedroid APIs have been removed: + + - :component_file:`bt/host/bluedroid/api/include/api/esp_gap_ble_api.h` + + - Remove ``esp_err_t esp_ble_gap_set_device_name(const char *name)`` + + - Local device name setting calls have been moved to :cpp:func:`esp_bt_dev_set_device_name`. This function can be deleted directly. + + - Remove ``esp_err_t esp_ble_gap_get_device_name(void)`` + + - Local device name getting calls have been moved to :cpp:func:`esp_bt_dev_get_device_name`. This function can be deleted directly. diff --git a/docs/en/migration-guides/release-5.x/5.3/index.rst b/docs/en/migration-guides/release-5.x/5.3/index.rst index c07bfca1c8..06f5ab107b 100644 --- a/docs/en/migration-guides/release-5.x/5.3/index.rst +++ b/docs/en/migration-guides/release-5.x/5.3/index.rst @@ -6,6 +6,7 @@ Migration from 5.2 to 5.3 .. toctree:: :maxdepth: 1 + bluetooth-low-energy peripherals security storage diff --git a/docs/zh_CN/migration-guides/release-5.x/5.3/bluetooth-low-energy.rst b/docs/zh_CN/migration-guides/release-5.x/5.3/bluetooth-low-energy.rst new file mode 100644 index 0000000000..35f297d565 --- /dev/null +++ b/docs/zh_CN/migration-guides/release-5.x/5.3/bluetooth-low-energy.rst @@ -0,0 +1,19 @@ +低功耗蓝牙 +========== + +:link_to_translation:`en:[English]` + +Bluedroid +--------- + + 以下 Bluedroid API 已被移除: + + - :component_file:`bt/host/bluedroid/api/include/api/esp_gap_ble_api.h` + + - 移除 ``esp_err_t esp_ble_gap_set_device_name(const char *name)`` + + - 设置本地设备名的调用已经被移到 :cpp:func:`esp_bt_dev_set_device_name` 中。可直接删除该函数。 + + - 移除 ``esp_err_t esp_ble_gap_get_device_name(void)`` + + - 获取本地设备名的调用已经被移到 :cpp:func:`esp_bt_dev_get_device_name` 中。可直接删除该函数。 diff --git a/docs/zh_CN/migration-guides/release-5.x/5.3/index.rst b/docs/zh_CN/migration-guides/release-5.x/5.3/index.rst index 51af4fd001..daae13829c 100644 --- a/docs/zh_CN/migration-guides/release-5.x/5.3/index.rst +++ b/docs/zh_CN/migration-guides/release-5.x/5.3/index.rst @@ -6,6 +6,7 @@ .. toctree:: :maxdepth: 1 + bluetooth-low-energy peripherals security storage diff --git a/examples/bluetooth/bluedroid/ble/ble_ancs/main/ble_ancs_demo.c b/examples/bluetooth/bluedroid/ble/ble_ancs/main/ble_ancs_demo.c index 0098cc9938..13d502f2b9 100644 --- a/examples/bluetooth/bluedroid/ble/ble_ancs/main/ble_ancs_demo.c +++ b/examples/bluetooth/bluedroid/ble/ble_ancs/main/ble_ancs_demo.c @@ -17,6 +17,7 @@ #include "esp_gatts_api.h" #include "esp_bt_defs.h" #include "esp_bt_main.h" +#include "esp_bt_device.h" #include "esp_gattc_api.h" #include "esp_gatt_defs.h" #include "esp_gatt_common_api.h" @@ -331,7 +332,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ switch (event) { case ESP_GATTC_REG_EVT: ESP_LOGI(BLE_ANCS_TAG, "REG_EVT"); - esp_ble_gap_set_device_name(EXAMPLE_DEVICE_NAME); + esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME); esp_ble_gap_config_local_icon (ESP_BLE_APPEARANCE_GENERIC_WATCH); //generate a resolvable random address esp_ble_gap_config_local_privacy(true); diff --git a/examples/bluetooth/bluedroid/ble/ble_compatibility_test/main/ble_compatibility_test.c b/examples/bluetooth/bluedroid/ble/ble_compatibility_test/main/ble_compatibility_test.c index a0102ab1bc..942aebb898 100644 --- a/examples/bluetooth/bluedroid/ble/ble_compatibility_test/main/ble_compatibility_test.c +++ b/examples/bluetooth/bluedroid/ble/ble_compatibility_test/main/ble_compatibility_test.c @@ -22,6 +22,7 @@ #include "esp_gap_ble_api.h" #include "esp_gatts_api.h" #include "esp_bt_main.h" +#include "esp_bt_device.h" #include "ble_compatibility_test.h" #include "esp_gatt_common_api.h" @@ -465,7 +466,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ { switch (event) { case ESP_GATTS_REG_EVT:{ - esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME); + esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(SAMPLE_DEVICE_NAME); if (set_dev_name_ret){ ESP_LOGE(EXAMPLE_TAG, "set device name failed, error code = %x", set_dev_name_ret); } diff --git a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c index c0e77c08a0..78aeb5b998 100644 --- a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c +++ b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c @@ -97,7 +97,7 @@ static void hidd_event_callback(esp_hidd_cb_event_t event, esp_hidd_cb_param_t * case ESP_HIDD_EVENT_REG_FINISH: { if (param->init_finish.state == ESP_HIDD_INIT_OK) { //esp_bd_addr_t rand_addr = {0x04,0x11,0x11,0x11,0x11,0x05}; - esp_ble_gap_set_device_name(HIDD_DEVICE_NAME); + esp_bt_dev_set_device_name(HIDD_DEVICE_NAME); esp_ble_gap_config_adv_data(&hidd_adv_data); } diff --git a/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c b/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c index ac90e4eb2f..92afdbc608 100644 --- a/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c +++ b/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c @@ -19,6 +19,7 @@ #include "esp_gatts_api.h" #include "esp_bt_defs.h" #include "esp_bt_main.h" +#include "esp_bt_device.h" #include "ble_spp_server_demo.h" #define GATTS_TABLE_TAG "GATTS_SPP_DEMO" @@ -498,7 +499,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ switch (event) { case ESP_GATTS_REG_EVT: ESP_LOGI(GATTS_TABLE_TAG, "%s %d", __func__, __LINE__); - esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME); + esp_bt_dev_set_device_name(SAMPLE_DEVICE_NAME); ESP_LOGI(GATTS_TABLE_TAG, "%s %d", __func__, __LINE__); esp_ble_gap_config_adv_data_raw((uint8_t *)spp_adv_data, sizeof(spp_adv_data)); diff --git a/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_server/main/example_ble_server_throughput.c b/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_server/main/example_ble_server_throughput.c index ceebe06f3b..84a6150d80 100644 --- a/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_server/main/example_ble_server_throughput.c +++ b/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_server/main/example_ble_server_throughput.c @@ -27,6 +27,7 @@ #include "esp_gatts_api.h" #include "esp_bt_defs.h" #include "esp_bt_main.h" +#include "esp_bt_device.h" #include "esp_gatt_common_api.h" #include "esp_timer.h" @@ -347,7 +348,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16; gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A; gl_profile_tab[PROFILE_A_APP_ID].gatts_if = gatts_if; - esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(TEST_DEVICE_NAME); + esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(TEST_DEVICE_NAME); if (set_dev_name_ret){ ESP_LOGE(GATTS_TAG, "set device name failed, error code = %x", set_dev_name_ret); } diff --git a/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c b/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c index f1ff6099cb..3371dbd69d 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c +++ b/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c @@ -17,6 +17,7 @@ #include "esp_gatts_api.h" #include "esp_bt_defs.h" #include "esp_bt_main.h" +#include "esp_bt_device.h" #include "example_ble_sec_gatts_demo.h" #define GATTS_TABLE_TAG "SEC_GATTS_DEMO" @@ -407,7 +408,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, ESP_LOGV(GATTS_TABLE_TAG, "event = %x",event); switch (event) { case ESP_GATTS_REG_EVT: - esp_ble_gap_set_device_name(EXAMPLE_DEVICE_NAME); + esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME); //generate a resolvable random address esp_ble_gap_config_local_privacy(true); esp_ble_gatts_create_attr_tab(heart_rate_gatt_db, gatts_if, diff --git a/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c b/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c index 18d2cc7ace..1e42e09c2d 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c +++ b/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c @@ -30,6 +30,7 @@ #include "esp_gatts_api.h" #include "esp_bt_defs.h" #include "esp_bt_main.h" +#include "esp_bt_device.h" #include "esp_gatt_common_api.h" #include "sdkconfig.h" @@ -309,7 +310,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16; gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A; - esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(TEST_DEVICE_NAME); + esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(TEST_DEVICE_NAME); if (set_dev_name_ret){ ESP_LOGE(GATTS_TAG, "set device name failed, error code = %x", set_dev_name_ret); } diff --git a/examples/bluetooth/bluedroid/ble/gatt_server/tutorial/Gatt_Server_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble/gatt_server/tutorial/Gatt_Server_Example_Walkthrough.md index 2de00d434b..9e66115dab 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server/tutorial/Gatt_Server_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble/gatt_server/tutorial/Gatt_Server_Example_Walkthrough.md @@ -254,7 +254,7 @@ An advertising payload can be up to 31 bytes of data. It is possible the paramet It is possible to also advertise customized raw data using the `esp_ble_gap_config_adv_data_raw()` and `esp_ble_gap_config_scan_rsp_data_raw()` functions, which require to create and pass a buffer for both advertising data and scanning response data. In this example, the raw data is represented by the `raw_adv_data[]` and `raw_scan_rsp_data[]` arrays. -Finally, to set the device name, the `esp_ble_gap_set_device_name()` function is used. The registering event handler is shown as follows: +Finally, to set the device name, the `esp_bt_dev_set_device_name()` function is used. The registering event handler is shown as follows: ```c static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) { @@ -266,7 +266,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16; gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A; - esp_ble_gap_set_device_name(TEST_DEVICE_NAME); + esp_bt_dev_set_device_name(TEST_DEVICE_NAME); #ifdef CONFIG_SET_RAW_ADV_DATA esp_err_t raw_adv_ret = esp_ble_gap_config_adv_data_raw(raw_adv_data, sizeof(raw_adv_data)); if (raw_adv_ret){ diff --git a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c index 4bd81ddef2..d2acb130f8 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c +++ b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c @@ -26,6 +26,7 @@ #include "esp_gap_ble_api.h" #include "esp_gatts_api.h" #include "esp_bt_main.h" +#include "esp_bt_device.h" #include "gatts_table_creat_demo.h" #include "esp_gatt_common_api.h" @@ -341,7 +342,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ { switch (event) { case ESP_GATTS_REG_EVT:{ - esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME); + esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(SAMPLE_DEVICE_NAME); if (set_dev_name_ret){ ESP_LOGE(GATTS_TABLE_TAG, "set device name failed, error code = %x", set_dev_name_ret); } diff --git a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md index 623043e713..748f29f012 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md @@ -165,7 +165,7 @@ The ``ESP_HEART_RATE_APP_ID`` serves as an application ID, distinguishing betwee The register application event is the first one that is triggered during the lifetime of the program. This example uses this event to configure advertising parameters upon registration in the profile event handler. The functions used to achieve this are: -* ``esp_ble_gap_set_device_name()``: used to set the advertised device name. +* ``esp_bt_dev_set_device_name()``: used to set the advertised device name. * ``esp_ble_gap_config_adv_data()``: used to configure standard advertising data. The function used to configure standard Bluetooth Specification advertisement parameters is ``esp_ble_gap_config_adv_data()`` which takes a pointer to an ``esp_ble_adv_data_t`` structure. The ``esp_ble_adv_data_t`` data structure for advertising data has the following definition: @@ -210,7 +210,7 @@ static esp_ble_adv_data_t heart_rate_adv_config = { The minimum and maximum slave preferred connection intervals are set in units of 1.25 ms. In this example, the minimum slave preferred connection interval is defined as 0x0006 * 1.25 ms = 7.5 ms and the maximum slave preferred connection interval is initialized as 0x0010 * 1.25 ms = 20 ms. -An advertising payload can be up to 31 bytes of data. It is possible that some of the parameters surpass the 31-byte advertisement packet limit which causes the stack to cut the message and leave some of the parameters out. To solve this, usually the longer parameters are stored in the scan response, which can be configured using the same ``esp_ble_gap_config_adv_data()`` function and an additional esp_ble_adv_data_t type structure with the .set_scan_rsp parameter is set to true. Finally, to set the device name the ``esp_ble_gap_set_device_name()`` function is used. The registering event handler is shown as follows: +An advertising payload can be up to 31 bytes of data. It is possible that some of the parameters surpass the 31-byte advertisement packet limit which causes the stack to cut the message and leave some of the parameters out. To solve this, usually the longer parameters are stored in the scan response, which can be configured using the same ``esp_ble_gap_config_adv_data()`` function and an additional esp_ble_adv_data_t type structure with the .set_scan_rsp parameter is set to true. Finally, to set the device name the ``esp_bt_dev_set_device_name()`` function is used. The registering event handler is shown as follows: ```c static void gatts_profile_event_handler(esp_gatts_cb_event_t event, @@ -220,7 +220,7 @@ esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) switch (event) { case ESP_GATTS_REG_EVT: ESP_LOGI(GATTS_TABLE_TAG, "%s %d", __func__, __LINE__); - esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME); + esp_bt_dev_set_device_name(SAMPLE_DEVICE_NAME); ESP_LOGI(GATTS_TABLE_TAG, "%s %d", __func__, __LINE__); esp_ble_gap_config_adv_data(&heart_rate_adv_config); ESP_LOGI(GATTS_TABLE_TAG, "%s %d", __func__, __LINE__); diff --git a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c index a140507146..4ccf9d05b4 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c @@ -37,6 +37,8 @@ enum { * STATIC FUNCTION DECLARATIONS *******************************/ +/* Device callback function */ +static void bt_app_dev_cb(esp_bt_dev_cb_event_t event, esp_bt_dev_cb_param_t *param); /* GAP callback function */ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param); /* handler for bluetooth stack enabled events */ @@ -46,6 +48,24 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param); * STATIC FUNCTION DEFINITIONS ******************************/ +static void bt_app_dev_cb(esp_bt_dev_cb_event_t event, esp_bt_dev_cb_param_t *param) +{ + switch (event) { + case ESP_BT_DEV_NAME_RES_EVT: { + if (param->name_res.status == ESP_BT_STATUS_SUCCESS) { + ESP_LOGI(BT_AV_TAG, "Get local device name success: %s", param->name_res.name); + } else { + ESP_LOGE(BT_AV_TAG, "Get local device name failed, status: %d", param->name_res.status); + } + break; + } + default: { + ESP_LOGI(BT_AV_TAG, "event: %d", event); + break; + } + } +} + static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) { uint8_t *bda = NULL; @@ -110,6 +130,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param) /* when do the stack up, this event comes */ case BT_APP_EVT_STACK_UP: { esp_bt_dev_set_device_name(LOCAL_DEVICE_NAME); + esp_bt_dev_register_callback(bt_app_dev_cb); esp_bt_gap_register_callback(bt_app_gap_cb); assert(esp_avrc_ct_init() == ESP_OK); @@ -127,6 +148,8 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param) /* Get the default value of the delay value */ esp_a2d_sink_get_delay_value(); + /* Get local device name */ + esp_bt_dev_get_device_name(); /* set discoverable and connectable mode, wait to be connected */ esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); diff --git a/examples/bluetooth/bluedroid/coex/gattc_gatts_coex/main/gattc_gatts_coex.c b/examples/bluetooth/bluedroid/coex/gattc_gatts_coex/main/gattc_gatts_coex.c index bbe1e80d2b..d7828cad85 100644 --- a/examples/bluetooth/bluedroid/coex/gattc_gatts_coex/main/gattc_gatts_coex.c +++ b/examples/bluetooth/bluedroid/coex/gattc_gatts_coex/main/gattc_gatts_coex.c @@ -19,6 +19,7 @@ #include "esp_gattc_api.h" #include "esp_gatt_defs.h" #include "esp_bt_main.h" +#include "esp_bt_device.h" #include "esp_gatt_common_api.h" #include "esp_gatts_api.h" #include "esp_bt_defs.h" @@ -601,7 +602,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i gatts_profile_tab[GATTS_PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16; gatts_profile_tab[GATTS_PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A; - esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(GATTS_ADV_NAME); + esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(GATTS_ADV_NAME); if (set_dev_name_ret) { ESP_LOGE(COEX_TAG, "set device name failed, error code = %x", set_dev_name_ret); } diff --git a/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c b/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c index 472fc6e71d..74542ae6f3 100644 --- a/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c +++ b/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c @@ -13,6 +13,7 @@ #include "freertos/task.h" #include "freertos/semphr.h" +#include "esp_bt_device.h" #include "esp_hid_gap.h" #if CONFIG_BT_NIMBLE_ENABLED @@ -699,7 +700,7 @@ esp_err_t esp_hid_ble_gap_adv_init(uint16_t appearance, const char *device_name) return ret; } - if ((ret = esp_ble_gap_set_device_name(device_name)) != ESP_OK) { + if ((ret = esp_bt_dev_set_device_name(device_name)) != ESP_OK) { ESP_LOGE(TAG, "GAP set_device_name failed: %d", ret); return ret; } diff --git a/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c b/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c index 0299b37d11..b39d0d9c91 100644 --- a/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c +++ b/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c @@ -13,6 +13,7 @@ #include "freertos/task.h" #include "freertos/semphr.h" +#include "esp_bt_device.h" #include "esp_hid_gap.h" #if CONFIG_BT_NIMBLE_ENABLED #include "host/ble_hs.h" @@ -738,7 +739,7 @@ esp_err_t esp_hid_ble_gap_adv_init(uint16_t appearance, const char *device_name) return ret; } - if ((ret = esp_ble_gap_set_device_name(device_name)) != ESP_OK) { + if ((ret = esp_bt_dev_set_device_name(device_name)) != ESP_OK) { ESP_LOGE(TAG, "GAP set_device_name failed: %d", ret); return ret; } diff --git a/examples/system/ota/advanced_https_ota/main/ble_helper/bluedroid_gatts.c b/examples/system/ota/advanced_https_ota/main/ble_helper/bluedroid_gatts.c index 22e64be4d8..3975c3280f 100644 --- a/examples/system/ota/advanced_https_ota/main/ble_helper/bluedroid_gatts.c +++ b/examples/system/ota/advanced_https_ota/main/ble_helper/bluedroid_gatts.c @@ -167,7 +167,7 @@ void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gat gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16; gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A; - esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(TEST_DEVICE_NAME); + esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(TEST_DEVICE_NAME); if (set_dev_name_ret) { ESP_LOGE(TAG, "set device name failed, error code = %x", set_dev_name_ret); } diff --git a/examples/system/ota/advanced_https_ota/main/ble_helper/include/bluedroid_gatts.h b/examples/system/ota/advanced_https_ota/main/ble_helper/include/bluedroid_gatts.h index 2ebbcc8b58..4d06c3486b 100644 --- a/examples/system/ota/advanced_https_ota/main/ble_helper/include/bluedroid_gatts.h +++ b/examples/system/ota/advanced_https_ota/main/ble_helper/include/bluedroid_gatts.h @@ -20,6 +20,7 @@ extern "C" { #include "esp_gatts_api.h" #include "esp_bt_defs.h" #include "esp_bt_main.h" +#include "esp_bt_device.h" #include "esp_gatt_common_api.h" #define PROFILE_NUM 1