• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "bd.h"
27 #include "bta_sys.h"
28 #include "bta_api.h"
29 #include "bta_dm_int.h"
30 #include "bta_sys_int.h"
31 #include "btm_api.h"
32 #include "btm_int.h"
33 #include <string.h>
34 #include "utl.h"
35 #include "vendor_ble.h"
36 
37 /*****************************************************************************
38 **  Constants
39 *****************************************************************************/
40 
41 static const tBTA_SYS_REG bta_dm_reg =
42 {
43     bta_dm_sm_execute,
44     bta_dm_sm_disable
45 };
46 
47 static const tBTA_SYS_REG bta_dm_search_reg =
48 {
49     bta_dm_search_sm_execute,
50     bta_dm_search_sm_disable
51 };
52 
53 /*******************************************************************************
54 **
55 ** Function         BTA_EnableBluetooth
56 **
57 ** Description      Enables bluetooth service.  This function must be
58 **                  called before any other functions in the BTA API are called.
59 **
60 **
61 ** Returns          tBTA_STATUS
62 **
63 *******************************************************************************/
BTA_EnableBluetooth(tBTA_DM_SEC_CBACK * p_cback)64 tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
65 {
66 
67     tBTA_DM_API_ENABLE    *p_msg;
68 
69     /* Bluetooth disabling is in progress */
70     if (bta_dm_cb.disabling)
71         return BTA_FAILURE;
72 
73     memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
74 
75     bta_sys_register (BTA_ID_DM, &bta_dm_reg );
76     bta_sys_register (BTA_ID_DM_SEARCH, &bta_dm_search_reg );
77 
78     /* if UUID list is not provided as static data */
79     bta_sys_eir_register(bta_dm_eir_update_uuid);
80 
81     if ((p_msg = (tBTA_DM_API_ENABLE *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE))) != NULL)
82     {
83         p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
84         p_msg->p_sec_cback = p_cback;
85         bta_sys_sendmsg(p_msg);
86         return BTA_SUCCESS;
87     }
88     return BTA_FAILURE;
89 
90 }
91 
92 /*******************************************************************************
93 **
94 ** Function         BTA_DisableBluetooth
95 **
96 ** Description      Disables bluetooth service.  This function is called when
97 **                  the application no longer needs bluetooth service
98 **
99 ** Returns          void
100 **
101 *******************************************************************************/
BTA_DisableBluetooth(void)102 tBTA_STATUS BTA_DisableBluetooth(void)
103 {
104 
105     BT_HDR    *p_msg;
106 
107     if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
108     {
109         p_msg->event = BTA_DM_API_DISABLE_EVT;
110         bta_sys_sendmsg(p_msg);
111     }
112     else
113     {
114         return BTA_FAILURE;
115     }
116 
117     return BTA_SUCCESS;
118 }
119 
120 /*******************************************************************************
121 **
122 ** Function         BTA_EnableTestMode
123 **
124 ** Description      Enables bluetooth device under test mode
125 **
126 **
127 ** Returns          tBTA_STATUS
128 **
129 *******************************************************************************/
BTA_EnableTestMode(void)130 tBTA_STATUS BTA_EnableTestMode(void)
131 {
132     BT_HDR    *p_msg;
133 
134     APPL_TRACE_API("BTA_EnableTestMode");
135 
136     if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
137     {
138         p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
139         bta_sys_sendmsg(p_msg);
140         return BTA_SUCCESS;
141     }
142     return BTA_FAILURE;
143 }
144 
145 /*******************************************************************************
146 **
147 ** Function         BTA_DisableTestMode
148 **
149 ** Description      Disable bluetooth device under test mode
150 **
151 **
152 ** Returns          None
153 **
154 *******************************************************************************/
BTA_DisableTestMode(void)155 void BTA_DisableTestMode(void)
156 {
157     BT_HDR    *p_msg;
158 
159     APPL_TRACE_API("BTA_DisableTestMode");
160 
161     if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
162     {
163         p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
164         bta_sys_sendmsg(p_msg);
165     }
166 }
167 
168 /*******************************************************************************
169 **
170 ** Function         BTA_DmIsDeviceUp
171 **
172 ** Description      Called during startup to check whether the bluetooth module
173 **                  is up and ready
174 **
175 ** Returns          BOOLEAN
176 **
177 *******************************************************************************/
BTA_DmIsDeviceUp(void)178 BOOLEAN BTA_DmIsDeviceUp(void)
179 {
180     return BTM_IsDeviceUp();
181 }
182 
183 /*******************************************************************************
184 **
185 ** Function         BTA_DmSetDeviceName
186 **
187 ** Description      This function sets the Bluetooth name of local device
188 **
189 **
190 ** Returns          void
191 **
192 *******************************************************************************/
BTA_DmSetDeviceName(char * p_name)193 void BTA_DmSetDeviceName(char *p_name)
194 {
195 
196     tBTA_DM_API_SET_NAME    *p_msg;
197 
198     if ((p_msg = (tBTA_DM_API_SET_NAME *) GKI_getbuf(sizeof(tBTA_DM_API_SET_NAME))) != NULL)
199     {
200         p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
201         /* truncate the name if needed */
202         BCM_STRNCPY_S((char *)p_msg->name, sizeof(p_msg->name), p_name, BD_NAME_LEN-1);
203         p_msg->name[BD_NAME_LEN-1]=0;
204 
205         bta_sys_sendmsg(p_msg);
206     }
207 
208 
209 }
210 
211 /*******************************************************************************
212 **
213 ** Function         BTA_DmSetVisibility
214 **
215 ** Description      This function sets the Bluetooth connectable,
216 **                  discoverable, pairable and conn paired only modes of local device
217 **
218 **
219 ** Returns          void
220 **
221 *******************************************************************************/
BTA_DmSetVisibility(tBTA_DM_DISC disc_mode,tBTA_DM_CONN conn_mode,UINT8 pairable_mode,UINT8 conn_filter)222 void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 pairable_mode, UINT8 conn_filter )
223 {
224 
225     tBTA_DM_API_SET_VISIBILITY    *p_msg;
226 
227     if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
228     {
229         p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
230         p_msg->disc_mode = disc_mode;
231         p_msg->conn_mode = conn_mode;
232         p_msg->pair_mode = pairable_mode;
233         p_msg->conn_paired_only = conn_filter;
234 
235 
236         bta_sys_sendmsg(p_msg);
237     }
238 
239 
240 }
241 
242 /*******************************************************************************
243 **
244 ** Function         BTA_DmSetScanParam
245 **
246 ** Description      This function sets the parameters for page scan and
247 **                  inquiry scan.
248 **
249 **
250 ** Returns          void
251 **
252 *******************************************************************************/
BTA_DmSetScanParam(UINT16 page_scan_interval,UINT16 page_scan_window,UINT16 inquiry_scan_interval,UINT16 inquiry_scan_window)253 void BTA_DmSetScanParam (UINT16 page_scan_interval, UINT16 page_scan_window,
254                                   UINT16 inquiry_scan_interval, UINT16 inquiry_scan_window)
255 {
256     APPL_TRACE_API ("BTA_DmSetScanParam: %d, %d, %d, %d",
257             page_scan_interval, page_scan_window,
258             inquiry_scan_interval, inquiry_scan_window);
259 
260     bta_dm_cb.page_scan_interval = page_scan_interval;
261     bta_dm_cb.page_scan_window = page_scan_window;
262     bta_dm_cb.inquiry_scan_interval = inquiry_scan_interval;
263     bta_dm_cb.inquiry_scan_window = inquiry_scan_window;
264 }
265 
266 /*******************************************************************************
267 **
268 ** Function         BTA_DmSetAfhChannels
269 **
270 ** Description      This function sets the AFH first and
271 **                  last disable channel, so channels within
272 **                  that range are disabled.
273 **
274 ** Returns          void
275 **
276 *******************************************************************************/
BTA_DmSetAfhChannels(UINT8 first,UINT8 last)277 void BTA_DmSetAfhChannels(UINT8 first, UINT8 last)
278 {
279 
280     tBTA_DM_API_SET_AFH_CHANNELS_EVT    *p_msg;
281 
282     if ((p_msg = (tBTA_DM_API_SET_AFH_CHANNELS_EVT *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
283     {
284         p_msg->hdr.event = BTA_DM_API_SET_AFH_CHANNELS_EVT;
285         p_msg->first = first;
286         p_msg->last = last;
287         bta_sys_sendmsg(p_msg);
288     }
289 
290 
291 }
292 
293 /*******************************************************************************
294 **
295 ** Function         BTA_SetAfhChannelAssessment
296 **
297 ** Description      This function is called to set the channel assessment mode on or off
298 **
299 ** Returns          status
300 **
301 *******************************************************************************/
BTA_DmSetAfhChannelAssessment(BOOLEAN enable_or_disable)302 void BTA_DmSetAfhChannelAssessment (BOOLEAN enable_or_disable)
303 {
304     tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT *p_msg;
305 
306     if ((p_msg = (tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT *) GKI_getbuf(sizeof(tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT))) != NULL)
307     {
308         p_msg->hdr.event    = BTA_DM_API_SET_AFH_CHANNEL_ASSESMENT_EVT;
309         p_msg->enable_or_disable = enable_or_disable;
310         bta_sys_sendmsg(p_msg);
311     }
312 }
313 
314 /*******************************************************************************
315 **
316 ** Function         BTA_DmVendorSpecificCommand
317 **
318 ** Description      This function sends the vendor specific command
319 **                  to the controller
320 **
321 **
322 ** Returns          tBTA_STATUS
323 **
324 *******************************************************************************/
BTA_DmVendorSpecificCommand(UINT16 opcode,UINT8 param_len,UINT8 * p_param_buf,tBTA_VENDOR_CMPL_CBACK * p_cback)325 tBTA_STATUS BTA_DmVendorSpecificCommand (UINT16 opcode, UINT8 param_len,
326                                          UINT8 *p_param_buf,
327                                          tBTA_VENDOR_CMPL_CBACK *p_cback)
328 {
329 
330     tBTA_DM_API_VENDOR_SPECIFIC_COMMAND    *p_msg;
331     UINT16 size;
332 
333     /* If p_cback is NULL, Notify application */
334     if (p_cback == NULL)
335     {
336         return (BTA_FAILURE);
337     }
338     else
339     {
340         size = sizeof (tBTA_DM_API_VENDOR_SPECIFIC_COMMAND) + param_len;
341         if ((p_msg = (tBTA_DM_API_VENDOR_SPECIFIC_COMMAND *) GKI_getbuf(size)) != NULL)
342         {
343             p_msg->hdr.event = BTA_DM_API_VENDOR_SPECIFIC_COMMAND_EVT;
344             p_msg->opcode = opcode;
345             p_msg->p_param_buf = (UINT8 *)(p_msg + 1);
346             p_msg->p_cback = p_cback;
347 
348             if (p_param_buf && param_len)
349             {
350                 memcpy (p_msg->p_param_buf, p_param_buf, param_len);
351                 p_msg->param_len = param_len;
352             }
353             else
354             {
355                 p_msg->param_len = 0;
356                 p_msg->p_param_buf = NULL;
357 
358             }
359 
360             bta_sys_sendmsg(p_msg);
361         }
362         return (BTA_SUCCESS);
363     }
364 }
365 /*******************************************************************************
366 **
367 ** Function         BTA_DmSearch
368 **
369 ** Description      This function searches for peer Bluetooth devices. It performs
370 **                  an inquiry and gets the remote name for devices. Service
371 **                  discovery is done if services is non zero
372 **
373 **
374 ** Returns          void
375 **
376 *******************************************************************************/
BTA_DmSearch(tBTA_DM_INQ * p_dm_inq,tBTA_SERVICE_MASK services,tBTA_DM_SEARCH_CBACK * p_cback)377 void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback)
378 {
379 
380     tBTA_DM_API_SEARCH    *p_msg;
381 
382     if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(sizeof(tBTA_DM_API_SEARCH))) != NULL)
383     {
384         memset(p_msg, 0, sizeof(tBTA_DM_API_SEARCH));
385 
386         p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
387         memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
388         p_msg->services = services;
389         p_msg->p_cback = p_cback;
390         p_msg->rs_res  = BTA_DM_RS_NONE;
391         bta_sys_sendmsg(p_msg);
392     }
393 
394 }
395 
396 
397 /*******************************************************************************
398 **
399 ** Function         BTA_DmSearchCancel
400 **
401 ** Description      This function  cancels a search initiated by BTA_DmSearch
402 **
403 **
404 ** Returns          void
405 **
406 *******************************************************************************/
BTA_DmSearchCancel(void)407 void BTA_DmSearchCancel(void)
408 {
409     BT_HDR    *p_msg;
410 
411     if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
412     {
413         p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
414         bta_sys_sendmsg(p_msg);
415     }
416 
417 }
418 
419 /*******************************************************************************
420 **
421 ** Function         BTA_DmDiscover
422 **
423 ** Description      This function does service discovery for services of a
424 **                  peer device
425 **
426 **
427 ** Returns          void
428 **
429 *******************************************************************************/
BTA_DmDiscover(BD_ADDR bd_addr,tBTA_SERVICE_MASK services,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search)430 void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
431                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
432 {
433     tBTA_DM_API_DISCOVER    *p_msg;
434 
435     if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL)
436     {
437         memset(p_msg, 0, sizeof(tBTA_DM_API_DISCOVER));
438 
439         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
440         bdcpy(p_msg->bd_addr, bd_addr);
441         p_msg->services = services;
442         p_msg->p_cback = p_cback;
443         p_msg->sdp_search = sdp_search;
444         bta_sys_sendmsg(p_msg);
445     }
446 
447 }
448 
449 /*******************************************************************************
450 **
451 ** Function         BTA_DmDiscoverUUID
452 **
453 ** Description      This function does service discovery for services of a
454 **                  peer device
455 **
456 **
457 ** Returns          void
458 **
459 *******************************************************************************/
BTA_DmDiscoverUUID(BD_ADDR bd_addr,tSDP_UUID * uuid,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search)460 void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
461                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
462 {
463     tBTA_DM_API_DISCOVER    *p_msg;
464 
465     if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL)
466     {
467         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
468         bdcpy(p_msg->bd_addr, bd_addr);
469         p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level
470         p_msg->p_cback = p_cback;
471         p_msg->sdp_search = sdp_search;
472 
473 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
474         p_msg->num_uuid = 0;
475         p_msg->p_uuid = NULL;
476 #endif
477         memcpy( &p_msg->uuid, uuid, sizeof(tSDP_UUID) );
478         bta_sys_sendmsg(p_msg);
479     }
480 
481 }
482 /*******************************************************************************
483 **
484 ** Function         BTA_DmIsMaster
485 **
486 ** Description      This function checks if the local device is the master of
487 **                  the link to the given device
488 **
489 ** Returns          TRUE if master.
490 **                  FALSE if not.
491 **
492 *******************************************************************************/
BTA_DmIsMaster(BD_ADDR bd_addr)493 BOOLEAN BTA_DmIsMaster(BD_ADDR bd_addr)
494 {
495     BOOLEAN is_master = FALSE;
496     UINT8 link_role;
497 
498     BTM_GetRole(bd_addr, &link_role);
499     APPL_TRACE_API("BTA_DmIsMaster role:x%x", link_role);
500     if(link_role == BTM_ROLE_MASTER)
501     {
502         is_master = TRUE;
503     }
504     return is_master;
505 }
506 
507 /*******************************************************************************
508 **
509 ** Function         BTA_DmBond
510 **
511 ** Description      This function initiates a bonding procedure with a peer
512 **                  device
513 **
514 **
515 ** Returns          void
516 **
517 *******************************************************************************/
BTA_DmBond(BD_ADDR bd_addr)518 void BTA_DmBond(BD_ADDR bd_addr)
519 {
520     BTA_DmBondByTransport (bd_addr, BTA_TRANSPORT_UNKNOWN);
521 }
522 
523 /*******************************************************************************
524 **
525 ** Function         BTA_DmBondByTransports
526 **
527 ** Description      This function initiates a bonding procedure with a peer
528 **                  device
529 **
530 **
531 ** Returns          void
532 **
533 *******************************************************************************/
BTA_DmBondByTransport(BD_ADDR bd_addr,tBTA_TRANSPORT transport)534 void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport)
535 {
536     tBTA_DM_API_BOND    *p_msg;
537 
538     if ((p_msg = (tBTA_DM_API_BOND *) GKI_getbuf(sizeof(tBTA_DM_API_BOND))) != NULL)
539     {
540         p_msg->hdr.event = BTA_DM_API_BOND_EVT;
541         bdcpy(p_msg->bd_addr, bd_addr);
542         p_msg->transport = transport;
543         bta_sys_sendmsg(p_msg);
544     }
545 
546 
547 }
548 
549 /*******************************************************************************
550 **
551 ** Function         BTA_DmBondCancel
552 **
553 ** Description      This function cancels the bonding procedure with a peer
554 **                  device
555 **
556 **
557 ** Returns          void
558 **
559 *******************************************************************************/
BTA_DmBondCancel(BD_ADDR bd_addr)560 void BTA_DmBondCancel(BD_ADDR bd_addr)
561 {
562     tBTA_DM_API_BOND_CANCEL    *p_msg;
563 
564     if ((p_msg = (tBTA_DM_API_BOND_CANCEL *) GKI_getbuf(sizeof(tBTA_DM_API_BOND_CANCEL))) != NULL)
565     {
566         p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
567         bdcpy(p_msg->bd_addr, bd_addr);
568         bta_sys_sendmsg(p_msg);
569     }
570 
571 
572 }
573 
574 /*******************************************************************************
575 **
576 ** Function         BTA_DmPinReply
577 **
578 ** Description      This function provides a pincode for a remote device when
579 **                  one is requested by DM through BTA_DM_PIN_REQ_EVT
580 **
581 **
582 ** Returns          void
583 **
584 *******************************************************************************/
BTA_DmPinReply(BD_ADDR bd_addr,BOOLEAN accept,UINT8 pin_len,UINT8 * p_pin)585 void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin)
586 
587 {
588     tBTA_DM_API_PIN_REPLY    *p_msg;
589 
590     if ((p_msg = (tBTA_DM_API_PIN_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PIN_REPLY))) != NULL)
591     {
592         p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
593         bdcpy(p_msg->bd_addr, bd_addr);
594         p_msg->accept = accept;
595         if(accept)
596         {
597             p_msg->pin_len = pin_len;
598             memcpy(p_msg->p_pin, p_pin, pin_len);
599         }
600         bta_sys_sendmsg(p_msg);
601     }
602 
603 }
604 
605 /*******************************************************************************
606 **
607 ** Function         BTA_DmLinkPolicy
608 **
609 ** Description      This function sets/clears the link policy mask to the given
610 **                  bd_addr.
611 **                  If clearing the sniff or park mode mask, the link is put
612 **                  in active mode.
613 **
614 ** Returns          void
615 **
616 *******************************************************************************/
BTA_DmLinkPolicy(BD_ADDR bd_addr,tBTA_DM_LP_MASK policy_mask,BOOLEAN set)617 void BTA_DmLinkPolicy(BD_ADDR bd_addr, tBTA_DM_LP_MASK policy_mask,
618                       BOOLEAN set)
619 {
620     tBTA_DM_API_LINK_POLICY    *p_msg;
621 
622     if ((p_msg = (tBTA_DM_API_LINK_POLICY *) GKI_getbuf(sizeof(tBTA_DM_API_LINK_POLICY))) != NULL)
623     {
624         p_msg->hdr.event = BTA_DM_API_LINK_POLICY_EVT;
625         bdcpy(p_msg->bd_addr, bd_addr);
626         p_msg->policy_mask = policy_mask;
627         p_msg->set = set;
628         bta_sys_sendmsg(p_msg);
629     }
630 }
631 
632 
633 #if (BTM_OOB_INCLUDED == TRUE)
634 /*******************************************************************************
635 **
636 ** Function         BTA_DmLocalOob
637 **
638 ** Description      This function retrieves the OOB data from local controller.
639 **                  The result is reported by bta_dm_co_loc_oob().
640 **
641 ** Returns          void
642 **
643 *******************************************************************************/
BTA_DmLocalOob(void)644 void BTA_DmLocalOob(void)
645 {
646     tBTA_DM_API_LOC_OOB    *p_msg;
647 
648     if ((p_msg = (tBTA_DM_API_LOC_OOB *) GKI_getbuf(sizeof(tBTA_DM_API_LOC_OOB))) != NULL)
649     {
650         p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
651         bta_sys_sendmsg(p_msg);
652     }
653 }
654 #endif /* BTM_OOB_INCLUDED */
655 /*******************************************************************************
656 **
657 ** Function         BTA_DmConfirm
658 **
659 ** Description      This function accepts or rejects the numerical value of the
660 **                  Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
661 **
662 ** Returns          void
663 **
664 *******************************************************************************/
BTA_DmConfirm(BD_ADDR bd_addr,BOOLEAN accept)665 void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept)
666 {
667     tBTA_DM_API_CONFIRM    *p_msg;
668 
669     if ((p_msg = (tBTA_DM_API_CONFIRM *) GKI_getbuf(sizeof(tBTA_DM_API_CONFIRM))) != NULL)
670     {
671         p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
672         bdcpy(p_msg->bd_addr, bd_addr);
673         p_msg->accept = accept;
674         bta_sys_sendmsg(p_msg);
675     }
676 }
677 
678 /*******************************************************************************
679 **
680 ** Function         BTA_DmPasskeyCancel
681 **
682 ** Description      This function is called to cancel the simple pairing process
683 **                  reported by BTA_DM_SP_KEY_NOTIF_EVT
684 **
685 ** Returns          void
686 **
687 *******************************************************************************/
688 #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)
BTA_DmPasskeyCancel(BD_ADDR bd_addr)689 void BTA_DmPasskeyCancel(BD_ADDR bd_addr)
690 {
691     tBTA_DM_API_PASKY_CANCEL    *p_msg;
692 
693     if ((p_msg = (tBTA_DM_API_PASKY_CANCEL *) \
694         GKI_getbuf(sizeof(tBTA_DM_API_PASKY_CANCEL))) != NULL)
695     {
696         p_msg->hdr.event = BTA_DM_API_PASKY_CANCEL_EVT;
697         bdcpy(p_msg->bd_addr, bd_addr);
698         bta_sys_sendmsg(p_msg);
699     }
700 }
701 #endif
702 
703 
704 /*******************************************************************************
705 **
706 ** Function         BTA_DmAddDevice
707 **
708 ** Description      This function adds a device to the security database list of
709 **                  peer device
710 **
711 **
712 ** Returns          void
713 **
714 *******************************************************************************/
BTA_DmAddDevice(BD_ADDR bd_addr,DEV_CLASS dev_class,LINK_KEY link_key,tBTA_SERVICE_MASK trusted_mask,BOOLEAN is_trusted,UINT8 key_type,tBTA_IO_CAP io_cap)715 void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
716                      tBTA_SERVICE_MASK trusted_mask, BOOLEAN is_trusted,
717                      UINT8 key_type, tBTA_IO_CAP io_cap)
718 {
719 
720     tBTA_DM_API_ADD_DEVICE *p_msg;
721 
722     if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL)
723     {
724         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE));
725 
726         p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
727         bdcpy(p_msg->bd_addr, bd_addr);
728         p_msg->tm = trusted_mask;
729         p_msg->is_trusted = is_trusted;
730         p_msg->io_cap = io_cap;
731 
732         if (link_key)
733         {
734             p_msg->link_key_known = TRUE;
735             p_msg->key_type = key_type;
736             memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
737         }
738 
739         /* Load device class if specified */
740         if (dev_class)
741         {
742             p_msg->dc_known = TRUE;
743             memcpy (p_msg->dc, dev_class, DEV_CLASS_LEN);
744         }
745 
746         memset (p_msg->bd_name, 0, BD_NAME_LEN);
747         memset (p_msg->features, 0, sizeof (p_msg->features));
748 
749         bta_sys_sendmsg(p_msg);
750     }
751 }
752 
753 
754 /*******************************************************************************
755 **
756 ** Function         BTA_DmRemoveDevice
757 **
758 ** Description      This function removes a device fromthe security database list of
759 **                  peer device
760 **
761 **
762 ** Returns          void
763 **
764 *******************************************************************************/
BTA_DmRemoveDevice(BD_ADDR bd_addr)765 tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
766 {
767     tBTA_DM_API_REMOVE_DEVICE *p_msg;
768 
769     if ((p_msg = (tBTA_DM_API_REMOVE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_DEVICE))) != NULL)
770     {
771         memset (p_msg, 0, sizeof(tBTA_DM_API_REMOVE_DEVICE));
772 
773         p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
774         bdcpy(p_msg->bd_addr, bd_addr);
775         bta_sys_sendmsg(p_msg);
776     }
777     else
778     {
779         return BTA_FAILURE;
780     }
781 
782     return BTA_SUCCESS;
783 }
784 
785 /*******************************************************************************
786 **
787 ** Function         BTA_DmAddDevWithName
788 **
789 ** Description      This function is newer version of  BTA_DmAddDevice()
790 **                  which added bd_name and features as input parameters.
791 **
792 **
793 ** Returns          void
794 **
795 *******************************************************************************/
BTA_DmAddDevWithName(BD_ADDR bd_addr,DEV_CLASS dev_class,BD_NAME bd_name,UINT8 * features,LINK_KEY link_key,tBTA_SERVICE_MASK trusted_mask,BOOLEAN is_trusted,UINT8 key_type,tBTA_IO_CAP io_cap)796 void BTA_DmAddDevWithName (BD_ADDR bd_addr, DEV_CLASS dev_class,
797                                       BD_NAME bd_name, UINT8 *features,
798                                       LINK_KEY link_key, tBTA_SERVICE_MASK trusted_mask,
799                                       BOOLEAN is_trusted, UINT8 key_type, tBTA_IO_CAP io_cap)
800 {
801     tBTA_DM_API_ADD_DEVICE *p_msg;
802 
803     if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL)
804     {
805         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE));
806 
807         p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
808         bdcpy(p_msg->bd_addr, bd_addr);
809         p_msg->tm = trusted_mask;
810         p_msg->is_trusted = is_trusted;
811         p_msg->io_cap = io_cap;
812 
813         if (link_key)
814         {
815             p_msg->link_key_known = TRUE;
816             p_msg->key_type = key_type;
817             memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
818         }
819 
820         /* Load device class if specified */
821         if (dev_class)
822         {
823             p_msg->dc_known = TRUE;
824             memcpy (p_msg->dc, dev_class, DEV_CLASS_LEN);
825         }
826 
827         if (bd_name)
828             memcpy(p_msg->bd_name, bd_name, BD_NAME_LEN);
829 
830         if (features)
831             memcpy(p_msg->features, features, sizeof(p_msg->features));
832 
833         bta_sys_sendmsg(p_msg);
834     }
835 }
836 
837 /*******************************************************************************
838 **
839 ** Function         BTA_DmAuthorizeReply
840 **
841 ** Description      This function provides an authorization reply when authorization
842 **                  is requested by BTA through BTA_DM_AUTHORIZE_EVT
843 **
844 **
845 ** Returns          tBTA_STATUS
846 **
847 *******************************************************************************/
BTA_DmAuthorizeReply(BD_ADDR bd_addr,tBTA_SERVICE_ID service,tBTA_AUTH_RESP response)848 void BTA_DmAuthorizeReply(BD_ADDR bd_addr, tBTA_SERVICE_ID service, tBTA_AUTH_RESP response)
849 {
850 
851     tBTA_DM_API_AUTH_REPLY    *p_msg;
852 
853     if ((p_msg = (tBTA_DM_API_AUTH_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_AUTH_REPLY))) != NULL)
854     {
855         p_msg->hdr.event = BTA_DM_API_AUTH_REPLY_EVT;
856         bdcpy(p_msg->bd_addr, bd_addr);
857         p_msg->service = service;
858         p_msg->response = response;
859 
860         bta_sys_sendmsg(p_msg);
861     }
862 
863 }
864 
865 /*******************************************************************************
866 **
867 ** Function         BTA_DmSignalStrength
868 **
869 ** Description      This function initiates RSSI and channnel quality
870 **                  measurments. BTA_DM_SIG_STRENGTH_EVT is sent to
871 **                  application with the values of RSSI and channel
872 **                  quality
873 **
874 **
875 ** Returns          void
876 **
877 *******************************************************************************/
BTA_DmSignalStrength(tBTA_SIG_STRENGTH_MASK mask,UINT16 period,BOOLEAN start)878 void BTA_DmSignalStrength(tBTA_SIG_STRENGTH_MASK mask, UINT16 period, BOOLEAN start)
879 {
880 
881     tBTA_API_DM_SIG_STRENGTH    *p_msg;
882 
883     if ((p_msg = (tBTA_API_DM_SIG_STRENGTH *) GKI_getbuf(sizeof(tBTA_API_DM_SIG_STRENGTH))) != NULL)
884     {
885         p_msg->hdr.event = BTA_API_DM_SIG_STRENGTH_EVT;
886         p_msg->mask = mask;
887         p_msg->period = period;
888         p_msg->start = start;
889 
890         bta_sys_sendmsg(p_msg);
891     }
892 
893 
894 }
895 
896 /*******************************************************************************
897 **
898 ** Function         BTA_DmWriteInqTxPower
899 **
900 ** Description      This command is used to write the inquiry transmit power level
901 **                  used to transmit the inquiry (ID) data packets.
902 **
903 ** Parameters       tx_power - tx inquiry power to use, valid value is -70 ~ 20
904 
905 ** Returns          void
906 **
907 *******************************************************************************/
BTA_DmWriteInqTxPower(INT8 tx_power)908 void BTA_DmWriteInqTxPower(INT8 tx_power)
909 {
910 
911     tBTA_API_DM_TX_INQPWR    *p_msg;
912 
913     if ((p_msg = (tBTA_API_DM_TX_INQPWR *) GKI_getbuf(sizeof(tBTA_API_DM_TX_INQPWR))) != NULL)
914     {
915         p_msg->hdr.event = BTA_DM_API_TX_INQPWR_EVT;
916         p_msg->tx_power = tx_power;
917 
918         bta_sys_sendmsg(p_msg);
919     }
920 }
921 
922 
923 /*******************************************************************************
924 **
925 ** Function         BTA_DmEirAddUUID
926 **
927 ** Description      This function is called to add UUID into EIR.
928 **
929 ** Parameters       tBT_UUID - UUID
930 **
931 ** Returns          None
932 **
933 *******************************************************************************/
BTA_DmEirAddUUID(tBT_UUID * p_uuid)934 void BTA_DmEirAddUUID (tBT_UUID *p_uuid)
935 {
936 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
937     tBTA_DM_API_UPDATE_EIR_UUID    *p_msg;
938 
939     if ((p_msg = (tBTA_DM_API_UPDATE_EIR_UUID *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_EIR_UUID))) != NULL)
940     {
941         p_msg->hdr.event = BTA_DM_API_UPDATE_EIR_UUID_EVT;
942         p_msg->is_add    = TRUE;
943         memcpy (&(p_msg->uuid), p_uuid, sizeof(tBT_UUID));
944 
945         bta_sys_sendmsg(p_msg);
946     }
947 #endif
948 }
949 
950 /*******************************************************************************
951 **
952 ** Function         BTA_DmEirRemoveUUID
953 **
954 ** Description      This function is called to remove UUID from EIR.
955 **
956 ** Parameters       tBT_UUID - UUID
957 **
958 ** Returns          None
959 **
960 *******************************************************************************/
BTA_DmEirRemoveUUID(tBT_UUID * p_uuid)961 void BTA_DmEirRemoveUUID (tBT_UUID *p_uuid)
962 {
963 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
964     tBTA_DM_API_UPDATE_EIR_UUID    *p_msg;
965 
966     if ((p_msg = (tBTA_DM_API_UPDATE_EIR_UUID *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_EIR_UUID))) != NULL)
967     {
968         p_msg->hdr.event = BTA_DM_API_UPDATE_EIR_UUID_EVT;
969         p_msg->is_add    = FALSE;
970         memcpy (&(p_msg->uuid), p_uuid, sizeof(tBT_UUID));
971 
972         bta_sys_sendmsg(p_msg);
973     }
974 #endif
975 }
976 
977 /*******************************************************************************
978 **
979 ** Function         BTA_DmSetEIRConfig
980 **
981 ** Description      This function is called to override the BTA default EIR parameters.
982 **                  This funciton is only valid in a system where BTU & App task
983 **                  are in the same memory space.
984 **
985 ** Parameters       Pointer to User defined EIR config
986 **
987 ** Returns          None
988 **
989 *******************************************************************************/
BTA_DmSetEIRConfig(tBTA_DM_EIR_CONF * p_eir_cfg)990 void BTA_DmSetEIRConfig (tBTA_DM_EIR_CONF *p_eir_cfg)
991 {
992 #if (BTM_EIR_SERVER_INCLUDED == TRUE)
993     tBTA_DM_API_SET_EIR_CONFIG  *p_msg;
994 
995     if ((p_msg = (tBTA_DM_API_SET_EIR_CONFIG *) GKI_getbuf(sizeof(tBTA_DM_API_SET_EIR_CONFIG))) != NULL)
996     {
997         p_msg->hdr.event = BTA_DM_API_SET_EIR_CONFIG_EVT;
998         p_msg->p_eir_cfg = p_eir_cfg;
999 
1000         bta_sys_sendmsg(p_msg);
1001     }
1002 #endif
1003 }
1004 
1005 /*******************************************************************************
1006 **
1007 ** Function         BTA_CheckEirData
1008 **
1009 ** Description      This function is called to get EIR data from significant part.
1010 **
1011 ** Parameters       p_eir - pointer of EIR significant part
1012 **                  type   - finding EIR data type
1013 **                  p_length - return the length of EIR data
1014 **
1015 ** Returns          pointer of EIR data
1016 **
1017 *******************************************************************************/
BTA_CheckEirData(UINT8 * p_eir,UINT8 type,UINT8 * p_length)1018 UINT8 *BTA_CheckEirData( UINT8 *p_eir, UINT8 type, UINT8 *p_length )
1019 {
1020 #if ( BTM_EIR_CLIENT_INCLUDED == TRUE )
1021     return BTM_CheckEirData( p_eir, type, p_length );
1022 #else
1023     return NULL;
1024 #endif
1025 }
1026 
1027 /*******************************************************************************
1028 **
1029 ** Function         BTA_GetEirService
1030 **
1031 ** Description      This function is called to get BTA service mask from EIR.
1032 **
1033 ** Parameters       p_eir - pointer of EIR significant part
1034 **                  p_services - return the BTA service mask
1035 **
1036 ** Returns          None
1037 **
1038 *******************************************************************************/
1039 extern const UINT16 bta_service_id_to_uuid_lkup_tbl [];
BTA_GetEirService(UINT8 * p_eir,tBTA_SERVICE_MASK * p_services)1040 void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services )
1041 {
1042 #if ( BTM_EIR_CLIENT_INCLUDED == TRUE )
1043     UINT8 xx, yy;
1044     UINT8 num_uuid, max_num_uuid = 32;
1045     UINT8 uuid_list[32*LEN_UUID_16];
1046     UINT16 *p_uuid16 = (UINT16 *)uuid_list;
1047     tBTA_SERVICE_MASK mask;
1048 
1049     BTM_GetEirUuidList( p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid);
1050     for( xx = 0; xx < num_uuid; xx++ )
1051     {
1052         mask = 1;
1053         for( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ )
1054         {
1055             if( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] )
1056             {
1057                 *p_services |= mask;
1058                 break;
1059             }
1060             mask <<= 1;
1061         }
1062 
1063         /* for HSP v1.2 only device */
1064         if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS)
1065             *p_services |= BTA_HSP_SERVICE_MASK;
1066 
1067        if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE)
1068             *p_services |= BTA_HL_SERVICE_MASK;
1069 
1070         if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK)
1071             *p_services |= BTA_HL_SERVICE_MASK;
1072     }
1073 #endif
1074 }
1075 
1076 /*******************************************************************************
1077 **
1078 ** Function         BTA_DmUseSsr
1079 **
1080 ** Description      This function is called to check if the connected peer device
1081 **                  supports SSR or not.
1082 **
1083 ** Returns          TRUE, if SSR is supported
1084 **
1085 *******************************************************************************/
BTA_DmUseSsr(BD_ADDR bd_addr)1086 BOOLEAN BTA_DmUseSsr( BD_ADDR bd_addr )
1087 {
1088     BOOLEAN use_ssr = FALSE;
1089     tBTA_DM_PEER_DEVICE * p_dev = bta_dm_find_peer_device(bd_addr);
1090     if(p_dev && (p_dev->info & BTA_DM_DI_USE_SSR) )
1091         use_ssr = TRUE;
1092     return use_ssr;
1093 }
1094 
1095 /*******************************************************************************
1096 **
1097 ** Function         BTA_DmGetConnectionState
1098 **
1099 ** Description      Returns whether the remote device is currently connected.
1100 **
1101 ** Returns          0 if the device is NOT connected.
1102 **
1103 *******************************************************************************/
BTA_DmGetConnectionState(BD_ADDR bd_addr)1104 UINT16 BTA_DmGetConnectionState( BD_ADDR bd_addr )
1105 {
1106     tBTA_DM_PEER_DEVICE * p_dev = bta_dm_find_peer_device(bd_addr);
1107     return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
1108 }
1109 
1110 
1111 /*******************************************************************************
1112 **                   Device Identification (DI) Server Functions
1113 *******************************************************************************/
1114 /*******************************************************************************
1115 **
1116 ** Function         BTA_DmSetLocalDiRecord
1117 **
1118 ** Description      This function adds a DI record to the local SDP database.
1119 **
1120 ** Returns          BTA_SUCCESS if record set sucessfully, otherwise error code.
1121 **
1122 *******************************************************************************/
BTA_DmSetLocalDiRecord(tBTA_DI_RECORD * p_device_info,UINT32 * p_handle)1123 tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
1124                               UINT32 *p_handle )
1125 {
1126     tBTA_STATUS  status = BTA_FAILURE;
1127 
1128     if(bta_dm_di_cb.di_num < BTA_DI_NUM_MAX)
1129     {
1130         if(SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS)
1131         {
1132             if(!p_device_info->primary_record)
1133             {
1134                 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
1135                 bta_dm_di_cb.di_num ++;
1136             }
1137 
1138             bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
1139             status =  BTA_SUCCESS;
1140         }
1141     }
1142 
1143     return status;
1144 }
1145 
1146 /*******************************************************************************
1147 **
1148 ** Function         BTA_DmGetLocalDiRecord
1149 **
1150 ** Description      Get a specified DI record to the local SDP database. If no
1151 **                  record handle is provided, the primary DI record will be
1152 **                  returned.
1153 **
1154 **                  Fills in the device information of the record
1155 **                  p_handle - if p_handle == 0, the primary record is returned
1156 **
1157 ** Returns          BTA_SUCCESS if record set sucessfully, otherwise error code.
1158 **
1159 *******************************************************************************/
BTA_DmGetLocalDiRecord(tBTA_DI_GET_RECORD * p_device_info,UINT32 * p_handle)1160 tBTA_STATUS BTA_DmGetLocalDiRecord( tBTA_DI_GET_RECORD *p_device_info,
1161                               UINT32 *p_handle )
1162 {
1163     UINT16  status;
1164 
1165     status = SDP_GetLocalDiRecord(p_device_info, p_handle);
1166 
1167     if (status == SDP_SUCCESS)
1168         return BTA_SUCCESS;
1169     else
1170         return BTA_FAILURE;
1171 
1172 }
1173 
1174 /*******************************************************************************
1175 **                   Device Identification (DI) Client Functions
1176 *******************************************************************************/
1177 /*******************************************************************************
1178 **
1179 ** Function         BTA_DmDiDiscover
1180 **
1181 ** Description      This function queries a remote device for DI information.
1182 **
1183 **
1184 ** Returns          None.
1185 **
1186 *******************************************************************************/
BTA_DmDiDiscover(BD_ADDR remote_device,tBTA_DISCOVERY_DB * p_db,UINT32 len,tBTA_DM_SEARCH_CBACK * p_cback)1187 void BTA_DmDiDiscover( BD_ADDR remote_device, tBTA_DISCOVERY_DB *p_db,
1188                        UINT32 len, tBTA_DM_SEARCH_CBACK *p_cback )
1189 {
1190     tBTA_DM_API_DI_DISC    *p_msg;
1191 
1192     if ((p_msg = (tBTA_DM_API_DI_DISC *) GKI_getbuf(sizeof(tBTA_DM_API_DI_DISC))) != NULL)
1193     {
1194         bdcpy(p_msg->bd_addr, remote_device);
1195         p_msg->hdr.event    = BTA_DM_API_DI_DISCOVER_EVT;
1196         p_msg->p_sdp_db     = p_db;
1197         p_msg->len          = len;
1198         p_msg->p_cback      = p_cback;
1199 
1200         bta_sys_sendmsg(p_msg);
1201     }
1202 }
1203 
1204 /*******************************************************************************
1205 **
1206 ** Function         BTA_DmGetDiRecord
1207 **
1208 ** Description      This function retrieves a remote device's DI record from
1209 **                  the specified database.
1210 **
1211 ** Returns          BTA_SUCCESS if Get DI record is succeed.
1212 **                  BTA_FAILURE if Get DI record failed.
1213 **
1214 *******************************************************************************/
BTA_DmGetDiRecord(UINT8 get_record_index,tBTA_DI_GET_RECORD * p_device_info,tBTA_DISCOVERY_DB * p_db)1215 tBTA_STATUS BTA_DmGetDiRecord( UINT8 get_record_index, tBTA_DI_GET_RECORD *p_device_info,
1216                         tBTA_DISCOVERY_DB *p_db )
1217 {
1218     if (SDP_GetDiRecord(get_record_index, p_device_info, p_db) != SDP_SUCCESS)
1219         return BTA_FAILURE;
1220     else
1221         return BTA_SUCCESS;
1222 }
1223 
1224 /*******************************************************************************
1225 **
1226 ** Function         BTA_SysFeatures
1227 **
1228 ** Description      This function is called to set system features.
1229 **
1230 ** Returns          void
1231 **
1232 *******************************************************************************/
BTA_SysFeatures(UINT16 sys_features)1233 void BTA_SysFeatures (UINT16 sys_features)
1234 {
1235     bta_sys_cb.sys_features = sys_features;
1236 
1237     APPL_TRACE_API("BTA_SysFeatures: sys_features = %d", sys_features);
1238 }
1239 
1240 /*******************************************************************************
1241 **
1242 ** Function         bta_dmexecutecallback
1243 **
1244 ** Description      This function will request BTA to execute a call back in the context of BTU task
1245 **                  This API was named in lower case because it is only intended
1246 **                  for the internal customers(like BTIF).
1247 **
1248 ** Returns          void
1249 **
1250 *******************************************************************************/
bta_dmexecutecallback(tBTA_DM_EXEC_CBACK * p_callback,void * p_param)1251 void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param)
1252 {
1253     tBTA_DM_API_EXECUTE_CBACK *p_msg;
1254 
1255     if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
1256     {
1257         p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
1258         p_msg->p_param= p_param;
1259         p_msg->p_exec_cback= p_callback;
1260         bta_sys_sendmsg(p_msg);
1261     }
1262 }
1263 
1264 /*******************************************************************************
1265 **
1266 ** Function         BTA_DmAddBleKey
1267 **
1268 ** Description      Add/modify LE device information.  This function will be
1269 **                  normally called during host startup to restore all required
1270 **                  information stored in the NVRAM.
1271 **
1272 ** Parameters:      bd_addr          - BD address of the peer
1273 **                  p_le_key         - LE key values.
1274 **                  key_type         - LE SMP key type.
1275 **
1276 ** Returns          void
1277 **
1278 *******************************************************************************/
BTA_DmAddBleKey(BD_ADDR bd_addr,tBTA_LE_KEY_VALUE * p_le_key,tBTA_LE_KEY_TYPE key_type)1279 void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_TYPE key_type)
1280 {
1281 #if BLE_INCLUDED == TRUE
1282 
1283     tBTA_DM_API_ADD_BLEKEY *p_msg;
1284 
1285     if ((p_msg = (tBTA_DM_API_ADD_BLEKEY *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLEKEY))) != NULL)
1286     {
1287         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLEKEY));
1288 
1289         p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
1290         p_msg->key_type = key_type;
1291         bdcpy(p_msg->bd_addr, bd_addr);
1292         memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE));
1293 
1294         bta_sys_sendmsg(p_msg);
1295     }
1296 
1297 #endif
1298 }
1299 
1300 /*******************************************************************************
1301 **
1302 ** Function         BTA_DmAddBleDevice
1303 **
1304 ** Description      Add a BLE device.  This function will be normally called
1305 **                  during host startup to restore all required information
1306 **                  for a LE device stored in the NVRAM.
1307 **
1308 ** Parameters:      bd_addr          - BD address of the peer
1309 **                  dev_type         - Remote device's device type.
1310 **                  addr_type        - LE device address type.
1311 **
1312 ** Returns          void
1313 **
1314 *******************************************************************************/
BTA_DmAddBleDevice(BD_ADDR bd_addr,tBLE_ADDR_TYPE addr_type,tBT_DEVICE_TYPE dev_type)1315 void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TYPE dev_type)
1316 {
1317 #if BLE_INCLUDED == TRUE
1318     tBTA_DM_API_ADD_BLE_DEVICE *p_msg;
1319 
1320     if ((p_msg = (tBTA_DM_API_ADD_BLE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLE_DEVICE))) != NULL)
1321     {
1322         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
1323 
1324         p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
1325         bdcpy(p_msg->bd_addr, bd_addr);
1326         p_msg->addr_type = addr_type;
1327         p_msg->dev_type = dev_type;
1328 
1329         bta_sys_sendmsg(p_msg);
1330     }
1331 #endif
1332 }
1333 /*******************************************************************************
1334 **
1335 ** Function         BTA_DmBlePasskeyReply
1336 **
1337 ** Description      Send BLE SMP passkey reply.
1338 **
1339 ** Parameters:      bd_addr          - BD address of the peer
1340 **                  accept           - passkey entry sucessful or declined.
1341 **                  passkey          - passkey value, must be a 6 digit number,
1342 **                                     can be lead by 0.
1343 **
1344 ** Returns          void
1345 **
1346 *******************************************************************************/
BTA_DmBlePasskeyReply(BD_ADDR bd_addr,BOOLEAN accept,UINT32 passkey)1347 void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey)
1348 {
1349 #if BLE_INCLUDED == TRUE
1350     tBTA_DM_API_PASSKEY_REPLY    *p_msg;
1351 
1352     if ((p_msg = (tBTA_DM_API_PASSKEY_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PASSKEY_REPLY))) != NULL)
1353     {
1354         memset(p_msg, 0, sizeof(tBTA_DM_API_PASSKEY_REPLY));
1355 
1356         p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
1357         bdcpy(p_msg->bd_addr, bd_addr);
1358         p_msg->accept = accept;
1359 
1360         if(accept)
1361         {
1362             p_msg->passkey = passkey;
1363         }
1364         bta_sys_sendmsg(p_msg);
1365     }
1366 #endif
1367 }
1368 /*******************************************************************************
1369 **
1370 ** Function         BTA_DmBleSecurityGrant
1371 **
1372 ** Description      Grant security request access.
1373 **
1374 ** Parameters:      bd_addr          - BD address of the peer
1375 **                  res              - security grant status.
1376 **
1377 ** Returns          void
1378 **
1379 *******************************************************************************/
BTA_DmBleSecurityGrant(BD_ADDR bd_addr,tBTA_DM_BLE_SEC_GRANT res)1380 void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
1381 {
1382 #if BLE_INCLUDED == TRUE
1383     tBTA_DM_API_BLE_SEC_GRANT    *p_msg;
1384 
1385     if ((p_msg = (tBTA_DM_API_BLE_SEC_GRANT *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SEC_GRANT))) != NULL)
1386     {
1387         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SEC_GRANT));
1388 
1389         p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
1390         bdcpy(p_msg->bd_addr, bd_addr);
1391         p_msg->res = res;
1392 
1393         bta_sys_sendmsg(p_msg);
1394     }
1395 #endif
1396 }
1397 /*******************************************************************************
1398 **
1399 ** Function         BTA_DmSetBlePrefConnParams
1400 **
1401 ** Description      This function is called to set the preferred connection
1402 **                  parameters when default connection parameter is not desired.
1403 **
1404 ** Parameters:      bd_addr          - BD address of the peripheral
1405 **                  scan_interval    - scan interval
1406 **                  scan_window      - scan window
1407 **                  min_conn_int     - minimum preferred connection interval
1408 **                  max_conn_int     - maximum preferred connection interval
1409 **                  slave_latency    - preferred slave latency
1410 **                  supervision_tout - preferred supervision timeout
1411 **
1412 **
1413 ** Returns          void
1414 **
1415 *******************************************************************************/
BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,UINT16 min_conn_int,UINT16 max_conn_int,UINT16 slave_latency,UINT16 supervision_tout)1416 void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,
1417                                UINT16 min_conn_int, UINT16 max_conn_int,
1418                                UINT16 slave_latency, UINT16 supervision_tout )
1419 {
1420 #if BLE_INCLUDED == TRUE
1421     tBTA_DM_API_BLE_CONN_PARAMS    *p_msg;
1422 
1423     if ((p_msg = (tBTA_DM_API_BLE_CONN_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_CONN_PARAMS))) != NULL)
1424     {
1425         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
1426 
1427         p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
1428 
1429         memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN);
1430 
1431         p_msg->conn_int_max     = max_conn_int;
1432         p_msg->conn_int_min     = min_conn_int;
1433         p_msg->slave_latency    = slave_latency;
1434         p_msg->supervision_tout = supervision_tout;
1435 
1436         bta_sys_sendmsg(p_msg);
1437     }
1438 #endif
1439 }
1440 
1441 /*******************************************************************************
1442 **
1443 ** Function         BTA_DmSetBleConnScanParams
1444 **
1445 ** Description      This function is called to set scan parameters used in
1446 **                  BLE connection request
1447 **
1448 ** Parameters:      scan_interval    - scan interval
1449 **                  scan_window      - scan window
1450 **
1451 ** Returns          void
1452 **
1453 *******************************************************************************/
BTA_DmSetBleConnScanParams(UINT16 scan_interval,UINT16 scan_window)1454 void BTA_DmSetBleConnScanParams(UINT16 scan_interval, UINT16 scan_window )
1455 {
1456 #if BLE_INCLUDED == TRUE
1457     tBTA_DM_API_BLE_SCAN_PARAMS    *p_msg;
1458 
1459     if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL)
1460     {
1461         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
1462 
1463         p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT;
1464 
1465         p_msg->scan_int         = scan_interval;
1466         p_msg->scan_window      = scan_window;
1467 
1468         bta_sys_sendmsg(p_msg);
1469     }
1470 #endif
1471 }
1472 
1473 /*******************************************************************************
1474 **
1475 ** Function         BTA_DmSetBleAdvParams
1476 **
1477 ** Description      This function sets the advertising parameters BLE functionality.
1478 **                  It is to be called when device act in peripheral or broadcaster
1479 **                  role.
1480 **
1481 **
1482 ** Returns          void
1483 **
1484 *******************************************************************************/
BTA_DmSetBleAdvParams(UINT16 adv_int_min,UINT16 adv_int_max,tBLE_BD_ADDR * p_dir_bda)1485 void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
1486                            tBLE_BD_ADDR *p_dir_bda)
1487 {
1488 #if BLE_INCLUDED == TRUE
1489     tBTA_DM_API_BLE_ADV_PARAMS    *p_msg;
1490 
1491     APPL_TRACE_API ("BTA_DmSetBleAdvParam: %d, %d", adv_int_min, adv_int_max);
1492 
1493     if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS))) != NULL)
1494     {
1495         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS));
1496 
1497         p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_EVT;
1498 
1499         p_msg->adv_int_min      = adv_int_min;
1500         p_msg->adv_int_max      = adv_int_max;
1501 
1502         if (p_dir_bda != NULL)
1503         {
1504             p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
1505             memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
1506         }
1507 
1508         bta_sys_sendmsg(p_msg);
1509     }
1510 #endif
1511 }
1512 /*******************************************************************************
1513 **                      BLE ADV data management API
1514 ********************************************************************************/
1515 
1516 #if BLE_INCLUDED == TRUE
1517 /*******************************************************************************
1518 **
1519 ** Function         BTA_DmBleSetAdvConfig
1520 **
1521 ** Description      This function is called to override the BTA default ADV parameters.
1522 **
1523 ** Parameters       data_mask: adv data mask.
1524 **                  p_adv_cfg: Pointer to User defined ADV data structure. This
1525 **                             memory space can not be freed until p_adv_data_cback
1526 **                             is received.
1527 **                  p_adv_data_cback: set adv data complete callback.
1528 **
1529 ** Returns          None
1530 **
1531 *******************************************************************************/
BTA_DmBleSetAdvConfig(tBTA_BLE_AD_MASK data_mask,tBTA_BLE_ADV_DATA * p_adv_cfg,tBTA_SET_ADV_DATA_CMPL_CBACK * p_adv_data_cback)1532 void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
1533                             tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
1534 {
1535     tBTA_DM_API_SET_ADV_CONFIG  *p_msg;
1536 
1537     if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
1538         GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL)
1539     {
1540         p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_EVT;
1541         p_msg->data_mask = data_mask;
1542         p_msg->p_adv_data_cback = p_adv_data_cback;
1543         p_msg->p_adv_cfg = p_adv_cfg;
1544 
1545         bta_sys_sendmsg(p_msg);
1546     }
1547 }
1548 
1549 /*******************************************************************************
1550 **
1551 ** Function         BTA_DmBleSetScanRsp
1552 **
1553 ** Description      This function is called to override the BTA scan response.
1554 **
1555 ** Parameters       Pointer to User defined ADV data structure
1556 **
1557 ** Returns          None
1558 **
1559 *******************************************************************************/
BTA_DmBleSetScanRsp(tBTA_BLE_AD_MASK data_mask,tBTA_BLE_ADV_DATA * p_adv_cfg,tBTA_SET_ADV_DATA_CMPL_CBACK * p_adv_data_cback)1560 BTA_API extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
1561                         tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
1562 {
1563     tBTA_DM_API_SET_ADV_CONFIG  *p_msg;
1564 
1565     if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
1566         GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL)
1567     {
1568         p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_EVT;
1569         p_msg->data_mask = data_mask;
1570         p_msg->p_adv_data_cback = p_adv_data_cback;
1571         p_msg->p_adv_cfg = p_adv_cfg;
1572 
1573         bta_sys_sendmsg(p_msg);
1574     }
1575 }
1576 
1577 /*******************************************************************************
1578 **
1579 ** Function         BTA_DmBleSetStorageParams
1580 **
1581 ** Description      This function is called to override the BTA scan response.
1582 **
1583 ** Parameters       batch_scan_full_max -Max storage space (in %) allocated to full scanning
1584 **                  batch_scan_trunc_max -Max storage space (in %) allocated to truncated scanning
1585 **                  batch_scan_notify_threshold -Setup notification level based on total space
1586 **                  p_setup_cback - Setup callback pointer
1587 **                  p_thres_cback - Threshold callback pointer
1588 **                  p_rep_cback - Reports callback pointer
1589 **                  ref_value - Ref value
1590 **
1591 ** Returns          None
1592 **
1593 *******************************************************************************/
BTA_DmBleSetStorageParams(UINT8 batch_scan_full_max,UINT8 batch_scan_trunc_max,UINT8 batch_scan_notify_threshold,tBTA_BLE_SCAN_SETUP_CBACK * p_setup_cback,tBTA_BLE_SCAN_THRESHOLD_CBACK * p_thres_cback,tBTA_BLE_SCAN_REP_CBACK * p_rep_cback,tBTA_DM_BLE_REF_VALUE ref_value)1594 BTA_API extern void BTA_DmBleSetStorageParams(UINT8 batch_scan_full_max,
1595                                          UINT8 batch_scan_trunc_max,
1596                                          UINT8 batch_scan_notify_threshold,
1597                                          tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback,
1598                                          tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback,
1599                                          tBTA_BLE_SCAN_REP_CBACK* p_rep_cback,
1600                                          tBTA_DM_BLE_REF_VALUE ref_value)
1601 {
1602     tBTA_DM_API_SET_STORAGE_CONFIG  *p_msg;
1603     bta_dm_cb.p_setup_cback = p_setup_cback;
1604     if ((p_msg = (tBTA_DM_API_SET_STORAGE_CONFIG *)
1605           GKI_getbuf(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG))) != NULL)
1606     {
1607         p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT;
1608         p_msg->p_setup_cback=bta_ble_scan_setup_cb;
1609         p_msg->p_thres_cback=p_thres_cback;
1610         p_msg->p_read_rep_cback=p_rep_cback;
1611         p_msg->ref_value = ref_value;
1612         p_msg->batch_scan_full_max = batch_scan_full_max;
1613         p_msg->batch_scan_trunc_max = batch_scan_trunc_max;
1614         p_msg->batch_scan_notify_threshold = batch_scan_notify_threshold;
1615         bta_sys_sendmsg(p_msg);
1616     }
1617 }
1618 
1619 /*******************************************************************************
1620 **
1621 ** Function         BTA_DmBleEnableBatchScan
1622 **
1623 ** Description      This function is called to enable the batch scan
1624 **
1625 ** Parameters       scan_mode -Batch scan mode
1626 **                  scan_interval - Scan interval
1627 **                  scan_window - Scan window
1628 **                  discard_rule -Discard rules
1629 **                  addr_type - Address type
1630 **                  ref_value - Reference value
1631 **
1632 ** Returns          None
1633 **
1634 *******************************************************************************/
BTA_DmBleEnableBatchScan(tBTA_BLE_SCAN_MODE scan_mode,UINT32 scan_interval,UINT32 scan_window,tBTA_BLE_DISCARD_RULE discard_rule,tBLE_ADDR_TYPE addr_type,tBTA_DM_BLE_REF_VALUE ref_value)1635 BTA_API extern void BTA_DmBleEnableBatchScan(tBTA_BLE_SCAN_MODE scan_mode,
1636                                          UINT32 scan_interval, UINT32 scan_window,
1637                                          tBTA_BLE_DISCARD_RULE discard_rule,
1638                                          tBLE_ADDR_TYPE        addr_type,
1639                                          tBTA_DM_BLE_REF_VALUE ref_value)
1640 {
1641     tBTA_DM_API_ENABLE_SCAN  *p_msg;
1642 
1643     if ((p_msg = (tBTA_DM_API_ENABLE_SCAN *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE_SCAN))) != NULL)
1644     {
1645         p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT;
1646         p_msg->scan_mode = scan_mode;
1647         p_msg->scan_int = scan_interval;
1648         p_msg->scan_window = scan_window;
1649         p_msg->discard_rule = discard_rule;
1650         p_msg->addr_type = addr_type;
1651         p_msg->ref_value = ref_value;
1652         bta_sys_sendmsg(p_msg);
1653     }
1654 }
1655 
1656 /*******************************************************************************
1657 **
1658 ** Function         BTA_DmBleDisableBatchScan
1659 **
1660 ** Description      This function is called to disable the batch scan
1661 **
1662 ** Parameters       ref_value - Reference value
1663 **
1664 ** Returns          None
1665 **
1666 *******************************************************************************/
BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)1667 BTA_API extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)
1668 {
1669     tBTA_DM_API_DISABLE_SCAN  *p_msg;
1670 
1671     if ((p_msg = (tBTA_DM_API_DISABLE_SCAN *)
1672          GKI_getbuf(sizeof(tBTA_DM_API_DISABLE_SCAN))) != NULL)
1673     {
1674         p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT;
1675         p_msg->ref_value = ref_value;
1676         bta_sys_sendmsg(p_msg);
1677     }
1678 }
1679 
1680 /*******************************************************************************
1681 **
1682 ** Function         BTA_DmBleReadScanReports
1683 **
1684 ** Description      This function is called to read scan reports
1685 **
1686 ** Parameters       scan_type -Batch scan mode
1687 **                  ref_value - Reference value
1688 **
1689 ** Returns          None
1690 **
1691 *******************************************************************************/
BTA_DmBleReadScanReports(tBTA_BLE_SCAN_MODE scan_type,tBTA_DM_BLE_REF_VALUE ref_value)1692 BTA_API extern void BTA_DmBleReadScanReports(tBTA_BLE_SCAN_MODE scan_type,
1693                                              tBTA_DM_BLE_REF_VALUE ref_value)
1694 {
1695     tBTA_DM_API_READ_SCAN_REPORTS  *p_msg;
1696 
1697     if ((p_msg = (tBTA_DM_API_READ_SCAN_REPORTS *)
1698           GKI_getbuf(sizeof(tBTA_DM_API_READ_SCAN_REPORTS))) != NULL)
1699     {
1700         p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT;
1701         p_msg->scan_type = scan_type;
1702         p_msg->ref_value = ref_value;
1703         bta_sys_sendmsg(p_msg);
1704     }
1705 }
1706 
1707 /*******************************************************************************
1708 **
1709 ** Function         BTA_DmBleTrackAdvertiser
1710 **
1711 ** Description      This function is called to track advertiser
1712 **
1713 ** Parameters       ref_value - Reference value
1714 **                  p_track_adv_cback - Track ADV callback
1715 **
1716 ** Returns          None
1717 **
1718 *******************************************************************************/
BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,tBTA_BLE_TRACK_ADV_CBACK * p_track_adv_cback)1719 BTA_API extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
1720                             tBTA_BLE_TRACK_ADV_CBACK *p_track_adv_cback)
1721 {
1722     tBTA_DM_API_TRACK_ADVERTISER  *p_msg;
1723 
1724     if ((p_msg = (tBTA_DM_API_TRACK_ADVERTISER *)
1725          GKI_getbuf(sizeof(tBTA_DM_API_TRACK_ADVERTISER))) != NULL)
1726     {
1727         p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT;
1728         p_msg->p_track_adv_cback = p_track_adv_cback;
1729         p_msg->ref_value = ref_value;
1730         bta_sys_sendmsg(p_msg);
1731     }
1732 }
1733 
1734 /*******************************************************************************
1735 **
1736 ** Function         BTA_DmBleBroadcast
1737 **
1738 ** Description      This function starts or stops LE broadcasting.
1739 **
1740 ** Parameters       start: start or stop broadcast.
1741 **
1742 ** Returns          None
1743 **
1744 *******************************************************************************/
BTA_DmBleBroadcast(BOOLEAN start)1745 BTA_API extern void BTA_DmBleBroadcast (BOOLEAN start)
1746 {
1747     tBTA_DM_API_BLE_OBSERVE   *p_msg;
1748 
1749     APPL_TRACE_API("BTA_DmBleBroadcast: start = %d ", start);
1750 
1751     if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL)
1752     {
1753         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
1754 
1755         p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
1756         p_msg->start = start;
1757 
1758         bta_sys_sendmsg(p_msg);
1759     }
1760 }
1761 
1762 #endif
1763 /*******************************************************************************
1764 **
1765 ** Function         BTA_DmBleSetBgConnType
1766 **
1767 ** Description      This function is called to set BLE connectable mode for a
1768 **                  peripheral device.
1769 **
1770 ** Parameters       bg_conn_type: it can be auto connection, or selective connection.
1771 **                  p_select_cback: callback function when selective connection procedure
1772 **                              is being used.
1773 **
1774 ** Returns          void
1775 **
1776 *******************************************************************************/
BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type,tBTA_DM_BLE_SEL_CBACK * p_select_cback)1777 void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback)
1778 {
1779 #if BLE_INCLUDED == TRUE
1780     tBTA_DM_API_BLE_SET_BG_CONN_TYPE    *p_msg;
1781 
1782     if ((p_msg = (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE))) != NULL)
1783     {
1784         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
1785 
1786         p_msg->hdr.event        = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
1787         p_msg->bg_conn_type     = bg_conn_type;
1788         p_msg->p_select_cback   = p_select_cback;
1789 
1790         bta_sys_sendmsg(p_msg);
1791     }
1792 #endif
1793 }
1794 
1795 /*******************************************************************************
1796 **
1797 ** Function         bta_dm_discover_send_msg
1798 **
1799 ** Description      This function send discover message to BTA task.
1800 **
1801 ** Returns          void
1802 **
1803 *******************************************************************************/
bta_dm_discover_send_msg(BD_ADDR bd_addr,tBTA_SERVICE_MASK_EXT * p_services,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search,tBTA_TRANSPORT transport)1804 static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1805                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
1806                     tBTA_TRANSPORT transport)
1807 {
1808     tBTA_DM_API_DISCOVER    *p_msg;
1809     UINT16  len = p_services ? (sizeof(tBTA_DM_API_DISCOVER) +
1810                                 sizeof(tBT_UUID) * p_services->num_uuid) :
1811                                 sizeof(tBTA_DM_API_DISCOVER);
1812 
1813     if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(len)) != NULL)
1814     {
1815         memset(p_msg, 0, len);
1816 
1817         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
1818         bdcpy(p_msg->bd_addr, bd_addr);
1819         p_msg->p_cback = p_cback;
1820         p_msg->sdp_search = sdp_search;
1821         p_msg->transport    = transport;
1822 
1823         if (p_services != NULL)
1824         {
1825 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1826             p_msg->services = p_services->srvc_mask;
1827             p_msg->num_uuid = p_services->num_uuid;
1828             if (p_services->num_uuid != 0)
1829             {
1830                 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1831                 memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
1832             }
1833 #endif
1834         }
1835 
1836         bta_sys_sendmsg(p_msg);
1837     }
1838 }
1839 
1840 /*******************************************************************************
1841 **
1842 ** Function         BTA_DmDiscoverByTransport
1843 **
1844 ** Description      This function does service discovery on particular transport
1845 **                  for services of a
1846 **                  peer device. When services.num_uuid is 0, it indicates all
1847 **                  GATT based services are to be searched; otherwise a list of
1848 **                  UUID of interested services should be provided through
1849 **                  p_services->p_uuid.
1850 **
1851 ** Parameters       bd_addr: Bluetooth address of remote device
1852 **                  p_services :bit mask of the list of services to be discovered
1853 **                  p_cback : Callback on which result will be received
1854 **                  sdp_search: if TRUE SDP search will be initiated, else services present in
1855 **                                     EIR structure of remote device will be returned.
1856 **                  transport : Physical transport BR/EDR or LE
1857 ** Returns          void
1858 **
1859 *******************************************************************************/
1860 
BTA_DmDiscoverByTransport(BD_ADDR bd_addr,tBTA_SERVICE_MASK_EXT * p_services,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search,tBTA_TRANSPORT transport)1861 void BTA_DmDiscoverByTransport(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1862                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
1863                     tBTA_TRANSPORT transport)
1864 {
1865     bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
1866 }
1867 
1868 
1869 /*******************************************************************************
1870 **
1871 ** Function         BTA_DmDiscoverExt
1872 **
1873 ** Description      This function does service discovery for services of a
1874 **                  peer device. When services.num_uuid is 0, it indicates all
1875 **                  GATT based services are to be searched; other wise a list of
1876 **                  UUID of interested services should be provided through
1877 **                  p_services->p_uuid.
1878 **
1879 ** Parameters       bd_addr: Bluetooth address of remote device
1880 **                  p_services :bit mask of the list of services to be discovered
1881 **                  p_cback : Callback on which result will be received
1882 **                  sdp_search: if TRUE SDP search will be initiated, else services present in
1883 **                                     EIR structure of remote device will be returned.
1884 **
1885 ** Returns          void
1886 **
1887 *******************************************************************************/
BTA_DmDiscoverExt(BD_ADDR bd_addr,tBTA_SERVICE_MASK_EXT * p_services,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search)1888 void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1889                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
1890 {
1891     bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, BTA_TRANSPORT_UNKNOWN);
1892 
1893 }
1894 
1895 /*******************************************************************************
1896 **
1897 ** Function         BTA_DmSearchExt
1898 **
1899 ** Description      This function searches for peer Bluetooth devices. It performs
1900 **                  an inquiry and gets the remote name for devices. Service
1901 **                  discovery is done if services is non zero
1902 **
1903 ** Parameters       p_dm_inq: inquiry conditions
1904 **                  p_services: if service is not empty, service discovery will be done.
1905 **                            for all GATT based service condition, put num_uuid, and
1906 **                            p_uuid is the pointer to the list of UUID values.
1907 **                  p_cback: callback functino when search is completed.
1908 **
1909 **
1910 **
1911 ** Returns          void
1912 **
1913 *******************************************************************************/
BTA_DmSearchExt(tBTA_DM_INQ * p_dm_inq,tBTA_SERVICE_MASK_EXT * p_services,tBTA_DM_SEARCH_CBACK * p_cback)1914 void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback)
1915 {
1916 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1917     tBTA_DM_API_SEARCH    *p_msg;
1918     UINT16  len = p_services ? (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid) :
1919                     sizeof(tBTA_DM_API_SEARCH);
1920 
1921     if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(len)) != NULL)
1922     {
1923         memset(p_msg, 0, len);
1924 
1925         p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
1926         memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
1927         p_msg->p_cback = p_cback;
1928         p_msg->rs_res  = BTA_DM_RS_NONE;
1929 
1930 
1931         if (p_services != NULL)
1932         {
1933             p_msg->services = p_services->srvc_mask;
1934             p_msg->num_uuid = p_services->num_uuid;
1935 
1936             if (p_services->num_uuid != 0)
1937             {
1938                 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1939                 memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
1940             }
1941             else
1942                 p_msg->p_uuid = NULL;
1943         }
1944 
1945         bta_sys_sendmsg(p_msg);
1946     }
1947 #else
1948     UNUSED(p_dm_inq);
1949     UNUSED(p_services);
1950     UNUSED(p_cback);
1951 #endif
1952 }
1953 
1954 /*******************************************************************************
1955 **
1956 ** Function         BTA_DmBleEnableRemotePrivacy
1957 **
1958 ** Description      Enable/disable privacy on a remote device
1959 **
1960 ** Parameters:      bd_addr          - BD address of the peer
1961 **                  privacy_enable   - enable/disabe privacy on remote device.
1962 **
1963 ** Returns          void
1964 **
1965 *******************************************************************************/
BTA_DmBleEnableRemotePrivacy(BD_ADDR bd_addr,BOOLEAN privacy_enable)1966 void BTA_DmBleEnableRemotePrivacy(BD_ADDR bd_addr, BOOLEAN privacy_enable)
1967 {
1968     UNUSED(bd_addr);
1969     UNUSED(privacy_enable);
1970 }
1971 
1972 
1973 /*******************************************************************************
1974 **
1975 ** Function         BTA_DmBleConfigLocalPrivacy
1976 **
1977 ** Description      Enable/disable privacy on the local device
1978 **
1979 ** Parameters:      privacy_enable   - enable/disabe privacy on remote device.
1980 **
1981 ** Returns          void
1982 **
1983 *******************************************************************************/
BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable)1984 void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable)
1985 {
1986 #if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE
1987     tBTA_DM_API_LOCAL_PRIVACY *p_msg;
1988 
1989     if ((p_msg = (tBTA_DM_API_LOCAL_PRIVACY *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE_PRIVACY))) != NULL)
1990     {
1991         memset (p_msg, 0, sizeof(tBTA_DM_API_LOCAL_PRIVACY));
1992 
1993         p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
1994         p_msg->privacy_enable   = privacy_enable;
1995 
1996         bta_sys_sendmsg(p_msg);
1997     }
1998 #else
1999     UNUSED (privacy_enable);
2000 #endif
2001 }
2002 
2003 #if BLE_INCLUDED == TRUE
2004 /*******************************************************************************
2005 **
2006 ** Function         BTA_BleEnableAdvInstance
2007 **
2008 ** Description      This function enable a Multi-ADV instance with the specififed
2009 **                  adv parameters
2010 **
2011 ** Parameters       p_params: pointer to the adv parameter structure.
2012 **                  p_cback: callback function associated to this adv instance.
2013 **                  p_ref: reference data pointer to this adv instance.
2014 **
2015 ** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
2016 **
2017 *******************************************************************************/
BTA_BleEnableAdvInstance(tBTA_BLE_ADV_PARAMS * p_params,tBTA_BLE_MULTI_ADV_CBACK * p_cback,void * p_ref)2018 void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
2019                                 tBTA_BLE_MULTI_ADV_CBACK *p_cback,
2020                                 void *p_ref)
2021 {
2022     tBTA_DM_API_BLE_MULTI_ADV_ENB    *p_msg;
2023     UINT16 len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB);
2024 
2025     APPL_TRACE_API ("BTA_BleEnableAdvInstance");
2026 
2027     if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_ENB *) GKI_getbuf(len)) != NULL)
2028     {
2029         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB));
2030 
2031         p_msg->hdr.event     = BTA_DM_API_BLE_MULTI_ADV_ENB_EVT;
2032         p_msg->p_cback      = (void *)p_cback;
2033         if (p_params != NULL)
2034         {
2035             p_msg->p_params =  (void *)(p_msg + 1);
2036             memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
2037         }
2038         p_msg->p_ref        = p_ref;
2039 
2040         bta_sys_sendmsg(p_msg);
2041     }
2042 }
2043 
2044 /*******************************************************************************
2045 **
2046 ** Function         BTA_BleUpdateAdvInstParam
2047 **
2048 ** Description      This function update a Multi-ADV instance with the specififed
2049 **                  adv parameters.
2050 **
2051 ** Parameters       inst_id: Adv instance to update the parameter.
2052 **                  p_params: pointer to the adv parameter structure.
2053 **
2054 ** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
2055 **
2056 *******************************************************************************/
BTA_BleUpdateAdvInstParam(UINT8 inst_id,tBTA_BLE_ADV_PARAMS * p_params)2057 void BTA_BleUpdateAdvInstParam (UINT8 inst_id, tBTA_BLE_ADV_PARAMS *p_params)
2058 {
2059     tBTA_DM_API_BLE_MULTI_ADV_PARAM    *p_msg;
2060     UINT16      len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM);
2061 
2062     APPL_TRACE_API ("BTA_BleUpdateAdvInstParam");
2063      if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_PARAM *) GKI_getbuf(len)) != NULL)
2064      {
2065           memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM));
2066           p_msg->hdr.event     = BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT;
2067           p_msg->inst_id        = inst_id;
2068           p_msg->p_params =  (void *)(p_msg + 1);
2069           memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
2070 
2071           bta_sys_sendmsg(p_msg);
2072     }
2073 }
2074 
2075 /*******************************************************************************
2076 **
2077 ** Function         BTA_BleCfgAdvInstData
2078 **
2079 ** Description      This function configure a Multi-ADV instance with the specififed
2080 **                  adv data or scan response data.
2081 **
2082 ** Parameter        inst_id: Adv instance to configure the adv data or scan response.
2083 **                  is_scan_rsp: is the data scan response or adv data.
2084 **                  data_mask: adv data type as bit mask.
2085 **                  p_data: pointer to the ADV data structure tBTA_BLE_ADV_DATA. This
2086 **                  memory space can not be freed until BTA_BLE_MULTI_ADV_DATA_EVT
2087 **                  is sent to application.
2088 **
2089 ** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
2090 **
2091 *******************************************************************************/
BTA_BleCfgAdvInstData(UINT8 inst_id,BOOLEAN is_scan_rsp,tBTA_BLE_AD_MASK data_mask,tBTA_BLE_ADV_DATA * p_data)2092 void BTA_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp,
2093                             tBTA_BLE_AD_MASK data_mask,
2094                             tBTA_BLE_ADV_DATA *p_data)
2095 {
2096     tBTA_DM_API_BLE_MULTI_ADV_DATA    *p_msg;
2097     UINT16      len =  sizeof(tBTA_DM_API_BLE_MULTI_ADV_DATA) ;
2098 
2099     APPL_TRACE_API ("BTA_BleCfgAdvInstData");
2100 
2101     if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DATA *) GKI_getbuf(len)) != NULL)
2102     {
2103           memset(p_msg, 0, len);
2104           p_msg->hdr.event     = BTA_DM_API_BLE_MULTI_ADV_DATA_EVT;
2105           p_msg->inst_id      = inst_id;
2106           p_msg->is_scan_rsp  = is_scan_rsp;
2107           p_msg->data_mask     = data_mask;
2108           p_msg->p_data        = p_data;
2109 
2110           bta_sys_sendmsg(p_msg);
2111     }
2112 }
2113 
2114 /*******************************************************************************
2115 **
2116 ** Function         BTA_BleDisableAdvInstance
2117 **
2118 ** Description      This function disable a Multi-ADV instance.
2119 **
2120 ** Parameter        inst_id: instance ID to disable.
2121 **
2122 ** Returns          BTA_SUCCESS if command started sucessfully; otherwise failure.
2123 **
2124 *******************************************************************************/
BTA_BleDisableAdvInstance(UINT8 inst_id)2125 void BTA_BleDisableAdvInstance (UINT8  inst_id)
2126 {
2127     tBTA_DM_API_BLE_MULTI_ADV_DISABLE    *p_msg;
2128 
2129     APPL_TRACE_API ("BTA_BleDisableAdvInstance: %d", inst_id);
2130     if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DISABLE *)
2131           GKI_getbuf(sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE))) != NULL)
2132     {
2133          memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE));
2134          p_msg->hdr.event    = BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT;
2135          p_msg->inst_id      = inst_id;
2136          bta_sys_sendmsg(p_msg);
2137     }
2138 }
2139 
2140 /*******************************************************************************
2141 **
2142 ** Function         BTA_DmBleCfgFilterCondition
2143 **
2144 ** Description      This function is called to configure the adv data payload filter
2145 **                  condition.
2146 **
2147 ** Parameters       action: to read/write/clear
2148 **                  cond_type: filter condition type
2149 **                  filt_index - Filter index
2150 **                  p_cond: filter condition parameter
2151 **                  p_cmpl_back - Command completed callback
2152 **                  ref_value - Reference value
2153 **
2154 ** Returns          void
2155 **
2156 *******************************************************************************/
BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,tBTA_DM_BLE_PF_COND_TYPE cond_type,tBTA_DM_BLE_PF_FILT_INDEX filt_index,tBTA_DM_BLE_PF_COND_PARAM * p_cond,tBTA_DM_BLE_PF_CFG_CBACK * p_cmpl_cback,tBTA_DM_BLE_REF_VALUE ref_value)2157 void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
2158                                  tBTA_DM_BLE_PF_COND_TYPE cond_type,
2159                                  tBTA_DM_BLE_PF_FILT_INDEX filt_index,
2160                                  tBTA_DM_BLE_PF_COND_PARAM *p_cond,
2161                                  tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback,
2162                                  tBTA_DM_BLE_REF_VALUE ref_value)
2163 {
2164 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
2165     tBTA_DM_API_CFG_FILTER_COND *p_msg;
2166     APPL_TRACE_API ("BTA_DmBleCfgFilterCondition: %d, %d", action, cond_type);
2167 
2168     UINT16  len = sizeof(tBTA_DM_API_CFG_FILTER_COND) +
2169                   sizeof(tBTA_DM_BLE_PF_COND_PARAM);
2170     UINT8 *p;
2171 
2172     if (NULL != p_cond)
2173     {
2174         switch(cond_type)
2175         {
2176             case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:
2177             case BTA_DM_BLE_PF_MANU_DATA:
2178                 /* Length of pattern and pattern mask and other elements in */
2179                 /* tBTA_DM_BLE_PF_MANU_COND */
2180                 len += ((p_cond->manu_data.data_len) * 2) +
2181                         sizeof(UINT16) + sizeof(UINT16) + sizeof(UINT8);
2182                 break;
2183 
2184             case BTA_DM_BLE_PF_LOCAL_NAME:
2185                 len += ((p_cond->local_name.data_len) + sizeof(UINT8));
2186                 break;
2187 
2188             case BTM_BLE_PF_SRVC_UUID:
2189             case BTM_BLE_PF_SRVC_SOL_UUID:
2190                 len += sizeof(tBLE_BD_ADDR) + sizeof(tBTA_DM_BLE_PF_COND_MASK);
2191                 break;
2192 
2193             default:
2194                 break;
2195         }
2196     }
2197 
2198     if ((p_msg = (tBTA_DM_API_CFG_FILTER_COND *) GKI_getbuf(len)) != NULL)
2199     {
2200         memset (p_msg, 0, len);
2201         p_msg->hdr.event        = BTA_DM_API_CFG_FILTER_COND_EVT;
2202         p_msg->action           = action;
2203         p_msg->cond_type        = cond_type;
2204         p_msg->filt_index       = filt_index;
2205         p_msg->p_filt_cfg_cback = p_cmpl_cback;
2206         p_msg->ref_value        = ref_value;
2207 
2208         if (p_cond)
2209         {
2210             p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM *)(p_msg + 1);
2211             memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
2212 
2213             p = (UINT8 *)(p_msg->p_cond_param + 1);
2214 
2215             if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN ||
2216                 cond_type == BTA_DM_BLE_PF_MANU_DATA)
2217             {
2218                 p_msg->p_cond_param->manu_data.p_pattern = p;
2219                 p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len;
2220                 memcpy(p_msg->p_cond_param->manu_data.p_pattern, p_cond->manu_data.p_pattern,
2221                     p_cond->manu_data.data_len);
2222                 p += p_cond->manu_data.data_len;
2223 
2224                 if (cond_type == BTA_DM_BLE_PF_MANU_DATA)
2225                 {
2226                     p_msg->p_cond_param->manu_data.company_id_mask =
2227                         p_cond->manu_data.company_id_mask;
2228                     if ( p_cond->manu_data.p_pattern_mask != NULL)
2229                     {
2230                         p_msg->p_cond_param->manu_data.p_pattern_mask = p;
2231                         memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask,
2232                             p_cond->manu_data.p_pattern_mask, p_cond->manu_data.data_len);
2233                     }
2234                 }
2235             }
2236             else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME)
2237             {
2238                 p_msg->p_cond_param->local_name.p_data = p;
2239                 p_msg->p_cond_param->local_name.data_len =
2240                     p_cond->local_name.data_len;
2241                 memcpy(p_msg->p_cond_param->local_name.p_data,
2242                     p_cond->local_name.p_data, p_cond->local_name.data_len);
2243             }
2244             else if ((cond_type == BTM_BLE_PF_SRVC_UUID
2245                 || cond_type == BTM_BLE_PF_SRVC_SOL_UUID))
2246             {
2247                 if (p_cond->srvc_uuid.p_target_addr != NULL)
2248                 {
2249                     p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR *)(p);
2250                     p_msg->p_cond_param->srvc_uuid.p_target_addr->type =
2251                         p_cond->srvc_uuid.p_target_addr->type;
2252                     memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda,
2253                         p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN);
2254                     p = (UINT8*)( p_msg->p_cond_param->srvc_uuid.p_target_addr + 1);
2255                 }
2256                 if (p_cond->srvc_uuid.p_uuid_mask)
2257                 {
2258                     p_msg->p_cond_param->srvc_uuid.p_uuid_mask = (tBTA_DM_BLE_PF_COND_MASK *)p;
2259                     memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask,
2260                         p_cond->srvc_uuid.p_uuid_mask, sizeof(tBTA_DM_BLE_PF_COND_MASK));
2261                 }
2262             }
2263         }
2264 
2265         bta_sys_sendmsg(p_msg);
2266     }
2267 #else
2268     UNUSED(action);
2269     UNUSED(cond_type);
2270     UNUSED(filt_index);
2271     UNUSED(p_cond);
2272     UNUSED(p_cmpl_cback);
2273     UNUSED(ref_value);
2274 #endif
2275 }
2276 
2277 /*******************************************************************************
2278 **
2279 ** Function         BTA_DmBleScanFilterSetup
2280 **
2281 ** Description      This function is called to setup the adv data payload filter param
2282 **
2283 ** Parameters       p_target: enable the filter condition on a target device; if NULL
2284 **                  filt_index - Filter index
2285 **                  p_filt_params -Filter parameters
2286 **                  ref_value - Reference value
2287 **                  action - Add, delete or clear
2288 **                  p_cmpl_back - Command completed callback
2289 **
2290 ** Returns          void
2291 **
2292 *******************************************************************************/
BTA_DmBleScanFilterSetup(UINT8 action,tBTA_DM_BLE_PF_FILT_INDEX filt_index,tBTA_DM_BLE_PF_FILT_PARAMS * p_filt_params,tBLE_BD_ADDR * p_target,tBTA_DM_BLE_PF_PARAM_CBACK * p_cmpl_cback,tBTA_DM_BLE_REF_VALUE ref_value)2293 void BTA_DmBleScanFilterSetup(UINT8 action, tBTA_DM_BLE_PF_FILT_INDEX filt_index,
2294                                     tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params,
2295                                     tBLE_BD_ADDR *p_target,
2296                                     tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback,
2297                                     tBTA_DM_BLE_REF_VALUE ref_value)
2298 {
2299 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
2300     tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *p_msg;
2301     APPL_TRACE_API ("BTA_DmBleScanFilterSetup: %d", action);
2302 
2303     UINT16  len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) + sizeof(tBLE_BD_ADDR);
2304 
2305     if ((p_msg = (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *) GKI_getbuf(len)) != NULL)
2306     {
2307         memset (p_msg, 0, len);
2308 
2309         p_msg->hdr.event        = BTA_DM_API_SCAN_FILTER_SETUP_EVT;
2310         p_msg->action       = action;
2311         p_msg->filt_index = filt_index;
2312         p_msg->p_filt_params = p_filt_params;
2313         p_msg->p_filt_param_cback = p_cmpl_cback;
2314         p_msg->ref_value        = ref_value;
2315 
2316         if (p_target)
2317         {
2318             p_msg->p_target = (tBLE_BD_ADDR *)(p_msg + 1);
2319             memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR));
2320         }
2321 
2322         bta_sys_sendmsg(p_msg);
2323     }
2324 #else
2325     UNUSED(action);
2326     UNUSED(filt_index);
2327     UNUSED(p_filt_params);
2328     UNUSED(p_target);
2329     UNUSED(p_cmpl_cback);
2330     UNUSED(ref_value);
2331 #endif
2332 }
2333 
2334 /*******************************************************************************
2335 **
2336 ** Function         BTA_DmBleGetEnergyInfo
2337 **
2338 ** Description      This function is called to obtain the energy info
2339 **
2340 ** Parameters       p_cmpl_cback - Command complete callback
2341 **
2342 ** Returns          void
2343 **
2344 *******************************************************************************/
BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK * p_cmpl_cback)2345 void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback)
2346 {
2347     tBTA_DM_API_ENERGY_INFO *p_msg;
2348     APPL_TRACE_API ("BTA_DmBleGetEnergyInfo");
2349 
2350     UINT16  len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
2351 
2352     if ((p_msg = (tBTA_DM_API_ENERGY_INFO *) GKI_getbuf(len)) != NULL)
2353     {
2354         memset (p_msg, 0, len);
2355         p_msg->hdr.event        = BTA_DM_API_BLE_ENERGY_INFO_EVT;
2356         p_msg->p_energy_info_cback = p_cmpl_cback;
2357         bta_sys_sendmsg(p_msg);
2358     }
2359 }
2360 
2361 /*******************************************************************************
2362 **
2363 ** Function         BTA_DmEnableScanFilter
2364 **
2365 ** Description      This function is called to enable the adv data payload filter
2366 **
2367 ** Parameters       action - enable or disable the APCF feature
2368 **                  p_cmpl_cback - Command completed callback
2369 **                  ref_value - Reference value
2370 **
2371 ** Returns          void
2372 **
2373 *******************************************************************************/
BTA_DmEnableScanFilter(UINT8 action,tBTA_DM_BLE_PF_STATUS_CBACK * p_cmpl_cback,tBTA_DM_BLE_REF_VALUE ref_value)2374 void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback,
2375                                     tBTA_DM_BLE_REF_VALUE ref_value)
2376 {
2377 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
2378     tBTA_DM_API_ENABLE_SCAN_FILTER *p_msg;
2379     APPL_TRACE_API ("BTA_DmEnableScanFilter: %d", action);
2380 
2381     UINT16  len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) + sizeof(tBLE_BD_ADDR);
2382 
2383     if ((p_msg = (tBTA_DM_API_ENABLE_SCAN_FILTER *) GKI_getbuf(len)) != NULL)
2384     {
2385         memset (p_msg, 0, len);
2386 
2387         p_msg->hdr.event        = BTA_DM_API_SCAN_FILTER_ENABLE_EVT;
2388         p_msg->action       = action;
2389         p_msg->ref_value    = ref_value;
2390         p_msg->p_filt_status_cback = p_cmpl_cback;
2391 
2392         bta_sys_sendmsg(p_msg);
2393     }
2394 #else
2395     UNUSED(action);
2396     UNUSED(p_cmpl_cback);
2397     UNUSED(ref_value);
2398 #endif
2399 }
2400 
2401 /*******************************************************************************
2402 **
2403 ** Function         BTA_DmBleUpdateConnectionParams
2404 **
2405 ** Description      Update connection parameters, can only be used when connection is up.
2406 **
2407 ** Parameters:      bd_addr   - BD address of the peer
2408 **                  min_int   -     minimum connection interval, [0x0004~ 0x4000]
2409 **                  max_int   -     maximum connection interval, [0x0004~ 0x4000]
2410 **                  latency   -     slave latency [0 ~ 500]
2411 **                  timeout   -     supervision timeout [0x000a ~ 0xc80]
2412 **
2413 ** Returns          void
2414 **
2415 *******************************************************************************/
BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr,UINT16 min_int,UINT16 max_int,UINT16 latency,UINT16 timeout)2416 void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max_int,
2417                                     UINT16 latency, UINT16 timeout)
2418 {
2419     tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
2420 
2421     if ((p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM))) != NULL)
2422     {
2423         memset (p_msg, 0, sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
2424 
2425         p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
2426         bdcpy(p_msg->bd_addr, bd_addr);
2427         p_msg->min_int   = min_int;
2428         p_msg->max_int   = max_int;
2429         p_msg->latency   = latency;
2430         p_msg->timeout   = timeout;
2431 
2432         bta_sys_sendmsg(p_msg);
2433     }
2434 }
2435 #endif
2436 
2437 /*******************************************************************************
2438 **
2439 ** Function         BTA_DmSetEncryption
2440 **
2441 ** Description      This function is called to ensure that connection is
2442 **                  encrypted.  Should be called only on an open connection.
2443 **                  Typically only needed for connections that first want to
2444 **                  bring up unencrypted links, then later encrypt them.
2445 **
2446 ** Parameters:      bd_addr       - Address of the peer device
2447 **                  transport     - transport of the link to be encruypted
2448 **                  p_callback    - Pointer to callback function to indicat the
2449 **                                  link encryption status
2450 **                  sec_act       - This is the security action to indicate
2451 **                                  what knid of BLE security level is required for
2452 **                                  the BLE link if the BLE is supported
2453 **                                  Note: This parameter is ignored for the BR/EDR link
2454 **                                        or the BLE is not supported
2455 **
2456 ** Returns          void
2457 **
2458 *******************************************************************************/
BTA_DmSetEncryption(BD_ADDR bd_addr,tBTA_TRANSPORT transport,tBTA_DM_ENCRYPT_CBACK * p_callback,tBTA_DM_BLE_SEC_ACT sec_act)2459 void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCRYPT_CBACK *p_callback,
2460                             tBTA_DM_BLE_SEC_ACT sec_act)
2461 {
2462     tBTA_DM_API_SET_ENCRYPTION   *p_msg;
2463 
2464     APPL_TRACE_API("BTA_DmSetEncryption"); //todo
2465     if ((p_msg = (tBTA_DM_API_SET_ENCRYPTION *) GKI_getbuf(sizeof(tBTA_DM_API_SET_ENCRYPTION))) != NULL)
2466     {
2467         memset(p_msg, 0, sizeof(tBTA_DM_API_SET_ENCRYPTION));
2468 
2469         p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
2470 
2471         memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
2472         p_msg->transport    = transport;
2473         p_msg->p_callback      = p_callback;
2474         p_msg->sec_act         = sec_act;
2475 
2476         bta_sys_sendmsg(p_msg);
2477     }
2478 }
2479 
2480 /*******************************************************************************
2481 **
2482 ** Function         BTA_DmCloseACL
2483 **
2484 ** Description      This function force to close an ACL connection and remove the
2485 **                  device from the security database list of known devices.
2486 **
2487 ** Parameters:      bd_addr       - Address of the peer device
2488 **                  remove_dev    - remove device or not after link down
2489 **
2490 ** Returns          void
2491 **
2492 *******************************************************************************/
BTA_DmCloseACL(BD_ADDR bd_addr,BOOLEAN remove_dev,tBTA_TRANSPORT transport)2493 void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT transport)
2494 {
2495     tBTA_DM_API_REMOVE_ACL   *p_msg;
2496 
2497     APPL_TRACE_API("BTA_DmCloseACL");
2498 
2499     if ((p_msg = (tBTA_DM_API_REMOVE_ACL *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_ACL))) != NULL)
2500     {
2501         memset(p_msg, 0, sizeof(tBTA_DM_API_REMOVE_ACL));
2502 
2503         p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
2504 
2505         memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
2506         p_msg->remove_dev      = remove_dev;
2507         p_msg->transport       = transport;
2508 
2509         bta_sys_sendmsg(p_msg);
2510     }
2511 }
2512 
2513 #if BLE_INCLUDED == TRUE
2514 /*******************************************************************************
2515 **
2516 ** Function         BTA_DmBleObserve
2517 **
2518 ** Description      This procedure keep the device listening for advertising
2519 **                  events from a broadcast device.
2520 **
2521 ** Parameters       start: start or stop observe.
2522 **
2523 ** Returns          void
2524 
2525 **
2526 ** Returns          void.
2527 **
2528 *******************************************************************************/
BTA_DmBleObserve(BOOLEAN start,UINT8 duration,tBTA_DM_SEARCH_CBACK * p_results_cb)2529 BTA_API extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
2530                                      tBTA_DM_SEARCH_CBACK *p_results_cb)
2531 {
2532     tBTA_DM_API_BLE_OBSERVE   *p_msg;
2533 
2534     APPL_TRACE_API("BTA_DmBleObserve:start = %d ", start);
2535 
2536     if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL)
2537     {
2538         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
2539 
2540         p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
2541         p_msg->start = start;
2542         p_msg->duration = duration;
2543         p_msg->p_cback = p_results_cb;
2544 
2545         bta_sys_sendmsg(p_msg);
2546     }
2547 }
2548 
2549 /*******************************************************************************
2550 **
2551 ** Function         BTA_VendorInit
2552 **
2553 ** Description      This function initializes vendor specific
2554 **
2555 ** Returns          void
2556 **
2557 *******************************************************************************/
BTA_VendorInit(void)2558 void BTA_VendorInit (void)
2559 {
2560     APPL_TRACE_API("BTA_VendorInit");
2561 }
2562 
2563 /*******************************************************************************
2564 **
2565 ** Function         BTA_VendorCleanup
2566 **
2567 ** Description      This function frees up Broadcom specific VS specific dynamic memory
2568 **
2569 ** Returns          void
2570 **
2571 *******************************************************************************/
BTA_VendorCleanup(void)2572 void BTA_VendorCleanup (void)
2573 {
2574     tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
2575     BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
2576 
2577 #if (BLE_INCLUDED == TRUE && BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
2578     if (cmn_ble_vsc_cb.max_filter > 0)
2579     {
2580         btm_ble_adv_filter_cleanup();
2581         btm_ble_vendor_cleanup();
2582     }
2583 
2584     if (cmn_ble_vsc_cb.tot_scan_results_strg > 0)
2585         btm_ble_batchscan_cleanup();
2586 #endif
2587 
2588    if(cmn_ble_vsc_cb.adv_inst_max > 0)
2589       btm_ble_multi_adv_cleanup();
2590 }
2591 
2592 #endif
2593