5 * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
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.
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.
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
32 #include <sys/signalfd.h>
38 #include <sys/resource.h>
44 #define CONF_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]) - 1)
46 #define DEFAULT_INPUT_REQUEST_TIMEOUT (120 * 1000)
47 #define DEFAULT_BROWSER_LAUNCH_TIMEOUT (300 * 1000)
50 #define DEFAULT_WIFI_INTERFACE "wlan0"
51 #define CONTAINER_FILE "/run/systemd/container"
54 #define MAINFILE "main.conf"
55 #define CONFIGMAINFILE CONFIGDIR "/" MAINFILE
57 static char *default_auto_connect[] = {
64 static char *default_favorite_techs[] = {
69 static char *default_blacklist[] = {
81 char **pref_timeservers;
82 unsigned int *auto_connect;
83 unsigned int *favorite_techs;
84 unsigned int *preferred_techs;
85 unsigned int *always_connected_techs;
86 char **fallback_nameservers;
87 unsigned int timeout_inputreq;
88 unsigned int timeout_browserlaunch;
89 char **blacklisted_interfaces;
90 bool allow_hostname_updates;
91 bool allow_domainname_updates;
93 char **tethering_technologies;
94 bool persistent_tethering_mode;
96 char *vendor_class_id;
97 bool enable_online_check;
98 bool auto_connect_roaming_services;
100 bool use_gateways_as_timeservers;
101 #if defined TIZEN_EXT
102 char **cellular_interfaces;
103 bool tizen_tv_extension;
105 char *global_nameserver;
106 bool supplicant_debug;
107 char *def_wifi_ifname;
112 } connman_settings = {
114 .pref_timeservers = NULL,
115 .auto_connect = NULL,
116 .favorite_techs = NULL,
117 .preferred_techs = NULL,
118 .always_connected_techs = NULL,
119 .fallback_nameservers = NULL,
120 .timeout_inputreq = DEFAULT_INPUT_REQUEST_TIMEOUT,
121 .timeout_browserlaunch = DEFAULT_BROWSER_LAUNCH_TIMEOUT,
122 .blacklisted_interfaces = NULL,
123 .allow_hostname_updates = true,
124 .allow_domainname_updates = true,
125 .single_tech = false,
126 .tethering_technologies = NULL,
127 .persistent_tethering_mode = false,
128 .enable_6to4 = false,
129 .vendor_class_id = NULL,
130 .enable_online_check = true,
131 .auto_connect_roaming_services = false,
133 .use_gateways_as_timeservers = false,
134 #if defined TIZEN_EXT
135 .cellular_interfaces = NULL,
136 .tizen_tv_extension = false,
138 .global_nameserver = NULL,
139 .supplicant_debug = false,
140 .def_wifi_ifname = DEFAULT_WIFI_INTERFACE,
147 #if defined TIZEN_EXT
150 char *ins_preferred_freq_bssid;
151 bool ins_last_connected_bssid;
152 bool ins_assoc_reject;
153 bool ins_signal_bssid;
154 unsigned int ins_preferred_freq_bssid_score;
155 unsigned int ins_last_connected_bssid_score;
156 unsigned int ins_assoc_reject_score;
158 bool ins_last_user_selection;
159 unsigned int ins_last_user_selection_time;
160 bool ins_last_connected;
161 char *ins_preferred_freq;
162 char **ins_security_priority;
163 unsigned int ins_security_priority_count;
166 unsigned int ins_last_user_selection_score;
167 unsigned int ins_last_connected_score;
168 unsigned int ins_preferred_freq_score;
169 unsigned int ins_security_priority_score;
170 unsigned int ins_internet_score;
172 int ins_signal_level3_5ghz;
173 int ins_signal_level3_24ghz;
174 } connman_ins_settings = {
176 .ins_preferred_freq_bssid = NULL,
177 .ins_last_connected_bssid = true,
178 .ins_assoc_reject = true,
179 .ins_signal_bssid = true,
180 .ins_preferred_freq_bssid_score = 20,
181 .ins_last_connected_bssid_score = 20,
182 .ins_assoc_reject_score = 10,
184 .ins_last_user_selection = true,
185 .ins_last_user_selection_time = 480,
186 .ins_last_connected = true,
187 .ins_preferred_freq = NULL,
188 .ins_security_priority = NULL,
189 .ins_security_priority_count = 0,
191 .ins_internet = true,
192 .ins_last_user_selection_score = 30,
193 .ins_last_connected_score = 30,
194 .ins_preferred_freq_score = 60,
195 .ins_security_priority_score = 5,
196 .ins_internet_score = 30,
198 .ins_signal_level3_5ghz = -76,
199 .ins_signal_level3_24ghz = -74,
203 #define CONF_BG_SCAN "BackgroundScanning"
204 #define CONF_PREF_TIMESERVERS "FallbackTimeservers"
205 #define CONF_AUTO_CONNECT_TECHS "DefaultAutoConnectTechnologies"
206 #define CONF_FAVORITE_TECHS "DefaultFavoriteTechnologies"
207 #define CONF_ALWAYS_CONNECTED_TECHS "AlwaysConnectedTechnologies"
208 #define CONF_PREFERRED_TECHS "PreferredTechnologies"
209 #define CONF_FALLBACK_NAMESERVERS "FallbackNameservers"
210 #define CONF_TIMEOUT_INPUTREQ "InputRequestTimeout"
211 #define CONF_TIMEOUT_BROWSERLAUNCH "BrowserLaunchTimeout"
212 #define CONF_BLACKLISTED_INTERFACES "NetworkInterfaceBlacklist"
213 #define CONF_ALLOW_HOSTNAME_UPDATES "AllowHostnameUpdates"
214 #define CONF_ALLOW_DOMAINNAME_UPDATES "AllowDomainnameUpdates"
215 #define CONF_SINGLE_TECH "SingleConnectedTechnology"
216 #define CONF_TETHERING_TECHNOLOGIES "TetheringTechnologies"
217 #define CONF_PERSISTENT_TETHERING_MODE "PersistentTetheringMode"
218 #define CONF_ENABLE_6TO4 "Enable6to4"
219 #define CONF_VENDOR_CLASS_ID "VendorClassID"
220 #define CONF_ENABLE_ONLINE_CHECK "EnableOnlineCheck"
221 #define CONF_AUTO_CONNECT_ROAMING_SERVICES "AutoConnectRoamingServices"
222 #define CONF_ACD "AddressConflictDetection"
223 #define CONF_USE_GATEWAYS_AS_TIMESERVERS "UseGatewaysAsTimeservers"
224 #if defined TIZEN_EXT
225 #define CONF_CELLULAR_INTERFACE "NetworkCellularInterfaceList"
226 #define CONF_TIZEN_TV_EXT "TizenTVExtension"
227 #define CONF_ENABLE_AUTO_IP "EnableAutoIp"
228 #define CONF_GLOBAL_NAMESERVER "GlobalNameserver"
229 #define CONF_CONNMAN_SUPPLICANT_DEBUG "ConnmanSupplicantDebug"
230 #define CONF_CONNMAN_WIFI_DEF_IFNAME "DefaultWifiInterface"
231 #define CONF_CONNMAN_FILE_LOG "FileLogging"
232 #define CONF_CONNMAN_DLOG_LOG "DlogLogging"
233 #define CONF_CONNMAN_SIMPLIFIED_LOG "SimplifiedLog"
236 #if defined TIZEN_EXT
238 #define CONF_INS_PREFERRED_FREQ_BSSID "INSPreferredFreqBSSID"
239 #define CONF_INS_PREFERRED_FREQ_BSSID_SCORE "INSPreferredFreqBSSIDScore"
240 #define CONF_INS_LAST_CONNECTED_BSSID "INSLastConnectedBSSID"
241 #define CONF_INS_LAST_CONNECTED_BSSID_SCORE "INSLastConnectedBSSIDScore"
242 #define CONF_INS_ASSOC_REJECT "INSAssocReject"
243 #define CONF_INS_ASSOC_REJECT_SCORE "INSAssocRejectScore"
244 #define CONF_INS_SIGNAL_BSSID "INSSignalBSSID"
246 #define CONF_INS_LAST_USER_SELECTION "INSLastUserSelection"
247 #define CONF_INS_LAST_USER_SELECTION_TIME "INSLastUserSelectionTime"
248 #define CONF_INS_LAST_USER_SELECTION_SCORE "INSLastUserSelectionScore"
249 #define CONF_INS_LAST_CONNECTED "INSLastConnected"
250 #define CONF_INS_LAST_CONNECTED_SCORE "INSLastConnectedScore"
251 #define CONF_INS_PREFERRED_FREQ "INSPreferredFreq"
252 #define CONF_INS_PREFERRED_FREQ_SCORE "INSPreferredFreqScore"
253 #define CONF_INS_SECURITY_PRIORITY "INSSecurityPriority"
254 #define CONF_INS_SECURITY_PRIORITY_COUNT "INSSecurityPriorityCount"
255 #define CONF_INS_SECURITY_PRIORITY_SCORE "INSSecurityPriorityScore"
256 #define CONF_INS_SIGNAL "INSSignal"
257 #define CONF_INS_INTERNET "INSInternet"
258 #define CONF_INS_INTERNET_SCORE "INSInternetScore"
260 #define CONF_INS_SIGNAL_LEVEL3_5GHZ "INSSignalLevel3_5GHz"
261 #define CONF_INS_SIGNAL_LEVEL3_24GHZ "INSSignalLevel3_24GHz"
264 static const char *supported_options[] = {
266 CONF_PREF_TIMESERVERS,
267 CONF_AUTO_CONNECT_TECHS,
268 CONF_ALWAYS_CONNECTED_TECHS,
269 CONF_PREFERRED_TECHS,
270 CONF_FALLBACK_NAMESERVERS,
271 CONF_TIMEOUT_INPUTREQ,
272 CONF_TIMEOUT_BROWSERLAUNCH,
273 CONF_BLACKLISTED_INTERFACES,
274 CONF_ALLOW_HOSTNAME_UPDATES,
275 CONF_ALLOW_DOMAINNAME_UPDATES,
277 CONF_TETHERING_TECHNOLOGIES,
278 CONF_PERSISTENT_TETHERING_MODE,
280 CONF_VENDOR_CLASS_ID,
281 CONF_ENABLE_ONLINE_CHECK,
282 CONF_AUTO_CONNECT_ROAMING_SERVICES,
284 CONF_USE_GATEWAYS_AS_TIMESERVERS,
285 #if defined TIZEN_EXT
286 CONF_CELLULAR_INTERFACE,
289 CONF_GLOBAL_NAMESERVER,
290 CONF_CONNMAN_SUPPLICANT_DEBUG,
291 CONF_CONNMAN_WIFI_DEF_IFNAME,
292 CONF_CONNMAN_FILE_LOG,
293 CONF_CONNMAN_DLOG_LOG,
294 CONF_CONNMAN_SIMPLIFIED_LOG,
299 #if defined TIZEN_EXT
300 static const char *supported_ins_options[] = {
302 CONF_INS_PREFERRED_FREQ_BSSID,
303 CONF_INS_PREFERRED_FREQ_BSSID_SCORE,
304 CONF_INS_LAST_CONNECTED_BSSID,
305 CONF_INS_LAST_CONNECTED_BSSID_SCORE,
306 CONF_INS_ASSOC_REJECT,
307 CONF_INS_ASSOC_REJECT_SCORE,
308 CONF_INS_SIGNAL_BSSID,
310 CONF_INS_LAST_USER_SELECTION,
311 CONF_INS_LAST_USER_SELECTION_TIME,
312 CONF_INS_LAST_USER_SELECTION_SCORE,
313 CONF_INS_LAST_CONNECTED,
314 CONF_INS_LAST_CONNECTED_SCORE,
315 CONF_INS_PREFERRED_FREQ,
316 CONF_INS_PREFERRED_FREQ_SCORE,
317 CONF_INS_SECURITY_PRIORITY,
318 CONF_INS_SECURITY_PRIORITY_COUNT,
319 CONF_INS_SECURITY_PRIORITY_SCORE,
322 CONF_INS_INTERNET_SCORE,
324 CONF_INS_SIGNAL_LEVEL3_5GHZ,
325 CONF_INS_SIGNAL_LEVEL3_24GHZ,
330 static GKeyFile *load_config(const char *file)
335 keyfile = g_key_file_new();
337 g_key_file_set_list_separator(keyfile, ',');
339 if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
340 if (err->code != G_FILE_ERROR_NOENT) {
341 connman_error("Parsing %s failed: %s", file,
346 g_key_file_free(keyfile);
353 static uint *parse_service_types(char **str_list, gsize len)
355 unsigned int *type_list;
357 enum connman_service_type type;
359 type_list = g_try_new0(unsigned int, len + 1);
365 while (str_list[i]) {
366 type = __connman_service_string2type(str_list[i]);
368 if (type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
375 type_list[j] = CONNMAN_SERVICE_TYPE_UNKNOWN;
380 static char **parse_fallback_nameservers(char **nameservers, gsize len)
385 servers = g_try_new0(char *, len + 1);
391 while (nameservers[i]) {
392 if (connman_inet_check_ipaddress(nameservers[i]) > 0) {
393 servers[j] = g_strdup(nameservers[i]);
402 static void check_config(GKeyFile *config)
410 keys = g_key_file_get_groups(config, NULL);
412 for (j = 0; keys && keys[j]; j++) {
413 #if defined TIZEN_EXT
414 if (g_strcmp0(keys[j], "General") != 0 &&
415 g_strcmp0(keys[j], "INS") != 0)
417 if (g_strcmp0(keys[j], "General") != 0)
419 connman_warn("Unknown group %s in %s",
425 keys = g_key_file_get_keys(config, "General", NULL, NULL);
427 for (j = 0; keys && keys[j]; j++) {
432 for (i = 0; supported_options[i]; i++) {
433 if (g_strcmp0(keys[j], supported_options[i]) == 0) {
438 if (!found && !supported_options[i])
439 connman_warn("Unknown option %s in %s",
445 #if defined TIZEN_EXT
446 keys = g_key_file_get_keys(config, "INS", NULL, NULL);
448 for (j = 0; keys && keys[j]; j++) {
453 for (i = 0; supported_ins_options[i]; i++) {
454 if (g_strcmp0(keys[j], supported_ins_options[i]) == 0) {
459 if (!found && !supported_ins_options[i])
460 connman_warn("Unknown option %s in %s",
468 #if defined TIZEN_EXT
469 static void check_Tizen_INS_configuration(GKeyFile *config)
471 GError *error = NULL;
472 char *ins_preferred_freq_bssid;
473 char *ins_preferred_freq;
474 char **ins_security_priority;
479 ins_preferred_freq_bssid = __connman_config_get_string(config, "INS",
480 CONF_INS_PREFERRED_FREQ_BSSID, &error);
482 connman_ins_settings.ins_preferred_freq_bssid = ins_preferred_freq_bssid;
484 g_clear_error(&error);
486 integer = g_key_file_get_integer(config, "INS",
487 CONF_INS_PREFERRED_FREQ_BSSID_SCORE, &error);
488 if (!error && integer >= 0)
489 connman_ins_settings.ins_preferred_freq_bssid_score = integer;
491 g_clear_error(&error);
493 boolean = __connman_config_get_bool(config, "INS",
494 CONF_INS_LAST_CONNECTED_BSSID, &error);
496 connman_ins_settings.ins_last_connected_bssid = boolean;
498 g_clear_error(&error);
500 integer = g_key_file_get_integer(config, "INS",
501 CONF_INS_LAST_CONNECTED_BSSID_SCORE, &error);
502 if (!error && integer >= 0)
503 connman_ins_settings.ins_last_connected_bssid_score = integer;
505 g_clear_error(&error);
507 boolean = __connman_config_get_bool(config, "INS",
508 CONF_INS_ASSOC_REJECT, &error);
510 connman_ins_settings.ins_assoc_reject = boolean;
512 g_clear_error(&error);
514 integer = g_key_file_get_integer(config, "INS",
515 CONF_INS_ASSOC_REJECT_SCORE, &error);
516 if (!error && integer >= 0)
517 connman_ins_settings.ins_assoc_reject_score = integer;
519 g_clear_error(&error);
521 boolean = __connman_config_get_bool(config, "INS",
522 CONF_INS_SIGNAL_BSSID, &error);
524 connman_ins_settings.ins_signal_bssid = boolean;
526 g_clear_error(&error);
528 boolean = __connman_config_get_bool(config, "INS",
529 CONF_INS_LAST_USER_SELECTION, &error);
531 connman_ins_settings.ins_last_user_selection = boolean;
533 g_clear_error(&error);
535 integer = g_key_file_get_integer(config, "INS",
536 CONF_INS_LAST_USER_SELECTION_TIME, &error);
537 if (!error && integer >= 0)
538 connman_ins_settings.ins_last_user_selection_time = integer;
540 g_clear_error(&error);
542 integer = g_key_file_get_integer(config, "INS",
543 CONF_INS_LAST_USER_SELECTION_SCORE, &error);
544 if (!error && integer >= 0)
545 connman_ins_settings.ins_last_user_selection_score = integer;
547 g_clear_error(&error);
549 boolean = __connman_config_get_bool(config, "INS",
550 CONF_INS_LAST_CONNECTED, &error);
552 connman_ins_settings.ins_last_connected = boolean;
554 g_clear_error(&error);
556 integer = g_key_file_get_integer(config, "INS",
557 CONF_INS_LAST_CONNECTED_SCORE, &error);
558 if (!error && integer >= 0)
559 connman_ins_settings.ins_last_connected_score = integer;
561 g_clear_error(&error);
563 ins_preferred_freq = __connman_config_get_string(config, "INS",
564 CONF_INS_PREFERRED_FREQ, &error);
566 connman_ins_settings.ins_preferred_freq = ins_preferred_freq;
568 g_clear_error(&error);
570 integer = g_key_file_get_integer(config, "INS",
571 CONF_INS_PREFERRED_FREQ_SCORE, &error);
572 if (!error && integer >= 0)
573 connman_ins_settings.ins_preferred_freq_score = integer;
575 g_clear_error(&error);
577 ins_security_priority = g_key_file_get_string_list(config, "INS",
578 CONF_INS_SECURITY_PRIORITY, &len, &error);
581 connman_ins_settings.ins_security_priority = ins_security_priority;
582 connman_ins_settings.ins_security_priority_count = len;
585 g_clear_error(&error);
587 integer = g_key_file_get_integer(config, "INS",
588 CONF_INS_SECURITY_PRIORITY_SCORE, &error);
589 if (!error && integer >= 0)
590 connman_ins_settings.ins_security_priority_score = integer;
592 g_clear_error(&error);
594 boolean = __connman_config_get_bool(config, "INS",
595 CONF_INS_SIGNAL, &error);
597 connman_ins_settings.ins_signal = boolean;
599 g_clear_error(&error);
601 boolean = __connman_config_get_bool(config, "INS",
602 CONF_INS_INTERNET, &error);
604 connman_ins_settings.ins_internet = boolean;
606 g_clear_error(&error);
608 integer = g_key_file_get_integer(config, "INS",
609 CONF_INS_INTERNET_SCORE, &error);
610 if (!error && integer >= 0)
611 connman_ins_settings.ins_internet_score = integer;
613 g_clear_error(&error);
615 integer = g_key_file_get_integer(config, "INS",
616 CONF_INS_SIGNAL_LEVEL3_5GHZ, &error);
618 connman_ins_settings.ins_signal_level3_5ghz = integer;
620 g_clear_error(&error);
622 integer = g_key_file_get_integer(config, "INS",
623 CONF_INS_SIGNAL_LEVEL3_24GHZ, &error);
625 connman_ins_settings.ins_signal_level3_24ghz = integer;
627 g_clear_error(&error);
630 static void check_Tizen_configuration(GKeyFile *config)
632 GError *error = NULL;
633 char **cellular_interfaces;
634 char *global_nameserver;
635 char *default_wifi_ifname;
639 cellular_interfaces = g_key_file_get_string_list(config, "General",
640 CONF_CELLULAR_INTERFACE, &len, &error);
643 connman_settings.cellular_interfaces = cellular_interfaces;
645 g_clear_error(&error);
647 boolean = __connman_config_get_bool(config, "General",
648 CONF_TIZEN_TV_EXT, &error);
650 connman_settings.tizen_tv_extension = boolean;
652 g_clear_error(&error);
654 boolean = __connman_config_get_bool(config, "General",
655 CONF_ENABLE_AUTO_IP, &error);
657 connman_settings.auto_ip = boolean;
659 g_clear_error(&error);
661 global_nameserver = __connman_config_get_string(config, "General",
662 CONF_GLOBAL_NAMESERVER, &error);
664 connman_settings.global_nameserver = global_nameserver;
666 g_clear_error(&error);
668 boolean = __connman_config_get_bool(config, "General",
669 CONF_CONNMAN_SUPPLICANT_DEBUG, &error);
671 connman_settings.supplicant_debug = boolean;
673 g_clear_error(&error);
675 default_wifi_ifname = __connman_config_get_string(config, "General",
676 CONF_CONNMAN_WIFI_DEF_IFNAME, &error);
678 connman_settings.def_wifi_ifname = default_wifi_ifname;
680 g_clear_error(&error);
682 boolean = __connman_config_get_bool(config, "General",
683 CONF_CONNMAN_FILE_LOG, &error);
685 connman_settings.file_log = boolean;
687 g_clear_error(&error);
689 boolean = __connman_config_get_bool(config, "General",
690 CONF_CONNMAN_DLOG_LOG, &error);
692 connman_settings.dlog_log = boolean;
694 g_clear_error(&error);
696 boolean = __connman_config_get_bool(config, "General",
697 CONF_CONNMAN_SIMPLIFIED_LOG, &error);
699 connman_settings.simple_log = boolean;
701 g_clear_error(&error);
703 check_Tizen_INS_configuration(config);
706 static void set_nofile_inc(void)
711 rlim.rlim_cur = 8192;
712 rlim.rlim_max = 8192;
714 err = setrlimit(RLIMIT_NOFILE, &rlim);
716 DBG("fail to increase FILENO err(%d)", err);
722 static void parse_config(GKeyFile *config)
724 GError *error = NULL;
730 char *vendor_class_id;
735 connman_settings.auto_connect =
736 parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
737 connman_settings.favorite_techs =
738 parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
739 connman_settings.blacklisted_interfaces =
740 g_strdupv(default_blacklist);
744 DBG("parsing %s", MAINFILE);
746 boolean = g_key_file_get_boolean(config, "General",
747 CONF_BG_SCAN, &error);
749 connman_settings.bg_scan = boolean;
751 g_clear_error(&error);
753 timeservers = __connman_config_get_string_list(config, "General",
754 CONF_PREF_TIMESERVERS, NULL, &error);
756 connman_settings.pref_timeservers = timeservers;
758 g_clear_error(&error);
760 str_list = __connman_config_get_string_list(config, "General",
761 CONF_AUTO_CONNECT_TECHS, &len, &error);
764 connman_settings.auto_connect =
765 parse_service_types(str_list, len);
767 connman_settings.auto_connect =
768 parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
770 g_strfreev(str_list);
772 g_clear_error(&error);
774 str_list = __connman_config_get_string_list(config, "General",
775 CONF_FAVORITE_TECHS, &len, &error);
778 connman_settings.favorite_techs =
779 parse_service_types(str_list, len);
781 connman_settings.favorite_techs =
782 parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
784 g_strfreev(str_list);
786 g_clear_error(&error);
788 str_list = __connman_config_get_string_list(config, "General",
789 CONF_PREFERRED_TECHS, &len, &error);
792 connman_settings.preferred_techs =
793 parse_service_types(str_list, len);
795 g_strfreev(str_list);
797 g_clear_error(&error);
799 str_list = __connman_config_get_string_list(config, "General",
800 CONF_ALWAYS_CONNECTED_TECHS, &len, &error);
803 connman_settings.always_connected_techs =
804 parse_service_types(str_list, len);
806 g_strfreev(str_list);
808 g_clear_error(&error);
810 str_list = __connman_config_get_string_list(config, "General",
811 CONF_FALLBACK_NAMESERVERS, &len, &error);
814 connman_settings.fallback_nameservers =
815 parse_fallback_nameservers(str_list, len);
817 g_strfreev(str_list);
819 g_clear_error(&error);
821 timeout = g_key_file_get_integer(config, "General",
822 CONF_TIMEOUT_INPUTREQ, &error);
823 if (!error && timeout >= 0)
824 connman_settings.timeout_inputreq = timeout * 1000;
826 g_clear_error(&error);
828 timeout = g_key_file_get_integer(config, "General",
829 CONF_TIMEOUT_BROWSERLAUNCH, &error);
830 if (!error && timeout >= 0)
831 connman_settings.timeout_browserlaunch = timeout * 1000;
833 g_clear_error(&error);
835 interfaces = __connman_config_get_string_list(config, "General",
836 CONF_BLACKLISTED_INTERFACES, &len, &error);
839 connman_settings.blacklisted_interfaces = interfaces;
841 connman_settings.blacklisted_interfaces =
842 g_strdupv(default_blacklist);
844 g_clear_error(&error);
846 boolean = __connman_config_get_bool(config, "General",
847 CONF_ALLOW_HOSTNAME_UPDATES,
850 connman_settings.allow_hostname_updates = boolean;
852 g_clear_error(&error);
854 boolean = __connman_config_get_bool(config, "General",
855 CONF_ALLOW_DOMAINNAME_UPDATES,
858 connman_settings.allow_domainname_updates = boolean;
860 g_clear_error(&error);
862 boolean = __connman_config_get_bool(config, "General",
863 CONF_SINGLE_TECH, &error);
865 connman_settings.single_tech = boolean;
867 g_clear_error(&error);
869 tethering = __connman_config_get_string_list(config, "General",
870 CONF_TETHERING_TECHNOLOGIES, &len, &error);
873 connman_settings.tethering_technologies = tethering;
875 g_clear_error(&error);
877 boolean = __connman_config_get_bool(config, "General",
878 CONF_PERSISTENT_TETHERING_MODE,
881 connman_settings.persistent_tethering_mode = boolean;
883 g_clear_error(&error);
885 boolean = __connman_config_get_bool(config, "General",
886 CONF_ENABLE_6TO4, &error);
888 connman_settings.enable_6to4 = boolean;
890 g_clear_error(&error);
892 vendor_class_id = __connman_config_get_string(config, "General",
893 CONF_VENDOR_CLASS_ID, &error);
895 connman_settings.vendor_class_id = vendor_class_id;
897 g_clear_error(&error);
899 boolean = __connman_config_get_bool(config, "General",
900 CONF_ENABLE_ONLINE_CHECK, &error);
902 connman_settings.enable_online_check = boolean;
904 connman_info("Online check disabled by main config.");
907 g_clear_error(&error);
909 boolean = __connman_config_get_bool(config, "General",
910 CONF_AUTO_CONNECT_ROAMING_SERVICES, &error);
912 connman_settings.auto_connect_roaming_services = boolean;
914 g_clear_error(&error);
916 boolean = __connman_config_get_bool(config, "General", CONF_ACD, &error);
918 connman_settings.acd = boolean;
920 g_clear_error(&error);
922 boolean = __connman_config_get_bool(config, "General",
923 CONF_USE_GATEWAYS_AS_TIMESERVERS, &error);
925 connman_settings.use_gateways_as_timeservers = boolean;
927 g_clear_error(&error);
929 #if defined TIZEN_EXT
930 check_Tizen_configuration(config);
934 static int config_init(const char *file)
938 #if defined TIZEN_EXT
941 config = load_config(file);
942 check_config(config);
943 parse_config(config);
945 g_key_file_free(config);
947 #if defined TIZEN_EXT
948 set_simple_log_option(connman_settings.simple_log);
949 set_dlog_logging_option(connman_settings.dlog_log);
950 set_file_logging_option(connman_settings.file_log);
955 static GMainLoop *main_loop = NULL;
957 static unsigned int __terminated = 0;
959 static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
962 struct signalfd_siginfo si;
966 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
969 fd = g_io_channel_unix_get_fd(channel);
971 result = read(fd, &si, sizeof(si));
972 if (result != sizeof(si))
975 switch (si.ssi_signo) {
978 if (__terminated == 0) {
979 connman_info("Terminating");
980 g_main_loop_quit(main_loop);
990 static guint setup_signalfd(void)
998 sigaddset(&mask, SIGINT);
999 sigaddset(&mask, SIGTERM);
1001 if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
1002 perror("Failed to set signal mask");
1006 fd = signalfd(-1, &mask, 0);
1008 perror("Failed to create signal descriptor");
1012 channel = g_io_channel_unix_new(fd);
1014 g_io_channel_set_close_on_unref(channel, TRUE);
1015 g_io_channel_set_encoding(channel, NULL, NULL);
1016 g_io_channel_set_buffered(channel, FALSE);
1018 source = g_io_add_watch(channel,
1019 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1020 signal_handler, NULL);
1022 g_io_channel_unref(channel);
1027 static void disconnect_callback(DBusConnection *conn, void *user_data)
1029 connman_error("D-Bus disconnect");
1031 g_main_loop_quit(main_loop);
1034 static gchar *option_config = NULL;
1035 static gchar *option_debug = NULL;
1036 static gchar *option_device = NULL;
1037 static gchar *option_plugin = NULL;
1038 static gchar *option_nodevice = NULL;
1039 static gchar *option_noplugin = NULL;
1040 static gchar *option_wifi = NULL;
1041 static gboolean option_detach = TRUE;
1042 static gboolean option_dnsproxy = TRUE;
1043 static gboolean option_backtrace = TRUE;
1044 static gboolean option_version = FALSE;
1046 static bool parse_debug(const char *key, const char *value,
1047 gpointer user_data, GError **error)
1051 char *prev = option_debug;
1053 option_debug = g_strconcat(prev, ",", value, NULL);
1056 option_debug = g_strdup(value);
1059 g_free(option_debug);
1060 option_debug = g_strdup("*");
1066 static bool parse_noplugin(const char *key, const char *value,
1067 gpointer user_data, GError **error)
1069 if (option_noplugin) {
1070 char *prev = option_noplugin;
1072 option_noplugin = g_strconcat(prev, ",", value, NULL);
1075 option_noplugin = g_strdup(value);
1081 static GOptionEntry options[] = {
1082 { "config", 'c', 0, G_OPTION_ARG_STRING, &option_config,
1083 "Load the specified configuration file "
1084 "instead of " CONFIGMAINFILE, "FILE" },
1085 { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
1086 G_OPTION_ARG_CALLBACK, parse_debug,
1087 "Specify debug options to enable", "DEBUG" },
1088 { "device", 'i', 0, G_OPTION_ARG_STRING, &option_device,
1089 "Specify networking devices or interfaces", "DEV,..." },
1090 { "nodevice", 'I', 0, G_OPTION_ARG_STRING, &option_nodevice,
1091 "Specify networking interfaces to ignore", "DEV,..." },
1092 { "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin,
1093 "Specify plugins to load", "NAME,..." },
1094 { "noplugin", 'P', 0, G_OPTION_ARG_CALLBACK, &parse_noplugin,
1095 "Specify plugins not to load", "NAME,..." },
1096 { "wifi", 'W', 0, G_OPTION_ARG_STRING, &option_wifi,
1097 "Specify driver for WiFi/Supplicant", "NAME" },
1098 { "nodaemon", 'n', G_OPTION_FLAG_REVERSE,
1099 G_OPTION_ARG_NONE, &option_detach,
1100 "Don't fork daemon to background" },
1101 { "nodnsproxy", 'r', G_OPTION_FLAG_REVERSE,
1102 G_OPTION_ARG_NONE, &option_dnsproxy,
1103 "Don't support DNS resolving" },
1104 { "nobacktrace", 0, G_OPTION_FLAG_REVERSE,
1105 G_OPTION_ARG_NONE, &option_backtrace,
1106 "Don't print out backtrace information" },
1107 { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
1108 "Show version information and exit" },
1112 const char *connman_option_get_string(const char *key)
1114 if (g_str_equal(key, CONF_VENDOR_CLASS_ID))
1115 return connman_settings.vendor_class_id;
1117 if (g_strcmp0(key, "wifi") == 0) {
1119 return "nl80211,wext";
1124 #if defined TIZEN_EXT
1125 if (g_str_equal(key, CONF_GLOBAL_NAMESERVER))
1126 return connman_settings.global_nameserver;
1128 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID))
1129 return connman_ins_settings.ins_preferred_freq_bssid;
1131 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ))
1132 return connman_ins_settings.ins_preferred_freq;
1134 if (g_str_equal(key, CONF_CONNMAN_WIFI_DEF_IFNAME))
1135 return connman_settings.def_wifi_ifname;
1140 bool connman_setting_get_bool(const char *key)
1142 if (g_str_equal(key, CONF_BG_SCAN))
1143 return connman_settings.bg_scan;
1145 if (g_str_equal(key, CONF_ALLOW_HOSTNAME_UPDATES))
1146 return connman_settings.allow_hostname_updates;
1148 if (g_str_equal(key, CONF_ALLOW_DOMAINNAME_UPDATES))
1149 return connman_settings.allow_domainname_updates;
1151 if (g_str_equal(key, CONF_SINGLE_TECH))
1152 return connman_settings.single_tech;
1154 if (g_str_equal(key, CONF_PERSISTENT_TETHERING_MODE))
1155 return connman_settings.persistent_tethering_mode;
1157 if (g_str_equal(key, CONF_ENABLE_6TO4))
1158 return connman_settings.enable_6to4;
1160 if (g_str_equal(key, CONF_ENABLE_ONLINE_CHECK))
1161 return connman_settings.enable_online_check;
1163 if (g_str_equal(key, CONF_AUTO_CONNECT_ROAMING_SERVICES))
1164 return connman_settings.auto_connect_roaming_services;
1166 if (g_str_equal(key, CONF_ACD))
1167 return connman_settings.acd;
1169 if (g_str_equal(key, CONF_USE_GATEWAYS_AS_TIMESERVERS))
1170 return connman_settings.use_gateways_as_timeservers;
1172 #if defined TIZEN_EXT
1173 if (g_str_equal(key, CONF_ENABLE_AUTO_IP))
1174 return connman_settings.auto_ip;
1176 if (g_str_equal(key, CONF_CONNMAN_SUPPLICANT_DEBUG))
1177 return connman_settings.supplicant_debug;
1179 if (g_str_equal(key, CONF_CONNMAN_FILE_LOG))
1180 return connman_settings.file_log;
1182 if (g_str_equal(key, CONF_CONNMAN_DLOG_LOG))
1183 return connman_settings.dlog_log;
1185 if (g_str_equal(key, CONF_CONNMAN_SIMPLIFIED_LOG))
1186 return connman_settings.simple_log;
1189 #if defined TIZEN_EXT
1190 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID))
1191 return connman_ins_settings.ins_last_connected_bssid;
1193 if (g_str_equal(key, CONF_INS_ASSOC_REJECT))
1194 return connman_ins_settings.ins_assoc_reject;
1196 if (g_str_equal(key, CONF_INS_SIGNAL_BSSID))
1197 return connman_ins_settings.ins_signal_bssid;
1199 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION))
1200 return connman_ins_settings.ins_last_user_selection;
1202 if (g_str_equal(key, CONF_INS_LAST_CONNECTED))
1203 return connman_ins_settings.ins_last_connected;
1205 if (g_str_equal(key, CONF_INS_SIGNAL))
1206 return connman_ins_settings.ins_signal;
1208 if (g_str_equal(key, CONF_INS_INTERNET))
1209 return connman_ins_settings.ins_internet;
1215 #if defined TIZEN_EXT
1216 unsigned int connman_setting_get_uint(const char *key)
1218 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID_SCORE))
1219 return connman_ins_settings.ins_preferred_freq_bssid_score;
1221 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID_SCORE))
1222 return connman_ins_settings.ins_last_connected_bssid_score;
1224 if (g_str_equal(key, CONF_INS_ASSOC_REJECT_SCORE))
1225 return connman_ins_settings.ins_assoc_reject_score;
1227 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_TIME))
1228 return connman_ins_settings.ins_last_user_selection_time;
1230 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_COUNT))
1231 return connman_ins_settings.ins_security_priority_count;
1233 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_SCORE))
1234 return connman_ins_settings.ins_last_user_selection_score;
1236 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_SCORE))
1237 return connman_ins_settings.ins_last_connected_score;
1239 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_SCORE))
1240 return connman_ins_settings.ins_preferred_freq_score;
1242 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_SCORE))
1243 return connman_ins_settings.ins_security_priority_score;
1245 if (g_str_equal(key, CONF_INS_INTERNET_SCORE))
1246 return connman_ins_settings.ins_internet_score;
1251 int connman_setting_get_int(const char *key)
1253 if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_5GHZ))
1254 return connman_ins_settings.ins_signal_level3_5ghz;
1256 if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_24GHZ))
1257 return connman_ins_settings.ins_signal_level3_24ghz;
1263 char **connman_setting_get_string_list(const char *key)
1265 if (g_str_equal(key, CONF_PREF_TIMESERVERS))
1266 return connman_settings.pref_timeservers;
1268 if (g_str_equal(key, CONF_FALLBACK_NAMESERVERS))
1269 return connman_settings.fallback_nameservers;
1271 if (g_str_equal(key, CONF_BLACKLISTED_INTERFACES))
1272 return connman_settings.blacklisted_interfaces;
1274 if (g_str_equal(key, CONF_TETHERING_TECHNOLOGIES))
1275 return connman_settings.tethering_technologies;
1277 #if defined TIZEN_EXT
1278 if (g_str_equal(key, CONF_CELLULAR_INTERFACE))
1279 return connman_settings.cellular_interfaces;
1282 #if defined TIZEN_EXT
1283 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY))
1284 return connman_ins_settings.ins_security_priority;
1290 unsigned int *connman_setting_get_uint_list(const char *key)
1292 if (g_str_equal(key, CONF_AUTO_CONNECT_TECHS))
1293 return connman_settings.auto_connect;
1295 if (g_str_equal(key, CONF_FAVORITE_TECHS))
1296 return connman_settings.favorite_techs;
1298 if (g_str_equal(key, CONF_PREFERRED_TECHS))
1299 return connman_settings.preferred_techs;
1301 if (g_str_equal(key, CONF_ALWAYS_CONNECTED_TECHS))
1302 return connman_settings.always_connected_techs;
1307 unsigned int connman_timeout_input_request(void)
1309 return connman_settings.timeout_inputreq;
1312 unsigned int connman_timeout_browser_launch(void)
1314 return connman_settings.timeout_browserlaunch;
1317 int main(int argc, char *argv[])
1319 GOptionContext *context;
1320 GError *error = NULL;
1321 DBusConnection *conn;
1325 context = g_option_context_new(NULL);
1326 g_option_context_add_main_entries(context, options, NULL);
1328 if (!g_option_context_parse(context, &argc, &argv, &error)) {
1330 g_printerr("%s\n", error->message);
1331 g_error_free(error);
1333 g_printerr("An unknown error occurred\n");
1337 g_option_context_free(context);
1339 if (option_version) {
1340 printf("%s\n", VERSION);
1344 if (option_detach) {
1346 perror("Can't start daemon");
1351 if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
1352 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
1353 if (errno != EEXIST)
1354 perror("Failed to create storage directory");
1359 main_loop = g_main_loop_new(NULL, FALSE);
1361 signal = setup_signalfd();
1363 dbus_error_init(&err);
1365 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
1367 if (dbus_error_is_set(&err)) {
1368 fprintf(stderr, "%s\n", err.message);
1369 dbus_error_free(&err);
1371 fprintf(stderr, "Can't register with system bus\n");
1375 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
1377 __connman_log_init(argv[0], option_debug, option_detach,
1378 option_backtrace, "Connection Manager", VERSION);
1380 __connman_dbus_init(conn);
1382 #if defined TIZEN_EXT
1383 if (access(CONTAINER_FILE, F_OK) == 0) {
1384 g_main_loop_run(main_loop);
1386 g_source_remove(signal);
1387 dbus_connection_unref(conn);
1388 g_main_loop_unref(main_loop);
1390 __connman_dbus_cleanup();
1391 __connman_log_cleanup(option_backtrace);
1398 config_init(CONFIGMAINFILE);
1400 config_init(option_config);
1402 __connman_util_init();
1403 __connman_inotify_init();
1404 __connman_technology_init();
1405 __connman_notifier_init();
1406 __connman_agent_init();
1407 __connman_service_init();
1408 __connman_peer_service_init();
1409 __connman_peer_init();
1410 #if defined TIZEN_EXT_WIFI_MESH
1411 __connman_mesh_init();
1412 #endif /* TIZEN_EXT_WIFI_MESH */
1413 __connman_provider_init();
1414 __connman_network_init();
1415 __connman_config_init();
1416 __connman_device_init(option_device, option_nodevice);
1418 __connman_ippool_init();
1419 __connman_firewall_init();
1420 __connman_nat_init();
1421 __connman_tethering_init();
1422 __connman_counter_init();
1423 __connman_manager_init();
1424 __connman_stats_init();
1425 __connman_clock_init();
1427 __connman_ipconfig_init();
1428 #if defined TIZEN_EXT
1429 __connman_rtnl_init(GIO_SOCKET_RETRY_COUNT);
1430 #else /* TIZEN_EXT */
1431 __connman_rtnl_init();
1432 #endif /* TIZEN_EXT */
1433 __connman_task_init();
1434 __connman_proxy_init();
1435 __connman_detect_init();
1436 __connman_session_init();
1437 __connman_timeserver_init();
1438 __connman_connection_init();
1440 __connman_plugin_init(option_plugin, option_noplugin);
1442 __connman_resolver_init(option_dnsproxy);
1443 __connman_rtnl_start();
1444 __connman_dhcp_init();
1445 __connman_dhcpv6_init();
1446 __connman_wpad_init();
1447 __connman_wispr_init();
1448 #if !defined TIZEN_EXT
1449 __connman_rfkill_init();
1450 __connman_machine_init();
1453 g_free(option_config);
1454 g_free(option_device);
1455 g_free(option_plugin);
1456 g_free(option_nodevice);
1457 g_free(option_noplugin);
1459 g_main_loop_run(main_loop);
1461 g_source_remove(signal);
1463 #if !defined TIZEN_EXT
1464 __connman_machine_cleanup();
1465 __connman_rfkill_cleanup();
1467 __connman_wispr_cleanup();
1468 __connman_wpad_cleanup();
1469 __connman_dhcpv6_cleanup();
1470 __connman_session_cleanup();
1471 __connman_plugin_cleanup();
1472 __connman_provider_cleanup();
1473 __connman_connection_cleanup();
1474 __connman_timeserver_cleanup();
1475 __connman_detect_cleanup();
1476 __connman_proxy_cleanup();
1477 __connman_task_cleanup();
1478 __connman_rtnl_cleanup();
1479 __connman_resolver_cleanup();
1481 __connman_clock_cleanup();
1482 __connman_stats_cleanup();
1483 __connman_config_cleanup();
1484 __connman_manager_cleanup();
1485 __connman_counter_cleanup();
1486 __connman_tethering_cleanup();
1487 __connman_nat_cleanup();
1488 __connman_firewall_cleanup();
1489 __connman_peer_service_cleanup();
1490 __connman_peer_cleanup();
1491 #if defined TIZEN_EXT_WIFI_MESH
1492 __connman_mesh_cleanup();
1493 #endif /* TIZEN_EXT_WIFI_MESH */
1494 __connman_ippool_cleanup();
1495 __connman_device_cleanup();
1496 __connman_network_cleanup();
1497 __connman_dhcp_cleanup();
1498 __connman_service_cleanup();
1499 __connman_agent_cleanup();
1500 __connman_ipconfig_cleanup();
1501 __connman_notifier_cleanup();
1502 __connman_technology_cleanup();
1503 __connman_inotify_cleanup();
1505 __connman_util_cleanup();
1506 __connman_dbus_cleanup();
1508 __connman_log_cleanup(option_backtrace);
1510 dbus_connection_unref(conn);
1512 g_main_loop_unref(main_loop);
1514 if (connman_settings.pref_timeservers)
1515 g_strfreev(connman_settings.pref_timeservers);
1517 g_free(connman_settings.auto_connect);
1518 g_free(connman_settings.favorite_techs);
1519 g_free(connman_settings.preferred_techs);
1520 g_strfreev(connman_settings.fallback_nameservers);
1521 g_strfreev(connman_settings.blacklisted_interfaces);
1522 g_strfreev(connman_settings.tethering_technologies);
1524 #if defined TIZEN_EXT
1525 g_free(connman_ins_settings.ins_preferred_freq_bssid);
1526 g_free(connman_ins_settings.ins_preferred_freq);
1527 if (connman_ins_settings.ins_security_priority)
1528 g_strfreev(connman_ins_settings.ins_security_priority);
1531 g_free(option_debug);
1532 g_free(option_wifi);