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 "bt_common.h"
28 #include "bta_closure_api.h"
29 #include "bta_dm_int.h"
30 #include "bta_sys_int.h"
36 /*****************************************************************************
38 *****************************************************************************/
40 static const tBTA_SYS_REG bta_dm_reg =
46 static const tBTA_SYS_REG bta_dm_search_reg =
48 bta_dm_search_sm_execute,
49 bta_dm_search_sm_disable
52 /*******************************************************************************
54 ** Function BTA_EnableBluetooth
56 ** Description Enables bluetooth service. This function must be
57 ** called before any other functions in the BTA API are called.
60 ** Returns tBTA_STATUS
62 *******************************************************************************/
63 tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
65 /* Bluetooth disabling is in progress */
66 if (bta_dm_cb.disabling)
71 bta_sys_register(BTA_ID_DM, &bta_dm_reg );
72 bta_sys_register(BTA_ID_DM_SEARCH, &bta_dm_search_reg );
74 /* if UUID list is not provided as static data */
75 bta_sys_eir_register(bta_dm_eir_update_uuid);
77 tBTA_DM_API_ENABLE *p_msg =
78 (tBTA_DM_API_ENABLE *)osi_malloc(sizeof(tBTA_DM_API_ENABLE));
79 p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
80 p_msg->p_sec_cback = p_cback;
82 bta_sys_sendmsg(p_msg);
87 /*******************************************************************************
89 ** Function BTA_DisableBluetooth
91 ** Description Disables bluetooth service. This function is called when
92 ** the application no longer needs bluetooth service
96 *******************************************************************************/
97 tBTA_STATUS BTA_DisableBluetooth(void)
99 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
101 p_msg->event = BTA_DM_API_DISABLE_EVT;
103 bta_sys_sendmsg(p_msg);
108 /*******************************************************************************
110 ** Function BTA_EnableTestMode
112 ** Description Enables bluetooth device under test mode
115 ** Returns tBTA_STATUS
117 *******************************************************************************/
118 tBTA_STATUS BTA_EnableTestMode(void)
120 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
122 APPL_TRACE_API("%s", __func__);
124 p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
125 bta_sys_sendmsg(p_msg);
130 /*******************************************************************************
132 ** Function BTA_DisableTestMode
134 ** Description Disable bluetooth device under test mode
139 *******************************************************************************/
140 void BTA_DisableTestMode(void)
142 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
144 APPL_TRACE_API("%s", __func__);
146 p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
147 bta_sys_sendmsg(p_msg);
150 /*******************************************************************************
152 ** Function BTA_DmSetDeviceName
154 ** Description This function sets the Bluetooth name of local device
159 *******************************************************************************/
160 void BTA_DmSetDeviceName(char *p_name)
162 tBTA_DM_API_SET_NAME *p_msg =
163 (tBTA_DM_API_SET_NAME *)osi_malloc(sizeof(tBTA_DM_API_SET_NAME));
165 p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
166 strlcpy((char*)p_msg->name, p_name, BD_NAME_LEN);
168 bta_sys_sendmsg(p_msg);
171 /*******************************************************************************
173 ** Function BTA_DmSetVisibility
175 ** Description This function sets the Bluetooth connectable,
176 ** discoverable, pairable and conn paired only modes of local device
181 *******************************************************************************/
182 void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, uint8_t pairable_mode, uint8_t conn_filter )
184 tBTA_DM_API_SET_VISIBILITY *p_msg =
185 (tBTA_DM_API_SET_VISIBILITY *)osi_malloc(sizeof(tBTA_DM_MSG));
187 p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
188 p_msg->disc_mode = disc_mode;
189 p_msg->conn_mode = conn_mode;
190 p_msg->pair_mode = pairable_mode;
191 p_msg->conn_paired_only = conn_filter;
193 bta_sys_sendmsg(p_msg);
196 /*******************************************************************************
198 ** Function BTA_DmSearch
200 ** Description This function searches for peer Bluetooth devices. It performs
201 ** an inquiry and gets the remote name for devices. Service
202 ** discovery is done if services is non zero
207 *******************************************************************************/
208 void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback)
210 tBTA_DM_API_SEARCH *p_msg =
211 (tBTA_DM_API_SEARCH *)osi_calloc(sizeof(tBTA_DM_API_SEARCH));
213 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
214 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
215 p_msg->services = services;
216 p_msg->p_cback = p_cback;
217 p_msg->rs_res = BTA_DM_RS_NONE;
219 bta_sys_sendmsg(p_msg);
222 /*******************************************************************************
224 ** Function BTA_DmSearchCancel
226 ** Description This function cancels a search initiated by BTA_DmSearch
231 *******************************************************************************/
232 void BTA_DmSearchCancel(void)
234 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
236 p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
237 bta_sys_sendmsg(p_msg);
240 /*******************************************************************************
242 ** Function BTA_DmDiscover
244 ** Description This function does service discovery for services of a
250 *******************************************************************************/
251 void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
252 tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search)
254 tBTA_DM_API_DISCOVER *p_msg =
255 (tBTA_DM_API_DISCOVER *)osi_calloc(sizeof(tBTA_DM_API_DISCOVER));
257 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
258 bdcpy(p_msg->bd_addr, bd_addr);
259 p_msg->services = services;
260 p_msg->p_cback = p_cback;
261 p_msg->sdp_search = sdp_search;
263 bta_sys_sendmsg(p_msg);
266 /*******************************************************************************
268 ** Function BTA_DmDiscoverUUID
270 ** Description This function does service discovery for services of a
276 *******************************************************************************/
277 void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
278 tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search)
280 tBTA_DM_API_DISCOVER *p_msg =
281 (tBTA_DM_API_DISCOVER *)osi_malloc(sizeof(tBTA_DM_API_DISCOVER));
283 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
284 bdcpy(p_msg->bd_addr, bd_addr);
285 p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level
286 p_msg->p_cback = p_cback;
287 p_msg->sdp_search = sdp_search;
289 #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
291 p_msg->p_uuid = NULL;
293 memcpy(&p_msg->uuid, uuid, sizeof(tSDP_UUID) );
295 bta_sys_sendmsg(p_msg);
298 /*******************************************************************************
300 ** Function BTA_DmBond
302 ** Description This function initiates a bonding procedure with a peer
308 *******************************************************************************/
309 void BTA_DmBond(BD_ADDR bd_addr)
311 tBTA_DM_API_BOND *p_msg =
312 (tBTA_DM_API_BOND *)osi_malloc(sizeof(tBTA_DM_API_BOND));
314 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
315 bdcpy(p_msg->bd_addr, bd_addr);
316 p_msg->transport = BTA_TRANSPORT_UNKNOWN;
318 bta_sys_sendmsg(p_msg);
321 /*******************************************************************************
323 ** Function BTA_DmBondByTransports
325 ** Description This function initiates a bonding procedure with a peer
331 *******************************************************************************/
332 void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport)
334 tBTA_DM_API_BOND *p_msg =
335 (tBTA_DM_API_BOND *)osi_malloc(sizeof(tBTA_DM_API_BOND));
337 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
338 bdcpy(p_msg->bd_addr, bd_addr);
339 p_msg->transport = transport;
341 bta_sys_sendmsg(p_msg);
344 /*******************************************************************************
346 ** Function BTA_DmBondCancel
348 ** Description This function cancels the bonding procedure with a peer
354 *******************************************************************************/
355 void BTA_DmBondCancel(BD_ADDR bd_addr)
357 tBTA_DM_API_BOND_CANCEL *p_msg =
358 (tBTA_DM_API_BOND_CANCEL *)osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL));
360 p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
361 bdcpy(p_msg->bd_addr, bd_addr);
363 bta_sys_sendmsg(p_msg);
366 /*******************************************************************************
368 ** Function BTA_DmPinReply
370 ** Description This function provides a pincode for a remote device when
371 ** one is requested by DM through BTA_DM_PIN_REQ_EVT
376 *******************************************************************************/
377 void BTA_DmPinReply(BD_ADDR bd_addr, bool accept, uint8_t pin_len, uint8_t *p_pin)
380 tBTA_DM_API_PIN_REPLY *p_msg =
381 (tBTA_DM_API_PIN_REPLY *)osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY));
383 p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
384 bdcpy(p_msg->bd_addr, bd_addr);
385 p_msg->accept = accept;
387 p_msg->pin_len = pin_len;
388 memcpy(p_msg->p_pin, p_pin, pin_len);
391 bta_sys_sendmsg(p_msg);
394 /*******************************************************************************
396 ** Function BTA_DmLocalOob
398 ** Description This function retrieves the OOB data from local controller.
399 ** The result is reported by:
400 ** - bta_dm_co_loc_oob_ext() if device supports secure
402 ** - bta_dm_co_loc_oob() if device doesn't support SC
406 *******************************************************************************/
407 void BTA_DmLocalOob(void)
409 tBTA_DM_API_LOC_OOB *p_msg =
410 (tBTA_DM_API_LOC_OOB *)osi_malloc(sizeof(tBTA_DM_API_LOC_OOB));
412 p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
413 bta_sys_sendmsg(p_msg);
416 /*******************************************************************************
418 ** Function BTA_DmConfirm
420 ** Description This function accepts or rejects the numerical value of the
421 ** Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
425 *******************************************************************************/
426 void BTA_DmConfirm(BD_ADDR bd_addr, bool accept)
428 tBTA_DM_API_CONFIRM *p_msg =
429 (tBTA_DM_API_CONFIRM *)osi_malloc(sizeof(tBTA_DM_API_CONFIRM));
431 p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
432 bdcpy(p_msg->bd_addr, bd_addr);
433 p_msg->accept = accept;
435 bta_sys_sendmsg(p_msg);
438 /*******************************************************************************
440 ** Function BTA_DmAddDevice
442 ** Description This function adds a device to the security database list of
448 *******************************************************************************/
449 void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
450 tBTA_SERVICE_MASK trusted_mask, bool is_trusted,
451 uint8_t key_type, tBTA_IO_CAP io_cap, uint8_t pin_length)
453 tBTA_DM_API_ADD_DEVICE *p_msg =
454 (tBTA_DM_API_ADD_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_ADD_DEVICE));
456 p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
457 bdcpy(p_msg->bd_addr, bd_addr);
458 p_msg->tm = trusted_mask;
459 p_msg->is_trusted = is_trusted;
460 p_msg->io_cap = io_cap;
463 p_msg->link_key_known = true;
464 p_msg->key_type = key_type;
465 memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
468 /* Load device class if specified */
470 p_msg->dc_known = true;
471 memcpy(p_msg->dc, dev_class, DEV_CLASS_LEN);
474 memset(p_msg->bd_name, 0, BD_NAME_LEN + 1);
475 memset(p_msg->features, 0, sizeof (p_msg->features));
476 p_msg->pin_length = pin_length;
478 bta_sys_sendmsg(p_msg);
481 /*******************************************************************************
483 ** Function BTA_DmRemoveDevice
485 ** Description This function removes a device fromthe security database list of
486 ** peer device. It manages unpairing even while connected.
491 *******************************************************************************/
492 tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
494 tBTA_DM_API_REMOVE_DEVICE *p_msg =
495 (tBTA_DM_API_REMOVE_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_REMOVE_DEVICE));
497 p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
498 bdcpy(p_msg->bd_addr, bd_addr);
500 bta_sys_sendmsg(p_msg);
505 /*******************************************************************************
507 ** Function BTA_GetEirService
509 ** Description This function is called to get BTA service mask from EIR.
511 ** Parameters p_eir - pointer of EIR significant part
512 ** p_services - return the BTA service mask
516 *******************************************************************************/
517 extern const uint16_t bta_service_id_to_uuid_lkup_tbl [];
518 void BTA_GetEirService( uint8_t *p_eir, tBTA_SERVICE_MASK *p_services )
521 uint8_t num_uuid, max_num_uuid = 32;
522 uint8_t uuid_list[32*LEN_UUID_16];
523 uint16_t *p_uuid16 = (uint16_t *)uuid_list;
524 tBTA_SERVICE_MASK mask;
526 BTM_GetEirUuidList( p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid);
527 for( xx = 0; xx < num_uuid; xx++ )
530 for( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ )
532 if( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] )
540 /* for HSP v1.2 only device */
541 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS)
542 *p_services |= BTA_HSP_SERVICE_MASK;
544 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE)
545 *p_services |= BTA_HL_SERVICE_MASK;
547 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK)
548 *p_services |= BTA_HL_SERVICE_MASK;
552 /*******************************************************************************
554 ** Function BTA_DmGetConnectionState
556 ** Description Returns whether the remote device is currently connected.
558 ** Returns 0 if the device is NOT connected.
560 *******************************************************************************/
561 uint16_t BTA_DmGetConnectionState(const BD_ADDR bd_addr )
563 tBTA_DM_PEER_DEVICE * p_dev = bta_dm_find_peer_device(bd_addr);
564 return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
568 /*******************************************************************************
569 ** Device Identification (DI) Server Functions
570 *******************************************************************************/
571 /*******************************************************************************
573 ** Function BTA_DmSetLocalDiRecord
575 ** Description This function adds a DI record to the local SDP database.
577 ** Returns BTA_SUCCESS if record set sucessfully, otherwise error code.
579 *******************************************************************************/
580 tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
583 tBTA_STATUS status = BTA_FAILURE;
585 if(bta_dm_di_cb.di_num < BTA_DI_NUM_MAX)
587 if(SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS)
589 if(!p_device_info->primary_record)
591 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
592 bta_dm_di_cb.di_num ++;
595 bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
596 status = BTA_SUCCESS;
603 /*******************************************************************************
605 ** Function bta_dmexecutecallback
607 ** Description This function will request BTA to execute a call back in the context of BTU task
608 ** This API was named in lower case because it is only intended
609 ** for the internal customers(like BTIF).
613 *******************************************************************************/
614 void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param)
616 tBTA_DM_API_EXECUTE_CBACK *p_msg =
617 (tBTA_DM_API_EXECUTE_CBACK *)osi_malloc(sizeof(tBTA_DM_MSG));
619 p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
620 p_msg->p_param= p_param;
621 p_msg->p_exec_cback= p_callback;
623 bta_sys_sendmsg(p_msg);
626 /*******************************************************************************
628 ** Function BTA_DmAddBleKey
630 ** Description Add/modify LE device information. This function will be
631 ** normally called during host startup to restore all required
632 ** information stored in the NVRAM.
634 ** Parameters: bd_addr - BD address of the peer
635 ** p_le_key - LE key values.
636 ** key_type - LE SMP key type.
638 ** Returns BTA_SUCCESS if successful
639 ** BTA_FAIL if operation failed.
641 *******************************************************************************/
642 void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_TYPE key_type)
644 #if (BLE_INCLUDED == TRUE)
646 tBTA_DM_API_ADD_BLEKEY *p_msg =
647 (tBTA_DM_API_ADD_BLEKEY *)osi_calloc(sizeof(tBTA_DM_API_ADD_BLEKEY));
649 p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
650 p_msg->key_type = key_type;
651 bdcpy(p_msg->bd_addr, bd_addr);
652 memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE));
654 bta_sys_sendmsg(p_msg);
658 /*******************************************************************************
660 ** Function BTA_DmAddBleDevice
662 ** Description Add a BLE device. This function will be normally called
663 ** during host startup to restore all required information
664 ** for a LE device stored in the NVRAM.
666 ** Parameters: bd_addr - BD address of the peer
667 ** dev_type - Remote device's device type.
668 ** addr_type - LE device address type.
672 *******************************************************************************/
673 void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TYPE dev_type)
675 #if (BLE_INCLUDED == TRUE)
676 tBTA_DM_API_ADD_BLE_DEVICE *p_msg =
677 (tBTA_DM_API_ADD_BLE_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
679 p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
680 bdcpy(p_msg->bd_addr, bd_addr);
681 p_msg->addr_type = addr_type;
682 p_msg->dev_type = dev_type;
684 bta_sys_sendmsg(p_msg);
688 /*******************************************************************************
690 ** Function BTA_DmBlePasskeyReply
692 ** Description Send BLE SMP passkey reply.
694 ** Parameters: bd_addr - BD address of the peer
695 ** accept - passkey entry sucessful or declined.
696 ** passkey - passkey value, must be a 6 digit number,
701 *******************************************************************************/
702 void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, bool accept, uint32_t passkey)
704 #if (BLE_INCLUDED == TRUE)
705 tBTA_DM_API_PASSKEY_REPLY *p_msg =
706 (tBTA_DM_API_PASSKEY_REPLY *)osi_calloc(sizeof(tBTA_DM_API_PASSKEY_REPLY));
708 p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
709 bdcpy(p_msg->bd_addr, bd_addr);
710 p_msg->accept = accept;
713 p_msg->passkey = passkey;
715 bta_sys_sendmsg(p_msg);
719 /*******************************************************************************
721 ** Function BTA_DmBleConfirmReply
723 ** Description Send BLE SMP SC user confirmation reply.
725 ** Parameters: bd_addr - BD address of the peer
726 ** accept - numbers to compare are the same or different.
730 *******************************************************************************/
731 void BTA_DmBleConfirmReply(BD_ADDR bd_addr, bool accept)
733 #if (BLE_INCLUDED == TRUE)
734 tBTA_DM_API_CONFIRM *p_msg =
735 (tBTA_DM_API_CONFIRM *)osi_calloc(sizeof(tBTA_DM_API_CONFIRM));
737 p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT;
738 bdcpy(p_msg->bd_addr, bd_addr);
739 p_msg->accept = accept;
741 bta_sys_sendmsg(p_msg);
745 /*******************************************************************************
747 ** Function BTA_DmBleSecurityGrant
749 ** Description Grant security request access.
751 ** Parameters: bd_addr - BD address of the peer
752 ** res - security grant status.
756 *******************************************************************************/
757 void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
759 #if (BLE_INCLUDED == TRUE)
760 tBTA_DM_API_BLE_SEC_GRANT *p_msg =
761 (tBTA_DM_API_BLE_SEC_GRANT *)osi_calloc(sizeof(tBTA_DM_API_BLE_SEC_GRANT));
763 p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
764 bdcpy(p_msg->bd_addr, bd_addr);
767 bta_sys_sendmsg(p_msg);
771 /*******************************************************************************
773 ** Function BTA_DmSetBlePrefConnParams
775 ** Description This function is called to set the preferred connection
776 ** parameters when default connection parameter is not desired.
778 ** Parameters: bd_addr - BD address of the peripheral
779 ** scan_interval - scan interval
780 ** scan_window - scan window
781 ** min_conn_int - minimum preferred connection interval
782 ** max_conn_int - maximum preferred connection interval
783 ** slave_latency - preferred slave latency
784 ** supervision_tout - preferred supervision timeout
789 *******************************************************************************/
790 void BTA_DmSetBlePrefConnParams(const BD_ADDR bd_addr,
791 uint16_t min_conn_int, uint16_t max_conn_int,
792 uint16_t slave_latency, uint16_t supervision_tout )
794 #if (BLE_INCLUDED == TRUE)
795 tBTA_DM_API_BLE_CONN_PARAMS *p_msg =
796 (tBTA_DM_API_BLE_CONN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
798 p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
799 memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN);
800 p_msg->conn_int_max = max_conn_int;
801 p_msg->conn_int_min = min_conn_int;
802 p_msg->slave_latency = slave_latency;
803 p_msg->supervision_tout = supervision_tout;
805 bta_sys_sendmsg(p_msg);
809 /*******************************************************************************
811 ** Function BTA_DmSetBleConnScanParams
813 ** Description This function is called to set scan parameters used in
814 ** BLE connection request
816 ** Parameters: scan_interval - scan interval
817 ** scan_window - scan window
821 *******************************************************************************/
822 void BTA_DmSetBleConnScanParams(uint32_t scan_interval, uint32_t scan_window)
824 #if (BLE_INCLUDED == TRUE)
825 tBTA_DM_API_BLE_SCAN_PARAMS *p_msg =
826 (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
828 p_msg->hdr.event = BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT;
829 p_msg->scan_int = scan_interval;
830 p_msg->scan_window = scan_window;
832 bta_sys_sendmsg(p_msg);
833 #endif // BLE_INCLUDED == true
836 /*******************************************************************************
838 ** Function BTA_DmSetBleScanParams
840 ** Description This function is called to set scan parameters
842 ** Parameters: client_if - Client IF
843 ** scan_interval - scan interval
844 ** scan_window - scan window
845 ** scan_mode - scan mode
846 ** scan_param_setup_status_cback - Set scan param status callback
850 *******************************************************************************/
852 #if (BLE_INCLUDED == TRUE)
853 void BTA_DmSetBleScanParams(tGATT_IF client_if, uint32_t scan_interval,
854 uint32_t scan_window, tBLE_SCAN_MODE scan_mode,
855 tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
857 tBTA_DM_API_BLE_SCAN_PARAMS *p_msg =
858 (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
860 p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT;
861 p_msg->client_if = client_if;
862 p_msg->scan_int = scan_interval;
863 p_msg->scan_window = scan_window;
864 p_msg->scan_mode = scan_mode;
865 p_msg->scan_param_setup_cback = scan_param_setup_cback;
867 bta_sys_sendmsg(p_msg);
869 #endif // BLE_INCLUDED == true
871 /*******************************************************************************
873 ** Function BTA_DmSetBleAdvParams
875 ** Description This function sets the advertising parameters BLE functionality.
876 ** It is to be called when device act in peripheral or broadcaster
882 *******************************************************************************/
883 void BTA_DmSetBleAdvParams(uint16_t adv_int_min, uint16_t adv_int_max,
884 tBLE_BD_ADDR *p_dir_bda)
886 #if (BLE_INCLUDED == TRUE)
887 if (p_dir_bda != NULL) {
888 tBLE_BD_ADDR *bda = new tBLE_BD_ADDR;
889 memcpy(bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
890 do_in_bta_thread(FROM_HERE,
891 base::Bind(&bta_dm_ble_set_adv_params, adv_int_min, adv_int_max, base::Owned(bda)));
894 do_in_bta_thread(FROM_HERE,
895 base::Bind(&bta_dm_ble_set_adv_params, adv_int_min, adv_int_max, nullptr));
900 /*******************************************************************************
901 ** BLE ADV data management API
902 ********************************************************************************/
904 #if (BLE_INCLUDED == TRUE)
905 /*******************************************************************************
907 ** Function BTA_DmBleSetStorageParams
909 ** Description This function is called to override the BTA scan response.
911 ** Parameters batch_scan_full_max -Max storage space (in %) allocated to full scanning
912 ** batch_scan_trunc_max -Max storage space (in %) allocated to truncated scanning
913 ** batch_scan_notify_threshold -Setup notification level based on total space
914 ** p_setup_cback - Setup callback pointer
915 ** p_thres_cback - Threshold callback pointer
916 ** p_rep_cback - Reports callback pointer
917 ** ref_value - Ref value
921 *******************************************************************************/
922 extern void BTA_DmBleSetStorageParams(uint8_t batch_scan_full_max,
923 uint8_t batch_scan_trunc_max,
924 uint8_t batch_scan_notify_threshold,
925 tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback,
926 tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback,
927 tBTA_BLE_SCAN_REP_CBACK* p_rep_cback,
928 tBTA_DM_BLE_REF_VALUE ref_value)
930 tBTA_DM_API_SET_STORAGE_CONFIG *p_msg =
931 (tBTA_DM_API_SET_STORAGE_CONFIG *)osi_malloc(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG));
933 bta_dm_cb.p_setup_cback = p_setup_cback;
935 p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT;
936 p_msg->p_setup_cback=bta_ble_scan_setup_cb;
937 p_msg->p_thres_cback=p_thres_cback;
938 p_msg->p_read_rep_cback=p_rep_cback;
939 p_msg->ref_value = ref_value;
940 p_msg->batch_scan_full_max = batch_scan_full_max;
941 p_msg->batch_scan_trunc_max = batch_scan_trunc_max;
942 p_msg->batch_scan_notify_threshold = batch_scan_notify_threshold;
944 bta_sys_sendmsg(p_msg);
947 /*******************************************************************************
949 ** Function BTA_DmBleEnableBatchScan
951 ** Description This function is called to enable the batch scan
953 ** Parameters scan_mode -Batch scan mode
954 ** scan_interval - Scan interval
955 ** scan_window - Scan window
956 ** discard_rule -Discard rules
957 ** addr_type - Address type
958 ** ref_value - Reference value
962 *******************************************************************************/
963 extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode,
964 uint32_t scan_interval, uint32_t scan_window,
965 tBTA_BLE_DISCARD_RULE discard_rule,
966 tBLE_ADDR_TYPE addr_type,
967 tBTA_DM_BLE_REF_VALUE ref_value)
969 tBTA_DM_API_ENABLE_SCAN *p_msg =
970 (tBTA_DM_API_ENABLE_SCAN *)osi_malloc(sizeof(tBTA_DM_API_ENABLE_SCAN));
972 p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT;
973 p_msg->scan_mode = scan_mode;
974 p_msg->scan_int = scan_interval;
975 p_msg->scan_window = scan_window;
976 p_msg->discard_rule = discard_rule;
977 p_msg->addr_type = addr_type;
978 p_msg->ref_value = ref_value;
980 bta_sys_sendmsg(p_msg);
983 /*******************************************************************************
985 ** Function BTA_DmBleDisableBatchScan
987 ** Description This function is called to disable the batch scan
989 ** Parameters ref_value - Reference value
993 *******************************************************************************/
994 extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)
996 tBTA_DM_API_DISABLE_SCAN *p_msg =
997 (tBTA_DM_API_DISABLE_SCAN *)osi_malloc(sizeof(tBTA_DM_API_DISABLE_SCAN));
999 p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT;
1000 p_msg->ref_value = ref_value;
1002 bta_sys_sendmsg(p_msg);
1005 /*******************************************************************************
1007 ** Function BTA_DmBleReadScanReports
1009 ** Description This function is called to read scan reports
1011 ** Parameters scan_type -Batch scan mode
1012 ** ref_value - Reference value
1016 *******************************************************************************/
1017 extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type,
1018 tBTA_DM_BLE_REF_VALUE ref_value)
1020 tBTA_DM_API_READ_SCAN_REPORTS *p_msg =
1021 (tBTA_DM_API_READ_SCAN_REPORTS *)osi_malloc(sizeof(tBTA_DM_API_READ_SCAN_REPORTS));
1023 p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT;
1024 p_msg->scan_type = scan_type;
1025 p_msg->ref_value = ref_value;
1027 bta_sys_sendmsg(p_msg);
1030 /*******************************************************************************
1032 ** Function BTA_DmBleTrackAdvertiser
1034 ** Description This function is called to track advertiser
1036 ** Parameters ref_value - Reference value
1037 ** p_track_adv_cback - Track ADV callback
1041 *******************************************************************************/
1042 extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
1043 tBTA_BLE_TRACK_ADV_CBACK *p_track_adv_cback)
1045 tBTA_DM_API_TRACK_ADVERTISER *p_msg =
1046 (tBTA_DM_API_TRACK_ADVERTISER *)osi_malloc(sizeof(tBTA_DM_API_TRACK_ADVERTISER));
1048 p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT;
1049 p_msg->p_track_adv_cback = p_track_adv_cback;
1050 p_msg->ref_value = ref_value;
1052 bta_sys_sendmsg(p_msg);
1057 /*******************************************************************************
1058 ** BLE ADV data management API
1059 ********************************************************************************/
1060 #if (BLE_INCLUDED == TRUE)
1062 /*******************************************************************************
1064 ** Function BTA_DmBleBroadcast
1066 ** Description This function starts or stops LE broadcasting.
1068 ** Parameters start: start or stop broadcast.
1072 *******************************************************************************/
1073 extern void BTA_DmBleBroadcast (bool start)
1075 tBTA_DM_API_BLE_OBSERVE *p_msg =
1076 (tBTA_DM_API_BLE_OBSERVE *)osi_calloc(sizeof(tBTA_DM_API_BLE_OBSERVE));
1078 APPL_TRACE_API("BTA_DmBleBroadcast: start = %d ", start);
1080 p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
1081 p_msg->start = start;
1083 bta_sys_sendmsg(p_msg);
1087 /*******************************************************************************
1089 ** Function BTA_DmBleSetBgConnType
1091 ** Description This function is called to set BLE connectable mode for a
1092 ** peripheral device.
1094 ** Parameters bg_conn_type: it can be auto connection, or selective connection.
1095 ** p_select_cback: callback function when selective connection procedure
1100 *******************************************************************************/
1101 void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback)
1103 #if (BLE_INCLUDED == TRUE)
1104 tBTA_DM_API_BLE_SET_BG_CONN_TYPE *p_msg =
1105 (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *)osi_calloc(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
1107 p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
1108 p_msg->bg_conn_type = bg_conn_type;
1109 p_msg->p_select_cback = p_select_cback;
1111 bta_sys_sendmsg(p_msg);
1115 /*******************************************************************************
1117 ** Function bta_dm_discover_send_msg
1119 ** Description This function send discover message to BTA task.
1123 *******************************************************************************/
1124 #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1125 static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1126 tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search,
1127 tBTA_TRANSPORT transport)
1129 const size_t len = p_services ?
1130 (sizeof(tBTA_DM_API_DISCOVER) + sizeof(tBT_UUID) * p_services->num_uuid)
1131 : sizeof(tBTA_DM_API_DISCOVER);
1132 tBTA_DM_API_DISCOVER *p_msg = (tBTA_DM_API_DISCOVER *)osi_calloc(len);
1134 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
1135 bdcpy(p_msg->bd_addr, bd_addr);
1136 p_msg->p_cback = p_cback;
1137 p_msg->sdp_search = sdp_search;
1138 p_msg->transport = transport;
1140 if (p_services != NULL) {
1141 #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1142 p_msg->services = p_services->srvc_mask;
1143 p_msg->num_uuid = p_services->num_uuid;
1144 if (p_services->num_uuid != 0) {
1145 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1146 memcpy(p_msg->p_uuid, p_services->p_uuid,
1147 sizeof(tBT_UUID) * p_services->num_uuid);
1152 bta_sys_sendmsg(p_msg);
1156 /*******************************************************************************
1158 ** Function BTA_DmDiscoverByTransport
1160 ** Description This function does service discovery on particular transport
1161 ** for services of a
1162 ** peer device. When services.num_uuid is 0, it indicates all
1163 ** GATT based services are to be searched; otherwise a list of
1164 ** UUID of interested services should be provided through
1165 ** p_services->p_uuid.
1171 *******************************************************************************/
1172 void BTA_DmDiscoverByTransport(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1173 tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search,
1174 tBTA_TRANSPORT transport)
1176 #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1177 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
1182 /*******************************************************************************
1184 ** Function BTA_DmDiscoverExt
1186 ** Description This function does service discovery for services of a
1187 ** peer device. When services.num_uuid is 0, it indicates all
1188 ** GATT based services are to be searched; other wise a list of
1189 ** UUID of interested services should be provided through
1190 ** p_services->p_uuid.
1196 *******************************************************************************/
1197 void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1198 tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search)
1200 #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1201 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, BTA_TRANSPORT_UNKNOWN);
1206 /*******************************************************************************
1208 ** Function BTA_DmSearchExt
1210 ** Description This function searches for peer Bluetooth devices. It performs
1211 ** an inquiry and gets the remote name for devices. Service
1212 ** discovery is done if services is non zero
1214 ** Parameters p_dm_inq: inquiry conditions
1215 ** p_services: if service is not empty, service discovery will be done.
1216 ** for all GATT based service condition, put num_uuid, and
1217 ** p_uuid is the pointer to the list of UUID values.
1218 ** p_cback: callback functino when search is completed.
1224 *******************************************************************************/
1225 void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback)
1227 #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1228 const size_t len = p_services ?
1229 (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid)
1230 : sizeof(tBTA_DM_API_SEARCH);
1231 tBTA_DM_API_SEARCH *p_msg = (tBTA_DM_API_SEARCH *)osi_calloc(len);
1233 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
1234 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
1235 p_msg->p_cback = p_cback;
1236 p_msg->rs_res = BTA_DM_RS_NONE;
1238 if (p_services != NULL) {
1239 p_msg->services = p_services->srvc_mask;
1240 p_msg->num_uuid = p_services->num_uuid;
1242 if (p_services->num_uuid != 0) {
1243 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1244 memcpy(p_msg->p_uuid, p_services->p_uuid,
1245 sizeof(tBT_UUID) * p_services->num_uuid);
1247 p_msg->p_uuid = NULL;
1251 bta_sys_sendmsg(p_msg);
1258 /*******************************************************************************
1260 ** Function BTA_DmBleUpdateConnectionParam
1262 ** Description Update connection parameters, can only be used when connection is up.
1264 ** Parameters: bd_addr - BD address of the peer
1265 ** min_int - minimum connection interval, [0x0004~ 0x4000]
1266 ** max_int - maximum connection interval, [0x0004~ 0x4000]
1267 ** latency - slave latency [0 ~ 500]
1268 ** timeout - supervision timeout [0x000a ~ 0xc80]
1272 *******************************************************************************/
1273 void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, uint16_t min_int,
1274 uint16_t max_int, uint16_t latency,
1277 #if (BLE_INCLUDED == TRUE)
1278 tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
1279 (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1281 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1282 bdcpy(p_msg->bd_addr, bd_addr);
1283 p_msg->min_int = min_int;
1284 p_msg->max_int = max_int;
1285 p_msg->latency = latency;
1286 p_msg->timeout = timeout;
1288 bta_sys_sendmsg(p_msg);
1292 /*******************************************************************************
1294 ** Function BTA_DmBleConfigLocalPrivacy
1296 ** Description Enable/disable privacy on the local device
1298 ** Parameters: privacy_enable - enable/disabe privacy on remote device.
1302 *******************************************************************************/
1303 void BTA_DmBleConfigLocalPrivacy(bool privacy_enable)
1305 #if (BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE)
1306 tBTA_DM_API_LOCAL_PRIVACY *p_msg =
1307 (tBTA_DM_API_LOCAL_PRIVACY *)osi_calloc(sizeof(tBTA_DM_API_ENABLE_PRIVACY));
1309 p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
1310 p_msg->privacy_enable = privacy_enable;
1312 bta_sys_sendmsg(p_msg);
1314 UNUSED (privacy_enable);
1318 #if (BLE_INCLUDED == TRUE)
1319 /*******************************************************************************
1321 ** Function BTA_DmBleCfgFilterCondition
1323 ** Description This function is called to configure the adv data payload filter
1326 ** Parameters action: to read/write/clear
1327 ** cond_type: filter condition type
1328 ** filt_index - Filter index
1329 ** p_cond: filter condition parameter
1330 ** p_cmpl_back - Command completed callback
1331 ** ref_value - Reference value
1335 *******************************************************************************/
1336 void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
1337 tBTA_DM_BLE_PF_COND_TYPE cond_type,
1338 tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1339 tBTA_DM_BLE_PF_COND_PARAM *p_cond,
1340 tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback,
1341 tBTA_DM_BLE_REF_VALUE ref_value)
1343 #if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
1344 tBTA_DM_API_CFG_FILTER_COND *p_msg;
1345 APPL_TRACE_API ("BTA_DmBleCfgFilterCondition: %d, %d", action, cond_type);
1347 uint16_t len = sizeof(tBTA_DM_API_CFG_FILTER_COND) +
1348 sizeof(tBTA_DM_BLE_PF_COND_PARAM);
1355 case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:
1356 case BTA_DM_BLE_PF_MANU_DATA:
1357 /* Length of pattern and pattern mask and other elements in */
1358 /* tBTA_DM_BLE_PF_MANU_COND */
1359 len += ((p_cond->manu_data.data_len) * 2) +
1360 sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint8_t);
1363 case BTA_DM_BLE_PF_LOCAL_NAME:
1364 len += ((p_cond->local_name.data_len) + sizeof(uint8_t));
1367 case BTM_BLE_PF_SRVC_UUID:
1368 case BTM_BLE_PF_SRVC_SOL_UUID:
1369 len += sizeof(tBLE_BD_ADDR) + sizeof(tBTA_DM_BLE_PF_COND_MASK);
1377 p_msg = (tBTA_DM_API_CFG_FILTER_COND *)osi_calloc(len);
1378 p_msg->hdr.event = BTA_DM_API_CFG_FILTER_COND_EVT;
1379 p_msg->action = action;
1380 p_msg->cond_type = cond_type;
1381 p_msg->filt_index = filt_index;
1382 p_msg->p_filt_cfg_cback = p_cmpl_cback;
1383 p_msg->ref_value = ref_value;
1385 p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM *)(p_msg + 1);
1386 memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
1388 p = (uint8_t *)(p_msg->p_cond_param + 1);
1390 if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN ||
1391 cond_type == BTA_DM_BLE_PF_MANU_DATA) {
1392 p_msg->p_cond_param->manu_data.p_pattern = p;
1393 p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len;
1394 memcpy(p_msg->p_cond_param->manu_data.p_pattern, p_cond->manu_data.p_pattern,
1395 p_cond->manu_data.data_len);
1396 p += p_cond->manu_data.data_len;
1398 if (cond_type == BTA_DM_BLE_PF_MANU_DATA) {
1399 p_msg->p_cond_param->manu_data.company_id_mask =
1400 p_cond->manu_data.company_id_mask;
1401 if ( p_cond->manu_data.p_pattern_mask != NULL) {
1402 p_msg->p_cond_param->manu_data.p_pattern_mask = p;
1403 memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask,
1404 p_cond->manu_data.p_pattern_mask,
1405 p_cond->manu_data.data_len);
1408 } else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME) {
1409 p_msg->p_cond_param->local_name.p_data = p;
1410 p_msg->p_cond_param->local_name.data_len =
1411 p_cond->local_name.data_len;
1412 memcpy(p_msg->p_cond_param->local_name.p_data,
1413 p_cond->local_name.p_data, p_cond->local_name.data_len);
1414 } else if (cond_type == BTM_BLE_PF_SRVC_UUID ||
1415 cond_type == BTM_BLE_PF_SRVC_SOL_UUID) {
1416 if (p_cond->srvc_uuid.p_target_addr != NULL) {
1417 p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR *)(p);
1418 p_msg->p_cond_param->srvc_uuid.p_target_addr->type =
1419 p_cond->srvc_uuid.p_target_addr->type;
1420 memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda,
1421 p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN);
1422 p = (uint8_t *)(p_msg->p_cond_param->srvc_uuid.p_target_addr + 1);
1424 if (p_cond->srvc_uuid.p_uuid_mask) {
1425 p_msg->p_cond_param->srvc_uuid.p_uuid_mask = (tBTA_DM_BLE_PF_COND_MASK *)p;
1426 memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask,
1427 p_cond->srvc_uuid.p_uuid_mask,
1428 sizeof(tBTA_DM_BLE_PF_COND_MASK));
1433 bta_sys_sendmsg(p_msg);
1440 UNUSED(p_cmpl_cback);
1445 /*******************************************************************************
1447 ** Function BTA_DmBleScanFilterSetup
1449 ** Description This function is called to setup the adv data payload filter param
1451 ** Parameters p_target: enable the filter condition on a target device; if NULL
1452 ** filt_index - Filter index
1453 ** p_filt_params -Filter parameters
1454 ** ref_value - Reference value
1455 ** action - Add, delete or clear
1456 ** p_cmpl_back - Command completed callback
1460 *******************************************************************************/
1461 void BTA_DmBleScanFilterSetup(uint8_t action,
1462 tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1463 tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params,
1464 tBLE_BD_ADDR *p_target,
1465 tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback,
1466 tBTA_DM_BLE_REF_VALUE ref_value)
1468 #if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
1469 const size_t len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) +
1470 sizeof(tBLE_BD_ADDR);
1471 tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *p_msg =
1472 (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *)osi_calloc(len);
1474 APPL_TRACE_API("%s: %d", __func__, action);
1476 p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_SETUP_EVT;
1477 p_msg->action = action;
1478 p_msg->filt_index = filt_index;
1479 if (p_filt_params) {
1480 memcpy(&p_msg->filt_params, p_filt_params,
1481 sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1483 p_msg->p_filt_param_cback = p_cmpl_cback;
1484 p_msg->ref_value = ref_value;
1487 p_msg->p_target = (tBLE_BD_ADDR *)(p_msg + 1);
1488 memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR));
1491 bta_sys_sendmsg(p_msg);
1496 UNUSED(p_filt_params);
1498 UNUSED(p_cmpl_cback);
1503 /*******************************************************************************
1505 ** Function BTA_DmBleGetEnergyInfo
1507 ** Description This function is called to obtain the energy info
1509 ** Parameters p_cmpl_cback - Command complete callback
1513 *******************************************************************************/
1514 void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback)
1516 const size_t len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
1517 tBTA_DM_API_ENERGY_INFO *p_msg = (tBTA_DM_API_ENERGY_INFO *)osi_calloc(len);
1519 APPL_TRACE_API("%s", __func__);
1521 p_msg->hdr.event = BTA_DM_API_BLE_ENERGY_INFO_EVT;
1522 p_msg->p_energy_info_cback = p_cmpl_cback;
1524 bta_sys_sendmsg(p_msg);
1527 /*******************************************************************************
1529 ** Function BTA_DmEnableScanFilter
1531 ** Description This function is called to enable the adv data payload filter
1533 ** Parameters action - enable or disable the APCF feature
1534 ** p_cmpl_cback - Command completed callback
1535 ** ref_value - Reference value
1539 *******************************************************************************/
1540 void BTA_DmEnableScanFilter(uint8_t action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback,
1541 tBTA_DM_BLE_REF_VALUE ref_value)
1543 #if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
1544 const size_t len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) +
1545 sizeof(tBLE_BD_ADDR);
1546 tBTA_DM_API_ENABLE_SCAN_FILTER *p_msg =
1547 (tBTA_DM_API_ENABLE_SCAN_FILTER *)osi_calloc(len);
1549 APPL_TRACE_API("%s: %d", __func__, action);
1551 p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_ENABLE_EVT;
1552 p_msg->action = action;
1553 p_msg->ref_value = ref_value;
1554 p_msg->p_filt_status_cback = p_cmpl_cback;
1556 bta_sys_sendmsg(p_msg);
1560 UNUSED(p_cmpl_cback);
1565 /*******************************************************************************
1567 ** Function BTA_DmBleUpdateConnectionParams
1569 ** Description Update connection parameters, can only be used when connection is up.
1571 ** Parameters: bd_addr - BD address of the peer
1572 ** min_int - minimum connection interval, [0x0004~ 0x4000]
1573 ** max_int - maximum connection interval, [0x0004~ 0x4000]
1574 ** latency - slave latency [0 ~ 500]
1575 ** timeout - supervision timeout [0x000a ~ 0xc80]
1579 *******************************************************************************/
1580 void BTA_DmBleUpdateConnectionParams(const BD_ADDR bd_addr, uint16_t min_int, uint16_t max_int,
1581 uint16_t latency, uint16_t timeout)
1583 tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
1584 (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1586 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1587 bdcpy(p_msg->bd_addr, bd_addr);
1588 p_msg->min_int = min_int;
1589 p_msg->max_int = max_int;
1590 p_msg->latency = latency;
1591 p_msg->timeout = timeout;
1593 bta_sys_sendmsg(p_msg);
1596 /*******************************************************************************
1598 ** Function BTA_DmBleSetDataLength
1600 ** Description This function is to set maximum LE data packet size
1605 *******************************************************************************/
1606 void BTA_DmBleSetDataLength(BD_ADDR remote_device, uint16_t tx_data_length)
1608 tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg =
1609 (tBTA_DM_API_BLE_SET_DATA_LENGTH *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH));
1611 bdcpy(p_msg->remote_bda, remote_device);
1612 p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
1613 p_msg->tx_data_length = tx_data_length;
1615 bta_sys_sendmsg(p_msg);
1620 /*******************************************************************************
1622 ** Function BTA_DmSetEncryption
1624 ** Description This function is called to ensure that connection is
1625 ** encrypted. Should be called only on an open connection.
1626 ** Typically only needed for connections that first want to
1627 ** bring up unencrypted links, then later encrypt them.
1629 ** Parameters: bd_addr - Address of the peer device
1630 ** transport - transport of the link to be encruypted
1631 ** p_callback - Pointer to callback function to indicat the
1632 ** link encryption status
1633 ** sec_act - This is the security action to indicate
1634 ** what knid of BLE security level is required for
1635 ** the BLE link if the BLE is supported
1636 ** Note: This parameter is ignored for the BR/EDR link
1637 ** or the BLE is not supported
1641 *******************************************************************************/
1642 void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCRYPT_CBACK *p_callback,
1643 tBTA_DM_BLE_SEC_ACT sec_act)
1645 tBTA_DM_API_SET_ENCRYPTION *p_msg = (tBTA_DM_API_SET_ENCRYPTION *)osi_calloc(sizeof(tBTA_DM_API_SET_ENCRYPTION));
1647 APPL_TRACE_API("%s", __func__);
1649 p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
1650 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
1651 p_msg->transport = transport;
1652 p_msg->p_callback = p_callback;
1653 p_msg->sec_act = sec_act;
1655 bta_sys_sendmsg(p_msg);
1658 /*******************************************************************************
1660 ** Function BTA_DmCloseACL
1662 ** Description This function force to close an ACL connection and remove the
1663 ** device from the security database list of known devices.
1665 ** Parameters: bd_addr - Address of the peer device
1666 ** remove_dev - remove device or not after link down
1670 *******************************************************************************/
1671 void BTA_DmCloseACL(BD_ADDR bd_addr, bool remove_dev, tBTA_TRANSPORT transport)
1673 tBTA_DM_API_REMOVE_ACL *p_msg =
1674 (tBTA_DM_API_REMOVE_ACL *)osi_calloc(sizeof(tBTA_DM_API_REMOVE_ACL));
1676 APPL_TRACE_API("%s", __func__);
1678 p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
1679 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
1680 p_msg->remove_dev = remove_dev;
1681 p_msg->transport = transport;
1683 bta_sys_sendmsg(p_msg);
1686 #if (BLE_INCLUDED == TRUE)
1687 /*******************************************************************************
1689 ** Function BTA_DmBleObserve
1691 ** Description This procedure keep the device listening for advertising
1692 ** events from a broadcast device.
1694 ** Parameters start: start or stop observe.
1701 *******************************************************************************/
1702 extern void BTA_DmBleObserve(bool start, uint8_t duration,
1703 tBTA_DM_SEARCH_CBACK *p_results_cb)
1705 tBTA_DM_API_BLE_OBSERVE *p_msg =
1706 (tBTA_DM_API_BLE_OBSERVE *)osi_calloc(sizeof(tBTA_DM_API_BLE_OBSERVE));
1708 APPL_TRACE_API("%s:start = %d ", __func__, start);
1710 p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
1711 p_msg->start = start;
1712 p_msg->duration = duration;
1713 p_msg->p_cback = p_results_cb;
1715 bta_sys_sendmsg(p_msg);
1718 /*******************************************************************************
1720 ** Function BTA_VendorInit
1722 ** Description This function initializes vendor specific
1726 *******************************************************************************/
1727 void BTA_VendorInit (void)
1729 APPL_TRACE_API("BTA_VendorInit");
1732 /*******************************************************************************
1734 ** Function BTA_VendorCleanup
1736 ** Description This function frees up Broadcom specific VS specific dynamic memory
1740 *******************************************************************************/
1741 void BTA_VendorCleanup (void)
1743 tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
1744 BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
1746 #if (BLE_INCLUDED == TRUE && BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
1747 if (cmn_ble_vsc_cb.max_filter > 0)
1749 btm_ble_adv_filter_cleanup();
1750 #if (BLE_PRIVACY_SPT == TRUE)
1751 btm_ble_resolving_list_cleanup ();
1755 if (cmn_ble_vsc_cb.tot_scan_results_strg > 0)
1756 btm_ble_batchscan_cleanup();
1759 if(cmn_ble_vsc_cb.adv_inst_max > 0)
1760 btm_ble_multi_adv_cleanup();