Merge tag 'upstream/1.40' into tizen.
[platform/upstream/connman.git] / src / main.c
index 34d572d..13e26d4 100755 (executable)
 #define DEFAULT_INPUT_REQUEST_TIMEOUT (120 * 1000)
 #define DEFAULT_BROWSER_LAUNCH_TIMEOUT (300 * 1000)
 
+/*
+ * We set the integer to 1 sec so that we have a chance to get
+ * necessary IPv6 router advertisement messages that might have
+ * DNS data etc.
+ */
+#define DEFAULT_ONLINE_CHECK_INITIAL_INTERVAL 1
+#define DEFAULT_ONLINE_CHECK_MAX_INTERVAL 12
+
 #if defined TIZEN_EXT
 #define DEFAULT_WIFI_INTERFACE "wlan0"
+#define CONTAINER_FILE "/run/systemd/container"
 #endif
 
 #define MAINFILE "main.conf"
@@ -94,6 +103,9 @@ static struct {
        bool enable_6to4;
        char *vendor_class_id;
        bool enable_online_check;
+       bool enable_online_to_ready_transition;
+       unsigned int online_check_initial_interval;
+       unsigned int online_check_max_interval;
        bool auto_connect_roaming_services;
        bool acd;
        bool use_gateways_as_timeservers;
@@ -107,6 +119,8 @@ static struct {
        bool file_log;
        bool dlog_log;
        bool simple_log;
+       bool wifi_roam_scan;
+       bool wifi_roam;
 #endif
 } connman_settings  = {
        .bg_scan = true,
@@ -127,6 +141,9 @@ static struct {
        .enable_6to4 = false,
        .vendor_class_id = NULL,
        .enable_online_check = true,
+       .enable_online_to_ready_transition = false,
+       .online_check_initial_interval = DEFAULT_ONLINE_CHECK_INITIAL_INTERVAL,
+       .online_check_max_interval = DEFAULT_ONLINE_CHECK_MAX_INTERVAL,
        .auto_connect_roaming_services = false,
        .acd = false,
        .use_gateways_as_timeservers = false,
@@ -140,6 +157,8 @@ static struct {
        .file_log = true,
        .dlog_log = true,
        .simple_log = true,
+       .wifi_roam_scan = false,
+       .wifi_roam = false,
 #endif
 };
 
@@ -217,6 +236,9 @@ static struct {
 #define CONF_ENABLE_6TO4                "Enable6to4"
 #define CONF_VENDOR_CLASS_ID            "VendorClassID"
 #define CONF_ENABLE_ONLINE_CHECK        "EnableOnlineCheck"
+#define CONF_ENABLE_ONLINE_TO_READY_TRANSITION "EnableOnlineToReadyTransition"
+#define CONF_ONLINE_CHECK_INITIAL_INTERVAL "OnlineCheckInitialInterval"
+#define CONF_ONLINE_CHECK_MAX_INTERVAL     "OnlineCheckMaxInterval"
 #define CONF_AUTO_CONNECT_ROAMING_SERVICES "AutoConnectRoamingServices"
 #define CONF_ACD                        "AddressConflictDetection"
 #define CONF_USE_GATEWAYS_AS_TIMESERVERS "UseGatewaysAsTimeservers"
@@ -230,6 +252,8 @@ static struct {
 #define CONF_CONNMAN_FILE_LOG           "FileLogging"
 #define CONF_CONNMAN_DLOG_LOG           "DlogLogging"
 #define CONF_CONNMAN_SIMPLIFIED_LOG     "SimplifiedLog"
+#define CONF_CONNMAN_WIFI_ROAM_SCAN     "WifiRoamingScan"
+#define CONF_CONNMAN_WIFI_ROAM          "WifiRoaming"
 #endif
 
 #if defined TIZEN_EXT
@@ -264,6 +288,7 @@ static const char *supported_options[] = {
        CONF_BG_SCAN,
        CONF_PREF_TIMESERVERS,
        CONF_AUTO_CONNECT_TECHS,
+       CONF_FAVORITE_TECHS,
        CONF_ALWAYS_CONNECTED_TECHS,
        CONF_PREFERRED_TECHS,
        CONF_FALLBACK_NAMESERVERS,
@@ -278,6 +303,9 @@ static const char *supported_options[] = {
        CONF_ENABLE_6TO4,
        CONF_VENDOR_CLASS_ID,
        CONF_ENABLE_ONLINE_CHECK,
+       CONF_ENABLE_ONLINE_TO_READY_TRANSITION,
+       CONF_ONLINE_CHECK_INITIAL_INTERVAL,
+       CONF_ONLINE_CHECK_MAX_INTERVAL,
        CONF_AUTO_CONNECT_ROAMING_SERVICES,
        CONF_ACD,
        CONF_USE_GATEWAYS_AS_TIMESERVERS,
@@ -291,6 +319,8 @@ static const char *supported_options[] = {
        CONF_CONNMAN_FILE_LOG,
        CONF_CONNMAN_DLOG_LOG,
        CONF_CONNMAN_SIMPLIFIED_LOG,
+       CONF_CONNMAN_WIFI_ROAM_SCAN,
+       CONF_CONNMAN_WIFI_ROAM,
 #endif
        NULL
 };
@@ -697,6 +727,16 @@ static void check_Tizen_configuration(GKeyFile *config)
        if (!error)
                connman_settings.simple_log = boolean;
 
+       boolean = __connman_config_get_bool(config, "General",
+                       CONF_CONNMAN_WIFI_ROAM_SCAN, &error);
+       if (!error)
+               connman_settings.wifi_roam_scan = boolean;
+
+       boolean = __connman_config_get_bool(config, "General",
+                       CONF_CONNMAN_WIFI_ROAM, &error);
+       if (!error)
+               connman_settings.wifi_roam = boolean;
+
        g_clear_error(&error);
 
        check_Tizen_INS_configuration(config);
@@ -726,9 +766,9 @@ static void parse_config(GKeyFile *config)
        char **interfaces;
        char **str_list;
        char **tethering;
-        char *vendor_class_id;
+       char *string;
        gsize len;
-       int timeout;
+       int integer;
 
        if (!config) {
                connman_settings.auto_connect =
@@ -766,6 +806,8 @@ static void parse_config(GKeyFile *config)
                connman_settings.auto_connect =
                        parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
 
+       g_strfreev(str_list);
+
        g_clear_error(&error);
 
        str_list = __connman_config_get_string_list(config, "General",
@@ -815,17 +857,17 @@ static void parse_config(GKeyFile *config)
 
        g_clear_error(&error);
 
-       timeout = g_key_file_get_integer(config, "General",
+       integer = g_key_file_get_integer(config, "General",
                        CONF_TIMEOUT_INPUTREQ, &error);
-       if (!error && timeout >= 0)
-               connman_settings.timeout_inputreq = timeout * 1000;
+       if (!error && integer >= 0)
+               connman_settings.timeout_inputreq = integer * 1000;
 
        g_clear_error(&error);
 
-       timeout = g_key_file_get_integer(config, "General",
+       integer = g_key_file_get_integer(config, "General",
                        CONF_TIMEOUT_BROWSERLAUNCH, &error);
-       if (!error && timeout >= 0)
-               connman_settings.timeout_browserlaunch = timeout * 1000;
+       if (!error && integer >= 0)
+               connman_settings.timeout_browserlaunch = integer * 1000;
 
        g_clear_error(&error);
 
@@ -886,10 +928,10 @@ static void parse_config(GKeyFile *config)
 
        g_clear_error(&error);
 
-       vendor_class_id = __connman_config_get_string(config, "General",
+       string = __connman_config_get_string(config, "General",
                                        CONF_VENDOR_CLASS_ID, &error);
        if (!error)
-               connman_settings.vendor_class_id = vendor_class_id;
+               connman_settings.vendor_class_id = string;
 
        g_clear_error(&error);
 
@@ -904,6 +946,40 @@ static void parse_config(GKeyFile *config)
        g_clear_error(&error);
 
        boolean = __connman_config_get_bool(config, "General",
+                       CONF_ENABLE_ONLINE_TO_READY_TRANSITION, &error);
+       if (!error) {
+               connman_settings.enable_online_to_ready_transition = boolean;
+       }
+
+       g_clear_error(&error);
+
+       integer = g_key_file_get_integer(config, "General",
+                       CONF_ONLINE_CHECK_INITIAL_INTERVAL, &error);
+       if (!error && integer >= 0)
+               connman_settings.online_check_initial_interval = integer;
+
+       g_clear_error(&error);
+
+       integer = g_key_file_get_integer(config, "General",
+                       CONF_ONLINE_CHECK_MAX_INTERVAL, &error);
+       if (!error && integer >= 0)
+               connman_settings.online_check_max_interval = integer;
+
+       g_clear_error(&error);
+
+       if (connman_settings.online_check_initial_interval < 1 ||
+               connman_settings.online_check_initial_interval >
+               connman_settings.online_check_max_interval) {
+               connman_warn("Incorrect online check intervals [%u, %u]",
+                               connman_settings.online_check_initial_interval,
+                               connman_settings.online_check_max_interval);
+               connman_settings.online_check_initial_interval =
+                       DEFAULT_ONLINE_CHECK_INITIAL_INTERVAL;
+               connman_settings.online_check_max_interval =
+                       DEFAULT_ONLINE_CHECK_MAX_INTERVAL;
+       }
+
+       boolean = __connman_config_get_bool(config, "General",
                                CONF_AUTO_CONNECT_ROAMING_SERVICES, &error);
        if (!error)
                connman_settings.auto_connect_roaming_services = boolean;
@@ -1106,7 +1182,7 @@ static GOptionEntry options[] = {
        { NULL },
 };
 
-const char *connman_option_get_string(const char *key)
+char *connman_setting_get_string(const char *key)
 {
        if (g_str_equal(key, CONF_VENDOR_CLASS_ID))
                return connman_settings.vendor_class_id;
@@ -1157,6 +1233,9 @@ bool connman_setting_get_bool(const char *key)
        if (g_str_equal(key, CONF_ENABLE_ONLINE_CHECK))
                return connman_settings.enable_online_check;
 
+       if (g_str_equal(key, CONF_ENABLE_ONLINE_TO_READY_TRANSITION))
+               return connman_settings.enable_online_to_ready_transition;
+
        if (g_str_equal(key, CONF_AUTO_CONNECT_ROAMING_SERVICES))
                return connman_settings.auto_connect_roaming_services;
 
@@ -1181,9 +1260,13 @@ bool connman_setting_get_bool(const char *key)
 
        if (g_str_equal(key, CONF_CONNMAN_SIMPLIFIED_LOG))
                return connman_settings.simple_log;
-#endif
 
-#if defined TIZEN_EXT
+       if (g_str_equal(key, CONF_CONNMAN_WIFI_ROAM_SCAN))
+               return connman_settings.wifi_roam_scan;
+
+       if (g_str_equal(key, CONF_CONNMAN_WIFI_ROAM))
+               return connman_settings.wifi_roam;
+
        if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID))
                return connman_ins_settings.ins_last_connected_bssid;
 
@@ -1209,9 +1292,15 @@ bool connman_setting_get_bool(const char *key)
        return false;
 }
 
-#if defined TIZEN_EXT
 unsigned int connman_setting_get_uint(const char *key)
 {
+       if (g_str_equal(key, CONF_ONLINE_CHECK_INITIAL_INTERVAL))
+               return connman_settings.online_check_initial_interval;
+
+       if (g_str_equal(key, CONF_ONLINE_CHECK_MAX_INTERVAL))
+               return connman_settings.online_check_max_interval;
+
+#if defined TIZEN_EXT
        if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID_SCORE))
                return connman_ins_settings.ins_preferred_freq_bssid_score;
 
@@ -1241,10 +1330,11 @@ unsigned int connman_setting_get_uint(const char *key)
 
        if (g_str_equal(key, CONF_INS_INTERNET_SCORE))
                return connman_ins_settings.ins_internet_score;
-
+#endif
        return 0;
 }
 
+#if defined TIZEN_EXT
 int connman_setting_get_int(const char *key)
 {
        if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_5GHZ))
@@ -1376,6 +1466,21 @@ int main(int argc, char *argv[])
 
        __connman_dbus_init(conn);
 
+#if defined TIZEN_EXT
+       if (access(CONTAINER_FILE, F_OK) == 0) {
+               g_main_loop_run(main_loop);
+
+               g_source_remove(signal);
+               dbus_connection_unref(conn);
+               g_main_loop_unref(main_loop);
+
+               __connman_dbus_cleanup();
+               __connman_log_cleanup(option_backtrace);
+
+               return 0;
+       }
+#endif
+
        if (!option_config)
                config_init(CONFIGMAINFILE);
        else
@@ -1502,6 +1607,7 @@ int main(int argc, char *argv[])
        g_strfreev(connman_settings.fallback_nameservers);
        g_strfreev(connman_settings.blacklisted_interfaces);
        g_strfreev(connman_settings.tethering_technologies);
+       g_free(connman_settings.vendor_class_id);
 
 #if defined TIZEN_EXT
        g_free(connman_ins_settings.ins_preferred_freq_bssid);