OSDN Git Service

resolve merge conflicts of 316589aa to nyc-mr2-dev
[android-x86/system-bt.git] / bta / dm / bta_dm_api.c
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_dm_int.h"
29 #include "bta_sys_int.h"
30 #include "btm_api.h"
31 #include "btm_int.h"
32 #include <string.h>
33 #include "utl.h"
34
35 /*****************************************************************************
36 **  Constants
37 *****************************************************************************/
38
39 static const tBTA_SYS_REG bta_dm_reg =
40 {
41     bta_dm_sm_execute,
42     bta_dm_sm_disable
43 };
44
45 static const tBTA_SYS_REG bta_dm_search_reg =
46 {
47     bta_dm_search_sm_execute,
48     bta_dm_search_sm_disable
49 };
50
51 /*******************************************************************************
52 **
53 ** Function         BTA_EnableBluetooth
54 **
55 ** Description      Enables bluetooth service.  This function must be
56 **                  called before any other functions in the BTA API are called.
57 **
58 **
59 ** Returns          tBTA_STATUS
60 **
61 *******************************************************************************/
62 tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
63 {
64     /* Bluetooth disabling is in progress */
65     if (bta_dm_cb.disabling)
66         return BTA_FAILURE;
67
68     bta_dm_init_cb();
69
70     bta_sys_register(BTA_ID_DM, &bta_dm_reg );
71     bta_sys_register(BTA_ID_DM_SEARCH, &bta_dm_search_reg );
72
73     /* if UUID list is not provided as static data */
74     bta_sys_eir_register(bta_dm_eir_update_uuid);
75
76     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;
80
81     bta_sys_sendmsg(p_msg);
82
83     return BTA_SUCCESS;
84 }
85
86 /*******************************************************************************
87 **
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 *******************************************************************************/
96 tBTA_STATUS BTA_DisableBluetooth(void)
97 {
98     BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
99
100     p_msg->event = BTA_DM_API_DISABLE_EVT;
101
102     bta_sys_sendmsg(p_msg);
103
104     return BTA_SUCCESS;
105 }
106
107 /*******************************************************************************
108 **
109 ** Function         BTA_EnableTestMode
110 **
111 ** Description      Enables bluetooth device under test mode
112 **
113 **
114 ** Returns          tBTA_STATUS
115 **
116 *******************************************************************************/
117 tBTA_STATUS BTA_EnableTestMode(void)
118 {
119     BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
120
121     APPL_TRACE_API("%s", __func__);
122
123     p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
124     bta_sys_sendmsg(p_msg);
125
126     return BTA_SUCCESS;
127 }
128
129 /*******************************************************************************
130 **
131 ** Function         BTA_DisableTestMode
132 **
133 ** Description      Disable bluetooth device under test mode
134 **
135 **
136 ** Returns          None
137 **
138 *******************************************************************************/
139 void BTA_DisableTestMode(void)
140 {
141     BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
142
143     APPL_TRACE_API("%s", __func__);
144
145     p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
146     bta_sys_sendmsg(p_msg);
147 }
148
149 /*******************************************************************************
150 **
151 ** Function         BTA_DmSetDeviceName
152 **
153 ** Description      This function sets the Bluetooth name of local device
154 **
155 **
156 ** Returns          void
157 **
158 *******************************************************************************/
159 void BTA_DmSetDeviceName(char *p_name)
160 {
161     tBTA_DM_API_SET_NAME *p_msg =
162         (tBTA_DM_API_SET_NAME *)osi_malloc(sizeof(tBTA_DM_API_SET_NAME));
163
164     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);
168 }
169
170 /*******************************************************************************
171 **
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 *******************************************************************************/
181 void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 pairable_mode, UINT8 conn_filter )
182 {
183     tBTA_DM_API_SET_VISIBILITY *p_msg =
184         (tBTA_DM_API_SET_VISIBILITY *)osi_malloc(sizeof(tBTA_DM_MSG));
185
186     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;
191
192     bta_sys_sendmsg(p_msg);
193 }
194
195 /*******************************************************************************
196 **
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 *******************************************************************************/
207 void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback)
208 {
209     tBTA_DM_API_SEARCH *p_msg =
210         (tBTA_DM_API_SEARCH *)osi_calloc(sizeof(tBTA_DM_API_SEARCH));
211
212     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;
217
218     bta_sys_sendmsg(p_msg);
219 }
220
221 /*******************************************************************************
222 **
223 ** Function         BTA_DmSearchCancel
224 **
225 ** Description      This function  cancels a search initiated by BTA_DmSearch
226 **
227 **
228 ** Returns          void
229 **
230 *******************************************************************************/
231 void BTA_DmSearchCancel(void)
232 {
233     BT_HDR *p_msg = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
234
235     p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
236     bta_sys_sendmsg(p_msg);
237 }
238
239 /*******************************************************************************
240 **
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 *******************************************************************************/
250 void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
251                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
252 {
253     tBTA_DM_API_DISCOVER *p_msg =
254         (tBTA_DM_API_DISCOVER *)osi_calloc(sizeof(tBTA_DM_API_DISCOVER));
255
256     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;
261
262     bta_sys_sendmsg(p_msg);
263 }
264
265 /*******************************************************************************
266 **
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 *******************************************************************************/
276 void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
277                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
278 {
279     tBTA_DM_API_DISCOVER *p_msg =
280         (tBTA_DM_API_DISCOVER *)osi_malloc(sizeof(tBTA_DM_API_DISCOVER));
281
282     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;
287
288 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
289     p_msg->num_uuid = 0;
290     p_msg->p_uuid = NULL;
291 #endif
292     memcpy(&p_msg->uuid, uuid, sizeof(tSDP_UUID) );
293
294     bta_sys_sendmsg(p_msg);
295 }
296
297 /*******************************************************************************
298 **
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 *******************************************************************************/
308 void BTA_DmBond(BD_ADDR bd_addr)
309 {
310     tBTA_DM_API_BOND *p_msg =
311         (tBTA_DM_API_BOND *)osi_malloc(sizeof(tBTA_DM_API_BOND));
312
313     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);
318 }
319
320 /*******************************************************************************
321 **
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 *******************************************************************************/
331 void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport)
332 {
333     tBTA_DM_API_BOND *p_msg =
334         (tBTA_DM_API_BOND *)osi_malloc(sizeof(tBTA_DM_API_BOND));
335
336     p_msg->hdr.event = BTA_DM_API_BOND_EVT;
337     bdcpy(p_msg->bd_addr, bd_addr);
338     p_msg->transport = transport;
339
340     bta_sys_sendmsg(p_msg);
341 }
342
343 /*******************************************************************************
344 **
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 *******************************************************************************/
354 void BTA_DmBondCancel(BD_ADDR bd_addr)
355 {
356     tBTA_DM_API_BOND_CANCEL *p_msg =
357         (tBTA_DM_API_BOND_CANCEL *)osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL));
358
359     p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
360     bdcpy(p_msg->bd_addr, bd_addr);
361
362     bta_sys_sendmsg(p_msg);
363 }
364
365 /*******************************************************************************
366 **
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 *******************************************************************************/
376 void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin)
377
378 {
379     tBTA_DM_API_PIN_REPLY *p_msg =
380         (tBTA_DM_API_PIN_REPLY *)osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY));
381
382     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);
388     }
389
390     bta_sys_sendmsg(p_msg);
391 }
392
393 /*******************************************************************************
394 **
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 *******************************************************************************/
406 void BTA_DmLocalOob(void)
407 {
408     tBTA_DM_API_LOC_OOB *p_msg =
409         (tBTA_DM_API_LOC_OOB *)osi_malloc(sizeof(tBTA_DM_API_LOC_OOB));
410
411     p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
412     bta_sys_sendmsg(p_msg);
413 }
414
415 /*******************************************************************************
416 **
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 *******************************************************************************/
425 void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept)
426 {
427     tBTA_DM_API_CONFIRM *p_msg =
428         (tBTA_DM_API_CONFIRM *)osi_malloc(sizeof(tBTA_DM_API_CONFIRM));
429
430     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);
435 }
436
437 /*******************************************************************************
438 **
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 *******************************************************************************/
448 void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
449                      tBTA_SERVICE_MASK trusted_mask, BOOLEAN is_trusted,
450                      UINT8 key_type, tBTA_IO_CAP io_cap, UINT8 pin_length)
451 {
452     tBTA_DM_API_ADD_DEVICE *p_msg =
453         (tBTA_DM_API_ADD_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_ADD_DEVICE));
454
455     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;
460
461     if (link_key) {
462         p_msg->link_key_known = TRUE;
463         p_msg->key_type = key_type;
464         memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
465     }
466
467     /* Load device class if specified */
468     if (dev_class) {
469         p_msg->dc_known = TRUE;
470         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 }
479
480 /*******************************************************************************
481 **
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 *******************************************************************************/
491 tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
492 {
493     tBTA_DM_API_REMOVE_DEVICE *p_msg =
494         (tBTA_DM_API_REMOVE_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_REMOVE_DEVICE));
495
496     p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
497     bdcpy(p_msg->bd_addr, bd_addr);
498
499     bta_sys_sendmsg(p_msg);
500
501     return BTA_SUCCESS;
502 }
503
504 /*******************************************************************************
505 **
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 *******************************************************************************/
516 extern const UINT16 bta_service_id_to_uuid_lkup_tbl [];
517 void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services )
518 {
519     UINT8 xx, yy;
520     UINT8 num_uuid, max_num_uuid = 32;
521     UINT8 uuid_list[32*LEN_UUID_16];
522     UINT16 *p_uuid16 = (UINT16 *)uuid_list;
523     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     }
549 }
550
551 /*******************************************************************************
552 **
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 *******************************************************************************/
560 UINT16 BTA_DmGetConnectionState( BD_ADDR bd_addr )
561 {
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 /*******************************************************************************
568 **                   Device Identification (DI) Server Functions
569 *******************************************************************************/
570 /*******************************************************************************
571 **
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 *******************************************************************************/
579 tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
580                               UINT32 *p_handle )
581 {
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 /*******************************************************************************
603 **
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 *******************************************************************************/
613 void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param)
614 {
615     tBTA_DM_API_EXECUTE_CBACK *p_msg =
616         (tBTA_DM_API_EXECUTE_CBACK *)osi_malloc(sizeof(tBTA_DM_MSG));
617
618     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);
623 }
624
625 /*******************************************************************************
626 **
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 *******************************************************************************/
641 void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_TYPE key_type)
642 {
643 #if BLE_INCLUDED == TRUE
644
645     tBTA_DM_API_ADD_BLEKEY *p_msg =
646         (tBTA_DM_API_ADD_BLEKEY *)osi_calloc(sizeof(tBTA_DM_API_ADD_BLEKEY));
647
648     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));
652
653     bta_sys_sendmsg(p_msg);
654 #endif
655 }
656
657 /*******************************************************************************
658 **
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 *******************************************************************************/
672 void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TYPE dev_type)
673 {
674 #if BLE_INCLUDED == TRUE
675     tBTA_DM_API_ADD_BLE_DEVICE *p_msg =
676         (tBTA_DM_API_ADD_BLE_DEVICE *)osi_calloc(sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
677
678     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;
682
683     bta_sys_sendmsg(p_msg);
684 #endif
685 }
686
687 /*******************************************************************************
688 **
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 *******************************************************************************/
701 void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey)
702 {
703 #if BLE_INCLUDED == TRUE
704     tBTA_DM_API_PASSKEY_REPLY *p_msg =
705         (tBTA_DM_API_PASSKEY_REPLY *)osi_calloc(sizeof(tBTA_DM_API_PASSKEY_REPLY));
706
707     p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
708     bdcpy(p_msg->bd_addr, bd_addr);
709     p_msg->accept = accept;
710
711     if (accept)
712         p_msg->passkey = passkey;
713
714     bta_sys_sendmsg(p_msg);
715 #endif
716 }
717
718 /*******************************************************************************
719 **
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 *******************************************************************************/
730 void BTA_DmBleConfirmReply(BD_ADDR bd_addr, BOOLEAN accept)
731 {
732 #if BLE_INCLUDED == TRUE
733     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);
741 #endif
742 }
743
744 /*******************************************************************************
745 **
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 *******************************************************************************/
756 void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
757 {
758 #if BLE_INCLUDED == TRUE
759     tBTA_DM_API_BLE_SEC_GRANT *p_msg =
760         (tBTA_DM_API_BLE_SEC_GRANT *)osi_calloc(sizeof(tBTA_DM_API_BLE_SEC_GRANT));
761
762     p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
763     bdcpy(p_msg->bd_addr, bd_addr);
764     p_msg->res = res;
765
766     bta_sys_sendmsg(p_msg);
767 #endif
768 }
769
770 /*******************************************************************************
771 **
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 *******************************************************************************/
789 void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,
790                                UINT16 min_conn_int, UINT16 max_conn_int,
791                                UINT16 slave_latency, UINT16 supervision_tout )
792 {
793 #if BLE_INCLUDED == TRUE
794     tBTA_DM_API_BLE_CONN_PARAMS *p_msg =
795         (tBTA_DM_API_BLE_CONN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
796
797     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;
803
804     bta_sys_sendmsg(p_msg);
805 #endif
806 }
807
808 /*******************************************************************************
809 **
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 *******************************************************************************/
821 void BTA_DmSetBleConnScanParams(UINT32 scan_interval, UINT32 scan_window)
822 {
823 #if BLE_INCLUDED == TRUE
824     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);
832 #endif  // BLE_INCLUDED == TRUE
833 }
834
835 /*******************************************************************************
836 **
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 *******************************************************************************/
850
851 #if BLE_INCLUDED == TRUE
852 void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval,
853                             UINT32 scan_window, tBLE_SCAN_MODE scan_mode,
854                             tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
855 {
856     tBTA_DM_API_BLE_SCAN_PARAMS *p_msg =
857         (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
858
859     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;
865
866     bta_sys_sendmsg(p_msg);
867 }
868 #endif  // BLE_INCLUDED == TRUE
869
870 /*******************************************************************************
871 **
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 *******************************************************************************/
882 void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
883                            tBLE_BD_ADDR *p_dir_bda)
884 {
885 #if BLE_INCLUDED == TRUE
886     tBTA_DM_API_BLE_ADV_PARAMS *p_msg =
887         (tBTA_DM_API_BLE_ADV_PARAMS *)osi_calloc(sizeof(tBTA_DM_API_BLE_ADV_PARAMS));
888
889     APPL_TRACE_API("BTA_DmSetBleAdvParam: %d, %d", adv_int_min, adv_int_max);
890
891     p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_EVT;
892     p_msg->adv_int_min = adv_int_min;
893     p_msg->adv_int_max = adv_int_max;
894
895     if (p_dir_bda != NULL) {
896         p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
897         memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
898     }
899
900     bta_sys_sendmsg(p_msg);
901 #endif
902 }
903
904 /*******************************************************************************
905 **                      BLE ADV data management API
906 ********************************************************************************/
907
908 #if BLE_INCLUDED == TRUE
909 /*******************************************************************************
910 **
911 ** Function         BTA_DmBleSetAdvConfig
912 **
913 ** Description      This function is called to override the BTA default ADV parameters.
914 **
915 ** Parameters       data_mask: adv data mask.
916 **                  p_adv_cfg: Pointer to User defined ADV data structure. This
917 **                             memory space can not be freed until p_adv_data_cback
918 **                             is received.
919 **                  p_adv_data_cback: set adv data complete callback.
920 **
921 ** Returns          None
922 **
923 *******************************************************************************/
924 void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
925                             tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
926 {
927   tBTA_DM_API_SET_ADV_CONFIG *p_msg = osi_calloc(sizeof(*p_msg));
928
929   p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_EVT;
930   p_msg->data_mask = data_mask;
931   p_msg->p_adv_data_cback = p_adv_data_cback;
932   memcpy(&p_msg->adv_cfg, p_adv_cfg, sizeof(p_msg->adv_cfg));
933
934   bta_sys_sendmsg(p_msg);
935 }
936
937 /*******************************************************************************
938 **
939 ** Function         BTA_DmBleSetScanRsp
940 **
941 ** Description      This function is called to override the BTA scan response.
942 **
943 ** Parameters       Pointer to User defined ADV data structure
944 **
945 ** Returns          None
946 **
947 *******************************************************************************/
948 extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
949                                  tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
950 {
951   tBTA_DM_API_SET_ADV_CONFIG *p_msg = osi_calloc(sizeof(*p_msg));
952
953   p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_EVT;
954   p_msg->data_mask = data_mask;
955   p_msg->p_adv_data_cback = p_adv_data_cback;
956   memcpy(&p_msg->adv_cfg, p_adv_cfg, sizeof(p_msg->adv_cfg));
957
958   bta_sys_sendmsg(p_msg);
959 }
960
961 /*******************************************************************************
962 **
963 ** Function         BTA_DmBleSetStorageParams
964 **
965 ** Description      This function is called to override the BTA scan response.
966 **
967 ** Parameters       batch_scan_full_max -Max storage space (in %) allocated to full scanning
968 **                  batch_scan_trunc_max -Max storage space (in %) allocated to truncated scanning
969 **                  batch_scan_notify_threshold -Setup notification level based on total space
970 **                  p_setup_cback - Setup callback pointer
971 **                  p_thres_cback - Threshold callback pointer
972 **                  p_rep_cback - Reports callback pointer
973 **                  ref_value - Ref value
974 **
975 ** Returns          None
976 **
977 *******************************************************************************/
978 extern void BTA_DmBleSetStorageParams(UINT8 batch_scan_full_max,
979                                          UINT8 batch_scan_trunc_max,
980                                          UINT8 batch_scan_notify_threshold,
981                                          tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback,
982                                          tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback,
983                                          tBTA_BLE_SCAN_REP_CBACK* p_rep_cback,
984                                          tBTA_DM_BLE_REF_VALUE ref_value)
985 {
986     tBTA_DM_API_SET_STORAGE_CONFIG *p_msg =
987         (tBTA_DM_API_SET_STORAGE_CONFIG *)osi_malloc(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG));
988
989     bta_dm_cb.p_setup_cback = p_setup_cback;
990
991     p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT;
992     p_msg->p_setup_cback=bta_ble_scan_setup_cb;
993     p_msg->p_thres_cback=p_thres_cback;
994     p_msg->p_read_rep_cback=p_rep_cback;
995     p_msg->ref_value = ref_value;
996     p_msg->batch_scan_full_max = batch_scan_full_max;
997     p_msg->batch_scan_trunc_max = batch_scan_trunc_max;
998     p_msg->batch_scan_notify_threshold = batch_scan_notify_threshold;
999
1000     bta_sys_sendmsg(p_msg);
1001 }
1002
1003 /*******************************************************************************
1004 **
1005 ** Function         BTA_DmBleEnableBatchScan
1006 **
1007 ** Description      This function is called to enable the batch scan
1008 **
1009 ** Parameters       scan_mode -Batch scan mode
1010 **                  scan_interval - Scan interval
1011 **                  scan_window - Scan window
1012 **                  discard_rule -Discard rules
1013 **                  addr_type - Address type
1014 **                  ref_value - Reference value
1015 **
1016 ** Returns          None
1017 **
1018 *******************************************************************************/
1019 extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode,
1020                                          UINT32 scan_interval, UINT32 scan_window,
1021                                          tBTA_BLE_DISCARD_RULE discard_rule,
1022                                          tBLE_ADDR_TYPE        addr_type,
1023                                          tBTA_DM_BLE_REF_VALUE ref_value)
1024 {
1025     tBTA_DM_API_ENABLE_SCAN *p_msg =
1026         (tBTA_DM_API_ENABLE_SCAN *)osi_malloc(sizeof(tBTA_DM_API_ENABLE_SCAN));
1027
1028     p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT;
1029     p_msg->scan_mode = scan_mode;
1030     p_msg->scan_int = scan_interval;
1031     p_msg->scan_window = scan_window;
1032     p_msg->discard_rule = discard_rule;
1033     p_msg->addr_type = addr_type;
1034     p_msg->ref_value = ref_value;
1035
1036     bta_sys_sendmsg(p_msg);
1037 }
1038
1039 /*******************************************************************************
1040 **
1041 ** Function         BTA_DmBleDisableBatchScan
1042 **
1043 ** Description      This function is called to disable the batch scan
1044 **
1045 ** Parameters       ref_value - Reference value
1046 **
1047 ** Returns          None
1048 **
1049 *******************************************************************************/
1050 extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)
1051 {
1052     tBTA_DM_API_DISABLE_SCAN *p_msg =
1053         (tBTA_DM_API_DISABLE_SCAN *)osi_malloc(sizeof(tBTA_DM_API_DISABLE_SCAN));
1054
1055     p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT;
1056     p_msg->ref_value = ref_value;
1057
1058     bta_sys_sendmsg(p_msg);
1059 }
1060
1061 /*******************************************************************************
1062 **
1063 ** Function         BTA_DmBleReadScanReports
1064 **
1065 ** Description      This function is called to read scan reports
1066 **
1067 ** Parameters       scan_type -Batch scan mode
1068 **                  ref_value - Reference value
1069 **
1070 ** Returns          None
1071 **
1072 *******************************************************************************/
1073 extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type,
1074                                              tBTA_DM_BLE_REF_VALUE ref_value)
1075 {
1076     tBTA_DM_API_READ_SCAN_REPORTS *p_msg =
1077         (tBTA_DM_API_READ_SCAN_REPORTS *)osi_malloc(sizeof(tBTA_DM_API_READ_SCAN_REPORTS));
1078
1079     p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT;
1080     p_msg->scan_type = scan_type;
1081     p_msg->ref_value = ref_value;
1082
1083     bta_sys_sendmsg(p_msg);
1084 }
1085
1086 /*******************************************************************************
1087 **
1088 ** Function         BTA_DmBleTrackAdvertiser
1089 **
1090 ** Description      This function is called to track advertiser
1091 **
1092 ** Parameters       ref_value - Reference value
1093 **                  p_track_adv_cback - Track ADV callback
1094 **
1095 ** Returns          None
1096 **
1097 *******************************************************************************/
1098 extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
1099                             tBTA_BLE_TRACK_ADV_CBACK *p_track_adv_cback)
1100 {
1101     tBTA_DM_API_TRACK_ADVERTISER *p_msg =
1102         (tBTA_DM_API_TRACK_ADVERTISER *)osi_malloc(sizeof(tBTA_DM_API_TRACK_ADVERTISER));
1103
1104     p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT;
1105     p_msg->p_track_adv_cback = p_track_adv_cback;
1106     p_msg->ref_value = ref_value;
1107
1108     bta_sys_sendmsg(p_msg);
1109 }
1110
1111 #endif
1112
1113 /*******************************************************************************
1114 **                      BLE ADV data management API
1115 ********************************************************************************/
1116 #if BLE_INCLUDED == TRUE
1117
1118 /*******************************************************************************
1119 **
1120 ** Function         BTA_DmBleBroadcast
1121 **
1122 ** Description      This function starts or stops LE broadcasting.
1123 **
1124 ** Parameters       start: start or stop broadcast.
1125 **
1126 ** Returns          None
1127 **
1128 *******************************************************************************/
1129 extern void BTA_DmBleBroadcast (BOOLEAN start)
1130 {
1131     tBTA_DM_API_BLE_OBSERVE *p_msg =
1132         (tBTA_DM_API_BLE_OBSERVE *)osi_calloc(sizeof(tBTA_DM_API_BLE_OBSERVE));
1133
1134     APPL_TRACE_API("BTA_DmBleBroadcast: start = %d ", start);
1135
1136     p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
1137     p_msg->start = start;
1138
1139     bta_sys_sendmsg(p_msg);
1140 }
1141
1142 #endif
1143 /*******************************************************************************
1144 **
1145 ** Function         BTA_DmBleSetBgConnType
1146 **
1147 ** Description      This function is called to set BLE connectable mode for a
1148 **                  peripheral device.
1149 **
1150 ** Parameters       bg_conn_type: it can be auto connection, or selective connection.
1151 **                  p_select_cback: callback function when selective connection procedure
1152 **                              is being used.
1153 **
1154 ** Returns          void
1155 **
1156 *******************************************************************************/
1157 void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback)
1158 {
1159 #if BLE_INCLUDED == TRUE
1160     tBTA_DM_API_BLE_SET_BG_CONN_TYPE *p_msg =
1161         (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *)osi_calloc(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
1162
1163     p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
1164     p_msg->bg_conn_type = bg_conn_type;
1165     p_msg->p_select_cback = p_select_cback;
1166
1167     bta_sys_sendmsg(p_msg);
1168 #endif
1169 }
1170
1171 /*******************************************************************************
1172 **
1173 ** Function         bta_dm_discover_send_msg
1174 **
1175 ** Description      This function send discover message to BTA task.
1176 **
1177 ** Returns          void
1178 **
1179 *******************************************************************************/
1180 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1181 static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1182                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
1183                     tBTA_TRANSPORT transport)
1184 {
1185     const size_t len = p_services ?
1186         (sizeof(tBTA_DM_API_DISCOVER) + sizeof(tBT_UUID) * p_services->num_uuid)
1187         : sizeof(tBTA_DM_API_DISCOVER);
1188     tBTA_DM_API_DISCOVER *p_msg = (tBTA_DM_API_DISCOVER *)osi_calloc(len);
1189
1190     p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
1191     bdcpy(p_msg->bd_addr, bd_addr);
1192     p_msg->p_cback = p_cback;
1193     p_msg->sdp_search = sdp_search;
1194     p_msg->transport    = transport;
1195
1196     if (p_services != NULL) {
1197 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1198         p_msg->services = p_services->srvc_mask;
1199         p_msg->num_uuid = p_services->num_uuid;
1200         if (p_services->num_uuid != 0) {
1201             p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1202             memcpy(p_msg->p_uuid, p_services->p_uuid,
1203                    sizeof(tBT_UUID) * p_services->num_uuid);
1204         }
1205 #endif
1206     }
1207
1208     bta_sys_sendmsg(p_msg);
1209 }
1210 #endif
1211
1212 /*******************************************************************************
1213 **
1214 ** Function         BTA_DmDiscoverByTransport
1215 **
1216 ** Description      This function does service discovery on particular transport
1217 **                  for services of a
1218 **                  peer device. When services.num_uuid is 0, it indicates all
1219 **                  GATT based services are to be searched; otherwise a list of
1220 **                  UUID of interested services should be provided through
1221 **                  p_services->p_uuid.
1222 **
1223 **
1224 **
1225 ** Returns          void
1226 **
1227 *******************************************************************************/
1228 void BTA_DmDiscoverByTransport(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1229                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
1230                     tBTA_TRANSPORT transport)
1231 {
1232 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1233     bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
1234 #endif
1235 }
1236
1237
1238 /*******************************************************************************
1239 **
1240 ** Function         BTA_DmDiscoverExt
1241 **
1242 ** Description      This function does service discovery for services of a
1243 **                  peer device. When services.num_uuid is 0, it indicates all
1244 **                  GATT based services are to be searched; other wise a list of
1245 **                  UUID of interested services should be provided through
1246 **                  p_services->p_uuid.
1247 **
1248 **
1249 **
1250 ** Returns          void
1251 **
1252 *******************************************************************************/
1253 void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1254                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
1255 {
1256 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1257     bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, BTA_TRANSPORT_UNKNOWN);
1258 #endif
1259
1260 }
1261
1262 /*******************************************************************************
1263 **
1264 ** Function         BTA_DmSearchExt
1265 **
1266 ** Description      This function searches for peer Bluetooth devices. It performs
1267 **                  an inquiry and gets the remote name for devices. Service
1268 **                  discovery is done if services is non zero
1269 **
1270 ** Parameters       p_dm_inq: inquiry conditions
1271 **                  p_services: if service is not empty, service discovery will be done.
1272 **                            for all GATT based service condition, put num_uuid, and
1273 **                            p_uuid is the pointer to the list of UUID values.
1274 **                  p_cback: callback functino when search is completed.
1275 **
1276 **
1277 **
1278 ** Returns          void
1279 **
1280 *******************************************************************************/
1281 void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback)
1282 {
1283 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1284     const size_t len = p_services ?
1285         (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid)
1286         : sizeof(tBTA_DM_API_SEARCH);
1287     tBTA_DM_API_SEARCH *p_msg = (tBTA_DM_API_SEARCH *)osi_calloc(len);
1288
1289     p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
1290     memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
1291     p_msg->p_cback = p_cback;
1292     p_msg->rs_res  = BTA_DM_RS_NONE;
1293
1294     if (p_services != NULL) {
1295         p_msg->services = p_services->srvc_mask;
1296         p_msg->num_uuid = p_services->num_uuid;
1297
1298         if (p_services->num_uuid != 0) {
1299             p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1300             memcpy(p_msg->p_uuid, p_services->p_uuid,
1301                    sizeof(tBT_UUID) * p_services->num_uuid);
1302         } else {
1303             p_msg->p_uuid = NULL;
1304         }
1305     }
1306
1307     bta_sys_sendmsg(p_msg);
1308 #else
1309     UNUSED(p_dm_inq);
1310     UNUSED(p_services);
1311     UNUSED(p_cback);
1312 #endif
1313 }
1314 /*******************************************************************************
1315 **
1316 ** Function         BTA_DmBleUpdateConnectionParam
1317 **
1318 ** Description      Update connection parameters, can only be used when connection is up.
1319 **
1320 ** Parameters:      bd_addr          - BD address of the peer
1321 **                  min_int   -     minimum connection interval, [0x0004~ 0x4000]
1322 **                  max_int   -     maximum connection interval, [0x0004~ 0x4000]
1323 **                  latency   -     slave latency [0 ~ 500]
1324 **                  timeout   -     supervision timeout [0x000a ~ 0xc80]
1325 **
1326 ** Returns          void
1327 **
1328 *******************************************************************************/
1329 void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
1330                                     UINT16 max_int, UINT16 latency,
1331                                     UINT16 timeout)
1332 {
1333 #if BLE_INCLUDED == TRUE
1334     tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
1335         (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1336
1337     p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1338     bdcpy(p_msg->bd_addr, bd_addr);
1339     p_msg->min_int = min_int;
1340     p_msg->max_int = max_int;
1341     p_msg->latency = latency;
1342     p_msg->timeout = timeout;
1343
1344     bta_sys_sendmsg(p_msg);
1345 #endif
1346 }
1347
1348 /*******************************************************************************
1349 **
1350 ** Function         BTA_DmBleConfigLocalPrivacy
1351 **
1352 ** Description      Enable/disable privacy on the local device
1353 **
1354 ** Parameters:      privacy_enable   - enable/disabe privacy on remote device.
1355 **
1356 ** Returns          void
1357 **
1358 *******************************************************************************/
1359 void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable)
1360 {
1361 #if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE
1362     tBTA_DM_API_LOCAL_PRIVACY *p_msg =
1363         (tBTA_DM_API_LOCAL_PRIVACY *)osi_calloc(sizeof(tBTA_DM_API_ENABLE_PRIVACY));
1364
1365     p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
1366     p_msg->privacy_enable   = privacy_enable;
1367
1368     bta_sys_sendmsg(p_msg);
1369 #else
1370     UNUSED (privacy_enable);
1371 #endif
1372 }
1373
1374 #if BLE_INCLUDED == TRUE
1375 /*******************************************************************************
1376 **
1377 ** Function         BTA_BleEnableAdvInstance
1378 **
1379 ** Description      This function enable a Multi-ADV instance with the specififed
1380 **                  adv parameters
1381 **
1382 ** Parameters       p_params: pointer to the adv parameter structure.
1383 **                  p_cback: callback function associated to this adv instance.
1384 **                  p_ref: reference data pointer to this adv instance.
1385 **
1386 ** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
1387 **
1388 *******************************************************************************/
1389 void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
1390                                 tBTA_BLE_MULTI_ADV_CBACK *p_cback,
1391                                 void *p_ref)
1392 {
1393     const size_t len = sizeof(tBTA_BLE_ADV_PARAMS) +
1394         sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB);
1395     tBTA_DM_API_BLE_MULTI_ADV_ENB *p_msg =
1396         (tBTA_DM_API_BLE_MULTI_ADV_ENB *)osi_calloc(len);
1397
1398     APPL_TRACE_API("%s", __func__);
1399
1400     p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_ENB_EVT;
1401     p_msg->p_cback = (void *)p_cback;
1402     if (p_params != NULL) {
1403         p_msg->p_params = (void *)(p_msg + 1);
1404         memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
1405     }
1406     p_msg->p_ref = p_ref;
1407
1408     bta_sys_sendmsg(p_msg);
1409 }
1410
1411 /*******************************************************************************
1412 **
1413 ** Function         BTA_BleUpdateAdvInstParam
1414 **
1415 ** Description      This function update a Multi-ADV instance with the specififed
1416 **                  adv parameters.
1417 **
1418 ** Parameters       inst_id: Adv instance to update the parameter.
1419 **                  p_params: pointer to the adv parameter structure.
1420 **
1421 ** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
1422 **
1423 *******************************************************************************/
1424 void BTA_BleUpdateAdvInstParam (UINT8 inst_id, tBTA_BLE_ADV_PARAMS *p_params)
1425 {
1426     const size_t len = sizeof(tBTA_BLE_ADV_PARAMS) +
1427         sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM);
1428     tBTA_DM_API_BLE_MULTI_ADV_PARAM *p_msg =
1429         (tBTA_DM_API_BLE_MULTI_ADV_PARAM *)osi_calloc(len);
1430
1431     APPL_TRACE_API("%s", __func__);
1432
1433     p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT;
1434     p_msg->inst_id = inst_id;
1435     p_msg->p_params = (void *)(p_msg + 1);
1436     memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
1437
1438     bta_sys_sendmsg(p_msg);
1439 }
1440
1441 /*******************************************************************************
1442 **
1443 ** Function         BTA_BleCfgAdvInstData
1444 **
1445 ** Description      This function configure a Multi-ADV instance with the specififed
1446 **                  adv data or scan response data.
1447 **
1448 ** Parameter        inst_id: Adv instance to configure the adv data or scan response.
1449 **                  is_scan_rsp: is the data scan response or adv data.
1450 **                  data_mask: adv data type as bit mask.
1451 **                  p_data: pointer to the ADV data structure tBTA_BLE_ADV_DATA. This
1452 **                  memory space can not be freed until BTA_BLE_MULTI_ADV_DATA_EVT
1453 **                  is sent to application.
1454 **
1455 ** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
1456 **
1457 *******************************************************************************/
1458 void BTA_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp,
1459                             tBTA_BLE_AD_MASK data_mask,
1460                             tBTA_BLE_ADV_DATA *p_data)
1461 {
1462   tBTA_DM_API_BLE_MULTI_ADV_DATA *p_msg = osi_calloc(sizeof(*p_msg));
1463
1464   p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_DATA_EVT;
1465   p_msg->inst_id = inst_id;
1466   p_msg->is_scan_rsp = is_scan_rsp;
1467   p_msg->data_mask = data_mask;
1468   memcpy(&p_msg->data, p_data, sizeof(p_msg->data));
1469
1470   bta_sys_sendmsg(p_msg);
1471 }
1472
1473 /*******************************************************************************
1474 **
1475 ** Function         BTA_BleDisableAdvInstance
1476 **
1477 ** Description      This function disable a Multi-ADV instance.
1478 **
1479 ** Parameter        inst_id: instance ID to disable.
1480 **
1481 ** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
1482 **
1483 *******************************************************************************/
1484 void BTA_BleDisableAdvInstance(UINT8 inst_id)
1485 {
1486     tBTA_DM_API_BLE_MULTI_ADV_DISABLE *p_msg =
1487         (tBTA_DM_API_BLE_MULTI_ADV_DISABLE *)osi_calloc(sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE));
1488
1489     APPL_TRACE_API("%s: %d", __func__, inst_id);
1490
1491     p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT;
1492     p_msg->inst_id = inst_id;
1493
1494     bta_sys_sendmsg(p_msg);
1495 }
1496
1497 /*******************************************************************************
1498 **
1499 ** Function         BTA_DmBleCfgFilterCondition
1500 **
1501 ** Description      This function is called to configure the adv data payload filter
1502 **                  condition.
1503 **
1504 ** Parameters       action: to read/write/clear
1505 **                  cond_type: filter condition type
1506 **                  filt_index - Filter index
1507 **                  p_cond: filter condition parameter
1508 **                  p_cmpl_back - Command completed callback
1509 **                  ref_value - Reference value
1510 **
1511 ** Returns          void
1512 **
1513 *******************************************************************************/
1514 void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
1515                                  tBTA_DM_BLE_PF_COND_TYPE cond_type,
1516                                  tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1517                                  tBTA_DM_BLE_PF_COND_PARAM *p_cond,
1518                                  tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback,
1519                                  tBTA_DM_BLE_REF_VALUE ref_value)
1520 {
1521 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
1522     tBTA_DM_API_CFG_FILTER_COND *p_msg;
1523     APPL_TRACE_API ("BTA_DmBleCfgFilterCondition: %d, %d", action, cond_type);
1524
1525     UINT16  len = sizeof(tBTA_DM_API_CFG_FILTER_COND) +
1526                   sizeof(tBTA_DM_BLE_PF_COND_PARAM);
1527     UINT8 *p;
1528
1529     if (NULL != p_cond)
1530     {
1531         switch(cond_type)
1532         {
1533             case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:
1534             case BTA_DM_BLE_PF_MANU_DATA:
1535                 /* Length of pattern and pattern mask and other elements in */
1536                 /* tBTA_DM_BLE_PF_MANU_COND */
1537                 len += ((p_cond->manu_data.data_len) * 2) +
1538                         sizeof(UINT16) + sizeof(UINT16) + sizeof(UINT8);
1539                 break;
1540
1541             case BTA_DM_BLE_PF_LOCAL_NAME:
1542                 len += ((p_cond->local_name.data_len) + sizeof(UINT8));
1543                 break;
1544
1545             case BTM_BLE_PF_SRVC_UUID:
1546             case BTM_BLE_PF_SRVC_SOL_UUID:
1547                 len += sizeof(tBLE_BD_ADDR) + sizeof(tBTA_DM_BLE_PF_COND_MASK);
1548                 break;
1549
1550             default:
1551                 break;
1552         }
1553     }
1554
1555     p_msg = (tBTA_DM_API_CFG_FILTER_COND *)osi_calloc(len);
1556     p_msg->hdr.event = BTA_DM_API_CFG_FILTER_COND_EVT;
1557     p_msg->action = action;
1558     p_msg->cond_type = cond_type;
1559     p_msg->filt_index = filt_index;
1560     p_msg->p_filt_cfg_cback = p_cmpl_cback;
1561     p_msg->ref_value = ref_value;
1562     if (p_cond) {
1563         p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM *)(p_msg + 1);
1564         memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
1565
1566         p = (UINT8 *)(p_msg->p_cond_param + 1);
1567
1568         if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN ||
1569             cond_type == BTA_DM_BLE_PF_MANU_DATA) {
1570             p_msg->p_cond_param->manu_data.p_pattern = p;
1571             p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len;
1572             memcpy(p_msg->p_cond_param->manu_data.p_pattern, p_cond->manu_data.p_pattern,
1573                    p_cond->manu_data.data_len);
1574             p += p_cond->manu_data.data_len;
1575
1576             if (cond_type == BTA_DM_BLE_PF_MANU_DATA) {
1577                 p_msg->p_cond_param->manu_data.company_id_mask =
1578                     p_cond->manu_data.company_id_mask;
1579                 if ( p_cond->manu_data.p_pattern_mask != NULL) {
1580                     p_msg->p_cond_param->manu_data.p_pattern_mask = p;
1581                     memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask,
1582                            p_cond->manu_data.p_pattern_mask,
1583                            p_cond->manu_data.data_len);
1584                 }
1585             }
1586         } else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME) {
1587             p_msg->p_cond_param->local_name.p_data = p;
1588             p_msg->p_cond_param->local_name.data_len =
1589                 p_cond->local_name.data_len;
1590             memcpy(p_msg->p_cond_param->local_name.p_data,
1591                    p_cond->local_name.p_data, p_cond->local_name.data_len);
1592         } else if (cond_type == BTM_BLE_PF_SRVC_UUID ||
1593                    cond_type == BTM_BLE_PF_SRVC_SOL_UUID) {
1594             if (p_cond->srvc_uuid.p_target_addr != NULL) {
1595                 p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR *)(p);
1596                 p_msg->p_cond_param->srvc_uuid.p_target_addr->type =
1597                     p_cond->srvc_uuid.p_target_addr->type;
1598                 memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda,
1599                        p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN);
1600                 p = (UINT8 *)(p_msg->p_cond_param->srvc_uuid.p_target_addr + 1);
1601             }
1602             if (p_cond->srvc_uuid.p_uuid_mask) {
1603                 p_msg->p_cond_param->srvc_uuid.p_uuid_mask = (tBTA_DM_BLE_PF_COND_MASK *)p;
1604                 memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask,
1605                        p_cond->srvc_uuid.p_uuid_mask,
1606                        sizeof(tBTA_DM_BLE_PF_COND_MASK));
1607             }
1608         }
1609     }
1610
1611     bta_sys_sendmsg(p_msg);
1612
1613 #else
1614     UNUSED(action);
1615     UNUSED(cond_type);
1616     UNUSED(filt_index);
1617     UNUSED(p_cond);
1618     UNUSED(p_cmpl_cback);
1619     UNUSED(ref_value);
1620 #endif
1621 }
1622
1623 /*******************************************************************************
1624 **
1625 ** Function         BTA_DmBleScanFilterSetup
1626 **
1627 ** Description      This function is called to setup the adv data payload filter param
1628 **
1629 ** Parameters       p_target: enable the filter condition on a target device; if NULL
1630 **                  filt_index - Filter index
1631 **                  p_filt_params -Filter parameters
1632 **                  ref_value - Reference value
1633 **                  action - Add, delete or clear
1634 **                  p_cmpl_back - Command completed callback
1635 **
1636 ** Returns          void
1637 **
1638 *******************************************************************************/
1639 void BTA_DmBleScanFilterSetup(UINT8 action,
1640                               tBTA_DM_BLE_PF_FILT_INDEX filt_index,
1641                               tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params,
1642                               tBLE_BD_ADDR *p_target,
1643                               tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback,
1644                               tBTA_DM_BLE_REF_VALUE ref_value)
1645 {
1646 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
1647     const size_t len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) +
1648         sizeof(tBLE_BD_ADDR);
1649     tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *p_msg =
1650         (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *)osi_calloc(len);
1651
1652     APPL_TRACE_API("%s: %d", __func__, action);
1653
1654     p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_SETUP_EVT;
1655     p_msg->action = action;
1656     p_msg->filt_index = filt_index;
1657     if (p_filt_params) {
1658         memcpy(&p_msg->filt_params, p_filt_params,
1659                sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1660     }
1661     p_msg->p_filt_param_cback = p_cmpl_cback;
1662     p_msg->ref_value        = ref_value;
1663
1664     if (p_target) {
1665         p_msg->p_target = (tBLE_BD_ADDR *)(p_msg + 1);
1666         memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR));
1667     }
1668
1669     bta_sys_sendmsg(p_msg);
1670
1671 #else
1672     UNUSED(action);
1673     UNUSED(filt_index);
1674     UNUSED(p_filt_params);
1675     UNUSED(p_target);
1676     UNUSED(p_cmpl_cback);
1677     UNUSED(ref_value);
1678 #endif
1679 }
1680
1681 /*******************************************************************************
1682 **
1683 ** Function         BTA_DmBleGetEnergyInfo
1684 **
1685 ** Description      This function is called to obtain the energy info
1686 **
1687 ** Parameters       p_cmpl_cback - Command complete callback
1688 **
1689 ** Returns          void
1690 **
1691 *******************************************************************************/
1692 void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback)
1693 {
1694     const size_t len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
1695     tBTA_DM_API_ENERGY_INFO *p_msg = (tBTA_DM_API_ENERGY_INFO *)osi_calloc(len);
1696
1697     APPL_TRACE_API("%s", __func__);
1698
1699     p_msg->hdr.event = BTA_DM_API_BLE_ENERGY_INFO_EVT;
1700     p_msg->p_energy_info_cback = p_cmpl_cback;
1701
1702     bta_sys_sendmsg(p_msg);
1703 }
1704
1705 /*******************************************************************************
1706 **
1707 ** Function         BTA_DmEnableScanFilter
1708 **
1709 ** Description      This function is called to enable the adv data payload filter
1710 **
1711 ** Parameters       action - enable or disable the APCF feature
1712 **                  p_cmpl_cback - Command completed callback
1713 **                  ref_value - Reference value
1714 **
1715 ** Returns          void
1716 **
1717 *******************************************************************************/
1718 void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback,
1719                                     tBTA_DM_BLE_REF_VALUE ref_value)
1720 {
1721 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
1722     const size_t len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) +
1723         sizeof(tBLE_BD_ADDR);
1724     tBTA_DM_API_ENABLE_SCAN_FILTER *p_msg =
1725         (tBTA_DM_API_ENABLE_SCAN_FILTER *)osi_calloc(len);
1726
1727     APPL_TRACE_API("%s: %d", __func__, action);
1728
1729     p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_ENABLE_EVT;
1730     p_msg->action = action;
1731     p_msg->ref_value = ref_value;
1732     p_msg->p_filt_status_cback = p_cmpl_cback;
1733
1734     bta_sys_sendmsg(p_msg);
1735
1736 #else
1737     UNUSED(action);
1738     UNUSED(p_cmpl_cback);
1739     UNUSED(ref_value);
1740 #endif
1741 }
1742
1743 /*******************************************************************************
1744 **
1745 ** Function         BTA_DmBleUpdateConnectionParams
1746 **
1747 ** Description      Update connection parameters, can only be used when connection is up.
1748 **
1749 ** Parameters:      bd_addr   - BD address of the peer
1750 **                  min_int   -     minimum connection interval, [0x0004~ 0x4000]
1751 **                  max_int   -     maximum connection interval, [0x0004~ 0x4000]
1752 **                  latency   -     slave latency [0 ~ 500]
1753 **                  timeout   -     supervision timeout [0x000a ~ 0xc80]
1754 **
1755 ** Returns          void
1756 **
1757 *******************************************************************************/
1758 void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max_int,
1759                                     UINT16 latency, UINT16 timeout)
1760 {
1761     tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
1762         (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1763
1764     p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1765     bdcpy(p_msg->bd_addr, bd_addr);
1766     p_msg->min_int = min_int;
1767     p_msg->max_int = max_int;
1768     p_msg->latency = latency;
1769     p_msg->timeout = timeout;
1770
1771     bta_sys_sendmsg(p_msg);
1772 }
1773
1774 /*******************************************************************************
1775 **
1776 ** Function         BTA_DmBleSetDataLength
1777 **
1778 ** Description      This function is to set maximum LE data packet size
1779 **
1780 ** Returns          void
1781 **
1782 **
1783 *******************************************************************************/
1784 void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length)
1785 {
1786     tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg =
1787         (tBTA_DM_API_BLE_SET_DATA_LENGTH *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH));
1788
1789     bdcpy(p_msg->remote_bda, remote_device);
1790     p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
1791     p_msg->tx_data_length = tx_data_length;
1792
1793     bta_sys_sendmsg(p_msg);
1794 }
1795
1796 #endif
1797
1798 /*******************************************************************************
1799 **
1800 ** Function         BTA_DmSetEncryption
1801 **
1802 ** Description      This function is called to ensure that connection is
1803 **                  encrypted.  Should be called only on an open connection.
1804 **                  Typically only needed for connections that first want to
1805 **                  bring up unencrypted links, then later encrypt them.
1806 **
1807 ** Parameters:      bd_addr       - Address of the peer device
1808 **                  transport     - transport of the link to be encruypted
1809 **                  p_callback    - Pointer to callback function to indicat the
1810 **                                  link encryption status
1811 **                  sec_act       - This is the security action to indicate
1812 **                                  what knid of BLE security level is required for
1813 **                                  the BLE link if the BLE is supported
1814 **                                  Note: This parameter is ignored for the BR/EDR link
1815 **                                        or the BLE is not supported
1816 **
1817 ** Returns          void
1818 **
1819 *******************************************************************************/
1820 void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCRYPT_CBACK *p_callback,
1821                             tBTA_DM_BLE_SEC_ACT sec_act)
1822 {
1823     tBTA_DM_API_SET_ENCRYPTION *p_msg = (tBTA_DM_API_SET_ENCRYPTION *)osi_calloc(sizeof(tBTA_DM_API_SET_ENCRYPTION));
1824
1825     APPL_TRACE_API("%s", __func__);
1826
1827     p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
1828     memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
1829     p_msg->transport = transport;
1830     p_msg->p_callback = p_callback;
1831     p_msg->sec_act = sec_act;
1832
1833     bta_sys_sendmsg(p_msg);
1834 }
1835
1836 /*******************************************************************************
1837 **
1838 ** Function         BTA_DmCloseACL
1839 **
1840 ** Description      This function force to close an ACL connection and remove the
1841 **                  device from the security database list of known devices.
1842 **
1843 ** Parameters:      bd_addr       - Address of the peer device
1844 **                  remove_dev    - remove device or not after link down
1845 **
1846 ** Returns          void
1847 **
1848 *******************************************************************************/
1849 void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT transport)
1850 {
1851     tBTA_DM_API_REMOVE_ACL *p_msg =
1852         (tBTA_DM_API_REMOVE_ACL *)osi_calloc(sizeof(tBTA_DM_API_REMOVE_ACL));
1853
1854     APPL_TRACE_API("%s", __func__);
1855
1856     p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
1857     memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
1858     p_msg->remove_dev = remove_dev;
1859     p_msg->transport = transport;
1860
1861     bta_sys_sendmsg(p_msg);
1862 }
1863
1864 #if BLE_INCLUDED == TRUE
1865 /*******************************************************************************
1866 **
1867 ** Function         BTA_DmBleObserve
1868 **
1869 ** Description      This procedure keep the device listening for advertising
1870 **                  events from a broadcast device.
1871 **
1872 ** Parameters       start: start or stop observe.
1873 **
1874 ** Returns          void
1875
1876 **
1877 ** Returns          void.
1878 **
1879 *******************************************************************************/
1880 extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
1881                              tBTA_DM_SEARCH_CBACK *p_results_cb)
1882 {
1883     tBTA_DM_API_BLE_OBSERVE *p_msg =
1884         (tBTA_DM_API_BLE_OBSERVE *)osi_calloc(sizeof(tBTA_DM_API_BLE_OBSERVE));
1885
1886     APPL_TRACE_API("%s:start = %d ", __func__, start);
1887
1888     p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
1889     p_msg->start = start;
1890     p_msg->duration = duration;
1891     p_msg->p_cback = p_results_cb;
1892
1893     bta_sys_sendmsg(p_msg);
1894 }
1895
1896 /*******************************************************************************
1897 **
1898 ** Function         BTA_VendorInit
1899 **
1900 ** Description      This function initializes vendor specific
1901 **
1902 ** Returns          void
1903 **
1904 *******************************************************************************/
1905 void BTA_VendorInit (void)
1906 {
1907     APPL_TRACE_API("BTA_VendorInit");
1908 }
1909
1910 /*******************************************************************************
1911 **
1912 ** Function         BTA_VendorCleanup
1913 **
1914 ** Description      This function frees up Broadcom specific VS specific dynamic memory
1915 **
1916 ** Returns          void
1917 **
1918 *******************************************************************************/
1919 void BTA_VendorCleanup (void)
1920 {
1921     tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
1922     BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
1923
1924 #if (BLE_INCLUDED == TRUE && BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
1925     if (cmn_ble_vsc_cb.max_filter > 0)
1926     {
1927         btm_ble_adv_filter_cleanup();
1928 #if BLE_PRIVACY_SPT == TRUE
1929         btm_ble_resolving_list_cleanup ();
1930 #endif
1931     }
1932
1933     if (cmn_ble_vsc_cb.tot_scan_results_strg > 0)
1934         btm_ble_batchscan_cleanup();
1935 #endif
1936
1937    if(cmn_ble_vsc_cb.adv_inst_max > 0)
1938       btm_ble_multi_adv_cleanup();
1939 }
1940
1941 #endif