• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Linux Foundation
3  * Copyright (C) 2012 The Android Open Source Project
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 #ifndef ANDROID_INCLUDE_BLUETOOTH_H
19 #define ANDROID_INCLUDE_BLUETOOTH_H
20 
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <sys/cdefs.h>
24 #include <sys/types.h>
25 
26 #include "avrcp/avrcp.h"
27 #include "base/functional/callback.h"
28 #include "bluetooth/uuid.h"
29 #include "bt_transport.h"
30 #include "raw_address.h"
31 
32 /**
33  * The Bluetooth Hardware Module ID
34  */
35 
36 #define BT_HARDWARE_MODULE_ID "bluetooth"
37 #define BT_STACK_MODULE_ID "bluetooth"
38 
39 /** Bluetooth profile interface IDs */
40 #define BT_PROFILE_HANDSFREE_ID "handsfree"
41 #define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
42 #define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
43 #define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
44 #define BT_PROFILE_SOCKETS_ID "socket"
45 #define BT_PROFILE_HIDHOST_ID "hidhost"
46 #define BT_PROFILE_HIDDEV_ID "hiddev"
47 #define BT_PROFILE_PAN_ID "pan"
48 #define BT_PROFILE_MAP_CLIENT_ID "map_client"
49 #define BT_PROFILE_SDP_CLIENT_ID "sdp"
50 #define BT_PROFILE_GATT_ID "gatt"
51 #define BT_PROFILE_AV_RC_ID "avrcp"
52 #define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
53 #define BT_PROFILE_HEARING_AID_ID "hearing_aid"
54 #define BT_PROFILE_HAP_CLIENT_ID "has_client"
55 #define BT_PROFILE_LE_AUDIO_ID "le_audio"
56 #define BT_KEYSTORE_ID "bluetooth_keystore"
57 #define BT_ACTIVITY_ATTRIBUTION_ID "activity_attribution"
58 #define BT_PROFILE_VC_ID "volume_control"
59 #define BT_PROFILE_CSIS_CLIENT_ID "csis_client"
60 #define BT_PROFILE_LE_AUDIO_ID "le_audio"
61 #define BT_PROFILE_LE_AUDIO_BROADCASTER_ID "le_audio_broadcaster"
62 #define BT_BQR_ID "bqr"
63 
64 /** Bluetooth Device Name */
65 typedef struct { uint8_t name[249]; } __attribute__((packed)) bt_bdname_t;
66 
67 /** Bluetooth Adapter Visibility Modes*/
68 typedef enum {
69   BT_SCAN_MODE_NONE,
70   BT_SCAN_MODE_CONNECTABLE,
71   BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE,
72   BT_SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE
73 } bt_scan_mode_t;
74 
75 /** Bluetooth Adapter State */
76 typedef enum { BT_STATE_OFF, BT_STATE_ON } bt_state_t;
77 
78 /** Bluetooth Adapter Input Output Capabilities which determine Pairing/Security
79  */
80 typedef enum {
81   BT_IO_CAP_OUT,    /* DisplayOnly */
82   BT_IO_CAP_IO,     /* DisplayYesNo */
83   BT_IO_CAP_IN,     /* KeyboardOnly */
84   BT_IO_CAP_NONE,   /* NoInputNoOutput */
85   BT_IO_CAP_KBDISP, /* Keyboard display */
86   BT_IO_CAP_MAX,
87   BT_IO_CAP_UNKNOWN = 0xFF /* Unknown value */
88 } bt_io_cap_t;
89 
90 /** Bluetooth Error Status */
91 /** We need to build on this */
92 
93 typedef enum {
94   BT_STATUS_SUCCESS = 0,
95   BT_STATUS_FAIL,
96   BT_STATUS_NOT_READY,
97   BT_STATUS_NOMEM,
98   BT_STATUS_BUSY, /* retryable error */
99   BT_STATUS_DONE, /* request already completed */
100   BT_STATUS_UNSUPPORTED,
101   BT_STATUS_PARM_INVALID,
102   BT_STATUS_UNHANDLED,
103   BT_STATUS_AUTH_FAILURE,
104   BT_STATUS_RMT_DEV_DOWN,
105   BT_STATUS_AUTH_REJECTED,
106   BT_STATUS_JNI_ENVIRONMENT_ERROR,
107   BT_STATUS_JNI_THREAD_ATTACH_ERROR,
108   BT_STATUS_WAKELOCK_ERROR
109 } bt_status_t;
110 
bt_status_text(const bt_status_t & status)111 inline std::string bt_status_text(const bt_status_t& status) {
112   switch (status) {
113     case BT_STATUS_SUCCESS:
114       return std::string("success");
115     case BT_STATUS_FAIL:
116       return std::string("fail");
117     case BT_STATUS_NOT_READY:
118       return std::string("not_ready");
119     case BT_STATUS_NOMEM:
120       return std::string("no_memory");
121     case BT_STATUS_BUSY:
122       return std::string("busy");
123     case BT_STATUS_DONE:
124       return std::string("already_done");
125     case BT_STATUS_UNSUPPORTED:
126       return std::string("unsupported");
127     case BT_STATUS_PARM_INVALID:
128       return std::string("parameter_invalid");
129     case BT_STATUS_UNHANDLED:
130       return std::string("unhandled");
131     case BT_STATUS_AUTH_FAILURE:
132       return std::string("failure");
133     case BT_STATUS_RMT_DEV_DOWN:
134       return std::string("remote_device_down");
135     case BT_STATUS_AUTH_REJECTED:
136       return std::string("rejected");
137     case BT_STATUS_JNI_ENVIRONMENT_ERROR:
138       return std::string("jni_env_error");
139     case BT_STATUS_JNI_THREAD_ATTACH_ERROR:
140       return std::string("jni_thread_error");
141     case BT_STATUS_WAKELOCK_ERROR:
142       return std::string("wakelock_error");
143     default:
144       return std::string("UNKNOWN");
145   }
146 }
147 
148 /** Bluetooth HCI Error Codes */
149 /** Corresponding to [Vol 2] Part D, "Error Codes" of Core_v5.1 specs */
150 typedef uint8_t bt_hci_error_code_t;
151 
152 /** Bluetooth PinKey Code */
153 typedef struct { uint8_t pin[16]; } __attribute__((packed)) bt_pin_code_t;
154 
155 typedef struct {
156   uint8_t status;
157   uint8_t ctrl_state;   /* stack reported state */
158   uint64_t tx_time;     /* in ms */
159   uint64_t rx_time;     /* in ms */
160   uint64_t idle_time;   /* in ms */
161   uint64_t energy_used; /* a product of mA, V and ms */
162 } __attribute__((packed)) bt_activity_energy_info;
163 
164 typedef struct {
165   int32_t app_uid;
166   uint64_t tx_bytes;
167   uint64_t rx_bytes;
168 } __attribute__((packed)) bt_uid_traffic_t;
169 
170 /** Bluetooth Adapter Discovery state */
171 typedef enum {
172   BT_DISCOVERY_STOPPED,
173   BT_DISCOVERY_STARTED
174 } bt_discovery_state_t;
175 
176 /** Bluetooth ACL connection state */
177 typedef enum {
178   BT_ACL_STATE_CONNECTED,
179   BT_ACL_STATE_DISCONNECTED
180 } bt_acl_state_t;
181 
182 /** Bluetooth ACL connection direction */
183 typedef enum {
184   BT_CONN_DIRECTION_UNKNOWN,
185   BT_CONN_DIRECTION_OUTGOING,
186   BT_CONN_DIRECTION_INCOMING
187 } bt_conn_direction_t;
188 
189 constexpr uint16_t INVALID_ACL_HANDLE = 0xFFFF;
190 
191 /** Bluetooth SDP service record */
192 typedef struct {
193   bluetooth::Uuid uuid;
194   uint16_t channel;
195   char name[256];  // what's the maximum length
196 } bt_service_record_t;
197 
198 /** Bluetooth Remote Version info */
199 typedef struct {
200   int version;
201   int sub_ver;
202   int manufacturer;
203 } bt_remote_version_t;
204 
205 typedef struct {
206   uint16_t version_supported;
207   uint8_t local_privacy_enabled;
208   uint8_t max_adv_instance;
209   uint8_t rpa_offload_supported;
210   uint8_t max_irk_list_size;
211   uint8_t max_adv_filter_supported;
212   uint8_t activity_energy_info_supported;
213   uint16_t scan_result_storage_size;
214   uint16_t total_trackable_advertisers;
215   bool extended_scan_support;
216   bool debug_logging_supported;
217   bool le_2m_phy_supported;
218   bool le_coded_phy_supported;
219   bool le_extended_advertising_supported;
220   bool le_periodic_advertising_supported;
221   uint16_t le_maximum_advertising_data_length;
222   uint32_t dynamic_audio_buffer_supported;
223   bool le_periodic_advertising_sync_transfer_sender_supported;
224   bool le_connected_isochronous_stream_central_supported;
225   bool le_isochronous_broadcast_supported;
226   bool le_periodic_advertising_sync_transfer_recipient_supported;
227   uint16_t adv_filter_extended_features_mask;
228 } bt_local_le_features_t;
229 
230 /** Bluetooth Vendor and Product ID info */
231 typedef struct {
232   uint8_t vendor_id_src;
233   uint16_t vendor_id;
234   uint16_t product_id;
235   uint16_t version;
236 } bt_vendor_product_info_t;
237 
238 /* Stored the default/maximum/minimum buffer time for dynamic audio buffer.
239  * For A2DP offload usage, the unit is millisecond.
240  * For A2DP legacy usage, the unit is buffer queue size*/
241 typedef struct {
242   uint16_t default_buffer_time;
243   uint16_t maximum_buffer_time;
244   uint16_t minimum_buffer_time;
245 } bt_dynamic_audio_buffer_type_t;
246 
247 typedef struct {
248   bt_dynamic_audio_buffer_type_t dab_item[32];
249 } bt_dynamic_audio_buffer_item_t;
250 
251 /* Bluetooth Adapter and Remote Device property types */
252 typedef enum {
253   /* Properties common to both adapter and remote device */
254   /**
255    * Description - Bluetooth Device Name
256    * Access mode - Adapter name can be GET/SET. Remote device can be GET
257    * Data type   - bt_bdname_t
258    */
259   BT_PROPERTY_BDNAME = 0x1,
260   /**
261    * Description - Bluetooth Device Address
262    * Access mode - Only GET.
263    * Data type   - RawAddress
264    */
265   BT_PROPERTY_BDADDR,
266   /**
267    * Description - Bluetooth Service 128-bit UUIDs
268    * Access mode - Only GET.
269    * Data type   - Array of bluetooth::Uuid (Array size inferred from property
270    *               length).
271    */
272   BT_PROPERTY_UUIDS,
273   /**
274    * Description - Bluetooth Class of Device as found in Assigned Numbers
275    * Access mode - Only GET.
276    * Data type   - uint32_t.
277    */
278   BT_PROPERTY_CLASS_OF_DEVICE,
279   /**
280    * Description - Device Type - BREDR, BLE or DUAL Mode
281    * Access mode - Only GET.
282    * Data type   - bt_device_type_t
283    */
284   BT_PROPERTY_TYPE_OF_DEVICE,
285   /**
286    * Description - Bluetooth Service Record
287    * Access mode - Only GET.
288    * Data type   - bt_service_record_t
289    */
290   BT_PROPERTY_SERVICE_RECORD,
291 
292   /* Properties unique to adapter */
293   /**
294    * Description - Bluetooth Adapter scan mode
295    * Access mode - GET and SET
296    * Data type   - bt_scan_mode_t.
297    */
298   BT_PROPERTY_ADAPTER_SCAN_MODE,
299   /**
300    * Description - List of bonded devices
301    * Access mode - Only GET.
302    * Data type   - Array of RawAddress of the bonded remote devices
303    *               (Array size inferred from property length).
304    */
305   BT_PROPERTY_ADAPTER_BONDED_DEVICES,
306   /**
307    * Description - Bluetooth Adapter Discoverable timeout (in seconds)
308    * Access mode - GET and SET
309    * Data type   - uint32_t
310    */
311   BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT,
312 
313   /* Properties unique to remote device */
314   /**
315    * Description - User defined friendly name of the remote device
316    * Access mode - GET and SET
317    * Data type   - bt_bdname_t.
318    */
319   BT_PROPERTY_REMOTE_FRIENDLY_NAME,
320   /**
321    * Description - RSSI value of the inquired remote device
322    * Access mode - Only GET.
323    * Data type   - int8_t.
324    */
325   BT_PROPERTY_REMOTE_RSSI,
326   /**
327    * Description - Remote version info
328    * Access mode - SET/GET.
329    * Data type   - bt_remote_version_t.
330    */
331 
332   BT_PROPERTY_REMOTE_VERSION_INFO,
333 
334   /**
335    * Description - Local LE features
336    * Access mode - GET.
337    * Data type   - bt_local_le_features_t.
338    */
339   BT_PROPERTY_LOCAL_LE_FEATURES,
340 
341   /**
342    * Description - Local Input/Output Capabilities for classic Bluetooth
343    * Access mode - GET and SET
344    * Data Type - bt_io_cap_t.
345    */
346   BT_PROPERTY_LOCAL_IO_CAPS,
347 
348   BT_PROPERTY_RESERVED_0F,
349 
350   BT_PROPERTY_DYNAMIC_AUDIO_BUFFER,
351 
352   /**
353    * Description - True if Remote is a Member of a Coordinated Set.
354    * Access mode - GET.
355    * Data Type - bool.
356    */
357   BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER,
358 
359   /**
360    * Description - Appearance as specified in Assigned Numbers.
361    * Access mode - GET.
362    * Data Type - uint16_t.
363    */
364   BT_PROPERTY_APPEARANCE,
365 
366   /**
367    * Description - Peer devices' vendor and product ID.
368    * Access mode - GET.
369    * Data Type - bt_vendor_product_info_t.
370    */
371   BT_PROPERTY_VENDOR_PRODUCT_INFO,
372   BT_PROPERTY_WL_MEDIA_PLAYERS_LIST,
373 
374   /**
375    * Description - ASHA capability.
376    * Access mode - GET.
377    * Data Type - int16_t.
378    */
379   BT_PROPERTY_REMOTE_ASHA_CAPABILITY,
380 
381   /**
382    * Description - ASHA truncated HiSyncID.
383    * Access mode - GET.
384    * Data Type - uint32_t.
385    */
386   BT_PROPERTY_REMOTE_ASHA_TRUNCATED_HISYNCID,
387 
388   /**
389    * Description - Model name read from Device Information Service(DIS).
390    * Access mode - GET and SET.
391    * Data Type - char array.
392    */
393   BT_PROPERTY_REMOTE_MODEL_NUM,
394 
395   BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
396 } bt_property_type_t;
397 
398 /** Bluetooth Adapter Property data structure */
399 typedef struct {
400   bt_property_type_t type;
401   int len;
402   void* val;
403 } bt_property_t;
404 
405 // OOB_ADDRESS_SIZE is 6 bytes address + 1 byte address type
406 #define OOB_ADDRESS_SIZE 7
407 #define OOB_C_SIZE 16
408 #define OOB_R_SIZE 16
409 #define OOB_NAME_MAX_SIZE 256
410 // Classic
411 #define OOB_DATA_LEN_SIZE 2
412 #define OOB_COD_SIZE 3
413 // LE
414 #define OOB_TK_SIZE 16
415 #define OOB_LE_FLAG_SIZE 1
416 #define OOB_LE_ROLE_SIZE 1
417 #define OOB_LE_APPEARANCE_SIZE 2
418 /** Represents the actual Out of Band data itself */
419 typedef struct bt_oob_data_s {
420   // Both
421   bool is_valid = false; /* Default to invalid data; force caller to verify */
422   uint8_t address[OOB_ADDRESS_SIZE];
423   uint8_t c[OOB_C_SIZE];      /* Simple Pairing Hash C-192/256 (Classic or LE) */
424   uint8_t r[OOB_R_SIZE];      /* Simple Pairing Randomizer R-192/256 (Classic or LE) */
425   uint8_t device_name[OOB_NAME_MAX_SIZE]; /* Name of the device */
426 
427   // Classic
428   uint8_t oob_data_length[OOB_DATA_LEN_SIZE]; /* Classic only data Length. Value includes this
429                                                  in length */
430   uint8_t class_of_device[OOB_COD_SIZE]; /* Class of Device (Classic or LE) */
431 
432   // LE
433   uint8_t le_device_role;   /* Supported and preferred role of device */
434   uint8_t sm_tk[OOB_TK_SIZE];        /* Security Manager TK Value (LE Only) */
435   uint8_t le_flags;         /* LE Flags for discoverability and features */
436   uint8_t le_appearance[OOB_LE_APPEARANCE_SIZE]; /* For the appearance of the device */
437 } bt_oob_data_t;
438 
439 /** Bluetooth Device Type */
440 typedef enum {
441   BT_DEVICE_DEVTYPE_BREDR = 0x1,
442   BT_DEVICE_DEVTYPE_BLE,
443   BT_DEVICE_DEVTYPE_DUAL
444 } bt_device_type_t;
445 
446 /** Bluetooth Bond state */
447 typedef enum {
448   BT_BOND_STATE_NONE,
449   BT_BOND_STATE_BONDING,
450   BT_BOND_STATE_BONDED
451 } bt_bond_state_t;
452 
453 /** Bluetooth SSP Bonding Variant */
454 typedef enum {
455   BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
456   BT_SSP_VARIANT_PASSKEY_ENTRY,
457   BT_SSP_VARIANT_CONSENT,
458   BT_SSP_VARIANT_PASSKEY_NOTIFICATION
459 } bt_ssp_variant_t;
460 
461 #define BT_MAX_NUM_UUIDS 32
462 
463 /** Bluetooth Interface callbacks */
464 
465 /** Bluetooth Enable/Disable Callback. */
466 typedef void (*adapter_state_changed_callback)(bt_state_t state);
467 
468 /** GET/SET Adapter Properties callback */
469 /* TODO: For the GET/SET property APIs/callbacks, we may need a session
470  * identifier to associate the call with the callback. This would be needed
471  * whenever more than one simultaneous instance of the same adapter_type
472  * is get/set.
473  *
474  * If this is going to be handled in the Java framework, then we do not need
475  * to manage sessions here.
476  */
477 typedef void (*adapter_properties_callback)(bt_status_t status,
478                                             int num_properties,
479                                             bt_property_t* properties);
480 
481 /** GET/SET Remote Device Properties callback */
482 /** TODO: For remote device properties, do not see a need to get/set
483  * multiple properties - num_properties shall be 1
484  */
485 typedef void (*remote_device_properties_callback)(bt_status_t status,
486                                                   RawAddress* bd_addr,
487                                                   int num_properties,
488                                                   bt_property_t* properties);
489 
490 /** New device discovered callback */
491 /** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1
492  * respectively */
493 typedef void (*device_found_callback)(int num_properties,
494                                       bt_property_t* properties);
495 
496 /** Discovery state changed callback */
497 typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state);
498 
499 /** Bluetooth Legacy PinKey Request callback */
500 typedef void (*pin_request_callback)(RawAddress* remote_bd_addr,
501                                      bt_bdname_t* bd_name, uint32_t cod,
502                                      bool min_16_digit);
503 
504 /** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
505 /** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT &
506  *  BT_SSP_PAIRING_PASSKEY_ENTRY */
507 /* TODO: Passkey request callback shall not be needed for devices with display
508  * capability. We still need support this in the stack for completeness */
509 typedef void (*ssp_request_callback)(RawAddress* remote_bd_addr,
510                                      bt_bdname_t* bd_name, uint32_t cod,
511                                      bt_ssp_variant_t pairing_variant,
512                                      uint32_t pass_key);
513 
514 /** Bluetooth Bond state changed callback */
515 /* Invoked in response to create_bond, cancel_bond or remove_bond */
516 typedef void (*bond_state_changed_callback)(bt_status_t status,
517                                             RawAddress* remote_bd_addr,
518                                             bt_bond_state_t state,
519                                             int fail_reason);
520 
521 /** Bluetooth Address consolidate callback */
522 /* Callback to inform upper layer that these two addresses come from same
523  * bluetooth device (DUAL mode) */
524 typedef void (*address_consolidate_callback)(RawAddress* main_bd_addr,
525                                              RawAddress* secondary_bd_addr);
526 
527 /** Bluetooth LE Address association callback */
528 /* Callback for the upper layer to associate the LE-only device's RPA to the
529  * identity address */
530 typedef void (*le_address_associate_callback)(RawAddress* main_bd_addr,
531                                               RawAddress* secondary_bd_addr);
532 
533 /** Bluetooth ACL connection state changed callback */
534 typedef void (*acl_state_changed_callback)(
535     bt_status_t status, RawAddress* remote_bd_addr, bt_acl_state_t state,
536     int transport_link_type, bt_hci_error_code_t hci_reason,
537     bt_conn_direction_t direction, uint16_t acl_handle);
538 
539 /** Bluetooth link quality report callback */
540 typedef void (*link_quality_report_callback)(
541     uint64_t timestamp, int report_id, int rssi, int snr,
542     int retransmission_count, int packets_not_receive_count,
543     int negative_acknowledgement_count);
544 
545 /** Switch the buffer size callback */
546 typedef void (*switch_buffer_size_callback)(bool is_low_latency_buffer_size);
547 
548 /** Switch the codec callback */
549 typedef void (*switch_codec_callback)(bool is_low_latency_buffer_size);
550 
551 typedef void (*le_rand_callback)(uint64_t random);
552 
553 typedef enum { ASSOCIATE_JVM, DISASSOCIATE_JVM } bt_cb_thread_evt;
554 
555 /** Thread Associate/Disassociate JVM Callback */
556 /* Callback that is invoked by the callback thread to allow upper layer to
557  * attach/detach to/from the JVM */
558 typedef void (*callback_thread_event)(bt_cb_thread_evt evt);
559 
560 /** Callback invoked when energy details are obtained */
561 /* Ctrl_state-Current controller state-Active-1,scan-2,or idle-3 state as
562  * defined by HCI spec. If the ctrl_state value is 0, it means the API call
563  * failed Time values-In milliseconds as returned by the controller Energy
564  * used-Value as returned by the controller Status-Provides the status of the
565  * read_energy_info API call uid_data provides an array of bt_uid_traffic_t,
566  * where the array is terminated by an element with app_uid set to -1.
567  */
568 typedef void (*energy_info_callback)(bt_activity_energy_info* energy_info,
569                                      bt_uid_traffic_t* uid_data);
570 
571 /** Callback invoked when OOB data is returned from the controller */
572 typedef void (*generate_local_oob_data_callback)(tBT_TRANSPORT transport,
573                                                  bt_oob_data_t oob_data);
574 
575 /** TODO: Add callbacks for Link Up/Down and other generic
576  *  notifications/callbacks */
577 
578 /** Bluetooth DM callback structure. */
579 typedef struct {
580   /** set to sizeof(bt_callbacks_t) */
581   size_t size;
582   adapter_state_changed_callback adapter_state_changed_cb;
583   adapter_properties_callback adapter_properties_cb;
584   remote_device_properties_callback remote_device_properties_cb;
585   device_found_callback device_found_cb;
586   discovery_state_changed_callback discovery_state_changed_cb;
587   pin_request_callback pin_request_cb;
588   ssp_request_callback ssp_request_cb;
589   bond_state_changed_callback bond_state_changed_cb;
590   address_consolidate_callback address_consolidate_cb;
591   le_address_associate_callback le_address_associate_cb;
592   acl_state_changed_callback acl_state_changed_cb;
593   callback_thread_event thread_evt_cb;
594   energy_info_callback energy_info_cb;
595   link_quality_report_callback link_quality_report_cb;
596   generate_local_oob_data_callback generate_local_oob_data_cb;
597   switch_buffer_size_callback switch_buffer_size_cb;
598   switch_codec_callback switch_codec_cb;
599   le_rand_callback le_rand_cb;
600 } bt_callbacks_t;
601 
602 typedef void (*alarm_cb)(void* data);
603 typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake,
604                                        alarm_cb cb, void* data);
605 typedef int (*acquire_wake_lock_callout)(const char* lock_name);
606 typedef int (*release_wake_lock_callout)(const char* lock_name);
607 
608 /** The set of functions required by bluedroid to set wake alarms and
609  * grab wake locks. This struct is passed into the stack through the
610  * |set_os_callouts| function on |bt_interface_t|.
611  */
612 typedef struct {
613   /* set to sizeof(bt_os_callouts_t) */
614   size_t size;
615 
616   set_wake_alarm_callout set_wake_alarm;
617   acquire_wake_lock_callout acquire_wake_lock;
618   release_wake_lock_callout release_wake_lock;
619 } bt_os_callouts_t;
620 
621 /** NOTE: By default, no profiles are initialized at the time of init/enable.
622  *  Whenever the application invokes the 'init' API of a profile, then one of
623  *  the following shall occur:
624  *
625  *    1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
626  *        profile as enabled. Subsequently, when the application invokes the
627  *        Bluetooth 'enable', as part of the enable sequence the profile that
628  * were marked shall be enabled by calling appropriate stack APIs. The
629  *        'adapter_properties_cb' shall return the list of UUIDs of the
630  *        enabled profiles.
631  *
632  *    2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the
633  * stack profile API to initialize the profile and trigger a
634  *        'adapter_properties_cb' with the current list of UUIDs including the
635  *        newly added profile's UUID.
636  *
637  *   The reverse shall occur whenever the profile 'cleanup' APIs are invoked
638  */
639 
640 /** Represents the standard Bluetooth DM interface. */
641 typedef struct {
642   /** set to sizeof(bt_interface_t) */
643   size_t size;
644   /**
645    * Opens the interface and provides the callback routines
646    * to the implemenation of this interface.
647    * The |start_restricted| flag inits the adapter in restricted mode. In
648    * restricted mode, bonds that are created are marked as restricted in the
649    * config file. These devices are deleted upon leaving restricted mode.
650    * The |is_common_criteria_mode| flag inits the adapter in commom criteria
651    * mode. The |config_compare_result| flag show the config checksum check
652    * result if is in common criteria mode. The |init_flags| are config flags
653    * that cannot change during run. The |is_atv| flag indicates whether the
654    * local device is an Android TV
655    */
656   int (*init)(bt_callbacks_t* callbacks, bool guest_mode,
657               bool is_common_criteria_mode, int config_compare_result,
658               const char** init_flags, bool is_atv,
659               const char* user_data_directory);
660 
661   /** Enable Bluetooth. */
662   int (*enable)();
663 
664   /** Disable Bluetooth. */
665   int (*disable)(void);
666 
667   /** Closes the interface. */
668   void (*cleanup)(void);
669 
670   /** Get all Bluetooth Adapter properties at init */
671   int (*get_adapter_properties)(void);
672 
673   /** Get Bluetooth Adapter property of 'type' */
674   int (*get_adapter_property)(bt_property_type_t type);
675 
676   /** Set Bluetooth Adapter property of 'type' */
677   /* Based on the type, val shall be one of
678    * RawAddress or bt_bdname_t or bt_scanmode_t etc
679    */
680   int (*set_adapter_property)(const bt_property_t* property);
681 
682   /** Get all Remote Device properties */
683   int (*get_remote_device_properties)(RawAddress* remote_addr);
684 
685   /** Get Remote Device property of 'type' */
686   int (*get_remote_device_property)(RawAddress* remote_addr,
687                                     bt_property_type_t type);
688 
689   /** Set Remote Device property of 'type' */
690   int (*set_remote_device_property)(RawAddress* remote_addr,
691                                     const bt_property_t* property);
692 
693   /** Get Remote Device's service record  for the given UUID */
694   int (*get_remote_service_record)(const RawAddress& remote_addr,
695                                    const bluetooth::Uuid& uuid);
696 
697   /** Start service discovery with tranport to get remote services */
698   int (*get_remote_services)(RawAddress* remote_addr, int transport);
699 
700   /** Start Discovery */
701   int (*start_discovery)(void);
702 
703   /** Cancel Discovery */
704   int (*cancel_discovery)(void);
705 
706   /** Create Bluetooth Bonding */
707   int (*create_bond)(const RawAddress* bd_addr, int transport);
708 
709   /** Create Bluetooth Bonding over le transport */
710   int (*create_bond_le)(const RawAddress* bd_addr, uint8_t addr_type);
711 
712   /** Create Bluetooth Bond using out of band data */
713   int (*create_bond_out_of_band)(const RawAddress* bd_addr, int transport,
714                                  const bt_oob_data_t* p192_data,
715                                  const bt_oob_data_t* p256_data);
716 
717   /** Remove Bond */
718   int (*remove_bond)(const RawAddress* bd_addr);
719 
720   /** Cancel Bond */
721   int (*cancel_bond)(const RawAddress* bd_addr);
722 
723   /**
724    * Get the connection status for a given remote device.
725    * return value of 0 means the device is not connected,
726    * non-zero return status indicates an active connection.
727    */
728   int (*get_connection_state)(const RawAddress* bd_addr);
729 
730   /** BT Legacy PinKey Reply */
731   /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
732   int (*pin_reply)(const RawAddress* bd_addr, uint8_t accept, uint8_t pin_len,
733                    bt_pin_code_t* pin_code);
734 
735   /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
736    * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
737    * BT_SSP_VARIANT_CONSENT
738    * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
739    * shall be zero */
740   int (*ssp_reply)(const RawAddress* bd_addr, bt_ssp_variant_t variant,
741                    uint8_t accept, uint32_t passkey);
742 
743   /** Get Bluetooth profile interface */
744   const void* (*get_profile_interface)(const char* profile_id);
745 
746   /** Sets the OS call-out functions that bluedroid needs for alarms and wake
747    * locks. This should be called immediately after a successful |init|.
748    */
749   int (*set_os_callouts)(bt_os_callouts_t* callouts);
750 
751   /** Read Energy info details - return value indicates BT_STATUS_SUCCESS or
752    * BT_STATUS_NOT_READY Success indicates that the VSC command was sent to
753    * controller
754    */
755   int (*read_energy_info)();
756 
757   /**
758    * Native support for dumpsys function
759    * Function is synchronous and |fd| is owned by caller.
760    * |arguments| are arguments which may affect the output, encoded as
761    * UTF-8 strings.
762    */
763   void (*dump)(int fd, const char** arguments);
764 
765   /**
766    * Native support for metrics protobuf dumping. The dumping format will be
767    * raw byte array
768    *
769    * @param output an externally allocated string to dump serialized protobuf
770    */
771   void (*dumpMetrics)(std::string* output);
772 
773   /**
774    * Clear /data/misc/bt_config.conf and erase all stored connections
775    */
776   int (*config_clear)(void);
777 
778   /**
779    * Clear (reset) the dynamic portion of the device interoperability database.
780    */
781   void (*interop_database_clear)(void);
782 
783   /**
784    * Add a new device interoperability workaround for a remote device whose
785    * first |len| bytes of the its device address match |addr|.
786    * NOTE: |feature| has to match an item defined in interop_feature_t
787    * (interop.h).
788    */
789   void (*interop_database_add)(uint16_t feature, const RawAddress* addr,
790                                size_t len);
791 
792   /**
793    * Get the AvrcpTarget Service interface to interact with the Avrcp Service
794    */
795   bluetooth::avrcp::ServiceInterface* (*get_avrcp_service)(void);
796 
797   /**
798    * Obfuscate Bluetooth MAC address into a PII free ID string
799    *
800    * @param address Bluetooth MAC address to be obfuscated
801    * @return a string of uint8_t that is unique to this MAC address
802    */
803   std::string (*obfuscate_address)(const RawAddress& address);
804 
805   /**
806    * Get an incremental id for as primary key for Bluetooth metric and log
807    *
808    * @param address Bluetooth MAC address of Bluetooth device
809    * @return int incremental Bluetooth id
810    */
811   int (*get_metric_id)(const RawAddress& address);
812 
813   /**
814    * Set the dynamic audio buffer size to the Controller
815    */
816   int (*set_dynamic_audio_buffer_size)(int codec, int size);
817 
818   /**
819    * Fetches the local Out of Band data.
820    */
821   int (*generate_local_oob_data)(tBT_TRANSPORT transport);
822 
823   /**
824    * Allow or disallow audio low latency
825    *
826    * @param allowed true if allowing audio low latency
827    * @param address Bluetooth MAC address of Bluetooth device
828    * @return true if audio low latency is successfully allowed or disallowed
829    */
830   bool (*allow_low_latency_audio)(bool allowed, const RawAddress& address);
831 
832   /**
833    * Set the event filter for the controller
834    */
835   int (*clear_event_filter)();
836 
837   /**
838    * Call to clear event mask
839    */
840   int (*clear_event_mask)();
841 
842   /**
843    * Call to clear out the filter accept list
844    */
845   int (*clear_filter_accept_list)();
846 
847   /**
848    * Call to disconnect all ACL connections
849    */
850   int (*disconnect_all_acls)();
851 
852   /**
853    * Call to retrieve a generated random
854    */
855   int (*le_rand)();
856 
857   /**
858    *
859    * Floss: Set the event filter to inquiry result device all
860    *
861    */
862   int (*set_event_filter_inquiry_result_all_devices)();
863 
864   /**
865    *
866    * Floss: Set the default event mask for Classic and LE except the given
867    *        values (they will be disabled in the final set mask).
868    *
869    */
870   int (*set_default_event_mask_except)(uint64_t mask, uint64_t le_mask);
871 
872   /**
873    *
874    * Floss: Restore the state of the for the filter accept list
875    *
876    */
877   int (*restore_filter_accept_list)();
878 
879   /**
880    *
881    * Allow the device to be woken by HID devices
882    *
883    */
884   int (*allow_wake_by_hid)();
885 
886   /**
887    *
888    * Tell the controller to allow all devices
889    *
890    */
891   int (*set_event_filter_connection_setup_all_devices)();
892 
893   /**
894    *
895    * Is wbs supported by the controller
896    *
897    */
898   bool (*get_wbs_supported)();
899 
900   /**
901    *
902    * Is swb supported by the controller
903    *
904    */
905   bool (*get_swb_supported)();
906 
907   /**
908    * Data passed from BluetoothDevice.metadata_changed
909    *
910    * @param remote_bd_addr remote address
911    * @param key Metadata key
912    * @param value Metadata value
913    */
914   void (*metadata_changed)(const RawAddress& remote_bd_addr, int key,
915                            std::vector<uint8_t> value);
916 
917   /** interop match address */
918   bool (*interop_match_addr)(const char* feature_name, const RawAddress* addr);
919 
920   /** interop match name */
921   bool (*interop_match_name)(const char* feature_name, const char* name);
922 
923   /** interop match address or name */
924   bool (*interop_match_addr_or_name)(const char* feature_name,
925                                      const RawAddress* addr);
926 
927   /** add or remove address entry to interop database */
928   void (*interop_database_add_remove_addr)(bool do_add,
929                                            const char* feature_name,
930                                            const RawAddress* addr, int length);
931 
932   /** add or remove name entry to interop database */
933   void (*interop_database_add_remove_name)(bool do_add,
934                                            const char* feature_name,
935                                            const char* name);
936 
937   /** get remote Pbap PCE  version*/
938   int (*get_remote_pbap_pce_version)(const RawAddress* bd_addr);
939 
940   /** check if pbap pse dynamic version upgrade is enable */
941   bool (*pbap_pse_dynamic_version_upgrade_is_enabled)();
942 
943 } bt_interface_t;
944 
945 #define BLUETOOTH_INTERFACE_STRING "bluetoothInterface"
946 
947 #endif /* ANDROID_INCLUDE_BLUETOOTH_H */
948