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 "bta/bta_sys.h"
26 #include "bta/bta_api.h"
27 #include "bta_dm_int.h"
28 #include "bta_sys_int.h"
29 #include "stack/btm_api.h"
30 #include "btm_int.h"
31 #include <string.h>
32 #include "bta/utl.h"
33 #include "osi/allocator.h"
34 
35 /*****************************************************************************
36 **  Constants
37 *****************************************************************************/
38 
39 static const tBTA_SYS_REG bta_dm_reg = {
40     bta_dm_sm_execute,
41     bta_dm_sm_disable
42 };
43 
44 static const tBTA_SYS_REG bta_dm_search_reg = {
45     bta_dm_search_sm_execute,
46     bta_dm_search_sm_disable
47 };
48 
49 /*******************************************************************************
50 **
51 ** Function         BTA_EnableBluetooth
52 **
53 ** Description      Enables bluetooth service.  This function must be
54 **                  called before any other functions in the BTA API are called.
55 **
56 **
57 ** Returns          tBTA_STATUS
58 **
59 *******************************************************************************/
BTA_EnableBluetooth(tBTA_DM_SEC_CBACK * p_cback)60 tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
61 {
62 
63     tBTA_DM_API_ENABLE    *p_msg;
64 
65     /* Bluetooth disabling is in progress */
66     if (bta_dm_cb.disabling) {
67         return BTA_FAILURE;
68     }
69 
70     memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
71 
72     bta_sys_register (BTA_ID_DM, &bta_dm_reg );
73     bta_sys_register (BTA_ID_DM_SEARCH, &bta_dm_search_reg );
74 
75     /* if UUID list is not provided as static data */
76     bta_sys_eir_register(bta_dm_eir_update_uuid);
77 
78     if ((p_msg = (tBTA_DM_API_ENABLE *) osi_malloc(sizeof(tBTA_DM_API_ENABLE))) != NULL) {
79         p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
80         p_msg->p_sec_cback = p_cback;
81         bta_sys_sendmsg(p_msg);
82         return BTA_SUCCESS;
83     }
84     return BTA_FAILURE;
85 
86 }
87 
88 /*******************************************************************************
89 **
90 ** Function         BTA_DisableBluetooth
91 **
92 ** Description      Disables bluetooth service.  This function is called when
93 **                  the application no longer needs bluetooth service
94 **
95 ** Returns          void
96 **
97 *******************************************************************************/
BTA_DisableBluetooth(void)98 tBTA_STATUS BTA_DisableBluetooth(void)
99 {
100 
101     BT_HDR    *p_msg;
102 
103     if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
104         p_msg->event = BTA_DM_API_DISABLE_EVT;
105         bta_sys_sendmsg(p_msg);
106     } else {
107         return BTA_FAILURE;
108     }
109 
110     return BTA_SUCCESS;
111 }
112 
113 /*******************************************************************************
114 **
115 ** Function         BTA_EnableTestMode
116 **
117 ** Description      Enables bluetooth device under test mode
118 **
119 **
120 ** Returns          tBTA_STATUS
121 **
122 *******************************************************************************/
BTA_EnableTestMode(void)123 tBTA_STATUS BTA_EnableTestMode(void)
124 {
125     BT_HDR    *p_msg;
126 
127     APPL_TRACE_API("BTA_EnableTestMode");
128 
129     if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
130         p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
131         bta_sys_sendmsg(p_msg);
132         return BTA_SUCCESS;
133     }
134     return BTA_FAILURE;
135 }
136 
137 /*******************************************************************************
138 **
139 ** Function         BTA_DisableTestMode
140 **
141 ** Description      Disable bluetooth device under test mode
142 **
143 **
144 ** Returns          None
145 **
146 *******************************************************************************/
BTA_DisableTestMode(void)147 void BTA_DisableTestMode(void)
148 {
149     BT_HDR    *p_msg;
150 
151     APPL_TRACE_API("BTA_DisableTestMode");
152 
153     if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
154         p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
155         bta_sys_sendmsg(p_msg);
156     }
157 }
158 
159 /*******************************************************************************
160 **
161 ** Function         BTA_DmSetDeviceName
162 **
163 ** Description      This function sets the Bluetooth name of local device
164 **
165 **
166 ** Returns          void
167 **
168 *******************************************************************************/
BTA_DmSetDeviceName(const char * p_name)169 void BTA_DmSetDeviceName(const char *p_name)
170 {
171 
172     tBTA_DM_API_SET_NAME    *p_msg;
173 
174     if ((p_msg = (tBTA_DM_API_SET_NAME *) osi_malloc(sizeof(tBTA_DM_API_SET_NAME))) != NULL) {
175         p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
176         /* truncate the name if needed */
177         BCM_STRNCPY_S((char *)p_msg->name, p_name, BD_NAME_LEN);
178         p_msg->name[BD_NAME_LEN] = '\0';
179 
180         bta_sys_sendmsg(p_msg);
181     }
182 }
183 
184 /*******************************************************************************
185 **
186 ** Function         BTA_DmGetDeviceName
187 **
188 ** Description      This function gets the Bluetooth name of local device
189 **
190 **
191 ** Returns          void
192 **
193 *******************************************************************************/
BTA_DmGetDeviceName(tBTA_GET_DEV_NAME_CBACK * p_cback)194 void BTA_DmGetDeviceName(tBTA_GET_DEV_NAME_CBACK *p_cback)
195 {
196     tBTA_DM_API_GET_NAME *p_msg;
197 
198     if ((p_msg = (tBTA_DM_API_GET_NAME *) osi_malloc(sizeof(tBTA_DM_API_GET_NAME))) != NULL) {
199         p_msg->hdr.event = BTA_DM_API_GET_NAME_EVT;
200         p_msg->p_cback = p_cback;
201         bta_sys_sendmsg(p_msg);
202     }
203 }
204 
205 #if (CLASSIC_BT_INCLUDED == TRUE)
206 
BTA_DmConfigEir(tBTA_DM_EIR_CONF * eir_config)207 void BTA_DmConfigEir(tBTA_DM_EIR_CONF *eir_config)
208 {
209     tBTA_DM_API_CONFIG_EIR    *p_msg;
210 
211     UINT8 eir_manufac_spec_len = eir_config->bta_dm_eir_manufac_spec_len;
212     UINT8 eir_url_len = eir_config->bta_dm_eir_url_len;
213 
214     if (eir_manufac_spec_len > HCI_EXT_INQ_RESPONSE_LEN) {
215         APPL_TRACE_WARNING ("%s: Manufacturer data is too long(%d), cut it to %d\n",
216                             __func__, eir_manufac_spec_len, HCI_EXT_INQ_RESPONSE_LEN);
217         eir_manufac_spec_len = HCI_EXT_INQ_RESPONSE_LEN;
218     }
219     if (eir_url_len > HCI_EXT_INQ_RESPONSE_LEN) {
220         APPL_TRACE_WARNING ("%s: URL is too long(%d), cut it to %d\n",
221                             __func__, eir_url_len, HCI_EXT_INQ_RESPONSE_LEN);
222         eir_url_len = HCI_EXT_INQ_RESPONSE_LEN;
223     }
224 
225     if ((p_msg = (tBTA_DM_API_CONFIG_EIR *) osi_malloc(sizeof(tBTA_DM_API_CONFIG_EIR) + eir_manufac_spec_len + eir_url_len)) != NULL) {
226         p_msg->hdr.event = BTA_DM_API_CONFIG_EIR_EVT;
227 
228         p_msg->eir_fec_required = eir_config->bta_dm_eir_fec_required;
229         p_msg->eir_included_tx_power = eir_config->bta_dm_eir_included_tx_power;
230         p_msg->eir_included_uuid = eir_config->bta_dm_eir_included_uuid;
231         p_msg->eir_flags = eir_config->bta_dm_eir_flags;
232         p_msg->eir_manufac_spec_len = eir_manufac_spec_len;
233         p_msg->eir_manufac_spec = p_msg->data;
234         p_msg->eir_url_len = eir_url_len;
235         p_msg->eir_url = p_msg->data + eir_manufac_spec_len;
236 
237         if (eir_manufac_spec_len > 0) {
238             memcpy(p_msg->eir_manufac_spec, eir_config->bta_dm_eir_manufac_spec, eir_manufac_spec_len);
239         }
240 
241         if (eir_url_len > 0) {
242             memcpy(p_msg->eir_url, eir_config->bta_dm_eir_url, eir_url_len);
243         }
244 
245         bta_sys_sendmsg(p_msg);
246     }
247 }
248 
249 
250 /*******************************************************************************
251 **
252 ** Function         BTA_DmSetAfhChannels
253 **
254 ** Description      This function sets the AFH channels
255 **
256 **
257 ** Returns          void
258 **
259 *******************************************************************************/
BTA_DmSetAfhChannels(const uint8_t * channels,tBTA_CMPL_CB * set_afh_cb)260 void BTA_DmSetAfhChannels(const uint8_t *channels, tBTA_CMPL_CB  *set_afh_cb)
261 {
262     tBTA_DM_API_SET_AFH_CHANNELS *p_msg;
263 
264     if ((p_msg = (tBTA_DM_API_SET_AFH_CHANNELS *) osi_malloc(sizeof(tBTA_DM_API_SET_AFH_CHANNELS))) != NULL) {
265         p_msg->hdr.event = BTA_DM_API_SET_AFH_CHANNELS_EVT;
266 
267         p_msg->set_afh_cb = set_afh_cb;
268         memcpy(p_msg->channels, channels, AFH_CHANNELS_LEN);
269 
270         bta_sys_sendmsg(p_msg);
271     }
272 }
273 #endif /// CLASSIC_BT_INCLUDED == TRUE
274 
275 #if (SDP_INCLUDED == TRUE)
276 /*******************************************************************************
277 **
278 ** Function         BTA_DmGetRemoteName
279 **
280 ** Description      This function gets the peer device's Bluetooth name.
281 **
282 **
283 ** Returns          void
284 **
285 *******************************************************************************/
BTA_DmGetRemoteName(BD_ADDR remote_addr,tBTA_CMPL_CB * rmt_name_cb)286 void BTA_DmGetRemoteName(BD_ADDR remote_addr, tBTA_CMPL_CB *rmt_name_cb)
287 {
288     tBTA_DM_API_GET_REMOTE_NAME *p_msg;
289 
290     if ((p_msg = (tBTA_DM_API_GET_REMOTE_NAME *) osi_malloc(sizeof(tBTA_DM_API_GET_REMOTE_NAME))) != NULL) {
291         p_msg->hdr.event = BTA_DM_API_GET_REMOTE_NAME_EVT;
292         p_msg->rmt_name_cb = rmt_name_cb;
293         bdcpy(p_msg->rmt_addr, remote_addr);
294         bta_sys_sendmsg(p_msg);
295     }
296 }
297 #endif
298 
299 #if (BLE_INCLUDED == TRUE)
300 /*******************************************************************************
301 **
302 ** Function         BTA_DmBleSetChannels
303 **
304 ** Description      This function sets BLE channels
305 **
306 **
307 ** Returns          void
308 **
309 *******************************************************************************/
BTA_DmBleSetChannels(const uint8_t * channels,tBTA_CMPL_CB * set_channels_cb)310 void BTA_DmBleSetChannels(const uint8_t *channels, tBTA_CMPL_CB  *set_channels_cb)
311 {
312 
313     tBTA_DM_API_BLE_SET_CHANNELS *p_msg;
314 
315     if ((p_msg = (tBTA_DM_API_BLE_SET_CHANNELS *) osi_malloc(sizeof(tBTA_DM_API_BLE_SET_CHANNELS))) != NULL) {
316         p_msg->hdr.event = BTA_DM_API_BLE_SET_CHANNELS_EVT;
317 
318         p_msg->set_channels_cb = set_channels_cb;
319         memcpy(p_msg->channels, channels, BLE_CHANNELS_LEN);
320 
321         bta_sys_sendmsg(p_msg);
322     }
323 
324 
325 }
326 
BTA_DmUpdateWhiteList(BOOLEAN add_remove,BD_ADDR remote_addr,tBLE_ADDR_TYPE addr_type,tBTA_UPDATE_WHITELIST_CBACK * update_wl_cb)327 void BTA_DmUpdateWhiteList(BOOLEAN add_remove,  BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type, tBTA_UPDATE_WHITELIST_CBACK *update_wl_cb)
328 {
329     tBTA_DM_API_UPDATE_WHITE_LIST *p_msg;
330     if ((p_msg = (tBTA_DM_API_UPDATE_WHITE_LIST *)osi_malloc(sizeof(tBTA_DM_API_UPDATE_WHITE_LIST))) != NULL) {
331         p_msg->hdr.event = BTA_DM_API_UPDATE_WHITE_LIST_EVT;
332         p_msg->add_remove = add_remove;
333         p_msg->addr_type = addr_type;
334         p_msg->update_wl_cb = update_wl_cb;
335         memcpy(p_msg->remote_addr, remote_addr, sizeof(BD_ADDR));
336 
337         bta_sys_sendmsg(p_msg);
338     }
339 }
340 
BTA_DmClearWhiteList(tBTA_UPDATE_WHITELIST_CBACK * update_wl_cb)341 void BTA_DmClearWhiteList(tBTA_UPDATE_WHITELIST_CBACK *update_wl_cb)
342 {
343     tBTA_DM_API_UPDATE_WHITE_LIST *p_msg;
344     if ((p_msg = (tBTA_DM_API_UPDATE_WHITE_LIST *)osi_malloc(sizeof(tBTA_DM_API_UPDATE_WHITE_LIST))) != NULL) {
345         p_msg->hdr.event = BTA_DM_API_CLEAR_WHITE_LIST_EVT;
346         p_msg->update_wl_cb = update_wl_cb;
347 
348         bta_sys_sendmsg(p_msg);
349     }
350 }
351 
BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB * cmpl_cb)352 void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb)
353 {
354     tBTA_DM_API_READ_ADV_TX_POWER *p_msg;
355     if ((p_msg = (tBTA_DM_API_READ_ADV_TX_POWER *)osi_malloc(sizeof(tBTA_DM_API_READ_ADV_TX_POWER))) != NULL) {
356         p_msg->hdr.event = BTA_DM_API_BLE_READ_ADV_TX_POWER_EVT;
357         p_msg->read_tx_power_cb = cmpl_cb;
358         bta_sys_sendmsg(p_msg);
359     }
360 }
361 #endif  ///BLE_INCLUDED == TRUE
362 
BTA_DmReadRSSI(BD_ADDR remote_addr,tBTA_TRANSPORT transport,tBTA_CMPL_CB * cmpl_cb)363 void BTA_DmReadRSSI(BD_ADDR remote_addr, tBTA_TRANSPORT transport, tBTA_CMPL_CB *cmpl_cb)
364 {
365     tBTA_DM_API_READ_RSSI *p_msg;
366     if ((p_msg = (tBTA_DM_API_READ_RSSI *)osi_malloc(sizeof(tBTA_DM_API_READ_RSSI))) != NULL) {
367         p_msg->hdr.event = BTA_DM_API_READ_RSSI_EVT;
368         memcpy(p_msg->remote_addr, remote_addr, sizeof(BD_ADDR));
369         p_msg->transport = transport;
370         p_msg->read_rssi_cb = cmpl_cb;
371         bta_sys_sendmsg(p_msg);
372     }
373 }
374 
375 /*******************************************************************************
376 **
377 ** Function         BTA_DmSetVisibility
378 **
379 ** Description      This function sets the Bluetooth connectable,
380 **                  discoverable, pairable and conn paired only modes of local device
381 **
382 **
383 ** Returns          void
384 **
385 *******************************************************************************/
BTA_DmSetVisibility(tBTA_DM_DISC disc_mode,tBTA_DM_CONN conn_mode,UINT8 pairable_mode,UINT8 conn_filter)386 void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 pairable_mode, UINT8 conn_filter )
387 {
388 
389     tBTA_DM_API_SET_VISIBILITY    *p_msg;
390 
391     if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) osi_malloc(sizeof(tBTA_DM_API_SET_VISIBILITY))) != NULL) {
392         p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
393         p_msg->disc_mode = disc_mode;
394         p_msg->conn_mode = conn_mode;
395         p_msg->pair_mode = pairable_mode;
396         p_msg->conn_paired_only = conn_filter;
397 
398 
399         bta_sys_sendmsg(p_msg);
400     }
401 
402 
403 }
404 
405 /*******************************************************************************
406 **
407 ** Function         BTA_DmSearch
408 **
409 ** Description      This function searches for peer Bluetooth devices. It performs
410 **                  an inquiry and gets the remote name for devices. Service
411 **                  discovery is done if services is non zero
412 **
413 **
414 ** Returns          void
415 **
416 *******************************************************************************/
BTA_DmSearch(tBTA_DM_INQ * p_dm_inq,tBTA_SERVICE_MASK services,tBTA_DM_SEARCH_CBACK * p_cback)417 void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback)
418 {
419 
420     tBTA_DM_API_SEARCH    *p_msg;
421 
422     if ((p_msg = (tBTA_DM_API_SEARCH *) osi_malloc(sizeof(tBTA_DM_API_SEARCH))) != NULL) {
423         memset(p_msg, 0, sizeof(tBTA_DM_API_SEARCH));
424 
425         p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
426         memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
427         p_msg->services = services;
428         p_msg->p_cback = p_cback;
429         p_msg->rs_res  = BTA_DM_RS_NONE;
430         bta_sys_sendmsg(p_msg);
431     }
432 
433 }
434 
435 
436 /*******************************************************************************
437 **
438 ** Function         BTA_DmSearchCancel
439 **
440 ** Description      This function  cancels a search initiated by BTA_DmSearch
441 **
442 **
443 ** Returns          void
444 **
445 *******************************************************************************/
BTA_DmSearchCancel(void)446 void BTA_DmSearchCancel(void)
447 {
448     BT_HDR    *p_msg;
449 
450     if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
451         p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
452         bta_sys_sendmsg(p_msg);
453     }
454 
455 }
456 
457 #if (SDP_INCLUDED == TRUE)
458 /*******************************************************************************
459 **
460 ** Function         BTA_DmDiscover
461 **
462 ** Description      This function does service discovery for services of a
463 **                  peer device
464 **
465 **
466 ** Returns          void
467 **
468 *******************************************************************************/
BTA_DmDiscover(BD_ADDR bd_addr,tBTA_SERVICE_MASK services,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search)469 void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
470                     tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
471 {
472     tBTA_DM_API_DISCOVER    *p_msg;
473 
474     if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
475         memset(p_msg, 0, sizeof(tBTA_DM_API_DISCOVER));
476 
477         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
478         bdcpy(p_msg->bd_addr, bd_addr);
479         p_msg->services = services;
480         p_msg->p_cback = p_cback;
481         p_msg->sdp_search = sdp_search;
482         bta_sys_sendmsg(p_msg);
483     }
484 }
485 
486 /*******************************************************************************
487 **
488 ** Function         BTA_DmDiscoverUUID
489 **
490 ** Description      This function does service discovery for services of a
491 **                  peer device
492 **
493 **
494 ** Returns          void
495 **
496 *******************************************************************************/
BTA_DmDiscoverUUID(BD_ADDR bd_addr,tSDP_UUID * uuid,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search)497 void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
498                         tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
499 {
500     tBTA_DM_API_DISCOVER    *p_msg;
501 
502     if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
503         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
504         bdcpy(p_msg->bd_addr, bd_addr);
505         p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level
506         p_msg->p_cback = p_cback;
507         p_msg->sdp_search = sdp_search;
508 
509 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
510         p_msg->num_uuid = 0;
511         p_msg->p_uuid = NULL;
512 #endif
513         memcpy( &p_msg->uuid, uuid, sizeof(tSDP_UUID) );
514         bta_sys_sendmsg(p_msg);
515     }
516 }
517 #endif  ///SDP_INCLUDED == TRUE
518 
519 /*******************************************************************************
520 **
521 ** Function         BTA_DmBond
522 **
523 ** Description      This function initiates a bonding procedure with a peer
524 **                  device
525 **
526 **
527 ** Returns          void
528 **
529 *******************************************************************************/
530 #if (SMP_INCLUDED == TRUE)
BTA_DmBond(BD_ADDR bd_addr)531 void BTA_DmBond(BD_ADDR bd_addr)
532 {
533     tBTA_DM_API_BOND    *p_msg;
534 
535     p_msg = (tBTA_DM_API_BOND *) osi_malloc(sizeof(tBTA_DM_API_BOND));
536     if (p_msg != NULL) {
537         p_msg->hdr.event = BTA_DM_API_BOND_EVT;
538         bdcpy(p_msg->bd_addr, bd_addr);
539         p_msg->transport = BTA_TRANSPORT_UNKNOWN;
540         bta_sys_sendmsg(p_msg);
541     }
542 }
543 
544 /*******************************************************************************
545 **
546 ** Function         BTA_DmBondByTransports
547 **
548 ** Description      This function initiates a bonding procedure with a peer
549 **                  device
550 **
551 **
552 ** Returns          void
553 **
554 *******************************************************************************/
BTA_DmBondByTransport(BD_ADDR bd_addr,tBTA_TRANSPORT transport)555 void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport)
556 {
557     tBTA_DM_API_BOND    *p_msg;
558 
559     if ((p_msg = (tBTA_DM_API_BOND *) osi_malloc(sizeof(tBTA_DM_API_BOND))) != NULL) {
560         p_msg->hdr.event = BTA_DM_API_BOND_EVT;
561         bdcpy(p_msg->bd_addr, bd_addr);
562         p_msg->transport = transport;
563         bta_sys_sendmsg(p_msg);
564     }
565 
566 
567 }
568 
569 /*******************************************************************************
570 **
571 ** Function         BTA_DmBondCancel
572 **
573 ** Description      This function cancels the bonding procedure with a peer
574 **                  device
575 **
576 **
577 ** Returns          void
578 **
579 *******************************************************************************/
BTA_DmBondCancel(BD_ADDR bd_addr)580 void BTA_DmBondCancel(BD_ADDR bd_addr)
581 {
582     tBTA_DM_API_BOND_CANCEL    *p_msg;
583 
584     if ((p_msg = (tBTA_DM_API_BOND_CANCEL *) osi_malloc(sizeof(tBTA_DM_API_BOND_CANCEL))) != NULL) {
585         p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
586         bdcpy(p_msg->bd_addr, bd_addr);
587         bta_sys_sendmsg(p_msg);
588     }
589 }
590 #endif  ///SMP_INCLUDED == TRUE
591 
592 #if (CLASSIC_BT_INCLUDED == TRUE)
593 /*******************************************************************************
594 **
595 ** Function         BTA_DMSetPinType
596 **
597 ** Description      This function set pin type as BTM_PIN_TYPE_FIXED or BTM_PIN_TYPE_VARIABLE
598 **
599 **
600 ** Returns          void
601 **
602 *******************************************************************************/
BTA_DMSetPinType(UINT8 pin_type,UINT8 * pin_code,UINT8 pin_code_len)603 void BTA_DMSetPinType (UINT8 pin_type, UINT8 *pin_code, UINT8 pin_code_len)
604 {
605     tBTA_DM_API_SET_PIN_TYPE    *p_msg;
606 
607     if ((p_msg = (tBTA_DM_API_SET_PIN_TYPE *) osi_malloc(sizeof(tBTA_DM_API_SET_PIN_TYPE))) != NULL) {
608         p_msg->hdr.event = BTA_DM_API_SET_PIN_TYPE_EVT;
609         p_msg->pin_type = pin_type;
610         p_msg->pin_len = pin_code_len;
611         memcpy(p_msg->p_pin, pin_code, pin_code_len);
612         bta_sys_sendmsg(p_msg);
613     }
614 }
615 
616 /*******************************************************************************
617 **
618 ** Function         BTA_DmPinReply
619 **
620 ** Description      This function provides a pincode for a remote device when
621 **                  one is requested by DM through BTA_DM_PIN_REQ_EVT
622 **
623 **
624 ** Returns          void
625 **
626 *******************************************************************************/
BTA_DmPinReply(BD_ADDR bd_addr,BOOLEAN accept,UINT8 pin_len,UINT8 * p_pin)627 void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin)
628 {
629     tBTA_DM_API_PIN_REPLY    *p_msg;
630 
631     if ((p_msg = (tBTA_DM_API_PIN_REPLY *) osi_malloc(sizeof(tBTA_DM_API_PIN_REPLY))) != NULL) {
632         p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
633         bdcpy(p_msg->bd_addr, bd_addr);
634         p_msg->accept = accept;
635         if (accept) {
636             p_msg->pin_len = pin_len;
637             memcpy(p_msg->p_pin, p_pin, pin_len);
638         }
639         bta_sys_sendmsg(p_msg);
640     }
641 
642 }
643 #endif  ///CLASSIC_BT_INCLUDED == TRUE
644 
645 #if (BTM_OOB_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
646 /*******************************************************************************
647 **
648 ** Function         BTA_DmLocalOob
649 **
650 ** Description      This function retrieves the OOB data from local controller.
651 **                  The result is reported by:
652 **                  - bta_dm_co_loc_oob_ext() if device supports secure
653 **                    connections (SC)
654 **                  - bta_dm_co_loc_oob() if device doesn't support SC
655 **
656 ** Returns          void
657 **
658 *******************************************************************************/
BTA_DmLocalOob(void)659 void BTA_DmLocalOob(void)
660 {
661     tBTA_DM_API_LOC_OOB    *p_msg;
662 
663     if ((p_msg = (tBTA_DM_API_LOC_OOB *) osi_malloc(sizeof(tBTA_DM_API_LOC_OOB))) != NULL) {
664         p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
665         bta_sys_sendmsg(p_msg);
666     }
667 }
668 
669 /*******************************************************************************
670 **
671 ** Function         BTA_DmOobReply
672 **
673 **                  This function is called to provide the OOB data for
674 **                  SMP in response to BTA_LE_OOB_REQ_EVT
675 **
676 ** Parameters:      bd_addr     - Address of the peer device
677 **                  len         - length of simple pairing Randomizer  C
678 **                  p_value     - simple pairing Randomizer  C.
679 **
680 ** Returns          void
681 **
682 *******************************************************************************/
BTA_DmOobReply(BD_ADDR bd_addr,UINT8 len,UINT8 * p_value)683 void BTA_DmOobReply(BD_ADDR bd_addr, UINT8 len, UINT8 *p_value)
684 {
685     tBTA_DM_API_OOB_REPLY    *p_msg;
686 
687     if ((p_msg = (tBTA_DM_API_OOB_REPLY *) osi_malloc(sizeof(tBTA_DM_API_OOB_REPLY))) != NULL) {
688         p_msg->hdr.event = BTA_DM_API_OOB_REPLY_EVT;
689         if(p_value == NULL || len > BT_OCTET16_LEN) {
690             osi_free(p_msg);
691             return;
692         }
693         memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
694         p_msg->len = len;
695         memcpy(p_msg->value, p_value, len);
696         bta_sys_sendmsg(p_msg);
697     }
698 }
699 
700 /*******************************************************************************
701 **
702 ** Function         BTA_DmSecureConnectionOobReply
703 **
704 **                  This function is called to provide the OOB data for
705 **                  SMP in response to BTA_LE_OOB_REQ_EVT
706 **
707 ** Parameters:      bd_addr     - Address of the peer device
708 **                  p_c         - Pointer to Confirmation
709 **                  p_r         - Pointer to Randomizer
710 **
711 ** Returns          void
712 **
713 *******************************************************************************/
BTA_DmSecureConnectionOobReply(BD_ADDR bd_addr,UINT8 * p_c,UINT8 * p_r)714 void BTA_DmSecureConnectionOobReply(BD_ADDR bd_addr, UINT8 *p_c, UINT8 *p_r)
715 {
716     tBTA_DM_API_SC_OOB_REPLY    *p_msg;
717 
718     if ((p_msg = (tBTA_DM_API_SC_OOB_REPLY *) osi_malloc(sizeof(tBTA_DM_API_OOB_REPLY))) != NULL) {
719         p_msg->hdr.event = BTA_DM_API_SC_OOB_REPLY_EVT;
720         if((p_c == NULL) || (p_r == NULL)) {
721             return;
722         }
723         memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
724         memcpy(p_msg->c, p_c, BT_OCTET16_LEN);
725         memcpy(p_msg->r, p_r, BT_OCTET16_LEN);
726         bta_sys_sendmsg(p_msg);
727     }
728 }
729 /*******************************************************************************
730 **
731 ** Function         BTA_DmSecureConnectionCreateOobData
732 **
733 **                  This function is called to create the OOB data for
734 **                  SMP when secure connection
735 **
736 ** Returns          void
737 **
738 *******************************************************************************/
BTA_DmSecureConnectionCreateOobData(void)739 void BTA_DmSecureConnectionCreateOobData(void)
740 {
741     tBTA_DM_API_SC_CR_OOB_DATA *p_msg;
742 
743     if ((p_msg = (tBTA_DM_API_SC_CR_OOB_DATA *) osi_malloc(sizeof(tBTA_DM_API_SC_CR_OOB_DATA))) != NULL) {
744         p_msg->hdr.event = BTA_DM_API_SC_CR_OOB_DATA_EVT;
745         bta_sys_sendmsg(p_msg);
746     }
747 }
748 #endif /* BTM_OOB_INCLUDED */
749 /*******************************************************************************
750 **
751 ** Function         BTA_DmConfirm
752 **
753 ** Description      This function accepts or rejects the numerical value of the
754 **                  Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
755 **
756 ** Returns          void
757 **
758 *******************************************************************************/
759 #if (SMP_INCLUDED == TRUE)
BTA_DmConfirm(BD_ADDR bd_addr,BOOLEAN accept)760 void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept)
761 {
762     tBTA_DM_API_CONFIRM    *p_msg;
763 
764     if ((p_msg = (tBTA_DM_API_CONFIRM *) osi_malloc(sizeof(tBTA_DM_API_CONFIRM))) != NULL) {
765         p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
766         bdcpy(p_msg->bd_addr, bd_addr);
767         p_msg->accept = accept;
768         bta_sys_sendmsg(p_msg);
769     }
770 }
771 
772 /*******************************************************************************
773 **
774 ** Function         BTA_DmPasskeyReqReply
775 **
776 ** Description      This function is called to provide the passkey for
777 **                  Simple Pairing in response to BTA_DM_SP_KEY_REQ_EVT
778 **
779 ** Returns          void
780 **
781 *******************************************************************************/
782 #if (BT_SSP_INCLUDED == TRUE)
BTA_DmPasskeyReqReply(BOOLEAN accept,BD_ADDR bd_addr,UINT32 passkey)783 void BTA_DmPasskeyReqReply(BOOLEAN accept, BD_ADDR bd_addr, UINT32 passkey)
784 {
785     tBTA_DM_API_KEY_REQ    *p_msg;
786     if ((p_msg = (tBTA_DM_API_KEY_REQ *) osi_malloc(sizeof(tBTA_DM_API_KEY_REQ))) != NULL) {
787         p_msg->hdr.event = BTA_DM_API_KEY_REQ_EVT;
788         bdcpy(p_msg->bd_addr, bd_addr);
789         p_msg->accept = accept;
790         p_msg->passkey = passkey;
791         bta_sys_sendmsg(p_msg);
792     }
793 }
794 #endif ///BT_SSP_INCLUDED == TRUE
795 #endif  ///SMP_INCLUDED == TRUE
796 /*******************************************************************************
797 **
798 ** Function         BTA_DmAddDevice
799 **
800 ** Description      This function adds a device to the security database list of
801 **                  peer device
802 **
803 **
804 ** Returns          void
805 **
806 *******************************************************************************/
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,UINT8 pin_length,UINT8 sc_support)807 void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
808                      tBTA_SERVICE_MASK trusted_mask, BOOLEAN is_trusted,
809                      UINT8 key_type, tBTA_IO_CAP io_cap, UINT8 pin_length,
810                      UINT8 sc_support)
811 {
812 
813     tBTA_DM_API_ADD_DEVICE *p_msg;
814 
815     if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL) {
816         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE));
817 
818         p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
819         bdcpy(p_msg->bd_addr, bd_addr);
820         p_msg->tm = trusted_mask;
821         p_msg->is_trusted = is_trusted;
822         p_msg->io_cap = io_cap;
823         p_msg->sc_support = sc_support;
824 
825         if (link_key) {
826             p_msg->link_key_known = TRUE;
827             p_msg->key_type = key_type;
828             memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
829         }
830 
831         /* Load device class if specified */
832         if (dev_class) {
833             p_msg->dc_known = TRUE;
834             memcpy (p_msg->dc, dev_class, DEV_CLASS_LEN);
835         }
836 
837         memset (p_msg->bd_name, 0, BD_NAME_LEN + 1);
838         memset (p_msg->features, 0, sizeof (p_msg->features));
839         p_msg->pin_length = pin_length;
840 
841         bta_sys_sendmsg(p_msg);
842     }
843 }
844 
845 
846 /*******************************************************************************
847 **
848 ** Function         BTA_DmRemoveDevice
849 **
850 ** Description      This function removes a device fromthe security database list of
851 **                  peer device. It manages unpairing even while connected.
852 **
853 **
854 ** Returns          void
855 **
856 *******************************************************************************/
BTA_DmRemoveDevice(BD_ADDR bd_addr,tBT_TRANSPORT transport)857 tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr, tBT_TRANSPORT transport)
858 {
859     tBTA_DM_API_REMOVE_DEVICE *p_msg;
860 
861     if ((p_msg = (tBTA_DM_API_REMOVE_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_REMOVE_DEVICE))) != NULL) {
862         memset (p_msg, 0, sizeof(tBTA_DM_API_REMOVE_DEVICE));
863 
864         p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
865         bdcpy(p_msg->bd_addr, bd_addr);
866         p_msg->transport = transport;
867         bta_sys_sendmsg(p_msg);
868     } else {
869         return BTA_FAILURE;
870     }
871 
872     return BTA_SUCCESS;
873 }
874 // #endif  ///SMP_INCLUDED == TRUE
875 
876 /*******************************************************************************
877 **
878 ** Function         BTA_GetEirService
879 **
880 ** Description      This function is called to get BTA service mask from EIR.
881 **
882 ** Parameters       p_eir - pointer of EIR significant part
883 **                  p_services - return the BTA service mask
884 **
885 ** Returns          None
886 **
887 *******************************************************************************/
888 extern const UINT16 bta_service_id_to_uuid_lkup_tbl [];
BTA_GetEirService(UINT8 * p_eir,tBTA_SERVICE_MASK * p_services)889 void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services )
890 {
891     UINT8 xx, yy;
892     UINT8 num_uuid, max_num_uuid = 32;
893     UINT8 uuid_list[32 * LEN_UUID_16];
894     UINT16 *p_uuid16 = (UINT16 *)uuid_list;
895     tBTA_SERVICE_MASK mask;
896 
897     BTM_GetEirUuidList( p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid);
898     for ( xx = 0; xx < num_uuid; xx++ ) {
899         mask = 1;
900         for ( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ ) {
901             if ( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] ) {
902                 *p_services |= mask;
903                 break;
904             }
905             mask <<= 1;
906         }
907 
908         /* for HSP v1.2 only device */
909         if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS) {
910             *p_services |= BTA_HSP_SERVICE_MASK;
911         }
912 
913         if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE) {
914             *p_services |= BTA_HL_SERVICE_MASK;
915         }
916 
917         if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK) {
918             *p_services |= BTA_HL_SERVICE_MASK;
919         }
920     }
921 }
922 
923 /*******************************************************************************
924 **
925 ** Function         BTA_DmGetConnectionState
926 **
927 ** Description      Returns whether the remote device is currently connected.
928 **
929 ** Returns          0 if the device is NOT connected.
930 **
931 *******************************************************************************/
BTA_DmGetConnectionState(BD_ADDR bd_addr)932 UINT16 BTA_DmGetConnectionState( BD_ADDR bd_addr )
933 {
934     tBTA_DM_PEER_DEVICE *p_dev = bta_dm_find_peer_device(bd_addr);
935     return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
936 }
937 
938 #if (SDP_INCLUDED == TRUE)
939 /*******************************************************************************
940 **                   Device Identification (DI) Server Functions
941 *******************************************************************************/
942 /*******************************************************************************
943 **
944 ** Function         BTA_DmSetLocalDiRecord
945 **
946 ** Description      This function adds a DI record to the local SDP database.
947 **
948 ** Returns          BTA_SUCCESS if record set successfully, otherwise error code.
949 **
950 *******************************************************************************/
BTA_DmSetLocalDiRecord(tBTA_DI_RECORD * p_device_info,UINT32 * p_handle)951 tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
952                                     UINT32 *p_handle )
953 {
954     tBTA_STATUS  status = BTA_FAILURE;
955 
956     if (bta_dm_di_cb.di_num < BTA_DI_NUM_MAX) {
957         if (SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS) {
958             if (!p_device_info->primary_record) {
959                 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
960                 bta_dm_di_cb.di_num ++;
961             }
962 
963             bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
964             status =  BTA_SUCCESS;
965         }
966     }
967 
968     return status;
969 }
970 #endif  ///SDP_INCLUDED == TRUE
971 /*******************************************************************************
972 **
973 ** Function         bta_dmexecutecallback
974 **
975 ** Description      This function will request BTA to execute a call back in the context of BTU task
976 **                  This API was named in lower case because it is only intended
977 **                  for the internal customers(like BTIF).
978 **
979 ** Returns          void
980 **
981 *******************************************************************************/
bta_dmexecutecallback(tBTA_DM_EXEC_CBACK * p_callback,void * p_param)982 void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK *p_callback, void *p_param)
983 {
984     tBTA_DM_API_EXECUTE_CBACK *p_msg;
985 
986     if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) osi_malloc(sizeof(tBTA_DM_API_EXECUTE_CBACK))) != NULL) {
987         p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
988         p_msg->p_param = p_param;
989         p_msg->p_exec_cback = p_callback;
990         bta_sys_sendmsg(p_msg);
991     }
992 }
993 
994 /*******************************************************************************
995 **
996 ** Function         BTA_DmAddBleKey
997 **
998 ** Description      Add/modify LE device information.  This function will be
999 **                  normally called during host startup to restore all required
1000 **                  information stored in the NVRAM.
1001 **
1002 ** Parameters:      bd_addr          - BD address of the peer
1003 **                  p_le_key         - LE key values.
1004 **                  key_type         - LE SMP key type.
1005 **
1006 ** Returns          BTA_SUCCESS if successful
1007 **                  BTA_FAIL if operation failed.
1008 **
1009 *******************************************************************************/
1010 #if BLE_INCLUDED == TRUE
1011 #if SMP_INCLUDED == TRUE
BTA_DmAddBleKey(BD_ADDR bd_addr,tBTA_LE_KEY_VALUE * p_le_key,tBTA_LE_KEY_TYPE key_type)1012 void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_TYPE key_type)
1013 {
1014     tBTA_DM_API_ADD_BLEKEY *p_msg;
1015 
1016     if ((p_msg = (tBTA_DM_API_ADD_BLEKEY *) osi_malloc(sizeof(tBTA_DM_API_ADD_BLEKEY))) != NULL) {
1017         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLEKEY));
1018 
1019         p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
1020         p_msg->key_type = key_type;
1021         bdcpy(p_msg->bd_addr, bd_addr);
1022         memcpy(&p_msg->blekey, p_le_key, sizeof(tBTA_LE_KEY_VALUE));
1023 
1024         bta_sys_sendmsg(p_msg);
1025     }
1026 
1027 }
1028 
1029 /*******************************************************************************
1030 **
1031 ** Function         BTA_DmAddBleDevice
1032 **
1033 ** Description      Add a BLE device.  This function will be normally called
1034 **                  during host startup to restore all required information
1035 **                  for a LE device stored in the NVRAM.
1036 **
1037 ** Parameters:      bd_addr          - BD address of the peer
1038 **                  dev_type         - Remote device's device type.
1039 **                  auth_mode        - auth mode
1040 **                  addr_type        - LE device address type.
1041 **
1042 ** Returns          void
1043 **
1044 *******************************************************************************/
BTA_DmAddBleDevice(BD_ADDR bd_addr,tBLE_ADDR_TYPE addr_type,int auth_mode,tBT_DEVICE_TYPE dev_type)1045 void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, int auth_mode, tBT_DEVICE_TYPE dev_type)
1046 {
1047     tBTA_DM_API_ADD_BLE_DEVICE *p_msg;
1048 
1049     if ((p_msg = (tBTA_DM_API_ADD_BLE_DEVICE *) osi_malloc(sizeof(tBTA_DM_API_ADD_BLE_DEVICE))) != NULL) {
1050         memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
1051 
1052         p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
1053         bdcpy(p_msg->bd_addr, bd_addr);
1054         p_msg->addr_type = addr_type;
1055         p_msg->auth_mode = auth_mode;
1056         p_msg->dev_type = dev_type;
1057 
1058         bta_sys_sendmsg(p_msg);
1059     }
1060 }
1061 /*******************************************************************************
1062 **
1063 ** Function         BTA_DmBlePasskeyReply
1064 **
1065 ** Description      Send BLE SMP passkey reply.
1066 **
1067 ** Parameters:      bd_addr          - BD address of the peer
1068 **                  accept           - passkey entry sucessful or declined.
1069 **                  passkey          - passkey value, must be a 6 digit number,
1070 **                                     can be lead by 0.
1071 **
1072 ** Returns          void
1073 **
1074 *******************************************************************************/
BTA_DmBlePasskeyReply(BD_ADDR bd_addr,BOOLEAN accept,UINT32 passkey)1075 void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey)
1076 {
1077     tBTA_DM_API_PASSKEY_REPLY    *p_msg;
1078 
1079     if ((p_msg = (tBTA_DM_API_PASSKEY_REPLY *) osi_malloc(sizeof(tBTA_DM_API_PASSKEY_REPLY))) != NULL) {
1080         memset(p_msg, 0, sizeof(tBTA_DM_API_PASSKEY_REPLY));
1081 
1082         p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
1083         bdcpy(p_msg->bd_addr, bd_addr);
1084         p_msg->accept = accept;
1085 
1086         if (accept) {
1087             p_msg->passkey = passkey;
1088         }
1089         bta_sys_sendmsg(p_msg);
1090     }
1091 }
1092 
BTA_DmBleSetStaticPasskey(bool add,uint32_t passkey)1093 void BTA_DmBleSetStaticPasskey(bool add, uint32_t passkey)
1094 {
1095     tBTA_DM_API_SET_DEFAULT_PASSKEY    *p_msg;
1096 
1097     if ((p_msg = (tBTA_DM_API_SET_DEFAULT_PASSKEY *) osi_malloc(sizeof(tBTA_DM_API_SET_DEFAULT_PASSKEY))) != NULL) {
1098         memset(p_msg, 0, sizeof(tBTA_DM_API_SET_DEFAULT_PASSKEY));
1099 
1100         p_msg->hdr.event = BTA_DM_API_BLE_SET_STATIC_PASSKEY_EVT;
1101         p_msg->add = add;
1102         p_msg->static_passkey = passkey;
1103         bta_sys_sendmsg(p_msg);
1104     }
1105 }
1106 
1107 /*******************************************************************************
1108 **
1109 ** Function         BTA_DmBleConfirmReply
1110 **
1111 ** Description      Send BLE SMP SC user confirmation reply.
1112 **
1113 ** Parameters:      bd_addr          - BD address of the peer
1114 **                  accept           - numbers to compare are the same or different.
1115 **
1116 ** Returns          void
1117 **
1118 *******************************************************************************/
BTA_DmBleConfirmReply(BD_ADDR bd_addr,BOOLEAN accept)1119 void BTA_DmBleConfirmReply(BD_ADDR bd_addr, BOOLEAN accept)
1120 {
1121     tBTA_DM_API_CONFIRM *p_msg = (tBTA_DM_API_CONFIRM *)osi_malloc(sizeof(tBTA_DM_API_CONFIRM));
1122     if (p_msg != NULL) {
1123         memset(p_msg, 0, sizeof(tBTA_DM_API_CONFIRM));
1124         p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT;
1125         bdcpy(p_msg->bd_addr, bd_addr);
1126         p_msg->accept = accept;
1127         bta_sys_sendmsg(p_msg);
1128     }
1129 }
1130 
1131 /*******************************************************************************
1132 **
1133 ** Function         BTA_DmBleSecurityGrant
1134 **
1135 ** Description      Grant security request access.
1136 **
1137 ** Parameters:      bd_addr          - BD address of the peer
1138 **                  res              - security grant status.
1139 **
1140 ** Returns          void
1141 **
1142 *******************************************************************************/
BTA_DmBleSecurityGrant(BD_ADDR bd_addr,tBTA_DM_BLE_SEC_GRANT res)1143 void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
1144 {
1145     tBTA_DM_API_BLE_SEC_GRANT    *p_msg;
1146 
1147     if ((p_msg = (tBTA_DM_API_BLE_SEC_GRANT *) osi_malloc(sizeof(tBTA_DM_API_BLE_SEC_GRANT))) != NULL) {
1148         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SEC_GRANT));
1149 
1150         p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
1151         bdcpy(p_msg->bd_addr, bd_addr);
1152         p_msg->res = res;
1153 
1154         bta_sys_sendmsg(p_msg);
1155     }
1156 }
1157 #endif  ///SMP_INCLUDED == TRUE
1158 
1159 
1160 /*******************************************************************************
1161 **
1162 ** Function         BTA_DmSetBlePrefConnParams
1163 **
1164 ** Description      This function is called to set the preferred connection
1165 **                  parameters when default connection parameter is not desired.
1166 **
1167 ** Parameters:      bd_addr          - BD address of the peripheral
1168 **                  scan_interval    - scan interval
1169 **                  scan_window      - scan window
1170 **                  min_conn_int     - minimum preferred connection interval
1171 **                  max_conn_int     - maximum preferred connection interval
1172 **                  slave_latency    - preferred slave latency
1173 **                  supervision_tout - preferred supervision timeout
1174 **
1175 **
1176 ** Returns          void
1177 **
1178 *******************************************************************************/
BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,UINT16 min_conn_int,UINT16 max_conn_int,UINT16 slave_latency,UINT16 supervision_tout)1179 void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,
1180                                 UINT16 min_conn_int, UINT16 max_conn_int,
1181                                 UINT16 slave_latency, UINT16 supervision_tout )
1182 {
1183 #if BLE_INCLUDED == TRUE
1184     tBTA_DM_API_BLE_CONN_PARAMS    *p_msg;
1185 
1186     if ((p_msg = (tBTA_DM_API_BLE_CONN_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_BLE_CONN_PARAMS))) != NULL) {
1187         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
1188 
1189         p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
1190 
1191         memcpy(p_msg->peer_bda, bd_addr, BD_ADDR_LEN);
1192 
1193         p_msg->conn_int_max     = max_conn_int;
1194         p_msg->conn_int_min     = min_conn_int;
1195         p_msg->slave_latency    = slave_latency;
1196         p_msg->supervision_tout = supervision_tout;
1197 
1198         bta_sys_sendmsg(p_msg);
1199     }
1200 #endif
1201 }
1202 
1203 /*******************************************************************************
1204 **
1205 ** Function         BTA_DmSetBleConnScanParams
1206 **
1207 ** Description      This function is called to set scan parameters used in
1208 **                  BLE connection request
1209 **
1210 ** Parameters:      scan_interval    - scan interval
1211 **                  scan_window      - scan window
1212 **
1213 ** Returns          void
1214 **
1215 *******************************************************************************/
BTA_DmSetBleConnScanParams(UINT32 scan_interval,UINT32 scan_window)1216 void BTA_DmSetBleConnScanParams(UINT32 scan_interval, UINT32 scan_window)
1217 {
1218     tBTA_DM_API_BLE_SCAN_PARAMS  *p_msg;
1219     if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
1220         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
1221         p_msg->hdr.event = BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT;
1222         p_msg->scan_int         = scan_interval;
1223         p_msg->scan_window      = scan_window;
1224         bta_sys_sendmsg(p_msg);
1225     }
1226 }
1227 
1228 /*******************************************************************************
1229 **
1230 ** Function         BTA_DmSetBleScanParams
1231 **
1232 ** Description      This function is called to set scan parameters
1233 **
1234 ** Parameters:      client_if - Client IF
1235 **                  scan_interval - scan interval
1236 **                  scan_window - scan window
1237 **                  scan_mode - scan mode
1238 **                  scan_param_setup_status_cback - Set scan param status callback
1239 **
1240 ** Returns          void
1241 **
1242 *******************************************************************************/
BTA_DmSetBleScanParams(tGATT_IF client_if,UINT32 scan_interval,UINT32 scan_window,tBLE_SCAN_MODE scan_mode,tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)1243 void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval,
1244                             UINT32 scan_window, tBLE_SCAN_MODE scan_mode,
1245                             tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
1246 {
1247     tBTA_DM_API_BLE_SCAN_PARAMS *p_msg;
1248 
1249     if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
1250         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
1251         p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT;
1252         p_msg->client_if = client_if;
1253         p_msg->scan_int = scan_interval;
1254         p_msg->scan_window = scan_window;
1255         p_msg->scan_mode = scan_mode;
1256         p_msg->scan_param_setup_cback = scan_param_setup_cback;
1257 
1258         bta_sys_sendmsg(p_msg);
1259     }
1260 }
1261 
1262 
1263 /*******************************************************************************
1264 **
1265 ** Function         BTA_DmSetBleScanFilterParams
1266 **
1267 ** Description      This function is called to set scan parameters
1268 **
1269 ** Parameters:      client_if - Client IF
1270 **                  scan_interval - scan interval
1271 **                  scan_window - scan window
1272 **                  scan_mode - scan mode
1273 **                  scan_duplicate_filter - scan duplicate filter
1274 **                  scan_param_setup_status_cback - Set scan param status callback
1275 **
1276 ** Returns          void
1277 **
1278 *******************************************************************************/
BTA_DmSetBleScanFilterParams(tGATT_IF client_if,UINT32 scan_interval,UINT32 scan_window,tBLE_SCAN_MODE scan_mode,UINT8 scan_fil_poilcy,UINT8 addr_type_own,UINT8 scan_duplicate_filter,tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)1279 void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval,
1280                                   UINT32 scan_window, tBLE_SCAN_MODE scan_mode, UINT8 scan_fil_poilcy,
1281                                   UINT8 addr_type_own, UINT8 scan_duplicate_filter, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
1282 {
1283     tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *p_msg;
1284 
1285     if ((p_msg = (tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS))) != NULL) {
1286         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS));
1287         p_msg->hdr.event = BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT;
1288         p_msg->client_if = client_if;
1289         p_msg->scan_int = scan_interval;
1290         p_msg->scan_window = scan_window;
1291         p_msg->scan_mode = scan_mode;
1292         p_msg->addr_type_own = addr_type_own;
1293         p_msg->scan_duplicate_filter = scan_duplicate_filter;
1294         p_msg->scan_filter_policy = scan_fil_poilcy;
1295         p_msg->scan_param_setup_cback = scan_param_setup_cback;
1296 
1297         bta_sys_sendmsg(p_msg);
1298     }
1299 
1300 
1301 }
1302 
1303 /*******************************************************************************
1304 **
1305 ** Function         BTA_DmSetBleAdvParams
1306 **
1307 ** Description      This function sets the advertising parameters BLE functionality.
1308 **                  It is to be called when device act in peripheral or broadcaster
1309 **                  role.
1310 **
1311 **
1312 ** Returns          void
1313 **
1314 *******************************************************************************/
BTA_DmSetBleAdvParams(UINT16 adv_int_min,UINT16 adv_int_max,tBLE_BD_ADDR * p_dir_bda)1315 void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
1316                             tBLE_BD_ADDR *p_dir_bda)
1317 {
1318 #if BLE_INCLUDED == TRUE
1319     tBTA_DM_API_BLE_ADV_PARAMS    *p_msg;
1320 
1321     APPL_TRACE_API ("BTA_DmSetBleAdvParam: %d, %d\n", adv_int_min, adv_int_max);
1322 
1323     if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_BLE_ADV_PARAMS)
1324                  + sizeof(tBLE_BD_ADDR))) != NULL) {
1325         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS) + sizeof(tBLE_BD_ADDR));
1326 
1327         p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_EVT;
1328 
1329         p_msg->adv_int_min      = adv_int_min;
1330         p_msg->adv_int_max      = adv_int_max;
1331 
1332         if (p_dir_bda != NULL) {
1333             p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
1334             memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
1335         }
1336 
1337         bta_sys_sendmsg(p_msg);
1338     }
1339 #endif
1340 }
1341 
BTA_DmSetBleAdvParamsAll(UINT16 adv_int_min,UINT16 adv_int_max,UINT8 adv_type,tBLE_ADDR_TYPE addr_type_own,tBTM_BLE_ADV_CHNL_MAP chnl_map,tBTM_BLE_AFP adv_fil_pol,tBLE_BD_ADDR * p_dir_bda,tBTA_START_ADV_CMPL_CBACK p_start_adv_cb)1342 void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max,
1343                                UINT8 adv_type, tBLE_ADDR_TYPE addr_type_own,
1344                                tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP adv_fil_pol,
1345                                tBLE_BD_ADDR *p_dir_bda, tBTA_START_ADV_CMPL_CBACK p_start_adv_cb)
1346 {
1347 #if BLE_INCLUDED == TRUE
1348     tBTA_DM_API_BLE_ADV_PARAMS_ALL    *p_msg;
1349 
1350     APPL_TRACE_API ("BTA_DmSetBleAdvParamsAll: %d, %d\n", adv_int_min, adv_int_max);
1351     APPL_TRACE_API ("adv_type = %d, addr_type_own = %d, chnl_map = %d, adv_fil_pol = %d\n",
1352                       adv_type, addr_type_own, chnl_map, adv_fil_pol);
1353     if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS_ALL *) osi_malloc(sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL)
1354                  + sizeof(tBLE_BD_ADDR))) != NULL) {
1355         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL));
1356 
1357         p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_All_EVT;
1358 
1359         p_msg->adv_int_min      = adv_int_min;
1360         p_msg->adv_int_max      = adv_int_max;
1361         p_msg->adv_type         = adv_type;
1362         p_msg->addr_type_own    = addr_type_own;
1363         p_msg->channel_map      = chnl_map;
1364         p_msg->adv_filter_policy    = adv_fil_pol;
1365         p_msg->p_start_adv_cback    = p_start_adv_cb;
1366         if (p_dir_bda != NULL) {
1367             p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
1368             memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
1369         }
1370 
1371         bta_sys_sendmsg(p_msg);
1372     }
1373 #endif
1374 }
1375 #endif  ///BLE_INCLUDED == TRUE
1376 
1377 
1378 /*******************************************************************************
1379 **                      BLE ADV data management API
1380 ********************************************************************************/
1381 
1382 #if BLE_INCLUDED == TRUE
1383 /*******************************************************************************
1384 **
1385 ** Function         BTA_DmBleSetAdvConfig
1386 **
1387 ** Description      This function is called to override the BTA default ADV parameters.
1388 **
1389 ** Parameters       data_mask: adv data mask.
1390 **                  p_adv_cfg: Pointer to User defined ADV data structure. This
1391 **                             memory space can not be freed until p_adv_data_cback
1392 **                             is received.
1393 **                  p_adv_data_cback: set adv data complete callback.
1394 **
1395 ** Returns          None
1396 **
1397 *******************************************************************************/
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)1398 void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
1399                             tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
1400 {
1401     tBTA_DM_API_SET_ADV_CONFIG  *p_msg;
1402 
1403     if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
1404                  osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
1405         p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_EVT;
1406         p_msg->data_mask = data_mask;
1407         p_msg->p_adv_data_cback = p_adv_data_cback;
1408         p_msg->p_adv_cfg = p_adv_cfg;
1409 
1410         bta_sys_sendmsg(p_msg);
1411     }
1412 }
1413 
1414 /*******************************************************************************
1415 **
1416 ** Function         BTA_DmBleSetAdvConfigRaw
1417 **
1418 ** Description      This function is called to set raw Advertising data
1419 **
1420 ** Parameters       p_raw_adv : raw advertising data.
1421 **                  raw_adv_len : raw advertising data length.
1422 **                  p_adv_data_cback : set adv data complete callback.
1423 **
1424 ** Returns          None
1425 **
1426 *******************************************************************************/
BTA_DmBleSetAdvConfigRaw(UINT8 * p_raw_adv,UINT32 raw_adv_len,tBTA_SET_ADV_DATA_CMPL_CBACK * p_adv_data_cback)1427 void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len,
1428                             tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
1429 {
1430     tBTA_DM_API_SET_ADV_CONFIG_RAW  *p_msg;
1431 
1432     if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
1433                  osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW) + raw_adv_len)) != NULL) {
1434         p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT;
1435         p_msg->p_adv_data_cback = p_adv_data_cback;
1436         p_msg->p_raw_adv = (UINT8 *)(p_msg + 1);
1437         memcpy(p_msg->p_raw_adv, p_raw_adv, raw_adv_len);
1438         p_msg->raw_adv_len = raw_adv_len;
1439 
1440         bta_sys_sendmsg(p_msg);
1441     }
1442 }
1443 
1444 /*******************************************************************************
1445 **
1446 ** Function         BTA_DmBleSetLongAdv
1447 **
1448 ** Description      This function is called to set long Advertising data
1449 **
1450 ** Parameters       adv_data : long advertising data.
1451 **                  adv_data_len : long advertising data length.
1452 **                  p_adv_data_cback : set long adv data complete callback.
1453 **
1454 ** Returns          None
1455 **
1456 *******************************************************************************/
BTA_DmBleSetLongAdv(UINT8 * adv_data,UINT32 adv_data_len,tBTA_SET_ADV_DATA_CMPL_CBACK * p_adv_data_cback)1457 void BTA_DmBleSetLongAdv (UINT8 *adv_data, UINT32 adv_data_len,
1458                             tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
1459 {
1460     tBTA_DM_API_SET_LONG_ADV  *p_msg;
1461 
1462     if ((p_msg = (tBTA_DM_API_SET_LONG_ADV *)
1463                  osi_malloc(sizeof(tBTA_DM_API_SET_LONG_ADV))) != NULL) {
1464         p_msg->hdr.event = BTA_DM_API_BLE_SET_LONG_ADV_EVT;
1465         p_msg->p_adv_data_cback = p_adv_data_cback;
1466         p_msg->adv_data = adv_data;
1467         p_msg->adv_data_len = adv_data_len;
1468 
1469         bta_sys_sendmsg(p_msg);
1470     }
1471 }
1472 
1473 /*******************************************************************************
1474 **
1475 ** Function         BTA_DmBleSetScanRsp
1476 **
1477 ** Description      This function is called to override the BTA scan response.
1478 **
1479 ** Parameters       Pointer to User defined ADV data structure
1480 **
1481 ** Returns          None
1482 **
1483 *******************************************************************************/
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)1484 extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg,
1485                                  tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
1486 {
1487     tBTA_DM_API_SET_ADV_CONFIG  *p_msg;
1488 
1489     if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
1490                  osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
1491         p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_EVT;
1492         p_msg->data_mask = data_mask;
1493         p_msg->p_adv_data_cback = p_adv_data_cback;
1494         p_msg->p_adv_cfg = p_adv_cfg;
1495 
1496         bta_sys_sendmsg(p_msg);
1497     }
1498 }
1499 
1500 /*******************************************************************************
1501 **
1502 ** Function         BTA_DmBleSetScanRspRaw
1503 **
1504 ** Description      This function is called to set raw scan response data
1505 **
1506 ** Parameters       p_raw_scan_rsp : raw scan_rspertising data.
1507 **                  raw_scan_rsp_len : raw scan_rspertising data length.
1508 **                  p_scan_rsp_data_cback : set scan_rsp data complete callback.
1509 **
1510 ** Returns          None
1511 **
1512 *******************************************************************************/
BTA_DmBleSetScanRspRaw(UINT8 * p_raw_scan_rsp,UINT32 raw_scan_rsp_len,tBTA_SET_ADV_DATA_CMPL_CBACK * p_scan_rsp_data_cback)1513 void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len,
1514                             tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback)
1515 {
1516     tBTA_DM_API_SET_ADV_CONFIG_RAW  *p_msg;
1517 
1518     if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *)
1519                  osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW) + raw_scan_rsp_len)) != NULL) {
1520         p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_RAW_EVT;
1521         p_msg->p_adv_data_cback = p_scan_rsp_data_cback;
1522         p_msg->p_raw_adv = (UINT8 *)(p_msg + 1);
1523         memcpy(p_msg->p_raw_adv, p_raw_scan_rsp, raw_scan_rsp_len);
1524         p_msg->raw_adv_len = raw_scan_rsp_len;
1525 
1526         bta_sys_sendmsg(p_msg);
1527     }
1528 }
1529 
1530 /*******************************************************************************
1531 **
1532 ** Function         BTA_DmUpdateDuplicateExceptionalList
1533 **
1534 ** Description      This function is called to update duplicate scan exceptional list
1535 **
1536 ** Parameters       subcode : add, remove or clean duplicate scan exceptional list.
1537 **                  type : device info type.
1538 **                  device_info:  device info
1539 **                  p_update_duplicate_ignore_list_cback :  update complete callback.
1540 **
1541 ** Returns          None
1542 **
1543 *******************************************************************************/
BTA_DmUpdateDuplicateExceptionalList(UINT8 subcode,UINT32 type,BD_ADDR device_info,tBTA_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK p_update_duplicate_exceptional_list_cback)1544 void BTA_DmUpdateDuplicateExceptionalList(UINT8 subcode, UINT32 type, BD_ADDR device_info, tBTA_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK p_update_duplicate_exceptional_list_cback)
1545 {
1546     tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST *p_msg;
1547     if ((p_msg = (tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST *)osi_malloc(sizeof(tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST))) != NULL) {
1548         p_msg->hdr.event = BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT;
1549         p_msg->subcode = subcode;
1550         p_msg->type = type;
1551         p_msg->exceptional_list_cb = p_update_duplicate_exceptional_list_cback;
1552         memcpy(p_msg->device_info, device_info, sizeof(BD_ADDR));
1553 
1554         bta_sys_sendmsg(p_msg);
1555     }
1556 }
1557 
1558 /*******************************************************************************
1559 **
1560 ** Function         BTA_DmBleSetStorageParams
1561 **
1562 ** Description      This function is called to override the BTA scan response.
1563 **
1564 ** Parameters       batch_scan_full_max -Max storage space (in %) allocated to full scanning
1565 **                  batch_scan_trunc_max -Max storage space (in %) allocated to truncated scanning
1566 **                  batch_scan_notify_threshold -Setup notification level based on total space
1567 **                  p_setup_cback - Setup callback pointer
1568 **                  p_thres_cback - Threshold callback pointer
1569 **                  p_rep_cback - Reports callback pointer
1570 **                  ref_value - Ref value
1571 **
1572 ** Returns          None
1573 **
1574 *******************************************************************************/
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)1575 extern void BTA_DmBleSetStorageParams(UINT8 batch_scan_full_max,
1576                                       UINT8 batch_scan_trunc_max,
1577                                       UINT8 batch_scan_notify_threshold,
1578                                       tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback,
1579                                       tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback,
1580                                       tBTA_BLE_SCAN_REP_CBACK *p_rep_cback,
1581                                       tBTA_DM_BLE_REF_VALUE ref_value)
1582 {
1583     tBTA_DM_API_SET_STORAGE_CONFIG  *p_msg;
1584     bta_dm_cb.p_setup_cback = p_setup_cback;
1585     if ((p_msg = (tBTA_DM_API_SET_STORAGE_CONFIG *)
1586                  osi_malloc(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG))) != NULL) {
1587         p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT;
1588         p_msg->p_setup_cback = bta_ble_scan_setup_cb;
1589         p_msg->p_thres_cback = p_thres_cback;
1590         p_msg->p_read_rep_cback = p_rep_cback;
1591         p_msg->ref_value = ref_value;
1592         p_msg->batch_scan_full_max = batch_scan_full_max;
1593         p_msg->batch_scan_trunc_max = batch_scan_trunc_max;
1594         p_msg->batch_scan_notify_threshold = batch_scan_notify_threshold;
1595         bta_sys_sendmsg(p_msg);
1596     }
1597 }
1598 
1599 /*******************************************************************************
1600 **
1601 ** Function         BTA_DmBleEnableBatchScan
1602 **
1603 ** Description      This function is called to enable the batch scan
1604 **
1605 ** Parameters       scan_mode -Batch scan mode
1606 **                  scan_interval - Scan interval
1607 **                  scan_window - Scan window
1608 **                  discard_rule -Discard rules
1609 **                  addr_type - Address type
1610 **                  ref_value - Reference value
1611 **
1612 ** Returns          None
1613 **
1614 *******************************************************************************/
BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_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)1615 extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode,
1616                                      UINT32 scan_interval, UINT32 scan_window,
1617                                      tBTA_BLE_DISCARD_RULE discard_rule,
1618                                      tBLE_ADDR_TYPE        addr_type,
1619                                      tBTA_DM_BLE_REF_VALUE ref_value)
1620 {
1621     tBTA_DM_API_ENABLE_SCAN  *p_msg;
1622 
1623     if ((p_msg = (tBTA_DM_API_ENABLE_SCAN *) osi_malloc(sizeof(tBTA_DM_API_ENABLE_SCAN))) != NULL) {
1624         p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT;
1625         p_msg->scan_mode = scan_mode;
1626         p_msg->scan_int = scan_interval;
1627         p_msg->scan_window = scan_window;
1628         p_msg->discard_rule = discard_rule;
1629         p_msg->addr_type = addr_type;
1630         p_msg->ref_value = ref_value;
1631         bta_sys_sendmsg(p_msg);
1632     }
1633 }
1634 
1635 /*******************************************************************************
1636 **
1637 ** Function         BTA_DmBleDisableBatchScan
1638 **
1639 ** Description      This function is called to disable the batch scan
1640 **
1641 ** Parameters       ref_value - Reference value
1642 **
1643 ** Returns          None
1644 **
1645 *******************************************************************************/
BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)1646 extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)
1647 {
1648     tBTA_DM_API_DISABLE_SCAN  *p_msg;
1649 
1650     if ((p_msg = (tBTA_DM_API_DISABLE_SCAN *)
1651                  osi_malloc(sizeof(tBTA_DM_API_DISABLE_SCAN))) != NULL) {
1652         p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT;
1653         p_msg->ref_value = ref_value;
1654         bta_sys_sendmsg(p_msg);
1655     }
1656 }
1657 
1658 /*******************************************************************************
1659 **
1660 ** Function         BTA_DmBleReadScanReports
1661 **
1662 ** Description      This function is called to read scan reports
1663 **
1664 ** Parameters       scan_type -Batch scan mode
1665 **                  ref_value - Reference value
1666 **
1667 ** Returns          None
1668 **
1669 *******************************************************************************/
BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type,tBTA_DM_BLE_REF_VALUE ref_value)1670 extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type,
1671                                      tBTA_DM_BLE_REF_VALUE ref_value)
1672 {
1673     tBTA_DM_API_READ_SCAN_REPORTS  *p_msg;
1674 
1675     if ((p_msg = (tBTA_DM_API_READ_SCAN_REPORTS *)
1676                  osi_malloc(sizeof(tBTA_DM_API_READ_SCAN_REPORTS))) != NULL) {
1677         p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT;
1678         p_msg->scan_type = scan_type;
1679         p_msg->ref_value = ref_value;
1680         bta_sys_sendmsg(p_msg);
1681     }
1682 }
1683 
1684 /*******************************************************************************
1685 **
1686 ** Function         BTA_DmBleTrackAdvertiser
1687 **
1688 ** Description      This function is called to track advertiser
1689 **
1690 ** Parameters       ref_value - Reference value
1691 **                  p_track_adv_cback - Track ADV callback
1692 **
1693 ** Returns          None
1694 **
1695 *******************************************************************************/
BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,tBTA_BLE_TRACK_ADV_CBACK * p_track_adv_cback)1696 extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
1697                                      tBTA_BLE_TRACK_ADV_CBACK *p_track_adv_cback)
1698 {
1699     tBTA_DM_API_TRACK_ADVERTISER  *p_msg;
1700 
1701     if ((p_msg = (tBTA_DM_API_TRACK_ADVERTISER *)
1702                  osi_malloc(sizeof(tBTA_DM_API_TRACK_ADVERTISER))) != NULL) {
1703         p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT;
1704         p_msg->p_track_adv_cback = p_track_adv_cback;
1705         p_msg->ref_value = ref_value;
1706         bta_sys_sendmsg(p_msg);
1707     }
1708 }
1709 
1710 #endif
1711 
1712 /*******************************************************************************
1713 **                      BLE ADV data management API
1714 ********************************************************************************/
1715 #if BLE_INCLUDED == TRUE
1716 
1717 /*******************************************************************************
1718 **
1719 ** Function         BTA_DmBleBroadcast
1720 **
1721 ** Description      This function starts or stops LE broadcasting.
1722 **
1723 ** Parameters       start: start or stop broadcast.
1724 **
1725 ** Returns          None
1726 **
1727 *******************************************************************************/
BTA_DmBleBroadcast(BOOLEAN start,tBTA_START_STOP_ADV_CMPL_CBACK * p_start_stop_adv_cb)1728 extern void BTA_DmBleBroadcast (BOOLEAN start, tBTA_START_STOP_ADV_CMPL_CBACK *p_start_stop_adv_cb)
1729 {
1730     tBTA_DM_API_BLE_OBSERVE   *p_msg;
1731 
1732     APPL_TRACE_API("BTA_DmBleBroadcast: start = %d \n", start);
1733 
1734     if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) osi_malloc(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
1735         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
1736 
1737         p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
1738         p_msg->start = start;
1739         if (start == FALSE){
1740             p_msg->p_stop_adv_cback= p_start_stop_adv_cb;
1741         }
1742 
1743         bta_sys_sendmsg(p_msg);
1744     }
1745 }
1746 
1747 #endif
1748 /*******************************************************************************
1749 **
1750 ** Function         BTA_DmBleSetBgConnType
1751 **
1752 ** Description      This function is called to set BLE connectable mode for a
1753 **                  peripheral device.
1754 **
1755 ** Parameters       bg_conn_type: it can be auto connection, or selective connection.
1756 **                  p_select_cback: callback function when selective connection procedure
1757 **                              is being used.
1758 **
1759 ** Returns          void
1760 **
1761 *******************************************************************************/
BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type,tBTA_DM_BLE_SEL_CBACK * p_select_cback)1762 void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_CBACK *p_select_cback)
1763 {
1764 #if BLE_INCLUDED == TRUE
1765     tBTA_DM_API_BLE_SET_BG_CONN_TYPE    *p_msg;
1766 
1767     if ((p_msg = (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *) osi_malloc(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE))) != NULL) {
1768         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
1769 
1770         p_msg->hdr.event        = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
1771         p_msg->bg_conn_type     = bg_conn_type;
1772         p_msg->p_select_cback   = p_select_cback;
1773 
1774         bta_sys_sendmsg(p_msg);
1775     }
1776 #endif
1777 }
1778 
1779 /*******************************************************************************
1780 **
1781 ** Function         bta_dm_discover_send_msg
1782 **
1783 ** Description      This function send discover message to BTA task.
1784 **
1785 ** Returns          void
1786 **
1787 *******************************************************************************/
1788 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE && SDP_INCLUDED == TRUE
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)1789 static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1790                                      tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
1791                                      tBTA_TRANSPORT transport)
1792 {
1793     tBTA_DM_API_DISCOVER    *p_msg;
1794     UINT16  len = p_services ? (sizeof(tBTA_DM_API_DISCOVER) +
1795                                 sizeof(tBT_UUID) * p_services->num_uuid) :
1796                   sizeof(tBTA_DM_API_DISCOVER);
1797 
1798     if ((p_msg = (tBTA_DM_API_DISCOVER *) osi_malloc(len)) != NULL) {
1799         memset(p_msg, 0, len);
1800 
1801         p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
1802         bdcpy(p_msg->bd_addr, bd_addr);
1803         p_msg->p_cback = p_cback;
1804         p_msg->sdp_search = sdp_search;
1805         p_msg->transport    = transport;
1806 
1807         if (p_services != NULL) {
1808 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1809             p_msg->services = p_services->srvc_mask;
1810             p_msg->num_uuid = p_services->num_uuid;
1811             if (p_services->num_uuid != 0) {
1812                 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1813                 memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
1814             }
1815 #endif
1816         }
1817 
1818         bta_sys_sendmsg(p_msg);
1819     }
1820 }
1821 #endif
1822 /*******************************************************************************
1823 **
1824 ** Function         BTA_DmDiscoverByTransport
1825 **
1826 ** Description      This function does service discovery on particular transport
1827 **                  for services of a
1828 **                  peer device. When services.num_uuid is 0, it indicates all
1829 **                  GATT based services are to be searched; otherwise a list of
1830 **                  UUID of interested services should be provided through
1831 **                  p_services->p_uuid.
1832 **
1833 **
1834 **
1835 ** Returns          void
1836 **
1837 *******************************************************************************/
BTA_DmDiscoverByTransport(BD_ADDR bd_addr,tBTA_SERVICE_MASK_EXT * p_services,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search,tBTA_TRANSPORT transport)1838 void BTA_DmDiscoverByTransport(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1839                                tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search,
1840                                tBTA_TRANSPORT transport)
1841 {
1842 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE && SDP_INCLUDED == TRUE
1843     bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, transport);
1844 #endif
1845 }
1846 
1847 
1848 /*******************************************************************************
1849 **
1850 ** Function         BTA_DmDiscoverExt
1851 **
1852 ** Description      This function does service discovery for services of a
1853 **                  peer device. When services.num_uuid is 0, it indicates all
1854 **                  GATT based services are to be searched; other wise a list of
1855 **                  UUID of interested services should be provided through
1856 **                  p_services->p_uuid.
1857 **
1858 **
1859 **
1860 ** Returns          void
1861 **
1862 *******************************************************************************/
BTA_DmDiscoverExt(BD_ADDR bd_addr,tBTA_SERVICE_MASK_EXT * p_services,tBTA_DM_SEARCH_CBACK * p_cback,BOOLEAN sdp_search)1863 void BTA_DmDiscoverExt(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_services,
1864                        tBTA_DM_SEARCH_CBACK *p_cback, BOOLEAN sdp_search)
1865 {
1866 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE && SDP_INCLUDED == TRUE
1867     bta_dm_discover_send_msg(bd_addr, p_services, p_cback, sdp_search, BTA_TRANSPORT_UNKNOWN);
1868 #endif
1869 
1870 }
1871 
1872 /*******************************************************************************
1873 **
1874 ** Function         BTA_DmSearchExt
1875 **
1876 ** Description      This function searches for peer Bluetooth devices. It performs
1877 **                  an inquiry and gets the remote name for devices. Service
1878 **                  discovery is done if services is non zero
1879 **
1880 ** Parameters       p_dm_inq: inquiry conditions
1881 **                  p_services: if service is not empty, service discovery will be done.
1882 **                            for all GATT based service condition, put num_uuid, and
1883 **                            p_uuid is the pointer to the list of UUID values.
1884 **                  p_cback: callback functino when search is completed.
1885 **
1886 **
1887 **
1888 ** Returns          void
1889 **
1890 *******************************************************************************/
BTA_DmSearchExt(tBTA_DM_INQ * p_dm_inq,tBTA_SERVICE_MASK_EXT * p_services,tBTA_DM_SEARCH_CBACK * p_cback)1891 void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, tBTA_DM_SEARCH_CBACK *p_cback)
1892 {
1893 #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1894     tBTA_DM_API_SEARCH    *p_msg;
1895     UINT16  len = p_services ? (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid) :
1896                   sizeof(tBTA_DM_API_SEARCH);
1897 
1898     if ((p_msg = (tBTA_DM_API_SEARCH *) osi_malloc(len)) != NULL) {
1899         memset(p_msg, 0, len);
1900 
1901         p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
1902         memcpy(&p_msg->inq_params, p_dm_inq, sizeof(tBTA_DM_INQ));
1903         p_msg->p_cback = p_cback;
1904         p_msg->rs_res  = BTA_DM_RS_NONE;
1905 
1906 
1907         if (p_services != NULL) {
1908             p_msg->services = p_services->srvc_mask;
1909             p_msg->num_uuid = p_services->num_uuid;
1910 
1911             if (p_services->num_uuid != 0) {
1912                 p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
1913                 memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
1914             } else {
1915                 p_msg->p_uuid = NULL;
1916             }
1917         }
1918 
1919         bta_sys_sendmsg(p_msg);
1920     }
1921 #else
1922     UNUSED(p_dm_inq);
1923     UNUSED(p_services);
1924     UNUSED(p_cback);
1925 #endif
1926 }
1927 /*******************************************************************************
1928 **
1929 ** Function         BTA_DmBleUpdateConnectionParam
1930 **
1931 ** Description      Update connection parameters, can only be used when connection is up.
1932 **
1933 ** Parameters:      bd_addr          - BD address of the peer
1934 **                  min_int   -     minimum connection interval, [0x0004~ 0x4000]
1935 **                  max_int   -     maximum connection interval, [0x0004~ 0x4000]
1936 **                  latency   -     slave latency [0 ~ 500]
1937 **                  timeout   -     supervision timeout [0x000a ~ 0xc80]
1938 **
1939 ** Returns          void
1940 **
1941 *******************************************************************************/
BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr,UINT16 min_int,UINT16 max_int,UINT16 latency,UINT16 timeout)1942 void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
1943                                     UINT16 max_int, UINT16 latency,
1944                                     UINT16 timeout)
1945 {
1946 #if BLE_INCLUDED == TRUE
1947     tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
1948 
1949     p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) osi_malloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1950     if (p_msg != NULL) {
1951         memset(p_msg, 0, sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
1952 
1953         p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
1954         bdcpy(p_msg->bd_addr, bd_addr);
1955         p_msg->min_int   = min_int;
1956         p_msg->max_int   = max_int;
1957         p_msg->latency   = latency;
1958         p_msg->timeout   = timeout;
1959 
1960         bta_sys_sendmsg(p_msg);
1961     }
1962 #endif
1963 }
1964 
1965 #if BLE_INCLUDED == TRUE
1966 /*******************************************************************************
1967 **
1968 ** Function         BTA_DmBleConfigLocalPrivacy
1969 **
1970 ** Description      Enable/disable privacy on the local device
1971 **
1972 ** Parameters:      privacy_enable   - enable/disabe privacy on remote device.
1973 **
1974 ** Returns          void
1975 **
1976 *******************************************************************************/
BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable,tBTA_SET_LOCAL_PRIVACY_CBACK * set_local_privacy_cback)1977 void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback)
1978 {
1979     ///This function used the irk to generate the resolve address
1980 #if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE
1981     tBTA_DM_API_LOCAL_PRIVACY *p_msg;
1982 
1983     if ((p_msg = (tBTA_DM_API_LOCAL_PRIVACY *) osi_malloc(sizeof(tBTA_DM_API_ENABLE_PRIVACY))) != NULL) {
1984         memset (p_msg, 0, sizeof(tBTA_DM_API_LOCAL_PRIVACY));
1985 
1986         p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
1987         p_msg->privacy_enable   = privacy_enable;
1988         p_msg->set_local_privacy_cback = set_local_privacy_cback;
1989         bta_sys_sendmsg(p_msg);
1990     }
1991 #else
1992     UNUSED (privacy_enable);
1993 #endif
1994 }
1995 
1996 /*******************************************************************************
1997 **
1998 ** Function         BTA_DmBleConfigLocalIcon
1999 **
2000 ** Description      set gap local icon
2001 **
2002 ** Parameters:      icon   - appearance value.
2003 **
2004 ** Returns          void
2005 **
2006 *******************************************************************************/
BTA_DmBleConfigLocalIcon(uint16_t icon)2007 void BTA_DmBleConfigLocalIcon(uint16_t icon)
2008 {
2009     tBTA_DM_API_LOCAL_ICON *p_msg;
2010 
2011     if ((p_msg = (tBTA_DM_API_LOCAL_ICON *) osi_malloc(sizeof(tBTA_DM_API_LOCAL_ICON))) != NULL) {
2012         memset (p_msg, 0, sizeof(tBTA_DM_API_LOCAL_ICON));
2013 
2014         p_msg->hdr.event = BTA_DM_API_LOCAL_ICON_EVT;
2015         p_msg->icon   = icon;
2016         bta_sys_sendmsg(p_msg);
2017     }
2018 }
2019 
2020 /*******************************************************************************
2021 **
2022 ** Function         BTA_BleEnableAdvInstance
2023 **
2024 ** Description      This function enable a Multi-ADV instance with the specififed
2025 **                  adv parameters
2026 **
2027 ** Parameters       p_params: pointer to the adv parameter structure.
2028 **                  p_cback: callback function associated to this adv instance.
2029 **                  p_ref: reference data pointer to this adv instance.
2030 **
2031 ** Returns          BTA_SUCCESS if command started successfully; otherwise failure.
2032 **
2033 *******************************************************************************/
BTA_BleEnableAdvInstance(tBTA_BLE_ADV_PARAMS * p_params,tBTA_BLE_MULTI_ADV_CBACK * p_cback,void * p_ref)2034 void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
2035                                tBTA_BLE_MULTI_ADV_CBACK *p_cback,
2036                                void *p_ref)
2037 {
2038     ///This function just used for vendor debug
2039     tBTA_DM_API_BLE_MULTI_ADV_ENB    *p_msg;
2040     UINT16 len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB);
2041 
2042     APPL_TRACE_API ("BTA_BleEnableAdvInstance");
2043 
2044     if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_ENB *) osi_malloc(len)) != NULL) {
2045         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB));
2046 
2047         p_msg->hdr.event     = BTA_DM_API_BLE_MULTI_ADV_ENB_EVT;
2048         p_msg->p_cback      = (void *)p_cback;
2049         if (p_params != NULL) {
2050             p_msg->p_params =  (void *)(p_msg + 1);
2051             memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
2052         }
2053         p_msg->p_ref        = p_ref;
2054 
2055         bta_sys_sendmsg(p_msg);
2056     }
2057 }
2058 
2059 /*******************************************************************************
2060 **
2061 ** Function         BTA_BleUpdateAdvInstParam
2062 **
2063 ** Description      This function update a Multi-ADV instance with the specififed
2064 **                  adv parameters.
2065 **
2066 ** Parameters       inst_id: Adv instance to update the parameter.
2067 **                  p_params: pointer to the adv parameter structure.
2068 **
2069 ** Returns          BTA_SUCCESS if command started successfully; otherwise failure.
2070 **
2071 *******************************************************************************/
BTA_BleUpdateAdvInstParam(UINT8 inst_id,tBTA_BLE_ADV_PARAMS * p_params)2072 void BTA_BleUpdateAdvInstParam (UINT8 inst_id, tBTA_BLE_ADV_PARAMS *p_params)
2073 {
2074     ///This function just used for vendor debug
2075     tBTA_DM_API_BLE_MULTI_ADV_PARAM    *p_msg;
2076     UINT16      len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM);
2077 
2078     APPL_TRACE_API ("BTA_BleUpdateAdvInstParam");
2079     if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_PARAM *) osi_malloc(len)) != NULL) {
2080         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM));
2081         p_msg->hdr.event     = BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT;
2082         p_msg->inst_id        = inst_id;
2083         p_msg->p_params =  (void *)(p_msg + 1);
2084         memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
2085 
2086         bta_sys_sendmsg(p_msg);
2087     }
2088 }
2089 
2090 /*******************************************************************************
2091 **
2092 ** Function         BTA_BleCfgAdvInstData
2093 **
2094 ** Description      This function configure a Multi-ADV instance with the specififed
2095 **                  adv data or scan response data.
2096 **
2097 ** Parameter        inst_id: Adv instance to configure the adv data or scan response.
2098 **                  is_scan_rsp: is the data scan response or adv data.
2099 **                  data_mask: adv data type as bit mask.
2100 **                  p_data: pointer to the ADV data structure tBTA_BLE_ADV_DATA. This
2101 **                  memory space can not be freed until BTA_BLE_MULTI_ADV_DATA_EVT
2102 **                  is sent to application.
2103 **
2104 ** Returns          BTA_SUCCESS if command started successfully; otherwise failure.
2105 **
2106 *******************************************************************************/
BTA_BleCfgAdvInstData(UINT8 inst_id,BOOLEAN is_scan_rsp,tBTA_BLE_AD_MASK data_mask,tBTA_BLE_ADV_DATA * p_data)2107 void BTA_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp,
2108                             tBTA_BLE_AD_MASK data_mask,
2109                             tBTA_BLE_ADV_DATA *p_data)
2110 {
2111     ///This function just used for vendor debug
2112     tBTA_DM_API_BLE_MULTI_ADV_DATA    *p_msg;
2113     UINT16      len =  sizeof(tBTA_DM_API_BLE_MULTI_ADV_DATA) ;
2114 
2115     APPL_TRACE_API ("BTA_BleCfgAdvInstData");
2116 
2117     if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DATA *) osi_malloc(len)) != NULL) {
2118         memset(p_msg, 0, len);
2119         p_msg->hdr.event     = BTA_DM_API_BLE_MULTI_ADV_DATA_EVT;
2120         p_msg->inst_id      = inst_id;
2121         p_msg->is_scan_rsp  = is_scan_rsp;
2122         p_msg->data_mask     = data_mask;
2123         p_msg->p_data        = p_data;
2124 
2125         bta_sys_sendmsg(p_msg);
2126     }
2127 }
2128 
2129 /*******************************************************************************
2130 **
2131 ** Function         BTA_BleDisableAdvInstance
2132 **
2133 ** Description      This function disable a Multi-ADV instance.
2134 **
2135 ** Parameter        inst_id: instance ID to disable.
2136 **
2137 ** Returns          BTA_SUCCESS if command started successfully; otherwise failure.
2138 **
2139 *******************************************************************************/
BTA_BleDisableAdvInstance(UINT8 inst_id)2140 void BTA_BleDisableAdvInstance (UINT8  inst_id)     //this function just used for vendor debug
2141 {
2142     tBTA_DM_API_BLE_MULTI_ADV_DISABLE    *p_msg;
2143 
2144     APPL_TRACE_API ("BTA_BleDisableAdvInstance: %d", inst_id);
2145     if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DISABLE *)
2146                  osi_malloc(sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE))) != NULL) {
2147         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE));
2148         p_msg->hdr.event    = BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT;
2149         p_msg->inst_id      = inst_id;
2150         bta_sys_sendmsg(p_msg);
2151     }
2152 }
2153 
2154 /*******************************************************************************
2155 **
2156 ** Function         BTA_DmBleCfgFilterCondition
2157 **
2158 ** Description      This function is called to configure the adv data payload filter
2159 **                  condition.
2160 **
2161 ** Parameters       action: to read/write/clear
2162 **                  cond_type: filter condition type
2163 **                  filt_index - Filter index
2164 **                  p_cond: filter condition parameter
2165 **                  p_cmpl_back - Command completed callback
2166 **                  ref_value - Reference value
2167 **
2168 ** Returns          void
2169 **
2170 *******************************************************************************/
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)2171 void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
2172                                  tBTA_DM_BLE_PF_COND_TYPE cond_type,
2173                                  tBTA_DM_BLE_PF_FILT_INDEX filt_index,
2174                                  tBTA_DM_BLE_PF_COND_PARAM *p_cond,
2175                                  tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback,
2176                                  tBTA_DM_BLE_REF_VALUE ref_value)
2177 {
2178 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
2179     tBTA_DM_API_CFG_FILTER_COND *p_msg;
2180     APPL_TRACE_API ("BTA_DmBleCfgFilterCondition: %d, %d", action, cond_type);
2181 
2182     UINT16  len = sizeof(tBTA_DM_API_CFG_FILTER_COND) +
2183                   sizeof(tBTA_DM_BLE_PF_COND_PARAM);
2184     UINT8 *p;
2185 
2186     if (NULL != p_cond) {
2187         switch (cond_type) {
2188         case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:
2189         case BTA_DM_BLE_PF_MANU_DATA:
2190             /* Length of pattern and pattern mask and other elements in */
2191             /* tBTA_DM_BLE_PF_MANU_COND */
2192             len += ((p_cond->manu_data.data_len) * 2) +
2193                    sizeof(UINT16) + sizeof(UINT16) + sizeof(UINT8);
2194             break;
2195 
2196         case BTA_DM_BLE_PF_LOCAL_NAME:
2197             len += ((p_cond->local_name.data_len) + sizeof(UINT8));
2198             break;
2199 
2200         case BTM_BLE_PF_SRVC_UUID:
2201         case BTM_BLE_PF_SRVC_SOL_UUID:
2202             len += sizeof(tBLE_BD_ADDR) + sizeof(tBTA_DM_BLE_PF_COND_MASK);
2203             break;
2204 
2205         default:
2206             break;
2207         }
2208     }
2209 
2210     if ((p_msg = (tBTA_DM_API_CFG_FILTER_COND *) osi_malloc(len)) != NULL) {
2211         memset (p_msg, 0, len);
2212 
2213         p_msg->hdr.event        = BTA_DM_API_CFG_FILTER_COND_EVT;
2214         p_msg->action           = action;
2215         p_msg->cond_type        = cond_type;
2216         p_msg->filt_index       = filt_index;
2217         p_msg->p_filt_cfg_cback = p_cmpl_cback;
2218         p_msg->ref_value        = ref_value;
2219         if (p_cond) {
2220             p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM *)(p_msg + 1);
2221             memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
2222 
2223             p = (UINT8 *)(p_msg->p_cond_param + 1);
2224 
2225             if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN ||
2226                     cond_type == BTA_DM_BLE_PF_MANU_DATA) {
2227                 p_msg->p_cond_param->manu_data.p_pattern = p;
2228                 p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len;
2229                 memcpy(p_msg->p_cond_param->manu_data.p_pattern, p_cond->manu_data.p_pattern,
2230                        p_cond->manu_data.data_len);
2231                 p += p_cond->manu_data.data_len;
2232 
2233                 if (cond_type == BTA_DM_BLE_PF_MANU_DATA) {
2234                     p_msg->p_cond_param->manu_data.company_id_mask =
2235                         p_cond->manu_data.company_id_mask;
2236                     if ( p_cond->manu_data.p_pattern_mask != NULL) {
2237                         p_msg->p_cond_param->manu_data.p_pattern_mask = p;
2238                         memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask,
2239                                p_cond->manu_data.p_pattern_mask, p_cond->manu_data.data_len);
2240                     }
2241                 }
2242             } else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME) {
2243                 p_msg->p_cond_param->local_name.p_data = p;
2244                 p_msg->p_cond_param->local_name.data_len =
2245                     p_cond->local_name.data_len;
2246                 memcpy(p_msg->p_cond_param->local_name.p_data,
2247                        p_cond->local_name.p_data, p_cond->local_name.data_len);
2248             } else if ((cond_type == BTM_BLE_PF_SRVC_UUID
2249                         || cond_type == BTM_BLE_PF_SRVC_SOL_UUID)) {
2250                 if (p_cond->srvc_uuid.p_target_addr != NULL) {
2251                     p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR *)(p);
2252                     p_msg->p_cond_param->srvc_uuid.p_target_addr->type =
2253                         p_cond->srvc_uuid.p_target_addr->type;
2254                     memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda,
2255                            p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN);
2256                     p = (UINT8 *)( p_msg->p_cond_param->srvc_uuid.p_target_addr + 1);
2257                 }
2258                 if (p_cond->srvc_uuid.p_uuid_mask) {
2259                     p_msg->p_cond_param->srvc_uuid.p_uuid_mask = (tBTA_DM_BLE_PF_COND_MASK *)p;
2260                     memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask,
2261                            p_cond->srvc_uuid.p_uuid_mask, sizeof(tBTA_DM_BLE_PF_COND_MASK));
2262                 }
2263             }
2264         }
2265 
2266         bta_sys_sendmsg(p_msg);
2267     }
2268 #else
2269     UNUSED(action);
2270     UNUSED(cond_type);
2271     UNUSED(filt_index);
2272     UNUSED(p_cond);
2273     UNUSED(p_cmpl_cback);
2274     UNUSED(ref_value);
2275 #endif
2276 }
2277 
2278 /*******************************************************************************
2279 **
2280 ** Function         BTA_DmBleScanFilterSetup
2281 **
2282 ** Description      This function is called to setup the adv data payload filter param
2283 **
2284 ** Parameters       p_target: enable the filter condition on a target device; if NULL
2285 **                  filt_index - Filter index
2286 **                  p_filt_params -Filter parameters
2287 **                  ref_value - Reference value
2288 **                  action - Add, delete or clear
2289 **                  p_cmpl_back - Command completed callback
2290 **
2291 ** Returns          void
2292 **
2293 *******************************************************************************/
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)2294 void BTA_DmBleScanFilterSetup(UINT8 action, tBTA_DM_BLE_PF_FILT_INDEX filt_index,
2295                               tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params,
2296                               tBLE_BD_ADDR *p_target,
2297                               tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback,
2298                               tBTA_DM_BLE_REF_VALUE ref_value)
2299 {
2300 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
2301     tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *p_msg;
2302     APPL_TRACE_API ("BTA_DmBleScanFilterSetup: %d", action);
2303 
2304     UINT16  len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) + sizeof(tBLE_BD_ADDR);
2305 
2306     if ((p_msg = (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *) osi_malloc(len)) != NULL) {
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         if (p_filt_params) {
2313             memcpy(&p_msg->filt_params, p_filt_params, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
2314         }
2315         p_msg->p_filt_param_cback = p_cmpl_cback;
2316         p_msg->ref_value        = ref_value;
2317 
2318         if (p_target) {
2319             p_msg->p_target = (tBLE_BD_ADDR *)(p_msg + 1);
2320             memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR));
2321         }
2322 
2323         bta_sys_sendmsg(p_msg);
2324     }
2325 #else
2326     UNUSED(action);
2327     UNUSED(filt_index);
2328     UNUSED(p_filt_params);
2329     UNUSED(p_target);
2330     UNUSED(p_cmpl_cback);
2331     UNUSED(ref_value);
2332 #endif
2333 }
2334 
2335 /*******************************************************************************
2336 **
2337 ** Function         BTA_DmBleGetEnergyInfo
2338 **
2339 ** Description      This function is called to obtain the energy info
2340 **
2341 ** Parameters       p_cmpl_cback - Command complete callback
2342 **
2343 ** Returns          void
2344 **
2345 *******************************************************************************/
BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK * p_cmpl_cback)2346 void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback)
2347 {
2348     tBTA_DM_API_ENERGY_INFO *p_msg;
2349     APPL_TRACE_API ("BTA_DmBleGetEnergyInfo");
2350 
2351     UINT16  len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
2352 
2353     if ((p_msg = (tBTA_DM_API_ENERGY_INFO *) osi_malloc(len)) != NULL) {
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\n", 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 *) osi_malloc(len)) != NULL) {
2384         memset (p_msg, 0, len);
2385 
2386         p_msg->hdr.event        = BTA_DM_API_SCAN_FILTER_ENABLE_EVT;
2387         p_msg->action       = action;
2388         p_msg->ref_value    = ref_value;
2389         p_msg->p_filt_status_cback = p_cmpl_cback;
2390 
2391         bta_sys_sendmsg(p_msg);
2392     }
2393 #else
2394     UNUSED(action);
2395     UNUSED(p_cmpl_cback);
2396     UNUSED(ref_value);
2397 #endif
2398 }
2399 
2400 /*******************************************************************************
2401 **
2402 ** Function         BTA_DmBleUpdateConnectionParams
2403 **
2404 ** Description      Update connection parameters, can only be used when connection is up.
2405 **
2406 ** Parameters:      bd_addr   - BD address of the peer
2407 **                  min_int   -     minimum connection interval, [0x0004~ 0x4000]
2408 **                  max_int   -     maximum connection interval, [0x0004~ 0x4000]
2409 **                  latency   -     slave latency [0 ~ 500]
2410 **                  timeout   -     supervision timeout [0x000a ~ 0xc80]
2411 **
2412 ** Returns          void
2413 **
2414 *******************************************************************************/
BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr,UINT16 min_int,UINT16 max_int,UINT16 latency,UINT16 timeout)2415 void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max_int,
2416                                      UINT16 latency, UINT16 timeout)
2417 {
2418     tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
2419 
2420     if ((p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) osi_malloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM))) != NULL) {
2421         memset (p_msg, 0, sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
2422 
2423         p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
2424         bdcpy(p_msg->bd_addr, bd_addr);
2425         p_msg->min_int   = min_int;
2426         p_msg->max_int   = max_int;
2427         p_msg->latency   = latency;
2428         p_msg->timeout   = timeout;
2429         bta_sys_sendmsg(p_msg);
2430     }
2431 }
2432 /*******************************************************************************
2433 **
2434 ** Function         BTA_DmBleDisconnect
2435 **
2436 ** Description      Disconnect the ble connection, can only be used when connection is up.
2437 **
2438 ** Parameters:      bd_addr   - BD address of the peer
2439 **
2440 ** Returns          void
2441 **
2442 *******************************************************************************/
BTA_DmBleDisconnect(BD_ADDR bd_addr)2443 void BTA_DmBleDisconnect(BD_ADDR bd_addr)
2444 {
2445     tBTA_DM_API_BLE_DISCONNECT *p_msg;
2446 
2447     if ((p_msg = (tBTA_DM_API_BLE_DISCONNECT *) osi_malloc(sizeof(tBTA_DM_API_BLE_DISCONNECT))) != NULL) {
2448         memset (p_msg, 0, sizeof(tBTA_DM_API_BLE_DISCONNECT));
2449 
2450         p_msg->hdr.event = BTA_DM_API_BLE_DISCONNECT_EVT;
2451         bdcpy(p_msg->remote_bda, bd_addr);
2452 
2453         bta_sys_sendmsg(p_msg);
2454     }
2455 }
2456 /*******************************************************************************
2457 **
2458 ** Function         BTA_DmBleSetDataLength
2459 **
2460 ** Description      This function is to set maximum LE data packet size
2461 **
2462 ** Returns          void
2463 **
2464 **
2465 *******************************************************************************/
BTA_DmBleSetDataLength(BD_ADDR remote_device,UINT16 tx_data_length,tBTA_SET_PKT_DATA_LENGTH_CBACK * p_set_pkt_data_cback)2466 void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length, tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback)
2467 {
2468     tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg;
2469 
2470     if ((p_msg = (tBTA_DM_API_BLE_SET_DATA_LENGTH *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH)))
2471             != NULL) {
2472         bdcpy(p_msg->remote_bda, remote_device);
2473         p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
2474         p_msg->tx_data_length = tx_data_length;
2475         p_msg->p_set_pkt_data_cback = p_set_pkt_data_cback;
2476 
2477         bta_sys_sendmsg(p_msg);
2478     }
2479 }
2480 
2481 #endif
2482 
2483 /*******************************************************************************
2484 **
2485 ** Function         BTA_DmSetEncryption
2486 **
2487 ** Description      This function is called to ensure that connection is
2488 **                  encrypted.  Should be called only on an open connection.
2489 **                  Typically only needed for connections that first want to
2490 **                  bring up unencrypted links, then later encrypt them.
2491 **
2492 ** Parameters:      bd_addr       - Address of the peer device
2493 **                  transport     - transport of the link to be encruypted
2494 **                  p_callback    - Pointer to callback function to indicat the
2495 **                                  link encryption status
2496 **                  sec_act       - This is the security action to indicate
2497 **                                  what kind of BLE security level is required for
2498 **                                  the BLE link if the BLE is supported
2499 **                                  Note: This parameter is ignored for the BR/EDR link
2500 **                                        or the BLE is not supported
2501 **
2502 ** Returns          void
2503 **
2504 *******************************************************************************/
2505 #if (SMP_INCLUDED == TRUE)
BTA_DmSetEncryption(BD_ADDR bd_addr,tBTA_TRANSPORT transport,tBTA_DM_ENCRYPT_CBACK * p_callback,tBTA_DM_BLE_SEC_ACT sec_act)2506 void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCRYPT_CBACK *p_callback,
2507                          tBTA_DM_BLE_SEC_ACT sec_act)
2508 {
2509     tBTA_DM_API_SET_ENCRYPTION   *p_msg;
2510 
2511     APPL_TRACE_API("BTA_DmSetEncryption"); //todo
2512     if ((p_msg = (tBTA_DM_API_SET_ENCRYPTION *) osi_malloc(sizeof(tBTA_DM_API_SET_ENCRYPTION))) != NULL) {
2513         memset(p_msg, 0, sizeof(tBTA_DM_API_SET_ENCRYPTION));
2514 
2515         p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
2516 
2517         memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
2518         p_msg->transport    = transport;
2519         p_msg->p_callback      = p_callback;
2520         p_msg->sec_act         = sec_act;
2521 
2522         bta_sys_sendmsg(p_msg);
2523     }
2524 }
2525 #endif  ///SMP_INCLUDED == TRUE
2526 
2527 /*******************************************************************************
2528 **
2529 ** Function         BTA_DmCloseACL
2530 **
2531 ** Description      This function force to close an ACL connection and remove the
2532 **                  device from the security database list of known devices.
2533 **
2534 ** Parameters:      bd_addr       - Address of the peer device
2535 **                  remove_dev    - remove device or not after link down
2536 **
2537 ** Returns          void
2538 **
2539 *******************************************************************************/
BTA_DmCloseACL(BD_ADDR bd_addr,BOOLEAN remove_dev,tBTA_TRANSPORT transport)2540 void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT transport)
2541 {
2542     tBTA_DM_API_REMOVE_ACL   *p_msg;
2543 
2544     APPL_TRACE_API("BTA_DmCloseACL");
2545 
2546     if ((p_msg = (tBTA_DM_API_REMOVE_ACL *) osi_malloc(sizeof(tBTA_DM_API_REMOVE_ACL))) != NULL) {
2547         memset(p_msg, 0, sizeof(tBTA_DM_API_REMOVE_ACL));
2548 
2549         p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
2550 
2551         memcpy(p_msg->bd_addr, bd_addr, BD_ADDR_LEN);
2552         p_msg->remove_dev      = remove_dev;
2553         p_msg->transport       = transport;
2554 
2555         bta_sys_sendmsg(p_msg);
2556     }
2557 }
2558 
2559 #if BLE_INCLUDED == TRUE
2560 /*******************************************************************************
2561 **
2562 ** Function         BTA_DmBleObserve
2563 **
2564 ** Description      This procedure keep the device listening for advertising
2565 **                  events from a broadcast device.
2566 **
2567 ** Parameters       start: start or stop observe.
2568 **
2569 ** Returns          void
2570 
2571 **
2572 ** Returns          void.
2573 **
2574 *******************************************************************************/
BTA_DmBleObserve(BOOLEAN start,UINT32 duration,tBTA_DM_SEARCH_CBACK * p_results_cb,tBTA_START_STOP_SCAN_CMPL_CBACK * p_start_stop_scan_cb)2575 extern void BTA_DmBleObserve(BOOLEAN start, UINT32 duration,
2576                              tBTA_DM_SEARCH_CBACK *p_results_cb,
2577                              tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb)
2578 {
2579     tBTA_DM_API_BLE_OBSERVE   *p_msg;
2580 
2581     APPL_TRACE_API("BTA_DmBleObserve:start = %d ", start);
2582 
2583     if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) osi_malloc(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
2584         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
2585 
2586         p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
2587         p_msg->start = start;
2588         p_msg->duration = duration;
2589         p_msg->p_cback = p_results_cb;
2590         if (start){
2591             p_msg->p_start_scan_cback = p_start_stop_scan_cb;
2592         }
2593         else {
2594             p_msg->p_stop_scan_cback = p_start_stop_scan_cb;
2595         }
2596 
2597         bta_sys_sendmsg(p_msg);
2598     }
2599 }
2600 
2601 /*******************************************************************************
2602 **
2603 ** Function         BTA_DmBleScan
2604 **
2605 ** Description      This procedure keep the device listening for advertising
2606 **                  events from a broadcast device.
2607 **
2608 ** Parameters       start: start or stop scan.
2609 **
2610 ** Returns          void
2611 
2612 **
2613 ** Returns          void.
2614 **
2615 *******************************************************************************/
BTA_DmBleScan(BOOLEAN start,UINT32 duration,tBTA_DM_SEARCH_CBACK * p_results_cb,tBTA_START_STOP_SCAN_CMPL_CBACK * p_start_stop_scan_cb)2616 extern void BTA_DmBleScan(BOOLEAN start, UINT32 duration,
2617                              tBTA_DM_SEARCH_CBACK *p_results_cb,
2618                              tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb)
2619 {
2620     tBTA_DM_API_BLE_SCAN   *p_msg;
2621 
2622     APPL_TRACE_API("BTA_DmBleScan:start = %d ", start);
2623 
2624     if ((p_msg = (tBTA_DM_API_BLE_SCAN *) osi_malloc(sizeof(tBTA_DM_API_BLE_SCAN))) != NULL) {
2625         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN));
2626 
2627         p_msg->hdr.event = BTA_DM_API_BLE_SCAN_EVT;
2628         p_msg->start = start;
2629         p_msg->duration = duration;
2630         p_msg->p_cback = p_results_cb;
2631         if (start){
2632             p_msg->p_start_scan_cback = p_start_stop_scan_cb;
2633         }
2634         else {
2635             p_msg->p_stop_scan_cback = p_start_stop_scan_cb;
2636         }
2637 
2638         bta_sys_sendmsg(p_msg);
2639     }
2640 }
2641 
2642 /*******************************************************************************
2643 **
2644 ** Function         BTA_DmBleStopAdvertising
2645 **
2646 ** Description      This function set the random address for the APP
2647 **
2648 ** Parameters       void
2649 **
2650 ** Returns          void
2651 **
2652 **
2653 *******************************************************************************/
BTA_DmBleStopAdvertising(void)2654 extern void BTA_DmBleStopAdvertising(void)
2655 {
2656     BT_HDR   *p_msg;
2657 
2658     APPL_TRACE_API("BTA_DmBleStopAdvertising\n");
2659 
2660     if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
2661         memset(p_msg, 0, sizeof(BT_HDR));
2662         p_msg->event = BTA_DM_API_BLE_STOP_ADV_EVT;
2663         bta_sys_sendmsg(p_msg);
2664     }
2665 }
2666 
2667 
2668 /*******************************************************************************
2669 **
2670 ** Function         BTA_DmSetRandAddress
2671 **
2672 ** Description      This function set the random address for the APP
2673 **
2674 ** Parameters       rand_addr: the random address whith should be setting
2675 **                  p_set_rand_addr_cback: complete callback
2676 ** Returns          void
2677 **
2678 **
2679 *******************************************************************************/
BTA_DmSetRandAddress(BD_ADDR rand_addr,tBTA_SET_RAND_ADDR_CBACK * p_set_rand_addr_cback)2680 extern void BTA_DmSetRandAddress(BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback)
2681 {
2682     tBTA_DM_APT_SET_DEV_ADDR *p_msg;
2683     APPL_TRACE_API("set the random address ");
2684     if ((p_msg = (tBTA_DM_APT_SET_DEV_ADDR *) osi_malloc(sizeof(tBTA_DM_APT_SET_DEV_ADDR))) != NULL) {
2685         memset(p_msg, 0, sizeof(tBTA_DM_APT_SET_DEV_ADDR));
2686         memcpy(p_msg->address, rand_addr, BD_ADDR_LEN);
2687         p_msg->hdr.event = BTA_DM_API_SET_RAND_ADDR_EVT;
2688         p_msg->addr_type = BLE_ADDR_RANDOM;
2689         p_msg->p_set_rand_addr_cback = p_set_rand_addr_cback;
2690         //start sent the msg to the bta system control moudle
2691         bta_sys_sendmsg(p_msg);
2692     }
2693 }
2694 
BTA_DmClearRandAddress(void)2695 void BTA_DmClearRandAddress(void)
2696 {
2697     tBTA_DM_APT_CLEAR_ADDR *p_msg;
2698     if ((p_msg = (tBTA_DM_APT_CLEAR_ADDR *) osi_malloc(sizeof(tBTA_DM_APT_CLEAR_ADDR))) != NULL) {
2699         memset(p_msg, 0, sizeof(tBTA_DM_APT_CLEAR_ADDR));
2700         p_msg->hdr.event = BTA_DM_API_CLEAR_RAND_ADDR_EVT;
2701         bta_sys_sendmsg(p_msg);
2702     }
2703 }
2704 
2705 /*******************************************************************************
2706 **
2707 ** Function         BTA_VendorInit
2708 **
2709 ** Description      This function initializes vendor specific
2710 **
2711 ** Returns          void
2712 **
2713 *******************************************************************************/
BTA_VendorInit(void)2714 void BTA_VendorInit (void)
2715 {
2716     APPL_TRACE_API("BTA_VendorInit");
2717 }
2718 
2719 /*******************************************************************************
2720 **
2721 ** Function         BTA_VendorCleanup
2722 **
2723 ** Description      This function frees up Broadcom specific VS specific dynamic memory
2724 **
2725 ** Returns          void
2726 **
2727 *******************************************************************************/
BTA_VendorCleanup(void)2728 void BTA_VendorCleanup (void)
2729 {
2730     tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
2731     BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
2732 
2733 #if (BLE_INCLUDED == TRUE && BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
2734     btm_ble_adv_filter_cleanup();       // when BLE_VND_INCLUDED is false, this function will be ignore, so move it out of "if"
2735 
2736 #if 0                                   //by TH, comment out temporarily
2737     if (cmn_ble_vsc_cb.max_filter > 0) {
2738         btm_ble_adv_filter_cleanup();
2739 #if BLE_PRIVACY_SPT == TRUE
2740         btm_ble_resolving_list_cleanup ();
2741 #endif
2742     }
2743 #endif
2744 
2745     if (cmn_ble_vsc_cb.tot_scan_results_strg > 0) {
2746         btm_ble_batchscan_cleanup();
2747     }
2748 #endif
2749 
2750     btm_ble_multi_adv_cleanup();
2751 }
2752 #if (BLE_50_FEATURE_SUPPORT == TRUE)
BTA_DmBleGapReadPHY(BD_ADDR addr)2753 void BTA_DmBleGapReadPHY(BD_ADDR addr)
2754 {
2755     tBTA_DM_API_READ_PHY *p_msg;
2756     APPL_TRACE_API("%s, read phy.", __func__);
2757     if ((p_msg = (tBTA_DM_API_READ_PHY *) osi_malloc(sizeof(tBTA_DM_API_READ_PHY))) != NULL) {
2758         memset(p_msg, 0, sizeof(tBTA_DM_API_READ_PHY));
2759         p_msg->hdr.event = BTA_DM_API_READ_PHY_EVT;
2760         memcpy(p_msg->bd_addr, addr, BD_ADDR_LEN);
2761         //start sent the msg to the bta system control moudle
2762         bta_sys_sendmsg(p_msg);
2763     } else {
2764         APPL_TRACE_ERROR("%s malloc failed", __func__);
2765     }
2766 
2767 }
2768 
BTA_DmBleGapSetPreferedDefaultPHY(tBTA_DM_BLE_GAP_PHY_MASK tx_phy_mask,tBTA_DM_BLE_GAP_PHY_MASK rx_phy_mask)2769 void BTA_DmBleGapSetPreferedDefaultPHY(tBTA_DM_BLE_GAP_PHY_MASK tx_phy_mask,
2770                                                           tBTA_DM_BLE_GAP_PHY_MASK rx_phy_mask)
2771 {
2772     tBTA_DM_API_SET_PER_DEF_PHY *p_msg;
2773     APPL_TRACE_API("%s, Set prefered default phy.", __func__);
2774     if ((p_msg = (tBTA_DM_API_SET_PER_DEF_PHY *) osi_malloc(sizeof(tBTA_DM_API_SET_PER_DEF_PHY))) != NULL) {
2775         memset(p_msg, 0, sizeof(tBTA_DM_API_SET_PER_DEF_PHY));
2776         p_msg->hdr.event = BTA_DM_API_SET_PER_DEF_PHY_EVT;
2777         p_msg->tx_phy_mask = tx_phy_mask;
2778         p_msg->rx_phy_mask = rx_phy_mask;
2779         //start sent the msg to the bta system control moudle
2780         bta_sys_sendmsg(p_msg);
2781     } else {
2782         APPL_TRACE_ERROR("%s malloc failed", __func__);
2783     }
2784 
2785 }
2786 
BTA_DmBleGapSetPreferedPHY(BD_ADDR addr,UINT8 all_phys,tBTA_DM_BLE_GAP_PHY_MASK tx_phy_mask,tBTA_DM_BLE_GAP_PHY_MASK rx_phy_mask,UINT16 phy_options)2787 void BTA_DmBleGapSetPreferedPHY(BD_ADDR addr,
2788                                                UINT8 all_phys,
2789                                                tBTA_DM_BLE_GAP_PHY_MASK tx_phy_mask,
2790                                                tBTA_DM_BLE_GAP_PHY_MASK rx_phy_mask,
2791                                                UINT16 phy_options)
2792 {
2793     tBTA_DM_API_SET_PER_PHY *p_msg;
2794     APPL_TRACE_API("%s, Set prefered phy.", __func__);
2795     if ((p_msg = (tBTA_DM_API_SET_PER_PHY *) osi_malloc(sizeof(tBTA_DM_API_SET_PER_PHY))) != NULL) {
2796         memset(p_msg, 0, sizeof(tBTA_DM_API_SET_PER_PHY));
2797         p_msg->hdr.event = BTA_DM_API_SET_PER_PHY_EVT;
2798         memcpy(p_msg->bd_addr, addr, BD_ADDR_LEN);
2799         p_msg->all_phys = all_phys;
2800         p_msg->tx_phy_mask = tx_phy_mask;
2801         p_msg->rx_phy_mask = rx_phy_mask;
2802         p_msg->phy_options = phy_options;
2803         //start sent the msg to the bta system control moudle
2804         bta_sys_sendmsg(p_msg);
2805     } else {
2806         APPL_TRACE_ERROR("%s malloc failed", __func__);
2807     }
2808 }
2809 
BTA_DmBleGapExtAdvSetRandaddr(UINT16 instance,BD_ADDR addr)2810 void BTA_DmBleGapExtAdvSetRandaddr(UINT16 instance, BD_ADDR addr)
2811 {
2812     tBTA_DM_API_EXT_ADV_SET_RAND_ADDR *p_msg;
2813     APPL_TRACE_API("%s, Set extended ADV parameters.", __func__);
2814     if ((p_msg = (tBTA_DM_API_EXT_ADV_SET_RAND_ADDR *) osi_malloc(sizeof(tBTA_DM_API_EXT_ADV_SET_RAND_ADDR))) != NULL) {
2815         memset(p_msg, 0, sizeof(tBTA_DM_API_EXT_ADV_SET_RAND_ADDR));
2816         p_msg->hdr.event = BTA_DM_API_SET_EXT_ADV_RAND_ADDR_EVT;
2817         p_msg->instance = instance;
2818         memcpy(&p_msg->rand_addr, addr, BD_ADDR_LEN);
2819         //start sent the msg to the bta system control moudle
2820         bta_sys_sendmsg(p_msg);
2821     } else {
2822         APPL_TRACE_ERROR("%s malloc failed", __func__);
2823     }
2824 
2825 }
2826 
BTA_DmBleGapExtAdvSetParams(UINT16 instance,const tBTA_DM_BLE_GAP_EXT_ADV_PARAMS * params)2827 void BTA_DmBleGapExtAdvSetParams(UINT16 instance,
2828                                                  const tBTA_DM_BLE_GAP_EXT_ADV_PARAMS *params)
2829 {
2830     tBTA_DM_API_EXT_ADV_SET_PARAMS *p_msg;
2831     APPL_TRACE_API("%s, Set extended ADV parameters.", __func__);
2832     if ((p_msg = (tBTA_DM_API_EXT_ADV_SET_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_EXT_ADV_SET_PARAMS))) != NULL) {
2833         memset(p_msg, 0, sizeof(tBTA_DM_API_EXT_ADV_SET_PARAMS));
2834         p_msg->hdr.event = BTA_DM_API_SET_EXT_ADV_PARAMS_EVT;
2835         p_msg->instance = instance;
2836         memcpy(&p_msg->params, params, sizeof(tBTA_DM_BLE_GAP_EXT_ADV_PARAMS));
2837         //start sent the msg to the bta system control moudle
2838         bta_sys_sendmsg(p_msg);
2839     } else {
2840         APPL_TRACE_ERROR("%s malloc failed", __func__);
2841     }
2842 
2843 }
2844 
BTA_DmBleGapConfigExtAdvDataRaw(BOOLEAN is_scan_rsp,UINT8 instance,UINT16 length,const UINT8 * data)2845 void BTA_DmBleGapConfigExtAdvDataRaw(BOOLEAN is_scan_rsp, UINT8 instance, UINT16 length,
2846                                                         const UINT8 *data)
2847 {
2848     tBTA_DM_API_CFG_EXT_ADV_DATA *p_msg;
2849     APPL_TRACE_API("%s, Config extended %s data.", __func__, is_scan_rsp ? "Scan rsp" : "Adv");
2850     if ((p_msg = (tBTA_DM_API_CFG_EXT_ADV_DATA *) osi_malloc(sizeof(tBTA_DM_API_CFG_EXT_ADV_DATA) + length)) != NULL) {
2851         memset(p_msg, 0, sizeof(tBTA_DM_API_CFG_EXT_ADV_DATA) + length);
2852         p_msg->hdr.event = BTA_DM_API_CFG_ADV_DATA_RAW_EVT;
2853         p_msg->is_scan_rsp = is_scan_rsp;
2854         p_msg->instance = instance;
2855         p_msg->length = length;
2856         p_msg->data = (UINT8 *)(p_msg + 1);
2857         if (data) {
2858             memcpy(p_msg->data, data, length);
2859         }
2860         //start sent the msg to the bta system control moudle
2861         bta_sys_sendmsg(p_msg);
2862     } else {
2863         APPL_TRACE_ERROR("%s malloc failed", __func__);
2864     }
2865 }
2866 
BTA_DmBleGapExtAdvEnable(BOOLEAN enable,UINT8 num,tBTA_DM_BLE_EXT_ADV * ext_adv)2867 void BTA_DmBleGapExtAdvEnable(BOOLEAN enable, UINT8 num, tBTA_DM_BLE_EXT_ADV *ext_adv)
2868 {
2869     tBTA_DM_API_BLE_EXT_ADV *p_msg;
2870     APPL_TRACE_API("%s, Start extended ADV", __func__);
2871     if ((p_msg = (tBTA_DM_API_BLE_EXT_ADV *) osi_malloc(sizeof(tBTA_DM_API_BLE_EXT_ADV) + sizeof(tBTA_DM_BLE_EXT_ADV)*num)) != NULL) {
2872         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_EXT_ADV) + sizeof(tBTA_DM_BLE_EXT_ADV)*num);
2873         p_msg->hdr.event = BTA_DM_API_EXT_ADV_ENABLE_EVT;
2874         p_msg->enable = enable;
2875         p_msg->num = num;
2876         p_msg->ext_adv = (tBTA_DM_BLE_EXT_ADV *)(p_msg + 1);
2877         if (ext_adv) {
2878             memcpy(p_msg->ext_adv, ext_adv, sizeof(tBTA_DM_BLE_EXT_ADV)*num);
2879         }
2880         //start sent the msg to the bta system control moudle
2881         bta_sys_sendmsg(p_msg);
2882     } else {
2883         APPL_TRACE_ERROR("%s malloc failed", __func__);
2884     }
2885 }
2886 
BTA_DmBleGapExtAdvSetRemove(UINT8 instance)2887 void BTA_DmBleGapExtAdvSetRemove(UINT8 instance)
2888 {
2889     tBTA_DM_API_BLE_EXT_ADV_SET_REMOVE *p_msg;
2890     APPL_TRACE_API("%s, Remove extended ADV", __func__);
2891     if ((p_msg = (tBTA_DM_API_BLE_EXT_ADV_SET_REMOVE *) osi_malloc(sizeof(tBTA_DM_API_BLE_EXT_ADV_SET_REMOVE))) != NULL) {
2892         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_EXT_ADV_SET_REMOVE));
2893         p_msg->hdr.event = BTA_DM_API_EXT_ADV_SET_REMOVE_EVT;
2894         p_msg->instance = instance;
2895         //start sent the msg to the bta system control moudle
2896         bta_sys_sendmsg(p_msg);
2897     } else {
2898         APPL_TRACE_ERROR("%s malloc failed", __func__);
2899     }
2900 }
2901 
BTA_DmBleGapExtAdvSetClear(void)2902 void BTA_DmBleGapExtAdvSetClear(void)
2903 {
2904     tBTA_DM_API_BLE_EXT_ADV_SET_CLEAR *p_msg;
2905     APPL_TRACE_API("%s, Clear extended ADV", __func__);
2906     if ((p_msg = (tBTA_DM_API_BLE_EXT_ADV_SET_CLEAR *) osi_malloc(sizeof(tBTA_DM_API_BLE_EXT_ADV_SET_CLEAR))) != NULL) {
2907         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_EXT_ADV_SET_CLEAR));
2908         p_msg->hdr.event = BTA_DM_API_EXT_ADV_SET_CLEAR_EVT;
2909         //start sent the msg to the bta system control moudle
2910         bta_sys_sendmsg(p_msg);
2911     } else {
2912         APPL_TRACE_ERROR("%s malloc failed", __func__);
2913     }
2914 }
2915 
BTA_DmBleGapPeriodicAdvSetParams(UINT8 instance,tBTA_DM_BLE_Periodic_Adv_Params * params)2916 void BTA_DmBleGapPeriodicAdvSetParams(UINT8 instance,
2917                                                          tBTA_DM_BLE_Periodic_Adv_Params *params)
2918 {
2919     tBTA_DM_API_BLE_PERIODIC_ADV_SET_PARAMS *p_msg;
2920     APPL_TRACE_API("%s, Periodic ADV set parameters.", __func__);
2921     if ((p_msg = (tBTA_DM_API_BLE_PERIODIC_ADV_SET_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_BLE_PERIODIC_ADV_SET_PARAMS))) != NULL) {
2922         memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_PERIODIC_ADV_SET_PARAMS));
2923         p_msg->hdr.event = BTA_DM_API_PERIODIC_ADV_SET_PARAMS_EVT;
2924         p_msg->instance = instance;
2925         memcpy(&p_msg->params, params, sizeof(tBTA_DM_BLE_Periodic_Adv_Params));
2926         //start sent the msg to the bta system control moudle
2927         bta_sys_sendmsg(p_msg);
2928     } else {
2929         APPL_TRACE_ERROR("%s malloc failed", __func__);
2930     }
2931 
2932 }
2933 
BTA_DmBleGapPeriodicAdvCfgDataRaw(UINT8 instance,UINT16 length,const UINT8 * data)2934 void BTA_DmBleGapPeriodicAdvCfgDataRaw(UINT8 instance, UINT16 length,
2935                                                            const UINT8 *data)
2936 {
2937     tBTA_DM_API_CFG_PERIODIC_ADV_DATA *p_msg;
2938     APPL_TRACE_API("%s, Periodic ADV config data raw.", __func__);
2939     if ((p_msg = (tBTA_DM_API_CFG_PERIODIC_ADV_DATA *) osi_malloc(sizeof(tBTA_DM_API_CFG_PERIODIC_ADV_DATA) + length)) != NULL) {
2940         memset(p_msg, 0, sizeof(tBTA_DM_API_CFG_PERIODIC_ADV_DATA) + length);
2941         p_msg->hdr.event = BTA_DM_API_PERIODIC_ADV_CFG_DATA_EVT;
2942         p_msg->instance = instance;
2943         p_msg->length = length;
2944         p_msg->data = (UINT8 *)(p_msg + 1);
2945         memcpy(p_msg->data, data, length);
2946         //start sent the msg to the bta system control moudle
2947         bta_sys_sendmsg(p_msg);
2948     } else {
2949         APPL_TRACE_ERROR("%s malloc failed", __func__);
2950     }
2951 
2952 }
2953 
BTA_DmBleGapPeriodicAdvEnable(BOOLEAN enable,UINT8 instance)2954 void BTA_DmBleGapPeriodicAdvEnable(BOOLEAN enable, UINT8 instance)
2955 {
2956     tBTA_DM_API_ENABLE_PERIODIC_ADV *p_msg;
2957     APPL_TRACE_API("%s, Periodic ADV %s.", __func__, enable ? "start" : "stop");
2958     if ((p_msg = (tBTA_DM_API_ENABLE_PERIODIC_ADV *) osi_malloc(sizeof(tBTA_DM_API_ENABLE_PERIODIC_ADV))) != NULL) {
2959         memset(p_msg, 0, sizeof(tBTA_DM_API_ENABLE_PERIODIC_ADV));
2960         p_msg->hdr.event = BTA_DM_API_PERIODIC_ADV_ENABLE_EVT;
2961         p_msg->instance = instance;
2962         p_msg->enable = enable;
2963         //start sent the msg to the bta system control moudle
2964         bta_sys_sendmsg(p_msg);
2965     } else {
2966         APPL_TRACE_ERROR("%s malloc failed", __func__);
2967     }
2968 
2969 }
2970 
BTA_DmBleGapPeriodicAdvCreateSync(tBTA_DM_BLE_Periodic_Sync_Params * params)2971 void BTA_DmBleGapPeriodicAdvCreateSync(tBTA_DM_BLE_Periodic_Sync_Params *params)
2972 {
2973     tBTA_DM_API_PERIODIC_ADV_SYNC *p_msg;
2974     APPL_TRACE_API("%s, Periodic ADV create sync.", __func__);
2975     if ((p_msg = (tBTA_DM_API_PERIODIC_ADV_SYNC *) osi_malloc(sizeof(tBTA_DM_API_PERIODIC_ADV_SYNC))) != NULL) {
2976         memset(p_msg, 0, sizeof(tBTA_DM_API_PERIODIC_ADV_SYNC));
2977         p_msg->hdr.event = BTA_DM_API_PERIODIC_ADV_SYNC_EVT;
2978         memcpy(&p_msg->params, params, sizeof(tBTA_DM_BLE_Periodic_Sync_Params));
2979         //start sent the msg to the bta system control moudle
2980         bta_sys_sendmsg(p_msg);
2981     } else {
2982         APPL_TRACE_ERROR("%s malloc failed", __func__);
2983     }
2984 
2985 }
2986 
BTA_DmBleGapPeriodicAdvSyncCancel(void)2987 void BTA_DmBleGapPeriodicAdvSyncCancel(void)
2988 {
2989     tBTA_DM_API_PERIODIC_ADV_SYNC_CANCEL *p_msg;
2990     APPL_TRACE_API("%s, Periodic ADV sync cancel.", __func__);
2991     if ((p_msg = (tBTA_DM_API_PERIODIC_ADV_SYNC_CANCEL *) osi_malloc(sizeof(tBTA_DM_API_PERIODIC_ADV_SYNC_CANCEL))) != NULL) {
2992         memset(p_msg, 0, sizeof(tBTA_DM_API_PERIODIC_ADV_SYNC_CANCEL));
2993         p_msg->hdr.event = BTA_DM_API_PERIODIC_ADV_SYNC_CANCEL_EVT;
2994         //start sent the msg to the bta system control moudle
2995         bta_sys_sendmsg(p_msg);
2996     } else {
2997         APPL_TRACE_ERROR("%s malloc failed", __func__);
2998     }
2999 
3000 }
3001 
BTA_DmBleGapPeriodicAdvSyncTerm(UINT16 sync_handle)3002 void BTA_DmBleGapPeriodicAdvSyncTerm(UINT16 sync_handle)
3003 {
3004     tBTA_DM_API_PERIODIC_ADV_SYNC_TERM *p_msg;
3005     APPL_TRACE_API("%s, Periodic ADV sync terminat.", __func__);
3006     if ((p_msg = (tBTA_DM_API_PERIODIC_ADV_SYNC_TERM *) osi_malloc(sizeof(tBTA_DM_API_PERIODIC_ADV_SYNC_TERM))) != NULL) {
3007         memset(p_msg, 0, sizeof(tBTA_DM_API_PERIODIC_ADV_SYNC_TERM));
3008         p_msg->hdr.event = BTA_DM_API_PERIODIC_ADV_SYNC_TERMINATE_EVT;
3009         p_msg->sync_handle = sync_handle;
3010         //start sent the msg to the bta system control moudle
3011         bta_sys_sendmsg(p_msg);
3012     } else {
3013         APPL_TRACE_ERROR("%s malloc failed", __func__);
3014     }
3015 
3016 }
3017 
BTA_DmBleGapPeriodicAdvAddDevToList(tBLE_ADDR_TYPE addr_type,BD_ADDR addr,UINT16 sid)3018 void BTA_DmBleGapPeriodicAdvAddDevToList(tBLE_ADDR_TYPE addr_type,
3019                                                               BD_ADDR addr,
3020                                                               UINT16 sid)
3021 {
3022     tBTA_DM_API_PERIODIC_ADV_ADD_DEV_TO_LIST *p_msg;
3023     APPL_TRACE_API("%s, Periodic ADV add device to list.", __func__);
3024     if ((p_msg = (tBTA_DM_API_PERIODIC_ADV_ADD_DEV_TO_LIST *) osi_malloc(sizeof(tBTA_DM_API_PERIODIC_ADV_ADD_DEV_TO_LIST))) != NULL) {
3025         memset(p_msg, 0, sizeof(tBTA_DM_API_PERIODIC_ADV_ADD_DEV_TO_LIST));
3026         p_msg->hdr.event = BTA_DM_API_PERIODIC_ADV_ADD_DEV_TO_LSIT_EVT;
3027         p_msg->addr_type = addr_type;
3028         p_msg->sid = sid;
3029         memcpy(p_msg->addr, addr, sizeof(BD_ADDR));
3030         //start sent the msg to the bta system control moudle
3031         bta_sys_sendmsg(p_msg);
3032     } else {
3033         APPL_TRACE_ERROR("%s malloc failed", __func__);
3034     }
3035 
3036 }
3037 
BTA_DmBleGapPeriodicAdvRemoveDevFromList(tBLE_ADDR_TYPE addr_type,BD_ADDR addr,UINT16 sid)3038 void BTA_DmBleGapPeriodicAdvRemoveDevFromList(tBLE_ADDR_TYPE addr_type,
3039                                                               BD_ADDR addr,
3040                                                               UINT16 sid)
3041 {
3042     tBTA_DM_API_PERIODIC_ADV_REMOVE_DEV_FROM_LIST *p_msg;
3043     APPL_TRACE_API("%s, Periodic ADV remove device from list.", __func__);
3044     if ((p_msg = (tBTA_DM_API_PERIODIC_ADV_REMOVE_DEV_FROM_LIST *) osi_malloc(sizeof(tBTA_DM_API_PERIODIC_ADV_REMOVE_DEV_FROM_LIST))) != NULL) {
3045         memset(p_msg, 0, sizeof(tBTA_DM_API_PERIODIC_ADV_REMOVE_DEV_FROM_LIST));
3046         p_msg->hdr.event = BTA_DM_API_PERIODIC_ADV_REMOVE_DEV_FROM_LSIT_EVT;
3047         p_msg->addr_type = addr_type;
3048         p_msg->sid = sid;
3049         memcpy(p_msg->addr, addr, sizeof(BD_ADDR));
3050         //start sent the msg to the bta system control moudle
3051         bta_sys_sendmsg(p_msg);
3052     } else {
3053         APPL_TRACE_ERROR("%s malloc failed", __func__);
3054     }
3055 
3056 }
3057 
BTA_DmBleGapPeriodicAdvClearDev(void)3058 void BTA_DmBleGapPeriodicAdvClearDev(void)
3059 {
3060     tBTA_DM_API_PERIODIC_ADV_DEV_CLEAR *p_msg;
3061     APPL_TRACE_API("%s, Periodic ADV clear device from list.", __func__);
3062     if ((p_msg = (tBTA_DM_API_PERIODIC_ADV_DEV_CLEAR *) osi_malloc(sizeof(tBTA_DM_API_PERIODIC_ADV_DEV_CLEAR))) != NULL) {
3063         memset(p_msg, 0, sizeof(tBTA_DM_API_PERIODIC_ADV_DEV_CLEAR));
3064         p_msg->hdr.event = BTA_DM_API_PERIODIC_ADV_CLEAR_DEV_EVT;
3065         //start sent the msg to the bta system control moudle
3066         bta_sys_sendmsg(p_msg);
3067     } else {
3068         APPL_TRACE_ERROR("%s malloc failed", __func__);
3069     }
3070 
3071 }
3072 
BTA_DmBleGapSetExtScanParams(tBTA_DM_BLE_EXT_SCAN_PARAMS * params)3073 void BTA_DmBleGapSetExtScanParams(tBTA_DM_BLE_EXT_SCAN_PARAMS *params)
3074 {
3075     tBTA_DM_API_SET_EXT_SCAN_PARAMS *p_msg;
3076     APPL_TRACE_API("%s, Set extended scan parameters.", __func__);
3077     if ((p_msg = (tBTA_DM_API_SET_EXT_SCAN_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_SET_EXT_SCAN_PARAMS))) != NULL) {
3078         memset(p_msg, 0, sizeof(tBTA_DM_API_SET_EXT_SCAN_PARAMS));
3079         p_msg->hdr.event = BTA_DM_API_SET_EXT_SCAN_PARAMS_EVT;
3080         memcpy(&p_msg->params, params, sizeof(tBTA_DM_BLE_EXT_SCAN_PARAMS));
3081         //start sent the msg to the bta system control moudle
3082         bta_sys_sendmsg(p_msg);
3083     } else {
3084         APPL_TRACE_ERROR("%s malloc failed", __func__);
3085     }
3086 
3087 }
3088 
BTA_DmBleGapExtScan(BOOLEAN start,UINT32 duration,UINT16 period)3089 void BTA_DmBleGapExtScan(BOOLEAN start, UINT32 duration, UINT16 period)
3090 {
3091     tBTA_DM_API_EXT_SCAN *p_msg;
3092     APPL_TRACE_API("%s, %s extended scan.", __func__, start ? "Start" : "Stop");
3093     if ((p_msg = (tBTA_DM_API_EXT_SCAN *) osi_malloc(sizeof(tBTA_DM_API_EXT_SCAN))) != NULL) {
3094         memset(p_msg, 0, sizeof(tBTA_DM_API_EXT_SCAN));
3095         p_msg->hdr.event = BTA_DM_API_START_EXT_SCAN_EVT;
3096         p_msg->start = start;
3097         p_msg->duration = duration;
3098         p_msg->period = period;
3099         //start sent the msg to the bta system control moudle
3100         bta_sys_sendmsg(p_msg);
3101     } else {
3102         APPL_TRACE_ERROR("%s malloc failed", __func__);
3103     }
3104 
3105 }
3106 
BTA_DmBleGapPreferExtConnectParamsSet(BD_ADDR bd_addr,UINT8 phy_mask,const tBTA_DM_BLE_CONN_PARAMS * phy_1m_conn_params,const tBTA_DM_BLE_CONN_PARAMS * phy_2m_conn_params,const tBTA_DM_BLE_CONN_PARAMS * phy_coded_conn_params)3107 void BTA_DmBleGapPreferExtConnectParamsSet(BD_ADDR bd_addr,
3108                                                                  UINT8 phy_mask,
3109                                                                  const tBTA_DM_BLE_CONN_PARAMS *phy_1m_conn_params,
3110                                                                  const tBTA_DM_BLE_CONN_PARAMS *phy_2m_conn_params,
3111                                                                  const tBTA_DM_BLE_CONN_PARAMS *phy_coded_conn_params)
3112 {
3113     tBTA_DM_API_SET_PER_EXT_CONN_PARAMS *p_msg;
3114     APPL_TRACE_API("%s, Set prefer extended connection parameters.", __func__);
3115     if ((p_msg = (tBTA_DM_API_SET_PER_EXT_CONN_PARAMS *) osi_malloc(sizeof(tBTA_DM_API_SET_PER_EXT_CONN_PARAMS))) != NULL) {
3116         memset(p_msg, 0, sizeof(tBTA_DM_API_SET_PER_EXT_CONN_PARAMS));
3117         p_msg->hdr.event = BTA_DM_API_SET_PERF_EXT_CONN_PARAMS_EVT;
3118         p_msg->phy_mask = phy_mask;
3119 
3120         memcpy(p_msg->bd_addr, bd_addr, sizeof(BD_ADDR));
3121 
3122         if (phy_1m_conn_params) {
3123             memcpy(&p_msg->phy_1m_conn_params, phy_1m_conn_params, sizeof(tBTA_DM_BLE_CONN_PARAMS));
3124         }
3125 
3126         if (phy_2m_conn_params) {
3127             memcpy(&p_msg->phy_2m_conn_params, phy_2m_conn_params, sizeof(tBTA_DM_BLE_CONN_PARAMS));
3128         }
3129 
3130         if (phy_coded_conn_params) {
3131             memcpy(&p_msg->phy_coded_conn_params, phy_coded_conn_params, sizeof(tBTA_DM_BLE_CONN_PARAMS));
3132         }
3133         //start sent the msg to the bta system control moudle
3134         bta_sys_sendmsg(p_msg);
3135     } else {
3136         APPL_TRACE_ERROR("%s malloc failed", __func__);
3137     }
3138 
3139 
3140 }
3141 
BTA_DmBleGapExtConnect(tBLE_ADDR_TYPE own_addr_type,const BD_ADDR peer_addr)3142 void BTA_DmBleGapExtConnect(tBLE_ADDR_TYPE own_addr_type, const BD_ADDR peer_addr)
3143 {
3144     tBTA_DM_API_EXT_CONN *p_msg;
3145     APPL_TRACE_API("%s, Start Extended connect.", __func__);
3146     APPL_TRACE_API("%s, Set prefer extended connection parameters.", __func__);
3147     if ((p_msg = (tBTA_DM_API_EXT_CONN *) osi_malloc(sizeof(tBTA_DM_API_EXT_CONN))) != NULL) {
3148         memset(p_msg, 0, sizeof(tBTA_DM_API_EXT_CONN));
3149         p_msg->hdr.event = BTA_DM_API_EXT_CONN_EVT;
3150         p_msg->own_addr_type = own_addr_type;
3151         memcpy(p_msg->peer_addr, peer_addr, sizeof(BD_ADDR));
3152         //start sent the msg to the bta system control moudle
3153         bta_sys_sendmsg(p_msg);
3154     } else {
3155         APPL_TRACE_ERROR("%s malloc failed", __func__);
3156     }
3157 
3158 }
3159 
3160 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
3161 
3162 #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
BTA_DmBlePeriodicAdvSetInfoTrans(uint8_t addr[6],uint16_t service_data,uint8_t adv_handle)3163 uint8_t BTA_DmBlePeriodicAdvSetInfoTrans(uint8_t addr[6], uint16_t service_data, uint8_t adv_handle)
3164 {
3165     BTM_BlePeriodicAdvSetInfoTrans(addr, service_data, adv_handle);
3166     return 0;
3167 }
3168 
BTA_DmBleSetPeriodicAdvSyncTransParams(uint8_t addr[6],uint8_t mode,uint16_t skip,uint16_t sync_timeout)3169 uint8_t BTA_DmBleSetPeriodicAdvSyncTransParams(uint8_t addr[6], uint8_t mode, uint16_t skip, uint16_t sync_timeout)
3170 {
3171     BTM_BleSetPeriodicAdvSyncTransParams(addr, mode, skip, sync_timeout, 0);
3172     return 0;
3173 }
3174 #endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
3175 
3176 #endif
3177