Revert "Added support to add ipv6 route using netlink."
[platform/core/connectivity/net-config.git] / src / utils / util.c
index bec7fc2..27c2238 100755 (executable)
@@ -63,6 +63,9 @@ static void *handle_telephony;
 static struct netconfig_headed_plugin_t *headed_plugin;
 static struct netconfig_telephony_plugin_t *telephony_plugin;
 
+static bool is_feature_checked[NETCONFIG_SUPPORTED_FEATURE_MAX] = {0, };
+static bool feature_supported[NETCONFIG_SUPPORTED_FEATURE_MAX] = {0, };
+
 gboolean netconfig_check_passphrase(const gchar *service, const char *passphrase)
 {
        gsize length;
@@ -317,7 +320,7 @@ void netconfig_wifi_device_picker_service_stop(void)
 
 gboolean netconfig_is_wifi_direct_on(void)
 {
-       if (!netconfig_check_feature_supported(WIFI_DIRECT_FEATURE))
+       if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT))
                return FALSE;
 
        int wifi_direct_state = 0;
@@ -330,7 +333,7 @@ gboolean netconfig_is_wifi_direct_on(void)
 
 gboolean netconfig_is_wifi_tethering_on(void)
 {
-       if (netconfig_check_feature_supported(TETHERING_FEATURE)) {
+       if (netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_TETHERING)) {
                int wifi_tethering_state = 0;
 
                netconfig_vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
@@ -579,6 +582,7 @@ int netconfig_execute_file_no_wait(const char *file_path, char *const args[])
 
        struct sigaction act;
        int state = 0;
+       char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
 
        act.sa_handler = no_wait_signal_handler;
        sigemptyset(&act.sa_mask);
@@ -601,7 +605,8 @@ int netconfig_execute_file_no_wait(const char *file_path, char *const args[])
 
                errno = 0;
                if (execvp(file_path, args) == -1) {
-                       ERR("Fail to execute command (%s)", strerror(errno));
+                       ERR("Fail to execute command (%s)",
+                               strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
                        return -1;
                }
        } else if (pid > 0) {
@@ -609,7 +614,8 @@ int netconfig_execute_file_no_wait(const char *file_path, char *const args[])
                return rv;
        }
 
-       DBG("failed to fork(%s)", strerror(errno));
+       DBG("failed to fork(%s)",
+               strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
        return -EIO;
 }
 
@@ -870,9 +876,9 @@ int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, u
 
 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
 {
-       if (!netconfig_check_feature_supported(WIFI_DIRECT_FEATURE)) {
+       if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT)) {
                wifi_complete_launch_direct(wifi, context);
-               return FALSE;
+               return TRUE;
        }
 
        int ret = 0;
@@ -886,7 +892,7 @@ gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
        if (ret < 0) {
                ERR("Failed to launch Wi-Fi direct daemon");
                netconfig_error_wifi_direct_failed(context);
-               return FALSE;
+               return TRUE;
        }
 
        wifi_complete_launch_direct(wifi, context);
@@ -972,7 +978,7 @@ gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context,
        if (execute_mdnsd_script("start") < 0) {
                ERR("Failed to launch mdnsresponder daemon");
                netconfig_error_invalid_parameter(context);
-               return FALSE;
+               return TRUE;
        }
 
        mdnsd_ref_count++;
@@ -1274,22 +1280,6 @@ tizen_profile_t _get_tizen_profile()
        return profile;
 }
 
-bool netconfig_check_feature_supported(const char *feature)
-{
-       bool is_supported = false;
-
-       if (!system_info_get_platform_bool(feature, &is_supported)) {
-               if (is_supported != TRUE)
-                       DBG("%s is not supported", feature);
-               else
-                       DBG("%s is supported", feature);
-       } else {
-               ERR("Error - Feature getting from System Info");
-       }
-
-       return is_supported;
-}
-
 void netconfig_plugin_init()
 {
        handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW);
@@ -1342,3 +1332,34 @@ 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;
+       }
+       return feature_supported[feature];
+}