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;
172 enum connman_dnsconfig_method dns_config_method_ipv4;
173 enum connman_dnsconfig_method dns_config_method_ipv6;
177 static bool allow_property_changed(struct connman_service *service);
179 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
180 int index, enum connman_ipconfig_method method);
181 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
183 static void dns_changed(struct connman_service *service);
187 struct connman_service *service;
190 #if defined TIZEN_EXT
192 * Public APIs to use user_pdn_connection_refcount
194 void connman_service_user_pdn_connection_ref(struct connman_service *service)
196 __sync_fetch_and_add(&service->user_pdn_connection_refcount, 1);
198 DBG("User made PDN connection referenced: %d",
199 service->user_pdn_connection_refcount);
202 gboolean connman_service_user_pdn_connection_unref_and_test(
203 struct connman_service *service)
205 __sync_synchronize();
207 DBG("User made PDN connection referenced: %d, which will be decreased",
208 service->user_pdn_connection_refcount);
210 if (service->user_pdn_connection_refcount < 1)
213 if (__sync_sub_and_fetch(&service->user_pdn_connection_refcount, 1) == 0)
219 gboolean connman_service_is_no_ref_user_pdn_connection(
220 struct connman_service *cellular)
222 if (cellular == NULL)
225 __sync_synchronize();
226 if (cellular->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
227 cellular->user_pdn_connection_refcount == 0)
234 static void compare_path(gpointer value, gpointer user_data)
236 struct connman_service *service = value;
237 struct find_data *data = user_data;
242 if (g_strcmp0(service->path, data->path) == 0)
243 data->service = service;
246 static struct connman_service *find_service(const char *path)
248 struct find_data data = { .path = path, .service = NULL };
250 DBG("path %s", path);
252 g_list_foreach(service_list, compare_path, &data);
257 static const char *reason2string(enum connman_service_connect_reason reason)
261 case CONNMAN_SERVICE_CONNECT_REASON_NONE:
263 case CONNMAN_SERVICE_CONNECT_REASON_USER:
265 case CONNMAN_SERVICE_CONNECT_REASON_AUTO:
267 case CONNMAN_SERVICE_CONNECT_REASON_SESSION:
274 const char *__connman_service_type2string(enum connman_service_type type)
277 case CONNMAN_SERVICE_TYPE_UNKNOWN:
279 case CONNMAN_SERVICE_TYPE_SYSTEM:
281 case CONNMAN_SERVICE_TYPE_ETHERNET:
283 case CONNMAN_SERVICE_TYPE_WIFI:
285 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
287 case CONNMAN_SERVICE_TYPE_CELLULAR:
289 case CONNMAN_SERVICE_TYPE_GPS:
291 case CONNMAN_SERVICE_TYPE_VPN:
293 case CONNMAN_SERVICE_TYPE_GADGET:
295 case CONNMAN_SERVICE_TYPE_P2P:
302 enum connman_service_type __connman_service_string2type(const char *str)
305 return CONNMAN_SERVICE_TYPE_UNKNOWN;
307 if (strcmp(str, "ethernet") == 0)
308 return CONNMAN_SERVICE_TYPE_ETHERNET;
309 if (strcmp(str, "gadget") == 0)
310 return CONNMAN_SERVICE_TYPE_GADGET;
311 if (strcmp(str, "wifi") == 0)
312 return CONNMAN_SERVICE_TYPE_WIFI;
313 if (strcmp(str, "cellular") == 0)
314 return CONNMAN_SERVICE_TYPE_CELLULAR;
315 if (strcmp(str, "bluetooth") == 0)
316 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
317 if (strcmp(str, "vpn") == 0)
318 return CONNMAN_SERVICE_TYPE_VPN;
319 if (strcmp(str, "gps") == 0)
320 return CONNMAN_SERVICE_TYPE_GPS;
321 if (strcmp(str, "system") == 0)
322 return CONNMAN_SERVICE_TYPE_SYSTEM;
323 if (strcmp(str, "p2p") == 0)
324 return CONNMAN_SERVICE_TYPE_P2P;
326 return CONNMAN_SERVICE_TYPE_UNKNOWN;
329 enum connman_service_security __connman_service_string2security(const char *str)
332 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
334 if (!strcmp(str, "psk"))
335 return CONNMAN_SERVICE_SECURITY_PSK;
336 if (!strcmp(str, "ieee8021x") || !strcmp(str, "8021x"))
337 return CONNMAN_SERVICE_SECURITY_8021X;
338 if (!strcmp(str, "none") || !strcmp(str, "open"))
339 return CONNMAN_SERVICE_SECURITY_NONE;
340 if (!strcmp(str, "wep"))
341 return CONNMAN_SERVICE_SECURITY_WEP;
342 #if defined TIZEN_EXT
343 if (!strcmp(str, "rsn"))
344 return CONNMAN_SERVICE_SECURITY_RSN;
347 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
350 static const char *security2string(enum connman_service_security security)
353 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
355 case CONNMAN_SERVICE_SECURITY_NONE:
357 case CONNMAN_SERVICE_SECURITY_WEP:
359 case CONNMAN_SERVICE_SECURITY_PSK:
360 case CONNMAN_SERVICE_SECURITY_WPA:
361 #if defined TIZEN_EXT
363 case CONNMAN_SERVICE_SECURITY_RSN:
366 case CONNMAN_SERVICE_SECURITY_RSN:
369 case CONNMAN_SERVICE_SECURITY_8021X:
376 static const char *state2string(enum connman_service_state state)
379 case CONNMAN_SERVICE_STATE_UNKNOWN:
381 case CONNMAN_SERVICE_STATE_IDLE:
383 case CONNMAN_SERVICE_STATE_ASSOCIATION:
384 return "association";
385 case CONNMAN_SERVICE_STATE_CONFIGURATION:
386 return "configuration";
387 case CONNMAN_SERVICE_STATE_READY:
389 case CONNMAN_SERVICE_STATE_ONLINE:
391 case CONNMAN_SERVICE_STATE_DISCONNECT:
393 case CONNMAN_SERVICE_STATE_FAILURE:
400 static const char *error2string(enum connman_service_error error)
403 case CONNMAN_SERVICE_ERROR_UNKNOWN:
405 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
406 return "out-of-range";
407 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
408 return "pin-missing";
409 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
410 return "dhcp-failed";
411 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
412 return "connect-failed";
413 case CONNMAN_SERVICE_ERROR_LOGIN_FAILED:
414 return "login-failed";
415 case CONNMAN_SERVICE_ERROR_AUTH_FAILED:
416 return "auth-failed";
417 case CONNMAN_SERVICE_ERROR_INVALID_KEY:
418 return "invalid-key";
419 case CONNMAN_SERVICE_ERROR_BLOCKED:
426 static const char *proxymethod2string(enum connman_service_proxy_method method)
429 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
431 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
433 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
435 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
442 static enum connman_service_proxy_method string2proxymethod(const char *method)
444 if (g_strcmp0(method, "direct") == 0)
445 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
446 else if (g_strcmp0(method, "auto") == 0)
447 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
448 else if (g_strcmp0(method, "manual") == 0)
449 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
451 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
455 static const char *__connman_dnsconfig_method2string(enum connman_dnsconfig_method method)
458 case CONNMAN_DNSCONFIG_METHOD_UNKNOWN:
460 case CONNMAN_DNSCONFIG_METHOD_MANUAL:
462 case CONNMAN_DNSCONFIG_METHOD_DHCP:
469 static enum connman_dnsconfig_method __connman_dnsconfig_string2method(
472 if (g_strcmp0(method, "manual") == 0)
473 return CONNMAN_DNSCONFIG_METHOD_MANUAL;
474 else if (g_strcmp0(method, "dhcp") == 0)
475 return CONNMAN_DNSCONFIG_METHOD_DHCP;
477 return CONNMAN_DNSCONFIG_METHOD_UNKNOWN;
482 connman_service_is_user_allowed(struct connman_service *service, uid_t uid)
484 uid_t favorite_user = service->user.favorite_user;
485 uid_t current_user = uid;
487 DBG("Service favorite UID: %d, current UID: %d", favorite_user, current_user);
488 if (favorite_user == USER_NONE || current_user == USER_ROOT)
491 if (favorite_user != current_user || current_user == USER_NONE) {
492 DBG("Current user is not a favorite user to this service!");
499 #if !defined TIZEN_EXT
500 static GList *connman_service_get_login_users()
504 GList *user_list = NULL;
508 while ((utmp = getutxent()) != NULL) {
509 DBG("User Name: %s", utmp->ut_user);
511 pwd = getpwnam(utmp->ut_user);
513 if (!g_list_find(user_list, GUINT_TO_POINTER(pwd->pw_uid)))
514 user_list = g_list_append(user_list,
515 GUINT_TO_POINTER(pwd->pw_uid));
517 DBG("User Name: %s, UID: %d", utmp->ut_user, pwd->pw_uid);
527 static bool is_service_owner_user_login(struct connman_service *service)
529 #if defined TIZEN_EXT
532 GList *list, *user_list;
535 /* Here we only care about wifi service */
536 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
539 DBG("service favorite user id is: %d", service->user.favorite_user);
541 user_list = connman_service_get_login_users();
542 if (user_list == NULL) {
543 DBG("Can not get any logged in user info.");
547 for (list = user_list; list; list = list->next) {
548 uid_t uid = GPOINTER_TO_UINT(list->data);
550 DBG("login user id is %d", uid);
552 if (service->user.favorite_user == uid) {
558 g_list_free(user_list);
564 static void set_split_routing(struct connman_service *service, bool value)
566 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
569 service->do_split_routing = value;
571 if (service->do_split_routing)
577 int __connman_service_load_modifiable(struct connman_service *service)
580 GError *error = NULL;
584 DBG("service %p", service);
586 keyfile = connman_storage_load_service(service->identifier);
590 switch (service->type) {
591 case CONNMAN_SERVICE_TYPE_UNKNOWN:
592 case CONNMAN_SERVICE_TYPE_SYSTEM:
593 case CONNMAN_SERVICE_TYPE_GPS:
594 case CONNMAN_SERVICE_TYPE_P2P:
596 case CONNMAN_SERVICE_TYPE_VPN:
597 set_split_routing(service, g_key_file_get_boolean(keyfile,
599 "SplitRouting", NULL));
602 case CONNMAN_SERVICE_TYPE_WIFI:
603 case CONNMAN_SERVICE_TYPE_GADGET:
604 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
605 case CONNMAN_SERVICE_TYPE_CELLULAR:
606 case CONNMAN_SERVICE_TYPE_ETHERNET:
607 autoconnect = g_key_file_get_boolean(keyfile,
608 service->identifier, "AutoConnect", &error);
610 service->autoconnect = autoconnect;
611 g_clear_error(&error);
615 str = g_key_file_get_string(keyfile,
616 service->identifier, "Modified", NULL);
618 g_time_val_from_iso8601(str, &service->modified);
622 g_key_file_free(keyfile);
627 static int service_load_passphrase(struct connman_service *service)
632 keyfile = connman_storage_load_service(service->identifier);
636 str = g_key_file_get_string(keyfile,
637 service->identifier, "Passphrase", NULL);
639 service->passphrase = str;
641 g_key_file_free(keyfile);
646 static int service_load(struct connman_service *service)
649 GError *error = NULL;
653 unsigned int ssid_len;
656 DBG("service %p", service);
658 keyfile = connman_storage_load_service(service->identifier);
660 service->new_service = true;
663 service->new_service = false;
665 switch (service->type) {
666 case CONNMAN_SERVICE_TYPE_UNKNOWN:
667 case CONNMAN_SERVICE_TYPE_SYSTEM:
668 case CONNMAN_SERVICE_TYPE_GPS:
669 case CONNMAN_SERVICE_TYPE_P2P:
671 case CONNMAN_SERVICE_TYPE_VPN:
672 set_split_routing(service, g_key_file_get_boolean(keyfile,
674 "SplitRouting", NULL));
676 autoconnect = g_key_file_get_boolean(keyfile,
677 service->identifier, "AutoConnect", &error);
679 service->autoconnect = autoconnect;
680 g_clear_error(&error);
682 case CONNMAN_SERVICE_TYPE_WIFI:
683 if (!service->name) {
686 name = g_key_file_get_string(keyfile,
687 service->identifier, "Name", NULL);
689 g_free(service->name);
690 service->name = name;
693 if (service->network)
694 connman_network_set_name(service->network,
698 if (service->network &&
699 !connman_network_get_blob(service->network,
700 "WiFi.SSID", &ssid_len)) {
703 hex_ssid = g_key_file_get_string(keyfile,
709 unsigned int i, j = 0, hex;
710 size_t hex_ssid_len = strlen(hex_ssid);
712 ssid = g_try_malloc0(hex_ssid_len / 2);
719 for (i = 0; i < hex_ssid_len; i += 2) {
720 sscanf(hex_ssid + i, "%02x", &hex);
724 connman_network_set_blob(service->network,
725 "WiFi.SSID", ssid, hex_ssid_len / 2);
734 case CONNMAN_SERVICE_TYPE_GADGET:
735 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
736 case CONNMAN_SERVICE_TYPE_CELLULAR:
737 service->favorite = g_key_file_get_boolean(keyfile,
738 service->identifier, "Favorite", NULL);
742 case CONNMAN_SERVICE_TYPE_ETHERNET:
743 autoconnect = g_key_file_get_boolean(keyfile,
744 service->identifier, "AutoConnect", &error);
746 service->autoconnect = autoconnect;
747 g_clear_error(&error);
751 str = g_key_file_get_string(keyfile,
752 service->identifier, "Modified", NULL);
754 g_time_val_from_iso8601(str, &service->modified);
758 str = g_key_file_get_string(keyfile,
759 service->identifier, "Passphrase", NULL);
761 g_free(service->passphrase);
762 service->passphrase = str;
765 if (service->ipconfig_ipv4)
766 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
767 service->identifier, "IPv4.");
769 if (service->ipconfig_ipv6)
770 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
771 service->identifier, "IPv6.");
773 service->nameservers_config = g_key_file_get_string_list(keyfile,
774 service->identifier, "Nameservers", &length, NULL);
775 if (service->nameservers_config && length == 0) {
776 g_strfreev(service->nameservers_config);
777 service->nameservers_config = NULL;
783 dns_method = g_key_file_get_string(keyfile, service->identifier,
784 "Nameservers.IPv4method", NULL);
785 service->dns_config_method_ipv4 = __connman_dnsconfig_string2method(dns_method);
787 dns_method = g_key_file_get_string(keyfile, service->identifier,
788 "Nameservers.IPv6method", NULL);
789 service->dns_config_method_ipv6 = __connman_dnsconfig_string2method(dns_method);
792 service->timeservers_config = g_key_file_get_string_list(keyfile,
793 service->identifier, "Timeservers", &length, NULL);
794 if (service->timeservers_config && length == 0) {
795 g_strfreev(service->timeservers_config);
796 service->timeservers_config = NULL;
799 service->domains = g_key_file_get_string_list(keyfile,
800 service->identifier, "Domains", &length, NULL);
801 if (service->domains && length == 0) {
802 g_strfreev(service->domains);
803 service->domains = NULL;
806 str = g_key_file_get_string(keyfile,
807 service->identifier, "Proxy.Method", NULL);
809 service->proxy_config = string2proxymethod(str);
813 service->proxies = g_key_file_get_string_list(keyfile,
814 service->identifier, "Proxy.Servers", &length, NULL);
815 if (service->proxies && length == 0) {
816 g_strfreev(service->proxies);
817 service->proxies = NULL;
820 service->excludes = g_key_file_get_string_list(keyfile,
821 service->identifier, "Proxy.Excludes", &length, NULL);
822 if (service->excludes && length == 0) {
823 g_strfreev(service->excludes);
824 service->excludes = NULL;
827 str = g_key_file_get_string(keyfile,
828 service->identifier, "Proxy.URL", NULL);
830 g_free(service->pac);
834 service->hidden_service = g_key_file_get_boolean(keyfile,
835 service->identifier, "Hidden", NULL);
837 #if defined TIZEN_EXT
838 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
839 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
840 str = g_key_file_get_string(keyfile,
841 service->identifier, "EAP", NULL);
843 g_free(service->eap);
847 str = g_key_file_get_string(keyfile,
848 service->identifier, "Phase2", NULL);
850 g_free(service->phase2);
851 service->phase2 = str;
854 str = g_key_file_get_string(keyfile,
855 service->identifier, "Identity", NULL);
857 g_free(service->identity);
858 service->identity = str;
861 str = g_key_file_get_string(keyfile,
862 service->identifier, "CACertFile", NULL);
864 g_free(service->ca_cert_file);
865 service->ca_cert_file = str;
868 str = g_key_file_get_string(keyfile,
869 service->identifier, "ClientCertFile", NULL);
871 g_free(service->client_cert_file);
872 service->client_cert_file = str;
875 str = g_key_file_get_string(keyfile,
876 service->identifier, "PrivateKeyFile", NULL);
878 g_free(service->private_key_file);
879 service->private_key_file = str;
882 str = g_key_file_get_string(keyfile,
883 service->identifier, "PrivateKeyPassphrase", NULL);
885 g_free(service->private_key_passphrase);
886 service->private_key_passphrase = str;
891 if (g_key_file_has_key(keyfile, service->identifier, "UID", NULL))
892 service->user.favorite_user = g_key_file_get_integer(keyfile,
893 service->identifier, "UID", NULL);
895 g_key_file_free(keyfile);
900 static int service_save(struct connman_service *service)
905 const char *cst_str = NULL;
908 DBG("service %p new %d", service, service->new_service);
910 if (service->new_service)
913 keyfile = __connman_storage_open_service(service->identifier);
918 g_key_file_set_string(keyfile, service->identifier,
919 "Name", service->name);
921 switch (service->type) {
922 case CONNMAN_SERVICE_TYPE_UNKNOWN:
923 case CONNMAN_SERVICE_TYPE_SYSTEM:
924 case CONNMAN_SERVICE_TYPE_GPS:
925 case CONNMAN_SERVICE_TYPE_P2P:
927 case CONNMAN_SERVICE_TYPE_VPN:
928 g_key_file_set_boolean(keyfile, service->identifier,
929 "SplitRouting", service->do_split_routing);
930 if (service->favorite)
931 g_key_file_set_boolean(keyfile, service->identifier,
932 "AutoConnect", service->autoconnect);
934 case CONNMAN_SERVICE_TYPE_WIFI:
935 if (service->network) {
936 const unsigned char *ssid;
937 unsigned int ssid_len = 0;
939 if (service->user.favorite_user == USER_NONE)
940 g_key_file_remove_key(keyfile, service->identifier,
943 g_key_file_set_integer(keyfile, service->identifier,
944 "UID", service->user.favorite_user);
946 ssid = connman_network_get_blob(service->network,
947 "WiFi.SSID", &ssid_len);
949 if (ssid && ssid_len > 0 && ssid[0] != '\0') {
950 char *identifier = service->identifier;
954 ssid_str = g_string_sized_new(ssid_len * 2);
960 for (i = 0; i < ssid_len; i++)
961 g_string_append_printf(ssid_str,
964 g_key_file_set_string(keyfile, identifier,
965 "SSID", ssid_str->str);
967 g_string_free(ssid_str, TRUE);
970 freq = connman_network_get_frequency(service->network);
971 g_key_file_set_integer(keyfile, service->identifier,
976 case CONNMAN_SERVICE_TYPE_GADGET:
977 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
978 case CONNMAN_SERVICE_TYPE_CELLULAR:
979 g_key_file_set_boolean(keyfile, service->identifier,
980 "Favorite", service->favorite);
982 g_key_file_remove_key(keyfile, service->identifier,
987 case CONNMAN_SERVICE_TYPE_ETHERNET:
988 if (service->favorite)
989 g_key_file_set_boolean(keyfile, service->identifier,
990 "AutoConnect", service->autoconnect);
994 str = g_time_val_to_iso8601(&service->modified);
996 g_key_file_set_string(keyfile, service->identifier,
1001 if (service->user.current_user == service->user.favorite_user) {
1002 if (service->passphrase && strlen(service->passphrase) > 0)
1003 g_key_file_set_string(keyfile, service->identifier,
1004 "Passphrase", service->passphrase);
1006 g_key_file_remove_key(keyfile, service->identifier,
1007 "Passphrase", NULL);
1010 if (service->ipconfig_ipv4)
1011 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
1012 service->identifier, "IPv4.");
1014 if (service->ipconfig_ipv6)
1015 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
1016 service->identifier, "IPv6.");
1018 if (service->nameservers_config) {
1019 guint len = g_strv_length(service->nameservers_config);
1021 g_key_file_set_string_list(keyfile, service->identifier,
1023 (const gchar **) service->nameservers_config, len);
1025 g_key_file_remove_key(keyfile, service->identifier,
1026 "Nameservers", NULL);
1028 #if defined TIZEN_EXT
1029 if(service->dns_config_method_ipv4 != 0) {
1031 method = __connman_dnsconfig_method2string(
1032 service->dns_config_method_ipv4);
1033 g_key_file_set_string(keyfile, service->identifier,
1034 "Nameservers.IPv4method", method);
1036 g_key_file_remove_key(keyfile, service->identifier,
1037 "Nameservers.IPv4method", NULL);
1039 if(service->dns_config_method_ipv6 != 0) {
1041 method = __connman_dnsconfig_method2string(
1042 service->dns_config_method_ipv6);
1043 g_key_file_set_string(keyfile, service->identifier,
1044 "Nameservers.IPv6method", method);
1046 g_key_file_remove_key(keyfile, service->identifier,
1047 "Nameservers.IPv6method", NULL);
1050 if (service->timeservers_config) {
1051 guint len = g_strv_length(service->timeservers_config);
1053 g_key_file_set_string_list(keyfile, service->identifier,
1055 (const gchar **) service->timeservers_config, len);
1057 g_key_file_remove_key(keyfile, service->identifier,
1058 "Timeservers", NULL);
1060 if (service->domains) {
1061 guint len = g_strv_length(service->domains);
1063 g_key_file_set_string_list(keyfile, service->identifier,
1065 (const gchar **) service->domains, len);
1067 g_key_file_remove_key(keyfile, service->identifier,
1070 cst_str = proxymethod2string(service->proxy_config);
1072 g_key_file_set_string(keyfile, service->identifier,
1073 "Proxy.Method", cst_str);
1075 if (service->proxies) {
1076 guint len = g_strv_length(service->proxies);
1078 g_key_file_set_string_list(keyfile, service->identifier,
1080 (const gchar **) service->proxies, len);
1082 g_key_file_remove_key(keyfile, service->identifier,
1083 "Proxy.Servers", NULL);
1085 if (service->excludes) {
1086 guint len = g_strv_length(service->excludes);
1088 g_key_file_set_string_list(keyfile, service->identifier,
1090 (const gchar **) service->excludes, len);
1092 g_key_file_remove_key(keyfile, service->identifier,
1093 "Proxy.Excludes", NULL);
1095 if (service->pac && strlen(service->pac) > 0)
1096 g_key_file_set_string(keyfile, service->identifier,
1097 "Proxy.URL", service->pac);
1099 g_key_file_remove_key(keyfile, service->identifier,
1102 if (service->hidden_service)
1103 g_key_file_set_boolean(keyfile, service->identifier, "Hidden",
1106 if (service->config_file && strlen(service->config_file) > 0)
1107 g_key_file_set_string(keyfile, service->identifier,
1108 "Config.file", service->config_file);
1110 if (service->config_entry &&
1111 strlen(service->config_entry) > 0)
1112 g_key_file_set_string(keyfile, service->identifier,
1113 "Config.ident", service->config_entry);
1115 #if defined TIZEN_EXT
1116 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1117 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
1118 if (service->eap != NULL && strlen(service->eap) > 0)
1119 g_key_file_set_string(keyfile, service->identifier,
1120 "EAP", service->eap);
1122 g_key_file_remove_key(keyfile, service->identifier,
1125 if (service->phase2 != NULL && strlen(service->phase2) > 0)
1126 g_key_file_set_string(keyfile, service->identifier,
1127 "Phase2", service->phase2);
1129 g_key_file_remove_key(keyfile, service->identifier,
1132 if (service->identity != NULL && strlen(service->identity) > 0)
1133 g_key_file_set_string(keyfile, service->identifier,
1134 "Identity", service->identity);
1136 g_key_file_remove_key(keyfile, service->identifier,
1139 if (service->ca_cert_file != NULL && strlen(service->ca_cert_file) > 0)
1140 g_key_file_set_string(keyfile, service->identifier,
1141 "CACertFile", service->ca_cert_file);
1143 g_key_file_remove_key(keyfile, service->identifier,
1144 "CACertFile", NULL);
1146 if (service->client_cert_file != NULL && strlen(service->client_cert_file) > 0)
1147 g_key_file_set_string(keyfile, service->identifier,
1148 "ClientCertFile", service->client_cert_file);
1150 g_key_file_remove_key(keyfile, service->identifier,
1151 "ClientCertFile", NULL);
1153 if (service->private_key_file != NULL && strlen(service->private_key_file) > 0)
1154 g_key_file_set_string(keyfile, service->identifier,
1155 "PrivateKeyFile", service->private_key_file);
1157 g_key_file_remove_key(keyfile, service->identifier,
1158 "PrivateKeyFile", NULL);
1160 if (service->private_key_passphrase != NULL && strlen(service->private_key_passphrase) > 0)
1161 g_key_file_set_string(keyfile, service->identifier,
1162 "PrivateKeyPassphrase", service->private_key_passphrase);
1164 g_key_file_remove_key(keyfile, service->identifier,
1165 "PrivateKeyPassphrase", NULL);
1170 __connman_storage_save_service(keyfile, service->identifier);
1172 g_key_file_free(keyfile);
1177 void __connman_service_save(struct connman_service *service)
1182 service_save(service);
1185 static enum connman_service_state combine_state(
1186 enum connman_service_state state_a,
1187 enum connman_service_state state_b)
1189 enum connman_service_state result;
1191 if (state_a == state_b) {
1196 if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
1201 if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
1206 if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
1211 if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
1216 if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
1221 if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
1226 if (state_a == CONNMAN_SERVICE_STATE_READY) {
1231 if (state_b == CONNMAN_SERVICE_STATE_READY) {
1236 if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1241 if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1246 if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1251 if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1256 if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
1261 if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
1266 result = CONNMAN_SERVICE_STATE_FAILURE;
1272 static bool is_connecting(enum connman_service_state state)
1275 case CONNMAN_SERVICE_STATE_UNKNOWN:
1276 case CONNMAN_SERVICE_STATE_IDLE:
1277 case CONNMAN_SERVICE_STATE_FAILURE:
1278 case CONNMAN_SERVICE_STATE_DISCONNECT:
1279 case CONNMAN_SERVICE_STATE_READY:
1280 case CONNMAN_SERVICE_STATE_ONLINE:
1282 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1283 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1290 static bool is_connected(enum connman_service_state state)
1293 case CONNMAN_SERVICE_STATE_UNKNOWN:
1294 case CONNMAN_SERVICE_STATE_IDLE:
1295 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1296 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1297 case CONNMAN_SERVICE_STATE_DISCONNECT:
1298 case CONNMAN_SERVICE_STATE_FAILURE:
1300 case CONNMAN_SERVICE_STATE_READY:
1301 case CONNMAN_SERVICE_STATE_ONLINE:
1308 static bool is_idle(enum connman_service_state state)
1311 case CONNMAN_SERVICE_STATE_IDLE:
1312 case CONNMAN_SERVICE_STATE_DISCONNECT:
1313 case CONNMAN_SERVICE_STATE_FAILURE:
1315 case CONNMAN_SERVICE_STATE_UNKNOWN:
1316 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1317 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1318 case CONNMAN_SERVICE_STATE_READY:
1319 case CONNMAN_SERVICE_STATE_ONLINE:
1326 static int nameservers_changed_cb(void *user_data)
1328 struct connman_service *service = user_data;
1330 DBG("service %p", service);
1332 service->nameservers_timeout = 0;
1333 if ((is_idle(service->state) && !service->nameservers) ||
1334 is_connected(service->state))
1335 dns_changed(service);
1340 static void nameservers_changed(struct connman_service *service)
1342 if (!service->nameservers_timeout)
1343 service->nameservers_timeout = g_idle_add(nameservers_changed_cb,
1347 static bool nameserver_available(struct connman_service *service,
1348 enum connman_ipconfig_type type,
1353 family = connman_inet_check_ipaddress(ns);
1355 if (family == AF_INET) {
1356 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1359 return is_connected(service->state_ipv4);
1362 if (family == AF_INET6) {
1363 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1366 return is_connected(service->state_ipv6);
1372 static int searchdomain_add_all(struct connman_service *service)
1376 if (!is_connected(service->state))
1379 index = __connman_service_get_index(service);
1383 if (service->domains) {
1384 while (service->domains[i]) {
1385 connman_resolver_append(index, service->domains[i],
1393 if (service->domainname)
1394 connman_resolver_append(index, service->domainname, NULL);
1400 static int searchdomain_remove_all(struct connman_service *service)
1404 if (!is_connected(service->state))
1407 index = __connman_service_get_index(service);
1411 while (service->domains && service->domains[i]) {
1412 connman_resolver_remove(index, service->domains[i], NULL);
1416 if (service->domainname)
1417 connman_resolver_remove(index, service->domainname, NULL);
1422 static int nameserver_add(struct connman_service *service,
1423 enum connman_ipconfig_type type,
1424 const char *nameserver)
1428 if (!nameserver_available(service, type, nameserver))
1431 index = __connman_service_get_index(service);
1435 #if defined TIZEN_EXT
1436 DBG("Resolver append nameserver: %s", nameserver);
1438 ret = connman_resolver_append(index, NULL, nameserver);
1440 nameservers_changed(service);
1445 static int nameserver_add_all(struct connman_service *service,
1446 enum connman_ipconfig_type type)
1450 if (service->nameservers_config) {
1451 while (service->nameservers_config[i]) {
1452 #if defined TIZEN_EXT
1453 DBG("type %d add service->nameservers_config[%d]:%s",type,
1454 i, service->nameservers_config[i]);
1455 if(strncmp(service->nameservers_config[i], "::", 2) == 0) {
1456 DBG("Invalid nameserver");
1462 case CONNMAN_IPCONFIG_TYPE_IPV4:
1463 if (connman_inet_check_ipaddress(
1464 service->nameservers_config[i]) == AF_INET &&
1465 service->dns_config_method_ipv4 ==
1466 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1467 nameserver_add(service, type,
1468 service->nameservers_config[i]);
1471 case CONNMAN_IPCONFIG_TYPE_IPV6:
1472 if (connman_inet_check_ipaddress(
1473 service->nameservers_config[i]) == AF_INET6 &&
1474 service->dns_config_method_ipv6 ==
1475 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1476 nameserver_add(service, type,
1477 service->nameservers_config[i]);
1480 case CONNMAN_IPCONFIG_TYPE_ALL:
1481 if (connman_inet_check_ipaddress(
1482 service->nameservers_config[i]) == AF_INET &&
1483 service->dns_config_method_ipv4 ==
1484 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1485 nameserver_add(service, type,
1486 service->nameservers_config[i]);
1488 if (connman_inet_check_ipaddress(
1489 service->nameservers_config[i]) == AF_INET6 &&
1490 service->dns_config_method_ipv6 ==
1491 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1492 nameserver_add(service, type,
1493 service->nameservers_config[i]);
1496 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1497 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1500 DBG("default case do nothing");
1504 nameserver_add(service, type,
1505 service->nameservers_config[i]);
1509 } else if (service->nameservers) {
1510 while (service->nameservers[i]) {
1511 #if defined TIZEN_EXT
1512 DBG("type %d service->nameservers[%d]: %s",type,
1513 i, service->nameservers[i]);
1516 case CONNMAN_IPCONFIG_TYPE_IPV4:
1517 if (connman_inet_check_ipaddress(
1518 service->nameservers[i]) == AF_INET &&
1519 service->dns_config_method_ipv4 ==
1520 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1521 nameserver_add(service, type,
1522 service->nameservers[i]);
1525 case CONNMAN_IPCONFIG_TYPE_IPV6:
1526 if (connman_inet_check_ipaddress(
1527 service->nameservers[i]) == AF_INET6 &&
1528 service->dns_config_method_ipv6 ==
1529 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1530 nameserver_add(service, type,
1531 service->nameservers[i]);
1534 case CONNMAN_IPCONFIG_TYPE_ALL:
1535 if (connman_inet_check_ipaddress(
1536 service->nameservers[i]) == AF_INET &&
1537 service->dns_config_method_ipv4 ==
1538 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1539 nameserver_add(service, type,
1540 service->nameservers[i]);
1542 if (connman_inet_check_ipaddress(
1543 service->nameservers[i]) == AF_INET6 &&
1544 service->dns_config_method_ipv6 ==
1545 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1546 nameserver_add(service, type,
1547 service->nameservers[i]);
1550 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1551 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1554 DBG("default case do nothing");
1558 nameserver_add(service, type,
1559 service->nameservers[i]);
1566 __connman_resolver_append_fallback_nameservers();
1568 searchdomain_add_all(service);
1573 static int nameserver_remove(struct connman_service *service,
1574 enum connman_ipconfig_type type,
1575 const char *nameserver)
1579 if (!nameserver_available(service, type, nameserver))
1582 index = __connman_service_get_index(service);
1586 #if defined TIZEN_EXT
1587 DBG("Resolver remove nameserver: %s", nameserver);
1589 ret = connman_resolver_remove(index, NULL, nameserver);
1591 nameservers_changed(service);
1596 static int nameserver_remove_all(struct connman_service *service,
1597 enum connman_ipconfig_type type)
1599 #if defined TIZEN_EXT
1601 * Skip this function if there is any connected profiles
1602 * that use same interface
1604 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
1605 __connman_service_get_connected_count_of_iface(service) > 0)
1610 index = __connman_service_get_index(service);
1614 while (service->nameservers_config && service->nameservers_config[i]) {
1615 #if defined TIZEN_EXT
1616 DBG("type %d Remove service->nameservers_config[%d]: %s",
1617 type, i, service->nameservers_config[i]);
1619 case CONNMAN_IPCONFIG_TYPE_IPV4:
1620 if (connman_inet_check_ipaddress(
1621 service->nameservers_config[i]) == AF_INET &&
1622 (service->dns_config_method_ipv4 ==
1623 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1624 service->dns_config_method_ipv4 ==
1625 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1626 nameserver_remove(service, type,
1627 service->nameservers_config[i]);
1630 case CONNMAN_IPCONFIG_TYPE_IPV6:
1631 if (connman_inet_check_ipaddress(
1632 service->nameservers_config[i]) == AF_INET6 &&
1633 (service->dns_config_method_ipv6 ==
1634 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1635 service->dns_config_method_ipv6 ==
1636 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1637 nameserver_remove(service, type,
1638 service->nameservers_config[i]);
1641 case CONNMAN_IPCONFIG_TYPE_ALL:
1642 if (connman_inet_check_ipaddress(
1643 service->nameservers_config[i]) == AF_INET &&
1644 (service->dns_config_method_ipv4 ==
1645 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1646 service->dns_config_method_ipv4 ==
1647 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1648 nameserver_remove(service, type,
1649 service->nameservers_config[i]);
1651 if (connman_inet_check_ipaddress(
1652 service->nameservers_config[i]) == AF_INET6 &&
1653 (service->dns_config_method_ipv6 ==
1654 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1655 service->dns_config_method_ipv6 ==
1656 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1657 nameserver_remove(service, type,
1658 service->nameservers_config[i]);
1661 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1662 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1665 DBG("default case do nothing");
1669 nameserver_remove(service, type,
1670 service->nameservers_config[i]);
1676 while (service->nameservers && service->nameservers[i]) {
1677 #if defined TIZEN_EXT
1678 DBG("type %d Remove service->nameservers[%d]: %s",type, i,
1679 service->nameservers[i]);
1681 case CONNMAN_IPCONFIG_TYPE_IPV4:
1682 if (connman_inet_check_ipaddress(
1683 service->nameservers[i]) == AF_INET &&
1684 (service->dns_config_method_ipv4 ==
1685 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1686 service->dns_config_method_ipv4 ==
1687 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1688 nameserver_remove(service, type,
1689 service->nameservers[i]);
1692 case CONNMAN_IPCONFIG_TYPE_IPV6:
1693 if (connman_inet_check_ipaddress(
1694 service->nameservers[i]) == AF_INET6 &&
1695 (service->dns_config_method_ipv6 ==
1696 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1697 service->dns_config_method_ipv6 ==
1698 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1699 nameserver_remove(service, type,
1700 service->nameservers[i]);
1703 case CONNMAN_IPCONFIG_TYPE_ALL:
1704 if (connman_inet_check_ipaddress(
1705 service->nameservers[i]) == AF_INET &&
1706 (service->dns_config_method_ipv4 ==
1707 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1708 service->dns_config_method_ipv4 ==
1709 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1710 nameserver_remove(service, type,
1711 service->nameservers[i]);
1713 if (connman_inet_check_ipaddress(
1714 service->nameservers[i]) == AF_INET6 &&
1715 (service->dns_config_method_ipv6 ==
1716 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1717 service->dns_config_method_ipv6 ==
1718 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1719 nameserver_remove(service, type,
1720 service->nameservers[i]);
1723 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1724 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1727 DBG("default case do nothing");
1731 nameserver_remove(service, type, service->nameservers[i]);
1736 searchdomain_remove_all(service);
1742 * The is_auto variable is set to true when IPv6 autoconf nameservers are
1743 * inserted to resolver via netlink message (see rtnl.c:rtnl_newnduseropt()
1744 * for details) and not through service.c
1746 #if defined TIZEN_EXT
1747 int __connman_service_nameserver_append(struct connman_service *service,
1748 const char *nameserver, bool is_auto,
1749 enum connman_ipconfig_type type)
1751 int __connman_service_nameserver_append(struct connman_service *service,
1752 const char *nameserver, bool is_auto)
1758 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1764 nameservers = service->nameservers_auto;
1766 nameservers = service->nameservers;
1768 for (i = 0; nameservers && nameservers[i]; i++)
1769 #if defined TIZEN_EXT
1771 DBG("nameservers[%d] %s, nameserver %s", i, nameservers[i], nameserver);
1773 if (g_strcmp0(nameservers[i], nameserver) == 0)
1775 #if defined TIZEN_EXT
1780 len = g_strv_length(nameservers);
1781 nameservers = g_try_renew(char *, nameservers, len + 2);
1784 nameservers = g_try_new0(char *, len + 2);
1790 nameservers[len] = g_strdup(nameserver);
1791 nameservers[len + 1] = NULL;
1794 if(type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
1795 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
1796 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
1798 if(type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
1799 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
1800 service->dns_config_method_ipv6 = CONNMAN_DNSCONFIG_METHOD_DHCP;
1804 service->nameservers_auto = nameservers;
1806 service->nameservers = nameservers;
1807 nameserver_add(service, CONNMAN_IPCONFIG_TYPE_ALL, nameserver);
1810 nameservers_changed(service);
1812 searchdomain_add_all(service);
1817 #if defined TIZEN_EXT
1818 int __connman_service_nameserver_remove(struct connman_service *service,
1819 const char *nameserver, bool is_auto,
1820 enum connman_ipconfig_type type)
1822 int __connman_service_nameserver_remove(struct connman_service *service,
1823 const char *nameserver, bool is_auto)
1826 char **servers, **nameservers;
1830 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1836 nameservers = service->nameservers_auto;
1838 nameservers = service->nameservers;
1843 for (i = 0; nameservers[i]; i++)
1844 if (g_strcmp0(nameservers[i], nameserver) == 0) {
1852 len = g_strv_length(nameservers);
1859 servers = g_try_new0(char *, len);
1863 for (i = 0, j = 0; i < len; i++) {
1864 if (g_strcmp0(nameservers[i], nameserver)) {
1865 servers[j] = nameservers[i];
1868 g_free(nameservers[i]);
1870 nameservers[i] = NULL;
1872 servers[len - 1] = NULL;
1875 g_strfreev(nameservers);
1876 nameservers = servers;
1879 service->nameservers_auto = nameservers;
1881 service->nameservers = nameservers;
1882 #if defined TIZEN_EXT
1883 DBG("nameserver remove ip_type: %d", type);
1884 nameserver_remove(service, type,
1887 nameserver_remove(service, CONNMAN_IPCONFIG_TYPE_ALL,
1895 void __connman_service_nameserver_clear(struct connman_service *service)
1897 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
1899 g_strfreev(service->nameservers);
1900 service->nameservers = NULL;
1902 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
1905 static void add_nameserver_route(int family, int index, char *nameserver,
1910 if (connman_inet_compare_subnet(index, nameserver))
1913 if (connman_inet_add_host_route(index, nameserver, gw) < 0)
1914 /* For P-t-P link the above route add will fail */
1915 connman_inet_add_host_route(index, nameserver, NULL);
1919 if (connman_inet_add_ipv6_host_route(index, nameserver,
1921 connman_inet_add_ipv6_host_route(index, nameserver,
1927 static void nameserver_add_routes(int index, char **nameservers,
1930 int i, ns_family, gw_family;
1932 gw_family = connman_inet_check_ipaddress(gw);
1936 for (i = 0; nameservers[i]; i++) {
1937 ns_family = connman_inet_check_ipaddress(nameservers[i]);
1938 if (ns_family < 0 || ns_family != gw_family)
1941 add_nameserver_route(ns_family, index, nameservers[i], gw);
1945 static void nameserver_del_routes(int index, char **nameservers,
1946 enum connman_ipconfig_type type)
1950 for (i = 0; nameservers[i]; i++) {
1951 family = connman_inet_check_ipaddress(nameservers[i]);
1957 if (type != CONNMAN_IPCONFIG_TYPE_IPV6)
1958 connman_inet_del_host_route(index,
1962 if (type != CONNMAN_IPCONFIG_TYPE_IPV4)
1963 connman_inet_del_ipv6_host_route(index,
1970 void __connman_service_nameserver_add_routes(struct connman_service *service,
1978 index = __connman_service_get_index(service);
1980 if (service->nameservers_config) {
1982 * Configured nameserver takes preference over the
1983 * discoverd nameserver gathered from DHCP, VPN, etc.
1985 nameserver_add_routes(index, service->nameservers_config, gw);
1986 } else if (service->nameservers) {
1988 * We add nameservers host routes for nameservers that
1989 * are not on our subnet. For those who are, the subnet
1990 * route will be installed by the time the dns proxy code
1991 * tries to reach them. The subnet route is installed
1992 * when setting the interface IP address.
1994 nameserver_add_routes(index, service->nameservers, gw);
1998 void __connman_service_nameserver_del_routes(struct connman_service *service,
1999 enum connman_ipconfig_type type)
2006 index = __connman_service_get_index(service);
2008 if (service->nameservers_config)
2009 nameserver_del_routes(index, service->nameservers_config,
2011 else if (service->nameservers)
2012 nameserver_del_routes(index, service->nameservers, type);
2015 static void address_updated(struct connman_service *service,
2016 enum connman_ipconfig_type type)
2018 if (is_connected(service->state) &&
2019 service == __connman_service_get_default()) {
2020 nameserver_remove_all(service, type);
2021 nameserver_add_all(service, type);
2023 __connman_timeserver_sync(service);
2027 static struct connman_stats *stats_get(struct connman_service *service)
2029 if (service->roaming)
2030 return &service->stats_roaming;
2032 return &service->stats;
2035 static bool stats_enabled(struct connman_service *service)
2037 struct connman_stats *stats = stats_get(service);
2039 return stats->enabled;
2042 static void stats_start(struct connman_service *service)
2044 struct connman_stats *stats = stats_get(service);
2046 DBG("service %p", service);
2051 stats->enabled = true;
2052 stats->data_last.time = stats->data.time;
2054 g_timer_start(stats->timer);
2057 static void stats_stop(struct connman_service *service)
2059 struct connman_stats *stats = stats_get(service);
2060 unsigned int seconds;
2062 DBG("service %p", service);
2067 if (!stats->enabled)
2070 g_timer_stop(stats->timer);
2072 seconds = g_timer_elapsed(stats->timer, NULL);
2073 stats->data.time = stats->data_last.time + seconds;
2075 stats->enabled = false;
2078 static void reset_stats(struct connman_service *service)
2080 DBG("service %p", service);
2083 service->stats.valid = false;
2085 service->stats.data.rx_packets = 0;
2086 service->stats.data.tx_packets = 0;
2087 service->stats.data.rx_bytes = 0;
2088 service->stats.data.tx_bytes = 0;
2089 service->stats.data.rx_errors = 0;
2090 service->stats.data.tx_errors = 0;
2091 service->stats.data.rx_dropped = 0;
2092 service->stats.data.tx_dropped = 0;
2093 service->stats.data.time = 0;
2094 service->stats.data_last.time = 0;
2096 g_timer_reset(service->stats.timer);
2099 service->stats_roaming.valid = false;
2101 service->stats_roaming.data.rx_packets = 0;
2102 service->stats_roaming.data.tx_packets = 0;
2103 service->stats_roaming.data.rx_bytes = 0;
2104 service->stats_roaming.data.tx_bytes = 0;
2105 service->stats_roaming.data.rx_errors = 0;
2106 service->stats_roaming.data.tx_errors = 0;
2107 service->stats_roaming.data.rx_dropped = 0;
2108 service->stats_roaming.data.tx_dropped = 0;
2109 service->stats_roaming.data.time = 0;
2110 service->stats_roaming.data_last.time = 0;
2112 g_timer_reset(service->stats_roaming.timer);
2115 #if defined TIZEN_EXT
2116 static gboolean __connman_service_is_internet_profile(
2117 struct connman_service *cellular)
2119 const char internet_suffix[] = "_1";
2121 DBG("Service path: %s", cellular->path);
2123 if (g_str_has_suffix(cellular->path, internet_suffix) == TRUE)
2129 static gboolean __connman_service_is_tethering_profile(
2130 struct connman_service *cellular)
2132 const char tethering_suffix[] = "_5";
2134 DBG("Service path: %s", cellular->path);
2136 if (g_str_has_suffix(cellular->path, tethering_suffix) == TRUE)
2142 struct connman_service *connman_service_get_default_connection(void)
2145 struct connman_service *service;
2146 struct connman_service *default_service = NULL;
2148 for (list = service_list; list; list = list->next) {
2149 service = list->data;
2151 DBG("service: %p %s %s %s", service, service->name,
2152 state2string(service->state),
2153 __connman_service_type2string(service->type));
2155 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
2156 is_connected(service->state) == TRUE) {
2158 } else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
2159 __connman_service_is_internet_profile(service) == TRUE) {
2160 if (default_service == NULL)
2161 default_service = service;
2162 else if (is_connected(service->state) == TRUE &&
2163 is_connected(default_service->state) == FALSE)
2164 default_service = service;
2165 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET &&
2166 is_connected(service->state) == TRUE) {
2167 if (default_service == NULL)
2168 default_service = service;
2169 } else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH &&
2170 is_connected(service->state) == TRUE) {
2171 if (default_service == NULL)
2172 default_service = service;
2176 return default_service;
2180 struct connman_service *__connman_service_get_default(void)
2182 struct connman_service *service;
2187 service = service_list->data;
2189 if (!is_connected(service->state))
2195 bool __connman_service_index_is_default(int index)
2197 struct connman_service *service;
2202 service = __connman_service_get_default();
2204 return __connman_service_get_index(service) == index;
2207 static void default_changed(void)
2209 struct connman_service *service = __connman_service_get_default();
2211 if (service == current_default)
2214 DBG("current default %p %s", current_default,
2215 current_default ? current_default->identifier : "");
2216 DBG("new default %p %s", service, service ? service->identifier : "");
2218 #if defined TIZEN_EXT
2219 current_default = service;
2221 __connman_service_timeserver_changed(service, NULL);
2223 __connman_service_timeserver_changed(current_default, NULL);
2225 current_default = service;
2229 if (service->hostname &&
2230 connman_setting_get_bool("AllowHostnameUpdates"))
2231 __connman_utsname_set_hostname(service->hostname);
2233 if (service->domainname)
2234 __connman_utsname_set_domainname(service->domainname);
2237 __connman_notifier_default_changed(service);
2240 static void state_changed(struct connman_service *service)
2244 __connman_notifier_service_state_changed(service, service->state);
2246 str = state2string(service->state);
2250 #if !defined TIZEN_EXT
2251 if (!allow_property_changed(service))
2254 #if defined TIZEN_EXT
2255 DBG(" %s, %s", str, service->path);
2257 connman_dbus_property_changed_basic(service->path,
2258 CONNMAN_SERVICE_INTERFACE, "State",
2259 DBUS_TYPE_STRING, &str);
2262 static void strength_changed(struct connman_service *service)
2264 if (service->strength == 0)
2267 if (!allow_property_changed(service))
2270 connman_dbus_property_changed_basic(service->path,
2271 CONNMAN_SERVICE_INTERFACE, "Strength",
2272 DBUS_TYPE_BYTE, &service->strength);
2275 static void favorite_changed(struct connman_service *service)
2277 dbus_bool_t favorite;
2282 if (!allow_property_changed(service))
2285 favorite = service->favorite;
2286 connman_dbus_property_changed_basic(service->path,
2287 CONNMAN_SERVICE_INTERFACE, "Favorite",
2288 DBUS_TYPE_BOOLEAN, &favorite);
2291 static void immutable_changed(struct connman_service *service)
2293 dbus_bool_t immutable;
2298 if (!allow_property_changed(service))
2301 immutable = service->immutable;
2302 connman_dbus_property_changed_basic(service->path,
2303 CONNMAN_SERVICE_INTERFACE, "Immutable",
2304 DBUS_TYPE_BOOLEAN, &immutable);
2307 static void roaming_changed(struct connman_service *service)
2309 dbus_bool_t roaming;
2314 if (!allow_property_changed(service))
2317 roaming = service->roaming;
2318 connman_dbus_property_changed_basic(service->path,
2319 CONNMAN_SERVICE_INTERFACE, "Roaming",
2320 DBUS_TYPE_BOOLEAN, &roaming);
2323 static void autoconnect_changed(struct connman_service *service)
2325 dbus_bool_t autoconnect;
2330 if (!allow_property_changed(service))
2333 autoconnect = service->autoconnect;
2334 connman_dbus_property_changed_basic(service->path,
2335 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
2336 DBUS_TYPE_BOOLEAN, &autoconnect);
2339 static void append_security(DBusMessageIter *iter, void *user_data)
2341 struct connman_service *service = user_data;
2344 str = security2string(service->security);
2346 dbus_message_iter_append_basic(iter,
2347 DBUS_TYPE_STRING, &str);
2350 * Some access points incorrectly advertise WPS even when they
2351 * are configured as open or no security, so filter
2355 switch (service->security) {
2356 case CONNMAN_SERVICE_SECURITY_PSK:
2357 case CONNMAN_SERVICE_SECURITY_WPA:
2358 case CONNMAN_SERVICE_SECURITY_RSN:
2360 dbus_message_iter_append_basic(iter,
2361 DBUS_TYPE_STRING, &str);
2363 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
2364 case CONNMAN_SERVICE_SECURITY_NONE:
2365 case CONNMAN_SERVICE_SECURITY_WEP:
2366 case CONNMAN_SERVICE_SECURITY_8021X:
2372 static void append_ethernet(DBusMessageIter *iter, void *user_data)
2374 struct connman_service *service = user_data;
2376 if (service->ipconfig_ipv4)
2377 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
2379 else if (service->ipconfig_ipv6)
2380 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
2384 static void append_ipv4(DBusMessageIter *iter, void *user_data)
2386 struct connman_service *service = user_data;
2388 if (!is_connected(service->state_ipv4))
2391 if (service->ipconfig_ipv4)
2392 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
2395 static void append_ipv6(DBusMessageIter *iter, void *user_data)
2397 struct connman_service *service = user_data;
2399 if (!is_connected(service->state_ipv6))
2402 if (service->ipconfig_ipv6)
2403 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
2404 service->ipconfig_ipv4);
2407 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
2409 struct connman_service *service = user_data;
2411 if (service->ipconfig_ipv4)
2412 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
2416 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
2418 struct connman_service *service = user_data;
2420 if (service->ipconfig_ipv6)
2421 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
2425 static void append_nameservers(DBusMessageIter *iter,
2426 struct connman_service *service, char **servers)
2429 bool available = true;
2431 for (i = 0; servers[i]; i++) {
2433 available = nameserver_available(service,
2434 CONNMAN_IPCONFIG_TYPE_ALL,
2438 dbus_message_iter_append_basic(iter,
2439 DBUS_TYPE_STRING, &servers[i]);
2443 #if defined TIZEN_EXT
2444 static void append_nameserver_manual(DBusMessageIter *iter,
2445 struct connman_service *service, const char *server)
2447 bool available = true;
2450 available = nameserver_available(service,
2451 CONNMAN_IPCONFIG_TYPE_ALL, server);
2454 dbus_message_iter_append_basic(iter,
2455 DBUS_TYPE_STRING, &server);
2458 static void append_nameserver_dhcp(DBusMessageIter *iter,
2459 struct connman_service *service, const char *server)
2461 bool available = true;
2464 available = nameserver_available(service,
2465 CONNMAN_IPCONFIG_TYPE_ALL, server);
2468 dbus_message_iter_append_basic(iter,
2469 DBUS_TYPE_STRING, &server);
2473 static void append_dns(DBusMessageIter *iter, void *user_data)
2475 struct connman_service *service = user_data;
2476 #if defined TIZEN_EXT
2480 if (!is_connected(service->state))
2486 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
2488 char *str1 = g_strdup_printf("ipv4.%s", str);
2489 dbus_message_iter_append_basic(iter,
2490 DBUS_TYPE_STRING, &str1);
2494 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
2496 char *str1 = g_strdup_printf("ipv6.%s", str);
2497 dbus_message_iter_append_basic(iter,
2498 DBUS_TYPE_STRING, &str1);
2503 if (service->nameservers_config) {
2504 #if defined TIZEN_EXT
2506 while (service->nameservers_config[i]) {
2507 if (connman_inet_check_ipaddress(
2508 service->nameservers_config[i]) == AF_INET &&
2509 service->dns_config_method_ipv4 ==
2510 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2511 append_nameserver_manual(iter, service,
2512 service->nameservers_config[i]);
2515 if (connman_inet_check_ipaddress(
2516 service->nameservers_config[i]) == AF_INET6 &&
2517 service->dns_config_method_ipv6 ==
2518 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2519 append_nameserver_manual(iter, service,
2520 service->nameservers_config[i]);
2524 /* In case of mixed DNS Config Type one of IPv4/IPv6 can be
2525 * dynamic while other is static so try to append the DNS
2526 * Address which is dynamic also */
2527 if (service->nameservers != NULL) {
2529 while (service->nameservers[i]) {
2530 if (connman_inet_check_ipaddress(
2531 service->nameservers[i]) == AF_INET &&
2532 service->dns_config_method_ipv4 ==
2533 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2534 append_nameserver_dhcp(iter, service,
2535 service->nameservers[i]);
2538 if (connman_inet_check_ipaddress(
2539 service->nameservers[i]) == AF_INET6 &&
2540 service->dns_config_method_ipv6 ==
2541 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2542 append_nameserver_dhcp(iter, service,
2543 service->nameservers[i]);
2549 append_nameservers(iter, service, service->nameservers_config);
2553 if (service->nameservers)
2554 #if defined TIZEN_EXT
2557 while (service->nameservers[i]) {
2558 if (connman_inet_check_ipaddress(
2559 service->nameservers[i]) == AF_INET &&
2560 service->dns_config_method_ipv4 ==
2561 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2562 append_nameserver_dhcp(iter, service,
2563 service->nameservers[i]);
2566 if (connman_inet_check_ipaddress(
2567 service->nameservers[i]) == AF_INET6 &&
2568 service->dns_config_method_ipv6 ==
2569 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2570 append_nameserver_dhcp(iter, service,
2571 service->nameservers[i]);
2577 append_nameservers(iter, service,
2578 service->nameservers);
2581 if (service->nameservers_auto)
2582 append_nameservers(iter, service,
2583 service->nameservers_auto);
2585 if (!service->nameservers && !service->nameservers_auto) {
2588 DBG("append fallback nameservers");
2590 ns = connman_setting_get_string_list("FallbackNameservers");
2592 append_nameservers(iter, service, ns);
2597 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
2599 struct connman_service *service = user_data;
2602 /* Append DNS Config Type */
2604 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
2606 char *str1 = g_strdup_printf("ipv4.%s", str);
2607 dbus_message_iter_append_basic(iter,
2608 DBUS_TYPE_STRING, &str1);
2612 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
2614 char *str1 = g_strdup_printf("ipv6.%s", str);
2615 dbus_message_iter_append_basic(iter,
2616 DBUS_TYPE_STRING, &str1);
2621 if (!service->nameservers_config)
2624 #if defined TIZEN_EXT
2626 while (service->nameservers_config[i]) {
2627 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET &&
2628 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2629 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
2632 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET6 &&
2633 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2634 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
2639 append_nameservers(iter, NULL, service->nameservers_config);
2643 static void append_ts(DBusMessageIter *iter, void *user_data)
2645 GSList *list = user_data;
2648 char *timeserver = list->data;
2651 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
2654 list = g_slist_next(list);
2658 static void append_tsconfig(DBusMessageIter *iter, void *user_data)
2660 struct connman_service *service = user_data;
2663 if (!service->timeservers_config)
2666 for (i = 0; service->timeservers_config[i]; i++) {
2667 dbus_message_iter_append_basic(iter,
2669 &service->timeservers_config[i]);
2673 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
2675 struct connman_service *service = user_data;
2678 if (!service->domains)
2681 for (i = 0; service->domains[i]; i++)
2682 dbus_message_iter_append_basic(iter,
2683 DBUS_TYPE_STRING, &service->domains[i]);
2686 static void append_domain(DBusMessageIter *iter, void *user_data)
2688 struct connman_service *service = user_data;
2690 if (!is_connected(service->state) &&
2691 !is_connecting(service->state))
2694 if (service->domains)
2695 append_domainconfig(iter, user_data);
2696 else if (service->domainname)
2697 dbus_message_iter_append_basic(iter,
2698 DBUS_TYPE_STRING, &service->domainname);
2701 static void append_proxies(DBusMessageIter *iter, void *user_data)
2703 struct connman_service *service = user_data;
2706 if (!service->proxies)
2709 for (i = 0; service->proxies[i]; i++)
2710 dbus_message_iter_append_basic(iter,
2711 DBUS_TYPE_STRING, &service->proxies[i]);
2714 static void append_excludes(DBusMessageIter *iter, void *user_data)
2716 struct connman_service *service = user_data;
2719 if (!service->excludes)
2722 for (i = 0; service->excludes[i]; i++)
2723 dbus_message_iter_append_basic(iter,
2724 DBUS_TYPE_STRING, &service->excludes[i]);
2727 static void append_proxy(DBusMessageIter *iter, void *user_data)
2729 struct connman_service *service = user_data;
2730 enum connman_service_proxy_method proxy;
2731 const char *pac = NULL;
2732 const char *method = proxymethod2string(
2733 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
2735 if (!is_connected(service->state))
2738 proxy = connman_service_get_proxy_method(service);
2741 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2743 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2745 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2746 connman_dbus_dict_append_array(iter, "Servers",
2747 DBUS_TYPE_STRING, append_proxies,
2750 connman_dbus_dict_append_array(iter, "Excludes",
2751 DBUS_TYPE_STRING, append_excludes,
2754 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2755 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
2756 if (service->ipconfig_ipv4)
2757 pac = __connman_ipconfig_get_proxy_autoconfig(
2758 service->ipconfig_ipv4);
2759 else if (service->ipconfig_ipv6)
2760 pac = __connman_ipconfig_get_proxy_autoconfig(
2761 service->ipconfig_ipv6);
2763 if (!service->pac && !pac)
2769 connman_dbus_dict_append_basic(iter, "URL",
2770 DBUS_TYPE_STRING, &pac);
2774 method = proxymethod2string(proxy);
2777 connman_dbus_dict_append_basic(iter, "Method",
2778 DBUS_TYPE_STRING, &method);
2781 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
2783 struct connman_service *service = user_data;
2786 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
2789 switch (service->proxy_config) {
2790 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2792 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2794 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2795 if (service->proxies)
2796 connman_dbus_dict_append_array(iter, "Servers",
2798 append_proxies, service);
2800 if (service->excludes)
2801 connman_dbus_dict_append_array(iter, "Excludes",
2803 append_excludes, service);
2805 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2807 connman_dbus_dict_append_basic(iter, "URL",
2808 DBUS_TYPE_STRING, &service->pac);
2812 method = proxymethod2string(service->proxy_config);
2814 connman_dbus_dict_append_basic(iter, "Method",
2815 DBUS_TYPE_STRING, &method);
2818 static void append_provider(DBusMessageIter *iter, void *user_data)
2820 struct connman_service *service = user_data;
2822 if (!is_connected(service->state))
2825 if (service->provider)
2826 __connman_provider_append_properties(service->provider, iter);
2830 static void settings_changed(struct connman_service *service,
2831 struct connman_ipconfig *ipconfig)
2833 enum connman_ipconfig_type type;
2835 type = __connman_ipconfig_get_config_type(ipconfig);
2837 __connman_notifier_ipconfig_changed(service, ipconfig);
2839 if (!allow_property_changed(service))
2842 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
2843 connman_dbus_property_changed_dict(service->path,
2844 CONNMAN_SERVICE_INTERFACE, "IPv4",
2845 append_ipv4, service);
2846 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2847 connman_dbus_property_changed_dict(service->path,
2848 CONNMAN_SERVICE_INTERFACE, "IPv6",
2849 append_ipv6, service);
2852 static void ipv4_configuration_changed(struct connman_service *service)
2854 if (!allow_property_changed(service))
2857 connman_dbus_property_changed_dict(service->path,
2858 CONNMAN_SERVICE_INTERFACE,
2859 "IPv4.Configuration",
2864 void __connman_service_notify_ipv4_configuration(
2865 struct connman_service *service)
2870 ipv4_configuration_changed(service);
2873 static void ipv6_configuration_changed(struct connman_service *service)
2875 if (!allow_property_changed(service))
2878 connman_dbus_property_changed_dict(service->path,
2879 CONNMAN_SERVICE_INTERFACE,
2880 "IPv6.Configuration",
2885 static void dns_changed(struct connman_service *service)
2887 if (!allow_property_changed(service))
2890 connman_dbus_property_changed_array(service->path,
2891 CONNMAN_SERVICE_INTERFACE, "Nameservers",
2892 DBUS_TYPE_STRING, append_dns, service);
2895 static void dns_configuration_changed(struct connman_service *service)
2897 if (!allow_property_changed(service))
2900 connman_dbus_property_changed_array(service->path,
2901 CONNMAN_SERVICE_INTERFACE,
2902 "Nameservers.Configuration",
2903 DBUS_TYPE_STRING, append_dnsconfig, service);
2905 dns_changed(service);
2908 static void domain_changed(struct connman_service *service)
2910 if (!allow_property_changed(service))
2913 connman_dbus_property_changed_array(service->path,
2914 CONNMAN_SERVICE_INTERFACE, "Domains",
2915 DBUS_TYPE_STRING, append_domain, service);
2918 static void domain_configuration_changed(struct connman_service *service)
2920 if (!allow_property_changed(service))
2923 connman_dbus_property_changed_array(service->path,
2924 CONNMAN_SERVICE_INTERFACE,
2925 "Domains.Configuration",
2926 DBUS_TYPE_STRING, append_domainconfig, service);
2929 static void proxy_changed(struct connman_service *service)
2931 if (!allow_property_changed(service))
2934 connman_dbus_property_changed_dict(service->path,
2935 CONNMAN_SERVICE_INTERFACE, "Proxy",
2936 append_proxy, service);
2939 static void proxy_configuration_changed(struct connman_service *service)
2941 if (!allow_property_changed(service))
2944 connman_dbus_property_changed_dict(service->path,
2945 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
2946 append_proxyconfig, service);
2948 proxy_changed(service);
2951 static void timeservers_configuration_changed(struct connman_service *service)
2953 if (!allow_property_changed(service))
2956 connman_dbus_property_changed_array(service->path,
2957 CONNMAN_SERVICE_INTERFACE,
2958 "Timeservers.Configuration",
2960 append_tsconfig, service);
2963 static void link_changed(struct connman_service *service)
2965 if (!allow_property_changed(service))
2968 connman_dbus_property_changed_dict(service->path,
2969 CONNMAN_SERVICE_INTERFACE, "Ethernet",
2970 append_ethernet, service);
2973 static void stats_append_counters(DBusMessageIter *dict,
2974 struct connman_stats_data *stats,
2975 struct connman_stats_data *counters,
2978 if (counters->rx_packets != stats->rx_packets || append_all) {
2979 counters->rx_packets = stats->rx_packets;
2980 connman_dbus_dict_append_basic(dict, "RX.Packets",
2981 DBUS_TYPE_UINT32, &stats->rx_packets);
2984 if (counters->tx_packets != stats->tx_packets || append_all) {
2985 counters->tx_packets = stats->tx_packets;
2986 connman_dbus_dict_append_basic(dict, "TX.Packets",
2987 DBUS_TYPE_UINT32, &stats->tx_packets);
2990 if (counters->rx_bytes != stats->rx_bytes || append_all) {
2991 counters->rx_bytes = stats->rx_bytes;
2992 connman_dbus_dict_append_basic(dict, "RX.Bytes",
2993 DBUS_TYPE_UINT32, &stats->rx_bytes);
2996 if (counters->tx_bytes != stats->tx_bytes || append_all) {
2997 counters->tx_bytes = stats->tx_bytes;
2998 connman_dbus_dict_append_basic(dict, "TX.Bytes",
2999 DBUS_TYPE_UINT32, &stats->tx_bytes);
3002 if (counters->rx_errors != stats->rx_errors || append_all) {
3003 counters->rx_errors = stats->rx_errors;
3004 connman_dbus_dict_append_basic(dict, "RX.Errors",
3005 DBUS_TYPE_UINT32, &stats->rx_errors);
3008 if (counters->tx_errors != stats->tx_errors || append_all) {
3009 counters->tx_errors = stats->tx_errors;
3010 connman_dbus_dict_append_basic(dict, "TX.Errors",
3011 DBUS_TYPE_UINT32, &stats->tx_errors);
3014 if (counters->rx_dropped != stats->rx_dropped || append_all) {
3015 counters->rx_dropped = stats->rx_dropped;
3016 connman_dbus_dict_append_basic(dict, "RX.Dropped",
3017 DBUS_TYPE_UINT32, &stats->rx_dropped);
3020 if (counters->tx_dropped != stats->tx_dropped || append_all) {
3021 counters->tx_dropped = stats->tx_dropped;
3022 connman_dbus_dict_append_basic(dict, "TX.Dropped",
3023 DBUS_TYPE_UINT32, &stats->tx_dropped);
3026 if (counters->time != stats->time || append_all) {
3027 counters->time = stats->time;
3028 connman_dbus_dict_append_basic(dict, "Time",
3029 DBUS_TYPE_UINT32, &stats->time);
3033 static void stats_append(struct connman_service *service,
3034 const char *counter,
3035 struct connman_stats_counter *counters,
3038 DBusMessageIter array, dict;
3041 DBG("service %p counter %s", service, counter);
3043 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
3047 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
3048 &service->path, DBUS_TYPE_INVALID);
3050 dbus_message_iter_init_append(msg, &array);
3053 connman_dbus_dict_open(&array, &dict);
3055 stats_append_counters(&dict, &service->stats.data,
3056 &counters->stats.data, append_all);
3058 connman_dbus_dict_close(&array, &dict);
3060 /* roaming counter */
3061 connman_dbus_dict_open(&array, &dict);
3063 stats_append_counters(&dict, &service->stats_roaming.data,
3064 &counters->stats_roaming.data, append_all);
3066 connman_dbus_dict_close(&array, &dict);
3068 __connman_counter_send_usage(counter, msg);
3071 static void stats_update(struct connman_service *service,
3072 unsigned int rx_packets, unsigned int tx_packets,
3073 unsigned int rx_bytes, unsigned int tx_bytes,
3074 unsigned int rx_errors, unsigned int tx_errors,
3075 unsigned int rx_dropped, unsigned int tx_dropped)
3077 struct connman_stats *stats = stats_get(service);
3078 struct connman_stats_data *data_last = &stats->data_last;
3079 struct connman_stats_data *data = &stats->data;
3080 unsigned int seconds;
3082 DBG("service %p", service);
3086 rx_packets - data_last->rx_packets;
3088 tx_packets - data_last->tx_packets;
3090 rx_bytes - data_last->rx_bytes;
3092 tx_bytes - data_last->tx_bytes;
3094 rx_errors - data_last->rx_errors;
3096 tx_errors - data_last->tx_errors;
3098 rx_dropped - data_last->rx_dropped;
3100 tx_dropped - data_last->tx_dropped;
3102 stats->valid = true;
3105 data_last->rx_packets = rx_packets;
3106 data_last->tx_packets = tx_packets;
3107 data_last->rx_bytes = rx_bytes;
3108 data_last->tx_bytes = tx_bytes;
3109 data_last->rx_errors = rx_errors;
3110 data_last->tx_errors = tx_errors;
3111 data_last->rx_dropped = rx_dropped;
3112 data_last->tx_dropped = tx_dropped;
3114 seconds = g_timer_elapsed(stats->timer, NULL);
3115 stats->data.time = stats->data_last.time + seconds;
3118 void __connman_service_notify(struct connman_service *service,
3119 unsigned int rx_packets, unsigned int tx_packets,
3120 unsigned int rx_bytes, unsigned int tx_bytes,
3121 unsigned int rx_errors, unsigned int tx_errors,
3122 unsigned int rx_dropped, unsigned int tx_dropped)
3124 GHashTableIter iter;
3125 gpointer key, value;
3126 const char *counter;
3127 struct connman_stats_counter *counters;
3128 struct connman_stats_data *data;
3134 if (!is_connected(service->state))
3137 stats_update(service,
3138 rx_packets, tx_packets,
3140 rx_errors, tx_errors,
3141 rx_dropped, tx_dropped);
3143 data = &stats_get(service)->data;
3144 err = __connman_stats_update(service, service->roaming, data);
3146 connman_error("Failed to store statistics for %s",
3147 service->identifier);
3149 g_hash_table_iter_init(&iter, service->counter_table);
3150 while (g_hash_table_iter_next(&iter, &key, &value)) {
3154 stats_append(service, counter, counters, counters->append_all);
3155 counters->append_all = false;
3159 int __connman_service_counter_register(const char *counter)
3161 struct connman_service *service;
3163 struct connman_stats_counter *counters;
3165 DBG("counter %s", counter);
3167 counter_list = g_slist_prepend(counter_list, (gpointer)counter);
3169 for (list = service_list; list; list = list->next) {
3170 service = list->data;
3172 counters = g_try_new0(struct connman_stats_counter, 1);
3176 counters->append_all = true;
3178 g_hash_table_replace(service->counter_table, (gpointer)counter,
3185 void __connman_service_counter_unregister(const char *counter)
3187 struct connman_service *service;
3190 DBG("counter %s", counter);
3192 for (list = service_list; list; list = list->next) {
3193 service = list->data;
3195 g_hash_table_remove(service->counter_table, counter);
3198 counter_list = g_slist_remove(counter_list, counter);
3201 int __connman_service_iterate_services(service_iterate_cb cb, void *user_data)
3205 for (list = service_list; list; list = list->next) {
3206 struct connman_service *service = list->data;
3208 cb(service, user_data);
3214 #if defined TIZEN_EXT
3215 static void append_wifi_ext_info(DBusMessageIter *dict,
3216 struct connman_network *network)
3218 char bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
3219 char *bssid_str = bssid_buff;
3221 unsigned int ssid_len;
3222 unsigned char *bssid;
3223 unsigned int maxrate;
3224 unsigned int keymgmt;
3226 const char *enc_mode;
3230 ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
3231 bssid = connman_network_get_bssid(network);
3232 maxrate = connman_network_get_maxrate(network);
3233 frequency = connman_network_get_frequency(network);
3234 enc_mode = connman_network_get_enc_mode(network);
3235 passpoint = connman_network_get_bool(network, "WiFi.HS20AP");
3236 keymgmt = connman_network_get_keymgmt(network);
3238 snprintf(bssid_str, WIFI_BSSID_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
3239 bssid[0], bssid[1], bssid[2],
3240 bssid[3], bssid[4], bssid[5]);
3242 connman_dbus_dict_append_fixed_array(dict, "SSID",
3243 DBUS_TYPE_BYTE, &ssid, ssid_len);
3244 connman_dbus_dict_append_basic(dict, "BSSID",
3245 DBUS_TYPE_STRING, &bssid_str);
3246 connman_dbus_dict_append_basic(dict, "MaxRate",
3247 DBUS_TYPE_UINT32, &maxrate);
3248 connman_dbus_dict_append_basic(dict, "Frequency",
3249 DBUS_TYPE_UINT16, &frequency);
3250 connman_dbus_dict_append_basic(dict, "EncryptionMode",
3251 DBUS_TYPE_STRING, &enc_mode);
3252 connman_dbus_dict_append_basic(dict, "Passpoint",
3253 DBUS_TYPE_BOOLEAN, &passpoint);
3254 connman_dbus_dict_append_basic(dict, "Keymgmt",
3255 DBUS_TYPE_UINT32, &keymgmt);
3257 str = connman_network_get_string(network, "WiFi.Security");
3258 if (str != NULL && g_str_equal(str, "ieee8021x") == TRUE) {
3259 str = connman_network_get_string(network, "WiFi.EAP");
3261 connman_dbus_dict_append_basic(dict, "EAP",
3262 DBUS_TYPE_STRING, &str);
3264 str = connman_network_get_string(network, "WiFi.Phase2");
3266 connman_dbus_dict_append_basic(dict, "Phase2",
3267 DBUS_TYPE_STRING, &str);
3269 str = connman_network_get_string(network, "WiFi.Identity");
3271 connman_dbus_dict_append_basic(dict, "Identity",
3272 DBUS_TYPE_STRING, &str);
3274 str = connman_network_get_string(network, "WiFi.CACertFile");
3276 connman_dbus_dict_append_basic(dict, "CACertFile",
3277 DBUS_TYPE_STRING, &str);
3279 str = connman_network_get_string(network,
3280 "WiFi.ClientCertFile");
3282 connman_dbus_dict_append_basic(dict, "ClientCertFile",
3283 DBUS_TYPE_STRING, &str);
3285 str = connman_network_get_string(network,
3286 "WiFi.PrivateKeyFile");
3288 connman_dbus_dict_append_basic(dict, "PrivateKeyFile",
3289 DBUS_TYPE_STRING, &str);
3294 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
3295 struct connman_service *service)
3301 #if defined TIZEN_EXT
3302 unsigned int frequency = 0U;
3303 if (service && service->network) {
3304 frequency = connman_network_get_frequency(service->network);
3305 connman_dbus_dict_append_basic(dict, "Frequency",
3306 DBUS_TYPE_UINT16, &frequency);
3308 const void *wifi_vsie;
3309 unsigned int wifi_vsie_len;
3310 wifi_vsie = connman_network_get_blob(service->network, "WiFi.Vsie", &wifi_vsie_len);
3311 if(wifi_vsie_len > 0) {
3312 DBG("ConnMan, service->path=%s vsie length=%d", service->path, wifi_vsie_len);
3314 connman_dbus_dict_append_fixed_array(dict, "Vsie", DBUS_TYPE_BYTE,
3315 &wifi_vsie, wifi_vsie_len);
3318 str = __connman_service_type2string(service->type);
3320 connman_dbus_dict_append_basic(dict, "Type",
3321 DBUS_TYPE_STRING, &str);
3323 connman_dbus_dict_append_array(dict, "Security",
3324 DBUS_TYPE_STRING, append_security, service);
3326 str = state2string(service->state);
3328 connman_dbus_dict_append_basic(dict, "State",
3329 DBUS_TYPE_STRING, &str);
3332 str = state2string(service->state_ipv6);
3334 connman_dbus_dict_append_basic(dict, "StateIPv6",
3335 DBUS_TYPE_STRING, &str);
3338 str = error2string(service->error);
3340 connman_dbus_dict_append_basic(dict, "Error",
3341 DBUS_TYPE_STRING, &str);
3343 if (service->strength > 0)
3344 connman_dbus_dict_append_basic(dict, "Strength",
3345 DBUS_TYPE_BYTE, &service->strength);
3347 val = service->favorite;
3348 connman_dbus_dict_append_basic(dict, "Favorite",
3349 DBUS_TYPE_BOOLEAN, &val);
3351 val = service->immutable;
3352 connman_dbus_dict_append_basic(dict, "Immutable",
3353 DBUS_TYPE_BOOLEAN, &val);
3355 if (service->favorite)
3356 val = service->autoconnect;
3358 val = service->favorite;
3360 connman_dbus_dict_append_basic(dict, "AutoConnect",
3361 DBUS_TYPE_BOOLEAN, &val);
3364 connman_dbus_dict_append_basic(dict, "Name",
3365 DBUS_TYPE_STRING, &service->name);
3367 switch (service->type) {
3368 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3369 case CONNMAN_SERVICE_TYPE_SYSTEM:
3370 case CONNMAN_SERVICE_TYPE_GPS:
3371 case CONNMAN_SERVICE_TYPE_VPN:
3372 case CONNMAN_SERVICE_TYPE_P2P:
3374 case CONNMAN_SERVICE_TYPE_CELLULAR:
3375 val = service->roaming;
3376 connman_dbus_dict_append_basic(dict, "Roaming",
3377 DBUS_TYPE_BOOLEAN, &val);
3379 connman_dbus_dict_append_dict(dict, "Ethernet",
3380 append_ethernet, service);
3382 case CONNMAN_SERVICE_TYPE_WIFI:
3383 #if defined TIZEN_EXT
3384 if (service->network != NULL)
3385 append_wifi_ext_info(dict, service->network);
3387 connman_dbus_dict_append_dict(dict, "Ethernet",
3388 append_ethernet, service);
3390 connman_dbus_dict_append_basic(dict, "DisconnectReason",
3391 DBUS_TYPE_INT32, &service->disconnect_reason);
3393 connman_dbus_dict_append_basic(dict, "AssocStatusCode",
3394 DBUS_TYPE_INT32, &service->assoc_status_code);
3398 case CONNMAN_SERVICE_TYPE_ETHERNET:
3399 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3400 case CONNMAN_SERVICE_TYPE_GADGET:
3401 connman_dbus_dict_append_dict(dict, "Ethernet",
3402 append_ethernet, service);
3406 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
3408 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
3409 append_ipv4config, service);
3411 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
3413 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
3414 append_ipv6config, service);
3416 connman_dbus_dict_append_array(dict, "Nameservers",
3417 DBUS_TYPE_STRING, append_dns, service);
3419 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
3420 DBUS_TYPE_STRING, append_dnsconfig, service);
3422 if (service->state == CONNMAN_SERVICE_STATE_READY ||
3423 service->state == CONNMAN_SERVICE_STATE_ONLINE)
3424 list = __connman_timeserver_get_all(service);
3428 connman_dbus_dict_append_array(dict, "Timeservers",
3429 DBUS_TYPE_STRING, append_ts, list);
3431 g_slist_free_full(list, g_free);
3433 connman_dbus_dict_append_array(dict, "Timeservers.Configuration",
3434 DBUS_TYPE_STRING, append_tsconfig, service);
3436 connman_dbus_dict_append_array(dict, "Domains",
3437 DBUS_TYPE_STRING, append_domain, service);
3439 connman_dbus_dict_append_array(dict, "Domains.Configuration",
3440 DBUS_TYPE_STRING, append_domainconfig, service);
3442 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
3444 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
3445 append_proxyconfig, service);
3447 connman_dbus_dict_append_dict(dict, "Provider",
3448 append_provider, service);
3451 static void append_struct_service(DBusMessageIter *iter,
3452 connman_dbus_append_cb_t function,
3453 struct connman_service *service)
3455 DBusMessageIter entry, dict;
3457 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
3459 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
3462 connman_dbus_dict_open(&entry, &dict);
3464 function(&dict, service);
3465 connman_dbus_dict_close(&entry, &dict);
3467 dbus_message_iter_close_container(iter, &entry);
3470 static void append_dict_properties(DBusMessageIter *dict, void *user_data)
3472 struct connman_service *service = user_data;
3474 append_properties(dict, TRUE, service);
3477 static void append_struct(gpointer value, gpointer user_data)
3479 struct connman_service *service = value;
3480 DBusMessageIter *iter = user_data;
3485 append_struct_service(iter, append_dict_properties, service);
3488 void __connman_service_list_struct(DBusMessageIter *iter)
3490 g_list_foreach(service_list, append_struct, iter);
3493 bool __connman_service_is_hidden(struct connman_service *service)
3495 return service->hidden;
3499 __connman_service_is_split_routing(struct connman_service *service)
3501 return service->do_split_routing;
3504 bool __connman_service_index_is_split_routing(int index)
3506 struct connman_service *service;
3511 service = __connman_service_lookup_from_index(index);
3515 return __connman_service_is_split_routing(service);
3518 int __connman_service_get_index(struct connman_service *service)
3523 if (service->network)
3524 return connman_network_get_index(service->network);
3525 else if (service->provider)
3526 return connman_provider_get_index(service->provider);
3531 void __connman_service_set_hidden(struct connman_service *service)
3533 if (!service || service->hidden)
3536 service->hidden_service = true;
3539 void __connman_service_set_hostname(struct connman_service *service,
3540 const char *hostname)
3542 if (!service || service->hidden)
3545 g_free(service->hostname);
3546 service->hostname = g_strdup(hostname);
3549 const char *__connman_service_get_hostname(struct connman_service *service)
3554 return service->hostname;
3557 void __connman_service_set_domainname(struct connman_service *service,
3558 const char *domainname)
3560 if (!service || service->hidden)
3563 g_free(service->domainname);
3564 service->domainname = g_strdup(domainname);
3566 domain_changed(service);
3569 const char *connman_service_get_domainname(struct connman_service *service)
3574 if (service->domains)
3575 return service->domains[0];
3577 return service->domainname;
3580 char **connman_service_get_nameservers(struct connman_service *service)
3585 if (service->nameservers_config)
3586 return g_strdupv(service->nameservers_config);
3587 else if (service->nameservers ||
3588 service->nameservers_auto) {
3589 int len = 0, len_auto = 0, i;
3592 if (service->nameservers)
3593 len = g_strv_length(service->nameservers);
3594 if (service->nameservers_auto)
3595 len_auto = g_strv_length(service->nameservers_auto);
3597 nameservers = g_try_new0(char *, len + len_auto + 1);
3601 for (i = 0; i < len; i++)
3602 nameservers[i] = g_strdup(service->nameservers[i]);
3604 for (i = 0; i < len_auto; i++)
3605 nameservers[i + len] =
3606 g_strdup(service->nameservers_auto[i]);
3611 return g_strdupv(connman_setting_get_string_list("FallbackNameservers"));
3614 char **connman_service_get_timeservers_config(struct connman_service *service)
3619 return service->timeservers_config;
3622 char **connman_service_get_timeservers(struct connman_service *service)
3627 return service->timeservers;
3630 #if defined TIZEN_EXT
3632 * Description: Telephony plug-in requires manual PROXY setting function
3634 int connman_service_set_proxy(struct connman_service *service,
3635 const char *proxy, gboolean active)
3637 char **proxies_array = NULL;
3639 if (service == NULL)
3642 switch (service->type) {
3643 case CONNMAN_SERVICE_TYPE_CELLULAR:
3644 case CONNMAN_SERVICE_TYPE_ETHERNET:
3645 case CONNMAN_SERVICE_TYPE_WIFI:
3652 g_strfreev(service->proxies);
3653 service->proxies = NULL;
3656 proxies_array = g_strsplit(proxy, " ", 0);
3658 service->proxies = proxies_array;
3660 if (proxy == NULL) {
3661 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
3662 DBG("proxy changed (%d)", active);
3664 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
3665 DBG("proxy chagned %s (%d)", proxy, active);
3668 if (active == TRUE) {
3669 proxy_changed(service);
3671 __connman_notifier_proxy_changed(service);
3678 void connman_service_set_proxy_method(struct connman_service *service,
3679 enum connman_service_proxy_method method)
3681 if (!service || service->hidden)
3684 service->proxy = method;
3686 proxy_changed(service);
3688 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
3689 __connman_notifier_proxy_changed(service);
3692 enum connman_service_proxy_method connman_service_get_proxy_method(
3693 struct connman_service *service)
3696 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
3698 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
3699 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
3701 return service->proxy;
3703 return service->proxy_config;
3706 return service->proxy;
3709 char **connman_service_get_proxy_servers(struct connman_service *service)
3711 return g_strdupv(service->proxies);
3714 char **connman_service_get_proxy_excludes(struct connman_service *service)
3716 return g_strdupv(service->excludes);
3719 const char *connman_service_get_proxy_url(struct connman_service *service)
3724 return service->pac;
3727 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
3730 if (!service || service->hidden)
3733 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
3735 if (service->ipconfig_ipv4) {
3736 if (__connman_ipconfig_set_proxy_autoconfig(
3737 service->ipconfig_ipv4, url) < 0)
3739 } else if (service->ipconfig_ipv6) {
3740 if (__connman_ipconfig_set_proxy_autoconfig(
3741 service->ipconfig_ipv6, url) < 0)
3746 proxy_changed(service);
3748 __connman_notifier_proxy_changed(service);
3751 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
3756 if (service->ipconfig_ipv4)
3757 return __connman_ipconfig_get_proxy_autoconfig(
3758 service->ipconfig_ipv4);
3759 else if (service->ipconfig_ipv6)
3760 return __connman_ipconfig_get_proxy_autoconfig(
3761 service->ipconfig_ipv6);
3765 #if defined TIZEN_EXT
3766 int connman_service_get_ipv6_dns_method(struct connman_service *service)
3769 DBG("Service is NULL");
3773 return service->dns_config_method_ipv6;
3777 void __connman_service_set_timeservers(struct connman_service *service,
3785 g_strfreev(service->timeservers);
3786 service->timeservers = NULL;
3788 for (i = 0; timeservers && timeservers[i]; i++)
3789 __connman_service_timeserver_append(service, timeservers[i]);
3792 int __connman_service_timeserver_append(struct connman_service *service,
3793 const char *timeserver)
3797 DBG("service %p timeserver %s", service, timeserver);
3802 if (service->timeservers) {
3805 for (i = 0; service->timeservers[i]; i++)
3806 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
3809 len = g_strv_length(service->timeservers);
3810 service->timeservers = g_try_renew(char *, service->timeservers,
3814 service->timeservers = g_try_new0(char *, len + 2);
3817 if (!service->timeservers)
3820 service->timeservers[len] = g_strdup(timeserver);
3821 service->timeservers[len + 1] = NULL;
3826 int __connman_service_timeserver_remove(struct connman_service *service,
3827 const char *timeserver)
3830 int len, i, j, found = 0;
3832 DBG("service %p timeserver %s", service, timeserver);
3837 if (!service->timeservers)
3840 for (i = 0; service->timeservers &&
3841 service->timeservers[i]; i++)
3842 if (g_strcmp0(service->timeservers[i], timeserver) == 0) {
3850 len = g_strv_length(service->timeservers);
3853 g_strfreev(service->timeservers);
3854 service->timeservers = NULL;
3859 servers = g_try_new0(char *, len);
3863 for (i = 0, j = 0; i < len; i++) {
3864 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
3865 servers[j] = g_strdup(service->timeservers[i]);
3871 servers[len - 1] = NULL;
3873 g_strfreev(service->timeservers);
3874 service->timeservers = servers;
3879 void __connman_service_timeserver_changed(struct connman_service *service,
3885 if (!allow_property_changed(service))
3888 connman_dbus_property_changed_array(service->path,
3889 CONNMAN_SERVICE_INTERFACE, "Timeservers",
3890 DBUS_TYPE_STRING, append_ts, ts_list);
3893 void __connman_service_set_pac(struct connman_service *service,
3896 if (service->hidden)
3898 g_free(service->pac);
3899 service->pac = g_strdup(pac);
3901 proxy_changed(service);
3904 #if defined TIZEN_EXT
3905 void __connman_service_set_proxy(struct connman_service *service,
3906 const char *proxies)
3908 char **proxies_array = NULL;
3910 g_strfreev(service->proxies);
3911 service->proxies = NULL;
3913 if (proxies != NULL)
3914 proxies_array = g_strsplit(proxies, " ", 0);
3916 service->proxies = proxies_array;
3920 void __connman_service_set_identity(struct connman_service *service,
3921 const char *identity)
3923 if (service->immutable || service->hidden)
3926 g_free(service->identity);
3927 service->identity = g_strdup(identity);
3929 if (service->network)
3930 connman_network_set_string(service->network,
3935 void __connman_service_set_anonymous_identity(struct connman_service *service,
3936 const char *anonymous_identity)
3938 if (service->immutable || service->hidden)
3941 g_free(service->anonymous_identity);
3942 service->anonymous_identity = g_strdup(anonymous_identity);
3944 if (service->network)
3945 connman_network_set_string(service->network,
3946 "WiFi.AnonymousIdentity",
3947 service->anonymous_identity);
3950 void __connman_service_set_subject_match(struct connman_service *service,
3951 const char *subject_match)
3953 if (service->immutable || service->hidden)
3956 g_free(service->subject_match);
3957 service->subject_match = g_strdup(subject_match);
3959 if (service->network)
3960 connman_network_set_string(service->network,
3961 "WiFi.SubjectMatch",
3962 service->subject_match);
3965 void __connman_service_set_altsubject_match(struct connman_service *service,
3966 const char *altsubject_match)
3968 if (service->immutable || service->hidden)
3971 g_free(service->altsubject_match);
3972 service->altsubject_match = g_strdup(altsubject_match);
3974 if (service->network)
3975 connman_network_set_string(service->network,
3976 "WiFi.AltSubjectMatch",
3977 service->altsubject_match);
3980 void __connman_service_set_domain_suffix_match(struct connman_service *service,
3981 const char *domain_suffix_match)
3983 if (service->immutable || service->hidden)
3986 g_free(service->domain_suffix_match);
3987 service->domain_suffix_match = g_strdup(domain_suffix_match);
3989 if (service->network)
3990 connman_network_set_string(service->network,
3991 "WiFi.DomainSuffixMatch",
3992 service->domain_suffix_match);
3995 void __connman_service_set_domain_match(struct connman_service *service,
3996 const char *domain_match)
3998 if (service->immutable || service->hidden)
4001 g_free(service->domain_match);
4002 service->domain_match = g_strdup(domain_match);
4004 if (service->network)
4005 connman_network_set_string(service->network,
4007 service->domain_match);
4010 void __connman_service_set_agent_identity(struct connman_service *service,
4011 const char *agent_identity)
4013 if (service->hidden)
4015 g_free(service->agent_identity);
4016 service->agent_identity = g_strdup(agent_identity);
4018 if (service->network)
4019 connman_network_set_string(service->network,
4020 "WiFi.AgentIdentity",
4021 service->agent_identity);
4024 int __connman_service_check_passphrase(enum connman_service_security security,
4025 const char *passphrase)
4033 length = strlen(passphrase);
4036 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
4037 case CONNMAN_SERVICE_SECURITY_NONE:
4038 case CONNMAN_SERVICE_SECURITY_WPA:
4039 #if !defined TIZEN_EXT
4040 case CONNMAN_SERVICE_SECURITY_RSN:
4043 DBG("service security '%s' (%d) not handled",
4044 security2string(security), security);
4048 case CONNMAN_SERVICE_SECURITY_PSK:
4049 #if defined TIZEN_EXT
4050 case CONNMAN_SERVICE_SECURITY_RSN:
4052 /* A raw key is always 64 bytes length,
4053 * its content is in hex representation.
4054 * A PSK key must be between [8..63].
4057 for (i = 0; i < 64; i++)
4058 if (!isxdigit((unsigned char)
4061 } else if (length < 8 || length > 63)
4064 case CONNMAN_SERVICE_SECURITY_WEP:
4065 /* length of WEP key is 10 or 26
4066 * length of WEP passphrase is 5 or 13
4068 if (length == 10 || length == 26) {
4069 for (i = 0; i < length; i++)
4070 if (!isxdigit((unsigned char)
4073 } else if (length != 5 && length != 13)
4077 case CONNMAN_SERVICE_SECURITY_8021X:
4084 int __connman_service_set_passphrase(struct connman_service *service,
4085 const char *passphrase)
4089 if (service->hidden)
4092 if (service->immutable &&
4093 service->security != CONNMAN_SERVICE_SECURITY_8021X)
4095 #if defined TIZEN_EXT
4096 /* The encrypted passphrase is used here
4097 * and validation is done by net-config before being encrypted.
4100 if (service->security != CONNMAN_SERVICE_SECURITY_PSK &&
4101 service->security != CONNMAN_SERVICE_SECURITY_RSN &&
4102 service->security != CONNMAN_SERVICE_SECURITY_WEP)
4104 err = __connman_service_check_passphrase(service->security, passphrase);
4109 g_free(service->passphrase);
4110 service->passphrase = g_strdup(passphrase);
4112 if (service->network)
4113 connman_network_set_string(service->network, "WiFi.Passphrase",
4114 service->passphrase);
4119 const char *__connman_service_get_passphrase(struct connman_service *service)
4124 return service->passphrase;
4127 static DBusMessage *get_properties(DBusConnection *conn,
4128 DBusMessage *msg, void *user_data)
4130 struct connman_service *service = user_data;
4132 DBusMessageIter array, dict;
4134 reply = dbus_message_new_method_return(msg);
4138 dbus_message_iter_init_append(reply, &array);
4140 connman_dbus_dict_open(&array, &dict);
4141 append_properties(&dict, FALSE, service);
4142 connman_dbus_dict_close(&array, &dict);
4147 static char **remove_empty_strings(char **strv)
4154 strv[index++] = *iter;
4164 static int update_proxy_configuration(struct connman_service *service,
4165 DBusMessageIter *array)
4167 DBusMessageIter dict;
4168 enum connman_service_proxy_method method;
4169 GString *servers_str = NULL;
4170 GString *excludes_str = NULL;
4171 const char *url = NULL;
4173 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
4175 dbus_message_iter_recurse(array, &dict);
4177 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
4178 DBusMessageIter entry, variant;
4182 dbus_message_iter_recurse(&dict, &entry);
4184 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
4187 dbus_message_iter_get_basic(&entry, &key);
4188 dbus_message_iter_next(&entry);
4190 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
4193 dbus_message_iter_recurse(&entry, &variant);
4195 type = dbus_message_iter_get_arg_type(&variant);
4197 if (g_str_equal(key, "Method")) {
4200 if (type != DBUS_TYPE_STRING)
4203 dbus_message_iter_get_basic(&variant, &val);
4204 method = string2proxymethod(val);
4205 } else if (g_str_equal(key, "URL")) {
4206 if (type != DBUS_TYPE_STRING)
4209 dbus_message_iter_get_basic(&variant, &url);
4210 } else if (g_str_equal(key, "Servers")) {
4211 DBusMessageIter str_array;
4213 if (type != DBUS_TYPE_ARRAY)
4216 servers_str = g_string_new(NULL);
4220 dbus_message_iter_recurse(&variant, &str_array);
4222 while (dbus_message_iter_get_arg_type(&str_array) ==
4226 dbus_message_iter_get_basic(&str_array, &val);
4228 if (servers_str->len > 0)
4229 g_string_append_printf(servers_str,
4232 g_string_append(servers_str, val);
4234 dbus_message_iter_next(&str_array);
4236 } else if (g_str_equal(key, "Excludes")) {
4237 DBusMessageIter str_array;
4239 if (type != DBUS_TYPE_ARRAY)
4242 excludes_str = g_string_new(NULL);
4246 dbus_message_iter_recurse(&variant, &str_array);
4248 while (dbus_message_iter_get_arg_type(&str_array) ==
4252 dbus_message_iter_get_basic(&str_array, &val);
4254 if (excludes_str->len > 0)
4255 g_string_append_printf(excludes_str,
4258 g_string_append(excludes_str, val);
4260 dbus_message_iter_next(&str_array);
4264 dbus_message_iter_next(&dict);
4268 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
4270 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
4271 if (!servers_str && !service->proxies)
4275 g_strfreev(service->proxies);
4277 if (servers_str->len > 0) {
4278 char **proxies = g_strsplit_set(
4279 servers_str->str, " ", 0);
4280 proxies = remove_empty_strings(proxies);
4281 service->proxies = proxies;
4283 service->proxies = NULL;
4287 g_strfreev(service->excludes);
4289 if (excludes_str->len > 0) {
4290 char **excludes = g_strsplit_set(
4291 excludes_str->str, " ", 0);
4292 excludes = remove_empty_strings(excludes);
4293 service->excludes = excludes;
4295 service->excludes = NULL;
4298 if (!service->proxies)
4299 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
4302 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
4303 g_free(service->pac);
4305 if (url && strlen(url) > 0)
4306 service->pac = g_strstrip(g_strdup(url));
4308 service->pac = NULL;
4310 /* if we are connected:
4311 - if service->pac == NULL
4312 - if __connman_ipconfig_get_proxy_autoconfig(
4313 service->ipconfig) == NULL
4314 --> We should start WPAD */
4317 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
4322 g_string_free(servers_str, TRUE);
4325 g_string_free(excludes_str, TRUE);
4327 service->proxy_config = method;
4333 g_string_free(servers_str, TRUE);
4336 g_string_free(excludes_str, TRUE);
4341 int __connman_service_reset_ipconfig(struct connman_service *service,
4342 enum connman_ipconfig_type type, DBusMessageIter *array,
4343 enum connman_service_state *new_state)
4345 struct connman_ipconfig *ipconfig, *new_ipconfig;
4346 enum connman_ipconfig_method old_method, new_method;
4347 enum connman_service_state state;
4350 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4351 ipconfig = service->ipconfig_ipv4;
4352 state = service->state_ipv4;
4353 new_method = CONNMAN_IPCONFIG_METHOD_DHCP;
4354 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4355 ipconfig = service->ipconfig_ipv6;
4356 state = service->state_ipv6;
4357 new_method = CONNMAN_IPCONFIG_METHOD_AUTO;
4364 old_method = __connman_ipconfig_get_method(ipconfig);
4365 index = __connman_ipconfig_get_index(ipconfig);
4367 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4368 new_ipconfig = create_ip4config(service, index,
4369 CONNMAN_IPCONFIG_METHOD_UNKNOWN);
4371 new_ipconfig = create_ip6config(service, index);
4374 err = __connman_ipconfig_set_config(new_ipconfig, array);
4376 __connman_ipconfig_unref(new_ipconfig);
4380 new_method = __connman_ipconfig_get_method(new_ipconfig);
4383 if (is_connecting(state) || is_connected(state))
4384 __connman_network_clear_ipconfig(service->network, ipconfig);
4386 __connman_ipconfig_unref(ipconfig);
4388 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4389 service->ipconfig_ipv4 = new_ipconfig;
4390 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4391 service->ipconfig_ipv6 = new_ipconfig;
4393 if (is_connecting(state) || is_connected(state))
4394 __connman_ipconfig_enable(new_ipconfig);
4396 if (new_state && new_method != old_method) {
4397 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4398 *new_state = service->state_ipv4;
4400 *new_state = service->state_ipv6;
4402 settings_changed(service, new_ipconfig);
4403 address_updated(service, new_method);
4405 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4408 DBG("err %d ipconfig %p type %d method %d state %s", err,
4409 new_ipconfig, type, new_method,
4410 !new_state ? "-" : state2string(*new_state));
4415 static DBusMessage *set_property(DBusConnection *conn,
4416 DBusMessage *msg, void *user_data)
4418 struct connman_service *service = user_data;
4419 DBusMessageIter iter, value;
4423 DBG("service %p", service);
4425 if (!dbus_message_iter_init(msg, &iter))
4426 return __connman_error_invalid_arguments(msg);
4428 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
4429 return __connman_error_invalid_arguments(msg);
4431 if (service->type == CONNMAN_SERVICE_TYPE_WIFI && is_connected(service->state)) {
4433 if (connman_dbus_get_connection_unix_user_sync(conn,
4434 dbus_message_get_sender(msg),
4436 DBG("Can not get unix user id!");
4437 return __connman_error_permission_denied(msg);
4440 if (!connman_service_is_user_allowed(service, uid)) {
4441 DBG("Not allow this user to operate this wifi service now!");
4442 return __connman_error_permission_denied(msg);
4446 dbus_message_iter_get_basic(&iter, &name);
4447 dbus_message_iter_next(&iter);
4449 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
4450 return __connman_error_invalid_arguments(msg);
4452 dbus_message_iter_recurse(&iter, &value);
4454 type = dbus_message_iter_get_arg_type(&value);
4456 if (g_str_equal(name, "AutoConnect")) {
4457 dbus_bool_t autoconnect;
4459 if (type != DBUS_TYPE_BOOLEAN)
4460 return __connman_error_invalid_arguments(msg);
4462 if (!service->favorite)
4463 return __connman_error_invalid_service(msg);
4465 dbus_message_iter_get_basic(&value, &autoconnect);
4467 if (service->autoconnect == autoconnect)
4468 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4470 service->autoconnect = autoconnect;
4472 autoconnect_changed(service);
4475 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4477 service_save(service);
4478 } else if (g_str_equal(name, "Nameservers.Configuration")) {
4479 DBusMessageIter entry;
4483 #if defined TIZEN_EXT
4484 enum connman_ipconfig_type ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4488 if (__connman_provider_is_immutable(service->provider) ||
4490 return __connman_error_not_supported(msg);
4492 if (type != DBUS_TYPE_ARRAY)
4493 return __connman_error_invalid_arguments(msg);
4495 str = g_string_new(NULL);
4497 return __connman_error_invalid_arguments(msg);
4499 index = __connman_service_get_index(service);
4500 gw = __connman_ipconfig_get_gateway_from_index(index,
4501 CONNMAN_IPCONFIG_TYPE_ALL);
4503 #if !defined TIZEN_EXT
4504 if (gw && strlen(gw))
4505 __connman_service_nameserver_del_routes(service,
4506 CONNMAN_IPCONFIG_TYPE_ALL);
4508 dbus_message_iter_recurse(&value, &entry);
4510 #if defined TIZEN_EXT
4511 /* IPv4/IPv6 Last DNS config method */
4512 int last_dns_ipv4 = service->dns_config_method_ipv4;
4513 int last_dns_ipv6 = service->dns_config_method_ipv6;
4514 DBG("Last DNS Config Method IPv4: %d IPv6: %d", last_dns_ipv4, last_dns_ipv6);
4517 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4519 dbus_message_iter_get_basic(&entry, &val);
4520 dbus_message_iter_next(&entry);
4522 /* First unpack the DNS Config Method */
4523 DBG("DNS Config Method: %s", val);
4524 if((g_strcmp0(val, "ipv4.manual") == 0)) {
4525 service->dns_config_method_ipv4 =
4526 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4528 if(last_dns_ipv4 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4529 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4530 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4532 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4535 } else if(g_strcmp0(val, "ipv4.dhcp") == 0) {
4536 service->dns_config_method_ipv4 =
4537 CONNMAN_DNSCONFIG_METHOD_DHCP;
4538 if(last_dns_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4539 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4542 } else if(g_strcmp0(val, "ipv6.manual") == 0) {
4543 service->dns_config_method_ipv6 =
4544 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4545 if(last_dns_ipv6 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4546 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4547 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4549 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4552 } else if(g_strcmp0(val, "ipv6.dhcp") == 0) {
4553 service->dns_config_method_ipv6 =
4554 CONNMAN_DNSCONFIG_METHOD_DHCP;
4555 if(last_dns_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4556 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4565 g_string_append_printf(str, " %s", val);
4567 g_string_append(str, val);
4570 #if defined TIZEN_EXT
4571 if (service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_DHCP &&
4572 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_DHCP) {
4573 DBG("Both IPv4 and IPv6 DNS Method DHCP");
4574 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4576 if (gw && strlen(gw))
4577 __connman_service_nameserver_del_routes(service,
4580 DBG("%s ip_type: %d nameserver remove all", name, ip_type);
4581 nameserver_remove_all(service, ip_type);
4583 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
4585 g_strfreev(service->nameservers_config);
4588 char **nameservers, **iter;
4590 nameservers = g_strsplit_set(str->str, " ", 0);
4592 for (iter = nameservers; *iter; iter++)
4593 if (connman_inet_check_ipaddress(*iter) <= 0)
4596 nameservers = remove_empty_strings(nameservers);
4597 service->nameservers_config = nameservers;
4599 service->nameservers_config = NULL;
4602 g_string_free(str, TRUE);
4604 if (gw && strlen(gw))
4605 __connman_service_nameserver_add_routes(service, gw);
4607 #if defined TIZEN_EXT
4608 DBG("%s ip_type: %d nameserver add all", name, ip_type);
4609 nameserver_add_all(service, ip_type);
4611 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
4613 dns_configuration_changed(service);
4615 if (__connman_service_is_connected_state(service,
4616 CONNMAN_IPCONFIG_TYPE_IPV4))
4617 __connman_wispr_start(service,
4618 CONNMAN_IPCONFIG_TYPE_IPV4);
4620 if (__connman_service_is_connected_state(service,
4621 CONNMAN_IPCONFIG_TYPE_IPV6))
4622 __connman_wispr_start(service,
4623 CONNMAN_IPCONFIG_TYPE_IPV6);
4625 service_save(service);
4626 } else if (g_str_equal(name, "Timeservers.Configuration")) {
4627 DBusMessageIter entry;
4630 if (service->immutable)
4631 return __connman_error_not_supported(msg);
4633 if (type != DBUS_TYPE_ARRAY)
4634 return __connman_error_invalid_arguments(msg);
4636 str = g_string_new(NULL);
4638 return __connman_error_invalid_arguments(msg);
4640 dbus_message_iter_recurse(&value, &entry);
4642 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4644 dbus_message_iter_get_basic(&entry, &val);
4645 dbus_message_iter_next(&entry);
4651 g_string_append_printf(str, " %s", val);
4653 g_string_append(str, val);
4656 g_strfreev(service->timeservers_config);
4657 service->timeservers_config = NULL;
4660 char **timeservers = g_strsplit_set(str->str, " ", 0);
4661 timeservers = remove_empty_strings(timeservers);
4662 service->timeservers_config = timeservers;
4664 service->timeservers = NULL;
4666 g_string_free(str, TRUE);
4668 service_save(service);
4669 timeservers_configuration_changed(service);
4671 if (service == __connman_service_get_default())
4672 __connman_timeserver_sync(service);
4674 } else if (g_str_equal(name, "Domains.Configuration")) {
4675 DBusMessageIter entry;
4678 if (service->immutable)
4679 return __connman_error_not_supported(msg);
4681 if (type != DBUS_TYPE_ARRAY)
4682 return __connman_error_invalid_arguments(msg);
4684 str = g_string_new(NULL);
4686 return __connman_error_invalid_arguments(msg);
4688 dbus_message_iter_recurse(&value, &entry);
4690 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4692 dbus_message_iter_get_basic(&entry, &val);
4693 dbus_message_iter_next(&entry);
4699 g_string_append_printf(str, " %s", val);
4701 g_string_append(str, val);
4704 searchdomain_remove_all(service);
4705 g_strfreev(service->domains);
4708 char **domains = g_strsplit_set(str->str, " ", 0);
4709 domains = remove_empty_strings(domains);
4710 service->domains = domains;
4712 service->domains = NULL;
4714 g_string_free(str, TRUE);
4716 searchdomain_add_all(service);
4717 domain_configuration_changed(service);
4718 domain_changed(service);
4720 service_save(service);
4721 } else if (g_str_equal(name, "Proxy.Configuration")) {
4724 if (service->immutable)
4725 return __connman_error_not_supported(msg);
4727 if (type != DBUS_TYPE_ARRAY)
4728 return __connman_error_invalid_arguments(msg);
4730 err = update_proxy_configuration(service, &value);
4733 return __connman_error_failed(msg, -err);
4735 proxy_configuration_changed(service);
4737 __connman_notifier_proxy_changed(service);
4739 service_save(service);
4740 } else if (g_str_equal(name, "IPv4.Configuration") ||
4741 g_str_equal(name, "IPv6.Configuration")) {
4743 enum connman_service_state state =
4744 CONNMAN_SERVICE_STATE_UNKNOWN;
4745 enum connman_ipconfig_type type =
4746 CONNMAN_IPCONFIG_TYPE_UNKNOWN;
4749 if (service->type == CONNMAN_SERVICE_TYPE_VPN ||
4751 return __connman_error_not_supported(msg);
4755 if (!service->ipconfig_ipv4 &&
4756 !service->ipconfig_ipv6)
4757 return __connman_error_invalid_property(msg);
4759 if (g_str_equal(name, "IPv4.Configuration"))
4760 type = CONNMAN_IPCONFIG_TYPE_IPV4;
4762 type = CONNMAN_IPCONFIG_TYPE_IPV6;
4764 err = __connman_service_reset_ipconfig(service, type, &value,
4768 if (is_connected(state) || is_connecting(state)) {
4769 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4770 __connman_network_enable_ipconfig(service->network,
4771 service->ipconfig_ipv4);
4773 __connman_network_enable_ipconfig(service->network,
4774 service->ipconfig_ipv6);
4777 return __connman_error_failed(msg, -err);
4780 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4781 ipv4_configuration_changed(service);
4783 ipv6_configuration_changed(service);
4785 if (is_connecting(service->state) ||
4786 is_connected(service->state)) {
4787 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4788 __connman_network_enable_ipconfig(service->network,
4789 service->ipconfig_ipv4);
4791 __connman_network_enable_ipconfig(service->network,
4792 service->ipconfig_ipv6);
4795 service_save(service);
4797 return __connman_error_invalid_property(msg);
4799 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4802 static void set_error(struct connman_service *service,
4803 enum connman_service_error error)
4807 if (service->error == error)
4810 service->error = error;
4815 #if !defined TIZEN_EXT
4816 if (!allow_property_changed(service))
4820 str = error2string(service->error);
4825 connman_dbus_property_changed_basic(service->path,
4826 CONNMAN_SERVICE_INTERFACE, "Error",
4827 DBUS_TYPE_STRING, &str);
4830 static void remove_timeout(struct connman_service *service)
4832 if (service->timeout > 0) {
4833 g_source_remove(service->timeout);
4834 service->timeout = 0;
4838 static void reply_pending(struct connman_service *service, int error)
4840 remove_timeout(service);
4842 if (service->pending) {
4843 connman_dbus_reply_pending(service->pending, error, NULL);
4844 service->pending = NULL;
4847 if (service->provider_pending) {
4848 connman_dbus_reply_pending(service->provider_pending,
4849 error, service->path);
4850 service->provider_pending = NULL;
4854 static void service_complete(struct connman_service *service)
4856 reply_pending(service, EIO);
4858 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
4859 __connman_service_auto_connect(service->connect_reason);
4861 g_get_current_time(&service->modified);
4862 service_save(service);
4865 static void set_idle(struct connman_service *service)
4867 service->state = service->state_ipv4 = service->state_ipv6 =
4868 CONNMAN_SERVICE_STATE_IDLE;
4869 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4870 state_changed(service);
4873 static DBusMessage *clear_property(DBusConnection *conn,
4874 DBusMessage *msg, void *user_data)
4876 struct connman_service *service = user_data;
4879 DBG("service %p", service);
4881 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
4884 if (g_str_equal(name, "Error")) {
4885 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4887 __connman_service_clear_error(service);
4888 service_complete(service);
4890 return __connman_error_invalid_property(msg);
4892 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4895 static bool is_ipconfig_usable(struct connman_service *service)
4897 if (!__connman_ipconfig_is_usable(service->ipconfig_ipv4) &&
4898 !__connman_ipconfig_is_usable(service->ipconfig_ipv6))
4904 static bool is_ignore(struct connman_service *service)
4906 if (!service->autoconnect)
4909 if (service->roaming)
4912 if (service->ignore)
4915 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
4918 if (!is_ipconfig_usable(service))
4924 static void disconnect_on_last_session(enum connman_service_type type)
4928 for (list = service_list; list; list = list->next) {
4929 struct connman_service *service = list->data;
4931 if (service->type != type)
4934 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_SESSION)
4937 __connman_service_disconnect(service);
4942 static int active_sessions[MAX_CONNMAN_SERVICE_TYPES] = {};
4943 static int always_connect[MAX_CONNMAN_SERVICE_TYPES] = {};
4944 static int active_count = 0;
4946 void __connman_service_set_active_session(bool enable, GSList *list)
4957 enum connman_service_type type = GPOINTER_TO_INT(list->data);
4960 case CONNMAN_SERVICE_TYPE_ETHERNET:
4961 case CONNMAN_SERVICE_TYPE_WIFI:
4962 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4963 case CONNMAN_SERVICE_TYPE_CELLULAR:
4964 case CONNMAN_SERVICE_TYPE_GADGET:
4966 active_sessions[type]++;
4968 active_sessions[type]--;
4971 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4972 case CONNMAN_SERVICE_TYPE_SYSTEM:
4973 case CONNMAN_SERVICE_TYPE_GPS:
4974 case CONNMAN_SERVICE_TYPE_VPN:
4975 case CONNMAN_SERVICE_TYPE_P2P:
4979 if (active_sessions[type] == 0)
4980 disconnect_on_last_session(type);
4982 list = g_slist_next(list);
4985 DBG("eth %d wifi %d bt %d cellular %d gadget %d sessions %d",
4986 active_sessions[CONNMAN_SERVICE_TYPE_ETHERNET],
4987 active_sessions[CONNMAN_SERVICE_TYPE_WIFI],
4988 active_sessions[CONNMAN_SERVICE_TYPE_BLUETOOTH],
4989 active_sessions[CONNMAN_SERVICE_TYPE_CELLULAR],
4990 active_sessions[CONNMAN_SERVICE_TYPE_GADGET],
4994 struct preferred_tech_data {
4995 GList *preferred_list;
4996 enum connman_service_type type;
4999 static void preferred_tech_add_by_type(gpointer data, gpointer user_data)
5001 struct connman_service *service = data;
5002 struct preferred_tech_data *tech_data = user_data;
5004 if (service->type == tech_data->type) {
5005 tech_data->preferred_list =
5006 g_list_append(tech_data->preferred_list, service);
5008 DBG("type %d service %p %s", tech_data->type, service,
5013 static GList *preferred_tech_list_get(void)
5015 unsigned int *tech_array;
5016 struct preferred_tech_data tech_data = { 0, };
5019 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
5023 if (connman_setting_get_bool("SingleConnectedTechnology")) {
5025 for (list = service_list; list; list = list->next) {
5026 struct connman_service *service = list->data;
5028 if (!is_connected(service->state))
5031 if (service->connect_reason ==
5032 CONNMAN_SERVICE_CONNECT_REASON_USER) {
5033 DBG("service %p name %s is user connected",
5034 service, service->name);
5035 #if defined TIZEN_EXT
5036 /* We can connect to a favorite service like
5037 * wifi even we have a userconnect for cellular
5038 * because we have refount for cellular service
5040 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5043 if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
5051 for (i = 0; tech_array[i] != 0; i += 1) {
5052 tech_data.type = tech_array[i];
5053 g_list_foreach(service_list, preferred_tech_add_by_type,
5057 return tech_data.preferred_list;
5060 static void set_always_connecting_technologies()
5062 unsigned int *always_connected_techs =
5063 connman_setting_get_uint_list("AlwaysConnectedTechnologies");
5065 for (i = 0; always_connected_techs && always_connected_techs[i]; i++)
5066 always_connect[always_connected_techs[i]] = 1;
5069 static bool autoconnect_no_session_active(struct connman_service *service)
5072 * Test active_count to see if there are no sessions set up and
5073 * stop autoconnecting, but continue connecting if the service
5074 * belongs to a technology which should always autoconnect.
5076 if (!active_count && !always_connect[service->type])
5082 static bool autoconnect_already_connecting(struct connman_service *service,
5083 bool autoconnecting)
5086 * If another service is already connecting and this service type has
5087 * not been marked as always connecting, stop the connecting procedure.
5089 if (autoconnecting &&
5090 !active_sessions[service->type] &&
5091 !always_connect[service->type])
5097 static bool auto_connect_service(GList *services,
5098 enum connman_service_connect_reason reason,
5101 struct connman_service *service = NULL;
5102 bool ignore[MAX_CONNMAN_SERVICE_TYPES] = { };
5103 bool autoconnecting = false;
5106 DBG("preferred %d sessions %d reason %s", preferred, active_count,
5107 reason2string(reason));
5109 ignore[CONNMAN_SERVICE_TYPE_VPN] = true;
5111 for (list = services; list; list = list->next) {
5112 service = list->data;
5114 if (ignore[service->type]) {
5115 DBG("service %p type %s ignore", service,
5116 __connman_service_type2string(service->type));
5120 #if defined TIZEN_EXT
5121 DBG("service %p %s %s %s, favorite(%d), ignore(%d), hidden(%d, %d)",
5122 service, service->name,
5123 state2string(service->state),
5124 __connman_service_type2string(service->type),
5125 service->favorite, is_ignore(service),
5126 service->hidden, service->hidden_service);
5128 /* Tizen takes Wi-Fi as the highest priority into consideration. */
5129 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
5130 if (is_connecting(service->state) == TRUE || is_connected(service->state) == TRUE)
5134 if (service->pending ||
5135 is_connecting(service->state) ||
5136 is_connected(service->state)) {
5137 if (autoconnect_no_session_active(service))
5140 ignore[service->type] = true;
5141 autoconnecting = true;
5143 DBG("service %p type %s busy", service,
5144 __connman_service_type2string(service->type));
5149 if (!service->favorite) {
5153 #if defined TIZEN_EXT
5154 DBG("Service is not favorite, autoconnecting %d",
5157 return autoconnecting;
5160 #if defined TIZEN_EXT
5161 DBG("service %p identifier %s roaming %d ignore %d "
5162 "ipconfig_usable %d autoconnect %d state %d",
5164 service->identifier, service->roaming,
5165 service->ignore, is_ipconfig_usable(service),
5166 service->autoconnect, service->state);
5168 if (is_ignore(service) || service->state !=
5169 CONNMAN_SERVICE_STATE_IDLE)
5172 if (autoconnect_already_connecting(service, autoconnecting)) {
5173 DBG("service %p type %s has no users", service,
5174 __connman_service_type2string(service->type));
5178 if (!is_service_owner_user_login(service)) {
5179 DBG("favorite user not login, wifi auto connect denied");
5183 DBG("service %p %s %s", service, service->name,
5184 (preferred) ? "preferred" : reason2string(reason));
5186 __connman_service_connect(service, reason);
5188 if (autoconnect_no_session_active(service))
5191 ignore[service->type] = true;
5194 return autoconnecting;
5197 static gboolean run_auto_connect(gpointer data)
5199 enum connman_service_connect_reason reason = GPOINTER_TO_UINT(data);
5200 bool autoconnecting = false;
5201 GList *preferred_tech;
5203 autoconnect_timeout = 0;
5207 preferred_tech = preferred_tech_list_get();
5208 if (preferred_tech) {
5209 autoconnecting = auto_connect_service(preferred_tech, reason,
5211 g_list_free(preferred_tech);
5214 if (!autoconnecting || active_count)
5215 auto_connect_service(service_list, reason, false);
5220 #if defined TIZEN_EXT
5221 bool __connman_service_get_auto_connect_mode(void)
5223 return auto_connect_mode;
5226 void __connman_service_set_auto_connect_mode(bool enable)
5228 DBG("set auto_connect_mode = %d", enable);
5230 if (auto_connect_mode != enable)
5231 auto_connect_mode = enable;
5235 void __connman_service_auto_connect(enum connman_service_connect_reason reason)
5239 if (autoconnect_timeout != 0)
5242 #if defined TIZEN_EXT
5243 if (auto_connect_mode == FALSE) {
5244 DBG("Currently, not auto connection mode");
5249 if (!__connman_session_policy_autoconnect(reason))
5252 #if defined TIZEN_EXT
5253 /* Adding Timeout of 500ms before trying to auto connect.
5254 * This is done because of below scenario
5255 * 1. Device is connected to AP1
5256 * 2. WPS Connection request is initiated for AP2
5257 * 3. Immediately WPS Connection is Cancelled
5258 * When WPS Connection Connection is initiated for AP2 then
5259 * sometimes there is a scenario where connman gets in ASSOCIATED
5260 * state with AP1 due to autoconnect and subsequently the connection
5261 * initiated by AP1 fails and connman service for AP1 comes in
5262 * FAILURE state due to this when connection with AP2 is cancelled
5263 * then autoconnect with AP1 doesn't works because its autoconnection
5264 * is ignored as its last state was FAILURE rather than IDLE */
5265 autoconnect_timeout = g_timeout_add(500, run_auto_connect,
5267 autoconnect_timeout = g_idle_add(run_auto_connect,
5269 GUINT_TO_POINTER(reason));
5272 static gboolean run_vpn_auto_connect(gpointer data) {
5274 bool need_split = false;
5276 vpn_autoconnect_timeout = 0;
5278 for (list = service_list; list; list = list->next) {
5279 struct connman_service *service = list->data;
5282 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
5285 if (is_connected(service->state) ||
5286 is_connecting(service->state)) {
5287 if (!service->do_split_routing)
5292 if (is_ignore(service) || !service->favorite)
5295 if (need_split && !service->do_split_routing) {
5296 DBG("service %p no split routing", service);
5300 DBG("service %p %s %s", service, service->name,
5301 service->do_split_routing ?
5302 "split routing" : "");
5304 res = __connman_service_connect(service,
5305 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5306 if (res < 0 && res != -EINPROGRESS)
5309 if (!service->do_split_routing)
5316 static void vpn_auto_connect(void)
5318 if (vpn_autoconnect_timeout)
5321 vpn_autoconnect_timeout =
5322 g_idle_add(run_vpn_auto_connect, NULL);
5326 __connman_service_is_provider_pending(struct connman_service *service)
5331 if (service->provider_pending)
5337 void __connman_service_set_provider_pending(struct connman_service *service,
5340 if (service->provider_pending) {
5341 DBG("service %p provider pending msg %p already exists",
5342 service, service->provider_pending);
5346 service->provider_pending = msg;
5350 static void check_pending_msg(struct connman_service *service)
5352 if (!service->pending)
5355 DBG("service %p pending msg %p already exists", service,
5357 dbus_message_unref(service->pending);
5360 void __connman_service_set_hidden_data(struct connman_service *service,
5363 DBusMessage *pending = user_data;
5365 DBG("service %p pending %p", service, pending);
5370 check_pending_msg(service);
5372 service->pending = pending;
5375 void __connman_service_return_error(struct connman_service *service,
5376 int error, gpointer user_data)
5378 DBG("service %p error %d user_data %p", service, error, user_data);
5380 __connman_service_set_hidden_data(service, user_data);
5382 reply_pending(service, error);
5385 static gboolean connect_timeout(gpointer user_data)
5387 struct connman_service *service = user_data;
5388 bool autoconnect = false;
5390 DBG("service %p", service);
5392 service->timeout = 0;
5394 if (service->network)
5395 __connman_network_disconnect(service->network);
5396 else if (service->provider)
5397 connman_provider_disconnect(service->provider);
5399 __connman_stats_service_unregister(service);
5401 if (service->pending) {
5404 reply = __connman_error_operation_timeout(service->pending);
5406 g_dbus_send_message(connection, reply);
5408 dbus_message_unref(service->pending);
5409 service->pending = NULL;
5413 __connman_service_ipconfig_indicate_state(service,
5414 CONNMAN_SERVICE_STATE_FAILURE,
5415 CONNMAN_IPCONFIG_TYPE_IPV4);
5416 __connman_service_ipconfig_indicate_state(service,
5417 CONNMAN_SERVICE_STATE_FAILURE,
5418 CONNMAN_IPCONFIG_TYPE_IPV6);
5421 service->connect_reason !=
5422 CONNMAN_SERVICE_CONNECT_REASON_USER)
5423 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5428 static DBusMessage *connect_service(DBusConnection *conn,
5429 DBusMessage *msg, void *user_data)
5431 struct connman_service *service = user_data;
5432 #if defined TIZEN_EXT
5439 DBG("service %p", service);
5441 #if defined TIZEN_EXT
5443 * Description: TIZEN implements system global connection management.
5445 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5446 connman_service_user_pdn_connection_ref(service);
5448 /*Reset the Disconnect Reason while issue connect request*/
5449 service->disconnect_reason = 0;
5451 /*Reset the association status code while issue connect request*/
5452 service->assoc_status_code = 0;
5455 if (service->pending)
5456 return __connman_error_in_progress(msg);
5458 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5460 if (connman_dbus_get_connection_unix_user_sync(conn,
5461 dbus_message_get_sender(msg),
5463 DBG("Can not get unix user id!");
5464 return __connman_error_permission_denied(msg);
5467 if (!__connman_service_is_user_allowed(CONNMAN_SERVICE_TYPE_WIFI, uid)) {
5468 DBG("Not allow this user to connect this wifi service now!");
5469 return __connman_error_permission_denied(msg);
5472 if (uid != USER_ROOT && uid != service->user.favorite_user)
5473 service->request_passphrase_input = true;
5475 service->user.current_user = uid;
5477 if (!service->passphrase && uid == service->user.favorite_user) {
5478 DBG("Now load this favorite user's passphrase.");
5479 service_load_passphrase(service);
5483 #if !defined TIZEN_EXT
5484 index = __connman_service_get_index(service);
5486 for (list = service_list; list; list = list->next) {
5487 struct connman_service *temp = list->data;
5489 #if defined TIZEN_EXT
5490 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5493 if (!is_connecting(temp->state) && !is_connected(temp->state))
5496 if (service == temp)
5499 if (service->type != temp->type)
5502 if (__connman_service_get_index(temp) == index &&
5503 __connman_service_disconnect(temp) == -EINPROGRESS)
5507 if (err == -EINPROGRESS)
5508 return __connman_error_operation_timeout(msg);
5511 service->ignore = false;
5513 service->pending = dbus_message_ref(msg);
5515 err = __connman_service_connect(service,
5516 CONNMAN_SERVICE_CONNECT_REASON_USER);
5518 if (err == -EINPROGRESS)
5521 if (service->pending) {
5522 dbus_message_unref(service->pending);
5523 service->pending = NULL;
5527 return __connman_error_failed(msg, -err);
5529 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5532 static DBusMessage *disconnect_service(DBusConnection *conn,
5533 DBusMessage *msg, void *user_data)
5535 struct connman_service *service = user_data;
5538 DBG("service %p", service);
5540 #if defined TIZEN_EXT
5542 * Description: TIZEN implements system global connection management.
5544 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
5545 if (connman_service_user_pdn_connection_unref_and_test(service) != TRUE)
5546 return __connman_error_failed(msg, EISCONN);
5548 if (is_connected(service->state) == TRUE &&
5549 service == connman_service_get_default_connection())
5550 return __connman_error_failed(msg, EISCONN);
5554 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5556 if (connman_dbus_get_connection_unix_user_sync(conn,
5557 dbus_message_get_sender(msg),
5559 DBG("Can not get unix user id!");
5560 return __connman_error_permission_denied(msg);
5563 if (!connman_service_is_user_allowed(service, uid)) {
5564 DBG("Not allow this user to disconnect this wifi service now!");
5565 return __connman_error_permission_denied(msg);
5569 service->ignore = true;
5571 err = __connman_service_disconnect(service);
5572 if (err < 0 && err != -EINPROGRESS)
5573 return __connman_error_failed(msg, -err);
5575 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5578 #if defined TIZEN_EXT
5579 static void __connman_service_cleanup_network_8021x(struct connman_service *service)
5581 if (service == NULL)
5584 DBG("service %p ", service);
5586 connman_network_set_string(service->network, "WiFi.EAP", NULL);
5587 connman_network_set_string(service->network, "WiFi.Identity", NULL);
5588 connman_network_set_string(service->network, "WiFi.CACertFile", NULL);
5589 connman_network_set_string(service->network, "WiFi.ClientCertFile", NULL);
5590 connman_network_set_string(service->network, "WiFi.PrivateKeyFile", NULL);
5591 connman_network_set_string(service->network, "WiFi.PrivateKeyPassphrase", NULL);
5592 connman_network_set_string(service->network, "WiFi.Phase2", NULL);
5596 bool __connman_service_remove(struct connman_service *service)
5598 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET ||
5599 service->type == CONNMAN_SERVICE_TYPE_GADGET)
5602 if (service->immutable || service->hidden ||
5603 __connman_provider_is_immutable(service->provider))
5606 #if !defined TIZEN_EXT
5607 if (!service->favorite && !is_idle(service->state))
5611 __connman_service_disconnect(service);
5613 g_free(service->passphrase);
5614 service->passphrase = NULL;
5616 g_free(service->identity);
5617 service->identity = NULL;
5619 g_free(service->anonymous_identity);
5620 service->anonymous_identity = NULL;
5622 g_free(service->subject_match);
5623 service->subject_match = NULL;
5625 g_free(service->altsubject_match);
5626 service->altsubject_match = NULL;
5628 g_free(service->domain_suffix_match);
5629 service->domain_suffix_match = NULL;
5631 g_free(service->domain_match);
5632 service->domain_match = NULL;
5634 g_free(service->agent_identity);
5635 service->agent_identity = NULL;
5637 g_free(service->eap);
5638 service->eap = NULL;
5640 #if defined TIZEN_EXT
5641 g_free(service->ca_cert_file);
5642 service->ca_cert_file = NULL;
5644 g_free(service->client_cert_file);
5645 service->client_cert_file = NULL;
5647 g_free(service->private_key_file);
5648 service->private_key_file = NULL;
5650 g_free(service->private_key_passphrase);
5651 service->private_key_passphrase = NULL;
5653 g_free(service->phase2);
5654 service->phase2 = NULL;
5656 __connman_service_cleanup_network_8021x(service);
5658 __connman_ipconfig_set_method(service->ipconfig_ipv4, CONNMAN_IPCONFIG_METHOD_DHCP);
5659 __connman_ipconfig_set_method(service->ipconfig_ipv6, CONNMAN_IPCONFIG_METHOD_AUTO);
5660 connman_service_set_proxy(service, NULL, false);
5662 __connman_service_nameserver_clear(service);
5664 g_strfreev(service->nameservers_config);
5665 service->nameservers_config = NULL;
5669 #if defined TIZEN_EXT
5670 if (service->security != CONNMAN_SERVICE_SECURITY_8021X)
5674 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
5676 service->user.favorite_user = USER_NONE;
5678 __connman_service_set_favorite(service, false);
5680 __connman_ipconfig_ipv6_reset_privacy(service->ipconfig_ipv6);
5682 #if defined TIZEN_EXT
5683 /* Reset IP Method and DNS Method to DHCP */
5684 __connman_ipconfig_set_method(service->ipconfig_ipv4,
5685 CONNMAN_IPCONFIG_METHOD_DHCP);
5686 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
5687 g_strfreev(service->nameservers_config);
5688 service->nameservers_config = NULL;
5691 #if defined TIZEN_EXT
5692 __connman_storage_remove_service(service->identifier);
5694 service_save(service);
5700 static DBusMessage *remove_service(DBusConnection *conn,
5701 DBusMessage *msg, void *user_data)
5703 struct connman_service *service = user_data;
5705 DBG("service %p", service);
5707 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5709 if (connman_dbus_get_connection_unix_user_sync(conn,
5710 dbus_message_get_sender(msg),
5712 DBG("Can not get unix user id!");
5713 return __connman_error_permission_denied(msg);
5716 #if !defined TIZEN_EXT
5717 if (!connman_service_is_user_allowed(service, uid)) {
5718 DBG("Not allow this user to remove this wifi service now!");
5719 return __connman_error_permission_denied(msg);
5724 if (!__connman_service_remove(service))
5725 return __connman_error_not_supported(msg);
5727 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5730 static bool check_suitable_state(enum connman_service_state a,
5731 enum connman_service_state b)
5734 * Special check so that "ready" service can be moved before
5737 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
5738 b == CONNMAN_SERVICE_STATE_READY) ||
5739 (b == CONNMAN_SERVICE_STATE_ONLINE &&
5740 a == CONNMAN_SERVICE_STATE_READY))
5746 static void downgrade_state(struct connman_service *service)
5751 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
5752 service->state_ipv6);
5754 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
5755 __connman_service_ipconfig_indicate_state(service,
5756 CONNMAN_SERVICE_STATE_READY,
5757 CONNMAN_IPCONFIG_TYPE_IPV4);
5759 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
5760 __connman_service_ipconfig_indicate_state(service,
5761 CONNMAN_SERVICE_STATE_READY,
5762 CONNMAN_IPCONFIG_TYPE_IPV6);
5765 static void apply_relevant_default_downgrade(struct connman_service *service)
5767 struct connman_service *def_service;
5769 def_service = __connman_service_get_default();
5773 if (def_service == service &&
5774 def_service->state == CONNMAN_SERVICE_STATE_ONLINE) {
5775 def_service->state = CONNMAN_SERVICE_STATE_READY;
5776 __connman_notifier_leave_online(def_service->type);
5777 state_changed(def_service);
5781 static void switch_default_service(struct connman_service *default_service,
5782 struct connman_service *downgrade_service)
5784 struct connman_service *service;
5787 apply_relevant_default_downgrade(default_service);
5788 src = g_list_find(service_list, downgrade_service);
5789 dst = g_list_find(service_list, default_service);
5792 if (src == dst || src->next == dst)
5795 service = src->data;
5796 service_list = g_list_delete_link(service_list, src);
5797 service_list = g_list_insert_before(service_list, dst, service);
5799 downgrade_state(downgrade_service);
5802 static DBusMessage *move_service(DBusConnection *conn,
5803 DBusMessage *msg, void *user_data,
5806 struct connman_service *service = user_data;
5807 struct connman_service *target;
5809 enum connman_ipconfig_method target4, target6;
5810 enum connman_ipconfig_method service4, service6;
5812 DBG("service %p", service);
5814 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
5817 if (!service->favorite)
5818 return __connman_error_not_supported(msg);
5820 target = find_service(path);
5821 if (!target || !target->favorite || target == service)
5822 return __connman_error_invalid_service(msg);
5824 if (target->type == CONNMAN_SERVICE_TYPE_VPN) {
5826 * We only allow VPN route splitting if there are
5827 * routes defined for a given VPN.
5829 if (!__connman_provider_check_routes(target->provider)) {
5830 connman_info("Cannot move service. "
5831 "No routes defined for provider %s",
5832 __connman_provider_get_ident(target->provider));
5833 return __connman_error_invalid_service(msg);
5836 set_split_routing(target, true);
5838 set_split_routing(target, false);
5840 set_split_routing(service, false);
5842 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
5843 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
5844 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
5845 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
5847 DBG("target %s method %d/%d state %d/%d split %d", target->identifier,
5848 target4, target6, target->state_ipv4, target->state_ipv6,
5849 target->do_split_routing);
5851 DBG("service %s method %d/%d state %d/%d", service->identifier,
5853 service->state_ipv4, service->state_ipv6);
5856 * If method is OFF, then we do not need to check the corresponding
5859 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5860 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5861 if (!check_suitable_state(target->state_ipv6,
5862 service->state_ipv6))
5863 return __connman_error_invalid_service(msg);
5867 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5868 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5869 if (!check_suitable_state(target->state_ipv4,
5870 service->state_ipv4))
5871 return __connman_error_invalid_service(msg);
5875 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5876 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5877 if (!check_suitable_state(target->state_ipv6,
5878 service->state_ipv6))
5879 return __connman_error_invalid_service(msg);
5883 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5884 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5885 if (!check_suitable_state(target->state_ipv4,
5886 service->state_ipv4))
5887 return __connman_error_invalid_service(msg);
5891 g_get_current_time(&service->modified);
5892 service_save(service);
5893 service_save(target);
5896 * If the service which goes down is the default service and is
5897 * online, we downgrade directly its state to ready so:
5898 * the service which goes up, needs to recompute its state which
5899 * is triggered via downgrading it - if relevant - to state ready.
5902 switch_default_service(target, service);
5904 switch_default_service(service, target);
5906 __connman_connection_update_gateway();
5908 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5911 static DBusMessage *move_before(DBusConnection *conn,
5912 DBusMessage *msg, void *user_data)
5914 return move_service(conn, msg, user_data, true);
5917 static DBusMessage *move_after(DBusConnection *conn,
5918 DBusMessage *msg, void *user_data)
5920 return move_service(conn, msg, user_data, false);
5923 static DBusMessage *reset_counters(DBusConnection *conn,
5924 DBusMessage *msg, void *user_data)
5926 struct connman_service *service = user_data;
5928 reset_stats(service);
5930 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5933 static DBusMessage *get_user_favorite(DBusConnection *conn,
5934 DBusMessage *msg, void *user_data)
5937 uid_t uid = USER_NONE;
5938 dbus_bool_t user_favorite = false;
5939 struct connman_service *service = user_data;
5941 connman_dbus_get_connection_unix_user_sync(conn,
5942 dbus_message_get_sender(msg),
5944 if (uid == USER_ROOT)
5945 user_favorite = service->favorite;
5946 else if (uid != USER_NONE && uid == service->user.favorite_user) {
5947 DBG("The service is favorite to this user!");
5948 user_favorite = true;
5951 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5952 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN,
5953 &user_favorite, DBUS_TYPE_INVALID);
5957 static struct _services_notify {
5963 static void service_append_added_foreach(gpointer data, gpointer user_data)
5965 struct connman_service *service = data;
5966 DBusMessageIter *iter = user_data;
5968 if (!service || !service->path) {
5969 #if !defined TIZEN_EXT
5970 DBG("service %p or path is NULL", service);
5975 if (g_hash_table_lookup(services_notify->add, service->path)) {
5976 #if !defined TIZEN_EXT
5977 DBG("new %s", service->path);
5980 append_struct(service, iter);
5981 g_hash_table_remove(services_notify->add, service->path);
5983 #if !defined TIZEN_EXT
5984 DBG("changed %s", service->path);
5987 append_struct_service(iter, NULL, service);
5991 static void service_append_ordered(DBusMessageIter *iter, void *user_data)
5993 g_list_foreach(service_list, service_append_added_foreach, iter);
5996 static void append_removed(gpointer key, gpointer value, gpointer user_data)
5998 char *objpath = key;
5999 DBusMessageIter *iter = user_data;
6001 DBG("removed %s", objpath);
6002 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath);
6005 static void service_append_removed(DBusMessageIter *iter, void *user_data)
6007 g_hash_table_foreach(services_notify->remove, append_removed, iter);
6010 static gboolean service_send_changed(gpointer data)
6012 DBusMessage *signal;
6016 services_notify->id = 0;
6018 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
6019 CONNMAN_MANAGER_INTERFACE, "ServicesChanged");
6023 __connman_dbus_append_objpath_dict_array(signal,
6024 service_append_ordered, NULL);
6025 __connman_dbus_append_objpath_array(signal,
6026 service_append_removed, NULL);
6028 dbus_connection_send(connection, signal, NULL);
6029 dbus_message_unref(signal);
6031 g_hash_table_remove_all(services_notify->remove);
6032 g_hash_table_remove_all(services_notify->add);
6037 static void service_schedule_changed(void)
6039 if (services_notify->id != 0)
6042 services_notify->id = g_timeout_add(100, service_send_changed, NULL);
6045 static void service_schedule_added(struct connman_service *service)
6047 DBG("service %p", service);
6049 g_hash_table_remove(services_notify->remove, service->path);
6050 g_hash_table_replace(services_notify->add, service->path, service);
6052 service_schedule_changed();
6055 static void service_schedule_removed(struct connman_service *service)
6057 if (!service || !service->path) {
6058 DBG("service %p or path is NULL", service);
6062 DBG("service %p %s", service, service->path);
6064 g_hash_table_remove(services_notify->add, service->path);
6065 g_hash_table_replace(services_notify->remove, g_strdup(service->path),
6068 service_schedule_changed();
6071 static bool allow_property_changed(struct connman_service *service)
6073 #if defined TIZEN_EXT
6074 if (service->path == NULL)
6077 if (g_hash_table_lookup_extended(services_notify->add, service->path,
6084 static const GDBusMethodTable service_methods[] = {
6085 { GDBUS_DEPRECATED_METHOD("GetProperties",
6086 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
6088 { GDBUS_METHOD("SetProperty",
6089 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
6090 NULL, set_property) },
6091 { GDBUS_METHOD("ClearProperty",
6092 GDBUS_ARGS({ "name", "s" }), NULL,
6094 { GDBUS_ASYNC_METHOD("Connect", NULL, NULL,
6096 { GDBUS_METHOD("Disconnect", NULL, NULL,
6097 disconnect_service) },
6098 { GDBUS_METHOD("Remove", NULL, NULL, remove_service) },
6099 { GDBUS_METHOD("MoveBefore",
6100 GDBUS_ARGS({ "service", "o" }), NULL,
6102 { GDBUS_METHOD("MoveAfter",
6103 GDBUS_ARGS({ "service", "o" }), NULL,
6105 { GDBUS_METHOD("ResetCounters", NULL, NULL, reset_counters) },
6106 { GDBUS_METHOD("GetUserFavorite",
6107 NULL, GDBUS_ARGS({ "value", "v" }),
6108 get_user_favorite) },
6112 static const GDBusSignalTable service_signals[] = {
6113 { GDBUS_SIGNAL("PropertyChanged",
6114 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
6118 static void service_free(gpointer user_data)
6120 struct connman_service *service = user_data;
6121 char *path = service->path;
6123 DBG("service %p", service);
6125 reply_pending(service, ENOENT);
6127 if (service->nameservers_timeout) {
6128 g_source_remove(service->nameservers_timeout);
6129 dns_changed(service);
6132 __connman_notifier_service_remove(service);
6133 service_schedule_removed(service);
6135 __connman_wispr_stop(service);
6136 stats_stop(service);
6138 service->path = NULL;
6141 __connman_connection_update_gateway();
6143 g_dbus_unregister_interface(connection, path,
6144 CONNMAN_SERVICE_INTERFACE);
6148 g_hash_table_destroy(service->counter_table);
6150 if (service->network) {
6151 __connman_network_disconnect(service->network);
6152 connman_network_unref(service->network);
6153 service->network = NULL;
6156 if (service->provider)
6157 connman_provider_unref(service->provider);
6159 if (service->ipconfig_ipv4) {
6160 __connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
6161 __connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
6162 __connman_ipconfig_unref(service->ipconfig_ipv4);
6163 service->ipconfig_ipv4 = NULL;
6166 if (service->ipconfig_ipv6) {
6167 __connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
6168 __connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
6169 __connman_ipconfig_unref(service->ipconfig_ipv6);
6170 service->ipconfig_ipv6 = NULL;
6173 g_strfreev(service->timeservers);
6174 g_strfreev(service->timeservers_config);
6175 g_strfreev(service->nameservers);
6176 g_strfreev(service->nameservers_config);
6177 g_strfreev(service->nameservers_auto);
6178 g_strfreev(service->domains);
6179 g_strfreev(service->proxies);
6180 g_strfreev(service->excludes);
6182 g_free(service->hostname);
6183 g_free(service->domainname);
6184 g_free(service->pac);
6185 g_free(service->name);
6186 g_free(service->passphrase);
6187 g_free(service->identifier);
6188 g_free(service->eap);
6189 g_free(service->identity);
6190 g_free(service->anonymous_identity);
6191 g_free(service->agent_identity);
6192 g_free(service->ca_cert_file);
6193 g_free(service->subject_match);
6194 g_free(service->altsubject_match);
6195 g_free(service->domain_suffix_match);
6196 g_free(service->domain_match);
6197 g_free(service->client_cert_file);
6198 g_free(service->private_key_file);
6199 g_free(service->private_key_passphrase);
6200 g_free(service->phase2);
6201 g_free(service->config_file);
6202 g_free(service->config_entry);
6204 if (service->stats.timer)
6205 g_timer_destroy(service->stats.timer);
6206 if (service->stats_roaming.timer)
6207 g_timer_destroy(service->stats_roaming.timer);
6209 if (current_default == service)
6210 current_default = NULL;
6215 static void stats_init(struct connman_service *service)
6218 service->stats.valid = false;
6219 service->stats.enabled = false;
6220 service->stats.timer = g_timer_new();
6223 service->stats_roaming.valid = false;
6224 service->stats_roaming.enabled = false;
6225 service->stats_roaming.timer = g_timer_new();
6228 static void service_initialize(struct connman_service *service)
6230 DBG("service %p", service);
6232 service->refcount = 1;
6234 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
6236 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
6237 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
6239 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
6240 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
6241 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
6243 service->favorite = false;
6244 service->immutable = false;
6245 service->hidden = false;
6247 service->ignore = false;
6249 service->user.favorite_user = USER_NONE;
6250 service->user.current_user = USER_NONE;
6252 service->request_passphrase_input = false;
6254 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
6258 stats_init(service);
6260 service->provider = NULL;
6262 service->wps = false;
6263 #if defined TIZEN_EXT
6264 service->storage_reload = false;
6266 * Description: TIZEN implements system global connection management.
6268 service->user_pdn_connection_refcount = 0;
6269 __sync_synchronize();
6274 * connman_service_create:
6276 * Allocate a new service.
6278 * Returns: a newly-allocated #connman_service structure
6280 struct connman_service *connman_service_create(void)
6283 struct connman_stats_counter *counters;
6284 const char *counter;
6286 struct connman_service *service;
6288 service = g_try_new0(struct connman_service, 1);
6292 DBG("service %p", service);
6294 service->counter_table = g_hash_table_new_full(g_str_hash,
6295 g_str_equal, NULL, g_free);
6297 for (list = counter_list; list; list = list->next) {
6298 counter = list->data;
6300 counters = g_try_new0(struct connman_stats_counter, 1);
6302 g_hash_table_destroy(service->counter_table);
6307 counters->append_all = true;
6309 g_hash_table_replace(service->counter_table, (gpointer)counter,
6313 service_initialize(service);
6319 * connman_service_ref:
6320 * @service: service structure
6322 * Increase reference counter of service
6324 struct connman_service *
6325 connman_service_ref_debug(struct connman_service *service,
6326 const char *file, int line, const char *caller)
6328 DBG("%p ref %d by %s:%d:%s()", service, service->refcount + 1,
6329 file, line, caller);
6331 __sync_fetch_and_add(&service->refcount, 1);
6337 * connman_service_unref:
6338 * @service: service structure
6340 * Decrease reference counter of service and release service if no
6343 void connman_service_unref_debug(struct connman_service *service,
6344 const char *file, int line, const char *caller)
6346 DBG("%p ref %d by %s:%d:%s()", service, service->refcount - 1,
6347 file, line, caller);
6349 if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
6352 service_list = g_list_remove(service_list, service);
6354 __connman_service_disconnect(service);
6356 g_hash_table_remove(service_hash, service->identifier);
6359 static gint service_compare(gconstpointer a, gconstpointer b)
6361 struct connman_service *service_a = (void *) a;
6362 struct connman_service *service_b = (void *) b;
6363 enum connman_service_state state_a, state_b;
6364 bool a_connected, b_connected;
6367 state_a = service_a->state;
6368 state_b = service_b->state;
6369 a_connected = is_connected(state_a);
6370 b_connected = is_connected(state_b);
6372 if (a_connected && b_connected) {
6373 if (service_a->order > service_b->order)
6376 if (service_a->order < service_b->order)
6380 if (state_a != state_b) {
6381 if (a_connected && b_connected) {
6382 /* We prefer online over ready state */
6383 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
6386 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
6395 if (is_connecting(state_a))
6397 if (is_connecting(state_b))
6401 if (service_a->favorite && !service_b->favorite)
6404 if (!service_a->favorite && service_b->favorite)
6407 if (service_a->type != service_b->type) {
6408 unsigned int *tech_array;
6411 tech_array = connman_setting_get_uint_list(
6412 "PreferredTechnologies");
6414 for (i = 0; tech_array[i]; i++) {
6415 if (tech_array[i] == service_a->type)
6418 if (tech_array[i] == service_b->type)
6423 if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6425 if (service_b->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6428 if (service_a->type == CONNMAN_SERVICE_TYPE_WIFI)
6430 if (service_b->type == CONNMAN_SERVICE_TYPE_WIFI)
6433 if (service_a->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6435 if (service_b->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6438 if (service_a->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6440 if (service_b->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6443 if (service_a->type == CONNMAN_SERVICE_TYPE_VPN)
6445 if (service_b->type == CONNMAN_SERVICE_TYPE_VPN)
6448 if (service_a->type == CONNMAN_SERVICE_TYPE_GADGET)
6450 if (service_b->type == CONNMAN_SERVICE_TYPE_GADGET)
6454 strength = (gint) service_b->strength - (gint) service_a->strength;
6458 return g_strcmp0(service_a->name, service_b->name);
6461 static void service_list_sort(void)
6463 if (service_list && service_list->next) {
6464 service_list = g_list_sort(service_list, service_compare);
6465 service_schedule_changed();
6469 int __connman_service_compare(const struct connman_service *a,
6470 const struct connman_service *b)
6472 return service_compare(a, b);
6476 * connman_service_get_type:
6477 * @service: service structure
6479 * Get the type of service
6481 enum connman_service_type connman_service_get_type(struct connman_service *service)
6484 return CONNMAN_SERVICE_TYPE_UNKNOWN;
6486 return service->type;
6490 * connman_service_get_interface:
6491 * @service: service structure
6493 * Get network interface of service
6495 char *connman_service_get_interface(struct connman_service *service)
6502 index = __connman_service_get_index(service);
6504 return connman_inet_ifname(index);
6508 * __connman_service_is_user_allowed:
6509 * @type: service type
6512 * Check a user is allowed to operate a type of service
6514 bool __connman_service_is_user_allowed(enum connman_service_type type,
6518 uid_t owner_user = USER_NONE;
6520 for (list = service_list; list; list = list->next) {
6521 struct connman_service *service = list->data;
6523 if (service->type != type)
6526 if (is_connected(service->state)) {
6527 owner_user = service->user.favorite_user;
6532 if (uid == USER_NONE ||
6533 (uid != USER_ROOT &&
6534 owner_user != USER_NONE &&
6542 * connman_service_get_network:
6543 * @service: service structure
6545 * Get the service network
6547 struct connman_network *
6548 __connman_service_get_network(struct connman_service *service)
6553 return service->network;
6556 struct connman_ipconfig *
6557 __connman_service_get_ip4config(struct connman_service *service)
6562 return service->ipconfig_ipv4;
6565 struct connman_ipconfig *
6566 __connman_service_get_ip6config(struct connman_service *service)
6571 return service->ipconfig_ipv6;
6574 struct connman_ipconfig *
6575 __connman_service_get_ipconfig(struct connman_service *service, int family)
6577 if (family == AF_INET)
6578 return __connman_service_get_ip4config(service);
6579 else if (family == AF_INET6)
6580 return __connman_service_get_ip6config(service);
6586 bool __connman_service_is_connected_state(struct connman_service *service,
6587 enum connman_ipconfig_type type)
6593 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
6595 case CONNMAN_IPCONFIG_TYPE_IPV4:
6596 return is_connected(service->state_ipv4);
6597 case CONNMAN_IPCONFIG_TYPE_IPV6:
6598 return is_connected(service->state_ipv6);
6599 case CONNMAN_IPCONFIG_TYPE_ALL:
6600 return is_connected(service->state_ipv4) &&
6601 is_connected(service->state_ipv6);
6606 enum connman_service_security __connman_service_get_security(
6607 struct connman_service *service)
6610 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
6612 return service->security;
6615 const char *__connman_service_get_phase2(struct connman_service *service)
6620 return service->phase2;
6623 bool __connman_service_wps_enabled(struct connman_service *service)
6628 return service->wps;
6631 void __connman_service_mark_dirty(void)
6633 services_dirty = true;
6636 #if defined TIZEN_EXT
6638 * Returns profile count if there is any connected profiles
6639 * that use same interface
6641 int __connman_service_get_connected_count_of_iface(
6642 struct connman_service *service)
6651 index1 = __connman_service_get_index(service);
6656 for (list = service_list; list; list = list->next) {
6657 struct connman_service *service2 = list->data;
6659 if (service == service2)
6662 index2 = __connman_service_get_index(service2);
6664 if (is_connected(service2->state) && index2 > 0 && index1 == index2)
6670 DBG("Interface index %d, count %d", index1, count);
6675 void __connman_service_set_storage_reload(struct connman_service *service,
6676 bool storage_reload)
6678 if (service != NULL)
6679 service->storage_reload = storage_reload;
6684 * __connman_service_set_favorite_delayed:
6685 * @service: service structure
6686 * @favorite: favorite value
6687 * @delay_ordering: do not order service sequence
6689 * Change the favorite setting of service
6691 int __connman_service_set_favorite_delayed(struct connman_service *service,
6693 bool delay_ordering)
6695 #if defined TIZEN_EXT
6696 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6699 if (service->hidden)
6702 if (service->favorite == favorite)
6705 service->favorite = favorite;
6707 if (!delay_ordering)
6708 __connman_service_get_order(service);
6710 favorite_changed(service);
6712 if (!delay_ordering) {
6714 service_list_sort();
6716 __connman_connection_update_gateway();
6723 * __connman_service_set_favorite:
6724 * @service: service structure
6725 * @favorite: favorite value
6727 * Change the favorite setting of service
6729 int __connman_service_set_favorite(struct connman_service *service,
6732 return __connman_service_set_favorite_delayed(service, favorite,
6736 bool connman_service_get_favorite(struct connman_service *service)
6738 return service->favorite;
6741 bool connman_service_get_autoconnect(struct connman_service *service)
6743 return service->autoconnect;
6746 int __connman_service_set_immutable(struct connman_service *service,
6749 if (service->hidden)
6752 if (service->immutable == immutable)
6755 service->immutable = immutable;
6757 immutable_changed(service);
6762 int __connman_service_set_ignore(struct connman_service *service,
6768 service->ignore = ignore;
6773 void __connman_service_set_string(struct connman_service *service,
6774 const char *key, const char *value)
6776 if (service->hidden)
6778 if (g_str_equal(key, "EAP")) {
6779 g_free(service->eap);
6780 service->eap = g_strdup(value);
6781 } else if (g_str_equal(key, "Identity")) {
6782 g_free(service->identity);
6783 service->identity = g_strdup(value);
6784 } else if (g_str_equal(key, "AnonymousIdentity")) {
6785 g_free(service->anonymous_identity);
6786 service->anonymous_identity = g_strdup(value);
6787 } else if (g_str_equal(key, "CACertFile")) {
6788 g_free(service->ca_cert_file);
6789 service->ca_cert_file = g_strdup(value);
6790 } else if (g_str_equal(key, "SubjectMatch")) {
6791 g_free(service->subject_match);
6792 service->subject_match = g_strdup(value);
6793 } else if (g_str_equal(key, "AltSubjectMatch")) {
6794 g_free(service->altsubject_match);
6795 service->altsubject_match = g_strdup(value);
6796 } else if (g_str_equal(key, "DomainSuffixMatch")) {
6797 g_free(service->domain_suffix_match);
6798 service->domain_suffix_match = g_strdup(value);
6799 } else if (g_str_equal(key, "DomainMatch")) {
6800 g_free(service->domain_match);
6801 service->domain_match = g_strdup(value);
6802 } else if (g_str_equal(key, "ClientCertFile")) {
6803 g_free(service->client_cert_file);
6804 service->client_cert_file = g_strdup(value);
6805 } else if (g_str_equal(key, "PrivateKeyFile")) {
6806 g_free(service->private_key_file);
6807 service->private_key_file = g_strdup(value);
6808 } else if (g_str_equal(key, "PrivateKeyPassphrase")) {
6809 g_free(service->private_key_passphrase);
6810 service->private_key_passphrase = g_strdup(value);
6811 } else if (g_str_equal(key, "Phase2")) {
6812 g_free(service->phase2);
6813 service->phase2 = g_strdup(value);
6814 } else if (g_str_equal(key, "Passphrase"))
6815 __connman_service_set_passphrase(service, value);
6818 void __connman_service_set_search_domains(struct connman_service *service,
6821 searchdomain_remove_all(service);
6823 if (service->domains)
6824 g_strfreev(service->domains);
6826 service->domains = g_strdupv(domains);
6828 searchdomain_add_all(service);
6831 static void report_error_cb(void *user_context, bool retry,
6834 struct connman_service *service = user_context;
6837 __connman_service_connect(service,
6838 CONNMAN_SERVICE_CONNECT_REASON_USER);
6840 /* It is not relevant to stay on Failure state
6841 * when failing is due to wrong user input */
6842 __connman_service_clear_error(service);
6843 #if defined TIZEN_EXT
6844 /* Reseting the state back in case of failure state */
6845 service->state_ipv4 = service->state_ipv6 =
6846 CONNMAN_SERVICE_STATE_IDLE;
6848 if (service->error != CONNMAN_SERVICE_ERROR_AUTH_FAILED)
6849 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6851 service_complete(service);
6852 __connman_connection_update_gateway();
6856 static int check_wpspin(struct connman_service *service, const char *wpspin)
6864 length = strlen(wpspin);
6866 /* If 0, it will mean user wants to use PBC method */
6868 connman_network_set_string(service->network,
6869 "WiFi.PinWPS", NULL);
6873 /* A WPS PIN is always 8 chars length,
6874 * its content is in digit representation.
6879 for (i = 0; i < 8; i++)
6880 if (!isdigit((unsigned char) wpspin[i]))
6883 connman_network_set_string(service->network, "WiFi.PinWPS", wpspin);
6888 static void request_input_cb(struct connman_service *service,
6889 bool values_received,
6890 const char *name, int name_len,
6891 const char *identity, const char *passphrase,
6892 bool wps, const char *wpspin,
6893 const char *error, void *user_data)
6895 struct connman_device *device;
6896 const char *security;
6899 DBG("RequestInput return, %p", service);
6902 DBG("error: %s", error);
6904 if (g_strcmp0(error,
6905 "net.connman.Agent.Error.Canceled") == 0) {
6908 if (service->hidden)
6909 __connman_service_return_error(service,
6914 if (service->hidden)
6915 __connman_service_return_error(service,
6916 ETIMEDOUT, user_data);
6920 if (service->hidden && name_len > 0 && name_len <= 32) {
6921 device = connman_network_get_device(service->network);
6922 security = connman_network_get_string(service->network,
6924 err = __connman_device_request_hidden_scan(device,
6926 identity, passphrase,
6927 security, user_data);
6929 __connman_service_return_error(service, -err,
6933 if (!values_received || service->hidden) {
6938 if (wps && service->network) {
6939 err = check_wpspin(service, wpspin);
6943 connman_network_set_bool(service->network, "WiFi.UseWPS", wps);
6947 __connman_service_set_agent_identity(service, identity);
6950 err = __connman_service_set_passphrase(service, passphrase);
6954 /* We forget any previous error. */
6955 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6957 __connman_service_connect(service,
6958 CONNMAN_SERVICE_CONNECT_REASON_USER);
6960 } else if (err == -ENOKEY) {
6961 __connman_service_indicate_error(service,
6962 CONNMAN_SERVICE_ERROR_INVALID_KEY);
6964 /* It is not relevant to stay on Failure state
6965 * when failing is due to wrong user input */
6966 service->state = CONNMAN_SERVICE_STATE_IDLE;
6968 if (!service->hidden) {
6970 * If there was a real error when requesting
6971 * hidden scan, then that error is returned already
6972 * to the user somewhere above so do not try to
6975 __connman_service_return_error(service, -err,
6979 service_complete(service);
6980 __connman_connection_update_gateway();
6984 static void downgrade_connected_services(void)
6986 struct connman_service *up_service;
6989 for (list = service_list; list; list = list->next) {
6990 up_service = list->data;
6992 if (!is_connected(up_service->state))
6995 if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
6998 downgrade_state(up_service);
7002 static int service_update_preferred_order(struct connman_service *default_service,
7003 struct connman_service *new_service,
7004 enum connman_service_state new_state)
7006 unsigned int *tech_array;
7009 if (!default_service || default_service == new_service ||
7010 default_service->state != new_state)
7013 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
7016 for (i = 0; tech_array[i] != 0; i += 1) {
7017 if (default_service->type == tech_array[i])
7020 if (new_service->type == tech_array[i]) {
7021 switch_default_service(default_service,
7023 __connman_connection_update_gateway();
7032 #if defined TIZEN_EXT
7033 static gboolean __connman_service_can_drop(struct connman_service *service)
7035 if (is_connected(service->state) == TRUE || is_connecting(service->state) == TRUE) {
7036 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
7038 else if (connman_service_is_no_ref_user_pdn_connection(service) == TRUE)
7044 static struct connman_device *default_connecting_device = NULL;
7046 static void __connman_service_disconnect_default(struct connman_service *service)
7048 struct connman_device *default_device = NULL;
7050 if (default_connecting_device == NULL)
7053 default_device = connman_network_get_device(
7054 __connman_service_get_network(service));
7056 DBG("Disconnecting service %p %s", service, service->path);
7057 DBG("Disconnecting device %p %p %s",
7058 default_connecting_device,
7060 connman_device_get_string(default_device, "Name"));
7062 if (default_connecting_device == default_device)
7063 default_connecting_device = NULL;
7066 static void __connman_service_connect_default(struct connman_service *current)
7070 bool default_internet;
7071 struct connman_service *service;
7072 struct connman_service *default_service = NULL;
7073 struct connman_device *default_device = NULL;
7075 if (current->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
7076 switch (current->state) {
7077 case CONNMAN_SERVICE_STATE_UNKNOWN:
7078 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7079 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7085 if (default_connecting_device &&
7086 __connman_service_is_internet_profile(current) == TRUE) {
7087 if (current->network == NULL)
7090 default_device = connman_network_get_device(current->network);
7091 if (default_connecting_device == default_device) {
7092 DBG("Cellular service[%s] %p %s",
7093 state2string(current->state), current, current->path);
7094 DBG("Cellular device %p %p %s",
7095 default_connecting_device, default_device,
7096 connman_device_get_string(default_device, "Name"));
7098 default_connecting_device = NULL;
7103 } else if (is_connected(current->state) == TRUE || is_connecting(current->state) == TRUE)
7106 /* Always-on: keep default cellular connection as possible */
7107 for (list = service_list; list; list = list->next) {
7108 service = list->data;
7110 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7111 __connman_service_is_internet_profile(service) != TRUE ||
7112 service->network == NULL) {
7117 connman_network_get_bool(service->network, "DefaultInternet");
7119 DBG("service: %p %s %s %s (default: %d)", service, service->name,
7120 __connman_service_type2string(service->type),
7121 state2string(service->state), default_internet);
7123 if (default_internet) {
7124 default_service = service;
7125 if (is_connected(default_service->state) == TRUE ||
7126 is_connecting(default_service->state) == TRUE)
7129 default_device = connman_network_get_device(default_service->network);
7130 if (default_connecting_device == default_device) {
7131 DBG("Device is connecting (%p)", default_connecting_device);
7135 default_connecting_device = default_device;
7136 default_service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_USER;
7138 err = __connman_network_connect(default_service->network);
7139 DBG("Connecting default service %p %s [%d]",
7140 default_service, default_service->path, err);
7141 DBG("Connecting device %p %s", default_connecting_device,
7142 connman_device_get_string(default_connecting_device, "Name"));
7143 if (err < 0 && err != -EINPROGRESS) {
7144 default_connecting_device = NULL;
7152 static void single_connected_tech(struct connman_service *allowed)
7154 struct connman_service *service;
7155 GSList *services = NULL, *list;
7158 DBG("keeping %p %s", allowed, allowed->path);
7160 #if defined TIZEN_EXT
7161 if (!allowed || allowed->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7165 for (iter = service_list; iter; iter = iter->next) {
7166 service = iter->data;
7168 #if defined TIZEN_EXT
7169 if (service != allowed && service->type != allowed->type &&
7170 __connman_service_can_drop(service) == TRUE)
7172 if (!is_connected(service->state))
7175 if (service == allowed)
7178 services = g_slist_prepend(services, service);
7181 for (list = services; list; list = list->next) {
7182 service = list->data;
7184 DBG("disconnecting %p %s", service, service->path);
7185 #if defined TIZEN_EXT
7186 __connman_service_disconnect_default(service);
7188 __connman_service_disconnect(service);
7191 g_slist_free(services);
7194 #if defined TIZEN_EXT
7195 static void set_priority_connected_service(void)
7197 struct connman_service *service;
7200 for (list = service_list; list; list = list->next) {
7201 service = list->data;
7203 if (is_connected(service->state) == FALSE)
7211 static const char *get_dbus_sender(struct connman_service *service)
7213 if (!service->pending)
7216 return dbus_message_get_sender(service->pending);
7219 static int service_indicate_state(struct connman_service *service)
7221 enum connman_service_state old_state, new_state;
7222 struct connman_service *def_service;
7223 enum connman_ipconfig_method method;
7229 old_state = service->state;
7230 new_state = combine_state(service->state_ipv4, service->state_ipv6);
7232 DBG("service %p old %s - new %s/%s => %s",
7234 state2string(old_state),
7235 state2string(service->state_ipv4),
7236 state2string(service->state_ipv6),
7237 state2string(new_state));
7239 if (old_state == new_state)
7242 def_service = __connman_service_get_default();
7244 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
7245 result = service_update_preferred_order(def_service,
7246 service, new_state);
7247 if (result == -EALREADY)
7251 if (old_state == CONNMAN_SERVICE_STATE_ONLINE)
7252 __connman_notifier_leave_online(service->type);
7254 if (is_connected(old_state) && !is_connected(new_state))
7255 searchdomain_remove_all(service);
7257 service->state = new_state;
7258 state_changed(service);
7260 if (!is_connected(old_state) && is_connected(new_state))
7261 searchdomain_add_all(service);
7264 case CONNMAN_SERVICE_STATE_UNKNOWN:
7268 case CONNMAN_SERVICE_STATE_IDLE:
7269 if (old_state != CONNMAN_SERVICE_STATE_DISCONNECT)
7270 __connman_service_disconnect(service);
7274 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7278 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7279 if (!service->new_service &&
7280 __connman_stats_service_register(service) == 0) {
7282 * For new services the statistics are updated after
7283 * we have successfully connected.
7285 __connman_stats_get(service, false,
7286 &service->stats.data);
7287 __connman_stats_get(service, true,
7288 &service->stats_roaming.data);
7293 case CONNMAN_SERVICE_STATE_READY:
7294 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7296 if (service->new_service &&
7297 __connman_stats_service_register(service) == 0) {
7299 * This is normally done after configuring state
7300 * but for new service do this after we have connected
7303 __connman_stats_get(service, false,
7304 &service->stats.data);
7305 __connman_stats_get(service, true,
7306 &service->stats_roaming.data);
7309 service->new_service = false;
7313 def_service = __connman_service_get_default();
7315 service_update_preferred_order(def_service, service, new_state);
7317 __connman_service_set_favorite(service, true);
7319 reply_pending(service, 0);
7321 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7322 connman_network_get_bool(service->network,
7326 pass = connman_network_get_string(service->network,
7329 __connman_service_set_passphrase(service, pass);
7331 connman_network_set_bool(service->network,
7332 "WiFi.UseWPS", false);
7335 g_get_current_time(&service->modified);
7336 service_save(service);
7338 domain_changed(service);
7339 proxy_changed(service);
7341 if (old_state != CONNMAN_SERVICE_STATE_ONLINE)
7342 __connman_notifier_connect(service->type);
7344 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
7345 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
7346 __connman_ipconfig_disable_ipv6(
7347 service->ipconfig_ipv6);
7349 if (connman_setting_get_bool("SingleConnectedTechnology"))
7350 single_connected_tech(service);
7351 else if (service->type != CONNMAN_SERVICE_TYPE_VPN)
7354 #if defined TIZEN_EXT
7355 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7356 set_priority_connected_service();
7361 case CONNMAN_SERVICE_STATE_ONLINE:
7365 case CONNMAN_SERVICE_STATE_DISCONNECT:
7366 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7368 reply_pending(service, ECONNABORTED);
7370 def_service = __connman_service_get_default();
7371 service->disconnect_reason = connman_network_get_disconnect_reason(service->network);
7372 service->assoc_status_code = connman_network_get_assoc_status_code(service->network);
7374 if (!__connman_notifier_is_connected() &&
7376 def_service->provider)
7377 connman_provider_disconnect(def_service->provider);
7381 __connman_wispr_stop(service);
7383 __connman_wpad_stop(service);
7385 #if defined TIZEN_EXT
7387 * Skip the functions if there is any connected profiles
7388 * that use same interface
7390 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7391 __connman_service_get_connected_count_of_iface(
7394 domain_changed(service);
7395 proxy_changed(service);
7396 #if defined TIZEN_EXT
7401 * Previous services which are connected and which states
7402 * are set to online should reset relevantly ipconfig_state
7403 * to ready so wispr/portal will be rerun on those
7405 downgrade_connected_services();
7407 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7410 case CONNMAN_SERVICE_STATE_FAILURE:
7411 #if defined TIZEN_EXT
7412 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7414 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7416 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7417 connman_agent_report_error(service, service->path,
7418 error2string(service->error),
7420 get_dbus_sender(service),
7421 NULL) == -EINPROGRESS)
7423 service_complete(service);
7428 service_list_sort();
7430 #if defined TIZEN_EXT
7431 __connman_service_connect_default(service);
7434 __connman_connection_update_gateway();
7436 if ((old_state == CONNMAN_SERVICE_STATE_ONLINE &&
7437 new_state != CONNMAN_SERVICE_STATE_READY) ||
7438 (old_state == CONNMAN_SERVICE_STATE_READY &&
7439 new_state != CONNMAN_SERVICE_STATE_ONLINE)) {
7440 __connman_notifier_disconnect(service->type);
7443 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
7444 __connman_notifier_enter_online(service->type);
7448 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7449 service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7450 (new_state == CONNMAN_SERVICE_STATE_READY ||
7451 new_state == CONNMAN_SERVICE_STATE_ONLINE)) {
7452 if (service->user.favorite_user != service->user.current_user) {
7453 DBG("Now set service favorite user id from %d to %d",
7454 service->user.favorite_user, service->user.current_user);
7456 service->user.favorite_user = service->user.current_user;
7458 service_save(service);
7465 int __connman_service_indicate_error(struct connman_service *service,
7466 enum connman_service_error error)
7468 DBG("service %p error %d", service, error);
7473 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
7476 set_error(service, error);
7478 /* default internet service: fix not cleared if pdp activation*/
7479 #if defined TIZEN_EXT
7481 * If connection failed for default service(DefaultInternet),
7482 * default_connecting_device should be cleared.
7484 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7485 service->error == CONNMAN_SERVICE_ERROR_CONNECT_FAILED)
7486 __connman_service_disconnect_default(service);
7488 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7489 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY) {
7490 g_free(service->passphrase);
7491 service->passphrase = NULL;
7495 __connman_service_ipconfig_indicate_state(service,
7496 CONNMAN_SERVICE_STATE_FAILURE,
7497 CONNMAN_IPCONFIG_TYPE_IPV4);
7498 __connman_service_ipconfig_indicate_state(service,
7499 CONNMAN_SERVICE_STATE_FAILURE,
7500 CONNMAN_IPCONFIG_TYPE_IPV6);
7504 int __connman_service_clear_error(struct connman_service *service)
7506 DBusMessage *pending, *provider_pending;
7508 DBG("service %p", service);
7513 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
7516 pending = service->pending;
7517 service->pending = NULL;
7518 provider_pending = service->provider_pending;
7519 service->provider_pending = NULL;
7521 __connman_service_ipconfig_indicate_state(service,
7522 CONNMAN_SERVICE_STATE_IDLE,
7523 CONNMAN_IPCONFIG_TYPE_IPV6);
7525 __connman_service_ipconfig_indicate_state(service,
7526 CONNMAN_SERVICE_STATE_IDLE,
7527 CONNMAN_IPCONFIG_TYPE_IPV4);
7529 service->pending = pending;
7530 service->provider_pending = provider_pending;
7535 int __connman_service_indicate_default(struct connman_service *service)
7537 DBG("service %p state %s", service, state2string(service->state));
7539 if (!is_connected(service->state)) {
7541 * If service is not yet fully connected, then we must not
7542 * change the default yet. The default gw will be changed
7543 * after the service state is in ready.
7545 return -EINPROGRESS;
7553 enum connman_service_state __connman_service_ipconfig_get_state(
7554 struct connman_service *service,
7555 enum connman_ipconfig_type type)
7558 return CONNMAN_SERVICE_STATE_UNKNOWN;
7560 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7561 return service->state_ipv4;
7563 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
7564 return service->state_ipv6;
7566 return CONNMAN_SERVICE_STATE_UNKNOWN;
7569 static void check_proxy_setup(struct connman_service *service)
7572 * We start WPAD if we haven't got a PAC URL from DHCP and
7573 * if our proxy manual configuration is either empty or set
7574 * to AUTO with an empty URL.
7577 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
7580 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
7581 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
7585 if (__connman_wpad_start(service) < 0) {
7586 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
7587 __connman_notifier_proxy_changed(service);
7594 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
7597 #if defined TIZEN_EXT
7598 void connman_check_proxy_setup_and_wispr_start(struct connman_service *service){
7600 DBG("check the proxy and start wispr");
7601 check_proxy_setup(service);
7607 * How many networks are connected at the same time. If more than 1,
7608 * then set the rp_filter setting properly (loose mode routing) so that network
7609 * connectivity works ok. This is only done for IPv4 networks as IPv6
7610 * does not have rp_filter knob.
7612 static int connected_networks_count;
7613 static int original_rp_filter;
7615 static void service_rp_filter(struct connman_service *service,
7618 enum connman_ipconfig_method method;
7620 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
7623 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7624 case CONNMAN_IPCONFIG_METHOD_OFF:
7625 case CONNMAN_IPCONFIG_METHOD_AUTO:
7627 case CONNMAN_IPCONFIG_METHOD_FIXED:
7628 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7629 case CONNMAN_IPCONFIG_METHOD_DHCP:
7634 if (connected_networks_count == 1) {
7636 filter_value = __connman_ipconfig_set_rp_filter();
7637 if (filter_value < 0)
7640 original_rp_filter = filter_value;
7642 connected_networks_count++;
7645 if (connected_networks_count == 2)
7646 __connman_ipconfig_unset_rp_filter(original_rp_filter);
7648 connected_networks_count--;
7649 if (connected_networks_count < 0)
7650 connected_networks_count = 0;
7653 DBG("%s %s ipconfig %p method %d count %d filter %d",
7654 connected ? "connected" : "disconnected", service->identifier,
7655 service->ipconfig_ipv4, method,
7656 connected_networks_count, original_rp_filter);
7659 static gboolean redo_wispr(gpointer user_data)
7661 struct connman_service *service = user_data;
7662 int refcount = service->refcount - 1;
7664 connman_service_unref(service);
7665 if (refcount == 0) {
7666 DBG("Service %p already removed", service);
7670 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV6);
7675 int __connman_service_online_check_failed(struct connman_service *service,
7676 enum connman_ipconfig_type type)
7678 DBG("service %p type %d count %d", service, type,
7679 service->online_check_count);
7681 /* currently we only retry IPv6 stuff */
7682 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 ||
7683 service->online_check_count != 1) {
7684 connman_warn("Online check failed for %p %s", service,
7689 service->online_check_count = 0;
7692 * We set the timeout to 1 sec so that we have a chance to get
7693 * necessary IPv6 router advertisement messages that might have
7696 g_timeout_add_seconds(1, redo_wispr, connman_service_ref(service));
7701 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
7702 enum connman_service_state new_state,
7703 enum connman_ipconfig_type type)
7705 struct connman_ipconfig *ipconfig = NULL;
7706 enum connman_service_state old_state;
7707 enum connman_ipconfig_method method;
7713 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
7714 case CONNMAN_IPCONFIG_TYPE_ALL:
7717 case CONNMAN_IPCONFIG_TYPE_IPV4:
7718 old_state = service->state_ipv4;
7719 ipconfig = service->ipconfig_ipv4;
7723 case CONNMAN_IPCONFIG_TYPE_IPV6:
7724 old_state = service->state_ipv6;
7725 ipconfig = service->ipconfig_ipv6;
7733 method = __connman_ipconfig_get_method(ipconfig);
7736 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7737 case CONNMAN_IPCONFIG_METHOD_OFF:
7738 if (new_state != CONNMAN_SERVICE_STATE_IDLE)
7739 connman_warn("ipconfig state %d ipconfig method %d",
7742 new_state = CONNMAN_SERVICE_STATE_IDLE;
7745 case CONNMAN_IPCONFIG_METHOD_FIXED:
7746 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7747 case CONNMAN_IPCONFIG_METHOD_DHCP:
7748 case CONNMAN_IPCONFIG_METHOD_AUTO:
7754 if (old_state == new_state)
7757 #if defined TIZEN_EXT
7758 __sync_synchronize();
7759 if (service->user_pdn_connection_refcount > 0 &&
7760 service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7761 if (new_state == CONNMAN_SERVICE_STATE_FAILURE ||
7762 new_state == CONNMAN_SERVICE_STATE_DISCONNECT ||
7763 new_state == CONNMAN_SERVICE_STATE_IDLE) {
7764 service->user_pdn_connection_refcount = 0;
7765 __sync_synchronize();
7769 DBG("service %p (%s) old state %d (%s) new state %d (%s) type %d (%s)",
7770 service, service ? service->identifier : NULL,
7771 old_state, state2string(old_state),
7772 new_state, state2string(new_state),
7773 type, __connman_ipconfig_type2string(type));
7775 switch (new_state) {
7776 case CONNMAN_SERVICE_STATE_UNKNOWN:
7777 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7779 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7781 case CONNMAN_SERVICE_STATE_READY:
7782 #if defined TIZEN_EXT
7783 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7784 __connman_service_is_internet_profile(service) != TRUE) {
7785 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7786 service_rp_filter(service, TRUE);
7791 if (connman_setting_get_bool("EnableOnlineCheck")) {
7792 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
7793 #if !defined TIZEN_EXT
7794 check_proxy_setup(service);
7797 service->online_check_count = 1;
7798 __connman_wispr_start(service, type);
7801 connman_info("Online check disabled. "
7802 "Default service remains in READY state.");
7803 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7804 service_rp_filter(service, true);
7806 case CONNMAN_SERVICE_STATE_ONLINE:
7808 case CONNMAN_SERVICE_STATE_DISCONNECT:
7809 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
7812 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7813 service_rp_filter(service, false);
7817 case CONNMAN_SERVICE_STATE_IDLE:
7818 case CONNMAN_SERVICE_STATE_FAILURE:
7819 __connman_ipconfig_disable(ipconfig);
7824 if (is_connected(old_state) && !is_connected(new_state))
7825 nameserver_remove_all(service, type);
7827 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7828 service->state_ipv4 = new_state;
7830 service->state_ipv6 = new_state;
7832 if (!is_connected(old_state) && is_connected(new_state))
7833 nameserver_add_all(service, type);
7835 __connman_timeserver_sync(service);
7837 #if defined TIZEN_EXT
7838 int ret = service_indicate_state(service);
7839 /*Sent the Ready changed signal again in case IPv4 IP set
7842 if(ret == -EALREADY && type == CONNMAN_IPCONFIG_TYPE_IPV4
7843 && new_state == CONNMAN_SERVICE_STATE_READY) {
7844 DBG("Notify IPv4 state new/old %d/%d", new_state,old_state);
7845 state_changed(service);
7850 return service_indicate_state(service);
7853 static bool prepare_network(struct connman_service *service)
7855 enum connman_network_type type;
7856 unsigned int ssid_len;
7858 type = connman_network_get_type(service->network);
7861 case CONNMAN_NETWORK_TYPE_UNKNOWN:
7862 case CONNMAN_NETWORK_TYPE_VENDOR:
7864 case CONNMAN_NETWORK_TYPE_WIFI:
7865 if (!connman_network_get_blob(service->network, "WiFi.SSID",
7869 if (service->passphrase)
7870 connman_network_set_string(service->network,
7871 "WiFi.Passphrase", service->passphrase);
7873 case CONNMAN_NETWORK_TYPE_ETHERNET:
7874 case CONNMAN_NETWORK_TYPE_GADGET:
7875 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
7876 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
7877 case CONNMAN_NETWORK_TYPE_CELLULAR:
7884 static void prepare_8021x(struct connman_service *service)
7887 connman_network_set_string(service->network, "WiFi.EAP",
7890 if (service->identity)
7891 connman_network_set_string(service->network, "WiFi.Identity",
7894 if (service->anonymous_identity)
7895 connman_network_set_string(service->network,
7896 "WiFi.AnonymousIdentity",
7897 service->anonymous_identity);
7899 if (service->ca_cert_file)
7900 connman_network_set_string(service->network, "WiFi.CACertFile",
7901 service->ca_cert_file);
7903 if (service->subject_match)
7904 connman_network_set_string(service->network, "WiFi.SubjectMatch",
7905 service->subject_match);
7907 if (service->altsubject_match)
7908 connman_network_set_string(service->network, "WiFi.AltSubjectMatch",
7909 service->altsubject_match);
7911 if (service->domain_suffix_match)
7912 connman_network_set_string(service->network, "WiFi.DomainSuffixMatch",
7913 service->domain_suffix_match);
7915 if (service->domain_match)
7916 connman_network_set_string(service->network, "WiFi.DomainMatch",
7917 service->domain_match);
7919 if (service->client_cert_file)
7920 connman_network_set_string(service->network,
7921 "WiFi.ClientCertFile",
7922 service->client_cert_file);
7924 if (service->private_key_file)
7925 connman_network_set_string(service->network,
7926 "WiFi.PrivateKeyFile",
7927 service->private_key_file);
7929 if (service->private_key_passphrase)
7930 connman_network_set_string(service->network,
7931 "WiFi.PrivateKeyPassphrase",
7932 service->private_key_passphrase);
7934 if (service->phase2)
7935 connman_network_set_string(service->network, "WiFi.Phase2",
7939 static int service_connect(struct connman_service *service)
7943 if (service->hidden)
7946 #if defined TIZEN_EXT
7950 index = __connman_service_get_index(service);
7952 for (list = service_list; list; list = list->next) {
7953 struct connman_service *temp = list->data;
7955 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7958 if (!is_connecting(temp->state) && !is_connected(temp->state))
7961 if (service == temp)
7964 if (service->type != temp->type)
7967 if (__connman_service_get_index(temp) == index &&
7968 __connman_service_disconnect(temp) == -EINPROGRESS)
7969 return -EINPROGRESS;
7973 switch (service->type) {
7974 case CONNMAN_SERVICE_TYPE_UNKNOWN:
7975 case CONNMAN_SERVICE_TYPE_SYSTEM:
7976 case CONNMAN_SERVICE_TYPE_GPS:
7977 case CONNMAN_SERVICE_TYPE_P2P:
7979 case CONNMAN_SERVICE_TYPE_ETHERNET:
7980 case CONNMAN_SERVICE_TYPE_GADGET:
7981 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
7982 case CONNMAN_SERVICE_TYPE_CELLULAR:
7983 case CONNMAN_SERVICE_TYPE_VPN:
7985 case CONNMAN_SERVICE_TYPE_WIFI:
7986 switch (service->security) {
7987 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
7988 case CONNMAN_SERVICE_SECURITY_NONE:
7990 case CONNMAN_SERVICE_SECURITY_WEP:
7991 case CONNMAN_SERVICE_SECURITY_PSK:
7992 case CONNMAN_SERVICE_SECURITY_WPA:
7993 case CONNMAN_SERVICE_SECURITY_RSN:
7994 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
7997 if (service->request_passphrase_input) {
7998 DBG("Now try to connect other user's favorite service");
7999 service->request_passphrase_input = false;
8001 } else if (!service->passphrase) {
8002 if (!service->network)
8005 if (!service->wps ||
8006 !connman_network_get_bool(service->network, "WiFi.UseWPS"))
8011 case CONNMAN_SERVICE_SECURITY_8021X:
8015 #if defined TIZEN_EXT
8017 * never request credentials if using EAP-TLS, EAP-SIM
8018 * or EAP-AKA (EAP-TLS, EAP-SIM and EAP-AKA networks
8019 * need to be fully provisioned)
8021 DBG("service eap: %s", service->eap);
8022 if (g_str_equal(service->eap, "tls") ||
8023 g_str_equal(service->eap, "sim") ||
8024 g_str_equal(service->eap, "aka"))
8028 * never request credentials if using EAP-TLS
8029 * (EAP-TLS networks need to be fully provisioned)
8031 if (g_str_equal(service->eap, "tls"))
8035 * Return -ENOKEY if either identity or passphrase is
8036 * missing. Agent provided credentials can be used as
8037 * fallback if needed.
8039 if (((!service->identity &&
8040 !service->agent_identity) ||
8041 !service->passphrase) ||
8042 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
8050 if (service->network) {
8051 if (!prepare_network(service))
8054 switch (service->security) {
8055 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
8056 case CONNMAN_SERVICE_SECURITY_NONE:
8057 case CONNMAN_SERVICE_SECURITY_WEP:
8058 case CONNMAN_SERVICE_SECURITY_PSK:
8059 case CONNMAN_SERVICE_SECURITY_WPA:
8060 case CONNMAN_SERVICE_SECURITY_RSN:
8062 case CONNMAN_SERVICE_SECURITY_8021X:
8063 prepare_8021x(service);
8067 if (__connman_stats_service_register(service) == 0) {
8068 __connman_stats_get(service, false,
8069 &service->stats.data);
8070 __connman_stats_get(service, true,
8071 &service->stats_roaming.data);
8074 err = __connman_network_connect(service->network);
8075 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8077 err = __connman_provider_connect(service->provider,
8078 get_dbus_sender(service));
8083 if (err != -EINPROGRESS) {
8084 __connman_service_ipconfig_indicate_state(service,
8085 CONNMAN_SERVICE_STATE_FAILURE,
8086 CONNMAN_IPCONFIG_TYPE_IPV4);
8087 __connman_service_ipconfig_indicate_state(service,
8088 CONNMAN_SERVICE_STATE_FAILURE,
8089 CONNMAN_IPCONFIG_TYPE_IPV6);
8090 __connman_stats_service_unregister(service);
8097 int __connman_service_connect(struct connman_service *service,
8098 enum connman_service_connect_reason reason)
8102 DBG("service %p state %s connect reason %s -> %s",
8103 service, state2string(service->state),
8104 reason2string(service->connect_reason),
8105 reason2string(reason));
8107 if (is_connected(service->state))
8110 if (is_connecting(service->state))
8113 switch (service->type) {
8114 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8115 case CONNMAN_SERVICE_TYPE_SYSTEM:
8116 case CONNMAN_SERVICE_TYPE_GPS:
8117 case CONNMAN_SERVICE_TYPE_P2P:
8120 case CONNMAN_SERVICE_TYPE_ETHERNET:
8121 case CONNMAN_SERVICE_TYPE_GADGET:
8122 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8123 case CONNMAN_SERVICE_TYPE_CELLULAR:
8124 case CONNMAN_SERVICE_TYPE_VPN:
8125 case CONNMAN_SERVICE_TYPE_WIFI:
8129 if (!is_ipconfig_usable(service))
8132 __connman_service_clear_error(service);
8134 err = service_connect(service);
8136 DBG("service %p err %d", service, err);
8138 service->connect_reason = reason;
8142 if (err == -EINPROGRESS) {
8143 if (service->timeout == 0)
8144 service->timeout = g_timeout_add_seconds(
8145 CONNECT_TIMEOUT, connect_timeout, service);
8147 return -EINPROGRESS;
8150 if (service->network)
8151 __connman_network_disconnect(service->network);
8152 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8154 connman_provider_disconnect(service->provider);
8156 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
8157 if (err == -ENOKEY || err == -EPERM) {
8158 DBusMessage *pending = NULL;
8159 const char *dbus_sender = get_dbus_sender(service);
8162 * We steal the reply here. The idea is that the
8163 * connecting client will see the connection status
8164 * after the real hidden network is connected or
8165 * connection failed.
8167 if (service->hidden) {
8168 pending = service->pending;
8169 service->pending = NULL;
8172 err = __connman_agent_request_passphrase_input(service,
8176 if (service->hidden && err != -EINPROGRESS)
8177 service->pending = pending;
8181 reply_pending(service, -err);
8187 int __connman_service_disconnect(struct connman_service *service)
8191 DBG("service %p", service);
8193 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
8194 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
8196 connman_agent_cancel(service);
8198 reply_pending(service, ECONNABORTED);
8200 if (service->network) {
8201 err = __connman_network_disconnect(service->network);
8202 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8204 err = connman_provider_disconnect(service->provider);
8208 if (err < 0 && err != -EINPROGRESS)
8211 __connman_6to4_remove(service->ipconfig_ipv4);
8213 if (service->ipconfig_ipv4)
8214 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
8217 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
8220 #if defined TIZEN_EXT
8222 * Skip the functions If there is any connected profiles
8223 * that use same interface
8225 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
8226 __connman_service_get_connected_count_of_iface(service) <= 0) {
8228 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
8229 settings_changed(service, service->ipconfig_ipv4);
8231 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
8232 settings_changed(service, service->ipconfig_ipv6);
8234 __connman_ipconfig_disable(service->ipconfig_ipv4);
8235 __connman_ipconfig_disable(service->ipconfig_ipv6);
8236 #if defined TIZEN_EXT
8240 __connman_stats_service_unregister(service);
8245 int __connman_service_disconnect_all(void)
8247 struct connman_service *service;
8248 GSList *services = NULL, *list;
8253 for (iter = service_list; iter; iter = iter->next) {
8254 service = iter->data;
8256 if (!is_connected(service->state))
8259 services = g_slist_prepend(services, service);
8262 for (list = services; list; list = list->next) {
8263 struct connman_service *service = list->data;
8265 service->ignore = true;
8267 __connman_service_disconnect(service);
8270 g_slist_free(services);
8276 * lookup_by_identifier:
8277 * @identifier: service identifier
8279 * Look up a service by identifier (reference count will not be increased)
8281 static struct connman_service *lookup_by_identifier(const char *identifier)
8283 return g_hash_table_lookup(service_hash, identifier);
8286 struct connman_service *connman_service_lookup_from_identifier(const char* identifier)
8288 return lookup_by_identifier(identifier);
8291 struct provision_user_data {
8296 static void provision_changed(gpointer value, gpointer user_data)
8298 struct connman_service *service = value;
8299 struct provision_user_data *data = user_data;
8300 const char *path = data->ident;
8303 ret = __connman_config_provision_service_ident(service, path,
8304 service->config_file, service->config_entry);
8309 int __connman_service_provision_changed(const char *ident)
8311 struct provision_user_data data = {
8316 g_list_foreach(service_list, provision_changed, (void *)&data);
8319 * Because the provision_changed() might have set some services
8320 * as favorite, we must sort the sequence now.
8322 if (services_dirty) {
8323 services_dirty = false;
8325 service_list_sort();
8327 __connman_connection_update_gateway();
8333 void __connman_service_set_config(struct connman_service *service,
8334 const char *file_id, const char *entry)
8339 g_free(service->config_file);
8340 service->config_file = g_strdup(file_id);
8342 g_free(service->config_entry);
8343 service->config_entry = g_strdup(entry);
8347 * __connman_service_get:
8348 * @identifier: service identifier
8350 * Look up a service by identifier or create a new one if not found
8352 static struct connman_service *service_get(const char *identifier)
8354 struct connman_service *service;
8356 service = g_hash_table_lookup(service_hash, identifier);
8358 connman_service_ref(service);
8362 service = connman_service_create();
8366 DBG("service %p", service);
8368 service->identifier = g_strdup(identifier);
8370 service_list = g_list_insert_sorted(service_list, service,
8373 g_hash_table_insert(service_hash, service->identifier, service);
8378 static int service_register(struct connman_service *service)
8380 DBG("service %p", service);
8385 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
8386 service->identifier);
8388 DBG("path %s", service->path);
8390 if (__connman_config_provision_service(service) < 0)
8391 service_load(service);
8393 g_dbus_register_interface(connection, service->path,
8394 CONNMAN_SERVICE_INTERFACE,
8395 service_methods, service_signals,
8396 NULL, service, NULL);
8398 service_list_sort();
8400 __connman_connection_update_gateway();
8405 static void service_up(struct connman_ipconfig *ipconfig,
8408 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8410 DBG("%s up", ifname);
8412 link_changed(service);
8414 service->stats.valid = false;
8415 service->stats_roaming.valid = false;
8418 static void service_down(struct connman_ipconfig *ipconfig,
8421 DBG("%s down", ifname);
8424 static void service_lower_up(struct connman_ipconfig *ipconfig,
8427 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8429 DBG("%s lower up", ifname);
8431 stats_start(service);
8434 static void service_lower_down(struct connman_ipconfig *ipconfig,
8437 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8439 DBG("%s lower down", ifname);
8441 stats_stop(service);
8442 service_save(service);
8445 static void service_ip_bound(struct connman_ipconfig *ipconfig,
8448 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8449 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8450 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8451 #if defined TIZEN_EXT
8455 DBG("%s ip bound", ifname);
8457 type = __connman_ipconfig_get_config_type(ipconfig);
8458 method = __connman_ipconfig_get_method(ipconfig);
8460 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8463 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8464 method == CONNMAN_IPCONFIG_METHOD_AUTO)
8465 #if defined TIZEN_EXT
8467 err = __connman_ipconfig_gateway_add(ipconfig, service);
8470 DBG("Failed to add gateway");
8473 __connman_service_ipconfig_indicate_state(service,
8474 CONNMAN_SERVICE_STATE_READY,
8475 CONNMAN_IPCONFIG_TYPE_IPV6);
8478 settings_changed(service, ipconfig);
8479 address_updated(service, type);
8482 static void service_ip_release(struct connman_ipconfig *ipconfig,
8485 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8486 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8487 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8489 DBG("%s ip release", ifname);
8491 type = __connman_ipconfig_get_config_type(ipconfig);
8492 method = __connman_ipconfig_get_method(ipconfig);
8494 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8497 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8498 method == CONNMAN_IPCONFIG_METHOD_OFF)
8499 __connman_service_ipconfig_indicate_state(service,
8500 CONNMAN_SERVICE_STATE_DISCONNECT,
8501 CONNMAN_IPCONFIG_TYPE_IPV6);
8503 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
8504 method == CONNMAN_IPCONFIG_METHOD_OFF)
8505 __connman_service_ipconfig_indicate_state(service,
8506 CONNMAN_SERVICE_STATE_DISCONNECT,
8507 CONNMAN_IPCONFIG_TYPE_IPV4);
8509 settings_changed(service, ipconfig);
8512 static void service_route_changed(struct connman_ipconfig *ipconfig,
8515 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8517 DBG("%s route changed", ifname);
8519 settings_changed(service, ipconfig);
8522 static const struct connman_ipconfig_ops service_ops = {
8524 .down = service_down,
8525 .lower_up = service_lower_up,
8526 .lower_down = service_lower_down,
8527 .ip_bound = service_ip_bound,
8528 .ip_release = service_ip_release,
8529 .route_set = service_route_changed,
8530 .route_unset = service_route_changed,
8533 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
8534 int index, enum connman_ipconfig_method method)
8536 struct connman_ipconfig *ipconfig_ipv4;
8538 ipconfig_ipv4 = __connman_ipconfig_create(index,
8539 CONNMAN_IPCONFIG_TYPE_IPV4);
8543 __connman_ipconfig_set_method(ipconfig_ipv4, method);
8545 __connman_ipconfig_set_data(ipconfig_ipv4, service);
8547 __connman_ipconfig_set_ops(ipconfig_ipv4, &service_ops);
8549 return ipconfig_ipv4;
8552 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
8555 struct connman_ipconfig *ipconfig_ipv6;
8557 ipconfig_ipv6 = __connman_ipconfig_create(index,
8558 CONNMAN_IPCONFIG_TYPE_IPV6);
8562 __connman_ipconfig_set_data(ipconfig_ipv6, service);
8564 __connman_ipconfig_set_ops(ipconfig_ipv6, &service_ops);
8566 return ipconfig_ipv6;
8569 void __connman_service_read_ip4config(struct connman_service *service)
8573 if (!service->ipconfig_ipv4)
8576 keyfile = connman_storage_load_service(service->identifier);
8580 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
8581 service->identifier, "IPv4.");
8583 g_key_file_free(keyfile);
8586 void connman_service_create_ip4config(struct connman_service *service,
8589 DBG("ipv4 %p", service->ipconfig_ipv4);
8591 if (service->ipconfig_ipv4)
8594 service->ipconfig_ipv4 = create_ip4config(service, index,
8595 CONNMAN_IPCONFIG_METHOD_DHCP);
8596 __connman_service_read_ip4config(service);
8599 void __connman_service_read_ip6config(struct connman_service *service)
8603 if (!service->ipconfig_ipv6)
8606 keyfile = connman_storage_load_service(service->identifier);
8610 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
8611 service->identifier, "IPv6.");
8613 g_key_file_free(keyfile);
8616 void connman_service_create_ip6config(struct connman_service *service,
8619 DBG("ipv6 %p", service->ipconfig_ipv6);
8621 if (service->ipconfig_ipv6)
8624 service->ipconfig_ipv6 = create_ip6config(service, index);
8626 __connman_service_read_ip6config(service);
8630 * connman_service_lookup_from_network:
8631 * @network: network structure
8633 * Look up a service by network (reference count will not be increased)
8635 struct connman_service *connman_service_lookup_from_network(struct connman_network *network)
8637 struct connman_service *service;
8638 const char *ident, *group;
8644 ident = __connman_network_get_ident(network);
8648 group = connman_network_get_group(network);
8652 name = g_strdup_printf("%s_%s_%s",
8653 __connman_network_get_type(network), ident, group);
8654 service = lookup_by_identifier(name);
8660 struct connman_service *__connman_service_lookup_from_index(int index)
8662 struct connman_service *service;
8665 for (list = service_list; list; list = list->next) {
8666 service = list->data;
8668 if (__connman_ipconfig_get_index(service->ipconfig_ipv4)
8672 if (__connman_ipconfig_get_index(service->ipconfig_ipv6)
8680 struct connman_service *__connman_service_lookup_from_ident(const char *identifier)
8682 return lookup_by_identifier(identifier);
8685 const char *__connman_service_get_ident(struct connman_service *service)
8687 return service->identifier;
8690 const char *__connman_service_get_path(struct connman_service *service)
8692 return service->path;
8695 const char *__connman_service_get_name(struct connman_service *service)
8697 return service->name;
8700 enum connman_service_state __connman_service_get_state(struct connman_service *service)
8702 return service->state;
8705 unsigned int __connman_service_get_order(struct connman_service *service)
8707 unsigned int order = 0;
8714 if (!service->favorite)
8717 #if defined TIZEN_EXT
8718 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8719 service->do_split_routing == FALSE)
8721 else if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
8722 if (service->order < 5)
8724 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
8726 else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
8728 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8729 __connman_service_is_internet_profile(service) == TRUE)
8731 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8732 __connman_service_is_tethering_profile(service) == TRUE)
8734 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8739 if (service == service_list->data)
8742 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8743 !service->do_split_routing) {
8744 service->order = 10;
8748 DBG("service %p name %s order %d split %d", service, service->name,
8749 order, service->do_split_routing);
8754 static enum connman_service_type convert_network_type(struct connman_network *network)
8756 enum connman_network_type type = connman_network_get_type(network);
8759 case CONNMAN_NETWORK_TYPE_UNKNOWN:
8760 case CONNMAN_NETWORK_TYPE_VENDOR:
8762 case CONNMAN_NETWORK_TYPE_ETHERNET:
8763 return CONNMAN_SERVICE_TYPE_ETHERNET;
8764 case CONNMAN_NETWORK_TYPE_WIFI:
8765 return CONNMAN_SERVICE_TYPE_WIFI;
8766 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
8767 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
8768 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
8769 case CONNMAN_NETWORK_TYPE_CELLULAR:
8770 return CONNMAN_SERVICE_TYPE_CELLULAR;
8771 case CONNMAN_NETWORK_TYPE_GADGET:
8772 return CONNMAN_SERVICE_TYPE_GADGET;
8775 return CONNMAN_SERVICE_TYPE_UNKNOWN;
8778 static enum connman_service_security convert_wifi_security(const char *security)
8781 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8782 else if (g_str_equal(security, "none"))
8783 return CONNMAN_SERVICE_SECURITY_NONE;
8784 else if (g_str_equal(security, "wep"))
8785 return CONNMAN_SERVICE_SECURITY_WEP;
8786 else if (g_str_equal(security, "psk"))
8787 return CONNMAN_SERVICE_SECURITY_PSK;
8788 else if (g_str_equal(security, "ieee8021x"))
8789 return CONNMAN_SERVICE_SECURITY_8021X;
8790 else if (g_str_equal(security, "wpa"))
8791 return CONNMAN_SERVICE_SECURITY_WPA;
8792 else if (g_str_equal(security, "rsn"))
8793 return CONNMAN_SERVICE_SECURITY_RSN;
8794 #if defined TIZEN_EXT
8795 else if (g_str_equal(security, "ft_psk") == TRUE)
8796 return CONNMAN_SERVICE_SECURITY_PSK;
8797 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
8798 return CONNMAN_SERVICE_SECURITY_8021X;
8801 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8804 #if defined TIZEN_EXT
8805 int check_passphrase_ext(struct connman_network *network,
8806 const char *passphrase)
8809 enum connman_service_security security;
8811 str = connman_network_get_string(network, "WiFi.Security");
8812 security = convert_wifi_security(str);
8814 return __connman_service_check_passphrase(security, passphrase);
8818 static void update_from_network(struct connman_service *service,
8819 struct connman_network *network)
8821 uint8_t strength = service->strength;
8824 DBG("service %p network %p", service, network);
8826 if (is_connected(service->state))
8829 if (is_connecting(service->state))
8832 str = connman_network_get_string(network, "Name");
8834 g_free(service->name);
8835 service->name = g_strdup(str);
8836 service->hidden = false;
8838 g_free(service->name);
8839 service->name = NULL;
8840 service->hidden = true;
8843 service->strength = connman_network_get_strength(network);
8844 service->roaming = connman_network_get_bool(network, "Roaming");
8846 if (service->strength == 0) {
8848 * Filter out 0-values; it's unclear what they mean
8849 * and they cause anomalous sorting of the priority list.
8851 service->strength = strength;
8854 str = connman_network_get_string(network, "WiFi.Security");
8855 service->security = convert_wifi_security(str);
8857 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
8858 service->wps = connman_network_get_bool(network, "WiFi.WPS");
8860 if (service->strength > strength && service->network) {
8861 connman_network_unref(service->network);
8862 service->network = connman_network_ref(network);
8864 strength_changed(service);
8867 if (!service->network)
8868 service->network = connman_network_ref(network);
8870 service_list_sort();
8874 * __connman_service_create_from_network:
8875 * @network: network structure
8877 * Look up service by network and if not found, create one
8879 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
8881 struct connman_service *service;
8882 struct connman_device *device;
8883 const char *ident, *group;
8885 unsigned int *auto_connect_types;
8888 DBG("network %p", network);
8893 ident = __connman_network_get_ident(network);
8897 group = connman_network_get_group(network);
8901 name = g_strdup_printf("%s_%s_%s",
8902 __connman_network_get_type(network), ident, group);
8903 service = service_get(name);
8909 if (__connman_network_get_weakness(network))
8912 if (service->path) {
8913 update_from_network(service, network);
8914 __connman_connection_update_gateway();
8918 service->type = convert_network_type(network);
8920 auto_connect_types = connman_setting_get_uint_list("DefaultAutoConnectTechnologies");
8921 service->autoconnect = false;
8922 for (i = 0; auto_connect_types &&
8923 auto_connect_types[i] != 0; i++) {
8924 if (service->type == auto_connect_types[i]) {
8925 service->autoconnect = true;
8930 switch (service->type) {
8931 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8932 case CONNMAN_SERVICE_TYPE_SYSTEM:
8933 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8934 case CONNMAN_SERVICE_TYPE_GPS:
8935 case CONNMAN_SERVICE_TYPE_VPN:
8936 case CONNMAN_SERVICE_TYPE_GADGET:
8937 case CONNMAN_SERVICE_TYPE_WIFI:
8938 case CONNMAN_SERVICE_TYPE_CELLULAR:
8939 case CONNMAN_SERVICE_TYPE_P2P:
8941 case CONNMAN_SERVICE_TYPE_ETHERNET:
8942 service->favorite = true;
8946 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
8947 service->state = combine_state(service->state_ipv4, service->state_ipv6);
8949 update_from_network(service, network);
8951 index = connman_network_get_index(network);
8953 if (!service->ipconfig_ipv4)
8954 service->ipconfig_ipv4 = create_ip4config(service, index,
8955 CONNMAN_IPCONFIG_METHOD_DHCP);
8957 if (!service->ipconfig_ipv6)
8958 service->ipconfig_ipv6 = create_ip6config(service, index);
8960 service_register(service);
8961 service_schedule_added(service);
8963 if (service->favorite) {
8964 device = connman_network_get_device(service->network);
8965 if (device && !connman_device_get_scanning(device)) {
8967 switch (service->type) {
8968 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8969 case CONNMAN_SERVICE_TYPE_SYSTEM:
8970 case CONNMAN_SERVICE_TYPE_P2P:
8973 case CONNMAN_SERVICE_TYPE_GADGET:
8974 case CONNMAN_SERVICE_TYPE_ETHERNET:
8975 if (service->autoconnect) {
8976 __connman_service_connect(service,
8977 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
8982 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8983 case CONNMAN_SERVICE_TYPE_GPS:
8984 case CONNMAN_SERVICE_TYPE_VPN:
8985 case CONNMAN_SERVICE_TYPE_WIFI:
8986 case CONNMAN_SERVICE_TYPE_CELLULAR:
8987 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
8992 #if defined TIZEN_EXT
8993 /* TIZEN synchronizes below information when the service creates */
8994 if (service->eap != NULL)
8995 connman_network_set_string(service->network, "WiFi.EAP",
8997 if (service->identity != NULL)
8998 connman_network_set_string(service->network, "WiFi.Identity",
9000 if (service->phase2 != NULL)
9001 connman_network_set_string(service->network, "WiFi.Phase2",
9006 __connman_notifier_service_add(service, service->name);
9011 void __connman_service_update_from_network(struct connman_network *network)
9013 bool need_sort = false;
9014 struct connman_service *service;
9020 service = connman_service_lookup_from_network(network);
9024 if (!service->network)
9027 #if defined TIZEN_EXT
9028 if (service->storage_reload) {
9029 service_load(service);
9030 __connman_service_set_storage_reload(service, false);
9034 name = connman_network_get_string(service->network, "Name");
9035 if (g_strcmp0(service->name, name) != 0) {
9036 g_free(service->name);
9037 service->name = g_strdup(name);
9039 if (allow_property_changed(service))
9040 connman_dbus_property_changed_basic(service->path,
9041 CONNMAN_SERVICE_INTERFACE, "Name",
9042 DBUS_TYPE_STRING, &service->name);
9045 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
9046 service->wps = connman_network_get_bool(network, "WiFi.WPS");
9048 strength = connman_network_get_strength(service->network);
9049 if (strength == service->strength)
9052 service->strength = strength;
9055 strength_changed(service);
9058 roaming = connman_network_get_bool(service->network, "Roaming");
9059 if (roaming == service->roaming)
9062 stats_enable = stats_enabled(service);
9064 stats_stop(service);
9066 service->roaming = roaming;
9070 stats_start(service);
9072 roaming_changed(service);
9076 service_list_sort();
9080 void __connman_service_remove_from_network(struct connman_network *network)
9082 struct connman_service *service;
9084 service = connman_service_lookup_from_network(network);
9086 DBG("network %p service %p", network, service);
9091 service->ignore = true;
9093 __connman_connection_gateway_remove(service,
9094 CONNMAN_IPCONFIG_TYPE_ALL);
9096 connman_service_unref(service);
9100 * __connman_service_create_from_provider:
9101 * @provider: provider structure
9103 * Look up service by provider and if not found, create one
9105 struct connman_service *
9106 __connman_service_create_from_provider(struct connman_provider *provider)
9108 struct connman_service *service;
9109 const char *ident, *str;
9111 int index = connman_provider_get_index(provider);
9113 DBG("provider %p", provider);
9115 ident = __connman_provider_get_ident(provider);
9119 name = g_strdup_printf("vpn_%s", ident);
9120 service = service_get(name);
9126 service->type = CONNMAN_SERVICE_TYPE_VPN;
9127 service->provider = connman_provider_ref(provider);
9128 service->autoconnect = false;
9129 service->favorite = true;
9131 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
9132 service->state = combine_state(service->state_ipv4, service->state_ipv6);
9134 str = connman_provider_get_string(provider, "Name");
9136 g_free(service->name);
9137 service->name = g_strdup(str);
9138 service->hidden = false;
9140 g_free(service->name);
9141 service->name = NULL;
9142 service->hidden = true;
9145 service->strength = 0;
9147 if (!service->ipconfig_ipv4)
9148 service->ipconfig_ipv4 = create_ip4config(service, index,
9149 CONNMAN_IPCONFIG_METHOD_MANUAL);
9151 if (!service->ipconfig_ipv6)
9152 service->ipconfig_ipv6 = create_ip6config(service, index);
9154 service_register(service);
9156 __connman_notifier_service_add(service, service->name);
9157 service_schedule_added(service);
9162 static void remove_unprovisioned_services(void)
9165 GKeyFile *keyfile, *configkeyfile;
9166 char *file, *section;
9169 services = connman_storage_get_services();
9173 for (; services[i]; i++) {
9174 file = section = NULL;
9175 keyfile = configkeyfile = NULL;
9177 keyfile = connman_storage_load_service(services[i]);
9181 file = g_key_file_get_string(keyfile, services[i],
9182 "Config.file", NULL);
9186 section = g_key_file_get_string(keyfile, services[i],
9187 "Config.ident", NULL);
9191 configkeyfile = __connman_storage_load_config(file);
9192 if (!configkeyfile) {
9194 * Config file is missing, remove the provisioned
9197 __connman_storage_remove_service(services[i]);
9201 if (!g_key_file_has_group(configkeyfile, section))
9203 * Config section is missing, remove the provisioned
9206 __connman_storage_remove_service(services[i]);
9210 g_key_file_free(keyfile);
9213 g_key_file_free(configkeyfile);
9219 g_strfreev(services);
9222 static int agent_probe(struct connman_agent *agent)
9224 DBG("agent %p", agent);
9228 static void agent_remove(struct connman_agent *agent)
9230 DBG("agent %p", agent);
9233 static void *agent_context_ref(void *context)
9235 struct connman_service *service = context;
9237 return (void *)connman_service_ref(service);
9240 static void agent_context_unref(void *context)
9242 struct connman_service *service = context;
9244 connman_service_unref(service);
9247 static struct connman_agent_driver agent_driver = {
9249 .interface = CONNMAN_AGENT_INTERFACE,
9250 .probe = agent_probe,
9251 .remove = agent_remove,
9252 .context_ref = agent_context_ref,
9253 .context_unref = agent_context_unref,
9256 int __connman_service_init(void)
9262 err = connman_agent_driver_register(&agent_driver);
9264 connman_error("Cannot register agent driver for %s",
9269 set_always_connecting_technologies();
9271 connection = connman_dbus_get_connection();
9273 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
9274 NULL, service_free);
9276 services_notify = g_new0(struct _services_notify, 1);
9277 services_notify->remove = g_hash_table_new_full(g_str_hash,
9278 g_str_equal, g_free, NULL);
9279 services_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
9281 remove_unprovisioned_services();
9286 void __connman_service_cleanup(void)
9290 if (vpn_autoconnect_timeout) {
9291 g_source_remove(vpn_autoconnect_timeout);
9292 vpn_autoconnect_timeout = 0;
9295 if (autoconnect_timeout != 0) {
9296 g_source_remove(autoconnect_timeout);
9297 autoconnect_timeout = 0;
9300 connman_agent_driver_unregister(&agent_driver);
9302 g_list_free(service_list);
9303 service_list = NULL;
9305 g_hash_table_destroy(service_hash);
9306 service_hash = NULL;
9308 g_slist_free(counter_list);
9309 counter_list = NULL;
9311 if (services_notify->id != 0) {
9312 g_source_remove(services_notify->id);
9313 service_send_changed(NULL);
9316 g_hash_table_destroy(services_notify->remove);
9317 g_hash_table_destroy(services_notify->add);
9318 g_free(services_notify);
9320 dbus_connection_unref(connection);