blob: a63a49cb93867f7798e136b084232d8da50052db [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"
Hemant Guptae7737c82013-08-19 18:02:54 +053040#define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
Andre Eisenbach05f49542012-09-18 12:15:26 -070041#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
364/** NOTE: By default, no profiles are initialized at the time of init/enable.
365 * Whenever the application invokes the 'init' API of a profile, then one of
366 * the following shall occur:
367 *
368 * 1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
369 * profile as enabled. Subsequently, when the application invokes the
370 * Bluetooth 'enable', as part of the enable sequence the profile that were
371 * marked shall be enabled by calling appropriate stack APIs. The
372 * 'adapter_properties_cb' shall return the list of UUIDs of the
373 * enabled profiles.
374 *
375 * 2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the stack
376 * profile API to initialize the profile and trigger a
377 * 'adapter_properties_cb' with the current list of UUIDs including the
378 * newly added profile's UUID.
379 *
380 * The reverse shall occur whenever the profile 'cleanup' APIs are invoked
381 */
382
383/** Represents the standard Bluetooth DM interface. */
384typedef struct {
385 /** set to sizeof(bt_interface_t) */
386 size_t size;
387 /**
388 * Opens the interface and provides the callback routines
389 * to the implemenation of this interface.
390 */
391 int (*init)(bt_callbacks_t* callbacks );
392
393 /** Enable Bluetooth. */
394 int (*enable)(void);
395
396 /** Disable Bluetooth. */
397 int (*disable)(void);
398
399 /** Closes the interface. */
400 void (*cleanup)(void);
401
402 /** Get all Bluetooth Adapter properties at init */
403 int (*get_adapter_properties)(void);
404
405 /** Get Bluetooth Adapter property of 'type' */
406 int (*get_adapter_property)(bt_property_type_t type);
407
408 /** Set Bluetooth Adapter property of 'type' */
409 /* Based on the type, val shall be one of
410 * bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc
411 */
412 int (*set_adapter_property)(const bt_property_t *property);
413
414 /** Get all Remote Device properties */
415 int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr);
416
417 /** Get Remote Device property of 'type' */
418 int (*get_remote_device_property)(bt_bdaddr_t *remote_addr,
419 bt_property_type_t type);
420
421 /** Set Remote Device property of 'type' */
422 int (*set_remote_device_property)(bt_bdaddr_t *remote_addr,
423 const bt_property_t *property);
424
425 /** Get Remote Device's service record for the given UUID */
426 int (*get_remote_service_record)(bt_bdaddr_t *remote_addr,
427 bt_uuid_t *uuid);
428
429 /** Start SDP to get remote services */
430 int (*get_remote_services)(bt_bdaddr_t *remote_addr);
431
432 /** Start Discovery */
433 int (*start_discovery)(void);
434
435 /** Cancel Discovery */
436 int (*cancel_discovery)(void);
437
438 /** Create Bluetooth Bonding */
439 int (*create_bond)(const bt_bdaddr_t *bd_addr);
440
441 /** Remove Bond */
442 int (*remove_bond)(const bt_bdaddr_t *bd_addr);
443
444 /** Cancel Bond */
445 int (*cancel_bond)(const bt_bdaddr_t *bd_addr);
446
447 /** BT Legacy PinKey Reply */
448 /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
449 int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,
450 uint8_t pin_len, bt_pin_code_t *pin_code);
451
452 /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
453 * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
454 * BT_SSP_VARIANT_CONSENT
455 * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
456 * shall be zero */
457 int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
458 uint8_t accept, uint32_t passkey);
459
460 /** Get Bluetooth profile interface */
461 const void* (*get_profile_interface) (const char *profile_id);
462
463 /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
464 /* Configure DUT Mode - Use this mode to enter/exit DUT mode */
465 int (*dut_mode_configure)(uint8_t enable);
466
467 /* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */
468 int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800469 /** BLE Test Mode APIs */
470 /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */
471 int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);
472
Zhihai Xua17b75b2013-06-10 20:23:45 -0700473 /* enable or disable bluetooth HCI snoop log */
474 int (*config_hci_snoop_log)(uint8_t enable);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700475} bt_interface_t;
476
477/** TODO: Need to add APIs for Service Discovery, Service authorization and
478 * connection management. Also need to add APIs for configuring
479 * properties of remote bonded devices such as name, UUID etc. */
480
481typedef struct {
482 struct hw_device_t common;
483 const bt_interface_t* (*get_bluetooth_interface)();
484} bluetooth_device_t;
485
486typedef bluetooth_device_t bluetooth_module_t;
487__END_DECLS
488
489#endif /* ANDROID_INCLUDE_BLUETOOTH_H */