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