1 /******************************************************************************
3 * Copyright (C) 2003-2014 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This is the API implementation file for the BTA device manager.
23 ******************************************************************************/
25 #include "bta/bta_sys.h"
26 #include "bta/bta_api.h"
27 #include "bta_dm_int.h"
28 #include "bta_sys_int.h"
29 #include "stack/btm_api.h"
33 #include "osi/allocator.h"
35 /*****************************************************************************
37 *****************************************************************************/
39 static const tBTA_SYS_REG bta_dm_reg = {
44 static const tBTA_SYS_REG bta_dm_search_reg = {
45 bta_dm_search_sm_execute,
46 bta_dm_search_sm_disable
49 /*******************************************************************************
51 ** Function BTA_EnableBluetooth
53 ** Description Enables bluetooth service. This function must be
54 ** called before any other functions in the BTA API are called.
57 ** Returns tBTA_STATUS
59 *******************************************************************************/
60 tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
63 tBTA_DM_API_ENABLE *p_msg;
65 /* Bluetooth disabling is in progress */
66 if (bta_dm_cb.disabling) {
70 memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
72 bta_sys_register (BTA_ID_DM, &bta_dm_reg );
73 bta_sys_register (BTA_ID_DM_SEARCH, &bta_dm_search_reg );
75 /* if UUID list is not provided as static data */
76 bta_sys_eir_register(bta_dm_eir_update_uuid);
78 if ((p_msg = (tBTA_DM_API_ENABLE *) osi_malloc(sizeof(tBTA_DM_API_ENABLE))) != NULL) {
79 p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
80 p_msg->p_sec_cback = p_cback;
81 bta_sys_sendmsg(p_msg);
88 /*******************************************************************************
90 ** Function BTA_DisableBluetooth
92 ** Description Disables bluetooth service. This function is called when
93 ** the application no longer needs bluetooth service
97 *******************************************************************************/
98 tBTA_STATUS BTA_DisableBluetooth(void)
103 if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
104 p_msg->event = BTA_DM_API_DISABLE_EVT;
105 bta_sys_sendmsg(p_msg);
113 /*******************************************************************************
115 ** Function BTA_EnableTestMode
117 ** Description Enables bluetooth device under test mode
120 ** Returns tBTA_STATUS
122 *******************************************************************************/
123 tBTA_STATUS BTA_EnableTestMode(void)
127 APPL_TRACE_API("BTA_EnableTestMode");
129 if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
130 p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
131 bta_sys_sendmsg(p_msg);
137 /*******************************************************************************
139 ** Function BTA_DisableTestMode
141 ** Description Disable bluetooth device under test mode
146 *******************************************************************************/
147 void BTA_DisableTestMode(void)
151 APPL_TRACE_API("BTA_DisableTestMode");
153 if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
154 p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
155 bta_sys_sendmsg(p_msg);
159 /*******************************************************************************
161 ** Function BTA_DmSetDeviceName
163 ** Description This function sets the Bluetooth name of local device
168 *******************************************************************************/
169 void BTA_DmSetDeviceName(const char *p_name)
172 tBTA_DM_API_SET_NAME *p_msg;
174 if ((p_msg = (tBTA_DM_API_SET_NAME *) osi_malloc(sizeof(tBTA_DM_API_SET_NAME))) != NULL) {
175 p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
176 /* truncate the name if needed */
177 BCM_STRNCPY_S((char *)p_msg->name, sizeof(p_msg->name), p_name, BD_NAME_LEN - 1);
178 p_msg->name[BD_NAME_LEN - 1] = 0;
180 bta_sys_sendmsg(p_msg);
186 void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBTA_ADD_WHITELIST_CBACK *add_wl_cb)
188 tBTA_DM_API_UPDATE_WHITE_LIST *p_msg;
189 if ((p_msg = (tBTA_DM_API_UPDATE_WHITE_LIST *)osi_malloc(sizeof(tBTA_DM_API_UPDATE_WHITE_LIST))) != NULL) {
190 p_msg->hdr.event = BTA_DM_API_UPDATE_WHITE_LIST_EVT;
191 p_msg->add_remove = add_remove;
192 p_msg->add_wl_cb = add_wl_cb;
193 memcpy(p_msg->remote_addr, remote_addr, sizeof(BD_ADDR));
195 bta_sys_sendmsg(p_msg);
199 void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb)
201 tBTA_DM_API_READ_ADV_TX_POWER *p_msg;
202 if ((p_msg = (tBTA_DM_API_READ_ADV_TX_POWER *)osi_malloc(sizeof(tBTA_DM_API_READ_ADV_TX_POWER))) != NULL) {
203 p_msg->hdr.event = BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT;
204 p_msg->read_tx_power_cb = cmpl_cb;
205 bta_sys_sendmsg(p_msg);
209 void BTA_DmBleReadRSSI(BD_ADDR remote_addr, tBTA_TRANSPORT transport, tBTA_CMPL_CB *cmpl_cb)
211 tBTA_DM_API_READ_RSSI *p_msg;
212 if ((p_msg = (tBTA_DM_API_READ_RSSI *)osi_malloc(sizeof(tBTA_DM_API_READ_RSSI))) != NULL) {
213 p_msg->hdr.event = BTA_DM_API_BLE_READ_RSSI_EVT;
214 memcpy(p_msg->remote_addr, remote_addr, sizeof(BD_ADDR));
215 p_msg->transport = transport;
216 p_msg->read_rssi_cb = cmpl_cb;
217 bta_sys_sendmsg(p_msg);
221 /*******************************************************************************
223 ** Function BTA_DmSetVisibility
225 ** Description This function sets the Bluetooth connectable,
226 ** discoverable, pairable and conn paired only modes of local device
231 *******************************************************************************/
232 void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 pairable_mode, UINT8 conn_filter )
235 tBTA_DM_API_SET_VISIBILITY *p_msg;
237 if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) osi_malloc(sizeof(tBTA_DM_API_SET_VISIBILITY))) != NULL) {
238 p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
239 p_msg->disc_mode = disc_mode;
240 p_msg->conn_mode = conn_mode;
241 p_msg->pair_mode = pairable_mode;
242 p_msg->conn_paired_only = conn_filter;
245 bta_sys_sendmsg(p_msg);
251 /*******************************************************************************
253 ** Function BTA_DmSearch
255 ** Description This function searches for peer Bluetooth devices. It performs
256 ** an inquiry and gets the remote name for devices. Service
257 ** discovery is done if services is non zero
262 *******************************************************************************/
263 void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback)
266 tBTA_DM_API_SEARCH *p_msg;
268 if ((p_msg = (tBTA_DM_API_SEARCH *) osi_malloc(sizeof(tBTA_DM_API_SEARCH))) != NULL) {
269 memset(p_msg, 0, sizeof(tBTA_DM_API_SEARCH));
271 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
272 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
273 p_msg->services = services;
274 p_msg->p_cback = p_cback;
275 p_msg->rs_res = BTA_DM_RS_NONE;
276 bta_sys_sendmsg(p_msg);
282 /*******************************************************************************
284 ** Function BTA_DmSearchCancel
286 ** Description This function cancels a search initiated by BTA_DmSearch
291 *******************************************************************************/
292 void BTA_DmSearchCancel(void)
296 if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
297 p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
298 bta_sys_sendmsg(p_msg);
303 /*******************************************************************************
305 ** Function BTA_DmDiscover
307 ** Description This function does service discovery for services of a
313 *******************************************************************************/
314 #if (SDP_INCLUDED == TRUE)
315 void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
316 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
318 tBTA_DM_API_DISCOVER *p_msg;
320 if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
321 memset(p_msg, 0, sizeof(tBTA_DM_API_DISCOVER));
323 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
324 bdcpy(p_msg->bd_addr, bd_addr);
325 p_msg->services = services;
326 p_msg->p_cback = p_cback;
327 p_msg->sdp_search = sdp_search;
328 bta_sys_sendmsg(p_msg);
332 /*******************************************************************************
334 ** Function BTA_DmDiscoverUUID
336 ** Description This function does service discovery for services of a
342 *******************************************************************************/
343 void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
344 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
346 tBTA_DM_API_DISCOVER *p_msg;
348 if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
349 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
350 bdcpy(p_msg->bd_addr, bd_addr);
351 p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level
352 p_msg->p_cback = p_cback;
353 p_msg->sdp_search = sdp_search;
355 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
357 p_msg->p_uuid = NULL;
359 memcpy( &p_msg->uuid, uuid, sizeof(tSDP_UUID) );
360 bta_sys_sendmsg(p_msg);
363 #endif ///SDP_INCLUDED == TRUE
365 /*******************************************************************************
367 ** Function BTA_DmBond
369 ** Description This function initiates a bonding procedure with a peer
375 *******************************************************************************/
376 #if (SMP_INCLUDED == TRUE)
377 void BTA_DmBond(BD_ADDR bd_addr)
379 tBTA_DM_API_BOND *p_msg;
381 p_msg = (tBTA_DM_API_BOND *) osi_malloc(sizeof(tBTA_DM_API_BOND));
383 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
384 bdcpy(p_msg->bd_addr, bd_addr);
385 p_msg->transport = BTA_TRANSPORT_UNKNOWN;
386 bta_sys_sendmsg(p_msg);
390 /*******************************************************************************
392 ** Function BTA_DmBondByTransports
394 ** Description This function initiates a bonding procedure with a peer
400 *******************************************************************************/
401 void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport)
403 tBTA_DM_API_BOND *p_msg;
405 if ((p_msg = (tBTA_DM_API_BOND *) osi_malloc(sizeof(tBTA_DM_API_BOND))) != NULL) {
406 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
407 bdcpy(p_msg->bd_addr, bd_addr);
408 p_msg->transport = transport;
409 bta_sys_sendmsg(p_msg);
415 /*******************************************************************************
417 ** Function BTA_DmBondCancel
419 ** Description This function cancels the bonding procedure with a peer
425 *******************************************************************************/
426 void BTA_DmBondCancel(BD_ADDR bd_addr)
428 tBTA_DM_API_BOND_CANCEL *p_msg;
430 if ((p_msg = (tBTA_DM_API_BOND_CANCEL *) osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL))) != NULL) {
431 p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
432 bdcpy(p_msg->bd_addr, bd_addr);
433 bta_sys_sendmsg(p_msg);
439 /*******************************************************************************
441 ** Function BTA_DMSetPinType
443 ** Description This function set pin type as BTM_PIN_TYPE_FIXED or BTM_PIN_TYPE_VARIABLE
448 *******************************************************************************/
449 void BTA_DMSetPinType (UINT8 pin_type, UINT8 *pin_code, UINT8 pin_code_len)
451 tBTA_DM_API_SET_PIN_TYPE *p_msg;
453 if ((p_msg = (tBTA_DM_API_SET_PIN_TYPE *) osi_malloc(sizeof(tBTA_DM_API_SET_PIN_TYPE))) != NULL) {
454 p_msg->hdr.event = BTA_DM_API_SET_PIN_TYPE_EVT;
455 p_msg->pin_type = pin_type;
456 p_msg->pin_len = pin_code_len;
457 memcpy(p_msg->p_pin, pin_code, pin_code_len);
458 bta_sys_sendmsg(p_msg);
462 /*******************************************************************************
464 ** Function BTA_DmPinReply
466 ** Description This function provides a pincode for a remote device when
467 ** one is requested by DM through BTA_DM_PIN_REQ_EVT
472 *******************************************************************************/
473 void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin)
475 tBTA_DM_API_PIN_REPLY *p_msg;
477 if ((p_msg = (tBTA_DM_API_PIN_REPLY *) osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY))) != NULL) {
478 p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
479 bdcpy(p_msg->bd_addr, bd_addr);
480 p_msg->accept = accept;
482 p_msg->pin_len = pin_len;
483 memcpy(p_msg->p_pin, p_pin, pin_len);
485 bta_sys_sendmsg(p_msg);
490 #if (BTM_OOB_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
491 /*******************************************************************************
493 ** Function BTA_DmLocalOob
495 ** Description This function retrieves the OOB data from local controller.
496 ** The result is reported by:
497 ** - bta_dm_co_loc_oob_ext() if device supports secure
499 ** - bta_dm_co_loc_oob() if device doesn't support SC
503 *******************************************************************************/
504 void BTA_DmLocalOob(void)
506 tBTA_DM_API_LOC_OOB *p_msg;
508 if ((p_msg = (tBTA_DM_API_LOC_OOB *) osi_malloc(sizeof(tBTA_DM_API_LOC_OOB))) != NULL) {
509 p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
510 bta_sys_sendmsg(p_msg);
514 /*******************************************************************************
516 ** Function BTA_DmOobReply
518 ** This function is called to provide the OOB data for
519 ** SMP in response to BTM_LE_OOB_REQ_EVT
521 ** Parameters: bd_addr - Address of the peer device
522 ** len - length of simple pairing Randomizer C
523 ** p_value - simple pairing Randomizer C.
527 *******************************************************************************/
528 void BTA_DmOobReply(BD_ADDR bd_addr, UINT8 len, UINT8 *p_value)
530 tBTA_DM_API_OOB_REPLY *p_msg;
532 if ((p_msg = (tBTA_DM_API_OOB_REPLY *) osi_malloc(sizeof(tBTA_DM_API_OOB_REPLY))) != NULL) {
533 p_msg->hdr.event = BTA_DM_API_OOB_REPLY_EVT;
534 if(p_value == NULL || len > BT_OCTET16_LEN) {
537 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
539 memcpy(p_msg->value, p_value, len);
540 bta_sys_sendmsg(p_msg);
543 #endif /* BTM_OOB_INCLUDED */
544 /*******************************************************************************
546 ** Function BTA_DmConfirm
548 ** Description This function accepts or rejects the numerical value of the
549 ** Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
553 *******************************************************************************/
554 void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept)
556 tBTA_DM_API_CONFIRM *p_msg;
558 if ((p_msg = (tBTA_DM_API_CONFIRM *) osi_malloc(sizeof(tBTA_DM_API_CONFIRM))) != NULL) {
559 p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
560 bdcpy(p_msg->bd_addr, bd_addr);
561 p_msg->accept = accept;
562 bta_sys_sendmsg(p_msg);
566 /*******************************************************************************
568 ** Function BTA_DmPasskeyReqReply
570 ** Description This function is called to provide the passkey for
571 ** Simple Pairing in response to BTA_DM_SP_KEY_REQ_EVT
575 *******************************************************************************/
576 #if (BT_SSP_INCLUDED == TRUE)
577 void BTA_DmPasskeyReqReply(BOOLEAN accept, BD_ADDR bd_addr, UINT32 passkey)
579 tBTA_DM_API_KEY_REQ *p_msg;
580 if ((p_msg = (tBTA_DM_API_KEY_REQ *) osi_malloc(sizeof(tBTA_DM_API_KEY_REQ))) != NULL) {
581 p_msg->hdr.event = BTA_DM_API_KEY_REQ_EVT;
582 bdcpy(p_msg->bd_addr, bd_addr);
583 p_msg->accept = accept;
584 p_msg->passkey = passkey;
585 bta_sys_sendmsg(p_msg);
588 #endif ///BT_SSP_INCLUDED == TRUE
589 /*******************************************************************************
591 ** Function BTA_DmAddDevice
593 ** Description This function adds a device to the security database list of
599 *******************************************************************************/
600 void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
601 tBTA_SERVICE_MASK trusted_mask, BOOLEAN is_trusted,
602 UINT8 key_type, tBTA_IO_CAP io_cap, UINT8 pin_length)
605 tBTA_DM_API_ADD_DEVICE *p_msg;
607 if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL) {
608 memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE));
610 p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
611 bdcpy(p_msg->bd_addr, bd_addr);
612 p_msg->tm = trusted_mask;
613 p_msg->is_trusted = is_trusted;
614 p_msg->io_cap = io_cap;
617 p_msg->link_key_known = TRUE;
618 p_msg->key_type = key_type;
619 memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
622 /* Load device class if specified */
624 p_msg->dc_known = TRUE;
625 memcpy (p_msg->dc, dev_class, DEV_CLASS_LEN);
628 memset (p_msg->bd_name, 0, BD_NAME_LEN + 1);
629 memset (p_msg->features, 0, sizeof (p_msg->features));
630 p_msg->pin_length = pin_length;
632 bta_sys_sendmsg(p_msg);
637 /*******************************************************************************
639 ** Function BTA_DmRemoveDevice
641 ** Description This function removes a device fromthe security database list of
642 ** peer device. It manages unpairing even while connected.
647 *******************************************************************************/
648 tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr, tBT_TRANSPORT transport)
650 tBTA_DM_API_REMOVE_DEVICE *p_msg;
652 if ((p_msg = (tBTA_DM_API_REMOVE_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_REMOVE_DEVICE))) != NULL) {
653 memset (p_msg, 0, sizeof(tBTA_DM_API_REMOVE_DEVICE));
655 p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
656 bdcpy(p_msg->bd_addr, bd_addr);
657 p_msg->transport = transport;
658 bta_sys_sendmsg(p_msg);
665 #endif ///SMP_INCLUDED == TRUE
667 /*******************************************************************************
669 ** Function BTA_GetEirService
671 ** Description This function is called to get BTA service mask from EIR.
673 ** Parameters p_eir - pointer of EIR significant part
674 ** p_services - return the BTA service mask
678 *******************************************************************************/
679 extern const UINT16 bta_service_id_to_uuid_lkup_tbl [];
680 void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services )
683 UINT8 num_uuid, max_num_uuid = 32;
684 UINT8 uuid_list[32 * LEN_UUID_16];
685 UINT16 *p_uuid16 = (UINT16 *)uuid_list;
686 tBTA_SERVICE_MASK mask;
688 BTM_GetEirUuidList( p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid);
689 for ( xx = 0; xx < num_uuid; xx++ ) {
691 for ( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ ) {
692 if ( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] ) {
699 /* for HSP v1.2 only device */
700 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS) {
701 *p_services |= BTA_HSP_SERVICE_MASK;
704 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE) {
705 *p_services |= BTA_HL_SERVICE_MASK;
708 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK) {
709 *p_services |= BTA_HL_SERVICE_MASK;
714 /*******************************************************************************
716 ** Function BTA_DmGetConnectionState
718 ** Description Returns whether the remote device is currently connected.
720 ** Returns 0 if the device is NOT connected.
722 *******************************************************************************/
723 UINT16 BTA_DmGetConnectionState( BD_ADDR bd_addr )
725 tBTA_DM_PEER_DEVICE *p_dev = bta_dm_find_peer_device(bd_addr);
726 return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
729 #if (SDP_INCLUDED == TRUE)
730 /*******************************************************************************
731 ** Device Identification (DI) Server Functions
732 *******************************************************************************/
733 /*******************************************************************************
735 ** Function BTA_DmSetLocalDiRecord
737 ** Description This function adds a DI record to the local SDP database.
739 ** Returns BTA_SUCCESS if record set sucessfully, otherwise error code.
741 *******************************************************************************/
742 tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
745 tBTA_STATUS status = BTA_FAILURE;
747 if (bta_dm_di_cb.di_num < BTA_DI_NUM_MAX) {
748 if (SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS) {
749 if (!p_device_info->primary_record) {
750 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
751 bta_dm_di_cb.di_num ++;
754 bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
755 status = BTA_SUCCESS;
761 #endif ///SDP_INCLUDED == TRUE
762 /*******************************************************************************
764 ** Function bta_dmexecutecallback
766 ** Description This function will request BTA to execute a call back in the context of BTU task
767 ** This API was named in lower case because it is only intended
768 ** for the internal customers(like BTIF).
772 *******************************************************************************/
773 void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK *p_callback, void *p_param)
775 tBTA_DM_API_EXECUTE_CBACK *p_msg;
777 if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) osi_malloc(sizeof(tBTA_DM_API_EXECUTE_CBACK))) != NULL) {
778 p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
779 p_msg->p_param = p_param;
780 p_msg->p_exec_cback = p_callback;
781 bta_sys_sendmsg(p_msg);
785 /*******************************************************************************
787 ** Function BTA_DmAddBleKey
789 ** Description Add/modify LE device information. This function will be
790 ** normally called during host startup to restore all required
791 ** information stored in the NVRAM.
793 ** Parameters: bd_addr - BD address of the peer
794 ** p_le_key - LE key values.
795 ** key_type - LE SMP key type.
797 ** Returns BTA_SUCCESS if successful
798 ** BTA_FAIL if operation failed.
800 *******************************************************************************/
801 #if BLE_INCLUDED == TRUE
802 #if SMP_INCLUDED == TRUE
803 void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_TYPE key_type)
805 tBTA_DM_API_ADD_BLEKEY *p_msg;
807 if ((p_msg = (tBTA_DM_API_ADD_BLEKEY *) osi_malloc(sizeof(tBTA_DM_API_ADD_BLEKEY))) != NULL) {
808 memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLEKEY));
810 p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
811 p_msg->key_type = key_type;
812 bdcpy(p_msg->bd_addr, bd_addr);
813 memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE));
815 bta_sys_sendmsg(p_msg);
820 /*******************************************************************************
822 ** Function BTA_DmAddBleDevice
824 ** Description Add a BLE device. This function will be normally called
825 ** during host startup to restore all required information
826 ** for a LE device stored in the NVRAM.
828 ** Parameters: bd_addr - BD address of the peer
829 ** dev_type - Remote device's device type.
830 ** auth_mode - auth mode
831 ** addr_type - LE device address type.
835 *******************************************************************************/
836 void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, int auth_mode, tBT_DEVICE_TYPE dev_type)
838 tBTA_DM_API_ADD_BLE_DEVICE *p_msg;
840 if ((p_msg = (tBTA_DM_API_ADD_BLE_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_ADD_BLE_DEVICE))) != NULL) {
841 memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
843 p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
844 bdcpy(p_msg->bd_addr, bd_addr);
845 p_msg->addr_type = addr_type;
846 p_msg->auth_mode = auth_mode;
847 p_msg->dev_type = dev_type;
849 bta_sys_sendmsg(p_msg);
852 /*******************************************************************************
854 ** Function BTA_DmBlePasskeyReply
856 ** Description Send BLE SMP passkey reply.
858 ** Parameters: bd_addr - BD address of the peer
859 ** accept - passkey entry sucessful or declined.
860 ** passkey - passkey value, must be a 6 digit number,
865 *******************************************************************************/
866 void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey)
868 tBTA_DM_API_PASSKEY_REPLY *p_msg;
870 if ((p_msg = (tBTA_DM_API_PASSKEY_REPLY *) osi_malloc(sizeof(tBTA_DM_API_PASSKEY_REPLY))) != NULL) {
871 memset(p_msg, 0, sizeof(tBTA_DM_API_PASSKEY_REPLY));
873 p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
874 bdcpy(p_msg->bd_addr, bd_addr);
875 p_msg->accept = accept;
878 p_msg->passkey = passkey;
880 bta_sys_sendmsg(p_msg);
884 void BTA_DmBleSetStaticPasskey(bool add, uint32_t passkey)
886 tBTA_DM_API_SET_DEFAULT_PASSKEY *p_msg;
888 if ((p_msg = (tBTA_DM_API_SET_DEFAULT_PASSKEY *) osi_malloc(sizeof(tBTA_DM_API_SET_DEFAULT_PASSKEY))) != NULL) {
889 memset(p_msg, 0, sizeof(tBTA_DM_API_SET_DEFAULT_PASSKEY));
891 p_msg->hdr.event = BTA_DM_API_BLE_SET_STATIC_PASSKEY_EVT;
893 p_msg->static_passkey = passkey;
894 bta_sys_sendmsg(p_msg);
898 /*******************************************************************************
900 ** Function BTA_DmBleConfirmReply
902 ** Description Send BLE SMP SC user confirmation reply.
904 ** Parameters: bd_addr - BD address of the peer
905 ** accept - numbers to compare are the same or different.
909 *******************************************************************************/
910 void BTA_DmBleConfirmReply(BD_ADDR bd_addr, BOOLEAN accept)
912 tBTA_DM_API_CONFIRM *p_msg = (tBTA_DM_API_CONFIRM *)osi_malloc(sizeof(tBTA_DM_API_CONFIRM));
914 memset(p_msg, 0, sizeof(tBTA_DM_API_CONFIRM));
915 p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT;
916 bdcpy(p_msg->bd_addr, bd_addr);
917 p_msg->accept = accept;
918 bta_sys_sendmsg(p_msg);
922 /*******************************************************************************
924 ** Function BTA_DmBleSecurityGrant
926 ** Description Grant security request access.
928 ** Parameters: bd_addr - BD address of the peer
929 ** res - security grant status.
933 *******************************************************************************/
934 void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
936 tBTA_DM_API_BLE_SEC_GRANT *p_msg;
938 if ((p_msg = (tBTA_DM_API_BLE_SEC_GRANT *) osi_malloc(sizeof(tBTA_DM_API_BLE_SEC_GRANT))) != NULL) {
939 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SEC_GRANT));
941 p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
942 bdcpy(p_msg->bd_addr, bd_addr);
945 bta_sys_sendmsg(p_msg);
948 #endif ///SMP_INCLUDED == TRUE
949 #endif ///BLE_INCLUDED == TRUE
952 /*******************************************************************************
954 ** Function BTA_DmSetBlePrefConnParams
956 ** Description This function is called to set the preferred connection
957 ** parameters when default connection parameter is not desired.
959 ** Parameters: bd_addr - BD address of the peripheral
960 ** scan_interval - scan interval
961 ** scan_window - scan window
962 ** min_conn_int - minimum preferred connection interval
963 ** max_conn_int - maximum preferred connection interval
964 ** slave_latency - preferred slave latency
965 ** supervision_tout - preferred supervision timeout
970 *******************************************************************************/
971 void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,
972 UINT16 min_conn_int, UINT16 max_conn_int,
973 UINT16 slave_latency, UINT16 supervision_tout )
975 #if BLE_INCLUDED == TRUE
976 tBTA_DM_API_BLE_CONN_PARAMS *p_msg;
978 if ((p_msg = (tBTA_DM_API_BLE_CONN_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_BLE_CONN_PARAMS))) != NULL) {
979 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
981 p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
983 memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN);
985 p_msg->conn_int_max = max_conn_int;
986 p_msg->conn_int_min = min_conn_int;
987 p_msg->slave_latency = slave_latency;
988 p_msg->supervision_tout = supervision_tout;
990 bta_sys_sendmsg(p_msg);
995 /*******************************************************************************
997 ** Function BTA_DmSetBleConnScanParams
999 ** Description This function is called to set scan parameters used in
1000 ** BLE connection request
1002 ** Parameters: scan_interval - scan interval
1003 ** scan_window - scan window
1007 *******************************************************************************/
1008 void BTA_DmSetBleConnScanParams(UINT32 scan_interval, UINT32 scan_window)
1010 tBTA_DM_API_BLE_SCAN_PARAMS *p_msg;
1011 if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
1012 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
1013 p_msg->hdr.event = BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT;
1014 p_msg->scan_int = scan_interval;
1015 p_msg->scan_window = scan_window;
1016 bta_sys_sendmsg(p_msg);
1020 /*******************************************************************************
1022 ** Function BTA_DmSetBleScanParams
1024 ** Description This function is called to set scan parameters
1026 ** Parameters: client_if - Client IF
1027 ** scan_interval - scan interval
1028 ** scan_window - scan window
1029 ** scan_mode - scan mode
1030 ** scan_param_setup_status_cback - Set scan param status callback
1034 *******************************************************************************/
1035 void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval,
1036 UINT32 scan_window, tBLE_SCAN_MODE scan_mode,
1037 tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
1039 tBTA_DM_API_BLE_SCAN_PARAMS *p_msg;
1041 if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
1042 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
1043 p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT;
1044 p_msg->client_if = client_if;
1045 p_msg->scan_int = scan_interval;
1046 p_msg->scan_window = scan_window;
1047 p_msg->scan_mode = scan_mode;
1048 p_msg->scan_param_setup_cback = scan_param_setup_cback;
1050 bta_sys_sendmsg(p_msg);
1055 /*******************************************************************************
1057 ** Function BTA_DmSetBleScanFilterParams
1059 ** Description This function is called to set scan parameters
1061 ** Parameters: client_if - Client IF
1062 ** scan_interval - scan interval
1063 ** scan_window - scan window
1064 ** scan_mode - scan mode
1065 ** scan_duplicate_filter - scan duplicate filter
1066 ** scan_param_setup_status_cback - Set scan param status callback
1070 *******************************************************************************/
1071 void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval,
1072 UINT32 scan_window, tBLE_SCAN_MODE scan_mode, UINT8 scan_fil_poilcy,
1073 UINT8 addr_type_own, UINT8 scan_duplicate_filter, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
1075 tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *p_msg;
1077 if ((p_msg = (tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS))) != NULL) {
1078 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS));
1079 p_msg->hdr.event = BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT;
1080 p_msg->client_if = client_if;
1081 p_msg->scan_int = scan_interval;
1082 p_msg->scan_window = scan_window;
1083 p_msg->scan_mode = scan_mode;
1084 p_msg->addr_type_own = addr_type_own;
1085 p_msg->scan_duplicate_filter = scan_duplicate_filter;
1086 p_msg->scan_filter_policy = scan_fil_poilcy;
1087 p_msg->scan_param_setup_cback = scan_param_setup_cback;
1089 bta_sys_sendmsg(p_msg);
1095 /*******************************************************************************
1097 ** Function BTA_DmSetBleAdvParams
1099 ** Description This function sets the advertising parameters BLE functionality.
1100 ** It is to be called when device act in peripheral or broadcaster
1106 *******************************************************************************/
1107 void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
1108 tBLE_BD_ADDR *p_dir_bda)
1110 #if BLE_INCLUDED == TRUE
1111 tBTA_DM_API_BLE_ADV_PARAMS *p_msg;
1113 APPL_TRACE_API ("BTA_DmSetBleAdvParam: %d, %d\n", adv_int_min, adv_int_max);
1115 if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_BLE_ADV_PARAMS)
1116 + sizeof(tBLE_BD_ADDR))) != NULL) {
1117 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS) + sizeof(tBLE_BD_ADDR));
1119 p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_EVT;
1121 p_msg->adv_int_min = adv_int_min;
1122 p_msg->adv_int_max = adv_int_max;
1124 if (p_dir_bda != NULL) {
1125 p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
1126 memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
1129 bta_sys_sendmsg(p_msg);
1134 void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max,
1135 UINT8 adv_type, tBLE_ADDR_TYPE addr_type_own,
1136 tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP adv_fil_pol,
1137 tBLE_BD_ADDR *p_dir_bda, tBTA_START_ADV_CMPL_CBACK p_start_adv_cb)
1139 #if BLE_INCLUDED == TRUE
1140 tBTA_DM_API_BLE_ADV_PARAMS_ALL *p_msg;
1142 APPL_TRACE_API ("BTA_DmSetBleAdvParamsAll: %d, %d\n", adv_int_min, adv_int_max);
1143 APPL_TRACE_API ("adv_type = %d, addr_type_own = %d, chnl_map = %d, adv_fil_pol = %d\n",
1144 adv_type, addr_type_own, chnl_map, adv_fil_pol);
1145 if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS_ALL *) osi_malloc(sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL)
1146 + sizeof(tBLE_BD_ADDR))) != NULL) {
1147 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL));
1149 p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_All_EVT;
1151 p_msg->adv_int_min = adv_int_min;
1152 p_msg->adv_int_max = adv_int_max;
1153 p_msg->adv_type = adv_type;
1154 p_msg->addr_type_own = addr_type_own;
1155 p_msg->channel_map = chnl_map;
1156 p_msg->adv_filter_policy = adv_fil_pol;
1157 p_msg->p_start_adv_cback = p_start_adv_cb;
1158 if (p_dir_bda != NULL) {
1159 p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
1160 memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
1163 bta_sys_sendmsg(p_msg);
1170 /*******************************************************************************
1171 ** BLE ADV data management API
1172 ********************************************************************************/
1174 #if BLE_INCLUDED == TRUE
1175 /*******************************************************************************
1177 ** Function BTA_DmBleSetAdvConfig
1179 ** Description This function is called to override the BTA default ADV parameters.
1181 ** Parameters data_mask: adv data mask.
1182 ** p_adv_cfg: Pointer to User defined ADV data structure. This
1183 ** memory space can not be freed until p_adv_data_cback
1185 ** p_adv_data_cback: set adv data complete callback.
1189 *******************************************************************************/
1190 void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
1191 tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
1193 tBTA_DM_API_SET_ADV_CONFIG *p_msg;
1195 if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
1196 osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
1197 p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_EVT;
1198 p_msg->data_mask = data_mask;
1199 p_msg->p_adv_data_cback = p_adv_data_cback;
1200 p_msg->p_adv_cfg = p_adv_cfg;
1202 bta_sys_sendmsg(p_msg);
1206 /*******************************************************************************
1208 ** Function BTA_DmBleSetAdvConfigRaw
1210 ** Description This function is called to set raw Advertising data
1212 ** Parameters p_raw_adv : raw advertising data.
1213 ** raw_adv_len : raw advertising data length.
1214 ** p_adv_data_cback : set adv data complete callback.
1218 *******************************************************************************/
1219 void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len,
1220 tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
1222 tBTA_DM_API_SET_ADV_CONFIG_RAW *p_msg;
1224 if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
1225 osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW) + raw_adv_len)) != NULL) {
1226 p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT;
1227 p_msg->p_adv_data_cback = p_adv_data_cback;
1228 p_msg->p_raw_adv = (UINT8 *)(p_msg + 1);
1229 memcpy(p_msg->p_raw_adv, p_raw_adv, raw_adv_len);
1230 p_msg->raw_adv_len = raw_adv_len;
1232 bta_sys_sendmsg(p_msg);
1236 /*******************************************************************************
1238 ** Function BTA_DmBleSetLongAdv
1240 ** Description This function is called to set long Advertising data
1242 ** Parameters adv_data : long advertising data.
1243 ** adv_data_len : long advertising data length.
1244 ** p_adv_data_cback : set long adv data complete callback.
1248 *******************************************************************************/
1249 void BTA_DmBleSetLongAdv (UINT8 *adv_data, UINT32 adv_data_len,
1250 tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
1252 tBTA_DM_API_SET_LONG_ADV *p_msg;
1254 if ((p_msg = (tBTA_DM_API_SET_LONG_ADV *)
1255 osi_malloc(sizeof(tBTA_DM_API_SET_LONG_ADV))) != NULL) {
1256 p_msg->hdr.event = BTA_DM_API_BLE_SET_LONG_ADV_EVT;
1257 p_msg->p_adv_data_cback = p_adv_data_cback;
1258 p_msg->adv_data = adv_data;
1259 p_msg->adv_data_len = adv_data_len;
1261 bta_sys_sendmsg(p_msg);
1265 /*******************************************************************************
1267 ** Function BTA_DmBleSetScanRsp
1269 ** Description This function is called to override the BTA scan response.
1271 ** Parameters Pointer to User defined ADV data structure
1275 *******************************************************************************/
1276 extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
1277 tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
1279 tBTA_DM_API_SET_ADV_CONFIG *p_msg;
1281 if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
1282 osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
1283 p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_EVT;
1284 p_msg->data_mask = data_mask;
1285 p_msg->p_adv_data_cback = p_adv_data_cback;
1286 p_msg->p_adv_cfg = p_adv_cfg;
1288 bta_sys_sendmsg(p_msg);
1292 /*******************************************************************************
1294 ** Function BTA_DmBleSetScanRspRaw
1296 ** Description This function is called to set raw scan response data
1298 ** Parameters p_raw_scan_rsp : raw scan_rspertising data.
1299 ** raw_scan_rsp_len : raw scan_rspertising data length.
1300 ** p_scan_rsp_data_cback : set scan_rsp data complete callback.
1304 *******************************************************************************/
1305 void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len,
1306 tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback)
1308 tBTA_DM_API_SET_ADV_CONFIG_RAW *p_msg;
1310 if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
1311 osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW) + raw_scan_rsp_len)) != NULL) {
1312 p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_RAW_EVT;
1313 p_msg->p_adv_data_cback = p_scan_rsp_data_cback;
1314 p_msg->p_raw_adv = (UINT8 *)(p_msg + 1);
1315 memcpy(p_msg->p_raw_adv, p_raw_scan_rsp, raw_scan_rsp_len);
1316 p_msg->raw_adv_len = raw_scan_rsp_len;
1318 bta_sys_sendmsg(p_msg);
1322 /*******************************************************************************
1324 ** Function BTA_DmUpdateDuplicateExceptionalList
1326 ** Description This function is called to update duplicate scan exceptional list
1328 ** Parameters subcode : add, remove or clean duplicate scan exceptional list.
1329 ** type : device info type.
1330 ** device_info: device info
1331 ** p_update_duplicate_ignore_list_cback : update complete callback.
1335 *******************************************************************************/
1336 void BTA_DmUpdateDuplicateExceptionalList(UINT8 subcode, UINT32 type, BD_ADDR device_info, tBTA_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK p_update_duplicate_exceptional_list_cback)
1338 tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST *p_msg;
1339 if ((p_msg = (tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST *)osi_malloc(sizeof(tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST))) != NULL) {
1340 p_msg->hdr.event = BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT;
1341 p_msg->subcode = subcode;
1343 p_msg->exceptional_list_cb = p_update_duplicate_exceptional_list_cback;
1344 memcpy(p_msg->device_info, device_info, sizeof(BD_ADDR));
1346 bta_sys_sendmsg(p_msg);
1350 /*******************************************************************************
1352 ** Function BTA_DmBleSetStorageParams
1354 ** Description This function is called to override the BTA scan response.
1356 ** Parameters batch_scan_full_max -Max storage space (in %) allocated to full scanning
1357 ** batch_scan_trunc_max -Max storage space (in %) allocated to truncated scanning
1358 ** batch_scan_notify_threshold -Setup notification level based on total space
1359 ** p_setup_cback - Setup callback pointer
1360 ** p_thres_cback - Threshold callback pointer
1361 ** p_rep_cback - Reports callback pointer
1362 ** ref_value - Ref value
1366 *******************************************************************************/
1367 extern void BTA_DmBleSetStorageParams(UINT8 batch_scan_full_max,
1368 UINT8 batch_scan_trunc_max,
1369 UINT8 batch_scan_notify_threshold,
1370 tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback,
1371 tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback,
1372 tBTA_BLE_SCAN_REP_CBACK *p_rep_cback,
1373 tBTA_DM_BLE_REF_VALUE ref_value)
1375 tBTA_DM_API_SET_STORAGE_CONFIG *p_msg;
1376 bta_dm_cb.p_setup_cback = p_setup_cback;
1377 if ((p_msg = (tBTA_DM_API_SET_STORAGE_CONFIG *)
1378 osi_malloc(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG))) != NULL) {
1379 p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT;
1380 p_msg->p_setup_cback = bta_ble_scan_setup_cb;
1381 p_msg->p_thres_cback = p_thres_cback;
1382 p_msg->p_read_rep_cback = p_rep_cback;
1383 p_msg->ref_value = ref_value;
1384 p_msg->batch_scan_full_max = batch_scan_full_max;
1385 p_msg->batch_scan_trunc_max = batch_scan_trunc_max;
1386 p_msg->batch_scan_notify_threshold = batch_scan_notify_threshold;
1387 bta_sys_sendmsg(p_msg);
1391 /*******************************************************************************
1393 ** Function BTA_DmBleEnableBatchScan
1395 ** Description This function is called to enable the batch scan
1397 ** Parameters scan_mode -Batch scan mode
1398 ** scan_interval - Scan interval
1399 ** scan_window - Scan window
1400 ** discard_rule -Discard rules
1401 ** addr_type - Address type
1402 ** ref_value - Reference value
1406 *******************************************************************************/
1407 extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode,
1408 UINT32 scan_interval, UINT32 scan_window,
1409 tBTA_BLE_DISCARD_RULE discard_rule,
1410 tBLE_ADDR_TYPE addr_type,
1411 tBTA_DM_BLE_REF_VALUE ref_value)
1413 tBTA_DM_API_ENABLE_SCAN *p_msg;
1415 if ((p_msg = (tBTA_DM_API_ENABLE_SCAN *) osi_malloc(sizeof(tBTA_DM_API_ENABLE_SCAN))) != NULL) {
1416 p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT;
1417 p_msg->scan_mode = scan_mode;
1418 p_msg->scan_int = scan_interval;
1419 p_msg->scan_window = scan_window;
1420 p_msg->discard_rule = discard_rule;
1421 p_msg->addr_type = addr_type;
1422 p_msg->ref_value = ref_value;
1423 bta_sys_sendmsg(p_msg);
1427 /*******************************************************************************
1429 ** Function BTA_DmBleDisableBatchScan
1431 ** Description This function is called to disable the batch scan
1433 ** Parameters ref_value - Reference value
1437 *******************************************************************************/
1438 extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)
1440 tBTA_DM_API_DISABLE_SCAN *p_msg;
1442 if ((p_msg = (tBTA_DM_API_DISABLE_SCAN *)
1443 osi_malloc(sizeof(tBTA_DM_API_DISABLE_SCAN))) != NULL) {
1444 p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT;
1445 p_msg->ref_value = ref_value;
1446 bta_sys_sendmsg(p_msg);
1450 /*******************************************************************************
1452 ** Function BTA_DmBleReadScanReports
1454 ** Description This function is called to read scan reports
1456 ** Parameters scan_type -Batch scan mode
1457 ** ref_value - Reference value
1461 *******************************************************************************/
1462 extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type,
1463 tBTA_DM_BLE_REF_VALUE ref_value)
1465 tBTA_DM_API_READ_SCAN_REPORTS *p_msg;
1467 if ((p_msg = (tBTA_DM_API_READ_SCAN_REPORTS *)
1468 osi_malloc(sizeof(tBTA_DM_API_READ_SCAN_REPORTS))) != NULL) {
1469 p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT;
1470 p_msg->scan_type = scan_type;
1471 p_msg->ref_value = ref_value;
1472 bta_sys_sendmsg(p_msg);
1476 /*******************************************************************************
1478 ** Function BTA_DmBleTrackAdvertiser
1480 ** Description This function is called to track advertiser
1482 ** Parameters ref_value - Reference value
1483 ** p_track_adv_cback - Track ADV callback
1487 *******************************************************************************/
1488 extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
1489 tBTA_BLE_TRACK_ADV_CBACK *p_track_adv_cback)
1491 tBTA_DM_API_TRACK_ADVERTISER *p_msg;
1493 if ((p_msg = (tBTA_DM_API_TRACK_ADVERTISER *)
1494 osi_malloc(sizeof(tBTA_DM_API_TRACK_ADVERTISER))) != NULL) {
1495 p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT;
1496 p_msg->p_track_adv_cback = p_track_adv_cback;
1497 p_msg->ref_value = ref_value;
1498 bta_sys_sendmsg(p_msg);
1504 /*******************************************************************************
1505 ** BLE ADV data management API
1506 ********************************************************************************/
1507 #if BLE_INCLUDED == TRUE
1509 /*******************************************************************************
1511 ** Function BTA_DmBleBroadcast
1513 ** Description This function starts or stops LE broadcasting.
1515 ** Parameters start: start or stop broadcast.
1519 *******************************************************************************/
1520 extern void BTA_DmBleBroadcast (BOOLEAN start, tBTA_START_STOP_ADV_CMPL_CBACK *p_start_stop_adv_cb)
1522 tBTA_DM_API_BLE_OBSERVE *p_msg;
1524 APPL_TRACE_API("BTA_DmBleBroadcast: start = %d \n", start);
1526 if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) osi_malloc(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
1527 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
1529 p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
1530 p_msg->start = start;
1531 if (start == FALSE){
1532 p_msg->p_stop_adv_cback= p_start_stop_adv_cb;
1535 bta_sys_sendmsg(p_msg);
1540 /*******************************************************************************
1542 ** Function BTA_DmBleSetBgConnType
1544 ** Description This function is called to set BLE connectable mode for a
1545 ** peripheral device.
1547 ** Parameters bg_conn_type: it can be auto connection, or selective connection.
1548 ** p_select_cback: callback function when selective connection procedure
1553 *******************************************************************************/
1554 void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback)
1556 #if BLE_INCLUDED == TRUE
1557 tBTA_DM_API_BLE_SET_BG_CONN_TYPE *p_msg;
1559 if ((p_msg = (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *) osi_malloc(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE))) != NULL) {
1560 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
1562 p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
1563 p_msg->bg_conn_type = bg_conn_type;
1564 p_msg->p_select_cback = p_select_cback;
1566 bta_sys_sendmsg(p_msg);
1571 /*******************************************************************************
1573 ** Function bta_dm_discover_send_msg
1575 ** Description This function send discover message to BTA task.
1579 *******************************************************************************/
1580 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE && SDP_INCLUDED == TRUE
1581 static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1582 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
1583 tBTA_TRANSPORT transport)
1585 tBTA_DM_API_DISCOVER *p_msg;
1586 UINT16 len = p_services ? (sizeof(tBTA_DM_API_DISCOVER) +
1587 sizeof(tBT_UUID) * p_services->num_uuid) :
1588 sizeof(tBTA_DM_API_DISCOVER);
1590 if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(len)) != NULL) {
1591 memset(p_msg, 0, len);
1593 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
1594 bdcpy(p_msg->bd_addr, bd_addr);
1595 p_msg->p_cback = p_cback;
1596 p_msg->sdp_search = sdp_search;
1597 p_msg->transport = transport;
1599 if (p_services != NULL) {
1600 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1601 p_msg->services = p_services->srvc_mask;
1602 p_msg->num_uuid = p_services->num_uuid;
1603 if (p_services->num_uuid != 0) {
1604 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1605 memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
1610 bta_sys_sendmsg(p_msg);
1614 /*******************************************************************************
1616 ** Function BTA_DmDiscoverByTransport
1618 ** Description This function does service discovery on particular transport
1619 ** for services of a
1620 ** peer device. When services.num_uuid is 0, it indicates all
1621 ** GATT based services are to be searched; otherwise a list of
1622 ** UUID of interested services should be provided through
1623 ** p_services->p_uuid.
1629 *******************************************************************************/
1630 void BTA_DmDiscoverByTransport(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1631 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
1632 tBTA_TRANSPORT transport)
1634 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE && SDP_INCLUDED == TRUE
1635 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
1640 /*******************************************************************************
1642 ** Function BTA_DmDiscoverExt
1644 ** Description This function does service discovery for services of a
1645 ** peer device. When services.num_uuid is 0, it indicates all
1646 ** GATT based services are to be searched; other wise a list of
1647 ** UUID of interested services should be provided through
1648 ** p_services->p_uuid.
1654 *******************************************************************************/
1655 void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1656 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
1658 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE && SDP_INCLUDED == TRUE
1659 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, BTA_TRANSPORT_UNKNOWN);
1664 /*******************************************************************************
1666 ** Function BTA_DmSearchExt
1668 ** Description This function searches for peer Bluetooth devices. It performs
1669 ** an inquiry and gets the remote name for devices. Service
1670 ** discovery is done if services is non zero
1672 ** Parameters p_dm_inq: inquiry conditions
1673 ** p_services: if service is not empty, service discovery will be done.
1674 ** for all GATT based service condition, put num_uuid, and
1675 ** p_uuid is the pointer to the list of UUID values.
1676 ** p_cback: callback functino when search is completed.
1682 *******************************************************************************/
1683 void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback)
1685 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1686 tBTA_DM_API_SEARCH *p_msg;
1687 UINT16 len = p_services ? (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid) :
1688 sizeof(tBTA_DM_API_SEARCH);
1690 if ((p_msg = (tBTA_DM_API_SEARCH *) osi_malloc(len)) != NULL) {
1691 memset(p_msg, 0, len);
1693 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
1694 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
1695 p_msg->p_cback = p_cback;
1696 p_msg->rs_res = BTA_DM_RS_NONE;
1699 if (p_services != NULL) {
1700 p_msg->services = p_services->srvc_mask;
1701 p_msg->num_uuid = p_services->num_uuid;
1703 if (p_services->num_uuid != 0) {
1704 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1705 memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
1707 p_msg->p_uuid = NULL;
1711 bta_sys_sendmsg(p_msg);
1719 /*******************************************************************************
1721 ** Function BTA_DmBleUpdateConnectionParam
1723 ** Description Update connection parameters, can only be used when connection is up.
1725 ** Parameters: bd_addr - BD address of the peer
1726 ** min_int - minimum connection interval, [0x0004~ 0x4000]
1727 ** max_int - maximum connection interval, [0x0004~ 0x4000]
1728 ** latency - slave latency [0 ~ 500]
1729 ** timeout - supervision timeout [0x000a ~ 0xc80]
1733 *******************************************************************************/
1734 void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
1735 UINT16 max_int, UINT16 latency,
1738 #if BLE_INCLUDED == TRUE
1739 tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
1741 p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) osi_malloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1742 if (p_msg != NULL) {
1743 memset(p_msg, 0, sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1745 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1746 bdcpy(p_msg->bd_addr, bd_addr);
1747 p_msg->min_int = min_int;
1748 p_msg->max_int = max_int;
1749 p_msg->latency = latency;
1750 p_msg->timeout = timeout;
1752 bta_sys_sendmsg(p_msg);
1756 /*******************************************************************************
1758 ** Function BTA_DmBleConfigLocalPrivacy
1760 ** Description Enable/disable privacy on the local device
1762 ** Parameters: privacy_enable - enable/disabe privacy on remote device.
1766 *******************************************************************************/
1767 void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback)
1769 ///This function used the irk to generate the resolve address
1770 #if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE
1771 tBTA_DM_API_LOCAL_PRIVACY *p_msg;
1773 if ((p_msg = (tBTA_DM_API_LOCAL_PRIVACY *) osi_malloc(sizeof(tBTA_DM_API_ENABLE_PRIVACY))) != NULL) {
1774 memset (p_msg, 0, sizeof(tBTA_DM_API_LOCAL_PRIVACY));
1776 p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
1777 p_msg->privacy_enable = privacy_enable;
1778 p_msg->set_local_privacy_cback = set_local_privacy_cback;
1779 bta_sys_sendmsg(p_msg);
1782 UNUSED (privacy_enable);
1786 #if BLE_INCLUDED == TRUE
1787 /*******************************************************************************
1789 ** Function BTA_DmBleConfigLocalIcon
1791 ** Description set gap local icon
1793 ** Parameters: icon - appearance value.
1797 *******************************************************************************/
1798 void BTA_DmBleConfigLocalIcon(uint16_t icon)
1800 tBTA_DM_API_LOCAL_ICON *p_msg;
1802 if ((p_msg = (tBTA_DM_API_LOCAL_ICON *) osi_malloc(sizeof(tBTA_DM_API_LOCAL_ICON))) != NULL) {
1803 memset (p_msg, 0, sizeof(tBTA_DM_API_LOCAL_ICON));
1805 p_msg->hdr.event = BTA_DM_API_LOCAL_ICON_EVT;
1807 bta_sys_sendmsg(p_msg);
1811 /*******************************************************************************
1813 ** Function BTA_BleEnableAdvInstance
1815 ** Description This function enable a Multi-ADV instance with the specififed
1818 ** Parameters p_params: pointer to the adv parameter structure.
1819 ** p_cback: callback function associated to this adv instance.
1820 ** p_ref: reference data pointer to this adv instance.
1822 ** Returns BTA_SUCCESS if command started sucessfully; otherwise failure.
1824 *******************************************************************************/
1825 void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
1826 tBTA_BLE_MULTI_ADV_CBACK *p_cback,
1829 ///This function just used for vendor debug
1830 tBTA_DM_API_BLE_MULTI_ADV_ENB *p_msg;
1831 UINT16 len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB);
1833 APPL_TRACE_API ("BTA_BleEnableAdvInstance");
1835 if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_ENB *) osi_malloc(len)) != NULL) {
1836 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB));
1838 p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_ENB_EVT;
1839 p_msg->p_cback = (void *)p_cback;
1840 if (p_params != NULL) {
1841 p_msg->p_params = (void *)(p_msg + 1);
1842 memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
1844 p_msg->p_ref = p_ref;
1846 bta_sys_sendmsg(p_msg);
1850 /*******************************************************************************
1852 ** Function BTA_BleUpdateAdvInstParam
1854 ** Description This function update a Multi-ADV instance with the specififed
1857 ** Parameters inst_id: Adv instance to update the parameter.
1858 ** p_params: pointer to the adv parameter structure.
1860 ** Returns BTA_SUCCESS if command started sucessfully; otherwise failure.
1862 *******************************************************************************/
1863 void BTA_BleUpdateAdvInstParam (UINT8 inst_id, tBTA_BLE_ADV_PARAMS *p_params)
1865 ///This function just used for vendor debug
1866 tBTA_DM_API_BLE_MULTI_ADV_PARAM *p_msg;
1867 UINT16 len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM);
1869 APPL_TRACE_API ("BTA_BleUpdateAdvInstParam");
1870 if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_PARAM *) osi_malloc(len)) != NULL) {
1871 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM));
1872 p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT;
1873 p_msg->inst_id = inst_id;
1874 p_msg->p_params = (void *)(p_msg + 1);
1875 memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
1877 bta_sys_sendmsg(p_msg);
1881 /*******************************************************************************
1883 ** Function BTA_BleCfgAdvInstData
1885 ** Description This function configure a Multi-ADV instance with the specififed
1886 ** adv data or scan response data.
1888 ** Parameter inst_id: Adv instance to configure the adv data or scan response.
1889 ** is_scan_rsp: is the data scan response or adv data.
1890 ** data_mask: adv data type as bit mask.
1891 ** p_data: pointer to the ADV data structure tBTA_BLE_ADV_DATA. This
1892 ** memory space can not be freed until BTA_BLE_MULTI_ADV_DATA_EVT
1893 ** is sent to application.
1895 ** Returns BTA_SUCCESS if command started sucessfully; otherwise failure.
1897 *******************************************************************************/
1898 void BTA_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp,
1899 tBTA_BLE_AD_MASK data_mask,
1900 tBTA_BLE_ADV_DATA *p_data)
1902 ///This function just used for vendor debug
1903 tBTA_DM_API_BLE_MULTI_ADV_DATA *p_msg;
1904 UINT16 len = sizeof(tBTA_DM_API_BLE_MULTI_ADV_DATA) ;
1906 APPL_TRACE_API ("BTA_BleCfgAdvInstData");
1908 if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DATA *) osi_malloc(len)) != NULL) {
1909 memset(p_msg, 0, len);
1910 p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_DATA_EVT;
1911 p_msg->inst_id = inst_id;
1912 p_msg->is_scan_rsp = is_scan_rsp;
1913 p_msg->data_mask = data_mask;
1914 p_msg->p_data = p_data;
1916 bta_sys_sendmsg(p_msg);
1920 /*******************************************************************************
1922 ** Function BTA_BleDisableAdvInstance
1924 ** Description This function disable a Multi-ADV instance.
1926 ** Parameter inst_id: instance ID to disable.
1928 ** Returns BTA_SUCCESS if command started sucessfully; otherwise failure.
1930 *******************************************************************************/
1931 void BTA_BleDisableAdvInstance (UINT8 inst_id) //this function just used for vendor debug
1933 tBTA_DM_API_BLE_MULTI_ADV_DISABLE *p_msg;
1935 APPL_TRACE_API ("BTA_BleDisableAdvInstance: %d", inst_id);
1936 if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DISABLE *)
1937 osi_malloc(sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE))) != NULL) {
1938 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE));
1939 p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT;
1940 p_msg->inst_id = inst_id;
1941 bta_sys_sendmsg(p_msg);
1945 /*******************************************************************************
1947 ** Function BTA_DmBleCfgFilterCondition
1949 ** Description This function is called to configure the adv data payload filter
1952 ** Parameters action: to read/write/clear
1953 ** cond_type: filter condition type
1954 ** filt_index - Filter index
1955 ** p_cond: filter condition parameter
1956 ** p_cmpl_back - Command completed callback
1957 ** ref_value - Reference value
1961 *******************************************************************************/
1962 void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
1963 tBTA_DM_BLE_PF_COND_TYPE cond_type,
1964 tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1965 tBTA_DM_BLE_PF_COND_PARAM *p_cond,
1966 tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback,
1967 tBTA_DM_BLE_REF_VALUE ref_value)
1969 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
1970 tBTA_DM_API_CFG_FILTER_COND *p_msg;
1971 APPL_TRACE_API ("BTA_DmBleCfgFilterCondition: %d, %d", action, cond_type);
1973 UINT16 len = sizeof(tBTA_DM_API_CFG_FILTER_COND) +
1974 sizeof(tBTA_DM_BLE_PF_COND_PARAM);
1977 if (NULL != p_cond) {
1978 switch (cond_type) {
1979 case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:
1980 case BTA_DM_BLE_PF_MANU_DATA:
1981 /* Length of pattern and pattern mask and other elements in */
1982 /* tBTA_DM_BLE_PF_MANU_COND */
1983 len += ((p_cond->manu_data.data_len) * 2) +
1984 sizeof(UINT16) + sizeof(UINT16) + sizeof(UINT8);
1987 case BTA_DM_BLE_PF_LOCAL_NAME:
1988 len += ((p_cond->local_name.data_len) + sizeof(UINT8));
1991 case BTM_BLE_PF_SRVC_UUID:
1992 case BTM_BLE_PF_SRVC_SOL_UUID:
1993 len += sizeof(tBLE_BD_ADDR) + sizeof(tBTA_DM_BLE_PF_COND_MASK);
2001 if ((p_msg = (tBTA_DM_API_CFG_FILTER_COND *) osi_malloc(len)) != NULL) {
2002 memset (p_msg, 0, len);
2004 p_msg->hdr.event = BTA_DM_API_CFG_FILTER_COND_EVT;
2005 p_msg->action = action;
2006 p_msg->cond_type = cond_type;
2007 p_msg->filt_index = filt_index;
2008 p_msg->p_filt_cfg_cback = p_cmpl_cback;
2009 p_msg->ref_value = ref_value;
2011 p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM *)(p_msg + 1);
2012 memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
2014 p = (UINT8 *)(p_msg->p_cond_param + 1);
2016 if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN ||
2017 cond_type == BTA_DM_BLE_PF_MANU_DATA) {
2018 p_msg->p_cond_param->manu_data.p_pattern = p;
2019 p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len;
2020 memcpy(p_msg->p_cond_param->manu_data.p_pattern, p_cond->manu_data.p_pattern,
2021 p_cond->manu_data.data_len);
2022 p += p_cond->manu_data.data_len;
2024 if (cond_type == BTA_DM_BLE_PF_MANU_DATA) {
2025 p_msg->p_cond_param->manu_data.company_id_mask =
2026 p_cond->manu_data.company_id_mask;
2027 if ( p_cond->manu_data.p_pattern_mask != NULL) {
2028 p_msg->p_cond_param->manu_data.p_pattern_mask = p;
2029 memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask,
2030 p_cond->manu_data.p_pattern_mask, p_cond->manu_data.data_len);
2033 } else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME) {
2034 p_msg->p_cond_param->local_name.p_data = p;
2035 p_msg->p_cond_param->local_name.data_len =
2036 p_cond->local_name.data_len;
2037 memcpy(p_msg->p_cond_param->local_name.p_data,
2038 p_cond->local_name.p_data, p_cond->local_name.data_len);
2039 } else if ((cond_type == BTM_BLE_PF_SRVC_UUID
2040 || cond_type == BTM_BLE_PF_SRVC_SOL_UUID)) {
2041 if (p_cond->srvc_uuid.p_target_addr != NULL) {
2042 p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR *)(p);
2043 p_msg->p_cond_param->srvc_uuid.p_target_addr->type =
2044 p_cond->srvc_uuid.p_target_addr->type;
2045 memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda,
2046 p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN);
2047 p = (UINT8 *)( p_msg->p_cond_param->srvc_uuid.p_target_addr + 1);
2049 if (p_cond->srvc_uuid.p_uuid_mask) {
2050 p_msg->p_cond_param->srvc_uuid.p_uuid_mask = (tBTA_DM_BLE_PF_COND_MASK *)p;
2051 memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask,
2052 p_cond->srvc_uuid.p_uuid_mask, sizeof(tBTA_DM_BLE_PF_COND_MASK));
2057 bta_sys_sendmsg(p_msg);
2064 UNUSED(p_cmpl_cback);
2069 /*******************************************************************************
2071 ** Function BTA_DmBleScanFilterSetup
2073 ** Description This function is called to setup the adv data payload filter param
2075 ** Parameters p_target: enable the filter condition on a target device; if NULL
2076 ** filt_index - Filter index
2077 ** p_filt_params -Filter parameters
2078 ** ref_value - Reference value
2079 ** action - Add, delete or clear
2080 ** p_cmpl_back - Command completed callback
2084 *******************************************************************************/
2085 void BTA_DmBleScanFilterSetup(UINT8 action, tBTA_DM_BLE_PF_FILT_INDEX filt_index,
2086 tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params,
2087 tBLE_BD_ADDR *p_target,
2088 tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback,
2089 tBTA_DM_BLE_REF_VALUE ref_value)
2091 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
2092 tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *p_msg;
2093 APPL_TRACE_API ("BTA_DmBleScanFilterSetup: %d", action);
2095 UINT16 len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) + sizeof(tBLE_BD_ADDR);
2097 if ((p_msg = (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *) osi_malloc(len)) != NULL) {
2098 memset (p_msg, 0, len);
2100 p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_SETUP_EVT;
2101 p_msg->action = action;
2102 p_msg->filt_index = filt_index;
2103 if (p_filt_params) {
2104 memcpy(&p_msg->filt_params, p_filt_params, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
2106 p_msg->p_filt_param_cback = p_cmpl_cback;
2107 p_msg->ref_value = ref_value;
2110 p_msg->p_target = (tBLE_BD_ADDR *)(p_msg + 1);
2111 memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR));
2114 bta_sys_sendmsg(p_msg);
2119 UNUSED(p_filt_params);
2121 UNUSED(p_cmpl_cback);
2126 /*******************************************************************************
2128 ** Function BTA_DmBleGetEnergyInfo
2130 ** Description This function is called to obtain the energy info
2132 ** Parameters p_cmpl_cback - Command complete callback
2136 *******************************************************************************/
2137 void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback)
2139 tBTA_DM_API_ENERGY_INFO *p_msg;
2140 APPL_TRACE_API ("BTA_DmBleGetEnergyInfo");
2142 UINT16 len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
2144 if ((p_msg = (tBTA_DM_API_ENERGY_INFO *) osi_malloc(len)) != NULL) {
2145 memset (p_msg, 0, len);
2146 p_msg->hdr.event = BTA_DM_API_BLE_ENERGY_INFO_EVT;
2147 p_msg->p_energy_info_cback = p_cmpl_cback;
2148 bta_sys_sendmsg(p_msg);
2152 /*******************************************************************************
2154 ** Function BTA_DmEnableScanFilter
2156 ** Description This function is called to enable the adv data payload filter
2158 ** Parameters action - enable or disable the APCF feature
2159 ** p_cmpl_cback - Command completed callback
2160 ** ref_value - Reference value
2164 *******************************************************************************/
2165 void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback,
2166 tBTA_DM_BLE_REF_VALUE ref_value)
2168 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
2169 tBTA_DM_API_ENABLE_SCAN_FILTER *p_msg;
2170 APPL_TRACE_API ("BTA_DmEnableScanFilter: %d\n", action);
2172 UINT16 len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) + sizeof(tBLE_BD_ADDR);
2174 if ((p_msg = (tBTA_DM_API_ENABLE_SCAN_FILTER *) osi_malloc(len)) != NULL) {
2175 memset (p_msg, 0, len);
2177 p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_ENABLE_EVT;
2178 p_msg->action = action;
2179 p_msg->ref_value = ref_value;
2180 p_msg->p_filt_status_cback = p_cmpl_cback;
2182 bta_sys_sendmsg(p_msg);
2186 UNUSED(p_cmpl_cback);
2191 /*******************************************************************************
2193 ** Function BTA_DmBleUpdateConnectionParams
2195 ** Description Update connection parameters, can only be used when connection is up.
2197 ** Parameters: bd_addr - BD address of the peer
2198 ** min_int - minimum connection interval, [0x0004~ 0x4000]
2199 ** max_int - maximum connection interval, [0x0004~ 0x4000]
2200 ** latency - slave latency [0 ~ 500]
2201 ** timeout - supervision timeout [0x000a ~ 0xc80]
2205 *******************************************************************************/
2206 void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max_int,
2207 UINT16 latency, UINT16 timeout)
2209 tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
2211 if ((p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) osi_malloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM))) != NULL) {
2212 memset (p_msg, 0, sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
2214 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
2215 bdcpy(p_msg->bd_addr, bd_addr);
2216 p_msg->min_int = min_int;
2217 p_msg->max_int = max_int;
2218 p_msg->latency = latency;
2219 p_msg->timeout = timeout;
2220 bta_sys_sendmsg(p_msg);
2223 /*******************************************************************************
2225 ** Function BTA_DmBleDisconnect
2227 ** Description Disconnect the ble connection, can only be used when connection is up.
2229 ** Parameters: bd_addr - BD address of the peer
2233 *******************************************************************************/
2234 void BTA_DmBleDisconnect(BD_ADDR bd_addr)
2236 tBTA_DM_API_BLE_DISCONNECT *p_msg;
2238 if ((p_msg = (tBTA_DM_API_BLE_DISCONNECT *) osi_malloc(sizeof(tBTA_DM_API_BLE_DISCONNECT))) != NULL) {
2239 memset (p_msg, 0, sizeof(tBTA_DM_API_BLE_DISCONNECT));
2241 p_msg->hdr.event = BTA_DM_API_BLE_DISCONNECT_EVT;
2242 bdcpy(p_msg->remote_bda, bd_addr);
2244 bta_sys_sendmsg(p_msg);
2247 /*******************************************************************************
2249 ** Function BTA_DmBleSetDataLength
2251 ** Description This function is to set maximum LE data packet size
2256 *******************************************************************************/
2257 void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length, tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback)
2259 tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg;
2261 if ((p_msg = (tBTA_DM_API_BLE_SET_DATA_LENGTH *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH)))
2263 bdcpy(p_msg->remote_bda, remote_device);
2264 p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
2265 p_msg->tx_data_length = tx_data_length;
2266 p_msg->p_set_pkt_data_cback = p_set_pkt_data_cback;
2268 bta_sys_sendmsg(p_msg);
2274 /*******************************************************************************
2276 ** Function BTA_DmSetEncryption
2278 ** Description This function is called to ensure that connection is
2279 ** encrypted. Should be called only on an open connection.
2280 ** Typically only needed for connections that first want to
2281 ** bring up unencrypted links, then later encrypt them.
2283 ** Parameters: bd_addr - Address of the peer device
2284 ** transport - transport of the link to be encruypted
2285 ** p_callback - Pointer to callback function to indicat the
2286 ** link encryption status
2287 ** sec_act - This is the security action to indicate
2288 ** what kind of BLE security level is required for
2289 ** the BLE link if the BLE is supported
2290 ** Note: This parameter is ignored for the BR/EDR link
2291 ** or the BLE is not supported
2295 *******************************************************************************/
2296 #if (SMP_INCLUDED == TRUE)
2297 void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCRYPT_CBACK *p_callback,
2298 tBTA_DM_BLE_SEC_ACT sec_act)
2300 tBTA_DM_API_SET_ENCRYPTION *p_msg;
2302 APPL_TRACE_API("BTA_DmSetEncryption"); //todo
2303 if ((p_msg = (tBTA_DM_API_SET_ENCRYPTION *) osi_malloc(sizeof(tBTA_DM_API_SET_ENCRYPTION))) != NULL) {
2304 memset(p_msg, 0, sizeof(tBTA_DM_API_SET_ENCRYPTION));
2306 p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
2308 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
2309 p_msg->transport = transport;
2310 p_msg->p_callback = p_callback;
2311 p_msg->sec_act = sec_act;
2313 bta_sys_sendmsg(p_msg);
2316 #endif ///SMP_INCLUDED == TRUE
2318 /*******************************************************************************
2320 ** Function BTA_DmCloseACL
2322 ** Description This function force to close an ACL connection and remove the
2323 ** device from the security database list of known devices.
2325 ** Parameters: bd_addr - Address of the peer device
2326 ** remove_dev - remove device or not after link down
2330 *******************************************************************************/
2331 void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT transport)
2333 tBTA_DM_API_REMOVE_ACL *p_msg;
2335 APPL_TRACE_API("BTA_DmCloseACL");
2337 if ((p_msg = (tBTA_DM_API_REMOVE_ACL *) osi_malloc(sizeof(tBTA_DM_API_REMOVE_ACL))) != NULL) {
2338 memset(p_msg, 0, sizeof(tBTA_DM_API_REMOVE_ACL));
2340 p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
2342 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
2343 p_msg->remove_dev = remove_dev;
2344 p_msg->transport = transport;
2346 bta_sys_sendmsg(p_msg);
2350 #if BLE_INCLUDED == TRUE
2351 /*******************************************************************************
2353 ** Function BTA_DmBleObserve
2355 ** Description This procedure keep the device listening for advertising
2356 ** events from a broadcast device.
2358 ** Parameters start: start or stop observe.
2365 *******************************************************************************/
2366 extern void BTA_DmBleObserve(BOOLEAN start, UINT32 duration,
2367 tBTA_DM_SEARCH_CBACK *p_results_cb,
2368 tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb)
2370 tBTA_DM_API_BLE_OBSERVE *p_msg;
2372 APPL_TRACE_API("BTA_DmBleObserve:start = %d ", start);
2374 if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) osi_malloc(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
2375 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
2377 p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
2378 p_msg->start = start;
2379 p_msg->duration = duration;
2380 p_msg->p_cback = p_results_cb;
2382 p_msg->p_start_scan_cback = p_start_stop_scan_cb;
2385 p_msg->p_stop_scan_cback = p_start_stop_scan_cb;
2388 bta_sys_sendmsg(p_msg);
2392 /*******************************************************************************
2394 ** Function BTA_DmBleScan
2396 ** Description This procedure keep the device listening for advertising
2397 ** events from a broadcast device.
2399 ** Parameters start: start or stop scan.
2406 *******************************************************************************/
2407 extern void BTA_DmBleScan(BOOLEAN start, UINT32 duration,
2408 tBTA_DM_SEARCH_CBACK *p_results_cb,
2409 tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb)
2411 tBTA_DM_API_BLE_SCAN *p_msg;
2413 APPL_TRACE_API("BTA_DmBleScan:start = %d ", start);
2415 if ((p_msg = (tBTA_DM_API_BLE_SCAN *) osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN))) != NULL) {
2416 memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN));
2418 p_msg->hdr.event = BTA_DM_API_BLE_SCAN_EVT;
2419 p_msg->start = start;
2420 p_msg->duration = duration;
2421 p_msg->p_cback = p_results_cb;
2423 p_msg->p_start_scan_cback = p_start_stop_scan_cb;
2426 p_msg->p_stop_scan_cback = p_start_stop_scan_cb;
2429 bta_sys_sendmsg(p_msg);
2433 /*******************************************************************************
2435 ** Function BTA_DmBleStopAdvertising
2437 ** Description This function set the random address for the APP
2444 *******************************************************************************/
2445 extern void BTA_DmBleStopAdvertising(void)
2449 APPL_TRACE_API("BTA_DmBleStopAdvertising\n");
2451 if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
2452 memset(p_msg, 0, sizeof(BT_HDR));
2453 p_msg->event = BTA_DM_API_BLE_STOP_ADV_EVT;
2454 bta_sys_sendmsg(p_msg);
2459 /*******************************************************************************
2461 ** Function BTA_DmSetRandAddress
2463 ** Description This function set the random address for the APP
2465 ** Parameters rand_addr: the random address whith should be setting
2466 ** p_set_rand_addr_cback: complete callback
2470 *******************************************************************************/
2471 extern void BTA_DmSetRandAddress(BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback)
2473 tBTA_DM_APT_SET_DEV_ADDR *p_msg;
2474 APPL_TRACE_API("set the random address ");
2475 if ((p_msg = (tBTA_DM_APT_SET_DEV_ADDR *) osi_malloc(sizeof(tBTA_DM_APT_SET_DEV_ADDR))) != NULL) {
2476 memset(p_msg, 0, sizeof(tBTA_DM_APT_SET_DEV_ADDR));
2477 memcpy(p_msg->address, rand_addr, BD_ADDR_LEN);
2478 p_msg->hdr.event = BTA_DM_API_SET_RAND_ADDR_EVT;
2479 p_msg->addr_type = BLE_ADDR_RANDOM;
2480 p_msg->p_set_rand_addr_cback = p_set_rand_addr_cback;
2481 //start sent the msg to the bta system control moudle
2482 bta_sys_sendmsg(p_msg);
2486 void BTA_DmClearRandAddress(void)
2488 tBTA_DM_APT_CLEAR_ADDR *p_msg;
2489 if ((p_msg = (tBTA_DM_APT_CLEAR_ADDR *) osi_malloc(sizeof(tBTA_DM_APT_CLEAR_ADDR))) != NULL) {
2490 memset(p_msg, 0, sizeof(tBTA_DM_APT_CLEAR_ADDR));
2491 p_msg->hdr.event = BTA_DM_API_CLEAR_RAND_ADDR_EVT;
2492 bta_sys_sendmsg(p_msg);
2496 /*******************************************************************************
2498 ** Function BTA_VendorInit
2500 ** Description This function initializes vendor specific
2504 *******************************************************************************/
2505 void BTA_VendorInit (void)
2507 APPL_TRACE_API("BTA_VendorInit");
2510 /*******************************************************************************
2512 ** Function BTA_VendorCleanup
2514 ** Description This function frees up Broadcom specific VS specific dynamic memory
2518 *******************************************************************************/
2519 void BTA_VendorCleanup (void)
2521 tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
2522 BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
2524 #if (BLE_INCLUDED == TRUE && BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
2525 btm_ble_adv_filter_cleanup(); // when BLE_VND_INCLUDED is false, this function will be ignore, so move it out of "if"
2527 #if 0 //by TH, comment out temporarily
2528 if (cmn_ble_vsc_cb.max_filter > 0) {
2529 btm_ble_adv_filter_cleanup();
2530 #if BLE_PRIVACY_SPT == TRUE
2531 btm_ble_resolving_list_cleanup ();
2536 if (cmn_ble_vsc_cb.tot_scan_results_strg > 0) {
2537 btm_ble_batchscan_cleanup();
2541 if (cmn_ble_vsc_cb.adv_inst_max > 0) {
2542 btm_ble_multi_adv_cleanup();