Skip to content

Commit 21ca237

Browse files
committed
Merge branch 'bugfix/fix_some_ble_bugs_2503' into 'master'
Bugfix/fix some ble bugs 2503 Closes BLERP-1678, BLERP-1679, BLERP-1680, BLERP-1681, BLERP-1683, BLERP-1685, and BLERP-1687 See merge request espressif/esp-idf!37930
2 parents fb0a087 + 55043e2 commit 21ca237

File tree

29 files changed

+336
-27
lines changed

29 files changed

+336
-27
lines changed

components/bt/common/btc/core/btc_manage.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -16,6 +16,12 @@ void **btc_profile_cb_tab;
1616

1717
void esp_profile_cb_reset(void)
1818
{
19+
#if BTC_DYNAMIC_MEMORY == TRUE
20+
if (btc_profile_cb_tab == NULL) {
21+
return;
22+
}
23+
#endif
24+
1925
int i;
2026

2127
for (i = 0; i < BTC_PID_NUM; i++) {
@@ -25,6 +31,12 @@ void esp_profile_cb_reset(void)
2531

2632
int btc_profile_cb_set(btc_pid_t profile_id, void *cb)
2733
{
34+
#if BTC_DYNAMIC_MEMORY == TRUE
35+
if (btc_profile_cb_tab == NULL) {
36+
return -1;
37+
}
38+
#endif
39+
2840
if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
2941
return -1;
3042
}
@@ -36,6 +48,12 @@ int btc_profile_cb_set(btc_pid_t profile_id, void *cb)
3648

3749
void *btc_profile_cb_get(btc_pid_t profile_id)
3850
{
51+
#if BTC_DYNAMIC_MEMORY == TRUE
52+
if (btc_profile_cb_tab == NULL) {
53+
return NULL;
54+
}
55+
#endif
56+
3957
if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
4058
return NULL;
4159
}

components/bt/host/bluedroid/api/esp_bt_device.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -95,6 +95,11 @@ esp_err_t esp_bt_dev_coex_status_config(esp_bt_dev_coex_type_t type, esp_bt_dev_
9595
}
9696
#endif
9797

98+
esp_err_t esp_bt_config_file_path_get(char *file_path)
99+
{
100+
return btc_config_file_path_get(file_path);
101+
}
102+
98103
esp_err_t esp_bt_config_file_path_update(const char *file_path)
99104
{
100105
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_UNINITIALIZED);

components/bt/host/bluedroid/api/esp_gap_ble_api.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ esp_err_t esp_ble_gap_read_rssi(esp_bd_addr_t remote_addr)
581581

582582
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
583583
}
584+
584585
#if (BLE_42_FEATURE_SUPPORT == TRUE)
585586
esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len)
586587
{
@@ -929,6 +930,26 @@ esp_err_t esp_gap_ble_set_channels(esp_gap_ble_channels channels)
929930
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
930931
}
931932

