[Adapt:Frwk] Implement get bonded device info APIs
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / 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 #include <oal-manager.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #undef LOG_TAG
35 #define LOG_TAG "BLUETOOTH_FRWK_SERVICE"
36
37 #ifdef FUNCTION_TRACE
38 #define FN_START BT_DBG("[ENTER FUNC]")
39 #define FN_END BT_DBG("[EXIT FUNC]")
40 #else
41 #define FN_START
42 #define FN_END
43 #endif
44
45 #define LOG_COLOR_RESET    "\033[0m"
46 #define LOG_COLOR_RED      "\033[31m"
47 #define LOG_COLOR_YELLOW   "\033[33m"
48 #define LOG_COLOR_GREEN         "\033[32m"
49 #define LOG_COLOR_BLUE          "\033[36m"
50 #define LOG_COLOR_PURPLE   "\033[35m"
51
52 #define BT_DBG(fmt, args...) \
53         SLOGD(fmt, ##args)
54 #define BT_INFO(fmt, args...) \
55         SLOGI(fmt, ##args)
56 #define BT_ERR(fmt, args...) \
57         SLOGE(fmt, ##args)
58
59 #define BT_INFO_C(fmt, arg...) \
60         SLOGI_IF(TRUE,  LOG_COLOR_GREEN" "fmt" "LOG_COLOR_RESET, ##arg)
61 #define BT_ERR_C(fmt, arg...) \
62         SLOGI_IF(TRUE,  LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg)
63
64 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
65 #define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
66
67 #define ret_if(expr) \
68         do { \
69                 if (expr) { \
70                         BT_ERR("(%s) return", #expr); \
71                         return; \
72                 } \
73         } while (0)
74
75 #define retv_if(expr, val) \
76         do { \
77                 if (expr) { \
78                         BT_ERR("(%s) return", #expr); \
79                         return (val); \
80                 } \
81         } while (0)
82
83 #define BT_CHECK_PARAMETER(arg, func) \
84         do { \
85                 if (arg == NULL) { \
86                         BT_ERR("%s is NULL", #arg); \
87                         func BLUETOOTH_ERROR_INVALID_PARAM; \
88                 } \
89         } while (0)
90
91
92 #define BT_ADDRESS_LENGTH_MAX 6
93 #define BT_ADDRESS_STRING_SIZE 18
94 #define BT_RFCOMM_BUFFER_MAX 1024
95 #define BT_LOWER_ADDRESS_LENGTH 9
96
97 #define BT_AGENT_AUTO_PAIR_BLACKLIST_FILE (APP_SYSCONFDIR"/auto-pair-blacklist")
98 #define BT_AGENT_NEW_LINE "\r\n"
99
100 #define BT_MAX_DBUS_TIMEOUT 45000
101 #ifndef TIZEN_TV
102 #define BT_ENABLE_TIMEOUT 20000 /* 20 seconds */
103 #else
104 #define BT_ENABLE_TIMEOUT 5000 /* 5 seconds */
105 #endif
106 #define BT_DISCOVERY_FINISHED_DELAY 200
107
108 #define MANAGER_EVENT_MATCH_RULE \
109                         "type='signal'," \
110                         "interface='%s'," \
111                         "member='%s'"
112
113 #define EVENT_MATCH_RULE \
114                         "type='signal'," \
115                         "interface='%s',"
116
117 #define BT_TEMINATING_WAIT_TIME 200
118
119 #define BT_TIMEOUT_MESSAGE "Did not receive a reply. Possible causes include: " \
120                         "the remote application did not send a reply, " \
121                         "the message bus security policy blocked the reply, " \
122                         "the reply timeout expired, or the network connection " \
123                         "was broken."
124
125 #define BT_BLUEZ_NAME "org.bluez"
126
127 #define BT_BLUEZ_PATH "/org/bluez"
128 #define BT_BLUEZ_HCI_PATH "/org/bluez/hci0"
129 #define BT_AGENT_NAME "org.bluez.frwk_agent"
130 #define BT_AGENT_PATH "/org/bluez/agent/frwk_agent"
131 #define BT_DEVICE_AGENT_PATH "/org/tizen/device_agent"
132 #define BT_ADAPTER_AGENT_PATH "/org/tizen/adapter_agent"
133 #define BT_MANAGER_PATH "/"
134
135
136 #define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
137 #define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
138 #define BT_AGENT_INTERFACE "org.bluez.Agent1"
139 #define BT_AGENT_MANAGER_INTERFACE "org.bluez.AgentManager1"
140 #define BT_DEVICE_INTERFACE "org.bluez.Device1"
141 #define BT_NETWORK_SERVER_INTERFACE "org.bluez.NetworkServer1"
142 #define BT_MEDIA_INTERFACE "org.bluez.Media1"
143 #define BT_MEDIA_PLAYER_INTERFACE "org.mpris.MediaPlayer2.Player"
144 #define BT_MEDIATRANSPORT_INTERFACE "org.bluez.MediaTransport1"
145 #define BT_MEDIA_CONTROL_INTERFACE "org.bluez.MediaControl1"
146 #define BT_PLAYER_CONTROL_INTERFACE "org.bluez.MediaPlayer1"
147 #define BT_GATT_CHAR_INTERFACE "org.bluez.GattCharacteristic1"
148
149 #define BT_INPUT_INTERFACE "org.bluez.Input1"
150 #define BT_NETWORK_INTERFACE "org.bluez.Network"
151 #define BT_NETWORK_CLIENT_INTERFACE "org.bluez.Network1"
152 #define BT_SERIAL_INTERFACE "org.bluez.Serial"
153 #define BT_SERIAL_MANAGER_INTERFACE "org.bluez.SerialProxyManager"
154 #define BT_SERIAL_PROXY_INTERFACE "org.bluez.SerialProxy"
155 #define BT_SINK_INTERFACE "org.bluez.AudioSink"
156 #define BT_AUDIO_INTERFACE "org.bluez.Audio"
157 #define BT_HEADSET_INTERFACE "org.bluez.Headset"
158 #define BT_OOB_INTERFACE "org.bluez.OutOfBand"
159 #define BT_HANDSFREE_GATEWAY_INTERFACE "org.bluez.HandsfreeGateway"
160 #define BT_OBEXD_INTERFACE "org.openobex"
161 #define BT_OBEXD_MANAGER_INTERFACE "org.openobex.Manager"
162 #define BT_OBEXD_TRANSFER_INTERFACE "org.openobex.Transfer"
163 #define BT_A2DP_SOURCE_INTERFACE "org.bluez.AudioSource"
164
165 #define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
166
167
168 #define BT_OBEX_SERVICE_NAME "org.bluez.obex"
169 #define BT_OBEX_CLIENT_PATH "/org/bluez/obex"
170 #define BT_OBEX_CLIENT_INTERFACE "org.bluez.obex.Client1"
171
172
173
174 #define BT_OBEX_TRANSFER_INTERFACE "org.bluez.obex.Transfer1"
175 #define BT_OBEX_AGENT_INTERFACE "org.bluez.obex.Agent1"
176
177
178
179 #define BT_OBEXD_DBUS_NAME "org.bluez.obex"
180 #define BT_OBEX_OBJECT_PUSH_INTERFACE "org.bluez.obex.ObjectPush1"
181
182
183 #define BT_FREEDESKTOP_INTERFACE "org.freedesktop.DBus"
184 #define BT_FREEDESKTOP_PATH "/org/freedesktop/DBus"
185
186
187 #define BT_INTERFACES_ADDED "InterfacesAdded"
188 #define BT_INTERFACES_REMOVED "InterfacesRemoved"
189 #define BT_NAME_OWNER_CHANGED "NameOwnerChanged"
190 #define BT_PROPERTIES_CHANGED "PropertiesChanged"
191
192
193
194 #define BT_SESSION_BASEPATH_SERVER "/org/bluez/obex/server"
195 #define BT_SESSION_BASEPATH_CLIENT "/org/bluez/obex/client"
196
197 #define BT_SERVICE_ERR_MSG_NOT_SUPPORTED "Operation is not supported"
198
199 /* UUID */
200 #define GENERIC_AUDIO_UUID      "00001203-0000-1000-8000-00805f9b34fb"
201
202 #define OBEX_OPP_UUID           "00001105-0000-1000-8000-00805f9b34fb"
203
204 #define HSP_HS_UUID             "00001108-0000-1000-8000-00805f9b34fb"
205 #define HSP_AG_UUID             "00001112-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 ADVANCED_AUDIO_UUID     "0000110d-0000-1000-8000-00805f9b34fb"
211
212 #define A2DP_SOURCE_UUID        "0000110a-0000-1000-8000-00805f9b34fb"
213 #define A2DP_SINK_UUID          "0000110b-0000-1000-8000-00805f9b34fb"
214
215 #define AVRCP_REMOTE_UUID       "0000110e-0000-1000-8000-00805f9b34fb"
216 #define AVRCP_TARGET_UUID       "0000110c-0000-1000-8000-00805f9b34fb"
217
218 #define HID_UUID                "00001124-0000-1000-8000-00805f9b34fb"
219 #define PNP_UUID                "00001200-0000-1000-8000-00805f9b34fb"
220 #define RFCOMM_UUID_STR         "00000003-0000-1000-8000-00805f9b34fb"
221 #define PANU_UUID               "00001115-0000-1000-8000-00805f9b34fb"
222 #define NAP_UUID                "00001116-0000-1000-8000-00805f9b34fb"
223 #define OBEX_PSE_UUID           "0000112f-0000-1000-8000-00805f9b34fb"
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_ALL = 0xffffffff,
268 } bt_profile_type_t;
269
270 typedef struct {
271         char *address;
272         int addr_type;
273         int rssi;
274         int adv_type;
275         bt_le_device_info_type_t dev_type;
276         int adv_data_len;
277         char *adv_data;
278 } bt_remote_le_dev_info_t;
279
280 typedef struct {
281         int rssi;
282         int class;
283         char *address;
284         char *name;
285         char **uuids;
286         unsigned int uuid_count;
287         gboolean paired;
288         bluetooth_connected_link_t connected;
289         gboolean trust;
290         char *manufacturer_data;
291         int manufacturer_data_len;
292         guchar addr_type;
293 #if 0 /* Should match with bt_dev_info_t in bluetooth-api.h */
294         bt_remote_le_dev_info_t le_dev_info;
295 #endif
296 } bt_remote_dev_info_t;
297
298 /* RFCOMM client /server will use this structure*/
299 typedef struct {
300         int fd;
301         GIOChannel *io_channel;
302         guint io_event;
303         char *dev_node;
304         char *address;
305         char *uuid;
306 } bt_rfcomm_info_t;
307
308 typedef struct {
309         int req_id;
310         char *address;
311 } bt_function_data_t;
312
313 typedef struct {
314         int count;
315         bluetooth_device_address_t *addr_list;
316         GArray *out_param;
317 } bonded_devices_req_info_t;
318
319 GDBusConnection *_bt_get_system_conn(void);
320
321 GDBusConnection *_bt_get_system_gconn(void);
322
323 GDBusConnection *_bt_get_session_gconn(void);
324
325 void *_bt_get_net_conn(void);
326
327 GDBusProxy *_bt_get_manager_proxy(void);
328
329 GDBusProxy *_bt_get_adapter_proxy(void);
330
331 GDBusProxy *_bt_get_adapter_properties_proxy(void);
332
333 char *_bt_get_device_object_path(char *address);
334
335 char *_bt_get_profile_uuid128(bt_profile_type_t profile_type);
336
337 char *_bt_convert_error_to_string(int error);
338
339 char * _bt_convert_disc_reason_to_string(int reason);
340
341 void _bt_logging_connection(gboolean connect, int addr_type);
342
343 char *_bt_get_adapter_path(void);
344
345 void _bt_deinit_proxys(void);
346
347 void _bt_convert_device_path_to_address(const char *device_path,
348                                                 char *device_address);
349
350 void _bt_convert_addr_string_to_type(unsigned char *addr,
351                                         const char *address);
352
353 void _bt_convert_addr_type_to_string(char *address,
354                                 unsigned char *addr);
355
356 void _bt_swap_byte_ordering(char *data, int data_len);
357
358 int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len);
359
360 int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
361                                 const char *mask, int data_len);
362
363 void _bt_print_device_address_t(const bluetooth_device_address_t *addr);
364
365 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
366                                 unsigned int cod);
367
368 void _bt_free_device_info(bt_remote_dev_info_t *dev_info);
369
370 void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info);
371
372 int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length);
373
374 gboolean _bt_utf8_validate(char *name);
375
376 int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd);
377
378 int _bt_unregister_osp_server_in_agent(int type, char *uuid);
379
380 int _bt_set_socket_non_blocking(int socket_fd);
381
382 int _bt_set_non_blocking_tty(int sk);
383
384 void _bt_deinit_bluez_proxy(void);
385
386 int _bt_eventsystem_set_value(const char *event, const char *key, const char *value);
387
388 void _bt_copy_remote_dev(bt_remote_dev_info_t * dev_info, remote_device_t * oal_device);
389
390 void _bt_uuid_to_string(service_uuid_t *p_uuid, char *str);
391
392 void _bt_truncate_non_utf8_chars(char * str);
393
394 void _bt_copy_remote_device(bt_remote_dev_info_t *rem_dev, bluetooth_device_info_t *dev);
395
396 void _bt_service_print_dev_info(bluetooth_device_info_t *dev_info);
397
398 #ifdef __cplusplus
399 }
400 #endif /* __cplusplus */
401 #endif /*_BT_COMMON_H_*/
402