blob: 4251005165616ad2c92ba2cea4ca49b144a96574 [file] [log] [blame]
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -07001/*
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
Ajay Panicker66401792018-03-14 23:45:54 -070025#include "avrcp/avrcp.h"
26#include "bluetooth/uuid.h"
27#include "raw_address.h"
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -070028
29/**
30 * The Bluetooth Hardware Module ID
31 */
32
33#define BT_HARDWARE_MODULE_ID "bluetooth"
34#define BT_STACK_MODULE_ID "bluetooth"
35
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -070036/** Bluetooth profile interface IDs */
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -070037#define BT_PROFILE_HANDSFREE_ID "handsfree"
38#define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
39#define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
40#define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -070041#define BT_PROFILE_SOCKETS_ID "socket"
42#define BT_PROFILE_HIDHOST_ID "hidhost"
43#define BT_PROFILE_HIDDEV_ID "hiddev"
44#define BT_PROFILE_PAN_ID "pan"
45#define BT_PROFILE_MAP_CLIENT_ID "map_client"
46#define BT_PROFILE_SDP_CLIENT_ID "sdp"
47#define BT_PROFILE_GATT_ID "gatt"
48#define BT_PROFILE_AV_RC_ID "avrcp"
49#define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
Jakub Pawlowskie8931792017-11-21 16:35:49 -080050#define BT_PROFILE_HEARING_AID_ID "hearing_aid"
weichinwengb30bb982020-04-21 09:42:27 +080051#define BT_KEYSTORE_ID "bluetooth_keystore"
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -070052
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -070053/** Bluetooth Device Name */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -070054typedef struct { uint8_t name[249]; } __attribute__((packed)) bt_bdname_t;
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -070055
56/** Bluetooth Adapter Visibility Modes*/
57typedef enum {
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -070058 BT_SCAN_MODE_NONE,
59 BT_SCAN_MODE_CONNECTABLE,
60 BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -070061} bt_scan_mode_t;
62
63/** Bluetooth Adapter State */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -070064typedef enum { BT_STATE_OFF, BT_STATE_ON } bt_state_t;
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -070065
Pulkit Bhuwalka2bc59e52018-03-22 14:34:33 -070066/** Bluetooth Adapter Input Output Capabilities which determine Pairing/Security
67 */
68typedef enum {
69 BT_IO_CAP_OUT, /* DisplayOnly */
70 BT_IO_CAP_IO, /* DisplayYesNo */
71 BT_IO_CAP_IN, /* KeyboardOnly */
72 BT_IO_CAP_NONE, /* NoInputNoOutput */
73 BT_IO_CAP_KBDISP, /* Keyboard display */
74 BT_IO_CAP_MAX,
75 BT_IO_CAP_UNKNOWN = 0xFF /* Unknown value */
76} bt_io_cap_t;
77
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -070078/** Bluetooth Error Status */
79/** We need to build on this */
80
81typedef enum {
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -070082 BT_STATUS_SUCCESS,
83 BT_STATUS_FAIL,
84 BT_STATUS_NOT_READY,
85 BT_STATUS_NOMEM,
86 BT_STATUS_BUSY,
87 BT_STATUS_DONE, /* request already completed */
88 BT_STATUS_UNSUPPORTED,
89 BT_STATUS_PARM_INVALID,
90 BT_STATUS_UNHANDLED,
91 BT_STATUS_AUTH_FAILURE,
92 BT_STATUS_RMT_DEV_DOWN,
93 BT_STATUS_AUTH_REJECTED,
94 BT_STATUS_JNI_ENVIRONMENT_ERROR,
95 BT_STATUS_JNI_THREAD_ATTACH_ERROR,
96 BT_STATUS_WAKELOCK_ERROR
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -070097} bt_status_t;
98
99/** Bluetooth PinKey Code */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700100typedef struct { uint8_t pin[16]; } __attribute__((packed)) bt_pin_code_t;
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700101
102typedef struct {
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700103 uint8_t status;
104 uint8_t ctrl_state; /* stack reported state */
105 uint64_t tx_time; /* in ms */
106 uint64_t rx_time; /* in ms */
107 uint64_t idle_time; /* in ms */
108 uint64_t energy_used; /* a product of mA, V and ms */
109} __attribute__((packed)) bt_activity_energy_info;
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700110
111typedef struct {
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700112 int32_t app_uid;
113 uint64_t tx_bytes;
114 uint64_t rx_bytes;
115} __attribute__((packed)) bt_uid_traffic_t;
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700116
117/** Bluetooth Adapter Discovery state */
118typedef enum {
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700119 BT_DISCOVERY_STOPPED,
120 BT_DISCOVERY_STARTED
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700121} bt_discovery_state_t;
122
123/** Bluetooth ACL connection state */
124typedef enum {
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700125 BT_ACL_STATE_CONNECTED,
126 BT_ACL_STATE_DISCONNECTED
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700127} bt_acl_state_t;
128
129/** Bluetooth SDP service record */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700130typedef struct {
131 bluetooth::Uuid uuid;
132 uint16_t channel;
133 char name[256]; // what's the maximum length
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700134} bt_service_record_t;
135
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700136/** Bluetooth Remote Version info */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700137typedef struct {
138 int version;
139 int sub_ver;
140 int manufacturer;
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700141} bt_remote_version_t;
142
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700143typedef struct {
144 uint16_t version_supported;
145 uint8_t local_privacy_enabled;
146 uint8_t max_adv_instance;
147 uint8_t rpa_offload_supported;
148 uint8_t max_irk_list_size;
149 uint8_t max_adv_filter_supported;
150 uint8_t activity_energy_info_supported;
151 uint16_t scan_result_storage_size;
152 uint16_t total_trackable_advertisers;
153 bool extended_scan_support;
154 bool debug_logging_supported;
155 bool le_2m_phy_supported;
156 bool le_coded_phy_supported;
157 bool le_extended_advertising_supported;
158 bool le_periodic_advertising_supported;
159 uint16_t le_maximum_advertising_data_length;
160} bt_local_le_features_t;
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700161
162/* Bluetooth Adapter and Remote Device property types */
163typedef enum {
164 /* Properties common to both adapter and remote device */
165 /**
166 * Description - Bluetooth Device Name
167 * Access mode - Adapter name can be GET/SET. Remote device can be GET
168 * Data type - bt_bdname_t
169 */
170 BT_PROPERTY_BDNAME = 0x1,
171 /**
172 * Description - Bluetooth Device Address
173 * Access mode - Only GET.
174 * Data type - RawAddress
175 */
176 BT_PROPERTY_BDADDR,
177 /**
178 * Description - Bluetooth Service 128-bit UUIDs
179 * Access mode - Only GET.
180 * Data type - Array of bluetooth::Uuid (Array size inferred from property
181 * length).
182 */
183 BT_PROPERTY_UUIDS,
184 /**
185 * Description - Bluetooth Class of Device as found in Assigned Numbers
186 * Access mode - Only GET.
187 * Data type - uint32_t.
188 */
189 BT_PROPERTY_CLASS_OF_DEVICE,
190 /**
191 * Description - Device Type - BREDR, BLE or DUAL Mode
192 * Access mode - Only GET.
193 * Data type - bt_device_type_t
194 */
195 BT_PROPERTY_TYPE_OF_DEVICE,
196 /**
197 * Description - Bluetooth Service Record
198 * Access mode - Only GET.
199 * Data type - bt_service_record_t
200 */
201 BT_PROPERTY_SERVICE_RECORD,
202
203 /* Properties unique to adapter */
204 /**
205 * Description - Bluetooth Adapter scan mode
206 * Access mode - GET and SET
207 * Data type - bt_scan_mode_t.
208 */
209 BT_PROPERTY_ADAPTER_SCAN_MODE,
210 /**
211 * Description - List of bonded devices
212 * Access mode - Only GET.
213 * Data type - Array of RawAddress of the bonded remote devices
214 * (Array size inferred from property length).
215 */
216 BT_PROPERTY_ADAPTER_BONDED_DEVICES,
217 /**
218 * Description - Bluetooth Adapter Discovery timeout (in seconds)
219 * Access mode - GET and SET
220 * Data type - uint32_t
221 */
222 BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
223
224 /* Properties unique to remote device */
225 /**
226 * Description - User defined friendly name of the remote device
227 * Access mode - GET and SET
228 * Data type - bt_bdname_t.
229 */
230 BT_PROPERTY_REMOTE_FRIENDLY_NAME,
231 /**
232 * Description - RSSI value of the inquired remote device
233 * Access mode - Only GET.
Tiansong Cui1dee3a52017-10-27 14:24:15 -0700234 * Data type - int8_t.
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700235 */
236 BT_PROPERTY_REMOTE_RSSI,
237 /**
238 * Description - Remote version info
239 * Access mode - SET/GET.
240 * Data type - bt_remote_version_t.
241 */
242
243 BT_PROPERTY_REMOTE_VERSION_INFO,
244
245 /**
246 * Description - Local LE features
247 * Access mode - GET.
248 * Data type - bt_local_le_features_t.
249 */
250 BT_PROPERTY_LOCAL_LE_FEATURES,
251
Pulkit Bhuwalka2bc59e52018-03-22 14:34:33 -0700252 /**
253 * Description - Local Input/Output Capabilities for classic Bluetooth
254 * Access mode - GET and SET
255 * Data Type - bt_io_cap_t.
256 */
257 BT_PROPERTY_LOCAL_IO_CAPS,
258
259 /**
260 * Description - Local Input/Output Capabilities for BLE
261 * Access mode - GET and SET
262 * Data Type - bt_io_cap_t.
263 */
264 BT_PROPERTY_LOCAL_IO_CAPS_BLE,
265
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700266 BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
267} bt_property_type_t;
268
269/** Bluetooth Adapter Property data structure */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700270typedef struct {
271 bt_property_type_t type;
272 int len;
273 void* val;
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700274} bt_property_t;
275
276/** Bluetooth Out Of Band data for bonding */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700277typedef struct {
278 uint8_t le_bt_dev_addr[7]; /* LE Bluetooth Device Address */
279 uint8_t c192[16]; /* Simple Pairing Hash C-192 */
280 uint8_t r192[16]; /* Simple Pairing Randomizer R-192 */
281 uint8_t c256[16]; /* Simple Pairing Hash C-256 */
282 uint8_t r256[16]; /* Simple Pairing Randomizer R-256 */
283 uint8_t sm_tk[16]; /* Security Manager TK Value */
284 uint8_t le_sc_c[16]; /* LE Secure Connections Confirmation Value */
285 uint8_t le_sc_r[16]; /* LE Secure Connections Random Value */
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700286} bt_out_of_band_data_t;
287
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700288/** Bluetooth Device Type */
289typedef enum {
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700290 BT_DEVICE_DEVTYPE_BREDR = 0x1,
291 BT_DEVICE_DEVTYPE_BLE,
292 BT_DEVICE_DEVTYPE_DUAL
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700293} bt_device_type_t;
294/** Bluetooth Bond state */
295typedef enum {
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700296 BT_BOND_STATE_NONE,
297 BT_BOND_STATE_BONDING,
298 BT_BOND_STATE_BONDED
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700299} bt_bond_state_t;
300
301/** Bluetooth SSP Bonding Variant */
302typedef enum {
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700303 BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
304 BT_SSP_VARIANT_PASSKEY_ENTRY,
305 BT_SSP_VARIANT_CONSENT,
306 BT_SSP_VARIANT_PASSKEY_NOTIFICATION
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700307} bt_ssp_variant_t;
308
309#define BT_MAX_NUM_UUIDS 32
310
311/** Bluetooth Interface callbacks */
312
313/** Bluetooth Enable/Disable Callback. */
314typedef void (*adapter_state_changed_callback)(bt_state_t state);
315
316/** GET/SET Adapter Properties callback */
317/* TODO: For the GET/SET property APIs/callbacks, we may need a session
318 * identifier to associate the call with the callback. This would be needed
319 * whenever more than one simultaneous instance of the same adapter_type
320 * is get/set.
321 *
322 * If this is going to be handled in the Java framework, then we do not need
323 * to manage sessions here.
324 */
325typedef void (*adapter_properties_callback)(bt_status_t status,
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700326 int num_properties,
327 bt_property_t* properties);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700328
329/** GET/SET Remote Device Properties callback */
330/** TODO: For remote device properties, do not see a need to get/set
331 * multiple properties - num_properties shall be 1
332 */
333typedef void (*remote_device_properties_callback)(bt_status_t status,
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700334 RawAddress* bd_addr,
335 int num_properties,
336 bt_property_t* properties);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700337
338/** New device discovered callback */
339/** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1
340 * respectively */
341typedef void (*device_found_callback)(int num_properties,
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700342 bt_property_t* properties);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700343
344/** Discovery state changed callback */
345typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state);
346
347/** Bluetooth Legacy PinKey Request callback */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700348typedef void (*pin_request_callback)(RawAddress* remote_bd_addr,
349 bt_bdname_t* bd_name, uint32_t cod,
350 bool min_16_digit);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700351
352/** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
353/** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT &
354 * BT_SSP_PAIRING_PASSKEY_ENTRY */
355/* TODO: Passkey request callback shall not be needed for devices with display
356 * capability. We still need support this in the stack for completeness */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700357typedef void (*ssp_request_callback)(RawAddress* remote_bd_addr,
358 bt_bdname_t* bd_name, uint32_t cod,
359 bt_ssp_variant_t pairing_variant,
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700360 uint32_t pass_key);
361
362/** Bluetooth Bond state changed callback */
363/* Invoked in response to create_bond, cancel_bond or remove_bond */
364typedef void (*bond_state_changed_callback)(bt_status_t status,
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700365 RawAddress* remote_bd_addr,
366 bt_bond_state_t state);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700367
368/** Bluetooth ACL connection state changed callback */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700369typedef void (*acl_state_changed_callback)(bt_status_t status,
370 RawAddress* remote_bd_addr,
371 bt_acl_state_t state);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700372
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700373typedef enum { ASSOCIATE_JVM, DISASSOCIATE_JVM } bt_cb_thread_evt;
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700374
375/** Thread Associate/Disassociate JVM Callback */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700376/* Callback that is invoked by the callback thread to allow upper layer to
377 * attach/detach to/from the JVM */
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700378typedef void (*callback_thread_event)(bt_cb_thread_evt evt);
379
380/** Bluetooth Test Mode Callback */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700381/* Receive any HCI event from controller. Must be in DUT Mode for this callback
382 * to be received */
383typedef void (*dut_mode_recv_callback)(uint16_t opcode, uint8_t* buf,
384 uint8_t len);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700385
386/* LE Test mode callbacks
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700387 * This callback shall be invoked whenever the le_tx_test, le_rx_test or
388 * le_test_end is invoked The num_packets is valid only for le_test_end command
389 */
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700390typedef void (*le_test_mode_callback)(bt_status_t status, uint16_t num_packets);
391
392/** Callback invoked when energy details are obtained */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700393/* Ctrl_state-Current controller state-Active-1,scan-2,or idle-3 state as
394 * defined by HCI spec. If the ctrl_state value is 0, it means the API call
395 * failed Time values-In milliseconds as returned by the controller Energy
396 * used-Value as returned by the controller Status-Provides the status of the
397 * read_energy_info API call uid_data provides an array of bt_uid_traffic_t,
398 * where the array is terminated by an element with app_uid set to -1.
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700399 */
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700400typedef void (*energy_info_callback)(bt_activity_energy_info* energy_info,
401 bt_uid_traffic_t* uid_data);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700402
403/** TODO: Add callbacks for Link Up/Down and other generic
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700404 * notifications/callbacks */
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700405
406/** Bluetooth DM callback structure. */
407typedef struct {
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700408 /** set to sizeof(bt_callbacks_t) */
409 size_t size;
410 adapter_state_changed_callback adapter_state_changed_cb;
411 adapter_properties_callback adapter_properties_cb;
412 remote_device_properties_callback remote_device_properties_cb;
413 device_found_callback device_found_cb;
414 discovery_state_changed_callback discovery_state_changed_cb;
415 pin_request_callback pin_request_cb;
416 ssp_request_callback ssp_request_cb;
417 bond_state_changed_callback bond_state_changed_cb;
418 acl_state_changed_callback acl_state_changed_cb;
419 callback_thread_event thread_evt_cb;
420 dut_mode_recv_callback dut_mode_recv_cb;
421 le_test_mode_callback le_test_mode_cb;
422 energy_info_callback energy_info_cb;
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700423} bt_callbacks_t;
424
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700425typedef void (*alarm_cb)(void* data);
426typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake,
427 alarm_cb cb, void* data);
428typedef int (*acquire_wake_lock_callout)(const char* lock_name);
429typedef int (*release_wake_lock_callout)(const char* lock_name);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700430
431/** The set of functions required by bluedroid to set wake alarms and
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700432 * grab wake locks. This struct is passed into the stack through the
433 * |set_os_callouts| function on |bt_interface_t|.
434 */
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700435typedef struct {
436 /* set to sizeof(bt_os_callouts_t) */
437 size_t size;
438
439 set_wake_alarm_callout set_wake_alarm;
440 acquire_wake_lock_callout acquire_wake_lock;
441 release_wake_lock_callout release_wake_lock;
442} bt_os_callouts_t;
443
444/** NOTE: By default, no profiles are initialized at the time of init/enable.
445 * Whenever the application invokes the 'init' API of a profile, then one of
446 * the following shall occur:
447 *
448 * 1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
449 * profile as enabled. Subsequently, when the application invokes the
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700450 * Bluetooth 'enable', as part of the enable sequence the profile that
451 * were marked shall be enabled by calling appropriate stack APIs. The
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700452 * 'adapter_properties_cb' shall return the list of UUIDs of the
453 * enabled profiles.
454 *
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700455 * 2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the
456 * stack profile API to initialize the profile and trigger a
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700457 * 'adapter_properties_cb' with the current list of UUIDs including the
458 * newly added profile's UUID.
459 *
460 * The reverse shall occur whenever the profile 'cleanup' APIs are invoked
461 */
462
463/** Represents the standard Bluetooth DM interface. */
464typedef struct {
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700465 /** set to sizeof(bt_interface_t) */
466 size_t size;
467 /**
468 * Opens the interface and provides the callback routines
469 * to the implemenation of this interface.
Martin Brabham1a88ace2019-05-10 12:42:15 -0700470 * The |start_restricted| flag inits the adapter in restricted mode. In
471 * restricted mode, bonds that are created are marked as restricted in the
472 * config file. These devices are deleted upon leaving restricted mode.
weichinweng14b98e02020-04-21 10:26:26 +0800473 * The |is_niap_mode| flag inits the adapter in NIAP mode.
474 * The |config_compare_result| flag show the config checksum check result if
475 * is in NIAP mode.
Rahul Sabnise198eb92020-07-31 19:44:27 -0700476 * The |is_atv| flag indicates whether the local device is an Android TV
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700477 */
weichinweng14b98e02020-04-21 10:26:26 +0800478 int (*init)(bt_callbacks_t* callbacks, bool guest_mode, bool is_niap_mode,
Rahul Sabnise198eb92020-07-31 19:44:27 -0700479 int config_compare_result, bool is_atv);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700480
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700481 /** Enable Bluetooth. */
Martin Brabham1a88ace2019-05-10 12:42:15 -0700482 int (*enable)();
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700483
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700484 /** Disable Bluetooth. */
485 int (*disable)(void);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700486
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700487 /** Closes the interface. */
488 void (*cleanup)(void);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700489
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700490 /** Get all Bluetooth Adapter properties at init */
491 int (*get_adapter_properties)(void);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700492
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700493 /** Get Bluetooth Adapter property of 'type' */
494 int (*get_adapter_property)(bt_property_type_t type);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700495
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700496 /** Set Bluetooth Adapter property of 'type' */
497 /* Based on the type, val shall be one of
498 * RawAddress or bt_bdname_t or bt_scanmode_t etc
499 */
500 int (*set_adapter_property)(const bt_property_t* property);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700501
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700502 /** Get all Remote Device properties */
503 int (*get_remote_device_properties)(RawAddress* remote_addr);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700504
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700505 /** Get Remote Device property of 'type' */
506 int (*get_remote_device_property)(RawAddress* remote_addr,
507 bt_property_type_t type);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700508
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700509 /** Set Remote Device property of 'type' */
510 int (*set_remote_device_property)(RawAddress* remote_addr,
511 const bt_property_t* property);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700512
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700513 /** Get Remote Device's service record for the given UUID */
514 int (*get_remote_service_record)(const RawAddress& remote_addr,
515 const bluetooth::Uuid& uuid);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700516
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700517 /** Start SDP to get remote services */
518 int (*get_remote_services)(RawAddress* remote_addr);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700519
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700520 /** Start Discovery */
521 int (*start_discovery)(void);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700522
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700523 /** Cancel Discovery */
524 int (*cancel_discovery)(void);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700525
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700526 /** Create Bluetooth Bonding */
527 int (*create_bond)(const RawAddress* bd_addr, int transport);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700528
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700529 /** Create Bluetooth Bond using out of band data */
530 int (*create_bond_out_of_band)(const RawAddress* bd_addr, int transport,
531 const bt_out_of_band_data_t* oob_data);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700532
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700533 /** Remove Bond */
534 int (*remove_bond)(const RawAddress* bd_addr);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700535
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700536 /** Cancel Bond */
537 int (*cancel_bond)(const RawAddress* bd_addr);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700538
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700539 /**
540 * Get the connection status for a given remote device.
541 * return value of 0 means the device is not connected,
542 * non-zero return status indicates an active connection.
543 */
544 int (*get_connection_state)(const RawAddress* bd_addr);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700545
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700546 /** BT Legacy PinKey Reply */
547 /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
548 int (*pin_reply)(const RawAddress* bd_addr, uint8_t accept, uint8_t pin_len,
549 bt_pin_code_t* pin_code);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700550
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700551 /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
552 * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
553 * BT_SSP_VARIANT_CONSENT
554 * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
555 * shall be zero */
556 int (*ssp_reply)(const RawAddress* bd_addr, bt_ssp_variant_t variant,
557 uint8_t accept, uint32_t passkey);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700558
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700559 /** Get Bluetooth profile interface */
560 const void* (*get_profile_interface)(const char* profile_id);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700561
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700562 /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
563 /* Configure DUT Mode - Use this mode to enter/exit DUT mode */
564 int (*dut_mode_configure)(uint8_t enable);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700565
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700566 /* Send any test HCI (vendor-specific) command to the controller. Must be in
567 * DUT Mode */
568 int (*dut_mode_send)(uint16_t opcode, uint8_t* buf, uint8_t len);
569 /** BLE Test Mode APIs */
570 /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End
571 */
572 int (*le_test_mode)(uint16_t opcode, uint8_t* buf, uint8_t len);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700573
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700574 /** Sets the OS call-out functions that bluedroid needs for alarms and wake
575 * locks. This should be called immediately after a successful |init|.
576 */
577 int (*set_os_callouts)(bt_os_callouts_t* callouts);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700578
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700579 /** Read Energy info details - return value indicates BT_STATUS_SUCCESS or
580 * BT_STATUS_NOT_READY Success indicates that the VSC command was sent to
581 * controller
582 */
583 int (*read_energy_info)();
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700584
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700585 /**
586 * Native support for dumpsys function
587 * Function is synchronous and |fd| is owned by caller.
588 * |arguments| are arguments which may affect the output, encoded as
589 * UTF-8 strings.
590 */
591 void (*dump)(int fd, const char** arguments);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700592
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700593 /**
Jack He9af00782018-01-31 16:51:26 -0800594 * Native support for metrics protobuf dumping. The dumping format will be
595 * raw byte array
596 *
597 * @param output an externally allocated string to dump serialized protobuf
598 */
599 void (*dumpMetrics)(std::string* output);
600
601 /**
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700602 * Clear /data/misc/bt_config.conf and erase all stored connections
603 */
604 int (*config_clear)(void);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700605
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700606 /**
607 * Clear (reset) the dynamic portion of the device interoperability database.
608 */
609 void (*interop_database_clear)(void);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700610
Jakub Pawlowski3a3b82c2017-10-18 20:49:54 -0700611 /**
612 * Add a new device interoperability workaround for a remote device whose
613 * first |len| bytes of the its device address match |addr|.
614 * NOTE: |feature| has to match an item defined in interop_feature_t
615 * (interop.h).
616 */
617 void (*interop_database_add)(uint16_t feature, const RawAddress* addr,
618 size_t len);
Ajay Panicker66401792018-03-14 23:45:54 -0700619
620 /**
621 * Get the AvrcpTarget Service interface to interact with the Avrcp Service
622 */
623 bluetooth::avrcp::ServiceInterface* (*get_avrcp_service)(void);
Jack He78b69d92018-11-16 02:59:43 -0800624
625 /**
626 * Obfuscate Bluetooth MAC address into a PII free ID string
627 *
628 * @param address Bluetooth MAC address to be obfuscated
629 * @return a string of uint8_t that is unique to this MAC address
630 */
631 std::string (*obfuscate_address)(const RawAddress& address);
Chen Chen4f6a3b22020-03-05 15:02:46 -0800632
633 /**
634 * Get an incremental id for as primary key for Bluetooth metric and log
635 *
636 * @param address Bluetooth MAC address of Bluetooth device
637 * @return int incremental Bluetooth id
638 */
639 int (*get_metric_id)(const RawAddress& address);
Jakub Pawlowskif2f207a2017-09-23 14:47:20 -0700640} bt_interface_t;
641
642#define BLUETOOTH_INTERFACE_STRING "bluetoothInterface"
643
644#endif /* ANDROID_INCLUDE_BLUETOOTH_H */