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