933+
esp_err_t esp_ble_gap_read_channel_map(esp_bd_addr_t bd_addr)
934+
{
935+
if (!bd_addr) {
936+
return ESP_ERR_INVALID_ARG;
937+
}
938+
939+
btc_msg_t msg;
940+
btc_ble_gap_args_t arg;
941+
942+
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
943+
944+
msg.sig = BTC_SIG_API_CALL;
945+
msg.pid = BTC_PID_GAP_BLE;
946+
msg.act = BTC_GAP_BLE_READ_CHANNEL_MAP;
947+
948+
memcpy(arg.read_channel_map.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
949+
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL)
950+
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
951+
}
952+
932953
esp_err_t esp_gap_ble_set_authorization(esp_bd_addr_t bd_addr, bool authorize)
933954
{
934955
if (!bd_addr) {

components/bt/host/bluedroid/api/include/api/esp_bt_device.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -128,6 +128,17 @@ esp_err_t esp_bt_dev_get_device_name(void) __attribute__((deprecated("Please use
128128
*/
129129
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);
130130

131+
/**
132+
* @brief This function is used to get the path name of the Bluetooth bond keys
133+
* saved in the NVS module.
134+
* @param[out] file_path: buffer to store the config file path, max length NVS_KEY_NAME_MAX_SIZE
135+
*
136+
* @return
137+
* - ESP_OK: success
138+
*
139+
*/
140+
esp_err_t esp_bt_config_file_path_get(char *file_path);
141+
131142
/**
132143
* @brief This function is used to update the path name of bluetooth bond keys saved in the NVS module
133144
* and need to be called before esp_bluedroid_init().

components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ typedef enum {
245245
ESP_GAP_BLE_SUBRATE_REQUEST_COMPLETE_EVT, /*!< when subrate request command complete, the event comes */
246246
ESP_GAP_BLE_SUBRATE_CHANGE_EVT, /*!< when Connection Subrate Update procedure has completed and some parameters of the specified connection have changed, the event comes */
247247
ESP_GAP_BLE_SET_HOST_FEATURE_CMPL_EVT, /*!< When host feature set complete, the event comes */
248+
ESP_GAP_BLE_READ_CHANNEL_MAP_COMPLETE_EVT, /*!< When BLE channel map result is received, the event comes */
248249
ESP_GAP_BLE_EVT_MAX, /*!< when maximum advertising event complete, the event comes */
249250
} esp_gap_ble_cb_event_t;
250251

@@ -1324,6 +1325,14 @@ typedef union {
13241325
if the RSSI cannot be read, the RSSI metric shall be set to 127. */
13251326
esp_bd_addr_t remote_addr; /*!< The remote device address */
13261327
} read_rssi_cmpl; /*!< Event parameter of ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT */
1328+
/**
1329+
* @brief ESP_GAP_BLE_READ_CHANNEL_MAP_COMPLETE_EVT
1330+
*/
1331+
struct ble_read_ble_channel_map_cmpl_evt_param {
1332+
esp_bt_status_t status; /*!< Status of the read channel map operation */
1333+
uint8_t channel_map[ESP_GAP_BLE_CHANNELS_LEN]; /*!< The BLE channel map, represented as a 5-byte array */
1334+
esp_bd_addr_t remote_addr; /*!< The remote device address */
1335+
} read_ble_channel_map_cmpl; /*!< Event parameter of ESP_GAP_BLE_READ_CHANNEL_MAP_COMPLETE_EVT */
13271336
/**
13281337
* @brief ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT
13291338
*/
@@ -1850,7 +1859,8 @@ esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params);
18501859
/**
18511860
* @brief This procedure keep the device scanning the peer device which advertising on the air
18521861
*
1853-
* @param[in] duration: Keeping the scanning time, the unit is second.
1862+
* @param[in] duration: The scanning duration in seconds.
1863+
* Set to 0 for continuous scanning until explicitly stopped.
18541864
*
18551865
* @return
18561866
* - ESP_OK : success
@@ -2193,6 +2203,7 @@ esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_d
21932203
* - other : failed
21942204
*/
21952205
esp_err_t esp_ble_gap_read_rssi(esp_bd_addr_t remote_addr);
2206+
21962207
#if (BLE_42_FEATURE_SUPPORT == TRUE)
21972208
/**
21982209
* @brief This function is called to add a device info into the duplicate scan exceptional list.
@@ -2440,6 +2451,18 @@ esp_err_t esp_ble_get_current_conn_params(esp_bd_addr_t bd_addr, esp_gap_conn_pa
24402451
*/
24412452
esp_err_t esp_gap_ble_set_channels(esp_gap_ble_channels channels);
24422453

2454+
/**
2455+
* @brief This function is used to read the current channel map
2456+
* for the connection identified by remote address.
2457+
*
2458+
* @param[in] bd_addr : BD address of the peer device
2459+
*
2460+
* @return - ESP_OK : success
2461+
* - other : failed
2462+
*
2463+
*/
2464+
esp_err_t esp_ble_gap_read_channel_map(esp_bd_addr_t bd_addr);
2465+
24432466
/**
24442467
* @brief This function is called to authorized a link after Authentication(MITM protection)
24452468
*

components/bt/host/bluedroid/bta/dm/bta_dm_act.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5865,6 +5865,13 @@ void bta_dm_ble_gap_set_vendor_evt_mask(tBTA_DM_MSG *p_data)
58655865
BTM_BleSetVendorEventMask(p_data->ble_set_vendor_evt_mask.evt_mask, p_data->ble_set_vendor_evt_mask.p_cback);
58665866
}
58675867

5868+
void bta_dm_read_ble_channel_map(tBTA_DM_MSG *p_data)
5869+
{
5870+
if (p_data && p_data->ch_map.read_ch_map_cb) {
5871+
BTM_ReadChannelMap(p_data->ch_map.remote_addr, p_data->ch_map.read_ch_map_cb);
5872+
}
5873+
}
5874+
58685875
#if (BLE_50_DTM_TEST_EN == TRUE)
58695876
void bta_dm_ble_gap_dtm_enhance_tx_start(tBTA_DM_MSG *p_data)
58705877
{

components/bt/host/bluedroid/bta/dm/bta_dm_api.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,20 @@ void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb)
500500
}
501501
#endif // BLE_HOST_READ_TX_POWER_EN
502502

503+
void BTA_DmBleReadChannelMap(BD_ADDR remote_device, tBTA_CMPL_CB *p_callback)
504+
{
505+
if (!remote_device || !p_callback) {
506+
return;
507+
}
508+
tBTA_DM_API_READ_CH_MAP *p_msg;
509+
510+
if ((p_msg = (tBTA_DM_API_READ_CH_MAP *)osi_malloc(sizeof(tBTA_DM_API_READ_CH_MAP))) != NULL) {
511+
p_msg->hdr.event = BTA_DM_API_BLE_READ_CH_MAP_EVT;
512+
memcpy(p_msg->remote_addr, remote_device, sizeof(BD_ADDR));
513+
p_msg->read_ch_map_cb = p_callback;
514+
bta_sys_sendmsg(p_msg);
515+
}
516+
}
503517
#endif ///BLE_INCLUDED == TRUE
504518

505519
void BTA_DmReadRSSI(BD_ADDR remote_addr, tBTA_TRANSPORT transport, tBTA_CMPL_CB *cmpl_cb)

components/bt/host/bluedroid/bta/dm/bta_dm_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
286286
bta_dm_ble_gap_set_privacy_mode, /* BTA_DM_API_SET_PRIVACY_MODE_EVT */
287287
bta_dm_ble_gap_set_csa_support, /* BTA_DM_API_BLE_SET_CSA_SUPPORT_EVT */
288288
bta_dm_ble_gap_set_vendor_evt_mask, /* BTA_DM_API_BLE_SET_VENDOR_EVT_MASK_EVT */
289+
bta_dm_read_ble_channel_map, /* BTA_DM_API_BLE_READ_CH_MAP_EVT */
289290
#endif
290291
#if (BLE_FEAT_ISO_EN == TRUE)
291292
#if (BLE_FEAT_ISO_BIG_BROCASTER_EN == TRUE)

components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ enum {
277277
BTA_DM_API_SET_PRIVACY_MODE_EVT,
278278
BTA_DM_API_BLE_SET_CSA_SUPPORT_EVT,
279279
BTA_DM_API_BLE_SET_VENDOR_EVT_MASK_EVT,
280+
BTA_DM_API_BLE_READ_CH_MAP_EVT,
280281
#endif
281282
#if (BLE_FEAT_ISO_EN == TRUE)
282283
#if (BLE_FEAT_ISO_BIG_BROCASTER_EN == TRUE)
@@ -490,6 +491,12 @@ typedef struct {
490491
tBTA_CMPL_CB *read_rssi_cb;
491492
}tBTA_DM_API_READ_RSSI;
492493

494+
typedef struct {
495+
BT_HDR hdr;
496+
BD_ADDR remote_addr;
497+
tBTA_CMPL_CB *read_ch_map_cb;
498+
} tBTA_DM_API_READ_CH_MAP;
499+
493500
/* data type for BTA_DM_API_SET_VISIBILITY_EVT */
494501
typedef struct {
495502
BT_HDR hdr;
@@ -1639,6 +1646,8 @@ typedef union {
16391646
#endif ///BLE_INCLUDED == TRUE
16401647
tBTA_DM_API_READ_RSSI rssi;
16411648

1649+
tBTA_DM_API_READ_CH_MAP ch_map;
1650+
16421651
tBTA_DM_API_SET_VISIBILITY set_visibility;
16431652

16441653
tBTA_DM_API_ADD_DEVICE add_dev;
@@ -2250,6 +2259,7 @@ extern void bta_dm_update_white_list(tBTA_DM_MSG *p_data);
22502259
extern void bta_dm_clear_white_list(tBTA_DM_MSG *p_data);
22512260
extern void bta_dm_ble_read_adv_tx_power(tBTA_DM_MSG *p_data);
22522261
extern void bta_dm_read_rssi(tBTA_DM_MSG *p_data);
2262+
extern void bta_dm_read_ble_channel_map(tBTA_DM_MSG *p_data);
22532263
#if (CLASSIC_BT_INCLUDED == TRUE)
22542264
extern void bta_dm_set_visibility (tBTA_DM_MSG *p_data);
22552265
#endif // #if (CLASSIC_BT_INCLUDED == TRUE)

components/bt/host/bluedroid/bta/include/bta/bta_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ typedef tBTM_TX_POWER_RESULTS tBTA_TX_POWER_RESULTS;
451451

452452
typedef tBTM_RSSI_RESULTS tBTA_RSSI_RESULTS;
453453

454+
typedef tBTM_BLE_CH_MAP_RESULTS tBTA_BLE_CH_MAP_RESULTS;
455+
454456
typedef tBTM_SET_AFH_CHANNELS_RESULTS tBTA_SET_AFH_CHANNELS_RESULTS;
455457
typedef tBTM_BLE_SET_CHANNELS_RESULTS tBTA_BLE_SET_CHANNELS_RESULTS;
456458

@@ -2067,6 +2069,7 @@ extern void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb);
20672069
#endif ///BLE_INCLUDED == TRUE
20682070

20692071
extern void BTA_DmReadRSSI(BD_ADDR remote_addr, tBTA_TRANSPORT transport, tBTA_CMPL_CB *cmpl_cb);
2072+
extern void BTA_DmBleReadChannelMap(BD_ADDR remote_device, tBTA_CMPL_CB *p_callback);
20702073

20712074
/*******************************************************************************
20722075
**

0 commit comments

Comments
 (0)