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