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;
61 struct connman_stats {
64 struct connman_stats_data data_last;
65 struct connman_stats_data data;
69 struct connman_stats_counter {
71 struct connman_stats stats;
72 struct connman_stats stats_roaming;
75 struct connman_service_user {
80 struct connman_service {
84 enum connman_service_type type;
85 enum connman_service_security security;
86 enum connman_service_state state;
87 enum connman_service_state state_ipv4;
88 enum connman_service_state state_ipv6;
89 enum connman_service_error error;
90 enum connman_service_connect_reason connect_reason;
102 bool request_passphrase_input;
103 struct connman_service_user user;
104 struct connman_ipconfig *ipconfig_ipv4;
105 struct connman_ipconfig *ipconfig_ipv6;
106 struct connman_network *network;
107 struct connman_provider *provider;
109 char **nameservers_config;
110 char **nameservers_auto;
115 char **timeservers_config;
116 /* 802.1x settings from the config files */
119 char *agent_identity;
121 char *client_cert_file;
122 char *private_key_file;
123 char *private_key_passphrase;
125 DBusMessage *pending;
126 DBusMessage *provider_pending;
128 struct connman_stats stats;
129 struct connman_stats stats_roaming;
130 GHashTable *counter_table;
131 enum connman_service_proxy_method proxy;
132 enum connman_service_proxy_method proxy_config;
137 int online_check_count;
138 bool do_split_routing;
143 #if defined TIZEN_EXT
145 * Description: TIZEN implements system global connection management.
146 * It's only for PDP (cellular) bearer. Wi-Fi is managed
147 * by ConnMan automatically. Reference count can help to
148 * manage open/close connection requests by each application.
150 int user_pdn_connection_refcount;
153 * Description: In case of EAP security type,
154 * user can select the keymgmt type for roaming(802.11r).
155 * - FT, CCKM, OKC, ...
158 int disconnect_reason;
161 enum connman_dnsconfig_method dns_config_method_ipv4;
162 enum connman_dnsconfig_method dns_config_method_ipv6;
166 static bool allow_property_changed(struct connman_service *service);
168 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
169 int index, enum connman_ipconfig_method method);
170 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
176 struct connman_service *service;
179 #if defined TIZEN_EXT
181 * Public APIs to use user_pdn_connection_refcount
183 void connman_service_user_pdn_connection_ref(struct connman_service *service)
185 __sync_fetch_and_add(&service->user_pdn_connection_refcount, 1);
187 DBG("User made PDN connection referenced: %d",
188 service->user_pdn_connection_refcount);
191 gboolean connman_service_user_pdn_connection_unref_and_test(
192 struct connman_service *service)
194 __sync_synchronize();
196 DBG("User made PDN connection referenced: %d, which will be decreased",
197 service->user_pdn_connection_refcount);
199 if (service->user_pdn_connection_refcount < 1)
202 if (__sync_sub_and_fetch(&service->user_pdn_connection_refcount, 1) == 0)
208 gboolean connman_service_is_no_ref_user_pdn_connection(
209 struct connman_service *cellular)
211 if (cellular == NULL)
214 __sync_synchronize();
215 if (cellular->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
216 cellular->user_pdn_connection_refcount == 0)
223 static void compare_path(gpointer value, gpointer user_data)
225 struct connman_service *service = value;
226 struct find_data *data = user_data;
231 if (g_strcmp0(service->path, data->path) == 0)
232 data->service = service;
235 static struct connman_service *find_service(const char *path)
237 struct find_data data = { .path = path, .service = NULL };
239 DBG("path %s", path);
241 g_list_foreach(service_list, compare_path, &data);
246 static const char *reason2string(enum connman_service_connect_reason reason)
250 case CONNMAN_SERVICE_CONNECT_REASON_NONE:
252 case CONNMAN_SERVICE_CONNECT_REASON_USER:
254 case CONNMAN_SERVICE_CONNECT_REASON_AUTO:
256 case CONNMAN_SERVICE_CONNECT_REASON_SESSION:
263 const char *__connman_service_type2string(enum connman_service_type type)
266 case CONNMAN_SERVICE_TYPE_UNKNOWN:
268 case CONNMAN_SERVICE_TYPE_SYSTEM:
270 case CONNMAN_SERVICE_TYPE_ETHERNET:
272 case CONNMAN_SERVICE_TYPE_WIFI:
274 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
276 case CONNMAN_SERVICE_TYPE_CELLULAR:
278 case CONNMAN_SERVICE_TYPE_GPS:
280 case CONNMAN_SERVICE_TYPE_VPN:
282 case CONNMAN_SERVICE_TYPE_GADGET:
284 case CONNMAN_SERVICE_TYPE_P2P:
291 enum connman_service_type __connman_service_string2type(const char *str)
294 return CONNMAN_SERVICE_TYPE_UNKNOWN;
296 if (strcmp(str, "ethernet") == 0)
297 return CONNMAN_SERVICE_TYPE_ETHERNET;
298 if (strcmp(str, "gadget") == 0)
299 return CONNMAN_SERVICE_TYPE_GADGET;
300 if (strcmp(str, "wifi") == 0)
301 return CONNMAN_SERVICE_TYPE_WIFI;
302 if (strcmp(str, "cellular") == 0)
303 return CONNMAN_SERVICE_TYPE_CELLULAR;
304 if (strcmp(str, "bluetooth") == 0)
305 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
306 if (strcmp(str, "vpn") == 0)
307 return CONNMAN_SERVICE_TYPE_VPN;
308 if (strcmp(str, "gps") == 0)
309 return CONNMAN_SERVICE_TYPE_GPS;
310 if (strcmp(str, "system") == 0)
311 return CONNMAN_SERVICE_TYPE_SYSTEM;
312 if (strcmp(str, "p2p") == 0)
313 return CONNMAN_SERVICE_TYPE_P2P;
315 return CONNMAN_SERVICE_TYPE_UNKNOWN;
318 enum connman_service_security __connman_service_string2security(const char *str)
321 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
323 if (!strcmp(str, "psk"))
324 return CONNMAN_SERVICE_SECURITY_PSK;
325 if (!strcmp(str, "ieee8021x"))
326 return CONNMAN_SERVICE_SECURITY_8021X;
327 if (!strcmp(str, "none"))
328 return CONNMAN_SERVICE_SECURITY_NONE;
329 if (!strcmp(str, "wep"))
330 return CONNMAN_SERVICE_SECURITY_WEP;
331 #if defined TIZEN_EXT
332 if (!strcmp(str, "rsn"))
333 return CONNMAN_SERVICE_SECURITY_RSN;
336 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
339 static const char *security2string(enum connman_service_security security)
342 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
344 case CONNMAN_SERVICE_SECURITY_NONE:
346 case CONNMAN_SERVICE_SECURITY_WEP:
348 case CONNMAN_SERVICE_SECURITY_PSK:
349 case CONNMAN_SERVICE_SECURITY_WPA:
350 #if defined TIZEN_EXT
352 case CONNMAN_SERVICE_SECURITY_RSN:
355 case CONNMAN_SERVICE_SECURITY_RSN:
358 case CONNMAN_SERVICE_SECURITY_8021X:
365 static const char *state2string(enum connman_service_state state)
368 case CONNMAN_SERVICE_STATE_UNKNOWN:
370 case CONNMAN_SERVICE_STATE_IDLE:
372 case CONNMAN_SERVICE_STATE_ASSOCIATION:
373 return "association";
374 case CONNMAN_SERVICE_STATE_CONFIGURATION:
375 return "configuration";
376 case CONNMAN_SERVICE_STATE_READY:
378 case CONNMAN_SERVICE_STATE_ONLINE:
380 case CONNMAN_SERVICE_STATE_DISCONNECT:
382 case CONNMAN_SERVICE_STATE_FAILURE:
389 static const char *error2string(enum connman_service_error error)
392 case CONNMAN_SERVICE_ERROR_UNKNOWN:
394 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
395 return "out-of-range";
396 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
397 return "pin-missing";
398 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
399 return "dhcp-failed";
400 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
401 return "connect-failed";
402 case CONNMAN_SERVICE_ERROR_LOGIN_FAILED:
403 return "login-failed";
404 case CONNMAN_SERVICE_ERROR_AUTH_FAILED:
405 return "auth-failed";
406 case CONNMAN_SERVICE_ERROR_INVALID_KEY:
407 return "invalid-key";
408 case CONNMAN_SERVICE_ERROR_BLOCKED:
415 static const char *proxymethod2string(enum connman_service_proxy_method method)
418 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
420 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
422 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
424 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
431 static enum connman_service_proxy_method string2proxymethod(const char *method)
433 if (g_strcmp0(method, "direct") == 0)
434 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
435 else if (g_strcmp0(method, "auto") == 0)
436 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
437 else if (g_strcmp0(method, "manual") == 0)
438 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
440 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
444 static const char *__connman_dnsconfig_method2string(enum connman_dnsconfig_method method)
447 case CONNMAN_DNSCONFIG_METHOD_UNKNOWN:
449 case CONNMAN_DNSCONFIG_METHOD_MANUAL:
451 case CONNMAN_DNSCONFIG_METHOD_DHCP:
458 static enum connman_dnsconfig_method __connman_dnsconfig_string2method(
461 if (g_strcmp0(method, "manual") == 0)
462 return CONNMAN_DNSCONFIG_METHOD_MANUAL;
463 else if (g_strcmp0(method, "dhcp") == 0)
464 return CONNMAN_DNSCONFIG_METHOD_DHCP;
466 return CONNMAN_DNSCONFIG_METHOD_UNKNOWN;
471 connman_service_is_user_allowed(struct connman_service *service, uid_t uid)
473 uid_t favorite_user = service->user.favorite_user;
474 uid_t current_user = uid;
476 DBG("Service favorite UID: %d, current UID: %d", favorite_user, current_user);
477 if (favorite_user == USER_NONE || current_user == USER_ROOT)
480 if (favorite_user != current_user || current_user == USER_NONE) {
481 DBG("Current user is not a favorite user to this service!");
488 #if !defined TIZEN_EXT
489 static GList *connman_service_get_login_users()
493 GList *user_list = NULL;
497 while ((utmp = getutxent()) != NULL) {
498 DBG("User Name: %s", utmp->ut_user);
500 pwd = getpwnam(utmp->ut_user);
502 if (!g_list_find(user_list, GUINT_TO_POINTER(pwd->pw_uid)))
503 user_list = g_list_append(user_list,
504 GUINT_TO_POINTER(pwd->pw_uid));
506 DBG("User Name: %s, UID: %d", utmp->ut_user, pwd->pw_uid);
516 static bool is_service_owner_user_login(struct connman_service *service)
518 #if defined TIZEN_EXT
521 GList *list, *user_list;
524 /* Here we only care about wifi service */
525 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
528 DBG("service favorite user id is: %d", service->user.favorite_user);
530 user_list = connman_service_get_login_users();
531 if (user_list == NULL) {
532 DBG("Can not get any logged in user info.");
536 for (list = user_list; list; list = list->next) {
537 uid_t uid = GPOINTER_TO_UINT(list->data);
539 DBG("login user id is %d", uid);
541 if (service->user.favorite_user == uid) {
547 g_list_free(user_list);
553 int __connman_service_load_modifiable(struct connman_service *service)
556 GError *error = NULL;
560 DBG("service %p", service);
562 keyfile = connman_storage_load_service(service->identifier);
566 switch (service->type) {
567 case CONNMAN_SERVICE_TYPE_UNKNOWN:
568 case CONNMAN_SERVICE_TYPE_SYSTEM:
569 case CONNMAN_SERVICE_TYPE_GPS:
570 case CONNMAN_SERVICE_TYPE_P2P:
572 case CONNMAN_SERVICE_TYPE_VPN:
573 service->do_split_routing = g_key_file_get_boolean(keyfile,
574 service->identifier, "SplitRouting", NULL);
576 case CONNMAN_SERVICE_TYPE_WIFI:
577 case CONNMAN_SERVICE_TYPE_GADGET:
578 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
579 case CONNMAN_SERVICE_TYPE_CELLULAR:
580 case CONNMAN_SERVICE_TYPE_ETHERNET:
581 autoconnect = g_key_file_get_boolean(keyfile,
582 service->identifier, "AutoConnect", &error);
584 service->autoconnect = autoconnect;
585 g_clear_error(&error);
589 str = g_key_file_get_string(keyfile,
590 service->identifier, "Modified", NULL);
592 g_time_val_from_iso8601(str, &service->modified);
596 g_key_file_free(keyfile);
601 static int service_load_passphrase(struct connman_service *service)
606 keyfile = connman_storage_load_service(service->identifier);
610 str = g_key_file_get_string(keyfile,
611 service->identifier, "Passphrase", NULL);
613 service->passphrase = str;
615 g_key_file_free(keyfile);
620 static int service_load(struct connman_service *service)
623 GError *error = NULL;
627 unsigned int ssid_len;
630 DBG("service %p", service);
632 keyfile = connman_storage_load_service(service->identifier);
634 service->new_service = true;
637 service->new_service = false;
639 switch (service->type) {
640 case CONNMAN_SERVICE_TYPE_UNKNOWN:
641 case CONNMAN_SERVICE_TYPE_SYSTEM:
642 case CONNMAN_SERVICE_TYPE_GPS:
643 case CONNMAN_SERVICE_TYPE_P2P:
645 case CONNMAN_SERVICE_TYPE_VPN:
646 service->do_split_routing = g_key_file_get_boolean(keyfile,
647 service->identifier, "SplitRouting", NULL);
648 autoconnect = g_key_file_get_boolean(keyfile,
649 service->identifier, "AutoConnect", &error);
651 service->autoconnect = autoconnect;
652 g_clear_error(&error);
654 case CONNMAN_SERVICE_TYPE_WIFI:
655 if (!service->name) {
658 name = g_key_file_get_string(keyfile,
659 service->identifier, "Name", NULL);
661 g_free(service->name);
662 service->name = name;
665 if (service->network)
666 connman_network_set_name(service->network,
670 if (service->network &&
671 !connman_network_get_blob(service->network,
672 "WiFi.SSID", &ssid_len)) {
675 hex_ssid = g_key_file_get_string(keyfile,
681 unsigned int i, j = 0, hex;
682 size_t hex_ssid_len = strlen(hex_ssid);
684 ssid = g_try_malloc0(hex_ssid_len / 2);
691 for (i = 0; i < hex_ssid_len; i += 2) {
692 sscanf(hex_ssid + i, "%02x", &hex);
696 connman_network_set_blob(service->network,
697 "WiFi.SSID", ssid, hex_ssid_len / 2);
706 case CONNMAN_SERVICE_TYPE_GADGET:
707 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
708 case CONNMAN_SERVICE_TYPE_CELLULAR:
709 service->favorite = g_key_file_get_boolean(keyfile,
710 service->identifier, "Favorite", NULL);
714 case CONNMAN_SERVICE_TYPE_ETHERNET:
715 autoconnect = g_key_file_get_boolean(keyfile,
716 service->identifier, "AutoConnect", &error);
718 service->autoconnect = autoconnect;
719 g_clear_error(&error);
723 str = g_key_file_get_string(keyfile,
724 service->identifier, "Modified", NULL);
726 g_time_val_from_iso8601(str, &service->modified);
730 str = g_key_file_get_string(keyfile,
731 service->identifier, "Passphrase", NULL);
733 g_free(service->passphrase);
734 service->passphrase = str;
737 if (service->ipconfig_ipv4)
738 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
739 service->identifier, "IPv4.");
741 if (service->ipconfig_ipv6)
742 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
743 service->identifier, "IPv6.");
745 service->nameservers_config = g_key_file_get_string_list(keyfile,
746 service->identifier, "Nameservers", &length, NULL);
747 if (service->nameservers_config && length == 0) {
748 g_strfreev(service->nameservers_config);
749 service->nameservers_config = NULL;
755 dns_method = g_key_file_get_string(keyfile, service->identifier,
756 "Nameservers.IPv4method", NULL);
757 service->dns_config_method_ipv4 = __connman_dnsconfig_string2method(dns_method);
759 dns_method = g_key_file_get_string(keyfile, service->identifier,
760 "Nameservers.IPv6method", NULL);
761 service->dns_config_method_ipv6 = __connman_dnsconfig_string2method(dns_method);
764 service->timeservers_config = g_key_file_get_string_list(keyfile,
765 service->identifier, "Timeservers", &length, NULL);
766 if (service->timeservers_config && length == 0) {
767 g_strfreev(service->timeservers_config);
768 service->timeservers_config = NULL;
771 service->domains = g_key_file_get_string_list(keyfile,
772 service->identifier, "Domains", &length, NULL);
773 if (service->domains && length == 0) {
774 g_strfreev(service->domains);
775 service->domains = NULL;
778 str = g_key_file_get_string(keyfile,
779 service->identifier, "Proxy.Method", NULL);
781 service->proxy_config = string2proxymethod(str);
785 service->proxies = g_key_file_get_string_list(keyfile,
786 service->identifier, "Proxy.Servers", &length, NULL);
787 if (service->proxies && length == 0) {
788 g_strfreev(service->proxies);
789 service->proxies = NULL;
792 service->excludes = g_key_file_get_string_list(keyfile,
793 service->identifier, "Proxy.Excludes", &length, NULL);
794 if (service->excludes && length == 0) {
795 g_strfreev(service->excludes);
796 service->excludes = NULL;
799 str = g_key_file_get_string(keyfile,
800 service->identifier, "Proxy.URL", NULL);
802 g_free(service->pac);
806 service->hidden_service = g_key_file_get_boolean(keyfile,
807 service->identifier, "Hidden", NULL);
809 #if defined TIZEN_EXT
810 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
811 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
812 str = g_key_file_get_string(keyfile,
813 service->identifier, "EAP", NULL);
815 g_free(service->eap);
819 str = g_key_file_get_string(keyfile,
820 service->identifier, "Phase2", NULL);
822 g_free(service->phase2);
823 service->phase2 = str;
826 str = g_key_file_get_string(keyfile,
827 service->identifier, "Identity", NULL);
829 g_free(service->identity);
830 service->identity = str;
833 str = g_key_file_get_string(keyfile,
834 service->identifier, "CACertFile", NULL);
836 g_free(service->ca_cert_file);
837 service->ca_cert_file = str;
840 str = g_key_file_get_string(keyfile,
841 service->identifier, "ClientCertFile", NULL);
843 g_free(service->client_cert_file);
844 service->client_cert_file = str;
847 str = g_key_file_get_string(keyfile,
848 service->identifier, "PrivateKeyFile", NULL);
850 g_free(service->private_key_file);
851 service->private_key_file = str;
854 str = g_key_file_get_string(keyfile,
855 service->identifier, "PrivateKeyPassphrase", NULL);
857 g_free(service->private_key_passphrase);
858 service->private_key_passphrase = str;
863 if (g_key_file_has_key(keyfile, service->identifier, "UID", NULL))
864 service->user.favorite_user = g_key_file_get_integer(keyfile,
865 service->identifier, "UID", NULL);
867 g_key_file_free(keyfile);
872 static int service_save(struct connman_service *service)
877 const char *cst_str = NULL;
880 DBG("service %p new %d", service, service->new_service);
882 if (service->new_service)
885 keyfile = __connman_storage_open_service(service->identifier);
890 g_key_file_set_string(keyfile, service->identifier,
891 "Name", service->name);
893 switch (service->type) {
894 case CONNMAN_SERVICE_TYPE_UNKNOWN:
895 case CONNMAN_SERVICE_TYPE_SYSTEM:
896 case CONNMAN_SERVICE_TYPE_GPS:
897 case CONNMAN_SERVICE_TYPE_P2P:
899 case CONNMAN_SERVICE_TYPE_VPN:
900 g_key_file_set_boolean(keyfile, service->identifier,
901 "SplitRouting", service->do_split_routing);
902 if (service->favorite)
903 g_key_file_set_boolean(keyfile, service->identifier,
904 "AutoConnect", service->autoconnect);
906 case CONNMAN_SERVICE_TYPE_WIFI:
907 if (service->network) {
908 const unsigned char *ssid;
909 unsigned int ssid_len = 0;
911 if (service->user.favorite_user == USER_NONE)
912 g_key_file_remove_key(keyfile, service->identifier,
915 g_key_file_set_integer(keyfile, service->identifier,
916 "UID", service->user.favorite_user);
918 ssid = connman_network_get_blob(service->network,
919 "WiFi.SSID", &ssid_len);
921 if (ssid && ssid_len > 0 && ssid[0] != '\0') {
922 char *identifier = service->identifier;
926 ssid_str = g_string_sized_new(ssid_len * 2);
932 for (i = 0; i < ssid_len; i++)
933 g_string_append_printf(ssid_str,
936 g_key_file_set_string(keyfile, identifier,
937 "SSID", ssid_str->str);
939 g_string_free(ssid_str, TRUE);
942 freq = connman_network_get_frequency(service->network);
943 g_key_file_set_integer(keyfile, service->identifier,
948 case CONNMAN_SERVICE_TYPE_GADGET:
949 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
950 case CONNMAN_SERVICE_TYPE_CELLULAR:
951 g_key_file_set_boolean(keyfile, service->identifier,
952 "Favorite", service->favorite);
954 g_key_file_remove_key(keyfile, service->identifier,
959 case CONNMAN_SERVICE_TYPE_ETHERNET:
960 if (service->favorite)
961 g_key_file_set_boolean(keyfile, service->identifier,
962 "AutoConnect", service->autoconnect);
966 str = g_time_val_to_iso8601(&service->modified);
968 g_key_file_set_string(keyfile, service->identifier,
973 if (service->user.current_user == service->user.favorite_user) {
974 if (service->passphrase && strlen(service->passphrase) > 0)
975 g_key_file_set_string(keyfile, service->identifier,
976 "Passphrase", service->passphrase);
978 g_key_file_remove_key(keyfile, service->identifier,
982 if (service->ipconfig_ipv4)
983 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
984 service->identifier, "IPv4.");
986 if (service->ipconfig_ipv6)
987 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
988 service->identifier, "IPv6.");
990 if (service->nameservers_config) {
991 guint len = g_strv_length(service->nameservers_config);
993 g_key_file_set_string_list(keyfile, service->identifier,
995 (const gchar **) service->nameservers_config, len);
997 g_key_file_remove_key(keyfile, service->identifier,
998 "Nameservers", NULL);
1000 #if defined TIZEN_EXT
1001 if(service->dns_config_method_ipv4 != 0) {
1003 method = __connman_dnsconfig_method2string(
1004 service->dns_config_method_ipv4);
1005 g_key_file_set_string(keyfile, service->identifier,
1006 "Nameservers.IPv4method", method);
1008 g_key_file_remove_key(keyfile, service->identifier,
1009 "Nameservers.IPv4method", NULL);
1011 if(service->dns_config_method_ipv6 != 0) {
1013 method = __connman_dnsconfig_method2string(
1014 service->dns_config_method_ipv6);
1015 g_key_file_set_string(keyfile, service->identifier,
1016 "Nameservers.IPv6method", method);
1018 g_key_file_remove_key(keyfile, service->identifier,
1019 "Nameservers.IPv6method", NULL);
1022 if (service->timeservers_config) {
1023 guint len = g_strv_length(service->timeservers_config);
1025 g_key_file_set_string_list(keyfile, service->identifier,
1027 (const gchar **) service->timeservers_config, len);
1029 g_key_file_remove_key(keyfile, service->identifier,
1030 "Timeservers", NULL);
1032 if (service->domains) {
1033 guint len = g_strv_length(service->domains);
1035 g_key_file_set_string_list(keyfile, service->identifier,
1037 (const gchar **) service->domains, len);
1039 g_key_file_remove_key(keyfile, service->identifier,
1042 cst_str = proxymethod2string(service->proxy_config);
1044 g_key_file_set_string(keyfile, service->identifier,
1045 "Proxy.Method", cst_str);
1047 if (service->proxies) {
1048 guint len = g_strv_length(service->proxies);
1050 g_key_file_set_string_list(keyfile, service->identifier,
1052 (const gchar **) service->proxies, len);
1054 g_key_file_remove_key(keyfile, service->identifier,
1055 "Proxy.Servers", NULL);
1057 if (service->excludes) {
1058 guint len = g_strv_length(service->excludes);
1060 g_key_file_set_string_list(keyfile, service->identifier,
1062 (const gchar **) service->excludes, len);
1064 g_key_file_remove_key(keyfile, service->identifier,
1065 "Proxy.Excludes", NULL);
1067 if (service->pac && strlen(service->pac) > 0)
1068 g_key_file_set_string(keyfile, service->identifier,
1069 "Proxy.URL", service->pac);
1071 g_key_file_remove_key(keyfile, service->identifier,
1074 if (service->hidden_service)
1075 g_key_file_set_boolean(keyfile, service->identifier, "Hidden",
1078 if (service->config_file && strlen(service->config_file) > 0)
1079 g_key_file_set_string(keyfile, service->identifier,
1080 "Config.file", service->config_file);
1082 if (service->config_entry &&
1083 strlen(service->config_entry) > 0)
1084 g_key_file_set_string(keyfile, service->identifier,
1085 "Config.ident", service->config_entry);
1087 #if defined TIZEN_EXT
1088 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1089 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
1090 if (service->eap != NULL && strlen(service->eap) > 0)
1091 g_key_file_set_string(keyfile, service->identifier,
1092 "EAP", service->eap);
1094 g_key_file_remove_key(keyfile, service->identifier,
1097 if (service->phase2 != NULL && strlen(service->phase2) > 0)
1098 g_key_file_set_string(keyfile, service->identifier,
1099 "Phase2", service->phase2);
1101 g_key_file_remove_key(keyfile, service->identifier,
1104 if (service->identity != NULL && strlen(service->identity) > 0)
1105 g_key_file_set_string(keyfile, service->identifier,
1106 "Identity", service->identity);
1108 g_key_file_remove_key(keyfile, service->identifier,
1111 if (service->ca_cert_file != NULL && strlen(service->ca_cert_file) > 0)
1112 g_key_file_set_string(keyfile, service->identifier,
1113 "CACertFile", service->ca_cert_file);
1115 g_key_file_remove_key(keyfile, service->identifier,
1116 "CACertFile", NULL);
1118 if (service->client_cert_file != NULL && strlen(service->client_cert_file) > 0)
1119 g_key_file_set_string(keyfile, service->identifier,
1120 "ClientCertFile", service->client_cert_file);
1122 g_key_file_remove_key(keyfile, service->identifier,
1123 "ClientCertFile", NULL);
1125 if (service->private_key_file != NULL && strlen(service->private_key_file) > 0)
1126 g_key_file_set_string(keyfile, service->identifier,
1127 "PrivateKeyFile", service->private_key_file);
1129 g_key_file_remove_key(keyfile, service->identifier,
1130 "PrivateKeyFile", NULL);
1132 if (service->private_key_passphrase != NULL && strlen(service->private_key_passphrase) > 0)
1133 g_key_file_set_string(keyfile, service->identifier,
1134 "PrivateKeyPassphrase", service->private_key_passphrase);
1136 g_key_file_remove_key(keyfile, service->identifier,
1137 "PrivateKeyPassphrase", NULL);
1142 __connman_storage_save_service(keyfile, service->identifier);
1144 g_key_file_free(keyfile);
1149 void __connman_service_save(struct connman_service *service)
1154 service_save(service);
1157 static enum connman_service_state combine_state(
1158 enum connman_service_state state_a,
1159 enum connman_service_state state_b)
1161 enum connman_service_state result;
1163 if (state_a == state_b) {
1168 if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
1173 if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
1178 if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
1183 if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
1188 if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
1193 if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
1198 if (state_a == CONNMAN_SERVICE_STATE_READY) {
1203 if (state_b == CONNMAN_SERVICE_STATE_READY) {
1208 if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1213 if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1218 if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1223 if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1228 if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
1233 if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
1238 result = CONNMAN_SERVICE_STATE_FAILURE;
1244 static bool is_connecting_state(struct connman_service *service,
1245 enum connman_service_state state)
1248 case CONNMAN_SERVICE_STATE_UNKNOWN:
1249 case CONNMAN_SERVICE_STATE_IDLE:
1250 case CONNMAN_SERVICE_STATE_FAILURE:
1251 if (service->network)
1252 return connman_network_get_connecting(service->network);
1253 case CONNMAN_SERVICE_STATE_DISCONNECT:
1254 case CONNMAN_SERVICE_STATE_READY:
1255 case CONNMAN_SERVICE_STATE_ONLINE:
1257 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1258 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1265 static bool is_connected_state(const struct connman_service *service,
1266 enum connman_service_state state)
1269 case CONNMAN_SERVICE_STATE_UNKNOWN:
1270 case CONNMAN_SERVICE_STATE_IDLE:
1271 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1272 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1273 case CONNMAN_SERVICE_STATE_DISCONNECT:
1274 case CONNMAN_SERVICE_STATE_FAILURE:
1276 case CONNMAN_SERVICE_STATE_READY:
1277 case CONNMAN_SERVICE_STATE_ONLINE:
1284 static bool is_idle_state(const struct connman_service *service,
1285 enum connman_service_state state)
1288 case CONNMAN_SERVICE_STATE_UNKNOWN:
1289 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1290 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1291 case CONNMAN_SERVICE_STATE_READY:
1292 case CONNMAN_SERVICE_STATE_ONLINE:
1293 case CONNMAN_SERVICE_STATE_DISCONNECT:
1294 case CONNMAN_SERVICE_STATE_FAILURE:
1296 case CONNMAN_SERVICE_STATE_IDLE:
1303 static bool is_connecting(struct connman_service *service)
1305 return is_connecting_state(service, service->state);
1308 static bool is_connected(struct connman_service *service)
1310 return is_connected_state(service, service->state);
1313 static bool nameserver_available(struct connman_service *service,
1318 family = connman_inet_check_ipaddress(ns);
1320 if (family == AF_INET)
1321 return is_connected_state(service, service->state_ipv4);
1323 if (family == AF_INET6)
1324 return is_connected_state(service, service->state_ipv6);
1329 static int nameserver_add(struct connman_service *service,
1330 const char *nameserver)
1334 if (!nameserver_available(service, nameserver))
1337 index = __connman_service_get_index(service);
1341 #if defined TIZEN_EXT
1342 DBG("Resolver append nameserver: %s", nameserver);
1344 return connman_resolver_append(index, NULL, nameserver);
1347 #if defined TIZEN_EXT
1348 static int nameserver_add_all(struct connman_service *service,
1349 enum connman_ipconfig_type type)
1351 static int nameserver_add_all(struct connman_service *service)
1356 if (service->nameservers_config) {
1357 while (service->nameservers_config[i]) {
1358 #if defined TIZEN_EXT
1359 DBG("type %d add service->nameservers_config[%d]:%s",type,
1360 i, service->nameservers_config[i]);
1361 if(strncmp(service->nameservers_config[i], "::", 2) == 0) {
1362 DBG("Invalid nameserver");
1368 case CONNMAN_IPCONFIG_TYPE_IPV4:
1369 if (connman_inet_check_ipaddress(
1370 service->nameservers_config[i]) == AF_INET &&
1371 service->dns_config_method_ipv4 ==
1372 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1373 nameserver_add(service,
1374 service->nameservers_config[i]);
1377 case CONNMAN_IPCONFIG_TYPE_IPV6:
1378 if (connman_inet_check_ipaddress(
1379 service->nameservers_config[i]) == AF_INET6 &&
1380 service->dns_config_method_ipv6 ==
1381 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1382 nameserver_add(service,
1383 service->nameservers_config[i]);
1386 case CONNMAN_IPCONFIG_TYPE_ALL:
1387 if (connman_inet_check_ipaddress(
1388 service->nameservers_config[i]) == AF_INET &&
1389 service->dns_config_method_ipv4 ==
1390 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1391 nameserver_add(service,
1392 service->nameservers_config[i]);
1394 if (connman_inet_check_ipaddress(
1395 service->nameservers_config[i]) == AF_INET6 &&
1396 service->dns_config_method_ipv6 ==
1397 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1398 nameserver_add(service,
1399 service->nameservers_config[i]);
1402 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1403 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1406 DBG("default case do nothing");
1410 nameserver_add(service, service->nameservers_config[i]);
1414 #if !defined TIZEN_EXT
1419 #if defined TIZEN_EXT
1422 if (service->nameservers) {
1423 while (service->nameservers[i]) {
1424 #if defined TIZEN_EXT
1425 DBG("type %d service->nameservers[%d]: %s",type,
1426 i, service->nameservers[i]);
1429 case CONNMAN_IPCONFIG_TYPE_IPV4:
1430 if (connman_inet_check_ipaddress(
1431 service->nameservers[i]) == AF_INET &&
1432 service->dns_config_method_ipv4 ==
1433 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1434 nameserver_add(service,
1435 service->nameservers[i]);
1438 case CONNMAN_IPCONFIG_TYPE_IPV6:
1439 if (connman_inet_check_ipaddress(
1440 service->nameservers[i]) == AF_INET6 &&
1441 service->dns_config_method_ipv6 ==
1442 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1443 nameserver_add(service,
1444 service->nameservers[i]);
1447 case CONNMAN_IPCONFIG_TYPE_ALL:
1448 if (connman_inet_check_ipaddress(
1449 service->nameservers[i]) == AF_INET &&
1450 service->dns_config_method_ipv4 ==
1451 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1452 nameserver_add(service,
1453 service->nameservers[i]);
1455 if (connman_inet_check_ipaddress(
1456 service->nameservers[i]) == AF_INET6 &&
1457 service->dns_config_method_ipv6 ==
1458 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1459 nameserver_add(service,
1460 service->nameservers[i]);
1463 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1464 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1467 DBG("default case do nothing");
1471 nameserver_add(service, service->nameservers[i]);
1480 static int nameserver_remove(struct connman_service *service,
1481 const char *nameserver)
1485 if (!nameserver_available(service, nameserver))
1488 index = __connman_service_get_index(service);
1492 #if defined TIZEN_EXT
1493 DBG("Resolver remove nameserver: %s", nameserver);
1495 return connman_resolver_remove(index, NULL, nameserver);
1498 #if defined TIZEN_EXT
1499 static int nameserver_remove_all(struct connman_service *service,
1500 enum connman_ipconfig_type type)
1502 static int nameserver_remove_all(struct connman_service *service)
1505 #if defined TIZEN_EXT
1507 * Skip this function if there is any connected profiles
1508 * that use same interface
1510 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
1511 __connman_service_get_connected_count_of_iface(service) > 0)
1516 index = __connman_service_get_index(service);
1520 while (service->nameservers_config && service->nameservers_config[i]) {
1521 #if defined TIZEN_EXT
1522 DBG("type %d Remove service->nameservers_config[%d]: %s",
1523 type, i, service->nameservers_config[i]);
1525 case CONNMAN_IPCONFIG_TYPE_IPV4:
1526 if (connman_inet_check_ipaddress(
1527 service->nameservers_config[i]) == AF_INET &&
1528 (service->dns_config_method_ipv4 ==
1529 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1530 service->dns_config_method_ipv4 ==
1531 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1532 nameserver_remove(service,
1533 service->nameservers_config[i]);
1536 case CONNMAN_IPCONFIG_TYPE_IPV6:
1537 if (connman_inet_check_ipaddress(
1538 service->nameservers_config[i]) == AF_INET6 &&
1539 (service->dns_config_method_ipv6 ==
1540 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1541 service->dns_config_method_ipv6 ==
1542 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1543 nameserver_remove(service,
1544 service->nameservers_config[i]);
1547 case CONNMAN_IPCONFIG_TYPE_ALL:
1548 if (connman_inet_check_ipaddress(
1549 service->nameservers_config[i]) == AF_INET &&
1550 (service->dns_config_method_ipv4 ==
1551 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1552 service->dns_config_method_ipv4 ==
1553 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1554 nameserver_remove(service,
1555 service->nameservers_config[i]);
1557 if (connman_inet_check_ipaddress(
1558 service->nameservers_config[i]) == AF_INET6 &&
1559 (service->dns_config_method_ipv6 ==
1560 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1561 service->dns_config_method_ipv6 ==
1562 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1563 nameserver_remove(service,
1564 service->nameservers_config[i]);
1567 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1568 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1571 DBG("default case do nothing");
1575 nameserver_remove(service, service->nameservers_config[i]);
1581 while (service->nameservers && service->nameservers[i]) {
1582 #if defined TIZEN_EXT
1583 DBG("type %d Remove service->nameservers[%d]: %s",type, i,
1584 service->nameservers[i]);
1586 case CONNMAN_IPCONFIG_TYPE_IPV4:
1587 if (connman_inet_check_ipaddress(
1588 service->nameservers[i]) == AF_INET &&
1589 (service->dns_config_method_ipv4 ==
1590 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1591 service->dns_config_method_ipv4 ==
1592 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1593 nameserver_remove(service,
1594 service->nameservers[i]);
1597 case CONNMAN_IPCONFIG_TYPE_IPV6:
1598 if (connman_inet_check_ipaddress(
1599 service->nameservers[i]) == AF_INET6 &&
1600 (service->dns_config_method_ipv6 ==
1601 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1602 service->dns_config_method_ipv6 ==
1603 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1604 nameserver_remove(service,
1605 service->nameservers[i]);
1608 case CONNMAN_IPCONFIG_TYPE_ALL:
1609 if (connman_inet_check_ipaddress(
1610 service->nameservers[i]) == AF_INET &&
1611 (service->dns_config_method_ipv4 ==
1612 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1613 service->dns_config_method_ipv4 ==
1614 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1615 nameserver_remove(service,
1616 service->nameservers[i]);
1618 if (connman_inet_check_ipaddress(
1619 service->nameservers[i]) == AF_INET6 &&
1620 (service->dns_config_method_ipv6 ==
1621 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1622 service->dns_config_method_ipv6 ==
1623 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1624 nameserver_remove(service,
1625 service->nameservers[i]);
1628 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1629 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1632 DBG("default case do nothing");
1636 nameserver_remove(service, service->nameservers[i]);
1644 static int searchdomain_add_all(struct connman_service *service)
1648 if (!is_connected(service))
1651 index = __connman_service_get_index(service);
1655 if (service->domains) {
1656 while (service->domains[i]) {
1657 connman_resolver_append(index, service->domains[i],
1665 if (service->domainname)
1666 connman_resolver_append(index, service->domainname, NULL);
1672 static int searchdomain_remove_all(struct connman_service *service)
1676 if (!is_connected(service))
1679 index = __connman_service_get_index(service);
1683 while (service->domains && service->domains[i]) {
1684 connman_resolver_remove(index, service->domains[i], NULL);
1688 if (service->domainname)
1689 connman_resolver_remove(index, service->domainname, NULL);
1695 * The is_auto variable is set to true when IPv6 autoconf nameservers are
1696 * inserted to resolver via netlink message (see rtnl.c:rtnl_newnduseropt()
1697 * for details) and not through service.c
1699 #if defined TIZEN_EXT
1700 int __connman_service_nameserver_append(struct connman_service *service,
1701 const char *nameserver, bool is_auto,
1702 enum connman_ipconfig_type type)
1704 int __connman_service_nameserver_append(struct connman_service *service,
1705 const char *nameserver, bool is_auto)
1711 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1717 nameservers = service->nameservers_auto;
1719 nameservers = service->nameservers;
1721 for (i = 0; nameservers && nameservers[i]; i++)
1722 #if defined TIZEN_EXT
1724 DBG("nameservers[%d] %s, nameserver %s", i, nameservers[i], nameserver);
1726 if (g_strcmp0(nameservers[i], nameserver) == 0)
1728 #if defined TIZEN_EXT
1733 len = g_strv_length(nameservers);
1734 nameservers = g_try_renew(char *, nameservers, len + 2);
1737 nameservers = g_try_new0(char *, len + 2);
1743 nameservers[len] = g_strdup(nameserver);
1744 nameservers[len + 1] = NULL;
1747 if(type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
1748 service->dns_config_method_ipv4 ==
1749 CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
1750 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
1752 if(type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
1753 service->dns_config_method_ipv6 ==
1754 CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
1755 service->dns_config_method_ipv6 = CONNMAN_DNSCONFIG_METHOD_DHCP;
1759 service->nameservers_auto = nameservers;
1761 service->nameservers = nameservers;
1762 #if defined TIZEN_EXT
1763 DBG("nameserver add: %s, type: %d", nameserver, type);
1765 nameserver_add(service, nameserver);
1771 #if defined TIZEN_EXT
1772 int __connman_service_nameserver_remove(struct connman_service *service,
1773 const char *nameserver, bool is_auto,
1774 enum connman_ipconfig_type type)
1776 int __connman_service_nameserver_remove(struct connman_service *service,
1777 const char *nameserver, bool is_auto)
1780 char **servers, **nameservers;
1784 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1790 nameservers = service->nameservers_auto;
1792 nameservers = service->nameservers;
1797 for (i = 0; nameservers && nameservers[i]; i++)
1798 if (g_strcmp0(nameservers[i], nameserver) == 0) {
1806 len = g_strv_length(nameservers);
1813 servers = g_try_new0(char *, len);
1817 for (i = 0, j = 0; i < len; i++) {
1818 if (g_strcmp0(nameservers[i], nameserver)) {
1819 servers[j] = nameservers[i];
1822 g_free(nameservers[i]);
1824 nameservers[i] = NULL;
1826 servers[len - 1] = NULL;
1829 g_strfreev(nameservers);
1830 nameservers = servers;
1833 service->nameservers_auto = nameservers;
1835 service->nameservers = nameservers;
1836 #if defined TIZEN_EXT
1837 DBG("nameserver remove ip_type: %d", type);
1839 nameserver_remove(service, nameserver);
1845 void __connman_service_nameserver_clear(struct connman_service *service)
1847 #if defined TIZEN_EXT
1848 DBG("nameserver remove all ip_type: CONNMAN_IPCONFIG_TYPE_ALL");
1849 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
1851 nameserver_remove_all(service);
1854 g_strfreev(service->nameservers);
1855 service->nameservers = NULL;
1857 #if defined TIZEN_EXT
1858 DBG("nameserver add all ip_type: CONNMAN_IPCONFIG_TYPE_ALL");
1859 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
1861 nameserver_add_all(service);
1866 static void add_nameserver_route(int family, int index, char *nameserver,
1871 if (connman_inet_compare_subnet(index, nameserver))
1874 if (connman_inet_add_host_route(index, nameserver, gw) < 0)
1875 /* For P-t-P link the above route add will fail */
1876 connman_inet_add_host_route(index, nameserver, NULL);
1880 if (connman_inet_add_ipv6_host_route(index, nameserver,
1882 connman_inet_add_ipv6_host_route(index, nameserver,
1888 static void nameserver_add_routes(int index, char **nameservers,
1891 int i, ns_family, gw_family;
1893 gw_family = connman_inet_check_ipaddress(gw);
1897 for (i = 0; nameservers[i]; i++) {
1898 ns_family = connman_inet_check_ipaddress(nameservers[i]);
1899 if (ns_family < 0 || ns_family != gw_family)
1902 add_nameserver_route(ns_family, index, nameservers[i], gw);
1906 static void nameserver_del_routes(int index, char **nameservers,
1907 enum connman_ipconfig_type type)
1911 for (i = 0; nameservers[i]; i++) {
1912 family = connman_inet_check_ipaddress(nameservers[i]);
1918 if (type != CONNMAN_IPCONFIG_TYPE_IPV6)
1919 connman_inet_del_host_route(index,
1923 if (type != CONNMAN_IPCONFIG_TYPE_IPV4)
1924 connman_inet_del_ipv6_host_route(index,
1931 void __connman_service_nameserver_add_routes(struct connman_service *service,
1939 index = __connman_service_get_index(service);
1941 if (service->nameservers_config) {
1943 * Configured nameserver takes preference over the
1944 * discoverd nameserver gathered from DHCP, VPN, etc.
1946 nameserver_add_routes(index, service->nameservers_config, gw);
1947 } else if (service->nameservers) {
1949 * We add nameservers host routes for nameservers that
1950 * are not on our subnet. For those who are, the subnet
1951 * route will be installed by the time the dns proxy code
1952 * tries to reach them. The subnet route is installed
1953 * when setting the interface IP address.
1955 nameserver_add_routes(index, service->nameservers, gw);
1959 void __connman_service_nameserver_del_routes(struct connman_service *service,
1960 enum connman_ipconfig_type type)
1967 index = __connman_service_get_index(service);
1969 if (service->nameservers_config)
1970 nameserver_del_routes(index, service->nameservers_config,
1972 else if (service->nameservers)
1973 nameserver_del_routes(index, service->nameservers, type);
1976 static struct connman_stats *stats_get(struct connman_service *service)
1978 if (service->roaming)
1979 return &service->stats_roaming;
1981 return &service->stats;
1984 static bool stats_enabled(struct connman_service *service)
1986 struct connman_stats *stats = stats_get(service);
1988 return stats->enabled;
1991 static void stats_start(struct connman_service *service)
1993 struct connman_stats *stats = stats_get(service);
1995 DBG("service %p", service);
2000 stats->enabled = true;
2001 stats->data_last.time = stats->data.time;
2003 g_timer_start(stats->timer);
2006 static void stats_stop(struct connman_service *service)
2008 struct connman_stats *stats = stats_get(service);
2009 unsigned int seconds;
2011 DBG("service %p", service);
2016 if (!stats->enabled)
2019 g_timer_stop(stats->timer);
2021 seconds = g_timer_elapsed(stats->timer, NULL);
2022 stats->data.time = stats->data_last.time + seconds;
2024 stats->enabled = false;
2027 static void reset_stats(struct connman_service *service)
2029 DBG("service %p", service);
2032 service->stats.valid = false;
2034 service->stats.data.rx_packets = 0;
2035 service->stats.data.tx_packets = 0;
2036 service->stats.data.rx_bytes = 0;
2037 service->stats.data.tx_bytes = 0;
2038 service->stats.data.rx_errors = 0;
2039 service->stats.data.tx_errors = 0;
2040 service->stats.data.rx_dropped = 0;
2041 service->stats.data.tx_dropped = 0;
2042 service->stats.data.time = 0;
2043 service->stats.data_last.time = 0;
2045 g_timer_reset(service->stats.timer);
2048 service->stats_roaming.valid = false;
2050 service->stats_roaming.data.rx_packets = 0;
2051 service->stats_roaming.data.tx_packets = 0;
2052 service->stats_roaming.data.rx_bytes = 0;
2053 service->stats_roaming.data.tx_bytes = 0;
2054 service->stats_roaming.data.rx_errors = 0;
2055 service->stats_roaming.data.tx_errors = 0;
2056 service->stats_roaming.data.rx_dropped = 0;
2057 service->stats_roaming.data.tx_dropped = 0;
2058 service->stats_roaming.data.time = 0;
2059 service->stats_roaming.data_last.time = 0;
2061 g_timer_reset(service->stats_roaming.timer);
2064 #if defined TIZEN_EXT
2065 static gboolean __connman_service_is_internet_profile(
2066 struct connman_service *cellular)
2068 const char internet_suffix[] = "_1";
2070 DBG("Service path: %s", cellular->path);
2072 if (g_str_has_suffix(cellular->path, internet_suffix) == TRUE)
2078 static gboolean __connman_service_is_tethering_profile(
2079 struct connman_service *cellular)
2081 const char tethering_suffix[] = "_5";
2083 DBG("Service path: %s", cellular->path);
2085 if (g_str_has_suffix(cellular->path, tethering_suffix) == TRUE)
2091 struct connman_service *connman_service_get_default_connection(void)
2094 struct connman_service *service;
2095 struct connman_service *default_service = NULL;
2097 for (list = service_list; list; list = list->next) {
2098 service = list->data;
2100 DBG("service: %p %s %s %s", service, service->name,
2101 state2string(service->state),
2102 __connman_service_type2string(service->type));
2104 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
2105 is_connected(service) == TRUE) {
2107 } else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
2108 __connman_service_is_internet_profile(service) == TRUE) {
2109 if (default_service == NULL)
2110 default_service = service;
2111 else if (is_connected(service) == TRUE &&
2112 is_connected(default_service) == FALSE)
2113 default_service = service;
2114 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET &&
2115 is_connected(service) == TRUE) {
2116 if (default_service == NULL)
2117 default_service = service;
2118 } else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH &&
2119 is_connected(service) == TRUE) {
2120 if (default_service == NULL)
2121 default_service = service;
2125 return default_service;
2129 struct connman_service *__connman_service_get_default(void)
2131 struct connman_service *service;
2136 service = service_list->data;
2138 if (!is_connected(service))
2144 bool __connman_service_index_is_default(int index)
2146 struct connman_service *service;
2151 service = __connman_service_get_default();
2153 return __connman_service_get_index(service) == index;
2156 static void default_changed(void)
2158 struct connman_service *service = __connman_service_get_default();
2160 if (service == current_default)
2163 DBG("current default %p %s", current_default,
2164 current_default ? current_default->identifier : "");
2165 DBG("new default %p %s", service, service ? service->identifier : "");
2167 #if defined TIZEN_EXT
2168 current_default = service;
2170 __connman_service_timeserver_changed(service, NULL);
2172 __connman_service_timeserver_changed(current_default, NULL);
2174 current_default = service;
2178 if (service->hostname &&
2179 connman_setting_get_bool("AllowHostnameUpdates"))
2180 __connman_utsname_set_hostname(service->hostname);
2182 if (service->domainname)
2183 __connman_utsname_set_domainname(service->domainname);
2186 __connman_notifier_default_changed(service);
2189 static void state_changed(struct connman_service *service)
2193 __connman_notifier_service_state_changed(service, service->state);
2195 str = state2string(service->state);
2199 #if !defined TIZEN_EXT
2200 if (!allow_property_changed(service))
2203 #if defined TIZEN_EXT
2204 DBG(" %s, %s", str, service->path);
2206 connman_dbus_property_changed_basic(service->path,
2207 CONNMAN_SERVICE_INTERFACE, "State",
2208 DBUS_TYPE_STRING, &str);
2211 static void strength_changed(struct connman_service *service)
2213 if (service->strength == 0)
2216 if (!allow_property_changed(service))
2219 connman_dbus_property_changed_basic(service->path,
2220 CONNMAN_SERVICE_INTERFACE, "Strength",
2221 DBUS_TYPE_BYTE, &service->strength);
2224 static void favorite_changed(struct connman_service *service)
2226 dbus_bool_t favorite;
2231 if (!allow_property_changed(service))
2234 favorite = service->favorite;
2235 connman_dbus_property_changed_basic(service->path,
2236 CONNMAN_SERVICE_INTERFACE, "Favorite",
2237 DBUS_TYPE_BOOLEAN, &favorite);
2240 static void immutable_changed(struct connman_service *service)
2242 dbus_bool_t immutable;
2247 if (!allow_property_changed(service))
2250 immutable = service->immutable;
2251 connman_dbus_property_changed_basic(service->path,
2252 CONNMAN_SERVICE_INTERFACE, "Immutable",
2253 DBUS_TYPE_BOOLEAN, &immutable);
2256 static void roaming_changed(struct connman_service *service)
2258 dbus_bool_t roaming;
2263 if (!allow_property_changed(service))
2266 roaming = service->roaming;
2267 connman_dbus_property_changed_basic(service->path,
2268 CONNMAN_SERVICE_INTERFACE, "Roaming",
2269 DBUS_TYPE_BOOLEAN, &roaming);
2272 static void autoconnect_changed(struct connman_service *service)
2274 dbus_bool_t autoconnect;
2279 if (!allow_property_changed(service))
2282 autoconnect = service->autoconnect;
2283 connman_dbus_property_changed_basic(service->path,
2284 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
2285 DBUS_TYPE_BOOLEAN, &autoconnect);
2288 static void append_security(DBusMessageIter *iter, void *user_data)
2290 struct connman_service *service = user_data;
2293 str = security2string(service->security);
2295 dbus_message_iter_append_basic(iter,
2296 DBUS_TYPE_STRING, &str);
2299 * Some access points incorrectly advertise WPS even when they
2300 * are configured as open or no security, so filter
2304 switch (service->security) {
2305 case CONNMAN_SERVICE_SECURITY_PSK:
2306 case CONNMAN_SERVICE_SECURITY_WPA:
2307 case CONNMAN_SERVICE_SECURITY_RSN:
2309 dbus_message_iter_append_basic(iter,
2310 DBUS_TYPE_STRING, &str);
2312 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
2313 case CONNMAN_SERVICE_SECURITY_NONE:
2314 case CONNMAN_SERVICE_SECURITY_WEP:
2315 case CONNMAN_SERVICE_SECURITY_8021X:
2321 static void append_ethernet(DBusMessageIter *iter, void *user_data)
2323 struct connman_service *service = user_data;
2325 if (service->ipconfig_ipv4)
2326 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
2328 else if (service->ipconfig_ipv6)
2329 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
2333 static void append_ipv4(DBusMessageIter *iter, void *user_data)
2335 struct connman_service *service = user_data;
2337 if (!is_connected_state(service, service->state_ipv4))
2340 if (service->ipconfig_ipv4)
2341 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
2344 static void append_ipv6(DBusMessageIter *iter, void *user_data)
2346 struct connman_service *service = user_data;
2348 if (!is_connected_state(service, service->state_ipv6))
2351 if (service->ipconfig_ipv6)
2352 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
2353 service->ipconfig_ipv4);
2356 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
2358 struct connman_service *service = user_data;
2360 if (service->ipconfig_ipv4)
2361 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
2365 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
2367 struct connman_service *service = user_data;
2369 if (service->ipconfig_ipv6)
2370 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
2374 static void append_nameservers(DBusMessageIter *iter,
2375 struct connman_service *service, char **servers)
2378 bool available = true;
2380 for (i = 0; servers[i]; i++) {
2382 available = nameserver_available(service, servers[i]);
2384 DBG("servers[%d] %s available %d", i, servers[i], available);
2387 dbus_message_iter_append_basic(iter,
2388 DBUS_TYPE_STRING, &servers[i]);
2392 #if defined TIZEN_EXT
2393 static void append_nameserver_manual(DBusMessageIter *iter,
2394 struct connman_service *service, const char *server)
2396 bool available = true;
2399 available = nameserver_available(service, server);
2402 dbus_message_iter_append_basic(iter,
2403 DBUS_TYPE_STRING, &server);
2406 static void append_nameserver_dhcp(DBusMessageIter *iter,
2407 struct connman_service *service, const char *server)
2409 bool available = true;
2412 available = nameserver_available(service, server);
2415 dbus_message_iter_append_basic(iter,
2416 DBUS_TYPE_STRING, &server);
2420 static void append_dns(DBusMessageIter *iter, void *user_data)
2422 struct connman_service *service = user_data;
2423 #if defined TIZEN_EXT
2427 if (!is_connected(service))
2433 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
2435 char *str1 = g_strdup_printf("ipv4.%s", str);
2436 dbus_message_iter_append_basic(iter,
2437 DBUS_TYPE_STRING, &str1);
2441 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
2443 char *str1 = g_strdup_printf("ipv6.%s", str);
2444 dbus_message_iter_append_basic(iter,
2445 DBUS_TYPE_STRING, &str1);
2450 if (service->nameservers_config) {
2451 #if defined TIZEN_EXT
2453 while (service->nameservers_config[i]) {
2454 if (connman_inet_check_ipaddress(
2455 service->nameservers_config[i]) == AF_INET &&
2456 service->dns_config_method_ipv4 ==
2457 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2458 append_nameserver_manual(iter, service,
2459 service->nameservers_config[i]);
2462 if (connman_inet_check_ipaddress(
2463 service->nameservers_config[i]) == AF_INET6 &&
2464 service->dns_config_method_ipv6 ==
2465 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2466 append_nameserver_manual(iter, service,
2467 service->nameservers_config[i]);
2471 /* In case of mixed DNS Config Type one of IPv4/IPv6 can be
2472 * dynamic while other is static so try to append the DNS
2473 * Address which is dynamic also */
2474 if (service->nameservers != NULL) {
2476 while (service->nameservers[i]) {
2477 if (connman_inet_check_ipaddress(
2478 service->nameservers[i]) == AF_INET &&
2479 service->dns_config_method_ipv4 ==
2480 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2481 append_nameserver_dhcp(iter, service,
2482 service->nameservers[i]);
2485 if (connman_inet_check_ipaddress(
2486 service->nameservers[i]) == AF_INET6 &&
2487 service->dns_config_method_ipv6 ==
2488 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2489 append_nameserver_dhcp(iter, service,
2490 service->nameservers[i]);
2496 append_nameservers(iter, service, service->nameservers_config);
2500 if (service->nameservers)
2501 #if defined TIZEN_EXT
2504 while (service->nameservers[i]) {
2505 if (connman_inet_check_ipaddress(
2506 service->nameservers[i]) == AF_INET &&
2507 service->dns_config_method_ipv4 ==
2508 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2509 append_nameserver_dhcp(iter, service,
2510 service->nameservers[i]);
2513 if (connman_inet_check_ipaddress(
2514 service->nameservers[i]) == AF_INET6 &&
2515 service->dns_config_method_ipv6 ==
2516 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2517 append_nameserver_dhcp(iter, service,
2518 service->nameservers[i]);
2524 append_nameservers(iter, service,
2525 service->nameservers);
2528 if (service->nameservers_auto)
2529 append_nameservers(iter, service,
2530 service->nameservers_auto);
2532 if (!service->nameservers && !service->nameservers_auto) {
2535 DBG("append fallback nameservers");
2537 ns = connman_setting_get_string_list("FallbackNameservers");
2539 append_nameservers(iter, service, ns);
2544 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
2546 struct connman_service *service = user_data;
2549 /* Append DNS Config Type */
2551 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
2553 char *str1 = g_strdup_printf("ipv4.%s", str);
2554 dbus_message_iter_append_basic(iter,
2555 DBUS_TYPE_STRING, &str1);
2559 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
2561 char *str1 = g_strdup_printf("ipv6.%s", str);
2562 dbus_message_iter_append_basic(iter,
2563 DBUS_TYPE_STRING, &str1);
2568 if (!service->nameservers_config)
2571 #if defined TIZEN_EXT
2573 while (service->nameservers_config[i]) {
2574 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET &&
2575 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2576 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
2579 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET6 &&
2580 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2581 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
2586 append_nameservers(iter, NULL, service->nameservers_config);
2590 static void append_ts(DBusMessageIter *iter, void *user_data)
2592 GSList *list = user_data;
2595 char *timeserver = list->data;
2598 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
2601 list = g_slist_next(list);
2605 static void append_tsconfig(DBusMessageIter *iter, void *user_data)
2607 struct connman_service *service = user_data;
2610 if (!service->timeservers_config)
2613 for (i = 0; service->timeservers_config[i]; i++) {
2614 dbus_message_iter_append_basic(iter,
2616 &service->timeservers_config[i]);
2620 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
2622 struct connman_service *service = user_data;
2625 if (!service->domains)
2628 for (i = 0; service->domains[i]; i++)
2629 dbus_message_iter_append_basic(iter,
2630 DBUS_TYPE_STRING, &service->domains[i]);
2633 static void append_domain(DBusMessageIter *iter, void *user_data)
2635 struct connman_service *service = user_data;
2637 if (!is_connected(service) &&
2638 !is_connecting(service))
2641 if (service->domains)
2642 append_domainconfig(iter, user_data);
2643 else if (service->domainname)
2644 dbus_message_iter_append_basic(iter,
2645 DBUS_TYPE_STRING, &service->domainname);
2648 static void append_proxies(DBusMessageIter *iter, void *user_data)
2650 struct connman_service *service = user_data;
2653 if (!service->proxies)
2656 for (i = 0; service->proxies[i]; i++)
2657 dbus_message_iter_append_basic(iter,
2658 DBUS_TYPE_STRING, &service->proxies[i]);
2661 static void append_excludes(DBusMessageIter *iter, void *user_data)
2663 struct connman_service *service = user_data;
2666 if (!service->excludes)
2669 for (i = 0; service->excludes[i]; i++)
2670 dbus_message_iter_append_basic(iter,
2671 DBUS_TYPE_STRING, &service->excludes[i]);
2674 static void append_proxy(DBusMessageIter *iter, void *user_data)
2676 struct connman_service *service = user_data;
2677 enum connman_service_proxy_method proxy;
2678 const char *pac = NULL;
2679 const char *method = proxymethod2string(
2680 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
2682 if (!is_connected(service))
2685 proxy = connman_service_get_proxy_method(service);
2688 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2690 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2692 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2693 connman_dbus_dict_append_array(iter, "Servers",
2694 DBUS_TYPE_STRING, append_proxies,
2697 connman_dbus_dict_append_array(iter, "Excludes",
2698 DBUS_TYPE_STRING, append_excludes,
2701 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2702 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
2703 if (service->ipconfig_ipv4)
2704 pac = __connman_ipconfig_get_proxy_autoconfig(
2705 service->ipconfig_ipv4);
2706 else if (service->ipconfig_ipv6)
2707 pac = __connman_ipconfig_get_proxy_autoconfig(
2708 service->ipconfig_ipv6);
2710 if (!service->pac && !pac)
2716 connman_dbus_dict_append_basic(iter, "URL",
2717 DBUS_TYPE_STRING, &pac);
2721 method = proxymethod2string(proxy);
2724 connman_dbus_dict_append_basic(iter, "Method",
2725 DBUS_TYPE_STRING, &method);
2728 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
2730 struct connman_service *service = user_data;
2733 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
2736 switch (service->proxy_config) {
2737 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2739 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2741 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2742 if (service->proxies)
2743 connman_dbus_dict_append_array(iter, "Servers",
2745 append_proxies, service);
2747 if (service->excludes)
2748 connman_dbus_dict_append_array(iter, "Excludes",
2750 append_excludes, service);
2752 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2754 connman_dbus_dict_append_basic(iter, "URL",
2755 DBUS_TYPE_STRING, &service->pac);
2759 method = proxymethod2string(service->proxy_config);
2761 connman_dbus_dict_append_basic(iter, "Method",
2762 DBUS_TYPE_STRING, &method);
2765 static void append_provider(DBusMessageIter *iter, void *user_data)
2767 struct connman_service *service = user_data;
2769 if (!is_connected(service))
2772 if (service->provider)
2773 __connman_provider_append_properties(service->provider, iter);
2777 static void settings_changed(struct connman_service *service,
2778 struct connman_ipconfig *ipconfig)
2780 enum connman_ipconfig_type type;
2782 if (!allow_property_changed(service))
2785 type = __connman_ipconfig_get_config_type(ipconfig);
2787 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
2788 connman_dbus_property_changed_dict(service->path,
2789 CONNMAN_SERVICE_INTERFACE, "IPv4",
2790 append_ipv4, service);
2791 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2792 connman_dbus_property_changed_dict(service->path,
2793 CONNMAN_SERVICE_INTERFACE, "IPv6",
2794 append_ipv6, service);
2796 __connman_notifier_ipconfig_changed(service, ipconfig);
2799 static void ipv4_configuration_changed(struct connman_service *service)
2801 if (!allow_property_changed(service))
2804 connman_dbus_property_changed_dict(service->path,
2805 CONNMAN_SERVICE_INTERFACE,
2806 "IPv4.Configuration",
2811 static void ipv6_configuration_changed(struct connman_service *service)
2813 if (!allow_property_changed(service))
2816 connman_dbus_property_changed_dict(service->path,
2817 CONNMAN_SERVICE_INTERFACE,
2818 "IPv6.Configuration",
2823 static void dns_changed(struct connman_service *service)
2825 if (!allow_property_changed(service))
2828 connman_dbus_property_changed_array(service->path,
2829 CONNMAN_SERVICE_INTERFACE, "Nameservers",
2830 DBUS_TYPE_STRING, append_dns, service);
2833 static void dns_configuration_changed(struct connman_service *service)
2835 if (!allow_property_changed(service))
2838 connman_dbus_property_changed_array(service->path,
2839 CONNMAN_SERVICE_INTERFACE,
2840 "Nameservers.Configuration",
2841 DBUS_TYPE_STRING, append_dnsconfig, service);
2843 dns_changed(service);
2846 static void domain_changed(struct connman_service *service)
2848 if (!allow_property_changed(service))
2851 connman_dbus_property_changed_array(service->path,
2852 CONNMAN_SERVICE_INTERFACE, "Domains",
2853 DBUS_TYPE_STRING, append_domain, service);
2856 static void domain_configuration_changed(struct connman_service *service)
2858 if (!allow_property_changed(service))
2861 connman_dbus_property_changed_array(service->path,
2862 CONNMAN_SERVICE_INTERFACE,
2863 "Domains.Configuration",
2864 DBUS_TYPE_STRING, append_domainconfig, service);
2867 static void proxy_changed(struct connman_service *service)
2869 if (!allow_property_changed(service))
2872 connman_dbus_property_changed_dict(service->path,
2873 CONNMAN_SERVICE_INTERFACE, "Proxy",
2874 append_proxy, service);
2877 static void proxy_configuration_changed(struct connman_service *service)
2879 if (!allow_property_changed(service))
2882 connman_dbus_property_changed_dict(service->path,
2883 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
2884 append_proxyconfig, service);
2886 proxy_changed(service);
2889 static void timeservers_configuration_changed(struct connman_service *service)
2891 if (!allow_property_changed(service))
2894 connman_dbus_property_changed_array(service->path,
2895 CONNMAN_SERVICE_INTERFACE,
2896 "Timeservers.Configuration",
2898 append_tsconfig, service);
2901 static void link_changed(struct connman_service *service)
2903 if (!allow_property_changed(service))
2906 connman_dbus_property_changed_dict(service->path,
2907 CONNMAN_SERVICE_INTERFACE, "Ethernet",
2908 append_ethernet, service);
2911 static void stats_append_counters(DBusMessageIter *dict,
2912 struct connman_stats_data *stats,
2913 struct connman_stats_data *counters,
2916 if (counters->rx_packets != stats->rx_packets || append_all) {
2917 counters->rx_packets = stats->rx_packets;
2918 connman_dbus_dict_append_basic(dict, "RX.Packets",
2919 DBUS_TYPE_UINT32, &stats->rx_packets);
2922 if (counters->tx_packets != stats->tx_packets || append_all) {
2923 counters->tx_packets = stats->tx_packets;
2924 connman_dbus_dict_append_basic(dict, "TX.Packets",
2925 DBUS_TYPE_UINT32, &stats->tx_packets);
2928 if (counters->rx_bytes != stats->rx_bytes || append_all) {
2929 counters->rx_bytes = stats->rx_bytes;
2930 connman_dbus_dict_append_basic(dict, "RX.Bytes",
2931 DBUS_TYPE_UINT32, &stats->rx_bytes);
2934 if (counters->tx_bytes != stats->tx_bytes || append_all) {
2935 counters->tx_bytes = stats->tx_bytes;
2936 connman_dbus_dict_append_basic(dict, "TX.Bytes",
2937 DBUS_TYPE_UINT32, &stats->tx_bytes);
2940 if (counters->rx_errors != stats->rx_errors || append_all) {
2941 counters->rx_errors = stats->rx_errors;
2942 connman_dbus_dict_append_basic(dict, "RX.Errors",
2943 DBUS_TYPE_UINT32, &stats->rx_errors);
2946 if (counters->tx_errors != stats->tx_errors || append_all) {
2947 counters->tx_errors = stats->tx_errors;
2948 connman_dbus_dict_append_basic(dict, "TX.Errors",
2949 DBUS_TYPE_UINT32, &stats->tx_errors);
2952 if (counters->rx_dropped != stats->rx_dropped || append_all) {
2953 counters->rx_dropped = stats->rx_dropped;
2954 connman_dbus_dict_append_basic(dict, "RX.Dropped",
2955 DBUS_TYPE_UINT32, &stats->rx_dropped);
2958 if (counters->tx_dropped != stats->tx_dropped || append_all) {
2959 counters->tx_dropped = stats->tx_dropped;
2960 connman_dbus_dict_append_basic(dict, "TX.Dropped",
2961 DBUS_TYPE_UINT32, &stats->tx_dropped);
2964 if (counters->time != stats->time || append_all) {
2965 counters->time = stats->time;
2966 connman_dbus_dict_append_basic(dict, "Time",
2967 DBUS_TYPE_UINT32, &stats->time);
2971 static void stats_append(struct connman_service *service,
2972 const char *counter,
2973 struct connman_stats_counter *counters,
2976 DBusMessageIter array, dict;
2979 DBG("service %p counter %s", service, counter);
2981 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
2985 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
2986 &service->path, DBUS_TYPE_INVALID);
2988 dbus_message_iter_init_append(msg, &array);
2991 connman_dbus_dict_open(&array, &dict);
2993 stats_append_counters(&dict, &service->stats.data,
2994 &counters->stats.data, append_all);
2996 connman_dbus_dict_close(&array, &dict);
2998 /* roaming counter */
2999 connman_dbus_dict_open(&array, &dict);
3001 stats_append_counters(&dict, &service->stats_roaming.data,
3002 &counters->stats_roaming.data, append_all);
3004 connman_dbus_dict_close(&array, &dict);
3006 __connman_counter_send_usage(counter, msg);
3009 static void stats_update(struct connman_service *service,
3010 unsigned int rx_packets, unsigned int tx_packets,
3011 unsigned int rx_bytes, unsigned int tx_bytes,
3012 unsigned int rx_errors, unsigned int tx_errors,
3013 unsigned int rx_dropped, unsigned int tx_dropped)
3015 struct connman_stats *stats = stats_get(service);
3016 struct connman_stats_data *data_last = &stats->data_last;
3017 struct connman_stats_data *data = &stats->data;
3018 unsigned int seconds;
3020 DBG("service %p", service);
3024 rx_packets - data_last->rx_packets;
3026 tx_packets - data_last->tx_packets;
3028 rx_bytes - data_last->rx_bytes;
3030 tx_bytes - data_last->tx_bytes;
3032 rx_errors - data_last->rx_errors;
3034 tx_errors - data_last->tx_errors;
3036 rx_dropped - data_last->rx_dropped;
3038 tx_dropped - data_last->tx_dropped;
3040 stats->valid = true;
3043 data_last->rx_packets = rx_packets;
3044 data_last->tx_packets = tx_packets;
3045 data_last->rx_bytes = rx_bytes;
3046 data_last->tx_bytes = tx_bytes;
3047 data_last->rx_errors = rx_errors;
3048 data_last->tx_errors = tx_errors;
3049 data_last->rx_dropped = rx_dropped;
3050 data_last->tx_dropped = tx_dropped;
3052 seconds = g_timer_elapsed(stats->timer, NULL);
3053 stats->data.time = stats->data_last.time + seconds;
3056 void __connman_service_notify(struct connman_service *service,
3057 unsigned int rx_packets, unsigned int tx_packets,
3058 unsigned int rx_bytes, unsigned int tx_bytes,
3059 unsigned int rx_errors, unsigned int tx_errors,
3060 unsigned int rx_dropped, unsigned int tx_dropped)
3062 GHashTableIter iter;
3063 gpointer key, value;
3064 const char *counter;
3065 struct connman_stats_counter *counters;
3066 struct connman_stats_data *data;
3072 if (!is_connected(service))
3075 stats_update(service,
3076 rx_packets, tx_packets,
3078 rx_errors, tx_errors,
3079 rx_dropped, tx_dropped);
3081 data = &stats_get(service)->data;
3082 err = __connman_stats_update(service, service->roaming, data);
3084 connman_error("Failed to store statistics for %s",
3085 service->identifier);
3087 g_hash_table_iter_init(&iter, service->counter_table);
3088 while (g_hash_table_iter_next(&iter, &key, &value)) {
3092 stats_append(service, counter, counters, counters->append_all);
3093 counters->append_all = false;
3097 int __connman_service_counter_register(const char *counter)
3099 struct connman_service *service;
3101 struct connman_stats_counter *counters;
3103 DBG("counter %s", counter);
3105 counter_list = g_slist_prepend(counter_list, (gpointer)counter);
3107 for (list = service_list; list; list = list->next) {
3108 service = list->data;
3110 counters = g_try_new0(struct connman_stats_counter, 1);
3114 counters->append_all = true;
3116 g_hash_table_replace(service->counter_table, (gpointer)counter,
3123 void __connman_service_counter_unregister(const char *counter)
3125 struct connman_service *service;
3128 DBG("counter %s", counter);
3130 for (list = service_list; list; list = list->next) {
3131 service = list->data;
3133 g_hash_table_remove(service->counter_table, counter);
3136 counter_list = g_slist_remove(counter_list, counter);
3139 int __connman_service_iterate_services(service_iterate_cb cb, void *user_data)
3143 for (list = service_list; list; list = list->next) {
3144 struct connman_service *service = list->data;
3146 cb(service, user_data);
3152 #if defined TIZEN_EXT
3153 static void append_wifi_ext_info(DBusMessageIter *dict,
3154 struct connman_network *network)
3156 char bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
3157 char *bssid_str = bssid_buff;
3159 unsigned int ssid_len;
3160 unsigned char *bssid;
3161 unsigned int maxrate;
3162 unsigned int keymgmt;
3164 const char *enc_mode;
3167 ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
3168 bssid = connman_network_get_bssid(network);
3169 maxrate = connman_network_get_maxrate(network);
3170 frequency = connman_network_get_frequency(network);
3171 enc_mode = connman_network_get_enc_mode(network);
3172 passpoint = connman_network_get_is_hs20AP(network);
3173 keymgmt = connman_network_get_keymgmt(network);
3175 snprintf(bssid_str, WIFI_BSSID_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
3176 bssid[0], bssid[1], bssid[2],
3177 bssid[3], bssid[4], bssid[5]);
3179 connman_dbus_dict_append_fixed_array(dict, "SSID",
3180 DBUS_TYPE_BYTE, &ssid, ssid_len);
3181 connman_dbus_dict_append_basic(dict, "BSSID",
3182 DBUS_TYPE_STRING, &bssid_str);
3183 connman_dbus_dict_append_basic(dict, "MaxRate",
3184 DBUS_TYPE_UINT32, &maxrate);
3185 connman_dbus_dict_append_basic(dict, "Frequency",
3186 DBUS_TYPE_UINT16, &frequency);
3187 connman_dbus_dict_append_basic(dict, "EncryptionMode",
3188 DBUS_TYPE_STRING, &enc_mode);
3189 connman_dbus_dict_append_basic(dict, "Passpoint",
3190 DBUS_TYPE_BOOLEAN, &passpoint);
3191 connman_dbus_dict_append_basic(dict, "Keymgmt",
3192 DBUS_TYPE_UINT32, &keymgmt);
3196 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
3197 struct connman_service *service)
3203 #if defined TIZEN_EXT
3204 unsigned int frequency = 0U;
3205 if (service && service->network) {
3206 frequency = connman_network_get_frequency(service->network);
3207 connman_dbus_dict_append_basic(dict, "Frequency",
3208 DBUS_TYPE_UINT16, &frequency);
3212 str = __connman_service_type2string(service->type);
3214 connman_dbus_dict_append_basic(dict, "Type",
3215 DBUS_TYPE_STRING, &str);
3217 connman_dbus_dict_append_array(dict, "Security",
3218 DBUS_TYPE_STRING, append_security, service);
3220 str = state2string(service->state);
3222 connman_dbus_dict_append_basic(dict, "State",
3223 DBUS_TYPE_STRING, &str);
3226 str = state2string(service->state_ipv6);
3228 connman_dbus_dict_append_basic(dict, "StateIPv6",
3229 DBUS_TYPE_STRING, &str);
3232 str = error2string(service->error);
3234 connman_dbus_dict_append_basic(dict, "Error",
3235 DBUS_TYPE_STRING, &str);
3237 if (service->strength > 0)
3238 connman_dbus_dict_append_basic(dict, "Strength",
3239 DBUS_TYPE_BYTE, &service->strength);
3241 val = service->favorite;
3242 connman_dbus_dict_append_basic(dict, "Favorite",
3243 DBUS_TYPE_BOOLEAN, &val);
3245 val = service->immutable;
3246 connman_dbus_dict_append_basic(dict, "Immutable",
3247 DBUS_TYPE_BOOLEAN, &val);
3249 if (service->favorite)
3250 val = service->autoconnect;
3252 val = service->favorite;
3254 connman_dbus_dict_append_basic(dict, "AutoConnect",
3255 DBUS_TYPE_BOOLEAN, &val);
3258 connman_dbus_dict_append_basic(dict, "Name",
3259 DBUS_TYPE_STRING, &service->name);
3261 switch (service->type) {
3262 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3263 case CONNMAN_SERVICE_TYPE_SYSTEM:
3264 case CONNMAN_SERVICE_TYPE_GPS:
3265 case CONNMAN_SERVICE_TYPE_VPN:
3266 case CONNMAN_SERVICE_TYPE_P2P:
3268 case CONNMAN_SERVICE_TYPE_CELLULAR:
3269 val = service->roaming;
3270 connman_dbus_dict_append_basic(dict, "Roaming",
3271 DBUS_TYPE_BOOLEAN, &val);
3273 connman_dbus_dict_append_dict(dict, "Ethernet",
3274 append_ethernet, service);
3276 case CONNMAN_SERVICE_TYPE_WIFI:
3277 #if defined TIZEN_EXT
3278 if (service->network != NULL)
3279 append_wifi_ext_info(dict, service->network);
3281 connman_dbus_dict_append_dict(dict, "Ethernet",
3282 append_ethernet, service);
3284 connman_dbus_dict_append_basic(dict, "DisconnectReason",
3285 DBUS_TYPE_INT32, &service->disconnect_reason);
3289 case CONNMAN_SERVICE_TYPE_ETHERNET:
3290 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3291 case CONNMAN_SERVICE_TYPE_GADGET:
3292 connman_dbus_dict_append_dict(dict, "Ethernet",
3293 append_ethernet, service);
3297 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
3299 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
3300 append_ipv4config, service);
3302 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
3304 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
3305 append_ipv6config, service);
3307 connman_dbus_dict_append_array(dict, "Nameservers",
3308 DBUS_TYPE_STRING, append_dns, service);
3310 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
3311 DBUS_TYPE_STRING, append_dnsconfig, service);
3313 if (service->state == CONNMAN_SERVICE_STATE_READY ||
3314 service->state == CONNMAN_SERVICE_STATE_ONLINE)
3315 list = __connman_timeserver_get_all(service);
3319 connman_dbus_dict_append_array(dict, "Timeservers",
3320 DBUS_TYPE_STRING, append_ts, list);
3322 g_slist_free_full(list, g_free);
3324 connman_dbus_dict_append_array(dict, "Timeservers.Configuration",
3325 DBUS_TYPE_STRING, append_tsconfig, service);
3327 connman_dbus_dict_append_array(dict, "Domains",
3328 DBUS_TYPE_STRING, append_domain, service);
3330 connman_dbus_dict_append_array(dict, "Domains.Configuration",
3331 DBUS_TYPE_STRING, append_domainconfig, service);
3333 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
3335 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
3336 append_proxyconfig, service);
3338 connman_dbus_dict_append_dict(dict, "Provider",
3339 append_provider, service);
3342 static void append_struct_service(DBusMessageIter *iter,
3343 connman_dbus_append_cb_t function,
3344 struct connman_service *service)
3346 DBusMessageIter entry, dict;
3348 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
3350 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
3353 connman_dbus_dict_open(&entry, &dict);
3355 function(&dict, service);
3356 connman_dbus_dict_close(&entry, &dict);
3358 dbus_message_iter_close_container(iter, &entry);
3361 static void append_dict_properties(DBusMessageIter *dict, void *user_data)
3363 struct connman_service *service = user_data;
3365 append_properties(dict, TRUE, service);
3368 static void append_struct(gpointer value, gpointer user_data)
3370 struct connman_service *service = value;
3371 DBusMessageIter *iter = user_data;
3376 append_struct_service(iter, append_dict_properties, service);
3379 void __connman_service_list_struct(DBusMessageIter *iter)
3381 g_list_foreach(service_list, append_struct, iter);
3384 bool __connman_service_is_hidden(struct connman_service *service)
3386 return service->hidden;
3390 __connman_service_is_split_routing(struct connman_service *service)
3392 return service->do_split_routing;
3395 bool __connman_service_index_is_split_routing(int index)
3397 struct connman_service *service;
3402 service = __connman_service_lookup_from_index(index);
3406 return __connman_service_is_split_routing(service);
3409 int __connman_service_get_index(struct connman_service *service)
3414 if (service->network)
3415 return connman_network_get_index(service->network);
3416 else if (service->provider)
3417 return connman_provider_get_index(service->provider);
3422 void __connman_service_set_hidden(struct connman_service *service)
3424 if (!service || service->hidden)
3427 service->hidden_service = true;
3430 void __connman_service_set_hostname(struct connman_service *service,
3431 const char *hostname)
3433 if (!service || service->hidden)
3436 g_free(service->hostname);
3437 service->hostname = g_strdup(hostname);
3440 const char *__connman_service_get_hostname(struct connman_service *service)
3445 return service->hostname;
3448 void __connman_service_set_domainname(struct connman_service *service,
3449 const char *domainname)
3451 if (!service || service->hidden)
3454 g_free(service->domainname);
3455 service->domainname = g_strdup(domainname);
3457 domain_changed(service);
3460 const char *connman_service_get_domainname(struct connman_service *service)
3465 if (service->domains)
3466 return service->domains[0];
3468 return service->domainname;
3471 char **connman_service_get_nameservers(struct connman_service *service)
3476 if (service->nameservers_config)
3477 return g_strdupv(service->nameservers_config);
3478 else if (service->nameservers ||
3479 service->nameservers_auto) {
3480 int len = 0, len_auto = 0, i;
3483 if (service->nameservers)
3484 len = g_strv_length(service->nameservers);
3485 if (service->nameservers_auto)
3486 len_auto = g_strv_length(service->nameservers_auto);
3488 nameservers = g_try_new0(char *, len + len_auto + 1);
3492 for (i = 0; i < len; i++)
3493 nameservers[i] = g_strdup(service->nameservers[i]);
3495 for (i = 0; i < len_auto; i++)
3496 nameservers[i + len] =
3497 g_strdup(service->nameservers_auto[i]);
3502 return g_strdupv(connman_setting_get_string_list("FallbackNameservers"));
3505 char **connman_service_get_timeservers_config(struct connman_service *service)
3510 return service->timeservers_config;
3513 char **connman_service_get_timeservers(struct connman_service *service)
3518 return service->timeservers;
3521 #if defined TIZEN_EXT
3523 * Description: Telephony plug-in requires manual PROXY setting function
3525 int connman_service_set_proxy(struct connman_service *service,
3526 const char *proxy, gboolean active)
3528 char **proxies_array = NULL;
3530 if (service == NULL)
3533 switch (service->type) {
3534 case CONNMAN_SERVICE_TYPE_CELLULAR:
3535 case CONNMAN_SERVICE_TYPE_ETHERNET:
3536 case CONNMAN_SERVICE_TYPE_WIFI:
3543 g_strfreev(service->proxies);
3544 service->proxies = NULL;
3547 proxies_array = g_strsplit(proxy, " ", 0);
3549 service->proxies = proxies_array;
3551 if (proxy == NULL) {
3552 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
3553 DBG("proxy changed (%d)", active);
3555 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
3556 DBG("proxy chagned %s (%d)", proxy, active);
3559 if (active == TRUE) {
3560 proxy_changed(service);
3562 __connman_notifier_proxy_changed(service);
3569 void connman_service_set_proxy_method(struct connman_service *service,
3570 enum connman_service_proxy_method method)
3572 if (!service || service->hidden)
3575 service->proxy = method;
3577 proxy_changed(service);
3579 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
3580 __connman_notifier_proxy_changed(service);
3583 enum connman_service_proxy_method connman_service_get_proxy_method(
3584 struct connman_service *service)
3587 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
3589 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
3590 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
3592 return service->proxy;
3594 return service->proxy_config;
3597 return service->proxy;
3600 char **connman_service_get_proxy_servers(struct connman_service *service)
3602 return g_strdupv(service->proxies);
3605 char **connman_service_get_proxy_excludes(struct connman_service *service)
3607 return g_strdupv(service->excludes);
3610 const char *connman_service_get_proxy_url(struct connman_service *service)
3615 return service->pac;
3618 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
3621 if (!service || service->hidden)
3624 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
3626 if (service->ipconfig_ipv4) {
3627 if (__connman_ipconfig_set_proxy_autoconfig(
3628 service->ipconfig_ipv4, url) < 0)
3630 } else if (service->ipconfig_ipv6) {
3631 if (__connman_ipconfig_set_proxy_autoconfig(
3632 service->ipconfig_ipv6, url) < 0)
3637 proxy_changed(service);
3639 __connman_notifier_proxy_changed(service);
3642 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
3647 if (service->ipconfig_ipv4)
3648 return __connman_ipconfig_get_proxy_autoconfig(
3649 service->ipconfig_ipv4);
3650 else if (service->ipconfig_ipv6)
3651 return __connman_ipconfig_get_proxy_autoconfig(
3652 service->ipconfig_ipv6);
3656 #if defined TIZEN_EXT
3657 int connman_service_get_ipv6_dns_method(struct connman_service *service)
3660 DBG("Service is NULL");
3664 return service->dns_config_method_ipv6;
3668 void __connman_service_set_timeservers(struct connman_service *service,
3676 g_strfreev(service->timeservers);
3677 service->timeservers = NULL;
3679 for (i = 0; timeservers && timeservers[i]; i++)
3680 __connman_service_timeserver_append(service, timeservers[i]);
3683 int __connman_service_timeserver_append(struct connman_service *service,
3684 const char *timeserver)
3688 DBG("service %p timeserver %s", service, timeserver);
3693 if (service->timeservers) {
3696 for (i = 0; service->timeservers[i]; i++)
3697 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
3700 len = g_strv_length(service->timeservers);
3701 service->timeservers = g_try_renew(char *, service->timeservers,
3705 service->timeservers = g_try_new0(char *, len + 2);
3708 if (!service->timeservers)
3711 service->timeservers[len] = g_strdup(timeserver);
3712 service->timeservers[len + 1] = NULL;
3717 int __connman_service_timeserver_remove(struct connman_service *service,
3718 const char *timeserver)
3721 int len, i, j, found = 0;
3723 DBG("service %p timeserver %s", service, timeserver);
3728 if (!service->timeservers)
3731 for (i = 0; service->timeservers &&
3732 service->timeservers[i]; i++)
3733 if (g_strcmp0(service->timeservers[i], timeserver) == 0) {
3741 len = g_strv_length(service->timeservers);
3744 g_strfreev(service->timeservers);
3745 service->timeservers = NULL;
3750 servers = g_try_new0(char *, len);
3754 for (i = 0, j = 0; i < len; i++) {
3755 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
3756 servers[j] = g_strdup(service->timeservers[i]);
3762 servers[len - 1] = NULL;
3764 g_strfreev(service->timeservers);
3765 service->timeservers = servers;
3770 void __connman_service_timeserver_changed(struct connman_service *service,
3776 if (!allow_property_changed(service))
3779 connman_dbus_property_changed_array(service->path,
3780 CONNMAN_SERVICE_INTERFACE, "Timeservers",
3781 DBUS_TYPE_STRING, append_ts, ts_list);
3784 void __connman_service_set_pac(struct connman_service *service,
3787 if (service->hidden)
3789 g_free(service->pac);
3790 service->pac = g_strdup(pac);
3792 proxy_changed(service);
3795 #if defined TIZEN_EXT
3796 void __connman_service_set_proxy(struct connman_service *service,
3797 const char *proxies)
3799 char **proxies_array = NULL;
3801 g_strfreev(service->proxies);
3802 service->proxies = NULL;
3804 if (proxies != NULL)
3805 proxies_array = g_strsplit(proxies, " ", 0);
3807 service->proxies = proxies_array;
3811 void __connman_service_set_identity(struct connman_service *service,
3812 const char *identity)
3814 if (service->immutable || service->hidden)
3817 g_free(service->identity);
3818 service->identity = g_strdup(identity);
3820 if (service->network)
3821 connman_network_set_string(service->network,
3826 void __connman_service_set_agent_identity(struct connman_service *service,
3827 const char *agent_identity)
3829 if (service->hidden)
3831 g_free(service->agent_identity);
3832 service->agent_identity = g_strdup(agent_identity);
3834 if (service->network)
3835 connman_network_set_string(service->network,
3836 "WiFi.AgentIdentity",
3837 service->agent_identity);
3840 static int check_passphrase(enum connman_service_security security,
3841 const char *passphrase)
3849 length = strlen(passphrase);
3852 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3853 case CONNMAN_SERVICE_SECURITY_NONE:
3854 case CONNMAN_SERVICE_SECURITY_WPA:
3855 #if !defined TIZEN_EXT
3856 case CONNMAN_SERVICE_SECURITY_RSN:
3859 DBG("service security '%s' (%d) not handled",
3860 security2string(security), security);
3864 case CONNMAN_SERVICE_SECURITY_PSK:
3865 #if defined TIZEN_EXT
3866 case CONNMAN_SERVICE_SECURITY_RSN:
3868 /* A raw key is always 64 bytes length,
3869 * its content is in hex representation.
3870 * A PSK key must be between [8..63].
3873 for (i = 0; i < 64; i++)
3874 if (!isxdigit((unsigned char)
3877 } else if (length < 8 || length > 63)
3880 case CONNMAN_SERVICE_SECURITY_WEP:
3881 /* length of WEP key is 10 or 26
3882 * length of WEP passphrase is 5 or 13
3884 if (length == 10 || length == 26) {
3885 for (i = 0; i < length; i++)
3886 if (!isxdigit((unsigned char)
3889 } else if (length != 5 && length != 13)
3893 case CONNMAN_SERVICE_SECURITY_8021X:
3900 int __connman_service_set_passphrase(struct connman_service *service,
3901 const char *passphrase)
3905 if (service->hidden)
3908 if (service->immutable &&
3909 service->security != CONNMAN_SERVICE_SECURITY_8021X)
3912 err = check_passphrase(service->security, passphrase);
3917 g_free(service->passphrase);
3918 service->passphrase = g_strdup(passphrase);
3920 if (service->network)
3921 connman_network_set_string(service->network, "WiFi.Passphrase",
3922 service->passphrase);
3927 const char *__connman_service_get_passphrase(struct connman_service *service)
3932 return service->passphrase;
3935 static DBusMessage *get_properties(DBusConnection *conn,
3936 DBusMessage *msg, void *user_data)
3938 struct connman_service *service = user_data;
3940 DBusMessageIter array, dict;
3942 DBG("service %p", service);
3944 reply = dbus_message_new_method_return(msg);
3948 dbus_message_iter_init_append(reply, &array);
3950 connman_dbus_dict_open(&array, &dict);
3951 append_properties(&dict, FALSE, service);
3952 connman_dbus_dict_close(&array, &dict);
3957 static int update_proxy_configuration(struct connman_service *service,
3958 DBusMessageIter *array)
3960 DBusMessageIter dict;
3961 enum connman_service_proxy_method method;
3962 GString *servers_str = NULL;
3963 GString *excludes_str = NULL;
3964 const char *url = NULL;
3966 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
3968 dbus_message_iter_recurse(array, &dict);
3970 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
3971 DBusMessageIter entry, variant;
3975 dbus_message_iter_recurse(&dict, &entry);
3977 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
3980 dbus_message_iter_get_basic(&entry, &key);
3981 dbus_message_iter_next(&entry);
3983 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
3986 dbus_message_iter_recurse(&entry, &variant);
3988 type = dbus_message_iter_get_arg_type(&variant);
3990 if (g_str_equal(key, "Method")) {
3993 if (type != DBUS_TYPE_STRING)
3996 dbus_message_iter_get_basic(&variant, &val);
3997 method = string2proxymethod(val);
3998 } else if (g_str_equal(key, "URL")) {
3999 if (type != DBUS_TYPE_STRING)
4002 dbus_message_iter_get_basic(&variant, &url);
4003 } else if (g_str_equal(key, "Servers")) {
4004 DBusMessageIter str_array;
4006 if (type != DBUS_TYPE_ARRAY)
4009 servers_str = g_string_new(NULL);
4013 dbus_message_iter_recurse(&variant, &str_array);
4015 while (dbus_message_iter_get_arg_type(&str_array) ==
4019 dbus_message_iter_get_basic(&str_array, &val);
4021 if (servers_str->len > 0)
4022 g_string_append_printf(servers_str,
4025 g_string_append(servers_str, val);
4027 dbus_message_iter_next(&str_array);
4029 } else if (g_str_equal(key, "Excludes")) {
4030 DBusMessageIter str_array;
4032 if (type != DBUS_TYPE_ARRAY)
4035 excludes_str = g_string_new(NULL);
4039 dbus_message_iter_recurse(&variant, &str_array);
4041 while (dbus_message_iter_get_arg_type(&str_array) ==
4045 dbus_message_iter_get_basic(&str_array, &val);
4047 if (excludes_str->len > 0)
4048 g_string_append_printf(excludes_str,
4051 g_string_append(excludes_str, val);
4053 dbus_message_iter_next(&str_array);
4057 dbus_message_iter_next(&dict);
4061 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
4063 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
4064 if (!servers_str && !service->proxies)
4068 g_strfreev(service->proxies);
4070 if (servers_str->len > 0)
4071 service->proxies = g_strsplit_set(
4072 servers_str->str, " ", 0);
4074 service->proxies = NULL;
4078 g_strfreev(service->excludes);
4080 if (excludes_str->len > 0)
4081 service->excludes = g_strsplit_set(
4082 excludes_str->str, " ", 0);
4084 service->excludes = NULL;
4087 if (!service->proxies)
4088 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
4091 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
4092 g_free(service->pac);
4094 if (url && strlen(url) > 0)
4095 service->pac = g_strdup(url);
4097 service->pac = NULL;
4099 /* if we are connected:
4100 - if service->pac == NULL
4101 - if __connman_ipconfig_get_proxy_autoconfig(
4102 service->ipconfig) == NULL
4103 --> We should start WPAD */
4106 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
4111 g_string_free(servers_str, TRUE);
4114 g_string_free(excludes_str, TRUE);
4116 service->proxy_config = method;
4122 g_string_free(servers_str, TRUE);
4125 g_string_free(excludes_str, TRUE);
4130 int __connman_service_reset_ipconfig(struct connman_service *service,
4131 enum connman_ipconfig_type type, DBusMessageIter *array,
4132 enum connman_service_state *new_state)
4134 struct connman_ipconfig *ipconfig, *new_ipconfig;
4135 enum connman_ipconfig_method old_method, new_method;
4136 enum connman_service_state state;
4139 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4140 ipconfig = service->ipconfig_ipv4;
4141 state = service->state_ipv4;
4142 new_method = CONNMAN_IPCONFIG_METHOD_DHCP;
4143 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4144 ipconfig = service->ipconfig_ipv6;
4145 state = service->state_ipv6;
4146 new_method = CONNMAN_IPCONFIG_METHOD_AUTO;
4153 old_method = __connman_ipconfig_get_method(ipconfig);
4154 index = __connman_ipconfig_get_index(ipconfig);
4156 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4157 new_ipconfig = create_ip4config(service, index,
4158 CONNMAN_IPCONFIG_METHOD_UNKNOWN);
4160 new_ipconfig = create_ip6config(service, index);
4163 err = __connman_ipconfig_set_config(new_ipconfig, array);
4165 __connman_ipconfig_unref(new_ipconfig);
4169 new_method = __connman_ipconfig_get_method(new_ipconfig);
4172 if (is_connecting_state(service, state) ||
4173 is_connected_state(service, state))
4174 __connman_network_clear_ipconfig(service->network, ipconfig);
4176 __connman_ipconfig_unref(ipconfig);
4178 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4179 service->ipconfig_ipv4 = new_ipconfig;
4180 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4181 service->ipconfig_ipv6 = new_ipconfig;
4183 if (is_connecting_state(service, state) ||
4184 is_connected_state(service, state))
4185 __connman_ipconfig_enable(new_ipconfig);
4187 if (new_state && new_method != old_method) {
4188 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4189 *new_state = service->state_ipv4;
4191 *new_state = service->state_ipv6;
4193 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4196 DBG("err %d ipconfig %p type %d method %d state %s", err,
4197 new_ipconfig, type, new_method,
4198 !new_state ? "-" : state2string(*new_state));
4203 static DBusMessage *set_property(DBusConnection *conn,
4204 DBusMessage *msg, void *user_data)
4206 struct connman_service *service = user_data;
4207 DBusMessageIter iter, value;
4211 DBG("service %p", service);
4213 if (!dbus_message_iter_init(msg, &iter))
4214 return __connman_error_invalid_arguments(msg);
4216 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
4217 return __connman_error_invalid_arguments(msg);
4219 if (service->type == CONNMAN_SERVICE_TYPE_WIFI && is_connected(service)) {
4221 if (connman_dbus_get_connection_unix_user_sync(conn,
4222 dbus_message_get_sender(msg),
4224 DBG("Can not get unix user id!");
4225 return __connman_error_permission_denied(msg);
4228 if (!connman_service_is_user_allowed(service, uid)) {
4229 DBG("Not allow this user to operate this wifi service now!");
4230 return __connman_error_permission_denied(msg);
4234 dbus_message_iter_get_basic(&iter, &name);
4235 dbus_message_iter_next(&iter);
4237 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
4238 return __connman_error_invalid_arguments(msg);
4240 dbus_message_iter_recurse(&iter, &value);
4242 type = dbus_message_iter_get_arg_type(&value);
4244 if (g_str_equal(name, "AutoConnect")) {
4245 dbus_bool_t autoconnect;
4247 if (type != DBUS_TYPE_BOOLEAN)
4248 return __connman_error_invalid_arguments(msg);
4250 if (!service->favorite)
4251 return __connman_error_invalid_service(msg);
4253 dbus_message_iter_get_basic(&value, &autoconnect);
4255 if (service->autoconnect == autoconnect)
4256 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4258 service->autoconnect = autoconnect;
4260 autoconnect_changed(service);
4263 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4265 service_save(service);
4266 } else if (g_str_equal(name, "Nameservers.Configuration")) {
4267 DBusMessageIter entry;
4271 #if defined TIZEN_EXT
4272 enum connman_ipconfig_type ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4276 if (__connman_provider_is_immutable(service->provider) ||
4278 return __connman_error_not_supported(msg);
4280 if (type != DBUS_TYPE_ARRAY)
4281 return __connman_error_invalid_arguments(msg);
4283 str = g_string_new(NULL);
4285 return __connman_error_invalid_arguments(msg);
4287 index = __connman_service_get_index(service);
4288 gw = __connman_ipconfig_get_gateway_from_index(index,
4289 CONNMAN_IPCONFIG_TYPE_ALL);
4291 if (gw && strlen(gw))
4292 __connman_service_nameserver_del_routes(service,
4293 CONNMAN_IPCONFIG_TYPE_ALL);
4295 dbus_message_iter_recurse(&value, &entry);
4297 #if defined TIZEN_EXT
4298 /* IPv4/IPv6 Last DNS config method */
4299 int last_dns_ipv4 = service->dns_config_method_ipv4;
4300 int last_dns_ipv6 = service->dns_config_method_ipv6;
4301 DBG("Last DNS Config Method IPv4: %d IPv6: %d", last_dns_ipv4, last_dns_ipv6);
4304 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4306 dbus_message_iter_get_basic(&entry, &val);
4307 dbus_message_iter_next(&entry);
4309 /* First unpack the DNS Config Method */
4310 DBG("DNS Config Method: %s", val);
4311 if((g_strcmp0(val, "ipv4.manual") == 0)) {
4312 service->dns_config_method_ipv4 =
4313 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4315 if(last_dns_ipv4 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4316 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4317 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4319 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4322 } else if(g_strcmp0(val, "ipv4.dhcp") == 0) {
4323 service->dns_config_method_ipv4 =
4324 CONNMAN_DNSCONFIG_METHOD_DHCP;
4325 if(last_dns_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4326 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4329 } else if(g_strcmp0(val, "ipv6.manual") == 0) {
4330 service->dns_config_method_ipv6 =
4331 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4332 if(last_dns_ipv6 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4333 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4334 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4336 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4339 } else if(g_strcmp0(val, "ipv6.dhcp") == 0) {
4340 service->dns_config_method_ipv6 =
4341 CONNMAN_DNSCONFIG_METHOD_DHCP;
4342 if(last_dns_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4343 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4348 if (connman_inet_check_ipaddress(val) > 0) {
4350 g_string_append_printf(str, " %s", val);
4352 g_string_append(str, val);
4356 #if defined TIZEN_EXT
4357 if (service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_DHCP &&
4358 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_DHCP) {
4359 DBG("Both IPv4 and IPv6 DNS Method DHCP");
4360 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4362 if (gw && strlen(gw))
4363 __connman_service_nameserver_del_routes(service,
4366 DBG("%s ip_type: %d nameserver remove all", name, ip_type);
4367 nameserver_remove_all(service, ip_type);
4369 nameserver_remove_all(service);
4371 g_strfreev(service->nameservers_config);
4374 service->nameservers_config =
4375 g_strsplit_set(str->str, " ", 0);
4377 service->nameservers_config = NULL;
4380 g_string_free(str, TRUE);
4382 if (gw && strlen(gw))
4383 __connman_service_nameserver_add_routes(service, gw);
4385 #if defined TIZEN_EXT
4386 DBG("%s ip_type: %d nameserver add all", name, ip_type);
4387 nameserver_add_all(service, ip_type);
4389 nameserver_add_all(service);
4391 dns_configuration_changed(service);
4393 if (__connman_service_is_connected_state(service,
4394 CONNMAN_IPCONFIG_TYPE_IPV4))
4395 __connman_wispr_start(service,
4396 CONNMAN_IPCONFIG_TYPE_IPV4);
4398 if (__connman_service_is_connected_state(service,
4399 CONNMAN_IPCONFIG_TYPE_IPV6))
4400 __connman_wispr_start(service,
4401 CONNMAN_IPCONFIG_TYPE_IPV6);
4403 service_save(service);
4404 } else if (g_str_equal(name, "Timeservers.Configuration")) {
4405 DBusMessageIter entry;
4406 GSList *list = NULL;
4409 if (service->immutable)
4410 return __connman_error_not_supported(msg);
4412 if (type != DBUS_TYPE_ARRAY)
4413 return __connman_error_invalid_arguments(msg);
4415 dbus_message_iter_recurse(&value, &entry);
4417 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4421 dbus_message_iter_get_basic(&entry, &val);
4423 new_head = __connman_timeserver_add_list(list, val);
4424 if (list != new_head) {
4429 dbus_message_iter_next(&entry);
4432 g_strfreev(service->timeservers_config);
4433 service->timeservers_config = NULL;
4436 service->timeservers_config = g_new0(char *, count+1);
4440 service->timeservers_config[count] = list->data;
4441 list = g_slist_delete_link(list, list);
4445 service_save(service);
4446 timeservers_configuration_changed(service);
4448 if (service == __connman_service_get_default())
4449 __connman_timeserver_sync(service);
4451 } else if (g_str_equal(name, "Domains.Configuration")) {
4452 DBusMessageIter entry;
4455 if (service->immutable)
4456 return __connman_error_not_supported(msg);
4458 if (type != DBUS_TYPE_ARRAY)
4459 return __connman_error_invalid_arguments(msg);
4461 str = g_string_new(NULL);
4463 return __connman_error_invalid_arguments(msg);
4465 dbus_message_iter_recurse(&value, &entry);
4467 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4469 dbus_message_iter_get_basic(&entry, &val);
4470 dbus_message_iter_next(&entry);
4472 g_string_append_printf(str, " %s", val);
4474 g_string_append(str, val);
4477 searchdomain_remove_all(service);
4478 g_strfreev(service->domains);
4481 service->domains = g_strsplit_set(str->str, " ", 0);
4483 service->domains = NULL;
4485 g_string_free(str, TRUE);
4487 searchdomain_add_all(service);
4488 domain_configuration_changed(service);
4489 domain_changed(service);
4491 service_save(service);
4492 } else if (g_str_equal(name, "Proxy.Configuration")) {
4495 if (service->immutable)
4496 return __connman_error_not_supported(msg);
4498 if (type != DBUS_TYPE_ARRAY)
4499 return __connman_error_invalid_arguments(msg);
4501 err = update_proxy_configuration(service, &value);
4504 return __connman_error_failed(msg, -err);
4506 proxy_configuration_changed(service);
4508 __connman_notifier_proxy_changed(service);
4510 service_save(service);
4511 } else if (g_str_equal(name, "IPv4.Configuration") ||
4512 g_str_equal(name, "IPv6.Configuration")) {
4514 enum connman_service_state state =
4515 CONNMAN_SERVICE_STATE_UNKNOWN;
4516 enum connman_ipconfig_type type =
4517 CONNMAN_IPCONFIG_TYPE_UNKNOWN;
4520 if (service->type == CONNMAN_SERVICE_TYPE_VPN ||
4522 return __connman_error_not_supported(msg);
4526 if (!service->ipconfig_ipv4 &&
4527 !service->ipconfig_ipv6)
4528 return __connman_error_invalid_property(msg);
4530 if (g_str_equal(name, "IPv4.Configuration"))
4531 type = CONNMAN_IPCONFIG_TYPE_IPV4;
4533 type = CONNMAN_IPCONFIG_TYPE_IPV6;
4535 err = __connman_service_reset_ipconfig(service, type, &value,
4539 if (is_connected_state(service, state) ||
4540 is_connecting_state(service, state)) {
4541 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4542 __connman_network_enable_ipconfig(service->network,
4543 service->ipconfig_ipv4);
4545 __connman_network_enable_ipconfig(service->network,
4546 service->ipconfig_ipv6);
4549 return __connman_error_failed(msg, -err);
4552 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4553 ipv4_configuration_changed(service);
4555 ipv6_configuration_changed(service);
4557 if (is_connecting(service) || is_connected(service)) {
4558 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4559 __connman_network_enable_ipconfig(service->network,
4560 service->ipconfig_ipv4);
4562 __connman_network_enable_ipconfig(service->network,
4563 service->ipconfig_ipv6);
4566 service_save(service);
4568 return __connman_error_invalid_property(msg);
4570 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4573 static void set_error(struct connman_service *service,
4574 enum connman_service_error error)
4578 if (service->error == error)
4581 service->error = error;
4586 #if !defined TIZEN_EXT
4587 if (!allow_property_changed(service))
4591 str = error2string(service->error);
4596 connman_dbus_property_changed_basic(service->path,
4597 CONNMAN_SERVICE_INTERFACE, "Error",
4598 DBUS_TYPE_STRING, &str);
4601 static void set_idle(struct connman_service *service)
4603 service->state = service->state_ipv4 = service->state_ipv6 =
4604 CONNMAN_SERVICE_STATE_IDLE;
4605 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4606 state_changed(service);
4609 static DBusMessage *clear_property(DBusConnection *conn,
4610 DBusMessage *msg, void *user_data)
4612 struct connman_service *service = user_data;
4615 DBG("service %p", service);
4617 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
4620 if (g_str_equal(name, "Error")) {
4621 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4623 g_get_current_time(&service->modified);
4624 service_save(service);
4626 return __connman_error_invalid_property(msg);
4628 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4631 static bool is_ipconfig_usable(struct connman_service *service)
4633 if (!__connman_ipconfig_is_usable(service->ipconfig_ipv4) &&
4634 !__connman_ipconfig_is_usable(service->ipconfig_ipv6))
4640 static bool is_ignore(struct connman_service *service)
4642 if (!service->autoconnect)
4645 if (service->roaming)
4648 if (service->ignore)
4651 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
4654 if (!is_ipconfig_usable(service))
4660 static void disconnect_on_last_session(enum connman_service_type type)
4664 for (list = service_list; list; list = list->next) {
4665 struct connman_service *service = list->data;
4667 if (service->type != type)
4670 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_SESSION)
4673 __connman_service_disconnect(service);
4678 static int active_sessions[MAX_CONNMAN_SERVICE_TYPES] = {};
4679 static int active_count = 0;
4681 void __connman_service_set_active_session(bool enable, GSList *list)
4691 while (list != NULL) {
4692 enum connman_service_type type = GPOINTER_TO_INT(list->data);
4695 case CONNMAN_SERVICE_TYPE_ETHERNET:
4696 case CONNMAN_SERVICE_TYPE_WIFI:
4697 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4698 case CONNMAN_SERVICE_TYPE_CELLULAR:
4699 case CONNMAN_SERVICE_TYPE_GADGET:
4701 active_sessions[type]++;
4703 active_sessions[type]--;
4706 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4707 case CONNMAN_SERVICE_TYPE_SYSTEM:
4708 case CONNMAN_SERVICE_TYPE_GPS:
4709 case CONNMAN_SERVICE_TYPE_VPN:
4710 case CONNMAN_SERVICE_TYPE_P2P:
4714 if (active_sessions[type] == 0)
4715 disconnect_on_last_session(type);
4717 list = g_slist_next(list);
4720 DBG("eth %d wifi %d bt %d cellular %d gadget %d sessions %d",
4721 active_sessions[CONNMAN_SERVICE_TYPE_ETHERNET],
4722 active_sessions[CONNMAN_SERVICE_TYPE_WIFI],
4723 active_sessions[CONNMAN_SERVICE_TYPE_BLUETOOTH],
4724 active_sessions[CONNMAN_SERVICE_TYPE_CELLULAR],
4725 active_sessions[CONNMAN_SERVICE_TYPE_GADGET],
4729 struct preferred_tech_data {
4730 GList *preferred_list;
4731 enum connman_service_type type;
4734 static void preferred_tech_add_by_type(gpointer data, gpointer user_data)
4736 struct connman_service *service = data;
4737 struct preferred_tech_data *tech_data = user_data;
4739 if (service->type == tech_data->type) {
4740 tech_data->preferred_list =
4741 g_list_append(tech_data->preferred_list, service);
4743 DBG("type %d service %p %s", tech_data->type, service,
4748 static GList *preferred_tech_list_get(void)
4750 unsigned int *tech_array;
4751 struct preferred_tech_data tech_data = { 0, };
4754 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
4758 if (connman_setting_get_bool("SingleConnectedTechnology")) {
4760 for (list = service_list; list; list = list->next) {
4761 struct connman_service *service = list->data;
4763 if (!is_connected(service))
4766 if (service->connect_reason ==
4767 CONNMAN_SERVICE_CONNECT_REASON_USER) {
4768 DBG("service %p name %s is user connected",
4769 service, service->name);
4770 #if defined TIZEN_EXT
4771 /* We can connect to a favorite service like
4772 * wifi even we have a userconnect for cellular
4773 * because we have refount for cellular service
4775 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
4778 if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
4786 for (i = 0; tech_array[i] != 0; i += 1) {
4787 tech_data.type = tech_array[i];
4788 g_list_foreach(service_list, preferred_tech_add_by_type,
4792 return tech_data.preferred_list;
4795 static bool auto_connect_service(GList *services,
4796 enum connman_service_connect_reason reason,
4799 struct connman_service *service = NULL;
4800 bool ignore[MAX_CONNMAN_SERVICE_TYPES] = { };
4801 bool autoconnecting = false;
4804 DBG("preferred %d sessions %d reason %s", preferred, active_count,
4805 reason2string(reason));
4807 ignore[CONNMAN_SERVICE_TYPE_VPN] = true;
4809 for (list = services; list; list = list->next) {
4810 service = list->data;
4812 if (ignore[service->type]) {
4813 DBG("service %p type %s ignore", service,
4814 __connman_service_type2string(service->type));
4818 #if defined TIZEN_EXT
4819 DBG("service %p %s %s %s, favorite(%d), ignore(%d), hidden(%d, %d)",
4820 service, service->name,
4821 state2string(service->state),
4822 __connman_service_type2string(service->type),
4823 service->favorite, is_ignore(service),
4824 service->hidden, service->hidden_service);
4826 /* Tizen takes Wi-Fi as the highest priority into consideration. */
4827 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
4828 if (is_connecting(service) == TRUE || is_connected(service) == TRUE)
4832 if (service->pending ||
4833 is_connecting(service) ||
4834 is_connected(service)) {
4838 ignore[service->type] = true;
4839 autoconnecting = true;
4841 DBG("service %p type %s busy", service,
4842 __connman_service_type2string(service->type));
4847 if (!service->favorite) {
4851 #if defined TIZEN_EXT
4852 DBG("Service is not favorite, autoconnecting %d",
4855 return autoconnecting;
4858 #if defined TIZEN_EXT
4859 DBG("service %p identifier %s roaming %d ignore %d "
4860 "ipconfig_usable %d autoconnect %d state %d",
4862 service->identifier, service->roaming,
4863 service->ignore, is_ipconfig_usable(service),
4864 service->autoconnect, service->state);
4866 if (is_ignore(service) || service->state !=
4867 CONNMAN_SERVICE_STATE_IDLE)
4870 if (autoconnecting && !active_sessions[service->type]) {
4871 DBG("service %p type %s has no users", service,
4872 __connman_service_type2string(service->type));
4876 if (!is_service_owner_user_login(service)) {
4877 DBG("favorite user not login, wifi auto connect denied");
4881 DBG("service %p %s %s", service, service->name,
4882 (preferred) ? "preferred" : reason2string(reason));
4884 __connman_service_connect(service, reason);
4889 ignore[service->type] = true;
4892 return autoconnecting;
4895 static gboolean run_auto_connect(gpointer data)
4897 enum connman_service_connect_reason reason = GPOINTER_TO_UINT(data);
4898 bool autoconnecting = false;
4899 GList *preferred_tech;
4901 autoconnect_timeout = 0;
4905 preferred_tech = preferred_tech_list_get();
4906 if (preferred_tech) {
4907 autoconnecting = auto_connect_service(preferred_tech, reason,
4909 g_list_free(preferred_tech);
4912 if (!autoconnecting || active_count)
4913 auto_connect_service(service_list, reason, false);
4918 void __connman_service_auto_connect(enum connman_service_connect_reason reason)
4922 if (autoconnect_timeout != 0)
4925 if (!__connman_session_policy_autoconnect(reason))
4928 #if defined TIZEN_EXT
4929 /* Adding Timeout of 500ms before trying to auto connect.
4930 * This is done because of below scenario
4931 * 1. Device is connected to AP1
4932 * 2. WPS Connection request is initiated for AP2
4933 * 3. Immediately WPS Connection is Cancelled
4934 * When WPS Connection Connection is initiated for AP2 then
4935 * sometimes there is a scenario where connman gets in ASSOCIATED
4936 * state with AP1 due to autoconnect and subsequently the connection
4937 * initiated by AP1 fails and connman service for AP1 comes in
4938 * FAILURE state due to this when connection with AP2 is cancelled
4939 * then autoconnect with AP1 doesn't works because its autoconnection
4940 * is ignored as its last state was FAILURE rather than IDLE */
4941 autoconnect_timeout = g_timeout_add(500, run_auto_connect,
4943 autoconnect_timeout = g_timeout_add_seconds(0, run_auto_connect,
4945 GUINT_TO_POINTER(reason));
4948 static gboolean run_vpn_auto_connect(gpointer data) {
4950 bool need_split = false;
4952 vpn_autoconnect_timeout = 0;
4954 for (list = service_list; list; list = list->next) {
4955 struct connman_service *service = list->data;
4958 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
4961 if (is_connected(service) || is_connecting(service)) {
4962 if (!service->do_split_routing)
4967 if (is_ignore(service) || !service->favorite)
4970 if (need_split && !service->do_split_routing) {
4971 DBG("service %p no split routing", service);
4975 DBG("service %p %s %s", service, service->name,
4976 service->do_split_routing ?
4977 "split routing" : "");
4979 res = __connman_service_connect(service,
4980 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4981 if (res < 0 && res != -EINPROGRESS)
4984 if (!service->do_split_routing)
4991 static void vpn_auto_connect(void)
4993 if (vpn_autoconnect_timeout)
4996 vpn_autoconnect_timeout =
4997 g_timeout_add_seconds(0, run_vpn_auto_connect, NULL);
5000 static void remove_timeout(struct connman_service *service)
5002 if (service->timeout > 0) {
5003 g_source_remove(service->timeout);
5004 service->timeout = 0;
5008 static void reply_pending(struct connman_service *service, int error)
5010 remove_timeout(service);
5012 if (service->pending) {
5013 connman_dbus_reply_pending(service->pending, error, NULL);
5014 service->pending = NULL;
5017 if (service->provider_pending) {
5018 connman_dbus_reply_pending(service->provider_pending,
5019 error, service->path);
5020 service->provider_pending = NULL;
5025 __connman_service_is_provider_pending(struct connman_service *service)
5030 if (service->provider_pending)
5036 void __connman_service_set_provider_pending(struct connman_service *service,
5039 if (service->provider_pending) {
5040 DBG("service %p provider pending msg %p already exists",
5041 service, service->provider_pending);
5045 service->provider_pending = msg;
5049 static void check_pending_msg(struct connman_service *service)
5051 if (!service->pending)
5054 DBG("service %p pending msg %p already exists", service,
5056 dbus_message_unref(service->pending);
5059 void __connman_service_set_hidden_data(struct connman_service *service,
5062 DBusMessage *pending = user_data;
5064 DBG("service %p pending %p", service, pending);
5069 check_pending_msg(service);
5071 service->pending = pending;
5074 void __connman_service_return_error(struct connman_service *service,
5075 int error, gpointer user_data)
5077 DBG("service %p error %d user_data %p", service, error, user_data);
5079 __connman_service_set_hidden_data(service, user_data);
5081 reply_pending(service, error);
5084 static gboolean connect_timeout(gpointer user_data)
5086 struct connman_service *service = user_data;
5087 bool autoconnect = false;
5089 DBG("service %p", service);
5091 service->timeout = 0;
5093 if (service->network)
5094 __connman_network_disconnect(service->network);
5095 else if (service->provider)
5096 connman_provider_disconnect(service->provider);
5098 __connman_ipconfig_disable(service->ipconfig_ipv4);
5099 __connman_ipconfig_disable(service->ipconfig_ipv6);
5101 __connman_stats_service_unregister(service);
5103 if (service->pending) {
5106 reply = __connman_error_operation_timeout(service->pending);
5108 g_dbus_send_message(connection, reply);
5110 dbus_message_unref(service->pending);
5111 service->pending = NULL;
5115 __connman_service_ipconfig_indicate_state(service,
5116 CONNMAN_SERVICE_STATE_FAILURE,
5117 CONNMAN_IPCONFIG_TYPE_IPV4);
5118 __connman_service_ipconfig_indicate_state(service,
5119 CONNMAN_SERVICE_STATE_FAILURE,
5120 CONNMAN_IPCONFIG_TYPE_IPV6);
5123 service->connect_reason !=
5124 CONNMAN_SERVICE_CONNECT_REASON_USER)
5125 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5130 static DBusMessage *connect_service(DBusConnection *conn,
5131 DBusMessage *msg, void *user_data)
5133 struct connman_service *service = user_data;
5134 #if defined TIZEN_EXT
5141 DBG("service %p", service);
5143 #if defined TIZEN_EXT
5145 * Description: TIZEN implements system global connection management.
5147 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5148 connman_service_user_pdn_connection_ref(service);
5151 if (service->pending)
5152 return __connman_error_in_progress(msg);
5154 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5156 if (connman_dbus_get_connection_unix_user_sync(conn,
5157 dbus_message_get_sender(msg),
5159 DBG("Can not get unix user id!");
5160 return __connman_error_permission_denied(msg);
5163 if (!__connman_service_is_user_allowed(CONNMAN_SERVICE_TYPE_WIFI, uid)) {
5164 DBG("Not allow this user to connect this wifi service now!");
5165 return __connman_error_permission_denied(msg);
5168 if (uid != USER_ROOT && uid != service->user.favorite_user)
5169 service->request_passphrase_input = true;
5171 service->user.current_user = uid;
5173 if (!service->passphrase && uid == service->user.favorite_user) {
5174 DBG("Now load this favorite user's passphrase.");
5175 service_load_passphrase(service);
5179 #if !defined TIZEN_EXT
5180 index = __connman_service_get_index(service);
5182 for (list = service_list; list; list = list->next) {
5183 struct connman_service *temp = list->data;
5185 #if defined TIZEN_EXT
5186 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5189 if (!is_connecting(temp) && !is_connected(temp))
5192 if (service == temp)
5195 if (service->type != temp->type)
5198 if (__connman_service_get_index(temp) == index &&
5199 __connman_service_disconnect(temp) == -EINPROGRESS)
5203 if (err == -EINPROGRESS)
5204 return __connman_error_operation_timeout(msg);
5207 service->ignore = false;
5209 service->pending = dbus_message_ref(msg);
5211 err = __connman_service_connect(service,
5212 CONNMAN_SERVICE_CONNECT_REASON_USER);
5214 if (err == -EINPROGRESS)
5217 if (service->pending) {
5218 dbus_message_unref(service->pending);
5219 service->pending = NULL;
5223 return __connman_error_failed(msg, -err);
5225 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5228 static DBusMessage *disconnect_service(DBusConnection *conn,
5229 DBusMessage *msg, void *user_data)
5231 struct connman_service *service = user_data;
5234 DBG("service %p", service);
5236 #if defined TIZEN_EXT
5238 * Description: TIZEN implements system global connection management.
5240 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
5241 if (connman_service_user_pdn_connection_unref_and_test(service) != TRUE)
5242 return __connman_error_failed(msg, EISCONN);
5244 if (is_connected(service) == TRUE &&
5245 service == connman_service_get_default_connection())
5246 return __connman_error_failed(msg, EISCONN);
5250 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5252 if (connman_dbus_get_connection_unix_user_sync(conn,
5253 dbus_message_get_sender(msg),
5255 DBG("Can not get unix user id!");
5256 return __connman_error_permission_denied(msg);
5259 if (!connman_service_is_user_allowed(service, uid)) {
5260 DBG("Not allow this user to disconnect this wifi service now!");
5261 return __connman_error_permission_denied(msg);
5265 service->ignore = true;
5267 err = __connman_service_disconnect(service);
5268 if (err < 0 && err != -EINPROGRESS)
5269 return __connman_error_failed(msg, -err);
5271 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5274 #if defined TIZEN_EXT
5275 static void __connman_service_cleanup_network_8021x(struct connman_service *service)
5277 if (service == NULL)
5280 DBG("service %p ", service);
5282 connman_network_set_string(service->network, "WiFi.EAP", NULL);
5283 connman_network_set_string(service->network, "WiFi.Identity", NULL);
5284 connman_network_set_string(service->network, "WiFi.CACertFile", NULL);
5285 connman_network_set_string(service->network, "WiFi.ClientCertFile", NULL);
5286 connman_network_set_string(service->network, "WiFi.PrivateKeyFile", NULL);
5287 connman_network_set_string(service->network, "WiFi.PrivateKeyPassphrase", NULL);
5288 connman_network_set_string(service->network, "WiFi.Phase2", NULL);
5292 bool __connman_service_remove(struct connman_service *service)
5294 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET ||
5295 service->type == CONNMAN_SERVICE_TYPE_GADGET)
5298 if (service->immutable || service->hidden ||
5299 __connman_provider_is_immutable(service->provider))
5302 #if !defined TIZEN_EXT
5303 if (!service->favorite && service->state !=
5304 CONNMAN_SERVICE_STATE_FAILURE)
5308 __connman_service_disconnect(service);
5310 g_free(service->passphrase);
5311 service->passphrase = NULL;
5313 g_free(service->identity);
5314 service->identity = NULL;
5316 g_free(service->agent_identity);
5317 service->agent_identity = NULL;
5319 g_free(service->eap);
5320 service->eap = NULL;
5322 #if defined TIZEN_EXT
5323 g_free(service->ca_cert_file);
5324 service->ca_cert_file = NULL;
5326 g_free(service->client_cert_file);
5327 service->client_cert_file = NULL;
5329 g_free(service->private_key_file);
5330 service->private_key_file = NULL;
5332 g_free(service->private_key_passphrase);
5333 service->private_key_passphrase = NULL;
5335 g_free(service->phase2);
5336 service->phase2 = NULL;
5338 __connman_service_cleanup_network_8021x(service);
5340 __connman_ipconfig_set_method(service->ipconfig_ipv4, CONNMAN_IPCONFIG_METHOD_DHCP);
5341 __connman_ipconfig_set_method(service->ipconfig_ipv6, CONNMAN_IPCONFIG_METHOD_AUTO);
5342 connman_service_set_proxy(service, NULL, false);
5344 __connman_service_nameserver_clear(service);
5346 g_strfreev(service->nameservers_config);
5347 service->nameservers_config = NULL;
5351 #if defined TIZEN_EXT
5352 if (service->security != CONNMAN_SERVICE_SECURITY_8021X)
5356 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
5358 service->user.favorite_user = USER_NONE;
5360 __connman_service_set_favorite(service, false);
5362 __connman_ipconfig_ipv6_reset_privacy(service->ipconfig_ipv6);
5364 #if defined TIZEN_EXT
5365 /* Reset IP Method and DNS Method to DHCP */
5366 __connman_ipconfig_set_method(service->ipconfig_ipv4,
5367 CONNMAN_IPCONFIG_METHOD_DHCP);
5368 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
5369 g_strfreev(service->nameservers_config);
5370 service->nameservers_config = NULL;
5373 #if defined TIZEN_EXT
5374 __connman_storage_remove_service(service->identifier);
5376 service_save(service);
5382 static DBusMessage *remove_service(DBusConnection *conn,
5383 DBusMessage *msg, void *user_data)
5385 struct connman_service *service = user_data;
5387 DBG("service %p", service);
5389 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5391 if (connman_dbus_get_connection_unix_user_sync(conn,
5392 dbus_message_get_sender(msg),
5394 DBG("Can not get unix user id!");
5395 return __connman_error_permission_denied(msg);
5398 #if !defined TIZEN_EXT
5399 if (!connman_service_is_user_allowed(service, uid)) {
5400 DBG("Not allow this user to remove this wifi service now!");
5401 return __connman_error_permission_denied(msg);
5406 if (!__connman_service_remove(service))
5407 return __connman_error_not_supported(msg);
5409 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5412 static bool check_suitable_state(enum connman_service_state a,
5413 enum connman_service_state b)
5416 * Special check so that "ready" service can be moved before
5419 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
5420 b == CONNMAN_SERVICE_STATE_READY) ||
5421 (b == CONNMAN_SERVICE_STATE_ONLINE &&
5422 a == CONNMAN_SERVICE_STATE_READY))
5428 static void downgrade_state(struct connman_service *service)
5433 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
5434 service->state_ipv6);
5436 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
5437 __connman_service_ipconfig_indicate_state(service,
5438 CONNMAN_SERVICE_STATE_READY,
5439 CONNMAN_IPCONFIG_TYPE_IPV4);
5441 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
5442 __connman_service_ipconfig_indicate_state(service,
5443 CONNMAN_SERVICE_STATE_READY,
5444 CONNMAN_IPCONFIG_TYPE_IPV6);
5447 static void apply_relevant_default_downgrade(struct connman_service *service)
5449 struct connman_service *def_service;
5451 def_service = __connman_service_get_default();
5455 if (def_service == service &&
5456 def_service->state == CONNMAN_SERVICE_STATE_ONLINE) {
5457 def_service->state = CONNMAN_SERVICE_STATE_READY;
5458 __connman_notifier_leave_online(def_service->type);
5459 state_changed(def_service);
5463 static void switch_default_service(struct connman_service *default_service,
5464 struct connman_service *downgrade_service)
5466 struct connman_service *service;
5469 apply_relevant_default_downgrade(default_service);
5470 src = g_list_find(service_list, downgrade_service);
5471 dst = g_list_find(service_list, default_service);
5474 if (src == dst || src->next == dst)
5477 service = src->data;
5478 service_list = g_list_delete_link(service_list, src);
5479 service_list = g_list_insert_before(service_list, dst, service);
5481 downgrade_state(downgrade_service);
5484 static DBusMessage *move_service(DBusConnection *conn,
5485 DBusMessage *msg, void *user_data,
5488 struct connman_service *service = user_data;
5489 struct connman_service *target;
5491 enum connman_ipconfig_method target4, target6;
5492 enum connman_ipconfig_method service4, service6;
5494 DBG("service %p", service);
5496 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
5499 if (!service->favorite)
5500 return __connman_error_not_supported(msg);
5502 target = find_service(path);
5503 if (!target || !target->favorite || target == service)
5504 return __connman_error_invalid_service(msg);
5506 if (target->type == CONNMAN_SERVICE_TYPE_VPN) {
5508 * We only allow VPN route splitting if there are
5509 * routes defined for a given VPN.
5511 if (!__connman_provider_check_routes(target->provider)) {
5512 connman_info("Cannot move service. "
5513 "No routes defined for provider %s",
5514 __connman_provider_get_ident(target->provider));
5515 return __connman_error_invalid_service(msg);
5518 target->do_split_routing = true;
5520 target->do_split_routing = false;
5522 service->do_split_routing = false;
5524 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
5525 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
5526 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
5527 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
5529 DBG("target %s method %d/%d state %d/%d split %d", target->identifier,
5530 target4, target6, target->state_ipv4, target->state_ipv6,
5531 target->do_split_routing);
5533 DBG("service %s method %d/%d state %d/%d", service->identifier,
5535 service->state_ipv4, service->state_ipv6);
5538 * If method is OFF, then we do not need to check the corresponding
5541 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5542 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5543 if (!check_suitable_state(target->state_ipv6,
5544 service->state_ipv6))
5545 return __connman_error_invalid_service(msg);
5549 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5550 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5551 if (!check_suitable_state(target->state_ipv4,
5552 service->state_ipv4))
5553 return __connman_error_invalid_service(msg);
5557 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5558 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5559 if (!check_suitable_state(target->state_ipv6,
5560 service->state_ipv6))
5561 return __connman_error_invalid_service(msg);
5565 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5566 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5567 if (!check_suitable_state(target->state_ipv4,
5568 service->state_ipv4))
5569 return __connman_error_invalid_service(msg);
5573 g_get_current_time(&service->modified);
5574 service_save(service);
5575 service_save(target);
5578 * If the service which goes down is the default service and is
5579 * online, we downgrade directly its state to ready so:
5580 * the service which goes up, needs to recompute its state which
5581 * is triggered via downgrading it - if relevant - to state ready.
5584 switch_default_service(target, service);
5586 switch_default_service(service, target);
5588 __connman_connection_update_gateway();
5590 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5593 static DBusMessage *move_before(DBusConnection *conn,
5594 DBusMessage *msg, void *user_data)
5596 return move_service(conn, msg, user_data, true);
5599 static DBusMessage *move_after(DBusConnection *conn,
5600 DBusMessage *msg, void *user_data)
5602 return move_service(conn, msg, user_data, false);
5605 static DBusMessage *reset_counters(DBusConnection *conn,
5606 DBusMessage *msg, void *user_data)
5608 struct connman_service *service = user_data;
5610 reset_stats(service);
5612 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5615 static DBusMessage *get_user_favorite(DBusConnection *conn,
5616 DBusMessage *msg, void *user_data)
5619 uid_t uid = USER_NONE;
5620 dbus_bool_t user_favorite = false;
5621 struct connman_service *service = user_data;
5623 connman_dbus_get_connection_unix_user_sync(conn,
5624 dbus_message_get_sender(msg),
5626 if (uid == USER_ROOT)
5627 user_favorite = service->favorite;
5628 else if (uid != USER_NONE && uid == service->user.favorite_user) {
5629 DBG("The service is favorite to this user!");
5630 user_favorite = true;
5633 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5634 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN,
5635 &user_favorite, DBUS_TYPE_INVALID);
5639 static struct _services_notify {
5645 static void service_append_added_foreach(gpointer data, gpointer user_data)
5647 struct connman_service *service = data;
5648 DBusMessageIter *iter = user_data;
5650 if (!service || !service->path) {
5651 #if !defined TIZEN_EXT
5652 DBG("service %p or path is NULL", service);
5657 if (g_hash_table_lookup(services_notify->add, service->path)) {
5658 #if !defined TIZEN_EXT
5659 DBG("new %s", service->path);
5662 append_struct(service, iter);
5663 g_hash_table_remove(services_notify->add, service->path);
5665 #if !defined TIZEN_EXT
5666 DBG("changed %s", service->path);
5669 append_struct_service(iter, NULL, service);
5673 static void service_append_ordered(DBusMessageIter *iter, void *user_data)
5675 g_list_foreach(service_list, service_append_added_foreach, iter);
5678 static void append_removed(gpointer key, gpointer value, gpointer user_data)
5680 char *objpath = key;
5681 DBusMessageIter *iter = user_data;
5683 DBG("removed %s", objpath);
5684 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath);
5687 static void service_append_removed(DBusMessageIter *iter, void *user_data)
5689 g_hash_table_foreach(services_notify->remove, append_removed, iter);
5692 static gboolean service_send_changed(gpointer data)
5694 DBusMessage *signal;
5698 services_notify->id = 0;
5700 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
5701 CONNMAN_MANAGER_INTERFACE, "ServicesChanged");
5705 __connman_dbus_append_objpath_dict_array(signal,
5706 service_append_ordered, NULL);
5707 __connman_dbus_append_objpath_array(signal,
5708 service_append_removed, NULL);
5710 dbus_connection_send(connection, signal, NULL);
5711 dbus_message_unref(signal);
5713 g_hash_table_remove_all(services_notify->remove);
5714 g_hash_table_remove_all(services_notify->add);
5719 static void service_schedule_changed(void)
5721 if (services_notify->id != 0)
5724 services_notify->id = g_timeout_add(100, service_send_changed, NULL);
5727 static void service_schedule_added(struct connman_service *service)
5729 DBG("service %p", service);
5731 g_hash_table_remove(services_notify->remove, service->path);
5732 g_hash_table_replace(services_notify->add, service->path, service);
5734 service_schedule_changed();
5737 static void service_schedule_removed(struct connman_service *service)
5739 if (!service || !service->path) {
5740 DBG("service %p or path is NULL", service);
5744 DBG("service %p %s", service, service->path);
5746 g_hash_table_remove(services_notify->add, service->path);
5747 g_hash_table_replace(services_notify->remove, g_strdup(service->path),
5750 service_schedule_changed();
5753 static bool allow_property_changed(struct connman_service *service)
5755 #if defined TIZEN_EXT
5756 if (service->path == NULL)
5759 if (g_hash_table_lookup_extended(services_notify->add, service->path,
5761 DBG("no property updates for service %p", service);
5768 static const GDBusMethodTable service_methods[] = {
5769 { GDBUS_DEPRECATED_METHOD("GetProperties",
5770 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
5772 { GDBUS_METHOD("SetProperty",
5773 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
5774 NULL, set_property) },
5775 { GDBUS_METHOD("ClearProperty",
5776 GDBUS_ARGS({ "name", "s" }), NULL,
5778 { GDBUS_ASYNC_METHOD("Connect", NULL, NULL,
5780 { GDBUS_METHOD("Disconnect", NULL, NULL,
5781 disconnect_service) },
5782 { GDBUS_METHOD("Remove", NULL, NULL, remove_service) },
5783 { GDBUS_METHOD("MoveBefore",
5784 GDBUS_ARGS({ "service", "o" }), NULL,
5786 { GDBUS_METHOD("MoveAfter",
5787 GDBUS_ARGS({ "service", "o" }), NULL,
5789 { GDBUS_METHOD("ResetCounters", NULL, NULL, reset_counters) },
5790 { GDBUS_METHOD("GetUserFavorite",
5791 NULL, GDBUS_ARGS({ "value", "v" }),
5792 get_user_favorite) },
5796 static const GDBusSignalTable service_signals[] = {
5797 { GDBUS_SIGNAL("PropertyChanged",
5798 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
5802 static void service_free(gpointer user_data)
5804 struct connman_service *service = user_data;
5805 char *path = service->path;
5807 DBG("service %p", service);
5809 reply_pending(service, ENOENT);
5811 __connman_notifier_service_remove(service);
5812 service_schedule_removed(service);
5814 __connman_wispr_stop(service);
5815 stats_stop(service);
5817 service->path = NULL;
5820 __connman_connection_update_gateway();
5822 g_dbus_unregister_interface(connection, path,
5823 CONNMAN_SERVICE_INTERFACE);
5827 g_hash_table_destroy(service->counter_table);
5829 if (service->network) {
5830 __connman_network_disconnect(service->network);
5831 connman_network_unref(service->network);
5832 service->network = NULL;
5835 if (service->provider)
5836 connman_provider_unref(service->provider);
5838 if (service->ipconfig_ipv4) {
5839 __connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
5840 __connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
5841 __connman_ipconfig_unref(service->ipconfig_ipv4);
5842 service->ipconfig_ipv4 = NULL;
5845 if (service->ipconfig_ipv6) {
5846 __connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
5847 __connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
5848 __connman_ipconfig_unref(service->ipconfig_ipv6);
5849 service->ipconfig_ipv6 = NULL;
5852 g_strfreev(service->timeservers);
5853 g_strfreev(service->timeservers_config);
5854 g_strfreev(service->nameservers);
5855 g_strfreev(service->nameservers_config);
5856 g_strfreev(service->nameservers_auto);
5857 g_strfreev(service->domains);
5858 g_strfreev(service->proxies);
5859 g_strfreev(service->excludes);
5861 g_free(service->hostname);
5862 g_free(service->domainname);
5863 g_free(service->pac);
5864 g_free(service->name);
5865 g_free(service->passphrase);
5866 g_free(service->identifier);
5867 g_free(service->eap);
5868 g_free(service->identity);
5869 g_free(service->agent_identity);
5870 g_free(service->ca_cert_file);
5871 g_free(service->client_cert_file);
5872 g_free(service->private_key_file);
5873 g_free(service->private_key_passphrase);
5874 g_free(service->phase2);
5875 g_free(service->config_file);
5876 g_free(service->config_entry);
5878 if (service->stats.timer)
5879 g_timer_destroy(service->stats.timer);
5880 if (service->stats_roaming.timer)
5881 g_timer_destroy(service->stats_roaming.timer);
5883 if (current_default == service)
5884 current_default = NULL;
5889 static void stats_init(struct connman_service *service)
5892 service->stats.valid = false;
5893 service->stats.enabled = false;
5894 service->stats.timer = g_timer_new();
5897 service->stats_roaming.valid = false;
5898 service->stats_roaming.enabled = false;
5899 service->stats_roaming.timer = g_timer_new();
5902 static void service_initialize(struct connman_service *service)
5904 DBG("service %p", service);
5906 service->refcount = 1;
5908 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
5910 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
5911 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
5913 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
5914 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
5915 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
5917 service->favorite = false;
5918 service->immutable = false;
5919 service->hidden = false;
5921 service->ignore = false;
5923 service->user.favorite_user = USER_NONE;
5924 service->user.current_user = USER_NONE;
5926 service->request_passphrase_input = false;
5928 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
5932 stats_init(service);
5934 service->provider = NULL;
5936 service->wps = false;
5937 #if defined TIZEN_EXT
5938 service->storage_reload = false;
5940 * Description: TIZEN implements system global connection management.
5942 service->user_pdn_connection_refcount = 0;
5943 __sync_synchronize();
5948 * connman_service_create:
5950 * Allocate a new service.
5952 * Returns: a newly-allocated #connman_service structure
5954 struct connman_service *connman_service_create(void)
5957 struct connman_stats_counter *counters;
5958 const char *counter;
5960 struct connman_service *service;
5962 service = g_try_new0(struct connman_service, 1);
5966 DBG("service %p", service);
5968 service->counter_table = g_hash_table_new_full(g_str_hash,
5969 g_str_equal, NULL, g_free);
5971 for (list = counter_list; list; list = list->next) {
5972 counter = list->data;
5974 counters = g_try_new0(struct connman_stats_counter, 1);
5976 g_hash_table_destroy(service->counter_table);
5981 counters->append_all = true;
5983 g_hash_table_replace(service->counter_table, (gpointer)counter,
5987 service_initialize(service);
5993 * connman_service_ref:
5994 * @service: service structure
5996 * Increase reference counter of service
5998 struct connman_service *
5999 connman_service_ref_debug(struct connman_service *service,
6000 const char *file, int line, const char *caller)
6002 DBG("%p ref %d by %s:%d:%s()", service, service->refcount + 1,
6003 file, line, caller);
6005 __sync_fetch_and_add(&service->refcount, 1);
6011 * connman_service_unref:
6012 * @service: service structure
6014 * Decrease reference counter of service and release service if no
6017 void connman_service_unref_debug(struct connman_service *service,
6018 const char *file, int line, const char *caller)
6020 DBG("%p ref %d by %s:%d:%s()", service, service->refcount - 1,
6021 file, line, caller);
6023 if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
6026 service_list = g_list_remove(service_list, service);
6028 __connman_service_disconnect(service);
6030 g_hash_table_remove(service_hash, service->identifier);
6033 static gint service_compare(gconstpointer a, gconstpointer b)
6035 struct connman_service *service_a = (void *) a;
6036 struct connman_service *service_b = (void *) b;
6037 enum connman_service_state state_a, state_b;
6038 bool a_connected, b_connected;
6041 state_a = service_a->state;
6042 state_b = service_b->state;
6043 a_connected = is_connected(service_a);
6044 b_connected = is_connected(service_b);
6046 if (a_connected && b_connected) {
6047 if (service_a->order > service_b->order)
6050 if (service_a->order < service_b->order)
6054 if (state_a != state_b) {
6055 if (a_connected && b_connected) {
6056 /* We prefer online over ready state */
6057 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
6060 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
6069 if (is_connecting(service_a))
6071 if (is_connecting(service_b))
6075 if (service_a->favorite && !service_b->favorite)
6078 if (!service_a->favorite && service_b->favorite)
6081 if (service_a->type != service_b->type) {
6083 if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6085 if (service_b->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6088 if (service_a->type == CONNMAN_SERVICE_TYPE_WIFI)
6090 if (service_b->type == CONNMAN_SERVICE_TYPE_WIFI)
6093 if (service_a->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6095 if (service_b->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6098 if (service_a->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6100 if (service_b->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6103 if (service_a->type == CONNMAN_SERVICE_TYPE_VPN)
6105 if (service_b->type == CONNMAN_SERVICE_TYPE_VPN)
6108 if (service_a->type == CONNMAN_SERVICE_TYPE_GADGET)
6110 if (service_b->type == CONNMAN_SERVICE_TYPE_GADGET)
6114 strength = (gint) service_b->strength - (gint) service_a->strength;
6118 return g_strcmp0(service_a->name, service_b->name);
6121 static void service_list_sort(void)
6123 if (service_list && service_list->next) {
6124 service_list = g_list_sort(service_list, service_compare);
6125 service_schedule_changed();
6130 * connman_service_get_type:
6131 * @service: service structure
6133 * Get the type of service
6135 enum connman_service_type connman_service_get_type(struct connman_service *service)
6138 return CONNMAN_SERVICE_TYPE_UNKNOWN;
6140 return service->type;
6144 * connman_service_get_interface:
6145 * @service: service structure
6147 * Get network interface of service
6149 char *connman_service_get_interface(struct connman_service *service)
6156 index = __connman_service_get_index(service);
6158 return connman_inet_ifname(index);
6162 * __connman_service_is_user_allowed:
6163 * @type: service type
6166 * Check a user is allowed to operate a type of service
6168 bool __connman_service_is_user_allowed(enum connman_service_type type,
6172 uid_t owner_user = USER_NONE;
6174 for (list = service_list; list; list = list->next) {
6175 struct connman_service *service = list->data;
6177 if (service->type != type)
6180 if (is_connected(service)) {
6181 owner_user = service->user.favorite_user;
6186 if (uid == USER_NONE ||
6187 (uid != USER_ROOT &&
6188 owner_user != USER_NONE &&
6196 * connman_service_get_network:
6197 * @service: service structure
6199 * Get the service network
6201 struct connman_network *
6202 __connman_service_get_network(struct connman_service *service)
6207 return service->network;
6210 struct connman_ipconfig *
6211 __connman_service_get_ip4config(struct connman_service *service)
6216 return service->ipconfig_ipv4;
6219 struct connman_ipconfig *
6220 __connman_service_get_ip6config(struct connman_service *service)
6225 return service->ipconfig_ipv6;
6228 struct connman_ipconfig *
6229 __connman_service_get_ipconfig(struct connman_service *service, int family)
6231 if (family == AF_INET)
6232 return __connman_service_get_ip4config(service);
6233 else if (family == AF_INET6)
6234 return __connman_service_get_ip6config(service);
6240 bool __connman_service_is_connected_state(struct connman_service *service,
6241 enum connman_ipconfig_type type)
6247 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
6249 case CONNMAN_IPCONFIG_TYPE_IPV4:
6250 return is_connected_state(service, service->state_ipv4);
6251 case CONNMAN_IPCONFIG_TYPE_IPV6:
6252 return is_connected_state(service, service->state_ipv6);
6253 case CONNMAN_IPCONFIG_TYPE_ALL:
6254 return is_connected_state(service,
6255 CONNMAN_IPCONFIG_TYPE_IPV4) &&
6256 is_connected_state(service,
6257 CONNMAN_IPCONFIG_TYPE_IPV6);
6262 enum connman_service_security __connman_service_get_security(
6263 struct connman_service *service)
6266 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
6268 return service->security;
6271 const char *__connman_service_get_phase2(struct connman_service *service)
6276 return service->phase2;
6279 bool __connman_service_wps_enabled(struct connman_service *service)
6284 return service->wps;
6287 void __connman_service_mark_dirty(void)
6289 services_dirty = true;
6292 #if defined TIZEN_EXT
6294 * Returns profile count if there is any connected profiles
6295 * that use same interface
6297 int __connman_service_get_connected_count_of_iface(
6298 struct connman_service *service)
6307 index1 = __connman_service_get_index(service);
6312 for (list = service_list; list; list = list->next) {
6313 struct connman_service *service2 = list->data;
6315 if (service == service2)
6318 index2 = __connman_service_get_index(service2);
6320 if (is_connected(service2) && index2 > 0 && index1 == index2)
6326 DBG("Interface index %d, count %d", index1, count);
6331 void __connman_service_set_storage_reload(struct connman_service *service,
6332 bool storage_reload)
6334 if (service != NULL)
6335 service->storage_reload = storage_reload;
6340 * __connman_service_set_favorite_delayed:
6341 * @service: service structure
6342 * @favorite: favorite value
6343 * @delay_ordering: do not order service sequence
6345 * Change the favorite setting of service
6347 int __connman_service_set_favorite_delayed(struct connman_service *service,
6349 bool delay_ordering)
6351 #if defined TIZEN_EXT
6352 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6355 if (service->hidden)
6358 if (service->favorite == favorite)
6361 service->favorite = favorite;
6363 if (!delay_ordering)
6364 __connman_service_get_order(service);
6366 favorite_changed(service);
6368 if (!delay_ordering) {
6370 service_list_sort();
6372 __connman_connection_update_gateway();
6379 * __connman_service_set_favorite:
6380 * @service: service structure
6381 * @favorite: favorite value
6383 * Change the favorite setting of service
6385 int __connman_service_set_favorite(struct connman_service *service,
6388 return __connman_service_set_favorite_delayed(service, favorite,
6392 bool connman_service_get_favorite(struct connman_service *service)
6394 return service->favorite;
6397 bool connman_service_get_autoconnect(struct connman_service *service)
6399 return service->autoconnect;
6402 int __connman_service_set_immutable(struct connman_service *service,
6405 if (service->hidden)
6408 if (service->immutable == immutable)
6411 service->immutable = immutable;
6413 immutable_changed(service);
6418 int __connman_service_set_ignore(struct connman_service *service,
6424 service->ignore = ignore;
6429 void __connman_service_set_string(struct connman_service *service,
6430 const char *key, const char *value)
6432 if (service->hidden)
6434 if (g_str_equal(key, "EAP")) {
6435 g_free(service->eap);
6436 service->eap = g_strdup(value);
6437 } else if (g_str_equal(key, "Identity")) {
6438 g_free(service->identity);
6439 service->identity = g_strdup(value);
6440 } else if (g_str_equal(key, "CACertFile")) {
6441 g_free(service->ca_cert_file);
6442 service->ca_cert_file = g_strdup(value);
6443 } else if (g_str_equal(key, "ClientCertFile")) {
6444 g_free(service->client_cert_file);
6445 service->client_cert_file = g_strdup(value);
6446 } else if (g_str_equal(key, "PrivateKeyFile")) {
6447 g_free(service->private_key_file);
6448 service->private_key_file = g_strdup(value);
6449 } else if (g_str_equal(key, "PrivateKeyPassphrase")) {
6450 g_free(service->private_key_passphrase);
6451 service->private_key_passphrase = g_strdup(value);
6452 } else if (g_str_equal(key, "Phase2")) {
6453 g_free(service->phase2);
6454 service->phase2 = g_strdup(value);
6455 } else if (g_str_equal(key, "Passphrase"))
6456 __connman_service_set_passphrase(service, value);
6459 void __connman_service_set_search_domains(struct connman_service *service,
6462 searchdomain_remove_all(service);
6464 if (service->domains)
6465 g_strfreev(service->domains);
6467 service->domains = g_strdupv(domains);
6469 searchdomain_add_all(service);
6472 static void service_complete(struct connman_service *service)
6474 reply_pending(service, EIO);
6476 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
6477 __connman_service_auto_connect(service->connect_reason);
6479 g_get_current_time(&service->modified);
6480 service_save(service);
6483 static void report_error_cb(void *user_context, bool retry,
6486 struct connman_service *service = user_context;
6489 __connman_service_connect(service,
6490 CONNMAN_SERVICE_CONNECT_REASON_USER);
6492 /* It is not relevant to stay on Failure state
6493 * when failing is due to wrong user input */
6494 __connman_service_clear_error(service);
6495 #if defined TIZEN_EXT
6496 /* Reseting the state back in case of failure state */
6497 service->state_ipv4 = service->state_ipv6 =
6498 CONNMAN_SERVICE_STATE_IDLE;
6500 if (service->error != CONNMAN_SERVICE_ERROR_AUTH_FAILED)
6501 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6503 service_complete(service);
6504 __connman_connection_update_gateway();
6508 static int check_wpspin(struct connman_service *service, const char *wpspin)
6516 length = strlen(wpspin);
6518 /* If 0, it will mean user wants to use PBC method */
6520 connman_network_set_string(service->network,
6521 "WiFi.PinWPS", NULL);
6525 /* A WPS PIN is always 8 chars length,
6526 * its content is in digit representation.
6531 for (i = 0; i < 8; i++)
6532 if (!isdigit((unsigned char) wpspin[i]))
6535 connman_network_set_string(service->network, "WiFi.PinWPS", wpspin);
6540 static void request_input_cb(struct connman_service *service,
6541 bool values_received,
6542 const char *name, int name_len,
6543 const char *identity, const char *passphrase,
6544 bool wps, const char *wpspin,
6545 const char *error, void *user_data)
6547 struct connman_device *device;
6548 const char *security;
6551 DBG("RequestInput return, %p", service);
6554 DBG("error: %s", error);
6556 if (g_strcmp0(error,
6557 "net.connman.Agent.Error.Canceled") == 0) {
6560 if (service->hidden)
6561 __connman_service_return_error(service,
6562 ECANCELED, user_data);
6565 if (service->hidden)
6566 __connman_service_return_error(service,
6567 ETIMEDOUT, user_data);
6571 if (service->hidden && name_len > 0 && name_len <= 32) {
6572 device = connman_network_get_device(service->network);
6573 security = connman_network_get_string(service->network,
6575 err = __connman_device_request_hidden_scan(device,
6577 identity, passphrase,
6578 security, user_data);
6580 __connman_service_return_error(service, -err,
6584 if (!values_received || service->hidden) {
6589 if (wps && service->network) {
6590 err = check_wpspin(service, wpspin);
6594 connman_network_set_bool(service->network, "WiFi.UseWPS", wps);
6598 __connman_service_set_agent_identity(service, identity);
6601 err = __connman_service_set_passphrase(service, passphrase);
6605 /* We forget any previous error. */
6606 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6608 __connman_service_connect(service,
6609 CONNMAN_SERVICE_CONNECT_REASON_USER);
6611 } else if (err == -ENOKEY) {
6612 __connman_service_indicate_error(service,
6613 CONNMAN_SERVICE_ERROR_INVALID_KEY);
6615 /* It is not relevant to stay on Failure state
6616 * when failing is due to wrong user input */
6617 service->state = CONNMAN_SERVICE_STATE_IDLE;
6619 if (!service->hidden) {
6621 * If there was a real error when requesting
6622 * hidden scan, then that error is returned already
6623 * to the user somewhere above so do not try to
6626 __connman_service_return_error(service, -err,
6630 service_complete(service);
6631 __connman_connection_update_gateway();
6635 static void downgrade_connected_services(void)
6637 struct connman_service *up_service;
6640 for (list = service_list; list; list = list->next) {
6641 up_service = list->data;
6643 if (!is_connected(up_service))
6646 if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
6649 downgrade_state(up_service);
6653 static int service_update_preferred_order(struct connman_service *default_service,
6654 struct connman_service *new_service,
6655 enum connman_service_state new_state)
6657 unsigned int *tech_array;
6660 if (!default_service || default_service == new_service ||
6661 default_service->state != new_state)
6664 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
6667 for (i = 0; tech_array[i] != 0; i += 1) {
6668 if (default_service->type == tech_array[i])
6671 if (new_service->type == tech_array[i]) {
6672 switch_default_service(default_service,
6674 __connman_connection_update_gateway();
6683 #if defined TIZEN_EXT
6684 static gboolean __connman_service_can_drop(struct connman_service *service)
6686 if (is_connected(service) == TRUE || is_connecting(service) == TRUE) {
6687 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
6689 else if (connman_service_is_no_ref_user_pdn_connection(service) == TRUE)
6695 static struct connman_device *default_connecting_device = NULL;
6697 static void __connman_service_disconnect_default(struct connman_service *service)
6699 struct connman_device *default_device = NULL;
6701 if (default_connecting_device == NULL)
6704 default_device = connman_network_get_device(
6705 __connman_service_get_network(service));
6707 DBG("Disconnecting service %p %s", service, service->path);
6708 DBG("Disconnecting device %p %p %s",
6709 default_connecting_device,
6711 connman_device_get_string(default_device, "Name"));
6713 if (default_connecting_device == default_device)
6714 default_connecting_device = NULL;
6717 static void __connman_service_connect_default(struct connman_service *current)
6721 bool default_internet;
6722 struct connman_service *service;
6723 struct connman_service *default_service = NULL;
6724 struct connman_device *default_device = NULL;
6726 if (current->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
6727 switch (current->state) {
6728 case CONNMAN_SERVICE_STATE_UNKNOWN:
6729 case CONNMAN_SERVICE_STATE_ASSOCIATION:
6730 case CONNMAN_SERVICE_STATE_CONFIGURATION:
6736 if (default_connecting_device &&
6737 __connman_service_is_internet_profile(current) == TRUE) {
6738 if (current->network == NULL)
6741 default_device = connman_network_get_device(current->network);
6742 if (default_connecting_device == default_device) {
6743 DBG("Cellular service[%s] %p %s",
6744 state2string(current->state), current, current->path);
6745 DBG("Cellular device %p %p %s",
6746 default_connecting_device, default_device,
6747 connman_device_get_string(default_device, "Name"));
6749 default_connecting_device = NULL;
6754 } else if (is_connected(current) == TRUE || is_connecting(current) == TRUE)
6757 /* Always-on: keep default cellular connection as possible */
6758 for (list = service_list; list; list = list->next) {
6759 service = list->data;
6761 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
6762 __connman_service_is_internet_profile(service) != TRUE ||
6763 service->network == NULL) {
6768 connman_network_get_bool(service->network, "DefaultInternet");
6770 DBG("service: %p %s %s %s (default: %d)", service, service->name,
6771 __connman_service_type2string(service->type),
6772 state2string(service->state), default_internet);
6774 if (default_internet) {
6775 default_service = service;
6776 if (is_connected(default_service) == TRUE ||
6777 is_connecting(default_service) == TRUE)
6780 default_device = connman_network_get_device(default_service->network);
6781 if (default_connecting_device == default_device) {
6782 DBG("Device is connecting (%p)", default_connecting_device);
6786 default_connecting_device = default_device;
6787 default_service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_USER;
6789 err = __connman_network_connect(default_service->network);
6790 DBG("Connecting default service %p %s [%d]",
6791 default_service, default_service->path, err);
6792 DBG("Connecting device %p %s", default_connecting_device,
6793 connman_device_get_string(default_connecting_device, "Name"));
6794 if (err < 0 && err != -EINPROGRESS) {
6795 default_connecting_device = NULL;
6803 static void single_connected_tech(struct connman_service *allowed)
6805 struct connman_service *service;
6806 GSList *services = NULL, *list;
6809 DBG("keeping %p %s", allowed, allowed->path);
6811 #if defined TIZEN_EXT
6812 if (!allowed || allowed->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6816 for (iter = service_list; iter; iter = iter->next) {
6817 service = iter->data;
6819 #if defined TIZEN_EXT
6820 if (service != allowed && service->type != allowed->type &&
6821 __connman_service_can_drop(service) == TRUE)
6823 if (!is_connected(service))
6826 if (service == allowed)
6829 services = g_slist_prepend(services, service);
6832 for (list = services; list; list = list->next) {
6833 service = list->data;
6835 DBG("disconnecting %p %s", service, service->path);
6836 #if defined TIZEN_EXT
6837 __connman_service_disconnect_default(service);
6839 __connman_service_disconnect(service);
6842 g_slist_free(services);
6845 #if defined TIZEN_EXT
6846 static void set_priority_connected_service(void)
6848 struct connman_service *service;
6851 for (list = service_list; list; list = list->next) {
6852 service = list->data;
6854 if (is_connected(service) == FALSE)
6862 static const char *get_dbus_sender(struct connman_service *service)
6864 if (!service->pending)
6867 return dbus_message_get_sender(service->pending);
6870 static int service_indicate_state(struct connman_service *service)
6872 enum connman_service_state old_state, new_state;
6873 struct connman_service *def_service;
6874 enum connman_ipconfig_method method;
6880 old_state = service->state;
6881 new_state = combine_state(service->state_ipv4, service->state_ipv6);
6883 DBG("service %p old %s - new %s/%s => %s",
6885 state2string(old_state),
6886 state2string(service->state_ipv4),
6887 state2string(service->state_ipv6),
6888 state2string(new_state));
6890 if (old_state == new_state)
6893 def_service = __connman_service_get_default();
6895 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
6896 result = service_update_preferred_order(def_service,
6897 service, new_state);
6898 if (result == -EALREADY)
6902 if (old_state == CONNMAN_SERVICE_STATE_ONLINE)
6903 __connman_notifier_leave_online(service->type);
6905 if (is_connected_state(service, old_state) &&
6906 !is_connected_state(service, new_state))
6907 searchdomain_remove_all(service);
6909 service->state = new_state;
6910 state_changed(service);
6913 case CONNMAN_SERVICE_STATE_UNKNOWN:
6917 case CONNMAN_SERVICE_STATE_IDLE:
6918 if (old_state != CONNMAN_SERVICE_STATE_DISCONNECT)
6919 __connman_service_disconnect(service);
6923 case CONNMAN_SERVICE_STATE_ASSOCIATION:
6927 case CONNMAN_SERVICE_STATE_CONFIGURATION:
6928 if (!service->new_service &&
6929 __connman_stats_service_register(service) == 0) {
6931 * For new services the statistics are updated after
6932 * we have successfully connected.
6934 __connman_stats_get(service, false,
6935 &service->stats.data);
6936 __connman_stats_get(service, true,
6937 &service->stats_roaming.data);
6942 case CONNMAN_SERVICE_STATE_READY:
6943 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6945 if (service->new_service &&
6946 __connman_stats_service_register(service) == 0) {
6948 * This is normally done after configuring state
6949 * but for new service do this after we have connected
6952 __connman_stats_get(service, false,
6953 &service->stats.data);
6954 __connman_stats_get(service, true,
6955 &service->stats_roaming.data);
6958 service->new_service = false;
6962 def_service = __connman_service_get_default();
6964 service_update_preferred_order(def_service, service, new_state);
6966 __connman_service_set_favorite(service, true);
6968 reply_pending(service, 0);
6970 g_get_current_time(&service->modified);
6971 service_save(service);
6973 searchdomain_add_all(service);
6974 dns_changed(service);
6975 domain_changed(service);
6976 proxy_changed(service);
6978 if (old_state != CONNMAN_SERVICE_STATE_ONLINE)
6979 __connman_notifier_connect(service->type);
6981 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
6982 connman_network_get_bool(service->network,
6986 pass = connman_network_get_string(service->network,
6989 __connman_service_set_passphrase(service, pass);
6991 connman_network_set_bool(service->network,
6992 "WiFi.UseWPS", false);
6995 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
6996 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
6997 __connman_ipconfig_disable_ipv6(
6998 service->ipconfig_ipv6);
7000 if (connman_setting_get_bool("SingleConnectedTechnology"))
7001 single_connected_tech(service);
7002 else if (service->type != CONNMAN_SERVICE_TYPE_VPN)
7005 #if defined TIZEN_EXT
7006 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7007 set_priority_connected_service();
7012 case CONNMAN_SERVICE_STATE_ONLINE:
7016 case CONNMAN_SERVICE_STATE_DISCONNECT:
7017 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7019 reply_pending(service, ECONNABORTED);
7021 def_service = __connman_service_get_default();
7022 service->disconnect_reason = connman_network_get_disconnect_reason(service->network);
7024 if (!__connman_notifier_is_connected() &&
7026 def_service->provider)
7027 connman_provider_disconnect(def_service->provider);
7031 __connman_wispr_stop(service);
7033 __connman_wpad_stop(service);
7035 #if defined TIZEN_EXT
7037 * Skip the functions if there is any connected profiles
7038 * that use same interface
7040 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7041 __connman_service_get_connected_count_of_iface(
7044 dns_changed(service);
7045 domain_changed(service);
7046 proxy_changed(service);
7047 #if defined TIZEN_EXT
7052 * Previous services which are connected and which states
7053 * are set to online should reset relevantly ipconfig_state
7054 * to ready so wispr/portal will be rerun on those
7056 downgrade_connected_services();
7058 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7061 case CONNMAN_SERVICE_STATE_FAILURE:
7062 #if defined TIZEN_EXT
7063 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7065 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7067 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7068 connman_agent_report_error(service, service->path,
7069 error2string(service->error),
7071 get_dbus_sender(service),
7072 NULL) == -EINPROGRESS)
7074 service_complete(service);
7079 service_list_sort();
7081 #if defined TIZEN_EXT
7082 __connman_service_connect_default(service);
7085 __connman_connection_update_gateway();
7087 if ((old_state == CONNMAN_SERVICE_STATE_ONLINE &&
7088 new_state != CONNMAN_SERVICE_STATE_READY) ||
7089 (old_state == CONNMAN_SERVICE_STATE_READY &&
7090 new_state != CONNMAN_SERVICE_STATE_ONLINE)) {
7091 __connman_notifier_disconnect(service->type);
7094 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
7095 __connman_notifier_enter_online(service->type);
7099 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7100 service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7101 (new_state == CONNMAN_SERVICE_STATE_READY ||
7102 new_state == CONNMAN_SERVICE_STATE_ONLINE)) {
7103 if (service->user.favorite_user != service->user.current_user) {
7104 DBG("Now set service favorite user id from %d to %d",
7105 service->user.favorite_user, service->user.current_user);
7107 service->user.favorite_user = service->user.current_user;
7109 service_save(service);
7116 int __connman_service_indicate_error(struct connman_service *service,
7117 enum connman_service_error error)
7119 DBG("service %p error %d", service, error);
7124 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
7127 set_error(service, error);
7129 /* default internet service: fix not cleared if pdp activation*/
7130 #if defined TIZEN_EXT
7132 * If connection failed for default service(DefaultInternet),
7133 * default_connecting_device should be cleared.
7135 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7136 service->error == CONNMAN_SERVICE_ERROR_CONNECT_FAILED)
7137 __connman_service_disconnect_default(service);
7139 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7140 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY) {
7141 g_free(service->passphrase);
7142 service->passphrase = NULL;
7146 __connman_service_ipconfig_indicate_state(service,
7147 CONNMAN_SERVICE_STATE_FAILURE,
7148 CONNMAN_IPCONFIG_TYPE_IPV4);
7149 __connman_service_ipconfig_indicate_state(service,
7150 CONNMAN_SERVICE_STATE_FAILURE,
7151 CONNMAN_IPCONFIG_TYPE_IPV6);
7155 int __connman_service_clear_error(struct connman_service *service)
7157 DBusMessage *pending, *provider_pending;
7159 DBG("service %p", service);
7164 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
7167 pending = service->pending;
7168 service->pending = NULL;
7169 provider_pending = service->provider_pending;
7170 service->provider_pending = NULL;
7172 __connman_service_ipconfig_indicate_state(service,
7173 CONNMAN_SERVICE_STATE_IDLE,
7174 CONNMAN_IPCONFIG_TYPE_IPV6);
7176 __connman_service_ipconfig_indicate_state(service,
7177 CONNMAN_SERVICE_STATE_IDLE,
7178 CONNMAN_IPCONFIG_TYPE_IPV4);
7180 service->pending = pending;
7181 service->provider_pending = provider_pending;
7186 int __connman_service_indicate_default(struct connman_service *service)
7188 DBG("service %p state %s", service, state2string(service->state));
7190 if (!is_connected(service)) {
7192 * If service is not yet fully connected, then we must not
7193 * change the default yet. The default gw will be changed
7194 * after the service state is in ready.
7196 return -EINPROGRESS;
7204 enum connman_service_state __connman_service_ipconfig_get_state(
7205 struct connman_service *service,
7206 enum connman_ipconfig_type type)
7209 return CONNMAN_SERVICE_STATE_UNKNOWN;
7211 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7212 return service->state_ipv4;
7214 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
7215 return service->state_ipv6;
7217 return CONNMAN_SERVICE_STATE_UNKNOWN;
7220 static void check_proxy_setup(struct connman_service *service)
7223 * We start WPAD if we haven't got a PAC URL from DHCP and
7224 * if our proxy manual configuration is either empty or set
7225 * to AUTO with an empty URL.
7228 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
7231 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
7232 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
7236 if (__connman_wpad_start(service) < 0) {
7237 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
7238 __connman_notifier_proxy_changed(service);
7245 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
7248 #if defined TIZEN_EXT
7249 void connman_check_proxy_setup_and_wispr_start(struct connman_service *service){
7251 DBG("check the proxy and start wispr");
7252 check_proxy_setup(service);
7258 * How many networks are connected at the same time. If more than 1,
7259 * then set the rp_filter setting properly (loose mode routing) so that network
7260 * connectivity works ok. This is only done for IPv4 networks as IPv6
7261 * does not have rp_filter knob.
7263 static int connected_networks_count;
7264 static int original_rp_filter;
7266 static void service_rp_filter(struct connman_service *service,
7269 enum connman_ipconfig_method method;
7271 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
7274 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7275 case CONNMAN_IPCONFIG_METHOD_OFF:
7276 case CONNMAN_IPCONFIG_METHOD_AUTO:
7278 case CONNMAN_IPCONFIG_METHOD_FIXED:
7279 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7280 case CONNMAN_IPCONFIG_METHOD_DHCP:
7285 if (connected_networks_count == 1) {
7287 filter_value = __connman_ipconfig_set_rp_filter();
7288 if (filter_value < 0)
7291 original_rp_filter = filter_value;
7293 connected_networks_count++;
7296 if (connected_networks_count == 2)
7297 __connman_ipconfig_unset_rp_filter(original_rp_filter);
7299 connected_networks_count--;
7300 if (connected_networks_count < 0)
7301 connected_networks_count = 0;
7304 DBG("%s %s ipconfig %p method %d count %d filter %d",
7305 connected ? "connected" : "disconnected", service->identifier,
7306 service->ipconfig_ipv4, method,
7307 connected_networks_count, original_rp_filter);
7310 static gboolean redo_wispr(gpointer user_data)
7312 struct connman_service *service = user_data;
7313 int refcount = service->refcount - 1;
7315 connman_service_unref(service);
7316 if (refcount == 0) {
7317 DBG("Service %p already removed", service);
7321 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV6);
7326 int __connman_service_online_check_failed(struct connman_service *service,
7327 enum connman_ipconfig_type type)
7329 DBG("service %p type %d count %d", service, type,
7330 service->online_check_count);
7332 /* currently we only retry IPv6 stuff */
7333 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 ||
7334 service->online_check_count != 1) {
7335 connman_warn("Online check failed for %p %s", service,
7340 service->online_check_count = 0;
7343 * We set the timeout to 1 sec so that we have a chance to get
7344 * necessary IPv6 router advertisement messages that might have
7347 g_timeout_add_seconds(1, redo_wispr, connman_service_ref(service));
7352 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
7353 enum connman_service_state new_state,
7354 enum connman_ipconfig_type type)
7356 struct connman_ipconfig *ipconfig = NULL;
7357 enum connman_service_state old_state;
7358 enum connman_ipconfig_method method;
7364 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
7365 case CONNMAN_IPCONFIG_TYPE_ALL:
7368 case CONNMAN_IPCONFIG_TYPE_IPV4:
7369 old_state = service->state_ipv4;
7370 ipconfig = service->ipconfig_ipv4;
7374 case CONNMAN_IPCONFIG_TYPE_IPV6:
7375 old_state = service->state_ipv6;
7376 ipconfig = service->ipconfig_ipv6;
7385 if (old_state == new_state)
7388 #if defined TIZEN_EXT
7389 __sync_synchronize();
7390 if (service->user_pdn_connection_refcount > 0 &&
7391 service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7392 if (new_state == CONNMAN_SERVICE_STATE_FAILURE ||
7393 new_state == CONNMAN_SERVICE_STATE_DISCONNECT ||
7394 new_state == CONNMAN_SERVICE_STATE_IDLE) {
7395 service->user_pdn_connection_refcount = 0;
7396 __sync_synchronize();
7400 DBG("service %p (%s) old state %d (%s) new state %d (%s) type %d (%s)",
7401 service, service ? service->identifier : NULL,
7402 old_state, state2string(old_state),
7403 new_state, state2string(new_state),
7404 type, __connman_ipconfig_type2string(type));
7406 switch (new_state) {
7407 case CONNMAN_SERVICE_STATE_UNKNOWN:
7408 case CONNMAN_SERVICE_STATE_IDLE:
7409 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7411 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7412 __connman_ipconfig_enable(ipconfig);
7414 case CONNMAN_SERVICE_STATE_READY:
7415 #if defined TIZEN_EXT
7416 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7417 __connman_service_is_internet_profile(service) != TRUE) {
7418 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7419 service_rp_filter(service, TRUE);
7424 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
7425 #if !defined TIZEN_EXT
7426 check_proxy_setup(service);
7428 service_rp_filter(service, true);
7430 service->online_check_count = 1;
7431 __connman_wispr_start(service, type);
7434 case CONNMAN_SERVICE_STATE_ONLINE:
7436 case CONNMAN_SERVICE_STATE_DISCONNECT:
7437 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
7440 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7441 service_rp_filter(service, false);
7444 case CONNMAN_SERVICE_STATE_FAILURE:
7448 /* Keep that state, but if the ipconfig method is OFF, then we set
7449 the state to IDLE so that it will not affect the combined state
7452 method = __connman_ipconfig_get_method(ipconfig);
7454 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7455 case CONNMAN_IPCONFIG_METHOD_OFF:
7456 new_state = CONNMAN_SERVICE_STATE_IDLE;
7459 case CONNMAN_IPCONFIG_METHOD_FIXED:
7460 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7461 case CONNMAN_IPCONFIG_METHOD_DHCP:
7462 case CONNMAN_IPCONFIG_METHOD_AUTO:
7467 if (is_connected_state(service, old_state) &&
7468 !is_connected_state(service, new_state))
7469 #if defined TIZEN_EXT
7471 DBG("nameserver remove all, type: %d", type);
7472 nameserver_remove_all(service, type);
7474 nameserver_remove_all(service);
7476 #if defined TIZEN_EXT
7480 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7481 service->state_ipv4 = new_state;
7483 service->state_ipv6 = new_state;
7485 if (!is_connected_state(service, old_state) &&
7486 is_connected_state(service, new_state))
7487 #if defined TIZEN_EXT
7489 DBG("nameserver add all, type: %d", type);
7490 nameserver_add_all(service, type);
7492 nameserver_add_all(service);
7494 #if defined TIZEN_EXT
7498 #if defined TIZEN_EXT
7499 int ret = service_indicate_state(service);
7500 /*Sent the Ready changed signal again in case IPv4 IP set
7503 if(ret == -EALREADY && type == CONNMAN_IPCONFIG_TYPE_IPV4
7504 && new_state == CONNMAN_SERVICE_STATE_READY) {
7505 DBG("Notify IPv4 state new/old %d/%d", new_state,old_state);
7506 state_changed(service);
7511 return service_indicate_state(service);
7514 static bool prepare_network(struct connman_service *service)
7516 enum connman_network_type type;
7517 unsigned int ssid_len;
7519 type = connman_network_get_type(service->network);
7522 case CONNMAN_NETWORK_TYPE_UNKNOWN:
7523 case CONNMAN_NETWORK_TYPE_VENDOR:
7525 case CONNMAN_NETWORK_TYPE_WIFI:
7526 if (!connman_network_get_blob(service->network, "WiFi.SSID",
7530 if (service->passphrase)
7531 connman_network_set_string(service->network,
7532 "WiFi.Passphrase", service->passphrase);
7534 case CONNMAN_NETWORK_TYPE_ETHERNET:
7535 case CONNMAN_NETWORK_TYPE_GADGET:
7536 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
7537 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
7538 case CONNMAN_NETWORK_TYPE_CELLULAR:
7545 static void prepare_8021x(struct connman_service *service)
7548 connman_network_set_string(service->network, "WiFi.EAP",
7551 if (service->identity)
7552 connman_network_set_string(service->network, "WiFi.Identity",
7555 if (service->ca_cert_file)
7556 connman_network_set_string(service->network, "WiFi.CACertFile",
7557 service->ca_cert_file);
7559 if (service->client_cert_file)
7560 connman_network_set_string(service->network,
7561 "WiFi.ClientCertFile",
7562 service->client_cert_file);
7564 if (service->private_key_file)
7565 connman_network_set_string(service->network,
7566 "WiFi.PrivateKeyFile",
7567 service->private_key_file);
7569 if (service->private_key_passphrase)
7570 connman_network_set_string(service->network,
7571 "WiFi.PrivateKeyPassphrase",
7572 service->private_key_passphrase);
7574 if (service->phase2)
7575 connman_network_set_string(service->network, "WiFi.Phase2",
7579 static int service_connect(struct connman_service *service)
7583 if (service->hidden)
7586 #if defined TIZEN_EXT
7590 index = __connman_service_get_index(service);
7592 for (list = service_list; list; list = list->next) {
7593 struct connman_service *temp = list->data;
7595 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7598 if (!is_connecting(temp) && !is_connected(temp))
7601 if (service == temp)
7604 if (service->type != temp->type)
7607 if (__connman_service_get_index(temp) == index &&
7608 __connman_service_disconnect(temp) == -EINPROGRESS)
7609 return -EINPROGRESS;
7613 switch (service->type) {
7614 case CONNMAN_SERVICE_TYPE_UNKNOWN:
7615 case CONNMAN_SERVICE_TYPE_SYSTEM:
7616 case CONNMAN_SERVICE_TYPE_GPS:
7617 case CONNMAN_SERVICE_TYPE_P2P:
7619 case CONNMAN_SERVICE_TYPE_ETHERNET:
7620 case CONNMAN_SERVICE_TYPE_GADGET:
7621 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
7622 case CONNMAN_SERVICE_TYPE_CELLULAR:
7623 case CONNMAN_SERVICE_TYPE_VPN:
7625 case CONNMAN_SERVICE_TYPE_WIFI:
7626 switch (service->security) {
7627 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
7628 case CONNMAN_SERVICE_SECURITY_NONE:
7630 case CONNMAN_SERVICE_SECURITY_WEP:
7631 case CONNMAN_SERVICE_SECURITY_PSK:
7632 case CONNMAN_SERVICE_SECURITY_WPA:
7633 case CONNMAN_SERVICE_SECURITY_RSN:
7634 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
7637 if (service->request_passphrase_input) {
7638 DBG("Now try to connect other user's favorite service");
7639 service->request_passphrase_input = false;
7641 } else if (!service->passphrase) {
7642 if (!service->network)
7645 if (!service->wps ||
7646 !connman_network_get_bool(service->network, "WiFi.UseWPS"))
7651 case CONNMAN_SERVICE_SECURITY_8021X:
7655 #if defined TIZEN_EXT
7657 * never request credentials if using EAP-TLS, EAP-SIM
7658 * or EAP-AKA (EAP-TLS, EAP-SIM and EAP-AKA networks
7659 * need to be fully provisioned)
7661 DBG("service eap: %s", service->eap);
7662 if (g_str_equal(service->eap, "tls") ||
7663 g_str_equal(service->eap, "sim") ||
7664 g_str_equal(service->eap, "aka"))
7668 * never request credentials if using EAP-TLS
7669 * (EAP-TLS networks need to be fully provisioned)
7671 if (g_str_equal(service->eap, "tls"))
7675 * Return -ENOKEY if either identity or passphrase is
7676 * missing. Agent provided credentials can be used as
7677 * fallback if needed.
7679 if (((!service->identity &&
7680 !service->agent_identity) ||
7681 !service->passphrase) ||
7682 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
7690 if (service->network) {
7691 if (!prepare_network(service))
7694 switch (service->security) {
7695 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
7696 case CONNMAN_SERVICE_SECURITY_NONE:
7697 case CONNMAN_SERVICE_SECURITY_WEP:
7698 case CONNMAN_SERVICE_SECURITY_PSK:
7699 case CONNMAN_SERVICE_SECURITY_WPA:
7700 case CONNMAN_SERVICE_SECURITY_RSN:
7702 case CONNMAN_SERVICE_SECURITY_8021X:
7703 prepare_8021x(service);
7707 if (__connman_stats_service_register(service) == 0) {
7708 __connman_stats_get(service, false,
7709 &service->stats.data);
7710 __connman_stats_get(service, true,
7711 &service->stats_roaming.data);
7714 if (service->ipconfig_ipv4)
7715 __connman_ipconfig_enable(service->ipconfig_ipv4);
7716 if (service->ipconfig_ipv6)
7717 __connman_ipconfig_enable(service->ipconfig_ipv6);
7719 err = __connman_network_connect(service->network);
7720 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7722 err = __connman_provider_connect(service->provider);
7727 if (err != -EINPROGRESS) {
7728 __connman_ipconfig_disable(service->ipconfig_ipv4);
7729 __connman_ipconfig_disable(service->ipconfig_ipv6);
7730 __connman_stats_service_unregister(service);
7737 int __connman_service_connect(struct connman_service *service,
7738 enum connman_service_connect_reason reason)
7742 DBG("service %p state %s connect reason %s -> %s",
7743 service, state2string(service->state),
7744 reason2string(service->connect_reason),
7745 reason2string(reason));
7747 if (is_connected(service))
7750 if (is_connecting(service))
7753 switch (service->type) {
7754 case CONNMAN_SERVICE_TYPE_UNKNOWN:
7755 case CONNMAN_SERVICE_TYPE_SYSTEM:
7756 case CONNMAN_SERVICE_TYPE_GPS:
7757 case CONNMAN_SERVICE_TYPE_P2P:
7760 case CONNMAN_SERVICE_TYPE_ETHERNET:
7761 case CONNMAN_SERVICE_TYPE_GADGET:
7762 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
7763 case CONNMAN_SERVICE_TYPE_CELLULAR:
7764 case CONNMAN_SERVICE_TYPE_VPN:
7765 case CONNMAN_SERVICE_TYPE_WIFI:
7769 if (!is_ipconfig_usable(service))
7772 __connman_service_clear_error(service);
7774 err = service_connect(service);
7776 service->connect_reason = reason;
7780 if (err == -EINPROGRESS) {
7781 if (service->timeout == 0)
7782 service->timeout = g_timeout_add_seconds(
7783 CONNECT_TIMEOUT, connect_timeout, service);
7785 return -EINPROGRESS;
7788 if (service->network)
7789 __connman_network_disconnect(service->network);
7790 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7792 connman_provider_disconnect(service->provider);
7794 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
7795 if (err == -ENOKEY || err == -EPERM) {
7796 DBusMessage *pending = NULL;
7799 * We steal the reply here. The idea is that the
7800 * connecting client will see the connection status
7801 * after the real hidden network is connected or
7802 * connection failed.
7804 if (service->hidden) {
7805 pending = service->pending;
7806 service->pending = NULL;
7809 err = __connman_agent_request_passphrase_input(service,
7811 get_dbus_sender(service),
7813 if (service->hidden && err != -EINPROGRESS)
7814 service->pending = pending;
7818 reply_pending(service, -err);
7824 int __connman_service_disconnect(struct connman_service *service)
7828 DBG("service %p", service);
7830 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
7831 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
7833 connman_agent_cancel(service);
7835 reply_pending(service, ECONNABORTED);
7837 if (service->network) {
7838 err = __connman_network_disconnect(service->network);
7839 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7841 err = connman_provider_disconnect(service->provider);
7845 if (err < 0 && err != -EINPROGRESS)
7848 __connman_6to4_remove(service->ipconfig_ipv4);
7850 if (service->ipconfig_ipv4)
7851 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
7854 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
7857 #if defined TIZEN_EXT
7859 * Skip the functions If there is any connected profiles
7860 * that use same interface
7862 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7863 __connman_service_get_connected_count_of_iface(service) <= 0) {
7865 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
7866 settings_changed(service, service->ipconfig_ipv4);
7868 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
7869 settings_changed(service, service->ipconfig_ipv6);
7871 __connman_ipconfig_disable(service->ipconfig_ipv4);
7872 __connman_ipconfig_disable(service->ipconfig_ipv6);
7873 #if defined TIZEN_EXT
7877 __connman_stats_service_unregister(service);
7882 int __connman_service_disconnect_all(void)
7884 struct connman_service *service;
7885 GSList *services = NULL, *list;
7890 for (iter = service_list; iter; iter = iter->next) {
7891 service = iter->data;
7893 if (!is_connected(service))
7896 services = g_slist_prepend(services, service);
7899 for (list = services; list; list = list->next) {
7900 struct connman_service *service = list->data;
7902 service->ignore = true;
7904 __connman_service_disconnect(service);
7907 g_slist_free(services);
7913 * lookup_by_identifier:
7914 * @identifier: service identifier
7916 * Look up a service by identifier (reference count will not be increased)
7918 static struct connman_service *lookup_by_identifier(const char *identifier)
7920 return g_hash_table_lookup(service_hash, identifier);
7923 struct provision_user_data {
7928 static void provision_changed(gpointer value, gpointer user_data)
7930 struct connman_service *service = value;
7931 struct provision_user_data *data = user_data;
7932 const char *path = data->ident;
7935 ret = __connman_config_provision_service_ident(service, path,
7936 service->config_file, service->config_entry);
7941 int __connman_service_provision_changed(const char *ident)
7943 struct provision_user_data data = {
7948 g_list_foreach(service_list, provision_changed, (void *)&data);
7951 * Because the provision_changed() might have set some services
7952 * as favorite, we must sort the sequence now.
7954 if (services_dirty) {
7955 services_dirty = false;
7957 service_list_sort();
7959 __connman_connection_update_gateway();
7965 void __connman_service_set_config(struct connman_service *service,
7966 const char *file_id, const char *entry)
7971 g_free(service->config_file);
7972 service->config_file = g_strdup(file_id);
7974 g_free(service->config_entry);
7975 service->config_entry = g_strdup(entry);
7979 * __connman_service_get:
7980 * @identifier: service identifier
7982 * Look up a service by identifier or create a new one if not found
7984 static struct connman_service *service_get(const char *identifier)
7986 struct connman_service *service;
7988 service = g_hash_table_lookup(service_hash, identifier);
7990 connman_service_ref(service);
7994 service = connman_service_create();
7998 DBG("service %p", service);
8000 service->identifier = g_strdup(identifier);
8002 service_list = g_list_insert_sorted(service_list, service,
8005 g_hash_table_insert(service_hash, service->identifier, service);
8010 static int service_register(struct connman_service *service)
8012 DBG("service %p", service);
8017 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
8018 service->identifier);
8020 DBG("path %s", service->path);
8022 if (__connman_config_provision_service(service) < 0)
8023 service_load(service);
8025 g_dbus_register_interface(connection, service->path,
8026 CONNMAN_SERVICE_INTERFACE,
8027 service_methods, service_signals,
8028 NULL, service, NULL);
8030 service_list_sort();
8032 __connman_connection_update_gateway();
8037 static void service_up(struct connman_ipconfig *ipconfig,
8040 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8042 DBG("%s up", ifname);
8044 link_changed(service);
8046 service->stats.valid = false;
8047 service->stats_roaming.valid = false;
8050 static void service_down(struct connman_ipconfig *ipconfig,
8053 DBG("%s down", ifname);
8056 static void service_lower_up(struct connman_ipconfig *ipconfig,
8059 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8061 DBG("%s lower up", ifname);
8063 stats_start(service);
8066 static void service_lower_down(struct connman_ipconfig *ipconfig,
8069 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8071 DBG("%s lower down", ifname);
8073 if (!is_idle_state(service, service->state_ipv4))
8074 __connman_ipconfig_disable(service->ipconfig_ipv4);
8076 if (!is_idle_state(service, service->state_ipv6))
8077 __connman_ipconfig_disable(service->ipconfig_ipv6);
8079 stats_stop(service);
8080 service_save(service);
8083 static void service_ip_bound(struct connman_ipconfig *ipconfig,
8086 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8087 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8088 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8089 #if defined TIZEN_EXT
8093 DBG("%s ip bound", ifname);
8095 type = __connman_ipconfig_get_config_type(ipconfig);
8096 method = __connman_ipconfig_get_method(ipconfig);
8098 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8101 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8102 method == CONNMAN_IPCONFIG_METHOD_AUTO)
8103 #if defined TIZEN_EXT
8105 err = __connman_ipconfig_gateway_add(ipconfig, service);
8108 __connman_connection_gateway_activate(service,
8109 CONNMAN_IPCONFIG_TYPE_IPV6);
8112 __connman_service_ipconfig_indicate_state(service,
8113 CONNMAN_SERVICE_STATE_READY,
8114 CONNMAN_IPCONFIG_TYPE_IPV6);
8117 settings_changed(service, ipconfig);
8120 static void service_ip_release(struct connman_ipconfig *ipconfig,
8123 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8124 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8125 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8127 DBG("%s ip release", ifname);
8129 type = __connman_ipconfig_get_config_type(ipconfig);
8130 method = __connman_ipconfig_get_method(ipconfig);
8132 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8135 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8136 method == CONNMAN_IPCONFIG_METHOD_OFF)
8137 __connman_service_ipconfig_indicate_state(service,
8138 CONNMAN_SERVICE_STATE_DISCONNECT,
8139 CONNMAN_IPCONFIG_TYPE_IPV6);
8141 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
8142 method == CONNMAN_IPCONFIG_METHOD_OFF)
8143 __connman_service_ipconfig_indicate_state(service,
8144 CONNMAN_SERVICE_STATE_DISCONNECT,
8145 CONNMAN_IPCONFIG_TYPE_IPV4);
8147 settings_changed(service, ipconfig);
8150 static void service_route_changed(struct connman_ipconfig *ipconfig,
8153 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8155 DBG("%s route changed", ifname);
8157 settings_changed(service, ipconfig);
8160 static const struct connman_ipconfig_ops service_ops = {
8162 .down = service_down,
8163 .lower_up = service_lower_up,
8164 .lower_down = service_lower_down,
8165 .ip_bound = service_ip_bound,
8166 .ip_release = service_ip_release,
8167 .route_set = service_route_changed,
8168 .route_unset = service_route_changed,
8171 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
8172 int index, enum connman_ipconfig_method method)
8174 struct connman_ipconfig *ipconfig_ipv4;
8176 ipconfig_ipv4 = __connman_ipconfig_create(index,
8177 CONNMAN_IPCONFIG_TYPE_IPV4);
8181 __connman_ipconfig_set_method(ipconfig_ipv4, method);
8183 __connman_ipconfig_set_data(ipconfig_ipv4, service);
8185 __connman_ipconfig_set_ops(ipconfig_ipv4, &service_ops);
8187 return ipconfig_ipv4;
8190 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
8193 struct connman_ipconfig *ipconfig_ipv6;
8195 ipconfig_ipv6 = __connman_ipconfig_create(index,
8196 CONNMAN_IPCONFIG_TYPE_IPV6);
8200 __connman_ipconfig_set_data(ipconfig_ipv6, service);
8202 __connman_ipconfig_set_ops(ipconfig_ipv6, &service_ops);
8204 return ipconfig_ipv6;
8207 void __connman_service_read_ip4config(struct connman_service *service)
8211 if (!service->ipconfig_ipv4)
8214 keyfile = connman_storage_load_service(service->identifier);
8218 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
8219 service->identifier, "IPv4.");
8221 g_key_file_free(keyfile);
8224 void connman_service_create_ip4config(struct connman_service *service,
8227 DBG("ipv4 %p", service->ipconfig_ipv4);
8229 if (service->ipconfig_ipv4)
8232 service->ipconfig_ipv4 = create_ip4config(service, index,
8233 CONNMAN_IPCONFIG_METHOD_DHCP);
8234 __connman_service_read_ip4config(service);
8237 void __connman_service_read_ip6config(struct connman_service *service)
8241 if (!service->ipconfig_ipv6)
8244 keyfile = connman_storage_load_service(service->identifier);
8248 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
8249 service->identifier, "IPv6.");
8251 g_key_file_free(keyfile);
8254 void connman_service_create_ip6config(struct connman_service *service,
8257 DBG("ipv6 %p", service->ipconfig_ipv6);
8259 if (service->ipconfig_ipv6)
8262 service->ipconfig_ipv6 = create_ip6config(service, index);
8264 __connman_service_read_ip6config(service);
8268 * connman_service_lookup_from_network:
8269 * @network: network structure
8271 * Look up a service by network (reference count will not be increased)
8273 struct connman_service *connman_service_lookup_from_network(struct connman_network *network)
8275 struct connman_service *service;
8276 const char *ident, *group;
8282 ident = __connman_network_get_ident(network);
8286 group = connman_network_get_group(network);
8290 name = g_strdup_printf("%s_%s_%s",
8291 __connman_network_get_type(network), ident, group);
8292 service = lookup_by_identifier(name);
8298 struct connman_service *__connman_service_lookup_from_index(int index)
8300 struct connman_service *service;
8303 for (list = service_list; list; list = list->next) {
8304 service = list->data;
8306 if (__connman_ipconfig_get_index(service->ipconfig_ipv4)
8310 if (__connman_ipconfig_get_index(service->ipconfig_ipv6)
8318 struct connman_service *__connman_service_lookup_from_ident(const char *identifier)
8320 return lookup_by_identifier(identifier);
8323 const char *__connman_service_get_ident(struct connman_service *service)
8325 return service->identifier;
8328 const char *__connman_service_get_path(struct connman_service *service)
8330 return service->path;
8333 const char *__connman_service_get_name(struct connman_service *service)
8335 return service->name;
8338 enum connman_service_state __connman_service_get_state(struct connman_service *service)
8340 return service->state;
8343 unsigned int __connman_service_get_order(struct connman_service *service)
8345 unsigned int order = 0;
8352 if (!service->favorite)
8355 #if defined TIZEN_EXT
8356 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8357 service->do_split_routing == FALSE)
8359 else if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
8360 if (service->order < 5)
8362 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
8364 else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
8366 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8367 __connman_service_is_internet_profile(service) == TRUE)
8369 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8370 __connman_service_is_tethering_profile(service) == TRUE)
8372 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8377 if (service == service_list->data)
8380 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8381 !service->do_split_routing) {
8382 service->order = 10;
8386 DBG("service %p name %s order %d split %d", service, service->name,
8387 order, service->do_split_routing);
8392 void __connman_service_update_ordering(void)
8394 if (service_list && service_list->next)
8395 service_list = g_list_sort(service_list, service_compare);
8398 static enum connman_service_type convert_network_type(struct connman_network *network)
8400 enum connman_network_type type = connman_network_get_type(network);
8403 case CONNMAN_NETWORK_TYPE_UNKNOWN:
8404 case CONNMAN_NETWORK_TYPE_VENDOR:
8406 case CONNMAN_NETWORK_TYPE_ETHERNET:
8407 return CONNMAN_SERVICE_TYPE_ETHERNET;
8408 case CONNMAN_NETWORK_TYPE_WIFI:
8409 return CONNMAN_SERVICE_TYPE_WIFI;
8410 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
8411 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
8412 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
8413 case CONNMAN_NETWORK_TYPE_CELLULAR:
8414 return CONNMAN_SERVICE_TYPE_CELLULAR;
8415 case CONNMAN_NETWORK_TYPE_GADGET:
8416 return CONNMAN_SERVICE_TYPE_GADGET;
8419 return CONNMAN_SERVICE_TYPE_UNKNOWN;
8422 static enum connman_service_security convert_wifi_security(const char *security)
8425 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8426 else if (g_str_equal(security, "none"))
8427 return CONNMAN_SERVICE_SECURITY_NONE;
8428 else if (g_str_equal(security, "wep"))
8429 return CONNMAN_SERVICE_SECURITY_WEP;
8430 else if (g_str_equal(security, "psk"))
8431 return CONNMAN_SERVICE_SECURITY_PSK;
8432 else if (g_str_equal(security, "ieee8021x"))
8433 return CONNMAN_SERVICE_SECURITY_8021X;
8434 else if (g_str_equal(security, "wpa"))
8435 return CONNMAN_SERVICE_SECURITY_WPA;
8436 else if (g_str_equal(security, "rsn"))
8437 return CONNMAN_SERVICE_SECURITY_RSN;
8438 #if defined TIZEN_EXT
8439 else if (g_str_equal(security, "ft_psk") == TRUE)
8440 return CONNMAN_SERVICE_SECURITY_PSK;
8441 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
8442 return CONNMAN_SERVICE_SECURITY_8021X;
8445 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8448 static void update_from_network(struct connman_service *service,
8449 struct connman_network *network)
8451 uint8_t strength = service->strength;
8454 DBG("service %p network %p", service, network);
8456 if (is_connected(service))
8459 if (is_connecting(service))
8462 str = connman_network_get_string(network, "Name");
8464 g_free(service->name);
8465 service->name = g_strdup(str);
8466 service->hidden = false;
8468 g_free(service->name);
8469 service->name = NULL;
8470 service->hidden = true;
8473 service->strength = connman_network_get_strength(network);
8474 service->roaming = connman_network_get_bool(network, "Roaming");
8476 if (service->strength == 0) {
8478 * Filter out 0-values; it's unclear what they mean
8479 * and they cause anomalous sorting of the priority list.
8481 service->strength = strength;
8484 str = connman_network_get_string(network, "WiFi.Security");
8485 service->security = convert_wifi_security(str);
8487 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
8488 service->wps = connman_network_get_bool(network, "WiFi.WPS");
8490 if (service->strength > strength && service->network) {
8491 connman_network_unref(service->network);
8492 service->network = connman_network_ref(network);
8494 strength_changed(service);
8497 if (!service->network)
8498 service->network = connman_network_ref(network);
8500 service_list_sort();
8504 * __connman_service_create_from_network:
8505 * @network: network structure
8507 * Look up service by network and if not found, create one
8509 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
8511 struct connman_service *service;
8512 struct connman_device *device;
8513 const char *ident, *group;
8515 unsigned int *auto_connect_types;
8518 DBG("network %p", network);
8523 ident = __connman_network_get_ident(network);
8527 group = connman_network_get_group(network);
8531 name = g_strdup_printf("%s_%s_%s",
8532 __connman_network_get_type(network), ident, group);
8533 service = service_get(name);
8539 if (__connman_network_get_weakness(network))
8542 if (service->path) {
8543 update_from_network(service, network);
8544 __connman_connection_update_gateway();
8548 service->type = convert_network_type(network);
8550 auto_connect_types = connman_setting_get_uint_list("DefaultAutoConnectTechnologies");
8551 service->autoconnect = false;
8552 for (i = 0; auto_connect_types &&
8553 auto_connect_types[i] != 0; i++) {
8554 if (service->type == auto_connect_types[i]) {
8555 service->autoconnect = true;
8560 switch (service->type) {
8561 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8562 case CONNMAN_SERVICE_TYPE_SYSTEM:
8563 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8564 case CONNMAN_SERVICE_TYPE_GPS:
8565 case CONNMAN_SERVICE_TYPE_VPN:
8566 case CONNMAN_SERVICE_TYPE_GADGET:
8567 case CONNMAN_SERVICE_TYPE_WIFI:
8568 case CONNMAN_SERVICE_TYPE_CELLULAR:
8569 case CONNMAN_SERVICE_TYPE_P2P:
8571 case CONNMAN_SERVICE_TYPE_ETHERNET:
8572 service->favorite = true;
8576 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
8577 service->state = combine_state(service->state_ipv4, service->state_ipv6);
8579 update_from_network(service, network);
8581 index = connman_network_get_index(network);
8583 if (!service->ipconfig_ipv4)
8584 service->ipconfig_ipv4 = create_ip4config(service, index,
8585 CONNMAN_IPCONFIG_METHOD_DHCP);
8587 if (!service->ipconfig_ipv6)
8588 service->ipconfig_ipv6 = create_ip6config(service, index);
8590 service_register(service);
8592 if (service->favorite) {
8593 device = connman_network_get_device(service->network);
8594 if (device && !connman_device_get_scanning(device)) {
8596 switch (service->type) {
8597 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8598 case CONNMAN_SERVICE_TYPE_SYSTEM:
8599 case CONNMAN_SERVICE_TYPE_P2P:
8602 case CONNMAN_SERVICE_TYPE_GADGET:
8603 case CONNMAN_SERVICE_TYPE_ETHERNET:
8604 if (service->autoconnect) {
8605 __connman_service_connect(service,
8606 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
8611 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8612 case CONNMAN_SERVICE_TYPE_GPS:
8613 case CONNMAN_SERVICE_TYPE_VPN:
8614 case CONNMAN_SERVICE_TYPE_WIFI:
8615 case CONNMAN_SERVICE_TYPE_CELLULAR:
8616 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
8621 #if defined TIZEN_EXT
8622 /* TIZEN synchronizes below information when the service creates */
8623 if (service->eap != NULL)
8624 connman_network_set_string(service->network, "WiFi.EAP",
8626 if (service->identity != NULL)
8627 connman_network_set_string(service->network, "WiFi.Identity",
8629 if (service->phase2 != NULL)
8630 connman_network_set_string(service->network, "WiFi.Phase2",
8635 __connman_notifier_service_add(service, service->name);
8636 service_schedule_added(service);
8641 void __connman_service_update_from_network(struct connman_network *network)
8643 bool need_sort = false;
8644 struct connman_service *service;
8650 service = connman_service_lookup_from_network(network);
8654 if (!service->network)
8657 #if defined TIZEN_EXT
8658 if (service->storage_reload) {
8659 service_load(service);
8660 __connman_service_set_storage_reload(service, false);
8664 name = connman_network_get_string(service->network, "Name");
8665 if (g_strcmp0(service->name, name) != 0) {
8666 g_free(service->name);
8667 service->name = g_strdup(name);
8669 if (allow_property_changed(service))
8670 connman_dbus_property_changed_basic(service->path,
8671 CONNMAN_SERVICE_INTERFACE, "Name",
8672 DBUS_TYPE_STRING, &service->name);
8675 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
8676 service->wps = connman_network_get_bool(network, "WiFi.WPS");
8678 strength = connman_network_get_strength(service->network);
8679 if (strength == service->strength)
8682 service->strength = strength;
8685 strength_changed(service);
8688 roaming = connman_network_get_bool(service->network, "Roaming");
8689 if (roaming == service->roaming)
8692 stats_enable = stats_enabled(service);
8694 stats_stop(service);
8696 service->roaming = roaming;
8700 stats_start(service);
8702 roaming_changed(service);
8706 service_list_sort();
8710 void __connman_service_remove_from_network(struct connman_network *network)
8712 struct connman_service *service;
8714 service = connman_service_lookup_from_network(network);
8716 DBG("network %p service %p", network, service);
8721 service->ignore = true;
8723 __connman_connection_gateway_remove(service,
8724 CONNMAN_IPCONFIG_TYPE_ALL);
8726 connman_service_unref(service);
8730 * __connman_service_create_from_provider:
8731 * @provider: provider structure
8733 * Look up service by provider and if not found, create one
8735 struct connman_service *
8736 __connman_service_create_from_provider(struct connman_provider *provider)
8738 struct connman_service *service;
8739 const char *ident, *str;
8741 int index = connman_provider_get_index(provider);
8743 DBG("provider %p", provider);
8745 ident = __connman_provider_get_ident(provider);
8749 name = g_strdup_printf("vpn_%s", ident);
8750 service = service_get(name);
8756 service->type = CONNMAN_SERVICE_TYPE_VPN;
8757 service->provider = connman_provider_ref(provider);
8758 service->autoconnect = false;
8759 service->favorite = true;
8761 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
8762 service->state = combine_state(service->state_ipv4, service->state_ipv6);
8764 str = connman_provider_get_string(provider, "Name");
8766 g_free(service->name);
8767 service->name = g_strdup(str);
8768 service->hidden = false;
8770 g_free(service->name);
8771 service->name = NULL;
8772 service->hidden = true;
8775 service->strength = 0;
8777 if (!service->ipconfig_ipv4)
8778 service->ipconfig_ipv4 = create_ip4config(service, index,
8779 CONNMAN_IPCONFIG_METHOD_MANUAL);
8781 if (!service->ipconfig_ipv6)
8782 service->ipconfig_ipv6 = create_ip6config(service, index);
8784 service_register(service);
8786 __connman_notifier_service_add(service, service->name);
8787 service_schedule_added(service);
8792 static void remove_unprovisioned_services(void)
8795 GKeyFile *keyfile, *configkeyfile;
8796 char *file, *section;
8799 services = connman_storage_get_services();
8803 for (; services[i]; i++) {
8804 file = section = NULL;
8805 keyfile = configkeyfile = NULL;
8807 keyfile = connman_storage_load_service(services[i]);
8811 file = g_key_file_get_string(keyfile, services[i],
8812 "Config.file", NULL);
8816 section = g_key_file_get_string(keyfile, services[i],
8817 "Config.ident", NULL);
8821 configkeyfile = __connman_storage_load_config(file);
8822 if (!configkeyfile) {
8824 * Config file is missing, remove the provisioned
8827 __connman_storage_remove_service(services[i]);
8831 if (!g_key_file_has_group(configkeyfile, section))
8833 * Config section is missing, remove the provisioned
8836 __connman_storage_remove_service(services[i]);
8840 g_key_file_free(keyfile);
8843 g_key_file_free(configkeyfile);
8849 g_strfreev(services);
8852 static int agent_probe(struct connman_agent *agent)
8854 DBG("agent %p", agent);
8858 static void agent_remove(struct connman_agent *agent)
8860 DBG("agent %p", agent);
8863 static void *agent_context_ref(void *context)
8865 struct connman_service *service = context;
8867 return (void *)connman_service_ref(service);
8870 static void agent_context_unref(void *context)
8872 struct connman_service *service = context;
8874 connman_service_unref(service);
8877 static struct connman_agent_driver agent_driver = {
8879 .interface = CONNMAN_AGENT_INTERFACE,
8880 .probe = agent_probe,
8881 .remove = agent_remove,
8882 .context_ref = agent_context_ref,
8883 .context_unref = agent_context_unref,
8886 int __connman_service_init(void)
8892 err = connman_agent_driver_register(&agent_driver);
8894 connman_error("Cannot register agent driver for %s",
8899 connection = connman_dbus_get_connection();
8901 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
8902 NULL, service_free);
8904 services_notify = g_new0(struct _services_notify, 1);
8905 services_notify->remove = g_hash_table_new_full(g_str_hash,
8906 g_str_equal, g_free, NULL);
8907 services_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
8909 remove_unprovisioned_services();
8914 void __connman_service_cleanup(void)
8918 if (vpn_autoconnect_timeout) {
8919 g_source_remove(vpn_autoconnect_timeout);
8920 vpn_autoconnect_timeout = 0;
8923 if (autoconnect_timeout != 0) {
8924 g_source_remove(autoconnect_timeout);
8925 autoconnect_timeout = 0;
8928 connman_agent_driver_unregister(&agent_driver);
8930 g_list_free(service_list);
8931 service_list = NULL;
8933 g_hash_table_destroy(service_hash);
8934 service_hash = NULL;
8936 g_slist_free(counter_list);
8937 counter_list = NULL;
8939 if (services_notify->id != 0) {
8940 g_source_remove(services_notify->id);
8941 service_send_changed(NULL);
8942 g_hash_table_destroy(services_notify->remove);
8943 g_hash_table_destroy(services_notify->add);
8945 g_free(services_notify);
8947 dbus_connection_unref(connection);