Merge branch 'feat/add_get_device_name_api' into 'master'

feat(bt/bluedroid): Added API to get local device name

Closes BT-3526

See merge request espressif/esp-idf!27667
This commit is contained in:
Wang Meng Yang 2023-12-27 10:37:33 +08:00
commit 4c8f6c5458
28 changed files with 254 additions and 26 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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)
{

View File

@ -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.

View File

@ -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.

View File

@ -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 <string.h>
#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(&param, 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, &param, 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);
}

View File

@ -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__ */

View File

@ -14,6 +14,7 @@
#include <esp_gap_ble_api.h>
#include <esp_gatts_api.h>
#include <esp_bt_main.h>
#include "esp_bt_device.h"
#include <esp_gatt_common_api.h>
#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;

View File

@ -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.

View File

@ -6,6 +6,7 @@ Migration from 5.2 to 5.3
.. toctree::
:maxdepth: 1
bluetooth-low-energy
peripherals
security
storage

View File

@ -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` 中。可直接删除该函数。

View File

@ -6,6 +6,7 @@
.. toctree::
:maxdepth: 1
bluetooth-low-energy
peripherals
security
storage

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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));

View File

@ -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);
}

View File

@ -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,

View File

@ -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);
}

View File

@ -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){

View File

@ -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);
}

View File

@ -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__);

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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