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