OSDN Git Service

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