Merge "Remove RW upgrade script" into tizen
[platform/upstream/connman.git] / src / main.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2013  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <signal.h>
32 #include <sys/signalfd.h>
33 #include <getopt.h>
34 #include <sys/stat.h>
35 #include <net/if.h>
36 #include <netdb.h>
37 #include <sys/time.h>
38 #include <sys/resource.h>
39
40 #include <gdbus.h>
41
42 #include "connman.h"
43
44 #define CONF_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]) - 1)
45
46 #define DEFAULT_INPUT_REQUEST_TIMEOUT (120 * 1000)
47 #define DEFAULT_BROWSER_LAUNCH_TIMEOUT (300 * 1000)
48
49 #define MAINFILE "main.conf"
50 #define CONFIGMAINFILE CONFIGDIR "/" MAINFILE
51
52 static char *default_auto_connect[] = {
53         "wifi",
54         "ethernet",
55         "cellular",
56         NULL
57 };
58
59 static char *default_favorite_techs[] = {
60         "ethernet",
61         NULL
62 };
63
64 static char *default_blacklist[] = {
65         "vmnet",
66         "vboxnet",
67         "virbr",
68         "ifb",
69         "ve-",
70         "vb-",
71         NULL
72 };
73
74 static struct {
75         bool bg_scan;
76         char **pref_timeservers;
77         unsigned int *auto_connect;
78         unsigned int *favorite_techs;
79         unsigned int *preferred_techs;
80         unsigned int *always_connected_techs;
81         char **fallback_nameservers;
82         unsigned int timeout_inputreq;
83         unsigned int timeout_browserlaunch;
84         char **blacklisted_interfaces;
85         bool allow_hostname_updates;
86         bool allow_domainname_updates;
87         bool single_tech;
88         char **tethering_technologies;
89         bool persistent_tethering_mode;
90         bool enable_6to4;
91         char *vendor_class_id;
92         bool enable_online_check;
93         bool auto_connect_roaming_services;
94         bool acd;
95         bool use_gateways_as_timeservers;
96 #if defined TIZEN_EXT
97         char **cellular_interfaces;
98         bool tizen_tv_extension;
99         bool auto_ip;
100         char *global_nameserver;
101         bool supplicant_debug;
102 #endif
103 } connman_settings  = {
104         .bg_scan = true,
105         .pref_timeservers = NULL,
106         .auto_connect = NULL,
107         .favorite_techs = NULL,
108         .preferred_techs = NULL,
109         .always_connected_techs = NULL,
110         .fallback_nameservers = NULL,
111         .timeout_inputreq = DEFAULT_INPUT_REQUEST_TIMEOUT,
112         .timeout_browserlaunch = DEFAULT_BROWSER_LAUNCH_TIMEOUT,
113         .blacklisted_interfaces = NULL,
114         .allow_hostname_updates = true,
115         .allow_domainname_updates = true,
116         .single_tech = false,
117         .tethering_technologies = NULL,
118         .persistent_tethering_mode = false,
119         .enable_6to4 = false,
120         .vendor_class_id = NULL,
121         .enable_online_check = true,
122         .auto_connect_roaming_services = false,
123         .acd = false,
124         .use_gateways_as_timeservers = false,
125 #if defined TIZEN_EXT
126         .cellular_interfaces = NULL,
127         .tizen_tv_extension = false,
128         .auto_ip = true,
129         .global_nameserver = NULL,
130         .supplicant_debug = false,
131 #endif
132 };
133
134 #if defined TIZEN_EXT
135 static struct {
136         /* BSSID */
137         char *ins_preferred_freq_bssid;
138         bool ins_last_connected_bssid;
139         bool ins_assoc_reject;
140         bool ins_signal_bssid;
141         unsigned int ins_preferred_freq_bssid_score;
142         unsigned int ins_last_connected_bssid_score;
143         unsigned int ins_assoc_reject_score;
144         /* SSID */
145         bool ins_last_user_selection;
146         unsigned int ins_last_user_selection_time;
147         bool ins_last_connected;
148         char *ins_preferred_freq;
149         char **ins_security_priority;
150         unsigned int ins_security_priority_count;
151         bool ins_signal;
152         bool ins_internet;
153         unsigned int ins_last_user_selection_score;
154         unsigned int ins_last_connected_score;
155         unsigned int ins_preferred_freq_score;
156         unsigned int ins_security_priority_score;
157         unsigned int ins_internet_score;
158         /* Common */
159         int ins_signal_level3_5ghz;
160         int ins_signal_level3_24ghz;
161 } connman_ins_settings = {
162         /* BSSID */
163         .ins_preferred_freq_bssid = NULL,
164         .ins_last_connected_bssid = true,
165         .ins_assoc_reject = true,
166         .ins_signal_bssid = true,
167         .ins_preferred_freq_bssid_score = 20,
168         .ins_last_connected_bssid_score = 20,
169         .ins_assoc_reject_score = 10,
170         /* SSID */
171         .ins_last_user_selection = true,
172         .ins_last_user_selection_time = 480,
173         .ins_last_connected = true,
174         .ins_preferred_freq = NULL,
175         .ins_security_priority = NULL,
176         .ins_security_priority_count = 0,
177         .ins_signal = true,
178         .ins_internet = true,
179         .ins_last_user_selection_score = 30,
180         .ins_last_connected_score = 30,
181         .ins_preferred_freq_score = 60,
182         .ins_security_priority_score = 5,
183         .ins_internet_score = 30,
184         /* Common */
185         .ins_signal_level3_5ghz = -76,
186         .ins_signal_level3_24ghz = -74,
187 };
188 #endif
189
190 #define CONF_BG_SCAN                    "BackgroundScanning"
191 #define CONF_PREF_TIMESERVERS           "FallbackTimeservers"
192 #define CONF_AUTO_CONNECT_TECHS         "DefaultAutoConnectTechnologies"
193 #define CONF_FAVORITE_TECHS             "DefaultFavoriteTechnologies"
194 #define CONF_ALWAYS_CONNECTED_TECHS     "AlwaysConnectedTechnologies"
195 #define CONF_PREFERRED_TECHS            "PreferredTechnologies"
196 #define CONF_FALLBACK_NAMESERVERS       "FallbackNameservers"
197 #define CONF_TIMEOUT_INPUTREQ           "InputRequestTimeout"
198 #define CONF_TIMEOUT_BROWSERLAUNCH      "BrowserLaunchTimeout"
199 #define CONF_BLACKLISTED_INTERFACES     "NetworkInterfaceBlacklist"
200 #define CONF_ALLOW_HOSTNAME_UPDATES     "AllowHostnameUpdates"
201 #define CONF_ALLOW_DOMAINNAME_UPDATES   "AllowDomainnameUpdates"
202 #define CONF_SINGLE_TECH                "SingleConnectedTechnology"
203 #define CONF_TETHERING_TECHNOLOGIES      "TetheringTechnologies"
204 #define CONF_PERSISTENT_TETHERING_MODE  "PersistentTetheringMode"
205 #define CONF_ENABLE_6TO4                "Enable6to4"
206 #define CONF_VENDOR_CLASS_ID            "VendorClassID"
207 #define CONF_ENABLE_ONLINE_CHECK        "EnableOnlineCheck"
208 #define CONF_AUTO_CONNECT_ROAMING_SERVICES "AutoConnectRoamingServices"
209 #define CONF_ACD                        "AddressConflictDetection"
210 #define CONF_USE_GATEWAYS_AS_TIMESERVERS "UseGatewaysAsTimeservers"
211 #if defined TIZEN_EXT
212 #define CONF_CELLULAR_INTERFACE         "NetworkCellularInterfaceList"
213 #define CONF_TIZEN_TV_EXT                       "TizenTVExtension"
214 #define CONF_ENABLE_AUTO_IP                     "EnableAutoIp"
215 #define CONF_GLOBAL_NAMESERVER          "GlobalNameserver"
216 #define CONF_CONNMAN_SUPPLICANT_DEBUG   "ConnmanSupplicantDebug"
217 #endif
218
219 #if defined TIZEN_EXT
220 /* BSSID */
221 #define CONF_INS_PREFERRED_FREQ_BSSID        "INSPreferredFreqBSSID"
222 #define CONF_INS_PREFERRED_FREQ_BSSID_SCORE  "INSPreferredFreqBSSIDScore"
223 #define CONF_INS_LAST_CONNECTED_BSSID        "INSLastConnectedBSSID"
224 #define CONF_INS_LAST_CONNECTED_BSSID_SCORE  "INSLastConnectedBSSIDScore"
225 #define CONF_INS_ASSOC_REJECT                "INSAssocReject"
226 #define CONF_INS_ASSOC_REJECT_SCORE          "INSAssocRejectScore"
227 #define CONF_INS_SIGNAL_BSSID                "INSSignalBSSID"
228 /* SSID */
229 #define CONF_INS_LAST_USER_SELECTION         "INSLastUserSelection"
230 #define CONF_INS_LAST_USER_SELECTION_TIME    "INSLastUserSelectionTime"
231 #define CONF_INS_LAST_USER_SELECTION_SCORE   "INSLastUserSelectionScore"
232 #define CONF_INS_LAST_CONNECTED              "INSLastConnected"
233 #define CONF_INS_LAST_CONNECTED_SCORE        "INSLastConnectedScore"
234 #define CONF_INS_PREFERRED_FREQ              "INSPreferredFreq"
235 #define CONF_INS_PREFERRED_FREQ_SCORE        "INSPreferredFreqScore"
236 #define CONF_INS_SECURITY_PRIORITY           "INSSecurityPriority"
237 #define CONF_INS_SECURITY_PRIORITY_COUNT     "INSSecurityPriorityCount"
238 #define CONF_INS_SECURITY_PRIORITY_SCORE     "INSSecurityPriorityScore"
239 #define CONF_INS_SIGNAL                      "INSSignal"
240 #define CONF_INS_INTERNET                    "INSInternet"
241 #define CONF_INS_INTERNET_SCORE              "INSInternetScore"
242 /* Common */
243 #define CONF_INS_SIGNAL_LEVEL3_5GHZ          "INSSignalLevel3_5GHz"
244 #define CONF_INS_SIGNAL_LEVEL3_24GHZ         "INSSignalLevel3_24GHz"
245 #endif
246
247 static const char *supported_options[] = {
248         CONF_BG_SCAN,
249         CONF_PREF_TIMESERVERS,
250         CONF_AUTO_CONNECT_TECHS,
251         CONF_ALWAYS_CONNECTED_TECHS,
252         CONF_PREFERRED_TECHS,
253         CONF_FALLBACK_NAMESERVERS,
254         CONF_TIMEOUT_INPUTREQ,
255         CONF_TIMEOUT_BROWSERLAUNCH,
256         CONF_BLACKLISTED_INTERFACES,
257         CONF_ALLOW_HOSTNAME_UPDATES,
258         CONF_ALLOW_DOMAINNAME_UPDATES,
259         CONF_SINGLE_TECH,
260         CONF_TETHERING_TECHNOLOGIES,
261         CONF_PERSISTENT_TETHERING_MODE,
262         CONF_ENABLE_6TO4,
263         CONF_VENDOR_CLASS_ID,
264         CONF_ENABLE_ONLINE_CHECK,
265         CONF_AUTO_CONNECT_ROAMING_SERVICES,
266         CONF_ACD,
267         CONF_USE_GATEWAYS_AS_TIMESERVERS,
268 #if defined TIZEN_EXT
269         CONF_CELLULAR_INTERFACE,
270         CONF_TIZEN_TV_EXT,
271         CONF_ENABLE_AUTO_IP,
272         CONF_GLOBAL_NAMESERVER,
273         CONF_CONNMAN_SUPPLICANT_DEBUG,
274 #endif
275         NULL
276 };
277
278 #if defined TIZEN_EXT
279 static const char *supported_ins_options[] = {
280         /* BSSID */
281         CONF_INS_PREFERRED_FREQ_BSSID,
282         CONF_INS_PREFERRED_FREQ_BSSID_SCORE,
283         CONF_INS_LAST_CONNECTED_BSSID,
284         CONF_INS_LAST_CONNECTED_BSSID_SCORE,
285         CONF_INS_ASSOC_REJECT,
286         CONF_INS_ASSOC_REJECT_SCORE,
287         CONF_INS_SIGNAL_BSSID,
288         /* SSID */
289         CONF_INS_LAST_USER_SELECTION,
290         CONF_INS_LAST_USER_SELECTION_TIME,
291         CONF_INS_LAST_USER_SELECTION_SCORE,
292         CONF_INS_LAST_CONNECTED,
293         CONF_INS_LAST_CONNECTED_SCORE,
294         CONF_INS_PREFERRED_FREQ,
295         CONF_INS_PREFERRED_FREQ_SCORE,
296         CONF_INS_SECURITY_PRIORITY,
297         CONF_INS_SECURITY_PRIORITY_COUNT,
298         CONF_INS_SECURITY_PRIORITY_SCORE,
299         CONF_INS_SIGNAL,
300         CONF_INS_INTERNET,
301         CONF_INS_INTERNET_SCORE,
302         /* Common */
303         CONF_INS_SIGNAL_LEVEL3_5GHZ,
304         CONF_INS_SIGNAL_LEVEL3_24GHZ,
305         NULL
306 };
307 #endif
308
309 static GKeyFile *load_config(const char *file)
310 {
311         GError *err = NULL;
312         GKeyFile *keyfile;
313
314         keyfile = g_key_file_new();
315
316         g_key_file_set_list_separator(keyfile, ',');
317
318         if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
319                 if (err->code != G_FILE_ERROR_NOENT) {
320                         connman_error("Parsing %s failed: %s", file,
321                                                                 err->message);
322                 }
323
324                 g_error_free(err);
325                 g_key_file_free(keyfile);
326                 return NULL;
327         }
328
329         return keyfile;
330 }
331
332 static uint *parse_service_types(char **str_list, gsize len)
333 {
334         unsigned int *type_list;
335         int i, j;
336         enum connman_service_type type;
337
338         type_list = g_try_new0(unsigned int, len + 1);
339         if (!type_list)
340                 return NULL;
341
342         i = 0;
343         j = 0;
344         while (str_list[i]) {
345                 type = __connman_service_string2type(str_list[i]);
346
347                 if (type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
348                         type_list[j] = type;
349                         j += 1;
350                 }
351                 i += 1;
352         }
353
354         type_list[j] = CONNMAN_SERVICE_TYPE_UNKNOWN;
355
356         return type_list;
357 }
358
359 static char **parse_fallback_nameservers(char **nameservers, gsize len)
360 {
361         char **servers;
362         int i, j;
363
364         servers = g_try_new0(char *, len + 1);
365         if (!servers)
366                 return NULL;
367
368         i = 0;
369         j = 0;
370         while (nameservers[i]) {
371                 if (connman_inet_check_ipaddress(nameservers[i]) > 0) {
372                         servers[j] = g_strdup(nameservers[i]);
373                         j += 1;
374                 }
375                 i += 1;
376         }
377
378         return servers;
379 }
380
381 static void check_config(GKeyFile *config)
382 {
383         char **keys;
384         int j;
385
386         if (!config)
387                 return;
388
389         keys = g_key_file_get_groups(config, NULL);
390
391         for (j = 0; keys && keys[j]; j++) {
392 #if defined TIZEN_EXT
393                 if (g_strcmp0(keys[j], "General") != 0 &&
394                         g_strcmp0(keys[j], "INS") != 0)
395 #else
396                 if (g_strcmp0(keys[j], "General") != 0)
397 #endif
398                         connman_warn("Unknown group %s in %s",
399                                                 keys[j], MAINFILE);
400         }
401
402         g_strfreev(keys);
403
404         keys = g_key_file_get_keys(config, "General", NULL, NULL);
405
406         for (j = 0; keys && keys[j]; j++) {
407                 bool found;
408                 int i;
409
410                 found = false;
411                 for (i = 0; supported_options[i]; i++) {
412                         if (g_strcmp0(keys[j], supported_options[i]) == 0) {
413                                 found = true;
414                                 break;
415                         }
416                 }
417                 if (!found && !supported_options[i])
418                         connman_warn("Unknown option %s in %s",
419                                                 keys[j], MAINFILE);
420         }
421
422         g_strfreev(keys);
423
424 #if defined TIZEN_EXT
425         keys = g_key_file_get_keys(config, "INS", NULL, NULL);
426
427         for (j = 0; keys && keys[j]; j++) {
428                 bool found;
429                 int i;
430
431                 found = false;
432                 for (i = 0; supported_ins_options[i]; i++) {
433                         if (g_strcmp0(keys[j], supported_ins_options[i]) == 0) {
434                                 found = true;
435                                 break;
436                         }
437                 }
438                 if (!found && !supported_ins_options[i])
439                         connman_warn("Unknown option %s in %s",
440                                                 keys[j], MAINFILE);
441         }
442
443         g_strfreev(keys);
444 #endif
445 }
446
447 #if defined TIZEN_EXT
448 static void check_Tizen_INS_configuration(GKeyFile *config)
449 {
450         GError *error = NULL;
451         char *ins_preferred_freq_bssid;
452         char *ins_preferred_freq;
453         char **ins_security_priority;
454         bool boolean;
455         int integer;
456         gsize len;
457
458         ins_preferred_freq_bssid = __connman_config_get_string(config, "INS",
459                                         CONF_INS_PREFERRED_FREQ_BSSID, &error);
460         if (!error)
461                 connman_ins_settings.ins_preferred_freq_bssid = ins_preferred_freq_bssid;
462
463         g_clear_error(&error);
464
465         integer = g_key_file_get_integer(config, "INS",
466                         CONF_INS_PREFERRED_FREQ_BSSID_SCORE, &error);
467         if (!error && integer >= 0)
468                 connman_ins_settings.ins_preferred_freq_bssid_score = integer;
469
470         g_clear_error(&error);
471
472         boolean = __connman_config_get_bool(config, "INS",
473                         CONF_INS_LAST_CONNECTED_BSSID, &error);
474         if (!error)
475                 connman_ins_settings.ins_last_connected_bssid = boolean;
476
477         g_clear_error(&error);
478
479         integer = g_key_file_get_integer(config, "INS",
480                         CONF_INS_LAST_CONNECTED_BSSID_SCORE, &error);
481         if (!error && integer >= 0)
482                 connman_ins_settings.ins_last_connected_bssid_score = integer;
483
484         g_clear_error(&error);
485
486         boolean = __connman_config_get_bool(config, "INS",
487                         CONF_INS_ASSOC_REJECT, &error);
488         if (!error)
489                 connman_ins_settings.ins_assoc_reject = boolean;
490
491         g_clear_error(&error);
492
493         integer = g_key_file_get_integer(config, "INS",
494                         CONF_INS_ASSOC_REJECT_SCORE, &error);
495         if (!error && integer >= 0)
496                 connman_ins_settings.ins_assoc_reject_score = integer;
497
498         g_clear_error(&error);
499
500         boolean = __connman_config_get_bool(config, "INS",
501                         CONF_INS_SIGNAL_BSSID, &error);
502         if (!error)
503                 connman_ins_settings.ins_signal_bssid = boolean;
504
505         g_clear_error(&error);
506
507         boolean = __connman_config_get_bool(config, "INS",
508                         CONF_INS_LAST_USER_SELECTION, &error);
509         if (!error)
510                 connman_ins_settings.ins_last_user_selection = boolean;
511
512         g_clear_error(&error);
513
514         integer = g_key_file_get_integer(config, "INS",
515                         CONF_INS_LAST_USER_SELECTION_TIME, &error);
516         if (!error && integer >= 0)
517                 connman_ins_settings.ins_last_user_selection_time = integer;
518
519         g_clear_error(&error);
520
521         integer = g_key_file_get_integer(config, "INS",
522                         CONF_INS_LAST_USER_SELECTION_SCORE, &error);
523         if (!error && integer >= 0)
524                 connman_ins_settings.ins_last_user_selection_score = integer;
525
526         g_clear_error(&error);
527
528         boolean = __connman_config_get_bool(config, "INS",
529                         CONF_INS_LAST_CONNECTED, &error);
530         if (!error)
531                 connman_ins_settings.ins_last_connected = boolean;
532
533         g_clear_error(&error);
534
535         integer = g_key_file_get_integer(config, "INS",
536                         CONF_INS_LAST_CONNECTED_SCORE, &error);
537         if (!error && integer >= 0)
538                 connman_ins_settings.ins_last_connected_score = integer;
539
540         g_clear_error(&error);
541
542         ins_preferred_freq = __connman_config_get_string(config, "INS",
543                                         CONF_INS_PREFERRED_FREQ, &error);
544         if (!error)
545                 connman_ins_settings.ins_preferred_freq = ins_preferred_freq;
546
547         g_clear_error(&error);
548
549         integer = g_key_file_get_integer(config, "INS",
550                         CONF_INS_PREFERRED_FREQ_SCORE, &error);
551         if (!error && integer >= 0)
552                 connman_ins_settings.ins_preferred_freq_score = integer;
553
554         g_clear_error(&error);
555
556         ins_security_priority = g_key_file_get_string_list(config, "INS",
557                         CONF_INS_SECURITY_PRIORITY, &len, &error);
558
559         if (error == NULL) {
560                 connman_ins_settings.ins_security_priority = ins_security_priority;
561                 connman_ins_settings.ins_security_priority_count = len;
562         }
563
564         g_clear_error(&error);
565
566         integer = g_key_file_get_integer(config, "INS",
567                         CONF_INS_SECURITY_PRIORITY_SCORE, &error);
568         if (!error && integer >= 0)
569                 connman_ins_settings.ins_security_priority_score = integer;
570
571         g_clear_error(&error);
572
573         boolean = __connman_config_get_bool(config, "INS",
574                         CONF_INS_SIGNAL, &error);
575         if (!error)
576                 connman_ins_settings.ins_signal = boolean;
577
578         g_clear_error(&error);
579
580         boolean = __connman_config_get_bool(config, "INS",
581                         CONF_INS_INTERNET, &error);
582         if (!error)
583                 connman_ins_settings.ins_internet = boolean;
584
585         g_clear_error(&error);
586
587         integer = g_key_file_get_integer(config, "INS",
588                         CONF_INS_INTERNET_SCORE, &error);
589         if (!error && integer >= 0)
590                 connman_ins_settings.ins_internet_score = integer;
591
592         g_clear_error(&error);
593
594         integer = g_key_file_get_integer(config, "INS",
595                         CONF_INS_SIGNAL_LEVEL3_5GHZ, &error);
596         if (!error)
597                 connman_ins_settings.ins_signal_level3_5ghz = integer;
598
599         g_clear_error(&error);
600
601         integer = g_key_file_get_integer(config, "INS",
602                         CONF_INS_SIGNAL_LEVEL3_24GHZ, &error);
603         if (!error)
604                 connman_ins_settings.ins_signal_level3_24ghz = integer;
605
606         g_clear_error(&error);
607 }
608
609 static void check_Tizen_configuration(GKeyFile *config)
610 {
611         GError *error = NULL;
612         char **cellular_interfaces;
613         char *global_nameserver;
614         bool boolean;
615         gsize len;
616
617         cellular_interfaces = g_key_file_get_string_list(config, "General",
618                         CONF_CELLULAR_INTERFACE, &len, &error);
619
620         if (error == NULL)
621                 connman_settings.cellular_interfaces = cellular_interfaces;
622
623         g_clear_error(&error);
624
625         boolean = __connman_config_get_bool(config, "General",
626                         CONF_TIZEN_TV_EXT, &error);
627         if (!error)
628                 connman_settings.tizen_tv_extension = boolean;
629
630         g_clear_error(&error);
631
632         boolean = __connman_config_get_bool(config, "General",
633                         CONF_ENABLE_AUTO_IP, &error);
634         if (!error)
635                 connman_settings.auto_ip = boolean;
636
637         g_clear_error(&error);
638
639         global_nameserver = __connman_config_get_string(config, "General",
640                                         CONF_GLOBAL_NAMESERVER, &error);
641         if (!error)
642                 connman_settings.global_nameserver = global_nameserver;
643
644         g_clear_error(&error);
645
646         boolean = __connman_config_get_bool(config, "General",
647                         CONF_CONNMAN_SUPPLICANT_DEBUG, &error);
648         if (!error)
649                 connman_settings.supplicant_debug = boolean;
650
651         g_clear_error(&error);
652
653         check_Tizen_INS_configuration(config);
654 }
655
656 static void set_nofile_inc(void)
657 {
658         int err;
659         struct rlimit rlim;
660
661         rlim.rlim_cur = 8192;
662         rlim.rlim_max = 8192;
663
664         err = setrlimit(RLIMIT_NOFILE, &rlim);
665         if (err)
666                 DBG("fail to increase FILENO err(%d)", err);
667
668         return;
669 }
670 #endif
671
672 static void parse_config(GKeyFile *config)
673 {
674         GError *error = NULL;
675         bool boolean;
676         char **timeservers;
677         char **interfaces;
678         char **str_list;
679         char **tethering;
680         char *vendor_class_id;
681         gsize len;
682         int timeout;
683
684         if (!config) {
685                 connman_settings.auto_connect =
686                         parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
687                 connman_settings.favorite_techs =
688                         parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
689                 connman_settings.blacklisted_interfaces =
690                         g_strdupv(default_blacklist);
691                 return;
692         }
693
694         DBG("parsing %s", MAINFILE);
695
696         boolean = g_key_file_get_boolean(config, "General",
697                                                 CONF_BG_SCAN, &error);
698         if (!error)
699                 connman_settings.bg_scan = boolean;
700
701         g_clear_error(&error);
702
703         timeservers = __connman_config_get_string_list(config, "General",
704                                         CONF_PREF_TIMESERVERS, NULL, &error);
705         if (!error)
706                 connman_settings.pref_timeservers = timeservers;
707
708         g_clear_error(&error);
709
710         str_list = __connman_config_get_string_list(config, "General",
711                         CONF_AUTO_CONNECT_TECHS, &len, &error);
712
713         if (!error)
714                 connman_settings.auto_connect =
715                         parse_service_types(str_list, len);
716         else
717                 connman_settings.auto_connect =
718                         parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
719
720         g_clear_error(&error);
721
722         str_list = __connman_config_get_string_list(config, "General",
723                         CONF_FAVORITE_TECHS, &len, &error);
724
725         if (!error)
726                 connman_settings.favorite_techs =
727                         parse_service_types(str_list, len);
728         else
729                 connman_settings.favorite_techs =
730                         parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
731
732         g_strfreev(str_list);
733
734         g_clear_error(&error);
735
736         str_list = __connman_config_get_string_list(config, "General",
737                         CONF_PREFERRED_TECHS, &len, &error);
738
739         if (!error)
740                 connman_settings.preferred_techs =
741                         parse_service_types(str_list, len);
742
743         g_strfreev(str_list);
744
745         g_clear_error(&error);
746
747         str_list = __connman_config_get_string_list(config, "General",
748                         CONF_ALWAYS_CONNECTED_TECHS, &len, &error);
749
750         if (!error)
751                 connman_settings.always_connected_techs =
752                         parse_service_types(str_list, len);
753
754         g_strfreev(str_list);
755
756         g_clear_error(&error);
757
758         str_list = __connman_config_get_string_list(config, "General",
759                         CONF_FALLBACK_NAMESERVERS, &len, &error);
760
761         if (!error)
762                 connman_settings.fallback_nameservers =
763                         parse_fallback_nameservers(str_list, len);
764
765         g_strfreev(str_list);
766
767         g_clear_error(&error);
768
769         timeout = g_key_file_get_integer(config, "General",
770                         CONF_TIMEOUT_INPUTREQ, &error);
771         if (!error && timeout >= 0)
772                 connman_settings.timeout_inputreq = timeout * 1000;
773
774         g_clear_error(&error);
775
776         timeout = g_key_file_get_integer(config, "General",
777                         CONF_TIMEOUT_BROWSERLAUNCH, &error);
778         if (!error && timeout >= 0)
779                 connman_settings.timeout_browserlaunch = timeout * 1000;
780
781         g_clear_error(&error);
782
783         interfaces = __connman_config_get_string_list(config, "General",
784                         CONF_BLACKLISTED_INTERFACES, &len, &error);
785
786         if (!error)
787                 connman_settings.blacklisted_interfaces = interfaces;
788         else
789                 connman_settings.blacklisted_interfaces =
790                         g_strdupv(default_blacklist);
791
792         g_clear_error(&error);
793
794         boolean = __connman_config_get_bool(config, "General",
795                                         CONF_ALLOW_HOSTNAME_UPDATES,
796                                         &error);
797         if (!error)
798                 connman_settings.allow_hostname_updates = boolean;
799
800         g_clear_error(&error);
801
802         boolean = __connman_config_get_bool(config, "General",
803                                         CONF_ALLOW_DOMAINNAME_UPDATES,
804                                         &error);
805         if (!error)
806                 connman_settings.allow_domainname_updates = boolean;
807
808         g_clear_error(&error);
809
810         boolean = __connman_config_get_bool(config, "General",
811                         CONF_SINGLE_TECH, &error);
812         if (!error)
813                 connman_settings.single_tech = boolean;
814
815         g_clear_error(&error);
816
817         tethering = __connman_config_get_string_list(config, "General",
818                         CONF_TETHERING_TECHNOLOGIES, &len, &error);
819
820         if (!error)
821                 connman_settings.tethering_technologies = tethering;
822
823         g_clear_error(&error);
824
825         boolean = __connman_config_get_bool(config, "General",
826                                         CONF_PERSISTENT_TETHERING_MODE,
827                                         &error);
828         if (!error)
829                 connman_settings.persistent_tethering_mode = boolean;
830
831         g_clear_error(&error);
832
833         boolean = __connman_config_get_bool(config, "General",
834                                         CONF_ENABLE_6TO4, &error);
835         if (!error)
836                 connman_settings.enable_6to4 = boolean;
837
838         g_clear_error(&error);
839
840         vendor_class_id = __connman_config_get_string(config, "General",
841                                         CONF_VENDOR_CLASS_ID, &error);
842         if (!error)
843                 connman_settings.vendor_class_id = vendor_class_id;
844
845         g_clear_error(&error);
846
847         boolean = __connman_config_get_bool(config, "General",
848                                         CONF_ENABLE_ONLINE_CHECK, &error);
849         if (!error) {
850                 connman_settings.enable_online_check = boolean;
851                 if (!boolean)
852                         connman_info("Online check disabled by main config.");
853         }
854
855         g_clear_error(&error);
856
857         boolean = __connman_config_get_bool(config, "General",
858                                 CONF_AUTO_CONNECT_ROAMING_SERVICES, &error);
859         if (!error)
860                 connman_settings.auto_connect_roaming_services = boolean;
861
862         g_clear_error(&error);
863
864         boolean = __connman_config_get_bool(config, "General", CONF_ACD, &error);
865         if (!error)
866                 connman_settings.acd = boolean;
867
868         g_clear_error(&error);
869
870         boolean = __connman_config_get_bool(config, "General",
871                                 CONF_USE_GATEWAYS_AS_TIMESERVERS, &error);
872         if (!error)
873                 connman_settings.use_gateways_as_timeservers = boolean;
874
875         g_clear_error(&error);
876
877 #if defined TIZEN_EXT
878         check_Tizen_configuration(config);
879 #endif
880 }
881
882 static int config_init(const char *file)
883 {
884         GKeyFile *config;
885
886 #if defined TIZEN_EXT
887         set_nofile_inc();
888 #endif
889         config = load_config(file);
890         check_config(config);
891         parse_config(config);
892         if (config)
893                 g_key_file_free(config);
894
895         return 0;
896 }
897
898 static GMainLoop *main_loop = NULL;
899
900 static unsigned int __terminated = 0;
901
902 static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
903                                                         gpointer user_data)
904 {
905         struct signalfd_siginfo si;
906         ssize_t result;
907         int fd;
908
909         if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
910                 return FALSE;
911
912         fd = g_io_channel_unix_get_fd(channel);
913
914         result = read(fd, &si, sizeof(si));
915         if (result != sizeof(si))
916                 return FALSE;
917
918         switch (si.ssi_signo) {
919         case SIGINT:
920         case SIGTERM:
921                 if (__terminated == 0) {
922                         connman_info("Terminating");
923                         g_main_loop_quit(main_loop);
924                 }
925
926                 __terminated = 1;
927                 break;
928         }
929
930         return TRUE;
931 }
932
933 static guint setup_signalfd(void)
934 {
935         GIOChannel *channel;
936         guint source;
937         sigset_t mask;
938         int fd;
939
940         sigemptyset(&mask);
941         sigaddset(&mask, SIGINT);
942         sigaddset(&mask, SIGTERM);
943
944         if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
945                 perror("Failed to set signal mask");
946                 return 0;
947         }
948
949         fd = signalfd(-1, &mask, 0);
950         if (fd < 0) {
951                 perror("Failed to create signal descriptor");
952                 return 0;
953         }
954
955         channel = g_io_channel_unix_new(fd);
956
957         g_io_channel_set_close_on_unref(channel, TRUE);
958         g_io_channel_set_encoding(channel, NULL, NULL);
959         g_io_channel_set_buffered(channel, FALSE);
960
961         source = g_io_add_watch(channel,
962                                 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
963                                 signal_handler, NULL);
964
965         g_io_channel_unref(channel);
966
967         return source;
968 }
969
970 static void disconnect_callback(DBusConnection *conn, void *user_data)
971 {
972         connman_error("D-Bus disconnect");
973
974         g_main_loop_quit(main_loop);
975 }
976
977 static gchar *option_config = NULL;
978 static gchar *option_debug = NULL;
979 static gchar *option_device = NULL;
980 static gchar *option_plugin = NULL;
981 static gchar *option_nodevice = NULL;
982 static gchar *option_noplugin = NULL;
983 static gchar *option_wifi = NULL;
984 static gboolean option_detach = TRUE;
985 static gboolean option_dnsproxy = TRUE;
986 static gboolean option_backtrace = TRUE;
987 static gboolean option_version = FALSE;
988
989 static bool parse_debug(const char *key, const char *value,
990                                         gpointer user_data, GError **error)
991 {
992         if (value) {
993                 if (option_debug) {
994                         char *prev = option_debug;
995
996                         option_debug = g_strconcat(prev, ",", value, NULL);
997                         g_free(prev);
998                 } else {
999                         option_debug = g_strdup(value);
1000                 }
1001         } else {
1002                 g_free(option_debug);
1003                 option_debug = g_strdup("*");
1004         }
1005
1006         return true;
1007 }
1008
1009 static bool parse_noplugin(const char *key, const char *value,
1010                                         gpointer user_data, GError **error)
1011 {
1012         if (option_noplugin) {
1013                 char *prev = option_noplugin;
1014
1015                 option_noplugin = g_strconcat(prev, ",", value, NULL);
1016                 g_free(prev);
1017         } else {
1018                 option_noplugin = g_strdup(value);
1019         }
1020
1021         return true;
1022 }
1023
1024 static GOptionEntry options[] = {
1025         { "config", 'c', 0, G_OPTION_ARG_STRING, &option_config,
1026                                 "Load the specified configuration file "
1027                                 "instead of " CONFIGMAINFILE, "FILE" },
1028         { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
1029                                 G_OPTION_ARG_CALLBACK, parse_debug,
1030                                 "Specify debug options to enable", "DEBUG" },
1031         { "device", 'i', 0, G_OPTION_ARG_STRING, &option_device,
1032                         "Specify networking devices or interfaces", "DEV,..." },
1033         { "nodevice", 'I', 0, G_OPTION_ARG_STRING, &option_nodevice,
1034                         "Specify networking interfaces to ignore", "DEV,..." },
1035         { "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin,
1036                                 "Specify plugins to load", "NAME,..." },
1037         { "noplugin", 'P', 0, G_OPTION_ARG_CALLBACK, &parse_noplugin,
1038                                 "Specify plugins not to load", "NAME,..." },
1039         { "wifi", 'W', 0, G_OPTION_ARG_STRING, &option_wifi,
1040                                 "Specify driver for WiFi/Supplicant", "NAME" },
1041         { "nodaemon", 'n', G_OPTION_FLAG_REVERSE,
1042                                 G_OPTION_ARG_NONE, &option_detach,
1043                                 "Don't fork daemon to background" },
1044         { "nodnsproxy", 'r', G_OPTION_FLAG_REVERSE,
1045                                 G_OPTION_ARG_NONE, &option_dnsproxy,
1046                                 "Don't support DNS resolving" },
1047         { "nobacktrace", 0, G_OPTION_FLAG_REVERSE,
1048                                 G_OPTION_ARG_NONE, &option_backtrace,
1049                                 "Don't print out backtrace information" },
1050         { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
1051                                 "Show version information and exit" },
1052         { NULL },
1053 };
1054
1055 const char *connman_option_get_string(const char *key)
1056 {
1057         if (g_str_equal(key, CONF_VENDOR_CLASS_ID))
1058                 return connman_settings.vendor_class_id;
1059
1060         if (g_strcmp0(key, "wifi") == 0) {
1061                 if (!option_wifi)
1062                         return "nl80211,wext";
1063                 else
1064                         return option_wifi;
1065         }
1066
1067 #if defined TIZEN_EXT
1068         if (g_str_equal(key, CONF_GLOBAL_NAMESERVER))
1069                 return connman_settings.global_nameserver;
1070 #endif
1071
1072 #if defined TIZEN_EXT
1073         if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID))
1074                 return connman_ins_settings.ins_preferred_freq_bssid;
1075
1076         if (g_str_equal(key, CONF_INS_PREFERRED_FREQ))
1077                 return connman_ins_settings.ins_preferred_freq;
1078 #endif
1079         return NULL;
1080 }
1081
1082 bool connman_setting_get_bool(const char *key)
1083 {
1084         if (g_str_equal(key, CONF_BG_SCAN))
1085                 return connman_settings.bg_scan;
1086
1087         if (g_str_equal(key, CONF_ALLOW_HOSTNAME_UPDATES))
1088                 return connman_settings.allow_hostname_updates;
1089
1090         if (g_str_equal(key, CONF_ALLOW_DOMAINNAME_UPDATES))
1091                 return connman_settings.allow_domainname_updates;
1092
1093         if (g_str_equal(key, CONF_SINGLE_TECH))
1094                 return connman_settings.single_tech;
1095
1096         if (g_str_equal(key, CONF_PERSISTENT_TETHERING_MODE))
1097                 return connman_settings.persistent_tethering_mode;
1098
1099         if (g_str_equal(key, CONF_ENABLE_6TO4))
1100                 return connman_settings.enable_6to4;
1101
1102         if (g_str_equal(key, CONF_ENABLE_ONLINE_CHECK))
1103                 return connman_settings.enable_online_check;
1104
1105         if (g_str_equal(key, CONF_AUTO_CONNECT_ROAMING_SERVICES))
1106                 return connman_settings.auto_connect_roaming_services;
1107
1108         if (g_str_equal(key, CONF_ACD))
1109                 return connman_settings.acd;
1110
1111         if (g_str_equal(key, CONF_USE_GATEWAYS_AS_TIMESERVERS))
1112                 return connman_settings.use_gateways_as_timeservers;
1113
1114 #if defined TIZEN_EXT
1115         if (g_str_equal(key, CONF_ENABLE_AUTO_IP))
1116                 return connman_settings.auto_ip;
1117
1118         if (g_str_equal(key, CONF_CONNMAN_SUPPLICANT_DEBUG))
1119                 return connman_settings.supplicant_debug;
1120 #endif
1121
1122 #if defined TIZEN_EXT
1123         if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID))
1124                 return connman_ins_settings.ins_last_connected_bssid;
1125
1126         if (g_str_equal(key, CONF_INS_ASSOC_REJECT))
1127                 return connman_ins_settings.ins_assoc_reject;
1128
1129         if (g_str_equal(key, CONF_INS_SIGNAL_BSSID))
1130                 return connman_ins_settings.ins_signal_bssid;
1131
1132         if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION))
1133                 return connman_ins_settings.ins_last_user_selection;
1134
1135         if (g_str_equal(key, CONF_INS_LAST_CONNECTED))
1136                 return connman_ins_settings.ins_last_connected;
1137
1138         if (g_str_equal(key, CONF_INS_SIGNAL))
1139                 return connman_ins_settings.ins_signal;
1140
1141         if (g_str_equal(key, CONF_INS_INTERNET))
1142                 return connman_ins_settings.ins_internet;
1143 #endif
1144
1145         return false;
1146 }
1147
1148 #if defined TIZEN_EXT
1149 unsigned int connman_setting_get_uint(const char *key)
1150 {
1151         if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID_SCORE))
1152                 return connman_ins_settings.ins_preferred_freq_bssid_score;
1153
1154         if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID_SCORE))
1155                 return connman_ins_settings.ins_last_connected_bssid_score;
1156
1157         if (g_str_equal(key, CONF_INS_ASSOC_REJECT_SCORE))
1158                 return connman_ins_settings.ins_assoc_reject_score;
1159
1160         if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_TIME))
1161                 return connman_ins_settings.ins_last_user_selection_time;
1162
1163         if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_COUNT))
1164                 return connman_ins_settings.ins_security_priority_count;
1165
1166         if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_SCORE))
1167                 return connman_ins_settings.ins_last_user_selection_score;
1168
1169         if (g_str_equal(key, CONF_INS_LAST_CONNECTED_SCORE))
1170                 return connman_ins_settings.ins_last_connected_score;
1171
1172         if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_SCORE))
1173                 return connman_ins_settings.ins_preferred_freq_score;
1174
1175         if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_SCORE))
1176                 return connman_ins_settings.ins_security_priority_score;
1177
1178         if (g_str_equal(key, CONF_INS_INTERNET_SCORE))
1179                 return connman_ins_settings.ins_internet_score;
1180
1181         return 0;
1182 }
1183
1184 int connman_setting_get_int(const char *key)
1185 {
1186         if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_5GHZ))
1187                 return connman_ins_settings.ins_signal_level3_5ghz;
1188
1189         if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_24GHZ))
1190                 return connman_ins_settings.ins_signal_level3_24ghz;
1191
1192         return 0;
1193 }
1194 #endif
1195
1196 char **connman_setting_get_string_list(const char *key)
1197 {
1198         if (g_str_equal(key, CONF_PREF_TIMESERVERS))
1199                 return connman_settings.pref_timeservers;
1200
1201         if (g_str_equal(key, CONF_FALLBACK_NAMESERVERS))
1202                 return connman_settings.fallback_nameservers;
1203
1204         if (g_str_equal(key, CONF_BLACKLISTED_INTERFACES))
1205                 return connman_settings.blacklisted_interfaces;
1206
1207         if (g_str_equal(key, CONF_TETHERING_TECHNOLOGIES))
1208                 return connman_settings.tethering_technologies;
1209
1210 #if defined TIZEN_EXT
1211         if (g_str_equal(key, CONF_CELLULAR_INTERFACE))
1212                 return connman_settings.cellular_interfaces;
1213 #endif
1214
1215 #if defined TIZEN_EXT
1216         if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY))
1217                 return connman_ins_settings.ins_security_priority;
1218 #endif
1219
1220         return NULL;
1221 }
1222
1223 unsigned int *connman_setting_get_uint_list(const char *key)
1224 {
1225         if (g_str_equal(key, CONF_AUTO_CONNECT_TECHS))
1226                 return connman_settings.auto_connect;
1227
1228         if (g_str_equal(key, CONF_FAVORITE_TECHS))
1229                 return connman_settings.favorite_techs;
1230
1231         if (g_str_equal(key, CONF_PREFERRED_TECHS))
1232                 return connman_settings.preferred_techs;
1233
1234         if (g_str_equal(key, CONF_ALWAYS_CONNECTED_TECHS))
1235                 return connman_settings.always_connected_techs;
1236
1237         return NULL;
1238 }
1239
1240 unsigned int connman_timeout_input_request(void)
1241 {
1242         return connman_settings.timeout_inputreq;
1243 }
1244
1245 unsigned int connman_timeout_browser_launch(void)
1246 {
1247         return connman_settings.timeout_browserlaunch;
1248 }
1249
1250 int main(int argc, char *argv[])
1251 {
1252         GOptionContext *context;
1253         GError *error = NULL;
1254         DBusConnection *conn;
1255         DBusError err;
1256         guint signal;
1257
1258         context = g_option_context_new(NULL);
1259         g_option_context_add_main_entries(context, options, NULL);
1260
1261         if (!g_option_context_parse(context, &argc, &argv, &error)) {
1262                 if (error) {
1263                         g_printerr("%s\n", error->message);
1264                         g_error_free(error);
1265                 } else
1266                         g_printerr("An unknown error occurred\n");
1267                 exit(1);
1268         }
1269
1270         g_option_context_free(context);
1271
1272         if (option_version) {
1273                 printf("%s\n", VERSION);
1274                 exit(0);
1275         }
1276
1277         if (option_detach) {
1278                 if (daemon(0, 0)) {
1279                         perror("Can't start daemon");
1280                         exit(1);
1281                 }
1282         }
1283
1284         if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
1285                                 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
1286                 if (errno != EEXIST)
1287                         perror("Failed to create storage directory");
1288         }
1289
1290         umask(0077);
1291
1292         main_loop = g_main_loop_new(NULL, FALSE);
1293
1294         signal = setup_signalfd();
1295
1296         dbus_error_init(&err);
1297
1298         conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
1299         if (!conn) {
1300                 if (dbus_error_is_set(&err)) {
1301                         fprintf(stderr, "%s\n", err.message);
1302                         dbus_error_free(&err);
1303                 } else
1304                         fprintf(stderr, "Can't register with system bus\n");
1305                 exit(1);
1306         }
1307
1308         g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
1309
1310         __connman_log_init(argv[0], option_debug, option_detach,
1311                         option_backtrace, "Connection Manager", VERSION);
1312
1313         __connman_dbus_init(conn);
1314
1315         if (!option_config)
1316                 config_init(CONFIGMAINFILE);
1317         else
1318                 config_init(option_config);
1319
1320         __connman_util_init();
1321         __connman_inotify_init();
1322         __connman_technology_init();
1323         __connman_notifier_init();
1324         __connman_agent_init();
1325         __connman_service_init();
1326         __connman_peer_service_init();
1327         __connman_peer_init();
1328 #if defined TIZEN_EXT_WIFI_MESH
1329         __connman_mesh_init();
1330 #endif /* TIZEN_EXT_WIFI_MESH */
1331         __connman_provider_init();
1332         __connman_network_init();
1333         __connman_config_init();
1334         __connman_device_init(option_device, option_nodevice);
1335
1336         __connman_ippool_init();
1337         __connman_firewall_init();
1338         __connman_nat_init();
1339         __connman_tethering_init();
1340         __connman_counter_init();
1341         __connman_manager_init();
1342         __connman_stats_init();
1343         __connman_clock_init();
1344
1345         __connman_ipconfig_init();
1346         __connman_rtnl_init();
1347         __connman_task_init();
1348         __connman_proxy_init();
1349         __connman_detect_init();
1350         __connman_session_init();
1351         __connman_timeserver_init();
1352         __connman_connection_init();
1353
1354         __connman_plugin_init(option_plugin, option_noplugin);
1355
1356         __connman_resolver_init(option_dnsproxy);
1357         __connman_rtnl_start();
1358         __connman_dhcp_init();
1359         __connman_dhcpv6_init();
1360         __connman_wpad_init();
1361         __connman_wispr_init();
1362 #if !defined TIZEN_EXT
1363         __connman_rfkill_init();
1364         __connman_machine_init();
1365 #endif
1366
1367         g_free(option_config);
1368         g_free(option_device);
1369         g_free(option_plugin);
1370         g_free(option_nodevice);
1371         g_free(option_noplugin);
1372
1373         g_main_loop_run(main_loop);
1374
1375         g_source_remove(signal);
1376
1377 #if !defined TIZEN_EXT
1378         __connman_machine_cleanup();
1379         __connman_rfkill_cleanup();
1380 #endif
1381         __connman_wispr_cleanup();
1382         __connman_wpad_cleanup();
1383         __connman_dhcpv6_cleanup();
1384         __connman_session_cleanup();
1385         __connman_plugin_cleanup();
1386         __connman_provider_cleanup();
1387         __connman_connection_cleanup();
1388         __connman_timeserver_cleanup();
1389         __connman_detect_cleanup();
1390         __connman_proxy_cleanup();
1391         __connman_task_cleanup();
1392         __connman_rtnl_cleanup();
1393         __connman_resolver_cleanup();
1394
1395         __connman_clock_cleanup();
1396         __connman_stats_cleanup();
1397         __connman_config_cleanup();
1398         __connman_manager_cleanup();
1399         __connman_counter_cleanup();
1400         __connman_tethering_cleanup();
1401         __connman_nat_cleanup();
1402         __connman_firewall_cleanup();
1403         __connman_peer_service_cleanup();
1404         __connman_peer_cleanup();
1405 #if defined TIZEN_EXT_WIFI_MESH
1406         __connman_mesh_cleanup();
1407 #endif /* TIZEN_EXT_WIFI_MESH */
1408         __connman_ippool_cleanup();
1409         __connman_device_cleanup();
1410         __connman_network_cleanup();
1411         __connman_dhcp_cleanup();
1412         __connman_service_cleanup();
1413         __connman_agent_cleanup();
1414         __connman_ipconfig_cleanup();
1415         __connman_notifier_cleanup();
1416         __connman_technology_cleanup();
1417         __connman_inotify_cleanup();
1418
1419         __connman_util_cleanup();
1420         __connman_dbus_cleanup();
1421
1422         __connman_log_cleanup(option_backtrace);
1423
1424         dbus_connection_unref(conn);
1425
1426         g_main_loop_unref(main_loop);
1427
1428         if (connman_settings.pref_timeservers)
1429                 g_strfreev(connman_settings.pref_timeservers);
1430
1431         g_free(connman_settings.auto_connect);
1432         g_free(connman_settings.favorite_techs);
1433         g_free(connman_settings.preferred_techs);
1434         g_strfreev(connman_settings.fallback_nameservers);
1435         g_strfreev(connman_settings.blacklisted_interfaces);
1436         g_strfreev(connman_settings.tethering_technologies);
1437
1438 #if defined TIZEN_EXT
1439         g_free(connman_ins_settings.ins_preferred_freq_bssid);
1440         g_free(connman_ins_settings.ins_preferred_freq);
1441         if (connman_ins_settings.ins_security_priority)
1442                 g_strfreev(connman_ins_settings.ins_security_priority);
1443 #endif
1444
1445         g_free(option_debug);
1446         g_free(option_wifi);
1447
1448         return 0;
1449 }