1 /*
2  * Copyright (c) 2016-2021 Nordic Semiconductor ASA
3  * Copyright (c) 2016 Vinayak Kariappa Chettimada
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 int ll_init(struct k_sem *sem_rx);
9 int ll_deinit(void);
10 void ll_reset(void);
11 
12 uint8_t ll_set_host_feature(uint8_t bit_number, uint8_t bit_value);
13 uint64_t ll_feat_get(void);
14 
15 uint8_t ll_addr_set(uint8_t addr_type, uint8_t const *const p_bdaddr);
16 uint8_t *ll_addr_get(uint8_t addr_type);
17 uint8_t *ll_addr_read(uint8_t addr_type, uint8_t *const bdaddr);
18 
19 #if defined(CONFIG_BT_CTLR_HCI_ADV_HANDLE_MAPPING)
20 uint8_t ll_adv_set_by_hci_handle_get(uint8_t hci_handle, uint8_t *handle);
21 uint8_t ll_adv_set_by_hci_handle_get_or_new(uint8_t hci_handle,
22 					    uint8_t *handle);
23 uint8_t ll_adv_set_hci_handle_get(uint8_t handle);
24 uint8_t ll_adv_iso_by_hci_handle_get(uint8_t hci_handle, uint8_t *handle);
25 uint8_t ll_adv_iso_by_hci_handle_new(uint8_t hci_handle, uint8_t *handle);
26 #else
ll_adv_set_by_hci_handle_get(uint8_t hci_handle,uint8_t * handle)27 static inline uint8_t ll_adv_set_by_hci_handle_get(uint8_t hci_handle,
28 						   uint8_t *handle)
29 {
30 	*handle = hci_handle;
31 	return 0;
32 }
33 
ll_adv_set_by_hci_handle_get_or_new(uint8_t hci_handle,uint8_t * handle)34 static inline uint8_t ll_adv_set_by_hci_handle_get_or_new(uint8_t hci_handle,
35 							  uint8_t *handle)
36 {
37 	*handle = hci_handle;
38 	return 0;
39 }
40 
ll_adv_set_hci_handle_get(uint8_t handle)41 static inline uint8_t ll_adv_set_hci_handle_get(uint8_t handle)
42 {
43 	return handle;
44 }
45 
ll_adv_iso_by_hci_handle_get(uint8_t hci_handle,uint8_t * handle)46 static inline uint8_t ll_adv_iso_by_hci_handle_get(uint8_t hci_handle,
47 						   uint8_t *handle)
48 {
49 	*handle = hci_handle;
50 	return 0;
51 }
52 
ll_adv_iso_by_hci_handle_new(uint8_t hci_handle,uint8_t * handle)53 static inline uint8_t ll_adv_iso_by_hci_handle_new(uint8_t hci_handle,
54 						   uint8_t *handle)
55 {
56 	*handle = hci_handle;
57 	return 0;
58 }
59 #endif
60 
61 #if defined(CONFIG_BT_CTLR_ADV_EXT)
62 uint8_t ll_adv_params_set(uint8_t handle, uint16_t evt_prop, uint32_t interval,
63 		       uint8_t adv_type, uint8_t own_addr_type,
64 		       uint8_t direct_addr_type, uint8_t const *const direct_addr,
65 		       uint8_t chan_map, uint8_t filter_policy,
66 		       uint8_t *const tx_pwr, uint8_t phy_p, uint8_t skip,
67 		       uint8_t phy_s, uint8_t sid, uint8_t sreq);
68 uint8_t ll_adv_data_set(uint8_t handle, uint8_t len,
69 			uint8_t const *const p_data);
70 uint8_t ll_adv_scan_rsp_set(uint8_t handle, uint8_t len,
71 			    uint8_t const *const p_data);
72 #else /* !CONFIG_BT_CTLR_ADV_EXT */
73 uint8_t ll_adv_params_set(uint16_t interval, uint8_t adv_type,
74 		       uint8_t own_addr_type, uint8_t direct_addr_type,
75 		       uint8_t const *const direct_addr, uint8_t chan_map,
76 		       uint8_t filter_policy);
77 uint8_t ll_adv_data_set(uint8_t len, uint8_t const *const p_data);
78 uint8_t ll_adv_scan_rsp_set(uint8_t len, uint8_t const *const p_data);
79 #endif /* !CONFIG_BT_CTLR_ADV_EXT */
80 
81 uint8_t ll_adv_aux_random_addr_set(uint8_t handle, uint8_t const *const addr);
82 uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref,
83 			       uint8_t len, uint8_t const *const data);
84 uint8_t ll_adv_aux_sr_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref,
85 			       uint8_t len, uint8_t const *const data);
86 uint16_t ll_adv_aux_max_data_length_get(void);
87 uint8_t ll_adv_aux_set_count_get(void);
88 uint8_t ll_adv_aux_set_remove(uint8_t handle);
89 uint8_t ll_adv_aux_set_clear(void);
90 uint8_t ll_adv_sync_param_set(uint8_t handle, uint16_t interval,
91 			      uint16_t flags);
92 uint8_t ll_adv_sync_ad_data_set(uint8_t handle, uint8_t op, uint8_t len,
93 				uint8_t const *const data);
94 uint8_t ll_adv_sync_enable(uint8_t handle, uint8_t enable);
95 
96 #if defined(CONFIG_BT_CTLR_ADV_EXT) || defined(CONFIG_BT_HCI_MESH_EXT)
97 #if defined(CONFIG_BT_HCI_MESH_EXT)
98 uint8_t ll_adv_enable(uint8_t handle, uint8_t enable,
99 		   uint8_t at_anchor, uint32_t ticks_anchor, uint8_t retry,
100 		   uint8_t scan_window, uint8_t scan_delay);
101 #else /* !CONFIG_BT_HCI_MESH_EXT */
102 uint8_t ll_adv_enable(uint8_t handle, uint8_t enable,
103 		   uint16_t duration, uint8_t max_ext_adv_evts);
104 #endif /* !CONFIG_BT_HCI_MESH_EXT */
105 #else /* !CONFIG_BT_CTLR_ADV_EXT || !CONFIG_BT_HCI_MESH_EXT */
106 uint8_t ll_adv_enable(uint8_t enable);
107 #endif /* !CONFIG_BT_CTLR_ADV_EXT || !CONFIG_BT_HCI_MESH_EXT */
108 
109 uint8_t ll_adv_disable_all(void);
110 
111 uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis,
112 		      uint32_t sdu_interval, uint16_t max_sdu,
113 		      uint16_t max_latency, uint8_t rtn, uint8_t phy,
114 		      uint8_t packing, uint8_t framing, uint8_t encryption,
115 		      uint8_t *bcode);
116 uint8_t ll_big_test_create(uint8_t big_handle, uint8_t adv_handle,
117 			   uint8_t num_bis, uint32_t sdu_interval,
118 			   uint16_t iso_interval, uint8_t nse, uint16_t max_sdu,
119 			   uint16_t max_pdu, uint8_t phy, uint8_t packing,
120 			   uint8_t framing, uint8_t bn, uint8_t irc,
121 			   uint8_t pto, uint8_t encryption, uint8_t *bcode);
122 uint8_t ll_big_terminate(uint8_t big_handle, uint8_t reason);
123 
124 uint8_t ll_scan_params_set(uint8_t type, uint16_t interval, uint16_t window,
125 		uint8_t own_addr_type, uint8_t filter_policy);
126 #if defined(CONFIG_BT_CTLR_ADV_EXT)
127 uint8_t ll_scan_enable(uint8_t enable, uint16_t duration, uint16_t period);
128 #else /* !CONFIG_BT_CTLR_ADV_EXT */
129 uint8_t ll_scan_enable(uint8_t enable);
130 #endif /* !CONFIG_BT_CTLR_ADV_EXT */
131 
132 uint8_t ll_sync_create(uint8_t options, uint8_t sid, uint8_t adv_addr_type,
133 		       uint8_t *adv_addr, uint16_t skip,
134 		       uint16_t sync_timeout, uint8_t sync_cte_type);
135 uint8_t ll_sync_create_cancel(void **rx);
136 uint8_t ll_sync_terminate(uint16_t handle);
137 uint8_t ll_sync_recv_enable(uint16_t handle, uint8_t enable);
138 uint8_t ll_big_sync_create(uint8_t big_handle, uint16_t sync_handle,
139 			   uint8_t encryption, uint8_t *bcode, uint8_t mse,
140 			   uint16_t sync_timeout, uint8_t num_bis,
141 			   uint8_t *bis);
142 uint8_t ll_big_sync_terminate(uint8_t big_handle, void **rx);
143 
144 uint8_t ll_cig_parameters_open(uint8_t cig_id,
145 			       uint32_t c_interval, uint32_t p_interval,
146 			       uint8_t sca, uint8_t packing, uint8_t framing,
147 			       uint16_t c_latency, uint16_t p_latency,
148 			       uint8_t num_cis);
149 uint8_t ll_cis_parameters_set(uint8_t cis_id,
150 			      uint16_t c_sdu, uint16_t p_sdu,
151 			      uint8_t c_phy, uint8_t p_phy,
152 			      uint8_t c_rtn, uint8_t p_rtn);
153 uint8_t ll_cig_parameters_commit(uint8_t cig_id, uint16_t *handles);
154 uint8_t ll_cig_parameters_test_open(uint8_t cig_id,
155 				    uint32_t c_interval,
156 				    uint32_t p_interval,
157 				    uint8_t c_ft,
158 				    uint8_t p_ft,
159 				    uint16_t iso_interval,
160 				    uint8_t sca,
161 				    uint8_t packing,
162 				    uint8_t framing,
163 				    uint8_t num_cis);
164 uint8_t ll_cis_parameters_test_set(uint8_t cis_id, uint8_t nse,
165 				   uint16_t c_sdu, uint16_t p_sdu,
166 				   uint16_t c_pdu, uint16_t p_pdu,
167 				   uint8_t c_phy, uint8_t p_phy,
168 				   uint8_t c_bn, uint8_t p_bn);
169 /* Must be implemented by vendor if vendor-specific data path is supported */
170 uint8_t ll_configure_data_path(uint8_t data_path_dir,
171 			       uint8_t data_path_id,
172 			       uint8_t vs_config_len,
173 			       uint8_t  *vs_config);
174 uint8_t ll_read_iso_tx_sync(uint16_t handle, uint16_t *seq,
175 			    uint32_t *timestamp, uint32_t *offset);
176 uint8_t ll_read_iso_link_quality(uint16_t  handle,
177 				 uint32_t *tx_unacked_packets,
178 				 uint32_t *tx_flushed_packets,
179 				 uint32_t *tx_last_subevent_packets,
180 				 uint32_t *retransmitted_packets,
181 				 uint32_t *crc_error_packets,
182 				 uint32_t *rx_unreceived_packets,
183 				 uint32_t *duplicate_packets);
184 uint8_t ll_setup_iso_path(uint16_t handle, uint8_t path_dir, uint8_t path_id,
185 			  uint8_t coding_format, uint16_t company_id,
186 			  uint16_t vs_codec_id, uint32_t controller_delay,
187 			  uint8_t codec_config_len, uint8_t *codec_config);
188 uint8_t ll_remove_iso_path(uint16_t handle, uint8_t path_dir);
189 uint8_t ll_iso_receive_test(uint16_t handle, uint8_t payload_type);
190 uint8_t ll_iso_transmit_test(uint16_t handle, uint8_t payload_type);
191 uint8_t ll_iso_test_end(uint16_t handle, uint32_t *received_cnt,
192 			uint32_t *missed_cnt, uint32_t *failed_cnt);
193 uint8_t ll_iso_read_test_counters(uint16_t handle, uint32_t *received_cnt,
194 				  uint32_t *missed_cnt,
195 				  uint32_t *failed_cnt);
196 
197 uint8_t ll_cig_remove(uint8_t cig_id);
198 
199 uint8_t ll_cis_create_check(uint16_t cis_handle, uint16_t acl_handle);
200 void ll_cis_create(uint16_t cis_handle, uint16_t acl_handle);
201 
202 uint8_t ll_cis_accept(uint16_t handle);
203 uint8_t ll_cis_reject(uint16_t handle, uint8_t reason);
204 
205 uint8_t ll_fal_size_get(void);
206 uint8_t ll_fal_clear(void);
207 uint8_t ll_fal_add(bt_addr_le_t *addr);
208 uint8_t ll_fal_remove(bt_addr_le_t *addr);
209 
210 uint8_t ll_pal_size_get(void);
211 uint8_t ll_pal_clear(void);
212 uint8_t ll_pal_add(const bt_addr_le_t *const addr, const uint8_t sid);
213 uint8_t ll_pal_remove(const bt_addr_le_t *const addr, const uint8_t sid);
214 
215 void ll_rl_id_addr_get(uint8_t rl_idx, uint8_t *id_addr_type, uint8_t *id_addr);
216 uint8_t ll_rl_size_get(void);
217 uint8_t ll_rl_clear(void);
218 uint8_t ll_rl_add(bt_addr_le_t *id_addr, const uint8_t pirk[16],
219 		const uint8_t lirk[16]);
220 uint8_t ll_rl_remove(bt_addr_le_t *id_addr);
221 void ll_rl_crpa_set(uint8_t id_addr_type, uint8_t *id_addr, uint8_t rl_idx, uint8_t *crpa);
222 uint8_t ll_rl_crpa_get(bt_addr_le_t *id_addr, bt_addr_t *crpa);
223 uint8_t ll_rl_lrpa_get(bt_addr_le_t *id_addr, bt_addr_t *lrpa);
224 uint8_t ll_rl_enable(uint8_t enable);
225 void  ll_rl_timeout_set(uint16_t timeout);
226 uint8_t ll_priv_mode_set(bt_addr_le_t *id_addr, uint8_t mode);
227 
228 #if defined(CONFIG_BT_CTLR_ADV_EXT)
229 uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window,
230 			  uint8_t filter_policy, uint8_t peer_addr_type,
231 			  uint8_t const *const peer_addr, uint8_t own_addr_type,
232 			  uint16_t interval, uint16_t latency, uint16_t timeout,
233 			  uint8_t phy);
234 uint8_t ll_connect_enable(uint8_t is_coded_included);
235 #else /* !CONFIG_BT_CTLR_ADV_EXT */
236 uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window,
237 			  uint8_t filter_policy, uint8_t peer_addr_type,
238 			  uint8_t const *const peer_addr, uint8_t own_addr_type,
239 			  uint16_t interval, uint16_t latency, uint16_t timeout);
240 #endif /* !CONFIG_BT_CTLR_ADV_EXT */
241 uint8_t ll_connect_disable(void **rx);
242 uint8_t ll_conn_update(uint16_t handle, uint8_t cmd, uint8_t status, uint16_t interval_min,
243 		    uint16_t interval_max, uint16_t latency, uint16_t timeout, uint16_t *offset);
244 uint8_t ll_chm_update(uint8_t const *const chm);
245 uint8_t ll_chm_get(uint16_t handle, uint8_t *const chm);
246 uint8_t ll_enc_req_send(uint16_t handle, uint8_t const *const rand_num, uint8_t const *const ediv,
247 			uint8_t const *const ltk);
248 uint8_t ll_start_enc_req_send(uint16_t handle, uint8_t err_code,
249 			   uint8_t const *const ltk);
250 uint8_t ll_req_peer_sca(uint16_t handle);
251 uint8_t ll_feature_req_send(uint16_t handle);
252 uint8_t ll_version_ind_send(uint16_t handle);
253 uint8_t ll_terminate_ind_send(uint16_t handle, uint8_t reason);
254 uint8_t ll_rssi_get(uint16_t handle, uint8_t *const rssi);
255 uint8_t ll_tx_pwr_lvl_get(uint8_t handle_type,
256 		       uint16_t handle, uint8_t type, int8_t *const tx_pwr_lvl);
257 void ll_tx_pwr_get(int8_t *const min, int8_t *const max);
258 uint8_t ll_tx_pwr_lvl_set(uint8_t handle_type, uint16_t handle,
259 			  int8_t *const tx_pwr_lvl);
260 
261 uint8_t ll_apto_get(uint16_t handle, uint16_t *const apto);
262 uint8_t ll_apto_set(uint16_t handle, uint16_t apto);
263 
264 uint32_t ll_length_req_send(uint16_t handle, uint16_t tx_octets, uint16_t tx_time);
265 void ll_length_default_get(uint16_t *const max_tx_octets,
266 			   uint16_t *const max_tx_time);
267 uint32_t ll_length_default_set(uint16_t max_tx_octets, uint16_t max_tx_time);
268 void ll_length_max_get(uint16_t *const max_tx_octets,
269 		       uint16_t *const max_tx_time,
270 		       uint16_t *const max_rx_octets,
271 		       uint16_t *const max_rx_time);
272 
273 uint8_t ll_phy_get(uint16_t handle, uint8_t *const tx, uint8_t *const rx);
274 uint8_t ll_phy_default_set(uint8_t tx, uint8_t rx);
275 uint8_t ll_phy_req_send(uint16_t handle, uint8_t tx, uint8_t flags, uint8_t rx);
276 
277 uint8_t ll_set_min_used_chans(uint16_t handle, uint8_t const phys,
278 		     uint8_t const min_used_chans);
279 
280 /* Direction Finding */
281 /* Sets CTE transmission parameters for periodic advertising */
282 uint8_t ll_df_set_cl_cte_tx_params(uint8_t adv_handle, uint8_t cte_len,
283 				   uint8_t cte_type, uint8_t cte_count,
284 				   uint8_t num_ant_ids, uint8_t *ant_ids);
285 /* Enables or disables CTE TX for periodic advertising */
286 uint8_t ll_df_set_cl_cte_tx_enable(uint8_t adv_handle, uint8_t cte_enable);
287 /* Provides information about antennae switching and sampling settings */
288 uint8_t ll_df_set_conn_cte_tx_params(uint16_t handle, uint8_t cte_types,
289 				     uint8_t switching_patterns_len, const uint8_t *ant_id);
290 /* Enables or disables CTE sampling in direction fingin connected mode. */
291 uint8_t ll_df_set_conn_cte_rx_params(uint16_t handle, uint8_t sampling_enable,
292 				     uint8_t slot_durations, uint8_t switch_pattern_len,
293 				     const uint8_t *ant_ids);
294 /* Enables or disables CTE request control procedure in direction fingin connected mode. */
295 uint8_t ll_df_set_conn_cte_req_enable(uint16_t handle, uint8_t enable,
296 				      uint16_t cte_request_interval, uint8_t requested_cte_length,
297 				      uint8_t requested_cte_type);
298 /* Enables or disables CTE response control procedure in direction fingin connected mode. */
299 uint8_t ll_df_set_conn_cte_rsp_enable(uint16_t handle, uint8_t enable);
300 /* Enables or disables CTE sampling in periodic advertising scan */
301 uint8_t ll_df_set_cl_iq_sampling_enable(uint16_t handle,
302 					uint8_t sampling_enable,
303 					uint8_t slot_durations,
304 					uint8_t max_cte_count,
305 					uint8_t switch_pattern_len,
306 					uint8_t *ant_ids);
307 /* Sets CTE transmission parameters for a connection */
308 void ll_df_read_ant_inf(uint8_t *switch_sample_rates,
309 			uint8_t *num_ant,
310 			uint8_t *max_switch_pattern_len,
311 			uint8_t *max_cte_len);
312 
313 /* Downstream - Data */
314 void *ll_tx_mem_acquire(void);
315 void ll_tx_mem_release(void *node_tx);
316 int ll_tx_mem_enqueue(uint16_t handle, void *node_tx);
317 
318 /* Upstream - Num. Completes, Events and Data */
319 uint8_t ll_rx_get(void **node_rx, uint16_t *handle);
320 void ll_rx_dequeue(void);
321 void ll_rx_mem_release(void **node_rx);
322 void ll_iso_rx_mem_release(void **node_rx);
323 
324 /* Downstream - ISO Data */
325 void *ll_iso_tx_mem_acquire(void);
326 void ll_iso_tx_mem_release(void *tx);
327 int ll_iso_tx_mem_enqueue(uint16_t handle, void *tx, void *link);
328 void ll_iso_link_tx_release(void *link);
329 
330 uint8_t ll_conn_iso_accept_timeout_get(uint16_t *timeout);
331 uint8_t ll_conn_iso_accept_timeout_set(uint16_t timeout);
332 
333 /* External co-operation */
334 void ll_timeslice_ticker_id_get(uint8_t * const instance_index,
335 				uint8_t * const ticker_id);
336 void ll_coex_ticker_id_get(uint8_t * const instance_index,
337 				uint8_t * const ticker_id);
338 void ll_radio_state_abort(void);
339 uint32_t ll_radio_state_is_idle(void);
340