Upgrade Bluetooth-frwk to match Bluez5.X
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / include / bt-common.h
1 /*
2  * bluetooth-frwk
3  *
4  * Copyright (c) 2012-2013 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
21 #ifndef _BT_COMMON_H_
22 #define _BT_COMMON_H_
23
24 #include <sys/types.h>
25 #include <libintl.h>
26 #include <dbus/dbus-glib.h>
27 #include <dbus/dbus.h>
28 #include <dlog.h>
29
30 #include "bluetooth-api.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
35
36 #undef LOG_TAG
37 #define LOG_TAG "BLUETOOTH_FRWK"
38
39 #ifndef BT_EXPORT_API
40 #define BT_EXPORT_API __attribute__((visibility("default")))
41 #endif
42
43 #define BT_DBG(fmt, args...) \
44         SLOGD(fmt, ##args)
45 #define BT_ERR(fmt, args...) \
46         SLOGE(fmt, ##args)
47
48 #define ret_if(expr) \
49         do { \
50                 if (expr) { \
51                         BT_ERR("(%s) return", #expr); \
52                         return; \
53                 } \
54         } while (0)
55
56 #define retv_if(expr, val) \
57         do { \
58                 if (expr) { \
59                         BT_ERR("(%s) return", #expr); \
60                         return (val); \
61                 } \
62         } while (0)
63
64 #define BT_INIT_PARAMS() \
65         GArray *in_param1 = NULL; \
66         GArray *in_param2 = NULL; \
67         GArray *in_param3 = NULL; \
68         GArray *in_param4 = NULL; \
69         GArray *out_param = NULL;
70
71 #define BT_FREE_PARAMS(IP1,IP2,IP3,IP4,OP) \
72         do { \
73                 if (IP1) \
74                         g_array_free(IP1, TRUE); \
75                 if (IP2) \
76                         g_array_free(IP2, TRUE); \
77                 if (IP3) \
78                         g_array_free(IP3, TRUE); \
79                 if (IP4) \
80                         g_array_free(IP4, TRUE); \
81                 if (OP) \
82                         g_array_free(OP, TRUE); \
83         } while (0)
84
85 #define BT_ALLOC_PARAMS(IP1,IP2,IP3,IP4,OP ) \
86         do { \
87                 IP1 = g_array_new(FALSE, FALSE, sizeof(gchar)); \
88                 IP2 = g_array_new(FALSE, FALSE, sizeof(gchar)); \
89                 IP3 = g_array_new(FALSE, FALSE, sizeof(gchar)); \
90                 IP4 = g_array_new(FALSE, FALSE, sizeof(gchar)); \
91         } while (0)
92
93 #define BT_INIT_AGENT_PARAMS() \
94         GArray *in_param = NULL; \
95         GArray *out_param = NULL;
96
97 #define BT_FREE_AGENT_PARAMS(IP,OP) \
98         do { \
99                 if (IP) \
100                         g_array_free(IP, TRUE); \
101                 if (OP) \
102                         g_array_free(OP, TRUE); \
103         } while (0)
104
105 #define BT_ALLOC_AGENT_PARAMS(IP,OP) \
106         do { \
107                 IP = g_array_new(FALSE, FALSE, sizeof(gchar));  \
108         } while (0)
109
110 #define BT_CHECK_PARAMETER(arg, func) \
111         do { \
112                 if (arg == NULL) \
113                 { \
114                         BT_ERR("INVALID PARAMETER"); \
115                         func BLUETOOTH_ERROR_INVALID_PARAM; \
116                 } \
117         } while (0)
118
119 #define BT_CHECK_ENABLED(func) \
120         do { \
121                 if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED) \
122                 { \
123                         BT_ERR("BT is not enabled"); \
124                         func BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; \
125                 } \
126         } while (0)
127
128 #define BT_ADDRESS_LENGTH_MAX 6
129 #define BT_ADDRESS_STRING_SIZE 18
130 #define BT_ADAPTER_OBJECT_PATH_MAX 50
131
132 #define BT_EVENT_FREEDESKTOP "org.freedesktop.DBus"
133 #define BT_FREEDESKTOP_PATH "/org/freedesktop/DBus"
134
135 #define BT_EVENT_MANAGER "org.bluez.Manager"
136 #define BT_MANAGER_PATH "/"
137 #define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
138 #define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
139 #define BT_DEVICE_INTERFACE "org.bluez.Device1"
140
141 #define BT_BLUEZ_NAME "org.bluez"
142 #define BT_DBUS_NAME "org.projectx.bt"
143 #define BT_SERVICE_PATH "/org/projectx/bt_service"
144
145 #define BT_AGENT_NAME "org.bluez.frwk_agent"
146 #define BT_AGENT_PATH "/org/bluez/agent/frwk_agent"
147 #define BT_AGENT_INTERFACE "org.bluez.Agent1"
148
149 #define BT_MAX_USER_INFO 5
150 #define RFKILL_EVENT_SIZE 8
151 #define RFKILL_NODE "/dev/rfkill"
152
153 typedef enum {
154         RFKILL_TYPE_ALL = 0,
155         RFKILL_TYPE_WLAN,
156         RFKILL_TYPE_BLUETOOTH,
157         RFKILL_TYPE_UWB,
158         RFKILL_TYPE_WIMAX,
159         RFKILL_TYPE_WWAN,
160         RFKILL_TYPE_GPS,
161         RFKILL_TYPE_FM,
162         NUM_RFKILL_TYPES,
163 } rfkill_type;
164
165 typedef struct {
166         unsigned int idx;
167         unsigned char type;
168         unsigned char op;
169         unsigned char soft;
170         unsigned char hard;
171 } rfkill_event;
172
173 typedef enum {
174         BT_COMMON = 0x00,
175         BT_HID,
176         BT_AUDIO,
177         BT_AVRCP,
178 } bt_user_info_type_t;
179
180 typedef struct {
181         void *cb;
182         void *user_data;
183 } bt_user_info_t;
184
185 void _bt_set_user_data(int type, void *callback, void *user_data);
186
187 void _bt_print_device_address_t(const bluetooth_device_address_t *addr);
188
189 bt_user_info_t* _bt_get_user_data(int type);
190
191 void _bt_common_event_cb(int event, int result, void *param,
192                                 void *callback, void *user_data);
193
194 void _bt_input_event_cb(int event, int result, void *param,
195                                         void *callback, void *user_data);
196
197 void _bt_headset_event_cb(int event, int result, void *param,
198                                         void *callback, void *user_data);
199
200 void _bt_avrcp_event_cb(int event, int result, void *param,
201                                         void *callback, void *user_data);
202
203 void _bt_opp_client_event_cb(int event, int result, void *param,
204                                         void *callback, void *user_data);
205
206 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
207                                 unsigned int cod);
208
209 void _bt_convert_addr_string_to_type(unsigned char *addr,
210                                         const char *address);
211
212 void _bt_convert_addr_type_to_string(char *address,
213                                 unsigned char *addr);
214
215 int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length);
216
217 int _bt_get_adapter_path(DBusGConnection *g_conn, char *path);
218
219 DBusGProxy *_bt_get_adapter_proxy(DBusGConnection *conn);
220
221 void _bt_device_path_to_address(const char *device_path, char *device_address);
222
223 DBusGConnection *__bt_init_system_gconn(void);
224
225 DBusGConnection *_bt_get_system_gconn(void);
226
227 DBusConnection *_bt_get_system_conn(void);
228
229 #ifdef __cplusplus
230 }
231 #endif /* __cplusplus */
232 #endif /*_BT_COMMON_H_*/
233