Support association failed error
[platform/core/connectivity/net-config.git] / src / main.c
index 25e1fac..f1832c7 100755 (executable)
 #include <system_info.h>
 
 #include "log.h"
+#include "util.h"
 #include "wifi.h"
+#include "setting.h"
 #include "netdbus.h"
 #include "emulator.h"
 #include "neterror.h"
 #include "wifi-agent.h"
 #include "wifi-power.h"
+#include "vpnsvc.h"
+#include "mptcp.h"
 #include "network-clock.h"
+#include "network-dpm.h"
 #include "network-state.h"
 #include "network-monitor.h"
 #include "signal-handler.h"
 #include "network-statistics.h"
+#include "network-dump.h"
+#include "ethernet.h"
+#include "wifi-firmware.h"
 
 static GMainLoop *main_loop = NULL;
 
-#define ETHERNET_FEATURE       "http://tizen.org/feature/network.ethernet"
-
 /*Poll the ethernet Cable Plug-in /Plug-out status at every 1000 ms*/
 #define ETH_POLLING_TIME       1000
 
@@ -50,25 +56,45 @@ gboolean __net_ethernet_cable_status_polling_callback(gpointer data)
        return TRUE;
 }
 
-void __netconfig_got_name_cb(void)
+void _got_name_cb_container(void)
 {
-       netconfig_wifi_create_and_init();
-       netconfig_network_state_create_and_init();
-       netconfig_network_statistics_create_and_init();
+       register_gdbus_signal_container();
+       netconfig_update_initial_container_vconf();
+}
 
-       netconfig_register_signal();
-       netconfig_agent_register();
+void _got_name_cb(void)
+{
+       wifi_object_create_and_init();
+       state_object_create_and_init();
+       statistics_object_create_and_init();
+       vpnsvc_create_and_init();
+       mptcp_object_create_and_init();
+       ethernet_object_create_and_init();
 
-#if defined TIZEN_TV
-       __netconfig_set_ether_macaddr();
-#endif
+       register_gdbus_signal();
+       connman_register_agent();
+
+       if (TIZEN_TV)
+               __netconfig_set_ether_macaddr();
+}
+
+static void _objects_deinit(void)
+{
+       cleanup_gdbus();
+       wifi_object_deinit();
+       state_object_deinit();
+       statistics_object_deinit();
+       vpnsvc_destroy_deinit();
+       mptcp_object_deinit();
+       ethernet_object_deinit();
 }
 
 int main(int argc, char *argv[])
 {
        int ret;
        int check_ethernet_monitor_timer = 0;
-       bool ethernet_feature_supported = FALSE;
+       char *ifname = NULL;
+       char *wifi_def_mac = NULL;
 
        umask(0077);
 
@@ -88,64 +114,114 @@ int main(int argc, char *argv[])
                        ERR("Failed to create cert directory");
        }
 
-#if !GLIB_CHECK_VERSION(2,36,0)
+#if !GLIB_CHECK_VERSION(2, 36, 0)
        g_type_init();
 #endif
 
        main_loop = g_main_loop_new(NULL, FALSE);
        if (main_loop == NULL) {
                ERR("Couldn't create GMainLoop\n");
+               log_cleanup();
                return 0;
        }
 
-       ret = netconfig_setup_gdbus(__netconfig_got_name_cb);
+       if (access(CONTAINER_FILE, F_OK) == 0) {
+               ret = setup_gdbus(_got_name_cb_container);
+               if (ret != 0) {
+                       ERR("_netconfig_setup_gdbus is failed\n");
+                       return 0;
+               }
+
+               g_main_loop_run(main_loop);
+
+               cleanup_gdbus();
+               log_cleanup();
+               deregister_gdbus_signal_container();
+
+               return 0;
+       }
+
+       /* Backward compatibility:
+        * Execute only when the old style hal architecture is not running
+        */
+       if (!wifi_check_systemd_service()) {
+               ifname = netconfig_get_default_ifname_from_file();
+
+               if (ifname && netconfig_wifi_firmware_get_mac(ifname, &wifi_def_mac) == 0)
+                       wifi_set_default_mac(wifi_def_mac);
+
+               g_free(ifname);
+       }
+
+       ret = setup_gdbus(_got_name_cb);
        if (ret > 0) {
                ERR("_netconfig_setup_gdbus is failed\n");
                return 0;
        }
 
+       netconfig_setting_init();
+
        netconfig_error_init();
 
-#if !defined TIZEN_TELEPHONY_ENABLE
-       netconfig_clock_init();
-#endif
+       if (TIZEN_NTP_ENABLE)
+               netconfig_clock_init();
 
        /* If its environment uses Emulator, network configuration is set by emulator default */
-       netconfig_emulator_test_and_start();
+       emulator_test_and_start();
+
+       /* For device policy manager */
+       netconfig_dpm_init();
+
+       /* Start tcpdump if dump state is on */
+#if defined TIZEN_DEBUG_ENABLE
+       check_dump_state_and_start();
+#endif
+
+       /* Backward compatibility:
+        * Execute only when the old style hal architecture is running
+        */
+       if (TIZEN_WLAN_BOARD_SPRD && wifi_check_systemd_service())
+               wifi_firmware_download();
 
        /*In case no emulator, set the ETH0 Mac address*/
-#if defined TIZEN_TV
-       if (netconfig_emulator_is_emulated() == FALSE)
+       if (TIZEN_TV && emulator_is_emulated() == FALSE)
                __netconfig_set_ether_macaddr();
-#endif
 
-       if (!system_info_get_platform_bool(ETHERNET_FEATURE, &ethernet_feature_supported)) {
-               if (ethernet_feature_supported == TRUE) {
-                       //Register the callback to check the ethernet Plug-in /Plug-out Status
-                       check_ethernet_monitor_timer = g_timeout_add(ETH_POLLING_TIME,
-                                       __net_ethernet_cable_status_polling_callback,
-                                       &check_ethernet_monitor_timer);
-               }
-       } else {
-               ERR("Error - Feature getting from System Info");
+       if (netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_ETHERNET)) {
+               /* Register the callback to check the ethernet Plug-in /Plug-out Status */
+               check_ethernet_monitor_timer = g_timeout_add(ETH_POLLING_TIME,
+                               __net_ethernet_cable_status_polling_callback,
+                               &check_ethernet_monitor_timer);
        }
 
+       netconfig_plugin_init();
+
        g_main_loop_run(main_loop);
 
-       netconfig_cleanup_gdbus();
+       netconfig_plugin_deinit();
+
+       _objects_deinit();
 
-       netconfig_deregister_signal();
+       log_cleanup();
 
-       netconfig_wifi_power_deinitialize();
+       deregister_gdbus_signal();
+
+       netconfig_dpm_deinit();
+
+       netconfig_setting_deinit();
+
+       if (TIZEN_NTP_ENABLE)
+               netconfig_clock_deinit();
 
-       netconfig_wifi_state_notifier_cleanup();
 
        /*remove the Timer*/
-       if(check_ethernet_monitor_timer >0)
+       if (check_ethernet_monitor_timer > 0)
                g_source_remove(check_ethernet_monitor_timer);
 
+       wifi_state_notifier_cleanup();
+
        /* Unregistering the agent */
-       netconfig_agent_unregister();
+       connman_unregister_agent();
 
        return 0;
 }