blob: e968bd1fc5ee6a0135ebb1fe4df8e7f3e78fcf73 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Jakub Pawlowski5b790fe2017-09-18 09:00:20 -07003 * Copyright 2003-2014 Broadcom Corporation
The Android Open Source Project5738f832012-12-12 16:00:35 -08004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19/******************************************************************************
20 *
21 * This is the API implementation file for the BTA device manager.
22 *
23 ******************************************************************************/
Jakub Pawlowski70984322016-12-16 10:43:49 -080024#include <base/bind_helpers.h>
Myles Watsonf355ef52016-11-09 13:04:33 -080025#include <string.h>
The Android Open Source Project5738f832012-12-12 16:00:35 -080026
Pavlin Radoslavov258c2532015-09-27 20:59:05 -070027#include "bt_common.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080028#include "bta_api.h"
Jakub Pawlowski5b12a832016-08-11 03:30:47 -070029#include "bta_closure_api.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080030#include "bta_dm_int.h"
Myles Watsoncd1fd072016-11-09 13:17:43 -080031#include "bta_sys.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080032#include "bta_sys_int.h"
33#include "btm_api.h"
34#include "btm_int.h"
Myles Watsond7ffd642016-10-27 10:27:36 -070035#include "osi/include/osi.h"
Mike J. Chen5cd8bff2014-01-31 18:16:59 -080036#include "utl.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080037
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -070038using bluetooth::Uuid;
39
The Android Open Source Project5738f832012-12-12 16:00:35 -080040/*****************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080041 * Constants
42 ****************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080043
Myles Watsoncd1fd072016-11-09 13:17:43 -080044static const tBTA_SYS_REG bta_dm_search_reg = {bta_dm_search_sm_execute,
45 bta_dm_search_sm_disable};
The Android Open Source Project5738f832012-12-12 16:00:35 -080046
47/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080048 *
49 * Function BTA_EnableBluetooth
50 *
51 * Description Enables bluetooth service. This function must be
52 * called before any other functions in the BTA API are called.
53 *
54 *
55 * Returns tBTA_STATUS
56 *
57 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -080058tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK* p_cback) {
59 /* Bluetooth disabling is in progress */
60 if (bta_dm_cb.disabling) return BTA_FAILURE;
The Android Open Source Project5738f832012-12-12 16:00:35 -080061
Myles Watsoncd1fd072016-11-09 13:17:43 -080062 bta_sys_register(BTA_ID_DM_SEARCH, &bta_dm_search_reg);
The Android Open Source Project5738f832012-12-12 16:00:35 -080063
Myles Watsoncd1fd072016-11-09 13:17:43 -080064 /* if UUID list is not provided as static data */
65 bta_sys_eir_register(bta_dm_eir_update_uuid);
The Android Open Source Project5738f832012-12-12 16:00:35 -080066
Jakub Pawlowski154be112018-01-22 10:22:43 -080067 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_enable, p_cback));
Myles Watsoncd1fd072016-11-09 13:17:43 -080068 return BTA_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -080069}
70
71/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080072 *
73 * Function BTA_DisableBluetooth
74 *
75 * Description Disables bluetooth service. This function is called when
76 * the application no longer needs bluetooth service
77 *
78 * Returns void
79 *
80 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -080081tBTA_STATUS BTA_DisableBluetooth(void) {
Jakub Pawlowski154be112018-01-22 10:22:43 -080082 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_disable));
Myles Watsoncd1fd072016-11-09 13:17:43 -080083 return BTA_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -080084}
85
Jakub Pawlowski154be112018-01-22 10:22:43 -080086/** Enables bluetooth device under test mode */
87void BTA_EnableTestMode(void) {
Jakub Pawlowski0d486802018-01-23 12:46:07 -080088 do_in_bta_thread(FROM_HERE,
89 base::Bind(base::IgnoreResult(BTM_EnableTestMode)));
The Android Open Source Project5738f832012-12-12 16:00:35 -080090}
91
Jakub Pawlowski154be112018-01-22 10:22:43 -080092/** Disable bluetooth device under test mode */
Myles Watsoncd1fd072016-11-09 13:17:43 -080093void BTA_DisableTestMode(void) {
Jakub Pawlowski0d486802018-01-23 12:46:07 -080094 do_in_bta_thread(FROM_HERE, base::Bind(BTM_DeviceReset, nullptr));
The Android Open Source Project5738f832012-12-12 16:00:35 -080095}
96
Jakub Pawlowski0d486802018-01-23 12:46:07 -080097/** This function sets the Bluetooth name of local device */
Myles Watsoncd1fd072016-11-09 13:17:43 -080098void BTA_DmSetDeviceName(char* p_name) {
Jakub Pawlowski0d486802018-01-23 12:46:07 -080099 std::vector<uint8_t> name(BD_NAME_LEN);
100 strlcpy((char*)name.data(), p_name, BD_NAME_LEN);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800101
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800102 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_set_dev_name, name));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800103}
104
Jakub Pawlowski154be112018-01-22 10:22:43 -0800105/** This function sets the Bluetooth connectable, discoverable, pairable and
106 * conn paired only modes of local device
107 */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800108void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode,
Jakub Pawlowski154be112018-01-22 10:22:43 -0800109 uint8_t pairable_mode, uint8_t conn_paired_only) {
110 do_in_bta_thread(FROM_HERE,
111 base::Bind(bta_dm_set_visibility, disc_mode, conn_mode,
112 pairable_mode, conn_paired_only));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800113}
114
115/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800116 *
117 * Function BTA_DmSearch
118 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800119 * Description This function searches for peer Bluetooth devices. It
Myles Watson1baaae32016-11-09 14:25:23 -0800120 * performs an inquiry and gets the remote name for devices.
121 * Service discovery is done if services is non zero
Myles Watson8af480e2016-11-09 10:40:23 -0800122 *
123 *
124 * Returns void
125 *
126 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800127void BTA_DmSearch(tBTA_DM_INQ* p_dm_inq, tBTA_SERVICE_MASK services,
128 tBTA_DM_SEARCH_CBACK* p_cback) {
129 tBTA_DM_API_SEARCH* p_msg =
130 (tBTA_DM_API_SEARCH*)osi_calloc(sizeof(tBTA_DM_API_SEARCH));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800131
Myles Watsoncd1fd072016-11-09 13:17:43 -0800132 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
133 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
134 p_msg->services = services;
135 p_msg->p_cback = p_cback;
136 p_msg->rs_res = BTA_DM_RS_NONE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800137
Myles Watsoncd1fd072016-11-09 13:17:43 -0800138 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800139}
140
The Android Open Source Project5738f832012-12-12 16:00:35 -0800141/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800142 *
143 * Function BTA_DmSearchCancel
144 *
145 * Description This function cancels a search initiated by BTA_DmSearch
146 *
147 *
148 * Returns void
149 *
150 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800151void BTA_DmSearchCancel(void) {
152 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800153
Myles Watsoncd1fd072016-11-09 13:17:43 -0800154 p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
155 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800156}
157
158/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800159 *
160 * Function BTA_DmDiscover
161 *
162 * Description This function does service discovery for services of a
163 * peer device
164 *
165 *
166 * Returns void
167 *
168 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700169void BTA_DmDiscover(const RawAddress& bd_addr, tBTA_SERVICE_MASK services,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800170 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search) {
171 tBTA_DM_API_DISCOVER* p_msg =
172 (tBTA_DM_API_DISCOVER*)osi_calloc(sizeof(tBTA_DM_API_DISCOVER));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800173
Myles Watsoncd1fd072016-11-09 13:17:43 -0800174 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700175 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800176 p_msg->services = services;
177 p_msg->p_cback = p_cback;
178 p_msg->sdp_search = sdp_search;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800179
Myles Watsoncd1fd072016-11-09 13:17:43 -0800180 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800181}
182
183/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800184 *
185 * Function BTA_DmDiscoverUUID
186 *
187 * Description This function does service discovery for services of a
188 * peer device
189 *
190 *
191 * Returns void
192 *
193 ******************************************************************************/
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700194void BTA_DmDiscoverUUID(const RawAddress& bd_addr, const Uuid& uuid,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800195 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search) {
196 tBTA_DM_API_DISCOVER* p_msg =
197 (tBTA_DM_API_DISCOVER*)osi_malloc(sizeof(tBTA_DM_API_DISCOVER));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800198
Myles Watsoncd1fd072016-11-09 13:17:43 -0800199 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700200 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800201 p_msg->services = BTA_USER_SERVICE_MASK; // Not exposed at API level
202 p_msg->p_cback = p_cback;
203 p_msg->sdp_search = sdp_search;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800204
Myles Watsoncd1fd072016-11-09 13:17:43 -0800205 p_msg->num_uuid = 0;
206 p_msg->p_uuid = NULL;
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700207 p_msg->uuid = uuid;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800208
Myles Watsoncd1fd072016-11-09 13:17:43 -0800209 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800210}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800211
Jakub Pawlowski154be112018-01-22 10:22:43 -0800212/** This function initiates a bonding procedure with a peer device */
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700213void BTA_DmBond(const RawAddress& bd_addr) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800214 do_in_bta_thread(FROM_HERE,
215 base::Bind(bta_dm_bond, bd_addr, BTA_TRANSPORT_UNKNOWN));
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700216}
217
Jakub Pawlowski154be112018-01-22 10:22:43 -0800218/** This function initiates a bonding procedure with a peer device */
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700219void BTA_DmBondByTransport(const RawAddress& bd_addr,
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700220 tBTA_TRANSPORT transport) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800221 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_bond, bd_addr, transport));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800222}
223
Jakub Pawlowski154be112018-01-22 10:22:43 -0800224/** This function cancels the bonding procedure with a peer device
225 */
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700226void BTA_DmBondCancel(const RawAddress& bd_addr) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800227 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_bond_cancel, bd_addr));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800228}
229
230/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800231 *
232 * Function BTA_DmPinReply
233 *
234 * Description This function provides a pincode for a remote device when
235 * one is requested by DM through BTA_DM_PIN_REQ_EVT
236 *
237 *
238 * Returns void
239 *
240 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700241void BTA_DmPinReply(const RawAddress& bd_addr, bool accept, uint8_t pin_len,
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800242 uint8_t* p_pin) {
243 std::unique_ptr<tBTA_DM_API_PIN_REPLY> msg =
244 std::make_unique<tBTA_DM_API_PIN_REPLY>();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800245
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800246 msg->bd_addr = bd_addr;
247 msg->accept = accept;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800248 if (accept) {
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800249 msg->pin_len = pin_len;
250 memcpy(msg->p_pin, p_pin, pin_len);
Myles Watsoncd1fd072016-11-09 13:17:43 -0800251 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800252
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800253 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_pin_reply, base::Passed(&msg)));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800254}
255
The Android Open Source Project5738f832012-12-12 16:00:35 -0800256/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800257 *
258 * Function BTA_DmLocalOob
259 *
260 * Description This function retrieves the OOB data from local controller.
261 * The result is reported by:
262 * - bta_dm_co_loc_oob_ext() if device supports secure
263 * connections (SC)
264 * - bta_dm_co_loc_oob() if device doesn't support SC
265 *
266 * Returns void
267 *
268 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800269void BTA_DmLocalOob(void) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800270 do_in_bta_thread(FROM_HERE, base::Bind(BTM_ReadLocalOobData));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800271}
Jakub Pawlowski175da702015-11-12 15:00:58 -0800272
The Android Open Source Project5738f832012-12-12 16:00:35 -0800273/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800274 *
275 * Function BTA_DmConfirm
276 *
277 * Description This function accepts or rejects the numerical value of the
278 * Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
279 *
280 * Returns void
281 *
282 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700283void BTA_DmConfirm(const RawAddress& bd_addr, bool accept) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800284 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_confirm, bd_addr, accept));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800285}
286
287/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800288 *
289 * Function BTA_DmAddDevice
290 *
291 * Description This function adds a device to the security database list of
292 * peer device
293 *
294 *
295 * Returns void
296 *
297 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700298void BTA_DmAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700299 LINK_KEY link_key, tBTA_SERVICE_MASK trusted_mask,
300 bool is_trusted, uint8_t key_type, tBTA_IO_CAP io_cap,
301 uint8_t pin_length) {
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800302 std::unique_ptr<tBTA_DM_API_ADD_DEVICE> msg =
303 std::make_unique<tBTA_DM_API_ADD_DEVICE>();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800304
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800305 msg->bd_addr = bd_addr;
306 msg->tm = trusted_mask;
307 msg->is_trusted = is_trusted;
308 msg->io_cap = io_cap;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800309
Myles Watsoncd1fd072016-11-09 13:17:43 -0800310 if (link_key) {
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800311 msg->link_key_known = true;
312 msg->key_type = key_type;
313 memcpy(msg->link_key, link_key, LINK_KEY_LEN);
Myles Watsoncd1fd072016-11-09 13:17:43 -0800314 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800315
Myles Watsoncd1fd072016-11-09 13:17:43 -0800316 /* Load device class if specified */
317 if (dev_class) {
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800318 msg->dc_known = true;
319 memcpy(msg->dc, dev_class, DEV_CLASS_LEN);
Myles Watsoncd1fd072016-11-09 13:17:43 -0800320 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800321
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800322 memset(msg->bd_name, 0, BD_NAME_LEN + 1);
323 memset(msg->features, 0, sizeof(msg->features));
324 msg->pin_length = pin_length;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800325
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800326 do_in_bta_thread(FROM_HERE,
327 base::Bind(bta_dm_add_device, base::Passed(&msg)));
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800328}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800329
Jakub Pawlowski154be112018-01-22 10:22:43 -0800330/** This function removes a device fromthe security database list of peer
331 * device. It manages unpairing even while connected */
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700332tBTA_STATUS BTA_DmRemoveDevice(const RawAddress& bd_addr) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800333 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_remove_device, bd_addr));
Myles Watsoncd1fd072016-11-09 13:17:43 -0800334 return BTA_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800335}
336
337/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800338 *
339 * Function BTA_GetEirService
340 *
341 * Description This function is called to get BTA service mask from EIR.
342 *
343 * Parameters p_eir - pointer of EIR significant part
344 * p_services - return the BTA service mask
345 *
346 * Returns None
347 *
348 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800349extern const uint16_t bta_service_id_to_uuid_lkup_tbl[];
Jakub Pawlowski0595ca02017-02-07 12:15:06 -0800350void BTA_GetEirService(uint8_t* p_eir, size_t eir_len,
351 tBTA_SERVICE_MASK* p_services) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800352 uint8_t xx, yy;
353 uint8_t num_uuid, max_num_uuid = 32;
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700354 uint8_t uuid_list[32 * Uuid::kNumBytes16];
Myles Watsoncd1fd072016-11-09 13:17:43 -0800355 uint16_t* p_uuid16 = (uint16_t*)uuid_list;
356 tBTA_SERVICE_MASK mask;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800357
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700358 BTM_GetEirUuidList(p_eir, eir_len, Uuid::kNumBytes16, &num_uuid, uuid_list,
Jakub Pawlowski0595ca02017-02-07 12:15:06 -0800359 max_num_uuid);
Myles Watsoncd1fd072016-11-09 13:17:43 -0800360 for (xx = 0; xx < num_uuid; xx++) {
361 mask = 1;
362 for (yy = 0; yy < BTA_MAX_SERVICE_ID; yy++) {
363 if (*(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy]) {
364 *p_services |= mask;
365 break;
366 }
367 mask <<= 1;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800368 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800369
370 /* for HSP v1.2 only device */
371 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS)
372 *p_services |= BTA_HSP_SERVICE_MASK;
373
374 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE)
375 *p_services |= BTA_HL_SERVICE_MASK;
376
377 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK)
378 *p_services |= BTA_HL_SERVICE_MASK;
379 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800380}
381
382/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800383 *
384 * Function BTA_DmGetConnectionState
385 *
386 * Description Returns whether the remote device is currently connected.
387 *
388 * Returns 0 if the device is NOT connected.
389 *
390 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700391uint16_t BTA_DmGetConnectionState(const RawAddress& bd_addr) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800392 tBTA_DM_PEER_DEVICE* p_dev = bta_dm_find_peer_device(bd_addr);
393 return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
Andre Eisenbach5c0b0522014-06-18 12:20:37 -0700394}
395
Andre Eisenbach5c0b0522014-06-18 12:20:37 -0700396/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800397 * Device Identification (DI) Server Functions
398 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800399/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800400 *
401 * Function BTA_DmSetLocalDiRecord
402 *
403 * Description This function adds a DI record to the local SDP database.
404 *
405 * Returns BTA_SUCCESS if record set sucessfully, otherwise error code.
406 *
407 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800408tBTA_STATUS BTA_DmSetLocalDiRecord(tBTA_DI_RECORD* p_device_info,
409 uint32_t* p_handle) {
410 tBTA_STATUS status = BTA_FAILURE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800411
Myles Watsoncd1fd072016-11-09 13:17:43 -0800412 if (bta_dm_di_cb.di_num < BTA_DI_NUM_MAX) {
413 if (SDP_SetLocalDiRecord((tSDP_DI_RECORD*)p_device_info, p_handle) ==
414 SDP_SUCCESS) {
415 if (!p_device_info->primary_record) {
416 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
417 bta_dm_di_cb.di_num++;
418 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800419
Myles Watsoncd1fd072016-11-09 13:17:43 -0800420 bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
421 status = BTA_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800422 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800423 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800424
Myles Watsoncd1fd072016-11-09 13:17:43 -0800425 return status;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800426}
427
428/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800429 *
Myles Watson8af480e2016-11-09 10:40:23 -0800430 * Function BTA_DmAddBleKey
431 *
432 * Description Add/modify LE device information. This function will be
433 * normally called during host startup to restore all required
434 * information stored in the NVRAM.
435 *
436 * Parameters: bd_addr - BD address of the peer
437 * p_le_key - LE key values.
438 * key_type - LE SMP key type.
439 *
440 * Returns BTA_SUCCESS if successful
441 * BTA_FAIL if operation failed.
442 *
443 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700444void BTA_DmAddBleKey(const RawAddress& bd_addr, tBTA_LE_KEY_VALUE* p_le_key,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800445 tBTA_LE_KEY_TYPE key_type) {
Jakub Pawlowski0d486802018-01-23 12:46:07 -0800446 do_in_bta_thread(FROM_HERE,
447 base::Bind(bta_dm_add_blekey, bd_addr, *p_le_key, key_type));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800448}
449
450/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800451 *
452 * Function BTA_DmAddBleDevice
453 *
454 * Description Add a BLE device. This function will be normally called
455 * during host startup to restore all required information
456 * for a LE device stored in the NVRAM.
457 *
458 * Parameters: bd_addr - BD address of the peer
459 * dev_type - Remote device's device type.
460 * addr_type - LE device address type.
461 *
462 * Returns void
463 *
464 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700465void BTA_DmAddBleDevice(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800466 tBT_DEVICE_TYPE dev_type) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800467 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_add_ble_device, bd_addr,
468 addr_type, dev_type));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800469}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800470
The Android Open Source Project5738f832012-12-12 16:00:35 -0800471/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800472 *
473 * Function BTA_DmBlePasskeyReply
474 *
475 * Description Send BLE SMP passkey reply.
476 *
477 * Parameters: bd_addr - BD address of the peer
478 * accept - passkey entry sucessful or declined.
479 * passkey - passkey value, must be a 6 digit number,
480 * can be lead by 0.
481 *
482 * Returns void
483 *
484 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700485void BTA_DmBlePasskeyReply(const RawAddress& bd_addr, bool accept,
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700486 uint32_t passkey) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800487 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_ble_passkey_reply, bd_addr,
488 accept, accept ? passkey : 0));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800489}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800490
The Android Open Source Project5738f832012-12-12 16:00:35 -0800491/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800492 *
493 * Function BTA_DmBleConfirmReply
494 *
495 * Description Send BLE SMP SC user confirmation reply.
496 *
497 * Parameters: bd_addr - BD address of the peer
Myles Watsoncd1fd072016-11-09 13:17:43 -0800498 * accept - numbers to compare are the same or
Myles Watson1baaae32016-11-09 14:25:23 -0800499 * different.
Myles Watson8af480e2016-11-09 10:40:23 -0800500 *
501 * Returns void
502 *
503 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700504void BTA_DmBleConfirmReply(const RawAddress& bd_addr, bool accept) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800505 do_in_bta_thread(FROM_HERE,
506 base::Bind(bta_dm_ble_confirm_reply, bd_addr, accept));
Satya Calloji444a8da2015-03-06 10:38:22 -0800507}
508
509/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800510 *
511 * Function BTA_DmBleSecurityGrant
512 *
513 * Description Grant security request access.
514 *
515 * Parameters: bd_addr - BD address of the peer
516 * res - security grant status.
517 *
518 * Returns void
519 *
520 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700521void BTA_DmBleSecurityGrant(const RawAddress& bd_addr,
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700522 tBTA_DM_BLE_SEC_GRANT res) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800523 do_in_bta_thread(FROM_HERE, base::Bind(BTM_SecurityGrant, bd_addr, res));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800524}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800525
The Android Open Source Project5738f832012-12-12 16:00:35 -0800526/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800527 *
528 * Function BTA_DmSetBlePrefConnParams
529 *
530 * Description This function is called to set the preferred connection
531 * parameters when default connection parameter is not desired.
532 *
533 * Parameters: bd_addr - BD address of the peripheral
534 * scan_interval - scan interval
535 * scan_window - scan window
536 * min_conn_int - minimum preferred connection interval
537 * max_conn_int - maximum preferred connection interval
538 * slave_latency - preferred slave latency
539 * supervision_tout - preferred supervision timeout
540 *
541 *
542 * Returns void
543 *
544 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700545void BTA_DmSetBlePrefConnParams(const RawAddress& bd_addr,
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700546 uint16_t min_conn_int, uint16_t max_conn_int,
547 uint16_t slave_latency,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800548 uint16_t supervision_tout) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800549 do_in_bta_thread(FROM_HERE,
550 base::Bind(bta_dm_ble_set_conn_params, bd_addr, min_conn_int,
551 max_conn_int, slave_latency, supervision_tout));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800552}
553
554/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800555 *
556 * Function BTA_DmSetBleConnScanParams
557 *
558 * Description This function is called to set scan parameters used in
559 * BLE connection request
560 *
561 * Parameters: scan_interval - scan interval
562 * scan_window - scan window
563 *
564 * Returns void
565 *
566 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800567void BTA_DmSetBleConnScanParams(uint32_t scan_interval, uint32_t scan_window) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800568 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_ble_set_conn_scan_params,
569 scan_interval, scan_window));
Satya Calloji5725fc62015-03-31 13:24:32 -0700570}
571
Jakub Pawlowski154be112018-01-22 10:22:43 -0800572/** Set BLE connectable mode to auto connect */
Jakub Pawlowski83211b02016-12-07 11:25:15 -0800573void BTA_DmBleStartAutoConn() {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800574 do_in_bta_thread(FROM_HERE, base::Bind(BTM_BleStartAutoConn));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800575}
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700576
The Android Open Source Project5738f832012-12-12 16:00:35 -0800577/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800578 *
579 * Function bta_dm_discover_send_msg
580 *
581 * Description This function send discover message to BTA task.
582 *
583 * Returns void
584 *
585 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700586static void bta_dm_discover_send_msg(const RawAddress& bd_addr,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800587 tBTA_SERVICE_MASK_EXT* p_services,
588 tBTA_DM_SEARCH_CBACK* p_cback,
589 bool sdp_search,
590 tBTA_TRANSPORT transport) {
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700591 const size_t len =
592 p_services
593 ? (sizeof(tBTA_DM_API_DISCOVER) + sizeof(Uuid) * p_services->num_uuid)
594 : sizeof(tBTA_DM_API_DISCOVER);
Myles Watsoncd1fd072016-11-09 13:17:43 -0800595 tBTA_DM_API_DISCOVER* p_msg = (tBTA_DM_API_DISCOVER*)osi_calloc(len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800596
Myles Watsoncd1fd072016-11-09 13:17:43 -0800597 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700598 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800599 p_msg->p_cback = p_cback;
600 p_msg->sdp_search = sdp_search;
601 p_msg->transport = transport;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800602
Myles Watsoncd1fd072016-11-09 13:17:43 -0800603 if (p_services != NULL) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800604 p_msg->services = p_services->srvc_mask;
605 p_msg->num_uuid = p_services->num_uuid;
606 if (p_services->num_uuid != 0) {
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700607 p_msg->p_uuid = (Uuid*)(p_msg + 1);
Myles Watsoncd1fd072016-11-09 13:17:43 -0800608 memcpy(p_msg->p_uuid, p_services->p_uuid,
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700609 sizeof(Uuid) * p_services->num_uuid);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800610 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800611 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800612
Myles Watsoncd1fd072016-11-09 13:17:43 -0800613 bta_sys_sendmsg(p_msg);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700614}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800615
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700616/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800617 *
618 * Function BTA_DmDiscoverByTransport
619 *
620 * Description This function does service discovery on particular transport
621 * for services of a
622 * peer device. When services.num_uuid is 0, it indicates all
623 * GATT based services are to be searched; otherwise a list of
624 * UUID of interested services should be provided through
625 * p_services->p_uuid.
626 *
627 *
628 *
629 * Returns void
630 *
631 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700632void BTA_DmDiscoverByTransport(const RawAddress& bd_addr,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800633 tBTA_SERVICE_MASK_EXT* p_services,
634 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search,
635 tBTA_TRANSPORT transport) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800636 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700637}
638
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700639/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800640 *
641 * Function BTA_DmDiscoverExt
642 *
643 * Description This function does service discovery for services of a
644 * peer device. When services.num_uuid is 0, it indicates all
645 * GATT based services are to be searched; other wise a list of
646 * UUID of interested services should be provided through
647 * p_services->p_uuid.
648 *
649 *
650 *
651 * Returns void
652 *
653 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700654void BTA_DmDiscoverExt(const RawAddress& bd_addr,
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700655 tBTA_SERVICE_MASK_EXT* p_services,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800656 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800657 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search,
658 BTA_TRANSPORT_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800659}
660
661/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800662 *
663 * Function BTA_DmSearchExt
664 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800665 * Description This function searches for peer Bluetooth devices. It
Myles Watson1baaae32016-11-09 14:25:23 -0800666 * performs an inquiry and gets the remote name for devices.
667 * Service discovery is done if services is non zero
Myles Watson8af480e2016-11-09 10:40:23 -0800668 *
669 * Parameters p_dm_inq: inquiry conditions
Myles Watsoncd1fd072016-11-09 13:17:43 -0800670 * p_services: if service is not empty, service discovery will
Myles Watson1baaae32016-11-09 14:25:23 -0800671 * be done. For all GATT based service conditions,
672 * put num_uuid, and p_uuid is the pointer to the
673 * list of UUID values.
674 * p_cback: callback function when search is completed.
Myles Watson8af480e2016-11-09 10:40:23 -0800675 *
676 *
677 *
678 * Returns void
679 *
680 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800681void BTA_DmSearchExt(tBTA_DM_INQ* p_dm_inq, tBTA_SERVICE_MASK_EXT* p_services,
682 tBTA_DM_SEARCH_CBACK* p_cback) {
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700683 const size_t len =
684 p_services
685 ? (sizeof(tBTA_DM_API_SEARCH) + sizeof(Uuid) * p_services->num_uuid)
686 : sizeof(tBTA_DM_API_SEARCH);
Myles Watsoncd1fd072016-11-09 13:17:43 -0800687 tBTA_DM_API_SEARCH* p_msg = (tBTA_DM_API_SEARCH*)osi_calloc(len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800688
Myles Watsoncd1fd072016-11-09 13:17:43 -0800689 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
690 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
691 p_msg->p_cback = p_cback;
692 p_msg->rs_res = BTA_DM_RS_NONE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800693
Myles Watsoncd1fd072016-11-09 13:17:43 -0800694 if (p_services != NULL) {
695 p_msg->services = p_services->srvc_mask;
696 p_msg->num_uuid = p_services->num_uuid;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800697
Myles Watsoncd1fd072016-11-09 13:17:43 -0800698 if (p_services->num_uuid != 0) {
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700699 p_msg->p_uuid = (Uuid*)(p_msg + 1);
Myles Watsoncd1fd072016-11-09 13:17:43 -0800700 memcpy(p_msg->p_uuid, p_services->p_uuid,
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -0700701 sizeof(Uuid) * p_services->num_uuid);
Myles Watsoncd1fd072016-11-09 13:17:43 -0800702 } else {
703 p_msg->p_uuid = NULL;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800704 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800705 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800706
Myles Watsoncd1fd072016-11-09 13:17:43 -0800707 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800708}
Myles Watson99791212016-11-18 08:42:23 -0800709
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800710/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800711 *
712 * Function BTA_DmBleUpdateConnectionParam
713 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800714 * Description Update connection parameters, can only be used when
Myles Watson1baaae32016-11-09 14:25:23 -0800715 * connection is up.
Myles Watson8af480e2016-11-09 10:40:23 -0800716 *
717 * Parameters: bd_addr - BD address of the peer
Myles Watson1baaae32016-11-09 14:25:23 -0800718 * min_int - minimum connection interval,
719 * [0x0004 ~ 0x4000]
720 * max_int - maximum connection interval,
721 * [0x0004 ~ 0x4000]
Myles Watson8af480e2016-11-09 10:40:23 -0800722 * latency - slave latency [0 ~ 500]
723 * timeout - supervision timeout [0x000a ~ 0xc80]
724 *
725 * Returns void
726 *
727 ******************************************************************************/
Jakub Pawlowski154be112018-01-22 10:22:43 -0800728void BTA_DmBleUpdateConnectionParams(const RawAddress& bd_addr,
729 uint16_t min_int, uint16_t max_int,
Stanley Tnga0b984e2018-03-19 12:48:04 -0700730 uint16_t latency, uint16_t timeout,
731 uint16_t min_ce_len, uint16_t max_ce_len) {
732 do_in_bta_thread(
733 FROM_HERE, base::Bind(bta_dm_ble_update_conn_params, bd_addr, min_int,
734 max_int, latency, timeout, min_ce_len, max_ce_len));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800735}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800736
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800737/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800738 *
739 * Function BTA_DmBleConfigLocalPrivacy
740 *
741 * Description Enable/disable privacy on the local device
742 *
743 * Parameters: privacy_enable - enable/disabe privacy on remote device.
744 *
745 * Returns void
746 *
747 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800748void BTA_DmBleConfigLocalPrivacy(bool privacy_enable) {
Myles Watson84baa7f2016-11-14 12:05:37 -0800749#if (BLE_PRIVACY_SPT == TRUE)
Jakub Pawlowski154be112018-01-22 10:22:43 -0800750 do_in_bta_thread(FROM_HERE,
751 base::Bind(bta_dm_ble_config_local_privacy, privacy_enable));
Wei Wanged534e32014-05-20 06:30:13 +0000752#else
Myles Watsoncd1fd072016-11-09 13:17:43 -0800753 UNUSED(privacy_enable);
Wei Wanged534e32014-05-20 06:30:13 +0000754#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800755}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800756
757/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800758 *
Myles Watson8af480e2016-11-09 10:40:23 -0800759 * Function BTA_DmBleGetEnergyInfo
760 *
761 * Description This function is called to obtain the energy info
762 *
763 * Parameters p_cmpl_cback - Command complete callback
764 *
765 * Returns void
766 *
767 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800768void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK* p_cmpl_cback) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800769 do_in_bta_thread(FROM_HERE,
770 base::Bind(bta_dm_ble_get_energy_info, p_cmpl_cback));
Satya Callojie5ba8842014-07-03 17:18:02 -0700771}
772
Jakub Pawlowski154be112018-01-22 10:22:43 -0800773/** This function is to set maximum LE data packet size */
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700774void BTA_DmBleSetDataLength(const RawAddress& remote_device,
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700775 uint16_t tx_data_length) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800776 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_ble_set_data_length,
777 remote_device, tx_data_length));
Priti Aghera636d6712014-12-18 13:55:48 -0800778}
779
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700780/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800781 *
782 * Function BTA_DmSetEncryption
783 *
784 * Description This function is called to ensure that connection is
785 * encrypted. Should be called only on an open connection.
786 * Typically only needed for connections that first want to
787 * bring up unencrypted links, then later encrypt them.
788 *
789 * Parameters: bd_addr - Address of the peer device
790 * transport - transport of the link to be encruypted
791 * p_callback - Pointer to callback function to indicat the
792 * link encryption status
793 * sec_act - This is the security action to indicate
Myles Watson1baaae32016-11-09 14:25:23 -0800794 * what kind of BLE security level is required
795 * for the BLE link if BLE is supported.
Myles Watsoncd1fd072016-11-09 13:17:43 -0800796 * Note: This parameter is ignored for the
Myles Watson1baaae32016-11-09 14:25:23 -0800797 * BR/EDR or if BLE is not supported.
Myles Watson8af480e2016-11-09 10:40:23 -0800798 *
799 * Returns void
800 *
801 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700802void BTA_DmSetEncryption(const RawAddress& bd_addr, tBTA_TRANSPORT transport,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800803 tBTA_DM_ENCRYPT_CBACK* p_callback,
804 tBTA_DM_BLE_SEC_ACT sec_act) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800805 APPL_TRACE_API("%s", __func__);
Jakub Pawlowski154be112018-01-22 10:22:43 -0800806 do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_set_encryption, bd_addr,
807 transport, p_callback, sec_act));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800808}
809
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800810/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800811 *
812 * Function BTA_DmCloseACL
813 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800814 * Description This function force to close an ACL connection and remove
Myles Watson1baaae32016-11-09 14:25:23 -0800815 * the device from the security database list of known devices.
Myles Watson8af480e2016-11-09 10:40:23 -0800816 *
817 * Parameters: bd_addr - Address of the peer device
818 * remove_dev - remove device or not after link down
819 *
820 * Returns void
821 *
822 ******************************************************************************/
Jakub Pawlowskia484a882017-06-24 17:30:18 -0700823void BTA_DmCloseACL(const RawAddress& bd_addr, bool remove_dev,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800824 tBTA_TRANSPORT transport) {
Jakub Pawlowski154be112018-01-22 10:22:43 -0800825 do_in_bta_thread(
826 FROM_HERE, base::Bind(bta_dm_close_acl, bd_addr, remove_dev, transport));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800827}
828
829/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800830 *
831 * Function BTA_DmBleObserve
832 *
833 * Description This procedure keep the device listening for advertising
834 * events from a broadcast device.
835 *
836 * Parameters start: start or stop observe.
837 *
838 * Returns void
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800839
Myles Watson8af480e2016-11-09 10:40:23 -0800840 *
841 * Returns void.
842 *
843 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700844extern void BTA_DmBleObserve(bool start, uint8_t duration,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800845 tBTA_DM_SEARCH_CBACK* p_results_cb) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800846 APPL_TRACE_API("%s:start = %d ", __func__, start);
Jakub Pawlowski154be112018-01-22 10:22:43 -0800847 do_in_bta_thread(
848 FROM_HERE, base::Bind(bta_dm_ble_observe, start, duration, p_results_cb));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800849}
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700850
851/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800852 *
853 * Function BTA_VendorInit
854 *
855 * Description This function initializes vendor specific
856 *
857 * Returns void
858 *
859 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800860void BTA_VendorInit(void) { APPL_TRACE_API("BTA_VendorInit"); }
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700861
862/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800863 *
864 * Function BTA_VendorCleanup
865 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800866 * Description This function frees up Broadcom specific VS specific dynamic
Myles Watson1baaae32016-11-09 14:25:23 -0800867 * memory
Myles Watson8af480e2016-11-09 10:40:23 -0800868 *
869 * Returns void
870 *
871 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800872void BTA_VendorCleanup(void) {
873 tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
874 BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700875
Myles Watsoncd1fd072016-11-09 13:17:43 -0800876 if (cmn_ble_vsc_cb.max_filter > 0) {
877 btm_ble_adv_filter_cleanup();
Marie Janssene9e58ce2016-06-17 14:12:17 -0700878#if (BLE_PRIVACY_SPT == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800879 btm_ble_resolving_list_cleanup();
Satya Calloji444a8da2015-03-06 10:38:22 -0800880#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -0800881 }
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700882
Myles Watsoncd1fd072016-11-09 13:17:43 -0800883 if (cmn_ble_vsc_cb.tot_scan_results_strg > 0) btm_ble_batchscan_cleanup();
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700884
Myles Watsoncd1fd072016-11-09 13:17:43 -0800885 if (cmn_ble_vsc_cb.adv_inst_max > 0) btm_ble_multi_adv_cleanup();
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700886}