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 public interface file for BTA, Broadcom's Bluetooth
22 * application layer for mobile phones.
23 *
24 ******************************************************************************/
25 #ifndef BTA_API_H
26 #define BTA_API_H
27
28 #include <base/functional/callback.h>
29 #include <base/strings/stringprintf.h>
30 #include <bluetooth/log.h>
31
32 #include <cstdint>
33 #include <vector>
34
35 #include "bta_api_data_types.h"
36 #include "hci/le_rand_callback.h"
37 #include "macros.h"
38 #include "stack/btm/btm_eir.h"
39 #include "stack/btm/power_mode.h"
40 #include "stack/include/bt_dev_class.h"
41 #include "stack/include/bt_device_type.h"
42 #include "stack/include/bt_name.h"
43 #include "stack/include/btm_api_types.h"
44 #include "stack/include/btm_ble_api_types.h"
45 #include "stack/include/hci_error_code.h"
46 #include "stack/include/sdp_device_id.h"
47 #include "types/ble_address_with_type.h"
48 #include "types/bluetooth/uuid.h"
49 #include "types/bt_transport.h"
50 #include "types/raw_address.h"
51
52 /*
53 * Service ID
54 */
55
56 #define BTA_A2DP_SOURCE_SERVICE_ID 3 /* A2DP Source profile. */
57 #define BTA_HSP_SERVICE_ID 5 /* Headset profile. */
58 #define BTA_HFP_SERVICE_ID 6 /* Hands-free profile. */
59 #define BTA_BIP_SERVICE_ID 13 /* Basic Imaging profile */
60 #define BTA_A2DP_SINK_SERVICE_ID 18 /* A2DP Sink */
61 #define BTA_HID_SERVICE_ID 20 /* HID */
62 #define BTA_PBAP_SERVICE_ID 22 /* PhoneBook Access Server*/
63 #define BTA_HFP_HS_SERVICE_ID 24 /* HSP HS role */
64 #define BTA_MAP_SERVICE_ID 25 /* Message Access Profile */
65 #define BTA_MN_SERVICE_ID 26 /* Message Notification Service */
66 #define BTA_PCE_SERVICE_ID 28 /* PhoneBook Access Client */
67 #define BTA_SDP_SERVICE_ID 29 /* SDP Search */
68 #define BTA_HIDD_SERVICE_ID 30 /* HID Device */
69
70 /* BLE profile service ID */
71 #define BTA_BLE_SERVICE_ID 31 /* GATT profile */
72 #define BTA_USER_SERVICE_ID 32 /* User requested UUID */
73 #define BTA_MAX_SERVICE_ID 33
74
75 /* service IDs (BTM_SEC_SERVICE_FIRST_EMPTY + 1) to (BTM_SEC_MAX_SERVICES - 1)
76 * are used by BTA JV */
77 #define BTA_FIRST_JV_SERVICE_ID (BTM_SEC_SERVICE_FIRST_EMPTY + 1)
78 #define BTA_LAST_JV_SERVICE_ID (BTM_SEC_MAX_SERVICES - 1)
79
80 typedef uint8_t tBTA_SERVICE_ID;
81
82 /* Service ID Mask */
83 #define BTA_RES_SERVICE_MASK 0x00000001 /* Reserved */
84 #define BTA_HSP_SERVICE_MASK 0x00000020 /* HSP AG role. */
85 #define BTA_HFP_SERVICE_MASK 0x00000040 /* HFP AG role */
86 #define BTA_HL_SERVICE_MASK 0x08000000 /* Health Device Profile */
87
88 #define BTA_BLE_SERVICE_MASK 0x40000000 /* GATT based service */
89 #define BTA_ALL_SERVICE_MASK 0x7FFFFFFF /* All services supported by BTA. */
90 #define BTA_USER_SERVICE_MASK 0x80000000 /* Message Notification Profile */
91
92 typedef uint32_t tBTA_SERVICE_MASK;
93
94 #define BTA_APP_ID_PAN_MULTI 0xFE /* app id for pan multiple connection */
95 #define BTA_ALL_APP_ID 0xFF
96
97 /* Discoverable Modes */
98 typedef uint16_t tBTA_DM_DISC; /* this discoverability mode is a bit mask among BR mode and
99 LE mode */
100
101 /* Connectable Modes */
102 typedef uint16_t tBTA_DM_CONN;
103
104 /* Central/peripheral preferred roles */
105 typedef enum : uint8_t {
106 BTA_ANY_ROLE = 0x00,
107 BTA_CENTRAL_ROLE_PREF = 0x01,
108 BTA_CENTRAL_ROLE_ONLY = 0x02,
109 /* Used for PANU only, skip role switch to central */
110 BTA_PERIPHERAL_ROLE_ONLY = 0x03,
111 } tBTA_PREF_ROLES;
112
toBTA_PREF_ROLES(uint8_t role)113 inline tBTA_PREF_ROLES toBTA_PREF_ROLES(uint8_t role) {
114 bluetooth::log::assert_that(role <= BTA_PERIPHERAL_ROLE_ONLY,
115 "Passing illegal preferred role:0x{:02x} [0x{:02x}<=>0x{:02x}]", role,
116 int(BTA_ANY_ROLE), int(BTA_PERIPHERAL_ROLE_ONLY));
117 return static_cast<tBTA_PREF_ROLES>(role);
118 }
119
preferred_role_text(const tBTA_PREF_ROLES & role)120 inline std::string preferred_role_text(const tBTA_PREF_ROLES& role) {
121 switch (role) {
122 CASE_RETURN_TEXT(BTA_ANY_ROLE);
123 CASE_RETURN_TEXT(BTA_CENTRAL_ROLE_PREF);
124 CASE_RETURN_TEXT(BTA_CENTRAL_ROLE_ONLY);
125 CASE_RETURN_TEXT(BTA_PERIPHERAL_ROLE_ONLY);
126 default:
127 return base::StringPrintf("UNKNOWN[%hhu]", role);
128 }
129 }
130
131 enum {
132 BTA_DM_NO_SCATTERNET, /* Device doesn't support scatternet, it might
133 support "role switch during connection" for
134 an incoming connection, when it already has
135 another connection in central role */
136 BTA_DM_PARTIAL_SCATTERNET, /* Device supports partial scatternet. It can have
137 simultaneous connection in Central and
138 Peripheral roles for small period of time */
139 BTA_DM_FULL_SCATTERNET /* Device can have simultaneous connection in central
140 and peripheral roles */
141 };
142
143 typedef struct {
144 uint8_t bta_dm_eir_min_name_len; /* minimum length of local name when it is
145 shortened */
146 uint32_t uuid_mask[BTM_EIR_SERVICE_ARRAY_SIZE]; /* mask of UUID list in EIR */
147 int8_t* bta_dm_eir_inq_tx_power; /* Inquiry TX power */
148 uint8_t bta_dm_eir_flag_len; /* length of flags in bytes */
149 uint8_t* bta_dm_eir_flags; /* flags for EIR */
150 uint8_t bta_dm_eir_manufac_spec_len; /* length of manufacturer specific in
151 bytes */
152 uint8_t* bta_dm_eir_manufac_spec; /* manufacturer specific */
153 uint8_t bta_dm_eir_additional_len; /* length of additional data in bytes */
154 uint8_t* bta_dm_eir_additional; /* additional data */
155 } tBTA_DM_EIR_CONF;
156
157 typedef uint8_t tBTA_DM_BLE_RSSI_ALERT_TYPE;
158
159 typedef enum : uint8_t {
160 BTA_DM_LINK_UP_EVT = 5, /* Connection UP event */
161 BTA_DM_LINK_DOWN_EVT = 6, /* Connection DOWN event */
162 BTA_DM_LE_FEATURES_READ = 27, /* Controller specific LE features are read */
163 BTA_DM_LPP_OFFLOAD_FEATURES_READ = 28, /* Low power processor offload features are read */
164 BTA_DM_LINK_UP_FAILED_EVT = 34, /* Create connection failed event */
165 } tBTA_DM_ACL_EVT;
166
167 /* Structure associated with BTA_DM_LINK_UP_EVT */
168 typedef struct {
169 RawAddress bd_addr; /* BD address peer device. */
170 tBT_TRANSPORT transport_link_type;
171 uint16_t acl_handle;
172 } tBTA_DM_LINK_UP;
173
174 /* Structure associated with BTA_DM_LINK_UP_FAILED_EVT */
175 typedef struct {
176 RawAddress bd_addr; /* BD address peer device. */
177 tBT_TRANSPORT transport_link_type;
178 tHCI_STATUS status; /* The HCI error code associated with this event */
179 } tBTA_DM_LINK_UP_FAILED;
180
181 /* Structure associated with BTA_DM_LINK_DOWN_EVT */
182 typedef struct {
183 RawAddress bd_addr; /* BD address peer device. */
184 tBT_TRANSPORT transport_link_type;
185 tHCI_STATUS status;
186 } tBTA_DM_LINK_DOWN;
187
188 typedef union {
189 tBTA_DM_LINK_UP link_up; /* ACL connection up event */
190 tBTA_DM_LINK_UP_FAILED link_up_failed; /* ACL connection up failure event */
191 tBTA_DM_LINK_DOWN link_down; /* ACL connection down event */
192 } tBTA_DM_ACL;
193
194 typedef void(tBTA_DM_ACL_CBACK)(tBTA_DM_ACL_EVT event, tBTA_DM_ACL* p_data);
195
196 #define BTA_DM_BLE_PF_LIST_LOGIC_OR 1
197 #define BTA_DM_BLE_PF_FILT_LOGIC_OR 0
198
199 /* Search callback events */
200 typedef enum : uint8_t {
201 BTA_DM_INQ_RES_EVT = 0, /* Inquiry result for a peer device. */
202 BTA_DM_INQ_CMPL_EVT = 1, /* Inquiry complete. */
203 BTA_DM_DISC_RES_EVT = 2, /* Service Discovery result for a peer device. */
204 BTA_DM_DISC_CMPL_EVT = 3, /* Discovery complete. */
205 BTA_DM_SEARCH_CANCEL_CMPL_EVT = 4, /* Search cancelled */
206 BTA_DM_NAME_READ_EVT = 5, /* Name read complete. */
207 BTA_DM_OBSERVE_CMPL_EVT = 6, /* Observe complete. */
208 } tBTA_DM_SEARCH_EVT;
209
bta_dm_search_evt_text(const tBTA_DM_SEARCH_EVT & event)210 inline std::string bta_dm_search_evt_text(const tBTA_DM_SEARCH_EVT& event) {
211 switch (event) {
212 CASE_RETURN_TEXT(BTA_DM_INQ_RES_EVT);
213 CASE_RETURN_TEXT(BTA_DM_INQ_CMPL_EVT);
214 CASE_RETURN_TEXT(BTA_DM_DISC_RES_EVT);
215 CASE_RETURN_TEXT(BTA_DM_DISC_CMPL_EVT);
216 CASE_RETURN_TEXT(BTA_DM_SEARCH_CANCEL_CMPL_EVT);
217 CASE_RETURN_TEXT(BTA_DM_NAME_READ_EVT);
218 CASE_RETURN_TEXT(BTA_DM_OBSERVE_CMPL_EVT);
219 default:
220 return base::StringPrintf("UNKNOWN[%hhu]", event);
221 }
222 }
223
224 /* Structure associated with BTA_DM_INQ_RES_EVT */
225 typedef struct {
226 RawAddress bd_addr; /* BD address peer device. */
227 DEV_CLASS dev_class; /* Device class of peer device. */
228 bool remt_name_not_required; /* Application sets this flag if it already knows
229 the name of the device */
230 /* If the device name is known to application BTA skips the remote name
231 * request */
232 bool is_limited; /* true, if the limited inquiry bit is set in the CoD */
233 int8_t rssi; /* The rssi value */
234 const uint8_t* p_eir; /* received EIR */
235 uint16_t eir_len; /* received EIR length */
236 uint8_t inq_result_type;
237 tBLE_ADDR_TYPE ble_addr_type;
238 uint16_t ble_evt_type;
239 uint8_t ble_primary_phy;
240 uint8_t ble_secondary_phy;
241 uint8_t ble_advertising_sid;
242 int8_t ble_tx_power;
243 uint16_t ble_periodic_adv_int;
244 tBT_DEVICE_TYPE device_type;
245 uint8_t flag;
246 bool include_rsi; /* true, if ADV contains RSI data */
247 RawAddress original_bda; /* original address to pass up to
248 GattService#onScanResult */
249 uint16_t clock_offset;
250 } tBTA_DM_INQ_RES;
251
252 /* Structure associated with BTA_DM_OBSERVE_CMPL_EVT */
253 typedef struct {
254 uint8_t num_resps; /* Number of responses. */
255 } tBTA_DM_OBSERVE_CMPL;
256
257 /* Structure associated with BTA_DM_NAME_READ_EVT */
258 typedef struct {
259 RawAddress bd_addr; /* BD address peer device. */
260 BD_NAME bd_name; /* Name of peer device. */
261 } tBTA_DM_NAME_READ_CMPL;
262
263 /* Union of all search callback structures */
264 typedef union {
265 tBTA_DM_INQ_RES inq_res; /* Inquiry result for a peer device. */
266 tBTA_DM_NAME_READ_CMPL name_res; /* Name read result for a peer device. */
267 tBTA_DM_OBSERVE_CMPL observe_cmpl; /* Observe complete. */
268 } tBTA_DM_SEARCH;
269
270 /* Search callback */
271 typedef void(tBTA_DM_SEARCH_CBACK)(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data);
272
273 typedef void(tBTA_DM_GATT_DISC_CBACK)(RawAddress bd_addr, std::vector<bluetooth::Uuid>& services,
274 bool transport_le);
275 typedef void(tBTA_DM_DID_RES_CBACK)(RawAddress bd_addr, uint8_t vendor_id_src, uint16_t vendor_id,
276 uint16_t product_id, uint16_t version);
277 typedef void(tBTA_DM_DISC_CBACK)(RawAddress bd_addr, const std::vector<bluetooth::Uuid>& uuids,
278 tBTA_STATUS result);
279 struct service_discovery_callbacks {
280 tBTA_DM_GATT_DISC_CBACK* on_gatt_results;
281 tBTA_DM_DID_RES_CBACK* on_did_received;
282 tBTA_DM_DISC_CBACK* on_service_discovery_results;
283 };
284
285 /* Execute call back */
286 typedef void(tBTA_DM_EXEC_CBACK)(void* p_param);
287
288 typedef void(tBTA_BLE_ENERGY_INFO_CBACK)(tBTM_BLE_TX_TIME_MS tx_time, tBTM_BLE_RX_TIME_MS rx_time,
289 tBTM_BLE_IDLE_TIME_MS idle_time,
290 tBTM_BLE_ENERGY_USED energy_used,
291 tBTM_CONTRL_STATE ctrl_state, tBTA_STATUS status);
292
293 /* Maximum service name length */
294 #define BTA_SERVICE_NAME_LEN 35
295
296 typedef enum : uint8_t {
297 /* power mode actions */
298 BTA_DM_PM_NO_ACTION = 0x00, /* no change to the current pm setting */
299 BTA_DM_PM_PARK = 0x10, /* prefers park mode */
300 BTA_DM_PM_SNIFF = 0x20, /* prefers sniff mode */
301 BTA_DM_PM_SNIFF1 = 0x21, /* prefers sniff1 mode */
302 BTA_DM_PM_SNIFF2 = 0x22, /* prefers sniff2 mode */
303 BTA_DM_PM_SNIFF3 = 0x23, /* prefers sniff3 mode */
304 BTA_DM_PM_SNIFF4 = 0x24, /* prefers sniff4 mode */
305 BTA_DM_PM_SNIFF5 = 0x25, /* prefers sniff5 mode */
306 BTA_DM_PM_SNIFF6 = 0x26, /* prefers sniff6 mode */
307 BTA_DM_PM_SNIFF7 = 0x27, /* prefers sniff7 mode */
308 BTA_DM_PM_SNIFF_USER0 = 0x28, /* prefers user-defined sniff0 mode (testtool only) */
309 BTA_DM_PM_SNIFF_USER1 = 0x29, /* prefers user-defined sniff1 mode (testtool only) */
310 BTA_DM_PM_ACTIVE = 0x40, /* prefers active mode */
311 BTA_DM_PM_RETRY = 0x80, /* retry power mode based on current settings */
312 BTA_DM_PM_SUSPEND = 0x04, /* prefers suspend mode */
313 BTA_DM_PM_NO_PREF = 0x01, /* service has no preference on power mode setting.
314 eg. connection to \ service got closed */
315 BTA_DM_PM_SNIFF_MASK = 0x0f, // Masks the sniff submode
316 } tBTA_DM_PM_ACTION_BITMASK;
317 typedef uint8_t tBTA_DM_PM_ACTION;
318
319 /* index to bta_dm_ssr_spec */
320 enum {
321 BTA_DM_PM_SSR0 = 0,
322 /* BTA_DM_PM_SSR1 will be dedicated for \
323 HH SSR setting entry, no other profile can use it */
324 BTA_DM_PM_SSR1 = 1,
325 BTA_DM_PM_SSR2 = 2,
326 BTA_DM_PM_SSR3 = 3,
327 BTA_DM_PM_SSR4 = 4,
328 };
329
330 #define BTA_DM_PM_NUM_EVTS 9
331
332 #ifndef BTA_DM_PM_PARK_IDX
333 #define BTA_DM_PM_PARK_IDX 7 /* the actual index to bta_dm_pm_md[] for PARK mode */
334 #endif
335
336 #ifndef BTA_DM_PM_SNIFF_A2DP_IDX
337 #define BTA_DM_PM_SNIFF_A2DP_IDX BTA_DM_PM_SNIFF
338 #endif
339
340 #ifndef BTA_DM_PM_SNIFF_HD_IDLE_IDX
341 #define BTA_DM_PM_SNIFF_HD_IDLE_IDX BTA_DM_PM_SNIFF2
342 #endif
343
344 #ifndef BTA_DM_PM_SNIFF_SCO_OPEN_IDX
345 #define BTA_DM_PM_SNIFF_SCO_OPEN_IDX BTA_DM_PM_SNIFF3
346 #endif
347
348 #ifndef BTA_DM_PM_SNIFF_HD_ACTIVE_IDX
349 #define BTA_DM_PM_SNIFF_HD_ACTIVE_IDX BTA_DM_PM_SNIFF4
350 #endif
351
352 #ifndef BTA_DM_PM_SNIFF_HH_OPEN_IDX
353 #define BTA_DM_PM_SNIFF_HH_OPEN_IDX BTA_DM_PM_SNIFF2
354 #endif
355
356 #ifndef BTA_DM_PM_SNIFF_HH_ACTIVE_IDX
357 #define BTA_DM_PM_SNIFF_HH_ACTIVE_IDX BTA_DM_PM_SNIFF2
358 #endif
359
360 #ifndef BTA_DM_PM_SNIFF_HH_IDLE_IDX
361 #define BTA_DM_PM_SNIFF_HH_IDLE_IDX BTA_DM_PM_SNIFF2
362 #endif
363
364 #ifndef BTA_DM_PM_HH_OPEN_DELAY
365 #define BTA_DM_PM_HH_OPEN_DELAY 30000
366 #endif
367
368 #ifndef BTA_DM_PM_HH_ACTIVE_DELAY
369 #define BTA_DM_PM_HH_ACTIVE_DELAY 30000
370 #endif
371
372 #ifndef BTA_DM_PM_HH_IDLE_DELAY
373 #define BTA_DM_PM_HH_IDLE_DELAY 30000
374 #endif
375
376 /* The Sniff Parameters defined below must be ordered from highest
377 * latency (biggest interval) to lowest latency. If there is a conflict
378 * among the connected services the setting with the lowest latency will
379 * be selected. If a device should override a sniff parameter then it
380 * must insure that order is maintained.
381 */
382 #ifndef BTA_DM_PM_SNIFF_MAX
383 #define BTA_DM_PM_SNIFF_MAX 800
384 #define BTA_DM_PM_SNIFF_MIN 400
385 #define BTA_DM_PM_SNIFF_ATTEMPT 4
386 #define BTA_DM_PM_SNIFF_TIMEOUT 1
387 #endif
388
389 #ifndef BTA_DM_PM_SNIFF1_MAX
390 #define BTA_DM_PM_SNIFF1_MAX 400
391 #define BTA_DM_PM_SNIFF1_MIN 200
392 #define BTA_DM_PM_SNIFF1_ATTEMPT 4
393 #define BTA_DM_PM_SNIFF1_TIMEOUT 1
394 #endif
395
396 #ifndef BTA_DM_PM_SNIFF2_MAX
397 #define BTA_DM_PM_SNIFF2_MAX 54
398 #define BTA_DM_PM_SNIFF2_MIN 30
399 #define BTA_DM_PM_SNIFF2_ATTEMPT 4
400 #define BTA_DM_PM_SNIFF2_TIMEOUT 1
401 #endif
402
403 #ifndef BTA_DM_PM_SNIFF3_MAX
404 #define BTA_DM_PM_SNIFF3_MAX 150
405 #define BTA_DM_PM_SNIFF3_MIN 50
406 #define BTA_DM_PM_SNIFF3_ATTEMPT 4
407 #define BTA_DM_PM_SNIFF3_TIMEOUT 1
408 #endif
409
410 #ifndef BTA_DM_PM_SNIFF4_MAX
411 #define BTA_DM_PM_SNIFF4_MAX 18
412 #define BTA_DM_PM_SNIFF4_MIN 10
413 #define BTA_DM_PM_SNIFF4_ATTEMPT 4
414 #define BTA_DM_PM_SNIFF4_TIMEOUT 1
415 #endif
416
417 #ifndef BTA_DM_PM_SNIFF5_MAX
418 #define BTA_DM_PM_SNIFF5_MAX 36
419 #define BTA_DM_PM_SNIFF5_MIN 30
420 #define BTA_DM_PM_SNIFF5_ATTEMPT 2
421 #define BTA_DM_PM_SNIFF5_TIMEOUT 0
422 #endif
423
424 #ifndef BTA_DM_PM_SNIFF6_MAX
425 #define BTA_DM_PM_SNIFF6_MAX 18
426 #define BTA_DM_PM_SNIFF6_MIN 14
427 #define BTA_DM_PM_SNIFF6_ATTEMPT 1
428 #define BTA_DM_PM_SNIFF6_TIMEOUT 0
429 #endif
430
431 #ifndef BTA_DM_PM_PARK_MAX
432 #define BTA_DM_PM_PARK_MAX 800
433 #define BTA_DM_PM_PARK_MIN 400
434 #define BTA_DM_PM_PARK_ATTEMPT 0
435 #define BTA_DM_PM_PARK_TIMEOUT 0
436 #endif
437
438 /* Device Identification (DI) data structure
439 */
440
441 #ifndef BTA_DI_NUM_MAX
442 #define BTA_DI_NUM_MAX 3
443 #endif
444
445 #define IMMEDIATE_DELY_MODE 0x00
446 #define ALLOW_ALL_FILTER 0x00
447 #define LOWEST_RSSI_VALUE 129
448
449 /*****************************************************************************
450 * External Function Declarations
451 ****************************************************************************/
452
453 void BTA_dm_init();
454
455 /*******************************************************************************
456 *
457 * Function BTA_EnableTestMode
458 *
459 * Description Enables bluetooth device under test mode
460 *
461 *
462 * Returns tBTA_STATUS
463 *
464 ******************************************************************************/
465 extern void BTA_EnableTestMode(void);
466
467 /*******************************************************************************
468 *
469 * Function BTA_DmSetDeviceName
470 *
471 * Description This function sets the Bluetooth name of the local device.
472 *
473 *
474 * Returns void
475 *
476 ******************************************************************************/
477 void BTA_DmSetDeviceName(const char* p_name);
478
479 /*******************************************************************************
480 *
481 * Function BTA_DmSetVisibility
482 *
483 * Description This function sets the Bluetooth connectable,discoverable,
484 * pairable and conn paired only modesmodes of the local
485 * device.
486 * This controls whether other Bluetooth devices can find and
487 * connect to the local device.
488 *
489 *
490 * Returns void
491 *
492 ******************************************************************************/
493 bool BTA_DmSetVisibility(bt_scan_mode_t mode);
494
495 /*******************************************************************************
496 *
497 * Function BTA_DmSearch
498 *
499 * Description This function searches for peer Bluetooth devices. It
500 * first performs an inquiry; for each device found from the
501 * inquiry it gets the remote name of the device. If
502 * parameter services is nonzero, service discovery will be
503 * performed on each device for the services specified.
504 *
505 *
506 * Returns void
507 *
508 ******************************************************************************/
509 void BTA_DmSearch(tBTA_DM_SEARCH_CBACK* p_cback);
510
511 /*******************************************************************************
512 *
513 * Function BTA_DmSearchCancel
514 *
515 * Description This function cancels a search that has been initiated
516 * by calling BTA_DmSearch().
517 *
518 *
519 * Returns void
520 *
521 ******************************************************************************/
522 void BTA_DmSearchCancel(void);
523
524 /*******************************************************************************
525 *
526 * Function BTA_DmDiscover
527 *
528 * Description This function performs service discovery for the services
529 * of a particular peer device.
530 *
531 *
532 * Returns void
533 *
534 ******************************************************************************/
535 void BTA_DmDiscover(const RawAddress& bd_addr, service_discovery_callbacks cback,
536 tBT_TRANSPORT transport);
537
538 /*******************************************************************************
539 *
540 * Function BTA_DmGetCachedRemoteName
541 *
542 * Description Retieve cached remote name if available
543 *
544 * Returns BTA_SUCCESS if cached name was retrieved
545 * BTA_FAILURE if cached name is not available
546 *
547 ******************************************************************************/
548 tBTA_STATUS BTA_DmGetCachedRemoteName(const RawAddress& remote_device, uint8_t** pp_cached_name);
549
550 /*******************************************************************************
551 *
552 * Function BTA_DmGetConnectionState
553 *
554 * Description Returns whether the remote device is currently connected.
555 *
556 * Returns true if the device is NOT connected, false otherwise.
557 *
558 ******************************************************************************/
559 bool BTA_DmGetConnectionState(const RawAddress& bd_addr);
560
561 /*******************************************************************************
562 *
563 * Function BTA_DmSetLocalDiRecord
564 *
565 * Description This function adds a DI record to the local SDP database.
566 *
567 * Returns BTA_SUCCESS if record set sucessfully, otherwise error code.
568 *
569 ******************************************************************************/
570 tBTA_STATUS BTA_DmSetLocalDiRecord(tSDP_DI_RECORD* p_device_info, uint32_t* p_handle);
571
572 /*******************************************************************************
573 *
574 * Function BTA_DmSetBlePrefConnParams
575 *
576 * Description This function is called to set the preferred connection
577 * parameters when default connection parameter is not desired.
578 *
579 * Parameters: bd_addr - BD address of the peripheral
580 * min_conn_int - minimum preferred connection interval
581 * max_conn_int - maximum preferred connection interval
582 * peripheral_latency - preferred peripheral latency
583 * supervision_tout - preferred supervision timeout
584 *
585 *
586 * Returns void
587 *
588 ******************************************************************************/
589 void BTA_DmSetBlePrefConnParams(const RawAddress& bd_addr, uint16_t min_conn_int,
590 uint16_t max_conn_int, uint16_t peripheral_latency,
591 uint16_t supervision_tout);
592
593 /*******************************************************************************
594 *
595 * Function BTA_DmBleScan
596 *
597 * Description Start or stop the scan procedure.
598 *
599 * Parameters start: start or stop the scan procedure,
600 * duration_sec: Duration of the scan. Continuous scan if 0 is
601 * passed,
602 *
603 * Returns void
604 *
605 ******************************************************************************/
606 void BTA_DmBleScan(bool start, uint8_t duration);
607
608 /*******************************************************************************
609 *
610 * Function BTA_DmBleCsisObserve
611 *
612 * Description This procedure keeps the external observer listening for
613 * advertising events from a CSIS grouped device.
614 *
615 * Parameters observe: enable or disable passive observe,
616 * p_results_cb: Callback to be called with scan results,
617 *
618 * Returns void
619 *
620 ******************************************************************************/
621 void BTA_DmBleCsisObserve(bool observe, tBTA_DM_SEARCH_CBACK* p_results_cb);
622
623 /*******************************************************************************
624 *
625 * Function BTA_DmBleConfigLocalPrivacy
626 *
627 * Description Enable/disable privacy on the local device
628 *
629 * Parameters: privacy_enable - enable/disabe privacy on remote device.
630 *
631 * Returns void
632 *
633 ******************************************************************************/
634 void BTA_DmBleConfigLocalPrivacy(bool privacy_enable);
635
636 /*******************************************************************************
637 *
638 * Function BTA_DmBleEnableRemotePrivacy
639 *
640 * Description Enable/disable privacy on a remote device
641 *
642 * Parameters: bd_addr - BD address of the peer
643 * privacy_enable - enable/disabe privacy on remote device.
644 *
645 * Returns void
646 *
647 ******************************************************************************/
648 void BTA_DmBleEnableRemotePrivacy(const RawAddress& bd_addr, bool privacy_enable);
649
650 /*******************************************************************************
651 *
652 * Function BTA_DmBleUpdateConnectionParams
653 *
654 * Description Update connection parameters, can only be used when
655 * connection is up.
656 *
657 * Parameters: bd_addr - BD address of the peer
658 * min_int - minimum connection interval, [0x0004 ~ 0x4000]
659 * max_int - maximum connection interval, [0x0004 ~ 0x4000]
660 * latency - peripheral latency [0 ~ 500]
661 * timeout - supervision timeout [0x000a ~ 0xc80]
662 *
663 * Returns void
664 *
665 ******************************************************************************/
666 void BTA_DmBleUpdateConnectionParams(const RawAddress& bd_addr, uint16_t min_int, uint16_t max_int,
667 uint16_t latency, uint16_t timeout, uint16_t min_ce_len,
668 uint16_t max_ce_len);
669
670 /*******************************************************************************
671 *
672 * Function BTA_DmBleSetDataLength
673 *
674 * Description This function is to set maximum LE data packet size
675 *
676 * Returns void
677 *
678 ******************************************************************************/
679 void BTA_DmBleRequestMaxTxDataLength(const RawAddress& remote_device);
680
681 /*******************************************************************************
682 *
683 * Function BTA_DmBleGetEnergyInfo
684 *
685 * Description This function is called to obtain the energy info
686 *
687 * Parameters p_cmpl_cback - Command complete callback
688 *
689 * Returns void
690 *
691 ******************************************************************************/
692 void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK* p_cmpl_cback);
693
694 /*******************************************************************************
695 *
696 * Function BTA_DmClearEventFilter
697 *
698 * Description This function clears the event filter
699 *
700 * Returns void
701 *
702 ******************************************************************************/
703 void BTA_DmClearEventFilter(void);
704
705 /*******************************************************************************
706 *
707 * Function BTA_DmClearEventMask
708 *
709 * Description This function clears the event mask
710 *
711 * Returns void
712 *
713 ******************************************************************************/
714 void BTA_DmClearEventMask(void);
715
716 /*******************************************************************************
717 *
718 * Function BTA_DmDisconnectAllAcls
719 *
720 * Description This function will disconnect all LE and Classic ACLs.
721 *
722 * Returns void
723 *
724 ******************************************************************************/
725 void BTA_DmDisconnectAllAcls(void);
726
727 /*******************************************************************************
728 *
729 * Function BTA_DmClearFilterAcceptList
730 *
731 * Description This function clears the filter accept list
732 *
733 * Returns void
734 *
735 ******************************************************************************/
736 void BTA_DmClearFilterAcceptList(void);
737
738 /*******************************************************************************
739 *
740 * Function BTA_DmLeRand
741 *
742 * Description This function clears the event filter
743 *
744 * Returns cb: callback to receive the resulting random number
745 *
746 ******************************************************************************/
747 void BTA_DmLeRand(bluetooth::hci::LeRandCallback cb);
748
749 /*******************************************************************************
750 *
751 * Function BTA_DmSetEventFilterConnectionSetupAllDevices
752 *
753 * Description Tell the controller to allow all devices
754 *
755 * Parameters
756 *
757 *******************************************************************************/
758 void BTA_DmSetEventFilterConnectionSetupAllDevices();
759
760 /*******************************************************************************
761 *
762 * Function BTA_DmAllowWakeByHid
763 *
764 * Description Allow the device to be woken by HID devices
765 *
766 * Parameters
767 *
768 *******************************************************************************/
769 void BTA_DmAllowWakeByHid(std::vector<RawAddress> classic_hid_devices,
770 std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices);
771
772 /*******************************************************************************
773 *
774 * Function BTA_DmRestoreFilterAcceptList
775 *
776 * Description Floss: Restore the state of the for the filter accept list
777 *
778 * Parameters
779 *
780 *******************************************************************************/
781 void BTA_DmRestoreFilterAcceptList(std::vector<std::pair<RawAddress, uint8_t>> le_devices);
782
783 /*******************************************************************************
784 *
785 * Function BTA_DmSetDefaultEventMaskExcept
786 *
787 * Description Floss: Set the default event mask for Classic and LE except
788 * the given values (they will be disabled in the final set
789 * mask).
790 *
791 * Parameters Bits set for event mask and le event mask that should be
792 * disabled in the final value.
793 *
794 *******************************************************************************/
795 void BTA_DmSetDefaultEventMaskExcept(uint64_t mask, uint64_t le_mask);
796
797 /*******************************************************************************
798 *
799 * Function BTA_DmSetEventFilterInquiryResultAllDevices
800 *
801 * Description Floss: Set the event filter to inquiry result device all
802 *
803 * Parameters
804 *
805 *******************************************************************************/
806 void BTA_DmSetEventFilterInquiryResultAllDevices();
807
808 /*******************************************************************************
809 *
810 * Function BTA_DmBleResetId
811 *
812 * Description This function resets the ble keys such as IRK
813 *
814 * Returns void
815 *
816 ******************************************************************************/
817 void BTA_DmBleResetId(void);
818
819 /*******************************************************************************
820 *
821 * Function BTA_DmBleSubrateRequest
822 *
823 * Description subrate request, can only be used when connection is up.
824 *
825 * Parameters: bd_addr - BD address of the peer
826 * subrate_min - subrate min
827 * subrate_max - subrate max
828 * max_latency - max latency
829 * cont_num - continuation number
830 * timeout - supervision timeout
831 *
832 * Returns void
833 *
834 ******************************************************************************/
835 void BTA_DmBleSubrateRequest(const RawAddress& bd_addr, uint16_t subrate_min, uint16_t subrate_max,
836 uint16_t max_latency, uint16_t cont_num, uint16_t timeout);
837
838 /*******************************************************************************
839 *
840 * Function BTA_DmCheckLeAudioCapable
841 *
842 * Description Checks if device should be considered as LE Audio capable
843 *
844 * Returns True if Le Audio capable device, false otherwise
845 *
846 ******************************************************************************/
847 bool BTA_DmCheckLeAudioCapable(const RawAddress& address);
848
849 void DumpsysBtaDm(int fd);
850
851 namespace std {
852 template <>
853 struct formatter<tBTA_DM_SEARCH_EVT> : enum_formatter<tBTA_DM_SEARCH_EVT> {};
854 template <>
855 struct formatter<tBTA_DM_ACL_EVT> : enum_formatter<tBTA_DM_ACL_EVT> {};
856 template <>
857 struct formatter<tBTA_PREF_ROLES> : enum_formatter<tBTA_PREF_ROLES> {};
858 } // namespace std
859
860 #endif /* BTA_API_H */
861