• 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/strings/stringprintf.h>
29 #include <base/functional/callback.h>
30 
31 #include <cstdint>
32 #include <vector>
33 
34 #include "bt_target.h"  // Must be first to define build configuration
35 #include "osi/include/log.h"
36 #include "stack/include/bt_octets.h"
37 #include "stack/include/bt_types.h"
38 #include "stack/include/btm_api_types.h"
39 #include "stack/include/btm_ble_api_types.h"
40 #include "stack/include/hci_error_code.h"
41 #include "stack/include/sdp_api.h"
42 #include "types/ble_address_with_type.h"
43 #include "types/bluetooth/uuid.h"
44 #include "types/bt_transport.h"
45 #include "types/raw_address.h"
46 
47 /*****************************************************************************
48  *  Constants and data types
49  ****************************************************************************/
50 
51 /* Status Return Value */
52 typedef enum : uint8_t {
53   BTA_SUCCESS = 0, /* Successful operation. */
54   BTA_FAILURE = 1, /* Generic failure. */
55   BTA_PENDING = 2, /* API cannot be completed right now */
56   BTA_BUSY = 3,
57   BTA_NO_RESOURCES = 4,
58   BTA_WRONG_MODE = 5,
59 } tBTA_STATUS;
60 
61 #ifndef CASE_RETURN_TEXT
62 #define CASE_RETURN_TEXT(code) \
63   case code:                   \
64     return #code
65 #endif
66 
bta_status_text(const tBTA_STATUS & status)67 inline std::string bta_status_text(const tBTA_STATUS& status) {
68   switch (status) {
69     CASE_RETURN_TEXT(BTA_SUCCESS);
70     CASE_RETURN_TEXT(BTA_FAILURE);
71     CASE_RETURN_TEXT(BTA_PENDING);
72     CASE_RETURN_TEXT(BTA_BUSY);
73     CASE_RETURN_TEXT(BTA_NO_RESOURCES);
74     CASE_RETURN_TEXT(BTA_WRONG_MODE);
75     default:
76       return base::StringPrintf("UNKNOWN[%d]", status);
77   }
78 }
79 
80 #undef CASE_RETURN_TEXT
81 
82 /*
83  * Service ID
84  */
85 
86 #define BTA_A2DP_SOURCE_SERVICE_ID 3 /* A2DP Source profile. */
87 #define BTA_HSP_SERVICE_ID 5         /* Headset profile. */
88 #define BTA_HFP_SERVICE_ID 6         /* Hands-free profile. */
89 #define BTA_BIP_SERVICE_ID 13        /* Basic Imaging profile */
90 #define BTA_A2DP_SINK_SERVICE_ID 18  /* A2DP Sink */
91 #define BTA_HID_SERVICE_ID 20        /* HID */
92 #define BTA_PBAP_SERVICE_ID 22       /* PhoneBook Access Server*/
93 #define BTA_HFP_HS_SERVICE_ID 24     /* HSP HS role */
94 #define BTA_MAP_SERVICE_ID 25        /* Message Access Profile */
95 #define BTA_MN_SERVICE_ID 26         /* Message Notification Service */
96 #define BTA_PCE_SERVICE_ID 28        /* PhoneBook Access Client */
97 #define BTA_SDP_SERVICE_ID 29        /* SDP Search */
98 #define BTA_HIDD_SERVICE_ID 30       /* HID Device */
99 
100 /* BLE profile service ID */
101 #define BTA_BLE_SERVICE_ID 31  /* GATT profile */
102 #define BTA_USER_SERVICE_ID 32 /* User requested UUID */
103 #define BTA_MAX_SERVICE_ID 33
104 
105 /* service IDs (BTM_SEC_SERVICE_FIRST_EMPTY + 1) to (BTM_SEC_MAX_SERVICES - 1)
106  * are used by BTA JV */
107 #define BTA_FIRST_JV_SERVICE_ID (BTM_SEC_SERVICE_FIRST_EMPTY + 1)
108 #define BTA_LAST_JV_SERVICE_ID (BTM_SEC_MAX_SERVICES - 1)
109 
110 typedef uint8_t tBTA_SERVICE_ID;
111 
112 /* Service ID Mask */
113 #define BTA_RES_SERVICE_MASK 0x00000001    /* Reserved */
114 #define BTA_HSP_SERVICE_MASK 0x00000020    /* HSP AG role. */
115 #define BTA_HFP_SERVICE_MASK 0x00000040    /* HFP AG role */
116 #define BTA_HL_SERVICE_MASK 0x08000000     /* Health Device Profile */
117 
118 #define BTA_BLE_SERVICE_MASK 0x40000000  /* GATT based service */
119 #define BTA_ALL_SERVICE_MASK 0x7FFFFFFF  /* All services supported by BTA. */
120 #define BTA_USER_SERVICE_MASK 0x80000000 /* Message Notification Profile */
121 
122 typedef uint32_t tBTA_SERVICE_MASK;
123 
124 /* Security Setting Mask */
125 #define BTA_SEC_AUTHENTICATE \
126   (BTM_SEC_IN_AUTHENTICATE | \
127    BTM_SEC_OUT_AUTHENTICATE) /* Authentication required. */
128 #define BTA_SEC_ENCRYPT \
129   (BTM_SEC_IN_ENCRYPT | BTM_SEC_OUT_ENCRYPT) /* Encryption required. */
130 
131 typedef uint16_t tBTA_SEC;
132 
133 #define BTA_APP_ID_PAN_MULTI 0xFE /* app id for pan multiple connection */
134 #define BTA_ALL_APP_ID 0xFF
135 
136 /* Discoverable Modes */
137 #define BTA_DM_NON_DISC BTM_NON_DISCOVERABLE /* Device is not discoverable. */
138 #define BTA_DM_GENERAL_DISC                         \
139   BTM_GENERAL_DISCOVERABLE /* General discoverable. \
140                               */
141 #define BTA_DM_LIMITED_DISC BTM_LIMITED_DISCOVERABLE
142 
143 typedef uint16_t
144     tBTA_DM_DISC; /* this discoverability mode is a bit mask among BR mode and
145                      LE mode */
146 
147 /* Connectable Modes */
148 #define BTA_DM_NON_CONN BTM_NON_CONNECTABLE /* Device is not connectable. */
149 #define BTA_DM_CONN BTM_CONNECTABLE         /* Device is connectable. */
150 
151 typedef uint16_t tBTA_DM_CONN;
152 
153 /* Central/peripheral preferred roles */
154 typedef enum : uint8_t {
155   BTA_ANY_ROLE = 0x00,
156   BTA_CENTRAL_ROLE_PREF = 0x01,
157   BTA_CENTRAL_ROLE_ONLY = 0x02,
158   /* Used for PANU only, skip role switch to central */
159   BTA_PERIPHERAL_ROLE_ONLY = 0x03,
160 } tBTA_PREF_ROLES;
161 
toBTA_PREF_ROLES(uint8_t role)162 inline tBTA_PREF_ROLES toBTA_PREF_ROLES(uint8_t role) {
163   ASSERT_LOG(role <= BTA_PERIPHERAL_ROLE_ONLY,
164              "Passing illegal preferred role:0x%02x [0x%02x<=>0x%02x]", role,
165              BTA_ANY_ROLE, BTA_PERIPHERAL_ROLE_ONLY);
166   return static_cast<tBTA_PREF_ROLES>(role);
167 }
168 
169 #define CASE_RETURN_TEXT(code) \
170   case code:                   \
171     return #code
172 
preferred_role_text(const tBTA_PREF_ROLES & role)173 inline std::string preferred_role_text(const tBTA_PREF_ROLES& role) {
174   switch (role) {
175     CASE_RETURN_TEXT(BTA_ANY_ROLE);
176     CASE_RETURN_TEXT(BTA_CENTRAL_ROLE_PREF);
177     CASE_RETURN_TEXT(BTA_CENTRAL_ROLE_ONLY);
178     CASE_RETURN_TEXT(BTA_PERIPHERAL_ROLE_ONLY);
179     default:
180       return base::StringPrintf("UNKNOWN[%hhu]", role);
181   }
182 }
183 #undef CASE_RETURN_TEXT
184 
185 enum {
186 
187   BTA_DM_NO_SCATTERNET,      /* Device doesn't support scatternet, it might
188                                 support "role switch during connection" for
189                                 an incoming connection, when it already has
190                                 another connection in central role */
191   BTA_DM_PARTIAL_SCATTERNET, /* Device supports partial scatternet. It can have
192                                 simultaneous connection in Central and
193                                 Peripheral roles for short period of time */
194   BTA_DM_FULL_SCATTERNET /* Device can have simultaneous connection in central
195                             and peripheral roles */
196 
197 };
198 
199 typedef struct {
200   uint8_t bta_dm_eir_min_name_len; /* minimum length of local name when it is
201                                       shortened */
202 #if (BTA_EIR_CANNED_UUID_LIST == TRUE)
203   uint8_t bta_dm_eir_uuid16_len; /* length of 16-bit UUIDs */
204   uint8_t* bta_dm_eir_uuid16;    /* 16-bit UUIDs */
205 #else
206   uint32_t uuid_mask[BTM_EIR_SERVICE_ARRAY_SIZE]; /* mask of UUID list in EIR */
207 #endif
208   int8_t* bta_dm_eir_inq_tx_power;     /* Inquiry TX power         */
209   uint8_t bta_dm_eir_flag_len;         /* length of flags in bytes */
210   uint8_t* bta_dm_eir_flags;           /* flags for EIR */
211   uint8_t bta_dm_eir_manufac_spec_len; /* length of manufacturer specific in
212                                           bytes */
213   uint8_t* bta_dm_eir_manufac_spec;    /* manufacturer specific */
214   uint8_t bta_dm_eir_additional_len;   /* length of additional data in bytes */
215   uint8_t* bta_dm_eir_additional;      /* additional data */
216 } tBTA_DM_EIR_CONF;
217 
218 typedef uint8_t tBTA_DM_BLE_RSSI_ALERT_TYPE;
219 
220 typedef enum : uint8_t {
221   /* Security Callback Events */
222   BTA_DM_PIN_REQ_EVT = 2,          /* PIN request. */
223   BTA_DM_AUTH_CMPL_EVT = 3,        /* Authentication complete indication. */
224   BTA_DM_AUTHORIZE_EVT = 4,        /* Authorization request. */
225   BTA_DM_LINK_UP_EVT = 5,          /* Connection UP event */
226   BTA_DM_LINK_DOWN_EVT = 6,        /* Connection DOWN event */
227   BTA_DM_BOND_CANCEL_CMPL_EVT = 9, /* Bond cancel complete indication */
228   BTA_DM_SP_CFM_REQ_EVT = 10,   /* Simple Pairing User Confirmation request. \
229                                  */
230   BTA_DM_SP_KEY_NOTIF_EVT = 11, /* Simple Pairing Passkey Notification */
231   BTA_DM_BLE_KEY_EVT = 15,      /* BLE SMP key event for peer device keys */
232   BTA_DM_BLE_SEC_REQ_EVT = 16,  /* BLE SMP security request */
233   BTA_DM_BLE_PASSKEY_NOTIF_EVT = 17, /* SMP passkey notification event */
234   BTA_DM_BLE_PASSKEY_REQ_EVT = 18,   /* SMP passkey request event */
235   BTA_DM_BLE_OOB_REQ_EVT = 19,       /* SMP OOB request event */
236   BTA_DM_BLE_LOCAL_IR_EVT = 20,      /* BLE local IR event */
237   BTA_DM_BLE_LOCAL_ER_EVT = 21,      /* BLE local ER event */
238   BTA_DM_BLE_NC_REQ_EVT = 22,        /* SMP Numeric Comparison request event */
239   BTA_DM_SP_RMT_OOB_EXT_EVT =
240       23, /* Simple Pairing Remote OOB Extended Data request. */
241   BTA_DM_BLE_AUTH_CMPL_EVT = 24, /* BLE Auth complete */
242   BTA_DM_DEV_UNPAIRED_EVT = 25,
243   BTA_DM_LE_FEATURES_READ = 27,    /* Cotroller specific LE features are read \
244                                     */
245   BTA_DM_ENER_INFO_READ = 28,      /* Energy info read */
246   BTA_DM_BLE_SC_OOB_REQ_EVT = 29,  /* SMP SC OOB request event */
247   BTA_DM_BLE_CONSENT_REQ_EVT = 30, /* SMP consent request event */
248   BTA_DM_BLE_SC_CR_LOC_OOB_EVT = 31, /* SMP SC Create Local OOB request event */
249   BTA_DM_REPORT_BONDING_EVT = 32,    /*handle for pin or key missing*/
250   BTA_DM_LE_ADDR_ASSOC_EVT = 33,     /* identity address association event */
251   BTA_DM_LINK_UP_FAILED_EVT = 34,    /* Create connection failed event */
252 } tBTA_DM_SEC_EVT;
253 
254 /* Structure associated with BTA_DM_PIN_REQ_EVT */
255 typedef struct {
256   /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
257    * order */
258   RawAddress bd_addr;  /* BD address peer device. */
259   DEV_CLASS dev_class; /* Class of Device */
260   BD_NAME bd_name;     /* Name of peer device. */
261   bool min_16_digit;   /* true if the pin returned must be at least 16 digits */
262 } tBTA_DM_PIN_REQ;
263 
264 /* BLE related definition */
265 
266 #define BTA_DM_AUTH_FAIL_BASE (HCI_ERR_MAX_ERR + 10)
267 
268 /* Converts SMP error codes defined in smp_api.h to SMP auth fail reasons below.
269  */
270 #define BTA_DM_AUTH_CONVERT_SMP_CODE(x) (BTA_DM_AUTH_FAIL_BASE + (x))
271 
272 #define BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL \
273   (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_AUTH_FAIL)
274 #define BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL \
275   (BTA_DM_AUTH_FAIL_BASE + SMP_CONFIRM_VALUE_ERR)
276 #define BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT \
277   (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_NOT_SUPPORT)
278 #define BTA_DM_AUTH_SMP_UNKNOWN_ERR \
279   (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_FAIL_UNKNOWN)
280 #define BTA_DM_AUTH_SMP_CONN_TOUT (BTA_DM_AUTH_FAIL_BASE + SMP_CONN_TOUT)
281 
282 typedef uint8_t tBTA_LE_KEY_TYPE; /* can be used as a bit mask */
283 
284 typedef union {
285   tBTM_LE_PENC_KEYS penc_key;  /* received peer encryption key */
286   tBTM_LE_PCSRK_KEYS psrk_key; /* received peer device SRK */
287   tBTM_LE_PID_KEYS pid_key;    /* peer device ID key */
288   tBTM_LE_LENC_KEYS
289       lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
290   tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
291   tBTM_LE_PID_KEYS lid_key; /* local device ID key for the particular remote */
292 } tBTA_LE_KEY_VALUE;
293 
294 #define BTA_BLE_LOCAL_KEY_TYPE_ID 1
295 #define BTA_BLE_LOCAL_KEY_TYPE_ER 2
296 typedef uint8_t tBTA_DM_BLE_LOCAL_KEY_MASK;
297 
298 typedef struct {
299   Octet16 ir;
300   Octet16 irk;
301   Octet16 dhk;
302 } tBTA_BLE_LOCAL_ID_KEYS;
303 
304 #define BTA_DM_SEC_GRANTED BTA_SUCCESS
305 #define BTA_DM_SEC_PAIR_NOT_SPT BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT
306 typedef uint8_t tBTA_DM_BLE_SEC_GRANT;
307 
308 /* Structure associated with BTA_DM_BLE_SEC_REQ_EVT */
309 typedef struct {
310   RawAddress bd_addr; /* peer address */
311   BD_NAME bd_name; /* peer device name */
312 } tBTA_DM_BLE_SEC_REQ;
313 
314 typedef struct {
315   RawAddress bd_addr; /* peer address */
316   tBTM_LE_KEY_TYPE key_type;
317   tBTM_LE_KEY_VALUE* p_key_value;
318 } tBTA_DM_BLE_KEY;
319 
320 /* Structure associated with BTA_DM_AUTH_CMPL_EVT */
321 typedef struct {
322   RawAddress bd_addr;  /* BD address peer device. */
323   BD_NAME bd_name;     /* Name of peer device. */
324   bool key_present;    /* Valid link key value in key element */
325   LinkKey key;         /* Link key associated with peer device. */
326   uint8_t key_type;    /* The type of Link Key */
327   bool success;        /* true of authentication succeeded, false if failed. */
328   tHCI_REASON
329       fail_reason; /* The HCI reason/error code for when success=false */
330   tBLE_ADDR_TYPE addr_type; /* Peer device address type */
331   tBT_DEVICE_TYPE dev_type;
332   bool is_ctkd; /* True if key is derived using CTKD procedure */
333 } tBTA_DM_AUTH_CMPL;
334 
335 /* Structure associated with BTA_DM_LINK_UP_EVT */
336 typedef struct {
337   RawAddress bd_addr; /* BD address peer device. */
338   tBT_TRANSPORT transport_link_type;
339   uint16_t acl_handle;
340 } tBTA_DM_LINK_UP;
341 
342 /* Structure associated with BTA_DM_LINK_UP_FAILED_EVT */
343 typedef struct {
344   RawAddress bd_addr; /* BD address peer device. */
345   tBT_TRANSPORT transport_link_type;
346   tHCI_STATUS status; /* The HCI error code associated with this event */
347 } tBTA_DM_LINK_UP_FAILED;
348 
349 /* Structure associated with BTA_DM_LINK_DOWN_EVT */
350 typedef struct {
351   RawAddress bd_addr; /* BD address peer device. */
352   tBT_TRANSPORT transport_link_type;
353   tHCI_STATUS status;
354 } tBTA_DM_LINK_DOWN;
355 
356 #define BTA_AUTH_SP_YES                                                       \
357   BTM_AUTH_SP_YES /* 1 MITM Protection Required - Single Profile/non-bonding  \
358                     Use IO Capabilities to determine authentication procedure \
359                     */
360 
361 #define BTA_AUTH_DD_BOND \
362   BTM_AUTH_DD_BOND /* 2 this bit is set for dedicated bonding */
363 #define BTA_AUTH_GEN_BOND \
364   BTM_AUTH_SPGB_NO /* 4 this bit is set for general bonding */
365 #define BTA_AUTH_BONDS \
366   BTM_AUTH_BONDS /* 6 the general/dedicated bonding bits  */
367 
368 #define BTA_LE_AUTH_REQ_SC_MITM_BOND BTM_LE_AUTH_REQ_SC_MITM_BOND /* 1101 */
369 
370 /* Structure associated with BTA_DM_SP_CFM_REQ_EVT */
371 typedef struct {
372   /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
373    * order */
374   RawAddress bd_addr;  /* peer address */
375   DEV_CLASS dev_class; /* peer CoD */
376   BD_NAME bd_name;     /* peer device name */
377   uint32_t num_val; /* the numeric value for comparison. If just_works, do not
378                        show this number to UI */
379   bool just_works;  /* true, if "Just Works" association model */
380   tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */
381   tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */
382   tBTM_IO_CAP loc_io_caps;    /* IO Capabilities of local device */
383   tBTM_AUTH_REQ rmt_io_caps;  /* IO Capabilities of remote device */
384 } tBTA_DM_SP_CFM_REQ;
385 
386 /* Structure associated with BTA_DM_SP_KEY_NOTIF_EVT */
387 typedef struct {
388   /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
389    * order */
390   RawAddress bd_addr;  /* peer address */
391   DEV_CLASS dev_class; /* peer CoD */
392   BD_NAME bd_name;     /* peer device name */
393   uint32_t passkey; /* the numeric value for comparison. If just_works, do not
394                        show this number to UI */
395 } tBTA_DM_SP_KEY_NOTIF;
396 
397 /* Structure associated with BTA_DM_SP_RMT_OOB_EVT */
398 typedef struct {
399   /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
400    * order */
401   RawAddress bd_addr;  /* peer address */
402   DEV_CLASS dev_class; /* peer CoD */
403   BD_NAME bd_name;     /* peer device name */
404 } tBTA_DM_SP_RMT_OOB;
405 
406 /* Structure associated with BTA_DM_BOND_CANCEL_CMPL_EVT */
407 typedef struct {
408   tBTA_STATUS result; /* true of bond cancel succeeded, false if failed. */
409 } tBTA_DM_BOND_CANCEL_CMPL;
410 
411 /* Add to remove bond of key missing RC */
412 typedef struct {
413   RawAddress bd_addr;
414 } tBTA_DM_RC_UNPAIR;
415 
416 typedef struct {
417   Octet16 local_oob_c; /* Local OOB Data Confirmation/Commitment */
418   Octet16 local_oob_r; /* Local OOB Data Randomizer */
419 } tBTA_DM_LOC_OOB_DATA;
420 
421 typedef struct {
422   RawAddress pairing_bda;
423   RawAddress id_addr;
424 } tBTA_DM_PROC_ID_ADDR;
425 
426 /* Union of all security callback structures */
427 typedef union {
428   tBTA_DM_PIN_REQ pin_req;        /* PIN request. */
429   tBTA_DM_AUTH_CMPL auth_cmpl;    /* Authentication complete indication. */
430   tBTA_DM_LINK_UP link_up;        /* ACL connection up event */
431   tBTA_DM_LINK_UP_FAILED link_up_failed; /* ACL connection up failure event */
432   tBTA_DM_LINK_DOWN link_down;    /* ACL connection down event */
433   tBTA_DM_SP_CFM_REQ cfm_req;     /* user confirm request */
434   tBTA_DM_SP_KEY_NOTIF key_notif; /* passkey notification */
435   tBTA_DM_SP_RMT_OOB rmt_oob;     /* remote oob */
436   tBTA_DM_BOND_CANCEL_CMPL
437       bond_cancel_cmpl;               /* Bond Cancel Complete indication */
438   tBTA_DM_BLE_SEC_REQ ble_req;        /* BLE SMP related request */
439   tBTA_DM_BLE_KEY ble_key;            /* BLE SMP keys used when pairing */
440   tBTA_BLE_LOCAL_ID_KEYS ble_id_keys; /* IR event */
441   Octet16 ble_er;                     /* ER event data */
442   tBTA_DM_LOC_OOB_DATA local_oob_data; /* Local OOB data generated by us */
443   tBTA_DM_RC_UNPAIR delete_key_RC_to_unpair;
444   tBTA_DM_PROC_ID_ADDR proc_id_addr; /* Identity address event */
445 } tBTA_DM_SEC;
446 
447 /* Security callback */
448 typedef void(tBTA_DM_SEC_CBACK)(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data);
449 
450 #define BTA_DM_BLE_PF_LIST_LOGIC_OR 1
451 #define BTA_DM_BLE_PF_FILT_LOGIC_OR 0
452 
453 /* Search callback events */
454 typedef enum : uint8_t {
455   BTA_DM_INQ_RES_EVT = 0,  /* Inquiry result for a peer device. */
456   BTA_DM_INQ_CMPL_EVT = 1, /* Inquiry complete. */
457   BTA_DM_DISC_RES_EVT = 2, /* Discovery result for a peer device. */
458   BTA_DM_GATT_OVER_LE_RES_EVT =
459       3,                    /* GATT services over LE transport discovered */
460   BTA_DM_DISC_CMPL_EVT = 4, /* Discovery complete. */
461   BTA_DM_SEARCH_CANCEL_CMPL_EVT = 5, /* Search cancelled */
462   BTA_DM_DID_RES_EVT = 6,            /* Vendor/Product ID search result */
463   BTA_DM_GATT_OVER_SDP_RES_EVT = 7,  /* GATT services over SDP discovered */
464 } tBTA_DM_SEARCH_EVT;
465 
466 #ifndef CASE_RETURN_TEXT
467 #define CASE_RETURN_TEXT(code) \
468   case code:                   \
469     return #code
470 #endif
471 
bta_dm_search_evt_text(const tBTA_DM_SEARCH_EVT & event)472 inline std::string bta_dm_search_evt_text(const tBTA_DM_SEARCH_EVT& event) {
473   switch (event) {
474     CASE_RETURN_TEXT(BTA_DM_INQ_RES_EVT);
475     CASE_RETURN_TEXT(BTA_DM_INQ_CMPL_EVT);
476     CASE_RETURN_TEXT(BTA_DM_DISC_RES_EVT);
477     CASE_RETURN_TEXT(BTA_DM_GATT_OVER_LE_RES_EVT);
478     CASE_RETURN_TEXT(BTA_DM_DISC_CMPL_EVT);
479     CASE_RETURN_TEXT(BTA_DM_SEARCH_CANCEL_CMPL_EVT);
480     CASE_RETURN_TEXT(BTA_DM_DID_RES_EVT);
481     CASE_RETURN_TEXT(BTA_DM_GATT_OVER_SDP_RES_EVT);
482     default:
483       return base::StringPrintf("UNKNOWN[%hhu]", event);
484   }
485 }
486 
487 #undef CASE_RETURN_TEXT
488 
489 /* Structure associated with BTA_DM_INQ_RES_EVT */
490 typedef struct {
491   RawAddress bd_addr;          /* BD address peer device. */
492   DEV_CLASS dev_class;         /* Device class of peer device. */
493   bool remt_name_not_required; /* Application sets this flag if it already knows
494                                   the name of the device */
495   /* If the device name is known to application BTA skips the remote name
496    * request */
497   bool is_limited; /* true, if the limited inquiry bit is set in the CoD */
498   int8_t rssi;     /* The rssi value */
499   const uint8_t* p_eir; /* received EIR */
500   uint16_t eir_len; /* received EIR length */
501   uint8_t inq_result_type;
502   tBLE_ADDR_TYPE ble_addr_type;
503   uint16_t ble_evt_type;
504   uint8_t ble_primary_phy;
505   uint8_t ble_secondary_phy;
506   uint8_t ble_advertising_sid;
507   int8_t ble_tx_power;
508   uint16_t ble_periodic_adv_int;
509   tBT_DEVICE_TYPE device_type;
510   uint8_t flag;
511   bool include_rsi; /* true, if ADV contains RSI data */
512   RawAddress original_bda; /* original address to pass up to
513                               GattService#onScanResult */
514 } tBTA_DM_INQ_RES;
515 
516 /* Structure associated with BTA_DM_INQ_CMPL_EVT */
517 typedef struct {
518   uint8_t num_resps; /* Number of inquiry responses. */
519 } tBTA_DM_INQ_CMPL;
520 
521 /* Structure associated with BTA_DM_DISC_RES_EVT */
522 typedef struct {
523   RawAddress bd_addr;          /* BD address peer device. */
524   BD_NAME bd_name;             /* Name of peer device. */
525   tBTA_SERVICE_MASK services;  /* Services found on peer device. */
526   tBT_DEVICE_TYPE device_type; /* device type in case it is BLE device */
527   size_t num_uuids;
528   bluetooth::Uuid* p_uuid_list;
529   tBTA_STATUS result;
530   tHCI_STATUS hci_status;
531 } tBTA_DM_DISC_RES;
532 
533 /* Structure associated with tBTA_DM_DISC_BLE_RES */
534 typedef struct {
535   RawAddress bd_addr; /* BD address peer device. */
536   BD_NAME bd_name;  /* Name of peer device. */
537   std::vector<bluetooth::Uuid>*
538       services; /* GATT based Services UUID found on peer device. */
539 } tBTA_DM_DISC_BLE_RES;
540 
541 /* Structure associated with tBTA_DM_DID_RES */
542 typedef struct {
543   RawAddress bd_addr; /* BD address peer device. */
544   uint8_t vendor_id_src;
545   uint16_t vendor_id;
546   uint16_t product_id;
547   uint16_t version;
548 } tBTA_DM_DID_RES;
549 
550 /* Union of all search callback structures */
551 typedef union {
552   tBTA_DM_INQ_RES inq_res;   /* Inquiry result for a peer device. */
553   tBTA_DM_INQ_CMPL inq_cmpl; /* Inquiry complete. */
554   tBTA_DM_DISC_RES disc_res; /* Discovery result for a peer device. */
555   tBTA_DM_DISC_BLE_RES
556       disc_ble_res;             /* discovery result for GATT based service */
557   tBTA_DM_DID_RES did_res;      /* Vendor and Product ID of peer device */
558 } tBTA_DM_SEARCH;
559 
560 /* Search callback */
561 typedef void(tBTA_DM_SEARCH_CBACK)(tBTA_DM_SEARCH_EVT event,
562                                    tBTA_DM_SEARCH* p_data);
563 
564 /* Execute call back */
565 typedef void(tBTA_DM_EXEC_CBACK)(void* p_param);
566 
567 /* Encryption callback*/
568 typedef void(tBTA_DM_ENCRYPT_CBACK)(const RawAddress& bd_addr,
569                                     tBT_TRANSPORT transport,
570                                     tBTA_STATUS result);
571 
572 typedef void(tBTA_BLE_ENERGY_INFO_CBACK)(tBTM_BLE_TX_TIME_MS tx_time,
573                                          tBTM_BLE_RX_TIME_MS rx_time,
574                                          tBTM_BLE_IDLE_TIME_MS idle_time,
575                                          tBTM_BLE_ENERGY_USED energy_used,
576                                          tBTM_CONTRL_STATE ctrl_state,
577                                          tBTA_STATUS status);
578 
579 /* Maximum service name length */
580 #define BTA_SERVICE_NAME_LEN 35
581 
582 typedef enum : uint8_t {
583   /* power mode actions  */
584   BTA_DM_PM_NO_ACTION = 0x00, /* no change to the current pm setting */
585   BTA_DM_PM_PARK = 0x10,      /* prefers park mode */
586   BTA_DM_PM_SNIFF = 0x20,     /* prefers sniff mode */
587   BTA_DM_PM_SNIFF1 = 0x21,    /* prefers sniff1 mode */
588   BTA_DM_PM_SNIFF2 = 0x22,    /* prefers sniff2 mode */
589   BTA_DM_PM_SNIFF3 = 0x23,    /* prefers sniff3 mode */
590   BTA_DM_PM_SNIFF4 = 0x24,    /* prefers sniff4 mode */
591   BTA_DM_PM_SNIFF5 = 0x25,    /* prefers sniff5 mode */
592   BTA_DM_PM_SNIFF6 = 0x26,    /* prefers sniff6 mode */
593   BTA_DM_PM_SNIFF7 = 0x27,    /* prefers sniff7 mode */
594   BTA_DM_PM_SNIFF_USER0 =
595       0x28, /* prefers user-defined sniff0 mode (testtool only) */
596   BTA_DM_PM_SNIFF_USER1 =
597       0x29, /* prefers user-defined sniff1 mode (testtool only) */
598   BTA_DM_PM_ACTIVE = 0x40,  /* prefers active mode */
599   BTA_DM_PM_RETRY = 0x80,   /* retry power mode based on current settings */
600   BTA_DM_PM_SUSPEND = 0x04, /* prefers suspend mode */
601   BTA_DM_PM_NO_PREF = 0x01, /* service has no preference on power mode setting.
602                                eg. connection to \ service got closed */
603   BTA_DM_PM_SNIFF_MASK = 0x0f,  // Masks the sniff submode
604 } tBTA_DM_PM_ACTION_BITMASK;
605 typedef uint8_t tBTA_DM_PM_ACTION;
606 
607 /* index to bta_dm_ssr_spec */
608 enum {
609   BTA_DM_PM_SSR0 = 0,
610   /* BTA_DM_PM_SSR1 will be dedicated for \
611      HH SSR setting entry, no other profile can use it */
612   BTA_DM_PM_SSR1 = 1,
613   BTA_DM_PM_SSR2 = 2,
614   BTA_DM_PM_SSR3 = 3,
615   BTA_DM_PM_SSR4 = 4,
616 };
617 
618 #define BTA_DM_PM_NUM_EVTS 9
619 
620 #ifndef BTA_DM_PM_PARK_IDX
621 #define BTA_DM_PM_PARK_IDX \
622   7 /* the actual index to bta_dm_pm_md[] for PARK mode */
623 #endif
624 
625 #ifndef BTA_DM_PM_SNIFF_A2DP_IDX
626 #define BTA_DM_PM_SNIFF_A2DP_IDX BTA_DM_PM_SNIFF
627 #endif
628 
629 #ifndef BTA_DM_PM_SNIFF_HD_IDLE_IDX
630 #define BTA_DM_PM_SNIFF_HD_IDLE_IDX BTA_DM_PM_SNIFF2
631 #endif
632 
633 #ifndef BTA_DM_PM_SNIFF_SCO_OPEN_IDX
634 #define BTA_DM_PM_SNIFF_SCO_OPEN_IDX BTA_DM_PM_SNIFF3
635 #endif
636 
637 #ifndef BTA_DM_PM_SNIFF_HD_ACTIVE_IDX
638 #define BTA_DM_PM_SNIFF_HD_ACTIVE_IDX BTA_DM_PM_SNIFF4
639 #endif
640 
641 #ifndef BTA_DM_PM_SNIFF_HH_OPEN_IDX
642 #define BTA_DM_PM_SNIFF_HH_OPEN_IDX BTA_DM_PM_SNIFF2
643 #endif
644 
645 #ifndef BTA_DM_PM_SNIFF_HH_ACTIVE_IDX
646 #define BTA_DM_PM_SNIFF_HH_ACTIVE_IDX BTA_DM_PM_SNIFF2
647 #endif
648 
649 #ifndef BTA_DM_PM_SNIFF_HH_IDLE_IDX
650 #define BTA_DM_PM_SNIFF_HH_IDLE_IDX BTA_DM_PM_SNIFF2
651 #endif
652 
653 #ifndef BTA_DM_PM_HH_OPEN_DELAY
654 #define BTA_DM_PM_HH_OPEN_DELAY 30000
655 #endif
656 
657 #ifndef BTA_DM_PM_HH_ACTIVE_DELAY
658 #define BTA_DM_PM_HH_ACTIVE_DELAY 30000
659 #endif
660 
661 #ifndef BTA_DM_PM_HH_IDLE_DELAY
662 #define BTA_DM_PM_HH_IDLE_DELAY 30000
663 #endif
664 
665 /* The Sniff Parameters defined below must be ordered from highest
666  * latency (biggest interval) to lowest latency.  If there is a conflict
667  * among the connected services the setting with the lowest latency will
668  * be selected.  If a device should override a sniff parameter then it
669  * must insure that order is maintained.
670  */
671 #ifndef BTA_DM_PM_SNIFF_MAX
672 #define BTA_DM_PM_SNIFF_MAX 800
673 #define BTA_DM_PM_SNIFF_MIN 400
674 #define BTA_DM_PM_SNIFF_ATTEMPT 4
675 #define BTA_DM_PM_SNIFF_TIMEOUT 1
676 #endif
677 
678 #ifndef BTA_DM_PM_SNIFF1_MAX
679 #define BTA_DM_PM_SNIFF1_MAX 400
680 #define BTA_DM_PM_SNIFF1_MIN 200
681 #define BTA_DM_PM_SNIFF1_ATTEMPT 4
682 #define BTA_DM_PM_SNIFF1_TIMEOUT 1
683 #endif
684 
685 #ifndef BTA_DM_PM_SNIFF2_MAX
686 #define BTA_DM_PM_SNIFF2_MAX 54
687 #define BTA_DM_PM_SNIFF2_MIN 30
688 #define BTA_DM_PM_SNIFF2_ATTEMPT 4
689 #define BTA_DM_PM_SNIFF2_TIMEOUT 1
690 #endif
691 
692 #ifndef BTA_DM_PM_SNIFF3_MAX
693 #define BTA_DM_PM_SNIFF3_MAX 150
694 #define BTA_DM_PM_SNIFF3_MIN 50
695 #define BTA_DM_PM_SNIFF3_ATTEMPT 4
696 #define BTA_DM_PM_SNIFF3_TIMEOUT 1
697 #endif
698 
699 #ifndef BTA_DM_PM_SNIFF4_MAX
700 #define BTA_DM_PM_SNIFF4_MAX 18
701 #define BTA_DM_PM_SNIFF4_MIN 10
702 #define BTA_DM_PM_SNIFF4_ATTEMPT 4
703 #define BTA_DM_PM_SNIFF4_TIMEOUT 1
704 #endif
705 
706 #ifndef BTA_DM_PM_SNIFF5_MAX
707 #define BTA_DM_PM_SNIFF5_MAX 36
708 #define BTA_DM_PM_SNIFF5_MIN 30
709 #define BTA_DM_PM_SNIFF5_ATTEMPT 2
710 #define BTA_DM_PM_SNIFF5_TIMEOUT 0
711 #endif
712 
713 #ifndef BTA_DM_PM_SNIFF6_MAX
714 #define BTA_DM_PM_SNIFF6_MAX 18
715 #define BTA_DM_PM_SNIFF6_MIN 14
716 #define BTA_DM_PM_SNIFF6_ATTEMPT 1
717 #define BTA_DM_PM_SNIFF6_TIMEOUT 0
718 #endif
719 
720 #ifndef BTA_DM_PM_PARK_MAX
721 #define BTA_DM_PM_PARK_MAX 800
722 #define BTA_DM_PM_PARK_MIN 400
723 #define BTA_DM_PM_PARK_ATTEMPT 0
724 #define BTA_DM_PM_PARK_TIMEOUT 0
725 #endif
726 
727 /* Device Identification (DI) data structure
728 */
729 
730 #ifndef BTA_DI_NUM_MAX
731 #define BTA_DI_NUM_MAX 3
732 #endif
733 
734 #define IMMEDIATE_DELY_MODE 0x00
735 #define ALLOW_ALL_FILTER 0x00
736 #define LOWEST_RSSI_VALUE 129
737 
738 /*****************************************************************************
739  *  External Function Declarations
740  ****************************************************************************/
741 
742 void BTA_dm_init();
743 
744 /*******************************************************************************
745  *
746  * Function         BTA_DmSetDeviceName
747  *
748  * Description      This function sets the Bluetooth name of the local device.
749  *
750  *
751  * Returns          void
752  *
753  ******************************************************************************/
754 void BTA_DmSetDeviceName(const char* p_name);
755 
756 /*******************************************************************************
757  *
758  * Function         BTA_DmSetVisibility
759  *
760  * Description      This function sets the Bluetooth connectable,discoverable,
761  *                  pairable and conn paired only modesmodes of the local
762  *                  device.
763  *                  This controls whether other Bluetooth devices can find and
764  *                  connect to the local device.
765  *
766  *
767  * Returns          void
768  *
769  ******************************************************************************/
770 bool BTA_DmSetVisibility(bt_scan_mode_t mode);
771 
772 /*******************************************************************************
773  *
774  * Function         BTA_DmSearch
775  *
776  * Description      This function searches for peer Bluetooth devices.  It
777  *                  first performs an inquiry; for each device found from the
778  *                  inquiry it gets the remote name of the device.  If
779  *                  parameter services is nonzero, service discovery will be
780  *                  performed on each device for the services specified.
781  *
782  *
783  * Returns          void
784  *
785  ******************************************************************************/
786 void BTA_DmSearch(tBTA_DM_SEARCH_CBACK* p_cback);
787 
788 /*******************************************************************************
789  *
790  * Function         BTA_DmSearchCancel
791  *
792  * Description      This function cancels a search that has been initiated
793  *                  by calling BTA_DmSearch().
794  *
795  *
796  * Returns          void
797  *
798  ******************************************************************************/
799 void BTA_DmSearchCancel(void);
800 
801 /*******************************************************************************
802  *
803  * Function         BTA_DmDiscover
804  *
805  * Description      This function performs service discovery for the services
806  *                  of a particular peer device.
807  *
808  *
809  * Returns          void
810  *
811  ******************************************************************************/
812 void BTA_DmDiscover(const RawAddress& bd_addr, tBTA_DM_SEARCH_CBACK* p_cback,
813                     tBT_TRANSPORT transport);
814 
815 /*******************************************************************************
816  *
817  * Function         BTA_DmGetCachedRemoteName
818  *
819  * Description      Retieve cached remote name if available
820  *
821  * Returns          BTA_SUCCESS if cached name was retrieved
822  *                  BTA_FAILURE if cached name is not available
823  *
824  ******************************************************************************/
825 tBTA_STATUS BTA_DmGetCachedRemoteName(const RawAddress& remote_device,
826                                       uint8_t** pp_cached_name);
827 
828 /*******************************************************************************
829  *
830  * Function         BTA_DmBond
831  *
832  * Description      This function initiates a bonding procedure with a peer
833  *                  device by designated transport.  The bonding procedure
834  *                  enables authentication and optionally encryption on the
835  *                  Bluetooth link.
836  *
837  *
838  * Returns          void
839  *
840  ******************************************************************************/
841 void BTA_DmBond(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
842                 tBT_TRANSPORT transport, tBT_DEVICE_TYPE device_type);
843 
844 /*******************************************************************************
845  *
846  * Function         BTA_DmBondCancel
847  *
848  * Description      This function cancels a bonding procedure with a peer
849  *                  device.
850  *
851  *
852  * Returns          void
853  *
854  ******************************************************************************/
855 void BTA_DmBondCancel(const RawAddress& bd_addr);
856 
857 /*******************************************************************************
858  *
859  * Function         BTA_DmPinReply
860  *
861  * Description      This function provides a PIN when one is requested by DM
862  *                  during a bonding procedure.  The application should call
863  *                  this function after the security callback is called with
864  *                  a BTA_DM_PIN_REQ_EVT.
865  *
866  *
867  * Returns          void
868  *
869  ******************************************************************************/
870 void BTA_DmPinReply(const RawAddress& bd_addr, bool accept, uint8_t pin_len,
871                     uint8_t* p_pin);
872 
873 /*******************************************************************************
874  *
875  * Function         BTA_DmLocalOob
876  *
877  * Description      This function retrieves the OOB data from local controller.
878  *                  The result is reported by bta_dm_co_loc_oob().
879  *
880  * Returns          void
881  *
882  ******************************************************************************/
883 void BTA_DmLocalOob(void);
884 
885 /*******************************************************************************
886  *
887  * Function         BTA_DmConfirm
888  *
889  * Description      This function accepts or rejects the numerical value of the
890  *                  Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
891  *
892  * Returns          void
893  *
894  ******************************************************************************/
895 void BTA_DmConfirm(const RawAddress& bd_addr, bool accept);
896 
897 /*******************************************************************************
898  *
899  * Function         BTA_DmAddDevice
900  *
901  * Description      This function adds a device to the security database list
902  *                  of peer devices. This function would typically be called
903  *                  at system startup to initialize the security database with
904  *                  known peer devices.  This is a direct execution function
905  *                  that may lock task scheduling on some platforms.
906  *
907  * Returns          void
908  *
909  ******************************************************************************/
910 void BTA_DmAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
911                      const LinkKey& link_key, uint8_t key_type,
912                      uint8_t pin_length);
913 
914 /*******************************************************************************
915  *
916  * Function         BTA_DmRemoveDevice
917  *
918  * Description      This function removes a device from the security database.
919  *                  This is a direct execution function that may lock task
920  *                  scheduling on some platforms.
921  *
922  *
923  * Returns          BTA_SUCCESS if successful.
924  *                  BTA_FAIL if operation failed.
925  *
926  ******************************************************************************/
927 tBTA_STATUS BTA_DmRemoveDevice(const RawAddress& bd_addr);
928 
929 /*******************************************************************************
930  *
931  * Function         BTA_GetEirService
932  *
933  * Description      This function is called to get BTA service mask from EIR.
934  *
935  * Parameters       p_eir - pointer of EIR significant part
936  *                  eir_len - EIR length
937  *                  p_services - return the BTA service mask
938  *
939  * Returns          None
940  *
941  ******************************************************************************/
942 void BTA_GetEirService(const uint8_t* p_eir, size_t eir_len,
943                        tBTA_SERVICE_MASK* p_services);
944 
945 /*******************************************************************************
946  *
947  * Function         BTA_DmGetConnectionState
948  *
949  * Description      Returns whether the remote device is currently connected.
950  *
951  * Returns          true if the device is NOT connected, false otherwise.
952  *
953  ******************************************************************************/
954 bool BTA_DmGetConnectionState(const RawAddress& bd_addr);
955 
956 /*******************************************************************************
957  *
958  * Function         BTA_DmSetLocalDiRecord
959  *
960  * Description      This function adds a DI record to the local SDP database.
961  *
962  * Returns          BTA_SUCCESS if record set sucessfully, otherwise error code.
963  *
964  ******************************************************************************/
965 tBTA_STATUS BTA_DmSetLocalDiRecord(tSDP_DI_RECORD* p_device_info,
966                                    uint32_t* p_handle);
967 
968 /*******************************************************************************
969  *
970  *
971  * Function         BTA_DmCloseACL
972  *
973  * Description      This function force to close an ACL connection and remove
974  the
975  *                  device from the security database list of known devices.
976  *
977  * Parameters:      bd_addr       - Address of the peer device
978  *                  remove_dev    - remove device or not after link down
979  *                  transport     - which transport to close
980 
981  *
982  * Returns          void.
983  *
984  ******************************************************************************/
985 void BTA_DmCloseACL(const RawAddress& bd_addr, bool remove_dev,
986                     tBT_TRANSPORT transport);
987 
988 /* BLE related API functions */
989 /*******************************************************************************
990  *
991  * Function         BTA_DmBleSecurityGrant
992  *
993  * Description      Grant security request access.
994  *
995  * Parameters:      bd_addr          - BD address of the peer
996  *                  res              - security grant status.
997  *
998  * Returns          void
999  *
1000  ******************************************************************************/
1001 void BTA_DmBleSecurityGrant(const RawAddress& bd_addr,
1002                             tBTA_DM_BLE_SEC_GRANT res);
1003 
1004 /*******************************************************************************
1005  *
1006  * Function         BTA_DmBlePasskeyReply
1007  *
1008  * Description      Send BLE SMP passkey reply.
1009  *
1010  * Parameters:      bd_addr          - BD address of the peer
1011  *                  accept           - passkey entry sucessful or declined.
1012  *                  passkey          - passkey value, must be a 6 digit number,
1013  *                                     can be lead by 0.
1014  *
1015  * Returns          void
1016  *
1017  ******************************************************************************/
1018 void BTA_DmBlePasskeyReply(const RawAddress& bd_addr, bool accept,
1019                            uint32_t passkey);
1020 
1021 /*******************************************************************************
1022  *
1023  * Function         BTA_DmBleConfirmReply
1024  *
1025  * Description      Send BLE SMP SC user confirmation reply.
1026  *
1027  * Parameters:      bd_addr          - BD address of the peer
1028  *                  accept           - numbers to compare are the same or
1029  *                                     different.
1030  *
1031  * Returns          void
1032  *
1033  ******************************************************************************/
1034 void BTA_DmBleConfirmReply(const RawAddress& bd_addr, bool accept);
1035 
1036 /*******************************************************************************
1037  *
1038  * Function         BTA_DmAddBleDevice
1039  *
1040  * Description      Add a BLE device.  This function will be normally called
1041  *                  during host startup to restore all required information
1042  *                  for a LE device stored in the NVRAM.
1043  *
1044  * Parameters:      bd_addr          - BD address of the peer
1045  *                  dev_type         - Remote device's device type.
1046  *                  addr_type        - LE device address type.
1047  *
1048  * Returns          void
1049  *
1050  ******************************************************************************/
1051 void BTA_DmAddBleDevice(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
1052                         tBT_DEVICE_TYPE dev_type);
1053 
1054 /*******************************************************************************
1055  *
1056  * Function         BTA_DmAddBleKey
1057  *
1058  * Description      Add/modify LE device information.  This function will be
1059  *                  normally called during host startup to restore all required
1060  *                  information stored in the NVRAM.
1061  *
1062  * Parameters:      bd_addr          - BD address of the peer
1063  *                  p_le_key         - LE key values.
1064  *                  key_type         - LE SMP key type.
1065  *
1066  * Returns          void
1067  *
1068  ******************************************************************************/
1069 void BTA_DmAddBleKey(const RawAddress& bd_addr, tBTA_LE_KEY_VALUE* p_le_key,
1070                      tBTM_LE_KEY_TYPE key_type);
1071 
1072 /*******************************************************************************
1073  *
1074  * Function         BTA_DmSetBlePrefConnParams
1075  *
1076  * Description      This function is called to set the preferred connection
1077  *                  parameters when default connection parameter is not desired.
1078  *
1079  * Parameters:      bd_addr          - BD address of the peripheral
1080  *                  min_conn_int     - minimum preferred connection interval
1081  *                  max_conn_int     - maximum preferred connection interval
1082  *                  peripheral_latency    - preferred peripheral latency
1083  *                  supervision_tout - preferred supervision timeout
1084  *
1085  *
1086  * Returns          void
1087  *
1088  ******************************************************************************/
1089 void BTA_DmSetBlePrefConnParams(const RawAddress& bd_addr,
1090                                 uint16_t min_conn_int, uint16_t max_conn_int,
1091                                 uint16_t peripheral_latency,
1092                                 uint16_t supervision_tout);
1093 
1094 /*******************************************************************************
1095  *
1096  * Function         BTA_DmSetEncryption
1097  *
1098  * Description      This function is called to ensure that connection is
1099  *                  encrypted.  Should be called only on an open connection.
1100  *                  Typically only needed for connections that first want to
1101  *                  bring up unencrypted links, then later encrypt them.
1102  *
1103  * Parameters:      bd_addr       - Address of the peer device
1104  *                  transport     - transport of the link to be encruypted
1105  *                  p_callback    - Pointer to callback function to indicat the
1106  *                                  link encryption status
1107  *                  sec_act       - This is the security action to indicate
1108  *                                  what kind of BLE security level is required
1109  *                                  for the BLE link if BLE is supported
1110  *                                  Note: This parameter is ignored for
1111  *                                        BR/EDR or if BLE is not supported.
1112  *
1113  * Returns          void
1114  *
1115  *
1116  ******************************************************************************/
1117 void BTA_DmSetEncryption(const RawAddress& bd_addr, tBT_TRANSPORT transport,
1118                          tBTA_DM_ENCRYPT_CBACK* p_callback,
1119                          tBTM_BLE_SEC_ACT sec_act);
1120 
1121 /*******************************************************************************
1122  *
1123  * Function         BTA_DmBleObserve
1124  *
1125  * Description      This procedure keep the device listening for advertising
1126  *                  events from a broadcast device.
1127  *
1128  * Parameters       start: start or stop observe.
1129  *                  duration : Duration of the scan. Continuous scan if 0 is
1130  *                             passed
1131  *                  p_results_cb: Callback to be called with scan results
1132  *
1133  * Returns          void
1134  *
1135  ******************************************************************************/
1136 void BTA_DmBleObserve(bool start, uint8_t duration,
1137                       tBTA_DM_SEARCH_CBACK* p_results_cb);
1138 
1139 /*******************************************************************************
1140  *
1141  * Function         BTA_DmBleScan
1142  *
1143  * Description      Start or stop the scan procedure if it's not already started
1144  *                  with BTA_DmBleObserve().
1145  *
1146  * Parameters       start: start or stop the scan procedure,
1147  *                  duration_sec: Duration of the scan. Continuous scan if 0 is
1148  *                                passed,
1149  *                  low_latency_scan: whether this is a low latency scan,
1150  *                                    default is false,
1151  *
1152  * Returns          void
1153  *
1154  ******************************************************************************/
1155 void BTA_DmBleScan(bool start, uint8_t duration, bool low_latency_scan = false);
1156 
1157 /*******************************************************************************
1158  *
1159  * Function         BTA_DmBleCsisObserve
1160  *
1161  * Description      This procedure keeps the external observer listening for
1162  *                  advertising events from a CSIS grouped device.
1163  *
1164  * Parameters       observe: enable or disable passive observe,
1165  *                  p_results_cb: Callback to be called with scan results,
1166  *
1167  * Returns          void
1168  *
1169  ******************************************************************************/
1170 void BTA_DmBleCsisObserve(bool observe, tBTA_DM_SEARCH_CBACK* p_results_cb);
1171 
1172 /*******************************************************************************
1173  *
1174  * Function         BTA_DmBleConfigLocalPrivacy
1175  *
1176  * Description      Enable/disable privacy on the local device
1177  *
1178  * Parameters:      privacy_enable   - enable/disabe privacy on remote device.
1179  *
1180  * Returns          void
1181  *
1182  ******************************************************************************/
1183 void BTA_DmBleConfigLocalPrivacy(bool privacy_enable);
1184 
1185 /*******************************************************************************
1186  *
1187  * Function         BTA_DmBleEnableRemotePrivacy
1188  *
1189  * Description      Enable/disable privacy on a remote device
1190  *
1191  * Parameters:      bd_addr          - BD address of the peer
1192  *                  privacy_enable   - enable/disabe privacy on remote device.
1193  *
1194  * Returns          void
1195  *
1196  ******************************************************************************/
1197 void BTA_DmBleEnableRemotePrivacy(const RawAddress& bd_addr,
1198                                   bool privacy_enable);
1199 
1200 /*******************************************************************************
1201  *
1202  * Function         BTA_DmBleUpdateConnectionParams
1203  *
1204  * Description      Update connection parameters, can only be used when
1205  *                  connection is up.
1206  *
1207  * Parameters:      bd_addr   - BD address of the peer
1208  *                  min_int   - minimum connection interval, [0x0004 ~ 0x4000]
1209  *                  max_int   - maximum connection interval, [0x0004 ~ 0x4000]
1210  *                  latency   - peripheral latency [0 ~ 500]
1211  *                  timeout   - supervision timeout [0x000a ~ 0xc80]
1212  *
1213  * Returns          void
1214  *
1215  ******************************************************************************/
1216 void BTA_DmBleUpdateConnectionParams(const RawAddress& bd_addr,
1217                                      uint16_t min_int, uint16_t max_int,
1218                                      uint16_t latency, uint16_t timeout,
1219                                      uint16_t min_ce_len, uint16_t max_ce_len);
1220 
1221 /*******************************************************************************
1222  *
1223  * Function         BTA_DmBleSetDataLength
1224  *
1225  * Description      This function is to set maximum LE data packet size
1226  *
1227  * Returns          void
1228  *
1229  ******************************************************************************/
1230 void BTA_DmBleRequestMaxTxDataLength(const RawAddress& remote_device);
1231 
1232 /*******************************************************************************
1233  *
1234  * Function         BTA_DmBleGetEnergyInfo
1235  *
1236  * Description      This function is called to obtain the energy info
1237  *
1238  * Parameters       p_cmpl_cback - Command complete callback
1239  *
1240  * Returns          void
1241  *
1242  ******************************************************************************/
1243 void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK* p_cmpl_cback);
1244 
1245 /*******************************************************************************
1246  *
1247  * Function         BTA_BrcmInit
1248  *
1249  * Description      This function initializes Broadcom specific VS handler in
1250  *                  BTA
1251  *
1252  * Returns          void
1253  *
1254  ******************************************************************************/
1255 void BTA_VendorInit(void);
1256 
1257 /*******************************************************************************
1258  *
1259  * Function         BTA_DmClearEventFilter
1260  *
1261  * Description      This function clears the event filter
1262  *
1263  * Returns          void
1264  *
1265  ******************************************************************************/
1266 void BTA_DmClearEventFilter(void);
1267 
1268 /*******************************************************************************
1269  *
1270  * Function         BTA_DmClearEventMask
1271  *
1272  * Description      This function clears the event mask
1273  *
1274  * Returns          void
1275  *
1276  ******************************************************************************/
1277 void BTA_DmClearEventMask(void);
1278 
1279 /*******************************************************************************
1280  *
1281  * Function         BTA_DmDisconnectAllAcls
1282  *
1283  * Description      This function will disconnect all LE and Classic ACLs.
1284  *
1285  * Returns          void
1286  *
1287  ******************************************************************************/
1288 void BTA_DmDisconnectAllAcls(void);
1289 
1290 /*******************************************************************************
1291  *
1292  * Function         BTA_DmClearFilterAcceptList
1293  *
1294  * Description      This function clears the filter accept list
1295  *
1296  * Returns          void
1297  *
1298  ******************************************************************************/
1299 void BTA_DmClearFilterAcceptList(void);
1300 
1301 using LeRandCallback = base::Callback<void(uint64_t)>;
1302 /*******************************************************************************
1303  *
1304  * Function         BTA_DmLeRand
1305  *
1306  * Description      This function clears the event filter
1307  *
1308  * Returns          cb: callback to receive the resulting random number
1309  *
1310  ******************************************************************************/
1311 void BTA_DmLeRand(LeRandCallback cb);
1312 
1313 /*******************************************************************************
1314  *
1315  * Function        BTA_DmSetEventFilterConnectionSetupAllDevices
1316  *
1317  * Description    Tell the controller to allow all devices
1318  *
1319  * Parameters
1320  *
1321  *******************************************************************************/
1322 void BTA_DmSetEventFilterConnectionSetupAllDevices();
1323 
1324 /*******************************************************************************
1325  *
1326  * Function        BTA_DmAllowWakeByHid
1327  *
1328  * Description    Allow the device to be woken by HID devices
1329  *
1330  * Parameters
1331  *
1332  *******************************************************************************/
1333 void BTA_DmAllowWakeByHid(
1334     std::vector<RawAddress> classic_hid_devices,
1335     std::vector<std::pair<RawAddress, uint8_t>> le_hid_devices);
1336 
1337 /*******************************************************************************
1338  *
1339  * Function        BTA_DmRestoreFilterAcceptList
1340  *
1341  * Description    Floss: Restore the state of the for the filter accept list
1342  *
1343  * Parameters
1344  *
1345  *******************************************************************************/
1346 void BTA_DmRestoreFilterAcceptList(
1347     std::vector<std::pair<RawAddress, uint8_t>> le_devices);
1348 
1349 /*******************************************************************************
1350  *
1351  * Function       BTA_DmSetDefaultEventMaskExcept
1352  *
1353  * Description    Floss: Set the default event mask for Classic and LE except
1354  *                the given values (they will be disabled in the final set
1355  *                mask).
1356  *
1357  * Parameters     Bits set for event mask and le event mask that should be
1358  *                disabled in the final value.
1359  *
1360  *******************************************************************************/
1361 void BTA_DmSetDefaultEventMaskExcept(uint64_t mask, uint64_t le_mask);
1362 
1363 /*******************************************************************************
1364  *
1365  * Function        BTA_DmSetEventFilterInquiryResultAllDevices
1366  *
1367  * Description    Floss: Set the event filter to inquiry result device all
1368  *
1369  * Parameters
1370  *
1371  *******************************************************************************/
1372 void BTA_DmSetEventFilterInquiryResultAllDevices();
1373 
1374 /*******************************************************************************
1375  *
1376  * Function         BTA_DmBleResetId
1377  *
1378  * Description      This function resets the ble keys such as IRK
1379  *
1380  * Returns          void
1381  *
1382  ******************************************************************************/
1383 void BTA_DmBleResetId(void);
1384 
1385 /*******************************************************************************
1386  *
1387  * Function         BTA_DmBleSubrateRequest
1388  *
1389  * Description      subrate request, can only be used when connection is up.
1390  *
1391  * Parameters:      bd_addr       - BD address of the peer
1392  *                  subrate_min   - subrate min
1393  *                  subrate_max   - subrate max
1394  *                  max_latency   - max latency
1395  *                  cont_num      - continuation number
1396  *                  timeout       - supervision timeout
1397  *
1398  * Returns          void
1399  *
1400  ******************************************************************************/
1401 void BTA_DmBleSubrateRequest(const RawAddress& bd_addr, uint16_t subrate_min,
1402                              uint16_t subrate_max, uint16_t max_latency,
1403                              uint16_t cont_num, uint16_t timeout);
1404 
1405 /*******************************************************************************
1406  *
1407  * Function         BTA_DmCheckLeAudioCapable
1408  *
1409  * Description      Checks if device should be considered as LE Audio capable
1410  *
1411  * Returns          True if Le Audio capable device, false otherwise
1412  *
1413  ******************************************************************************/
1414 bool BTA_DmCheckLeAudioCapable(const RawAddress& address);
1415 
1416 void DumpsysBtaDm(int fd);
1417 
1418 #endif /* BTA_API_H */
1419