fix(nimble): memset the sync structs to prevent uncertainty for ext_adv reports

This commit is contained in:
Abhinav Kudnar
2025-05-29 11:55:33 +05:30
parent 37acb543a7
commit 009ed01b68
2 changed files with 8 additions and 40 deletions

View File

@ -22,7 +22,6 @@ static void start_scan(void);
static struct ble_hs_adv_fields fields; static struct ble_hs_adv_fields fields;
static bool synced = false; static bool synced = false;
uint8_t rsp_slot_idx = 0;
static int static int
gap_event_cb(struct ble_gap_event *event, void *arg) gap_event_cb(struct ble_gap_event *event, void *arg)
{ {
@ -57,12 +56,11 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
event->periodic_report.event_counter, event->periodic_report.event_counter,
event->periodic_report.subevent); event->periodic_report.subevent);
rsp_slot_idx += 1;
struct ble_gap_periodic_adv_response_params param = { struct ble_gap_periodic_adv_response_params param = {
.request_event = event->periodic_report.event_counter, .request_event = event->periodic_report.event_counter,
.request_subevent = event->periodic_report.subevent, .request_subevent = event->periodic_report.subevent,
.response_subevent = event->periodic_report.subevent, .response_subevent = event->periodic_report.subevent,
.response_slot = rsp_slot_idx, .response_slot = 2,
}; };
struct os_mbuf *data = os_msys_get_pkthdr(BLE_PAWR_RSP_DATA_LEN, 0); struct os_mbuf *data = os_msys_get_pkthdr(BLE_PAWR_RSP_DATA_LEN, 0);
@ -129,8 +127,9 @@ static int
create_periodic_sync(struct ble_gap_ext_disc_desc *disc) create_periodic_sync(struct ble_gap_ext_disc_desc *disc)
{ {
int rc; int rc;
struct ble_gap_periodic_sync_params params; struct ble_gap_periodic_sync_params params = {0};
memset(&params, 0, sizeof(params));
params.skip = 0; params.skip = 0;
params.sync_timeout = 4000; params.sync_timeout = 4000;
params.reports_disabled = 0; params.reports_disabled = 0;
@ -159,9 +158,11 @@ start_scan(void)
int rc; int rc;
struct ble_gap_ext_disc_params disc_params; struct ble_gap_ext_disc_params disc_params;
/* Perform a passive scan. I.e., don't send follow-up scan requests to /* Perform a passive scan. I.e., don't send follow-up scan requests to
* each advertiser. * each advertiser.
*/ */
memset(&disc_params, 0, sizeof(disc_params));
disc_params.itvl = BLE_GAP_SCAN_ITVL_MS(600); disc_params.itvl = BLE_GAP_SCAN_ITVL_MS(600);
disc_params.window = BLE_GAP_SCAN_ITVL_MS(300); disc_params.window = BLE_GAP_SCAN_ITVL_MS(300);
disc_params.passive = 1; disc_params.passive = 1;
@ -182,23 +183,6 @@ on_reset(int reason)
ESP_LOGE(TAG, "Resetting state; reason=%d\n", reason); ESP_LOGE(TAG, "Resetting state; reason=%d\n", reason);
} }
/* Cnnot find `ble_single_xxxx()`, workaround */
// static void
// on_sync(void)
// {
// int ble_single_env_init(void);
// int ble_single_init(void);
// int rc;
// rc = ble_single_env_init();
// assert(!rc);
// rc = ble_single_init();
// assert(!rc);
// start_scan();
// }
static void static void
on_sync(void) on_sync(void)
{ {

View File

@ -185,8 +185,8 @@ static int
create_periodic_sync(struct ble_gap_ext_disc_desc *disc) create_periodic_sync(struct ble_gap_ext_disc_desc *disc)
{ {
int rc; int rc;
struct ble_gap_periodic_sync_params params; struct ble_gap_periodic_sync_params params = {0};
memset(&params, 0, sizeof(params));
params.skip = 0; params.skip = 0;
params.sync_timeout = 4000; params.sync_timeout = 4000;
params.reports_disabled = 0; params.reports_disabled = 0;
@ -218,6 +218,7 @@ start_scan(void)
/* Perform a passive scan. I.e., don't send follow-up scan requests to /* Perform a passive scan. I.e., don't send follow-up scan requests to
* each advertiser. * each advertiser.
*/ */
memset(&disc_params, 0, sizeof(disc_params));
disc_params.itvl = BLE_GAP_SCAN_ITVL_MS(600); disc_params.itvl = BLE_GAP_SCAN_ITVL_MS(600);
disc_params.window = BLE_GAP_SCAN_ITVL_MS(300); disc_params.window = BLE_GAP_SCAN_ITVL_MS(300);
disc_params.passive = 1; disc_params.passive = 1;
@ -238,23 +239,6 @@ on_reset(int reason)
ESP_LOGE(TAG, "Resetting state; reason=%d\n", reason); ESP_LOGE(TAG, "Resetting state; reason=%d\n", reason);
} }
/* Cnnot find `ble_single_xxxx()`, workaround */
// static void
// on_sync(void)
// {
// int ble_single_env_init(void);
// int ble_single_init(void);
// int rc;
// rc = ble_single_env_init();
// assert(!rc);
// rc = ble_single_init();
// assert(!rc);
// start_scan();
// }
static void static void
on_sync(void) on_sync(void)
{ {