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