Merge branch 'master' into tizen_2.1
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / include / bt-service-common.h
1 /*
2  * bluetooth-frwk
3  *
4  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *              http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef _BT_SERVICE_COMMON_H_
21 #define _BT_SERVICE_COMMON_H_
22
23 #include <sys/types.h>
24 #include <dlog.h>
25 #include <dbus/dbus-glib.h>
26 #include <dbus/dbus.h>
27
28 #include "bluetooth-api.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #undef LOG_TAG
35 #define LOG_TAG "BLUETOOTH_FRWK_SERVICE"
36
37 #define BT_DBG(fmt, args...) \
38         SLOGD(fmt, ##args)
39 #define BT_ERR(fmt, args...) \
40         SLOGE(fmt, ##args)
41
42 #define ret_if(expr) \
43         do { \
44                 if (expr) { \
45                         BT_ERR("(%s) return", #expr); \
46                         return; \
47                 } \
48         } while (0)
49
50 #define retv_if(expr, val) \
51         do { \
52                 if (expr) { \
53                         BT_ERR("(%s) return", #expr); \
54                         return (val); \
55                 } \
56         } while (0)
57
58 #define BT_CHECK_PARAMETER(arg, func) \
59         do { \
60                 if (arg == NULL) \
61                 { \
62                         BT_ERR("INVALID PARAMETER"); \
63                         func BLUETOOTH_ERROR_INVALID_PARAM; \
64                 } \
65         } while (0)
66
67 #define BT_CHANNEL_LENGTH_MAX 5
68 #define BT_ADDRESS_LENGTH_MAX 6
69 #define BT_ADDRESS_STRING_SIZE 18
70 #define BT_RFCOMM_BUFFER_MAX 1024
71 #define BT_LOWER_ADDRESS_LENGTH 9
72
73 #define BT_AGENT_AUTO_PAIR_BLACKLIST_FILE (APP_SYSCONFDIR"/auto-pair-blacklist")
74 #define BT_AGENT_NEW_LINE "\r\n"
75
76 #define BT_MAX_DBUS_TIMEOUT 45000
77 #define BT_ENABLE_TIMEOUT 5000 /* 5 seconds */
78 #define BT_DISCOVERY_FINISHED_DELAY 200
79
80 #define MANAGER_EVENT_MATCH_RULE \
81                         "type='signal'," \
82                         "interface='%s'," \
83                         "path='%s'"
84
85 #define EVENT_MATCH_RULE \
86                         "type='signal'," \
87                         "interface='%s',"
88
89 #define BT_TEMINATING_WAIT_TIME 200
90
91 #define BT_TIMEOUT_MESSAGE "Did not receive a reply. Possible causes include: " \
92                         "the remote application did not send a reply, " \
93                         "the message bus security policy blocked the reply, " \
94                         "the reply timeout expired, or the network connection " \
95                         "was broken."
96
97 #define BT_BLUEZ_NAME "org.bluez"
98 #define BT_AGENT_NAME "org.bluez.frwk_agent"
99 #define BT_AGENT_PATH "/org/bluez/agent/frwk_agent"
100 #define BT_DEVICE_AGENT_PATH "/org/tizen/device_agent"
101 #define BT_ADAPTER_AGENT_PATH "/org/tizen/adapter_agent"
102 #define BT_MANAGER_PATH "/"
103 #define BT_MANAGER_INTERFACE "org.bluez.Manager"
104 #define BT_ADAPTER_INTERFACE "org.bluez.Adapter"
105 #define BT_AGENT_INTERFACE "org.bluez.Agent"
106 #define BT_DEVICE_INTERFACE "org.bluez.Device"
107 #define BT_INPUT_INTERFACE "org.bluez.Input"
108 #define BT_NETWORK_INTERFACE "org.bluez.Network"
109 #define BT_NETWORK_SERVER_INTERFACE "org.bluez.NetworkServer"
110 #define BT_NETWORK_CLIENT_INTERFACE "org.bluez.Network"
111 #define BT_SERIAL_INTERFACE "org.bluez.Serial"
112 #define BT_SERIAL_MANAGER_INTERFACE "org.bluez.SerialProxyManager"
113 #define BT_SERIAL_PROXY_INTERFACE "org.bluez.SerialProxy"
114 #define BT_HEADSET_INTERFACE "org.bluez.Headset"
115 #define BT_SINK_INTERFACE "org.bluez.AudioSink"
116 #define BT_AUDIO_INTERFACE "org.bluez.Audio"
117 #define BT_OOB_INTERFACE "org.bluez.OutOfBand"
118 #define BT_MEDIA_INTERFACE "org.bluez.Media"
119 #define BT_MEDIA_PLAYER_INTERFACE "org.bluez.MediaPlayer"
120 #define BT_OBEXD_INTERFACE "org.openobex"
121 #define BT_OBEXD_MANAGER_INTERFACE "org.openobex.Manager"
122 #define BT_OBEXD_TRANSFER_INTERFACE "org.openobex.Transfer"
123
124 #define BT_OBEX_SERVICE_NAME "org.openobex.client"
125
126 #define BT_OBEX_CLIENT_PATH "/"
127 #define BT_OBEX_CLIENT_INTERFACE "org.openobex.Client"
128 #define BT_OBEX_TRANSFER_INTERFACE "org.openobex.Transfer"
129 #define BT_OBEX_AGENT_INTERFACE "org.openobex.Agent"
130
131 #define BT_FREEDESKTOP_INTERFACE "org.freedesktop.DBus"
132 #define BT_FREEDESKTOP_PATH "/org/freedesktop/DBus"
133
134 typedef enum {
135         BT_OBEX_SERVER = 0x00,
136         BT_RFCOMM_SERVER = 0x01,
137 } bt_osp_server_type_t;
138
139 typedef struct {
140         int rssi;
141         int class;
142         char *address;
143         char *name;
144         char **uuids;
145         int uuid_count;
146         gboolean paired;
147         gboolean connected;
148         gboolean trust;
149 } bt_remote_dev_info_t;
150
151 /* RFCOMM client /server will use this structure*/
152 typedef struct {
153         int fd;
154         GIOChannel *io_channel;
155         guint io_event;
156         char *dev_node;
157         char *address;
158         char *uuid;
159 } bt_rfcomm_info_t;
160
161 typedef struct {
162         int req_id;
163         char *address;
164 } bt_function_data_t;
165
166 DBusConnection *_bt_get_system_conn(void);
167
168 DBusGConnection *_bt_get_system_gconn(void);
169
170 DBusGConnection *_bt_get_session_gconn(void);
171
172 DBusGProxy *_bt_get_manager_proxy(void);
173
174 DBusGProxy *_bt_get_adapter_proxy(void);
175
176 char *_bt_get_adapter_path(void);
177
178 void _bt_deinit_proxys(void);
179
180 void _bt_convert_device_path_to_address(const char *device_path,
181                                                 char *device_address);
182
183 void _bt_convert_addr_string_to_type(unsigned char *addr,
184                                         const char *address);
185
186 void _bt_convert_addr_type_to_string(char *address,
187                                 unsigned char *addr);
188
189 void _bt_print_device_address_t(const bluetooth_device_address_t *addr);
190
191 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
192                                 unsigned int cod);
193
194 void _bt_free_device_info(bt_remote_dev_info_t *dev_info);
195
196 int _bt_register_osp_server_in_agent(int type, char *uuid);
197
198 int _bt_unregister_osp_server_in_agent(int type, char *uuid);
199
200 int _bt_set_socket_non_blocking(int socket_fd);
201
202 int _bt_set_non_blocking_tty(int sk);
203
204 gboolean _bt_is_headset_class(int dev_class);
205
206 void _bt_deinit_bluez_proxy(void);
207
208 #ifdef __cplusplus
209 }
210 #endif /* __cplusplus */
211 #endif /*_BT_COMMON_H_*/
212