Skip to content

Commit c6637ae

Browse files
committed
Merge branch 'bugfix/fix_few_nimble_issues_v5.4' into 'release/v5.4'
fix(nimble): Fix few nimble issues 11012025 (v5.4) See merge request espressif/esp-idf!36310
2 parents 1ceb4e4 + 3f4dd2b commit c6637ae

File tree

10 files changed

+137
-199
lines changed

10 files changed

+137
-199
lines changed

components/bt/host/nimble/Kconfig.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ config BT_NIMBLE_SMP_ID_RESET
177177
default n
178178
help
179179
There are tracking risks associated with using a fixed or static IRK.
180-
If enabled this option, Bluedroid will assign a new randomly-generated IRK
180+
If enabled this option, NimBLE will assign a new randomly-generated IRK
181181
when all pairing and bonding records are deleted. This would decrease the ability
182182
of a previously paired peer to be used to determine whether a device
183183
with which it previously shared an IRK is within range.

examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_adv/main/main.c

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -10,12 +10,13 @@
1010
#include "nimble/nimble_port_freertos.h"
1111
#include "host/ble_hs.h"
1212

13-
#define BLE_PAWR_NUM_SUBEVTS (5)
14-
#define BLE_PAWR_SUB_INTERVAL (12) /*!< Interval between subevents (N * 1.25 ms) */
15-
#define BLE_PAWR_RSP_SLOT_DELAY (1) /*!< The first response slot delay (N * 1.25 ms)*/
13+
#define BLE_PAWR_EVENT_INTERVAL (600)
14+
#define BLE_PAWR_NUM_SUBEVTS (10)
15+
#define BLE_PAWR_SUB_INTERVAL (44) /*!< Interval between subevents (N * 1.25 ms) */
16+
#define BLE_PAWR_RSP_SLOT_DELAY (20) /*!< The first response slot delay (N * 1.25 ms)*/
1617
#define BLE_PAWR_RSP_SLOT_SPACING (32) /*!< Time between response slots (N * 0.125 ms) */
17-
#define BLE_PAWR_NUM_RSP_SLOTS (3) /*!< Number of subevent response slots */
18-
#define BLE_PAWR_SUB_DATA_LEN (10)
18+
#define BLE_PAWR_NUM_RSP_SLOTS (5) /*!< Number of subevent response slots */
19+
#define BLE_PAWR_SUB_DATA_LEN (20)
1920

2021
#define TAG "NimBLE_BLE_PAwR"
2122

@@ -63,29 +64,20 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
6364
return 0;
6465

6566
case BLE_GAP_EVENT_PER_SUBEV_RESP:
66-
67-
if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_INCOMPLETE) {
68-
// ESP_LOGI(TAG,"Incomplete response report received, discarding \n");
69-
}
70-
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_RX_FAILED) {
71-
// ESP_LOGI(TAG,"Controller failed to received the AUX_SYNC_SUBEVENT_RSP\n");
72-
}
73-
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) {
74-
ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d, data:%x",
75-
event->periodic_adv_response.subevent,
76-
event->periodic_adv_response.response_slot,
77-
event->periodic_adv_response.data_length,
78-
event->periodic_adv_response.data[0]);
79-
}
80-
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_TRUNCATED) {
81-
// ESP_LOGI(TAG,"Truncated response report received, discarding\n");
67+
if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) {
68+
ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d",
69+
event->periodic_adv_response.subevent,
70+
event->periodic_adv_response.response_slot,
71+
event->periodic_adv_response.data_length);
72+
const uint8_t *data = event->periodic_adv_response.data;
73+
ESP_LOGI(TAG, "data: 0x%0x, 0x%0x", data[0], data[1]);
74+
} else {
75+
ESP_LOGE(TAG, "[Response] subevent:%d, response_slot:%d, rsp_data status:%d",
76+
event->periodic_adv_response.subevent,
77+
event->periodic_adv_response.response_slot,
78+
event->periodic_adv_response.data_status);
8279
}
83-
else {
84-
ESP_LOGE(TAG,"Invalid data status\n");
85-
}
86-
8780
return 0;
88-
8981
default:
9082
return 0;
9183
}
@@ -120,8 +112,8 @@ start_periodic_adv(void)
120112
params.primary_phy = BLE_HCI_LE_PHY_CODED;
121113
params.secondary_phy = BLE_HCI_LE_PHY_1M;
122114
params.sid = 0;
123-
params.itvl_min = BLE_GAP_ADV_ITVL_MS(100);
124-
params.itvl_max = BLE_GAP_ADV_ITVL_MS(100);
115+
params.itvl_min = BLE_PAWR_EVENT_INTERVAL;
116+
params.itvl_max = BLE_PAWR_EVENT_INTERVAL;
125117

