Added dbus method to commit iptables
[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_BACKGROUND_APP_ID "BACKGROUND"
28 #define STC_TOTAL_DATACALL "TOTAL_DATACALL"
29 #define STC_TOTAL_WIFI "TOTAL_WIFI"
30 #define STC_TOTAL_BLUETOOTH "TOTAL_BLUETOOTH"
31 #define STC_TOTAL_IPV4 "TOTAL_IPV4"
32 #define STC_TOTAL_IPV6 "TOTAL_IPV6"
33
34 #define STC_IPTABLES "/usr/sbin/iptables"
35 #define STC_IP6TABLES "/usr/sbin/ip6tables"
36
37 #define STC_CMD_SIZE 256
38
39 #define STC_DEBUG_LOG (stc_util_get_debuglog())
40
41 typedef enum {
42         STC_CANCEL = 0,    /**< cancel */
43         STC_CONTINUE = 1,  /**< continue */
44 } stc_cb_ret_e;
45
46 typedef enum {
47         STC_CMD_NONE,
48         STC_CMD_SET_FOREGRD,
49         STC_CMD_SET_BACKGRD,
50         STC_CMD_SET_APP_LAUNCHED,
51         STC_CMD_SET_SERVICE_LAUNCHED,
52         STC_CMD_SET_TERMINATED,
53         STC_CMD_MAX_ELEM
54 } stc_cmd_type_e;
55
56 typedef enum {
57         STC_FW_DIRECTION_NONE,
58         STC_FW_DIRECTION_IN,
59         STC_FW_DIRECTION_OUT
60 } stc_fw_direction_e;
61
62 typedef enum {
63         STC_FW_FAMILY_NONE,
64         STC_FW_FAMILY_V4,
65         STC_FW_FAMILY_V6
66 } stc_fw_family_type_e;
67
68 typedef enum {
69         STC_FW_IP_NONE,
70         STC_FW_IP_SINGLE,
71         STC_FW_IP_MASK,
72         STC_FW_IP_RANGE
73 } stc_fw_ip_type_e;
74
75 typedef enum {
76         STC_FW_PORT_NONE,
77         STC_FW_PORT_SINGLE,
78         STC_FW_PORT_RANGE
79 } stc_fw_port_type_e;
80
81 typedef enum {
82         STC_FW_PROTOCOL_NONE,
83         STC_FW_PROTOCOL_TCP,
84         STC_FW_PROTOCOL_UDP,
85         STC_FW_PROTOCOL_ICMP,
86         STC_FW_PROTOCOL_ESP,
87         STC_FW_PROTOCOL_AH,
88         STC_FW_PROTOCOL_SCTP,
89         STC_FW_PROTOCOL_MH,
90         STC_FW_PROTOCOL_ALL,
91 } stc_fw_protocol_type_e;
92
93 typedef enum {
94         STC_FW_CHAIN_TARGET_NONE,
95         STC_FW_CHAIN_TARGET_INPUT,
96         STC_FW_CHAIN_TARGET_OUTPUT
97 } stc_fw_chain_target_e;
98
99 typedef enum {
100         STC_FW_RULE_TARGET_NONE,
101         STC_FW_RULE_TARGET_ACCEPT,
102         STC_FW_RULE_TARGET_DROP,
103         STC_FW_RULE_TARGET_LOG,
104 } stc_fw_rule_target_e;
105
106 /**
107  * @brief Monitored application types
108  */
109 typedef enum {
110         STC_APP_TYPE_NONE,
111         STC_APP_TYPE_READY,
112         STC_APP_TYPE_GUI,
113         STC_APP_TYPE_SERVICE,
114         STC_APP_TYPE_GROUP,
115         STC_APP_TYPE_WATCH,
116         STC_APP_TYPE_WIDGET,
117         STC_APP_TYPE_MAX,
118 } stc_app_type_e;
119
120 /**
121  * @brief State of the statisticsed process
122  */
123 typedef enum {
124         STC_APP_STATE_UNKNOWN = 0,
125         STC_APP_STATE_FOREGROUND = 1 << 1,  /** < foreground state */
126         STC_APP_STATE_BACKGROUND = 1 << 2,  /** < background state */
127         STC_APP_STATE_LAST_ELEM = 1 << 3
128 } stc_app_state_e;
129
130 /**
131  * @brief Network restriction states
132  */
133 typedef enum {
134         STC_RESTRICTION_UNKNOWN,
135         STC_RESTRICTION_ACTIVATED,  /**< restriction has been activated */
136         STC_RESTRICTION_DEACTIVATED,  /**< restriction has been deactivated */
137         STC_RESTRICTION_LAST_ELEM
138 } stc_restriction_state_e;
139
140 /**
141  * @brief Network restriction types
142  */
143 typedef enum {
144         STC_RSTN_TYPE_UNKNOWN,
145         STC_RSTN_TYPE_EXCLUDED,  /**< exclusion */
146         STC_RSTN_TYPE_BLOCKED,    /**< block */
147         STC_RSTN_TYPE_LAST_ELEM
148 } stc_rstn_type_e;
149
150 /**
151  * @brief Network interface types
152  */
153 typedef enum {
154         STC_IFACE_UNKNOWN,    /**< undefined iface */
155         STC_IFACE_DATACALL,   /**< mobile data */
156         STC_IFACE_WIFI,       /**< wifi data */
157         STC_IFACE_WIRED,      /**< wired interface */
158         STC_IFACE_BLUETOOTH,  /**< bluetooth interface */
159         STC_IFACE_IPV4,       /**< ipv4 interface */
160         STC_IFACE_IPV6,       /**< ipv6 interface */
161         STC_IFACE_ALL,        /**< enumerate all network interface types */
162         STC_IFACE_LAST_ELEM
163 } stc_iface_type_e;
164
165 /**
166  * @brief Network roaming type
167  */
168 typedef enum {
169         STC_ROAMING_UNKNOWN,   /**< can't define roaming - roaming unknown */
170         STC_ROAMING_ENABLE,    /**< in roaming */
171         STC_ROAMING_DISABLE,   /**< not in roaming */
172         STC_ROAMING_LAST_ELEM,
173 } stc_roaming_type_e;
174
175 /**
176  * @brief Hardware network protocol types
177  */
178 typedef enum {
179         STC_PROTOCOL_UNKNOWN,             /**< Network unknown */
180         STC_PROTOCOL_DATACALL_NOSVC,      /**< Network no service */
181         STC_PROTOCOL_DATACALL_EMERGENCY,  /**< Network emergency */
182         STC_PROTOCOL_DATACALL_SEARCH,     /**< Network search 1900 */
183         STC_PROTOCOL_DATACALL_2G,         /**< Network 2G */
184         STC_PROTOCOL_DATACALL_2_5G,       /**< Network 2.5G */
185         STC_PROTOCOL_DATACALL_2_5G_EDGE,  /**< Network EDGE */
186         STC_PROTOCOL_DATACALL_3G,         /**< Network UMTS */
187         STC_PROTOCOL_DATACALL_HSDPA,      /**< Network HSDPA */
188         STC_PROTOCOL_DATACALL_LTE,        /**< Network LTE */
189         STC_PROTOCOL_MAX_ELEM
190 } stc_hw_net_protocol_type_e;
191
192 /**
193  * @desc Description of the boolean option for enabling/disabling
194  *     network interfaces and enabling/disabling some behaviar
195  */
196 typedef enum {
197         STC_DB_OPTION_UNDEF,
198         STC_DB_OPTION_ENABLE,
199         STC_DB_OPTION_DISABLE
200 } stc_option_state_e;
201
202 /**
203  * @desc Set of the options.
204  * wifi - enable/disable wifi, STC_DB_OPTION_UNDEF to leave option as is
205  * datacall - enable/disable datacall, STC_DB_OPTION_UNDEF to leave option as is
206  * datausage_timer - set period of the updating data from the kernel,
207  *     0 to leave option as is
208  * datacall_logging - enable/disable datacall_logging,
209  *     STC_DB_OPTION_UNDEF to leave option as is
210  */
211 typedef struct {
212         stc_option_state_e wifi;
213         stc_option_state_e datacall;
214         time_t datausage_timer;
215         stc_option_state_e datacall_logging;
216 } stc_options_s;
217
218 /**
219  * @brief datausage in bytes
220  */
221 typedef struct {
222         int64_t in_bytes;  /**< incoming bytes */
223         int64_t out_bytes;  /**< outgoing bytes */
224 } stc_data_counter_s;
225
226 typedef struct {
227         GMainLoop *main_loop;
228
229         gpointer statistics_obj;
230         gpointer restriction_obj;
231         gpointer firewall_obj;
232         gpointer manager_obj;
233
234         GDBusObjectManagerServer *obj_mgr;
235         GDBusConnection *connection;
236         guint gdbus_owner_id;
237
238         void *system; /* stc_system_s */
239         struct counter_arg *carg;
240 } stc_s;
241
242 stc_s *stc_get_manager(void);
243 void stc_stop_manager(void);
244 int stc_commit_iptables(char *cmd, int *err_num, char **err_str);
245
246 #endif /* __STC_MANAGER__ */