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 void BTM_unblock_role_switch_and_sniff_mode_for(const RawAddress& peer_addr); 39 void BTM_block_role_switch_and_sniff_mode_for(const RawAddress& peer_addr); 40 41 void BTM_default_unblock_role_switch(); 42 void BTM_default_block_role_switch(); 43 44 void BTM_acl_after_controller_started(const controller_t* controller); 45 46 /******************************************************************************* 47 * 48 * Function BTM_SetLinkSuperTout 49 * 50 * Description Create and send HCI "Write Link Supervision Timeout" command 51 * 52 * Returns BTM_CMD_STARTED if successfully initiated, otherwise error 53 * 54 ******************************************************************************/ 55 tBTM_STATUS BTM_SetLinkSuperTout(const RawAddress& remote_bda, 56 uint16_t timeout); 57 /******************************************************************************* 58 * 59 * Function BTM_GetLinkSuperTout 60 * 61 * Description Read the link supervision timeout value of the connection 62 * 63 * Returns status of the operation 64 * 65 ******************************************************************************/ 66 tBTM_STATUS BTM_GetLinkSuperTout(const RawAddress& remote_bda, 67 uint16_t* p_timeout); 68 69 /******************************************************************************* 70 * 71 * Function BTM_IsAclConnectionUp 72 * 73 * Description This function is called to check if an ACL connection exists 74 * to a specific remote BD Address. The second version ensures 75 * the hci handle is valid (Unsure if needed) 76 * 77 * Returns true if connection is up, else false. 78 * 79 ******************************************************************************/ 80 bool BTM_IsAclConnectionUp(const RawAddress& remote_bda, 81 tBT_TRANSPORT transport); 82 83 bool BTM_IsAclConnectionUpAndHandleValid(const RawAddress& remote_bda, 84 tBT_TRANSPORT transport); 85 86 bool BTM_IsAclConnectionUpFromHandle(uint16_t hci_handle); 87 88 /******************************************************************************* 89 * 90 * Function BTM_GetRole 91 * 92 * Description This function is called to get the role of the local device 93 * for the ACL connection with the specified remote device 94 * 95 * Returns BTM_SUCCESS if connection exists. 96 * BTM_UNKNOWN_ADDR if no active link with bd addr specified 97 * 98 ******************************************************************************/ 99 tBTM_STATUS BTM_GetRole(const RawAddress& remote_bd_addr, tHCI_ROLE* p_role); 100 101 /******************************************************************************* 102 * 103 * Function BTM_SwitchRoleToCentral 104 * 105 * Description This function is called to switch role between central and 106 * peripheral. If role is already set it will do nothing. 107 * 108 * Returns BTM_SUCCESS if already in specified role. 109 * BTM_CMD_STARTED if command issued to controller. 110 * BTM_NO_RESOURCES if memory couldn't be allocated to issue 111 * the command 112 * BTM_UNKNOWN_ADDR if no active link with bd addr specified 113 * BTM_MODE_UNSUPPORTED if the local device does not support 114 * role switching 115 * 116 ******************************************************************************/ 117 tBTM_STATUS BTM_SwitchRoleToCentral(const RawAddress& remote_bd_addr); 118 119 /******************************************************************************* 120 * 121 * Function BTM_ReadRSSI 122 * 123 * Description This function is called to read the link policy settings. 124 * The address of link policy results are returned in the 125 * callback. (tBTM_RSSI_RESULT) 126 * 127 * Returns BTM_CMD_STARTED if command issued to controller. 128 * BTM_NO_RESOURCES if memory couldn't be allocated to issue 129 * the command 130 * BTM_UNKNOWN_ADDR if no active link with bd addr specified 131 * BTM_BUSY if command is already in progress 132 * 133 ******************************************************************************/ 134 tBTM_STATUS BTM_ReadRSSI(const RawAddress& remote_bda, tBTM_CMPL_CB* p_cb); 135 136 /******************************************************************************* 137 * 138 * Function BTM_ReadFailedContactCounter 139 * 140 * Description This function is called to read the failed contact counter. 141 * The result is returned in the callback. 142 * (tBTM_FAILED_CONTACT_COUNTER_RESULT) 143 * 144 * Returns BTM_CMD_STARTED if command issued to controller. 145 * BTM_NO_RESOURCES if memory couldn't be allocated to issue 146 * the command 147 * BTM_UNKNOWN_ADDR if no active link with bd addr specified 148 * BTM_BUSY if command is already in progress 149 * 150 ******************************************************************************/ 151 tBTM_STATUS BTM_ReadFailedContactCounter(const RawAddress& remote_bda, 152 tBTM_CMPL_CB* p_cb); 153 154 /******************************************************************************* 155 * 156 * Function BTM_ReadTxPower 157 * 158 * Description This function is called to read the current connection 159 * TX power of the connection. The TX power level results 160 * are returned in the callback. 161 * (tBTM_RSSI_RESULT) 162 * 163 * Returns BTM_CMD_STARTED if command issued to controller. 164 * BTM_NO_RESOURCES if memory couldn't be allocated to issue 165 * the command 166 * BTM_UNKNOWN_ADDR if no active link with bd addr specified 167 * BTM_BUSY if command is already in progress 168 * 169 ******************************************************************************/ 170 tBTM_STATUS BTM_ReadTxPower(const RawAddress& remote_bda, 171 tBT_TRANSPORT transport, tBTM_CMPL_CB* p_cb); 172 173 /******************************************************************************* 174 * 175 * Function BTM_GetNumAclLinks 176 * 177 * Description This function is called to count the number of 178 * ACL links that are active. 179 * 180 * Returns uint16_t Number of active ACL links 181 * 182 ******************************************************************************/ 183 uint16_t BTM_GetNumAclLinks(void); 184 185 void btm_set_packet_types_from_address(const RawAddress& bda, 186 uint16_t pkt_types); 187 188 #define BLE_RESOLVE_ADDR_MASK 0xc0 189 #define BLE_RESOLVE_ADDR_MSB 0x40 190 191 bool BTM_BLE_IS_RESOLVE_BDA(const RawAddress& x); 192 193 bool acl_refresh_remote_address(const RawAddress& identity_address, 194 tBLE_ADDR_TYPE identity_address_type, 195 const RawAddress& remote_bda, 196 tBTM_SEC_BLE::tADDRESS_TYPE rra_type, 197 const RawAddress& rpa); 198 199 void btm_establish_continue_from_address(const RawAddress& remote_bda, 200 tBT_TRANSPORT transport); 201 202 bool acl_peer_supports_ble_connection_parameters_request( 203 const RawAddress& remote_bda); 204 205 bool sco_peer_supports_esco_2m_phy(const RawAddress& remote_bda); 206 bool sco_peer_supports_esco_3m_phy(const RawAddress& remote_bda); 207 bool sco_peer_supports_esco_ev3(const RawAddress& remote_bda); 208 209 bool acl_peer_supports_ble_packet_extension(uint16_t hci_handle); 210 bool acl_peer_supports_ble_2m_phy(uint16_t hci_handle); 211 bool acl_peer_supports_ble_coded_phy(uint16_t hci_handle); 212 213 bool acl_is_switch_role_idle(const RawAddress& bd_addr, 214 tBT_TRANSPORT transport); 215 216 bool acl_peer_supports_ble_packet_extension(uint16_t hci_handle); 217 218 /******************************************************************************* 219 * 220 * Function BTM_ReadConnectionAddr 221 * 222 * Description Read the local device random address. 223 * 224 * Returns void 225 * 226 ******************************************************************************/ 227 void BTM_ReadConnectionAddr(const RawAddress& remote_bda, 228 RawAddress& local_conn_addr, 229 tBLE_ADDR_TYPE* p_addr_type); 230 231 /******************************************************************************* 232 * 233 * Function BTM_IsBleConnection 234 * 235 * Description This function is called to check if the connection handle 236 * for an LE link 237 * 238 * Returns true if connection is LE link, otherwise false. 239 * 240 ******************************************************************************/ 241 bool BTM_IsBleConnection(uint16_t hci_handle); 242 243 const RawAddress acl_address_from_handle(uint16_t hci_handle); 244 245 void btm_ble_refresh_local_resolvable_private_addr( 246 const RawAddress& pseudo_addr, const RawAddress& local_rpa); 247 248 void btm_cont_rswitch_from_handle(uint16_t hci_handle); 249 250 uint8_t acl_link_role_from_handle(uint16_t handle); 251 252 void acl_set_disconnect_reason(tHCI_STATUS acl_disc_reason); 253 254 bool acl_is_role_switch_allowed(); 255 256 uint16_t acl_get_supported_packet_types(); 257 258 bool acl_set_peer_le_features_from_handle(uint16_t hci_handle, 259 const uint8_t* p); 260 261 tBTM_STATUS btm_read_power_mode_state(const RawAddress& remote_bda, 262 tBTM_PM_STATE* pmState); 263 264 void btm_acl_notif_conn_collision(const RawAddress& bda); 265 266 void btm_acl_update_conn_addr(uint16_t conn_handle, const RawAddress& address); 267 268 void btm_configure_data_path(uint8_t direction, uint8_t path_id, 269 std::vector<uint8_t> vendor_config); 270 271 /******************************************************************************* 272 * 273 * Function BTM_ReadPowerMode 274 * 275 * Description This returns the current mode for a specific 276 * ACL connection. 277 * 278 * Input Param remote_bda - device address of desired ACL connection 279 * 280 * Output Param p_mode - address where the current mode is copied into. 281 * BTM_ACL_MODE_NORMAL 282 * BTM_ACL_MODE_HOLD 283 * BTM_ACL_MODE_SNIFF 284 * BTM_ACL_MODE_PARK 285 * (valid only if return code is BTM_SUCCESS) 286 * 287 * Returns true if successful, false otherwise. 288 * 289 ******************************************************************************/ 290 bool BTM_ReadPowerMode(const RawAddress& remote_bda, tBTM_PM_MODE* p_mode); 291 292 void btm_acl_created(const RawAddress& bda, uint16_t hci_handle, 293 tHCI_ROLE link_role, tBT_TRANSPORT transport); 294 295 void btm_acl_removed(uint16_t handle); 296 297 void acl_disconnect_from_handle(uint16_t handle, tHCI_STATUS reason, 298 std::string comment); 299 void acl_disconnect_after_role_switch(uint16_t conn_handle, tHCI_STATUS reason, 300 std::string comment); 301 302 bool acl_peer_supports_sniff_subrating(const RawAddress& remote_bda); 303 304 void btm_acl_set_paging(bool value); 305 306 void btm_process_cancel_complete(uint8_t status, uint8_t mode); 307 308 uint8_t btm_handle_to_acl_index(uint16_t hci_handle); 309 310 tHCI_REASON btm_get_acl_disc_reason_code(void); 311 312 extern tBTM_STATUS btm_remove_acl(const RawAddress& bd_addr, 313 tBT_TRANSPORT transport); 314 315 void btm_acl_device_down(void); 316 void btm_acl_update_inquiry_status(uint8_t status); 317 318 void ACL_RegisterClient(struct acl_client_callback_s* callbacks); 319 void ACL_UnregisterClient(struct acl_client_callback_s* callbacks); 320 bool ACL_SupportTransparentSynchronousData(const RawAddress& bd_addr); 321