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"
53 #define MAINFILE "main.conf"
54 #define CONFIGMAINFILE CONFIGDIR "/" MAINFILE
56 static char *default_auto_connect[] = {
63 static char *default_favorite_techs[] = {
68 static char *default_blacklist[] = {
80 char **pref_timeservers;
81 unsigned int *auto_connect;
82 unsigned int *favorite_techs;
83 unsigned int *preferred_techs;
84 unsigned int *always_connected_techs;
85 char **fallback_nameservers;
86 unsigned int timeout_inputreq;
87 unsigned int timeout_browserlaunch;
88 char **blacklisted_interfaces;
89 bool allow_hostname_updates;
90 bool allow_domainname_updates;
92 char **tethering_technologies;
93 bool persistent_tethering_mode;
95 char *vendor_class_id;
96 bool enable_online_check;
97 bool auto_connect_roaming_services;
99 bool use_gateways_as_timeservers;
100 #if defined TIZEN_EXT
101 char **cellular_interfaces;
102 bool tizen_tv_extension;
104 char *global_nameserver;
105 bool supplicant_debug;
106 char *def_wifi_ifname;
111 } connman_settings = {
113 .pref_timeservers = NULL,
114 .auto_connect = NULL,
115 .favorite_techs = NULL,
116 .preferred_techs = NULL,
117 .always_connected_techs = NULL,
118 .fallback_nameservers = NULL,
119 .timeout_inputreq = DEFAULT_INPUT_REQUEST_TIMEOUT,
120 .timeout_browserlaunch = DEFAULT_BROWSER_LAUNCH_TIMEOUT,
121 .blacklisted_interfaces = NULL,
122 .allow_hostname_updates = true,
123 .allow_domainname_updates = true,
124 .single_tech = false,
125 .tethering_technologies = NULL,
126 .persistent_tethering_mode = false,
127 .enable_6to4 = false,
128 .vendor_class_id = NULL,
129 .enable_online_check = true,
130 .auto_connect_roaming_services = false,
132 .use_gateways_as_timeservers = false,
133 #if defined TIZEN_EXT
134 .cellular_interfaces = NULL,
135 .tizen_tv_extension = false,
137 .global_nameserver = NULL,
138 .supplicant_debug = false,
139 .def_wifi_ifname = DEFAULT_WIFI_INTERFACE,
146 #if defined TIZEN_EXT
149 char *ins_preferred_freq_bssid;
150 bool ins_last_connected_bssid;
151 bool ins_assoc_reject;
152 bool ins_signal_bssid;
153 unsigned int ins_preferred_freq_bssid_score;
154 unsigned int ins_last_connected_bssid_score;
155 unsigned int ins_assoc_reject_score;
157 bool ins_last_user_selection;
158 unsigned int ins_last_user_selection_time;
159 bool ins_last_connected;
160 char *ins_preferred_freq;
161 char **ins_security_priority;
162 unsigned int ins_security_priority_count;
165 unsigned int ins_last_user_selection_score;
166 unsigned int ins_last_connected_score;
167 unsigned int ins_preferred_freq_score;
168 unsigned int ins_security_priority_score;
169 unsigned int ins_internet_score;
171 int ins_signal_level3_5ghz;
172 int ins_signal_level3_24ghz;
173 } connman_ins_settings = {
175 .ins_preferred_freq_bssid = NULL,
176 .ins_last_connected_bssid = true,
177 .ins_assoc_reject = true,
178 .ins_signal_bssid = true,
179 .ins_preferred_freq_bssid_score = 20,
180 .ins_last_connected_bssid_score = 20,
181 .ins_assoc_reject_score = 10,
183 .ins_last_user_selection = true,
184 .ins_last_user_selection_time = 480,
185 .ins_last_connected = true,
186 .ins_preferred_freq = NULL,
187 .ins_security_priority = NULL,
188 .ins_security_priority_count = 0,
190 .ins_internet = true,
191 .ins_last_user_selection_score = 30,
192 .ins_last_connected_score = 30,
193 .ins_preferred_freq_score = 60,
194 .ins_security_priority_score = 5,
195 .ins_internet_score = 30,
197 .ins_signal_level3_5ghz = -76,
198 .ins_signal_level3_24ghz = -74,
202 #define CONF_BG_SCAN "BackgroundScanning"
203 #define CONF_PREF_TIMESERVERS "FallbackTimeservers"
204 #define CONF_AUTO_CONNECT_TECHS "DefaultAutoConnectTechnologies"
205 #define CONF_FAVORITE_TECHS "DefaultFavoriteTechnologies"
206 #define CONF_ALWAYS_CONNECTED_TECHS "AlwaysConnectedTechnologies"
207 #define CONF_PREFERRED_TECHS "PreferredTechnologies"
208 #define CONF_FALLBACK_NAMESERVERS "FallbackNameservers"
209 #define CONF_TIMEOUT_INPUTREQ "InputRequestTimeout"
210 #define CONF_TIMEOUT_BROWSERLAUNCH "BrowserLaunchTimeout"
211 #define CONF_BLACKLISTED_INTERFACES "NetworkInterfaceBlacklist"
212 #define CONF_ALLOW_HOSTNAME_UPDATES "AllowHostnameUpdates"
213 #define CONF_ALLOW_DOMAINNAME_UPDATES "AllowDomainnameUpdates"
214 #define CONF_SINGLE_TECH "SingleConnectedTechnology"
215 #define CONF_TETHERING_TECHNOLOGIES "TetheringTechnologies"
216 #define CONF_PERSISTENT_TETHERING_MODE "PersistentTetheringMode"
217 #define CONF_ENABLE_6TO4 "Enable6to4"
218 #define CONF_VENDOR_CLASS_ID "VendorClassID"
219 #define CONF_ENABLE_ONLINE_CHECK "EnableOnlineCheck"
220 #define CONF_AUTO_CONNECT_ROAMING_SERVICES "AutoConnectRoamingServices"
221 #define CONF_ACD "AddressConflictDetection"
222 #define CONF_USE_GATEWAYS_AS_TIMESERVERS "UseGatewaysAsTimeservers"
223 #if defined TIZEN_EXT
224 #define CONF_CELLULAR_INTERFACE "NetworkCellularInterfaceList"
225 #define CONF_TIZEN_TV_EXT "TizenTVExtension"
226 #define CONF_ENABLE_AUTO_IP "EnableAutoIp"
227 #define CONF_GLOBAL_NAMESERVER "GlobalNameserver"
228 #define CONF_CONNMAN_SUPPLICANT_DEBUG "ConnmanSupplicantDebug"
229 #define CONF_CONNMAN_WIFI_DEF_IFNAME "DefaultWifiInterface"
230 #define CONF_CONNMAN_FILE_LOG "FileLogging"
231 #define CONF_CONNMAN_DLOG_LOG "DlogLogging"
232 #define CONF_CONNMAN_SIMPLIFIED_LOG "SimplifiedLog"
235 #if defined TIZEN_EXT
237 #define CONF_INS_PREFERRED_FREQ_BSSID "INSPreferredFreqBSSID"
238 #define CONF_INS_PREFERRED_FREQ_BSSID_SCORE "INSPreferredFreqBSSIDScore"
239 #define CONF_INS_LAST_CONNECTED_BSSID "INSLastConnectedBSSID"
240 #define CONF_INS_LAST_CONNECTED_BSSID_SCORE "INSLastConnectedBSSIDScore"
241 #define CONF_INS_ASSOC_REJECT "INSAssocReject"
242 #define CONF_INS_ASSOC_REJECT_SCORE "INSAssocRejectScore"
243 #define CONF_INS_SIGNAL_BSSID "INSSignalBSSID"
245 #define CONF_INS_LAST_USER_SELECTION "INSLastUserSelection"
246 #define CONF_INS_LAST_USER_SELECTION_TIME "INSLastUserSelectionTime"
247 #define CONF_INS_LAST_USER_SELECTION_SCORE "INSLastUserSelectionScore"
248 #define CONF_INS_LAST_CONNECTED "INSLastConnected"
249 #define CONF_INS_LAST_CONNECTED_SCORE "INSLastConnectedScore"
250 #define CONF_INS_PREFERRED_FREQ "INSPreferredFreq"
251 #define CONF_INS_PREFERRED_FREQ_SCORE "INSPreferredFreqScore"
252 #define CONF_INS_SECURITY_PRIORITY "INSSecurityPriority"
253 #define CONF_INS_SECURITY_PRIORITY_COUNT "INSSecurityPriorityCount"
254 #define CONF_INS_SECURITY_PRIORITY_SCORE "INSSecurityPriorityScore"
255 #define CONF_INS_SIGNAL "INSSignal"
256 #define CONF_INS_INTERNET "INSInternet"
257 #define CONF_INS_INTERNET_SCORE "INSInternetScore"
259 #define CONF_INS_SIGNAL_LEVEL3_5GHZ "INSSignalLevel3_5GHz"
260 #define CONF_INS_SIGNAL_LEVEL3_24GHZ "INSSignalLevel3_24GHz"
263 static const char *supported_options[] = {
265 CONF_PREF_TIMESERVERS,
266 CONF_AUTO_CONNECT_TECHS,
267 CONF_ALWAYS_CONNECTED_TECHS,
268 CONF_PREFERRED_TECHS,
269 CONF_FALLBACK_NAMESERVERS,
270 CONF_TIMEOUT_INPUTREQ,
271 CONF_TIMEOUT_BROWSERLAUNCH,
272 CONF_BLACKLISTED_INTERFACES,
273 CONF_ALLOW_HOSTNAME_UPDATES,
274 CONF_ALLOW_DOMAINNAME_UPDATES,
276 CONF_TETHERING_TECHNOLOGIES,
277 CONF_PERSISTENT_TETHERING_MODE,
279 CONF_VENDOR_CLASS_ID,
280 CONF_ENABLE_ONLINE_CHECK,
281 CONF_AUTO_CONNECT_ROAMING_SERVICES,
283 CONF_USE_GATEWAYS_AS_TIMESERVERS,
284 #if defined TIZEN_EXT
285 CONF_CELLULAR_INTERFACE,
288 CONF_GLOBAL_NAMESERVER,
289 CONF_CONNMAN_SUPPLICANT_DEBUG,
290 CONF_CONNMAN_WIFI_DEF_IFNAME,
291 CONF_CONNMAN_FILE_LOG,
292 CONF_CONNMAN_DLOG_LOG,
293 CONF_CONNMAN_SIMPLIFIED_LOG,
298 #if defined TIZEN_EXT
299 static const char *supported_ins_options[] = {
301 CONF_INS_PREFERRED_FREQ_BSSID,
302 CONF_INS_PREFERRED_FREQ_BSSID_SCORE,
303 CONF_INS_LAST_CONNECTED_BSSID,
304 CONF_INS_LAST_CONNECTED_BSSID_SCORE,
305 CONF_INS_ASSOC_REJECT,
306 CONF_INS_ASSOC_REJECT_SCORE,
307 CONF_INS_SIGNAL_BSSID,
309 CONF_INS_LAST_USER_SELECTION,
310 CONF_INS_LAST_USER_SELECTION_TIME,
311 CONF_INS_LAST_USER_SELECTION_SCORE,
312 CONF_INS_LAST_CONNECTED,
313 CONF_INS_LAST_CONNECTED_SCORE,
314 CONF_INS_PREFERRED_FREQ,
315 CONF_INS_PREFERRED_FREQ_SCORE,
316 CONF_INS_SECURITY_PRIORITY,
317 CONF_INS_SECURITY_PRIORITY_COUNT,
318 CONF_INS_SECURITY_PRIORITY_SCORE,
321 CONF_INS_INTERNET_SCORE,
323 CONF_INS_SIGNAL_LEVEL3_5GHZ,
324 CONF_INS_SIGNAL_LEVEL3_24GHZ,
329 static GKeyFile *load_config(const char *file)
334 keyfile = g_key_file_new();
336 g_key_file_set_list_separator(keyfile, ',');
338 if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
339 if (err->code != G_FILE_ERROR_NOENT) {
340 connman_error("Parsing %s failed: %s", file,
345 g_key_file_free(keyfile);
352 static uint *parse_service_types(char **str_list, gsize len)
354 unsigned int *type_list;
356 enum connman_service_type type;
358 type_list = g_try_new0(unsigned int, len + 1);
364 while (str_list[i]) {
365 type = __connman_service_string2type(str_list[i]);
367 if (type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
374 type_list[j] = CONNMAN_SERVICE_TYPE_UNKNOWN;
379 static char **parse_fallback_nameservers(char **nameservers, gsize len)
384 servers = g_try_new0(char *, len + 1);
390 while (nameservers[i]) {
391 if (connman_inet_check_ipaddress(nameservers[i]) > 0) {
392 servers[j] = g_strdup(nameservers[i]);
401 static void check_config(GKeyFile *config)
409 keys = g_key_file_get_groups(config, NULL);
411 for (j = 0; keys && keys[j]; j++) {
412 #if defined TIZEN_EXT
413 if (g_strcmp0(keys[j], "General") != 0 &&
414 g_strcmp0(keys[j], "INS") != 0)
416 if (g_strcmp0(keys[j], "General") != 0)
418 connman_warn("Unknown group %s in %s",
424 keys = g_key_file_get_keys(config, "General", NULL, NULL);
426 for (j = 0; keys && keys[j]; j++) {
431 for (i = 0; supported_options[i]; i++) {
432 if (g_strcmp0(keys[j], supported_options[i]) == 0) {
437 if (!found && !supported_options[i])
438 connman_warn("Unknown option %s in %s",
444 #if defined TIZEN_EXT
445 keys = g_key_file_get_keys(config, "INS", NULL, NULL);
447 for (j = 0; keys && keys[j]; j++) {
452 for (i = 0; supported_ins_options[i]; i++) {
453 if (g_strcmp0(keys[j], supported_ins_options[i]) == 0) {
458 if (!found && !supported_ins_options[i])
459 connman_warn("Unknown option %s in %s",
467 #if defined TIZEN_EXT
468 static void check_Tizen_INS_configuration(GKeyFile *config)
470 GError *error = NULL;
471 char *ins_preferred_freq_bssid;
472 char *ins_preferred_freq;
473 char **ins_security_priority;
478 ins_preferred_freq_bssid = __connman_config_get_string(config, "INS",
479 CONF_INS_PREFERRED_FREQ_BSSID, &error);
481 connman_ins_settings.ins_preferred_freq_bssid = ins_preferred_freq_bssid;
483 g_clear_error(&error);
485 integer = g_key_file_get_integer(config, "INS",
486 CONF_INS_PREFERRED_FREQ_BSSID_SCORE, &error);
487 if (!error && integer >= 0)
488 connman_ins_settings.ins_preferred_freq_bssid_score = integer;
490 g_clear_error(&error);
492 boolean = __connman_config_get_bool(config, "INS",
493 CONF_INS_LAST_CONNECTED_BSSID, &error);
495 connman_ins_settings.ins_last_connected_bssid = boolean;
497 g_clear_error(&error);
499 integer = g_key_file_get_integer(config, "INS",
500 CONF_INS_LAST_CONNECTED_BSSID_SCORE, &error);
501 if (!error && integer >= 0)
502 connman_ins_settings.ins_last_connected_bssid_score = integer;
504 g_clear_error(&error);
506 boolean = __connman_config_get_bool(config, "INS",
507 CONF_INS_ASSOC_REJECT, &error);
509 connman_ins_settings.ins_assoc_reject = boolean;
511 g_clear_error(&error);
513 integer = g_key_file_get_integer(config, "INS",
514 CONF_INS_ASSOC_REJECT_SCORE, &error);
515 if (!error && integer >= 0)
516 connman_ins_settings.ins_assoc_reject_score = integer;
518 g_clear_error(&error);
520 boolean = __connman_config_get_bool(config, "INS",
521 CONF_INS_SIGNAL_BSSID, &error);
523 connman_ins_settings.ins_signal_bssid = boolean;
525 g_clear_error(&error);
527 boolean = __connman_config_get_bool(config, "INS",
528 CONF_INS_LAST_USER_SELECTION, &error);
530 connman_ins_settings.ins_last_user_selection = boolean;
532 g_clear_error(&error);
534 integer = g_key_file_get_integer(config, "INS",
535 CONF_INS_LAST_USER_SELECTION_TIME, &error);
536 if (!error && integer >= 0)
537 connman_ins_settings.ins_last_user_selection_time = integer;
539 g_clear_error(&error);
541 integer = g_key_file_get_integer(config, "INS",
542 CONF_INS_LAST_USER_SELECTION_SCORE, &error);
543 if (!error && integer >= 0)
544 connman_ins_settings.ins_last_user_selection_score = integer;
546 g_clear_error(&error);
548 boolean = __connman_config_get_bool(config, "INS",
549 CONF_INS_LAST_CONNECTED, &error);
551 connman_ins_settings.ins_last_connected = boolean;
553 g_clear_error(&error);
555 integer = g_key_file_get_integer(config, "INS",
556 CONF_INS_LAST_CONNECTED_SCORE, &error);
557 if (!error && integer >= 0)
558 connman_ins_settings.ins_last_connected_score = integer;
560 g_clear_error(&error);
562 ins_preferred_freq = __connman_config_get_string(config, "INS",
563 CONF_INS_PREFERRED_FREQ, &error);
565 connman_ins_settings.ins_preferred_freq = ins_preferred_freq;
567 g_clear_error(&error);
569 integer = g_key_file_get_integer(config, "INS",
570 CONF_INS_PREFERRED_FREQ_SCORE, &error);
571 if (!error && integer >= 0)
572 connman_ins_settings.ins_preferred_freq_score = integer;
574 g_clear_error(&error);
576 ins_security_priority = g_key_file_get_string_list(config, "INS",
577 CONF_INS_SECURITY_PRIORITY, &len, &error);
580 connman_ins_settings.ins_security_priority = ins_security_priority;
581 connman_ins_settings.ins_security_priority_count = len;
584 g_clear_error(&error);
586 integer = g_key_file_get_integer(config, "INS",
587 CONF_INS_SECURITY_PRIORITY_SCORE, &error);
588 if (!error && integer >= 0)
589 connman_ins_settings.ins_security_priority_score = integer;
591 g_clear_error(&error);
593 boolean = __connman_config_get_bool(config, "INS",
594 CONF_INS_SIGNAL, &error);
596 connman_ins_settings.ins_signal = boolean;
598 g_clear_error(&error);
600 boolean = __connman_config_get_bool(config, "INS",
601 CONF_INS_INTERNET, &error);
603 connman_ins_settings.ins_internet = boolean;
605 g_clear_error(&error);
607 integer = g_key_file_get_integer(config, "INS",
608 CONF_INS_INTERNET_SCORE, &error);
609 if (!error && integer >= 0)
610 connman_ins_settings.ins_internet_score = integer;
612 g_clear_error(&error);
614 integer = g_key_file_get_integer(config, "INS",
615 CONF_INS_SIGNAL_LEVEL3_5GHZ, &error);
617 connman_ins_settings.ins_signal_level3_5ghz = integer;
619 g_clear_error(&error);
621 integer = g_key_file_get_integer(config, "INS",
622 CONF_INS_SIGNAL_LEVEL3_24GHZ, &error);
624 connman_ins_settings.ins_signal_level3_24ghz = integer;
626 g_clear_error(&error);
629 static void check_Tizen_configuration(GKeyFile *config)
631 GError *error = NULL;
632 char **cellular_interfaces;
633 char *global_nameserver;
634 char *default_wifi_ifname;
638 cellular_interfaces = g_key_file_get_string_list(config, "General",
639 CONF_CELLULAR_INTERFACE, &len, &error);
642 connman_settings.cellular_interfaces = cellular_interfaces;
644 g_clear_error(&error);
646 boolean = __connman_config_get_bool(config, "General",
647 CONF_TIZEN_TV_EXT, &error);
649 connman_settings.tizen_tv_extension = boolean;
651 g_clear_error(&error);
653 boolean = __connman_config_get_bool(config, "General",
654 CONF_ENABLE_AUTO_IP, &error);
656 connman_settings.auto_ip = boolean;
658 g_clear_error(&error);
660 global_nameserver = __connman_config_get_string(config, "General",
661 CONF_GLOBAL_NAMESERVER, &error);
663 connman_settings.global_nameserver = global_nameserver;
665 g_clear_error(&error);
667 boolean = __connman_config_get_bool(config, "General",
668 CONF_CONNMAN_SUPPLICANT_DEBUG, &error);
670 connman_settings.supplicant_debug = boolean;
672 g_clear_error(&error);
674 default_wifi_ifname = __connman_config_get_string(config, "General",
675 CONF_CONNMAN_WIFI_DEF_IFNAME, &error);
677 connman_settings.def_wifi_ifname = default_wifi_ifname;
679 g_clear_error(&error);
681 boolean = __connman_config_get_bool(config, "General",
682 CONF_CONNMAN_FILE_LOG, &error);
684 connman_settings.file_log = boolean;
686 g_clear_error(&error);
688 boolean = __connman_config_get_bool(config, "General",
689 CONF_CONNMAN_DLOG_LOG, &error);
691 connman_settings.dlog_log = boolean;
693 g_clear_error(&error);
695 boolean = __connman_config_get_bool(config, "General",
696 CONF_CONNMAN_SIMPLIFIED_LOG, &error);
698 connman_settings.simple_log = boolean;
700 g_clear_error(&error);
702 check_Tizen_INS_configuration(config);
705 static void set_nofile_inc(void)
710 rlim.rlim_cur = 8192;
711 rlim.rlim_max = 8192;
713 err = setrlimit(RLIMIT_NOFILE, &rlim);
715 DBG("fail to increase FILENO err(%d)", err);
721 static void parse_config(GKeyFile *config)
723 GError *error = NULL;
729 char *vendor_class_id;
734 connman_settings.auto_connect =
735 parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
736 connman_settings.favorite_techs =
737 parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
738 connman_settings.blacklisted_interfaces =
739 g_strdupv(default_blacklist);
743 DBG("parsing %s", MAINFILE);
745 boolean = g_key_file_get_boolean(config, "General",
746 CONF_BG_SCAN, &error);
748 connman_settings.bg_scan = boolean;
750 g_clear_error(&error);
752 timeservers = __connman_config_get_string_list(config, "General",
753 CONF_PREF_TIMESERVERS, NULL, &error);
755 connman_settings.pref_timeservers = timeservers;
757 g_clear_error(&error);
759 str_list = __connman_config_get_string_list(config, "General",
760 CONF_AUTO_CONNECT_TECHS, &len, &error);
763 connman_settings.auto_connect =
764 parse_service_types(str_list, len);
766 connman_settings.auto_connect =
767 parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
769 g_strfreev(str_list);
771 g_clear_error(&error);
773 str_list = __connman_config_get_string_list(config, "General",
774 CONF_FAVORITE_TECHS, &len, &error);
777 connman_settings.favorite_techs =
778 parse_service_types(str_list, len);
780 connman_settings.favorite_techs =
781 parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
783 g_strfreev(str_list);
785 g_clear_error(&error);
787 str_list = __connman_config_get_string_list(config, "General",
788 CONF_PREFERRED_TECHS, &len, &error);
791 connman_settings.preferred_techs =
792 parse_service_types(str_list, len);
794 g_strfreev(str_list);
796 g_clear_error(&error);
798 str_list = __connman_config_get_string_list(config, "General",
799 CONF_ALWAYS_CONNECTED_TECHS, &len, &error);
802 connman_settings.always_connected_techs =
803 parse_service_types(str_list, len);
805 g_strfreev(str_list);
807 g_clear_error(&error);
809 str_list = __connman_config_get_string_list(config, "General",
810 CONF_FALLBACK_NAMESERVERS, &len, &error);
813 connman_settings.fallback_nameservers =
814 parse_fallback_nameservers(str_list, len);
816 g_strfreev(str_list);
818 g_clear_error(&error);
820 timeout = g_key_file_get_integer(config, "General",
821 CONF_TIMEOUT_INPUTREQ, &error);
822 if (!error && timeout >= 0)
823 connman_settings.timeout_inputreq = timeout * 1000;
825 g_clear_error(&error);
827 timeout = g_key_file_get_integer(config, "General",
828 CONF_TIMEOUT_BROWSERLAUNCH, &error);
829 if (!error && timeout >= 0)
830 connman_settings.timeout_browserlaunch = timeout * 1000;
832 g_clear_error(&error);
834 interfaces = __connman_config_get_string_list(config, "General",
835 CONF_BLACKLISTED_INTERFACES, &len, &error);
838 connman_settings.blacklisted_interfaces = interfaces;
840 connman_settings.blacklisted_interfaces =
841 g_strdupv(default_blacklist);
843 g_clear_error(&error);
845 boolean = __connman_config_get_bool(config, "General",
846 CONF_ALLOW_HOSTNAME_UPDATES,
849 connman_settings.allow_hostname_updates = boolean;
851 g_clear_error(&error);
853 boolean = __connman_config_get_bool(config, "General",
854 CONF_ALLOW_DOMAINNAME_UPDATES,
857 connman_settings.allow_domainname_updates = boolean;
859 g_clear_error(&error);
861 boolean = __connman_config_get_bool(config, "General",
862 CONF_SINGLE_TECH, &error);
864 connman_settings.single_tech = boolean;
866 g_clear_error(&error);
868 tethering = __connman_config_get_string_list(config, "General",
869 CONF_TETHERING_TECHNOLOGIES, &len, &error);
872 connman_settings.tethering_technologies = tethering;
874 g_clear_error(&error);
876 boolean = __connman_config_get_bool(config, "General",
877 CONF_PERSISTENT_TETHERING_MODE,
880 connman_settings.persistent_tethering_mode = boolean;
882 g_clear_error(&error);
884 boolean = __connman_config_get_bool(config, "General",
885 CONF_ENABLE_6TO4, &error);
887 connman_settings.enable_6to4 = boolean;
889 g_clear_error(&error);
891 vendor_class_id = __connman_config_get_string(config, "General",
892 CONF_VENDOR_CLASS_ID, &error);
894 connman_settings.vendor_class_id = vendor_class_id;
896 g_clear_error(&error);
898 boolean = __connman_config_get_bool(config, "General",
899 CONF_ENABLE_ONLINE_CHECK, &error);
901 connman_settings.enable_online_check = boolean;
903 connman_info("Online check disabled by main config.");
906 g_clear_error(&error);
908 boolean = __connman_config_get_bool(config, "General",
909 CONF_AUTO_CONNECT_ROAMING_SERVICES, &error);
911 connman_settings.auto_connect_roaming_services = boolean;
913 g_clear_error(&error);
915 boolean = __connman_config_get_bool(config, "General", CONF_ACD, &error);
917 connman_settings.acd = boolean;
919 g_clear_error(&error);
921 boolean = __connman_config_get_bool(config, "General",
922 CONF_USE_GATEWAYS_AS_TIMESERVERS, &error);
924 connman_settings.use_gateways_as_timeservers = boolean;
926 g_clear_error(&error);
928 #if defined TIZEN_EXT
929 check_Tizen_configuration(config);
933 static int config_init(const char *file)
937 #if defined TIZEN_EXT
940 config = load_config(file);
941 check_config(config);
942 parse_config(config);
944 g_key_file_free(config);
946 #if defined TIZEN_EXT
947 set_simple_log_option(connman_settings.simple_log);
948 set_dlog_logging_option(connman_settings.dlog_log);
949 set_file_logging_option(connman_settings.file_log);
954 static GMainLoop *main_loop = NULL;
956 static unsigned int __terminated = 0;
958 static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
961 struct signalfd_siginfo si;
965 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
968 fd = g_io_channel_unix_get_fd(channel);
970 result = read(fd, &si, sizeof(si));
971 if (result != sizeof(si))
974 switch (si.ssi_signo) {
977 if (__terminated == 0) {
978 connman_info("Terminating");
979 g_main_loop_quit(main_loop);
989 static guint setup_signalfd(void)
997 sigaddset(&mask, SIGINT);
998 sigaddset(&mask, SIGTERM);
1000 if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
1001 perror("Failed to set signal mask");
1005 fd = signalfd(-1, &mask, 0);
1007 perror("Failed to create signal descriptor");
1011 channel = g_io_channel_unix_new(fd);
1013 g_io_channel_set_close_on_unref(channel, TRUE);
1014 g_io_channel_set_encoding(channel, NULL, NULL);
1015 g_io_channel_set_buffered(channel, FALSE);
1017 source = g_io_add_watch(channel,
1018 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1019 signal_handler, NULL);
1021 g_io_channel_unref(channel);
1026 static void disconnect_callback(DBusConnection *conn, void *user_data)
1028 connman_error("D-Bus disconnect");
1030 g_main_loop_quit(main_loop);
1033 static gchar *option_config = NULL;
1034 static gchar *option_debug = NULL;
1035 static gchar *option_device = NULL;
1036 static gchar *option_plugin = NULL;
1037 static gchar *option_nodevice = NULL;
1038 static gchar *option_noplugin = NULL;
1039 static gchar *option_wifi = NULL;
1040 static gboolean option_detach = TRUE;
1041 static gboolean option_dnsproxy = TRUE;
1042 static gboolean option_backtrace = TRUE;
1043 static gboolean option_version = FALSE;
1045 static bool parse_debug(const char *key, const char *value,
1046 gpointer user_data, GError **error)
1050 char *prev = option_debug;
1052 option_debug = g_strconcat(prev, ",", value, NULL);
1055 option_debug = g_strdup(value);
1058 g_free(option_debug);
1059 option_debug = g_strdup("*");
1065 static bool parse_noplugin(const char *key, const char *value,
1066 gpointer user_data, GError **error)
1068 if (option_noplugin) {
1069 char *prev = option_noplugin;
1071 option_noplugin = g_strconcat(prev, ",", value, NULL);
1074 option_noplugin = g_strdup(value);
1080 static GOptionEntry options[] = {
1081 { "config", 'c', 0, G_OPTION_ARG_STRING, &option_config,
1082 "Load the specified configuration file "
1083 "instead of " CONFIGMAINFILE, "FILE" },
1084 { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
1085 G_OPTION_ARG_CALLBACK, parse_debug,
1086 "Specify debug options to enable", "DEBUG" },
1087 { "device", 'i', 0, G_OPTION_ARG_STRING, &option_device,
1088 "Specify networking devices or interfaces", "DEV,..." },
1089 { "nodevice", 'I', 0, G_OPTION_ARG_STRING, &option_nodevice,
1090 "Specify networking interfaces to ignore", "DEV,..." },
1091 { "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin,
1092 "Specify plugins to load", "NAME,..." },
1093 { "noplugin", 'P', 0, G_OPTION_ARG_CALLBACK, &parse_noplugin,
1094 "Specify plugins not to load", "NAME,..." },
1095 { "wifi", 'W', 0, G_OPTION_ARG_STRING, &option_wifi,
1096 "Specify driver for WiFi/Supplicant", "NAME" },
1097 { "nodaemon", 'n', G_OPTION_FLAG_REVERSE,
1098 G_OPTION_ARG_NONE, &option_detach,
1099 "Don't fork daemon to background" },
1100 { "nodnsproxy", 'r', G_OPTION_FLAG_REVERSE,
1101 G_OPTION_ARG_NONE, &option_dnsproxy,
1102 "Don't support DNS resolving" },
1103 { "nobacktrace", 0, G_OPTION_FLAG_REVERSE,
1104 G_OPTION_ARG_NONE, &option_backtrace,
1105 "Don't print out backtrace information" },
1106 { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
1107 "Show version information and exit" },
1111 const char *connman_option_get_string(const char *key)
1113 if (g_str_equal(key, CONF_VENDOR_CLASS_ID))
1114 return connman_settings.vendor_class_id;
1116 if (g_strcmp0(key, "wifi") == 0) {
1118 return "nl80211,wext";
1123 #if defined TIZEN_EXT
1124 if (g_str_equal(key, CONF_GLOBAL_NAMESERVER))
1125 return connman_settings.global_nameserver;
1127 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID))
1128 return connman_ins_settings.ins_preferred_freq_bssid;
1130 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ))
1131 return connman_ins_settings.ins_preferred_freq;
1133 if (g_str_equal(key, CONF_CONNMAN_WIFI_DEF_IFNAME))
1134 return connman_settings.def_wifi_ifname;
1139 bool connman_setting_get_bool(const char *key)
1141 if (g_str_equal(key, CONF_BG_SCAN))
1142 return connman_settings.bg_scan;
1144 if (g_str_equal(key, CONF_ALLOW_HOSTNAME_UPDATES))
1145 return connman_settings.allow_hostname_updates;
1147 if (g_str_equal(key, CONF_ALLOW_DOMAINNAME_UPDATES))
1148 return connman_settings.allow_domainname_updates;
1150 if (g_str_equal(key, CONF_SINGLE_TECH))
1151 return connman_settings.single_tech;
1153 if (g_str_equal(key, CONF_PERSISTENT_TETHERING_MODE))
1154 return connman_settings.persistent_tethering_mode;
1156 if (g_str_equal(key, CONF_ENABLE_6TO4))
1157 return connman_settings.enable_6to4;
1159 if (g_str_equal(key, CONF_ENABLE_ONLINE_CHECK))
1160 return connman_settings.enable_online_check;
1162 if (g_str_equal(key, CONF_AUTO_CONNECT_ROAMING_SERVICES))
1163 return connman_settings.auto_connect_roaming_services;
1165 if (g_str_equal(key, CONF_ACD))
1166 return connman_settings.acd;
1168 if (g_str_equal(key, CONF_USE_GATEWAYS_AS_TIMESERVERS))
1169 return connman_settings.use_gateways_as_timeservers;
1171 #if defined TIZEN_EXT
1172 if (g_str_equal(key, CONF_ENABLE_AUTO_IP))
1173 return connman_settings.auto_ip;
1175 if (g_str_equal(key, CONF_CONNMAN_SUPPLICANT_DEBUG))
1176 return connman_settings.supplicant_debug;
1178 if (g_str_equal(key, CONF_CONNMAN_FILE_LOG))
1179 return connman_settings.file_log;
1181 if (g_str_equal(key, CONF_CONNMAN_DLOG_LOG))
1182 return connman_settings.dlog_log;
1184 if (g_str_equal(key, CONF_CONNMAN_SIMPLIFIED_LOG))
1185 return connman_settings.simple_log;
1188 #if defined TIZEN_EXT
1189 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID))
1190 return connman_ins_settings.ins_last_connected_bssid;
1192 if (g_str_equal(key, CONF_INS_ASSOC_REJECT))
1193 return connman_ins_settings.ins_assoc_reject;
1195 if (g_str_equal(key, CONF_INS_SIGNAL_BSSID))
1196 return connman_ins_settings.ins_signal_bssid;
1198 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION))
1199 return connman_ins_settings.ins_last_user_selection;
1201 if (g_str_equal(key, CONF_INS_LAST_CONNECTED))
1202 return connman_ins_settings.ins_last_connected;
1204 if (g_str_equal(key, CONF_INS_SIGNAL))
1205 return connman_ins_settings.ins_signal;
1207 if (g_str_equal(key, CONF_INS_INTERNET))
1208 return connman_ins_settings.ins_internet;
1214 #if defined TIZEN_EXT
1215 unsigned int connman_setting_get_uint(const char *key)
1217 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID_SCORE))
1218 return connman_ins_settings.ins_preferred_freq_bssid_score;
1220 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID_SCORE))
1221 return connman_ins_settings.ins_last_connected_bssid_score;
1223 if (g_str_equal(key, CONF_INS_ASSOC_REJECT_SCORE))
1224 return connman_ins_settings.ins_assoc_reject_score;
1226 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_TIME))
1227 return connman_ins_settings.ins_last_user_selection_time;
1229 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_COUNT))
1230 return connman_ins_settings.ins_security_priority_count;
1232 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_SCORE))
1233 return connman_ins_settings.ins_last_user_selection_score;
1235 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_SCORE))
1236 return connman_ins_settings.ins_last_connected_score;
1238 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_SCORE))
1239 return connman_ins_settings.ins_preferred_freq_score;
1241 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_SCORE))
1242 return connman_ins_settings.ins_security_priority_score;
1244 if (g_str_equal(key, CONF_INS_INTERNET_SCORE))
1245 return connman_ins_settings.ins_internet_score;
1250 int connman_setting_get_int(const char *key)
1252 if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_5GHZ))
1253 return connman_ins_settings.ins_signal_level3_5ghz;
1255 if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_24GHZ))
1256 return connman_ins_settings.ins_signal_level3_24ghz;
1262 char **connman_setting_get_string_list(const char *key)
1264 if (g_str_equal(key, CONF_PREF_TIMESERVERS))
1265 return connman_settings.pref_timeservers;
1267 if (g_str_equal(key, CONF_FALLBACK_NAMESERVERS))
1268 return connman_settings.fallback_nameservers;
1270 if (g_str_equal(key, CONF_BLACKLISTED_INTERFACES))
1271 return connman_settings.blacklisted_interfaces;
1273 if (g_str_equal(key, CONF_TETHERING_TECHNOLOGIES))
1274 return connman_settings.tethering_technologies;
1276 #if defined TIZEN_EXT
1277 if (g_str_equal(key, CONF_CELLULAR_INTERFACE))
1278 return connman_settings.cellular_interfaces;
1281 #if defined TIZEN_EXT
1282 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY))
1283 return connman_ins_settings.ins_security_priority;
1289 unsigned int *connman_setting_get_uint_list(const char *key)
1291 if (g_str_equal(key, CONF_AUTO_CONNECT_TECHS))
1292 return connman_settings.auto_connect;
1294 if (g_str_equal(key, CONF_FAVORITE_TECHS))
1295 return connman_settings.favorite_techs;
1297 if (g_str_equal(key, CONF_PREFERRED_TECHS))
1298 return connman_settings.preferred_techs;
1300 if (g_str_equal(key, CONF_ALWAYS_CONNECTED_TECHS))
1301 return connman_settings.always_connected_techs;
1306 unsigned int connman_timeout_input_request(void)
1308 return connman_settings.timeout_inputreq;
1311 unsigned int connman_timeout_browser_launch(void)
1313 return connman_settings.timeout_browserlaunch;
1316 int main(int argc, char *argv[])
1318 GOptionContext *context;
1319 GError *error = NULL;
1320 DBusConnection *conn;
1324 context = g_option_context_new(NULL);
1325 g_option_context_add_main_entries(context, options, NULL);
1327 if (!g_option_context_parse(context, &argc, &argv, &error)) {
1329 g_printerr("%s\n", error->message);
1330 g_error_free(error);
1332 g_printerr("An unknown error occurred\n");
1336 g_option_context_free(context);
1338 if (option_version) {
1339 printf("%s\n", VERSION);
1343 if (option_detach) {
1345 perror("Can't start daemon");
1350 if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
1351 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
1352 if (errno != EEXIST)
1353 perror("Failed to create storage directory");
1358 main_loop = g_main_loop_new(NULL, FALSE);
1360 signal = setup_signalfd();
1362 dbus_error_init(&err);
1364 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
1366 if (dbus_error_is_set(&err)) {
1367 fprintf(stderr, "%s\n", err.message);
1368 dbus_error_free(&err);
1370 fprintf(stderr, "Can't register with system bus\n");
1374 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
1376 __connman_log_init(argv[0], option_debug, option_detach,
1377 option_backtrace, "Connection Manager", VERSION);
1379 __connman_dbus_init(conn);
1382 config_init(CONFIGMAINFILE);
1384 config_init(option_config);
1386 __connman_util_init();
1387 __connman_inotify_init();
1388 __connman_technology_init();
1389 __connman_notifier_init();
1390 __connman_agent_init();
1391 __connman_service_init();
1392 __connman_peer_service_init();
1393 __connman_peer_init();
1394 #if defined TIZEN_EXT_WIFI_MESH
1395 __connman_mesh_init();
1396 #endif /* TIZEN_EXT_WIFI_MESH */
1397 __connman_provider_init();
1398 __connman_network_init();
1399 __connman_config_init();
1400 __connman_device_init(option_device, option_nodevice);
1402 __connman_ippool_init();
1403 __connman_firewall_init();
1404 __connman_nat_init();
1405 __connman_tethering_init();
1406 __connman_counter_init();
1407 __connman_manager_init();
1408 __connman_stats_init();
1409 __connman_clock_init();
1411 __connman_ipconfig_init();
1412 #if defined TIZEN_EXT
1413 __connman_rtnl_init(GIO_SOCKET_RETRY_COUNT);
1414 #else /* TIZEN_EXT */
1415 __connman_rtnl_init();
1416 #endif /* TIZEN_EXT */
1417 __connman_task_init();
1418 __connman_proxy_init();
1419 __connman_detect_init();
1420 __connman_session_init();
1421 __connman_timeserver_init();
1422 __connman_connection_init();
1424 __connman_plugin_init(option_plugin, option_noplugin);
1426 __connman_resolver_init(option_dnsproxy);
1427 __connman_rtnl_start();
1428 __connman_dhcp_init();
1429 __connman_dhcpv6_init();
1430 __connman_wpad_init();
1431 __connman_wispr_init();
1432 #if !defined TIZEN_EXT
1433 __connman_rfkill_init();
1434 __connman_machine_init();
1437 g_free(option_config);
1438 g_free(option_device);
1439 g_free(option_plugin);
1440 g_free(option_nodevice);
1441 g_free(option_noplugin);
1443 g_main_loop_run(main_loop);
1445 g_source_remove(signal);
1447 #if !defined TIZEN_EXT
1448 __connman_machine_cleanup();
1449 __connman_rfkill_cleanup();
1451 __connman_wispr_cleanup();
1452 __connman_wpad_cleanup();
1453 __connman_dhcpv6_cleanup();
1454 __connman_session_cleanup();
1455 __connman_plugin_cleanup();
1456 __connman_provider_cleanup();
1457 __connman_connection_cleanup();
1458 __connman_timeserver_cleanup();
1459 __connman_detect_cleanup();
1460 __connman_proxy_cleanup();
1461 __connman_task_cleanup();
1462 __connman_rtnl_cleanup();
1463 __connman_resolver_cleanup();
1465 __connman_clock_cleanup();
1466 __connman_stats_cleanup();
1467 __connman_config_cleanup();
1468 __connman_manager_cleanup();
1469 __connman_counter_cleanup();
1470 __connman_tethering_cleanup();
1471 __connman_nat_cleanup();
1472 __connman_firewall_cleanup();
1473 __connman_peer_service_cleanup();
1474 __connman_peer_cleanup();
1475 #if defined TIZEN_EXT_WIFI_MESH
1476 __connman_mesh_cleanup();
1477 #endif /* TIZEN_EXT_WIFI_MESH */
1478 __connman_ippool_cleanup();
1479 __connman_device_cleanup();
1480 __connman_network_cleanup();
1481 __connman_dhcp_cleanup();
1482 __connman_service_cleanup();
1483 __connman_agent_cleanup();
1484 __connman_ipconfig_cleanup();
1485 __connman_notifier_cleanup();
1486 __connman_technology_cleanup();
1487 __connman_inotify_cleanup();
1489 __connman_util_cleanup();
1490 __connman_dbus_cleanup();
1492 __connman_log_cleanup(option_backtrace);
1494 dbus_connection_unref(conn);
1496 g_main_loop_unref(main_loop);
1498 if (connman_settings.pref_timeservers)
1499 g_strfreev(connman_settings.pref_timeservers);
1501 g_free(connman_settings.auto_connect);
1502 g_free(connman_settings.favorite_techs);
1503 g_free(connman_settings.preferred_techs);
1504 g_strfreev(connman_settings.fallback_nameservers);
1505 g_strfreev(connman_settings.blacklisted_interfaces);
1506 g_strfreev(connman_settings.tethering_technologies);
1508 #if defined TIZEN_EXT
1509 g_free(connman_ins_settings.ins_preferred_freq_bssid);
1510 g_free(connman_ins_settings.ins_preferred_freq);
1511 if (connman_ins_settings.ins_security_priority)
1512 g_strfreev(connman_ins_settings.ins_security_priority);
1515 g_free(option_debug);
1516 g_free(option_wifi);