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>
33 #include "wifi-agent.h"
34 #include "wifi-power.h"
37 #include "network-clock.h"
38 #include "network-dpm.h"
39 #include "network-state.h"
40 #include "network-monitor.h"
41 #include "signal-handler.h"
42 #include "network-statistics.h"
43 #include "network-dump.h"
45 #include "wifi-firmware.h"
47 static GMainLoop *main_loop = NULL;
49 /*Poll the ethernet Cable Plug-in /Plug-out status at every 1000 ms*/
50 #define ETH_POLLING_TIME 1000
52 /* Callback to Poll the Ethernet Status*/
53 gboolean __net_ethernet_cable_status_polling_callback(gpointer data)
55 netconfig_ethernet_cable_plugin_status_check();
59 void _got_name_cb(void)
61 wifi_object_create_and_init();
62 state_object_create_and_init();
63 statistics_object_create_and_init();
64 vpnsvc_create_and_init();
65 mptcp_object_create_and_init();
66 ethernet_object_create_and_init();
68 register_gdbus_signal();
69 connman_register_agent();
72 __netconfig_set_ether_macaddr();
75 static void _objects_deinit(void)
79 state_object_deinit();
80 statistics_object_deinit();
81 vpnsvc_destroy_deinit();
82 mptcp_object_deinit();
83 ethernet_object_deinit();
86 int main(int argc, char *argv[])
89 int check_ethernet_monitor_timer = 0;
91 char *wifi_def_mac = NULL;
95 DBG("Network Configuration service");
96 if (daemon(0, 0) != 0)
97 DBG("Cannot start daemon");
99 if (mkdir(WIFI_STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
100 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
102 ERR("Failed to create Wi-Fi directory");
105 if (mkdir(WIFI_CERT_STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
106 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
108 ERR("Failed to create cert directory");
111 #if !GLIB_CHECK_VERSION(2, 36, 0)
115 /* Backward compatibility:
116 * Execute only when the old style hal architecture is not running
118 if (!wifi_check_systemd_service()) {
119 ifname = netconfig_get_default_ifname_from_file();
121 if (ifname && netconfig_wifi_firmware_get_mac(ifname, &wifi_def_mac) == 0)
122 wifi_set_default_mac(wifi_def_mac);
127 main_loop = g_main_loop_new(NULL, FALSE);
128 if (main_loop == NULL) {
129 ERR("Couldn't create GMainLoop\n");
133 ret = setup_gdbus(_got_name_cb);
135 ERR("_netconfig_setup_gdbus is failed\n");
139 netconfig_setting_init();
141 netconfig_error_init();
143 if (TIZEN_NTP_ENABLE)
144 netconfig_clock_init();
146 /* If its environment uses Emulator, network configuration is set by emulator default */
147 emulator_test_and_start();
149 /* For device policy manager */
150 netconfig_dpm_init();
152 /* Start tcpdump if dump state is on */
153 #if defined TIZEN_DEBUG_ENABLE
154 check_dump_state_and_start();
157 /* Backward compatibility:
158 * Execute only when the old style hal architecture is running
160 if (TIZEN_WLAN_BOARD_SPRD && wifi_check_systemd_service())
161 wifi_firmware_download();
163 /*In case no emulator, set the ETH0 Mac address*/
164 if (TIZEN_TV && emulator_is_emulated() == FALSE)
165 __netconfig_set_ether_macaddr();
167 if (netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_ETHERNET)) {
168 /* Register the callback to check the ethernet Plug-in /Plug-out Status */
169 check_ethernet_monitor_timer = g_timeout_add(ETH_POLLING_TIME,
170 __net_ethernet_cable_status_polling_callback,
171 &check_ethernet_monitor_timer);
174 netconfig_plugin_init();
176 g_main_loop_run(main_loop);
178 netconfig_plugin_deinit();
184 deregister_gdbus_signal();
186 netconfig_dpm_deinit();
188 netconfig_setting_deinit();
190 if (TIZEN_NTP_ENABLE)
191 netconfig_clock_deinit();
195 if (check_ethernet_monitor_timer > 0)
196 g_source_remove(check_ethernet_monitor_timer);
198 wifi_state_notifier_cleanup();
200 /* Unregistering the agent */
201 connman_unregister_agent();