Skip to content

Commit a5ecb8a

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'bugfix/fix_some_ble_bugs_2503_v5.0' into 'release/v5.0'
Bugfix/fix some ble bugs 2503 (v5.0) See merge request espressif/esp-idf!38287
2 parents 1779887 + 287f45a commit a5ecb8a

File tree

13 files changed

+68
-29
lines changed

13 files changed

+68
-29
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/include/api/esp_gap_ble_api.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,8 @@ esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params);
16611661
/**
16621662
* @brief This procedure keep the device scanning the peer device which advertising on the air
16631663
*
1664-
* @param[in] duration: Keeping the scanning time, the unit is second.
1664+
* @param[in] duration: The scanning duration in seconds.
1665+
* Set to 0 for continuous scanning until explicitly stopped.
16651666
*
16661667
* @return
16671668
* - ESP_OK : success

components/bt/host/bluedroid/device/controller.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ static controller_local_param_t *controller_param_ptr;
9696

9797
#define AWAIT_COMMAND(command) future_await(controller_param.hci->transmit_command_futured(command))
9898

99+
static bool loaded = false;
99100
// Module lifecycle functions
100101

101102
static void start_up(void)
@@ -322,6 +323,17 @@ static void shut_down(void)
322323
controller_param.readable = false;
323324
}
324325

326+
#if (BT_BLE_DYNAMIC_ENV_MEMORY == TRUE)
327+
void free_controller_param(void)
328+
{
329+
if (controller_param_ptr) {
330+
osi_free(controller_param_ptr);
331+
controller_param_ptr = NULL;
332+
loaded = false;
333+
}
334+
}
335+
#endif
336+
325337
static bool get_is_ready(void)
326338
{
327339
return controller_param.readable;
@@ -598,7 +610,6 @@ static const controller_t interface = {
598610

599611
const controller_t *controller_get_interface(void)
600612
{
601-
static bool loaded = false;
602613
if (!loaded) {
603614
loaded = true;
604615
#if (BT_BLE_DYNAMIC_ENV_MEMORY == TRUE)

components/bt/host/bluedroid/main/bte_main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ static void bte_main_enable(void);
6464
bluedroid_init_done_cb_t bluedroid_init_done_cb;
6565

6666
extern void osi_mem_dbg_init(void);
67+
#if (BT_BLE_DYNAMIC_ENV_MEMORY == TRUE)
68+
extern void free_controller_param(void);
69+
#endif
6770
/******************************************************************************
6871
**
6972
** Function bte_main_boot_entry
@@ -85,7 +88,7 @@ int bte_main_boot_entry(bluedroid_init_done_cb_t cb)
8588

8689
osi_init();
8790

88-
//Enbale HCI
91+
//Enable HCI
8992
bte_main_enable();
9093

9194
return 0;
@@ -105,6 +108,11 @@ void bte_main_shutdown(void)
105108
#if (BLE_INCLUDED == TRUE)
106109
BTA_VendorCleanup();
107110
#endif
111+
112+
#if (BT_BLE_DYNAMIC_ENV_MEMORY == TRUE)
113+
free_controller_param();
114+
#endif
115+
108116
bte_main_disable();
109117

110118
osi_deinit();

components/bt/host/bluedroid/stack/btm/btm_ble.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,17 +2289,16 @@ UINT8 btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data)
22892289

22902290

22912291
}
2292-
} else {
2293-
if (event == SMP_SC_LOC_OOB_DATA_UP_EVT) {
2294-
tBTM_LE_EVT_DATA evt_data;
2295-
memcpy(&evt_data.local_oob_data, &p_data->loc_oob_data, sizeof(tSMP_LOC_OOB_DATA));
2296-
if (btm_cb.api.p_le_callback) {
2297-
(*btm_cb.api.p_le_callback)(event, bd_addr, &evt_data);
2298-
}
2299-
} else {
2300-
BTM_TRACE_ERROR("btm_proc_smp_cback received for unknown device");
2292+
}
2293+
2294+
if (event == SMP_SC_LOC_OOB_DATA_UP_EVT) {
2295+
tBTM_LE_EVT_DATA evt_data;
2296+
memcpy(&evt_data.local_oob_data, &p_data->loc_oob_data, sizeof(tSMP_LOC_OOB_DATA));
2297+
if (btm_cb.api.p_le_callback) {
2298+
(*btm_cb.api.p_le_callback)(event, bd_addr, &evt_data);
23012299
}
23022300
}
2301+
23032302
return 0;
23042303
}
23052304
#endif ///SMP_INCLUDED == TRUE

components/bt/host/bluedroid/stack/btu/btu_task.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec)
448448
// NOTE: This value is in seconds but stored in a ticks field.
449449
p_tle->ticks = timeout_sec;
450450
p_tle->in_use = TRUE;
451-
osi_alarm_set(alarm, (period_ms_t)(timeout_sec * 1000));
451+
osi_alarm_set(alarm, (period_ms_t)((period_ms_t)timeout_sec * 1000));
452452
}
453453

454454

examples/bluetooth/bluedroid/ble/ble_eddystone_receiver/main/esp_eddystone_demo.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -52,9 +52,9 @@ static void esp_eddystone_show_inform(const esp_eddystone_result_t* res)
5252
ESP_LOGI(DEMO_TAG, "Eddystone UID inform:");
5353
ESP_LOGI(DEMO_TAG, "Measured power(RSSI at 0m distance):%d dbm", res->inform.uid.ranging_data);
5454
ESP_LOGI(DEMO_TAG, "EDDYSTONE_DEMO: Namespace ID:0x");
55-
esp_log_buffer_hex(DEMO_TAG, res->inform.uid.namespace_id, 10);
55+
ESP_LOG_BUFFER_HEX(DEMO_TAG, res->inform.uid.namespace_id, 10);
5656
ESP_LOGI(DEMO_TAG, "EDDYSTONE_DEMO: Instance ID:0x");
57-
esp_log_buffer_hex(DEMO_TAG, res->inform.uid.instance_id, 6);
57+
ESP_LOG_BUFFER_HEX(DEMO_TAG, res->inform.uid.instance_id, 6);
5858
break;
5959
}
6060
case EDDYSTONE_FRAME_TYPE_URL: {
@@ -84,6 +84,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* par
8484
switch(event)
8585
{
8686
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
87+
// the unit of the duration is second, 0 means scan permanently
8788
uint32_t duration = 0;
8889
esp_ble_gap_start_scanning(duration);
8990
break;
@@ -111,10 +112,10 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* par
111112
return;
112113
} else {
113114
// The received adv data is a correct eddystone frame packet.
114-
// Here, we get the eddystone infomation in eddystone_res, we can use the data in res to do other things.
115+
// Here, we get the eddystone information in eddystone_res, we can use the data in res to do other things.
115116
// For example, just print them:
116117
ESP_LOGI(DEMO_TAG, "--------Eddystone Found----------");
117-
esp_log_buffer_hex("EDDYSTONE_DEMO: Device address:", scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
118+
ESP_LOG_BUFFER_HEX("EDDYSTONE_DEMO: Device address:", scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
118119
ESP_LOGI(DEMO_TAG, "RSSI of packet:%d dbm", scan_result->scan_rst.rssi);
119120
esp_eddystone_show_inform(&eddystone_res);
120121
}

examples/bluetooth/bluedroid/ble/ble_ibeacon/main/ibeacon_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
7373
}
7474
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
7575
#if (IBEACON_MODE == IBEACON_RECEIVER)
76-
//the unit of the duration is second, 0 means scan permanently
76+
// the unit of the duration is second, 0 means scan permanently
7777
uint32_t duration = 0;
7878
esp_ble_gap_start_scanning(duration);
7979
#endif

examples/bluetooth/bluedroid/ble/ble_spp_client/main/spp_client_demo.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -216,9 +216,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
216216
ESP_LOGE(GATTC_TAG, "Scan param set failed: %s", esp_err_to_name(err));
217217
break;
218218
}
219-
//the unit of the duration is second
220-
uint32_t duration = 0xFFFF;
221-
ESP_LOGI(GATTC_TAG, "Enable Ble Scan:during time %04" PRIx32 " minutes.",duration);
219+
// the unit of the duration is second, 0 means scan permanently
220+
uint32_t duration = 0;
222221
esp_ble_gap_start_scanning(duration);
223222
break;
224223
}

examples/bluetooth/bluedroid/ble/gatt_client/main/gattc_demo.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
315315
uint8_t adv_name_len = 0;
316316
switch (event) {
317317
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
318-
//the unit of the duration is second
318+
// The unit of duration is seconds.
319+
// If duration is set to 0, scanning will continue indefinitely
320+
// until esp_ble_gap_stop_scanning is explicitly called.
319321
uint32_t duration = 30;
320322
esp_ble_gap_start_scanning(duration);
321323
break;

examples/bluetooth/bluedroid/ble/gatt_security_client/main/example_ble_sec_gattc_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
379379
}
380380
break;
381381
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
382-
//the unit of the duration is second
382+
// the unit of the duration is second, 0 means scan permanently
383383
uint32_t duration = 30;
384384
esp_ble_gap_start_scanning(duration);
385385
break;

examples/bluetooth/bluedroid/ble/gattc_multi_connect/main/gattc_multi_connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
750750
param->update_conn_params.timeout);
751751
break;
752752
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
753-
//the unit of the duration is second
753+
// the unit of the duration is second, 0 means scan permanently
754754
uint32_t duration = 30;
755755
esp_ble_gap_start_scanning(duration);
756756
break;

examples/bluetooth/bluedroid/coex/gattc_gatts_coex/main/gattc_gatts_coex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
276276
ESP_LOGI(COEX_TAG, "ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT, stop scan successfully\n");
277277
break;
278278
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
279-
ESP_LOGI(COEX_TAG, "ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, set scan sparameters complete\n");
280-
//the unit of the duration is second
279+
ESP_LOGI(COEX_TAG, "ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, set scan sparameters complete");
280+
// the unit of the duration is second, 0 means scan permanently
281281
uint32_t duration = 120;
282282
esp_ble_gap_start_scanning(duration);
283283
break;

0 commit comments

Comments
 (0)