126118
rc = ble_gap_ext_adv_configure(instance, &params, NULL, gap_event_cb, NULL);
127119
assert (rc == 0);
@@ -147,9 +139,9 @@ start_periodic_adv(void)
147139
pparams.itvl_max = BLE_GAP_PERIODIC_ITVL_MS(3000);
148140
/* Configure the parameters of PAwR. */
149141
pparams.num_subevents = BLE_PAWR_NUM_SUBEVTS;
150-
pparams.subevent_interval = BLE_GAP_PERIODIC_ITVL_MS(300);
151-
pparams.response_slot_delay = BLE_GAP_PERIODIC_ITVL_MS(80);
152-
pparams.response_slot_spacing = 0xFF;
142+
pparams.subevent_interval = BLE_PAWR_SUB_INTERVAL;
143+
pparams.response_slot_delay = BLE_PAWR_RSP_SLOT_DELAY;
144+
pparams.response_slot_spacing = BLE_PAWR_RSP_SLOT_SPACING;
153145
pparams.num_response_slots = BLE_PAWR_NUM_RSP_SLOTS;
154146

155147
rc = ble_gap_periodic_adv_configure(instance, &pparams);

examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_adv/sdkconfig.defaults

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,4 @@ CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1
1313
CONFIG_BT_NIMBLE_ROLE_CENTRAL=y
1414
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
1515

16-
CONFIG_BT_CONTROLLER_DISABLED=y
17-
18-
#
19-
# Host-controller Transport
20-
#
21-
CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT=1
22-
CONFIG_UART_BAUDRATE_115200=y
23-
CONFIG_BT_NIMBLE_UART_TX_PIN=20
24-
CONFIG_BT_NIMBLE_UART_RX_PIN=21
25-
CONFIG_UART_HW_FLOWCTRL_CTS_RTS=n
26-
# CONFIG_BT_NIMBLE_HCI_UART_RTS_PIN=22
27-
# CONFIG_BT_NIMBLE_HCI_UART_CTS_PIN=23
28-
# end of Host-controller Transport
29-
# end of NimBLE Options
30-
31-
# C6 Nordic
32-
# TX: 20 ---- RX
33-
# RX: 21 ---- TX
34-
# RTS: 22 ---- CTS
35-
# CTS: 23 ---- RTS
16+
CONFIG_BT_CONTROLLER_ENABLED=y

examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_sync/main/main.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -13,7 +13,7 @@
1313

1414
#define TAG "NimBLE_BLE_PAwR"
1515
#define TARGET_NAME "Nimble_PAwR"
16-
#define BLE_PAWR_RSP_DATA_LEN (20)
16+
#define BLE_PAWR_RSP_DATA_LEN (16)
1717
static uint8_t sub_data_pattern[BLE_PAWR_RSP_DATA_LEN] = {0};
1818

1919
static int create_periodic_sync(struct ble_gap_ext_disc_desc *disc);
@@ -22,6 +22,7 @@ static void start_scan(void);
2222
static struct ble_hs_adv_fields fields;
2323
static bool synced = false;
2424

