Rollback changes to submit TIZEN:COMMON project
[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                         "member='%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_BLUEZ_PATH "/org/bluez"
99 #define BT_BLUEZ_HCI_PATH "/org/bluez/hci0"
100 #define BT_BLUEZ_HCI_DEV_PATH "/org/bluez/hci0/dev"
101 #define BT_AGENT_NAME "org.bluez.frwk_agent"
102 #define BT_AGENT_PATH "/org/bluez/agent/frwk_agent"
103 #define BT_DEVICE_AGENT_PATH "/org/tizen/device_agent"
104 #define BT_ADAPTER_AGENT_PATH "/org/tizen/adapter_agent"
105 #define BT_MANAGER_PATH "/"
106 #define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
107 #define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
108 #define BT_AGENT_INTERFACE "org.bluez.Agent1"
109 #define BT_AGENT_MANAGER_INTERFACE "org.bluez.AgentManager1"
110 #define BT_DEVICE_INTERFACE "org.bluez.Device1"
111 #define BT_INPUT_INTERFACE "org.bluez.Input"
112 #define BT_NETWORK_INTERFACE "org.bluez.Network1"
113 #define BT_NETWORK_SERVER_INTERFACE "org.bluez.NetworkServer1"
114 #define BT_NETWORK_CLIENT_INTERFACE "org.bluez.Network1"
115 #define BT_SERIAL_INTERFACE "org.bluez.Serial"
116 #define BT_SERIAL_MANAGER_INTERFACE "org.bluez.SerialProxyManager"
117 #define BT_SERIAL_PROXY_INTERFACE "org.bluez.SerialProxy"
118 #define BT_HFP_AGENT_INTERFACE "Org.Hfp.App.Interface"
119 #define BT_SINK_INTERFACE "org.bluez.AudioSink"
120 #define BT_AUDIO_INTERFACE "org.bluez.Audio"
121 #define BT_OOB_INTERFACE "org.bluez.OutOfBand"
122 #define BT_MEDIA_INTERFACE "org.bluez.Media1"
123 #define BT_MEDIA_PLAYER_INTERFACE "org.mpris.MediaPlayer2.Player"
124 #define BT_OBEXD_DBUS_NAME "org.bluez.obex"
125 #define BT_OBEXD_MANAGER_INTERFACE "org.bluez.obex.AgentManager1"
126 #define BT_OBEXD_TRANSFER_INTERFACE "org.bluez.obex.Transfer1"
127 #define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
128 #define BT_MEDIA_CONTROL_INTERFACE "org.bluez.MediaControl1"
129 #define MPRIS_PLAYER_INTERFACE "org.mpris.MediaPlayer2.Player"
130
131 #define BT_OBEX_SERVICE_NAME "org.bluez.obex"
132
133 #define BT_OBEX_CLIENT_PATH "/org/bluez/obex"
134 #define BT_OBEX_CLIENT_INTERFACE "org.bluez.obex.Client1"
135 #define BT_OBEX_OBJECT_PUSH_INTERFACE "org.bluez.obex.ObjectPush1"
136 #define BT_OBEX_TRANSFER_INTERFACE "org.bluez.obex.Transfer1"
137 #define BT_OBEX_AGENT_INTERFACE "org.bluez.obex.Agent1"
138
139 #define BT_SESSION_BASEPATH_SERVER "/org/bluez/obex/server"
140 #define BT_SESSION_BASEPATH_CLIENT "/org/bluez/obex/client"
141
142 #define BT_FREEDESKTOP_INTERFACE "org.freedesktop.DBus"
143 #define BT_FREEDESKTOP_PATH "/org/freedesktop/DBus"
144
145 #define BT_INTERFACES_ADDED "InterfacesAdded"
146 #define BT_INTERFACES_REMOVED "InterfacesRemoved"
147 #define BT_NAME_OWNER_CHANGED "NameOwnerChanged"
148 #define BT_PROPERTIES_CHANGED "PropertiesChanged"
149 #define DBUS_INTERFACE_OBJECT_MANAGER "/"
150
151 #define GENERIC_AUDIO_UUID      "00001203-0000-1000-8000-00805f9b34fb"
152
153 #define HSP_HS_UUID             "00001108-0000-1000-8000-00805f9b34fb"
154 #define HSP_AG_UUID             "00001112-0000-1000-8000-00805f9b34fb"
155
156 #define HFP_HS_UUID             "0000111e-0000-1000-8000-00805f9b34fb"
157 #define HFP_AG_UUID             "0000111f-0000-1000-8000-00805f9b34fb"
158
159 #define ADVANCED_AUDIO_UUID     "0000110d-0000-1000-8000-00805f9b34fb"
160
161 #define A2DP_SOURCE_UUID        "0000110a-0000-1000-8000-00805f9b34fb"
162 #define A2DP_SINK_UUID          "0000110b-0000-1000-8000-00805f9b34fb"
163
164 #define AVRCP_REMOTE_UUID       "0000110e-0000-1000-8000-00805f9b34fb"
165 #define AVRCP_TARGET_UUID       "0000110c-0000-1000-8000-00805f9b34fb"
166
167 #define HID_UUID                "00001124-0000-1000-8000-00805f9b34fb"
168 #define PNP_UUID                "00001200-0000-1000-8000-00805f9b34fb"
169
170 #define BT_STOP_DISCOVERY_TIMEOUT 1000*15
171
172 typedef enum {
173         BT_OBEX_SERVER = 0x00,
174         BT_RFCOMM_SERVER = 0x01,
175 } bt_osp_server_type_t;
176
177 typedef struct {
178         int rssi;
179         int class;
180         char *address;
181         char *name;
182         char **uuids;
183         int uuid_count;
184         gboolean paired;
185         gboolean connected;
186         gboolean trust;
187 } bt_remote_dev_info_t;
188
189 /* RFCOMM client /server will use this structure*/
190 typedef struct {
191         int fd;
192         GIOChannel *io_channel;
193         guint io_event;
194         char *dev_node;
195         char *address;
196         char *uuid;
197 } bt_rfcomm_info_t;
198
199 typedef struct {
200         int req_id;
201         char *address;
202 } bt_function_data_t;
203
204 DBusConnection *_bt_get_system_conn(void);
205
206 DBusGConnection *_bt_get_system_gconn(void);
207
208 DBusGConnection *_bt_get_session_gconn(void);
209
210 DBusGProxy *_bt_get_manager_proxy(void);
211
212 DBusGProxy *_bt_get_adapter_proxy(void);
213
214 DBusGProxy *_bt_get_adapter_properties_proxy(void);
215
216 char *_bt_get_adapter_path(void);
217
218 gboolean _bt_get_adapter_power(void);
219
220 void _bt_deinit_proxys(void);
221
222 void _bt_convert_device_path_to_address(const char *device_path,
223                                                 char *device_address);
224
225 void _bt_convert_addr_string_to_type(unsigned char *addr,
226                                         const char *address);
227
228 void _bt_convert_addr_type_to_string(char *address,
229                                 unsigned char *addr);
230
231 void _bt_print_device_address_t(const bluetooth_device_address_t *addr);
232
233 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
234                                 unsigned int cod);
235
236 void _bt_free_device_info(bt_remote_dev_info_t *dev_info);
237
238 int _bt_register_osp_server_in_agent(int type, char *uuid);
239
240 int _bt_unregister_osp_server_in_agent(int type, char *uuid);
241
242 int _bt_set_socket_non_blocking(int socket_fd);
243
244 int _bt_set_non_blocking_tty(int sk);
245
246 gboolean _bt_is_headset_class(int dev_class);
247
248 char *_bt_get_device_object_path(char *address);
249
250 void _bt_deinit_bluez_proxy(void);
251
252 #ifdef __cplusplus
253 }
254 #endif /* __cplusplus */
255 #endif /*_BT_COMMON_H_*/
256