1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 #ifndef H_BLE_GAP_CONN_ 21 #define H_BLE_GAP_CONN_ 22 23 #include <stdint.h> 24 #include "syscfg/syscfg.h" 25 #include "stats/stats.h" 26 #include "host/ble_gap.h" 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 struct hci_le_conn_upd_complete; 32 struct hci_le_conn_param_req; 33 struct hci_le_conn_complete; 34 struct hci_disconn_complete; 35 struct hci_encrypt_change; 36 struct ble_hs_hci_ack; 37 struct ble_hs_adv; 38 39 STATS_SECT_START(ble_gap_stats) 40 STATS_SECT_ENTRY(wl_set) 41 STATS_SECT_ENTRY(wl_set_fail) 42 STATS_SECT_ENTRY(adv_stop) 43 STATS_SECT_ENTRY(adv_stop_fail) 44 STATS_SECT_ENTRY(adv_start) 45 STATS_SECT_ENTRY(adv_start_fail) 46 STATS_SECT_ENTRY(adv_set_data) 47 STATS_SECT_ENTRY(adv_set_data_fail) 48 STATS_SECT_ENTRY(adv_rsp_set_data) 49 STATS_SECT_ENTRY(adv_rsp_set_data_fail) 50 STATS_SECT_ENTRY(discover) 51 STATS_SECT_ENTRY(discover_fail) 52 STATS_SECT_ENTRY(initiate) 53 STATS_SECT_ENTRY(initiate_fail) 54 STATS_SECT_ENTRY(terminate) 55 STATS_SECT_ENTRY(terminate_fail) 56 STATS_SECT_ENTRY(cancel) 57 STATS_SECT_ENTRY(cancel_fail) 58 STATS_SECT_ENTRY(update) 59 STATS_SECT_ENTRY(update_fail) 60 STATS_SECT_ENTRY(connect_mst) 61 STATS_SECT_ENTRY(connect_slv) 62 STATS_SECT_ENTRY(disconnect) 63 STATS_SECT_ENTRY(rx_disconnect) 64 STATS_SECT_ENTRY(rx_update_complete) 65 STATS_SECT_ENTRY(rx_adv_report) 66 STATS_SECT_ENTRY(rx_conn_complete) 67 STATS_SECT_ENTRY(discover_cancel) 68 STATS_SECT_ENTRY(discover_cancel_fail) 69 STATS_SECT_ENTRY(security_initiate) 70 STATS_SECT_ENTRY(security_initiate_fail) 71 STATS_SECT_END 72 73 extern STATS_SECT_DECL(ble_gap_stats) ble_gap_stats; 74 75 #define BLE_GAP_CONN_MODE_MAX 3 76 #define BLE_GAP_DISC_MODE_MAX 3 77 78 #if MYNEWT_VAL(BLE_EXT_ADV) && NIMBLE_BLE_SCAN 79 void ble_gap_rx_le_scan_timeout(void); 80 #endif 81 82 #if MYNEWT_VAL(BLE_EXT_ADV) 83 void ble_gap_rx_ext_adv_report(struct ble_gap_ext_disc_desc *desc); 84 void ble_gap_rx_adv_set_terminated(const struct ble_hci_ev_le_subev_adv_set_terminated *ev); 85 #if MYNEWT_VAL(BLE_PERIODIC_ADV) 86 void ble_gap_rx_peroidic_adv_sync_estab(const struct ble_hci_ev_le_subev_periodic_adv_sync_estab 87 *ev); 88 void ble_gap_rx_periodic_adv_rpt(const struct ble_hci_ev_le_subev_periodic_adv_rpt *ev); 89 void ble_gap_rx_periodic_adv_sync_lost(const struct ble_hci_ev_le_subev_periodic_adv_sync_lost *ev); 90 void ble_gap_rx_periodic_adv_sync_transfer(const struct 91 ble_hci_ev_le_subev_periodic_adv_sync_transfer *ev); 92 #endif 93 void ble_gap_rx_scan_req_rcvd(const struct ble_hci_ev_le_subev_scan_req_rcvd *ev); 94 #endif 95 void ble_gap_rx_adv_report(struct ble_gap_disc_desc *desc); 96 void ble_gap_rx_rd_rem_sup_feat_complete(const struct ble_hci_ev_le_subev_rd_rem_used_feat *ev); 97 98 struct ble_gap_conn_complete { 99 uint8_t status; 100 uint16_t connection_handle; 101 uint8_t role; 102 uint8_t peer_addr_type; 103 uint8_t peer_addr[BLE_DEV_ADDR_LEN]; 104 uint16_t conn_itvl; 105 uint16_t conn_latency; 106 uint16_t supervision_timeout; 107 uint8_t master_clk_acc; 108 uint8_t local_rpa[BLE_DEV_ADDR_LEN]; 109 uint8_t peer_rpa[BLE_DEV_ADDR_LEN]; 110 }; 111 112 int ble_gap_rx_conn_complete(struct ble_gap_conn_complete *evt, uint8_t instance); 113 void ble_gap_rx_disconn_complete(const struct ble_hci_ev_disconn_cmp *ev); 114 void ble_gap_rx_update_complete(const struct ble_hci_ev_le_subev_conn_upd_complete *ev); 115 void ble_gap_rx_param_req(const struct ble_hci_ev_le_subev_rem_conn_param_req *ev); 116 int ble_gap_rx_l2cap_update_req(uint16_t conn_handle, 117 struct ble_gap_upd_params *params); 118 void ble_gap_rx_phy_update_complete(const struct ble_hci_ev_le_subev_phy_update_complete *ev); 119 void ble_gap_enc_event(uint16_t conn_handle, int status, 120 int security_restored); 121 void ble_gap_passkey_event(uint16_t conn_handle, 122 struct ble_gap_passkey_params *passkey_params); 123 void ble_gap_notify_rx_event(uint16_t conn_handle, uint16_t attr_handle, 124 struct os_mbuf *om, int is_indication); 125 void ble_gap_notify_tx_event(int status, uint16_t conn_handle, 126 uint16_t attr_handle, int is_indication); 127 void ble_gap_subscribe_event(uint16_t conn_handle, uint16_t attr_handle, 128 uint8_t reason, 129 uint8_t prev_notify, uint8_t cur_notify, 130 uint8_t prev_indicate, uint8_t cur_indicate); 131 void ble_gap_mtu_event(uint16_t conn_handle, uint16_t cid, uint16_t mtu); 132 void ble_gap_identity_event(uint16_t conn_handle); 133 int ble_gap_repeat_pairing_event(const struct ble_gap_repeat_pairing *rp); 134 int ble_gap_master_in_progress(void); 135 136 void ble_gap_preempt(void); 137 void ble_gap_preempt_done(void); 138 139 int ble_gap_terminate_with_conn(struct ble_hs_conn *conn, uint8_t hci_reason); 140 void ble_gap_conn_broken(uint16_t conn_handle, int reason); 141 int32_t ble_gap_timer(void); 142 143 int ble_gap_init(void); 144 void ble_gap_deinit(void); 145 146 #if MYNEWT_VAL(BLE_HS_DEBUG) 147 int ble_gap_dbg_update_active(uint16_t conn_handle); 148 #endif 149 150 #ifdef __cplusplus 151 } 152 #endif 153 154 #endif 155