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