OSDN Git Service

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