Re-merge the codes
[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
83 #define RFKILL_NODE "/dev/rfkill"
84
85 #define BLUETOOTH_UUID_POSTFIX "0000-1000-8000-00805f9b34fb"
86
87 #define BT_COMMON_PKG "ug-setting-bluetooth-efl"
88
89 #define BT_STR_DISABLED_RESTRICTS \
90         dgettext(BT_COMMON_PKG, "IDS_BT_BODY_SECURITY_POLICY_RESTRICTS_USE_OF_BLUETOOTH_CONNECTION")
91
92 #define BT_STR_HANDS_FREE_RESTRICTS \
93         dgettext(BT_COMMON_PKG, "IDS_BT_BODY_SECURITY_POLICY_RESTRICTS_USE_OF_BLUETOOTH_CONNECTION_TO_HANDS_FREE_FEATURES_ONLY")
94
95 #define RFKILL_EVENT_SIZE 8
96
97 #define BT_PHONE_NUM_LEN 50
98 #define BT_FILE_BUFFER_MAX 256
99
100 #define SLEEP_TIME 50000 /* 50 ms */
101 #define BLOCK_MAX_TIMEOUT 2000000 /* 2 seconds */
102
103 typedef enum {
104         BT_STORE_BOOLEAN,
105         BT_STORE_INT,
106         BT_STORE_STRING,
107 } bt_store_type_t;
108
109 typedef enum {
110         BT_STORE_NAME,
111         BT_STORE_DISCOVERABLE_MODE,
112 } bt_store_key_t;
113
114
115 typedef enum {
116         RFKILL_TYPE_ALL = 0,
117         RFKILL_TYPE_WLAN,
118         RFKILL_TYPE_BLUETOOTH,
119         RFKILL_TYPE_UWB,
120         RFKILL_TYPE_WIMAX,
121         RFKILL_TYPE_WWAN,
122         RFKILL_TYPE_GPS,
123         RFKILL_TYPE_FM,
124         NUM_RFKILL_TYPES,
125 } rfkill_type;
126
127 typedef enum {
128         BT_ACCEPT,
129         BT_REJECT,
130         BT_CANCEL,
131         BT_TIMEOUT,
132 } bt_accept_type_t;
133
134 typedef struct {
135         unsigned int idx;
136         unsigned char type;
137         unsigned char op;
138         unsigned char soft;
139         unsigned char hard;
140 } rfkill_event;
141
142 typedef struct {
143         const char *match;
144         unsigned short match_uuid16;
145         const char *match_name;
146         unsigned int match_handle;
147 } match_entries_t;
148
149 typedef struct {
150         match_entries_t *search_match_ptr;
151         bluetooth_device_address_t remote_device_addr;
152         int success_search_index;
153 } bt_info_for_searching_support_service_t;
154
155 /**
156  *   @internal
157  *   This structure has information about BT
158  */
159
160 typedef struct {
161         pid_t application_pid;                  /**< Application process id */
162         bluetooth_cb_func_ptr bt_cb_ptr;        /**< Function pointer for
163                                                 responsing event to application */
164
165         DBusGConnection *conn;                  /**< DBUS bus connection for bluez ipc */
166         DBusConnection *sys_conn;
167         DBusGProxy *dbus_proxy;                 /**< DBUS proxy */
168         DBusGProxy *manager_proxy;              /**< bluez manager ipc proxy */
169         DBusGProxy *adapter_proxy;              /**< bluez adapter ipc proxy */
170         DBusGProxy *agent_proxy;                /**< Agent ipc proxy */
171         DBusGProxy *network_server_proxy;
172         DBusGProxy *rfcomm_proxy;
173         char adapter_path[BT_ADAPTER_OBJECT_PATH_MAX];  /*bluez adapter path*/
174         char *connecting_uuid;
175         GList *device_proxy_list;                       /**< bluez device ipc proxy list */
176
177         bluetooth_adapter_state_t bt_adapter_state;     /*Current bluetooth state*/
178         guint bt_change_state_timer;                    /**< g_timeout for checking timeout
179                                                         of BT status change */
180         bluetooth_device_name_t bt_local_name;          /*Local bluetooth device name*/
181
182         guint bt_discovery_req_timer;                   /**< g_timeout for checking timeout of
183                                                         BT discovery request */
184         gboolean is_discovery_req;                      /**< application request discovery or not*/
185         gboolean is_discovering;                        /**< Currently discovery state */
186         gboolean is_discovery_cancel;                   /**< discovery cancel is requested */
187
188         guint bt_bonding_req_timer;                     /**< g_timeout for checking timeout of
189                                                                  BT discovery request */
190         gboolean is_bonding_req;                        /*application request bonding or not*/
191         gboolean is_headset_bonding;
192         char bt_bonding_req_addrstr[BT_ADDRESS_STRING_SIZE]; /**< bluetooth device address which
193                                                         currently bonding is requested to */
194         gboolean is_headset_pin_req;                    /*application request bonding or not*/
195         bt_info_for_searching_support_service_t info_for_searching_support_service;  /**< Service
196                                                                 Seaching Session Infomation */
197
198         gboolean is_service_req;                        /**< Request to discover device services */
199         void *user_data;
200
201 } bt_info_t;
202
203 bt_info_t *_bluetooth_internal_get_information(void);
204 void _bluetooth_internal_event_cb(int event, int result, void *param_data);
205
206 void _bluetooth_internal_session_init(void);
207
208 bool _bluetooth_internal_is_adapter_enabled(void);
209
210 DBusGProxy *_bluetooth_internal_find_device_by_path(const char *dev_path);
211 DBusGProxy *_bluetooth_internal_add_device(const char *path);
212
213 void _bluetooth_change_uuids_to_sdp_info(GValue *value, bt_sdp_info_t *sdp_data);
214
215 void _bluetooth_internal_print_bluetooth_device_address_t(const  bluetooth_device_address_t  *addr);
216 void _bluetooth_internal_convert_addr_string_to_addr_type(bluetooth_device_address_t *addr,
217                                                         const char *address);
218 void _bluetooth_internal_addr_type_to_addr_string(char *address,
219                                                 const bluetooth_device_address_t *addr);
220 void _bluetooth_internal_divide_device_class(bluetooth_device_class_t *device_class,
221                                                                         unsigned int cod);
222 void _bluetooth_internal_device_path_to_address(const char *device_path,
223                                                char *device_address);
224
225 int _bluetooth_get_default_adapter_name(bluetooth_device_name_t *dev_name, int size);
226
227 int _bluetooth_internal_get_adapter_path(DBusGConnection *conn, char *path);
228
229 DBusGProxy *_bluetooth_internal_get_adapter_proxy(DBusGConnection *conn);
230
231 #ifdef __cplusplus
232 extern "C" {
233 #endif                          /* __cplusplus */
234
235 #ifdef __cplusplus
236 }
237 #endif                          /* __cplusplus */
238 #endif                          /*_BLUETOOTH_API_COMMON_H_*/
239