1 /****************************************************************************** 2 * 3 * Copyright (C) 2003-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 /****************************************************************************** 20 * 21 * This is the API implementation file for the BTA device manager. 22 * 23 ******************************************************************************/ 24 25 #include "gki.h" 26 #include "bd.h" 27 #include "bta_sys.h" 28 #include "bta_api.h" 29 #include "bta_dm_int.h" 30 #include "bta_sys_int.h" 31 #include "btm_api.h" 32 #include "btm_int.h" 33 #include <string.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 GKI_sched_lock(); 74 bta_sys_register (BTA_ID_DM, &bta_dm_reg ); 75 bta_sys_register (BTA_ID_DM_SEARCH, &bta_dm_search_reg ); 76 77 /* if UUID list is not provided as static data */ 78 bta_sys_eir_register(bta_dm_eir_update_uuid); 79 80 GKI_sched_unlock(); 81 82 if ((p_msg = (tBTA_DM_API_ENABLE *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE))) != NULL) 83 { 84 p_msg->hdr.event = BTA_DM_API_ENABLE_EVT; 85 p_msg->p_sec_cback = p_cback; 86 bta_sys_sendmsg(p_msg); 87 return BTA_SUCCESS; 88 } 89 return BTA_FAILURE; 90 91 } 92 93 /******************************************************************************* 94 ** 95 ** Function BTA_DisableBluetooth 96 ** 97 ** Description Disables bluetooth service. This function is called when 98 ** the application no longer needs bluetooth service 99 ** 100 ** Returns void 101 ** 102 *******************************************************************************/ 103 tBTA_STATUS BTA_DisableBluetooth(void) 104 { 105 106 BT_HDR *p_msg; 107 108 if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) 109 { 110 p_msg->event = BTA_DM_API_DISABLE_EVT; 111 bta_sys_sendmsg(p_msg); 112 } 113 else 114 { 115 return BTA_FAILURE; 116 } 117 118 return BTA_SUCCESS; 119 } 120 121 /******************************************************************************* 122 ** 123 ** Function BTA_EnableTestMode 124 ** 125 ** Description Enables bluetooth device under test mode 126 ** 127 ** 128 ** Returns tBTA_STATUS 129 ** 130 *******************************************************************************/ 131 tBTA_STATUS BTA_EnableTestMode(void) 132 { 133 BT_HDR *p_msg; 134 135 APPL_TRACE_API0("BTA_EnableTestMode"); 136 137 if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) 138 { 139 p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT; 140 bta_sys_sendmsg(p_msg); 141 return BTA_SUCCESS; 142 } 143 return BTA_FAILURE; 144 } 145 146 /******************************************************************************* 147 ** 148 ** Function BTA_DisableTestMode 149 ** 150 ** Description Disable bluetooth device under test mode 151 ** 152 ** 153 ** Returns None 154 ** 155 *******************************************************************************/ 156 void BTA_DisableTestMode(void) 157 { 158 BT_HDR *p_msg; 159 160 APPL_TRACE_API0("BTA_DisableTestMode"); 161 162 if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) 163 { 164 p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT; 165 bta_sys_sendmsg(p_msg); 166 } 167 } 168 169 /******************************************************************************* 170 ** 171 ** Function BTA_DmIsDeviceUp 172 ** 173 ** Description Called during startup to check whether the bluetooth module 174 ** is up and ready 175 ** 176 ** Returns BOOLEAN 177 ** 178 *******************************************************************************/ 179 BOOLEAN BTA_DmIsDeviceUp(void) 180 { 181 182 BOOLEAN status; 183 184 GKI_sched_lock(); 185 status = BTM_IsDeviceUp(); 186 GKI_sched_unlock(); 187 return status; 188 189 } 190 191 /******************************************************************************* 192 ** 193 ** Function BTA_DmSetDeviceName 194 ** 195 ** Description This function sets the Bluetooth name of local device 196 ** 197 ** 198 ** Returns void 199 ** 200 *******************************************************************************/ 201 void BTA_DmSetDeviceName(char *p_name) 202 { 203 204 tBTA_DM_API_SET_NAME *p_msg; 205 206 if ((p_msg = (tBTA_DM_API_SET_NAME *) GKI_getbuf(sizeof(tBTA_DM_API_SET_NAME))) != NULL) 207 { 208 p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT; 209 /* truncate the name if needed */ 210 BCM_STRNCPY_S(p_msg->name, sizeof(p_msg->name), p_name, BD_NAME_LEN-1); 211 p_msg->name[BD_NAME_LEN-1]=0; 212 213 bta_sys_sendmsg(p_msg); 214 } 215 216 217 } 218 219 /******************************************************************************* 220 ** 221 ** Function BTA_DmSetVisibility 222 ** 223 ** Description This function sets the Bluetooth connectable, 224 ** discoverable, pairable and conn paired only modes of local device 225 ** 226 ** 227 ** Returns void 228 ** 229 *******************************************************************************/ 230 void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 pairable_mode, UINT8 conn_filter ) 231 { 232 233 tBTA_DM_API_SET_VISIBILITY *p_msg; 234 235 if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) 236 { 237 p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT; 238 p_msg->disc_mode = disc_mode; 239 p_msg->conn_mode = conn_mode; 240 p_msg->pair_mode = pairable_mode; 241 p_msg->conn_paired_only = conn_filter; 242 243 244 bta_sys_sendmsg(p_msg); 245 } 246 247 248 } 249 250 /******************************************************************************* 251 ** 252 ** Function BTA_DmSetScanParam 253 ** 254 ** Description This function sets the parameters for page scan and 255 ** inquiry scan. 256 ** 257 ** 258 ** Returns void 259 ** 260 *******************************************************************************/ 261 void BTA_DmSetScanParam (UINT16 page_scan_interval, UINT16 page_scan_window, 262 UINT16 inquiry_scan_interval, UINT16 inquiry_scan_window) 263 { 264 APPL_TRACE_API4 ("BTA_DmSetScanParam: %d, %d, %d, %d", 265 page_scan_interval, page_scan_window, 266 inquiry_scan_interval, inquiry_scan_window); 267 268 bta_dm_cb.page_scan_interval = page_scan_interval; 269 bta_dm_cb.page_scan_window = page_scan_window; 270 bta_dm_cb.inquiry_scan_interval = inquiry_scan_interval; 271 bta_dm_cb.inquiry_scan_window = inquiry_scan_window; 272 } 273 274 /******************************************************************************* 275 ** 276 ** Function BTA_DmSetAfhChannels 277 ** 278 ** Description This function sets the AFH first and 279 ** last disable channel, so channels within 280 ** that range are disabled. 281 ** 282 ** Returns void 283 ** 284 *******************************************************************************/ 285 void BTA_DmSetAfhChannels(UINT8 first, UINT8 last) 286 { 287 288 tBTA_DM_API_SET_AFH_CHANNELS_EVT *p_msg; 289 290 if ((p_msg = (tBTA_DM_API_SET_AFH_CHANNELS_EVT *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) 291 { 292 p_msg->hdr.event = BTA_DM_API_SET_AFH_CHANNELS_EVT; 293 p_msg->first = first; 294 p_msg->last = last; 295 bta_sys_sendmsg(p_msg); 296 } 297 298 299 } 300 301 /******************************************************************************* 302 ** 303 ** Function BTA_SetAfhChannelAssessment 304 ** 305 ** Description This function is called to set the channel assessment mode on or off 306 ** 307 ** Returns status 308 ** 309 *******************************************************************************/ 310 void BTA_DmSetAfhChannelAssessment (BOOLEAN enable_or_disable) 311 { 312 tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT *p_msg; 313 314 if ((p_msg = (tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT *) GKI_getbuf(sizeof(tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT))) != NULL) 315 { 316 p_msg->hdr.event = BTA_DM_API_SET_AFH_CHANNEL_ASSESMENT_EVT; 317 p_msg->enable_or_disable = enable_or_disable; 318 bta_sys_sendmsg(p_msg); 319 } 320 } 321 322 /******************************************************************************* 323 ** 324 ** Function BTA_DmVendorSpecificCommand 325 ** 326 ** Description This function sends the vendor specific command 327 ** to the controller 328 ** 329 ** 330 ** Returns tBTA_STATUS 331 ** 332 *******************************************************************************/ 333 tBTA_STATUS BTA_DmVendorSpecificCommand (UINT16 opcode, UINT8 param_len, 334 UINT8 *p_param_buf, 335 tBTA_VENDOR_CMPL_CBACK *p_cback) 336 { 337 338 tBTA_DM_API_VENDOR_SPECIFIC_COMMAND *p_msg; 339 UINT16 size; 340 341 /* If p_cback is NULL, Notify application */ 342 if (p_cback == NULL) 343 { 344 return (BTA_FAILURE); 345 } 346 else 347 { 348 size = sizeof (tBTA_DM_API_VENDOR_SPECIFIC_COMMAND) + param_len; 349 if ((p_msg = (tBTA_DM_API_VENDOR_SPECIFIC_COMMAND *) GKI_getbuf(size)) != NULL) 350 { 351 p_msg->hdr.event = BTA_DM_API_VENDOR_SPECIFIC_COMMAND_EVT; 352 p_msg->opcode = opcode; 353 p_msg->p_param_buf = (UINT8 *)(p_msg + 1); 354 p_msg->p_cback = p_cback; 355 356 if (p_param_buf && param_len) 357 { 358 memcpy (p_msg->p_param_buf, p_param_buf, param_len); 359 p_msg->param_len = param_len; 360 } 361 else 362 { 363 p_msg->param_len = 0; 364 p_msg->p_param_buf = NULL; 365 366 } 367 368 bta_sys_sendmsg(p_msg); 369 } 370 return (BTA_SUCCESS); 371 } 372 } 373 /******************************************************************************* 374 ** 375 ** Function BTA_DmSearch 376 ** 377 ** Description This function searches for peer Bluetooth devices. It performs 378 ** an inquiry and gets the remote name for devices. Service 379 ** discovery is done if services is non zero 380 ** 381 ** 382 ** Returns void 383 ** 384 *******************************************************************************/ 385 void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback) 386 { 387 388 tBTA_DM_API_SEARCH *p_msg; 389 390 if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(sizeof(tBTA_DM_API_SEARCH))) != NULL) 391 { 392 memset(p_msg, 0, sizeof(tBTA_DM_API_SEARCH)); 393 394 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT; 395 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ)); 396 p_msg->services = services; 397 p_msg->p_cback = p_cback; 398 p_msg->rs_res = BTA_DM_RS_NONE; 399 bta_sys_sendmsg(p_msg); 400 } 401 402 } 403 404 405 /******************************************************************************* 406 ** 407 ** Function BTA_DmSearchCancel 408 ** 409 ** Description This function cancels a search initiated by BTA_DmSearch 410 ** 411 ** 412 ** Returns void 413 ** 414 *******************************************************************************/ 415 void BTA_DmSearchCancel(void) 416 { 417 BT_HDR *p_msg; 418 419 if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) 420 { 421 p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT; 422 bta_sys_sendmsg(p_msg); 423 } 424 425 } 426 427 /******************************************************************************* 428 ** 429 ** Function BTA_DmDiscover 430 ** 431 ** Description This function does service discovery for services of a 432 ** peer device 433 ** 434 ** 435 ** Returns void 436 ** 437 *******************************************************************************/ 438 void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services, 439 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search) 440 { 441 tBTA_DM_API_DISCOVER *p_msg; 442 443 if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL) 444 { 445 memset(p_msg, 0, sizeof(tBTA_DM_API_DISCOVER)); 446 447 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT; 448 bdcpy(p_msg->bd_addr, bd_addr); 449 p_msg->services = services; 450 p_msg->p_cback = p_cback; 451 p_msg->sdp_search = sdp_search; 452 bta_sys_sendmsg(p_msg); 453 } 454 455 } 456 457 /******************************************************************************* 458 ** 459 ** Function BTA_DmDiscoverUUID 460 ** 461 ** Description This function does service discovery for services of a 462 ** peer device 463 ** 464 ** 465 ** Returns void 466 ** 467 *******************************************************************************/ 468 void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid, 469 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search) 470 { 471 tBTA_DM_API_DISCOVER *p_msg; 472 473 if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL) 474 { 475 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT; 476 bdcpy(p_msg->bd_addr, bd_addr); 477 p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level 478 p_msg->p_cback = p_cback; 479 p_msg->sdp_search = sdp_search; 480 481 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE 482 p_msg->num_uuid = 0; 483 p_msg->p_uuid = NULL; 484 #endif 485 memcpy( &p_msg->uuid, uuid, sizeof(tSDP_UUID) ); 486 bta_sys_sendmsg(p_msg); 487 } 488 489 } 490 /******************************************************************************* 491 ** 492 ** Function BTA_DmIsMaster 493 ** 494 ** Description This function checks if the local device is the master of 495 ** the link to the given device 496 ** 497 ** Returns TRUE if master. 498 ** FALSE if not. 499 ** 500 *******************************************************************************/ 501 BOOLEAN BTA_DmIsMaster(BD_ADDR bd_addr) 502 { 503 BOOLEAN is_master = FALSE; 504 UINT8 link_role; 505 506 BTM_GetRole(bd_addr, &link_role); 507 APPL_TRACE_API1("BTA_DmIsMaster role:x%x", link_role); 508 if(link_role == BTM_ROLE_MASTER) 509 { 510 is_master = TRUE; 511 } 512 return is_master; 513 } 514 515 /******************************************************************************* 516 ** 517 ** Function BTA_DmBond 518 ** 519 ** Description This function initiates a bonding procedure with a peer 520 ** device 521 ** 522 ** 523 ** Returns void 524 ** 525 *******************************************************************************/ 526 void BTA_DmBond(BD_ADDR bd_addr) 527 { 528 tBTA_DM_API_BOND *p_msg; 529 530 if ((p_msg = (tBTA_DM_API_BOND *) GKI_getbuf(sizeof(tBTA_DM_API_BOND))) != NULL) 531 { 532 p_msg->hdr.event = BTA_DM_API_BOND_EVT; 533 bdcpy(p_msg->bd_addr, bd_addr); 534 bta_sys_sendmsg(p_msg); 535 } 536 537 538 } 539 540 /******************************************************************************* 541 ** 542 ** Function BTA_DmBondCancel 543 ** 544 ** Description This function cancels the bonding procedure with a peer 545 ** device 546 ** 547 ** 548 ** Returns void 549 ** 550 *******************************************************************************/ 551 void BTA_DmBondCancel(BD_ADDR bd_addr) 552 { 553 tBTA_DM_API_BOND_CANCEL *p_msg; 554 555 if ((p_msg = (tBTA_DM_API_BOND_CANCEL *) GKI_getbuf(sizeof(tBTA_DM_API_BOND_CANCEL))) != NULL) 556 { 557 p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT; 558 bdcpy(p_msg->bd_addr, bd_addr); 559 bta_sys_sendmsg(p_msg); 560 } 561 562 563 } 564 565 /******************************************************************************* 566 ** 567 ** Function BTA_DmPinReply 568 ** 569 ** Description This function provides a pincode for a remote device when 570 ** one is requested by DM through BTA_DM_PIN_REQ_EVT 571 ** 572 ** 573 ** Returns void 574 ** 575 *******************************************************************************/ 576 void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin) 577 578 { 579 tBTA_DM_API_PIN_REPLY *p_msg; 580 581 if ((p_msg = (tBTA_DM_API_PIN_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PIN_REPLY))) != NULL) 582 { 583 p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT; 584 bdcpy(p_msg->bd_addr, bd_addr); 585 p_msg->accept = accept; 586 if(accept) 587 { 588 p_msg->pin_len = pin_len; 589 memcpy(p_msg->p_pin, p_pin, pin_len); 590 } 591 bta_sys_sendmsg(p_msg); 592 } 593 594 } 595 596 /******************************************************************************* 597 ** 598 ** Function BTA_DmLinkPolicy 599 ** 600 ** Description This function sets/clears the link policy mask to the given 601 ** bd_addr. 602 ** If clearing the sniff or park mode mask, the link is put 603 ** in active mode. 604 ** 605 ** Returns void 606 ** 607 *******************************************************************************/ 608 void BTA_DmLinkPolicy(BD_ADDR bd_addr, tBTA_DM_LP_MASK policy_mask, 609 BOOLEAN set) 610 { 611 tBTA_DM_API_LINK_POLICY *p_msg; 612 613 if ((p_msg = (tBTA_DM_API_LINK_POLICY *) GKI_getbuf(sizeof(tBTA_DM_API_LINK_POLICY))) != NULL) 614 { 615 p_msg->hdr.event = BTA_DM_API_LINK_POLICY_EVT; 616 bdcpy(p_msg->bd_addr, bd_addr); 617 p_msg->policy_mask = policy_mask; 618 p_msg->set = set; 619 bta_sys_sendmsg(p_msg); 620 } 621 } 622 623 624 #if (BTM_OOB_INCLUDED == TRUE) 625 /******************************************************************************* 626 ** 627 ** Function BTA_DmLocalOob 628 ** 629 ** Description This function retrieves the OOB data from local controller. 630 ** The result is reported by bta_dm_co_loc_oob(). 631 ** 632 ** Returns void 633 ** 634 *******************************************************************************/ 635 void BTA_DmLocalOob(void) 636 { 637 tBTA_DM_API_LOC_OOB *p_msg; 638 639 if ((p_msg = (tBTA_DM_API_LOC_OOB *) GKI_getbuf(sizeof(tBTA_DM_API_LOC_OOB))) != NULL) 640 { 641 p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT; 642 bta_sys_sendmsg(p_msg); 643 } 644 } 645 #endif /* BTM_OOB_INCLUDED */ 646 /******************************************************************************* 647 ** 648 ** Function BTA_DmConfirm 649 ** 650 ** Description This function accepts or rejects the numerical value of the 651 ** Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT 652 ** 653 ** Returns void 654 ** 655 *******************************************************************************/ 656 void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept) 657 { 658 tBTA_DM_API_CONFIRM *p_msg; 659 660 if ((p_msg = (tBTA_DM_API_CONFIRM *) GKI_getbuf(sizeof(tBTA_DM_API_CONFIRM))) != NULL) 661 { 662 p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT; 663 bdcpy(p_msg->bd_addr, bd_addr); 664 p_msg->accept = accept; 665 bta_sys_sendmsg(p_msg); 666 } 667 } 668 669 /******************************************************************************* 670 ** 671 ** Function BTA_DmPasskeyCancel 672 ** 673 ** Description This function is called to cancel the simple pairing process 674 ** reported by BTA_DM_SP_KEY_NOTIF_EVT 675 ** 676 ** Returns void 677 ** 678 *******************************************************************************/ 679 #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) 680 void BTA_DmPasskeyCancel(BD_ADDR bd_addr) 681 { 682 tBTA_DM_API_PASKY_CANCEL *p_msg; 683 684 if ((p_msg = (tBTA_DM_API_PASKY_CANCEL *) \ 685 GKI_getbuf(sizeof(tBTA_DM_API_PASKY_CANCEL))) != NULL) 686 { 687 p_msg->hdr.event = BTA_DM_API_PASKY_CANCEL_EVT; 688 bdcpy(p_msg->bd_addr, bd_addr); 689 bta_sys_sendmsg(p_msg); 690 } 691 } 692 #endif 693 694 695 /******************************************************************************* 696 ** 697 ** Function BTA_DmAddDevice 698 ** 699 ** Description This function adds a device to the security database list of 700 ** peer device 701 ** 702 ** 703 ** Returns void 704 ** 705 *******************************************************************************/ 706 void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key, 707 tBTA_SERVICE_MASK trusted_mask, BOOLEAN is_trusted, 708 UINT8 key_type, tBTA_IO_CAP io_cap) 709 { 710 711 tBTA_DM_API_ADD_DEVICE *p_msg; 712 713 if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL) 714 { 715 memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE)); 716 717 p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT; 718 bdcpy(p_msg->bd_addr, bd_addr); 719 p_msg->tm = trusted_mask; 720 p_msg->is_trusted = is_trusted; 721 p_msg->io_cap = io_cap; 722 723 if (link_key) 724 { 725 p_msg->link_key_known = TRUE; 726 p_msg->key_type = key_type; 727 memcpy(p_msg->link_key, link_key, LINK_KEY_LEN); 728 } 729 730 /* Load device class if specified */ 731 if (dev_class) 732 { 733 p_msg->dc_known = TRUE; 734 memcpy (p_msg->dc, dev_class, DEV_CLASS_LEN); 735 } 736 737 memset (p_msg->bd_name, 0, BD_NAME_LEN); 738 memset (p_msg->features, 0, sizeof (p_msg->features)); 739 740 bta_sys_sendmsg(p_msg); 741 } 742 } 743 744 745 /******************************************************************************* 746 ** 747 ** Function BTA_DmRemoveDevice 748 ** 749 ** Description This function removes a device fromthe security database list of 750 ** peer device 751 ** 752 ** 753 ** Returns void 754 ** 755 *******************************************************************************/ 756 tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr) 757 { 758 tBTA_DM_API_REMOVE_DEVICE *p_msg; 759 760 if ((p_msg = (tBTA_DM_API_REMOVE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_DEVICE))) != NULL) 761 { 762 memset (p_msg, 0, sizeof(tBTA_DM_API_REMOVE_DEVICE)); 763 764 p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT; 765 bdcpy(p_msg->bd_addr, bd_addr); 766 bta_sys_sendmsg(p_msg); 767 } 768 else 769 { 770 return BTA_FAILURE; 771 } 772 773 return BTA_SUCCESS; 774 } 775 776 /******************************************************************************* 777 ** 778 ** Function BTA_DmAddDevWithName 779 ** 780 ** Description This function is newer version of BTA_DmAddDevice() 781 ** which added bd_name and features as input parameters. 782 ** 783 ** 784 ** Returns void 785 ** 786 *******************************************************************************/ 787 void BTA_DmAddDevWithName (BD_ADDR bd_addr, DEV_CLASS dev_class, 788 BD_NAME bd_name, UINT8 *features, 789 LINK_KEY link_key, tBTA_SERVICE_MASK trusted_mask, 790 BOOLEAN is_trusted, UINT8 key_type, tBTA_IO_CAP io_cap) 791 { 792 tBTA_DM_API_ADD_DEVICE *p_msg; 793 794 if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL) 795 { 796 memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE)); 797 798 p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT; 799 bdcpy(p_msg->bd_addr, bd_addr); 800 p_msg->tm = trusted_mask; 801 p_msg->is_trusted = is_trusted; 802 p_msg->io_cap = io_cap; 803 804 if (link_key) 805 { 806 p_msg->link_key_known = TRUE; 807 p_msg->key_type = key_type; 808 memcpy(p_msg->link_key, link_key, LINK_KEY_LEN); 809 } 810 811 /* Load device class if specified */ 812 if (dev_class) 813 { 814 p_msg->dc_known = TRUE; 815 memcpy (p_msg->dc, dev_class, DEV_CLASS_LEN); 816 } 817 818 if (bd_name) 819 memcpy(p_msg->bd_name, bd_name, BD_NAME_LEN); 820 821 if (features) 822 memcpy(p_msg->features, features, sizeof(p_msg->features)); 823 824 bta_sys_sendmsg(p_msg); 825 } 826 } 827 828 /******************************************************************************* 829 ** 830 ** Function BTA_DmAuthorizeReply 831 ** 832 ** Description This function provides an authorization reply when authorization 833 ** is requested by BTA through BTA_DM_AUTHORIZE_EVT 834 ** 835 ** 836 ** Returns tBTA_STATUS 837 ** 838 *******************************************************************************/ 839 void BTA_DmAuthorizeReply(BD_ADDR bd_addr, tBTA_SERVICE_ID service, tBTA_AUTH_RESP response) 840 { 841 842 tBTA_DM_API_AUTH_REPLY *p_msg; 843 844 if ((p_msg = (tBTA_DM_API_AUTH_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_AUTH_REPLY))) != NULL) 845 { 846 p_msg->hdr.event = BTA_DM_API_AUTH_REPLY_EVT; 847 bdcpy(p_msg->bd_addr, bd_addr); 848 p_msg->service = service; 849 p_msg->response = response; 850 851 bta_sys_sendmsg(p_msg); 852 } 853 854 } 855 856 /******************************************************************************* 857 ** 858 ** Function BTA_DmSignalStrength 859 ** 860 ** Description This function initiates RSSI and channnel quality 861 ** measurments. BTA_DM_SIG_STRENGTH_EVT is sent to 862 ** application with the values of RSSI and channel 863 ** quality 864 ** 865 ** 866 ** Returns void 867 ** 868 *******************************************************************************/ 869 void BTA_DmSignalStrength(tBTA_SIG_STRENGTH_MASK mask, UINT16 period, BOOLEAN start) 870 { 871 872 tBTA_API_DM_SIG_STRENGTH *p_msg; 873 874 if ((p_msg = (tBTA_API_DM_SIG_STRENGTH *) GKI_getbuf(sizeof(tBTA_API_DM_SIG_STRENGTH))) != NULL) 875 { 876 p_msg->hdr.event = BTA_API_DM_SIG_STRENGTH_EVT; 877 p_msg->mask = mask; 878 p_msg->period = period; 879 p_msg->start = start; 880 881 bta_sys_sendmsg(p_msg); 882 } 883 884 885 } 886 887 /******************************************************************************* 888 ** 889 ** Function BTA_DmWriteInqTxPower 890 ** 891 ** Description This command is used to write the inquiry transmit power level 892 ** used to transmit the inquiry (ID) data packets. 893 ** 894 ** Parameters tx_power - tx inquiry power to use, valid value is -70 ~ 20 895 896 ** Returns void 897 ** 898 *******************************************************************************/ 899 void BTA_DmWriteInqTxPower(INT8 tx_power) 900 { 901 902 tBTA_API_DM_TX_INQPWR *p_msg; 903 904 if ((p_msg = (tBTA_API_DM_TX_INQPWR *) GKI_getbuf(sizeof(tBTA_API_DM_TX_INQPWR))) != NULL) 905 { 906 p_msg->hdr.event = BTA_DM_API_TX_INQPWR_EVT; 907 p_msg->tx_power = tx_power; 908 909 bta_sys_sendmsg(p_msg); 910 } 911 } 912 913 914 /******************************************************************************* 915 ** 916 ** Function BTA_DmEirAddUUID 917 ** 918 ** Description This function is called to add UUID into EIR. 919 ** 920 ** Parameters tBT_UUID - UUID 921 ** 922 ** Returns None 923 ** 924 *******************************************************************************/ 925 void BTA_DmEirAddUUID (tBT_UUID *p_uuid) 926 { 927 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) 928 tBTA_DM_API_UPDATE_EIR_UUID *p_msg; 929 930 if ((p_msg = (tBTA_DM_API_UPDATE_EIR_UUID *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_EIR_UUID))) != NULL) 931 { 932 p_msg->hdr.event = BTA_DM_API_UPDATE_EIR_UUID_EVT; 933 p_msg->is_add = TRUE; 934 memcpy (&(p_msg->uuid), p_uuid, sizeof(tBT_UUID)); 935 936 bta_sys_sendmsg(p_msg); 937 } 938 #endif 939 } 940 941 /******************************************************************************* 942 ** 943 ** Function BTA_DmEirRemoveUUID 944 ** 945 ** Description This function is called to remove UUID from EIR. 946 ** 947 ** Parameters tBT_UUID - UUID 948 ** 949 ** Returns None 950 ** 951 *******************************************************************************/ 952 void BTA_DmEirRemoveUUID (tBT_UUID *p_uuid) 953 { 954 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) 955 tBTA_DM_API_UPDATE_EIR_UUID *p_msg; 956 957 if ((p_msg = (tBTA_DM_API_UPDATE_EIR_UUID *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_EIR_UUID))) != NULL) 958 { 959 p_msg->hdr.event = BTA_DM_API_UPDATE_EIR_UUID_EVT; 960 p_msg->is_add = FALSE; 961 memcpy (&(p_msg->uuid), p_uuid, sizeof(tBT_UUID)); 962 963 bta_sys_sendmsg(p_msg); 964 } 965 #endif 966 } 967 968 /******************************************************************************* 969 ** 970 ** Function BTA_DmSetEIRConfig 971 ** 972 ** Description This function is called to override the BTA default EIR parameters. 973 ** This funciton is only valid in a system where BTU & App task 974 ** are in the same memory space. 975 ** 976 ** Parameters Pointer to User defined EIR config 977 ** 978 ** Returns None 979 ** 980 *******************************************************************************/ 981 void BTA_DmSetEIRConfig (tBTA_DM_EIR_CONF *p_eir_cfg) 982 { 983 #if (BTM_EIR_SERVER_INCLUDED == TRUE) 984 tBTA_DM_API_SET_EIR_CONFIG *p_msg; 985 986 if ((p_msg = (tBTA_DM_API_SET_EIR_CONFIG *) GKI_getbuf(sizeof(tBTA_DM_API_SET_EIR_CONFIG))) != NULL) 987 { 988 p_msg->hdr.event = BTA_DM_API_SET_EIR_CONFIG_EVT; 989 p_msg->p_eir_cfg = p_eir_cfg; 990 991 bta_sys_sendmsg(p_msg); 992 } 993 #endif 994 } 995 996 /******************************************************************************* 997 ** 998 ** Function BTA_CheckEirData 999 ** 1000 ** Description This function is called to get EIR data from significant part. 1001 ** 1002 ** Parameters p_eir - pointer of EIR significant part 1003 ** type - finding EIR data type 1004 ** p_length - return the length of EIR data 1005 ** 1006 ** Returns pointer of EIR data 1007 ** 1008 *******************************************************************************/ 1009 UINT8 *BTA_CheckEirData( UINT8 *p_eir, UINT8 type, UINT8 *p_length ) 1010 { 1011 #if ( BTM_EIR_CLIENT_INCLUDED == TRUE ) 1012 return BTM_CheckEirData( p_eir, type, p_length ); 1013 #else 1014 return NULL; 1015 #endif 1016 } 1017 1018 /******************************************************************************* 1019 ** 1020 ** Function BTA_GetEirService 1021 ** 1022 ** Description This function is called to get BTA service mask from EIR. 1023 ** 1024 ** Parameters p_eir - pointer of EIR significant part 1025 ** p_services - return the BTA service mask 1026 ** 1027 ** Returns None 1028 ** 1029 *******************************************************************************/ 1030 extern const UINT16 bta_service_id_to_uuid_lkup_tbl []; 1031 void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services ) 1032 { 1033 #if ( BTM_EIR_CLIENT_INCLUDED == TRUE ) 1034 UINT8 xx, yy; 1035 UINT8 num_uuid, max_num_uuid = 32; 1036 UINT8 uuid_list[32*LEN_UUID_16]; 1037 UINT16 *p_uuid16 = (UINT16 *)uuid_list; 1038 tBTA_SERVICE_MASK mask; 1039 1040 BTM_GetEirUuidList( p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid); 1041 for( xx = 0; xx < num_uuid; xx++ ) 1042 { 1043 mask = 1; 1044 for( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ ) 1045 { 1046 if( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] ) 1047 { 1048 *p_services |= mask; 1049 break; 1050 } 1051 mask <<= 1; 1052 } 1053 1054 /* for HSP v1.2 only device */ 1055 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS) 1056 *p_services |= BTA_HSP_SERVICE_MASK; 1057 1058 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE) 1059 *p_services |= BTA_HL_SERVICE_MASK; 1060 1061 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK) 1062 *p_services |= BTA_HL_SERVICE_MASK; 1063 } 1064 #endif 1065 } 1066 1067 /******************************************************************************* 1068 ** 1069 ** Function BTA_DmUseSsr 1070 ** 1071 ** Description This function is called to check if the connected peer device 1072 ** supports SSR or not. 1073 ** 1074 ** Returns TRUE, if SSR is supported 1075 ** 1076 *******************************************************************************/ 1077 BOOLEAN BTA_DmUseSsr( BD_ADDR bd_addr ) 1078 { 1079 BOOLEAN use_ssr = FALSE; 1080 tBTA_DM_PEER_DEVICE * p_dev = bta_dm_find_peer_device(bd_addr); 1081 if(p_dev && (p_dev->info & BTA_DM_DI_USE_SSR) ) 1082 use_ssr = TRUE; 1083 return use_ssr; 1084 } 1085 1086 /******************************************************************************* 1087 ** Device Identification (DI) Server Functions 1088 *******************************************************************************/ 1089 /******************************************************************************* 1090 ** 1091 ** Function BTA_DmSetLocalDiRecord 1092 ** 1093 ** Description This function adds a DI record to the local SDP database. 1094 ** 1095 ** Returns BTA_SUCCESS if record set sucessfully, otherwise error code. 1096 ** 1097 *******************************************************************************/ 1098 tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info, 1099 UINT32 *p_handle ) 1100 { 1101 tBTA_STATUS status = BTA_FAILURE; 1102 1103 if(bta_dm_di_cb.di_num < BTA_DI_NUM_MAX) 1104 { 1105 if(SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS) 1106 { 1107 if(!p_device_info->primary_record) 1108 { 1109 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle; 1110 bta_dm_di_cb.di_num ++; 1111 } 1112 1113 bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION); 1114 status = BTA_SUCCESS; 1115 } 1116 } 1117 1118 return status; 1119 } 1120 1121 /******************************************************************************* 1122 ** 1123 ** Function BTA_DmGetLocalDiRecord 1124 ** 1125 ** Description Get a specified DI record to the local SDP database. If no 1126 ** record handle is provided, the primary DI record will be 1127 ** returned. 1128 ** 1129 ** Fills in the device information of the record 1130 ** p_handle - if p_handle == 0, the primary record is returned 1131 ** 1132 ** Returns BTA_SUCCESS if record set sucessfully, otherwise error code. 1133 ** 1134 *******************************************************************************/ 1135 tBTA_STATUS BTA_DmGetLocalDiRecord( tBTA_DI_GET_RECORD *p_device_info, 1136 UINT32 *p_handle ) 1137 { 1138 UINT16 status; 1139 1140 status = SDP_GetLocalDiRecord(p_device_info, p_handle); 1141 1142 if (status == SDP_SUCCESS) 1143 return BTA_SUCCESS; 1144 else 1145 return BTA_FAILURE; 1146 1147 } 1148 1149 /******************************************************************************* 1150 ** Device Identification (DI) Client Functions 1151 *******************************************************************************/ 1152 /******************************************************************************* 1153 ** 1154 ** Function BTA_DmDiDiscover 1155 ** 1156 ** Description This function queries a remote device for DI information. 1157 ** 1158 ** 1159 ** Returns None. 1160 ** 1161 *******************************************************************************/ 1162 void BTA_DmDiDiscover( BD_ADDR remote_device, tBTA_DISCOVERY_DB *p_db, 1163 UINT32 len, tBTA_DM_SEARCH_CBACK *p_cback ) 1164 { 1165 tBTA_DM_API_DI_DISC *p_msg; 1166 1167 if ((p_msg = (tBTA_DM_API_DI_DISC *) GKI_getbuf(sizeof(tBTA_DM_API_DI_DISC))) != NULL) 1168 { 1169 bdcpy(p_msg->bd_addr, remote_device); 1170 p_msg->hdr.event = BTA_DM_API_DI_DISCOVER_EVT; 1171 p_msg->p_sdp_db = p_db; 1172 p_msg->len = len; 1173 p_msg->p_cback = p_cback; 1174 1175 bta_sys_sendmsg(p_msg); 1176 } 1177 } 1178 1179 /******************************************************************************* 1180 ** 1181 ** Function BTA_DmGetDiRecord 1182 ** 1183 ** Description This function retrieves a remote device's DI record from 1184 ** the specified database. 1185 ** 1186 ** Returns BTA_SUCCESS if Get DI record is succeed. 1187 ** BTA_FAILURE if Get DI record failed. 1188 ** 1189 *******************************************************************************/ 1190 tBTA_STATUS BTA_DmGetDiRecord( UINT8 get_record_index, tBTA_DI_GET_RECORD *p_device_info, 1191 tBTA_DISCOVERY_DB *p_db ) 1192 { 1193 if (SDP_GetDiRecord(get_record_index, p_device_info, p_db) != SDP_SUCCESS) 1194 return BTA_FAILURE; 1195 else 1196 return BTA_SUCCESS; 1197 } 1198 1199 /******************************************************************************* 1200 ** 1201 ** Function BTA_SysFeatures 1202 ** 1203 ** Description This function is called to set system features. 1204 ** 1205 ** Returns void 1206 ** 1207 *******************************************************************************/ 1208 void BTA_SysFeatures (UINT16 sys_features) 1209 { 1210 bta_sys_cb.sys_features = sys_features; 1211 1212 APPL_TRACE_API1("BTA_SysFeatures: sys_features = %d", sys_features); 1213 } 1214 1215 /******************************************************************************* 1216 ** 1217 ** Function bta_dmexecutecallback 1218 ** 1219 ** Description This function will request BTA to execute a call back in the context of BTU task 1220 ** This API was named in lower case because it is only intended 1221 ** for the internal customers(like BTIF). 1222 ** 1223 ** Returns void 1224 ** 1225 *******************************************************************************/ 1226 void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param) 1227 { 1228 tBTA_DM_API_EXECUTE_CBACK *p_msg; 1229 1230 if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) 1231 { 1232 p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT; 1233 p_msg->p_param= p_param; 1234 p_msg->p_exec_cback= p_callback; 1235 bta_sys_sendmsg(p_msg); 1236 } 1237 } 1238 1239 /******************************************************************************* 1240 ** 1241 ** Function BTA_DmAddBleKey 1242 ** 1243 ** Description Add/modify LE device information. This function will be 1244 ** normally called during host startup to restore all required 1245 ** information stored in the NVRAM. 1246 ** 1247 ** Parameters: bd_addr - BD address of the peer 1248 ** p_le_key - LE key values. 1249 ** key_type - LE SMP key type. 1250 ** 1251 ** Returns void 1252 ** 1253 *******************************************************************************/ 1254 void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_TYPE key_type) 1255 { 1256 #if BLE_INCLUDED == TRUE 1257 1258 tBTA_DM_API_ADD_BLEKEY *p_msg; 1259 1260 if ((p_msg = (tBTA_DM_API_ADD_BLEKEY *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLEKEY))) != NULL) 1261 { 1262 memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLEKEY)); 1263 1264 p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT; 1265 p_msg->key_type = key_type; 1266 bdcpy(p_msg->bd_addr, bd_addr); 1267 memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE)); 1268 1269 bta_sys_sendmsg(p_msg); 1270 } 1271 1272 #endif 1273 } 1274 1275 /******************************************************************************* 1276 ** 1277 ** Function BTA_DmAddBleDevice 1278 ** 1279 ** Description Add a BLE device. This function will be normally called 1280 ** during host startup to restore all required information 1281 ** for a LE device stored in the NVRAM. 1282 ** 1283 ** Parameters: bd_addr - BD address of the peer 1284 ** dev_type - Remote device's device type. 1285 ** addr_type - LE device address type. 1286 ** 1287 ** Returns void 1288 ** 1289 *******************************************************************************/ 1290 void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TYPE dev_type) 1291 { 1292 #if BLE_INCLUDED == TRUE 1293 tBTA_DM_API_ADD_BLE_DEVICE *p_msg; 1294 1295 if ((p_msg = (tBTA_DM_API_ADD_BLE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLE_DEVICE))) != NULL) 1296 { 1297 memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLE_DEVICE)); 1298 1299 p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT; 1300 bdcpy(p_msg->bd_addr, bd_addr); 1301 p_msg->addr_type = addr_type; 1302 p_msg->dev_type = dev_type; 1303 1304 bta_sys_sendmsg(p_msg); 1305 } 1306 #endif 1307 } 1308 /******************************************************************************* 1309 ** 1310 ** Function BTA_DmBlePasskeyReply 1311 ** 1312 ** Description Send BLE SMP passkey reply. 1313 ** 1314 ** Parameters: bd_addr - BD address of the peer 1315 ** accept - passkey entry sucessful or declined. 1316 ** passkey - passkey value, must be a 6 digit number, 1317 ** can be lead by 0. 1318 ** 1319 ** Returns void 1320 ** 1321 *******************************************************************************/ 1322 void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey) 1323 { 1324 #if BLE_INCLUDED == TRUE 1325 tBTA_DM_API_PASSKEY_REPLY *p_msg; 1326 1327 if ((p_msg = (tBTA_DM_API_PASSKEY_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PASSKEY_REPLY))) != NULL) 1328 { 1329 memset(p_msg, 0, sizeof(tBTA_DM_API_PASSKEY_REPLY)); 1330 1331 p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT; 1332 bdcpy(p_msg->bd_addr, bd_addr); 1333 p_msg->accept = accept; 1334 1335 if(accept) 1336 { 1337 p_msg->passkey = passkey; 1338 } 1339 bta_sys_sendmsg(p_msg); 1340 } 1341 #endif 1342 } 1343 /******************************************************************************* 1344 ** 1345 ** Function BTA_DmBleSecurityGrant 1346 ** 1347 ** Description Grant security request access. 1348 ** 1349 ** Parameters: bd_addr - BD address of the peer 1350 ** res - security grant status. 1351 ** 1352 ** Returns void 1353 ** 1354 *******************************************************************************/ 1355 void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res) 1356 { 1357 #if BLE_INCLUDED == TRUE 1358 tBTA_DM_API_BLE_SEC_GRANT *p_msg; 1359 1360 if ((p_msg = (tBTA_DM_API_BLE_SEC_GRANT *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SEC_GRANT))) != NULL) 1361 { 1362 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SEC_GRANT)); 1363 1364 p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT; 1365 bdcpy(p_msg->bd_addr, bd_addr); 1366 p_msg->res = res; 1367 1368 bta_sys_sendmsg(p_msg); 1369 } 1370 #endif 1371 } 1372 /******************************************************************************* 1373 ** 1374 ** Function BTA_DmSetBlePrefConnParams 1375 ** 1376 ** Description This function is called to set the preferred connection 1377 ** parameters when default connection parameter is not desired. 1378 ** 1379 ** Parameters: bd_addr - BD address of the peripheral 1380 ** scan_interval - scan interval 1381 ** scan_window - scan window 1382 ** min_conn_int - minimum preferred connection interval 1383 ** max_conn_int - maximum preferred connection interval 1384 ** slave_latency - preferred slave latency 1385 ** supervision_tout - preferred supervision timeout 1386 ** 1387 ** 1388 ** Returns void 1389 ** 1390 *******************************************************************************/ 1391 void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr, 1392 UINT16 min_conn_int, UINT16 max_conn_int, 1393 UINT16 slave_latency, UINT16 supervision_tout ) 1394 { 1395 #if BLE_INCLUDED == TRUE 1396 tBTA_DM_API_BLE_CONN_PARAMS *p_msg; 1397 1398 if ((p_msg = (tBTA_DM_API_BLE_CONN_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_CONN_PARAMS))) != NULL) 1399 { 1400 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_CONN_PARAMS)); 1401 1402 p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT; 1403 1404 memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN); 1405 1406 p_msg->conn_int_max = max_conn_int; 1407 p_msg->conn_int_min = min_conn_int; 1408 p_msg->slave_latency = slave_latency; 1409 p_msg->supervision_tout = supervision_tout; 1410 1411 bta_sys_sendmsg(p_msg); 1412 } 1413 #endif 1414 } 1415 1416 /******************************************************************************* 1417 ** 1418 ** Function BTA_DmSetBleConnScanParams 1419 ** 1420 ** Description This function is called to set scan parameters used in 1421 ** BLE connection request 1422 ** 1423 ** Parameters: scan_interval - scan interval 1424 ** scan_window - scan window 1425 ** 1426 ** Returns void 1427 ** 1428 *******************************************************************************/ 1429 void BTA_DmSetBleConnScanParams(UINT16 scan_interval, UINT16 scan_window ) 1430 { 1431 #if BLE_INCLUDED == TRUE 1432 tBTA_DM_API_BLE_SCAN_PARAMS *p_msg; 1433 1434 if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) 1435 { 1436 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS)); 1437 1438 p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT; 1439 1440 p_msg->scan_int = scan_interval; 1441 p_msg->scan_window = scan_window; 1442 1443 bta_sys_sendmsg(p_msg); 1444 } 1445 #endif 1446 } 1447 1448 /******************************************************************************* 1449 ** 1450 ** Function BTA_DmSetBleAdvParams 1451 ** 1452 ** Description This function sets the advertising parameters BLE functionality. 1453 ** It is to be called when device act in peripheral or broadcaster 1454 ** role. 1455 ** 1456 ** 1457 ** Returns void 1458 ** 1459 *******************************************************************************/ 1460 void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max, 1461 tBLE_BD_ADDR *p_dir_bda) 1462 { 1463 #if BLE_INCLUDED == TRUE 1464 tBTA_DM_API_BLE_ADV_PARAMS *p_msg; 1465 1466 APPL_TRACE_API2 ("BTA_DmSetBleAdvParam: %d, %d", adv_int_min, adv_int_max); 1467 1468 if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS))) != NULL) 1469 { 1470 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS)); 1471 1472 p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_EVT; 1473 1474 p_msg->adv_int_min = adv_int_min; 1475 p_msg->adv_int_max = adv_int_max; 1476 1477 if (p_dir_bda != NULL) 1478 { 1479 p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1); 1480 memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR)); 1481 } 1482 1483 bta_sys_sendmsg(p_msg); 1484 } 1485 #endif 1486 } 1487 1488 #if BLE_INCLUDED == TRUE 1489 /******************************************************************************* 1490 ** 1491 ** Function BTA_DmBleSetAdvConfig 1492 ** 1493 ** Description This function is called to override the BTA default ADV parameters. 1494 ** 1495 ** Parameters Pointer to User defined ADV data structure 1496 ** 1497 ** Returns None 1498 ** 1499 *******************************************************************************/ 1500 void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg) 1501 { 1502 tBTA_DM_API_SET_ADV_CONFIG *p_msg; 1503 1504 if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *) GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) 1505 { 1506 p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_EVT; 1507 p_msg->data_mask = data_mask; 1508 p_msg->p_adv_cfg = p_adv_cfg; 1509 1510 bta_sys_sendmsg(p_msg); 1511 } 1512 } 1513 1514 /******************************************************************************* 1515 ** 1516 ** Function BTA_DmBleSetScanRsp 1517 ** 1518 ** Description This function is called to override the BTA scan response. 1519 ** 1520 ** Parameters Pointer to User defined ADV data structure 1521 ** 1522 ** Returns None 1523 ** 1524 *******************************************************************************/ 1525 BTA_API extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg) 1526 { 1527 tBTA_DM_API_SET_ADV_CONFIG *p_msg; 1528 1529 if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *) GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) 1530 { 1531 p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_EVT; 1532 p_msg->data_mask = data_mask; 1533 p_msg->p_adv_cfg = p_adv_cfg; 1534 1535 bta_sys_sendmsg(p_msg); 1536 } 1537 } 1538 1539 /******************************************************************************* 1540 ** 1541 ** Function BTA_DmBleBroadcast 1542 ** 1543 ** Description This function starts or stops LE broadcasting. 1544 ** 1545 ** Parameters start: start or stop broadcast. 1546 ** 1547 ** Returns None 1548 ** 1549 *******************************************************************************/ 1550 BTA_API extern void BTA_DmBleBroadcast (BOOLEAN start) 1551 { 1552 tBTA_DM_API_BLE_OBSERVE *p_msg; 1553 1554 APPL_TRACE_API1("BTA_DmBleBroadcast: start = %d ", start); 1555 1556 if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) 1557 { 1558 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE)); 1559 1560 p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT; 1561 p_msg->start = start; 1562 1563 bta_sys_sendmsg(p_msg); 1564 } 1565 } 1566 1567 #endif 1568 /******************************************************************************* 1569 ** 1570 ** Function BTA_DmBleSetBgConnType 1571 ** 1572 ** Description This function is called to set BLE connectable mode for a 1573 ** peripheral device. 1574 ** 1575 ** Parameters bg_conn_type: it can be auto connection, or selective connection. 1576 ** p_select_cback: callback function when selective connection procedure 1577 ** is being used. 1578 ** 1579 ** Returns void 1580 ** 1581 *******************************************************************************/ 1582 void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback) 1583 { 1584 #if BLE_INCLUDED == TRUE 1585 tBTA_DM_API_BLE_SET_BG_CONN_TYPE *p_msg; 1586 1587 if ((p_msg = (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE))) != NULL) 1588 { 1589 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE)); 1590 1591 p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE; 1592 p_msg->bg_conn_type = bg_conn_type; 1593 p_msg->p_select_cback = p_select_cback; 1594 1595 bta_sys_sendmsg(p_msg); 1596 } 1597 #endif 1598 } 1599 /******************************************************************************* 1600 ** 1601 ** Function BTA_DmDiscoverExt 1602 ** 1603 ** Description This function does service discovery for services of a 1604 ** peer device. When services.num_uuid is 0, it indicates all 1605 ** GATT based services are to be searched; other wise a list of 1606 ** UUID of interested services should be provided through 1607 ** p_services->p_uuid. 1608 ** 1609 ** 1610 ** 1611 ** Returns void 1612 ** 1613 *******************************************************************************/ 1614 void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services, 1615 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search) 1616 { 1617 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE 1618 tBTA_DM_API_DISCOVER *p_msg; 1619 UINT16 len = p_services ? (sizeof(tBTA_DM_API_DISCOVER) + sizeof(tBT_UUID) * p_services->num_uuid) : 1620 sizeof(tBTA_DM_API_DISCOVER); 1621 1622 if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(len)) != NULL) 1623 { 1624 memset(p_msg, 0, len); 1625 1626 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT; 1627 bdcpy(p_msg->bd_addr, bd_addr); 1628 p_msg->p_cback = p_cback; 1629 p_msg->sdp_search = sdp_search; 1630 1631 if (p_services != NULL) 1632 { 1633 p_msg->services = p_services->srvc_mask; 1634 p_msg->num_uuid = p_services->num_uuid; 1635 1636 if (p_services->num_uuid != 0) 1637 { 1638 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1); 1639 memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid); 1640 } 1641 } 1642 1643 bta_sys_sendmsg(p_msg); 1644 } 1645 #endif 1646 1647 } 1648 1649 /******************************************************************************* 1650 ** 1651 ** Function BTA_DmSearchExt 1652 ** 1653 ** Description This function searches for peer Bluetooth devices. It performs 1654 ** an inquiry and gets the remote name for devices. Service 1655 ** discovery is done if services is non zero 1656 ** 1657 ** Parameters p_dm_inq: inquiry conditions 1658 ** p_services: if service is not empty, service discovery will be done. 1659 ** for all GATT based service condition, put num_uuid, and 1660 ** p_uuid is the pointer to the list of UUID values. 1661 ** p_cback: callback functino when search is completed. 1662 ** 1663 ** 1664 ** 1665 ** Returns void 1666 ** 1667 *******************************************************************************/ 1668 void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback) 1669 { 1670 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE 1671 tBTA_DM_API_SEARCH *p_msg; 1672 UINT16 len = p_services ? (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid) : 1673 sizeof(tBTA_DM_API_SEARCH); 1674 1675 if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(len)) != NULL) 1676 { 1677 memset(p_msg, 0, len); 1678 1679 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT; 1680 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ)); 1681 p_msg->p_cback = p_cback; 1682 p_msg->rs_res = BTA_DM_RS_NONE; 1683 1684 1685 if (p_services != NULL) 1686 { 1687 p_msg->services = p_services->srvc_mask; 1688 p_msg->num_uuid = p_services->num_uuid; 1689 1690 if (p_services->num_uuid != 0) 1691 { 1692 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1); 1693 memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid); 1694 } 1695 else 1696 p_msg->p_uuid = NULL; 1697 } 1698 1699 bta_sys_sendmsg(p_msg); 1700 } 1701 #endif 1702 } 1703 1704 /******************************************************************************* 1705 ** 1706 ** Function BTA_DmBleEnableRemotePrivacy 1707 ** 1708 ** Description Enable/disable privacy on a remote device 1709 ** 1710 ** Parameters: bd_addr - BD address of the peer 1711 ** privacy_enable - enable/disabe privacy on remote device. 1712 ** 1713 ** Returns void 1714 ** 1715 *******************************************************************************/ 1716 void BTA_DmBleEnableRemotePrivacy(BD_ADDR bd_addr, BOOLEAN privacy_enable) 1717 { 1718 #if BLE_INCLUDED == TRUE 1719 #endif 1720 } 1721 1722 1723 /******************************************************************************* 1724 ** 1725 ** Function BTA_DmBleConfigLocalPrivacy 1726 ** 1727 ** Description Enable/disable privacy on the local device 1728 ** 1729 ** Parameters: privacy_enable - enable/disabe privacy on remote device. 1730 ** 1731 ** Returns void 1732 ** 1733 *******************************************************************************/ 1734 void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable) 1735 { 1736 #if BLE_INCLUDED == TRUE 1737 #endif 1738 } 1739 1740 1741 /******************************************************************************* 1742 ** 1743 ** Function BTA_DmSetEncryption 1744 ** 1745 ** Description This function is called to ensure that connection is 1746 ** encrypted. Should be called only on an open connection. 1747 ** Typically only needed for connections that first want to 1748 ** bring up unencrypted links, then later encrypt them. 1749 ** 1750 ** Parameters: bd_addr - Address of the peer device 1751 ** p_callback - Pointer to callback function to indicat the 1752 ** link encryption status 1753 ** sec_act - This is the security action to indicate 1754 ** what knid of BLE security level is required for 1755 ** the BLE link if the BLE is supported 1756 ** Note: This parameter is ignored for the BR/EDR link 1757 ** or the BLE is not supported 1758 ** 1759 ** Returns void 1760 ** 1761 *******************************************************************************/ 1762 void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_DM_ENCRYPT_CBACK *p_callback, 1763 tBTA_DM_BLE_SEC_ACT sec_act) 1764 { 1765 tBTA_DM_API_SET_ENCRYPTION *p_msg; 1766 1767 APPL_TRACE_API0("BTA_DmSetEncryption"); //todo 1768 if ((p_msg = (tBTA_DM_API_SET_ENCRYPTION *) GKI_getbuf(sizeof(tBTA_DM_API_SET_ENCRYPTION))) != NULL) 1769 { 1770 memset(p_msg, 0, sizeof(tBTA_DM_API_SET_ENCRYPTION)); 1771 1772 p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT; 1773 1774 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN); 1775 p_msg->p_callback = p_callback; 1776 p_msg->sec_act = sec_act; 1777 1778 bta_sys_sendmsg(p_msg); 1779 } 1780 } 1781 1782 /******************************************************************************* 1783 ** 1784 ** Function BTA_DmCloseACL 1785 ** 1786 ** Description This function force to close an ACL connection and remove the 1787 ** device from the security database list of known devices. 1788 ** 1789 ** Parameters: bd_addr - Address of the peer device 1790 ** remove_dev - remove device or not after link down 1791 ** 1792 ** Returns void 1793 ** 1794 *******************************************************************************/ 1795 void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev) 1796 { 1797 tBTA_DM_API_REMOVE_ACL *p_msg; 1798 1799 APPL_TRACE_API0("BTA_DmCloseACL"); 1800 1801 if ((p_msg = (tBTA_DM_API_REMOVE_ACL *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_ACL))) != NULL) 1802 { 1803 memset(p_msg, 0, sizeof(tBTA_DM_API_REMOVE_ACL)); 1804 1805 p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT; 1806 1807 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN); 1808 p_msg->remove_dev = remove_dev; 1809 1810 bta_sys_sendmsg(p_msg); 1811 } 1812 } 1813 1814 /******************************************************************************* 1815 ** 1816 ** Function BTA_DmBleObserve 1817 ** 1818 ** Description This procedure keep the device listening for advertising 1819 ** events from a broadcast device. 1820 ** 1821 ** Parameters start: start or stop observe. 1822 ** 1823 ** Returns void 1824 1825 ** 1826 ** Returns void. 1827 ** 1828 *******************************************************************************/ 1829 BTA_API extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration, 1830 tBTA_DM_SEARCH_CBACK *p_results_cb) 1831 { 1832 #if BLE_INCLUDED == TRUE 1833 1834 tBTA_DM_API_BLE_OBSERVE *p_msg; 1835 1836 APPL_TRACE_API1("BTA_DmBleObserve:start = %d ", start); 1837 1838 if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) 1839 { 1840 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE)); 1841 1842 p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT; 1843 p_msg->start = start; 1844 p_msg->duration = duration; 1845 p_msg->p_cback = p_results_cb; 1846 1847 bta_sys_sendmsg(p_msg); 1848 } 1849 #endif 1850 } 1851 1852 1853