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