/* SELECT statements */
#define SELECT_FOR_PERIOD "select binpath, hw_net_protocol_type, " \
"is_roaming, sum(received) as received, " \
- "sum(sent) as sent, imsi, ground from statistics " \
+ "sum(sent) as sent, imsi, ground, iftype, ifname from statistics " \
"where time_stamp between ? and ? " \
"group by binpath, is_roaming, imsi order by received desc"
#define SELECT_FOR_PERIOD_IFACE "select binpath, hw_net_protocol_type, " \
"is_roaming, sum(received) as received, " \
- "sum(sent) as sent, imsi, ground from statistics " \
+ "sum(sent) as sent, imsi, ground, iftype, ifname from statistics " \
"where time_stamp between ? and ? " \
"and iftype=? group by binpath, is_roaming, imsi order by received desc"
#define SELECT_CHUNKS "select binpath, hw_net_protocol_type, " \
"is_roaming, sum(received) as received, " \
- "sum(sent) as sent, time_stamp - time_stamp % ? as time_stamp, imsi, " \
- "ground " \
+ "sum(sent) as sent, imsi, ground, iftype, ifname, " \
+ "time_stamp - time_stamp % ? as time_stamp " \
"from statistics where time_stamp between ? and ? " \
"group by binpath, time_stamp, imsi order by time_stamp"
#define SELECT_CHUNKS_IFACE "select binpath, hw_net_protocol_type, " \
"is_roaming, sum(received) as received, " \
- "sum(sent) as sent, imsi, ground, " \
+ "sum(sent) as sent, imsi, ground, iftype, ifname, " \
"time_stamp - time_stamp % ? as time_stamp " \
"from statistics where time_stamp between ? and ? and iftype=?" \
"group by binpath, time_stamp, imsi order by time_stamp"
#define SELECT_TOTAL "select iftype, hw_net_protocol_type, " \
"is_roaming, sum(received) as received, sum(sent) as sent, " \
"ifname, imsi, ground from statistics " \
- " where (time_stamp between ? and ?) " \
+ " where (time_stamp between ? and ?) and binpath != 'TOTAL_DATACALL' " \
+ "and binpath != 'TOTAL_WIFI' and binpath != 'TOTAL_BLUETOOTH' " \
"group by iftype, ifname, imsi, hw_net_protocol_type, is_roaming " \
"order by time_stamp, iftype, ifname, imsi, hw_net_protocol_type, " \
"is_roaming"
data.app_id = (char *)sqlite3_column_text(stmt, 0);
data.hw_net_protocol_type = sqlite3_column_int(stmt, 1);
data.roaming = sqlite3_column_int(stmt, 2);
- data.ground = sqlite3_column_int(stmt, 6);
data.cnt.in_bytes = sqlite3_column_int64(stmt, 3);
data.cnt.out_bytes = sqlite3_column_int64(stmt, 4);
data.imsi = (char *)sqlite3_column_text(stmt, 5);
+ data.ground = sqlite3_column_int(stmt, 6);
+ data.iftype = sqlite3_column_int(stmt, 7);
+ data.ifname = (char *)sqlite3_column_text(stmt, 8);
+
if (rule->granularity) {
- interval.from = sqlite3_column_int64(stmt, 7);
+ interval.from = sqlite3_column_int64(stmt, 9);
interval.to = interval.from + rule->granularity;
}
default_connection_s *connection = (default_connection_s *)data;
stc_s *stc = stc_get_manager();
+ if (app_value->classid == STC_TOTAL_DATACALL_CLASSID ||
+ app_value->classid == STC_TOTAL_WIFI_CLASSID ||
+ app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID)
+ return FALSE;
+
if (stc && connection && connection->ifname) {
struct nfacct_rule counter;
counter.carg = stc->carg;
counter.classid = app_value->classid;
counter.intend = NFACCT_COUNTER;
+ counter.iftype = connection->type;
g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
__add_iptables_in(&counter);
counter.carg = stc->carg;
counter.classid = app_value->classid;
counter.intend = NFACCT_COUNTER;
+ counter.iftype = connection->type;
g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
__del_iptables_in(&counter);
counter.carg = stc->carg;
counter.classid = rstn_value->classid;
counter.intend = NFACCT_BLOCK;
- counter.iftype = STC_IFACE_UNKNOWN;
+ counter.iftype = rstn_key->iftype;
g_strlcpy(counter.ifname, default_ifname,
MAX_IFACE_LENGTH);
counter.carg = stc->carg;
counter.classid = rstn_value->classid;
counter.intend = NFACCT_BLOCK;
- counter.iftype = STC_IFACE_UNKNOWN;
+ counter.iftype = rstn_key->iftype;
g_strlcpy(counter.ifname, default_ifname,
MAX_IFACE_LENGTH);
return STC_ERROR_NONE;
}
-static gboolean __rstn_counter_update_foreach_classid(gpointer key,
- gpointer value,
- gpointer data)
+static gboolean __rstn_counter_update(stc_rstn_key_s *rstn_key,
+ stc_rstn_value_s *rstn_value,
+ classid_bytes_context_s *context)
{
- stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
- stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
- classid_bytes_context_s *context = (classid_bytes_context_s *)data;
-
- if (context->counter->intend != NFACCT_COUNTER)
- goto try_next_callback;
-
- if (rstn_value->classid != context->counter->classid)
- goto try_next_callback;
-
- if (rstn_value->data_limit_reached == TRUE) {
- context->data_limit_reached = TRUE;
- goto try_next_callback;
- }
-
switch (context->counter->iotype) {
case NFACCT_COUNTER_IN:
case NFACCT_COUNTER_OUT:
STC_DBUS_SERVICE_RESTRICTION_PATH,
STC_DBUS_INTERFACE_RESTRICTION,
"WarnThresholdCrossed",
- g_variant_new("(s)", rstn_key->app_id));
+ g_variant_new("(si)", rstn_key->app_id, rstn_key->iftype));
if (rv == TRUE)
rstn_value->warn_limit_crossed_notified = TRUE;
STC_DBUS_SERVICE_RESTRICTION_PATH,
STC_DBUS_INTERFACE_RESTRICTION,
"RestrictionThresholdCrossed",
- g_variant_new("(s)", rstn_key->app_id));
+ g_variant_new("(si)", rstn_key->app_id, rstn_key->iftype));
if (rv == TRUE)
rstn_value->rstn_limit_crossed_notified = TRUE;
STC_LOGE("unknown iotype");
}
+ return FALSE;
+}
+
+static gboolean __interface_rstn_counter_update(stc_rstn_key_s *rstn_key,
+ stc_rstn_value_s *rstn_value,
+ classid_bytes_context_s *context)
+{
+ if ((rstn_value->classid == STC_TOTAL_DATACALL_CLASSID &&
+ context->counter->iftype == STC_IFACE_DATACALL) ||
+ (rstn_value->classid == STC_TOTAL_WIFI_CLASSID &&
+ context->counter->iftype == STC_IFACE_WIFI) ||
+ (rstn_value->classid == STC_TOTAL_BLUETOOTH_CLASSID &&
+ context->counter->iftype == STC_IFACE_BLUETOOTH)) {
+ context->counter->classid = rstn_value->classid;
+ return __rstn_counter_update(rstn_key, rstn_value, context);
+ }
-try_next_callback:
return FALSE;
}
+static gboolean __rstn_counter_update_foreach_classid(gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ gboolean rv = FALSE;
+ stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
+ stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
+ classid_bytes_context_s *context = (classid_bytes_context_s *)data;
+ uint32_t classid;
+
+ if (context->counter->intend != NFACCT_COUNTER)
+ goto try_next_callback;
+
+ if (rstn_value->data_limit_reached == TRUE) {
+ context->data_limit_reached = TRUE;
+ goto try_next_callback;
+ }
+
+ classid = context->counter->classid;
+ rv = __interface_rstn_counter_update(rstn_key, rstn_value, context);
+
+ context->counter->classid = classid;
+ if (rstn_value->classid != context->counter->classid)
+ goto try_next_callback;
+
+ rv = __rstn_counter_update(rstn_key, rstn_value, context);
+
+try_next_callback:
+ return rv;
+}
+
static gboolean __update_app_statistics(gpointer key, gpointer value,
gpointer data)
{
return G_SOURCE_REMOVE;
}
-static gboolean __apps_counter_update_foreach_classid(gpointer key,
- gpointer value,
- gpointer data)
+static void __app_counter_update(stc_app_key_s *app_key,
+ stc_app_value_s *app_value,
+ classid_bytes_context_s *context)
{
- stc_app_key_s *app_key = (stc_app_key_s *)key;
- stc_app_value_s *app_value = (stc_app_value_s *)value;
- classid_bytes_context_s *context = (classid_bytes_context_s *)data;
-
- if (context->counter->intend != NFACCT_COUNTER)
- goto try_next_callback;
-
- if (app_value->classid != context->counter->classid)
- goto try_next_callback;
-
switch (context->counter->iotype) {
case NFACCT_COUNTER_IN:
app_value->data_usage.in_bytes += context->bytes;
default:
STC_LOGE("unknown iotype");
}
+}
+
+static void __interface_counter_update(stc_app_key_s *app_key,
+ stc_app_value_s *app_value,
+ classid_bytes_context_s *context)
+{
+ if ((app_value->classid == STC_TOTAL_DATACALL_CLASSID &&
+ context->counter->iftype == STC_IFACE_DATACALL) ||
+ (app_value->classid == STC_TOTAL_WIFI_CLASSID &&
+ context->counter->iftype == STC_IFACE_WIFI) ||
+ (app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID &&
+ context->counter->iftype == STC_IFACE_BLUETOOTH))
+ __app_counter_update(app_key, app_value, context);
+}
+
+static gboolean __apps_counter_update_foreach_classid(gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ stc_app_key_s *app_key = (stc_app_key_s *)key;
+ stc_app_value_s *app_value = (stc_app_value_s *)value;
+ classid_bytes_context_s *context = (classid_bytes_context_s *)data;
+
+ if (context->counter->intend != NFACCT_COUNTER)
+ goto try_next_callback;
+
+ __interface_counter_update(app_key, app_value, context);
+
+ if (app_value->classid != context->counter->classid)
+ goto try_next_callback;
+
+ __app_counter_update(app_key, app_value, context);
try_next_callback:
return FALSE;
app_id);
}
+static void __stc_monitor_add_application_by_interface(const char *app_id)
+{
+ stc_app_key_s app_key;
+ stc_app_value_s app_value;
+
+ if (app_id == NULL)
+ return;
+
+ memset(&app_key, 0, sizeof(stc_app_key_s));
+ memset(&app_value, 0, sizeof(stc_app_value_s));
+
+ app_key.pkg_id = g_strdup(app_id);
+ app_key.app_id = g_strdup(app_id);
+
+ app_value.type = STC_APP_TYPE_NONE;
+ app_value.processes = NULL;
+ app_value.counter.in_bytes = 0;
+ app_value.counter.out_bytes = 0;
+
+ stc_monitor_application_add(app_key, app_value);
+
+ FREE(app_key.pkg_id);
+ FREE(app_key.app_id);
+}
+
stc_error_e stc_monitor_init(void)
{
stc_system_s *system = MALLOC0(stc_system_s, 1);
g_system = system;
+ __stc_monitor_add_application_by_interface(STC_TOTAL_DATACALL);
+ __stc_monitor_add_application_by_interface(STC_TOTAL_WIFI);
+ __stc_monitor_add_application_by_interface(STC_TOTAL_BLUETOOTH);
+
/* creating restriction rules tree */
__update_contr_cb(NULL);