Skip to content

Commit b03186d

Browse files
committed
fix(nimble): memset the sync structs to prevent uncertainty for ext_adv reports
1 parent d835854 commit b03186d

File tree

2 files changed

+8
-40
lines changed
  • examples/bluetooth/nimble
    • ble_pawr_adv_conn/ble_pawr_sync_conn/main
    • ble_pawr_adv/ble_pawr_sync/main

2 files changed

+8
-40
lines changed

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ 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;
2625
static int
2726
gap_event_cb(struct ble_gap_event *event, void *arg)
2827
{
@@ -57,12 +56,11 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
5756
event->periodic_report.event_counter,
5857
event->periodic_report.subevent);
5958

60-
rsp_slot_idx += 1;
6159
struct ble_gap_periodic_adv_response_params param = {
6260
.request_event = event->periodic_report.event_counter,
6361
.request_subevent = event->periodic_report.subevent,
6462
.response_subevent = event->periodic_report.subevent,
65-
.response_slot = rsp_slot_idx,
63+
.response_slot = 2,
6664
};
6765

6866
struct os_mbuf *data = os_msys_get_pkthdr(BLE_PAWR_RSP_DATA_LEN, 0);
@@ -129,8 +127,9 @@ static int
129127
create_periodic_sync(struct ble_gap_ext_disc_desc *disc)
130128
{
131129
int rc;
132-
struct ble_gap_periodic_sync_params params;
130+
struct ble_gap_periodic_sync_params params = {0};
133131

132+
memset(&params, 0, sizeof(params));
134133
params.skip = 0;
135134
params.sync_timeout = 4000;
136135
params.reports_disabled = 0;
@@ -159,9 +158,11 @@ start_scan(void)
159158
int rc;
160159
struct ble_gap_ext_disc_params disc_params;
161160

161+
162162
/* Perform a passive scan. I.e., don't send follow-up scan requests to
163163
* each advertiser.
164164
*/
165+
memset(&disc_params, 0, sizeof(disc_params));
165166
disc_params.itvl = BLE_GAP_SCAN_ITVL_MS(600);
166167
disc_params.window = BLE_GAP_SCAN_ITVL_MS(300);
167168
disc_params.passive = 1;
@@ -182,23 +183,6 @@ on_reset(int reason)
182183
ESP_LOGE(TAG, "Resetting state; reason=%d\n", reason);
183184
}
184185

185-
/* Cnnot find `ble_single_xxxx()`, workaround */
186-
// static void
187-
// on_sync(void)
188-
// {
189-
// int ble_single_env_init(void);
190-
// int ble_single_init(void);
191-
192-
// int rc;
193-
194-
// rc = ble_single_env_init();
195-
// assert(!rc);
196-
// rc = ble_single_init();
197-
// assert(!rc);
198-
199-
// start_scan();
200-
// }
201-
202186
static void
203187
on_sync(void)
204188
{

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ static int
185185
create_periodic_sync(struct ble_gap_ext_disc_desc *disc)
186186
{
187187
int rc;
188-
struct ble_gap_periodic_sync_params params;
189-
188+
struct ble_gap_periodic_sync_params params = {0};
189+
memset(&params, 0, sizeof(params));
190190
params.skip = 0;
191191
params.sync_timeout = 4000;
192192
params.reports_disabled = 0;
@@ -218,6 +218,7 @@ start_scan(void)
218218
/* Perform a passive scan. I.e., don't send follow-up scan requests to
219219
* each advertiser.
220220
*/
221+
memset(&disc_params, 0, sizeof(disc_params));
221222
disc_params.itvl = BLE_GAP_SCAN_ITVL_MS(600);
222223
disc_params.window = BLE_GAP_SCAN_ITVL_MS(300);
223224
disc_params.passive = 1;
@@ -238,23 +239,6 @@ on_reset(int reason)
238239
ESP_LOGE(TAG, "Resetting state; reason=%d\n", reason);
239240
}
240241

241-
/* Cnnot find `ble_single_xxxx()`, workaround */
242-
// static void
243-
// on_sync(void)
244-
// {
245-
// int ble_single_env_init(void);
246-
// int ble_single_init(void);
247-
248-
// int rc;
249-
250-
// rc = ble_single_env_init();
251-
// assert(!rc);
252-
// rc = ble_single_init();
253-
// assert(!rc);
254-
255-
// start_scan();
256-
// }
257-
258242
static void
259243
on_sync(void)
260244
{

0 commit comments

Comments
 (0)