2 * Network Configuration Module
4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <system_info.h>
32 #include "wifi-agent.h"
33 #include "wifi-power.h"
36 #include "network-clock.h"
37 #include "network-dpm.h"
38 #include "network-state.h"
39 #include "network-monitor.h"
40 #include "signal-handler.h"
41 #include "network-statistics.h"
42 #include "network-dump.h"
44 static GMainLoop *main_loop = NULL;
46 /*Poll the ethernet Cable Plug-in /Plug-out status at every 1000 ms*/
47 #define ETH_POLLING_TIME 1000
49 /* Callback to Poll the Ethernet Status*/
50 gboolean __net_ethernet_cable_status_polling_callback(gpointer data)
52 netconfig_ethernet_cable_plugin_status_check();
56 void _got_name_cb(void)
58 wifi_object_create_and_init();
59 state_object_create_and_init();
60 statistics_object_create_and_init();
61 vpnsvc_create_and_init();
62 mptcp_object_create_and_init();
64 register_gdbus_signal();
65 connman_register_agent();
68 __netconfig_set_ether_macaddr();
71 static void _objects_deinit(void)
75 state_object_deinit();
76 statistics_object_deinit();
77 vpnsvc_destroy_deinit();
78 mptcp_object_deinit();
81 int main(int argc, char *argv[])
84 int check_ethernet_monitor_timer = 0;
88 DBG("Network Configuration service");
89 if (daemon(0, 0) != 0)
90 DBG("Cannot start daemon");
92 if (mkdir(WIFI_STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
93 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
95 ERR("Failed to create Wi-Fi directory");
98 if (mkdir(WIFI_CERT_STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
99 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
101 ERR("Failed to create cert directory");
104 #if !GLIB_CHECK_VERSION(2, 36, 0)
108 main_loop = g_main_loop_new(NULL, FALSE);
109 if (main_loop == NULL) {
110 ERR("Couldn't create GMainLoop\n");
114 ret = setup_gdbus(_got_name_cb);
116 ERR("_netconfig_setup_gdbus is failed\n");
120 netconfig_error_init();
122 if (TIZEN_NTP_ENABLE)
123 netconfig_clock_init();
125 /* If its environment uses Emulator, network configuration is set by emulator default */
126 emulator_test_and_start();
128 /* For device policy manager */
129 netconfig_dpm_init();
131 /* Start tcpdump if dump state is on */
132 #if defined TIZEN_DEBUG_ENABLE
133 check_dump_state_and_start();
136 if (TIZEN_WLAN_BOARD_SPRD)
137 wifi_firmware_download();
139 /*In case no emulator, set the ETH0 Mac address*/
140 if (TIZEN_TV && emulator_is_emulated() == FALSE)
141 __netconfig_set_ether_macaddr();
143 if (netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_ETHERNET)) {
144 /* Register the callback to check the ethernet Plug-in /Plug-out Status */
145 check_ethernet_monitor_timer = g_timeout_add(ETH_POLLING_TIME,
146 __net_ethernet_cable_status_polling_callback,
147 &check_ethernet_monitor_timer);
150 netconfig_plugin_init();
152 g_main_loop_run(main_loop);
154 netconfig_plugin_deinit();
160 deregister_gdbus_signal();
162 netconfig_dpm_deinit();
164 if (TIZEN_NTP_ENABLE)
165 netconfig_clock_deinit();
169 if (check_ethernet_monitor_timer > 0)
170 g_source_remove(check_ethernet_monitor_timer);
172 wifi_state_notifier_cleanup();
174 /* Unregistering the agent */
175 connman_unregister_agent();