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