From 1fa7edc41d7ee415699b7abe8fa1f7375d344c83 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Mon, 8 Jul 2024 16:46:07 +0530 Subject: [PATCH] Introduce new BLE_GAP_EVENT_LINK_ESTAB event to ensure link is established --- nimble/host/include/host/ble_gap.h | 20 ++++++++++++++++++++ nimble/host/src/ble_gap.c | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/nimble/host/include/host/ble_gap.h b/nimble/host/include/host/ble_gap.h index 1fe995745..4a9e5c3e1 100644 --- a/nimble/host/include/host/ble_gap.h +++ b/nimble/host/include/host/ble_gap.h @@ -159,6 +159,7 @@ struct hci_conn_update; #define BLE_GAP_EVENT_AUTHORIZE 30 #define BLE_GAP_EVENT_TEST_UPDATE 31 #define BLE_GAP_EVENT_DATA_LEN_CHG 32 +#define BLE_GAP_EVENT_LINK_ESTAB 33 /* DTM events */ #define BLE_GAP_DTM_TX_START_EVT 0 @@ -537,6 +538,25 @@ struct ble_gap_event { uint16_t conn_handle; } connect; + /** + * Represents a successful Link establishment attempt. Valid for the following event + * types: + * o BLE_GAP_EVENT_LINK_ESTAB + */ + + struct { + /** + * The final status of the link establishment; + * o 0: the connection was successfully established. + * o BLE host error code: the connection attempt failed for + * the specified reason. + */ + int status; + + /** The handle of the relevant connection. */ + uint16_t conn_handle; + } link_estab; + /** * Represents a terminated connection. Valid for the following event * types: diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 7b1e60182..98ec66cca 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -1005,6 +1005,9 @@ ble_gap_master_connect_failure(int status) event.connect.status = status; rc = state.cb(&event, state.cb_arg); + + event.type = BLE_GAP_EVENT_LINK_ESTAB; + rc = state.cb(&event, state.cb_arg); } else { rc = 0; } @@ -1031,6 +1034,9 @@ ble_gap_master_connect_cancelled(void) event.connect.status = BLE_HS_ETIMEOUT; } state.cb(&event, state.cb_arg); + + event.type = BLE_GAP_EVENT_LINK_ESTAB; + state.cb(&event, state.cb_arg); } } @@ -2291,6 +2297,17 @@ ble_gap_rx_rd_rem_sup_feat_complete(const struct ble_hci_ev_le_subev_rd_rem_used conn = ble_hs_conn_find(le16toh(ev->conn_handle)); if ((conn != NULL) && (ev->status == 0)) { conn->supported_feat = get_le32(ev->features); + + struct ble_gap_event event; + uint16_t conn_handle = le16toh(ev->conn_handle); + + memset(&event, 0, sizeof event); + event.type = BLE_GAP_EVENT_LINK_ESTAB; + event.link_estab.status = ev->status; + event.link_estab.conn_handle = conn_handle; + + ble_gap_event_listener_call(&event); + ble_gap_call_conn_event_cb(&event, conn_handle); } ble_hs_unlock();