25+
uint8_t rsp_slot_idx = 0;
2526
static int
2627
gap_event_cb(struct ble_gap_event *event, void *arg)
2728
{
@@ -51,20 +52,17 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
5152
return 0;
5253

5354
case BLE_GAP_EVENT_PERIODIC_REPORT:
54-
if (event->periodic_report.event_counter % 10 == 0) {
55-
// print every 10th event
56-
ESP_LOGI(TAG, "[Periodic Adv Report] handle:%d, rssi:%d, data status:0x%x",
57-
event->periodic_report.sync_handle, event->periodic_report.rssi,
58-
event->periodic_report.data_status);
59-
ESP_LOGI(TAG, "[Periodic Adv Report] event_counter(%d), subevent(%d)",
60-
event->periodic_report.event_counter, event->periodic_report.subevent);
61-
}
55+
ESP_LOGI(TAG, "[Periodic Adv Report] handle:%d, event_counter(%d), subevent(%d)",
56+
event->periodic_report.sync_handle,
57+
event->periodic_report.event_counter,
58+
event->periodic_report.subevent);
6259

60+
rsp_slot_idx += 1;
6361
struct ble_gap_periodic_adv_response_params param = {
6462
.request_event = event->periodic_report.event_counter,
6563
.request_subevent = event->periodic_report.subevent,
6664
.response_subevent = event->periodic_report.subevent,
67-
.response_slot = 0
65+
.response_slot = rsp_slot_idx,
6866
};
6967

7068
struct os_mbuf *data = os_msys_get_pkthdr(BLE_PAWR_RSP_DATA_LEN, 0);
@@ -79,8 +77,12 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
7977

8078
rc = ble_gap_periodic_adv_set_response_data(event->periodic_report.sync_handle, &param, data);
8179
if (rc) {
82-
ESP_LOGE(TAG, "Set response data failed, subev(%x), rsp_slot(%d), rc(0x%x)",
83-
sub_data_pattern[0], event->periodic_report.subevent, rc);
80+
ESP_LOGE(TAG, "Set response data failed, sync handle: %d, subev(%x), rsp_slot(%d), rc(0x%x)",
81+
event->periodic_report.sync_handle, param.response_subevent, param.response_slot, rc);
82+
}
83+
else{
84+
ESP_LOGI(TAG, "[RSP Data Set] sync handle: %d, subev(%x), rsp_slot(%d), rc(0x%x)",
85+
event->periodic_report.sync_handle, param.response_subevent, param.response_slot, rc);
8486
}
8587
os_mbuf_free_chain(data);
8688

examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_sync/sdkconfig.defaults

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,4 @@ CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1
1313
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
1414
CONFIG_BT_NIMBLE_ROLE_OBSERVER=y
1515

16-
CONFIG_BT_CONTROLLER_DISABLED=y
17-
18-
#
19-
# Host-controller Transport
20-
#
21-
CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT=1
22-
CONFIG_UART_BAUDRATE_115200=y
23-
CONFIG_BT_NIMBLE_UART_TX_PIN=20
24-
CONFIG_BT_NIMBLE_UART_RX_PIN=21
25-
CONFIG_UART_HW_FLOWCTRL_CTS_RTS=n
26-
# CONFIG_BT_NIMBLE_HCI_UART_RTS_PIN=22
27-
# CONFIG_BT_NIMBLE_HCI_UART_CTS_PIN=23
28-
# end of Host-controller Transport
29-
# end of NimBLE Options
30-
31-
# C6 Nordic
32-
# TX: 20 ---- RX
33-
# RX: 21 ---- TX
34-
# RTS: 22 ---- CTS
35-
# CTS: 23 ---- RTS
16+
CONFIG_BT_CONTROLLER_ENABLED=y

examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/main/main.c

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -10,14 +10,15 @@
1010
#include "nimble/nimble_port_freertos.h"
1111
#include "host/ble_hs.h"
1212

13-
#define BLE_PAWR_NUM_SUBEVTS (5)
14-
#define BLE_PAWR_SUB_INTERVAL (12) /*!< Interval between subevents (N * 1.25 ms) */
15-
#define BLE_PAWR_RSP_SLOT_DELAY (1) /*!< The first response slot delay (N * 1.25 ms)*/
16-
#define BLE_PAWR_RSP_SLOT_SPACING (32) /*!< Time between response slots (N * 0.125 ms) */
17-
#define BLE_PAWR_NUM_RSP_SLOTS (3) /*!< Number of subevent response slots */
18-
#define BLE_PAWR_SUB_DATA_LEN (10)
13+
#define BLE_PAWR_EVENT_INTERVAL (520)
14+
#define BLE_PAWR_NUM_SUBEVTS (10)
15+
#define BLE_PAWR_SUB_INTERVAL (52) /*!< Interval between subevents (N * 1.25 ms) */
16+
#define BLE_PAWR_RSP_SLOT_DELAY (5) /*!< The first response slot delay (N * 1.25 ms)*/
17+
#define BLE_PAWR_RSP_SLOT_SPACING (10) /*!< Time between response slots (N * 0.125 ms) */
18+
#define BLE_PAWR_NUM_RSP_SLOTS (25) /*!< Number of subevent response slots */
19+
#define BLE_PAWR_SUB_DATA_LEN (20)
1920

20-
#define TAG "NimBLE_BLE_PAwR"
21+
#define TAG "NimBLE_BLE_PAwR_CONN"
2122

2223
static struct ble_gap_set_periodic_adv_subev_data_params sub_data_params[BLE_PAWR_NUM_SUBEVTS];
2324
static uint8_t sub_data_pattern[BLE_PAWR_SUB_DATA_LEN] = {0};
@@ -71,18 +72,28 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
7172
uint8_t phy_mask;
7273

7374
switch (event->type) {
74-
case BLE_GAP_EVENT_CONNECT:
75-
printf("\n");
76-
ESP_LOGI(TAG, "Connection established, conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->connect.conn_handle,event->connect.adv_handle, event->connect.status);
77-
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
78-
if(rc == 0){
79-
print_conn_desc(&desc);
80-
}
81-
else{
82-
ESP_LOGE(TAG,"Failed to find Conn Information");
83-
}
84-
85-
return 0;
75+
76+
case BLE_GAP_EVENT_LINK_ESTAB:
77+
if (event->link_estab.status == 0) {
78+
ESP_LOGI(TAG, "[Connection established], conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.adv_handle, event->link_estab.status);
79+
rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc);
80+
if (rc == 0) {
81+
print_conn_desc(&desc);
82+
}
83+
else{
84+
ESP_LOGE(TAG,"Failed to find Conn Information");
85+
}
86+
} else {
87+
ESP_LOGW(TAG, "[Connection Failed], conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.adv_handle, event->link_estab.status);
88+
conn = 0;
89+
}
90+
91+
return 0;
92+
case BLE_GAP_EVENT_DISCONNECT:
93+
ESP_LOGI(TAG, "[Disconnected], conn_handle = 0x%02x, status = 0x%0x\n",event->disconnect.conn.conn_handle,event->disconnect.reason);
94+
conn = 0;
95+
return 0;
96+
8697
case BLE_GAP_EVENT_PER_SUBEV_DATA_REQ:
8798
ESP_LOGI(TAG, "[Request] data: %x, subevt start:%d, subevt count:%d",
8899
sub_data_pattern[0],
@@ -115,20 +126,17 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
115126

116127
case BLE_GAP_EVENT_PER_SUBEV_RESP:
117128

118-
if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_INCOMPLETE) {
119-
// ESP_LOGI(TAG,"Incomplete response report received, discarding \n");
120-
}
121-
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_RX_FAILED) {
122-
// ESP_LOGI(TAG,"Controller failed to received the AUX_SYNC_SUBEVENT_RSP\n");
123-
}
124-
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) {
125-
ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d, data:%x",
129+
if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) {
130+
ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d",
126131
event->periodic_adv_response.subevent,
127132
event->periodic_adv_response.response_slot,
128-
event->periodic_adv_response.data_length,
129-
event->periodic_adv_response.data[0]);
133+
event->periodic_adv_response.data_length);
134+
const uint8_t *data = event->periodic_adv_response.data;
135+
ESP_LOGI(TAG, "data: 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x",
136+
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9]);
137+
130138
peer_addr.type=0;
131-
memcpy(peer_addr.val,&event->periodic_adv_response.data[1],6);
139+
memcpy(peer_addr.val,&event->periodic_adv_response.data[2],6);
132140

