From e72f1360c7084f0a15d6cf7125e77f09aab6017d Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Wed, 18 Dec 2024 17:40:36 +0530 Subject: [PATCH] Corrected link_estab event handling parameters --- nimble/host/include/host/ble_gap.h | 24 ++++++++++++++++++++++-- nimble/host/src/ble_gap.c | 20 +++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/nimble/host/include/host/ble_gap.h b/nimble/host/include/host/ble_gap.h index 279e580e1..3d26d3cab 100644 --- a/nimble/host/include/host/ble_gap.h +++ b/nimble/host/include/host/ble_gap.h @@ -620,7 +620,10 @@ struct ble_gap_event { } connect; /** - * Represents a successful Link establishment attempt. Valid for the following event + * Represents a successful Link establishment attempt. Sometimes, in noisy environment, + * even if BLE_GAP_EVENT_CONNECT is posted, the link syncronization procedure may fail + * and link gets disconnected with reason 0x3E. Application can wait for below event to ensure + * the link syncronization is completed. Valid for the following event * types: * o BLE_GAP_EVENT_LINK_ESTAB */ @@ -636,7 +639,24 @@ struct ble_gap_event { /** The handle of the relevant connection. */ uint16_t conn_handle; - } link_estab; +#if MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES) + /* + * Adv_Handle is used to identify an advertising set. + * If the connection is established from periodic advertising with responses + * and Role is 0x00 then the Advertising_Handle parameter shall be set + * according to the periodic advertising train the connection was established from + */ + uint8_t adv_handle; + + /* + * Sync_Handle identifying the periodic advertising train + * If the connection is established from periodic advertising with responses + * and Role is 0x01, then the Sync_Handle parameter shall be set according + * to the periodic advertising train the connection was established from + */ + uint16_t sync_handle; +#endif + } link_estab; /** * Represents a terminated connection. Valid for the following event diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 28e278274..fdbf73a3c 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -157,7 +157,6 @@ struct ble_gap_adv_reattempt_ctxt { }ble_adv_reattempt; #endif - /** * The state of the in-progress master connection. If no master connection is * currently in progress, then the op field is set to BLE_GAP_OP_NULL. @@ -263,6 +262,11 @@ static os_membuf_t ble_gap_update_entry_mem[ static struct os_mempool ble_gap_update_entry_pool; static struct ble_gap_update_entry_list ble_gap_update_entries; +#if MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES) +static uint8_t pawr_adv_handle; +static uint16_t pawr_sync_handle; +#endif + static void ble_gap_update_entry_free(struct ble_gap_update_entry *entry); #if NIMBLE_BLE_CONNECT @@ -994,6 +998,8 @@ ble_gap_master_connect_failure(int status) rc = state.cb(&event, state.cb_arg); event.type = BLE_GAP_EVENT_LINK_ESTAB; + event.link_estab.status = status; + rc = state.cb(&event, state.cb_arg); } else { rc = 0; @@ -1023,6 +1029,9 @@ ble_gap_master_connect_cancelled(void) state.cb(&event, state.cb_arg); event.type = BLE_GAP_EVENT_LINK_ESTAB; + event.link_estab.conn_handle = event.connect.conn_handle; + event.link_estab.status = event.connect.status; + state.cb(&event, state.cb_arg); } } @@ -2364,7 +2373,11 @@ ble_gap_rx_conn_complete(struct ble_gap_conn_complete *evt, uint8_t instance) #if MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES) event.connect.sync_handle = evt->sync_handle; event.connect.adv_handle = evt->adv_handle; + + pawr_sync_handle = evt->sync_handle; + pawr_adv_handle = evt->adv_handle; #endif + ble_gap_event_listener_call(&event); ble_gap_call_conn_event_cb(&event, evt->connection_handle); @@ -2396,6 +2409,11 @@ ble_gap_rx_rd_rem_sup_feat_complete(const struct ble_hci_ev_le_subev_rd_rem_used event.link_estab.status = ev->status; event.link_estab.conn_handle = conn_handle; +#if MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES) + event.link_estab.sync_handle = pawr_sync_handle; + event.link_estab.adv_handle = pawr_adv_handle; +#endif + ble_gap_event_listener_call(&event); ble_gap_call_conn_event_cb(&event, conn_handle);