d614da148864dadc6794e85e1268cda369c526c0
[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 <dbus/dbus-glib.h>
24 #include <dlog.h>
25
26 #include "tethering.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #ifndef API
33 #define API __attribute__ ((visibility("default")))
34 #endif
35
36 #ifndef DEPRECATED_API
37 #  define DEPRECATED_API __attribute__ ((deprecated))
38 #endif
39
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
44 #define _warn_if(expr, fmt, arg...) do { \
45                 if (expr) { \
46                         WARN(fmt, ##arg); \
47                 } \
48         } while (0)
49
50 #define _ret_if(expr) do { \
51                 if (expr) { \
52                         return; \
53                 } \
54         } while (0)
55
56 #define _retv_if(expr, val) do { \
57                 if (expr) { \
58                         return (val); \
59                 } \
60         } while (0)
61
62 #define _retm_if(expr, fmt, arg...) do { \
63                 if (expr) { \
64                         ERR(fmt, ##arg); \
65                         return; \
66                 } \
67         } while (0)
68
69 #define _retvm_if(expr, val, fmt, arg...) do { \
70                 if (expr) { \
71                         ERR(fmt, ##arg); \
72                         return (val); \
73                 } \
74         } while (0)
75
76 /**
77 * Start of mobileap-agent common values
78 * When these values are changed, mobileap-agent should be also changed.
79 * But some of those will be removed.
80 */
81
82 /*
83 * from mobileap_lib.h
84 */
85
86 /**
87 * Common configuration
88 */
89 #define TETHERING_TYPE_MAX              4       /**< All, USB, Wi-Fi, BT */
90 #define TETHERING_STR_INFO_LEN          20      /**< length of the ip or mac address */
91 #define TETHERING_STR_HOSTNAME_LEN      32      /**< length of the hostname */
92
93 /**
94 * Mobile AP error code
95 */
96 typedef enum {
97         MOBILE_AP_ERROR_NONE,                   /**< No error */
98         MOBILE_AP_ERROR_RESOURCE,               /**< Socket creation error, file open error */
99         MOBILE_AP_ERROR_INTERNAL,               /**< Driver related error */
100         MOBILE_AP_ERROR_INVALID_PARAM,          /**< Invalid parameter */
101         MOBILE_AP_ERROR_ALREADY_ENABLED,        /**< Mobile AP is already ON */
102         MOBILE_AP_ERROR_NOT_ENABLED,            /**< Mobile AP is not ON, so cannot be disabled */
103         MOBILE_AP_ERROR_NET_OPEN,               /**< PDP network open error */
104         MOBILE_AP_ERROR_NET_CLOSE,              /**< PDP network close error */
105         MOBILE_AP_ERROR_DHCP,                   /**< DHCP error */
106         MOBILE_AP_ERROR_IN_PROGRESS,            /**< Request is in progress */
107         MOBILE_AP_ERROR_NOT_PERMITTED,          /**< Operation is not permitted */
108         MOBILE_AP_ERROR_PERMISSION_DENIED,  /**< Permission Denied */
109
110         MOBILE_AP_ERROR_MAX
111 } mobile_ap_error_code_e;
112
113 /**
114 * Event type on callback
115 */
116 typedef enum {
117         MOBILE_AP_ENABLE_CFM,
118         MOBILE_AP_DISABLE_CFM,
119
120         MOBILE_AP_ENABLE_WIFI_TETHERING_CFM,
121         MOBILE_AP_DISABLE_WIFI_TETHERING_CFM,
122         MOBILE_AP_CHANGE_WIFI_CONFIG_CFM,
123
124         MOBILE_AP_ENABLE_USB_TETHERING_CFM,
125         MOBILE_AP_DISABLE_USB_TETHERING_CFM,
126
127         MOBILE_AP_ENABLE_BT_TETHERING_CFM,
128         MOBILE_AP_DISABLE_BT_TETHERING_CFM,
129
130         MOBILE_AP_GET_STATION_INFO_CFM,
131         MOBILE_AP_GET_DATA_PACKET_USAGE_CFM
132 } mobile_ap_event_e;
133
134 typedef enum {
135         MOBILE_AP_TYPE_WIFI,
136         MOBILE_AP_TYPE_USB,
137         MOBILE_AP_TYPE_BT,
138         MOBILE_AP_TYPE_WIFI_AP,
139         MOBILE_AP_TYPE_MAX,
140 } mobile_ap_type_e;
141
142
143 /*
144 * from mobileap_internal.h
145 */
146 #define DBUS_STRUCT_UINT_STRING (dbus_g_type_get_struct ("GValueArray", \
147                         G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID))
148
149 #define DBUS_STRUCT_STATIONS (dbus_g_type_get_struct ("GValueArray", \
150                         G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, \
151                         G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID))
152
153 #define DBUS_STRUCT_STATION (dbus_g_type_get_struct ("GValueArray", \
154                         G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \
155                         G_TYPE_INVALID))
156
157 #define DBUS_STRUCT_INTERFACE (dbus_g_type_get_struct ("GValueArray", \
158                         G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \
159                         G_TYPE_STRING, G_TYPE_INVALID))
160
161 #define TETHERING_SERVICE_OBJECT_PATH   "/Tethering"
162 #define TETHERING_SERVICE_NAME          "org.tizen.tethering"
163 #define TETHERING_SERVICE_INTERFACE     "org.tizen.tethering"
164
165 #define TETHERING_SIGNAL_NAME_LEN       64
166
167 #define SIGNAL_NAME_NET_CLOSED          "net_closed"
168 #define SIGNAL_NAME_STA_CONNECT         "sta_connected"
169 #define SIGNAL_NAME_STA_DISCONNECT      "sta_disconnected"
170 #define SIGNAL_NAME_WIFI_TETHER_ON      "wifi_on"
171 #define SIGNAL_NAME_WIFI_TETHER_OFF     "wifi_off"
172 #define SIGNAL_NAME_USB_TETHER_ON       "usb_on"
173 #define SIGNAL_NAME_USB_TETHER_OFF      "usb_off"
174 #define SIGNAL_NAME_BT_TETHER_ON        "bluetooth_on"
175 #define SIGNAL_NAME_BT_TETHER_OFF       "bluetooth_off"
176 #define SIGNAL_NAME_NO_DATA_TIMEOUT     "no_data_timeout"
177 #define SIGNAL_NAME_LOW_BATTERY_MODE    "low_batt_mode"
178 #define SIGNAL_NAME_FLIGHT_MODE         "flight_mode"
179 #define SIGNAL_NAME_DHCP_STATUS         "dhcp_status"
180 #define SIGNAL_NAME_SECURITY_TYPE_CHANGED       "security_type_changed"
181 #define SIGNAL_NAME_SSID_VISIBILITY_CHANGED     "ssid_visibility_changed"
182 #define SIGNAL_NAME_PASSPHRASE_CHANGED          "passphrase_changed"
183
184 #define SIGNAL_MSG_NOT_AVAIL_INTERFACE  "Interface is not available"
185 #define SIGNAL_MSG_TIMEOUT              "There is no connection for a while"
186 #define SIGNAL_MSG_SSID_VISIBLE         "ssid_visible"
187 #define SIGNAL_MSG_SSID_HIDE            "ssid_hide"
188
189 /* Network Interface */
190 #define TETHERING_SUBNET_MASK           "255.255.255.0"
191
192 #define TETHERING_USB_IF                "usb0"
193 #define TETHERING_USB_GATEWAY           "192.168.129.1"
194
195 #define TETHERING_WIFI_IF               "wlan0"
196 #define TETHERING_WIFI_GATEWAY          "192.168.61.1"
197
198 #define TETHERING_BT_IF                 "bnep0"
199 #define TETHERING_BT_GATEWAY            "192.168.130.1"
200
201 #define TETHERING_WIFI_SSID_MAX_LEN     31      /**< Maximum length of ssid */
202 #define TETHERING_WIFI_KEY_MIN_LEN      8       /**< Minimum length of wifi key */
203 #define TETHERING_WIFI_KEY_MAX_LEN      63      /**< Maximum length of wifi key */
204 /**
205 * End of mobileap-agent common values
206 */
207 #define TETHERING_DBUS_MAX_RETRY_COUNT                  3
208
209 #define TETHERING_DEFAULT_SSID                          "Redwood"
210 #define TETHERING_DEFAULT_PASSPHRASE                    "eoiugkl!"
211 #define TETHERING_WIFI_SECURITY_TYPE_OPEN_STR           "open"
212 #define TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR       "wpa2-psk"
213
214
215 typedef void (*__handle_cb_t)(DBusGProxy *proxy, const char *name, gpointer data);
216 typedef struct {
217         char name[TETHERING_SIGNAL_NAME_LEN];
218         __handle_cb_t cb;
219 } __tethering_sig_t;
220
221 typedef struct {
222         DBusGConnection *client_bus;
223         DBusGProxy *client_bus_proxy;
224
225         tethering_enabled_cb enabled_cb[TETHERING_TYPE_MAX];
226         void *enabled_user_data[TETHERING_TYPE_MAX];
227         tethering_disabled_cb disabled_cb[TETHERING_TYPE_MAX];
228         void *disabled_user_data[TETHERING_TYPE_MAX];
229         tethering_connection_state_changed_cb changed_cb[TETHERING_TYPE_MAX];
230         void *changed_user_data[TETHERING_TYPE_MAX];
231         tethering_data_usage_cb data_usage_cb;
232         void *data_usage_user_data;
233         tethering_wifi_security_type_changed_cb security_type_changed_cb;
234         void *security_type_user_data;
235         tethering_wifi_ssid_visibility_changed_cb ssid_visibility_changed_cb;
236         void *ssid_visibility_user_data;
237         tethering_wifi_passphrase_changed_cb passphrase_changed_cb;
238         void *passphrase_user_data;
239
240         char *ssid;
241 } __tethering_h;
242
243 typedef struct {
244         tethering_type_e interface;                     /**< interface type */
245         char ip[TETHERING_STR_INFO_LEN];                /**< assigned IP address */
246         char mac[TETHERING_STR_INFO_LEN];               /**< MAC Address */
247         char hostname[TETHERING_STR_HOSTNAME_LEN];      /**< alphanumeric name */
248         time_t tm;      /**< connection time */
249 } __tethering_client_h;
250
251 typedef struct {
252         tethering_type_e interface;                     /**< interface type */
253         char interface_name[TETHERING_STR_INFO_LEN];    /**< interface alphanumeric name */
254         char ip_address[TETHERING_STR_INFO_LEN];        /**< assigned ip addresss to interface */
255         char gateway_address[TETHERING_STR_INFO_LEN];   /**< gateway address of interface */
256         char subnet_mask[TETHERING_STR_INFO_LEN];       /**< subnet mask of interface */
257 } __tethering_interface_t;
258
259 #ifdef __cplusplus
260 }
261 #endif
262
263 #endif /* __TETHERING_PRIVATE_H__ */