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