blob: f41bbfe0867e4657e785c682dc0d08a06ce21207 [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 ******************************************************************************/
24
Pavlin Radoslavov258c2532015-09-27 20:59:05 -070025#include "bt_common.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080026#include "bta_sys.h"
27#include "bta_api.h"
Jakub Pawlowski5b12a832016-08-11 03:30:47 -070028#include "bta_closure_api.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080029#include "bta_dm_int.h"
30#include "bta_sys_int.h"
31#include "btm_api.h"
32#include "btm_int.h"
Myles Watsond7ffd642016-10-27 10:27:36 -070033#include "osi/include/osi.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080034#include <string.h>
Mike J. Chen5cd8bff2014-01-31 18:16:59 -080035#include "utl.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080036
37/*****************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080038 * Constants
39 ****************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080040
41static const tBTA_SYS_REG bta_dm_reg =
42{
43 bta_dm_sm_execute,
44 bta_dm_sm_disable
45};
46
47static const tBTA_SYS_REG bta_dm_search_reg =
48{
49 bta_dm_search_sm_execute,
50 bta_dm_search_sm_disable
51};
52
53/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080054 *
55 * Function BTA_EnableBluetooth
56 *
57 * Description Enables bluetooth service. This function must be
58 * called before any other functions in the BTA API are called.
59 *
60 *
61 * Returns tBTA_STATUS
62 *
63 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080064tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
65{
The Android Open Source Project5738f832012-12-12 16:00:35 -080066 /* Bluetooth disabling is in progress */
67 if (bta_dm_cb.disabling)
68 return BTA_FAILURE;
69
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -080070 bta_sys_register(BTA_ID_DM, &bta_dm_reg );
71 bta_sys_register(BTA_ID_DM_SEARCH, &bta_dm_search_reg );
The Android Open Source Project5738f832012-12-12 16:00:35 -080072
73 /* if UUID list is not provided as static data */
74 bta_sys_eir_register(bta_dm_eir_update_uuid);
75
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -080076 tBTA_DM_API_ENABLE *p_msg =
77 (tBTA_DM_API_ENABLE *)osi_malloc(sizeof(tBTA_DM_API_ENABLE));
78 p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
79 p_msg->p_sec_cback = p_cback;
The Android Open Source Project5738f832012-12-12 16:00:35 -080080
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -080081 bta_sys_sendmsg(p_msg);
82
83 return BTA_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -080084}
85
86/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080087 *
88 * Function BTA_DisableBluetooth
89 *
90 * Description Disables bluetooth service. This function is called when
91 * the application no longer needs bluetooth service
92 *
93 * Returns void
94 *
95 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080096tBTA_STATUS BTA_DisableBluetooth(void)
97{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -080098 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
The Android Open Source Project5738f832012-12-12 16:00:35 -080099
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800100 p_msg->event = BTA_DM_API_DISABLE_EVT;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800101
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800102 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800103
104 return BTA_SUCCESS;
105}
106
107/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800108 *
109 * Function BTA_EnableTestMode
110 *
111 * Description Enables bluetooth device under test mode
112 *
113 *
114 * Returns tBTA_STATUS
115 *
116 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800117tBTA_STATUS BTA_EnableTestMode(void)
118{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800119 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800120
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800121 APPL_TRACE_API("%s", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800122
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800123 p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
124 bta_sys_sendmsg(p_msg);
125
126 return BTA_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800127}
128
129/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800130 *
131 * Function BTA_DisableTestMode
132 *
133 * Description Disable bluetooth device under test mode
134 *
135 *
136 * Returns None
137 *
138 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800139void BTA_DisableTestMode(void)
140{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800141 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800142
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800143 APPL_TRACE_API("%s", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800144
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800145 p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
146 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800147}
148
149/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800150 *
151 * Function BTA_DmSetDeviceName
152 *
153 * Description This function sets the Bluetooth name of local device
154 *
155 *
156 * Returns void
157 *
158 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800159void BTA_DmSetDeviceName(char *p_name)
160{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800161 tBTA_DM_API_SET_NAME *p_msg =
162 (tBTA_DM_API_SET_NAME *)osi_malloc(sizeof(tBTA_DM_API_SET_NAME));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800163
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800164 p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
165 strlcpy((char*)p_msg->name, p_name, BD_NAME_LEN);
166
167 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800168}
169
170/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800171 *
172 * Function BTA_DmSetVisibility
173 *
174 * Description This function sets the Bluetooth connectable,
175 * discoverable, pairable and conn paired only modes of local device
176 *
177 *
178 * Returns void
179 *
180 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700181void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, uint8_t pairable_mode, uint8_t conn_filter )
The Android Open Source Project5738f832012-12-12 16:00:35 -0800182{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800183 tBTA_DM_API_SET_VISIBILITY *p_msg =
184 (tBTA_DM_API_SET_VISIBILITY *)osi_malloc(sizeof(tBTA_DM_MSG));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800185
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800186 p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
187 p_msg->disc_mode = disc_mode;
188 p_msg->conn_mode = conn_mode;
189 p_msg->pair_mode = pairable_mode;
190 p_msg->conn_paired_only = conn_filter;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800191
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800192 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800193}
194
195/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800196 *
197 * Function BTA_DmSearch
198 *
199 * Description This function searches for peer Bluetooth devices. It performs
200 * an inquiry and gets the remote name for devices. Service
201 * discovery is done if services is non zero
202 *
203 *
204 * Returns void
205 *
206 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800207void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback)
208{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800209 tBTA_DM_API_SEARCH *p_msg =
210 (tBTA_DM_API_SEARCH *)osi_calloc(sizeof(tBTA_DM_API_SEARCH));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800211
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800212 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
213 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
214 p_msg->services = services;
215 p_msg->p_cback = p_cback;
216 p_msg->rs_res = BTA_DM_RS_NONE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800217
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800218 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800219}
220
The Android Open Source Project5738f832012-12-12 16:00:35 -0800221/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800222 *
223 * Function BTA_DmSearchCancel
224 *
225 * Description This function cancels a search initiated by BTA_DmSearch
226 *
227 *
228 * Returns void
229 *
230 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800231void BTA_DmSearchCancel(void)
232{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800233 BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800234
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800235 p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
236 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800237}
238
239/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800240 *
241 * Function BTA_DmDiscover
242 *
243 * Description This function does service discovery for services of a
244 * peer device
245 *
246 *
247 * Returns void
248 *
249 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800250void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
Marie Janssene9e58ce2016-06-17 14:12:17 -0700251 tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800252{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800253 tBTA_DM_API_DISCOVER *p_msg =
254 (tBTA_DM_API_DISCOVER *)osi_calloc(sizeof(tBTA_DM_API_DISCOVER));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800255
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800256 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
257 bdcpy(p_msg->bd_addr, bd_addr);
258 p_msg->services = services;
259 p_msg->p_cback = p_cback;
260 p_msg->sdp_search = sdp_search;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800261
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800262 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800263}
264
265/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800266 *
267 * Function BTA_DmDiscoverUUID
268 *
269 * Description This function does service discovery for services of a
270 * peer device
271 *
272 *
273 * Returns void
274 *
275 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800276void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
Marie Janssene9e58ce2016-06-17 14:12:17 -0700277 tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800278{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800279 tBTA_DM_API_DISCOVER *p_msg =
280 (tBTA_DM_API_DISCOVER *)osi_malloc(sizeof(tBTA_DM_API_DISCOVER));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800281
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800282 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
283 bdcpy(p_msg->bd_addr, bd_addr);
284 p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level
285 p_msg->p_cback = p_cback;
286 p_msg->sdp_search = sdp_search;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800287
Marie Janssene9e58ce2016-06-17 14:12:17 -0700288#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800289 p_msg->num_uuid = 0;
290 p_msg->p_uuid = NULL;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800291#endif
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800292 memcpy(&p_msg->uuid, uuid, sizeof(tSDP_UUID) );
The Android Open Source Project5738f832012-12-12 16:00:35 -0800293
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800294 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800295}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800296
297/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800298 *
299 * Function BTA_DmBond
300 *
301 * Description This function initiates a bonding procedure with a peer
302 * device
303 *
304 *
305 * Returns void
306 *
307 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800308void BTA_DmBond(BD_ADDR bd_addr)
309{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800310 tBTA_DM_API_BOND *p_msg =
311 (tBTA_DM_API_BOND *)osi_malloc(sizeof(tBTA_DM_API_BOND));
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -0700312
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800313 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
314 bdcpy(p_msg->bd_addr, bd_addr);
315 p_msg->transport = BTA_TRANSPORT_UNKNOWN;
316
317 bta_sys_sendmsg(p_msg);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700318}
319
320/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800321 *
322 * Function BTA_DmBondByTransports
323 *
324 * Description This function initiates a bonding procedure with a peer
325 * device
326 *
327 *
328 * Returns void
329 *
330 ******************************************************************************/
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700331void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport)
332{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800333 tBTA_DM_API_BOND *p_msg =
334 (tBTA_DM_API_BOND *)osi_malloc(sizeof(tBTA_DM_API_BOND));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800335
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800336 p_msg->hdr.event = BTA_DM_API_BOND_EVT;
337 bdcpy(p_msg->bd_addr, bd_addr);
338 p_msg->transport = transport;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800339
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800340 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800341}
342
343/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800344 *
345 * Function BTA_DmBondCancel
346 *
347 * Description This function cancels the bonding procedure with a peer
348 * device
349 *
350 *
351 * Returns void
352 *
353 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800354void BTA_DmBondCancel(BD_ADDR bd_addr)
355{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800356 tBTA_DM_API_BOND_CANCEL *p_msg =
357 (tBTA_DM_API_BOND_CANCEL *)osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800358
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800359 p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
360 bdcpy(p_msg->bd_addr, bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800361
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800362 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800363}
364
365/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800366 *
367 * Function BTA_DmPinReply
368 *
369 * Description This function provides a pincode for a remote device when
370 * one is requested by DM through BTA_DM_PIN_REQ_EVT
371 *
372 *
373 * Returns void
374 *
375 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700376void BTA_DmPinReply(BD_ADDR bd_addr, bool accept, uint8_t pin_len, uint8_t *p_pin)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800377
378{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800379 tBTA_DM_API_PIN_REPLY *p_msg =
380 (tBTA_DM_API_PIN_REPLY *)osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800381
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800382 p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
383 bdcpy(p_msg->bd_addr, bd_addr);
384 p_msg->accept = accept;
385 if (accept) {
386 p_msg->pin_len = pin_len;
387 memcpy(p_msg->p_pin, p_pin, pin_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800388 }
389
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800390 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800391}
392
The Android Open Source Project5738f832012-12-12 16:00:35 -0800393/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800394 *
395 * Function BTA_DmLocalOob
396 *
397 * Description This function retrieves the OOB data from local controller.
398 * The result is reported by:
399 * - bta_dm_co_loc_oob_ext() if device supports secure
400 * connections (SC)
401 * - bta_dm_co_loc_oob() if device doesn't support SC
402 *
403 * Returns void
404 *
405 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800406void BTA_DmLocalOob(void)
407{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800408 tBTA_DM_API_LOC_OOB *p_msg =
409 (tBTA_DM_API_LOC_OOB *)osi_malloc(sizeof(tBTA_DM_API_LOC_OOB));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800410
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800411 p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
412 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800413}
Jakub Pawlowski175da702015-11-12 15:00:58 -0800414
The Android Open Source Project5738f832012-12-12 16:00:35 -0800415/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800416 *
417 * Function BTA_DmConfirm
418 *
419 * Description This function accepts or rejects the numerical value of the
420 * Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
421 *
422 * Returns void
423 *
424 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700425void BTA_DmConfirm(BD_ADDR bd_addr, bool accept)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800426{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800427 tBTA_DM_API_CONFIRM *p_msg =
428 (tBTA_DM_API_CONFIRM *)osi_malloc(sizeof(tBTA_DM_API_CONFIRM));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800429
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800430 p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
431 bdcpy(p_msg->bd_addr, bd_addr);
432 p_msg->accept = accept;
433
434 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800435}
436
437/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800438 *
439 * Function BTA_DmAddDevice
440 *
441 * Description This function adds a device to the security database list of
442 * peer device
443 *
444 *
445 * Returns void
446 *
447 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800448void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
Marie Janssene9e58ce2016-06-17 14:12:17 -0700449 tBTA_SERVICE_MASK trusted_mask, bool is_trusted,
450 uint8_t key_type, tBTA_IO_CAP io_cap, uint8_t pin_length)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800451{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800452 tBTA_DM_API_ADD_DEVICE *p_msg =
453 (tBTA_DM_API_ADD_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_ADD_DEVICE));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800454
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800455 p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
456 bdcpy(p_msg->bd_addr, bd_addr);
457 p_msg->tm = trusted_mask;
458 p_msg->is_trusted = is_trusted;
459 p_msg->io_cap = io_cap;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800460
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800461 if (link_key) {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700462 p_msg->link_key_known = true;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800463 p_msg->key_type = key_type;
464 memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800465 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800466
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800467 /* Load device class if specified */
468 if (dev_class) {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700469 p_msg->dc_known = true;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800470 memcpy(p_msg->dc, dev_class, DEV_CLASS_LEN);
471 }
472
473 memset(p_msg->bd_name, 0, BD_NAME_LEN + 1);
474 memset(p_msg->features, 0, sizeof (p_msg->features));
475 p_msg->pin_length = pin_length;
476
477 bta_sys_sendmsg(p_msg);
478}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800479
480/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800481 *
482 * Function BTA_DmRemoveDevice
483 *
484 * Description This function removes a device fromthe security database list of
485 * peer device. It manages unpairing even while connected.
486 *
487 *
488 * Returns void
489 *
490 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800491tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
492{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800493 tBTA_DM_API_REMOVE_DEVICE *p_msg =
494 (tBTA_DM_API_REMOVE_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_REMOVE_DEVICE));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800495
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800496 p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
497 bdcpy(p_msg->bd_addr, bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800498
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800499 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800500
501 return BTA_SUCCESS;
502}
503
504/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800505 *
506 * Function BTA_GetEirService
507 *
508 * Description This function is called to get BTA service mask from EIR.
509 *
510 * Parameters p_eir - pointer of EIR significant part
511 * p_services - return the BTA service mask
512 *
513 * Returns None
514 *
515 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700516extern const uint16_t bta_service_id_to_uuid_lkup_tbl [];
517void BTA_GetEirService( uint8_t *p_eir, tBTA_SERVICE_MASK *p_services )
The Android Open Source Project5738f832012-12-12 16:00:35 -0800518{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700519 uint8_t xx, yy;
520 uint8_t num_uuid, max_num_uuid = 32;
521 uint8_t uuid_list[32*LEN_UUID_16];
522 uint16_t *p_uuid16 = (uint16_t *)uuid_list;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800523 tBTA_SERVICE_MASK mask;
524
525 BTM_GetEirUuidList( p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid);
526 for( xx = 0; xx < num_uuid; xx++ )
527 {
528 mask = 1;
529 for( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ )
530 {
531 if( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] )
532 {
533 *p_services |= mask;
534 break;
535 }
536 mask <<= 1;
537 }
538
539 /* for HSP v1.2 only device */
540 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS)
541 *p_services |= BTA_HSP_SERVICE_MASK;
542
543 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE)
544 *p_services |= BTA_HL_SERVICE_MASK;
545
546 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK)
547 *p_services |= BTA_HL_SERVICE_MASK;
548 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800549}
550
551/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800552 *
553 * Function BTA_DmGetConnectionState
554 *
555 * Description Returns whether the remote device is currently connected.
556 *
557 * Returns 0 if the device is NOT connected.
558 *
559 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700560uint16_t BTA_DmGetConnectionState(const BD_ADDR bd_addr )
Andre Eisenbach5c0b0522014-06-18 12:20:37 -0700561{
562 tBTA_DM_PEER_DEVICE * p_dev = bta_dm_find_peer_device(bd_addr);
563 return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
564}
565
566
567/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800568 * Device Identification (DI) Server Functions
569 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800570/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800571 *
572 * Function BTA_DmSetLocalDiRecord
573 *
574 * Description This function adds a DI record to the local SDP database.
575 *
576 * Returns BTA_SUCCESS if record set sucessfully, otherwise error code.
577 *
578 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800579tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
Marie Janssene9e58ce2016-06-17 14:12:17 -0700580 uint32_t *p_handle )
The Android Open Source Project5738f832012-12-12 16:00:35 -0800581{
582 tBTA_STATUS status = BTA_FAILURE;
583
584 if(bta_dm_di_cb.di_num < BTA_DI_NUM_MAX)
585 {
586 if(SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS)
587 {
588 if(!p_device_info->primary_record)
589 {
590 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
591 bta_dm_di_cb.di_num ++;
592 }
593
594 bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
595 status = BTA_SUCCESS;
596 }
597 }
598
599 return status;
600}
601
602/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800603 *
604 * Function bta_dmexecutecallback
605 *
606 * Description This function will request BTA to execute a call back in the context of BTU task
607 * This API was named in lower case because it is only intended
608 * for the internal customers(like BTIF).
609 *
610 * Returns void
611 *
612 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800613void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param)
614{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800615 tBTA_DM_API_EXECUTE_CBACK *p_msg =
616 (tBTA_DM_API_EXECUTE_CBACK *)osi_malloc(sizeof(tBTA_DM_MSG));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800617
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800618 p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
619 p_msg->p_param= p_param;
620 p_msg->p_exec_cback= p_callback;
621
622 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800623}
624
625/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800626 *
627 * Function BTA_DmAddBleKey
628 *
629 * Description Add/modify LE device information. This function will be
630 * normally called during host startup to restore all required
631 * information stored in the NVRAM.
632 *
633 * Parameters: bd_addr - BD address of the peer
634 * p_le_key - LE key values.
635 * key_type - LE SMP key type.
636 *
637 * Returns BTA_SUCCESS if successful
638 * BTA_FAIL if operation failed.
639 *
640 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800641void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_TYPE key_type)
642{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700643#if (BLE_INCLUDED == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800644
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800645 tBTA_DM_API_ADD_BLEKEY *p_msg =
646 (tBTA_DM_API_ADD_BLEKEY *)osi_calloc(sizeof(tBTA_DM_API_ADD_BLEKEY));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800647
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800648 p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
649 p_msg->key_type = key_type;
650 bdcpy(p_msg->bd_addr, bd_addr);
651 memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800652
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800653 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800654#endif
655}
656
657/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800658 *
659 * Function BTA_DmAddBleDevice
660 *
661 * Description Add a BLE device. This function will be normally called
662 * during host startup to restore all required information
663 * for a LE device stored in the NVRAM.
664 *
665 * Parameters: bd_addr - BD address of the peer
666 * dev_type - Remote device's device type.
667 * addr_type - LE device address type.
668 *
669 * Returns void
670 *
671 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800672void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TYPE dev_type)
673{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700674#if (BLE_INCLUDED == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800675 tBTA_DM_API_ADD_BLE_DEVICE *p_msg =
676 (tBTA_DM_API_ADD_BLE_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800677
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800678 p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
679 bdcpy(p_msg->bd_addr, bd_addr);
680 p_msg->addr_type = addr_type;
681 p_msg->dev_type = dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800682
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800683 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800684#endif
685}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800686
The Android Open Source Project5738f832012-12-12 16:00:35 -0800687/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800688 *
689 * Function BTA_DmBlePasskeyReply
690 *
691 * Description Send BLE SMP passkey reply.
692 *
693 * Parameters: bd_addr - BD address of the peer
694 * accept - passkey entry sucessful or declined.
695 * passkey - passkey value, must be a 6 digit number,
696 * can be lead by 0.
697 *
698 * Returns void
699 *
700 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700701void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, bool accept, uint32_t passkey)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800702{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700703#if (BLE_INCLUDED == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800704 tBTA_DM_API_PASSKEY_REPLY *p_msg =
705 (tBTA_DM_API_PASSKEY_REPLY *)osi_calloc(sizeof(tBTA_DM_API_PASSKEY_REPLY));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800706
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800707 p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
708 bdcpy(p_msg->bd_addr, bd_addr);
709 p_msg->accept = accept;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800710
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800711 if (accept)
712 p_msg->passkey = passkey;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800713
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800714 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800715#endif
716}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800717
The Android Open Source Project5738f832012-12-12 16:00:35 -0800718/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800719 *
720 * Function BTA_DmBleConfirmReply
721 *
722 * Description Send BLE SMP SC user confirmation reply.
723 *
724 * Parameters: bd_addr - BD address of the peer
725 * accept - numbers to compare are the same or different.
726 *
727 * Returns void
728 *
729 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700730void BTA_DmBleConfirmReply(BD_ADDR bd_addr, bool accept)
Satya Calloji444a8da2015-03-06 10:38:22 -0800731{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700732#if (BLE_INCLUDED == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800733 tBTA_DM_API_CONFIRM *p_msg =
734 (tBTA_DM_API_CONFIRM *)osi_calloc(sizeof(tBTA_DM_API_CONFIRM));
735
736 p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT;
737 bdcpy(p_msg->bd_addr, bd_addr);
738 p_msg->accept = accept;
739
740 bta_sys_sendmsg(p_msg);
Andre Eisenbach77668212015-05-06 21:49:35 -0700741#endif
Satya Calloji444a8da2015-03-06 10:38:22 -0800742}
743
744/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800745 *
746 * Function BTA_DmBleSecurityGrant
747 *
748 * Description Grant security request access.
749 *
750 * Parameters: bd_addr - BD address of the peer
751 * res - security grant status.
752 *
753 * Returns void
754 *
755 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800756void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
757{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700758#if (BLE_INCLUDED == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800759 tBTA_DM_API_BLE_SEC_GRANT *p_msg =
760 (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 -0800761
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800762 p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
763 bdcpy(p_msg->bd_addr, bd_addr);
764 p_msg->res = res;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800765
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800766 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800767#endif
768}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800769
The Android Open Source Project5738f832012-12-12 16:00:35 -0800770/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800771 *
772 * Function BTA_DmSetBlePrefConnParams
773 *
774 * Description This function is called to set the preferred connection
775 * parameters when default connection parameter is not desired.
776 *
777 * Parameters: bd_addr - BD address of the peripheral
778 * scan_interval - scan interval
779 * scan_window - scan window
780 * min_conn_int - minimum preferred connection interval
781 * max_conn_int - maximum preferred connection interval
782 * slave_latency - preferred slave latency
783 * supervision_tout - preferred supervision timeout
784 *
785 *
786 * Returns void
787 *
788 ******************************************************************************/
Jakub Pawlowski063ca022016-04-25 10:43:02 -0700789void BTA_DmSetBlePrefConnParams(const BD_ADDR bd_addr,
Marie Janssene9e58ce2016-06-17 14:12:17 -0700790 uint16_t min_conn_int, uint16_t max_conn_int,
791 uint16_t slave_latency, uint16_t supervision_tout )
The Android Open Source Project5738f832012-12-12 16:00:35 -0800792{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700793#if (BLE_INCLUDED == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800794 tBTA_DM_API_BLE_CONN_PARAMS *p_msg =
795 (tBTA_DM_API_BLE_CONN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800796
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800797 p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
798 memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN);
799 p_msg->conn_int_max = max_conn_int;
800 p_msg->conn_int_min = min_conn_int;
801 p_msg->slave_latency = slave_latency;
802 p_msg->supervision_tout = supervision_tout;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800803
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800804 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800805#endif
806}
807
808/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800809 *
810 * Function BTA_DmSetBleConnScanParams
811 *
812 * Description This function is called to set scan parameters used in
813 * BLE connection request
814 *
815 * Parameters: scan_interval - scan interval
816 * scan_window - scan window
817 *
818 * Returns void
819 *
820 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700821void BTA_DmSetBleConnScanParams(uint32_t scan_interval, uint32_t scan_window)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800822{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700823#if (BLE_INCLUDED == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800824 tBTA_DM_API_BLE_SCAN_PARAMS *p_msg =
825 (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
826
827 p_msg->hdr.event = BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT;
828 p_msg->scan_int = scan_interval;
829 p_msg->scan_window = scan_window;
830
831 bta_sys_sendmsg(p_msg);
Marie Janssene9e58ce2016-06-17 14:12:17 -0700832#endif // BLE_INCLUDED == true
Satya Calloji5725fc62015-03-31 13:24:32 -0700833}
834
835/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800836 *
837 * Function BTA_DmSetBleScanParams
838 *
839 * Description This function is called to set scan parameters
840 *
841 * Parameters: client_if - Client IF
842 * scan_interval - scan interval
843 * scan_window - scan window
844 * scan_mode - scan mode
845 * scan_param_setup_status_cback - Set scan param status callback
846 *
847 * Returns void
848 *
849 ******************************************************************************/
Scott James Remnantdd339ab2015-11-19 15:27:41 -0800850
Marie Janssene9e58ce2016-06-17 14:12:17 -0700851#if (BLE_INCLUDED == TRUE)
852void BTA_DmSetBleScanParams(tGATT_IF client_if, uint32_t scan_interval,
853 uint32_t scan_window, tBLE_SCAN_MODE scan_mode,
Satya Calloji5725fc62015-03-31 13:24:32 -0700854 tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
855{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800856 tBTA_DM_API_BLE_SCAN_PARAMS *p_msg =
857 (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
Satya Calloji5725fc62015-03-31 13:24:32 -0700858
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800859 p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT;
860 p_msg->client_if = client_if;
861 p_msg->scan_int = scan_interval;
862 p_msg->scan_window = scan_window;
863 p_msg->scan_mode = scan_mode;
864 p_msg->scan_param_setup_cback = scan_param_setup_cback;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800865
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800866 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800867}
Marie Janssene9e58ce2016-06-17 14:12:17 -0700868#endif // BLE_INCLUDED == true
The Android Open Source Project5738f832012-12-12 16:00:35 -0800869
870/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800871 *
872 * Function BTA_DmSetBleAdvParams
873 *
874 * Description This function sets the advertising parameters BLE functionality.
875 * It is to be called when device act in peripheral or broadcaster
876 * role.
877 *
878 *
879 * Returns void
880 *
881 ******************************************************************************/
Jakub Pawlowski5b12a832016-08-11 03:30:47 -0700882void BTA_DmSetBleAdvParams(uint16_t adv_int_min, uint16_t adv_int_max,
Andre Eisenbach5c44e452013-08-06 18:19:37 -0700883 tBLE_BD_ADDR *p_dir_bda)
884{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700885#if (BLE_INCLUDED == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800886 if (p_dir_bda != NULL) {
Jakub Pawlowski5b12a832016-08-11 03:30:47 -0700887 tBLE_BD_ADDR *bda = new tBLE_BD_ADDR;
888 memcpy(bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
889 do_in_bta_thread(FROM_HERE,
890 base::Bind(&bta_dm_ble_set_adv_params, adv_int_min, adv_int_max, base::Owned(bda)));
Andre Eisenbach5c44e452013-08-06 18:19:37 -0700891 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800892
Jakub Pawlowski5b12a832016-08-11 03:30:47 -0700893 do_in_bta_thread(FROM_HERE,
894 base::Bind(&bta_dm_ble_set_adv_params, adv_int_min, adv_int_max, nullptr));
895
Andre Eisenbach5c44e452013-08-06 18:19:37 -0700896#endif
897}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800898
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700899/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800900 * BLE ADV data management API
901 *******************************************************************************/
Andre Eisenbach5c44e452013-08-06 18:19:37 -0700902
Marie Janssene9e58ce2016-06-17 14:12:17 -0700903#if (BLE_INCLUDED == TRUE)
Andre Eisenbach5c44e452013-08-06 18:19:37 -0700904/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800905 *
906 * Function BTA_DmBleSetStorageParams
907 *
908 * Description This function is called to override the BTA scan response.
909 *
910 * Parameters batch_scan_full_max -Max storage space (in %) allocated to full scanning
911 * batch_scan_trunc_max -Max storage space (in %) allocated to truncated scanning
912 * batch_scan_notify_threshold -Setup notification level based on total space
913 * p_setup_cback - Setup callback pointer
914 * p_thres_cback - Threshold callback pointer
915 * p_rep_cback - Reports callback pointer
916 * ref_value - Ref value
917 *
918 * Returns None
919 *
920 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700921extern void BTA_DmBleSetStorageParams(uint8_t batch_scan_full_max,
922 uint8_t batch_scan_trunc_max,
923 uint8_t batch_scan_notify_threshold,
Satya Callojic4e25962014-05-10 23:46:24 -0700924 tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback,
925 tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback,
926 tBTA_BLE_SCAN_REP_CBACK* p_rep_cback,
927 tBTA_DM_BLE_REF_VALUE ref_value)
928{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800929 tBTA_DM_API_SET_STORAGE_CONFIG *p_msg =
930 (tBTA_DM_API_SET_STORAGE_CONFIG *)osi_malloc(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG));
931
Satya Callojic4e25962014-05-10 23:46:24 -0700932 bta_dm_cb.p_setup_cback = p_setup_cback;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800933
934 p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT;
935 p_msg->p_setup_cback=bta_ble_scan_setup_cb;
936 p_msg->p_thres_cback=p_thres_cback;
937 p_msg->p_read_rep_cback=p_rep_cback;
938 p_msg->ref_value = ref_value;
939 p_msg->batch_scan_full_max = batch_scan_full_max;
940 p_msg->batch_scan_trunc_max = batch_scan_trunc_max;
941 p_msg->batch_scan_notify_threshold = batch_scan_notify_threshold;
942
943 bta_sys_sendmsg(p_msg);
Satya Callojic4e25962014-05-10 23:46:24 -0700944}
945
946/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800947 *
948 * Function BTA_DmBleEnableBatchScan
949 *
950 * Description This function is called to enable the batch scan
951 *
952 * Parameters scan_mode -Batch scan mode
953 * scan_interval - Scan interval
954 * scan_window - Scan window
955 * discard_rule -Discard rules
956 * addr_type - Address type
957 * ref_value - Reference value
958 *
959 * Returns None
960 *
961 ******************************************************************************/
Satya Calloji5725fc62015-03-31 13:24:32 -0700962extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode,
Marie Janssene9e58ce2016-06-17 14:12:17 -0700963 uint32_t scan_interval, uint32_t scan_window,
Satya Callojic4e25962014-05-10 23:46:24 -0700964 tBTA_BLE_DISCARD_RULE discard_rule,
965 tBLE_ADDR_TYPE addr_type,
966 tBTA_DM_BLE_REF_VALUE ref_value)
967{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800968 tBTA_DM_API_ENABLE_SCAN *p_msg =
969 (tBTA_DM_API_ENABLE_SCAN *)osi_malloc(sizeof(tBTA_DM_API_ENABLE_SCAN));
Satya Callojic4e25962014-05-10 23:46:24 -0700970
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800971 p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT;
972 p_msg->scan_mode = scan_mode;
973 p_msg->scan_int = scan_interval;
974 p_msg->scan_window = scan_window;
975 p_msg->discard_rule = discard_rule;
976 p_msg->addr_type = addr_type;
977 p_msg->ref_value = ref_value;
978
979 bta_sys_sendmsg(p_msg);
Satya Callojic4e25962014-05-10 23:46:24 -0700980}
981
982/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800983 *
984 * Function BTA_DmBleDisableBatchScan
985 *
986 * Description This function is called to disable the batch scan
987 *
988 * Parameters ref_value - Reference value
989 *
990 * Returns None
991 *
992 ******************************************************************************/
June R. Tate-Gans24933b52014-09-24 15:25:02 -0700993extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)
Satya Callojic4e25962014-05-10 23:46:24 -0700994{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800995 tBTA_DM_API_DISABLE_SCAN *p_msg =
996 (tBTA_DM_API_DISABLE_SCAN *)osi_malloc(sizeof(tBTA_DM_API_DISABLE_SCAN));
Satya Callojic4e25962014-05-10 23:46:24 -0700997
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800998 p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT;
999 p_msg->ref_value = ref_value;
1000
1001 bta_sys_sendmsg(p_msg);
Satya Callojic4e25962014-05-10 23:46:24 -07001002}
1003
1004/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001005 *
1006 * Function BTA_DmBleReadScanReports
1007 *
1008 * Description This function is called to read scan reports
1009 *
1010 * Parameters scan_type -Batch scan mode
1011 * ref_value - Reference value
1012 *
1013 * Returns None
1014 *
1015 ******************************************************************************/
Satya Calloji5725fc62015-03-31 13:24:32 -07001016extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type,
Satya Callojic4e25962014-05-10 23:46:24 -07001017 tBTA_DM_BLE_REF_VALUE ref_value)
1018{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001019 tBTA_DM_API_READ_SCAN_REPORTS *p_msg =
1020 (tBTA_DM_API_READ_SCAN_REPORTS *)osi_malloc(sizeof(tBTA_DM_API_READ_SCAN_REPORTS));
Satya Callojic4e25962014-05-10 23:46:24 -07001021
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001022 p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT;
1023 p_msg->scan_type = scan_type;
1024 p_msg->ref_value = ref_value;
1025
1026 bta_sys_sendmsg(p_msg);
Satya Callojic4e25962014-05-10 23:46:24 -07001027}
1028
1029/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001030 *
1031 * Function BTA_DmBleTrackAdvertiser
1032 *
1033 * Description This function is called to track advertiser
1034 *
1035 * Parameters ref_value - Reference value
1036 * p_track_adv_cback - Track ADV callback
1037 *
1038 * Returns None
1039 *
1040 ******************************************************************************/
June R. Tate-Gans24933b52014-09-24 15:25:02 -07001041extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
Satya Calloji1acb61c2014-06-14 23:16:18 -07001042 tBTA_BLE_TRACK_ADV_CBACK *p_track_adv_cback)
1043{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001044 tBTA_DM_API_TRACK_ADVERTISER *p_msg =
1045 (tBTA_DM_API_TRACK_ADVERTISER *)osi_malloc(sizeof(tBTA_DM_API_TRACK_ADVERTISER));
Satya Calloji1acb61c2014-06-14 23:16:18 -07001046
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001047 p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT;
1048 p_msg->p_track_adv_cback = p_track_adv_cback;
1049 p_msg->ref_value = ref_value;
1050
1051 bta_sys_sendmsg(p_msg);
Satya Calloji1acb61c2014-06-14 23:16:18 -07001052}
1053
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -07001054#endif
1055
1056/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001057 * BLE ADV data management API
1058 *******************************************************************************/
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -07001059
Satya Calloji1acb61c2014-06-14 23:16:18 -07001060/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001061 *
1062 * Function BTA_DmBleSetBgConnType
1063 *
1064 * Description This function is called to set BLE connectable mode for a
1065 * peripheral device.
1066 *
1067 * Parameters bg_conn_type: it can be auto connection, or selective connection.
1068 * p_select_cback: callback function when selective connection procedure
1069 * is being used.
1070 *
1071 * Returns void
1072 *
1073 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -08001074void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback)
1075{
Marie Janssene9e58ce2016-06-17 14:12:17 -07001076#if (BLE_INCLUDED == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001077 tBTA_DM_API_BLE_SET_BG_CONN_TYPE *p_msg =
1078 (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *)osi_calloc(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001079
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001080 p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
1081 p_msg->bg_conn_type = bg_conn_type;
1082 p_msg->p_select_cback = p_select_cback;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001083
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001084 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001085#endif
1086}
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001087
The Android Open Source Project5738f832012-12-12 16:00:35 -08001088/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001089 *
1090 * Function bta_dm_discover_send_msg
1091 *
1092 * Description This function send discover message to BTA task.
1093 *
1094 * Returns void
1095 *
1096 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001097#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001098static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
Marie Janssene9e58ce2016-06-17 14:12:17 -07001099 tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search,
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001100 tBTA_TRANSPORT transport)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001101{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001102 const size_t len = p_services ?
1103 (sizeof(tBTA_DM_API_DISCOVER) + sizeof(tBT_UUID) * p_services->num_uuid)
1104 : sizeof(tBTA_DM_API_DISCOVER);
1105 tBTA_DM_API_DISCOVER *p_msg = (tBTA_DM_API_DISCOVER *)osi_calloc(len);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001106
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001107 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
1108 bdcpy(p_msg->bd_addr, bd_addr);
1109 p_msg->p_cback = p_cback;
1110 p_msg->sdp_search = sdp_search;
1111 p_msg->transport = transport;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001112
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001113 if (p_services != NULL) {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001114#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001115 p_msg->services = p_services->srvc_mask;
1116 p_msg->num_uuid = p_services->num_uuid;
1117 if (p_services->num_uuid != 0) {
1118 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1119 memcpy(p_msg->p_uuid, p_services->p_uuid,
1120 sizeof(tBT_UUID) * p_services->num_uuid);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001121 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001122#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001123 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001124
1125 bta_sys_sendmsg(p_msg);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001126}
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -07001127#endif
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001128
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001129/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001130 *
1131 * Function BTA_DmDiscoverByTransport
1132 *
1133 * Description This function does service discovery on particular transport
1134 * for services of a
1135 * peer device. When services.num_uuid is 0, it indicates all
1136 * GATT based services are to be searched; otherwise a list of
1137 * UUID of interested services should be provided through
1138 * p_services->p_uuid.
1139 *
1140 *
1141 *
1142 * Returns void
1143 *
1144 ******************************************************************************/
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001145void BTA_DmDiscoverByTransport(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
Marie Janssene9e58ce2016-06-17 14:12:17 -07001146 tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search,
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001147 tBTA_TRANSPORT transport)
1148{
Marie Janssene9e58ce2016-06-17 14:12:17 -07001149#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001150 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -07001151#endif
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001152}
1153
1154
1155/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001156 *
1157 * Function BTA_DmDiscoverExt
1158 *
1159 * Description This function does service discovery for services of a
1160 * peer device. When services.num_uuid is 0, it indicates all
1161 * GATT based services are to be searched; other wise a list of
1162 * UUID of interested services should be provided through
1163 * p_services->p_uuid.
1164 *
1165 *
1166 *
1167 * Returns void
1168 *
1169 ******************************************************************************/
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001170void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
Marie Janssene9e58ce2016-06-17 14:12:17 -07001171 tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search)
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001172{
Marie Janssene9e58ce2016-06-17 14:12:17 -07001173#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001174 bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, BTA_TRANSPORT_UNKNOWN);
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -07001175#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001176
1177}
1178
1179/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001180 *
1181 * Function BTA_DmSearchExt
1182 *
1183 * Description This function searches for peer Bluetooth devices. It performs
1184 * an inquiry and gets the remote name for devices. Service
1185 * discovery is done if services is non zero
1186 *
1187 * Parameters p_dm_inq: inquiry conditions
1188 * p_services: if service is not empty, service discovery will be done.
1189 * for all GATT based service condition, put num_uuid, and
1190 * p_uuid is the pointer to the list of UUID values.
1191 * p_cback: callback functino when search is completed.
1192 *
1193 *
1194 *
1195 * Returns void
1196 *
1197 ******************************************************************************/
Myles Watsond628a062016-10-27 10:02:37 -07001198#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001199void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback)
1200{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001201 const size_t len = p_services ?
1202 (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid)
1203 : sizeof(tBTA_DM_API_SEARCH);
1204 tBTA_DM_API_SEARCH *p_msg = (tBTA_DM_API_SEARCH *)osi_calloc(len);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001205
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001206 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
1207 memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
1208 p_msg->p_cback = p_cback;
1209 p_msg->rs_res = BTA_DM_RS_NONE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001210
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001211 if (p_services != NULL) {
1212 p_msg->services = p_services->srvc_mask;
1213 p_msg->num_uuid = p_services->num_uuid;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001214
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001215 if (p_services->num_uuid != 0) {
1216 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1217 memcpy(p_msg->p_uuid, p_services->p_uuid,
1218 sizeof(tBT_UUID) * p_services->num_uuid);
1219 } else {
1220 p_msg->p_uuid = NULL;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001221 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001222 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001223
1224 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001225}
Myles Watsond628a062016-10-27 10:02:37 -07001226#else
1227void BTA_DmSearchExt(UNUSED_ATTR tBTA_DM_INQ *p_dm_inq,
1228 UNUSED_ATTR tBTA_SERVICE_MASK_EXT *p_services,
1229 UNUSED_ATTR tBTA_DM_SEARCH_CBACK *p_cback)
1230{
1231}
1232#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001233/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001234 *
1235 * Function BTA_DmBleUpdateConnectionParam
1236 *
1237 * Description Update connection parameters, can only be used when connection is up.
1238 *
1239 * Parameters: bd_addr - BD address of the peer
1240 * min_int - minimum connection interval, [0x0004~ 0x4000]
1241 * max_int - maximum connection interval, [0x0004~ 0x4000]
1242 * latency - slave latency [0 ~ 500]
1243 * timeout - supervision timeout [0x000a ~ 0xc80]
1244 *
1245 * Returns void
1246 *
1247 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001248void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, uint16_t min_int,
1249 uint16_t max_int, uint16_t latency,
1250 uint16_t timeout)
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001251{
Marie Janssene9e58ce2016-06-17 14:12:17 -07001252#if (BLE_INCLUDED == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001253 tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
1254 (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -07001255
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001256 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1257 bdcpy(p_msg->bd_addr, bd_addr);
1258 p_msg->min_int = min_int;
1259 p_msg->max_int = max_int;
1260 p_msg->latency = latency;
1261 p_msg->timeout = timeout;
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -07001262
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001263 bta_sys_sendmsg(p_msg);
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -07001264#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001265}
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001266
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001267/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001268 *
1269 * Function BTA_DmBleConfigLocalPrivacy
1270 *
1271 * Description Enable/disable privacy on the local device
1272 *
1273 * Parameters: privacy_enable - enable/disabe privacy on remote device.
1274 *
1275 * Returns void
1276 *
1277 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001278void BTA_DmBleConfigLocalPrivacy(bool privacy_enable)
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001279{
Marie Janssene9e58ce2016-06-17 14:12:17 -07001280#if (BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE)
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001281 tBTA_DM_API_LOCAL_PRIVACY *p_msg =
1282 (tBTA_DM_API_LOCAL_PRIVACY *)osi_calloc(sizeof(tBTA_DM_API_ENABLE_PRIVACY));
Wei Wanged534e32014-05-20 06:30:13 +00001283
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001284 p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
1285 p_msg->privacy_enable = privacy_enable;
Wei Wanged534e32014-05-20 06:30:13 +00001286
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001287 bta_sys_sendmsg(p_msg);
Wei Wanged534e32014-05-20 06:30:13 +00001288#else
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001289 UNUSED (privacy_enable);
Wei Wanged534e32014-05-20 06:30:13 +00001290#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001291}
The Android Open Source Project5738f832012-12-12 16:00:35 -08001292
Marie Janssene9e58ce2016-06-17 14:12:17 -07001293#if (BLE_INCLUDED == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001294/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001295 *
1296 * Function BTA_DmBleCfgFilterCondition
1297 *
1298 * Description This function is called to configure the adv data payload filter
1299 * condition.
1300 *
1301 * Parameters action: to read/write/clear
1302 * cond_type: filter condition type
1303 * filt_index - Filter index
1304 * p_cond: filter condition parameter
1305 * p_cmpl_back - Command completed callback
1306 * ref_value - Reference value
1307 *
1308 * Returns void
1309 *
1310 ******************************************************************************/
Myles Watsond628a062016-10-27 10:02:37 -07001311#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
Satya Calloji1a9247a2014-06-05 13:15:15 -07001312void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
1313 tBTA_DM_BLE_PF_COND_TYPE cond_type,
1314 tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1315 tBTA_DM_BLE_PF_COND_PARAM *p_cond,
1316 tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback,
1317 tBTA_DM_BLE_REF_VALUE ref_value)
1318{
Satya Calloji1a9247a2014-06-05 13:15:15 -07001319 tBTA_DM_API_CFG_FILTER_COND *p_msg;
1320 APPL_TRACE_API ("BTA_DmBleCfgFilterCondition: %d, %d", action, cond_type);
1321
Marie Janssene9e58ce2016-06-17 14:12:17 -07001322 uint16_t len = sizeof(tBTA_DM_API_CFG_FILTER_COND) +
Satya Calloji6cbb1132014-09-03 10:01:44 -07001323 sizeof(tBTA_DM_BLE_PF_COND_PARAM);
Marie Janssene9e58ce2016-06-17 14:12:17 -07001324 uint8_t *p;
Satya Calloji1a9247a2014-06-05 13:15:15 -07001325
Satya Calloji6cbb1132014-09-03 10:01:44 -07001326 if (NULL != p_cond)
1327 {
1328 switch(cond_type)
1329 {
1330 case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:
1331 case BTA_DM_BLE_PF_MANU_DATA:
1332 /* Length of pattern and pattern mask and other elements in */
1333 /* tBTA_DM_BLE_PF_MANU_COND */
1334 len += ((p_cond->manu_data.data_len) * 2) +
Marie Janssene9e58ce2016-06-17 14:12:17 -07001335 sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint8_t);
Satya Calloji6cbb1132014-09-03 10:01:44 -07001336 break;
1337
1338 case BTA_DM_BLE_PF_LOCAL_NAME:
Marie Janssene9e58ce2016-06-17 14:12:17 -07001339 len += ((p_cond->local_name.data_len) + sizeof(uint8_t));
Satya Calloji6cbb1132014-09-03 10:01:44 -07001340 break;
1341
1342 case BTM_BLE_PF_SRVC_UUID:
1343 case BTM_BLE_PF_SRVC_SOL_UUID:
1344 len += sizeof(tBLE_BD_ADDR) + sizeof(tBTA_DM_BLE_PF_COND_MASK);
1345 break;
1346
1347 default:
1348 break;
1349 }
1350 }
1351
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001352 p_msg = (tBTA_DM_API_CFG_FILTER_COND *)osi_calloc(len);
1353 p_msg->hdr.event = BTA_DM_API_CFG_FILTER_COND_EVT;
1354 p_msg->action = action;
1355 p_msg->cond_type = cond_type;
1356 p_msg->filt_index = filt_index;
1357 p_msg->p_filt_cfg_cback = p_cmpl_cback;
1358 p_msg->ref_value = ref_value;
1359 if (p_cond) {
1360 p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM *)(p_msg + 1);
1361 memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
VenkatRaghavan VijayaRaghavan76356ae2015-04-21 11:32:29 -07001362
Marie Janssene9e58ce2016-06-17 14:12:17 -07001363 p = (uint8_t *)(p_msg->p_cond_param + 1);
Satya Calloji1a9247a2014-06-05 13:15:15 -07001364
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001365 if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN ||
1366 cond_type == BTA_DM_BLE_PF_MANU_DATA) {
1367 p_msg->p_cond_param->manu_data.p_pattern = p;
1368 p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len;
1369 memcpy(p_msg->p_cond_param->manu_data.p_pattern, p_cond->manu_data.p_pattern,
1370 p_cond->manu_data.data_len);
1371 p += p_cond->manu_data.data_len;
Satya Calloji1a9247a2014-06-05 13:15:15 -07001372
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001373 if (cond_type == BTA_DM_BLE_PF_MANU_DATA) {
1374 p_msg->p_cond_param->manu_data.company_id_mask =
1375 p_cond->manu_data.company_id_mask;
1376 if ( p_cond->manu_data.p_pattern_mask != NULL) {
1377 p_msg->p_cond_param->manu_data.p_pattern_mask = p;
1378 memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask,
1379 p_cond->manu_data.p_pattern_mask,
1380 p_cond->manu_data.data_len);
Satya Calloji1a9247a2014-06-05 13:15:15 -07001381 }
1382 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001383 } else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME) {
1384 p_msg->p_cond_param->local_name.p_data = p;
1385 p_msg->p_cond_param->local_name.data_len =
1386 p_cond->local_name.data_len;
1387 memcpy(p_msg->p_cond_param->local_name.p_data,
1388 p_cond->local_name.p_data, p_cond->local_name.data_len);
1389 } else if (cond_type == BTM_BLE_PF_SRVC_UUID ||
1390 cond_type == BTM_BLE_PF_SRVC_SOL_UUID) {
1391 if (p_cond->srvc_uuid.p_target_addr != NULL) {
1392 p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR *)(p);
1393 p_msg->p_cond_param->srvc_uuid.p_target_addr->type =
1394 p_cond->srvc_uuid.p_target_addr->type;
1395 memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda,
1396 p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN);
Marie Janssene9e58ce2016-06-17 14:12:17 -07001397 p = (uint8_t *)(p_msg->p_cond_param->srvc_uuid.p_target_addr + 1);
Satya Calloji1a9247a2014-06-05 13:15:15 -07001398 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001399 if (p_cond->srvc_uuid.p_uuid_mask) {
1400 p_msg->p_cond_param->srvc_uuid.p_uuid_mask = (tBTA_DM_BLE_PF_COND_MASK *)p;
1401 memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask,
1402 p_cond->srvc_uuid.p_uuid_mask,
1403 sizeof(tBTA_DM_BLE_PF_COND_MASK));
Satya Calloji1a9247a2014-06-05 13:15:15 -07001404 }
1405 }
Satya Calloji1a9247a2014-06-05 13:15:15 -07001406 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001407
1408 bta_sys_sendmsg(p_msg);
1409
Satya Calloji1a9247a2014-06-05 13:15:15 -07001410}
Myles Watsond628a062016-10-27 10:02:37 -07001411#else
1412void BTA_DmBleCfgFilterCondition(UNUSED_ATTR tBTA_DM_BLE_SCAN_COND_OP action,
1413 UNUSED_ATTR tBTA_DM_BLE_PF_COND_TYPE cond_type,
1414 UNUSED_ATTR tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1415 UNUSED_ATTR tBTA_DM_BLE_PF_COND_PARAM *p_cond,
1416 UNUSED_ATTR tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback,
1417 UNUSED_ATTR tBTA_DM_BLE_REF_VALUE ref_value)
1418{
1419}
1420#endif
Satya Calloji1a9247a2014-06-05 13:15:15 -07001421
1422/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001423 *
1424 * Function BTA_DmBleScanFilterSetup
1425 *
1426 * Description This function is called to setup the adv data payload filter param
1427 *
1428 * Parameters p_target: enable the filter condition on a target device; if NULL
1429 * filt_index - Filter index
1430 * p_filt_params -Filter parameters
1431 * ref_value - Reference value
1432 * action - Add, delete or clear
1433 * p_cmpl_back - Command completed callback
1434 *
1435 * Returns void
1436 *
1437 ******************************************************************************/
Myles Watsond628a062016-10-27 10:02:37 -07001438#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
Marie Janssene9e58ce2016-06-17 14:12:17 -07001439void BTA_DmBleScanFilterSetup(uint8_t action,
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001440 tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1441 tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params,
1442 tBLE_BD_ADDR *p_target,
1443 tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback,
1444 tBTA_DM_BLE_REF_VALUE ref_value)
Satya Calloji1a9247a2014-06-05 13:15:15 -07001445{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001446 const size_t len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) +
1447 sizeof(tBLE_BD_ADDR);
1448 tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *p_msg =
1449 (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *)osi_calloc(len);
Satya Calloji1a9247a2014-06-05 13:15:15 -07001450
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001451 APPL_TRACE_API("%s: %d", __func__, action);
Satya Calloji1a9247a2014-06-05 13:15:15 -07001452
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001453 p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_SETUP_EVT;
1454 p_msg->action = action;
1455 p_msg->filt_index = filt_index;
1456 if (p_filt_params) {
1457 memcpy(&p_msg->filt_params, p_filt_params,
1458 sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
Satya Calloji1a9247a2014-06-05 13:15:15 -07001459 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001460 p_msg->p_filt_param_cback = p_cmpl_cback;
1461 p_msg->ref_value = ref_value;
1462
1463 if (p_target) {
1464 p_msg->p_target = (tBLE_BD_ADDR *)(p_msg + 1);
1465 memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR));
1466 }
1467
1468 bta_sys_sendmsg(p_msg);
Satya Calloji1a9247a2014-06-05 13:15:15 -07001469}
Myles Watsond628a062016-10-27 10:02:37 -07001470#else
1471void BTA_DmBleScanFilterSetup(UNUSED_ATTR uint8_t action,
1472 UNUSED_ATTR tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1473 UNUSED_ATTR tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params,
1474 UNUSED_ATTR tBLE_BD_ADDR *p_target,
1475 UNUSED_ATTR tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback,
1476 UNUSED_ATTR tBTA_DM_BLE_REF_VALUE ref_value)
1477}
1478#endif
Satya Calloji1a9247a2014-06-05 13:15:15 -07001479
1480/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001481 *
1482 * Function BTA_DmBleGetEnergyInfo
1483 *
1484 * Description This function is called to obtain the energy info
1485 *
1486 * Parameters p_cmpl_cback - Command complete callback
1487 *
1488 * Returns void
1489 *
1490 ******************************************************************************/
Satya Callojie5ba8842014-07-03 17:18:02 -07001491void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback)
1492{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001493 const size_t len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
1494 tBTA_DM_API_ENERGY_INFO *p_msg = (tBTA_DM_API_ENERGY_INFO *)osi_calloc(len);
Satya Callojie5ba8842014-07-03 17:18:02 -07001495
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001496 APPL_TRACE_API("%s", __func__);
Satya Callojie5ba8842014-07-03 17:18:02 -07001497
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001498 p_msg->hdr.event = BTA_DM_API_BLE_ENERGY_INFO_EVT;
1499 p_msg->p_energy_info_cback = p_cmpl_cback;
1500
1501 bta_sys_sendmsg(p_msg);
Satya Callojie5ba8842014-07-03 17:18:02 -07001502}
1503
1504/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001505 *
1506 * Function BTA_DmEnableScanFilter
1507 *
1508 * Description This function is called to enable the adv data payload filter
1509 *
1510 * Parameters action - enable or disable the APCF feature
1511 * p_cmpl_cback - Command completed callback
1512 * ref_value - Reference value
1513 *
1514 * Returns void
1515 *
1516 ******************************************************************************/
Myles Watsond628a062016-10-27 10:02:37 -07001517#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
Marie Janssene9e58ce2016-06-17 14:12:17 -07001518void BTA_DmEnableScanFilter(uint8_t action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback,
Satya Calloji1a9247a2014-06-05 13:15:15 -07001519 tBTA_DM_BLE_REF_VALUE ref_value)
1520{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001521 const size_t len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) +
1522 sizeof(tBLE_BD_ADDR);
1523 tBTA_DM_API_ENABLE_SCAN_FILTER *p_msg =
1524 (tBTA_DM_API_ENABLE_SCAN_FILTER *)osi_calloc(len);
Satya Calloji1a9247a2014-06-05 13:15:15 -07001525
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001526 APPL_TRACE_API("%s: %d", __func__, action);
Satya Calloji1a9247a2014-06-05 13:15:15 -07001527
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001528 p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_ENABLE_EVT;
1529 p_msg->action = action;
1530 p_msg->ref_value = ref_value;
1531 p_msg->p_filt_status_cback = p_cmpl_cback;
Satya Calloji1a9247a2014-06-05 13:15:15 -07001532
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001533 bta_sys_sendmsg(p_msg);
Satya Calloji1a9247a2014-06-05 13:15:15 -07001534
Satya Calloji1a9247a2014-06-05 13:15:15 -07001535}
Myles Watsond628a062016-10-27 10:02:37 -07001536#else
1537void BTA_DmEnableScanFilter(UNUSED_ATTR uint8_t action,
1538 UNUSED_ATTR tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback,
1539 UNUSED_ATTR tBTA_DM_BLE_REF_VALUE ref_value)
1540{
1541}
1542#endif
Satya Calloji1a9247a2014-06-05 13:15:15 -07001543
1544/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001545 *
1546 * Function BTA_DmBleUpdateConnectionParams
1547 *
1548 * Description Update connection parameters, can only be used when connection is up.
1549 *
1550 * Parameters: bd_addr - BD address of the peer
1551 * min_int - minimum connection interval, [0x0004~ 0x4000]
1552 * max_int - maximum connection interval, [0x0004~ 0x4000]
1553 * latency - slave latency [0 ~ 500]
1554 * timeout - supervision timeout [0x000a ~ 0xc80]
1555 *
1556 * Returns void
1557 *
1558 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001559void BTA_DmBleUpdateConnectionParams(const BD_ADDR bd_addr, uint16_t min_int, uint16_t max_int,
1560 uint16_t latency, uint16_t timeout)
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001561{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001562 tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
1563 (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001564
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001565 p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1566 bdcpy(p_msg->bd_addr, bd_addr);
1567 p_msg->min_int = min_int;
1568 p_msg->max_int = max_int;
1569 p_msg->latency = latency;
1570 p_msg->timeout = timeout;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001571
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001572 bta_sys_sendmsg(p_msg);
Wei Wangea850482014-05-20 04:52:26 +00001573}
Priti Aghera636d6712014-12-18 13:55:48 -08001574
1575/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001576 *
1577 * Function BTA_DmBleSetDataLength
1578 *
1579 * Description This function is to set maximum LE data packet size
1580 *
1581 * Returns void
1582 *
1583 *
1584 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001585void BTA_DmBleSetDataLength(BD_ADDR remote_device, uint16_t tx_data_length)
Priti Aghera636d6712014-12-18 13:55:48 -08001586{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001587 tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg =
1588 (tBTA_DM_API_BLE_SET_DATA_LENGTH *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH));
Priti Aghera636d6712014-12-18 13:55:48 -08001589
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001590 bdcpy(p_msg->remote_bda, remote_device);
1591 p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
1592 p_msg->tx_data_length = tx_data_length;
Priti Aghera636d6712014-12-18 13:55:48 -08001593
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001594 bta_sys_sendmsg(p_msg);
Priti Aghera636d6712014-12-18 13:55:48 -08001595}
1596
Wei Wanga6ce7752014-05-20 06:30:32 +00001597#endif
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001598
1599/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001600 *
1601 * Function BTA_DmSetEncryption
1602 *
1603 * Description This function is called to ensure that connection is
1604 * encrypted. Should be called only on an open connection.
1605 * Typically only needed for connections that first want to
1606 * bring up unencrypted links, then later encrypt them.
1607 *
1608 * Parameters: bd_addr - Address of the peer device
1609 * transport - transport of the link to be encruypted
1610 * p_callback - Pointer to callback function to indicat the
1611 * link encryption status
1612 * sec_act - This is the security action to indicate
1613 * what knid of BLE security level is required for
1614 * the BLE link if the BLE is supported
1615 * Note: This parameter is ignored for the BR/EDR link
1616 * or the BLE is not supported
1617 *
1618 * Returns void
1619 *
1620 ******************************************************************************/
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001621void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCRYPT_CBACK *p_callback,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001622 tBTA_DM_BLE_SEC_ACT sec_act)
1623{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001624 tBTA_DM_API_SET_ENCRYPTION *p_msg = (tBTA_DM_API_SET_ENCRYPTION *)osi_calloc(sizeof(tBTA_DM_API_SET_ENCRYPTION));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001625
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001626 APPL_TRACE_API("%s", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001627
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001628 p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
1629 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
1630 p_msg->transport = transport;
1631 p_msg->p_callback = p_callback;
1632 p_msg->sec_act = sec_act;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001633
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001634 bta_sys_sendmsg(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001635}
1636
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001637/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001638 *
1639 * Function BTA_DmCloseACL
1640 *
1641 * Description This function force to close an ACL connection and remove the
1642 * device from the security database list of known devices.
1643 *
1644 * Parameters: bd_addr - Address of the peer device
1645 * remove_dev - remove device or not after link down
1646 *
1647 * Returns void
1648 *
1649 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001650void BTA_DmCloseACL(BD_ADDR bd_addr, bool remove_dev, tBTA_TRANSPORT transport)
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001651{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001652 tBTA_DM_API_REMOVE_ACL *p_msg =
1653 (tBTA_DM_API_REMOVE_ACL *)osi_calloc(sizeof(tBTA_DM_API_REMOVE_ACL));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001654
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001655 APPL_TRACE_API("%s", __func__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001656
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001657 p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
1658 memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
1659 p_msg->remove_dev = remove_dev;
1660 p_msg->transport = transport;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001661
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001662 bta_sys_sendmsg(p_msg);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001663}
1664
Marie Janssene9e58ce2016-06-17 14:12:17 -07001665#if (BLE_INCLUDED == TRUE)
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001666/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001667 *
1668 * Function BTA_DmBleObserve
1669 *
1670 * Description This procedure keep the device listening for advertising
1671 * events from a broadcast device.
1672 *
1673 * Parameters start: start or stop observe.
1674 *
1675 * Returns void
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001676
Myles Watson8af480e2016-11-09 10:40:23 -08001677 *
1678 * Returns void.
1679 *
1680 ******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001681extern void BTA_DmBleObserve(bool start, uint8_t duration,
June R. Tate-Gans24933b52014-09-24 15:25:02 -07001682 tBTA_DM_SEARCH_CBACK *p_results_cb)
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001683{
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001684 tBTA_DM_API_BLE_OBSERVE *p_msg =
1685 (tBTA_DM_API_BLE_OBSERVE *)osi_calloc(sizeof(tBTA_DM_API_BLE_OBSERVE));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001686
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001687 APPL_TRACE_API("%s:start = %d ", __func__, start);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001688
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001689 p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
1690 p_msg->start = start;
1691 p_msg->duration = duration;
1692 p_msg->p_cback = p_results_cb;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001693
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001694 bta_sys_sendmsg(p_msg);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001695}
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001696
1697/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001698 *
1699 * Function BTA_VendorInit
1700 *
1701 * Description This function initializes vendor specific
1702 *
1703 * Returns void
1704 *
1705 ******************************************************************************/
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001706void BTA_VendorInit (void)
1707{
1708 APPL_TRACE_API("BTA_VendorInit");
1709}
1710
1711/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -08001712 *
1713 * Function BTA_VendorCleanup
1714 *
1715 * Description This function frees up Broadcom specific VS specific dynamic memory
1716 *
1717 * Returns void
1718 *
1719 ******************************************************************************/
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001720void BTA_VendorCleanup (void)
1721{
1722 tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
Satya Callojiadb7bb52014-08-13 13:57:27 -07001723 BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001724
1725#if (BLE_INCLUDED == TRUE && BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
Satya Callojiadb7bb52014-08-13 13:57:27 -07001726 if (cmn_ble_vsc_cb.max_filter > 0)
1727 {
1728 btm_ble_adv_filter_cleanup();
Marie Janssene9e58ce2016-06-17 14:12:17 -07001729#if (BLE_PRIVACY_SPT == TRUE)
Satya Calloji444a8da2015-03-06 10:38:22 -08001730 btm_ble_resolving_list_cleanup ();
1731#endif
Satya Callojiadb7bb52014-08-13 13:57:27 -07001732 }
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001733
Satya Callojiadb7bb52014-08-13 13:57:27 -07001734 if (cmn_ble_vsc_cb.tot_scan_results_strg > 0)
1735 btm_ble_batchscan_cleanup();
1736#endif
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001737
1738 if(cmn_ble_vsc_cb.adv_inst_max > 0)
1739 btm_ble_multi_adv_cleanup();
1740}
1741
Mike J. Chenbf9a8aa2014-02-11 13:51:29 -08001742#endif