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;
113 } connman_settings = {
115 .pref_timeservers = NULL,
116 .auto_connect = NULL,
117 .favorite_techs = NULL,
118 .preferred_techs = NULL,
119 .always_connected_techs = NULL,
120 .fallback_nameservers = NULL,
121 .timeout_inputreq = DEFAULT_INPUT_REQUEST_TIMEOUT,
122 .timeout_browserlaunch = DEFAULT_BROWSER_LAUNCH_TIMEOUT,
123 .blacklisted_interfaces = NULL,
124 .allow_hostname_updates = true,
125 .allow_domainname_updates = true,
126 .single_tech = false,
127 .tethering_technologies = NULL,
128 .persistent_tethering_mode = false,
129 .enable_6to4 = false,
130 .vendor_class_id = NULL,
131 .enable_online_check = true,
132 .auto_connect_roaming_services = false,
134 .use_gateways_as_timeservers = false,
135 #if defined TIZEN_EXT
136 .cellular_interfaces = NULL,
137 .tizen_tv_extension = false,
139 .global_nameserver = NULL,
140 .supplicant_debug = false,
141 .def_wifi_ifname = DEFAULT_WIFI_INTERFACE,
145 .wifi_roam_scan = true,
149 #if defined TIZEN_EXT
152 char *ins_preferred_freq_bssid;
153 bool ins_last_connected_bssid;
154 bool ins_assoc_reject;
155 bool ins_signal_bssid;
156 unsigned int ins_preferred_freq_bssid_score;
157 unsigned int ins_last_connected_bssid_score;
158 unsigned int ins_assoc_reject_score;
160 bool ins_last_user_selection;
161 unsigned int ins_last_user_selection_time;
162 bool ins_last_connected;
163 char *ins_preferred_freq;
164 char **ins_security_priority;
165 unsigned int ins_security_priority_count;
168 unsigned int ins_last_user_selection_score;
169 unsigned int ins_last_connected_score;
170 unsigned int ins_preferred_freq_score;
171 unsigned int ins_security_priority_score;
172 unsigned int ins_internet_score;
174 int ins_signal_level3_5ghz;
175 int ins_signal_level3_24ghz;
176 } connman_ins_settings = {
178 .ins_preferred_freq_bssid = NULL,
179 .ins_last_connected_bssid = true,
180 .ins_assoc_reject = true,
181 .ins_signal_bssid = true,
182 .ins_preferred_freq_bssid_score = 20,
183 .ins_last_connected_bssid_score = 20,
184 .ins_assoc_reject_score = 10,
186 .ins_last_user_selection = true,
187 .ins_last_user_selection_time = 480,
188 .ins_last_connected = true,
189 .ins_preferred_freq = NULL,
190 .ins_security_priority = NULL,
191 .ins_security_priority_count = 0,
193 .ins_internet = true,
194 .ins_last_user_selection_score = 30,
195 .ins_last_connected_score = 30,
196 .ins_preferred_freq_score = 60,
197 .ins_security_priority_score = 5,
198 .ins_internet_score = 30,
200 .ins_signal_level3_5ghz = -76,
201 .ins_signal_level3_24ghz = -74,
205 #define CONF_BG_SCAN "BackgroundScanning"
206 #define CONF_PREF_TIMESERVERS "FallbackTimeservers"
207 #define CONF_AUTO_CONNECT_TECHS "DefaultAutoConnectTechnologies"
208 #define CONF_FAVORITE_TECHS "DefaultFavoriteTechnologies"
209 #define CONF_ALWAYS_CONNECTED_TECHS "AlwaysConnectedTechnologies"
210 #define CONF_PREFERRED_TECHS "PreferredTechnologies"
211 #define CONF_FALLBACK_NAMESERVERS "FallbackNameservers"
212 #define CONF_TIMEOUT_INPUTREQ "InputRequestTimeout"
213 #define CONF_TIMEOUT_BROWSERLAUNCH "BrowserLaunchTimeout"
214 #define CONF_BLACKLISTED_INTERFACES "NetworkInterfaceBlacklist"
215 #define CONF_ALLOW_HOSTNAME_UPDATES "AllowHostnameUpdates"
216 #define CONF_ALLOW_DOMAINNAME_UPDATES "AllowDomainnameUpdates"
217 #define CONF_SINGLE_TECH "SingleConnectedTechnology"
218 #define CONF_TETHERING_TECHNOLOGIES "TetheringTechnologies"
219 #define CONF_PERSISTENT_TETHERING_MODE "PersistentTetheringMode"
220 #define CONF_ENABLE_6TO4 "Enable6to4"
221 #define CONF_VENDOR_CLASS_ID "VendorClassID"
222 #define CONF_ENABLE_ONLINE_CHECK "EnableOnlineCheck"
223 #define CONF_AUTO_CONNECT_ROAMING_SERVICES "AutoConnectRoamingServices"
224 #define CONF_ACD "AddressConflictDetection"
225 #define CONF_USE_GATEWAYS_AS_TIMESERVERS "UseGatewaysAsTimeservers"
226 #if defined TIZEN_EXT
227 #define CONF_CELLULAR_INTERFACE "NetworkCellularInterfaceList"
228 #define CONF_TIZEN_TV_EXT "TizenTVExtension"
229 #define CONF_ENABLE_AUTO_IP "EnableAutoIp"
230 #define CONF_GLOBAL_NAMESERVER "GlobalNameserver"
231 #define CONF_CONNMAN_SUPPLICANT_DEBUG "ConnmanSupplicantDebug"
232 #define CONF_CONNMAN_WIFI_DEF_IFNAME "DefaultWifiInterface"
233 #define CONF_CONNMAN_FILE_LOG "FileLogging"
234 #define CONF_CONNMAN_DLOG_LOG "DlogLogging"
235 #define CONF_CONNMAN_SIMPLIFIED_LOG "SimplifiedLog"
236 #define CONF_CONNMAN_WIFI_ROAM_SCAN "WifiRoamingScan"
239 #if defined TIZEN_EXT
241 #define CONF_INS_PREFERRED_FREQ_BSSID "INSPreferredFreqBSSID"
242 #define CONF_INS_PREFERRED_FREQ_BSSID_SCORE "INSPreferredFreqBSSIDScore"
243 #define CONF_INS_LAST_CONNECTED_BSSID "INSLastConnectedBSSID"
244 #define CONF_INS_LAST_CONNECTED_BSSID_SCORE "INSLastConnectedBSSIDScore"
245 #define CONF_INS_ASSOC_REJECT "INSAssocReject"
246 #define CONF_INS_ASSOC_REJECT_SCORE "INSAssocRejectScore"
247 #define CONF_INS_SIGNAL_BSSID "INSSignalBSSID"
249 #define CONF_INS_LAST_USER_SELECTION "INSLastUserSelection"
250 #define CONF_INS_LAST_USER_SELECTION_TIME "INSLastUserSelectionTime"
251 #define CONF_INS_LAST_USER_SELECTION_SCORE "INSLastUserSelectionScore"
252 #define CONF_INS_LAST_CONNECTED "INSLastConnected"
253 #define CONF_INS_LAST_CONNECTED_SCORE "INSLastConnectedScore"
254 #define CONF_INS_PREFERRED_FREQ "INSPreferredFreq"
255 #define CONF_INS_PREFERRED_FREQ_SCORE "INSPreferredFreqScore"
256 #define CONF_INS_SECURITY_PRIORITY "INSSecurityPriority"
257 #define CONF_INS_SECURITY_PRIORITY_COUNT "INSSecurityPriorityCount"
258 #define CONF_INS_SECURITY_PRIORITY_SCORE "INSSecurityPriorityScore"
259 #define CONF_INS_SIGNAL "INSSignal"
260 #define CONF_INS_INTERNET "INSInternet"
261 #define CONF_INS_INTERNET_SCORE "INSInternetScore"
263 #define CONF_INS_SIGNAL_LEVEL3_5GHZ "INSSignalLevel3_5GHz"
264 #define CONF_INS_SIGNAL_LEVEL3_24GHZ "INSSignalLevel3_24GHz"
267 static const char *supported_options[] = {
269 CONF_PREF_TIMESERVERS,
270 CONF_AUTO_CONNECT_TECHS,
271 CONF_ALWAYS_CONNECTED_TECHS,
272 CONF_PREFERRED_TECHS,
273 CONF_FALLBACK_NAMESERVERS,
274 CONF_TIMEOUT_INPUTREQ,
275 CONF_TIMEOUT_BROWSERLAUNCH,
276 CONF_BLACKLISTED_INTERFACES,
277 CONF_ALLOW_HOSTNAME_UPDATES,
278 CONF_ALLOW_DOMAINNAME_UPDATES,
280 CONF_TETHERING_TECHNOLOGIES,
281 CONF_PERSISTENT_TETHERING_MODE,
283 CONF_VENDOR_CLASS_ID,
284 CONF_ENABLE_ONLINE_CHECK,
285 CONF_AUTO_CONNECT_ROAMING_SERVICES,
287 CONF_USE_GATEWAYS_AS_TIMESERVERS,
288 #if defined TIZEN_EXT
289 CONF_CELLULAR_INTERFACE,
292 CONF_GLOBAL_NAMESERVER,
293 CONF_CONNMAN_SUPPLICANT_DEBUG,
294 CONF_CONNMAN_WIFI_DEF_IFNAME,
295 CONF_CONNMAN_FILE_LOG,
296 CONF_CONNMAN_DLOG_LOG,
297 CONF_CONNMAN_SIMPLIFIED_LOG,
298 CONF_CONNMAN_WIFI_ROAM_SCAN,
303 #if defined TIZEN_EXT
304 static const char *supported_ins_options[] = {
306 CONF_INS_PREFERRED_FREQ_BSSID,
307 CONF_INS_PREFERRED_FREQ_BSSID_SCORE,
308 CONF_INS_LAST_CONNECTED_BSSID,
309 CONF_INS_LAST_CONNECTED_BSSID_SCORE,
310 CONF_INS_ASSOC_REJECT,
311 CONF_INS_ASSOC_REJECT_SCORE,
312 CONF_INS_SIGNAL_BSSID,
314 CONF_INS_LAST_USER_SELECTION,
315 CONF_INS_LAST_USER_SELECTION_TIME,
316 CONF_INS_LAST_USER_SELECTION_SCORE,
317 CONF_INS_LAST_CONNECTED,
318 CONF_INS_LAST_CONNECTED_SCORE,
319 CONF_INS_PREFERRED_FREQ,
320 CONF_INS_PREFERRED_FREQ_SCORE,
321 CONF_INS_SECURITY_PRIORITY,
322 CONF_INS_SECURITY_PRIORITY_COUNT,
323 CONF_INS_SECURITY_PRIORITY_SCORE,
326 CONF_INS_INTERNET_SCORE,
328 CONF_INS_SIGNAL_LEVEL3_5GHZ,
329 CONF_INS_SIGNAL_LEVEL3_24GHZ,
334 static GKeyFile *load_config(const char *file)
339 keyfile = g_key_file_new();
341 g_key_file_set_list_separator(keyfile, ',');
343 if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
344 if (err->code != G_FILE_ERROR_NOENT) {
345 connman_error("Parsing %s failed: %s", file,
350 g_key_file_free(keyfile);
357 static uint *parse_service_types(char **str_list, gsize len)
359 unsigned int *type_list;
361 enum connman_service_type type;
363 type_list = g_try_new0(unsigned int, len + 1);
369 while (str_list[i]) {
370 type = __connman_service_string2type(str_list[i]);
372 if (type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
379 type_list[j] = CONNMAN_SERVICE_TYPE_UNKNOWN;
384 static char **parse_fallback_nameservers(char **nameservers, gsize len)
389 servers = g_try_new0(char *, len + 1);
395 while (nameservers[i]) {
396 if (connman_inet_check_ipaddress(nameservers[i]) > 0) {
397 servers[j] = g_strdup(nameservers[i]);
406 static void check_config(GKeyFile *config)
414 keys = g_key_file_get_groups(config, NULL);
416 for (j = 0; keys && keys[j]; j++) {
417 #if defined TIZEN_EXT
418 if (g_strcmp0(keys[j], "General") != 0 &&
419 g_strcmp0(keys[j], "INS") != 0)
421 if (g_strcmp0(keys[j], "General") != 0)
423 connman_warn("Unknown group %s in %s",
429 keys = g_key_file_get_keys(config, "General", NULL, NULL);
431 for (j = 0; keys && keys[j]; j++) {
436 for (i = 0; supported_options[i]; i++) {
437 if (g_strcmp0(keys[j], supported_options[i]) == 0) {
442 if (!found && !supported_options[i])
443 connman_warn("Unknown option %s in %s",
449 #if defined TIZEN_EXT
450 keys = g_key_file_get_keys(config, "INS", NULL, NULL);
452 for (j = 0; keys && keys[j]; j++) {
457 for (i = 0; supported_ins_options[i]; i++) {
458 if (g_strcmp0(keys[j], supported_ins_options[i]) == 0) {
463 if (!found && !supported_ins_options[i])
464 connman_warn("Unknown option %s in %s",
472 #if defined TIZEN_EXT
473 static void check_Tizen_INS_configuration(GKeyFile *config)
475 GError *error = NULL;
476 char *ins_preferred_freq_bssid;
477 char *ins_preferred_freq;
478 char **ins_security_priority;
483 ins_preferred_freq_bssid = __connman_config_get_string(config, "INS",
484 CONF_INS_PREFERRED_FREQ_BSSID, &error);
486 connman_ins_settings.ins_preferred_freq_bssid = ins_preferred_freq_bssid;
488 g_clear_error(&error);
490 integer = g_key_file_get_integer(config, "INS",
491 CONF_INS_PREFERRED_FREQ_BSSID_SCORE, &error);
492 if (!error && integer >= 0)
493 connman_ins_settings.ins_preferred_freq_bssid_score = integer;
495 g_clear_error(&error);
497 boolean = __connman_config_get_bool(config, "INS",
498 CONF_INS_LAST_CONNECTED_BSSID, &error);
500 connman_ins_settings.ins_last_connected_bssid = boolean;
502 g_clear_error(&error);
504 integer = g_key_file_get_integer(config, "INS",
505 CONF_INS_LAST_CONNECTED_BSSID_SCORE, &error);
506 if (!error && integer >= 0)
507 connman_ins_settings.ins_last_connected_bssid_score = integer;
509 g_clear_error(&error);
511 boolean = __connman_config_get_bool(config, "INS",
512 CONF_INS_ASSOC_REJECT, &error);
514 connman_ins_settings.ins_assoc_reject = boolean;
516 g_clear_error(&error);
518 integer = g_key_file_get_integer(config, "INS",
519 CONF_INS_ASSOC_REJECT_SCORE, &error);
520 if (!error && integer >= 0)
521 connman_ins_settings.ins_assoc_reject_score = integer;
523 g_clear_error(&error);
525 boolean = __connman_config_get_bool(config, "INS",
526 CONF_INS_SIGNAL_BSSID, &error);
528 connman_ins_settings.ins_signal_bssid = boolean;
530 g_clear_error(&error);
532 boolean = __connman_config_get_bool(config, "INS",
533 CONF_INS_LAST_USER_SELECTION, &error);
535 connman_ins_settings.ins_last_user_selection = boolean;
537 g_clear_error(&error);
539 integer = g_key_file_get_integer(config, "INS",
540 CONF_INS_LAST_USER_SELECTION_TIME, &error);
541 if (!error && integer >= 0)
542 connman_ins_settings.ins_last_user_selection_time = integer;
544 g_clear_error(&error);
546 integer = g_key_file_get_integer(config, "INS",
547 CONF_INS_LAST_USER_SELECTION_SCORE, &error);
548 if (!error && integer >= 0)
549 connman_ins_settings.ins_last_user_selection_score = integer;
551 g_clear_error(&error);
553 boolean = __connman_config_get_bool(config, "INS",
554 CONF_INS_LAST_CONNECTED, &error);
556 connman_ins_settings.ins_last_connected = boolean;
558 g_clear_error(&error);
560 integer = g_key_file_get_integer(config, "INS",
561 CONF_INS_LAST_CONNECTED_SCORE, &error);
562 if (!error && integer >= 0)
563 connman_ins_settings.ins_last_connected_score = integer;
565 g_clear_error(&error);
567 ins_preferred_freq = __connman_config_get_string(config, "INS",
568 CONF_INS_PREFERRED_FREQ, &error);
570 connman_ins_settings.ins_preferred_freq = ins_preferred_freq;
572 g_clear_error(&error);
574 integer = g_key_file_get_integer(config, "INS",
575 CONF_INS_PREFERRED_FREQ_SCORE, &error);
576 if (!error && integer >= 0)
577 connman_ins_settings.ins_preferred_freq_score = integer;
579 g_clear_error(&error);
581 ins_security_priority = g_key_file_get_string_list(config, "INS",
582 CONF_INS_SECURITY_PRIORITY, &len, &error);
585 connman_ins_settings.ins_security_priority = ins_security_priority;
586 connman_ins_settings.ins_security_priority_count = len;
589 g_clear_error(&error);
591 integer = g_key_file_get_integer(config, "INS",
592 CONF_INS_SECURITY_PRIORITY_SCORE, &error);
593 if (!error && integer >= 0)
594 connman_ins_settings.ins_security_priority_score = integer;
596 g_clear_error(&error);
598 boolean = __connman_config_get_bool(config, "INS",
599 CONF_INS_SIGNAL, &error);
601 connman_ins_settings.ins_signal = boolean;
603 g_clear_error(&error);
605 boolean = __connman_config_get_bool(config, "INS",
606 CONF_INS_INTERNET, &error);
608 connman_ins_settings.ins_internet = boolean;
610 g_clear_error(&error);
612 integer = g_key_file_get_integer(config, "INS",
613 CONF_INS_INTERNET_SCORE, &error);
614 if (!error && integer >= 0)
615 connman_ins_settings.ins_internet_score = integer;
617 g_clear_error(&error);
619 integer = g_key_file_get_integer(config, "INS",
620 CONF_INS_SIGNAL_LEVEL3_5GHZ, &error);
622 connman_ins_settings.ins_signal_level3_5ghz = integer;
624 g_clear_error(&error);
626 integer = g_key_file_get_integer(config, "INS",
627 CONF_INS_SIGNAL_LEVEL3_24GHZ, &error);
629 connman_ins_settings.ins_signal_level3_24ghz = integer;
631 g_clear_error(&error);
634 static void check_Tizen_configuration(GKeyFile *config)
636 GError *error = NULL;
637 char **cellular_interfaces;
638 char *global_nameserver;
639 char *default_wifi_ifname;
643 cellular_interfaces = g_key_file_get_string_list(config, "General",
644 CONF_CELLULAR_INTERFACE, &len, &error);
647 connman_settings.cellular_interfaces = cellular_interfaces;
649 g_clear_error(&error);
651 boolean = __connman_config_get_bool(config, "General",
652 CONF_TIZEN_TV_EXT, &error);
654 connman_settings.tizen_tv_extension = boolean;
656 g_clear_error(&error);
658 boolean = __connman_config_get_bool(config, "General",
659 CONF_ENABLE_AUTO_IP, &error);
661 connman_settings.auto_ip = boolean;
663 g_clear_error(&error);
665 global_nameserver = __connman_config_get_string(config, "General",
666 CONF_GLOBAL_NAMESERVER, &error);
668 connman_settings.global_nameserver = global_nameserver;
670 g_clear_error(&error);
672 boolean = __connman_config_get_bool(config, "General",
673 CONF_CONNMAN_SUPPLICANT_DEBUG, &error);
675 connman_settings.supplicant_debug = boolean;
677 g_clear_error(&error);
679 default_wifi_ifname = __connman_config_get_string(config, "General",
680 CONF_CONNMAN_WIFI_DEF_IFNAME, &error);
682 connman_settings.def_wifi_ifname = default_wifi_ifname;
684 g_clear_error(&error);
686 boolean = __connman_config_get_bool(config, "General",
687 CONF_CONNMAN_FILE_LOG, &error);
689 connman_settings.file_log = boolean;
691 g_clear_error(&error);
693 boolean = __connman_config_get_bool(config, "General",
694 CONF_CONNMAN_DLOG_LOG, &error);
696 connman_settings.dlog_log = boolean;
698 g_clear_error(&error);
700 boolean = __connman_config_get_bool(config, "General",
701 CONF_CONNMAN_SIMPLIFIED_LOG, &error);
703 connman_settings.simple_log = boolean;
705 boolean = __connman_config_get_bool(config, "General",
706 CONF_CONNMAN_WIFI_ROAM_SCAN, &error);
708 connman_settings.wifi_roam_scan = boolean;
710 g_clear_error(&error);
712 check_Tizen_INS_configuration(config);
715 static void set_nofile_inc(void)
720 rlim.rlim_cur = 8192;
721 rlim.rlim_max = 8192;
723 err = setrlimit(RLIMIT_NOFILE, &rlim);
725 DBG("fail to increase FILENO err(%d)", err);
731 static void parse_config(GKeyFile *config)
733 GError *error = NULL;
739 char *vendor_class_id;
744 connman_settings.auto_connect =
745 parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
746 connman_settings.favorite_techs =
747 parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
748 connman_settings.blacklisted_interfaces =
749 g_strdupv(default_blacklist);
753 DBG("parsing %s", MAINFILE);
755 boolean = g_key_file_get_boolean(config, "General",
756 CONF_BG_SCAN, &error);
758 connman_settings.bg_scan = boolean;
760 g_clear_error(&error);
762 timeservers = __connman_config_get_string_list(config, "General",
763 CONF_PREF_TIMESERVERS, NULL, &error);
765 connman_settings.pref_timeservers = timeservers;
767 g_clear_error(&error);
769 str_list = __connman_config_get_string_list(config, "General",
770 CONF_AUTO_CONNECT_TECHS, &len, &error);
773 connman_settings.auto_connect =
774 parse_service_types(str_list, len);
776 connman_settings.auto_connect =
777 parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
779 g_strfreev(str_list);
781 g_clear_error(&error);
783 str_list = __connman_config_get_string_list(config, "General",
784 CONF_FAVORITE_TECHS, &len, &error);
787 connman_settings.favorite_techs =
788 parse_service_types(str_list, len);
790 connman_settings.favorite_techs =
791 parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
793 g_strfreev(str_list);
795 g_clear_error(&error);
797 str_list = __connman_config_get_string_list(config, "General",
798 CONF_PREFERRED_TECHS, &len, &error);
801 connman_settings.preferred_techs =
802 parse_service_types(str_list, len);
804 g_strfreev(str_list);
806 g_clear_error(&error);
808 str_list = __connman_config_get_string_list(config, "General",
809 CONF_ALWAYS_CONNECTED_TECHS, &len, &error);
812 connman_settings.always_connected_techs =
813 parse_service_types(str_list, len);
815 g_strfreev(str_list);
817 g_clear_error(&error);
819 str_list = __connman_config_get_string_list(config, "General",
820 CONF_FALLBACK_NAMESERVERS, &len, &error);
823 connman_settings.fallback_nameservers =
824 parse_fallback_nameservers(str_list, len);
826 g_strfreev(str_list);
828 g_clear_error(&error);
830 timeout = g_key_file_get_integer(config, "General",
831 CONF_TIMEOUT_INPUTREQ, &error);
832 if (!error && timeout >= 0)
833 connman_settings.timeout_inputreq = timeout * 1000;
835 g_clear_error(&error);
837 timeout = g_key_file_get_integer(config, "General",
838 CONF_TIMEOUT_BROWSERLAUNCH, &error);
839 if (!error && timeout >= 0)
840 connman_settings.timeout_browserlaunch = timeout * 1000;
842 g_clear_error(&error);
844 interfaces = __connman_config_get_string_list(config, "General",
845 CONF_BLACKLISTED_INTERFACES, &len, &error);
848 connman_settings.blacklisted_interfaces = interfaces;
850 connman_settings.blacklisted_interfaces =
851 g_strdupv(default_blacklist);
853 g_clear_error(&error);
855 boolean = __connman_config_get_bool(config, "General",
856 CONF_ALLOW_HOSTNAME_UPDATES,
859 connman_settings.allow_hostname_updates = boolean;
861 g_clear_error(&error);
863 boolean = __connman_config_get_bool(config, "General",
864 CONF_ALLOW_DOMAINNAME_UPDATES,
867 connman_settings.allow_domainname_updates = boolean;
869 g_clear_error(&error);
871 boolean = __connman_config_get_bool(config, "General",
872 CONF_SINGLE_TECH, &error);
874 connman_settings.single_tech = boolean;
876 g_clear_error(&error);
878 tethering = __connman_config_get_string_list(config, "General",
879 CONF_TETHERING_TECHNOLOGIES, &len, &error);
882 connman_settings.tethering_technologies = tethering;
884 g_clear_error(&error);
886 boolean = __connman_config_get_bool(config, "General",
887 CONF_PERSISTENT_TETHERING_MODE,
890 connman_settings.persistent_tethering_mode = boolean;
892 g_clear_error(&error);
894 boolean = __connman_config_get_bool(config, "General",
895 CONF_ENABLE_6TO4, &error);
897 connman_settings.enable_6to4 = boolean;
899 g_clear_error(&error);
901 vendor_class_id = __connman_config_get_string(config, "General",
902 CONF_VENDOR_CLASS_ID, &error);
904 connman_settings.vendor_class_id = vendor_class_id;
906 g_clear_error(&error);
908 boolean = __connman_config_get_bool(config, "General",
909 CONF_ENABLE_ONLINE_CHECK, &error);
911 connman_settings.enable_online_check = boolean;
913 connman_info("Online check disabled by main config.");
916 g_clear_error(&error);
918 boolean = __connman_config_get_bool(config, "General",
919 CONF_AUTO_CONNECT_ROAMING_SERVICES, &error);
921 connman_settings.auto_connect_roaming_services = boolean;
923 g_clear_error(&error);
925 boolean = __connman_config_get_bool(config, "General", CONF_ACD, &error);
927 connman_settings.acd = boolean;
929 g_clear_error(&error);
931 boolean = __connman_config_get_bool(config, "General",
932 CONF_USE_GATEWAYS_AS_TIMESERVERS, &error);
934 connman_settings.use_gateways_as_timeservers = boolean;
936 g_clear_error(&error);
938 #if defined TIZEN_EXT
939 check_Tizen_configuration(config);
943 static int config_init(const char *file)
947 #if defined TIZEN_EXT
950 config = load_config(file);
951 check_config(config);
952 parse_config(config);
954 g_key_file_free(config);
956 #if defined TIZEN_EXT
957 set_simple_log_option(connman_settings.simple_log);
958 set_dlog_logging_option(connman_settings.dlog_log);
959 set_file_logging_option(connman_settings.file_log);
964 static GMainLoop *main_loop = NULL;
966 static unsigned int __terminated = 0;
968 static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
971 struct signalfd_siginfo si;
975 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
978 fd = g_io_channel_unix_get_fd(channel);
980 result = read(fd, &si, sizeof(si));
981 if (result != sizeof(si))
984 switch (si.ssi_signo) {
987 if (__terminated == 0) {
988 connman_info("Terminating");
989 g_main_loop_quit(main_loop);
999 static guint setup_signalfd(void)
1001 GIOChannel *channel;
1007 sigaddset(&mask, SIGINT);
1008 sigaddset(&mask, SIGTERM);
1010 if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
1011 perror("Failed to set signal mask");
1015 fd = signalfd(-1, &mask, 0);
1017 perror("Failed to create signal descriptor");
1021 channel = g_io_channel_unix_new(fd);
1023 g_io_channel_set_close_on_unref(channel, TRUE);
1024 g_io_channel_set_encoding(channel, NULL, NULL);
1025 g_io_channel_set_buffered(channel, FALSE);
1027 source = g_io_add_watch(channel,
1028 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1029 signal_handler, NULL);
1031 g_io_channel_unref(channel);
1036 static void disconnect_callback(DBusConnection *conn, void *user_data)
1038 connman_error("D-Bus disconnect");
1040 g_main_loop_quit(main_loop);
1043 static gchar *option_config = NULL;
1044 static gchar *option_debug = NULL;
1045 static gchar *option_device = NULL;
1046 static gchar *option_plugin = NULL;
1047 static gchar *option_nodevice = NULL;
1048 static gchar *option_noplugin = NULL;
1049 static gchar *option_wifi = NULL;
1050 static gboolean option_detach = TRUE;
1051 static gboolean option_dnsproxy = TRUE;
1052 static gboolean option_backtrace = TRUE;
1053 static gboolean option_version = FALSE;
1055 static bool parse_debug(const char *key, const char *value,
1056 gpointer user_data, GError **error)
1060 char *prev = option_debug;
1062 option_debug = g_strconcat(prev, ",", value, NULL);
1065 option_debug = g_strdup(value);
1068 g_free(option_debug);
1069 option_debug = g_strdup("*");
1075 static bool parse_noplugin(const char *key, const char *value,
1076 gpointer user_data, GError **error)
1078 if (option_noplugin) {
1079 char *prev = option_noplugin;
1081 option_noplugin = g_strconcat(prev, ",", value, NULL);
1084 option_noplugin = g_strdup(value);
1090 static GOptionEntry options[] = {
1091 { "config", 'c', 0, G_OPTION_ARG_STRING, &option_config,
1092 "Load the specified configuration file "
1093 "instead of " CONFIGMAINFILE, "FILE" },
1094 { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
1095 G_OPTION_ARG_CALLBACK, parse_debug,
1096 "Specify debug options to enable", "DEBUG" },
1097 { "device", 'i', 0, G_OPTION_ARG_STRING, &option_device,
1098 "Specify networking devices or interfaces", "DEV,..." },
1099 { "nodevice", 'I', 0, G_OPTION_ARG_STRING, &option_nodevice,
1100 "Specify networking interfaces to ignore", "DEV,..." },
1101 { "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin,
1102 "Specify plugins to load", "NAME,..." },
1103 { "noplugin", 'P', 0, G_OPTION_ARG_CALLBACK, &parse_noplugin,
1104 "Specify plugins not to load", "NAME,..." },
1105 { "wifi", 'W', 0, G_OPTION_ARG_STRING, &option_wifi,
1106 "Specify driver for WiFi/Supplicant", "NAME" },
1107 { "nodaemon", 'n', G_OPTION_FLAG_REVERSE,
1108 G_OPTION_ARG_NONE, &option_detach,
1109 "Don't fork daemon to background" },
1110 { "nodnsproxy", 'r', G_OPTION_FLAG_REVERSE,
1111 G_OPTION_ARG_NONE, &option_dnsproxy,
1112 "Don't support DNS resolving" },
1113 { "nobacktrace", 0, G_OPTION_FLAG_REVERSE,
1114 G_OPTION_ARG_NONE, &option_backtrace,
1115 "Don't print out backtrace information" },
1116 { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
1117 "Show version information and exit" },
1121 const char *connman_option_get_string(const char *key)
1123 if (g_str_equal(key, CONF_VENDOR_CLASS_ID))
1124 return connman_settings.vendor_class_id;
1126 if (g_strcmp0(key, "wifi") == 0) {
1128 return "nl80211,wext";
1133 #if defined TIZEN_EXT
1134 if (g_str_equal(key, CONF_GLOBAL_NAMESERVER))
1135 return connman_settings.global_nameserver;
1137 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID))
1138 return connman_ins_settings.ins_preferred_freq_bssid;
1140 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ))
1141 return connman_ins_settings.ins_preferred_freq;
1143 if (g_str_equal(key, CONF_CONNMAN_WIFI_DEF_IFNAME))
1144 return connman_settings.def_wifi_ifname;
1149 bool connman_setting_get_bool(const char *key)
1151 if (g_str_equal(key, CONF_BG_SCAN))
1152 return connman_settings.bg_scan;
1154 if (g_str_equal(key, CONF_ALLOW_HOSTNAME_UPDATES))
1155 return connman_settings.allow_hostname_updates;
1157 if (g_str_equal(key, CONF_ALLOW_DOMAINNAME_UPDATES))
1158 return connman_settings.allow_domainname_updates;
1160 if (g_str_equal(key, CONF_SINGLE_TECH))
1161 return connman_settings.single_tech;
1163 if (g_str_equal(key, CONF_PERSISTENT_TETHERING_MODE))
1164 return connman_settings.persistent_tethering_mode;
1166 if (g_str_equal(key, CONF_ENABLE_6TO4))
1167 return connman_settings.enable_6to4;
1169 if (g_str_equal(key, CONF_ENABLE_ONLINE_CHECK))
1170 return connman_settings.enable_online_check;
1172 if (g_str_equal(key, CONF_AUTO_CONNECT_ROAMING_SERVICES))
1173 return connman_settings.auto_connect_roaming_services;
1175 if (g_str_equal(key, CONF_ACD))
1176 return connman_settings.acd;
1178 if (g_str_equal(key, CONF_USE_GATEWAYS_AS_TIMESERVERS))
1179 return connman_settings.use_gateways_as_timeservers;
1181 #if defined TIZEN_EXT
1182 if (g_str_equal(key, CONF_ENABLE_AUTO_IP))
1183 return connman_settings.auto_ip;
1185 if (g_str_equal(key, CONF_CONNMAN_SUPPLICANT_DEBUG))
1186 return connman_settings.supplicant_debug;
1188 if (g_str_equal(key, CONF_CONNMAN_FILE_LOG))
1189 return connman_settings.file_log;
1191 if (g_str_equal(key, CONF_CONNMAN_DLOG_LOG))
1192 return connman_settings.dlog_log;
1194 if (g_str_equal(key, CONF_CONNMAN_SIMPLIFIED_LOG))
1195 return connman_settings.simple_log;
1197 if (g_str_equal(key, CONF_CONNMAN_WIFI_ROAM_SCAN))
1198 return connman_settings.wifi_roam_scan;
1201 #if defined TIZEN_EXT
1202 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID))
1203 return connman_ins_settings.ins_last_connected_bssid;
1205 if (g_str_equal(key, CONF_INS_ASSOC_REJECT))
1206 return connman_ins_settings.ins_assoc_reject;
1208 if (g_str_equal(key, CONF_INS_SIGNAL_BSSID))
1209 return connman_ins_settings.ins_signal_bssid;
1211 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION))
1212 return connman_ins_settings.ins_last_user_selection;
1214 if (g_str_equal(key, CONF_INS_LAST_CONNECTED))
1215 return connman_ins_settings.ins_last_connected;
1217 if (g_str_equal(key, CONF_INS_SIGNAL))
1218 return connman_ins_settings.ins_signal;
1220 if (g_str_equal(key, CONF_INS_INTERNET))
1221 return connman_ins_settings.ins_internet;
1227 #if defined TIZEN_EXT
1228 unsigned int connman_setting_get_uint(const char *key)
1230 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID_SCORE))
1231 return connman_ins_settings.ins_preferred_freq_bssid_score;
1233 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID_SCORE))
1234 return connman_ins_settings.ins_last_connected_bssid_score;
1236 if (g_str_equal(key, CONF_INS_ASSOC_REJECT_SCORE))
1237 return connman_ins_settings.ins_assoc_reject_score;
1239 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_TIME))
1240 return connman_ins_settings.ins_last_user_selection_time;
1242 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_COUNT))
1243 return connman_ins_settings.ins_security_priority_count;
1245 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_SCORE))
1246 return connman_ins_settings.ins_last_user_selection_score;
1248 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_SCORE))
1249 return connman_ins_settings.ins_last_connected_score;
1251 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_SCORE))
1252 return connman_ins_settings.ins_preferred_freq_score;
1254 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_SCORE))
1255 return connman_ins_settings.ins_security_priority_score;
1257 if (g_str_equal(key, CONF_INS_INTERNET_SCORE))
1258 return connman_ins_settings.ins_internet_score;
1263 int connman_setting_get_int(const char *key)
1265 if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_5GHZ))
1266 return connman_ins_settings.ins_signal_level3_5ghz;
1268 if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_24GHZ))
1269 return connman_ins_settings.ins_signal_level3_24ghz;
1275 char **connman_setting_get_string_list(const char *key)
1277 if (g_str_equal(key, CONF_PREF_TIMESERVERS))
1278 return connman_settings.pref_timeservers;
1280 if (g_str_equal(key, CONF_FALLBACK_NAMESERVERS))
1281 return connman_settings.fallback_nameservers;
1283 if (g_str_equal(key, CONF_BLACKLISTED_INTERFACES))
1284 return connman_settings.blacklisted_interfaces;
1286 if (g_str_equal(key, CONF_TETHERING_TECHNOLOGIES))
1287 return connman_settings.tethering_technologies;
1289 #if defined TIZEN_EXT
1290 if (g_str_equal(key, CONF_CELLULAR_INTERFACE))
1291 return connman_settings.cellular_interfaces;
1294 #if defined TIZEN_EXT
1295 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY))
1296 return connman_ins_settings.ins_security_priority;
1302 unsigned int *connman_setting_get_uint_list(const char *key)
1304 if (g_str_equal(key, CONF_AUTO_CONNECT_TECHS))
1305 return connman_settings.auto_connect;
1307 if (g_str_equal(key, CONF_FAVORITE_TECHS))
1308 return connman_settings.favorite_techs;
1310 if (g_str_equal(key, CONF_PREFERRED_TECHS))
1311 return connman_settings.preferred_techs;
1313 if (g_str_equal(key, CONF_ALWAYS_CONNECTED_TECHS))
1314 return connman_settings.always_connected_techs;
1319 unsigned int connman_timeout_input_request(void)
1321 return connman_settings.timeout_inputreq;
1324 unsigned int connman_timeout_browser_launch(void)
1326 return connman_settings.timeout_browserlaunch;
1329 int main(int argc, char *argv[])
1331 GOptionContext *context;
1332 GError *error = NULL;
1333 DBusConnection *conn;
1337 context = g_option_context_new(NULL);
1338 g_option_context_add_main_entries(context, options, NULL);
1340 if (!g_option_context_parse(context, &argc, &argv, &error)) {
1342 g_printerr("%s\n", error->message);
1343 g_error_free(error);
1345 g_printerr("An unknown error occurred\n");
1349 g_option_context_free(context);
1351 if (option_version) {
1352 printf("%s\n", VERSION);
1356 if (option_detach) {
1358 perror("Can't start daemon");
1363 if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
1364 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
1365 if (errno != EEXIST)
1366 perror("Failed to create storage directory");
1371 main_loop = g_main_loop_new(NULL, FALSE);
1373 signal = setup_signalfd();
1375 dbus_error_init(&err);
1377 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
1379 if (dbus_error_is_set(&err)) {
1380 fprintf(stderr, "%s\n", err.message);
1381 dbus_error_free(&err);
1383 fprintf(stderr, "Can't register with system bus\n");
1387 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
1389 __connman_log_init(argv[0], option_debug, option_detach,
1390 option_backtrace, "Connection Manager", VERSION);
1392 __connman_dbus_init(conn);
1394 #if defined TIZEN_EXT
1395 if (access(CONTAINER_FILE, F_OK) == 0) {
1396 g_main_loop_run(main_loop);
1398 g_source_remove(signal);
1399 dbus_connection_unref(conn);
1400 g_main_loop_unref(main_loop);
1402 __connman_dbus_cleanup();
1403 __connman_log_cleanup(option_backtrace);
1410 config_init(CONFIGMAINFILE);
1412 config_init(option_config);
1414 __connman_util_init();
1415 __connman_inotify_init();
1416 __connman_technology_init();
1417 __connman_notifier_init();
1418 __connman_agent_init();
1419 __connman_service_init();
1420 __connman_peer_service_init();
1421 __connman_peer_init();
1422 #if defined TIZEN_EXT_WIFI_MESH
1423 __connman_mesh_init();
1424 #endif /* TIZEN_EXT_WIFI_MESH */
1425 __connman_provider_init();
1426 __connman_network_init();
1427 __connman_config_init();
1428 __connman_device_init(option_device, option_nodevice);
1430 __connman_ippool_init();
1431 __connman_firewall_init();
1432 __connman_nat_init();
1433 __connman_tethering_init();
1434 __connman_counter_init();
1435 __connman_manager_init();
1436 __connman_stats_init();
1437 __connman_clock_init();
1439 __connman_ipconfig_init();
1440 #if defined TIZEN_EXT
1441 __connman_rtnl_init(GIO_SOCKET_RETRY_COUNT);
1442 #else /* TIZEN_EXT */
1443 __connman_rtnl_init();
1444 #endif /* TIZEN_EXT */
1445 __connman_task_init();
1446 __connman_proxy_init();
1447 __connman_detect_init();
1448 __connman_session_init();
1449 __connman_timeserver_init();
1450 __connman_connection_init();
1452 __connman_plugin_init(option_plugin, option_noplugin);
1454 __connman_resolver_init(option_dnsproxy);
1455 __connman_rtnl_start();
1456 __connman_dhcp_init();
1457 __connman_dhcpv6_init();
1458 __connman_wpad_init();
1459 __connman_wispr_init();
1460 #if !defined TIZEN_EXT
1461 __connman_rfkill_init();
1462 __connman_machine_init();
1465 g_free(option_config);
1466 g_free(option_device);
1467 g_free(option_plugin);
1468 g_free(option_nodevice);
1469 g_free(option_noplugin);
1471 g_main_loop_run(main_loop);
1473 g_source_remove(signal);
1475 #if !defined TIZEN_EXT
1476 __connman_machine_cleanup();
1477 __connman_rfkill_cleanup();
1479 __connman_wispr_cleanup();
1480 __connman_wpad_cleanup();
1481 __connman_dhcpv6_cleanup();
1482 __connman_session_cleanup();
1483 __connman_plugin_cleanup();
1484 __connman_provider_cleanup();
1485 __connman_connection_cleanup();
1486 __connman_timeserver_cleanup();
1487 __connman_detect_cleanup();
1488 __connman_proxy_cleanup();
1489 __connman_task_cleanup();
1490 __connman_rtnl_cleanup();
1491 __connman_resolver_cleanup();
1493 __connman_clock_cleanup();
1494 __connman_stats_cleanup();
1495 __connman_config_cleanup();
1496 __connman_manager_cleanup();
1497 __connman_counter_cleanup();
1498 __connman_tethering_cleanup();
1499 __connman_nat_cleanup();
1500 __connman_firewall_cleanup();
1501 __connman_peer_service_cleanup();
1502 __connman_peer_cleanup();
1503 #if defined TIZEN_EXT_WIFI_MESH
1504 __connman_mesh_cleanup();
1505 #endif /* TIZEN_EXT_WIFI_MESH */
1506 __connman_ippool_cleanup();
1507 __connman_device_cleanup();
1508 __connman_network_cleanup();
1509 __connman_dhcp_cleanup();
1510 __connman_service_cleanup();
1511 __connman_agent_cleanup();
1512 __connman_ipconfig_cleanup();
1513 __connman_notifier_cleanup();
1514 __connman_technology_cleanup();
1515 __connman_inotify_cleanup();
1517 __connman_util_cleanup();
1518 __connman_dbus_cleanup();
1520 __connman_log_cleanup(option_backtrace);
1522 dbus_connection_unref(conn);
1524 g_main_loop_unref(main_loop);
1526 if (connman_settings.pref_timeservers)
1527 g_strfreev(connman_settings.pref_timeservers);
1529 g_free(connman_settings.auto_connect);
1530 g_free(connman_settings.favorite_techs);
1531 g_free(connman_settings.preferred_techs);
1532 g_strfreev(connman_settings.fallback_nameservers);
1533 g_strfreev(connman_settings.blacklisted_interfaces);
1534 g_strfreev(connman_settings.tethering_technologies);
1536 #if defined TIZEN_EXT
1537 g_free(connman_ins_settings.ins_preferred_freq_bssid);
1538 g_free(connman_ins_settings.ins_preferred_freq);
1539 if (connman_ins_settings.ins_security_priority)
1540 g_strfreev(connman_ins_settings.ins_security_priority);
1543 g_free(option_debug);
1544 g_free(option_wifi);