xref: /nrf52832-nimble/packages/NimBLE-latest/nimble/host/src/ble_hs_conn_priv.h (revision 042d53a763ad75cb1465103098bb88c245d95138)
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_HS_CONN_
21 #define H_BLE_HS_CONN_
22 
23 #include <inttypes.h>
24 #include "ble_l2cap_priv.h"
25 #include "ble_gatt_priv.h"
26 #include "ble_att_priv.h"
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 struct hci_le_conn_complete;
32 struct hci_create_conn;
33 struct ble_l2cap_chan;
34 
35 typedef uint8_t ble_hs_conn_flags_t;
36 
37 #define BLE_HS_CONN_F_MASTER        0x01
38 #define BLE_HS_CONN_F_TERMINATING   0x02
39 #define BLE_HS_CONN_F_TX_FRAG       0x04 /* Cur ACL packet partially txed. */
40 
41 struct ble_hs_conn {
42     SLIST_ENTRY(ble_hs_conn) bhc_next;
43     uint16_t bhc_handle;
44     uint8_t bhc_our_addr_type;
45 #if MYNEWT_VAL(BLE_EXT_ADV)
46     uint8_t bhc_our_rnd_addr[6];
47 #endif
48     ble_addr_t bhc_peer_addr;
49     ble_addr_t bhc_our_rpa_addr;
50     ble_addr_t bhc_peer_rpa_addr;
51 
52     uint16_t bhc_itvl;
53     uint16_t bhc_latency;
54     uint16_t bhc_supervision_timeout;
55     uint8_t bhc_master_clock_accuracy;
56 
57     uint32_t supported_feat;
58 
59     ble_hs_conn_flags_t bhc_flags;
60 
61     struct ble_l2cap_chan_list bhc_channels;
62     struct ble_l2cap_chan *bhc_rx_chan; /* Channel rxing current packet. */
63     ble_npl_time_t bhc_rx_timeout;
64 
65     /**
66      * Count of packets sent over this connection that the controller has not
67      * transmitted or flushed yet.
68      */
69     uint16_t bhc_outstanding_pkts;
70 
71 #if MYNEWT_VAL(BLE_HS_FLOW_CTRL)
72     /**
73      * Count of packets received over this connection that have been processed
74      * and freed.
75      */
76     uint16_t bhc_completed_pkts;
77 #endif
78 
79     /** Queue of outgoing packets that could not be sent. */
80     STAILQ_HEAD(, os_mbuf_pkthdr) bhc_tx_q;
81 
82     struct ble_att_svr_conn bhc_att_svr;
83     struct ble_gatts_conn bhc_gatt_svr;
84 
85     struct ble_gap_sec_state bhc_sec_state;
86 
87     ble_gap_event_fn *bhc_cb;
88     void *bhc_cb_arg;
89 };
90 
91 struct ble_hs_conn_addrs {
92     ble_addr_t our_id_addr;
93     ble_addr_t peer_id_addr;
94     ble_addr_t our_ota_addr;
95     ble_addr_t peer_ota_addr;
96 };
97 
98 int ble_hs_conn_can_alloc(void);
99 struct ble_hs_conn *ble_hs_conn_alloc(uint16_t conn_handle);
100 void ble_hs_conn_free(struct ble_hs_conn *conn);
101 void ble_hs_conn_insert(struct ble_hs_conn *conn);
102 void ble_hs_conn_remove(struct ble_hs_conn *conn);
103 struct ble_hs_conn *ble_hs_conn_find(uint16_t conn_handle);
104 struct ble_hs_conn *ble_hs_conn_find_assert(uint16_t conn_handle);
105 struct ble_hs_conn *ble_hs_conn_find_by_addr(const ble_addr_t *addr);
106 struct ble_hs_conn *ble_hs_conn_find_by_idx(int idx);
107 int ble_hs_conn_exists(uint16_t conn_handle);
108 struct ble_hs_conn *ble_hs_conn_first(void);
109 struct ble_l2cap_chan *ble_hs_conn_chan_find_by_scid(struct ble_hs_conn *conn,
110                                              uint16_t cid);
111 struct ble_l2cap_chan *ble_hs_conn_chan_find_by_dcid(struct ble_hs_conn *conn,
112                                              uint16_t cid);
113 int ble_hs_conn_chan_insert(struct ble_hs_conn *conn,
114                             struct ble_l2cap_chan *chan);
115 void
116 ble_hs_conn_delete_chan(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan);
117 
118 void ble_hs_conn_addrs(const struct ble_hs_conn *conn,
119                        struct ble_hs_conn_addrs *addrs);
120 int32_t ble_hs_conn_timer(void);
121 
122 int ble_hs_conn_init(void);
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 
128 #endif
129