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