1 /***************************************************************************//**
2  * @brief Bluetooth Link Layer configuration API
3  *******************************************************************************
4  * # License
5  * <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
6  *******************************************************************************
7  *
8  * SPDX-License-Identifier: Zlib
9  *
10  * The licensor of this software is Silicon Laboratories Inc.
11  *
12  * This software is provided 'as-is', without any express or implied
13  * warranty. In no event will the authors be held liable for any damages
14  * arising from the use of this software.
15  *
16  * Permission is granted to anyone to use this software for any purpose,
17  * including commercial applications, and to alter it and redistribute it
18  * freely, subject to the following restrictions:
19  *
20  * 1. The origin of this software must not be misrepresented; you must not
21  *    claim that you wrote the original software. If you use this software
22  *    in a product, an acknowledgment in the product documentation would be
23  *    appreciated but is not required.
24  * 2. Altered source versions must be plainly marked as such, and must not be
25  *    misrepresented as being the original software.
26  * 3. This notice may not be removed or altered from any source distribution.
27  *
28  ******************************************************************************/
29 
30 #ifndef _SL_BTCTRL_LINKLAYER_H_
31 #define _SL_BTCTRL_LINKLAYER_H_
32 #include "sl_status.h"
33 #include <stdint.h>
34 
35 void sl_bt_controller_init(void);
36 
37 void sl_bt_controller_deinit(void);
38 
39 void sl_btctrl_init(void);
40 
41 /**
42  * Allocate memory buffers for controller
43  *
44  * @param memsize size of memory to allocate
45  * @returns number of memory buffers allocated
46  */
47 uint32_t sl_btctrl_init_mem(uint32_t memsize);
48 
49 /**
50  *  Configures how many maximum sized ACL data packets
51  *  can the controller store.
52  */
53 void sl_btctrl_configure_le_buffer_size(uint8_t count);
54 
55 /**
56  * Release all memory allocated by controller
57  */
58 void sli_btctrl_deinit_mem(void);
59 
60 void sli_btctrl_set_interrupt_priorities();
61 
62 sl_status_t sl_btctrl_init_ll(void);
63 
64 void sli_btctrl_set_address(uint8_t *address);
65 
66 //Initialize memory objects used by LinkLayer
67 //In future these should be configured individually
68 sl_status_t sl_btctrl_init_basic(uint8_t connections, uint8_t adv_sets, uint8_t whitelist);
69 
70 void sli_btctrl_events_init(void);
71 
72 enum sl_btctrl_channelmap_flags{
73   SL_BTCTRL_CHANNELMAP_FLAG_ACTIVE_ADAPTIVITY = 0x01,
74   SL_BTCTRL_CHANNELMAP_FLAG_PASSIVE_ADAPTIVITY= 0x02,
75 };
76 
77 /**
78  * Initialize and enable adaptive frequency hopping
79  */
80 sl_status_t sl_btctrl_init_afh(uint32_t flags);
81 
82 /**
83  * Enable high power use under appropriate conditions
84  */
85 void sl_btctrl_init_highpower(void);
86 
87 /**
88  * @brief Initilize periodic advertiser
89  */
90 void sl_btctrl_init_periodic_adv();
91 
92 /**
93  * @brief Initilize periodic advertiser
94  */
95 void sl_btctrl_init_periodic_scan();
96 
97 /**
98  * Configuration for Periodic Advertising with Responses.
99  */
100 struct sl_btctrl_pawr_advertiser_config {
101   /**
102    * Number of advertising sets supporting PAwR.
103    * If set to zero, previously allocated PAwR sets are only freed. */
104   uint8_t max_pawr_sets;
105   /**
106    * Hint to the controller what will be the maximum advertised data length.
107    * The value does not prevent using longer advertising data. Value zero means
108    * that maximum data length can expected to be up to the length of Periodic
109    * Advertising Delay. */
110   uint8_t max_advertised_data_length_hint;
111   /**
112    * The number of subevent advertising packets requested from the host
113    * at once. */
114   uint8_t subevent_data_request_count;
115   /**
116    * How many subevents before airing a subevent its data is requested from
117    * the host. */
118   uint8_t subevent_data_request_advance;
119 };
120 
121 /**
122  * Configuration of synchronizer for Periodic Advertising with Responses.
123  */
124 struct sl_btctrl_pawr_synchronizer_config {
125   /**
126    * Number of advertising sets supporting PArR.
127    * If set to zero, previously allocated PArR sets are only freed. */
128   uint8_t max_pawr_sets;
129 };
130 
131 /**
132  * @brief Enable and initialize support for the PAwR advertiser.
133  * @param[in] pawr_adv_config PAwR advertiser configuration.
134  * @return SL_STATUS_OK, or an appropriate error code. */
135 sl_status_t sl_btctrl_pawr_advertiser_configure(struct sl_btctrl_pawr_advertiser_config *pawr_adv_config);
136 
137 /**
138  * @brief Enable and initialize support for PAwR sync/receiver.
139  * @param[in] pawr_sync_config PAwR synchronizer configuration.
140  * @return SL_STATUS_OK, or an appropriate error code. */
141 sl_status_t sl_btctrl_pawr_synchronizer_configure(struct sl_btctrl_pawr_synchronizer_config *pawr_sync_config);
142 
143 /**
144  * @brief Allocate memory for synchronized scanners
145  *
146  * @param num_scan Number of Periodic Scanners Allowed
147  * @return SL_STATUS_OK if allocation was succesfull, failure reason otherwise
148  */
149 sl_status_t sl_btctrl_alloc_periodic_scan(uint8_t num_scan);
150 
151 /**
152  * @brief Allocate memory for periodic advertisers
153  *
154  * @param num_adv Number of advertisers to allocate
155  */
156 sl_status_t sl_btctrl_alloc_periodic_adv(uint8_t num_adv);
157 
158 /**
159  * Call to import the conn scheduler state variables in the binary
160  */
161 void sli_btctrl_enable_conn_scheduler_state(void);
162 
163 /**
164  * @brief Set maximum number of advertisement reports allowed to be queued
165  *
166  * @param num_adv Maximum number of advertisement reports allowed to be queued
167  */
168 void sl_btctrl_configure_max_queued_adv_reports(uint8_t num_reports);
169 
170 /**
171  * Call to enable the even connection scheduling algorithm.
172  * This function should be called before link layer initialization.
173  */
174 void sl_btctrl_enable_even_connsch();
175 
176 /**
177  * Call to enable the PAwR aware connection scheduling algorithm.
178  * This function should be called before link layer initialization.
179  */
180 void sl_btctrl_enable_pawr_connsch();
181 
182 /**
183  * Call to enable the legacy connection scheduling algorithm.
184  * This function should be called before link layer initialization.
185  */
186 void sl_btctrl_enable_legacy_connsch();
187 
188 /**
189  * Call to enable connection statistics collection.
190  */
191 void sl_btctrl_init_conn_statistics(void);
192 
193 /**
194  * Call to initialize multiprotocol
195  * in bluetooth controller
196  */
197 void sl_btctrl_init_multiprotocol();
198 
199 /**
200  * Link with symbol to enable radio watchdog
201  */
202 void sl_btctrl_enable_radio_watchdog();
203 
204 /**
205  * Initialize CTE receiver
206  */
207 sl_status_t sl_btctrl_init_cte_receiver();
208 
209 /**
210  * Initialize CTE transmitter
211  */
212 sl_status_t sl_btctrl_init_cte_transmitter();
213 
214 /**
215  * Initialize both CTE receiver and transmitter
216  *
217  * Note: This is for backward compatibility. It is recommend to
218  * use sl_btctrl_init_cte_receiver and sl_btctrl_init_cte_transmitter
219  * functions instead.
220  */
221 sl_status_t sl_btctrl_init_cte();
222 
223 /**
224  * Initialize Channel Sounding
225  */
226 struct sl_btctrl_cs_config {
227   /** number of channel sounding configurations per connection */
228   uint8_t configs_per_connection;
229   /** number of simultaneous channel sounding procedures */
230   uint8_t procedures;
231 };
232 
233 sl_status_t sl_btctrl_init_cs(const struct sl_btctrl_cs_config *config);
234 
235 /**
236  * Check if event bitmap indicates pending events
237  * @return bool pending events
238  */
239 bool sli_pending_btctrl_events(void);
240 
241 /**
242  * Disable the support for Coded and Simulscan PHYs.
243  */
244 void sl_btctrl_disable_coded_phy(void);
245 
246 /**
247  * Disable the support for 2M PHY.
248  */
249 void sl_btctrl_disable_2m_phy(void);
250 
251 /**
252  * Initialize adv component
253  */
254 void sl_btctrl_init_adv(void);
255 
256 void sl_btctrl_init_conn(void);
257 
258 void sl_btctrl_init_subrate(void);
259 
260 sl_status_t sl_btctrl_allocate_conn_subrate_memory(uint8_t connectionsCount);
261 
262 void sl_btctrl_init_phy(void);
263 
264 void sl_btctrl_init_adv_ext(void);
265 
266 void sl_btctrl_init_privacy(void);
267 
268 sl_status_t sl_btctrl_allocate_resolving_list_memory(uint8_t resolvingListSize);
269 
270 /**
271  * @brief Initialize extended scanner state
272  *
273  */
274 void sl_btctrl_init_scan_ext(void);
275 
276 void sl_btctrl_init_scan(void);
277 
278 /**
279  * @brief return true if controller is initialized
280  *
281  */
282 bool sl_btctrl_is_initialized();
283 
284 /**
285  * @brief Sets PAST initiator feature bit,
286  * and links in PAST sender and ll_adv_sync symbols to the project.
287  */
288 void sl_btctrl_init_past_local_sync_transfer(void);
289 
290 /**
291  * @brief Sets PAST initiator feature bit,
292  * and links in PAST sender, ll_scan_sync and ll_scan_sync_registry symbols to the project.
293  */
294 void sl_btctrl_init_past_remote_sync_transfer(void);
295 
296 /**
297  * @brief Sets PAST receiver feature bit,
298  * and links in PAST receiver, ll_scan_sync and ll_scan_sync_registry symbols to the project.
299  */
300 void sl_btctrl_init_past_receiver(void);
301 
302 /**
303  * @brief Configure how often to send the Number Of Completed Packets HCI event.
304  * @param[in] packets When the controller has transmitted this number of ACL data packets it will send
305  * the Number Of Completed Packets HCI event to the host.
306  * @param[in] events When this number of connection events have passed and the controller did not yet report
307  * all the transmitted packets, then it will send the Number Of Completed Packets HCI event to the host.
308  */
309 void sl_btctrl_configure_completed_packets_reporting(uint8_t packets, uint8_t events);
310 
311 #endif
312