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