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