1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_INCLUDE_BLUETOOTH_H
18 #define ANDROID_INCLUDE_BLUETOOTH_H
19 
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <sys/cdefs.h>
23 #include <sys/types.h>
24 
25 #include "avrcp/avrcp.h"
26 #include "bluetooth/uuid.h"
27 #include "bt_transport.h"
28 #include "raw_address.h"
29 
30 /**
31  * The Bluetooth Hardware Module ID
32  */
33 
34 #define BT_HARDWARE_MODULE_ID "bluetooth"
35 #define BT_STACK_MODULE_ID "bluetooth"
36 
37 /** Bluetooth profile interface IDs */
38 #define BT_PROFILE_HANDSFREE_ID "handsfree"
39 #define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
40 #define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
41 #define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
42 #define BT_PROFILE_SOCKETS_ID "socket"
43 #define BT_PROFILE_HIDHOST_ID "hidhost"
44 #define BT_PROFILE_HIDDEV_ID "hiddev"
45 #define BT_PROFILE_PAN_ID "pan"
46 #define BT_PROFILE_MAP_CLIENT_ID "map_client"
47 #define BT_PROFILE_SDP_CLIENT_ID "sdp"
48 #define BT_PROFILE_GATT_ID "gatt"
49 #define BT_PROFILE_AV_RC_ID "avrcp"
50 #define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
51 #define BT_PROFILE_HEARING_AID_ID "hearing_aid"
52 #define BT_PROFILE_LE_AUDIO_ID "le_audio"
53 #define BT_KEYSTORE_ID "bluetooth_keystore"
54 #define BT_ACTIVITY_ATTRIBUTION_ID "activity_attribution"
55 #define BT_PROFILE_VC_ID "volume_control"
56 
57 /** Bluetooth Device Name */
58 typedef struct { uint8_t name[249]; } __attribute__((packed)) bt_bdname_t;
59 
60 /** Bluetooth Adapter Visibility Modes*/
61 typedef enum {
62   BT_SCAN_MODE_NONE,
63   BT_SCAN_MODE_CONNECTABLE,
64   BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
65 } bt_scan_mode_t;
66 
67 /** Bluetooth Adapter State */
68 typedef enum { BT_STATE_OFF, BT_STATE_ON } bt_state_t;
69 
70 /** Bluetooth Adapter Input Output Capabilities which determine Pairing/Security
71  */
72 typedef enum {
73   BT_IO_CAP_OUT,    /* DisplayOnly */
74   BT_IO_CAP_IO,     /* DisplayYesNo */
75   BT_IO_CAP_IN,     /* KeyboardOnly */
76   BT_IO_CAP_NONE,   /* NoInputNoOutput */
77   BT_IO_CAP_KBDISP, /* Keyboard display */
78   BT_IO_CAP_MAX,
79   BT_IO_CAP_UNKNOWN = 0xFF /* Unknown value */
80 } bt_io_cap_t;
81 
82 /** Bluetooth Error Status */
83 /** We need to build on this */
84 
85 typedef enum {
86   BT_STATUS_SUCCESS = 0,
87   BT_STATUS_FAIL,
88   BT_STATUS_NOT_READY,
89   BT_STATUS_NOMEM,
90   BT_STATUS_BUSY,
91   BT_STATUS_DONE, /* request already completed */
92   BT_STATUS_UNSUPPORTED,
93   BT_STATUS_PARM_INVALID,
94   BT_STATUS_UNHANDLED,
95   BT_STATUS_AUTH_FAILURE,
96   BT_STATUS_RMT_DEV_DOWN,
97   BT_STATUS_AUTH_REJECTED,
98   BT_STATUS_JNI_ENVIRONMENT_ERROR,
99   BT_STATUS_JNI_THREAD_ATTACH_ERROR,
100   BT_STATUS_WAKELOCK_ERROR
101 } bt_status_t;
102 
bt_status_text(const bt_status_t & status)103 inline std::string bt_status_text(const bt_status_t& status) {
104   switch (status) {
105     case BT_STATUS_SUCCESS:
106       return std::string("success");
107     case BT_STATUS_FAIL:
108       return std::string("fail");
109     case BT_STATUS_NOT_READY:
110       return std::string("not_ready");
111     case BT_STATUS_NOMEM:
112       return std::string("no_memory");
113     case BT_STATUS_BUSY:
114       return std::string("busy");
115     case BT_STATUS_DONE:
116       return std::string("already_done");
117     case BT_STATUS_UNSUPPORTED:
118       return std::string("unsupported");
119     case BT_STATUS_PARM_INVALID:
120       return std::string("parameter_invalid");
121     case BT_STATUS_UNHANDLED:
122       return std::string("unhandled");
123     case BT_STATUS_AUTH_FAILURE:
124       return std::string("failure");
125     case BT_STATUS_RMT_DEV_DOWN:
126       return std::string("remote_device_down");
127     case BT_STATUS_AUTH_REJECTED:
128       return std::string("rejected");
129     case BT_STATUS_JNI_ENVIRONMENT_ERROR:
130       return std::string("jni_env_error");
131     case BT_STATUS_JNI_THREAD_ATTACH_ERROR:
132       return std::string("jni_thread_error");
133     case BT_STATUS_WAKELOCK_ERROR:
134       return std::string("wakelock_error");
135     default:
136       return std::string("UNKNOWN");
137   }
138 }
139 
140 /** Bluetooth HCI Error Codes */
141 /** Corresponding to [Vol 2] Part D, "Error Codes" of Core_v5.1 specs */
142 typedef uint8_t bt_hci_error_code_t;
143 
144 /** Bluetooth PinKey Code */
145 typedef struct { uint8_t pin[16]; } __attribute__((packed)) bt_pin_code_t;
146 
147 typedef struct {
148   uint8_t status;
149   uint8_t ctrl_state;   /* stack reported state */
150   uint64_t tx_time;     /* in ms */
151   uint64_t rx_time;     /* in ms */
152   uint64_t idle_time;   /* in ms */
153   uint64_t energy_used; /* a product of mA, V and ms */
154 } __attribute__((packed)) bt_activity_energy_info;
155 
156 typedef struct {
157   int32_t app_uid;
158   uint64_t tx_bytes;
159   uint64_t rx_bytes;
160 } __attribute__((packed)) bt_uid_traffic_t;
161 
162 /** Bluetooth Adapter Discovery state */
163 typedef enum {
164   BT_DISCOVERY_STOPPED,
165   BT_DISCOVERY_STARTED
166 } bt_discovery_state_t;
167 
168 /** Bluetooth ACL connection state */
169 typedef enum {
170   BT_ACL_STATE_CONNECTED,
171   BT_ACL_STATE_DISCONNECTED
172 } bt_acl_state_t;
173 
174 /** Bluetooth SDP service record */
175 typedef struct {
176   bluetooth::Uuid uuid;
177   uint16_t channel;
178   char name[256];  // what's the maximum length
179 } bt_service_record_t;
180 
181 /** Bluetooth Remote Version info */
182 typedef struct {
183   int version;
184   int sub_ver;
185   int manufacturer;
186 } bt_remote_version_t;
187 
188 typedef struct {
189   uint16_t version_supported;
190   uint8_t local_privacy_enabled;
191   uint8_t max_adv_instance;
192   uint8_t rpa_offload_supported;
193   uint8_t max_irk_list_size;
194   uint8_t max_adv_filter_supported;
195   uint8_t activity_energy_info_supported;
196   uint16_t scan_result_storage_size;
197   uint16_t total_trackable_advertisers;
198   bool extended_scan_support;
199   bool debug_logging_supported;
200   bool le_2m_phy_supported;
201   bool le_coded_phy_supported;
202   bool le_extended_advertising_supported;
203   bool le_periodic_advertising_supported;
204   uint16_t le_maximum_advertising_data_length;
205   uint32_t dynamic_audio_buffer_supported;
206 } bt_local_le_features_t;
207 
208 /* Stored the default/maximum/minimum buffer time for dynamic audio buffer.
209  * For A2DP offload usage, the unit is millisecond.
210  * For A2DP legacy usage, the unit is buffer queue size*/
211 typedef struct {
212   uint16_t default_buffer_time;
213   uint16_t maximum_buffer_time;
214   uint16_t minimum_buffer_time;
215 } bt_dynamic_audio_buffer_type_t;
216 
217 typedef struct {
218   bt_dynamic_audio_buffer_type_t dab_item[32];
219 } bt_dynamic_audio_buffer_item_t;
220 
221 /* Bluetooth Adapter and Remote Device property types */
222 typedef enum {
223   /* Properties common to both adapter and remote device */
224   /**
225    * Description - Bluetooth Device Name
226    * Access mode - Adapter name can be GET/SET. Remote device can be GET
227    * Data type   - bt_bdname_t
228    */
229   BT_PROPERTY_BDNAME = 0x1,
230   /**
231    * Description - Bluetooth Device Address
232    * Access mode - Only GET.
233    * Data type   - RawAddress
234    */
235   BT_PROPERTY_BDADDR,
236   /**
237    * Description - Bluetooth Service 128-bit UUIDs
238    * Access mode - Only GET.
239    * Data type   - Array of bluetooth::Uuid (Array size inferred from property
240    *               length).
241    */
242   BT_PROPERTY_UUIDS,
243   /**
244    * Description - Bluetooth Class of Device as found in Assigned Numbers
245    * Access mode - Only GET.
246    * Data type   - uint32_t.
247    */
248   BT_PROPERTY_CLASS_OF_DEVICE,
249   /**
250    * Description - Device Type - BREDR, BLE or DUAL Mode
251    * Access mode - Only GET.
252    * Data type   - bt_device_type_t
253    */
254   BT_PROPERTY_TYPE_OF_DEVICE,
255   /**
256    * Description - Bluetooth Service Record
257    * Access mode - Only GET.
258    * Data type   - bt_service_record_t
259    */
260   BT_PROPERTY_SERVICE_RECORD,
261 
262   /* Properties unique to adapter */
263   /**
264    * Description - Bluetooth Adapter scan mode
265    * Access mode - GET and SET
266    * Data type   - bt_scan_mode_t.
267    */
268   BT_PROPERTY_ADAPTER_SCAN_MODE,
269   /**
270    * Description - List of bonded devices
271    * Access mode - Only GET.
272    * Data type   - Array of RawAddress of the bonded remote devices
273    *               (Array size inferred from property length).
274    */
275   BT_PROPERTY_ADAPTER_BONDED_DEVICES,
276   /**
277    * Description - Bluetooth Adapter Discovery timeout (in seconds)
278    * Access mode - GET and SET
279    * Data type   - uint32_t
280    */
281   BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
282 
283   /* Properties unique to remote device */
284   /**
285    * Description - User defined friendly name of the remote device
286    * Access mode - GET and SET
287    * Data type   - bt_bdname_t.
288    */
289   BT_PROPERTY_REMOTE_FRIENDLY_NAME,
290   /**
291    * Description - RSSI value of the inquired remote device
292    * Access mode - Only GET.
293    * Data type   - int8_t.
294    */
295   BT_PROPERTY_REMOTE_RSSI,
296   /**
297    * Description - Remote version info
298    * Access mode - SET/GET.
299    * Data type   - bt_remote_version_t.
300    */
301 
302   BT_PROPERTY_REMOTE_VERSION_INFO,
303 
304   /**
305    * Description - Local LE features
306    * Access mode - GET.
307    * Data type   - bt_local_le_features_t.
308    */
309   BT_PROPERTY_LOCAL_LE_FEATURES,
310 
311   /**
312    * Description - Local Input/Output Capabilities for classic Bluetooth
313    * Access mode - GET and SET
314    * Data Type - bt_io_cap_t.
315    */
316   BT_PROPERTY_LOCAL_IO_CAPS,
317 
318   /**
319    * Description - Local Input/Output Capabilities for BLE
320    * Access mode - GET and SET
321    * Data Type - bt_io_cap_t.
322    */
323   BT_PROPERTY_LOCAL_IO_CAPS_BLE,
324 
325   BT_PROPERTY_DYNAMIC_AUDIO_BUFFER,
326 
327   BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
328 } bt_property_type_t;
329 
330 /** Bluetooth Adapter Property data structure */
331 typedef struct {
332   bt_property_type_t type;
333   int len;
334   void* val;
335 } bt_property_t;
336 
337 /** Represents the actual Out of Band data itself */
338 typedef struct {
339   // Both
340   bool is_valid = false; /* Default to invalid data; force caller to verify */
341   uint8_t address[7]; /* Bluetooth Device Address (6) plus Address Type (1) */
342   uint8_t c[16];      /* Simple Pairing Hash C-192/256 (Classic or LE) */
343   uint8_t r[16];      /* Simple Pairing Randomizer R-192/256 (Classic or LE) */
344   uint8_t device_name[256]; /* Name of the device */
345 
346   // Classic
347   uint8_t oob_data_length[2]; /* Classic only data Length. Value includes this
348                                  in length */
349   uint8_t class_of_device[2]; /* Class of Device (Classic or LE) */
350 
351   // LE
352   uint8_t le_device_role;   /* Supported and preferred role of device */
353   uint8_t sm_tk[16];        /* Security Manager TK Value (LE Only) */
354   uint8_t le_flags;         /* LE Flags for discoverability and features */
355   uint8_t le_appearance[2]; /* For the appearance of the device */
356 } bt_oob_data_t;
357 
358 /** Bluetooth Device Type */
359 typedef enum {
360   BT_DEVICE_DEVTYPE_BREDR = 0x1,
361   BT_DEVICE_DEVTYPE_BLE,
362   BT_DEVICE_DEVTYPE_DUAL
363 } bt_device_type_t;
364 
365 /** Bluetooth Bond state */
366 typedef enum {
367   BT_BOND_STATE_NONE,
368   BT_BOND_STATE_BONDING,
369   BT_BOND_STATE_BONDED
370 } bt_bond_state_t;
371 
372 /** Bluetooth SSP Bonding Variant */
373 typedef enum {
374   BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
375   BT_SSP_VARIANT_PASSKEY_ENTRY,
376   BT_SSP_VARIANT_CONSENT,
377   BT_SSP_VARIANT_PASSKEY_NOTIFICATION
378 } bt_ssp_variant_t;
379 
380 #define BT_MAX_NUM_UUIDS 32
381 
382 /** Bluetooth Interface callbacks */
383 
384 /** Bluetooth Enable/Disable Callback. */
385 typedef void (*adapter_state_changed_callback)(bt_state_t state);
386 
387 /** GET/SET Adapter Properties callback */
388 /* TODO: For the GET/SET property APIs/callbacks, we may need a session
389  * identifier to associate the call with the callback. This would be needed
390  * whenever more than one simultaneous instance of the same adapter_type
391  * is get/set.
392  *
393  * If this is going to be handled in the Java framework, then we do not need
394  * to manage sessions here.
395  */
396 typedef void (*adapter_properties_callback)(bt_status_t status,
397                                             int num_properties,
398                                             bt_property_t* properties);
399 
400 /** GET/SET Remote Device Properties callback */
401 /** TODO: For remote device properties, do not see a need to get/set
402  * multiple properties - num_properties shall be 1
403  */
404 typedef void (*remote_device_properties_callback)(bt_status_t status,
405                                                   RawAddress* bd_addr,
406                                                   int num_properties,
407                                                   bt_property_t* properties);
408 
409 /** New device discovered callback */
410 /** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1
411  * respectively */
412 typedef void (*device_found_callback)(int num_properties,
413                                       bt_property_t* properties);
414 
415 /** Discovery state changed callback */
416 typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state);
417 
418 /** Bluetooth Legacy PinKey Request callback */
419 typedef void (*pin_request_callback)(RawAddress* remote_bd_addr,
420                                      bt_bdname_t* bd_name, uint32_t cod,
421                                      bool min_16_digit);
422 
423 /** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
424 /** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT &
425  *  BT_SSP_PAIRING_PASSKEY_ENTRY */
426 /* TODO: Passkey request callback shall not be needed for devices with display
427  * capability. We still need support this in the stack for completeness */
428 typedef void (*ssp_request_callback)(RawAddress* remote_bd_addr,
429                                      bt_bdname_t* bd_name, uint32_t cod,
430                                      bt_ssp_variant_t pairing_variant,
431                                      uint32_t pass_key);
432 
433 /** Bluetooth Bond state changed callback */
434 /* Invoked in response to create_bond, cancel_bond or remove_bond */
435 typedef void (*bond_state_changed_callback)(bt_status_t status,
436                                             RawAddress* remote_bd_addr,
437                                             bt_bond_state_t state);
438 
439 /** Bluetooth ACL connection state changed callback */
440 typedef void (*acl_state_changed_callback)(bt_status_t status,
441                                            RawAddress* remote_bd_addr,
442                                            bt_acl_state_t state,
443                                            bt_hci_error_code_t hci_reason);
444 
445 /** Bluetooth link quality report callback */
446 typedef void (*link_quality_report_callback)(
447     uint64_t timestamp, int report_id, int rssi, int snr,
448     int retransmission_count, int packets_not_receive_count,
449     int negative_acknowledgement_count);
450 
451 typedef enum { ASSOCIATE_JVM, DISASSOCIATE_JVM } bt_cb_thread_evt;
452 
453 /** Thread Associate/Disassociate JVM Callback */
454 /* Callback that is invoked by the callback thread to allow upper layer to
455  * attach/detach to/from the JVM */
456 typedef void (*callback_thread_event)(bt_cb_thread_evt evt);
457 
458 /** Bluetooth Test Mode Callback */
459 /* Receive any HCI event from controller. Must be in DUT Mode for this callback
460  * to be received */
461 typedef void (*dut_mode_recv_callback)(uint16_t opcode, uint8_t* buf,
462                                        uint8_t len);
463 
464 /* LE Test mode callbacks
465  * This callback shall be invoked whenever the le_tx_test, le_rx_test or
466  * le_test_end is invoked The num_packets is valid only for le_test_end command
467  */
468 typedef void (*le_test_mode_callback)(bt_status_t status, uint16_t num_packets);
469 
470 /** Callback invoked when energy details are obtained */
471 /* Ctrl_state-Current controller state-Active-1,scan-2,or idle-3 state as
472  * defined by HCI spec. If the ctrl_state value is 0, it means the API call
473  * failed Time values-In milliseconds as returned by the controller Energy
474  * used-Value as returned by the controller Status-Provides the status of the
475  * read_energy_info API call uid_data provides an array of bt_uid_traffic_t,
476  * where the array is terminated by an element with app_uid set to -1.
477  */
478 typedef void (*energy_info_callback)(bt_activity_energy_info* energy_info,
479                                      bt_uid_traffic_t* uid_data);
480 
481 /** Callback invoked when OOB data is returned from the controller */
482 typedef void (*generate_local_oob_data_callback)(tBT_TRANSPORT transport,
483                                                  bt_oob_data_t oob_data);
484 
485 /** TODO: Add callbacks for Link Up/Down and other generic
486  *  notifications/callbacks */
487 
488 /** Bluetooth DM callback structure. */
489 typedef struct {
490   /** set to sizeof(bt_callbacks_t) */
491   size_t size;
492   adapter_state_changed_callback adapter_state_changed_cb;
493   adapter_properties_callback adapter_properties_cb;
494   remote_device_properties_callback remote_device_properties_cb;
495   device_found_callback device_found_cb;
496   discovery_state_changed_callback discovery_state_changed_cb;
497   pin_request_callback pin_request_cb;
498   ssp_request_callback ssp_request_cb;
499   bond_state_changed_callback bond_state_changed_cb;
500   acl_state_changed_callback acl_state_changed_cb;
501   callback_thread_event thread_evt_cb;
502   dut_mode_recv_callback dut_mode_recv_cb;
503   le_test_mode_callback le_test_mode_cb;
504   energy_info_callback energy_info_cb;
505   link_quality_report_callback link_quality_report_cb;
506   generate_local_oob_data_callback generate_local_oob_data_cb;
507 } bt_callbacks_t;
508 
509 typedef void (*alarm_cb)(void* data);
510 typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake,
511                                        alarm_cb cb, void* data);
512 typedef int (*acquire_wake_lock_callout)(const char* lock_name);
513 typedef int (*release_wake_lock_callout)(const char* lock_name);
514 
515 /** The set of functions required by bluedroid to set wake alarms and
516  * grab wake locks. This struct is passed into the stack through the
517  * |set_os_callouts| function on |bt_interface_t|.
518  */
519 typedef struct {
520   /* set to sizeof(bt_os_callouts_t) */
521   size_t size;
522 
523   set_wake_alarm_callout set_wake_alarm;
524   acquire_wake_lock_callout acquire_wake_lock;
525   release_wake_lock_callout release_wake_lock;
526 } bt_os_callouts_t;
527 
528 /** NOTE: By default, no profiles are initialized at the time of init/enable.
529  *  Whenever the application invokes the 'init' API of a profile, then one of
530  *  the following shall occur:
531  *
532  *    1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
533  *        profile as enabled. Subsequently, when the application invokes the
534  *        Bluetooth 'enable', as part of the enable sequence the profile that
535  * were marked shall be enabled by calling appropriate stack APIs. The
536  *        'adapter_properties_cb' shall return the list of UUIDs of the
537  *        enabled profiles.
538  *
539  *    2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the
540  * stack profile API to initialize the profile and trigger a
541  *        'adapter_properties_cb' with the current list of UUIDs including the
542  *        newly added profile's UUID.
543  *
544  *   The reverse shall occur whenever the profile 'cleanup' APIs are invoked
545  */
546 
547 /** Represents the standard Bluetooth DM interface. */
548 typedef struct {
549   /** set to sizeof(bt_interface_t) */
550   size_t size;
551   /**
552    * Opens the interface and provides the callback routines
553    * to the implemenation of this interface.
554    * The |start_restricted| flag inits the adapter in restricted mode. In
555    * restricted mode, bonds that are created are marked as restricted in the
556    * config file. These devices are deleted upon leaving restricted mode.
557    * The |is_common_criteria_mode| flag inits the adapter in commom criteria
558    * mode. The |config_compare_result| flag show the config checksum check
559    * result if is in common criteria mode. The |init_flags| are config flags
560    * that cannot change during run. The |is_atv| flag indicates whether the
561    * local device is an Android TV
562    */
563   int (*init)(bt_callbacks_t* callbacks, bool guest_mode,
564               bool is_common_criteria_mode, int config_compare_result,
565               const char** init_flags, bool is_atv);
566 
567   /** Enable Bluetooth. */
568   int (*enable)();
569 
570   /** Disable Bluetooth. */
571   int (*disable)(void);
572 
573   /** Closes the interface. */
574   void (*cleanup)(void);
575 
576   /** Get all Bluetooth Adapter properties at init */
577   int (*get_adapter_properties)(void);
578 
579   /** Get Bluetooth Adapter property of 'type' */
580   int (*get_adapter_property)(bt_property_type_t type);
581 
582   /** Set Bluetooth Adapter property of 'type' */
583   /* Based on the type, val shall be one of
584    * RawAddress or bt_bdname_t or bt_scanmode_t etc
585    */
586   int (*set_adapter_property)(const bt_property_t* property);
587 
588   /** Get all Remote Device properties */
589   int (*get_remote_device_properties)(RawAddress* remote_addr);
590 
591   /** Get Remote Device property of 'type' */
592   int (*get_remote_device_property)(RawAddress* remote_addr,
593                                     bt_property_type_t type);
594 
595   /** Set Remote Device property of 'type' */
596   int (*set_remote_device_property)(RawAddress* remote_addr,
597                                     const bt_property_t* property);
598 
599   /** Get Remote Device's service record  for the given UUID */
600   int (*get_remote_service_record)(const RawAddress& remote_addr,
601                                    const bluetooth::Uuid& uuid);
602 
603   /** Start SDP to get remote services */
604   int (*get_remote_services)(RawAddress* remote_addr);
605 
606   /** Start Discovery */
607   int (*start_discovery)(void);
608 
609   /** Cancel Discovery */
610   int (*cancel_discovery)(void);
611 
612   /** Create Bluetooth Bonding */
613   int (*create_bond)(const RawAddress* bd_addr, int transport);
614 
615   /** Create Bluetooth Bond using out of band data */
616   int (*create_bond_out_of_band)(const RawAddress* bd_addr, int transport,
617                                  const bt_oob_data_t* p192_data,
618                                  const bt_oob_data_t* p256_data);
619 
620   /** Remove Bond */
621   int (*remove_bond)(const RawAddress* bd_addr);
622 
623   /** Cancel Bond */
624   int (*cancel_bond)(const RawAddress* bd_addr);
625 
626   /**
627    * Get the connection status for a given remote device.
628    * return value of 0 means the device is not connected,
629    * non-zero return status indicates an active connection.
630    */
631   int (*get_connection_state)(const RawAddress* bd_addr);
632 
633   /** BT Legacy PinKey Reply */
634   /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
635   int (*pin_reply)(const RawAddress* bd_addr, uint8_t accept, uint8_t pin_len,
636                    bt_pin_code_t* pin_code);
637 
638   /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
639    * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
640    * BT_SSP_VARIANT_CONSENT
641    * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
642    * shall be zero */
643   int (*ssp_reply)(const RawAddress* bd_addr, bt_ssp_variant_t variant,
644                    uint8_t accept, uint32_t passkey);
645 
646   /** Get Bluetooth profile interface */
647   const void* (*get_profile_interface)(const char* profile_id);
648 
649   /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
650   /* Configure DUT Mode - Use this mode to enter/exit DUT mode */
651   int (*dut_mode_configure)(uint8_t enable);
652 
653   /* Send any test HCI (vendor-specific) command to the controller. Must be in
654    * DUT Mode */
655   int (*dut_mode_send)(uint16_t opcode, uint8_t* buf, uint8_t len);
656   /** BLE Test Mode APIs */
657   /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End
658    */
659   int (*le_test_mode)(uint16_t opcode, uint8_t* buf, uint8_t len);
660 
661   /** Sets the OS call-out functions that bluedroid needs for alarms and wake
662    * locks. This should be called immediately after a successful |init|.
663    */
664   int (*set_os_callouts)(bt_os_callouts_t* callouts);
665 
666   /** Read Energy info details - return value indicates BT_STATUS_SUCCESS or
667    * BT_STATUS_NOT_READY Success indicates that the VSC command was sent to
668    * controller
669    */
670   int (*read_energy_info)();
671 
672   /**
673    * Native support for dumpsys function
674    * Function is synchronous and |fd| is owned by caller.
675    * |arguments| are arguments which may affect the output, encoded as
676    * UTF-8 strings.
677    */
678   void (*dump)(int fd, const char** arguments);
679 
680   /**
681    * Native support for metrics protobuf dumping. The dumping format will be
682    * raw byte array
683    *
684    * @param output an externally allocated string to dump serialized protobuf
685    */
686   void (*dumpMetrics)(std::string* output);
687 
688   /**
689    * Clear /data/misc/bt_config.conf and erase all stored connections
690    */
691   int (*config_clear)(void);
692 
693   /**
694    * Clear (reset) the dynamic portion of the device interoperability database.
695    */
696   void (*interop_database_clear)(void);
697 
698   /**
699    * Add a new device interoperability workaround for a remote device whose
700    * first |len| bytes of the its device address match |addr|.
701    * NOTE: |feature| has to match an item defined in interop_feature_t
702    * (interop.h).
703    */
704   void (*interop_database_add)(uint16_t feature, const RawAddress* addr,
705                                size_t len);
706 
707   /**
708    * Get the AvrcpTarget Service interface to interact with the Avrcp Service
709    */
710   bluetooth::avrcp::ServiceInterface* (*get_avrcp_service)(void);
711 
712   /**
713    * Obfuscate Bluetooth MAC address into a PII free ID string
714    *
715    * @param address Bluetooth MAC address to be obfuscated
716    * @return a string of uint8_t that is unique to this MAC address
717    */
718   std::string (*obfuscate_address)(const RawAddress& address);
719 
720   /**
721    * Get an incremental id for as primary key for Bluetooth metric and log
722    *
723    * @param address Bluetooth MAC address of Bluetooth device
724    * @return int incremental Bluetooth id
725    */
726   int (*get_metric_id)(const RawAddress& address);
727 
728   /**
729    * Set the dynamic audio buffer size to the Controller
730    */
731   int (*set_dynamic_audio_buffer_size)(int codec, int size);
732 
733   /**
734    * Fetches the local Out of Band data.
735    */
736   int (*generate_local_oob_data)(tBT_TRANSPORT transport);
737 } bt_interface_t;
738 
739 #define BLUETOOTH_INTERFACE_STRING "bluetoothInterface"
740 
741 #endif /* ANDROID_INCLUDE_BLUETOOTH_H */
742