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