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
21 #include <sys/cdefs.h>
22 #include <sys/types.h>
24 #include <hardware/hardware.h>
29 * The Bluetooth Hardware Module ID
32 #define BT_HARDWARE_MODULE_ID "bluetooth"
33 #define BT_STACK_MODULE_ID "bluetooth"
34 #define BT_STACK_TEST_MODULE_ID "bluetooth_test"
37 /* Bluetooth profile interface IDs */
39 #define BT_PROFILE_HANDSFREE_ID "handsfree"
40 #define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
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_PAN_ID "pan"
47 /** Bluetooth Address */
50 } __attribute__((packed
))bt_bdaddr_t
;
52 /** Bluetooth Device Name */
55 } __attribute__((packed
))bt_bdname_t
;
57 /** Bluetooth Adapter Visibility Modes*/
60 BT_SCAN_MODE_CONNECTABLE
,
61 BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
64 /** Bluetooth Adapter State */
70 /** Bluetooth Error Status */
71 /** We need to build on this */
79 BT_STATUS_DONE
, /* request already completed */
80 BT_STATUS_UNSUPPORTED
,
81 BT_STATUS_PARM_INVALID
,
83 BT_STATUS_AUTH_FAILURE
,
84 BT_STATUS_RMT_DEV_DOWN
88 /** Bluetooth PinKey Code */
91 } __attribute__((packed
))bt_pin_code_t
;
93 /** Bluetooth Adapter Discovery state */
97 } bt_discovery_state_t
;
99 /** Bluetooth ACL connection state */
101 BT_ACL_STATE_CONNECTED
,
102 BT_ACL_STATE_DISCONNECTED
105 /** Bluetooth 128-bit UUID */
110 /** Bluetooth SDP service record */
115 char name
[256]; // what's the maximum length
116 } bt_service_record_t
;
118 /* Bluetooth Adapter and Remote Device property types */
120 /* Properties common to both adapter and remote device */
122 * Description - Bluetooth Device Name
123 * Access mode - Adapter name can be GET/SET. Remote device can be GET
124 * Data type - bt_bdname_t
126 BT_PROPERTY_BDNAME
= 0x1,
128 * Description - Bluetooth Device Address
129 * Access mode - Only GET.
130 * Data type - bt_bdaddr_t
134 * Description - Bluetooth Service 128-bit UUIDs
135 * Access mode - Only GET.
136 * Data type - Array of bt_uuid_t (Array size inferred from property length).
140 * Description - Bluetooth Class of Device as found in Assigned Numbers
141 * Access mode - Only GET.
142 * Data type - uint32_t.
144 BT_PROPERTY_CLASS_OF_DEVICE
,
146 * Description - Device Type - BREDR, BLE or DUAL Mode
147 * Access mode - Only GET.
148 * Data type - bt_device_type_t
150 BT_PROPERTY_TYPE_OF_DEVICE
,
152 * Description - Bluetooth Service Record
153 * Access mode - Only GET.
154 * Data type - bt_service_record_t
156 BT_PROPERTY_SERVICE_RECORD
,
158 /* Properties unique to adapter */
160 * Description - Bluetooth Adapter scan mode
161 * Access mode - GET and SET
162 * Data type - bt_scan_mode_t.
164 BT_PROPERTY_ADAPTER_SCAN_MODE
,
166 * Description - List of bonded devices
167 * Access mode - Only GET.
168 * Data type - Array of bt_bdaddr_t of the bonded remote devices
169 * (Array size inferred from property length).
171 BT_PROPERTY_ADAPTER_BONDED_DEVICES
,
173 * Description - Bluetooth Adapter Discovery timeout (in seconds)
174 * Access mode - GET and SET
175 * Data type - uint32_t
177 BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT
,
179 /* Properties unique to remote device */
181 * Description - User defined friendly name of the remote device
182 * Access mode - GET and SET
183 * Data type - bt_bdname_t.
185 BT_PROPERTY_REMOTE_FRIENDLY_NAME
,
187 * Description - RSSI value of the inquired remote device
188 * Access mode - Only GET.
189 * Data type - int32_t.
191 BT_PROPERTY_REMOTE_RSSI
,
193 BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP
= 0xFF,
194 } bt_property_type_t
;
196 /** Bluetooth Adapter Property data structure */
199 bt_property_type_t type
;
204 /** Bluetooth Device Type */
206 BT_DEVICE_DEVTYPE_BREDR
= 0x1,
207 BT_DEVICE_DEVTYPE_BLE
,
208 BT_DEVICE_DEVTYPE_DUAL
210 /** Bluetooth Bond state */
213 BT_BOND_STATE_BONDING
,
217 /** Bluetooth SSP Bonding Variant */
219 BT_SSP_VARIANT_PASSKEY_CONFIRMATION
,
220 BT_SSP_VARIANT_PASSKEY_ENTRY
,
221 BT_SSP_VARIANT_CONSENT
,
222 BT_SSP_VARIANT_PASSKEY_NOTIFICATION
225 #define BT_MAX_NUM_UUIDS 32
227 /** Bluetooth Interface callbacks */
229 /** Bluetooth Enable/Disable Callback. */
230 typedef void (*adapter_state_changed_callback
)(bt_state_t state
);
232 /** GET/SET Adapter Properties callback */
233 /* TODO: For the GET/SET property APIs/callbacks, we may need a session
234 * identifier to associate the call with the callback. This would be needed
235 * whenever more than one simultaneous instance of the same adapter_type
238 * If this is going to be handled in the Java framework, then we do not need
239 * to manage sessions here.
241 typedef void (*adapter_properties_callback
)(bt_status_t status
,
243 bt_property_t
*properties
);
245 /** GET/SET Remote Device Properties callback */
246 /** TODO: For remote device properties, do not see a need to get/set
247 * multiple properties - num_properties shall be 1
249 typedef void (*remote_device_properties_callback
)(bt_status_t status
,
250 bt_bdaddr_t
*bd_addr
,
252 bt_property_t
*properties
);
254 /** New device discovered callback */
255 /** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1
257 typedef void (*device_found_callback
)(int num_properties
,
258 bt_property_t
*properties
);
260 /** Discovery state changed callback */
261 typedef void (*discovery_state_changed_callback
)(bt_discovery_state_t state
);
263 /** Bluetooth Legacy PinKey Request callback */
264 typedef void (*pin_request_callback
)(bt_bdaddr_t
*remote_bd_addr
,
265 bt_bdname_t
*bd_name
, uint32_t cod
);
267 /** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
268 /** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT &
269 * BT_SSP_PAIRING_PASSKEY_ENTRY */
270 /* TODO: Passkey request callback shall not be needed for devices with display
271 * capability. We still need support this in the stack for completeness */
272 typedef void (*ssp_request_callback
)(bt_bdaddr_t
*remote_bd_addr
,
273 bt_bdname_t
*bd_name
,
275 bt_ssp_variant_t pairing_variant
,
278 /** Bluetooth Bond state changed callback */
279 /* Invoked in response to create_bond, cancel_bond or remove_bond */
280 typedef void (*bond_state_changed_callback
)(bt_status_t status
,
281 bt_bdaddr_t
*remote_bd_addr
,
282 bt_bond_state_t state
);
284 /** Bluetooth ACL connection state changed callback */
285 typedef void (*acl_state_changed_callback
)(bt_status_t status
, bt_bdaddr_t
*remote_bd_addr
,
286 bt_acl_state_t state
);
293 /** Thread Associate/Disassociate JVM Callback */
294 /* Callback that is invoked by the callback thread to allow upper layer to attach/detach to/from
296 typedef void (*callback_thread_event
)(bt_cb_thread_evt evt
);
298 /** Bluetooth Test Mode Callback */
299 /* Receive any HCI event from controller. Must be in DUT Mode for this callback to be received */
300 typedef void (*dut_mode_recv_callback
)(uint16_t opcode
, uint8_t *buf
, uint8_t len
);
302 /** TODO: Add callbacks for Link Up/Down and other generic
303 * notifications/callbacks */
305 /** Bluetooth DM callback structure. */
307 /** set to sizeof(bt_callbacks_t) */
309 adapter_state_changed_callback adapter_state_changed_cb
;
310 adapter_properties_callback adapter_properties_cb
;
311 remote_device_properties_callback remote_device_properties_cb
;
312 device_found_callback device_found_cb
;
313 discovery_state_changed_callback discovery_state_changed_cb
;
314 pin_request_callback pin_request_cb
;
315 ssp_request_callback ssp_request_cb
;
316 bond_state_changed_callback bond_state_changed_cb
;
317 acl_state_changed_callback acl_state_changed_cb
;
318 callback_thread_event thread_evt_cb
;
319 dut_mode_recv_callback dut_mode_recv_cb
;
322 /** NOTE: By default, no profiles are initialized at the time of init/enable.
323 * Whenever the application invokes the 'init' API of a profile, then one of
324 * the following shall occur:
326 * 1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
327 * profile as enabled. Subsequently, when the application invokes the
328 * Bluetooth 'enable', as part of the enable sequence the profile that were
329 * marked shall be enabled by calling appropriate stack APIs. The
330 * 'adapter_properties_cb' shall return the list of UUIDs of the
333 * 2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the stack
334 * profile API to initialize the profile and trigger a
335 * 'adapter_properties_cb' with the current list of UUIDs including the
336 * newly added profile's UUID.
338 * The reverse shall occur whenever the profile 'cleanup' APIs are invoked
341 /** Represents the standard Bluetooth DM interface. */
343 /** set to sizeof(bt_interface_t) */
346 * Opens the interface and provides the callback routines
347 * to the implemenation of this interface.
349 int (*init
)(bt_callbacks_t
* callbacks
);
351 /** Enable Bluetooth. */
354 /** Disable Bluetooth. */
355 int (*disable
)(void);
357 /** Closes the interface. */
358 void (*cleanup
)(void);
360 /** Get all Bluetooth Adapter properties at init */
361 int (*get_adapter_properties
)(void);
363 /** Get Bluetooth Adapter property of 'type' */
364 int (*get_adapter_property
)(bt_property_type_t type
);
366 /** Set Bluetooth Adapter property of 'type' */
367 /* Based on the type, val shall be one of
368 * bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc
370 int (*set_adapter_property
)(const bt_property_t
*property
);
372 /** Get all Remote Device properties */
373 int (*get_remote_device_properties
)(bt_bdaddr_t
*remote_addr
);
375 /** Get Remote Device property of 'type' */
376 int (*get_remote_device_property
)(bt_bdaddr_t
*remote_addr
,
377 bt_property_type_t type
);
379 /** Set Remote Device property of 'type' */
380 int (*set_remote_device_property
)(bt_bdaddr_t
*remote_addr
,
381 const bt_property_t
*property
);
383 /** Get Remote Device's service record for the given UUID */
384 int (*get_remote_service_record
)(bt_bdaddr_t
*remote_addr
,
387 /** Start SDP to get remote services */
388 int (*get_remote_services
)(bt_bdaddr_t
*remote_addr
);
390 /** Start Discovery */
391 int (*start_discovery
)(void);
393 /** Cancel Discovery */
394 int (*cancel_discovery
)(void);
396 /** Create Bluetooth Bonding */
397 int (*create_bond
)(const bt_bdaddr_t
*bd_addr
);
400 int (*remove_bond
)(const bt_bdaddr_t
*bd_addr
);
403 int (*cancel_bond
)(const bt_bdaddr_t
*bd_addr
);
405 /** BT Legacy PinKey Reply */
406 /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
407 int (*pin_reply
)(const bt_bdaddr_t
*bd_addr
, uint8_t accept
,
408 uint8_t pin_len
, bt_pin_code_t
*pin_code
);
410 /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
411 * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
412 * BT_SSP_VARIANT_CONSENT
413 * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
415 int (*ssp_reply
)(const bt_bdaddr_t
*bd_addr
, bt_ssp_variant_t variant
,
416 uint8_t accept
, uint32_t passkey
);
418 /** Get Bluetooth profile interface */
419 const void* (*get_profile_interface
) (const char *profile_id
);
421 /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
422 /* Configure DUT Mode - Use this mode to enter/exit DUT mode */
423 int (*dut_mode_configure
)(uint8_t enable
);
425 /* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */
426 int (*dut_mode_send
)(uint16_t opcode
, uint8_t *buf
, uint8_t len
);
429 /** TODO: Need to add APIs for Service Discovery, Service authorization and
430 * connection management. Also need to add APIs for configuring
431 * properties of remote bonded devices such as name, UUID etc. */
434 struct hw_device_t common
;
435 const bt_interface_t
* (*get_bluetooth_interface
)();
436 } bluetooth_device_t
;
438 typedef bluetooth_device_t bluetooth_module_t
;
441 #endif /* ANDROID_INCLUDE_BLUETOOTH_H */