*/
#include <vconf/vconf.h>
+#include <openssl/sha.h>
#include "stc-monitor.h"
+#include "stc-firewall.h"
#include "stc-manager-gdbus.h"
#include "stc-default-connection.h"
int current_sim = 0;
if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT_COUNT, &sim_slot_count) != 0) {
- STC_LOGD("failed to get sim slot count");
- return -1;
+ STC_LOGD("failed to get sim slot count"); //LCOV_EXCL_LINE
+ return -1; //LCOV_EXCL_LINE
}
if (sim_slot_count == SIM_SLOT_SINGLE) {
- STC_LOGD("It's single sim model");
- return current_sim;
+ STC_LOGD("It's single sim model"); //LCOV_EXCL_LINE
+ return current_sim; //LCOV_EXCL_LINE
}
if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, ¤t_sim) != 0) {
- STC_LOGD("failed to get default data service = %d\n",
+ STC_LOGD("failed to get default data service = %d\n", //LCOV_EXCL_LINE
current_sim);
- return -1;
+ return -1; //LCOV_EXCL_LINE
}
return current_sim;
}
-static void __telephony_get_modem_imsi(GDBusConnection *connection,
+static void __make_imsi_to_subscriber_id(char *imsi)
+{
+ int i = 0;
+ SHA256_CTX ctx;
+ unsigned char md[SHA256_DIGEST_LENGTH];
+
+ SHA256_Init(&ctx);
+ SHA256_Update(&ctx, imsi, strlen(imsi));
+ SHA256_Final(md, &ctx);
+
+ for (i = 0; i < SHA256_DIGEST_LENGTH; ++i)
+ snprintf(g_default_connection.subscriber_id + (i * 2), 3, "%02x", md[i]);
+}
+
+static void __telephony_get_modem_subscriber_id(GDBusConnection *connection,
const char *default_modem_name)
{
GVariant *message = NULL;
char tel_path[MAX_PATH_LENGTH];
+ char imsi[IMSI_LENGTH];
const char *plmn = NULL;
int plmn_len = 0;
const char *msin = NULL;
TELEPHONY_GET_IMSI,
NULL);
if (message == NULL) {
- STC_LOGE("Failed to get services informations");
- goto done;
+ STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
DEBUG_PARAMS(message);
DEBUG_PARAM_TYPE(message);
g_variant_get(message, "(&s&s)", &plmn, &msin);
- plmn_len = strlen(plmn);
- msin_len = strlen(msin);
+ if (plmn)
+ plmn_len = strlen(plmn);
+ if (msin)
+ msin_len = strlen(msin);
if (msin_len + plmn_len >= IMSI_LENGTH) {
- STC_LOGD("Incorrect length of mobile subscriber identifier + net id");
- goto done;
+ STC_LOGD("Incorrect length of mobile subscriber identifier + net id"); //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
- snprintf(g_default_connection.imsi, IMSI_LENGTH, "%s%s", plmn, msin);
+ snprintf(imsi, IMSI_LENGTH, "%s%s", plmn, msin);
+ __make_imsi_to_subscriber_id(imsi);
done:
g_variant_unref(message);
return;
}
-static void __telephony_update_default_modem_imsi(GDBusConnection *connection)
+static void __telephony_update_default_modem_subscriber_id(GDBusConnection *connection)
{
GVariant *message = NULL;
GVariantIter *iter = NULL;
int current_sim = __telephony_get_current_sim();
if (current_sim < 0) {
- STC_LOGI("Sim not found");
- return;
+ STC_LOGI("Sim not found"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
message = stc_manager_gdbus_call_sync(connection,
TELEPHONY_GET_MODEMS,
NULL);
if (message == NULL) {
- STC_LOGE("Failed to get services informations");
- return;
+ STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
g_variant_get(message, "(as)", &iter);
FREE(modem_name);
break;
}
- current_sim--;
+ current_sim--; //LCOV_EXCL_LINE
}
- __telephony_get_modem_imsi(connection, default_modem_name);
+ __telephony_get_modem_subscriber_id(connection, default_modem_name);
FREE(default_modem_name);
g_variant_iter_free(iter);
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("imsi [%s]", g_default_connection.imsi);
+ STC_LOGI("sub_id [%s]", g_default_connection.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("====================================================");
+}
+
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)
if (profile == NULL)
return FALSE;
- return g_str_has_prefix(profile,
+ return g_str_has_prefix(profile, //LCOV_EXCL_LINE
CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX);
}
if (profile == NULL)
return FALSE;
- return g_str_has_prefix(profile, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX);
+ return g_str_has_prefix(profile, //LCOV_EXCL_LINE
+ CONNMAN_WIFI_SERVICE_PROFILE_PREFIX);
}
static gboolean __is_ethernet_profile(const char *profile)
if (profile == NULL)
return FALSE;
- return g_str_has_prefix(profile,
+ return g_str_has_prefix(profile, //LCOV_EXCL_LINE
CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX);
}
if (profile == NULL)
return FALSE;
- return g_str_has_prefix(profile,
+ return g_str_has_prefix(profile, //LCOV_EXCL_LINE
CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX);
}
CONNMAN_SERVICE_INTERFACE,
"GetProperties", NULL);
if (message == NULL) {
- STC_LOGE("Failed to get services informations");
- goto done;
+ STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
g_variant_get(message, "(a{sv})", &iter);
if (iter == NULL) {
- STC_LOGE("Profile %s doesn't exist", object_path);
- goto done;
+ STC_LOGE("Profile %s doesn't exist", object_path); //LCOV_EXCL_LINE
+ goto done; //LCOV_EXCL_LINE
}
while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
g_variant_get(variant, "a{sv}", &iter1);
if (iter1 == NULL)
- continue;
+ continue; //LCOV_EXCL_LINE
while (g_variant_iter_loop(iter1, "{sv}", &key1,
&variant1)) {
CONNMAN_MANAGER_INTERFACE,
"GetServices", NULL);
if (message == NULL) {
- STC_LOGE("Failed to get profiles");
- return STC_ERROR_FAIL;
+ STC_LOGE("Failed to get profiles"); //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
g_variant_get(message, "(a(oa{sv}))", &iter);
while (g_variant_iter_loop(iter, "(oa{sv})", &object_path, &next)) {
if (object_path == NULL)
- continue;
+ continue; //LCOV_EXCL_LINE
if (__is_cellular_profile(object_path) &&
!__is_cellular_internet_profile(object_path))
g_variant_unref(message);
if (__is_cellular_profile(g_default_connection.path)) {
- g_default_connection.type = STC_IFACE_DATACALL;
- __telephony_update_default_modem_imsi(connection);
+ 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;
+ 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;
+ 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;
+ g_default_connection.type = STC_IFACE_BLUETOOTH; //LCOV_EXCL_LINE
} else {
- g_default_connection.type = STC_IFACE_UNKNOWN;
+ 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_rstn_by_default_connection(&g_default_connection);
+ stc_monitor_update_by_default_connection(&g_default_connection);
+ stc_firewall_update();
return STC_ERROR_NONE;
}
}
} else {
if (g_strcmp0(g_default_connection.path, path) == 0) {
- __reset_default_connection_data();
- __get_default_profile(stc->connection);
+ __reset_default_connection_data(); //LCOV_EXCL_LINE
+ __get_default_profile(stc->connection); //LCOV_EXCL_LINE
}
}
} else if (g_strcmp0(sigvalue, "Roaming") == 0) {
+ //LCOV_EXCL_START
if (g_strcmp0(g_default_connection.path, path) == 0) {
gboolean roaming = 0;
g_default_connection.roaming = roaming;
}
}
+ //LCOV_EXCL_STOP
} else {
;//Do nothing
}
return;
}
+static void __vconf_key_callback(keynode_t *node, void *user_data)
+{
+ int vconf_key;
+
+ if (node == NULL) {
+ STC_LOGE("Invalid parameter");
+ return;
+ }
+
+ if (vconf_keynode_get_type(node) != VCONF_TYPE_INT) {
+ STC_LOGE("Invalid vconf key type");
+ return;
+ }
+
+ vconf_key = vconf_keynode_get_int(node);
+
+ /* Check the tethering type */
+ 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;
+ 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;
+ 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;
+ 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;
+ break;
+ case VCONFKEY_MOBILE_HOTSPOT_MODE_NONE:
+ STC_LOGI("Hotspot mode none");
+ g_default_connection.tether_state = FALSE;
+ break;
+ default:
+ STC_LOGE("Unknown Hotspot mode type !");
+ break;
+ }
+
+ /* add monitoring for tethering if active found */
+ 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_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;
+ STC_LOGI("Data monitoring stopped for tethering iface !");
+ return;
+ }
+}
+
stc_error_e stc_default_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);
_service_signal_cb,
NULL, NULL);
+ ret = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, __vconf_key_callback, NULL);
+ if (ret < 0)
+ STC_LOGE("vconf_notify_key_changed failed: %d", ret);
+
STC_LOGI("Successfully subscribed connman [%s] signal", CONNMAN_SIGNAL_PROPERTY_CHANGED);
return STC_ERROR_NONE;
}