20#ifndef H_BLE_LL_CONN_PRIV_
21#define H_BLE_LL_CONN_PRIV_
23#include "../include/controller/ble_ll_conn.h"
24#include "../include/controller/ble_ll_hci.h"
34#define BLE_LL_CONN_SUPP_TIME_MIN (328)
35#define BLE_LL_CONN_SUPP_TIME_MAX (17040)
36#define BLE_LL_CONN_SUPP_TIME_MIN_UNCODED (328)
37#define BLE_LL_CONN_SUPP_TIME_MAX_UNCODED (2120)
38#define BLE_LL_CONN_SUPP_TIME_MIN_CODED (2704)
39#define BLE_LL_CONN_SUPP_TIME_MAX_CODED (17040)
40#define BLE_LL_CONN_SUPP_BYTES_MIN (27)
41#define BLE_LL_CONN_SUPP_BYTES_MAX (251)
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)
50#define BLE_LL_CONN_PERIPH_LATENCY_MAX (499)
53#define BLE_LL_CONN_MAX_CONN_HANDLE (0x0EFF)
56#define BLE_LL_CONN_REQ_ADVA_OFF (BLE_LL_PDU_HDR_LEN + BLE_DEV_ADDR_LEN)
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)
62#if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED)
63#define BLE_LL_CONN_CSS_NO_SLOT (UINT16_MAX)
67struct ble_ll_conn_global_params
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;
89extern struct ble_ll_conn_global_params g_ble_ll_conn_params;
91#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_TRANSFER)
92struct ble_ll_conn_sync_transfer_params
94 uint32_t sync_timeout_us;
98extern struct ble_ll_conn_sync_transfer_params g_ble_ll_conn_sync_transfer_params;
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;
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;
121struct ble_ll_conn_create_params {
123 uint32_t conn_itvl_ticks;
124 uint8_t conn_itvl_usecs;
125 uint16_t conn_latency;
126 uint16_t supervision_timeout;
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];
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;
142struct ble_ll_len_req;
146struct hci_create_conn
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;
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);
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);
175int ble_ll_conn_periph_start(uint8_t *rxbuf, uint8_t pat,
176 struct ble_mbuf_hdr *rxhdr,
bool force_csa2);
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);
191void ble_ll_disconn_comp_event_send(
struct ble_ll_conn_sm *connsm,
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,
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);
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);
237#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_PING)
238void ble_ll_conn_auth_pyld_timer_start(
struct ble_ll_conn_sm *connsm);
240#define ble_ll_conn_auth_pyld_timer_start(x)
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);
249void ble_ll_conn_itvl_to_ticks(uint32_t itvl,
250 uint32_t *itvl_ticks, uint8_t *itvl_usecs);
252int ble_ll_hci_cmd_rx(uint8_t *cmd,
void *arg);
253int ble_ll_hci_acl_rx(
struct os_mbuf *om,
void *arg);
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);
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);
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);