diff --git a/nimble/host/include/host/ble_gap.h b/nimble/host/include/host/ble_gap.h index 348d0dd08..3a4dda421 100644 --- a/nimble/host/include/host/ble_gap.h +++ b/nimble/host/include/host/ble_gap.h @@ -164,11 +164,13 @@ 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 -#define BLE_GAP_EVENT_EATT 39 -#define BLE_GAP_EVENT_PER_SUBEV_DATA_REQ 40 -#define BLE_GAP_EVENT_PER_SUBEV_RESP 41 -#define BLE_GAP_EVENT_PERIODIC_TRANSFER_V2 42 + +/* Deprecate the EVENT_LINK_ESTAB */ +#define BLE_GAP_EVENT_LINK_ESTAB BLE_GAP_EVENT_CONNECT +#define BLE_GAP_EVENT_EATT 38 +#define BLE_GAP_EVENT_PER_SUBEV_DATA_REQ 39 +#define BLE_GAP_EVENT_PER_SUBEV_RESP 40 +#define BLE_GAP_EVENT_PERIODIC_TRANSFER_V2 41 /* DTM events */ #define BLE_GAP_DTM_TX_START_EVT 0 @@ -636,45 +638,6 @@ struct ble_gap_event { #endif } connect; - /** - * 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 - */ - - 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; -#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 * types: diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 681ff9b4a..9dafc9c85 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -1098,11 +1098,10 @@ ble_gap_master_connect_failure(int status) event.type = BLE_GAP_EVENT_CONNECT; event.connect.status = status; - rc = state.cb(&event, state.cb_arg); - - event.type = BLE_GAP_EVENT_LINK_ESTAB; - event.link_estab.status = status; - +#if MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES) + event.connect.sync_handle = pawr_sync_handle; + event.connect.adv_handle = pawr_adv_handle; +#endif rc = state.cb(&event, state.cb_arg); } else { rc = 0; @@ -1129,12 +1128,11 @@ ble_gap_master_connect_cancelled(void) /* Connect procedure timed out. */ event.connect.status = BLE_HS_ETIMEOUT; } - 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; +#if MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES) + event.connect.sync_handle = pawr_sync_handle; + event.connect.adv_handle = pawr_adv_handle; +#endif state.cb(&event, state.cb_arg); } } @@ -2551,7 +2549,6 @@ int ble_gap_rx_conn_complete(struct ble_gap_conn_complete *evt, uint8_t instance) { #if NIMBLE_BLE_CONNECT - struct ble_gap_event event; struct ble_hs_conn *conn; int rc; #if MYNEWT_VAL(BLE_GATT_CACHING) @@ -2695,15 +2692,10 @@ ble_gap_rx_conn_complete(struct ble_gap_conn_complete *evt, uint8_t instance) ble_hs_lock(); - memset(&event, 0, sizeof event); ble_hs_conn_insert(conn); ble_hs_unlock(); - event.type = BLE_GAP_EVENT_CONNECT; - event.connect.conn_handle = evt->connection_handle; - event.connect.status = 0; - /* add gatt connection */ #if MYNEWT_VAL(BLE_GATT_CACHING) if (evt->role == BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER) { @@ -2724,16 +2716,10 @@ ble_gap_rx_conn_complete(struct ble_gap_conn_complete *evt, uint8_t instance) } #endif #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); - if (evt->role == BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE) { ble_gap_rd_rem_ver_tx(evt->connection_handle); } else { @@ -2747,19 +2733,19 @@ ble_gap_rx_conn_complete(struct ble_gap_conn_complete *evt, uint8_t instance) } void -ble_gap_link_estab_call(uint16_t conn_handle, int status) +ble_gap_event_connect_call(uint16_t conn_handle, int status) { struct ble_gap_event event; uint16_t handle = le16toh(conn_handle); memset(&event, 0, sizeof event); - event.type = BLE_GAP_EVENT_LINK_ESTAB; - event.link_estab.status = status; - event.link_estab.conn_handle = handle; + event.type = BLE_GAP_EVENT_CONNECT; + event.connect.status = status; + event.connect.conn_handle = 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; + event.connect.sync_handle = pawr_sync_handle; + event.connect.adv_handle = pawr_adv_handle; #endif ble_gap_event_listener_call(&event); @@ -2789,7 +2775,7 @@ ble_gap_rx_rd_rem_sup_feat_complete(const struct ble_hci_ev_le_subev_rd_rem_used } else { if ((conn != NULL) && (ev->status == 0)) { conn->supported_feat = get_le32(ev->features); - ble_gap_link_estab_call(ev->conn_handle, ev->status); + ble_gap_event_connect_call(ev->conn_handle, ev->status); slave_conn[ev->conn_handle] = 1; } } @@ -2816,7 +2802,7 @@ ble_gap_rx_rd_rem_ver_info_complete(const struct ble_hci_ev_rd_rem_ver_info_cmp ble_gap_rd_rem_sup_feat_tx(ev->conn_handle); } else { if ((conn != NULL) && (ev->status == 0)) { - ble_gap_link_estab_call(ev->conn_handle, ev->status); + ble_gap_event_connect_call(ev->conn_handle, ev->status); } } #endif diff --git a/nimble/host/src/ble_gap_priv.h b/nimble/host/src/ble_gap_priv.h index 0987bca08..a9f029f98 100644 --- a/nimble/host/src/ble_gap_priv.h +++ b/nimble/host/src/ble_gap_priv.h @@ -96,7 +96,7 @@ void ble_gap_rx_scan_req_rcvd(const struct ble_hci_ev_le_subev_scan_req_rcvd *ev void ble_gap_rx_adv_report(struct ble_gap_disc_desc *desc); void ble_gap_rx_rd_rem_sup_feat_complete(const struct ble_hci_ev_le_subev_rd_rem_used_feat *ev); void ble_gap_rx_rd_rem_ver_info_complete(const struct ble_hci_ev_rd_rem_ver_info_cmp *ev); -void ble_gap_link_estab_call(uint16_t conn_handle, int status); +void ble_gap_event_connect_call(uint16_t conn_handle, int status); #if MYNEWT_VAL(BLE_CONN_SUBRATING) void ble_gap_rx_subrate_change(const struct ble_hci_ev_le_subev_subrate_change *ev); #endif