NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
ble_ll_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_LL_CONN_PRIV_
21#define H_BLE_LL_CONN_PRIV_
22
23#include "../include/controller/ble_ll_conn.h"
24#include "../include/controller/ble_ll_hci.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*
31 * Definitions for min/max RX/TX time/bytes values allowed for connections.
32 * Source: Core 5.0 specification, Vol 6, Part B, section 4.5.10
33 */
34#define BLE_LL_CONN_SUPP_TIME_MIN (328) /* usecs */
35#define BLE_LL_CONN_SUPP_TIME_MAX (17040) /* usecs */
36#define BLE_LL_CONN_SUPP_TIME_MIN_UNCODED (328) /* usecs */
37#define BLE_LL_CONN_SUPP_TIME_MAX_UNCODED (2120) /* usecs */
38#define BLE_LL_CONN_SUPP_TIME_MIN_CODED (2704) /* usecs */
39#define BLE_LL_CONN_SUPP_TIME_MAX_CODED (17040) /* usecs */
40#define BLE_LL_CONN_SUPP_BYTES_MIN (27) /* bytes */
41#define BLE_LL_CONN_SUPP_BYTES_MAX (251) /* bytes */
42
43/* Connection event timing */
44#define BLE_LL_CONN_INITIAL_OFFSET (1250)
45#define BLE_LL_CONN_ITVL_USECS (1250)
46#define BLE_LL_CONN_TX_WIN_USECS (1250)
47#define BLE_LL_CONN_TX_OFF_USECS (1250)
48#define BLE_LL_CONN_CE_USECS (625)
49#define BLE_LL_CONN_TX_WIN_MIN (1) /* in tx win units */
50#define BLE_LL_CONN_PERIPH_LATENCY_MAX (499)
51
52/* Connection handle range */
53#define BLE_LL_CONN_MAX_CONN_HANDLE (0x0EFF)
54
55/* Offset (in bytes) of advertising address in connect request */
56#define BLE_LL_CONN_REQ_ADVA_OFF (BLE_LL_PDU_HDR_LEN + BLE_DEV_ADDR_LEN)
57
58/* Default authenticated payload timeout (30 seconds; in 10 msecs increments) */
59#define BLE_LL_CONN_DEF_AUTH_PYLD_TMO (3000)
60#define BLE_LL_CONN_AUTH_PYLD_OS_TMO(x) ble_npl_time_ms_to_ticks32((x) * 10)
61
62#if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED)
63#define BLE_LL_CONN_CSS_NO_SLOT (UINT16_MAX)
64#endif
65
66/* Global Link Layer connection parameters */
67struct ble_ll_conn_global_params
68{
69#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL) || MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
70 uint8_t supp_max_tx_octets;
71 uint8_t supp_max_rx_octets;
72 uint8_t conn_init_max_tx_octets;
73 uint8_t sugg_tx_octets;
74 uint16_t sugg_tx_time;
75 uint16_t conn_init_max_tx_time;
76 uint16_t conn_init_max_tx_time_uncoded;
77 uint16_t conn_init_max_tx_time_coded;
78 uint16_t supp_max_tx_time;
79 uint16_t supp_max_rx_time;
80#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_ENHANCED_CONN_UPDATE)
81 uint16_t acc_subrate_min;
82 uint16_t acc_subrate_max;
83 uint16_t acc_max_latency;
84 uint16_t acc_cont_num;
85 uint16_t acc_supervision_tmo;
86#endif
87#endif
88};
89extern struct ble_ll_conn_global_params g_ble_ll_conn_params;
90
91#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_TRANSFER)
92struct ble_ll_conn_sync_transfer_params
93{
94 uint32_t sync_timeout_us;
95 uint16_t max_skip;
96 uint8_t mode;
97};
98extern struct ble_ll_conn_sync_transfer_params g_ble_ll_conn_sync_transfer_params;
99#endif
100
101/* Some data structures used by other LL routines */
102SLIST_HEAD(ble_ll_conn_active_list, ble_ll_conn_sm);
103STAILQ_HEAD(ble_ll_conn_free_list, ble_ll_conn_sm);
104extern struct ble_ll_conn_active_list g_ble_ll_conn_active_list;
105extern struct ble_ll_conn_free_list g_ble_ll_conn_free_list;
106
107struct ble_ll_conn_create_scan {
108 uint8_t filter_policy;
109 uint8_t own_addr_type;
110 uint8_t peer_addr_type;
111 uint8_t peer_addr[BLE_DEV_ADDR_LEN];
112#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
113 uint8_t init_phy_mask;
114#endif
115 struct {
116 uint16_t itvl;
117 uint16_t window;
118 } scan_params[2];
119};
120
121struct ble_ll_conn_create_params {
122 uint32_t conn_itvl;
123 uint32_t conn_itvl_ticks;
124 uint8_t conn_itvl_usecs;
125 uint16_t conn_latency;
126 uint16_t supervision_timeout;
127 uint16_t min_ce_len;
128 uint16_t max_ce_len;
129};
130
131struct ble_ll_conn_create_sm {
132 struct ble_ll_conn_sm *connsm;
133#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
134 struct ble_ll_conn_create_params params[3];
135#endif
136};
137
138extern struct ble_ll_conn_create_sm g_ble_ll_conn_create_sm;
139extern struct ble_ll_conn_sm *g_ble_ll_conn_css_ref;
140
141/* Generic interface */
142struct ble_ll_len_req;
143struct ble_mbuf_hdr;
144struct ble_ll_adv_sm;
145
146struct hci_create_conn
147{
148 uint16_t scan_itvl;
149 uint16_t scan_window;
150 uint8_t filter_policy;
151 uint8_t peer_addr_type;
152 uint8_t peer_addr[BLE_DEV_ADDR_LEN];
153 uint8_t own_addr_type;
154 uint16_t conn_itvl_min;
155 uint16_t conn_itvl_max;
156 uint16_t conn_latency;
157 uint16_t supervision_timeout;
158 uint16_t min_ce_len;
159 uint16_t max_ce_len;
160};
161
162void ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm);
163void ble_ll_conn_end(struct ble_ll_conn_sm *connsm, uint8_t ble_err);
164void ble_ll_conn_enqueue_pkt(struct ble_ll_conn_sm *connsm, struct os_mbuf *om,
165 uint8_t hdr_byte, uint16_t length);
166struct ble_ll_conn_sm *ble_ll_conn_sm_get(void);
167void ble_ll_conn_central_init(struct ble_ll_conn_sm *connsm,
168 struct ble_ll_conn_create_scan *cc_scan,
169 struct ble_ll_conn_create_params *cc_params);
170
171struct ble_ll_conn_sm *ble_ll_conn_find_by_handle(uint16_t handle);
172void ble_ll_conn_update_eff_data_len(struct ble_ll_conn_sm *connsm);
173
174/* Advertising interface */
175int ble_ll_conn_periph_start(uint8_t *rxbuf, uint8_t pat,
176 struct ble_mbuf_hdr *rxhdr, bool force_csa2);
177
178/* Link Layer interface */
179void ble_ll_conn_module_init(void);
180void ble_ll_conn_set_global_chanmap(uint8_t num_used_chans, const uint8_t *chanmap);
181void ble_ll_conn_module_reset(void);
182void ble_ll_conn_tx_pkt_in(struct os_mbuf *om, uint16_t handle, uint16_t len);
183int ble_ll_conn_rx_isr_start(struct ble_mbuf_hdr *rxhdr, uint32_t aa);
184int ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr);
185void ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr);
186void ble_ll_conn_wfr_timer_exp(void);
187int ble_ll_conn_is_lru(struct ble_ll_conn_sm *s1, struct ble_ll_conn_sm *s2);
188uint32_t ble_ll_conn_get_ce_end_time(void);
189void ble_ll_conn_event_halt(void);
190/* HCI */
191void ble_ll_disconn_comp_event_send(struct ble_ll_conn_sm *connsm,
192 uint8_t reason);
193void ble_ll_auth_pyld_tmo_event_send(struct ble_ll_conn_sm *connsm);
194int ble_ll_conn_hci_disconnect_cmd(const struct ble_hci_lc_disconnect_cp *cmd);
195int ble_ll_conn_hci_rd_rem_ver_cmd(const uint8_t *cmdbuf, uint8_t len);
196int ble_ll_conn_hci_create(const uint8_t *cmdbuf, uint8_t len);
197int ble_ll_conn_hci_update(const uint8_t *cmdbuf, uint8_t len);
198int ble_ll_conn_hci_set_chan_class(const uint8_t *cmdbuf, uint8_t len);
199int ble_ll_conn_hci_param_rr(const uint8_t *cmdbuf, uint8_t len,
200 uint8_t *rspbuf, uint8_t *rsplen);
201int ble_ll_conn_hci_param_nrr(const uint8_t *cmdbuf, uint8_t len,
202 uint8_t *rspbuf, uint8_t *rsplen);
203int ble_ll_conn_create_cancel(ble_ll_hci_post_cmd_complete_cb *post_cmd_cb);
204void ble_ll_conn_num_comp_pkts_event_send(struct ble_ll_conn_sm *connsm);
205void ble_ll_conn_comp_event_send(struct ble_ll_conn_sm *connsm, uint8_t status,
206 uint8_t *evbuf, struct ble_ll_adv_sm *advsm);
207void ble_ll_conn_timeout(struct ble_ll_conn_sm *connsm, uint8_t ble_err);
208int ble_ll_conn_hci_chk_conn_params(uint16_t itvl_min, uint16_t itvl_max,
209 uint16_t latency, uint16_t spvn_tmo);
210int ble_ll_conn_hci_read_rem_features(const uint8_t *cmdbuf, uint8_t len);
211int ble_ll_conn_hci_rd_rssi(const uint8_t *cmdbuf, uint8_t len, uint8_t *rspbuf,
212 uint8_t *rsplen);
213int ble_ll_conn_hci_rd_chan_map(const uint8_t *cmdbuf, uint8_t len,
214 uint8_t *rspbuf, uint8_t *rsplen);
215int ble_ll_conn_hci_set_data_len(const uint8_t *cmdbuf, uint8_t len,
216 uint8_t *rspbuf, uint8_t *rsplen);
217int ble_ll_conn_hci_le_start_encrypt(const uint8_t *cmdbuf, uint8_t len);
218int ble_ll_conn_hci_le_ltk_reply(const uint8_t *cmdbuf, uint8_t len,
219 uint8_t *rspbuf, uint8_t *rsplen);
220int ble_ll_conn_hci_le_ltk_neg_reply(const uint8_t *cmdbuf, uint8_t len,
221 uint8_t *rspbuf, uint8_t *rsplen);
222int ble_ll_conn_hci_wr_auth_pyld_tmo(const uint8_t *cmdbuf, uint8_t len,
223 uint8_t *rspbuf, uint8_t *rsplen);
224int ble_ll_conn_hci_rd_auth_pyld_tmo(const uint8_t *cmdbuf, uint8_t len,
225 uint8_t *rspbuf, uint8_t *rsplen);
226#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_SCA_UPDATE)
227int ble_ll_conn_req_peer_sca(const uint8_t *cmdbuf, uint8_t len,
228 uint8_t *rspbuf, uint8_t *rsplen);
229#endif
230#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_ENHANCED_CONN_UPDATE)
231int ble_ll_conn_hci_set_default_subrate(const uint8_t *cmdbuf, uint8_t len,
232 uint8_t *rspbuf, uint8_t *rsplen);
233int ble_ll_conn_hci_subrate_req(const uint8_t *cmdbuf, uint8_t len,
234 uint8_t *rspbuf, uint8_t *rsplen);
235#endif
236
237#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_PING)
238void ble_ll_conn_auth_pyld_timer_start(struct ble_ll_conn_sm *connsm);
239#else
240#define ble_ll_conn_auth_pyld_timer_start(x)
241#endif
242
243#if MYNEWT_VAL(BLE_LL_CFG_FEAT_CTRL_TO_HOST_FLOW_CONTROL)
244void ble_ll_conn_cth_flow_set_buffers(uint16_t num_buffers);
245bool ble_ll_conn_cth_flow_enable(bool enabled);
246void ble_ll_conn_cth_flow_process_cmd(const uint8_t *cmdbuf);
247#endif
248
249void ble_ll_conn_itvl_to_ticks(uint32_t itvl,
250 uint32_t *itvl_ticks, uint8_t *itvl_usecs);
251
252int ble_ll_hci_cmd_rx(uint8_t *cmd, void *arg);
253int ble_ll_hci_acl_rx(struct os_mbuf *om, void *arg);
254
255int ble_ll_conn_hci_le_rd_phy(const uint8_t *cmdbuf, uint8_t len,
256 uint8_t *rsp, uint8_t *rsplen);
257int ble_ll_conn_hci_le_set_phy(const uint8_t *cmdbuf, uint8_t len);
258int ble_ll_conn_phy_update_if_needed(struct ble_ll_conn_sm *connsm);
259#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
260int ble_ll_conn_hci_ext_create(const uint8_t *cmdbuf, uint8_t len);
261#endif
262
263#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_TRANSFER)
264int ble_ll_set_sync_transfer_params(const uint8_t *cmdbuf, uint8_t len,
265 uint8_t *rspbuf, uint8_t *rsplen);
266int ble_ll_set_default_sync_transfer_params(const uint8_t *cmdbuf, uint8_t len);
267#endif
268
269#if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED)
270void ble_ll_conn_css_set_next_slot(uint16_t slot_idx);
271uint16_t ble_ll_conn_css_get_next_slot(void);
272int ble_ll_conn_css_is_slot_busy(uint16_t slot_idx);
273int ble_ll_conn_css_move(struct ble_ll_conn_sm *connsm, uint16_t slot_idx);
274
275#endif
276
277#ifdef __cplusplus
278}
279#endif
280
281#endif /* H_BLE_LL_CONN_PRIV_ */
Definition os_mbuf.h:86