NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
ble_hs_conn_priv.h
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
28extern "C" {
29#endif
30
31struct hci_le_conn_complete;
32struct hci_create_conn;
33struct ble_l2cap_chan;
34
35typedef 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#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM)
42#define BLE_HS_CONN_L2CAP_COC_CID_MASK_LEN_REM \
43 ((MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) % (8 * sizeof(uint32_t))) ? 1 : 0)
44
45#define BLE_HS_CONN_L2CAP_COC_CID_MASK_LEN \
46 (MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) / (8 * sizeof(uint32_t)) + \
47 BLE_HS_CONN_L2CAP_COC_CID_MASK_LEN_REM)
48#endif
49
50struct ble_hs_conn {
51 SLIST_ENTRY(ble_hs_conn) bhc_next;
52 uint16_t bhc_handle;
53 uint8_t bhc_our_addr_type;
54#if MYNEWT_VAL(BLE_EXT_ADV)
55 uint8_t bhc_our_rnd_addr[6];
56#endif
57 ble_addr_t bhc_peer_addr;
58 ble_addr_t bhc_our_rpa_addr;
59 ble_addr_t bhc_peer_rpa_addr;
60
61 uint16_t bhc_itvl;
62 uint16_t bhc_latency;
63 uint16_t bhc_supervision_timeout;
64 uint8_t bhc_master_clock_accuracy;
65
66 uint32_t supported_feat;
67
68 ble_hs_conn_flags_t bhc_flags;
69
70 struct ble_l2cap_chan_list bhc_channels;
71 struct ble_l2cap_chan *bhc_rx_chan; /* Channel rxing current packet. */
72 ble_npl_time_t bhc_rx_timeout;
73#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM)
74 uint32_t l2cap_coc_cid_mask[BLE_HS_CONN_L2CAP_COC_CID_MASK_LEN];
75#endif
76
81 uint16_t bhc_outstanding_pkts;
82
83#if MYNEWT_VAL(BLE_HS_FLOW_CTRL)
88 uint16_t bhc_completed_pkts;
89#endif
90
92 STAILQ_HEAD(, os_mbuf_pkthdr) bhc_tx_q;
93
94 struct ble_att_svr_conn bhc_att_svr;
95 struct ble_gatts_conn bhc_gatt_svr;
96
97 struct ble_gap_sec_state bhc_sec_state;
98
99 ble_gap_event_fn *bhc_cb;
100 void *bhc_cb_arg;
101
102#if MYNEWT_VAL(BLE_PERIODIC_ADV)
103 struct ble_hs_periodic_sync *psync;
104#endif
105};
106
107struct ble_hs_conn_addrs {
108 ble_addr_t our_id_addr;
109 ble_addr_t peer_id_addr;
110 ble_addr_t our_ota_addr;
111 ble_addr_t peer_ota_addr;
112};
113
114int ble_hs_conn_can_alloc(void);
115struct ble_hs_conn *ble_hs_conn_alloc(uint16_t conn_handle);
116void ble_hs_conn_free(struct ble_hs_conn *conn);
117void ble_hs_conn_insert(struct ble_hs_conn *conn);
118void ble_hs_conn_remove(struct ble_hs_conn *conn);
119struct ble_hs_conn *ble_hs_conn_find(uint16_t conn_handle);
120struct ble_hs_conn *ble_hs_conn_find_assert(uint16_t conn_handle);
121struct ble_hs_conn *ble_hs_conn_find_by_addr(const ble_addr_t *addr);
122struct ble_hs_conn *ble_hs_conn_find_by_idx(int idx);
123int ble_hs_conn_exists(uint16_t conn_handle);
124struct ble_hs_conn *ble_hs_conn_first(void);
125struct ble_l2cap_chan *ble_hs_conn_chan_find_by_scid(struct ble_hs_conn *conn,
126 uint16_t cid);
127struct ble_l2cap_chan *ble_hs_conn_chan_find_by_dcid(struct ble_hs_conn *conn,
128 uint16_t cid);
129bool ble_hs_conn_chan_exist(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan);
130int ble_hs_conn_chan_insert(struct ble_hs_conn *conn,
131 struct ble_l2cap_chan *chan);
132void ble_hs_conn_delete_chan(struct ble_hs_conn *conn,
133 struct ble_l2cap_chan *chan);
134
135void ble_hs_conn_addrs(const struct ble_hs_conn *conn,
136 struct ble_hs_conn_addrs *addrs);
137int32_t ble_hs_conn_timer(void);
138
139typedef int ble_hs_conn_foreach_fn(struct ble_hs_conn *conn, void *arg);
140void ble_hs_conn_foreach(ble_hs_conn_foreach_fn *cb, void *arg);
141
142int ble_hs_conn_init(void);
143
144#ifdef __cplusplus
145}
146#endif
147
148#endif
Definition ble_gap.h:202
Definition os_mbuf.h:70