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