blob: 4d38ff769d5bc313dc073e451cbcb801fcbd6cbd [file] [log] [blame]
Andre Eisenbach05f49542012-09-18 12:15:26 -07001/*
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 Nanavati3bd8cba2014-05-30 16:43:38 -070020#include <stdbool.h>
Andre Eisenbach05f49542012-09-18 12:15:26 -070021#include <stdint.h>
22#include <sys/cdefs.h>
23#include <sys/types.h>
24
25#include <hardware/hardware.h>
26
27__BEGIN_DECLS
28
29/**
30 * The Bluetooth Hardware Module ID
31 */
32
33#define BT_HARDWARE_MODULE_ID "bluetooth"
34#define BT_STACK_MODULE_ID "bluetooth"
35#define BT_STACK_TEST_MODULE_ID "bluetooth_test"
36
37
38/* Bluetooth profile interface IDs */
39
40#define BT_PROFILE_HANDSFREE_ID "handsfree"
Hemant Guptae7737c82013-08-19 18:02:54 +053041#define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
Andre Eisenbach05f49542012-09-18 12:15:26 -070042#define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
Mike Lockwood21e50b12014-06-07 14:05:22 -070043#define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
Andre Eisenbach05f49542012-09-18 12:15:26 -070044#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"
Hemant Gupta053cccf2014-04-18 12:25:24 +053048#define BT_PROFILE_MAP_CLIENT_ID "map_client"
Andre Eisenbach05f49542012-09-18 12:15:26 -070049
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080050#define BT_PROFILE_GATT_ID "gatt"
Ravi Nagarajan482ba782013-02-26 10:34:41 -080051#define BT_PROFILE_AV_RC_ID "avrcp"
Mike Lockwood7da4cb82014-06-02 16:20:51 -070052#define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
Andre Eisenbach05f49542012-09-18 12:15:26 -070053
54/** Bluetooth Address */
55typedef struct {
56 uint8_t address[6];
57} __attribute__((packed))bt_bdaddr_t;
58
59/** Bluetooth Device Name */
60typedef struct {
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080061 uint8_t name[249];
Andre Eisenbach05f49542012-09-18 12:15:26 -070062} __attribute__((packed))bt_bdname_t;
63
64/** Bluetooth Adapter Visibility Modes*/
65typedef enum {
66 BT_SCAN_MODE_NONE,
67 BT_SCAN_MODE_CONNECTABLE,
68 BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
69} bt_scan_mode_t;
70
71/** Bluetooth Adapter State */
72typedef enum {
73 BT_STATE_OFF,
74 BT_STATE_ON
75} bt_state_t;
76
77/** Bluetooth Error Status */
78/** We need to build on this */
79
80typedef enum {
81 BT_STATUS_SUCCESS,
82 BT_STATUS_FAIL,
83 BT_STATUS_NOT_READY,
84 BT_STATUS_NOMEM,
85 BT_STATUS_BUSY,
86 BT_STATUS_DONE, /* request already completed */
87 BT_STATUS_UNSUPPORTED,
88 BT_STATUS_PARM_INVALID,
89 BT_STATUS_UNHANDLED,
90 BT_STATUS_AUTH_FAILURE,
Hemant Gupta4d864552013-07-31 19:14:02 +053091 BT_STATUS_RMT_DEV_DOWN,
92 BT_STATUS_AUTH_REJECTED
Andre Eisenbach05f49542012-09-18 12:15:26 -070093
94} bt_status_t;
95
96/** Bluetooth PinKey Code */
97typedef struct {
98 uint8_t pin[16];
99} __attribute__((packed))bt_pin_code_t;
100
101/** Bluetooth Adapter Discovery state */
102typedef enum {
103 BT_DISCOVERY_STOPPED,
104 BT_DISCOVERY_STARTED
105} bt_discovery_state_t;
106
107/** Bluetooth ACL connection state */
108typedef enum {
109 BT_ACL_STATE_CONNECTED,
110 BT_ACL_STATE_DISCONNECTED
111} bt_acl_state_t;
112
113/** Bluetooth 128-bit UUID */
114typedef struct {
115 uint8_t uu[16];
116} bt_uuid_t;
117
118/** Bluetooth SDP service record */
119typedef struct
120{
121 bt_uuid_t uuid;
122 uint16_t channel;
123 char name[256]; // what's the maximum length
124} bt_service_record_t;
125
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800126
127/** Bluetooth Remote Version info */
128typedef struct
129{
130 int version;
131 int sub_ver;
132 int manufacturer;
133} bt_remote_version_t;
134
Ganesh Ganapathi Batta460343a2014-05-27 16:03:11 -0700135typedef struct
136{
137 uint8_t local_privacy_enabled;
138 uint8_t max_adv_instance;
139 uint8_t rpa_offload_supported;
140 uint8_t max_irk_list_size;
141 uint8_t max_adv_filter_supported;
142 uint8_t scan_result_storage_size;
143}bt_local_le_features_t;
144
Andre Eisenbach05f49542012-09-18 12:15:26 -0700145/* Bluetooth Adapter and Remote Device property types */
146typedef enum {
147 /* Properties common to both adapter and remote device */
148 /**
149 * Description - Bluetooth Device Name
150 * Access mode - Adapter name can be GET/SET. Remote device can be GET
151 * Data type - bt_bdname_t
152 */
153 BT_PROPERTY_BDNAME = 0x1,
154 /**
155 * Description - Bluetooth Device Address
156 * Access mode - Only GET.
157 * Data type - bt_bdaddr_t
158 */
159 BT_PROPERTY_BDADDR,
160 /**
161 * Description - Bluetooth Service 128-bit UUIDs
162 * Access mode - Only GET.
163 * Data type - Array of bt_uuid_t (Array size inferred from property length).
164 */
165 BT_PROPERTY_UUIDS,
166 /**
167 * Description - Bluetooth Class of Device as found in Assigned Numbers
168 * Access mode - Only GET.
169 * Data type - uint32_t.
170 */
171 BT_PROPERTY_CLASS_OF_DEVICE,
172 /**
173 * Description - Device Type - BREDR, BLE or DUAL Mode
174 * Access mode - Only GET.
175 * Data type - bt_device_type_t
176 */
177 BT_PROPERTY_TYPE_OF_DEVICE,
178 /**
179 * Description - Bluetooth Service Record
180 * Access mode - Only GET.
181 * Data type - bt_service_record_t
182 */
183 BT_PROPERTY_SERVICE_RECORD,
184
185 /* Properties unique to adapter */
186 /**
187 * Description - Bluetooth Adapter scan mode
188 * Access mode - GET and SET
189 * Data type - bt_scan_mode_t.
190 */
191 BT_PROPERTY_ADAPTER_SCAN_MODE,
192 /**
193 * Description - List of bonded devices
194 * Access mode - Only GET.
195 * Data type - Array of bt_bdaddr_t of the bonded remote devices
196 * (Array size inferred from property length).
197 */
198 BT_PROPERTY_ADAPTER_BONDED_DEVICES,
199 /**
200 * Description - Bluetooth Adapter Discovery timeout (in seconds)
201 * Access mode - GET and SET
202 * Data type - uint32_t
203 */
204 BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
205
206 /* Properties unique to remote device */
207 /**
208 * Description - User defined friendly name of the remote device
209 * Access mode - GET and SET
210 * Data type - bt_bdname_t.
211 */
212 BT_PROPERTY_REMOTE_FRIENDLY_NAME,
213 /**
214 * Description - RSSI value of the inquired remote device
215 * Access mode - Only GET.
216 * Data type - int32_t.
217 */
218 BT_PROPERTY_REMOTE_RSSI,
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800219 /**
220 * Description - Remote version info
221 * Access mode - SET/GET.
222 * Data type - bt_remote_version_t.
223 */
224
225 BT_PROPERTY_REMOTE_VERSION_INFO,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700226
Ganesh Ganapathi Batta460343a2014-05-27 16:03:11 -0700227 /**
228 * Description - Local LE features
229 * Access mode - GET.
230 * Data type - bt_local_le_features_t.
231 */
232 BT_PROPERTY_LOCAL_LE_FEATURES,
233
Andre Eisenbach05f49542012-09-18 12:15:26 -0700234 BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
235} bt_property_type_t;
236
237/** Bluetooth Adapter Property data structure */
238typedef struct
239{
240 bt_property_type_t type;
241 int len;
242 void *val;
243} bt_property_t;
244
Ganesh Ganapathi Batta460343a2014-05-27 16:03:11 -0700245
Andre Eisenbach05f49542012-09-18 12:15:26 -0700246/** Bluetooth Device Type */
247typedef enum {
248 BT_DEVICE_DEVTYPE_BREDR = 0x1,
249 BT_DEVICE_DEVTYPE_BLE,
250 BT_DEVICE_DEVTYPE_DUAL
251} bt_device_type_t;
252/** Bluetooth Bond state */
253typedef enum {
254 BT_BOND_STATE_NONE,
255 BT_BOND_STATE_BONDING,
256 BT_BOND_STATE_BONDED
257} bt_bond_state_t;
258
259/** Bluetooth SSP Bonding Variant */
260typedef enum {
261 BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
262 BT_SSP_VARIANT_PASSKEY_ENTRY,
263 BT_SSP_VARIANT_CONSENT,
264 BT_SSP_VARIANT_PASSKEY_NOTIFICATION
265} bt_ssp_variant_t;
266
267#define BT_MAX_NUM_UUIDS 32
268
269/** Bluetooth Interface callbacks */
270
271/** Bluetooth Enable/Disable Callback. */
272typedef void (*adapter_state_changed_callback)(bt_state_t state);
273
274/** GET/SET Adapter Properties callback */
275/* TODO: For the GET/SET property APIs/callbacks, we may need a session
276 * identifier to associate the call with the callback. This would be needed
277 * whenever more than one simultaneous instance of the same adapter_type
278 * is get/set.
279 *
280 * If this is going to be handled in the Java framework, then we do not need
281 * to manage sessions here.
282 */
283typedef void (*adapter_properties_callback)(bt_status_t status,
284 int num_properties,
285 bt_property_t *properties);
286
287/** GET/SET Remote Device Properties callback */
288/** TODO: For remote device properties, do not see a need to get/set
289 * multiple properties - num_properties shall be 1
290 */
291typedef void (*remote_device_properties_callback)(bt_status_t status,
292 bt_bdaddr_t *bd_addr,
293 int num_properties,
294 bt_property_t *properties);
295
296/** New device discovered callback */
297/** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1
298 * respectively */
299typedef void (*device_found_callback)(int num_properties,
300 bt_property_t *properties);
301
302/** Discovery state changed callback */
303typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state);
304
305/** Bluetooth Legacy PinKey Request callback */
306typedef void (*pin_request_callback)(bt_bdaddr_t *remote_bd_addr,
307 bt_bdname_t *bd_name, uint32_t cod);
308
309/** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
310/** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT &
311 * BT_SSP_PAIRING_PASSKEY_ENTRY */
312/* TODO: Passkey request callback shall not be needed for devices with display
313 * capability. We still need support this in the stack for completeness */
314typedef void (*ssp_request_callback)(bt_bdaddr_t *remote_bd_addr,
315 bt_bdname_t *bd_name,
316 uint32_t cod,
317 bt_ssp_variant_t pairing_variant,
318 uint32_t pass_key);
319
320/** Bluetooth Bond state changed callback */
321/* Invoked in response to create_bond, cancel_bond or remove_bond */
322typedef void (*bond_state_changed_callback)(bt_status_t status,
323 bt_bdaddr_t *remote_bd_addr,
324 bt_bond_state_t state);
325
326/** Bluetooth ACL connection state changed callback */
327typedef void (*acl_state_changed_callback)(bt_status_t status, bt_bdaddr_t *remote_bd_addr,
328 bt_acl_state_t state);
329
330typedef enum {
331 ASSOCIATE_JVM,
332 DISASSOCIATE_JVM
333} bt_cb_thread_evt;
334
335/** Thread Associate/Disassociate JVM Callback */
336/* Callback that is invoked by the callback thread to allow upper layer to attach/detach to/from
337 * the JVM */
338typedef void (*callback_thread_event)(bt_cb_thread_evt evt);
339
340/** Bluetooth Test Mode Callback */
341/* Receive any HCI event from controller. Must be in DUT Mode for this callback to be received */
342typedef void (*dut_mode_recv_callback)(uint16_t opcode, uint8_t *buf, uint8_t len);
343
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800344/* LE Test mode callbacks
345* This callback shall be invoked whenever the le_tx_test, le_rx_test or le_test_end is invoked
346* The num_packets is valid only for le_test_end command */
347typedef void (*le_test_mode_callback)(bt_status_t status, uint16_t num_packets);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700348/** TODO: Add callbacks for Link Up/Down and other generic
349 * notifications/callbacks */
350
351/** Bluetooth DM callback structure. */
352typedef struct {
353 /** set to sizeof(bt_callbacks_t) */
354 size_t size;
355 adapter_state_changed_callback adapter_state_changed_cb;
356 adapter_properties_callback adapter_properties_cb;
357 remote_device_properties_callback remote_device_properties_cb;
358 device_found_callback device_found_cb;
359 discovery_state_changed_callback discovery_state_changed_cb;
360 pin_request_callback pin_request_cb;
361 ssp_request_callback ssp_request_cb;
362 bond_state_changed_callback bond_state_changed_cb;
363 acl_state_changed_callback acl_state_changed_cb;
364 callback_thread_event thread_evt_cb;
365 dut_mode_recv_callback dut_mode_recv_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800366 le_test_mode_callback le_test_mode_cb;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700367} bt_callbacks_t;
368
Sharvil Nanavati3bd8cba2014-05-30 16:43:38 -0700369typedef void (*alarm_cb)(void *data);
370typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data);
371typedef int (*acquire_wake_lock_callout)(const char *lock_name);
372typedef int (*release_wake_lock_callout)(const char *lock_name);
373
374/** The set of functions required by bluedroid to set wake alarms and
375 * grab wake locks. This struct is passed into the stack through the
376 * |set_os_callouts| function on |bt_interface_t|.
377 */
378typedef struct {
379 /* set to sizeof(bt_os_callouts_t) */
380 size_t size;
381
382 set_wake_alarm_callout set_wake_alarm;
383 acquire_wake_lock_callout acquire_wake_lock;
384 release_wake_lock_callout release_wake_lock;
385} bt_os_callouts_t;
386
Andre Eisenbach05f49542012-09-18 12:15:26 -0700387/** NOTE: By default, no profiles are initialized at the time of init/enable.
388 * Whenever the application invokes the 'init' API of a profile, then one of
389 * the following shall occur:
390 *
391 * 1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
392 * profile as enabled. Subsequently, when the application invokes the
393 * Bluetooth 'enable', as part of the enable sequence the profile that were
394 * marked shall be enabled by calling appropriate stack APIs. The
395 * 'adapter_properties_cb' shall return the list of UUIDs of the
396 * enabled profiles.
397 *
398 * 2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the stack
399 * profile API to initialize the profile and trigger a
400 * 'adapter_properties_cb' with the current list of UUIDs including the
401 * newly added profile's UUID.
402 *
403 * The reverse shall occur whenever the profile 'cleanup' APIs are invoked
404 */
405
406/** Represents the standard Bluetooth DM interface. */
407typedef struct {
408 /** set to sizeof(bt_interface_t) */
409 size_t size;
410 /**
411 * Opens the interface and provides the callback routines
412 * to the implemenation of this interface.
413 */
414 int (*init)(bt_callbacks_t* callbacks );
415
416 /** Enable Bluetooth. */
417 int (*enable)(void);
418
419 /** Disable Bluetooth. */
420 int (*disable)(void);
421
422 /** Closes the interface. */
423 void (*cleanup)(void);
424
425 /** Get all Bluetooth Adapter properties at init */
426 int (*get_adapter_properties)(void);
427
428 /** Get Bluetooth Adapter property of 'type' */
429 int (*get_adapter_property)(bt_property_type_t type);
430
431 /** Set Bluetooth Adapter property of 'type' */
432 /* Based on the type, val shall be one of
433 * bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc
434 */
435 int (*set_adapter_property)(const bt_property_t *property);
436
437 /** Get all Remote Device properties */
438 int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr);
439
440 /** Get Remote Device property of 'type' */
441 int (*get_remote_device_property)(bt_bdaddr_t *remote_addr,
442 bt_property_type_t type);
443
444 /** Set Remote Device property of 'type' */
445 int (*set_remote_device_property)(bt_bdaddr_t *remote_addr,
446 const bt_property_t *property);
447
448 /** Get Remote Device's service record for the given UUID */
449 int (*get_remote_service_record)(bt_bdaddr_t *remote_addr,
450 bt_uuid_t *uuid);
451
452 /** Start SDP to get remote services */
453 int (*get_remote_services)(bt_bdaddr_t *remote_addr);
454
455 /** Start Discovery */
456 int (*start_discovery)(void);
457
458 /** Cancel Discovery */
459 int (*cancel_discovery)(void);
460
461 /** Create Bluetooth Bonding */
462 int (*create_bond)(const bt_bdaddr_t *bd_addr);
463
464 /** Remove Bond */
465 int (*remove_bond)(const bt_bdaddr_t *bd_addr);
466
467 /** Cancel Bond */
468 int (*cancel_bond)(const bt_bdaddr_t *bd_addr);
469
Andre Eisenbach0d553bc2014-06-18 12:18:34 -0700470 /**
471 * Get the connection status for a given remote device.
472 * return value of 0 means the device is not connected,
473 * non-zero return status indicates an active connection.
474 */
475 int (*get_connection_state)(const bt_bdaddr_t *bd_addr);
476
Andre Eisenbach05f49542012-09-18 12:15:26 -0700477 /** BT Legacy PinKey Reply */
478 /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
479 int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,
480 uint8_t pin_len, bt_pin_code_t *pin_code);
481
482 /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
483 * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
484 * BT_SSP_VARIANT_CONSENT
485 * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
486 * shall be zero */
487 int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
488 uint8_t accept, uint32_t passkey);
489
490 /** Get Bluetooth profile interface */
491 const void* (*get_profile_interface) (const char *profile_id);
492
493 /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
494 /* Configure DUT Mode - Use this mode to enter/exit DUT mode */
495 int (*dut_mode_configure)(uint8_t enable);
496
497 /* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */
498 int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800499 /** BLE Test Mode APIs */
500 /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */
501 int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);
502
Zhihai Xua17b75b2013-06-10 20:23:45 -0700503 /* enable or disable bluetooth HCI snoop log */
504 int (*config_hci_snoop_log)(uint8_t enable);
Sharvil Nanavati3bd8cba2014-05-30 16:43:38 -0700505
506 /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks.
507 * This should be called immediately after a successful |init|.
508 */
509 int (*set_os_callouts)(bt_os_callouts_t *callouts);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700510} bt_interface_t;
511
512/** TODO: Need to add APIs for Service Discovery, Service authorization and
513 * connection management. Also need to add APIs for configuring
514 * properties of remote bonded devices such as name, UUID etc. */
515
516typedef struct {
517 struct hw_device_t common;
518 const bt_interface_t* (*get_bluetooth_interface)();
519} bluetooth_device_t;
520
521typedef bluetooth_device_t bluetooth_module_t;
522__END_DECLS
523
524#endif /* ANDROID_INCLUDE_BLUETOOTH_H */