133141
adv_handle = event->periodic_adv_response.adv_handle;
134142
subevent = event->periodic_adv_response.subevent;
@@ -138,15 +146,16 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
138146
rc = ble_gap_connect_with_synced(0,adv_handle,subevent,&peer_addr,30000,phy_mask,NULL,NULL,NULL,gap_event_cb,NULL);
139147
if (rc != 0 ) {
140148
ESP_LOGI(TAG,"Error: Failed to connect to device , rc = %d\n",rc);
149+
}else {
150+
ESP_LOGI(TAG,"Connection create sent, adv handle = %d, subevent = %d", adv_handle, subevent);
141151
}
142152
conn = 1;
143153
}
144-
}
145-
else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_TRUNCATED) {
146-
// ESP_LOGI(TAG,"Truncated response report received, discarding\n");
147-
}
148-
else {
149-
ESP_LOGE(TAG,"Invalid data status\n");
154+
} else {
155+
ESP_LOGE(TAG, "[Response] subevent:%d, response_slot:%d, rsp_data status:%d",
156+
event->periodic_adv_response.subevent,
157+
event->periodic_adv_response.response_slot,
158+
event->periodic_adv_response.data_status);
150159
}
151160

152161
return 0;
@@ -185,14 +194,14 @@ start_periodic_adv(void)
185194
params.primary_phy = BLE_HCI_LE_PHY_CODED;
186195
params.secondary_phy = BLE_HCI_LE_PHY_1M;
187196
params.sid = 0;
188-
params.itvl_min = BLE_GAP_ADV_ITVL_MS(100);
189-
params.itvl_max = BLE_GAP_ADV_ITVL_MS(100);
197+
params.itvl_min = BLE_GAP_ADV_ITVL_MS(50);
198+
params.itvl_max = BLE_GAP_ADV_ITVL_MS(50);
190199

