diff --git a/nimble/host/include/host/ble_gap.h b/nimble/host/include/host/ble_gap.h index fedcb3e35..da4043bdd 100644 --- a/nimble/host/include/host/ble_gap.h +++ b/nimble/host/include/host/ble_gap.h @@ -164,6 +164,7 @@ struct hci_conn_update; #define BLE_GAP_EVENT_CONNLESS_IQ_REPORT 35 #define BLE_GAP_EVENT_CONN_IQ_REPORT 36 #define BLE_GAP_EVENT_CTE_REQ_FAILED 37 +#define BLE_GAP_EVENT_LINK_ESTAB 38 /* DTM events */ #define BLE_GAP_DTM_TX_START_EVT 0 @@ -542,6 +543,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 f0b468941..2b79b162e 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -1056,6 +1056,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; } @@ -1082,6 +1085,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); } } @@ -2466,6 +2472,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();