Fix the bug about the device discovery
[framework/connectivity/bluetooth-frwk.git] / lib / bluetooth-api-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 _BLUETOOTH_API_COMMON_H_
26 #define _BLUETOOTH_API_COMMON_H_
27
28 #include <stdbool.h>
29 #include <string.h>
30 #include <malloc.h>
31 #include <errno.h>
32 #include <sys/types.h>
33 #include <libintl.h>
34
35 #include <dbus/dbus-glib-lowlevel.h>
36 #include <dbus/dbus-glib.h>
37 #include <dbus/dbus.h>
38 #include <glib.h>
39
40 #include <dlog.h>
41 #include <vconf-keys.h>
42
43 #include "bluetooth-api.h"
44
45 #define BT_FRWK "BT_FRWK"
46
47 #ifndef BT_EXPORT_API
48 #define BT_EXPORT_API __attribute__((visibility("default")))
49 #endif
50
51 #define PRT(level, fmt, function, args...) \
52         SLOG(LOG_DEBUG, BT_FRWK, "%s():%d "fmt, __func__, __LINE__, ##args)
53 #define DBG(fmt, args...) \
54         SLOG(LOG_DEBUG, BT_FRWK, "%s():%d "fmt, __func__, __LINE__, ##args)
55 #define ERR(fmt, args...) \
56         SLOG(LOG_ERROR, BT_FRWK, "%s():%d "fmt, __func__, __LINE__, ##args)
57 #define AST(fmt, args...) \
58         SLOG(LOG_ERROR, BT_FRWK, "%s():%d "fmt, __func__, __LINE__, ##args)
59
60 #define BT_SETTING_DEVICE_NAME "db/setting/device_name"
61 #define BT_MEMORY_OBEX_NO_AGENT "memory/private/libbluetooth-frwk-0/obex_no_agent"
62 #define BT_MEMORY_RFCOMM_UUID "memory/private/libbluetooth-frwk-0/uuid"
63 #define BT_FILE_VISIBLE_TIME "file/private/libug-setting-bluetooth-efl/visibility_time"
64
65 #define BLUEZ_SERVICE_NAME "org.bluez"
66 #define BLUEZ_MANAGER_OBJ_PATH "/"
67 #define BLUEZ_MANAGER_INTERFACE "org.bluez.Manager"
68
69 #define BLUEZ_ADAPTER_INTERFACE "org.bluez.Adapter"
70 #define BLUEZ_DEVICE_INTERFACE "org.bluez.Device"
71
72 #define BT_AGENT_INTERFACE "User.Bluetooth.agent"
73
74 #define HCI_SCAN_ENABLE_NO_SCAN                                         0x00
75 #define HCI_SCAN_ENABLE_INQUIRY_ONLY                                    0x01
76 #define HCI_SCAN_ENABLE_PAGE_ONLY                                       0x02
77 #define HCI_SCAN_ENABLE_PAGE_AND_INQUIRY                                0x03
78
79 #define BT_ADDRESS_STRING_SIZE 18
80 #define BT_128_UUID_LEN 36
81 #define BT_ADAPTER_OBJECT_PATH_MAX 50
82 #define BT_DISCOVERY_FINISHED_DELAY 200
83
84 #define RFKILL_NODE "/dev/rfkill"
85
86 #define BLUETOOTH_UUID_POSTFIX "0000-1000-8000-00805f9b34fb"
87
88 #define BT_COMMON_PKG "ug-setting-bluetooth-efl"
89
90 #define BT_STR_DISABLED_RESTRICTS \
91         dgettext(BT_COMMON_PKG, "IDS_BT_BODY_SECURITY_POLICY_RESTRICTS_USE_OF_BLUETOOTH_CONNECTION")
92
93 #define BT_STR_HANDS_FREE_RESTRICTS \
94         dgettext(BT_COMMON_PKG, "IDS_BT_BODY_SECURITY_POLICY_RESTRICTS_USE_OF_BLUETOOTH_CONNECTION_TO_HANDS_FREE_FEATURES_ONLY")
95
96 #define RFKILL_EVENT_SIZE 8
97
98 #define BT_PHONE_NUM_LEN 50
99 #define BT_FILE_BUFFER_MAX 256
100
101 #define SLEEP_TIME 50000 /* 50 ms */
102 #define BLOCK_MAX_TIMEOUT 2000000 /* 2 seconds */
103
104 typedef enum {
105         BT_STORE_BOOLEAN,
106         BT_STORE_INT,
107         BT_STORE_STRING,
108 } bt_store_type_t;
109
110 typedef enum {
111         BT_STORE_NAME,
112         BT_STORE_DISCOVERABLE_MODE,
113 } bt_store_key_t;
114
115
116 typedef enum {
117         RFKILL_TYPE_ALL = 0,
118         RFKILL_TYPE_WLAN,
119         RFKILL_TYPE_BLUETOOTH,
120         RFKILL_TYPE_UWB,
121         RFKILL_TYPE_WIMAX,
122         RFKILL_TYPE_WWAN,
123         RFKILL_TYPE_GPS,
124         RFKILL_TYPE_FM,
125         NUM_RFKILL_TYPES,
126 } rfkill_type;
127
128 typedef enum {
129         BT_ACCEPT,
130         BT_REJECT,
131         BT_CANCEL,
132         BT_TIMEOUT,
133 } bt_accept_type_t;
134
135 typedef struct {
136         unsigned int idx;
137         unsigned char type;
138         unsigned char op;
139         unsigned char soft;
140         unsigned char hard;
141 } rfkill_event;
142
143 typedef struct {
144         const char *match;
145         unsigned short match_uuid16;
146         const char *match_name;
147         unsigned int match_handle;
148 } match_entries_t;
149
150 typedef struct {
151         match_entries_t *search_match_ptr;
152         bluetooth_device_address_t remote_device_addr;
153         int success_search_index;
154 } bt_info_for_searching_support_service_t;
155
156 /**
157  *   @internal
158  *   This structure has information about BT
159  */
160
161 typedef struct {
162         pid_t application_pid;                  /**< Application process id */
163         bluetooth_cb_func_ptr bt_cb_ptr;        /**< Function pointer for
164                                                 responsing event to application */
165
166         DBusGConnection *conn;                  /**< DBUS bus connection for bluez ipc */
167         DBusConnection *sys_conn;
168         DBusGProxy *dbus_proxy;                 /**< DBUS proxy */
169         DBusGProxy *manager_proxy;              /**< bluez manager ipc proxy */
170         DBusGProxy *adapter_proxy;              /**< bluez adapter ipc proxy */
171         DBusGProxy *agent_proxy;                /**< Agent ipc proxy */
172         DBusGProxy *network_server_proxy;
173         DBusGProxy *rfcomm_proxy;
174         char adapter_path[BT_ADAPTER_OBJECT_PATH_MAX];  /*bluez adapter path*/
175         char *connecting_uuid;
176         GList *device_proxy_list;                       /**< bluez device ipc proxy list */
177
178         bluetooth_adapter_state_t bt_adapter_state;     /*Current bluetooth state*/
179         guint bt_change_state_timer;                    /**< g_timeout for checking timeout
180                                                         of BT status change */
181         bluetooth_device_name_t bt_local_name;          /*Local bluetooth device name*/
182
183         guint bt_discovery_req_timer;                   /**< g_timeout for checking timeout of
184                                                         BT discovery request */
185         gboolean is_discovery_req;                      /**< application request discovery or not*/
186         gboolean is_discovering;                        /**< Currently discovery state */
187         gboolean is_discovery_cancel;                   /**< discovery cancel is requested */
188
189         guint bt_bonding_req_timer;                     /**< g_timeout for checking timeout of
190                                                                  BT discovery request */
191         gboolean is_bonding_req;                        /*application request bonding or not*/
192         gboolean is_headset_bonding;
193         char bt_bonding_req_addrstr[BT_ADDRESS_STRING_SIZE]; /**< bluetooth device address which
194                                                         currently bonding is requested to */
195         gboolean is_headset_pin_req;                    /*application request bonding or not*/
196         bt_info_for_searching_support_service_t info_for_searching_support_service;  /**< Service
197                                                                 Seaching Session Infomation */
198
199         gboolean is_service_req;                        /**< Request to discover device services */
200         void *user_data;
201
202 } bt_info_t;
203
204 bt_info_t *_bluetooth_internal_get_information(void);
205 void _bluetooth_internal_event_cb(int event, int result, void *param_data);
206
207 void _bluetooth_internal_session_init(void);
208
209 bool _bluetooth_internal_is_adapter_enabled(void);
210
211 DBusGProxy *_bluetooth_internal_find_device_by_path(const char *dev_path);
212 DBusGProxy *_bluetooth_internal_add_device(const char *path);
213
214 void _bluetooth_change_uuids_to_sdp_info(GValue *value, bt_sdp_info_t *sdp_data);
215
216 void _bluetooth_internal_print_bluetooth_device_address_t(const  bluetooth_device_address_t  *addr);
217 void _bluetooth_internal_convert_addr_string_to_addr_type(bluetooth_device_address_t *addr,
218                                                         const char *address);
219 void _bluetooth_internal_addr_type_to_addr_string(char *address,
220                                                 const bluetooth_device_address_t *addr);
221 void _bluetooth_internal_divide_device_class(bluetooth_device_class_t *device_class,
222                                                                         unsigned int cod);
223 void _bluetooth_internal_device_path_to_address(const char *device_path,
224                                                char *device_address);
225
226 int _bluetooth_get_default_adapter_name(bluetooth_device_name_t *dev_name, int size);
227
228 int _bluetooth_internal_get_adapter_path(DBusGConnection *conn, char *path);
229
230 DBusGProxy *_bluetooth_internal_get_adapter_proxy(DBusGConnection *conn);
231
232 #ifdef __cplusplus
233 extern "C" {
234 #endif                          /* __cplusplus */
235
236 #ifdef __cplusplus
237 }
238 #endif                          /* __cplusplus */
239 #endif                          /*_BLUETOOTH_API_COMMON_H_*/
240