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