1 /****************************************************************************** 2 * 3 * Copyright 1999-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 * This file contains the Bluetooth Manager (BTM) API function external 22 * definitions. 23 * 24 ******************************************************************************/ 25 #ifndef BTM_BLE_API_H 26 #define BTM_BLE_API_H 27 28 #include <base/callback_forward.h> 29 #include <hardware/bt_common_types.h> 30 #include <memory> 31 #include "bt_common.h" 32 #include "btm_api.h" 33 #include "btm_ble_api_types.h" 34 #include "osi/include/alarm.h" 35 #include "stack/btm/neighbor_inquiry.h" 36 #include "types/bt_transport.h" 37 38 void btm_ble_init(); 39 void btm_ble_free(); 40 41 /***************************************************************************** 42 * EXTERNAL FUNCTION DECLARATIONS 43 ****************************************************************************/ 44 /******************************************************************************* 45 * 46 * Function BTM_SecAddBleDevice 47 * 48 * Description Add/modify device. This function will be normally called 49 * during host startup to restore all required information 50 * for a LE device stored in the NVRAM. 51 * 52 * Parameters: bd_addr - BD address of the peer 53 * dev_type - Remote device's device type. 54 * addr_type - LE device address type. 55 * 56 ******************************************************************************/ 57 extern void BTM_SecAddBleDevice(const RawAddress& bd_addr, 58 tBT_DEVICE_TYPE dev_type, 59 tBLE_ADDR_TYPE addr_type); 60 61 /******************************************************************************* 62 * 63 * Function BTM_SecAddBleKey 64 * 65 * Description Add/modify LE device information. This function will be 66 * normally called during host startup to restore all required 67 * information stored in the NVRAM. 68 * 69 * Parameters: bd_addr - BD address of the peer 70 * p_le_key - LE key values. 71 * key_type - LE SMP key type. 72 * 73 ******************************************************************************/ 74 extern void BTM_SecAddBleKey(const RawAddress& bd_addr, 75 tBTM_LE_KEY_VALUE* p_le_key, 76 tBTM_LE_KEY_TYPE key_type); 77 78 /** 79 * This function is called to set scan parameters. |cb| is called with operation 80 * status 81 **/ 82 extern void BTM_BleSetScanParams(uint32_t scan_interval, uint32_t scan_window, 83 tBLE_SCAN_MODE scan_type, 84 base::Callback<void(uint8_t)> cb); 85 86 /******************************************************************************* 87 * 88 * Function BTM_BleGetVendorCapabilities 89 * 90 * Description This function reads local LE features 91 * 92 * Parameters p_cmn_vsc_cb : Locala LE capability structure 93 * 94 * Returns void 95 * 96 ******************************************************************************/ 97 extern void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB* p_cmn_vsc_cb); 98 99 /******************************************************************************* 100 * 101 * Function BTM_BleGetDynamicAudioBuffer 102 * 103 * Description This function reads dynamic audio buffer 104 * 105 * Parameters p_dynamic_audio_buffer_cb : Dynamic Audio Buffer structure 106 * 107 * Returns void 108 * 109 ******************************************************************************/ 110 extern void BTM_BleGetDynamicAudioBuffer( 111 tBTM_BT_DYNAMIC_AUDIO_BUFFER_CB* p_dynamic_audio_buffer_cb); 112 113 /******************************************************************************* 114 * 115 * Function BTM_BleSetStorageConfig 116 * 117 * Description This function is called to setup storage configuration and 118 * setup callbacks. 119 * 120 * Parameters uint8_t batch_scan_full_max -Batch scan full maximum 121 uint8_t batch_scan_trunc_max - Batch scan truncated value 122 maximum 123 uint8_t batch_scan_notify_threshold - Threshold value 124 cb - Setup callback 125 tBTM_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback -Threshold 126 callback 127 void *p_ref - Reference value 128 * 129 * 130 ******************************************************************************/ 131 extern void BTM_BleSetStorageConfig( 132 uint8_t batch_scan_full_max, uint8_t batch_scan_trunc_max, 133 uint8_t batch_scan_notify_threshold, 134 base::Callback<void(uint8_t /* status */)> cb, 135 tBTM_BLE_SCAN_THRESHOLD_CBACK* p_thres_cback, tBTM_BLE_REF_VALUE ref_value); 136 137 /* This function is called to enable batch scan */ 138 extern void BTM_BleEnableBatchScan( 139 tBTM_BLE_BATCH_SCAN_MODE scan_mode, uint32_t scan_interval, 140 uint32_t scan_window, tBTM_BLE_DISCARD_RULE discard_rule, 141 tBLE_ADDR_TYPE addr_type, base::Callback<void(uint8_t /* status */)> cb); 142 143 /* This function is called to disable batch scanning */ 144 extern void BTM_BleDisableBatchScan( 145 base::Callback<void(uint8_t /* status */)> cb); 146 147 /* This function is called to read batch scan reports */ 148 extern void BTM_BleReadScanReports(tBLE_SCAN_MODE scan_mode, 149 tBTM_BLE_SCAN_REP_CBACK cb); 150 151 /* This function is called to setup the callback for tracking */ 152 extern void BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK* p_track_cback, 153 tBTM_BLE_REF_VALUE ref_value); 154 155 /******************************************************************************* 156 * 157 * Function BTM_BleObserve 158 * 159 * Description This procedure keep the device listening for advertising 160 * events from a broadcast device. 161 * 162 * Parameters start: start or stop observe. 163 * 164 * Returns void 165 * 166 ******************************************************************************/ 167 extern tBTM_STATUS BTM_BleObserve(bool start, uint8_t duration, 168 tBTM_INQ_RESULTS_CB* p_results_cb, 169 tBTM_CMPL_CB* p_cmpl_cb); 170 171 /** Returns local device encryption root (ER) */ 172 const Octet16& BTM_GetDeviceEncRoot(); 173 174 /** Returns local device identity root (IR) */ 175 extern const Octet16& BTM_GetDeviceIDRoot(); 176 177 /** Return local device DHK. */ 178 extern const Octet16& BTM_GetDeviceDHK(); 179 180 /******************************************************************************* 181 * 182 * Function BTM_SecurityGrant 183 * 184 * Description This function is called to grant security process. 185 * 186 * Parameters bd_addr - peer device bd address. 187 * res - result of the operation BTM_SUCCESS if success. 188 * Otherwise, BTM_REPEATED_ATTEMPTS is too many 189 * attempts. 190 * 191 * Returns None 192 * 193 ******************************************************************************/ 194 extern void BTM_SecurityGrant(const RawAddress& bd_addr, uint8_t res); 195 196 /******************************************************************************* 197 * 198 * Function BTM_BlePasskeyReply 199 * 200 * Description This function is called after Security Manager submitted 201 * passkey request to the application. 202 * 203 * Parameters: bd_addr - Address of the device for which passkey was 204 * requested 205 * res - result of the operation SMP_SUCCESS if success 206 * passkey - numeric value in the range of 207 * BTM_MIN_PASSKEY_VAL(0) - 208 * BTM_MAX_PASSKEY_VAL(999999(0xF423F)). 209 * 210 ******************************************************************************/ 211 extern void BTM_BlePasskeyReply(const RawAddress& bd_addr, uint8_t res, 212 uint32_t passkey); 213 214 /******************************************************************************* 215 * 216 * Function BTM_BleConfirmReply 217 * 218 * Description This function is called after Security Manager submitted 219 * numeric comparison request to the application. 220 * 221 * Parameters: bd_addr - Address of the device with which numeric 222 * comparison was requested 223 * res - comparison result BTM_SUCCESS if success 224 * 225 ******************************************************************************/ 226 extern void BTM_BleConfirmReply(const RawAddress& bd_addr, uint8_t res); 227 228 /******************************************************************************* 229 * 230 * Function BTM_LeOobDataReply 231 * 232 * Description This function is called to provide the OOB data for 233 * SMP in response to BTM_LE_OOB_REQ_EVT 234 * 235 * Parameters: bd_addr - Address of the peer device 236 * res - result of the operation SMP_SUCCESS if success 237 * p_data - simple pairing Randomizer C. 238 * 239 ******************************************************************************/ 240 extern void BTM_BleOobDataReply(const RawAddress& bd_addr, uint8_t res, 241 uint8_t len, uint8_t* p_data); 242 243 /******************************************************************************* 244 * 245 * Function BTM_BleSecureConnectionOobDataReply 246 * 247 * Description This function is called to provide the OOB data for 248 * SMP in response to BTM_LE_OOB_REQ_EVT when secure connection 249 * data is available 250 * 251 * Parameters: bd_addr - Address of the peer device 252 * p_c - pointer to Confirmation 253 * p_r - pointer to Randomizer. 254 * 255 ******************************************************************************/ 256 extern void BTM_BleSecureConnectionOobDataReply(const RawAddress& bd_addr, 257 uint8_t* p_c, uint8_t* p_r); 258 259 /******************************************************************************* 260 * 261 * Function BTM_BleDataSignature 262 * 263 * Description This function is called to sign the data using AES128 CMAC 264 * algorith. 265 * 266 * Parameter bd_addr: target device the data to be signed for. 267 * p_text: singing data 268 * len: length of the signing data 269 * signature: output parameter where data signature is going to 270 * be stored. 271 * 272 * Returns true if signing sucessul, otherwise false. 273 * 274 ******************************************************************************/ 275 extern bool BTM_BleDataSignature(const RawAddress& bd_addr, uint8_t* p_text, 276 uint16_t len, BLE_SIGNATURE signature); 277 278 /******************************************************************************* 279 * 280 * Function BTM_BleVerifySignature 281 * 282 * Description This function is called to verify the data signature 283 * 284 * Parameter bd_addr: target device the data to be signed for. 285 * p_orig: original data before signature. 286 * len: length of the signing data 287 * counter: counter used when doing data signing 288 * p_comp: signature to be compared against. 289 290 * Returns true if signature verified correctly; otherwise false. 291 * 292 ******************************************************************************/ 293 extern bool BTM_BleVerifySignature(const RawAddress& bd_addr, uint8_t* p_orig, 294 uint16_t len, uint32_t counter, 295 uint8_t* p_comp); 296 297 /******************************************************************************* 298 * 299 * Function BTM_IsBleConnection 300 * 301 * Description This function is called to check if the connection handle 302 * for an LE link 303 * 304 * Returns true if connection is LE link, otherwise false. 305 * 306 ******************************************************************************/ 307 extern bool BTM_IsBleConnection(uint16_t conn_handle); 308 309 /******************************************************************************* 310 * 311 * Function BTM_ReadRemoteConnectionAddr 312 * 313 * Description Read the remote device address currently used. 314 * 315 * Returns void 316 * 317 ******************************************************************************/ 318 extern bool BTM_ReadRemoteConnectionAddr(const RawAddress& pseudo_addr, 319 RawAddress& conn_addr, 320 tBLE_ADDR_TYPE* p_addr_type); 321 322 /******************************************************************************* 323 * 324 * Function BTM_BleLoadLocalKeys 325 * 326 * Description Local local identity key, encryption root or sign counter. 327 * 328 * Parameters: key_type: type of key, can be BTM_BLE_KEY_TYPE_ID, 329 * BTM_BLE_KEY_TYPE_ER 330 * or BTM_BLE_KEY_TYPE_COUNTER. 331 * p_key: pointer to the key. 332 * 333 * Returns non2. 334 * 335 ******************************************************************************/ 336 extern void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key); 337 338 #include "stack/btm/btm_ble_bgconn.h" 339 340 /******************************************************** 341 * 342 * Function BTM_BleSetPrefConnParams 343 * 344 * Description Set a peripheral's preferred connection parameters. When 345 * any of the value does not want to be updated while others 346 * do, use BTM_BLE_CONN_PARAM_UNDEF for the ones want to 347 * leave untouched. 348 * 349 * Parameters: bd_addr - BD address of the peripheral 350 * min_conn_int - minimum preferred connection interval 351 * max_conn_int - maximum preferred connection interval 352 * peripheral_latency - preferred peripheral latency 353 * supervision_tout - preferred supervision timeout 354 * 355 * Returns void 356 * 357 ******************************************************************************/ 358 extern void BTM_BleSetPrefConnParams(const RawAddress& bd_addr, 359 uint16_t min_conn_int, 360 uint16_t max_conn_int, 361 uint16_t peripheral_latency, 362 uint16_t supervision_tout); 363 364 /****************************************************************************** 365 * 366 * Function BTM_BleReadControllerFeatures 367 * 368 * Description Reads BLE specific controller features 369 * 370 * Parameters: tBTM_BLE_CTRL_FEATURES_CBACK : Callback to notify when 371 * features are read 372 * 373 * Returns void 374 * 375 ******************************************************************************/ 376 extern void BTM_BleReadControllerFeatures( 377 tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback); 378 379 /******************************************************************************* 380 * 381 * Function BTM__BLEReadDiscoverability 382 * 383 * Description This function is called to read the current LE 384 * discoverability mode of the device. 385 * 386 * Returns BTM_BLE_NON_DISCOVERABLE ,BTM_BLE_LIMITED_DISCOVERABLE or 387 * BTM_BLE_GENRAL_DISCOVERABLE 388 * 389 ******************************************************************************/ 390 uint16_t BTM_BleReadDiscoverability(); 391 392 /******************************************************************************* 393 * 394 * Function BTM__BLEReadConnectability 395 * 396 * Description This function is called to read the current LE 397 * connectibility mode of the device. 398 * 399 * Returns BTM_BLE_NON_CONNECTABLE or BTM_BLE_CONNECTABLE 400 * 401 ******************************************************************************/ 402 extern uint16_t BTM_BleReadConnectability(); 403 404 /******************************************************************************* 405 * 406 * Function BTM_ReadDevInfo 407 * 408 * Description This function is called to read the device/address type 409 * of BD address. 410 * 411 * Parameter remote_bda: remote device address 412 * p_dev_type: output parameter to read the device type. 413 * p_addr_type: output parameter to read the address type. 414 * 415 ******************************************************************************/ 416 extern void BTM_ReadDevInfo(const RawAddress& remote_bda, 417 tBT_DEVICE_TYPE* p_dev_type, 418 tBLE_ADDR_TYPE* p_addr_type); 419 420 /******************************************************************************* 421 * 422 * Function BTM_ReadConnectedTransportAddress 423 * 424 * Description This function is called to read the paired device/address 425 * type of other device paired corresponding to the BD_address 426 * 427 * Parameter remote_bda: remote device address, carry out the transport 428 * address 429 * transport: active transport 430 * 431 * Return true if an active link is identified; false otherwise 432 * 433 ******************************************************************************/ 434 extern bool BTM_ReadConnectedTransportAddress(RawAddress* remote_bda, 435 tBT_TRANSPORT transport); 436 437 /******************************************************************************* 438 * 439 * Function BTM_BleConfigPrivacy 440 * 441 * Description This function is called to enable or disable the privacy in 442 * the local device. 443 * 444 * Parameters enable: true to enable it; false to disable it. 445 * 446 * Returns bool privacy mode set success; otherwise failed. 447 * 448 ******************************************************************************/ 449 extern bool BTM_BleConfigPrivacy(bool enable); 450 451 /******************************************************************************* 452 * 453 * Function BTM_BleLocalPrivacyEnabled 454 * 455 * Description Checks if local device supports private address 456 * 457 * Returns Return true if local privacy is enabled else false 458 * 459 ******************************************************************************/ 460 extern bool BTM_BleLocalPrivacyEnabled(void); 461 462 /******************************************************************************* 463 * 464 * Function BTM_BleMaxMultiAdvInstanceCount 465 * 466 * Description Returns the maximum number of multi adv instances supported 467 * by the controller. 468 * 469 * Returns Max multi adv instance count 470 * 471 ******************************************************************************/ 472 extern uint8_t BTM_BleMaxMultiAdvInstanceCount(); 473 474 /******************************************************************************* 475 * 476 * Function BTM_BleReceiverTest 477 * 478 * Description This function is called to start the LE Receiver test 479 * 480 * Parameter rx_freq - Frequency Range 481 * p_cmd_cmpl_cback - Command Complete callback 482 * 483 ******************************************************************************/ 484 void BTM_BleReceiverTest(uint8_t rx_freq, tBTM_CMPL_CB* p_cmd_cmpl_cback); 485 486 /******************************************************************************* 487 * 488 * Function BTM_BleTransmitterTest 489 * 490 * Description This function is called to start the LE Transmitter test 491 * 492 * Parameter tx_freq - Frequency Range 493 * test_data_len - Length in bytes of payload data in each 494 * packet 495 * packet_payload - Pattern to use in the payload 496 * p_cmd_cmpl_cback - Command Complete callback 497 * 498 ******************************************************************************/ 499 void BTM_BleTransmitterTest(uint8_t tx_freq, uint8_t test_data_len, 500 uint8_t packet_payload, 501 tBTM_CMPL_CB* p_cmd_cmpl_cback); 502 503 /******************************************************************************* 504 * 505 * Function BTM_BleTestEnd 506 * 507 * Description This function is called to stop the in-progress TX or RX test 508 * 509 * Parameter p_cmd_cmpl_cback - Command complete callback 510 * 511 ******************************************************************************/ 512 void BTM_BleTestEnd(tBTM_CMPL_CB* p_cmd_cmpl_cback); 513 514 /******************************************************************************* 515 * 516 * Function BTM_UseLeLink 517 * 518 * Description Select the underlying physical link to use. 519 * 520 * Returns true to use LE, false use BR/EDR. 521 * 522 ******************************************************************************/ 523 extern bool BTM_UseLeLink(const RawAddress& bd_addr); 524 525 /******************************************************************************* 526 * 527 * Function BTM_BleAdvFilterParamSetup 528 * 529 * Description This function is called to setup the adv data payload filter 530 * condition. 531 * 532 ******************************************************************************/ 533 extern void BTM_BleAdvFilterParamSetup( 534 int action, tBTM_BLE_PF_FILT_INDEX filt_index, 535 std::unique_ptr<btgatt_filt_param_setup_t> p_filt_params, 536 tBTM_BLE_PF_PARAM_CB cb); 537 538 /** 539 * This functions are called to configure the adv data payload filter condition 540 */ 541 extern void BTM_LE_PF_set(tBTM_BLE_PF_FILT_INDEX filt_index, 542 std::vector<ApcfCommand> commands, 543 tBTM_BLE_PF_CFG_CBACK cb); 544 extern void BTM_LE_PF_clear(tBTM_BLE_PF_FILT_INDEX filt_index, 545 tBTM_BLE_PF_CFG_CBACK cb); 546 547 /******************************************************************************* 548 * 549 * Function BTM_BleEnableDisableFilterFeature 550 * 551 * Description Enable or disable the APCF feature 552 * 553 * Parameters enable - true - enables APCF, false - disables APCF 554 * 555 ******************************************************************************/ 556 extern void BTM_BleEnableDisableFilterFeature( 557 uint8_t enable, tBTM_BLE_PF_STATUS_CBACK p_stat_cback); 558 559 /******************************************************************************* 560 * 561 * Function BTM_BleGetEnergyInfo 562 * 563 * Description This function obtains the energy info 564 * 565 * Parameters p_ener_cback - Callback pointer 566 * 567 * Returns status 568 * 569 ******************************************************************************/ 570 extern tBTM_STATUS BTM_BleGetEnergyInfo( 571 tBTM_BLE_ENERGY_INFO_CBACK* p_ener_cback); 572 573 /******************************************************************************* 574 * 575 * Function BTM_SetBleDataLength 576 * 577 * Description Set the maximum BLE transmission packet size 578 * 579 * Returns BTM_SUCCESS if success; otherwise failed. 580 * 581 ******************************************************************************/ 582 extern tBTM_STATUS BTM_SetBleDataLength(const RawAddress& bd_addr, 583 uint16_t tx_pdu_length); 584 585 /******************************************************************************* 586 * 587 * Function BTM_BleReadPhy 588 * 589 * Description To read the current PHYs for specified LE connection 590 * 591 * 592 * Returns BTM_SUCCESS if success; otherwise failed. 593 * 594 ******************************************************************************/ 595 extern void BTM_BleReadPhy( 596 const RawAddress& bd_addr, 597 base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)> cb); 598 599 /******************************************************************************* 600 * 601 * Function BTM_BleSetPhy 602 * 603 * Description To set PHY preferences for specified LE connection 604 * 605 * 606 * Returns BTM_SUCCESS if success; otherwise failed. 607 * 608 ******************************************************************************/ 609 extern void BTM_BleSetPhy(const RawAddress& bd_addr, uint8_t tx_phys, 610 uint8_t rx_phys, uint16_t phy_options); 611 612 extern void btm_ble_multi_adv_cleanup(void); 613 614 /******************************************************************************* 615 * 616 * Function btm_ble_get_acl_remote_addr 617 * 618 * Description This function reads the active remote address used for the 619 * connection. 620 * 621 * Returns success return true, otherwise false. 622 * 623 ******************************************************************************/ 624 bool btm_ble_get_acl_remote_addr(uint16_t hci_handle, RawAddress& conn_addr, 625 tBLE_ADDR_TYPE* p_addr_type); 626 627 #endif 628