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