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