1 /****************************************************************************** 2 * 3 * Copyright 2009-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 /******************************************************************************* 20 * 21 * Filename: btif_api.h 22 * 23 * Description: Main API header file for all BTIF functions accessed 24 * from main bluetooth HAL. All HAL extensions will not 25 * require headerfiles as they would be accessed through 26 * callout/callins. 27 * 28 ******************************************************************************/ 29 30 #ifndef BTIF_API_H 31 #define BTIF_API_H 32 33 #include <hardware/bluetooth.h> 34 35 #include "btif_common.h" 36 #include "btif_dm.h" 37 #include "types/raw_address.h" 38 39 /******************************************************************************* 40 * BTIF CORE API 41 ******************************************************************************/ 42 43 /******************************************************************************* 44 * 45 * Function btif_init_bluetooth 46 * 47 * Description Creates BTIF task and prepares BT scheduler for startup 48 * 49 * Returns bt_status_t 50 * 51 ******************************************************************************/ 52 bt_status_t btif_init_bluetooth(void); 53 54 /******************************************************************************* 55 * 56 * Function btif_enable_bluetooth 57 * 58 * Description Performs chip power on and kickstarts OS scheduler 59 * 60 * Returns bt_status_t 61 * 62 ******************************************************************************/ 63 bt_status_t btif_enable_bluetooth(void); 64 65 /******************************************************************************* 66 * 67 * Function btif_cleanup_bluetooth 68 * 69 * Description Cleanup BTIF state. 70 * 71 * 72 * Returns void 73 * 74 ******************************************************************************/ 75 bt_status_t btif_cleanup_bluetooth(void); 76 77 /******************************************************************************* 78 * 79 * Function is_restricted_mode 80 * 81 * Description Checks if BT was enabled in restriced mode. In restricted 82 * mode, bonds that are created are marked as temporary. 83 * These bonds persist until we leave restricted mode, at 84 * which point they will be deleted from the config. Also 85 * while in restricted mode, the user can access devices 86 * that are already paired before entering restricted mode, 87 * but they cannot remove any of these devices. 88 * 89 * Returns bool 90 * 91 ******************************************************************************/ 92 bool is_restricted_mode(void); 93 94 /******************************************************************************* 95 * 96 * Function is_common_criteria_mode 97 * 98 * Description Check if BT is enabled in common criteria mode. In this 99 * mode, will use the LTK from the keystore to authenticate. 100 * 101 * Returns bool 102 * 103 ******************************************************************************/ 104 bool is_common_criteria_mode(void); 105 106 /******************************************************************************* 107 * 108 * Function get_common_criteria_config_compare_result 109 * 110 * Description Get the common criteria config compare result for confirming 111 * the config checksum compare result. When the common criteria 112 * mode doesn't enable, it should be all pass (0b11). 113 * Bit define: 114 * CONFIG_FILE_COMPARE_PASS = 0b01 115 * CONFIG_BACKUP_COMPARE_PASS = 0b10 116 * 117 * Returns int 118 * 119 ******************************************************************************/ 120 int get_common_criteria_config_compare_result(void); 121 122 /******************************************************************************* 123 * 124 * Function is_atv_device 125 * 126 * Description Returns true if the local device is an Android TV 127 * device, false if it is not. 128 * 129 * Returns bool 130 * 131 ******************************************************************************/ 132 bool is_atv_device(void); 133 134 /******************************************************************************* 135 * 136 * Function btif_get_adapter_properties 137 * 138 * Description Fetches all local adapter properties 139 * 140 ******************************************************************************/ 141 void btif_get_adapter_properties(void); 142 143 bt_property_t* property_deep_copy(const bt_property_t* prop); 144 145 /******************************************************************************* 146 * 147 * Function btif_get_adapter_property 148 * 149 * Description Fetches property value from local cache 150 * 151 ******************************************************************************/ 152 void btif_get_adapter_property(bt_property_type_t type); 153 154 /******************************************************************************* 155 * 156 * Function btif_set_adapter_property 157 * 158 * Description Updates core stack with property value and stores it in 159 * local cache 160 * 161 ******************************************************************************/ 162 void btif_set_adapter_property(bt_property_t* property); 163 164 /******************************************************************************* 165 * 166 * Function btif_get_remote_device_property 167 * 168 * Description Fetches the remote device property from the NVRAM 169 * 170 ******************************************************************************/ 171 void btif_get_remote_device_property(RawAddress remote_addr, 172 bt_property_type_t type); 173 174 /******************************************************************************* 175 * 176 * Function btif_get_remote_device_properties 177 * 178 * Description Fetches all the remote device properties from NVRAM 179 * 180 ******************************************************************************/ 181 void btif_get_remote_device_properties(RawAddress remote_addr); 182 183 /******************************************************************************* 184 * 185 * Function btif_set_remote_device_property 186 * 187 * Description Writes the remote device property to NVRAM. 188 * Currently, BT_PROPERTY_REMOTE_FRIENDLY_NAME is the only 189 * remote device property that can be set 190 * 191 ******************************************************************************/ 192 void btif_set_remote_device_property(RawAddress* remote_addr, 193 bt_property_t* property); 194 195 /******************************************************************************* 196 * BTIF DM API 197 ******************************************************************************/ 198 199 /******************************************************************************* 200 * 201 * Function btif_dm_start_discovery 202 * 203 * Description Start device discovery/inquiry 204 * 205 ******************************************************************************/ 206 void btif_dm_start_discovery(void); 207 208 /******************************************************************************* 209 * 210 * Function btif_dm_cancel_discovery 211 * 212 * Description Cancels search 213 * 214 ******************************************************************************/ 215 void btif_dm_cancel_discovery(void); 216 217 bool btif_dm_pairing_is_busy(); 218 /******************************************************************************* 219 * 220 * Function btif_dm_create_bond 221 * 222 * Description Initiate bonding with the specified device 223 * 224 ******************************************************************************/ 225 void btif_dm_create_bond(const RawAddress bd_addr, int transport); 226 227 /******************************************************************************* 228 * 229 * Function btif_dm_create_bond_le 230 * 231 * Description Initiate bonding with the specified device over le transport 232 * 233 ******************************************************************************/ 234 void btif_dm_create_bond_le(const RawAddress bd_addr, uint8_t addr_type); 235 236 /******************************************************************************* 237 * 238 * Function btif_dm_create_bond_out_of_band 239 * 240 * Description Initiate bonding with the specified device using OOB data. 241 * 242 ******************************************************************************/ 243 void btif_dm_create_bond_out_of_band(const RawAddress bd_addr, 244 tBT_TRANSPORT transport, 245 const bt_oob_data_t p192_data, 246 const bt_oob_data_t p256_data); 247 248 /******************************************************************************* 249 * 250 * Function btif_dm_cancel_bond 251 * 252 * Description Initiate bonding with the specified device 253 * 254 ******************************************************************************/ 255 void btif_dm_cancel_bond(const RawAddress bd_addr); 256 257 /******************************************************************************* 258 * 259 * Function btif_dm_remove_bond 260 * 261 * Description Removes bonding with the specified device 262 * 263 ******************************************************************************/ 264 void btif_dm_remove_bond(const RawAddress bd_addr); 265 266 /******************************************************************************* 267 * 268 * Function btif_dm_get_connection_state 269 * btif_dm_get_connection_state_sync 270 * 271 * Description Returns bitmask on remote device connection state indicating 272 * connection and encryption. The `_sync` version properly 273 * synchronizes the state and is the preferred mechanism. 274 * NOTE: Currently no address resolution is attempted upon 275 * LE random addresses. 276 * 277 * Returns '000 (0x0000) if not connected 278 * '001 (0x0001) Connected with no encryption to remote 279 * device on BR/EDR or LE ACL 280 * '011 (0x0003) Connected with encryption to remote 281 * device on BR/EDR ACL 282 * '101 (0x0005) Connected with encruption to remote 283 * device on LE ACL 284 * '111 (0x0007) Connected with encruption to remote 285 * device on both BR/EDR and LE ACLs 286 * All other values are reserved 287 * 288 ******************************************************************************/ 289 uint16_t btif_dm_get_connection_state(const RawAddress& bd_addr); 290 uint16_t btif_dm_get_connection_state_sync(const RawAddress& bd_addr); 291 292 /******************************************************************************* 293 * 294 * Function btif_dm_pin_reply 295 * 296 * Description BT legacy pairing - PIN code reply 297 * 298 ******************************************************************************/ 299 void btif_dm_pin_reply(const RawAddress bd_addr, uint8_t accept, 300 uint8_t pin_len, bt_pin_code_t pin_code); 301 302 /******************************************************************************* 303 * 304 * Function btif_dm_passkey_reply 305 * 306 * Description BT SSP passkey reply 307 * 308 * Returns bt_status_t 309 * 310 ******************************************************************************/ 311 bt_status_t btif_dm_passkey_reply(const RawAddress* bd_addr, uint8_t accept, 312 uint32_t passkey); 313 314 /******************************************************************************* 315 * 316 * Function btif_dm_ssp_reply 317 * 318 * Description BT SSP Reply - Just Works, Numeric Comparison & Passkey 319 * Entry 320 * 321 ******************************************************************************/ 322 void btif_dm_ssp_reply(const RawAddress bd_addr, bt_ssp_variant_t variant, 323 uint8_t accept); 324 325 /******************************************************************************* 326 * 327 * Function btif_dm_get_adapter_property 328 * 329 * Description Queries the BTA for the adapter property 330 * 331 * Returns bt_status_t 332 * 333 ******************************************************************************/ 334 bt_status_t btif_dm_get_adapter_property(bt_property_t* prop); 335 336 /******************************************************************************* 337 * 338 * Function btif_dm_get_remote_services 339 * 340 * Description Start SDP to get remote services 341 * 342 * Returns bt_status_t 343 * 344 ******************************************************************************/ 345 void btif_dm_get_remote_services(const RawAddress remote_addr, int transport); 346 347 /******************************************************************************* 348 * 349 * Function btif_dut_mode_configure 350 * 351 * Description Configure Test Mode - 'enable' to 1 puts the device in test 352 * mode and 0 exits test mode 353 * 354 ******************************************************************************/ 355 void btif_dut_mode_configure(uint8_t enable); 356 357 bool btif_is_dut_mode(); 358 359 /******************************************************************************* 360 * 361 * Function btif_dut_mode_send 362 * 363 * Description Sends a HCI Vendor specific command to the controller 364 * 365 ******************************************************************************/ 366 void btif_dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len); 367 368 void btif_ble_transmitter_test(uint8_t tx_freq, uint8_t test_data_len, 369 uint8_t packet_payload); 370 371 void btif_ble_receiver_test(uint8_t rx_freq); 372 void btif_ble_test_end(); 373 374 /******************************************************************************* 375 * 376 * Function btif_dm_read_energy_info 377 * 378 * Description Reads the energy info from controller 379 * 380 * Returns void 381 * 382 ******************************************************************************/ 383 void btif_dm_read_energy_info(); 384 385 /******************************************************************************* 386 * 387 * Function btif_config_hci_snoop_log 388 * 389 * Description enable or disable HCI snoop log 390 * 391 * Returns BT_STATUS_SUCCESS on success 392 * 393 ******************************************************************************/ 394 bt_status_t btif_config_hci_snoop_log(uint8_t enable); 395 396 /******************************************************************************* 397 * 398 * Function btif_debug_bond_event_dump 399 * 400 * Description Dump bond event information 401 * 402 * Returns void 403 * 404 ******************************************************************************/ 405 void btif_debug_bond_event_dump(int fd); 406 407 /******************************************************************************* 408 * 409 * Function btif_set_dynamic_audio_buffer_size 410 * 411 * Description Set dynamic audio buffer size 412 * 413 * Returns BT_STATUS_SUCCESS on success 414 * 415 ******************************************************************************/ 416 bt_status_t btif_set_dynamic_audio_buffer_size(int codec, int size); 417 418 /******************************************************************************* 419 * 420 * Function btif_debug_linkkey_type_dump 421 * 422 * Description Dump exchanged linkkey types information 423 * 424 * Returns void 425 * 426 ******************************************************************************/ 427 void btif_debug_linkkey_type_dump(int fd); 428 429 #endif /* BTIF_API_H */ 430