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);
790 service->dns_config_method_ipv4 = __connman_dnsconfig_string2method(dns_method);
794 dns_method = g_key_file_get_string(keyfile, service->identifier,
795 "Nameservers.IPv6method", NULL);
797 service->dns_config_method_ipv6 = __connman_dnsconfig_string2method(dns_method);
802 service->timeservers_config = g_key_file_get_string_list(keyfile,
803 service->identifier, "Timeservers", &length, NULL);
804 if (service->timeservers_config && length == 0) {
805 g_strfreev(service->timeservers_config);
806 service->timeservers_config = NULL;
809 service->domains = g_key_file_get_string_list(keyfile,
810 service->identifier, "Domains", &length, NULL);
811 if (service->domains && length == 0) {
812 g_strfreev(service->domains);
813 service->domains = NULL;
816 str = g_key_file_get_string(keyfile,
817 service->identifier, "Proxy.Method", NULL);
819 service->proxy_config = string2proxymethod(str);
823 service->proxies = g_key_file_get_string_list(keyfile,
824 service->identifier, "Proxy.Servers", &length, NULL);
825 if (service->proxies && length == 0) {
826 g_strfreev(service->proxies);
827 service->proxies = NULL;
830 service->excludes = g_key_file_get_string_list(keyfile,
831 service->identifier, "Proxy.Excludes", &length, NULL);
832 if (service->excludes && length == 0) {
833 g_strfreev(service->excludes);
834 service->excludes = NULL;
837 str = g_key_file_get_string(keyfile,
838 service->identifier, "Proxy.URL", NULL);
840 g_free(service->pac);
844 service->hidden_service = g_key_file_get_boolean(keyfile,
845 service->identifier, "Hidden", NULL);
847 #if defined TIZEN_EXT
848 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
849 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
850 str = g_key_file_get_string(keyfile,
851 service->identifier, "EAP", NULL);
853 g_free(service->eap);
857 str = g_key_file_get_string(keyfile,
858 service->identifier, "Phase2", NULL);
860 g_free(service->phase2);
861 service->phase2 = str;
864 str = g_key_file_get_string(keyfile,
865 service->identifier, "Identity", NULL);
867 g_free(service->identity);
868 service->identity = str;
871 str = g_key_file_get_string(keyfile,
872 service->identifier, "CACertFile", NULL);
874 g_free(service->ca_cert_file);
875 service->ca_cert_file = str;
878 str = g_key_file_get_string(keyfile,
879 service->identifier, "ClientCertFile", NULL);
881 g_free(service->client_cert_file);
882 service->client_cert_file = str;
885 str = g_key_file_get_string(keyfile,
886 service->identifier, "PrivateKeyFile", NULL);
888 g_free(service->private_key_file);
889 service->private_key_file = str;
892 str = g_key_file_get_string(keyfile,
893 service->identifier, "PrivateKeyPassphrase", NULL);
895 g_free(service->private_key_passphrase);
896 service->private_key_passphrase = str;
901 if (g_key_file_has_key(keyfile, service->identifier, "UID", NULL))
902 service->user.favorite_user = g_key_file_get_integer(keyfile,
903 service->identifier, "UID", NULL);
905 g_key_file_free(keyfile);
910 static int service_save(struct connman_service *service)
915 const char *cst_str = NULL;
918 DBG("service %p new %d", service, service->new_service);
920 if (service->new_service)
923 keyfile = __connman_storage_open_service(service->identifier);
928 g_key_file_set_string(keyfile, service->identifier,
929 "Name", service->name);
931 switch (service->type) {
932 case CONNMAN_SERVICE_TYPE_UNKNOWN:
933 case CONNMAN_SERVICE_TYPE_SYSTEM:
934 case CONNMAN_SERVICE_TYPE_GPS:
935 case CONNMAN_SERVICE_TYPE_P2P:
937 case CONNMAN_SERVICE_TYPE_VPN:
938 g_key_file_set_boolean(keyfile, service->identifier,
939 "SplitRouting", service->do_split_routing);
940 if (service->favorite)
941 g_key_file_set_boolean(keyfile, service->identifier,
942 "AutoConnect", service->autoconnect);
944 case CONNMAN_SERVICE_TYPE_WIFI:
945 if (service->network) {
946 const unsigned char *ssid;
947 unsigned int ssid_len = 0;
949 if (service->user.favorite_user == USER_NONE)
950 g_key_file_remove_key(keyfile, service->identifier,
953 g_key_file_set_integer(keyfile, service->identifier,
954 "UID", service->user.favorite_user);
956 ssid = connman_network_get_blob(service->network,
957 "WiFi.SSID", &ssid_len);
959 if (ssid && ssid_len > 0 && ssid[0] != '\0') {
960 char *identifier = service->identifier;
964 ssid_str = g_string_sized_new(ssid_len * 2);
970 for (i = 0; i < ssid_len; i++)
971 g_string_append_printf(ssid_str,
974 g_key_file_set_string(keyfile, identifier,
975 "SSID", ssid_str->str);
977 g_string_free(ssid_str, TRUE);
980 freq = connman_network_get_frequency(service->network);
981 g_key_file_set_integer(keyfile, service->identifier,
986 case CONNMAN_SERVICE_TYPE_GADGET:
987 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
988 case CONNMAN_SERVICE_TYPE_CELLULAR:
989 g_key_file_set_boolean(keyfile, service->identifier,
990 "Favorite", service->favorite);
992 g_key_file_remove_key(keyfile, service->identifier,
997 case CONNMAN_SERVICE_TYPE_ETHERNET:
998 if (service->favorite)
999 g_key_file_set_boolean(keyfile, service->identifier,
1000 "AutoConnect", service->autoconnect);
1004 str = g_time_val_to_iso8601(&service->modified);
1006 g_key_file_set_string(keyfile, service->identifier,
1011 if (service->user.current_user == service->user.favorite_user) {
1012 if (service->passphrase && strlen(service->passphrase) > 0)
1013 g_key_file_set_string(keyfile, service->identifier,
1014 "Passphrase", service->passphrase);
1016 g_key_file_remove_key(keyfile, service->identifier,
1017 "Passphrase", NULL);
1020 if (service->ipconfig_ipv4)
1021 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
1022 service->identifier, "IPv4.");
1024 if (service->ipconfig_ipv6)
1025 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
1026 service->identifier, "IPv6.");
1028 if (service->nameservers_config) {
1029 guint len = g_strv_length(service->nameservers_config);
1031 g_key_file_set_string_list(keyfile, service->identifier,
1033 (const gchar **) service->nameservers_config, len);
1035 g_key_file_remove_key(keyfile, service->identifier,
1036 "Nameservers", NULL);
1038 #if defined TIZEN_EXT
1039 if(service->dns_config_method_ipv4 != 0) {
1041 method = __connman_dnsconfig_method2string(
1042 service->dns_config_method_ipv4);
1043 g_key_file_set_string(keyfile, service->identifier,
1044 "Nameservers.IPv4method", method);
1046 g_key_file_remove_key(keyfile, service->identifier,
1047 "Nameservers.IPv4method", NULL);
1049 if(service->dns_config_method_ipv6 != 0) {
1051 method = __connman_dnsconfig_method2string(
1052 service->dns_config_method_ipv6);
1053 g_key_file_set_string(keyfile, service->identifier,
1054 "Nameservers.IPv6method", method);
1056 g_key_file_remove_key(keyfile, service->identifier,
1057 "Nameservers.IPv6method", NULL);
1060 if (service->timeservers_config) {
1061 guint len = g_strv_length(service->timeservers_config);
1063 g_key_file_set_string_list(keyfile, service->identifier,
1065 (const gchar **) service->timeservers_config, len);
1067 g_key_file_remove_key(keyfile, service->identifier,
1068 "Timeservers", NULL);
1070 if (service->domains) {
1071 guint len = g_strv_length(service->domains);
1073 g_key_file_set_string_list(keyfile, service->identifier,
1075 (const gchar **) service->domains, len);
1077 g_key_file_remove_key(keyfile, service->identifier,
1080 cst_str = proxymethod2string(service->proxy_config);
1082 g_key_file_set_string(keyfile, service->identifier,
1083 "Proxy.Method", cst_str);
1085 if (service->proxies) {
1086 guint len = g_strv_length(service->proxies);
1088 g_key_file_set_string_list(keyfile, service->identifier,
1090 (const gchar **) service->proxies, len);
1092 g_key_file_remove_key(keyfile, service->identifier,
1093 "Proxy.Servers", NULL);
1095 if (service->excludes) {
1096 guint len = g_strv_length(service->excludes);
1098 g_key_file_set_string_list(keyfile, service->identifier,
1100 (const gchar **) service->excludes, len);
1102 g_key_file_remove_key(keyfile, service->identifier,
1103 "Proxy.Excludes", NULL);
1105 if (service->pac && strlen(service->pac) > 0)
1106 g_key_file_set_string(keyfile, service->identifier,
1107 "Proxy.URL", service->pac);
1109 g_key_file_remove_key(keyfile, service->identifier,
1112 if (service->hidden_service)
1113 g_key_file_set_boolean(keyfile, service->identifier, "Hidden",
1116 if (service->config_file && strlen(service->config_file) > 0)
1117 g_key_file_set_string(keyfile, service->identifier,
1118 "Config.file", service->config_file);
1120 if (service->config_entry &&
1121 strlen(service->config_entry) > 0)
1122 g_key_file_set_string(keyfile, service->identifier,
1123 "Config.ident", service->config_entry);
1125 #if defined TIZEN_EXT
1126 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1127 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
1128 if (service->eap != NULL && strlen(service->eap) > 0)
1129 g_key_file_set_string(keyfile, service->identifier,
1130 "EAP", service->eap);
1132 g_key_file_remove_key(keyfile, service->identifier,
1135 if (service->phase2 != NULL && strlen(service->phase2) > 0)
1136 g_key_file_set_string(keyfile, service->identifier,
1137 "Phase2", service->phase2);
1139 g_key_file_remove_key(keyfile, service->identifier,
1142 if (service->identity != NULL && strlen(service->identity) > 0)
1143 g_key_file_set_string(keyfile, service->identifier,
1144 "Identity", service->identity);
1146 g_key_file_remove_key(keyfile, service->identifier,
1149 if (service->ca_cert_file != NULL && strlen(service->ca_cert_file) > 0)
1150 g_key_file_set_string(keyfile, service->identifier,
1151 "CACertFile", service->ca_cert_file);
1153 g_key_file_remove_key(keyfile, service->identifier,
1154 "CACertFile", NULL);
1156 if (service->client_cert_file != NULL && strlen(service->client_cert_file) > 0)
1157 g_key_file_set_string(keyfile, service->identifier,
1158 "ClientCertFile", service->client_cert_file);
1160 g_key_file_remove_key(keyfile, service->identifier,
1161 "ClientCertFile", NULL);
1163 if (service->private_key_file != NULL && strlen(service->private_key_file) > 0)
1164 g_key_file_set_string(keyfile, service->identifier,
1165 "PrivateKeyFile", service->private_key_file);
1167 g_key_file_remove_key(keyfile, service->identifier,
1168 "PrivateKeyFile", NULL);
1170 if (service->private_key_passphrase != NULL && strlen(service->private_key_passphrase) > 0)
1171 g_key_file_set_string(keyfile, service->identifier,
1172 "PrivateKeyPassphrase", service->private_key_passphrase);
1174 g_key_file_remove_key(keyfile, service->identifier,
1175 "PrivateKeyPassphrase", NULL);
1180 __connman_storage_save_service(keyfile, service->identifier);
1182 g_key_file_free(keyfile);
1187 void __connman_service_save(struct connman_service *service)
1192 service_save(service);
1195 static enum connman_service_state combine_state(
1196 enum connman_service_state state_a,
1197 enum connman_service_state state_b)
1199 enum connman_service_state result;
1201 if (state_a == state_b) {
1206 if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
1211 if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
1216 if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
1221 if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
1226 if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
1231 if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
1236 if (state_a == CONNMAN_SERVICE_STATE_READY) {
1241 if (state_b == CONNMAN_SERVICE_STATE_READY) {
1246 if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1251 if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1256 if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1261 if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1266 if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
1271 if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
1276 result = CONNMAN_SERVICE_STATE_FAILURE;
1282 static bool is_connecting(enum connman_service_state state)
1285 case CONNMAN_SERVICE_STATE_UNKNOWN:
1286 case CONNMAN_SERVICE_STATE_IDLE:
1287 case CONNMAN_SERVICE_STATE_FAILURE:
1288 case CONNMAN_SERVICE_STATE_DISCONNECT:
1289 case CONNMAN_SERVICE_STATE_READY:
1290 case CONNMAN_SERVICE_STATE_ONLINE:
1292 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1293 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1300 static bool is_connected(enum connman_service_state state)
1303 case CONNMAN_SERVICE_STATE_UNKNOWN:
1304 case CONNMAN_SERVICE_STATE_IDLE:
1305 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1306 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1307 case CONNMAN_SERVICE_STATE_DISCONNECT:
1308 case CONNMAN_SERVICE_STATE_FAILURE:
1310 case CONNMAN_SERVICE_STATE_READY:
1311 case CONNMAN_SERVICE_STATE_ONLINE:
1318 static bool is_idle(enum connman_service_state state)
1321 case CONNMAN_SERVICE_STATE_IDLE:
1322 case CONNMAN_SERVICE_STATE_DISCONNECT:
1323 case CONNMAN_SERVICE_STATE_FAILURE:
1325 case CONNMAN_SERVICE_STATE_UNKNOWN:
1326 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1327 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1328 case CONNMAN_SERVICE_STATE_READY:
1329 case CONNMAN_SERVICE_STATE_ONLINE:
1336 static int nameservers_changed_cb(void *user_data)
1338 struct connman_service *service = user_data;
1340 DBG("service %p", service);
1342 service->nameservers_timeout = 0;
1343 if ((is_idle(service->state) && !service->nameservers) ||
1344 is_connected(service->state))
1345 dns_changed(service);
1350 static void nameservers_changed(struct connman_service *service)
1352 if (!service->nameservers_timeout)
1353 service->nameservers_timeout = g_idle_add(nameservers_changed_cb,
1357 static bool nameserver_available(struct connman_service *service,
1358 enum connman_ipconfig_type type,
1363 family = connman_inet_check_ipaddress(ns);
1365 if (family == AF_INET) {
1366 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1369 return is_connected(service->state_ipv4);
1372 if (family == AF_INET6) {
1373 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1376 return is_connected(service->state_ipv6);
1382 static int searchdomain_add_all(struct connman_service *service)
1386 if (!is_connected(service->state))
1389 index = __connman_service_get_index(service);
1393 if (service->domains) {
1394 while (service->domains[i]) {
1395 connman_resolver_append(index, service->domains[i],
1403 if (service->domainname)
1404 connman_resolver_append(index, service->domainname, NULL);
1410 static int searchdomain_remove_all(struct connman_service *service)
1414 if (!is_connected(service->state))
1417 index = __connman_service_get_index(service);
1421 while (service->domains && service->domains[i]) {
1422 connman_resolver_remove(index, service->domains[i], NULL);
1426 if (service->domainname)
1427 connman_resolver_remove(index, service->domainname, NULL);
1432 static int nameserver_add(struct connman_service *service,
1433 enum connman_ipconfig_type type,
1434 const char *nameserver)
1438 if (!nameserver_available(service, type, nameserver))
1441 index = __connman_service_get_index(service);
1445 #if defined TIZEN_EXT
1446 DBG("Resolver append nameserver: %s", nameserver);
1448 ret = connman_resolver_append(index, NULL, nameserver);
1450 nameservers_changed(service);
1455 static int nameserver_add_all(struct connman_service *service,
1456 enum connman_ipconfig_type type)
1460 if (service->nameservers_config) {
1461 while (service->nameservers_config[i]) {
1462 #if defined TIZEN_EXT
1463 DBG("type %d add service->nameservers_config[%d]:%s",type,
1464 i, service->nameservers_config[i]);
1465 if(strncmp(service->nameservers_config[i], "::", 2) == 0) {
1466 DBG("Invalid nameserver");
1472 case CONNMAN_IPCONFIG_TYPE_IPV4:
1473 if (connman_inet_check_ipaddress(
1474 service->nameservers_config[i]) == AF_INET &&
1475 service->dns_config_method_ipv4 ==
1476 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1477 nameserver_add(service, type,
1478 service->nameservers_config[i]);
1481 case CONNMAN_IPCONFIG_TYPE_IPV6:
1482 if (connman_inet_check_ipaddress(
1483 service->nameservers_config[i]) == AF_INET6 &&
1484 service->dns_config_method_ipv6 ==
1485 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1486 nameserver_add(service, type,
1487 service->nameservers_config[i]);
1490 case CONNMAN_IPCONFIG_TYPE_ALL:
1491 if (connman_inet_check_ipaddress(
1492 service->nameservers_config[i]) == AF_INET &&
1493 service->dns_config_method_ipv4 ==
1494 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1495 nameserver_add(service, type,
1496 service->nameservers_config[i]);
1498 if (connman_inet_check_ipaddress(
1499 service->nameservers_config[i]) == AF_INET6 &&
1500 service->dns_config_method_ipv6 ==
1501 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1502 nameserver_add(service, type,
1503 service->nameservers_config[i]);
1506 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1507 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1510 DBG("default case do nothing");
1514 nameserver_add(service, type,
1515 service->nameservers_config[i]);
1519 } else if (service->nameservers) {
1520 while (service->nameservers[i]) {
1521 #if defined TIZEN_EXT
1522 DBG("type %d service->nameservers[%d]: %s",type,
1523 i, service->nameservers[i]);
1526 case CONNMAN_IPCONFIG_TYPE_IPV4:
1527 if (connman_inet_check_ipaddress(
1528 service->nameservers[i]) == AF_INET &&
1529 service->dns_config_method_ipv4 ==
1530 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1531 nameserver_add(service, type,
1532 service->nameservers[i]);
1535 case CONNMAN_IPCONFIG_TYPE_IPV6:
1536 if (connman_inet_check_ipaddress(
1537 service->nameservers[i]) == AF_INET6 &&
1538 service->dns_config_method_ipv6 ==
1539 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1540 nameserver_add(service, type,
1541 service->nameservers[i]);
1544 case CONNMAN_IPCONFIG_TYPE_ALL:
1545 if (connman_inet_check_ipaddress(
1546 service->nameservers[i]) == AF_INET &&
1547 service->dns_config_method_ipv4 ==
1548 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1549 nameserver_add(service, type,
1550 service->nameservers[i]);
1552 if (connman_inet_check_ipaddress(
1553 service->nameservers[i]) == AF_INET6 &&
1554 service->dns_config_method_ipv6 ==
1555 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1556 nameserver_add(service, type,
1557 service->nameservers[i]);
1560 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1561 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1564 DBG("default case do nothing");
1568 nameserver_add(service, type,
1569 service->nameservers[i]);
1576 __connman_resolver_append_fallback_nameservers();
1578 searchdomain_add_all(service);
1583 static int nameserver_remove(struct connman_service *service,
1584 enum connman_ipconfig_type type,
1585 const char *nameserver)
1589 if (!nameserver_available(service, type, nameserver))
1592 index = __connman_service_get_index(service);
1596 #if defined TIZEN_EXT
1597 DBG("Resolver remove nameserver: %s", nameserver);
1599 ret = connman_resolver_remove(index, NULL, nameserver);
1601 nameservers_changed(service);
1606 static int nameserver_remove_all(struct connman_service *service,
1607 enum connman_ipconfig_type type)
1609 #if defined TIZEN_EXT
1611 * Skip this function if there is any connected profiles
1612 * that use same interface
1614 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
1615 __connman_service_get_connected_count_of_iface(service) > 0)
1620 index = __connman_service_get_index(service);
1624 while (service->nameservers_config && service->nameservers_config[i]) {
1625 #if defined TIZEN_EXT
1626 DBG("type %d Remove service->nameservers_config[%d]: %s",
1627 type, i, service->nameservers_config[i]);
1629 case CONNMAN_IPCONFIG_TYPE_IPV4:
1630 if (connman_inet_check_ipaddress(
1631 service->nameservers_config[i]) == AF_INET &&
1632 (service->dns_config_method_ipv4 ==
1633 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1634 service->dns_config_method_ipv4 ==
1635 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1636 nameserver_remove(service, type,
1637 service->nameservers_config[i]);
1640 case CONNMAN_IPCONFIG_TYPE_IPV6:
1641 if (connman_inet_check_ipaddress(
1642 service->nameservers_config[i]) == AF_INET6 &&
1643 (service->dns_config_method_ipv6 ==
1644 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1645 service->dns_config_method_ipv6 ==
1646 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1647 nameserver_remove(service, type,
1648 service->nameservers_config[i]);
1651 case CONNMAN_IPCONFIG_TYPE_ALL:
1652 if (connman_inet_check_ipaddress(
1653 service->nameservers_config[i]) == AF_INET &&
1654 (service->dns_config_method_ipv4 ==
1655 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1656 service->dns_config_method_ipv4 ==
1657 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1658 nameserver_remove(service, type,
1659 service->nameservers_config[i]);
1661 if (connman_inet_check_ipaddress(
1662 service->nameservers_config[i]) == AF_INET6 &&
1663 (service->dns_config_method_ipv6 ==
1664 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1665 service->dns_config_method_ipv6 ==
1666 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1667 nameserver_remove(service, type,
1668 service->nameservers_config[i]);
1671 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1672 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1675 DBG("default case do nothing");
1679 nameserver_remove(service, type,
1680 service->nameservers_config[i]);
1686 while (service->nameservers && service->nameservers[i]) {
1687 #if defined TIZEN_EXT
1688 DBG("type %d Remove service->nameservers[%d]: %s",type, i,
1689 service->nameservers[i]);
1691 case CONNMAN_IPCONFIG_TYPE_IPV4:
1692 if (connman_inet_check_ipaddress(
1693 service->nameservers[i]) == AF_INET &&
1694 (service->dns_config_method_ipv4 ==
1695 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1696 service->dns_config_method_ipv4 ==
1697 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1698 nameserver_remove(service, type,
1699 service->nameservers[i]);
1702 case CONNMAN_IPCONFIG_TYPE_IPV6:
1703 if (connman_inet_check_ipaddress(
1704 service->nameservers[i]) == AF_INET6 &&
1705 (service->dns_config_method_ipv6 ==
1706 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1707 service->dns_config_method_ipv6 ==
1708 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1709 nameserver_remove(service, type,
1710 service->nameservers[i]);
1713 case CONNMAN_IPCONFIG_TYPE_ALL:
1714 if (connman_inet_check_ipaddress(
1715 service->nameservers[i]) == AF_INET &&
1716 (service->dns_config_method_ipv4 ==
1717 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1718 service->dns_config_method_ipv4 ==
1719 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1720 nameserver_remove(service, type,
1721 service->nameservers[i]);
1723 if (connman_inet_check_ipaddress(
1724 service->nameservers[i]) == AF_INET6 &&
1725 (service->dns_config_method_ipv6 ==
1726 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1727 service->dns_config_method_ipv6 ==
1728 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1729 nameserver_remove(service, type,
1730 service->nameservers[i]);
1733 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1734 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1737 DBG("default case do nothing");
1741 nameserver_remove(service, type, service->nameservers[i]);
1746 searchdomain_remove_all(service);
1752 * The is_auto variable is set to true when IPv6 autoconf nameservers are
1753 * inserted to resolver via netlink message (see rtnl.c:rtnl_newnduseropt()
1754 * for details) and not through service.c
1756 #if defined TIZEN_EXT
1757 int __connman_service_nameserver_append(struct connman_service *service,
1758 const char *nameserver, bool is_auto,
1759 enum connman_ipconfig_type type)
1761 int __connman_service_nameserver_append(struct connman_service *service,
1762 const char *nameserver, bool is_auto)
1768 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1774 nameservers = service->nameservers_auto;
1776 nameservers = service->nameservers;
1778 for (i = 0; nameservers && nameservers[i]; i++)
1779 #if defined TIZEN_EXT
1781 DBG("nameservers[%d] %s, nameserver %s", i, nameservers[i], nameserver);
1783 if (g_strcmp0(nameservers[i], nameserver) == 0)
1785 #if defined TIZEN_EXT
1790 len = g_strv_length(nameservers);
1791 nameservers = g_try_renew(char *, nameservers, len + 2);
1794 nameservers = g_try_new0(char *, len + 2);
1800 nameservers[len] = g_strdup(nameserver);
1801 nameservers[len + 1] = NULL;
1804 if(type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
1805 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
1806 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
1808 if(type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
1809 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
1810 service->dns_config_method_ipv6 = CONNMAN_DNSCONFIG_METHOD_DHCP;
1814 service->nameservers_auto = nameservers;
1816 service->nameservers = nameservers;
1817 nameserver_add(service, CONNMAN_IPCONFIG_TYPE_ALL, nameserver);
1820 nameservers_changed(service);
1822 searchdomain_add_all(service);
1827 #if defined TIZEN_EXT
1828 int __connman_service_nameserver_remove(struct connman_service *service,
1829 const char *nameserver, bool is_auto,
1830 enum connman_ipconfig_type type)
1832 int __connman_service_nameserver_remove(struct connman_service *service,
1833 const char *nameserver, bool is_auto)
1836 char **servers, **nameservers;
1840 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1846 nameservers = service->nameservers_auto;
1848 nameservers = service->nameservers;
1853 for (i = 0; nameservers[i]; i++)
1854 if (g_strcmp0(nameservers[i], nameserver) == 0) {
1862 len = g_strv_length(nameservers);
1869 servers = g_try_new0(char *, len);
1873 for (i = 0, j = 0; i < len; i++) {
1874 if (g_strcmp0(nameservers[i], nameserver)) {
1875 servers[j] = nameservers[i];
1878 g_free(nameservers[i]);
1880 nameservers[i] = NULL;
1882 servers[len - 1] = NULL;
1885 g_strfreev(nameservers);
1886 nameservers = servers;
1889 service->nameservers_auto = nameservers;
1891 service->nameservers = nameservers;
1892 #if defined TIZEN_EXT
1893 DBG("nameserver remove ip_type: %d", type);
1894 nameserver_remove(service, type,
1897 nameserver_remove(service, CONNMAN_IPCONFIG_TYPE_ALL,
1905 void __connman_service_nameserver_clear(struct connman_service *service)
1907 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
1909 g_strfreev(service->nameservers);
1910 service->nameservers = NULL;
1912 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
1915 static void add_nameserver_route(int family, int index, char *nameserver,
1920 if (connman_inet_compare_subnet(index, nameserver))
1923 if (connman_inet_add_host_route(index, nameserver, gw) < 0)
1924 /* For P-t-P link the above route add will fail */
1925 connman_inet_add_host_route(index, nameserver, NULL);
1929 if (connman_inet_add_ipv6_host_route(index, nameserver,
1931 connman_inet_add_ipv6_host_route(index, nameserver,
1937 static void nameserver_add_routes(int index, char **nameservers,
1940 int i, ns_family, gw_family;
1942 gw_family = connman_inet_check_ipaddress(gw);
1946 for (i = 0; nameservers[i]; i++) {
1947 ns_family = connman_inet_check_ipaddress(nameservers[i]);
1948 if (ns_family < 0 || ns_family != gw_family)
1951 add_nameserver_route(ns_family, index, nameservers[i], gw);
1955 static void nameserver_del_routes(int index, char **nameservers,
1956 enum connman_ipconfig_type type)
1960 for (i = 0; nameservers[i]; i++) {
1961 family = connman_inet_check_ipaddress(nameservers[i]);
1967 if (type != CONNMAN_IPCONFIG_TYPE_IPV6)
1968 connman_inet_del_host_route(index,
1972 if (type != CONNMAN_IPCONFIG_TYPE_IPV4)
1973 connman_inet_del_ipv6_host_route(index,
1980 void __connman_service_nameserver_add_routes(struct connman_service *service,
1988 index = __connman_service_get_index(service);
1990 if (service->nameservers_config) {
1992 * Configured nameserver takes preference over the
1993 * discoverd nameserver gathered from DHCP, VPN, etc.
1995 nameserver_add_routes(index, service->nameservers_config, gw);
1996 } else if (service->nameservers) {
1998 * We add nameservers host routes for nameservers that
1999 * are not on our subnet. For those who are, the subnet
2000 * route will be installed by the time the dns proxy code
2001 * tries to reach them. The subnet route is installed
2002 * when setting the interface IP address.
2004 nameserver_add_routes(index, service->nameservers, gw);
2008 void __connman_service_nameserver_del_routes(struct connman_service *service,
2009 enum connman_ipconfig_type type)
2016 index = __connman_service_get_index(service);
2018 if (service->nameservers_config)
2019 nameserver_del_routes(index, service->nameservers_config,
2021 else if (service->nameservers)
2022 nameserver_del_routes(index, service->nameservers, type);
2025 static void address_updated(struct connman_service *service,
2026 enum connman_ipconfig_type type)
2028 if (is_connected(service->state) &&
2029 service == __connman_service_get_default()) {
2030 nameserver_remove_all(service, type);
2031 nameserver_add_all(service, type);
2033 __connman_timeserver_sync(service);
2037 static struct connman_stats *stats_get(struct connman_service *service)
2039 if (service->roaming)
2040 return &service->stats_roaming;
2042 return &service->stats;
2045 static bool stats_enabled(struct connman_service *service)
2047 struct connman_stats *stats = stats_get(service);
2049 return stats->enabled;
2052 static void stats_start(struct connman_service *service)
2054 struct connman_stats *stats = stats_get(service);
2056 DBG("service %p", service);
2061 stats->enabled = true;
2062 stats->data_last.time = stats->data.time;
2064 g_timer_start(stats->timer);
2067 static void stats_stop(struct connman_service *service)
2069 struct connman_stats *stats = stats_get(service);
2070 unsigned int seconds;
2072 DBG("service %p", service);
2077 if (!stats->enabled)
2080 g_timer_stop(stats->timer);
2082 seconds = g_timer_elapsed(stats->timer, NULL);
2083 stats->data.time = stats->data_last.time + seconds;
2085 stats->enabled = false;
2088 static void reset_stats(struct connman_service *service)
2090 DBG("service %p", service);
2093 service->stats.valid = false;
2095 service->stats.data.rx_packets = 0;
2096 service->stats.data.tx_packets = 0;
2097 service->stats.data.rx_bytes = 0;
2098 service->stats.data.tx_bytes = 0;
2099 service->stats.data.rx_errors = 0;
2100 service->stats.data.tx_errors = 0;
2101 service->stats.data.rx_dropped = 0;
2102 service->stats.data.tx_dropped = 0;
2103 service->stats.data.time = 0;
2104 service->stats.data_last.time = 0;
2106 g_timer_reset(service->stats.timer);
2109 service->stats_roaming.valid = false;
2111 service->stats_roaming.data.rx_packets = 0;
2112 service->stats_roaming.data.tx_packets = 0;
2113 service->stats_roaming.data.rx_bytes = 0;
2114 service->stats_roaming.data.tx_bytes = 0;
2115 service->stats_roaming.data.rx_errors = 0;
2116 service->stats_roaming.data.tx_errors = 0;
2117 service->stats_roaming.data.rx_dropped = 0;
2118 service->stats_roaming.data.tx_dropped = 0;
2119 service->stats_roaming.data.time = 0;
2120 service->stats_roaming.data_last.time = 0;
2122 g_timer_reset(service->stats_roaming.timer);
2125 #if defined TIZEN_EXT
2126 static gboolean __connman_service_is_internet_profile(
2127 struct connman_service *cellular)
2129 const char internet_suffix[] = "_1";
2131 DBG("Service path: %s", cellular->path);
2133 if (g_str_has_suffix(cellular->path, internet_suffix) == TRUE)
2139 static gboolean __connman_service_is_tethering_profile(
2140 struct connman_service *cellular)
2142 const char tethering_suffix[] = "_5";
2144 DBG("Service path: %s", cellular->path);
2146 if (g_str_has_suffix(cellular->path, tethering_suffix) == TRUE)
2152 struct connman_service *connman_service_get_default_connection(void)
2155 struct connman_service *service;
2156 struct connman_service *default_service = NULL;
2158 for (list = service_list; list; list = list->next) {
2159 service = list->data;
2161 DBG("service: %p %s %s %s", service, service->name,
2162 state2string(service->state),
2163 __connman_service_type2string(service->type));
2165 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
2166 is_connected(service->state) == TRUE) {
2168 } else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
2169 __connman_service_is_internet_profile(service) == TRUE) {
2170 if (default_service == NULL)
2171 default_service = service;
2172 else if (is_connected(service->state) == TRUE &&
2173 is_connected(default_service->state) == FALSE)
2174 default_service = service;
2175 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET &&
2176 is_connected(service->state) == TRUE) {
2177 if (default_service == NULL)
2178 default_service = service;
2179 } else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH &&
2180 is_connected(service->state) == TRUE) {
2181 if (default_service == NULL)
2182 default_service = service;
2186 return default_service;
2190 struct connman_service *__connman_service_get_default(void)
2192 struct connman_service *service;
2197 service = service_list->data;
2199 if (!is_connected(service->state))
2205 bool __connman_service_index_is_default(int index)
2207 struct connman_service *service;
2212 service = __connman_service_get_default();
2214 return __connman_service_get_index(service) == index;
2217 static void default_changed(void)
2219 struct connman_service *service = __connman_service_get_default();
2221 if (service == current_default)
2224 DBG("current default %p %s", current_default,
2225 current_default ? current_default->identifier : "");
2226 DBG("new default %p %s", service, service ? service->identifier : "");
2228 #if defined TIZEN_EXT
2229 current_default = service;
2231 __connman_service_timeserver_changed(service, NULL);
2233 __connman_service_timeserver_changed(current_default, NULL);
2235 current_default = service;
2239 if (service->hostname &&
2240 connman_setting_get_bool("AllowHostnameUpdates"))
2241 __connman_utsname_set_hostname(service->hostname);
2243 if (service->domainname)
2244 __connman_utsname_set_domainname(service->domainname);
2247 __connman_notifier_default_changed(service);
2250 static void state_changed(struct connman_service *service)
2254 __connman_notifier_service_state_changed(service, service->state);
2256 str = state2string(service->state);
2260 #if !defined TIZEN_EXT
2261 if (!allow_property_changed(service))
2264 #if defined TIZEN_EXT
2265 DBG(" %s, %s", str, service->path);
2267 connman_dbus_property_changed_basic(service->path,
2268 CONNMAN_SERVICE_INTERFACE, "State",
2269 DBUS_TYPE_STRING, &str);
2272 static void strength_changed(struct connman_service *service)
2274 if (service->strength == 0)
2277 if (!allow_property_changed(service))
2280 connman_dbus_property_changed_basic(service->path,
2281 CONNMAN_SERVICE_INTERFACE, "Strength",
2282 DBUS_TYPE_BYTE, &service->strength);
2285 static void favorite_changed(struct connman_service *service)
2287 dbus_bool_t favorite;
2292 if (!allow_property_changed(service))
2295 favorite = service->favorite;
2296 connman_dbus_property_changed_basic(service->path,
2297 CONNMAN_SERVICE_INTERFACE, "Favorite",
2298 DBUS_TYPE_BOOLEAN, &favorite);
2301 static void immutable_changed(struct connman_service *service)
2303 dbus_bool_t immutable;
2308 if (!allow_property_changed(service))
2311 immutable = service->immutable;
2312 connman_dbus_property_changed_basic(service->path,
2313 CONNMAN_SERVICE_INTERFACE, "Immutable",
2314 DBUS_TYPE_BOOLEAN, &immutable);
2317 static void roaming_changed(struct connman_service *service)
2319 dbus_bool_t roaming;
2324 if (!allow_property_changed(service))
2327 roaming = service->roaming;
2328 connman_dbus_property_changed_basic(service->path,
2329 CONNMAN_SERVICE_INTERFACE, "Roaming",
2330 DBUS_TYPE_BOOLEAN, &roaming);
2333 static void autoconnect_changed(struct connman_service *service)
2335 dbus_bool_t autoconnect;
2340 if (!allow_property_changed(service))
2343 autoconnect = service->autoconnect;
2344 connman_dbus_property_changed_basic(service->path,
2345 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
2346 DBUS_TYPE_BOOLEAN, &autoconnect);
2349 static void append_security(DBusMessageIter *iter, void *user_data)
2351 struct connman_service *service = user_data;
2354 str = security2string(service->security);
2356 dbus_message_iter_append_basic(iter,
2357 DBUS_TYPE_STRING, &str);
2360 * Some access points incorrectly advertise WPS even when they
2361 * are configured as open or no security, so filter
2365 switch (service->security) {
2366 case CONNMAN_SERVICE_SECURITY_PSK:
2367 case CONNMAN_SERVICE_SECURITY_WPA:
2368 case CONNMAN_SERVICE_SECURITY_RSN:
2370 dbus_message_iter_append_basic(iter,
2371 DBUS_TYPE_STRING, &str);
2373 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
2374 case CONNMAN_SERVICE_SECURITY_NONE:
2375 case CONNMAN_SERVICE_SECURITY_WEP:
2376 case CONNMAN_SERVICE_SECURITY_8021X:
2382 static void append_ethernet(DBusMessageIter *iter, void *user_data)
2384 struct connman_service *service = user_data;
2386 if (service->ipconfig_ipv4)
2387 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
2389 else if (service->ipconfig_ipv6)
2390 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
2394 static void append_ipv4(DBusMessageIter *iter, void *user_data)
2396 struct connman_service *service = user_data;
2398 if (!is_connected(service->state_ipv4))
2401 if (service->ipconfig_ipv4)
2402 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
2405 static void append_ipv6(DBusMessageIter *iter, void *user_data)
2407 struct connman_service *service = user_data;
2409 if (!is_connected(service->state_ipv6))
2412 if (service->ipconfig_ipv6)
2413 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
2414 service->ipconfig_ipv4);
2417 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
2419 struct connman_service *service = user_data;
2421 if (service->ipconfig_ipv4)
2422 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
2426 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
2428 struct connman_service *service = user_data;
2430 if (service->ipconfig_ipv6)
2431 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
2435 static void append_nameservers(DBusMessageIter *iter,
2436 struct connman_service *service, char **servers)
2439 bool available = true;
2441 for (i = 0; servers[i]; i++) {
2443 available = nameserver_available(service,
2444 CONNMAN_IPCONFIG_TYPE_ALL,
2448 dbus_message_iter_append_basic(iter,
2449 DBUS_TYPE_STRING, &servers[i]);
2453 #if defined TIZEN_EXT
2454 static void append_nameserver_manual(DBusMessageIter *iter,
2455 struct connman_service *service, const char *server)
2457 bool available = true;
2460 available = nameserver_available(service,
2461 CONNMAN_IPCONFIG_TYPE_ALL, server);
2464 dbus_message_iter_append_basic(iter,
2465 DBUS_TYPE_STRING, &server);
2468 static void append_nameserver_dhcp(DBusMessageIter *iter,
2469 struct connman_service *service, const char *server)
2471 bool available = true;
2474 available = nameserver_available(service,
2475 CONNMAN_IPCONFIG_TYPE_ALL, server);
2478 dbus_message_iter_append_basic(iter,
2479 DBUS_TYPE_STRING, &server);
2483 static void append_dns(DBusMessageIter *iter, void *user_data)
2485 struct connman_service *service = user_data;
2486 #if defined TIZEN_EXT
2490 if (!is_connected(service->state))
2496 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
2498 char *str1 = g_strdup_printf("ipv4.%s", str);
2499 dbus_message_iter_append_basic(iter,
2500 DBUS_TYPE_STRING, &str1);
2504 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
2506 char *str1 = g_strdup_printf("ipv6.%s", str);
2507 dbus_message_iter_append_basic(iter,
2508 DBUS_TYPE_STRING, &str1);
2513 if (service->nameservers_config) {
2514 #if defined TIZEN_EXT
2516 while (service->nameservers_config[i]) {
2517 if (connman_inet_check_ipaddress(
2518 service->nameservers_config[i]) == AF_INET &&
2519 service->dns_config_method_ipv4 ==
2520 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2521 append_nameserver_manual(iter, service,
2522 service->nameservers_config[i]);
2525 if (connman_inet_check_ipaddress(
2526 service->nameservers_config[i]) == AF_INET6 &&
2527 service->dns_config_method_ipv6 ==
2528 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2529 append_nameserver_manual(iter, service,
2530 service->nameservers_config[i]);
2534 /* In case of mixed DNS Config Type one of IPv4/IPv6 can be
2535 * dynamic while other is static so try to append the DNS
2536 * Address which is dynamic also */
2537 if (service->nameservers != NULL) {
2539 while (service->nameservers[i]) {
2540 if (connman_inet_check_ipaddress(
2541 service->nameservers[i]) == AF_INET &&
2542 service->dns_config_method_ipv4 ==
2543 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2544 append_nameserver_dhcp(iter, service,
2545 service->nameservers[i]);
2548 if (connman_inet_check_ipaddress(
2549 service->nameservers[i]) == AF_INET6 &&
2550 service->dns_config_method_ipv6 ==
2551 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2552 append_nameserver_dhcp(iter, service,
2553 service->nameservers[i]);
2559 append_nameservers(iter, service, service->nameservers_config);
2563 if (service->nameservers)
2564 #if defined TIZEN_EXT
2567 while (service->nameservers[i]) {
2568 if (connman_inet_check_ipaddress(
2569 service->nameservers[i]) == AF_INET &&
2570 service->dns_config_method_ipv4 ==
2571 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2572 append_nameserver_dhcp(iter, service,
2573 service->nameservers[i]);
2576 if (connman_inet_check_ipaddress(
2577 service->nameservers[i]) == AF_INET6 &&
2578 service->dns_config_method_ipv6 ==
2579 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2580 append_nameserver_dhcp(iter, service,
2581 service->nameservers[i]);
2587 append_nameservers(iter, service,
2588 service->nameservers);
2591 if (service->nameservers_auto)
2592 append_nameservers(iter, service,
2593 service->nameservers_auto);
2595 if (!service->nameservers && !service->nameservers_auto) {
2598 DBG("append fallback nameservers");
2600 ns = connman_setting_get_string_list("FallbackNameservers");
2602 append_nameservers(iter, service, ns);
2607 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
2609 struct connman_service *service = user_data;
2612 /* Append DNS Config Type */
2614 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
2616 char *str1 = g_strdup_printf("ipv4.%s", str);
2617 dbus_message_iter_append_basic(iter,
2618 DBUS_TYPE_STRING, &str1);
2622 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
2624 char *str1 = g_strdup_printf("ipv6.%s", str);
2625 dbus_message_iter_append_basic(iter,
2626 DBUS_TYPE_STRING, &str1);
2631 if (!service->nameservers_config)
2634 #if defined TIZEN_EXT
2636 while (service->nameservers_config[i]) {
2637 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET &&
2638 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2639 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
2642 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET6 &&
2643 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2644 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
2649 append_nameservers(iter, NULL, service->nameservers_config);
2653 static void append_ts(DBusMessageIter *iter, void *user_data)
2655 GSList *list = user_data;
2658 char *timeserver = list->data;
2661 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
2664 list = g_slist_next(list);
2668 static void append_tsconfig(DBusMessageIter *iter, void *user_data)
2670 struct connman_service *service = user_data;
2673 if (!service->timeservers_config)
2676 for (i = 0; service->timeservers_config[i]; i++) {
2677 dbus_message_iter_append_basic(iter,
2679 &service->timeservers_config[i]);
2683 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
2685 struct connman_service *service = user_data;
2688 if (!service->domains)
2691 for (i = 0; service->domains[i]; i++)
2692 dbus_message_iter_append_basic(iter,
2693 DBUS_TYPE_STRING, &service->domains[i]);
2696 static void append_domain(DBusMessageIter *iter, void *user_data)
2698 struct connman_service *service = user_data;
2700 if (!is_connected(service->state) &&
2701 !is_connecting(service->state))
2704 if (service->domains)
2705 append_domainconfig(iter, user_data);
2706 else if (service->domainname)
2707 dbus_message_iter_append_basic(iter,
2708 DBUS_TYPE_STRING, &service->domainname);
2711 static void append_proxies(DBusMessageIter *iter, void *user_data)
2713 struct connman_service *service = user_data;
2716 if (!service->proxies)
2719 for (i = 0; service->proxies[i]; i++)
2720 dbus_message_iter_append_basic(iter,
2721 DBUS_TYPE_STRING, &service->proxies[i]);
2724 static void append_excludes(DBusMessageIter *iter, void *user_data)
2726 struct connman_service *service = user_data;
2729 if (!service->excludes)
2732 for (i = 0; service->excludes[i]; i++)
2733 dbus_message_iter_append_basic(iter,
2734 DBUS_TYPE_STRING, &service->excludes[i]);
2737 static void append_proxy(DBusMessageIter *iter, void *user_data)
2739 struct connman_service *service = user_data;
2740 enum connman_service_proxy_method proxy;
2741 const char *pac = NULL;
2742 const char *method = proxymethod2string(
2743 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
2745 if (!is_connected(service->state))
2748 proxy = connman_service_get_proxy_method(service);
2751 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2753 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2755 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2756 connman_dbus_dict_append_array(iter, "Servers",
2757 DBUS_TYPE_STRING, append_proxies,
2760 connman_dbus_dict_append_array(iter, "Excludes",
2761 DBUS_TYPE_STRING, append_excludes,
2764 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2765 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
2766 if (service->ipconfig_ipv4)
2767 pac = __connman_ipconfig_get_proxy_autoconfig(
2768 service->ipconfig_ipv4);
2769 else if (service->ipconfig_ipv6)
2770 pac = __connman_ipconfig_get_proxy_autoconfig(
2771 service->ipconfig_ipv6);
2773 if (!service->pac && !pac)
2779 connman_dbus_dict_append_basic(iter, "URL",
2780 DBUS_TYPE_STRING, &pac);
2784 method = proxymethod2string(proxy);
2787 connman_dbus_dict_append_basic(iter, "Method",
2788 DBUS_TYPE_STRING, &method);
2791 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
2793 struct connman_service *service = user_data;
2796 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
2799 switch (service->proxy_config) {
2800 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2802 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2804 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2805 if (service->proxies)
2806 connman_dbus_dict_append_array(iter, "Servers",
2808 append_proxies, service);
2810 if (service->excludes)
2811 connman_dbus_dict_append_array(iter, "Excludes",
2813 append_excludes, service);
2815 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2817 connman_dbus_dict_append_basic(iter, "URL",
2818 DBUS_TYPE_STRING, &service->pac);
2822 method = proxymethod2string(service->proxy_config);
2824 connman_dbus_dict_append_basic(iter, "Method",
2825 DBUS_TYPE_STRING, &method);
2828 static void append_provider(DBusMessageIter *iter, void *user_data)
2830 struct connman_service *service = user_data;
2832 if (!is_connected(service->state))
2835 if (service->provider)
2836 __connman_provider_append_properties(service->provider, iter);
2840 static void settings_changed(struct connman_service *service,
2841 struct connman_ipconfig *ipconfig)
2843 enum connman_ipconfig_type type;
2845 type = __connman_ipconfig_get_config_type(ipconfig);
2847 __connman_notifier_ipconfig_changed(service, ipconfig);
2849 if (!allow_property_changed(service))
2852 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
2853 connman_dbus_property_changed_dict(service->path,
2854 CONNMAN_SERVICE_INTERFACE, "IPv4",
2855 append_ipv4, service);
2856 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2857 connman_dbus_property_changed_dict(service->path,
2858 CONNMAN_SERVICE_INTERFACE, "IPv6",
2859 append_ipv6, service);
2862 static void ipv4_configuration_changed(struct connman_service *service)
2864 if (!allow_property_changed(service))
2867 connman_dbus_property_changed_dict(service->path,
2868 CONNMAN_SERVICE_INTERFACE,
2869 "IPv4.Configuration",
2874 void __connman_service_notify_ipv4_configuration(
2875 struct connman_service *service)
2880 ipv4_configuration_changed(service);
2883 static void ipv6_configuration_changed(struct connman_service *service)
2885 if (!allow_property_changed(service))
2888 connman_dbus_property_changed_dict(service->path,
2889 CONNMAN_SERVICE_INTERFACE,
2890 "IPv6.Configuration",
2895 static void dns_changed(struct connman_service *service)
2897 if (!allow_property_changed(service))
2900 connman_dbus_property_changed_array(service->path,
2901 CONNMAN_SERVICE_INTERFACE, "Nameservers",
2902 DBUS_TYPE_STRING, append_dns, service);
2905 static void dns_configuration_changed(struct connman_service *service)
2907 if (!allow_property_changed(service))
2910 connman_dbus_property_changed_array(service->path,
2911 CONNMAN_SERVICE_INTERFACE,
2912 "Nameservers.Configuration",
2913 DBUS_TYPE_STRING, append_dnsconfig, service);
2915 dns_changed(service);
2918 static void domain_changed(struct connman_service *service)
2920 if (!allow_property_changed(service))
2923 connman_dbus_property_changed_array(service->path,
2924 CONNMAN_SERVICE_INTERFACE, "Domains",
2925 DBUS_TYPE_STRING, append_domain, service);
2928 static void domain_configuration_changed(struct connman_service *service)
2930 if (!allow_property_changed(service))
2933 connman_dbus_property_changed_array(service->path,
2934 CONNMAN_SERVICE_INTERFACE,
2935 "Domains.Configuration",
2936 DBUS_TYPE_STRING, append_domainconfig, service);
2939 static void proxy_changed(struct connman_service *service)
2941 if (!allow_property_changed(service))
2944 connman_dbus_property_changed_dict(service->path,
2945 CONNMAN_SERVICE_INTERFACE, "Proxy",
2946 append_proxy, service);
2949 static void proxy_configuration_changed(struct connman_service *service)
2951 if (!allow_property_changed(service))
2954 connman_dbus_property_changed_dict(service->path,
2955 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
2956 append_proxyconfig, service);
2958 proxy_changed(service);
2961 static void timeservers_configuration_changed(struct connman_service *service)
2963 if (!allow_property_changed(service))
2966 connman_dbus_property_changed_array(service->path,
2967 CONNMAN_SERVICE_INTERFACE,
2968 "Timeservers.Configuration",
2970 append_tsconfig, service);
2973 static void link_changed(struct connman_service *service)
2975 if (!allow_property_changed(service))
2978 connman_dbus_property_changed_dict(service->path,
2979 CONNMAN_SERVICE_INTERFACE, "Ethernet",
2980 append_ethernet, service);
2983 static void stats_append_counters(DBusMessageIter *dict,
2984 struct connman_stats_data *stats,
2985 struct connman_stats_data *counters,
2988 if (counters->rx_packets != stats->rx_packets || append_all) {
2989 counters->rx_packets = stats->rx_packets;
2990 connman_dbus_dict_append_basic(dict, "RX.Packets",
2991 DBUS_TYPE_UINT32, &stats->rx_packets);
2994 if (counters->tx_packets != stats->tx_packets || append_all) {
2995 counters->tx_packets = stats->tx_packets;
2996 connman_dbus_dict_append_basic(dict, "TX.Packets",
2997 DBUS_TYPE_UINT32, &stats->tx_packets);
3000 if (counters->rx_bytes != stats->rx_bytes || append_all) {
3001 counters->rx_bytes = stats->rx_bytes;
3002 connman_dbus_dict_append_basic(dict, "RX.Bytes",
3003 DBUS_TYPE_UINT32, &stats->rx_bytes);
3006 if (counters->tx_bytes != stats->tx_bytes || append_all) {
3007 counters->tx_bytes = stats->tx_bytes;
3008 connman_dbus_dict_append_basic(dict, "TX.Bytes",
3009 DBUS_TYPE_UINT32, &stats->tx_bytes);
3012 if (counters->rx_errors != stats->rx_errors || append_all) {
3013 counters->rx_errors = stats->rx_errors;
3014 connman_dbus_dict_append_basic(dict, "RX.Errors",
3015 DBUS_TYPE_UINT32, &stats->rx_errors);
3018 if (counters->tx_errors != stats->tx_errors || append_all) {
3019 counters->tx_errors = stats->tx_errors;
3020 connman_dbus_dict_append_basic(dict, "TX.Errors",
3021 DBUS_TYPE_UINT32, &stats->tx_errors);
3024 if (counters->rx_dropped != stats->rx_dropped || append_all) {
3025 counters->rx_dropped = stats->rx_dropped;
3026 connman_dbus_dict_append_basic(dict, "RX.Dropped",
3027 DBUS_TYPE_UINT32, &stats->rx_dropped);
3030 if (counters->tx_dropped != stats->tx_dropped || append_all) {
3031 counters->tx_dropped = stats->tx_dropped;
3032 connman_dbus_dict_append_basic(dict, "TX.Dropped",
3033 DBUS_TYPE_UINT32, &stats->tx_dropped);
3036 if (counters->time != stats->time || append_all) {
3037 counters->time = stats->time;
3038 connman_dbus_dict_append_basic(dict, "Time",
3039 DBUS_TYPE_UINT32, &stats->time);
3043 static void stats_append(struct connman_service *service,
3044 const char *counter,
3045 struct connman_stats_counter *counters,
3048 DBusMessageIter array, dict;
3051 DBG("service %p counter %s", service, counter);
3053 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
3057 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
3058 &service->path, DBUS_TYPE_INVALID);
3060 dbus_message_iter_init_append(msg, &array);
3063 connman_dbus_dict_open(&array, &dict);
3065 stats_append_counters(&dict, &service->stats.data,
3066 &counters->stats.data, append_all);
3068 connman_dbus_dict_close(&array, &dict);
3070 /* roaming counter */
3071 connman_dbus_dict_open(&array, &dict);
3073 stats_append_counters(&dict, &service->stats_roaming.data,
3074 &counters->stats_roaming.data, append_all);
3076 connman_dbus_dict_close(&array, &dict);
3078 __connman_counter_send_usage(counter, msg);
3081 static void stats_update(struct connman_service *service,
3082 unsigned int rx_packets, unsigned int tx_packets,
3083 unsigned int rx_bytes, unsigned int tx_bytes,
3084 unsigned int rx_errors, unsigned int tx_errors,
3085 unsigned int rx_dropped, unsigned int tx_dropped)
3087 struct connman_stats *stats = stats_get(service);
3088 struct connman_stats_data *data_last = &stats->data_last;
3089 struct connman_stats_data *data = &stats->data;
3090 unsigned int seconds;
3092 DBG("service %p", service);
3096 rx_packets - data_last->rx_packets;
3098 tx_packets - data_last->tx_packets;
3100 rx_bytes - data_last->rx_bytes;
3102 tx_bytes - data_last->tx_bytes;
3104 rx_errors - data_last->rx_errors;
3106 tx_errors - data_last->tx_errors;
3108 rx_dropped - data_last->rx_dropped;
3110 tx_dropped - data_last->tx_dropped;
3112 stats->valid = true;
3115 data_last->rx_packets = rx_packets;
3116 data_last->tx_packets = tx_packets;
3117 data_last->rx_bytes = rx_bytes;
3118 data_last->tx_bytes = tx_bytes;
3119 data_last->rx_errors = rx_errors;
3120 data_last->tx_errors = tx_errors;
3121 data_last->rx_dropped = rx_dropped;
3122 data_last->tx_dropped = tx_dropped;
3124 seconds = g_timer_elapsed(stats->timer, NULL);
3125 stats->data.time = stats->data_last.time + seconds;
3128 void __connman_service_notify(struct connman_service *service,
3129 unsigned int rx_packets, unsigned int tx_packets,
3130 unsigned int rx_bytes, unsigned int tx_bytes,
3131 unsigned int rx_errors, unsigned int tx_errors,
3132 unsigned int rx_dropped, unsigned int tx_dropped)
3134 GHashTableIter iter;
3135 gpointer key, value;
3136 const char *counter;
3137 struct connman_stats_counter *counters;
3138 struct connman_stats_data *data;
3144 if (!is_connected(service->state))
3147 stats_update(service,
3148 rx_packets, tx_packets,
3150 rx_errors, tx_errors,
3151 rx_dropped, tx_dropped);
3153 data = &stats_get(service)->data;
3154 err = __connman_stats_update(service, service->roaming, data);
3156 connman_error("Failed to store statistics for %s",
3157 service->identifier);
3159 g_hash_table_iter_init(&iter, service->counter_table);
3160 while (g_hash_table_iter_next(&iter, &key, &value)) {
3164 stats_append(service, counter, counters, counters->append_all);
3165 counters->append_all = false;
3169 int __connman_service_counter_register(const char *counter)
3171 struct connman_service *service;
3173 struct connman_stats_counter *counters;
3175 DBG("counter %s", counter);
3177 counter_list = g_slist_prepend(counter_list, (gpointer)counter);
3179 for (list = service_list; list; list = list->next) {
3180 service = list->data;
3182 counters = g_try_new0(struct connman_stats_counter, 1);
3186 counters->append_all = true;
3188 g_hash_table_replace(service->counter_table, (gpointer)counter,
3195 void __connman_service_counter_unregister(const char *counter)
3197 struct connman_service *service;
3200 DBG("counter %s", counter);
3202 for (list = service_list; list; list = list->next) {
3203 service = list->data;
3205 g_hash_table_remove(service->counter_table, counter);
3208 counter_list = g_slist_remove(counter_list, counter);
3211 int __connman_service_iterate_services(service_iterate_cb cb, void *user_data)
3215 for (list = service_list; list; list = list->next) {
3216 struct connman_service *service = list->data;
3218 cb(service, user_data);
3224 #if defined TIZEN_EXT
3225 static void append_wifi_ext_info(DBusMessageIter *dict,
3226 struct connman_network *network)
3228 char bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
3229 char *bssid_str = bssid_buff;
3231 unsigned int ssid_len;
3232 unsigned char *bssid;
3233 unsigned int maxrate;
3234 unsigned int keymgmt;
3236 const char *enc_mode;
3239 char country_code_buff[WIFI_COUNTRY_CODE_LEN + 1] = {0,};
3240 char *country_code_str = country_code_buff;
3241 unsigned char *country_code;
3243 ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
3244 bssid = connman_network_get_bssid(network);
3245 maxrate = connman_network_get_maxrate(network);
3246 frequency = connman_network_get_frequency(network);
3247 enc_mode = connman_network_get_enc_mode(network);
3248 passpoint = connman_network_get_bool(network, "WiFi.HS20AP");
3249 keymgmt = connman_network_get_keymgmt(network);
3250 country_code = connman_network_get_countrycode(network);
3252 snprintf(bssid_str, WIFI_BSSID_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
3253 bssid[0], bssid[1], bssid[2],
3254 bssid[3], bssid[4], bssid[5]);
3256 snprintf(country_code_str, (WIFI_COUNTRY_CODE_LEN + 1), "%c%c",
3257 country_code[0], country_code[1]);
3260 connman_dbus_dict_append_fixed_array(dict, "SSID",
3261 DBUS_TYPE_BYTE, &ssid, ssid_len);
3262 connman_dbus_dict_append_basic(dict, "BSSID",
3263 DBUS_TYPE_STRING, &bssid_str);
3264 connman_dbus_dict_append_basic(dict, "MaxRate",
3265 DBUS_TYPE_UINT32, &maxrate);
3266 connman_dbus_dict_append_basic(dict, "Frequency",
3267 DBUS_TYPE_UINT16, &frequency);
3268 connman_dbus_dict_append_basic(dict, "EncryptionMode",
3269 DBUS_TYPE_STRING, &enc_mode);
3270 connman_dbus_dict_append_basic(dict, "Passpoint",
3271 DBUS_TYPE_BOOLEAN, &passpoint);
3272 connman_dbus_dict_append_basic(dict, "Keymgmt",
3273 DBUS_TYPE_UINT32, &keymgmt);
3274 connman_dbus_dict_append_basic(dict, "Country", DBUS_TYPE_STRING,
3277 str = connman_network_get_string(network, "WiFi.Security");
3278 if (str != NULL && g_str_equal(str, "ieee8021x") == TRUE) {
3279 str = connman_network_get_string(network, "WiFi.EAP");
3281 connman_dbus_dict_append_basic(dict, "EAP",
3282 DBUS_TYPE_STRING, &str);
3284 str = connman_network_get_string(network, "WiFi.Phase2");
3286 connman_dbus_dict_append_basic(dict, "Phase2",
3287 DBUS_TYPE_STRING, &str);
3289 str = connman_network_get_string(network, "WiFi.Identity");
3291 connman_dbus_dict_append_basic(dict, "Identity",
3292 DBUS_TYPE_STRING, &str);
3294 str = connman_network_get_string(network, "WiFi.CACertFile");
3296 connman_dbus_dict_append_basic(dict, "CACertFile",
3297 DBUS_TYPE_STRING, &str);
3299 str = connman_network_get_string(network,
3300 "WiFi.ClientCertFile");
3302 connman_dbus_dict_append_basic(dict, "ClientCertFile",
3303 DBUS_TYPE_STRING, &str);
3305 str = connman_network_get_string(network,
3306 "WiFi.PrivateKeyFile");
3308 connman_dbus_dict_append_basic(dict, "PrivateKeyFile",
3309 DBUS_TYPE_STRING, &str);
3313 static void append_bssid_info(DBusMessageIter *iter, void *user_data)
3315 GSList *bssid_list = NULL;
3316 struct connman_network *network = user_data;
3317 struct connman_bssids *bssids;
3318 char bssid_buf[18] = {0,};
3319 char *bssid_str = bssid_buf;
3321 bssid_list = (GSList *)connman_network_get_bssid_list(network);
3324 for (list = bssid_list; list; list = list->next) {
3325 bssids = (struct connman_bssids *)list->data;
3326 memcpy(bssid_str, bssids->bssid, 18);
3328 connman_dbus_dict_append_basic(iter, "BSSID",
3329 DBUS_TYPE_STRING, &bssid_str);
3331 connman_dbus_dict_append_basic(iter, "Strength",
3332 DBUS_TYPE_UINT16, &bssids->strength);
3334 connman_dbus_dict_append_basic(iter, "Frequency",
3335 DBUS_TYPE_UINT16, &bssids->frequency);
3341 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
3342 struct connman_service *service)
3348 #if defined TIZEN_EXT
3349 unsigned int frequency = 0U;
3350 if (service && service->network) {
3351 frequency = connman_network_get_frequency(service->network);
3352 connman_dbus_dict_append_basic(dict, "Frequency",
3353 DBUS_TYPE_UINT16, &frequency);
3356 unsigned char *wifi_vsie;
3357 unsigned int wifi_vsie_len;
3358 GSList *vsie_list = NULL;
3360 if (service->network)
3361 vsie_list = (GSList *)connman_network_get_vsie_list(service->network);
3365 for (list = vsie_list; list; list = list->next) {
3366 wifi_vsie = (unsigned char *)list->data;
3367 wifi_vsie_len = wifi_vsie[1] + 2;
3369 connman_dbus_dict_append_fixed_array(dict, "Vsie", DBUS_TYPE_BYTE,
3370 &wifi_vsie, wifi_vsie_len);
3375 str = __connman_service_type2string(service->type);
3377 connman_dbus_dict_append_basic(dict, "Type",
3378 DBUS_TYPE_STRING, &str);
3380 connman_dbus_dict_append_array(dict, "Security",
3381 DBUS_TYPE_STRING, append_security, service);
3383 str = state2string(service->state);
3385 connman_dbus_dict_append_basic(dict, "State",
3386 DBUS_TYPE_STRING, &str);
3389 str = state2string(service->state_ipv6);
3391 connman_dbus_dict_append_basic(dict, "StateIPv6",
3392 DBUS_TYPE_STRING, &str);
3395 str = error2string(service->error);
3397 connman_dbus_dict_append_basic(dict, "Error",
3398 DBUS_TYPE_STRING, &str);
3400 if (service->strength > 0)
3401 connman_dbus_dict_append_basic(dict, "Strength",
3402 DBUS_TYPE_BYTE, &service->strength);
3404 val = service->favorite;
3405 connman_dbus_dict_append_basic(dict, "Favorite",
3406 DBUS_TYPE_BOOLEAN, &val);
3408 val = service->immutable;
3409 connman_dbus_dict_append_basic(dict, "Immutable",
3410 DBUS_TYPE_BOOLEAN, &val);
3412 if (service->favorite)
3413 val = service->autoconnect;
3415 val = service->favorite;
3417 connman_dbus_dict_append_basic(dict, "AutoConnect",
3418 DBUS_TYPE_BOOLEAN, &val);
3421 connman_dbus_dict_append_basic(dict, "Name",
3422 DBUS_TYPE_STRING, &service->name);
3424 switch (service->type) {
3425 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3426 case CONNMAN_SERVICE_TYPE_SYSTEM:
3427 case CONNMAN_SERVICE_TYPE_GPS:
3428 case CONNMAN_SERVICE_TYPE_VPN:
3429 case CONNMAN_SERVICE_TYPE_P2P:
3431 case CONNMAN_SERVICE_TYPE_CELLULAR:
3432 val = service->roaming;
3433 connman_dbus_dict_append_basic(dict, "Roaming",
3434 DBUS_TYPE_BOOLEAN, &val);
3436 connman_dbus_dict_append_dict(dict, "Ethernet",
3437 append_ethernet, service);
3439 case CONNMAN_SERVICE_TYPE_WIFI:
3440 #if defined TIZEN_EXT
3441 if (service->network != NULL) {
3442 append_wifi_ext_info(dict, service->network);
3443 connman_dbus_dict_append_dict(dict, "BSSID.List",
3444 append_bssid_info, service->network);
3447 connman_dbus_dict_append_dict(dict, "Ethernet",
3448 append_ethernet, service);
3450 connman_dbus_dict_append_basic(dict, "DisconnectReason",
3451 DBUS_TYPE_INT32, &service->disconnect_reason);
3453 connman_dbus_dict_append_basic(dict, "AssocStatusCode",
3454 DBUS_TYPE_INT32, &service->assoc_status_code);
3458 case CONNMAN_SERVICE_TYPE_ETHERNET:
3459 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3460 case CONNMAN_SERVICE_TYPE_GADGET:
3461 connman_dbus_dict_append_dict(dict, "Ethernet",
3462 append_ethernet, service);
3466 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
3468 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
3469 append_ipv4config, service);
3471 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
3473 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
3474 append_ipv6config, service);
3476 connman_dbus_dict_append_array(dict, "Nameservers",
3477 DBUS_TYPE_STRING, append_dns, service);
3479 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
3480 DBUS_TYPE_STRING, append_dnsconfig, service);
3482 if (service->state == CONNMAN_SERVICE_STATE_READY ||
3483 service->state == CONNMAN_SERVICE_STATE_ONLINE)
3484 list = __connman_timeserver_get_all(service);
3488 connman_dbus_dict_append_array(dict, "Timeservers",
3489 DBUS_TYPE_STRING, append_ts, list);
3491 g_slist_free_full(list, g_free);
3493 connman_dbus_dict_append_array(dict, "Timeservers.Configuration",
3494 DBUS_TYPE_STRING, append_tsconfig, service);
3496 connman_dbus_dict_append_array(dict, "Domains",
3497 DBUS_TYPE_STRING, append_domain, service);
3499 connman_dbus_dict_append_array(dict, "Domains.Configuration",
3500 DBUS_TYPE_STRING, append_domainconfig, service);
3502 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
3504 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
3505 append_proxyconfig, service);
3507 connman_dbus_dict_append_dict(dict, "Provider",
3508 append_provider, service);
3511 static void append_struct_service(DBusMessageIter *iter,
3512 connman_dbus_append_cb_t function,
3513 struct connman_service *service)
3515 DBusMessageIter entry, dict;
3517 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
3519 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
3522 connman_dbus_dict_open(&entry, &dict);
3524 function(&dict, service);
3525 connman_dbus_dict_close(&entry, &dict);
3527 dbus_message_iter_close_container(iter, &entry);
3530 static void append_dict_properties(DBusMessageIter *dict, void *user_data)
3532 struct connman_service *service = user_data;
3534 append_properties(dict, TRUE, service);
3537 static void append_struct(gpointer value, gpointer user_data)
3539 struct connman_service *service = value;
3540 DBusMessageIter *iter = user_data;
3545 append_struct_service(iter, append_dict_properties, service);
3548 void __connman_service_list_struct(DBusMessageIter *iter)
3550 g_list_foreach(service_list, append_struct, iter);
3553 bool __connman_service_is_hidden(struct connman_service *service)
3555 return service->hidden;
3559 __connman_service_is_split_routing(struct connman_service *service)
3561 return service->do_split_routing;
3564 bool __connman_service_index_is_split_routing(int index)
3566 struct connman_service *service;
3571 service = __connman_service_lookup_from_index(index);
3575 return __connman_service_is_split_routing(service);
3578 int __connman_service_get_index(struct connman_service *service)
3583 if (service->network)
3584 return connman_network_get_index(service->network);
3585 else if (service->provider)
3586 return connman_provider_get_index(service->provider);
3591 void __connman_service_set_hidden(struct connman_service *service)
3593 if (!service || service->hidden)
3596 service->hidden_service = true;
3599 void __connman_service_set_hostname(struct connman_service *service,
3600 const char *hostname)
3602 if (!service || service->hidden)
3605 g_free(service->hostname);
3606 service->hostname = g_strdup(hostname);
3609 const char *__connman_service_get_hostname(struct connman_service *service)
3614 return service->hostname;
3617 void __connman_service_set_domainname(struct connman_service *service,
3618 const char *domainname)
3620 if (!service || service->hidden)
3623 g_free(service->domainname);
3624 service->domainname = g_strdup(domainname);
3626 domain_changed(service);
3629 const char *connman_service_get_domainname(struct connman_service *service)
3634 if (service->domains)
3635 return service->domains[0];
3637 return service->domainname;
3640 char **connman_service_get_nameservers(struct connman_service *service)
3645 if (service->nameservers_config)
3646 return g_strdupv(service->nameservers_config);
3647 else if (service->nameservers ||
3648 service->nameservers_auto) {
3649 int len = 0, len_auto = 0, i;
3652 if (service->nameservers)
3653 len = g_strv_length(service->nameservers);
3654 if (service->nameservers_auto)
3655 len_auto = g_strv_length(service->nameservers_auto);
3657 nameservers = g_try_new0(char *, len + len_auto + 1);
3661 for (i = 0; i < len; i++)
3662 nameservers[i] = g_strdup(service->nameservers[i]);
3664 for (i = 0; i < len_auto; i++)
3665 nameservers[i + len] =
3666 g_strdup(service->nameservers_auto[i]);
3671 return g_strdupv(connman_setting_get_string_list("FallbackNameservers"));
3674 char **connman_service_get_timeservers_config(struct connman_service *service)
3679 return service->timeservers_config;
3682 char **connman_service_get_timeservers(struct connman_service *service)
3687 return service->timeservers;
3690 #if defined TIZEN_EXT
3692 * Description: Telephony plug-in requires manual PROXY setting function
3694 int connman_service_set_proxy(struct connman_service *service,
3695 const char *proxy, gboolean active)
3697 char **proxies_array = NULL;
3699 if (service == NULL)
3702 switch (service->type) {
3703 case CONNMAN_SERVICE_TYPE_CELLULAR:
3704 case CONNMAN_SERVICE_TYPE_ETHERNET:
3705 case CONNMAN_SERVICE_TYPE_WIFI:
3712 g_strfreev(service->proxies);
3713 service->proxies = NULL;
3716 proxies_array = g_strsplit(proxy, " ", 0);
3718 service->proxies = proxies_array;
3720 if (proxy == NULL) {
3721 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
3722 DBG("proxy changed (%d)", active);
3724 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
3725 DBG("proxy chagned %s (%d)", proxy, active);
3728 if (active == TRUE) {
3729 proxy_changed(service);
3731 __connman_notifier_proxy_changed(service);
3738 void connman_service_set_proxy_method(struct connman_service *service,
3739 enum connman_service_proxy_method method)
3741 if (!service || service->hidden)
3744 service->proxy = method;
3746 proxy_changed(service);
3748 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
3749 __connman_notifier_proxy_changed(service);
3752 enum connman_service_proxy_method connman_service_get_proxy_method(
3753 struct connman_service *service)
3756 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
3758 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
3759 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
3761 return service->proxy;
3763 return service->proxy_config;
3766 return service->proxy;
3769 char **connman_service_get_proxy_servers(struct connman_service *service)
3771 return g_strdupv(service->proxies);
3774 char **connman_service_get_proxy_excludes(struct connman_service *service)
3776 return g_strdupv(service->excludes);
3779 const char *connman_service_get_proxy_url(struct connman_service *service)
3784 return service->pac;
3787 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
3790 if (!service || service->hidden)
3793 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
3795 if (service->ipconfig_ipv4) {
3796 if (__connman_ipconfig_set_proxy_autoconfig(
3797 service->ipconfig_ipv4, url) < 0)
3799 } else if (service->ipconfig_ipv6) {
3800 if (__connman_ipconfig_set_proxy_autoconfig(
3801 service->ipconfig_ipv6, url) < 0)
3806 proxy_changed(service);
3808 __connman_notifier_proxy_changed(service);
3811 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
3816 if (service->ipconfig_ipv4)
3817 return __connman_ipconfig_get_proxy_autoconfig(
3818 service->ipconfig_ipv4);
3819 else if (service->ipconfig_ipv6)
3820 return __connman_ipconfig_get_proxy_autoconfig(
3821 service->ipconfig_ipv6);
3825 #if defined TIZEN_EXT
3826 int connman_service_get_ipv6_dns_method(struct connman_service *service)
3829 DBG("Service is NULL");
3833 return service->dns_config_method_ipv6;
3837 void __connman_service_set_timeservers(struct connman_service *service,
3845 g_strfreev(service->timeservers);
3846 service->timeservers = NULL;
3848 for (i = 0; timeservers && timeservers[i]; i++)
3849 __connman_service_timeserver_append(service, timeservers[i]);
3852 int __connman_service_timeserver_append(struct connman_service *service,
3853 const char *timeserver)
3857 DBG("service %p timeserver %s", service, timeserver);
3862 if (service->timeservers) {
3865 for (i = 0; service->timeservers[i]; i++)
3866 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
3869 len = g_strv_length(service->timeservers);
3870 service->timeservers = g_try_renew(char *, service->timeservers,
3874 service->timeservers = g_try_new0(char *, len + 2);
3877 if (!service->timeservers)
3880 service->timeservers[len] = g_strdup(timeserver);
3881 service->timeservers[len + 1] = NULL;
3886 int __connman_service_timeserver_remove(struct connman_service *service,
3887 const char *timeserver)
3890 int len, i, j, found = 0;
3892 DBG("service %p timeserver %s", service, timeserver);
3897 if (!service->timeservers)
3900 for (i = 0; service->timeservers &&
3901 service->timeservers[i]; i++)
3902 if (g_strcmp0(service->timeservers[i], timeserver) == 0) {
3910 len = g_strv_length(service->timeservers);
3913 g_strfreev(service->timeservers);
3914 service->timeservers = NULL;
3919 servers = g_try_new0(char *, len);
3923 for (i = 0, j = 0; i < len; i++) {
3924 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
3925 servers[j] = g_strdup(service->timeservers[i]);
3931 servers[len - 1] = NULL;
3933 g_strfreev(service->timeservers);
3934 service->timeservers = servers;
3939 void __connman_service_timeserver_changed(struct connman_service *service,
3945 if (!allow_property_changed(service))
3948 connman_dbus_property_changed_array(service->path,
3949 CONNMAN_SERVICE_INTERFACE, "Timeservers",
3950 DBUS_TYPE_STRING, append_ts, ts_list);
3953 void __connman_service_set_pac(struct connman_service *service,
3956 if (service->hidden)
3958 g_free(service->pac);
3959 service->pac = g_strdup(pac);
3961 proxy_changed(service);
3964 #if defined TIZEN_EXT
3965 void __connman_service_set_proxy(struct connman_service *service,
3966 const char *proxies)
3968 char **proxies_array = NULL;
3970 g_strfreev(service->proxies);
3971 service->proxies = NULL;
3973 if (proxies != NULL)
3974 proxies_array = g_strsplit(proxies, " ", 0);
3976 service->proxies = proxies_array;
3980 void __connman_service_set_identity(struct connman_service *service,
3981 const char *identity)
3983 if (service->immutable || service->hidden)
3986 g_free(service->identity);
3987 service->identity = g_strdup(identity);
3989 if (service->network)
3990 connman_network_set_string(service->network,
3995 void __connman_service_set_anonymous_identity(struct connman_service *service,
3996 const char *anonymous_identity)
3998 if (service->immutable || service->hidden)
4001 g_free(service->anonymous_identity);
4002 service->anonymous_identity = g_strdup(anonymous_identity);
4004 if (service->network)
4005 connman_network_set_string(service->network,
4006 "WiFi.AnonymousIdentity",
4007 service->anonymous_identity);
4010 void __connman_service_set_subject_match(struct connman_service *service,
4011 const char *subject_match)
4013 if (service->immutable || service->hidden)
4016 g_free(service->subject_match);
4017 service->subject_match = g_strdup(subject_match);
4019 if (service->network)
4020 connman_network_set_string(service->network,
4021 "WiFi.SubjectMatch",
4022 service->subject_match);
4025 void __connman_service_set_altsubject_match(struct connman_service *service,
4026 const char *altsubject_match)
4028 if (service->immutable || service->hidden)
4031 g_free(service->altsubject_match);
4032 service->altsubject_match = g_strdup(altsubject_match);
4034 if (service->network)
4035 connman_network_set_string(service->network,
4036 "WiFi.AltSubjectMatch",
4037 service->altsubject_match);
4040 void __connman_service_set_domain_suffix_match(struct connman_service *service,
4041 const char *domain_suffix_match)
4043 if (service->immutable || service->hidden)
4046 g_free(service->domain_suffix_match);
4047 service->domain_suffix_match = g_strdup(domain_suffix_match);
4049 if (service->network)
4050 connman_network_set_string(service->network,
4051 "WiFi.DomainSuffixMatch",
4052 service->domain_suffix_match);
4055 void __connman_service_set_domain_match(struct connman_service *service,
4056 const char *domain_match)
4058 if (service->immutable || service->hidden)
4061 g_free(service->domain_match);
4062 service->domain_match = g_strdup(domain_match);
4064 if (service->network)
4065 connman_network_set_string(service->network,
4067 service->domain_match);
4070 void __connman_service_set_agent_identity(struct connman_service *service,
4071 const char *agent_identity)
4073 if (service->hidden)
4075 g_free(service->agent_identity);
4076 service->agent_identity = g_strdup(agent_identity);
4078 if (service->network)
4079 connman_network_set_string(service->network,
4080 "WiFi.AgentIdentity",
4081 service->agent_identity);
4084 int __connman_service_check_passphrase(enum connman_service_security security,
4085 const char *passphrase)
4093 length = strlen(passphrase);
4096 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
4097 case CONNMAN_SERVICE_SECURITY_NONE:
4098 case CONNMAN_SERVICE_SECURITY_WPA:
4099 #if !defined TIZEN_EXT
4100 case CONNMAN_SERVICE_SECURITY_RSN:
4103 DBG("service security '%s' (%d) not handled",
4104 security2string(security), security);
4108 case CONNMAN_SERVICE_SECURITY_PSK:
4109 #if defined TIZEN_EXT
4110 case CONNMAN_SERVICE_SECURITY_RSN:
4112 /* A raw key is always 64 bytes length,
4113 * its content is in hex representation.
4114 * A PSK key must be between [8..63].
4117 for (i = 0; i < 64; i++)
4118 if (!isxdigit((unsigned char)
4121 } else if (length < 8 || length > 63)
4124 case CONNMAN_SERVICE_SECURITY_WEP:
4125 /* length of WEP key is 10 or 26
4126 * length of WEP passphrase is 5 or 13
4128 if (length == 10 || length == 26) {
4129 for (i = 0; i < length; i++)
4130 if (!isxdigit((unsigned char)
4133 } else if (length != 5 && length != 13)
4137 case CONNMAN_SERVICE_SECURITY_8021X:
4144 int __connman_service_set_passphrase(struct connman_service *service,
4145 const char *passphrase)
4149 if (service->hidden)
4152 if (service->immutable &&
4153 service->security != CONNMAN_SERVICE_SECURITY_8021X)
4155 #if defined TIZEN_EXT
4156 /* The encrypted passphrase is used here
4157 * and validation is done by net-config before being encrypted.
4160 if (service->security != CONNMAN_SERVICE_SECURITY_PSK &&
4161 service->security != CONNMAN_SERVICE_SECURITY_RSN &&
4162 service->security != CONNMAN_SERVICE_SECURITY_WEP)
4164 err = __connman_service_check_passphrase(service->security, passphrase);
4169 g_free(service->passphrase);
4170 service->passphrase = g_strdup(passphrase);
4172 if (service->network)
4173 connman_network_set_string(service->network, "WiFi.Passphrase",
4174 service->passphrase);
4179 const char *__connman_service_get_passphrase(struct connman_service *service)
4184 return service->passphrase;
4187 static DBusMessage *get_properties(DBusConnection *conn,
4188 DBusMessage *msg, void *user_data)
4190 struct connman_service *service = user_data;
4192 DBusMessageIter array, dict;
4194 reply = dbus_message_new_method_return(msg);
4198 dbus_message_iter_init_append(reply, &array);
4200 connman_dbus_dict_open(&array, &dict);
4201 append_properties(&dict, FALSE, service);
4202 connman_dbus_dict_close(&array, &dict);
4207 static char **remove_empty_strings(char **strv)
4214 strv[index++] = *iter;
4224 static int update_proxy_configuration(struct connman_service *service,
4225 DBusMessageIter *array)
4227 DBusMessageIter dict;
4228 enum connman_service_proxy_method method;
4229 GString *servers_str = NULL;
4230 GString *excludes_str = NULL;
4231 const char *url = NULL;
4233 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
4235 dbus_message_iter_recurse(array, &dict);
4237 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
4238 DBusMessageIter entry, variant;
4242 dbus_message_iter_recurse(&dict, &entry);
4244 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
4247 dbus_message_iter_get_basic(&entry, &key);
4248 dbus_message_iter_next(&entry);
4250 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
4253 dbus_message_iter_recurse(&entry, &variant);
4255 type = dbus_message_iter_get_arg_type(&variant);
4257 if (g_str_equal(key, "Method")) {
4260 if (type != DBUS_TYPE_STRING)
4263 dbus_message_iter_get_basic(&variant, &val);
4264 method = string2proxymethod(val);
4265 } else if (g_str_equal(key, "URL")) {
4266 if (type != DBUS_TYPE_STRING)
4269 dbus_message_iter_get_basic(&variant, &url);
4270 } else if (g_str_equal(key, "Servers")) {
4271 DBusMessageIter str_array;
4273 if (type != DBUS_TYPE_ARRAY)
4276 servers_str = g_string_new(NULL);
4280 dbus_message_iter_recurse(&variant, &str_array);
4282 while (dbus_message_iter_get_arg_type(&str_array) ==
4286 dbus_message_iter_get_basic(&str_array, &val);
4288 if (servers_str->len > 0)
4289 g_string_append_printf(servers_str,
4292 g_string_append(servers_str, val);
4294 dbus_message_iter_next(&str_array);
4296 } else if (g_str_equal(key, "Excludes")) {
4297 DBusMessageIter str_array;
4299 if (type != DBUS_TYPE_ARRAY)
4302 excludes_str = g_string_new(NULL);
4306 dbus_message_iter_recurse(&variant, &str_array);
4308 while (dbus_message_iter_get_arg_type(&str_array) ==
4312 dbus_message_iter_get_basic(&str_array, &val);
4314 if (excludes_str->len > 0)
4315 g_string_append_printf(excludes_str,
4318 g_string_append(excludes_str, val);
4320 dbus_message_iter_next(&str_array);
4324 dbus_message_iter_next(&dict);
4328 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
4330 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
4331 if (!servers_str && !service->proxies)
4335 g_strfreev(service->proxies);
4337 if (servers_str->len > 0) {
4338 char **proxies = g_strsplit_set(
4339 servers_str->str, " ", 0);
4340 proxies = remove_empty_strings(proxies);
4341 service->proxies = proxies;
4343 service->proxies = NULL;
4347 g_strfreev(service->excludes);
4349 if (excludes_str->len > 0) {
4350 char **excludes = g_strsplit_set(
4351 excludes_str->str, " ", 0);
4352 excludes = remove_empty_strings(excludes);
4353 service->excludes = excludes;
4355 service->excludes = NULL;
4358 if (!service->proxies)
4359 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
4362 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
4363 g_free(service->pac);
4365 if (url && strlen(url) > 0)
4366 service->pac = g_strstrip(g_strdup(url));
4368 service->pac = NULL;
4370 /* if we are connected:
4371 - if service->pac == NULL
4372 - if __connman_ipconfig_get_proxy_autoconfig(
4373 service->ipconfig) == NULL
4374 --> We should start WPAD */
4377 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
4382 g_string_free(servers_str, TRUE);
4385 g_string_free(excludes_str, TRUE);
4387 service->proxy_config = method;
4393 g_string_free(servers_str, TRUE);
4396 g_string_free(excludes_str, TRUE);
4401 int __connman_service_reset_ipconfig(struct connman_service *service,
4402 enum connman_ipconfig_type type, DBusMessageIter *array,
4403 enum connman_service_state *new_state)
4405 struct connman_ipconfig *ipconfig, *new_ipconfig;
4406 enum connman_ipconfig_method old_method, new_method;
4407 enum connman_service_state state;
4410 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4411 ipconfig = service->ipconfig_ipv4;
4412 state = service->state_ipv4;
4413 new_method = CONNMAN_IPCONFIG_METHOD_DHCP;
4414 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4415 ipconfig = service->ipconfig_ipv6;
4416 state = service->state_ipv6;
4417 new_method = CONNMAN_IPCONFIG_METHOD_AUTO;
4424 old_method = __connman_ipconfig_get_method(ipconfig);
4425 index = __connman_ipconfig_get_index(ipconfig);
4427 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4428 new_ipconfig = create_ip4config(service, index,
4429 CONNMAN_IPCONFIG_METHOD_UNKNOWN);
4431 new_ipconfig = create_ip6config(service, index);
4434 err = __connman_ipconfig_set_config(new_ipconfig, array);
4436 __connman_ipconfig_unref(new_ipconfig);
4440 new_method = __connman_ipconfig_get_method(new_ipconfig);
4443 if (is_connecting(state) || is_connected(state))
4444 __connman_network_clear_ipconfig(service->network, ipconfig);
4446 __connman_ipconfig_unref(ipconfig);
4448 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4449 service->ipconfig_ipv4 = new_ipconfig;
4450 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4451 service->ipconfig_ipv6 = new_ipconfig;
4453 if (is_connecting(state) || is_connected(state))
4454 __connman_ipconfig_enable(new_ipconfig);
4456 if (new_state && new_method != old_method) {
4457 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4458 *new_state = service->state_ipv4;
4460 *new_state = service->state_ipv6;
4462 settings_changed(service, new_ipconfig);
4463 address_updated(service, new_method);
4465 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4468 DBG("err %d ipconfig %p type %d method %d state %s", err,
4469 new_ipconfig, type, new_method,
4470 !new_state ? "-" : state2string(*new_state));
4475 static DBusMessage *set_property(DBusConnection *conn,
4476 DBusMessage *msg, void *user_data)
4478 struct connman_service *service = user_data;
4479 DBusMessageIter iter, value;
4483 DBG("service %p", service);
4485 if (!dbus_message_iter_init(msg, &iter))
4486 return __connman_error_invalid_arguments(msg);
4488 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
4489 return __connman_error_invalid_arguments(msg);
4491 if (service->type == CONNMAN_SERVICE_TYPE_WIFI && is_connected(service->state)) {
4493 if (connman_dbus_get_connection_unix_user_sync(conn,
4494 dbus_message_get_sender(msg),
4496 DBG("Can not get unix user id!");
4497 return __connman_error_permission_denied(msg);
4500 if (!connman_service_is_user_allowed(service, uid)) {
4501 DBG("Not allow this user to operate this wifi service now!");
4502 return __connman_error_permission_denied(msg);
4506 dbus_message_iter_get_basic(&iter, &name);
4507 dbus_message_iter_next(&iter);
4509 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
4510 return __connman_error_invalid_arguments(msg);
4512 dbus_message_iter_recurse(&iter, &value);
4514 type = dbus_message_iter_get_arg_type(&value);
4516 if (g_str_equal(name, "AutoConnect")) {
4517 dbus_bool_t autoconnect;
4519 if (type != DBUS_TYPE_BOOLEAN)
4520 return __connman_error_invalid_arguments(msg);
4522 if (!service->favorite)
4523 return __connman_error_invalid_service(msg);
4525 dbus_message_iter_get_basic(&value, &autoconnect);
4527 if (service->autoconnect == autoconnect)
4528 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4530 service->autoconnect = autoconnect;
4532 autoconnect_changed(service);
4535 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4537 service_save(service);
4538 } else if (g_str_equal(name, "Nameservers.Configuration")) {
4539 DBusMessageIter entry;
4543 #if defined TIZEN_EXT
4544 enum connman_ipconfig_type ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4548 if (__connman_provider_is_immutable(service->provider) ||
4550 return __connman_error_not_supported(msg);
4552 if (type != DBUS_TYPE_ARRAY)
4553 return __connman_error_invalid_arguments(msg);
4555 str = g_string_new(NULL);
4557 return __connman_error_invalid_arguments(msg);
4559 index = __connman_service_get_index(service);
4560 gw = __connman_ipconfig_get_gateway_from_index(index,
4561 CONNMAN_IPCONFIG_TYPE_ALL);
4563 #if !defined TIZEN_EXT
4564 if (gw && strlen(gw))
4565 __connman_service_nameserver_del_routes(service,
4566 CONNMAN_IPCONFIG_TYPE_ALL);
4568 dbus_message_iter_recurse(&value, &entry);
4570 #if defined TIZEN_EXT
4571 /* IPv4/IPv6 Last DNS config method */
4572 int last_dns_ipv4 = service->dns_config_method_ipv4;
4573 int last_dns_ipv6 = service->dns_config_method_ipv6;
4574 DBG("Last DNS Config Method IPv4: %d IPv6: %d", last_dns_ipv4, last_dns_ipv6);
4577 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4579 dbus_message_iter_get_basic(&entry, &val);
4580 dbus_message_iter_next(&entry);
4582 /* First unpack the DNS Config Method */
4583 DBG("DNS Config Method: %s", val);
4584 if((g_strcmp0(val, "ipv4.manual") == 0)) {
4585 service->dns_config_method_ipv4 =
4586 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4588 if(last_dns_ipv4 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4589 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4590 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4592 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4595 } else if(g_strcmp0(val, "ipv4.dhcp") == 0) {
4596 service->dns_config_method_ipv4 =
4597 CONNMAN_DNSCONFIG_METHOD_DHCP;
4598 if(last_dns_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4599 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4602 } else if(g_strcmp0(val, "ipv6.manual") == 0) {
4603 service->dns_config_method_ipv6 =
4604 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4605 if(last_dns_ipv6 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4606 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4607 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4609 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4612 } else if(g_strcmp0(val, "ipv6.dhcp") == 0) {
4613 service->dns_config_method_ipv6 =
4614 CONNMAN_DNSCONFIG_METHOD_DHCP;
4615 if(last_dns_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4616 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4625 g_string_append_printf(str, " %s", val);
4627 g_string_append(str, val);
4630 #if defined TIZEN_EXT
4631 if (service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_DHCP &&
4632 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_DHCP) {
4633 DBG("Both IPv4 and IPv6 DNS Method DHCP");
4634 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4636 if (gw && strlen(gw))
4637 __connman_service_nameserver_del_routes(service,
4640 DBG("%s ip_type: %d nameserver remove all", name, ip_type);
4641 nameserver_remove_all(service, ip_type);
4643 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
4645 g_strfreev(service->nameservers_config);
4648 char **nameservers, **iter;
4650 nameservers = g_strsplit_set(str->str, " ", 0);
4652 for (iter = nameservers; *iter; iter++)
4653 if (connman_inet_check_ipaddress(*iter) <= 0)
4656 nameservers = remove_empty_strings(nameservers);
4657 service->nameservers_config = nameservers;
4659 service->nameservers_config = NULL;
4662 g_string_free(str, TRUE);
4664 if (gw && strlen(gw))
4665 __connman_service_nameserver_add_routes(service, gw);
4667 #if defined TIZEN_EXT
4668 DBG("%s ip_type: %d nameserver add all", name, ip_type);
4669 nameserver_add_all(service, ip_type);
4671 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
4673 dns_configuration_changed(service);
4675 if (__connman_service_is_connected_state(service,
4676 CONNMAN_IPCONFIG_TYPE_IPV4))
4677 __connman_wispr_start(service,
4678 CONNMAN_IPCONFIG_TYPE_IPV4);
4680 if (__connman_service_is_connected_state(service,
4681 CONNMAN_IPCONFIG_TYPE_IPV6))
4682 __connman_wispr_start(service,
4683 CONNMAN_IPCONFIG_TYPE_IPV6);
4685 service_save(service);
4686 } else if (g_str_equal(name, "Timeservers.Configuration")) {
4687 DBusMessageIter entry;
4690 if (service->immutable)
4691 return __connman_error_not_supported(msg);
4693 if (type != DBUS_TYPE_ARRAY)
4694 return __connman_error_invalid_arguments(msg);
4696 str = g_string_new(NULL);
4698 return __connman_error_invalid_arguments(msg);
4700 dbus_message_iter_recurse(&value, &entry);
4702 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4704 dbus_message_iter_get_basic(&entry, &val);
4705 dbus_message_iter_next(&entry);
4711 g_string_append_printf(str, " %s", val);
4713 g_string_append(str, val);
4716 g_strfreev(service->timeservers_config);
4717 service->timeservers_config = NULL;
4720 char **timeservers = g_strsplit_set(str->str, " ", 0);
4721 timeservers = remove_empty_strings(timeservers);
4722 service->timeservers_config = timeservers;
4724 service->timeservers = NULL;
4726 g_string_free(str, TRUE);
4728 service_save(service);
4729 timeservers_configuration_changed(service);
4731 if (service == __connman_service_get_default())
4732 __connman_timeserver_sync(service);
4734 } else if (g_str_equal(name, "Domains.Configuration")) {
4735 DBusMessageIter entry;
4738 if (service->immutable)
4739 return __connman_error_not_supported(msg);
4741 if (type != DBUS_TYPE_ARRAY)
4742 return __connman_error_invalid_arguments(msg);
4744 str = g_string_new(NULL);
4746 return __connman_error_invalid_arguments(msg);
4748 dbus_message_iter_recurse(&value, &entry);
4750 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4752 dbus_message_iter_get_basic(&entry, &val);
4753 dbus_message_iter_next(&entry);
4759 g_string_append_printf(str, " %s", val);
4761 g_string_append(str, val);
4764 searchdomain_remove_all(service);
4765 g_strfreev(service->domains);
4768 char **domains = g_strsplit_set(str->str, " ", 0);
4769 domains = remove_empty_strings(domains);
4770 service->domains = domains;
4772 service->domains = NULL;
4774 g_string_free(str, TRUE);
4776 searchdomain_add_all(service);
4777 domain_configuration_changed(service);
4778 domain_changed(service);
4780 service_save(service);
4781 } else if (g_str_equal(name, "Proxy.Configuration")) {
4784 if (service->immutable)
4785 return __connman_error_not_supported(msg);
4787 if (type != DBUS_TYPE_ARRAY)
4788 return __connman_error_invalid_arguments(msg);
4790 err = update_proxy_configuration(service, &value);
4793 return __connman_error_failed(msg, -err);
4795 proxy_configuration_changed(service);
4797 __connman_notifier_proxy_changed(service);
4799 service_save(service);
4800 } else if (g_str_equal(name, "IPv4.Configuration") ||
4801 g_str_equal(name, "IPv6.Configuration")) {
4803 enum connman_service_state state =
4804 CONNMAN_SERVICE_STATE_UNKNOWN;
4805 enum connman_ipconfig_type type =
4806 CONNMAN_IPCONFIG_TYPE_UNKNOWN;
4809 if (service->type == CONNMAN_SERVICE_TYPE_VPN ||
4811 return __connman_error_not_supported(msg);
4815 if (!service->ipconfig_ipv4 &&
4816 !service->ipconfig_ipv6)
4817 return __connman_error_invalid_property(msg);
4819 if (g_str_equal(name, "IPv4.Configuration"))
4820 type = CONNMAN_IPCONFIG_TYPE_IPV4;
4822 type = CONNMAN_IPCONFIG_TYPE_IPV6;
4824 err = __connman_service_reset_ipconfig(service, type, &value,
4828 if (is_connected(state) || is_connecting(state)) {
4829 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4830 __connman_network_enable_ipconfig(service->network,
4831 service->ipconfig_ipv4);
4833 __connman_network_enable_ipconfig(service->network,
4834 service->ipconfig_ipv6);
4837 return __connman_error_failed(msg, -err);
4840 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4841 ipv4_configuration_changed(service);
4843 ipv6_configuration_changed(service);
4845 if (is_connecting(service->state) ||
4846 is_connected(service->state)) {
4847 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4848 __connman_network_enable_ipconfig(service->network,
4849 service->ipconfig_ipv4);
4851 __connman_network_enable_ipconfig(service->network,
4852 service->ipconfig_ipv6);
4855 service_save(service);
4856 #if defined TIZEN_EXT
4857 /* When AP is connected using WPS without SSID then its password needs
4858 * to be saved for autoconnection */
4859 } else if (g_str_equal(name, "Passphrase")) {
4862 if (type != DBUS_TYPE_STRING)
4863 return __connman_error_invalid_arguments(msg);
4865 dbus_message_iter_get_basic(&value, &passphrase);
4867 __connman_service_set_passphrase(service, passphrase);
4870 return __connman_error_invalid_property(msg);
4872 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4875 static void set_error(struct connman_service *service,
4876 enum connman_service_error error)
4880 if (service->error == error)
4883 service->error = error;
4888 #if !defined TIZEN_EXT
4889 if (!allow_property_changed(service))
4893 str = error2string(service->error);
4898 connman_dbus_property_changed_basic(service->path,
4899 CONNMAN_SERVICE_INTERFACE, "Error",
4900 DBUS_TYPE_STRING, &str);
4903 static void remove_timeout(struct connman_service *service)
4905 if (service->timeout > 0) {
4906 g_source_remove(service->timeout);
4907 service->timeout = 0;
4911 static void reply_pending(struct connman_service *service, int error)
4913 remove_timeout(service);
4915 if (service->pending) {
4916 connman_dbus_reply_pending(service->pending, error, NULL);
4917 service->pending = NULL;
4920 if (service->provider_pending) {
4921 connman_dbus_reply_pending(service->provider_pending,
4922 error, service->path);
4923 service->provider_pending = NULL;
4927 static void service_complete(struct connman_service *service)
4929 reply_pending(service, EIO);
4931 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
4932 __connman_service_auto_connect(service->connect_reason);
4934 g_get_current_time(&service->modified);
4935 service_save(service);
4938 static void set_idle(struct connman_service *service)
4940 service->state = service->state_ipv4 = service->state_ipv6 =
4941 CONNMAN_SERVICE_STATE_IDLE;
4942 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4943 state_changed(service);
4946 static DBusMessage *clear_property(DBusConnection *conn,
4947 DBusMessage *msg, void *user_data)
4949 struct connman_service *service = user_data;
4952 DBG("service %p", service);
4954 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
4957 if (g_str_equal(name, "Error")) {
4958 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4960 __connman_service_clear_error(service);
4961 service_complete(service);
4963 return __connman_error_invalid_property(msg);
4965 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4968 static bool is_ipconfig_usable(struct connman_service *service)
4970 if (!__connman_ipconfig_is_usable(service->ipconfig_ipv4) &&
4971 !__connman_ipconfig_is_usable(service->ipconfig_ipv6))
4977 static bool is_ignore(struct connman_service *service)
4979 if (!service->autoconnect)
4982 if (service->roaming)
4985 if (service->ignore)
4988 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
4991 if (!is_ipconfig_usable(service))
4997 static void disconnect_on_last_session(enum connman_service_type type)
5001 for (list = service_list; list; list = list->next) {
5002 struct connman_service *service = list->data;
5004 if (service->type != type)
5007 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_SESSION)
5010 __connman_service_disconnect(service);
5015 static int active_sessions[MAX_CONNMAN_SERVICE_TYPES] = {};
5016 static int always_connect[MAX_CONNMAN_SERVICE_TYPES] = {};
5017 static int active_count = 0;
5019 void __connman_service_set_active_session(bool enable, GSList *list)
5030 enum connman_service_type type = GPOINTER_TO_INT(list->data);
5033 case CONNMAN_SERVICE_TYPE_ETHERNET:
5034 case CONNMAN_SERVICE_TYPE_WIFI:
5035 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
5036 case CONNMAN_SERVICE_TYPE_CELLULAR:
5037 case CONNMAN_SERVICE_TYPE_GADGET:
5039 active_sessions[type]++;
5041 active_sessions[type]--;
5044 case CONNMAN_SERVICE_TYPE_UNKNOWN:
5045 case CONNMAN_SERVICE_TYPE_SYSTEM:
5046 case CONNMAN_SERVICE_TYPE_GPS:
5047 case CONNMAN_SERVICE_TYPE_VPN:
5048 case CONNMAN_SERVICE_TYPE_P2P:
5052 if (active_sessions[type] == 0)
5053 disconnect_on_last_session(type);
5055 list = g_slist_next(list);
5058 DBG("eth %d wifi %d bt %d cellular %d gadget %d sessions %d",
5059 active_sessions[CONNMAN_SERVICE_TYPE_ETHERNET],
5060 active_sessions[CONNMAN_SERVICE_TYPE_WIFI],
5061 active_sessions[CONNMAN_SERVICE_TYPE_BLUETOOTH],
5062 active_sessions[CONNMAN_SERVICE_TYPE_CELLULAR],
5063 active_sessions[CONNMAN_SERVICE_TYPE_GADGET],
5067 struct preferred_tech_data {
5068 GList *preferred_list;
5069 enum connman_service_type type;
5072 static void preferred_tech_add_by_type(gpointer data, gpointer user_data)
5074 struct connman_service *service = data;
5075 struct preferred_tech_data *tech_data = user_data;
5077 if (service->type == tech_data->type) {
5078 tech_data->preferred_list =
5079 g_list_append(tech_data->preferred_list, service);
5081 DBG("type %d service %p %s", tech_data->type, service,
5086 static GList *preferred_tech_list_get(void)
5088 unsigned int *tech_array;
5089 struct preferred_tech_data tech_data = { 0, };
5092 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
5096 if (connman_setting_get_bool("SingleConnectedTechnology")) {
5098 for (list = service_list; list; list = list->next) {
5099 struct connman_service *service = list->data;
5101 if (!is_connected(service->state))
5104 if (service->connect_reason ==
5105 CONNMAN_SERVICE_CONNECT_REASON_USER) {
5106 DBG("service %p name %s is user connected",
5107 service, service->name);
5108 #if defined TIZEN_EXT
5109 /* We can connect to a favorite service like
5110 * wifi even we have a userconnect for cellular
5111 * because we have refount for cellular service
5113 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5116 if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
5124 for (i = 0; tech_array[i] != 0; i += 1) {
5125 tech_data.type = tech_array[i];
5126 g_list_foreach(service_list, preferred_tech_add_by_type,
5130 return tech_data.preferred_list;
5133 static void set_always_connecting_technologies()
5135 unsigned int *always_connected_techs =
5136 connman_setting_get_uint_list("AlwaysConnectedTechnologies");
5138 for (i = 0; always_connected_techs && always_connected_techs[i]; i++)
5139 always_connect[always_connected_techs[i]] = 1;
5142 static bool autoconnect_no_session_active(struct connman_service *service)
5145 * Test active_count to see if there are no sessions set up and
5146 * stop autoconnecting, but continue connecting if the service
5147 * belongs to a technology which should always autoconnect.
5149 if (!active_count && !always_connect[service->type])
5155 static bool autoconnect_already_connecting(struct connman_service *service,
5156 bool autoconnecting)
5159 * If another service is already connecting and this service type has
5160 * not been marked as always connecting, stop the connecting procedure.
5162 if (autoconnecting &&
5163 !active_sessions[service->type] &&
5164 !always_connect[service->type])
5170 static bool auto_connect_service(GList *services,
5171 enum connman_service_connect_reason reason,
5174 struct connman_service *service = NULL;
5175 bool ignore[MAX_CONNMAN_SERVICE_TYPES] = { };
5176 bool autoconnecting = false;
5179 DBG("preferred %d sessions %d reason %s", preferred, active_count,
5180 reason2string(reason));
5182 ignore[CONNMAN_SERVICE_TYPE_VPN] = true;
5184 for (list = services; list; list = list->next) {
5185 service = list->data;
5187 if (ignore[service->type]) {
5188 DBG("service %p type %s ignore", service,
5189 __connman_service_type2string(service->type));
5193 #if defined TIZEN_EXT
5194 DBG("service %p %s %s %s, favorite(%d), ignore(%d), hidden(%d, %d)",
5195 service, service->name,
5196 state2string(service->state),
5197 __connman_service_type2string(service->type),
5198 service->favorite, is_ignore(service),
5199 service->hidden, service->hidden_service);
5201 /* Tizen takes Wi-Fi as the highest priority into consideration. */
5202 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
5203 if (is_connecting(service->state) == TRUE || is_connected(service->state) == TRUE)
5207 if (service->pending ||
5208 is_connecting(service->state) ||
5209 is_connected(service->state)) {
5210 if (autoconnect_no_session_active(service))
5213 ignore[service->type] = true;
5214 autoconnecting = true;
5216 DBG("service %p type %s busy", service,
5217 __connman_service_type2string(service->type));
5222 if (!service->favorite) {
5226 #if defined TIZEN_EXT
5227 DBG("Service is not favorite, autoconnecting %d",
5230 return autoconnecting;
5233 #if defined TIZEN_EXT
5234 DBG("service %p identifier %s roaming %d ignore %d "
5235 "ipconfig_usable %d autoconnect %d state %d",
5237 service->identifier, service->roaming,
5238 service->ignore, is_ipconfig_usable(service),
5239 service->autoconnect, service->state);
5241 if (is_ignore(service) || service->state !=
5242 CONNMAN_SERVICE_STATE_IDLE)
5245 if (autoconnect_already_connecting(service, autoconnecting)) {
5246 DBG("service %p type %s has no users", service,
5247 __connman_service_type2string(service->type));
5251 if (!is_service_owner_user_login(service)) {
5252 DBG("favorite user not login, wifi auto connect denied");
5256 DBG("service %p %s %s", service, service->name,
5257 (preferred) ? "preferred" : reason2string(reason));
5259 __connman_service_connect(service, reason);
5261 if (autoconnect_no_session_active(service))
5264 ignore[service->type] = true;
5267 return autoconnecting;
5270 static gboolean run_auto_connect(gpointer data)
5272 enum connman_service_connect_reason reason = GPOINTER_TO_UINT(data);
5273 bool autoconnecting = false;
5274 GList *preferred_tech;
5276 autoconnect_timeout = 0;
5280 preferred_tech = preferred_tech_list_get();
5281 if (preferred_tech) {
5282 autoconnecting = auto_connect_service(preferred_tech, reason,
5284 g_list_free(preferred_tech);
5287 if (!autoconnecting || active_count)
5288 auto_connect_service(service_list, reason, false);
5293 #if defined TIZEN_EXT
5294 bool __connman_service_get_auto_connect_mode(void)
5296 return auto_connect_mode;
5299 void __connman_service_set_auto_connect_mode(bool enable)
5301 DBG("set auto_connect_mode = %d", enable);
5303 if (auto_connect_mode != enable)
5304 auto_connect_mode = enable;
5308 void __connman_service_auto_connect(enum connman_service_connect_reason reason)
5312 if (autoconnect_timeout != 0)
5315 #if defined TIZEN_EXT
5316 if (auto_connect_mode == FALSE) {
5317 DBG("Currently, not auto connection mode");
5322 if (!__connman_session_policy_autoconnect(reason))
5325 #if defined TIZEN_EXT
5326 /* Adding Timeout of 500ms before trying to auto connect.
5327 * This is done because of below scenario
5328 * 1. Device is connected to AP1
5329 * 2. WPS Connection request is initiated for AP2
5330 * 3. Immediately WPS Connection is Cancelled
5331 * When WPS Connection Connection is initiated for AP2 then
5332 * sometimes there is a scenario where connman gets in ASSOCIATED
5333 * state with AP1 due to autoconnect and subsequently the connection
5334 * initiated by AP1 fails and connman service for AP1 comes in
5335 * FAILURE state due to this when connection with AP2 is cancelled
5336 * then autoconnect with AP1 doesn't works because its autoconnection
5337 * is ignored as its last state was FAILURE rather than IDLE */
5338 autoconnect_timeout = g_timeout_add(500, run_auto_connect,
5340 autoconnect_timeout = g_idle_add(run_auto_connect,
5342 GUINT_TO_POINTER(reason));
5345 static gboolean run_vpn_auto_connect(gpointer data) {
5347 bool need_split = false;
5349 vpn_autoconnect_timeout = 0;
5351 for (list = service_list; list; list = list->next) {
5352 struct connman_service *service = list->data;
5355 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
5358 if (is_connected(service->state) ||
5359 is_connecting(service->state)) {
5360 if (!service->do_split_routing)
5365 if (is_ignore(service) || !service->favorite)
5368 if (need_split && !service->do_split_routing) {
5369 DBG("service %p no split routing", service);
5373 DBG("service %p %s %s", service, service->name,
5374 service->do_split_routing ?
5375 "split routing" : "");
5377 res = __connman_service_connect(service,
5378 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5379 if (res < 0 && res != -EINPROGRESS)
5382 if (!service->do_split_routing)
5389 static void vpn_auto_connect(void)
5391 if (vpn_autoconnect_timeout)
5394 vpn_autoconnect_timeout =
5395 g_idle_add(run_vpn_auto_connect, NULL);
5399 __connman_service_is_provider_pending(struct connman_service *service)
5404 if (service->provider_pending)
5410 void __connman_service_set_provider_pending(struct connman_service *service,
5413 if (service->provider_pending) {
5414 DBG("service %p provider pending msg %p already exists",
5415 service, service->provider_pending);
5419 service->provider_pending = msg;
5423 static void check_pending_msg(struct connman_service *service)
5425 if (!service->pending)
5428 DBG("service %p pending msg %p already exists", service,
5430 dbus_message_unref(service->pending);
5433 void __connman_service_set_hidden_data(struct connman_service *service,
5436 DBusMessage *pending = user_data;
5438 DBG("service %p pending %p", service, pending);
5443 check_pending_msg(service);
5445 service->pending = pending;
5448 void __connman_service_return_error(struct connman_service *service,
5449 int error, gpointer user_data)
5451 DBG("service %p error %d user_data %p", service, error, user_data);
5453 __connman_service_set_hidden_data(service, user_data);
5455 reply_pending(service, error);
5458 static gboolean connect_timeout(gpointer user_data)
5460 struct connman_service *service = user_data;
5461 bool autoconnect = false;
5463 DBG("service %p", service);
5465 service->timeout = 0;
5467 if (service->network)
5468 __connman_network_disconnect(service->network);
5469 else if (service->provider)
5470 connman_provider_disconnect(service->provider);
5472 __connman_stats_service_unregister(service);
5474 if (service->pending) {
5477 reply = __connman_error_operation_timeout(service->pending);
5479 g_dbus_send_message(connection, reply);
5481 dbus_message_unref(service->pending);
5482 service->pending = NULL;
5486 __connman_service_ipconfig_indicate_state(service,
5487 CONNMAN_SERVICE_STATE_FAILURE,
5488 CONNMAN_IPCONFIG_TYPE_IPV4);
5489 __connman_service_ipconfig_indicate_state(service,
5490 CONNMAN_SERVICE_STATE_FAILURE,
5491 CONNMAN_IPCONFIG_TYPE_IPV6);
5494 service->connect_reason !=
5495 CONNMAN_SERVICE_CONNECT_REASON_USER)
5496 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5501 static DBusMessage *connect_service(DBusConnection *conn,
5502 DBusMessage *msg, void *user_data)
5504 struct connman_service *service = user_data;
5505 #if defined TIZEN_EXT
5512 DBG("service %p", service);
5514 #if defined TIZEN_EXT
5516 * Description: TIZEN implements system global connection management.
5518 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5519 connman_service_user_pdn_connection_ref(service);
5521 /*Reset the Disconnect Reason while issue connect request*/
5522 service->disconnect_reason = 0;
5524 /*Reset the association status code while issue connect request*/
5525 service->assoc_status_code = 0;
5528 if (service->pending)
5529 return __connman_error_in_progress(msg);
5531 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5533 if (connman_dbus_get_connection_unix_user_sync(conn,
5534 dbus_message_get_sender(msg),
5536 DBG("Can not get unix user id!");
5537 return __connman_error_permission_denied(msg);
5540 if (!__connman_service_is_user_allowed(CONNMAN_SERVICE_TYPE_WIFI, uid)) {
5541 DBG("Not allow this user to connect this wifi service now!");
5542 return __connman_error_permission_denied(msg);
5545 if (uid != USER_ROOT && uid != service->user.favorite_user)
5546 service->request_passphrase_input = true;
5548 service->user.current_user = uid;
5550 if (!service->passphrase && uid == service->user.favorite_user) {
5551 DBG("Now load this favorite user's passphrase.");
5552 service_load_passphrase(service);
5556 #if !defined TIZEN_EXT
5557 index = __connman_service_get_index(service);
5559 for (list = service_list; list; list = list->next) {
5560 struct connman_service *temp = list->data;
5562 #if defined TIZEN_EXT
5563 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5566 if (!is_connecting(temp->state) && !is_connected(temp->state))
5569 if (service == temp)
5572 if (service->type != temp->type)
5575 if (__connman_service_get_index(temp) == index &&
5576 __connman_service_disconnect(temp) == -EINPROGRESS)
5580 if (err == -EINPROGRESS)
5581 return __connman_error_operation_timeout(msg);
5584 service->ignore = false;
5586 service->pending = dbus_message_ref(msg);
5588 err = __connman_service_connect(service,
5589 CONNMAN_SERVICE_CONNECT_REASON_USER);
5591 if (err == -EINPROGRESS)
5594 if (service->pending) {
5595 dbus_message_unref(service->pending);
5596 service->pending = NULL;
5600 return __connman_error_failed(msg, -err);
5602 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5605 static DBusMessage *disconnect_service(DBusConnection *conn,
5606 DBusMessage *msg, void *user_data)
5608 struct connman_service *service = user_data;
5611 DBG("service %p", service);
5613 #if defined TIZEN_EXT
5615 * Description: TIZEN implements system global connection management.
5617 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
5618 if (connman_service_user_pdn_connection_unref_and_test(service) != TRUE)
5619 return __connman_error_failed(msg, EISCONN);
5621 if (is_connected(service->state) == TRUE &&
5622 service == connman_service_get_default_connection())
5623 return __connman_error_failed(msg, EISCONN);
5627 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5629 if (connman_dbus_get_connection_unix_user_sync(conn,
5630 dbus_message_get_sender(msg),
5632 DBG("Can not get unix user id!");
5633 return __connman_error_permission_denied(msg);
5636 if (!connman_service_is_user_allowed(service, uid)) {
5637 DBG("Not allow this user to disconnect this wifi service now!");
5638 return __connman_error_permission_denied(msg);
5642 service->ignore = true;
5644 err = __connman_service_disconnect(service);
5645 if (err < 0 && err != -EINPROGRESS)
5646 return __connman_error_failed(msg, -err);
5648 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5651 #if defined TIZEN_EXT
5652 static void __connman_service_cleanup_network_8021x(struct connman_service *service)
5654 if (service == NULL)
5657 DBG("service %p ", service);
5659 connman_network_set_string(service->network, "WiFi.EAP", NULL);
5660 connman_network_set_string(service->network, "WiFi.Identity", NULL);
5661 connman_network_set_string(service->network, "WiFi.CACertFile", NULL);
5662 connman_network_set_string(service->network, "WiFi.ClientCertFile", NULL);
5663 connman_network_set_string(service->network, "WiFi.PrivateKeyFile", NULL);
5664 connman_network_set_string(service->network, "WiFi.PrivateKeyPassphrase", NULL);
5665 connman_network_set_string(service->network, "WiFi.Phase2", NULL);
5666 connman_network_set_string(service->network, "WiFi.AnonymousIdentity", NULL);
5670 bool __connman_service_remove(struct connman_service *service)
5672 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET ||
5673 service->type == CONNMAN_SERVICE_TYPE_GADGET)
5676 if (service->immutable || service->hidden ||
5677 __connman_provider_is_immutable(service->provider))
5680 #if !defined TIZEN_EXT
5681 if (!service->favorite && !is_idle(service->state))
5685 __connman_service_disconnect(service);
5687 g_free(service->passphrase);
5688 service->passphrase = NULL;
5690 g_free(service->identity);
5691 service->identity = NULL;
5693 g_free(service->anonymous_identity);
5694 service->anonymous_identity = NULL;
5696 g_free(service->subject_match);
5697 service->subject_match = NULL;
5699 g_free(service->altsubject_match);
5700 service->altsubject_match = NULL;
5702 g_free(service->domain_suffix_match);
5703 service->domain_suffix_match = NULL;
5705 g_free(service->domain_match);
5706 service->domain_match = NULL;
5708 g_free(service->agent_identity);
5709 service->agent_identity = NULL;
5711 g_free(service->eap);
5712 service->eap = NULL;
5714 #if defined TIZEN_EXT
5715 g_free(service->ca_cert_file);
5716 service->ca_cert_file = NULL;
5718 g_free(service->client_cert_file);
5719 service->client_cert_file = NULL;
5721 g_free(service->private_key_file);
5722 service->private_key_file = NULL;
5724 g_free(service->private_key_passphrase);
5725 service->private_key_passphrase = NULL;
5727 g_free(service->phase2);
5728 service->phase2 = NULL;
5730 __connman_service_cleanup_network_8021x(service);
5732 __connman_ipconfig_set_method(service->ipconfig_ipv4, CONNMAN_IPCONFIG_METHOD_DHCP);
5733 __connman_ipconfig_set_method(service->ipconfig_ipv6, CONNMAN_IPCONFIG_METHOD_AUTO);
5734 connman_service_set_proxy(service, NULL, false);
5736 __connman_service_nameserver_clear(service);
5738 g_strfreev(service->nameservers_config);
5739 service->nameservers_config = NULL;
5743 #if defined TIZEN_EXT
5744 if (service->security != CONNMAN_SERVICE_SECURITY_8021X)
5748 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
5750 service->user.favorite_user = USER_NONE;
5752 __connman_service_set_favorite(service, false);
5754 __connman_ipconfig_ipv6_reset_privacy(service->ipconfig_ipv6);
5756 #if defined TIZEN_EXT
5757 /* Reset IP Method and DNS Method to DHCP */
5758 __connman_ipconfig_set_method(service->ipconfig_ipv4,
5759 CONNMAN_IPCONFIG_METHOD_DHCP);
5760 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
5761 g_strfreev(service->nameservers_config);
5762 service->nameservers_config = NULL;
5765 #if defined TIZEN_EXT
5766 __connman_storage_remove_service(service->identifier);
5768 service_save(service);
5774 static DBusMessage *remove_service(DBusConnection *conn,
5775 DBusMessage *msg, void *user_data)
5777 struct connman_service *service = user_data;
5779 DBG("service %p", service);
5781 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5783 if (connman_dbus_get_connection_unix_user_sync(conn,
5784 dbus_message_get_sender(msg),
5786 DBG("Can not get unix user id!");
5787 return __connman_error_permission_denied(msg);
5790 #if !defined TIZEN_EXT
5791 if (!connman_service_is_user_allowed(service, uid)) {
5792 DBG("Not allow this user to remove this wifi service now!");
5793 return __connman_error_permission_denied(msg);
5798 if (!__connman_service_remove(service))
5799 return __connman_error_not_supported(msg);
5801 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5804 static bool check_suitable_state(enum connman_service_state a,
5805 enum connman_service_state b)
5808 * Special check so that "ready" service can be moved before
5811 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
5812 b == CONNMAN_SERVICE_STATE_READY) ||
5813 (b == CONNMAN_SERVICE_STATE_ONLINE &&
5814 a == CONNMAN_SERVICE_STATE_READY))
5820 static void downgrade_state(struct connman_service *service)
5825 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
5826 service->state_ipv6);
5828 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
5829 __connman_service_ipconfig_indicate_state(service,
5830 CONNMAN_SERVICE_STATE_READY,
5831 CONNMAN_IPCONFIG_TYPE_IPV4);
5833 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
5834 __connman_service_ipconfig_indicate_state(service,
5835 CONNMAN_SERVICE_STATE_READY,
5836 CONNMAN_IPCONFIG_TYPE_IPV6);
5839 static void apply_relevant_default_downgrade(struct connman_service *service)
5841 struct connman_service *def_service;
5843 def_service = __connman_service_get_default();
5847 if (def_service == service &&
5848 def_service->state == CONNMAN_SERVICE_STATE_ONLINE) {
5849 def_service->state = CONNMAN_SERVICE_STATE_READY;
5850 __connman_notifier_leave_online(def_service->type);
5851 state_changed(def_service);
5855 static void switch_default_service(struct connman_service *default_service,
5856 struct connman_service *downgrade_service)
5858 struct connman_service *service;
5861 apply_relevant_default_downgrade(default_service);
5862 src = g_list_find(service_list, downgrade_service);
5863 dst = g_list_find(service_list, default_service);
5866 if (src == dst || src->next == dst)
5869 service = src->data;
5870 service_list = g_list_delete_link(service_list, src);
5871 service_list = g_list_insert_before(service_list, dst, service);
5873 downgrade_state(downgrade_service);
5876 static DBusMessage *move_service(DBusConnection *conn,
5877 DBusMessage *msg, void *user_data,
5880 struct connman_service *service = user_data;
5881 struct connman_service *target;
5883 enum connman_ipconfig_method target4, target6;
5884 enum connman_ipconfig_method service4, service6;
5886 DBG("service %p", service);
5888 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
5891 if (!service->favorite)
5892 return __connman_error_not_supported(msg);
5894 target = find_service(path);
5895 if (!target || !target->favorite || target == service)
5896 return __connman_error_invalid_service(msg);
5898 if (target->type == CONNMAN_SERVICE_TYPE_VPN) {
5900 * We only allow VPN route splitting if there are
5901 * routes defined for a given VPN.
5903 if (!__connman_provider_check_routes(target->provider)) {
5904 connman_info("Cannot move service. "
5905 "No routes defined for provider %s",
5906 __connman_provider_get_ident(target->provider));
5907 return __connman_error_invalid_service(msg);
5910 set_split_routing(target, true);
5912 set_split_routing(target, false);
5914 set_split_routing(service, false);
5916 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
5917 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
5918 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
5919 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
5921 DBG("target %s method %d/%d state %d/%d split %d", target->identifier,
5922 target4, target6, target->state_ipv4, target->state_ipv6,
5923 target->do_split_routing);
5925 DBG("service %s method %d/%d state %d/%d", service->identifier,
5927 service->state_ipv4, service->state_ipv6);
5930 * If method is OFF, then we do not need to check the corresponding
5933 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5934 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5935 if (!check_suitable_state(target->state_ipv6,
5936 service->state_ipv6))
5937 return __connman_error_invalid_service(msg);
5941 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5942 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5943 if (!check_suitable_state(target->state_ipv4,
5944 service->state_ipv4))
5945 return __connman_error_invalid_service(msg);
5949 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5950 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5951 if (!check_suitable_state(target->state_ipv6,
5952 service->state_ipv6))
5953 return __connman_error_invalid_service(msg);
5957 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5958 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5959 if (!check_suitable_state(target->state_ipv4,
5960 service->state_ipv4))
5961 return __connman_error_invalid_service(msg);
5965 g_get_current_time(&service->modified);
5966 service_save(service);
5967 service_save(target);
5970 * If the service which goes down is the default service and is
5971 * online, we downgrade directly its state to ready so:
5972 * the service which goes up, needs to recompute its state which
5973 * is triggered via downgrading it - if relevant - to state ready.
5976 switch_default_service(target, service);
5978 switch_default_service(service, target);
5980 __connman_connection_update_gateway();
5982 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5985 static DBusMessage *move_before(DBusConnection *conn,
5986 DBusMessage *msg, void *user_data)
5988 return move_service(conn, msg, user_data, true);
5991 static DBusMessage *move_after(DBusConnection *conn,
5992 DBusMessage *msg, void *user_data)
5994 return move_service(conn, msg, user_data, false);
5997 static DBusMessage *reset_counters(DBusConnection *conn,
5998 DBusMessage *msg, void *user_data)
6000 struct connman_service *service = user_data;
6002 reset_stats(service);
6004 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
6007 static DBusMessage *get_user_favorite(DBusConnection *conn,
6008 DBusMessage *msg, void *user_data)
6011 uid_t uid = USER_NONE;
6012 dbus_bool_t user_favorite = false;
6013 struct connman_service *service = user_data;
6015 connman_dbus_get_connection_unix_user_sync(conn,
6016 dbus_message_get_sender(msg),
6018 if (uid == USER_ROOT)
6019 user_favorite = service->favorite;
6020 else if (uid != USER_NONE && uid == service->user.favorite_user) {
6021 DBG("The service is favorite to this user!");
6022 user_favorite = true;
6025 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
6026 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN,
6027 &user_favorite, DBUS_TYPE_INVALID);
6031 static struct _services_notify {
6037 static void service_append_added_foreach(gpointer data, gpointer user_data)
6039 struct connman_service *service = data;
6040 DBusMessageIter *iter = user_data;
6042 if (!service || !service->path) {
6043 #if !defined TIZEN_EXT
6044 DBG("service %p or path is NULL", service);
6049 if (g_hash_table_lookup(services_notify->add, service->path)) {
6050 #if !defined TIZEN_EXT
6051 DBG("new %s", service->path);
6054 append_struct(service, iter);
6055 g_hash_table_remove(services_notify->add, service->path);
6057 #if !defined TIZEN_EXT
6058 DBG("changed %s", service->path);
6061 append_struct_service(iter, NULL, service);
6065 static void service_append_ordered(DBusMessageIter *iter, void *user_data)
6067 g_list_foreach(service_list, service_append_added_foreach, iter);
6070 static void append_removed(gpointer key, gpointer value, gpointer user_data)
6072 char *objpath = key;
6073 DBusMessageIter *iter = user_data;
6075 DBG("removed %s", objpath);
6076 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath);
6079 static void service_append_removed(DBusMessageIter *iter, void *user_data)
6081 g_hash_table_foreach(services_notify->remove, append_removed, iter);
6084 static gboolean service_send_changed(gpointer data)
6086 DBusMessage *signal;
6090 services_notify->id = 0;
6092 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
6093 CONNMAN_MANAGER_INTERFACE, "ServicesChanged");
6097 __connman_dbus_append_objpath_dict_array(signal,
6098 service_append_ordered, NULL);
6099 __connman_dbus_append_objpath_array(signal,
6100 service_append_removed, NULL);
6102 dbus_connection_send(connection, signal, NULL);
6103 dbus_message_unref(signal);
6105 g_hash_table_remove_all(services_notify->remove);
6106 g_hash_table_remove_all(services_notify->add);
6111 static void service_schedule_changed(void)
6113 if (services_notify->id != 0)
6116 services_notify->id = g_timeout_add(100, service_send_changed, NULL);
6119 static void service_schedule_added(struct connman_service *service)
6121 DBG("service %p", service);
6123 g_hash_table_remove(services_notify->remove, service->path);
6124 g_hash_table_replace(services_notify->add, service->path, service);
6126 service_schedule_changed();
6129 static void service_schedule_removed(struct connman_service *service)
6131 if (!service || !service->path) {
6132 DBG("service %p or path is NULL", service);
6136 DBG("service %p %s", service, service->path);
6138 g_hash_table_remove(services_notify->add, service->path);
6139 g_hash_table_replace(services_notify->remove, g_strdup(service->path),
6142 service_schedule_changed();
6145 static bool allow_property_changed(struct connman_service *service)
6147 #if defined TIZEN_EXT
6148 if (service->path == NULL)
6151 if (g_hash_table_lookup_extended(services_notify->add, service->path,
6158 static const GDBusMethodTable service_methods[] = {
6159 { GDBUS_DEPRECATED_METHOD("GetProperties",
6160 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
6162 { GDBUS_METHOD("SetProperty",
6163 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
6164 NULL, set_property) },
6165 { GDBUS_METHOD("ClearProperty",
6166 GDBUS_ARGS({ "name", "s" }), NULL,
6168 { GDBUS_ASYNC_METHOD("Connect", NULL, NULL,
6170 { GDBUS_METHOD("Disconnect", NULL, NULL,
6171 disconnect_service) },
6172 { GDBUS_METHOD("Remove", NULL, NULL, remove_service) },
6173 { GDBUS_METHOD("MoveBefore",
6174 GDBUS_ARGS({ "service", "o" }), NULL,
6176 { GDBUS_METHOD("MoveAfter",
6177 GDBUS_ARGS({ "service", "o" }), NULL,
6179 { GDBUS_METHOD("ResetCounters", NULL, NULL, reset_counters) },
6180 { GDBUS_METHOD("GetUserFavorite",
6181 NULL, GDBUS_ARGS({ "value", "v" }),
6182 get_user_favorite) },
6186 static const GDBusSignalTable service_signals[] = {
6187 { GDBUS_SIGNAL("PropertyChanged",
6188 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
6192 static void service_free(gpointer user_data)
6194 struct connman_service *service = user_data;
6195 char *path = service->path;
6197 DBG("service %p", service);
6199 reply_pending(service, ENOENT);
6201 if (service->nameservers_timeout) {
6202 g_source_remove(service->nameservers_timeout);
6203 dns_changed(service);
6206 __connman_notifier_service_remove(service);
6207 service_schedule_removed(service);
6209 __connman_wispr_stop(service);
6210 stats_stop(service);
6212 service->path = NULL;
6215 __connman_connection_update_gateway();
6217 g_dbus_unregister_interface(connection, path,
6218 CONNMAN_SERVICE_INTERFACE);
6222 g_hash_table_destroy(service->counter_table);
6224 if (service->network) {
6225 __connman_network_disconnect(service->network);
6226 connman_network_unref(service->network);
6227 service->network = NULL;
6230 if (service->provider)
6231 connman_provider_unref(service->provider);
6233 if (service->ipconfig_ipv4) {
6234 __connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
6235 __connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
6236 __connman_ipconfig_unref(service->ipconfig_ipv4);
6237 service->ipconfig_ipv4 = NULL;
6240 if (service->ipconfig_ipv6) {
6241 __connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
6242 __connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
6243 __connman_ipconfig_unref(service->ipconfig_ipv6);
6244 service->ipconfig_ipv6 = NULL;
6247 g_strfreev(service->timeservers);
6248 g_strfreev(service->timeservers_config);
6249 g_strfreev(service->nameservers);
6250 g_strfreev(service->nameservers_config);
6251 g_strfreev(service->nameservers_auto);
6252 g_strfreev(service->domains);
6253 g_strfreev(service->proxies);
6254 g_strfreev(service->excludes);
6256 g_free(service->hostname);
6257 g_free(service->domainname);
6258 g_free(service->pac);
6259 g_free(service->name);
6260 g_free(service->passphrase);
6261 g_free(service->identifier);
6262 g_free(service->eap);
6263 g_free(service->identity);
6264 g_free(service->anonymous_identity);
6265 g_free(service->agent_identity);
6266 g_free(service->ca_cert_file);
6267 g_free(service->subject_match);
6268 g_free(service->altsubject_match);
6269 g_free(service->domain_suffix_match);
6270 g_free(service->domain_match);
6271 g_free(service->client_cert_file);
6272 g_free(service->private_key_file);
6273 g_free(service->private_key_passphrase);
6274 g_free(service->phase2);
6275 g_free(service->config_file);
6276 g_free(service->config_entry);
6278 if (service->stats.timer)
6279 g_timer_destroy(service->stats.timer);
6280 if (service->stats_roaming.timer)
6281 g_timer_destroy(service->stats_roaming.timer);
6283 if (current_default == service)
6284 current_default = NULL;
6289 static void stats_init(struct connman_service *service)
6292 service->stats.valid = false;
6293 service->stats.enabled = false;
6294 service->stats.timer = g_timer_new();
6297 service->stats_roaming.valid = false;
6298 service->stats_roaming.enabled = false;
6299 service->stats_roaming.timer = g_timer_new();
6302 static void service_initialize(struct connman_service *service)
6304 DBG("service %p", service);
6306 service->refcount = 1;
6308 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
6310 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
6311 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
6313 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
6314 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
6315 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
6317 service->favorite = false;
6318 service->immutable = false;
6319 service->hidden = false;
6321 service->ignore = false;
6323 service->user.favorite_user = USER_NONE;
6324 service->user.current_user = USER_NONE;
6326 service->request_passphrase_input = false;
6328 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
6332 stats_init(service);
6334 service->provider = NULL;
6336 service->wps = false;
6337 #if defined TIZEN_EXT
6338 service->storage_reload = false;
6340 * Description: TIZEN implements system global connection management.
6342 service->user_pdn_connection_refcount = 0;
6343 __sync_synchronize();
6348 * connman_service_create:
6350 * Allocate a new service.
6352 * Returns: a newly-allocated #connman_service structure
6354 struct connman_service *connman_service_create(void)
6357 struct connman_stats_counter *counters;
6358 const char *counter;
6360 struct connman_service *service;
6362 service = g_try_new0(struct connman_service, 1);
6366 DBG("service %p", service);
6368 service->counter_table = g_hash_table_new_full(g_str_hash,
6369 g_str_equal, NULL, g_free);
6371 for (list = counter_list; list; list = list->next) {
6372 counter = list->data;
6374 counters = g_try_new0(struct connman_stats_counter, 1);
6376 g_hash_table_destroy(service->counter_table);
6381 counters->append_all = true;
6383 g_hash_table_replace(service->counter_table, (gpointer)counter,
6387 service_initialize(service);
6393 * connman_service_ref:
6394 * @service: service structure
6396 * Increase reference counter of service
6398 struct connman_service *
6399 connman_service_ref_debug(struct connman_service *service,
6400 const char *file, int line, const char *caller)
6402 DBG("%p ref %d by %s:%d:%s()", service, service->refcount + 1,
6403 file, line, caller);
6405 __sync_fetch_and_add(&service->refcount, 1);
6411 * connman_service_unref:
6412 * @service: service structure
6414 * Decrease reference counter of service and release service if no
6417 void connman_service_unref_debug(struct connman_service *service,
6418 const char *file, int line, const char *caller)
6420 DBG("%p ref %d by %s:%d:%s()", service, service->refcount - 1,
6421 file, line, caller);
6423 if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
6426 service_list = g_list_remove(service_list, service);
6428 __connman_service_disconnect(service);
6430 g_hash_table_remove(service_hash, service->identifier);
6433 static gint service_compare(gconstpointer a, gconstpointer b)
6435 struct connman_service *service_a = (void *) a;
6436 struct connman_service *service_b = (void *) b;
6437 enum connman_service_state state_a, state_b;
6438 bool a_connected, b_connected;
6441 state_a = service_a->state;
6442 state_b = service_b->state;
6443 a_connected = is_connected(state_a);
6444 b_connected = is_connected(state_b);
6446 if (a_connected && b_connected) {
6447 if (service_a->order > service_b->order)
6450 if (service_a->order < service_b->order)
6454 if (state_a != state_b) {
6455 if (a_connected && b_connected) {
6456 /* We prefer online over ready state */
6457 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
6460 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
6469 if (is_connecting(state_a))
6471 if (is_connecting(state_b))
6475 if (service_a->favorite && !service_b->favorite)
6478 if (!service_a->favorite && service_b->favorite)
6481 if (service_a->type != service_b->type) {
6482 unsigned int *tech_array;
6485 tech_array = connman_setting_get_uint_list(
6486 "PreferredTechnologies");
6488 for (i = 0; tech_array[i]; i++) {
6489 if (tech_array[i] == service_a->type)
6492 if (tech_array[i] == service_b->type)
6497 if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6499 if (service_b->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6502 if (service_a->type == CONNMAN_SERVICE_TYPE_WIFI)
6504 if (service_b->type == CONNMAN_SERVICE_TYPE_WIFI)
6507 if (service_a->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6509 if (service_b->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6512 if (service_a->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6514 if (service_b->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6517 if (service_a->type == CONNMAN_SERVICE_TYPE_VPN)
6519 if (service_b->type == CONNMAN_SERVICE_TYPE_VPN)
6522 if (service_a->type == CONNMAN_SERVICE_TYPE_GADGET)
6524 if (service_b->type == CONNMAN_SERVICE_TYPE_GADGET)
6528 strength = (gint) service_b->strength - (gint) service_a->strength;
6532 return g_strcmp0(service_a->name, service_b->name);
6535 static void service_list_sort(void)
6537 if (service_list && service_list->next) {
6538 service_list = g_list_sort(service_list, service_compare);
6539 service_schedule_changed();
6543 int __connman_service_compare(const struct connman_service *a,
6544 const struct connman_service *b)
6546 return service_compare(a, b);
6550 * connman_service_get_type:
6551 * @service: service structure
6553 * Get the type of service
6555 enum connman_service_type connman_service_get_type(struct connman_service *service)
6558 return CONNMAN_SERVICE_TYPE_UNKNOWN;
6560 return service->type;
6564 * connman_service_get_interface:
6565 * @service: service structure
6567 * Get network interface of service
6569 char *connman_service_get_interface(struct connman_service *service)
6576 index = __connman_service_get_index(service);
6578 return connman_inet_ifname(index);
6582 * __connman_service_is_user_allowed:
6583 * @type: service type
6586 * Check a user is allowed to operate a type of service
6588 bool __connman_service_is_user_allowed(enum connman_service_type type,
6592 uid_t owner_user = USER_NONE;
6594 for (list = service_list; list; list = list->next) {
6595 struct connman_service *service = list->data;
6597 if (service->type != type)
6600 if (is_connected(service->state)) {
6601 owner_user = service->user.favorite_user;
6606 if (uid == USER_NONE ||
6607 (uid != USER_ROOT &&
6608 owner_user != USER_NONE &&
6616 * connman_service_get_network:
6617 * @service: service structure
6619 * Get the service network
6621 struct connman_network *
6622 __connman_service_get_network(struct connman_service *service)
6627 return service->network;
6630 struct connman_ipconfig *
6631 __connman_service_get_ip4config(struct connman_service *service)
6636 return service->ipconfig_ipv4;
6639 struct connman_ipconfig *
6640 __connman_service_get_ip6config(struct connman_service *service)
6645 return service->ipconfig_ipv6;
6648 struct connman_ipconfig *
6649 __connman_service_get_ipconfig(struct connman_service *service, int family)
6651 if (family == AF_INET)
6652 return __connman_service_get_ip4config(service);
6653 else if (family == AF_INET6)
6654 return __connman_service_get_ip6config(service);
6660 bool __connman_service_is_connected_state(struct connman_service *service,
6661 enum connman_ipconfig_type type)
6667 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
6669 case CONNMAN_IPCONFIG_TYPE_IPV4:
6670 return is_connected(service->state_ipv4);
6671 case CONNMAN_IPCONFIG_TYPE_IPV6:
6672 return is_connected(service->state_ipv6);
6673 case CONNMAN_IPCONFIG_TYPE_ALL:
6674 return is_connected(service->state_ipv4) &&
6675 is_connected(service->state_ipv6);
6680 enum connman_service_security __connman_service_get_security(
6681 struct connman_service *service)
6684 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
6686 return service->security;
6689 const char *__connman_service_get_phase2(struct connman_service *service)
6694 return service->phase2;
6697 bool __connman_service_wps_enabled(struct connman_service *service)
6702 return service->wps;
6705 void __connman_service_mark_dirty(void)
6707 services_dirty = true;
6710 #if defined TIZEN_EXT
6712 * Returns profile count if there is any connected profiles
6713 * that use same interface
6715 int __connman_service_get_connected_count_of_iface(
6716 struct connman_service *service)
6725 index1 = __connman_service_get_index(service);
6730 for (list = service_list; list; list = list->next) {
6731 struct connman_service *service2 = list->data;
6733 if (service == service2)
6736 index2 = __connman_service_get_index(service2);
6738 if (is_connected(service2->state) && index2 > 0 && index1 == index2)
6744 DBG("Interface index %d, count %d", index1, count);
6749 void __connman_service_set_storage_reload(struct connman_service *service,
6750 bool storage_reload)
6752 if (service != NULL)
6753 service->storage_reload = storage_reload;
6758 * __connman_service_set_favorite_delayed:
6759 * @service: service structure
6760 * @favorite: favorite value
6761 * @delay_ordering: do not order service sequence
6763 * Change the favorite setting of service
6765 int __connman_service_set_favorite_delayed(struct connman_service *service,
6767 bool delay_ordering)
6769 #if defined TIZEN_EXT
6770 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6773 if (service->hidden)
6776 if (service->favorite == favorite)
6779 service->favorite = favorite;
6781 if (!delay_ordering)
6782 __connman_service_get_order(service);
6784 favorite_changed(service);
6786 if (!delay_ordering) {
6788 service_list_sort();
6790 __connman_connection_update_gateway();
6797 * __connman_service_set_favorite:
6798 * @service: service structure
6799 * @favorite: favorite value
6801 * Change the favorite setting of service
6803 int __connman_service_set_favorite(struct connman_service *service,
6806 return __connman_service_set_favorite_delayed(service, favorite,
6810 bool connman_service_get_favorite(struct connman_service *service)
6812 return service->favorite;
6815 bool connman_service_get_autoconnect(struct connman_service *service)
6817 return service->autoconnect;
6820 int __connman_service_set_immutable(struct connman_service *service,
6823 if (service->hidden)
6826 if (service->immutable == immutable)
6829 service->immutable = immutable;
6831 immutable_changed(service);
6836 int __connman_service_set_ignore(struct connman_service *service,
6842 service->ignore = ignore;
6847 void __connman_service_set_string(struct connman_service *service,
6848 const char *key, const char *value)
6850 if (service->hidden)
6852 if (g_str_equal(key, "EAP")) {
6853 g_free(service->eap);
6854 service->eap = g_strdup(value);
6855 } else if (g_str_equal(key, "Identity")) {
6856 g_free(service->identity);
6857 service->identity = g_strdup(value);
6858 } else if (g_str_equal(key, "AnonymousIdentity")) {
6859 g_free(service->anonymous_identity);
6860 service->anonymous_identity = g_strdup(value);
6861 } else if (g_str_equal(key, "CACertFile")) {
6862 g_free(service->ca_cert_file);
6863 service->ca_cert_file = g_strdup(value);
6864 } else if (g_str_equal(key, "SubjectMatch")) {
6865 g_free(service->subject_match);
6866 service->subject_match = g_strdup(value);
6867 } else if (g_str_equal(key, "AltSubjectMatch")) {
6868 g_free(service->altsubject_match);
6869 service->altsubject_match = g_strdup(value);
6870 } else if (g_str_equal(key, "DomainSuffixMatch")) {
6871 g_free(service->domain_suffix_match);
6872 service->domain_suffix_match = g_strdup(value);
6873 } else if (g_str_equal(key, "DomainMatch")) {
6874 g_free(service->domain_match);
6875 service->domain_match = g_strdup(value);
6876 } else if (g_str_equal(key, "ClientCertFile")) {
6877 g_free(service->client_cert_file);
6878 service->client_cert_file = g_strdup(value);
6879 } else if (g_str_equal(key, "PrivateKeyFile")) {
6880 g_free(service->private_key_file);
6881 service->private_key_file = g_strdup(value);
6882 } else if (g_str_equal(key, "PrivateKeyPassphrase")) {
6883 g_free(service->private_key_passphrase);
6884 service->private_key_passphrase = g_strdup(value);
6885 } else if (g_str_equal(key, "Phase2")) {
6886 g_free(service->phase2);
6887 service->phase2 = g_strdup(value);
6888 } else if (g_str_equal(key, "Passphrase"))
6889 __connman_service_set_passphrase(service, value);
6892 void __connman_service_set_search_domains(struct connman_service *service,
6895 searchdomain_remove_all(service);
6897 if (service->domains)
6898 g_strfreev(service->domains);
6900 service->domains = g_strdupv(domains);
6902 searchdomain_add_all(service);
6905 static void report_error_cb(void *user_context, bool retry,
6908 struct connman_service *service = user_context;
6911 __connman_service_connect(service,
6912 CONNMAN_SERVICE_CONNECT_REASON_USER);
6914 /* It is not relevant to stay on Failure state
6915 * when failing is due to wrong user input */
6916 __connman_service_clear_error(service);
6917 #if defined TIZEN_EXT
6918 /* Reseting the state back in case of failure state */
6919 service->state_ipv4 = service->state_ipv6 =
6920 CONNMAN_SERVICE_STATE_IDLE;
6922 if (service->error != CONNMAN_SERVICE_ERROR_AUTH_FAILED)
6923 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6925 service_complete(service);
6926 __connman_connection_update_gateway();
6930 static int check_wpspin(struct connman_service *service, const char *wpspin)
6938 length = strlen(wpspin);
6940 /* If 0, it will mean user wants to use PBC method */
6942 connman_network_set_string(service->network,
6943 "WiFi.PinWPS", NULL);
6947 /* A WPS PIN is always 8 chars length,
6948 * its content is in digit representation.
6953 for (i = 0; i < 8; i++)
6954 if (!isdigit((unsigned char) wpspin[i]))
6957 connman_network_set_string(service->network, "WiFi.PinWPS", wpspin);
6962 static void request_input_cb(struct connman_service *service,
6963 bool values_received,
6964 const char *name, int name_len,
6965 const char *identity, const char *passphrase,
6966 bool wps, const char *wpspin,
6967 const char *error, void *user_data)
6969 struct connman_device *device;
6970 const char *security;
6973 DBG("RequestInput return, %p", service);
6976 DBG("error: %s", error);
6978 if (g_strcmp0(error,
6979 "net.connman.Agent.Error.Canceled") == 0) {
6982 if (service->hidden)
6983 __connman_service_return_error(service,
6988 if (service->hidden)
6989 __connman_service_return_error(service,
6990 ETIMEDOUT, user_data);
6994 if (service->hidden && name_len > 0 && name_len <= 32) {
6995 device = connman_network_get_device(service->network);
6996 security = connman_network_get_string(service->network,
6998 err = __connman_device_request_hidden_scan(device,
7000 identity, passphrase,
7001 security, user_data);
7003 __connman_service_return_error(service, -err,
7007 if (!values_received || service->hidden) {
7012 if (wps && service->network) {
7013 err = check_wpspin(service, wpspin);
7017 connman_network_set_bool(service->network, "WiFi.UseWPS", wps);
7021 __connman_service_set_agent_identity(service, identity);
7024 err = __connman_service_set_passphrase(service, passphrase);
7028 /* We forget any previous error. */
7029 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7031 __connman_service_connect(service,
7032 CONNMAN_SERVICE_CONNECT_REASON_USER);
7034 } else if (err == -ENOKEY) {
7035 __connman_service_indicate_error(service,
7036 CONNMAN_SERVICE_ERROR_INVALID_KEY);
7038 /* It is not relevant to stay on Failure state
7039 * when failing is due to wrong user input */
7040 service->state = CONNMAN_SERVICE_STATE_IDLE;
7042 if (!service->hidden) {
7044 * If there was a real error when requesting
7045 * hidden scan, then that error is returned already
7046 * to the user somewhere above so do not try to
7049 __connman_service_return_error(service, -err,
7053 service_complete(service);
7054 __connman_connection_update_gateway();
7058 static void downgrade_connected_services(void)
7060 struct connman_service *up_service;
7063 for (list = service_list; list; list = list->next) {
7064 up_service = list->data;
7066 if (!is_connected(up_service->state))
7069 if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
7072 downgrade_state(up_service);
7076 static int service_update_preferred_order(struct connman_service *default_service,
7077 struct connman_service *new_service,
7078 enum connman_service_state new_state)
7080 unsigned int *tech_array;
7083 if (!default_service || default_service == new_service ||
7084 default_service->state != new_state)
7087 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
7090 for (i = 0; tech_array[i] != 0; i += 1) {
7091 if (default_service->type == tech_array[i])
7094 if (new_service->type == tech_array[i]) {
7095 switch_default_service(default_service,
7097 __connman_connection_update_gateway();
7106 #if defined TIZEN_EXT
7107 static gboolean __connman_service_can_drop(struct connman_service *service)
7109 if (is_connected(service->state) == TRUE || is_connecting(service->state) == TRUE) {
7110 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
7112 else if (connman_service_is_no_ref_user_pdn_connection(service) == TRUE)
7118 static struct connman_device *default_connecting_device = NULL;
7120 static void __connman_service_disconnect_default(struct connman_service *service)
7122 struct connman_device *default_device = NULL;
7124 if (default_connecting_device == NULL)
7127 default_device = connman_network_get_device(
7128 __connman_service_get_network(service));
7130 DBG("Disconnecting service %p %s", service, service->path);
7131 DBG("Disconnecting device %p %p %s",
7132 default_connecting_device,
7134 connman_device_get_string(default_device, "Name"));
7136 if (default_connecting_device == default_device)
7137 default_connecting_device = NULL;
7140 static void __connman_service_connect_default(struct connman_service *current)
7144 bool default_internet;
7145 struct connman_service *service;
7146 struct connman_service *default_service = NULL;
7147 struct connman_device *default_device = NULL;
7149 if (current->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
7150 switch (current->state) {
7151 case CONNMAN_SERVICE_STATE_UNKNOWN:
7152 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7153 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7159 if (default_connecting_device &&
7160 __connman_service_is_internet_profile(current) == TRUE) {
7161 if (current->network == NULL)
7164 default_device = connman_network_get_device(current->network);
7165 if (default_connecting_device == default_device) {
7166 DBG("Cellular service[%s] %p %s",
7167 state2string(current->state), current, current->path);
7168 DBG("Cellular device %p %p %s",
7169 default_connecting_device, default_device,
7170 connman_device_get_string(default_device, "Name"));
7172 default_connecting_device = NULL;
7177 } else if (is_connected(current->state) == TRUE || is_connecting(current->state) == TRUE)
7180 /* Always-on: keep default cellular connection as possible */
7181 for (list = service_list; list; list = list->next) {
7182 service = list->data;
7184 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7185 __connman_service_is_internet_profile(service) != TRUE ||
7186 service->network == NULL) {
7191 connman_network_get_bool(service->network, "DefaultInternet");
7193 DBG("service: %p %s %s %s (default: %d)", service, service->name,
7194 __connman_service_type2string(service->type),
7195 state2string(service->state), default_internet);
7197 if (default_internet) {
7198 default_service = service;
7199 if (is_connected(default_service->state) == TRUE ||
7200 is_connecting(default_service->state) == TRUE)
7203 default_device = connman_network_get_device(default_service->network);
7204 if (default_connecting_device == default_device) {
7205 DBG("Device is connecting (%p)", default_connecting_device);
7209 default_connecting_device = default_device;
7210 default_service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_USER;
7212 err = __connman_network_connect(default_service->network);
7213 DBG("Connecting default service %p %s [%d]",
7214 default_service, default_service->path, err);
7215 DBG("Connecting device %p %s", default_connecting_device,
7216 connman_device_get_string(default_connecting_device, "Name"));
7217 if (err < 0 && err != -EINPROGRESS) {
7218 default_connecting_device = NULL;
7226 static void single_connected_tech(struct connman_service *allowed)
7228 struct connman_service *service;
7229 GSList *services = NULL, *list;
7232 DBG("keeping %p %s", allowed, allowed->path);
7234 #if defined TIZEN_EXT
7235 if (!allowed || allowed->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7239 for (iter = service_list; iter; iter = iter->next) {
7240 service = iter->data;
7242 #if defined TIZEN_EXT
7243 if (service != allowed && service->type != allowed->type &&
7244 __connman_service_can_drop(service) == TRUE)
7246 if (!is_connected(service->state))
7249 if (service == allowed)
7252 services = g_slist_prepend(services, service);
7255 for (list = services; list; list = list->next) {
7256 service = list->data;
7258 DBG("disconnecting %p %s", service, service->path);
7259 #if defined TIZEN_EXT
7260 __connman_service_disconnect_default(service);
7262 __connman_service_disconnect(service);
7265 g_slist_free(services);
7268 #if defined TIZEN_EXT
7269 static void set_priority_connected_service(void)
7271 struct connman_service *service;
7274 for (list = service_list; list; list = list->next) {
7275 service = list->data;
7277 if (is_connected(service->state) == FALSE)
7285 static const char *get_dbus_sender(struct connman_service *service)
7287 if (!service->pending)
7290 return dbus_message_get_sender(service->pending);
7293 static int service_indicate_state(struct connman_service *service)
7295 enum connman_service_state old_state, new_state;
7296 struct connman_service *def_service;
7297 enum connman_ipconfig_method method;
7303 old_state = service->state;
7304 new_state = combine_state(service->state_ipv4, service->state_ipv6);
7306 DBG("service %p old %s - new %s/%s => %s",
7308 state2string(old_state),
7309 state2string(service->state_ipv4),
7310 state2string(service->state_ipv6),
7311 state2string(new_state));
7313 if (old_state == new_state)
7316 def_service = __connman_service_get_default();
7318 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
7319 result = service_update_preferred_order(def_service,
7320 service, new_state);
7321 if (result == -EALREADY)
7325 if (old_state == CONNMAN_SERVICE_STATE_ONLINE)
7326 __connman_notifier_leave_online(service->type);
7328 if (is_connected(old_state) && !is_connected(new_state))
7329 searchdomain_remove_all(service);
7331 service->state = new_state;
7332 state_changed(service);
7334 if (!is_connected(old_state) && is_connected(new_state))
7335 searchdomain_add_all(service);
7338 case CONNMAN_SERVICE_STATE_UNKNOWN:
7342 case CONNMAN_SERVICE_STATE_IDLE:
7343 if (old_state != CONNMAN_SERVICE_STATE_DISCONNECT)
7344 __connman_service_disconnect(service);
7348 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7352 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7353 if (!service->new_service &&
7354 __connman_stats_service_register(service) == 0) {
7356 * For new services the statistics are updated after
7357 * we have successfully connected.
7359 __connman_stats_get(service, false,
7360 &service->stats.data);
7361 __connman_stats_get(service, true,
7362 &service->stats_roaming.data);
7367 case CONNMAN_SERVICE_STATE_READY:
7368 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7370 if (service->new_service &&
7371 __connman_stats_service_register(service) == 0) {
7373 * This is normally done after configuring state
7374 * but for new service do this after we have connected
7377 __connman_stats_get(service, false,
7378 &service->stats.data);
7379 __connman_stats_get(service, true,
7380 &service->stats_roaming.data);
7383 service->new_service = false;
7387 def_service = __connman_service_get_default();
7389 service_update_preferred_order(def_service, service, new_state);
7391 __connman_service_set_favorite(service, true);
7393 reply_pending(service, 0);
7395 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7396 connman_network_get_bool(service->network,
7400 pass = connman_network_get_string(service->network,
7403 __connman_service_set_passphrase(service, pass);
7405 connman_network_set_bool(service->network,
7406 "WiFi.UseWPS", false);
7409 g_get_current_time(&service->modified);
7410 service_save(service);
7412 domain_changed(service);
7413 proxy_changed(service);
7415 if (old_state != CONNMAN_SERVICE_STATE_ONLINE)
7416 __connman_notifier_connect(service->type);
7418 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
7419 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
7420 __connman_ipconfig_disable_ipv6(
7421 service->ipconfig_ipv6);
7423 if (connman_setting_get_bool("SingleConnectedTechnology"))
7424 single_connected_tech(service);
7425 else if (service->type != CONNMAN_SERVICE_TYPE_VPN)
7428 #if defined TIZEN_EXT
7429 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7430 set_priority_connected_service();
7435 case CONNMAN_SERVICE_STATE_ONLINE:
7439 case CONNMAN_SERVICE_STATE_DISCONNECT:
7440 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7442 reply_pending(service, ECONNABORTED);
7444 def_service = __connman_service_get_default();
7445 service->disconnect_reason = connman_network_get_disconnect_reason(service->network);
7446 service->assoc_status_code = connman_network_get_assoc_status_code(service->network);
7448 if (!__connman_notifier_is_connected() &&
7450 def_service->provider)
7451 connman_provider_disconnect(def_service->provider);
7455 __connman_wispr_stop(service);
7457 __connman_wpad_stop(service);
7459 #if defined TIZEN_EXT
7461 * Skip the functions if there is any connected profiles
7462 * that use same interface
7464 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7465 __connman_service_get_connected_count_of_iface(
7468 domain_changed(service);
7469 proxy_changed(service);
7470 #if defined TIZEN_EXT
7475 * Previous services which are connected and which states
7476 * are set to online should reset relevantly ipconfig_state
7477 * to ready so wispr/portal will be rerun on those
7479 downgrade_connected_services();
7481 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7484 case CONNMAN_SERVICE_STATE_FAILURE:
7485 #if defined TIZEN_EXT
7486 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7488 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7490 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7491 connman_agent_report_error(service, service->path,
7492 error2string(service->error),
7494 get_dbus_sender(service),
7495 NULL) == -EINPROGRESS)
7497 service_complete(service);
7502 service_list_sort();
7504 #if defined TIZEN_EXT
7505 __connman_service_connect_default(service);
7508 __connman_connection_update_gateway();
7510 if ((old_state == CONNMAN_SERVICE_STATE_ONLINE &&
7511 new_state != CONNMAN_SERVICE_STATE_READY) ||
7512 (old_state == CONNMAN_SERVICE_STATE_READY &&
7513 new_state != CONNMAN_SERVICE_STATE_ONLINE)) {
7514 __connman_notifier_disconnect(service->type);
7517 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
7518 __connman_notifier_enter_online(service->type);
7522 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7523 service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7524 (new_state == CONNMAN_SERVICE_STATE_READY ||
7525 new_state == CONNMAN_SERVICE_STATE_ONLINE)) {
7526 if (service->user.favorite_user != service->user.current_user) {
7527 DBG("Now set service favorite user id from %d to %d",
7528 service->user.favorite_user, service->user.current_user);
7530 service->user.favorite_user = service->user.current_user;
7532 service_save(service);
7539 int __connman_service_indicate_error(struct connman_service *service,
7540 enum connman_service_error error)
7542 DBG("service %p error %d", service, error);
7547 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
7550 set_error(service, error);
7552 /* default internet service: fix not cleared if pdp activation*/
7553 #if defined TIZEN_EXT
7555 * If connection failed for default service(DefaultInternet),
7556 * default_connecting_device should be cleared.
7558 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7559 service->error == CONNMAN_SERVICE_ERROR_CONNECT_FAILED)
7560 __connman_service_disconnect_default(service);
7562 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7563 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY) {
7564 g_free(service->passphrase);
7565 service->passphrase = NULL;
7569 __connman_service_ipconfig_indicate_state(service,
7570 CONNMAN_SERVICE_STATE_FAILURE,
7571 CONNMAN_IPCONFIG_TYPE_IPV4);
7572 __connman_service_ipconfig_indicate_state(service,
7573 CONNMAN_SERVICE_STATE_FAILURE,
7574 CONNMAN_IPCONFIG_TYPE_IPV6);
7578 int __connman_service_clear_error(struct connman_service *service)
7580 DBusMessage *pending, *provider_pending;
7582 DBG("service %p", service);
7587 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
7590 pending = service->pending;
7591 service->pending = NULL;
7592 provider_pending = service->provider_pending;
7593 service->provider_pending = NULL;
7595 __connman_service_ipconfig_indicate_state(service,
7596 CONNMAN_SERVICE_STATE_IDLE,
7597 CONNMAN_IPCONFIG_TYPE_IPV6);
7599 __connman_service_ipconfig_indicate_state(service,
7600 CONNMAN_SERVICE_STATE_IDLE,
7601 CONNMAN_IPCONFIG_TYPE_IPV4);
7603 service->pending = pending;
7604 service->provider_pending = provider_pending;
7609 int __connman_service_indicate_default(struct connman_service *service)
7611 DBG("service %p state %s", service, state2string(service->state));
7613 if (!is_connected(service->state)) {
7615 * If service is not yet fully connected, then we must not
7616 * change the default yet. The default gw will be changed
7617 * after the service state is in ready.
7619 return -EINPROGRESS;
7627 enum connman_service_state __connman_service_ipconfig_get_state(
7628 struct connman_service *service,
7629 enum connman_ipconfig_type type)
7632 return CONNMAN_SERVICE_STATE_UNKNOWN;
7634 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7635 return service->state_ipv4;
7637 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
7638 return service->state_ipv6;
7640 return CONNMAN_SERVICE_STATE_UNKNOWN;
7643 static void check_proxy_setup(struct connman_service *service)
7646 * We start WPAD if we haven't got a PAC URL from DHCP and
7647 * if our proxy manual configuration is either empty or set
7648 * to AUTO with an empty URL.
7651 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
7654 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
7655 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
7659 if (__connman_wpad_start(service) < 0) {
7660 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
7661 __connman_notifier_proxy_changed(service);
7668 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
7671 #if defined TIZEN_EXT
7672 void connman_check_proxy_setup_and_wispr_start(struct connman_service *service){
7674 DBG("check the proxy and start wispr");
7675 check_proxy_setup(service);
7681 * How many networks are connected at the same time. If more than 1,
7682 * then set the rp_filter setting properly (loose mode routing) so that network
7683 * connectivity works ok. This is only done for IPv4 networks as IPv6
7684 * does not have rp_filter knob.
7686 static int connected_networks_count;
7687 static int original_rp_filter;
7689 static void service_rp_filter(struct connman_service *service,
7692 enum connman_ipconfig_method method;
7694 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
7697 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7698 case CONNMAN_IPCONFIG_METHOD_OFF:
7699 case CONNMAN_IPCONFIG_METHOD_AUTO:
7701 case CONNMAN_IPCONFIG_METHOD_FIXED:
7702 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7703 case CONNMAN_IPCONFIG_METHOD_DHCP:
7708 if (connected_networks_count == 1) {
7710 filter_value = __connman_ipconfig_set_rp_filter();
7711 if (filter_value < 0)
7714 original_rp_filter = filter_value;
7716 connected_networks_count++;
7719 if (connected_networks_count == 2)
7720 __connman_ipconfig_unset_rp_filter(original_rp_filter);
7722 connected_networks_count--;
7723 if (connected_networks_count < 0)
7724 connected_networks_count = 0;
7727 DBG("%s %s ipconfig %p method %d count %d filter %d",
7728 connected ? "connected" : "disconnected", service->identifier,
7729 service->ipconfig_ipv4, method,
7730 connected_networks_count, original_rp_filter);
7733 static gboolean redo_wispr(gpointer user_data)
7735 struct connman_service *service = user_data;
7736 int refcount = service->refcount - 1;
7738 connman_service_unref(service);
7739 if (refcount == 0) {
7740 DBG("Service %p already removed", service);
7744 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV6);
7749 int __connman_service_online_check_failed(struct connman_service *service,
7750 enum connman_ipconfig_type type)
7752 DBG("service %p type %d count %d", service, type,
7753 service->online_check_count);
7755 /* currently we only retry IPv6 stuff */
7756 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 ||
7757 service->online_check_count != 1) {
7758 connman_warn("Online check failed for %p %s", service,
7763 service->online_check_count = 0;
7766 * We set the timeout to 1 sec so that we have a chance to get
7767 * necessary IPv6 router advertisement messages that might have
7770 g_timeout_add_seconds(1, redo_wispr, connman_service_ref(service));
7775 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
7776 enum connman_service_state new_state,
7777 enum connman_ipconfig_type type)
7779 struct connman_ipconfig *ipconfig = NULL;
7780 enum connman_service_state old_state;
7781 enum connman_ipconfig_method method;
7787 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
7788 case CONNMAN_IPCONFIG_TYPE_ALL:
7791 case CONNMAN_IPCONFIG_TYPE_IPV4:
7792 old_state = service->state_ipv4;
7793 ipconfig = service->ipconfig_ipv4;
7797 case CONNMAN_IPCONFIG_TYPE_IPV6:
7798 old_state = service->state_ipv6;
7799 ipconfig = service->ipconfig_ipv6;
7807 method = __connman_ipconfig_get_method(ipconfig);
7810 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7811 case CONNMAN_IPCONFIG_METHOD_OFF:
7812 if (new_state != CONNMAN_SERVICE_STATE_IDLE)
7813 connman_warn("ipconfig state %d ipconfig method %d",
7816 new_state = CONNMAN_SERVICE_STATE_IDLE;
7819 case CONNMAN_IPCONFIG_METHOD_FIXED:
7820 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7821 case CONNMAN_IPCONFIG_METHOD_DHCP:
7822 case CONNMAN_IPCONFIG_METHOD_AUTO:
7828 if (old_state == new_state)
7831 #if defined TIZEN_EXT
7832 __sync_synchronize();
7833 if (service->user_pdn_connection_refcount > 0 &&
7834 service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7835 if (new_state == CONNMAN_SERVICE_STATE_FAILURE ||
7836 new_state == CONNMAN_SERVICE_STATE_DISCONNECT ||
7837 new_state == CONNMAN_SERVICE_STATE_IDLE) {
7838 service->user_pdn_connection_refcount = 0;
7839 __sync_synchronize();
7843 DBG("service %p (%s) old state %d (%s) new state %d (%s) type %d (%s)",
7844 service, service ? service->identifier : NULL,
7845 old_state, state2string(old_state),
7846 new_state, state2string(new_state),
7847 type, __connman_ipconfig_type2string(type));
7849 switch (new_state) {
7850 case CONNMAN_SERVICE_STATE_UNKNOWN:
7851 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7853 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7855 case CONNMAN_SERVICE_STATE_READY:
7856 #if defined TIZEN_EXT
7857 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7858 __connman_service_is_internet_profile(service) != TRUE) {
7859 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7860 service_rp_filter(service, TRUE);
7865 if (connman_setting_get_bool("EnableOnlineCheck")) {
7866 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
7867 #if !defined TIZEN_EXT
7868 check_proxy_setup(service);
7871 service->online_check_count = 1;
7872 __connman_wispr_start(service, type);
7875 connman_info("Online check disabled. "
7876 "Default service remains in READY state.");
7877 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7878 service_rp_filter(service, true);
7880 case CONNMAN_SERVICE_STATE_ONLINE:
7882 case CONNMAN_SERVICE_STATE_DISCONNECT:
7883 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
7886 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7887 service_rp_filter(service, false);
7891 case CONNMAN_SERVICE_STATE_IDLE:
7892 case CONNMAN_SERVICE_STATE_FAILURE:
7893 __connman_ipconfig_disable(ipconfig);
7898 if (is_connected(old_state) && !is_connected(new_state))
7899 nameserver_remove_all(service, type);
7901 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7902 service->state_ipv4 = new_state;
7904 service->state_ipv6 = new_state;
7906 if (!is_connected(old_state) && is_connected(new_state))
7907 nameserver_add_all(service, type);
7909 __connman_timeserver_sync(service);
7911 #if defined TIZEN_EXT
7912 int ret = service_indicate_state(service);
7913 /*Sent the Ready changed signal again in case IPv4 IP set
7916 if(ret == -EALREADY && type == CONNMAN_IPCONFIG_TYPE_IPV4
7917 && new_state == CONNMAN_SERVICE_STATE_READY) {
7918 DBG("Notify IPv4 state new/old %d/%d", new_state,old_state);
7919 state_changed(service);
7924 return service_indicate_state(service);
7927 static bool prepare_network(struct connman_service *service)
7929 enum connman_network_type type;
7930 unsigned int ssid_len;
7932 type = connman_network_get_type(service->network);
7935 case CONNMAN_NETWORK_TYPE_UNKNOWN:
7936 case CONNMAN_NETWORK_TYPE_VENDOR:
7938 case CONNMAN_NETWORK_TYPE_WIFI:
7939 if (!connman_network_get_blob(service->network, "WiFi.SSID",
7943 if (service->passphrase)
7944 connman_network_set_string(service->network,
7945 "WiFi.Passphrase", service->passphrase);
7947 case CONNMAN_NETWORK_TYPE_ETHERNET:
7948 case CONNMAN_NETWORK_TYPE_GADGET:
7949 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
7950 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
7951 case CONNMAN_NETWORK_TYPE_CELLULAR:
7958 static void prepare_8021x(struct connman_service *service)
7961 connman_network_set_string(service->network, "WiFi.EAP",
7964 if (service->identity)
7965 connman_network_set_string(service->network, "WiFi.Identity",
7968 if (service->anonymous_identity)
7969 connman_network_set_string(service->network,
7970 "WiFi.AnonymousIdentity",
7971 service->anonymous_identity);
7973 if (service->ca_cert_file)
7974 connman_network_set_string(service->network, "WiFi.CACertFile",
7975 service->ca_cert_file);
7977 if (service->subject_match)
7978 connman_network_set_string(service->network, "WiFi.SubjectMatch",
7979 service->subject_match);
7981 if (service->altsubject_match)
7982 connman_network_set_string(service->network, "WiFi.AltSubjectMatch",
7983 service->altsubject_match);
7985 if (service->domain_suffix_match)
7986 connman_network_set_string(service->network, "WiFi.DomainSuffixMatch",
7987 service->domain_suffix_match);
7989 if (service->domain_match)
7990 connman_network_set_string(service->network, "WiFi.DomainMatch",
7991 service->domain_match);
7993 if (service->client_cert_file)
7994 connman_network_set_string(service->network,
7995 "WiFi.ClientCertFile",
7996 service->client_cert_file);
7998 if (service->private_key_file)
7999 connman_network_set_string(service->network,
8000 "WiFi.PrivateKeyFile",
8001 service->private_key_file);
8003 if (service->private_key_passphrase)
8004 connman_network_set_string(service->network,
8005 "WiFi.PrivateKeyPassphrase",
8006 service->private_key_passphrase);
8008 if (service->phase2)
8009 connman_network_set_string(service->network, "WiFi.Phase2",
8012 #if defined TIZEN_EXT
8013 if (service->keymgmt_type)
8014 connman_network_set_string(service->network, "WiFi.KeymgmtType",
8015 service->keymgmt_type);
8017 DBG("service->phase1 : %s", service->phase1);
8018 if (service->phase1)
8019 connman_network_set_string(service->network, "WiFi.Phase1",
8024 static int service_connect(struct connman_service *service)
8028 if (service->hidden)
8031 #if defined TIZEN_EXT
8035 index = __connman_service_get_index(service);
8037 for (list = service_list; list; list = list->next) {
8038 struct connman_service *temp = list->data;
8040 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8043 if (!is_connecting(temp->state) && !is_connected(temp->state))
8046 if (service == temp)
8049 if (service->type != temp->type)
8052 if (__connman_service_get_index(temp) == index &&
8053 __connman_service_disconnect(temp) == -EINPROGRESS)
8054 return -EINPROGRESS;
8058 switch (service->type) {
8059 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8060 case CONNMAN_SERVICE_TYPE_SYSTEM:
8061 case CONNMAN_SERVICE_TYPE_GPS:
8062 case CONNMAN_SERVICE_TYPE_P2P:
8064 case CONNMAN_SERVICE_TYPE_ETHERNET:
8065 case CONNMAN_SERVICE_TYPE_GADGET:
8066 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8067 case CONNMAN_SERVICE_TYPE_CELLULAR:
8068 case CONNMAN_SERVICE_TYPE_VPN:
8070 case CONNMAN_SERVICE_TYPE_WIFI:
8071 switch (service->security) {
8072 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
8073 case CONNMAN_SERVICE_SECURITY_NONE:
8075 case CONNMAN_SERVICE_SECURITY_WEP:
8076 case CONNMAN_SERVICE_SECURITY_PSK:
8077 case CONNMAN_SERVICE_SECURITY_WPA:
8078 case CONNMAN_SERVICE_SECURITY_RSN:
8079 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
8082 if (service->request_passphrase_input) {
8083 DBG("Now try to connect other user's favorite service");
8084 service->request_passphrase_input = false;
8086 } else if (!service->passphrase) {
8087 if (!service->network)
8090 if (!service->wps ||
8091 !connman_network_get_bool(service->network, "WiFi.UseWPS"))
8096 case CONNMAN_SERVICE_SECURITY_8021X:
8100 #if defined TIZEN_EXT
8102 * never request credentials if using EAP-TLS, EAP-SIM
8103 * or EAP-AKA (EAP-TLS, EAP-SIM and EAP-AKA networks
8104 * need to be fully provisioned)
8106 DBG("service eap: %s", service->eap);
8107 if (g_str_equal(service->eap, "tls") ||
8108 g_str_equal(service->eap, "sim") ||
8109 g_str_equal(service->eap, "aka") ||
8110 g_str_equal(service->eap, "aka'") ||
8111 g_str_equal(service->eap, "pwd") ||
8112 g_str_equal(service->eap, "fast"))
8116 * never request credentials if using EAP-TLS
8117 * (EAP-TLS networks need to be fully provisioned)
8119 if (g_str_equal(service->eap, "tls"))
8123 * Return -ENOKEY if either identity or passphrase is
8124 * missing. Agent provided credentials can be used as
8125 * fallback if needed.
8127 if (((!service->identity &&
8128 !service->agent_identity) ||
8129 !service->passphrase) ||
8130 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
8138 if (service->network) {
8139 if (!prepare_network(service))
8142 switch (service->security) {
8143 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
8144 case CONNMAN_SERVICE_SECURITY_NONE:
8145 case CONNMAN_SERVICE_SECURITY_WEP:
8146 case CONNMAN_SERVICE_SECURITY_PSK:
8147 case CONNMAN_SERVICE_SECURITY_WPA:
8148 case CONNMAN_SERVICE_SECURITY_RSN:
8150 case CONNMAN_SERVICE_SECURITY_8021X:
8151 prepare_8021x(service);
8155 if (__connman_stats_service_register(service) == 0) {
8156 __connman_stats_get(service, false,
8157 &service->stats.data);
8158 __connman_stats_get(service, true,
8159 &service->stats_roaming.data);
8162 err = __connman_network_connect(service->network);
8163 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8165 err = __connman_provider_connect(service->provider,
8166 get_dbus_sender(service));
8171 if (err != -EINPROGRESS) {
8172 __connman_service_ipconfig_indicate_state(service,
8173 CONNMAN_SERVICE_STATE_FAILURE,
8174 CONNMAN_IPCONFIG_TYPE_IPV4);
8175 __connman_service_ipconfig_indicate_state(service,
8176 CONNMAN_SERVICE_STATE_FAILURE,
8177 CONNMAN_IPCONFIG_TYPE_IPV6);
8178 __connman_stats_service_unregister(service);
8185 int __connman_service_connect(struct connman_service *service,
8186 enum connman_service_connect_reason reason)
8190 DBG("service %p state %s connect reason %s -> %s",
8191 service, state2string(service->state),
8192 reason2string(service->connect_reason),
8193 reason2string(reason));
8195 if (is_connected(service->state))
8198 if (is_connecting(service->state))
8201 switch (service->type) {
8202 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8203 case CONNMAN_SERVICE_TYPE_SYSTEM:
8204 case CONNMAN_SERVICE_TYPE_GPS:
8205 case CONNMAN_SERVICE_TYPE_P2P:
8208 case CONNMAN_SERVICE_TYPE_ETHERNET:
8209 case CONNMAN_SERVICE_TYPE_GADGET:
8210 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8211 case CONNMAN_SERVICE_TYPE_CELLULAR:
8212 case CONNMAN_SERVICE_TYPE_VPN:
8213 case CONNMAN_SERVICE_TYPE_WIFI:
8217 if (!is_ipconfig_usable(service))
8220 __connman_service_clear_error(service);
8222 err = service_connect(service);
8224 DBG("service %p err %d", service, err);
8226 service->connect_reason = reason;
8230 if (err == -EINPROGRESS) {
8231 if (service->timeout == 0)
8232 service->timeout = g_timeout_add_seconds(
8233 CONNECT_TIMEOUT, connect_timeout, service);
8235 return -EINPROGRESS;
8238 if (service->network)
8239 __connman_network_disconnect(service->network);
8240 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8242 connman_provider_disconnect(service->provider);
8244 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
8245 if (err == -ENOKEY || err == -EPERM) {
8246 DBusMessage *pending = NULL;
8247 const char *dbus_sender = get_dbus_sender(service);
8250 * We steal the reply here. The idea is that the
8251 * connecting client will see the connection status
8252 * after the real hidden network is connected or
8253 * connection failed.
8255 if (service->hidden) {
8256 pending = service->pending;
8257 service->pending = NULL;
8260 err = __connman_agent_request_passphrase_input(service,
8264 if (service->hidden && err != -EINPROGRESS)
8265 service->pending = pending;
8269 reply_pending(service, -err);
8275 int __connman_service_disconnect(struct connman_service *service)
8279 DBG("service %p", service);
8281 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
8282 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
8284 connman_agent_cancel(service);
8286 reply_pending(service, ECONNABORTED);
8288 if (service->network) {
8289 err = __connman_network_disconnect(service->network);
8290 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8292 err = connman_provider_disconnect(service->provider);
8296 if (err < 0 && err != -EINPROGRESS)
8299 __connman_6to4_remove(service->ipconfig_ipv4);
8301 if (service->ipconfig_ipv4)
8302 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
8305 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
8308 #if defined TIZEN_EXT
8310 * Skip the functions If there is any connected profiles
8311 * that use same interface
8313 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
8314 __connman_service_get_connected_count_of_iface(service) <= 0) {
8316 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
8317 settings_changed(service, service->ipconfig_ipv4);
8319 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
8320 settings_changed(service, service->ipconfig_ipv6);
8322 __connman_ipconfig_disable(service->ipconfig_ipv4);
8323 __connman_ipconfig_disable(service->ipconfig_ipv6);
8324 #if defined TIZEN_EXT
8328 __connman_stats_service_unregister(service);
8333 int __connman_service_disconnect_all(void)
8335 struct connman_service *service;
8336 GSList *services = NULL, *list;
8341 for (iter = service_list; iter; iter = iter->next) {
8342 service = iter->data;
8344 if (!is_connected(service->state))
8347 services = g_slist_prepend(services, service);
8350 for (list = services; list; list = list->next) {
8351 struct connman_service *service = list->data;
8353 service->ignore = true;
8355 __connman_service_disconnect(service);
8358 g_slist_free(services);
8364 * lookup_by_identifier:
8365 * @identifier: service identifier
8367 * Look up a service by identifier (reference count will not be increased)
8369 static struct connman_service *lookup_by_identifier(const char *identifier)
8371 return g_hash_table_lookup(service_hash, identifier);
8374 struct connman_service *connman_service_lookup_from_identifier(const char* identifier)
8376 return lookup_by_identifier(identifier);
8379 struct provision_user_data {
8384 static void provision_changed(gpointer value, gpointer user_data)
8386 struct connman_service *service = value;
8387 struct provision_user_data *data = user_data;
8388 const char *path = data->ident;
8391 ret = __connman_config_provision_service_ident(service, path,
8392 service->config_file, service->config_entry);
8397 int __connman_service_provision_changed(const char *ident)
8399 struct provision_user_data data = {
8404 g_list_foreach(service_list, provision_changed, (void *)&data);
8407 * Because the provision_changed() might have set some services
8408 * as favorite, we must sort the sequence now.
8410 if (services_dirty) {
8411 services_dirty = false;
8413 service_list_sort();
8415 __connman_connection_update_gateway();
8421 void __connman_service_set_config(struct connman_service *service,
8422 const char *file_id, const char *entry)
8427 g_free(service->config_file);
8428 service->config_file = g_strdup(file_id);
8430 g_free(service->config_entry);
8431 service->config_entry = g_strdup(entry);
8435 * __connman_service_get:
8436 * @identifier: service identifier
8438 * Look up a service by identifier or create a new one if not found
8440 static struct connman_service *service_get(const char *identifier)
8442 struct connman_service *service;
8444 service = g_hash_table_lookup(service_hash, identifier);
8446 connman_service_ref(service);
8450 service = connman_service_create();
8454 DBG("service %p", service);
8456 service->identifier = g_strdup(identifier);
8458 service_list = g_list_insert_sorted(service_list, service,
8461 g_hash_table_insert(service_hash, service->identifier, service);
8466 static int service_register(struct connman_service *service)
8468 DBG("service %p", service);
8473 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
8474 service->identifier);
8476 DBG("path %s", service->path);
8478 if (__connman_config_provision_service(service) < 0)
8479 service_load(service);
8481 g_dbus_register_interface(connection, service->path,
8482 CONNMAN_SERVICE_INTERFACE,
8483 service_methods, service_signals,
8484 NULL, service, NULL);
8486 service_list_sort();
8488 __connman_connection_update_gateway();
8493 static void service_up(struct connman_ipconfig *ipconfig,
8496 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8498 DBG("%s up", ifname);
8500 link_changed(service);
8502 service->stats.valid = false;
8503 service->stats_roaming.valid = false;
8506 static void service_down(struct connman_ipconfig *ipconfig,
8509 DBG("%s down", ifname);
8512 static void service_lower_up(struct connman_ipconfig *ipconfig,
8515 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8517 DBG("%s lower up", ifname);
8519 stats_start(service);
8522 static void service_lower_down(struct connman_ipconfig *ipconfig,
8525 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8527 DBG("%s lower down", ifname);
8529 stats_stop(service);
8530 service_save(service);
8533 static void service_ip_bound(struct connman_ipconfig *ipconfig,
8536 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8537 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8538 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8539 #if defined TIZEN_EXT
8543 DBG("%s ip bound", ifname);
8545 type = __connman_ipconfig_get_config_type(ipconfig);
8546 method = __connman_ipconfig_get_method(ipconfig);
8548 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8551 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8552 method == CONNMAN_IPCONFIG_METHOD_AUTO)
8553 #if defined TIZEN_EXT
8555 err = __connman_ipconfig_gateway_add(ipconfig, service);
8558 DBG("Failed to add gateway");
8561 __connman_service_ipconfig_indicate_state(service,
8562 CONNMAN_SERVICE_STATE_READY,
8563 CONNMAN_IPCONFIG_TYPE_IPV6);
8566 settings_changed(service, ipconfig);
8567 address_updated(service, type);
8570 static void service_ip_release(struct connman_ipconfig *ipconfig,
8573 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8574 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8575 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8577 DBG("%s ip release", ifname);
8579 type = __connman_ipconfig_get_config_type(ipconfig);
8580 method = __connman_ipconfig_get_method(ipconfig);
8582 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8585 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8586 method == CONNMAN_IPCONFIG_METHOD_OFF)
8587 __connman_service_ipconfig_indicate_state(service,
8588 CONNMAN_SERVICE_STATE_DISCONNECT,
8589 CONNMAN_IPCONFIG_TYPE_IPV6);
8591 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
8592 method == CONNMAN_IPCONFIG_METHOD_OFF)
8593 __connman_service_ipconfig_indicate_state(service,
8594 CONNMAN_SERVICE_STATE_DISCONNECT,
8595 CONNMAN_IPCONFIG_TYPE_IPV4);
8597 settings_changed(service, ipconfig);
8600 static void service_route_changed(struct connman_ipconfig *ipconfig,
8603 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8605 DBG("%s route changed", ifname);
8607 settings_changed(service, ipconfig);
8610 static const struct connman_ipconfig_ops service_ops = {
8612 .down = service_down,
8613 .lower_up = service_lower_up,
8614 .lower_down = service_lower_down,
8615 .ip_bound = service_ip_bound,
8616 .ip_release = service_ip_release,
8617 .route_set = service_route_changed,
8618 .route_unset = service_route_changed,
8621 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
8622 int index, enum connman_ipconfig_method method)
8624 struct connman_ipconfig *ipconfig_ipv4;
8626 ipconfig_ipv4 = __connman_ipconfig_create(index,
8627 CONNMAN_IPCONFIG_TYPE_IPV4);
8631 __connman_ipconfig_set_method(ipconfig_ipv4, method);
8633 __connman_ipconfig_set_data(ipconfig_ipv4, service);
8635 __connman_ipconfig_set_ops(ipconfig_ipv4, &service_ops);
8637 return ipconfig_ipv4;
8640 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
8643 struct connman_ipconfig *ipconfig_ipv6;
8645 ipconfig_ipv6 = __connman_ipconfig_create(index,
8646 CONNMAN_IPCONFIG_TYPE_IPV6);
8650 __connman_ipconfig_set_data(ipconfig_ipv6, service);
8652 __connman_ipconfig_set_ops(ipconfig_ipv6, &service_ops);
8654 return ipconfig_ipv6;
8657 void __connman_service_read_ip4config(struct connman_service *service)
8661 if (!service->ipconfig_ipv4)
8664 keyfile = connman_storage_load_service(service->identifier);
8668 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
8669 service->identifier, "IPv4.");
8671 g_key_file_free(keyfile);
8674 void connman_service_create_ip4config(struct connman_service *service,
8677 DBG("ipv4 %p", service->ipconfig_ipv4);
8679 if (service->ipconfig_ipv4)
8682 service->ipconfig_ipv4 = create_ip4config(service, index,
8683 CONNMAN_IPCONFIG_METHOD_DHCP);
8684 __connman_service_read_ip4config(service);
8687 void __connman_service_read_ip6config(struct connman_service *service)
8691 if (!service->ipconfig_ipv6)
8694 keyfile = connman_storage_load_service(service->identifier);
8698 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
8699 service->identifier, "IPv6.");
8701 g_key_file_free(keyfile);
8704 void connman_service_create_ip6config(struct connman_service *service,
8707 DBG("ipv6 %p", service->ipconfig_ipv6);
8709 if (service->ipconfig_ipv6)
8712 service->ipconfig_ipv6 = create_ip6config(service, index);
8714 __connman_service_read_ip6config(service);
8718 * connman_service_lookup_from_network:
8719 * @network: network structure
8721 * Look up a service by network (reference count will not be increased)
8723 struct connman_service *connman_service_lookup_from_network(struct connman_network *network)
8725 struct connman_service *service;
8726 const char *ident, *group;
8732 ident = __connman_network_get_ident(network);
8736 group = connman_network_get_group(network);
8740 name = g_strdup_printf("%s_%s_%s",
8741 __connman_network_get_type(network), ident, group);
8742 service = lookup_by_identifier(name);
8748 struct connman_service *__connman_service_lookup_from_index(int index)
8750 struct connman_service *service;
8753 for (list = service_list; list; list = list->next) {
8754 service = list->data;
8756 if (__connman_ipconfig_get_index(service->ipconfig_ipv4)
8760 if (__connman_ipconfig_get_index(service->ipconfig_ipv6)
8768 struct connman_service *__connman_service_lookup_from_ident(const char *identifier)
8770 return lookup_by_identifier(identifier);
8773 const char *__connman_service_get_ident(struct connman_service *service)
8775 return service->identifier;
8778 const char *__connman_service_get_path(struct connman_service *service)
8780 return service->path;
8783 const char *__connman_service_get_name(struct connman_service *service)
8785 return service->name;
8788 enum connman_service_state __connman_service_get_state(struct connman_service *service)
8790 return service->state;
8793 unsigned int __connman_service_get_order(struct connman_service *service)
8795 unsigned int order = 0;
8802 if (!service->favorite)
8805 #if defined TIZEN_EXT
8806 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8807 service->do_split_routing == FALSE)
8809 else if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
8810 if (service->order < 5)
8812 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
8814 else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
8816 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8817 __connman_service_is_internet_profile(service) == TRUE)
8819 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8820 __connman_service_is_tethering_profile(service) == TRUE)
8822 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8827 if (service == service_list->data)
8830 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8831 !service->do_split_routing) {
8832 service->order = 10;
8836 DBG("service %p name %s order %d split %d", service, service->name,
8837 order, service->do_split_routing);
8842 static enum connman_service_type convert_network_type(struct connman_network *network)
8844 enum connman_network_type type = connman_network_get_type(network);
8847 case CONNMAN_NETWORK_TYPE_UNKNOWN:
8848 case CONNMAN_NETWORK_TYPE_VENDOR:
8850 case CONNMAN_NETWORK_TYPE_ETHERNET:
8851 return CONNMAN_SERVICE_TYPE_ETHERNET;
8852 case CONNMAN_NETWORK_TYPE_WIFI:
8853 return CONNMAN_SERVICE_TYPE_WIFI;
8854 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
8855 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
8856 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
8857 case CONNMAN_NETWORK_TYPE_CELLULAR:
8858 return CONNMAN_SERVICE_TYPE_CELLULAR;
8859 case CONNMAN_NETWORK_TYPE_GADGET:
8860 return CONNMAN_SERVICE_TYPE_GADGET;
8863 return CONNMAN_SERVICE_TYPE_UNKNOWN;
8866 static enum connman_service_security convert_wifi_security(const char *security)
8869 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8870 else if (g_str_equal(security, "none"))
8871 return CONNMAN_SERVICE_SECURITY_NONE;
8872 else if (g_str_equal(security, "wep"))
8873 return CONNMAN_SERVICE_SECURITY_WEP;
8874 else if (g_str_equal(security, "psk"))
8875 return CONNMAN_SERVICE_SECURITY_PSK;
8876 else if (g_str_equal(security, "ieee8021x"))
8877 return CONNMAN_SERVICE_SECURITY_8021X;
8878 else if (g_str_equal(security, "wpa"))
8879 return CONNMAN_SERVICE_SECURITY_WPA;
8880 else if (g_str_equal(security, "rsn"))
8881 return CONNMAN_SERVICE_SECURITY_RSN;
8882 #if defined TIZEN_EXT
8883 else if (g_str_equal(security, "ft_psk") == TRUE)
8884 return CONNMAN_SERVICE_SECURITY_PSK;
8885 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
8886 return CONNMAN_SERVICE_SECURITY_8021X;
8889 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8892 #if defined TIZEN_EXT
8893 int check_passphrase_ext(struct connman_network *network,
8894 const char *passphrase)
8897 enum connman_service_security security;
8899 str = connman_network_get_string(network, "WiFi.Security");
8900 security = convert_wifi_security(str);
8902 return __connman_service_check_passphrase(security, passphrase);
8906 static void update_from_network(struct connman_service *service,
8907 struct connman_network *network)
8909 uint8_t strength = service->strength;
8912 DBG("service %p network %p", service, network);
8914 if (is_connected(service->state))
8917 if (is_connecting(service->state))
8920 str = connman_network_get_string(network, "Name");
8922 g_free(service->name);
8923 service->name = g_strdup(str);
8924 service->hidden = false;
8926 g_free(service->name);
8927 service->name = NULL;
8928 service->hidden = true;
8931 service->strength = connman_network_get_strength(network);
8932 service->roaming = connman_network_get_bool(network, "Roaming");
8934 if (service->strength == 0) {
8936 * Filter out 0-values; it's unclear what they mean
8937 * and they cause anomalous sorting of the priority list.
8939 service->strength = strength;
8942 str = connman_network_get_string(network, "WiFi.Security");
8943 service->security = convert_wifi_security(str);
8945 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
8946 service->wps = connman_network_get_bool(network, "WiFi.WPS");
8948 if (service->strength > strength && service->network) {
8949 connman_network_unref(service->network);
8950 service->network = connman_network_ref(network);
8952 strength_changed(service);
8955 if (!service->network)
8956 service->network = connman_network_ref(network);
8958 service_list_sort();
8962 * __connman_service_create_from_network:
8963 * @network: network structure
8965 * Look up service by network and if not found, create one
8967 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
8969 struct connman_service *service;
8970 struct connman_device *device;
8971 const char *ident, *group;
8973 unsigned int *auto_connect_types;
8976 DBG("network %p", network);
8981 ident = __connman_network_get_ident(network);
8985 group = connman_network_get_group(network);
8989 name = g_strdup_printf("%s_%s_%s",
8990 __connman_network_get_type(network), ident, group);
8991 service = service_get(name);
8997 if (__connman_network_get_weakness(network))
9000 if (service->path) {
9001 update_from_network(service, network);
9002 __connman_connection_update_gateway();
9006 service->type = convert_network_type(network);
9008 auto_connect_types = connman_setting_get_uint_list("DefaultAutoConnectTechnologies");
9009 service->autoconnect = false;
9010 for (i = 0; auto_connect_types &&
9011 auto_connect_types[i] != 0; i++) {
9012 if (service->type == auto_connect_types[i]) {
9013 service->autoconnect = true;
9018 switch (service->type) {
9019 case CONNMAN_SERVICE_TYPE_UNKNOWN:
9020 case CONNMAN_SERVICE_TYPE_SYSTEM:
9021 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
9022 case CONNMAN_SERVICE_TYPE_GPS:
9023 case CONNMAN_SERVICE_TYPE_VPN:
9024 case CONNMAN_SERVICE_TYPE_GADGET:
9025 case CONNMAN_SERVICE_TYPE_WIFI:
9026 case CONNMAN_SERVICE_TYPE_CELLULAR:
9027 case CONNMAN_SERVICE_TYPE_P2P:
9029 case CONNMAN_SERVICE_TYPE_ETHERNET:
9030 service->favorite = true;
9034 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
9035 service->state = combine_state(service->state_ipv4, service->state_ipv6);
9037 update_from_network(service, network);
9039 index = connman_network_get_index(network);
9041 if (!service->ipconfig_ipv4)
9042 service->ipconfig_ipv4 = create_ip4config(service, index,
9043 CONNMAN_IPCONFIG_METHOD_DHCP);
9045 if (!service->ipconfig_ipv6)
9046 service->ipconfig_ipv6 = create_ip6config(service, index);
9048 service_register(service);
9049 service_schedule_added(service);
9051 if (service->favorite) {
9052 device = connman_network_get_device(service->network);
9053 if (device && !connman_device_get_scanning(device)) {
9055 switch (service->type) {
9056 case CONNMAN_SERVICE_TYPE_UNKNOWN:
9057 case CONNMAN_SERVICE_TYPE_SYSTEM:
9058 case CONNMAN_SERVICE_TYPE_P2P:
9061 case CONNMAN_SERVICE_TYPE_GADGET:
9062 case CONNMAN_SERVICE_TYPE_ETHERNET:
9063 if (service->autoconnect) {
9064 __connman_service_connect(service,
9065 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
9070 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
9071 case CONNMAN_SERVICE_TYPE_GPS:
9072 case CONNMAN_SERVICE_TYPE_VPN:
9073 case CONNMAN_SERVICE_TYPE_WIFI:
9074 case CONNMAN_SERVICE_TYPE_CELLULAR:
9075 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
9080 #if defined TIZEN_EXT
9081 /* TIZEN synchronizes below information when the service creates */
9082 if (service->eap != NULL)
9083 connman_network_set_string(service->network, "WiFi.EAP",
9085 if (service->identity != NULL)
9086 connman_network_set_string(service->network, "WiFi.Identity",
9088 if (service->phase2 != NULL)
9089 connman_network_set_string(service->network, "WiFi.Phase2",
9094 __connman_notifier_service_add(service, service->name);
9099 void __connman_service_update_from_network(struct connman_network *network)
9101 bool need_sort = false;
9102 struct connman_service *service;
9108 service = connman_service_lookup_from_network(network);
9112 if (!service->network)
9115 #if defined TIZEN_EXT
9116 if (service->storage_reload) {
9117 service_load(service);
9118 __connman_service_set_storage_reload(service, false);
9122 name = connman_network_get_string(service->network, "Name");
9123 if (g_strcmp0(service->name, name) != 0) {
9124 g_free(service->name);
9125 service->name = g_strdup(name);
9127 if (allow_property_changed(service))
9128 connman_dbus_property_changed_basic(service->path,
9129 CONNMAN_SERVICE_INTERFACE, "Name",
9130 DBUS_TYPE_STRING, &service->name);
9133 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
9134 service->wps = connman_network_get_bool(network, "WiFi.WPS");
9136 strength = connman_network_get_strength(service->network);
9137 if (strength == service->strength)
9140 service->strength = strength;
9143 strength_changed(service);
9146 roaming = connman_network_get_bool(service->network, "Roaming");
9147 if (roaming == service->roaming)
9150 stats_enable = stats_enabled(service);
9152 stats_stop(service);
9154 service->roaming = roaming;
9158 stats_start(service);
9160 roaming_changed(service);
9164 service_list_sort();
9168 void __connman_service_remove_from_network(struct connman_network *network)
9170 struct connman_service *service;
9172 service = connman_service_lookup_from_network(network);
9174 DBG("network %p service %p", network, service);
9179 service->ignore = true;
9181 __connman_connection_gateway_remove(service,
9182 CONNMAN_IPCONFIG_TYPE_ALL);
9184 connman_service_unref(service);
9188 * __connman_service_create_from_provider:
9189 * @provider: provider structure
9191 * Look up service by provider and if not found, create one
9193 struct connman_service *
9194 __connman_service_create_from_provider(struct connman_provider *provider)
9196 struct connman_service *service;
9197 const char *ident, *str;
9199 int index = connman_provider_get_index(provider);
9201 DBG("provider %p", provider);
9203 ident = __connman_provider_get_ident(provider);
9207 name = g_strdup_printf("vpn_%s", ident);
9208 service = service_get(name);
9214 service->type = CONNMAN_SERVICE_TYPE_VPN;
9215 service->provider = connman_provider_ref(provider);
9216 service->autoconnect = false;
9217 service->favorite = true;
9219 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
9220 service->state = combine_state(service->state_ipv4, service->state_ipv6);
9222 str = connman_provider_get_string(provider, "Name");
9224 g_free(service->name);
9225 service->name = g_strdup(str);
9226 service->hidden = false;
9228 g_free(service->name);
9229 service->name = NULL;
9230 service->hidden = true;
9233 service->strength = 0;
9235 if (!service->ipconfig_ipv4)
9236 service->ipconfig_ipv4 = create_ip4config(service, index,
9237 CONNMAN_IPCONFIG_METHOD_MANUAL);
9239 if (!service->ipconfig_ipv6)
9240 service->ipconfig_ipv6 = create_ip6config(service, index);
9242 service_register(service);
9244 __connman_notifier_service_add(service, service->name);
9245 service_schedule_added(service);
9250 static void remove_unprovisioned_services(void)
9253 GKeyFile *keyfile, *configkeyfile;
9254 char *file, *section;
9257 services = connman_storage_get_services();
9261 for (; services[i]; i++) {
9262 file = section = NULL;
9263 keyfile = configkeyfile = NULL;
9265 keyfile = connman_storage_load_service(services[i]);
9269 file = g_key_file_get_string(keyfile, services[i],
9270 "Config.file", NULL);
9274 section = g_key_file_get_string(keyfile, services[i],
9275 "Config.ident", NULL);
9279 configkeyfile = __connman_storage_load_config(file);
9280 if (!configkeyfile) {
9282 * Config file is missing, remove the provisioned
9285 __connman_storage_remove_service(services[i]);
9289 if (!g_key_file_has_group(configkeyfile, section))
9291 * Config section is missing, remove the provisioned
9294 __connman_storage_remove_service(services[i]);
9298 g_key_file_free(keyfile);
9301 g_key_file_free(configkeyfile);
9307 g_strfreev(services);
9310 static int agent_probe(struct connman_agent *agent)
9312 DBG("agent %p", agent);
9316 static void agent_remove(struct connman_agent *agent)
9318 DBG("agent %p", agent);
9321 static void *agent_context_ref(void *context)
9323 struct connman_service *service = context;
9325 return (void *)connman_service_ref(service);
9328 static void agent_context_unref(void *context)
9330 struct connman_service *service = context;
9332 connman_service_unref(service);
9335 static struct connman_agent_driver agent_driver = {
9337 .interface = CONNMAN_AGENT_INTERFACE,
9338 .probe = agent_probe,
9339 .remove = agent_remove,
9340 .context_ref = agent_context_ref,
9341 .context_unref = agent_context_unref,
9344 int __connman_service_init(void)
9350 err = connman_agent_driver_register(&agent_driver);
9352 connman_error("Cannot register agent driver for %s",
9357 set_always_connecting_technologies();
9359 connection = connman_dbus_get_connection();
9361 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
9362 NULL, service_free);
9364 services_notify = g_new0(struct _services_notify, 1);
9365 services_notify->remove = g_hash_table_new_full(g_str_hash,
9366 g_str_equal, g_free, NULL);
9367 services_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
9369 remove_unprovisioned_services();
9374 void __connman_service_cleanup(void)
9378 if (vpn_autoconnect_timeout) {
9379 g_source_remove(vpn_autoconnect_timeout);
9380 vpn_autoconnect_timeout = 0;
9383 if (autoconnect_timeout != 0) {
9384 g_source_remove(autoconnect_timeout);
9385 autoconnect_timeout = 0;
9388 connman_agent_driver_unregister(&agent_driver);
9390 g_list_free(service_list);
9391 service_list = NULL;
9393 g_hash_table_destroy(service_hash);
9394 service_hash = NULL;
9396 g_slist_free(counter_list);
9397 counter_list = NULL;
9399 if (services_notify->id != 0) {
9400 g_source_remove(services_notify->id);
9401 service_send_changed(NULL);
9404 g_hash_table_destroy(services_notify->remove);
9405 g_hash_table_destroy(services_notify->add);
9406 g_free(services_notify);
9408 dbus_connection_unref(connection);