bta_dm_api.cc revision 6a9666116668683fb473239ff381dec16b784421
1/******************************************************************************
2 *
3 *  Copyright (C) 2003-2014 Broadcom Corporation
4 *
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
25#include "bt_common.h"
26#include "bta_sys.h"
27#include "bta_api.h"
28#include "bta_closure_api.h"
29#include "bta_dm_int.h"
30#include "bta_sys_int.h"
31#include "btm_api.h"
32#include "btm_int.h"
33#include <string.h>
34#include "utl.h"
35
36/*****************************************************************************
37**  Constants
38*****************************************************************************/
39
40static const tBTA_SYS_REG bta_dm_reg =
41{
42    bta_dm_sm_execute,
43    bta_dm_sm_disable
44};
45
46static const tBTA_SYS_REG bta_dm_search_reg =
47{
48    bta_dm_search_sm_execute,
49    bta_dm_search_sm_disable
50};
51
52/*******************************************************************************
53**
54** Function         BTA_EnableBluetooth
55**
56** Description      Enables bluetooth service.  This function must be
57**                  called before any other functions in the BTA API are called.
58**
59**
60** Returns          tBTA_STATUS
61**
62*******************************************************************************/
63tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
64{
65    /* Bluetooth disabling is in progress */
66    if (bta_dm_cb.disabling)
67        return BTA_FAILURE;
68
69    bta_dm_init_cb();
70
71    bta_sys_register(BTA_ID_DM, &bta_dm_reg );
72    bta_sys_register(BTA_ID_DM_SEARCH, &bta_dm_search_reg );
73
74    /* if UUID list is not provided as static data */
75    bta_sys_eir_register(bta_dm_eir_update_uuid);
76
77    tBTA_DM_API_ENABLE *p_msg =
78        (tBTA_DM_API_ENABLE *)osi_malloc(sizeof(tBTA_DM_API_ENABLE));
79    p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
80    p_msg->p_sec_cback = p_cback;
81
82    bta_sys_sendmsg(p_msg);
83
84    return BTA_SUCCESS;
85}
86
87/*******************************************************************************
88**
89** Function         BTA_DisableBluetooth
90**
91** Description      Disables bluetooth service.  This function is called when
92**                  the application no longer needs bluetooth service
93**
94** Returns          void
95**
96*******************************************************************************/
97tBTA_STATUS BTA_DisableBluetooth(void)
98{
99    BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
100
101    p_msg->event = BTA_DM_API_DISABLE_EVT;
102
103    bta_sys_sendmsg(p_msg);
104
105    return BTA_SUCCESS;
106}
107
108/*******************************************************************************
109**
110** Function         BTA_EnableTestMode
111**
112** Description      Enables bluetooth device under test mode
113**
114**
115** Returns          tBTA_STATUS
116**
117*******************************************************************************/
118tBTA_STATUS BTA_EnableTestMode(void)
119{
120    BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
121
122    APPL_TRACE_API("%s", __func__);
123
124    p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
125    bta_sys_sendmsg(p_msg);
126
127    return BTA_SUCCESS;
128}
129
130/*******************************************************************************
131**
132** Function         BTA_DisableTestMode
133**
134** Description      Disable bluetooth device under test mode
135**
136**
137** Returns          None
138**
139*******************************************************************************/
140void BTA_DisableTestMode(void)
141{
142    BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
143
144    APPL_TRACE_API("%s", __func__);
145
146    p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
147    bta_sys_sendmsg(p_msg);
148}
149
150/*******************************************************************************
151**
152** Function         BTA_DmSetDeviceName
153**
154** Description      This function sets the Bluetooth name of local device
155**
156**
157** Returns          void
158**
159*******************************************************************************/
160void BTA_DmSetDeviceName(char *p_name)
161{
162    tBTA_DM_API_SET_NAME *p_msg =
163        (tBTA_DM_API_SET_NAME *)osi_malloc(sizeof(tBTA_DM_API_SET_NAME));
164
165    p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
166    strlcpy((char*)p_msg->name, p_name, BD_NAME_LEN);
167
168    bta_sys_sendmsg(p_msg);
169}
170
171/*******************************************************************************
172**
173** Function         BTA_DmSetVisibility
174**
175** Description      This function sets the Bluetooth connectable,
176**                  discoverable, pairable and conn paired only modes of local device
177**
178**
179** Returns          void
180**
181*******************************************************************************/
182void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, uint8_t pairable_mode, uint8_t conn_filter )
183{
184    tBTA_DM_API_SET_VISIBILITY *p_msg =
185        (tBTA_DM_API_SET_VISIBILITY *)osi_malloc(sizeof(tBTA_DM_MSG));
186
187    p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
188    p_msg->disc_mode = disc_mode;
189    p_msg->conn_mode = conn_mode;
190    p_msg->pair_mode = pairable_mode;
191    p_msg->conn_paired_only = conn_filter;
192
193    bta_sys_sendmsg(p_msg);
194}
195
196/*******************************************************************************
197**
198** Function         BTA_DmSearch
199**
200** Description      This function searches for peer Bluetooth devices. It performs
201**                  an inquiry and gets the remote name for devices. Service
202**                  discovery is done if services is non zero
203**
204**
205** Returns          void
206**
207*******************************************************************************/
208void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback)
209{
210    tBTA_DM_API_SEARCH *p_msg =
211        (tBTA_DM_API_SEARCH *)osi_calloc(sizeof(tBTA_DM_API_SEARCH));
212
213    p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
214    memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
215    p_msg->services = services;
216    p_msg->p_cback = p_cback;
217    p_msg->rs_res  = BTA_DM_RS_NONE;
218
219    bta_sys_sendmsg(p_msg);
220}
221
222/*******************************************************************************
223**
224** Function         BTA_DmSearchCancel
225**
226** Description      This function  cancels a search initiated by BTA_DmSearch
227**
228**
229** Returns          void
230**
231*******************************************************************************/
232void BTA_DmSearchCancel(void)
233{
234    BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
235
236    p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
237    bta_sys_sendmsg(p_msg);
238}
239
240/*******************************************************************************
241**
242** Function         BTA_DmDiscover
243**
244** Description      This function does service discovery for services of a
245**                  peer device
246**
247**
248** Returns          void
249**
250*******************************************************************************/
251void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
252                    tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search)
253{
254    tBTA_DM_API_DISCOVER *p_msg =
255        (tBTA_DM_API_DISCOVER *)osi_calloc(sizeof(tBTA_DM_API_DISCOVER));
256
257    p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
258    bdcpy(p_msg->bd_addr, bd_addr);
259    p_msg->services = services;
260    p_msg->p_cback = p_cback;
261    p_msg->sdp_search = sdp_search;
262
263    bta_sys_sendmsg(p_msg);
264}
265
266/*******************************************************************************
267**
268** Function         BTA_DmDiscoverUUID
269**
270** Description      This function does service discovery for services of a
271**                  peer device
272**
273**
274** Returns          void
275**
276*******************************************************************************/
277void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
278                    tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search)
279{
280    tBTA_DM_API_DISCOVER *p_msg =
281        (tBTA_DM_API_DISCOVER *)osi_malloc(sizeof(tBTA_DM_API_DISCOVER));
282
283    p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
284    bdcpy(p_msg->bd_addr, bd_addr);
285    p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level
286    p_msg->p_cback = p_cback;
287    p_msg->sdp_search = sdp_search;
288
289#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
290    p_msg->num_uuid = 0;
291    p_msg->p_uuid = NULL;
292#endif
293    memcpy(&p_msg->uuid, uuid, sizeof(tSDP_UUID) );
294
295    bta_sys_sendmsg(p_msg);
296}
297
298/*******************************************************************************
299**
300** Function         BTA_DmBond
301**
302** Description      This function initiates a bonding procedure with a peer
303**                  device
304**
305**
306** Returns          void
307**
308*******************************************************************************/
309void BTA_DmBond(BD_ADDR bd_addr)
310{
311    tBTA_DM_API_BOND *p_msg =
312        (tBTA_DM_API_BOND *)osi_malloc(sizeof(tBTA_DM_API_BOND));
313
314    p_msg->hdr.event = BTA_DM_API_BOND_EVT;
315    bdcpy(p_msg->bd_addr, bd_addr);
316    p_msg->transport = BTA_TRANSPORT_UNKNOWN;
317
318    bta_sys_sendmsg(p_msg);
319}
320
321/*******************************************************************************
322**
323** Function         BTA_DmBondByTransports
324**
325** Description      This function initiates a bonding procedure with a peer
326**                  device
327**
328**
329** Returns          void
330**
331*******************************************************************************/
332void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport)
333{
334    tBTA_DM_API_BOND *p_msg =
335        (tBTA_DM_API_BOND *)osi_malloc(sizeof(tBTA_DM_API_BOND));
336
337    p_msg->hdr.event = BTA_DM_API_BOND_EVT;
338    bdcpy(p_msg->bd_addr, bd_addr);
339    p_msg->transport = transport;
340
341    bta_sys_sendmsg(p_msg);
342}
343
344/*******************************************************************************
345**
346** Function         BTA_DmBondCancel
347**
348** Description      This function cancels the bonding procedure with a peer
349**                  device
350**
351**
352** Returns          void
353**
354*******************************************************************************/
355void BTA_DmBondCancel(BD_ADDR bd_addr)
356{
357    tBTA_DM_API_BOND_CANCEL *p_msg =
358        (tBTA_DM_API_BOND_CANCEL *)osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL));
359
360    p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
361    bdcpy(p_msg->bd_addr, bd_addr);
362
363    bta_sys_sendmsg(p_msg);
364}
365
366/*******************************************************************************
367**
368** Function         BTA_DmPinReply
369**
370** Description      This function provides a pincode for a remote device when
371**                  one is requested by DM through BTA_DM_PIN_REQ_EVT
372**
373**
374** Returns          void
375**
376*******************************************************************************/
377void BTA_DmPinReply(BD_ADDR bd_addr, bool accept, uint8_t pin_len, uint8_t *p_pin)
378
379{
380    tBTA_DM_API_PIN_REPLY *p_msg =
381        (tBTA_DM_API_PIN_REPLY *)osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY));
382
383    p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
384    bdcpy(p_msg->bd_addr, bd_addr);
385    p_msg->accept = accept;
386    if (accept) {
387        p_msg->pin_len = pin_len;
388        memcpy(p_msg->p_pin, p_pin, pin_len);
389    }
390
391    bta_sys_sendmsg(p_msg);
392}
393
394/*******************************************************************************
395**
396** Function         BTA_DmLocalOob
397**
398** Description      This function retrieves the OOB data from local controller.
399**                  The result is reported by:
400**                  - bta_dm_co_loc_oob_ext() if device supports secure
401**                    connections (SC)
402**                  - bta_dm_co_loc_oob() if device doesn't support SC
403**
404** Returns          void
405**
406*******************************************************************************/
407void BTA_DmLocalOob(void)
408{
409    tBTA_DM_API_LOC_OOB *p_msg =
410        (tBTA_DM_API_LOC_OOB *)osi_malloc(sizeof(tBTA_DM_API_LOC_OOB));
411
412    p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
413    bta_sys_sendmsg(p_msg);
414}
415
416/*******************************************************************************
417**
418** Function         BTA_DmConfirm
419**
420** Description      This function accepts or rejects the numerical value of the
421**                  Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
422**
423** Returns          void
424**
425*******************************************************************************/
426void BTA_DmConfirm(BD_ADDR bd_addr, bool accept)
427{
428    tBTA_DM_API_CONFIRM *p_msg =
429        (tBTA_DM_API_CONFIRM *)osi_malloc(sizeof(tBTA_DM_API_CONFIRM));
430
431    p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
432    bdcpy(p_msg->bd_addr, bd_addr);
433    p_msg->accept = accept;
434
435    bta_sys_sendmsg(p_msg);
436}
437
438/*******************************************************************************
439**
440** Function         BTA_DmAddDevice
441**
442** Description      This function adds a device to the security database list of
443**                  peer device
444**
445**
446** Returns          void
447**
448*******************************************************************************/
449void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
450                     tBTA_SERVICE_MASK trusted_mask, bool is_trusted,
451                     uint8_t key_type, tBTA_IO_CAP io_cap, uint8_t pin_length)
452{
453    tBTA_DM_API_ADD_DEVICE *p_msg =
454        (tBTA_DM_API_ADD_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_ADD_DEVICE));
455
456    p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
457    bdcpy(p_msg->bd_addr, bd_addr);
458    p_msg->tm = trusted_mask;
459    p_msg->is_trusted = is_trusted;
460    p_msg->io_cap = io_cap;
461
462    if (link_key) {
463        p_msg->link_key_known = true;
464        p_msg->key_type = key_type;
465        memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
466    }
467
468    /* Load device class if specified */
469    if (dev_class) {
470        p_msg->dc_known = true;
471        memcpy(p_msg->dc, dev_class, DEV_CLASS_LEN);
472    }
473
474    memset(p_msg->bd_name, 0, BD_NAME_LEN + 1);
475    memset(p_msg->features, 0, sizeof (p_msg->features));
476    p_msg->pin_length = pin_length;
477
478    bta_sys_sendmsg(p_msg);
479}
480
481/*******************************************************************************
482**
483** Function         BTA_DmRemoveDevice
484**
485** Description      This function removes a device fromthe security database list of
486**                  peer device. It manages unpairing even while connected.
487**
488**
489** Returns          void
490**
491*******************************************************************************/
492tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
493{
494    tBTA_DM_API_REMOVE_DEVICE *p_msg =
495        (tBTA_DM_API_REMOVE_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_REMOVE_DEVICE));
496
497    p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
498    bdcpy(p_msg->bd_addr, bd_addr);
499
500    bta_sys_sendmsg(p_msg);
501
502    return BTA_SUCCESS;
503}
504
505/*******************************************************************************
506**
507** Function         BTA_GetEirService
508**
509** Description      This function is called to get BTA service mask from EIR.
510**
511** Parameters       p_eir - pointer of EIR significant part
512**                  p_services - return the BTA service mask
513**
514** Returns          None
515**
516*******************************************************************************/
517extern const uint16_t bta_service_id_to_uuid_lkup_tbl [];
518void BTA_GetEirService( uint8_t *p_eir, tBTA_SERVICE_MASK *p_services )
519{
520    uint8_t xx, yy;
521    uint8_t num_uuid, max_num_uuid = 32;
522    uint8_t uuid_list[32*LEN_UUID_16];
523    uint16_t *p_uuid16 = (uint16_t *)uuid_list;
524    tBTA_SERVICE_MASK mask;
525
526    BTM_GetEirUuidList( p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid);
527    for( xx = 0; xx < num_uuid; xx++ )
528    {
529        mask = 1;
530        for( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ )
531        {
532            if( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] )
533            {
534                *p_services |= mask;
535                break;
536            }
537            mask <<= 1;
538        }
539
540        /* for HSP v1.2 only device */
541        if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS)
542            *p_services |= BTA_HSP_SERVICE_MASK;
543
544       if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE)
545            *p_services |= BTA_HL_SERVICE_MASK;
546
547        if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK)
548            *p_services |= BTA_HL_SERVICE_MASK;
549    }
550}
551
552/*******************************************************************************
553**
554** Function         BTA_DmGetConnectionState
555**
556** Description      Returns whether the remote device is currently connected.
557**
558** Returns          0 if the device is NOT connected.
559**
560*******************************************************************************/
561uint16_t BTA_DmGetConnectionState(const BD_ADDR bd_addr )
562{
563    tBTA_DM_PEER_DEVICE * p_dev = bta_dm_find_peer_device(bd_addr);
564    return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
565}
566
567
568/*******************************************************************************
569**                   Device Identification (DI) Server Functions
570*******************************************************************************/
571/*******************************************************************************
572**
573** Function         BTA_DmSetLocalDiRecord
574**
575** Description      This function adds a DI record to the local SDP database.
576**
577** Returns          BTA_SUCCESS if record set sucessfully, otherwise error code.
578**
579*******************************************************************************/
580tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
581                              uint32_t *p_handle )
582{
583    tBTA_STATUS  status = BTA_FAILURE;
584
585    if(bta_dm_di_cb.di_num < BTA_DI_NUM_MAX)
586    {
587        if(SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS)
588        {
589            if(!p_device_info->primary_record)
590            {
591                bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
592                bta_dm_di_cb.di_num ++;
593            }
594
595            bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
596            status =  BTA_SUCCESS;
597        }
598    }
599
600    return status;
601}
602
603/*******************************************************************************
604**
605** Function         bta_dmexecutecallback
606**
607** Description      This function will request BTA to execute a call back in the context of BTU task
608**                  This API was named in lower case because it is only intended
609**                  for the internal customers(like BTIF).
610**
611** Returns          void
612**
613*******************************************************************************/
614void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param)
615{
616    tBTA_DM_API_EXECUTE_CBACK *p_msg =
617        (tBTA_DM_API_EXECUTE_CBACK *)osi_malloc(sizeof(tBTA_DM_MSG));
618
619    p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
620    p_msg->p_param= p_param;
621    p_msg->p_exec_cback= p_callback;
622
623    bta_sys_sendmsg(p_msg);
624}
625
626/*******************************************************************************
627**
628** Function         BTA_DmAddBleKey
629**
630** Description      Add/modify LE device information.  This function will be
631**                  normally called during host startup to restore all required
632**                  information stored in the NVRAM.
633**
634** Parameters:      bd_addr          - BD address of the peer
635**                  p_le_key         - LE key values.
636**                  key_type         - LE SMP key type.
637**
638** Returns          BTA_SUCCESS if successful
639**                  BTA_FAIL if operation failed.
640**
641*******************************************************************************/
642void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_TYPE key_type)
643{
644#if (BLE_INCLUDED == TRUE)
645
646    tBTA_DM_API_ADD_BLEKEY *p_msg =
647        (tBTA_DM_API_ADD_BLEKEY *)osi_calloc(sizeof(tBTA_DM_API_ADD_BLEKEY));
648
649    p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
650    p_msg->key_type = key_type;
651    bdcpy(p_msg->bd_addr, bd_addr);
652    memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE));
653
654    bta_sys_sendmsg(p_msg);
655#endif
656}
657
658/*******************************************************************************
659**
660** Function         BTA_DmAddBleDevice
661**
662** Description      Add a BLE device.  This function will be normally called
663**                  during host startup to restore all required information
664**                  for a LE device stored in the NVRAM.
665**
666** Parameters:      bd_addr          - BD address of the peer
667**                  dev_type         - Remote device's device type.
668**                  addr_type        - LE device address type.
669**
670** Returns          void
671**
672*******************************************************************************/
673void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TYPE dev_type)
674{
675#if (BLE_INCLUDED == TRUE)
676    tBTA_DM_API_ADD_BLE_DEVICE *p_msg =
677        (tBTA_DM_API_ADD_BLE_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
678
679    p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
680    bdcpy(p_msg->bd_addr, bd_addr);
681    p_msg->addr_type = addr_type;
682    p_msg->dev_type = dev_type;
683
684    bta_sys_sendmsg(p_msg);
685#endif
686}
687
688/*******************************************************************************
689**
690** Function         BTA_DmBlePasskeyReply
691**
692** Description      Send BLE SMP passkey reply.
693**
694** Parameters:      bd_addr          - BD address of the peer
695**                  accept           - passkey entry sucessful or declined.
696**                  passkey          - passkey value, must be a 6 digit number,
697**                                     can be lead by 0.
698**
699** Returns          void
700**
701*******************************************************************************/
702void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, bool accept, uint32_t passkey)
703{
704#if (BLE_INCLUDED == TRUE)
705    tBTA_DM_API_PASSKEY_REPLY *p_msg =
706        (tBTA_DM_API_PASSKEY_REPLY *)osi_calloc(sizeof(tBTA_DM_API_PASSKEY_REPLY));
707
708    p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
709    bdcpy(p_msg->bd_addr, bd_addr);
710    p_msg->accept = accept;
711
712    if (accept)
713        p_msg->passkey = passkey;
714
715    bta_sys_sendmsg(p_msg);
716#endif
717}
718
719/*******************************************************************************
720**
721** Function         BTA_DmBleConfirmReply
722**
723** Description      Send BLE SMP SC user confirmation reply.
724**
725** Parameters:      bd_addr          - BD address of the peer
726**                  accept           - numbers to compare are the same or different.
727**
728** Returns          void
729**
730*******************************************************************************/
731void BTA_DmBleConfirmReply(BD_ADDR bd_addr, bool accept)
732{
733#if (BLE_INCLUDED == TRUE)
734    tBTA_DM_API_CONFIRM *p_msg =
735        (tBTA_DM_API_CONFIRM *)osi_calloc(sizeof(tBTA_DM_API_CONFIRM));
736
737    p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT;
738    bdcpy(p_msg->bd_addr, bd_addr);
739    p_msg->accept = accept;
740
741    bta_sys_sendmsg(p_msg);
742#endif
743}
744
745/*******************************************************************************
746**
747** Function         BTA_DmBleSecurityGrant
748**
749** Description      Grant security request access.
750**
751** Parameters:      bd_addr          - BD address of the peer
752**                  res              - security grant status.
753**
754** Returns          void
755**
756*******************************************************************************/
757void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
758{
759#if (BLE_INCLUDED == TRUE)
760    tBTA_DM_API_BLE_SEC_GRANT *p_msg =
761        (tBTA_DM_API_BLE_SEC_GRANT *)osi_calloc(sizeof(tBTA_DM_API_BLE_SEC_GRANT));
762
763    p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
764    bdcpy(p_msg->bd_addr, bd_addr);
765    p_msg->res = res;
766
767    bta_sys_sendmsg(p_msg);
768#endif
769}
770
771/*******************************************************************************
772**
773** Function         BTA_DmSetBlePrefConnParams
774**
775** Description      This function is called to set the preferred connection
776**                  parameters when default connection parameter is not desired.
777**
778** Parameters:      bd_addr          - BD address of the peripheral
779**                  scan_interval    - scan interval
780**                  scan_window      - scan window
781**                  min_conn_int     - minimum preferred connection interval
782**                  max_conn_int     - maximum preferred connection interval
783**                  slave_latency    - preferred slave latency
784**                  supervision_tout - preferred supervision timeout
785**
786**
787** Returns          void
788**
789*******************************************************************************/
790void BTA_DmSetBlePrefConnParams(const BD_ADDR bd_addr,
791                               uint16_t min_conn_int, uint16_t max_conn_int,
792                               uint16_t slave_latency, uint16_t supervision_tout )
793{
794#if (BLE_INCLUDED == TRUE)
795    tBTA_DM_API_BLE_CONN_PARAMS *p_msg =
796        (tBTA_DM_API_BLE_CONN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
797
798    p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
799    memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN);
800    p_msg->conn_int_max = max_conn_int;
801    p_msg->conn_int_min = min_conn_int;
802    p_msg->slave_latency = slave_latency;
803    p_msg->supervision_tout = supervision_tout;
804
805    bta_sys_sendmsg(p_msg);
806#endif
807}
808
809/*******************************************************************************
810**
811** Function         BTA_DmSetBleConnScanParams
812**
813** Description      This function is called to set scan parameters used in
814**                  BLE connection request
815**
816** Parameters:      scan_interval    - scan interval
817**                  scan_window      - scan window
818**
819** Returns          void
820**
821*******************************************************************************/
822void BTA_DmSetBleConnScanParams(uint32_t scan_interval, uint32_t scan_window)
823{
824#if (BLE_INCLUDED == TRUE)
825    tBTA_DM_API_BLE_SCAN_PARAMS *p_msg =
826        (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
827
828    p_msg->hdr.event = BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT;
829    p_msg->scan_int = scan_interval;
830    p_msg->scan_window = scan_window;
831
832    bta_sys_sendmsg(p_msg);
833#endif  // BLE_INCLUDED == true
834}
835
836/*******************************************************************************
837**
838** Function         BTA_DmSetBleScanParams
839**
840** Description      This function is called to set scan parameters
841**
842** Parameters:      client_if - Client IF
843**                  scan_interval - scan interval
844**                  scan_window - scan window
845**                  scan_mode - scan mode
846**                  scan_param_setup_status_cback - Set scan param status callback
847**
848** Returns          void
849**
850*******************************************************************************/
851
852#if (BLE_INCLUDED == TRUE)
853void BTA_DmSetBleScanParams(tGATT_IF client_if, uint32_t scan_interval,
854                            uint32_t scan_window, tBLE_SCAN_MODE scan_mode,
855                            tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
856{
857    tBTA_DM_API_BLE_SCAN_PARAMS *p_msg =
858        (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
859
860    p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT;
861    p_msg->client_if = client_if;
862    p_msg->scan_int = scan_interval;
863    p_msg->scan_window = scan_window;
864    p_msg->scan_mode = scan_mode;
865    p_msg->scan_param_setup_cback = scan_param_setup_cback;
866
867    bta_sys_sendmsg(p_msg);
868}
869#endif  // BLE_INCLUDED == true
870
871/*******************************************************************************
872**
873** Function         BTA_DmSetBleAdvParams
874**
875** Description      This function sets the advertising parameters BLE functionality.
876**                  It is to be called when device act in peripheral or broadcaster
877**                  role.
878**
879**
880** Returns          void
881**
882*******************************************************************************/
883void BTA_DmSetBleAdvParams(uint16_t adv_int_min, uint16_t adv_int_max,
884                           tBLE_BD_ADDR *p_dir_bda)
885{
886#if (BLE_INCLUDED == TRUE)
887    if (p_dir_bda != NULL) {
888        tBLE_BD_ADDR *bda  = new tBLE_BD_ADDR;
889        memcpy(bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
890        do_in_bta_thread(FROM_HERE,
891          base::Bind(&bta_dm_ble_set_adv_params, adv_int_min, adv_int_max, base::Owned(bda)));
892    }
893
894    do_in_bta_thread(FROM_HERE,
895      base::Bind(&bta_dm_ble_set_adv_params, adv_int_min, adv_int_max, nullptr));
896
897#endif
898}
899
900/*******************************************************************************
901**                      BLE ADV data management API
902********************************************************************************/
903
904#if (BLE_INCLUDED == TRUE)
905/*******************************************************************************
906**
907** Function         BTA_DmBleSetAdvConfig
908**
909** Description      This function is called to override the BTA default ADV parameters.
910**
911** Parameters       data_mask: adv data mask.
912**                  p_adv_cfg: Pointer to User defined ADV data structure. This
913**                             memory space can not be freed until p_adv_data_cback
914**                             is received.
915**                  p_adv_data_cback: set adv data complete callback.
916**
917** Returns          None
918**
919*******************************************************************************/
920void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
921                            tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
922{
923  tBTA_BLE_ADV_DATA *adv_cfg = new tBTA_BLE_ADV_DATA;
924  memcpy(adv_cfg, p_adv_cfg, sizeof(tBTA_BLE_ADV_DATA));
925
926  do_in_bta_thread(FROM_HERE,
927      base::Bind(&bta_dm_ble_set_adv_config, data_mask, base::Owned(adv_cfg), p_adv_data_cback));
928}
929
930/*******************************************************************************
931**
932** Function         BTA_DmBleSetScanRsp
933**
934** Description      This function is called to override the BTA scan response.
935**
936** Parameters       Pointer to User defined ADV data structure
937**
938** Returns          None
939**
940*******************************************************************************/
941extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
942                                 tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
943{
944  tBTA_BLE_ADV_DATA *adv_cfg = new tBTA_BLE_ADV_DATA;
945  memcpy(adv_cfg, p_adv_cfg, sizeof(tBTA_BLE_ADV_DATA));
946
947  do_in_bta_thread(FROM_HERE,
948      base::Bind(&bta_dm_ble_set_scan_rsp, data_mask, base::Owned(adv_cfg), p_adv_data_cback));
949}
950
951/*******************************************************************************
952**
953** Function         BTA_DmBleSetStorageParams
954**
955** Description      This function is called to override the BTA scan response.
956**
957** Parameters       batch_scan_full_max -Max storage space (in %) allocated to full scanning
958**                  batch_scan_trunc_max -Max storage space (in %) allocated to truncated scanning
959**                  batch_scan_notify_threshold -Setup notification level based on total space
960**                  p_setup_cback - Setup callback pointer
961**                  p_thres_cback - Threshold callback pointer
962**                  p_rep_cback - Reports callback pointer
963**                  ref_value - Ref value
964**
965** Returns          None
966**
967*******************************************************************************/
968extern void BTA_DmBleSetStorageParams(uint8_t batch_scan_full_max,
969                                         uint8_t batch_scan_trunc_max,
970                                         uint8_t batch_scan_notify_threshold,
971                                         tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback,
972                                         tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback,
973                                         tBTA_BLE_SCAN_REP_CBACK* p_rep_cback,
974                                         tBTA_DM_BLE_REF_VALUE ref_value)
975{
976    tBTA_DM_API_SET_STORAGE_CONFIG *p_msg =
977        (tBTA_DM_API_SET_STORAGE_CONFIG *)osi_malloc(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG));
978
979    bta_dm_cb.p_setup_cback = p_setup_cback;
980
981    p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT;
982    p_msg->p_setup_cback=bta_ble_scan_setup_cb;
983    p_msg->p_thres_cback=p_thres_cback;
984    p_msg->p_read_rep_cback=p_rep_cback;
985    p_msg->ref_value = ref_value;
986    p_msg->batch_scan_full_max = batch_scan_full_max;
987    p_msg->batch_scan_trunc_max = batch_scan_trunc_max;
988    p_msg->batch_scan_notify_threshold = batch_scan_notify_threshold;
989
990    bta_sys_sendmsg(p_msg);
991}
992
993/*******************************************************************************
994**
995** Function         BTA_DmBleEnableBatchScan
996**
997** Description      This function is called to enable the batch scan
998**
999** Parameters       scan_mode -Batch scan mode
1000**                  scan_interval - Scan interval
1001**                  scan_window - Scan window
1002**                  discard_rule -Discard rules
1003**                  addr_type - Address type
1004**                  ref_value - Reference value
1005**
1006** Returns          None
1007**
1008*******************************************************************************/
1009extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode,
1010                                         uint32_t scan_interval, uint32_t scan_window,
1011                                         tBTA_BLE_DISCARD_RULE discard_rule,
1012                                         tBLE_ADDR_TYPE        addr_type,
1013                                         tBTA_DM_BLE_REF_VALUE ref_value)
1014{
1015    tBTA_DM_API_ENABLE_SCAN *p_msg =
1016        (tBTA_DM_API_ENABLE_SCAN *)osi_malloc(sizeof(tBTA_DM_API_ENABLE_SCAN));
1017
1018    p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT;
1019    p_msg->scan_mode = scan_mode;
1020    p_msg->scan_int = scan_interval;
1021    p_msg->scan_window = scan_window;
1022    p_msg->discard_rule = discard_rule;
1023    p_msg->addr_type = addr_type;
1024    p_msg->ref_value = ref_value;
1025
1026    bta_sys_sendmsg(p_msg);
1027}
1028
1029/*******************************************************************************
1030**
1031** Function         BTA_DmBleDisableBatchScan
1032**
1033** Description      This function is called to disable the batch scan
1034**
1035** Parameters       ref_value - Reference value
1036**
1037** Returns          None
1038**
1039*******************************************************************************/
1040extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)
1041{
1042    tBTA_DM_API_DISABLE_SCAN *p_msg =
1043        (tBTA_DM_API_DISABLE_SCAN *)osi_malloc(sizeof(tBTA_DM_API_DISABLE_SCAN));
1044
1045    p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT;
1046    p_msg->ref_value = ref_value;
1047
1048    bta_sys_sendmsg(p_msg);
1049}
1050
1051/*******************************************************************************
1052**
1053** Function         BTA_DmBleReadScanReports
1054**
1055** Description      This function is called to read scan reports
1056**
1057** Parameters       scan_type -Batch scan mode
1058**                  ref_value - Reference value
1059**
1060** Returns          None
1061**
1062*******************************************************************************/
1063extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type,
1064                                             tBTA_DM_BLE_REF_VALUE ref_value)
1065{
1066    tBTA_DM_API_READ_SCAN_REPORTS *p_msg =
1067        (tBTA_DM_API_READ_SCAN_REPORTS *)osi_malloc(sizeof(tBTA_DM_API_READ_SCAN_REPORTS));
1068
1069    p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT;
1070    p_msg->scan_type = scan_type;
1071    p_msg->ref_value = ref_value;
1072
1073    bta_sys_sendmsg(p_msg);
1074}
1075
1076/*******************************************************************************
1077**
1078** Function         BTA_DmBleTrackAdvertiser
1079**
1080** Description      This function is called to track advertiser
1081**
1082** Parameters       ref_value - Reference value
1083**                  p_track_adv_cback - Track ADV callback
1084**
1085** Returns          None
1086**
1087*******************************************************************************/
1088extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
1089                            tBTA_BLE_TRACK_ADV_CBACK *p_track_adv_cback)
1090{
1091    tBTA_DM_API_TRACK_ADVERTISER *p_msg =
1092        (tBTA_DM_API_TRACK_ADVERTISER *)osi_malloc(sizeof(tBTA_DM_API_TRACK_ADVERTISER));
1093
1094    p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT;
1095    p_msg->p_track_adv_cback = p_track_adv_cback;
1096    p_msg->ref_value = ref_value;
1097
1098    bta_sys_sendmsg(p_msg);
1099}
1100
1101#endif
1102
1103/*******************************************************************************
1104**                      BLE ADV data management API
1105********************************************************************************/
1106#if (BLE_INCLUDED == TRUE)
1107
1108/*******************************************************************************
1109**
1110** Function         BTA_DmBleBroadcast
1111**
1112** Description      This function starts or stops LE broadcasting.
1113**
1114** Parameters       start: start or stop broadcast.
1115**
1116** Returns          None
1117**
1118*******************************************************************************/
1119extern void BTA_DmBleBroadcast (bool start)
1120{
1121    tBTA_DM_API_BLE_OBSERVE *p_msg =
1122        (tBTA_DM_API_BLE_OBSERVE *)osi_calloc(sizeof(tBTA_DM_API_BLE_OBSERVE));
1123
1124    APPL_TRACE_API("BTA_DmBleBroadcast: start = %d ", start);
1125
1126    p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
1127    p_msg->start = start;
1128
1129    bta_sys_sendmsg(p_msg);
1130}
1131
1132#endif
1133/*******************************************************************************
1134**
1135** Function         BTA_DmBleSetBgConnType
1136**
1137** Description      This function is called to set BLE connectable mode for a
1138**                  peripheral device.
1139**
1140** Parameters       bg_conn_type: it can be auto connection, or selective connection.
1141**                  p_select_cback: callback function when selective connection procedure
1142**                              is being used.
1143**
1144** Returns          void
1145**
1146*******************************************************************************/
1147void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback)
1148{
1149#if (BLE_INCLUDED == TRUE)
1150    tBTA_DM_API_BLE_SET_BG_CONN_TYPE *p_msg =
1151        (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *)osi_calloc(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
1152
1153    p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
1154    p_msg->bg_conn_type = bg_conn_type;
1155    p_msg->p_select_cback = p_select_cback;
1156
1157    bta_sys_sendmsg(p_msg);
1158#endif
1159}
1160
1161/*******************************************************************************
1162**
1163** Function         bta_dm_discover_send_msg
1164**
1165** Description      This function send discover message to BTA task.
1166**
1167** Returns          void
1168**
1169*******************************************************************************/
1170#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1171static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1172                    tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search,
1173                    tBTA_TRANSPORT transport)
1174{
1175    const size_t len = p_services ?
1176        (sizeof(tBTA_DM_API_DISCOVER) + sizeof(tBT_UUID) * p_services->num_uuid)
1177        : sizeof(tBTA_DM_API_DISCOVER);
1178    tBTA_DM_API_DISCOVER *p_msg = (tBTA_DM_API_DISCOVER *)osi_calloc(len);
1179
1180    p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
1181    bdcpy(p_msg->bd_addr, bd_addr);
1182    p_msg->p_cback = p_cback;
1183    p_msg->sdp_search = sdp_search;
1184    p_msg->transport    = transport;
1185
1186    if (p_services != NULL) {
1187#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1188        p_msg->services = p_services->srvc_mask;
1189        p_msg->num_uuid = p_services->num_uuid;
1190        if (p_services->num_uuid != 0) {
1191            p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1192            memcpy(p_msg->p_uuid, p_services->p_uuid,
1193                   sizeof(tBT_UUID) * p_services->num_uuid);
1194        }
1195#endif
1196    }
1197
1198    bta_sys_sendmsg(p_msg);
1199}
1200#endif
1201
1202/*******************************************************************************
1203**
1204** Function         BTA_DmDiscoverByTransport
1205**
1206** Description      This function does service discovery on particular transport
1207**                  for services of a
1208**                  peer device. When services.num_uuid is 0, it indicates all
1209**                  GATT based services are to be searched; otherwise a list of
1210**                  UUID of interested services should be provided through
1211**                  p_services->p_uuid.
1212**
1213**
1214**
1215** Returns          void
1216**
1217*******************************************************************************/
1218void BTA_DmDiscoverByTransport(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1219                    tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search,
1220                    tBTA_TRANSPORT transport)
1221{
1222#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1223    bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
1224#endif
1225}
1226
1227
1228/*******************************************************************************
1229**
1230** Function         BTA_DmDiscoverExt
1231**
1232** Description      This function does service discovery for services of a
1233**                  peer device. When services.num_uuid is 0, it indicates all
1234**                  GATT based services are to be searched; other wise a list of
1235**                  UUID of interested services should be provided through
1236**                  p_services->p_uuid.
1237**
1238**
1239**
1240** Returns          void
1241**
1242*******************************************************************************/
1243void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1244                    tBTA_DM_SEARCH_CBACK *p_cback, bool sdp_search)
1245{
1246#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1247    bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, BTA_TRANSPORT_UNKNOWN);
1248#endif
1249
1250}
1251
1252/*******************************************************************************
1253**
1254** Function         BTA_DmSearchExt
1255**
1256** Description      This function searches for peer Bluetooth devices. It performs
1257**                  an inquiry and gets the remote name for devices. Service
1258**                  discovery is done if services is non zero
1259**
1260** Parameters       p_dm_inq: inquiry conditions
1261**                  p_services: if service is not empty, service discovery will be done.
1262**                            for all GATT based service condition, put num_uuid, and
1263**                            p_uuid is the pointer to the list of UUID values.
1264**                  p_cback: callback functino when search is completed.
1265**
1266**
1267**
1268** Returns          void
1269**
1270*******************************************************************************/
1271void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback)
1272{
1273#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1274    const size_t len = p_services ?
1275        (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid)
1276        : sizeof(tBTA_DM_API_SEARCH);
1277    tBTA_DM_API_SEARCH *p_msg = (tBTA_DM_API_SEARCH *)osi_calloc(len);
1278
1279    p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
1280    memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
1281    p_msg->p_cback = p_cback;
1282    p_msg->rs_res  = BTA_DM_RS_NONE;
1283
1284    if (p_services != NULL) {
1285        p_msg->services = p_services->srvc_mask;
1286        p_msg->num_uuid = p_services->num_uuid;
1287
1288        if (p_services->num_uuid != 0) {
1289            p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1290            memcpy(p_msg->p_uuid, p_services->p_uuid,
1291                   sizeof(tBT_UUID) * p_services->num_uuid);
1292        } else {
1293            p_msg->p_uuid = NULL;
1294        }
1295    }
1296
1297    bta_sys_sendmsg(p_msg);
1298#else
1299    UNUSED(p_dm_inq);
1300    UNUSED(p_services);
1301    UNUSED(p_cback);
1302#endif
1303}
1304/*******************************************************************************
1305**
1306** Function         BTA_DmBleUpdateConnectionParam
1307**
1308** Description      Update connection parameters, can only be used when connection is up.
1309**
1310** Parameters:      bd_addr          - BD address of the peer
1311**                  min_int   -     minimum connection interval, [0x0004~ 0x4000]
1312**                  max_int   -     maximum connection interval, [0x0004~ 0x4000]
1313**                  latency   -     slave latency [0 ~ 500]
1314**                  timeout   -     supervision timeout [0x000a ~ 0xc80]
1315**
1316** Returns          void
1317**
1318*******************************************************************************/
1319void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, uint16_t min_int,
1320                                    uint16_t max_int, uint16_t latency,
1321                                    uint16_t timeout)
1322{
1323#if (BLE_INCLUDED == TRUE)
1324    tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
1325        (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1326
1327    p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1328    bdcpy(p_msg->bd_addr, bd_addr);
1329    p_msg->min_int = min_int;
1330    p_msg->max_int = max_int;
1331    p_msg->latency = latency;
1332    p_msg->timeout = timeout;
1333
1334    bta_sys_sendmsg(p_msg);
1335#endif
1336}
1337
1338/*******************************************************************************
1339**
1340** Function         BTA_DmBleConfigLocalPrivacy
1341**
1342** Description      Enable/disable privacy on the local device
1343**
1344** Parameters:      privacy_enable   - enable/disabe privacy on remote device.
1345**
1346** Returns          void
1347**
1348*******************************************************************************/
1349void BTA_DmBleConfigLocalPrivacy(bool privacy_enable)
1350{
1351#if (BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE)
1352    tBTA_DM_API_LOCAL_PRIVACY *p_msg =
1353        (tBTA_DM_API_LOCAL_PRIVACY *)osi_calloc(sizeof(tBTA_DM_API_ENABLE_PRIVACY));
1354
1355    p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
1356    p_msg->privacy_enable   = privacy_enable;
1357
1358    bta_sys_sendmsg(p_msg);
1359#else
1360    UNUSED (privacy_enable);
1361#endif
1362}
1363
1364#if (BLE_INCLUDED == TRUE)
1365
1366/*******************************************************************************
1367**
1368** Register an advertising instance, status will be returned in |p_cback|
1369** callback, with assigned id, if operation succeeds. Instance is freed when
1370** advertising is disabled by calling |BTA_BleDisableAdvInstance|, or when any
1371** of the operations fails.
1372*******************************************************************************/
1373void BTA_BleAdvRegisterInstance(tBTA_BLE_MULTI_ADV_CBACK *p_cback) {
1374    do_in_bta_thread(FROM_HERE,
1375        base::Bind(&bta_dm_ble_multi_adv_register, p_cback));
1376}
1377
1378/*******************************************************************************
1379**
1380** Function         BTA_BleEnableAdvInstance
1381**
1382** Description      This function enable a Multi-ADV instance with the specififed
1383**                  adv parameters
1384**
1385** Parameters       inst_id: Adv instance to update the parameter.
1386**                  p_params: pointer to the adv parameter structure.
1387**
1388** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
1389**
1390*******************************************************************************/
1391void BTA_BleEnableAdvInstance (uint8_t inst_id, tBTA_BLE_ADV_PARAMS *p_params)
1392{
1393    APPL_TRACE_API("%s", __func__);
1394
1395    if (p_params != NULL) {
1396        tBTA_BLE_ADV_PARAMS *params = new tBTA_BLE_ADV_PARAMS;
1397        memcpy(params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
1398        do_in_bta_thread(FROM_HERE,
1399            base::Bind(&bta_dm_ble_multi_adv_enb, inst_id, base::Owned(params)));
1400    } else {
1401        do_in_bta_thread(FROM_HERE,
1402            base::Bind(&bta_dm_ble_multi_adv_enb, inst_id, nullptr));
1403    }
1404}
1405
1406/*******************************************************************************
1407**
1408** Function         BTA_BleUpdateAdvInstParam
1409**
1410** Description      This function update a Multi-ADV instance with the specififed
1411**                  adv parameters.
1412**
1413** Parameters       inst_id: Adv instance to update the parameter.
1414**                  p_params: pointer to the adv parameter structure.
1415**
1416** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
1417**
1418*******************************************************************************/
1419void BTA_BleUpdateAdvInstParam (uint8_t inst_id, tBTA_BLE_ADV_PARAMS *p_params)
1420{
1421    APPL_TRACE_API("%s", __func__);
1422
1423    tBTA_BLE_ADV_PARAMS *params = new tBTA_BLE_ADV_PARAMS;
1424    memcpy(params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
1425    do_in_bta_thread(FROM_HERE,
1426        base::Bind(&bta_dm_ble_multi_adv_upd_param, inst_id, base::Owned(params)));
1427}
1428
1429/*******************************************************************************
1430**
1431** Function         BTA_BleCfgAdvInstData
1432**
1433** Description      This function configure a Multi-ADV instance with the specififed
1434**                  adv data or scan response data.
1435**
1436** Parameter        inst_id: Adv instance to configure the adv data or scan response.
1437**                  is_scan_rsp: is the data scan response or adv data.
1438**                  data_mask: adv data type as bit mask.
1439**                  p_data: pointer to the ADV data structure tBTA_BLE_ADV_DATA. This
1440**                  memory space can not be freed until BTA_BLE_MULTI_ADV_DATA_EVT
1441**                  is sent to application.
1442**
1443** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
1444**
1445*******************************************************************************/
1446void BTA_BleCfgAdvInstData (uint8_t inst_id, bool is_scan_rsp,
1447                            tBTA_BLE_AD_MASK data_mask,
1448                            tBTA_BLE_ADV_DATA *p_data)
1449{
1450  do_in_bta_thread(FROM_HERE,
1451      base::Bind(&bta_dm_ble_multi_adv_data, inst_id, is_scan_rsp, data_mask, *p_data));
1452}
1453
1454/*******************************************************************************
1455**
1456** Function         BTA_BleDisableAdvInstance
1457**
1458** Description      This function disable a Multi-ADV instance.
1459**
1460** Parameter        inst_id: instance ID to disable.
1461**
1462** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
1463**
1464*******************************************************************************/
1465void BTA_BleDisableAdvInstance(uint8_t inst_id)
1466{
1467    APPL_TRACE_API("%s: %d", __func__, inst_id);
1468
1469    do_in_bta_thread(FROM_HERE,
1470        base::Bind(&btm_dm_ble_multi_adv_disable, inst_id));
1471}
1472
1473/*******************************************************************************
1474**
1475** Function         BTA_DmBleCfgFilterCondition
1476**
1477** Description      This function is called to configure the adv data payload filter
1478**                  condition.
1479**
1480** Parameters       action: to read/write/clear
1481**                  cond_type: filter condition type
1482**                  filt_index - Filter index
1483**                  p_cond: filter condition parameter
1484**                  p_cmpl_back - Command completed callback
1485**                  ref_value - Reference value
1486**
1487** Returns          void
1488**
1489*******************************************************************************/
1490void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
1491                                 tBTA_DM_BLE_PF_COND_TYPE cond_type,
1492                                 tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1493                                 tBTA_DM_BLE_PF_COND_PARAM *p_cond,
1494                                 tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback,
1495                                 tBTA_DM_BLE_REF_VALUE ref_value)
1496{
1497#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
1498    tBTA_DM_API_CFG_FILTER_COND *p_msg;
1499    APPL_TRACE_API ("BTA_DmBleCfgFilterCondition: %d, %d", action, cond_type);
1500
1501    uint16_t  len = sizeof(tBTA_DM_API_CFG_FILTER_COND) +
1502                  sizeof(tBTA_DM_BLE_PF_COND_PARAM);
1503    uint8_t *p;
1504
1505    if (NULL != p_cond)
1506    {
1507        switch(cond_type)
1508        {
1509            case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:
1510            case BTA_DM_BLE_PF_MANU_DATA:
1511                /* Length of pattern and pattern mask and other elements in */
1512                /* tBTA_DM_BLE_PF_MANU_COND */
1513                len += ((p_cond->manu_data.data_len) * 2) +
1514                        sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint8_t);
1515                break;
1516
1517            case BTA_DM_BLE_PF_LOCAL_NAME:
1518                len += ((p_cond->local_name.data_len) + sizeof(uint8_t));
1519                break;
1520
1521            case BTM_BLE_PF_SRVC_UUID:
1522            case BTM_BLE_PF_SRVC_SOL_UUID:
1523                len += sizeof(tBLE_BD_ADDR) + sizeof(tBTA_DM_BLE_PF_COND_MASK);
1524                break;
1525
1526            default:
1527                break;
1528        }
1529    }
1530
1531    p_msg = (tBTA_DM_API_CFG_FILTER_COND *)osi_calloc(len);
1532    p_msg->hdr.event = BTA_DM_API_CFG_FILTER_COND_EVT;
1533    p_msg->action = action;
1534    p_msg->cond_type = cond_type;
1535    p_msg->filt_index = filt_index;
1536    p_msg->p_filt_cfg_cback = p_cmpl_cback;
1537    p_msg->ref_value = ref_value;
1538    if (p_cond) {
1539        p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM *)(p_msg + 1);
1540        memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
1541
1542        p = (uint8_t *)(p_msg->p_cond_param + 1);
1543
1544        if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN ||
1545            cond_type == BTA_DM_BLE_PF_MANU_DATA) {
1546            p_msg->p_cond_param->manu_data.p_pattern = p;
1547            p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len;
1548            memcpy(p_msg->p_cond_param->manu_data.p_pattern, p_cond->manu_data.p_pattern,
1549                   p_cond->manu_data.data_len);
1550            p += p_cond->manu_data.data_len;
1551
1552            if (cond_type == BTA_DM_BLE_PF_MANU_DATA) {
1553                p_msg->p_cond_param->manu_data.company_id_mask =
1554                    p_cond->manu_data.company_id_mask;
1555                if ( p_cond->manu_data.p_pattern_mask != NULL) {
1556                    p_msg->p_cond_param->manu_data.p_pattern_mask = p;
1557                    memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask,
1558                           p_cond->manu_data.p_pattern_mask,
1559                           p_cond->manu_data.data_len);
1560                }
1561            }
1562        } else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME) {
1563            p_msg->p_cond_param->local_name.p_data = p;
1564            p_msg->p_cond_param->local_name.data_len =
1565                p_cond->local_name.data_len;
1566            memcpy(p_msg->p_cond_param->local_name.p_data,
1567                   p_cond->local_name.p_data, p_cond->local_name.data_len);
1568        } else if (cond_type == BTM_BLE_PF_SRVC_UUID ||
1569                   cond_type == BTM_BLE_PF_SRVC_SOL_UUID) {
1570            if (p_cond->srvc_uuid.p_target_addr != NULL) {
1571                p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR *)(p);
1572                p_msg->p_cond_param->srvc_uuid.p_target_addr->type =
1573                    p_cond->srvc_uuid.p_target_addr->type;
1574                memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda,
1575                       p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN);
1576                p = (uint8_t *)(p_msg->p_cond_param->srvc_uuid.p_target_addr + 1);
1577            }
1578            if (p_cond->srvc_uuid.p_uuid_mask) {
1579                p_msg->p_cond_param->srvc_uuid.p_uuid_mask = (tBTA_DM_BLE_PF_COND_MASK *)p;
1580                memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask,
1581                       p_cond->srvc_uuid.p_uuid_mask,
1582                       sizeof(tBTA_DM_BLE_PF_COND_MASK));
1583            }
1584        }
1585    }
1586
1587    bta_sys_sendmsg(p_msg);
1588
1589#else
1590    UNUSED(action);
1591    UNUSED(cond_type);
1592    UNUSED(filt_index);
1593    UNUSED(p_cond);
1594    UNUSED(p_cmpl_cback);
1595    UNUSED(ref_value);
1596#endif
1597}
1598
1599/*******************************************************************************
1600**
1601** Function         BTA_DmBleScanFilterSetup
1602**
1603** Description      This function is called to setup the adv data payload filter param
1604**
1605** Parameters       p_target: enable the filter condition on a target device; if NULL
1606**                  filt_index - Filter index
1607**                  p_filt_params -Filter parameters
1608**                  ref_value - Reference value
1609**                  action - Add, delete or clear
1610**                  p_cmpl_back - Command completed callback
1611**
1612** Returns          void
1613**
1614*******************************************************************************/
1615void BTA_DmBleScanFilterSetup(uint8_t action,
1616                              tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1617                              tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params,
1618                              tBLE_BD_ADDR *p_target,
1619                              tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback,
1620                              tBTA_DM_BLE_REF_VALUE ref_value)
1621{
1622#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
1623    const size_t len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) +
1624        sizeof(tBLE_BD_ADDR);
1625    tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *p_msg =
1626        (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *)osi_calloc(len);
1627
1628    APPL_TRACE_API("%s: %d", __func__, action);
1629
1630    p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_SETUP_EVT;
1631    p_msg->action = action;
1632    p_msg->filt_index = filt_index;
1633    if (p_filt_params) {
1634        memcpy(&p_msg->filt_params, p_filt_params,
1635               sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1636    }
1637    p_msg->p_filt_param_cback = p_cmpl_cback;
1638    p_msg->ref_value        = ref_value;
1639
1640    if (p_target) {
1641        p_msg->p_target = (tBLE_BD_ADDR *)(p_msg + 1);
1642        memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR));
1643    }
1644
1645    bta_sys_sendmsg(p_msg);
1646
1647#else
1648    UNUSED(action);
1649    UNUSED(filt_index);
1650    UNUSED(p_filt_params);
1651    UNUSED(p_target);
1652    UNUSED(p_cmpl_cback);
1653    UNUSED(ref_value);
1654#endif
1655}
1656
1657/*******************************************************************************
1658**
1659** Function         BTA_DmBleGetEnergyInfo
1660**
1661** Description      This function is called to obtain the energy info
1662**
1663** Parameters       p_cmpl_cback - Command complete callback
1664**
1665** Returns          void
1666**
1667*******************************************************************************/
1668void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback)
1669{
1670    const size_t len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
1671    tBTA_DM_API_ENERGY_INFO *p_msg = (tBTA_DM_API_ENERGY_INFO *)osi_calloc(len);
1672
1673    APPL_TRACE_API("%s", __func__);
1674
1675    p_msg->hdr.event = BTA_DM_API_BLE_ENERGY_INFO_EVT;
1676    p_msg->p_energy_info_cback = p_cmpl_cback;
1677
1678    bta_sys_sendmsg(p_msg);
1679}
1680
1681/*******************************************************************************
1682**
1683** Function         BTA_DmEnableScanFilter
1684**
1685** Description      This function is called to enable the adv data payload filter
1686**
1687** Parameters       action - enable or disable the APCF feature
1688**                  p_cmpl_cback - Command completed callback
1689**                  ref_value - Reference value
1690**
1691** Returns          void
1692**
1693*******************************************************************************/
1694void BTA_DmEnableScanFilter(uint8_t action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback,
1695                                    tBTA_DM_BLE_REF_VALUE ref_value)
1696{
1697#if (BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
1698    const size_t len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) +
1699        sizeof(tBLE_BD_ADDR);
1700    tBTA_DM_API_ENABLE_SCAN_FILTER *p_msg =
1701        (tBTA_DM_API_ENABLE_SCAN_FILTER *)osi_calloc(len);
1702
1703    APPL_TRACE_API("%s: %d", __func__, action);
1704
1705    p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_ENABLE_EVT;
1706    p_msg->action = action;
1707    p_msg->ref_value = ref_value;
1708    p_msg->p_filt_status_cback = p_cmpl_cback;
1709
1710    bta_sys_sendmsg(p_msg);
1711
1712#else
1713    UNUSED(action);
1714    UNUSED(p_cmpl_cback);
1715    UNUSED(ref_value);
1716#endif
1717}
1718
1719/*******************************************************************************
1720**
1721** Function         BTA_DmBleUpdateConnectionParams
1722**
1723** Description      Update connection parameters, can only be used when connection is up.
1724**
1725** Parameters:      bd_addr   - BD address of the peer
1726**                  min_int   -     minimum connection interval, [0x0004~ 0x4000]
1727**                  max_int   -     maximum connection interval, [0x0004~ 0x4000]
1728**                  latency   -     slave latency [0 ~ 500]
1729**                  timeout   -     supervision timeout [0x000a ~ 0xc80]
1730**
1731** Returns          void
1732**
1733*******************************************************************************/
1734void BTA_DmBleUpdateConnectionParams(const BD_ADDR bd_addr, uint16_t min_int, uint16_t max_int,
1735                                    uint16_t latency, uint16_t timeout)
1736{
1737    tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
1738        (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1739
1740    p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1741    bdcpy(p_msg->bd_addr, bd_addr);
1742    p_msg->min_int = min_int;
1743    p_msg->max_int = max_int;
1744    p_msg->latency = latency;
1745    p_msg->timeout = timeout;
1746
1747    bta_sys_sendmsg(p_msg);
1748}
1749
1750/*******************************************************************************
1751**
1752** Function         BTA_DmBleSetDataLength
1753**
1754** Description      This function is to set maximum LE data packet size
1755**
1756** Returns          void
1757**
1758**
1759*******************************************************************************/
1760void BTA_DmBleSetDataLength(BD_ADDR remote_device, uint16_t tx_data_length)
1761{
1762    tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg =
1763        (tBTA_DM_API_BLE_SET_DATA_LENGTH *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH));
1764
1765    bdcpy(p_msg->remote_bda, remote_device);
1766    p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
1767    p_msg->tx_data_length = tx_data_length;
1768
1769    bta_sys_sendmsg(p_msg);
1770}
1771
1772#endif
1773
1774/*******************************************************************************
1775**
1776** Function         BTA_DmSetEncryption
1777**
1778** Description      This function is called to ensure that connection is
1779**                  encrypted.  Should be called only on an open connection.
1780**                  Typically only needed for connections that first want to
1781**                  bring up unencrypted links, then later encrypt them.
1782**
1783** Parameters:      bd_addr       - Address of the peer device
1784**                  transport     - transport of the link to be encruypted
1785**                  p_callback    - Pointer to callback function to indicat the
1786**                                  link encryption status
1787**                  sec_act       - This is the security action to indicate
1788**                                  what knid of BLE security level is required for
1789**                                  the BLE link if the BLE is supported
1790**                                  Note: This parameter is ignored for the BR/EDR link
1791**                                        or the BLE is not supported
1792**
1793** Returns          void
1794**
1795*******************************************************************************/
1796void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCRYPT_CBACK *p_callback,
1797                            tBTA_DM_BLE_SEC_ACT sec_act)
1798{
1799    tBTA_DM_API_SET_ENCRYPTION *p_msg = (tBTA_DM_API_SET_ENCRYPTION *)osi_calloc(sizeof(tBTA_DM_API_SET_ENCRYPTION));
1800
1801    APPL_TRACE_API("%s", __func__);
1802
1803    p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
1804    memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
1805    p_msg->transport = transport;
1806    p_msg->p_callback = p_callback;
1807    p_msg->sec_act = sec_act;
1808
1809    bta_sys_sendmsg(p_msg);
1810}
1811
1812/*******************************************************************************
1813**
1814** Function         BTA_DmCloseACL
1815**
1816** Description      This function force to close an ACL connection and remove the
1817**                  device from the security database list of known devices.
1818**
1819** Parameters:      bd_addr       - Address of the peer device
1820**                  remove_dev    - remove device or not after link down
1821**
1822** Returns          void
1823**
1824*******************************************************************************/
1825void BTA_DmCloseACL(BD_ADDR bd_addr, bool remove_dev, tBTA_TRANSPORT transport)
1826{
1827    tBTA_DM_API_REMOVE_ACL *p_msg =
1828        (tBTA_DM_API_REMOVE_ACL *)osi_calloc(sizeof(tBTA_DM_API_REMOVE_ACL));
1829
1830    APPL_TRACE_API("%s", __func__);
1831
1832    p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
1833    memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
1834    p_msg->remove_dev = remove_dev;
1835    p_msg->transport = transport;
1836
1837    bta_sys_sendmsg(p_msg);
1838}
1839
1840#if (BLE_INCLUDED == TRUE)
1841/*******************************************************************************
1842**
1843** Function         BTA_DmBleObserve
1844**
1845** Description      This procedure keep the device listening for advertising
1846**                  events from a broadcast device.
1847**
1848** Parameters       start: start or stop observe.
1849**
1850** Returns          void
1851
1852**
1853** Returns          void.
1854**
1855*******************************************************************************/
1856extern void BTA_DmBleObserve(bool start, uint8_t duration,
1857                             tBTA_DM_SEARCH_CBACK *p_results_cb)
1858{
1859    tBTA_DM_API_BLE_OBSERVE *p_msg =
1860        (tBTA_DM_API_BLE_OBSERVE *)osi_calloc(sizeof(tBTA_DM_API_BLE_OBSERVE));
1861
1862    APPL_TRACE_API("%s:start = %d ", __func__, start);
1863
1864    p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
1865    p_msg->start = start;
1866    p_msg->duration = duration;
1867    p_msg->p_cback = p_results_cb;
1868
1869    bta_sys_sendmsg(p_msg);
1870}
1871
1872/*******************************************************************************
1873**
1874** Function         BTA_VendorInit
1875**
1876** Description      This function initializes vendor specific
1877**
1878** Returns          void
1879**
1880*******************************************************************************/
1881void BTA_VendorInit (void)
1882{
1883    APPL_TRACE_API("BTA_VendorInit");
1884}
1885
1886/*******************************************************************************
1887**
1888** Function         BTA_VendorCleanup
1889**
1890** Description      This function frees up Broadcom specific VS specific dynamic memory
1891**
1892** Returns          void
1893**
1894*******************************************************************************/
1895void BTA_VendorCleanup (void)
1896{
1897    tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
1898    BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
1899
1900#if (BLE_INCLUDED == TRUE && BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
1901    if (cmn_ble_vsc_cb.max_filter > 0)
1902    {
1903        btm_ble_adv_filter_cleanup();
1904#if (BLE_PRIVACY_SPT == TRUE)
1905        btm_ble_resolving_list_cleanup ();
1906#endif
1907    }
1908
1909    if (cmn_ble_vsc_cb.tot_scan_results_strg > 0)
1910        btm_ble_batchscan_cleanup();
1911#endif
1912
1913   if(cmn_ble_vsc_cb.adv_inst_max > 0)
1914      btm_ble_multi_adv_cleanup();
1915}
1916
1917#endif
1918