1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include "base/functional/callback.h" 20 #include "device/include/esco_parameters.h" 21 #include "stack/btm/btm_sec.h" 22 #include "stack/btm/neighbor_inquiry.h" 23 #include "stack/include/acl_api_types.h" 24 #include "stack/include/bt_hdr.h" 25 #include "stack/include/bt_octets.h" 26 #include "stack/include/btm_api_types.h" 27 #include "stack/include/btm_ble_api_types.h" 28 #include "types/bluetooth/uuid.h" 29 #include "types/hci_role.h" 30 #include "types/raw_address.h" 31 32 namespace bluetooth { 33 namespace shim { 34 35 /******************************************************************************* 36 * 37 * Function BTM_StartInquiry 38 * 39 * Description This function is called to start an inquiry. 40 * 41 * Parameters: p_inqparms - pointer to the inquiry information 42 * mode - GENERAL or LIMITED inquiry 43 * duration - length in 1.28 sec intervals (If '0', the 44 * inquiry is CANCELLED) 45 * filter_cond_type - BTM_CLR_INQUIRY_FILTER, 46 * BTM_FILTER_COND_DEVICE_CLASS, or 47 * BTM_FILTER_COND_BD_ADDR 48 * filter_cond - value for the filter (based on 49 * filter_cond_type) 50 * 51 * p_results_cb - Pointer to the callback routine which gets 52 * called upon receipt of an inquiry result. If 53 * this field is NULL, the application is not 54 * notified. 55 * 56 * p_cmpl_cb - Pointer to the callback routine which gets 57 * called upon completion. If this field is 58 * NULL, the application is not notified when 59 * completed. 60 * Returns tBTM_STATUS 61 * BTM_CMD_STARTED if successfully initiated 62 * BTM_BUSY if already in progress 63 * BTM_ILLEGAL_VALUE if parameter(s) are out of range 64 * BTM_NO_RESOURCES if could not allocate resources to start 65 * the command 66 * BTM_WRONG_MODE if the device is not up. 67 * 68 ******************************************************************************/ 69 tBTM_STATUS BTM_StartInquiry(tBTM_INQ_RESULTS_CB* p_results_cb, 70 tBTM_CMPL_CB* p_cmpl_cb); 71 72 /******************************************************************************* 73 * 74 * Function BTM_SetDiscoverability 75 * 76 * Description This function is called to set the device into or out of 77 * discoverable mode. Discoverable mode means inquiry 78 * scans are enabled. If a value of '0' is entered for window 79 * or interval, the default values are used. 80 * 81 * Returns BTM_SUCCESS if successful 82 * BTM_BUSY if a setting of the filter is already in progress 83 * BTM_NO_RESOURCES if couldn't get a memory pool buffer 84 * BTM_ILLEGAL_VALUE if a bad parameter was detected 85 * BTM_WRONG_MODE if the device is not up. 86 * 87 ******************************************************************************/ 88 tBTM_STATUS BTM_SetDiscoverability(uint16_t inq_mode, uint16_t window, 89 uint16_t interval); 90 91 /******************************************************************************* 92 * 93 * Function BTM_BleObserve 94 * 95 * Description This procedure keep the device listening for advertising 96 * events from a broadcast device. 97 * 98 * Parameters start: start or stop observe. 99 * 100 * Returns void 101 * 102 ******************************************************************************/ 103 tBTM_STATUS BTM_BleObserve(bool start, uint8_t duration, 104 tBTM_INQ_RESULTS_CB* p_results_cb, 105 tBTM_CMPL_CB* p_cmpl_cb); 106 107 /******************************************************************************* 108 * 109 * Function BTM_BleOpportunisticObserve 110 * 111 * Description Register/unregister opportunistic scan callback. This method 112 * does not trigger scan start/stop, but if scan is ever started, 113 * this callback would get called with scan results. Additionally, 114 * this callback is not reset on each scan start/stop. It's 115 * intended to be used by LE Audio related profiles, that would 116 * find yet unpaired members of CSIS set, or broadcasts. 117 * 118 * Parameters enable: enable/disable observing. 119 * p_results_cb: callback for results. 120 * 121 * Returns void 122 * 123 ******************************************************************************/ 124 void BTM_BleOpportunisticObserve(bool enable, 125 tBTM_INQ_RESULTS_CB* p_results_cb); 126 127 /******************************************************************************* 128 * 129 * Function BTM_BleTargetAnnouncementObserve 130 * 131 * Description Register/Unregister client interested in the targeted 132 * announcements. Not that it is client responsible for parsing 133 * advertising data. 134 * 135 * Parameters start: start or stop observe. 136 * p_results_cb: callback for results. 137 * 138 * Returns void 139 * 140 ******************************************************************************/ 141 void BTM_BleTargetAnnouncementObserve(bool enable, 142 tBTM_INQ_RESULTS_CB* p_results_cb); 143 144 void BTM_EnableInterlacedInquiryScan(); 145 146 void BTM_EnableInterlacedPageScan(); 147 148 /******************************************************************************* 149 * 150 * Function BTM_SetInquiryMode 151 * 152 * Description This function is called to set standard, with RSSI 153 * mode or extended of the inquiry for local device. 154 * 155 * Input Params: BTM_INQ_RESULT_STANDARD, BTM_INQ_RESULT_WITH_RSSI or 156 * BTM_INQ_RESULT_EXTENDED 157 * 158 * Returns BTM_SUCCESS if successful 159 * BTM_NO_RESOURCES if couldn't get a memory pool buffer 160 * BTM_ILLEGAL_VALUE if a bad parameter was detected 161 * BTM_WRONG_MODE if the device is not up. 162 * 163 ******************************************************************************/ 164 tBTM_STATUS BTM_SetInquiryMode(uint8_t mode); 165 166 /******************************************************************************* 167 * 168 * Function BTM_SetConnectability 169 * 170 * Description This function is called to set the device into or out of 171 * connectable mode. Discoverable mode means page scans are 172 * enabled. 173 * 174 * Returns BTM_SUCCESS if successful 175 * BTM_ILLEGAL_VALUE if a bad parameter is detected 176 * BTM_NO_RESOURCES if could not allocate a message buffer 177 * BTM_WRONG_MODE if the device is not up. 178 * 179 ******************************************************************************/ 180 tBTM_STATUS BTM_SetConnectability(uint16_t page_mode, uint16_t window, 181 uint16_t interval); 182 183 /******************************************************************************* 184 * 185 * Function BTM_IsInquiryActive 186 * 187 * Description Return a bit mask of the current inquiry state 188 * 189 * Returns BTM_INQUIRY_INACTIVE if inactive (0) 190 * BTM_GENERAL_INQUIRY_ACTIVE if a general inquiry is active 191 * 192 ******************************************************************************/ 193 uint16_t BTM_IsInquiryActive(void); 194 195 /******************************************************************************* 196 * 197 * Function BTM_CancelInquiry 198 * 199 * Description This function cancels an inquiry if active 200 * 201 ******************************************************************************/ 202 void BTM_CancelInquiry(void); 203 204 /******************************************************************************* 205 * 206 * Function BTM_ReadRemoteDeviceName 207 * 208 * Description This function initiates a remote device HCI command to the 209 * controller and calls the callback when the process has 210 * completed. 211 * 212 * Input Params: remote_bda - device address of name to retrieve 213 * p_cb - callback function called when 214 * BTM_CMD_STARTED is returned. 215 * A pointer to tBTM_REMOTE_DEV_NAME is 216 * passed to the callback. 217 * 218 * Returns 219 * BTM_CMD_STARTED is returned if the request was successfully 220 * sent to HCI. 221 * BTM_BUSY if already in progress 222 * BTM_UNKNOWN_ADDR if device address is bad 223 * BTM_NO_RESOURCES if resources could not be allocated to 224 * start the command 225 * BTM_WRONG_MODE if the device is not up. 226 * 227 ******************************************************************************/ 228 tBTM_STATUS BTM_ReadRemoteDeviceName(const RawAddress& remote_bda, 229 tBTM_NAME_CMPL_CB* p_cb, 230 tBT_TRANSPORT transport); 231 232 /******************************************************************************* 233 * 234 * Function BTM_CancelRemoteDeviceName 235 * 236 * Description This function initiates the cancel request for the specified 237 * remote device. 238 * 239 * Input Params: None 240 * 241 * Returns 242 * BTM_CMD_STARTED is returned if the request was successfully 243 * sent to HCI. 244 * BTM_NO_RESOURCES if resources could not be allocated to 245 * start the command 246 * BTM_WRONG_MODE if there is no active remote name request. 247 * 248 ******************************************************************************/ 249 tBTM_STATUS BTM_CancelRemoteDeviceName(void); 250 251 /******************************************************************************* 252 * 253 * Function BTM_InqDbRead 254 * 255 * Description This function looks through the inquiry database for a match 256 * based on Bluetooth Device Address. This is the application's 257 * interface to get the inquiry details of a specific BD 258 * address. 259 * 260 * Returns pointer to entry, or NULL if not found 261 * 262 ******************************************************************************/ 263 tBTM_INQ_INFO* BTM_InqDbRead(const RawAddress& p_bda); 264 265 /******************************************************************************* 266 * 267 * Function BTM_InqDbFirst 268 * 269 * Description This function looks through the inquiry database for the 270 * first used entry, and returns that. This is used in 271 * conjunction with BTM_InqDbNext by applications as a way to 272 * walk through the inquiry database. 273 * 274 * Returns pointer to first in-use entry, or NULL if DB is empty 275 * 276 ******************************************************************************/ 277 tBTM_INQ_INFO* BTM_InqDbFirst(void); 278 279 /******************************************************************************* 280 * 281 * Function BTM_InqDbNext 282 * 283 * Description This function looks through the inquiry database for the 284 * next used entry, and returns that. If the input parameter 285 * is NULL, the first entry is returned. 286 * 287 * Returns pointer to next in-use entry, or NULL if no more found. 288 * 289 ******************************************************************************/ 290 tBTM_INQ_INFO* BTM_InqDbNext(tBTM_INQ_INFO* p_cur); 291 292 /******************************************************************************* 293 * 294 * Function BTM_ClearInqDb 295 * 296 * Description This function is called to clear out a device or all devices 297 * from the inquiry database. 298 * 299 * Parameter p_bda - (input) BD_ADDR -> Address of device to clear 300 * (NULL clears all entries) 301 * 302 * Returns BTM_BUSY if an inquiry, get remote name, or event filter 303 * is active, otherwise BTM_SUCCESS 304 * 305 ******************************************************************************/ 306 tBTM_STATUS BTM_ClearInqDb(const RawAddress* p_bda); 307 308 /******************************************************************************* 309 * 310 * Function BTM_HasEirService 311 * 312 * Description This function is called to know if UUID in bit map of UUID. 313 * 314 * Parameters p_eir_uuid - bit map of UUID list 315 * uuid16 - UUID 16-bit 316 * 317 * Returns true - if found 318 * false - if not found 319 * 320 ******************************************************************************/ 321 bool BTM_HasEirService(const uint32_t* p_eir_uuid, uint16_t uuid16); 322 323 /******************************************************************************* 324 * 325 * Function BTM_HasInquiryEirService 326 * 327 * Description Return if a UUID is in the bit map of a UUID list. 328 * 329 * Parameters p_results - inquiry results 330 * uuid16 - UUID 16-bit 331 * 332 * Returns BTM_EIR_FOUND - if found 333 * BTM_EIR_NOT_FOUND - if not found and it is a complete list 334 * BTM_EIR_UNKNOWN - if not found and it is not complete list 335 * 336 ******************************************************************************/ 337 tBTM_EIR_SEARCH_RESULT BTM_HasInquiryEirService(tBTM_INQ_RESULTS* p_results, 338 uint16_t uuid16); 339 340 /******************************************************************************* 341 * 342 * Function BTM_AddEirService 343 * 344 * Description This function is called to add a service in the bit map UUID 345 * list. 346 * 347 * Parameters p_eir_uuid - bit mask of UUID list for EIR 348 * uuid16 - UUID 16-bit 349 * 350 * Returns None 351 * 352 ******************************************************************************/ 353 void BTM_AddEirService(uint32_t* p_eir_uuid, uint16_t uuid16); 354 355 /******************************************************************************* 356 * 357 * Function BTM_SecAddBleDevice 358 * 359 * Description Add/modify device. This function will be normally called 360 * during host startup to restore all required information 361 * for a LE device stored in the NVRAM. 362 * 363 * Parameters: bd_addr - BD address of the peer 364 * dev_type - Remote device's device type. 365 * addr_type - LE device address type. 366 * 367 ******************************************************************************/ 368 void BTM_SecAddBleDevice(const RawAddress& bd_addr, tBT_DEVICE_TYPE dev_type, 369 tBLE_ADDR_TYPE addr_type); 370 371 /******************************************************************************* 372 * 373 * Function BTM_SecAddBleKey 374 * 375 * Description Add/modify LE device information. This function will be 376 * normally called during host startup to restore all required 377 * information stored in the NVRAM. 378 * 379 * Parameters: bd_addr - BD address of the peer 380 * p_le_key - LE key values. 381 * key_type - LE SMP key type. 382 * 383 ******************************************************************************/ 384 void BTM_SecAddBleKey(const RawAddress& bd_addr, tBTM_LE_KEY_VALUE* p_le_key, 385 tBTM_LE_KEY_TYPE key_type); 386 387 /******************************************************************************* 388 * 389 * Function BTM_BleLoadLocalKeys 390 * 391 * Description Local local identity key, encryption root or sign counter. 392 * 393 * Parameters: key_type: type of key, can be BTM_BLE_KEY_TYPE_ID, 394 * BTM_BLE_KEY_TYPE_ER 395 * or BTM_BLE_KEY_TYPE_COUNTER. 396 * p_key: pointer to the key. 397 * 398 * Returns non2. 399 * 400 ******************************************************************************/ 401 void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key); 402 403 /** Returns local device encryption root (ER) */ 404 const Octet16& BTM_GetDeviceEncRoot(); 405 406 /** Returns local device identity root (IR) */ 407 const Octet16& BTM_GetDeviceIDRoot(); 408 409 /** Return local device DHK. */ 410 const Octet16& BTM_GetDeviceDHK(); 411 412 /******************************************************************************* 413 * 414 * Function BTM_ReadConnectionAddr 415 * 416 * Description Read the local device random address. 417 * 418 * Returns void 419 * 420 ******************************************************************************/ 421 void BTM_ReadConnectionAddr(const RawAddress& remote_bda, 422 RawAddress& local_conn_addr, 423 tBLE_ADDR_TYPE* p_addr_type); 424 425 /******************************************************************************* 426 * 427 * Function BTM_ReadRemoteConnectionAddr 428 * 429 * Description Read the remote device address currently used. 430 * 431 * Returns void 432 * 433 ******************************************************************************/ 434 bool BTM_ReadRemoteConnectionAddr(const RawAddress& pseudo_addr, 435 RawAddress& conn_addr, 436 tBLE_ADDR_TYPE* p_addr_type); 437 438 /******************************************************************************* 439 * 440 * Function BTM_SecurityGrant 441 * 442 * Description This function is called to grant security process. 443 * 444 * Parameters bd_addr - peer device bd address. 445 * res - result of the operation BTM_SUCCESS if success. 446 * Otherwise, BTM_REPEATED_ATTEMPTS is too many 447 * attempts. 448 * 449 * Returns None 450 * 451 ******************************************************************************/ 452 void BTM_SecurityGrant(const RawAddress& bd_addr, uint8_t res); 453 454 /******************************************************************************* 455 * 456 * Function BTM_LeOobDataReply 457 * 458 * Description This function is called to provide the OOB data for 459 * SMP in response to BTM_LE_OOB_REQ_EVT 460 * 461 * Parameters: bd_addr - Address of the peer device 462 * res - result of the operation SMP_SUCCESS if success 463 * p_data - simple pairing Randomizer C. 464 * 465 ******************************************************************************/ 466 void BTM_BleOobDataReply(const RawAddress& bd_addr, uint8_t res, uint8_t len, 467 uint8_t* p_data); 468 469 /******************************************************************************* 470 * 471 * Function BTM_BleSecureConnectionOobDataReply 472 * 473 * Description This function is called to provide the OOB data for 474 * SMP in response to BTM_LE_OOB_REQ_EVT when secure connection 475 * data is available 476 * 477 * Parameters: bd_addr - Address of the peer device 478 * p_c - pointer to Confirmation 479 * p_r - pointer to Randomizer. 480 * 481 ******************************************************************************/ 482 void BTM_BleSecureConnectionOobDataReply(const RawAddress& bd_addr, 483 uint8_t* p_c, uint8_t* p_r); 484 485 /****************************************************************************** 486 * 487 * Function BTM_BleSetConnScanParams 488 * 489 * Description Set scan parameters used in BLE connection request 490 * 491 * Parameters: scan_interval - scan interval 492 * scan_window - scan window 493 * 494 * Returns void 495 * 496 ******************************************************************************/ 497 void BTM_BleSetConnScanParams(uint32_t scan_interval, uint32_t scan_window); 498 499 /******************************************************** 500 * 501 * Function BTM_BleSetPrefConnParams 502 * 503 * Description Set a peripheral's preferred connection parameters. When 504 * any of the value does not want to be updated while others 505 * do, use BTM_BLE_CONN_PARAM_UNDEF for the ones want to 506 * leave untouched. 507 * 508 * Parameters: bd_addr - BD address of the peripheral 509 * min_conn_int - minimum preferred connection interval 510 * max_conn_int - maximum preferred connection interval 511 * peripheral_latency - preferred peripheral latency 512 * supervision_tout - preferred supervision timeout 513 * 514 * Returns void 515 * 516 ******************************************************************************/ 517 void BTM_BleSetPrefConnParams(const RawAddress& bd_addr, uint16_t min_conn_int, 518 uint16_t max_conn_int, 519 uint16_t peripheral_latency, 520 uint16_t supervision_tout); 521 522 /******************************************************************************* 523 * 524 * Function BTM_ReadDevInfo 525 * 526 * Description This function is called to read the device/address type 527 * of BD address. 528 * 529 * Parameter remote_bda: remote device address 530 * p_dev_type: output parameter to read the device type. 531 * p_addr_type: output parameter to read the address type. 532 * 533 ******************************************************************************/ 534 void BTM_ReadDevInfo(const RawAddress& remote_bda, tBT_DEVICE_TYPE* p_dev_type, 535 tBLE_ADDR_TYPE* p_addr_type); 536 537 /******************************************************************************* 538 * 539 * Function BTM_ReadConnectedTransportAddress 540 * 541 * Description This function is called to read the paired device/address 542 * type of other device paired corresponding to the BD_address 543 * 544 * Parameter remote_bda: remote device address, carry out the transport 545 * address 546 * transport: active transport 547 * 548 * Return true if an active link is identified; false otherwise 549 * 550 ******************************************************************************/ 551 bool BTM_ReadConnectedTransportAddress(RawAddress* remote_bda, 552 tBT_TRANSPORT transport); 553 554 /******************************************************************************* 555 * 556 * Function BTM_UseLeLink 557 * 558 * Description Select the underlying physical link to use. 559 * 560 * Returns true to use LE, false use BR/EDR. 561 * 562 ******************************************************************************/ 563 bool BTM_UseLeLink(const RawAddress& bd_addr); 564 565 /******************************************************************************* 566 * 567 * Function BTM_BleReadPhy 568 * 569 * Description To read the current PHYs for specified LE connection 570 * 571 * 572 * Returns BTM_SUCCESS if success; otherwise failed. 573 * 574 ******************************************************************************/ 575 void BTM_BleReadPhy( 576 const RawAddress& bd_addr, 577 base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)> cb); 578 579 /******************************************************************************* 580 * 581 * Function BTM_BleSetPhy 582 * 583 * Description To set PHY preferences for specified LE connection 584 * 585 * 586 * Returns BTM_SUCCESS if success; otherwise failed. 587 * BTM_MODE_UNSUPPORTED if local controller doesn't support LE 588 * 2M or LE Coded PHY, 589 * BTM_ILLEGAL_VALUE if specified remote doesn't support LE 2M 590 * or LE Coded PHY, 591 * BTM_WRONG_MODE if Device in wrong mode for request. 592 * 593 ******************************************************************************/ 594 void BTM_BleSetPhy(const RawAddress& bd_addr, uint8_t tx_phys, uint8_t rx_phys, 595 uint16_t phy_options); 596 597 /******************************************************************************* 598 * 599 * Function BTM_BleDataSignature 600 * 601 * Description This function is called to sign the data using AES128 CMAC 602 * algorith. 603 * 604 * Parameter bd_addr: target device the data to be signed for. 605 * p_text: singing data 606 * len: length of the signing data 607 * signature: output parameter where data signature is going to 608 * be stored. 609 * 610 * Returns true if signing sucessul, otherwise false. 611 * 612 ******************************************************************************/ 613 bool BTM_BleDataSignature(const RawAddress& bd_addr, uint8_t* p_text, 614 uint16_t len, BLE_SIGNATURE signature); 615 616 /******************************************************************************* 617 * 618 * Function BTM_BleVerifySignature 619 * 620 * Description This function is called to verify the data signature 621 * 622 * Parameter bd_addr: target device the data to be signed for. 623 * p_orig: original data before signature. 624 * len: length of the signing data 625 * counter: counter used when doing data signing 626 * p_comp: signature to be compared against. 627 628 * Returns true if signature verified correctly; otherwise false. 629 * 630 ******************************************************************************/ 631 bool BTM_BleVerifySignature(const RawAddress& bd_addr, uint8_t* p_orig, 632 uint16_t len, uint32_t counter, uint8_t* p_comp); 633 634 /******************************************************************************* 635 * 636 * Function BTM_GetLeSecurityState 637 * 638 * Description This function is called to get security mode 1 flags and 639 * encryption key size for LE peer. 640 * 641 * Returns bool true if LE device is found, false otherwise. 642 * 643 ******************************************************************************/ 644 bool BTM_GetLeSecurityState(const RawAddress& bd_addr, 645 uint8_t* p_le_dev_sec_flags, 646 uint8_t* p_le_key_size); 647 648 /******************************************************************************* 649 * 650 * Function BTM_BleSecurityProcedureIsRunning 651 * 652 * Description This function indicates if LE security procedure is 653 * currently running with the peer. 654 * 655 * Returns bool true if security procedure is running, false otherwise. 656 * 657 ******************************************************************************/ 658 bool BTM_BleSecurityProcedureIsRunning(const RawAddress& bd_addr); 659 660 /******************************************************************************* 661 * 662 * Function BTM_BleGetSupportedKeySize 663 * 664 * Description This function gets the maximum encryption key size in bytes 665 * the local device can suport. 666 * record. 667 * 668 * Returns the key size or 0 if the size can't be retrieved. 669 * 670 ******************************************************************************/ 671 uint8_t BTM_BleGetSupportedKeySize(const RawAddress& bd_addr); 672 673 void BTM_LE_PF_local_name(tBTM_BLE_SCAN_COND_OP action, 674 tBTM_BLE_PF_FILT_INDEX filt_index, 675 std::vector<uint8_t> name, tBTM_BLE_PF_CFG_CBACK cb); 676 677 void BTM_LE_PF_srvc_data(tBTM_BLE_SCAN_COND_OP action, 678 tBTM_BLE_PF_FILT_INDEX filt_index); 679 680 void BTM_LE_PF_manu_data(tBTM_BLE_SCAN_COND_OP action, 681 tBTM_BLE_PF_FILT_INDEX filt_index, uint16_t company_id, 682 uint16_t company_id_mask, std::vector<uint8_t> data, 683 std::vector<uint8_t> data_mask, 684 tBTM_BLE_PF_CFG_CBACK cb); 685 686 void BTM_LE_PF_srvc_data_pattern(tBTM_BLE_SCAN_COND_OP action, 687 tBTM_BLE_PF_FILT_INDEX filt_index, 688 std::vector<uint8_t> data, 689 std::vector<uint8_t> data_mask, 690 tBTM_BLE_PF_CFG_CBACK cb); 691 692 void BTM_LE_PF_addr_filter(tBTM_BLE_SCAN_COND_OP action, 693 tBTM_BLE_PF_FILT_INDEX filt_index, tBLE_BD_ADDR addr, 694 tBTM_BLE_PF_CFG_CBACK cb); 695 696 void BTM_LE_PF_uuid_filter(tBTM_BLE_SCAN_COND_OP action, 697 tBTM_BLE_PF_FILT_INDEX filt_index, 698 tBTM_BLE_PF_COND_TYPE filter_type, 699 const bluetooth::Uuid& uuid, 700 tBTM_BLE_PF_LOGIC_TYPE cond_logic, 701 const bluetooth::Uuid& uuid_mask, 702 tBTM_BLE_PF_CFG_CBACK cb); 703 704 void BTM_LE_PF_set(tBTM_BLE_PF_FILT_INDEX filt_index, 705 std::vector<ApcfCommand> commands, tBTM_BLE_PF_CFG_CBACK cb); 706 void BTM_LE_PF_clear(tBTM_BLE_PF_FILT_INDEX filt_index, 707 tBTM_BLE_PF_CFG_CBACK cb); 708 709 /******************************************************************************* 710 * 711 * Function BTM_BleAdvFilterParamSetup 712 * 713 * Description This function is called to setup the adv data payload filter 714 * condition. 715 * 716 ******************************************************************************/ 717 void BTM_BleAdvFilterParamSetup( 718 tBTM_BLE_SCAN_COND_OP action, tBTM_BLE_PF_FILT_INDEX filt_index, 719 std::unique_ptr<btgatt_filt_param_setup_t> p_filt_params, 720 tBTM_BLE_PF_PARAM_CB cb); 721 722 /******************************************************************************* 723 * 724 * Function BTM_BleUpdateAdvFilterPolicy 725 * 726 * Description This function update the filter policy of advertiser. 727 * 728 * Parameter adv_policy: advertising filter policy 729 * 730 * Return void 731 ******************************************************************************/ 732 void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy); 733 734 /******************************************************************************* 735 * 736 * Function BTM_BleEnableDisableFilterFeature 737 * 738 * Description Enable or disable the APCF feature 739 * 740 * Parameters enable - true - enables APCF, false - disables APCF 741 * 742 ******************************************************************************/ 743 void BTM_BleEnableDisableFilterFeature(uint8_t enable, 744 tBTM_BLE_PF_STATUS_CBACK p_stat_cback); 745 746 /******************************************************************************* 747 * 748 * Function BTM_BleMaxMultiAdvInstanceCount 749 * 750 * Description Returns the maximum number of multi adv instances supported 751 * by the controller. 752 * 753 * Returns Max multi adv instance count 754 * 755 ******************************************************************************/ 756 uint8_t BTM_BleMaxMultiAdvInstanceCount(); 757 758 void BTM_reset_complete(); 759 760 /******************************************************************************* 761 * 762 * Function BTM_IsDeviceUp 763 * 764 * Description This function is called to check if the device is up. 765 * 766 * Returns true if device is up, else false 767 * 768 ******************************************************************************/ 769 bool BTM_IsDeviceUp(void); 770 771 /******************************************************************************* 772 * 773 * Function BTM_SetLocalDeviceName 774 * 775 * Description This function is called to set the local device name. 776 * 777 * Returns BTM_CMD_STARTED if successful, otherwise an error 778 * 779 ******************************************************************************/ 780 tBTM_STATUS BTM_SetLocalDeviceName(const char* p_name); 781 782 /******************************************************************************* 783 * 784 * Function BTM_SetDeviceClass 785 * 786 * Description This function is called to set the local device class 787 * 788 * Returns BTM_SUCCESS if successful, otherwise an error 789 * 790 ******************************************************************************/ 791 tBTM_STATUS BTM_SetDeviceClass(DEV_CLASS dev_class); 792 793 /******************************************************************************* 794 * 795 * Function BTM_ReadLocalDeviceName 796 * 797 * Description This function is called to read the local device name. 798 * 799 * Returns status of the operation 800 * If success, BTM_SUCCESS is returned and p_name points stored 801 * local device name 802 * If BTM doesn't store local device name, BTM_NO_RESOURCES is 803 * is returned and p_name is set to NULL 804 * 805 ******************************************************************************/ 806 tBTM_STATUS BTM_ReadLocalDeviceName(const char** p_name); 807 808 /******************************************************************************* 809 * 810 * Function BTM_ReadLocalDeviceNameFromController 811 * 812 * Description Get local device name from controller. Do not use cached 813 * name (used to get chip-id prior to btm reset complete). 814 * 815 * Returns BTM_CMD_STARTED if successful, otherwise an error 816 * 817 ******************************************************************************/ 818 tBTM_STATUS BTM_ReadLocalDeviceNameFromController( 819 tBTM_CMPL_CB* p_rln_cmpl_cback); 820 821 /******************************************************************************* 822 * 823 * Function BTM_ReadDeviceClass 824 * 825 * Description This function is called to read the local device class 826 * 827 * Returns pointer to the device class 828 * 829 ******************************************************************************/ 830 uint8_t* BTM_ReadDeviceClass(void); 831 832 /******************************************************************************* 833 * 834 * Function BTM_RegisterForVSEvents 835 * 836 * Description This function is called to register/deregister for vendor 837 * specific HCI events. 838 * 839 * If is_register=true, then the function will be registered; 840 * otherwise the function will be deregistered. 841 * 842 * Returns BTM_SUCCESS if successful, 843 * BTM_BUSY if maximum number of callbacks have already been 844 * registered. 845 * 846 ******************************************************************************/ 847 tBTM_STATUS BTM_RegisterForVSEvents(tBTM_VS_EVT_CB* p_cb, bool is_register); 848 849 /******************************************************************************* 850 * 851 * Function BTM_VendorSpecificCommand 852 * 853 * Description Send a vendor specific HCI command to the controller. 854 * 855 ******************************************************************************/ 856 void BTM_VendorSpecificCommand(uint16_t opcode, uint8_t param_len, 857 uint8_t* p_param_buf, tBTM_VSC_CMPL_CB* p_cb); 858 859 /******************************************************************************* 860 * 861 * Function BTM_AllocateSCN 862 * 863 * Description Look through the Server Channel Numbers for a free one to be 864 * used with an RFCOMM connection. 865 * 866 * Returns Allocated SCN number or 0 if none. 867 * 868 ******************************************************************************/ 869 uint8_t BTM_AllocateSCN(void); 870 871 /******************************************************************************* 872 * 873 * Function BTM_TryAllocateSCN 874 * 875 * Description Try to allocate a fixed server channel 876 * 877 * Returns Returns true if server channel was available 878 * 879 ******************************************************************************/ 880 bool BTM_TryAllocateSCN(uint8_t scn); 881 882 /******************************************************************************* 883 * 884 * Function BTM_FreeSCN 885 * 886 * Description Free the specified SCN. 887 * 888 * Returns true if successful, false if SCN is not in use or invalid 889 * 890 ******************************************************************************/ 891 bool BTM_FreeSCN(uint8_t scn); 892 893 /******************************************************************************* 894 * 895 * Function BTM_SetTraceLevel 896 * 897 * Description This function sets the trace level for BTM. If called with 898 * a value of 0xFF, it simply returns the current trace level. 899 * 900 * Returns The new or current trace level 901 * 902 ******************************************************************************/ 903 uint8_t BTM_SetTraceLevel(uint8_t new_level); 904 905 /******************************************************************************* 906 * 907 * Function BTM_WritePageTimeout 908 * 909 * Description Send HCI Wite Page Timeout. 910 * 911 ******************************************************************************/ 912 void BTM_WritePageTimeout(uint16_t timeout); 913 914 /******************************************************************************* 915 * 916 * Function BTM_WriteVoiceSettings 917 * 918 * Description Send HCI Write Voice Settings command. 919 * See hcidefs.h for settings bitmask values. 920 * 921 ******************************************************************************/ 922 void BTM_WriteVoiceSettings(uint16_t settings); 923 924 /******************************************************************************* 925 * 926 * Function BTM_ReadRemoteVersion 927 * 928 * Description This function is called to read a remote device's version 929 * 930 * Returns true if valid, false otherwise 931 * 932 ******************************************************************************/ 933 bool BTM_ReadRemoteVersion(const RawAddress& addr, uint8_t* lmp_version, 934 uint16_t* manufacturer, uint16_t* lmp_sub_version); 935 936 /******************************************************************************* 937 * 938 * Function BTM_ReadRemoteFeatures 939 * 940 * Description This function is called to read a remote device's 941 * supported features mask (features mask located at page 0) 942 * 943 * Returns pointer to the remote supported features mask 944 * The size of device features mask page is 945 * HCI_FEATURE_BYTES_PER_PAGE bytes. 946 * 947 ******************************************************************************/ 948 uint8_t* BTM_ReadRemoteFeatures(const RawAddress& addr); 949 950 /***************************************************************************** 951 * ACL CHANNEL MANAGEMENT FUNCTIONS 952 ****************************************************************************/ 953 void BTM_unblock_sniff_mode_for(const RawAddress& peer_addr); 954 void BTM_block_sniff_mode_for(const RawAddress& peer_addr); 955 void BTM_unblock_role_switch_for(const RawAddress& peer_addr); 956 void BTM_block_role_switch_for(const RawAddress& peer_addr); 957 958 void BTM_default_unblock_role_switch(); 959 void BTM_default_block_role_switch(); 960 961 /******************************************************************************* 962 * 963 * Function BTM_SetDefaultLinkSuperTout 964 * 965 * Description Set the default value for HCI "Write Link Supervision 966 * Timeout" command to use when an ACL link is created. 967 * 968 * Returns void 969 * 970 ******************************************************************************/ 971 void BTM_SetDefaultLinkSuperTout(uint16_t timeout); 972 973 /******************************************************************************* 974 * 975 * Function BTM_SetLinkSuperTout 976 * 977 * Description Create and send HCI "Write Link Supervision Timeout" command 978 * 979 * Returns BTM_CMD_STARTED if successfully initiated, otherwise error 980 * 981 ******************************************************************************/ 982 tBTM_STATUS BTM_SetLinkSuperTout(const RawAddress& remote_bda, 983 uint16_t timeout); 984 /******************************************************************************* 985 * 986 * Function BTM_GetLinkSuperTout 987 * 988 * Description Read the link supervision timeout value of the connection 989 * 990 * Returns status of the operation 991 * 992 ******************************************************************************/ 993 tBTM_STATUS BTM_GetLinkSuperTout(const RawAddress& remote_bda, 994 uint16_t* p_timeout); 995 996 /******************************************************************************* 997 * 998 * Function BTM_IsAclConnectionUp 999 * 1000 * Description This function is called to check if an ACL connection exists 1001 * to a specific remote BD Address. 1002 * 1003 * Returns true if connection is up, else false. 1004 * 1005 ******************************************************************************/ 1006 bool BTM_IsAclConnectionUp(const RawAddress& remote_bda, 1007 tBT_TRANSPORT transport); 1008 1009 /******************************************************************************* 1010 * 1011 * Function BTM_GetRole 1012 * 1013 * Description This function is called to get the role of the local device 1014 * for the ACL connection with the specified remote device 1015 * 1016 * Returns BTM_SUCCESS if connection exists. 1017 * BTM_UNKNOWN_ADDR if no active link with bd addr specified 1018 * 1019 ******************************************************************************/ 1020 tBTM_STATUS BTM_GetRole(const RawAddress& remote_bd_addr, tHCI_ROLE* p_role); 1021 1022 /******************************************************************************* 1023 * 1024 * Function BTM_SwitchRole 1025 * 1026 * Description This function is called to switch role between central and 1027 * peripheral. If role is already set it will do nothing. 1028 * 1029 * Returns BTM_SUCCESS if already in specified role. 1030 * BTM_CMD_STARTED if command issued to controller. 1031 * BTM_NO_RESOURCES if memory couldn't be allocated to issue 1032 * the command 1033 * BTM_UNKNOWN_ADDR if no active link with bd addr specified 1034 * BTM_MODE_UNSUPPORTED if the local device does not support 1035 * role switching 1036 * 1037 ******************************************************************************/ 1038 tBTM_STATUS BTM_SwitchRole(const RawAddress& remote_bd_addr, uint8_t new_role); 1039 1040 /******************************************************************************* 1041 * 1042 * Function BTM_ReadRSSI 1043 * 1044 * Description This function is called to read the link policy settings. 1045 * The address of link policy results are returned in the 1046 * callback. (tBTM_RSSI_RESULT) 1047 * 1048 * Returns BTM_CMD_STARTED if command issued to controller. 1049 * BTM_NO_RESOURCES if memory couldn't be allocated to issue 1050 * the command 1051 * BTM_UNKNOWN_ADDR if no active link with bd addr specified 1052 * BTM_BUSY if command is already in progress 1053 * 1054 ******************************************************************************/ 1055 tBTM_STATUS BTM_ReadRSSI(const RawAddress& remote_bda, tBTM_CMPL_CB* p_cb); 1056 1057 /******************************************************************************* 1058 * 1059 * Function BTM_ReadFailedContactCounter 1060 * 1061 * Description This function is called to read the failed contact counter. 1062 * The result is returned in the callback. 1063 * (tBTM_FAILED_CONTACT_COUNTER_RESULT) 1064 * 1065 * Returns BTM_CMD_STARTED if command issued to controller. 1066 * BTM_NO_RESOURCES if memory couldn't be allocated to issue 1067 * the command 1068 * BTM_UNKNOWN_ADDR if no active link with bd addr specified 1069 * BTM_BUSY if command is already in progress 1070 * 1071 ******************************************************************************/ 1072 tBTM_STATUS BTM_ReadFailedContactCounter(const RawAddress& remote_bda, 1073 tBTM_CMPL_CB* p_cb); 1074 1075 /******************************************************************************* 1076 * 1077 * Function BTM_ReadAutomaticFlushTimeout 1078 * 1079 * Description This function is called to read the automatic flush timeout. 1080 * The result is returned in the callback. 1081 * (tBTM_AUTOMATIC_FLUSH_TIMEOUT_RESULT) 1082 * 1083 * Returns BTM_CMD_STARTED if command issued to controller. 1084 * BTM_NO_RESOURCES if memory couldn't be allocated to issue 1085 * the command 1086 * BTM_UNKNOWN_ADDR if no active link with bd addr specified 1087 * BTM_BUSY if command is already in progress 1088 * 1089 ******************************************************************************/ 1090 tBTM_STATUS BTM_ReadAutomaticFlushTimeout(const RawAddress& remote_bda, 1091 tBTM_CMPL_CB* p_cb); 1092 1093 /******************************************************************************* 1094 * 1095 * Function BTM_ReadTxPower 1096 * 1097 * Description This function is called to read the current connection 1098 * TX power of the connection. The TX power level results 1099 * are returned in the callback. 1100 * (tBTM_RSSI_RESULT) 1101 * 1102 * Returns BTM_CMD_STARTED if command issued to controller. 1103 * BTM_NO_RESOURCES if memory couldn't be allocated to issue 1104 * the command 1105 * BTM_UNKNOWN_ADDR if no active link with bd addr specified 1106 * BTM_BUSY if command is already in progress 1107 * 1108 ******************************************************************************/ 1109 tBTM_STATUS BTM_ReadTxPower(const RawAddress& remote_bda, 1110 tBT_TRANSPORT transport, tBTM_CMPL_CB* p_cb); 1111 1112 /***************************************************************************** 1113 * (e)SCO CHANNEL MANAGEMENT FUNCTIONS 1114 ****************************************************************************/ 1115 /******************************************************************************* 1116 * 1117 * Function BTM_CreateSco 1118 * 1119 * Description This function is called to create an SCO connection. If the 1120 * "is_orig" flag is true, the connection will be originated, 1121 * otherwise BTM will wait for the other side to connect. 1122 * 1123 * Returns BTM_UNKNOWN_ADDR if the ACL connection is not up 1124 * BTM_BUSY if another SCO being set up to 1125 * the same BD address 1126 * BTM_NO_RESOURCES if the max SCO limit has been reached 1127 * BTM_CMD_STARTED if the connection establishment is started. 1128 * In this case, "*p_sco_inx" is filled in 1129 * with the sco index used for the connection. 1130 * 1131 ******************************************************************************/ 1132 tBTM_STATUS BTM_CreateSco(const RawAddress* remote_bda, bool is_orig, 1133 uint16_t pkt_types, uint16_t* p_sco_inx, 1134 tBTM_SCO_CB* p_conn_cb, tBTM_SCO_CB* p_disc_cb); 1135 1136 /******************************************************************************* 1137 * 1138 * Function BTM_RemoveSco 1139 * 1140 * Description This function is called to remove a specific SCO connection. 1141 * 1142 * Returns BTM_CMD_STARTED if successfully initiated, otherwise error 1143 * 1144 ******************************************************************************/ 1145 tBTM_STATUS BTM_RemoveSco(uint16_t sco_inx); 1146 1147 /******************************************************************************* 1148 * 1149 * Function BTM_ReadScoBdAddr 1150 * 1151 * Description This function is read the remote BD Address for a specific 1152 * SCO connection, 1153 * 1154 * Returns pointer to BD address or NULL if not known 1155 * 1156 ******************************************************************************/ 1157 const RawAddress* BTM_ReadScoBdAddr(uint16_t sco_inx); 1158 1159 /******************************************************************************* 1160 * 1161 * Function BTM_SetEScoMode 1162 * 1163 * Description This function sets up the negotiated parameters for SCO or 1164 * eSCO, and sets as the default mode used for calls to 1165 * BTM_CreateSco. It can be called only when there are no 1166 * active (e)SCO links. 1167 * 1168 * Returns BTM_SUCCESS if the successful. 1169 * BTM_BUSY if there are one or more active (e)SCO links. 1170 * 1171 ******************************************************************************/ 1172 tBTM_STATUS BTM_SetEScoMode(enh_esco_params_t* p_parms); 1173 1174 /******************************************************************************* 1175 * 1176 * Function BTM_RegForEScoEvts 1177 * 1178 * Description This function registers a SCO event callback with the 1179 * specified instance. It should be used to received 1180 * connection indication events and change of link parameter 1181 * events. 1182 * 1183 * Returns BTM_SUCCESS if the successful. 1184 * BTM_ILLEGAL_VALUE if there is an illegal sco_inx 1185 * 1186 ******************************************************************************/ 1187 tBTM_STATUS BTM_RegForEScoEvts(uint16_t sco_inx, tBTM_ESCO_CBACK* p_esco_cback); 1188 1189 /******************************************************************************* 1190 * 1191 * Function BTM_EScoConnRsp 1192 * 1193 * Description This function is called upon receipt of an (e)SCO connection 1194 * request event (BTM_ESCO_CONN_REQ_EVT) to accept or reject 1195 * the request. Parameters used to negotiate eSCO links. 1196 * If p_parms is NULL, then values set through BTM_SetEScoMode 1197 * are used. 1198 * If the link type of the incoming request is SCO, then only 1199 * the tx_bw, max_latency, content format, and packet_types are 1200 * valid. The hci_status parameter should be 1201 * ([0x0] to accept, [0x0d..0x0f] to reject) 1202 * 1203 * 1204 * Returns void 1205 * 1206 ******************************************************************************/ 1207 void BTM_EScoConnRsp(uint16_t sco_inx, uint8_t hci_status, 1208 enh_esco_params_t* p_parms); 1209 1210 /******************************************************************************* 1211 * 1212 * Function BTM_GetNumScoLinks 1213 * 1214 * Description This function returns the number of active SCO links. 1215 * 1216 * Returns uint8_t 1217 * 1218 ******************************************************************************/ 1219 uint8_t BTM_GetNumScoLinks(void); 1220 1221 /***************************************************************************** 1222 * SECURITY MANAGEMENT FUNCTIONS 1223 ****************************************************************************/ 1224 /******************************************************************************* 1225 * 1226 * Function BTM_SecRegister 1227 * 1228 * Description Application manager calls this function to register for 1229 * security services. There can be one and only one 1230 * application saving link keys. BTM allows only first 1231 * registration. 1232 * 1233 * Returns true if registered OK, else false 1234 * 1235 ******************************************************************************/ 1236 bool BTM_SecRegister(const tBTM_APPL_INFO* p_cb_info); 1237 1238 /******************************************************************************* 1239 * 1240 * Function BTM_SecAddRmtNameNotifyCallback 1241 * 1242 * Description Profiles can register to be notified when name of the 1243 * remote device is resolved (up to 1244 * BTM_SEC_MAX_RMT_NAME_CALLBACKS). 1245 * 1246 * Returns true if registered OK, else false 1247 * 1248 ******************************************************************************/ 1249 bool BTM_SecAddRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback); 1250 1251 /******************************************************************************* 1252 * 1253 * Function BTM_SecDeleteRmtNameNotifyCallback 1254 * 1255 * Description A profile can deregister notification when a new Link Key 1256 * is generated per connection. 1257 * 1258 * Returns true if OK, else false 1259 * 1260 ******************************************************************************/ 1261 bool BTM_SecDeleteRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback); 1262 1263 /******************************************************************************* 1264 * 1265 * Function BTM_GetSecurityFlagsByTransport 1266 * 1267 * Description Get security flags for the device on a particular transport 1268 * 1269 * Parameters bd_addr: BD address of remote device 1270 * p_sec_flags : Out parameter to be filled with security 1271 * flags for the connection 1272 * transport : Physical transport of the connection 1273 * (BR/EDR or LE) 1274 * 1275 * Returns bool true or false is device found 1276 * 1277 ******************************************************************************/ 1278 bool BTM_GetSecurityFlagsByTransport(const RawAddress& bd_addr, 1279 uint8_t* p_sec_flags, 1280 tBT_TRANSPORT transport); 1281 1282 /******************************************************************************* 1283 * 1284 * Function BTM_SetPinType 1285 * 1286 * Description Set PIN type for the device. 1287 * 1288 * Returns void 1289 * 1290 ******************************************************************************/ 1291 void BTM_SetPinType(uint8_t pin_type, PIN_CODE pin_code, uint8_t pin_code_len); 1292 1293 /******************************************************************************* 1294 * 1295 * Function BTM_SetSecurityLevel 1296 * 1297 * Description Register service security level with Security Manager. Each 1298 * service must register its requirements regardless of the 1299 * security level that is used. This API is called once for 1300 * originators and again for acceptors of connections. 1301 * 1302 * Returns true if registered OK, else false 1303 * 1304 ******************************************************************************/ 1305 bool BTM_SetSecurityLevel(bool is_originator, const char* p_name, 1306 uint8_t service_id, uint16_t sec_level, uint16_t psm, 1307 uint32_t mx_proto_id, uint32_t mx_chan_id); 1308 1309 /******************************************************************************* 1310 * 1311 * Function BTM_SecClrService 1312 * 1313 * Description Removes specified service record(s) from the security 1314 * database. All service records with the specified name are 1315 * removed. Typically used only by devices with limited RAM 1316 * so that it can reuse an old security service record. 1317 * 1318 * Returns Number of records that were freed. 1319 * 1320 ******************************************************************************/ 1321 uint8_t BTM_SecClrService(uint8_t service_id); 1322 1323 /******************************************************************************* 1324 * 1325 * Function BTM_SecAddDevice 1326 * 1327 * Description Add/modify device. This function will be normally called 1328 * during host startup to restore all required information 1329 * stored in the NVRAM. 1330 * dev_class, bd_name, link_key, and features are NULL if 1331 * unknown 1332 * 1333 * Returns true if added OK, else false 1334 * 1335 ******************************************************************************/ 1336 bool BTM_SecAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class, 1337 const BD_NAME& bd_name, uint8_t* features, 1338 LinkKey* link_key, uint8_t key_type, uint8_t pin_length); 1339 1340 /** Free resources associated with the device associated with |bd_addr| address. 1341 * 1342 * *** WARNING *** 1343 * tBTM_SEC_DEV_REC associated with bd_addr becomes invalid after this function 1344 * is called, also any of it's fields. i.e. if you use p_dev_rec->bd_addr, it is 1345 * no longer valid! 1346 * *** WARNING *** 1347 * 1348 * Returns true if removed OK, false if not found or ACL link is active. 1349 */ 1350 bool BTM_SecDeleteDevice(const RawAddress& bd_addr); 1351 1352 /******************************************************************************* 1353 * 1354 * Function BTM_SecClearSecurityFlags 1355 * 1356 * Description Reset the security flags (mark as not-paired) for a given 1357 * remove device. 1358 * 1359 ******************************************************************************/ 1360 void BTM_SecClearSecurityFlags(const RawAddress& bd_addr); 1361 1362 /******************************************************************************* 1363 * 1364 * Function BTM_SecGetDeviceLinkKeyType 1365 * 1366 * Description This function is called to obtain link key type for the 1367 * device. 1368 * it returns BTM_SUCCESS if link key is available, or 1369 * BTM_UNKNOWN_ADDR if Security Manager does not know about 1370 * the device or device record does not contain link key info 1371 * 1372 * Returns BTM_LKEY_TYPE_IGNORE if link key is unknown, link type 1373 * otherwise. 1374 * 1375 ******************************************************************************/ 1376 tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType(const RawAddress& bd_addr); 1377 1378 /******************************************************************************* 1379 * 1380 * Function BTM_PINCodeReply 1381 * 1382 * Description This function is called after Security Manager submitted 1383 * PIN code request to the UI. 1384 * 1385 * Parameters: bd_addr - Address of the device for which PIN was 1386 * requested 1387 * res - result of the operation BTM_SUCCESS if 1388 * success 1389 * pin_len - length in bytes of the PIN Code 1390 * p_pin - pointer to array with the PIN Code 1391 * 1392 * Returns void 1393 * 1394 ******************************************************************************/ 1395 void BTM_PINCodeReply(const RawAddress& bd_addr, tBTM_STATUS res, 1396 uint8_t pin_len, uint8_t* p_pin); 1397 1398 /******************************************************************************* 1399 * 1400 * Function BTM_SecBond 1401 * 1402 * Description Perform bonding by designated transport 1403 * 1404 * Parameters: bd_addr - Address of the device to bond 1405 * addr_type - address type for LE transport 1406 * pin_len - length in bytes of the PIN Code 1407 * p_pin - pointer to array with the PIN Code 1408 * transport : Physical transport to use for bonding 1409 * (BR/EDR or LE) 1410 * 1411 * Returns BTM_CMD_STARTED if successfully initiated, otherwise error 1412 * 1413 ******************************************************************************/ 1414 tBTM_STATUS BTM_SecBond(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type, 1415 tBT_TRANSPORT transport, tBT_DEVICE_TYPE device_type); 1416 1417 /******************************************************************************* 1418 * 1419 * Function BTM_SecBondCancel 1420 * 1421 * Description This function is called to cancel ongoing bonding process 1422 * with peer device. 1423 * 1424 * Returns BTM_CMD_STARTED if successfully initiated, otherwise error 1425 * 1426 ******************************************************************************/ 1427 tBTM_STATUS BTM_SecBondCancel(const RawAddress& bd_addr); 1428 1429 /******************************************************************************* 1430 * 1431 * Function BTM_SetEncryption 1432 * 1433 * Description This function is called to ensure that connection is 1434 * encrypted. Should be called only on an open connection. 1435 * Typically only needed for connections that first want to 1436 * bring up unencrypted links, then later encrypt them. 1437 * 1438 * Parameters: bd_addr - Address of the peer device 1439 * transport - Link transport 1440 * p_callback - Pointer to callback function called if 1441 * this function returns PENDING after required 1442 * procedures are completed. Can be set to 1443 * NULL if status is not desired. 1444 * p_ref_data - pointer to any data the caller wishes to 1445 * receive in the callback function upon 1446 * completion. 1447 * can be set to NULL if not used. 1448 * sec_act - LE security action, unused for BR/EDR 1449 * 1450 * Returns BTM_SUCCESS - already encrypted 1451 * BTM_PENDING - command will be returned in the callback 1452 * BTM_WRONG_MODE- connection not up. 1453 * BTM_BUSY - security procedures are currently active 1454 * BTM_MODE_UNSUPPORTED - if security manager not linked in. 1455 * 1456 ******************************************************************************/ 1457 tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr, 1458 tBT_TRANSPORT transport, 1459 tBTM_SEC_CALLBACK* p_callback, void* p_ref_data, 1460 tBTM_BLE_SEC_ACT sec_act); 1461 1462 /******************************************************************************* 1463 * 1464 * Function BTM_ConfirmReqReply 1465 * 1466 * Description This function is called to confirm the numeric value for 1467 * Simple Pairing in response to BTM_SP_CFM_REQ_EVT 1468 * 1469 * Parameters: res - result of the operation BTM_SUCCESS if 1470 * success 1471 * bd_addr - Address of the peer device 1472 * 1473 ******************************************************************************/ 1474 void BTM_ConfirmReqReply(tBTM_STATUS res, const RawAddress& bd_addr); 1475 1476 /******************************************************************************* 1477 * 1478 * Function BTM_PasskeyReqReply 1479 * 1480 * Description This function is called to provide the passkey for 1481 * Simple Pairing in response to BTM_SP_KEY_REQ_EVT 1482 * 1483 * Parameters: res - result of the operation BTM_SUCCESS if 1484 * success 1485 * bd_addr - Address of the peer device 1486 * passkey - numeric value in the range of 1487 * 0 - 999999(0xF423F). 1488 * 1489 ******************************************************************************/ 1490 void BTM_PasskeyReqReply(tBTM_STATUS res, const RawAddress& bd_addr, 1491 uint32_t passkey); 1492 1493 /******************************************************************************* 1494 * 1495 * Function BTM_IoCapRsp 1496 * 1497 * Description This function is called in response to BTM_SP_IO_REQ_EVT 1498 * When the event data io_req.oob_data is set to 1499 * BTM_OOB_UNKNOWN by the tBTM_SP_CALLBACK implementation, this 1500 * function is called to provide the actual response 1501 * 1502 * Parameters: bd_addr - Address of the peer device 1503 * io_cap - The IO capability of local device. 1504 * oob - BTM_OOB_NONE or BTM_OOB_PRESENT. 1505 * auth_req- MITM protection required or not. 1506 * 1507 ******************************************************************************/ 1508 void BTM_IoCapRsp(const RawAddress& bd_addr, tBTM_IO_CAP io_cap, 1509 tBTM_OOB_DATA oob, tBTM_AUTH_REQ auth_req); 1510 1511 /******************************************************************************* 1512 * 1513 * Function BTM_ReadLocalOobData 1514 * 1515 * Description This function is called to read the local OOB data from 1516 * LM 1517 * 1518 ******************************************************************************/ 1519 void BTM_ReadLocalOobData(void); 1520 1521 /******************************************************************************* 1522 * 1523 * Function BTM_RemoteOobDataReply 1524 * 1525 * Description This function is called to provide the remote OOB data for 1526 * Simple Pairing in response to BTM_SP_RMT_OOB_EVT 1527 * 1528 * Parameters: bd_addr - Address of the peer device 1529 * c - simple pairing Hash C. 1530 * r - simple pairing Randomizer C. 1531 * 1532 ******************************************************************************/ 1533 void BTM_RemoteOobDataReply(tBTM_STATUS res, const RawAddress& bd_addr, 1534 const Octet16& c, const Octet16& r); 1535 1536 /******************************************************************************* 1537 * 1538 * Function BTM_BothEndsSupportSecureConnections 1539 * 1540 * Description This function is called to check if both the local device 1541 * and the peer device specified by bd_addr support BR/EDR 1542 * Secure Connections. 1543 * 1544 * Parameters: bd_addr - address of the peer 1545 * 1546 * Returns true if BR/EDR Secure Connections are supported by both 1547 * local and the remote device. 1548 * else false. 1549 * 1550 ******************************************************************************/ 1551 bool BTM_BothEndsSupportSecureConnections(const RawAddress& bd_addr); 1552 1553 /******************************************************************************* 1554 * 1555 * Function BTM_PeerSupportsSecureConnections 1556 * 1557 * Description This function is called to check if the peer supports 1558 * BR/EDR Secure Connections. 1559 * 1560 * Parameters: bd_addr - address of the peer 1561 * 1562 * Returns true if BR/EDR Secure Connections are supported by the peer, 1563 * else false. 1564 * 1565 ******************************************************************************/ 1566 bool BTM_PeerSupportsSecureConnections(const RawAddress& bd_addr); 1567 1568 /******************************************************************************* 1569 * 1570 * Function BTM_GetPeerDeviceTypeFromFeatures 1571 * 1572 * Description This function is called to retrieve the peer device type 1573 * by referencing the remote features. 1574 * 1575 * Parameters: bd_addr - address of the peer 1576 * 1577 * Returns BT_DEVICE_TYPE_DUMO if both BR/EDR and BLE transports are 1578 * supported by the peer, 1579 * BT_DEVICE_TYPE_BREDR if only BR/EDR transport is supported, 1580 * BT_DEVICE_TYPE_BLE if only BLE transport is supported. 1581 * 1582 ******************************************************************************/ 1583 tBT_DEVICE_TYPE BTM_GetPeerDeviceTypeFromFeatures(const RawAddress& bd_addr); 1584 1585 /******************************************************************************* 1586 * 1587 * Function BTM_SecReadDevName 1588 * 1589 * Description Looks for the device name in the security database for the 1590 * specified BD address. 1591 * 1592 * Returns Pointer to the name or NULL 1593 * 1594 ******************************************************************************/ 1595 char* BTM_SecReadDevName(const RawAddress& bd_addr); 1596 1597 /******************************************************************************* 1598 * 1599 * Function BTM_GetHCIConnHandle 1600 * 1601 * Description This function is called to get the handle for an ACL 1602 * connection to a specific remote BD Address. 1603 * 1604 * Returns the handle of the connection, or 0xFFFF if none. 1605 * 1606 ******************************************************************************/ 1607 uint16_t BTM_GetHCIConnHandle(const RawAddress& remote_bda, 1608 tBT_TRANSPORT transport); 1609 1610 /******************************************************************************* 1611 * 1612 * Function BTM_DeleteStoredLinkKey 1613 * 1614 * Description This function is called to delete link key for the specified 1615 * device addresses from the NVRAM storage attached to the 1616 * Bluetooth controller. 1617 * 1618 * Parameters: bd_addr - Addresses of the devices 1619 * p_cb - Call back function to be called to return 1620 * the results 1621 * 1622 ******************************************************************************/ 1623 tBTM_STATUS BTM_DeleteStoredLinkKey(const RawAddress* bd_addr, 1624 tBTM_CMPL_CB* p_cb); 1625 1626 tBTM_CONTRL_STATE BTM_PM_ReadControllerState(void); 1627 1628 /** 1629 * 1630 * BLE API 1631 */ 1632 1633 /** 1634 * This function is called to set scan parameters. |cb| is called with operation 1635 * status 1636 **/ 1637 void BTM_BleSetScanParams(uint32_t scan_interval, uint32_t scan_window, 1638 tBLE_SCAN_MODE scan_type, 1639 base::Callback<void(uint8_t)> cb); 1640 1641 /******************************************************************************* 1642 * 1643 * Function BTM_BleGetVendorCapabilities 1644 * 1645 * Description This function reads local LE features 1646 * 1647 * Parameters p_cmn_vsc_cb : Locala LE capability structure 1648 * 1649 * Returns void 1650 * 1651 ******************************************************************************/ 1652 void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB* p_cmn_vsc_cb); 1653 1654 /******************************************************************************* 1655 * 1656 * Function BTM_BleSetStorageConfig 1657 * 1658 * Description This function is called to setup storage configuration and 1659 * setup callbacks. 1660 * 1661 * Parameters uint8_t batch_scan_full_max -Batch scan full maximum 1662 * uint8_t batch_scan_trunc_max - Batch scan truncated value 1663 *maximum uint8_t batch_scan_notify_threshold - Threshold value cb - Setup 1664 *callback tBTM_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback -Threshold callback void 1665 **p_ref - Reference value 1666 * 1667 * 1668 ******************************************************************************/ 1669 void BTM_BleSetStorageConfig(uint8_t batch_scan_full_max, 1670 uint8_t batch_scan_trunc_max, 1671 uint8_t batch_scan_notify_threshold, 1672 base::Callback<void(uint8_t /* status */)> cb, 1673 tBTM_BLE_SCAN_THRESHOLD_CBACK* p_thres_cback, 1674 tBTM_BLE_REF_VALUE ref_value); 1675 1676 /* This function is called to enable batch scan */ 1677 void BTM_BleEnableBatchScan(tBTM_BLE_BATCH_SCAN_MODE scan_mode, 1678 uint32_t scan_interval, uint32_t scan_window, 1679 tBTM_BLE_DISCARD_RULE discard_rule, 1680 tBLE_ADDR_TYPE addr_type, 1681 base::Callback<void(uint8_t /* status */)> cb); 1682 1683 /* This function is called to disable batch scanning */ 1684 void BTM_BleDisableBatchScan(base::Callback<void(uint8_t /* status */)> cb); 1685 1686 /* This function is called to read batch scan reports */ 1687 void BTM_BleReadScanReports(tBLE_SCAN_MODE scan_mode, 1688 tBTM_BLE_SCAN_REP_CBACK cb); 1689 1690 /* This function is called to setup the callback for tracking */ 1691 void BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK* p_track_cback, 1692 tBTM_BLE_REF_VALUE ref_value); 1693 1694 /****************************************************************************** 1695 * 1696 * Function BTM_BleReadControllerFeatures 1697 * 1698 * Description Reads BLE specific controller features 1699 * 1700 * Parameters: tBTM_BLE_CTRL_FEATURES_CBACK : Callback to notify when 1701 * features are read 1702 * 1703 * Returns void 1704 * 1705 ******************************************************************************/ 1706 void BTM_BleReadControllerFeatures(tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback); 1707 1708 /******************************************************************************* 1709 * 1710 * Function BTM__BLEReadDiscoverability 1711 * 1712 * Description This function is called to read the current LE 1713 * discoverability mode of the device. 1714 * 1715 * Returns BTM_BLE_NON_DISCOVERABLE ,BTM_BLE_LIMITED_DISCOVERABLE or 1716 * BTM_BLE_GENRAL_DISCOVERABLE 1717 * 1718 ******************************************************************************/ 1719 uint16_t BTM_BleReadDiscoverability(); 1720 1721 /******************************************************************************* 1722 * 1723 * Function BTM__BLEReadConnectability 1724 * 1725 * Description This function is called to read the current LE 1726 * connectibility mode of the device. 1727 * 1728 * Returns BTM_BLE_NON_CONNECTABLE or BTM_BLE_CONNECTABLE 1729 * 1730 ******************************************************************************/ 1731 uint16_t BTM_BleReadConnectability(); 1732 1733 /******************************************************************************* 1734 * 1735 * Function BTM_BleConfigPrivacy 1736 * 1737 * Description This function is called to enable or disable the privacy in 1738 * the local device. 1739 * 1740 * Parameters enable: true to enable it; false to disable it. 1741 * 1742 * Returns bool privacy mode set success; otherwise failed. 1743 * 1744 ******************************************************************************/ 1745 bool BTM_BleConfigPrivacy(bool enable); 1746 1747 /******************************************************************************* 1748 * 1749 * Function BTM_BleLocalPrivacyEnabled 1750 * 1751 * Description Checks if local device supports private address 1752 * 1753 * Returns Return true if local privacy is enabled else false 1754 * 1755 ******************************************************************************/ 1756 bool BTM_BleLocalPrivacyEnabled(void); 1757 1758 /** 1759 * This functions are called to configure the adv data payload filter condition 1760 */ 1761 /******************************************************************************* 1762 * 1763 * Function BTM_BleGetEnergyInfo 1764 * 1765 * Description This function obtains the energy info 1766 * 1767 * Parameters p_ener_cback - Callback pointer 1768 * 1769 * Returns status 1770 * 1771 ******************************************************************************/ 1772 tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK* p_ener_cback); 1773 1774 /******************************************************************************* 1775 * 1776 * Function BTM_ClearEventFilter 1777 * 1778 * Description Clears the event filter in the controller 1779 * 1780 * Returns Return btm status 1781 * 1782 ******************************************************************************/ 1783 tBTM_STATUS BTM_ClearEventFilter(void); 1784 1785 /******************************************************************************* 1786 * 1787 * Function BTM_ClearEventMask 1788 * 1789 * Description Clears the event mask in the controller 1790 * 1791 * Returns Return btm status 1792 * 1793 ******************************************************************************/ 1794 tBTM_STATUS BTM_ClearEventMask(void); 1795 1796 /******************************************************************************* 1797 * 1798 * Function BTM_ClearFilterAcceptList 1799 * 1800 * Description Clears the connect list in the controller 1801 * 1802 * Returns Return btm status 1803 * 1804 ******************************************************************************/ 1805 tBTM_STATUS BTM_ClearFilterAcceptList(void); 1806 1807 /******************************************************************************* 1808 * 1809 * Function BTM_DisconnectAllAcls 1810 * 1811 * Description Disconnects all of the ACL connections 1812 * 1813 * Returns Return btm status 1814 * 1815 ******************************************************************************/ 1816 tBTM_STATUS BTM_DisconnectAllAcls(void); 1817 1818 /******************************************************************************* 1819 * 1820 * Function BTM_LeRand 1821 * 1822 * Description Retrieves a random number from the controller 1823 * 1824 * Parameters cb - The callback to receive the random number 1825 * 1826 * Returns Return btm status 1827 * 1828 ******************************************************************************/ 1829 using LeRandCallback = base::Callback<void(uint64_t)>; 1830 tBTM_STATUS BTM_LeRand(LeRandCallback); 1831 1832 /******************************************************************************* 1833 * 1834 * Function BTM_SetEventFilterConnectionSetupAllDevices 1835 * 1836 * Description Tell the controller to allow all devices 1837 * 1838 * Parameters 1839 * 1840 *******************************************************************************/ 1841 tBTM_STATUS BTM_SetEventFilterConnectionSetupAllDevices(void); 1842 1843 /******************************************************************************* 1844 * 1845 * Function BTM_AllowWakeByHid 1846 * 1847 * Description Allow the device to be woken by HID devices 1848 * 1849 * Parameters std::vector of RawAddress 1850 * 1851 *******************************************************************************/ 1852 tBTM_STATUS BTM_AllowWakeByHid( 1853 std::vector<RawAddress> classic_hid_devices, 1854 std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices); 1855 1856 /******************************************************************************* 1857 * 1858 * Function BTM_RestoreFilterAcceptList 1859 * 1860 * Description Floss: Restore the state of the for the filter accept list 1861 * 1862 * Parameters 1863 * 1864 *******************************************************************************/ 1865 tBTM_STATUS BTM_RestoreFilterAcceptList( 1866 std::vector<std::pair<RawAddress, uint8_t>> le_devices); 1867 1868 /******************************************************************************* 1869 * 1870 * Function BTM_SetDefaultEventMaskExcept 1871 * 1872 * Description Floss: Set the default event mask for Classic and LE except 1873 * the given values (they will be disabled in the final set 1874 * mask). 1875 * 1876 * Parameters Bits set for event mask and le event mask that should be 1877 * disabled in the final value. 1878 * 1879 *******************************************************************************/ 1880 tBTM_STATUS BTM_SetDefaultEventMaskExcept(uint64_t mask, uint64_t le_mask); 1881 1882 /******************************************************************************* 1883 * 1884 * Function BTM_SetEventFilterInquiryResultAllDevices 1885 * 1886 * Description Floss: Set the event filter to inquiry result device all 1887 * 1888 * Parameters 1889 * 1890 *******************************************************************************/ 1891 tBTM_STATUS BTM_SetEventFilterInquiryResultAllDevices(void); 1892 1893 /******************************************************************************* 1894 * 1895 * Function BTM_BleResetId 1896 * 1897 * Description Resets the local BLE keys 1898 * 1899 *******************************************************************************/ 1900 tBTM_STATUS BTM_BleResetId(void); 1901 1902 /** 1903 * Send remote name request to GD shim Name module 1904 */ 1905 void SendRemoteNameRequest(const RawAddress& raw_address); 1906 1907 tBTM_STATUS btm_sec_mx_access_request(const RawAddress& bd_addr, 1908 bool is_originator, 1909 uint16_t security_requirement, 1910 tBTM_SEC_CALLBACK* p_callback, 1911 void* p_ref_data); 1912 1913 } // namespace shim 1914 } // namespace bluetooth 1915