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