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 ******************************************************************************/
24 #include <base/bind_helpers.h>
27 #include "bt_common.h"
29 #include "bta_closure_api.h"
30 #include "bta_dm_int.h"
32 #include "bta_sys_int.h"
35 #include "osi/include/osi.h"
38 /*****************************************************************************
40 ****************************************************************************/
42 static const tBTA_SYS_REG bta_dm_reg = {bta_dm_sm_execute, bta_dm_sm_disable};
44 static const tBTA_SYS_REG bta_dm_search_reg = {bta_dm_search_sm_execute,
45 bta_dm_search_sm_disable};
47 /*******************************************************************************
49 * Function BTA_EnableBluetooth
51 * Description Enables bluetooth service. This function must be
52 * called before any other functions in the BTA API are called.
57 ******************************************************************************/
58 tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK* p_cback) {
59 /* Bluetooth disabling is in progress */
60 if (bta_dm_cb.disabling) return BTA_FAILURE;
62 bta_sys_register(BTA_ID_DM, &bta_dm_reg);
63 bta_sys_register(BTA_ID_DM_SEARCH, &bta_dm_search_reg);
65 /* if UUID list is not provided as static data */
66 bta_sys_eir_register(bta_dm_eir_update_uuid);
68 tBTA_DM_API_ENABLE* p_msg =
69 (tBTA_DM_API_ENABLE*)osi_malloc(sizeof(tBTA_DM_API_ENABLE));
70 p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
71 p_msg->p_sec_cback = p_cback;
73 bta_sys_sendmsg(p_msg);
78 /*******************************************************************************
80 * Function BTA_DisableBluetooth
82 * Description Disables bluetooth service. This function is called when
83 * the application no longer needs bluetooth service
87 ******************************************************************************/
88 tBTA_STATUS BTA_DisableBluetooth(void) {
89 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
91 p_msg->event = BTA_DM_API_DISABLE_EVT;
93 bta_sys_sendmsg(p_msg);
98 /*******************************************************************************
100 * Function BTA_EnableTestMode
102 * Description Enables bluetooth device under test mode
105 * Returns tBTA_STATUS
107 ******************************************************************************/
108 tBTA_STATUS BTA_EnableTestMode(void) {
109 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
111 APPL_TRACE_API("%s", __func__);
113 p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
114 bta_sys_sendmsg(p_msg);
119 /*******************************************************************************
121 * Function BTA_DisableTestMode
123 * Description Disable bluetooth device under test mode
128 ******************************************************************************/
129 void BTA_DisableTestMode(void) {
130 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
132 APPL_TRACE_API("%s", __func__);
134 p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
135 bta_sys_sendmsg(p_msg);
138 /*******************************************************************************
140 * Function BTA_DmSetDeviceName
142 * Description This function sets the Bluetooth name of local device
147 ******************************************************************************/
148 void BTA_DmSetDeviceName(char* p_name) {
149 tBTA_DM_API_SET_NAME* p_msg =
150 (tBTA_DM_API_SET_NAME*)osi_malloc(sizeof(tBTA_DM_API_SET_NAME));
152 p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
153 strlcpy((char*)p_msg->name, p_name, BD_NAME_LEN);
155 bta_sys_sendmsg(p_msg);
158 /*******************************************************************************
160 * Function BTA_DmSetVisibility
162 * Description This function sets the Bluetooth connectable,
163 * discoverable, pairable and conn paired only modes of local
169 ******************************************************************************/
170 void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode,
171 uint8_t pairable_mode, uint8_t conn_filter) {
172 tBTA_DM_API_SET_VISIBILITY* p_msg =
173 (tBTA_DM_API_SET_VISIBILITY*)osi_malloc(sizeof(tBTA_DM_MSG));
175 p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
176 p_msg->disc_mode = disc_mode;
177 p_msg->conn_mode = conn_mode;
178 p_msg->pair_mode = pairable_mode;
179 p_msg->conn_paired_only = conn_filter;
181 bta_sys_sendmsg(p_msg);
184 /*******************************************************************************
186 * Function BTA_DmSearch
188 * Description This function searches for peer Bluetooth devices. It
189 * performs an inquiry and gets the remote name for devices.
190 * Service discovery is done if services is non zero
195 ******************************************************************************/
196 void BTA_DmSearch(tBTA_DM_INQ* p_dm_inq, tBTA_SERVICE_MASK services,
197 tBTA_DM_SEARCH_CBACK* p_cback) {
198 tBTA_DM_API_SEARCH* p_msg =
199 (tBTA_DM_API_SEARCH*)osi_calloc(sizeof(tBTA_DM_API_SEARCH));
201 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
202 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
203 p_msg->services = services;
204 p_msg->p_cback = p_cback;
205 p_msg->rs_res = BTA_DM_RS_NONE;
207 bta_sys_sendmsg(p_msg);
210 /*******************************************************************************
212 * Function BTA_DmSearchCancel
214 * Description This function cancels a search initiated by BTA_DmSearch
219 ******************************************************************************/
220 void BTA_DmSearchCancel(void) {
221 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
223 p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
224 bta_sys_sendmsg(p_msg);
227 /*******************************************************************************
229 * Function BTA_DmDiscover
231 * Description This function does service discovery for services of a
237 ******************************************************************************/
238 void BTA_DmDiscover(const RawAddress& bd_addr, tBTA_SERVICE_MASK services,
239 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search) {
240 tBTA_DM_API_DISCOVER* p_msg =
241 (tBTA_DM_API_DISCOVER*)osi_calloc(sizeof(tBTA_DM_API_DISCOVER));
243 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
244 p_msg->bd_addr = bd_addr;
245 p_msg->services = services;
246 p_msg->p_cback = p_cback;
247 p_msg->sdp_search = sdp_search;
249 bta_sys_sendmsg(p_msg);
252 /*******************************************************************************
254 * Function BTA_DmDiscoverUUID
256 * Description This function does service discovery for services of a
262 ******************************************************************************/
263 void BTA_DmDiscoverUUID(const RawAddress& bd_addr, tSDP_UUID* uuid,
264 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search) {
265 tBTA_DM_API_DISCOVER* p_msg =
266 (tBTA_DM_API_DISCOVER*)osi_malloc(sizeof(tBTA_DM_API_DISCOVER));
268 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
269 p_msg->bd_addr = bd_addr;
270 p_msg->services = BTA_USER_SERVICE_MASK; // Not exposed at API level
271 p_msg->p_cback = p_cback;
272 p_msg->sdp_search = sdp_search;
275 p_msg->p_uuid = NULL;
277 memcpy(&p_msg->uuid, uuid, sizeof(tSDP_UUID));
279 bta_sys_sendmsg(p_msg);
282 /*******************************************************************************
284 * Function BTA_DmBond
286 * Description This function initiates a bonding procedure with a peer
292 ******************************************************************************/
293 void BTA_DmBond(const RawAddress& bd_addr) {
294 tBTA_DM_API_BOND* p_msg =
295 (tBTA_DM_API_BOND*)osi_malloc(sizeof(tBTA_DM_API_BOND));
297 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
298 p_msg->bd_addr = bd_addr;
299 p_msg->transport = BTA_TRANSPORT_UNKNOWN;
301 bta_sys_sendmsg(p_msg);
304 /*******************************************************************************
306 * Function BTA_DmBondByTransports
308 * Description This function initiates a bonding procedure with a peer
314 ******************************************************************************/
315 void BTA_DmBondByTransport(const RawAddress& bd_addr,
316 tBTA_TRANSPORT transport) {
317 tBTA_DM_API_BOND* p_msg =
318 (tBTA_DM_API_BOND*)osi_malloc(sizeof(tBTA_DM_API_BOND));
320 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
321 p_msg->bd_addr = bd_addr;
322 p_msg->transport = transport;
324 bta_sys_sendmsg(p_msg);
327 /*******************************************************************************
329 * Function BTA_DmBondCancel
331 * Description This function cancels the bonding procedure with a peer
337 ******************************************************************************/
338 void BTA_DmBondCancel(const RawAddress& bd_addr) {
339 tBTA_DM_API_BOND_CANCEL* p_msg =
340 (tBTA_DM_API_BOND_CANCEL*)osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL));
342 p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
343 p_msg->bd_addr = bd_addr;
345 bta_sys_sendmsg(p_msg);
348 /*******************************************************************************
350 * Function BTA_DmPinReply
352 * Description This function provides a pincode for a remote device when
353 * one is requested by DM through BTA_DM_PIN_REQ_EVT
358 ******************************************************************************/
359 void BTA_DmPinReply(const RawAddress& bd_addr, bool accept, uint8_t pin_len,
363 tBTA_DM_API_PIN_REPLY* p_msg =
364 (tBTA_DM_API_PIN_REPLY*)osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY));
366 p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
367 p_msg->bd_addr = bd_addr;
368 p_msg->accept = accept;
370 p_msg->pin_len = pin_len;
371 memcpy(p_msg->p_pin, p_pin, pin_len);
374 bta_sys_sendmsg(p_msg);
377 /*******************************************************************************
379 * Function BTA_DmLocalOob
381 * Description This function retrieves the OOB data from local controller.
382 * The result is reported by:
383 * - bta_dm_co_loc_oob_ext() if device supports secure
385 * - bta_dm_co_loc_oob() if device doesn't support SC
389 ******************************************************************************/
390 void BTA_DmLocalOob(void) {
391 tBTA_DM_API_LOC_OOB* p_msg =
392 (tBTA_DM_API_LOC_OOB*)osi_malloc(sizeof(tBTA_DM_API_LOC_OOB));
394 p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
395 bta_sys_sendmsg(p_msg);
398 /*******************************************************************************
400 * Function BTA_DmConfirm
402 * Description This function accepts or rejects the numerical value of the
403 * Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
407 ******************************************************************************/
408 void BTA_DmConfirm(const RawAddress& bd_addr, bool accept) {
409 tBTA_DM_API_CONFIRM* p_msg =
410 (tBTA_DM_API_CONFIRM*)osi_malloc(sizeof(tBTA_DM_API_CONFIRM));
412 p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
413 p_msg->bd_addr = bd_addr;
414 p_msg->accept = accept;
416 bta_sys_sendmsg(p_msg);
419 /*******************************************************************************
421 * Function BTA_DmAddDevice
423 * Description This function adds a device to the security database list of
429 ******************************************************************************/
430 void BTA_DmAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
431 LINK_KEY link_key, tBTA_SERVICE_MASK trusted_mask,
432 bool is_trusted, uint8_t key_type, tBTA_IO_CAP io_cap,
433 uint8_t pin_length) {
434 tBTA_DM_API_ADD_DEVICE* p_msg =
435 (tBTA_DM_API_ADD_DEVICE*)osi_calloc(sizeof(tBTA_DM_API_ADD_DEVICE));
437 p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
438 p_msg->bd_addr = bd_addr;
439 p_msg->tm = trusted_mask;
440 p_msg->is_trusted = is_trusted;
441 p_msg->io_cap = io_cap;
444 p_msg->link_key_known = true;
445 p_msg->key_type = key_type;
446 memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
449 /* Load device class if specified */
451 p_msg->dc_known = true;
452 memcpy(p_msg->dc, dev_class, DEV_CLASS_LEN);
455 memset(p_msg->bd_name, 0, BD_NAME_LEN + 1);
456 memset(p_msg->features, 0, sizeof(p_msg->features));
457 p_msg->pin_length = pin_length;
459 bta_sys_sendmsg(p_msg);
462 /*******************************************************************************
464 * Function BTA_DmRemoveDevice
466 * Description This function removes a device fromthe security database
467 * list of peer device. It manages unpairing even while
473 ******************************************************************************/
474 tBTA_STATUS BTA_DmRemoveDevice(const RawAddress& bd_addr) {
475 tBTA_DM_API_REMOVE_DEVICE* p_msg =
476 (tBTA_DM_API_REMOVE_DEVICE*)osi_calloc(sizeof(tBTA_DM_API_REMOVE_DEVICE));
478 p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
479 p_msg->bd_addr = bd_addr;
481 bta_sys_sendmsg(p_msg);
486 /*******************************************************************************
488 * Function BTA_GetEirService
490 * Description This function is called to get BTA service mask from EIR.
492 * Parameters p_eir - pointer of EIR significant part
493 * p_services - return the BTA service mask
497 ******************************************************************************/
498 extern const uint16_t bta_service_id_to_uuid_lkup_tbl[];
499 void BTA_GetEirService(uint8_t* p_eir, size_t eir_len,
500 tBTA_SERVICE_MASK* p_services) {
502 uint8_t num_uuid, max_num_uuid = 32;
503 uint8_t uuid_list[32 * LEN_UUID_16];
504 uint16_t* p_uuid16 = (uint16_t*)uuid_list;
505 tBTA_SERVICE_MASK mask;
507 BTM_GetEirUuidList(p_eir, eir_len, LEN_UUID_16, &num_uuid, uuid_list,
509 for (xx = 0; xx < num_uuid; xx++) {
511 for (yy = 0; yy < BTA_MAX_SERVICE_ID; yy++) {
512 if (*(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy]) {
519 /* for HSP v1.2 only device */
520 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS)
521 *p_services |= BTA_HSP_SERVICE_MASK;
523 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE)
524 *p_services |= BTA_HL_SERVICE_MASK;
526 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK)
527 *p_services |= BTA_HL_SERVICE_MASK;
531 /*******************************************************************************
533 * Function BTA_DmGetConnectionState
535 * Description Returns whether the remote device is currently connected.
537 * Returns 0 if the device is NOT connected.
539 ******************************************************************************/
540 uint16_t BTA_DmGetConnectionState(const RawAddress& bd_addr) {
541 tBTA_DM_PEER_DEVICE* p_dev = bta_dm_find_peer_device(bd_addr);
542 return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
545 /*******************************************************************************
546 * Device Identification (DI) Server Functions
547 ******************************************************************************/
548 /*******************************************************************************
550 * Function BTA_DmSetLocalDiRecord
552 * Description This function adds a DI record to the local SDP database.
554 * Returns BTA_SUCCESS if record set sucessfully, otherwise error code.
556 ******************************************************************************/
557 tBTA_STATUS BTA_DmSetLocalDiRecord(tBTA_DI_RECORD* p_device_info,
558 uint32_t* p_handle) {
559 tBTA_STATUS status = BTA_FAILURE;
561 if (bta_dm_di_cb.di_num < BTA_DI_NUM_MAX) {
562 if (SDP_SetLocalDiRecord((tSDP_DI_RECORD*)p_device_info, p_handle) ==
564 if (!p_device_info->primary_record) {
565 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
566 bta_dm_di_cb.di_num++;
569 bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
570 status = BTA_SUCCESS;
577 /*******************************************************************************
579 * Function bta_dmexecutecallback
581 * Description This function will request BTA to execute a call back in the
582 * context of BTU task.
583 * This API was named in lower case because it is only intended
584 * for the internal customers(like BTIF).
588 ******************************************************************************/
589 void bta_dmexecutecallback(tBTA_DM_EXEC_CBACK* p_callback, void* p_param) {
590 tBTA_DM_API_EXECUTE_CBACK* p_msg =
591 (tBTA_DM_API_EXECUTE_CBACK*)osi_malloc(sizeof(tBTA_DM_MSG));
593 p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
594 p_msg->p_param = p_param;
595 p_msg->p_exec_cback = p_callback;
597 bta_sys_sendmsg(p_msg);
600 /*******************************************************************************
602 * Function BTA_DmAddBleKey
604 * Description Add/modify LE device information. This function will be
605 * normally called during host startup to restore all required
606 * information stored in the NVRAM.
608 * Parameters: bd_addr - BD address of the peer
609 * p_le_key - LE key values.
610 * key_type - LE SMP key type.
612 * Returns BTA_SUCCESS if successful
613 * BTA_FAIL if operation failed.
615 ******************************************************************************/
616 void BTA_DmAddBleKey(const RawAddress& bd_addr, tBTA_LE_KEY_VALUE* p_le_key,
617 tBTA_LE_KEY_TYPE key_type) {
618 tBTA_DM_API_ADD_BLEKEY* p_msg =
619 (tBTA_DM_API_ADD_BLEKEY*)osi_calloc(sizeof(tBTA_DM_API_ADD_BLEKEY));
621 p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
622 p_msg->key_type = key_type;
623 p_msg->bd_addr = bd_addr;
624 memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE));
626 bta_sys_sendmsg(p_msg);
629 /*******************************************************************************
631 * Function BTA_DmAddBleDevice
633 * Description Add a BLE device. This function will be normally called
634 * during host startup to restore all required information
635 * for a LE device stored in the NVRAM.
637 * Parameters: bd_addr - BD address of the peer
638 * dev_type - Remote device's device type.
639 * addr_type - LE device address type.
643 ******************************************************************************/
644 void BTA_DmAddBleDevice(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
645 tBT_DEVICE_TYPE dev_type) {
646 tBTA_DM_API_ADD_BLE_DEVICE* p_msg = (tBTA_DM_API_ADD_BLE_DEVICE*)osi_calloc(
647 sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
649 p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
650 p_msg->bd_addr = bd_addr;
651 p_msg->addr_type = addr_type;
652 p_msg->dev_type = dev_type;
654 bta_sys_sendmsg(p_msg);
657 /*******************************************************************************
659 * Function BTA_DmBlePasskeyReply
661 * Description Send BLE SMP passkey reply.
663 * Parameters: bd_addr - BD address of the peer
664 * accept - passkey entry sucessful or declined.
665 * passkey - passkey value, must be a 6 digit number,
670 ******************************************************************************/
671 void BTA_DmBlePasskeyReply(const RawAddress& bd_addr, bool accept,
673 tBTA_DM_API_PASSKEY_REPLY* p_msg =
674 (tBTA_DM_API_PASSKEY_REPLY*)osi_calloc(sizeof(tBTA_DM_API_PASSKEY_REPLY));
676 p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
677 p_msg->bd_addr = bd_addr;
678 p_msg->accept = accept;
680 if (accept) p_msg->passkey = passkey;
682 bta_sys_sendmsg(p_msg);
685 /*******************************************************************************
687 * Function BTA_DmBleConfirmReply
689 * Description Send BLE SMP SC user confirmation reply.
691 * Parameters: bd_addr - BD address of the peer
692 * accept - numbers to compare are the same or
697 ******************************************************************************/
698 void BTA_DmBleConfirmReply(const RawAddress& bd_addr, bool accept) {
699 tBTA_DM_API_CONFIRM* p_msg =
700 (tBTA_DM_API_CONFIRM*)osi_calloc(sizeof(tBTA_DM_API_CONFIRM));
702 p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT;
703 p_msg->bd_addr = bd_addr;
704 p_msg->accept = accept;
706 bta_sys_sendmsg(p_msg);
709 /*******************************************************************************
711 * Function BTA_DmBleSecurityGrant
713 * Description Grant security request access.
715 * Parameters: bd_addr - BD address of the peer
716 * res - security grant status.
720 ******************************************************************************/
721 void BTA_DmBleSecurityGrant(const RawAddress& bd_addr,
722 tBTA_DM_BLE_SEC_GRANT res) {
723 tBTA_DM_API_BLE_SEC_GRANT* p_msg =
724 (tBTA_DM_API_BLE_SEC_GRANT*)osi_calloc(sizeof(tBTA_DM_API_BLE_SEC_GRANT));
726 p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
727 p_msg->bd_addr = bd_addr;
730 bta_sys_sendmsg(p_msg);
733 /*******************************************************************************
735 * Function BTA_DmSetBlePrefConnParams
737 * Description This function is called to set the preferred connection
738 * parameters when default connection parameter is not desired.
740 * Parameters: bd_addr - BD address of the peripheral
741 * scan_interval - scan interval
742 * scan_window - scan window
743 * min_conn_int - minimum preferred connection interval
744 * max_conn_int - maximum preferred connection interval
745 * slave_latency - preferred slave latency
746 * supervision_tout - preferred supervision timeout
751 ******************************************************************************/
752 void BTA_DmSetBlePrefConnParams(const RawAddress& bd_addr,
753 uint16_t min_conn_int, uint16_t max_conn_int,
754 uint16_t slave_latency,
755 uint16_t supervision_tout) {
756 tBTA_DM_API_BLE_CONN_PARAMS* p_msg = (tBTA_DM_API_BLE_CONN_PARAMS*)osi_calloc(
757 sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
759 p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
760 p_msg->peer_bda = bd_addr;
761 p_msg->conn_int_max = max_conn_int;
762 p_msg->conn_int_min = min_conn_int;
763 p_msg->slave_latency = slave_latency;
764 p_msg->supervision_tout = supervision_tout;
766 bta_sys_sendmsg(p_msg);
769 /*******************************************************************************
771 * Function BTA_DmSetBleConnScanParams
773 * Description This function is called to set scan parameters used in
774 * BLE connection request
776 * Parameters: scan_interval - scan interval
777 * scan_window - scan window
781 ******************************************************************************/
782 void BTA_DmSetBleConnScanParams(uint32_t scan_interval, uint32_t scan_window) {
783 tBTA_DM_API_BLE_SCAN_PARAMS* p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS*)osi_calloc(
784 sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
786 p_msg->hdr.event = BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT;
787 p_msg->scan_int = scan_interval;
788 p_msg->scan_window = scan_window;
790 bta_sys_sendmsg(p_msg);
794 * Set BLE connectable mode to auto connect
796 void BTA_DmBleStartAutoConn() {
797 tBTA_DM_API_SET_NAME* p_msg =
798 (tBTA_DM_API_SET_NAME*)osi_calloc(sizeof(tBTA_DM_API_SET_NAME));
800 p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
801 bta_sys_sendmsg(p_msg);
804 /*******************************************************************************
806 * Function bta_dm_discover_send_msg
808 * Description This function send discover message to BTA task.
812 ******************************************************************************/
813 static void bta_dm_discover_send_msg(const RawAddress& bd_addr,
814 tBTA_SERVICE_MASK_EXT* p_services,
815 tBTA_DM_SEARCH_CBACK* p_cback,
817 tBTA_TRANSPORT transport) {
818 const size_t len = p_services ? (sizeof(tBTA_DM_API_DISCOVER) +
819 sizeof(tBT_UUID) * p_services->num_uuid)
820 : sizeof(tBTA_DM_API_DISCOVER);
821 tBTA_DM_API_DISCOVER* p_msg = (tBTA_DM_API_DISCOVER*)osi_calloc(len);
823 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
824 p_msg->bd_addr = bd_addr;
825 p_msg->p_cback = p_cback;
826 p_msg->sdp_search = sdp_search;
827 p_msg->transport = transport;
829 if (p_services != NULL) {
830 p_msg->services = p_services->srvc_mask;
831 p_msg->num_uuid = p_services->num_uuid;
832 if (p_services->num_uuid != 0) {
833 p_msg->p_uuid = (tBT_UUID*)(p_msg + 1);
834 memcpy(p_msg->p_uuid, p_services->p_uuid,
835 sizeof(tBT_UUID) * p_services->num_uuid);
839 bta_sys_sendmsg(p_msg);
842 /*******************************************************************************
844 * Function BTA_DmDiscoverByTransport
846 * Description This function does service discovery on particular transport
848 * peer device. When services.num_uuid is 0, it indicates all
849 * GATT based services are to be searched; otherwise a list of
850 * UUID of interested services should be provided through
851 * p_services->p_uuid.
857 ******************************************************************************/
858 void BTA_DmDiscoverByTransport(const RawAddress& bd_addr,
859 tBTA_SERVICE_MASK_EXT* p_services,
860 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search,
861 tBTA_TRANSPORT transport) {
862 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
865 /*******************************************************************************
867 * Function BTA_DmDiscoverExt
869 * Description This function does service discovery for services of a
870 * peer device. When services.num_uuid is 0, it indicates all
871 * GATT based services are to be searched; other wise a list of
872 * UUID of interested services should be provided through
873 * p_services->p_uuid.
879 ******************************************************************************/
880 void BTA_DmDiscoverExt(const RawAddress& bd_addr,
881 tBTA_SERVICE_MASK_EXT* p_services,
882 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search) {
883 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search,
884 BTA_TRANSPORT_UNKNOWN);
887 /*******************************************************************************
889 * Function BTA_DmSearchExt
891 * Description This function searches for peer Bluetooth devices. It
892 * performs an inquiry and gets the remote name for devices.
893 * Service discovery is done if services is non zero
895 * Parameters p_dm_inq: inquiry conditions
896 * p_services: if service is not empty, service discovery will
897 * be done. For all GATT based service conditions,
898 * put num_uuid, and p_uuid is the pointer to the
899 * list of UUID values.
900 * p_cback: callback function when search is completed.
906 ******************************************************************************/
907 void BTA_DmSearchExt(tBTA_DM_INQ* p_dm_inq, tBTA_SERVICE_MASK_EXT* p_services,
908 tBTA_DM_SEARCH_CBACK* p_cback) {
909 const size_t len = p_services ? (sizeof(tBTA_DM_API_SEARCH) +
910 sizeof(tBT_UUID) * p_services->num_uuid)
911 : sizeof(tBTA_DM_API_SEARCH);
912 tBTA_DM_API_SEARCH* p_msg = (tBTA_DM_API_SEARCH*)osi_calloc(len);
914 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
915 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
916 p_msg->p_cback = p_cback;
917 p_msg->rs_res = BTA_DM_RS_NONE;
919 if (p_services != NULL) {
920 p_msg->services = p_services->srvc_mask;
921 p_msg->num_uuid = p_services->num_uuid;
923 if (p_services->num_uuid != 0) {
924 p_msg->p_uuid = (tBT_UUID*)(p_msg + 1);
925 memcpy(p_msg->p_uuid, p_services->p_uuid,
926 sizeof(tBT_UUID) * p_services->num_uuid);
928 p_msg->p_uuid = NULL;
932 bta_sys_sendmsg(p_msg);
935 /*******************************************************************************
937 * Function BTA_DmBleUpdateConnectionParam
939 * Description Update connection parameters, can only be used when
942 * Parameters: bd_addr - BD address of the peer
943 * min_int - minimum connection interval,
945 * max_int - maximum connection interval,
947 * latency - slave latency [0 ~ 500]
948 * timeout - supervision timeout [0x000a ~ 0xc80]
952 ******************************************************************************/
953 void BTA_DmBleUpdateConnectionParam(const RawAddress& bd_addr, uint16_t min_int,
954 uint16_t max_int, uint16_t latency,
956 tBTA_DM_API_UPDATE_CONN_PARAM* p_msg =
957 (tBTA_DM_API_UPDATE_CONN_PARAM*)osi_calloc(
958 sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
960 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
961 p_msg->bd_addr = bd_addr;
962 p_msg->min_int = min_int;
963 p_msg->max_int = max_int;
964 p_msg->latency = latency;
965 p_msg->timeout = timeout;
967 bta_sys_sendmsg(p_msg);
970 /*******************************************************************************
972 * Function BTA_DmBleConfigLocalPrivacy
974 * Description Enable/disable privacy on the local device
976 * Parameters: privacy_enable - enable/disabe privacy on remote device.
980 ******************************************************************************/
981 void BTA_DmBleConfigLocalPrivacy(bool privacy_enable) {
982 #if (BLE_PRIVACY_SPT == TRUE)
983 tBTA_DM_API_LOCAL_PRIVACY* p_msg = (tBTA_DM_API_LOCAL_PRIVACY*)osi_calloc(
984 sizeof(tBTA_DM_API_ENABLE_PRIVACY));
986 p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
987 p_msg->privacy_enable = privacy_enable;
989 bta_sys_sendmsg(p_msg);
991 UNUSED(privacy_enable);
995 /*******************************************************************************
997 * Function BTA_DmBleGetEnergyInfo
999 * Description This function is called to obtain the energy info
1001 * Parameters p_cmpl_cback - Command complete callback
1005 ******************************************************************************/
1006 void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK* p_cmpl_cback) {
1007 const size_t len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
1008 tBTA_DM_API_ENERGY_INFO* p_msg = (tBTA_DM_API_ENERGY_INFO*)osi_calloc(len);
1010 APPL_TRACE_API("%s", __func__);
1012 p_msg->hdr.event = BTA_DM_API_BLE_ENERGY_INFO_EVT;
1013 p_msg->p_energy_info_cback = p_cmpl_cback;
1015 bta_sys_sendmsg(p_msg);
1018 /*******************************************************************************
1020 * Function BTA_DmBleUpdateConnectionParams
1022 * Description Update connection parameters, can only be used when
1025 * Parameters: bd_addr - BD address of the peer
1026 * min_int - minimum connection interval,
1028 * max_int - maximum connection interval,
1030 * latency - slave latency [0 ~ 500]
1031 * timeout - supervision timeout [0x000a ~ 0xc80]
1035 ******************************************************************************/
1036 void BTA_DmBleUpdateConnectionParams(const RawAddress& bd_addr,
1037 uint16_t min_int, uint16_t max_int,
1038 uint16_t latency, uint16_t timeout) {
1039 tBTA_DM_API_UPDATE_CONN_PARAM* p_msg =
1040 (tBTA_DM_API_UPDATE_CONN_PARAM*)osi_calloc(
1041 sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1043 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1044 p_msg->bd_addr = bd_addr;
1045 p_msg->min_int = min_int;
1046 p_msg->max_int = max_int;
1047 p_msg->latency = latency;
1048 p_msg->timeout = timeout;
1050 bta_sys_sendmsg(p_msg);
1053 /*******************************************************************************
1055 * Function BTA_DmBleSetDataLength
1057 * Description This function is to set maximum LE data packet size
1062 ******************************************************************************/
1063 void BTA_DmBleSetDataLength(const RawAddress& remote_device,
1064 uint16_t tx_data_length) {
1065 tBTA_DM_API_BLE_SET_DATA_LENGTH* p_msg =
1066 (tBTA_DM_API_BLE_SET_DATA_LENGTH*)osi_malloc(
1067 sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH));
1069 p_msg->remote_bda = remote_device;
1070 p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
1071 p_msg->tx_data_length = tx_data_length;
1073 bta_sys_sendmsg(p_msg);
1076 /*******************************************************************************
1078 * Function BTA_DmSetEncryption
1080 * Description This function is called to ensure that connection is
1081 * encrypted. Should be called only on an open connection.
1082 * Typically only needed for connections that first want to
1083 * bring up unencrypted links, then later encrypt them.
1085 * Parameters: bd_addr - Address of the peer device
1086 * transport - transport of the link to be encruypted
1087 * p_callback - Pointer to callback function to indicat the
1088 * link encryption status
1089 * sec_act - This is the security action to indicate
1090 * what kind of BLE security level is required
1091 * for the BLE link if BLE is supported.
1092 * Note: This parameter is ignored for the
1093 * BR/EDR or if BLE is not supported.
1097 ******************************************************************************/
1098 void BTA_DmSetEncryption(const RawAddress& bd_addr, tBTA_TRANSPORT transport,
1099 tBTA_DM_ENCRYPT_CBACK* p_callback,
1100 tBTA_DM_BLE_SEC_ACT sec_act) {
1101 tBTA_DM_API_SET_ENCRYPTION* p_msg = (tBTA_DM_API_SET_ENCRYPTION*)osi_calloc(
1102 sizeof(tBTA_DM_API_SET_ENCRYPTION));
1104 APPL_TRACE_API("%s", __func__);
1106 p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
1107 p_msg->bd_addr = bd_addr;
1108 p_msg->transport = transport;
1109 p_msg->p_callback = p_callback;
1110 p_msg->sec_act = sec_act;
1112 bta_sys_sendmsg(p_msg);
1115 /*******************************************************************************
1117 * Function BTA_DmCloseACL
1119 * Description This function force to close an ACL connection and remove
1120 * the device from the security database list of known devices.
1122 * Parameters: bd_addr - Address of the peer device
1123 * remove_dev - remove device or not after link down
1127 ******************************************************************************/
1128 void BTA_DmCloseACL(const RawAddress& bd_addr, bool remove_dev,
1129 tBTA_TRANSPORT transport) {
1130 tBTA_DM_API_REMOVE_ACL* p_msg =
1131 (tBTA_DM_API_REMOVE_ACL*)osi_calloc(sizeof(tBTA_DM_API_REMOVE_ACL));
1133 APPL_TRACE_API("%s", __func__);
1135 p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
1136 p_msg->bd_addr = bd_addr;
1137 p_msg->remove_dev = remove_dev;
1138 p_msg->transport = transport;
1140 bta_sys_sendmsg(p_msg);
1143 /*******************************************************************************
1145 * Function BTA_DmBleObserve
1147 * Description This procedure keep the device listening for advertising
1148 * events from a broadcast device.
1150 * Parameters start: start or stop observe.
1157 ******************************************************************************/
1158 extern void BTA_DmBleObserve(bool start, uint8_t duration,
1159 tBTA_DM_SEARCH_CBACK* p_results_cb) {
1160 tBTA_DM_API_BLE_OBSERVE* p_msg =
1161 (tBTA_DM_API_BLE_OBSERVE*)osi_calloc(sizeof(tBTA_DM_API_BLE_OBSERVE));
1163 APPL_TRACE_API("%s:start = %d ", __func__, start);
1165 p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
1166 p_msg->start = start;
1167 p_msg->duration = duration;
1168 p_msg->p_cback = p_results_cb;
1170 bta_sys_sendmsg(p_msg);
1173 /*******************************************************************************
1175 * Function BTA_VendorInit
1177 * Description This function initializes vendor specific
1181 ******************************************************************************/
1182 void BTA_VendorInit(void) { APPL_TRACE_API("BTA_VendorInit"); }
1184 /*******************************************************************************
1186 * Function BTA_VendorCleanup
1188 * Description This function frees up Broadcom specific VS specific dynamic
1193 ******************************************************************************/
1194 void BTA_VendorCleanup(void) {
1195 tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
1196 BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
1198 if (cmn_ble_vsc_cb.max_filter > 0) {
1199 btm_ble_adv_filter_cleanup();
1200 #if (BLE_PRIVACY_SPT == TRUE)
1201 btm_ble_resolving_list_cleanup();
1205 if (cmn_ble_vsc_cb.tot_scan_results_strg > 0) btm_ble_batchscan_cleanup();
1207 if (cmn_ble_vsc_cb.adv_inst_max > 0) btm_ble_multi_adv_cleanup();