e5e8e3d5812d5e1f4eb55e7565308a4a27e8401d
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / 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-request-handler.h"
29 #include <oal-manager.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 #define BT_DBG(fmt, args...) \
54         SLOGD(fmt, ##args)
55 #define BT_INFO(fmt, args...) \
56         SLOGI(fmt, ##args)
57 #define BT_ERR(fmt, args...) \
58         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 #ifdef TIZEN_FEATURE_BT_OBEX
67 #define INFO_SECURE(fmt, args...) SECURE_SLOGI(fmt, ##args)
68 #endif
69 #define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
70
71 #define ret_if(expr) \
72         do { \
73                 if (expr) { \
74                         BT_ERR("(%s) return", #expr); \
75                         return; \
76                 } \
77         } while (0)
78
79 #define retv_if(expr, val) \
80         do { \
81                 if (expr) { \
82                         BT_ERR("(%s) return", #expr); \
83                         return (val); \
84                 } \
85         } while (0)
86
87 #define BT_CHECK_PARAMETER(arg, func) \
88         do { \
89                 if (arg == NULL) { \
90                         BT_ERR("%s is NULL", #arg); \
91                         func BLUETOOTH_ERROR_INVALID_PARAM; \
92                 } \
93         } while (0)
94
95
96 #define BT_ADDRESS_LENGTH_MAX 6
97 #define BT_ADDRESS_STRING_SIZE 18
98 #define BT_RFCOMM_BUFFER_MAX 1024
99 #define BT_LOWER_ADDRESS_LENGTH 9
100 #define BT_UUID_LEN 16
101
102 #define BT_AGENT_AUTO_PAIR_BLACKLIST_FILE (APP_SYSCONFDIR"/auto-pair-blacklist")
103 #define BT_AGENT_NEW_LINE "\r\n"
104
105 #define BT_MAX_DBUS_TIMEOUT 45000
106 #ifndef TIZEN_TV
107 #define BT_ENABLE_TIMEOUT 20000 /* 20 seconds */
108 #else
109 #define BT_ENABLE_TIMEOUT 5000 /* 5 seconds */
110 #endif
111 #define BT_DISCOVERY_FINISHED_DELAY 200
112
113 #define MANAGER_EVENT_MATCH_RULE \
114                         "type='signal'," \
115                         "interface='%s'," \
116                         "member='%s'"
117
118 #define EVENT_MATCH_RULE \
119                         "type='signal'," \
120                         "interface='%s',"
121
122 #define BT_TEMINATING_WAIT_TIME 200
123
124 #define BT_TIMEOUT_MESSAGE "Did not receive a reply. Possible causes include: " \
125                         "the remote application did not send a reply, " \
126                         "the message bus security policy blocked the reply, " \
127                         "the reply timeout expired, or the network connection " \
128                         "was broken."
129
130 #define BT_BLUEZ_NAME "org.bluez"
131
132 #ifdef TIZEN_FEATURE_BT_IPSP
133 #define BT_IPSP_NAME "org.projectx.bt_ipsp"
134 #define BT_IPSP_INTERFACE "org.projectx.bt_ipsp"
135 #endif
136
137 #define BT_BLUEZ_PATH "/org/bluez"
138 #define BT_BLUEZ_HCI_PATH "/org/bluez/hci0"
139 #define BT_AGENT_NAME "org.bluez.frwk_agent"
140 #define BT_AGENT_PATH "/org/bluez/agent/frwk_agent"
141 #define BT_DEVICE_AGENT_PATH "/org/tizen/device_agent"
142 #define BT_ADAPTER_AGENT_PATH "/org/tizen/adapter_agent"
143 #define BT_MANAGER_PATH "/"
144
145
146 #define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
147 #define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
148 #define BT_AGENT_INTERFACE "org.bluez.Agent1"
149 #define BT_AGENT_MANAGER_INTERFACE "org.bluez.AgentManager1"
150 #define BT_DEVICE_INTERFACE "org.bluez.Device1"
151 #define BT_NETWORK_SERVER_INTERFACE "org.bluez.NetworkServer1"
152 #define BT_MEDIA_INTERFACE "org.bluez.Media1"
153 #define BT_MEDIA_PLAYER_INTERFACE "org.mpris.MediaPlayer2.Player"
154 #define BT_MEDIATRANSPORT_INTERFACE "org.bluez.MediaTransport1"
155 #define BT_MEDIA_CONTROL_INTERFACE "org.bluez.MediaControl1"
156 #define BT_PLAYER_CONTROL_INTERFACE "org.bluez.MediaPlayer1"
157 #define BT_GATT_CHAR_INTERFACE "org.bluez.GattCharacteristic1"
158
159 #define BT_INPUT_INTERFACE "org.bluez.Input1"
160 #define BT_NETWORK_INTERFACE "org.bluez.Network"
161 #define BT_NETWORK_CLIENT_INTERFACE "org.bluez.Network1"
162 #define BT_SERIAL_INTERFACE "org.bluez.Serial"
163 #define BT_SERIAL_MANAGER_INTERFACE "org.bluez.SerialProxyManager"
164 #define BT_SERIAL_PROXY_INTERFACE "org.bluez.SerialProxy"
165 #define BT_SINK_INTERFACE "org.bluez.AudioSink"
166 #define BT_AUDIO_INTERFACE "org.bluez.Audio"
167 #define BT_HEADSET_INTERFACE "org.bluez.Headset"
168 #define BT_OOB_INTERFACE "org.bluez.OutOfBand"
169 #define BT_HANDSFREE_GATEWAY_INTERFACE "org.bluez.HandsfreeGateway"
170 #define BT_OBEXD_INTERFACE "org.openobex"
171 #define BT_OBEXD_MANAGER_INTERFACE "org.openobex.Manager"
172 #define BT_OBEXD_TRANSFER_INTERFACE "org.openobex.Transfer"
173 #define BT_A2DP_SOURCE_INTERFACE "org.bluez.AudioSource"
174
175 #define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
176
177
178 #define BT_OBEX_SERVICE_NAME "org.bluez.obex"
179 #define BT_OBEX_CLIENT_PATH "/org/bluez/obex"
180 #define BT_OBEX_CLIENT_INTERFACE "org.bluez.obex.Client1"
181 #ifdef TIZEN_FEATURE_BT_OBEX
182 #define BT_OBEX_MESSAGE_INTERFACE "org.bluez.obex.MessageAccess1"
183 #endif
184
185 #define BT_OBEX_TRANSFER_INTERFACE "org.bluez.obex.Transfer1"
186 #define BT_OBEX_AGENT_INTERFACE "org.bluez.obex.Agent1"
187
188
189
190 #define BT_OBEXD_DBUS_NAME "org.bluez.obex"
191 #define BT_OBEX_OBJECT_PUSH_INTERFACE "org.bluez.obex.ObjectPush1"
192
193
194 #define BT_FREEDESKTOP_INTERFACE "org.freedesktop.DBus"
195 #define BT_FREEDESKTOP_SERVICE "org.freedesktop.DBus"
196 #define BT_FREEDESKTOP_PATH "/org/freedesktop/DBus"
197
198 #define BT_DUMP_SERVICE_NAME "org.tizen.system.dumpservice"
199 #define BT_DUMP_SERVICE_PATH "/Org/Tizen/System/DumpService"
200 #define BT_DUMP_SERVICE_INTERFACE BT_DUMP_SERVICE_NAME
201
202 #define BT_DUMP_SERVICE_SIGNAL "Dump"
203 #define BT_DUMP_SERVICE_START_SIGNAL "Start"
204 #define BT_DUMP_SERVICE_FINISH_SIGNAL "Finish"
205
206 #define BT_INTERFACES_ADDED "InterfacesAdded"
207 #define BT_INTERFACES_REMOVED "InterfacesRemoved"
208 #define BT_NAME_OWNER_CHANGED "NameOwnerChanged"
209 #define BT_PROPERTIES_CHANGED "PropertiesChanged"
210 #define BT_IPSP_STATE_CHANGE "IpspStateChanged"
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 OBEX_OPP_UUID           "00001105-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 HFP_HS_UUID             "0000111e-0000-1000-8000-00805f9b34fb"
227 #define HFP_AG_UUID             "0000111f-0000-1000-8000-00805f9b34fb"
228
229 #define ADVANCED_AUDIO_UUID     "0000110d-0000-1000-8000-00805f9b34fb"
230
231 #define A2DP_SOURCE_UUID        "0000110a-0000-1000-8000-00805f9b34fb"
232 #define A2DP_SINK_UUID          "0000110b-0000-1000-8000-00805f9b34fb"
233
234 #define AVRCP_REMOTE_UUID       "0000110e-0000-1000-8000-00805f9b34fb"
235 #define AVRCP_TARGET_UUID       "0000110c-0000-1000-8000-00805f9b34fb"
236
237 #define HID_UUID                "00001124-0000-1000-8000-00805f9b34fb"
238 #define PNP_UUID                "00001200-0000-1000-8000-00805f9b34fb"
239 #define RFCOMM_UUID_STR         "00000003-0000-1000-8000-00805f9b34fb"
240 #define PANU_UUID               "00001115-0000-1000-8000-00805f9b34fb"
241 #define NAP_UUID                "00001116-0000-1000-8000-00805f9b34fb"
242 #define OBEX_PSE_UUID           "0000112f-0000-1000-8000-00805f9b34fb"
243 #define GATT_UUID               "00001801-0000-1000-8000-00805f9b34fb"
244
245 /* Privilege */
246 #define BT_PRIVILEGE_PUBLIC "http://tizen.org/privilege/bluetooth"
247 #define BT_PRIVILEGE_PLATFORM "http://tizen.org/privilege/bluetooth.admin"
248 #define MEDIASTORAGE_PRIVILEGE "http://tizen.org/privilege/mediastorage"
249
250 /* BD Address type */
251 #define BDADDR_BREDR           0x00
252 #define BDADDR_LE_PUBLIC       0x01
253 #define BDADDR_LE_RANDOM       0x02
254
255 /* Advertising report event types */
256 #define BT_LE_ADV_IND           0x00
257 #define BT_LE_ADV_DIRECT_IND    0x01
258 #define BT_LE_ADV_SCAN_IND              0x02
259 #define BT_LE_ADV_NONCONN_IND   0x03
260 #define BT_LE_ADV_SCAN_RSP              0x04
261
262 /* Profile states matched to btd_service_state_t of bluez service.h */
263 typedef enum {
264         BT_PROFILE_STATE_UNAVAILABLE,
265         BT_PROFILE_STATE_DISCONNECTED,
266         BT_PROFILE_STATE_CONNECTING,
267         BT_PROFILE_STATE_CONNECTED,
268         BT_PROFILE_STATE_DISCONNECTING,
269 } bt_profile_state_t;
270
271 typedef enum {
272         BT_ADV_IND_INFO = 0x00,
273         BT_SCAN_RSP_INFO = 0x01,
274 } bt_le_device_info_type_t;
275
276 typedef enum {
277         BT_PROFILE_CONN_RFCOMM = 0x01,
278         BT_PROFILE_CONN_A2DP = 0x02,
279         BT_PROFILE_CONN_HSP = 0x04,
280         BT_PROFILE_CONN_HID = 0x08,
281         BT_PROFILE_CONN_NAP = 0x10,
282         BT_PROFILE_CONN_HFG = 0x20,
283         BT_PROFILE_CONN_GATT = 0x40,
284         BT_PROGILE_CONN_NAP = 0x80,
285         BT_PROFILE_CONN_A2DP_SINK = 0x100,
286         BT_PROFILE_CONN_ALL = 0xffffffff,
287 } bt_profile_type_t;
288
289 typedef struct {
290         char *address;
291         int addr_type;
292         int rssi;
293         int adv_type;
294         bt_le_device_info_type_t dev_type;
295         int adv_data_len;
296         char *adv_data;
297 } bt_remote_le_dev_info_t;
298
299 typedef struct {
300         int rssi;
301         int class;
302         char *address;
303         char *name;
304         char *alias;
305         char **uuids;
306         unsigned int uuid_count;
307         gboolean paired;
308         bluetooth_connected_link_t connected;
309         gboolean trust;
310         gboolean is_alias_set;
311         char *manufacturer_data;
312         int manufacturer_data_len;
313         guchar addr_type;
314 #if 0 /* Should match with bt_dev_info_t in bluetooth-api.h */
315         bt_remote_le_dev_info_t le_dev_info;
316 #endif
317         int vid;
318         int pid;
319         int device_type;
320 } bt_remote_dev_info_t;
321
322 /* RFCOMM client /server will use this structure*/
323 typedef struct {
324         int fd;
325         GIOChannel *io_channel;
326         guint io_event;
327         char *dev_node;
328         char *address;
329         char *uuid;
330 } bt_rfcomm_info_t;
331
332 typedef struct {
333         int req_id;
334         char *address;
335 } bt_function_data_t;
336
337 typedef struct {
338         int count;
339         bluetooth_device_address_t *addr_list;
340         GArray *out_param;
341 } bonded_devices_req_info_t;
342
343 GDBusConnection *_bt_get_system_conn(void);
344
345 GDBusConnection *_bt_get_system_gconn(void);
346
347 GDBusConnection *_bt_get_session_gconn(void);
348
349 void *_bt_get_net_conn(void);
350
351 GDBusProxy *_bt_get_manager_proxy(void);
352
353 GDBusProxy *_bt_get_adapter_proxy(void);
354
355 #ifdef TIZEN_FEATURE_BT_IPSP
356 GDBusProxy *_bt_get_ipsp_proxy(void);
357 #endif
358 GDBusProxy *_bt_get_adapter_properties_proxy(void);
359
360 char *_bt_get_device_object_path(char *address);
361
362 char *_bt_get_profile_uuid128(bt_profile_type_t profile_type);
363
364 const char *_bt_convert_error_to_string(int error);
365
366 const char * _bt_convert_disc_reason_to_string(int reason);
367
368 void _bt_logging_connection(gboolean connect, int addr_type);
369
370 char *_bt_get_adapter_path(void);
371
372 void _bt_deinit_proxys(void);
373
374 void _bt_convert_device_path_to_address(const char *device_path,
375                                                 char *device_address);
376
377 void _bt_convert_addr_string_to_type(unsigned char *addr,
378                                         const char *address);
379
380 void _bt_convert_addr_type_to_string(char *address,
381                                 unsigned char *addr);
382
383 void _bt_swap_byte_ordering(char *data, int data_len);
384
385 int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len);
386
387 int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
388                                 const char *mask, int data_len);
389
390 gboolean _bt_compare_adddress(const bluetooth_device_address_t *addr1,
391                 const bluetooth_device_address_t *addr2);
392
393 void _bt_print_device_address_t(const bluetooth_device_address_t *addr);
394
395 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
396                                 unsigned int cod);
397
398 void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info);
399
400 int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length);
401
402 gboolean _bt_utf8_validate(char *name);
403
404 int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd);
405
406 int _bt_unregister_osp_server_in_agent(int type, char *uuid);
407
408 int _bt_set_socket_non_blocking(int socket_fd);
409
410 int _bt_set_non_blocking_tty(int sk);
411
412 void _bt_deinit_bluez_proxy(void);
413
414 int _bt_eventsystem_set_value(const char *event, const char *key, const char *value);
415
416 void _bt_copy_remote_dev(bt_remote_dev_info_t * dev_info, remote_device_t * oal_device);
417
418 void _bt_uuid_to_string(service_uuid_t *p_uuid, char *str);
419
420 void _bt_truncate_non_utf8_chars(char * str);
421
422 void _bt_copy_remote_device(bt_remote_dev_info_t *rem_dev, bluetooth_device_info_t *dev);
423
424 void _bt_service_print_dev_info(bluetooth_device_info_t *dev_info);
425
426 void _bt_free_remote_dev(bt_remote_dev_info_t * dev_info);
427
428 void _bt_set_device_values(gboolean connected, int state);
429
430 void _bt_string_to_uuid(char *str, service_uuid_t *p_uuid);
431
432 int _bt_get_ad_data_by_type(char *in_data, int in_len,
433                 char in_type, char **data, int *data_len);
434
435 invocation_info_t* _bt_get_request_info_data(int service_function, char *address);
436
437 extern bt_plugin_info_t *headed_plugin_info;
438
439 #if defined(TIZEN_FEATURE_BT_OBEX) || defined(TIZEN_FEATURE_BT_PAN_NAP)
440 GDBusConnection *_bt_gdbus_get_system_gconn(void);
441 #endif
442
443 void _bt_copy_remote_dev_info(bt_remote_dev_info_t *dest, bt_remote_dev_info_t *src);
444
445 #ifdef __cplusplus
446 }
447 #endif /* __cplusplus */
448 #endif /*_BT_COMMON_H_*/
449