1 /******************************************************************************
2 *
3 * Copyright 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 <base/functional/bind.h>
26
27 #include <vector>
28
29 #include "bt_target.h" // Must be first to define build configuration
30 #include "bta/dm/bta_dm_int.h"
31 #include "osi/include/allocator.h"
32 #include "osi/include/compat.h"
33 #include "stack/btm/btm_sec.h"
34 #include "stack/include/bt_octets.h"
35 #include "stack/include/btm_api.h"
36 #include "stack/include/btm_client_interface.h"
37 #include "stack/include/btu.h" // do_in_main_thread
38 #include "types/bluetooth/uuid.h"
39 #include "types/raw_address.h"
40
41 using bluetooth::Uuid;
42
43 /*****************************************************************************
44 * Constants
45 ****************************************************************************/
46
47 static const tBTA_SYS_REG bta_dm_search_reg = {bta_dm_search_sm_execute,
48 bta_dm_search_sm_disable};
49
BTA_dm_init()50 void BTA_dm_init() {
51 bta_sys_register(BTA_ID_DM_SEARCH, &bta_dm_search_reg);
52 /* if UUID list is not provided as static data */
53 bta_sys_eir_register(bta_dm_eir_update_uuid);
54 bta_sys_cust_eir_register(bta_dm_eir_update_cust_uuid);
55 BTM_SetConsolidationCallback(bta_dm_consolidate);
56 }
57
58 /** This function sets the Bluetooth name of local device */
BTA_DmSetDeviceName(const char * p_name)59 void BTA_DmSetDeviceName(const char* p_name) {
60 std::vector<uint8_t> name(BD_NAME_LEN + 1);
61 strlcpy((char*)name.data(), p_name, BD_NAME_LEN + 1);
62
63 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_set_dev_name, name));
64 }
65
66 /*******************************************************************************
67 *
68 * Function BTA_DmSearch
69 *
70 * Description This function searches for peer Bluetooth devices. It
71 * performs an inquiry and gets the remote name for devices.
72 * Service discovery is done if services is non zero
73 *
74 *
75 * Returns void
76 *
77 ******************************************************************************/
BTA_DmSearch(tBTA_DM_SEARCH_CBACK * p_cback)78 void BTA_DmSearch(tBTA_DM_SEARCH_CBACK* p_cback) {
79 tBTA_DM_API_SEARCH* p_msg =
80 (tBTA_DM_API_SEARCH*)osi_calloc(sizeof(tBTA_DM_API_SEARCH));
81
82 p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
83 p_msg->p_cback = p_cback;
84
85 bta_sys_sendmsg(p_msg);
86 }
87
88 /*******************************************************************************
89 *
90 * Function BTA_DmSearchCancel
91 *
92 * Description This function cancels a search initiated by BTA_DmSearch
93 *
94 *
95 * Returns void
96 *
97 ******************************************************************************/
BTA_DmSearchCancel(void)98 void BTA_DmSearchCancel(void) {
99 tBTA_DM_API_DISCOVERY_CANCEL* p_msg =
100 (tBTA_DM_API_DISCOVERY_CANCEL*)osi_calloc(
101 sizeof(tBTA_DM_API_DISCOVERY_CANCEL));
102
103 p_msg->hdr.event = BTA_DM_API_SEARCH_CANCEL_EVT;
104 bta_sys_sendmsg(p_msg);
105 }
106
107 /*******************************************************************************
108 *
109 * Function BTA_DmDiscover
110 *
111 * Description This function does service discovery for services of a
112 * peer device
113 *
114 *
115 * Returns void
116 *
117 ******************************************************************************/
BTA_DmDiscover(const RawAddress & bd_addr,tBTA_DM_SEARCH_CBACK * p_cback,tBT_TRANSPORT transport)118 void BTA_DmDiscover(const RawAddress& bd_addr, tBTA_DM_SEARCH_CBACK* p_cback,
119 tBT_TRANSPORT transport) {
120 tBTA_DM_API_DISCOVER* p_msg =
121 (tBTA_DM_API_DISCOVER*)osi_calloc(sizeof(tBTA_DM_API_DISCOVER));
122
123 p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
124 p_msg->bd_addr = bd_addr;
125 p_msg->transport = transport;
126 p_msg->p_cback = p_cback;
127
128 bta_sys_sendmsg(p_msg);
129 }
130
131 /** This function initiates a bonding procedure with a peer device */
BTA_DmBond(const RawAddress & bd_addr,tBLE_ADDR_TYPE addr_type,tBT_TRANSPORT transport,tBT_DEVICE_TYPE device_type)132 void BTA_DmBond(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
133 tBT_TRANSPORT transport, tBT_DEVICE_TYPE device_type) {
134 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_bond, bd_addr, addr_type,
135 transport, device_type));
136 }
137
138 /** This function cancels the bonding procedure with a peer device
139 */
BTA_DmBondCancel(const RawAddress & bd_addr)140 void BTA_DmBondCancel(const RawAddress& bd_addr) {
141 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_bond_cancel, bd_addr));
142 }
143
144 /*******************************************************************************
145 *
146 * Function BTA_DmPinReply
147 *
148 * Description This function provides a pincode for a remote device when
149 * one is requested by DM through BTA_DM_PIN_REQ_EVT
150 *
151 *
152 * Returns void
153 *
154 ******************************************************************************/
BTA_DmPinReply(const RawAddress & bd_addr,bool accept,uint8_t pin_len,uint8_t * p_pin)155 void BTA_DmPinReply(const RawAddress& bd_addr, bool accept, uint8_t pin_len,
156 uint8_t* p_pin) {
157 std::unique_ptr<tBTA_DM_API_PIN_REPLY> msg =
158 std::make_unique<tBTA_DM_API_PIN_REPLY>();
159
160 msg->bd_addr = bd_addr;
161 msg->accept = accept;
162 if (accept) {
163 msg->pin_len = pin_len;
164 memcpy(msg->p_pin, p_pin, pin_len);
165 }
166
167 do_in_main_thread(FROM_HERE,
168 base::Bind(bta_dm_pin_reply, base::Passed(&msg)));
169 }
170
171 /*******************************************************************************
172 *
173 * Function BTA_DmLocalOob
174 *
175 * Description This function retrieves the OOB data from local controller.
176 * The result is reported by:
177 * - bta_dm_co_loc_oob_ext() if device supports secure
178 * connections (SC)
179 * - bta_dm_co_loc_oob() if device doesn't support SC
180 *
181 * Returns void
182 *
183 ******************************************************************************/
BTA_DmLocalOob(void)184 void BTA_DmLocalOob(void) {
185 do_in_main_thread(FROM_HERE, base::Bind(BTM_ReadLocalOobData));
186 }
187
188 /*******************************************************************************
189 *
190 * Function BTA_DmConfirm
191 *
192 * Description This function accepts or rejects the numerical value of the
193 * Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
194 *
195 * Returns void
196 *
197 ******************************************************************************/
BTA_DmConfirm(const RawAddress & bd_addr,bool accept)198 void BTA_DmConfirm(const RawAddress& bd_addr, bool accept) {
199 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_confirm, bd_addr, accept));
200 }
201
202 /*******************************************************************************
203 *
204 * Function BTA_DmAddDevice
205 *
206 * Description This function adds a device to the security database list of
207 * peer device
208 *
209 *
210 * Returns void
211 *
212 ******************************************************************************/
BTA_DmAddDevice(const RawAddress & bd_addr,DEV_CLASS dev_class,const LinkKey & link_key,uint8_t key_type,uint8_t pin_length)213 void BTA_DmAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
214 const LinkKey& link_key, uint8_t key_type,
215 uint8_t pin_length) {
216 std::unique_ptr<tBTA_DM_API_ADD_DEVICE> msg =
217 std::make_unique<tBTA_DM_API_ADD_DEVICE>();
218
219 msg->bd_addr = bd_addr;
220 msg->link_key_known = true;
221 msg->key_type = key_type;
222 msg->link_key = link_key;
223
224 /* Load device class if specified */
225 if (dev_class) {
226 msg->dc_known = true;
227 memcpy(msg->dc, dev_class, DEV_CLASS_LEN);
228 }
229
230 memset(msg->bd_name, 0, BD_NAME_LEN + 1);
231 msg->pin_length = pin_length;
232
233 do_in_main_thread(FROM_HERE,
234 base::Bind(bta_dm_add_device, base::Passed(&msg)));
235 }
236
237 /** This function removes a device fromthe security database list of peer
238 * device. It manages unpairing even while connected */
BTA_DmRemoveDevice(const RawAddress & bd_addr)239 tBTA_STATUS BTA_DmRemoveDevice(const RawAddress& bd_addr) {
240 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_remove_device, bd_addr));
241 return BTA_SUCCESS;
242 }
243
244 /*******************************************************************************
245 *
246 * Function BTA_GetEirService
247 *
248 * Description This function is called to get BTA service mask from EIR.
249 *
250 * Parameters p_eir - pointer of EIR significant part
251 * p_services - return the BTA service mask
252 *
253 * Returns None
254 *
255 ******************************************************************************/
256 extern const uint16_t bta_service_id_to_uuid_lkup_tbl[];
BTA_GetEirService(const uint8_t * p_eir,size_t eir_len,tBTA_SERVICE_MASK * p_services)257 void BTA_GetEirService(const uint8_t* p_eir, size_t eir_len,
258 tBTA_SERVICE_MASK* p_services) {
259 uint8_t xx, yy;
260 uint8_t num_uuid, max_num_uuid = 32;
261 uint8_t uuid_list[32 * Uuid::kNumBytes16];
262 uint16_t* p_uuid16 = (uint16_t*)uuid_list;
263 tBTA_SERVICE_MASK mask;
264
265 get_btm_client_interface().eir.BTM_GetEirUuidList(
266 p_eir, eir_len, Uuid::kNumBytes16, &num_uuid, uuid_list, max_num_uuid);
267 for (xx = 0; xx < num_uuid; xx++) {
268 mask = 1;
269 for (yy = 0; yy < BTA_MAX_SERVICE_ID; yy++) {
270 if (*(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy]) {
271 *p_services |= mask;
272 break;
273 }
274 mask <<= 1;
275 }
276
277 /* for HSP v1.2 only device */
278 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS)
279 *p_services |= BTA_HSP_SERVICE_MASK;
280
281 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE)
282 *p_services |= BTA_HL_SERVICE_MASK;
283
284 if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK)
285 *p_services |= BTA_HL_SERVICE_MASK;
286 }
287 }
288
289 /*******************************************************************************
290 *
291 * Function BTA_DmGetConnectionState
292 *
293 * Description Returns whether the remote device is currently connected.
294 *
295 * Returns 0 if the device is NOT connected.
296 *
297 ******************************************************************************/
BTA_DmGetConnectionState(const RawAddress & bd_addr)298 bool BTA_DmGetConnectionState(const RawAddress& bd_addr) {
299 tBTA_DM_PEER_DEVICE* p_dev = bta_dm_find_peer_device(bd_addr);
300 return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
301 }
302
303 /*******************************************************************************
304 * Device Identification (DI) Server Functions
305 ******************************************************************************/
306 /*******************************************************************************
307 *
308 * Function BTA_DmSetLocalDiRecord
309 *
310 * Description This function adds a DI record to the local SDP database.
311 *
312 * Returns BTA_SUCCESS if record set sucessfully, otherwise error code.
313 *
314 ******************************************************************************/
BTA_DmSetLocalDiRecord(tSDP_DI_RECORD * p_device_info,uint32_t * p_handle)315 tBTA_STATUS BTA_DmSetLocalDiRecord(tSDP_DI_RECORD* p_device_info,
316 uint32_t* p_handle) {
317 tBTA_STATUS status = BTA_FAILURE;
318
319 if (bta_dm_di_cb.di_num < BTA_DI_NUM_MAX) {
320 if (SDP_SetLocalDiRecord((tSDP_DI_RECORD*)p_device_info, p_handle) ==
321 SDP_SUCCESS) {
322 if (!p_device_info->primary_record) {
323 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
324 bta_dm_di_cb.di_num++;
325 }
326
327 bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
328 status = BTA_SUCCESS;
329 }
330 }
331
332 return status;
333 }
334
335 /*******************************************************************************
336 *
337 * Function BTA_DmAddBleKey
338 *
339 * Description Add/modify LE device information. This function will be
340 * normally called during host startup to restore all required
341 * information stored in the NVRAM.
342 *
343 * Parameters: bd_addr - BD address of the peer
344 * p_le_key - LE key values.
345 * key_type - LE SMP key type.
346 *
347 * Returns BTA_SUCCESS if successful
348 * BTA_FAIL if operation failed.
349 *
350 ******************************************************************************/
BTA_DmAddBleKey(const RawAddress & bd_addr,tBTA_LE_KEY_VALUE * p_le_key,tBTM_LE_KEY_TYPE key_type)351 void BTA_DmAddBleKey(const RawAddress& bd_addr, tBTA_LE_KEY_VALUE* p_le_key,
352 tBTM_LE_KEY_TYPE key_type) {
353 do_in_main_thread(
354 FROM_HERE, base::Bind(bta_dm_add_blekey, bd_addr, *p_le_key, key_type));
355 }
356
357 /*******************************************************************************
358 *
359 * Function BTA_DmAddBleDevice
360 *
361 * Description Add a BLE device. This function will be normally called
362 * during host startup to restore all required information
363 * for a LE device stored in the NVRAM.
364 *
365 * Parameters: bd_addr - BD address of the peer
366 * dev_type - Remote device's device type.
367 * addr_type - LE device address type.
368 *
369 * Returns void
370 *
371 ******************************************************************************/
BTA_DmAddBleDevice(const RawAddress & bd_addr,tBLE_ADDR_TYPE addr_type,tBT_DEVICE_TYPE dev_type)372 void BTA_DmAddBleDevice(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
373 tBT_DEVICE_TYPE dev_type) {
374 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_add_ble_device, bd_addr,
375 addr_type, dev_type));
376 }
377
378 /*******************************************************************************
379 *
380 * Function BTA_DmBlePasskeyReply
381 *
382 * Description Send BLE SMP passkey reply.
383 *
384 * Parameters: bd_addr - BD address of the peer
385 * accept - passkey entry sucessful or declined.
386 * passkey - passkey value, must be a 6 digit number,
387 * can be lead by 0.
388 *
389 * Returns void
390 *
391 ******************************************************************************/
BTA_DmBlePasskeyReply(const RawAddress & bd_addr,bool accept,uint32_t passkey)392 void BTA_DmBlePasskeyReply(const RawAddress& bd_addr, bool accept,
393 uint32_t passkey) {
394 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_ble_passkey_reply, bd_addr,
395 accept, accept ? passkey : 0));
396 }
397
398 /*******************************************************************************
399 *
400 * Function BTA_DmBleConfirmReply
401 *
402 * Description Send BLE SMP SC user confirmation reply.
403 *
404 * Parameters: bd_addr - BD address of the peer
405 * accept - numbers to compare are the same or
406 * different.
407 *
408 * Returns void
409 *
410 ******************************************************************************/
BTA_DmBleConfirmReply(const RawAddress & bd_addr,bool accept)411 void BTA_DmBleConfirmReply(const RawAddress& bd_addr, bool accept) {
412 do_in_main_thread(FROM_HERE,
413 base::Bind(bta_dm_ble_confirm_reply, bd_addr, accept));
414 }
415
416 /*******************************************************************************
417 *
418 * Function BTA_DmBleSecurityGrant
419 *
420 * Description Grant security request access.
421 *
422 * Parameters: bd_addr - BD address of the peer
423 * res - security grant status.
424 *
425 * Returns void
426 *
427 ******************************************************************************/
BTA_DmBleSecurityGrant(const RawAddress & bd_addr,tBTA_DM_BLE_SEC_GRANT res)428 void BTA_DmBleSecurityGrant(const RawAddress& bd_addr,
429 tBTA_DM_BLE_SEC_GRANT res) {
430 do_in_main_thread(FROM_HERE, base::Bind(BTM_SecurityGrant, bd_addr, res));
431 }
432
433 /*******************************************************************************
434 *
435 * Function BTA_DmSetBlePrefConnParams
436 *
437 * Description This function is called to set the preferred connection
438 * parameters when default connection parameter is not desired.
439 *
440 * Parameters: bd_addr - BD address of the peripheral
441 * scan_interval - scan interval
442 * scan_window - scan window
443 * min_conn_int - minimum preferred connection interval
444 * max_conn_int - maximum preferred connection interval
445 * peripheral_latency - preferred peripheral latency
446 * supervision_tout - preferred supervision timeout
447 *
448 *
449 * Returns void
450 *
451 ******************************************************************************/
BTA_DmSetBlePrefConnParams(const RawAddress & bd_addr,uint16_t min_conn_int,uint16_t max_conn_int,uint16_t peripheral_latency,uint16_t supervision_tout)452 void BTA_DmSetBlePrefConnParams(const RawAddress& bd_addr,
453 uint16_t min_conn_int, uint16_t max_conn_int,
454 uint16_t peripheral_latency,
455 uint16_t supervision_tout) {
456 do_in_main_thread(
457 FROM_HERE,
458 base::Bind(bta_dm_ble_set_conn_params, bd_addr, min_conn_int,
459 max_conn_int, peripheral_latency, supervision_tout));
460 }
461
462 /*******************************************************************************
463 *
464 * Function BTA_DmBleUpdateConnectionParam
465 *
466 * Description Update connection parameters, can only be used when
467 * connection is up.
468 *
469 * Parameters: bd_addr - BD address of the peer
470 * min_int - minimum connection interval,
471 * [0x0004 ~ 0x4000]
472 * max_int - maximum connection interval,
473 * [0x0004 ~ 0x4000]
474 * latency - peripheral latency [0 ~ 500]
475 * timeout - supervision timeout [0x000a ~ 0xc80]
476 *
477 * Returns void
478 *
479 ******************************************************************************/
BTA_DmBleUpdateConnectionParams(const RawAddress & bd_addr,uint16_t min_int,uint16_t max_int,uint16_t latency,uint16_t timeout,uint16_t min_ce_len,uint16_t max_ce_len)480 void BTA_DmBleUpdateConnectionParams(const RawAddress& bd_addr,
481 uint16_t min_int, uint16_t max_int,
482 uint16_t latency, uint16_t timeout,
483 uint16_t min_ce_len, uint16_t max_ce_len) {
484 do_in_main_thread(
485 FROM_HERE, base::Bind(bta_dm_ble_update_conn_params, bd_addr, min_int,
486 max_int, latency, timeout, min_ce_len, max_ce_len));
487 }
488
489 /*******************************************************************************
490 *
491 * Function BTA_DmBleConfigLocalPrivacy
492 *
493 * Description Enable/disable privacy on the local device
494 *
495 * Parameters: privacy_enable - enable/disabe privacy on remote device.
496 *
497 * Returns void
498 *
499 ******************************************************************************/
BTA_DmBleConfigLocalPrivacy(bool privacy_enable)500 void BTA_DmBleConfigLocalPrivacy(bool privacy_enable) {
501 do_in_main_thread(
502 FROM_HERE, base::Bind(bta_dm_ble_config_local_privacy, privacy_enable));
503 }
504
505 /*******************************************************************************
506 *
507 * Function BTA_DmBleGetEnergyInfo
508 *
509 * Description This function is called to obtain the energy info
510 *
511 * Parameters p_cmpl_cback - Command complete callback
512 *
513 * Returns void
514 *
515 ******************************************************************************/
BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK * p_cmpl_cback)516 void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK* p_cmpl_cback) {
517 do_in_main_thread(FROM_HERE,
518 base::Bind(bta_dm_ble_get_energy_info, p_cmpl_cback));
519 }
520
521 /** This function is to set maximum LE data packet size */
BTA_DmBleRequestMaxTxDataLength(const RawAddress & remote_device)522 void BTA_DmBleRequestMaxTxDataLength(const RawAddress& remote_device) {
523 do_in_main_thread(FROM_HERE,
524 base::Bind(bta_dm_ble_set_data_length, remote_device));
525 }
526
527 /*******************************************************************************
528 *
529 * Function BTA_DmSetEncryption
530 *
531 * Description This function is called to ensure that connection is
532 * encrypted. Should be called only on an open connection.
533 * Typically only needed for connections that first want to
534 * bring up unencrypted links, then later encrypt them.
535 *
536 * Parameters: bd_addr - Address of the peer device
537 * transport - transport of the link to be encruypted
538 * p_callback - Pointer to callback function to indicat the
539 * link encryption status
540 * sec_act - This is the security action to indicate
541 * what kind of BLE security level is required
542 * for the BLE link if BLE is supported.
543 * Note: This parameter is ignored for the
544 * BR/EDR or if BLE is not supported.
545 *
546 * Returns void
547 *
548 ******************************************************************************/
BTA_DmSetEncryption(const RawAddress & bd_addr,tBT_TRANSPORT transport,tBTA_DM_ENCRYPT_CBACK * p_callback,tBTM_BLE_SEC_ACT sec_act)549 void BTA_DmSetEncryption(const RawAddress& bd_addr, tBT_TRANSPORT transport,
550 tBTA_DM_ENCRYPT_CBACK* p_callback,
551 tBTM_BLE_SEC_ACT sec_act) {
552 APPL_TRACE_API("%s", __func__);
553 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_set_encryption, bd_addr,
554 transport, p_callback, sec_act));
555 }
556
557 /*******************************************************************************
558 *
559 * Function BTA_DmCloseACL
560 *
561 * Description This function force to close an ACL connection and remove
562 * the device from the security database list of known devices.
563 *
564 * Parameters: bd_addr - Address of the peer device
565 * remove_dev - remove device or not after link down
566 *
567 * Returns void
568 *
569 ******************************************************************************/
BTA_DmCloseACL(const RawAddress & bd_addr,bool remove_dev,tBT_TRANSPORT transport)570 void BTA_DmCloseACL(const RawAddress& bd_addr, bool remove_dev,
571 tBT_TRANSPORT transport) {
572 do_in_main_thread(
573 FROM_HERE, base::Bind(bta_dm_close_acl, bd_addr, remove_dev, transport));
574 }
575
576 /*******************************************************************************
577 *
578 * Function BTA_DmBleObserve
579 *
580 * Description This procedure keep the device listening for advertising
581 * events from a broadcast device.
582 *
583 * Parameters start: start or stop observe.
584 *
585 * Returns void
586
587 *
588 * Returns void.
589 *
590 ******************************************************************************/
BTA_DmBleObserve(bool start,uint8_t duration,tBTA_DM_SEARCH_CBACK * p_results_cb)591 void BTA_DmBleObserve(bool start, uint8_t duration,
592 tBTA_DM_SEARCH_CBACK* p_results_cb) {
593 APPL_TRACE_API("%s:start = %d ", __func__, start);
594 do_in_main_thread(
595 FROM_HERE, base::Bind(bta_dm_ble_observe, start, duration, p_results_cb));
596 }
597
598 /*******************************************************************************
599 *
600 * Function BTA_DmBleScan
601 *
602 * Description Start or stop the scan procedure if it's not already started
603 * with BTA_DmBleObserve().
604 *
605 * Parameters start: start or stop the scan procedure,
606 * duration_sec: Duration of the scan. Continuous scan if 0 is
607 * passed,
608 * low_latency_scan: whether this is an low latency scan,
609 * default is false.
610 *
611 * Returns void
612 *
613 ******************************************************************************/
BTA_DmBleScan(bool start,uint8_t duration_sec,bool low_latency_scan)614 void BTA_DmBleScan(bool start, uint8_t duration_sec, bool low_latency_scan) {
615 APPL_TRACE_API("%s:start = %d ", __func__, start);
616 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_ble_scan, start, duration_sec,
617 low_latency_scan));
618 }
619
620 /*******************************************************************************
621 *
622 * Function BTA_DmBleCsisObserve
623 *
624 * Description This procedure keeps the external observer listening for
625 * advertising events from a CSIS grouped device.
626 *
627 * Parameters observe: enable or disable passive observe,
628 * p_results_cb: Callback to be called with scan results,
629 *
630 * Returns void
631 *
632 ******************************************************************************/
BTA_DmBleCsisObserve(bool observe,tBTA_DM_SEARCH_CBACK * p_results_cb)633 void BTA_DmBleCsisObserve(bool observe, tBTA_DM_SEARCH_CBACK* p_results_cb) {
634 APPL_TRACE_API("%s:enable = %d ", __func__, observe);
635 do_in_main_thread(FROM_HERE,
636 base::Bind(bta_dm_ble_csis_observe, observe, p_results_cb));
637 }
638
639 /*******************************************************************************
640 *
641 * Function BTA_VendorInit
642 *
643 * Description This function initializes vendor specific
644 *
645 * Returns void
646 *
647 ******************************************************************************/
BTA_VendorInit(void)648 void BTA_VendorInit(void) { APPL_TRACE_API("BTA_VendorInit"); }
649
650 /*******************************************************************************
651 *
652 * Function BTA_DmClearEventFilter
653 *
654 * Description This function clears the event filter
655 *
656 * Returns void
657 *
658 ******************************************************************************/
BTA_DmClearEventFilter(void)659 void BTA_DmClearEventFilter(void) {
660 APPL_TRACE_API("BTA_DmClearEventFilter");
661 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_clear_event_filter));
662 }
663
664 /*******************************************************************************
665 *
666 * Function BTA_DmClearEventMask
667 *
668 * Description This function clears the event mask
669 *
670 * Returns void
671 *
672 ******************************************************************************/
BTA_DmClearEventMask(void)673 void BTA_DmClearEventMask(void) {
674 APPL_TRACE_API("BTA_DmClearEventMask");
675 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_clear_event_mask));
676 }
677
678 /*******************************************************************************
679 *
680 * Function BTA_DmClearEventMask
681 *
682 * Description This function clears the filter accept list
683 *
684 * Returns void
685 *
686 ******************************************************************************/
BTA_DmClearFilterAcceptList(void)687 void BTA_DmClearFilterAcceptList(void) {
688 APPL_TRACE_API("BTA_DmClearFilterAcceptList");
689 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_clear_filter_accept_list));
690 }
691
692 /*******************************************************************************
693 *
694 * Function BTA_DmLeRand
695 *
696 * Description This function clears the event filter
697 *
698 * Returns cb: callback to receive the resulting random number
699 *
700 ******************************************************************************/
BTA_DmLeRand(LeRandCallback cb)701 void BTA_DmLeRand(LeRandCallback cb) {
702 APPL_TRACE_API("BTA_DmLeRand");
703 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_le_rand, cb));
704 }
705
706 /*******************************************************************************
707 *
708 * Function BTA_DmDisconnectAllAcls
709 *
710 * Description This function will disconnect all LE and Classic ACLs.
711 *
712 * Returns void
713 *
714 ******************************************************************************/
BTA_DmDisconnectAllAcls()715 void BTA_DmDisconnectAllAcls() {
716 APPL_TRACE_API("BTA_DmLeRand");
717 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_disconnect_all_acls));
718 }
719
BTA_DmSetEventFilterConnectionSetupAllDevices()720 void BTA_DmSetEventFilterConnectionSetupAllDevices() {
721 APPL_TRACE_API("BTA_DmSetEventFilterConnectionSetupAllDevices");
722 do_in_main_thread(
723 FROM_HERE,
724 base::Bind(bta_dm_set_event_filter_connection_setup_all_devices));
725 }
726
BTA_DmAllowWakeByHid(std::vector<RawAddress> classic_hid_devices,std::vector<std::pair<RawAddress,uint8_t>> le_hid_devices)727 void BTA_DmAllowWakeByHid(
728 std::vector<RawAddress> classic_hid_devices,
729 std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices) {
730 APPL_TRACE_API("BTA_DmAllowWakeByHid");
731 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_allow_wake_by_hid,
732 std::move(classic_hid_devices),
733 std::move(le_hid_devices)));
734 }
735
BTA_DmRestoreFilterAcceptList(std::vector<std::pair<RawAddress,uint8_t>> le_devices)736 void BTA_DmRestoreFilterAcceptList(
737 std::vector<std::pair<RawAddress, uint8_t>> le_devices) {
738 APPL_TRACE_API("BTA_DmRestoreFilterAcceptList");
739 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_restore_filter_accept_list,
740 std::move(le_devices)));
741 }
742
BTA_DmSetDefaultEventMaskExcept(uint64_t mask,uint64_t le_mask)743 void BTA_DmSetDefaultEventMaskExcept(uint64_t mask, uint64_t le_mask) {
744 APPL_TRACE_API("BTA_DmSetDefaultEventMaskExcept");
745 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_set_default_event_mask_except,
746 mask, le_mask));
747 }
748
BTA_DmSetEventFilterInquiryResultAllDevices()749 void BTA_DmSetEventFilterInquiryResultAllDevices() {
750 APPL_TRACE_API("BTA_DmSetEventFilterInquiryResultAllDevices");
751 do_in_main_thread(
752 FROM_HERE,
753 base::Bind(bta_dm_set_event_filter_inquiry_result_all_devices));
754 }
755
756 /*******************************************************************************
757 *
758 * Function BTA_DmBleResetId
759 *
760 * Description This function resets the ble keys such as IRK
761 *
762 * Returns void
763 *
764 ******************************************************************************/
BTA_DmBleResetId(void)765 void BTA_DmBleResetId(void) {
766 APPL_TRACE_API("BTA_DmBleResetId");
767 do_in_main_thread(FROM_HERE, base::Bind(bta_dm_ble_reset_id));
768 }
769
770 /*******************************************************************************
771 *
772 * Function BTA_DmBleSubrateRequest
773 *
774 * Description subrate request, can only be used when connection is up.
775 *
776 * Parameters: bd_addr - BD address of the peer
777 * subrate_min - subrate factor minimum, [0x0001 - 0x01F4]
778 * subrate_max - subrate factor maximum, [0x0001 - 0x01F4]
779 * max_latency - max peripheral latency [0x0000 - 01F3]
780 * cont_num - continuation number [0x0000 - 01F3]
781 * timeout - supervision timeout [0x000a - 0xc80]
782 *
783 * Returns void
784 *
785 ******************************************************************************/
BTA_DmBleSubrateRequest(const RawAddress & bd_addr,uint16_t subrate_min,uint16_t subrate_max,uint16_t max_latency,uint16_t cont_num,uint16_t timeout)786 void BTA_DmBleSubrateRequest(const RawAddress& bd_addr, uint16_t subrate_min,
787 uint16_t subrate_max, uint16_t max_latency,
788 uint16_t cont_num, uint16_t timeout) {
789 APPL_TRACE_API("%s", __func__);
790 do_in_main_thread(FROM_HERE,
791 base::Bind(bta_dm_ble_subrate_request, bd_addr, subrate_min,
792 subrate_max, max_latency, cont_num, timeout));
793 }
794
BTA_DmCheckLeAudioCapable(const RawAddress & address)795 bool BTA_DmCheckLeAudioCapable(const RawAddress& address) {
796 for (tBTM_INQ_INFO* inq_ent = BTM_InqDbFirst(); inq_ent != nullptr;
797 inq_ent = BTM_InqDbNext(inq_ent)) {
798 if (inq_ent->results.remote_bd_addr != address) continue;
799
800 LOG_INFO("Device is LE Audio capable based on AD content");
801 return inq_ent->results.ble_ad_is_le_audio_capable;
802 }
803 return false;
804 }
805