Merge "Return errors to caller" into tizen_5.5
[platform/core/connectivity/stc-manager.git] / include / stc-manager.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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 __STC_MANAGER_H__
18 #define __STC_MANAGER_H__
19
20 #include "stc-error.h"
21 #include "stc-manager-util.h"
22
23 #define NET_RELEASE_AGENT "/usr/bin/net-cls-release"
24 #define NET_CLS_SUBSYS "net_cls"
25
26 #define STC_BACKGROUND_APP_SUFFIX "_BACKGROUND"
27 #define STC_TETHERING_APP_SUFFIX "_TETHERING"
28 #define STC_TOTAL_BACKGROUND "TOTAL_BACKGROUND"
29 #define STC_TOTAL_DATACALL "TOTAL_DATACALL"
30 #define STC_TOTAL_WIFI "TOTAL_WIFI"
31 #define STC_TOTAL_BLUETOOTH "TOTAL_BLUETOOTH"
32 #define STC_TOTAL_IPV4 "TOTAL_IPV4"
33 #define STC_TOTAL_IPV6 "TOTAL_IPV6"
34 #define STC_TOTAL_TETHERING "TOTAL_TETHERING"
35
36 #define STC_IPTABLES "/usr/sbin/iptables"
37 #define STC_IP6TABLES "/usr/sbin/ip6tables"
38
39 #define STC_CMD_INSERT "-I"
40 #define STC_CMD_SIZE 256
41
42 #define STC_DEBUG_LOG (stc_util_get_log_state(DEBUG_LOG_INFO))
43 #define STC_STAT_LOG (stc_util_get_log_state(STAT_LOG_INFO))
44 #define STC_RSTN_LOG (stc_util_get_log_state(RSTN_LOG_INFO))
45 #define STC_FW_LOG (stc_util_get_log_state(FW_LOG_INFO))
46 #define STC_PCAP_LOG (stc_util_get_log_state(PCAP_LOG_INFO))
47
48 typedef enum {
49         STC_CANCEL = 0,    /**< cancel */
50         STC_CONTINUE = 1,  /**< continue */
51 } stc_cb_ret_e;
52
53 typedef enum {
54         STC_CMD_NONE,
55         STC_CMD_SET_FOREGRD,
56         STC_CMD_SET_BACKGRD,
57         STC_CMD_SET_APP_LAUNCHED,
58         STC_CMD_SET_SERVICE_LAUNCHED,
59         STC_CMD_SET_TERMINATED,
60         STC_CMD_MAX_ELEM
61 } stc_cmd_type_e;
62
63 typedef enum {
64         STC_FW_DIRECTION_NONE,
65         STC_FW_DIRECTION_IN,
66         STC_FW_DIRECTION_OUT
67 } stc_fw_direction_e;
68
69 typedef enum {
70         STC_FW_FAMILY_NONE,
71         STC_FW_FAMILY_V4,
72         STC_FW_FAMILY_V6
73 } stc_fw_family_type_e;
74
75 typedef enum {
76         STC_FW_IP_NONE,
77         STC_FW_IP_SINGLE,
78         STC_FW_IP_MASK,
79         STC_FW_IP_RANGE
80 } stc_fw_ip_type_e;
81
82 typedef enum {
83         STC_FW_PORT_NONE,
84         STC_FW_PORT_SINGLE,
85         STC_FW_PORT_RANGE
86 } stc_fw_port_type_e;
87
88 typedef enum {
89         STC_FW_PROTOCOL_NONE,
90         STC_FW_PROTOCOL_TCP,
91         STC_FW_PROTOCOL_UDP,
92         STC_FW_PROTOCOL_ICMP,
93         STC_FW_PROTOCOL_ESP,
94         STC_FW_PROTOCOL_AH,
95         STC_FW_PROTOCOL_SCTP,
96         STC_FW_PROTOCOL_MH,
97         STC_FW_PROTOCOL_ALL,
98 } stc_fw_protocol_type_e;
99
100 typedef enum {
101         STC_FW_CHAIN_TARGET_NONE,
102         STC_FW_CHAIN_TARGET_INPUT,
103         STC_FW_CHAIN_TARGET_OUTPUT,
104         STC_FW_CHAIN_TARGET_MAX
105 } stc_fw_chain_target_e;
106
107 typedef enum {
108         STC_FW_RULE_TARGET_NONE,
109         STC_FW_RULE_TARGET_ACCEPT,
110         STC_FW_RULE_TARGET_DROP,
111         STC_FW_RULE_TARGET_LOG,
112         STC_FW_RULE_TARGET_NFLOG,
113         STC_FW_RULE_TARGET_MAX
114 } stc_fw_rule_target_e;
115
116 /**
117  * @brief Monitored application types
118  */
119 typedef enum {
120         STC_APP_TYPE_NONE,
121         STC_APP_TYPE_READY,
122         STC_APP_TYPE_GUI,
123         STC_APP_TYPE_SERVICE,
124         STC_APP_TYPE_GROUP,
125         STC_APP_TYPE_WATCH,
126         STC_APP_TYPE_WIDGET,
127         STC_APP_TYPE_TETHERING,
128         STC_APP_TYPE_MAX,
129 } stc_app_type_e;
130
131 /**
132  * @brief State of the statisticsed process
133  */
134 typedef enum {
135         STC_APP_STATE_UNKNOWN,
136         STC_APP_STATE_FOREGROUND = 1 << 1,  /** < foreground state */
137         STC_APP_STATE_BACKGROUND = 1 << 2,  /** < background state */
138         STC_APP_STATE_LAST_ELEM
139 } stc_app_state_e;
140
141 /**
142  * @brief Network restriction states
143  */
144 typedef enum {
145         STC_RSTN_STATE_UNKNOWN,
146         STC_RSTN_STATE_ACTIVATED,
147         STC_RSTN_STATE_DEACTIVATED,
148         STC_RSTN_STATE_LAST_ELEM
149 } stc_rstn_state_e;
150
151 /**
152  * @brief Network restriction types
153  */
154 typedef enum {
155         STC_RSTN_TYPE_UNKNOWN,
156         STC_RSTN_TYPE_ACCEPT,
157         STC_RSTN_TYPE_DROP,
158         STC_RSTN_TYPE_LAST_ELEM
159 } stc_rstn_type_e;
160
161 /**
162  * @brief Network interface types
163  */
164 typedef enum {
165         STC_IFACE_UNKNOWN,    /**< undefined iface */
166         STC_IFACE_DATACALL,   /**< mobile data */
167         STC_IFACE_WIFI,       /**< wifi data */
168         STC_IFACE_WIRED,      /**< wired interface */
169         STC_IFACE_BLUETOOTH,  /**< bluetooth interface */
170         STC_IFACE_IPV4,       /**< ipv4 interface */
171         STC_IFACE_IPV6,       /**< ipv6 interface */
172         STC_IFACE_USB,        /**< usb interface */
173         STC_IFACE_P2P,        /**< p2p interface */
174         STC_IFACE_ALL,        /**< enumerate all network interface types */
175         STC_IFACE_LAST_ELEM
176 } stc_iface_type_e;
177
178 /**
179  * @brief Network roaming type
180  */
181 typedef enum {
182         STC_ROAMING_UNKNOWN,
183         STC_ROAMING_ENABLE,    /**< in roaming */
184         STC_ROAMING_DISABLE,   /**< not in roaming */
185 } stc_roaming_type_e;
186
187 /**
188  * @brief Hardware network protocol types
189  */
190 typedef enum {
191         STC_PROTOCOL_UNKNOWN,             /**< Network unknown */
192         STC_PROTOCOL_DATACALL_NOSVC,      /**< Network no service */
193         STC_PROTOCOL_DATACALL_EMERGENCY,  /**< Network emergency */
194         STC_PROTOCOL_DATACALL_SEARCH,     /**< Network search 1900 */
195         STC_PROTOCOL_DATACALL_2G,         /**< Network 2G */
196         STC_PROTOCOL_DATACALL_2_5G,       /**< Network 2.5G */
197         STC_PROTOCOL_DATACALL_2_5G_EDGE,  /**< Network EDGE */
198         STC_PROTOCOL_DATACALL_3G,         /**< Network UMTS */
199         STC_PROTOCOL_DATACALL_HSDPA,      /**< Network HSDPA */
200         STC_PROTOCOL_DATACALL_LTE,        /**< Network LTE */
201         STC_PROTOCOL_MAX_ELEM
202 } stc_hw_net_protocol_type_e;
203
204 /**
205  * @desc Description of the boolean option for enabling/disabling
206  *     network interfaces and enabling/disabling some behaviar
207  */
208 typedef enum {
209         STC_DB_OPTION_UNDEF,
210         STC_DB_OPTION_ENABLE,
211         STC_DB_OPTION_DISABLE
212 } stc_option_state_e;
213
214 /**
215  * @desc Set of the options.
216  * wifi - enable/disable wifi, STC_DB_OPTION_UNDEF to leave option as is
217  * datacall - enable/disable datacall, STC_DB_OPTION_UNDEF to leave option as is
218  * datausage_timer - set period of the updating data from the kernel,
219  *     0 to leave option as is
220  * datacall_logging - enable/disable datacall_logging,
221  *     STC_DB_OPTION_UNDEF to leave option as is
222  */
223 typedef struct {
224         stc_option_state_e wifi;
225         stc_option_state_e datacall;
226         time_t datausage_timer;
227         stc_option_state_e datacall_logging;
228 } stc_options_s;
229
230 /**
231  * @brief datausage in bytes
232  */
233 typedef struct {
234         long long int in_bytes;  /**< incoming bytes */
235         long long int out_bytes;  /**< outgoing bytes */
236 } stc_data_counter_s;
237
238 typedef struct {
239         GMainLoop *main_loop;
240         guint timer;
241         gboolean keep_alive;
242         gboolean ondemand_mode;
243
244         gpointer statistics_obj;
245         gpointer restriction_obj;
246         gpointer firewall_obj;
247         gpointer pcap_obj;
248         gpointer manager_obj;
249
250         GDBusObjectManagerServer *obj_mgr;
251         GDBusConnection *connection;
252         guint gdbus_owner_id;
253
254         void *system; /* stc_system_s */
255         struct counter_arg *carg;
256 } stc_s;
257
258 stc_s *stc_get_manager(void);
259 void stc_stop_manager(void);
260 int stc_commit_iptables(char *cmd, int *err_num, char **err_str);
261 void stc_set_keep_alive(gboolean keep_alive);
262
263 #endif /* __STC_MANAGER__ */