40cd96822d42a9860ce889a75a6f2cd7466ef3a2
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / hardware / bluetooth.h
1 /*
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 <stdbool.h>
21 #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_HANDSFREE_CLIENT_ID "handsfree_client"
42 #define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
43 #define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
44 #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"
48 #define BT_PROFILE_MAP_CLIENT_ID "map_client"
49
50 #define BT_PROFILE_GATT_ID "gatt"
51 #define BT_PROFILE_AV_RC_ID "avrcp"
52 #define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
53
54 /** Bluetooth Address */
55 typedef struct {
56     uint8_t address[6];
57 } __attribute__((packed))bt_bdaddr_t;
58
59 /** Bluetooth Device Name */
60 typedef struct {
61     uint8_t name[249];
62 } __attribute__((packed))bt_bdname_t;
63
64 /** Bluetooth Adapter Visibility Modes*/
65 typedef 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 */
72 typedef 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
80 typedef 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,
91     BT_STATUS_RMT_DEV_DOWN,
92     BT_STATUS_AUTH_REJECTED
93
94 } bt_status_t;
95
96 /** Bluetooth PinKey Code */
97 typedef struct {
98     uint8_t pin[16];
99 } __attribute__((packed))bt_pin_code_t;
100
101 typedef 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
110 /** Bluetooth Adapter Discovery state */
111 typedef enum {
112     BT_DISCOVERY_STOPPED,
113     BT_DISCOVERY_STARTED
114 } bt_discovery_state_t;
115
116 /** Bluetooth ACL connection state */
117 typedef enum {
118     BT_ACL_STATE_CONNECTED,
119     BT_ACL_STATE_DISCONNECTED
120 } bt_acl_state_t;
121
122 /** Remote Device Trusted state */
123 typedef enum {
124     BT_DEVICE_TRUSTED,
125     BT_DEVICE_NOT_TRUSTED
126 } bt_device_trust_state_t;
127
128 /** Bluetooth 128-bit UUID */
129 typedef struct {
130    uint8_t uu[16];
131 } bt_uuid_t;
132
133 /** Bluetooth SDP service record */
134 typedef struct
135 {
136    bt_uuid_t uuid;
137    uint16_t channel;
138    char name[256]; // what's the maximum length
139 } bt_service_record_t;
140
141
142 /** Bluetooth Remote Version info */
143 typedef struct
144 {
145    int version;
146    int sub_ver;
147    int manufacturer;
148 } bt_remote_version_t;
149
150 typedef struct
151 {
152     uint8_t local_privacy_enabled;
153     uint8_t max_adv_instance;
154     uint8_t rpa_offload_supported;
155     uint8_t max_irk_list_size;
156     uint8_t max_adv_filter_supported;
157     uint8_t scan_result_storage_size_lobyte;
158     uint8_t scan_result_storage_size_hibyte;
159     uint8_t activity_energy_info_supported;
160 }bt_local_le_features_t;
161
162 /* Bluetooth Adapter and Remote Device property types */
163 typedef enum {
164         /* Properties common to both adapter and remote device */
165         /**
166          * Description - Bluetooth Device Name
167          * Access mode - Adapter name can be GET/SET. Remote device can be GET
168          * Data type   - bt_bdname_t
169          */
170         BT_PROPERTY_BDNAME = 0x1,
171         /**
172          * Description - Bluetooth Device Address
173          * Access mode - Only GET.
174          * Data type   - bt_bdaddr_t
175          */
176         BT_PROPERTY_BDADDR,
177         /**
178          * Description - Bluetooth Service 128-bit UUIDs
179          * Access mode - Only GET.
180          * Data type   - Array of bt_uuid_t (Array size inferred from property length).
181          */
182         BT_PROPERTY_UUIDS,
183         /**
184          * Description - Bluetooth Class of Device as found in Assigned Numbers
185          * Access mode - Only GET.
186          * Data type   - uint32_t.
187          */
188         BT_PROPERTY_CLASS_OF_DEVICE,
189         /**
190          * Description - Device Type - BREDR, BLE or DUAL Mode
191          * Access mode - Only GET.
192          * Data type   - bt_device_type_t
193          */
194         BT_PROPERTY_TYPE_OF_DEVICE,
195         /**
196          * Description - Bluetooth Service Record
197          * Access mode - Only GET.
198          * Data type   - bt_service_record_t
199          */
200         BT_PROPERTY_SERVICE_RECORD,
201
202         /* Properties unique to adapter */
203         /**
204          * Description - Bluetooth Adapter scan mode
205          * Access mode - GET and SET
206          * Data type   - bt_scan_mode_t.
207          */
208         BT_PROPERTY_ADAPTER_SCAN_MODE,
209         /**
210          * Description - List of bonded devices
211          * Access mode - Only GET.
212          * Data type   - Array of bt_bdaddr_t of the bonded remote devices
213          *               (Array size inferred from property length).
214          */
215         BT_PROPERTY_ADAPTER_BONDED_DEVICES,
216         /**
217          * Description - Bluetooth Adapter Discovery timeout (in seconds)
218          * Access mode - GET and SET
219          * Data type   - uint32_t
220          */
221         BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
222
223         /* Properties unique to remote device */
224         /**
225          * Description - User defined friendly name of the remote device
226          * Access mode - GET and SET
227          * Data type   - bt_bdname_t.
228          */
229         BT_PROPERTY_REMOTE_FRIENDLY_NAME,
230         /**
231          * Description - RSSI value of the inquired remote device
232          * Access mode - Only GET.
233          * Data type   - int32_t.
234          */
235         BT_PROPERTY_REMOTE_RSSI,
236         /**
237          * Description - Remote version info
238          * Access mode - SET/GET.
239          * Data type   - bt_remote_version_t.
240          */
241
242         BT_PROPERTY_REMOTE_VERSION_INFO,
243
244         /* Tizen Specific Adapter and Remote Device properties */
245         /**
246          * Description - Remote Device paired Info
247          * Access mode - GET.
248          * Data type   - uint8_t.
249          */
250         BT_PROPERTY_REMOTE_PAIRED,
251
252         /**
253          * Description - Remote Device connected Info
254          * Access mode - GET.
255          * Data type   - unsigned int.
256          */
257         BT_PROPERTY_REMOTE_CONNECTED,
258
259         /**
260          * Description - Remote Device Trusted info
261          * Access mode - GET.
262          * Data type   - uint8_t.
263          */
264         BT_PROPERTY_REMOTE_TRUST,
265
266         /**
267          * Description - Adapter Pairable info
268          * Access mode - GET\SET.
269          * Data type   - uint8_t
270          */
271         BT_PROPERTY_PAIRABLE,
272
273         /**
274          * Description - Adapter pairable Timeout value
275          * Access mode - GET.
276          * Data type   - uint32_t
277          */
278         BT_PROPERTY_PAIRABLE_TIMEOUT,
279
280         /**
281          * Description - Adapter version
282          * Access mode - GET
283          * Data type   - Array of character string
284          */
285         BT_PROPERTY_VERSION,
286
287         /**
288          * Description - Adapter IPSP initialized state info
289          * Access mode - GET
290          * Data type   - uint8_t
291          */
292         BT_PROPERTY_IPSP_INITIALIZED,
293
294         /**
295          * Description - Adapter Modalias info
296          * Access mode - GET
297          * Data type   - Array of character string
298          */
299         BT_PROPERTY_MODALIAS,
300
301         /**
302          * Description - BLE Device manufacturer data length
303          * Access mode - GET
304          * Data type   - uint32_t
305          */
306         BT_PROPERTY_REMOTE_DEVICE_MANUFACTURER_DATA_LEN,
307
308         /**
309          * Description - BLE Device manufacturer data
310          * Access mode - GET
311          * Data type   - Array of character string
312          */
313         BT_PROPERTY_REMOTE_DEVICE_MANUFACTURER_DATA,
314
315         /**
316          * Description - Remote BLE advertising data
317          * Access mode - Only received during device found callback.
318          * Data type   - Array of uint8_t of remote BLE adv data.
319          *               (Array size inferred from property length).
320          */
321         BT_PROPERTY_REMOTE_BLE_ADV_DATA,
322
323         /**
324          * Description - Local LE features
325          * Access mode - GET.
326          * Data type   - bt_local_le_features_t.
327          */
328         BT_PROPERTY_LOCAL_LE_FEATURES,
329
330         /**
331          * Description - Remote device friendly name set?
332          * Access mode - GET.
333          * Data type   - uint8_t
334          */
335         BT_PROPERTY_REMOTE_IS_ALIAS_SET,
336
337         BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
338 } bt_property_type_t;
339
340 /** Bluetooth Adapter Property data structure */
341 typedef struct
342 {
343     bt_property_type_t type;
344     int len;
345     void *val;
346 } bt_property_t;
347
348
349 /** Bluetooth Device Type */
350 typedef enum {
351     BT_DEVICE_DEVTYPE_BREDR = 0x1,
352     BT_DEVICE_DEVTYPE_BLE,
353     BT_DEVICE_DEVTYPE_DUAL
354 } bt_device_type_t;
355 /** Bluetooth Bond state */
356 typedef enum {
357     BT_BOND_STATE_NONE,
358     BT_BOND_STATE_BONDING,
359     BT_BOND_STATE_BONDED
360 } bt_bond_state_t;
361
362 /** Bluetooth SSP Bonding Variant */
363 typedef enum {
364     BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
365     BT_SSP_VARIANT_PASSKEY_ENTRY,
366     BT_SSP_VARIANT_CONSENT,
367     BT_SSP_VARIANT_PASSKEY_NOTIFICATION
368 } bt_ssp_variant_t;
369
370 /** Bluetooth Profile Service IDs */
371 typedef enum {
372     BT_RES_SERVICE_ID,              /* Reserved */
373     BT_SPP_SERVICE_ID,              /* Serial port profile. */
374     BT_DUN_SERVICE_ID,              /* Dial-up networking profile. */
375     BT_A2DP_SRC_SERVICE_ID,         /* A2DP Source profile. */
376     BT_LAP_SERVICE_ID,              /* LAN access profile. */
377     BT_HSP_SERVICE_ID,              /* Headset profile. */
378     BT_HFP_SERVICE_ID,              /* Hands-free profile. */
379     BT_OPP_SERVICE_ID,              /* Object push  */
380     BT_FTP_SERVICE_ID,              /* File transfer */
381     BT_AVRCP_CT_SERVICE_ID,         /* AVRC Controller Terminal */
382     BT_ICP_SERVICE_ID,              /* Intercom Terminal */
383     BT_SYNC_SERVICE_ID,             /* Synchronization */
384     BT_BPP_SERVICE_ID,              /* Basic printing profile */
385     BT_BIP_SERVICE_ID,              /* Basic Imaging profile */
386     BT_PANU_SERVICE_ID,             /* PAN User */
387     BT_NAP_SERVICE_ID,              /* PAN Network access point */
388     BT_GN_SERVICE_ID,               /* PAN Group Ad-hoc networks */
389     BT_SAP_SERVICE_ID,              /* SIM Access profile */
390     BT_A2DP_SERVICE_ID,             /* A2DP Sink */
391     BT_AVRCP_SERVICE_ID,            /* A/V remote control */
392     BT_HID_SERVICE_ID,              /* HID */
393     BT_VDP_SERVICE_ID,              /* Video distribution */
394     BT_PBAP_SERVICE_ID,             /* PhoneBook Access Server*/
395     BT_HSP_HS_SERVICE_ID,           /* HFP HS role */
396     BT_HFP_HS_SERVICE_ID,           /* HSP HS role */
397     BT_MAP_SERVICE_ID,              /* Message Access Profile */
398     BT_MN_SERVICE_ID,               /* Message Notification Service */
399     BT_HDP_SERVICE_ID,              /* Health Device Profile */
400     BT_PCE_SERVICE_ID,              /* PhoneBook Access Client*/
401 #ifdef TIZEN_BT_HAL
402     BT_IOTIVITY_SERVICE_ID,         /* Custom IOTIVITY UUID */
403 #endif
404 } bt_service_id_t;
405
406 #define BT_MAX_NUM_UUIDS 32
407
408 #ifdef TIZEN_BT_HAL
409 #define BT_OSP_SERVER_OBEX 0x00
410 /* TODO: Add more types If and when required */
411 #define BT_OSP_SERVER_MAX 0xFF
412
413 /* Tizen BT discovery Types */
414 typedef enum {
415     BT_DISC_ROLE_BREDR = 0x01,
416     BT_DISC_ROLE_LE,
417     BT_DISC_ROLE_DUAL
418 } bt_disc_role_type_t;
419
420 /** Bluetooth Trusted Profiles */
421 typedef enum {
422         BT_TRUSTED_PROFILE_PBAP = 1,
423         BT_TRUSTED_PROFILE_MAP,
424         BT_TRUSTED_PROFILE_SAP,
425         BT_TRUSTED_PROFILE_HFP_HF,
426         BT_TRUSTED_PROFILE_A2DP,
427         BT_TRUSTED_PROFILE_ALL = 0xFFFFFFFF,
428 } bt_trusted_profile_t;
429
430 /** Bluetooth Bonding Authentication Notifications */
431 typedef enum {
432     BT_PASSKEY_CONFIRMATION = 1,
433     BT_PASSKEY_DISPLAY,
434     BT_PASSKEY_ENTRY,
435     BT_PINCODE_ENTRY,
436 } bt_gap_auth_variant_t;
437 #endif
438
439 /** Bluetooth Interface callbacks */
440
441 /** Bluetooth Enable/Disable Callback. */
442 typedef void (*adapter_state_changed_callback)(bt_state_t state);
443
444 #ifdef TIZEN_BT_HAL
445 /** BLE Enable/Disable Callback. */
446 typedef void (*le_state_changed_callback)(bt_state_t state);
447 #endif
448
449 /** GET/SET Adapter Properties callback */
450 /* TODO: For the GET/SET property APIs/callbacks, we may need a session
451  * identifier to associate the call with the callback. This would be needed
452  * whenever more than one simultaneous instance of the same adapter_type
453  * is get/set.
454  *
455  * If this is going to be handled in the Java framework, then we do not need
456  * to manage sessions here.
457  */
458 typedef void (*adapter_properties_callback)(bt_status_t status,
459                                                int num_properties,
460                                                bt_property_t *properties);
461
462 /** GET/SET Remote Device Properties callback */
463 /** TODO: For remote device properties, do not see a need to get/set
464  * multiple properties - num_properties shall be 1
465  */
466 typedef void (*remote_device_properties_callback)(bt_status_t status,
467                                                        bt_bdaddr_t *bd_addr,
468                                                        int num_properties,
469                                                        bt_property_t *properties);
470
471 /** New device discovered callback */
472 /** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1
473  * respectively */
474 typedef void (*device_found_callback)(int num_properties,
475                                          bt_property_t *properties);
476
477 /** Discovery state changed callback */
478 typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state);
479
480 /** Bluetooth Legacy PinKey Request callback */
481 typedef void (*pin_request_callback)(bt_bdaddr_t *remote_bd_addr,
482                                         bt_bdname_t *bd_name, uint32_t cod);
483
484 /** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
485 /** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT &
486  *  BT_SSP_PAIRING_PASSKEY_ENTRY */
487 /* TODO: Passkey request callback shall not be needed for devices with display
488  * capability. We still need support this in the stack for completeness */
489 typedef void (*ssp_request_callback)(bt_bdaddr_t *remote_bd_addr,
490                                         bt_bdname_t *bd_name,
491                                         uint32_t cod,
492                                         bt_ssp_variant_t pairing_variant,
493                                      uint32_t pass_key);
494
495 /** Bluetooth Bond state changed callback */
496 /* Invoked in response to create_bond, cancel_bond or remove_bond */
497 typedef void (*bond_state_changed_callback)(bt_status_t status,
498                                                bt_bdaddr_t *remote_bd_addr,
499                                                bt_bond_state_t state);
500
501 /** Bluetooth ACL connection state changed callback */
502 typedef void (*acl_state_changed_callback)(bt_status_t status, bt_bdaddr_t *remote_bd_addr,
503                                             bt_acl_state_t state);
504
505 typedef enum {
506     ASSOCIATE_JVM,
507     DISASSOCIATE_JVM
508 } bt_cb_thread_evt;
509
510 /** Thread Associate/Disassociate JVM Callback */
511 /* Callback that is invoked by the callback thread to allow upper layer to attach/detach to/from
512  * the JVM */
513 typedef void (*callback_thread_event)(bt_cb_thread_evt evt);
514
515 /** Bluetooth Test Mode Callback */
516 /* Receive any HCI event from controller. Must be in DUT Mode for this callback to be received */
517 typedef void (*dut_mode_recv_callback)(uint16_t opcode, uint8_t *buf, uint8_t len);
518
519 /* LE Test mode callbacks
520 * This callback shall be invoked whenever the le_tx_test, le_rx_test or le_test_end is invoked
521 * The num_packets is valid only for le_test_end command */
522 typedef void (*le_test_mode_callback)(bt_status_t status, uint16_t num_packets);
523
524 /** Callback invoked when energy details are obtained */
525 /* Ctrl_state-Current controller state-Active-1,scan-2,or idle-3 state as defined by HCI spec.
526  * If the ctrl_state value is 0, it means the API call failed
527  * Time values-In milliseconds as returned by the controller
528  * Energy used-Value as returned by the controller
529  * Status-Provides the status of the read_energy_info API call */
530 typedef void (*energy_info_callback)(bt_activity_energy_info *energy_info);
531
532 /* Service level Authorization request callback */
533 typedef void (*authorize_request_callback) (bt_bdaddr_t *remote_bd_addr, bt_service_id_t service_d);
534
535 #ifdef TIZEN_BT_HAL
536 /* Service level Authorization request callback */
537 typedef void (*sock_authorize_request_callback) (bt_bdaddr_t *remote_bd_addr, bt_uuid_t *uuid);
538
539 /** Bluetooth ACL connection state */
540 typedef enum {
541     BT_LE_CONN_STATE_CONNECTED,
542     BT_LE_CONN_STATE_DISCONNECTED
543 } bt_le_conn_state_t;
544
545 /** Bluetooth ACL connection state changed callback */
546 typedef void (*le_conn_state_changed_callback)(bt_status_t status, bt_bdaddr_t *remote_bd_addr,
547                 bt_le_conn_state_t state);
548
549 /** Remote device trusted profiles changed callback */
550 typedef void (*device_trusted_profiles_changed_callback)(bt_bdaddr_t *bd_addr, uint32_t trust_val);
551
552 /** Remote device RSSI monitoring state changed callback */
553 typedef void (*rssi_monitor_state_changed_callback)(bt_bdaddr_t *bd_addr, int32_t link_type, uint8_t state);
554
555 /** Remote device RSSI alert callback */
556 typedef void (*rssi_alert_callback)(bt_bdaddr_t *bd_addr, int32_t link_type, int32_t alert_type, int32_t rssi);
557
558 /** Remote device Raw RSSI received callback */
559 typedef void (*raw_rssi_received_callback)(bt_bdaddr_t *bd_addr, int32_t link_type, int32_t rssi);
560 #endif
561
562 /** TODO: Add callbacks for Link Up/Down and other generic
563   *  notifications/callbacks */
564
565 /** Remote Device Trust state changed callback */
566 typedef void (*device_trust_state_changed_callback)(bt_bdaddr_t *remote_bd_addr,
567                                             bt_device_trust_state_t trust);
568
569 /** Bluetooth DM callback structure. */
570 typedef struct {
571     /** set to sizeof(bt_callbacks_t) */
572     size_t size;
573     adapter_state_changed_callback adapter_state_changed_cb;
574     adapter_properties_callback adapter_properties_cb;
575     remote_device_properties_callback remote_device_properties_cb;
576     device_found_callback device_found_cb;
577     discovery_state_changed_callback discovery_state_changed_cb;
578     pin_request_callback pin_request_cb;
579     ssp_request_callback ssp_request_cb;
580     bond_state_changed_callback bond_state_changed_cb;
581     acl_state_changed_callback acl_state_changed_cb;
582     callback_thread_event thread_evt_cb;
583     dut_mode_recv_callback dut_mode_recv_cb;
584     le_test_mode_callback le_test_mode_cb;
585     energy_info_callback energy_info_cb;
586     authorize_request_callback authorize_request_cb;
587     device_trust_state_changed_callback device_trust_state_changed_cb;
588 #ifdef TIZEN_BT_HAL
589     sock_authorize_request_callback socket_authorize_request_cb;
590         le_state_changed_callback le_state_changed_cb;
591         le_conn_state_changed_callback le_conn_state_changed_cb;
592         device_trusted_profiles_changed_callback device_trusted_profiles_changed_cb;
593         rssi_monitor_state_changed_callback rssi_monitor_state_changed_cb;
594         rssi_alert_callback rssi_alert_cb;
595         raw_rssi_received_callback raw_rssi_received_cb;
596 #endif
597 } bt_callbacks_t;
598
599 typedef void (*alarm_cb)(void *data);
600 typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data);
601 typedef int (*acquire_wake_lock_callout)(const char *lock_name);
602 typedef int (*release_wake_lock_callout)(const char *lock_name);
603
604 /** The set of functions required by bluedroid to set wake alarms and
605   * grab wake locks. This struct is passed into the stack through the
606   * |set_os_callouts| function on |bt_interface_t|.
607   */
608 typedef struct {
609   /* set to sizeof(bt_os_callouts_t) */
610   size_t size;
611
612   set_wake_alarm_callout set_wake_alarm;
613   acquire_wake_lock_callout acquire_wake_lock;
614   release_wake_lock_callout release_wake_lock;
615 } bt_os_callouts_t;
616
617 /** NOTE: By default, no profiles are initialized at the time of init/enable.
618  *  Whenever the application invokes the 'init' API of a profile, then one of
619  *  the following shall occur:
620  *
621  *    1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
622  *        profile as enabled. Subsequently, when the application invokes the
623  *        Bluetooth 'enable', as part of the enable sequence the profile that were
624  *        marked shall be enabled by calling appropriate stack APIs. The
625  *        'adapter_properties_cb' shall return the list of UUIDs of the
626  *        enabled profiles.
627  *
628  *    2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the stack
629  *        profile API to initialize the profile and trigger a
630  *        'adapter_properties_cb' with the current list of UUIDs including the
631  *        newly added profile's UUID.
632  *
633  *   The reverse shall occur whenever the profile 'cleanup' APIs are invoked
634  */
635
636 /** Represents the standard Bluetooth DM interface. */
637 typedef struct {
638     /** set to sizeof(bt_interface_t) */
639     size_t size;
640     /**
641      * Opens the interface and provides the callback routines
642      * to the implemenation of this interface.
643      */
644     int (*init)(bt_callbacks_t* callbacks );
645
646     /** Enable Bluetooth. */
647     int (*enable)(void);
648
649     /** Disable Bluetooth. */
650     int (*disable)(void);
651
652 #ifdef TIZEN_BT_HAL
653     /** Reset Bluetooth. */
654     int (*reset)(void);
655 #endif
656
657 #ifdef TIZEN_BT_HAL
658     /** Enable LE Bluetooth. */
659     int (*le_enable)(void);
660
661     /** Disable LE Bluetooth. */
662     int (*le_disable)(void);
663
664     int (*le_init)(void);
665
666     void (*le_deinit)(void);
667 #endif
668
669     /** Closes the interface. */
670     void (*cleanup)(void);
671
672 #ifdef TIZEN_BT_HAL
673     /** Get Bluetooth Adapter Powered status */
674     int (*get_adapter_powered_status)(uint8_t *status);
675 #endif
676
677     /** Get all Bluetooth Adapter properties at init */
678     int (*get_adapter_properties)(void);
679
680     /** Get Bluetooth Adapter property of 'type' */
681     int (*get_adapter_property)(bt_property_type_t type);
682
683     /** Set Bluetooth Adapter property of 'type' */
684     /* Based on the type, val shall be one of
685      * bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc
686      */
687     int (*set_adapter_property)(const bt_property_t *property);
688
689     /** Get all Remote Device properties */
690     int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr);
691
692     /** Get Remote Device property of 'type' */
693     int (*get_remote_device_property)(bt_bdaddr_t *remote_addr,
694                                       bt_property_type_t type);
695
696     /** Set Remote Device property of 'type' */
697     int (*set_remote_device_property)(bt_bdaddr_t *remote_addr,
698                                       const bt_property_t *property);
699
700     /** Get Remote Device's service record  for the given UUID */
701     int (*get_remote_service_record)(bt_bdaddr_t *remote_addr,
702                                      bt_uuid_t *uuid);
703
704     /** Start SDP to get remote services */
705     int (*get_remote_services)(bt_bdaddr_t *remote_addr);
706
707     /** Start Discovery */
708     int (*start_discovery)(void);
709
710 #ifdef TIZEN_BT_HAL
711     int (*start_custom_discovery)(bt_disc_role_type_t disc_type);
712 #endif
713
714     /** Cancel Discovery */
715     int (*cancel_discovery)(void);
716
717     /** Create Bluetooth Bonding */
718     int (*create_bond)(const bt_bdaddr_t *bd_addr, int transport);
719
720     /** Remove Bond */
721     int (*remove_bond)(const bt_bdaddr_t *bd_addr);
722
723     /** Cancel Bond */
724     int (*cancel_bond)(const bt_bdaddr_t *bd_addr);
725
726     /**
727      * Get the connection status for a given remote device.
728      * return value of 0 means the device is not connected,
729      * non-zero return status indicates an active connection.
730      */
731     int (*get_connection_state)(const bt_bdaddr_t *bd_addr);
732
733     /** BT Legacy PinKey Reply */
734     /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
735     int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,
736                      uint8_t pin_len, bt_pin_code_t *pin_code);
737
738     /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
739      * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
740      * BT_SSP_VARIANT_CONSENT
741      * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
742      * shall be zero */
743     int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
744                      uint8_t accept, uint32_t passkey);
745
746     /** Get Bluetooth profile interface */
747     const void* (*get_profile_interface) (const char *profile_id);
748
749     /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
750     /* Configure DUT Mode - Use this mode to enter/exit DUT mode */
751     int (*dut_mode_configure)(uint8_t enable);
752
753     /* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */
754     int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len);
755     /** BLE Test Mode APIs */
756     /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */
757     int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);
758
759     /* enable or disable bluetooth HCI snoop log */
760     int (*config_hci_snoop_log)(uint8_t enable);
761
762     /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks.
763       * This should be called immediately after a successful |init|.
764       */
765     int (*set_os_callouts)(bt_os_callouts_t *callouts);
766
767     /** Read Energy info details - return value indicates BT_STATUS_SUCCESS or BT_STATUS_NOT_READY
768       * Success indicates that the VSC command was sent to controller
769       */
770     int (*read_energy_info)();
771
772      /* Tizen Specific: Send  service level Authorization response */
773      int (*authorize_response)(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
774                                         uint8_t authorize, uint8_t save_settings);
775
776      /** Set auto authorization for peer device. Should be a paired device */
777      int (*set_authorization)(bt_bdaddr_t *bd_addr, uint8_t auth);
778 #ifdef TIZEN_BT_HAL
779     /**
780      * get the service connection status for a given remote device.
781      * return value of 0 means the device is not connected,
782      * non-zero return status indicates an active connection.
783      */
784     int (*get_service_connection_state)(const bt_bdaddr_t *bd_addr, bt_service_id_t rem_svc_id);
785
786     /*
787      * Enable/Disable osp server in gap agent.
788      * enable == 0/1 -> Register/Unregister osp server.
789      */
790     int (*set_agent_osp_server)(uint32_t type, uint8_t enable);
791
792     /**
793      * Set profile as trusted for remote device
794      */
795     int (*set_trusted_profile)(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint8_t trust);
796
797     /**
798      * Get profile trusted status for remote device
799      */
800     int (*get_trusted_profile)(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint32_t *trusted);
801
802     /**
803      * Get raw RSSI strength of remote device for connected link type
804      * conn_link_type: (0 = BR/EDR link, 1 = LE link, 0xFF = Any (Default))
805      */
806     int (*get_connected_link_rssi_strength)(bt_bdaddr_t *bd_addr, uint32_t conn_link_type);
807
808     /**
809      * Enable RSSI monitoring of remote device for connected link type
810      * conn_link_type: (0 = BR/EDR link, 1 = LE link, 0xFF = Any (Default))
811      * Threshold : (low_threshold, in_range_threshold, high_threshold)
812      */
813     int (*enable_rssi_monitoring)(bt_bdaddr_t *bd_addr, uint32_t conn_link_type,
814                     int low_threshold, int in_range_threshold, int high_threshold);
815     /*
816      * Enable/Disable GAP authentication notification to application
817      * enable == 0/1 -> Enable/Disable notification sending
818      * type == value from bt_gap_auth_variant_t
819      */
820     int (*enable_gap_auth_notifications)(uint32_t type, uint8_t enable);
821
822 #endif
823 } bt_interface_t;
824
825 /** TODO: Need to add APIs for Service Discovery, Service authorization and
826   *       connection management. Also need to add APIs for configuring
827   *       properties of remote bonded devices such as name, UUID etc. */
828
829 typedef struct {
830     struct hw_device_t common;
831     const bt_interface_t* (*get_bluetooth_interface)();
832 } bluetooth_device_t;
833
834 typedef bluetooth_device_t bluetooth_module_t;
835 __END_DECLS
836
837 #endif /* ANDROID_INCLUDE_BLUETOOTH_H */