Modified to get security info for ssid scan
[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 "wifi.h"
28 #include "netdbus.h"
29 #include "emulator.h"
30 #include "neterror.h"
31 #include "wifi-agent.h"
32 #include "wifi-power.h"
33 #include "vpnsvc.h"
34 #include "network-clock.h"
35 #include "network-dpm.h"
36 #include "network-state.h"
37 #include "network-monitor.h"
38 #include "signal-handler.h"
39 #include "network-statistics.h"
40
41 static GMainLoop *main_loop = NULL;
42
43 #define ETHERNET_FEATURE       "http://tizen.org/feature/network.ethernet"
44
45 /*Poll the ethernet Cable Plug-in /Plug-out status at every 1000 ms*/
46 #define ETH_POLLING_TIME       1000
47
48 /* Callback to Poll the Ethernet Status*/
49 gboolean __net_ethernet_cable_status_polling_callback(gpointer data)
50 {
51         netconfig_ethernet_cable_plugin_status_check();
52         return TRUE;
53 }
54
55 void _got_name_cb(void)
56 {
57         wifi_object_create_and_init();
58         state_object_create_and_init();
59         statistics_object_create_and_init();
60         vpnsvc_create_and_init();
61
62         register_gdbus_signal();
63         connman_register_agent();
64
65 #if defined TIZEN_TV
66         __netconfig_set_ether_macaddr();
67 #endif
68 }
69
70 static void _objects_deinit(void)
71 {
72         cleanup_gdbus();
73         wifi_object_deinit();
74         state_object_deinit();
75         statistics_object_deinit();
76         vpnsvc_destroy_deinit();
77 }
78
79 int main(int argc, char *argv[])
80 {
81         int ret;
82         int check_ethernet_monitor_timer = 0;
83         bool ethernet_feature_supported = FALSE;
84
85         umask(0077);
86
87         DBG("Network Configuration service");
88         if (daemon(0, 0) != 0)
89                 DBG("Cannot start daemon");
90
91         if (mkdir(WIFI_STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
92                         S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
93                 if (errno != EEXIST)
94                         ERR("Failed to create Wi-Fi directory");
95         }
96
97         if (mkdir(WIFI_CERT_STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
98                         S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
99                 if (errno != EEXIST)
100                         ERR("Failed to create cert directory");
101         }
102
103 #if !GLIB_CHECK_VERSION(2, 36, 0)
104         g_type_init();
105 #endif
106
107         main_loop = g_main_loop_new(NULL, FALSE);
108         if (main_loop == NULL) {
109                 ERR("Couldn't create GMainLoop\n");
110                 return 0;
111         }
112
113         ret = setup_gdbus(_got_name_cb);
114         if (ret > 0) {
115                 ERR("_netconfig_setup_gdbus is failed\n");
116                 return 0;
117         }
118
119         netconfig_error_init();
120
121 #if !defined TIZEN_TELEPHONY_ENABLE
122         netconfig_clock_init();
123 #endif
124
125         /* If its environment uses Emulator, network configuration is set by emulator default */
126         emulator_test_and_start();
127
128         /* For device policy manager */
129         netconfig_dpm_init();
130
131 #if defined TIZEN_WLAN_BOARD_SPRD
132         wifi_firmware_download();
133 #endif
134
135         /*In case no emulator, set the ETH0 Mac address*/
136 #if defined TIZEN_TV
137         if (emulator_is_emulated() == FALSE)
138                 __netconfig_set_ether_macaddr();
139 #endif
140
141         if (!system_info_get_platform_bool(ETHERNET_FEATURE, &ethernet_feature_supported)) {
142                 if (ethernet_feature_supported == TRUE) {
143                         /* Register the callback to check the ethernet Plug-in /Plug-out Status */
144                         check_ethernet_monitor_timer = g_timeout_add(ETH_POLLING_TIME,
145                                         __net_ethernet_cable_status_polling_callback,
146                                         &check_ethernet_monitor_timer);
147                 }
148         } else {
149                 ERR("Error - Feature getting from System Info");
150         }
151
152         g_main_loop_run(main_loop);
153
154         _objects_deinit();
155
156         log_cleanup();
157
158         deregister_gdbus_signal();
159
160         netconfig_dpm_deinit();
161
162 #if !defined TIZEN_TELEPHONY_ENABLE
163         netconfig_clock_deinit();
164 #endif
165
166
167         /*remove the Timer*/
168         if (check_ethernet_monitor_timer > 0)
169                 g_source_remove(check_ethernet_monitor_timer);
170
171         wifi_state_notifier_cleanup();
172
173         /* Unregistering the agent */
174         connman_unregister_agent();
175
176         return 0;
177 }