Porting flight mode logic to HAL
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / include / oal-manager.h
1 /*
2 * Open Adaptation Layer (OAL)
3 *
4 * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *                          http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20 #ifndef _OAL_MANAGER_H_
21 #define _OAL_MANAGER_H_
22
23 #include <glib.h>
24 #include <stdint.h>
25 #include <sys/types.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #define BT_VERSION_STR_LEN_MAX       30 /**< This specifies maximum adapter version string length */
32
33 #define BT_DEVICE_NAME_LENGTH_MAX       248 /**< This specifies maximum device name length */
34
35 #define BT_ADDRESS_BYTES_NUM            6 /**< This specifies bluetooth device address length */
36
37 #define OAL_UUID_MAX_LENGTH                             16/**< This specifies ble service UUID Length */
38
39 #define BLE_ADV_DATA_LENGTH            62 /**< This specifies Advertising Data Length */
40
41 #define BT_ADDRESS_STR_LEN                              18 /**< BT address String length> */
42
43 #define BT_MAX_SERVICES_FOR_DEVICE  60 /**< This specifies the Maximum UUID Id mentioned in bta_api.h>*/
44
45 #define BLUETOOTH_UUID_STRING_MAX       50
46
47 typedef void (*oal_event_callback)(int event, gpointer event_data, gsize size);
48
49 typedef struct {
50         unsigned char addr[BT_ADDRESS_BYTES_NUM];
51 } bt_address_t;
52
53 typedef struct {
54         char name[BT_DEVICE_NAME_LENGTH_MAX + 1];
55 } bt_name_t;
56
57 typedef enum {
58         OAL_STATUS_SUCCESS,
59         /* Generic */
60         OAL_STATUS_INTERNAL_ERROR,
61         OAL_STATUS_NOT_READY,
62         OAL_STATUS_BUSY,
63         OAL_STATUS_INVALID_PARAM,
64         OAL_STATUS_RMT_DEVICE_DOWN,
65         OAL_STATUS_AUTH_FAILED,
66         OAL_STATUS_NOT_SUPPORT, //For APIs not supported
67         OAL_STATUS_ALREADY_DONE,
68         OAL_STATUS_PENDING,
69         OAL_STATUS_CONN_TIMEOUT,
70         /* HID */
71         OAL_STATUS_HID_FAILED_MOUSE,
72 #ifndef TIZEN_BT_HAL
73         OAL_STATUS_LINK_LOSS
74 #else
75         OAL_STATUS_LINK_LOSS,
76         OAL_STATUS_CONN_TERM_LOCAL_HOST,
77         OAL_STATUS_CONN_TERM_RMT_HOST
78 #endif
79 } oal_status_t;
80
81
82
83 /* NOTE: If anything changes in bt_service_id_t enum definition of Bluedroid header, change here too */
84 typedef enum {
85         A2DP_SRC_SERVICE_ID = 3,
86         HSP_SERVICE_ID = 5,
87         HFP_SERVICE_ID = 6,
88         OPP_SERVICE_ID = 7,
89         AVRCP_CT_SERVICE_ID = 9,
90         SAP_SERVICE_ID = 17,
91         A2DP_SERVICE_ID = 18,
92         AVRCP_SERVICE_ID = 19,
93         HID_SERVICE_ID = 20,
94         HSP_HS_SERVICE_ID = 23,
95         HFP_HS_SERVICE_ID = 24,
96 #ifdef TIZEN_BT_HAL
97         IOTIVITY_SERVICE_ID = 29,
98 #endif
99 } oal_service_t;
100
101 /** Bluetooth 128-bit UUID */
102 typedef struct {
103         uint8_t uuid[16];
104 } oal_uuid_t;
105
106 typedef oal_uuid_t service_uuid_t;
107
108 typedef enum {
109         DEV_TYPE_BREDR,
110         DEV_TYPE_BLE_ONLY,
111         DEV_TYPE_DUAL
112 } device_type_t;
113
114 typedef enum {
115         BT_DISC_TYPE_BREDR = 0x01,
116         BT_DISC_TYPE_LE,
117         BT_DISC_TYPE_DUAL
118 } discovery_type_t;
119
120 typedef struct {
121         char name[BT_DEVICE_NAME_LENGTH_MAX + 1];
122         char alias[BT_DEVICE_NAME_LENGTH_MAX + 1];
123         bt_address_t address;
124         int cod;
125         int rssi;
126         int vid;
127         int pid;
128         int is_bonded;
129         int is_connected;
130         device_type_t type;
131         int uuid_count;
132         oal_uuid_t uuid[BT_MAX_SERVICES_FOR_DEVICE];
133         int is_trusted;
134         int is_alias_set;
135 } remote_device_t;
136
137 /** GATT ID adding instance id tracking to the UUID */
138 typedef struct {
139         oal_uuid_t          uuid;
140         uint8_t             inst_id;
141 } oal_gatt_id_t;
142
143 /** GATT Service ID also identifies the service type (primary/secondary) */
144 typedef struct {
145         oal_gatt_id_t    id;
146         uint8_t              is_prmry;
147 } oal_gatt_srvc_id_t;
148
149 /**
150  * @brief Initializes OAL layer
151  *
152  * @remarks Other API can only be used after successful return. \n
153  *
154  * @details EVENT: N/A
155  *
156  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
157  * @retval #OAL_STATUS_SUCCESS  Successful
158  *
159  * @pre N/A
160  *
161  * @see  oal_bt_deinit()
162  */
163 oal_status_t oal_bt_init(oal_event_callback cb);
164
165 /**
166  * @brief Deinitializes OAL Layer
167  *
168  * @remarks Other API can only be used after oal_bt_init done again. \n
169  *
170  * @details EVENT: N/A
171  *
172  * @return void.
173  * @retval void
174  *
175  * @pre N/A
176  *
177  * @see  oal_bt_init()
178  */
179 void oal_bt_deinit(void);
180
181 /**
182  * @brief Initialize Stack lib based on chip
183  *
184  * @remarks Other API can only be used after oal_lib_init done. \n
185  *
186  * @details EVENT: OAL_EVENT_OAL_INITIALISED_SUCCESS, OAL_EVENT_OAL_INITIALISED_FAILED
187  *
188  * @return bool.
189  * @retval bool
190  *
191  * @pre N/A
192  *
193  * @see  N/A
194  */
195 gboolean oal_lib_init(gpointer data);
196
197 /**
198  * @brief Set Debug Mode Flag to TRUE
199  *
200  * @remarks OAL will run in exclusive mode, no processing of api-call and no event sending. \n
201  *
202  * @details EVENT: N/A
203  *
204  * @return void
205  * @retval void
206  *
207  * @pre N/A
208  *
209  * @see  oal_get_debug_mode()
210  */
211 void oal_set_debug_mode(gboolean mode);
212
213 /**
214  * @brief Set Debug Mode Flag
215  *
216  * @remarks To check whether Debug mode is running. \n
217  *
218  * @details EVENT: N/A
219  *
220  * @return TRUE if debug mode is on, otherwise FALSE
221  * @retval #TRUE  Successful
222  *
223  * @pre N/A
224  *
225  * @see  oal_set_debug_mode()
226  */
227 gboolean oal_get_debug_mode(void);
228
229 #ifdef OAL_DEBUG
230 /**
231  * @brief Register the debug mode event catcher
232  *
233  * @remarks handles the incoming events and passes to debug handler. \n
234  *
235  * @details EVENT: N/A
236  *
237  * @return void
238  * @retval void
239  *
240  * @pre N/A
241  *
242  * @see  N/A
243  */
244 void server_event_catch_register(oal_event_callback dbg_cb);
245 #endif
246
247 #ifdef __cplusplus
248 }
249 #endif /* __cplusplus */
250 #endif /*_OAL_HARDWARE_H_*/
251
252 /**
253  * @brief calls function to set the is_activating variable in HAL to true
254  *
255  * @remarks It is required to let adapter switched on event propagate upwards
256  *
257  * @details EVENT: N/A
258  *
259  * @return sucess if variable set in HAL
260  * @retval BT_STATUS_SUCCESS
261  *
262  * @pre N/A
263  *
264  * @see  N/A
265 */
266 int oal_set_adapter_request_state(int enable);
267
268 /*
269 * @brief calls function to set the is_activating variable in HAL to true
270  *
271  * @remarks It is required to let le adapter switched on event propagate upwards
272  *
273  * @details EVENT: N/A
274  *
275  * @return sucess if variable set in HAL
276  * @retval BT_STATUS_SUCCESS
277  *
278  * @pre N/A
279  *
280  * @see  N/A
281 */
282 int oal_set_le_request_state(int enable);