89c10a90d60e46e64c0ede74c72111fd69deabad
[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            31 /**< 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 #define BT_DEVICE_MANUFACTURER_DATA_LEN_MAX 240 /**<This specifies the Maximum manufacturer data Length>*/
48
49 typedef void (*oal_event_callback)(int event, gpointer event_data, gsize size);
50
51 typedef struct {
52         unsigned char addr[BT_ADDRESS_BYTES_NUM];
53 } bt_address_t;
54
55 typedef struct {
56         char name[BT_DEVICE_NAME_LENGTH_MAX + 1];
57 } bt_name_t;
58
59 typedef struct {
60         int data_len;           /**< manafacturer specific data length */
61         char data[BT_DEVICE_MANUFACTURER_DATA_LEN_MAX];
62 } oal_manufacturer_data_t;
63
64 typedef enum {
65         OAL_STATUS_SUCCESS,
66         /* Generic */
67         OAL_STATUS_INTERNAL_ERROR,
68         OAL_STATUS_NOT_READY,
69         OAL_STATUS_BUSY,
70         OAL_STATUS_INVALID_PARAM,
71         OAL_STATUS_RMT_DEVICE_DOWN,
72         OAL_STATUS_AUTH_FAILED,
73         OAL_STATUS_NOT_SUPPORT, //For APIs not supported
74         OAL_STATUS_NOT_PAIRED,
75         OAL_STATUS_ALREADY_DONE,
76         OAL_STATUS_PENDING,
77         OAL_STATUS_CONN_TIMEOUT,
78         /* HID */
79         OAL_STATUS_HID_FAILED_MOUSE,
80 #ifndef TIZEN_BT_HAL
81         OAL_STATUS_LINK_LOSS
82 #else
83         OAL_STATUS_LINK_LOSS,
84         OAL_STATUS_CONN_TERM_LOCAL_HOST,
85         OAL_STATUS_CONN_TERM_RMT_HOST,
86         OAL_STATUS_ALREADY_CONNECT,
87 #endif
88 } oal_status_t;
89
90
91
92 /* NOTE: If anything changes in bt_service_id_t enum definition of Bluedroid header, change here too */
93 typedef enum {
94         A2DP_SRC_SERVICE_ID = 3,
95         HSP_SERVICE_ID = 5,
96         HFP_SERVICE_ID = 6,
97         OPP_SERVICE_ID = 7,
98         AVRCP_CT_SERVICE_ID = 9,
99         SAP_SERVICE_ID = 17,
100         A2DP_SERVICE_ID = 18,
101         AVRCP_SERVICE_ID = 19,
102         HID_SERVICE_ID = 20,
103         HSP_HS_SERVICE_ID = 23,
104         HFP_HS_SERVICE_ID = 24,
105 #ifdef TIZEN_BT_HAL
106         IOTIVITY_SERVICE_ID = 29,
107 #endif
108 } oal_service_t;
109
110 /** Bluetooth 128-bit UUID */
111 typedef struct {
112         uint8_t uuid[16];
113 } oal_uuid_t;
114
115 typedef oal_uuid_t service_uuid_t;
116
117 typedef enum {
118         DEV_TYPE_BREDR,
119         DEV_TYPE_BLE_ONLY,
120         DEV_TYPE_DUAL
121 } device_type_t;
122
123 typedef enum {
124         BT_DISC_TYPE_BREDR = 0x01,
125         BT_DISC_TYPE_LE,
126         BT_DISC_TYPE_DUAL
127 } discovery_type_t;
128
129 typedef struct {
130         char name[BT_DEVICE_NAME_LENGTH_MAX + 1];
131         char alias[BT_DEVICE_NAME_LENGTH_MAX + 1];
132         bt_address_t address;
133         int cod;
134         int rssi;
135         int vid;
136         int pid;
137         int is_bonded;
138         int is_connected;
139         device_type_t type;
140         int uuid_count;
141         oal_uuid_t uuid[BT_MAX_SERVICES_FOR_DEVICE];
142         int is_trusted;
143         int is_alias_set;
144         char manufacturer_data[BT_DEVICE_MANUFACTURER_DATA_LEN_MAX];
145         int manufacturer_data_len;
146 } remote_device_t;
147
148 /** GATT ID adding instance id tracking to the UUID */
149 typedef struct {
150         oal_uuid_t          uuid;
151         uint8_t             inst_id;
152 } oal_gatt_id_t;
153
154 /** GATT Service ID also identifies the service type (primary/secondary) */
155 typedef struct {
156         oal_gatt_id_t    id;
157         uint8_t              is_prmry;
158 } oal_gatt_srvc_id_t;
159
160 /**
161  * @brief Initializes OAL layer
162  *
163  * @remarks Other API can only be used after successful return. \n
164  *
165  * @details EVENT: N/A
166  *
167  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
168  * @retval #OAL_STATUS_SUCCESS  Successful
169  *
170  * @pre N/A
171  *
172  * @see  oal_bt_deinit()
173  */
174 oal_status_t oal_bt_init(oal_event_callback cb);
175
176 /**
177  * @brief Deinitializes OAL Layer
178  *
179  * @remarks Other API can only be used after oal_bt_init done again. \n
180  *
181  * @details EVENT: N/A
182  *
183  * @return void.
184  * @retval void
185  *
186  * @pre N/A
187  *
188  * @see  oal_bt_init()
189  */
190 void oal_bt_deinit(void);
191
192 /**
193  * @brief Initialize Stack lib based on chip
194  *
195  * @remarks Other API can only be used after oal_lib_init done. \n
196  *
197  * @details EVENT: OAL_EVENT_OAL_INITIALISED_SUCCESS, OAL_EVENT_OAL_INITIALISED_FAILED
198  *
199  * @return bool.
200  * @retval bool
201  *
202  * @pre N/A
203  *
204  * @see  N/A
205  */
206 gboolean oal_lib_init(gpointer data);
207
208 /**
209  * @brief Set Debug Mode Flag to TRUE
210  *
211  * @remarks OAL will run in exclusive mode, no processing of api-call and no event sending. \n
212  *
213  * @details EVENT: N/A
214  *
215  * @return void
216  * @retval void
217  *
218  * @pre N/A
219  *
220  * @see  oal_get_debug_mode()
221  */
222 void oal_set_debug_mode(gboolean mode);
223
224 /**
225  * @brief Set Debug Mode Flag
226  *
227  * @remarks To check whether Debug mode is running. \n
228  *
229  * @details EVENT: N/A
230  *
231  * @return TRUE if debug mode is on, otherwise FALSE
232  * @retval #TRUE  Successful
233  *
234  * @pre N/A
235  *
236  * @see  oal_set_debug_mode()
237  */
238 gboolean oal_get_debug_mode(void);
239
240 #ifdef OAL_DEBUG
241 /**
242  * @brief Register the debug mode event catcher
243  *
244  * @remarks handles the incoming events and passes to debug handler. \n
245  *
246  * @details EVENT: N/A
247  *
248  * @return void
249  * @retval void
250  *
251  * @pre N/A
252  *
253  * @see  N/A
254  */
255 void server_event_catch_register(oal_event_callback dbg_cb);
256 #endif
257
258 /**
259  * @brief Get stack name
260  *
261  * @return stack name
262  *
263  * @pre OAL API must be initialized with oal_bt_init().
264  */
265 const char *oal_get_stack_name(void);
266
267 #ifdef __cplusplus
268 }
269 #endif /* __cplusplus */
270 #endif /*_OAL_HARDWARE_H_*/
271
272 /**
273  * @brief calls function to set the is_activating variable in HAL to true
274  *
275  * @remarks It is required to let adapter switched on event propagate upwards
276  *
277  * @details EVENT: N/A
278  *
279  * @return sucess if variable set in HAL
280  * @retval BT_STATUS_SUCCESS
281  *
282  * @pre N/A
283  *
284  * @see  N/A
285 */
286 int oal_set_adapter_request_state(int enable);
287
288 /*
289 * @brief calls function to set the is_activating variable in HAL to true
290  *
291  * @remarks It is required to let le adapter switched on event propagate upwards
292  *
293  * @details EVENT: N/A
294  *
295  * @return sucess if variable set in HAL
296  * @retval BT_STATUS_SUCCESS
297  *
298  * @pre N/A
299  *
300  * @see  N/A
301 */
302 int oal_set_le_request_state(int enable);