191200
rc = ble_gap_ext_adv_configure(instance, &params, NULL, gap_event_cb, NULL);
192201
assert (rc == 0);
193202

194203
memset(&adv_fields, 0, sizeof(adv_fields));
195-
adv_fields.name = (const uint8_t *)"Nimble_PAwR";
204+
adv_fields.name = (const uint8_t *)"Nimble_PAwR_CONN";
196205
adv_fields.name_len = strlen((char *)adv_fields.name);
197206

198207
/* mbuf chain will be increased if needed */
@@ -212,9 +221,9 @@ start_periodic_adv(void)
212221
pparams.itvl_max = BLE_GAP_PERIODIC_ITVL_MS(3000);
213222
/* Configure the parameters of PAwR. */
214223
pparams.num_subevents = BLE_PAWR_NUM_SUBEVTS;
215-
pparams.subevent_interval = BLE_GAP_PERIODIC_ITVL_MS(300);
216-
pparams.response_slot_delay = BLE_GAP_PERIODIC_ITVL_MS(80);
217-
pparams.response_slot_spacing = 0xFF;
224+
pparams.subevent_interval = BLE_PAWR_SUB_INTERVAL;
225+
pparams.response_slot_delay = BLE_PAWR_RSP_SLOT_DELAY;
226+
pparams.response_slot_spacing = BLE_PAWR_RSP_SLOT_SPACING;
218227
pparams.num_response_slots = BLE_PAWR_NUM_RSP_SLOTS;
219228

220229
rc = ble_gap_periodic_adv_configure(instance, &pparams);

0 commit comments

Comments
 (0)