• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 The Android Open Source Project
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <cstdint>
19 
20 #include "stack/btm/btm_int_types.h"
21 #include "stack/include/acl_api_types.h"
22 #include "stack/include/bt_types.h"
23 #include "stack/include/btm_status.h"
24 #include "stack/include/hci_error_code.h"
25 #include "types/raw_address.h"
26 
27 // Note: From stack/include/btm_api.h
28 
29 /*****************************************************************************
30  *  ACL CHANNEL MANAGEMENT FUNCTIONS
31  ****************************************************************************/
32 bool BTM_is_sniff_allowed_for(const RawAddress& peer_addr);
33 
34 void BTM_unblock_sniff_mode_for(const RawAddress& peer_addr);
35 void BTM_block_sniff_mode_for(const RawAddress& peer_addr);
36 void BTM_unblock_role_switch_for(const RawAddress& peer_addr);
37 void BTM_block_role_switch_for(const RawAddress& peer_addr);
38 
39 void BTM_default_unblock_role_switch();
40 void BTM_default_block_role_switch();
41 
42 void BTM_acl_after_controller_started(const controller_t* controller);
43 
44 /*******************************************************************************
45  *
46  * Function         BTM_SetLinkSuperTout
47  *
48  * Description      Create and send HCI "Write Link Supervision Timeout" command
49  *
50  * Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
51  *
52  ******************************************************************************/
53 tBTM_STATUS BTM_SetLinkSuperTout(const RawAddress& remote_bda,
54                                  uint16_t timeout);
55 /*******************************************************************************
56  *
57  * Function         BTM_GetLinkSuperTout
58  *
59  * Description      Read the link supervision timeout value of the connection
60  *
61  * Returns          status of the operation
62  *
63  ******************************************************************************/
64 tBTM_STATUS BTM_GetLinkSuperTout(const RawAddress& remote_bda,
65                                  uint16_t* p_timeout);
66 
67 /*******************************************************************************
68  *
69  * Function         BTM_IsAclConnectionUp
70  *
71  * Description      This function is called to check if an ACL connection exists
72  *                  to a specific remote BD Address.  The second version ensures
73  *                  the hci handle is valid (Unsure if needed)
74  *
75  * Returns          true if connection is up, else false.
76  *
77  ******************************************************************************/
78 bool BTM_IsAclConnectionUp(const RawAddress& remote_bda,
79                            tBT_TRANSPORT transport);
80 
81 bool BTM_IsAclConnectionUpAndHandleValid(const RawAddress& remote_bda,
82                                          tBT_TRANSPORT transport);
83 
84 bool BTM_IsAclConnectionUpFromHandle(uint16_t hci_handle);
85 
86 /*******************************************************************************
87  *
88  * Function         BTM_GetRole
89  *
90  * Description      This function is called to get the role of the local device
91  *                  for the ACL connection with the specified remote device
92  *
93  * Returns          BTM_SUCCESS if connection exists.
94  *                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
95  *
96  ******************************************************************************/
97 tBTM_STATUS BTM_GetRole(const RawAddress& remote_bd_addr, tHCI_ROLE* p_role);
98 
99 /*******************************************************************************
100  *
101  * Function         BTM_SwitchRoleToCentral
102  *
103  * Description      This function is called to switch role between central and
104  *                  peripheral.  If role is already set it will do nothing.
105  *
106  * Returns          BTM_SUCCESS if already in specified role.
107  *                  BTM_CMD_STARTED if command issued to controller.
108  *                  BTM_NO_RESOURCES if memory couldn't be allocated to issue
109  *                                   the command
110  *                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
111  *                  BTM_MODE_UNSUPPORTED if the local device does not support
112  *                                       role switching
113  *
114  ******************************************************************************/
115 tBTM_STATUS BTM_SwitchRoleToCentral(const RawAddress& remote_bd_addr);
116 
117 /*******************************************************************************
118  *
119  * Function         BTM_ReadRSSI
120  *
121  * Description      This function is called to read the link policy settings.
122  *                  The address of link policy results are returned in the
123  *                  callback. (tBTM_RSSI_RESULT)
124  *
125  * Returns          BTM_CMD_STARTED if command issued to controller.
126  *                  BTM_NO_RESOURCES if memory couldn't be allocated to issue
127  *                                   the command
128  *                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
129  *                  BTM_BUSY if command is already in progress
130  *
131  ******************************************************************************/
132 tBTM_STATUS BTM_ReadRSSI(const RawAddress& remote_bda, tBTM_CMPL_CB* p_cb);
133 
134 /*******************************************************************************
135  *
136  * Function         BTM_ReadFailedContactCounter
137  *
138  * Description      This function is called to read the failed contact counter.
139  *                  The result is returned in the callback.
140  *                  (tBTM_FAILED_CONTACT_COUNTER_RESULT)
141  *
142  * Returns          BTM_CMD_STARTED if command issued to controller.
143  *                  BTM_NO_RESOURCES if memory couldn't be allocated to issue
144  *                                   the command
145  *                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
146  *                  BTM_BUSY if command is already in progress
147  *
148  ******************************************************************************/
149 tBTM_STATUS BTM_ReadFailedContactCounter(const RawAddress& remote_bda,
150                                          tBTM_CMPL_CB* p_cb);
151 
152 /*******************************************************************************
153  *
154  * Function         BTM_ReadTxPower
155  *
156  * Description      This function is called to read the current connection
157  *                  TX power of the connection. The TX power level results
158  *                  are returned in the callback.
159  *                  (tBTM_RSSI_RESULT)
160  *
161  * Returns          BTM_CMD_STARTED if command issued to controller.
162  *                  BTM_NO_RESOURCES if memory couldn't be allocated to issue
163  *                                   the command
164  *                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
165  *                  BTM_BUSY if command is already in progress
166  *
167  ******************************************************************************/
168 tBTM_STATUS BTM_ReadTxPower(const RawAddress& remote_bda,
169                             tBT_TRANSPORT transport, tBTM_CMPL_CB* p_cb);
170 
171 /*******************************************************************************
172  *
173  * Function         BTM_GetNumAclLinks
174  *
175  * Description      This function is called to count the number of
176  *                  ACL links that are active.
177  *
178  * Returns          uint16_t Number of active ACL links
179  *
180  ******************************************************************************/
181 uint16_t BTM_GetNumAclLinks(void);
182 
183 void btm_set_packet_types_from_address(const RawAddress& bda,
184                                        uint16_t pkt_types);
185 
186 #define BLE_RESOLVE_ADDR_MASK 0xc0
187 #define BLE_RESOLVE_ADDR_MSB 0x40
188 
189 bool BTM_BLE_IS_RESOLVE_BDA(const RawAddress& x);
190 
191 bool acl_refresh_remote_address(const RawAddress& identity_address,
192                                 tBLE_ADDR_TYPE identity_address_type,
193                                 const RawAddress& remote_bda, uint8_t rra_type,
194                                 const RawAddress& rpa);
195 
196 void btm_establish_continue_from_address(const RawAddress& remote_bda,
197                                          tBT_TRANSPORT transport);
198 
199 bool acl_peer_supports_ble_connection_parameters_request(
200     const RawAddress& remote_bda);
201 
202 bool sco_peer_supports_esco_2m_phy(const RawAddress& remote_bda);
203 bool sco_peer_supports_esco_3m_phy(const RawAddress& remote_bda);
204 
205 bool acl_peer_supports_ble_packet_extension(uint16_t hci_handle);
206 bool acl_peer_supports_ble_2m_phy(uint16_t hci_handle);
207 bool acl_peer_supports_ble_coded_phy(uint16_t hci_handle);
208 
209 bool acl_is_switch_role_idle(const RawAddress& bd_addr,
210                              tBT_TRANSPORT transport);
211 
212 bool acl_peer_supports_ble_packet_extension(uint16_t hci_handle);
213 
214 /*******************************************************************************
215  *
216  * Function         BTM_ReadConnectionAddr
217  *
218  * Description      Read the local device random address.
219  *
220  * Returns          void
221  *
222  ******************************************************************************/
223 void BTM_ReadConnectionAddr(const RawAddress& remote_bda,
224                             RawAddress& local_conn_addr,
225                             tBLE_ADDR_TYPE* p_addr_type);
226 
227 /*******************************************************************************
228  *
229  * Function         BTM_IsBleConnection
230  *
231  * Description      This function is called to check if the connection handle
232  *                  for an LE link
233  *
234  * Returns          true if connection is LE link, otherwise false.
235  *
236  ******************************************************************************/
237 bool BTM_IsBleConnection(uint16_t hci_handle);
238 
239 const RawAddress acl_address_from_handle(uint16_t hci_handle);
240 
241 void btm_ble_refresh_local_resolvable_private_addr(
242     const RawAddress& pseudo_addr, const RawAddress& local_rpa);
243 
244 void btm_cont_rswitch_from_handle(uint16_t hci_handle);
245 
246 uint8_t acl_link_role_from_handle(uint16_t handle);
247 
248 void acl_set_disconnect_reason(tHCI_STATUS acl_disc_reason);
249 
250 bool acl_is_role_switch_allowed();
251 
252 uint16_t acl_get_supported_packet_types();
253 
254 bool acl_set_peer_le_features_from_handle(uint16_t hci_handle,
255                                           const uint8_t* p);
256 
257 tBTM_STATUS btm_read_power_mode_state(const RawAddress& remote_bda,
258                                       tBTM_PM_STATE* pmState);
259 
260 void btm_acl_notif_conn_collision(const RawAddress& bda);
261 
262 void btm_acl_update_conn_addr(uint16_t conn_handle, const RawAddress& address);
263 
264 /*******************************************************************************
265  *
266  * Function         BTM_ReadPowerMode
267  *
268  * Description      This returns the current mode for a specific
269  *                  ACL connection.
270  *
271  * Input Param      remote_bda - device address of desired ACL connection
272  *
273  * Output Param     p_mode - address where the current mode is copied into.
274  *                          BTM_ACL_MODE_NORMAL
275  *                          BTM_ACL_MODE_HOLD
276  *                          BTM_ACL_MODE_SNIFF
277  *                          BTM_ACL_MODE_PARK
278  *                          (valid only if return code is BTM_SUCCESS)
279  *
280  * Returns          true if successful, false otherwise.
281  *
282  ******************************************************************************/
283 bool BTM_ReadPowerMode(const RawAddress& remote_bda, tBTM_PM_MODE* p_mode);
284 
285 void btm_acl_created(const RawAddress& bda, uint16_t hci_handle,
286                      tHCI_ROLE link_role, tBT_TRANSPORT transport);
287 
288 void btm_acl_removed(uint16_t handle);
289 
290 void acl_disconnect_from_handle(uint16_t handle, tHCI_STATUS reason);
291 void acl_disconnect_after_role_switch(uint16_t conn_handle, tHCI_STATUS reason);
292 
293 bool acl_peer_supports_sniff_subrating(const RawAddress& remote_bda);
294 
295 void btm_acl_set_paging(bool value);
296 
297 void btm_process_cancel_complete(uint8_t status, uint8_t mode);
298 
299 uint8_t btm_handle_to_acl_index(uint16_t hci_handle);
300 
301 tHCI_REASON btm_get_acl_disc_reason_code(void);
302 
303 extern tBTM_STATUS btm_remove_acl(const RawAddress& bd_addr,
304                                   tBT_TRANSPORT transport);
305 
306 void btm_acl_device_down(void);
307 void btm_acl_update_inquiry_status(uint8_t status);
308 
309 void ACL_RegisterClient(struct acl_client_callback_s* callbacks);
310 void ACL_UnregisterClient(struct acl_client_callback_s* callbacks);
311 bool ACL_SupportTransparentSynchronousData(const RawAddress& bd_addr);
312 
313 void acl_add_to_ignore_auto_connect_after_disconnect(const RawAddress& bd_addr);
314 bool acl_check_and_clear_ignore_auto_connect_after_disconnect(
315     const RawAddress& bd_addr);
316 void acl_clear_all_ignore_auto_connect_after_disconnect();
317