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_dm_int.h"
29 #include "bta_sys_int.h"
35 /*****************************************************************************
37 *****************************************************************************/
39 static const tBTA_SYS_REG bta_dm_reg =
45 static const tBTA_SYS_REG bta_dm_search_reg =
47 bta_dm_search_sm_execute,
48 bta_dm_search_sm_disable
51 /*******************************************************************************
53 ** Function BTA_EnableBluetooth
55 ** Description Enables bluetooth service. This function must be
56 ** called before any other functions in the BTA API are called.
59 ** Returns tBTA_STATUS
61 *******************************************************************************/
62 tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
64 /* Bluetooth disabling is in progress */
65 if (bta_dm_cb.disabling)
70 bta_sys_register(BTA_ID_DM, &bta_dm_reg );
71 bta_sys_register(BTA_ID_DM_SEARCH, &bta_dm_search_reg );
73 /* if UUID list is not provided as static data */
74 bta_sys_eir_register(bta_dm_eir_update_uuid);
76 tBTA_DM_API_ENABLE *p_msg =
77 (tBTA_DM_API_ENABLE *)osi_malloc(sizeof(tBTA_DM_API_ENABLE));
78 p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
79 p_msg->p_sec_cback = p_cback;
81 bta_sys_sendmsg(p_msg);
86 /*******************************************************************************
88 ** Function BTA_DisableBluetooth
90 ** Description Disables bluetooth service. This function is called when
91 ** the application no longer needs bluetooth service
95 *******************************************************************************/
96 tBTA_STATUS BTA_DisableBluetooth(void)
98 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
100 p_msg->event = BTA_DM_API_DISABLE_EVT;
102 bta_sys_sendmsg(p_msg);
107 /*******************************************************************************
109 ** Function BTA_EnableTestMode
111 ** Description Enables bluetooth device under test mode
114 ** Returns tBTA_STATUS
116 *******************************************************************************/
117 tBTA_STATUS BTA_EnableTestMode(void)
119 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
121 APPL_TRACE_API("%s", __func__);
123 p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
124 bta_sys_sendmsg(p_msg);
129 /*******************************************************************************
131 ** Function BTA_DisableTestMode
133 ** Description Disable bluetooth device under test mode
138 *******************************************************************************/
139 void BTA_DisableTestMode(void)
141 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
143 APPL_TRACE_API("%s", __func__);
145 p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
146 bta_sys_sendmsg(p_msg);
149 /*******************************************************************************
151 ** Function BTA_DmSetDeviceName
153 ** Description This function sets the Bluetooth name of local device
158 *******************************************************************************/
159 void BTA_DmSetDeviceName(char *p_name)
161 tBTA_DM_API_SET_NAME *p_msg =
162 (tBTA_DM_API_SET_NAME *)osi_malloc(sizeof(tBTA_DM_API_SET_NAME));
164 p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
165 strlcpy((char*)p_msg->name, p_name, BD_NAME_LEN);
167 bta_sys_sendmsg(p_msg);
170 /*******************************************************************************
172 ** Function BTA_DmSetVisibility
174 ** Description This function sets the Bluetooth connectable,
175 ** discoverable, pairable and conn paired only modes of local device
180 *******************************************************************************/
181 void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 pairable_mode, UINT8 conn_filter )
183 tBTA_DM_API_SET_VISIBILITY *p_msg =
184 (tBTA_DM_API_SET_VISIBILITY *)osi_malloc(sizeof(tBTA_DM_MSG));
186 p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
187 p_msg->disc_mode = disc_mode;
188 p_msg->conn_mode = conn_mode;
189 p_msg->pair_mode = pairable_mode;
190 p_msg->conn_paired_only = conn_filter;
192 bta_sys_sendmsg(p_msg);
195 /*******************************************************************************
197 ** Function BTA_DmSearch
199 ** Description This function searches for peer Bluetooth devices. It performs
200 ** an inquiry and gets the remote name for devices. Service
201 ** discovery is done if services is non zero
206 *******************************************************************************/
207 void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback)
209 tBTA_DM_API_SEARCH *p_msg =
210 (tBTA_DM_API_SEARCH *)osi_calloc(sizeof(tBTA_DM_API_SEARCH));
212 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
213 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
214 p_msg->services = services;
215 p_msg->p_cback = p_cback;
216 p_msg->rs_res = BTA_DM_RS_NONE;
218 bta_sys_sendmsg(p_msg);
221 /*******************************************************************************
223 ** Function BTA_DmSearchCancel
225 ** Description This function cancels a search initiated by BTA_DmSearch
230 *******************************************************************************/
231 void BTA_DmSearchCancel(void)
233 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
235 p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
236 bta_sys_sendmsg(p_msg);
239 /*******************************************************************************
241 ** Function BTA_DmDiscover
243 ** Description This function does service discovery for services of a
249 *******************************************************************************/
250 void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
251 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
253 tBTA_DM_API_DISCOVER *p_msg =
254 (tBTA_DM_API_DISCOVER *)osi_calloc(sizeof(tBTA_DM_API_DISCOVER));
256 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
257 bdcpy(p_msg->bd_addr, bd_addr);
258 p_msg->services = services;
259 p_msg->p_cback = p_cback;
260 p_msg->sdp_search = sdp_search;
262 bta_sys_sendmsg(p_msg);
265 /*******************************************************************************
267 ** Function BTA_DmDiscoverUUID
269 ** Description This function does service discovery for services of a
275 *******************************************************************************/
276 void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
277 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
279 tBTA_DM_API_DISCOVER *p_msg =
280 (tBTA_DM_API_DISCOVER *)osi_malloc(sizeof(tBTA_DM_API_DISCOVER));
282 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
283 bdcpy(p_msg->bd_addr, bd_addr);
284 p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level
285 p_msg->p_cback = p_cback;
286 p_msg->sdp_search = sdp_search;
288 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
290 p_msg->p_uuid = NULL;
292 memcpy(&p_msg->uuid, uuid, sizeof(tSDP_UUID) );
294 bta_sys_sendmsg(p_msg);
297 /*******************************************************************************
299 ** Function BTA_DmBond
301 ** Description This function initiates a bonding procedure with a peer
307 *******************************************************************************/
308 void BTA_DmBond(BD_ADDR bd_addr)
310 tBTA_DM_API_BOND *p_msg =
311 (tBTA_DM_API_BOND *)osi_malloc(sizeof(tBTA_DM_API_BOND));
313 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
314 bdcpy(p_msg->bd_addr, bd_addr);
315 p_msg->transport = BTA_TRANSPORT_UNKNOWN;
317 bta_sys_sendmsg(p_msg);
320 /*******************************************************************************
322 ** Function BTA_DmBondByTransports
324 ** Description This function initiates a bonding procedure with a peer
330 *******************************************************************************/
331 void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport)
333 tBTA_DM_API_BOND *p_msg =
334 (tBTA_DM_API_BOND *)osi_malloc(sizeof(tBTA_DM_API_BOND));
336 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
337 bdcpy(p_msg->bd_addr, bd_addr);
338 p_msg->transport = transport;
340 bta_sys_sendmsg(p_msg);
343 /*******************************************************************************
345 ** Function BTA_DmBondCancel
347 ** Description This function cancels the bonding procedure with a peer
353 *******************************************************************************/
354 void BTA_DmBondCancel(BD_ADDR bd_addr)
356 tBTA_DM_API_BOND_CANCEL *p_msg =
357 (tBTA_DM_API_BOND_CANCEL *)osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL));
359 p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
360 bdcpy(p_msg->bd_addr, bd_addr);
362 bta_sys_sendmsg(p_msg);
365 /*******************************************************************************
367 ** Function BTA_DmPinReply
369 ** Description This function provides a pincode for a remote device when
370 ** one is requested by DM through BTA_DM_PIN_REQ_EVT
375 *******************************************************************************/
376 void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin)
379 tBTA_DM_API_PIN_REPLY *p_msg =
380 (tBTA_DM_API_PIN_REPLY *)osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY));
382 p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
383 bdcpy(p_msg->bd_addr, bd_addr);
384 p_msg->accept = accept;
386 p_msg->pin_len = pin_len;
387 memcpy(p_msg->p_pin, p_pin, pin_len);
390 bta_sys_sendmsg(p_msg);
393 /*******************************************************************************
395 ** Function BTA_DmLocalOob
397 ** Description This function retrieves the OOB data from local controller.
398 ** The result is reported by:
399 ** - bta_dm_co_loc_oob_ext() if device supports secure
401 ** - bta_dm_co_loc_oob() if device doesn't support SC
405 *******************************************************************************/
406 void BTA_DmLocalOob(void)
408 tBTA_DM_API_LOC_OOB *p_msg =
409 (tBTA_DM_API_LOC_OOB *)osi_malloc(sizeof(tBTA_DM_API_LOC_OOB));
411 p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
412 bta_sys_sendmsg(p_msg);
415 /*******************************************************************************
417 ** Function BTA_DmConfirm
419 ** Description This function accepts or rejects the numerical value of the
420 ** Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
424 *******************************************************************************/
425 void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept)
427 tBTA_DM_API_CONFIRM *p_msg =
428 (tBTA_DM_API_CONFIRM *)osi_malloc(sizeof(tBTA_DM_API_CONFIRM));
430 p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
431 bdcpy(p_msg->bd_addr, bd_addr);
432 p_msg->accept = accept;
434 bta_sys_sendmsg(p_msg);
437 /*******************************************************************************
439 ** Function BTA_DmAddDevice
441 ** Description This function adds a device to the security database list of
447 *******************************************************************************/
448 void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
449 tBTA_SERVICE_MASK trusted_mask, BOOLEAN is_trusted,
450 UINT8 key_type, tBTA_IO_CAP io_cap, UINT8 pin_length)
452 tBTA_DM_API_ADD_DEVICE *p_msg =
453 (tBTA_DM_API_ADD_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_ADD_DEVICE));
455 p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
456 bdcpy(p_msg->bd_addr, bd_addr);
457 p_msg->tm = trusted_mask;
458 p_msg->is_trusted = is_trusted;
459 p_msg->io_cap = io_cap;
462 p_msg->link_key_known = TRUE;
463 p_msg->key_type = key_type;
464 memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
467 /* Load device class if specified */
469 p_msg->dc_known = TRUE;
470 memcpy(p_msg->dc, dev_class, DEV_CLASS_LEN);
473 memset(p_msg->bd_name, 0, BD_NAME_LEN + 1);
474 memset(p_msg->features, 0, sizeof (p_msg->features));
475 p_msg->pin_length = pin_length;
477 bta_sys_sendmsg(p_msg);
480 /*******************************************************************************
482 ** Function BTA_DmRemoveDevice
484 ** Description This function removes a device fromthe security database list of
485 ** peer device. It manages unpairing even while connected.
490 *******************************************************************************/
491 tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
493 tBTA_DM_API_REMOVE_DEVICE *p_msg =
494 (tBTA_DM_API_REMOVE_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_REMOVE_DEVICE));
496 p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
497 bdcpy(p_msg->bd_addr, bd_addr);
499 bta_sys_sendmsg(p_msg);
504 /*******************************************************************************
506 ** Function BTA_GetEirService
508 ** Description This function is called to get BTA service mask from EIR.
510 ** Parameters p_eir - pointer of EIR significant part
511 ** p_services - return the BTA service mask
515 *******************************************************************************/
516 extern const UINT16 bta_service_id_to_uuid_lkup_tbl [];
517 void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services )
520 UINT8 num_uuid, max_num_uuid = 32;
521 UINT8 uuid_list[32*LEN_UUID_16];
522 UINT16 *p_uuid16 = (UINT16 *)uuid_list;
523 tBTA_SERVICE_MASK mask;
525 BTM_GetEirUuidList( p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid);
526 for( xx = 0; xx < num_uuid; xx++ )
529 for( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ )
531 if( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] )
539 /* for HSP v1.2 only device */
540 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS)
541 *p_services |= BTA_HSP_SERVICE_MASK;
543 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE)
544 *p_services |= BTA_HL_SERVICE_MASK;
546 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK)
547 *p_services |= BTA_HL_SERVICE_MASK;
551 /*******************************************************************************
553 ** Function BTA_DmGetConnectionState
555 ** Description Returns whether the remote device is currently connected.
557 ** Returns 0 if the device is NOT connected.
559 *******************************************************************************/
560 UINT16 BTA_DmGetConnectionState( BD_ADDR bd_addr )
562 tBTA_DM_PEER_DEVICE * p_dev = bta_dm_find_peer_device(bd_addr);
563 return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
567 /*******************************************************************************
568 ** Device Identification (DI) Server Functions
569 *******************************************************************************/
570 /*******************************************************************************
572 ** Function BTA_DmSetLocalDiRecord
574 ** Description This function adds a DI record to the local SDP database.
576 ** Returns BTA_SUCCESS if record set sucessfully, otherwise error code.
578 *******************************************************************************/
579 tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
582 tBTA_STATUS status = BTA_FAILURE;
584 if(bta_dm_di_cb.di_num < BTA_DI_NUM_MAX)
586 if(SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS)
588 if(!p_device_info->primary_record)
590 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
591 bta_dm_di_cb.di_num ++;
594 bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
595 status = BTA_SUCCESS;
602 /*******************************************************************************
604 ** Function bta_dmexecutecallback
606 ** Description This function will request BTA to execute a call back in the context of BTU task
607 ** This API was named in lower case because it is only intended
608 ** for the internal customers(like BTIF).
612 *******************************************************************************/
613 void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param)
615 tBTA_DM_API_EXECUTE_CBACK *p_msg =
616 (tBTA_DM_API_EXECUTE_CBACK *)osi_malloc(sizeof(tBTA_DM_MSG));
618 p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
619 p_msg->p_param= p_param;
620 p_msg->p_exec_cback= p_callback;
622 bta_sys_sendmsg(p_msg);
625 /*******************************************************************************
627 ** Function BTA_DmAddBleKey
629 ** Description Add/modify LE device information. This function will be
630 ** normally called during host startup to restore all required
631 ** information stored in the NVRAM.
633 ** Parameters: bd_addr - BD address of the peer
634 ** p_le_key - LE key values.
635 ** key_type - LE SMP key type.
637 ** Returns BTA_SUCCESS if successful
638 ** BTA_FAIL if operation failed.
640 *******************************************************************************/
641 void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_TYPE key_type)
643 #if BLE_INCLUDED == TRUE
645 tBTA_DM_API_ADD_BLEKEY *p_msg =
646 (tBTA_DM_API_ADD_BLEKEY *)osi_calloc(sizeof(tBTA_DM_API_ADD_BLEKEY));
648 p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
649 p_msg->key_type = key_type;
650 bdcpy(p_msg->bd_addr, bd_addr);
651 memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE));
653 bta_sys_sendmsg(p_msg);
657 /*******************************************************************************
659 ** Function BTA_DmAddBleDevice
661 ** Description Add a BLE device. This function will be normally called
662 ** during host startup to restore all required information
663 ** for a LE device stored in the NVRAM.
665 ** Parameters: bd_addr - BD address of the peer
666 ** dev_type - Remote device's device type.
667 ** addr_type - LE device address type.
671 *******************************************************************************/
672 void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TYPE dev_type)
674 #if BLE_INCLUDED == TRUE
675 tBTA_DM_API_ADD_BLE_DEVICE *p_msg =
676 (tBTA_DM_API_ADD_BLE_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
678 p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
679 bdcpy(p_msg->bd_addr, bd_addr);
680 p_msg->addr_type = addr_type;
681 p_msg->dev_type = dev_type;
683 bta_sys_sendmsg(p_msg);
687 /*******************************************************************************
689 ** Function BTA_DmBlePasskeyReply
691 ** Description Send BLE SMP passkey reply.
693 ** Parameters: bd_addr - BD address of the peer
694 ** accept - passkey entry sucessful or declined.
695 ** passkey - passkey value, must be a 6 digit number,
700 *******************************************************************************/
701 void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey)
703 #if BLE_INCLUDED == TRUE
704 tBTA_DM_API_PASSKEY_REPLY *p_msg =
705 (tBTA_DM_API_PASSKEY_REPLY *)osi_calloc(sizeof(tBTA_DM_API_PASSKEY_REPLY));
707 p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
708 bdcpy(p_msg->bd_addr, bd_addr);
709 p_msg->accept = accept;
712 p_msg->passkey = passkey;
714 bta_sys_sendmsg(p_msg);
718 /*******************************************************************************
720 ** Function BTA_DmBleConfirmReply
722 ** Description Send BLE SMP SC user confirmation reply.
724 ** Parameters: bd_addr - BD address of the peer
725 ** accept - numbers to compare are the same or different.
729 *******************************************************************************/
730 void BTA_DmBleConfirmReply(BD_ADDR bd_addr, BOOLEAN accept)
732 #if BLE_INCLUDED == TRUE
733 tBTA_DM_API_CONFIRM *p_msg =
734 (tBTA_DM_API_CONFIRM *)osi_calloc(sizeof(tBTA_DM_API_CONFIRM));
736 p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT;
737 bdcpy(p_msg->bd_addr, bd_addr);
738 p_msg->accept = accept;
740 bta_sys_sendmsg(p_msg);
744 /*******************************************************************************
746 ** Function BTA_DmBleSecurityGrant
748 ** Description Grant security request access.
750 ** Parameters: bd_addr - BD address of the peer
751 ** res - security grant status.
755 *******************************************************************************/
756 void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
758 #if BLE_INCLUDED == TRUE
759 tBTA_DM_API_BLE_SEC_GRANT *p_msg =
760 (tBTA_DM_API_BLE_SEC_GRANT *)osi_calloc(sizeof(tBTA_DM_API_BLE_SEC_GRANT));
762 p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
763 bdcpy(p_msg->bd_addr, bd_addr);
766 bta_sys_sendmsg(p_msg);
770 /*******************************************************************************
772 ** Function BTA_DmSetBlePrefConnParams
774 ** Description This function is called to set the preferred connection
775 ** parameters when default connection parameter is not desired.
777 ** Parameters: bd_addr - BD address of the peripheral
778 ** scan_interval - scan interval
779 ** scan_window - scan window
780 ** min_conn_int - minimum preferred connection interval
781 ** max_conn_int - maximum preferred connection interval
782 ** slave_latency - preferred slave latency
783 ** supervision_tout - preferred supervision timeout
788 *******************************************************************************/
789 void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,
790 UINT16 min_conn_int, UINT16 max_conn_int,
791 UINT16 slave_latency, UINT16 supervision_tout )
793 #if BLE_INCLUDED == TRUE
794 tBTA_DM_API_BLE_CONN_PARAMS *p_msg =
795 (tBTA_DM_API_BLE_CONN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
797 p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
798 memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN);
799 p_msg->conn_int_max = max_conn_int;
800 p_msg->conn_int_min = min_conn_int;
801 p_msg->slave_latency = slave_latency;
802 p_msg->supervision_tout = supervision_tout;
804 bta_sys_sendmsg(p_msg);
808 /*******************************************************************************
810 ** Function BTA_DmSetBleConnScanParams
812 ** Description This function is called to set scan parameters used in
813 ** BLE connection request
815 ** Parameters: scan_interval - scan interval
816 ** scan_window - scan window
820 *******************************************************************************/
821 void BTA_DmSetBleConnScanParams(UINT32 scan_interval, UINT32 scan_window)
823 #if BLE_INCLUDED == TRUE
824 tBTA_DM_API_BLE_SCAN_PARAMS *p_msg =
825 (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
827 p_msg->hdr.event = BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT;
828 p_msg->scan_int = scan_interval;
829 p_msg->scan_window = scan_window;
831 bta_sys_sendmsg(p_msg);
832 #endif // BLE_INCLUDED == TRUE
835 /*******************************************************************************
837 ** Function BTA_DmSetBleScanParams
839 ** Description This function is called to set scan parameters
841 ** Parameters: client_if - Client IF
842 ** scan_interval - scan interval
843 ** scan_window - scan window
844 ** scan_mode - scan mode
845 ** scan_param_setup_status_cback - Set scan param status callback
849 *******************************************************************************/
851 #if BLE_INCLUDED == TRUE
852 void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval,
853 UINT32 scan_window, tBLE_SCAN_MODE scan_mode,
854 tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
856 tBTA_DM_API_BLE_SCAN_PARAMS *p_msg =
857 (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
859 p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT;
860 p_msg->client_if = client_if;
861 p_msg->scan_int = scan_interval;
862 p_msg->scan_window = scan_window;
863 p_msg->scan_mode = scan_mode;
864 p_msg->scan_param_setup_cback = scan_param_setup_cback;
866 bta_sys_sendmsg(p_msg);
868 #endif // BLE_INCLUDED == TRUE
870 /*******************************************************************************
872 ** Function BTA_DmSetBleAdvParams
874 ** Description This function sets the advertising parameters BLE functionality.
875 ** It is to be called when device act in peripheral or broadcaster
881 *******************************************************************************/
882 void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
883 tBLE_BD_ADDR *p_dir_bda)
885 #if BLE_INCLUDED == TRUE
886 tBTA_DM_API_BLE_ADV_PARAMS *p_msg =
887 (tBTA_DM_API_BLE_ADV_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_ADV_PARAMS));
889 APPL_TRACE_API("BTA_DmSetBleAdvParam: %d, %d", adv_int_min, adv_int_max);
891 p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_EVT;
892 p_msg->adv_int_min = adv_int_min;
893 p_msg->adv_int_max = adv_int_max;
895 if (p_dir_bda != NULL) {
896 p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
897 memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
900 bta_sys_sendmsg(p_msg);
904 /*******************************************************************************
905 ** BLE ADV data management API
906 ********************************************************************************/
908 #if BLE_INCLUDED == TRUE
909 /*******************************************************************************
911 ** Function BTA_DmBleSetAdvConfig
913 ** Description This function is called to override the BTA default ADV parameters.
915 ** Parameters data_mask: adv data mask.
916 ** p_adv_cfg: Pointer to User defined ADV data structure. This
917 ** memory space can not be freed until p_adv_data_cback
919 ** p_adv_data_cback: set adv data complete callback.
923 *******************************************************************************/
924 void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
925 tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
927 tBTA_DM_API_SET_ADV_CONFIG *p_msg = osi_calloc(sizeof(*p_msg));
929 p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_EVT;
930 p_msg->data_mask = data_mask;
931 p_msg->p_adv_data_cback = p_adv_data_cback;
932 memcpy(&p_msg->adv_cfg, p_adv_cfg, sizeof(p_msg->adv_cfg));
934 bta_sys_sendmsg(p_msg);
937 /*******************************************************************************
939 ** Function BTA_DmBleSetScanRsp
941 ** Description This function is called to override the BTA scan response.
943 ** Parameters Pointer to User defined ADV data structure
947 *******************************************************************************/
948 extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
949 tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
951 tBTA_DM_API_SET_ADV_CONFIG *p_msg = osi_calloc(sizeof(*p_msg));
953 p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_EVT;
954 p_msg->data_mask = data_mask;
955 p_msg->p_adv_data_cback = p_adv_data_cback;
956 memcpy(&p_msg->adv_cfg, p_adv_cfg, sizeof(p_msg->adv_cfg));
958 bta_sys_sendmsg(p_msg);
961 /*******************************************************************************
963 ** Function BTA_DmBleSetStorageParams
965 ** Description This function is called to override the BTA scan response.
967 ** Parameters batch_scan_full_max -Max storage space (in %) allocated to full scanning
968 ** batch_scan_trunc_max -Max storage space (in %) allocated to truncated scanning
969 ** batch_scan_notify_threshold -Setup notification level based on total space
970 ** p_setup_cback - Setup callback pointer
971 ** p_thres_cback - Threshold callback pointer
972 ** p_rep_cback - Reports callback pointer
973 ** ref_value - Ref value
977 *******************************************************************************/
978 extern void BTA_DmBleSetStorageParams(UINT8 batch_scan_full_max,
979 UINT8 batch_scan_trunc_max,
980 UINT8 batch_scan_notify_threshold,
981 tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback,
982 tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback,
983 tBTA_BLE_SCAN_REP_CBACK* p_rep_cback,
984 tBTA_DM_BLE_REF_VALUE ref_value)
986 tBTA_DM_API_SET_STORAGE_CONFIG *p_msg =
987 (tBTA_DM_API_SET_STORAGE_CONFIG *)osi_malloc(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG));
989 bta_dm_cb.p_setup_cback = p_setup_cback;
991 p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT;
992 p_msg->p_setup_cback=bta_ble_scan_setup_cb;
993 p_msg->p_thres_cback=p_thres_cback;
994 p_msg->p_read_rep_cback=p_rep_cback;
995 p_msg->ref_value = ref_value;
996 p_msg->batch_scan_full_max = batch_scan_full_max;
997 p_msg->batch_scan_trunc_max = batch_scan_trunc_max;
998 p_msg->batch_scan_notify_threshold = batch_scan_notify_threshold;
1000 bta_sys_sendmsg(p_msg);
1003 /*******************************************************************************
1005 ** Function BTA_DmBleEnableBatchScan
1007 ** Description This function is called to enable the batch scan
1009 ** Parameters scan_mode -Batch scan mode
1010 ** scan_interval - Scan interval
1011 ** scan_window - Scan window
1012 ** discard_rule -Discard rules
1013 ** addr_type - Address type
1014 ** ref_value - Reference value
1018 *******************************************************************************/
1019 extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode,
1020 UINT32 scan_interval, UINT32 scan_window,
1021 tBTA_BLE_DISCARD_RULE discard_rule,
1022 tBLE_ADDR_TYPE addr_type,
1023 tBTA_DM_BLE_REF_VALUE ref_value)
1025 tBTA_DM_API_ENABLE_SCAN *p_msg =
1026 (tBTA_DM_API_ENABLE_SCAN *)osi_malloc(sizeof(tBTA_DM_API_ENABLE_SCAN));
1028 p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT;
1029 p_msg->scan_mode = scan_mode;
1030 p_msg->scan_int = scan_interval;
1031 p_msg->scan_window = scan_window;
1032 p_msg->discard_rule = discard_rule;
1033 p_msg->addr_type = addr_type;
1034 p_msg->ref_value = ref_value;
1036 bta_sys_sendmsg(p_msg);
1039 /*******************************************************************************
1041 ** Function BTA_DmBleDisableBatchScan
1043 ** Description This function is called to disable the batch scan
1045 ** Parameters ref_value - Reference value
1049 *******************************************************************************/
1050 extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)
1052 tBTA_DM_API_DISABLE_SCAN *p_msg =
1053 (tBTA_DM_API_DISABLE_SCAN *)osi_malloc(sizeof(tBTA_DM_API_DISABLE_SCAN));
1055 p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT;
1056 p_msg->ref_value = ref_value;
1058 bta_sys_sendmsg(p_msg);
1061 /*******************************************************************************
1063 ** Function BTA_DmBleReadScanReports
1065 ** Description This function is called to read scan reports
1067 ** Parameters scan_type -Batch scan mode
1068 ** ref_value - Reference value
1072 *******************************************************************************/
1073 extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type,
1074 tBTA_DM_BLE_REF_VALUE ref_value)
1076 tBTA_DM_API_READ_SCAN_REPORTS *p_msg =
1077 (tBTA_DM_API_READ_SCAN_REPORTS *)osi_malloc(sizeof(tBTA_DM_API_READ_SCAN_REPORTS));
1079 p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT;
1080 p_msg->scan_type = scan_type;
1081 p_msg->ref_value = ref_value;
1083 bta_sys_sendmsg(p_msg);
1086 /*******************************************************************************
1088 ** Function BTA_DmBleTrackAdvertiser
1090 ** Description This function is called to track advertiser
1092 ** Parameters ref_value - Reference value
1093 ** p_track_adv_cback - Track ADV callback
1097 *******************************************************************************/
1098 extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
1099 tBTA_BLE_TRACK_ADV_CBACK *p_track_adv_cback)
1101 tBTA_DM_API_TRACK_ADVERTISER *p_msg =
1102 (tBTA_DM_API_TRACK_ADVERTISER *)osi_malloc(sizeof(tBTA_DM_API_TRACK_ADVERTISER));
1104 p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT;
1105 p_msg->p_track_adv_cback = p_track_adv_cback;
1106 p_msg->ref_value = ref_value;
1108 bta_sys_sendmsg(p_msg);
1113 /*******************************************************************************
1114 ** BLE ADV data management API
1115 ********************************************************************************/
1116 #if BLE_INCLUDED == TRUE
1118 /*******************************************************************************
1120 ** Function BTA_DmBleBroadcast
1122 ** Description This function starts or stops LE broadcasting.
1124 ** Parameters start: start or stop broadcast.
1128 *******************************************************************************/
1129 extern void BTA_DmBleBroadcast (BOOLEAN start)
1131 tBTA_DM_API_BLE_OBSERVE *p_msg =
1132 (tBTA_DM_API_BLE_OBSERVE *)osi_calloc(sizeof(tBTA_DM_API_BLE_OBSERVE));
1134 APPL_TRACE_API("BTA_DmBleBroadcast: start = %d ", start);
1136 p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
1137 p_msg->start = start;
1139 bta_sys_sendmsg(p_msg);
1143 /*******************************************************************************
1145 ** Function BTA_DmBleSetBgConnType
1147 ** Description This function is called to set BLE connectable mode for a
1148 ** peripheral device.
1150 ** Parameters bg_conn_type: it can be auto connection, or selective connection.
1151 ** p_select_cback: callback function when selective connection procedure
1156 *******************************************************************************/
1157 void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback)
1159 #if BLE_INCLUDED == TRUE
1160 tBTA_DM_API_BLE_SET_BG_CONN_TYPE *p_msg =
1161 (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *)osi_calloc(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
1163 p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
1164 p_msg->bg_conn_type = bg_conn_type;
1165 p_msg->p_select_cback = p_select_cback;
1167 bta_sys_sendmsg(p_msg);
1171 /*******************************************************************************
1173 ** Function bta_dm_discover_send_msg
1175 ** Description This function send discover message to BTA task.
1179 *******************************************************************************/
1180 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1181 static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1182 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
1183 tBTA_TRANSPORT transport)
1185 const size_t len = p_services ?
1186 (sizeof(tBTA_DM_API_DISCOVER) + sizeof(tBT_UUID) * p_services->num_uuid)
1187 : sizeof(tBTA_DM_API_DISCOVER);
1188 tBTA_DM_API_DISCOVER *p_msg = (tBTA_DM_API_DISCOVER *)osi_calloc(len);
1190 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
1191 bdcpy(p_msg->bd_addr, bd_addr);
1192 p_msg->p_cback = p_cback;
1193 p_msg->sdp_search = sdp_search;
1194 p_msg->transport = transport;
1196 if (p_services != NULL) {
1197 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1198 p_msg->services = p_services->srvc_mask;
1199 p_msg->num_uuid = p_services->num_uuid;
1200 if (p_services->num_uuid != 0) {
1201 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1202 memcpy(p_msg->p_uuid, p_services->p_uuid,
1203 sizeof(tBT_UUID) * p_services->num_uuid);
1208 bta_sys_sendmsg(p_msg);
1212 /*******************************************************************************
1214 ** Function BTA_DmDiscoverByTransport
1216 ** Description This function does service discovery on particular transport
1217 ** for services of a
1218 ** peer device. When services.num_uuid is 0, it indicates all
1219 ** GATT based services are to be searched; otherwise a list of
1220 ** UUID of interested services should be provided through
1221 ** p_services->p_uuid.
1227 *******************************************************************************/
1228 void BTA_DmDiscoverByTransport(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1229 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
1230 tBTA_TRANSPORT transport)
1232 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1233 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
1238 /*******************************************************************************
1240 ** Function BTA_DmDiscoverExt
1242 ** Description This function does service discovery for services of a
1243 ** peer device. When services.num_uuid is 0, it indicates all
1244 ** GATT based services are to be searched; other wise a list of
1245 ** UUID of interested services should be provided through
1246 ** p_services->p_uuid.
1252 *******************************************************************************/
1253 void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1254 tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
1256 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1257 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, BTA_TRANSPORT_UNKNOWN);
1262 /*******************************************************************************
1264 ** Function BTA_DmSearchExt
1266 ** Description This function searches for peer Bluetooth devices. It performs
1267 ** an inquiry and gets the remote name for devices. Service
1268 ** discovery is done if services is non zero
1270 ** Parameters p_dm_inq: inquiry conditions
1271 ** p_services: if service is not empty, service discovery will be done.
1272 ** for all GATT based service condition, put num_uuid, and
1273 ** p_uuid is the pointer to the list of UUID values.
1274 ** p_cback: callback functino when search is completed.
1280 *******************************************************************************/
1281 void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback)
1283 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1284 const size_t len = p_services ?
1285 (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid)
1286 : sizeof(tBTA_DM_API_SEARCH);
1287 tBTA_DM_API_SEARCH *p_msg = (tBTA_DM_API_SEARCH *)osi_calloc(len);
1289 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
1290 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
1291 p_msg->p_cback = p_cback;
1292 p_msg->rs_res = BTA_DM_RS_NONE;
1294 if (p_services != NULL) {
1295 p_msg->services = p_services->srvc_mask;
1296 p_msg->num_uuid = p_services->num_uuid;
1298 if (p_services->num_uuid != 0) {
1299 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1300 memcpy(p_msg->p_uuid, p_services->p_uuid,
1301 sizeof(tBT_UUID) * p_services->num_uuid);
1303 p_msg->p_uuid = NULL;
1307 bta_sys_sendmsg(p_msg);
1314 /*******************************************************************************
1316 ** Function BTA_DmBleUpdateConnectionParam
1318 ** Description Update connection parameters, can only be used when connection is up.
1320 ** Parameters: bd_addr - BD address of the peer
1321 ** min_int - minimum connection interval, [0x0004~ 0x4000]
1322 ** max_int - maximum connection interval, [0x0004~ 0x4000]
1323 ** latency - slave latency [0 ~ 500]
1324 ** timeout - supervision timeout [0x000a ~ 0xc80]
1328 *******************************************************************************/
1329 void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
1330 UINT16 max_int, UINT16 latency,
1333 #if BLE_INCLUDED == TRUE
1334 tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
1335 (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1337 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1338 bdcpy(p_msg->bd_addr, bd_addr);
1339 p_msg->min_int = min_int;
1340 p_msg->max_int = max_int;
1341 p_msg->latency = latency;
1342 p_msg->timeout = timeout;
1344 bta_sys_sendmsg(p_msg);
1348 /*******************************************************************************
1350 ** Function BTA_DmBleConfigLocalPrivacy
1352 ** Description Enable/disable privacy on the local device
1354 ** Parameters: privacy_enable - enable/disabe privacy on remote device.
1358 *******************************************************************************/
1359 void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable)
1361 #if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE
1362 tBTA_DM_API_LOCAL_PRIVACY *p_msg =
1363 (tBTA_DM_API_LOCAL_PRIVACY *)osi_calloc(sizeof(tBTA_DM_API_ENABLE_PRIVACY));
1365 p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
1366 p_msg->privacy_enable = privacy_enable;
1368 bta_sys_sendmsg(p_msg);
1370 UNUSED (privacy_enable);
1374 #if BLE_INCLUDED == TRUE
1375 /*******************************************************************************
1377 ** Function BTA_BleEnableAdvInstance
1379 ** Description This function enable a Multi-ADV instance with the specififed
1382 ** Parameters p_params: pointer to the adv parameter structure.
1383 ** p_cback: callback function associated to this adv instance.
1384 ** p_ref: reference data pointer to this adv instance.
1386 ** Returns BTA_SUCCESS if command started sucessfully; otherwise failure.
1388 *******************************************************************************/
1389 void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
1390 tBTA_BLE_MULTI_ADV_CBACK *p_cback,
1393 const size_t len = sizeof(tBTA_BLE_ADV_PARAMS) +
1394 sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB);
1395 tBTA_DM_API_BLE_MULTI_ADV_ENB *p_msg =
1396 (tBTA_DM_API_BLE_MULTI_ADV_ENB *)osi_calloc(len);
1398 APPL_TRACE_API("%s", __func__);
1400 p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_ENB_EVT;
1401 p_msg->p_cback = (void *)p_cback;
1402 if (p_params != NULL) {
1403 p_msg->p_params = (void *)(p_msg + 1);
1404 memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
1406 p_msg->p_ref = p_ref;
1408 bta_sys_sendmsg(p_msg);
1411 /*******************************************************************************
1413 ** Function BTA_BleUpdateAdvInstParam
1415 ** Description This function update a Multi-ADV instance with the specififed
1418 ** Parameters inst_id: Adv instance to update the parameter.
1419 ** p_params: pointer to the adv parameter structure.
1421 ** Returns BTA_SUCCESS if command started sucessfully; otherwise failure.
1423 *******************************************************************************/
1424 void BTA_BleUpdateAdvInstParam (UINT8 inst_id, tBTA_BLE_ADV_PARAMS *p_params)
1426 const size_t len = sizeof(tBTA_BLE_ADV_PARAMS) +
1427 sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM);
1428 tBTA_DM_API_BLE_MULTI_ADV_PARAM *p_msg =
1429 (tBTA_DM_API_BLE_MULTI_ADV_PARAM *)osi_calloc(len);
1431 APPL_TRACE_API("%s", __func__);
1433 p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT;
1434 p_msg->inst_id = inst_id;
1435 p_msg->p_params = (void *)(p_msg + 1);
1436 memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
1438 bta_sys_sendmsg(p_msg);
1441 /*******************************************************************************
1443 ** Function BTA_BleCfgAdvInstData
1445 ** Description This function configure a Multi-ADV instance with the specififed
1446 ** adv data or scan response data.
1448 ** Parameter inst_id: Adv instance to configure the adv data or scan response.
1449 ** is_scan_rsp: is the data scan response or adv data.
1450 ** data_mask: adv data type as bit mask.
1451 ** p_data: pointer to the ADV data structure tBTA_BLE_ADV_DATA. This
1452 ** memory space can not be freed until BTA_BLE_MULTI_ADV_DATA_EVT
1453 ** is sent to application.
1455 ** Returns BTA_SUCCESS if command started sucessfully; otherwise failure.
1457 *******************************************************************************/
1458 void BTA_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp,
1459 tBTA_BLE_AD_MASK data_mask,
1460 tBTA_BLE_ADV_DATA *p_data)
1462 tBTA_DM_API_BLE_MULTI_ADV_DATA *p_msg = osi_calloc(sizeof(*p_msg));
1464 p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_DATA_EVT;
1465 p_msg->inst_id = inst_id;
1466 p_msg->is_scan_rsp = is_scan_rsp;
1467 p_msg->data_mask = data_mask;
1468 memcpy(&p_msg->data, p_data, sizeof(p_msg->data));
1470 bta_sys_sendmsg(p_msg);
1473 /*******************************************************************************
1475 ** Function BTA_BleDisableAdvInstance
1477 ** Description This function disable a Multi-ADV instance.
1479 ** Parameter inst_id: instance ID to disable.
1481 ** Returns BTA_SUCCESS if command started sucessfully; otherwise failure.
1483 *******************************************************************************/
1484 void BTA_BleDisableAdvInstance(UINT8 inst_id)
1486 tBTA_DM_API_BLE_MULTI_ADV_DISABLE *p_msg =
1487 (tBTA_DM_API_BLE_MULTI_ADV_DISABLE *)osi_calloc(sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE));
1489 APPL_TRACE_API("%s: %d", __func__, inst_id);
1491 p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT;
1492 p_msg->inst_id = inst_id;
1494 bta_sys_sendmsg(p_msg);
1497 /*******************************************************************************
1499 ** Function BTA_DmBleCfgFilterCondition
1501 ** Description This function is called to configure the adv data payload filter
1504 ** Parameters action: to read/write/clear
1505 ** cond_type: filter condition type
1506 ** filt_index - Filter index
1507 ** p_cond: filter condition parameter
1508 ** p_cmpl_back - Command completed callback
1509 ** ref_value - Reference value
1513 *******************************************************************************/
1514 void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
1515 tBTA_DM_BLE_PF_COND_TYPE cond_type,
1516 tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1517 tBTA_DM_BLE_PF_COND_PARAM *p_cond,
1518 tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback,
1519 tBTA_DM_BLE_REF_VALUE ref_value)
1521 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
1522 tBTA_DM_API_CFG_FILTER_COND *p_msg;
1523 APPL_TRACE_API ("BTA_DmBleCfgFilterCondition: %d, %d", action, cond_type);
1525 UINT16 len = sizeof(tBTA_DM_API_CFG_FILTER_COND) +
1526 sizeof(tBTA_DM_BLE_PF_COND_PARAM);
1533 case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:
1534 case BTA_DM_BLE_PF_MANU_DATA:
1535 /* Length of pattern and pattern mask and other elements in */
1536 /* tBTA_DM_BLE_PF_MANU_COND */
1537 len += ((p_cond->manu_data.data_len) * 2) +
1538 sizeof(UINT16) + sizeof(UINT16) + sizeof(UINT8);
1541 case BTA_DM_BLE_PF_LOCAL_NAME:
1542 len += ((p_cond->local_name.data_len) + sizeof(UINT8));
1545 case BTM_BLE_PF_SRVC_UUID:
1546 case BTM_BLE_PF_SRVC_SOL_UUID:
1547 len += sizeof(tBLE_BD_ADDR) + sizeof(tBTA_DM_BLE_PF_COND_MASK);
1555 p_msg = (tBTA_DM_API_CFG_FILTER_COND *)osi_calloc(len);
1556 p_msg->hdr.event = BTA_DM_API_CFG_FILTER_COND_EVT;
1557 p_msg->action = action;
1558 p_msg->cond_type = cond_type;
1559 p_msg->filt_index = filt_index;
1560 p_msg->p_filt_cfg_cback = p_cmpl_cback;
1561 p_msg->ref_value = ref_value;
1563 p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM *)(p_msg + 1);
1564 memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
1566 p = (UINT8 *)(p_msg->p_cond_param + 1);
1568 if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN ||
1569 cond_type == BTA_DM_BLE_PF_MANU_DATA) {
1570 p_msg->p_cond_param->manu_data.p_pattern = p;
1571 p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len;
1572 memcpy(p_msg->p_cond_param->manu_data.p_pattern, p_cond->manu_data.p_pattern,
1573 p_cond->manu_data.data_len);
1574 p += p_cond->manu_data.data_len;
1576 if (cond_type == BTA_DM_BLE_PF_MANU_DATA) {
1577 p_msg->p_cond_param->manu_data.company_id_mask =
1578 p_cond->manu_data.company_id_mask;
1579 if ( p_cond->manu_data.p_pattern_mask != NULL) {
1580 p_msg->p_cond_param->manu_data.p_pattern_mask = p;
1581 memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask,
1582 p_cond->manu_data.p_pattern_mask,
1583 p_cond->manu_data.data_len);
1586 } else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME) {
1587 p_msg->p_cond_param->local_name.p_data = p;
1588 p_msg->p_cond_param->local_name.data_len =
1589 p_cond->local_name.data_len;
1590 memcpy(p_msg->p_cond_param->local_name.p_data,
1591 p_cond->local_name.p_data, p_cond->local_name.data_len);
1592 } else if (cond_type == BTM_BLE_PF_SRVC_UUID ||
1593 cond_type == BTM_BLE_PF_SRVC_SOL_UUID) {
1594 if (p_cond->srvc_uuid.p_target_addr != NULL) {
1595 p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR *)(p);
1596 p_msg->p_cond_param->srvc_uuid.p_target_addr->type =
1597 p_cond->srvc_uuid.p_target_addr->type;
1598 memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda,
1599 p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN);
1600 p = (UINT8 *)(p_msg->p_cond_param->srvc_uuid.p_target_addr + 1);
1602 if (p_cond->srvc_uuid.p_uuid_mask) {
1603 p_msg->p_cond_param->srvc_uuid.p_uuid_mask = (tBTA_DM_BLE_PF_COND_MASK *)p;
1604 memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask,
1605 p_cond->srvc_uuid.p_uuid_mask,
1606 sizeof(tBTA_DM_BLE_PF_COND_MASK));
1611 bta_sys_sendmsg(p_msg);
1618 UNUSED(p_cmpl_cback);
1623 /*******************************************************************************
1625 ** Function BTA_DmBleScanFilterSetup
1627 ** Description This function is called to setup the adv data payload filter param
1629 ** Parameters p_target: enable the filter condition on a target device; if NULL
1630 ** filt_index - Filter index
1631 ** p_filt_params -Filter parameters
1632 ** ref_value - Reference value
1633 ** action - Add, delete or clear
1634 ** p_cmpl_back - Command completed callback
1638 *******************************************************************************/
1639 void BTA_DmBleScanFilterSetup(UINT8 action,
1640 tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1641 tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params,
1642 tBLE_BD_ADDR *p_target,
1643 tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback,
1644 tBTA_DM_BLE_REF_VALUE ref_value)
1646 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
1647 const size_t len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) +
1648 sizeof(tBLE_BD_ADDR);
1649 tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *p_msg =
1650 (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *)osi_calloc(len);
1652 APPL_TRACE_API("%s: %d", __func__, action);
1654 p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_SETUP_EVT;
1655 p_msg->action = action;
1656 p_msg->filt_index = filt_index;
1657 if (p_filt_params) {
1658 memcpy(&p_msg->filt_params, p_filt_params,
1659 sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1661 p_msg->p_filt_param_cback = p_cmpl_cback;
1662 p_msg->ref_value = ref_value;
1665 p_msg->p_target = (tBLE_BD_ADDR *)(p_msg + 1);
1666 memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR));
1669 bta_sys_sendmsg(p_msg);
1674 UNUSED(p_filt_params);
1676 UNUSED(p_cmpl_cback);
1681 /*******************************************************************************
1683 ** Function BTA_DmBleGetEnergyInfo
1685 ** Description This function is called to obtain the energy info
1687 ** Parameters p_cmpl_cback - Command complete callback
1691 *******************************************************************************/
1692 void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback)
1694 const size_t len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
1695 tBTA_DM_API_ENERGY_INFO *p_msg = (tBTA_DM_API_ENERGY_INFO *)osi_calloc(len);
1697 APPL_TRACE_API("%s", __func__);
1699 p_msg->hdr.event = BTA_DM_API_BLE_ENERGY_INFO_EVT;
1700 p_msg->p_energy_info_cback = p_cmpl_cback;
1702 bta_sys_sendmsg(p_msg);
1705 /*******************************************************************************
1707 ** Function BTA_DmEnableScanFilter
1709 ** Description This function is called to enable the adv data payload filter
1711 ** Parameters action - enable or disable the APCF feature
1712 ** p_cmpl_cback - Command completed callback
1713 ** ref_value - Reference value
1717 *******************************************************************************/
1718 void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback,
1719 tBTA_DM_BLE_REF_VALUE ref_value)
1721 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
1722 const size_t len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) +
1723 sizeof(tBLE_BD_ADDR);
1724 tBTA_DM_API_ENABLE_SCAN_FILTER *p_msg =
1725 (tBTA_DM_API_ENABLE_SCAN_FILTER *)osi_calloc(len);
1727 APPL_TRACE_API("%s: %d", __func__, action);
1729 p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_ENABLE_EVT;
1730 p_msg->action = action;
1731 p_msg->ref_value = ref_value;
1732 p_msg->p_filt_status_cback = p_cmpl_cback;
1734 bta_sys_sendmsg(p_msg);
1738 UNUSED(p_cmpl_cback);
1743 /*******************************************************************************
1745 ** Function BTA_DmBleUpdateConnectionParams
1747 ** Description Update connection parameters, can only be used when connection is up.
1749 ** Parameters: bd_addr - BD address of the peer
1750 ** min_int - minimum connection interval, [0x0004~ 0x4000]
1751 ** max_int - maximum connection interval, [0x0004~ 0x4000]
1752 ** latency - slave latency [0 ~ 500]
1753 ** timeout - supervision timeout [0x000a ~ 0xc80]
1757 *******************************************************************************/
1758 void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max_int,
1759 UINT16 latency, UINT16 timeout)
1761 tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
1762 (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1764 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1765 bdcpy(p_msg->bd_addr, bd_addr);
1766 p_msg->min_int = min_int;
1767 p_msg->max_int = max_int;
1768 p_msg->latency = latency;
1769 p_msg->timeout = timeout;
1771 bta_sys_sendmsg(p_msg);
1774 /*******************************************************************************
1776 ** Function BTA_DmBleSetDataLength
1778 ** Description This function is to set maximum LE data packet size
1783 *******************************************************************************/
1784 void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length)
1786 tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg =
1787 (tBTA_DM_API_BLE_SET_DATA_LENGTH *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH));
1789 bdcpy(p_msg->remote_bda, remote_device);
1790 p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
1791 p_msg->tx_data_length = tx_data_length;
1793 bta_sys_sendmsg(p_msg);
1798 /*******************************************************************************
1800 ** Function BTA_DmSetEncryption
1802 ** Description This function is called to ensure that connection is
1803 ** encrypted. Should be called only on an open connection.
1804 ** Typically only needed for connections that first want to
1805 ** bring up unencrypted links, then later encrypt them.
1807 ** Parameters: bd_addr - Address of the peer device
1808 ** transport - transport of the link to be encruypted
1809 ** p_callback - Pointer to callback function to indicat the
1810 ** link encryption status
1811 ** sec_act - This is the security action to indicate
1812 ** what knid of BLE security level is required for
1813 ** the BLE link if the BLE is supported
1814 ** Note: This parameter is ignored for the BR/EDR link
1815 ** or the BLE is not supported
1819 *******************************************************************************/
1820 void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCRYPT_CBACK *p_callback,
1821 tBTA_DM_BLE_SEC_ACT sec_act)
1823 tBTA_DM_API_SET_ENCRYPTION *p_msg = (tBTA_DM_API_SET_ENCRYPTION *)osi_calloc(sizeof(tBTA_DM_API_SET_ENCRYPTION));
1825 APPL_TRACE_API("%s", __func__);
1827 p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
1828 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
1829 p_msg->transport = transport;
1830 p_msg->p_callback = p_callback;
1831 p_msg->sec_act = sec_act;
1833 bta_sys_sendmsg(p_msg);
1836 /*******************************************************************************
1838 ** Function BTA_DmCloseACL
1840 ** Description This function force to close an ACL connection and remove the
1841 ** device from the security database list of known devices.
1843 ** Parameters: bd_addr - Address of the peer device
1844 ** remove_dev - remove device or not after link down
1848 *******************************************************************************/
1849 void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT transport)
1851 tBTA_DM_API_REMOVE_ACL *p_msg =
1852 (tBTA_DM_API_REMOVE_ACL *)osi_calloc(sizeof(tBTA_DM_API_REMOVE_ACL));
1854 APPL_TRACE_API("%s", __func__);
1856 p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
1857 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
1858 p_msg->remove_dev = remove_dev;
1859 p_msg->transport = transport;
1861 bta_sys_sendmsg(p_msg);
1864 #if BLE_INCLUDED == TRUE
1865 /*******************************************************************************
1867 ** Function BTA_DmBleObserve
1869 ** Description This procedure keep the device listening for advertising
1870 ** events from a broadcast device.
1872 ** Parameters start: start or stop observe.
1879 *******************************************************************************/
1880 extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
1881 tBTA_DM_SEARCH_CBACK *p_results_cb)
1883 tBTA_DM_API_BLE_OBSERVE *p_msg =
1884 (tBTA_DM_API_BLE_OBSERVE *)osi_calloc(sizeof(tBTA_DM_API_BLE_OBSERVE));
1886 APPL_TRACE_API("%s:start = %d ", __func__, start);
1888 p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
1889 p_msg->start = start;
1890 p_msg->duration = duration;
1891 p_msg->p_cback = p_results_cb;
1893 bta_sys_sendmsg(p_msg);
1896 /*******************************************************************************
1898 ** Function BTA_VendorInit
1900 ** Description This function initializes vendor specific
1904 *******************************************************************************/
1905 void BTA_VendorInit (void)
1907 APPL_TRACE_API("BTA_VendorInit");
1910 /*******************************************************************************
1912 ** Function BTA_VendorCleanup
1914 ** Description This function frees up Broadcom specific VS specific dynamic memory
1918 *******************************************************************************/
1919 void BTA_VendorCleanup (void)
1921 tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
1922 BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
1924 #if (BLE_INCLUDED == TRUE && BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
1925 if (cmn_ble_vsc_cb.max_filter > 0)
1927 btm_ble_adv_filter_cleanup();
1928 #if BLE_PRIVACY_SPT == TRUE
1929 btm_ble_resolving_list_cleanup ();
1933 if (cmn_ble_vsc_cb.tot_scan_results_strg > 0)
1934 btm_ble_batchscan_cleanup();
1937 if(cmn_ble_vsc_cb.adv_inst_max > 0)
1938 btm_ble_multi_adv_cleanup();