Name: stc-manager
Summary: STC(Smart Traffic Control) manager
-Version: 0.0.80
+Version: 0.0.81
Release: 0
Group: Network & Connectivity/Other
License: Apache-2.0
* limitations under the License.
*/
-#ifndef __STC_DEFAULT_CONNECTION_H__
-#define __STC_DEFAULT_CONNECTION_H__
+#ifndef __STC_CONNECTION_H__
+#define __STC_CONNECTION_H__
#include <glib.h>
#include "stc-error.h"
} tether_iface_s;
/**
- * @brief default connection information will be fetched from net-config
+ * @brief connection information will be fetched from connman
*/
typedef struct {
/* to identify each connection uniquely */
/* tethering interface */
tether_iface_s tether_iface;
-} default_connection_s;
+} stc_connection_s;
-stc_error_e stc_default_connection_monitor_init(stc_s *stc);
-stc_error_e stc_default_connection_monitor_deinit(stc_s *stc);
+stc_error_e stc_connection_monitor_init(stc_s *stc);
+stc_error_e stc_connection_monitor_deinit(stc_s *stc);
-gchar *stc_default_connection_get_ifname(void);
-default_connection_s *stc_get_default_connection(void);
+GSList *stc_get_connection_list(void);
-#endif /* __STC_DEFAULT_CONNECTION_H__ */
+#endif /* __STC_CONNECTION_H__ */
#include "stc-error.h"
#include "stc-manager.h"
#include "stc-monitor-context.h"
-#include "stc-default-connection.h"
+#include "stc-connection.h"
#define MAC_ADDRESS_LEN 18
#define SUBSCRIBERID_NONE "none_subid"
void stc_monitor_app_add_monitor(gpointer key,
gpointer value, gpointer data);
-void stc_monitor_app_add_by_connection(default_connection_s *conn);
+void stc_monitor_app_add_by_connection(stc_connection_s *conn);
void stc_monitor_app_add_accept(gpointer key,
gpointer value, gpointer data);
void stc_monitor_app_remove_monitor(gpointer key,
gpointer value, gpointer data);
-void stc_monitor_app_remove_by_connection(default_connection_s *conn);
+void stc_monitor_app_remove_by_connection(stc_connection_s *conn);
void stc_monitor_app_remove_accept(gpointer key,
gpointer value, gpointer data);
#include "stc-error.h"
#include "stc-manager.h"
#include "stc-monitor-context.h"
-#include "stc-default-connection.h"
+#include "stc-connection.h"
#include "stc-restriction.h"
#include "table-restrictions.h"
void stc_monitor_rstn_add_for_app(uint32_t classid);
-void stc_monitor_rstn_add_by_connection(default_connection_s *conn);
+void stc_monitor_rstn_add_by_connection(stc_connection_s *conn);
stc_error_e stc_monitor_rstn_remove(const table_restrictions_info *info);
void stc_monitor_rstn_remove_for_app(uint32_t classid);
-void stc_monitor_rstn_remove_by_connection(default_connection_s *conn);
+void stc_monitor_rstn_remove_by_connection(stc_connection_s *conn);
void stc_monitor_rstns_load(void);
gboolean stc_monitor_get_background_state(void);
-void stc_monitor_update_by_default_connection(void *data);
+void stc_monitor_update_by_connection(void *data);
+
+void stc_monitor_add_by_connection(void *data);
+
+void stc_monitor_remove_by_connection(void *data);
stc_error_e stc_monitor_check_excn_by_cmdline(char *cmdline);
#include "stc-monitor.h"
#include "stc-firewall.h"
#include "stc-manager-gdbus.h"
-#include "stc-default-connection.h"
+#include "stc-connection.h"
/* connman service dbus details */
#define CONNMAN_SERVICE "net.connman"
#define VCONF_TELEPHONY_DEFAULT_DATA_SERVICE "db/telephony/dualsim/default_data_service"
-default_connection_s g_default_connection;
-guint g_default_connection_sub_id = 0;
+stc_connection_s *g_default_connection = NULL;
+GSList *g_connection_list = NULL;
+guint g_connection_sub_id = 0;
+
+static void __conn_list_free(gpointer value)
+{
+ stc_connection_s *conn = (stc_connection_s *)value;
+
+ FREE(conn->path);
+ FREE(conn->ifname);
+ FREE(conn->tether_iface.ifname);
+ FREE(conn);
+}
+
+static gint __conn_list_comp(gconstpointer a, gconstpointer b)
+{
+ stc_connection_s *conn = (stc_connection_s *)a;
+ char *path = (char *)b;
+
+ if (g_strcmp0(conn->path, path) == 0)
+ return 0;
+
+ return -1;
+}
+
+static void __update_monitor_by_conn(gpointer data, gpointer user_data)
+{
+ stc_connection_s *conn = (stc_connection_s *)data;
+
+ stc_monitor_update_by_connection(conn);
+}
static int __telephony_get_current_sim(void)
{
return current_sim;
}
-static void __make_imsi_to_subscriber_id(char *imsi)
+static void __make_imsi_to_subscriber_id(stc_connection_s *conn, char *imsi)
{
int i = 0;
SHA256_CTX ctx;
SHA256_Final(md, &ctx);
for (i = 0; i < SHA256_DIGEST_LENGTH; ++i)
- snprintf(g_default_connection.subscriber_id + (i * 2), 3, "%02x", md[i]);
+ snprintf(conn->subscriber_id + (i * 2), 3, "%02x", md[i]);
}
static void __telephony_get_modem_subscriber_id(GDBusConnection *connection,
- const char *default_modem_name)
+ stc_connection_s *conn, const char *default_modem_name)
{
GVariant *message = NULL;
char tel_path[MAX_PATH_LENGTH];
}
snprintf(imsi, IMSI_LENGTH, "%s%s", plmn, msin);
- __make_imsi_to_subscriber_id(imsi);
+ __make_imsi_to_subscriber_id(conn, imsi);
done:
g_variant_unref(message);
return;
}
-static void __telephony_update_default_modem_subscriber_id(GDBusConnection *connection)
+static void __telephony_update_default_modem_subscriber_id(GDBusConnection *connection,
+ stc_connection_s *conn)
{
GVariant *message = NULL;
GVariantIter *iter = NULL;
current_sim--; //LCOV_EXCL_LINE
}
- __telephony_get_modem_subscriber_id(connection, default_modem_name);
+ __telephony_get_modem_subscriber_id(connection, conn, default_modem_name);
FREE(default_modem_name);
g_variant_iter_free(iter);
return;
}
-static void __print_default_connection_info(void)
+static void __print_connection_info(stc_connection_s *conn)
{
- STC_LOGI("============= default connection info ============");
- STC_LOGI("path [%s]", g_default_connection.path);
- STC_LOGI("type [%d]", g_default_connection.type);
- STC_LOGI("ifname [%s]", g_default_connection.ifname);
- STC_LOGI("roaming [%u]", g_default_connection.roaming ? TRUE : FALSE);
- if (g_default_connection.type == STC_IFACE_DATACALL)
- STC_LOGI("sub_id [%s]", g_default_connection.subscriber_id);
+ STC_LOGI("============= connection info ============");
+ STC_LOGI("path [%s]", conn->path);
+ STC_LOGI("type [%d]", conn->type);
+ STC_LOGI("ifname [%s]", conn->ifname);
+ STC_LOGI("roaming [%u]", conn->roaming ? TRUE : FALSE);
+ if (conn->type == STC_IFACE_DATACALL)
+ STC_LOGI("sub_id [%s]", conn->subscriber_id);
STC_LOGI("==================================================");
}
static void __print_tether_connection_info(void)
{
STC_LOGI("============= tethering connection info ============");
- STC_LOGI("mode [%u]", g_default_connection.tether_state ? TRUE : FALSE);
- STC_LOGI("type [%d]", g_default_connection.tether_iface.type);
- STC_LOGI("ifname [%s]", g_default_connection.tether_iface.ifname);
+ STC_LOGI("mode [%u]", g_default_connection->tether_state ? TRUE : FALSE);
+ STC_LOGI("type [%d]", g_default_connection->tether_iface.type);
+ STC_LOGI("ifname [%s]", g_default_connection->tether_iface.ifname);
STC_LOGI("====================================================");
}
-static void __reset_default_connection_data(void)
-{
- FREE(g_default_connection.path);
- FREE(g_default_connection.ifname);
- FREE(g_default_connection.tether_iface.ifname);
- g_default_connection.type = STC_IFACE_UNKNOWN;
- g_default_connection.roaming = FALSE;
- g_default_connection.tether_iface.type = STC_IFACE_UNKNOWN;
- g_default_connection.tether_state = FALSE;
-}
-
static gboolean __is_cellular_internet_profile(const char *profile)
{
const char internet_suffix[] = "_1";
return is_connected;
}
-static void __get_default_connection_info(GDBusConnection *connection,
- const char *object_path)
+static void __get_connection_info(GDBusConnection *connection,
+ stc_connection_s *conn, const char *object_path)
{
GVariant *message = NULL;
GVariantIter *iter = NULL;
const gchar *value =
g_variant_get_string(variant1,
NULL);
- g_default_connection.ifname =
- g_strdup(value);
+ conn->ifname = g_strdup(value);
}
}
if (g_variant_is_of_type(variant,
G_VARIANT_TYPE_BOOLEAN)) {
roaming = g_variant_get_boolean(variant);
- g_default_connection.roaming = roaming;
+ conn->roaming = roaming;
}
}
}
return;
}
-static stc_error_e __get_default_profile(GDBusConnection *connection)
+static stc_error_e __get_connected_profiles(GDBusConnection *connection)
{
GVariant *message = NULL;
GVariantIter *iter = NULL;
GVariantIter *next;
gchar *object_path;
+ stc_connection_s *conn;
+ gboolean default_conn = TRUE;
message = stc_manager_gdbus_call_sync(connection,
CONNMAN_SERVICE,
return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
+ g_slist_free_full(g_connection_list, __conn_list_free);
+
g_variant_get(message, "(a(oa{sv}))", &iter);
while (g_variant_iter_loop(iter, "(oa{sv})", &object_path, &next)) {
if (object_path == NULL)
continue;
if (__is_connected(next) == TRUE) {
- /* reset old default connection data */
- FREE(g_default_connection.path);
- FREE(g_default_connection.ifname);
- g_default_connection.type = STC_IFACE_UNKNOWN;
- g_default_connection.roaming = FALSE;
+ conn = MALLOC0(stc_connection_s, 1);
+ if (conn == NULL)
+ continue;
+
+ conn->path = g_strdup(object_path);
+ conn->roaming = FALSE;
+
+ if (__is_cellular_profile(conn->path)) {
+ conn->type = STC_IFACE_DATACALL;
+ __telephony_update_default_modem_subscriber_id(connection, conn);
+ } else if (__is_wifi_profile(conn->path)) {
+ conn->type = STC_IFACE_WIFI;
+ } else if (__is_ethernet_profile(conn->path)) {
+ conn->type = STC_IFACE_WIRED;
+ } else if (__is_bluetooth_profile(conn->path)) {
+ conn->type = STC_IFACE_BLUETOOTH;
+ } else {
+ conn->type = STC_IFACE_UNKNOWN;
+ }
+
+ __get_connection_info(connection, conn, conn->path);
+ __print_connection_info(conn);
+
+ if (default_conn == TRUE) {
+ g_default_connection = conn;
+ default_conn = FALSE;
+ }
+
+ g_connection_list = g_slist_append(g_connection_list, conn);
- g_default_connection.path = g_strdup(object_path);
g_free(object_path);
g_variant_iter_free(next);
- break;
+ continue;
}
}
g_variant_iter_free(iter);
g_variant_unref(message);
- if (__is_cellular_profile(g_default_connection.path)) {
- g_default_connection.type = STC_IFACE_DATACALL; //LCOV_EXCL_LINE
- __telephony_update_default_modem_subscriber_id(connection); //LCOV_EXCL_LINE
- } else if (__is_wifi_profile(g_default_connection.path)) {
- g_default_connection.type = STC_IFACE_WIFI; //LCOV_EXCL_LINE
- } else if (__is_ethernet_profile(g_default_connection.path)) {
- g_default_connection.type = STC_IFACE_WIRED; //LCOV_EXCL_LINE
- } else if (__is_bluetooth_profile(g_default_connection.path)) {
- g_default_connection.type = STC_IFACE_BLUETOOTH; //LCOV_EXCL_LINE
- } else {
- g_default_connection.type = STC_IFACE_UNKNOWN; //LCOV_EXCL_LINE
- }
-
- __get_default_connection_info(connection, g_default_connection.path);
-
- __print_default_connection_info();
-
- stc_monitor_update_by_default_connection(&g_default_connection);
+ g_slist_foreach(g_connection_list, __update_monitor_by_conn, NULL);
stc_firewall_update();
return STC_ERROR_NONE;
}
-static void _service_signal_cb(GDBusConnection *conn,
- const gchar *name, const gchar *path,
- const gchar *interface, const gchar *sig,
- GVariant *param, gpointer user_data)
+static stc_error_e __get_default_connection(GDBusConnection *connection)
{
- gchar *sigvalue = NULL;
- GVariant *variant = NULL;
- stc_s *stc = (stc_s *)stc_get_manager();
- ret_msg_if(stc == NULL, "failed to get stc data");
+ GVariant *message = NULL;
+ GVariantIter *iter = NULL;
+ GVariantIter *next;
+ gchar *object_path;
- if (path == NULL || param == NULL)
- goto done;
+ message = stc_manager_gdbus_call_sync(connection,
+ CONNMAN_SERVICE,
+ CONNMAN_MANAGER_PATH,
+ CONNMAN_MANAGER_INTERFACE,
+ "GetServices", NULL);
+ if (message == NULL) {
+ STC_LOGE("Failed to get profiles"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
+ }
- g_variant_get(param, "(sv)", &sigvalue, &variant);
- if (sigvalue == NULL)
- goto done;
+ g_variant_get(message, "(a(oa{sv}))", &iter);
+ while (g_variant_iter_loop(iter, "(oa{sv})", &object_path, &next)) {
+ if (object_path == NULL)
+ continue; //LCOV_EXCL_LINE
- if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
- goto done;
+ if (__is_cellular_profile(object_path) &&
+ !__is_cellular_internet_profile(object_path))
+ continue;
- if (g_strcmp0(sigvalue, "State") == 0 &&
- g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
- const gchar *state = NULL;
+ if (__is_connected(next) == TRUE) {
+ GSList *comp = g_slist_find_custom(g_connection_list,
+ object_path, __conn_list_comp);
+ if (comp && comp->data)
+ g_default_connection = comp->data;
- state = g_variant_get_string(variant, NULL);
- if (g_strcmp0(state, "ready") == 0 ||
- g_strcmp0(state, "online") == 0) {
- if (g_strcmp0(g_default_connection.path, path)) {
- __reset_default_connection_data();
- __get_default_profile(stc->connection);
- }
- } else {
- if (g_strcmp0(g_default_connection.path, path) == 0) {
- __reset_default_connection_data(); //LCOV_EXCL_LINE
- __get_default_profile(stc->connection); //LCOV_EXCL_LINE
- }
+ break;
}
- } else if (g_strcmp0(sigvalue, "Roaming") == 0) {
- //LCOV_EXCL_START
- if (g_strcmp0(g_default_connection.path, path) == 0) {
- gboolean roaming = 0;
+ }
- if (g_variant_is_of_type(variant,
- G_VARIANT_TYPE_BOOLEAN)) {
- roaming = g_variant_get_boolean(variant);
- g_default_connection.roaming = roaming;
- }
- }
- //LCOV_EXCL_STOP
+ g_variant_iter_free(iter);
+ g_variant_unref(message);
+
+ return STC_ERROR_NONE;
+}
+
+static void __append_connected_profile(GDBusConnection *connection,
+ const char *path)
+{
+ stc_connection_s *conn;
+
+ conn = MALLOC0(stc_connection_s, 1);
+ if (conn == NULL)
+ return;
+
+ conn->path = g_strdup(path);
+ conn->roaming = FALSE;
+
+ if (__is_cellular_profile(conn->path)) {
+ conn->type = STC_IFACE_DATACALL;
+ __telephony_update_default_modem_subscriber_id(connection, conn);
+ } else if (__is_wifi_profile(conn->path)) {
+ conn->type = STC_IFACE_WIFI;
+ } else if (__is_ethernet_profile(conn->path)) {
+ conn->type = STC_IFACE_WIRED;
+ } else if (__is_bluetooth_profile(conn->path)) {
+ conn->type = STC_IFACE_BLUETOOTH;
} else {
- ;//Do nothing
+ conn->type = STC_IFACE_UNKNOWN;
}
-done:
- if (sigvalue)
- g_free(sigvalue);
- if (variant)
- g_variant_unref(variant);
+ __get_connection_info(connection, conn, conn->path);
+ __print_connection_info(conn);
- return;
+ g_connection_list = g_slist_append(g_connection_list, conn);
+
+ stc_monitor_add_by_connection(conn);
+ stc_firewall_update();
+
+ __get_default_connection(connection);
+}
+
+static void __remove_disconnected_profile(GDBusConnection *connection,
+ stc_connection_s *conn)
+{
+ __print_connection_info(conn);
+
+ stc_monitor_remove_by_connection(conn);
+
+ g_connection_list = g_slist_remove(g_connection_list, conn);
+
+ __get_default_connection(connection);
+
+ FREE(conn->path);
+ FREE(conn->ifname);
+ FREE(conn->tether_iface.ifname);
+ FREE(conn);
}
static void __vconf_key_callback(keynode_t *node, void *user_data)
return;
}
+ if (g_default_connection == NULL)
+ return;
+
if (vconf_keynode_get_type(node) != VCONF_TYPE_INT) {
STC_LOGE("Invalid vconf key type");
return;
switch (vconf_key) {
case VCONFKEY_MOBILE_HOTSPOT_MODE_USB:
STC_LOGI("Hotspot mode USB type !");
- g_default_connection.tether_state = TRUE;
- g_default_connection.tether_iface.ifname = g_strdup(TETHERING_USB_IF);
- g_default_connection.tether_iface.type = STC_IFACE_USB;
+ g_default_connection->tether_state = TRUE;
+ g_default_connection->tether_iface.ifname = g_strdup(TETHERING_USB_IF);
+ g_default_connection->tether_iface.type = STC_IFACE_USB;
break;
case VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI:
STC_LOGI("Hotspot mode Wi-Fi type !");
- g_default_connection.tether_state = TRUE;
- g_default_connection.tether_iface.ifname = g_strdup(TETHERING_WIFI_IF);
- g_default_connection.tether_iface.type = STC_IFACE_WIFI;
+ g_default_connection->tether_state = TRUE;
+ g_default_connection->tether_iface.ifname = g_strdup(TETHERING_WIFI_IF);
+ g_default_connection->tether_iface.type = STC_IFACE_WIFI;
break;
case VCONFKEY_MOBILE_HOTSPOT_MODE_BT:
STC_LOGI("Hotspot mode Bluetooth type !");
- g_default_connection.tether_state = TRUE;
- g_default_connection.tether_iface.ifname = g_strdup(TETHERING_BT_IF);
- g_default_connection.tether_iface.type = STC_IFACE_BLUETOOTH;
+ g_default_connection->tether_state = TRUE;
+ g_default_connection->tether_iface.ifname = g_strdup(TETHERING_BT_IF);
+ g_default_connection->tether_iface.type = STC_IFACE_BLUETOOTH;
break;
case VCONFKEY_MOBILE_HOTSPOT_MODE_P2P:
STC_LOGI("Hotspot mode P2P type !");
- g_default_connection.tether_state = TRUE;
- g_default_connection.tether_iface.ifname = g_strdup(TETHERING_P2P_IF);
- g_default_connection.tether_iface.type = STC_IFACE_P2P;
+ g_default_connection->tether_state = TRUE;
+ g_default_connection->tether_iface.ifname = g_strdup(TETHERING_P2P_IF);
+ g_default_connection->tether_iface.type = STC_IFACE_P2P;
break;
case VCONFKEY_MOBILE_HOTSPOT_MODE_NONE:
STC_LOGI("Hotspot mode none");
- g_default_connection.tether_state = FALSE;
+ g_default_connection->tether_state = FALSE;
break;
default:
STC_LOGE("Unknown Hotspot mode type !");
}
/* add monitoring for tethering if active found */
- if (g_default_connection.tether_state == TRUE && g_default_connection.tether_iface.ifname) {
+ if (g_default_connection->tether_state == TRUE && g_default_connection->tether_iface.ifname) {
__print_tether_connection_info();
- stc_monitor_update_by_default_connection(&g_default_connection);
+ stc_monitor_update_by_connection(&g_default_connection);
stc_firewall_update();
STC_LOGI("Data monitoring started for tethering iface !");
return;
}
/* remove monitoring for tethering if in-active found */
- if (g_default_connection.tether_state == FALSE && g_default_connection.tether_iface.ifname) {
- stc_monitor_update_by_default_connection(&g_default_connection);
- g_free(g_default_connection.tether_iface.ifname);
- g_default_connection.tether_iface.ifname = NULL;
- g_default_connection.tether_iface.type = STC_IFACE_UNKNOWN;
+ if (g_default_connection->tether_state == FALSE && g_default_connection->tether_iface.ifname) {
+ stc_monitor_update_by_connection(&g_default_connection);
+ g_free(g_default_connection->tether_iface.ifname);
+ g_default_connection->tether_iface.ifname = NULL;
+ g_default_connection->tether_iface.type = STC_IFACE_UNKNOWN;
STC_LOGI("Data monitoring stopped for tethering iface !");
return;
}
}
-stc_error_e stc_default_connection_monitor_init(stc_s *stc)
+static void _service_signal_cb(GDBusConnection *connection,
+ const gchar *name, const gchar *path,
+ const gchar *interface, const gchar *sig,
+ GVariant *param, gpointer user_data)
+{
+ gchar *sigvalue = NULL;
+ GVariant *variant = NULL;
+ stc_s *stc = (stc_s *)stc_get_manager();
+ ret_msg_if(stc == NULL, "failed to get stc data");
+
+ if (path == NULL || param == NULL)
+ goto done;
+
+ g_variant_get(param, "(sv)", &sigvalue, &variant);
+ if (sigvalue == NULL)
+ goto done;
+
+ if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
+ goto done;
+
+ if (g_strcmp0(sigvalue, "State") == 0 &&
+ g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
+ const gchar *state = NULL;
+
+ state = g_variant_get_string(variant, NULL);
+ if (g_strcmp0(state, "ready") == 0 ||
+ g_strcmp0(state, "online") == 0) {
+ GSList *comp = g_slist_find_custom(g_connection_list,
+ path, __conn_list_comp);
+ if (!comp)
+ __append_connected_profile(stc->connection, path);
+ } else if (g_strcmp0(state, "idle") == 0 ||
+ g_strcmp0(state, "disconnect") == 0) {
+ GSList *comp = g_slist_find_custom(g_connection_list,
+ path, __conn_list_comp);
+ if (comp && comp->data)
+ __remove_disconnected_profile(stc->connection, comp->data);
+ }
+ } else if (g_strcmp0(sigvalue, "Roaming") == 0) {
+ //LCOV_EXCL_START
+ GSList *comp = g_slist_find_custom(g_connection_list,
+ path, __conn_list_comp);
+
+ if (comp) {
+ stc_connection_s *conn = comp->data;
+ gboolean roaming = 0;
+
+ if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) {
+ roaming = g_variant_get_boolean(variant);
+ conn->roaming = roaming;
+ }
+ }
+ //LCOV_EXCL_STOP
+ } else {
+ ;//Do nothing
+ }
+done:
+ if (sigvalue)
+ g_free(sigvalue);
+
+ if (variant)
+ g_variant_unref(variant);
+
+ return;
+}
+
+stc_error_e stc_connection_monitor_init(stc_s *stc)
{
int ret;
ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
- __get_default_profile(stc->connection);
- g_default_connection_sub_id =
+ __get_connected_profiles(stc->connection);
+ g_connection_sub_id =
stc_manager_gdbus_subscribe_signal(stc->connection,
CONNMAN_SERVICE,
CONNMAN_SERVICE_INTERFACE,
return STC_ERROR_NONE;
}
-stc_error_e stc_default_connection_monitor_deinit(stc_s *stc)
+stc_error_e stc_connection_monitor_deinit(stc_s *stc)
{
ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
stc_manager_gdbus_unsubscribe_signal(stc->connection,
- g_default_connection_sub_id);
- FREE(g_default_connection.path);
- FREE(g_default_connection.ifname);
- return STC_ERROR_NONE;
-}
+ g_connection_sub_id);
-gchar *stc_default_connection_get_ifname(void)
-{
- return g_strdup(g_default_connection.ifname);
+ g_slist_free_full(g_connection_list, __conn_list_free);
+
+ return STC_ERROR_NONE;
}
-default_connection_s *stc_get_default_connection(void)
+GSList *stc_get_connection_list(void)
{
- return &g_default_connection;
+ return g_connection_list;
}
{
stc_app_value_s *app_value = (stc_app_value_s *)value;
time_t *touch_time = (time_t *)data;
- stc_db_classid_iftype_key stat_key;
- stc_db_app_stats stat;
- default_connection_s *default_connection = stc_get_default_connection();
-
- memset(&stat_key, 0, sizeof(stc_db_classid_iftype_key));
- memset(&stat, 0 , sizeof(stc_db_app_stats));
-
- /* Do not update statistics for Tethering
- * if tethering is in-active found */
- if (default_connection &&
- default_connection->tether_state == FALSE &&
- !strcmp(app_value->app_id, STC_TOTAL_TETHERING))
- return;
+ GSList *conn_list = stc_get_connection_list();
- /* Do not update statistics for Wi-Fi
- * if tethering is active on wlan0 iface */
- if (default_connection && default_connection->tether_state &&
- default_connection->tether_iface.type == STC_IFACE_WIFI &&
- !strcmp(app_value->app_id, STC_TOTAL_WIFI))
- return;
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
+ stc_db_classid_iftype_key stat_key;
+ stc_db_app_stats stat;
+
+ memset(&stat_key, 0, sizeof(stc_db_classid_iftype_key));
+ memset(&stat, 0 , sizeof(stc_db_app_stats));
+
+ /* Do not update statistics for Tethering
+ * if tethering is in-active found */
+ if (conn && conn->tether_state == FALSE &&
+ !strcmp(app_value->app_id, STC_TOTAL_TETHERING))
+ return;
+
+ /* Do not update statistics for Wi-Fi
+ * if tethering is active on wlan0 iface */
+ if (conn && conn->tether_state &&
+ conn->tether_iface.type == STC_IFACE_WIFI &&
+ !strcmp(app_value->app_id, STC_TOTAL_WIFI))
+ return;
+
+ stat_key.classid = app_value->classid;
- stat_key.classid = app_value->classid;
-
- if (app_value->classid == STC_TETHERING_APP_CLASSID &&
- default_connection->tether_state == TRUE)
- stat_key.iftype = default_connection->tether_iface.type;
- else if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX))
- stat_key.iftype = default_connection->tether_iface.type;
- else
- stat_key.iftype = default_connection->type;
-
- if (STC_IFACE_DATACALL == stat_key.iftype)
- stat_key.subscriber_id = g_strdup(default_connection->subscriber_id);
- else
- stat_key.subscriber_id = g_strdup(SUBSCRIBERID_NONE);
-
- if (app_value->classid == STC_TETHERING_APP_CLASSID &&
- default_connection->tether_state == TRUE)
- g_strlcpy(stat_key.ifname, default_connection->tether_iface.ifname,
- MAX_IFACE_LENGTH);
- else if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX))
- g_strlcpy(stat_key.ifname, default_connection->tether_iface.ifname,
- MAX_IFACE_LENGTH);
- else
- g_strlcpy(stat_key.ifname, default_connection->ifname,
- MAX_IFACE_LENGTH);
-
- stat.app_id = g_strdup(app_value->app_id);
- stat.snd_count = app_value->counter.out_bytes;
- stat.rcv_count = app_value->counter.in_bytes;
- stat.is_roaming = default_connection->roaming;
-
- if (strstr(stat.app_id, "_BACKGROUND")) {
- stat.ground = STC_APP_STATE_BACKGROUND;
- } else {
- if (strstr(stat.app_id, "TOTAL_"))
- stat.ground = STC_APP_STATE_UNKNOWN;
+ if (app_value->classid == STC_TETHERING_APP_CLASSID &&
+ conn->tether_state == TRUE)
+ stat_key.iftype = conn->tether_iface.type;
+ else if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX))
+ stat_key.iftype = conn->tether_iface.type;
else
- stat.ground = STC_APP_STATE_FOREGROUND;
- }
+ stat_key.iftype = conn->type;
+
+ if (STC_IFACE_DATACALL == stat_key.iftype)
+ stat_key.subscriber_id = g_strdup(conn->subscriber_id);
+ else
+ stat_key.subscriber_id = g_strdup(SUBSCRIBERID_NONE);
+
+ if (app_value->classid == STC_TETHERING_APP_CLASSID &&
+ conn->tether_state == TRUE)
+ g_strlcpy(stat_key.ifname, conn->tether_iface.ifname,
+ MAX_IFACE_LENGTH);
+ else if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX))
+ g_strlcpy(stat_key.ifname, conn->tether_iface.ifname,
+ MAX_IFACE_LENGTH);
+ else
+ g_strlcpy(stat_key.ifname, conn->ifname,
+ MAX_IFACE_LENGTH);
- table_statistics_insert(&stat_key, &stat, *touch_time);
+ stat.app_id = g_strdup(app_value->app_id);
+ stat.snd_count = app_value->counter.out_bytes;
+ stat.rcv_count = app_value->counter.in_bytes;
+ stat.is_roaming = conn->roaming;
+
+ if (strstr(stat.app_id, "_BACKGROUND")) {
+ stat.ground = STC_APP_STATE_BACKGROUND;
+ } else {
+ if (strstr(stat.app_id, "TOTAL_"))
+ stat.ground = STC_APP_STATE_UNKNOWN;
+ else
+ stat.ground = STC_APP_STATE_FOREGROUND;
+ }
- app_value->counter.out_bytes = 0;
- app_value->counter.in_bytes = 0;
+ table_statistics_insert(&stat_key, &stat, *touch_time);
- FREE(stat.app_id);
- FREE(stat_key.subscriber_id);
+ app_value->counter.out_bytes = 0;
+ app_value->counter.in_bytes = 0;
+
+ FREE(stat.app_id);
+ FREE(stat_key.subscriber_id);
+ }
return;
}
gpointer value, gpointer data)
{
stc_app_value_s *app_value = (stc_app_value_s *)value;
- default_connection_s *connection = (default_connection_s *)data;
+ stc_connection_s *connection = (stc_connection_s *)data;
stc_s *stc = stc_get_manager();
struct nfacct_rule counter;
char *ipaddr = NULL;
gpointer value, gpointer data)
{
stc_app_value_s *app_value = (stc_app_value_s *)value;
- default_connection_s *connection = (default_connection_s *)data;
+ stc_connection_s *connection = (stc_connection_s *)data;
stc_s *stc = stc_get_manager();
struct nfacct_rule counter;
char *ipaddr = NULL;
stc_app_value_s *lookup_value;
GHashTable *apps = stc_monitor_get_system_apps();
+ GSList *conn_list = stc_get_connection_list();
if (!apps)
return STC_ERROR_NO_DATA;
g_hash_table_insert(apps, GUINT_TO_POINTER(classid), app_value);
- /* add nfacct rule for this classid */
- stc_monitor_app_add_monitor(GUINT_TO_POINTER(classid),
- app_value, stc_get_default_connection());
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
+ /* add nfacct rule for this classid */
+ stc_monitor_app_add_monitor(GUINT_TO_POINTER(classid),
+ app_value, conn);
- if (app_value->state == STC_APP_STATE_FOREGROUND)
- stc_monitor_app_add_accept(GUINT_TO_POINTER(classid),
- app_value, stc_get_default_connection());
+ if (app_value->state == STC_APP_STATE_FOREGROUND)
+ stc_monitor_app_add_accept(GUINT_TO_POINTER(classid),
+ app_value, conn);
+ }
stc_monitor_rstn_add_for_app(classid);
gpointer value, gpointer data)
{
stc_app_value_s *app_value = (stc_app_value_s *)value;
- default_connection_s *connection = (default_connection_s *)data;
+ stc_connection_s *connection = (stc_connection_s *)data;
stc_s *stc = stc_get_manager();
if (app_value->classid == STC_TOTAL_DATACALL_CLASSID ||
}
}
-void stc_monitor_app_add_by_connection(default_connection_s *conn)
+void stc_monitor_app_add_by_connection(stc_connection_s *conn)
{
GHashTable *apps = stc_monitor_get_system_apps();
return;
g_hash_table_foreach(apps, stc_monitor_app_add_monitor, conn);
+ g_hash_table_foreach(apps, stc_monitor_app_add_accept, conn);
}
void stc_monitor_app_add_accept(gpointer key,
gpointer value, gpointer data)
{
stc_app_value_s *app_value = (stc_app_value_s *)value;
- default_connection_s *connection = (default_connection_s *)data;
+ stc_connection_s *connection = (stc_connection_s *)data;
stc_s *stc = stc_get_manager();
if (app_value->classid == STC_TOTAL_DATACALL_CLASSID ||
app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID)
return;
+ if (app_value->state != STC_APP_STATE_FOREGROUND)
+ return;
+
if (stc && connection && connection->ifname) {
struct nfacct_rule counter;
{
stc_app_value_s *app_lookup;
GHashTable *apps = stc_monitor_get_system_apps();
+ GSList *conn_list = stc_get_connection_list();
if (!apps)
return STC_ERROR_NO_DATA;
return STC_ERROR_FAIL;
}
- /* remove nfacct rule for this classid */
- stc_monitor_app_remove_monitor(GUINT_TO_POINTER(classid),
- app_lookup, stc_get_default_connection());
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
+ /* remove nfacct rule for this classid */
+ stc_monitor_app_remove_monitor(GUINT_TO_POINTER(classid),
+ app_lookup, conn);
+
+ if (app_lookup->state == STC_APP_STATE_FOREGROUND)
+ stc_monitor_app_remove_accept(GUINT_TO_POINTER(classid),
+ app_lookup, conn);
+ }
/* remove ristrictions if any */
stc_monitor_rstn_remove_for_app(classid);
gpointer value, gpointer data)
{
stc_app_value_s *app_value = (stc_app_value_s *)value;
- default_connection_s *connection = (default_connection_s *)data;
+ stc_connection_s *connection = (stc_connection_s *)data;
stc_s *stc = stc_get_manager();
if (stc && connection && connection->ifname) {
return;
}
-void stc_monitor_app_remove_by_connection(default_connection_s *conn)
+void stc_monitor_app_remove_by_connection(stc_connection_s *conn)
{
GHashTable *apps = stc_monitor_get_system_apps();
return;
g_hash_table_foreach(apps, stc_monitor_app_remove_monitor, conn);
+ g_hash_table_foreach(apps, stc_monitor_app_remove_accept, conn);
}
void stc_monitor_app_remove_accept(gpointer key,
gpointer value, gpointer data)
{
stc_app_value_s *app_value = (stc_app_value_s *)value;
- default_connection_s *connection = (default_connection_s *)data;
+ stc_connection_s *connection = (stc_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;
+
+ if (app_value->state != STC_APP_STATE_FOREGROUND)
+ return;
+
if (stc && connection && connection->ifname) {
struct nfacct_rule counter;
#include "stc-monitor.h"
#include "stc-monitor-proc.h"
-#include "stc-default-connection.h"
+#include "stc-connection.h"
#include "helper-net-cls.h"
static void __print_proc(gpointer key, gpointer value,
stc_app_value_s *app_lookup = NULL;
guint pid_count = 0;
GHashTable *apps = stc_monitor_get_system_apps();
+ GSList *conn_list = stc_get_connection_list();
remove_pid_context_s context = {
.pid = pid,
.app_value = NULL,
pid_count = g_hash_table_size(app_lookup->processes);
if (!pid_count) {
- /* remove nfacct rule for this classid */
- stc_monitor_app_remove_monitor(GUINT_TO_POINTER(classid),
- app_lookup, stc_get_default_connection());
-
- if (app_lookup->state == STC_APP_STATE_FOREGROUND)
- stc_monitor_app_remove_accept(GUINT_TO_POINTER(classid),
- app_lookup, stc_get_default_connection());
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
+ /* remove nfacct rule for this classid */
+ stc_monitor_app_remove_monitor(GUINT_TO_POINTER(classid),
+ app_lookup, conn);
+
+ if (app_lookup->state == STC_APP_STATE_FOREGROUND)
+ stc_monitor_app_remove_accept(GUINT_TO_POINTER(classid),
+ app_lookup, conn);
+ }
stc_monitor_rstn_remove_for_app(classid);
stc_error_e ret = STC_ERROR_NONE;
stc_app_value_s *from_lookup = NULL;
stc_app_value_s *to_lookup = NULL;
+ GSList *conn_list = stc_get_connection_list();
GHashTable *apps = stc_monitor_get_system_apps();
if (!apps)
"[\033[1;36m%d\033[0;m]", from);
}
- stc_monitor_app_remove_monitor(GUINT_TO_POINTER(from),
- from_lookup, stc_get_default_connection());
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
+ stc_monitor_app_remove_monitor(GUINT_TO_POINTER(from),
+ from_lookup, conn);
- if (from_lookup->state == STC_APP_STATE_FOREGROUND)
- stc_monitor_app_remove_accept(GUINT_TO_POINTER(from),
- from_lookup, stc_get_default_connection());
+ if (from_lookup->state == STC_APP_STATE_FOREGROUND)
+ stc_monitor_app_remove_accept(GUINT_TO_POINTER(from),
+ from_lookup, conn);
+ }
stc_monitor_rstn_remove_for_app(from);
static void __rstn_add_tether_rule(int64_t classid, gchar *mac,
nfacct_rule_intend intend, stc_iface_type_e iftype)
{
- default_connection_s *connection = stc_get_default_connection();
+ GSList *conn_list = stc_get_connection_list();
struct nfacct_rule counter;
stc_s *stc = stc_get_manager();
char *ipaddr = NULL;
if (!stc || !mac)
return;
- if (!stc->carg) {
- stc->carg = MALLOC0(counter_arg_s, 1);
- if (stc->carg == NULL)
- return;
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
- stc->carg->sock = stc_monitor_get_contr_sock();
- }
+ if (!stc->carg) {
+ stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL)
+ return;
- memset(&counter, 0, sizeof(struct nfacct_rule));
+ stc->carg->sock = stc_monitor_get_contr_sock();
+ }
- counter.carg = stc->carg;
- counter.classid = classid;
- counter.intend = intend;
+ memset(&counter, 0, sizeof(struct nfacct_rule));
- if (connection->tether_state != TRUE ||
- connection->tether_iface.ifname == NULL)
- return;
+ counter.carg = stc->carg;
+ counter.classid = classid;
+ counter.intend = intend;
- counter.iftype = connection->tether_iface.type;
- g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
+ if (conn->tether_state != TRUE ||
+ conn->tether_iface.ifname == NULL)
+ return;
- /* get connected station ip based on its mac */
- ret = stc_plugin_tether_get_station_ip(mac, &ipaddr);
- if (ret != STC_ERROR_NONE)
- return;
+ counter.iftype = conn->tether_iface.type;
+ g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
- /* tethering iptables rule */
- stc_monitor_tether_add_in(&counter, ipaddr);
- stc_monitor_tether_add_out(&counter, ipaddr);
- g_free(ipaddr);
+ /* get connected station ip based on its mac */
+ ret = stc_plugin_tether_get_station_ip(mac, &ipaddr);
+ if (ret != STC_ERROR_NONE)
+ return;
+
+ /* tethering iptables rule */
+ stc_monitor_tether_add_in(&counter, ipaddr);
+ stc_monitor_tether_add_out(&counter, ipaddr);
+ g_free(ipaddr);
+ }
}
static void __rstn_del_tether_rule(int64_t classid, gchar *mac,
nfacct_rule_intend intend, stc_iface_type_e iftype)
{
- default_connection_s *connection = stc_get_default_connection();
+ GSList *conn_list = stc_get_connection_list();
struct nfacct_rule counter;
stc_s *stc = stc_get_manager();
char *ipaddr = NULL;
if (!stc || !mac)
return;
- if (!stc->carg) {
- stc->carg = MALLOC0(counter_arg_s, 1);
- if (stc->carg == NULL)
- return;
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
- stc->carg->sock = stc_monitor_get_contr_sock();
- }
+ if (!stc->carg) {
+ stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL)
+ return;
- memset(&counter, 0, sizeof(struct nfacct_rule));
+ stc->carg->sock = stc_monitor_get_contr_sock();
+ }
- counter.carg = stc->carg;
- counter.classid = classid;
- counter.intend = intend;
+ memset(&counter, 0, sizeof(struct nfacct_rule));
- if (connection->tether_state != TRUE ||
- connection->tether_iface.ifname == NULL)
- return;
+ counter.carg = stc->carg;
+ counter.classid = classid;
+ counter.intend = intend;
- counter.iftype = connection->tether_iface.type;
- g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
+ if (conn->tether_state != TRUE ||
+ conn->tether_iface.ifname == NULL)
+ return;
- /* get connected station ip based on its mac */
- ret = stc_plugin_tether_get_station_ip(mac, &ipaddr);
- if (ret != STC_ERROR_NONE) {
- STC_LOGE("Error: no IP found for station mac(%s)", mac);
- return;
- }
+ counter.iftype = conn->tether_iface.type;
+ g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
+
+ /* get connected station ip based on its mac */
+ ret = stc_plugin_tether_get_station_ip(mac, &ipaddr);
+ if (ret != STC_ERROR_NONE) {
+ STC_LOGE("Error: no IP found for station mac(%s)", mac);
+ return;
+ }
- /* tethering iptables rule */
- stc_monitor_tether_del_in(&counter, ipaddr);
- stc_monitor_tether_del_out(&counter, ipaddr);
- g_free(ipaddr);
+ /* tethering iptables rule */
+ stc_monitor_tether_del_in(&counter, ipaddr);
+ stc_monitor_tether_del_out(&counter, ipaddr);
+ g_free(ipaddr);
+ }
}
static void __rstn_add_ipt_rule(int64_t classid, nfacct_rule_intend intend,
stc_iface_type_e iftype)
{
- char *default_ifname = stc_default_connection_get_ifname();
- default_connection_s *connection = stc_get_default_connection();
+ GSList *conn_list = stc_get_connection_list();
struct nfacct_rule counter;
stc_s *stc = stc_get_manager();
- if (!stc) {
- g_free(default_ifname);
+
+ if (!stc)
return;
- }
- if (!stc->carg) {
- stc->carg = MALLOC0(counter_arg_s, 1);
- if (stc->carg == NULL) {
- g_free(default_ifname);
- return;
- }
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
- stc->carg->sock = stc_monitor_get_contr_sock();
- }
+ if (!stc->carg) {
+ stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL)
+ return;
- memset(&counter, 0, sizeof(struct nfacct_rule));
+ stc->carg->sock = stc_monitor_get_contr_sock();
+ }
- counter.carg = stc->carg;
- counter.classid = classid;
- counter.intend = intend;
+ memset(&counter, 0, sizeof(struct nfacct_rule));
- if (connection && connection->tether_iface.ifname != NULL &&
- classid == STC_TETHERING_APP_CLASSID) {
- counter.iftype = connection->tether_iface.type;
- g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
- } else {
- counter.iftype = iftype;
- g_strlcpy(counter.ifname, default_ifname, MAX_IFACE_LENGTH);
- }
+ counter.carg = stc->carg;
+ counter.classid = classid;
+ counter.intend = intend;
- g_free(default_ifname);
+ if (conn && conn->tether_iface.ifname != NULL &&
+ classid == STC_TETHERING_APP_CLASSID) {
+ counter.iftype = conn->tether_iface.type;
+ g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
+ } else {
+ counter.iftype = iftype;
+ g_strlcpy(counter.ifname, conn->ifname, MAX_IFACE_LENGTH);
+ }
- /* iptables rule */
- stc_monitor_ipt_add_in(&counter);
- stc_monitor_ipt_add_out(&counter);
+ /* iptables rule */
+ stc_monitor_ipt_add_in(&counter);
+ stc_monitor_ipt_add_out(&counter);
- /* ip6tables rule */
- stc_monitor_ip6t_add_in(&counter);
- stc_monitor_ip6t_add_out(&counter);
+ /* ip6tables rule */
+ stc_monitor_ip6t_add_in(&counter);
+ stc_monitor_ip6t_add_out(&counter);
+ }
}
static void __rstn_del_ipt_rule(int64_t classid, nfacct_rule_intend intend,
stc_iface_type_e iftype)
{
- char *default_ifname = stc_default_connection_get_ifname();
- default_connection_s *connection = stc_get_default_connection();
+ GSList *conn_list = stc_get_connection_list();
struct nfacct_rule counter;
stc_s *stc = stc_get_manager();
- if (!stc) {
- g_free(default_ifname);
+
+ if (!stc)
return;
- }
- if (!stc->carg) {
- stc->carg = MALLOC0(counter_arg_s, 1);
- if (stc->carg == NULL) {
- g_free(default_ifname);
- return;
- }
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
- stc->carg->sock = stc_monitor_get_contr_sock();
- }
+ if (!stc->carg) {
+ stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL)
+ return;
- memset(&counter, 0, sizeof(struct nfacct_rule));
+ stc->carg->sock = stc_monitor_get_contr_sock();
+ }
- counter.carg = stc->carg;
- counter.classid = classid;
- counter.intend = intend;
+ memset(&counter, 0, sizeof(struct nfacct_rule));
- if (connection && connection->tether_iface.ifname != NULL &&
- classid == STC_TETHERING_APP_CLASSID) {
- counter.iftype = connection->tether_iface.type;
- g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
- } else {
- counter.iftype = iftype;
- g_strlcpy(counter.ifname, default_ifname, MAX_IFACE_LENGTH);
- }
+ counter.carg = stc->carg;
+ counter.classid = classid;
+ counter.intend = intend;
- g_free(default_ifname);
+ if (conn && conn->tether_iface.ifname != NULL &&
+ classid == STC_TETHERING_APP_CLASSID) {
+ counter.iftype = conn->tether_iface.type;
+ g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
+ } else {
+ counter.iftype = iftype;
+ g_strlcpy(counter.ifname, conn->ifname, MAX_IFACE_LENGTH);
+ }
- /* iptables rule */
- stc_monitor_ipt_del_in(&counter);
- stc_monitor_ipt_del_out(&counter);
+ /* iptables rule */
+ stc_monitor_ipt_del_in(&counter);
+ stc_monitor_ipt_del_out(&counter);
- /* ip6tables rule */
- stc_monitor_ip6t_del_in(&counter);
- stc_monitor_ip6t_del_out(&counter);
+ /* ip6tables rule */
+ stc_monitor_ip6t_del_in(&counter);
+ stc_monitor_ip6t_del_out(&counter);
+ }
}
static void __rstn_set_noti_state(int value)
static void __rstn_tethering_process(enum traffic_restriction_type rstn_type,
char *app_id, stc_rstn_data_s *rstn_data, void *data)
{
- default_connection_s *old_connection = (default_connection_s *)data;
- default_connection_s *connection = NULL;
+ stc_connection_s *old_connection = (stc_connection_s *)data;
+ stc_connection_s *connection = NULL;
char *mac_str = NULL;
- if (old_connection != NULL)
+ if (old_connection != NULL) {
connection = old_connection;
- else
- connection = stc_get_default_connection();
+ if (connection->tether_state == FALSE)
+ return;
- /* in case tethering is not active */
- if (connection->tether_state == FALSE)
- return;
+ /* rstn not applicable for this interface */
+ if (rstn_data->ifname != NULL &&
+ g_strcmp0("", rstn_data->ifname) != 0 &&
+ g_strcmp0(connection->tether_iface.ifname, rstn_data->ifname) != 0)
+ return;
+ } else {
+ GSList *conn_list = stc_get_connection_list();
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
+ if (conn->tether_state == FALSE)
+ continue;
+
+ if (rstn_data->ifname != NULL &&
+ g_strcmp0(rstn_data->ifname, "") != 0 &&
+ g_strcmp0(conn->tether_iface.ifname, rstn_data->ifname) == 0)
+ connection = conn;
+ }
- /* rstn not applicable for this interface */
- if (rstn_data->ifname != NULL && g_strcmp0("", rstn_data->ifname) != 0 &&
- (g_strcmp0(connection->tether_iface.ifname, rstn_data->ifname) != 0))
- return;
+ if (connection == NULL)
+ return;
+ }
/* in case appid not a tethering app */
if (!g_str_has_suffix(app_id, STC_TETHERING_APP_SUFFIX))
static void __rstn_process(enum traffic_restriction_type rstn_type,
char *app_id, stc_rstn_data_s *rstn_data, void *data)
{
- default_connection_s *old_connection = (default_connection_s *)data;
- default_connection_s *connection = NULL;
+ stc_connection_s *old_connection = (stc_connection_s *)data;
+ stc_connection_s *connection = NULL;
- if (old_connection != NULL)
+ if (old_connection != NULL) {
connection = old_connection;
- else
- connection = stc_get_default_connection();
+ if (connection->ifname == NULL)
+ return;
- /* no default ifname */
- if (connection->ifname == NULL)
- return;
+ /* rstn not applicable for this interface */
+ if (rstn_data->ifname != NULL &&
+ g_strcmp0(rstn_data->ifname, "") != 0 &&
+ g_strcmp0(connection->ifname, rstn_data->ifname) != 0 &&
+ g_strcmp0(connection->tether_iface.ifname, rstn_data->ifname) != 0)
+ return;
+ } else {
+ GSList *conn_list = stc_get_connection_list();
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
+ if (conn == NULL || conn->ifname == NULL)
+ continue;
+
+ if (rstn_data->ifname != NULL &&
+ g_strcmp0(rstn_data->ifname, "") != 0 &&
+ g_strcmp0(conn->ifname, rstn_data->ifname) == 0 &&
+ g_strcmp0(conn->tether_iface.ifname, rstn_data->ifname) == 0)
+ connection = conn;
+ }
- /* rstn not applicable for this interface */
- if (rstn_data->ifname != NULL &&
- g_strcmp0(rstn_data->ifname, "") != 0 &&
- (g_strcmp0(connection->ifname, rstn_data->ifname) != 0) &&
- (g_strcmp0(connection->tether_iface.ifname, rstn_data->ifname) != 0))
- return;
+ if (connection == NULL)
+ return;
+ }
/* classid is invalid */
if (rstn_data->classid <= STC_UNKNOWN_CLASSID)
if (rstn_data->limit_exceeded & (1 << i)) {
/* remove iptables rule */
- char *default_ifname = stc_default_connection_get_ifname();
+ GSList *conn_list = stc_get_connection_list();
struct nfacct_rule counter;
stc_s *stc = stc_get_manager();
if (stc == NULL) {
STC_LOGE("Can't get stc data");
- g_free(default_ifname);
goto try_next_callback;
}
if (!stc->carg) {
stc->carg = MALLOC0(counter_arg_s, 1);
if (stc->carg == NULL) {
- g_free(default_ifname);
goto try_next_callback;
}
stc->carg->sock = stc_monitor_get_contr_sock();
}
- memset(&counter, 0, sizeof(struct nfacct_rule));
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
- counter.carg = stc->carg;
- counter.classid = rstn_data->classid;
- counter.intend = NFACCT_BLOCK;
- counter.iftype = rstn_data->iftype;
- g_strlcpy(counter.ifname, default_ifname,
- MAX_IFACE_LENGTH);
+ memset(&counter, 0, sizeof(struct nfacct_rule));
- g_free(default_ifname);
+ counter.carg = stc->carg;
+ counter.classid = rstn_data->classid;
+ counter.intend = NFACCT_BLOCK;
+ counter.iftype = rstn_data->iftype;
+ g_strlcpy(counter.ifname, conn->ifname, MAX_IFACE_LENGTH);
- /* iptables rule */
- stc_monitor_ipt_del_in(&counter);
- stc_monitor_ipt_del_out(&counter);
+ /* iptables rule */
+ stc_monitor_ipt_del_in(&counter);
+ stc_monitor_ipt_del_out(&counter);
- /* ip6tables rule */
- stc_monitor_ip6t_del_in(&counter);
- stc_monitor_ip6t_del_out(&counter);
+ /* ip6tables rule */
+ stc_monitor_ip6t_del_in(&counter);
+ stc_monitor_ip6t_del_out(&counter);
- rstn_data->rstn_state = STC_RSTN_STATE_DEACTIVATED;
- rstn_data->limit_exceeded &= ~(1 << i);
- rstn_data->limit_notified &= ~(1 << i);
+ rstn_data->rstn_state = STC_RSTN_STATE_DEACTIVATED;
+ rstn_data->limit_exceeded &= ~(1 << i);
+ rstn_data->limit_notified &= ~(1 << i);
+ }
}
}
}
int i;
stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
classid_bytes_context_s *context = (classid_bytes_context_s *)user_data;
- default_connection_s *default_connection = stc_get_default_connection();
-
- if (rstn_data->iftype != context->counter->iftype)
- return;
+ GSList *conn_list = stc_get_connection_list();
- if (rstn_data->ifname != NULL &&
- g_strcmp0(rstn_data->ifname, "") &&
- g_strcmp0(rstn_data->ifname, context->counter->ifname) != 0)
- return;
+ for (; conn_list != NULL; conn_list = conn_list->next) {
+ stc_connection_s *conn = conn_list->data;
- if (rstn_data->subscriber_id != NULL &&
- g_strcmp0(rstn_data->subscriber_id, "") &&
- g_strcmp0(rstn_data->subscriber_id, default_connection->subscriber_id) != 0)
- return;
+ if (rstn_data->iftype != context->counter->iftype)
+ return;
- if (rstn_data->roaming != default_connection->roaming)
- return;
+ if (rstn_data->ifname != NULL &&
+ g_strcmp0(rstn_data->ifname, "") &&
+ g_strcmp0(rstn_data->ifname, context->counter->ifname) != 0)
+ return;
- if (rstn_data->limit_exceeded != 0) {
- context->data_limit_exceeded = TRUE;
- return;
- }
+ if (rstn_data->subscriber_id != NULL &&
+ g_strcmp0(rstn_data->subscriber_id, "") &&
+ g_strcmp0(rstn_data->subscriber_id, conn->subscriber_id) != 0)
+ return;
- switch (context->counter->iotype) {
- case NFACCT_COUNTER_IN:
- case NFACCT_COUNTER_OUT:
- if ((rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] == 0 &&
- rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA] >= 0) ||
- (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] == 0 &&
- rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] >= 0) ||
- (rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] == 0 &&
- rstn_data->limit[STC_RSTN_LIMIT_TYPE_MONTHLY] >= 0) ||
- (rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] == 0 &&
- rstn_data->limit[STC_RSTN_LIMIT_TYPE_WEEKLY] >= 0) ||
- (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] == 0 &&
- rstn_data->limit[STC_RSTN_LIMIT_TYPE_DAILY] >= 0)) {
- table_counters_info info;
- memset(&info, 0, sizeof(table_counters_info));
- table_counters_get(rstn_data->restriction_id, &info);
+ if (rstn_data->roaming != conn->roaming)
+ return;
- rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] = info.data_counter;
- rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info.warn_counter;
- rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] = info.monthly_counter;
- rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] = info.weekly_counter;
- rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] = info.daily_counter;
+ if (rstn_data->limit_exceeded != 0) {
+ context->data_limit_exceeded = TRUE;
+ return;
}
- for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
- if (rstn_data->limit[i] >= 0 &&
- !(rstn_data->limit_notified & (1 << i))) {
- rstn_data->counter[i] += context->bytes;
- if (rstn_data->limit[i] <= rstn_data->counter[i])
- stc_monitor_rstn_action_when_limit_exceeded(i,
- rstn_data,
- context);
+ switch (context->counter->iotype) {
+ case NFACCT_COUNTER_IN:
+ case NFACCT_COUNTER_OUT:
+ if ((rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] == 0 &&
+ rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA] >= 0) ||
+ (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] == 0 &&
+ rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] >= 0) ||
+ (rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] == 0 &&
+ rstn_data->limit[STC_RSTN_LIMIT_TYPE_MONTHLY] >= 0) ||
+ (rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] == 0 &&
+ rstn_data->limit[STC_RSTN_LIMIT_TYPE_WEEKLY] >= 0) ||
+ (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] == 0 &&
+ rstn_data->limit[STC_RSTN_LIMIT_TYPE_DAILY] >= 0)) {
+ table_counters_info info;
+ memset(&info, 0, sizeof(table_counters_info));
+ table_counters_get(rstn_data->restriction_id, &info);
+
+ rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] = info.data_counter;
+ rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info.warn_counter;
+ rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] = info.monthly_counter;
+ rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] = info.weekly_counter;
+ rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] = info.daily_counter;
}
- }
- stc_monitor_set_rstns_updated(TRUE);
- __print_rstn(rstn_data);
- break;
- default:
- STC_LOGE("Unknown iotype");
+ for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
+ if (rstn_data->limit[i] >= 0 &&
+ !(rstn_data->limit_notified & (1 << i))) {
+ rstn_data->counter[i] += context->bytes;
+ if (rstn_data->limit[i] <= rstn_data->counter[i])
+ stc_monitor_rstn_action_when_limit_exceeded(i,
+ rstn_data,
+ context);
+ }
+ }
+
+ stc_monitor_set_rstns_updated(TRUE);
+ __print_rstn(rstn_data);
+ break;
+ default:
+ STC_LOGE("Unknown iotype");
+ }
}
}
g_slist_foreach(lookup_value->rules, __rstn_add, NULL);
}
-void stc_monitor_rstn_add_by_connection(default_connection_s *conn)
+void stc_monitor_rstn_add_by_connection(stc_connection_s *conn)
{
GHashTable *rstns = stc_monitor_get_system_rstns();
g_slist_foreach(lookup_value->rules, __rstn_remove, NULL);
}
-void stc_monitor_rstn_remove_by_connection(default_connection_s *conn)
+void stc_monitor_rstn_remove_by_connection(stc_connection_s *conn)
{
GHashTable *rstns = stc_monitor_get_system_rstns();
#include <vconf.h>
#include <vconf-keys.h>
-#include "stc-default-connection.h"
+#include "stc-connection.h"
#include "helper-nl.h"
#include "helper-nfacct-rule.h"
#include "helper-net-cls.h"
return g_system->background_state;
}
-void stc_monitor_update_by_default_connection(void *data)
+void stc_monitor_update_by_connection(void *data)
{
- static default_connection_s old_connection;
- default_connection_s *new_connection = (default_connection_s *)data;
+ stc_connection_s *connection = (stc_connection_s *)data;
- if (old_connection.path != NULL) {
- stc_monitor_app_remove_by_connection(&old_connection);
- stc_monitor_rstn_remove_by_connection(&old_connection);
+ if (connection != NULL && connection->path != NULL) {
+ stc_monitor_app_remove_by_connection(connection);
+ stc_monitor_rstn_remove_by_connection(connection);
iptables_flush_chains();
+
+ stc_monitor_app_add_by_connection(connection);
+ stc_monitor_rstn_add_by_connection(connection);
}
+}
+
+void stc_monitor_add_by_connection(void *data)
+{
+ stc_connection_s *connection = (stc_connection_s *)data;
+
+ if (connection != NULL && connection->path != NULL) {
+ stc_monitor_app_add_by_connection(connection);
+ stc_monitor_rstn_add_by_connection(connection);
+ }
+}
+
+void stc_monitor_remove_by_connection(void *data)
+{
+ stc_connection_s *connection = (stc_connection_s *)data;
- FREE(old_connection.path);
- FREE(old_connection.ifname);
- FREE(old_connection.tether_iface.ifname);
- old_connection.type = 0;
- old_connection.roaming = 0;
- old_connection.tether_state = FALSE;
- old_connection.tether_iface.type = 0;
-
- if (new_connection != NULL && new_connection->path != NULL) {
- stc_monitor_app_add_by_connection(new_connection);
- stc_monitor_rstn_add_by_connection(new_connection);
-
- old_connection.path = g_strdup(new_connection->path);
- old_connection.ifname = g_strdup(new_connection->ifname);
- old_connection.tether_iface.ifname = g_strdup(new_connection->tether_iface.ifname);
- old_connection.type = new_connection->type;
- old_connection.roaming = new_connection->roaming;
- old_connection.tether_state = new_connection->tether_state;
- old_connection.tether_iface.type = new_connection->tether_iface.type;
+ if (connection != NULL && connection->path != NULL) {
+ stc_monitor_app_remove_by_connection(connection);
+ stc_monitor_rstn_remove_by_connection(connection);
}
}
#include "stc-statistics.h"
#include "stc-restriction.h"
#include "stc-firewall.h"
-#include "stc-default-connection.h"
+#include "stc-connection.h"
#include "stc-manager-util.h"
#include "stc-manager-plugin-appstatus.h"
#include "stc-manager-plugin-procfs.h"
stc->connection);
iptables_init();
- stc_default_connection_monitor_init(stc);
+ stc_connection_monitor_init(stc);
stc_plugin_appstatus_register_state_changed_cb(stc,
stc_plugin_procfs_app_status_changed, NULL);
stc_s *stc = (stc_s *)stc_data;
stc_plugin_appstatus_deregister_state_changed_cb(stc);
- stc_default_connection_monitor_deinit(stc);
+ stc_connection_monitor_deinit(stc);
g_bus_unown_name(stc->gdbus_owner_id);