blob: 8bc69e1aef8977ee22e9548eb041e8969750b0bb [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Satya Callojic4e25962014-05-10 23:46:24 -07003 * Copyright (C) 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
38/*****************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080039 * Constants
40 ****************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080041
Myles Watsoncd1fd072016-11-09 13:17:43 -080042static const tBTA_SYS_REG bta_dm_reg = {bta_dm_sm_execute, bta_dm_sm_disable};
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, &bta_dm_reg);
63 bta_sys_register(BTA_ID_DM_SEARCH, &bta_dm_search_reg);
The Android Open Source Project5738f832012-12-12 16:00:35 -080064
Myles Watsoncd1fd072016-11-09 13:17:43 -080065 /* if UUID list is not provided as static data */
66 bta_sys_eir_register(bta_dm_eir_update_uuid);
The Android Open Source Project5738f832012-12-12 16:00:35 -080067
Myles Watsoncd1fd072016-11-09 13:17:43 -080068 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;
The Android Open Source Project5738f832012-12-12 16:00:35 -080072
Myles Watsoncd1fd072016-11-09 13:17:43 -080073 bta_sys_sendmsg(p_msg);
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -080074
Myles Watsoncd1fd072016-11-09 13:17:43 -080075 return BTA_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -080076}
77
78/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080079 *
80 * Function BTA_DisableBluetooth
81 *
82 * Description Disables bluetooth service. This function is called when
83 * the application no longer needs bluetooth service
84 *
85 * Returns void
86 *
87 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -080088tBTA_STATUS BTA_DisableBluetooth(void) {
89 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
The Android Open Source Project5738f832012-12-12 16:00:35 -080090
Myles Watsoncd1fd072016-11-09 13:17:43 -080091 p_msg->event = BTA_DM_API_DISABLE_EVT;
The Android Open Source Project5738f832012-12-12 16:00:35 -080092
Myles Watsoncd1fd072016-11-09 13:17:43 -080093 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -080094
Myles Watsoncd1fd072016-11-09 13:17:43 -080095 return BTA_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -080096}
97
98/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080099 *
100 * Function BTA_EnableTestMode
101 *
102 * Description Enables bluetooth device under test mode
103 *
104 *
105 * Returns tBTA_STATUS
106 *
107 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800108tBTA_STATUS BTA_EnableTestMode(void) {
109 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800110
Myles Watsoncd1fd072016-11-09 13:17:43 -0800111 APPL_TRACE_API("%s", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800112
Myles Watsoncd1fd072016-11-09 13:17:43 -0800113 p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
114 bta_sys_sendmsg(p_msg);
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800115
Myles Watsoncd1fd072016-11-09 13:17:43 -0800116 return BTA_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800117}
118
119/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800120 *
121 * Function BTA_DisableTestMode
122 *
123 * Description Disable bluetooth device under test mode
124 *
125 *
126 * Returns None
127 *
128 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800129void BTA_DisableTestMode(void) {
130 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800131
Myles Watsoncd1fd072016-11-09 13:17:43 -0800132 APPL_TRACE_API("%s", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800133
Myles Watsoncd1fd072016-11-09 13:17:43 -0800134 p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
135 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800136}
137
138/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800139 *
140 * Function BTA_DmSetDeviceName
141 *
142 * Description This function sets the Bluetooth name of local device
143 *
144 *
145 * Returns void
146 *
147 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800148void 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));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800151
Myles Watsoncd1fd072016-11-09 13:17:43 -0800152 p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
153 strlcpy((char*)p_msg->name, p_name, BD_NAME_LEN);
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800154
Myles Watsoncd1fd072016-11-09 13:17:43 -0800155 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_DmSetVisibility
161 *
162 * Description This function sets the Bluetooth connectable,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800163 * discoverable, pairable and conn paired only modes of local
Myles Watson1baaae32016-11-09 14:25:23 -0800164 * device
Myles Watson8af480e2016-11-09 10:40:23 -0800165 *
166 *
167 * Returns void
168 *
169 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800170void 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));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800174
Myles Watsoncd1fd072016-11-09 13:17:43 -0800175 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;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800180
Myles Watsoncd1fd072016-11-09 13:17:43 -0800181 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800182}
183
184/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800185 *
186 * Function BTA_DmSearch
187 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800188 * Description This function searches for peer Bluetooth devices. It
Myles Watson1baaae32016-11-09 14:25:23 -0800189 * performs an inquiry and gets the remote name for devices.
190 * Service discovery is done if services is non zero
Myles Watson8af480e2016-11-09 10:40:23 -0800191 *
192 *
193 * Returns void
194 *
195 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800196void 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));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800200
Myles Watsoncd1fd072016-11-09 13:17:43 -0800201 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;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800206
Myles Watsoncd1fd072016-11-09 13:17:43 -0800207 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800208}
209
The Android Open Source Project5738f832012-12-12 16:00:35 -0800210/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800211 *
212 * Function BTA_DmSearchCancel
213 *
214 * Description This function cancels a search initiated by BTA_DmSearch
215 *
216 *
217 * Returns void
218 *
219 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800220void BTA_DmSearchCancel(void) {
221 BT_HDR* p_msg = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800222
Myles Watsoncd1fd072016-11-09 13:17:43 -0800223 p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
224 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800225}
226
227/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800228 *
229 * Function BTA_DmDiscover
230 *
231 * Description This function does service discovery for services of a
232 * peer device
233 *
234 *
235 * Returns void
236 *
237 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700238void BTA_DmDiscover(const bt_bdaddr_t& bd_addr, tBTA_SERVICE_MASK services,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800239 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));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800242
Myles Watsoncd1fd072016-11-09 13:17:43 -0800243 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700244 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800245 p_msg->services = services;
246 p_msg->p_cback = p_cback;
247 p_msg->sdp_search = sdp_search;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800248
Myles Watsoncd1fd072016-11-09 13:17:43 -0800249 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800250}
251
252/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800253 *
254 * Function BTA_DmDiscoverUUID
255 *
256 * Description This function does service discovery for services of a
257 * peer device
258 *
259 *
260 * Returns void
261 *
262 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700263void BTA_DmDiscoverUUID(const bt_bdaddr_t& bd_addr, tSDP_UUID* uuid,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800264 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));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800267
Myles Watsoncd1fd072016-11-09 13:17:43 -0800268 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700269 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800270 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;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800273
Myles Watsoncd1fd072016-11-09 13:17:43 -0800274 p_msg->num_uuid = 0;
275 p_msg->p_uuid = NULL;
Myles Watson99791212016-11-18 08:42:23 -0800276
Myles Watsoncd1fd072016-11-09 13:17:43 -0800277 memcpy(&p_msg->uuid, uuid, sizeof(tSDP_UUID));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800278
Myles Watsoncd1fd072016-11-09 13:17:43 -0800279 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800280}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800281
282/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800283 *
284 * Function BTA_DmBond
285 *
286 * Description This function initiates a bonding procedure with a peer
287 * device
288 *
289 *
290 * Returns void
291 *
292 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700293void BTA_DmBond(const bt_bdaddr_t& bd_addr) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800294 tBTA_DM_API_BOND* p_msg =
295 (tBTA_DM_API_BOND*)osi_malloc(sizeof(tBTA_DM_API_BOND));
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -0700296
Myles Watsoncd1fd072016-11-09 13:17:43 -0800297 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700298 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800299 p_msg->transport = BTA_TRANSPORT_UNKNOWN;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800300
Myles Watsoncd1fd072016-11-09 13:17:43 -0800301 bta_sys_sendmsg(p_msg);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700302}
303
304/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800305 *
306 * Function BTA_DmBondByTransports
307 *
308 * Description This function initiates a bonding procedure with a peer
309 * device
310 *
311 *
312 * Returns void
313 *
314 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700315void BTA_DmBondByTransport(const bt_bdaddr_t& bd_addr,
316 tBTA_TRANSPORT transport) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800317 tBTA_DM_API_BOND* p_msg =
318 (tBTA_DM_API_BOND*)osi_malloc(sizeof(tBTA_DM_API_BOND));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800319
Myles Watsoncd1fd072016-11-09 13:17:43 -0800320 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700321 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800322 p_msg->transport = transport;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800323
Myles Watsoncd1fd072016-11-09 13:17:43 -0800324 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800325}
326
327/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800328 *
329 * Function BTA_DmBondCancel
330 *
331 * Description This function cancels the bonding procedure with a peer
332 * device
333 *
334 *
335 * Returns void
336 *
337 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700338void BTA_DmBondCancel(const bt_bdaddr_t& bd_addr) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800339 tBTA_DM_API_BOND_CANCEL* p_msg =
340 (tBTA_DM_API_BOND_CANCEL*)osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800341
Myles Watsoncd1fd072016-11-09 13:17:43 -0800342 p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700343 p_msg->bd_addr = bd_addr;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800344
Myles Watsoncd1fd072016-11-09 13:17:43 -0800345 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800346}
347
348/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800349 *
350 * Function BTA_DmPinReply
351 *
352 * Description This function provides a pincode for a remote device when
353 * one is requested by DM through BTA_DM_PIN_REQ_EVT
354 *
355 *
356 * Returns void
357 *
358 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700359void BTA_DmPinReply(const bt_bdaddr_t& bd_addr, bool accept, uint8_t pin_len,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800360 uint8_t* p_pin)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800361
362{
Myles Watsoncd1fd072016-11-09 13:17:43 -0800363 tBTA_DM_API_PIN_REPLY* p_msg =
364 (tBTA_DM_API_PIN_REPLY*)osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800365
Myles Watsoncd1fd072016-11-09 13:17:43 -0800366 p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700367 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800368 p_msg->accept = accept;
369 if (accept) {
370 p_msg->pin_len = pin_len;
371 memcpy(p_msg->p_pin, p_pin, pin_len);
372 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800373
Myles Watsoncd1fd072016-11-09 13:17:43 -0800374 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800375}
376
The Android Open Source Project5738f832012-12-12 16:00:35 -0800377/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800378 *
379 * Function BTA_DmLocalOob
380 *
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
384 * connections (SC)
385 * - bta_dm_co_loc_oob() if device doesn't support SC
386 *
387 * Returns void
388 *
389 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800390void 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));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800393
Myles Watsoncd1fd072016-11-09 13:17:43 -0800394 p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
395 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800396}
Jakub Pawlowski175da702015-11-12 15:00:58 -0800397
The Android Open Source Project5738f832012-12-12 16:00:35 -0800398/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800399 *
400 * Function BTA_DmConfirm
401 *
402 * Description This function accepts or rejects the numerical value of the
403 * Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
404 *
405 * Returns void
406 *
407 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700408void BTA_DmConfirm(const bt_bdaddr_t& bd_addr, bool accept) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800409 tBTA_DM_API_CONFIRM* p_msg =
410 (tBTA_DM_API_CONFIRM*)osi_malloc(sizeof(tBTA_DM_API_CONFIRM));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800411
Myles Watsoncd1fd072016-11-09 13:17:43 -0800412 p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700413 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800414 p_msg->accept = accept;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800415
Myles Watsoncd1fd072016-11-09 13:17:43 -0800416 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800417}
418
419/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800420 *
421 * Function BTA_DmAddDevice
422 *
423 * Description This function adds a device to the security database list of
424 * peer device
425 *
426 *
427 * Returns void
428 *
429 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700430void BTA_DmAddDevice(const bt_bdaddr_t& 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) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800434 tBTA_DM_API_ADD_DEVICE* p_msg =
435 (tBTA_DM_API_ADD_DEVICE*)osi_calloc(sizeof(tBTA_DM_API_ADD_DEVICE));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800436
Myles Watsoncd1fd072016-11-09 13:17:43 -0800437 p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700438 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800439 p_msg->tm = trusted_mask;
440 p_msg->is_trusted = is_trusted;
441 p_msg->io_cap = io_cap;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800442
Myles Watsoncd1fd072016-11-09 13:17:43 -0800443 if (link_key) {
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);
447 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800448
Myles Watsoncd1fd072016-11-09 13:17:43 -0800449 /* Load device class if specified */
450 if (dev_class) {
451 p_msg->dc_known = true;
452 memcpy(p_msg->dc, dev_class, DEV_CLASS_LEN);
453 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800454
Myles Watsoncd1fd072016-11-09 13:17:43 -0800455 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;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800458
Myles Watsoncd1fd072016-11-09 13:17:43 -0800459 bta_sys_sendmsg(p_msg);
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800460}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800461
462/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800463 *
464 * Function BTA_DmRemoveDevice
465 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800466 * Description This function removes a device fromthe security database
Myles Watson1baaae32016-11-09 14:25:23 -0800467 * list of peer device. It manages unpairing even while
468 * connected.
Myles Watson8af480e2016-11-09 10:40:23 -0800469 *
470 *
471 * Returns void
472 *
473 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700474tBTA_STATUS BTA_DmRemoveDevice(const bt_bdaddr_t& bd_addr) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800475 tBTA_DM_API_REMOVE_DEVICE* p_msg =
476 (tBTA_DM_API_REMOVE_DEVICE*)osi_calloc(sizeof(tBTA_DM_API_REMOVE_DEVICE));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800477
Myles Watsoncd1fd072016-11-09 13:17:43 -0800478 p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700479 p_msg->bd_addr = bd_addr;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800480
Myles Watsoncd1fd072016-11-09 13:17:43 -0800481 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800482
Myles Watsoncd1fd072016-11-09 13:17:43 -0800483 return BTA_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800484}
485
486/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800487 *
488 * Function BTA_GetEirService
489 *
490 * Description This function is called to get BTA service mask from EIR.
491 *
492 * Parameters p_eir - pointer of EIR significant part
493 * p_services - return the BTA service mask
494 *
495 * Returns None
496 *
497 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800498extern const uint16_t bta_service_id_to_uuid_lkup_tbl[];
Jakub Pawlowski0595ca02017-02-07 12:15:06 -0800499void BTA_GetEirService(uint8_t* p_eir, size_t eir_len,
500 tBTA_SERVICE_MASK* p_services) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800501 uint8_t xx, yy;
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;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800506
Jakub Pawlowski0595ca02017-02-07 12:15:06 -0800507 BTM_GetEirUuidList(p_eir, eir_len, LEN_UUID_16, &num_uuid, uuid_list,
508 max_num_uuid);
Myles Watsoncd1fd072016-11-09 13:17:43 -0800509 for (xx = 0; xx < num_uuid; xx++) {
510 mask = 1;
511 for (yy = 0; yy < BTA_MAX_SERVICE_ID; yy++) {
512 if (*(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy]) {
513 *p_services |= mask;
514 break;
515 }
516 mask <<= 1;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800517 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800518
519 /* for HSP v1.2 only device */
520 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS)
521 *p_services |= BTA_HSP_SERVICE_MASK;
522
523 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE)
524 *p_services |= BTA_HL_SERVICE_MASK;
525
526 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK)
527 *p_services |= BTA_HL_SERVICE_MASK;
528 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800529}
530
531/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800532 *
533 * Function BTA_DmGetConnectionState
534 *
535 * Description Returns whether the remote device is currently connected.
536 *
537 * Returns 0 if the device is NOT connected.
538 *
539 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700540uint16_t BTA_DmGetConnectionState(const bt_bdaddr_t& bd_addr) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800541 tBTA_DM_PEER_DEVICE* p_dev = bta_dm_find_peer_device(bd_addr);
542 return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
Andre Eisenbach5c0b0522014-06-18 12:20:37 -0700543}
544
Andre Eisenbach5c0b0522014-06-18 12:20:37 -0700545/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800546 * Device Identification (DI) Server Functions
547 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800548/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800549 *
550 * Function BTA_DmSetLocalDiRecord
551 *
552 * Description This function adds a DI record to the local SDP database.
553 *
554 * Returns BTA_SUCCESS if record set sucessfully, otherwise error code.
555 *
556 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800557tBTA_STATUS BTA_DmSetLocalDiRecord(tBTA_DI_RECORD* p_device_info,
558 uint32_t* p_handle) {
559 tBTA_STATUS status = BTA_FAILURE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800560
Myles Watsoncd1fd072016-11-09 13:17:43 -0800561 if (bta_dm_di_cb.di_num < BTA_DI_NUM_MAX) {
562 if (SDP_SetLocalDiRecord((tSDP_DI_RECORD*)p_device_info, p_handle) ==
563 SDP_SUCCESS) {
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++;
567 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800568
Myles Watsoncd1fd072016-11-09 13:17:43 -0800569 bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
570 status = BTA_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800571 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800572 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800573
Myles Watsoncd1fd072016-11-09 13:17:43 -0800574 return status;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800575}
576
577/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800578 *
579 * Function bta_dmexecutecallback
580 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800581 * Description This function will request BTA to execute a call back in the
Myles Watson1baaae32016-11-09 14:25:23 -0800582 * context of BTU task.
Myles Watson8af480e2016-11-09 10:40:23 -0800583 * This API was named in lower case because it is only intended
584 * for the internal customers(like BTIF).
585 *
586 * Returns void
587 *
588 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800589void 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));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800592
Myles Watsoncd1fd072016-11-09 13:17:43 -0800593 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;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800596
Myles Watsoncd1fd072016-11-09 13:17:43 -0800597 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800598}
599
600/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800601 *
602 * Function BTA_DmAddBleKey
603 *
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.
607 *
608 * Parameters: bd_addr - BD address of the peer
609 * p_le_key - LE key values.
610 * key_type - LE SMP key type.
611 *
612 * Returns BTA_SUCCESS if successful
613 * BTA_FAIL if operation failed.
614 *
615 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700616void BTA_DmAddBleKey(const bt_bdaddr_t& bd_addr, tBTA_LE_KEY_VALUE* p_le_key,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800617 tBTA_LE_KEY_TYPE key_type) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800618 tBTA_DM_API_ADD_BLEKEY* p_msg =
619 (tBTA_DM_API_ADD_BLEKEY*)osi_calloc(sizeof(tBTA_DM_API_ADD_BLEKEY));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800620
Myles Watsoncd1fd072016-11-09 13:17:43 -0800621 p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
622 p_msg->key_type = key_type;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700623 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800624 memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800625
Myles Watsoncd1fd072016-11-09 13:17:43 -0800626 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800627}
628
629/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800630 *
631 * Function BTA_DmAddBleDevice
632 *
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.
636 *
637 * Parameters: bd_addr - BD address of the peer
638 * dev_type - Remote device's device type.
639 * addr_type - LE device address type.
640 *
641 * Returns void
642 *
643 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700644void BTA_DmAddBleDevice(const bt_bdaddr_t& bd_addr, tBLE_ADDR_TYPE addr_type,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800645 tBT_DEVICE_TYPE dev_type) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800646 tBTA_DM_API_ADD_BLE_DEVICE* p_msg = (tBTA_DM_API_ADD_BLE_DEVICE*)osi_calloc(
647 sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800648
Myles Watsoncd1fd072016-11-09 13:17:43 -0800649 p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700650 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800651 p_msg->addr_type = addr_type;
652 p_msg->dev_type = dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800653
Myles Watsoncd1fd072016-11-09 13:17:43 -0800654 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800655}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800656
The Android Open Source Project5738f832012-12-12 16:00:35 -0800657/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800658 *
659 * Function BTA_DmBlePasskeyReply
660 *
661 * Description Send BLE SMP passkey reply.
662 *
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,
666 * can be lead by 0.
667 *
668 * Returns void
669 *
670 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700671void BTA_DmBlePasskeyReply(const bt_bdaddr_t& bd_addr, bool accept,
672 uint32_t passkey) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800673 tBTA_DM_API_PASSKEY_REPLY* p_msg =
674 (tBTA_DM_API_PASSKEY_REPLY*)osi_calloc(sizeof(tBTA_DM_API_PASSKEY_REPLY));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800675
Myles Watsoncd1fd072016-11-09 13:17:43 -0800676 p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700677 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800678 p_msg->accept = accept;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800679
Myles Watsoncd1fd072016-11-09 13:17:43 -0800680 if (accept) p_msg->passkey = passkey;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800681
Myles Watsoncd1fd072016-11-09 13:17:43 -0800682 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800683}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800684
The Android Open Source Project5738f832012-12-12 16:00:35 -0800685/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800686 *
687 * Function BTA_DmBleConfirmReply
688 *
689 * Description Send BLE SMP SC user confirmation reply.
690 *
691 * Parameters: bd_addr - BD address of the peer
Myles Watsoncd1fd072016-11-09 13:17:43 -0800692 * accept - numbers to compare are the same or
Myles Watson1baaae32016-11-09 14:25:23 -0800693 * different.
Myles Watson8af480e2016-11-09 10:40:23 -0800694 *
695 * Returns void
696 *
697 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700698void BTA_DmBleConfirmReply(const bt_bdaddr_t& bd_addr, bool accept) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800699 tBTA_DM_API_CONFIRM* p_msg =
700 (tBTA_DM_API_CONFIRM*)osi_calloc(sizeof(tBTA_DM_API_CONFIRM));
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800701
Myles Watsoncd1fd072016-11-09 13:17:43 -0800702 p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700703 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800704 p_msg->accept = accept;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800705
Myles Watsoncd1fd072016-11-09 13:17:43 -0800706 bta_sys_sendmsg(p_msg);
Satya Calloji444a8da2015-03-06 10:38:22 -0800707}
708
709/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800710 *
711 * Function BTA_DmBleSecurityGrant
712 *
713 * Description Grant security request access.
714 *
715 * Parameters: bd_addr - BD address of the peer
716 * res - security grant status.
717 *
718 * Returns void
719 *
720 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700721void BTA_DmBleSecurityGrant(const bt_bdaddr_t& bd_addr,
722 tBTA_DM_BLE_SEC_GRANT res) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800723 tBTA_DM_API_BLE_SEC_GRANT* p_msg =
724 (tBTA_DM_API_BLE_SEC_GRANT*)osi_calloc(sizeof(tBTA_DM_API_BLE_SEC_GRANT));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800725
Myles Watsoncd1fd072016-11-09 13:17:43 -0800726 p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700727 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800728 p_msg->res = res;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800729
Myles Watsoncd1fd072016-11-09 13:17:43 -0800730 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800731}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800732
The Android Open Source Project5738f832012-12-12 16:00:35 -0800733/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800734 *
735 * Function BTA_DmSetBlePrefConnParams
736 *
737 * Description This function is called to set the preferred connection
738 * parameters when default connection parameter is not desired.
739 *
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
747 *
748 *
749 * Returns void
750 *
751 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700752void BTA_DmSetBlePrefConnParams(const bt_bdaddr_t& bd_addr,
753 uint16_t min_conn_int, uint16_t max_conn_int,
754 uint16_t slave_latency,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800755 uint16_t supervision_tout) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800756 tBTA_DM_API_BLE_CONN_PARAMS* p_msg = (tBTA_DM_API_BLE_CONN_PARAMS*)osi_calloc(
757 sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800758
Myles Watsoncd1fd072016-11-09 13:17:43 -0800759 p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700760 p_msg->peer_bda = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800761 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;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800765
Myles Watsoncd1fd072016-11-09 13:17:43 -0800766 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800767}
768
769/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800770 *
771 * Function BTA_DmSetBleConnScanParams
772 *
773 * Description This function is called to set scan parameters used in
774 * BLE connection request
775 *
776 * Parameters: scan_interval - scan interval
777 * scan_window - scan window
778 *
779 * Returns void
780 *
781 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800782void BTA_DmSetBleConnScanParams(uint32_t scan_interval, uint32_t scan_window) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800783 tBTA_DM_API_BLE_SCAN_PARAMS* p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS*)osi_calloc(
784 sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800785
Myles Watsoncd1fd072016-11-09 13:17:43 -0800786 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;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800789
Myles Watsoncd1fd072016-11-09 13:17:43 -0800790 bta_sys_sendmsg(p_msg);
Satya Calloji5725fc62015-03-31 13:24:32 -0700791}
792
Jakub Pawlowski83211b02016-12-07 11:25:15 -0800793/**
794 * Set BLE connectable mode to auto connect
795 */
796void BTA_DmBleStartAutoConn() {
797 tBTA_DM_API_SET_NAME* p_msg =
798 (tBTA_DM_API_SET_NAME*)osi_calloc(sizeof(tBTA_DM_API_SET_NAME));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800799
Myles Watsoncd1fd072016-11-09 13:17:43 -0800800 p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800801 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800802}
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700803
The Android Open Source Project5738f832012-12-12 16:00:35 -0800804/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800805 *
806 * Function bta_dm_discover_send_msg
807 *
808 * Description This function send discover message to BTA task.
809 *
810 * Returns void
811 *
812 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700813static void bta_dm_discover_send_msg(const bt_bdaddr_t& bd_addr,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800814 tBTA_SERVICE_MASK_EXT* p_services,
815 tBTA_DM_SEARCH_CBACK* p_cback,
816 bool sdp_search,
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);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800822
Myles Watsoncd1fd072016-11-09 13:17:43 -0800823 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700824 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800825 p_msg->p_cback = p_cback;
826 p_msg->sdp_search = sdp_search;
827 p_msg->transport = transport;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800828
Myles Watsoncd1fd072016-11-09 13:17:43 -0800829 if (p_services != NULL) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800830 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);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800836 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800837 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800838
Myles Watsoncd1fd072016-11-09 13:17:43 -0800839 bta_sys_sendmsg(p_msg);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700840}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800841
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700842/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800843 *
844 * Function BTA_DmDiscoverByTransport
845 *
846 * Description This function does service discovery on particular transport
847 * for services of a
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.
852 *
853 *
854 *
855 * Returns void
856 *
857 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700858void BTA_DmDiscoverByTransport(const bt_bdaddr_t& bd_addr,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800859 tBTA_SERVICE_MASK_EXT* p_services,
860 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search,
861 tBTA_TRANSPORT transport) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800862 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700863}
864
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700865/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800866 *
867 * Function BTA_DmDiscoverExt
868 *
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.
874 *
875 *
876 *
877 * Returns void
878 *
879 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700880void BTA_DmDiscoverExt(const bt_bdaddr_t& bd_addr,
881 tBTA_SERVICE_MASK_EXT* p_services,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800882 tBTA_DM_SEARCH_CBACK* p_cback, bool sdp_search) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800883 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search,
884 BTA_TRANSPORT_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800885}
886
887/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800888 *
889 * Function BTA_DmSearchExt
890 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800891 * Description This function searches for peer Bluetooth devices. It
Myles Watson1baaae32016-11-09 14:25:23 -0800892 * performs an inquiry and gets the remote name for devices.
893 * Service discovery is done if services is non zero
Myles Watson8af480e2016-11-09 10:40:23 -0800894 *
895 * Parameters p_dm_inq: inquiry conditions
Myles Watsoncd1fd072016-11-09 13:17:43 -0800896 * p_services: if service is not empty, service discovery will
Myles Watson1baaae32016-11-09 14:25:23 -0800897 * 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.
Myles Watson8af480e2016-11-09 10:40:23 -0800901 *
902 *
903 *
904 * Returns void
905 *
906 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800907void 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);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800913
Myles Watsoncd1fd072016-11-09 13:17:43 -0800914 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;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800918
Myles Watsoncd1fd072016-11-09 13:17:43 -0800919 if (p_services != NULL) {
920 p_msg->services = p_services->srvc_mask;
921 p_msg->num_uuid = p_services->num_uuid;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800922
Myles Watsoncd1fd072016-11-09 13:17:43 -0800923 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);
927 } else {
928 p_msg->p_uuid = NULL;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800929 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800930 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800931
Myles Watsoncd1fd072016-11-09 13:17:43 -0800932 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800933}
Myles Watson99791212016-11-18 08:42:23 -0800934
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800935/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800936 *
937 * Function BTA_DmBleUpdateConnectionParam
938 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800939 * Description Update connection parameters, can only be used when
Myles Watson1baaae32016-11-09 14:25:23 -0800940 * connection is up.
Myles Watson8af480e2016-11-09 10:40:23 -0800941 *
942 * Parameters: bd_addr - BD address of the peer
Myles Watson1baaae32016-11-09 14:25:23 -0800943 * min_int - minimum connection interval,
944 * [0x0004 ~ 0x4000]
945 * max_int - maximum connection interval,
946 * [0x0004 ~ 0x4000]
Myles Watson8af480e2016-11-09 10:40:23 -0800947 * latency - slave latency [0 ~ 500]
948 * timeout - supervision timeout [0x000a ~ 0xc80]
949 *
950 * Returns void
951 *
952 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700953void BTA_DmBleUpdateConnectionParam(const bt_bdaddr_t& bd_addr,
954 uint16_t min_int, uint16_t max_int,
955 uint16_t latency, uint16_t timeout) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800956 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));
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -0700959
Myles Watsoncd1fd072016-11-09 13:17:43 -0800960 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -0700961 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800962 p_msg->min_int = min_int;
963 p_msg->max_int = max_int;
964 p_msg->latency = latency;
965 p_msg->timeout = timeout;
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -0700966
Myles Watsoncd1fd072016-11-09 13:17:43 -0800967 bta_sys_sendmsg(p_msg);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800968}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800969
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800970/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800971 *
972 * Function BTA_DmBleConfigLocalPrivacy
973 *
974 * Description Enable/disable privacy on the local device
975 *
976 * Parameters: privacy_enable - enable/disabe privacy on remote device.
977 *
978 * Returns void
979 *
980 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800981void BTA_DmBleConfigLocalPrivacy(bool privacy_enable) {
Myles Watson84baa7f2016-11-14 12:05:37 -0800982#if (BLE_PRIVACY_SPT == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800983 tBTA_DM_API_LOCAL_PRIVACY* p_msg = (tBTA_DM_API_LOCAL_PRIVACY*)osi_calloc(
984 sizeof(tBTA_DM_API_ENABLE_PRIVACY));
Wei Wanged534e32014-05-20 06:30:13 +0000985
Myles Watsoncd1fd072016-11-09 13:17:43 -0800986 p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
987 p_msg->privacy_enable = privacy_enable;
Wei Wanged534e32014-05-20 06:30:13 +0000988
Myles Watsoncd1fd072016-11-09 13:17:43 -0800989 bta_sys_sendmsg(p_msg);
Wei Wanged534e32014-05-20 06:30:13 +0000990#else
Myles Watsoncd1fd072016-11-09 13:17:43 -0800991 UNUSED(privacy_enable);
Wei Wanged534e32014-05-20 06:30:13 +0000992#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800993}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800994
995/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800996 *
Myles Watson8af480e2016-11-09 10:40:23 -0800997 * Function BTA_DmBleGetEnergyInfo
998 *
999 * Description This function is called to obtain the energy info
1000 *
1001 * Parameters p_cmpl_cback - Command complete callback
1002 *
1003 * Returns void
1004 *
1005 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -08001006void 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);
Satya Callojie5ba8842014-07-03 17:18:02 -07001009
Myles Watsoncd1fd072016-11-09 13:17:43 -08001010 APPL_TRACE_API("%s", __func__);
Satya Callojie5ba8842014-07-03 17:18:02 -07001011
Myles Watsoncd1fd072016-11-09 13:17:43 -08001012 p_msg->hdr.event = BTA_DM_API_BLE_ENERGY_INFO_EVT;
1013 p_msg->p_energy_info_cback = p_cmpl_cback;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001014
Myles Watsoncd1fd072016-11-09 13:17:43 -08001015 bta_sys_sendmsg(p_msg);
Satya Callojie5ba8842014-07-03 17:18:02 -07001016}
1017
1018/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001019 *
Myles Watson8af480e2016-11-09 10:40:23 -08001020 * Function BTA_DmBleUpdateConnectionParams
1021 *
Myles Watsoncd1fd072016-11-09 13:17:43 -08001022 * Description Update connection parameters, can only be used when
Myles Watson1baaae32016-11-09 14:25:23 -08001023 * connection is up.
Myles Watson8af480e2016-11-09 10:40:23 -08001024 *
1025 * Parameters: bd_addr - BD address of the peer
Myles Watson1baaae32016-11-09 14:25:23 -08001026 * min_int - minimum connection interval,
1027 * [0x0004 ~ 0x4000]
1028 * max_int - maximum connection interval,
1029 * [0x0004 ~ 0x4000]
Myles Watson8af480e2016-11-09 10:40:23 -08001030 * latency - slave latency [0 ~ 500]
1031 * timeout - supervision timeout [0x000a ~ 0xc80]
1032 *
1033 * Returns void
1034 *
1035 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -07001036void BTA_DmBleUpdateConnectionParams(const bt_bdaddr_t& bd_addr,
1037 uint16_t min_int, uint16_t max_int,
1038 uint16_t latency, uint16_t timeout) {
Myles Watsoncd1fd072016-11-09 13:17:43 -08001039 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));
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001042
Myles Watsoncd1fd072016-11-09 13:17:43 -08001043 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -07001044 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -08001045 p_msg->min_int = min_int;
1046 p_msg->max_int = max_int;
1047 p_msg->latency = latency;
1048 p_msg->timeout = timeout;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001049
Myles Watsoncd1fd072016-11-09 13:17:43 -08001050 bta_sys_sendmsg(p_msg);
Wei Wangea850482014-05-20 04:52:26 +00001051}
Priti Aghera636d6712014-12-18 13:55:48 -08001052
1053/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001054 *
1055 * Function BTA_DmBleSetDataLength
1056 *
1057 * Description This function is to set maximum LE data packet size
1058 *
1059 * Returns void
1060 *
1061 *
1062 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -07001063void BTA_DmBleSetDataLength(const bt_bdaddr_t& remote_device,
1064 uint16_t tx_data_length) {
Myles Watsoncd1fd072016-11-09 13:17:43 -08001065 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));
Priti Aghera636d6712014-12-18 13:55:48 -08001068
Jakub Pawlowskic2276b02017-06-09 16:00:25 -07001069 p_msg->remote_bda = remote_device;
Myles Watsoncd1fd072016-11-09 13:17:43 -08001070 p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
1071 p_msg->tx_data_length = tx_data_length;
Priti Aghera636d6712014-12-18 13:55:48 -08001072
Myles Watsoncd1fd072016-11-09 13:17:43 -08001073 bta_sys_sendmsg(p_msg);
Priti Aghera636d6712014-12-18 13:55:48 -08001074}
1075
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001076/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001077 *
1078 * Function BTA_DmSetEncryption
1079 *
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.
1084 *
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
Myles Watson1baaae32016-11-09 14:25:23 -08001090 * what kind of BLE security level is required
1091 * for the BLE link if BLE is supported.
Myles Watsoncd1fd072016-11-09 13:17:43 -08001092 * Note: This parameter is ignored for the
Myles Watson1baaae32016-11-09 14:25:23 -08001093 * BR/EDR or if BLE is not supported.
Myles Watson8af480e2016-11-09 10:40:23 -08001094 *
1095 * Returns void
1096 *
1097 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -07001098void BTA_DmSetEncryption(const bt_bdaddr_t& bd_addr, tBTA_TRANSPORT transport,
Myles Watsoncd1fd072016-11-09 13:17:43 -08001099 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));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001103
Myles Watsoncd1fd072016-11-09 13:17:43 -08001104 APPL_TRACE_API("%s", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001105
Myles Watsoncd1fd072016-11-09 13:17:43 -08001106 p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -07001107 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -08001108 p_msg->transport = transport;
1109 p_msg->p_callback = p_callback;
1110 p_msg->sec_act = sec_act;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001111
Myles Watsoncd1fd072016-11-09 13:17:43 -08001112 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001113}
1114
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001115/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001116 *
1117 * Function BTA_DmCloseACL
1118 *
Myles Watsoncd1fd072016-11-09 13:17:43 -08001119 * Description This function force to close an ACL connection and remove
Myles Watson1baaae32016-11-09 14:25:23 -08001120 * the device from the security database list of known devices.
Myles Watson8af480e2016-11-09 10:40:23 -08001121 *
1122 * Parameters: bd_addr - Address of the peer device
1123 * remove_dev - remove device or not after link down
1124 *
1125 * Returns void
1126 *
1127 ******************************************************************************/
Jakub Pawlowskic2276b02017-06-09 16:00:25 -07001128void BTA_DmCloseACL(const bt_bdaddr_t& bd_addr, bool remove_dev,
Myles Watsoncd1fd072016-11-09 13:17:43 -08001129 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));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001132
Myles Watsoncd1fd072016-11-09 13:17:43 -08001133 APPL_TRACE_API("%s", __func__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001134
Myles Watsoncd1fd072016-11-09 13:17:43 -08001135 p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
Jakub Pawlowskic2276b02017-06-09 16:00:25 -07001136 p_msg->bd_addr = bd_addr;
Myles Watsoncd1fd072016-11-09 13:17:43 -08001137 p_msg->remove_dev = remove_dev;
1138 p_msg->transport = transport;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001139
Myles Watsoncd1fd072016-11-09 13:17:43 -08001140 bta_sys_sendmsg(p_msg);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001141}
1142
1143/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001144 *
1145 * Function BTA_DmBleObserve
1146 *
1147 * Description This procedure keep the device listening for advertising
1148 * events from a broadcast device.
1149 *
1150 * Parameters start: start or stop observe.
1151 *
1152 * Returns void
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001153
Myles Watson8af480e2016-11-09 10:40:23 -08001154 *
1155 * Returns void.
1156 *
1157 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001158extern void BTA_DmBleObserve(bool start, uint8_t duration,
Myles Watsoncd1fd072016-11-09 13:17:43 -08001159 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));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001162
Myles Watsoncd1fd072016-11-09 13:17:43 -08001163 APPL_TRACE_API("%s:start = %d ", __func__, start);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001164
Myles Watsoncd1fd072016-11-09 13:17:43 -08001165 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;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001169
Myles Watsoncd1fd072016-11-09 13:17:43 -08001170 bta_sys_sendmsg(p_msg);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001171}
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001172
1173/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001174 *
1175 * Function BTA_VendorInit
1176 *
1177 * Description This function initializes vendor specific
1178 *
1179 * Returns void
1180 *
1181 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -08001182void BTA_VendorInit(void) { APPL_TRACE_API("BTA_VendorInit"); }
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001183
1184/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001185 *
1186 * Function BTA_VendorCleanup
1187 *
Myles Watsoncd1fd072016-11-09 13:17:43 -08001188 * Description This function frees up Broadcom specific VS specific dynamic
Myles Watson1baaae32016-11-09 14:25:23 -08001189 * memory
Myles Watson8af480e2016-11-09 10:40:23 -08001190 *
1191 * Returns void
1192 *
1193 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -08001194void BTA_VendorCleanup(void) {
1195 tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
1196 BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001197
Myles Watsoncd1fd072016-11-09 13:17:43 -08001198 if (cmn_ble_vsc_cb.max_filter > 0) {
1199 btm_ble_adv_filter_cleanup();
Marie Janssene9e58ce2016-06-17 14:12:17 -07001200#if (BLE_PRIVACY_SPT == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -08001201 btm_ble_resolving_list_cleanup();
Satya Calloji444a8da2015-03-06 10:38:22 -08001202#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -08001203 }
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001204
Myles Watsoncd1fd072016-11-09 13:17:43 -08001205 if (cmn_ble_vsc_cb.tot_scan_results_strg > 0) btm_ble_batchscan_cleanup();
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001206
Myles Watsoncd1fd072016-11-09 13:17:43 -08001207 if (cmn_ble_vsc_cb.adv_inst_max > 0) btm_ble_multi_adv_cleanup();
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001208}