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;
114 } connman_settings = {
116 .pref_timeservers = NULL,
117 .auto_connect = NULL,
118 .favorite_techs = NULL,
119 .preferred_techs = NULL,
120 .always_connected_techs = NULL,
121 .fallback_nameservers = NULL,
122 .timeout_inputreq = DEFAULT_INPUT_REQUEST_TIMEOUT,
123 .timeout_browserlaunch = DEFAULT_BROWSER_LAUNCH_TIMEOUT,
124 .blacklisted_interfaces = NULL,
125 .allow_hostname_updates = true,
126 .allow_domainname_updates = true,
127 .single_tech = false,
128 .tethering_technologies = NULL,
129 .persistent_tethering_mode = false,
130 .enable_6to4 = false,
131 .vendor_class_id = NULL,
132 .enable_online_check = true,
133 .auto_connect_roaming_services = false,
135 .use_gateways_as_timeservers = false,
136 #if defined TIZEN_EXT
137 .cellular_interfaces = NULL,
138 .tizen_tv_extension = false,
140 .global_nameserver = NULL,
141 .supplicant_debug = false,
142 .def_wifi_ifname = DEFAULT_WIFI_INTERFACE,
146 .wifi_roam_scan = false,
151 #if defined TIZEN_EXT
154 char *ins_preferred_freq_bssid;
155 bool ins_last_connected_bssid;
156 bool ins_assoc_reject;
157 bool ins_signal_bssid;
158 unsigned int ins_preferred_freq_bssid_score;
159 unsigned int ins_last_connected_bssid_score;
160 unsigned int ins_assoc_reject_score;
162 bool ins_last_user_selection;
163 unsigned int ins_last_user_selection_time;
164 bool ins_last_connected;
165 char *ins_preferred_freq;
166 char **ins_security_priority;
167 unsigned int ins_security_priority_count;
170 unsigned int ins_last_user_selection_score;
171 unsigned int ins_last_connected_score;
172 unsigned int ins_preferred_freq_score;
173 unsigned int ins_security_priority_score;
174 unsigned int ins_internet_score;
176 int ins_signal_level3_5ghz;
177 int ins_signal_level3_24ghz;
178 } connman_ins_settings = {
180 .ins_preferred_freq_bssid = NULL,
181 .ins_last_connected_bssid = true,
182 .ins_assoc_reject = true,
183 .ins_signal_bssid = true,
184 .ins_preferred_freq_bssid_score = 20,
185 .ins_last_connected_bssid_score = 20,
186 .ins_assoc_reject_score = 10,
188 .ins_last_user_selection = true,
189 .ins_last_user_selection_time = 480,
190 .ins_last_connected = true,
191 .ins_preferred_freq = NULL,
192 .ins_security_priority = NULL,
193 .ins_security_priority_count = 0,
195 .ins_internet = true,
196 .ins_last_user_selection_score = 30,
197 .ins_last_connected_score = 30,
198 .ins_preferred_freq_score = 60,
199 .ins_security_priority_score = 5,
200 .ins_internet_score = 30,
202 .ins_signal_level3_5ghz = -76,
203 .ins_signal_level3_24ghz = -74,
207 #define CONF_BG_SCAN "BackgroundScanning"
208 #define CONF_PREF_TIMESERVERS "FallbackTimeservers"
209 #define CONF_AUTO_CONNECT_TECHS "DefaultAutoConnectTechnologies"
210 #define CONF_FAVORITE_TECHS "DefaultFavoriteTechnologies"
211 #define CONF_ALWAYS_CONNECTED_TECHS "AlwaysConnectedTechnologies"
212 #define CONF_PREFERRED_TECHS "PreferredTechnologies"
213 #define CONF_FALLBACK_NAMESERVERS "FallbackNameservers"
214 #define CONF_TIMEOUT_INPUTREQ "InputRequestTimeout"
215 #define CONF_TIMEOUT_BROWSERLAUNCH "BrowserLaunchTimeout"
216 #define CONF_BLACKLISTED_INTERFACES "NetworkInterfaceBlacklist"
217 #define CONF_ALLOW_HOSTNAME_UPDATES "AllowHostnameUpdates"
218 #define CONF_ALLOW_DOMAINNAME_UPDATES "AllowDomainnameUpdates"
219 #define CONF_SINGLE_TECH "SingleConnectedTechnology"
220 #define CONF_TETHERING_TECHNOLOGIES "TetheringTechnologies"
221 #define CONF_PERSISTENT_TETHERING_MODE "PersistentTetheringMode"
222 #define CONF_ENABLE_6TO4 "Enable6to4"
223 #define CONF_VENDOR_CLASS_ID "VendorClassID"
224 #define CONF_ENABLE_ONLINE_CHECK "EnableOnlineCheck"
225 #define CONF_AUTO_CONNECT_ROAMING_SERVICES "AutoConnectRoamingServices"
226 #define CONF_ACD "AddressConflictDetection"
227 #define CONF_USE_GATEWAYS_AS_TIMESERVERS "UseGatewaysAsTimeservers"
228 #if defined TIZEN_EXT
229 #define CONF_CELLULAR_INTERFACE "NetworkCellularInterfaceList"
230 #define CONF_TIZEN_TV_EXT "TizenTVExtension"
231 #define CONF_ENABLE_AUTO_IP "EnableAutoIp"
232 #define CONF_GLOBAL_NAMESERVER "GlobalNameserver"
233 #define CONF_CONNMAN_SUPPLICANT_DEBUG "ConnmanSupplicantDebug"
234 #define CONF_CONNMAN_WIFI_DEF_IFNAME "DefaultWifiInterface"
235 #define CONF_CONNMAN_FILE_LOG "FileLogging"
236 #define CONF_CONNMAN_DLOG_LOG "DlogLogging"
237 #define CONF_CONNMAN_SIMPLIFIED_LOG "SimplifiedLog"
238 #define CONF_CONNMAN_WIFI_ROAM_SCAN "WifiRoamingScan"
239 #define CONF_CONNMAN_WIFI_ROAM "WifiRoaming"
242 #if defined TIZEN_EXT
244 #define CONF_INS_PREFERRED_FREQ_BSSID "INSPreferredFreqBSSID"
245 #define CONF_INS_PREFERRED_FREQ_BSSID_SCORE "INSPreferredFreqBSSIDScore"
246 #define CONF_INS_LAST_CONNECTED_BSSID "INSLastConnectedBSSID"
247 #define CONF_INS_LAST_CONNECTED_BSSID_SCORE "INSLastConnectedBSSIDScore"
248 #define CONF_INS_ASSOC_REJECT "INSAssocReject"
249 #define CONF_INS_ASSOC_REJECT_SCORE "INSAssocRejectScore"
250 #define CONF_INS_SIGNAL_BSSID "INSSignalBSSID"
252 #define CONF_INS_LAST_USER_SELECTION "INSLastUserSelection"
253 #define CONF_INS_LAST_USER_SELECTION_TIME "INSLastUserSelectionTime"
254 #define CONF_INS_LAST_USER_SELECTION_SCORE "INSLastUserSelectionScore"
255 #define CONF_INS_LAST_CONNECTED "INSLastConnected"
256 #define CONF_INS_LAST_CONNECTED_SCORE "INSLastConnectedScore"
257 #define CONF_INS_PREFERRED_FREQ "INSPreferredFreq"
258 #define CONF_INS_PREFERRED_FREQ_SCORE "INSPreferredFreqScore"
259 #define CONF_INS_SECURITY_PRIORITY "INSSecurityPriority"
260 #define CONF_INS_SECURITY_PRIORITY_COUNT "INSSecurityPriorityCount"
261 #define CONF_INS_SECURITY_PRIORITY_SCORE "INSSecurityPriorityScore"
262 #define CONF_INS_SIGNAL "INSSignal"
263 #define CONF_INS_INTERNET "INSInternet"
264 #define CONF_INS_INTERNET_SCORE "INSInternetScore"
266 #define CONF_INS_SIGNAL_LEVEL3_5GHZ "INSSignalLevel3_5GHz"
267 #define CONF_INS_SIGNAL_LEVEL3_24GHZ "INSSignalLevel3_24GHz"
270 static const char *supported_options[] = {
272 CONF_PREF_TIMESERVERS,
273 CONF_AUTO_CONNECT_TECHS,
274 CONF_ALWAYS_CONNECTED_TECHS,
275 CONF_PREFERRED_TECHS,
276 CONF_FALLBACK_NAMESERVERS,
277 CONF_TIMEOUT_INPUTREQ,
278 CONF_TIMEOUT_BROWSERLAUNCH,
279 CONF_BLACKLISTED_INTERFACES,
280 CONF_ALLOW_HOSTNAME_UPDATES,
281 CONF_ALLOW_DOMAINNAME_UPDATES,
283 CONF_TETHERING_TECHNOLOGIES,
284 CONF_PERSISTENT_TETHERING_MODE,
286 CONF_VENDOR_CLASS_ID,
287 CONF_ENABLE_ONLINE_CHECK,
288 CONF_AUTO_CONNECT_ROAMING_SERVICES,
290 CONF_USE_GATEWAYS_AS_TIMESERVERS,
291 #if defined TIZEN_EXT
292 CONF_CELLULAR_INTERFACE,
295 CONF_GLOBAL_NAMESERVER,
296 CONF_CONNMAN_SUPPLICANT_DEBUG,
297 CONF_CONNMAN_WIFI_DEF_IFNAME,
298 CONF_CONNMAN_FILE_LOG,
299 CONF_CONNMAN_DLOG_LOG,
300 CONF_CONNMAN_SIMPLIFIED_LOG,
301 CONF_CONNMAN_WIFI_ROAM_SCAN,
302 CONF_CONNMAN_WIFI_ROAM,
307 #if defined TIZEN_EXT
308 static const char *supported_ins_options[] = {
310 CONF_INS_PREFERRED_FREQ_BSSID,
311 CONF_INS_PREFERRED_FREQ_BSSID_SCORE,
312 CONF_INS_LAST_CONNECTED_BSSID,
313 CONF_INS_LAST_CONNECTED_BSSID_SCORE,
314 CONF_INS_ASSOC_REJECT,
315 CONF_INS_ASSOC_REJECT_SCORE,
316 CONF_INS_SIGNAL_BSSID,
318 CONF_INS_LAST_USER_SELECTION,
319 CONF_INS_LAST_USER_SELECTION_TIME,
320 CONF_INS_LAST_USER_SELECTION_SCORE,
321 CONF_INS_LAST_CONNECTED,
322 CONF_INS_LAST_CONNECTED_SCORE,
323 CONF_INS_PREFERRED_FREQ,
324 CONF_INS_PREFERRED_FREQ_SCORE,
325 CONF_INS_SECURITY_PRIORITY,
326 CONF_INS_SECURITY_PRIORITY_COUNT,
327 CONF_INS_SECURITY_PRIORITY_SCORE,
330 CONF_INS_INTERNET_SCORE,
332 CONF_INS_SIGNAL_LEVEL3_5GHZ,
333 CONF_INS_SIGNAL_LEVEL3_24GHZ,
338 static GKeyFile *load_config(const char *file)
343 keyfile = g_key_file_new();
345 g_key_file_set_list_separator(keyfile, ',');
347 if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
348 if (err->code != G_FILE_ERROR_NOENT) {
349 connman_error("Parsing %s failed: %s", file,
354 g_key_file_free(keyfile);
361 static uint *parse_service_types(char **str_list, gsize len)
363 unsigned int *type_list;
365 enum connman_service_type type;
367 type_list = g_try_new0(unsigned int, len + 1);
373 while (str_list[i]) {
374 type = __connman_service_string2type(str_list[i]);
376 if (type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
383 type_list[j] = CONNMAN_SERVICE_TYPE_UNKNOWN;
388 static char **parse_fallback_nameservers(char **nameservers, gsize len)
393 servers = g_try_new0(char *, len + 1);
399 while (nameservers[i]) {
400 if (connman_inet_check_ipaddress(nameservers[i]) > 0) {
401 servers[j] = g_strdup(nameservers[i]);
410 static void check_config(GKeyFile *config)
418 keys = g_key_file_get_groups(config, NULL);
420 for (j = 0; keys && keys[j]; j++) {
421 #if defined TIZEN_EXT
422 if (g_strcmp0(keys[j], "General") != 0 &&
423 g_strcmp0(keys[j], "INS") != 0)
425 if (g_strcmp0(keys[j], "General") != 0)
427 connman_warn("Unknown group %s in %s",
433 keys = g_key_file_get_keys(config, "General", NULL, NULL);
435 for (j = 0; keys && keys[j]; j++) {
440 for (i = 0; supported_options[i]; i++) {
441 if (g_strcmp0(keys[j], supported_options[i]) == 0) {
446 if (!found && !supported_options[i])
447 connman_warn("Unknown option %s in %s",
453 #if defined TIZEN_EXT
454 keys = g_key_file_get_keys(config, "INS", NULL, NULL);
456 for (j = 0; keys && keys[j]; j++) {
461 for (i = 0; supported_ins_options[i]; i++) {
462 if (g_strcmp0(keys[j], supported_ins_options[i]) == 0) {
467 if (!found && !supported_ins_options[i])
468 connman_warn("Unknown option %s in %s",
476 #if defined TIZEN_EXT
477 static void check_Tizen_INS_configuration(GKeyFile *config)
479 GError *error = NULL;
480 char *ins_preferred_freq_bssid;
481 char *ins_preferred_freq;
482 char **ins_security_priority;
487 ins_preferred_freq_bssid = __connman_config_get_string(config, "INS",
488 CONF_INS_PREFERRED_FREQ_BSSID, &error);
490 connman_ins_settings.ins_preferred_freq_bssid = ins_preferred_freq_bssid;
492 g_clear_error(&error);
494 integer = g_key_file_get_integer(config, "INS",
495 CONF_INS_PREFERRED_FREQ_BSSID_SCORE, &error);
496 if (!error && integer >= 0)
497 connman_ins_settings.ins_preferred_freq_bssid_score = integer;
499 g_clear_error(&error);
501 boolean = __connman_config_get_bool(config, "INS",
502 CONF_INS_LAST_CONNECTED_BSSID, &error);
504 connman_ins_settings.ins_last_connected_bssid = boolean;
506 g_clear_error(&error);
508 integer = g_key_file_get_integer(config, "INS",
509 CONF_INS_LAST_CONNECTED_BSSID_SCORE, &error);
510 if (!error && integer >= 0)
511 connman_ins_settings.ins_last_connected_bssid_score = integer;
513 g_clear_error(&error);
515 boolean = __connman_config_get_bool(config, "INS",
516 CONF_INS_ASSOC_REJECT, &error);
518 connman_ins_settings.ins_assoc_reject = boolean;
520 g_clear_error(&error);
522 integer = g_key_file_get_integer(config, "INS",
523 CONF_INS_ASSOC_REJECT_SCORE, &error);
524 if (!error && integer >= 0)
525 connman_ins_settings.ins_assoc_reject_score = integer;
527 g_clear_error(&error);
529 boolean = __connman_config_get_bool(config, "INS",
530 CONF_INS_SIGNAL_BSSID, &error);
532 connman_ins_settings.ins_signal_bssid = boolean;
534 g_clear_error(&error);
536 boolean = __connman_config_get_bool(config, "INS",
537 CONF_INS_LAST_USER_SELECTION, &error);
539 connman_ins_settings.ins_last_user_selection = boolean;
541 g_clear_error(&error);
543 integer = g_key_file_get_integer(config, "INS",
544 CONF_INS_LAST_USER_SELECTION_TIME, &error);
545 if (!error && integer >= 0)
546 connman_ins_settings.ins_last_user_selection_time = integer;
548 g_clear_error(&error);
550 integer = g_key_file_get_integer(config, "INS",
551 CONF_INS_LAST_USER_SELECTION_SCORE, &error);
552 if (!error && integer >= 0)
553 connman_ins_settings.ins_last_user_selection_score = integer;
555 g_clear_error(&error);
557 boolean = __connman_config_get_bool(config, "INS",
558 CONF_INS_LAST_CONNECTED, &error);
560 connman_ins_settings.ins_last_connected = boolean;
562 g_clear_error(&error);
564 integer = g_key_file_get_integer(config, "INS",
565 CONF_INS_LAST_CONNECTED_SCORE, &error);
566 if (!error && integer >= 0)
567 connman_ins_settings.ins_last_connected_score = integer;
569 g_clear_error(&error);
571 ins_preferred_freq = __connman_config_get_string(config, "INS",
572 CONF_INS_PREFERRED_FREQ, &error);
574 connman_ins_settings.ins_preferred_freq = ins_preferred_freq;
576 g_clear_error(&error);
578 integer = g_key_file_get_integer(config, "INS",
579 CONF_INS_PREFERRED_FREQ_SCORE, &error);
580 if (!error && integer >= 0)
581 connman_ins_settings.ins_preferred_freq_score = integer;
583 g_clear_error(&error);
585 ins_security_priority = g_key_file_get_string_list(config, "INS",
586 CONF_INS_SECURITY_PRIORITY, &len, &error);
589 connman_ins_settings.ins_security_priority = ins_security_priority;
590 connman_ins_settings.ins_security_priority_count = len;
593 g_clear_error(&error);
595 integer = g_key_file_get_integer(config, "INS",
596 CONF_INS_SECURITY_PRIORITY_SCORE, &error);
597 if (!error && integer >= 0)
598 connman_ins_settings.ins_security_priority_score = integer;
600 g_clear_error(&error);
602 boolean = __connman_config_get_bool(config, "INS",
603 CONF_INS_SIGNAL, &error);
605 connman_ins_settings.ins_signal = boolean;
607 g_clear_error(&error);
609 boolean = __connman_config_get_bool(config, "INS",
610 CONF_INS_INTERNET, &error);
612 connman_ins_settings.ins_internet = boolean;
614 g_clear_error(&error);
616 integer = g_key_file_get_integer(config, "INS",
617 CONF_INS_INTERNET_SCORE, &error);
618 if (!error && integer >= 0)
619 connman_ins_settings.ins_internet_score = integer;
621 g_clear_error(&error);
623 integer = g_key_file_get_integer(config, "INS",
624 CONF_INS_SIGNAL_LEVEL3_5GHZ, &error);
626 connman_ins_settings.ins_signal_level3_5ghz = integer;
628 g_clear_error(&error);
630 integer = g_key_file_get_integer(config, "INS",
631 CONF_INS_SIGNAL_LEVEL3_24GHZ, &error);
633 connman_ins_settings.ins_signal_level3_24ghz = integer;
635 g_clear_error(&error);
638 static void check_Tizen_configuration(GKeyFile *config)
640 GError *error = NULL;
641 char **cellular_interfaces;
642 char *global_nameserver;
643 char *default_wifi_ifname;
647 cellular_interfaces = g_key_file_get_string_list(config, "General",
648 CONF_CELLULAR_INTERFACE, &len, &error);
651 connman_settings.cellular_interfaces = cellular_interfaces;
653 g_clear_error(&error);
655 boolean = __connman_config_get_bool(config, "General",
656 CONF_TIZEN_TV_EXT, &error);
658 connman_settings.tizen_tv_extension = boolean;
660 g_clear_error(&error);
662 boolean = __connman_config_get_bool(config, "General",
663 CONF_ENABLE_AUTO_IP, &error);
665 connman_settings.auto_ip = boolean;
667 g_clear_error(&error);
669 global_nameserver = __connman_config_get_string(config, "General",
670 CONF_GLOBAL_NAMESERVER, &error);
672 connman_settings.global_nameserver = global_nameserver;
674 g_clear_error(&error);
676 boolean = __connman_config_get_bool(config, "General",
677 CONF_CONNMAN_SUPPLICANT_DEBUG, &error);
679 connman_settings.supplicant_debug = boolean;
681 g_clear_error(&error);
683 default_wifi_ifname = __connman_config_get_string(config, "General",
684 CONF_CONNMAN_WIFI_DEF_IFNAME, &error);
686 connman_settings.def_wifi_ifname = default_wifi_ifname;
688 g_clear_error(&error);
690 boolean = __connman_config_get_bool(config, "General",
691 CONF_CONNMAN_FILE_LOG, &error);
693 connman_settings.file_log = boolean;
695 g_clear_error(&error);
697 boolean = __connman_config_get_bool(config, "General",
698 CONF_CONNMAN_DLOG_LOG, &error);
700 connman_settings.dlog_log = boolean;
702 g_clear_error(&error);
704 boolean = __connman_config_get_bool(config, "General",
705 CONF_CONNMAN_SIMPLIFIED_LOG, &error);
707 connman_settings.simple_log = boolean;
709 boolean = __connman_config_get_bool(config, "General",
710 CONF_CONNMAN_WIFI_ROAM_SCAN, &error);
712 connman_settings.wifi_roam_scan = boolean;
714 boolean = __connman_config_get_bool(config, "General",
715 CONF_CONNMAN_WIFI_ROAM, &error);
717 connman_settings.wifi_roam = boolean;
719 g_clear_error(&error);
721 check_Tizen_INS_configuration(config);
724 static void set_nofile_inc(void)
729 rlim.rlim_cur = 8192;
730 rlim.rlim_max = 8192;
732 err = setrlimit(RLIMIT_NOFILE, &rlim);
734 DBG("fail to increase FILENO err(%d)", err);
740 static void parse_config(GKeyFile *config)
742 GError *error = NULL;
748 char *vendor_class_id;
753 connman_settings.auto_connect =
754 parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
755 connman_settings.favorite_techs =
756 parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
757 connman_settings.blacklisted_interfaces =
758 g_strdupv(default_blacklist);
762 DBG("parsing %s", MAINFILE);
764 boolean = g_key_file_get_boolean(config, "General",
765 CONF_BG_SCAN, &error);
767 connman_settings.bg_scan = boolean;
769 g_clear_error(&error);
771 timeservers = __connman_config_get_string_list(config, "General",
772 CONF_PREF_TIMESERVERS, NULL, &error);
774 connman_settings.pref_timeservers = timeservers;
776 g_clear_error(&error);
778 str_list = __connman_config_get_string_list(config, "General",
779 CONF_AUTO_CONNECT_TECHS, &len, &error);
782 connman_settings.auto_connect =
783 parse_service_types(str_list, len);
785 connman_settings.auto_connect =
786 parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
788 g_strfreev(str_list);
790 g_clear_error(&error);
792 str_list = __connman_config_get_string_list(config, "General",
793 CONF_FAVORITE_TECHS, &len, &error);
796 connman_settings.favorite_techs =
797 parse_service_types(str_list, len);
799 connman_settings.favorite_techs =
800 parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
802 g_strfreev(str_list);
804 g_clear_error(&error);
806 str_list = __connman_config_get_string_list(config, "General",
807 CONF_PREFERRED_TECHS, &len, &error);
810 connman_settings.preferred_techs =
811 parse_service_types(str_list, len);
813 g_strfreev(str_list);
815 g_clear_error(&error);
817 str_list = __connman_config_get_string_list(config, "General",
818 CONF_ALWAYS_CONNECTED_TECHS, &len, &error);
821 connman_settings.always_connected_techs =
822 parse_service_types(str_list, len);
824 g_strfreev(str_list);
826 g_clear_error(&error);
828 str_list = __connman_config_get_string_list(config, "General",
829 CONF_FALLBACK_NAMESERVERS, &len, &error);
832 connman_settings.fallback_nameservers =
833 parse_fallback_nameservers(str_list, len);
835 g_strfreev(str_list);
837 g_clear_error(&error);
839 timeout = g_key_file_get_integer(config, "General",
840 CONF_TIMEOUT_INPUTREQ, &error);
841 if (!error && timeout >= 0)
842 connman_settings.timeout_inputreq = timeout * 1000;
844 g_clear_error(&error);
846 timeout = g_key_file_get_integer(config, "General",
847 CONF_TIMEOUT_BROWSERLAUNCH, &error);
848 if (!error && timeout >= 0)
849 connman_settings.timeout_browserlaunch = timeout * 1000;
851 g_clear_error(&error);
853 interfaces = __connman_config_get_string_list(config, "General",
854 CONF_BLACKLISTED_INTERFACES, &len, &error);
857 connman_settings.blacklisted_interfaces = interfaces;
859 connman_settings.blacklisted_interfaces =
860 g_strdupv(default_blacklist);
862 g_clear_error(&error);
864 boolean = __connman_config_get_bool(config, "General",
865 CONF_ALLOW_HOSTNAME_UPDATES,
868 connman_settings.allow_hostname_updates = boolean;
870 g_clear_error(&error);
872 boolean = __connman_config_get_bool(config, "General",
873 CONF_ALLOW_DOMAINNAME_UPDATES,
876 connman_settings.allow_domainname_updates = boolean;
878 g_clear_error(&error);
880 boolean = __connman_config_get_bool(config, "General",
881 CONF_SINGLE_TECH, &error);
883 connman_settings.single_tech = boolean;
885 g_clear_error(&error);
887 tethering = __connman_config_get_string_list(config, "General",
888 CONF_TETHERING_TECHNOLOGIES, &len, &error);
891 connman_settings.tethering_technologies = tethering;
893 g_clear_error(&error);
895 boolean = __connman_config_get_bool(config, "General",
896 CONF_PERSISTENT_TETHERING_MODE,
899 connman_settings.persistent_tethering_mode = boolean;
901 g_clear_error(&error);
903 boolean = __connman_config_get_bool(config, "General",
904 CONF_ENABLE_6TO4, &error);
906 connman_settings.enable_6to4 = boolean;
908 g_clear_error(&error);
910 vendor_class_id = __connman_config_get_string(config, "General",
911 CONF_VENDOR_CLASS_ID, &error);
913 connman_settings.vendor_class_id = vendor_class_id;
915 g_clear_error(&error);
917 boolean = __connman_config_get_bool(config, "General",
918 CONF_ENABLE_ONLINE_CHECK, &error);
920 connman_settings.enable_online_check = boolean;
922 connman_info("Online check disabled by main config.");
925 g_clear_error(&error);
927 boolean = __connman_config_get_bool(config, "General",
928 CONF_AUTO_CONNECT_ROAMING_SERVICES, &error);
930 connman_settings.auto_connect_roaming_services = boolean;
932 g_clear_error(&error);
934 boolean = __connman_config_get_bool(config, "General", CONF_ACD, &error);
936 connman_settings.acd = boolean;
938 g_clear_error(&error);
940 boolean = __connman_config_get_bool(config, "General",
941 CONF_USE_GATEWAYS_AS_TIMESERVERS, &error);
943 connman_settings.use_gateways_as_timeservers = boolean;
945 g_clear_error(&error);
947 #if defined TIZEN_EXT
948 check_Tizen_configuration(config);
952 static int config_init(const char *file)
956 #if defined TIZEN_EXT
959 config = load_config(file);
960 check_config(config);
961 parse_config(config);
963 g_key_file_free(config);
965 #if defined TIZEN_EXT
966 set_simple_log_option(connman_settings.simple_log);
967 set_dlog_logging_option(connman_settings.dlog_log);
968 set_file_logging_option(connman_settings.file_log);
973 static GMainLoop *main_loop = NULL;
975 static unsigned int __terminated = 0;
977 static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
980 struct signalfd_siginfo si;
984 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
987 fd = g_io_channel_unix_get_fd(channel);
989 result = read(fd, &si, sizeof(si));
990 if (result != sizeof(si))
993 switch (si.ssi_signo) {
996 if (__terminated == 0) {
997 connman_info("Terminating");
998 g_main_loop_quit(main_loop);
1008 static guint setup_signalfd(void)
1010 GIOChannel *channel;
1016 sigaddset(&mask, SIGINT);
1017 sigaddset(&mask, SIGTERM);
1019 if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
1020 perror("Failed to set signal mask");
1024 fd = signalfd(-1, &mask, 0);
1026 perror("Failed to create signal descriptor");
1030 channel = g_io_channel_unix_new(fd);
1032 g_io_channel_set_close_on_unref(channel, TRUE);
1033 g_io_channel_set_encoding(channel, NULL, NULL);
1034 g_io_channel_set_buffered(channel, FALSE);
1036 source = g_io_add_watch(channel,
1037 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1038 signal_handler, NULL);
1040 g_io_channel_unref(channel);
1045 static void disconnect_callback(DBusConnection *conn, void *user_data)
1047 connman_error("D-Bus disconnect");
1049 g_main_loop_quit(main_loop);
1052 static gchar *option_config = NULL;
1053 static gchar *option_debug = NULL;
1054 static gchar *option_device = NULL;
1055 static gchar *option_plugin = NULL;
1056 static gchar *option_nodevice = NULL;
1057 static gchar *option_noplugin = NULL;
1058 static gchar *option_wifi = NULL;
1059 static gboolean option_detach = TRUE;
1060 static gboolean option_dnsproxy = TRUE;
1061 static gboolean option_backtrace = TRUE;
1062 static gboolean option_version = FALSE;
1064 static bool parse_debug(const char *key, const char *value,
1065 gpointer user_data, GError **error)
1069 char *prev = option_debug;
1071 option_debug = g_strconcat(prev, ",", value, NULL);
1074 option_debug = g_strdup(value);
1077 g_free(option_debug);
1078 option_debug = g_strdup("*");
1084 static bool parse_noplugin(const char *key, const char *value,
1085 gpointer user_data, GError **error)
1087 if (option_noplugin) {
1088 char *prev = option_noplugin;
1090 option_noplugin = g_strconcat(prev, ",", value, NULL);
1093 option_noplugin = g_strdup(value);
1099 static GOptionEntry options[] = {
1100 { "config", 'c', 0, G_OPTION_ARG_STRING, &option_config,
1101 "Load the specified configuration file "
1102 "instead of " CONFIGMAINFILE, "FILE" },
1103 { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
1104 G_OPTION_ARG_CALLBACK, parse_debug,
1105 "Specify debug options to enable", "DEBUG" },
1106 { "device", 'i', 0, G_OPTION_ARG_STRING, &option_device,
1107 "Specify networking devices or interfaces", "DEV,..." },
1108 { "nodevice", 'I', 0, G_OPTION_ARG_STRING, &option_nodevice,
1109 "Specify networking interfaces to ignore", "DEV,..." },
1110 { "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin,
1111 "Specify plugins to load", "NAME,..." },
1112 { "noplugin", 'P', 0, G_OPTION_ARG_CALLBACK, &parse_noplugin,
1113 "Specify plugins not to load", "NAME,..." },
1114 { "wifi", 'W', 0, G_OPTION_ARG_STRING, &option_wifi,
1115 "Specify driver for WiFi/Supplicant", "NAME" },
1116 { "nodaemon", 'n', G_OPTION_FLAG_REVERSE,
1117 G_OPTION_ARG_NONE, &option_detach,
1118 "Don't fork daemon to background" },
1119 { "nodnsproxy", 'r', G_OPTION_FLAG_REVERSE,
1120 G_OPTION_ARG_NONE, &option_dnsproxy,
1121 "Don't support DNS resolving" },
1122 { "nobacktrace", 0, G_OPTION_FLAG_REVERSE,
1123 G_OPTION_ARG_NONE, &option_backtrace,
1124 "Don't print out backtrace information" },
1125 { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
1126 "Show version information and exit" },
1130 const char *connman_option_get_string(const char *key)
1132 if (g_str_equal(key, CONF_VENDOR_CLASS_ID))
1133 return connman_settings.vendor_class_id;
1135 if (g_strcmp0(key, "wifi") == 0) {
1137 return "nl80211,wext";
1142 #if defined TIZEN_EXT
1143 if (g_str_equal(key, CONF_GLOBAL_NAMESERVER))
1144 return connman_settings.global_nameserver;
1146 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID))
1147 return connman_ins_settings.ins_preferred_freq_bssid;
1149 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ))
1150 return connman_ins_settings.ins_preferred_freq;
1152 if (g_str_equal(key, CONF_CONNMAN_WIFI_DEF_IFNAME))
1153 return connman_settings.def_wifi_ifname;
1158 bool connman_setting_get_bool(const char *key)
1160 if (g_str_equal(key, CONF_BG_SCAN))
1161 return connman_settings.bg_scan;
1163 if (g_str_equal(key, CONF_ALLOW_HOSTNAME_UPDATES))
1164 return connman_settings.allow_hostname_updates;
1166 if (g_str_equal(key, CONF_ALLOW_DOMAINNAME_UPDATES))
1167 return connman_settings.allow_domainname_updates;
1169 if (g_str_equal(key, CONF_SINGLE_TECH))
1170 return connman_settings.single_tech;
1172 if (g_str_equal(key, CONF_PERSISTENT_TETHERING_MODE))
1173 return connman_settings.persistent_tethering_mode;
1175 if (g_str_equal(key, CONF_ENABLE_6TO4))
1176 return connman_settings.enable_6to4;
1178 if (g_str_equal(key, CONF_ENABLE_ONLINE_CHECK))
1179 return connman_settings.enable_online_check;
1181 if (g_str_equal(key, CONF_AUTO_CONNECT_ROAMING_SERVICES))
1182 return connman_settings.auto_connect_roaming_services;
1184 if (g_str_equal(key, CONF_ACD))
1185 return connman_settings.acd;
1187 if (g_str_equal(key, CONF_USE_GATEWAYS_AS_TIMESERVERS))
1188 return connman_settings.use_gateways_as_timeservers;
1190 #if defined TIZEN_EXT
1191 if (g_str_equal(key, CONF_ENABLE_AUTO_IP))
1192 return connman_settings.auto_ip;
1194 if (g_str_equal(key, CONF_CONNMAN_SUPPLICANT_DEBUG))
1195 return connman_settings.supplicant_debug;
1197 if (g_str_equal(key, CONF_CONNMAN_FILE_LOG))
1198 return connman_settings.file_log;
1200 if (g_str_equal(key, CONF_CONNMAN_DLOG_LOG))
1201 return connman_settings.dlog_log;
1203 if (g_str_equal(key, CONF_CONNMAN_SIMPLIFIED_LOG))
1204 return connman_settings.simple_log;
1206 if (g_str_equal(key, CONF_CONNMAN_WIFI_ROAM_SCAN))
1207 return connman_settings.wifi_roam_scan;
1209 if (g_str_equal(key, CONF_CONNMAN_WIFI_ROAM))
1210 return connman_settings.wifi_roam;
1213 #if defined TIZEN_EXT
1214 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID))
1215 return connman_ins_settings.ins_last_connected_bssid;
1217 if (g_str_equal(key, CONF_INS_ASSOC_REJECT))
1218 return connman_ins_settings.ins_assoc_reject;
1220 if (g_str_equal(key, CONF_INS_SIGNAL_BSSID))
1221 return connman_ins_settings.ins_signal_bssid;
1223 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION))
1224 return connman_ins_settings.ins_last_user_selection;
1226 if (g_str_equal(key, CONF_INS_LAST_CONNECTED))
1227 return connman_ins_settings.ins_last_connected;
1229 if (g_str_equal(key, CONF_INS_SIGNAL))
1230 return connman_ins_settings.ins_signal;
1232 if (g_str_equal(key, CONF_INS_INTERNET))
1233 return connman_ins_settings.ins_internet;
1239 #if defined TIZEN_EXT
1240 unsigned int connman_setting_get_uint(const char *key)
1242 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID_SCORE))
1243 return connman_ins_settings.ins_preferred_freq_bssid_score;
1245 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID_SCORE))
1246 return connman_ins_settings.ins_last_connected_bssid_score;
1248 if (g_str_equal(key, CONF_INS_ASSOC_REJECT_SCORE))
1249 return connman_ins_settings.ins_assoc_reject_score;
1251 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_TIME))
1252 return connman_ins_settings.ins_last_user_selection_time;
1254 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_COUNT))
1255 return connman_ins_settings.ins_security_priority_count;
1257 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_SCORE))
1258 return connman_ins_settings.ins_last_user_selection_score;
1260 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_SCORE))
1261 return connman_ins_settings.ins_last_connected_score;
1263 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_SCORE))
1264 return connman_ins_settings.ins_preferred_freq_score;
1266 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_SCORE))
1267 return connman_ins_settings.ins_security_priority_score;
1269 if (g_str_equal(key, CONF_INS_INTERNET_SCORE))
1270 return connman_ins_settings.ins_internet_score;
1275 int connman_setting_get_int(const char *key)
1277 if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_5GHZ))
1278 return connman_ins_settings.ins_signal_level3_5ghz;
1280 if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_24GHZ))
1281 return connman_ins_settings.ins_signal_level3_24ghz;
1287 char **connman_setting_get_string_list(const char *key)
1289 if (g_str_equal(key, CONF_PREF_TIMESERVERS))
1290 return connman_settings.pref_timeservers;
1292 if (g_str_equal(key, CONF_FALLBACK_NAMESERVERS))
1293 return connman_settings.fallback_nameservers;
1295 if (g_str_equal(key, CONF_BLACKLISTED_INTERFACES))
1296 return connman_settings.blacklisted_interfaces;
1298 if (g_str_equal(key, CONF_TETHERING_TECHNOLOGIES))
1299 return connman_settings.tethering_technologies;
1301 #if defined TIZEN_EXT
1302 if (g_str_equal(key, CONF_CELLULAR_INTERFACE))
1303 return connman_settings.cellular_interfaces;
1306 #if defined TIZEN_EXT
1307 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY))
1308 return connman_ins_settings.ins_security_priority;
1314 unsigned int *connman_setting_get_uint_list(const char *key)
1316 if (g_str_equal(key, CONF_AUTO_CONNECT_TECHS))
1317 return connman_settings.auto_connect;
1319 if (g_str_equal(key, CONF_FAVORITE_TECHS))
1320 return connman_settings.favorite_techs;
1322 if (g_str_equal(key, CONF_PREFERRED_TECHS))
1323 return connman_settings.preferred_techs;
1325 if (g_str_equal(key, CONF_ALWAYS_CONNECTED_TECHS))
1326 return connman_settings.always_connected_techs;
1331 unsigned int connman_timeout_input_request(void)
1333 return connman_settings.timeout_inputreq;
1336 unsigned int connman_timeout_browser_launch(void)
1338 return connman_settings.timeout_browserlaunch;
1341 int main(int argc, char *argv[])
1343 GOptionContext *context;
1344 GError *error = NULL;
1345 DBusConnection *conn;
1349 context = g_option_context_new(NULL);
1350 g_option_context_add_main_entries(context, options, NULL);
1352 if (!g_option_context_parse(context, &argc, &argv, &error)) {
1354 g_printerr("%s\n", error->message);
1355 g_error_free(error);
1357 g_printerr("An unknown error occurred\n");
1361 g_option_context_free(context);
1363 if (option_version) {
1364 printf("%s\n", VERSION);
1368 if (option_detach) {
1370 perror("Can't start daemon");
1375 if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
1376 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
1377 if (errno != EEXIST)
1378 perror("Failed to create storage directory");
1383 main_loop = g_main_loop_new(NULL, FALSE);
1385 signal = setup_signalfd();
1387 dbus_error_init(&err);
1389 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
1391 if (dbus_error_is_set(&err)) {
1392 fprintf(stderr, "%s\n", err.message);
1393 dbus_error_free(&err);
1395 fprintf(stderr, "Can't register with system bus\n");
1399 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
1401 __connman_log_init(argv[0], option_debug, option_detach,
1402 option_backtrace, "Connection Manager", VERSION);
1404 __connman_dbus_init(conn);
1406 #if defined TIZEN_EXT
1407 if (access(CONTAINER_FILE, F_OK) == 0) {
1408 g_main_loop_run(main_loop);
1410 g_source_remove(signal);
1411 dbus_connection_unref(conn);
1412 g_main_loop_unref(main_loop);
1414 __connman_dbus_cleanup();
1415 __connman_log_cleanup(option_backtrace);
1422 config_init(CONFIGMAINFILE);
1424 config_init(option_config);
1426 __connman_util_init();
1427 __connman_inotify_init();
1428 __connman_technology_init();
1429 __connman_notifier_init();
1430 __connman_agent_init();
1431 __connman_service_init();
1432 __connman_peer_service_init();
1433 __connman_peer_init();
1434 #if defined TIZEN_EXT_WIFI_MESH
1435 __connman_mesh_init();
1436 #endif /* TIZEN_EXT_WIFI_MESH */
1437 __connman_provider_init();
1438 __connman_network_init();
1439 __connman_config_init();
1440 __connman_device_init(option_device, option_nodevice);
1442 __connman_ippool_init();
1443 __connman_firewall_init();
1444 __connman_nat_init();
1445 __connman_tethering_init();
1446 __connman_counter_init();
1447 __connman_manager_init();
1448 __connman_stats_init();
1449 __connman_clock_init();
1451 __connman_ipconfig_init();
1452 #if defined TIZEN_EXT
1453 __connman_rtnl_init(GIO_SOCKET_RETRY_COUNT);
1454 #else /* TIZEN_EXT */
1455 __connman_rtnl_init();
1456 #endif /* TIZEN_EXT */
1457 __connman_task_init();
1458 __connman_proxy_init();
1459 __connman_detect_init();
1460 __connman_session_init();
1461 __connman_timeserver_init();
1462 __connman_connection_init();
1464 __connman_plugin_init(option_plugin, option_noplugin);
1466 __connman_resolver_init(option_dnsproxy);
1467 __connman_rtnl_start();
1468 __connman_dhcp_init();
1469 __connman_dhcpv6_init();
1470 __connman_wpad_init();
1471 __connman_wispr_init();
1472 #if !defined TIZEN_EXT
1473 __connman_rfkill_init();
1474 __connman_machine_init();
1477 g_free(option_config);
1478 g_free(option_device);
1479 g_free(option_plugin);
1480 g_free(option_nodevice);
1481 g_free(option_noplugin);
1483 g_main_loop_run(main_loop);
1485 g_source_remove(signal);
1487 #if !defined TIZEN_EXT
1488 __connman_machine_cleanup();
1489 __connman_rfkill_cleanup();
1491 __connman_wispr_cleanup();
1492 __connman_wpad_cleanup();
1493 __connman_dhcpv6_cleanup();
1494 __connman_session_cleanup();
1495 __connman_plugin_cleanup();
1496 __connman_provider_cleanup();
1497 __connman_connection_cleanup();
1498 __connman_timeserver_cleanup();
1499 __connman_detect_cleanup();
1500 __connman_proxy_cleanup();
1501 __connman_task_cleanup();
1502 __connman_rtnl_cleanup();
1503 __connman_resolver_cleanup();
1505 __connman_clock_cleanup();
1506 __connman_stats_cleanup();
1507 __connman_config_cleanup();
1508 __connman_manager_cleanup();
1509 __connman_counter_cleanup();
1510 __connman_tethering_cleanup();
1511 __connman_nat_cleanup();
1512 __connman_firewall_cleanup();
1513 __connman_peer_service_cleanup();
1514 __connman_peer_cleanup();
1515 #if defined TIZEN_EXT_WIFI_MESH
1516 __connman_mesh_cleanup();
1517 #endif /* TIZEN_EXT_WIFI_MESH */
1518 __connman_ippool_cleanup();
1519 __connman_device_cleanup();
1520 __connman_network_cleanup();
1521 __connman_dhcp_cleanup();
1522 __connman_service_cleanup();
1523 __connman_agent_cleanup();
1524 __connman_ipconfig_cleanup();
1525 __connman_notifier_cleanup();
1526 __connman_technology_cleanup();
1527 __connman_inotify_cleanup();
1529 __connman_util_cleanup();
1530 __connman_dbus_cleanup();
1532 __connman_log_cleanup(option_backtrace);
1534 dbus_connection_unref(conn);
1536 g_main_loop_unref(main_loop);
1538 if (connman_settings.pref_timeservers)
1539 g_strfreev(connman_settings.pref_timeservers);
1541 g_free(connman_settings.auto_connect);
1542 g_free(connman_settings.favorite_techs);
1543 g_free(connman_settings.preferred_techs);
1544 g_strfreev(connman_settings.fallback_nameservers);
1545 g_strfreev(connman_settings.blacklisted_interfaces);
1546 g_strfreev(connman_settings.tethering_technologies);
1548 #if defined TIZEN_EXT
1549 g_free(connman_ins_settings.ins_preferred_freq_bssid);
1550 g_free(connman_ins_settings.ins_preferred_freq);
1551 if (connman_ins_settings.ins_security_priority)
1552 g_strfreev(connman_ins_settings.ins_security_priority);
1555 g_free(option_debug);
1556 g_free(option_wifi);