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)
49 #define MAINFILE "main.conf"
50 #define CONFIGMAINFILE CONFIGDIR "/" MAINFILE
52 static char *default_auto_connect[] = {
59 static char *default_favorite_techs[] = {
64 static char *default_blacklist[] = {
76 char **pref_timeservers;
77 unsigned int *auto_connect;
78 unsigned int *favorite_techs;
79 unsigned int *preferred_techs;
80 unsigned int *always_connected_techs;
81 char **fallback_nameservers;
82 unsigned int timeout_inputreq;
83 unsigned int timeout_browserlaunch;
84 char **blacklisted_interfaces;
85 bool allow_hostname_updates;
86 bool allow_domainname_updates;
88 char **tethering_technologies;
89 bool persistent_tethering_mode;
91 char *vendor_class_id;
92 bool enable_online_check;
93 bool auto_connect_roaming_services;
95 bool use_gateways_as_timeservers;
97 char **cellular_interfaces;
98 bool tizen_tv_extension;
100 char *global_nameserver;
101 bool supplicant_debug;
103 } connman_settings = {
105 .pref_timeservers = NULL,
106 .auto_connect = NULL,
107 .favorite_techs = NULL,
108 .preferred_techs = NULL,
109 .always_connected_techs = NULL,
110 .fallback_nameservers = NULL,
111 .timeout_inputreq = DEFAULT_INPUT_REQUEST_TIMEOUT,
112 .timeout_browserlaunch = DEFAULT_BROWSER_LAUNCH_TIMEOUT,
113 .blacklisted_interfaces = NULL,
114 .allow_hostname_updates = true,
115 .allow_domainname_updates = true,
116 .single_tech = false,
117 .tethering_technologies = NULL,
118 .persistent_tethering_mode = false,
119 .enable_6to4 = false,
120 .vendor_class_id = NULL,
121 .enable_online_check = true,
122 .auto_connect_roaming_services = false,
124 .use_gateways_as_timeservers = false,
125 #if defined TIZEN_EXT
126 .cellular_interfaces = NULL,
127 .tizen_tv_extension = false,
129 .global_nameserver = NULL,
130 .supplicant_debug = false,
134 #if defined TIZEN_EXT
137 char *ins_preferred_freq_bssid;
138 bool ins_last_connected_bssid;
139 bool ins_assoc_reject;
140 bool ins_signal_bssid;
141 unsigned int ins_preferred_freq_bssid_score;
142 unsigned int ins_last_connected_bssid_score;
143 unsigned int ins_assoc_reject_score;
145 bool ins_last_user_selection;
146 unsigned int ins_last_user_selection_time;
147 bool ins_last_connected;
148 char *ins_preferred_freq;
149 char **ins_security_priority;
150 unsigned int ins_security_priority_count;
153 unsigned int ins_last_user_selection_score;
154 unsigned int ins_last_connected_score;
155 unsigned int ins_preferred_freq_score;
156 unsigned int ins_security_priority_score;
157 unsigned int ins_internet_score;
159 int ins_signal_level3_5ghz;
160 int ins_signal_level3_24ghz;
161 } connman_ins_settings = {
163 .ins_preferred_freq_bssid = NULL,
164 .ins_last_connected_bssid = true,
165 .ins_assoc_reject = true,
166 .ins_signal_bssid = true,
167 .ins_preferred_freq_bssid_score = 20,
168 .ins_last_connected_bssid_score = 20,
169 .ins_assoc_reject_score = 10,
171 .ins_last_user_selection = true,
172 .ins_last_user_selection_time = 480,
173 .ins_last_connected = true,
174 .ins_preferred_freq = NULL,
175 .ins_security_priority = NULL,
176 .ins_security_priority_count = 0,
178 .ins_internet = true,
179 .ins_last_user_selection_score = 30,
180 .ins_last_connected_score = 30,
181 .ins_preferred_freq_score = 60,
182 .ins_security_priority_score = 5,
183 .ins_internet_score = 30,
185 .ins_signal_level3_5ghz = -76,
186 .ins_signal_level3_24ghz = -74,
190 #define CONF_BG_SCAN "BackgroundScanning"
191 #define CONF_PREF_TIMESERVERS "FallbackTimeservers"
192 #define CONF_AUTO_CONNECT_TECHS "DefaultAutoConnectTechnologies"
193 #define CONF_FAVORITE_TECHS "DefaultFavoriteTechnologies"
194 #define CONF_ALWAYS_CONNECTED_TECHS "AlwaysConnectedTechnologies"
195 #define CONF_PREFERRED_TECHS "PreferredTechnologies"
196 #define CONF_FALLBACK_NAMESERVERS "FallbackNameservers"
197 #define CONF_TIMEOUT_INPUTREQ "InputRequestTimeout"
198 #define CONF_TIMEOUT_BROWSERLAUNCH "BrowserLaunchTimeout"
199 #define CONF_BLACKLISTED_INTERFACES "NetworkInterfaceBlacklist"
200 #define CONF_ALLOW_HOSTNAME_UPDATES "AllowHostnameUpdates"
201 #define CONF_ALLOW_DOMAINNAME_UPDATES "AllowDomainnameUpdates"
202 #define CONF_SINGLE_TECH "SingleConnectedTechnology"
203 #define CONF_TETHERING_TECHNOLOGIES "TetheringTechnologies"
204 #define CONF_PERSISTENT_TETHERING_MODE "PersistentTetheringMode"
205 #define CONF_ENABLE_6TO4 "Enable6to4"
206 #define CONF_VENDOR_CLASS_ID "VendorClassID"
207 #define CONF_ENABLE_ONLINE_CHECK "EnableOnlineCheck"
208 #define CONF_AUTO_CONNECT_ROAMING_SERVICES "AutoConnectRoamingServices"
209 #define CONF_ACD "AddressConflictDetection"
210 #define CONF_USE_GATEWAYS_AS_TIMESERVERS "UseGatewaysAsTimeservers"
211 #if defined TIZEN_EXT
212 #define CONF_CELLULAR_INTERFACE "NetworkCellularInterfaceList"
213 #define CONF_TIZEN_TV_EXT "TizenTVExtension"
214 #define CONF_ENABLE_AUTO_IP "EnableAutoIp"
215 #define CONF_GLOBAL_NAMESERVER "GlobalNameserver"
216 #define CONF_CONNMAN_SUPPLICANT_DEBUG "ConnmanSupplicantDebug"
219 #if defined TIZEN_EXT
221 #define CONF_INS_PREFERRED_FREQ_BSSID "INSPreferredFreqBSSID"
222 #define CONF_INS_PREFERRED_FREQ_BSSID_SCORE "INSPreferredFreqBSSIDScore"
223 #define CONF_INS_LAST_CONNECTED_BSSID "INSLastConnectedBSSID"
224 #define CONF_INS_LAST_CONNECTED_BSSID_SCORE "INSLastConnectedBSSIDScore"
225 #define CONF_INS_ASSOC_REJECT "INSAssocReject"
226 #define CONF_INS_ASSOC_REJECT_SCORE "INSAssocRejectScore"
227 #define CONF_INS_SIGNAL_BSSID "INSSignalBSSID"
229 #define CONF_INS_LAST_USER_SELECTION "INSLastUserSelection"
230 #define CONF_INS_LAST_USER_SELECTION_TIME "INSLastUserSelectionTime"
231 #define CONF_INS_LAST_USER_SELECTION_SCORE "INSLastUserSelectionScore"
232 #define CONF_INS_LAST_CONNECTED "INSLastConnected"
233 #define CONF_INS_LAST_CONNECTED_SCORE "INSLastConnectedScore"
234 #define CONF_INS_PREFERRED_FREQ "INSPreferredFreq"
235 #define CONF_INS_PREFERRED_FREQ_SCORE "INSPreferredFreqScore"
236 #define CONF_INS_SECURITY_PRIORITY "INSSecurityPriority"
237 #define CONF_INS_SECURITY_PRIORITY_COUNT "INSSecurityPriorityCount"
238 #define CONF_INS_SECURITY_PRIORITY_SCORE "INSSecurityPriorityScore"
239 #define CONF_INS_SIGNAL "INSSignal"
240 #define CONF_INS_INTERNET "INSInternet"
241 #define CONF_INS_INTERNET_SCORE "INSInternetScore"
243 #define CONF_INS_SIGNAL_LEVEL3_5GHZ "INSSignalLevel3_5GHz"
244 #define CONF_INS_SIGNAL_LEVEL3_24GHZ "INSSignalLevel3_24GHz"
247 static const char *supported_options[] = {
249 CONF_PREF_TIMESERVERS,
250 CONF_AUTO_CONNECT_TECHS,
251 CONF_ALWAYS_CONNECTED_TECHS,
252 CONF_PREFERRED_TECHS,
253 CONF_FALLBACK_NAMESERVERS,
254 CONF_TIMEOUT_INPUTREQ,
255 CONF_TIMEOUT_BROWSERLAUNCH,
256 CONF_BLACKLISTED_INTERFACES,
257 CONF_ALLOW_HOSTNAME_UPDATES,
258 CONF_ALLOW_DOMAINNAME_UPDATES,
260 CONF_TETHERING_TECHNOLOGIES,
261 CONF_PERSISTENT_TETHERING_MODE,
263 CONF_VENDOR_CLASS_ID,
264 CONF_ENABLE_ONLINE_CHECK,
265 CONF_AUTO_CONNECT_ROAMING_SERVICES,
267 CONF_USE_GATEWAYS_AS_TIMESERVERS,
268 #if defined TIZEN_EXT
269 CONF_CELLULAR_INTERFACE,
272 CONF_GLOBAL_NAMESERVER,
273 CONF_CONNMAN_SUPPLICANT_DEBUG,
278 #if defined TIZEN_EXT
279 static const char *supported_ins_options[] = {
281 CONF_INS_PREFERRED_FREQ_BSSID,
282 CONF_INS_PREFERRED_FREQ_BSSID_SCORE,
283 CONF_INS_LAST_CONNECTED_BSSID,
284 CONF_INS_LAST_CONNECTED_BSSID_SCORE,
285 CONF_INS_ASSOC_REJECT,
286 CONF_INS_ASSOC_REJECT_SCORE,
287 CONF_INS_SIGNAL_BSSID,
289 CONF_INS_LAST_USER_SELECTION,
290 CONF_INS_LAST_USER_SELECTION_TIME,
291 CONF_INS_LAST_USER_SELECTION_SCORE,
292 CONF_INS_LAST_CONNECTED,
293 CONF_INS_LAST_CONNECTED_SCORE,
294 CONF_INS_PREFERRED_FREQ,
295 CONF_INS_PREFERRED_FREQ_SCORE,
296 CONF_INS_SECURITY_PRIORITY,
297 CONF_INS_SECURITY_PRIORITY_COUNT,
298 CONF_INS_SECURITY_PRIORITY_SCORE,
301 CONF_INS_INTERNET_SCORE,
303 CONF_INS_SIGNAL_LEVEL3_5GHZ,
304 CONF_INS_SIGNAL_LEVEL3_24GHZ,
309 static GKeyFile *load_config(const char *file)
314 keyfile = g_key_file_new();
316 g_key_file_set_list_separator(keyfile, ',');
318 if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
319 if (err->code != G_FILE_ERROR_NOENT) {
320 connman_error("Parsing %s failed: %s", file,
325 g_key_file_free(keyfile);
332 static uint *parse_service_types(char **str_list, gsize len)
334 unsigned int *type_list;
336 enum connman_service_type type;
338 type_list = g_try_new0(unsigned int, len + 1);
344 while (str_list[i]) {
345 type = __connman_service_string2type(str_list[i]);
347 if (type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
354 type_list[j] = CONNMAN_SERVICE_TYPE_UNKNOWN;
359 static char **parse_fallback_nameservers(char **nameservers, gsize len)
364 servers = g_try_new0(char *, len + 1);
370 while (nameservers[i]) {
371 if (connman_inet_check_ipaddress(nameservers[i]) > 0) {
372 servers[j] = g_strdup(nameservers[i]);
381 static void check_config(GKeyFile *config)
389 keys = g_key_file_get_groups(config, NULL);
391 for (j = 0; keys && keys[j]; j++) {
392 #if defined TIZEN_EXT
393 if (g_strcmp0(keys[j], "General") != 0 &&
394 g_strcmp0(keys[j], "INS") != 0)
396 if (g_strcmp0(keys[j], "General") != 0)
398 connman_warn("Unknown group %s in %s",
404 keys = g_key_file_get_keys(config, "General", NULL, NULL);
406 for (j = 0; keys && keys[j]; j++) {
411 for (i = 0; supported_options[i]; i++) {
412 if (g_strcmp0(keys[j], supported_options[i]) == 0) {
417 if (!found && !supported_options[i])
418 connman_warn("Unknown option %s in %s",
424 #if defined TIZEN_EXT
425 keys = g_key_file_get_keys(config, "INS", NULL, NULL);
427 for (j = 0; keys && keys[j]; j++) {
432 for (i = 0; supported_ins_options[i]; i++) {
433 if (g_strcmp0(keys[j], supported_ins_options[i]) == 0) {
438 if (!found && !supported_ins_options[i])
439 connman_warn("Unknown option %s in %s",
447 #if defined TIZEN_EXT
448 static void check_Tizen_INS_configuration(GKeyFile *config)
450 GError *error = NULL;
451 char *ins_preferred_freq_bssid;
452 char *ins_preferred_freq;
453 char **ins_security_priority;
458 ins_preferred_freq_bssid = __connman_config_get_string(config, "INS",
459 CONF_INS_PREFERRED_FREQ_BSSID, &error);
461 connman_ins_settings.ins_preferred_freq_bssid = ins_preferred_freq_bssid;
463 g_clear_error(&error);
465 integer = g_key_file_get_integer(config, "INS",
466 CONF_INS_PREFERRED_FREQ_BSSID_SCORE, &error);
467 if (!error && integer >= 0)
468 connman_ins_settings.ins_preferred_freq_bssid_score = integer;
470 g_clear_error(&error);
472 boolean = __connman_config_get_bool(config, "INS",
473 CONF_INS_LAST_CONNECTED_BSSID, &error);
475 connman_ins_settings.ins_last_connected_bssid = boolean;
477 g_clear_error(&error);
479 integer = g_key_file_get_integer(config, "INS",
480 CONF_INS_LAST_CONNECTED_BSSID_SCORE, &error);
481 if (!error && integer >= 0)
482 connman_ins_settings.ins_last_connected_bssid_score = integer;
484 g_clear_error(&error);
486 boolean = __connman_config_get_bool(config, "INS",
487 CONF_INS_ASSOC_REJECT, &error);
489 connman_ins_settings.ins_assoc_reject = boolean;
491 g_clear_error(&error);
493 integer = g_key_file_get_integer(config, "INS",
494 CONF_INS_ASSOC_REJECT_SCORE, &error);
495 if (!error && integer >= 0)
496 connman_ins_settings.ins_assoc_reject_score = integer;
498 g_clear_error(&error);
500 boolean = __connman_config_get_bool(config, "INS",
501 CONF_INS_SIGNAL_BSSID, &error);
503 connman_ins_settings.ins_signal_bssid = boolean;
505 g_clear_error(&error);
507 boolean = __connman_config_get_bool(config, "INS",
508 CONF_INS_LAST_USER_SELECTION, &error);
510 connman_ins_settings.ins_last_user_selection = boolean;
512 g_clear_error(&error);
514 integer = g_key_file_get_integer(config, "INS",
515 CONF_INS_LAST_USER_SELECTION_TIME, &error);
516 if (!error && integer >= 0)
517 connman_ins_settings.ins_last_user_selection_time = integer;
519 g_clear_error(&error);
521 integer = g_key_file_get_integer(config, "INS",
522 CONF_INS_LAST_USER_SELECTION_SCORE, &error);
523 if (!error && integer >= 0)
524 connman_ins_settings.ins_last_user_selection_score = integer;
526 g_clear_error(&error);
528 boolean = __connman_config_get_bool(config, "INS",
529 CONF_INS_LAST_CONNECTED, &error);
531 connman_ins_settings.ins_last_connected = boolean;
533 g_clear_error(&error);
535 integer = g_key_file_get_integer(config, "INS",
536 CONF_INS_LAST_CONNECTED_SCORE, &error);
537 if (!error && integer >= 0)
538 connman_ins_settings.ins_last_connected_score = integer;
540 g_clear_error(&error);
542 ins_preferred_freq = __connman_config_get_string(config, "INS",
543 CONF_INS_PREFERRED_FREQ, &error);
545 connman_ins_settings.ins_preferred_freq = ins_preferred_freq;
547 g_clear_error(&error);
549 integer = g_key_file_get_integer(config, "INS",
550 CONF_INS_PREFERRED_FREQ_SCORE, &error);
551 if (!error && integer >= 0)
552 connman_ins_settings.ins_preferred_freq_score = integer;
554 g_clear_error(&error);
556 ins_security_priority = g_key_file_get_string_list(config, "INS",
557 CONF_INS_SECURITY_PRIORITY, &len, &error);
560 connman_ins_settings.ins_security_priority = ins_security_priority;
561 connman_ins_settings.ins_security_priority_count = len;
564 g_clear_error(&error);
566 integer = g_key_file_get_integer(config, "INS",
567 CONF_INS_SECURITY_PRIORITY_SCORE, &error);
568 if (!error && integer >= 0)
569 connman_ins_settings.ins_security_priority_score = integer;
571 g_clear_error(&error);
573 boolean = __connman_config_get_bool(config, "INS",
574 CONF_INS_SIGNAL, &error);
576 connman_ins_settings.ins_signal = boolean;
578 g_clear_error(&error);
580 boolean = __connman_config_get_bool(config, "INS",
581 CONF_INS_INTERNET, &error);
583 connman_ins_settings.ins_internet = boolean;
585 g_clear_error(&error);
587 integer = g_key_file_get_integer(config, "INS",
588 CONF_INS_INTERNET_SCORE, &error);
589 if (!error && integer >= 0)
590 connman_ins_settings.ins_internet_score = integer;
592 g_clear_error(&error);
594 integer = g_key_file_get_integer(config, "INS",
595 CONF_INS_SIGNAL_LEVEL3_5GHZ, &error);
597 connman_ins_settings.ins_signal_level3_5ghz = integer;
599 g_clear_error(&error);
601 integer = g_key_file_get_integer(config, "INS",
602 CONF_INS_SIGNAL_LEVEL3_24GHZ, &error);
604 connman_ins_settings.ins_signal_level3_24ghz = integer;
606 g_clear_error(&error);
609 static void check_Tizen_configuration(GKeyFile *config)
611 GError *error = NULL;
612 char **cellular_interfaces;
613 char *global_nameserver;
617 cellular_interfaces = g_key_file_get_string_list(config, "General",
618 CONF_CELLULAR_INTERFACE, &len, &error);
621 connman_settings.cellular_interfaces = cellular_interfaces;
623 g_clear_error(&error);
625 boolean = __connman_config_get_bool(config, "General",
626 CONF_TIZEN_TV_EXT, &error);
628 connman_settings.tizen_tv_extension = boolean;
630 g_clear_error(&error);
632 boolean = __connman_config_get_bool(config, "General",
633 CONF_ENABLE_AUTO_IP, &error);
635 connman_settings.auto_ip = boolean;
637 g_clear_error(&error);
639 global_nameserver = __connman_config_get_string(config, "General",
640 CONF_GLOBAL_NAMESERVER, &error);
642 connman_settings.global_nameserver = global_nameserver;
644 g_clear_error(&error);
646 boolean = __connman_config_get_bool(config, "General",
647 CONF_CONNMAN_SUPPLICANT_DEBUG, &error);
649 connman_settings.supplicant_debug = boolean;
651 g_clear_error(&error);
653 check_Tizen_INS_configuration(config);
656 static void set_nofile_inc(void)
661 rlim.rlim_cur = 8192;
662 rlim.rlim_max = 8192;
664 err = setrlimit(RLIMIT_NOFILE, &rlim);
666 DBG("fail to increase FILENO err(%d)", err);
672 static void parse_config(GKeyFile *config)
674 GError *error = NULL;
680 char *vendor_class_id;
685 connman_settings.auto_connect =
686 parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
687 connman_settings.favorite_techs =
688 parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
689 connman_settings.blacklisted_interfaces =
690 g_strdupv(default_blacklist);
694 DBG("parsing %s", MAINFILE);
696 boolean = g_key_file_get_boolean(config, "General",
697 CONF_BG_SCAN, &error);
699 connman_settings.bg_scan = boolean;
701 g_clear_error(&error);
703 timeservers = __connman_config_get_string_list(config, "General",
704 CONF_PREF_TIMESERVERS, NULL, &error);
706 connman_settings.pref_timeservers = timeservers;
708 g_clear_error(&error);
710 str_list = __connman_config_get_string_list(config, "General",
711 CONF_AUTO_CONNECT_TECHS, &len, &error);
714 connman_settings.auto_connect =
715 parse_service_types(str_list, len);
717 connman_settings.auto_connect =
718 parse_service_types(default_auto_connect, CONF_ARRAY_SIZE(default_auto_connect));
720 g_clear_error(&error);
722 str_list = __connman_config_get_string_list(config, "General",
723 CONF_FAVORITE_TECHS, &len, &error);
726 connman_settings.favorite_techs =
727 parse_service_types(str_list, len);
729 connman_settings.favorite_techs =
730 parse_service_types(default_favorite_techs, CONF_ARRAY_SIZE(default_favorite_techs));
732 g_strfreev(str_list);
734 g_clear_error(&error);
736 str_list = __connman_config_get_string_list(config, "General",
737 CONF_PREFERRED_TECHS, &len, &error);
740 connman_settings.preferred_techs =
741 parse_service_types(str_list, len);
743 g_strfreev(str_list);
745 g_clear_error(&error);
747 str_list = __connman_config_get_string_list(config, "General",
748 CONF_ALWAYS_CONNECTED_TECHS, &len, &error);
751 connman_settings.always_connected_techs =
752 parse_service_types(str_list, len);
754 g_strfreev(str_list);
756 g_clear_error(&error);
758 str_list = __connman_config_get_string_list(config, "General",
759 CONF_FALLBACK_NAMESERVERS, &len, &error);
762 connman_settings.fallback_nameservers =
763 parse_fallback_nameservers(str_list, len);
765 g_strfreev(str_list);
767 g_clear_error(&error);
769 timeout = g_key_file_get_integer(config, "General",
770 CONF_TIMEOUT_INPUTREQ, &error);
771 if (!error && timeout >= 0)
772 connman_settings.timeout_inputreq = timeout * 1000;
774 g_clear_error(&error);
776 timeout = g_key_file_get_integer(config, "General",
777 CONF_TIMEOUT_BROWSERLAUNCH, &error);
778 if (!error && timeout >= 0)
779 connman_settings.timeout_browserlaunch = timeout * 1000;
781 g_clear_error(&error);
783 interfaces = __connman_config_get_string_list(config, "General",
784 CONF_BLACKLISTED_INTERFACES, &len, &error);
787 connman_settings.blacklisted_interfaces = interfaces;
789 connman_settings.blacklisted_interfaces =
790 g_strdupv(default_blacklist);
792 g_clear_error(&error);
794 boolean = __connman_config_get_bool(config, "General",
795 CONF_ALLOW_HOSTNAME_UPDATES,
798 connman_settings.allow_hostname_updates = boolean;
800 g_clear_error(&error);
802 boolean = __connman_config_get_bool(config, "General",
803 CONF_ALLOW_DOMAINNAME_UPDATES,
806 connman_settings.allow_domainname_updates = boolean;
808 g_clear_error(&error);
810 boolean = __connman_config_get_bool(config, "General",
811 CONF_SINGLE_TECH, &error);
813 connman_settings.single_tech = boolean;
815 g_clear_error(&error);
817 tethering = __connman_config_get_string_list(config, "General",
818 CONF_TETHERING_TECHNOLOGIES, &len, &error);
821 connman_settings.tethering_technologies = tethering;
823 g_clear_error(&error);
825 boolean = __connman_config_get_bool(config, "General",
826 CONF_PERSISTENT_TETHERING_MODE,
829 connman_settings.persistent_tethering_mode = boolean;
831 g_clear_error(&error);
833 boolean = __connman_config_get_bool(config, "General",
834 CONF_ENABLE_6TO4, &error);
836 connman_settings.enable_6to4 = boolean;
838 g_clear_error(&error);
840 vendor_class_id = __connman_config_get_string(config, "General",
841 CONF_VENDOR_CLASS_ID, &error);
843 connman_settings.vendor_class_id = vendor_class_id;
845 g_clear_error(&error);
847 boolean = __connman_config_get_bool(config, "General",
848 CONF_ENABLE_ONLINE_CHECK, &error);
850 connman_settings.enable_online_check = boolean;
852 connman_info("Online check disabled by main config.");
855 g_clear_error(&error);
857 boolean = __connman_config_get_bool(config, "General",
858 CONF_AUTO_CONNECT_ROAMING_SERVICES, &error);
860 connman_settings.auto_connect_roaming_services = boolean;
862 g_clear_error(&error);
864 boolean = __connman_config_get_bool(config, "General", CONF_ACD, &error);
866 connman_settings.acd = boolean;
868 g_clear_error(&error);
870 boolean = __connman_config_get_bool(config, "General",
871 CONF_USE_GATEWAYS_AS_TIMESERVERS, &error);
873 connman_settings.use_gateways_as_timeservers = boolean;
875 g_clear_error(&error);
877 #if defined TIZEN_EXT
878 check_Tizen_configuration(config);
882 static int config_init(const char *file)
886 #if defined TIZEN_EXT
889 config = load_config(file);
890 check_config(config);
891 parse_config(config);
893 g_key_file_free(config);
898 static GMainLoop *main_loop = NULL;
900 static unsigned int __terminated = 0;
902 static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
905 struct signalfd_siginfo si;
909 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
912 fd = g_io_channel_unix_get_fd(channel);
914 result = read(fd, &si, sizeof(si));
915 if (result != sizeof(si))
918 switch (si.ssi_signo) {
921 if (__terminated == 0) {
922 connman_info("Terminating");
923 g_main_loop_quit(main_loop);
933 static guint setup_signalfd(void)
941 sigaddset(&mask, SIGINT);
942 sigaddset(&mask, SIGTERM);
944 if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
945 perror("Failed to set signal mask");
949 fd = signalfd(-1, &mask, 0);
951 perror("Failed to create signal descriptor");
955 channel = g_io_channel_unix_new(fd);
957 g_io_channel_set_close_on_unref(channel, TRUE);
958 g_io_channel_set_encoding(channel, NULL, NULL);
959 g_io_channel_set_buffered(channel, FALSE);
961 source = g_io_add_watch(channel,
962 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
963 signal_handler, NULL);
965 g_io_channel_unref(channel);
970 static void disconnect_callback(DBusConnection *conn, void *user_data)
972 connman_error("D-Bus disconnect");
974 g_main_loop_quit(main_loop);
977 static gchar *option_config = NULL;
978 static gchar *option_debug = NULL;
979 static gchar *option_device = NULL;
980 static gchar *option_plugin = NULL;
981 static gchar *option_nodevice = NULL;
982 static gchar *option_noplugin = NULL;
983 static gchar *option_wifi = NULL;
984 static gboolean option_detach = TRUE;
985 static gboolean option_dnsproxy = TRUE;
986 static gboolean option_backtrace = TRUE;
987 static gboolean option_version = FALSE;
989 static bool parse_debug(const char *key, const char *value,
990 gpointer user_data, GError **error)
994 char *prev = option_debug;
996 option_debug = g_strconcat(prev, ",", value, NULL);
999 option_debug = g_strdup(value);
1002 g_free(option_debug);
1003 option_debug = g_strdup("*");
1009 static bool parse_noplugin(const char *key, const char *value,
1010 gpointer user_data, GError **error)
1012 if (option_noplugin) {
1013 char *prev = option_noplugin;
1015 option_noplugin = g_strconcat(prev, ",", value, NULL);
1018 option_noplugin = g_strdup(value);
1024 static GOptionEntry options[] = {
1025 { "config", 'c', 0, G_OPTION_ARG_STRING, &option_config,
1026 "Load the specified configuration file "
1027 "instead of " CONFIGMAINFILE, "FILE" },
1028 { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
1029 G_OPTION_ARG_CALLBACK, parse_debug,
1030 "Specify debug options to enable", "DEBUG" },
1031 { "device", 'i', 0, G_OPTION_ARG_STRING, &option_device,
1032 "Specify networking devices or interfaces", "DEV,..." },
1033 { "nodevice", 'I', 0, G_OPTION_ARG_STRING, &option_nodevice,
1034 "Specify networking interfaces to ignore", "DEV,..." },
1035 { "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin,
1036 "Specify plugins to load", "NAME,..." },
1037 { "noplugin", 'P', 0, G_OPTION_ARG_CALLBACK, &parse_noplugin,
1038 "Specify plugins not to load", "NAME,..." },
1039 { "wifi", 'W', 0, G_OPTION_ARG_STRING, &option_wifi,
1040 "Specify driver for WiFi/Supplicant", "NAME" },
1041 { "nodaemon", 'n', G_OPTION_FLAG_REVERSE,
1042 G_OPTION_ARG_NONE, &option_detach,
1043 "Don't fork daemon to background" },
1044 { "nodnsproxy", 'r', G_OPTION_FLAG_REVERSE,
1045 G_OPTION_ARG_NONE, &option_dnsproxy,
1046 "Don't support DNS resolving" },
1047 { "nobacktrace", 0, G_OPTION_FLAG_REVERSE,
1048 G_OPTION_ARG_NONE, &option_backtrace,
1049 "Don't print out backtrace information" },
1050 { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
1051 "Show version information and exit" },
1055 const char *connman_option_get_string(const char *key)
1057 if (g_str_equal(key, CONF_VENDOR_CLASS_ID))
1058 return connman_settings.vendor_class_id;
1060 if (g_strcmp0(key, "wifi") == 0) {
1062 return "nl80211,wext";
1067 #if defined TIZEN_EXT
1068 if (g_str_equal(key, CONF_GLOBAL_NAMESERVER))
1069 return connman_settings.global_nameserver;
1072 #if defined TIZEN_EXT
1073 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID))
1074 return connman_ins_settings.ins_preferred_freq_bssid;
1076 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ))
1077 return connman_ins_settings.ins_preferred_freq;
1082 bool connman_setting_get_bool(const char *key)
1084 if (g_str_equal(key, CONF_BG_SCAN))
1085 return connman_settings.bg_scan;
1087 if (g_str_equal(key, CONF_ALLOW_HOSTNAME_UPDATES))
1088 return connman_settings.allow_hostname_updates;
1090 if (g_str_equal(key, CONF_ALLOW_DOMAINNAME_UPDATES))
1091 return connman_settings.allow_domainname_updates;
1093 if (g_str_equal(key, CONF_SINGLE_TECH))
1094 return connman_settings.single_tech;
1096 if (g_str_equal(key, CONF_PERSISTENT_TETHERING_MODE))
1097 return connman_settings.persistent_tethering_mode;
1099 if (g_str_equal(key, CONF_ENABLE_6TO4))
1100 return connman_settings.enable_6to4;
1102 if (g_str_equal(key, CONF_ENABLE_ONLINE_CHECK))
1103 return connman_settings.enable_online_check;
1105 if (g_str_equal(key, CONF_AUTO_CONNECT_ROAMING_SERVICES))
1106 return connman_settings.auto_connect_roaming_services;
1108 if (g_str_equal(key, CONF_ACD))
1109 return connman_settings.acd;
1111 if (g_str_equal(key, CONF_USE_GATEWAYS_AS_TIMESERVERS))
1112 return connman_settings.use_gateways_as_timeservers;
1114 #if defined TIZEN_EXT
1115 if (g_str_equal(key, CONF_ENABLE_AUTO_IP))
1116 return connman_settings.auto_ip;
1118 if (g_str_equal(key, CONF_CONNMAN_SUPPLICANT_DEBUG))
1119 return connman_settings.supplicant_debug;
1122 #if defined TIZEN_EXT
1123 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID))
1124 return connman_ins_settings.ins_last_connected_bssid;
1126 if (g_str_equal(key, CONF_INS_ASSOC_REJECT))
1127 return connman_ins_settings.ins_assoc_reject;
1129 if (g_str_equal(key, CONF_INS_SIGNAL_BSSID))
1130 return connman_ins_settings.ins_signal_bssid;
1132 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION))
1133 return connman_ins_settings.ins_last_user_selection;
1135 if (g_str_equal(key, CONF_INS_LAST_CONNECTED))
1136 return connman_ins_settings.ins_last_connected;
1138 if (g_str_equal(key, CONF_INS_SIGNAL))
1139 return connman_ins_settings.ins_signal;
1141 if (g_str_equal(key, CONF_INS_INTERNET))
1142 return connman_ins_settings.ins_internet;
1148 #if defined TIZEN_EXT
1149 unsigned int connman_setting_get_uint(const char *key)
1151 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_BSSID_SCORE))
1152 return connman_ins_settings.ins_preferred_freq_bssid_score;
1154 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_BSSID_SCORE))
1155 return connman_ins_settings.ins_last_connected_bssid_score;
1157 if (g_str_equal(key, CONF_INS_ASSOC_REJECT_SCORE))
1158 return connman_ins_settings.ins_assoc_reject_score;
1160 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_TIME))
1161 return connman_ins_settings.ins_last_user_selection_time;
1163 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_COUNT))
1164 return connman_ins_settings.ins_security_priority_count;
1166 if (g_str_equal(key, CONF_INS_LAST_USER_SELECTION_SCORE))
1167 return connman_ins_settings.ins_last_user_selection_score;
1169 if (g_str_equal(key, CONF_INS_LAST_CONNECTED_SCORE))
1170 return connman_ins_settings.ins_last_connected_score;
1172 if (g_str_equal(key, CONF_INS_PREFERRED_FREQ_SCORE))
1173 return connman_ins_settings.ins_preferred_freq_score;
1175 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY_SCORE))
1176 return connman_ins_settings.ins_security_priority_score;
1178 if (g_str_equal(key, CONF_INS_INTERNET_SCORE))
1179 return connman_ins_settings.ins_internet_score;
1184 int connman_setting_get_int(const char *key)
1186 if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_5GHZ))
1187 return connman_ins_settings.ins_signal_level3_5ghz;
1189 if (g_str_equal(key, CONF_INS_SIGNAL_LEVEL3_24GHZ))
1190 return connman_ins_settings.ins_signal_level3_24ghz;
1196 char **connman_setting_get_string_list(const char *key)
1198 if (g_str_equal(key, CONF_PREF_TIMESERVERS))
1199 return connman_settings.pref_timeservers;
1201 if (g_str_equal(key, CONF_FALLBACK_NAMESERVERS))
1202 return connman_settings.fallback_nameservers;
1204 if (g_str_equal(key, CONF_BLACKLISTED_INTERFACES))
1205 return connman_settings.blacklisted_interfaces;
1207 if (g_str_equal(key, CONF_TETHERING_TECHNOLOGIES))
1208 return connman_settings.tethering_technologies;
1210 #if defined TIZEN_EXT
1211 if (g_str_equal(key, CONF_CELLULAR_INTERFACE))
1212 return connman_settings.cellular_interfaces;
1215 #if defined TIZEN_EXT
1216 if (g_str_equal(key, CONF_INS_SECURITY_PRIORITY))
1217 return connman_ins_settings.ins_security_priority;
1223 unsigned int *connman_setting_get_uint_list(const char *key)
1225 if (g_str_equal(key, CONF_AUTO_CONNECT_TECHS))
1226 return connman_settings.auto_connect;
1228 if (g_str_equal(key, CONF_FAVORITE_TECHS))
1229 return connman_settings.favorite_techs;
1231 if (g_str_equal(key, CONF_PREFERRED_TECHS))
1232 return connman_settings.preferred_techs;
1234 if (g_str_equal(key, CONF_ALWAYS_CONNECTED_TECHS))
1235 return connman_settings.always_connected_techs;
1240 unsigned int connman_timeout_input_request(void)
1242 return connman_settings.timeout_inputreq;
1245 unsigned int connman_timeout_browser_launch(void)
1247 return connman_settings.timeout_browserlaunch;
1250 int main(int argc, char *argv[])
1252 GOptionContext *context;
1253 GError *error = NULL;
1254 DBusConnection *conn;
1258 context = g_option_context_new(NULL);
1259 g_option_context_add_main_entries(context, options, NULL);
1261 if (!g_option_context_parse(context, &argc, &argv, &error)) {
1263 g_printerr("%s\n", error->message);
1264 g_error_free(error);
1266 g_printerr("An unknown error occurred\n");
1270 g_option_context_free(context);
1272 if (option_version) {
1273 printf("%s\n", VERSION);
1277 if (option_detach) {
1279 perror("Can't start daemon");
1284 if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
1285 S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
1286 if (errno != EEXIST)
1287 perror("Failed to create storage directory");
1292 main_loop = g_main_loop_new(NULL, FALSE);
1294 signal = setup_signalfd();
1296 dbus_error_init(&err);
1298 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
1300 if (dbus_error_is_set(&err)) {
1301 fprintf(stderr, "%s\n", err.message);
1302 dbus_error_free(&err);
1304 fprintf(stderr, "Can't register with system bus\n");
1308 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
1310 __connman_log_init(argv[0], option_debug, option_detach,
1311 option_backtrace, "Connection Manager", VERSION);
1313 __connman_dbus_init(conn);
1316 config_init(CONFIGMAINFILE);
1318 config_init(option_config);
1320 __connman_util_init();
1321 __connman_inotify_init();
1322 __connman_technology_init();
1323 __connman_notifier_init();
1324 __connman_agent_init();
1325 __connman_service_init();
1326 __connman_peer_service_init();
1327 __connman_peer_init();
1328 #if defined TIZEN_EXT_WIFI_MESH
1329 __connman_mesh_init();
1330 #endif /* TIZEN_EXT_WIFI_MESH */
1331 __connman_provider_init();
1332 __connman_network_init();
1333 __connman_config_init();
1334 __connman_device_init(option_device, option_nodevice);
1336 __connman_ippool_init();
1337 __connman_firewall_init();
1338 __connman_nat_init();
1339 __connman_tethering_init();
1340 __connman_counter_init();
1341 __connman_manager_init();
1342 __connman_stats_init();
1343 __connman_clock_init();
1345 __connman_ipconfig_init();
1346 __connman_rtnl_init();
1347 __connman_task_init();
1348 __connman_proxy_init();
1349 __connman_detect_init();
1350 __connman_session_init();
1351 __connman_timeserver_init();
1352 __connman_connection_init();
1354 __connman_plugin_init(option_plugin, option_noplugin);
1356 __connman_resolver_init(option_dnsproxy);
1357 __connman_rtnl_start();
1358 __connman_dhcp_init();
1359 __connman_dhcpv6_init();
1360 __connman_wpad_init();
1361 __connman_wispr_init();
1362 #if !defined TIZEN_EXT
1363 __connman_rfkill_init();
1364 __connman_machine_init();
1367 g_free(option_config);
1368 g_free(option_device);
1369 g_free(option_plugin);
1370 g_free(option_nodevice);
1371 g_free(option_noplugin);
1373 g_main_loop_run(main_loop);
1375 g_source_remove(signal);
1377 #if !defined TIZEN_EXT
1378 __connman_machine_cleanup();
1379 __connman_rfkill_cleanup();
1381 __connman_wispr_cleanup();
1382 __connman_wpad_cleanup();
1383 __connman_dhcpv6_cleanup();
1384 __connman_session_cleanup();
1385 __connman_plugin_cleanup();
1386 __connman_provider_cleanup();
1387 __connman_connection_cleanup();
1388 __connman_timeserver_cleanup();
1389 __connman_detect_cleanup();
1390 __connman_proxy_cleanup();
1391 __connman_task_cleanup();
1392 __connman_rtnl_cleanup();
1393 __connman_resolver_cleanup();
1395 __connman_clock_cleanup();
1396 __connman_stats_cleanup();
1397 __connman_config_cleanup();
1398 __connman_manager_cleanup();
1399 __connman_counter_cleanup();
1400 __connman_tethering_cleanup();
1401 __connman_nat_cleanup();
1402 __connman_firewall_cleanup();
1403 __connman_peer_service_cleanup();
1404 __connman_peer_cleanup();
1405 #if defined TIZEN_EXT_WIFI_MESH
1406 __connman_mesh_cleanup();
1407 #endif /* TIZEN_EXT_WIFI_MESH */
1408 __connman_ippool_cleanup();
1409 __connman_device_cleanup();
1410 __connman_network_cleanup();
1411 __connman_dhcp_cleanup();
1412 __connman_service_cleanup();
1413 __connman_agent_cleanup();
1414 __connman_ipconfig_cleanup();
1415 __connman_notifier_cleanup();
1416 __connman_technology_cleanup();
1417 __connman_inotify_cleanup();
1419 __connman_util_cleanup();
1420 __connman_dbus_cleanup();
1422 __connman_log_cleanup(option_backtrace);
1424 dbus_connection_unref(conn);
1426 g_main_loop_unref(main_loop);
1428 if (connman_settings.pref_timeservers)
1429 g_strfreev(connman_settings.pref_timeservers);
1431 g_free(connman_settings.auto_connect);
1432 g_free(connman_settings.favorite_techs);
1433 g_free(connman_settings.preferred_techs);
1434 g_strfreev(connman_settings.fallback_nameservers);
1435 g_strfreev(connman_settings.blacklisted_interfaces);
1436 g_strfreev(connman_settings.tethering_technologies);
1438 #if defined TIZEN_EXT
1439 g_free(connman_ins_settings.ins_preferred_freq_bssid);
1440 g_free(connman_ins_settings.ins_preferred_freq);
1441 if (connman_ins_settings.ins_security_priority)
1442 g_strfreev(connman_ins_settings.ins_security_priority);
1445 g_free(option_debug);
1446 g_free(option_wifi);