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