Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 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 | |
Sharvil Nanavati | 3bd8cba | 2014-05-30 16:43:38 -0700 | [diff] [blame] | 20 | #include <stdbool.h> |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
| 22 | #include <sys/cdefs.h> |
| 23 | #include <sys/types.h> |
| 24 | |
| 25 | #include <hardware/hardware.h> |
| 26 | |
| 27 | __BEGIN_DECLS |
| 28 | |
| 29 | /** |
| 30 | * The Bluetooth Hardware Module ID |
| 31 | */ |
| 32 | |
| 33 | #define BT_HARDWARE_MODULE_ID "bluetooth" |
| 34 | #define BT_STACK_MODULE_ID "bluetooth" |
| 35 | #define BT_STACK_TEST_MODULE_ID "bluetooth_test" |
| 36 | |
| 37 | |
| 38 | /* Bluetooth profile interface IDs */ |
| 39 | |
| 40 | #define BT_PROFILE_HANDSFREE_ID "handsfree" |
Hemant Gupta | e7737c8 | 2013-08-19 18:02:54 +0530 | [diff] [blame] | 41 | #define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client" |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 42 | #define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp" |
Mike Lockwood | 21e50b1 | 2014-06-07 14:05:22 -0700 | [diff] [blame] | 43 | #define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink" |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 44 | #define BT_PROFILE_HEALTH_ID "health" |
| 45 | #define BT_PROFILE_SOCKETS_ID "socket" |
| 46 | #define BT_PROFILE_HIDHOST_ID "hidhost" |
Hemant Gupta | 7ed5a7f | 2014-04-18 12:18:16 +0530 | [diff] [blame] | 47 | #define BT_PROFILE_HIDDEV_ID "hiddev" |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 48 | #define BT_PROFILE_PAN_ID "pan" |
Hemant Gupta | 053cccf | 2014-04-18 12:25:24 +0530 | [diff] [blame] | 49 | #define BT_PROFILE_MAP_CLIENT_ID "map_client" |
kschulz | 9a92a7b | 2015-03-06 09:15:43 +0100 | [diff] [blame] | 50 | #define BT_PROFILE_SDP_CLIENT_ID "sdp" |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 51 | #define BT_PROFILE_GATT_ID "gatt" |
Ravi Nagarajan | 482ba78 | 2013-02-26 10:34:41 -0800 | [diff] [blame] | 52 | #define BT_PROFILE_AV_RC_ID "avrcp" |
Mike Lockwood | 7da4cb8 | 2014-06-02 16:20:51 -0700 | [diff] [blame] | 53 | #define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl" |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 54 | |
| 55 | /** Bluetooth Address */ |
| 56 | typedef struct { |
| 57 | uint8_t address[6]; |
| 58 | } __attribute__((packed))bt_bdaddr_t; |
| 59 | |
| 60 | /** Bluetooth Device Name */ |
| 61 | typedef struct { |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 62 | uint8_t name[249]; |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 63 | } __attribute__((packed))bt_bdname_t; |
| 64 | |
| 65 | /** Bluetooth Adapter Visibility Modes*/ |
| 66 | typedef 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 */ |
| 73 | typedef 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 | |
| 81 | typedef 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 Gupta | 4d86455 | 2013-07-31 19:14:02 +0530 | [diff] [blame] | 92 | BT_STATUS_RMT_DEV_DOWN, |
Andre Eisenbach | f65d125 | 2016-03-17 16:46:39 -0700 | [diff] [blame] | 93 | BT_STATUS_AUTH_REJECTED, |
| 94 | BT_STATUS_JNI_ENVIRONMENT_ERROR, |
| 95 | BT_STATUS_JNI_THREAD_ATTACH_ERROR, |
| 96 | BT_STATUS_WAKELOCK_ERROR |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 97 | } bt_status_t; |
| 98 | |
| 99 | /** Bluetooth PinKey Code */ |
| 100 | typedef struct { |
| 101 | uint8_t pin[16]; |
| 102 | } __attribute__((packed))bt_pin_code_t; |
| 103 | |
Satya Calloji | be7f044 | 2014-07-03 10:59:16 -0700 | [diff] [blame] | 104 | typedef 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 Lesinski | e2d316d | 2015-12-03 11:40:47 -0800 | [diff] [blame] | 113 | typedef 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 Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 119 | /** Bluetooth Adapter Discovery state */ |
| 120 | typedef enum { |
| 121 | BT_DISCOVERY_STOPPED, |
| 122 | BT_DISCOVERY_STARTED |
| 123 | } bt_discovery_state_t; |
| 124 | |
| 125 | /** Bluetooth ACL connection state */ |
| 126 | typedef enum { |
| 127 | BT_ACL_STATE_CONNECTED, |
| 128 | BT_ACL_STATE_DISCONNECTED |
| 129 | } bt_acl_state_t; |
| 130 | |
| 131 | /** Bluetooth 128-bit UUID */ |
| 132 | typedef struct { |
| 133 | uint8_t uu[16]; |
| 134 | } bt_uuid_t; |
| 135 | |
| 136 | /** Bluetooth SDP service record */ |
| 137 | typedef struct |
| 138 | { |
| 139 | bt_uuid_t uuid; |
| 140 | uint16_t channel; |
| 141 | char name[256]; // what's the maximum length |
| 142 | } bt_service_record_t; |
| 143 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 144 | |
| 145 | /** Bluetooth Remote Version info */ |
| 146 | typedef struct |
| 147 | { |
| 148 | int version; |
| 149 | int sub_ver; |
| 150 | int manufacturer; |
| 151 | } bt_remote_version_t; |
| 152 | |
Ganesh Ganapathi Batta | 460343a | 2014-05-27 16:03:11 -0700 | [diff] [blame] | 153 | typedef struct |
| 154 | { |
Satya Calloji | a8b49d3 | 2015-02-10 09:20:07 -0800 | [diff] [blame] | 155 | uint16_t version_supported; |
Ganesh Ganapathi Batta | 460343a | 2014-05-27 16:03:11 -0700 | [diff] [blame] | 156 | uint8_t local_privacy_enabled; |
| 157 | uint8_t max_adv_instance; |
| 158 | uint8_t rpa_offload_supported; |
| 159 | uint8_t max_irk_list_size; |
| 160 | uint8_t max_adv_filter_supported; |
Satya Calloji | be7f044 | 2014-07-03 10:59:16 -0700 | [diff] [blame] | 161 | uint8_t activity_energy_info_supported; |
Satya Calloji | a8b49d3 | 2015-02-10 09:20:07 -0800 | [diff] [blame] | 162 | uint16_t scan_result_storage_size; |
| 163 | uint16_t total_trackable_advertisers; |
Satya Calloji | 5122502 | 2015-03-31 13:58:21 -0700 | [diff] [blame] | 164 | bool extended_scan_support; |
| 165 | bool debug_logging_supported; |
Jakub Pawlowski | 0a660af | 2017-03-09 18:16:56 -0800 | [diff] [blame^] | 166 | bool le_2m_phy_supported; |
| 167 | bool le_coded_phy_supported; |
| 168 | bool le_extended_advertising_supported; |
| 169 | bool le_periodic_advertising_supported; |
Ganesh Ganapathi Batta | 460343a | 2014-05-27 16:03:11 -0700 | [diff] [blame] | 170 | }bt_local_le_features_t; |
| 171 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 172 | /* Bluetooth Adapter and Remote Device property types */ |
| 173 | typedef enum { |
| 174 | /* Properties common to both adapter and remote device */ |
| 175 | /** |
| 176 | * Description - Bluetooth Device Name |
| 177 | * Access mode - Adapter name can be GET/SET. Remote device can be GET |
| 178 | * Data type - bt_bdname_t |
| 179 | */ |
| 180 | BT_PROPERTY_BDNAME = 0x1, |
| 181 | /** |
| 182 | * Description - Bluetooth Device Address |
| 183 | * Access mode - Only GET. |
| 184 | * Data type - bt_bdaddr_t |
| 185 | */ |
| 186 | BT_PROPERTY_BDADDR, |
| 187 | /** |
| 188 | * Description - Bluetooth Service 128-bit UUIDs |
| 189 | * Access mode - Only GET. |
| 190 | * Data type - Array of bt_uuid_t (Array size inferred from property length). |
| 191 | */ |
| 192 | BT_PROPERTY_UUIDS, |
| 193 | /** |
| 194 | * Description - Bluetooth Class of Device as found in Assigned Numbers |
| 195 | * Access mode - Only GET. |
| 196 | * Data type - uint32_t. |
| 197 | */ |
| 198 | BT_PROPERTY_CLASS_OF_DEVICE, |
| 199 | /** |
| 200 | * Description - Device Type - BREDR, BLE or DUAL Mode |
| 201 | * Access mode - Only GET. |
| 202 | * Data type - bt_device_type_t |
| 203 | */ |
| 204 | BT_PROPERTY_TYPE_OF_DEVICE, |
| 205 | /** |
| 206 | * Description - Bluetooth Service Record |
| 207 | * Access mode - Only GET. |
| 208 | * Data type - bt_service_record_t |
| 209 | */ |
| 210 | BT_PROPERTY_SERVICE_RECORD, |
| 211 | |
| 212 | /* Properties unique to adapter */ |
| 213 | /** |
| 214 | * Description - Bluetooth Adapter scan mode |
| 215 | * Access mode - GET and SET |
| 216 | * Data type - bt_scan_mode_t. |
| 217 | */ |
| 218 | BT_PROPERTY_ADAPTER_SCAN_MODE, |
| 219 | /** |
| 220 | * Description - List of bonded devices |
| 221 | * Access mode - Only GET. |
| 222 | * Data type - Array of bt_bdaddr_t of the bonded remote devices |
| 223 | * (Array size inferred from property length). |
| 224 | */ |
| 225 | BT_PROPERTY_ADAPTER_BONDED_DEVICES, |
| 226 | /** |
| 227 | * Description - Bluetooth Adapter Discovery timeout (in seconds) |
| 228 | * Access mode - GET and SET |
| 229 | * Data type - uint32_t |
| 230 | */ |
| 231 | BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT, |
| 232 | |
| 233 | /* Properties unique to remote device */ |
| 234 | /** |
| 235 | * Description - User defined friendly name of the remote device |
| 236 | * Access mode - GET and SET |
| 237 | * Data type - bt_bdname_t. |
| 238 | */ |
| 239 | BT_PROPERTY_REMOTE_FRIENDLY_NAME, |
| 240 | /** |
| 241 | * Description - RSSI value of the inquired remote device |
| 242 | * Access mode - Only GET. |
| 243 | * Data type - int32_t. |
| 244 | */ |
| 245 | BT_PROPERTY_REMOTE_RSSI, |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 246 | /** |
| 247 | * Description - Remote version info |
| 248 | * Access mode - SET/GET. |
| 249 | * Data type - bt_remote_version_t. |
| 250 | */ |
| 251 | |
| 252 | BT_PROPERTY_REMOTE_VERSION_INFO, |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 253 | |
Ganesh Ganapathi Batta | 460343a | 2014-05-27 16:03:11 -0700 | [diff] [blame] | 254 | /** |
| 255 | * Description - Local LE features |
| 256 | * Access mode - GET. |
| 257 | * Data type - bt_local_le_features_t. |
| 258 | */ |
| 259 | BT_PROPERTY_LOCAL_LE_FEATURES, |
| 260 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 261 | BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF, |
| 262 | } bt_property_type_t; |
| 263 | |
| 264 | /** Bluetooth Adapter Property data structure */ |
| 265 | typedef struct |
| 266 | { |
| 267 | bt_property_type_t type; |
| 268 | int len; |
| 269 | void *val; |
| 270 | } bt_property_t; |
| 271 | |
Jakub Pawlowski | 00202ff | 2015-12-01 12:06:23 -0800 | [diff] [blame] | 272 | /** Bluetooth Out Of Band data for bonding */ |
| 273 | typedef struct |
| 274 | { |
Jakub Pawlowski | d82fbad | 2016-11-09 16:44:30 -0800 | [diff] [blame] | 275 | uint8_t le_bt_dev_addr[7]; /* LE Bluetooth Device Address */ |
Jakub Pawlowski | 00202ff | 2015-12-01 12:06:23 -0800 | [diff] [blame] | 276 | uint8_t c192[16]; /* Simple Pairing Hash C-192 */ |
| 277 | uint8_t r192[16]; /* Simple Pairing Randomizer R-192 */ |
| 278 | uint8_t c256[16]; /* Simple Pairing Hash C-256 */ |
| 279 | uint8_t r256[16]; /* Simple Pairing Randomizer R-256 */ |
| 280 | uint8_t sm_tk[16]; /* Security Manager TK Value */ |
Jakub Pawlowski | 9caabe1 | 2016-07-29 01:37:59 -0700 | [diff] [blame] | 281 | uint8_t le_sc_c[16]; /* LE Secure Connections Confirmation Value */ |
Jakub Pawlowski | 00202ff | 2015-12-01 12:06:23 -0800 | [diff] [blame] | 282 | uint8_t le_sc_r[16]; /* LE Secure Connections Random Value */ |
| 283 | } bt_out_of_band_data_t; |
| 284 | |
| 285 | |
Ganesh Ganapathi Batta | 460343a | 2014-05-27 16:03:11 -0700 | [diff] [blame] | 286 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 287 | /** Bluetooth Device Type */ |
| 288 | typedef enum { |
| 289 | BT_DEVICE_DEVTYPE_BREDR = 0x1, |
| 290 | BT_DEVICE_DEVTYPE_BLE, |
| 291 | BT_DEVICE_DEVTYPE_DUAL |
| 292 | } bt_device_type_t; |
| 293 | /** Bluetooth Bond state */ |
| 294 | typedef enum { |
| 295 | BT_BOND_STATE_NONE, |
| 296 | BT_BOND_STATE_BONDING, |
| 297 | BT_BOND_STATE_BONDED |
| 298 | } bt_bond_state_t; |
| 299 | |
| 300 | /** Bluetooth SSP Bonding Variant */ |
| 301 | typedef enum { |
| 302 | BT_SSP_VARIANT_PASSKEY_CONFIRMATION, |
| 303 | BT_SSP_VARIANT_PASSKEY_ENTRY, |
| 304 | BT_SSP_VARIANT_CONSENT, |
| 305 | BT_SSP_VARIANT_PASSKEY_NOTIFICATION |
| 306 | } bt_ssp_variant_t; |
| 307 | |
| 308 | #define BT_MAX_NUM_UUIDS 32 |
| 309 | |
| 310 | /** Bluetooth Interface callbacks */ |
| 311 | |
| 312 | /** Bluetooth Enable/Disable Callback. */ |
| 313 | typedef void (*adapter_state_changed_callback)(bt_state_t state); |
| 314 | |
| 315 | /** GET/SET Adapter Properties callback */ |
| 316 | /* TODO: For the GET/SET property APIs/callbacks, we may need a session |
| 317 | * identifier to associate the call with the callback. This would be needed |
| 318 | * whenever more than one simultaneous instance of the same adapter_type |
| 319 | * is get/set. |
| 320 | * |
| 321 | * If this is going to be handled in the Java framework, then we do not need |
| 322 | * to manage sessions here. |
| 323 | */ |
| 324 | typedef void (*adapter_properties_callback)(bt_status_t status, |
| 325 | int num_properties, |
| 326 | bt_property_t *properties); |
| 327 | |
| 328 | /** GET/SET Remote Device Properties callback */ |
| 329 | /** TODO: For remote device properties, do not see a need to get/set |
| 330 | * multiple properties - num_properties shall be 1 |
| 331 | */ |
| 332 | typedef void (*remote_device_properties_callback)(bt_status_t status, |
| 333 | bt_bdaddr_t *bd_addr, |
| 334 | int num_properties, |
| 335 | bt_property_t *properties); |
| 336 | |
| 337 | /** New device discovered callback */ |
| 338 | /** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1 |
| 339 | * respectively */ |
| 340 | typedef void (*device_found_callback)(int num_properties, |
| 341 | bt_property_t *properties); |
| 342 | |
| 343 | /** Discovery state changed callback */ |
| 344 | typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state); |
| 345 | |
| 346 | /** Bluetooth Legacy PinKey Request callback */ |
| 347 | typedef void (*pin_request_callback)(bt_bdaddr_t *remote_bd_addr, |
Casper Bonde | 5ccdc51 | 2015-05-08 14:33:58 +0200 | [diff] [blame] | 348 | bt_bdname_t *bd_name, uint32_t cod, bool min_16_digit); |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 349 | |
| 350 | /** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/ |
| 351 | /** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT & |
| 352 | * BT_SSP_PAIRING_PASSKEY_ENTRY */ |
| 353 | /* TODO: Passkey request callback shall not be needed for devices with display |
| 354 | * capability. We still need support this in the stack for completeness */ |
| 355 | typedef void (*ssp_request_callback)(bt_bdaddr_t *remote_bd_addr, |
| 356 | bt_bdname_t *bd_name, |
| 357 | uint32_t cod, |
| 358 | bt_ssp_variant_t pairing_variant, |
| 359 | uint32_t pass_key); |
| 360 | |
| 361 | /** Bluetooth Bond state changed callback */ |
| 362 | /* Invoked in response to create_bond, cancel_bond or remove_bond */ |
| 363 | typedef void (*bond_state_changed_callback)(bt_status_t status, |
| 364 | bt_bdaddr_t *remote_bd_addr, |
| 365 | bt_bond_state_t state); |
| 366 | |
| 367 | /** Bluetooth ACL connection state changed callback */ |
| 368 | typedef void (*acl_state_changed_callback)(bt_status_t status, bt_bdaddr_t *remote_bd_addr, |
| 369 | bt_acl_state_t state); |
| 370 | |
| 371 | typedef enum { |
| 372 | ASSOCIATE_JVM, |
| 373 | DISASSOCIATE_JVM |
| 374 | } bt_cb_thread_evt; |
| 375 | |
| 376 | /** Thread Associate/Disassociate JVM Callback */ |
| 377 | /* Callback that is invoked by the callback thread to allow upper layer to attach/detach to/from |
| 378 | * the JVM */ |
| 379 | typedef void (*callback_thread_event)(bt_cb_thread_evt evt); |
| 380 | |
| 381 | /** Bluetooth Test Mode Callback */ |
| 382 | /* Receive any HCI event from controller. Must be in DUT Mode for this callback to be received */ |
| 383 | typedef void (*dut_mode_recv_callback)(uint16_t opcode, uint8_t *buf, uint8_t len); |
| 384 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 385 | /* LE Test mode callbacks |
| 386 | * This callback shall be invoked whenever the le_tx_test, le_rx_test or le_test_end is invoked |
| 387 | * The num_packets is valid only for le_test_end command */ |
| 388 | typedef void (*le_test_mode_callback)(bt_status_t status, uint16_t num_packets); |
Satya Calloji | be7f044 | 2014-07-03 10:59:16 -0700 | [diff] [blame] | 389 | |
| 390 | /** Callback invoked when energy details are obtained */ |
| 391 | /* Ctrl_state-Current controller state-Active-1,scan-2,or idle-3 state as defined by HCI spec. |
| 392 | * If the ctrl_state value is 0, it means the API call failed |
| 393 | * Time values-In milliseconds as returned by the controller |
| 394 | * Energy used-Value as returned by the controller |
Adam Lesinski | e2d316d | 2015-12-03 11:40:47 -0800 | [diff] [blame] | 395 | * Status-Provides the status of the read_energy_info API call |
| 396 | * uid_data provides an array of bt_uid_traffic_t, where the array is terminated by an element with |
| 397 | * app_uid set to -1. |
| 398 | */ |
| 399 | typedef void (*energy_info_callback)(bt_activity_energy_info *energy_info, |
| 400 | bt_uid_traffic_t *uid_data); |
Satya Calloji | be7f044 | 2014-07-03 10:59:16 -0700 | [diff] [blame] | 401 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 402 | /** TODO: Add callbacks for Link Up/Down and other generic |
| 403 | * notifications/callbacks */ |
| 404 | |
| 405 | /** Bluetooth DM callback structure. */ |
| 406 | typedef struct { |
| 407 | /** set to sizeof(bt_callbacks_t) */ |
| 408 | size_t size; |
| 409 | adapter_state_changed_callback adapter_state_changed_cb; |
| 410 | adapter_properties_callback adapter_properties_cb; |
| 411 | remote_device_properties_callback remote_device_properties_cb; |
| 412 | device_found_callback device_found_cb; |
| 413 | discovery_state_changed_callback discovery_state_changed_cb; |
| 414 | pin_request_callback pin_request_cb; |
| 415 | ssp_request_callback ssp_request_cb; |
| 416 | bond_state_changed_callback bond_state_changed_cb; |
| 417 | acl_state_changed_callback acl_state_changed_cb; |
| 418 | callback_thread_event thread_evt_cb; |
| 419 | dut_mode_recv_callback dut_mode_recv_cb; |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 420 | le_test_mode_callback le_test_mode_cb; |
Satya Calloji | be7f044 | 2014-07-03 10:59:16 -0700 | [diff] [blame] | 421 | energy_info_callback energy_info_cb; |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 422 | } bt_callbacks_t; |
| 423 | |
Sharvil Nanavati | 3bd8cba | 2014-05-30 16:43:38 -0700 | [diff] [blame] | 424 | typedef void (*alarm_cb)(void *data); |
| 425 | typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data); |
| 426 | typedef int (*acquire_wake_lock_callout)(const char *lock_name); |
| 427 | typedef int (*release_wake_lock_callout)(const char *lock_name); |
| 428 | |
| 429 | /** The set of functions required by bluedroid to set wake alarms and |
| 430 | * grab wake locks. This struct is passed into the stack through the |
| 431 | * |set_os_callouts| function on |bt_interface_t|. |
| 432 | */ |
| 433 | typedef struct { |
| 434 | /* set to sizeof(bt_os_callouts_t) */ |
| 435 | size_t size; |
| 436 | |
| 437 | set_wake_alarm_callout set_wake_alarm; |
| 438 | acquire_wake_lock_callout acquire_wake_lock; |
| 439 | release_wake_lock_callout release_wake_lock; |
| 440 | } bt_os_callouts_t; |
| 441 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 442 | /** NOTE: By default, no profiles are initialized at the time of init/enable. |
| 443 | * Whenever the application invokes the 'init' API of a profile, then one of |
| 444 | * the following shall occur: |
| 445 | * |
| 446 | * 1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the |
| 447 | * profile as enabled. Subsequently, when the application invokes the |
| 448 | * Bluetooth 'enable', as part of the enable sequence the profile that were |
| 449 | * marked shall be enabled by calling appropriate stack APIs. The |
| 450 | * 'adapter_properties_cb' shall return the list of UUIDs of the |
| 451 | * enabled profiles. |
| 452 | * |
| 453 | * 2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the stack |
| 454 | * profile API to initialize the profile and trigger a |
| 455 | * 'adapter_properties_cb' with the current list of UUIDs including the |
| 456 | * newly added profile's UUID. |
| 457 | * |
| 458 | * The reverse shall occur whenever the profile 'cleanup' APIs are invoked |
| 459 | */ |
| 460 | |
| 461 | /** Represents the standard Bluetooth DM interface. */ |
| 462 | typedef struct { |
| 463 | /** set to sizeof(bt_interface_t) */ |
| 464 | size_t size; |
| 465 | /** |
| 466 | * Opens the interface and provides the callback routines |
| 467 | * to the implemenation of this interface. |
| 468 | */ |
| 469 | int (*init)(bt_callbacks_t* callbacks ); |
| 470 | |
| 471 | /** Enable Bluetooth. */ |
Ajay Panicker | d51c01d | 2016-03-18 14:27:36 -0700 | [diff] [blame] | 472 | int (*enable)(bool guest_mode); |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 473 | |
| 474 | /** Disable Bluetooth. */ |
| 475 | int (*disable)(void); |
| 476 | |
| 477 | /** Closes the interface. */ |
| 478 | void (*cleanup)(void); |
| 479 | |
| 480 | /** Get all Bluetooth Adapter properties at init */ |
| 481 | int (*get_adapter_properties)(void); |
| 482 | |
| 483 | /** Get Bluetooth Adapter property of 'type' */ |
| 484 | int (*get_adapter_property)(bt_property_type_t type); |
| 485 | |
| 486 | /** Set Bluetooth Adapter property of 'type' */ |
| 487 | /* Based on the type, val shall be one of |
| 488 | * bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc |
| 489 | */ |
| 490 | int (*set_adapter_property)(const bt_property_t *property); |
| 491 | |
| 492 | /** Get all Remote Device properties */ |
| 493 | int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr); |
| 494 | |
| 495 | /** Get Remote Device property of 'type' */ |
| 496 | int (*get_remote_device_property)(bt_bdaddr_t *remote_addr, |
| 497 | bt_property_type_t type); |
| 498 | |
| 499 | /** Set Remote Device property of 'type' */ |
| 500 | int (*set_remote_device_property)(bt_bdaddr_t *remote_addr, |
| 501 | const bt_property_t *property); |
| 502 | |
| 503 | /** Get Remote Device's service record for the given UUID */ |
| 504 | int (*get_remote_service_record)(bt_bdaddr_t *remote_addr, |
| 505 | bt_uuid_t *uuid); |
| 506 | |
| 507 | /** Start SDP to get remote services */ |
| 508 | int (*get_remote_services)(bt_bdaddr_t *remote_addr); |
| 509 | |
| 510 | /** Start Discovery */ |
| 511 | int (*start_discovery)(void); |
| 512 | |
| 513 | /** Cancel Discovery */ |
| 514 | int (*cancel_discovery)(void); |
| 515 | |
| 516 | /** Create Bluetooth Bonding */ |
Andre Eisenbach | 01206e5 | 2014-08-04 17:22:29 -0700 | [diff] [blame] | 517 | int (*create_bond)(const bt_bdaddr_t *bd_addr, int transport); |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 518 | |
Jakub Pawlowski | 00202ff | 2015-12-01 12:06:23 -0800 | [diff] [blame] | 519 | /** Create Bluetooth Bond using out of band data */ |
| 520 | int (*create_bond_out_of_band)(const bt_bdaddr_t *bd_addr, int transport, |
| 521 | const bt_out_of_band_data_t *oob_data); |
| 522 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 523 | /** Remove Bond */ |
| 524 | int (*remove_bond)(const bt_bdaddr_t *bd_addr); |
| 525 | |
| 526 | /** Cancel Bond */ |
| 527 | int (*cancel_bond)(const bt_bdaddr_t *bd_addr); |
| 528 | |
Andre Eisenbach | 0d553bc | 2014-06-18 12:18:34 -0700 | [diff] [blame] | 529 | /** |
| 530 | * Get the connection status for a given remote device. |
| 531 | * return value of 0 means the device is not connected, |
| 532 | * non-zero return status indicates an active connection. |
| 533 | */ |
| 534 | int (*get_connection_state)(const bt_bdaddr_t *bd_addr); |
| 535 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 536 | /** BT Legacy PinKey Reply */ |
| 537 | /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */ |
| 538 | int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept, |
| 539 | uint8_t pin_len, bt_pin_code_t *pin_code); |
| 540 | |
| 541 | /** BT SSP Reply - Just Works, Numeric Comparison and Passkey |
| 542 | * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON & |
| 543 | * BT_SSP_VARIANT_CONSENT |
| 544 | * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey |
| 545 | * shall be zero */ |
| 546 | int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant, |
| 547 | uint8_t accept, uint32_t passkey); |
| 548 | |
| 549 | /** Get Bluetooth profile interface */ |
| 550 | const void* (*get_profile_interface) (const char *profile_id); |
| 551 | |
| 552 | /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */ |
| 553 | /* Configure DUT Mode - Use this mode to enter/exit DUT mode */ |
| 554 | int (*dut_mode_configure)(uint8_t enable); |
| 555 | |
| 556 | /* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */ |
| 557 | int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 558 | /** BLE Test Mode APIs */ |
| 559 | /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */ |
| 560 | int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len); |
| 561 | |
Zhihai Xu | a17b75b | 2013-06-10 20:23:45 -0700 | [diff] [blame] | 562 | /* enable or disable bluetooth HCI snoop log */ |
| 563 | int (*config_hci_snoop_log)(uint8_t enable); |
Sharvil Nanavati | 3bd8cba | 2014-05-30 16:43:38 -0700 | [diff] [blame] | 564 | |
| 565 | /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks. |
| 566 | * This should be called immediately after a successful |init|. |
| 567 | */ |
| 568 | int (*set_os_callouts)(bt_os_callouts_t *callouts); |
Satya Calloji | be7f044 | 2014-07-03 10:59:16 -0700 | [diff] [blame] | 569 | |
| 570 | /** Read Energy info details - return value indicates BT_STATUS_SUCCESS or BT_STATUS_NOT_READY |
| 571 | * Success indicates that the VSC command was sent to controller |
| 572 | */ |
| 573 | int (*read_energy_info)(); |
Andre Eisenbach | 34ab95a | 2014-12-05 09:35:57 -0800 | [diff] [blame] | 574 | |
| 575 | /** |
| 576 | * Native support for dumpsys function |
| 577 | * Function is synchronous and |fd| is owned by caller. |
Marie Janssen | 32d45dd | 2016-01-08 11:16:29 -0800 | [diff] [blame] | 578 | * |arguments| are arguments which may affect the output, encoded as |
| 579 | * UTF-8 strings. |
Andre Eisenbach | 34ab95a | 2014-12-05 09:35:57 -0800 | [diff] [blame] | 580 | */ |
Marie Janssen | 32d45dd | 2016-01-08 11:16:29 -0800 | [diff] [blame] | 581 | void (*dump)(int fd, const char **arguments); |
Ajay Panicker | b375971 | 2015-07-28 16:53:53 -0700 | [diff] [blame] | 582 | |
| 583 | /** |
| 584 | * Clear /data/misc/bt_config.conf and erase all stored connections |
| 585 | */ |
| 586 | int (*config_clear)(void); |
| 587 | |
Andre Eisenbach | e410940 | 2016-01-14 02:03:36 -0800 | [diff] [blame] | 588 | /** |
| 589 | * Clear (reset) the dynamic portion of the device interoperability database. |
| 590 | */ |
| 591 | void (*interop_database_clear)(void); |
| 592 | |
| 593 | /** |
| 594 | * Add a new device interoperability workaround for a remote device whose |
| 595 | * first |len| bytes of the its device address match |addr|. |
| 596 | * NOTE: |feature| has to match an item defined in interop_feature_t (interop.h). |
| 597 | */ |
| 598 | void (*interop_database_add)(uint16_t feature, const bt_bdaddr_t *addr, size_t len); |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 599 | } bt_interface_t; |
| 600 | |
| 601 | /** TODO: Need to add APIs for Service Discovery, Service authorization and |
| 602 | * connection management. Also need to add APIs for configuring |
| 603 | * properties of remote bonded devices such as name, UUID etc. */ |
| 604 | |
| 605 | typedef struct { |
| 606 | struct hw_device_t common; |
| 607 | const bt_interface_t* (*get_bluetooth_interface)(); |
| 608 | } bluetooth_device_t; |
| 609 | |
| 610 | typedef bluetooth_device_t bluetooth_module_t; |
kschulz | 9a92a7b | 2015-03-06 09:15:43 +0100 | [diff] [blame] | 611 | |
| 612 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 613 | __END_DECLS |
| 614 | |
| 615 | #endif /* ANDROID_INCLUDE_BLUETOOTH_H */ |