blob: d6f6e3e9cf8b0afa9b341cb00445390d6aebf4a4 [file] [log] [blame]
Andre Eisenbach05f49542012-09-18 12:15:26 -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
Sharvil Nanavati3bd8cba2014-05-30 16:43:38 -070020#include <stdbool.h>
Andre Eisenbach05f49542012-09-18 12:15:26 -070021#include <stdint.h>
22#include <sys/cdefs.h>
23#include <sys/types.h>
24
25#include <hardware/hardware.h>
26
Jakub Pawlowskieab6b6e2017-07-11 09:25:44 -070027#include <bluetooth/uuid.h>
Jakub Pawlowskibec70c62017-07-05 11:13:00 -070028#include <raw_address.h>
29
Andre Eisenbach05f49542012-09-18 12:15:26 -070030__BEGIN_DECLS
31
32/**
33 * The Bluetooth Hardware Module ID
34 */
35
36#define BT_HARDWARE_MODULE_ID "bluetooth"
37#define BT_STACK_MODULE_ID "bluetooth"
Andre Eisenbach05f49542012-09-18 12:15:26 -070038
39
Jack He9213f5b2017-05-13 13:54:26 -070040/** Bluetooth profile interface IDs */
Andre Eisenbach05f49542012-09-18 12:15:26 -070041
42#define BT_PROFILE_HANDSFREE_ID "handsfree"
Hemant Guptae7737c82013-08-19 18:02:54 +053043#define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
Andre Eisenbach05f49542012-09-18 12:15:26 -070044#define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
Mike Lockwood21e50b12014-06-07 14:05:22 -070045#define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
Andre Eisenbach05f49542012-09-18 12:15:26 -070046#define BT_PROFILE_HEALTH_ID "health"
47#define BT_PROFILE_SOCKETS_ID "socket"
48#define BT_PROFILE_HIDHOST_ID "hidhost"
Hemant Gupta7ed5a7f2014-04-18 12:18:16 +053049#define BT_PROFILE_HIDDEV_ID "hiddev"
Andre Eisenbach05f49542012-09-18 12:15:26 -070050#define BT_PROFILE_PAN_ID "pan"
Hemant Gupta053cccf2014-04-18 12:25:24 +053051#define BT_PROFILE_MAP_CLIENT_ID "map_client"
kschulz9a92a7b2015-03-06 09:15:43 +010052#define BT_PROFILE_SDP_CLIENT_ID "sdp"
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080053#define BT_PROFILE_GATT_ID "gatt"
Ravi Nagarajan482ba782013-02-26 10:34:41 -080054#define BT_PROFILE_AV_RC_ID "avrcp"
Mike Lockwood7da4cb82014-06-02 16:20:51 -070055#define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
Andre Eisenbach05f49542012-09-18 12:15:26 -070056
Jack He9213f5b2017-05-13 13:54:26 -070057/** Bluetooth test interface IDs */
58#define BT_TEST_INTERFACE_MCAP_ID "mcap_test"
59
Andre Eisenbach05f49542012-09-18 12:15:26 -070060/** Bluetooth Device Name */
61typedef struct {
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080062 uint8_t name[249];
Andre Eisenbach05f49542012-09-18 12:15:26 -070063} __attribute__((packed))bt_bdname_t;
64
65/** Bluetooth Adapter Visibility Modes*/
66typedef enum {
67 BT_SCAN_MODE_NONE,
68 BT_SCAN_MODE_CONNECTABLE,
69 BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
70} bt_scan_mode_t;
71
72/** Bluetooth Adapter State */
73typedef enum {
74 BT_STATE_OFF,
75 BT_STATE_ON
76} bt_state_t;
77
78/** Bluetooth Error Status */
79/** We need to build on this */
80
81typedef enum {
82 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,
Hemant Gupta4d864552013-07-31 19:14:02 +053092 BT_STATUS_RMT_DEV_DOWN,
Andre Eisenbachf65d1252016-03-17 16:46:39 -070093 BT_STATUS_AUTH_REJECTED,
94 BT_STATUS_JNI_ENVIRONMENT_ERROR,
95 BT_STATUS_JNI_THREAD_ATTACH_ERROR,
96 BT_STATUS_WAKELOCK_ERROR
Andre Eisenbach05f49542012-09-18 12:15:26 -070097} bt_status_t;
98
99/** Bluetooth PinKey Code */
100typedef struct {
101 uint8_t pin[16];
102} __attribute__((packed))bt_pin_code_t;
103
Satya Callojibe7f0442014-07-03 10:59:16 -0700104typedef struct {
105 uint8_t status;
106 uint8_t ctrl_state; /* stack reported state */
107 uint64_t tx_time; /* in ms */
108 uint64_t rx_time; /* in ms */
109 uint64_t idle_time; /* in ms */
110 uint64_t energy_used; /* a product of mA, V and ms */
111} __attribute__((packed))bt_activity_energy_info;
112
Adam Lesinskie2d316d2015-12-03 11:40:47 -0800113typedef struct {
114 int32_t app_uid;
115 uint64_t tx_bytes;
116 uint64_t rx_bytes;
117} __attribute__((packed))bt_uid_traffic_t;
118
Andre Eisenbach05f49542012-09-18 12:15:26 -0700119/** Bluetooth Adapter Discovery state */
120typedef enum {
121 BT_DISCOVERY_STOPPED,
122 BT_DISCOVERY_STARTED
123} bt_discovery_state_t;
124
125/** Bluetooth ACL connection state */
126typedef enum {
127 BT_ACL_STATE_CONNECTED,
128 BT_ACL_STATE_DISCONNECTED
129} bt_acl_state_t;
130
Andre Eisenbach05f49542012-09-18 12:15:26 -0700131/** Bluetooth SDP service record */
132typedef struct
133{
Jakub Pawlowskieab6b6e2017-07-11 09:25:44 -0700134 bluetooth::Uuid uuid;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700135 uint16_t channel;
136 char name[256]; // what's the maximum length
137} bt_service_record_t;
138
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800139
140/** Bluetooth Remote Version info */
141typedef struct
142{
143 int version;
144 int sub_ver;
145 int manufacturer;
146} bt_remote_version_t;
147
Ganesh Ganapathi Batta460343a2014-05-27 16:03:11 -0700148typedef struct
149{
Satya Callojia8b49d32015-02-10 09:20:07 -0800150 uint16_t version_supported;
Ganesh Ganapathi Batta460343a2014-05-27 16:03:11 -0700151 uint8_t local_privacy_enabled;
152 uint8_t max_adv_instance;
153 uint8_t rpa_offload_supported;
154 uint8_t max_irk_list_size;
155 uint8_t max_adv_filter_supported;
Satya Callojibe7f0442014-07-03 10:59:16 -0700156 uint8_t activity_energy_info_supported;
Satya Callojia8b49d32015-02-10 09:20:07 -0800157 uint16_t scan_result_storage_size;
158 uint16_t total_trackable_advertisers;
Satya Calloji51225022015-03-31 13:58:21 -0700159 bool extended_scan_support;
160 bool debug_logging_supported;
Jakub Pawlowski0a660af2017-03-09 18:16:56 -0800161 bool le_2m_phy_supported;
162 bool le_coded_phy_supported;
163 bool le_extended_advertising_supported;
164 bool le_periodic_advertising_supported;
Jakub Pawlowski696f6992017-03-16 18:20:49 -0700165 uint16_t le_maximum_advertising_data_length;
Ganesh Ganapathi Batta460343a2014-05-27 16:03:11 -0700166}bt_local_le_features_t;
167
Andre Eisenbach05f49542012-09-18 12:15:26 -0700168/* Bluetooth Adapter and Remote Device property types */
169typedef enum {
Jakub Pawlowskieab6b6e2017-07-11 09:25:44 -0700170 /* Properties common to both adapter and remote device */
171 /**
172 * Description - Bluetooth Device Name
173 * Access mode - Adapter name can be GET/SET. Remote device can be GET
174 * Data type - bt_bdname_t
175 */
176 BT_PROPERTY_BDNAME = 0x1,
177 /**
178 * Description - Bluetooth Device Address
179 * Access mode - Only GET.
180 * Data type - RawAddress
181 */
182 BT_PROPERTY_BDADDR,
183 /**
184 * Description - Bluetooth Service 128-bit UUIDs
185 * Access mode - Only GET.
186 * Data type - Array of bluetooth::Uuid (Array size inferred from property
187 * length).
188 */
189 BT_PROPERTY_UUIDS,
190 /**
191 * Description - Bluetooth Class of Device as found in Assigned Numbers
192 * Access mode - Only GET.
193 * Data type - uint32_t.
194 */
195 BT_PROPERTY_CLASS_OF_DEVICE,
196 /**
197 * Description - Device Type - BREDR, BLE or DUAL Mode
198 * Access mode - Only GET.
199 * Data type - bt_device_type_t
200 */
201 BT_PROPERTY_TYPE_OF_DEVICE,
202 /**
203 * Description - Bluetooth Service Record
204 * Access mode - Only GET.
205 * Data type - bt_service_record_t
206 */
207 BT_PROPERTY_SERVICE_RECORD,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700208
Jakub Pawlowskieab6b6e2017-07-11 09:25:44 -0700209 /* Properties unique to adapter */
210 /**
211 * Description - Bluetooth Adapter scan mode
212 * Access mode - GET and SET
213 * Data type - bt_scan_mode_t.
214 */
215 BT_PROPERTY_ADAPTER_SCAN_MODE,
216 /**
217 * Description - List of bonded devices
218 * Access mode - Only GET.
219 * Data type - Array of RawAddress of the bonded remote devices
220 * (Array size inferred from property length).
221 */
222 BT_PROPERTY_ADAPTER_BONDED_DEVICES,
223 /**
224 * Description - Bluetooth Adapter Discovery timeout (in seconds)
225 * Access mode - GET and SET
226 * Data type - uint32_t
227 */
228 BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700229
Jakub Pawlowskieab6b6e2017-07-11 09:25:44 -0700230 /* Properties unique to remote device */
231 /**
232 * Description - User defined friendly name of the remote device
233 * Access mode - GET and SET
234 * Data type - bt_bdname_t.
235 */
236 BT_PROPERTY_REMOTE_FRIENDLY_NAME,
237 /**
238 * Description - RSSI value of the inquired remote device
239 * Access mode - Only GET.
240 * Data type - int32_t.
241 */
242 BT_PROPERTY_REMOTE_RSSI,
243 /**
244 * Description - Remote version info
245 * Access mode - SET/GET.
246 * Data type - bt_remote_version_t.
247 */
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800248
Jakub Pawlowskieab6b6e2017-07-11 09:25:44 -0700249 BT_PROPERTY_REMOTE_VERSION_INFO,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700250
Jakub Pawlowskieab6b6e2017-07-11 09:25:44 -0700251 /**
252 * Description - Local LE features
253 * Access mode - GET.
254 * Data type - bt_local_le_features_t.
255 */
256 BT_PROPERTY_LOCAL_LE_FEATURES,
Ganesh Ganapathi Batta460343a2014-05-27 16:03:11 -0700257
Jakub Pawlowskieab6b6e2017-07-11 09:25:44 -0700258 BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700259} bt_property_type_t;
260
261/** Bluetooth Adapter Property data structure */
262typedef struct
263{
264 bt_property_type_t type;
265 int len;
266 void *val;
267} bt_property_t;
268
Jakub Pawlowski00202ff2015-12-01 12:06:23 -0800269/** Bluetooth Out Of Band data for bonding */
270typedef struct
271{
Jakub Pawlowskid82fbad2016-11-09 16:44:30 -0800272 uint8_t le_bt_dev_addr[7]; /* LE Bluetooth Device Address */
Jakub Pawlowski00202ff2015-12-01 12:06:23 -0800273 uint8_t c192[16]; /* Simple Pairing Hash C-192 */
274 uint8_t r192[16]; /* Simple Pairing Randomizer R-192 */
275 uint8_t c256[16]; /* Simple Pairing Hash C-256 */
276 uint8_t r256[16]; /* Simple Pairing Randomizer R-256 */
277 uint8_t sm_tk[16]; /* Security Manager TK Value */
Jakub Pawlowski9caabe12016-07-29 01:37:59 -0700278 uint8_t le_sc_c[16]; /* LE Secure Connections Confirmation Value */
Jakub Pawlowski00202ff2015-12-01 12:06:23 -0800279 uint8_t le_sc_r[16]; /* LE Secure Connections Random Value */
280} bt_out_of_band_data_t;
281
282
Ganesh Ganapathi Batta460343a2014-05-27 16:03:11 -0700283
Andre Eisenbach05f49542012-09-18 12:15:26 -0700284/** Bluetooth Device Type */
285typedef enum {
286 BT_DEVICE_DEVTYPE_BREDR = 0x1,
287 BT_DEVICE_DEVTYPE_BLE,
288 BT_DEVICE_DEVTYPE_DUAL
289} bt_device_type_t;
290/** Bluetooth Bond state */
291typedef enum {
292 BT_BOND_STATE_NONE,
293 BT_BOND_STATE_BONDING,
294 BT_BOND_STATE_BONDED
295} bt_bond_state_t;
296
297/** Bluetooth SSP Bonding Variant */
298typedef enum {
299 BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
300 BT_SSP_VARIANT_PASSKEY_ENTRY,
301 BT_SSP_VARIANT_CONSENT,
302 BT_SSP_VARIANT_PASSKEY_NOTIFICATION
303} bt_ssp_variant_t;
304
305#define BT_MAX_NUM_UUIDS 32
306
307/** Bluetooth Interface callbacks */
308
309/** Bluetooth Enable/Disable Callback. */
310typedef void (*adapter_state_changed_callback)(bt_state_t state);
311
312/** GET/SET Adapter Properties callback */
313/* TODO: For the GET/SET property APIs/callbacks, we may need a session
314 * identifier to associate the call with the callback. This would be needed
315 * whenever more than one simultaneous instance of the same adapter_type
316 * is get/set.
317 *
318 * If this is going to be handled in the Java framework, then we do not need
319 * to manage sessions here.
320 */
321typedef void (*adapter_properties_callback)(bt_status_t status,
322 int num_properties,
323 bt_property_t *properties);
324
325/** GET/SET Remote Device Properties callback */
326/** TODO: For remote device properties, do not see a need to get/set
327 * multiple properties - num_properties shall be 1
328 */
329typedef void (*remote_device_properties_callback)(bt_status_t status,
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700330 RawAddress *bd_addr,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700331 int num_properties,
332 bt_property_t *properties);
333
334/** New device discovered callback */
335/** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1
336 * respectively */
337typedef void (*device_found_callback)(int num_properties,
338 bt_property_t *properties);
339
340/** Discovery state changed callback */
341typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state);
342
343/** Bluetooth Legacy PinKey Request callback */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700344typedef void (*pin_request_callback)(RawAddress *remote_bd_addr,
Casper Bonde5ccdc512015-05-08 14:33:58 +0200345 bt_bdname_t *bd_name, uint32_t cod, bool min_16_digit);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700346
347/** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
348/** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT &
349 * BT_SSP_PAIRING_PASSKEY_ENTRY */
350/* TODO: Passkey request callback shall not be needed for devices with display
351 * capability. We still need support this in the stack for completeness */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700352typedef void (*ssp_request_callback)(RawAddress *remote_bd_addr,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700353 bt_bdname_t *bd_name,
354 uint32_t cod,
355 bt_ssp_variant_t pairing_variant,
356 uint32_t pass_key);
357
358/** Bluetooth Bond state changed callback */
359/* Invoked in response to create_bond, cancel_bond or remove_bond */
360typedef void (*bond_state_changed_callback)(bt_status_t status,
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700361 RawAddress *remote_bd_addr,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700362 bt_bond_state_t state);
363
364/** Bluetooth ACL connection state changed callback */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700365typedef void (*acl_state_changed_callback)(bt_status_t status, RawAddress *remote_bd_addr,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700366 bt_acl_state_t state);
367
368typedef enum {
369 ASSOCIATE_JVM,
370 DISASSOCIATE_JVM
371} bt_cb_thread_evt;
372
373/** Thread Associate/Disassociate JVM Callback */
374/* Callback that is invoked by the callback thread to allow upper layer to attach/detach to/from
375 * the JVM */
376typedef void (*callback_thread_event)(bt_cb_thread_evt evt);
377
378/** Bluetooth Test Mode Callback */
379/* Receive any HCI event from controller. Must be in DUT Mode for this callback to be received */
380typedef void (*dut_mode_recv_callback)(uint16_t opcode, uint8_t *buf, uint8_t len);
381
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800382/* LE Test mode callbacks
383* This callback shall be invoked whenever the le_tx_test, le_rx_test or le_test_end is invoked
384* The num_packets is valid only for le_test_end command */
385typedef void (*le_test_mode_callback)(bt_status_t status, uint16_t num_packets);
Satya Callojibe7f0442014-07-03 10:59:16 -0700386
387/** Callback invoked when energy details are obtained */
388/* Ctrl_state-Current controller state-Active-1,scan-2,or idle-3 state as defined by HCI spec.
389 * If the ctrl_state value is 0, it means the API call failed
390 * Time values-In milliseconds as returned by the controller
391 * Energy used-Value as returned by the controller
Adam Lesinskie2d316d2015-12-03 11:40:47 -0800392 * Status-Provides the status of the read_energy_info API call
393 * uid_data provides an array of bt_uid_traffic_t, where the array is terminated by an element with
394 * app_uid set to -1.
395 */
396typedef void (*energy_info_callback)(bt_activity_energy_info *energy_info,
397 bt_uid_traffic_t *uid_data);
Satya Callojibe7f0442014-07-03 10:59:16 -0700398
Andre Eisenbach05f49542012-09-18 12:15:26 -0700399/** TODO: Add callbacks for Link Up/Down and other generic
400 * notifications/callbacks */
401
402/** Bluetooth DM callback structure. */
403typedef struct {
404 /** set to sizeof(bt_callbacks_t) */
405 size_t size;
406 adapter_state_changed_callback adapter_state_changed_cb;
407 adapter_properties_callback adapter_properties_cb;
408 remote_device_properties_callback remote_device_properties_cb;
409 device_found_callback device_found_cb;
410 discovery_state_changed_callback discovery_state_changed_cb;
411 pin_request_callback pin_request_cb;
412 ssp_request_callback ssp_request_cb;
413 bond_state_changed_callback bond_state_changed_cb;
414 acl_state_changed_callback acl_state_changed_cb;
415 callback_thread_event thread_evt_cb;
416 dut_mode_recv_callback dut_mode_recv_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800417 le_test_mode_callback le_test_mode_cb;
Satya Callojibe7f0442014-07-03 10:59:16 -0700418 energy_info_callback energy_info_cb;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700419} bt_callbacks_t;
420
Sharvil Nanavati3bd8cba2014-05-30 16:43:38 -0700421typedef void (*alarm_cb)(void *data);
422typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data);
423typedef int (*acquire_wake_lock_callout)(const char *lock_name);
424typedef int (*release_wake_lock_callout)(const char *lock_name);
425
426/** The set of functions required by bluedroid to set wake alarms and
427 * grab wake locks. This struct is passed into the stack through the
428 * |set_os_callouts| function on |bt_interface_t|.
429 */
430typedef struct {
431 /* set to sizeof(bt_os_callouts_t) */
432 size_t size;
433
434 set_wake_alarm_callout set_wake_alarm;
435 acquire_wake_lock_callout acquire_wake_lock;
436 release_wake_lock_callout release_wake_lock;
437} bt_os_callouts_t;
438
Andre Eisenbach05f49542012-09-18 12:15:26 -0700439/** NOTE: By default, no profiles are initialized at the time of init/enable.
440 * Whenever the application invokes the 'init' API of a profile, then one of
441 * the following shall occur:
442 *
443 * 1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
444 * profile as enabled. Subsequently, when the application invokes the
445 * Bluetooth 'enable', as part of the enable sequence the profile that were
446 * marked shall be enabled by calling appropriate stack APIs. The
447 * 'adapter_properties_cb' shall return the list of UUIDs of the
448 * enabled profiles.
449 *
450 * 2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the stack
451 * profile API to initialize the profile and trigger a
452 * 'adapter_properties_cb' with the current list of UUIDs including the
453 * newly added profile's UUID.
454 *
455 * The reverse shall occur whenever the profile 'cleanup' APIs are invoked
456 */
457
458/** Represents the standard Bluetooth DM interface. */
459typedef struct {
460 /** set to sizeof(bt_interface_t) */
461 size_t size;
462 /**
463 * Opens the interface and provides the callback routines
464 * to the implemenation of this interface.
465 */
466 int (*init)(bt_callbacks_t* callbacks );
467
468 /** Enable Bluetooth. */
Ajay Panickerd51c01d2016-03-18 14:27:36 -0700469 int (*enable)(bool guest_mode);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700470
471 /** Disable Bluetooth. */
472 int (*disable)(void);
473
474 /** Closes the interface. */
475 void (*cleanup)(void);
476
477 /** Get all Bluetooth Adapter properties at init */
478 int (*get_adapter_properties)(void);
479
480 /** Get Bluetooth Adapter property of 'type' */
481 int (*get_adapter_property)(bt_property_type_t type);
482
483 /** Set Bluetooth Adapter property of 'type' */
484 /* Based on the type, val shall be one of
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700485 * RawAddress or bt_bdname_t or bt_scanmode_t etc
Andre Eisenbach05f49542012-09-18 12:15:26 -0700486 */
487 int (*set_adapter_property)(const bt_property_t *property);
488
489 /** Get all Remote Device properties */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700490 int (*get_remote_device_properties)(RawAddress *remote_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700491
492 /** Get Remote Device property of 'type' */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700493 int (*get_remote_device_property)(RawAddress *remote_addr,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700494 bt_property_type_t type);
495
496 /** Set Remote Device property of 'type' */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700497 int (*set_remote_device_property)(RawAddress *remote_addr,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700498 const bt_property_t *property);
499
500 /** Get Remote Device's service record for the given UUID */
Jakub Pawlowskieab6b6e2017-07-11 09:25:44 -0700501 int (*get_remote_service_record)(const RawAddress& remote_addr,
502 const bluetooth::Uuid& uuid);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700503
504 /** Start SDP to get remote services */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700505 int (*get_remote_services)(RawAddress *remote_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700506
507 /** Start Discovery */
508 int (*start_discovery)(void);
509
510 /** Cancel Discovery */
511 int (*cancel_discovery)(void);
512
513 /** Create Bluetooth Bonding */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700514 int (*create_bond)(const RawAddress *bd_addr, int transport);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700515
Jakub Pawlowski00202ff2015-12-01 12:06:23 -0800516 /** Create Bluetooth Bond using out of band data */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700517 int (*create_bond_out_of_band)(const RawAddress *bd_addr, int transport,
Jakub Pawlowski00202ff2015-12-01 12:06:23 -0800518 const bt_out_of_band_data_t *oob_data);
519
Andre Eisenbach05f49542012-09-18 12:15:26 -0700520 /** Remove Bond */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700521 int (*remove_bond)(const RawAddress *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700522
523 /** Cancel Bond */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700524 int (*cancel_bond)(const RawAddress *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700525
Andre Eisenbach0d553bc2014-06-18 12:18:34 -0700526 /**
527 * Get the connection status for a given remote device.
528 * return value of 0 means the device is not connected,
529 * non-zero return status indicates an active connection.
530 */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700531 int (*get_connection_state)(const RawAddress *bd_addr);
Andre Eisenbach0d553bc2014-06-18 12:18:34 -0700532
Andre Eisenbach05f49542012-09-18 12:15:26 -0700533 /** BT Legacy PinKey Reply */
534 /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700535 int (*pin_reply)(const RawAddress *bd_addr, uint8_t accept,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700536 uint8_t pin_len, bt_pin_code_t *pin_code);
537
538 /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
539 * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
540 * BT_SSP_VARIANT_CONSENT
541 * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
542 * shall be zero */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700543 int (*ssp_reply)(const RawAddress *bd_addr, bt_ssp_variant_t variant,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700544 uint8_t accept, uint32_t passkey);
545
546 /** Get Bluetooth profile interface */
547 const void* (*get_profile_interface) (const char *profile_id);
548
549 /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
550 /* Configure DUT Mode - Use this mode to enter/exit DUT mode */
551 int (*dut_mode_configure)(uint8_t enable);
552
553 /* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */
554 int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800555 /** BLE Test Mode APIs */
556 /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */
557 int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);
558
Sharvil Nanavati3bd8cba2014-05-30 16:43:38 -0700559 /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks.
560 * This should be called immediately after a successful |init|.
561 */
562 int (*set_os_callouts)(bt_os_callouts_t *callouts);
Satya Callojibe7f0442014-07-03 10:59:16 -0700563
564 /** Read Energy info details - return value indicates BT_STATUS_SUCCESS or BT_STATUS_NOT_READY
565 * Success indicates that the VSC command was sent to controller
566 */
567 int (*read_energy_info)();
Andre Eisenbach34ab95a2014-12-05 09:35:57 -0800568
569 /**
570 * Native support for dumpsys function
571 * Function is synchronous and |fd| is owned by caller.
Marie Janssen32d45dd2016-01-08 11:16:29 -0800572 * |arguments| are arguments which may affect the output, encoded as
573 * UTF-8 strings.
Andre Eisenbach34ab95a2014-12-05 09:35:57 -0800574 */
Marie Janssen32d45dd2016-01-08 11:16:29 -0800575 void (*dump)(int fd, const char **arguments);
Ajay Panickerb3759712015-07-28 16:53:53 -0700576
577 /**
578 * Clear /data/misc/bt_config.conf and erase all stored connections
579 */
580 int (*config_clear)(void);
581
Andre Eisenbache4109402016-01-14 02:03:36 -0800582 /**
583 * Clear (reset) the dynamic portion of the device interoperability database.
584 */
585 void (*interop_database_clear)(void);
586
587 /**
588 * Add a new device interoperability workaround for a remote device whose
589 * first |len| bytes of the its device address match |addr|.
590 * NOTE: |feature| has to match an item defined in interop_feature_t (interop.h).
591 */
Jakub Pawlowski5a852002017-06-24 17:33:20 -0700592 void (*interop_database_add)(uint16_t feature, const RawAddress *addr, size_t len);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700593} bt_interface_t;
594
595/** TODO: Need to add APIs for Service Discovery, Service authorization and
596 * connection management. Also need to add APIs for configuring
597 * properties of remote bonded devices such as name, UUID etc. */
598
599typedef struct {
600 struct hw_device_t common;
601 const bt_interface_t* (*get_bluetooth_interface)();
602} bluetooth_device_t;
603
604typedef bluetooth_device_t bluetooth_module_t;
kschulz9a92a7b2015-03-06 09:15:43 +0100605
606
Andre Eisenbach05f49542012-09-18 12:15:26 -0700607__END_DECLS
608
609#endif /* ANDROID_INCLUDE_BLUETOOTH_H */