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