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