From 4dda86b35286e0c27cca16240dbb22de0998696b Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Mon, 15 Apr 2024 20:01:30 +0800 Subject: [PATCH] fix(nt/bluedroid): Split the device name set functions feat(bt/bluedroid): added APIs to get/set device name on BT GAP side change(bt/bluedroid): use BT GAP APIs to set/get device name in bluetooth classic examples change(bt/bluedroid): use BT/BLE GAP APIs to set/get device name in coexist examples --- .../core/bluedroid_host/adapter.c | 4 +- .../bt/host/bluedroid/api/esp_gap_ble_api.c | 20 +++++- .../bt/host/bluedroid/api/esp_gap_bt_api.c | 38 ++++++++++- .../api/include/api/esp_gap_bt_api.h | 37 +++++++++-- .../bt/host/bluedroid/bta/dm/bta_dm_act.c | 10 +-- .../bt/host/bluedroid/bta/dm/bta_dm_api.c | 6 +- .../bluedroid/bta/dm/include/bta_dm_int.h | 4 +- .../host/bluedroid/bta/include/bta/bta_api.h | 4 +- .../bt/host/bluedroid/btc/core/btc_dev.c | 2 +- .../bt/host/bluedroid/btc/core/btc_dm.c | 2 +- .../btc/profile/std/gap/btc_gap_ble.c | 24 ++++++- .../btc/profile/std/gap/btc_gap_bt.c | 63 ++++++++++++++++++- .../btc/profile/std/include/btc_gap_ble.h | 2 +- .../btc/profile/std/include/btc_gap_bt.h | 9 ++- .../bt/host/bluedroid/stack/btm/btm_ble_gap.c | 8 +-- .../bt/host/bluedroid/stack/btm/btm_devctl.c | 56 +++++++++++++---- .../bt/host/bluedroid/stack/btm/btm_sec.c | 22 +++---- .../bluedroid/stack/btm/include/btm_int.h | 3 +- .../bt/host/bluedroid/stack/gap/gap_ble.c | 18 +++--- .../bluedroid/stack/include/stack/bt_types.h | 2 + .../bluedroid/stack/include/stack/btm_api.h | 5 +- .../bluedroid_host_only_uart/main/main.c | 2 +- .../classic_bt/a2dp_sink/main/main.c | 4 +- .../classic_bt/a2dp_source/main/main.c | 32 ++++++---- .../classic_bt/bt_discovery/README.md | 6 +- .../classic_bt/bt_discovery/main/main.c | 4 +- .../bt_hid_mouse_device/main/main.c | 2 +- .../classic_bt/bt_l2cap_client/main/main.c | 2 +- .../tutorial/example_workflow.md | 4 +- .../classic_bt/bt_l2cap_server/main/main.c | 2 +- .../classic_bt/bt_spp_acceptor/main/main.c | 2 +- .../classic_bt/bt_spp_initiator/main/main.c | 8 +-- .../bt_spp_vfs_acceptor/main/main.c | 2 +- .../bt_spp_vfs_initiator/main/main.c | 2 +- .../bluedroid/classic_bt/hfp_ag/main/main.c | 4 +- .../bluedroid/classic_bt/hfp_hf/main/main.c | 4 +- .../coex/a2dp_gatts_coex/main/main.c | 7 ++- .../esp_hid_device/main/esp_hid_device_main.c | 2 +- 38 files changed, 325 insertions(+), 103 deletions(-) diff --git a/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c b/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c index 0d6b9e5a3c..610d19a5b1 100644 --- a/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c +++ b/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c @@ -1132,7 +1132,7 @@ int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc) int bt_mesh_gatts_set_local_device_name(const char *name) { - BTM_SetLocalDeviceName((char *)name); + BTM_SetLocalDeviceName((char *)name, BT_DEVICE_TYPE_BLE); return 0; } @@ -1481,7 +1481,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) result = NULL; } - /* Register Notification fot Mesh Provisioning/Proxy Data Out Characteristic */ + /* Register Notification for Mesh Provisioning/Proxy Data Out Characteristic */ status = BTA_GATTC_RegisterForNotifications(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val, bt_mesh_gattc_info[i].data_out_handle); if (status != BTA_GATT_OK) { diff --git a/components/bt/host/bluedroid/api/esp_gap_ble_api.c b/components/bt/host/bluedroid/api/esp_gap_ble_api.c index b665db4ddf..24bc9dd1ef 100644 --- a/components/bt/host/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_ble_api.c @@ -397,9 +397,25 @@ esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr, esp_err_t esp_ble_gap_set_device_name(const char *name) { - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); + btc_msg_t msg = {0}; + btc_ble_gap_args_t arg; - return esp_bt_dev_set_device_name(name); + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + if (!name){ + return ESP_ERR_INVALID_ARG; + } + if (strlen(name) > BTC_MAX_LOC_BD_NAME_LEN) { + return ESP_ERR_INVALID_ARG; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_ACT_SET_DEV_NAME; + arg.set_dev_name.device_name = (char *)name; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy, btc_gap_ble_arg_deep_free) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } esp_err_t esp_ble_gap_get_device_name(void) diff --git a/components/bt/host/bluedroid/api/esp_gap_bt_api.c b/components/bt/host/bluedroid/api/esp_gap_bt_api.c index 3e58847d28..d68bf971c6 100644 --- a/components/bt/host/bluedroid/api/esp_gap_bt_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_bt_api.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -494,4 +494,40 @@ esp_err_t esp_bt_gap_set_acl_pkt_types(esp_bd_addr_t remote_bda, uint16_t pkt_ty return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } +esp_err_t esp_bt_gap_set_device_name(const char *name) +{ + btc_msg_t msg; + btc_gap_bt_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + if ((!name) || (strlen(name) > BTC_MAX_LOC_BD_NAME_LEN)) { + return ESP_ERR_INVALID_ARG; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BT; + msg.act = BTC_GAP_BT_ACT_SET_DEV_NAME; + arg.bt_set_dev_name.device_name = (char *)name; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), btc_gap_bt_arg_deep_copy, + btc_gap_bt_arg_deep_free) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_bt_gap_get_device_name(void) +{ + btc_msg_t msg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BT; + msg.act = BTC_GAP_BT_ACT_GET_DEV_NAME; + + return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + #endif /* #if BTC_GAP_BT_INCLUDED == TRUE */ diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h index 6396534fc8..d54123548a 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -105,7 +105,7 @@ typedef uint8_t esp_bt_eir_type_t; #define ESP_BT_ACL_PKT_TYPES_MASK_NO_2_DH5 0x1000 #define ESP_BT_ACL_PKT_TYPES_MASK_NO_3_DH5 0x2000 -// DM1 cann not be disabled. All options are mandatory to include DM1. +// DM1 can not be disabled. All options are mandatory to include DM1. #define ESP_BT_ACL_DM1_ONLY (ESP_BT_ACL_PKT_TYPES_MASK_DM1 | 0x330e) /* 0x330e */ #define ESP_BT_ACL_DH1_ONLY (ESP_BT_ACL_PKT_TYPES_MASK_DH1 | 0x330e) /* 0x331e */ #define ESP_BT_ACL_DM3_ONLY (ESP_BT_ACL_PKT_TYPES_MASK_DM3 | 0x330e) /* 0x370e */ @@ -142,7 +142,7 @@ typedef struct { uint8_t *p_url; /*!< URL point */ } esp_bt_eir_data_t; -/// Major service class field of Class of Device, mutiple bits can be set +/// Major service class field of Class of Device, multiple bits can be set typedef enum { ESP_BT_COD_SRVC_NONE = 0, /*!< None indicates an invalid value */ ESP_BT_COD_SRVC_LMTD_DISCOVER = 0x1, /*!< Limited Discoverable Mode */ @@ -266,6 +266,7 @@ typedef enum { ESP_BT_GAP_GET_PAGE_TO_EVT, /*!< Get page timeout event */ ESP_BT_GAP_ACL_PKT_TYPE_CHANGED_EVT, /*!< Set ACL packet types event */ ESP_BT_GAP_ENC_CHG_EVT, /*!< Encryption change event */ + ESP_BT_GAP_GET_DEV_NAME_CMPL_EVT, /*!< Get device name complete event */ ESP_BT_GAP_EVT_MAX, } esp_bt_gap_cb_event_t; @@ -475,6 +476,14 @@ typedef union { uint16_t handle; /*!< ACL connection handle */ esp_bd_addr_t bda; /*!< remote bluetooth device address */ } acl_disconn_cmpl_stat; /*!< ACL disconnection complete status parameter struct */ + + /** + * @brief ESP_GAP_BT_GET_DEV_NAME_CMPL_EVT + */ + struct get_dev_name_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the get device name success status */ + char *name; /*!< Name of bluetooth device */ + } get_dev_name_cmpl; /*!< Get device name complete status parameter struct */ } esp_bt_gap_cb_param_t; /** @@ -541,7 +550,7 @@ static inline uint32_t esp_bt_gap_get_cod_format_type(uint32_t cod) * * @return * - true if cod is valid - * - false otherise + * - false otherwise */ static inline bool esp_bt_gap_is_valid_cod(uint32_t cod) { @@ -909,6 +918,26 @@ esp_err_t esp_bt_gap_get_page_timeout(void); */ esp_err_t esp_bt_gap_set_acl_pkt_types(esp_bd_addr_t remote_bda, esp_bt_acl_pkt_type_t pkt_types); +/** + * @brief Set device name to the local device + * + * @param[in] name - device name. + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_bt_gap_set_device_name(const char *name); + +/** + * @brief Get device name of the local device + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_bt_gap_get_device_name(void); + #ifdef __cplusplus } #endif diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c index 2e8a3563d7..c67bc29083 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -683,9 +683,11 @@ static void bta_dm_disable_timer_cback (TIMER_LIST_ENT *p_tle) *******************************************************************************/ void bta_dm_set_dev_name (tBTA_DM_MSG *p_data) { - BTM_SetLocalDeviceName((char *)p_data->set_name.name); + BTM_SetLocalDeviceName((char *)p_data->set_name.name, p_data->set_name.name_type); #if CLASSIC_BT_INCLUDED - bta_dm_set_eir ((char *)p_data->set_name.name); + if (p_data->set_name.name_type & BT_DEVICE_TYPE_BREDR) { + bta_dm_set_eir ((char *)p_data->set_name.name); + } #endif /// CLASSIC_BT_INCLUDED } @@ -704,7 +706,7 @@ void bta_dm_get_dev_name (tBTA_DM_MSG *p_data) tBTM_STATUS status; char *name = NULL; - status = BTM_ReadLocalDeviceName(&name); + status = BTM_ReadLocalDeviceName(&name, p_data->get_name.name_type); if (p_data->get_name.p_cback) { (*p_data->get_name.p_cback)(status, name); } @@ -4151,7 +4153,7 @@ static void bta_dm_set_eir (char *local_name) if (p_bta_dm_eir_cfg->bta_dm_eir_included_name) { /* if local name is not provided, get it from controller */ if ( local_name == NULL ) { - if ( BTM_ReadLocalDeviceName( &local_name ) != BTM_SUCCESS ) { + if ( BTM_ReadLocalDeviceName( &local_name, BT_DEVICE_TYPE_BREDR) != BTM_SUCCESS ) { APPL_TRACE_ERROR("Fail to read local device name for EIR"); } } diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c index 06d748937d..11c6151587 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c @@ -166,7 +166,7 @@ void BTA_DisableTestMode(void) ** Returns void ** *******************************************************************************/ -void BTA_DmSetDeviceName(const char *p_name) +void BTA_DmSetDeviceName(const char *p_name, tBT_DEVICE_TYPE name_type) { tBTA_DM_API_SET_NAME *p_msg; @@ -176,6 +176,7 @@ void BTA_DmSetDeviceName(const char *p_name) /* truncate the name if needed */ BCM_STRNCPY_S((char *)p_msg->name, p_name, BD_NAME_LEN); p_msg->name[BD_NAME_LEN] = '\0'; + p_msg->name_type = name_type; bta_sys_sendmsg(p_msg); } @@ -191,13 +192,14 @@ void BTA_DmSetDeviceName(const char *p_name) ** Returns void ** *******************************************************************************/ -void BTA_DmGetDeviceName(tBTA_GET_DEV_NAME_CBACK *p_cback) +void BTA_DmGetDeviceName(tBTA_GET_DEV_NAME_CBACK *p_cback, tBT_DEVICE_TYPE name_type) { tBTA_DM_API_GET_NAME *p_msg; if ((p_msg = (tBTA_DM_API_GET_NAME *) osi_malloc(sizeof(tBTA_DM_API_GET_NAME))) != NULL) { p_msg->hdr.event = BTA_DM_API_GET_NAME_EVT; p_msg->p_cback = p_cback; + p_msg->name_type = name_type; bta_sys_sendmsg(p_msg); } } diff --git a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h index 4689460a5a..2a7eb12d2e 100644 --- a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h +++ b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h @@ -250,11 +250,13 @@ typedef struct { typedef struct { BT_HDR hdr; BD_NAME name; /* max 248 bytes name, plus must be Null terminated */ + tBT_DEVICE_TYPE name_type; /* name for BLE, name for BT or name for BTDM */ } tBTA_DM_API_SET_NAME; typedef struct { - BT_HDR hdr; + BT_HDR hdr; tBTA_GET_DEV_NAME_CBACK *p_cback; + tBT_DEVICE_TYPE name_type; } tBTA_DM_API_GET_NAME; #if (ESP_COEX_VSC_INCLUDED == TRUE) diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_api.h index 54922ade8a..6840dc9779 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -1720,7 +1720,7 @@ extern void BTA_DisableTestMode(void); ** Returns void ** *******************************************************************************/ -extern void BTA_DmSetDeviceName(const char *p_name); +extern void BTA_DmSetDeviceName(const char *p_name, tBT_DEVICE_TYPE name_type); /******************************************************************************* ** @@ -1732,7 +1732,7 @@ extern void BTA_DmSetDeviceName(const char *p_name); ** Returns void ** *******************************************************************************/ -extern void BTA_DmGetDeviceName(tBTA_GET_DEV_NAME_CBACK *p_cback); +extern void BTA_DmGetDeviceName(tBTA_GET_DEV_NAME_CBACK *p_cback, tBT_DEVICE_TYPE name_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..eac955f552 100644 --- a/components/bt/host/bluedroid/btc/core/btc_dev.c +++ b/components/bt/host/bluedroid/btc/core/btc_dev.c @@ -41,7 +41,7 @@ void btc_dev_call_handler(btc_msg_t *msg) switch (msg->act) { case BTC_DEV_ACT_SET_DEVICE_NAME: - BTA_DmSetDeviceName(arg->set_dev_name.device_name); + BTA_DmSetDeviceName(arg->set_dev_name.device_name, BT_DEVICE_TYPE_DUMO); break; #if (ESP_COEX_VSC_INCLUDED == TRUE) case BTC_DEV_ACT_CFG_COEX_STATUS: diff --git a/components/bt/host/bluedroid/btc/core/btc_dm.c b/components/bt/host/bluedroid/btc/core/btc_dm.c index a19b618db9..7e242a734a 100644 --- a/components/bt/host/bluedroid/btc/core/btc_dm.c +++ b/components/bt/host/bluedroid/btc/core/btc_dm.c @@ -789,7 +789,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) /* Set initial device name, it can be overwritten later */ if (p_data->enable.status == BTA_SUCCESS) { const char *initial_device_name = "ESP32"; - BTA_DmSetDeviceName(initial_device_name); + BTA_DmSetDeviceName(initial_device_name, BT_DEVICE_TYPE_DUMO); } btc_enable_bluetooth_evt(p_data->enable.status); break; diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c index 2a636454e6..e84197862d 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -1647,6 +1647,18 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) } break; } + case BTC_GAP_BLE_ACT_SET_DEV_NAME:{ + btc_ble_gap_args_t *src = (btc_ble_gap_args_t *)p_src; + btc_ble_gap_args_t *dst = (btc_ble_gap_args_t *)p_dest; + dst->set_dev_name.device_name = (char *)osi_malloc((BTC_MAX_LOC_BD_NAME_LEN + 1) * sizeof(char)); + if (dst->set_dev_name.device_name) { + BCM_STRNCPY_S(dst->set_dev_name.device_name, src->set_dev_name.device_name, BTC_MAX_LOC_BD_NAME_LEN); + dst->set_dev_name.device_name[BTC_MAX_LOC_BD_NAME_LEN] = '\0'; + } else { + BTC_TRACE_ERROR("%s %d no mem\n",__func__, msg->act); + } + break; + } default: BTC_TRACE_ERROR("Unhandled deep copy %d\n", msg->act); break; @@ -1775,6 +1787,14 @@ void btc_gap_ble_arg_deep_free(btc_msg_t *msg) } break; } + case BTC_GAP_BLE_ACT_SET_DEV_NAME:{ + char *p_name = ((btc_ble_gap_args_t *)msg->arg)->set_dev_name.device_name; + if (p_name) { + osi_free((uint8_t *)p_name); + } + break; + } + break; default: BTC_TRACE_DEBUG("Unhandled deep free %d\n", msg->act); break; @@ -1886,10 +1906,10 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) break; #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE) case BTC_GAP_BLE_ACT_SET_DEV_NAME: - BTA_DmSetDeviceName(arg->set_dev_name.device_name); + BTA_DmSetDeviceName(arg->set_dev_name.device_name, BT_DEVICE_TYPE_BLE); break; case BTC_GAP_BLE_ACT_GET_DEV_NAME: - BTA_DmGetDeviceName(btc_gap_ble_get_dev_name_callback); + BTA_DmGetDeviceName(btc_gap_ble_get_dev_name_callback, BT_DEVICE_TYPE_BLE); break; #if (BLE_42_FEATURE_SUPPORT == TRUE) case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW: diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c index 2f9dedfdde..1ed888834e 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -853,6 +853,33 @@ static void btc_gap_bt_set_qos(btc_gap_bt_args_t *arg) #endif /// (BTA_DM_QOS_INCLUDED == TRUE) } +static void btc_gap_bt_get_dev_name_callback(UINT8 status, char *name) +{ + esp_bt_gap_cb_param_t param; + bt_status_t ret; + btc_msg_t msg = {0}; + + memset(¶m, 0, sizeof(esp_bt_gap_cb_param_t)); + + msg.sig = BTC_SIG_API_CB; + msg.pid = BTC_PID_GAP_BT; + msg.act = BTC_GAP_BT_GET_DEV_NAME_CMPL_EVT; + + param.get_dev_name_cmpl.status = btc_btm_status_to_esp_status(status); + param.get_dev_name_cmpl.name = (char *)osi_malloc(BTC_MAX_LOC_BD_NAME_LEN + 1); + if (param.get_dev_name_cmpl.name) { + BCM_STRNCPY_S(param.get_dev_name_cmpl.name, name, BTC_MAX_LOC_BD_NAME_LEN); + param.get_dev_name_cmpl.name[BTC_MAX_LOC_BD_NAME_LEN] = '\0'; + } else { + param.get_dev_name_cmpl.status = ESP_BT_STATUS_NOMEM; + } + + ret = btc_transfer_context(&msg, ¶m, sizeof(esp_bt_gap_cb_param_t), NULL, NULL); + if (ret != BT_STATUS_SUCCESS) { + BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__); + } +} + void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) { switch (msg->act) { @@ -872,6 +899,7 @@ void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) case BTC_GAP_BT_ACT_SET_PAGE_TIMEOUT: case BTC_GAP_BT_ACT_GET_PAGE_TIMEOUT: case BTC_GAP_BT_ACT_SET_ACL_PKT_TYPES: + case BTC_GAP_BT_ACT_GET_DEV_NAME: break; case BTC_GAP_BT_ACT_PASSKEY_REPLY: case BTC_GAP_BT_ACT_CONFIRM_REPLY: @@ -913,6 +941,18 @@ void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) } break; } + case BTC_GAP_BT_ACT_SET_DEV_NAME: { + btc_gap_bt_args_t *src = (btc_gap_bt_args_t *)p_src; + btc_gap_bt_args_t *dst = (btc_gap_bt_args_t *)p_dest; + dst->bt_set_dev_name.device_name = (char *)osi_malloc((BTC_MAX_LOC_BD_NAME_LEN + 1) * sizeof(char)); + if (dst->bt_set_dev_name.device_name) { + BCM_STRNCPY_S(dst->bt_set_dev_name.device_name, src->bt_set_dev_name.device_name, BTC_MAX_LOC_BD_NAME_LEN); + dst->bt_set_dev_name.device_name[BTC_MAX_LOC_BD_NAME_LEN] = '\0'; + } else { + BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act); + } + break; + } default: BTC_TRACE_ERROR("Unhandled deep copy %d\n", msg->act); break; @@ -939,6 +979,7 @@ void btc_gap_bt_arg_deep_free(btc_msg_t *msg) case BTC_GAP_BT_ACT_SET_PAGE_TIMEOUT: case BTC_GAP_BT_ACT_GET_PAGE_TIMEOUT: case BTC_GAP_BT_ACT_SET_ACL_PKT_TYPES: + case BTC_GAP_BT_ACT_GET_DEV_NAME: break; case BTC_GAP_BT_ACT_PASSKEY_REPLY: case BTC_GAP_BT_ACT_CONFIRM_REPLY: @@ -957,6 +998,13 @@ void btc_gap_bt_arg_deep_free(btc_msg_t *msg) osi_free(arg->config_eir.eir_data.p_url); } break; + case BTC_GAP_BT_ACT_SET_DEV_NAME: { + char *p_name = arg->bt_set_dev_name.device_name; + if (p_name) { + osi_free((uint8_t *)p_name); + } + break; + } default: BTC_TRACE_ERROR("Unhandled deep copy %d, arg: %p\n", msg->act, arg); break; @@ -1049,6 +1097,14 @@ void btc_gap_bt_call_handler(btc_msg_t *msg) btc_gap_set_acl_pkt_types(arg); break; } + case BTC_GAP_BT_ACT_SET_DEV_NAME: { + BTA_DmSetDeviceName(arg->bt_set_dev_name.device_name, BT_DEVICE_TYPE_BREDR); + break; + } + case BTC_GAP_BT_ACT_GET_DEV_NAME: { + BTA_DmGetDeviceName(btc_gap_bt_get_dev_name_callback, BT_DEVICE_TYPE_BREDR); + break; + } default: break; } @@ -1101,6 +1157,7 @@ void btc_gap_bt_cb_deep_free(btc_msg_t *msg) #if (BTC_DM_PM_INCLUDED == TRUE) case BTC_GAP_BT_MODE_CHG_EVT: #endif /// BTC_DM_PM_INCLUDED == TRUE + case BTC_GAP_BT_GET_DEV_NAME_CMPL_EVT: break; default: BTC_TRACE_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act); @@ -1192,6 +1249,10 @@ void btc_gap_bt_cb_handler(btc_msg_t *msg) btc_gap_bt_cb_to_app(ESP_BT_GAP_ACL_PKT_TYPE_CHANGED_EVT, (esp_bt_gap_cb_param_t *)msg->arg); break; } + case BTC_GAP_BT_GET_DEV_NAME_CMPL_EVT: { + btc_gap_bt_cb_to_app(ESP_BT_GAP_GET_DEV_NAME_CMPL_EVT, (esp_bt_gap_cb_param_t *)msg->arg); + break; + } default: BTC_TRACE_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act); break; diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h index 71d89359d9..a6c6a2b10b 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -173,7 +173,7 @@ typedef union { //BTC_GAP_BLE_ACT_SET_DEV_NAME, struct set_dev_name_args { #define ESP_GAP_DEVICE_NAME_MAX (32) - char device_name[ESP_GAP_DEVICE_NAME_MAX + 1]; + char *device_name; } set_dev_name; #if (BLE_42_FEATURE_SUPPORT == TRUE) //BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW, diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h index 2b631da9dd..c0f6e21c87 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_bt.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -35,6 +35,7 @@ typedef enum { BTC_GAP_BT_SET_PAGE_TO_EVT, BTC_GAP_BT_GET_PAGE_TO_EVT, BTC_GAP_BT_SET_ACL_PKT_TYPES_EVT, + BTC_GAP_BT_GET_DEV_NAME_CMPL_EVT, }btc_gap_bt_evt_t; typedef enum { @@ -58,6 +59,8 @@ typedef enum { BTC_GAP_BT_ACT_SET_PAGE_TIMEOUT, BTC_GAP_BT_ACT_GET_PAGE_TIMEOUT, BTC_GAP_BT_ACT_SET_ACL_PKT_TYPES, + BTC_GAP_BT_ACT_SET_DEV_NAME, + BTC_GAP_BT_ACT_GET_DEV_NAME, } btc_gap_bt_act_t; /* btc_bt_gap_args_t */ @@ -165,6 +168,10 @@ typedef union { uint16_t pkt_types; } set_acl_pkt_types; + // BTC_GAP_BT_ACT_SET_DEV_NAME + struct bt_set_dev_name_args { + char *device_name; + } bt_set_dev_name; } btc_gap_bt_args_t; void btc_gap_bt_call_handler(btc_msg_t *msg); diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c index 7dad8217a2..82a999ff8c 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c @@ -2236,16 +2236,16 @@ UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst, /* device name */ #if BTM_MAX_LOC_BD_NAME_LEN > 0 if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_DEV_NAME) { - if (strlen(btm_cb.cfg.bd_name) > (UINT16)(len - MIN_ADV_LENGTH)) { + if (strlen(btm_cb.cfg.ble_bd_name) > (UINT16)(len - MIN_ADV_LENGTH)) { cp_len = (UINT16)(len - MIN_ADV_LENGTH); *p++ = cp_len + 1; *p++ = BTM_BLE_AD_TYPE_NAME_SHORT; - ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, cp_len); + ARRAY_TO_STREAM(p, btm_cb.cfg.ble_bd_name, cp_len); } else { - cp_len = (UINT16)strlen(btm_cb.cfg.bd_name); + cp_len = (UINT16)strlen(btm_cb.cfg.ble_bd_name); *p++ = cp_len + 1; *p++ = BTM_BLE_AD_TYPE_NAME_CMPL; - ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, cp_len); + ARRAY_TO_STREAM(p, btm_cb.cfg.ble_bd_name, cp_len); } len -= (cp_len + MIN_ADV_LENGTH); data_mask &= ~BTM_BLE_AD_BIT_DEV_NAME; diff --git a/components/bt/host/bluedroid/stack/btm/btm_devctl.c b/components/bt/host/bluedroid/stack/btm/btm_devctl.c index 21534d5a76..ab297c38e0 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_devctl.c +++ b/components/bt/host/bluedroid/stack/btm/btm_devctl.c @@ -81,7 +81,8 @@ void btm_dev_init (void) /* Initialize nonzero defaults */ #if (BTM_MAX_LOC_BD_NAME_LEN > 0) - memset(btm_cb.cfg.bd_name, 0, sizeof(tBTM_LOC_BD_NAME)); + memset(btm_cb.cfg.ble_bd_name, 0, sizeof(tBTM_LOC_BD_NAME)); + memset(btm_cb.cfg.bredr_bd_name, 0, sizeof(tBTM_LOC_BD_NAME)); #endif btm_cb.devcb.reset_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RESET; @@ -449,11 +450,11 @@ static void btm_decode_ext_features_page (UINT8 page_number, const BD_FEATURES p ** Returns status of the operation ** *******************************************************************************/ -tBTM_STATUS BTM_SetLocalDeviceName (char *p_name) +tBTM_STATUS BTM_SetLocalDeviceName (char *p_name, tBT_DEVICE_TYPE name_type) { UINT8 *p; - if (!p_name || !p_name[0] || (strlen ((char *)p_name) > BD_NAME_LEN)) { + if (!p_name || !p_name[0] || (strlen ((char *)p_name) > BD_NAME_LEN) || (name_type > BT_DEVICE_TYPE_DUMO)) { return (BTM_ILLEGAL_VALUE); } @@ -463,16 +464,26 @@ tBTM_STATUS BTM_SetLocalDeviceName (char *p_name) #if BTM_MAX_LOC_BD_NAME_LEN > 0 /* Save the device name if local storage is enabled */ - p = (UINT8 *)btm_cb.cfg.bd_name; - if (p != (UINT8 *)p_name) { - BCM_STRNCPY_S(btm_cb.cfg.bd_name, p_name, BTM_MAX_LOC_BD_NAME_LEN); - btm_cb.cfg.bd_name[BTM_MAX_LOC_BD_NAME_LEN] = '\0'; + if (name_type & BT_DEVICE_TYPE_BLE) { + p = (UINT8 *)btm_cb.cfg.ble_bd_name; + if (p != (UINT8 *)p_name) { + BCM_STRNCPY_S(btm_cb.cfg.ble_bd_name, p_name, BTM_MAX_LOC_BD_NAME_LEN); + btm_cb.cfg.ble_bd_name[BTM_MAX_LOC_BD_NAME_LEN] = '\0'; + } + } + + if (name_type & BT_DEVICE_TYPE_BREDR) { + p = (UINT8 *)btm_cb.cfg.bredr_bd_name; + if (p != (UINT8 *)p_name) { + BCM_STRNCPY_S(btm_cb.cfg.bredr_bd_name, p_name, BTM_MAX_LOC_BD_NAME_LEN); + btm_cb.cfg.bredr_bd_name[BTM_MAX_LOC_BD_NAME_LEN] = '\0'; + } } #else p = (UINT8 *)p_name; #endif #if CLASSIC_BT_INCLUDED - if (btsnd_hcic_change_name(p)) { + if ((name_type & BT_DEVICE_TYPE_BREDR) && btsnd_hcic_change_name(p)) { return (BTM_CMD_STARTED); } else #endif @@ -496,10 +507,33 @@ tBTM_STATUS BTM_SetLocalDeviceName (char *p_name) ** is returned and p_name is set to NULL ** *******************************************************************************/ -tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name) +tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name, tBT_DEVICE_TYPE name_type) { + /* + // name_type should be BT_DEVICE_TYPE_BLE or BT_DEVICE_TYPE_BREDR + if (name_type > BT_DEVICE_TYPE_BREDR) { + *p_name = NULL; + BTM_TRACE_ERROR("name_type unknown %d", name_type); + return (BTM_NO_RESOURCES); + } + */ + #if BTM_MAX_LOC_BD_NAME_LEN > 0 - *p_name = btm_cb.cfg.bd_name; + if ((name_type == BT_DEVICE_TYPE_DUMO) && + (BCM_STRNCMP_S(btm_cb.cfg.bredr_bd_name, btm_cb.cfg.ble_bd_name, BTM_MAX_LOC_BD_NAME_LEN) != 0)) { + *p_name = NULL; + BTM_TRACE_ERROR("Error, BLE and BREDR have different names, return NULL\n"); + return (BTM_NO_RESOURCES); + } + + if (name_type & BT_DEVICE_TYPE_BLE) { + *p_name = btm_cb.cfg.ble_bd_name; + } + + if (name_type & BT_DEVICE_TYPE_BREDR) { + *p_name = btm_cb.cfg.bredr_bd_name; + } + return (BTM_SUCCESS); #else *p_name = NULL; @@ -747,7 +781,7 @@ void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len, /* If there was a callback address for vcs complete, call it */ if (p_vsc_cplt_cback) { - /* Pass paramters to the callback function */ + /* Pass parameters to the callback function */ vcs_cplt_params.opcode = opcode; /* Number of bytes in return info */ vcs_cplt_params.param_len = evt_len; /* Number of bytes in return info */ vcs_cplt_params.p_param_buf = p; diff --git a/components/bt/host/bluedroid/stack/btm/btm_sec.c b/components/bt/host/bluedroid/stack/btm/btm_sec.c index 7d06a45ea7..ca5f99e17c 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_sec.c +++ b/components/bt/host/bluedroid/stack/btm/btm_sec.c @@ -809,7 +809,7 @@ void btm_sec_clr_temp_auth_service (BD_ADDR bda) return; } - /* Reset the temporary authorized flag so that next time (untrusted) service is accessed autorization will take place */ + /* Reset the temporary authorized flag so that next time (untrusted) service is accessed authorization will take place */ if (p_dev_rec->last_author_service_id != BTM_SEC_NO_LAST_SERVICE_ID && p_dev_rec->p_cur_service) { BTM_TRACE_DEBUG ("btm_sec_clr_auth_service_by_psm [clearing device: %02x:%02x:%02x:%02x:%02x:%02x]\n", bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); @@ -1364,7 +1364,7 @@ tBTM_STATUS BTM_SetEncryption (BD_ADDR bd_addr, tBT_TRANSPORT transport, tBTM_SE || (transport == BT_TRANSPORT_LE && p_dev_rec->ble_hci_handle == BTM_SEC_INVALID_HANDLE) #endif ) { - /* Connection should be up and runnning */ + /* Connection should be up and running */ BTM_TRACE_WARNING ("Security Manager: BTM_SetEncryption not connected\n"); if (p_callback) { @@ -1790,15 +1790,15 @@ UINT16 BTM_BuildOobData(UINT8 *p_data, UINT16 max_len, BT_OCTET16 c, } #if BTM_MAX_LOC_BD_NAME_LEN > 0 name_size = name_len; - if (name_size > strlen(btm_cb.cfg.bd_name)) { + if (name_size > strlen(btm_cb.cfg.bredr_bd_name)) { name_type = BTM_EIR_COMPLETE_LOCAL_NAME_TYPE; - name_size = (UINT16)strlen(btm_cb.cfg.bd_name); + name_size = (UINT16)strlen(btm_cb.cfg.bredr_bd_name); } delta = name_size + 2; if (max_len >= delta) { *p++ = name_size + 1; *p++ = name_type; - ARRAY_TO_STREAM (p, btm_cb.cfg.bd_name, name_size); + ARRAY_TO_STREAM (p, btm_cb.cfg.bredr_bd_name, name_size); len += delta; max_len -= delta; } @@ -2118,7 +2118,7 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle /* If there is no application registered with this PSM do not allow connection */ if (!p_serv_rec) { - BTM_TRACE_WARNING ("%s() PSM: %d no application registerd\n", __func__, psm); + BTM_TRACE_WARNING ("%s() PSM: %d no application registered\n", __func__, psm); (*p_callback) (bd_addr, transport, p_ref_data, BTM_MODE_UNSUPPORTED); return (BTM_MODE_UNSUPPORTED); } @@ -2514,7 +2514,7 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_o if (rc == BTM_SUCCESS) { BTM_TRACE_EVENT("%s: allow to bypass, checking authorization\n", __FUNCTION__); - /* the security in BTM_SEC_IN_FLAGS is fullfilled so far, check the requirements in */ + /* the security in BTM_SEC_IN_FLAGS is fulfilled so far, check the requirements in */ /* btm_sec_execute_procedure */ if ((is_originator && (p_serv_rec->security_flags & BTM_SEC_OUT_AUTHORIZE)) || (!is_originator && (p_serv_rec->security_flags & BTM_SEC_IN_AUTHORIZE))) { @@ -3979,7 +3979,7 @@ void btm_sec_auth_complete (UINT16 handle, UINT8 status) /* or BR key is higher security than existing LE keys */ (!(p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_AUTHED) && (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED)))) { - BTM_TRACE_DEBUG ("link encrypted afer dedic bonding can use SMP_BR_CHNL\n"); + BTM_TRACE_DEBUG ("link encrypted after dedic bonding can use SMP_BR_CHNL\n"); if (btm_sec_is_master(p_dev_rec)) { // Encryption is required to start SM over BR/EDR @@ -4255,7 +4255,7 @@ static void btm_sec_connect_after_reject_timeout (TIMER_LIST_ENT *p_tle) ** Function btm_sec_connected ** ** Description This function is when a connection to the peer device is -** establsihed +** established ** ** Returns void ** @@ -5926,7 +5926,7 @@ static BOOLEAN btm_sec_check_prefetch_pin (tBTM_SEC_DEV_REC *p_dev_rec) ** ** Function btm_sec_auth_payload_tout ** -** Description Processes the HCI Autheniticated Payload Timeout Event +** Description Processes the HCI Authenticated Payload Timeout Event ** indicating that a packet containing a valid MIC on the ** connection handle was not received within the programmed ** timeout value. (Spec Default is 30 secs, but can be @@ -6294,7 +6294,7 @@ static BOOLEAN btm_sec_is_master(tBTM_SEC_DEV_REC *p_dev_rec) ** Description This function is called when legacy authentication is used ** and only remote device has completed the authentication ** -** Returns TRUE if aunthentication command sent successfully +** Returns TRUE if authentication command sent successfully ** *******************************************************************************/ BOOLEAN btm_sec_legacy_authentication_mutual (tBTM_SEC_DEV_REC *p_dev_rec) diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_int.h index c22423a10f..e254b6b85c 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_int.h @@ -715,7 +715,8 @@ struct tBTM_SEC_DEV_REC{ */ typedef struct { #if BTM_MAX_LOC_BD_NAME_LEN > 0 - tBTM_LOC_BD_NAME bd_name; /* local Bluetooth device name */ + tBTM_LOC_BD_NAME bredr_bd_name; /* local BREDR device name */ + tBTM_LOC_BD_NAME ble_bd_name; /* local BLE device name */ #endif BOOLEAN pin_type; /* TRUE if PIN type is fixed */ UINT8 pin_code_len; /* Bonding information */ diff --git a/components/bt/host/bluedroid/stack/gap/gap_ble.c b/components/bt/host/bluedroid/stack/gap/gap_ble.c index 5bac86f0c2..e32151298e 100644 --- a/components/bt/host/bluedroid/stack/gap/gap_ble.c +++ b/components/bt/host/bluedroid/stack/gap/gap_ble.c @@ -65,7 +65,7 @@ static const tGATT_CBACK gap_cback = { ** ** Function gap_find_clcb_by_bd_addr ** -** Description The function searches all LCB with macthing bd address +** Description The function searches all LCB with matching bd address ** ** Returns total number of clcb found. ** @@ -88,7 +88,7 @@ tGAP_CLCB *gap_find_clcb_by_bd_addr(BD_ADDR bda) ** ** Function gap_ble_find_clcb_by_conn_id ** -** Description The function searches all LCB with macthing connection ID +** Description The function searches all LCB with matching connection ID ** ** Returns total number of clcb found. ** @@ -163,7 +163,7 @@ void gap_ble_dealloc_clcb(tGAP_CLCB *p_clcb) ** ** Description The function enqueue a GAP client request ** -** Returns TRUE is successul; FALSE otherwise +** Returns TRUE is successful; FALSE otherwise ** *******************************************************************************/ BOOLEAN gap_ble_enqueue_request (tGAP_CLCB *p_clcb, UINT16 uuid, tGAP_BLE_CMPL_CBACK *p_cback) @@ -185,7 +185,7 @@ BOOLEAN gap_ble_enqueue_request (tGAP_CLCB *p_clcb, UINT16 uuid, tGAP_BLE_CMPL_C ** ** Description The function dequeue a GAP client request if any ** -** Returns TRUE is successul; FALSE otherwise +** Returns TRUE is successful; FALSE otherwise ** *******************************************************************************/ BOOLEAN gap_ble_dequeue_request (tGAP_CLCB *p_clcb, UINT16 *p_uuid, tGAP_BLE_CMPL_CBACK **p_cback) @@ -221,7 +221,7 @@ tGATT_STATUS gap_read_attr_value (UINT16 handle, tGATT_VALUE *p_value, BOOLEAN i switch (p_db_attr->uuid) { case GATT_UUID_GAP_DEVICE_NAME: - BTM_ReadLocalDeviceName((char **)&p_dev_name); + BTM_ReadLocalDeviceName((char **)&p_dev_name, BT_DEVICE_TYPE_BLE); if (strlen ((char *)p_dev_name) > GATT_MAX_ATTR_LEN) { p_value->len = GATT_MAX_ATTR_LEN; } else { @@ -304,7 +304,7 @@ UINT8 gap_proc_write_req( tGATTS_REQ_TYPE type, tGATT_WRITE_REQ *p_data) case GATT_UUID_GAP_DEVICE_NAME: { UINT8 *p_val = p_data->value; p_val[p_data->len] = '\0'; - BTM_SetLocalDeviceName((char *)p_val); + BTM_SetLocalDeviceName((char *)p_val, BT_DEVICE_TYPE_BLE); return GATT_SUCCESS; } #endif @@ -385,7 +385,7 @@ void gap_ble_s_attr_request_cback (UINT16 conn_id, UINT32 trans_id, ** ** Function btm_ble_att_db_init ** -** Description GAP ATT database initalization. +** Description GAP ATT database initialization. ** ** Returns void. ** @@ -510,7 +510,7 @@ void GAP_BleAttrDBUpdate(UINT16 attr_uuid, tGAP_BLE_ATTR_VALUE *p_value) break; case GATT_UUID_GAP_DEVICE_NAME: - BTM_SetLocalDeviceName((char *)p_value->p_dev_name); + BTM_SetLocalDeviceName((char *)p_value->p_dev_name, BT_DEVICE_TYPE_BLE); break; case GATT_UUID_GAP_CENTRAL_ADDR_RESOL: @@ -529,7 +529,7 @@ void GAP_BleAttrDBUpdate(UINT16 attr_uuid, tGAP_BLE_ATTR_VALUE *p_value) ** ** Function gap_ble_send_cl_read_request ** -** Description utility function to send a read request for a GAP charactersitic +** Description utility function to send a read request for a GAP characteristic ** ** Returns TRUE if read started, else FALSE if GAP is busy ** diff --git a/components/bt/host/bluedroid/stack/include/stack/bt_types.h b/components/bt/host/bluedroid/stack/include/stack/bt_types.h index be803d50d2..23721d4f32 100644 --- a/components/bt/host/bluedroid/stack/include/stack/bt_types.h +++ b/components/bt/host/bluedroid/stack/include/stack/bt_types.h @@ -33,6 +33,8 @@ typedef int32_t INT32; #define BCM_STRCPY_S(x1,x2) strcpy((x1),(x2)) #define BCM_STRNCPY_S(x1,x2,x3) strncpy((x1),(x2),(x3)) +#define BCM_STRCMP_S(x1,x2) strcmp((x1),(x2)) +#define BCM_STRNCMP_S(x1,x2,x3) strncmp((x1),(x2),(x3)) /* READ WELL !! ** diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_api.h index 24024505da..5cacf3aa9f 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_api.h @@ -470,7 +470,6 @@ typedef enum { #define BTM_COD_SERVICE_CLASS_LO_B 0x00E0 #define BTM_COD_SERVICE_CLASS_MASK 0xFFE0 - /* BTM service definitions ** Used for storing EIR data to bit mask */ @@ -2067,7 +2066,7 @@ BOOLEAN BTM_IsDeviceUp (void); ** *******************************************************************************/ //extern -tBTM_STATUS BTM_SetLocalDeviceName (char *p_name); +tBTM_STATUS BTM_SetLocalDeviceName (char *p_name, tBT_DEVICE_TYPE name_type); /******************************************************************************* ** @@ -2096,7 +2095,7 @@ tBTM_STATUS BTM_SetDeviceClass (DEV_CLASS dev_class); ** *******************************************************************************/ //extern -tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name); +tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name, tBT_DEVICE_TYPE name_type); /******************************************************************************* ** diff --git a/examples/bluetooth/bluedroid/bluedroid_host_only/bluedroid_host_only_uart/main/main.c b/examples/bluetooth/bluedroid/bluedroid_host_only/bluedroid_host_only_uart/main/main.c index 465e0f780a..bc70e96834 100644 --- a/examples/bluetooth/bluedroid/bluedroid_host_only/bluedroid_host_only_uart/main/main.c +++ b/examples/bluetooth/bluedroid/bluedroid_host_only/bluedroid_host_only_uart/main/main.c @@ -257,7 +257,7 @@ static void bt_app_gap_start_up(void) esp_bt_gap_register_callback(bt_app_gap_cb); char *dev_name = "ESP_GAP_INQRUIY"; - esp_bt_dev_set_device_name(dev_name); + esp_bt_gap_set_device_name(dev_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/classic_bt/a2dp_sink/main/main.c b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c index 780c36f386..2595ac32b2 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c @@ -117,7 +117,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param) switch (event) { /* 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_gap_set_device_name(LOCAL_DEVICE_NAME); esp_bt_gap_register_callback(bt_app_gap_cb); assert(esp_avrc_ct_init() == ESP_OK); @@ -135,6 +135,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_gap_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/classic_bt/a2dp_source/main/main.c b/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c index 1ea7348415..16fceef285 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -226,7 +226,7 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa s_a2d_state = APP_AV_STATE_CONNECTING; ESP_LOGI(BT_AV_TAG, "Device discovery stopped."); ESP_LOGI(BT_AV_TAG, "a2dp connecting to peer: %s", s_peer_bdname); - /* connect source to peer device specificed by Bluetooth Device Address */ + /* connect source to peer device specified by Bluetooth Device Address */ esp_a2d_source_connect(s_peer_bda); } else { /* not discovered, continue to discover */ @@ -287,6 +287,13 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa case ESP_BT_GAP_MODE_CHG_EVT: ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode: %d", param->mode_chg.mode); break; + case ESP_BT_GAP_GET_DEV_NAME_CMPL_EVT: + if (param->get_dev_name_cmpl.status == ESP_BT_STATUS_SUCCESS) { + ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_GET_DEV_NAME_CMPL_EVT device name: %s", param->get_dev_name_cmpl.name); + } else { + ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_GET_DEV_NAME_CMPL_EVT failed, state: %d", param->get_dev_name_cmpl.status); + } + break; /* other */ default: { ESP_LOGI(BT_AV_TAG, "event: %d", event); @@ -305,7 +312,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param) /* when stack up worked, this event comes */ case BT_APP_STACK_UP_EVT: { char *dev_name = LOCAL_DEVICE_NAME; - esp_bt_dev_set_device_name(dev_name); + esp_bt_gap_set_device_name(dev_name); esp_bt_gap_register_callback(bt_app_gap_cb); esp_avrc_ct_init(); @@ -321,6 +328,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param) /* Avoid the state error of s_a2d_state caused by the connection initiated by the peer device. */ esp_bt_gap_set_scan_mode(ESP_BT_NON_CONNECTABLE, ESP_BT_NON_DISCOVERABLE); + esp_bt_gap_get_device_name(); ESP_LOGI(BT_AV_TAG, "Starting device discovery..."); s_a2d_state = APP_AV_STATE_DISCOVERING; @@ -398,7 +406,7 @@ static void bt_app_av_sm_hdlr(uint16_t event, void *param) static void bt_app_av_state_unconnected_hdlr(uint16_t event, void *param) { esp_a2d_cb_param_t *a2d = NULL; - /* handle the events of intrest in unconnected state */ + /* handle the events of interest in unconnected state */ switch (event) { case ESP_A2D_CONNECTION_STATE_EVT: case ESP_A2D_AUDIO_STATE_EVT: @@ -430,7 +438,7 @@ static void bt_app_av_state_connecting_hdlr(uint16_t event, void *param) { esp_a2d_cb_param_t *a2d = NULL; - /* handle the events of intrest in connecting state */ + /* handle the events of interest in connecting state */ switch (event) { case ESP_A2D_CONNECTION_STATE_EVT: { a2d = (esp_a2d_cb_param_t *)(param); @@ -497,7 +505,7 @@ static void bt_app_av_media_proc(uint16_t event, void *param) s_intv_cnt = 0; s_media_state = APP_AV_MEDIA_STATE_STARTED; } else { - /* not started succesfully, transfer to idle state */ + /* not started successfully, transfer to idle state */ ESP_LOGI(BT_AV_TAG, "a2dp media start failed."); s_media_state = APP_AV_MEDIA_STATE_IDLE; } @@ -542,7 +550,7 @@ static void bt_app_av_state_connected_hdlr(uint16_t event, void *param) { esp_a2d_cb_param_t *a2d = NULL; - /* handle the events of intrest in connected state */ + /* handle the events of interest in connected state */ switch (event) { case ESP_A2D_CONNECTION_STATE_EVT: { a2d = (esp_a2d_cb_param_t *)(param); @@ -560,7 +568,7 @@ static void bt_app_av_state_connected_hdlr(uint16_t event, void *param) break; } case ESP_A2D_AUDIO_CFG_EVT: - // not suppposed to occur for A2DP source + // not supposed to occur for A2DP source break; case ESP_A2D_MEDIA_CTRL_ACK_EVT: case BT_APP_HEART_BEAT_EVT: { @@ -583,7 +591,7 @@ static void bt_app_av_state_disconnecting_hdlr(uint16_t event, void *param) { esp_a2d_cb_param_t *a2d = NULL; - /* handle the events of intrest in disconnecing state */ + /* handle the events of interest in disconnecing state */ switch (event) { case ESP_A2D_CONNECTION_STATE_EVT: { a2d = (esp_a2d_cb_param_t *)(param); @@ -676,13 +684,13 @@ static void bt_av_hdl_avrc_ct_evt(uint16_t event, void *p_param) } break; } - /* when passthrough responsed, this event comes */ + /* when passthrough responded, this event comes */ case ESP_AVRC_CT_PASSTHROUGH_RSP_EVT: { ESP_LOGI(BT_RC_CT_TAG, "AVRC passthrough response: key_code 0x%x, key_state %d, rsp_code %d", rc->psth_rsp.key_code, rc->psth_rsp.key_state, rc->psth_rsp.rsp_code); break; } - /* when metadata responsed, this event comes */ + /* when metadata responded, this event comes */ case ESP_AVRC_CT_METADATA_RSP_EVT: { ESP_LOGI(BT_RC_CT_TAG, "AVRC metadata response: attribute id 0x%x, %s", rc->meta_rsp.attr_id, rc->meta_rsp.attr_text); free(rc->meta_rsp.attr_text); @@ -708,7 +716,7 @@ static void bt_av_hdl_avrc_ct_evt(uint16_t event, void *p_param) bt_av_volume_changed(); break; } - /* when set absolute volume responsed, this event comes */ + /* when set absolute volume responded, this event comes */ case ESP_AVRC_CT_SET_ABSOLUTE_VOLUME_RSP_EVT: { ESP_LOGI(BT_RC_CT_TAG, "Set absolute volume response: volume %d", rc->set_volume_rsp.volume); break; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_discovery/README.md b/examples/bluetooth/bluedroid/classic_bt/bt_discovery/README.md index d9f0cd621c..af561b931e 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_discovery/README.md +++ b/examples/bluetooth/bluedroid/classic_bt/bt_discovery/README.md @@ -50,7 +50,7 @@ See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/l #include "esp_gap_bt_api.h" ``` -These `includes` are required for the FreeRTOS and underlaying system components to run, including the logging functionality and a library to store data in non-volatile flash memory. We are interested in `bt.h`, `esp_bt_main.h`, `esp_bt_device.h` and `esp_gap_bt_api.h`, which expose the Classic Bluetooth APIs required to implement this example. +These `includes` are required for the FreeRTOS and underlying system components to run, including the logging functionality and a library to store data in non-volatile flash memory. We are interested in `bt.h`, `esp_bt_main.h`, `esp_bt_device.h` and `esp_gap_bt_api.h`, which expose the Classic Bluetooth APIs required to implement this example. * `bt.h`: configures the Bluetooth controller and VHCI from the host side. * `esp_bt_main.h`: initializes and enables the Bluedroid stack. @@ -152,7 +152,7 @@ The application function then sets the device name and sets it as discoverable a ```c char *dev_name = "ESP_GAP_INQRUIY"; -esp_bt_dev_set_device_name(dev_name); +esp_bt_gap_set_device_name(dev_name); /* set discoverable and connectable mode, wait to be connected */ esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); @@ -161,7 +161,7 @@ esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); The application function then initialises the information and status of application layer and starts to discover nearby Bluetooth devices. ```c -/* inititialize device information and status */ +/* initialize device information and status */ bt_app_gap_init(); /* start to discover nearby Bluetooth devices */ diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_discovery/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_discovery/main/main.c index cf451a18ed..5b4123c45e 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_discovery/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_discovery/main/main.c @@ -256,12 +256,12 @@ static void bt_app_gap_start_up(void) esp_bt_gap_register_callback(bt_app_gap_cb); char *dev_name = "ESP_GAP_INQRUIY"; - esp_bt_dev_set_device_name(dev_name); + esp_bt_gap_set_device_name(dev_name); /* set discoverable and connectable mode, wait to be connected */ esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); - /* inititialize device information and status */ + /* initialize device information and status */ bt_app_gap_init(); /* start to discover nearby Bluetooth devices */ diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c index f6e5906470..349a812801 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c @@ -431,7 +431,7 @@ void app_main(void) } ESP_LOGI(TAG, "setting device name"); - esp_bt_dev_set_device_name("HID Mouse Example"); + esp_bt_gap_set_device_name("HID Mouse Example"); ESP_LOGI(TAG, "setting cod major, peripheral"); esp_bt_cod_t cod; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/main.c index 610a3b3bba..4048fd129d 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/main.c @@ -366,7 +366,7 @@ static void esp_hdl_sdp_cb_evt(uint16_t event, void *p_param) case ESP_SDP_CREATE_RECORD_COMP_EVT: ESP_LOGI(SDP_TAG, "ESP_SDP_CREATE_RECORD_COMP_EVT: status:%d", sdp_param->create_record.status); if (sdp_param->create_record.status == ESP_SDP_SUCCESS) { - esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME); + esp_bt_gap_set_device_name(EXAMPLE_DEVICE_NAME); esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, 10, 0); } diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/tutorial/example_workflow.md b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/tutorial/example_workflow.md index 93e91742cf..56684e3db5 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/tutorial/example_workflow.md +++ b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/tutorial/example_workflow.md @@ -34,9 +34,9 @@ Step `7` in sequence diagram is the setting of SDP and process of service discov - The SDP callback is registered by calling `esp_sdp_register_callback()`. - The `Server` initiates SDP by calling `esp_sdp_init()`, and the asynchronous callback event `ESP_SDP_INIT_EVT` is returned to indicate the initialization completion. - Then the `Server` creates an SDP record by calling `esp_sdp_create_record()`, and an asynchronous callback event `ESP_SDP_CREATE_RECORD_COMP_EVT` is returned to indicate the completion of the record creation. - - The `Server` can also set the device name by calling `esp_bt_dev_set_device_name()` and make itself connectable and discoverable by calling `esp_bt_gap_set_scan_mode()`. + - The `Server` can also set the device name by calling `esp_bt_gap_set_device_name()` and make itself connectable and discoverable by calling `esp_bt_gap_set_scan_mode()`. - In the client path: - - The `Client` also calls functions `esp_sdp_register_callback()`, `esp_sdp_init()`, `esp_sdp_create_record()`, `esp_bt_dev_set_device_name()` and `esp_bt_gap_set_scan_mode()` to register SDP callback, initiate the SDP, create sdp record, set device name and set the scan mode. + - The `Client` also calls functions `esp_sdp_register_callback()`, `esp_sdp_init()`, `esp_sdp_create_record()`, `esp_bt_gap_set_device_name()` and `esp_bt_gap_set_scan_mode()` to register SDP callback, initiate the SDP, create sdp record, set device name and set the scan mode. - Additionally, the `Client` calls `esp_bt_gap_start_discovery()` to start `Inquiry`. When the `Inquiry` process is completed, the asynchronous callback event `ESP_BT_GAP_DISC_RES_EVT` will be returned. Once the event `ESP_BT_GAP_DISC_RES_EVT` is returned, the `Client` will try to make a L2CAP connection to the `BD Address` of `Server` by calling function `esp_bt_connect()` in step `8`. diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/main.c index 86d4dc020e..bcfeea5fae 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/main.c @@ -270,7 +270,7 @@ static void esp_hdl_sdp_cb_evt(uint16_t event, void *p_param) case ESP_SDP_CREATE_RECORD_COMP_EVT: ESP_LOGI(SDP_TAG, "ESP_SDP_CREATE_RECORD_COMP_EVT: status:%d", sdp_param->create_record.status); if (sdp_param->create_record.status == ESP_SDP_SUCCESS) { - esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME); + esp_bt_gap_set_device_name(EXAMPLE_DEVICE_NAME); esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); } break; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/main.c index 02dbd1c8ec..688db21cd5 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/main.c @@ -90,7 +90,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) if (param->start.status == ESP_SPP_SUCCESS) { ESP_LOGI(SPP_TAG, "ESP_SPP_START_EVT handle:%"PRIu32" sec_id:%d scn:%d", param->start.handle, param->start.sec_id, param->start.scn); - esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME); + esp_bt_gap_set_device_name(EXAMPLE_DEVICE_NAME); esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); } else { ESP_LOGE(SPP_TAG, "ESP_SPP_START_EVT status:%d", param->start.status); diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/main.c index c7e4c6f30b..df95ba91ed 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -121,7 +121,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) case ESP_SPP_INIT_EVT: if (param->init.status == ESP_SPP_SUCCESS) { ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT"); - esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME); + esp_bt_gap_set_device_name(EXAMPLE_DEVICE_NAME); esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps); } else { @@ -204,7 +204,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) } #endif } else { - /* Means the prevous data packet is not sent at all, need to send the whole data packet again. */ + /* Means the previous data packet is not sent at all, need to send the whole data packet again. */ ESP_LOGE(SPP_TAG, "ESP_SPP_WRITE_EVT status:%d", param->write.status); } @@ -309,7 +309,7 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; case ESP_BT_GAP_KEY_NOTIF_EVT: ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%"PRIu32, param->key_notif.passkey); - ESP_LOGW(SPP_TAG, "Waiting responce..."); + ESP_LOGW(SPP_TAG, "Waiting response..."); break; case ESP_BT_GAP_KEY_REQ_EVT: ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!"); diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/main.c index 4aee8ee354..2230fc0214 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/main.c @@ -121,7 +121,7 @@ static void esp_spp_cb(uint16_t e, void *p) if (param->start.status == ESP_SPP_SUCCESS) { ESP_LOGI(SPP_TAG, "ESP_SPP_START_EVT handle:%"PRIu32" sec_id:%d scn:%d", param->start.handle, param->start.sec_id, param->start.scn); - esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME); + esp_bt_gap_set_device_name(EXAMPLE_DEVICE_NAME); esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); } else { ESP_LOGE(SPP_TAG, "ESP_SPP_START_EVT status:%d", param->start.status); diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/main.c index 71947b8870..8f811110c6 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/main.c @@ -194,7 +194,7 @@ static void esp_spp_cb(uint16_t e, void *p) case ESP_SPP_VFS_REGISTER_EVT: if (param->vfs_register.status == ESP_SPP_SUCCESS) { ESP_LOGI(SPP_TAG, "ESP_SPP_VFS_REGISTER_EVT"); - esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME); + esp_bt_gap_set_device_name(EXAMPLE_DEVICE_NAME); esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps); } else { diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/main.c b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/main.c index 38e4d0632c..d5e6f3d30e 100644 --- a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/main.c @@ -42,7 +42,7 @@ static void bt_hf_hdl_stack_evt(uint16_t event, void *p_param) { /* set up device name */ char *dev_name = "ESP_HFP_AG"; - esp_bt_dev_set_device_name(dev_name); + esp_bt_gap_set_device_name(dev_name); esp_hf_ag_register_callback(bt_app_hf_cb); @@ -112,7 +112,7 @@ void app_main(void) app_gpio_pcm_io_cfg(); #endif - /* configure externel chip for acoustic echo cancellation */ + /* configure external chip for acoustic echo cancellation */ #if ACOUSTIC_ECHO_CANCELLATION_ENABLE app_gpio_aec_io_cfg(); #endif /* ACOUSTIC_ECHO_CANCELLATION_ENABLE */ diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/main.c b/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/main.c index ffb3d6d63b..cfd1e4844f 100644 --- a/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/main.c @@ -197,7 +197,7 @@ void app_main(void) app_gpio_pcm_io_cfg(); #endif - /* configure externel chip for acoustic echo cancellation */ + /* configure external chip for acoustic echo cancellation */ #if ACOUSTIC_ECHO_CANCELLATION_ENABLE app_gpio_aec_io_cfg(); #endif /* ACOUSTIC_ECHO_CANCELLATION_ENABLE */ @@ -232,7 +232,7 @@ static void bt_hf_client_hdl_stack_evt(uint16_t event, void *p_param) case BT_APP_EVT_STACK_UP: { /* set up device name */ char *dev_name = "ESP_HFP_HF"; - esp_bt_dev_set_device_name(dev_name); + esp_bt_gap_set_device_name(dev_name); /* register GAP callback function */ esp_bt_gap_register_callback(esp_bt_gap_cb); diff --git a/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c b/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c index bc2dd5e938..95efcce108 100644 --- a/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c +++ b/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -45,7 +45,7 @@ /* log tag */ #define BT_BLE_COEX_TAG "BT_BLE_COEX" /* device name */ -#define BT_DEVICE_NAME "ESP_COEX_A2DP_DEMO" +#define BTDM_DEVICE_NAME "ESP_COEX_BTDM_DEMO" #define BLE_ADV_NAME "ESP_COEX_BLE_DEMO" /* BLE defines */ @@ -669,7 +669,8 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param) switch (event) { /* when do the stack up, this event comes */ case BT_APP_EVT_STACK_UP: { - esp_bt_dev_set_device_name(BT_DEVICE_NAME); + esp_bt_gap_set_device_name(BTDM_DEVICE_NAME); + esp_ble_gap_set_device_name(BTDM_DEVICE_NAME); esp_bt_gap_register_callback(bt_app_gap_cb); assert(esp_avrc_ct_init() == ESP_OK); diff --git a/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c b/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c index 7f32ddb446..d3574bb5e5 100644 --- a/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c +++ b/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c @@ -901,7 +901,7 @@ void app_main(void) #if CONFIG_BT_HID_DEVICE_ENABLED ESP_LOGI(TAG, "setting device name"); - esp_bt_dev_set_device_name(bt_hid_config.device_name); + esp_bt_gap_set_device_name(bt_hid_config.device_name); ESP_LOGI(TAG, "setting cod major, peripheral"); esp_bt_cod_t cod; cod.major = ESP_BT_COD_MAJOR_DEV_PERIPHERAL;