[Tizen 3.0 Product] Enable debug logs
[platform/core/api/tethering.git] / include / tethering_private.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 #ifndef __TETHERING_PRIVATE_H__
18 #define __TETHERING_PRIVATE_H__
19
20 #define LOG_TAG "CAPI_NETWORK_TETHERING"
21
22 #include <glib.h>
23 #include <dlog.h>
24 #include <gio/gio.h>
25 #include "tethering.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #ifndef API
32 #define API __attribute__ ((visibility("default")))
33 #endif
34
35 #ifndef DEPRECATED_API
36 #define DEPRECATED_API __attribute__ ((deprecated))
37 #endif
38
39 #define INFO(fmt, args...)      LOGI(fmt, ##args)
40 #define DBG(fmt, args...)       LOGD(fmt, ##args)
41 #define WARN(fmt, args...)      LOGW(fmt, ##args)
42 #define ERR(fmt, args...)       LOGE(fmt, ##args)
43 #define SDBG(fmt, args...)      SECURE_LOGD(fmt, ##args)
44 #define SERR(fmt, args...)      SECURE_LOGE(fmt, ##args)
45
46 #define _warn_if(expr, fmt, arg...) do { \
47                 if (expr) { \
48                         WARN(fmt, ##arg); \
49                 } \
50         } while (0)
51
52 #define _ret_if(expr) do { \
53                 if (expr) { \
54                         return; \
55                 } \
56         } while (0)
57
58 #define _retv_if(expr, val) do { \
59                 if (expr) { \
60                         return (val); \
61                 } \
62         } while (0)
63
64 #define _retm_if(expr, fmt, arg...) do { \
65                 if (expr) { \
66                         ERR(fmt, ##arg); \
67                         return; \
68                 } \
69         } while (0)
70
71 #define _retvm_if(expr, val, fmt, arg...) do { \
72                 if (expr) { \
73                         ERR(fmt, ##arg); \
74                         return (val); \
75                 } \
76         } while (0)
77
78 /**
79  * To check supported feature
80  */
81
82 #define TETHERING_FEATURE               "http://tizen.org/feature/network.tethering"
83 #define TETHERING_BT_FEATURE            "http://tizen.org/feature/network.tethering.bluetooth"
84 #define TETHERING_USB_FEATURE           "http://tizen.org/feature/network.tethering.usb"
85 #define TETHERING_WIFI_FEATURE          "http://tizen.org/feature/network.tethering.wifi"
86
87 typedef enum
88 {
89         TETHERING_SUPPORTED_FEATURE,
90         TETHERING_SUPPORTED_FEATURE_WIFI,
91         TETHERING_SUPPORTED_FEATURE_BT,
92         TETHERING_SUPPORTED_FEATURE_USB,
93         TETHERING_SUPPORTED_FEATURE_MAX,
94 } tethering_supported_feature_e;
95
96 #define CHECK_FEATURE_SUPPORTED(...) \
97         do { \
98                 int rv = _tethering_check_feature_supported(__VA_ARGS__, NULL); \
99                 if(rv != TETHERING_ERROR_NONE) { \
100                         return rv; \
101                 } \
102         } while (0)
103
104 int _tethering_check_feature_supported(const char* feature, ...);
105
106 /**
107 * Start of mobileap-agent common values
108 * When these values are changed, mobileap-agent should be also changed.
109 * But some of those will be removed.
110 */
111
112 /*
113 * from mobileap_lib.h
114 */
115
116 /**
117 * Common configuration
118 */
119 #define TETHERING_TYPE_MAX              5       /**< All, USB, Wi-Fi, BT, Wi-Fi AP */
120 #define TETHERING_STR_INFO_LEN          20      /**< length of the ip or mac address */
121
122 /**
123 * Mobile AP error code
124 */
125 typedef enum {
126         MOBILE_AP_ERROR_NONE,                   /**< No error */
127         MOBILE_AP_ERROR_RESOURCE,               /**< Socket creation error, file open error */
128         MOBILE_AP_ERROR_INTERNAL,               /**< Driver related error */
129         MOBILE_AP_ERROR_INVALID_PARAM,          /**< Invalid parameter */
130         MOBILE_AP_ERROR_ALREADY_ENABLED,        /**< Mobile AP is already ON */
131         MOBILE_AP_ERROR_NOT_ENABLED,            /**< Mobile AP is not ON, so cannot be disabled */
132         MOBILE_AP_ERROR_NET_OPEN,               /**< PDP network open error */
133         MOBILE_AP_ERROR_NET_CLOSE,              /**< PDP network close error */
134         MOBILE_AP_ERROR_DHCP,                   /**< DHCP error */
135         MOBILE_AP_ERROR_IN_PROGRESS,            /**< Request is in progress */
136         MOBILE_AP_ERROR_NOT_PERMITTED,          /**< Operation is not permitted */
137         MOBILE_AP_ERROR_PERMISSION_DENIED,  /**< Permission Denied */
138
139         MOBILE_AP_ERROR_MAX
140 } mobile_ap_error_code_e;
141
142 /**
143 * Event type on callback
144 */
145 typedef enum {
146         MOBILE_AP_ENABLE_CFM,
147         MOBILE_AP_DISABLE_CFM,
148
149         MOBILE_AP_ENABLE_WIFI_TETHERING_CFM,
150         MOBILE_AP_DISABLE_WIFI_TETHERING_CFM,
151         MOBILE_AP_CHANGE_WIFI_CONFIG_CFM,
152
153         MOBILE_AP_ENABLE_USB_TETHERING_CFM,
154         MOBILE_AP_DISABLE_USB_TETHERING_CFM,
155
156         MOBILE_AP_ENABLE_BT_TETHERING_CFM,
157         MOBILE_AP_DISABLE_BT_TETHERING_CFM,
158
159         MOBILE_AP_GET_STATION_INFO_CFM,
160         MOBILE_AP_GET_DATA_PACKET_USAGE_CFM
161 } mobile_ap_event_e;
162
163 typedef enum {
164         MOBILE_AP_TYPE_WIFI,
165         MOBILE_AP_TYPE_USB,
166         MOBILE_AP_TYPE_BT,
167         MOBILE_AP_TYPE_MAX,
168 } mobile_ap_type_e;
169
170 typedef enum {
171         E_SIGNAL_NET_CLOSED = 0,
172         E_SIGNAL_WIFI_TETHER_ON,
173         E_SIGNAL_WIFI_TETHER_OFF,
174         E_SIGNAL_USB_TETHER_ON,
175         E_SIGNAL_USB_TETHER_OFF,
176         E_SIGNAL_BT_TETHER_ON,
177         E_SIGNAL_BT_TETHER_OFF,
178         E_SIGNAL_NO_DATA_TIMEOUT,
179         E_SIGNAL_LOW_BATTERY_MODE,
180         E_SIGNAL_FLIGHT_MODE,
181         E_SIGNAL_POWER_SAVE_MODE,
182         E_SIGNAL_SECURITY_TYPE_CHANGED,
183         E_SIGNAL_SSID_VISIBILITY_CHANGED,
184         E_SIGNAL_PASSPHRASE_CHANGED,
185         E_SIGNAL_DHCP_STATUS,
186         E_SIGNAL_MAX
187 } mobile_ap_sig_e;
188
189 #define TETHERING_SERVICE_OBJECT_PATH   "/MobileapAgent"
190 #define TETHERING_SERVICE_NAME          "org.tizen.MobileapAgent"
191 #define TETHERING_SERVICE_INTERFACE     "org.tizen.tethering"
192
193 #define TETHERING_SIGNAL_MATCH_RULE     "type='signal',interface='org.tizen.tethering'"
194 #define TETHERING_SIGNAL_NAME_LEN       64
195
196 #define SIGNAL_NAME_NET_CLOSED          "net_closed"
197 #define SIGNAL_NAME_STA_CONNECT         "sta_connected"
198 #define SIGNAL_NAME_STA_DISCONNECT      "sta_disconnected"
199 #define SIGNAL_NAME_WIFI_TETHER_ON      "wifi_on"
200 #define SIGNAL_NAME_WIFI_TETHER_OFF     "wifi_off"
201 #define SIGNAL_NAME_USB_TETHER_ON       "usb_on"
202 #define SIGNAL_NAME_USB_TETHER_OFF      "usb_off"
203 #define SIGNAL_NAME_BT_TETHER_ON        "bluetooth_on"
204 #define SIGNAL_NAME_BT_TETHER_OFF       "bluetooth_off"
205 #define SIGNAL_NAME_NO_DATA_TIMEOUT     "no_data_timeout"
206 #define SIGNAL_NAME_LOW_BATTERY_MODE    "low_batt_mode"
207 #define SIGNAL_NAME_FLIGHT_MODE         "flight_mode"
208 #define SIGNAL_NAME_SECURITY_TYPE_CHANGED       "security_type_changed"
209 #define SIGNAL_NAME_SSID_VISIBILITY_CHANGED     "ssid_visibility_changed"
210 #define SIGNAL_NAME_PASSPHRASE_CHANGED          "passphrase_changed"
211 #define SIGNAL_NAME_DHCP_STATUS         "dhcp_status"
212
213 #define SIGNAL_MSG_NOT_AVAIL_INTERFACE  "Interface is not available"
214 #define SIGNAL_MSG_TIMEOUT              "There is no connection for a while"
215 #define SIGNAL_MSG_SSID_VISIBLE         "ssid_visible"
216 #define SIGNAL_MSG_SSID_HIDE            "ssid_hide"
217
218 /* Network Interface */
219 #define TETHERING_SUBNET_MASK           "255.255.255.0"
220
221 #define TETHERING_USB_IF                "usb0"
222 #define TETHERING_USB_GATEWAY           "192.168.129.1"
223
224 #define TETHERING_WIFI_IF               "wlan0"
225 #define TETHERING_WIFI_GATEWAY          "192.168.43.1"
226
227 #define TETHERING_BT_IF                 "bnep0"
228 #define TETHERING_BT_GATEWAY            "192.168.130.1"
229
230 #define TETHERING_WIFI_SSID_MAX_LEN     32      /**< Maximum length of ssid */
231 #define TETHERING_WIFI_KEY_MIN_LEN      8       /**< Minimum length of wifi key */
232 #define TETHERING_WIFI_KEY_MAX_LEN      64      /**< Maximum length of wifi key */
233 #define TETHERING_WIFI_HASH_KEY_MAX_LEN 64
234 #define TETHERING_WIFI_MAX_STA 10               /**< Maximum Wi-Fi tethering station */
235
236 #define TETHERING_WIFI_MODE_MAX_LEN 10  /**< Maximum length of mode */
237
238 #define VCONFKEY_MOBILE_HOTSPOT_SSID    "memory/private/mobileap-agent/ssid"
239 #define TETHERING_PASSPHRASE_PATH       "wifi_tethering.txt"
240 #define TETHERING_WIFI_PASSPHRASE_STORE_KEY "tethering_wifi_passphrase"
241 #define MAX_ALIAS_LEN   256
242
243 /**
244 * End of mobileap-agent common values
245 */
246
247 #define TETHERING_DEFAULT_SSID  "Tizen"
248 #define TETHERING_WIFI_SECURITY_TYPE_OPEN_STR           "open"
249 #define TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR       "wpa2-psk"
250 #define TETHERING_WIFI_SECURITY_TYPE_WPS_STR    "wps"
251 #define TETHERING_ERROR_RECOVERY_MAX                    3
252 #define SECURITY_TYPE_LEN       32
253 #define PSK_ITERATION_COUNT     4096
254
255 typedef void (*__handle_cb_t)(GDBusConnection *connection, const gchar *sender_name,
256                 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
257                 GVariant *parameters, gpointer user_data);
258
259 typedef struct {
260         int sig_id;
261         char name[TETHERING_SIGNAL_NAME_LEN];
262         __handle_cb_t cb;
263 } __tethering_sig_t;
264
265 typedef struct {
266         GDBusConnection *client_bus;
267         GDBusProxy *client_bus_proxy;
268         GCancellable *cancellable;
269
270         tethering_enabled_cb enabled_cb[TETHERING_TYPE_MAX];
271         void *enabled_user_data[TETHERING_TYPE_MAX];
272         tethering_disabled_cb disabled_cb[TETHERING_TYPE_MAX];
273         void *disabled_user_data[TETHERING_TYPE_MAX];
274         tethering_connection_state_changed_cb changed_cb[TETHERING_TYPE_MAX];
275         void *changed_user_data[TETHERING_TYPE_MAX];
276         tethering_data_usage_cb data_usage_cb;
277         void *data_usage_user_data;
278         tethering_wifi_security_type_changed_cb security_type_changed_cb;
279         void *security_type_user_data;
280         tethering_wifi_ssid_visibility_changed_cb ssid_visibility_changed_cb;
281         void *ssid_visibility_user_data;
282         tethering_wifi_passphrase_changed_cb passphrase_changed_cb;
283         void *passphrase_user_data;
284         tethering_wifi_settings_reloaded_cb settings_reloaded_cb;
285         void *settings_reloaded_user_data;
286         char *ssid;
287         char passphrase[TETHERING_WIFI_KEY_MAX_LEN + 1];
288         tethering_wifi_security_type_e sec_type;
289         tethering_wifi_mode_type_e mode_type;
290         bool visibility;
291         bool mac_filter;
292         bool port_forwarding;
293         bool port_filtering;
294         bool dhcp_enabled;
295         bool change_mac;
296         int channel;
297         int wifi_max_connected;
298 } __tethering_h;
299
300 typedef struct {
301         tethering_type_e interface;                     /**< interface type */
302         char ip[TETHERING_STR_INFO_LEN];                /**< assigned IP address */
303         char mac[TETHERING_STR_INFO_LEN];               /**< MAC Address */
304         char *hostname;
305         time_t tm;      /**< connection time */
306 } __tethering_client_h;
307
308 typedef struct {
309         tethering_type_e interface;                     /**< interface type */
310         char interface_name[TETHERING_STR_INFO_LEN];    /**< interface alphanumeric name */
311         char ip_address[TETHERING_STR_INFO_LEN];        /**< assigned ip addresss to interface */
312         char gateway_address[TETHERING_STR_INFO_LEN];   /**< gateway address of interface */
313         char subnet_mask[TETHERING_STR_INFO_LEN];       /**< subnet mask of interface */
314 } __tethering_interface_t;
315
316 typedef struct {
317         char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1];
318         char key[TETHERING_WIFI_KEY_MAX_LEN + 1];
319         char mode[TETHERING_WIFI_MODE_MAX_LEN + 1];
320         tethering_wifi_security_type_e sec_type;
321         bool visibility;
322         bool mac_filter;
323         int max_connected;
324         int channel;
325 } _softap_settings_t;
326
327 #ifdef __cplusplus
328 }
329 #endif
330
331 #endif /* __TETHERING_PRIVATE_H__ */