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