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