merge with master
[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
109         MOBILE_AP_ERROR_MAX
110 } mobile_ap_error_code_e;
111
112 /**
113 * Event type on callback
114 */
115 typedef enum {
116         MOBILE_AP_ENABLE_CFM,
117         MOBILE_AP_DISABLE_CFM,
118
119         MOBILE_AP_ENABLE_WIFI_TETHERING_CFM,
120         MOBILE_AP_DISABLE_WIFI_TETHERING_CFM,
121         MOBILE_AP_CHANGE_WIFI_CONFIG_CFM,
122
123         MOBILE_AP_ENABLE_USB_TETHERING_CFM,
124         MOBILE_AP_DISABLE_USB_TETHERING_CFM,
125
126         MOBILE_AP_ENABLE_BT_TETHERING_CFM,
127         MOBILE_AP_DISABLE_BT_TETHERING_CFM,
128
129         MOBILE_AP_GET_STATION_INFO_CFM,
130         MOBILE_AP_GET_DATA_PACKET_USAGE_CFM
131 } mobile_ap_event_e;
132
133 typedef enum {
134         MOBILE_AP_TYPE_WIFI,
135         MOBILE_AP_TYPE_USB,
136         MOBILE_AP_TYPE_BT,
137         MOBILE_AP_TYPE_MAX,
138 } mobile_ap_type_e;
139
140
141 /*
142 * from mobileap_internal.h
143 */
144 #define DBUS_STRUCT_UINT_STRING (dbus_g_type_get_struct ("GValueArray", \
145                         G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID))
146
147 #define DBUS_STRUCT_STATIONS (dbus_g_type_get_struct ("GValueArray", \
148                         G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, \
149                         G_TYPE_STRING, G_TYPE_INVALID))
150
151 #define DBUS_STRUCT_STATION (dbus_g_type_get_struct ("GValueArray", \
152                         G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \
153                         G_TYPE_INVALID))
154
155 #define DBUS_STRUCT_INTERFACE (dbus_g_type_get_struct ("GValueArray", \
156                         G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \
157                         G_TYPE_STRING, G_TYPE_INVALID))
158
159 #define TETHERING_SERVICE_OBJECT_PATH   "/Tethering"
160 #define TETHERING_SERVICE_NAME          "org.tizen.tethering"
161 #define TETHERING_SERVICE_INTERFACE     "org.tizen.tethering"
162
163 #define TETHERING_SIGNAL_NAME_LEN       64
164
165 #define SIGNAL_NAME_NET_CLOSED          "net_closed"
166 #define SIGNAL_NAME_STA_CONNECT         "sta_connected"
167 #define SIGNAL_NAME_STA_DISCONNECT      "sta_disconnected"
168 #define SIGNAL_NAME_WIFI_TETHER_ON      "wifi_on"
169 #define SIGNAL_NAME_WIFI_TETHER_OFF     "wifi_off"
170 #define SIGNAL_NAME_USB_TETHER_ON       "usb_on"
171 #define SIGNAL_NAME_USB_TETHER_OFF      "usb_off"
172 #define SIGNAL_NAME_BT_TETHER_ON        "bluetooth_on"
173 #define SIGNAL_NAME_BT_TETHER_OFF       "bluetooth_off"
174 #define SIGNAL_NAME_NO_DATA_TIMEOUT     "no_data_timeout"
175 #define SIGNAL_NAME_LOW_BATTERY_MODE    "low_batt_mode"
176 #define SIGNAL_NAME_FLIGHT_MODE         "flight_mode"
177 #define SIGNAL_NAME_DHCP_STATUS         "dhcp_status"
178 #define SIGNAL_NAME_SECURITY_TYPE_CHANGED       "security_type_changed"
179 #define SIGNAL_NAME_SSID_VISIBILITY_CHANGED     "ssid_visibility_changed"
180 #define SIGNAL_NAME_PASSPHRASE_CHANGED          "passphrase_changed"
181
182 #define SIGNAL_MSG_NOT_AVAIL_INTERFACE  "Interface is not available"
183 #define SIGNAL_MSG_TIMEOUT              "There is no connection for a while"
184 #define SIGNAL_MSG_SSID_VISIBLE         "ssid_visible"
185 #define SIGNAL_MSG_SSID_HIDE            "ssid_hide"
186
187 /* Network Interface */
188 #define TETHERING_SUBNET_MASK           "255.255.255.0"
189
190 #define TETHERING_USB_IF                "usb0"
191 #define TETHERING_USB_GATEWAY           "192.168.129.1"
192
193 #define TETHERING_WIFI_IF               "wlan0"
194 #define TETHERING_WIFI_GATEWAY          "192.168.61.1"
195
196 #define TETHERING_BT_IF                 "bnep0"
197 #define TETHERING_BT_GATEWAY            "192.168.130.1"
198
199 #define TETHERING_WIFI_SSID_MAX_LEN     31      /**< Maximum length of ssid */
200 #define TETHERING_WIFI_KEY_MIN_LEN      8       /**< Minimum length of wifi key */
201 #define TETHERING_WIFI_KEY_MAX_LEN      63      /**< Maximum length of wifi key */
202 /**
203 * End of mobileap-agent common values
204 */
205
206 #define TETHERING_DEFAULT_SSID                          "Redwood"
207 #define TETHERING_DEFAULT_PASSPHRASE                    "eoiugkl!"
208 #define TETHERING_WIFI_SECURITY_TYPE_OPEN_STR           "open"
209 #define TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR       "wpa2-psk"
210
211
212 typedef void (*__handle_cb_t)(DBusGProxy *proxy, const char *name, gpointer data);
213 typedef struct {
214         char name[TETHERING_SIGNAL_NAME_LEN];
215         __handle_cb_t cb;
216 } __tethering_sig_t;
217
218 typedef struct {
219         DBusGConnection *client_bus;
220         DBusGProxy *client_bus_proxy;
221
222         tethering_enabled_cb enabled_cb[TETHERING_TYPE_MAX];
223         void *enabled_user_data[TETHERING_TYPE_MAX];
224         tethering_disabled_cb disabled_cb[TETHERING_TYPE_MAX];
225         void *disabled_user_data[TETHERING_TYPE_MAX];
226         tethering_connection_state_changed_cb changed_cb[TETHERING_TYPE_MAX];
227         void *changed_user_data[TETHERING_TYPE_MAX];
228         tethering_data_usage_cb data_usage_cb;
229         void *data_usage_user_data;
230         tethering_wifi_security_type_changed_cb security_type_changed_cb;
231         void *security_type_user_data;
232         tethering_wifi_ssid_visibility_changed_cb ssid_visibility_changed_cb;
233         void *ssid_visibility_user_data;
234         tethering_wifi_passphrase_changed_cb passphrase_changed_cb;
235         void *passphrase_user_data;
236
237         char *ssid;
238 } __tethering_h;
239
240 typedef struct {
241         tethering_type_e interface;                     /**< interface type */
242         char ip[TETHERING_STR_INFO_LEN];                /**< assigned IP address */
243         char mac[TETHERING_STR_INFO_LEN];               /**< MAC Address */
244         char hostname[TETHERING_STR_HOSTNAME_LEN];      /**< alphanumeric name */
245 } __tethering_client_h;
246
247 typedef struct {
248         tethering_type_e interface;                     /**< interface type */
249         char interface_name[TETHERING_STR_INFO_LEN];    /**< interface alphanumeric name */
250         char ip_address[TETHERING_STR_INFO_LEN];        /**< assigned ip addresss to interface */
251         char gateway_address[TETHERING_STR_INFO_LEN];   /**< gateway address of interface */
252         char subnet_mask[TETHERING_STR_INFO_LEN];       /**< subnet mask of interface */
253 } __tethering_interface_t;
254
255 #ifdef __cplusplus
256 }
257 #endif
258
259 #endif /* __TETHERING_PRIVATE_H__ */