bta_dm_api.cc revision 9979121f0865e07432215529f9b157792ae3ef21
1/****************************************************************************** 2 * 3 * Copyright (C) 2003-2014 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 is the API implementation file for the BTA device manager. 22 * 23 ******************************************************************************/ 24#include <string.h> 25 26#include "bt_common.h" 27#include "bta_api.h" 28#include "bta_closure_api.h" 29#include "bta_dm_int.h" 30#include "bta_sys.h" 31#include "bta_sys_int.h" 32#include "btm_api.h" 33#include "btm_int.h" 34#include "osi/include/osi.h" 35#include "utl.h" 36 37/***************************************************************************** 38 * Constants 39 ****************************************************************************/ 40 41static const tBTA_SYS_REG bta_dm_reg = {bta_dm_sm_execute, bta_dm_sm_disable}; 42 43static const tBTA_SYS_REG bta_dm_search_reg = {bta_dm_search_sm_execute, 44 bta_dm_search_sm_disable}; 45 46/******************************************************************************* 47 * 48 * Function BTA_EnableBluetooth 49 * 50 * Description Enables bluetooth service. This function must be 51 * called before any other functions in the BTA API are called. 52 * 53 * 54 * Returns tBTA_STATUS 55 * 56 ******************************************************************************/ 57tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK* p_cback) { 58 /* Bluetooth disabling is in progress */ 59 if (bta_dm_cb.disabling) return BTA_FAILURE; 60 61 bta_sys_register(BTA_ID_DM, &bta_dm_reg); 62 bta_sys_register(BTA_ID_DM_SEARCH, &bta_dm_search_reg); 63 64 /* if UUID list is not provided as static data */ 65 bta_sys_eir_register(bta_dm_eir_update_uuid); 66 67 tBTA_DM_API_ENABLE* p_msg = 68 (tBTA_DM_API_ENABLE*)osi_malloc(sizeof(tBTA_DM_API_ENABLE)); 69 p_msg->hdr.event = BTA_DM_API_ENABLE_EVT; 70 p_msg->p_sec_cback = p_cback; 71 72 bta_sys_sendmsg(p_msg); 73 74 return BTA_SUCCESS; 75} 76 77/******************************************************************************* 78 * 79 * Function BTA_DisableBluetooth 80 * 81 * Description Disables bluetooth service. This function is called when 82 * the application no longer needs bluetooth service 83 * 84 * Returns void 85 * 86 ******************************************************************************/ 87tBTA_STATUS BTA_DisableBluetooth(void) { 88 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR)); 89 90 p_msg->event = BTA_DM_API_DISABLE_EVT; 91 92 bta_sys_sendmsg(p_msg); 93 94 return BTA_SUCCESS; 95} 96 97/******************************************************************************* 98 * 99 * Function BTA_EnableTestMode 100 * 101 * Description Enables bluetooth device under test mode 102 * 103 * 104 * Returns tBTA_STATUS 105 * 106 ******************************************************************************/ 107tBTA_STATUS BTA_EnableTestMode(void) { 108 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR)); 109 110 APPL_TRACE_API("%s", __func__); 111 112 p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT; 113 bta_sys_sendmsg(p_msg); 114 115 return BTA_SUCCESS; 116} 117 118/******************************************************************************* 119 * 120 * Function BTA_DisableTestMode 121 * 122 * Description Disable bluetooth device under test mode 123 * 124 * 125 * Returns None 126 * 127 ******************************************************************************/ 128void BTA_DisableTestMode(void) { 129 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR)); 130 131 APPL_TRACE_API("%s", __func__); 132 133 p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT; 134 bta_sys_sendmsg(p_msg); 135} 136 137/******************************************************************************* 138 * 139 * Function BTA_DmSetDeviceName 140 * 141 * Description This function sets the Bluetooth name of local device 142 * 143 * 144 * Returns void 145 * 146 ******************************************************************************/ 147void BTA_DmSetDeviceName(char* p_name) { 148 tBTA_DM_API_SET_NAME* p_msg = 149 (tBTA_DM_API_SET_NAME*)osi_malloc(sizeof(tBTA_DM_API_SET_NAME)); 150 151 p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT; 152 strlcpy((char*)p_msg->name, p_name, BD_NAME_LEN); 153 154 bta_sys_sendmsg(p_msg); 155} 156 157/******************************************************************************* 158 * 159 * Function BTA_DmSetVisibility 160 * 161 * Description This function sets the Bluetooth connectable, 162 * discoverable, pairable and conn paired only modes of local 163 * device 164 * 165 * 166 * Returns void 167 * 168 ******************************************************************************/ 169void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, 170 uint8_t pairable_mode, uint8_t conn_filter) { 171 tBTA_DM_API_SET_VISIBILITY* p_msg = 172 (tBTA_DM_API_SET_VISIBILITY*)osi_malloc(sizeof(tBTA_DM_MSG)); 173 174 p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT; 175 p_msg->disc_mode = disc_mode; 176 p_msg->conn_mode = conn_mode; 177 p_msg->pair_mode = pairable_mode; 178 p_msg->conn_paired_only = conn_filter; 179 180 bta_sys_sendmsg(p_msg); 181} 182 183/******************************************************************************* 184 * 185 * Function BTA_DmSearch 186 * 187 * Description This function searches for peer Bluetooth devices. It 188 * performs an inquiry and gets the remote name for devices. 189 * Service discovery is done if services is non zero 190 * 191 * 192 * Returns void 193 * 194 ******************************************************************************/ 195void BTA_DmSearch(tBTA_DM_INQ* p_dm_inq, tBTA_SERVICE_MASK services, 196 tBTA_DM_SEARCH_CBACK* p_cback) { 197 tBTA_DM_API_SEARCH* p_msg = 198 (tBTA_DM_API_SEARCH*)osi_calloc(sizeof(tBTA_DM_API_SEARCH)); 199 200 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT; 201 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ)); 202 p_msg->services = services; 203 p_msg->p_cback = p_cback; 204 p_msg->rs_res = BTA_DM_RS_NONE; 205 206 bta_sys_sendmsg(p_msg); 207} 208 209/******************************************************************************* 210 * 211 * Function BTA_DmSearchCancel 212 * 213 * Description This function cancels a search initiated by BTA_DmSearch 214 * 215 * 216 * Returns void 217 * 218 ******************************************************************************/ 219void BTA_DmSearchCancel(void) { 220 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR)); 221 222 p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT; 223 bta_sys_sendmsg(p_msg); 224} 225 226/******************************************************************************* 227 * 228 * Function BTA_DmDiscover 229 * 230 * Description This function does service discovery for services of a 231 * peer device 232 * 233 * 234 * Returns void 235 * 236 ******************************************************************************/ 237void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services, 238 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search) { 239 tBTA_DM_API_DISCOVER* p_msg = 240 (tBTA_DM_API_DISCOVER*)osi_calloc(sizeof(tBTA_DM_API_DISCOVER)); 241 242 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT; 243 bdcpy(p_msg->bd_addr, bd_addr); 244 p_msg->services = services; 245 p_msg->p_cback = p_cback; 246 p_msg->sdp_search = sdp_search; 247 248 bta_sys_sendmsg(p_msg); 249} 250 251/******************************************************************************* 252 * 253 * Function BTA_DmDiscoverUUID 254 * 255 * Description This function does service discovery for services of a 256 * peer device 257 * 258 * 259 * Returns void 260 * 261 ******************************************************************************/ 262void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID* uuid, 263 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search) { 264 tBTA_DM_API_DISCOVER* p_msg = 265 (tBTA_DM_API_DISCOVER*)osi_malloc(sizeof(tBTA_DM_API_DISCOVER)); 266 267 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT; 268 bdcpy(p_msg->bd_addr, bd_addr); 269 p_msg->services = BTA_USER_SERVICE_MASK; // Not exposed at API level 270 p_msg->p_cback = p_cback; 271 p_msg->sdp_search = sdp_search; 272 273 p_msg->num_uuid = 0; 274 p_msg->p_uuid = NULL; 275 276 memcpy(&p_msg->uuid, uuid, sizeof(tSDP_UUID)); 277 278 bta_sys_sendmsg(p_msg); 279} 280 281/******************************************************************************* 282 * 283 * Function BTA_DmBond 284 * 285 * Description This function initiates a bonding procedure with a peer 286 * device 287 * 288 * 289 * Returns void 290 * 291 ******************************************************************************/ 292void BTA_DmBond(BD_ADDR bd_addr) { 293 tBTA_DM_API_BOND* p_msg = 294 (tBTA_DM_API_BOND*)osi_malloc(sizeof(tBTA_DM_API_BOND)); 295 296 p_msg->hdr.event = BTA_DM_API_BOND_EVT; 297 bdcpy(p_msg->bd_addr, bd_addr); 298 p_msg->transport = BTA_TRANSPORT_UNKNOWN; 299 300 bta_sys_sendmsg(p_msg); 301} 302 303/******************************************************************************* 304 * 305 * Function BTA_DmBondByTransports 306 * 307 * Description This function initiates a bonding procedure with a peer 308 * device 309 * 310 * 311 * Returns void 312 * 313 ******************************************************************************/ 314void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport) { 315 tBTA_DM_API_BOND* p_msg = 316 (tBTA_DM_API_BOND*)osi_malloc(sizeof(tBTA_DM_API_BOND)); 317 318 p_msg->hdr.event = BTA_DM_API_BOND_EVT; 319 bdcpy(p_msg->bd_addr, bd_addr); 320 p_msg->transport = transport; 321 322 bta_sys_sendmsg(p_msg); 323} 324 325/******************************************************************************* 326 * 327 * Function BTA_DmBondCancel 328 * 329 * Description This function cancels the bonding procedure with a peer 330 * device 331 * 332 * 333 * Returns void 334 * 335 ******************************************************************************/ 336void BTA_DmBondCancel(BD_ADDR bd_addr) { 337 tBTA_DM_API_BOND_CANCEL* p_msg = 338 (tBTA_DM_API_BOND_CANCEL*)osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL)); 339 340 p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT; 341 bdcpy(p_msg->bd_addr, bd_addr); 342 343 bta_sys_sendmsg(p_msg); 344} 345 346/******************************************************************************* 347 * 348 * Function BTA_DmPinReply 349 * 350 * Description This function provides a pincode for a remote device when 351 * one is requested by DM through BTA_DM_PIN_REQ_EVT 352 * 353 * 354 * Returns void 355 * 356 ******************************************************************************/ 357void BTA_DmPinReply(BD_ADDR bd_addr, bool accept, uint8_t pin_len, 358 uint8_t* p_pin) 359 360{ 361 tBTA_DM_API_PIN_REPLY* p_msg = 362 (tBTA_DM_API_PIN_REPLY*)osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY)); 363 364 p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT; 365 bdcpy(p_msg->bd_addr, bd_addr); 366 p_msg->accept = accept; 367 if (accept) { 368 p_msg->pin_len = pin_len; 369 memcpy(p_msg->p_pin, p_pin, pin_len); 370 } 371 372 bta_sys_sendmsg(p_msg); 373} 374 375/******************************************************************************* 376 * 377 * Function BTA_DmLocalOob 378 * 379 * Description This function retrieves the OOB data from local controller. 380 * The result is reported by: 381 * - bta_dm_co_loc_oob_ext() if device supports secure 382 * connections (SC) 383 * - bta_dm_co_loc_oob() if device doesn't support SC 384 * 385 * Returns void 386 * 387 ******************************************************************************/ 388void BTA_DmLocalOob(void) { 389 tBTA_DM_API_LOC_OOB* p_msg = 390 (tBTA_DM_API_LOC_OOB*)osi_malloc(sizeof(tBTA_DM_API_LOC_OOB)); 391 392 p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT; 393 bta_sys_sendmsg(p_msg); 394} 395 396/******************************************************************************* 397 * 398 * Function BTA_DmConfirm 399 * 400 * Description This function accepts or rejects the numerical value of the 401 * Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT 402 * 403 * Returns void 404 * 405 ******************************************************************************/ 406void BTA_DmConfirm(BD_ADDR bd_addr, bool accept) { 407 tBTA_DM_API_CONFIRM* p_msg = 408 (tBTA_DM_API_CONFIRM*)osi_malloc(sizeof(tBTA_DM_API_CONFIRM)); 409 410 p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT; 411 bdcpy(p_msg->bd_addr, bd_addr); 412 p_msg->accept = accept; 413 414 bta_sys_sendmsg(p_msg); 415} 416 417/******************************************************************************* 418 * 419 * Function BTA_DmAddDevice 420 * 421 * Description This function adds a device to the security database list of 422 * peer device 423 * 424 * 425 * Returns void 426 * 427 ******************************************************************************/ 428void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key, 429 tBTA_SERVICE_MASK trusted_mask, bool is_trusted, 430 uint8_t key_type, tBTA_IO_CAP io_cap, uint8_t pin_length) { 431 tBTA_DM_API_ADD_DEVICE* p_msg = 432 (tBTA_DM_API_ADD_DEVICE*)osi_calloc(sizeof(tBTA_DM_API_ADD_DEVICE)); 433 434 p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT; 435 bdcpy(p_msg->bd_addr, bd_addr); 436 p_msg->tm = trusted_mask; 437 p_msg->is_trusted = is_trusted; 438 p_msg->io_cap = io_cap; 439 440 if (link_key) { 441 p_msg->link_key_known = true; 442 p_msg->key_type = key_type; 443 memcpy(p_msg->link_key, link_key, LINK_KEY_LEN); 444 } 445 446 /* Load device class if specified */ 447 if (dev_class) { 448 p_msg->dc_known = true; 449 memcpy(p_msg->dc, dev_class, DEV_CLASS_LEN); 450 } 451 452 memset(p_msg->bd_name, 0, BD_NAME_LEN + 1); 453 memset(p_msg->features, 0, sizeof(p_msg->features)); 454 p_msg->pin_length = pin_length; 455 456 bta_sys_sendmsg(p_msg); 457} 458 459/******************************************************************************* 460 * 461 * Function BTA_DmRemoveDevice 462 * 463 * Description This function removes a device fromthe security database 464 * list of peer device. It manages unpairing even while 465 * connected. 466 * 467 * 468 * Returns void 469 * 470 ******************************************************************************/ 471tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr) { 472 tBTA_DM_API_REMOVE_DEVICE* p_msg = 473 (tBTA_DM_API_REMOVE_DEVICE*)osi_calloc(sizeof(tBTA_DM_API_REMOVE_DEVICE)); 474 475 p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT; 476 bdcpy(p_msg->bd_addr, bd_addr); 477 478 bta_sys_sendmsg(p_msg); 479 480 return BTA_SUCCESS; 481} 482 483/******************************************************************************* 484 * 485 * Function BTA_GetEirService 486 * 487 * Description This function is called to get BTA service mask from EIR. 488 * 489 * Parameters p_eir - pointer of EIR significant part 490 * p_services - return the BTA service mask 491 * 492 * Returns None 493 * 494 ******************************************************************************/ 495extern const uint16_t bta_service_id_to_uuid_lkup_tbl[]; 496void BTA_GetEirService(uint8_t* p_eir, tBTA_SERVICE_MASK* p_services) { 497 uint8_t xx, yy; 498 uint8_t num_uuid, max_num_uuid = 32; 499 uint8_t uuid_list[32 * LEN_UUID_16]; 500 uint16_t* p_uuid16 = (uint16_t*)uuid_list; 501 tBTA_SERVICE_MASK mask; 502 503 BTM_GetEirUuidList(p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid); 504 for (xx = 0; xx < num_uuid; xx++) { 505 mask = 1; 506 for (yy = 0; yy < BTA_MAX_SERVICE_ID; yy++) { 507 if (*(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy]) { 508 *p_services |= mask; 509 break; 510 } 511 mask <<= 1; 512 } 513 514 /* for HSP v1.2 only device */ 515 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS) 516 *p_services |= BTA_HSP_SERVICE_MASK; 517 518 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE) 519 *p_services |= BTA_HL_SERVICE_MASK; 520 521 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK) 522 *p_services |= BTA_HL_SERVICE_MASK; 523 } 524} 525 526/******************************************************************************* 527 * 528 * Function BTA_DmGetConnectionState 529 * 530 * Description Returns whether the remote device is currently connected. 531 * 532 * Returns 0 if the device is NOT connected. 533 * 534 ******************************************************************************/ 535uint16_t BTA_DmGetConnectionState(const BD_ADDR bd_addr) { 536 tBTA_DM_PEER_DEVICE* p_dev = bta_dm_find_peer_device(bd_addr); 537 return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED); 538} 539 540/******************************************************************************* 541 * Device Identification (DI) Server Functions 542 ******************************************************************************/ 543/******************************************************************************* 544 * 545 * Function BTA_DmSetLocalDiRecord 546 * 547 * Description This function adds a DI record to the local SDP database. 548 * 549 * Returns BTA_SUCCESS if record set sucessfully, otherwise error code. 550 * 551 ******************************************************************************/ 552tBTA_STATUS BTA_DmSetLocalDiRecord(tBTA_DI_RECORD* p_device_info, 553 uint32_t* p_handle) { 554 tBTA_STATUS status = BTA_FAILURE; 555 556 if (bta_dm_di_cb.di_num < BTA_DI_NUM_MAX) { 557 if (SDP_SetLocalDiRecord((tSDP_DI_RECORD*)p_device_info, p_handle) == 558 SDP_SUCCESS) { 559 if (!p_device_info->primary_record) { 560 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle; 561 bta_dm_di_cb.di_num++; 562 } 563 564 bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION); 565 status = BTA_SUCCESS; 566 } 567 } 568 569 return status; 570} 571 572/******************************************************************************* 573 * 574 * Function bta_dmexecutecallback 575 * 576 * Description This function will request BTA to execute a call back in the 577 * context of BTU task. 578 * This API was named in lower case because it is only intended 579 * for the internal customers(like BTIF). 580 * 581 * Returns void 582 * 583 ******************************************************************************/ 584void bta_dmexecutecallback(tBTA_DM_EXEC_CBACK* p_callback, void* p_param) { 585 tBTA_DM_API_EXECUTE_CBACK* p_msg = 586 (tBTA_DM_API_EXECUTE_CBACK*)osi_malloc(sizeof(tBTA_DM_MSG)); 587 588 p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT; 589 p_msg->p_param = p_param; 590 p_msg->p_exec_cback = p_callback; 591 592 bta_sys_sendmsg(p_msg); 593} 594 595/******************************************************************************* 596 * 597 * Function BTA_DmAddBleKey 598 * 599 * Description Add/modify LE device information. This function will be 600 * normally called during host startup to restore all required 601 * information stored in the NVRAM. 602 * 603 * Parameters: bd_addr - BD address of the peer 604 * p_le_key - LE key values. 605 * key_type - LE SMP key type. 606 * 607 * Returns BTA_SUCCESS if successful 608 * BTA_FAIL if operation failed. 609 * 610 ******************************************************************************/ 611void BTA_DmAddBleKey(BD_ADDR bd_addr, tBTA_LE_KEY_VALUE* p_le_key, 612 tBTA_LE_KEY_TYPE key_type) { 613 614 tBTA_DM_API_ADD_BLEKEY* p_msg = 615 (tBTA_DM_API_ADD_BLEKEY*)osi_calloc(sizeof(tBTA_DM_API_ADD_BLEKEY)); 616 617 p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT; 618 p_msg->key_type = key_type; 619 bdcpy(p_msg->bd_addr, bd_addr); 620 memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE)); 621 622 bta_sys_sendmsg(p_msg); 623} 624 625/******************************************************************************* 626 * 627 * Function BTA_DmAddBleDevice 628 * 629 * Description Add a BLE device. This function will be normally called 630 * during host startup to restore all required information 631 * for a LE device stored in the NVRAM. 632 * 633 * Parameters: bd_addr - BD address of the peer 634 * dev_type - Remote device's device type. 635 * addr_type - LE device address type. 636 * 637 * Returns void 638 * 639 ******************************************************************************/ 640void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, 641 tBT_DEVICE_TYPE dev_type) { 642 tBTA_DM_API_ADD_BLE_DEVICE* p_msg = (tBTA_DM_API_ADD_BLE_DEVICE*)osi_calloc( 643 sizeof(tBTA_DM_API_ADD_BLE_DEVICE)); 644 645 p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT; 646 bdcpy(p_msg->bd_addr, bd_addr); 647 p_msg->addr_type = addr_type; 648 p_msg->dev_type = dev_type; 649 650 bta_sys_sendmsg(p_msg); 651} 652 653/******************************************************************************* 654 * 655 * Function BTA_DmBlePasskeyReply 656 * 657 * Description Send BLE SMP passkey reply. 658 * 659 * Parameters: bd_addr - BD address of the peer 660 * accept - passkey entry sucessful or declined. 661 * passkey - passkey value, must be a 6 digit number, 662 * can be lead by 0. 663 * 664 * Returns void 665 * 666 ******************************************************************************/ 667void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, bool accept, uint32_t passkey) { 668 tBTA_DM_API_PASSKEY_REPLY* p_msg = 669 (tBTA_DM_API_PASSKEY_REPLY*)osi_calloc(sizeof(tBTA_DM_API_PASSKEY_REPLY)); 670 671 p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT; 672 bdcpy(p_msg->bd_addr, bd_addr); 673 p_msg->accept = accept; 674 675 if (accept) p_msg->passkey = passkey; 676 677 bta_sys_sendmsg(p_msg); 678} 679 680/******************************************************************************* 681 * 682 * Function BTA_DmBleConfirmReply 683 * 684 * Description Send BLE SMP SC user confirmation reply. 685 * 686 * Parameters: bd_addr - BD address of the peer 687 * accept - numbers to compare are the same or 688 * different. 689 * 690 * Returns void 691 * 692 ******************************************************************************/ 693void BTA_DmBleConfirmReply(BD_ADDR bd_addr, bool accept) { 694 tBTA_DM_API_CONFIRM* p_msg = 695 (tBTA_DM_API_CONFIRM*)osi_calloc(sizeof(tBTA_DM_API_CONFIRM)); 696 697 p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT; 698 bdcpy(p_msg->bd_addr, bd_addr); 699 p_msg->accept = accept; 700 701 bta_sys_sendmsg(p_msg); 702} 703 704/******************************************************************************* 705 * 706 * Function BTA_DmBleSecurityGrant 707 * 708 * Description Grant security request access. 709 * 710 * Parameters: bd_addr - BD address of the peer 711 * res - security grant status. 712 * 713 * Returns void 714 * 715 ******************************************************************************/ 716void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res) { 717 tBTA_DM_API_BLE_SEC_GRANT* p_msg = 718 (tBTA_DM_API_BLE_SEC_GRANT*)osi_calloc(sizeof(tBTA_DM_API_BLE_SEC_GRANT)); 719 720 p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT; 721 bdcpy(p_msg->bd_addr, bd_addr); 722 p_msg->res = res; 723 724 bta_sys_sendmsg(p_msg); 725} 726 727/******************************************************************************* 728 * 729 * Function BTA_DmSetBlePrefConnParams 730 * 731 * Description This function is called to set the preferred connection 732 * parameters when default connection parameter is not desired. 733 * 734 * Parameters: bd_addr - BD address of the peripheral 735 * scan_interval - scan interval 736 * scan_window - scan window 737 * min_conn_int - minimum preferred connection interval 738 * max_conn_int - maximum preferred connection interval 739 * slave_latency - preferred slave latency 740 * supervision_tout - preferred supervision timeout 741 * 742 * 743 * Returns void 744 * 745 ******************************************************************************/ 746void BTA_DmSetBlePrefConnParams(const BD_ADDR bd_addr, uint16_t min_conn_int, 747 uint16_t max_conn_int, uint16_t slave_latency, 748 uint16_t supervision_tout) { 749 tBTA_DM_API_BLE_CONN_PARAMS* p_msg = (tBTA_DM_API_BLE_CONN_PARAMS*)osi_calloc( 750 sizeof(tBTA_DM_API_BLE_CONN_PARAMS)); 751 752 p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT; 753 memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN); 754 p_msg->conn_int_max = max_conn_int; 755 p_msg->conn_int_min = min_conn_int; 756 p_msg->slave_latency = slave_latency; 757 p_msg->supervision_tout = supervision_tout; 758 759 bta_sys_sendmsg(p_msg); 760} 761 762/******************************************************************************* 763 * 764 * Function BTA_DmSetBleConnScanParams 765 * 766 * Description This function is called to set scan parameters used in 767 * BLE connection request 768 * 769 * Parameters: scan_interval - scan interval 770 * scan_window - scan window 771 * 772 * Returns void 773 * 774 ******************************************************************************/ 775void BTA_DmSetBleConnScanParams(uint32_t scan_interval, uint32_t scan_window) { 776 tBTA_DM_API_BLE_SCAN_PARAMS* p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS*)osi_calloc( 777 sizeof(tBTA_DM_API_BLE_SCAN_PARAMS)); 778 779 p_msg->hdr.event = BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT; 780 p_msg->scan_int = scan_interval; 781 p_msg->scan_window = scan_window; 782 783 bta_sys_sendmsg(p_msg); 784} 785 786/******************************************************************************* 787 * 788 * Function BTA_DmSetBleScanParams 789 * 790 * Description This function is called to set scan parameters 791 * 792 * Parameters: client_if - Client IF 793 * scan_interval - scan interval 794 * scan_window - scan window 795 * scan_mode - scan mode 796 * scan_param_setup_status_cback - Set scan param status 797 * callback 798 * 799 * Returns void 800 * 801 ******************************************************************************/ 802 803void BTA_DmSetBleScanParams( 804 tGATT_IF client_if, uint32_t scan_interval, uint32_t scan_window, 805 tBLE_SCAN_MODE scan_mode, 806 tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback) { 807 tBTA_DM_API_BLE_SCAN_PARAMS* p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS*)osi_calloc( 808 sizeof(tBTA_DM_API_BLE_SCAN_PARAMS)); 809 810 p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT; 811 p_msg->client_if = client_if; 812 p_msg->scan_int = scan_interval; 813 p_msg->scan_window = scan_window; 814 p_msg->scan_mode = scan_mode; 815 p_msg->scan_param_setup_cback = scan_param_setup_cback; 816 817 bta_sys_sendmsg(p_msg); 818} 819 820/******************************************************************************* 821 * 822 * Function BTA_DmSetBleAdvParams 823 * 824 * Description This function sets the advertising parameters BLE 825 * functionality. 826 * It is to be called when device act in peripheral or 827 * broadcaster role. 828 * 829 * 830 * Returns void 831 * 832 ******************************************************************************/ 833void BTA_DmSetBleAdvParams(uint16_t adv_int_min, uint16_t adv_int_max, 834 tBLE_BD_ADDR* p_dir_bda) { 835 if (p_dir_bda != NULL) { 836 tBLE_BD_ADDR* bda = new tBLE_BD_ADDR; 837 memcpy(bda, p_dir_bda, sizeof(tBLE_BD_ADDR)); 838 do_in_bta_thread(FROM_HERE, 839 base::Bind(&bta_dm_ble_set_adv_params, adv_int_min, 840 adv_int_max, base::Owned(bda))); 841 } 842 843 do_in_bta_thread(FROM_HERE, base::Bind(&bta_dm_ble_set_adv_params, 844 adv_int_min, adv_int_max, nullptr)); 845 846} 847 848/******************************************************************************* 849 * BLE ADV data management API 850 *******************************************************************************/ 851 852/******************************************************************************* 853 * 854 * Function BTA_DmBleSetStorageParams 855 * 856 * Description This function is called to override the BTA scan response. 857 * 858 * Parameters batch_scan_full_max -Max storage space (in %) allocated to 859 * full scanning 860 * batch_scan_trunc_max -Max storage space (in %) allocated to 861 * truncated scanning 862 * batch_scan_notify_threshold -Setup notification level based 863 * on total space 864 * p_setup_cback - Setup callback pointer 865 * p_thres_cback - Threshold callback pointer 866 * p_rep_cback - Reports callback pointer 867 * ref_value - Ref value 868 * 869 * Returns None 870 * 871 ******************************************************************************/ 872extern void BTA_DmBleSetStorageParams( 873 uint8_t batch_scan_full_max, uint8_t batch_scan_trunc_max, 874 uint8_t batch_scan_notify_threshold, 875 tBTA_BLE_SCAN_SETUP_CBACK* p_setup_cback, 876 tBTA_BLE_SCAN_THRESHOLD_CBACK* p_thres_cback, 877 tBTA_BLE_SCAN_REP_CBACK* p_rep_cback, tBTA_DM_BLE_REF_VALUE ref_value) { 878 tBTA_DM_API_SET_STORAGE_CONFIG* p_msg = 879 (tBTA_DM_API_SET_STORAGE_CONFIG*)osi_malloc( 880 sizeof(tBTA_DM_API_SET_STORAGE_CONFIG)); 881 882 bta_dm_cb.p_setup_cback = p_setup_cback; 883 884 p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT; 885 p_msg->p_setup_cback = bta_ble_scan_setup_cb; 886 p_msg->p_thres_cback = p_thres_cback; 887 p_msg->p_read_rep_cback = p_rep_cback; 888 p_msg->ref_value = ref_value; 889 p_msg->batch_scan_full_max = batch_scan_full_max; 890 p_msg->batch_scan_trunc_max = batch_scan_trunc_max; 891 p_msg->batch_scan_notify_threshold = batch_scan_notify_threshold; 892 893 bta_sys_sendmsg(p_msg); 894} 895 896/******************************************************************************* 897 * 898 * Function BTA_DmBleEnableBatchScan 899 * 900 * Description This function is called to enable the batch scan 901 * 902 * Parameters scan_mode -Batch scan mode 903 * scan_interval - Scan interval 904 * scan_window - Scan window 905 * discard_rule -Discard rules 906 * addr_type - Address type 907 * ref_value - Reference value 908 * 909 * Returns None 910 * 911 ******************************************************************************/ 912extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode, 913 uint32_t scan_interval, 914 uint32_t scan_window, 915 tBTA_BLE_DISCARD_RULE discard_rule, 916 tBLE_ADDR_TYPE addr_type, 917 tBTA_DM_BLE_REF_VALUE ref_value) { 918 tBTA_DM_API_ENABLE_SCAN* p_msg = 919 (tBTA_DM_API_ENABLE_SCAN*)osi_malloc(sizeof(tBTA_DM_API_ENABLE_SCAN)); 920 921 p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT; 922 p_msg->scan_mode = scan_mode; 923 p_msg->scan_int = scan_interval; 924 p_msg->scan_window = scan_window; 925 p_msg->discard_rule = discard_rule; 926 p_msg->addr_type = addr_type; 927 p_msg->ref_value = ref_value; 928 929 bta_sys_sendmsg(p_msg); 930} 931 932/******************************************************************************* 933 * 934 * Function BTA_DmBleDisableBatchScan 935 * 936 * Description This function is called to disable the batch scan 937 * 938 * Parameters ref_value - Reference value 939 * 940 * Returns None 941 * 942 ******************************************************************************/ 943extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value) { 944 tBTA_DM_API_DISABLE_SCAN* p_msg = 945 (tBTA_DM_API_DISABLE_SCAN*)osi_malloc(sizeof(tBTA_DM_API_DISABLE_SCAN)); 946 947 p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT; 948 p_msg->ref_value = ref_value; 949 950 bta_sys_sendmsg(p_msg); 951} 952 953/******************************************************************************* 954 * 955 * Function BTA_DmBleReadScanReports 956 * 957 * Description This function is called to read scan reports 958 * 959 * Parameters scan_type -Batch scan mode 960 * ref_value - Reference value 961 * 962 * Returns None 963 * 964 ******************************************************************************/ 965extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type, 966 tBTA_DM_BLE_REF_VALUE ref_value) { 967 tBTA_DM_API_READ_SCAN_REPORTS* p_msg = 968 (tBTA_DM_API_READ_SCAN_REPORTS*)osi_malloc( 969 sizeof(tBTA_DM_API_READ_SCAN_REPORTS)); 970 971 p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT; 972 p_msg->scan_type = scan_type; 973 p_msg->ref_value = ref_value; 974 975 bta_sys_sendmsg(p_msg); 976} 977 978/******************************************************************************* 979 * 980 * Function BTA_DmBleTrackAdvertiser 981 * 982 * Description This function is called to track advertiser 983 * 984 * Parameters ref_value - Reference value 985 * p_track_adv_cback - Track ADV callback 986 * 987 * Returns None 988 * 989 ******************************************************************************/ 990extern void BTA_DmBleTrackAdvertiser( 991 tBTA_DM_BLE_REF_VALUE ref_value, 992 tBTA_BLE_TRACK_ADV_CBACK* p_track_adv_cback) { 993 tBTA_DM_API_TRACK_ADVERTISER* p_msg = 994 (tBTA_DM_API_TRACK_ADVERTISER*)osi_malloc( 995 sizeof(tBTA_DM_API_TRACK_ADVERTISER)); 996 997 p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT; 998 p_msg->p_track_adv_cback = p_track_adv_cback; 999 p_msg->ref_value = ref_value; 1000 1001 bta_sys_sendmsg(p_msg); 1002} 1003 1004/******************************************************************************* 1005 * BLE ADV data management API 1006 *******************************************************************************/ 1007 1008/******************************************************************************* 1009 * 1010 * Function BTA_DmBleSetBgConnType 1011 * 1012 * Description This function is called to set BLE connectable mode for a 1013 * peripheral device. 1014 * 1015 * Parameters bg_conn_type: it can be auto connection, or selective 1016 * connection. 1017 * p_select_cback: callback function when selective connection 1018 * procedure is being used. 1019 * 1020 * Returns void 1021 * 1022 ******************************************************************************/ 1023void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, 1024 tBTA_DM_BLE_SEL_CBACK* p_select_cback) { 1025 tBTA_DM_API_BLE_SET_BG_CONN_TYPE* p_msg = 1026 (tBTA_DM_API_BLE_SET_BG_CONN_TYPE*)osi_calloc( 1027 sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE)); 1028 1029 p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE; 1030 p_msg->bg_conn_type = bg_conn_type; 1031 p_msg->p_select_cback = p_select_cback; 1032 1033 bta_sys_sendmsg(p_msg); 1034} 1035 1036/******************************************************************************* 1037 * 1038 * Function bta_dm_discover_send_msg 1039 * 1040 * Description This function send discover message to BTA task. 1041 * 1042 * Returns void 1043 * 1044 ******************************************************************************/ 1045static void bta_dm_discover_send_msg(BD_ADDR bd_addr, 1046 tBTA_SERVICE_MASK_EXT* p_services, 1047 tBTA_DM_SEARCH_CBACK* p_cback, 1048 bool sdp_search, 1049 tBTA_TRANSPORT transport) { 1050 const size_t len = p_services ? (sizeof(tBTA_DM_API_DISCOVER) + 1051 sizeof(tBT_UUID) * p_services->num_uuid) 1052 : sizeof(tBTA_DM_API_DISCOVER); 1053 tBTA_DM_API_DISCOVER* p_msg = (tBTA_DM_API_DISCOVER*)osi_calloc(len); 1054 1055 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT; 1056 bdcpy(p_msg->bd_addr, bd_addr); 1057 p_msg->p_cback = p_cback; 1058 p_msg->sdp_search = sdp_search; 1059 p_msg->transport = transport; 1060 1061 if (p_services != NULL) { 1062 p_msg->services = p_services->srvc_mask; 1063 p_msg->num_uuid = p_services->num_uuid; 1064 if (p_services->num_uuid != 0) { 1065 p_msg->p_uuid = (tBT_UUID*)(p_msg + 1); 1066 memcpy(p_msg->p_uuid, p_services->p_uuid, 1067 sizeof(tBT_UUID) * p_services->num_uuid); 1068 } 1069 } 1070 1071 bta_sys_sendmsg(p_msg); 1072} 1073 1074/******************************************************************************* 1075 * 1076 * Function BTA_DmDiscoverByTransport 1077 * 1078 * Description This function does service discovery on particular transport 1079 * for services of a 1080 * peer device. When services.num_uuid is 0, it indicates all 1081 * GATT based services are to be searched; otherwise a list of 1082 * UUID of interested services should be provided through 1083 * p_services->p_uuid. 1084 * 1085 * 1086 * 1087 * Returns void 1088 * 1089 ******************************************************************************/ 1090void BTA_DmDiscoverByTransport(BD_ADDR bd_addr, 1091 tBTA_SERVICE_MASK_EXT* p_services, 1092 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search, 1093 tBTA_TRANSPORT transport) { 1094 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport); 1095} 1096 1097/******************************************************************************* 1098 * 1099 * Function BTA_DmDiscoverExt 1100 * 1101 * Description This function does service discovery for services of a 1102 * peer device. When services.num_uuid is 0, it indicates all 1103 * GATT based services are to be searched; other wise a list of 1104 * UUID of interested services should be provided through 1105 * p_services->p_uuid. 1106 * 1107 * 1108 * 1109 * Returns void 1110 * 1111 ******************************************************************************/ 1112void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT* p_services, 1113 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search) { 1114 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, 1115 BTA_TRANSPORT_UNKNOWN); 1116} 1117 1118/******************************************************************************* 1119 * 1120 * Function BTA_DmSearchExt 1121 * 1122 * Description This function searches for peer Bluetooth devices. It 1123 * performs an inquiry and gets the remote name for devices. 1124 * Service discovery is done if services is non zero 1125 * 1126 * Parameters p_dm_inq: inquiry conditions 1127 * p_services: if service is not empty, service discovery will 1128 * be done. For all GATT based service conditions, 1129 * put num_uuid, and p_uuid is the pointer to the 1130 * list of UUID values. 1131 * p_cback: callback function when search is completed. 1132 * 1133 * 1134 * 1135 * Returns void 1136 * 1137 ******************************************************************************/ 1138void BTA_DmSearchExt(tBTA_DM_INQ* p_dm_inq, tBTA_SERVICE_MASK_EXT* p_services, 1139 tBTA_DM_SEARCH_CBACK* p_cback) { 1140 const size_t len = p_services ? (sizeof(tBTA_DM_API_SEARCH) + 1141 sizeof(tBT_UUID) * p_services->num_uuid) 1142 : sizeof(tBTA_DM_API_SEARCH); 1143 tBTA_DM_API_SEARCH* p_msg = (tBTA_DM_API_SEARCH*)osi_calloc(len); 1144 1145 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT; 1146 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ)); 1147 p_msg->p_cback = p_cback; 1148 p_msg->rs_res = BTA_DM_RS_NONE; 1149 1150 if (p_services != NULL) { 1151 p_msg->services = p_services->srvc_mask; 1152 p_msg->num_uuid = p_services->num_uuid; 1153 1154 if (p_services->num_uuid != 0) { 1155 p_msg->p_uuid = (tBT_UUID*)(p_msg + 1); 1156 memcpy(p_msg->p_uuid, p_services->p_uuid, 1157 sizeof(tBT_UUID) * p_services->num_uuid); 1158 } else { 1159 p_msg->p_uuid = NULL; 1160 } 1161 } 1162 1163 bta_sys_sendmsg(p_msg); 1164} 1165 1166/******************************************************************************* 1167 * 1168 * Function BTA_DmBleUpdateConnectionParam 1169 * 1170 * Description Update connection parameters, can only be used when 1171 * connection is up. 1172 * 1173 * Parameters: bd_addr - BD address of the peer 1174 * min_int - minimum connection interval, 1175 * [0x0004 ~ 0x4000] 1176 * max_int - maximum connection interval, 1177 * [0x0004 ~ 0x4000] 1178 * latency - slave latency [0 ~ 500] 1179 * timeout - supervision timeout [0x000a ~ 0xc80] 1180 * 1181 * Returns void 1182 * 1183 ******************************************************************************/ 1184void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, uint16_t min_int, 1185 uint16_t max_int, uint16_t latency, 1186 uint16_t timeout) { 1187 tBTA_DM_API_UPDATE_CONN_PARAM* p_msg = 1188 (tBTA_DM_API_UPDATE_CONN_PARAM*)osi_calloc( 1189 sizeof(tBTA_DM_API_UPDATE_CONN_PARAM)); 1190 1191 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT; 1192 bdcpy(p_msg->bd_addr, bd_addr); 1193 p_msg->min_int = min_int; 1194 p_msg->max_int = max_int; 1195 p_msg->latency = latency; 1196 p_msg->timeout = timeout; 1197 1198 bta_sys_sendmsg(p_msg); 1199} 1200 1201/******************************************************************************* 1202 * 1203 * Function BTA_DmBleConfigLocalPrivacy 1204 * 1205 * Description Enable/disable privacy on the local device 1206 * 1207 * Parameters: privacy_enable - enable/disabe privacy on remote device. 1208 * 1209 * Returns void 1210 * 1211 ******************************************************************************/ 1212void BTA_DmBleConfigLocalPrivacy(bool privacy_enable) { 1213#if (BLE_PRIVACY_SPT == TRUE) 1214 tBTA_DM_API_LOCAL_PRIVACY* p_msg = (tBTA_DM_API_LOCAL_PRIVACY*)osi_calloc( 1215 sizeof(tBTA_DM_API_ENABLE_PRIVACY)); 1216 1217 p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT; 1218 p_msg->privacy_enable = privacy_enable; 1219 1220 bta_sys_sendmsg(p_msg); 1221#else 1222 UNUSED(privacy_enable); 1223#endif 1224} 1225 1226/******************************************************************************* 1227 * 1228 * Function BTA_DmBleCfgFilterCondition 1229 * 1230 * Description This function is called to configure the adv data payload 1231 * filter condition. 1232 * 1233 * Parameters action: to read/write/clear 1234 * cond_type: filter condition type 1235 * filt_index - Filter index 1236 * p_cond: filter condition parameter 1237 * p_cmpl_back - Command completed callback 1238 * ref_value - Reference value 1239 * 1240 * Returns void 1241 * 1242 ******************************************************************************/ 1243#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE) 1244void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action, 1245 tBTA_DM_BLE_PF_COND_TYPE cond_type, 1246 tBTA_DM_BLE_PF_FILT_INDEX filt_index, 1247 tBTA_DM_BLE_PF_COND_PARAM* p_cond, 1248 tBTA_DM_BLE_PF_CFG_CBACK* p_cmpl_cback, 1249 tBTA_DM_BLE_REF_VALUE ref_value) { 1250 tBTA_DM_API_CFG_FILTER_COND* p_msg; 1251 APPL_TRACE_API("BTA_DmBleCfgFilterCondition: %d, %d", action, cond_type); 1252 1253 uint16_t len = 1254 sizeof(tBTA_DM_API_CFG_FILTER_COND) + sizeof(tBTA_DM_BLE_PF_COND_PARAM); 1255 uint8_t* p; 1256 1257 if (NULL != p_cond) { 1258 switch (cond_type) { 1259 case BTA_DM_BLE_PF_SRVC_DATA_PATTERN: 1260 case BTA_DM_BLE_PF_MANU_DATA: 1261 /* Length of pattern and pattern mask and other elements in */ 1262 /* tBTA_DM_BLE_PF_MANU_COND */ 1263 len += ((p_cond->manu_data.data_len) * 2) + sizeof(uint16_t) + 1264 sizeof(uint16_t) + sizeof(uint8_t); 1265 break; 1266 1267 case BTA_DM_BLE_PF_LOCAL_NAME: 1268 len += ((p_cond->local_name.data_len) + sizeof(uint8_t)); 1269 break; 1270 1271 case BTM_BLE_PF_SRVC_UUID: 1272 case BTM_BLE_PF_SRVC_SOL_UUID: 1273 len += sizeof(tBLE_BD_ADDR) + sizeof(tBTA_DM_BLE_PF_COND_MASK); 1274 break; 1275 1276 default: 1277 break; 1278 } 1279 } 1280 1281 p_msg = (tBTA_DM_API_CFG_FILTER_COND*)osi_calloc(len); 1282 p_msg->hdr.event = BTA_DM_API_CFG_FILTER_COND_EVT; 1283 p_msg->action = action; 1284 p_msg->cond_type = cond_type; 1285 p_msg->filt_index = filt_index; 1286 p_msg->p_filt_cfg_cback = p_cmpl_cback; 1287 p_msg->ref_value = ref_value; 1288 if (p_cond) { 1289 p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM*)(p_msg + 1); 1290 memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM)); 1291 1292 p = (uint8_t*)(p_msg->p_cond_param + 1); 1293 1294 if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN || 1295 cond_type == BTA_DM_BLE_PF_MANU_DATA) { 1296 p_msg->p_cond_param->manu_data.p_pattern = p; 1297 p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len; 1298 memcpy(p_msg->p_cond_param->manu_data.p_pattern, 1299 p_cond->manu_data.p_pattern, p_cond->manu_data.data_len); 1300 p += p_cond->manu_data.data_len; 1301 1302 if (cond_type == BTA_DM_BLE_PF_MANU_DATA) { 1303 p_msg->p_cond_param->manu_data.company_id_mask = 1304 p_cond->manu_data.company_id_mask; 1305 if (p_cond->manu_data.p_pattern_mask != NULL) { 1306 p_msg->p_cond_param->manu_data.p_pattern_mask = p; 1307 memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask, 1308 p_cond->manu_data.p_pattern_mask, p_cond->manu_data.data_len); 1309 } 1310 } 1311 } else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME) { 1312 p_msg->p_cond_param->local_name.p_data = p; 1313 p_msg->p_cond_param->local_name.data_len = p_cond->local_name.data_len; 1314 memcpy(p_msg->p_cond_param->local_name.p_data, p_cond->local_name.p_data, 1315 p_cond->local_name.data_len); 1316 } else if (cond_type == BTM_BLE_PF_SRVC_UUID || 1317 cond_type == BTM_BLE_PF_SRVC_SOL_UUID) { 1318 if (p_cond->srvc_uuid.p_target_addr != NULL) { 1319 p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR*)(p); 1320 p_msg->p_cond_param->srvc_uuid.p_target_addr->type = 1321 p_cond->srvc_uuid.p_target_addr->type; 1322 memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda, 1323 p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN); 1324 p = (uint8_t*)(p_msg->p_cond_param->srvc_uuid.p_target_addr + 1); 1325 } 1326 if (p_cond->srvc_uuid.p_uuid_mask) { 1327 p_msg->p_cond_param->srvc_uuid.p_uuid_mask = 1328 (tBTA_DM_BLE_PF_COND_MASK*)p; 1329 memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask, 1330 p_cond->srvc_uuid.p_uuid_mask, sizeof(tBTA_DM_BLE_PF_COND_MASK)); 1331 } 1332 } 1333 } 1334 1335 bta_sys_sendmsg(p_msg); 1336} 1337#else 1338void BTA_DmBleCfgFilterCondition( 1339 UNUSED_ATTR tBTA_DM_BLE_SCAN_COND_OP action, 1340 UNUSED_ATTR tBTA_DM_BLE_PF_COND_TYPE cond_type, 1341 UNUSED_ATTR tBTA_DM_BLE_PF_FILT_INDEX filt_index, 1342 UNUSED_ATTR tBTA_DM_BLE_PF_COND_PARAM* p_cond, 1343 UNUSED_ATTR tBTA_DM_BLE_PF_CFG_CBACK* p_cmpl_cback, 1344 UNUSED_ATTR tBTA_DM_BLE_REF_VALUE ref_value) {} 1345#endif 1346 1347/******************************************************************************* 1348 * 1349 * Function BTA_DmBleScanFilterSetup 1350 * 1351 * Description This function is called to setup the adv data payload filter 1352 * param 1353 * 1354 * Parameters p_target: enable the filter condition on a target device; if 1355 * NULL 1356 * filt_index - Filter index 1357 * p_filt_params -Filter parameters 1358 * ref_value - Reference value 1359 * action - Add, delete or clear 1360 * p_cmpl_back - Command completed callback 1361 * 1362 * Returns void 1363 * 1364 ******************************************************************************/ 1365#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE) 1366void BTA_DmBleScanFilterSetup(uint8_t action, 1367 tBTA_DM_BLE_PF_FILT_INDEX filt_index, 1368 tBTA_DM_BLE_PF_FILT_PARAMS* p_filt_params, 1369 tBLE_BD_ADDR* p_target, 1370 tBTA_DM_BLE_PF_PARAM_CBACK* p_cmpl_cback, 1371 tBTA_DM_BLE_REF_VALUE ref_value) { 1372 const size_t len = 1373 sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) + sizeof(tBLE_BD_ADDR); 1374 tBTA_DM_API_SCAN_FILTER_PARAM_SETUP* p_msg = 1375 (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP*)osi_calloc(len); 1376 1377 APPL_TRACE_API("%s: %d", __func__, action); 1378 1379 p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_SETUP_EVT; 1380 p_msg->action = action; 1381 p_msg->filt_index = filt_index; 1382 if (p_filt_params) { 1383 memcpy(&p_msg->filt_params, p_filt_params, 1384 sizeof(tBTA_DM_BLE_PF_FILT_PARAMS)); 1385 } 1386 p_msg->p_filt_param_cback = p_cmpl_cback; 1387 p_msg->ref_value = ref_value; 1388 1389 if (p_target) { 1390 p_msg->p_target = (tBLE_BD_ADDR*)(p_msg + 1); 1391 memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR)); 1392 } 1393 1394 bta_sys_sendmsg(p_msg); 1395} 1396#else 1397void BTA_DmBleScanFilterSetup( 1398 UNUSED_ATTR uint8_t action, 1399 UNUSED_ATTR tBTA_DM_BLE_PF_FILT_INDEX filt_index, 1400 UNUSED_ATTR tBTA_DM_BLE_PF_FILT_PARAMS* p_filt_params, 1401 UNUSED_ATTR tBLE_BD_ADDR* p_target, 1402 UNUSED_ATTR tBTA_DM_BLE_PF_PARAM_CBACK* p_cmpl_cback, 1403 UNUSED_ATTR tBTA_DM_BLE_REF_VALUE ref_value) 1404} 1405#endif 1406 1407/******************************************************************************* 1408 * 1409 * Function BTA_DmBleGetEnergyInfo 1410 * 1411 * Description This function is called to obtain the energy info 1412 * 1413 * Parameters p_cmpl_cback - Command complete callback 1414 * 1415 * Returns void 1416 * 1417 ******************************************************************************/ 1418void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK* p_cmpl_cback) { 1419 const size_t len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR); 1420 tBTA_DM_API_ENERGY_INFO* p_msg = (tBTA_DM_API_ENERGY_INFO*)osi_calloc(len); 1421 1422 APPL_TRACE_API("%s", __func__); 1423 1424 p_msg->hdr.event = BTA_DM_API_BLE_ENERGY_INFO_EVT; 1425 p_msg->p_energy_info_cback = p_cmpl_cback; 1426 1427 bta_sys_sendmsg(p_msg); 1428} 1429 1430/******************************************************************************* 1431 * 1432 * Function BTA_DmEnableScanFilter 1433 * 1434 * Description This function is called to enable the adv data payload 1435 * filter 1436 * 1437 * Parameters action - enable or disable the APCF feature 1438 * p_cmpl_cback - Command completed callback 1439 * ref_value - Reference value 1440 * 1441 * Returns void 1442 * 1443 ******************************************************************************/ 1444#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE) 1445void BTA_DmEnableScanFilter(uint8_t action, 1446 tBTA_DM_BLE_PF_STATUS_CBACK* p_cmpl_cback, 1447 tBTA_DM_BLE_REF_VALUE ref_value) { 1448 const size_t len = 1449 sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) + sizeof(tBLE_BD_ADDR); 1450 tBTA_DM_API_ENABLE_SCAN_FILTER* p_msg = 1451 (tBTA_DM_API_ENABLE_SCAN_FILTER*)osi_calloc(len); 1452 1453 APPL_TRACE_API("%s: %d", __func__, action); 1454 1455 p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_ENABLE_EVT; 1456 p_msg->action = action; 1457 p_msg->ref_value = ref_value; 1458 p_msg->p_filt_status_cback = p_cmpl_cback; 1459 1460 bta_sys_sendmsg(p_msg); 1461} 1462#else 1463void BTA_DmEnableScanFilter( 1464 UNUSED_ATTR uint8_t action, 1465 UNUSED_ATTR tBTA_DM_BLE_PF_STATUS_CBACK* p_cmpl_cback, 1466 UNUSED_ATTR tBTA_DM_BLE_REF_VALUE ref_value) {} 1467#endif 1468 1469/******************************************************************************* 1470 * 1471 * Function BTA_DmBleUpdateConnectionParams 1472 * 1473 * Description Update connection parameters, can only be used when 1474 * connection is up. 1475 * 1476 * Parameters: bd_addr - BD address of the peer 1477 * min_int - minimum connection interval, 1478 * [0x0004 ~ 0x4000] 1479 * max_int - maximum connection interval, 1480 * [0x0004 ~ 0x4000] 1481 * latency - slave latency [0 ~ 500] 1482 * timeout - supervision timeout [0x000a ~ 0xc80] 1483 * 1484 * Returns void 1485 * 1486 ******************************************************************************/ 1487void BTA_DmBleUpdateConnectionParams(const BD_ADDR bd_addr, uint16_t min_int, 1488 uint16_t max_int, uint16_t latency, 1489 uint16_t timeout) { 1490 tBTA_DM_API_UPDATE_CONN_PARAM* p_msg = 1491 (tBTA_DM_API_UPDATE_CONN_PARAM*)osi_calloc( 1492 sizeof(tBTA_DM_API_UPDATE_CONN_PARAM)); 1493 1494 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT; 1495 bdcpy(p_msg->bd_addr, bd_addr); 1496 p_msg->min_int = min_int; 1497 p_msg->max_int = max_int; 1498 p_msg->latency = latency; 1499 p_msg->timeout = timeout; 1500 1501 bta_sys_sendmsg(p_msg); 1502} 1503 1504/******************************************************************************* 1505 * 1506 * Function BTA_DmBleSetDataLength 1507 * 1508 * Description This function is to set maximum LE data packet size 1509 * 1510 * Returns void 1511 * 1512 * 1513 ******************************************************************************/ 1514void BTA_DmBleSetDataLength(BD_ADDR remote_device, uint16_t tx_data_length) { 1515 tBTA_DM_API_BLE_SET_DATA_LENGTH* p_msg = 1516 (tBTA_DM_API_BLE_SET_DATA_LENGTH*)osi_malloc( 1517 sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH)); 1518 1519 bdcpy(p_msg->remote_bda, remote_device); 1520 p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT; 1521 p_msg->tx_data_length = tx_data_length; 1522 1523 bta_sys_sendmsg(p_msg); 1524} 1525 1526 1527/******************************************************************************* 1528 * 1529 * Function BTA_DmSetEncryption 1530 * 1531 * Description This function is called to ensure that connection is 1532 * encrypted. Should be called only on an open connection. 1533 * Typically only needed for connections that first want to 1534 * bring up unencrypted links, then later encrypt them. 1535 * 1536 * Parameters: bd_addr - Address of the peer device 1537 * transport - transport of the link to be encruypted 1538 * p_callback - Pointer to callback function to indicat the 1539 * link encryption status 1540 * sec_act - This is the security action to indicate 1541 * what kind of BLE security level is required 1542 * for the BLE link if BLE is supported. 1543 * Note: This parameter is ignored for the 1544 * BR/EDR or if BLE is not supported. 1545 * 1546 * Returns void 1547 * 1548 ******************************************************************************/ 1549void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, 1550 tBTA_DM_ENCRYPT_CBACK* p_callback, 1551 tBTA_DM_BLE_SEC_ACT sec_act) { 1552 tBTA_DM_API_SET_ENCRYPTION* p_msg = (tBTA_DM_API_SET_ENCRYPTION*)osi_calloc( 1553 sizeof(tBTA_DM_API_SET_ENCRYPTION)); 1554 1555 APPL_TRACE_API("%s", __func__); 1556 1557 p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT; 1558 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN); 1559 p_msg->transport = transport; 1560 p_msg->p_callback = p_callback; 1561 p_msg->sec_act = sec_act; 1562 1563 bta_sys_sendmsg(p_msg); 1564} 1565 1566/******************************************************************************* 1567 * 1568 * Function BTA_DmCloseACL 1569 * 1570 * Description This function force to close an ACL connection and remove 1571 * the device from the security database list of known devices. 1572 * 1573 * Parameters: bd_addr - Address of the peer device 1574 * remove_dev - remove device or not after link down 1575 * 1576 * Returns void 1577 * 1578 ******************************************************************************/ 1579void BTA_DmCloseACL(BD_ADDR bd_addr, bool remove_dev, 1580 tBTA_TRANSPORT transport) { 1581 tBTA_DM_API_REMOVE_ACL* p_msg = 1582 (tBTA_DM_API_REMOVE_ACL*)osi_calloc(sizeof(tBTA_DM_API_REMOVE_ACL)); 1583 1584 APPL_TRACE_API("%s", __func__); 1585 1586 p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT; 1587 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN); 1588 p_msg->remove_dev = remove_dev; 1589 p_msg->transport = transport; 1590 1591 bta_sys_sendmsg(p_msg); 1592} 1593 1594/******************************************************************************* 1595 * 1596 * Function BTA_DmBleObserve 1597 * 1598 * Description This procedure keep the device listening for advertising 1599 * events from a broadcast device. 1600 * 1601 * Parameters start: start or stop observe. 1602 * 1603 * Returns void 1604 1605 * 1606 * Returns void. 1607 * 1608 ******************************************************************************/ 1609extern void BTA_DmBleObserve(bool start, uint8_t duration, 1610 tBTA_DM_SEARCH_CBACK* p_results_cb) { 1611 tBTA_DM_API_BLE_OBSERVE* p_msg = 1612 (tBTA_DM_API_BLE_OBSERVE*)osi_calloc(sizeof(tBTA_DM_API_BLE_OBSERVE)); 1613 1614 APPL_TRACE_API("%s:start = %d ", __func__, start); 1615 1616 p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT; 1617 p_msg->start = start; 1618 p_msg->duration = duration; 1619 p_msg->p_cback = p_results_cb; 1620 1621 bta_sys_sendmsg(p_msg); 1622} 1623 1624/******************************************************************************* 1625 * 1626 * Function BTA_VendorInit 1627 * 1628 * Description This function initializes vendor specific 1629 * 1630 * Returns void 1631 * 1632 ******************************************************************************/ 1633void BTA_VendorInit(void) { APPL_TRACE_API("BTA_VendorInit"); } 1634 1635/******************************************************************************* 1636 * 1637 * Function BTA_VendorCleanup 1638 * 1639 * Description This function frees up Broadcom specific VS specific dynamic 1640 * memory 1641 * 1642 * Returns void 1643 * 1644 ******************************************************************************/ 1645void BTA_VendorCleanup(void) { 1646 tBTM_BLE_VSC_CB cmn_ble_vsc_cb; 1647 BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); 1648 1649#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE) 1650 if (cmn_ble_vsc_cb.max_filter > 0) { 1651 btm_ble_adv_filter_cleanup(); 1652#if (BLE_PRIVACY_SPT == TRUE) 1653 btm_ble_resolving_list_cleanup(); 1654#endif 1655 } 1656 1657 if (cmn_ble_vsc_cb.tot_scan_results_strg > 0) btm_ble_batchscan_cleanup(); 1658#endif 1659 1660 if (cmn_ble_vsc_cb.adv_inst_max > 0) btm_ble_multi_adv_cleanup(); 1661} 1662 1663