+ int ret = 0;
+ DBG("Launch Wi-Fi direct daemon");
+
+ const char *path = "/usr/bin/wifi-direct-server.sh";
+ char *const args[] = { "wifi-direct-server.sh", "start", NULL };
+ char *const envs[] = { NULL };
+
+ ret = netconfig_execute_file(path, args, envs);
+ if (ret < 0) {
+ ERR("Failed to launch Wi-Fi direct daemon");
+ netconfig_error_wifi_direct_failed(context);
+ return TRUE;
+ }
+
+ wifi_complete_launch_direct(wifi, context);
+ return TRUE;
+}
+
+int execute_mdnsd_script(char* op)
+{
+ const char *path = "/usr/bin/mdnsresponder-server.sh";
+ char *const args[] = { "mdnsresponder-server.sh", op, NULL };
+ char *const envs[] = { NULL };
+
+ return netconfig_execute_file(path, args, envs);
+}
+
+static void __dnssd_conn_destroyed_cb(GDBusConnection *conn,
+ const gchar *Name, const gchar *path, const gchar *interface,
+ const gchar *sig, GVariant *param, gpointer user_data)
+{
+ gchar *name = NULL;
+ gchar *old = NULL;
+ gchar *new = NULL;
+ dnssd_conn_destroy_data *data = user_data;
+ GDBusConnection *connection = NULL;
+ connection = netdbus_get_connection();
+
+ if (param == NULL)
+ return;
+
+ g_variant_get(param, "(sss)", &name, &old, &new);
+
+ if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') {
+ DBG("Connection %s Destroyed: name %s id %d", data->conn_name, name,
+ data->conn_id);
+ mdnsd_ref_count--;
+ g_dbus_connection_signal_unsubscribe(connection, data->conn_id);
+ if (mdnsd_ref_count == 0) {
+ if (execute_mdnsd_script("stop") < 0)
+ ERR("Failed to stop mdnsresponder daemon");
+ }
+ }
+ g_free(name);
+ g_free(old);
+ g_free(new);
+ g_free(data->conn_name);
+ g_free(data);
+ return;
+}
+
+static void register_dnssd_conn_destroy_signal(gchar *name)
+{
+ dnssd_conn_destroy_data *data;
+ GDBusConnection *connection = NULL;
+ connection = netdbus_get_connection();
+
+ if (connection == NULL) {
+ ERR("Failed to get GDbus Connection");
+ return;
+ }
+
+ data = g_try_malloc0(sizeof(dnssd_conn_destroy_data));
+
+ if (data == NULL) {
+ ERR("Out of Memory!");
+ return;
+ }
+
+ data->conn_name = g_strdup(name);
+
+ data->conn_id = g_dbus_connection_signal_subscribe(connection,
+ DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS,
+ "NameOwnerChanged", NULL, name,
+ G_DBUS_SIGNAL_FLAGS_NONE, __dnssd_conn_destroyed_cb,
+ data, NULL);
+ return;
+}
+
+gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context,
+ gchar *name)
+{
+ DBG("Launch mdnsresponder daemon");
+
+ if (execute_mdnsd_script("start") < 0) {
+ ERR("Failed to launch mdnsresponder daemon");
+ netconfig_error_invalid_parameter(context);
+ return TRUE;
+ }
+
+ mdnsd_ref_count++;
+ register_dnssd_conn_destroy_signal(name);
+ DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
+
+ network_complete_launch_mdns(object, context);
+ return TRUE;
+}
+
+gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
+{
+ if (!netconfig_plugin_headed_enabled)
+ return FALSE;
+
+ if (!headed_plugin)
+ return FALSE;
+
+ return headed_plugin->send_notification_to_net_popup(noti, ssid);
+}
+
+int netconfig_send_message_to_net_popup(const char *title,
+ const char *content, const char *type, const char *ssid)
+{
+ if (!netconfig_plugin_headed_enabled)
+ return 0;
+
+ if (!headed_plugin)
+ return 0;
+
+ return headed_plugin->send_message_to_net_popup(title, content, type, ssid);
+}
+
+int netconfig_send_restriction_to_net_popup(const char *title,
+ const char *type, const char *restriction)
+{
+ if (!netconfig_plugin_headed_enabled)
+ return 0;
+
+ if (!headed_plugin)
+ return 0;
+
+ return headed_plugin->send_restriction_to_net_popup(title, type, restriction);
+}
+
+void netconfig_set_system_event(int sys_evt, int evt_key, int evt_val)
+{
+ if (!netconfig_plugin_headed_enabled)
+ return;
+
+ if (!headed_plugin)
+ return;
+
+ headed_plugin->set_system_event(sys_evt, evt_key, evt_val);
+}
+
+void __netconfig_pop_wifi_connected_poppup(const char *ssid)
+{
+ if (!netconfig_plugin_headed_enabled)
+ return;
+
+ if (!headed_plugin)
+ return;
+
+ headed_plugin->pop_wifi_connected_poppup(ssid);
+}
+
+void netconfig_get_telephony_network_type(int *svctype, int *pstype)
+{
+ if (!netconfig_plugin_telephony_enabled)
+ return;
+
+ if (!telephony_plugin)
+ return;
+
+ telephony_plugin->get_telephony_network_type(svctype, pstype);
+}
+
+gboolean __netconfig_wifi_get_sim_imsi(Wifi *wifi, GDBusMethodInvocation *context)
+{
+ if (!netconfig_plugin_telephony_enabled)
+ return FALSE;
+
+ if (!telephony_plugin)
+ return FALSE;
+
+ return telephony_plugin->wifi_get_sim_imsi(wifi, context);
+}
+
+netconfig_error_e __netconfig_wifi_req_aka_auth(GArray *rand_data, GArray *autn_data,
+ GDBusMethodInvocation *context, struct wifi_authentication_data **data)
+{
+ if (!netconfig_plugin_telephony_enabled)
+ return NETCONFIG_ERROR_INTERNAL;
+
+ if (!telephony_plugin)
+ return NETCONFIG_ERROR_INTERNAL;
+
+ return telephony_plugin->wifi_req_aka_auth(rand_data, autn_data, context, data);
+}
+
+gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data,
+ GDBusMethodInvocation *context, struct wifi_authentication_data **data)
+{
+ if (!netconfig_plugin_telephony_enabled)
+ return FALSE;
+
+ if (!telephony_plugin)
+ return FALSE;
+
+ return telephony_plugin->wifi_req_sim_auth(rand_data, context, data);
+}
+
+gboolean netconfig_tapi_check_sim_state(void)
+{
+ if (!netconfig_plugin_telephony_enabled)
+ return FALSE;
+
+ if (!telephony_plugin)
+ return FALSE;
+
+ return telephony_plugin->tapi_check_sim_state();
+}
+
+gboolean __netconfig_wifi_get_aka_authdata(Wifi *wifi,
+ GDBusMethodInvocation *context, struct wifi_authentication_data **data)
+{
+ if (!netconfig_plugin_telephony_enabled)
+ return FALSE;
+
+ if (!telephony_plugin)
+ return FALSE;
+
+ return telephony_plugin->wifi_get_aka_authdata(wifi, context, data);
+}
+
+gboolean __netconfig_wifi_get_sim_authdata(Wifi *wifi,
+ GDBusMethodInvocation *context, struct wifi_authentication_data **data)
+{
+ if (!netconfig_plugin_telephony_enabled)
+ return FALSE;
+
+ if (!telephony_plugin)
+ return FALSE;
+
+ return telephony_plugin->wifi_get_sim_authdata(wifi, context, data);
+}
+
+void netconfig_set_vconf_int(const char * key, int value)
+{
+ int ret = 0;
+
+ DBG("[%s: %d]", key, value);
+
+ ret = vconf_set_int(key, value);
+ if (ret != VCONF_OK)
+ ERR("Failed to set");
+}
+
+void netconfig_set_vconf_str(const char * key, const char * value)
+{
+ int ret = 0;
+
+ DBG("[%s: %s]", key, value);
+
+ ret = vconf_set_str(key, value);
+ if (ret != VCONF_OK)
+ ERR("Failed to set");
+}
+
+int netconfig_vconf_get_int(const char * key, int *value)
+{
+ int ret = 0;
+
+ ret = vconf_get_int(key, value);
+ if (ret != VCONF_OK) {
+ ERR("Failed to get vconfkey [%s] value", key);
+ return -1;
+ }
+
+ return 0;
+}
+
+int netconfig_vconf_get_bool(const char * key, int *value)
+{
+ int ret = 0;
+
+ ret = vconf_get_bool(key, value);
+ if (ret != VCONF_OK) {
+ ERR("Failed to get vconfkey [%s] value", key);
+ return -1;
+ }
+
+ return 0;
+}
+
+char* netconfig_get_env(const char *key)
+{
+ FILE *fp;
+ char buf[256], *entry = NULL, *value = NULL, *last;
+ int len = 0;
+
+ if (!key)
+ return NULL;
+
+ fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
+ if (!fp)
+ return NULL;
+
+ while (fgets(buf, sizeof(buf), fp)) {
+ entry = buf;
+ entry = strtok_r(entry, "=", &last);
+ if (entry) {
+ if (strstr(entry, key)) {
+ entry = strtok_r(NULL, "\n", &last);
+ if (entry) {
+ len = strlen(entry);
+ value = (char*)malloc(len+1);
+ g_strlcpy(value, entry, len+1);
+ } else {
+ value = (char*)malloc(sizeof(char));
+ g_strlcpy(value, "\n", sizeof(char));
+ }
+ break;
+ }
+ }
+ }
+
+ fclose(fp);
+ return value;
+}
+
+void netconfig_set_mac_address_from_file(void)
+{
+ FILE *file = NULL;
+ char mac_str[MAC_ADDRESS_MAX_LEN];
+ gchar *mac_lower_str = NULL;
+ int mac_len = 0;
+
+ file = fopen(MAC_INFO_FILEPATH, "r");
+ if (file == NULL) {
+ ERR("Fail to open %s", MAC_INFO_FILEPATH);
+ file = fopen(MAC_ADDRESS_FILEPATH, "r");
+ if (file == NULL) {
+ ERR("Fail to open %s", MAC_ADDRESS_FILEPATH);
+ return;
+ }
+ }
+ if (fgets(mac_str, sizeof(mac_str), file) == NULL) {
+ ERR("Fail to read mac address");
+ fclose(file);
+ return;
+ }
+
+ mac_len = strlen(mac_str);
+ if (mac_len < 17) {
+ ERR("mac.info is empty");
+ fclose(file);
+ return;
+ }
+
+ mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
+ netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
+
+ g_free(mac_lower_str);
+ fclose(file);
+}
+
+tizen_profile_t _get_tizen_profile()
+{
+ static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
+ if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+ return profile;
+
+ char *profileName;
+ system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
+ switch (*profileName) {
+ case 'm':
+ case 'M':
+ profile = TIZEN_PROFILE_MOBILE;
+ break;
+ case 'w':
+ case 'W':
+ profile = TIZEN_PROFILE_WEARABLE;
+ break;
+ case 't':
+ case 'T':
+ profile = TIZEN_PROFILE_TV;
+ break;
+ case 'i':
+ case 'I':
+ profile = TIZEN_PROFILE_IVI;
+ break;
+ default: // common or unknown ==> ALL ARE COMMON.
+ profile = TIZEN_PROFILE_COMMON;
+ }
+ free(profileName);
+
+ return profile;
+}
+
+void netconfig_plugin_init()
+{
+ handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW);
+ if (!handle_headed) {
+ ERR("Can't load %s: %s", HEADED_PLUGIN_FILEPATH, dlerror());
+ } else {
+ headed_plugin = dlsym(handle_headed, "netconfig_headed_plugin");
+ if (!headed_plugin) {
+ ERR("Can't load symbol: %s", dlerror());
+ dlclose(handle_headed);
+ } else {
+ netconfig_plugin_headed_enabled = TRUE;
+ }
+ }
+
+ handle_telephony = dlopen(TELEPHONY_PLUGIN_FILEPATH, RTLD_NOW);
+ if (!handle_telephony) {
+ ERR("Can't load %s: %s", TELEPHONY_PLUGIN_FILEPATH, dlerror());
+ } else {
+ telephony_plugin = dlsym(handle_telephony, "netconfig_telephony_plugin");
+ if (!telephony_plugin) {
+ ERR("Can't load symbol: %s", dlerror());
+ dlclose(handle_telephony);
+ } else {
+ netconfig_plugin_telephony_enabled = TRUE;
+ }
+ }
+}
+
+void netconfig_plugin_deinit()
+{
+ if (netconfig_plugin_headed_enabled) {
+ netconfig_plugin_headed_enabled = FALSE;
+ dlclose(handle_headed);
+ }
+
+ if (netconfig_plugin_telephony_enabled) {
+ netconfig_plugin_telephony_enabled = FALSE;
+ dlclose(handle_telephony);
+ }
+}
+
+gboolean netconfig_get_headed_plugin_flag()
+{
+ return netconfig_plugin_headed_enabled;
+}
+
+gboolean netconfig_get_telephony_plugin_flag()
+{
+ return netconfig_plugin_telephony_enabled;
+}
+
+bool netconfig_check_feature_supported(netconfig_supported_feature_e feature)
+{
+ const char *key = NULL;
+
+ if (!is_feature_checked[feature]) {
+ switch (feature) {
+ case NETCONFIG_SUPPORTED_FEATURE_ETHERNET:
+ key = ETHERNET_FEATURE;
+ break;
+ case NETCONFIG_SUPPORTED_FEATURE_TETHERING:
+ key = TETHERING_FEATURE;
+ break;
+ case NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT:
+ key = WIFI_DIRECT_FEATURE;
+ break;
+ case NETCONFIG_SUPPORTED_FEATURE_WIFI_SOFTAP:
+ key = WIFI_SOFTAP_FEATURE;
+ break;
+ default:
+ ERR("Uknown feature");
+ return false;
+ }
+
+ if (system_info_get_platform_bool(key, &feature_supported[feature]) < 0) {
+ ERR("Get feature is failed");
+ return false;
+ }
+ is_feature_checked[feature] = true;