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