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