Remove Profile Build Dependenceis: do it at runtime
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / include / bt-service-common.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
18
19 #ifndef _BT_SERVICE_COMMON_H_
20 #define _BT_SERVICE_COMMON_H_
21
22 #include <sys/types.h>
23 #include <dlog.h>
24 #include <glib.h>
25 #include <gio/gio.h>
26
27 #include "bluetooth-api.h"
28 #include "bt-internal-types.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #undef LOG_TAG
35 #define LOG_TAG "BLUETOOTH_FRWK_SERVICE"
36
37 #ifdef FUNCTION_TRACE
38 #define FN_START BT_DBG("[ENTER FUNC]")
39 #define FN_END BT_DBG("[EXIT FUNC]")
40 #else
41 #define FN_START
42 #define FN_END
43 #endif
44
45 #define LOG_COLOR_RESET    "\033[0m"
46 #define LOG_COLOR_RED      "\033[31m"
47 #define LOG_COLOR_YELLOW   "\033[33m"
48 #define LOG_COLOR_GREEN         "\033[32m"
49 #define LOG_COLOR_BLUE          "\033[36m"
50 #define LOG_COLOR_PURPLE   "\033[35m"
51
52
53 #define BT_DBG(fmt, args...) \
54         ((TIZEN_PROFILE_TV) ? (LOGI(fmt, ##args)) : (SLOGD(fmt, ##args)))
55 #define BT_INFO(fmt, args...) \
56         ((TIZEN_PROFILE_TV) ? (LOGI(fmt, ##args)) : (SLOGI(fmt, ##args)))
57 #define BT_ERR(fmt, args...) \
58         ((TIZEN_PROFILE_TV) ? (LOGE(fmt, ##args)) : (SLOGE(fmt, ##args)))
59
60 #define BT_INFO_C(fmt, arg...) \
61         SLOGI_IF(TRUE,  LOG_COLOR_GREEN" "fmt" "LOG_COLOR_RESET, ##arg)
62 #define BT_ERR_C(fmt, arg...) \
63         SLOGI_IF(TRUE,  LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg)
64
65 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
66 #define INFO_SECURE(fmt, args...) SECURE_SLOGI(fmt, ##args)
67 #define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
68
69 #define ret_if(expr) \
70         do { \
71                 if (expr) { \
72                         BT_ERR("(%s) return", #expr); \
73                         return; \
74                 } \
75         } while (0)
76
77 #define retv_if(expr, val) \
78         do { \
79                 if (expr) { \
80                         BT_ERR("(%s) return", #expr); \
81                         return (val); \
82                 } \
83         } while (0)
84
85 #define BT_CHECK_PARAMETER(arg, func) \
86         do { \
87                 if (arg == NULL) { \
88                         BT_ERR("%s is NULL", #arg); \
89                         func BLUETOOTH_ERROR_INVALID_PARAM; \
90                 } \
91         } while (0)
92
93
94 #define BT_ADDRESS_LENGTH_MAX 6
95 #define BT_ADDRESS_STRING_SIZE 18
96 #define BT_RFCOMM_BUFFER_MAX 1024
97 #define BT_LOWER_ADDRESS_LENGTH 9
98
99 #define BT_AGENT_AUTO_PAIR_BLACKLIST_FILE (APP_SYSCONFDIR"/auto-pair-blacklist")
100 #define BT_AGENT_NEW_LINE "\r\n"
101
102 #define BT_MAX_DBUS_TIMEOUT 45000
103 #define BT_ENABLE_TIMEOUT ((TIZEN_PROFILE_TV) ? 5000 : 20000) /* 5(TV),20(others) seconds */
104 #define BT_DISCOVERY_FINISHED_DELAY 200
105
106 #define BT_SESSION_BUS_GET_TIMEOUT 200 /* 200 ms */
107
108 #define MANAGER_EVENT_MATCH_RULE \
109                         "type='signal'," \
110                         "interface='%s'," \
111                         "member='%s'"
112
113 #define EVENT_MATCH_RULE \
114                         "type='signal'," \
115                         "interface='%s',"
116
117 #define BT_TEMINATING_WAIT_TIME 200
118
119 #define BT_TIMEOUT_MESSAGE "Did not receive a reply. Possible causes include: " \
120                         "the remote application did not send a reply, " \
121                         "the message bus security policy blocked the reply, " \
122                         "the reply timeout expired, or the network connection " \
123                         "was broken."
124
125 #define BT_DBUS_TIMEOUT_MESSAGE "Timeout was reached"
126
127 #define BT_BLUEZ_NAME "org.bluez"
128
129 #define BT_BLUEZ_PATH "/org/bluez"
130 #define BT_BLUEZ_HCI_PATH "/org/bluez/hci0"
131 #define BT_AGENT_NAME "org.bluez.frwk_agent"
132 #define BT_AGENT_PATH "/org/bluez/agent/frwk_agent"
133 #define BT_DEVICE_AGENT_PATH "/org/tizen/device_agent"
134 #define BT_ADAPTER_AGENT_PATH "/org/tizen/adapter_agent"
135 #define BT_MANAGER_PATH "/"
136
137
138 #define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
139 #define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
140 #define BT_AGENT_INTERFACE "org.bluez.Agent1"
141 #define BT_AGENT_MANAGER_INTERFACE "org.bluez.AgentManager1"
142 #define BT_DEVICE_INTERFACE "org.bluez.Device1"
143 #define BT_NETWORK_SERVER_INTERFACE "org.bluez.NetworkServer1"
144 #define BT_MEDIA_INTERFACE "org.bluez.Media1"
145 #define BT_MEDIA_PLAYER_INTERFACE "org.mpris.MediaPlayer2.Player"
146 #define BT_MEDIATRANSPORT_INTERFACE "org.bluez.MediaTransport1"
147 #define BT_MEDIA_CONTROL_INTERFACE "org.bluez.MediaControl1"
148 #define BT_PLAYER_CONTROL_INTERFACE "org.bluez.MediaPlayer1"
149 #define BT_GATT_CHAR_INTERFACE "org.bluez.GattCharacteristic1"
150
151 #define BT_INPUT_INTERFACE "org.bluez.Input1"
152 #define BT_NETWORK_INTERFACE "org.bluez.Network"
153 #define BT_NETWORK_CLIENT_INTERFACE "org.bluez.Network1"
154 #define BT_SERIAL_INTERFACE "org.bluez.Serial"
155 #define BT_SERIAL_MANAGER_INTERFACE "org.bluez.SerialProxyManager"
156 #define BT_SERIAL_PROXY_INTERFACE "org.bluez.SerialProxy"
157 #define BT_SINK_INTERFACE "org.bluez.AudioSink"
158 #define BT_AUDIO_INTERFACE "org.bluez.Audio"
159 #define BT_HEADSET_INTERFACE "org.bluez.Headset"
160 #define BT_OOB_INTERFACE "org.bluez.OutOfBand"
161 #define BT_HANDSFREE_GATEWAY_INTERFACE "org.bluez.HandsfreeGateway"
162 #define BT_OBEXD_INTERFACE "org.openobex"
163 #define BT_OBEXD_MANAGER_INTERFACE "org.openobex.Manager"
164 #define BT_OBEXD_TRANSFER_INTERFACE "org.openobex.Transfer"
165 #define BT_A2DP_SOURCE_INTERFACE "org.bluez.AudioSource"
166 #define BT_PROXIMITY_MONITOR_INTERFACE "org.bluez.ProximityMonitor1"
167 #define BT_PROXIMITY_REPORTER_INTERFACE "org.bluez.ProximityReporter1"
168
169 #define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
170
171 #define BT_OBEX_SERVICE_NAME "org.bluez.obex"
172 #define BT_OBEX_CLIENT_PATH "/org/bluez/obex"
173 #define BT_OBEX_CLIENT_INTERFACE "org.bluez.obex.Client1"
174
175
176
177 #define BT_OBEX_TRANSFER_INTERFACE "org.bluez.obex.Transfer1"
178 #define BT_OBEX_AGENT_INTERFACE "org.bluez.obex.Agent1"
179
180
181
182 #define BT_OBEXD_DBUS_NAME "org.bluez.obex"
183 #define BT_OBEX_OBJECT_PUSH_INTERFACE "org.bluez.obex.ObjectPush1"
184
185
186 #define BT_FREEDESKTOP_INTERFACE "org.freedesktop.DBus"
187 #define BT_FREEDESKTOP_PATH "/org/freedesktop/DBus"
188
189
190 #define BT_DUMP_SERVICE_NAME "org.tizen.system.dumpservice"
191 #define BT_DUMP_SERVICE_PATH "/Org/Tizen/System/DumpService"
192 #define BT_DUMP_SERVICE_INTERFACE BT_DUMP_SERVICE_NAME
193
194 #define BT_DUMP_SERVICE_SIGNAL "Dump"
195 #define BT_DUMP_SERVICE_START_SIGNAL "Start"
196 #define BT_DUMP_SERVICE_FINISH_SIGNAL "Finish"
197
198
199 #define BT_INTERFACES_ADDED "InterfacesAdded"
200 #define BT_INTERFACES_REMOVED "InterfacesRemoved"
201 #define BT_NAME_OWNER_CHANGED "NameOwnerChanged"
202 #define BT_PROPERTIES_CHANGED "PropertiesChanged"
203
204
205
206 #define BT_SESSION_BASEPATH_SERVER "/org/bluez/obex/server"
207 #define BT_SESSION_BASEPATH_CLIENT "/org/bluez/obex/client"
208
209 #define BT_SERVICE_ERR_MSG_NOT_SUPPORTED "Operation is not supported"
210
211 /* UUID */
212 #define GENERIC_AUDIO_UUID      "00001203-0000-1000-8000-00805f9b34fb"
213
214 #define AVRCP_TARGET_UUID       "0000110c-0000-1000-8000-00805f9b34fb"
215 #define AVRCP_REMOTE_UUID       "0000110e-0000-1000-8000-00805f9b34fb"
216 #define ADVANCED_AUDIO_UUID     "0000110d-0000-1000-8000-00805f9b34fb"
217 #define A2DP_SINK_UUID          "0000110b-0000-1000-8000-00805f9b34fb"
218 #define A2DP_SOURCE_UUID        "0000110a-0000-1000-8000-00805f9b34fb"
219
220 #define HFP_HS_UUID             "0000111e-0000-1000-8000-00805f9b34fb"
221 #define HFP_AG_UUID             "0000111f-0000-1000-8000-00805f9b34fb"
222
223 #define HSP_HS_UUID             "00001108-0000-1000-8000-00805f9b34fb"
224 #define HSP_AG_UUID             "00001112-0000-1000-8000-00805f9b34fb"
225
226 #define RFCOMM_UUID_STR                 "00000003-0000-1000-8000-00805f9b34fb"
227 #define HID_DEVICE_UUID                 "00001124-0000-1000-8000-00805f9b43bf"
228 #define HID_UUID                "00001124-0000-1000-8000-00805f9b34fb"
229 #define PANU_UUID                               "00001115-0000-1000-8000-00805f9b34fb"
230 #define NAP_UUID                                "00001116-0000-1000-8000-00805f9b34fb"
231 #define PNP_UUID                "00001200-0000-1000-8000-00805f9b34fb"
232 #define PBAP_UUID               "0000112f-0000-1000-8000-00805f9b34fb"
233
234 #define OBEX_OPP_UUID                   "00001105-0000-1000-8000-00805f9b34fb"
235 #define OBEX_PSE_UUID                   "0000112f-0000-1000-8000-00805f9b34fb"
236
237 #define GATT_UUID                               "00001801-0000-1000-8000-00805f9b34fb"
238
239 /* Privilege */
240 #define BT_PRIVILEGE_PUBLIC "http://tizen.org/privilege/bluetooth"
241 #define BT_PRIVILEGE_PLATFORM "http://tizen.org/privilege/bluetooth.admin"
242 #define MEDIASTORAGE_PRIVILEGE "http://tizen.org/privilege/mediastorage"
243
244 /* BD Address type */
245 #define BDADDR_BREDR           0x00
246 #define BDADDR_LE_PUBLIC       0x01
247 #define BDADDR_LE_RANDOM       0x02
248
249 /* Advertising report event types */
250 #define BT_LE_ADV_IND           0x00
251 #define BT_LE_ADV_DIRECT_IND    0x01
252 #define BT_LE_ADV_SCAN_IND              0x02
253 #define BT_LE_ADV_NONCONN_IND   0x03
254 #define BT_LE_ADV_SCAN_RSP              0x04
255
256 /* Profile states matched to btd_service_state_t of bluez service.h */
257 typedef enum {
258         BT_PROFILE_STATE_UNAVAILABLE,
259         BT_PROFILE_STATE_DISCONNECTED,
260         BT_PROFILE_STATE_CONNECTING,
261         BT_PROFILE_STATE_CONNECTED,
262         BT_PROFILE_STATE_DISCONNECTING,
263 } bt_profile_state_t;
264
265 typedef enum {
266         BT_ADV_IND_INFO = 0x00,
267         BT_SCAN_RSP_INFO = 0x01,
268 } bt_le_device_info_type_t;
269
270 typedef enum {
271         BT_PROFILE_CONN_RFCOMM = 0x01,
272         BT_PROFILE_CONN_A2DP = 0x02,
273         BT_PROFILE_CONN_HSP = 0x04,
274         BT_PROFILE_CONN_HID = 0x08,
275         BT_PROFILE_CONN_NAP = 0x10,
276         BT_PROFILE_CONN_HFG = 0x20,
277         BT_PROFILE_CONN_GATT = 0x40,
278         BT_PROGILE_CONN_NAP = 0x80,
279         BT_PROFILE_CONN_A2DP_SINK = 0x100,
280         BT_PROFILE_CONN_PBAP = 0x200,
281         BT_PROFILE_CONN_ALL = 0xffffffff,
282 } bt_profile_type_t;
283
284 typedef struct {
285         char *address;
286         int addr_type;
287         int rssi;
288         int adv_type;
289         bt_le_device_info_type_t dev_type;
290         int adv_data_len;
291         char *adv_data;
292 } bt_remote_le_dev_info_t;
293
294 typedef struct {
295         int rssi;
296         int class;
297         char *address;
298         char *name;
299         char **uuids;
300         unsigned int uuid_count;
301         gboolean paired;
302         bluetooth_connected_link_t connected;
303         gboolean trust;
304         gboolean is_alias_set;
305         char *manufacturer_data;
306         int manufacturer_data_len;
307         guchar addr_type;
308 #if 0 /* Should match with bt_dev_info_t in bluetooth-api.h */
309         bt_remote_le_dev_info_t le_dev_info;
310 #endif
311 } bt_remote_dev_info_t;
312
313 /* RFCOMM client /server will use this structure*/
314 typedef struct {
315         int fd;
316         GIOChannel *io_channel;
317         guint io_event;
318         char *dev_node;
319         char *address;
320         char *uuid;
321 } bt_rfcomm_info_t;
322
323 typedef struct {
324         int req_id;
325         char *address;
326 } bt_function_data_t;
327
328 GDBusConnection *_bt_gdbus_get_system_gconn(void);
329
330 GDBusConnection *_bt_gdbus_get_session_gconn(void);
331
332 void *_bt_get_net_conn(void);
333
334 GDBusProxy *_bt_get_manager_proxy(void);
335
336 GDBusProxy *_bt_get_adapter_proxy(void);
337
338 GDBusProxy *_bt_get_adapter_properties_proxy(void);
339
340 char *_bt_get_device_object_path(char *address);
341
342 char *_bt_get_profile_uuid128(bt_profile_type_t profile_type);
343
344 char *_bt_convert_error_to_string(int error);
345
346 char * _bt_convert_disc_reason_to_string(int reason);
347
348 void _bt_logging_connection(gboolean connect, int addr_type);
349
350 char *_bt_get_adapter_path(void);
351
352 void _bt_deinit_proxys(void);
353
354 void _bt_convert_device_path_to_address(const char *device_path,
355                                                 char *device_address);
356
357 void _bt_convert_addr_string_to_type(unsigned char *addr,
358                                         const char *address);
359
360 void _bt_convert_addr_string_to_secure_string(char *addr,
361                                         const char *address);
362
363 void _bt_convert_addr_type_to_string(char *address,
364                                 unsigned char *addr);
365
366 void _bt_swap_byte_ordering(char *data, int data_len);
367
368 int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len);
369
370 int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
371                                 const char *mask, int data_len);
372
373 void _bt_print_device_address_t(const bluetooth_device_address_t *addr);
374
375 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
376                                 unsigned int cod);
377
378 void _bt_free_device_info(bt_remote_dev_info_t *dev_info);
379
380 void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info);
381
382 int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length);
383
384 gboolean _bt_utf8_validate(char *name);
385
386 int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd);
387
388 int _bt_unregister_osp_server_in_agent(int type, char *uuid);
389
390 int _bt_set_socket_non_blocking(int socket_fd);
391
392 int _bt_set_non_blocking_tty(int sk);
393
394 void _bt_deinit_bluez_proxy(void);
395
396 int _bt_eventsystem_set_value(const char *event, const char *key, const char *value);
397
398 void __bt_get_auth_info(GVariant *reply,  char *auth_info);
399
400 int _bt_convert_gerror(GError *g_error);
401
402 #ifdef __cplusplus
403 }
404 #endif /* __cplusplus */
405 #endif /*_BT_COMMON_H_*/
406