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