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