5 * Copyright (C) 2007-2014 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
36 #include <connman/storage.h>
37 #include <connman/setting.h>
38 #include <connman/agent.h>
42 #define CONNECT_TIMEOUT 120
45 #define USER_NONE (uid_t)-1
48 #define WIFI_BSSID_STR_LEN 18
51 static DBusConnection *connection = NULL;
53 static GList *service_list = NULL;
54 static GHashTable *service_hash = NULL;
55 static GSList *counter_list = NULL;
56 static unsigned int autoconnect_timeout = 0;
57 static unsigned int vpn_autoconnect_timeout = 0;
58 static struct connman_service *current_default = NULL;
59 static bool services_dirty = false;
62 static bool auto_connect_mode = TRUE;
65 struct connman_stats {
68 struct connman_stats_data data_last;
69 struct connman_stats_data data;
73 struct connman_stats_counter {
75 struct connman_stats stats;
76 struct connman_stats stats_roaming;
79 struct connman_service_user {
84 struct connman_service {
88 enum connman_service_type type;
89 enum connman_service_security security;
90 enum connman_service_state state;
91 enum connman_service_state state_ipv4;
92 enum connman_service_state state_ipv6;
93 enum connman_service_error error;
94 enum connman_service_connect_reason connect_reason;
106 bool request_passphrase_input;
107 struct connman_service_user user;
108 struct connman_ipconfig *ipconfig_ipv4;
109 struct connman_ipconfig *ipconfig_ipv6;
110 struct connman_network *network;
111 struct connman_provider *provider;
113 char **nameservers_config;
114 char **nameservers_auto;
115 int nameservers_timeout;
120 char **timeservers_config;
121 /* 802.1x settings from the config files */
124 char *anonymous_identity;
125 char *agent_identity;
128 char *altsubject_match;
129 char *domain_suffix_match;
131 char *client_cert_file;
132 char *private_key_file;
133 char *private_key_passphrase;
135 DBusMessage *pending;
136 DBusMessage *provider_pending;
138 struct connman_stats stats;
139 struct connman_stats stats_roaming;
140 GHashTable *counter_table;
141 enum connman_service_proxy_method proxy;
142 enum connman_service_proxy_method proxy_config;
147 int online_check_count;
148 bool do_split_routing;
153 #if defined TIZEN_EXT
155 * Description: TIZEN implements system global connection management.
156 * It's only for PDP (cellular) bearer. Wi-Fi is managed
157 * by ConnMan automatically. Reference count can help to
158 * manage open/close connection requests by each application.
160 int user_pdn_connection_refcount;
163 * Description: In case of EAP security type,
164 * user can select the keymgmt type for roaming(802.11r).
165 * - FT, CCKM, OKC, ...
168 int disconnect_reason;
169 int assoc_status_code;
176 enum connman_dnsconfig_method dns_config_method_ipv4;
177 enum connman_dnsconfig_method dns_config_method_ipv6;
181 static bool allow_property_changed(struct connman_service *service);
183 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
184 int index, enum connman_ipconfig_method method);
185 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
187 static void dns_changed(struct connman_service *service);
191 struct connman_service *service;
194 #if defined TIZEN_EXT
196 * Public APIs to use user_pdn_connection_refcount
198 void connman_service_user_pdn_connection_ref(struct connman_service *service)
200 __sync_fetch_and_add(&service->user_pdn_connection_refcount, 1);
202 DBG("User made PDN connection referenced: %d",
203 service->user_pdn_connection_refcount);
206 gboolean connman_service_user_pdn_connection_unref_and_test(
207 struct connman_service *service)
209 __sync_synchronize();
211 DBG("User made PDN connection referenced: %d, which will be decreased",
212 service->user_pdn_connection_refcount);
214 if (service->user_pdn_connection_refcount < 1)
217 if (__sync_sub_and_fetch(&service->user_pdn_connection_refcount, 1) == 0)
223 gboolean connman_service_is_no_ref_user_pdn_connection(
224 struct connman_service *cellular)
226 if (cellular == NULL)
229 __sync_synchronize();
230 if (cellular->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
231 cellular->user_pdn_connection_refcount == 0)
238 static void compare_path(gpointer value, gpointer user_data)
240 struct connman_service *service = value;
241 struct find_data *data = user_data;
246 if (g_strcmp0(service->path, data->path) == 0)
247 data->service = service;
250 static struct connman_service *find_service(const char *path)
252 struct find_data data = { .path = path, .service = NULL };
254 DBG("path %s", path);
256 g_list_foreach(service_list, compare_path, &data);
261 static const char *reason2string(enum connman_service_connect_reason reason)
265 case CONNMAN_SERVICE_CONNECT_REASON_NONE:
267 case CONNMAN_SERVICE_CONNECT_REASON_USER:
269 case CONNMAN_SERVICE_CONNECT_REASON_AUTO:
271 case CONNMAN_SERVICE_CONNECT_REASON_SESSION:
278 const char *__connman_service_type2string(enum connman_service_type type)
281 case CONNMAN_SERVICE_TYPE_UNKNOWN:
283 case CONNMAN_SERVICE_TYPE_SYSTEM:
285 case CONNMAN_SERVICE_TYPE_ETHERNET:
287 case CONNMAN_SERVICE_TYPE_WIFI:
289 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
291 case CONNMAN_SERVICE_TYPE_CELLULAR:
293 case CONNMAN_SERVICE_TYPE_GPS:
295 case CONNMAN_SERVICE_TYPE_VPN:
297 case CONNMAN_SERVICE_TYPE_GADGET:
299 case CONNMAN_SERVICE_TYPE_P2P:
306 enum connman_service_type __connman_service_string2type(const char *str)
309 return CONNMAN_SERVICE_TYPE_UNKNOWN;
311 if (strcmp(str, "ethernet") == 0)
312 return CONNMAN_SERVICE_TYPE_ETHERNET;
313 if (strcmp(str, "gadget") == 0)
314 return CONNMAN_SERVICE_TYPE_GADGET;
315 if (strcmp(str, "wifi") == 0)
316 return CONNMAN_SERVICE_TYPE_WIFI;
317 if (strcmp(str, "cellular") == 0)
318 return CONNMAN_SERVICE_TYPE_CELLULAR;
319 if (strcmp(str, "bluetooth") == 0)
320 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
321 if (strcmp(str, "vpn") == 0)
322 return CONNMAN_SERVICE_TYPE_VPN;
323 if (strcmp(str, "gps") == 0)
324 return CONNMAN_SERVICE_TYPE_GPS;
325 if (strcmp(str, "system") == 0)
326 return CONNMAN_SERVICE_TYPE_SYSTEM;
327 if (strcmp(str, "p2p") == 0)
328 return CONNMAN_SERVICE_TYPE_P2P;
330 return CONNMAN_SERVICE_TYPE_UNKNOWN;
333 enum connman_service_security __connman_service_string2security(const char *str)
336 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
338 if (!strcmp(str, "psk"))
339 return CONNMAN_SERVICE_SECURITY_PSK;
340 if (!strcmp(str, "ieee8021x") || !strcmp(str, "8021x"))
341 return CONNMAN_SERVICE_SECURITY_8021X;
342 if (!strcmp(str, "none") || !strcmp(str, "open"))
343 return CONNMAN_SERVICE_SECURITY_NONE;
344 if (!strcmp(str, "wep"))
345 return CONNMAN_SERVICE_SECURITY_WEP;
346 #if defined TIZEN_EXT
347 if (!strcmp(str, "rsn"))
348 return CONNMAN_SERVICE_SECURITY_RSN;
351 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
354 static const char *security2string(enum connman_service_security security)
357 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
359 case CONNMAN_SERVICE_SECURITY_NONE:
361 case CONNMAN_SERVICE_SECURITY_WEP:
363 case CONNMAN_SERVICE_SECURITY_PSK:
364 case CONNMAN_SERVICE_SECURITY_WPA:
365 #if defined TIZEN_EXT
367 case CONNMAN_SERVICE_SECURITY_RSN:
370 case CONNMAN_SERVICE_SECURITY_RSN:
373 case CONNMAN_SERVICE_SECURITY_8021X:
380 static const char *state2string(enum connman_service_state state)
383 case CONNMAN_SERVICE_STATE_UNKNOWN:
385 case CONNMAN_SERVICE_STATE_IDLE:
387 case CONNMAN_SERVICE_STATE_ASSOCIATION:
388 return "association";
389 case CONNMAN_SERVICE_STATE_CONFIGURATION:
390 return "configuration";
391 case CONNMAN_SERVICE_STATE_READY:
393 case CONNMAN_SERVICE_STATE_ONLINE:
395 case CONNMAN_SERVICE_STATE_DISCONNECT:
397 case CONNMAN_SERVICE_STATE_FAILURE:
404 static const char *error2string(enum connman_service_error error)
407 case CONNMAN_SERVICE_ERROR_UNKNOWN:
409 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
410 return "out-of-range";
411 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
412 return "pin-missing";
413 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
414 return "dhcp-failed";
415 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
416 return "connect-failed";
417 case CONNMAN_SERVICE_ERROR_LOGIN_FAILED:
418 return "login-failed";
419 case CONNMAN_SERVICE_ERROR_AUTH_FAILED:
420 return "auth-failed";
421 case CONNMAN_SERVICE_ERROR_INVALID_KEY:
422 return "invalid-key";
423 case CONNMAN_SERVICE_ERROR_BLOCKED:
430 static const char *proxymethod2string(enum connman_service_proxy_method method)
433 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
435 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
437 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
439 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
446 static enum connman_service_proxy_method string2proxymethod(const char *method)
448 if (g_strcmp0(method, "direct") == 0)
449 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
450 else if (g_strcmp0(method, "auto") == 0)
451 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
452 else if (g_strcmp0(method, "manual") == 0)
453 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
455 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
459 static const char *__connman_dnsconfig_method2string(enum connman_dnsconfig_method method)
462 case CONNMAN_DNSCONFIG_METHOD_UNKNOWN:
464 case CONNMAN_DNSCONFIG_METHOD_MANUAL:
466 case CONNMAN_DNSCONFIG_METHOD_DHCP:
473 static enum connman_dnsconfig_method __connman_dnsconfig_string2method(
476 if (g_strcmp0(method, "manual") == 0)
477 return CONNMAN_DNSCONFIG_METHOD_MANUAL;
478 else if (g_strcmp0(method, "dhcp") == 0)
479 return CONNMAN_DNSCONFIG_METHOD_DHCP;
481 return CONNMAN_DNSCONFIG_METHOD_UNKNOWN;
486 connman_service_is_user_allowed(struct connman_service *service, uid_t uid)
488 uid_t favorite_user = service->user.favorite_user;
489 uid_t current_user = uid;
491 DBG("Service favorite UID: %d, current UID: %d", favorite_user, current_user);
492 if (favorite_user == USER_NONE || current_user == USER_ROOT)
495 if (favorite_user != current_user || current_user == USER_NONE) {
496 DBG("Current user is not a favorite user to this service!");
503 #if !defined TIZEN_EXT
504 static GList *connman_service_get_login_users()
508 GList *user_list = NULL;
512 while ((utmp = getutxent()) != NULL) {
513 DBG("User Name: %s", utmp->ut_user);
515 pwd = getpwnam(utmp->ut_user);
517 if (!g_list_find(user_list, GUINT_TO_POINTER(pwd->pw_uid)))
518 user_list = g_list_append(user_list,
519 GUINT_TO_POINTER(pwd->pw_uid));
521 DBG("User Name: %s, UID: %d", utmp->ut_user, pwd->pw_uid);
531 static bool is_service_owner_user_login(struct connman_service *service)
533 #if defined TIZEN_EXT
536 GList *list, *user_list;
539 /* Here we only care about wifi service */
540 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
543 DBG("service favorite user id is: %d", service->user.favorite_user);
545 user_list = connman_service_get_login_users();
546 if (user_list == NULL) {
547 DBG("Can not get any logged in user info.");
551 for (list = user_list; list; list = list->next) {
552 uid_t uid = GPOINTER_TO_UINT(list->data);
554 DBG("login user id is %d", uid);
556 if (service->user.favorite_user == uid) {
562 g_list_free(user_list);
568 static void set_split_routing(struct connman_service *service, bool value)
570 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
573 service->do_split_routing = value;
575 if (service->do_split_routing)
581 int __connman_service_load_modifiable(struct connman_service *service)
584 GError *error = NULL;
588 DBG("service %p", service);
590 keyfile = connman_storage_load_service(service->identifier);
594 switch (service->type) {
595 case CONNMAN_SERVICE_TYPE_UNKNOWN:
596 case CONNMAN_SERVICE_TYPE_SYSTEM:
597 case CONNMAN_SERVICE_TYPE_GPS:
598 case CONNMAN_SERVICE_TYPE_P2P:
600 case CONNMAN_SERVICE_TYPE_VPN:
601 set_split_routing(service, g_key_file_get_boolean(keyfile,
603 "SplitRouting", NULL));
606 case CONNMAN_SERVICE_TYPE_WIFI:
607 case CONNMAN_SERVICE_TYPE_GADGET:
608 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
609 case CONNMAN_SERVICE_TYPE_CELLULAR:
610 case CONNMAN_SERVICE_TYPE_ETHERNET:
611 autoconnect = g_key_file_get_boolean(keyfile,
612 service->identifier, "AutoConnect", &error);
614 service->autoconnect = autoconnect;
615 g_clear_error(&error);
619 str = g_key_file_get_string(keyfile,
620 service->identifier, "Modified", NULL);
622 g_time_val_from_iso8601(str, &service->modified);
626 g_key_file_free(keyfile);
631 static int service_load_passphrase(struct connman_service *service)
636 keyfile = connman_storage_load_service(service->identifier);
640 str = g_key_file_get_string(keyfile,
641 service->identifier, "Passphrase", NULL);
643 service->passphrase = str;
645 g_key_file_free(keyfile);
650 static int service_load(struct connman_service *service)
653 GError *error = NULL;
657 unsigned int ssid_len;
660 DBG("service %p", service);
662 keyfile = connman_storage_load_service(service->identifier);
664 service->new_service = true;
667 service->new_service = false;
669 switch (service->type) {
670 case CONNMAN_SERVICE_TYPE_UNKNOWN:
671 case CONNMAN_SERVICE_TYPE_SYSTEM:
672 case CONNMAN_SERVICE_TYPE_GPS:
673 case CONNMAN_SERVICE_TYPE_P2P:
675 case CONNMAN_SERVICE_TYPE_VPN:
676 set_split_routing(service, g_key_file_get_boolean(keyfile,
678 "SplitRouting", NULL));
680 autoconnect = g_key_file_get_boolean(keyfile,
681 service->identifier, "AutoConnect", &error);
683 service->autoconnect = autoconnect;
684 g_clear_error(&error);
686 case CONNMAN_SERVICE_TYPE_WIFI:
687 if (!service->name) {
690 name = g_key_file_get_string(keyfile,
691 service->identifier, "Name", NULL);
693 g_free(service->name);
694 service->name = name;
697 if (service->network)
698 connman_network_set_name(service->network,
702 if (service->network &&
703 !connman_network_get_blob(service->network,
704 "WiFi.SSID", &ssid_len)) {
707 hex_ssid = g_key_file_get_string(keyfile,
713 unsigned int i, j = 0, hex;
714 size_t hex_ssid_len = strlen(hex_ssid);
716 ssid = g_try_malloc0(hex_ssid_len / 2);
723 for (i = 0; i < hex_ssid_len; i += 2) {
724 sscanf(hex_ssid + i, "%02x", &hex);
728 connman_network_set_blob(service->network,
729 "WiFi.SSID", ssid, hex_ssid_len / 2);
738 case CONNMAN_SERVICE_TYPE_GADGET:
739 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
740 case CONNMAN_SERVICE_TYPE_CELLULAR:
741 service->favorite = g_key_file_get_boolean(keyfile,
742 service->identifier, "Favorite", NULL);
746 case CONNMAN_SERVICE_TYPE_ETHERNET:
747 autoconnect = g_key_file_get_boolean(keyfile,
748 service->identifier, "AutoConnect", &error);
750 service->autoconnect = autoconnect;
751 g_clear_error(&error);
755 str = g_key_file_get_string(keyfile,
756 service->identifier, "Modified", NULL);
758 g_time_val_from_iso8601(str, &service->modified);
762 str = g_key_file_get_string(keyfile,
763 service->identifier, "Passphrase", NULL);
765 g_free(service->passphrase);
766 service->passphrase = str;
769 if (service->ipconfig_ipv4)
770 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
771 service->identifier, "IPv4.");
773 if (service->ipconfig_ipv6)
774 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
775 service->identifier, "IPv6.");
777 service->nameservers_config = g_key_file_get_string_list(keyfile,
778 service->identifier, "Nameservers", &length, NULL);
779 if (service->nameservers_config && length == 0) {
780 g_strfreev(service->nameservers_config);
781 service->nameservers_config = NULL;
787 dns_method = g_key_file_get_string(keyfile, service->identifier,
788 "Nameservers.IPv4method", NULL);
789 service->dns_config_method_ipv4 = __connman_dnsconfig_string2method(dns_method);
791 dns_method = g_key_file_get_string(keyfile, service->identifier,
792 "Nameservers.IPv6method", NULL);
793 service->dns_config_method_ipv6 = __connman_dnsconfig_string2method(dns_method);
796 service->timeservers_config = g_key_file_get_string_list(keyfile,
797 service->identifier, "Timeservers", &length, NULL);
798 if (service->timeservers_config && length == 0) {
799 g_strfreev(service->timeservers_config);
800 service->timeservers_config = NULL;
803 service->domains = g_key_file_get_string_list(keyfile,
804 service->identifier, "Domains", &length, NULL);
805 if (service->domains && length == 0) {
806 g_strfreev(service->domains);
807 service->domains = NULL;
810 str = g_key_file_get_string(keyfile,
811 service->identifier, "Proxy.Method", NULL);
813 service->proxy_config = string2proxymethod(str);
817 service->proxies = g_key_file_get_string_list(keyfile,
818 service->identifier, "Proxy.Servers", &length, NULL);
819 if (service->proxies && length == 0) {
820 g_strfreev(service->proxies);
821 service->proxies = NULL;
824 service->excludes = g_key_file_get_string_list(keyfile,
825 service->identifier, "Proxy.Excludes", &length, NULL);
826 if (service->excludes && length == 0) {
827 g_strfreev(service->excludes);
828 service->excludes = NULL;
831 str = g_key_file_get_string(keyfile,
832 service->identifier, "Proxy.URL", NULL);
834 g_free(service->pac);
838 service->hidden_service = g_key_file_get_boolean(keyfile,
839 service->identifier, "Hidden", NULL);
841 #if defined TIZEN_EXT
842 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
843 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
844 str = g_key_file_get_string(keyfile,
845 service->identifier, "EAP", NULL);
847 g_free(service->eap);
851 str = g_key_file_get_string(keyfile,
852 service->identifier, "Phase2", NULL);
854 g_free(service->phase2);
855 service->phase2 = str;
858 str = g_key_file_get_string(keyfile,
859 service->identifier, "Identity", NULL);
861 g_free(service->identity);
862 service->identity = str;
865 str = g_key_file_get_string(keyfile,
866 service->identifier, "CACertFile", NULL);
868 g_free(service->ca_cert_file);
869 service->ca_cert_file = str;
872 str = g_key_file_get_string(keyfile,
873 service->identifier, "ClientCertFile", NULL);
875 g_free(service->client_cert_file);
876 service->client_cert_file = str;
879 str = g_key_file_get_string(keyfile,
880 service->identifier, "PrivateKeyFile", NULL);
882 g_free(service->private_key_file);
883 service->private_key_file = str;
886 str = g_key_file_get_string(keyfile,
887 service->identifier, "PrivateKeyPassphrase", NULL);
889 g_free(service->private_key_passphrase);
890 service->private_key_passphrase = str;
895 if (g_key_file_has_key(keyfile, service->identifier, "UID", NULL))
896 service->user.favorite_user = g_key_file_get_integer(keyfile,
897 service->identifier, "UID", NULL);
899 g_key_file_free(keyfile);
904 static int service_save(struct connman_service *service)
909 const char *cst_str = NULL;
912 DBG("service %p new %d", service, service->new_service);
914 if (service->new_service)
917 keyfile = __connman_storage_open_service(service->identifier);
922 g_key_file_set_string(keyfile, service->identifier,
923 "Name", service->name);
925 switch (service->type) {
926 case CONNMAN_SERVICE_TYPE_UNKNOWN:
927 case CONNMAN_SERVICE_TYPE_SYSTEM:
928 case CONNMAN_SERVICE_TYPE_GPS:
929 case CONNMAN_SERVICE_TYPE_P2P:
931 case CONNMAN_SERVICE_TYPE_VPN:
932 g_key_file_set_boolean(keyfile, service->identifier,
933 "SplitRouting", service->do_split_routing);
934 if (service->favorite)
935 g_key_file_set_boolean(keyfile, service->identifier,
936 "AutoConnect", service->autoconnect);
938 case CONNMAN_SERVICE_TYPE_WIFI:
939 if (service->network) {
940 const unsigned char *ssid;
941 unsigned int ssid_len = 0;
943 if (service->user.favorite_user == USER_NONE)
944 g_key_file_remove_key(keyfile, service->identifier,
947 g_key_file_set_integer(keyfile, service->identifier,
948 "UID", service->user.favorite_user);
950 ssid = connman_network_get_blob(service->network,
951 "WiFi.SSID", &ssid_len);
953 if (ssid && ssid_len > 0 && ssid[0] != '\0') {
954 char *identifier = service->identifier;
958 ssid_str = g_string_sized_new(ssid_len * 2);
964 for (i = 0; i < ssid_len; i++)
965 g_string_append_printf(ssid_str,
968 g_key_file_set_string(keyfile, identifier,
969 "SSID", ssid_str->str);
971 g_string_free(ssid_str, TRUE);
974 freq = connman_network_get_frequency(service->network);
975 g_key_file_set_integer(keyfile, service->identifier,
980 case CONNMAN_SERVICE_TYPE_GADGET:
981 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
982 case CONNMAN_SERVICE_TYPE_CELLULAR:
983 g_key_file_set_boolean(keyfile, service->identifier,
984 "Favorite", service->favorite);
986 g_key_file_remove_key(keyfile, service->identifier,
991 case CONNMAN_SERVICE_TYPE_ETHERNET:
992 if (service->favorite)
993 g_key_file_set_boolean(keyfile, service->identifier,
994 "AutoConnect", service->autoconnect);
998 str = g_time_val_to_iso8601(&service->modified);
1000 g_key_file_set_string(keyfile, service->identifier,
1005 if (service->user.current_user == service->user.favorite_user) {
1006 if (service->passphrase && strlen(service->passphrase) > 0)
1007 g_key_file_set_string(keyfile, service->identifier,
1008 "Passphrase", service->passphrase);
1010 g_key_file_remove_key(keyfile, service->identifier,
1011 "Passphrase", NULL);
1014 if (service->ipconfig_ipv4)
1015 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
1016 service->identifier, "IPv4.");
1018 if (service->ipconfig_ipv6)
1019 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
1020 service->identifier, "IPv6.");
1022 if (service->nameservers_config) {
1023 guint len = g_strv_length(service->nameservers_config);
1025 g_key_file_set_string_list(keyfile, service->identifier,
1027 (const gchar **) service->nameservers_config, len);
1029 g_key_file_remove_key(keyfile, service->identifier,
1030 "Nameservers", NULL);
1032 #if defined TIZEN_EXT
1033 if(service->dns_config_method_ipv4 != 0) {
1035 method = __connman_dnsconfig_method2string(
1036 service->dns_config_method_ipv4);
1037 g_key_file_set_string(keyfile, service->identifier,
1038 "Nameservers.IPv4method", method);
1040 g_key_file_remove_key(keyfile, service->identifier,
1041 "Nameservers.IPv4method", NULL);
1043 if(service->dns_config_method_ipv6 != 0) {
1045 method = __connman_dnsconfig_method2string(
1046 service->dns_config_method_ipv6);
1047 g_key_file_set_string(keyfile, service->identifier,
1048 "Nameservers.IPv6method", method);
1050 g_key_file_remove_key(keyfile, service->identifier,
1051 "Nameservers.IPv6method", NULL);
1054 if (service->timeservers_config) {
1055 guint len = g_strv_length(service->timeservers_config);
1057 g_key_file_set_string_list(keyfile, service->identifier,
1059 (const gchar **) service->timeservers_config, len);
1061 g_key_file_remove_key(keyfile, service->identifier,
1062 "Timeservers", NULL);
1064 if (service->domains) {
1065 guint len = g_strv_length(service->domains);
1067 g_key_file_set_string_list(keyfile, service->identifier,
1069 (const gchar **) service->domains, len);
1071 g_key_file_remove_key(keyfile, service->identifier,
1074 cst_str = proxymethod2string(service->proxy_config);
1076 g_key_file_set_string(keyfile, service->identifier,
1077 "Proxy.Method", cst_str);
1079 if (service->proxies) {
1080 guint len = g_strv_length(service->proxies);
1082 g_key_file_set_string_list(keyfile, service->identifier,
1084 (const gchar **) service->proxies, len);
1086 g_key_file_remove_key(keyfile, service->identifier,
1087 "Proxy.Servers", NULL);
1089 if (service->excludes) {
1090 guint len = g_strv_length(service->excludes);
1092 g_key_file_set_string_list(keyfile, service->identifier,
1094 (const gchar **) service->excludes, len);
1096 g_key_file_remove_key(keyfile, service->identifier,
1097 "Proxy.Excludes", NULL);
1099 if (service->pac && strlen(service->pac) > 0)
1100 g_key_file_set_string(keyfile, service->identifier,
1101 "Proxy.URL", service->pac);
1103 g_key_file_remove_key(keyfile, service->identifier,
1106 if (service->hidden_service)
1107 g_key_file_set_boolean(keyfile, service->identifier, "Hidden",
1110 if (service->config_file && strlen(service->config_file) > 0)
1111 g_key_file_set_string(keyfile, service->identifier,
1112 "Config.file", service->config_file);
1114 if (service->config_entry &&
1115 strlen(service->config_entry) > 0)
1116 g_key_file_set_string(keyfile, service->identifier,
1117 "Config.ident", service->config_entry);
1119 #if defined TIZEN_EXT
1120 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1121 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
1122 if (service->eap != NULL && strlen(service->eap) > 0)
1123 g_key_file_set_string(keyfile, service->identifier,
1124 "EAP", service->eap);
1126 g_key_file_remove_key(keyfile, service->identifier,
1129 if (service->phase2 != NULL && strlen(service->phase2) > 0)
1130 g_key_file_set_string(keyfile, service->identifier,
1131 "Phase2", service->phase2);
1133 g_key_file_remove_key(keyfile, service->identifier,
1136 if (service->identity != NULL && strlen(service->identity) > 0)
1137 g_key_file_set_string(keyfile, service->identifier,
1138 "Identity", service->identity);
1140 g_key_file_remove_key(keyfile, service->identifier,
1143 if (service->ca_cert_file != NULL && strlen(service->ca_cert_file) > 0)
1144 g_key_file_set_string(keyfile, service->identifier,
1145 "CACertFile", service->ca_cert_file);
1147 g_key_file_remove_key(keyfile, service->identifier,
1148 "CACertFile", NULL);
1150 if (service->client_cert_file != NULL && strlen(service->client_cert_file) > 0)
1151 g_key_file_set_string(keyfile, service->identifier,
1152 "ClientCertFile", service->client_cert_file);
1154 g_key_file_remove_key(keyfile, service->identifier,
1155 "ClientCertFile", NULL);
1157 if (service->private_key_file != NULL && strlen(service->private_key_file) > 0)
1158 g_key_file_set_string(keyfile, service->identifier,
1159 "PrivateKeyFile", service->private_key_file);
1161 g_key_file_remove_key(keyfile, service->identifier,
1162 "PrivateKeyFile", NULL);
1164 if (service->private_key_passphrase != NULL && strlen(service->private_key_passphrase) > 0)
1165 g_key_file_set_string(keyfile, service->identifier,
1166 "PrivateKeyPassphrase", service->private_key_passphrase);
1168 g_key_file_remove_key(keyfile, service->identifier,
1169 "PrivateKeyPassphrase", NULL);
1174 __connman_storage_save_service(keyfile, service->identifier);
1176 g_key_file_free(keyfile);
1181 void __connman_service_save(struct connman_service *service)
1186 service_save(service);
1189 static enum connman_service_state combine_state(
1190 enum connman_service_state state_a,
1191 enum connman_service_state state_b)
1193 enum connman_service_state result;
1195 if (state_a == state_b) {
1200 if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
1205 if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
1210 if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
1215 if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
1220 if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
1225 if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
1230 if (state_a == CONNMAN_SERVICE_STATE_READY) {
1235 if (state_b == CONNMAN_SERVICE_STATE_READY) {
1240 if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1245 if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1250 if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1255 if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1260 if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
1265 if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
1270 result = CONNMAN_SERVICE_STATE_FAILURE;
1276 static bool is_connecting(enum connman_service_state state)
1279 case CONNMAN_SERVICE_STATE_UNKNOWN:
1280 case CONNMAN_SERVICE_STATE_IDLE:
1281 case CONNMAN_SERVICE_STATE_FAILURE:
1282 case CONNMAN_SERVICE_STATE_DISCONNECT:
1283 case CONNMAN_SERVICE_STATE_READY:
1284 case CONNMAN_SERVICE_STATE_ONLINE:
1286 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1287 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1294 static bool is_connected(enum connman_service_state state)
1297 case CONNMAN_SERVICE_STATE_UNKNOWN:
1298 case CONNMAN_SERVICE_STATE_IDLE:
1299 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1300 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1301 case CONNMAN_SERVICE_STATE_DISCONNECT:
1302 case CONNMAN_SERVICE_STATE_FAILURE:
1304 case CONNMAN_SERVICE_STATE_READY:
1305 case CONNMAN_SERVICE_STATE_ONLINE:
1312 static bool is_idle(enum connman_service_state state)
1315 case CONNMAN_SERVICE_STATE_IDLE:
1316 case CONNMAN_SERVICE_STATE_DISCONNECT:
1317 case CONNMAN_SERVICE_STATE_FAILURE:
1319 case CONNMAN_SERVICE_STATE_UNKNOWN:
1320 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1321 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1322 case CONNMAN_SERVICE_STATE_READY:
1323 case CONNMAN_SERVICE_STATE_ONLINE:
1330 static int nameservers_changed_cb(void *user_data)
1332 struct connman_service *service = user_data;
1334 DBG("service %p", service);
1336 service->nameservers_timeout = 0;
1337 if ((is_idle(service->state) && !service->nameservers) ||
1338 is_connected(service->state))
1339 dns_changed(service);
1344 static void nameservers_changed(struct connman_service *service)
1346 if (!service->nameservers_timeout)
1347 service->nameservers_timeout = g_idle_add(nameservers_changed_cb,
1351 static bool nameserver_available(struct connman_service *service,
1352 enum connman_ipconfig_type type,
1357 family = connman_inet_check_ipaddress(ns);
1359 if (family == AF_INET) {
1360 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1363 return is_connected(service->state_ipv4);
1366 if (family == AF_INET6) {
1367 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1370 return is_connected(service->state_ipv6);
1376 static int searchdomain_add_all(struct connman_service *service)
1380 if (!is_connected(service->state))
1383 index = __connman_service_get_index(service);
1387 if (service->domains) {
1388 while (service->domains[i]) {
1389 connman_resolver_append(index, service->domains[i],
1397 if (service->domainname)
1398 connman_resolver_append(index, service->domainname, NULL);
1404 static int searchdomain_remove_all(struct connman_service *service)
1408 if (!is_connected(service->state))
1411 index = __connman_service_get_index(service);
1415 while (service->domains && service->domains[i]) {
1416 connman_resolver_remove(index, service->domains[i], NULL);
1420 if (service->domainname)
1421 connman_resolver_remove(index, service->domainname, NULL);
1426 static int nameserver_add(struct connman_service *service,
1427 enum connman_ipconfig_type type,
1428 const char *nameserver)
1432 if (!nameserver_available(service, type, nameserver))
1435 index = __connman_service_get_index(service);
1439 #if defined TIZEN_EXT
1440 DBG("Resolver append nameserver: %s", nameserver);
1442 ret = connman_resolver_append(index, NULL, nameserver);
1444 nameservers_changed(service);
1449 static int nameserver_add_all(struct connman_service *service,
1450 enum connman_ipconfig_type type)
1454 if (service->nameservers_config) {
1455 while (service->nameservers_config[i]) {
1456 #if defined TIZEN_EXT
1457 DBG("type %d add service->nameservers_config[%d]:%s",type,
1458 i, service->nameservers_config[i]);
1459 if(strncmp(service->nameservers_config[i], "::", 2) == 0) {
1460 DBG("Invalid nameserver");
1466 case CONNMAN_IPCONFIG_TYPE_IPV4:
1467 if (connman_inet_check_ipaddress(
1468 service->nameservers_config[i]) == AF_INET &&
1469 service->dns_config_method_ipv4 ==
1470 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1471 nameserver_add(service, type,
1472 service->nameservers_config[i]);
1475 case CONNMAN_IPCONFIG_TYPE_IPV6:
1476 if (connman_inet_check_ipaddress(
1477 service->nameservers_config[i]) == AF_INET6 &&
1478 service->dns_config_method_ipv6 ==
1479 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1480 nameserver_add(service, type,
1481 service->nameservers_config[i]);
1484 case CONNMAN_IPCONFIG_TYPE_ALL:
1485 if (connman_inet_check_ipaddress(
1486 service->nameservers_config[i]) == AF_INET &&
1487 service->dns_config_method_ipv4 ==
1488 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1489 nameserver_add(service, type,
1490 service->nameservers_config[i]);
1492 if (connman_inet_check_ipaddress(
1493 service->nameservers_config[i]) == AF_INET6 &&
1494 service->dns_config_method_ipv6 ==
1495 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1496 nameserver_add(service, type,
1497 service->nameservers_config[i]);
1500 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1501 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1504 DBG("default case do nothing");
1508 nameserver_add(service, type,
1509 service->nameservers_config[i]);
1513 } else if (service->nameservers) {
1514 while (service->nameservers[i]) {
1515 #if defined TIZEN_EXT
1516 DBG("type %d service->nameservers[%d]: %s",type,
1517 i, service->nameservers[i]);
1520 case CONNMAN_IPCONFIG_TYPE_IPV4:
1521 if (connman_inet_check_ipaddress(
1522 service->nameservers[i]) == AF_INET &&
1523 service->dns_config_method_ipv4 ==
1524 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1525 nameserver_add(service, type,
1526 service->nameservers[i]);
1529 case CONNMAN_IPCONFIG_TYPE_IPV6:
1530 if (connman_inet_check_ipaddress(
1531 service->nameservers[i]) == AF_INET6 &&
1532 service->dns_config_method_ipv6 ==
1533 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1534 nameserver_add(service, type,
1535 service->nameservers[i]);
1538 case CONNMAN_IPCONFIG_TYPE_ALL:
1539 if (connman_inet_check_ipaddress(
1540 service->nameservers[i]) == AF_INET &&
1541 service->dns_config_method_ipv4 ==
1542 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1543 nameserver_add(service, type,
1544 service->nameservers[i]);
1546 if (connman_inet_check_ipaddress(
1547 service->nameservers[i]) == AF_INET6 &&
1548 service->dns_config_method_ipv6 ==
1549 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1550 nameserver_add(service, type,
1551 service->nameservers[i]);
1554 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1555 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1558 DBG("default case do nothing");
1562 nameserver_add(service, type,
1563 service->nameservers[i]);
1570 __connman_resolver_append_fallback_nameservers();
1572 searchdomain_add_all(service);
1577 static int nameserver_remove(struct connman_service *service,
1578 enum connman_ipconfig_type type,
1579 const char *nameserver)
1583 if (!nameserver_available(service, type, nameserver))
1586 index = __connman_service_get_index(service);
1590 #if defined TIZEN_EXT
1591 DBG("Resolver remove nameserver: %s", nameserver);
1593 ret = connman_resolver_remove(index, NULL, nameserver);
1595 nameservers_changed(service);
1600 static int nameserver_remove_all(struct connman_service *service,
1601 enum connman_ipconfig_type type)
1603 #if defined TIZEN_EXT
1605 * Skip this function if there is any connected profiles
1606 * that use same interface
1608 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
1609 __connman_service_get_connected_count_of_iface(service) > 0)
1614 index = __connman_service_get_index(service);
1618 while (service->nameservers_config && service->nameservers_config[i]) {
1619 #if defined TIZEN_EXT
1620 DBG("type %d Remove service->nameservers_config[%d]: %s",
1621 type, i, service->nameservers_config[i]);
1623 case CONNMAN_IPCONFIG_TYPE_IPV4:
1624 if (connman_inet_check_ipaddress(
1625 service->nameservers_config[i]) == AF_INET &&
1626 (service->dns_config_method_ipv4 ==
1627 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1628 service->dns_config_method_ipv4 ==
1629 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1630 nameserver_remove(service, type,
1631 service->nameservers_config[i]);
1634 case CONNMAN_IPCONFIG_TYPE_IPV6:
1635 if (connman_inet_check_ipaddress(
1636 service->nameservers_config[i]) == AF_INET6 &&
1637 (service->dns_config_method_ipv6 ==
1638 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1639 service->dns_config_method_ipv6 ==
1640 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1641 nameserver_remove(service, type,
1642 service->nameservers_config[i]);
1645 case CONNMAN_IPCONFIG_TYPE_ALL:
1646 if (connman_inet_check_ipaddress(
1647 service->nameservers_config[i]) == AF_INET &&
1648 (service->dns_config_method_ipv4 ==
1649 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1650 service->dns_config_method_ipv4 ==
1651 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1652 nameserver_remove(service, type,
1653 service->nameservers_config[i]);
1655 if (connman_inet_check_ipaddress(
1656 service->nameservers_config[i]) == AF_INET6 &&
1657 (service->dns_config_method_ipv6 ==
1658 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1659 service->dns_config_method_ipv6 ==
1660 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1661 nameserver_remove(service, type,
1662 service->nameservers_config[i]);
1665 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1666 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1669 DBG("default case do nothing");
1673 nameserver_remove(service, type,
1674 service->nameservers_config[i]);
1680 while (service->nameservers && service->nameservers[i]) {
1681 #if defined TIZEN_EXT
1682 DBG("type %d Remove service->nameservers[%d]: %s",type, i,
1683 service->nameservers[i]);
1685 case CONNMAN_IPCONFIG_TYPE_IPV4:
1686 if (connman_inet_check_ipaddress(
1687 service->nameservers[i]) == AF_INET &&
1688 (service->dns_config_method_ipv4 ==
1689 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1690 service->dns_config_method_ipv4 ==
1691 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1692 nameserver_remove(service, type,
1693 service->nameservers[i]);
1696 case CONNMAN_IPCONFIG_TYPE_IPV6:
1697 if (connman_inet_check_ipaddress(
1698 service->nameservers[i]) == AF_INET6 &&
1699 (service->dns_config_method_ipv6 ==
1700 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1701 service->dns_config_method_ipv6 ==
1702 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1703 nameserver_remove(service, type,
1704 service->nameservers[i]);
1707 case CONNMAN_IPCONFIG_TYPE_ALL:
1708 if (connman_inet_check_ipaddress(
1709 service->nameservers[i]) == AF_INET &&
1710 (service->dns_config_method_ipv4 ==
1711 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1712 service->dns_config_method_ipv4 ==
1713 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1714 nameserver_remove(service, type,
1715 service->nameservers[i]);
1717 if (connman_inet_check_ipaddress(
1718 service->nameservers[i]) == AF_INET6 &&
1719 (service->dns_config_method_ipv6 ==
1720 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1721 service->dns_config_method_ipv6 ==
1722 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1723 nameserver_remove(service, type,
1724 service->nameservers[i]);
1727 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1728 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1731 DBG("default case do nothing");
1735 nameserver_remove(service, type, service->nameservers[i]);
1740 searchdomain_remove_all(service);
1746 * The is_auto variable is set to true when IPv6 autoconf nameservers are
1747 * inserted to resolver via netlink message (see rtnl.c:rtnl_newnduseropt()
1748 * for details) and not through service.c
1750 #if defined TIZEN_EXT
1751 int __connman_service_nameserver_append(struct connman_service *service,
1752 const char *nameserver, bool is_auto,
1753 enum connman_ipconfig_type type)
1755 int __connman_service_nameserver_append(struct connman_service *service,
1756 const char *nameserver, bool is_auto)
1762 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1768 nameservers = service->nameservers_auto;
1770 nameservers = service->nameservers;
1772 for (i = 0; nameservers && nameservers[i]; i++)
1773 #if defined TIZEN_EXT
1775 DBG("nameservers[%d] %s, nameserver %s", i, nameservers[i], nameserver);
1777 if (g_strcmp0(nameservers[i], nameserver) == 0)
1779 #if defined TIZEN_EXT
1784 len = g_strv_length(nameservers);
1785 nameservers = g_try_renew(char *, nameservers, len + 2);
1788 nameservers = g_try_new0(char *, len + 2);
1794 nameservers[len] = g_strdup(nameserver);
1795 nameservers[len + 1] = NULL;
1798 if(type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
1799 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
1800 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
1802 if(type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
1803 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
1804 service->dns_config_method_ipv6 = CONNMAN_DNSCONFIG_METHOD_DHCP;
1808 service->nameservers_auto = nameservers;
1810 service->nameservers = nameservers;
1811 nameserver_add(service, CONNMAN_IPCONFIG_TYPE_ALL, nameserver);
1814 nameservers_changed(service);
1816 searchdomain_add_all(service);
1821 #if defined TIZEN_EXT
1822 int __connman_service_nameserver_remove(struct connman_service *service,
1823 const char *nameserver, bool is_auto,
1824 enum connman_ipconfig_type type)
1826 int __connman_service_nameserver_remove(struct connman_service *service,
1827 const char *nameserver, bool is_auto)
1830 char **servers, **nameservers;
1834 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1840 nameservers = service->nameservers_auto;
1842 nameservers = service->nameservers;
1847 for (i = 0; nameservers[i]; i++)
1848 if (g_strcmp0(nameservers[i], nameserver) == 0) {
1856 len = g_strv_length(nameservers);
1863 servers = g_try_new0(char *, len);
1867 for (i = 0, j = 0; i < len; i++) {
1868 if (g_strcmp0(nameservers[i], nameserver)) {
1869 servers[j] = nameservers[i];
1872 g_free(nameservers[i]);
1874 nameservers[i] = NULL;
1876 servers[len - 1] = NULL;
1879 g_strfreev(nameservers);
1880 nameservers = servers;
1883 service->nameservers_auto = nameservers;
1885 service->nameservers = nameservers;
1886 #if defined TIZEN_EXT
1887 DBG("nameserver remove ip_type: %d", type);
1888 nameserver_remove(service, type,
1891 nameserver_remove(service, CONNMAN_IPCONFIG_TYPE_ALL,
1899 void __connman_service_nameserver_clear(struct connman_service *service)
1901 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
1903 g_strfreev(service->nameservers);
1904 service->nameservers = NULL;
1906 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
1909 static void add_nameserver_route(int family, int index, char *nameserver,
1914 if (connman_inet_compare_subnet(index, nameserver))
1917 if (connman_inet_add_host_route(index, nameserver, gw) < 0)
1918 /* For P-t-P link the above route add will fail */
1919 connman_inet_add_host_route(index, nameserver, NULL);
1923 if (connman_inet_add_ipv6_host_route(index, nameserver,
1925 connman_inet_add_ipv6_host_route(index, nameserver,
1931 static void nameserver_add_routes(int index, char **nameservers,
1934 int i, ns_family, gw_family;
1936 gw_family = connman_inet_check_ipaddress(gw);
1940 for (i = 0; nameservers[i]; i++) {
1941 ns_family = connman_inet_check_ipaddress(nameservers[i]);
1942 if (ns_family < 0 || ns_family != gw_family)
1945 add_nameserver_route(ns_family, index, nameservers[i], gw);
1949 static void nameserver_del_routes(int index, char **nameservers,
1950 enum connman_ipconfig_type type)
1954 for (i = 0; nameservers[i]; i++) {
1955 family = connman_inet_check_ipaddress(nameservers[i]);
1961 if (type != CONNMAN_IPCONFIG_TYPE_IPV6)
1962 connman_inet_del_host_route(index,
1966 if (type != CONNMAN_IPCONFIG_TYPE_IPV4)
1967 connman_inet_del_ipv6_host_route(index,
1974 void __connman_service_nameserver_add_routes(struct connman_service *service,
1982 index = __connman_service_get_index(service);
1984 if (service->nameservers_config) {
1986 * Configured nameserver takes preference over the
1987 * discoverd nameserver gathered from DHCP, VPN, etc.
1989 nameserver_add_routes(index, service->nameservers_config, gw);
1990 } else if (service->nameservers) {
1992 * We add nameservers host routes for nameservers that
1993 * are not on our subnet. For those who are, the subnet
1994 * route will be installed by the time the dns proxy code
1995 * tries to reach them. The subnet route is installed
1996 * when setting the interface IP address.
1998 nameserver_add_routes(index, service->nameservers, gw);
2002 void __connman_service_nameserver_del_routes(struct connman_service *service,
2003 enum connman_ipconfig_type type)
2010 index = __connman_service_get_index(service);
2012 if (service->nameservers_config)
2013 nameserver_del_routes(index, service->nameservers_config,
2015 else if (service->nameservers)
2016 nameserver_del_routes(index, service->nameservers, type);
2019 static void address_updated(struct connman_service *service,
2020 enum connman_ipconfig_type type)
2022 if (is_connected(service->state) &&
2023 service == __connman_service_get_default()) {
2024 nameserver_remove_all(service, type);
2025 nameserver_add_all(service, type);
2027 __connman_timeserver_sync(service);
2031 static struct connman_stats *stats_get(struct connman_service *service)
2033 if (service->roaming)
2034 return &service->stats_roaming;
2036 return &service->stats;
2039 static bool stats_enabled(struct connman_service *service)
2041 struct connman_stats *stats = stats_get(service);
2043 return stats->enabled;
2046 static void stats_start(struct connman_service *service)
2048 struct connman_stats *stats = stats_get(service);
2050 DBG("service %p", service);
2055 stats->enabled = true;
2056 stats->data_last.time = stats->data.time;
2058 g_timer_start(stats->timer);
2061 static void stats_stop(struct connman_service *service)
2063 struct connman_stats *stats = stats_get(service);
2064 unsigned int seconds;
2066 DBG("service %p", service);
2071 if (!stats->enabled)
2074 g_timer_stop(stats->timer);
2076 seconds = g_timer_elapsed(stats->timer, NULL);
2077 stats->data.time = stats->data_last.time + seconds;
2079 stats->enabled = false;
2082 static void reset_stats(struct connman_service *service)
2084 DBG("service %p", service);
2087 service->stats.valid = false;
2089 service->stats.data.rx_packets = 0;
2090 service->stats.data.tx_packets = 0;
2091 service->stats.data.rx_bytes = 0;
2092 service->stats.data.tx_bytes = 0;
2093 service->stats.data.rx_errors = 0;
2094 service->stats.data.tx_errors = 0;
2095 service->stats.data.rx_dropped = 0;
2096 service->stats.data.tx_dropped = 0;
2097 service->stats.data.time = 0;
2098 service->stats.data_last.time = 0;
2100 g_timer_reset(service->stats.timer);
2103 service->stats_roaming.valid = false;
2105 service->stats_roaming.data.rx_packets = 0;
2106 service->stats_roaming.data.tx_packets = 0;
2107 service->stats_roaming.data.rx_bytes = 0;
2108 service->stats_roaming.data.tx_bytes = 0;
2109 service->stats_roaming.data.rx_errors = 0;
2110 service->stats_roaming.data.tx_errors = 0;
2111 service->stats_roaming.data.rx_dropped = 0;
2112 service->stats_roaming.data.tx_dropped = 0;
2113 service->stats_roaming.data.time = 0;
2114 service->stats_roaming.data_last.time = 0;
2116 g_timer_reset(service->stats_roaming.timer);
2119 #if defined TIZEN_EXT
2120 static gboolean __connman_service_is_internet_profile(
2121 struct connman_service *cellular)
2123 const char internet_suffix[] = "_1";
2125 DBG("Service path: %s", cellular->path);
2127 if (g_str_has_suffix(cellular->path, internet_suffix) == TRUE)
2133 static gboolean __connman_service_is_tethering_profile(
2134 struct connman_service *cellular)
2136 const char tethering_suffix[] = "_5";
2138 DBG("Service path: %s", cellular->path);
2140 if (g_str_has_suffix(cellular->path, tethering_suffix) == TRUE)
2146 struct connman_service *connman_service_get_default_connection(void)
2149 struct connman_service *service;
2150 struct connman_service *default_service = NULL;
2152 for (list = service_list; list; list = list->next) {
2153 service = list->data;
2155 DBG("service: %p %s %s %s", service, service->name,
2156 state2string(service->state),
2157 __connman_service_type2string(service->type));
2159 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
2160 is_connected(service->state) == TRUE) {
2162 } else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
2163 __connman_service_is_internet_profile(service) == TRUE) {
2164 if (default_service == NULL)
2165 default_service = service;
2166 else if (is_connected(service->state) == TRUE &&
2167 is_connected(default_service->state) == FALSE)
2168 default_service = service;
2169 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET &&
2170 is_connected(service->state) == TRUE) {
2171 if (default_service == NULL)
2172 default_service = service;
2173 } else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH &&
2174 is_connected(service->state) == TRUE) {
2175 if (default_service == NULL)
2176 default_service = service;
2180 return default_service;
2184 struct connman_service *__connman_service_get_default(void)
2186 struct connman_service *service;
2191 service = service_list->data;
2193 if (!is_connected(service->state))
2199 bool __connman_service_index_is_default(int index)
2201 struct connman_service *service;
2206 service = __connman_service_get_default();
2208 return __connman_service_get_index(service) == index;
2211 static void default_changed(void)
2213 struct connman_service *service = __connman_service_get_default();
2215 if (service == current_default)
2218 DBG("current default %p %s", current_default,
2219 current_default ? current_default->identifier : "");
2220 DBG("new default %p %s", service, service ? service->identifier : "");
2222 #if defined TIZEN_EXT
2223 current_default = service;
2225 __connman_service_timeserver_changed(service, NULL);
2227 __connman_service_timeserver_changed(current_default, NULL);
2229 current_default = service;
2233 if (service->hostname &&
2234 connman_setting_get_bool("AllowHostnameUpdates"))
2235 __connman_utsname_set_hostname(service->hostname);
2237 if (service->domainname)
2238 __connman_utsname_set_domainname(service->domainname);
2241 __connman_notifier_default_changed(service);
2244 static void state_changed(struct connman_service *service)
2248 __connman_notifier_service_state_changed(service, service->state);
2250 str = state2string(service->state);
2254 #if !defined TIZEN_EXT
2255 if (!allow_property_changed(service))
2258 #if defined TIZEN_EXT
2259 DBG(" %s, %s", str, service->path);
2261 connman_dbus_property_changed_basic(service->path,
2262 CONNMAN_SERVICE_INTERFACE, "State",
2263 DBUS_TYPE_STRING, &str);
2266 static void strength_changed(struct connman_service *service)
2268 if (service->strength == 0)
2271 if (!allow_property_changed(service))
2274 connman_dbus_property_changed_basic(service->path,
2275 CONNMAN_SERVICE_INTERFACE, "Strength",
2276 DBUS_TYPE_BYTE, &service->strength);
2279 static void favorite_changed(struct connman_service *service)
2281 dbus_bool_t favorite;
2286 if (!allow_property_changed(service))
2289 favorite = service->favorite;
2290 connman_dbus_property_changed_basic(service->path,
2291 CONNMAN_SERVICE_INTERFACE, "Favorite",
2292 DBUS_TYPE_BOOLEAN, &favorite);
2295 static void immutable_changed(struct connman_service *service)
2297 dbus_bool_t immutable;
2302 if (!allow_property_changed(service))
2305 immutable = service->immutable;
2306 connman_dbus_property_changed_basic(service->path,
2307 CONNMAN_SERVICE_INTERFACE, "Immutable",
2308 DBUS_TYPE_BOOLEAN, &immutable);
2311 static void roaming_changed(struct connman_service *service)
2313 dbus_bool_t roaming;
2318 if (!allow_property_changed(service))
2321 roaming = service->roaming;
2322 connman_dbus_property_changed_basic(service->path,
2323 CONNMAN_SERVICE_INTERFACE, "Roaming",
2324 DBUS_TYPE_BOOLEAN, &roaming);
2327 static void autoconnect_changed(struct connman_service *service)
2329 dbus_bool_t autoconnect;
2334 if (!allow_property_changed(service))
2337 autoconnect = service->autoconnect;
2338 connman_dbus_property_changed_basic(service->path,
2339 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
2340 DBUS_TYPE_BOOLEAN, &autoconnect);
2343 static void append_security(DBusMessageIter *iter, void *user_data)
2345 struct connman_service *service = user_data;
2348 str = security2string(service->security);
2350 dbus_message_iter_append_basic(iter,
2351 DBUS_TYPE_STRING, &str);
2354 * Some access points incorrectly advertise WPS even when they
2355 * are configured as open or no security, so filter
2359 switch (service->security) {
2360 case CONNMAN_SERVICE_SECURITY_PSK:
2361 case CONNMAN_SERVICE_SECURITY_WPA:
2362 case CONNMAN_SERVICE_SECURITY_RSN:
2364 dbus_message_iter_append_basic(iter,
2365 DBUS_TYPE_STRING, &str);
2367 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
2368 case CONNMAN_SERVICE_SECURITY_NONE:
2369 case CONNMAN_SERVICE_SECURITY_WEP:
2370 case CONNMAN_SERVICE_SECURITY_8021X:
2376 static void append_ethernet(DBusMessageIter *iter, void *user_data)
2378 struct connman_service *service = user_data;
2380 if (service->ipconfig_ipv4)
2381 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
2383 else if (service->ipconfig_ipv6)
2384 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
2388 static void append_ipv4(DBusMessageIter *iter, void *user_data)
2390 struct connman_service *service = user_data;
2392 if (!is_connected(service->state_ipv4))
2395 if (service->ipconfig_ipv4)
2396 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
2399 static void append_ipv6(DBusMessageIter *iter, void *user_data)
2401 struct connman_service *service = user_data;
2403 if (!is_connected(service->state_ipv6))
2406 if (service->ipconfig_ipv6)
2407 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
2408 service->ipconfig_ipv4);
2411 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
2413 struct connman_service *service = user_data;
2415 if (service->ipconfig_ipv4)
2416 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
2420 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
2422 struct connman_service *service = user_data;
2424 if (service->ipconfig_ipv6)
2425 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
2429 static void append_nameservers(DBusMessageIter *iter,
2430 struct connman_service *service, char **servers)
2433 bool available = true;
2435 for (i = 0; servers[i]; i++) {
2437 available = nameserver_available(service,
2438 CONNMAN_IPCONFIG_TYPE_ALL,
2442 dbus_message_iter_append_basic(iter,
2443 DBUS_TYPE_STRING, &servers[i]);
2447 #if defined TIZEN_EXT
2448 static void append_nameserver_manual(DBusMessageIter *iter,
2449 struct connman_service *service, const char *server)
2451 bool available = true;
2454 available = nameserver_available(service,
2455 CONNMAN_IPCONFIG_TYPE_ALL, server);
2458 dbus_message_iter_append_basic(iter,
2459 DBUS_TYPE_STRING, &server);
2462 static void append_nameserver_dhcp(DBusMessageIter *iter,
2463 struct connman_service *service, const char *server)
2465 bool available = true;
2468 available = nameserver_available(service,
2469 CONNMAN_IPCONFIG_TYPE_ALL, server);
2472 dbus_message_iter_append_basic(iter,
2473 DBUS_TYPE_STRING, &server);
2477 static void append_dns(DBusMessageIter *iter, void *user_data)
2479 struct connman_service *service = user_data;
2480 #if defined TIZEN_EXT
2484 if (!is_connected(service->state))
2490 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
2492 char *str1 = g_strdup_printf("ipv4.%s", str);
2493 dbus_message_iter_append_basic(iter,
2494 DBUS_TYPE_STRING, &str1);
2498 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
2500 char *str1 = g_strdup_printf("ipv6.%s", str);
2501 dbus_message_iter_append_basic(iter,
2502 DBUS_TYPE_STRING, &str1);
2507 if (service->nameservers_config) {
2508 #if defined TIZEN_EXT
2510 while (service->nameservers_config[i]) {
2511 if (connman_inet_check_ipaddress(
2512 service->nameservers_config[i]) == AF_INET &&
2513 service->dns_config_method_ipv4 ==
2514 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2515 append_nameserver_manual(iter, service,
2516 service->nameservers_config[i]);
2519 if (connman_inet_check_ipaddress(
2520 service->nameservers_config[i]) == AF_INET6 &&
2521 service->dns_config_method_ipv6 ==
2522 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2523 append_nameserver_manual(iter, service,
2524 service->nameservers_config[i]);
2528 /* In case of mixed DNS Config Type one of IPv4/IPv6 can be
2529 * dynamic while other is static so try to append the DNS
2530 * Address which is dynamic also */
2531 if (service->nameservers != NULL) {
2533 while (service->nameservers[i]) {
2534 if (connman_inet_check_ipaddress(
2535 service->nameservers[i]) == AF_INET &&
2536 service->dns_config_method_ipv4 ==
2537 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2538 append_nameserver_dhcp(iter, service,
2539 service->nameservers[i]);
2542 if (connman_inet_check_ipaddress(
2543 service->nameservers[i]) == AF_INET6 &&
2544 service->dns_config_method_ipv6 ==
2545 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2546 append_nameserver_dhcp(iter, service,
2547 service->nameservers[i]);
2553 append_nameservers(iter, service, service->nameservers_config);
2557 if (service->nameservers)
2558 #if defined TIZEN_EXT
2561 while (service->nameservers[i]) {
2562 if (connman_inet_check_ipaddress(
2563 service->nameservers[i]) == AF_INET &&
2564 service->dns_config_method_ipv4 ==
2565 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2566 append_nameserver_dhcp(iter, service,
2567 service->nameservers[i]);
2570 if (connman_inet_check_ipaddress(
2571 service->nameservers[i]) == AF_INET6 &&
2572 service->dns_config_method_ipv6 ==
2573 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2574 append_nameserver_dhcp(iter, service,
2575 service->nameservers[i]);
2581 append_nameservers(iter, service,
2582 service->nameservers);
2585 if (service->nameservers_auto)
2586 append_nameservers(iter, service,
2587 service->nameservers_auto);
2589 if (!service->nameservers && !service->nameservers_auto) {
2592 DBG("append fallback nameservers");
2594 ns = connman_setting_get_string_list("FallbackNameservers");
2596 append_nameservers(iter, service, ns);
2601 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
2603 struct connman_service *service = user_data;
2606 /* Append DNS Config Type */
2608 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
2610 char *str1 = g_strdup_printf("ipv4.%s", str);
2611 dbus_message_iter_append_basic(iter,
2612 DBUS_TYPE_STRING, &str1);
2616 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
2618 char *str1 = g_strdup_printf("ipv6.%s", str);
2619 dbus_message_iter_append_basic(iter,
2620 DBUS_TYPE_STRING, &str1);
2625 if (!service->nameservers_config)
2628 #if defined TIZEN_EXT
2630 while (service->nameservers_config[i]) {
2631 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET &&
2632 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2633 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
2636 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET6 &&
2637 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2638 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
2643 append_nameservers(iter, NULL, service->nameservers_config);
2647 static void append_ts(DBusMessageIter *iter, void *user_data)
2649 GSList *list = user_data;
2652 char *timeserver = list->data;
2655 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
2658 list = g_slist_next(list);
2662 static void append_tsconfig(DBusMessageIter *iter, void *user_data)
2664 struct connman_service *service = user_data;
2667 if (!service->timeservers_config)
2670 for (i = 0; service->timeservers_config[i]; i++) {
2671 dbus_message_iter_append_basic(iter,
2673 &service->timeservers_config[i]);
2677 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
2679 struct connman_service *service = user_data;
2682 if (!service->domains)
2685 for (i = 0; service->domains[i]; i++)
2686 dbus_message_iter_append_basic(iter,
2687 DBUS_TYPE_STRING, &service->domains[i]);
2690 static void append_domain(DBusMessageIter *iter, void *user_data)
2692 struct connman_service *service = user_data;
2694 if (!is_connected(service->state) &&
2695 !is_connecting(service->state))
2698 if (service->domains)
2699 append_domainconfig(iter, user_data);
2700 else if (service->domainname)
2701 dbus_message_iter_append_basic(iter,
2702 DBUS_TYPE_STRING, &service->domainname);
2705 static void append_proxies(DBusMessageIter *iter, void *user_data)
2707 struct connman_service *service = user_data;
2710 if (!service->proxies)
2713 for (i = 0; service->proxies[i]; i++)
2714 dbus_message_iter_append_basic(iter,
2715 DBUS_TYPE_STRING, &service->proxies[i]);
2718 static void append_excludes(DBusMessageIter *iter, void *user_data)
2720 struct connman_service *service = user_data;
2723 if (!service->excludes)
2726 for (i = 0; service->excludes[i]; i++)
2727 dbus_message_iter_append_basic(iter,
2728 DBUS_TYPE_STRING, &service->excludes[i]);
2731 static void append_proxy(DBusMessageIter *iter, void *user_data)
2733 struct connman_service *service = user_data;
2734 enum connman_service_proxy_method proxy;
2735 const char *pac = NULL;
2736 const char *method = proxymethod2string(
2737 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
2739 if (!is_connected(service->state))
2742 proxy = connman_service_get_proxy_method(service);
2745 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2747 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2749 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2750 connman_dbus_dict_append_array(iter, "Servers",
2751 DBUS_TYPE_STRING, append_proxies,
2754 connman_dbus_dict_append_array(iter, "Excludes",
2755 DBUS_TYPE_STRING, append_excludes,
2758 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2759 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
2760 if (service->ipconfig_ipv4)
2761 pac = __connman_ipconfig_get_proxy_autoconfig(
2762 service->ipconfig_ipv4);
2763 else if (service->ipconfig_ipv6)
2764 pac = __connman_ipconfig_get_proxy_autoconfig(
2765 service->ipconfig_ipv6);
2767 if (!service->pac && !pac)
2773 connman_dbus_dict_append_basic(iter, "URL",
2774 DBUS_TYPE_STRING, &pac);
2778 method = proxymethod2string(proxy);
2781 connman_dbus_dict_append_basic(iter, "Method",
2782 DBUS_TYPE_STRING, &method);
2785 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
2787 struct connman_service *service = user_data;
2790 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
2793 switch (service->proxy_config) {
2794 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2796 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2798 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2799 if (service->proxies)
2800 connman_dbus_dict_append_array(iter, "Servers",
2802 append_proxies, service);
2804 if (service->excludes)
2805 connman_dbus_dict_append_array(iter, "Excludes",
2807 append_excludes, service);
2809 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2811 connman_dbus_dict_append_basic(iter, "URL",
2812 DBUS_TYPE_STRING, &service->pac);
2816 method = proxymethod2string(service->proxy_config);
2818 connman_dbus_dict_append_basic(iter, "Method",
2819 DBUS_TYPE_STRING, &method);
2822 static void append_provider(DBusMessageIter *iter, void *user_data)
2824 struct connman_service *service = user_data;
2826 if (!is_connected(service->state))
2829 if (service->provider)
2830 __connman_provider_append_properties(service->provider, iter);
2834 static void settings_changed(struct connman_service *service,
2835 struct connman_ipconfig *ipconfig)
2837 enum connman_ipconfig_type type;
2839 type = __connman_ipconfig_get_config_type(ipconfig);
2841 __connman_notifier_ipconfig_changed(service, ipconfig);
2843 if (!allow_property_changed(service))
2846 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
2847 connman_dbus_property_changed_dict(service->path,
2848 CONNMAN_SERVICE_INTERFACE, "IPv4",
2849 append_ipv4, service);
2850 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2851 connman_dbus_property_changed_dict(service->path,
2852 CONNMAN_SERVICE_INTERFACE, "IPv6",
2853 append_ipv6, service);
2856 static void ipv4_configuration_changed(struct connman_service *service)
2858 if (!allow_property_changed(service))
2861 connman_dbus_property_changed_dict(service->path,
2862 CONNMAN_SERVICE_INTERFACE,
2863 "IPv4.Configuration",
2868 void __connman_service_notify_ipv4_configuration(
2869 struct connman_service *service)
2874 ipv4_configuration_changed(service);
2877 static void ipv6_configuration_changed(struct connman_service *service)
2879 if (!allow_property_changed(service))
2882 connman_dbus_property_changed_dict(service->path,
2883 CONNMAN_SERVICE_INTERFACE,
2884 "IPv6.Configuration",
2889 static void dns_changed(struct connman_service *service)
2891 if (!allow_property_changed(service))
2894 connman_dbus_property_changed_array(service->path,
2895 CONNMAN_SERVICE_INTERFACE, "Nameservers",
2896 DBUS_TYPE_STRING, append_dns, service);
2899 static void dns_configuration_changed(struct connman_service *service)
2901 if (!allow_property_changed(service))
2904 connman_dbus_property_changed_array(service->path,
2905 CONNMAN_SERVICE_INTERFACE,
2906 "Nameservers.Configuration",
2907 DBUS_TYPE_STRING, append_dnsconfig, service);
2909 dns_changed(service);
2912 static void domain_changed(struct connman_service *service)
2914 if (!allow_property_changed(service))
2917 connman_dbus_property_changed_array(service->path,
2918 CONNMAN_SERVICE_INTERFACE, "Domains",
2919 DBUS_TYPE_STRING, append_domain, service);
2922 static void domain_configuration_changed(struct connman_service *service)
2924 if (!allow_property_changed(service))
2927 connman_dbus_property_changed_array(service->path,
2928 CONNMAN_SERVICE_INTERFACE,
2929 "Domains.Configuration",
2930 DBUS_TYPE_STRING, append_domainconfig, service);
2933 static void proxy_changed(struct connman_service *service)
2935 if (!allow_property_changed(service))
2938 connman_dbus_property_changed_dict(service->path,
2939 CONNMAN_SERVICE_INTERFACE, "Proxy",
2940 append_proxy, service);
2943 static void proxy_configuration_changed(struct connman_service *service)
2945 if (!allow_property_changed(service))
2948 connman_dbus_property_changed_dict(service->path,
2949 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
2950 append_proxyconfig, service);
2952 proxy_changed(service);
2955 static void timeservers_configuration_changed(struct connman_service *service)
2957 if (!allow_property_changed(service))
2960 connman_dbus_property_changed_array(service->path,
2961 CONNMAN_SERVICE_INTERFACE,
2962 "Timeservers.Configuration",
2964 append_tsconfig, service);
2967 static void link_changed(struct connman_service *service)
2969 if (!allow_property_changed(service))
2972 connman_dbus_property_changed_dict(service->path,
2973 CONNMAN_SERVICE_INTERFACE, "Ethernet",
2974 append_ethernet, service);
2977 static void stats_append_counters(DBusMessageIter *dict,
2978 struct connman_stats_data *stats,
2979 struct connman_stats_data *counters,
2982 if (counters->rx_packets != stats->rx_packets || append_all) {
2983 counters->rx_packets = stats->rx_packets;
2984 connman_dbus_dict_append_basic(dict, "RX.Packets",
2985 DBUS_TYPE_UINT32, &stats->rx_packets);
2988 if (counters->tx_packets != stats->tx_packets || append_all) {
2989 counters->tx_packets = stats->tx_packets;
2990 connman_dbus_dict_append_basic(dict, "TX.Packets",
2991 DBUS_TYPE_UINT32, &stats->tx_packets);
2994 if (counters->rx_bytes != stats->rx_bytes || append_all) {
2995 counters->rx_bytes = stats->rx_bytes;
2996 connman_dbus_dict_append_basic(dict, "RX.Bytes",
2997 DBUS_TYPE_UINT32, &stats->rx_bytes);
3000 if (counters->tx_bytes != stats->tx_bytes || append_all) {
3001 counters->tx_bytes = stats->tx_bytes;
3002 connman_dbus_dict_append_basic(dict, "TX.Bytes",
3003 DBUS_TYPE_UINT32, &stats->tx_bytes);
3006 if (counters->rx_errors != stats->rx_errors || append_all) {
3007 counters->rx_errors = stats->rx_errors;
3008 connman_dbus_dict_append_basic(dict, "RX.Errors",
3009 DBUS_TYPE_UINT32, &stats->rx_errors);
3012 if (counters->tx_errors != stats->tx_errors || append_all) {
3013 counters->tx_errors = stats->tx_errors;
3014 connman_dbus_dict_append_basic(dict, "TX.Errors",
3015 DBUS_TYPE_UINT32, &stats->tx_errors);
3018 if (counters->rx_dropped != stats->rx_dropped || append_all) {
3019 counters->rx_dropped = stats->rx_dropped;
3020 connman_dbus_dict_append_basic(dict, "RX.Dropped",
3021 DBUS_TYPE_UINT32, &stats->rx_dropped);
3024 if (counters->tx_dropped != stats->tx_dropped || append_all) {
3025 counters->tx_dropped = stats->tx_dropped;
3026 connman_dbus_dict_append_basic(dict, "TX.Dropped",
3027 DBUS_TYPE_UINT32, &stats->tx_dropped);
3030 if (counters->time != stats->time || append_all) {
3031 counters->time = stats->time;
3032 connman_dbus_dict_append_basic(dict, "Time",
3033 DBUS_TYPE_UINT32, &stats->time);
3037 static void stats_append(struct connman_service *service,
3038 const char *counter,
3039 struct connman_stats_counter *counters,
3042 DBusMessageIter array, dict;
3045 DBG("service %p counter %s", service, counter);
3047 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
3051 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
3052 &service->path, DBUS_TYPE_INVALID);
3054 dbus_message_iter_init_append(msg, &array);
3057 connman_dbus_dict_open(&array, &dict);
3059 stats_append_counters(&dict, &service->stats.data,
3060 &counters->stats.data, append_all);
3062 connman_dbus_dict_close(&array, &dict);
3064 /* roaming counter */
3065 connman_dbus_dict_open(&array, &dict);
3067 stats_append_counters(&dict, &service->stats_roaming.data,
3068 &counters->stats_roaming.data, append_all);
3070 connman_dbus_dict_close(&array, &dict);
3072 __connman_counter_send_usage(counter, msg);
3075 static void stats_update(struct connman_service *service,
3076 unsigned int rx_packets, unsigned int tx_packets,
3077 unsigned int rx_bytes, unsigned int tx_bytes,
3078 unsigned int rx_errors, unsigned int tx_errors,
3079 unsigned int rx_dropped, unsigned int tx_dropped)
3081 struct connman_stats *stats = stats_get(service);
3082 struct connman_stats_data *data_last = &stats->data_last;
3083 struct connman_stats_data *data = &stats->data;
3084 unsigned int seconds;
3086 DBG("service %p", service);
3090 rx_packets - data_last->rx_packets;
3092 tx_packets - data_last->tx_packets;
3094 rx_bytes - data_last->rx_bytes;
3096 tx_bytes - data_last->tx_bytes;
3098 rx_errors - data_last->rx_errors;
3100 tx_errors - data_last->tx_errors;
3102 rx_dropped - data_last->rx_dropped;
3104 tx_dropped - data_last->tx_dropped;
3106 stats->valid = true;
3109 data_last->rx_packets = rx_packets;
3110 data_last->tx_packets = tx_packets;
3111 data_last->rx_bytes = rx_bytes;
3112 data_last->tx_bytes = tx_bytes;
3113 data_last->rx_errors = rx_errors;
3114 data_last->tx_errors = tx_errors;
3115 data_last->rx_dropped = rx_dropped;
3116 data_last->tx_dropped = tx_dropped;
3118 seconds = g_timer_elapsed(stats->timer, NULL);
3119 stats->data.time = stats->data_last.time + seconds;
3122 void __connman_service_notify(struct connman_service *service,
3123 unsigned int rx_packets, unsigned int tx_packets,
3124 unsigned int rx_bytes, unsigned int tx_bytes,
3125 unsigned int rx_errors, unsigned int tx_errors,
3126 unsigned int rx_dropped, unsigned int tx_dropped)
3128 GHashTableIter iter;
3129 gpointer key, value;
3130 const char *counter;
3131 struct connman_stats_counter *counters;
3132 struct connman_stats_data *data;
3138 if (!is_connected(service->state))
3141 stats_update(service,
3142 rx_packets, tx_packets,
3144 rx_errors, tx_errors,
3145 rx_dropped, tx_dropped);
3147 data = &stats_get(service)->data;
3148 err = __connman_stats_update(service, service->roaming, data);
3150 connman_error("Failed to store statistics for %s",
3151 service->identifier);
3153 g_hash_table_iter_init(&iter, service->counter_table);
3154 while (g_hash_table_iter_next(&iter, &key, &value)) {
3158 stats_append(service, counter, counters, counters->append_all);
3159 counters->append_all = false;
3163 int __connman_service_counter_register(const char *counter)
3165 struct connman_service *service;
3167 struct connman_stats_counter *counters;
3169 DBG("counter %s", counter);
3171 counter_list = g_slist_prepend(counter_list, (gpointer)counter);
3173 for (list = service_list; list; list = list->next) {
3174 service = list->data;
3176 counters = g_try_new0(struct connman_stats_counter, 1);
3180 counters->append_all = true;
3182 g_hash_table_replace(service->counter_table, (gpointer)counter,
3189 void __connman_service_counter_unregister(const char *counter)
3191 struct connman_service *service;
3194 DBG("counter %s", counter);
3196 for (list = service_list; list; list = list->next) {
3197 service = list->data;
3199 g_hash_table_remove(service->counter_table, counter);
3202 counter_list = g_slist_remove(counter_list, counter);
3205 int __connman_service_iterate_services(service_iterate_cb cb, void *user_data)
3209 for (list = service_list; list; list = list->next) {
3210 struct connman_service *service = list->data;
3212 cb(service, user_data);
3218 #if defined TIZEN_EXT
3219 static void append_wifi_ext_info(DBusMessageIter *dict,
3220 struct connman_network *network)
3222 char bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
3223 char *bssid_str = bssid_buff;
3225 unsigned int ssid_len;
3226 unsigned char *bssid;
3227 unsigned int maxrate;
3228 unsigned int keymgmt;
3230 const char *enc_mode;
3233 char country_code_buff[WIFI_COUNTRY_CODE_LEN + 1] = {0,};
3234 char *country_code_str = country_code_buff;
3235 unsigned char *country_code;
3237 ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
3238 bssid = connman_network_get_bssid(network);
3239 maxrate = connman_network_get_maxrate(network);
3240 frequency = connman_network_get_frequency(network);
3241 enc_mode = connman_network_get_enc_mode(network);
3242 passpoint = connman_network_get_bool(network, "WiFi.HS20AP");
3243 keymgmt = connman_network_get_keymgmt(network);
3244 country_code = connman_network_get_countrycode(network);
3246 snprintf(bssid_str, WIFI_BSSID_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
3247 bssid[0], bssid[1], bssid[2],
3248 bssid[3], bssid[4], bssid[5]);
3250 snprintf(country_code_str, (WIFI_COUNTRY_CODE_LEN + 1), "%c%c",
3251 country_code[0], country_code[1]);
3254 connman_dbus_dict_append_fixed_array(dict, "SSID",
3255 DBUS_TYPE_BYTE, &ssid, ssid_len);
3256 connman_dbus_dict_append_basic(dict, "BSSID",
3257 DBUS_TYPE_STRING, &bssid_str);
3258 connman_dbus_dict_append_basic(dict, "MaxRate",
3259 DBUS_TYPE_UINT32, &maxrate);
3260 connman_dbus_dict_append_basic(dict, "Frequency",
3261 DBUS_TYPE_UINT16, &frequency);
3262 connman_dbus_dict_append_basic(dict, "EncryptionMode",
3263 DBUS_TYPE_STRING, &enc_mode);
3264 connman_dbus_dict_append_basic(dict, "Passpoint",
3265 DBUS_TYPE_BOOLEAN, &passpoint);
3266 connman_dbus_dict_append_basic(dict, "Keymgmt",
3267 DBUS_TYPE_UINT32, &keymgmt);
3268 connman_dbus_dict_append_basic(dict, "Country", DBUS_TYPE_STRING,
3271 str = connman_network_get_string(network, "WiFi.Security");
3272 if (str != NULL && g_str_equal(str, "ieee8021x") == TRUE) {
3273 str = connman_network_get_string(network, "WiFi.EAP");
3275 connman_dbus_dict_append_basic(dict, "EAP",
3276 DBUS_TYPE_STRING, &str);
3278 str = connman_network_get_string(network, "WiFi.Phase2");
3280 connman_dbus_dict_append_basic(dict, "Phase2",
3281 DBUS_TYPE_STRING, &str);
3283 str = connman_network_get_string(network, "WiFi.Identity");
3285 connman_dbus_dict_append_basic(dict, "Identity",
3286 DBUS_TYPE_STRING, &str);
3288 str = connman_network_get_string(network, "WiFi.CACertFile");
3290 connman_dbus_dict_append_basic(dict, "CACertFile",
3291 DBUS_TYPE_STRING, &str);
3293 str = connman_network_get_string(network,
3294 "WiFi.ClientCertFile");
3296 connman_dbus_dict_append_basic(dict, "ClientCertFile",
3297 DBUS_TYPE_STRING, &str);
3299 str = connman_network_get_string(network,
3300 "WiFi.PrivateKeyFile");
3302 connman_dbus_dict_append_basic(dict, "PrivateKeyFile",
3303 DBUS_TYPE_STRING, &str);
3307 static void append_bssid_info(DBusMessageIter *iter, void *user_data)
3309 GSList *bssid_list = NULL;
3310 struct connman_network *network = user_data;
3311 struct connman_bssids *bssids;
3312 char bssid_buf[18] = {0,};
3313 char *bssid_str = bssid_buf;
3315 bssid_list = (GSList *)connman_network_get_bssid_list(network);
3318 for (list = bssid_list; list; list = list->next) {
3319 bssids = (struct connman_bssids *)list->data;
3320 memcpy(bssid_str, bssids->bssid, 18);
3322 connman_dbus_dict_append_basic(iter, "BSSID",
3323 DBUS_TYPE_STRING, &bssid_str);
3325 connman_dbus_dict_append_basic(iter, "Strength",
3326 DBUS_TYPE_UINT16, &bssids->strength);
3328 connman_dbus_dict_append_basic(iter, "Frequency",
3329 DBUS_TYPE_UINT16, &bssids->frequency);
3335 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
3336 struct connman_service *service)
3342 #if defined TIZEN_EXT
3343 unsigned int frequency = 0U;
3344 if (service && service->network) {
3345 frequency = connman_network_get_frequency(service->network);
3346 connman_dbus_dict_append_basic(dict, "Frequency",
3347 DBUS_TYPE_UINT16, &frequency);
3350 unsigned char *wifi_vsie;
3351 unsigned int wifi_vsie_len;
3352 GSList *vsie_list = NULL;
3354 if (service->network)
3355 vsie_list = (GSList *)connman_network_get_vsie_list(service->network);
3358 DBG("ConnMan, service->path=%s No.of elements in list: %d", service->path, g_slist_length(vsie_list));
3360 for (list = vsie_list; list; list = list->next) {
3361 wifi_vsie = (unsigned char *)list->data;
3362 wifi_vsie_len = wifi_vsie[1] + 2;
3364 connman_dbus_dict_append_fixed_array(dict, "Vsie", DBUS_TYPE_BYTE,
3365 &wifi_vsie, wifi_vsie_len);
3370 str = __connman_service_type2string(service->type);
3372 connman_dbus_dict_append_basic(dict, "Type",
3373 DBUS_TYPE_STRING, &str);
3375 connman_dbus_dict_append_array(dict, "Security",
3376 DBUS_TYPE_STRING, append_security, service);
3378 str = state2string(service->state);
3380 connman_dbus_dict_append_basic(dict, "State",
3381 DBUS_TYPE_STRING, &str);
3384 str = state2string(service->state_ipv6);
3386 connman_dbus_dict_append_basic(dict, "StateIPv6",
3387 DBUS_TYPE_STRING, &str);
3390 str = error2string(service->error);
3392 connman_dbus_dict_append_basic(dict, "Error",
3393 DBUS_TYPE_STRING, &str);
3395 if (service->strength > 0)
3396 connman_dbus_dict_append_basic(dict, "Strength",
3397 DBUS_TYPE_BYTE, &service->strength);
3399 val = service->favorite;
3400 connman_dbus_dict_append_basic(dict, "Favorite",
3401 DBUS_TYPE_BOOLEAN, &val);
3403 val = service->immutable;
3404 connman_dbus_dict_append_basic(dict, "Immutable",
3405 DBUS_TYPE_BOOLEAN, &val);
3407 if (service->favorite)
3408 val = service->autoconnect;
3410 val = service->favorite;
3412 connman_dbus_dict_append_basic(dict, "AutoConnect",
3413 DBUS_TYPE_BOOLEAN, &val);
3416 connman_dbus_dict_append_basic(dict, "Name",
3417 DBUS_TYPE_STRING, &service->name);
3419 switch (service->type) {
3420 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3421 case CONNMAN_SERVICE_TYPE_SYSTEM:
3422 case CONNMAN_SERVICE_TYPE_GPS:
3423 case CONNMAN_SERVICE_TYPE_VPN:
3424 case CONNMAN_SERVICE_TYPE_P2P:
3426 case CONNMAN_SERVICE_TYPE_CELLULAR:
3427 val = service->roaming;
3428 connman_dbus_dict_append_basic(dict, "Roaming",
3429 DBUS_TYPE_BOOLEAN, &val);
3431 connman_dbus_dict_append_dict(dict, "Ethernet",
3432 append_ethernet, service);
3434 case CONNMAN_SERVICE_TYPE_WIFI:
3435 #if defined TIZEN_EXT
3436 if (service->network != NULL) {
3437 append_wifi_ext_info(dict, service->network);
3438 connman_dbus_dict_append_dict(dict, "BSSID.List",
3439 append_bssid_info, service->network);
3442 connman_dbus_dict_append_dict(dict, "Ethernet",
3443 append_ethernet, service);
3445 connman_dbus_dict_append_basic(dict, "DisconnectReason",
3446 DBUS_TYPE_INT32, &service->disconnect_reason);
3448 connman_dbus_dict_append_basic(dict, "AssocStatusCode",
3449 DBUS_TYPE_INT32, &service->assoc_status_code);
3453 case CONNMAN_SERVICE_TYPE_ETHERNET:
3454 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3455 case CONNMAN_SERVICE_TYPE_GADGET:
3456 connman_dbus_dict_append_dict(dict, "Ethernet",
3457 append_ethernet, service);
3461 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
3463 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
3464 append_ipv4config, service);
3466 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
3468 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
3469 append_ipv6config, service);
3471 connman_dbus_dict_append_array(dict, "Nameservers",
3472 DBUS_TYPE_STRING, append_dns, service);
3474 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
3475 DBUS_TYPE_STRING, append_dnsconfig, service);
3477 if (service->state == CONNMAN_SERVICE_STATE_READY ||
3478 service->state == CONNMAN_SERVICE_STATE_ONLINE)
3479 list = __connman_timeserver_get_all(service);
3483 connman_dbus_dict_append_array(dict, "Timeservers",
3484 DBUS_TYPE_STRING, append_ts, list);
3486 g_slist_free_full(list, g_free);
3488 connman_dbus_dict_append_array(dict, "Timeservers.Configuration",
3489 DBUS_TYPE_STRING, append_tsconfig, service);
3491 connman_dbus_dict_append_array(dict, "Domains",
3492 DBUS_TYPE_STRING, append_domain, service);
3494 connman_dbus_dict_append_array(dict, "Domains.Configuration",
3495 DBUS_TYPE_STRING, append_domainconfig, service);
3497 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
3499 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
3500 append_proxyconfig, service);
3502 connman_dbus_dict_append_dict(dict, "Provider",
3503 append_provider, service);
3506 static void append_struct_service(DBusMessageIter *iter,
3507 connman_dbus_append_cb_t function,
3508 struct connman_service *service)
3510 DBusMessageIter entry, dict;
3512 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
3514 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
3517 connman_dbus_dict_open(&entry, &dict);
3519 function(&dict, service);
3520 connman_dbus_dict_close(&entry, &dict);
3522 dbus_message_iter_close_container(iter, &entry);
3525 static void append_dict_properties(DBusMessageIter *dict, void *user_data)
3527 struct connman_service *service = user_data;
3529 append_properties(dict, TRUE, service);
3532 static void append_struct(gpointer value, gpointer user_data)
3534 struct connman_service *service = value;
3535 DBusMessageIter *iter = user_data;
3540 append_struct_service(iter, append_dict_properties, service);
3543 void __connman_service_list_struct(DBusMessageIter *iter)
3545 g_list_foreach(service_list, append_struct, iter);
3548 bool __connman_service_is_hidden(struct connman_service *service)
3550 return service->hidden;
3554 __connman_service_is_split_routing(struct connman_service *service)
3556 return service->do_split_routing;
3559 bool __connman_service_index_is_split_routing(int index)
3561 struct connman_service *service;
3566 service = __connman_service_lookup_from_index(index);
3570 return __connman_service_is_split_routing(service);
3573 int __connman_service_get_index(struct connman_service *service)
3578 if (service->network)
3579 return connman_network_get_index(service->network);
3580 else if (service->provider)
3581 return connman_provider_get_index(service->provider);
3586 void __connman_service_set_hidden(struct connman_service *service)
3588 if (!service || service->hidden)
3591 service->hidden_service = true;
3594 void __connman_service_set_hostname(struct connman_service *service,
3595 const char *hostname)
3597 if (!service || service->hidden)
3600 g_free(service->hostname);
3601 service->hostname = g_strdup(hostname);
3604 const char *__connman_service_get_hostname(struct connman_service *service)
3609 return service->hostname;
3612 void __connman_service_set_domainname(struct connman_service *service,
3613 const char *domainname)
3615 if (!service || service->hidden)
3618 g_free(service->domainname);
3619 service->domainname = g_strdup(domainname);
3621 domain_changed(service);
3624 const char *connman_service_get_domainname(struct connman_service *service)
3629 if (service->domains)
3630 return service->domains[0];
3632 return service->domainname;
3635 char **connman_service_get_nameservers(struct connman_service *service)
3640 if (service->nameservers_config)
3641 return g_strdupv(service->nameservers_config);
3642 else if (service->nameservers ||
3643 service->nameservers_auto) {
3644 int len = 0, len_auto = 0, i;
3647 if (service->nameservers)
3648 len = g_strv_length(service->nameservers);
3649 if (service->nameservers_auto)
3650 len_auto = g_strv_length(service->nameservers_auto);
3652 nameservers = g_try_new0(char *, len + len_auto + 1);
3656 for (i = 0; i < len; i++)
3657 nameservers[i] = g_strdup(service->nameservers[i]);
3659 for (i = 0; i < len_auto; i++)
3660 nameservers[i + len] =
3661 g_strdup(service->nameservers_auto[i]);
3666 return g_strdupv(connman_setting_get_string_list("FallbackNameservers"));
3669 char **connman_service_get_timeservers_config(struct connman_service *service)
3674 return service->timeservers_config;
3677 char **connman_service_get_timeservers(struct connman_service *service)
3682 return service->timeservers;
3685 #if defined TIZEN_EXT
3687 * Description: Telephony plug-in requires manual PROXY setting function
3689 int connman_service_set_proxy(struct connman_service *service,
3690 const char *proxy, gboolean active)
3692 char **proxies_array = NULL;
3694 if (service == NULL)
3697 switch (service->type) {
3698 case CONNMAN_SERVICE_TYPE_CELLULAR:
3699 case CONNMAN_SERVICE_TYPE_ETHERNET:
3700 case CONNMAN_SERVICE_TYPE_WIFI:
3707 g_strfreev(service->proxies);
3708 service->proxies = NULL;
3711 proxies_array = g_strsplit(proxy, " ", 0);
3713 service->proxies = proxies_array;
3715 if (proxy == NULL) {
3716 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
3717 DBG("proxy changed (%d)", active);
3719 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
3720 DBG("proxy chagned %s (%d)", proxy, active);
3723 if (active == TRUE) {
3724 proxy_changed(service);
3726 __connman_notifier_proxy_changed(service);
3733 void connman_service_set_proxy_method(struct connman_service *service,
3734 enum connman_service_proxy_method method)
3736 if (!service || service->hidden)
3739 service->proxy = method;
3741 proxy_changed(service);
3743 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
3744 __connman_notifier_proxy_changed(service);
3747 enum connman_service_proxy_method connman_service_get_proxy_method(
3748 struct connman_service *service)
3751 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
3753 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
3754 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
3756 return service->proxy;
3758 return service->proxy_config;
3761 return service->proxy;
3764 char **connman_service_get_proxy_servers(struct connman_service *service)
3766 return g_strdupv(service->proxies);
3769 char **connman_service_get_proxy_excludes(struct connman_service *service)
3771 return g_strdupv(service->excludes);
3774 const char *connman_service_get_proxy_url(struct connman_service *service)
3779 return service->pac;
3782 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
3785 if (!service || service->hidden)
3788 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
3790 if (service->ipconfig_ipv4) {
3791 if (__connman_ipconfig_set_proxy_autoconfig(
3792 service->ipconfig_ipv4, url) < 0)
3794 } else if (service->ipconfig_ipv6) {
3795 if (__connman_ipconfig_set_proxy_autoconfig(
3796 service->ipconfig_ipv6, url) < 0)
3801 proxy_changed(service);
3803 __connman_notifier_proxy_changed(service);
3806 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
3811 if (service->ipconfig_ipv4)
3812 return __connman_ipconfig_get_proxy_autoconfig(
3813 service->ipconfig_ipv4);
3814 else if (service->ipconfig_ipv6)
3815 return __connman_ipconfig_get_proxy_autoconfig(
3816 service->ipconfig_ipv6);
3820 #if defined TIZEN_EXT
3821 int connman_service_get_ipv6_dns_method(struct connman_service *service)
3824 DBG("Service is NULL");
3828 return service->dns_config_method_ipv6;
3832 void __connman_service_set_timeservers(struct connman_service *service,
3840 g_strfreev(service->timeservers);
3841 service->timeservers = NULL;
3843 for (i = 0; timeservers && timeservers[i]; i++)
3844 __connman_service_timeserver_append(service, timeservers[i]);
3847 int __connman_service_timeserver_append(struct connman_service *service,
3848 const char *timeserver)
3852 DBG("service %p timeserver %s", service, timeserver);
3857 if (service->timeservers) {
3860 for (i = 0; service->timeservers[i]; i++)
3861 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
3864 len = g_strv_length(service->timeservers);
3865 service->timeservers = g_try_renew(char *, service->timeservers,
3869 service->timeservers = g_try_new0(char *, len + 2);
3872 if (!service->timeservers)
3875 service->timeservers[len] = g_strdup(timeserver);
3876 service->timeservers[len + 1] = NULL;
3881 int __connman_service_timeserver_remove(struct connman_service *service,
3882 const char *timeserver)
3885 int len, i, j, found = 0;
3887 DBG("service %p timeserver %s", service, timeserver);
3892 if (!service->timeservers)
3895 for (i = 0; service->timeservers &&
3896 service->timeservers[i]; i++)
3897 if (g_strcmp0(service->timeservers[i], timeserver) == 0) {
3905 len = g_strv_length(service->timeservers);
3908 g_strfreev(service->timeservers);
3909 service->timeservers = NULL;
3914 servers = g_try_new0(char *, len);
3918 for (i = 0, j = 0; i < len; i++) {
3919 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
3920 servers[j] = g_strdup(service->timeservers[i]);
3926 servers[len - 1] = NULL;
3928 g_strfreev(service->timeservers);
3929 service->timeservers = servers;
3934 void __connman_service_timeserver_changed(struct connman_service *service,
3940 if (!allow_property_changed(service))
3943 connman_dbus_property_changed_array(service->path,
3944 CONNMAN_SERVICE_INTERFACE, "Timeservers",
3945 DBUS_TYPE_STRING, append_ts, ts_list);
3948 void __connman_service_set_pac(struct connman_service *service,
3951 if (service->hidden)
3953 g_free(service->pac);
3954 service->pac = g_strdup(pac);
3956 proxy_changed(service);
3959 #if defined TIZEN_EXT
3960 void __connman_service_set_proxy(struct connman_service *service,
3961 const char *proxies)
3963 char **proxies_array = NULL;
3965 g_strfreev(service->proxies);
3966 service->proxies = NULL;
3968 if (proxies != NULL)
3969 proxies_array = g_strsplit(proxies, " ", 0);
3971 service->proxies = proxies_array;
3975 void __connman_service_set_identity(struct connman_service *service,
3976 const char *identity)
3978 if (service->immutable || service->hidden)
3981 g_free(service->identity);
3982 service->identity = g_strdup(identity);
3984 if (service->network)
3985 connman_network_set_string(service->network,
3990 void __connman_service_set_anonymous_identity(struct connman_service *service,
3991 const char *anonymous_identity)
3993 if (service->immutable || service->hidden)
3996 g_free(service->anonymous_identity);
3997 service->anonymous_identity = g_strdup(anonymous_identity);
3999 if (service->network)
4000 connman_network_set_string(service->network,
4001 "WiFi.AnonymousIdentity",
4002 service->anonymous_identity);
4005 void __connman_service_set_subject_match(struct connman_service *service,
4006 const char *subject_match)
4008 if (service->immutable || service->hidden)
4011 g_free(service->subject_match);
4012 service->subject_match = g_strdup(subject_match);
4014 if (service->network)
4015 connman_network_set_string(service->network,
4016 "WiFi.SubjectMatch",
4017 service->subject_match);
4020 void __connman_service_set_altsubject_match(struct connman_service *service,
4021 const char *altsubject_match)
4023 if (service->immutable || service->hidden)
4026 g_free(service->altsubject_match);
4027 service->altsubject_match = g_strdup(altsubject_match);
4029 if (service->network)
4030 connman_network_set_string(service->network,
4031 "WiFi.AltSubjectMatch",
4032 service->altsubject_match);
4035 void __connman_service_set_domain_suffix_match(struct connman_service *service,
4036 const char *domain_suffix_match)
4038 if (service->immutable || service->hidden)
4041 g_free(service->domain_suffix_match);
4042 service->domain_suffix_match = g_strdup(domain_suffix_match);
4044 if (service->network)
4045 connman_network_set_string(service->network,
4046 "WiFi.DomainSuffixMatch",
4047 service->domain_suffix_match);
4050 void __connman_service_set_domain_match(struct connman_service *service,
4051 const char *domain_match)
4053 if (service->immutable || service->hidden)
4056 g_free(service->domain_match);
4057 service->domain_match = g_strdup(domain_match);
4059 if (service->network)
4060 connman_network_set_string(service->network,
4062 service->domain_match);
4065 void __connman_service_set_agent_identity(struct connman_service *service,
4066 const char *agent_identity)
4068 if (service->hidden)
4070 g_free(service->agent_identity);
4071 service->agent_identity = g_strdup(agent_identity);
4073 if (service->network)
4074 connman_network_set_string(service->network,
4075 "WiFi.AgentIdentity",
4076 service->agent_identity);
4079 int __connman_service_check_passphrase(enum connman_service_security security,
4080 const char *passphrase)
4088 length = strlen(passphrase);
4091 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
4092 case CONNMAN_SERVICE_SECURITY_NONE:
4093 case CONNMAN_SERVICE_SECURITY_WPA:
4094 #if !defined TIZEN_EXT
4095 case CONNMAN_SERVICE_SECURITY_RSN:
4098 DBG("service security '%s' (%d) not handled",
4099 security2string(security), security);
4103 case CONNMAN_SERVICE_SECURITY_PSK:
4104 #if defined TIZEN_EXT
4105 case CONNMAN_SERVICE_SECURITY_RSN:
4107 /* A raw key is always 64 bytes length,
4108 * its content is in hex representation.
4109 * A PSK key must be between [8..63].
4112 for (i = 0; i < 64; i++)
4113 if (!isxdigit((unsigned char)
4116 } else if (length < 8 || length > 63)
4119 case CONNMAN_SERVICE_SECURITY_WEP:
4120 /* length of WEP key is 10 or 26
4121 * length of WEP passphrase is 5 or 13
4123 if (length == 10 || length == 26) {
4124 for (i = 0; i < length; i++)
4125 if (!isxdigit((unsigned char)
4128 } else if (length != 5 && length != 13)
4132 case CONNMAN_SERVICE_SECURITY_8021X:
4139 int __connman_service_set_passphrase(struct connman_service *service,
4140 const char *passphrase)
4144 if (service->hidden)
4147 if (service->immutable &&
4148 service->security != CONNMAN_SERVICE_SECURITY_8021X)
4150 #if defined TIZEN_EXT
4151 /* The encrypted passphrase is used here
4152 * and validation is done by net-config before being encrypted.
4155 if (service->security != CONNMAN_SERVICE_SECURITY_PSK &&
4156 service->security != CONNMAN_SERVICE_SECURITY_RSN &&
4157 service->security != CONNMAN_SERVICE_SECURITY_WEP)
4159 err = __connman_service_check_passphrase(service->security, passphrase);
4164 g_free(service->passphrase);
4165 service->passphrase = g_strdup(passphrase);
4167 if (service->network)
4168 connman_network_set_string(service->network, "WiFi.Passphrase",
4169 service->passphrase);
4174 const char *__connman_service_get_passphrase(struct connman_service *service)
4179 return service->passphrase;
4182 static DBusMessage *get_properties(DBusConnection *conn,
4183 DBusMessage *msg, void *user_data)
4185 struct connman_service *service = user_data;
4187 DBusMessageIter array, dict;
4189 reply = dbus_message_new_method_return(msg);
4193 dbus_message_iter_init_append(reply, &array);
4195 connman_dbus_dict_open(&array, &dict);
4196 append_properties(&dict, FALSE, service);
4197 connman_dbus_dict_close(&array, &dict);
4202 static char **remove_empty_strings(char **strv)
4209 strv[index++] = *iter;
4219 static int update_proxy_configuration(struct connman_service *service,
4220 DBusMessageIter *array)
4222 DBusMessageIter dict;
4223 enum connman_service_proxy_method method;
4224 GString *servers_str = NULL;
4225 GString *excludes_str = NULL;
4226 const char *url = NULL;
4228 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
4230 dbus_message_iter_recurse(array, &dict);
4232 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
4233 DBusMessageIter entry, variant;
4237 dbus_message_iter_recurse(&dict, &entry);
4239 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
4242 dbus_message_iter_get_basic(&entry, &key);
4243 dbus_message_iter_next(&entry);
4245 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
4248 dbus_message_iter_recurse(&entry, &variant);
4250 type = dbus_message_iter_get_arg_type(&variant);
4252 if (g_str_equal(key, "Method")) {
4255 if (type != DBUS_TYPE_STRING)
4258 dbus_message_iter_get_basic(&variant, &val);
4259 method = string2proxymethod(val);
4260 } else if (g_str_equal(key, "URL")) {
4261 if (type != DBUS_TYPE_STRING)
4264 dbus_message_iter_get_basic(&variant, &url);
4265 } else if (g_str_equal(key, "Servers")) {
4266 DBusMessageIter str_array;
4268 if (type != DBUS_TYPE_ARRAY)
4271 servers_str = g_string_new(NULL);
4275 dbus_message_iter_recurse(&variant, &str_array);
4277 while (dbus_message_iter_get_arg_type(&str_array) ==
4281 dbus_message_iter_get_basic(&str_array, &val);
4283 if (servers_str->len > 0)
4284 g_string_append_printf(servers_str,
4287 g_string_append(servers_str, val);
4289 dbus_message_iter_next(&str_array);
4291 } else if (g_str_equal(key, "Excludes")) {
4292 DBusMessageIter str_array;
4294 if (type != DBUS_TYPE_ARRAY)
4297 excludes_str = g_string_new(NULL);
4301 dbus_message_iter_recurse(&variant, &str_array);
4303 while (dbus_message_iter_get_arg_type(&str_array) ==
4307 dbus_message_iter_get_basic(&str_array, &val);
4309 if (excludes_str->len > 0)
4310 g_string_append_printf(excludes_str,
4313 g_string_append(excludes_str, val);
4315 dbus_message_iter_next(&str_array);
4319 dbus_message_iter_next(&dict);
4323 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
4325 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
4326 if (!servers_str && !service->proxies)
4330 g_strfreev(service->proxies);
4332 if (servers_str->len > 0) {
4333 char **proxies = g_strsplit_set(
4334 servers_str->str, " ", 0);
4335 proxies = remove_empty_strings(proxies);
4336 service->proxies = proxies;
4338 service->proxies = NULL;
4342 g_strfreev(service->excludes);
4344 if (excludes_str->len > 0) {
4345 char **excludes = g_strsplit_set(
4346 excludes_str->str, " ", 0);
4347 excludes = remove_empty_strings(excludes);
4348 service->excludes = excludes;
4350 service->excludes = NULL;
4353 if (!service->proxies)
4354 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
4357 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
4358 g_free(service->pac);
4360 if (url && strlen(url) > 0)
4361 service->pac = g_strstrip(g_strdup(url));
4363 service->pac = NULL;
4365 /* if we are connected:
4366 - if service->pac == NULL
4367 - if __connman_ipconfig_get_proxy_autoconfig(
4368 service->ipconfig) == NULL
4369 --> We should start WPAD */
4372 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
4377 g_string_free(servers_str, TRUE);
4380 g_string_free(excludes_str, TRUE);
4382 service->proxy_config = method;
4388 g_string_free(servers_str, TRUE);
4391 g_string_free(excludes_str, TRUE);
4396 int __connman_service_reset_ipconfig(struct connman_service *service,
4397 enum connman_ipconfig_type type, DBusMessageIter *array,
4398 enum connman_service_state *new_state)
4400 struct connman_ipconfig *ipconfig, *new_ipconfig;
4401 enum connman_ipconfig_method old_method, new_method;
4402 enum connman_service_state state;
4405 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4406 ipconfig = service->ipconfig_ipv4;
4407 state = service->state_ipv4;
4408 new_method = CONNMAN_IPCONFIG_METHOD_DHCP;
4409 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4410 ipconfig = service->ipconfig_ipv6;
4411 state = service->state_ipv6;
4412 new_method = CONNMAN_IPCONFIG_METHOD_AUTO;
4419 old_method = __connman_ipconfig_get_method(ipconfig);
4420 index = __connman_ipconfig_get_index(ipconfig);
4422 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4423 new_ipconfig = create_ip4config(service, index,
4424 CONNMAN_IPCONFIG_METHOD_UNKNOWN);
4426 new_ipconfig = create_ip6config(service, index);
4429 err = __connman_ipconfig_set_config(new_ipconfig, array);
4431 __connman_ipconfig_unref(new_ipconfig);
4435 new_method = __connman_ipconfig_get_method(new_ipconfig);
4438 if (is_connecting(state) || is_connected(state))
4439 __connman_network_clear_ipconfig(service->network, ipconfig);
4441 __connman_ipconfig_unref(ipconfig);
4443 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4444 service->ipconfig_ipv4 = new_ipconfig;
4445 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4446 service->ipconfig_ipv6 = new_ipconfig;
4448 if (is_connecting(state) || is_connected(state))
4449 __connman_ipconfig_enable(new_ipconfig);
4451 if (new_state && new_method != old_method) {
4452 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4453 *new_state = service->state_ipv4;
4455 *new_state = service->state_ipv6;
4457 settings_changed(service, new_ipconfig);
4458 address_updated(service, new_method);
4460 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4463 DBG("err %d ipconfig %p type %d method %d state %s", err,
4464 new_ipconfig, type, new_method,
4465 !new_state ? "-" : state2string(*new_state));
4470 static DBusMessage *set_property(DBusConnection *conn,
4471 DBusMessage *msg, void *user_data)
4473 struct connman_service *service = user_data;
4474 DBusMessageIter iter, value;
4478 DBG("service %p", service);
4480 if (!dbus_message_iter_init(msg, &iter))
4481 return __connman_error_invalid_arguments(msg);
4483 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
4484 return __connman_error_invalid_arguments(msg);
4486 if (service->type == CONNMAN_SERVICE_TYPE_WIFI && is_connected(service->state)) {
4488 if (connman_dbus_get_connection_unix_user_sync(conn,
4489 dbus_message_get_sender(msg),
4491 DBG("Can not get unix user id!");
4492 return __connman_error_permission_denied(msg);
4495 if (!connman_service_is_user_allowed(service, uid)) {
4496 DBG("Not allow this user to operate this wifi service now!");
4497 return __connman_error_permission_denied(msg);
4501 dbus_message_iter_get_basic(&iter, &name);
4502 dbus_message_iter_next(&iter);
4504 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
4505 return __connman_error_invalid_arguments(msg);
4507 dbus_message_iter_recurse(&iter, &value);
4509 type = dbus_message_iter_get_arg_type(&value);
4511 if (g_str_equal(name, "AutoConnect")) {
4512 dbus_bool_t autoconnect;
4514 if (type != DBUS_TYPE_BOOLEAN)
4515 return __connman_error_invalid_arguments(msg);
4517 if (!service->favorite)
4518 return __connman_error_invalid_service(msg);
4520 dbus_message_iter_get_basic(&value, &autoconnect);
4522 if (service->autoconnect == autoconnect)
4523 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4525 service->autoconnect = autoconnect;
4527 autoconnect_changed(service);
4530 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4532 service_save(service);
4533 } else if (g_str_equal(name, "Nameservers.Configuration")) {
4534 DBusMessageIter entry;
4538 #if defined TIZEN_EXT
4539 enum connman_ipconfig_type ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4543 if (__connman_provider_is_immutable(service->provider) ||
4545 return __connman_error_not_supported(msg);
4547 if (type != DBUS_TYPE_ARRAY)
4548 return __connman_error_invalid_arguments(msg);
4550 str = g_string_new(NULL);
4552 return __connman_error_invalid_arguments(msg);
4554 index = __connman_service_get_index(service);
4555 gw = __connman_ipconfig_get_gateway_from_index(index,
4556 CONNMAN_IPCONFIG_TYPE_ALL);
4558 #if !defined TIZEN_EXT
4559 if (gw && strlen(gw))
4560 __connman_service_nameserver_del_routes(service,
4561 CONNMAN_IPCONFIG_TYPE_ALL);
4563 dbus_message_iter_recurse(&value, &entry);
4565 #if defined TIZEN_EXT
4566 /* IPv4/IPv6 Last DNS config method */
4567 int last_dns_ipv4 = service->dns_config_method_ipv4;
4568 int last_dns_ipv6 = service->dns_config_method_ipv6;
4569 DBG("Last DNS Config Method IPv4: %d IPv6: %d", last_dns_ipv4, last_dns_ipv6);
4572 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4574 dbus_message_iter_get_basic(&entry, &val);
4575 dbus_message_iter_next(&entry);
4577 /* First unpack the DNS Config Method */
4578 DBG("DNS Config Method: %s", val);
4579 if((g_strcmp0(val, "ipv4.manual") == 0)) {
4580 service->dns_config_method_ipv4 =
4581 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4583 if(last_dns_ipv4 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4584 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4585 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4587 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4590 } else if(g_strcmp0(val, "ipv4.dhcp") == 0) {
4591 service->dns_config_method_ipv4 =
4592 CONNMAN_DNSCONFIG_METHOD_DHCP;
4593 if(last_dns_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4594 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4597 } else if(g_strcmp0(val, "ipv6.manual") == 0) {
4598 service->dns_config_method_ipv6 =
4599 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4600 if(last_dns_ipv6 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4601 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4602 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4604 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4607 } else if(g_strcmp0(val, "ipv6.dhcp") == 0) {
4608 service->dns_config_method_ipv6 =
4609 CONNMAN_DNSCONFIG_METHOD_DHCP;
4610 if(last_dns_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4611 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4620 g_string_append_printf(str, " %s", val);
4622 g_string_append(str, val);
4625 #if defined TIZEN_EXT
4626 if (service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_DHCP &&
4627 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_DHCP) {
4628 DBG("Both IPv4 and IPv6 DNS Method DHCP");
4629 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4631 if (gw && strlen(gw))
4632 __connman_service_nameserver_del_routes(service,
4635 DBG("%s ip_type: %d nameserver remove all", name, ip_type);
4636 nameserver_remove_all(service, ip_type);
4638 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
4640 g_strfreev(service->nameservers_config);
4643 char **nameservers, **iter;
4645 nameservers = g_strsplit_set(str->str, " ", 0);
4647 for (iter = nameservers; *iter; iter++)
4648 if (connman_inet_check_ipaddress(*iter) <= 0)
4651 nameservers = remove_empty_strings(nameservers);
4652 service->nameservers_config = nameservers;
4654 service->nameservers_config = NULL;
4657 g_string_free(str, TRUE);
4659 if (gw && strlen(gw))
4660 __connman_service_nameserver_add_routes(service, gw);
4662 #if defined TIZEN_EXT
4663 DBG("%s ip_type: %d nameserver add all", name, ip_type);
4664 nameserver_add_all(service, ip_type);
4666 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
4668 dns_configuration_changed(service);
4670 if (__connman_service_is_connected_state(service,
4671 CONNMAN_IPCONFIG_TYPE_IPV4))
4672 __connman_wispr_start(service,
4673 CONNMAN_IPCONFIG_TYPE_IPV4);
4675 if (__connman_service_is_connected_state(service,
4676 CONNMAN_IPCONFIG_TYPE_IPV6))
4677 __connman_wispr_start(service,
4678 CONNMAN_IPCONFIG_TYPE_IPV6);
4680 service_save(service);
4681 } else if (g_str_equal(name, "Timeservers.Configuration")) {
4682 DBusMessageIter entry;
4685 if (service->immutable)
4686 return __connman_error_not_supported(msg);
4688 if (type != DBUS_TYPE_ARRAY)
4689 return __connman_error_invalid_arguments(msg);
4691 str = g_string_new(NULL);
4693 return __connman_error_invalid_arguments(msg);
4695 dbus_message_iter_recurse(&value, &entry);
4697 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4699 dbus_message_iter_get_basic(&entry, &val);
4700 dbus_message_iter_next(&entry);
4706 g_string_append_printf(str, " %s", val);
4708 g_string_append(str, val);
4711 g_strfreev(service->timeservers_config);
4712 service->timeservers_config = NULL;
4715 char **timeservers = g_strsplit_set(str->str, " ", 0);
4716 timeservers = remove_empty_strings(timeservers);
4717 service->timeservers_config = timeservers;
4719 service->timeservers = NULL;
4721 g_string_free(str, TRUE);
4723 service_save(service);
4724 timeservers_configuration_changed(service);
4726 if (service == __connman_service_get_default())
4727 __connman_timeserver_sync(service);
4729 } else if (g_str_equal(name, "Domains.Configuration")) {
4730 DBusMessageIter entry;
4733 if (service->immutable)
4734 return __connman_error_not_supported(msg);
4736 if (type != DBUS_TYPE_ARRAY)
4737 return __connman_error_invalid_arguments(msg);
4739 str = g_string_new(NULL);
4741 return __connman_error_invalid_arguments(msg);
4743 dbus_message_iter_recurse(&value, &entry);
4745 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4747 dbus_message_iter_get_basic(&entry, &val);
4748 dbus_message_iter_next(&entry);
4754 g_string_append_printf(str, " %s", val);
4756 g_string_append(str, val);
4759 searchdomain_remove_all(service);
4760 g_strfreev(service->domains);
4763 char **domains = g_strsplit_set(str->str, " ", 0);
4764 domains = remove_empty_strings(domains);
4765 service->domains = domains;
4767 service->domains = NULL;
4769 g_string_free(str, TRUE);
4771 searchdomain_add_all(service);
4772 domain_configuration_changed(service);
4773 domain_changed(service);
4775 service_save(service);
4776 } else if (g_str_equal(name, "Proxy.Configuration")) {
4779 if (service->immutable)
4780 return __connman_error_not_supported(msg);
4782 if (type != DBUS_TYPE_ARRAY)
4783 return __connman_error_invalid_arguments(msg);
4785 err = update_proxy_configuration(service, &value);
4788 return __connman_error_failed(msg, -err);
4790 proxy_configuration_changed(service);
4792 __connman_notifier_proxy_changed(service);
4794 service_save(service);
4795 } else if (g_str_equal(name, "IPv4.Configuration") ||
4796 g_str_equal(name, "IPv6.Configuration")) {
4798 enum connman_service_state state =
4799 CONNMAN_SERVICE_STATE_UNKNOWN;
4800 enum connman_ipconfig_type type =
4801 CONNMAN_IPCONFIG_TYPE_UNKNOWN;
4804 if (service->type == CONNMAN_SERVICE_TYPE_VPN ||
4806 return __connman_error_not_supported(msg);
4810 if (!service->ipconfig_ipv4 &&
4811 !service->ipconfig_ipv6)
4812 return __connman_error_invalid_property(msg);
4814 if (g_str_equal(name, "IPv4.Configuration"))
4815 type = CONNMAN_IPCONFIG_TYPE_IPV4;
4817 type = CONNMAN_IPCONFIG_TYPE_IPV6;
4819 err = __connman_service_reset_ipconfig(service, type, &value,
4823 if (is_connected(state) || is_connecting(state)) {
4824 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4825 __connman_network_enable_ipconfig(service->network,
4826 service->ipconfig_ipv4);
4828 __connman_network_enable_ipconfig(service->network,
4829 service->ipconfig_ipv6);
4832 return __connman_error_failed(msg, -err);
4835 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4836 ipv4_configuration_changed(service);
4838 ipv6_configuration_changed(service);
4840 if (is_connecting(service->state) ||
4841 is_connected(service->state)) {
4842 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4843 __connman_network_enable_ipconfig(service->network,
4844 service->ipconfig_ipv4);
4846 __connman_network_enable_ipconfig(service->network,
4847 service->ipconfig_ipv6);
4850 service_save(service);
4852 return __connman_error_invalid_property(msg);
4854 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4857 static void set_error(struct connman_service *service,
4858 enum connman_service_error error)
4862 if (service->error == error)
4865 service->error = error;
4870 #if !defined TIZEN_EXT
4871 if (!allow_property_changed(service))
4875 str = error2string(service->error);
4880 connman_dbus_property_changed_basic(service->path,
4881 CONNMAN_SERVICE_INTERFACE, "Error",
4882 DBUS_TYPE_STRING, &str);
4885 static void remove_timeout(struct connman_service *service)
4887 if (service->timeout > 0) {
4888 g_source_remove(service->timeout);
4889 service->timeout = 0;
4893 static void reply_pending(struct connman_service *service, int error)
4895 remove_timeout(service);
4897 if (service->pending) {
4898 connman_dbus_reply_pending(service->pending, error, NULL);
4899 service->pending = NULL;
4902 if (service->provider_pending) {
4903 connman_dbus_reply_pending(service->provider_pending,
4904 error, service->path);
4905 service->provider_pending = NULL;
4909 static void service_complete(struct connman_service *service)
4911 reply_pending(service, EIO);
4913 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
4914 __connman_service_auto_connect(service->connect_reason);
4916 g_get_current_time(&service->modified);
4917 service_save(service);
4920 static void set_idle(struct connman_service *service)
4922 service->state = service->state_ipv4 = service->state_ipv6 =
4923 CONNMAN_SERVICE_STATE_IDLE;
4924 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4925 state_changed(service);
4928 static DBusMessage *clear_property(DBusConnection *conn,
4929 DBusMessage *msg, void *user_data)
4931 struct connman_service *service = user_data;
4934 DBG("service %p", service);
4936 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
4939 if (g_str_equal(name, "Error")) {
4940 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4942 __connman_service_clear_error(service);
4943 service_complete(service);
4945 return __connman_error_invalid_property(msg);
4947 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4950 static bool is_ipconfig_usable(struct connman_service *service)
4952 if (!__connman_ipconfig_is_usable(service->ipconfig_ipv4) &&
4953 !__connman_ipconfig_is_usable(service->ipconfig_ipv6))
4959 static bool is_ignore(struct connman_service *service)
4961 if (!service->autoconnect)
4964 if (service->roaming)
4967 if (service->ignore)
4970 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
4973 if (!is_ipconfig_usable(service))
4979 static void disconnect_on_last_session(enum connman_service_type type)
4983 for (list = service_list; list; list = list->next) {
4984 struct connman_service *service = list->data;
4986 if (service->type != type)
4989 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_SESSION)
4992 __connman_service_disconnect(service);
4997 static int active_sessions[MAX_CONNMAN_SERVICE_TYPES] = {};
4998 static int always_connect[MAX_CONNMAN_SERVICE_TYPES] = {};
4999 static int active_count = 0;
5001 void __connman_service_set_active_session(bool enable, GSList *list)
5012 enum connman_service_type type = GPOINTER_TO_INT(list->data);
5015 case CONNMAN_SERVICE_TYPE_ETHERNET:
5016 case CONNMAN_SERVICE_TYPE_WIFI:
5017 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
5018 case CONNMAN_SERVICE_TYPE_CELLULAR:
5019 case CONNMAN_SERVICE_TYPE_GADGET:
5021 active_sessions[type]++;
5023 active_sessions[type]--;
5026 case CONNMAN_SERVICE_TYPE_UNKNOWN:
5027 case CONNMAN_SERVICE_TYPE_SYSTEM:
5028 case CONNMAN_SERVICE_TYPE_GPS:
5029 case CONNMAN_SERVICE_TYPE_VPN:
5030 case CONNMAN_SERVICE_TYPE_P2P:
5034 if (active_sessions[type] == 0)
5035 disconnect_on_last_session(type);
5037 list = g_slist_next(list);
5040 DBG("eth %d wifi %d bt %d cellular %d gadget %d sessions %d",
5041 active_sessions[CONNMAN_SERVICE_TYPE_ETHERNET],
5042 active_sessions[CONNMAN_SERVICE_TYPE_WIFI],
5043 active_sessions[CONNMAN_SERVICE_TYPE_BLUETOOTH],
5044 active_sessions[CONNMAN_SERVICE_TYPE_CELLULAR],
5045 active_sessions[CONNMAN_SERVICE_TYPE_GADGET],
5049 struct preferred_tech_data {
5050 GList *preferred_list;
5051 enum connman_service_type type;
5054 static void preferred_tech_add_by_type(gpointer data, gpointer user_data)
5056 struct connman_service *service = data;
5057 struct preferred_tech_data *tech_data = user_data;
5059 if (service->type == tech_data->type) {
5060 tech_data->preferred_list =
5061 g_list_append(tech_data->preferred_list, service);
5063 DBG("type %d service %p %s", tech_data->type, service,
5068 static GList *preferred_tech_list_get(void)
5070 unsigned int *tech_array;
5071 struct preferred_tech_data tech_data = { 0, };
5074 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
5078 if (connman_setting_get_bool("SingleConnectedTechnology")) {
5080 for (list = service_list; list; list = list->next) {
5081 struct connman_service *service = list->data;
5083 if (!is_connected(service->state))
5086 if (service->connect_reason ==
5087 CONNMAN_SERVICE_CONNECT_REASON_USER) {
5088 DBG("service %p name %s is user connected",
5089 service, service->name);
5090 #if defined TIZEN_EXT
5091 /* We can connect to a favorite service like
5092 * wifi even we have a userconnect for cellular
5093 * because we have refount for cellular service
5095 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5098 if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
5106 for (i = 0; tech_array[i] != 0; i += 1) {
5107 tech_data.type = tech_array[i];
5108 g_list_foreach(service_list, preferred_tech_add_by_type,
5112 return tech_data.preferred_list;
5115 static void set_always_connecting_technologies()
5117 unsigned int *always_connected_techs =
5118 connman_setting_get_uint_list("AlwaysConnectedTechnologies");
5120 for (i = 0; always_connected_techs && always_connected_techs[i]; i++)
5121 always_connect[always_connected_techs[i]] = 1;
5124 static bool autoconnect_no_session_active(struct connman_service *service)
5127 * Test active_count to see if there are no sessions set up and
5128 * stop autoconnecting, but continue connecting if the service
5129 * belongs to a technology which should always autoconnect.
5131 if (!active_count && !always_connect[service->type])
5137 static bool autoconnect_already_connecting(struct connman_service *service,
5138 bool autoconnecting)
5141 * If another service is already connecting and this service type has
5142 * not been marked as always connecting, stop the connecting procedure.
5144 if (autoconnecting &&
5145 !active_sessions[service->type] &&
5146 !always_connect[service->type])
5152 static bool auto_connect_service(GList *services,
5153 enum connman_service_connect_reason reason,
5156 struct connman_service *service = NULL;
5157 bool ignore[MAX_CONNMAN_SERVICE_TYPES] = { };
5158 bool autoconnecting = false;
5161 DBG("preferred %d sessions %d reason %s", preferred, active_count,
5162 reason2string(reason));
5164 ignore[CONNMAN_SERVICE_TYPE_VPN] = true;
5166 for (list = services; list; list = list->next) {
5167 service = list->data;
5169 if (ignore[service->type]) {
5170 DBG("service %p type %s ignore", service,
5171 __connman_service_type2string(service->type));
5175 #if defined TIZEN_EXT
5176 DBG("service %p %s %s %s, favorite(%d), ignore(%d), hidden(%d, %d)",
5177 service, service->name,
5178 state2string(service->state),
5179 __connman_service_type2string(service->type),
5180 service->favorite, is_ignore(service),
5181 service->hidden, service->hidden_service);
5183 /* Tizen takes Wi-Fi as the highest priority into consideration. */
5184 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
5185 if (is_connecting(service->state) == TRUE || is_connected(service->state) == TRUE)
5189 if (service->pending ||
5190 is_connecting(service->state) ||
5191 is_connected(service->state)) {
5192 if (autoconnect_no_session_active(service))
5195 ignore[service->type] = true;
5196 autoconnecting = true;
5198 DBG("service %p type %s busy", service,
5199 __connman_service_type2string(service->type));
5204 if (!service->favorite) {
5208 #if defined TIZEN_EXT
5209 DBG("Service is not favorite, autoconnecting %d",
5212 return autoconnecting;
5215 #if defined TIZEN_EXT
5216 DBG("service %p identifier %s roaming %d ignore %d "
5217 "ipconfig_usable %d autoconnect %d state %d",
5219 service->identifier, service->roaming,
5220 service->ignore, is_ipconfig_usable(service),
5221 service->autoconnect, service->state);
5223 if (is_ignore(service) || service->state !=
5224 CONNMAN_SERVICE_STATE_IDLE)
5227 if (autoconnect_already_connecting(service, autoconnecting)) {
5228 DBG("service %p type %s has no users", service,
5229 __connman_service_type2string(service->type));
5233 if (!is_service_owner_user_login(service)) {
5234 DBG("favorite user not login, wifi auto connect denied");
5238 DBG("service %p %s %s", service, service->name,
5239 (preferred) ? "preferred" : reason2string(reason));
5241 __connman_service_connect(service, reason);
5243 if (autoconnect_no_session_active(service))
5246 ignore[service->type] = true;
5249 return autoconnecting;
5252 static gboolean run_auto_connect(gpointer data)
5254 enum connman_service_connect_reason reason = GPOINTER_TO_UINT(data);
5255 bool autoconnecting = false;
5256 GList *preferred_tech;
5258 autoconnect_timeout = 0;
5262 preferred_tech = preferred_tech_list_get();
5263 if (preferred_tech) {
5264 autoconnecting = auto_connect_service(preferred_tech, reason,
5266 g_list_free(preferred_tech);
5269 if (!autoconnecting || active_count)
5270 auto_connect_service(service_list, reason, false);
5275 #if defined TIZEN_EXT
5276 bool __connman_service_get_auto_connect_mode(void)
5278 return auto_connect_mode;
5281 void __connman_service_set_auto_connect_mode(bool enable)
5283 DBG("set auto_connect_mode = %d", enable);
5285 if (auto_connect_mode != enable)
5286 auto_connect_mode = enable;
5290 void __connman_service_auto_connect(enum connman_service_connect_reason reason)
5294 if (autoconnect_timeout != 0)
5297 #if defined TIZEN_EXT
5298 if (auto_connect_mode == FALSE) {
5299 DBG("Currently, not auto connection mode");
5304 if (!__connman_session_policy_autoconnect(reason))
5307 #if defined TIZEN_EXT
5308 /* Adding Timeout of 500ms before trying to auto connect.
5309 * This is done because of below scenario
5310 * 1. Device is connected to AP1
5311 * 2. WPS Connection request is initiated for AP2
5312 * 3. Immediately WPS Connection is Cancelled
5313 * When WPS Connection Connection is initiated for AP2 then
5314 * sometimes there is a scenario where connman gets in ASSOCIATED
5315 * state with AP1 due to autoconnect and subsequently the connection
5316 * initiated by AP1 fails and connman service for AP1 comes in
5317 * FAILURE state due to this when connection with AP2 is cancelled
5318 * then autoconnect with AP1 doesn't works because its autoconnection
5319 * is ignored as its last state was FAILURE rather than IDLE */
5320 autoconnect_timeout = g_timeout_add(500, run_auto_connect,
5322 autoconnect_timeout = g_idle_add(run_auto_connect,
5324 GUINT_TO_POINTER(reason));
5327 static gboolean run_vpn_auto_connect(gpointer data) {
5329 bool need_split = false;
5331 vpn_autoconnect_timeout = 0;
5333 for (list = service_list; list; list = list->next) {
5334 struct connman_service *service = list->data;
5337 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
5340 if (is_connected(service->state) ||
5341 is_connecting(service->state)) {
5342 if (!service->do_split_routing)
5347 if (is_ignore(service) || !service->favorite)
5350 if (need_split && !service->do_split_routing) {
5351 DBG("service %p no split routing", service);
5355 DBG("service %p %s %s", service, service->name,
5356 service->do_split_routing ?
5357 "split routing" : "");
5359 res = __connman_service_connect(service,
5360 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5361 if (res < 0 && res != -EINPROGRESS)
5364 if (!service->do_split_routing)
5371 static void vpn_auto_connect(void)
5373 if (vpn_autoconnect_timeout)
5376 vpn_autoconnect_timeout =
5377 g_idle_add(run_vpn_auto_connect, NULL);
5381 __connman_service_is_provider_pending(struct connman_service *service)
5386 if (service->provider_pending)
5392 void __connman_service_set_provider_pending(struct connman_service *service,
5395 if (service->provider_pending) {
5396 DBG("service %p provider pending msg %p already exists",
5397 service, service->provider_pending);
5401 service->provider_pending = msg;
5405 static void check_pending_msg(struct connman_service *service)
5407 if (!service->pending)
5410 DBG("service %p pending msg %p already exists", service,
5412 dbus_message_unref(service->pending);
5415 void __connman_service_set_hidden_data(struct connman_service *service,
5418 DBusMessage *pending = user_data;
5420 DBG("service %p pending %p", service, pending);
5425 check_pending_msg(service);
5427 service->pending = pending;
5430 void __connman_service_return_error(struct connman_service *service,
5431 int error, gpointer user_data)
5433 DBG("service %p error %d user_data %p", service, error, user_data);
5435 __connman_service_set_hidden_data(service, user_data);
5437 reply_pending(service, error);
5440 static gboolean connect_timeout(gpointer user_data)
5442 struct connman_service *service = user_data;
5443 bool autoconnect = false;
5445 DBG("service %p", service);
5447 service->timeout = 0;
5449 if (service->network)
5450 __connman_network_disconnect(service->network);
5451 else if (service->provider)
5452 connman_provider_disconnect(service->provider);
5454 __connman_stats_service_unregister(service);
5456 if (service->pending) {
5459 reply = __connman_error_operation_timeout(service->pending);
5461 g_dbus_send_message(connection, reply);
5463 dbus_message_unref(service->pending);
5464 service->pending = NULL;
5468 __connman_service_ipconfig_indicate_state(service,
5469 CONNMAN_SERVICE_STATE_FAILURE,
5470 CONNMAN_IPCONFIG_TYPE_IPV4);
5471 __connman_service_ipconfig_indicate_state(service,
5472 CONNMAN_SERVICE_STATE_FAILURE,
5473 CONNMAN_IPCONFIG_TYPE_IPV6);
5476 service->connect_reason !=
5477 CONNMAN_SERVICE_CONNECT_REASON_USER)
5478 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5483 static DBusMessage *connect_service(DBusConnection *conn,
5484 DBusMessage *msg, void *user_data)
5486 struct connman_service *service = user_data;
5487 #if defined TIZEN_EXT
5494 DBG("service %p", service);
5496 #if defined TIZEN_EXT
5498 * Description: TIZEN implements system global connection management.
5500 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5501 connman_service_user_pdn_connection_ref(service);
5503 /*Reset the Disconnect Reason while issue connect request*/
5504 service->disconnect_reason = 0;
5506 /*Reset the association status code while issue connect request*/
5507 service->assoc_status_code = 0;
5510 if (service->pending)
5511 return __connman_error_in_progress(msg);
5513 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5515 if (connman_dbus_get_connection_unix_user_sync(conn,
5516 dbus_message_get_sender(msg),
5518 DBG("Can not get unix user id!");
5519 return __connman_error_permission_denied(msg);
5522 if (!__connman_service_is_user_allowed(CONNMAN_SERVICE_TYPE_WIFI, uid)) {
5523 DBG("Not allow this user to connect this wifi service now!");
5524 return __connman_error_permission_denied(msg);
5527 if (uid != USER_ROOT && uid != service->user.favorite_user)
5528 service->request_passphrase_input = true;
5530 service->user.current_user = uid;
5532 if (!service->passphrase && uid == service->user.favorite_user) {
5533 DBG("Now load this favorite user's passphrase.");
5534 service_load_passphrase(service);
5538 #if !defined TIZEN_EXT
5539 index = __connman_service_get_index(service);
5541 for (list = service_list; list; list = list->next) {
5542 struct connman_service *temp = list->data;
5544 #if defined TIZEN_EXT
5545 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5548 if (!is_connecting(temp->state) && !is_connected(temp->state))
5551 if (service == temp)
5554 if (service->type != temp->type)
5557 if (__connman_service_get_index(temp) == index &&
5558 __connman_service_disconnect(temp) == -EINPROGRESS)
5562 if (err == -EINPROGRESS)
5563 return __connman_error_operation_timeout(msg);
5566 service->ignore = false;
5568 service->pending = dbus_message_ref(msg);
5570 err = __connman_service_connect(service,
5571 CONNMAN_SERVICE_CONNECT_REASON_USER);
5573 if (err == -EINPROGRESS)
5576 if (service->pending) {
5577 dbus_message_unref(service->pending);
5578 service->pending = NULL;
5582 return __connman_error_failed(msg, -err);
5584 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5587 static DBusMessage *disconnect_service(DBusConnection *conn,
5588 DBusMessage *msg, void *user_data)
5590 struct connman_service *service = user_data;
5593 DBG("service %p", service);
5595 #if defined TIZEN_EXT
5597 * Description: TIZEN implements system global connection management.
5599 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
5600 if (connman_service_user_pdn_connection_unref_and_test(service) != TRUE)
5601 return __connman_error_failed(msg, EISCONN);
5603 if (is_connected(service->state) == TRUE &&
5604 service == connman_service_get_default_connection())
5605 return __connman_error_failed(msg, EISCONN);
5609 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5611 if (connman_dbus_get_connection_unix_user_sync(conn,
5612 dbus_message_get_sender(msg),
5614 DBG("Can not get unix user id!");
5615 return __connman_error_permission_denied(msg);
5618 if (!connman_service_is_user_allowed(service, uid)) {
5619 DBG("Not allow this user to disconnect this wifi service now!");
5620 return __connman_error_permission_denied(msg);
5624 service->ignore = true;
5626 err = __connman_service_disconnect(service);
5627 if (err < 0 && err != -EINPROGRESS)
5628 return __connman_error_failed(msg, -err);
5630 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5633 #if defined TIZEN_EXT
5634 static void __connman_service_cleanup_network_8021x(struct connman_service *service)
5636 if (service == NULL)
5639 DBG("service %p ", service);
5641 connman_network_set_string(service->network, "WiFi.EAP", NULL);
5642 connman_network_set_string(service->network, "WiFi.Identity", NULL);
5643 connman_network_set_string(service->network, "WiFi.CACertFile", NULL);
5644 connman_network_set_string(service->network, "WiFi.ClientCertFile", NULL);
5645 connman_network_set_string(service->network, "WiFi.PrivateKeyFile", NULL);
5646 connman_network_set_string(service->network, "WiFi.PrivateKeyPassphrase", NULL);
5647 connman_network_set_string(service->network, "WiFi.Phase2", NULL);
5651 bool __connman_service_remove(struct connman_service *service)
5653 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET ||
5654 service->type == CONNMAN_SERVICE_TYPE_GADGET)
5657 if (service->immutable || service->hidden ||
5658 __connman_provider_is_immutable(service->provider))
5661 #if !defined TIZEN_EXT
5662 if (!service->favorite && !is_idle(service->state))
5666 __connman_service_disconnect(service);
5668 g_free(service->passphrase);
5669 service->passphrase = NULL;
5671 g_free(service->identity);
5672 service->identity = NULL;
5674 g_free(service->anonymous_identity);
5675 service->anonymous_identity = NULL;
5677 g_free(service->subject_match);
5678 service->subject_match = NULL;
5680 g_free(service->altsubject_match);
5681 service->altsubject_match = NULL;
5683 g_free(service->domain_suffix_match);
5684 service->domain_suffix_match = NULL;
5686 g_free(service->domain_match);
5687 service->domain_match = NULL;
5689 g_free(service->agent_identity);
5690 service->agent_identity = NULL;
5692 g_free(service->eap);
5693 service->eap = NULL;
5695 #if defined TIZEN_EXT
5696 g_free(service->ca_cert_file);
5697 service->ca_cert_file = NULL;
5699 g_free(service->client_cert_file);
5700 service->client_cert_file = NULL;
5702 g_free(service->private_key_file);
5703 service->private_key_file = NULL;
5705 g_free(service->private_key_passphrase);
5706 service->private_key_passphrase = NULL;
5708 g_free(service->phase2);
5709 service->phase2 = NULL;
5711 __connman_service_cleanup_network_8021x(service);
5713 __connman_ipconfig_set_method(service->ipconfig_ipv4, CONNMAN_IPCONFIG_METHOD_DHCP);
5714 __connman_ipconfig_set_method(service->ipconfig_ipv6, CONNMAN_IPCONFIG_METHOD_AUTO);
5715 connman_service_set_proxy(service, NULL, false);
5717 __connman_service_nameserver_clear(service);
5719 g_strfreev(service->nameservers_config);
5720 service->nameservers_config = NULL;
5724 #if defined TIZEN_EXT
5725 if (service->security != CONNMAN_SERVICE_SECURITY_8021X)
5729 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
5731 service->user.favorite_user = USER_NONE;
5733 __connman_service_set_favorite(service, false);
5735 __connman_ipconfig_ipv6_reset_privacy(service->ipconfig_ipv6);
5737 #if defined TIZEN_EXT
5738 /* Reset IP Method and DNS Method to DHCP */
5739 __connman_ipconfig_set_method(service->ipconfig_ipv4,
5740 CONNMAN_IPCONFIG_METHOD_DHCP);
5741 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
5742 g_strfreev(service->nameservers_config);
5743 service->nameservers_config = NULL;
5746 #if defined TIZEN_EXT
5747 __connman_storage_remove_service(service->identifier);
5749 service_save(service);
5755 static DBusMessage *remove_service(DBusConnection *conn,
5756 DBusMessage *msg, void *user_data)
5758 struct connman_service *service = user_data;
5760 DBG("service %p", service);
5762 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5764 if (connman_dbus_get_connection_unix_user_sync(conn,
5765 dbus_message_get_sender(msg),
5767 DBG("Can not get unix user id!");
5768 return __connman_error_permission_denied(msg);
5771 #if !defined TIZEN_EXT
5772 if (!connman_service_is_user_allowed(service, uid)) {
5773 DBG("Not allow this user to remove this wifi service now!");
5774 return __connman_error_permission_denied(msg);
5779 if (!__connman_service_remove(service))
5780 return __connman_error_not_supported(msg);
5782 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5785 static bool check_suitable_state(enum connman_service_state a,
5786 enum connman_service_state b)
5789 * Special check so that "ready" service can be moved before
5792 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
5793 b == CONNMAN_SERVICE_STATE_READY) ||
5794 (b == CONNMAN_SERVICE_STATE_ONLINE &&
5795 a == CONNMAN_SERVICE_STATE_READY))
5801 static void downgrade_state(struct connman_service *service)
5806 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
5807 service->state_ipv6);
5809 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
5810 __connman_service_ipconfig_indicate_state(service,
5811 CONNMAN_SERVICE_STATE_READY,
5812 CONNMAN_IPCONFIG_TYPE_IPV4);
5814 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
5815 __connman_service_ipconfig_indicate_state(service,
5816 CONNMAN_SERVICE_STATE_READY,
5817 CONNMAN_IPCONFIG_TYPE_IPV6);
5820 static void apply_relevant_default_downgrade(struct connman_service *service)
5822 struct connman_service *def_service;
5824 def_service = __connman_service_get_default();
5828 if (def_service == service &&
5829 def_service->state == CONNMAN_SERVICE_STATE_ONLINE) {
5830 def_service->state = CONNMAN_SERVICE_STATE_READY;
5831 __connman_notifier_leave_online(def_service->type);
5832 state_changed(def_service);
5836 static void switch_default_service(struct connman_service *default_service,
5837 struct connman_service *downgrade_service)
5839 struct connman_service *service;
5842 apply_relevant_default_downgrade(default_service);
5843 src = g_list_find(service_list, downgrade_service);
5844 dst = g_list_find(service_list, default_service);
5847 if (src == dst || src->next == dst)
5850 service = src->data;
5851 service_list = g_list_delete_link(service_list, src);
5852 service_list = g_list_insert_before(service_list, dst, service);
5854 downgrade_state(downgrade_service);
5857 static DBusMessage *move_service(DBusConnection *conn,
5858 DBusMessage *msg, void *user_data,
5861 struct connman_service *service = user_data;
5862 struct connman_service *target;
5864 enum connman_ipconfig_method target4, target6;
5865 enum connman_ipconfig_method service4, service6;
5867 DBG("service %p", service);
5869 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
5872 if (!service->favorite)
5873 return __connman_error_not_supported(msg);
5875 target = find_service(path);
5876 if (!target || !target->favorite || target == service)
5877 return __connman_error_invalid_service(msg);
5879 if (target->type == CONNMAN_SERVICE_TYPE_VPN) {
5881 * We only allow VPN route splitting if there are
5882 * routes defined for a given VPN.
5884 if (!__connman_provider_check_routes(target->provider)) {
5885 connman_info("Cannot move service. "
5886 "No routes defined for provider %s",
5887 __connman_provider_get_ident(target->provider));
5888 return __connman_error_invalid_service(msg);
5891 set_split_routing(target, true);
5893 set_split_routing(target, false);
5895 set_split_routing(service, false);
5897 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
5898 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
5899 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
5900 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
5902 DBG("target %s method %d/%d state %d/%d split %d", target->identifier,
5903 target4, target6, target->state_ipv4, target->state_ipv6,
5904 target->do_split_routing);
5906 DBG("service %s method %d/%d state %d/%d", service->identifier,
5908 service->state_ipv4, service->state_ipv6);
5911 * If method is OFF, then we do not need to check the corresponding
5914 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5915 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5916 if (!check_suitable_state(target->state_ipv6,
5917 service->state_ipv6))
5918 return __connman_error_invalid_service(msg);
5922 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5923 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5924 if (!check_suitable_state(target->state_ipv4,
5925 service->state_ipv4))
5926 return __connman_error_invalid_service(msg);
5930 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5931 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5932 if (!check_suitable_state(target->state_ipv6,
5933 service->state_ipv6))
5934 return __connman_error_invalid_service(msg);
5938 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5939 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5940 if (!check_suitable_state(target->state_ipv4,
5941 service->state_ipv4))
5942 return __connman_error_invalid_service(msg);
5946 g_get_current_time(&service->modified);
5947 service_save(service);
5948 service_save(target);
5951 * If the service which goes down is the default service and is
5952 * online, we downgrade directly its state to ready so:
5953 * the service which goes up, needs to recompute its state which
5954 * is triggered via downgrading it - if relevant - to state ready.
5957 switch_default_service(target, service);
5959 switch_default_service(service, target);
5961 __connman_connection_update_gateway();
5963 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5966 static DBusMessage *move_before(DBusConnection *conn,
5967 DBusMessage *msg, void *user_data)
5969 return move_service(conn, msg, user_data, true);
5972 static DBusMessage *move_after(DBusConnection *conn,
5973 DBusMessage *msg, void *user_data)
5975 return move_service(conn, msg, user_data, false);
5978 static DBusMessage *reset_counters(DBusConnection *conn,
5979 DBusMessage *msg, void *user_data)
5981 struct connman_service *service = user_data;
5983 reset_stats(service);
5985 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5988 static DBusMessage *get_user_favorite(DBusConnection *conn,
5989 DBusMessage *msg, void *user_data)
5992 uid_t uid = USER_NONE;
5993 dbus_bool_t user_favorite = false;
5994 struct connman_service *service = user_data;
5996 connman_dbus_get_connection_unix_user_sync(conn,
5997 dbus_message_get_sender(msg),
5999 if (uid == USER_ROOT)
6000 user_favorite = service->favorite;
6001 else if (uid != USER_NONE && uid == service->user.favorite_user) {
6002 DBG("The service is favorite to this user!");
6003 user_favorite = true;
6006 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
6007 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN,
6008 &user_favorite, DBUS_TYPE_INVALID);
6012 static struct _services_notify {
6018 static void service_append_added_foreach(gpointer data, gpointer user_data)
6020 struct connman_service *service = data;
6021 DBusMessageIter *iter = user_data;
6023 if (!service || !service->path) {
6024 #if !defined TIZEN_EXT
6025 DBG("service %p or path is NULL", service);
6030 if (g_hash_table_lookup(services_notify->add, service->path)) {
6031 #if !defined TIZEN_EXT
6032 DBG("new %s", service->path);
6035 append_struct(service, iter);
6036 g_hash_table_remove(services_notify->add, service->path);
6038 #if !defined TIZEN_EXT
6039 DBG("changed %s", service->path);
6042 append_struct_service(iter, NULL, service);
6046 static void service_append_ordered(DBusMessageIter *iter, void *user_data)
6048 g_list_foreach(service_list, service_append_added_foreach, iter);
6051 static void append_removed(gpointer key, gpointer value, gpointer user_data)
6053 char *objpath = key;
6054 DBusMessageIter *iter = user_data;
6056 DBG("removed %s", objpath);
6057 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath);
6060 static void service_append_removed(DBusMessageIter *iter, void *user_data)
6062 g_hash_table_foreach(services_notify->remove, append_removed, iter);
6065 static gboolean service_send_changed(gpointer data)
6067 DBusMessage *signal;
6071 services_notify->id = 0;
6073 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
6074 CONNMAN_MANAGER_INTERFACE, "ServicesChanged");
6078 __connman_dbus_append_objpath_dict_array(signal,
6079 service_append_ordered, NULL);
6080 __connman_dbus_append_objpath_array(signal,
6081 service_append_removed, NULL);
6083 dbus_connection_send(connection, signal, NULL);
6084 dbus_message_unref(signal);
6086 g_hash_table_remove_all(services_notify->remove);
6087 g_hash_table_remove_all(services_notify->add);
6092 static void service_schedule_changed(void)
6094 if (services_notify->id != 0)
6097 services_notify->id = g_timeout_add(100, service_send_changed, NULL);
6100 static void service_schedule_added(struct connman_service *service)
6102 DBG("service %p", service);
6104 g_hash_table_remove(services_notify->remove, service->path);
6105 g_hash_table_replace(services_notify->add, service->path, service);
6107 service_schedule_changed();
6110 static void service_schedule_removed(struct connman_service *service)
6112 if (!service || !service->path) {
6113 DBG("service %p or path is NULL", service);
6117 DBG("service %p %s", service, service->path);
6119 g_hash_table_remove(services_notify->add, service->path);
6120 g_hash_table_replace(services_notify->remove, g_strdup(service->path),
6123 service_schedule_changed();
6126 static bool allow_property_changed(struct connman_service *service)
6128 #if defined TIZEN_EXT
6129 if (service->path == NULL)
6132 if (g_hash_table_lookup_extended(services_notify->add, service->path,
6139 static const GDBusMethodTable service_methods[] = {
6140 { GDBUS_DEPRECATED_METHOD("GetProperties",
6141 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
6143 { GDBUS_METHOD("SetProperty",
6144 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
6145 NULL, set_property) },
6146 { GDBUS_METHOD("ClearProperty",
6147 GDBUS_ARGS({ "name", "s" }), NULL,
6149 { GDBUS_ASYNC_METHOD("Connect", NULL, NULL,
6151 { GDBUS_METHOD("Disconnect", NULL, NULL,
6152 disconnect_service) },
6153 { GDBUS_METHOD("Remove", NULL, NULL, remove_service) },
6154 { GDBUS_METHOD("MoveBefore",
6155 GDBUS_ARGS({ "service", "o" }), NULL,
6157 { GDBUS_METHOD("MoveAfter",
6158 GDBUS_ARGS({ "service", "o" }), NULL,
6160 { GDBUS_METHOD("ResetCounters", NULL, NULL, reset_counters) },
6161 { GDBUS_METHOD("GetUserFavorite",
6162 NULL, GDBUS_ARGS({ "value", "v" }),
6163 get_user_favorite) },
6167 static const GDBusSignalTable service_signals[] = {
6168 { GDBUS_SIGNAL("PropertyChanged",
6169 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
6173 static void service_free(gpointer user_data)
6175 struct connman_service *service = user_data;
6176 char *path = service->path;
6178 DBG("service %p", service);
6180 reply_pending(service, ENOENT);
6182 if (service->nameservers_timeout) {
6183 g_source_remove(service->nameservers_timeout);
6184 dns_changed(service);
6187 __connman_notifier_service_remove(service);
6188 service_schedule_removed(service);
6190 __connman_wispr_stop(service);
6191 stats_stop(service);
6193 service->path = NULL;
6196 __connman_connection_update_gateway();
6198 g_dbus_unregister_interface(connection, path,
6199 CONNMAN_SERVICE_INTERFACE);
6203 g_hash_table_destroy(service->counter_table);
6205 if (service->network) {
6206 __connman_network_disconnect(service->network);
6207 connman_network_unref(service->network);
6208 service->network = NULL;
6211 if (service->provider)
6212 connman_provider_unref(service->provider);
6214 if (service->ipconfig_ipv4) {
6215 __connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
6216 __connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
6217 __connman_ipconfig_unref(service->ipconfig_ipv4);
6218 service->ipconfig_ipv4 = NULL;
6221 if (service->ipconfig_ipv6) {
6222 __connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
6223 __connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
6224 __connman_ipconfig_unref(service->ipconfig_ipv6);
6225 service->ipconfig_ipv6 = NULL;
6228 g_strfreev(service->timeservers);
6229 g_strfreev(service->timeservers_config);
6230 g_strfreev(service->nameservers);
6231 g_strfreev(service->nameservers_config);
6232 g_strfreev(service->nameservers_auto);
6233 g_strfreev(service->domains);
6234 g_strfreev(service->proxies);
6235 g_strfreev(service->excludes);
6237 g_free(service->hostname);
6238 g_free(service->domainname);
6239 g_free(service->pac);
6240 g_free(service->name);
6241 g_free(service->passphrase);
6242 g_free(service->identifier);
6243 g_free(service->eap);
6244 g_free(service->identity);
6245 g_free(service->anonymous_identity);
6246 g_free(service->agent_identity);
6247 g_free(service->ca_cert_file);
6248 g_free(service->subject_match);
6249 g_free(service->altsubject_match);
6250 g_free(service->domain_suffix_match);
6251 g_free(service->domain_match);
6252 g_free(service->client_cert_file);
6253 g_free(service->private_key_file);
6254 g_free(service->private_key_passphrase);
6255 g_free(service->phase2);
6256 g_free(service->config_file);
6257 g_free(service->config_entry);
6259 if (service->stats.timer)
6260 g_timer_destroy(service->stats.timer);
6261 if (service->stats_roaming.timer)
6262 g_timer_destroy(service->stats_roaming.timer);
6264 if (current_default == service)
6265 current_default = NULL;
6270 static void stats_init(struct connman_service *service)
6273 service->stats.valid = false;
6274 service->stats.enabled = false;
6275 service->stats.timer = g_timer_new();
6278 service->stats_roaming.valid = false;
6279 service->stats_roaming.enabled = false;
6280 service->stats_roaming.timer = g_timer_new();
6283 static void service_initialize(struct connman_service *service)
6285 DBG("service %p", service);
6287 service->refcount = 1;
6289 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
6291 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
6292 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
6294 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
6295 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
6296 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
6298 service->favorite = false;
6299 service->immutable = false;
6300 service->hidden = false;
6302 service->ignore = false;
6304 service->user.favorite_user = USER_NONE;
6305 service->user.current_user = USER_NONE;
6307 service->request_passphrase_input = false;
6309 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
6313 stats_init(service);
6315 service->provider = NULL;
6317 service->wps = false;
6318 #if defined TIZEN_EXT
6319 service->storage_reload = false;
6321 * Description: TIZEN implements system global connection management.
6323 service->user_pdn_connection_refcount = 0;
6324 __sync_synchronize();
6329 * connman_service_create:
6331 * Allocate a new service.
6333 * Returns: a newly-allocated #connman_service structure
6335 struct connman_service *connman_service_create(void)
6338 struct connman_stats_counter *counters;
6339 const char *counter;
6341 struct connman_service *service;
6343 service = g_try_new0(struct connman_service, 1);
6347 DBG("service %p", service);
6349 service->counter_table = g_hash_table_new_full(g_str_hash,
6350 g_str_equal, NULL, g_free);
6352 for (list = counter_list; list; list = list->next) {
6353 counter = list->data;
6355 counters = g_try_new0(struct connman_stats_counter, 1);
6357 g_hash_table_destroy(service->counter_table);
6362 counters->append_all = true;
6364 g_hash_table_replace(service->counter_table, (gpointer)counter,
6368 service_initialize(service);
6374 * connman_service_ref:
6375 * @service: service structure
6377 * Increase reference counter of service
6379 struct connman_service *
6380 connman_service_ref_debug(struct connman_service *service,
6381 const char *file, int line, const char *caller)
6383 DBG("%p ref %d by %s:%d:%s()", service, service->refcount + 1,
6384 file, line, caller);
6386 __sync_fetch_and_add(&service->refcount, 1);
6392 * connman_service_unref:
6393 * @service: service structure
6395 * Decrease reference counter of service and release service if no
6398 void connman_service_unref_debug(struct connman_service *service,
6399 const char *file, int line, const char *caller)
6401 DBG("%p ref %d by %s:%d:%s()", service, service->refcount - 1,
6402 file, line, caller);
6404 if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
6407 service_list = g_list_remove(service_list, service);
6409 __connman_service_disconnect(service);
6411 g_hash_table_remove(service_hash, service->identifier);
6414 static gint service_compare(gconstpointer a, gconstpointer b)
6416 struct connman_service *service_a = (void *) a;
6417 struct connman_service *service_b = (void *) b;
6418 enum connman_service_state state_a, state_b;
6419 bool a_connected, b_connected;
6422 state_a = service_a->state;
6423 state_b = service_b->state;
6424 a_connected = is_connected(state_a);
6425 b_connected = is_connected(state_b);
6427 if (a_connected && b_connected) {
6428 if (service_a->order > service_b->order)
6431 if (service_a->order < service_b->order)
6435 if (state_a != state_b) {
6436 if (a_connected && b_connected) {
6437 /* We prefer online over ready state */
6438 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
6441 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
6450 if (is_connecting(state_a))
6452 if (is_connecting(state_b))
6456 if (service_a->favorite && !service_b->favorite)
6459 if (!service_a->favorite && service_b->favorite)
6462 if (service_a->type != service_b->type) {
6463 unsigned int *tech_array;
6466 tech_array = connman_setting_get_uint_list(
6467 "PreferredTechnologies");
6469 for (i = 0; tech_array[i]; i++) {
6470 if (tech_array[i] == service_a->type)
6473 if (tech_array[i] == service_b->type)
6478 if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6480 if (service_b->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6483 if (service_a->type == CONNMAN_SERVICE_TYPE_WIFI)
6485 if (service_b->type == CONNMAN_SERVICE_TYPE_WIFI)
6488 if (service_a->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6490 if (service_b->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6493 if (service_a->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6495 if (service_b->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6498 if (service_a->type == CONNMAN_SERVICE_TYPE_VPN)
6500 if (service_b->type == CONNMAN_SERVICE_TYPE_VPN)
6503 if (service_a->type == CONNMAN_SERVICE_TYPE_GADGET)
6505 if (service_b->type == CONNMAN_SERVICE_TYPE_GADGET)
6509 strength = (gint) service_b->strength - (gint) service_a->strength;
6513 return g_strcmp0(service_a->name, service_b->name);
6516 static void service_list_sort(void)
6518 if (service_list && service_list->next) {
6519 service_list = g_list_sort(service_list, service_compare);
6520 service_schedule_changed();
6524 int __connman_service_compare(const struct connman_service *a,
6525 const struct connman_service *b)
6527 return service_compare(a, b);
6531 * connman_service_get_type:
6532 * @service: service structure
6534 * Get the type of service
6536 enum connman_service_type connman_service_get_type(struct connman_service *service)
6539 return CONNMAN_SERVICE_TYPE_UNKNOWN;
6541 return service->type;
6545 * connman_service_get_interface:
6546 * @service: service structure
6548 * Get network interface of service
6550 char *connman_service_get_interface(struct connman_service *service)
6557 index = __connman_service_get_index(service);
6559 return connman_inet_ifname(index);
6563 * __connman_service_is_user_allowed:
6564 * @type: service type
6567 * Check a user is allowed to operate a type of service
6569 bool __connman_service_is_user_allowed(enum connman_service_type type,
6573 uid_t owner_user = USER_NONE;
6575 for (list = service_list; list; list = list->next) {
6576 struct connman_service *service = list->data;
6578 if (service->type != type)
6581 if (is_connected(service->state)) {
6582 owner_user = service->user.favorite_user;
6587 if (uid == USER_NONE ||
6588 (uid != USER_ROOT &&
6589 owner_user != USER_NONE &&
6597 * connman_service_get_network:
6598 * @service: service structure
6600 * Get the service network
6602 struct connman_network *
6603 __connman_service_get_network(struct connman_service *service)
6608 return service->network;
6611 struct connman_ipconfig *
6612 __connman_service_get_ip4config(struct connman_service *service)
6617 return service->ipconfig_ipv4;
6620 struct connman_ipconfig *
6621 __connman_service_get_ip6config(struct connman_service *service)
6626 return service->ipconfig_ipv6;
6629 struct connman_ipconfig *
6630 __connman_service_get_ipconfig(struct connman_service *service, int family)
6632 if (family == AF_INET)
6633 return __connman_service_get_ip4config(service);
6634 else if (family == AF_INET6)
6635 return __connman_service_get_ip6config(service);
6641 bool __connman_service_is_connected_state(struct connman_service *service,
6642 enum connman_ipconfig_type type)
6648 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
6650 case CONNMAN_IPCONFIG_TYPE_IPV4:
6651 return is_connected(service->state_ipv4);
6652 case CONNMAN_IPCONFIG_TYPE_IPV6:
6653 return is_connected(service->state_ipv6);
6654 case CONNMAN_IPCONFIG_TYPE_ALL:
6655 return is_connected(service->state_ipv4) &&
6656 is_connected(service->state_ipv6);
6661 enum connman_service_security __connman_service_get_security(
6662 struct connman_service *service)
6665 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
6667 return service->security;
6670 const char *__connman_service_get_phase2(struct connman_service *service)
6675 return service->phase2;
6678 bool __connman_service_wps_enabled(struct connman_service *service)
6683 return service->wps;
6686 void __connman_service_mark_dirty(void)
6688 services_dirty = true;
6691 #if defined TIZEN_EXT
6693 * Returns profile count if there is any connected profiles
6694 * that use same interface
6696 int __connman_service_get_connected_count_of_iface(
6697 struct connman_service *service)
6706 index1 = __connman_service_get_index(service);
6711 for (list = service_list; list; list = list->next) {
6712 struct connman_service *service2 = list->data;
6714 if (service == service2)
6717 index2 = __connman_service_get_index(service2);
6719 if (is_connected(service2->state) && index2 > 0 && index1 == index2)
6725 DBG("Interface index %d, count %d", index1, count);
6730 void __connman_service_set_storage_reload(struct connman_service *service,
6731 bool storage_reload)
6733 if (service != NULL)
6734 service->storage_reload = storage_reload;
6739 * __connman_service_set_favorite_delayed:
6740 * @service: service structure
6741 * @favorite: favorite value
6742 * @delay_ordering: do not order service sequence
6744 * Change the favorite setting of service
6746 int __connman_service_set_favorite_delayed(struct connman_service *service,
6748 bool delay_ordering)
6750 #if defined TIZEN_EXT
6751 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6754 if (service->hidden)
6757 if (service->favorite == favorite)
6760 service->favorite = favorite;
6762 if (!delay_ordering)
6763 __connman_service_get_order(service);
6765 favorite_changed(service);
6767 if (!delay_ordering) {
6769 service_list_sort();
6771 __connman_connection_update_gateway();
6778 * __connman_service_set_favorite:
6779 * @service: service structure
6780 * @favorite: favorite value
6782 * Change the favorite setting of service
6784 int __connman_service_set_favorite(struct connman_service *service,
6787 return __connman_service_set_favorite_delayed(service, favorite,
6791 bool connman_service_get_favorite(struct connman_service *service)
6793 return service->favorite;
6796 bool connman_service_get_autoconnect(struct connman_service *service)
6798 return service->autoconnect;
6801 int __connman_service_set_immutable(struct connman_service *service,
6804 if (service->hidden)
6807 if (service->immutable == immutable)
6810 service->immutable = immutable;
6812 immutable_changed(service);
6817 int __connman_service_set_ignore(struct connman_service *service,
6823 service->ignore = ignore;
6828 void __connman_service_set_string(struct connman_service *service,
6829 const char *key, const char *value)
6831 if (service->hidden)
6833 if (g_str_equal(key, "EAP")) {
6834 g_free(service->eap);
6835 service->eap = g_strdup(value);
6836 } else if (g_str_equal(key, "Identity")) {
6837 g_free(service->identity);
6838 service->identity = g_strdup(value);
6839 } else if (g_str_equal(key, "AnonymousIdentity")) {
6840 g_free(service->anonymous_identity);
6841 service->anonymous_identity = g_strdup(value);
6842 } else if (g_str_equal(key, "CACertFile")) {
6843 g_free(service->ca_cert_file);
6844 service->ca_cert_file = g_strdup(value);
6845 } else if (g_str_equal(key, "SubjectMatch")) {
6846 g_free(service->subject_match);
6847 service->subject_match = g_strdup(value);
6848 } else if (g_str_equal(key, "AltSubjectMatch")) {
6849 g_free(service->altsubject_match);
6850 service->altsubject_match = g_strdup(value);
6851 } else if (g_str_equal(key, "DomainSuffixMatch")) {
6852 g_free(service->domain_suffix_match);
6853 service->domain_suffix_match = g_strdup(value);
6854 } else if (g_str_equal(key, "DomainMatch")) {
6855 g_free(service->domain_match);
6856 service->domain_match = g_strdup(value);
6857 } else if (g_str_equal(key, "ClientCertFile")) {
6858 g_free(service->client_cert_file);
6859 service->client_cert_file = g_strdup(value);
6860 } else if (g_str_equal(key, "PrivateKeyFile")) {
6861 g_free(service->private_key_file);
6862 service->private_key_file = g_strdup(value);
6863 } else if (g_str_equal(key, "PrivateKeyPassphrase")) {
6864 g_free(service->private_key_passphrase);
6865 service->private_key_passphrase = g_strdup(value);
6866 } else if (g_str_equal(key, "Phase2")) {
6867 g_free(service->phase2);
6868 service->phase2 = g_strdup(value);
6869 } else if (g_str_equal(key, "Passphrase"))
6870 __connman_service_set_passphrase(service, value);
6873 void __connman_service_set_search_domains(struct connman_service *service,
6876 searchdomain_remove_all(service);
6878 if (service->domains)
6879 g_strfreev(service->domains);
6881 service->domains = g_strdupv(domains);
6883 searchdomain_add_all(service);
6886 static void report_error_cb(void *user_context, bool retry,
6889 struct connman_service *service = user_context;
6892 __connman_service_connect(service,
6893 CONNMAN_SERVICE_CONNECT_REASON_USER);
6895 /* It is not relevant to stay on Failure state
6896 * when failing is due to wrong user input */
6897 __connman_service_clear_error(service);
6898 #if defined TIZEN_EXT
6899 /* Reseting the state back in case of failure state */
6900 service->state_ipv4 = service->state_ipv6 =
6901 CONNMAN_SERVICE_STATE_IDLE;
6903 if (service->error != CONNMAN_SERVICE_ERROR_AUTH_FAILED)
6904 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6906 service_complete(service);
6907 __connman_connection_update_gateway();
6911 static int check_wpspin(struct connman_service *service, const char *wpspin)
6919 length = strlen(wpspin);
6921 /* If 0, it will mean user wants to use PBC method */
6923 connman_network_set_string(service->network,
6924 "WiFi.PinWPS", NULL);
6928 /* A WPS PIN is always 8 chars length,
6929 * its content is in digit representation.
6934 for (i = 0; i < 8; i++)
6935 if (!isdigit((unsigned char) wpspin[i]))
6938 connman_network_set_string(service->network, "WiFi.PinWPS", wpspin);
6943 static void request_input_cb(struct connman_service *service,
6944 bool values_received,
6945 const char *name, int name_len,
6946 const char *identity, const char *passphrase,
6947 bool wps, const char *wpspin,
6948 const char *error, void *user_data)
6950 struct connman_device *device;
6951 const char *security;
6954 DBG("RequestInput return, %p", service);
6957 DBG("error: %s", error);
6959 if (g_strcmp0(error,
6960 "net.connman.Agent.Error.Canceled") == 0) {
6963 if (service->hidden)
6964 __connman_service_return_error(service,
6969 if (service->hidden)
6970 __connman_service_return_error(service,
6971 ETIMEDOUT, user_data);
6975 if (service->hidden && name_len > 0 && name_len <= 32) {
6976 device = connman_network_get_device(service->network);
6977 security = connman_network_get_string(service->network,
6979 err = __connman_device_request_hidden_scan(device,
6981 identity, passphrase,
6982 security, user_data);
6984 __connman_service_return_error(service, -err,
6988 if (!values_received || service->hidden) {
6993 if (wps && service->network) {
6994 err = check_wpspin(service, wpspin);
6998 connman_network_set_bool(service->network, "WiFi.UseWPS", wps);
7002 __connman_service_set_agent_identity(service, identity);
7005 err = __connman_service_set_passphrase(service, passphrase);
7009 /* We forget any previous error. */
7010 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7012 __connman_service_connect(service,
7013 CONNMAN_SERVICE_CONNECT_REASON_USER);
7015 } else if (err == -ENOKEY) {
7016 __connman_service_indicate_error(service,
7017 CONNMAN_SERVICE_ERROR_INVALID_KEY);
7019 /* It is not relevant to stay on Failure state
7020 * when failing is due to wrong user input */
7021 service->state = CONNMAN_SERVICE_STATE_IDLE;
7023 if (!service->hidden) {
7025 * If there was a real error when requesting
7026 * hidden scan, then that error is returned already
7027 * to the user somewhere above so do not try to
7030 __connman_service_return_error(service, -err,
7034 service_complete(service);
7035 __connman_connection_update_gateway();
7039 static void downgrade_connected_services(void)
7041 struct connman_service *up_service;
7044 for (list = service_list; list; list = list->next) {
7045 up_service = list->data;
7047 if (!is_connected(up_service->state))
7050 if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
7053 downgrade_state(up_service);
7057 static int service_update_preferred_order(struct connman_service *default_service,
7058 struct connman_service *new_service,
7059 enum connman_service_state new_state)
7061 unsigned int *tech_array;
7064 if (!default_service || default_service == new_service ||
7065 default_service->state != new_state)
7068 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
7071 for (i = 0; tech_array[i] != 0; i += 1) {
7072 if (default_service->type == tech_array[i])
7075 if (new_service->type == tech_array[i]) {
7076 switch_default_service(default_service,
7078 __connman_connection_update_gateway();
7087 #if defined TIZEN_EXT
7088 static gboolean __connman_service_can_drop(struct connman_service *service)
7090 if (is_connected(service->state) == TRUE || is_connecting(service->state) == TRUE) {
7091 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
7093 else if (connman_service_is_no_ref_user_pdn_connection(service) == TRUE)
7099 static struct connman_device *default_connecting_device = NULL;
7101 static void __connman_service_disconnect_default(struct connman_service *service)
7103 struct connman_device *default_device = NULL;
7105 if (default_connecting_device == NULL)
7108 default_device = connman_network_get_device(
7109 __connman_service_get_network(service));
7111 DBG("Disconnecting service %p %s", service, service->path);
7112 DBG("Disconnecting device %p %p %s",
7113 default_connecting_device,
7115 connman_device_get_string(default_device, "Name"));
7117 if (default_connecting_device == default_device)
7118 default_connecting_device = NULL;
7121 static void __connman_service_connect_default(struct connman_service *current)
7125 bool default_internet;
7126 struct connman_service *service;
7127 struct connman_service *default_service = NULL;
7128 struct connman_device *default_device = NULL;
7130 if (current->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
7131 switch (current->state) {
7132 case CONNMAN_SERVICE_STATE_UNKNOWN:
7133 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7134 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7140 if (default_connecting_device &&
7141 __connman_service_is_internet_profile(current) == TRUE) {
7142 if (current->network == NULL)
7145 default_device = connman_network_get_device(current->network);
7146 if (default_connecting_device == default_device) {
7147 DBG("Cellular service[%s] %p %s",
7148 state2string(current->state), current, current->path);
7149 DBG("Cellular device %p %p %s",
7150 default_connecting_device, default_device,
7151 connman_device_get_string(default_device, "Name"));
7153 default_connecting_device = NULL;
7158 } else if (is_connected(current->state) == TRUE || is_connecting(current->state) == TRUE)
7161 /* Always-on: keep default cellular connection as possible */
7162 for (list = service_list; list; list = list->next) {
7163 service = list->data;
7165 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7166 __connman_service_is_internet_profile(service) != TRUE ||
7167 service->network == NULL) {
7172 connman_network_get_bool(service->network, "DefaultInternet");
7174 DBG("service: %p %s %s %s (default: %d)", service, service->name,
7175 __connman_service_type2string(service->type),
7176 state2string(service->state), default_internet);
7178 if (default_internet) {
7179 default_service = service;
7180 if (is_connected(default_service->state) == TRUE ||
7181 is_connecting(default_service->state) == TRUE)
7184 default_device = connman_network_get_device(default_service->network);
7185 if (default_connecting_device == default_device) {
7186 DBG("Device is connecting (%p)", default_connecting_device);
7190 default_connecting_device = default_device;
7191 default_service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_USER;
7193 err = __connman_network_connect(default_service->network);
7194 DBG("Connecting default service %p %s [%d]",
7195 default_service, default_service->path, err);
7196 DBG("Connecting device %p %s", default_connecting_device,
7197 connman_device_get_string(default_connecting_device, "Name"));
7198 if (err < 0 && err != -EINPROGRESS) {
7199 default_connecting_device = NULL;
7207 static void single_connected_tech(struct connman_service *allowed)
7209 struct connman_service *service;
7210 GSList *services = NULL, *list;
7213 DBG("keeping %p %s", allowed, allowed->path);
7215 #if defined TIZEN_EXT
7216 if (!allowed || allowed->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7220 for (iter = service_list; iter; iter = iter->next) {
7221 service = iter->data;
7223 #if defined TIZEN_EXT
7224 if (service != allowed && service->type != allowed->type &&
7225 __connman_service_can_drop(service) == TRUE)
7227 if (!is_connected(service->state))
7230 if (service == allowed)
7233 services = g_slist_prepend(services, service);
7236 for (list = services; list; list = list->next) {
7237 service = list->data;
7239 DBG("disconnecting %p %s", service, service->path);
7240 #if defined TIZEN_EXT
7241 __connman_service_disconnect_default(service);
7243 __connman_service_disconnect(service);
7246 g_slist_free(services);
7249 #if defined TIZEN_EXT
7250 static void set_priority_connected_service(void)
7252 struct connman_service *service;
7255 for (list = service_list; list; list = list->next) {
7256 service = list->data;
7258 if (is_connected(service->state) == FALSE)
7266 static const char *get_dbus_sender(struct connman_service *service)
7268 if (!service->pending)
7271 return dbus_message_get_sender(service->pending);
7274 static int service_indicate_state(struct connman_service *service)
7276 enum connman_service_state old_state, new_state;
7277 struct connman_service *def_service;
7278 enum connman_ipconfig_method method;
7284 old_state = service->state;
7285 new_state = combine_state(service->state_ipv4, service->state_ipv6);
7287 DBG("service %p old %s - new %s/%s => %s",
7289 state2string(old_state),
7290 state2string(service->state_ipv4),
7291 state2string(service->state_ipv6),
7292 state2string(new_state));
7294 if (old_state == new_state)
7297 def_service = __connman_service_get_default();
7299 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
7300 result = service_update_preferred_order(def_service,
7301 service, new_state);
7302 if (result == -EALREADY)
7306 if (old_state == CONNMAN_SERVICE_STATE_ONLINE)
7307 __connman_notifier_leave_online(service->type);
7309 if (is_connected(old_state) && !is_connected(new_state))
7310 searchdomain_remove_all(service);
7312 service->state = new_state;
7313 state_changed(service);
7315 if (!is_connected(old_state) && is_connected(new_state))
7316 searchdomain_add_all(service);
7319 case CONNMAN_SERVICE_STATE_UNKNOWN:
7323 case CONNMAN_SERVICE_STATE_IDLE:
7324 if (old_state != CONNMAN_SERVICE_STATE_DISCONNECT)
7325 __connman_service_disconnect(service);
7329 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7333 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7334 if (!service->new_service &&
7335 __connman_stats_service_register(service) == 0) {
7337 * For new services the statistics are updated after
7338 * we have successfully connected.
7340 __connman_stats_get(service, false,
7341 &service->stats.data);
7342 __connman_stats_get(service, true,
7343 &service->stats_roaming.data);
7348 case CONNMAN_SERVICE_STATE_READY:
7349 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7351 if (service->new_service &&
7352 __connman_stats_service_register(service) == 0) {
7354 * This is normally done after configuring state
7355 * but for new service do this after we have connected
7358 __connman_stats_get(service, false,
7359 &service->stats.data);
7360 __connman_stats_get(service, true,
7361 &service->stats_roaming.data);
7364 service->new_service = false;
7368 def_service = __connman_service_get_default();
7370 service_update_preferred_order(def_service, service, new_state);
7372 __connman_service_set_favorite(service, true);
7374 reply_pending(service, 0);
7376 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7377 connman_network_get_bool(service->network,
7381 pass = connman_network_get_string(service->network,
7384 __connman_service_set_passphrase(service, pass);
7386 connman_network_set_bool(service->network,
7387 "WiFi.UseWPS", false);
7390 g_get_current_time(&service->modified);
7391 service_save(service);
7393 domain_changed(service);
7394 proxy_changed(service);
7396 if (old_state != CONNMAN_SERVICE_STATE_ONLINE)
7397 __connman_notifier_connect(service->type);
7399 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
7400 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
7401 __connman_ipconfig_disable_ipv6(
7402 service->ipconfig_ipv6);
7404 if (connman_setting_get_bool("SingleConnectedTechnology"))
7405 single_connected_tech(service);
7406 else if (service->type != CONNMAN_SERVICE_TYPE_VPN)
7409 #if defined TIZEN_EXT
7410 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7411 set_priority_connected_service();
7416 case CONNMAN_SERVICE_STATE_ONLINE:
7420 case CONNMAN_SERVICE_STATE_DISCONNECT:
7421 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7423 reply_pending(service, ECONNABORTED);
7425 def_service = __connman_service_get_default();
7426 service->disconnect_reason = connman_network_get_disconnect_reason(service->network);
7427 service->assoc_status_code = connman_network_get_assoc_status_code(service->network);
7429 if (!__connman_notifier_is_connected() &&
7431 def_service->provider)
7432 connman_provider_disconnect(def_service->provider);
7436 __connman_wispr_stop(service);
7438 __connman_wpad_stop(service);
7440 #if defined TIZEN_EXT
7442 * Skip the functions if there is any connected profiles
7443 * that use same interface
7445 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7446 __connman_service_get_connected_count_of_iface(
7449 domain_changed(service);
7450 proxy_changed(service);
7451 #if defined TIZEN_EXT
7456 * Previous services which are connected and which states
7457 * are set to online should reset relevantly ipconfig_state
7458 * to ready so wispr/portal will be rerun on those
7460 downgrade_connected_services();
7462 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7465 case CONNMAN_SERVICE_STATE_FAILURE:
7466 #if defined TIZEN_EXT
7467 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7469 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7471 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7472 connman_agent_report_error(service, service->path,
7473 error2string(service->error),
7475 get_dbus_sender(service),
7476 NULL) == -EINPROGRESS)
7478 service_complete(service);
7483 service_list_sort();
7485 #if defined TIZEN_EXT
7486 __connman_service_connect_default(service);
7489 __connman_connection_update_gateway();
7491 if ((old_state == CONNMAN_SERVICE_STATE_ONLINE &&
7492 new_state != CONNMAN_SERVICE_STATE_READY) ||
7493 (old_state == CONNMAN_SERVICE_STATE_READY &&
7494 new_state != CONNMAN_SERVICE_STATE_ONLINE)) {
7495 __connman_notifier_disconnect(service->type);
7498 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
7499 __connman_notifier_enter_online(service->type);
7503 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7504 service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7505 (new_state == CONNMAN_SERVICE_STATE_READY ||
7506 new_state == CONNMAN_SERVICE_STATE_ONLINE)) {
7507 if (service->user.favorite_user != service->user.current_user) {
7508 DBG("Now set service favorite user id from %d to %d",
7509 service->user.favorite_user, service->user.current_user);
7511 service->user.favorite_user = service->user.current_user;
7513 service_save(service);
7520 int __connman_service_indicate_error(struct connman_service *service,
7521 enum connman_service_error error)
7523 DBG("service %p error %d", service, error);
7528 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
7531 set_error(service, error);
7533 /* default internet service: fix not cleared if pdp activation*/
7534 #if defined TIZEN_EXT
7536 * If connection failed for default service(DefaultInternet),
7537 * default_connecting_device should be cleared.
7539 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7540 service->error == CONNMAN_SERVICE_ERROR_CONNECT_FAILED)
7541 __connman_service_disconnect_default(service);
7543 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7544 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY) {
7545 g_free(service->passphrase);
7546 service->passphrase = NULL;
7550 __connman_service_ipconfig_indicate_state(service,
7551 CONNMAN_SERVICE_STATE_FAILURE,
7552 CONNMAN_IPCONFIG_TYPE_IPV4);
7553 __connman_service_ipconfig_indicate_state(service,
7554 CONNMAN_SERVICE_STATE_FAILURE,
7555 CONNMAN_IPCONFIG_TYPE_IPV6);
7559 int __connman_service_clear_error(struct connman_service *service)
7561 DBusMessage *pending, *provider_pending;
7563 DBG("service %p", service);
7568 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
7571 pending = service->pending;
7572 service->pending = NULL;
7573 provider_pending = service->provider_pending;
7574 service->provider_pending = NULL;
7576 __connman_service_ipconfig_indicate_state(service,
7577 CONNMAN_SERVICE_STATE_IDLE,
7578 CONNMAN_IPCONFIG_TYPE_IPV6);
7580 __connman_service_ipconfig_indicate_state(service,
7581 CONNMAN_SERVICE_STATE_IDLE,
7582 CONNMAN_IPCONFIG_TYPE_IPV4);
7584 service->pending = pending;
7585 service->provider_pending = provider_pending;
7590 int __connman_service_indicate_default(struct connman_service *service)
7592 DBG("service %p state %s", service, state2string(service->state));
7594 if (!is_connected(service->state)) {
7596 * If service is not yet fully connected, then we must not
7597 * change the default yet. The default gw will be changed
7598 * after the service state is in ready.
7600 return -EINPROGRESS;
7608 enum connman_service_state __connman_service_ipconfig_get_state(
7609 struct connman_service *service,
7610 enum connman_ipconfig_type type)
7613 return CONNMAN_SERVICE_STATE_UNKNOWN;
7615 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7616 return service->state_ipv4;
7618 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
7619 return service->state_ipv6;
7621 return CONNMAN_SERVICE_STATE_UNKNOWN;
7624 static void check_proxy_setup(struct connman_service *service)
7627 * We start WPAD if we haven't got a PAC URL from DHCP and
7628 * if our proxy manual configuration is either empty or set
7629 * to AUTO with an empty URL.
7632 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
7635 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
7636 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
7640 if (__connman_wpad_start(service) < 0) {
7641 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
7642 __connman_notifier_proxy_changed(service);
7649 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
7652 #if defined TIZEN_EXT
7653 void connman_check_proxy_setup_and_wispr_start(struct connman_service *service){
7655 DBG("check the proxy and start wispr");
7656 check_proxy_setup(service);
7662 * How many networks are connected at the same time. If more than 1,
7663 * then set the rp_filter setting properly (loose mode routing) so that network
7664 * connectivity works ok. This is only done for IPv4 networks as IPv6
7665 * does not have rp_filter knob.
7667 static int connected_networks_count;
7668 static int original_rp_filter;
7670 static void service_rp_filter(struct connman_service *service,
7673 enum connman_ipconfig_method method;
7675 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
7678 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7679 case CONNMAN_IPCONFIG_METHOD_OFF:
7680 case CONNMAN_IPCONFIG_METHOD_AUTO:
7682 case CONNMAN_IPCONFIG_METHOD_FIXED:
7683 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7684 case CONNMAN_IPCONFIG_METHOD_DHCP:
7689 if (connected_networks_count == 1) {
7691 filter_value = __connman_ipconfig_set_rp_filter();
7692 if (filter_value < 0)
7695 original_rp_filter = filter_value;
7697 connected_networks_count++;
7700 if (connected_networks_count == 2)
7701 __connman_ipconfig_unset_rp_filter(original_rp_filter);
7703 connected_networks_count--;
7704 if (connected_networks_count < 0)
7705 connected_networks_count = 0;
7708 DBG("%s %s ipconfig %p method %d count %d filter %d",
7709 connected ? "connected" : "disconnected", service->identifier,
7710 service->ipconfig_ipv4, method,
7711 connected_networks_count, original_rp_filter);
7714 static gboolean redo_wispr(gpointer user_data)
7716 struct connman_service *service = user_data;
7717 int refcount = service->refcount - 1;
7719 connman_service_unref(service);
7720 if (refcount == 0) {
7721 DBG("Service %p already removed", service);
7725 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV6);
7730 int __connman_service_online_check_failed(struct connman_service *service,
7731 enum connman_ipconfig_type type)
7733 DBG("service %p type %d count %d", service, type,
7734 service->online_check_count);
7736 /* currently we only retry IPv6 stuff */
7737 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 ||
7738 service->online_check_count != 1) {
7739 connman_warn("Online check failed for %p %s", service,
7744 service->online_check_count = 0;
7747 * We set the timeout to 1 sec so that we have a chance to get
7748 * necessary IPv6 router advertisement messages that might have
7751 g_timeout_add_seconds(1, redo_wispr, connman_service_ref(service));
7756 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
7757 enum connman_service_state new_state,
7758 enum connman_ipconfig_type type)
7760 struct connman_ipconfig *ipconfig = NULL;
7761 enum connman_service_state old_state;
7762 enum connman_ipconfig_method method;
7768 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
7769 case CONNMAN_IPCONFIG_TYPE_ALL:
7772 case CONNMAN_IPCONFIG_TYPE_IPV4:
7773 old_state = service->state_ipv4;
7774 ipconfig = service->ipconfig_ipv4;
7778 case CONNMAN_IPCONFIG_TYPE_IPV6:
7779 old_state = service->state_ipv6;
7780 ipconfig = service->ipconfig_ipv6;
7788 method = __connman_ipconfig_get_method(ipconfig);
7791 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7792 case CONNMAN_IPCONFIG_METHOD_OFF:
7793 if (new_state != CONNMAN_SERVICE_STATE_IDLE)
7794 connman_warn("ipconfig state %d ipconfig method %d",
7797 new_state = CONNMAN_SERVICE_STATE_IDLE;
7800 case CONNMAN_IPCONFIG_METHOD_FIXED:
7801 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7802 case CONNMAN_IPCONFIG_METHOD_DHCP:
7803 case CONNMAN_IPCONFIG_METHOD_AUTO:
7809 if (old_state == new_state)
7812 #if defined TIZEN_EXT
7813 __sync_synchronize();
7814 if (service->user_pdn_connection_refcount > 0 &&
7815 service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7816 if (new_state == CONNMAN_SERVICE_STATE_FAILURE ||
7817 new_state == CONNMAN_SERVICE_STATE_DISCONNECT ||
7818 new_state == CONNMAN_SERVICE_STATE_IDLE) {
7819 service->user_pdn_connection_refcount = 0;
7820 __sync_synchronize();
7824 DBG("service %p (%s) old state %d (%s) new state %d (%s) type %d (%s)",
7825 service, service ? service->identifier : NULL,
7826 old_state, state2string(old_state),
7827 new_state, state2string(new_state),
7828 type, __connman_ipconfig_type2string(type));
7830 switch (new_state) {
7831 case CONNMAN_SERVICE_STATE_UNKNOWN:
7832 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7834 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7836 case CONNMAN_SERVICE_STATE_READY:
7837 #if defined TIZEN_EXT
7838 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7839 __connman_service_is_internet_profile(service) != TRUE) {
7840 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7841 service_rp_filter(service, TRUE);
7846 if (connman_setting_get_bool("EnableOnlineCheck")) {
7847 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
7848 #if !defined TIZEN_EXT
7849 check_proxy_setup(service);
7852 service->online_check_count = 1;
7853 __connman_wispr_start(service, type);
7856 connman_info("Online check disabled. "
7857 "Default service remains in READY state.");
7858 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7859 service_rp_filter(service, true);
7861 case CONNMAN_SERVICE_STATE_ONLINE:
7863 case CONNMAN_SERVICE_STATE_DISCONNECT:
7864 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
7867 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7868 service_rp_filter(service, false);
7872 case CONNMAN_SERVICE_STATE_IDLE:
7873 case CONNMAN_SERVICE_STATE_FAILURE:
7874 __connman_ipconfig_disable(ipconfig);
7879 if (is_connected(old_state) && !is_connected(new_state))
7880 nameserver_remove_all(service, type);
7882 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7883 service->state_ipv4 = new_state;
7885 service->state_ipv6 = new_state;
7887 if (!is_connected(old_state) && is_connected(new_state))
7888 nameserver_add_all(service, type);
7890 __connman_timeserver_sync(service);
7892 #if defined TIZEN_EXT
7893 int ret = service_indicate_state(service);
7894 /*Sent the Ready changed signal again in case IPv4 IP set
7897 if(ret == -EALREADY && type == CONNMAN_IPCONFIG_TYPE_IPV4
7898 && new_state == CONNMAN_SERVICE_STATE_READY) {
7899 DBG("Notify IPv4 state new/old %d/%d", new_state,old_state);
7900 state_changed(service);
7905 return service_indicate_state(service);
7908 static bool prepare_network(struct connman_service *service)
7910 enum connman_network_type type;
7911 unsigned int ssid_len;
7913 type = connman_network_get_type(service->network);
7916 case CONNMAN_NETWORK_TYPE_UNKNOWN:
7917 case CONNMAN_NETWORK_TYPE_VENDOR:
7919 case CONNMAN_NETWORK_TYPE_WIFI:
7920 if (!connman_network_get_blob(service->network, "WiFi.SSID",
7924 if (service->passphrase)
7925 connman_network_set_string(service->network,
7926 "WiFi.Passphrase", service->passphrase);
7928 case CONNMAN_NETWORK_TYPE_ETHERNET:
7929 case CONNMAN_NETWORK_TYPE_GADGET:
7930 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
7931 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
7932 case CONNMAN_NETWORK_TYPE_CELLULAR:
7939 static void prepare_8021x(struct connman_service *service)
7942 connman_network_set_string(service->network, "WiFi.EAP",
7945 if (service->identity)
7946 connman_network_set_string(service->network, "WiFi.Identity",
7949 if (service->anonymous_identity)
7950 connman_network_set_string(service->network,
7951 "WiFi.AnonymousIdentity",
7952 service->anonymous_identity);
7954 if (service->ca_cert_file)
7955 connman_network_set_string(service->network, "WiFi.CACertFile",
7956 service->ca_cert_file);
7958 if (service->subject_match)
7959 connman_network_set_string(service->network, "WiFi.SubjectMatch",
7960 service->subject_match);
7962 if (service->altsubject_match)
7963 connman_network_set_string(service->network, "WiFi.AltSubjectMatch",
7964 service->altsubject_match);
7966 if (service->domain_suffix_match)
7967 connman_network_set_string(service->network, "WiFi.DomainSuffixMatch",
7968 service->domain_suffix_match);
7970 if (service->domain_match)
7971 connman_network_set_string(service->network, "WiFi.DomainMatch",
7972 service->domain_match);
7974 if (service->client_cert_file)
7975 connman_network_set_string(service->network,
7976 "WiFi.ClientCertFile",
7977 service->client_cert_file);
7979 if (service->private_key_file)
7980 connman_network_set_string(service->network,
7981 "WiFi.PrivateKeyFile",
7982 service->private_key_file);
7984 if (service->private_key_passphrase)
7985 connman_network_set_string(service->network,
7986 "WiFi.PrivateKeyPassphrase",
7987 service->private_key_passphrase);
7989 if (service->phase2)
7990 connman_network_set_string(service->network, "WiFi.Phase2",
7993 #if defined TIZEN_EXT
7994 if (service->keymgmt_type)
7995 connman_network_set_string(service->network, "WiFi.KeymgmtType",
7996 service->keymgmt_type);
7998 DBG("service->phase1 : %s", service->phase1);
7999 if (service->phase1)
8000 connman_network_set_string(service->network, "WiFi.Phase1",
8005 static int service_connect(struct connman_service *service)
8009 if (service->hidden)
8012 #if defined TIZEN_EXT
8016 index = __connman_service_get_index(service);
8018 for (list = service_list; list; list = list->next) {
8019 struct connman_service *temp = list->data;
8021 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8024 if (!is_connecting(temp->state) && !is_connected(temp->state))
8027 if (service == temp)
8030 if (service->type != temp->type)
8033 if (__connman_service_get_index(temp) == index &&
8034 __connman_service_disconnect(temp) == -EINPROGRESS)
8035 return -EINPROGRESS;
8039 switch (service->type) {
8040 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8041 case CONNMAN_SERVICE_TYPE_SYSTEM:
8042 case CONNMAN_SERVICE_TYPE_GPS:
8043 case CONNMAN_SERVICE_TYPE_P2P:
8045 case CONNMAN_SERVICE_TYPE_ETHERNET:
8046 case CONNMAN_SERVICE_TYPE_GADGET:
8047 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8048 case CONNMAN_SERVICE_TYPE_CELLULAR:
8049 case CONNMAN_SERVICE_TYPE_VPN:
8051 case CONNMAN_SERVICE_TYPE_WIFI:
8052 switch (service->security) {
8053 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
8054 case CONNMAN_SERVICE_SECURITY_NONE:
8056 case CONNMAN_SERVICE_SECURITY_WEP:
8057 case CONNMAN_SERVICE_SECURITY_PSK:
8058 case CONNMAN_SERVICE_SECURITY_WPA:
8059 case CONNMAN_SERVICE_SECURITY_RSN:
8060 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
8063 if (service->request_passphrase_input) {
8064 DBG("Now try to connect other user's favorite service");
8065 service->request_passphrase_input = false;
8067 } else if (!service->passphrase) {
8068 if (!service->network)
8071 if (!service->wps ||
8072 !connman_network_get_bool(service->network, "WiFi.UseWPS"))
8077 case CONNMAN_SERVICE_SECURITY_8021X:
8081 #if defined TIZEN_EXT
8083 * never request credentials if using EAP-TLS, EAP-SIM
8084 * or EAP-AKA (EAP-TLS, EAP-SIM and EAP-AKA networks
8085 * need to be fully provisioned)
8087 DBG("service eap: %s", service->eap);
8088 if (g_str_equal(service->eap, "tls") ||
8089 g_str_equal(service->eap, "sim") ||
8090 g_str_equal(service->eap, "aka") ||
8091 g_str_equal(service->eap, "aka'") ||
8092 g_str_equal(service->eap, "pwd") ||
8093 g_str_equal(service->eap, "fast"))
8097 * never request credentials if using EAP-TLS
8098 * (EAP-TLS networks need to be fully provisioned)
8100 if (g_str_equal(service->eap, "tls"))
8104 * Return -ENOKEY if either identity or passphrase is
8105 * missing. Agent provided credentials can be used as
8106 * fallback if needed.
8108 if (((!service->identity &&
8109 !service->agent_identity) ||
8110 !service->passphrase) ||
8111 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
8119 if (service->network) {
8120 if (!prepare_network(service))
8123 switch (service->security) {
8124 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
8125 case CONNMAN_SERVICE_SECURITY_NONE:
8126 case CONNMAN_SERVICE_SECURITY_WEP:
8127 case CONNMAN_SERVICE_SECURITY_PSK:
8128 case CONNMAN_SERVICE_SECURITY_WPA:
8129 case CONNMAN_SERVICE_SECURITY_RSN:
8131 case CONNMAN_SERVICE_SECURITY_8021X:
8132 prepare_8021x(service);
8136 if (__connman_stats_service_register(service) == 0) {
8137 __connman_stats_get(service, false,
8138 &service->stats.data);
8139 __connman_stats_get(service, true,
8140 &service->stats_roaming.data);
8143 err = __connman_network_connect(service->network);
8144 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8146 err = __connman_provider_connect(service->provider,
8147 get_dbus_sender(service));
8152 if (err != -EINPROGRESS) {
8153 __connman_service_ipconfig_indicate_state(service,
8154 CONNMAN_SERVICE_STATE_FAILURE,
8155 CONNMAN_IPCONFIG_TYPE_IPV4);
8156 __connman_service_ipconfig_indicate_state(service,
8157 CONNMAN_SERVICE_STATE_FAILURE,
8158 CONNMAN_IPCONFIG_TYPE_IPV6);
8159 __connman_stats_service_unregister(service);
8166 int __connman_service_connect(struct connman_service *service,
8167 enum connman_service_connect_reason reason)
8171 DBG("service %p state %s connect reason %s -> %s",
8172 service, state2string(service->state),
8173 reason2string(service->connect_reason),
8174 reason2string(reason));
8176 if (is_connected(service->state))
8179 if (is_connecting(service->state))
8182 switch (service->type) {
8183 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8184 case CONNMAN_SERVICE_TYPE_SYSTEM:
8185 case CONNMAN_SERVICE_TYPE_GPS:
8186 case CONNMAN_SERVICE_TYPE_P2P:
8189 case CONNMAN_SERVICE_TYPE_ETHERNET:
8190 case CONNMAN_SERVICE_TYPE_GADGET:
8191 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8192 case CONNMAN_SERVICE_TYPE_CELLULAR:
8193 case CONNMAN_SERVICE_TYPE_VPN:
8194 case CONNMAN_SERVICE_TYPE_WIFI:
8198 if (!is_ipconfig_usable(service))
8201 __connman_service_clear_error(service);
8203 err = service_connect(service);
8205 DBG("service %p err %d", service, err);
8207 service->connect_reason = reason;
8211 if (err == -EINPROGRESS) {
8212 if (service->timeout == 0)
8213 service->timeout = g_timeout_add_seconds(
8214 CONNECT_TIMEOUT, connect_timeout, service);
8216 return -EINPROGRESS;
8219 if (service->network)
8220 __connman_network_disconnect(service->network);
8221 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8223 connman_provider_disconnect(service->provider);
8225 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
8226 if (err == -ENOKEY || err == -EPERM) {
8227 DBusMessage *pending = NULL;
8228 const char *dbus_sender = get_dbus_sender(service);
8231 * We steal the reply here. The idea is that the
8232 * connecting client will see the connection status
8233 * after the real hidden network is connected or
8234 * connection failed.
8236 if (service->hidden) {
8237 pending = service->pending;
8238 service->pending = NULL;
8241 err = __connman_agent_request_passphrase_input(service,
8245 if (service->hidden && err != -EINPROGRESS)
8246 service->pending = pending;
8250 reply_pending(service, -err);
8256 int __connman_service_disconnect(struct connman_service *service)
8260 DBG("service %p", service);
8262 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
8263 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
8265 connman_agent_cancel(service);
8267 reply_pending(service, ECONNABORTED);
8269 if (service->network) {
8270 err = __connman_network_disconnect(service->network);
8271 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8273 err = connman_provider_disconnect(service->provider);
8277 if (err < 0 && err != -EINPROGRESS)
8280 __connman_6to4_remove(service->ipconfig_ipv4);
8282 if (service->ipconfig_ipv4)
8283 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
8286 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
8289 #if defined TIZEN_EXT
8291 * Skip the functions If there is any connected profiles
8292 * that use same interface
8294 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
8295 __connman_service_get_connected_count_of_iface(service) <= 0) {
8297 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
8298 settings_changed(service, service->ipconfig_ipv4);
8300 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
8301 settings_changed(service, service->ipconfig_ipv6);
8303 __connman_ipconfig_disable(service->ipconfig_ipv4);
8304 __connman_ipconfig_disable(service->ipconfig_ipv6);
8305 #if defined TIZEN_EXT
8309 __connman_stats_service_unregister(service);
8314 int __connman_service_disconnect_all(void)
8316 struct connman_service *service;
8317 GSList *services = NULL, *list;
8322 for (iter = service_list; iter; iter = iter->next) {
8323 service = iter->data;
8325 if (!is_connected(service->state))
8328 services = g_slist_prepend(services, service);
8331 for (list = services; list; list = list->next) {
8332 struct connman_service *service = list->data;
8334 service->ignore = true;
8336 __connman_service_disconnect(service);
8339 g_slist_free(services);
8345 * lookup_by_identifier:
8346 * @identifier: service identifier
8348 * Look up a service by identifier (reference count will not be increased)
8350 static struct connman_service *lookup_by_identifier(const char *identifier)
8352 return g_hash_table_lookup(service_hash, identifier);
8355 struct connman_service *connman_service_lookup_from_identifier(const char* identifier)
8357 return lookup_by_identifier(identifier);
8360 struct provision_user_data {
8365 static void provision_changed(gpointer value, gpointer user_data)
8367 struct connman_service *service = value;
8368 struct provision_user_data *data = user_data;
8369 const char *path = data->ident;
8372 ret = __connman_config_provision_service_ident(service, path,
8373 service->config_file, service->config_entry);
8378 int __connman_service_provision_changed(const char *ident)
8380 struct provision_user_data data = {
8385 g_list_foreach(service_list, provision_changed, (void *)&data);
8388 * Because the provision_changed() might have set some services
8389 * as favorite, we must sort the sequence now.
8391 if (services_dirty) {
8392 services_dirty = false;
8394 service_list_sort();
8396 __connman_connection_update_gateway();
8402 void __connman_service_set_config(struct connman_service *service,
8403 const char *file_id, const char *entry)
8408 g_free(service->config_file);
8409 service->config_file = g_strdup(file_id);
8411 g_free(service->config_entry);
8412 service->config_entry = g_strdup(entry);
8416 * __connman_service_get:
8417 * @identifier: service identifier
8419 * Look up a service by identifier or create a new one if not found
8421 static struct connman_service *service_get(const char *identifier)
8423 struct connman_service *service;
8425 service = g_hash_table_lookup(service_hash, identifier);
8427 connman_service_ref(service);
8431 service = connman_service_create();
8435 DBG("service %p", service);
8437 service->identifier = g_strdup(identifier);
8439 service_list = g_list_insert_sorted(service_list, service,
8442 g_hash_table_insert(service_hash, service->identifier, service);
8447 static int service_register(struct connman_service *service)
8449 DBG("service %p", service);
8454 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
8455 service->identifier);
8457 DBG("path %s", service->path);
8459 if (__connman_config_provision_service(service) < 0)
8460 service_load(service);
8462 g_dbus_register_interface(connection, service->path,
8463 CONNMAN_SERVICE_INTERFACE,
8464 service_methods, service_signals,
8465 NULL, service, NULL);
8467 service_list_sort();
8469 __connman_connection_update_gateway();
8474 static void service_up(struct connman_ipconfig *ipconfig,
8477 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8479 DBG("%s up", ifname);
8481 link_changed(service);
8483 service->stats.valid = false;
8484 service->stats_roaming.valid = false;
8487 static void service_down(struct connman_ipconfig *ipconfig,
8490 DBG("%s down", ifname);
8493 static void service_lower_up(struct connman_ipconfig *ipconfig,
8496 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8498 DBG("%s lower up", ifname);
8500 stats_start(service);
8503 static void service_lower_down(struct connman_ipconfig *ipconfig,
8506 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8508 DBG("%s lower down", ifname);
8510 stats_stop(service);
8511 service_save(service);
8514 static void service_ip_bound(struct connman_ipconfig *ipconfig,
8517 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8518 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8519 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8520 #if defined TIZEN_EXT
8524 DBG("%s ip bound", ifname);
8526 type = __connman_ipconfig_get_config_type(ipconfig);
8527 method = __connman_ipconfig_get_method(ipconfig);
8529 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8532 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8533 method == CONNMAN_IPCONFIG_METHOD_AUTO)
8534 #if defined TIZEN_EXT
8536 err = __connman_ipconfig_gateway_add(ipconfig, service);
8539 DBG("Failed to add gateway");
8542 __connman_service_ipconfig_indicate_state(service,
8543 CONNMAN_SERVICE_STATE_READY,
8544 CONNMAN_IPCONFIG_TYPE_IPV6);
8547 settings_changed(service, ipconfig);
8548 address_updated(service, type);
8551 static void service_ip_release(struct connman_ipconfig *ipconfig,
8554 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8555 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8556 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8558 DBG("%s ip release", ifname);
8560 type = __connman_ipconfig_get_config_type(ipconfig);
8561 method = __connman_ipconfig_get_method(ipconfig);
8563 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8566 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8567 method == CONNMAN_IPCONFIG_METHOD_OFF)
8568 __connman_service_ipconfig_indicate_state(service,
8569 CONNMAN_SERVICE_STATE_DISCONNECT,
8570 CONNMAN_IPCONFIG_TYPE_IPV6);
8572 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
8573 method == CONNMAN_IPCONFIG_METHOD_OFF)
8574 __connman_service_ipconfig_indicate_state(service,
8575 CONNMAN_SERVICE_STATE_DISCONNECT,
8576 CONNMAN_IPCONFIG_TYPE_IPV4);
8578 settings_changed(service, ipconfig);
8581 static void service_route_changed(struct connman_ipconfig *ipconfig,
8584 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8586 DBG("%s route changed", ifname);
8588 settings_changed(service, ipconfig);
8591 static const struct connman_ipconfig_ops service_ops = {
8593 .down = service_down,
8594 .lower_up = service_lower_up,
8595 .lower_down = service_lower_down,
8596 .ip_bound = service_ip_bound,
8597 .ip_release = service_ip_release,
8598 .route_set = service_route_changed,
8599 .route_unset = service_route_changed,
8602 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
8603 int index, enum connman_ipconfig_method method)
8605 struct connman_ipconfig *ipconfig_ipv4;
8607 ipconfig_ipv4 = __connman_ipconfig_create(index,
8608 CONNMAN_IPCONFIG_TYPE_IPV4);
8612 __connman_ipconfig_set_method(ipconfig_ipv4, method);
8614 __connman_ipconfig_set_data(ipconfig_ipv4, service);
8616 __connman_ipconfig_set_ops(ipconfig_ipv4, &service_ops);
8618 return ipconfig_ipv4;
8621 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
8624 struct connman_ipconfig *ipconfig_ipv6;
8626 ipconfig_ipv6 = __connman_ipconfig_create(index,
8627 CONNMAN_IPCONFIG_TYPE_IPV6);
8631 __connman_ipconfig_set_data(ipconfig_ipv6, service);
8633 __connman_ipconfig_set_ops(ipconfig_ipv6, &service_ops);
8635 return ipconfig_ipv6;
8638 void __connman_service_read_ip4config(struct connman_service *service)
8642 if (!service->ipconfig_ipv4)
8645 keyfile = connman_storage_load_service(service->identifier);
8649 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
8650 service->identifier, "IPv4.");
8652 g_key_file_free(keyfile);
8655 void connman_service_create_ip4config(struct connman_service *service,
8658 DBG("ipv4 %p", service->ipconfig_ipv4);
8660 if (service->ipconfig_ipv4)
8663 service->ipconfig_ipv4 = create_ip4config(service, index,
8664 CONNMAN_IPCONFIG_METHOD_DHCP);
8665 __connman_service_read_ip4config(service);
8668 void __connman_service_read_ip6config(struct connman_service *service)
8672 if (!service->ipconfig_ipv6)
8675 keyfile = connman_storage_load_service(service->identifier);
8679 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
8680 service->identifier, "IPv6.");
8682 g_key_file_free(keyfile);
8685 void connman_service_create_ip6config(struct connman_service *service,
8688 DBG("ipv6 %p", service->ipconfig_ipv6);
8690 if (service->ipconfig_ipv6)
8693 service->ipconfig_ipv6 = create_ip6config(service, index);
8695 __connman_service_read_ip6config(service);
8699 * connman_service_lookup_from_network:
8700 * @network: network structure
8702 * Look up a service by network (reference count will not be increased)
8704 struct connman_service *connman_service_lookup_from_network(struct connman_network *network)
8706 struct connman_service *service;
8707 const char *ident, *group;
8713 ident = __connman_network_get_ident(network);
8717 group = connman_network_get_group(network);
8721 name = g_strdup_printf("%s_%s_%s",
8722 __connman_network_get_type(network), ident, group);
8723 service = lookup_by_identifier(name);
8729 struct connman_service *__connman_service_lookup_from_index(int index)
8731 struct connman_service *service;
8734 for (list = service_list; list; list = list->next) {
8735 service = list->data;
8737 if (__connman_ipconfig_get_index(service->ipconfig_ipv4)
8741 if (__connman_ipconfig_get_index(service->ipconfig_ipv6)
8749 struct connman_service *__connman_service_lookup_from_ident(const char *identifier)
8751 return lookup_by_identifier(identifier);
8754 const char *__connman_service_get_ident(struct connman_service *service)
8756 return service->identifier;
8759 const char *__connman_service_get_path(struct connman_service *service)
8761 return service->path;
8764 const char *__connman_service_get_name(struct connman_service *service)
8766 return service->name;
8769 enum connman_service_state __connman_service_get_state(struct connman_service *service)
8771 return service->state;
8774 unsigned int __connman_service_get_order(struct connman_service *service)
8776 unsigned int order = 0;
8783 if (!service->favorite)
8786 #if defined TIZEN_EXT
8787 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8788 service->do_split_routing == FALSE)
8790 else if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
8791 if (service->order < 5)
8793 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
8795 else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
8797 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8798 __connman_service_is_internet_profile(service) == TRUE)
8800 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8801 __connman_service_is_tethering_profile(service) == TRUE)
8803 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8808 if (service == service_list->data)
8811 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8812 !service->do_split_routing) {
8813 service->order = 10;
8817 DBG("service %p name %s order %d split %d", service, service->name,
8818 order, service->do_split_routing);
8823 static enum connman_service_type convert_network_type(struct connman_network *network)
8825 enum connman_network_type type = connman_network_get_type(network);
8828 case CONNMAN_NETWORK_TYPE_UNKNOWN:
8829 case CONNMAN_NETWORK_TYPE_VENDOR:
8831 case CONNMAN_NETWORK_TYPE_ETHERNET:
8832 return CONNMAN_SERVICE_TYPE_ETHERNET;
8833 case CONNMAN_NETWORK_TYPE_WIFI:
8834 return CONNMAN_SERVICE_TYPE_WIFI;
8835 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
8836 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
8837 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
8838 case CONNMAN_NETWORK_TYPE_CELLULAR:
8839 return CONNMAN_SERVICE_TYPE_CELLULAR;
8840 case CONNMAN_NETWORK_TYPE_GADGET:
8841 return CONNMAN_SERVICE_TYPE_GADGET;
8844 return CONNMAN_SERVICE_TYPE_UNKNOWN;
8847 static enum connman_service_security convert_wifi_security(const char *security)
8850 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8851 else if (g_str_equal(security, "none"))
8852 return CONNMAN_SERVICE_SECURITY_NONE;
8853 else if (g_str_equal(security, "wep"))
8854 return CONNMAN_SERVICE_SECURITY_WEP;
8855 else if (g_str_equal(security, "psk"))
8856 return CONNMAN_SERVICE_SECURITY_PSK;
8857 else if (g_str_equal(security, "ieee8021x"))
8858 return CONNMAN_SERVICE_SECURITY_8021X;
8859 else if (g_str_equal(security, "wpa"))
8860 return CONNMAN_SERVICE_SECURITY_WPA;
8861 else if (g_str_equal(security, "rsn"))
8862 return CONNMAN_SERVICE_SECURITY_RSN;
8863 #if defined TIZEN_EXT
8864 else if (g_str_equal(security, "ft_psk") == TRUE)
8865 return CONNMAN_SERVICE_SECURITY_PSK;
8866 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
8867 return CONNMAN_SERVICE_SECURITY_8021X;
8870 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8873 #if defined TIZEN_EXT
8874 int check_passphrase_ext(struct connman_network *network,
8875 const char *passphrase)
8878 enum connman_service_security security;
8880 str = connman_network_get_string(network, "WiFi.Security");
8881 security = convert_wifi_security(str);
8883 return __connman_service_check_passphrase(security, passphrase);
8887 static void update_from_network(struct connman_service *service,
8888 struct connman_network *network)
8890 uint8_t strength = service->strength;
8893 DBG("service %p network %p", service, network);
8895 if (is_connected(service->state))
8898 if (is_connecting(service->state))
8901 str = connman_network_get_string(network, "Name");
8903 g_free(service->name);
8904 service->name = g_strdup(str);
8905 service->hidden = false;
8907 g_free(service->name);
8908 service->name = NULL;
8909 service->hidden = true;
8912 service->strength = connman_network_get_strength(network);
8913 service->roaming = connman_network_get_bool(network, "Roaming");
8915 if (service->strength == 0) {
8917 * Filter out 0-values; it's unclear what they mean
8918 * and they cause anomalous sorting of the priority list.
8920 service->strength = strength;
8923 str = connman_network_get_string(network, "WiFi.Security");
8924 service->security = convert_wifi_security(str);
8926 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
8927 service->wps = connman_network_get_bool(network, "WiFi.WPS");
8929 if (service->strength > strength && service->network) {
8930 connman_network_unref(service->network);
8931 service->network = connman_network_ref(network);
8933 strength_changed(service);
8936 if (!service->network)
8937 service->network = connman_network_ref(network);
8939 service_list_sort();
8943 * __connman_service_create_from_network:
8944 * @network: network structure
8946 * Look up service by network and if not found, create one
8948 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
8950 struct connman_service *service;
8951 struct connman_device *device;
8952 const char *ident, *group;
8954 unsigned int *auto_connect_types;
8957 DBG("network %p", network);
8962 ident = __connman_network_get_ident(network);
8966 group = connman_network_get_group(network);
8970 name = g_strdup_printf("%s_%s_%s",
8971 __connman_network_get_type(network), ident, group);
8972 service = service_get(name);
8978 if (__connman_network_get_weakness(network))
8981 if (service->path) {
8982 update_from_network(service, network);
8983 __connman_connection_update_gateway();
8987 service->type = convert_network_type(network);
8989 auto_connect_types = connman_setting_get_uint_list("DefaultAutoConnectTechnologies");
8990 service->autoconnect = false;
8991 for (i = 0; auto_connect_types &&
8992 auto_connect_types[i] != 0; i++) {
8993 if (service->type == auto_connect_types[i]) {
8994 service->autoconnect = true;
8999 switch (service->type) {
9000 case CONNMAN_SERVICE_TYPE_UNKNOWN:
9001 case CONNMAN_SERVICE_TYPE_SYSTEM:
9002 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
9003 case CONNMAN_SERVICE_TYPE_GPS:
9004 case CONNMAN_SERVICE_TYPE_VPN:
9005 case CONNMAN_SERVICE_TYPE_GADGET:
9006 case CONNMAN_SERVICE_TYPE_WIFI:
9007 case CONNMAN_SERVICE_TYPE_CELLULAR:
9008 case CONNMAN_SERVICE_TYPE_P2P:
9010 case CONNMAN_SERVICE_TYPE_ETHERNET:
9011 service->favorite = true;
9015 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
9016 service->state = combine_state(service->state_ipv4, service->state_ipv6);
9018 update_from_network(service, network);
9020 index = connman_network_get_index(network);
9022 if (!service->ipconfig_ipv4)
9023 service->ipconfig_ipv4 = create_ip4config(service, index,
9024 CONNMAN_IPCONFIG_METHOD_DHCP);
9026 if (!service->ipconfig_ipv6)
9027 service->ipconfig_ipv6 = create_ip6config(service, index);
9029 service_register(service);
9030 service_schedule_added(service);
9032 if (service->favorite) {
9033 device = connman_network_get_device(service->network);
9034 if (device && !connman_device_get_scanning(device)) {
9036 switch (service->type) {
9037 case CONNMAN_SERVICE_TYPE_UNKNOWN:
9038 case CONNMAN_SERVICE_TYPE_SYSTEM:
9039 case CONNMAN_SERVICE_TYPE_P2P:
9042 case CONNMAN_SERVICE_TYPE_GADGET:
9043 case CONNMAN_SERVICE_TYPE_ETHERNET:
9044 if (service->autoconnect) {
9045 __connman_service_connect(service,
9046 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
9051 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
9052 case CONNMAN_SERVICE_TYPE_GPS:
9053 case CONNMAN_SERVICE_TYPE_VPN:
9054 case CONNMAN_SERVICE_TYPE_WIFI:
9055 case CONNMAN_SERVICE_TYPE_CELLULAR:
9056 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
9061 #if defined TIZEN_EXT
9062 /* TIZEN synchronizes below information when the service creates */
9063 if (service->eap != NULL)
9064 connman_network_set_string(service->network, "WiFi.EAP",
9066 if (service->identity != NULL)
9067 connman_network_set_string(service->network, "WiFi.Identity",
9069 if (service->phase2 != NULL)
9070 connman_network_set_string(service->network, "WiFi.Phase2",
9075 __connman_notifier_service_add(service, service->name);
9080 void __connman_service_update_from_network(struct connman_network *network)
9082 bool need_sort = false;
9083 struct connman_service *service;
9089 service = connman_service_lookup_from_network(network);
9093 if (!service->network)
9096 #if defined TIZEN_EXT
9097 if (service->storage_reload) {
9098 service_load(service);
9099 __connman_service_set_storage_reload(service, false);
9103 name = connman_network_get_string(service->network, "Name");
9104 if (g_strcmp0(service->name, name) != 0) {
9105 g_free(service->name);
9106 service->name = g_strdup(name);
9108 if (allow_property_changed(service))
9109 connman_dbus_property_changed_basic(service->path,
9110 CONNMAN_SERVICE_INTERFACE, "Name",
9111 DBUS_TYPE_STRING, &service->name);
9114 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
9115 service->wps = connman_network_get_bool(network, "WiFi.WPS");
9117 strength = connman_network_get_strength(service->network);
9118 if (strength == service->strength)
9121 service->strength = strength;
9124 strength_changed(service);
9127 roaming = connman_network_get_bool(service->network, "Roaming");
9128 if (roaming == service->roaming)
9131 stats_enable = stats_enabled(service);
9133 stats_stop(service);
9135 service->roaming = roaming;
9139 stats_start(service);
9141 roaming_changed(service);
9145 service_list_sort();
9149 void __connman_service_remove_from_network(struct connman_network *network)
9151 struct connman_service *service;
9153 service = connman_service_lookup_from_network(network);
9155 DBG("network %p service %p", network, service);
9160 service->ignore = true;
9162 __connman_connection_gateway_remove(service,
9163 CONNMAN_IPCONFIG_TYPE_ALL);
9165 connman_service_unref(service);
9169 * __connman_service_create_from_provider:
9170 * @provider: provider structure
9172 * Look up service by provider and if not found, create one
9174 struct connman_service *
9175 __connman_service_create_from_provider(struct connman_provider *provider)
9177 struct connman_service *service;
9178 const char *ident, *str;
9180 int index = connman_provider_get_index(provider);
9182 DBG("provider %p", provider);
9184 ident = __connman_provider_get_ident(provider);
9188 name = g_strdup_printf("vpn_%s", ident);
9189 service = service_get(name);
9195 service->type = CONNMAN_SERVICE_TYPE_VPN;
9196 service->provider = connman_provider_ref(provider);
9197 service->autoconnect = false;
9198 service->favorite = true;
9200 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
9201 service->state = combine_state(service->state_ipv4, service->state_ipv6);
9203 str = connman_provider_get_string(provider, "Name");
9205 g_free(service->name);
9206 service->name = g_strdup(str);
9207 service->hidden = false;
9209 g_free(service->name);
9210 service->name = NULL;
9211 service->hidden = true;
9214 service->strength = 0;
9216 if (!service->ipconfig_ipv4)
9217 service->ipconfig_ipv4 = create_ip4config(service, index,
9218 CONNMAN_IPCONFIG_METHOD_MANUAL);
9220 if (!service->ipconfig_ipv6)
9221 service->ipconfig_ipv6 = create_ip6config(service, index);
9223 service_register(service);
9225 __connman_notifier_service_add(service, service->name);
9226 service_schedule_added(service);
9231 static void remove_unprovisioned_services(void)
9234 GKeyFile *keyfile, *configkeyfile;
9235 char *file, *section;
9238 services = connman_storage_get_services();
9242 for (; services[i]; i++) {
9243 file = section = NULL;
9244 keyfile = configkeyfile = NULL;
9246 keyfile = connman_storage_load_service(services[i]);
9250 file = g_key_file_get_string(keyfile, services[i],
9251 "Config.file", NULL);
9255 section = g_key_file_get_string(keyfile, services[i],
9256 "Config.ident", NULL);
9260 configkeyfile = __connman_storage_load_config(file);
9261 if (!configkeyfile) {
9263 * Config file is missing, remove the provisioned
9266 __connman_storage_remove_service(services[i]);
9270 if (!g_key_file_has_group(configkeyfile, section))
9272 * Config section is missing, remove the provisioned
9275 __connman_storage_remove_service(services[i]);
9279 g_key_file_free(keyfile);
9282 g_key_file_free(configkeyfile);
9288 g_strfreev(services);
9291 static int agent_probe(struct connman_agent *agent)
9293 DBG("agent %p", agent);
9297 static void agent_remove(struct connman_agent *agent)
9299 DBG("agent %p", agent);
9302 static void *agent_context_ref(void *context)
9304 struct connman_service *service = context;
9306 return (void *)connman_service_ref(service);
9309 static void agent_context_unref(void *context)
9311 struct connman_service *service = context;
9313 connman_service_unref(service);
9316 static struct connman_agent_driver agent_driver = {
9318 .interface = CONNMAN_AGENT_INTERFACE,
9319 .probe = agent_probe,
9320 .remove = agent_remove,
9321 .context_ref = agent_context_ref,
9322 .context_unref = agent_context_unref,
9325 int __connman_service_init(void)
9331 err = connman_agent_driver_register(&agent_driver);
9333 connman_error("Cannot register agent driver for %s",
9338 set_always_connecting_technologies();
9340 connection = connman_dbus_get_connection();
9342 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
9343 NULL, service_free);
9345 services_notify = g_new0(struct _services_notify, 1);
9346 services_notify->remove = g_hash_table_new_full(g_str_hash,
9347 g_str_equal, g_free, NULL);
9348 services_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
9350 remove_unprovisioned_services();
9355 void __connman_service_cleanup(void)
9359 if (vpn_autoconnect_timeout) {
9360 g_source_remove(vpn_autoconnect_timeout);
9361 vpn_autoconnect_timeout = 0;
9364 if (autoconnect_timeout != 0) {
9365 g_source_remove(autoconnect_timeout);
9366 autoconnect_timeout = 0;
9369 connman_agent_driver_unregister(&agent_driver);
9371 g_list_free(service_list);
9372 service_list = NULL;
9374 g_hash_table_destroy(service_hash);
9375 service_hash = NULL;
9377 g_slist_free(counter_list);
9378 counter_list = NULL;
9380 if (services_notify->id != 0) {
9381 g_source_remove(services_notify->id);
9382 service_send_changed(NULL);
9385 g_hash_table_destroy(services_notify->remove);
9386 g_hash_table_destroy(services_notify->add);
9387 g_free(services_notify);
9389 dbus_connection_unref(connection);