Remove temporary code changes.
[platform/core/connectivity/net-config.git] / src / main.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <stdio.h>
21 #include <errno.h>
22 #include <unistd.h>
23 #include <sys/stat.h>
24 #include <system_info.h>
25
26 #include "log.h"
27 #include "util.h"
28 #include "wifi.h"
29 #include "setting.h"
30 #include "netdbus.h"
31 #include "emulator.h"
32 #include "neterror.h"
33 #include "wifi-agent.h"
34 #include "wifi-power.h"
35 #include "vpnsvc.h"
36 #include "mptcp.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"
44 #include "ethernet.h"
45
46 static GMainLoop *main_loop = NULL;
47
48 /*Poll the ethernet Cable Plug-in /Plug-out status at every 1000 ms*/
49 #define ETH_POLLING_TIME       1000
50
51 /* Callback to Poll the Ethernet Status*/
52 gboolean __net_ethernet_cable_status_polling_callback(gpointer data)
53 {
54         netconfig_ethernet_cable_plugin_status_check();
55         return TRUE;
56 }
57
58 void _got_name_cb(void)
59 {
60         wifi_object_create_and_init();
61         state_object_create_and_init();
62         statistics_object_create_and_init();
63         vpnsvc_create_and_init();
64         mptcp_object_create_and_init();
65         ethernet_object_create_and_init();
66
67         register_gdbus_signal();
68         connman_register_agent();
69
70         if (TIZEN_TV)
71                 __netconfig_set_ether_macaddr();
72 }
73
74 static void _objects_deinit(void)
75 {
76         cleanup_gdbus();
77         wifi_object_deinit();
78         state_object_deinit();
79         statistics_object_deinit();
80         vpnsvc_destroy_deinit();
81         mptcp_object_deinit();
82         ethernet_object_deinit();
83 }
84
85 int main(int argc, char *argv[])
86 {
87         int ret;
88         int check_ethernet_monitor_timer = 0;
89
90         umask(0077);
91
92         DBG("Network Configuration service");
93         if (daemon(0, 0) != 0)
94                 DBG("Cannot start daemon");
95
96         if (mkdir(WIFI_STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
97                         S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
98                 if (errno != EEXIST)
99                         ERR("Failed to create Wi-Fi directory");
100         }
101
102         if (mkdir(WIFI_CERT_STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
103                         S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
104                 if (errno != EEXIST)
105                         ERR("Failed to create cert directory");
106         }
107
108 #if !GLIB_CHECK_VERSION(2, 36, 0)
109         g_type_init();
110 #endif
111
112         main_loop = g_main_loop_new(NULL, FALSE);
113         if (main_loop == NULL) {
114                 ERR("Couldn't create GMainLoop\n");
115                 return 0;
116         }
117
118         ret = setup_gdbus(_got_name_cb);
119         if (ret > 0) {
120                 ERR("_netconfig_setup_gdbus is failed\n");
121                 return 0;
122         }
123
124         netconfig_setting_init();
125
126         netconfig_error_init();
127
128         if (TIZEN_NTP_ENABLE)
129                 netconfig_clock_init();
130
131         /* If its environment uses Emulator, network configuration is set by emulator default */
132         emulator_test_and_start();
133
134         /* For device policy manager */
135         netconfig_dpm_init();
136
137         /* Start tcpdump if dump state is on */
138 #if defined TIZEN_DEBUG_ENABLE
139         check_dump_state_and_start();
140 #endif
141
142         if (TIZEN_WLAN_BOARD_SPRD)
143                 wifi_firmware_download();
144
145         /*In case no emulator, set the ETH0 Mac address*/
146         if (TIZEN_TV && emulator_is_emulated() == FALSE)
147                 __netconfig_set_ether_macaddr();
148
149         if (netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_ETHERNET)) {
150                 /* Register the callback to check the ethernet Plug-in /Plug-out Status */
151                 check_ethernet_monitor_timer = g_timeout_add(ETH_POLLING_TIME,
152                                 __net_ethernet_cable_status_polling_callback,
153                                 &check_ethernet_monitor_timer);
154         }
155
156         netconfig_plugin_init();
157
158         g_main_loop_run(main_loop);
159
160         netconfig_plugin_deinit();
161
162         _objects_deinit();
163
164         log_cleanup();
165
166         deregister_gdbus_signal();
167
168         netconfig_dpm_deinit();
169
170         netconfig_setting_deinit();
171
172         if (TIZEN_NTP_ENABLE)
173                 netconfig_clock_deinit();
174
175
176         /*remove the Timer*/
177         if (check_ethernet_monitor_timer > 0)
178                 g_source_remove(check_ethernet_monitor_timer);
179
180         wifi_state_notifier_cleanup();
181
182         /* Unregistering the agent */
183         connman_unregister_agent();
184
185         return 0;
186 }