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