• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2003-2012 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 
35 /*****************************************************************************
36 **  Constants
37 *****************************************************************************/
38 
39 static const tBTA_SYS_REG bta_dm_reg =
40 {
41     bta_dm_sm_execute,
42     bta_dm_sm_disable
43 };
44 
45 static const tBTA_SYS_REG bta_dm_search_reg =
46 {
47     bta_dm_search_sm_execute,
48     bta_dm_search_sm_disable
49 };
50 
51 /*******************************************************************************
52 **
53 ** Function         BTA_EnableBluetooth
54 **
55 ** Description      Enables bluetooth service.  This function must be
56 **                  called before any other functions in the BTA API are called.
57 **
58 **
59 ** Returns          tBTA_STATUS
60 **
61 *******************************************************************************/
BTA_EnableBluetooth(tBTA_DM_SEC_CBACK * p_cback)62 tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
63 {
64 
65     tBTA_DM_API_ENABLE    *p_msg;
66 
67     /* Bluetooth disabling is in progress */
68     if (bta_dm_cb.disabling)
69         return BTA_FAILURE;
70 
71     memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
72 
73     GKI_sched_lock();
74     bta_sys_register (BTA_ID_DM, &bta_dm_reg );
75     bta_sys_register (BTA_ID_DM_SEARCH, &bta_dm_search_reg );
76 
77     /* if UUID list is not provided as static data */
78     bta_sys_eir_register(bta_dm_eir_update_uuid);
79 
80     GKI_sched_unlock();
81 
82     if ((p_msg = (tBTA_DM_API_ENABLE *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE))) != NULL)
83     {
84         p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
85         p_msg->p_sec_cback = p_cback;
86         bta_sys_sendmsg(p_msg);
87         return BTA_SUCCESS;
88     }
89     return BTA_FAILURE;
90 
91 }
92 
93 /*******************************************************************************
94 **
95 ** Function         BTA_DisableBluetooth
96 **
97 ** Description      Disables bluetooth service.  This function is called when
98 **                  the application no longer needs bluetooth service
99 **
100 ** Returns          void
101 **
102 *******************************************************************************/
BTA_DisableBluetooth(void)103 tBTA_STATUS BTA_DisableBluetooth(void)
104 {
105 
106     BT_HDR    *p_msg;
107 
108     if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
109     {
110         p_msg->event = BTA_DM_API_DISABLE_EVT;
111         bta_sys_sendmsg(p_msg);
112     }
113     else
114     {
115         return BTA_FAILURE;
116     }
117 
118     return BTA_SUCCESS;
119 }
120 
121 /*******************************************************************************
122 **
123 ** Function         BTA_EnableTestMode
124 **
125 ** Description      Enables bluetooth device under test mode
126 **
127 **
128 ** Returns          tBTA_STATUS
129 **
130 *******************************************************************************/
BTA_EnableTestMode(void)131 tBTA_STATUS BTA_EnableTestMode(void)
132 {
133     BT_HDR    *p_msg;
134 
135     APPL_TRACE_API0("BTA_EnableTestMode");
136 
137     if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
138     {
139         p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
140         bta_sys_sendmsg(p_msg);
141         return BTA_SUCCESS;
142     }
143     return BTA_FAILURE;
144 }
145 
146 /*******************************************************************************
147 **
148 ** Function         BTA_DisableTestMode
149 **
150 ** Description      Disable bluetooth device under test mode
151 **
152 **
153 ** Returns          None
154 **
155 *******************************************************************************/
BTA_DisableTestMode(void)156 void BTA_DisableTestMode(void)
157 {
158     BT_HDR    *p_msg;
159 
160     APPL_TRACE_API0("BTA_DisableTestMode");
161 
162     if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
163     {
164         p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
165         bta_sys_sendmsg(p_msg);
166     }
167 }
168 
169 /*******************************************************************************
170 **
171 ** Function         BTA_DmIsDeviceUp
172 **
173 ** Description      Called during startup to check whether the bluetooth module
174 **                  is up and ready
175 **
176 ** Returns          BOOLEAN
177 **
178 *******************************************************************************/
BTA_DmIsDeviceUp(void)179 BOOLEAN BTA_DmIsDeviceUp(void)
180 {
181 
182     BOOLEAN status;
183 
184     GKI_sched_lock();
185     status = BTM_IsDeviceUp();
186     GKI_sched_unlock();
187     return status;
188 
189 }
190 
191 /*******************************************************************************
192 **
193 ** Function         BTA_DmSetDeviceName
194 **
195 ** Description      This function sets the Bluetooth name of local device
196 **
197 **
198 ** Returns          void
199 **
200 *******************************************************************************/
BTA_DmSetDeviceName(char * p_name)201 void BTA_DmSetDeviceName(char *p_name)
202 {
203 
204     tBTA_DM_API_SET_NAME    *p_msg;
205 
206     if ((p_msg = (tBTA_DM_API_SET_NAME *) GKI_getbuf(sizeof(tBTA_DM_API_SET_NAME))) != NULL)
207     {
208         p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
209         /* truncate the name if needed */
210         BCM_STRNCPY_S(p_msg->name, sizeof(p_msg->name), p_name, BD_NAME_LEN-1);
211         p_msg->name[BD_NAME_LEN-1]=0;
212 
213         bta_sys_sendmsg(p_msg);
214     }
215 
216 
217 }
218 
219 /*******************************************************************************
220 **
221 ** Function         BTA_DmSetVisibility
222 **
223 ** Description      This function sets the Bluetooth connectable,
224 **                  discoverable, pairable and conn paired only modes of local device
225 **
226 **
227 ** Returns          void
228 **
229 *******************************************************************************/
BTA_DmSetVisibility(tBTA_DM_DISC disc_mode,tBTA_DM_CONN conn_mode,UINT8 pairable_mode,UINT8 conn_filter)230 void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 pairable_mode, UINT8 conn_filter )
231 {
232 
233     tBTA_DM_API_SET_VISIBILITY    *p_msg;
234 
235     if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
236     {
237         p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
238         p_msg->disc_mode = disc_mode;
239         p_msg->conn_mode = conn_mode;
240         p_msg->pair_mode = pairable_mode;
241         p_msg->conn_paired_only = conn_filter;
242 
243 
244         bta_sys_sendmsg(p_msg);
245     }
246 
247 
248 }
249 
250 /*******************************************************************************
251 **
252 ** Function         BTA_DmSetScanParam
253 **
254 ** Description      This function sets the parameters for page scan and
255 **                  inquiry scan.
256 **
257 **
258 ** Returns          void
259 **
260 *******************************************************************************/
BTA_DmSetScanParam(UINT16 page_scan_interval,UINT16 page_scan_window,UINT16 inquiry_scan_interval,UINT16 inquiry_scan_window)261 void BTA_DmSetScanParam (UINT16 page_scan_interval, UINT16 page_scan_window,
262                                   UINT16 inquiry_scan_interval, UINT16 inquiry_scan_window)
263 {
264     APPL_TRACE_API4 ("BTA_DmSetScanParam: %d, %d, %d, %d",
265             page_scan_interval, page_scan_window,
266             inquiry_scan_interval, inquiry_scan_window);
267 
268     bta_dm_cb.page_scan_interval = page_scan_interval;
269     bta_dm_cb.page_scan_window = page_scan_window;
270     bta_dm_cb.inquiry_scan_interval = inquiry_scan_interval;
271     bta_dm_cb.inquiry_scan_window = inquiry_scan_window;
272 }
273 
274 /*******************************************************************************
275 **
276 ** Function         BTA_DmSetAfhChannels
277 **
278 ** Description      This function sets the AFH first and
279 **                  last disable channel, so channels within
280 **                  that range are disabled.
281 **
282 ** Returns          void
283 **
284 *******************************************************************************/
BTA_DmSetAfhChannels(UINT8 first,UINT8 last)285 void BTA_DmSetAfhChannels(UINT8 first, UINT8 last)
286 {
287 
288     tBTA_DM_API_SET_AFH_CHANNELS_EVT    *p_msg;
289 
290     if ((p_msg = (tBTA_DM_API_SET_AFH_CHANNELS_EVT *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
291     {
292         p_msg->hdr.event = BTA_DM_API_SET_AFH_CHANNELS_EVT;
293         p_msg->first = first;
294         p_msg->last = last;
295         bta_sys_sendmsg(p_msg);
296     }
297 
298 
299 }
300 
301 /*******************************************************************************
302 **
303 ** Function         BTA_SetAfhChannelAssessment
304 **
305 ** Description      This function is called to set the channel assessment mode on or off
306 **
307 ** Returns          status
308 **
309 *******************************************************************************/
BTA_DmSetAfhChannelAssessment(BOOLEAN enable_or_disable)310 void BTA_DmSetAfhChannelAssessment (BOOLEAN enable_or_disable)
311 {
312     tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT *p_msg;
313 
314     if ((p_msg = (tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT *) GKI_getbuf(sizeof(tBTA_DM_API_SET_AFH_CHANNEL_ASSESSMENT))) != NULL)
315     {
316         p_msg->hdr.event    = BTA_DM_API_SET_AFH_CHANNEL_ASSESMENT_EVT;
317         p_msg->enable_or_disable = enable_or_disable;
318         bta_sys_sendmsg(p_msg);
319     }
320 }
321 
322 /*******************************************************************************
323 **
324 ** Function         BTA_DmVendorSpecificCommand
325 **
326 ** Description      This function sends the vendor specific command
327 **                  to the controller
328 **
329 **
330 ** Returns          tBTA_STATUS
331 **
332 *******************************************************************************/
BTA_DmVendorSpecificCommand(UINT16 opcode,UINT8 param_len,UINT8 * p_param_buf,tBTA_VENDOR_CMPL_CBACK * p_cback)333 tBTA_STATUS BTA_DmVendorSpecificCommand (UINT16 opcode, UINT8 param_len,
334                                          UINT8 *p_param_buf,
335                                          tBTA_VENDOR_CMPL_CBACK *p_cback)
336 {
337 
338     tBTA_DM_API_VENDOR_SPECIFIC_COMMAND    *p_msg;
339     UINT16 size;
340 
341     /* If p_cback is NULL, Notify application */
342     if (p_cback == NULL)
343     {
344         return (BTA_FAILURE);
345     }
346     else
347     {
348         size = sizeof (tBTA_DM_API_VENDOR_SPECIFIC_COMMAND) + param_len;
349         if ((p_msg = (tBTA_DM_API_VENDOR_SPECIFIC_COMMAND *) GKI_getbuf(size)) != NULL)
350         {
351             p_msg->hdr.event = BTA_DM_API_VENDOR_SPECIFIC_COMMAND_EVT;
352             p_msg->opcode = opcode;
353             p_msg->param_len = param_len;
354             p_msg->p_param_buf = (UINT8 *)(p_msg + 1);
355             p_msg->p_cback = p_cback;
356 
357             memcpy (p_msg->p_param_buf, p_param_buf, param_len);
358 
359             bta_sys_sendmsg(p_msg);
360         }
361         return (BTA_SUCCESS);
362     }
363 }
364 /*******************************************************************************
365 **
366 ** Function         BTA_DmSearch
367 **
368 ** Description      This function searches for peer Bluetooth devices. It performs
369 **                  an inquiry and gets the remote name for devices. Service
370 **                  discovery is done if services is non zero
371 **
372 **
373 ** Returns          void
374 **
375 *******************************************************************************/
BTA_DmSearch(tBTA_DM_INQ * p_dm_inq,tBTA_SERVICE_MASK services,tBTA_DM_SEARCH_CBACK * p_cback)376 void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback)
377 {
378 
379     tBTA_DM_API_SEARCH    *p_msg;
380 
381     if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(sizeof(tBTA_DM_API_SEARCH))) != NULL)
382     {
383         memset(p_msg, 0, sizeof(tBTA_DM_API_SEARCH));
384 
385         p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
386         memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
387         p_msg->services = services;
388         p_msg->p_cback = p_cback;
389         p_msg->rs_res  = BTA_DM_RS_NONE;
390         bta_sys_sendmsg(p_msg);
391     }
392 
393 }
394 
395 
396 /*******************************************************************************
397 **
398 ** Function         BTA_DmSearchCancel
399 **
400 ** Description      This function  cancels a search initiated by BTA_DmSearch
401 **
402 **
403 ** Returns          void
404 **
405 *******************************************************************************/
BTA_DmSearchCancel(void)406 void BTA_DmSearchCancel(void)
407 {
408     BT_HDR    *p_msg;
409 
410     if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
411     {
412         p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
413         bta_sys_sendmsg(p_msg);
414     }
415 
416 }
417 
418 /*******************************************************************************
419 **
420 ** Function         BTA_DmDiscover
421 **
422 ** Description      This function does service discovery for services of a
423 **                  peer device
424 **
425 **
426 ** Returns          void
427 **
428 *******************************************************************************/
BTA_DmDiscover(BD_ADDR bd_addr,tBTA_SERVICE_MASK services,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search)429 void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
430                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
431 {
432     tBTA_DM_API_DISCOVER    *p_msg;
433 
434     if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL)
435     {
436         memset(p_msg, 0, sizeof(tBTA_DM_API_DISCOVER));
437 
438         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
439         bdcpy(p_msg->bd_addr, bd_addr);
440         p_msg->services = services;
441         p_msg->p_cback = p_cback;
442         p_msg->sdp_search = sdp_search;
443         bta_sys_sendmsg(p_msg);
444     }
445 
446 }
447 
448 /*******************************************************************************
449 **
450 ** Function         BTA_DmDiscoverUUID
451 **
452 ** Description      This function does service discovery for services of a
453 **                  peer device
454 **
455 **
456 ** Returns          void
457 **
458 *******************************************************************************/
BTA_DmDiscoverUUID(BD_ADDR bd_addr,tSDP_UUID * uuid,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search)459 void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
460                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
461 {
462     tBTA_DM_API_DISCOVER    *p_msg;
463 
464     if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL)
465     {
466         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
467         bdcpy(p_msg->bd_addr, bd_addr);
468         p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level
469         p_msg->p_cback = p_cback;
470         p_msg->sdp_search = sdp_search;
471 
472 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
473         p_msg->num_uuid = 0;
474         p_msg->p_uuid = NULL;
475 #endif
476         memcpy( &p_msg->uuid, uuid, sizeof(tSDP_UUID) );
477         bta_sys_sendmsg(p_msg);
478     }
479 
480 }
481 /*******************************************************************************
482 **
483 ** Function         BTA_DmIsMaster
484 **
485 ** Description      This function checks if the local device is the master of
486 **                  the link to the given device
487 **
488 ** Returns          TRUE if master.
489 **                  FALSE if not.
490 **
491 *******************************************************************************/
BTA_DmIsMaster(BD_ADDR bd_addr)492 BOOLEAN BTA_DmIsMaster(BD_ADDR bd_addr)
493 {
494     BOOLEAN is_master = FALSE;
495     UINT8 link_role;
496 
497     BTM_GetRole(bd_addr, &link_role);
498     APPL_TRACE_API1("BTA_DmIsMaster role:x%x", link_role);
499     if(link_role == BTM_ROLE_MASTER)
500     {
501         is_master = TRUE;
502     }
503     return is_master;
504 }
505 
506 /*******************************************************************************
507 **
508 ** Function         BTA_DmBond
509 **
510 ** Description      This function initiates a bonding procedure with a peer
511 **                  device
512 **
513 **
514 ** Returns          void
515 **
516 *******************************************************************************/
BTA_DmBond(BD_ADDR bd_addr)517 void BTA_DmBond(BD_ADDR bd_addr)
518 {
519     tBTA_DM_API_BOND    *p_msg;
520 
521     if ((p_msg = (tBTA_DM_API_BOND *) GKI_getbuf(sizeof(tBTA_DM_API_BOND))) != NULL)
522     {
523         p_msg->hdr.event = BTA_DM_API_BOND_EVT;
524         bdcpy(p_msg->bd_addr, bd_addr);
525         bta_sys_sendmsg(p_msg);
526     }
527 
528 
529 }
530 
531 /*******************************************************************************
532 **
533 ** Function         BTA_DmBondCancel
534 **
535 ** Description      This function cancels the bonding procedure with a peer
536 **                  device
537 **
538 **
539 ** Returns          void
540 **
541 *******************************************************************************/
BTA_DmBondCancel(BD_ADDR bd_addr)542 void BTA_DmBondCancel(BD_ADDR bd_addr)
543 {
544     tBTA_DM_API_BOND_CANCEL    *p_msg;
545 
546     if ((p_msg = (tBTA_DM_API_BOND_CANCEL *) GKI_getbuf(sizeof(tBTA_DM_API_BOND_CANCEL))) != NULL)
547     {
548         p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
549         bdcpy(p_msg->bd_addr, bd_addr);
550         bta_sys_sendmsg(p_msg);
551     }
552 
553 
554 }
555 
556 /*******************************************************************************
557 **
558 ** Function         BTA_DmPinReply
559 **
560 ** Description      This function provides a pincode for a remote device when
561 **                  one is requested by DM through BTA_DM_PIN_REQ_EVT
562 **
563 **
564 ** Returns          void
565 **
566 *******************************************************************************/
BTA_DmPinReply(BD_ADDR bd_addr,BOOLEAN accept,UINT8 pin_len,UINT8 * p_pin)567 void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin)
568 
569 {
570     tBTA_DM_API_PIN_REPLY    *p_msg;
571 
572     if ((p_msg = (tBTA_DM_API_PIN_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PIN_REPLY))) != NULL)
573     {
574         p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
575         bdcpy(p_msg->bd_addr, bd_addr);
576         p_msg->accept = accept;
577         if(accept)
578         {
579             p_msg->pin_len = pin_len;
580             memcpy(p_msg->p_pin, p_pin, pin_len);
581         }
582         bta_sys_sendmsg(p_msg);
583     }
584 
585 }
586 
587 /*******************************************************************************
588 **
589 ** Function         BTA_DmLinkPolicy
590 **
591 ** Description      This function sets/clears the link policy mask to the given
592 **                  bd_addr.
593 **                  If clearing the sniff or park mode mask, the link is put
594 **                  in active mode.
595 **
596 ** Returns          void
597 **
598 *******************************************************************************/
BTA_DmLinkPolicy(BD_ADDR bd_addr,tBTA_DM_LP_MASK policy_mask,BOOLEAN set)599 void BTA_DmLinkPolicy(BD_ADDR bd_addr, tBTA_DM_LP_MASK policy_mask,
600                       BOOLEAN set)
601 {
602     tBTA_DM_API_LINK_POLICY    *p_msg;
603 
604     if ((p_msg = (tBTA_DM_API_LINK_POLICY *) GKI_getbuf(sizeof(tBTA_DM_API_LINK_POLICY))) != NULL)
605     {
606         p_msg->hdr.event = BTA_DM_API_LINK_POLICY_EVT;
607         bdcpy(p_msg->bd_addr, bd_addr);
608         p_msg->policy_mask = policy_mask;
609         p_msg->set = set;
610         bta_sys_sendmsg(p_msg);
611     }
612 }
613 
614 
615 #if (BTM_OOB_INCLUDED == TRUE)
616 /*******************************************************************************
617 **
618 ** Function         BTA_DmLocalOob
619 **
620 ** Description      This function retrieves the OOB data from local controller.
621 **                  The result is reported by bta_dm_co_loc_oob().
622 **
623 ** Returns          void
624 **
625 *******************************************************************************/
BTA_DmLocalOob(void)626 void BTA_DmLocalOob(void)
627 {
628     tBTA_DM_API_LOC_OOB    *p_msg;
629 
630     if ((p_msg = (tBTA_DM_API_LOC_OOB *) GKI_getbuf(sizeof(tBTA_DM_API_LOC_OOB))) != NULL)
631     {
632         p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
633         bta_sys_sendmsg(p_msg);
634     }
635 }
636 #endif /* BTM_OOB_INCLUDED */
637 /*******************************************************************************
638 **
639 ** Function         BTA_DmConfirm
640 **
641 ** Description      This function accepts or rejects the numerical value of the
642 **                  Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
643 **
644 ** Returns          void
645 **
646 *******************************************************************************/
BTA_DmConfirm(BD_ADDR bd_addr,BOOLEAN accept)647 void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept)
648 {
649     tBTA_DM_API_CONFIRM    *p_msg;
650 
651     if ((p_msg = (tBTA_DM_API_CONFIRM *) GKI_getbuf(sizeof(tBTA_DM_API_CONFIRM))) != NULL)
652     {
653         p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
654         bdcpy(p_msg->bd_addr, bd_addr);
655         p_msg->accept = accept;
656         bta_sys_sendmsg(p_msg);
657     }
658 }
659 
660 /*******************************************************************************
661 **
662 ** Function         BTA_DmPasskeyCancel
663 **
664 ** Description      This function is called to cancel the simple pairing process
665 **                  reported by BTA_DM_SP_KEY_NOTIF_EVT
666 **
667 ** Returns          void
668 **
669 *******************************************************************************/
670 #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)
BTA_DmPasskeyCancel(BD_ADDR bd_addr)671 void BTA_DmPasskeyCancel(BD_ADDR bd_addr)
672 {
673     tBTA_DM_API_PASKY_CANCEL    *p_msg;
674 
675     if ((p_msg = (tBTA_DM_API_PASKY_CANCEL *) \
676         GKI_getbuf(sizeof(tBTA_DM_API_PASKY_CANCEL))) != NULL)
677     {
678         p_msg->hdr.event = BTA_DM_API_PASKY_CANCEL_EVT;
679         bdcpy(p_msg->bd_addr, bd_addr);
680         bta_sys_sendmsg(p_msg);
681     }
682 }
683 #endif
684 
685 
686 /*******************************************************************************
687 **
688 ** Function         BTA_DmAddDevice
689 **
690 ** Description      This function adds a device to the security database list of
691 **                  peer device
692 **
693 **
694 ** Returns          void
695 **
696 *******************************************************************************/
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)697 void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
698                      tBTA_SERVICE_MASK trusted_mask, BOOLEAN is_trusted,
699                      UINT8 key_type, tBTA_IO_CAP io_cap)
700 {
701 
702     tBTA_DM_API_ADD_DEVICE *p_msg;
703 
704     if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL)
705     {
706         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE));
707 
708         p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
709         bdcpy(p_msg->bd_addr, bd_addr);
710         p_msg->tm = trusted_mask;
711         p_msg->is_trusted = is_trusted;
712         p_msg->io_cap = io_cap;
713 
714         if (link_key)
715         {
716             p_msg->link_key_known = TRUE;
717             p_msg->key_type = key_type;
718             memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
719         }
720 
721         /* Load device class if specified */
722         if (dev_class)
723         {
724             p_msg->dc_known = TRUE;
725             memcpy (p_msg->dc, dev_class, DEV_CLASS_LEN);
726         }
727 
728         memset (p_msg->bd_name, 0, BD_NAME_LEN);
729         memset (p_msg->features, 0, BD_FEATURES_LEN);
730 
731         bta_sys_sendmsg(p_msg);
732     }
733 }
734 
735 
736 /*******************************************************************************
737 **
738 ** Function         BTA_DmRemoveDevice
739 **
740 ** Description      This function removes a device fromthe security database list of
741 **                  peer device
742 **
743 **
744 ** Returns          void
745 **
746 *******************************************************************************/
BTA_DmRemoveDevice(BD_ADDR bd_addr)747 tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
748 {
749     tBTA_DM_API_REMOVE_DEVICE *p_msg;
750 
751     if ((p_msg = (tBTA_DM_API_REMOVE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_DEVICE))) != NULL)
752     {
753         memset (p_msg, 0, sizeof(tBTA_DM_API_REMOVE_DEVICE));
754 
755         p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
756         bdcpy(p_msg->bd_addr, bd_addr);
757         bta_sys_sendmsg(p_msg);
758     }
759     else
760     {
761         return BTA_FAILURE;
762     }
763 
764     return BTA_SUCCESS;
765 }
766 
767 /*******************************************************************************
768 **
769 ** Function         BTA_DmAddDevWithName
770 **
771 ** Description      This function is newer version of  BTA_DmAddDevice()
772 **                  which added bd_name and features as input parameters.
773 **
774 **
775 ** Returns          void
776 **
777 *******************************************************************************/
BTA_DmAddDevWithName(BD_ADDR bd_addr,DEV_CLASS dev_class,BD_NAME bd_name,BD_FEATURES features,LINK_KEY link_key,tBTA_SERVICE_MASK trusted_mask,BOOLEAN is_trusted,UINT8 key_type,tBTA_IO_CAP io_cap)778 void BTA_DmAddDevWithName (BD_ADDR bd_addr, DEV_CLASS dev_class,
779                                       BD_NAME bd_name, BD_FEATURES features,
780                                       LINK_KEY link_key, tBTA_SERVICE_MASK trusted_mask,
781                                       BOOLEAN is_trusted, UINT8 key_type, tBTA_IO_CAP io_cap)
782 {
783     tBTA_DM_API_ADD_DEVICE *p_msg;
784 
785     if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL)
786     {
787         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE));
788 
789         p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
790         bdcpy(p_msg->bd_addr, bd_addr);
791         p_msg->tm = trusted_mask;
792         p_msg->is_trusted = is_trusted;
793         p_msg->io_cap = io_cap;
794 
795         if (link_key)
796         {
797             p_msg->link_key_known = TRUE;
798             p_msg->key_type = key_type;
799             memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
800         }
801 
802         /* Load device class if specified */
803         if (dev_class)
804         {
805             p_msg->dc_known = TRUE;
806             memcpy (p_msg->dc, dev_class, DEV_CLASS_LEN);
807         }
808 
809         if (bd_name)
810             memcpy(p_msg->bd_name, bd_name, BD_NAME_LEN);
811 
812         if (features)
813             memcpy(p_msg->features, features, BD_FEATURES_LEN);
814 
815         bta_sys_sendmsg(p_msg);
816     }
817 }
818 
819 /*******************************************************************************
820 **
821 ** Function         BTA_DmAuthorizeReply
822 **
823 ** Description      This function provides an authorization reply when authorization
824 **                  is requested by BTA through BTA_DM_AUTHORIZE_EVT
825 **
826 **
827 ** Returns          tBTA_STATUS
828 **
829 *******************************************************************************/
BTA_DmAuthorizeReply(BD_ADDR bd_addr,tBTA_SERVICE_ID service,tBTA_AUTH_RESP response)830 void BTA_DmAuthorizeReply(BD_ADDR bd_addr, tBTA_SERVICE_ID service, tBTA_AUTH_RESP response)
831 {
832 
833     tBTA_DM_API_AUTH_REPLY    *p_msg;
834 
835     if ((p_msg = (tBTA_DM_API_AUTH_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_AUTH_REPLY))) != NULL)
836     {
837         p_msg->hdr.event = BTA_DM_API_AUTH_REPLY_EVT;
838         bdcpy(p_msg->bd_addr, bd_addr);
839         p_msg->service = service;
840         p_msg->response = response;
841 
842         bta_sys_sendmsg(p_msg);
843     }
844 
845 }
846 
847 /*******************************************************************************
848 **
849 ** Function         BTA_DmSignalStrength
850 **
851 ** Description      This function initiates RSSI and channnel quality
852 **                  measurments. BTA_DM_SIG_STRENGTH_EVT is sent to
853 **                  application with the values of RSSI and channel
854 **                  quality
855 **
856 **
857 ** Returns          void
858 **
859 *******************************************************************************/
BTA_DmSignalStrength(tBTA_SIG_STRENGTH_MASK mask,UINT16 period,BOOLEAN start)860 void BTA_DmSignalStrength(tBTA_SIG_STRENGTH_MASK mask, UINT16 period, BOOLEAN start)
861 {
862 
863     tBTA_API_DM_SIG_STRENGTH    *p_msg;
864 
865     if ((p_msg = (tBTA_API_DM_SIG_STRENGTH *) GKI_getbuf(sizeof(tBTA_API_DM_SIG_STRENGTH))) != NULL)
866     {
867         p_msg->hdr.event = BTA_API_DM_SIG_STRENGTH_EVT;
868         p_msg->mask = mask;
869         p_msg->period = period;
870         p_msg->start = start;
871 
872         bta_sys_sendmsg(p_msg);
873     }
874 
875 
876 }
877 
878 /*******************************************************************************
879 **
880 ** Function         BTA_DmWriteInqTxPower
881 **
882 ** Description      This command is used to write the inquiry transmit power level
883 **                  used to transmit the inquiry (ID) data packets.
884 **
885 ** Parameters       tx_power - tx inquiry power to use, valid value is -70 ~ 20
886 
887 ** Returns          void
888 **
889 *******************************************************************************/
BTA_DmWriteInqTxPower(INT8 tx_power)890 void BTA_DmWriteInqTxPower(INT8 tx_power)
891 {
892 
893     tBTA_API_DM_TX_INQPWR    *p_msg;
894 
895     if ((p_msg = (tBTA_API_DM_TX_INQPWR *) GKI_getbuf(sizeof(tBTA_API_DM_TX_INQPWR))) != NULL)
896     {
897         p_msg->hdr.event = BTA_DM_API_TX_INQPWR_EVT;
898         p_msg->tx_power = tx_power;
899 
900         bta_sys_sendmsg(p_msg);
901     }
902 }
903 
904 
905 /*******************************************************************************
906 **
907 ** Function         BTA_DmEirAddUUID
908 **
909 ** Description      This function is called to add UUID into EIR.
910 **
911 ** Parameters       tBT_UUID - UUID
912 **
913 ** Returns          None
914 **
915 *******************************************************************************/
BTA_DmEirAddUUID(tBT_UUID * p_uuid)916 void BTA_DmEirAddUUID (tBT_UUID *p_uuid)
917 {
918 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
919     tBTA_DM_API_UPDATE_EIR_UUID    *p_msg;
920 
921     if ((p_msg = (tBTA_DM_API_UPDATE_EIR_UUID *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_EIR_UUID))) != NULL)
922     {
923         p_msg->hdr.event = BTA_DM_API_UPDATE_EIR_UUID_EVT;
924         p_msg->is_add    = TRUE;
925         memcpy (&(p_msg->uuid), p_uuid, sizeof(tBT_UUID));
926 
927         bta_sys_sendmsg(p_msg);
928     }
929 #endif
930 }
931 
932 /*******************************************************************************
933 **
934 ** Function         BTA_DmEirRemoveUUID
935 **
936 ** Description      This function is called to remove UUID from EIR.
937 **
938 ** Parameters       tBT_UUID - UUID
939 **
940 ** Returns          None
941 **
942 *******************************************************************************/
BTA_DmEirRemoveUUID(tBT_UUID * p_uuid)943 void BTA_DmEirRemoveUUID (tBT_UUID *p_uuid)
944 {
945 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
946     tBTA_DM_API_UPDATE_EIR_UUID    *p_msg;
947 
948     if ((p_msg = (tBTA_DM_API_UPDATE_EIR_UUID *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_EIR_UUID))) != NULL)
949     {
950         p_msg->hdr.event = BTA_DM_API_UPDATE_EIR_UUID_EVT;
951         p_msg->is_add    = FALSE;
952         memcpy (&(p_msg->uuid), p_uuid, sizeof(tBT_UUID));
953 
954         bta_sys_sendmsg(p_msg);
955     }
956 #endif
957 }
958 
959 /*******************************************************************************
960 **
961 ** Function         BTA_DmSetEIRConfig
962 **
963 ** Description      This function is called to override the BTA default EIR parameters.
964 **                  This funciton is only valid in a system where BTU & App task
965 **                  are in the same memory space.
966 **
967 ** Parameters       Pointer to User defined EIR config
968 **
969 ** Returns          None
970 **
971 *******************************************************************************/
BTA_DmSetEIRConfig(tBTA_DM_EIR_CONF * p_eir_cfg)972 void BTA_DmSetEIRConfig (tBTA_DM_EIR_CONF *p_eir_cfg)
973 {
974 #if (BTM_EIR_SERVER_INCLUDED == TRUE)
975     tBTA_DM_API_SET_EIR_CONFIG  *p_msg;
976 
977     if ((p_msg = (tBTA_DM_API_SET_EIR_CONFIG *) GKI_getbuf(sizeof(tBTA_DM_API_SET_EIR_CONFIG))) != NULL)
978     {
979         p_msg->hdr.event = BTA_DM_API_SET_EIR_CONFIG_EVT;
980         p_msg->p_eir_cfg = p_eir_cfg;
981 
982         bta_sys_sendmsg(p_msg);
983     }
984 #endif
985 }
986 
987 /*******************************************************************************
988 **
989 ** Function         BTA_CheckEirData
990 **
991 ** Description      This function is called to get EIR data from significant part.
992 **
993 ** Parameters       p_eir - pointer of EIR significant part
994 **                  type   - finding EIR data type
995 **                  p_length - return the length of EIR data
996 **
997 ** Returns          pointer of EIR data
998 **
999 *******************************************************************************/
BTA_CheckEirData(UINT8 * p_eir,UINT8 type,UINT8 * p_length)1000 UINT8 *BTA_CheckEirData( UINT8 *p_eir, UINT8 type, UINT8 *p_length )
1001 {
1002 #if ( BTM_EIR_CLIENT_INCLUDED == TRUE )
1003     return BTM_CheckEirData( p_eir, type, p_length );
1004 #else
1005     return NULL;
1006 #endif
1007 }
1008 
1009 /*******************************************************************************
1010 **
1011 ** Function         BTA_GetEirService
1012 **
1013 ** Description      This function is called to get BTA service mask from EIR.
1014 **
1015 ** Parameters       p_eir - pointer of EIR significant part
1016 **                  p_services - return the BTA service mask
1017 **
1018 ** Returns          None
1019 **
1020 *******************************************************************************/
1021 extern const UINT16 bta_service_id_to_uuid_lkup_tbl [];
BTA_GetEirService(UINT8 * p_eir,tBTA_SERVICE_MASK * p_services)1022 void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services )
1023 {
1024 #if ( BTM_EIR_CLIENT_INCLUDED == TRUE )
1025     UINT8 xx, yy;
1026     UINT8 num_uuid, max_num_uuid = 32;
1027     UINT8 uuid_list[32*LEN_UUID_16];
1028     UINT16 *p_uuid16 = (UINT16 *)uuid_list;
1029     tBTA_SERVICE_MASK mask;
1030 
1031     BTM_GetEirUuidList( p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid);
1032     for( xx = 0; xx < num_uuid; xx++ )
1033     {
1034         mask = 1;
1035         for( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ )
1036         {
1037             if( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] )
1038             {
1039                 *p_services |= mask;
1040                 break;
1041             }
1042             mask <<= 1;
1043         }
1044 
1045         /* for HSP v1.2 only device */
1046         if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS)
1047             *p_services |= BTA_HSP_SERVICE_MASK;
1048 
1049        if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE)
1050             *p_services |= BTA_HL_SERVICE_MASK;
1051 
1052         if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK)
1053             *p_services |= BTA_HL_SERVICE_MASK;
1054     }
1055 #endif
1056 }
1057 
1058 /*******************************************************************************
1059 **
1060 ** Function         BTA_DmUseSsr
1061 **
1062 ** Description      This function is called to check if the connected peer device
1063 **                  supports SSR or not.
1064 **
1065 ** Returns          TRUE, if SSR is supported
1066 **
1067 *******************************************************************************/
BTA_DmUseSsr(BD_ADDR bd_addr)1068 BOOLEAN BTA_DmUseSsr( BD_ADDR bd_addr )
1069 {
1070     BOOLEAN use_ssr = FALSE;
1071     tBTA_DM_PEER_DEVICE * p_dev = bta_dm_find_peer_device(bd_addr);
1072     if(p_dev && (p_dev->info & BTA_DM_DI_USE_SSR) )
1073         use_ssr = TRUE;
1074     return use_ssr;
1075 }
1076 
1077 /*******************************************************************************
1078 **                   Device Identification (DI) Server Functions
1079 *******************************************************************************/
1080 /*******************************************************************************
1081 **
1082 ** Function         BTA_DmSetLocalDiRecord
1083 **
1084 ** Description      This function adds a DI record to the local SDP database.
1085 **
1086 ** Returns          BTA_SUCCESS if record set sucessfully, otherwise error code.
1087 **
1088 *******************************************************************************/
BTA_DmSetLocalDiRecord(tBTA_DI_RECORD * p_device_info,UINT32 * p_handle)1089 tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
1090                               UINT32 *p_handle )
1091 {
1092     tBTA_STATUS  status = BTA_FAILURE;
1093 
1094     if(bta_dm_di_cb.di_num < BTA_DI_NUM_MAX)
1095     {
1096         if(SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS)
1097         {
1098             if(!p_device_info->primary_record)
1099             {
1100                 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
1101                 bta_dm_di_cb.di_num ++;
1102             }
1103 
1104             bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
1105             status =  BTA_SUCCESS;
1106         }
1107     }
1108 
1109     return status;
1110 }
1111 
1112 /*******************************************************************************
1113 **
1114 ** Function         BTA_DmGetLocalDiRecord
1115 **
1116 ** Description      Get a specified DI record to the local SDP database. If no
1117 **                  record handle is provided, the primary DI record will be
1118 **                  returned.
1119 **
1120 **                  Fills in the device information of the record
1121 **                  p_handle - if p_handle == 0, the primary record is returned
1122 **
1123 ** Returns          BTA_SUCCESS if record set sucessfully, otherwise error code.
1124 **
1125 *******************************************************************************/
BTA_DmGetLocalDiRecord(tBTA_DI_GET_RECORD * p_device_info,UINT32 * p_handle)1126 tBTA_STATUS BTA_DmGetLocalDiRecord( tBTA_DI_GET_RECORD *p_device_info,
1127                               UINT32 *p_handle )
1128 {
1129     UINT16  status;
1130 
1131     status = SDP_GetLocalDiRecord(p_device_info, p_handle);
1132 
1133     if (status == SDP_SUCCESS)
1134         return BTA_SUCCESS;
1135     else
1136         return BTA_FAILURE;
1137 
1138 }
1139 
1140 /*******************************************************************************
1141 **                   Device Identification (DI) Client Functions
1142 *******************************************************************************/
1143 /*******************************************************************************
1144 **
1145 ** Function         BTA_DmDiDiscover
1146 **
1147 ** Description      This function queries a remote device for DI information.
1148 **
1149 **
1150 ** Returns          None.
1151 **
1152 *******************************************************************************/
BTA_DmDiDiscover(BD_ADDR remote_device,tBTA_DISCOVERY_DB * p_db,UINT32 len,tBTA_DM_SEARCH_CBACK * p_cback)1153 void BTA_DmDiDiscover( BD_ADDR remote_device, tBTA_DISCOVERY_DB *p_db,
1154                        UINT32 len, tBTA_DM_SEARCH_CBACK *p_cback )
1155 {
1156     tBTA_DM_API_DI_DISC    *p_msg;
1157 
1158     if ((p_msg = (tBTA_DM_API_DI_DISC *) GKI_getbuf(sizeof(tBTA_DM_API_DI_DISC))) != NULL)
1159     {
1160         bdcpy(p_msg->bd_addr, remote_device);
1161         p_msg->hdr.event    = BTA_DM_API_DI_DISCOVER_EVT;
1162         p_msg->p_sdp_db     = p_db;
1163         p_msg->len          = len;
1164         p_msg->p_cback      = p_cback;
1165 
1166         bta_sys_sendmsg(p_msg);
1167     }
1168 }
1169 
1170 /*******************************************************************************
1171 **
1172 ** Function         BTA_DmGetDiRecord
1173 **
1174 ** Description      This function retrieves a remote device's DI record from
1175 **                  the specified database.
1176 **
1177 ** Returns          BTA_SUCCESS if Get DI record is succeed.
1178 **                  BTA_FAILURE if Get DI record failed.
1179 **
1180 *******************************************************************************/
BTA_DmGetDiRecord(UINT8 get_record_index,tBTA_DI_GET_RECORD * p_device_info,tBTA_DISCOVERY_DB * p_db)1181 tBTA_STATUS BTA_DmGetDiRecord( UINT8 get_record_index, tBTA_DI_GET_RECORD *p_device_info,
1182                         tBTA_DISCOVERY_DB *p_db )
1183 {
1184     if (SDP_GetDiRecord(get_record_index, p_device_info, p_db) != SDP_SUCCESS)
1185         return BTA_FAILURE;
1186     else
1187         return BTA_SUCCESS;
1188 }
1189 
1190 /*******************************************************************************
1191 **
1192 ** Function         BTA_SysFeatures
1193 **
1194 ** Description      This function is called to set system features.
1195 **
1196 ** Returns          void
1197 **
1198 *******************************************************************************/
BTA_SysFeatures(UINT16 sys_features)1199 void BTA_SysFeatures (UINT16 sys_features)
1200 {
1201     bta_sys_cb.sys_features = sys_features;
1202 
1203     APPL_TRACE_API1("BTA_SysFeatures: sys_features = %d", sys_features);
1204 }
1205 
1206 /*******************************************************************************
1207 **
1208 ** Function         bta_dmexecutecallback
1209 **
1210 ** Description      This function will request BTA to execute a call back in the context of BTU task
1211 **                  This API was named in lower case because it is only intended
1212 **                  for the internal customers(like BTIF).
1213 **
1214 ** Returns          void
1215 **
1216 *******************************************************************************/
bta_dmexecutecallback(tBTA_DM_EXEC_CBACK * p_callback,void * p_param)1217 void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param)
1218 {
1219     tBTA_DM_API_EXECUTE_CBACK *p_msg;
1220 
1221     if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
1222     {
1223         p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
1224         p_msg->p_param= p_param;
1225         p_msg->p_exec_cback= p_callback;
1226         bta_sys_sendmsg(p_msg);
1227     }
1228 }
1229 
1230 /*******************************************************************************
1231 **
1232 ** Function         BTA_DmAddBleKey
1233 **
1234 ** Description      Add/modify LE device information.  This function will be
1235 **                  normally called during host startup to restore all required
1236 **                  information stored in the NVRAM.
1237 **
1238 ** Parameters:      bd_addr          - BD address of the peer
1239 **                  p_le_key         - LE key values.
1240 **                  key_type         - LE SMP key type.
1241 **
1242 ** Returns          void
1243 **
1244 *******************************************************************************/
BTA_DmAddBleKey(BD_ADDR bd_addr,tBTA_LE_KEY_VALUE * p_le_key,tBTA_LE_KEY_TYPE key_type)1245 void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_TYPE key_type)
1246 {
1247 #if BLE_INCLUDED == TRUE
1248 
1249     tBTA_DM_API_ADD_BLEKEY *p_msg;
1250 
1251     if ((p_msg = (tBTA_DM_API_ADD_BLEKEY *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLEKEY))) != NULL)
1252     {
1253         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLEKEY));
1254 
1255         p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
1256         p_msg->key_type = key_type;
1257         bdcpy(p_msg->bd_addr, bd_addr);
1258         memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE));
1259 
1260         bta_sys_sendmsg(p_msg);
1261     }
1262 
1263 #endif
1264 }
1265 
1266 /*******************************************************************************
1267 **
1268 ** Function         BTA_DmAddBleDevice
1269 **
1270 ** Description      Add a BLE device.  This function will be normally called
1271 **                  during host startup to restore all required information
1272 **                  for a LE device stored in the NVRAM.
1273 **
1274 ** Parameters:      bd_addr          - BD address of the peer
1275 **                  dev_type         - Remote device's device type.
1276 **                  addr_type        - LE device address type.
1277 **
1278 ** Returns          void
1279 **
1280 *******************************************************************************/
BTA_DmAddBleDevice(BD_ADDR bd_addr,tBLE_ADDR_TYPE addr_type,tBT_DEVICE_TYPE dev_type)1281 void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TYPE dev_type)
1282 {
1283 #if BLE_INCLUDED == TRUE
1284     tBTA_DM_API_ADD_BLE_DEVICE *p_msg;
1285 
1286     if ((p_msg = (tBTA_DM_API_ADD_BLE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLE_DEVICE))) != NULL)
1287     {
1288         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
1289 
1290         p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
1291         bdcpy(p_msg->bd_addr, bd_addr);
1292         p_msg->addr_type = addr_type;
1293         p_msg->dev_type = dev_type;
1294 
1295         bta_sys_sendmsg(p_msg);
1296     }
1297 #endif
1298 }
1299 /*******************************************************************************
1300 **
1301 ** Function         BTA_DmBlePasskeyReply
1302 **
1303 ** Description      Send BLE SMP passkey reply.
1304 **
1305 ** Parameters:      bd_addr          - BD address of the peer
1306 **                  accept           - passkey entry sucessful or declined.
1307 **                  passkey          - passkey value, must be a 6 digit number,
1308 **                                     can be lead by 0.
1309 **
1310 ** Returns          void
1311 **
1312 *******************************************************************************/
BTA_DmBlePasskeyReply(BD_ADDR bd_addr,BOOLEAN accept,UINT32 passkey)1313 void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey)
1314 {
1315 #if BLE_INCLUDED == TRUE
1316     tBTA_DM_API_PASSKEY_REPLY    *p_msg;
1317 
1318     if ((p_msg = (tBTA_DM_API_PASSKEY_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PASSKEY_REPLY))) != NULL)
1319     {
1320         memset(p_msg, 0, sizeof(tBTA_DM_API_PASSKEY_REPLY));
1321 
1322         p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
1323         bdcpy(p_msg->bd_addr, bd_addr);
1324         p_msg->accept = accept;
1325 
1326         if(accept)
1327         {
1328             p_msg->passkey = passkey;
1329         }
1330         bta_sys_sendmsg(p_msg);
1331     }
1332 #endif
1333 }
1334 /*******************************************************************************
1335 **
1336 ** Function         BTA_DmBleSecurityGrant
1337 **
1338 ** Description      Grant security request access.
1339 **
1340 ** Parameters:      bd_addr          - BD address of the peer
1341 **                  res              - security grant status.
1342 **
1343 ** Returns          void
1344 **
1345 *******************************************************************************/
BTA_DmBleSecurityGrant(BD_ADDR bd_addr,tBTA_DM_BLE_SEC_GRANT res)1346 void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
1347 {
1348 #if BLE_INCLUDED == TRUE
1349     tBTA_DM_API_BLE_SEC_GRANT    *p_msg;
1350 
1351     if ((p_msg = (tBTA_DM_API_BLE_SEC_GRANT *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SEC_GRANT))) != NULL)
1352     {
1353         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SEC_GRANT));
1354 
1355         p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
1356         bdcpy(p_msg->bd_addr, bd_addr);
1357         p_msg->res = res;
1358 
1359         bta_sys_sendmsg(p_msg);
1360     }
1361 #endif
1362 }
1363 /*******************************************************************************
1364 **
1365 ** Function         BTA_DmSetBlePrefConnParams
1366 **
1367 ** Description      This function is called to set the preferred connection
1368 **                  parameters when default connection parameter is not desired.
1369 **
1370 ** Parameters:      bd_addr          - BD address of the peripheral
1371 **                  scan_interval    - scan interval
1372 **                  scan_window      - scan window
1373 **                  min_conn_int     - minimum preferred connection interval
1374 **                  max_conn_int     - maximum preferred connection interval
1375 **                  slave_latency    - preferred slave latency
1376 **                  supervision_tout - preferred supervision timeout
1377 **
1378 **
1379 ** Returns          void
1380 **
1381 *******************************************************************************/
BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,UINT16 min_conn_int,UINT16 max_conn_int,UINT16 slave_latency,UINT16 supervision_tout)1382 void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,
1383                                UINT16 min_conn_int, UINT16 max_conn_int,
1384                                UINT16 slave_latency, UINT16 supervision_tout )
1385 {
1386 #if BLE_INCLUDED == TRUE
1387     tBTA_DM_API_BLE_CONN_PARAMS    *p_msg;
1388 
1389     if ((p_msg = (tBTA_DM_API_BLE_CONN_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_CONN_PARAMS))) != NULL)
1390     {
1391         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
1392 
1393         p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
1394 
1395         memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN);
1396 
1397         p_msg->conn_int_max     = max_conn_int;
1398         p_msg->conn_int_min     = min_conn_int;
1399         p_msg->slave_latency    = slave_latency;
1400         p_msg->supervision_tout = supervision_tout;
1401 
1402         bta_sys_sendmsg(p_msg);
1403     }
1404 #endif
1405 }
1406 
1407 /*******************************************************************************
1408 **
1409 ** Function         BTA_DmSetBleConnScanParams
1410 **
1411 ** Description      This function is called to set scan parameters used in
1412 **                  BLE connection request
1413 **
1414 ** Parameters:      scan_interval    - scan interval
1415 **                  scan_window      - scan window
1416 **
1417 ** Returns          void
1418 **
1419 *******************************************************************************/
BTA_DmSetBleConnScanParams(UINT16 scan_interval,UINT16 scan_window)1420 void BTA_DmSetBleConnScanParams(UINT16 scan_interval, UINT16 scan_window )
1421 {
1422 #if BLE_INCLUDED == TRUE
1423     tBTA_DM_API_BLE_SCAN_PARAMS    *p_msg;
1424 
1425     if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL)
1426     {
1427         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
1428 
1429         p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT;
1430 
1431         p_msg->scan_int         = scan_interval;
1432         p_msg->scan_window      = scan_window;
1433 
1434         bta_sys_sendmsg(p_msg);
1435     }
1436 #endif
1437 }
1438 
1439 /*******************************************************************************
1440 **
1441 ** Function         BTA_DmBleSetBgConnType
1442 **
1443 ** Description      This function is called to set BLE connectable mode for a
1444 **                  peripheral device.
1445 **
1446 ** Parameters       bg_conn_type: it can be auto connection, or selective connection.
1447 **                  p_select_cback: callback function when selective connection procedure
1448 **                              is being used.
1449 **
1450 ** Returns          void
1451 **
1452 *******************************************************************************/
BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type,tBTA_DM_BLE_SEL_CBACK * p_select_cback)1453 void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback)
1454 {
1455 #if BLE_INCLUDED == TRUE
1456     tBTA_DM_API_BLE_SET_BG_CONN_TYPE    *p_msg;
1457 
1458     if ((p_msg = (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE))) != NULL)
1459     {
1460         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
1461 
1462         p_msg->hdr.event        = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
1463         p_msg->bg_conn_type     = bg_conn_type;
1464         p_msg->p_select_cback   = p_select_cback;
1465 
1466         bta_sys_sendmsg(p_msg);
1467     }
1468 #endif
1469 }
1470 /*******************************************************************************
1471 **
1472 ** Function         BTA_DmDiscoverExt
1473 **
1474 ** Description      This function does service discovery for services of a
1475 **                  peer device. When services.num_uuid is 0, it indicates all
1476 **                  GATT based services are to be searched; other wise a list of
1477 **                  UUID of interested services should be provided through
1478 **                  p_services->p_uuid.
1479 **
1480 **
1481 **
1482 ** Returns          void
1483 **
1484 *******************************************************************************/
BTA_DmDiscoverExt(BD_ADDR bd_addr,tBTA_SERVICE_MASK_EXT * p_services,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search)1485 void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1486                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
1487 {
1488 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1489     tBTA_DM_API_DISCOVER    *p_msg;
1490     UINT16  len = p_services ? (sizeof(tBTA_DM_API_DISCOVER) + sizeof(tBT_UUID) * p_services->num_uuid) :
1491                     sizeof(tBTA_DM_API_DISCOVER);
1492 
1493     if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(len)) != NULL)
1494     {
1495         memset(p_msg, 0, len);
1496 
1497         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
1498         bdcpy(p_msg->bd_addr, bd_addr);
1499         p_msg->p_cback = p_cback;
1500         p_msg->sdp_search = sdp_search;
1501 
1502         if (p_services != NULL)
1503         {
1504             p_msg->services = p_services->srvc_mask;
1505             p_msg->num_uuid = p_services->num_uuid;
1506 
1507             if (p_services->num_uuid != 0)
1508             {
1509                 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1510                 memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
1511             }
1512         }
1513 
1514         bta_sys_sendmsg(p_msg);
1515     }
1516 #endif
1517 
1518 }
1519 
1520 /*******************************************************************************
1521 **
1522 ** Function         BTA_DmSearchExt
1523 **
1524 ** Description      This function searches for peer Bluetooth devices. It performs
1525 **                  an inquiry and gets the remote name for devices. Service
1526 **                  discovery is done if services is non zero
1527 **
1528 ** Parameters       p_dm_inq: inquiry conditions
1529 **                  p_services: if service is not empty, service discovery will be done.
1530 **                            for all GATT based service condition, put num_uuid, and
1531 **                            p_uuid is the pointer to the list of UUID values.
1532 **                  p_cback: callback functino when search is completed.
1533 **
1534 **
1535 **
1536 ** Returns          void
1537 **
1538 *******************************************************************************/
BTA_DmSearchExt(tBTA_DM_INQ * p_dm_inq,tBTA_SERVICE_MASK_EXT * p_services,tBTA_DM_SEARCH_CBACK * p_cback)1539 void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback)
1540 {
1541 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1542     tBTA_DM_API_SEARCH    *p_msg;
1543     UINT16  len = p_services ? (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid) :
1544                     sizeof(tBTA_DM_API_SEARCH);
1545 
1546     if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(len)) != NULL)
1547     {
1548         memset(p_msg, 0, len);
1549 
1550         p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
1551         memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
1552         p_msg->p_cback = p_cback;
1553         p_msg->rs_res  = BTA_DM_RS_NONE;
1554 
1555 
1556         if (p_services != NULL)
1557         {
1558             p_msg->services = p_services->srvc_mask;
1559             p_msg->num_uuid = p_services->num_uuid;
1560 
1561             if (p_services->num_uuid != 0)
1562             {
1563                 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1564                 memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
1565             }
1566             else
1567                 p_msg->p_uuid = NULL;
1568         }
1569 
1570         bta_sys_sendmsg(p_msg);
1571     }
1572 #endif
1573 }
1574 
1575 
1576 /*******************************************************************************
1577 **
1578 ** Function         BTA_DmSetEncryption
1579 **
1580 ** Description      This function is called to ensure that connection is
1581 **                  encrypted.  Should be called only on an open connection.
1582 **                  Typically only needed for connections that first want to
1583 **                  bring up unencrypted links, then later encrypt them.
1584 **
1585 ** Parameters:      bd_addr       - Address of the peer device
1586 **                  p_callback    - Pointer to callback function to indicat the
1587 **                                  link encryption status
1588 **                  sec_act       - This is the security action to indicate
1589 **                                  what knid of BLE security level is required for
1590 **                                  the BLE link if the BLE is supported
1591 **                                  Note: This parameter is ignored for the BR/EDR link
1592 **                                        or the BLE is not supported
1593 **
1594 ** Returns          void
1595 **
1596 *******************************************************************************/
BTA_DmSetEncryption(BD_ADDR bd_addr,tBTA_DM_ENCRYPT_CBACK * p_callback,tBTA_DM_BLE_SEC_ACT sec_act)1597 void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_DM_ENCRYPT_CBACK *p_callback,
1598                             tBTA_DM_BLE_SEC_ACT sec_act)
1599 {
1600     tBTA_DM_API_SET_ENCRYPTION   *p_msg;
1601 
1602     APPL_TRACE_API0("BTA_DmSetEncryption"); //todo
1603     if ((p_msg = (tBTA_DM_API_SET_ENCRYPTION *) GKI_getbuf(sizeof(tBTA_DM_API_SET_ENCRYPTION))) != NULL)
1604     {
1605         memset(p_msg, 0, sizeof(tBTA_DM_API_SET_ENCRYPTION));
1606 
1607         p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
1608 
1609         memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
1610         p_msg->p_callback      = p_callback;
1611         p_msg->sec_act         = sec_act;
1612 
1613         bta_sys_sendmsg(p_msg);
1614     }
1615 }
1616 
1617