Source code upload
[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 "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("[%s()][Ln:%d] "fmt, __func__, __LINE__, ##args)
41 #define WARN(fmt, args...) LOGW("[%s()][Ln:%d] "fmt, __func__, __LINE__, ##args)
42 #define ERR(fmt, args...) LOGE("[%s()][Ln:%d] "fmt, __func__, __LINE__, ##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 * WiFi tethering configuration
88 */
89 #define TETHERING_WIFI_CHANNEL          7       /**< Channel number */
90 #define TETHERING_WIFI_BSSID_LEN        6       /**< BSSID Length */
91 #define TETHERING_WIFI_PASSPHRASE_MIN_LEN       8       /**< Minimum length of wifi key */
92 #define TETHERING_WIFI_PASSPHRASE_MAX_LEN       63      /**< Maximum length of wifi key */
93
94 /**
95 * Common configuration
96 */
97 #define TETHERING_MAX_WIFI_STA          8
98 #define TETHERING_MAX_BT_STA            7
99 #define TETHERING_MAX_USB_STA           1
100 #define TETHERING_MAX_CONNECTED_STA     16      /**< Maximum connected station. 8(Wi-Fi) + 7(BT) + 1(USB) */
101
102 #define TETHERING_NAME_UNKNOWN          "UNKNOWN"
103
104 #define TETHERING_TYPE_MAX              4       /**< All, USB, Wi-Fi, BT */
105 #define TETHERING_STR_INFO_LEN          20      /**< length of the ip or mac address */
106 #define TETHERING_STR_HOSTNAME_LEN      32      /**< length of the hostname */
107
108 /**
109 * Mobile AP error code
110 */
111 typedef enum {
112         MOBILE_AP_ERROR_NONE,                   /**< No error */
113         MOBILE_AP_ERROR_RESOURCE,               /**< Socket creation error, file open error */
114         MOBILE_AP_ERROR_INTERNAL,               /**< Driver related error */
115         MOBILE_AP_ERROR_INVALID_PARAM,          /**< Invalid parameter */
116         MOBILE_AP_ERROR_ALREADY_ENABLED,        /**< Mobile AP is already ON */
117         MOBILE_AP_ERROR_NOT_ENABLED,            /**< Mobile AP is not ON, so cannot be disabled */
118         MOBILE_AP_ERROR_NET_OPEN,               /**< PDP network open error */
119         MOBILE_AP_ERROR_NET_CLOSE,              /**< PDP network close error */
120         MOBILE_AP_ERROR_DHCP,                   /**< DHCP error */
121         MOBILE_AP_ERROR_IN_PROGRESS,            /**< Request is in progress */
122         MOBILE_AP_ERROR_NOT_PERMITTED,          /**< Operation is not permitted */
123
124         MOBILE_AP_ERROR_MAX
125 } mobile_ap_error_code_e;
126
127 /**
128 * Event type on callback
129 */
130 typedef enum {
131         MOBILE_AP_ENABLE_CFM,
132         MOBILE_AP_DISABLE_CFM,
133
134         MOBILE_AP_ENABLE_WIFI_TETHERING_CFM,
135         MOBILE_AP_DISABLE_WIFI_TETHERING_CFM,
136         MOBILE_AP_CHANGE_WIFI_CONFIG_CFM,
137
138         MOBILE_AP_ENABLE_USB_TETHERING_CFM,
139         MOBILE_AP_DISABLE_USB_TETHERING_CFM,
140
141         MOBILE_AP_ENABLE_BT_TETHERING_CFM,
142         MOBILE_AP_DISABLE_BT_TETHERING_CFM,
143
144         MOBILE_AP_GET_STATION_INFO_CFM,
145         MOBILE_AP_GET_DATA_PACKET_USAGE_CFM
146 } mobile_ap_event_e;
147
148 typedef enum {
149         MOBILE_AP_TYPE_WIFI,
150         MOBILE_AP_TYPE_USB,
151         MOBILE_AP_TYPE_BT,
152         MOBILE_AP_TYPE_MAX,
153 } mobile_ap_type_e;
154
155
156 /*
157 * from mobileap_internal.h
158 */
159 #define DBUS_STRUCT_UINT_STRING (dbus_g_type_get_struct ("GValueArray", \
160                         G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID))
161
162 #define DBUS_STRUCT_STATIONS (dbus_g_type_get_struct ("GValueArray", \
163                         G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, \
164                         G_TYPE_STRING, G_TYPE_INVALID))
165
166 #define DBUS_STRUCT_STATION (dbus_g_type_get_struct ("GValueArray", \
167                         G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \
168                         G_TYPE_INVALID))
169
170 #define DBUS_STRUCT_INTERFACE (dbus_g_type_get_struct ("GValueArray", \
171                         G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \
172                         G_TYPE_STRING, G_TYPE_INVALID))
173
174 #define TETHERING_SERVICE_OBJECT_PATH   "/MobileAP"
175 #define TETHERING_SERVICE_NAME          "com.samsung.mobileap"
176 #define TETHERING_SERVICE_INTERFACE     "com.samsung.mobileap"
177
178 #define TETHERING_SIGNAL_NAME_LEN       64
179
180 #define SIGNAL_NAME_NET_CLOSED          "net_closed"
181 #define SIGNAL_NAME_STA_CONNECT         "sta_connected"
182 #define SIGNAL_NAME_STA_DISCONNECT      "sta_disconnected"
183 #define SIGNAL_NAME_WIFI_TETHER_ON      "wifi_on"
184 #define SIGNAL_NAME_WIFI_TETHER_OFF     "wifi_off"
185 #define SIGNAL_NAME_USB_TETHER_ON       "usb_on"
186 #define SIGNAL_NAME_USB_TETHER_OFF      "usb_off"
187 #define SIGNAL_NAME_BT_TETHER_ON        "bluetooth_on"
188 #define SIGNAL_NAME_BT_TETHER_OFF       "bluetooth_off"
189 #define SIGNAL_NAME_NO_DATA_TIMEOUT     "no_data_timeout"
190 #define SIGNAL_NAME_LOW_BATTERY_MODE    "low_batt_mode"
191 #define SIGNAL_NAME_FLIGHT_MODE         "flight_mode"
192 #define SIGNAL_NAME_DHCP_STATUS         "dhcp_status"
193
194 #define SIGNAL_MSG_NOT_AVAIL_INTERFACE  "Interface is not available"
195
196 /* Network Interface */
197 #define TETHERING_SUBNET_MASK           "255.255.255.0"
198
199 #define TETHERING_USB_IF                "usb0"
200 #define TETHERING_USB_GATEWAY           "192.168.129.1"
201
202 #define TETHERING_WIFI_IF               "wlan0"
203 #define TETHERING_WIFI_GATEWAY          "192.168.61.1"
204
205 #define TETHERING_BT_IF                 "bnep0"
206 #define TETHERING_BT_GATEWAY            "192.168.130.1"
207 /**
208 * End of mobileap-agent common values
209 */
210
211 #define TETHERING_DEFAULT_SSID                          "Redwood"
212 #define TETHERING_DEFAULT_PASSPHRASE                    "eoiugkl!"
213 #define TETHERING_WIFI_SECURITY_TYPE_OPEN_STR           "open"
214 #define TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR       "wpa2-psk"
215
216
217 typedef void (*__handle_cb_t)(DBusGProxy *proxy, const char *name, gpointer data);
218 typedef struct {
219         char name[TETHERING_SIGNAL_NAME_LEN];
220         __handle_cb_t cb;
221 } __tethering_sig_t;
222
223 typedef struct {
224         DBusGConnection *client_bus;
225         DBusGProxy *client_bus_proxy;
226
227         tethering_enabled_cb enabled_cb[TETHERING_TYPE_MAX];
228         void *enabled_user_data[TETHERING_TYPE_MAX];
229         tethering_disabled_cb disabled_cb[TETHERING_TYPE_MAX];
230         void *disabled_user_data[TETHERING_TYPE_MAX];
231         tethering_connection_state_changed_cb changed_cb[TETHERING_TYPE_MAX];
232         void *changed_user_data[TETHERING_TYPE_MAX];
233         tethering_data_usage_cb data_usage_cb;
234         void *data_usage_user_data;
235 } __tethering_h;
236
237 typedef struct {
238         tethering_type_e interface;                     /**< interface type */
239         char ip[TETHERING_STR_INFO_LEN];                /**< assigned IP address */
240         char mac[TETHERING_STR_INFO_LEN];               /**< MAC Address */
241         char hostname[TETHERING_STR_HOSTNAME_LEN];      /**< alphanumeric name */
242 } __tethering_client_h;
243
244 typedef struct {
245         tethering_type_e interface;                     /**< interface type */
246         char interface_name[TETHERING_STR_INFO_LEN];    /**< interface alphanumeric name */
247         char ip_address[TETHERING_STR_INFO_LEN];        /**< assigned ip addresss to interface */
248         char gateway_address[TETHERING_STR_INFO_LEN];   /**< gateway address of interface */
249         char subnet_mask[TETHERING_STR_INFO_LEN];       /**< subnet mask of interface */
250 } __tethering_interface_t;
251
252 #ifdef __cplusplus
253 }
254 #endif
255
256 #endif /* __TETHERING_PRIVATE_H__ */