2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_INCLUDE_BLUETOOTH_H
18 #define ANDROID_INCLUDE_BLUETOOTH_H
22 #include <sys/cdefs.h>
23 #include <sys/types.h>
25 #include <hardware/hardware.h>
30 * The Bluetooth Hardware Module ID
33 #define BT_HARDWARE_MODULE_ID "bluetooth"
34 #define BT_STACK_MODULE_ID "bluetooth"
35 #define BT_STACK_TEST_MODULE_ID "bluetooth_test"
38 /* Bluetooth profile interface IDs */
40 #define BT_PROFILE_HANDSFREE_ID "handsfree"
41 #define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
42 #define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
43 #define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
44 #define BT_PROFILE_HEALTH_ID "health"
45 #define BT_PROFILE_SOCKETS_ID "socket"
46 #define BT_PROFILE_HIDHOST_ID "hidhost"
47 #define BT_PROFILE_PAN_ID "pan"
48 #define BT_PROFILE_MAP_CLIENT_ID "map_client"
49 #define BT_PROFILE_SDP_CLIENT_ID "sdp"
50 #define BT_PROFILE_GATT_ID "gatt"
51 #define BT_PROFILE_AV_RC_ID "avrcp"
52 #define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
54 /** Bluetooth Address */
57 } __attribute__((packed))bt_bdaddr_t;
59 /** Bluetooth Device Name */
62 } __attribute__((packed))bt_bdname_t;
64 /** Bluetooth Adapter Visibility Modes*/
67 BT_SCAN_MODE_CONNECTABLE,
68 BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
71 /** Bluetooth Adapter State */
77 /** Bluetooth Error Status */
78 /** We need to build on this */
86 BT_STATUS_DONE, /* request already completed */
87 BT_STATUS_UNSUPPORTED,
88 BT_STATUS_PARM_INVALID,
90 BT_STATUS_AUTH_FAILURE,
91 BT_STATUS_RMT_DEV_DOWN,
92 BT_STATUS_AUTH_REJECTED
96 /** Bluetooth PinKey Code */
99 } __attribute__((packed))bt_pin_code_t;
103 uint8_t ctrl_state; /* stack reported state */
104 uint64_t tx_time; /* in ms */
105 uint64_t rx_time; /* in ms */
106 uint64_t idle_time; /* in ms */
107 uint64_t energy_used; /* a product of mA, V and ms */
108 } __attribute__((packed))bt_activity_energy_info;
110 /** Bluetooth Adapter Discovery state */
112 BT_DISCOVERY_STOPPED,
114 } bt_discovery_state_t;
116 /** Bluetooth ACL connection state */
118 BT_ACL_STATE_CONNECTED,
119 BT_ACL_STATE_DISCONNECTED
122 /** Bluetooth 128-bit UUID */
127 /** Bluetooth SDP service record */
132 char name[256]; // what's the maximum length
133 } bt_service_record_t;
136 /** Bluetooth Remote Version info */
142 } bt_remote_version_t;
146 uint16_t version_supported;
147 uint8_t local_privacy_enabled;
148 uint8_t max_adv_instance;
149 uint8_t rpa_offload_supported;
150 uint8_t max_irk_list_size;
151 uint8_t max_adv_filter_supported;
152 uint8_t activity_energy_info_supported;
153 uint16_t scan_result_storage_size;
154 uint16_t total_trackable_advertisers;
155 bool extended_scan_support;
156 bool debug_logging_supported;
157 }bt_local_le_features_t;
159 /* Bluetooth Adapter and Remote Device property types */
161 /* Properties common to both adapter and remote device */
163 * Description - Bluetooth Device Name
164 * Access mode - Adapter name can be GET/SET. Remote device can be GET
165 * Data type - bt_bdname_t
167 BT_PROPERTY_BDNAME = 0x1,
169 * Description - Bluetooth Device Address
170 * Access mode - Only GET.
171 * Data type - bt_bdaddr_t
175 * Description - Bluetooth Service 128-bit UUIDs
176 * Access mode - Only GET.
177 * Data type - Array of bt_uuid_t (Array size inferred from property length).
181 * Description - Bluetooth Class of Device as found in Assigned Numbers
182 * Access mode - Only GET.
183 * Data type - uint32_t.
185 BT_PROPERTY_CLASS_OF_DEVICE,
187 * Description - Device Type - BREDR, BLE or DUAL Mode
188 * Access mode - Only GET.
189 * Data type - bt_device_type_t
191 BT_PROPERTY_TYPE_OF_DEVICE,
193 * Description - Bluetooth Service Record
194 * Access mode - Only GET.
195 * Data type - bt_service_record_t
197 BT_PROPERTY_SERVICE_RECORD,
199 /* Properties unique to adapter */
201 * Description - Bluetooth Adapter scan mode
202 * Access mode - GET and SET
203 * Data type - bt_scan_mode_t.
205 BT_PROPERTY_ADAPTER_SCAN_MODE,
207 * Description - List of bonded devices
208 * Access mode - Only GET.
209 * Data type - Array of bt_bdaddr_t of the bonded remote devices
210 * (Array size inferred from property length).
212 BT_PROPERTY_ADAPTER_BONDED_DEVICES,
214 * Description - Bluetooth Adapter Discovery timeout (in seconds)
215 * Access mode - GET and SET
216 * Data type - uint32_t
218 BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
220 /* Properties unique to remote device */
222 * Description - User defined friendly name of the remote device
223 * Access mode - GET and SET
224 * Data type - bt_bdname_t.
226 BT_PROPERTY_REMOTE_FRIENDLY_NAME,
228 * Description - RSSI value of the inquired remote device
229 * Access mode - Only GET.
230 * Data type - int32_t.
232 BT_PROPERTY_REMOTE_RSSI,
234 * Description - Remote version info
235 * Access mode - SET/GET.
236 * Data type - bt_remote_version_t.
239 BT_PROPERTY_REMOTE_VERSION_INFO,
242 * Description - Local LE features
244 * Data type - bt_local_le_features_t.
246 BT_PROPERTY_LOCAL_LE_FEATURES,
248 BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
249 } bt_property_type_t;
251 /** Bluetooth Adapter Property data structure */
254 bt_property_type_t type;
260 /** Bluetooth Device Type */
262 BT_DEVICE_DEVTYPE_BREDR = 0x1,
263 BT_DEVICE_DEVTYPE_BLE,
264 BT_DEVICE_DEVTYPE_DUAL
266 /** Bluetooth Bond state */
269 BT_BOND_STATE_BONDING,
273 /** Bluetooth SSP Bonding Variant */
275 BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
276 BT_SSP_VARIANT_PASSKEY_ENTRY,
277 BT_SSP_VARIANT_CONSENT,
278 BT_SSP_VARIANT_PASSKEY_NOTIFICATION
281 #define BT_MAX_NUM_UUIDS 32
283 /** Bluetooth Interface callbacks */
285 /** Bluetooth Enable/Disable Callback. */
286 typedef void (*adapter_state_changed_callback)(bt_state_t state);
288 /** GET/SET Adapter Properties callback */
289 /* TODO: For the GET/SET property APIs/callbacks, we may need a session
290 * identifier to associate the call with the callback. This would be needed
291 * whenever more than one simultaneous instance of the same adapter_type
294 * If this is going to be handled in the Java framework, then we do not need
295 * to manage sessions here.
297 typedef void (*adapter_properties_callback)(bt_status_t status,
299 bt_property_t *properties);
301 /** GET/SET Remote Device Properties callback */
302 /** TODO: For remote device properties, do not see a need to get/set
303 * multiple properties - num_properties shall be 1
305 typedef void (*remote_device_properties_callback)(bt_status_t status,
306 bt_bdaddr_t *bd_addr,
308 bt_property_t *properties);
310 /** New device discovered callback */
311 /** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1
313 typedef void (*device_found_callback)(int num_properties,
314 bt_property_t *properties);
316 /** Discovery state changed callback */
317 typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state);
319 /** Bluetooth Legacy PinKey Request callback */
320 typedef void (*pin_request_callback)(bt_bdaddr_t *remote_bd_addr,
321 bt_bdname_t *bd_name, uint32_t cod, bool min_16_digit);
323 /** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
324 /** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT &
325 * BT_SSP_PAIRING_PASSKEY_ENTRY */
326 /* TODO: Passkey request callback shall not be needed for devices with display
327 * capability. We still need support this in the stack for completeness */
328 typedef void (*ssp_request_callback)(bt_bdaddr_t *remote_bd_addr,
329 bt_bdname_t *bd_name,
331 bt_ssp_variant_t pairing_variant,
334 /** Bluetooth Bond state changed callback */
335 /* Invoked in response to create_bond, cancel_bond or remove_bond */
336 typedef void (*bond_state_changed_callback)(bt_status_t status,
337 bt_bdaddr_t *remote_bd_addr,
338 bt_bond_state_t state);
340 /** Bluetooth ACL connection state changed callback */
341 typedef void (*acl_state_changed_callback)(bt_status_t status, bt_bdaddr_t *remote_bd_addr,
342 bt_acl_state_t state);
349 /** Thread Associate/Disassociate JVM Callback */
350 /* Callback that is invoked by the callback thread to allow upper layer to attach/detach to/from
352 typedef void (*callback_thread_event)(bt_cb_thread_evt evt);
354 /** Bluetooth Test Mode Callback */
355 /* Receive any HCI event from controller. Must be in DUT Mode for this callback to be received */
356 typedef void (*dut_mode_recv_callback)(uint16_t opcode, uint8_t *buf, uint8_t len);
358 /* LE Test mode callbacks
359 * This callback shall be invoked whenever the le_tx_test, le_rx_test or le_test_end is invoked
360 * The num_packets is valid only for le_test_end command */
361 typedef void (*le_test_mode_callback)(bt_status_t status, uint16_t num_packets);
363 /** Callback invoked when energy details are obtained */
364 /* Ctrl_state-Current controller state-Active-1,scan-2,or idle-3 state as defined by HCI spec.
365 * If the ctrl_state value is 0, it means the API call failed
366 * Time values-In milliseconds as returned by the controller
367 * Energy used-Value as returned by the controller
368 * Status-Provides the status of the read_energy_info API call */
369 typedef void (*energy_info_callback)(bt_activity_energy_info *energy_info);
371 /** TODO: Add callbacks for Link Up/Down and other generic
372 * notifications/callbacks */
374 /** Bluetooth DM callback structure. */
376 /** set to sizeof(bt_callbacks_t) */
378 adapter_state_changed_callback adapter_state_changed_cb;
379 adapter_properties_callback adapter_properties_cb;
380 remote_device_properties_callback remote_device_properties_cb;
381 device_found_callback device_found_cb;
382 discovery_state_changed_callback discovery_state_changed_cb;
383 pin_request_callback pin_request_cb;
384 ssp_request_callback ssp_request_cb;
385 bond_state_changed_callback bond_state_changed_cb;
386 acl_state_changed_callback acl_state_changed_cb;
387 callback_thread_event thread_evt_cb;
388 dut_mode_recv_callback dut_mode_recv_cb;
389 le_test_mode_callback le_test_mode_cb;
390 energy_info_callback energy_info_cb;
393 typedef void (*alarm_cb)(void *data);
394 typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data);
395 typedef int (*acquire_wake_lock_callout)(const char *lock_name);
396 typedef int (*release_wake_lock_callout)(const char *lock_name);
398 /** The set of functions required by bluedroid to set wake alarms and
399 * grab wake locks. This struct is passed into the stack through the
400 * |set_os_callouts| function on |bt_interface_t|.
403 /* set to sizeof(bt_os_callouts_t) */
406 set_wake_alarm_callout set_wake_alarm;
407 acquire_wake_lock_callout acquire_wake_lock;
408 release_wake_lock_callout release_wake_lock;
411 /** NOTE: By default, no profiles are initialized at the time of init/enable.
412 * Whenever the application invokes the 'init' API of a profile, then one of
413 * the following shall occur:
415 * 1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
416 * profile as enabled. Subsequently, when the application invokes the
417 * Bluetooth 'enable', as part of the enable sequence the profile that were
418 * marked shall be enabled by calling appropriate stack APIs. The
419 * 'adapter_properties_cb' shall return the list of UUIDs of the
422 * 2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the stack
423 * profile API to initialize the profile and trigger a
424 * 'adapter_properties_cb' with the current list of UUIDs including the
425 * newly added profile's UUID.
427 * The reverse shall occur whenever the profile 'cleanup' APIs are invoked
430 /** Represents the standard Bluetooth DM interface. */
432 /** set to sizeof(bt_interface_t) */
435 * Opens the interface and provides the callback routines
436 * to the implemenation of this interface.
438 int (*init)(bt_callbacks_t* callbacks );
440 /** Enable Bluetooth. */
443 /** Disable Bluetooth. */
444 int (*disable)(void);
446 /** Closes the interface. */
447 void (*cleanup)(void);
449 /** Get all Bluetooth Adapter properties at init */
450 int (*get_adapter_properties)(void);
452 /** Get Bluetooth Adapter property of 'type' */
453 int (*get_adapter_property)(bt_property_type_t type);
455 /** Set Bluetooth Adapter property of 'type' */
456 /* Based on the type, val shall be one of
457 * bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc
459 int (*set_adapter_property)(const bt_property_t *property);
461 /** Get all Remote Device properties */
462 int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr);
464 /** Get Remote Device property of 'type' */
465 int (*get_remote_device_property)(bt_bdaddr_t *remote_addr,
466 bt_property_type_t type);
468 /** Set Remote Device property of 'type' */
469 int (*set_remote_device_property)(bt_bdaddr_t *remote_addr,
470 const bt_property_t *property);
472 /** Get Remote Device's service record for the given UUID */
473 int (*get_remote_service_record)(bt_bdaddr_t *remote_addr,
476 /** Start SDP to get remote services */
477 int (*get_remote_services)(bt_bdaddr_t *remote_addr);
479 /** Start Discovery */
480 int (*start_discovery)(void);
482 /** Cancel Discovery */
483 int (*cancel_discovery)(void);
485 /** Create Bluetooth Bonding */
486 int (*create_bond)(const bt_bdaddr_t *bd_addr, int transport);
489 int (*remove_bond)(const bt_bdaddr_t *bd_addr);
492 int (*cancel_bond)(const bt_bdaddr_t *bd_addr);
495 * Get the connection status for a given remote device.
496 * return value of 0 means the device is not connected,
497 * non-zero return status indicates an active connection.
499 int (*get_connection_state)(const bt_bdaddr_t *bd_addr);
501 /** BT Legacy PinKey Reply */
502 /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
503 int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,
504 uint8_t pin_len, bt_pin_code_t *pin_code);
506 /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
507 * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
508 * BT_SSP_VARIANT_CONSENT
509 * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
511 int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
512 uint8_t accept, uint32_t passkey);
514 /** Get Bluetooth profile interface */
515 const void* (*get_profile_interface) (const char *profile_id);
517 /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
518 /* Configure DUT Mode - Use this mode to enter/exit DUT mode */
519 int (*dut_mode_configure)(uint8_t enable);
521 /* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */
522 int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len);
523 /** BLE Test Mode APIs */
524 /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */
525 int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);
527 /* enable or disable bluetooth HCI snoop log */
528 int (*config_hci_snoop_log)(uint8_t enable);
530 /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks.
531 * This should be called immediately after a successful |init|.
533 int (*set_os_callouts)(bt_os_callouts_t *callouts);
535 /** Read Energy info details - return value indicates BT_STATUS_SUCCESS or BT_STATUS_NOT_READY
536 * Success indicates that the VSC command was sent to controller
538 int (*read_energy_info)();
541 * Native support for dumpsys function
542 * Function is synchronous and |fd| is owned by caller.
544 void (*dump)(int fd);
547 * Clear /data/misc/bt_config.conf and erase all stored connections
549 int (*config_clear)(void);
552 * Clear (reset) the dynamic portion of the device interoperability database.
554 void (*interop_database_clear)(void);
557 * Add a new device interoperability workaround for a remote device whose
558 * first |len| bytes of the its device address match |addr|.
559 * NOTE: |feature| has to match an item defined in interop_feature_t (interop.h).
561 void (*interop_database_add)(uint16_t feature, const bt_bdaddr_t *addr, size_t len);
564 /** TODO: Need to add APIs for Service Discovery, Service authorization and
565 * connection management. Also need to add APIs for configuring
566 * properties of remote bonded devices such as name, UUID etc. */
569 struct hw_device_t common;
570 const bt_interface_t* (*get_bluetooth_interface)();
571 } bluetooth_device_t;
573 typedef bluetooth_device_t bluetooth_module_t;
578 #endif /* ANDROID_INCLUDE_BLUETOOTH_H */