5 * Copyright (C) 2007-2014 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 #include <connman/storage.h>
37 #include <connman/setting.h>
38 #include <connman/agent.h>
42 #define CONNECT_TIMEOUT 120
45 #define USER_NONE (uid_t)-1
48 #define WIFI_BSSID_STR_LEN 18
51 static DBusConnection *connection = NULL;
53 static GList *service_list = NULL;
54 static GHashTable *service_hash = NULL;
55 static GSList *counter_list = NULL;
56 static unsigned int autoconnect_timeout = 0;
57 static unsigned int vpn_autoconnect_timeout = 0;
58 static struct connman_service *current_default = NULL;
59 static bool services_dirty = false;
62 static bool auto_connect_mode = TRUE;
65 struct connman_stats {
68 struct connman_stats_data data_last;
69 struct connman_stats_data data;
73 struct connman_stats_counter {
75 struct connman_stats stats;
76 struct connman_stats stats_roaming;
79 struct connman_service_user {
84 struct connman_service {
88 enum connman_service_type type;
89 enum connman_service_security security;
90 enum connman_service_state state;
91 enum connman_service_state state_ipv4;
92 enum connman_service_state state_ipv6;
93 enum connman_service_error error;
94 enum connman_service_connect_reason connect_reason;
106 bool request_passphrase_input;
107 struct connman_service_user user;
108 struct connman_ipconfig *ipconfig_ipv4;
109 struct connman_ipconfig *ipconfig_ipv6;
110 struct connman_network *network;
111 struct connman_provider *provider;
113 char **nameservers_config;
114 char **nameservers_auto;
119 char **timeservers_config;
120 /* 802.1x settings from the config files */
123 char *agent_identity;
125 char *client_cert_file;
126 char *private_key_file;
127 char *private_key_passphrase;
129 DBusMessage *pending;
130 DBusMessage *provider_pending;
132 struct connman_stats stats;
133 struct connman_stats stats_roaming;
134 GHashTable *counter_table;
135 enum connman_service_proxy_method proxy;
136 enum connman_service_proxy_method proxy_config;
141 int online_check_count;
142 bool do_split_routing;
147 #if defined TIZEN_EXT
149 * Description: TIZEN implements system global connection management.
150 * It's only for PDP (cellular) bearer. Wi-Fi is managed
151 * by ConnMan automatically. Reference count can help to
152 * manage open/close connection requests by each application.
154 int user_pdn_connection_refcount;
157 * Description: In case of EAP security type,
158 * user can select the keymgmt type for roaming(802.11r).
159 * - FT, CCKM, OKC, ...
162 int disconnect_reason;
165 enum connman_dnsconfig_method dns_config_method_ipv4;
166 enum connman_dnsconfig_method dns_config_method_ipv6;
170 static bool allow_property_changed(struct connman_service *service);
172 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
173 int index, enum connman_ipconfig_method method);
174 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
180 struct connman_service *service;
183 #if defined TIZEN_EXT
185 * Public APIs to use user_pdn_connection_refcount
187 void connman_service_user_pdn_connection_ref(struct connman_service *service)
189 __sync_fetch_and_add(&service->user_pdn_connection_refcount, 1);
191 DBG("User made PDN connection referenced: %d",
192 service->user_pdn_connection_refcount);
195 gboolean connman_service_user_pdn_connection_unref_and_test(
196 struct connman_service *service)
198 __sync_synchronize();
200 DBG("User made PDN connection referenced: %d, which will be decreased",
201 service->user_pdn_connection_refcount);
203 if (service->user_pdn_connection_refcount < 1)
206 if (__sync_sub_and_fetch(&service->user_pdn_connection_refcount, 1) == 0)
212 gboolean connman_service_is_no_ref_user_pdn_connection(
213 struct connman_service *cellular)
215 if (cellular == NULL)
218 __sync_synchronize();
219 if (cellular->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
220 cellular->user_pdn_connection_refcount == 0)
227 static void compare_path(gpointer value, gpointer user_data)
229 struct connman_service *service = value;
230 struct find_data *data = user_data;
235 if (g_strcmp0(service->path, data->path) == 0)
236 data->service = service;
239 static struct connman_service *find_service(const char *path)
241 struct find_data data = { .path = path, .service = NULL };
243 DBG("path %s", path);
245 g_list_foreach(service_list, compare_path, &data);
250 static const char *reason2string(enum connman_service_connect_reason reason)
254 case CONNMAN_SERVICE_CONNECT_REASON_NONE:
256 case CONNMAN_SERVICE_CONNECT_REASON_USER:
258 case CONNMAN_SERVICE_CONNECT_REASON_AUTO:
260 case CONNMAN_SERVICE_CONNECT_REASON_SESSION:
267 const char *__connman_service_type2string(enum connman_service_type type)
270 case CONNMAN_SERVICE_TYPE_UNKNOWN:
272 case CONNMAN_SERVICE_TYPE_SYSTEM:
274 case CONNMAN_SERVICE_TYPE_ETHERNET:
276 case CONNMAN_SERVICE_TYPE_WIFI:
278 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
280 case CONNMAN_SERVICE_TYPE_CELLULAR:
282 case CONNMAN_SERVICE_TYPE_GPS:
284 case CONNMAN_SERVICE_TYPE_VPN:
286 case CONNMAN_SERVICE_TYPE_GADGET:
288 case CONNMAN_SERVICE_TYPE_P2P:
295 enum connman_service_type __connman_service_string2type(const char *str)
298 return CONNMAN_SERVICE_TYPE_UNKNOWN;
300 if (strcmp(str, "ethernet") == 0)
301 return CONNMAN_SERVICE_TYPE_ETHERNET;
302 if (strcmp(str, "gadget") == 0)
303 return CONNMAN_SERVICE_TYPE_GADGET;
304 if (strcmp(str, "wifi") == 0)
305 return CONNMAN_SERVICE_TYPE_WIFI;
306 if (strcmp(str, "cellular") == 0)
307 return CONNMAN_SERVICE_TYPE_CELLULAR;
308 if (strcmp(str, "bluetooth") == 0)
309 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
310 if (strcmp(str, "vpn") == 0)
311 return CONNMAN_SERVICE_TYPE_VPN;
312 if (strcmp(str, "gps") == 0)
313 return CONNMAN_SERVICE_TYPE_GPS;
314 if (strcmp(str, "system") == 0)
315 return CONNMAN_SERVICE_TYPE_SYSTEM;
316 if (strcmp(str, "p2p") == 0)
317 return CONNMAN_SERVICE_TYPE_P2P;
319 return CONNMAN_SERVICE_TYPE_UNKNOWN;
322 enum connman_service_security __connman_service_string2security(const char *str)
325 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
327 if (!strcmp(str, "psk"))
328 return CONNMAN_SERVICE_SECURITY_PSK;
329 if (!strcmp(str, "ieee8021x"))
330 return CONNMAN_SERVICE_SECURITY_8021X;
331 if (!strcmp(str, "none"))
332 return CONNMAN_SERVICE_SECURITY_NONE;
333 if (!strcmp(str, "wep"))
334 return CONNMAN_SERVICE_SECURITY_WEP;
335 #if defined TIZEN_EXT
336 if (!strcmp(str, "rsn"))
337 return CONNMAN_SERVICE_SECURITY_RSN;
340 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
343 static const char *security2string(enum connman_service_security security)
346 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
348 case CONNMAN_SERVICE_SECURITY_NONE:
350 case CONNMAN_SERVICE_SECURITY_WEP:
352 case CONNMAN_SERVICE_SECURITY_PSK:
353 case CONNMAN_SERVICE_SECURITY_WPA:
354 #if defined TIZEN_EXT
356 case CONNMAN_SERVICE_SECURITY_RSN:
359 case CONNMAN_SERVICE_SECURITY_RSN:
362 case CONNMAN_SERVICE_SECURITY_8021X:
369 static const char *state2string(enum connman_service_state state)
372 case CONNMAN_SERVICE_STATE_UNKNOWN:
374 case CONNMAN_SERVICE_STATE_IDLE:
376 case CONNMAN_SERVICE_STATE_ASSOCIATION:
377 return "association";
378 case CONNMAN_SERVICE_STATE_CONFIGURATION:
379 return "configuration";
380 case CONNMAN_SERVICE_STATE_READY:
382 case CONNMAN_SERVICE_STATE_ONLINE:
384 case CONNMAN_SERVICE_STATE_DISCONNECT:
386 case CONNMAN_SERVICE_STATE_FAILURE:
393 static const char *error2string(enum connman_service_error error)
396 case CONNMAN_SERVICE_ERROR_UNKNOWN:
398 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
399 return "out-of-range";
400 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
401 return "pin-missing";
402 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
403 return "dhcp-failed";
404 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
405 return "connect-failed";
406 case CONNMAN_SERVICE_ERROR_LOGIN_FAILED:
407 return "login-failed";
408 case CONNMAN_SERVICE_ERROR_AUTH_FAILED:
409 return "auth-failed";
410 case CONNMAN_SERVICE_ERROR_INVALID_KEY:
411 return "invalid-key";
412 case CONNMAN_SERVICE_ERROR_BLOCKED:
419 static const char *proxymethod2string(enum connman_service_proxy_method method)
422 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
424 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
426 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
428 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
435 static enum connman_service_proxy_method string2proxymethod(const char *method)
437 if (g_strcmp0(method, "direct") == 0)
438 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
439 else if (g_strcmp0(method, "auto") == 0)
440 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
441 else if (g_strcmp0(method, "manual") == 0)
442 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
444 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
448 static const char *__connman_dnsconfig_method2string(enum connman_dnsconfig_method method)
451 case CONNMAN_DNSCONFIG_METHOD_UNKNOWN:
453 case CONNMAN_DNSCONFIG_METHOD_MANUAL:
455 case CONNMAN_DNSCONFIG_METHOD_DHCP:
462 static enum connman_dnsconfig_method __connman_dnsconfig_string2method(
465 if (g_strcmp0(method, "manual") == 0)
466 return CONNMAN_DNSCONFIG_METHOD_MANUAL;
467 else if (g_strcmp0(method, "dhcp") == 0)
468 return CONNMAN_DNSCONFIG_METHOD_DHCP;
470 return CONNMAN_DNSCONFIG_METHOD_UNKNOWN;
475 connman_service_is_user_allowed(struct connman_service *service, uid_t uid)
477 uid_t favorite_user = service->user.favorite_user;
478 uid_t current_user = uid;
480 DBG("Service favorite UID: %d, current UID: %d", favorite_user, current_user);
481 if (favorite_user == USER_NONE || current_user == USER_ROOT)
484 if (favorite_user != current_user || current_user == USER_NONE) {
485 DBG("Current user is not a favorite user to this service!");
492 #if !defined TIZEN_EXT
493 static GList *connman_service_get_login_users()
497 GList *user_list = NULL;
501 while ((utmp = getutxent()) != NULL) {
502 DBG("User Name: %s", utmp->ut_user);
504 pwd = getpwnam(utmp->ut_user);
506 if (!g_list_find(user_list, GUINT_TO_POINTER(pwd->pw_uid)))
507 user_list = g_list_append(user_list,
508 GUINT_TO_POINTER(pwd->pw_uid));
510 DBG("User Name: %s, UID: %d", utmp->ut_user, pwd->pw_uid);
520 static bool is_service_owner_user_login(struct connman_service *service)
522 #if defined TIZEN_EXT
525 GList *list, *user_list;
528 /* Here we only care about wifi service */
529 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
532 DBG("service favorite user id is: %d", service->user.favorite_user);
534 user_list = connman_service_get_login_users();
535 if (user_list == NULL) {
536 DBG("Can not get any logged in user info.");
540 for (list = user_list; list; list = list->next) {
541 uid_t uid = GPOINTER_TO_UINT(list->data);
543 DBG("login user id is %d", uid);
545 if (service->user.favorite_user == uid) {
551 g_list_free(user_list);
557 int __connman_service_load_modifiable(struct connman_service *service)
560 GError *error = NULL;
564 DBG("service %p", service);
566 keyfile = connman_storage_load_service(service->identifier);
570 switch (service->type) {
571 case CONNMAN_SERVICE_TYPE_UNKNOWN:
572 case CONNMAN_SERVICE_TYPE_SYSTEM:
573 case CONNMAN_SERVICE_TYPE_GPS:
574 case CONNMAN_SERVICE_TYPE_P2P:
576 case CONNMAN_SERVICE_TYPE_VPN:
577 service->do_split_routing = g_key_file_get_boolean(keyfile,
578 service->identifier, "SplitRouting", NULL);
580 case CONNMAN_SERVICE_TYPE_WIFI:
581 case CONNMAN_SERVICE_TYPE_GADGET:
582 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
583 case CONNMAN_SERVICE_TYPE_CELLULAR:
584 case CONNMAN_SERVICE_TYPE_ETHERNET:
585 autoconnect = g_key_file_get_boolean(keyfile,
586 service->identifier, "AutoConnect", &error);
588 service->autoconnect = autoconnect;
589 g_clear_error(&error);
593 str = g_key_file_get_string(keyfile,
594 service->identifier, "Modified", NULL);
596 g_time_val_from_iso8601(str, &service->modified);
600 g_key_file_free(keyfile);
605 static int service_load_passphrase(struct connman_service *service)
610 keyfile = connman_storage_load_service(service->identifier);
614 str = g_key_file_get_string(keyfile,
615 service->identifier, "Passphrase", NULL);
617 service->passphrase = str;
619 g_key_file_free(keyfile);
624 static int service_load(struct connman_service *service)
627 GError *error = NULL;
631 unsigned int ssid_len;
634 DBG("service %p", service);
636 keyfile = connman_storage_load_service(service->identifier);
638 service->new_service = true;
641 service->new_service = false;
643 switch (service->type) {
644 case CONNMAN_SERVICE_TYPE_UNKNOWN:
645 case CONNMAN_SERVICE_TYPE_SYSTEM:
646 case CONNMAN_SERVICE_TYPE_GPS:
647 case CONNMAN_SERVICE_TYPE_P2P:
649 case CONNMAN_SERVICE_TYPE_VPN:
650 service->do_split_routing = g_key_file_get_boolean(keyfile,
651 service->identifier, "SplitRouting", NULL);
652 autoconnect = g_key_file_get_boolean(keyfile,
653 service->identifier, "AutoConnect", &error);
655 service->autoconnect = autoconnect;
656 g_clear_error(&error);
658 case CONNMAN_SERVICE_TYPE_WIFI:
659 if (!service->name) {
662 name = g_key_file_get_string(keyfile,
663 service->identifier, "Name", NULL);
665 g_free(service->name);
666 service->name = name;
669 if (service->network)
670 connman_network_set_name(service->network,
674 if (service->network &&
675 !connman_network_get_blob(service->network,
676 "WiFi.SSID", &ssid_len)) {
679 hex_ssid = g_key_file_get_string(keyfile,
685 unsigned int i, j = 0, hex;
686 size_t hex_ssid_len = strlen(hex_ssid);
688 ssid = g_try_malloc0(hex_ssid_len / 2);
695 for (i = 0; i < hex_ssid_len; i += 2) {
696 sscanf(hex_ssid + i, "%02x", &hex);
700 connman_network_set_blob(service->network,
701 "WiFi.SSID", ssid, hex_ssid_len / 2);
710 case CONNMAN_SERVICE_TYPE_GADGET:
711 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
712 case CONNMAN_SERVICE_TYPE_CELLULAR:
713 service->favorite = g_key_file_get_boolean(keyfile,
714 service->identifier, "Favorite", NULL);
718 case CONNMAN_SERVICE_TYPE_ETHERNET:
719 autoconnect = g_key_file_get_boolean(keyfile,
720 service->identifier, "AutoConnect", &error);
722 service->autoconnect = autoconnect;
723 g_clear_error(&error);
727 str = g_key_file_get_string(keyfile,
728 service->identifier, "Modified", NULL);
730 g_time_val_from_iso8601(str, &service->modified);
734 str = g_key_file_get_string(keyfile,
735 service->identifier, "Passphrase", NULL);
737 g_free(service->passphrase);
738 service->passphrase = str;
741 if (service->ipconfig_ipv4)
742 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
743 service->identifier, "IPv4.");
745 if (service->ipconfig_ipv6)
746 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
747 service->identifier, "IPv6.");
749 service->nameservers_config = g_key_file_get_string_list(keyfile,
750 service->identifier, "Nameservers", &length, NULL);
751 if (service->nameservers_config && length == 0) {
752 g_strfreev(service->nameservers_config);
753 service->nameservers_config = NULL;
759 dns_method = g_key_file_get_string(keyfile, service->identifier,
760 "Nameservers.IPv4method", NULL);
761 service->dns_config_method_ipv4 = __connman_dnsconfig_string2method(dns_method);
763 dns_method = g_key_file_get_string(keyfile, service->identifier,
764 "Nameservers.IPv6method", NULL);
765 service->dns_config_method_ipv6 = __connman_dnsconfig_string2method(dns_method);
768 service->timeservers_config = g_key_file_get_string_list(keyfile,
769 service->identifier, "Timeservers", &length, NULL);
770 if (service->timeservers_config && length == 0) {
771 g_strfreev(service->timeservers_config);
772 service->timeservers_config = NULL;
775 service->domains = g_key_file_get_string_list(keyfile,
776 service->identifier, "Domains", &length, NULL);
777 if (service->domains && length == 0) {
778 g_strfreev(service->domains);
779 service->domains = NULL;
782 str = g_key_file_get_string(keyfile,
783 service->identifier, "Proxy.Method", NULL);
785 service->proxy_config = string2proxymethod(str);
789 service->proxies = g_key_file_get_string_list(keyfile,
790 service->identifier, "Proxy.Servers", &length, NULL);
791 if (service->proxies && length == 0) {
792 g_strfreev(service->proxies);
793 service->proxies = NULL;
796 service->excludes = g_key_file_get_string_list(keyfile,
797 service->identifier, "Proxy.Excludes", &length, NULL);
798 if (service->excludes && length == 0) {
799 g_strfreev(service->excludes);
800 service->excludes = NULL;
803 str = g_key_file_get_string(keyfile,
804 service->identifier, "Proxy.URL", NULL);
806 g_free(service->pac);
810 service->hidden_service = g_key_file_get_boolean(keyfile,
811 service->identifier, "Hidden", NULL);
813 #if defined TIZEN_EXT
814 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
815 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
816 str = g_key_file_get_string(keyfile,
817 service->identifier, "EAP", NULL);
819 g_free(service->eap);
823 str = g_key_file_get_string(keyfile,
824 service->identifier, "Phase2", NULL);
826 g_free(service->phase2);
827 service->phase2 = str;
830 str = g_key_file_get_string(keyfile,
831 service->identifier, "Identity", NULL);
833 g_free(service->identity);
834 service->identity = str;
837 str = g_key_file_get_string(keyfile,
838 service->identifier, "CACertFile", NULL);
840 g_free(service->ca_cert_file);
841 service->ca_cert_file = str;
844 str = g_key_file_get_string(keyfile,
845 service->identifier, "ClientCertFile", NULL);
847 g_free(service->client_cert_file);
848 service->client_cert_file = str;
851 str = g_key_file_get_string(keyfile,
852 service->identifier, "PrivateKeyFile", NULL);
854 g_free(service->private_key_file);
855 service->private_key_file = str;
858 str = g_key_file_get_string(keyfile,
859 service->identifier, "PrivateKeyPassphrase", NULL);
861 g_free(service->private_key_passphrase);
862 service->private_key_passphrase = str;
867 if (g_key_file_has_key(keyfile, service->identifier, "UID", NULL))
868 service->user.favorite_user = g_key_file_get_integer(keyfile,
869 service->identifier, "UID", NULL);
871 g_key_file_free(keyfile);
876 static int service_save(struct connman_service *service)
881 const char *cst_str = NULL;
884 DBG("service %p new %d", service, service->new_service);
886 if (service->new_service)
889 keyfile = __connman_storage_open_service(service->identifier);
894 g_key_file_set_string(keyfile, service->identifier,
895 "Name", service->name);
897 switch (service->type) {
898 case CONNMAN_SERVICE_TYPE_UNKNOWN:
899 case CONNMAN_SERVICE_TYPE_SYSTEM:
900 case CONNMAN_SERVICE_TYPE_GPS:
901 case CONNMAN_SERVICE_TYPE_P2P:
903 case CONNMAN_SERVICE_TYPE_VPN:
904 g_key_file_set_boolean(keyfile, service->identifier,
905 "SplitRouting", service->do_split_routing);
906 if (service->favorite)
907 g_key_file_set_boolean(keyfile, service->identifier,
908 "AutoConnect", service->autoconnect);
910 case CONNMAN_SERVICE_TYPE_WIFI:
911 if (service->network) {
912 const unsigned char *ssid;
913 unsigned int ssid_len = 0;
915 if (service->user.favorite_user == USER_NONE)
916 g_key_file_remove_key(keyfile, service->identifier,
919 g_key_file_set_integer(keyfile, service->identifier,
920 "UID", service->user.favorite_user);
922 ssid = connman_network_get_blob(service->network,
923 "WiFi.SSID", &ssid_len);
925 if (ssid && ssid_len > 0 && ssid[0] != '\0') {
926 char *identifier = service->identifier;
930 ssid_str = g_string_sized_new(ssid_len * 2);
936 for (i = 0; i < ssid_len; i++)
937 g_string_append_printf(ssid_str,
940 g_key_file_set_string(keyfile, identifier,
941 "SSID", ssid_str->str);
943 g_string_free(ssid_str, TRUE);
946 freq = connman_network_get_frequency(service->network);
947 g_key_file_set_integer(keyfile, service->identifier,
952 case CONNMAN_SERVICE_TYPE_GADGET:
953 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
954 case CONNMAN_SERVICE_TYPE_CELLULAR:
955 g_key_file_set_boolean(keyfile, service->identifier,
956 "Favorite", service->favorite);
958 g_key_file_remove_key(keyfile, service->identifier,
963 case CONNMAN_SERVICE_TYPE_ETHERNET:
964 if (service->favorite)
965 g_key_file_set_boolean(keyfile, service->identifier,
966 "AutoConnect", service->autoconnect);
970 str = g_time_val_to_iso8601(&service->modified);
972 g_key_file_set_string(keyfile, service->identifier,
977 if (service->user.current_user == service->user.favorite_user) {
978 if (service->passphrase && strlen(service->passphrase) > 0)
979 g_key_file_set_string(keyfile, service->identifier,
980 "Passphrase", service->passphrase);
982 g_key_file_remove_key(keyfile, service->identifier,
986 if (service->ipconfig_ipv4)
987 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
988 service->identifier, "IPv4.");
990 if (service->ipconfig_ipv6)
991 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
992 service->identifier, "IPv6.");
994 if (service->nameservers_config) {
995 guint len = g_strv_length(service->nameservers_config);
997 g_key_file_set_string_list(keyfile, service->identifier,
999 (const gchar **) service->nameservers_config, len);
1001 g_key_file_remove_key(keyfile, service->identifier,
1002 "Nameservers", NULL);
1004 #if defined TIZEN_EXT
1005 if(service->dns_config_method_ipv4 != 0) {
1007 method = __connman_dnsconfig_method2string(
1008 service->dns_config_method_ipv4);
1009 g_key_file_set_string(keyfile, service->identifier,
1010 "Nameservers.IPv4method", method);
1012 g_key_file_remove_key(keyfile, service->identifier,
1013 "Nameservers.IPv4method", NULL);
1015 if(service->dns_config_method_ipv6 != 0) {
1017 method = __connman_dnsconfig_method2string(
1018 service->dns_config_method_ipv6);
1019 g_key_file_set_string(keyfile, service->identifier,
1020 "Nameservers.IPv6method", method);
1022 g_key_file_remove_key(keyfile, service->identifier,
1023 "Nameservers.IPv6method", NULL);
1026 if (service->timeservers_config) {
1027 guint len = g_strv_length(service->timeservers_config);
1029 g_key_file_set_string_list(keyfile, service->identifier,
1031 (const gchar **) service->timeservers_config, len);
1033 g_key_file_remove_key(keyfile, service->identifier,
1034 "Timeservers", NULL);
1036 if (service->domains) {
1037 guint len = g_strv_length(service->domains);
1039 g_key_file_set_string_list(keyfile, service->identifier,
1041 (const gchar **) service->domains, len);
1043 g_key_file_remove_key(keyfile, service->identifier,
1046 cst_str = proxymethod2string(service->proxy_config);
1048 g_key_file_set_string(keyfile, service->identifier,
1049 "Proxy.Method", cst_str);
1051 if (service->proxies) {
1052 guint len = g_strv_length(service->proxies);
1054 g_key_file_set_string_list(keyfile, service->identifier,
1056 (const gchar **) service->proxies, len);
1058 g_key_file_remove_key(keyfile, service->identifier,
1059 "Proxy.Servers", NULL);
1061 if (service->excludes) {
1062 guint len = g_strv_length(service->excludes);
1064 g_key_file_set_string_list(keyfile, service->identifier,
1066 (const gchar **) service->excludes, len);
1068 g_key_file_remove_key(keyfile, service->identifier,
1069 "Proxy.Excludes", NULL);
1071 if (service->pac && strlen(service->pac) > 0)
1072 g_key_file_set_string(keyfile, service->identifier,
1073 "Proxy.URL", service->pac);
1075 g_key_file_remove_key(keyfile, service->identifier,
1078 if (service->hidden_service)
1079 g_key_file_set_boolean(keyfile, service->identifier, "Hidden",
1082 if (service->config_file && strlen(service->config_file) > 0)
1083 g_key_file_set_string(keyfile, service->identifier,
1084 "Config.file", service->config_file);
1086 if (service->config_entry &&
1087 strlen(service->config_entry) > 0)
1088 g_key_file_set_string(keyfile, service->identifier,
1089 "Config.ident", service->config_entry);
1091 #if defined TIZEN_EXT
1092 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1093 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
1094 if (service->eap != NULL && strlen(service->eap) > 0)
1095 g_key_file_set_string(keyfile, service->identifier,
1096 "EAP", service->eap);
1098 g_key_file_remove_key(keyfile, service->identifier,
1101 if (service->phase2 != NULL && strlen(service->phase2) > 0)
1102 g_key_file_set_string(keyfile, service->identifier,
1103 "Phase2", service->phase2);
1105 g_key_file_remove_key(keyfile, service->identifier,
1108 if (service->identity != NULL && strlen(service->identity) > 0)
1109 g_key_file_set_string(keyfile, service->identifier,
1110 "Identity", service->identity);
1112 g_key_file_remove_key(keyfile, service->identifier,
1115 if (service->ca_cert_file != NULL && strlen(service->ca_cert_file) > 0)
1116 g_key_file_set_string(keyfile, service->identifier,
1117 "CACertFile", service->ca_cert_file);
1119 g_key_file_remove_key(keyfile, service->identifier,
1120 "CACertFile", NULL);
1122 if (service->client_cert_file != NULL && strlen(service->client_cert_file) > 0)
1123 g_key_file_set_string(keyfile, service->identifier,
1124 "ClientCertFile", service->client_cert_file);
1126 g_key_file_remove_key(keyfile, service->identifier,
1127 "ClientCertFile", NULL);
1129 if (service->private_key_file != NULL && strlen(service->private_key_file) > 0)
1130 g_key_file_set_string(keyfile, service->identifier,
1131 "PrivateKeyFile", service->private_key_file);
1133 g_key_file_remove_key(keyfile, service->identifier,
1134 "PrivateKeyFile", NULL);
1136 if (service->private_key_passphrase != NULL && strlen(service->private_key_passphrase) > 0)
1137 g_key_file_set_string(keyfile, service->identifier,
1138 "PrivateKeyPassphrase", service->private_key_passphrase);
1140 g_key_file_remove_key(keyfile, service->identifier,
1141 "PrivateKeyPassphrase", NULL);
1146 __connman_storage_save_service(keyfile, service->identifier);
1148 g_key_file_free(keyfile);
1153 void __connman_service_save(struct connman_service *service)
1158 service_save(service);
1161 static enum connman_service_state combine_state(
1162 enum connman_service_state state_a,
1163 enum connman_service_state state_b)
1165 enum connman_service_state result;
1167 if (state_a == state_b) {
1172 if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
1177 if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
1182 if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
1187 if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
1192 if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
1197 if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
1202 if (state_a == CONNMAN_SERVICE_STATE_READY) {
1207 if (state_b == CONNMAN_SERVICE_STATE_READY) {
1212 if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1217 if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1222 if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1227 if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1232 if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
1237 if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
1242 result = CONNMAN_SERVICE_STATE_FAILURE;
1248 static bool is_connecting_state(struct connman_service *service,
1249 enum connman_service_state state)
1252 case CONNMAN_SERVICE_STATE_UNKNOWN:
1253 case CONNMAN_SERVICE_STATE_IDLE:
1254 case CONNMAN_SERVICE_STATE_FAILURE:
1255 if (service->network)
1256 return connman_network_get_connecting(service->network);
1257 case CONNMAN_SERVICE_STATE_DISCONNECT:
1258 case CONNMAN_SERVICE_STATE_READY:
1259 case CONNMAN_SERVICE_STATE_ONLINE:
1261 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1262 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1269 static bool is_connected_state(const struct connman_service *service,
1270 enum connman_service_state state)
1273 case CONNMAN_SERVICE_STATE_UNKNOWN:
1274 case CONNMAN_SERVICE_STATE_IDLE:
1275 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1276 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1277 case CONNMAN_SERVICE_STATE_DISCONNECT:
1278 case CONNMAN_SERVICE_STATE_FAILURE:
1280 case CONNMAN_SERVICE_STATE_READY:
1281 case CONNMAN_SERVICE_STATE_ONLINE:
1288 static bool is_idle_state(const struct connman_service *service,
1289 enum connman_service_state state)
1292 case CONNMAN_SERVICE_STATE_UNKNOWN:
1293 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1294 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1295 case CONNMAN_SERVICE_STATE_READY:
1296 case CONNMAN_SERVICE_STATE_ONLINE:
1297 case CONNMAN_SERVICE_STATE_DISCONNECT:
1298 case CONNMAN_SERVICE_STATE_FAILURE:
1300 case CONNMAN_SERVICE_STATE_IDLE:
1307 static bool is_connecting(struct connman_service *service)
1309 return is_connecting_state(service, service->state);
1312 static bool is_connected(struct connman_service *service)
1314 return is_connected_state(service, service->state);
1317 static bool nameserver_available(struct connman_service *service,
1322 family = connman_inet_check_ipaddress(ns);
1324 if (family == AF_INET)
1325 return is_connected_state(service, service->state_ipv4);
1327 if (family == AF_INET6)
1328 return is_connected_state(service, service->state_ipv6);
1333 static int nameserver_add(struct connman_service *service,
1334 const char *nameserver)
1338 if (!nameserver_available(service, nameserver))
1341 index = __connman_service_get_index(service);
1345 #if defined TIZEN_EXT
1346 DBG("Resolver append nameserver: %s", nameserver);
1348 return connman_resolver_append(index, NULL, nameserver);
1351 #if defined TIZEN_EXT
1352 static int nameserver_add_all(struct connman_service *service,
1353 enum connman_ipconfig_type type)
1355 static int nameserver_add_all(struct connman_service *service)
1360 if (service->nameservers_config) {
1361 while (service->nameservers_config[i]) {
1362 #if defined TIZEN_EXT
1363 DBG("type %d add service->nameservers_config[%d]:%s",type,
1364 i, service->nameservers_config[i]);
1365 if(strncmp(service->nameservers_config[i], "::", 2) == 0) {
1366 DBG("Invalid nameserver");
1372 case CONNMAN_IPCONFIG_TYPE_IPV4:
1373 if (connman_inet_check_ipaddress(
1374 service->nameservers_config[i]) == AF_INET &&
1375 service->dns_config_method_ipv4 ==
1376 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1377 nameserver_add(service,
1378 service->nameservers_config[i]);
1381 case CONNMAN_IPCONFIG_TYPE_IPV6:
1382 if (connman_inet_check_ipaddress(
1383 service->nameservers_config[i]) == AF_INET6 &&
1384 service->dns_config_method_ipv6 ==
1385 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1386 nameserver_add(service,
1387 service->nameservers_config[i]);
1390 case CONNMAN_IPCONFIG_TYPE_ALL:
1391 if (connman_inet_check_ipaddress(
1392 service->nameservers_config[i]) == AF_INET &&
1393 service->dns_config_method_ipv4 ==
1394 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1395 nameserver_add(service,
1396 service->nameservers_config[i]);
1398 if (connman_inet_check_ipaddress(
1399 service->nameservers_config[i]) == AF_INET6 &&
1400 service->dns_config_method_ipv6 ==
1401 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
1402 nameserver_add(service,
1403 service->nameservers_config[i]);
1406 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1407 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1410 DBG("default case do nothing");
1414 nameserver_add(service, service->nameservers_config[i]);
1418 #if !defined TIZEN_EXT
1423 #if defined TIZEN_EXT
1426 if (service->nameservers) {
1427 while (service->nameservers[i]) {
1428 #if defined TIZEN_EXT
1429 DBG("type %d service->nameservers[%d]: %s",type,
1430 i, service->nameservers[i]);
1433 case CONNMAN_IPCONFIG_TYPE_IPV4:
1434 if (connman_inet_check_ipaddress(
1435 service->nameservers[i]) == AF_INET &&
1436 service->dns_config_method_ipv4 ==
1437 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1438 nameserver_add(service,
1439 service->nameservers[i]);
1442 case CONNMAN_IPCONFIG_TYPE_IPV6:
1443 if (connman_inet_check_ipaddress(
1444 service->nameservers[i]) == AF_INET6 &&
1445 service->dns_config_method_ipv6 ==
1446 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1447 nameserver_add(service,
1448 service->nameservers[i]);
1451 case CONNMAN_IPCONFIG_TYPE_ALL:
1452 if (connman_inet_check_ipaddress(
1453 service->nameservers[i]) == AF_INET &&
1454 service->dns_config_method_ipv4 ==
1455 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1456 nameserver_add(service,
1457 service->nameservers[i]);
1459 if (connman_inet_check_ipaddress(
1460 service->nameservers[i]) == AF_INET6 &&
1461 service->dns_config_method_ipv6 ==
1462 CONNMAN_DNSCONFIG_METHOD_DHCP) {
1463 nameserver_add(service,
1464 service->nameservers[i]);
1467 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1468 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1471 DBG("default case do nothing");
1475 nameserver_add(service, service->nameservers[i]);
1484 static int nameserver_remove(struct connman_service *service,
1485 const char *nameserver)
1489 if (!nameserver_available(service, nameserver))
1492 index = __connman_service_get_index(service);
1496 #if defined TIZEN_EXT
1497 DBG("Resolver remove nameserver: %s", nameserver);
1499 return connman_resolver_remove(index, NULL, nameserver);
1502 #if defined TIZEN_EXT
1503 static int nameserver_remove_all(struct connman_service *service,
1504 enum connman_ipconfig_type type)
1506 static int nameserver_remove_all(struct connman_service *service)
1509 #if defined TIZEN_EXT
1511 * Skip this function if there is any connected profiles
1512 * that use same interface
1514 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
1515 __connman_service_get_connected_count_of_iface(service) > 0)
1520 index = __connman_service_get_index(service);
1524 while (service->nameservers_config && service->nameservers_config[i]) {
1525 #if defined TIZEN_EXT
1526 DBG("type %d Remove service->nameservers_config[%d]: %s",
1527 type, i, service->nameservers_config[i]);
1529 case CONNMAN_IPCONFIG_TYPE_IPV4:
1530 if (connman_inet_check_ipaddress(
1531 service->nameservers_config[i]) == AF_INET &&
1532 (service->dns_config_method_ipv4 ==
1533 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1534 service->dns_config_method_ipv4 ==
1535 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1536 nameserver_remove(service,
1537 service->nameservers_config[i]);
1540 case CONNMAN_IPCONFIG_TYPE_IPV6:
1541 if (connman_inet_check_ipaddress(
1542 service->nameservers_config[i]) == AF_INET6 &&
1543 (service->dns_config_method_ipv6 ==
1544 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1545 service->dns_config_method_ipv6 ==
1546 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1547 nameserver_remove(service,
1548 service->nameservers_config[i]);
1551 case CONNMAN_IPCONFIG_TYPE_ALL:
1552 if (connman_inet_check_ipaddress(
1553 service->nameservers_config[i]) == AF_INET &&
1554 (service->dns_config_method_ipv4 ==
1555 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1556 service->dns_config_method_ipv4 ==
1557 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1558 nameserver_remove(service,
1559 service->nameservers_config[i]);
1561 if (connman_inet_check_ipaddress(
1562 service->nameservers_config[i]) == AF_INET6 &&
1563 (service->dns_config_method_ipv6 ==
1564 CONNMAN_DNSCONFIG_METHOD_DHCP ||
1565 service->dns_config_method_ipv6 ==
1566 CONNMAN_DNSCONFIG_METHOD_MANUAL)) {
1567 nameserver_remove(service,
1568 service->nameservers_config[i]);
1571 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1572 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1575 DBG("default case do nothing");
1579 nameserver_remove(service, service->nameservers_config[i]);
1585 while (service->nameservers && service->nameservers[i]) {
1586 #if defined TIZEN_EXT
1587 DBG("type %d Remove service->nameservers[%d]: %s",type, i,
1588 service->nameservers[i]);
1590 case CONNMAN_IPCONFIG_TYPE_IPV4:
1591 if (connman_inet_check_ipaddress(
1592 service->nameservers[i]) == AF_INET &&
1593 (service->dns_config_method_ipv4 ==
1594 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1595 service->dns_config_method_ipv4 ==
1596 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1597 nameserver_remove(service,
1598 service->nameservers[i]);
1601 case CONNMAN_IPCONFIG_TYPE_IPV6:
1602 if (connman_inet_check_ipaddress(
1603 service->nameservers[i]) == AF_INET6 &&
1604 (service->dns_config_method_ipv6 ==
1605 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1606 service->dns_config_method_ipv6 ==
1607 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1608 nameserver_remove(service,
1609 service->nameservers[i]);
1612 case CONNMAN_IPCONFIG_TYPE_ALL:
1613 if (connman_inet_check_ipaddress(
1614 service->nameservers[i]) == AF_INET &&
1615 (service->dns_config_method_ipv4 ==
1616 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1617 service->dns_config_method_ipv4 ==
1618 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1619 nameserver_remove(service,
1620 service->nameservers[i]);
1622 if (connman_inet_check_ipaddress(
1623 service->nameservers[i]) == AF_INET6 &&
1624 (service->dns_config_method_ipv6 ==
1625 CONNMAN_DNSCONFIG_METHOD_MANUAL ||
1626 service->dns_config_method_ipv6 ==
1627 CONNMAN_DNSCONFIG_METHOD_DHCP)) {
1628 nameserver_remove(service,
1629 service->nameservers[i]);
1632 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
1633 DBG("CONNMAN_IPCONFIG_TYPE_UNKNOWN do nothing");
1636 DBG("default case do nothing");
1640 nameserver_remove(service, service->nameservers[i]);
1648 static int searchdomain_add_all(struct connman_service *service)
1652 if (!is_connected(service))
1655 index = __connman_service_get_index(service);
1659 if (service->domains) {
1660 while (service->domains[i]) {
1661 connman_resolver_append(index, service->domains[i],
1669 if (service->domainname)
1670 connman_resolver_append(index, service->domainname, NULL);
1676 static int searchdomain_remove_all(struct connman_service *service)
1680 if (!is_connected(service))
1683 index = __connman_service_get_index(service);
1687 while (service->domains && service->domains[i]) {
1688 connman_resolver_remove(index, service->domains[i], NULL);
1692 if (service->domainname)
1693 connman_resolver_remove(index, service->domainname, NULL);
1699 * The is_auto variable is set to true when IPv6 autoconf nameservers are
1700 * inserted to resolver via netlink message (see rtnl.c:rtnl_newnduseropt()
1701 * for details) and not through service.c
1703 #if defined TIZEN_EXT
1704 int __connman_service_nameserver_append(struct connman_service *service,
1705 const char *nameserver, bool is_auto,
1706 enum connman_ipconfig_type type)
1708 int __connman_service_nameserver_append(struct connman_service *service,
1709 const char *nameserver, bool is_auto)
1715 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1721 nameservers = service->nameservers_auto;
1723 nameservers = service->nameservers;
1725 for (i = 0; nameservers && nameservers[i]; i++)
1726 #if defined TIZEN_EXT
1728 DBG("nameservers[%d] %s, nameserver %s", i, nameservers[i], nameserver);
1730 if (g_strcmp0(nameservers[i], nameserver) == 0)
1732 #if defined TIZEN_EXT
1737 len = g_strv_length(nameservers);
1738 nameservers = g_try_renew(char *, nameservers, len + 2);
1741 nameservers = g_try_new0(char *, len + 2);
1747 nameservers[len] = g_strdup(nameserver);
1748 nameservers[len + 1] = NULL;
1751 if(type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
1752 service->dns_config_method_ipv4 ==
1753 CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
1754 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
1756 if(type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
1757 service->dns_config_method_ipv6 ==
1758 CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
1759 service->dns_config_method_ipv6 = CONNMAN_DNSCONFIG_METHOD_DHCP;
1763 service->nameservers_auto = nameservers;
1765 service->nameservers = nameservers;
1766 #if defined TIZEN_EXT
1767 DBG("nameserver add: %s, type: %d", nameserver, type);
1769 nameserver_add(service, nameserver);
1775 #if defined TIZEN_EXT
1776 int __connman_service_nameserver_remove(struct connman_service *service,
1777 const char *nameserver, bool is_auto,
1778 enum connman_ipconfig_type type)
1780 int __connman_service_nameserver_remove(struct connman_service *service,
1781 const char *nameserver, bool is_auto)
1784 char **servers, **nameservers;
1788 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1794 nameservers = service->nameservers_auto;
1796 nameservers = service->nameservers;
1801 for (i = 0; nameservers && nameservers[i]; i++)
1802 if (g_strcmp0(nameservers[i], nameserver) == 0) {
1810 len = g_strv_length(nameservers);
1817 servers = g_try_new0(char *, len);
1821 for (i = 0, j = 0; i < len; i++) {
1822 if (g_strcmp0(nameservers[i], nameserver)) {
1823 servers[j] = nameservers[i];
1826 g_free(nameservers[i]);
1828 nameservers[i] = NULL;
1830 servers[len - 1] = NULL;
1833 g_strfreev(nameservers);
1834 nameservers = servers;
1837 service->nameservers_auto = nameservers;
1839 service->nameservers = nameservers;
1840 #if defined TIZEN_EXT
1841 DBG("nameserver remove ip_type: %d", type);
1843 nameserver_remove(service, nameserver);
1849 void __connman_service_nameserver_clear(struct connman_service *service)
1851 #if defined TIZEN_EXT
1852 DBG("nameserver remove all ip_type: CONNMAN_IPCONFIG_TYPE_ALL");
1853 nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
1855 nameserver_remove_all(service);
1858 g_strfreev(service->nameservers);
1859 service->nameservers = NULL;
1861 #if defined TIZEN_EXT
1862 DBG("nameserver add all ip_type: CONNMAN_IPCONFIG_TYPE_ALL");
1863 nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
1865 nameserver_add_all(service);
1870 static void add_nameserver_route(int family, int index, char *nameserver,
1875 if (connman_inet_compare_subnet(index, nameserver))
1878 if (connman_inet_add_host_route(index, nameserver, gw) < 0)
1879 /* For P-t-P link the above route add will fail */
1880 connman_inet_add_host_route(index, nameserver, NULL);
1884 if (connman_inet_add_ipv6_host_route(index, nameserver,
1886 connman_inet_add_ipv6_host_route(index, nameserver,
1892 static void nameserver_add_routes(int index, char **nameservers,
1895 int i, ns_family, gw_family;
1897 gw_family = connman_inet_check_ipaddress(gw);
1901 for (i = 0; nameservers[i]; i++) {
1902 ns_family = connman_inet_check_ipaddress(nameservers[i]);
1903 if (ns_family < 0 || ns_family != gw_family)
1906 add_nameserver_route(ns_family, index, nameservers[i], gw);
1910 static void nameserver_del_routes(int index, char **nameservers,
1911 enum connman_ipconfig_type type)
1915 for (i = 0; nameservers[i]; i++) {
1916 family = connman_inet_check_ipaddress(nameservers[i]);
1922 if (type != CONNMAN_IPCONFIG_TYPE_IPV6)
1923 connman_inet_del_host_route(index,
1927 if (type != CONNMAN_IPCONFIG_TYPE_IPV4)
1928 connman_inet_del_ipv6_host_route(index,
1935 void __connman_service_nameserver_add_routes(struct connman_service *service,
1943 index = __connman_service_get_index(service);
1945 if (service->nameservers_config) {
1947 * Configured nameserver takes preference over the
1948 * discoverd nameserver gathered from DHCP, VPN, etc.
1950 nameserver_add_routes(index, service->nameservers_config, gw);
1951 } else if (service->nameservers) {
1953 * We add nameservers host routes for nameservers that
1954 * are not on our subnet. For those who are, the subnet
1955 * route will be installed by the time the dns proxy code
1956 * tries to reach them. The subnet route is installed
1957 * when setting the interface IP address.
1959 nameserver_add_routes(index, service->nameservers, gw);
1963 void __connman_service_nameserver_del_routes(struct connman_service *service,
1964 enum connman_ipconfig_type type)
1971 index = __connman_service_get_index(service);
1973 if (service->nameservers_config)
1974 nameserver_del_routes(index, service->nameservers_config,
1976 else if (service->nameservers)
1977 nameserver_del_routes(index, service->nameservers, type);
1980 static struct connman_stats *stats_get(struct connman_service *service)
1982 if (service->roaming)
1983 return &service->stats_roaming;
1985 return &service->stats;
1988 static bool stats_enabled(struct connman_service *service)
1990 struct connman_stats *stats = stats_get(service);
1992 return stats->enabled;
1995 static void stats_start(struct connman_service *service)
1997 struct connman_stats *stats = stats_get(service);
1999 DBG("service %p", service);
2004 stats->enabled = true;
2005 stats->data_last.time = stats->data.time;
2007 g_timer_start(stats->timer);
2010 static void stats_stop(struct connman_service *service)
2012 struct connman_stats *stats = stats_get(service);
2013 unsigned int seconds;
2015 DBG("service %p", service);
2020 if (!stats->enabled)
2023 g_timer_stop(stats->timer);
2025 seconds = g_timer_elapsed(stats->timer, NULL);
2026 stats->data.time = stats->data_last.time + seconds;
2028 stats->enabled = false;
2031 static void reset_stats(struct connman_service *service)
2033 DBG("service %p", service);
2036 service->stats.valid = false;
2038 service->stats.data.rx_packets = 0;
2039 service->stats.data.tx_packets = 0;
2040 service->stats.data.rx_bytes = 0;
2041 service->stats.data.tx_bytes = 0;
2042 service->stats.data.rx_errors = 0;
2043 service->stats.data.tx_errors = 0;
2044 service->stats.data.rx_dropped = 0;
2045 service->stats.data.tx_dropped = 0;
2046 service->stats.data.time = 0;
2047 service->stats.data_last.time = 0;
2049 g_timer_reset(service->stats.timer);
2052 service->stats_roaming.valid = false;
2054 service->stats_roaming.data.rx_packets = 0;
2055 service->stats_roaming.data.tx_packets = 0;
2056 service->stats_roaming.data.rx_bytes = 0;
2057 service->stats_roaming.data.tx_bytes = 0;
2058 service->stats_roaming.data.rx_errors = 0;
2059 service->stats_roaming.data.tx_errors = 0;
2060 service->stats_roaming.data.rx_dropped = 0;
2061 service->stats_roaming.data.tx_dropped = 0;
2062 service->stats_roaming.data.time = 0;
2063 service->stats_roaming.data_last.time = 0;
2065 g_timer_reset(service->stats_roaming.timer);
2068 #if defined TIZEN_EXT
2069 static gboolean __connman_service_is_internet_profile(
2070 struct connman_service *cellular)
2072 const char internet_suffix[] = "_1";
2074 DBG("Service path: %s", cellular->path);
2076 if (g_str_has_suffix(cellular->path, internet_suffix) == TRUE)
2082 static gboolean __connman_service_is_tethering_profile(
2083 struct connman_service *cellular)
2085 const char tethering_suffix[] = "_5";
2087 DBG("Service path: %s", cellular->path);
2089 if (g_str_has_suffix(cellular->path, tethering_suffix) == TRUE)
2095 struct connman_service *connman_service_get_default_connection(void)
2098 struct connman_service *service;
2099 struct connman_service *default_service = NULL;
2101 for (list = service_list; list; list = list->next) {
2102 service = list->data;
2104 DBG("service: %p %s %s %s", service, service->name,
2105 state2string(service->state),
2106 __connman_service_type2string(service->type));
2108 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
2109 is_connected(service) == TRUE) {
2111 } else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
2112 __connman_service_is_internet_profile(service) == TRUE) {
2113 if (default_service == NULL)
2114 default_service = service;
2115 else if (is_connected(service) == TRUE &&
2116 is_connected(default_service) == FALSE)
2117 default_service = service;
2118 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET &&
2119 is_connected(service) == TRUE) {
2120 if (default_service == NULL)
2121 default_service = service;
2122 } else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH &&
2123 is_connected(service) == TRUE) {
2124 if (default_service == NULL)
2125 default_service = service;
2129 return default_service;
2133 struct connman_service *__connman_service_get_default(void)
2135 struct connman_service *service;
2140 service = service_list->data;
2142 if (!is_connected(service))
2148 bool __connman_service_index_is_default(int index)
2150 struct connman_service *service;
2155 service = __connman_service_get_default();
2157 return __connman_service_get_index(service) == index;
2160 static void default_changed(void)
2162 struct connman_service *service = __connman_service_get_default();
2164 if (service == current_default)
2167 DBG("current default %p %s", current_default,
2168 current_default ? current_default->identifier : "");
2169 DBG("new default %p %s", service, service ? service->identifier : "");
2171 #if defined TIZEN_EXT
2172 current_default = service;
2174 __connman_service_timeserver_changed(service, NULL);
2176 __connman_service_timeserver_changed(current_default, NULL);
2178 current_default = service;
2182 if (service->hostname &&
2183 connman_setting_get_bool("AllowHostnameUpdates"))
2184 __connman_utsname_set_hostname(service->hostname);
2186 if (service->domainname)
2187 __connman_utsname_set_domainname(service->domainname);
2190 __connman_notifier_default_changed(service);
2193 static void state_changed(struct connman_service *service)
2197 __connman_notifier_service_state_changed(service, service->state);
2199 str = state2string(service->state);
2203 #if !defined TIZEN_EXT
2204 if (!allow_property_changed(service))
2207 #if defined TIZEN_EXT
2208 DBG(" %s, %s", str, service->path);
2210 connman_dbus_property_changed_basic(service->path,
2211 CONNMAN_SERVICE_INTERFACE, "State",
2212 DBUS_TYPE_STRING, &str);
2215 static void strength_changed(struct connman_service *service)
2217 if (service->strength == 0)
2220 if (!allow_property_changed(service))
2223 connman_dbus_property_changed_basic(service->path,
2224 CONNMAN_SERVICE_INTERFACE, "Strength",
2225 DBUS_TYPE_BYTE, &service->strength);
2228 static void favorite_changed(struct connman_service *service)
2230 dbus_bool_t favorite;
2235 if (!allow_property_changed(service))
2238 favorite = service->favorite;
2239 connman_dbus_property_changed_basic(service->path,
2240 CONNMAN_SERVICE_INTERFACE, "Favorite",
2241 DBUS_TYPE_BOOLEAN, &favorite);
2244 static void immutable_changed(struct connman_service *service)
2246 dbus_bool_t immutable;
2251 if (!allow_property_changed(service))
2254 immutable = service->immutable;
2255 connman_dbus_property_changed_basic(service->path,
2256 CONNMAN_SERVICE_INTERFACE, "Immutable",
2257 DBUS_TYPE_BOOLEAN, &immutable);
2260 static void roaming_changed(struct connman_service *service)
2262 dbus_bool_t roaming;
2267 if (!allow_property_changed(service))
2270 roaming = service->roaming;
2271 connman_dbus_property_changed_basic(service->path,
2272 CONNMAN_SERVICE_INTERFACE, "Roaming",
2273 DBUS_TYPE_BOOLEAN, &roaming);
2276 static void autoconnect_changed(struct connman_service *service)
2278 dbus_bool_t autoconnect;
2283 if (!allow_property_changed(service))
2286 autoconnect = service->autoconnect;
2287 connman_dbus_property_changed_basic(service->path,
2288 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
2289 DBUS_TYPE_BOOLEAN, &autoconnect);
2292 static void append_security(DBusMessageIter *iter, void *user_data)
2294 struct connman_service *service = user_data;
2297 str = security2string(service->security);
2299 dbus_message_iter_append_basic(iter,
2300 DBUS_TYPE_STRING, &str);
2303 * Some access points incorrectly advertise WPS even when they
2304 * are configured as open or no security, so filter
2308 switch (service->security) {
2309 case CONNMAN_SERVICE_SECURITY_PSK:
2310 case CONNMAN_SERVICE_SECURITY_WPA:
2311 case CONNMAN_SERVICE_SECURITY_RSN:
2313 dbus_message_iter_append_basic(iter,
2314 DBUS_TYPE_STRING, &str);
2316 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
2317 case CONNMAN_SERVICE_SECURITY_NONE:
2318 case CONNMAN_SERVICE_SECURITY_WEP:
2319 case CONNMAN_SERVICE_SECURITY_8021X:
2325 static void append_ethernet(DBusMessageIter *iter, void *user_data)
2327 struct connman_service *service = user_data;
2329 if (service->ipconfig_ipv4)
2330 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
2332 else if (service->ipconfig_ipv6)
2333 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
2337 static void append_ipv4(DBusMessageIter *iter, void *user_data)
2339 struct connman_service *service = user_data;
2341 if (!is_connected_state(service, service->state_ipv4))
2344 if (service->ipconfig_ipv4)
2345 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
2348 static void append_ipv6(DBusMessageIter *iter, void *user_data)
2350 struct connman_service *service = user_data;
2352 if (!is_connected_state(service, service->state_ipv6))
2355 if (service->ipconfig_ipv6)
2356 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
2357 service->ipconfig_ipv4);
2360 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
2362 struct connman_service *service = user_data;
2364 if (service->ipconfig_ipv4)
2365 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
2369 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
2371 struct connman_service *service = user_data;
2373 if (service->ipconfig_ipv6)
2374 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
2378 static void append_nameservers(DBusMessageIter *iter,
2379 struct connman_service *service, char **servers)
2382 bool available = true;
2384 for (i = 0; servers[i]; i++) {
2386 available = nameserver_available(service, servers[i]);
2388 DBG("servers[%d] %s available %d", i, servers[i], available);
2391 dbus_message_iter_append_basic(iter,
2392 DBUS_TYPE_STRING, &servers[i]);
2396 #if defined TIZEN_EXT
2397 static void append_nameserver_manual(DBusMessageIter *iter,
2398 struct connman_service *service, const char *server)
2400 bool available = true;
2403 available = nameserver_available(service, server);
2406 dbus_message_iter_append_basic(iter,
2407 DBUS_TYPE_STRING, &server);
2410 static void append_nameserver_dhcp(DBusMessageIter *iter,
2411 struct connman_service *service, const char *server)
2413 bool available = true;
2416 available = nameserver_available(service, server);
2419 dbus_message_iter_append_basic(iter,
2420 DBUS_TYPE_STRING, &server);
2424 static void append_dns(DBusMessageIter *iter, void *user_data)
2426 struct connman_service *service = user_data;
2427 #if defined TIZEN_EXT
2431 if (!is_connected(service))
2437 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
2439 char *str1 = g_strdup_printf("ipv4.%s", str);
2440 dbus_message_iter_append_basic(iter,
2441 DBUS_TYPE_STRING, &str1);
2445 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
2447 char *str1 = g_strdup_printf("ipv6.%s", str);
2448 dbus_message_iter_append_basic(iter,
2449 DBUS_TYPE_STRING, &str1);
2454 if (service->nameservers_config) {
2455 #if defined TIZEN_EXT
2457 while (service->nameservers_config[i]) {
2458 if (connman_inet_check_ipaddress(
2459 service->nameservers_config[i]) == AF_INET &&
2460 service->dns_config_method_ipv4 ==
2461 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2462 append_nameserver_manual(iter, service,
2463 service->nameservers_config[i]);
2466 if (connman_inet_check_ipaddress(
2467 service->nameservers_config[i]) == AF_INET6 &&
2468 service->dns_config_method_ipv6 ==
2469 CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2470 append_nameserver_manual(iter, service,
2471 service->nameservers_config[i]);
2475 /* In case of mixed DNS Config Type one of IPv4/IPv6 can be
2476 * dynamic while other is static so try to append the DNS
2477 * Address which is dynamic also */
2478 if (service->nameservers != NULL) {
2480 while (service->nameservers[i]) {
2481 if (connman_inet_check_ipaddress(
2482 service->nameservers[i]) == AF_INET &&
2483 service->dns_config_method_ipv4 ==
2484 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2485 append_nameserver_dhcp(iter, service,
2486 service->nameservers[i]);
2489 if (connman_inet_check_ipaddress(
2490 service->nameservers[i]) == AF_INET6 &&
2491 service->dns_config_method_ipv6 ==
2492 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2493 append_nameserver_dhcp(iter, service,
2494 service->nameservers[i]);
2500 append_nameservers(iter, service, service->nameservers_config);
2504 if (service->nameservers)
2505 #if defined TIZEN_EXT
2508 while (service->nameservers[i]) {
2509 if (connman_inet_check_ipaddress(
2510 service->nameservers[i]) == AF_INET &&
2511 service->dns_config_method_ipv4 ==
2512 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2513 append_nameserver_dhcp(iter, service,
2514 service->nameservers[i]);
2517 if (connman_inet_check_ipaddress(
2518 service->nameservers[i]) == AF_INET6 &&
2519 service->dns_config_method_ipv6 ==
2520 CONNMAN_DNSCONFIG_METHOD_DHCP) {
2521 append_nameserver_dhcp(iter, service,
2522 service->nameservers[i]);
2528 append_nameservers(iter, service,
2529 service->nameservers);
2532 if (service->nameservers_auto)
2533 append_nameservers(iter, service,
2534 service->nameservers_auto);
2536 if (!service->nameservers && !service->nameservers_auto) {
2539 DBG("append fallback nameservers");
2541 ns = connman_setting_get_string_list("FallbackNameservers");
2543 append_nameservers(iter, service, ns);
2548 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
2550 struct connman_service *service = user_data;
2553 /* Append DNS Config Type */
2555 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv4);
2557 char *str1 = g_strdup_printf("ipv4.%s", str);
2558 dbus_message_iter_append_basic(iter,
2559 DBUS_TYPE_STRING, &str1);
2563 str = __connman_dnsconfig_method2string(service->dns_config_method_ipv6);
2565 char *str1 = g_strdup_printf("ipv6.%s", str);
2566 dbus_message_iter_append_basic(iter,
2567 DBUS_TYPE_STRING, &str1);
2572 if (!service->nameservers_config)
2575 #if defined TIZEN_EXT
2577 while (service->nameservers_config[i]) {
2578 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET &&
2579 service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2580 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
2583 if (connman_inet_check_ipaddress(service->nameservers_config[i]) == AF_INET6 &&
2584 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL) {
2585 append_nameserver_manual(iter, NULL, service->nameservers_config[i]);
2590 append_nameservers(iter, NULL, service->nameservers_config);
2594 static void append_ts(DBusMessageIter *iter, void *user_data)
2596 GSList *list = user_data;
2599 char *timeserver = list->data;
2602 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
2605 list = g_slist_next(list);
2609 static void append_tsconfig(DBusMessageIter *iter, void *user_data)
2611 struct connman_service *service = user_data;
2614 if (!service->timeservers_config)
2617 for (i = 0; service->timeservers_config[i]; i++) {
2618 dbus_message_iter_append_basic(iter,
2620 &service->timeservers_config[i]);
2624 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
2626 struct connman_service *service = user_data;
2629 if (!service->domains)
2632 for (i = 0; service->domains[i]; i++)
2633 dbus_message_iter_append_basic(iter,
2634 DBUS_TYPE_STRING, &service->domains[i]);
2637 static void append_domain(DBusMessageIter *iter, void *user_data)
2639 struct connman_service *service = user_data;
2641 if (!is_connected(service) &&
2642 !is_connecting(service))
2645 if (service->domains)
2646 append_domainconfig(iter, user_data);
2647 else if (service->domainname)
2648 dbus_message_iter_append_basic(iter,
2649 DBUS_TYPE_STRING, &service->domainname);
2652 static void append_proxies(DBusMessageIter *iter, void *user_data)
2654 struct connman_service *service = user_data;
2657 if (!service->proxies)
2660 for (i = 0; service->proxies[i]; i++)
2661 dbus_message_iter_append_basic(iter,
2662 DBUS_TYPE_STRING, &service->proxies[i]);
2665 static void append_excludes(DBusMessageIter *iter, void *user_data)
2667 struct connman_service *service = user_data;
2670 if (!service->excludes)
2673 for (i = 0; service->excludes[i]; i++)
2674 dbus_message_iter_append_basic(iter,
2675 DBUS_TYPE_STRING, &service->excludes[i]);
2678 static void append_proxy(DBusMessageIter *iter, void *user_data)
2680 struct connman_service *service = user_data;
2681 enum connman_service_proxy_method proxy;
2682 const char *pac = NULL;
2683 const char *method = proxymethod2string(
2684 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
2686 if (!is_connected(service))
2689 proxy = connman_service_get_proxy_method(service);
2692 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2694 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2696 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2697 connman_dbus_dict_append_array(iter, "Servers",
2698 DBUS_TYPE_STRING, append_proxies,
2701 connman_dbus_dict_append_array(iter, "Excludes",
2702 DBUS_TYPE_STRING, append_excludes,
2705 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2706 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
2707 if (service->ipconfig_ipv4)
2708 pac = __connman_ipconfig_get_proxy_autoconfig(
2709 service->ipconfig_ipv4);
2710 else if (service->ipconfig_ipv6)
2711 pac = __connman_ipconfig_get_proxy_autoconfig(
2712 service->ipconfig_ipv6);
2714 if (!service->pac && !pac)
2720 connman_dbus_dict_append_basic(iter, "URL",
2721 DBUS_TYPE_STRING, &pac);
2725 method = proxymethod2string(proxy);
2728 connman_dbus_dict_append_basic(iter, "Method",
2729 DBUS_TYPE_STRING, &method);
2732 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
2734 struct connman_service *service = user_data;
2737 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
2740 switch (service->proxy_config) {
2741 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2743 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2745 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2746 if (service->proxies)
2747 connman_dbus_dict_append_array(iter, "Servers",
2749 append_proxies, service);
2751 if (service->excludes)
2752 connman_dbus_dict_append_array(iter, "Excludes",
2754 append_excludes, service);
2756 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2758 connman_dbus_dict_append_basic(iter, "URL",
2759 DBUS_TYPE_STRING, &service->pac);
2763 method = proxymethod2string(service->proxy_config);
2765 connman_dbus_dict_append_basic(iter, "Method",
2766 DBUS_TYPE_STRING, &method);
2769 static void append_provider(DBusMessageIter *iter, void *user_data)
2771 struct connman_service *service = user_data;
2773 if (!is_connected(service))
2776 if (service->provider)
2777 __connman_provider_append_properties(service->provider, iter);
2781 static void settings_changed(struct connman_service *service,
2782 struct connman_ipconfig *ipconfig)
2784 enum connman_ipconfig_type type;
2786 if (!allow_property_changed(service))
2789 type = __connman_ipconfig_get_config_type(ipconfig);
2791 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
2792 connman_dbus_property_changed_dict(service->path,
2793 CONNMAN_SERVICE_INTERFACE, "IPv4",
2794 append_ipv4, service);
2795 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2796 connman_dbus_property_changed_dict(service->path,
2797 CONNMAN_SERVICE_INTERFACE, "IPv6",
2798 append_ipv6, service);
2800 __connman_notifier_ipconfig_changed(service, ipconfig);
2803 static void ipv4_configuration_changed(struct connman_service *service)
2805 if (!allow_property_changed(service))
2808 connman_dbus_property_changed_dict(service->path,
2809 CONNMAN_SERVICE_INTERFACE,
2810 "IPv4.Configuration",
2815 static void ipv6_configuration_changed(struct connman_service *service)
2817 if (!allow_property_changed(service))
2820 connman_dbus_property_changed_dict(service->path,
2821 CONNMAN_SERVICE_INTERFACE,
2822 "IPv6.Configuration",
2827 static void dns_changed(struct connman_service *service)
2829 if (!allow_property_changed(service))
2832 connman_dbus_property_changed_array(service->path,
2833 CONNMAN_SERVICE_INTERFACE, "Nameservers",
2834 DBUS_TYPE_STRING, append_dns, service);
2837 static void dns_configuration_changed(struct connman_service *service)
2839 if (!allow_property_changed(service))
2842 connman_dbus_property_changed_array(service->path,
2843 CONNMAN_SERVICE_INTERFACE,
2844 "Nameservers.Configuration",
2845 DBUS_TYPE_STRING, append_dnsconfig, service);
2847 dns_changed(service);
2850 static void domain_changed(struct connman_service *service)
2852 if (!allow_property_changed(service))
2855 connman_dbus_property_changed_array(service->path,
2856 CONNMAN_SERVICE_INTERFACE, "Domains",
2857 DBUS_TYPE_STRING, append_domain, service);
2860 static void domain_configuration_changed(struct connman_service *service)
2862 if (!allow_property_changed(service))
2865 connman_dbus_property_changed_array(service->path,
2866 CONNMAN_SERVICE_INTERFACE,
2867 "Domains.Configuration",
2868 DBUS_TYPE_STRING, append_domainconfig, service);
2871 static void proxy_changed(struct connman_service *service)
2873 if (!allow_property_changed(service))
2876 connman_dbus_property_changed_dict(service->path,
2877 CONNMAN_SERVICE_INTERFACE, "Proxy",
2878 append_proxy, service);
2881 static void proxy_configuration_changed(struct connman_service *service)
2883 if (!allow_property_changed(service))
2886 connman_dbus_property_changed_dict(service->path,
2887 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
2888 append_proxyconfig, service);
2890 proxy_changed(service);
2893 static void timeservers_configuration_changed(struct connman_service *service)
2895 if (!allow_property_changed(service))
2898 connman_dbus_property_changed_array(service->path,
2899 CONNMAN_SERVICE_INTERFACE,
2900 "Timeservers.Configuration",
2902 append_tsconfig, service);
2905 static void link_changed(struct connman_service *service)
2907 if (!allow_property_changed(service))
2910 connman_dbus_property_changed_dict(service->path,
2911 CONNMAN_SERVICE_INTERFACE, "Ethernet",
2912 append_ethernet, service);
2915 static void stats_append_counters(DBusMessageIter *dict,
2916 struct connman_stats_data *stats,
2917 struct connman_stats_data *counters,
2920 if (counters->rx_packets != stats->rx_packets || append_all) {
2921 counters->rx_packets = stats->rx_packets;
2922 connman_dbus_dict_append_basic(dict, "RX.Packets",
2923 DBUS_TYPE_UINT32, &stats->rx_packets);
2926 if (counters->tx_packets != stats->tx_packets || append_all) {
2927 counters->tx_packets = stats->tx_packets;
2928 connman_dbus_dict_append_basic(dict, "TX.Packets",
2929 DBUS_TYPE_UINT32, &stats->tx_packets);
2932 if (counters->rx_bytes != stats->rx_bytes || append_all) {
2933 counters->rx_bytes = stats->rx_bytes;
2934 connman_dbus_dict_append_basic(dict, "RX.Bytes",
2935 DBUS_TYPE_UINT32, &stats->rx_bytes);
2938 if (counters->tx_bytes != stats->tx_bytes || append_all) {
2939 counters->tx_bytes = stats->tx_bytes;
2940 connman_dbus_dict_append_basic(dict, "TX.Bytes",
2941 DBUS_TYPE_UINT32, &stats->tx_bytes);
2944 if (counters->rx_errors != stats->rx_errors || append_all) {
2945 counters->rx_errors = stats->rx_errors;
2946 connman_dbus_dict_append_basic(dict, "RX.Errors",
2947 DBUS_TYPE_UINT32, &stats->rx_errors);
2950 if (counters->tx_errors != stats->tx_errors || append_all) {
2951 counters->tx_errors = stats->tx_errors;
2952 connman_dbus_dict_append_basic(dict, "TX.Errors",
2953 DBUS_TYPE_UINT32, &stats->tx_errors);
2956 if (counters->rx_dropped != stats->rx_dropped || append_all) {
2957 counters->rx_dropped = stats->rx_dropped;
2958 connman_dbus_dict_append_basic(dict, "RX.Dropped",
2959 DBUS_TYPE_UINT32, &stats->rx_dropped);
2962 if (counters->tx_dropped != stats->tx_dropped || append_all) {
2963 counters->tx_dropped = stats->tx_dropped;
2964 connman_dbus_dict_append_basic(dict, "TX.Dropped",
2965 DBUS_TYPE_UINT32, &stats->tx_dropped);
2968 if (counters->time != stats->time || append_all) {
2969 counters->time = stats->time;
2970 connman_dbus_dict_append_basic(dict, "Time",
2971 DBUS_TYPE_UINT32, &stats->time);
2975 static void stats_append(struct connman_service *service,
2976 const char *counter,
2977 struct connman_stats_counter *counters,
2980 DBusMessageIter array, dict;
2983 DBG("service %p counter %s", service, counter);
2985 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
2989 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
2990 &service->path, DBUS_TYPE_INVALID);
2992 dbus_message_iter_init_append(msg, &array);
2995 connman_dbus_dict_open(&array, &dict);
2997 stats_append_counters(&dict, &service->stats.data,
2998 &counters->stats.data, append_all);
3000 connman_dbus_dict_close(&array, &dict);
3002 /* roaming counter */
3003 connman_dbus_dict_open(&array, &dict);
3005 stats_append_counters(&dict, &service->stats_roaming.data,
3006 &counters->stats_roaming.data, append_all);
3008 connman_dbus_dict_close(&array, &dict);
3010 __connman_counter_send_usage(counter, msg);
3013 static void stats_update(struct connman_service *service,
3014 unsigned int rx_packets, unsigned int tx_packets,
3015 unsigned int rx_bytes, unsigned int tx_bytes,
3016 unsigned int rx_errors, unsigned int tx_errors,
3017 unsigned int rx_dropped, unsigned int tx_dropped)
3019 struct connman_stats *stats = stats_get(service);
3020 struct connman_stats_data *data_last = &stats->data_last;
3021 struct connman_stats_data *data = &stats->data;
3022 unsigned int seconds;
3024 DBG("service %p", service);
3028 rx_packets - data_last->rx_packets;
3030 tx_packets - data_last->tx_packets;
3032 rx_bytes - data_last->rx_bytes;
3034 tx_bytes - data_last->tx_bytes;
3036 rx_errors - data_last->rx_errors;
3038 tx_errors - data_last->tx_errors;
3040 rx_dropped - data_last->rx_dropped;
3042 tx_dropped - data_last->tx_dropped;
3044 stats->valid = true;
3047 data_last->rx_packets = rx_packets;
3048 data_last->tx_packets = tx_packets;
3049 data_last->rx_bytes = rx_bytes;
3050 data_last->tx_bytes = tx_bytes;
3051 data_last->rx_errors = rx_errors;
3052 data_last->tx_errors = tx_errors;
3053 data_last->rx_dropped = rx_dropped;
3054 data_last->tx_dropped = tx_dropped;
3056 seconds = g_timer_elapsed(stats->timer, NULL);
3057 stats->data.time = stats->data_last.time + seconds;
3060 void __connman_service_notify(struct connman_service *service,
3061 unsigned int rx_packets, unsigned int tx_packets,
3062 unsigned int rx_bytes, unsigned int tx_bytes,
3063 unsigned int rx_errors, unsigned int tx_errors,
3064 unsigned int rx_dropped, unsigned int tx_dropped)
3066 GHashTableIter iter;
3067 gpointer key, value;
3068 const char *counter;
3069 struct connman_stats_counter *counters;
3070 struct connman_stats_data *data;
3076 if (!is_connected(service))
3079 stats_update(service,
3080 rx_packets, tx_packets,
3082 rx_errors, tx_errors,
3083 rx_dropped, tx_dropped);
3085 data = &stats_get(service)->data;
3086 err = __connman_stats_update(service, service->roaming, data);
3088 connman_error("Failed to store statistics for %s",
3089 service->identifier);
3091 g_hash_table_iter_init(&iter, service->counter_table);
3092 while (g_hash_table_iter_next(&iter, &key, &value)) {
3096 stats_append(service, counter, counters, counters->append_all);
3097 counters->append_all = false;
3101 int __connman_service_counter_register(const char *counter)
3103 struct connman_service *service;
3105 struct connman_stats_counter *counters;
3107 DBG("counter %s", counter);
3109 counter_list = g_slist_prepend(counter_list, (gpointer)counter);
3111 for (list = service_list; list; list = list->next) {
3112 service = list->data;
3114 counters = g_try_new0(struct connman_stats_counter, 1);
3118 counters->append_all = true;
3120 g_hash_table_replace(service->counter_table, (gpointer)counter,
3127 void __connman_service_counter_unregister(const char *counter)
3129 struct connman_service *service;
3132 DBG("counter %s", counter);
3134 for (list = service_list; list; list = list->next) {
3135 service = list->data;
3137 g_hash_table_remove(service->counter_table, counter);
3140 counter_list = g_slist_remove(counter_list, counter);
3143 int __connman_service_iterate_services(service_iterate_cb cb, void *user_data)
3147 for (list = service_list; list; list = list->next) {
3148 struct connman_service *service = list->data;
3150 cb(service, user_data);
3156 #if defined TIZEN_EXT
3157 static void append_wifi_ext_info(DBusMessageIter *dict,
3158 struct connman_network *network)
3160 char bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
3161 char *bssid_str = bssid_buff;
3163 unsigned int ssid_len;
3164 unsigned char *bssid;
3165 unsigned int maxrate;
3166 unsigned int keymgmt;
3168 const char *enc_mode;
3172 ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
3173 bssid = connman_network_get_bssid(network);
3174 maxrate = connman_network_get_maxrate(network);
3175 frequency = connman_network_get_frequency(network);
3176 enc_mode = connman_network_get_enc_mode(network);
3177 passpoint = connman_network_get_is_hs20AP(network);
3178 keymgmt = connman_network_get_keymgmt(network);
3180 snprintf(bssid_str, WIFI_BSSID_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
3181 bssid[0], bssid[1], bssid[2],
3182 bssid[3], bssid[4], bssid[5]);
3184 connman_dbus_dict_append_fixed_array(dict, "SSID",
3185 DBUS_TYPE_BYTE, &ssid, ssid_len);
3186 connman_dbus_dict_append_basic(dict, "BSSID",
3187 DBUS_TYPE_STRING, &bssid_str);
3188 connman_dbus_dict_append_basic(dict, "MaxRate",
3189 DBUS_TYPE_UINT32, &maxrate);
3190 connman_dbus_dict_append_basic(dict, "Frequency",
3191 DBUS_TYPE_UINT16, &frequency);
3192 connman_dbus_dict_append_basic(dict, "EncryptionMode",
3193 DBUS_TYPE_STRING, &enc_mode);
3194 connman_dbus_dict_append_basic(dict, "Passpoint",
3195 DBUS_TYPE_BOOLEAN, &passpoint);
3196 connman_dbus_dict_append_basic(dict, "Keymgmt",
3197 DBUS_TYPE_UINT32, &keymgmt);
3199 str = connman_network_get_string(network, "WiFi.Security");
3200 if (str != NULL && g_str_equal(str, "ieee8021x") == TRUE) {
3201 str = connman_network_get_string(network, "WiFi.EAP");
3203 connman_dbus_dict_append_basic(dict, "EAP",
3204 DBUS_TYPE_STRING, &str);
3206 str = connman_network_get_string(network, "WiFi.Phase2");
3208 connman_dbus_dict_append_basic(dict, "Phase2",
3209 DBUS_TYPE_STRING, &str);
3211 str = connman_network_get_string(network, "WiFi.Identity");
3213 connman_dbus_dict_append_basic(dict, "Identity",
3214 DBUS_TYPE_STRING, &str);
3216 str = connman_network_get_string(network, "WiFi.CACertFile");
3218 connman_dbus_dict_append_basic(dict, "CACertFile",
3219 DBUS_TYPE_STRING, &str);
3221 str = connman_network_get_string(network,
3222 "WiFi.ClientCertFile");
3224 connman_dbus_dict_append_basic(dict, "ClientCertFile",
3225 DBUS_TYPE_STRING, &str);
3227 str = connman_network_get_string(network,
3228 "WiFi.PrivateKeyFile");
3230 connman_dbus_dict_append_basic(dict, "PrivateKeyFile",
3231 DBUS_TYPE_STRING, &str);
3236 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
3237 struct connman_service *service)
3243 #if defined TIZEN_EXT
3244 unsigned int frequency = 0U;
3245 if (service && service->network) {
3246 frequency = connman_network_get_frequency(service->network);
3247 connman_dbus_dict_append_basic(dict, "Frequency",
3248 DBUS_TYPE_UINT16, &frequency);
3252 str = __connman_service_type2string(service->type);
3254 connman_dbus_dict_append_basic(dict, "Type",
3255 DBUS_TYPE_STRING, &str);
3257 connman_dbus_dict_append_array(dict, "Security",
3258 DBUS_TYPE_STRING, append_security, service);
3260 str = state2string(service->state);
3262 connman_dbus_dict_append_basic(dict, "State",
3263 DBUS_TYPE_STRING, &str);
3266 str = state2string(service->state_ipv6);
3268 connman_dbus_dict_append_basic(dict, "StateIPv6",
3269 DBUS_TYPE_STRING, &str);
3272 str = error2string(service->error);
3274 connman_dbus_dict_append_basic(dict, "Error",
3275 DBUS_TYPE_STRING, &str);
3277 if (service->strength > 0)
3278 connman_dbus_dict_append_basic(dict, "Strength",
3279 DBUS_TYPE_BYTE, &service->strength);
3281 val = service->favorite;
3282 connman_dbus_dict_append_basic(dict, "Favorite",
3283 DBUS_TYPE_BOOLEAN, &val);
3285 val = service->immutable;
3286 connman_dbus_dict_append_basic(dict, "Immutable",
3287 DBUS_TYPE_BOOLEAN, &val);
3289 if (service->favorite)
3290 val = service->autoconnect;
3292 val = service->favorite;
3294 connman_dbus_dict_append_basic(dict, "AutoConnect",
3295 DBUS_TYPE_BOOLEAN, &val);
3298 connman_dbus_dict_append_basic(dict, "Name",
3299 DBUS_TYPE_STRING, &service->name);
3301 switch (service->type) {
3302 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3303 case CONNMAN_SERVICE_TYPE_SYSTEM:
3304 case CONNMAN_SERVICE_TYPE_GPS:
3305 case CONNMAN_SERVICE_TYPE_VPN:
3306 case CONNMAN_SERVICE_TYPE_P2P:
3308 case CONNMAN_SERVICE_TYPE_CELLULAR:
3309 val = service->roaming;
3310 connman_dbus_dict_append_basic(dict, "Roaming",
3311 DBUS_TYPE_BOOLEAN, &val);
3313 connman_dbus_dict_append_dict(dict, "Ethernet",
3314 append_ethernet, service);
3316 case CONNMAN_SERVICE_TYPE_WIFI:
3317 #if defined TIZEN_EXT
3318 if (service->network != NULL)
3319 append_wifi_ext_info(dict, service->network);
3321 connman_dbus_dict_append_dict(dict, "Ethernet",
3322 append_ethernet, service);
3324 connman_dbus_dict_append_basic(dict, "DisconnectReason",
3325 DBUS_TYPE_INT32, &service->disconnect_reason);
3329 case CONNMAN_SERVICE_TYPE_ETHERNET:
3330 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3331 case CONNMAN_SERVICE_TYPE_GADGET:
3332 connman_dbus_dict_append_dict(dict, "Ethernet",
3333 append_ethernet, service);
3337 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
3339 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
3340 append_ipv4config, service);
3342 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
3344 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
3345 append_ipv6config, service);
3347 connman_dbus_dict_append_array(dict, "Nameservers",
3348 DBUS_TYPE_STRING, append_dns, service);
3350 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
3351 DBUS_TYPE_STRING, append_dnsconfig, service);
3353 if (service->state == CONNMAN_SERVICE_STATE_READY ||
3354 service->state == CONNMAN_SERVICE_STATE_ONLINE)
3355 list = __connman_timeserver_get_all(service);
3359 connman_dbus_dict_append_array(dict, "Timeservers",
3360 DBUS_TYPE_STRING, append_ts, list);
3362 g_slist_free_full(list, g_free);
3364 connman_dbus_dict_append_array(dict, "Timeservers.Configuration",
3365 DBUS_TYPE_STRING, append_tsconfig, service);
3367 connman_dbus_dict_append_array(dict, "Domains",
3368 DBUS_TYPE_STRING, append_domain, service);
3370 connman_dbus_dict_append_array(dict, "Domains.Configuration",
3371 DBUS_TYPE_STRING, append_domainconfig, service);
3373 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
3375 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
3376 append_proxyconfig, service);
3378 connman_dbus_dict_append_dict(dict, "Provider",
3379 append_provider, service);
3382 static void append_struct_service(DBusMessageIter *iter,
3383 connman_dbus_append_cb_t function,
3384 struct connman_service *service)
3386 DBusMessageIter entry, dict;
3388 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
3390 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
3393 connman_dbus_dict_open(&entry, &dict);
3395 function(&dict, service);
3396 connman_dbus_dict_close(&entry, &dict);
3398 dbus_message_iter_close_container(iter, &entry);
3401 static void append_dict_properties(DBusMessageIter *dict, void *user_data)
3403 struct connman_service *service = user_data;
3405 append_properties(dict, TRUE, service);
3408 static void append_struct(gpointer value, gpointer user_data)
3410 struct connman_service *service = value;
3411 DBusMessageIter *iter = user_data;
3416 append_struct_service(iter, append_dict_properties, service);
3419 void __connman_service_list_struct(DBusMessageIter *iter)
3421 g_list_foreach(service_list, append_struct, iter);
3424 #if defined TIZEN_EXT
3425 static void append_wifi_vsie_properties(DBusMessageIter *iter,
3426 struct connman_service *service)
3428 DBusMessageIter dict;
3429 const void *wifi_vsie;
3430 unsigned int wifi_vsie_len;
3432 connman_dbus_dict_open(iter, &dict);
3434 wifi_vsie = connman_network_get_blob(service->network, "WiFi.Vsie", &wifi_vsie_len);
3436 if(wifi_vsie_len > 0) {
3437 DBG("ConnMan, service->path=%s vsie length=%d", service->path, wifi_vsie_len);
3440 connman_dbus_dict_append_fixed_array(&dict, "Vsie", DBUS_TYPE_BYTE,
3441 &wifi_vsie, wifi_vsie_len);
3443 connman_dbus_dict_close(iter, &dict);
3446 void __connman_wifi_vsie_list_struct(DBusMessageIter *iter)
3449 DBusMessageIter entry;
3451 DBG("ConnMan, __connman_wifi_vsie_list_struct API called");
3453 for (list = service_list; list; list = list->next) {
3454 struct connman_service *service = list->data;
3456 if (!service->path ||
3457 service->type != CONNMAN_SERVICE_TYPE_WIFI ||
3458 service->network == NULL)
3461 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT,
3463 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
3465 append_wifi_vsie_properties(&entry, service);
3466 dbus_message_iter_close_container(iter, &entry);
3471 bool __connman_service_is_hidden(struct connman_service *service)
3473 return service->hidden;
3477 __connman_service_is_split_routing(struct connman_service *service)
3479 return service->do_split_routing;
3482 bool __connman_service_index_is_split_routing(int index)
3484 struct connman_service *service;
3489 service = __connman_service_lookup_from_index(index);
3493 return __connman_service_is_split_routing(service);
3496 int __connman_service_get_index(struct connman_service *service)
3501 if (service->network)
3502 return connman_network_get_index(service->network);
3503 else if (service->provider)
3504 return connman_provider_get_index(service->provider);
3509 void __connman_service_set_hidden(struct connman_service *service)
3511 if (!service || service->hidden)
3514 service->hidden_service = true;
3517 void __connman_service_set_hostname(struct connman_service *service,
3518 const char *hostname)
3520 if (!service || service->hidden)
3523 g_free(service->hostname);
3524 service->hostname = g_strdup(hostname);
3527 const char *__connman_service_get_hostname(struct connman_service *service)
3532 return service->hostname;
3535 void __connman_service_set_domainname(struct connman_service *service,
3536 const char *domainname)
3538 if (!service || service->hidden)
3541 g_free(service->domainname);
3542 service->domainname = g_strdup(domainname);
3544 domain_changed(service);
3547 const char *connman_service_get_domainname(struct connman_service *service)
3552 if (service->domains)
3553 return service->domains[0];
3555 return service->domainname;
3558 char **connman_service_get_nameservers(struct connman_service *service)
3563 if (service->nameservers_config)
3564 return g_strdupv(service->nameservers_config);
3565 else if (service->nameservers ||
3566 service->nameservers_auto) {
3567 int len = 0, len_auto = 0, i;
3570 if (service->nameservers)
3571 len = g_strv_length(service->nameservers);
3572 if (service->nameservers_auto)
3573 len_auto = g_strv_length(service->nameservers_auto);
3575 nameservers = g_try_new0(char *, len + len_auto + 1);
3579 for (i = 0; i < len; i++)
3580 nameservers[i] = g_strdup(service->nameservers[i]);
3582 for (i = 0; i < len_auto; i++)
3583 nameservers[i + len] =
3584 g_strdup(service->nameservers_auto[i]);
3589 return g_strdupv(connman_setting_get_string_list("FallbackNameservers"));
3592 char **connman_service_get_timeservers_config(struct connman_service *service)
3597 return service->timeservers_config;
3600 char **connman_service_get_timeservers(struct connman_service *service)
3605 return service->timeservers;
3608 #if defined TIZEN_EXT
3610 * Description: Telephony plug-in requires manual PROXY setting function
3612 int connman_service_set_proxy(struct connman_service *service,
3613 const char *proxy, gboolean active)
3615 char **proxies_array = NULL;
3617 if (service == NULL)
3620 switch (service->type) {
3621 case CONNMAN_SERVICE_TYPE_CELLULAR:
3622 case CONNMAN_SERVICE_TYPE_ETHERNET:
3623 case CONNMAN_SERVICE_TYPE_WIFI:
3630 g_strfreev(service->proxies);
3631 service->proxies = NULL;
3634 proxies_array = g_strsplit(proxy, " ", 0);
3636 service->proxies = proxies_array;
3638 if (proxy == NULL) {
3639 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
3640 DBG("proxy changed (%d)", active);
3642 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
3643 DBG("proxy chagned %s (%d)", proxy, active);
3646 if (active == TRUE) {
3647 proxy_changed(service);
3649 __connman_notifier_proxy_changed(service);
3656 void connman_service_set_proxy_method(struct connman_service *service,
3657 enum connman_service_proxy_method method)
3659 if (!service || service->hidden)
3662 service->proxy = method;
3664 proxy_changed(service);
3666 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
3667 __connman_notifier_proxy_changed(service);
3670 enum connman_service_proxy_method connman_service_get_proxy_method(
3671 struct connman_service *service)
3674 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
3676 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
3677 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
3679 return service->proxy;
3681 return service->proxy_config;
3684 return service->proxy;
3687 char **connman_service_get_proxy_servers(struct connman_service *service)
3689 return g_strdupv(service->proxies);
3692 char **connman_service_get_proxy_excludes(struct connman_service *service)
3694 return g_strdupv(service->excludes);
3697 const char *connman_service_get_proxy_url(struct connman_service *service)
3702 return service->pac;
3705 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
3708 if (!service || service->hidden)
3711 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
3713 if (service->ipconfig_ipv4) {
3714 if (__connman_ipconfig_set_proxy_autoconfig(
3715 service->ipconfig_ipv4, url) < 0)
3717 } else if (service->ipconfig_ipv6) {
3718 if (__connman_ipconfig_set_proxy_autoconfig(
3719 service->ipconfig_ipv6, url) < 0)
3724 proxy_changed(service);
3726 __connman_notifier_proxy_changed(service);
3729 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
3734 if (service->ipconfig_ipv4)
3735 return __connman_ipconfig_get_proxy_autoconfig(
3736 service->ipconfig_ipv4);
3737 else if (service->ipconfig_ipv6)
3738 return __connman_ipconfig_get_proxy_autoconfig(
3739 service->ipconfig_ipv6);
3743 #if defined TIZEN_EXT
3744 int connman_service_get_ipv6_dns_method(struct connman_service *service)
3747 DBG("Service is NULL");
3751 return service->dns_config_method_ipv6;
3755 void __connman_service_set_timeservers(struct connman_service *service,
3763 g_strfreev(service->timeservers);
3764 service->timeservers = NULL;
3766 for (i = 0; timeservers && timeservers[i]; i++)
3767 __connman_service_timeserver_append(service, timeservers[i]);
3770 int __connman_service_timeserver_append(struct connman_service *service,
3771 const char *timeserver)
3775 DBG("service %p timeserver %s", service, timeserver);
3780 if (service->timeservers) {
3783 for (i = 0; service->timeservers[i]; i++)
3784 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
3787 len = g_strv_length(service->timeservers);
3788 service->timeservers = g_try_renew(char *, service->timeservers,
3792 service->timeservers = g_try_new0(char *, len + 2);
3795 if (!service->timeservers)
3798 service->timeservers[len] = g_strdup(timeserver);
3799 service->timeservers[len + 1] = NULL;
3804 int __connman_service_timeserver_remove(struct connman_service *service,
3805 const char *timeserver)
3808 int len, i, j, found = 0;
3810 DBG("service %p timeserver %s", service, timeserver);
3815 if (!service->timeservers)
3818 for (i = 0; service->timeservers &&
3819 service->timeservers[i]; i++)
3820 if (g_strcmp0(service->timeservers[i], timeserver) == 0) {
3828 len = g_strv_length(service->timeservers);
3831 g_strfreev(service->timeservers);
3832 service->timeservers = NULL;
3837 servers = g_try_new0(char *, len);
3841 for (i = 0, j = 0; i < len; i++) {
3842 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
3843 servers[j] = g_strdup(service->timeservers[i]);
3849 servers[len - 1] = NULL;
3851 g_strfreev(service->timeservers);
3852 service->timeservers = servers;
3857 void __connman_service_timeserver_changed(struct connman_service *service,
3863 if (!allow_property_changed(service))
3866 connman_dbus_property_changed_array(service->path,
3867 CONNMAN_SERVICE_INTERFACE, "Timeservers",
3868 DBUS_TYPE_STRING, append_ts, ts_list);
3871 void __connman_service_set_pac(struct connman_service *service,
3874 if (service->hidden)
3876 g_free(service->pac);
3877 service->pac = g_strdup(pac);
3879 proxy_changed(service);
3882 #if defined TIZEN_EXT
3883 void __connman_service_set_proxy(struct connman_service *service,
3884 const char *proxies)
3886 char **proxies_array = NULL;
3888 g_strfreev(service->proxies);
3889 service->proxies = NULL;
3891 if (proxies != NULL)
3892 proxies_array = g_strsplit(proxies, " ", 0);
3894 service->proxies = proxies_array;
3898 void __connman_service_set_identity(struct connman_service *service,
3899 const char *identity)
3901 if (service->immutable || service->hidden)
3904 g_free(service->identity);
3905 service->identity = g_strdup(identity);
3907 if (service->network)
3908 connman_network_set_string(service->network,
3913 void __connman_service_set_agent_identity(struct connman_service *service,
3914 const char *agent_identity)
3916 if (service->hidden)
3918 g_free(service->agent_identity);
3919 service->agent_identity = g_strdup(agent_identity);
3921 if (service->network)
3922 connman_network_set_string(service->network,
3923 "WiFi.AgentIdentity",
3924 service->agent_identity);
3927 static int check_passphrase(enum connman_service_security security,
3928 const char *passphrase)
3936 length = strlen(passphrase);
3939 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3940 case CONNMAN_SERVICE_SECURITY_NONE:
3941 case CONNMAN_SERVICE_SECURITY_WPA:
3942 #if !defined TIZEN_EXT
3943 case CONNMAN_SERVICE_SECURITY_RSN:
3946 DBG("service security '%s' (%d) not handled",
3947 security2string(security), security);
3951 case CONNMAN_SERVICE_SECURITY_PSK:
3952 #if defined TIZEN_EXT
3953 case CONNMAN_SERVICE_SECURITY_RSN:
3955 /* A raw key is always 64 bytes length,
3956 * its content is in hex representation.
3957 * A PSK key must be between [8..63].
3960 for (i = 0; i < 64; i++)
3961 if (!isxdigit((unsigned char)
3964 } else if (length < 8 || length > 63)
3967 case CONNMAN_SERVICE_SECURITY_WEP:
3968 /* length of WEP key is 10 or 26
3969 * length of WEP passphrase is 5 or 13
3971 if (length == 10 || length == 26) {
3972 for (i = 0; i < length; i++)
3973 if (!isxdigit((unsigned char)
3976 } else if (length != 5 && length != 13)
3980 case CONNMAN_SERVICE_SECURITY_8021X:
3987 int __connman_service_set_passphrase(struct connman_service *service,
3988 const char *passphrase)
3992 if (service->hidden)
3995 if (service->immutable &&
3996 service->security != CONNMAN_SERVICE_SECURITY_8021X)
3999 err = check_passphrase(service->security, passphrase);
4004 g_free(service->passphrase);
4005 service->passphrase = g_strdup(passphrase);
4007 if (service->network)
4008 connman_network_set_string(service->network, "WiFi.Passphrase",
4009 service->passphrase);
4014 const char *__connman_service_get_passphrase(struct connman_service *service)
4019 return service->passphrase;
4022 static DBusMessage *get_properties(DBusConnection *conn,
4023 DBusMessage *msg, void *user_data)
4025 struct connman_service *service = user_data;
4027 DBusMessageIter array, dict;
4029 DBG("service %p", service);
4031 reply = dbus_message_new_method_return(msg);
4035 dbus_message_iter_init_append(reply, &array);
4037 connman_dbus_dict_open(&array, &dict);
4038 append_properties(&dict, FALSE, service);
4039 connman_dbus_dict_close(&array, &dict);
4044 static int update_proxy_configuration(struct connman_service *service,
4045 DBusMessageIter *array)
4047 DBusMessageIter dict;
4048 enum connman_service_proxy_method method;
4049 GString *servers_str = NULL;
4050 GString *excludes_str = NULL;
4051 const char *url = NULL;
4053 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
4055 dbus_message_iter_recurse(array, &dict);
4057 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
4058 DBusMessageIter entry, variant;
4062 dbus_message_iter_recurse(&dict, &entry);
4064 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
4067 dbus_message_iter_get_basic(&entry, &key);
4068 dbus_message_iter_next(&entry);
4070 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
4073 dbus_message_iter_recurse(&entry, &variant);
4075 type = dbus_message_iter_get_arg_type(&variant);
4077 if (g_str_equal(key, "Method")) {
4080 if (type != DBUS_TYPE_STRING)
4083 dbus_message_iter_get_basic(&variant, &val);
4084 method = string2proxymethod(val);
4085 } else if (g_str_equal(key, "URL")) {
4086 if (type != DBUS_TYPE_STRING)
4089 dbus_message_iter_get_basic(&variant, &url);
4090 } else if (g_str_equal(key, "Servers")) {
4091 DBusMessageIter str_array;
4093 if (type != DBUS_TYPE_ARRAY)
4096 servers_str = g_string_new(NULL);
4100 dbus_message_iter_recurse(&variant, &str_array);
4102 while (dbus_message_iter_get_arg_type(&str_array) ==
4106 dbus_message_iter_get_basic(&str_array, &val);
4108 if (servers_str->len > 0)
4109 g_string_append_printf(servers_str,
4112 g_string_append(servers_str, val);
4114 dbus_message_iter_next(&str_array);
4116 } else if (g_str_equal(key, "Excludes")) {
4117 DBusMessageIter str_array;
4119 if (type != DBUS_TYPE_ARRAY)
4122 excludes_str = g_string_new(NULL);
4126 dbus_message_iter_recurse(&variant, &str_array);
4128 while (dbus_message_iter_get_arg_type(&str_array) ==
4132 dbus_message_iter_get_basic(&str_array, &val);
4134 if (excludes_str->len > 0)
4135 g_string_append_printf(excludes_str,
4138 g_string_append(excludes_str, val);
4140 dbus_message_iter_next(&str_array);
4144 dbus_message_iter_next(&dict);
4148 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
4150 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
4151 if (!servers_str && !service->proxies)
4155 g_strfreev(service->proxies);
4157 if (servers_str->len > 0)
4158 service->proxies = g_strsplit_set(
4159 servers_str->str, " ", 0);
4161 service->proxies = NULL;
4165 g_strfreev(service->excludes);
4167 if (excludes_str->len > 0)
4168 service->excludes = g_strsplit_set(
4169 excludes_str->str, " ", 0);
4171 service->excludes = NULL;
4174 if (!service->proxies)
4175 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
4178 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
4179 g_free(service->pac);
4181 if (url && strlen(url) > 0)
4182 service->pac = g_strdup(url);
4184 service->pac = NULL;
4186 /* if we are connected:
4187 - if service->pac == NULL
4188 - if __connman_ipconfig_get_proxy_autoconfig(
4189 service->ipconfig) == NULL
4190 --> We should start WPAD */
4193 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
4198 g_string_free(servers_str, TRUE);
4201 g_string_free(excludes_str, TRUE);
4203 service->proxy_config = method;
4209 g_string_free(servers_str, TRUE);
4212 g_string_free(excludes_str, TRUE);
4217 int __connman_service_reset_ipconfig(struct connman_service *service,
4218 enum connman_ipconfig_type type, DBusMessageIter *array,
4219 enum connman_service_state *new_state)
4221 struct connman_ipconfig *ipconfig, *new_ipconfig;
4222 enum connman_ipconfig_method old_method, new_method;
4223 enum connman_service_state state;
4226 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4227 ipconfig = service->ipconfig_ipv4;
4228 state = service->state_ipv4;
4229 new_method = CONNMAN_IPCONFIG_METHOD_DHCP;
4230 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4231 ipconfig = service->ipconfig_ipv6;
4232 state = service->state_ipv6;
4233 new_method = CONNMAN_IPCONFIG_METHOD_AUTO;
4240 old_method = __connman_ipconfig_get_method(ipconfig);
4241 index = __connman_ipconfig_get_index(ipconfig);
4243 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4244 new_ipconfig = create_ip4config(service, index,
4245 CONNMAN_IPCONFIG_METHOD_UNKNOWN);
4247 new_ipconfig = create_ip6config(service, index);
4250 err = __connman_ipconfig_set_config(new_ipconfig, array);
4252 __connman_ipconfig_unref(new_ipconfig);
4256 new_method = __connman_ipconfig_get_method(new_ipconfig);
4259 if (is_connecting_state(service, state) ||
4260 is_connected_state(service, state))
4261 __connman_network_clear_ipconfig(service->network, ipconfig);
4263 __connman_ipconfig_unref(ipconfig);
4265 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4266 service->ipconfig_ipv4 = new_ipconfig;
4267 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4268 service->ipconfig_ipv6 = new_ipconfig;
4270 if (is_connecting_state(service, state) ||
4271 is_connected_state(service, state))
4272 __connman_ipconfig_enable(new_ipconfig);
4274 if (new_state && new_method != old_method) {
4275 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4276 *new_state = service->state_ipv4;
4278 *new_state = service->state_ipv6;
4280 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4283 DBG("err %d ipconfig %p type %d method %d state %s", err,
4284 new_ipconfig, type, new_method,
4285 !new_state ? "-" : state2string(*new_state));
4290 static DBusMessage *set_property(DBusConnection *conn,
4291 DBusMessage *msg, void *user_data)
4293 struct connman_service *service = user_data;
4294 DBusMessageIter iter, value;
4298 DBG("service %p", service);
4300 if (!dbus_message_iter_init(msg, &iter))
4301 return __connman_error_invalid_arguments(msg);
4303 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
4304 return __connman_error_invalid_arguments(msg);
4306 if (service->type == CONNMAN_SERVICE_TYPE_WIFI && is_connected(service)) {
4308 if (connman_dbus_get_connection_unix_user_sync(conn,
4309 dbus_message_get_sender(msg),
4311 DBG("Can not get unix user id!");
4312 return __connman_error_permission_denied(msg);
4315 if (!connman_service_is_user_allowed(service, uid)) {
4316 DBG("Not allow this user to operate this wifi service now!");
4317 return __connman_error_permission_denied(msg);
4321 dbus_message_iter_get_basic(&iter, &name);
4322 dbus_message_iter_next(&iter);
4324 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
4325 return __connman_error_invalid_arguments(msg);
4327 dbus_message_iter_recurse(&iter, &value);
4329 type = dbus_message_iter_get_arg_type(&value);
4331 if (g_str_equal(name, "AutoConnect")) {
4332 dbus_bool_t autoconnect;
4334 if (type != DBUS_TYPE_BOOLEAN)
4335 return __connman_error_invalid_arguments(msg);
4337 if (!service->favorite)
4338 return __connman_error_invalid_service(msg);
4340 dbus_message_iter_get_basic(&value, &autoconnect);
4342 if (service->autoconnect == autoconnect)
4343 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4345 service->autoconnect = autoconnect;
4347 autoconnect_changed(service);
4350 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4352 service_save(service);
4353 } else if (g_str_equal(name, "Nameservers.Configuration")) {
4354 DBusMessageIter entry;
4358 #if defined TIZEN_EXT
4359 enum connman_ipconfig_type ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4363 if (__connman_provider_is_immutable(service->provider) ||
4365 return __connman_error_not_supported(msg);
4367 if (type != DBUS_TYPE_ARRAY)
4368 return __connman_error_invalid_arguments(msg);
4370 str = g_string_new(NULL);
4372 return __connman_error_invalid_arguments(msg);
4374 index = __connman_service_get_index(service);
4375 gw = __connman_ipconfig_get_gateway_from_index(index,
4376 CONNMAN_IPCONFIG_TYPE_ALL);
4378 if (gw && strlen(gw))
4379 __connman_service_nameserver_del_routes(service,
4380 CONNMAN_IPCONFIG_TYPE_ALL);
4382 dbus_message_iter_recurse(&value, &entry);
4384 #if defined TIZEN_EXT
4385 /* IPv4/IPv6 Last DNS config method */
4386 int last_dns_ipv4 = service->dns_config_method_ipv4;
4387 int last_dns_ipv6 = service->dns_config_method_ipv6;
4388 DBG("Last DNS Config Method IPv4: %d IPv6: %d", last_dns_ipv4, last_dns_ipv6);
4391 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4393 dbus_message_iter_get_basic(&entry, &val);
4394 dbus_message_iter_next(&entry);
4396 /* First unpack the DNS Config Method */
4397 DBG("DNS Config Method: %s", val);
4398 if((g_strcmp0(val, "ipv4.manual") == 0)) {
4399 service->dns_config_method_ipv4 =
4400 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4402 if(last_dns_ipv4 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4403 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4404 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4406 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4409 } else if(g_strcmp0(val, "ipv4.dhcp") == 0) {
4410 service->dns_config_method_ipv4 =
4411 CONNMAN_DNSCONFIG_METHOD_DHCP;
4412 if(last_dns_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4413 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4416 } else if(g_strcmp0(val, "ipv6.manual") == 0) {
4417 service->dns_config_method_ipv6 =
4418 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4419 if(last_dns_ipv6 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4420 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4421 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4423 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4426 } else if(g_strcmp0(val, "ipv6.dhcp") == 0) {
4427 service->dns_config_method_ipv6 =
4428 CONNMAN_DNSCONFIG_METHOD_DHCP;
4429 if(last_dns_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4430 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4435 if (connman_inet_check_ipaddress(val) > 0) {
4437 g_string_append_printf(str, " %s", val);
4439 g_string_append(str, val);
4443 #if defined TIZEN_EXT
4444 if (service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_DHCP &&
4445 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_DHCP) {
4446 DBG("Both IPv4 and IPv6 DNS Method DHCP");
4447 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4449 if (gw && strlen(gw))
4450 __connman_service_nameserver_del_routes(service,
4453 DBG("%s ip_type: %d nameserver remove all", name, ip_type);
4454 nameserver_remove_all(service, ip_type);
4456 nameserver_remove_all(service);
4458 g_strfreev(service->nameservers_config);
4461 service->nameservers_config =
4462 g_strsplit_set(str->str, " ", 0);
4464 service->nameservers_config = NULL;
4467 g_string_free(str, TRUE);
4469 if (gw && strlen(gw))
4470 __connman_service_nameserver_add_routes(service, gw);
4472 #if defined TIZEN_EXT
4473 DBG("%s ip_type: %d nameserver add all", name, ip_type);
4474 nameserver_add_all(service, ip_type);
4476 nameserver_add_all(service);
4478 dns_configuration_changed(service);
4480 if (__connman_service_is_connected_state(service,
4481 CONNMAN_IPCONFIG_TYPE_IPV4))
4482 __connman_wispr_start(service,
4483 CONNMAN_IPCONFIG_TYPE_IPV4);
4485 if (__connman_service_is_connected_state(service,
4486 CONNMAN_IPCONFIG_TYPE_IPV6))
4487 __connman_wispr_start(service,
4488 CONNMAN_IPCONFIG_TYPE_IPV6);
4490 service_save(service);
4491 } else if (g_str_equal(name, "Timeservers.Configuration")) {
4492 DBusMessageIter entry;
4493 GSList *list = NULL;
4496 if (service->immutable)
4497 return __connman_error_not_supported(msg);
4499 if (type != DBUS_TYPE_ARRAY)
4500 return __connman_error_invalid_arguments(msg);
4502 dbus_message_iter_recurse(&value, &entry);
4504 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4508 dbus_message_iter_get_basic(&entry, &val);
4510 new_head = __connman_timeserver_add_list(list, val);
4511 if (list != new_head) {
4516 dbus_message_iter_next(&entry);
4519 g_strfreev(service->timeservers_config);
4520 service->timeservers_config = NULL;
4523 service->timeservers_config = g_new0(char *, count+1);
4527 service->timeservers_config[count] = list->data;
4528 list = g_slist_delete_link(list, list);
4532 service_save(service);
4533 timeservers_configuration_changed(service);
4535 if (service == __connman_service_get_default())
4536 __connman_timeserver_sync(service);
4538 } else if (g_str_equal(name, "Domains.Configuration")) {
4539 DBusMessageIter entry;
4542 if (service->immutable)
4543 return __connman_error_not_supported(msg);
4545 if (type != DBUS_TYPE_ARRAY)
4546 return __connman_error_invalid_arguments(msg);
4548 str = g_string_new(NULL);
4550 return __connman_error_invalid_arguments(msg);
4552 dbus_message_iter_recurse(&value, &entry);
4554 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4556 dbus_message_iter_get_basic(&entry, &val);
4557 dbus_message_iter_next(&entry);
4559 g_string_append_printf(str, " %s", val);
4561 g_string_append(str, val);
4564 searchdomain_remove_all(service);
4565 g_strfreev(service->domains);
4568 service->domains = g_strsplit_set(str->str, " ", 0);
4570 service->domains = NULL;
4572 g_string_free(str, TRUE);
4574 searchdomain_add_all(service);
4575 domain_configuration_changed(service);
4576 domain_changed(service);
4578 service_save(service);
4579 } else if (g_str_equal(name, "Proxy.Configuration")) {
4582 if (service->immutable)
4583 return __connman_error_not_supported(msg);
4585 if (type != DBUS_TYPE_ARRAY)
4586 return __connman_error_invalid_arguments(msg);
4588 err = update_proxy_configuration(service, &value);
4591 return __connman_error_failed(msg, -err);
4593 proxy_configuration_changed(service);
4595 __connman_notifier_proxy_changed(service);
4597 service_save(service);
4598 } else if (g_str_equal(name, "IPv4.Configuration") ||
4599 g_str_equal(name, "IPv6.Configuration")) {
4601 enum connman_service_state state =
4602 CONNMAN_SERVICE_STATE_UNKNOWN;
4603 enum connman_ipconfig_type type =
4604 CONNMAN_IPCONFIG_TYPE_UNKNOWN;
4607 if (service->type == CONNMAN_SERVICE_TYPE_VPN ||
4609 return __connman_error_not_supported(msg);
4613 if (!service->ipconfig_ipv4 &&
4614 !service->ipconfig_ipv6)
4615 return __connman_error_invalid_property(msg);
4617 if (g_str_equal(name, "IPv4.Configuration"))
4618 type = CONNMAN_IPCONFIG_TYPE_IPV4;
4620 type = CONNMAN_IPCONFIG_TYPE_IPV6;
4622 err = __connman_service_reset_ipconfig(service, type, &value,
4626 if (is_connected_state(service, state) ||
4627 is_connecting_state(service, state)) {
4628 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4629 __connman_network_enable_ipconfig(service->network,
4630 service->ipconfig_ipv4);
4632 __connman_network_enable_ipconfig(service->network,
4633 service->ipconfig_ipv6);
4636 return __connman_error_failed(msg, -err);
4639 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4640 ipv4_configuration_changed(service);
4642 ipv6_configuration_changed(service);
4644 if (is_connecting(service) || is_connected(service)) {
4645 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4646 __connman_network_enable_ipconfig(service->network,
4647 service->ipconfig_ipv4);
4649 __connman_network_enable_ipconfig(service->network,
4650 service->ipconfig_ipv6);
4653 service_save(service);
4655 return __connman_error_invalid_property(msg);
4657 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4660 static void set_error(struct connman_service *service,
4661 enum connman_service_error error)
4665 if (service->error == error)
4668 service->error = error;
4673 #if !defined TIZEN_EXT
4674 if (!allow_property_changed(service))
4678 str = error2string(service->error);
4683 connman_dbus_property_changed_basic(service->path,
4684 CONNMAN_SERVICE_INTERFACE, "Error",
4685 DBUS_TYPE_STRING, &str);
4688 static void set_idle(struct connman_service *service)
4690 service->state = service->state_ipv4 = service->state_ipv6 =
4691 CONNMAN_SERVICE_STATE_IDLE;
4692 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4693 state_changed(service);
4696 static DBusMessage *clear_property(DBusConnection *conn,
4697 DBusMessage *msg, void *user_data)
4699 struct connman_service *service = user_data;
4702 DBG("service %p", service);
4704 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
4707 if (g_str_equal(name, "Error")) {
4708 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4710 g_get_current_time(&service->modified);
4711 service_save(service);
4713 return __connman_error_invalid_property(msg);
4715 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4718 static bool is_ipconfig_usable(struct connman_service *service)
4720 if (!__connman_ipconfig_is_usable(service->ipconfig_ipv4) &&
4721 !__connman_ipconfig_is_usable(service->ipconfig_ipv6))
4727 static bool is_ignore(struct connman_service *service)
4729 if (!service->autoconnect)
4732 if (service->roaming)
4735 if (service->ignore)
4738 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
4741 if (!is_ipconfig_usable(service))
4747 static void disconnect_on_last_session(enum connman_service_type type)
4751 for (list = service_list; list; list = list->next) {
4752 struct connman_service *service = list->data;
4754 if (service->type != type)
4757 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_SESSION)
4760 __connman_service_disconnect(service);
4765 static int active_sessions[MAX_CONNMAN_SERVICE_TYPES] = {};
4766 static int active_count = 0;
4768 void __connman_service_set_active_session(bool enable, GSList *list)
4778 while (list != NULL) {
4779 enum connman_service_type type = GPOINTER_TO_INT(list->data);
4782 case CONNMAN_SERVICE_TYPE_ETHERNET:
4783 case CONNMAN_SERVICE_TYPE_WIFI:
4784 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4785 case CONNMAN_SERVICE_TYPE_CELLULAR:
4786 case CONNMAN_SERVICE_TYPE_GADGET:
4788 active_sessions[type]++;
4790 active_sessions[type]--;
4793 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4794 case CONNMAN_SERVICE_TYPE_SYSTEM:
4795 case CONNMAN_SERVICE_TYPE_GPS:
4796 case CONNMAN_SERVICE_TYPE_VPN:
4797 case CONNMAN_SERVICE_TYPE_P2P:
4801 if (active_sessions[type] == 0)
4802 disconnect_on_last_session(type);
4804 list = g_slist_next(list);
4807 DBG("eth %d wifi %d bt %d cellular %d gadget %d sessions %d",
4808 active_sessions[CONNMAN_SERVICE_TYPE_ETHERNET],
4809 active_sessions[CONNMAN_SERVICE_TYPE_WIFI],
4810 active_sessions[CONNMAN_SERVICE_TYPE_BLUETOOTH],
4811 active_sessions[CONNMAN_SERVICE_TYPE_CELLULAR],
4812 active_sessions[CONNMAN_SERVICE_TYPE_GADGET],
4816 struct preferred_tech_data {
4817 GList *preferred_list;
4818 enum connman_service_type type;
4821 static void preferred_tech_add_by_type(gpointer data, gpointer user_data)
4823 struct connman_service *service = data;
4824 struct preferred_tech_data *tech_data = user_data;
4826 if (service->type == tech_data->type) {
4827 tech_data->preferred_list =
4828 g_list_append(tech_data->preferred_list, service);
4830 DBG("type %d service %p %s", tech_data->type, service,
4835 static GList *preferred_tech_list_get(void)
4837 unsigned int *tech_array;
4838 struct preferred_tech_data tech_data = { 0, };
4841 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
4845 if (connman_setting_get_bool("SingleConnectedTechnology")) {
4847 for (list = service_list; list; list = list->next) {
4848 struct connman_service *service = list->data;
4850 if (!is_connected(service))
4853 if (service->connect_reason ==
4854 CONNMAN_SERVICE_CONNECT_REASON_USER) {
4855 DBG("service %p name %s is user connected",
4856 service, service->name);
4857 #if defined TIZEN_EXT
4858 /* We can connect to a favorite service like
4859 * wifi even we have a userconnect for cellular
4860 * because we have refount for cellular service
4862 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
4865 if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
4873 for (i = 0; tech_array[i] != 0; i += 1) {
4874 tech_data.type = tech_array[i];
4875 g_list_foreach(service_list, preferred_tech_add_by_type,
4879 return tech_data.preferred_list;
4882 static bool auto_connect_service(GList *services,
4883 enum connman_service_connect_reason reason,
4886 struct connman_service *service = NULL;
4887 bool ignore[MAX_CONNMAN_SERVICE_TYPES] = { };
4888 bool autoconnecting = false;
4891 DBG("preferred %d sessions %d reason %s", preferred, active_count,
4892 reason2string(reason));
4894 ignore[CONNMAN_SERVICE_TYPE_VPN] = true;
4896 for (list = services; list; list = list->next) {
4897 service = list->data;
4899 if (ignore[service->type]) {
4900 DBG("service %p type %s ignore", service,
4901 __connman_service_type2string(service->type));
4905 #if defined TIZEN_EXT
4906 DBG("service %p %s %s %s, favorite(%d), ignore(%d), hidden(%d, %d)",
4907 service, service->name,
4908 state2string(service->state),
4909 __connman_service_type2string(service->type),
4910 service->favorite, is_ignore(service),
4911 service->hidden, service->hidden_service);
4913 /* Tizen takes Wi-Fi as the highest priority into consideration. */
4914 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
4915 if (is_connecting(service) == TRUE || is_connected(service) == TRUE)
4919 if (service->pending ||
4920 is_connecting(service) ||
4921 is_connected(service)) {
4925 ignore[service->type] = true;
4926 autoconnecting = true;
4928 DBG("service %p type %s busy", service,
4929 __connman_service_type2string(service->type));
4934 if (!service->favorite) {
4938 #if defined TIZEN_EXT
4939 DBG("Service is not favorite, autoconnecting %d",
4942 return autoconnecting;
4945 #if defined TIZEN_EXT
4946 DBG("service %p identifier %s roaming %d ignore %d "
4947 "ipconfig_usable %d autoconnect %d state %d",
4949 service->identifier, service->roaming,
4950 service->ignore, is_ipconfig_usable(service),
4951 service->autoconnect, service->state);
4953 if (is_ignore(service) || service->state !=
4954 CONNMAN_SERVICE_STATE_IDLE)
4957 if (autoconnecting && !active_sessions[service->type]) {
4958 DBG("service %p type %s has no users", service,
4959 __connman_service_type2string(service->type));
4963 if (!is_service_owner_user_login(service)) {
4964 DBG("favorite user not login, wifi auto connect denied");
4968 DBG("service %p %s %s", service, service->name,
4969 (preferred) ? "preferred" : reason2string(reason));
4971 __connman_service_connect(service, reason);
4976 ignore[service->type] = true;
4979 return autoconnecting;
4982 static gboolean run_auto_connect(gpointer data)
4984 enum connman_service_connect_reason reason = GPOINTER_TO_UINT(data);
4985 bool autoconnecting = false;
4986 GList *preferred_tech;
4988 autoconnect_timeout = 0;
4992 preferred_tech = preferred_tech_list_get();
4993 if (preferred_tech) {
4994 autoconnecting = auto_connect_service(preferred_tech, reason,
4996 g_list_free(preferred_tech);
4999 if (!autoconnecting || active_count)
5000 auto_connect_service(service_list, reason, false);
5005 #if defined TIZEN_EXT
5006 bool __connman_service_get_auto_connect_mode(void)
5008 return auto_connect_mode;
5011 void __connman_service_set_auto_connect_mode(bool enable)
5013 DBG("set auto_connect_mode = %d", enable);
5015 if (auto_connect_mode != enable)
5016 auto_connect_mode = enable;
5020 void __connman_service_auto_connect(enum connman_service_connect_reason reason)
5024 if (autoconnect_timeout != 0)
5027 #if defined TIZEN_EXT
5028 if (auto_connect_mode == FALSE) {
5029 DBG("Currently, not auto connection mode");
5034 if (!__connman_session_policy_autoconnect(reason))
5037 #if defined TIZEN_EXT
5038 /* Adding Timeout of 500ms before trying to auto connect.
5039 * This is done because of below scenario
5040 * 1. Device is connected to AP1
5041 * 2. WPS Connection request is initiated for AP2
5042 * 3. Immediately WPS Connection is Cancelled
5043 * When WPS Connection Connection is initiated for AP2 then
5044 * sometimes there is a scenario where connman gets in ASSOCIATED
5045 * state with AP1 due to autoconnect and subsequently the connection
5046 * initiated by AP1 fails and connman service for AP1 comes in
5047 * FAILURE state due to this when connection with AP2 is cancelled
5048 * then autoconnect with AP1 doesn't works because its autoconnection
5049 * is ignored as its last state was FAILURE rather than IDLE */
5050 autoconnect_timeout = g_timeout_add(500, run_auto_connect,
5052 autoconnect_timeout = g_timeout_add_seconds(0, run_auto_connect,
5054 GUINT_TO_POINTER(reason));
5057 static gboolean run_vpn_auto_connect(gpointer data) {
5059 bool need_split = false;
5061 vpn_autoconnect_timeout = 0;
5063 for (list = service_list; list; list = list->next) {
5064 struct connman_service *service = list->data;
5067 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
5070 if (is_connected(service) || is_connecting(service)) {
5071 if (!service->do_split_routing)
5076 if (is_ignore(service) || !service->favorite)
5079 if (need_split && !service->do_split_routing) {
5080 DBG("service %p no split routing", service);
5084 DBG("service %p %s %s", service, service->name,
5085 service->do_split_routing ?
5086 "split routing" : "");
5088 res = __connman_service_connect(service,
5089 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5090 if (res < 0 && res != -EINPROGRESS)
5093 if (!service->do_split_routing)
5100 static void vpn_auto_connect(void)
5102 if (vpn_autoconnect_timeout)
5105 vpn_autoconnect_timeout =
5106 g_timeout_add_seconds(0, run_vpn_auto_connect, NULL);
5109 static void remove_timeout(struct connman_service *service)
5111 if (service->timeout > 0) {
5112 g_source_remove(service->timeout);
5113 service->timeout = 0;
5117 static void reply_pending(struct connman_service *service, int error)
5119 remove_timeout(service);
5121 if (service->pending) {
5122 connman_dbus_reply_pending(service->pending, error, NULL);
5123 service->pending = NULL;
5126 if (service->provider_pending) {
5127 connman_dbus_reply_pending(service->provider_pending,
5128 error, service->path);
5129 service->provider_pending = NULL;
5134 __connman_service_is_provider_pending(struct connman_service *service)
5139 if (service->provider_pending)
5145 void __connman_service_set_provider_pending(struct connman_service *service,
5148 if (service->provider_pending) {
5149 DBG("service %p provider pending msg %p already exists",
5150 service, service->provider_pending);
5154 service->provider_pending = msg;
5158 static void check_pending_msg(struct connman_service *service)
5160 if (!service->pending)
5163 DBG("service %p pending msg %p already exists", service,
5165 dbus_message_unref(service->pending);
5168 void __connman_service_set_hidden_data(struct connman_service *service,
5171 DBusMessage *pending = user_data;
5173 DBG("service %p pending %p", service, pending);
5178 check_pending_msg(service);
5180 service->pending = pending;
5183 void __connman_service_return_error(struct connman_service *service,
5184 int error, gpointer user_data)
5186 DBG("service %p error %d user_data %p", service, error, user_data);
5188 __connman_service_set_hidden_data(service, user_data);
5190 reply_pending(service, error);
5193 static gboolean connect_timeout(gpointer user_data)
5195 struct connman_service *service = user_data;
5196 bool autoconnect = false;
5198 DBG("service %p", service);
5200 service->timeout = 0;
5202 if (service->network)
5203 __connman_network_disconnect(service->network);
5204 else if (service->provider)
5205 connman_provider_disconnect(service->provider);
5207 __connman_ipconfig_disable(service->ipconfig_ipv4);
5208 __connman_ipconfig_disable(service->ipconfig_ipv6);
5210 __connman_stats_service_unregister(service);
5212 if (service->pending) {
5215 reply = __connman_error_operation_timeout(service->pending);
5217 g_dbus_send_message(connection, reply);
5219 dbus_message_unref(service->pending);
5220 service->pending = NULL;
5224 __connman_service_ipconfig_indicate_state(service,
5225 CONNMAN_SERVICE_STATE_FAILURE,
5226 CONNMAN_IPCONFIG_TYPE_IPV4);
5227 __connman_service_ipconfig_indicate_state(service,
5228 CONNMAN_SERVICE_STATE_FAILURE,
5229 CONNMAN_IPCONFIG_TYPE_IPV6);
5232 service->connect_reason !=
5233 CONNMAN_SERVICE_CONNECT_REASON_USER)
5234 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5239 static DBusMessage *connect_service(DBusConnection *conn,
5240 DBusMessage *msg, void *user_data)
5242 struct connman_service *service = user_data;
5243 #if defined TIZEN_EXT
5250 DBG("service %p", service);
5252 #if defined TIZEN_EXT
5254 * Description: TIZEN implements system global connection management.
5256 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5257 connman_service_user_pdn_connection_ref(service);
5260 if (service->pending)
5261 return __connman_error_in_progress(msg);
5263 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5265 if (connman_dbus_get_connection_unix_user_sync(conn,
5266 dbus_message_get_sender(msg),
5268 DBG("Can not get unix user id!");
5269 return __connman_error_permission_denied(msg);
5272 if (!__connman_service_is_user_allowed(CONNMAN_SERVICE_TYPE_WIFI, uid)) {
5273 DBG("Not allow this user to connect this wifi service now!");
5274 return __connman_error_permission_denied(msg);
5277 if (uid != USER_ROOT && uid != service->user.favorite_user)
5278 service->request_passphrase_input = true;
5280 service->user.current_user = uid;
5282 if (!service->passphrase && uid == service->user.favorite_user) {
5283 DBG("Now load this favorite user's passphrase.");
5284 service_load_passphrase(service);
5288 #if !defined TIZEN_EXT
5289 index = __connman_service_get_index(service);
5291 for (list = service_list; list; list = list->next) {
5292 struct connman_service *temp = list->data;
5294 #if defined TIZEN_EXT
5295 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5298 if (!is_connecting(temp) && !is_connected(temp))
5301 if (service == temp)
5304 if (service->type != temp->type)
5307 if (__connman_service_get_index(temp) == index &&
5308 __connman_service_disconnect(temp) == -EINPROGRESS)
5312 if (err == -EINPROGRESS)
5313 return __connman_error_operation_timeout(msg);
5316 service->ignore = false;
5318 service->pending = dbus_message_ref(msg);
5320 err = __connman_service_connect(service,
5321 CONNMAN_SERVICE_CONNECT_REASON_USER);
5323 if (err == -EINPROGRESS)
5326 if (service->pending) {
5327 dbus_message_unref(service->pending);
5328 service->pending = NULL;
5332 return __connman_error_failed(msg, -err);
5334 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5337 static DBusMessage *disconnect_service(DBusConnection *conn,
5338 DBusMessage *msg, void *user_data)
5340 struct connman_service *service = user_data;
5343 DBG("service %p", service);
5345 #if defined TIZEN_EXT
5347 * Description: TIZEN implements system global connection management.
5349 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
5350 if (connman_service_user_pdn_connection_unref_and_test(service) != TRUE)
5351 return __connman_error_failed(msg, EISCONN);
5353 if (is_connected(service) == TRUE &&
5354 service == connman_service_get_default_connection())
5355 return __connman_error_failed(msg, EISCONN);
5359 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5361 if (connman_dbus_get_connection_unix_user_sync(conn,
5362 dbus_message_get_sender(msg),
5364 DBG("Can not get unix user id!");
5365 return __connman_error_permission_denied(msg);
5368 if (!connman_service_is_user_allowed(service, uid)) {
5369 DBG("Not allow this user to disconnect this wifi service now!");
5370 return __connman_error_permission_denied(msg);
5374 service->ignore = true;
5376 err = __connman_service_disconnect(service);
5377 if (err < 0 && err != -EINPROGRESS)
5378 return __connman_error_failed(msg, -err);
5380 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5383 #if defined TIZEN_EXT
5384 static void __connman_service_cleanup_network_8021x(struct connman_service *service)
5386 if (service == NULL)
5389 DBG("service %p ", service);
5391 connman_network_set_string(service->network, "WiFi.EAP", NULL);
5392 connman_network_set_string(service->network, "WiFi.Identity", NULL);
5393 connman_network_set_string(service->network, "WiFi.CACertFile", NULL);
5394 connman_network_set_string(service->network, "WiFi.ClientCertFile", NULL);
5395 connman_network_set_string(service->network, "WiFi.PrivateKeyFile", NULL);
5396 connman_network_set_string(service->network, "WiFi.PrivateKeyPassphrase", NULL);
5397 connman_network_set_string(service->network, "WiFi.Phase2", NULL);
5401 bool __connman_service_remove(struct connman_service *service)
5403 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET ||
5404 service->type == CONNMAN_SERVICE_TYPE_GADGET)
5407 if (service->immutable || service->hidden ||
5408 __connman_provider_is_immutable(service->provider))
5411 #if !defined TIZEN_EXT
5412 if (!service->favorite && service->state !=
5413 CONNMAN_SERVICE_STATE_FAILURE)
5417 __connman_service_disconnect(service);
5419 g_free(service->passphrase);
5420 service->passphrase = NULL;
5422 g_free(service->identity);
5423 service->identity = NULL;
5425 g_free(service->agent_identity);
5426 service->agent_identity = NULL;
5428 g_free(service->eap);
5429 service->eap = NULL;
5431 #if defined TIZEN_EXT
5432 g_free(service->ca_cert_file);
5433 service->ca_cert_file = NULL;
5435 g_free(service->client_cert_file);
5436 service->client_cert_file = NULL;
5438 g_free(service->private_key_file);
5439 service->private_key_file = NULL;
5441 g_free(service->private_key_passphrase);
5442 service->private_key_passphrase = NULL;
5444 g_free(service->phase2);
5445 service->phase2 = NULL;
5447 __connman_service_cleanup_network_8021x(service);
5449 __connman_ipconfig_set_method(service->ipconfig_ipv4, CONNMAN_IPCONFIG_METHOD_DHCP);
5450 __connman_ipconfig_set_method(service->ipconfig_ipv6, CONNMAN_IPCONFIG_METHOD_AUTO);
5451 connman_service_set_proxy(service, NULL, false);
5453 __connman_service_nameserver_clear(service);
5455 g_strfreev(service->nameservers_config);
5456 service->nameservers_config = NULL;
5460 #if defined TIZEN_EXT
5461 if (service->security != CONNMAN_SERVICE_SECURITY_8021X)
5465 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
5467 service->user.favorite_user = USER_NONE;
5469 __connman_service_set_favorite(service, false);
5471 __connman_ipconfig_ipv6_reset_privacy(service->ipconfig_ipv6);
5473 #if defined TIZEN_EXT
5474 /* Reset IP Method and DNS Method to DHCP */
5475 __connman_ipconfig_set_method(service->ipconfig_ipv4,
5476 CONNMAN_IPCONFIG_METHOD_DHCP);
5477 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
5478 g_strfreev(service->nameservers_config);
5479 service->nameservers_config = NULL;
5482 #if defined TIZEN_EXT
5483 __connman_storage_remove_service(service->identifier);
5485 service_save(service);
5491 static DBusMessage *remove_service(DBusConnection *conn,
5492 DBusMessage *msg, void *user_data)
5494 struct connman_service *service = user_data;
5496 DBG("service %p", service);
5498 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5500 if (connman_dbus_get_connection_unix_user_sync(conn,
5501 dbus_message_get_sender(msg),
5503 DBG("Can not get unix user id!");
5504 return __connman_error_permission_denied(msg);
5507 #if !defined TIZEN_EXT
5508 if (!connman_service_is_user_allowed(service, uid)) {
5509 DBG("Not allow this user to remove this wifi service now!");
5510 return __connman_error_permission_denied(msg);
5515 if (!__connman_service_remove(service))
5516 return __connman_error_not_supported(msg);
5518 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5521 static bool check_suitable_state(enum connman_service_state a,
5522 enum connman_service_state b)
5525 * Special check so that "ready" service can be moved before
5528 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
5529 b == CONNMAN_SERVICE_STATE_READY) ||
5530 (b == CONNMAN_SERVICE_STATE_ONLINE &&
5531 a == CONNMAN_SERVICE_STATE_READY))
5537 static void downgrade_state(struct connman_service *service)
5542 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
5543 service->state_ipv6);
5545 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
5546 __connman_service_ipconfig_indicate_state(service,
5547 CONNMAN_SERVICE_STATE_READY,
5548 CONNMAN_IPCONFIG_TYPE_IPV4);
5550 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
5551 __connman_service_ipconfig_indicate_state(service,
5552 CONNMAN_SERVICE_STATE_READY,
5553 CONNMAN_IPCONFIG_TYPE_IPV6);
5556 static void apply_relevant_default_downgrade(struct connman_service *service)
5558 struct connman_service *def_service;
5560 def_service = __connman_service_get_default();
5564 if (def_service == service &&
5565 def_service->state == CONNMAN_SERVICE_STATE_ONLINE) {
5566 def_service->state = CONNMAN_SERVICE_STATE_READY;
5567 __connman_notifier_leave_online(def_service->type);
5568 state_changed(def_service);
5572 static void switch_default_service(struct connman_service *default_service,
5573 struct connman_service *downgrade_service)
5575 struct connman_service *service;
5578 apply_relevant_default_downgrade(default_service);
5579 src = g_list_find(service_list, downgrade_service);
5580 dst = g_list_find(service_list, default_service);
5583 if (src == dst || src->next == dst)
5586 service = src->data;
5587 service_list = g_list_delete_link(service_list, src);
5588 service_list = g_list_insert_before(service_list, dst, service);
5590 downgrade_state(downgrade_service);
5593 static DBusMessage *move_service(DBusConnection *conn,
5594 DBusMessage *msg, void *user_data,
5597 struct connman_service *service = user_data;
5598 struct connman_service *target;
5600 enum connman_ipconfig_method target4, target6;
5601 enum connman_ipconfig_method service4, service6;
5603 DBG("service %p", service);
5605 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
5608 if (!service->favorite)
5609 return __connman_error_not_supported(msg);
5611 target = find_service(path);
5612 if (!target || !target->favorite || target == service)
5613 return __connman_error_invalid_service(msg);
5615 if (target->type == CONNMAN_SERVICE_TYPE_VPN) {
5617 * We only allow VPN route splitting if there are
5618 * routes defined for a given VPN.
5620 if (!__connman_provider_check_routes(target->provider)) {
5621 connman_info("Cannot move service. "
5622 "No routes defined for provider %s",
5623 __connman_provider_get_ident(target->provider));
5624 return __connman_error_invalid_service(msg);
5627 target->do_split_routing = true;
5629 target->do_split_routing = false;
5631 service->do_split_routing = false;
5633 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
5634 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
5635 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
5636 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
5638 DBG("target %s method %d/%d state %d/%d split %d", target->identifier,
5639 target4, target6, target->state_ipv4, target->state_ipv6,
5640 target->do_split_routing);
5642 DBG("service %s method %d/%d state %d/%d", service->identifier,
5644 service->state_ipv4, service->state_ipv6);
5647 * If method is OFF, then we do not need to check the corresponding
5650 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5651 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5652 if (!check_suitable_state(target->state_ipv6,
5653 service->state_ipv6))
5654 return __connman_error_invalid_service(msg);
5658 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5659 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5660 if (!check_suitable_state(target->state_ipv4,
5661 service->state_ipv4))
5662 return __connman_error_invalid_service(msg);
5666 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5667 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5668 if (!check_suitable_state(target->state_ipv6,
5669 service->state_ipv6))
5670 return __connman_error_invalid_service(msg);
5674 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5675 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5676 if (!check_suitable_state(target->state_ipv4,
5677 service->state_ipv4))
5678 return __connman_error_invalid_service(msg);
5682 g_get_current_time(&service->modified);
5683 service_save(service);
5684 service_save(target);
5687 * If the service which goes down is the default service and is
5688 * online, we downgrade directly its state to ready so:
5689 * the service which goes up, needs to recompute its state which
5690 * is triggered via downgrading it - if relevant - to state ready.
5693 switch_default_service(target, service);
5695 switch_default_service(service, target);
5697 __connman_connection_update_gateway();
5699 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5702 static DBusMessage *move_before(DBusConnection *conn,
5703 DBusMessage *msg, void *user_data)
5705 return move_service(conn, msg, user_data, true);
5708 static DBusMessage *move_after(DBusConnection *conn,
5709 DBusMessage *msg, void *user_data)
5711 return move_service(conn, msg, user_data, false);
5714 static DBusMessage *reset_counters(DBusConnection *conn,
5715 DBusMessage *msg, void *user_data)
5717 struct connman_service *service = user_data;
5719 reset_stats(service);
5721 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5724 static DBusMessage *get_user_favorite(DBusConnection *conn,
5725 DBusMessage *msg, void *user_data)
5728 uid_t uid = USER_NONE;
5729 dbus_bool_t user_favorite = false;
5730 struct connman_service *service = user_data;
5732 connman_dbus_get_connection_unix_user_sync(conn,
5733 dbus_message_get_sender(msg),
5735 if (uid == USER_ROOT)
5736 user_favorite = service->favorite;
5737 else if (uid != USER_NONE && uid == service->user.favorite_user) {
5738 DBG("The service is favorite to this user!");
5739 user_favorite = true;
5742 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5743 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN,
5744 &user_favorite, DBUS_TYPE_INVALID);
5748 static struct _services_notify {
5754 static void service_append_added_foreach(gpointer data, gpointer user_data)
5756 struct connman_service *service = data;
5757 DBusMessageIter *iter = user_data;
5759 if (!service || !service->path) {
5760 #if !defined TIZEN_EXT
5761 DBG("service %p or path is NULL", service);
5766 if (g_hash_table_lookup(services_notify->add, service->path)) {
5767 #if !defined TIZEN_EXT
5768 DBG("new %s", service->path);
5771 append_struct(service, iter);
5772 g_hash_table_remove(services_notify->add, service->path);
5774 #if !defined TIZEN_EXT
5775 DBG("changed %s", service->path);
5778 append_struct_service(iter, NULL, service);
5782 static void service_append_ordered(DBusMessageIter *iter, void *user_data)
5784 g_list_foreach(service_list, service_append_added_foreach, iter);
5787 static void append_removed(gpointer key, gpointer value, gpointer user_data)
5789 char *objpath = key;
5790 DBusMessageIter *iter = user_data;
5792 DBG("removed %s", objpath);
5793 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath);
5796 static void service_append_removed(DBusMessageIter *iter, void *user_data)
5798 g_hash_table_foreach(services_notify->remove, append_removed, iter);
5801 static gboolean service_send_changed(gpointer data)
5803 DBusMessage *signal;
5807 services_notify->id = 0;
5809 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
5810 CONNMAN_MANAGER_INTERFACE, "ServicesChanged");
5814 __connman_dbus_append_objpath_dict_array(signal,
5815 service_append_ordered, NULL);
5816 __connman_dbus_append_objpath_array(signal,
5817 service_append_removed, NULL);
5819 dbus_connection_send(connection, signal, NULL);
5820 dbus_message_unref(signal);
5822 g_hash_table_remove_all(services_notify->remove);
5823 g_hash_table_remove_all(services_notify->add);
5828 static void service_schedule_changed(void)
5830 if (services_notify->id != 0)
5833 services_notify->id = g_timeout_add(100, service_send_changed, NULL);
5836 static void service_schedule_added(struct connman_service *service)
5838 DBG("service %p", service);
5840 g_hash_table_remove(services_notify->remove, service->path);
5841 g_hash_table_replace(services_notify->add, service->path, service);
5843 service_schedule_changed();
5846 static void service_schedule_removed(struct connman_service *service)
5848 if (!service || !service->path) {
5849 DBG("service %p or path is NULL", service);
5853 DBG("service %p %s", service, service->path);
5855 g_hash_table_remove(services_notify->add, service->path);
5856 g_hash_table_replace(services_notify->remove, g_strdup(service->path),
5859 service_schedule_changed();
5862 static bool allow_property_changed(struct connman_service *service)
5864 #if defined TIZEN_EXT
5865 if (service->path == NULL)
5868 if (g_hash_table_lookup_extended(services_notify->add, service->path,
5870 DBG("no property updates for service %p", service);
5877 static const GDBusMethodTable service_methods[] = {
5878 { GDBUS_DEPRECATED_METHOD("GetProperties",
5879 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
5881 { GDBUS_METHOD("SetProperty",
5882 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
5883 NULL, set_property) },
5884 { GDBUS_METHOD("ClearProperty",
5885 GDBUS_ARGS({ "name", "s" }), NULL,
5887 { GDBUS_ASYNC_METHOD("Connect", NULL, NULL,
5889 { GDBUS_METHOD("Disconnect", NULL, NULL,
5890 disconnect_service) },
5891 { GDBUS_METHOD("Remove", NULL, NULL, remove_service) },
5892 { GDBUS_METHOD("MoveBefore",
5893 GDBUS_ARGS({ "service", "o" }), NULL,
5895 { GDBUS_METHOD("MoveAfter",
5896 GDBUS_ARGS({ "service", "o" }), NULL,
5898 { GDBUS_METHOD("ResetCounters", NULL, NULL, reset_counters) },
5899 { GDBUS_METHOD("GetUserFavorite",
5900 NULL, GDBUS_ARGS({ "value", "v" }),
5901 get_user_favorite) },
5905 static const GDBusSignalTable service_signals[] = {
5906 { GDBUS_SIGNAL("PropertyChanged",
5907 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
5911 static void service_free(gpointer user_data)
5913 struct connman_service *service = user_data;
5914 char *path = service->path;
5916 DBG("service %p", service);
5918 reply_pending(service, ENOENT);
5920 __connman_notifier_service_remove(service);
5921 service_schedule_removed(service);
5923 __connman_wispr_stop(service);
5924 stats_stop(service);
5926 service->path = NULL;
5929 __connman_connection_update_gateway();
5931 g_dbus_unregister_interface(connection, path,
5932 CONNMAN_SERVICE_INTERFACE);
5936 g_hash_table_destroy(service->counter_table);
5938 if (service->network) {
5939 __connman_network_disconnect(service->network);
5940 connman_network_unref(service->network);
5941 service->network = NULL;
5944 if (service->provider)
5945 connman_provider_unref(service->provider);
5947 if (service->ipconfig_ipv4) {
5948 __connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
5949 __connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
5950 __connman_ipconfig_unref(service->ipconfig_ipv4);
5951 service->ipconfig_ipv4 = NULL;
5954 if (service->ipconfig_ipv6) {
5955 __connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
5956 __connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
5957 __connman_ipconfig_unref(service->ipconfig_ipv6);
5958 service->ipconfig_ipv6 = NULL;
5961 g_strfreev(service->timeservers);
5962 g_strfreev(service->timeservers_config);
5963 g_strfreev(service->nameservers);
5964 g_strfreev(service->nameservers_config);
5965 g_strfreev(service->nameservers_auto);
5966 g_strfreev(service->domains);
5967 g_strfreev(service->proxies);
5968 g_strfreev(service->excludes);
5970 g_free(service->hostname);
5971 g_free(service->domainname);
5972 g_free(service->pac);
5973 g_free(service->name);
5974 g_free(service->passphrase);
5975 g_free(service->identifier);
5976 g_free(service->eap);
5977 g_free(service->identity);
5978 g_free(service->agent_identity);
5979 g_free(service->ca_cert_file);
5980 g_free(service->client_cert_file);
5981 g_free(service->private_key_file);
5982 g_free(service->private_key_passphrase);
5983 g_free(service->phase2);
5984 g_free(service->config_file);
5985 g_free(service->config_entry);
5987 if (service->stats.timer)
5988 g_timer_destroy(service->stats.timer);
5989 if (service->stats_roaming.timer)
5990 g_timer_destroy(service->stats_roaming.timer);
5992 if (current_default == service)
5993 current_default = NULL;
5998 static void stats_init(struct connman_service *service)
6001 service->stats.valid = false;
6002 service->stats.enabled = false;
6003 service->stats.timer = g_timer_new();
6006 service->stats_roaming.valid = false;
6007 service->stats_roaming.enabled = false;
6008 service->stats_roaming.timer = g_timer_new();
6011 static void service_initialize(struct connman_service *service)
6013 DBG("service %p", service);
6015 service->refcount = 1;
6017 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
6019 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
6020 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
6022 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
6023 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
6024 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
6026 service->favorite = false;
6027 service->immutable = false;
6028 service->hidden = false;
6030 service->ignore = false;
6032 service->user.favorite_user = USER_NONE;
6033 service->user.current_user = USER_NONE;
6035 service->request_passphrase_input = false;
6037 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
6041 stats_init(service);
6043 service->provider = NULL;
6045 service->wps = false;
6046 #if defined TIZEN_EXT
6047 service->storage_reload = false;
6049 * Description: TIZEN implements system global connection management.
6051 service->user_pdn_connection_refcount = 0;
6052 __sync_synchronize();
6057 * connman_service_create:
6059 * Allocate a new service.
6061 * Returns: a newly-allocated #connman_service structure
6063 struct connman_service *connman_service_create(void)
6066 struct connman_stats_counter *counters;
6067 const char *counter;
6069 struct connman_service *service;
6071 service = g_try_new0(struct connman_service, 1);
6075 DBG("service %p", service);
6077 service->counter_table = g_hash_table_new_full(g_str_hash,
6078 g_str_equal, NULL, g_free);
6080 for (list = counter_list; list; list = list->next) {
6081 counter = list->data;
6083 counters = g_try_new0(struct connman_stats_counter, 1);
6085 g_hash_table_destroy(service->counter_table);
6090 counters->append_all = true;
6092 g_hash_table_replace(service->counter_table, (gpointer)counter,
6096 service_initialize(service);
6102 * connman_service_ref:
6103 * @service: service structure
6105 * Increase reference counter of service
6107 struct connman_service *
6108 connman_service_ref_debug(struct connman_service *service,
6109 const char *file, int line, const char *caller)
6111 DBG("%p ref %d by %s:%d:%s()", service, service->refcount + 1,
6112 file, line, caller);
6114 __sync_fetch_and_add(&service->refcount, 1);
6120 * connman_service_unref:
6121 * @service: service structure
6123 * Decrease reference counter of service and release service if no
6126 void connman_service_unref_debug(struct connman_service *service,
6127 const char *file, int line, const char *caller)
6129 DBG("%p ref %d by %s:%d:%s()", service, service->refcount - 1,
6130 file, line, caller);
6132 if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
6135 service_list = g_list_remove(service_list, service);
6137 __connman_service_disconnect(service);
6139 g_hash_table_remove(service_hash, service->identifier);
6142 static gint service_compare(gconstpointer a, gconstpointer b)
6144 struct connman_service *service_a = (void *) a;
6145 struct connman_service *service_b = (void *) b;
6146 enum connman_service_state state_a, state_b;
6147 bool a_connected, b_connected;
6150 state_a = service_a->state;
6151 state_b = service_b->state;
6152 a_connected = is_connected(service_a);
6153 b_connected = is_connected(service_b);
6155 if (a_connected && b_connected) {
6156 if (service_a->order > service_b->order)
6159 if (service_a->order < service_b->order)
6163 if (state_a != state_b) {
6164 if (a_connected && b_connected) {
6165 /* We prefer online over ready state */
6166 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
6169 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
6178 if (is_connecting(service_a))
6180 if (is_connecting(service_b))
6184 if (service_a->favorite && !service_b->favorite)
6187 if (!service_a->favorite && service_b->favorite)
6190 if (service_a->type != service_b->type) {
6192 if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6194 if (service_b->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6197 if (service_a->type == CONNMAN_SERVICE_TYPE_WIFI)
6199 if (service_b->type == CONNMAN_SERVICE_TYPE_WIFI)
6202 if (service_a->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6204 if (service_b->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6207 if (service_a->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6209 if (service_b->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6212 if (service_a->type == CONNMAN_SERVICE_TYPE_VPN)
6214 if (service_b->type == CONNMAN_SERVICE_TYPE_VPN)
6217 if (service_a->type == CONNMAN_SERVICE_TYPE_GADGET)
6219 if (service_b->type == CONNMAN_SERVICE_TYPE_GADGET)
6223 strength = (gint) service_b->strength - (gint) service_a->strength;
6227 return g_strcmp0(service_a->name, service_b->name);
6230 static void service_list_sort(void)
6232 if (service_list && service_list->next) {
6233 service_list = g_list_sort(service_list, service_compare);
6234 service_schedule_changed();
6239 * connman_service_get_type:
6240 * @service: service structure
6242 * Get the type of service
6244 enum connman_service_type connman_service_get_type(struct connman_service *service)
6247 return CONNMAN_SERVICE_TYPE_UNKNOWN;
6249 return service->type;
6253 * connman_service_get_interface:
6254 * @service: service structure
6256 * Get network interface of service
6258 char *connman_service_get_interface(struct connman_service *service)
6265 index = __connman_service_get_index(service);
6267 return connman_inet_ifname(index);
6271 * __connman_service_is_user_allowed:
6272 * @type: service type
6275 * Check a user is allowed to operate a type of service
6277 bool __connman_service_is_user_allowed(enum connman_service_type type,
6281 uid_t owner_user = USER_NONE;
6283 for (list = service_list; list; list = list->next) {
6284 struct connman_service *service = list->data;
6286 if (service->type != type)
6289 if (is_connected(service)) {
6290 owner_user = service->user.favorite_user;
6295 if (uid == USER_NONE ||
6296 (uid != USER_ROOT &&
6297 owner_user != USER_NONE &&
6305 * connman_service_get_network:
6306 * @service: service structure
6308 * Get the service network
6310 struct connman_network *
6311 __connman_service_get_network(struct connman_service *service)
6316 return service->network;
6319 struct connman_ipconfig *
6320 __connman_service_get_ip4config(struct connman_service *service)
6325 return service->ipconfig_ipv4;
6328 struct connman_ipconfig *
6329 __connman_service_get_ip6config(struct connman_service *service)
6334 return service->ipconfig_ipv6;
6337 struct connman_ipconfig *
6338 __connman_service_get_ipconfig(struct connman_service *service, int family)
6340 if (family == AF_INET)
6341 return __connman_service_get_ip4config(service);
6342 else if (family == AF_INET6)
6343 return __connman_service_get_ip6config(service);
6349 bool __connman_service_is_connected_state(struct connman_service *service,
6350 enum connman_ipconfig_type type)
6356 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
6358 case CONNMAN_IPCONFIG_TYPE_IPV4:
6359 return is_connected_state(service, service->state_ipv4);
6360 case CONNMAN_IPCONFIG_TYPE_IPV6:
6361 return is_connected_state(service, service->state_ipv6);
6362 case CONNMAN_IPCONFIG_TYPE_ALL:
6363 return is_connected_state(service,
6364 CONNMAN_IPCONFIG_TYPE_IPV4) &&
6365 is_connected_state(service,
6366 CONNMAN_IPCONFIG_TYPE_IPV6);
6371 enum connman_service_security __connman_service_get_security(
6372 struct connman_service *service)
6375 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
6377 return service->security;
6380 const char *__connman_service_get_phase2(struct connman_service *service)
6385 return service->phase2;
6388 bool __connman_service_wps_enabled(struct connman_service *service)
6393 return service->wps;
6396 void __connman_service_mark_dirty(void)
6398 services_dirty = true;
6401 #if defined TIZEN_EXT
6403 * Returns profile count if there is any connected profiles
6404 * that use same interface
6406 int __connman_service_get_connected_count_of_iface(
6407 struct connman_service *service)
6416 index1 = __connman_service_get_index(service);
6421 for (list = service_list; list; list = list->next) {
6422 struct connman_service *service2 = list->data;
6424 if (service == service2)
6427 index2 = __connman_service_get_index(service2);
6429 if (is_connected(service2) && index2 > 0 && index1 == index2)
6435 DBG("Interface index %d, count %d", index1, count);
6440 void __connman_service_set_storage_reload(struct connman_service *service,
6441 bool storage_reload)
6443 if (service != NULL)
6444 service->storage_reload = storage_reload;
6449 * __connman_service_set_favorite_delayed:
6450 * @service: service structure
6451 * @favorite: favorite value
6452 * @delay_ordering: do not order service sequence
6454 * Change the favorite setting of service
6456 int __connman_service_set_favorite_delayed(struct connman_service *service,
6458 bool delay_ordering)
6460 #if defined TIZEN_EXT
6461 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6464 if (service->hidden)
6467 if (service->favorite == favorite)
6470 service->favorite = favorite;
6472 if (!delay_ordering)
6473 __connman_service_get_order(service);
6475 favorite_changed(service);
6477 if (!delay_ordering) {
6479 service_list_sort();
6481 __connman_connection_update_gateway();
6488 * __connman_service_set_favorite:
6489 * @service: service structure
6490 * @favorite: favorite value
6492 * Change the favorite setting of service
6494 int __connman_service_set_favorite(struct connman_service *service,
6497 return __connman_service_set_favorite_delayed(service, favorite,
6501 bool connman_service_get_favorite(struct connman_service *service)
6503 return service->favorite;
6506 bool connman_service_get_autoconnect(struct connman_service *service)
6508 return service->autoconnect;
6511 int __connman_service_set_immutable(struct connman_service *service,
6514 if (service->hidden)
6517 if (service->immutable == immutable)
6520 service->immutable = immutable;
6522 immutable_changed(service);
6527 int __connman_service_set_ignore(struct connman_service *service,
6533 service->ignore = ignore;
6538 void __connman_service_set_string(struct connman_service *service,
6539 const char *key, const char *value)
6541 if (service->hidden)
6543 if (g_str_equal(key, "EAP")) {
6544 g_free(service->eap);
6545 service->eap = g_strdup(value);
6546 } else if (g_str_equal(key, "Identity")) {
6547 g_free(service->identity);
6548 service->identity = g_strdup(value);
6549 } else if (g_str_equal(key, "CACertFile")) {
6550 g_free(service->ca_cert_file);
6551 service->ca_cert_file = g_strdup(value);
6552 } else if (g_str_equal(key, "ClientCertFile")) {
6553 g_free(service->client_cert_file);
6554 service->client_cert_file = g_strdup(value);
6555 } else if (g_str_equal(key, "PrivateKeyFile")) {
6556 g_free(service->private_key_file);
6557 service->private_key_file = g_strdup(value);
6558 } else if (g_str_equal(key, "PrivateKeyPassphrase")) {
6559 g_free(service->private_key_passphrase);
6560 service->private_key_passphrase = g_strdup(value);
6561 } else if (g_str_equal(key, "Phase2")) {
6562 g_free(service->phase2);
6563 service->phase2 = g_strdup(value);
6564 } else if (g_str_equal(key, "Passphrase"))
6565 __connman_service_set_passphrase(service, value);
6568 void __connman_service_set_search_domains(struct connman_service *service,
6571 searchdomain_remove_all(service);
6573 if (service->domains)
6574 g_strfreev(service->domains);
6576 service->domains = g_strdupv(domains);
6578 searchdomain_add_all(service);
6581 static void service_complete(struct connman_service *service)
6583 reply_pending(service, EIO);
6585 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
6586 __connman_service_auto_connect(service->connect_reason);
6588 g_get_current_time(&service->modified);
6589 service_save(service);
6592 static void report_error_cb(void *user_context, bool retry,
6595 struct connman_service *service = user_context;
6598 __connman_service_connect(service,
6599 CONNMAN_SERVICE_CONNECT_REASON_USER);
6601 /* It is not relevant to stay on Failure state
6602 * when failing is due to wrong user input */
6603 __connman_service_clear_error(service);
6604 #if defined TIZEN_EXT
6605 /* Reseting the state back in case of failure state */
6606 service->state_ipv4 = service->state_ipv6 =
6607 CONNMAN_SERVICE_STATE_IDLE;
6609 if (service->error != CONNMAN_SERVICE_ERROR_AUTH_FAILED)
6610 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6612 service_complete(service);
6613 __connman_connection_update_gateway();
6617 static int check_wpspin(struct connman_service *service, const char *wpspin)
6625 length = strlen(wpspin);
6627 /* If 0, it will mean user wants to use PBC method */
6629 connman_network_set_string(service->network,
6630 "WiFi.PinWPS", NULL);
6634 /* A WPS PIN is always 8 chars length,
6635 * its content is in digit representation.
6640 for (i = 0; i < 8; i++)
6641 if (!isdigit((unsigned char) wpspin[i]))
6644 connman_network_set_string(service->network, "WiFi.PinWPS", wpspin);
6649 static void request_input_cb(struct connman_service *service,
6650 bool values_received,
6651 const char *name, int name_len,
6652 const char *identity, const char *passphrase,
6653 bool wps, const char *wpspin,
6654 const char *error, void *user_data)
6656 struct connman_device *device;
6657 const char *security;
6660 DBG("RequestInput return, %p", service);
6663 DBG("error: %s", error);
6665 if (g_strcmp0(error,
6666 "net.connman.Agent.Error.Canceled") == 0) {
6669 if (service->hidden)
6670 __connman_service_return_error(service,
6671 ECANCELED, user_data);
6674 if (service->hidden)
6675 __connman_service_return_error(service,
6676 ETIMEDOUT, user_data);
6680 if (service->hidden && name_len > 0 && name_len <= 32) {
6681 device = connman_network_get_device(service->network);
6682 security = connman_network_get_string(service->network,
6684 err = __connman_device_request_hidden_scan(device,
6686 identity, passphrase,
6687 security, user_data);
6689 __connman_service_return_error(service, -err,
6693 if (!values_received || service->hidden) {
6698 if (wps && service->network) {
6699 err = check_wpspin(service, wpspin);
6703 connman_network_set_bool(service->network, "WiFi.UseWPS", wps);
6707 __connman_service_set_agent_identity(service, identity);
6710 err = __connman_service_set_passphrase(service, passphrase);
6714 /* We forget any previous error. */
6715 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6717 __connman_service_connect(service,
6718 CONNMAN_SERVICE_CONNECT_REASON_USER);
6720 } else if (err == -ENOKEY) {
6721 __connman_service_indicate_error(service,
6722 CONNMAN_SERVICE_ERROR_INVALID_KEY);
6724 /* It is not relevant to stay on Failure state
6725 * when failing is due to wrong user input */
6726 service->state = CONNMAN_SERVICE_STATE_IDLE;
6728 if (!service->hidden) {
6730 * If there was a real error when requesting
6731 * hidden scan, then that error is returned already
6732 * to the user somewhere above so do not try to
6735 __connman_service_return_error(service, -err,
6739 service_complete(service);
6740 __connman_connection_update_gateway();
6744 static void downgrade_connected_services(void)
6746 struct connman_service *up_service;
6749 for (list = service_list; list; list = list->next) {
6750 up_service = list->data;
6752 if (!is_connected(up_service))
6755 if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
6758 downgrade_state(up_service);
6762 static int service_update_preferred_order(struct connman_service *default_service,
6763 struct connman_service *new_service,
6764 enum connman_service_state new_state)
6766 unsigned int *tech_array;
6769 if (!default_service || default_service == new_service ||
6770 default_service->state != new_state)
6773 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
6776 for (i = 0; tech_array[i] != 0; i += 1) {
6777 if (default_service->type == tech_array[i])
6780 if (new_service->type == tech_array[i]) {
6781 switch_default_service(default_service,
6783 __connman_connection_update_gateway();
6792 #if defined TIZEN_EXT
6793 static gboolean __connman_service_can_drop(struct connman_service *service)
6795 if (is_connected(service) == TRUE || is_connecting(service) == TRUE) {
6796 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
6798 else if (connman_service_is_no_ref_user_pdn_connection(service) == TRUE)
6804 static struct connman_device *default_connecting_device = NULL;
6806 static void __connman_service_disconnect_default(struct connman_service *service)
6808 struct connman_device *default_device = NULL;
6810 if (default_connecting_device == NULL)
6813 default_device = connman_network_get_device(
6814 __connman_service_get_network(service));
6816 DBG("Disconnecting service %p %s", service, service->path);
6817 DBG("Disconnecting device %p %p %s",
6818 default_connecting_device,
6820 connman_device_get_string(default_device, "Name"));
6822 if (default_connecting_device == default_device)
6823 default_connecting_device = NULL;
6826 static void __connman_service_connect_default(struct connman_service *current)
6830 bool default_internet;
6831 struct connman_service *service;
6832 struct connman_service *default_service = NULL;
6833 struct connman_device *default_device = NULL;
6835 if (current->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
6836 switch (current->state) {
6837 case CONNMAN_SERVICE_STATE_UNKNOWN:
6838 case CONNMAN_SERVICE_STATE_ASSOCIATION:
6839 case CONNMAN_SERVICE_STATE_CONFIGURATION:
6845 if (default_connecting_device &&
6846 __connman_service_is_internet_profile(current) == TRUE) {
6847 if (current->network == NULL)
6850 default_device = connman_network_get_device(current->network);
6851 if (default_connecting_device == default_device) {
6852 DBG("Cellular service[%s] %p %s",
6853 state2string(current->state), current, current->path);
6854 DBG("Cellular device %p %p %s",
6855 default_connecting_device, default_device,
6856 connman_device_get_string(default_device, "Name"));
6858 default_connecting_device = NULL;
6863 } else if (is_connected(current) == TRUE || is_connecting(current) == TRUE)
6866 /* Always-on: keep default cellular connection as possible */
6867 for (list = service_list; list; list = list->next) {
6868 service = list->data;
6870 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
6871 __connman_service_is_internet_profile(service) != TRUE ||
6872 service->network == NULL) {
6877 connman_network_get_bool(service->network, "DefaultInternet");
6879 DBG("service: %p %s %s %s (default: %d)", service, service->name,
6880 __connman_service_type2string(service->type),
6881 state2string(service->state), default_internet);
6883 if (default_internet) {
6884 default_service = service;
6885 if (is_connected(default_service) == TRUE ||
6886 is_connecting(default_service) == TRUE)
6889 default_device = connman_network_get_device(default_service->network);
6890 if (default_connecting_device == default_device) {
6891 DBG("Device is connecting (%p)", default_connecting_device);
6895 default_connecting_device = default_device;
6896 default_service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_USER;
6898 err = __connman_network_connect(default_service->network);
6899 DBG("Connecting default service %p %s [%d]",
6900 default_service, default_service->path, err);
6901 DBG("Connecting device %p %s", default_connecting_device,
6902 connman_device_get_string(default_connecting_device, "Name"));
6903 if (err < 0 && err != -EINPROGRESS) {
6904 default_connecting_device = NULL;
6912 static void single_connected_tech(struct connman_service *allowed)
6914 struct connman_service *service;
6915 GSList *services = NULL, *list;
6918 DBG("keeping %p %s", allowed, allowed->path);
6920 #if defined TIZEN_EXT
6921 if (!allowed || allowed->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6925 for (iter = service_list; iter; iter = iter->next) {
6926 service = iter->data;
6928 #if defined TIZEN_EXT
6929 if (service != allowed && service->type != allowed->type &&
6930 __connman_service_can_drop(service) == TRUE)
6932 if (!is_connected(service))
6935 if (service == allowed)
6938 services = g_slist_prepend(services, service);
6941 for (list = services; list; list = list->next) {
6942 service = list->data;
6944 DBG("disconnecting %p %s", service, service->path);
6945 #if defined TIZEN_EXT
6946 __connman_service_disconnect_default(service);
6948 __connman_service_disconnect(service);
6951 g_slist_free(services);
6954 #if defined TIZEN_EXT
6955 static void set_priority_connected_service(void)
6957 struct connman_service *service;
6960 for (list = service_list; list; list = list->next) {
6961 service = list->data;
6963 if (is_connected(service) == FALSE)
6971 static const char *get_dbus_sender(struct connman_service *service)
6973 if (!service->pending)
6976 return dbus_message_get_sender(service->pending);
6979 static int service_indicate_state(struct connman_service *service)
6981 enum connman_service_state old_state, new_state;
6982 struct connman_service *def_service;
6983 enum connman_ipconfig_method method;
6989 old_state = service->state;
6990 new_state = combine_state(service->state_ipv4, service->state_ipv6);
6992 DBG("service %p old %s - new %s/%s => %s",
6994 state2string(old_state),
6995 state2string(service->state_ipv4),
6996 state2string(service->state_ipv6),
6997 state2string(new_state));
6999 if (old_state == new_state)
7002 def_service = __connman_service_get_default();
7004 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
7005 result = service_update_preferred_order(def_service,
7006 service, new_state);
7007 if (result == -EALREADY)
7011 if (old_state == CONNMAN_SERVICE_STATE_ONLINE)
7012 __connman_notifier_leave_online(service->type);
7014 if (is_connected_state(service, old_state) &&
7015 !is_connected_state(service, new_state))
7016 searchdomain_remove_all(service);
7018 service->state = new_state;
7019 state_changed(service);
7022 case CONNMAN_SERVICE_STATE_UNKNOWN:
7026 case CONNMAN_SERVICE_STATE_IDLE:
7027 if (old_state != CONNMAN_SERVICE_STATE_DISCONNECT)
7028 __connman_service_disconnect(service);
7032 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7036 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7037 if (!service->new_service &&
7038 __connman_stats_service_register(service) == 0) {
7040 * For new services the statistics are updated after
7041 * we have successfully connected.
7043 __connman_stats_get(service, false,
7044 &service->stats.data);
7045 __connman_stats_get(service, true,
7046 &service->stats_roaming.data);
7051 case CONNMAN_SERVICE_STATE_READY:
7052 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7054 if (service->new_service &&
7055 __connman_stats_service_register(service) == 0) {
7057 * This is normally done after configuring state
7058 * but for new service do this after we have connected
7061 __connman_stats_get(service, false,
7062 &service->stats.data);
7063 __connman_stats_get(service, true,
7064 &service->stats_roaming.data);
7067 service->new_service = false;
7071 def_service = __connman_service_get_default();
7073 service_update_preferred_order(def_service, service, new_state);
7075 __connman_service_set_favorite(service, true);
7077 reply_pending(service, 0);
7079 g_get_current_time(&service->modified);
7080 service_save(service);
7082 searchdomain_add_all(service);
7083 dns_changed(service);
7084 domain_changed(service);
7085 proxy_changed(service);
7087 if (old_state != CONNMAN_SERVICE_STATE_ONLINE)
7088 __connman_notifier_connect(service->type);
7090 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7091 connman_network_get_bool(service->network,
7095 pass = connman_network_get_string(service->network,
7098 __connman_service_set_passphrase(service, pass);
7100 connman_network_set_bool(service->network,
7101 "WiFi.UseWPS", false);
7104 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
7105 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
7106 __connman_ipconfig_disable_ipv6(
7107 service->ipconfig_ipv6);
7109 if (connman_setting_get_bool("SingleConnectedTechnology"))
7110 single_connected_tech(service);
7111 else if (service->type != CONNMAN_SERVICE_TYPE_VPN)
7114 #if defined TIZEN_EXT
7115 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7116 set_priority_connected_service();
7121 case CONNMAN_SERVICE_STATE_ONLINE:
7125 case CONNMAN_SERVICE_STATE_DISCONNECT:
7126 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7128 reply_pending(service, ECONNABORTED);
7130 def_service = __connman_service_get_default();
7131 service->disconnect_reason = connman_network_get_disconnect_reason(service->network);
7133 if (!__connman_notifier_is_connected() &&
7135 def_service->provider)
7136 connman_provider_disconnect(def_service->provider);
7140 __connman_wispr_stop(service);
7142 __connman_wpad_stop(service);
7144 #if defined TIZEN_EXT
7146 * Skip the functions if there is any connected profiles
7147 * that use same interface
7149 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7150 __connman_service_get_connected_count_of_iface(
7153 dns_changed(service);
7154 domain_changed(service);
7155 proxy_changed(service);
7156 #if defined TIZEN_EXT
7161 * Previous services which are connected and which states
7162 * are set to online should reset relevantly ipconfig_state
7163 * to ready so wispr/portal will be rerun on those
7165 downgrade_connected_services();
7167 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7170 case CONNMAN_SERVICE_STATE_FAILURE:
7171 #if defined TIZEN_EXT
7172 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7174 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7176 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7177 connman_agent_report_error(service, service->path,
7178 error2string(service->error),
7180 get_dbus_sender(service),
7181 NULL) == -EINPROGRESS)
7183 service_complete(service);
7188 service_list_sort();
7190 #if defined TIZEN_EXT
7191 __connman_service_connect_default(service);
7194 __connman_connection_update_gateway();
7196 if ((old_state == CONNMAN_SERVICE_STATE_ONLINE &&
7197 new_state != CONNMAN_SERVICE_STATE_READY) ||
7198 (old_state == CONNMAN_SERVICE_STATE_READY &&
7199 new_state != CONNMAN_SERVICE_STATE_ONLINE)) {
7200 __connman_notifier_disconnect(service->type);
7203 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
7204 __connman_notifier_enter_online(service->type);
7208 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7209 service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7210 (new_state == CONNMAN_SERVICE_STATE_READY ||
7211 new_state == CONNMAN_SERVICE_STATE_ONLINE)) {
7212 if (service->user.favorite_user != service->user.current_user) {
7213 DBG("Now set service favorite user id from %d to %d",
7214 service->user.favorite_user, service->user.current_user);
7216 service->user.favorite_user = service->user.current_user;
7218 service_save(service);
7225 int __connman_service_indicate_error(struct connman_service *service,
7226 enum connman_service_error error)
7228 DBG("service %p error %d", service, error);
7233 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
7236 set_error(service, error);
7238 /* default internet service: fix not cleared if pdp activation*/
7239 #if defined TIZEN_EXT
7241 * If connection failed for default service(DefaultInternet),
7242 * default_connecting_device should be cleared.
7244 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7245 service->error == CONNMAN_SERVICE_ERROR_CONNECT_FAILED)
7246 __connman_service_disconnect_default(service);
7248 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7249 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY) {
7250 g_free(service->passphrase);
7251 service->passphrase = NULL;
7255 __connman_service_ipconfig_indicate_state(service,
7256 CONNMAN_SERVICE_STATE_FAILURE,
7257 CONNMAN_IPCONFIG_TYPE_IPV4);
7258 __connman_service_ipconfig_indicate_state(service,
7259 CONNMAN_SERVICE_STATE_FAILURE,
7260 CONNMAN_IPCONFIG_TYPE_IPV6);
7264 int __connman_service_clear_error(struct connman_service *service)
7266 DBusMessage *pending, *provider_pending;
7268 DBG("service %p", service);
7273 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
7276 pending = service->pending;
7277 service->pending = NULL;
7278 provider_pending = service->provider_pending;
7279 service->provider_pending = NULL;
7281 __connman_service_ipconfig_indicate_state(service,
7282 CONNMAN_SERVICE_STATE_IDLE,
7283 CONNMAN_IPCONFIG_TYPE_IPV6);
7285 __connman_service_ipconfig_indicate_state(service,
7286 CONNMAN_SERVICE_STATE_IDLE,
7287 CONNMAN_IPCONFIG_TYPE_IPV4);
7289 service->pending = pending;
7290 service->provider_pending = provider_pending;
7295 int __connman_service_indicate_default(struct connman_service *service)
7297 DBG("service %p state %s", service, state2string(service->state));
7299 if (!is_connected(service)) {
7301 * If service is not yet fully connected, then we must not
7302 * change the default yet. The default gw will be changed
7303 * after the service state is in ready.
7305 return -EINPROGRESS;
7313 enum connman_service_state __connman_service_ipconfig_get_state(
7314 struct connman_service *service,
7315 enum connman_ipconfig_type type)
7318 return CONNMAN_SERVICE_STATE_UNKNOWN;
7320 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7321 return service->state_ipv4;
7323 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
7324 return service->state_ipv6;
7326 return CONNMAN_SERVICE_STATE_UNKNOWN;
7329 static void check_proxy_setup(struct connman_service *service)
7332 * We start WPAD if we haven't got a PAC URL from DHCP and
7333 * if our proxy manual configuration is either empty or set
7334 * to AUTO with an empty URL.
7337 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
7340 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
7341 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
7345 if (__connman_wpad_start(service) < 0) {
7346 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
7347 __connman_notifier_proxy_changed(service);
7354 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
7357 #if defined TIZEN_EXT
7358 void connman_check_proxy_setup_and_wispr_start(struct connman_service *service){
7360 DBG("check the proxy and start wispr");
7361 check_proxy_setup(service);
7367 * How many networks are connected at the same time. If more than 1,
7368 * then set the rp_filter setting properly (loose mode routing) so that network
7369 * connectivity works ok. This is only done for IPv4 networks as IPv6
7370 * does not have rp_filter knob.
7372 static int connected_networks_count;
7373 static int original_rp_filter;
7375 static void service_rp_filter(struct connman_service *service,
7378 enum connman_ipconfig_method method;
7380 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
7383 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7384 case CONNMAN_IPCONFIG_METHOD_OFF:
7385 case CONNMAN_IPCONFIG_METHOD_AUTO:
7387 case CONNMAN_IPCONFIG_METHOD_FIXED:
7388 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7389 case CONNMAN_IPCONFIG_METHOD_DHCP:
7394 if (connected_networks_count == 1) {
7396 filter_value = __connman_ipconfig_set_rp_filter();
7397 if (filter_value < 0)
7400 original_rp_filter = filter_value;
7402 connected_networks_count++;
7405 if (connected_networks_count == 2)
7406 __connman_ipconfig_unset_rp_filter(original_rp_filter);
7408 connected_networks_count--;
7409 if (connected_networks_count < 0)
7410 connected_networks_count = 0;
7413 DBG("%s %s ipconfig %p method %d count %d filter %d",
7414 connected ? "connected" : "disconnected", service->identifier,
7415 service->ipconfig_ipv4, method,
7416 connected_networks_count, original_rp_filter);
7419 static gboolean redo_wispr(gpointer user_data)
7421 struct connman_service *service = user_data;
7422 int refcount = service->refcount - 1;
7424 connman_service_unref(service);
7425 if (refcount == 0) {
7426 DBG("Service %p already removed", service);
7430 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV6);
7435 int __connman_service_online_check_failed(struct connman_service *service,
7436 enum connman_ipconfig_type type)
7438 DBG("service %p type %d count %d", service, type,
7439 service->online_check_count);
7441 /* currently we only retry IPv6 stuff */
7442 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 ||
7443 service->online_check_count != 1) {
7444 connman_warn("Online check failed for %p %s", service,
7449 service->online_check_count = 0;
7452 * We set the timeout to 1 sec so that we have a chance to get
7453 * necessary IPv6 router advertisement messages that might have
7456 g_timeout_add_seconds(1, redo_wispr, connman_service_ref(service));
7461 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
7462 enum connman_service_state new_state,
7463 enum connman_ipconfig_type type)
7465 struct connman_ipconfig *ipconfig = NULL;
7466 enum connman_service_state old_state;
7467 enum connman_ipconfig_method method;
7473 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
7474 case CONNMAN_IPCONFIG_TYPE_ALL:
7477 case CONNMAN_IPCONFIG_TYPE_IPV4:
7478 old_state = service->state_ipv4;
7479 ipconfig = service->ipconfig_ipv4;
7483 case CONNMAN_IPCONFIG_TYPE_IPV6:
7484 old_state = service->state_ipv6;
7485 ipconfig = service->ipconfig_ipv6;
7494 if (old_state == new_state)
7497 #if defined TIZEN_EXT
7498 __sync_synchronize();
7499 if (service->user_pdn_connection_refcount > 0 &&
7500 service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7501 if (new_state == CONNMAN_SERVICE_STATE_FAILURE ||
7502 new_state == CONNMAN_SERVICE_STATE_DISCONNECT ||
7503 new_state == CONNMAN_SERVICE_STATE_IDLE) {
7504 service->user_pdn_connection_refcount = 0;
7505 __sync_synchronize();
7509 DBG("service %p (%s) old state %d (%s) new state %d (%s) type %d (%s)",
7510 service, service ? service->identifier : NULL,
7511 old_state, state2string(old_state),
7512 new_state, state2string(new_state),
7513 type, __connman_ipconfig_type2string(type));
7515 switch (new_state) {
7516 case CONNMAN_SERVICE_STATE_UNKNOWN:
7517 case CONNMAN_SERVICE_STATE_IDLE:
7518 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7520 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7521 __connman_ipconfig_enable(ipconfig);
7523 case CONNMAN_SERVICE_STATE_READY:
7524 #if defined TIZEN_EXT
7525 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7526 __connman_service_is_internet_profile(service) != TRUE) {
7527 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7528 service_rp_filter(service, TRUE);
7533 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
7534 #if !defined TIZEN_EXT
7535 check_proxy_setup(service);
7537 service_rp_filter(service, true);
7539 service->online_check_count = 1;
7540 __connman_wispr_start(service, type);
7543 case CONNMAN_SERVICE_STATE_ONLINE:
7545 case CONNMAN_SERVICE_STATE_DISCONNECT:
7546 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
7549 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7550 service_rp_filter(service, false);
7553 case CONNMAN_SERVICE_STATE_FAILURE:
7557 /* Keep that state, but if the ipconfig method is OFF, then we set
7558 the state to IDLE so that it will not affect the combined state
7561 method = __connman_ipconfig_get_method(ipconfig);
7563 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7564 case CONNMAN_IPCONFIG_METHOD_OFF:
7565 new_state = CONNMAN_SERVICE_STATE_IDLE;
7568 case CONNMAN_IPCONFIG_METHOD_FIXED:
7569 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7570 case CONNMAN_IPCONFIG_METHOD_DHCP:
7571 case CONNMAN_IPCONFIG_METHOD_AUTO:
7576 if (is_connected_state(service, old_state) &&
7577 !is_connected_state(service, new_state))
7578 #if defined TIZEN_EXT
7580 DBG("nameserver remove all, type: %d", type);
7581 nameserver_remove_all(service, type);
7583 nameserver_remove_all(service);
7585 #if defined TIZEN_EXT
7589 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7590 service->state_ipv4 = new_state;
7592 service->state_ipv6 = new_state;
7594 if (!is_connected_state(service, old_state) &&
7595 is_connected_state(service, new_state))
7596 #if defined TIZEN_EXT
7598 DBG("nameserver add all, type: %d", type);
7599 nameserver_add_all(service, type);
7601 nameserver_add_all(service);
7603 #if defined TIZEN_EXT
7607 #if defined TIZEN_EXT
7608 int ret = service_indicate_state(service);
7609 /*Sent the Ready changed signal again in case IPv4 IP set
7612 if(ret == -EALREADY && type == CONNMAN_IPCONFIG_TYPE_IPV4
7613 && new_state == CONNMAN_SERVICE_STATE_READY) {
7614 DBG("Notify IPv4 state new/old %d/%d", new_state,old_state);
7615 state_changed(service);
7620 return service_indicate_state(service);
7623 static bool prepare_network(struct connman_service *service)
7625 enum connman_network_type type;
7626 unsigned int ssid_len;
7628 type = connman_network_get_type(service->network);
7631 case CONNMAN_NETWORK_TYPE_UNKNOWN:
7632 case CONNMAN_NETWORK_TYPE_VENDOR:
7634 case CONNMAN_NETWORK_TYPE_WIFI:
7635 if (!connman_network_get_blob(service->network, "WiFi.SSID",
7639 if (service->passphrase)
7640 connman_network_set_string(service->network,
7641 "WiFi.Passphrase", service->passphrase);
7643 case CONNMAN_NETWORK_TYPE_ETHERNET:
7644 case CONNMAN_NETWORK_TYPE_GADGET:
7645 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
7646 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
7647 case CONNMAN_NETWORK_TYPE_CELLULAR:
7654 static void prepare_8021x(struct connman_service *service)
7657 connman_network_set_string(service->network, "WiFi.EAP",
7660 if (service->identity)
7661 connman_network_set_string(service->network, "WiFi.Identity",
7664 if (service->ca_cert_file)
7665 connman_network_set_string(service->network, "WiFi.CACertFile",
7666 service->ca_cert_file);
7668 if (service->client_cert_file)
7669 connman_network_set_string(service->network,
7670 "WiFi.ClientCertFile",
7671 service->client_cert_file);
7673 if (service->private_key_file)
7674 connman_network_set_string(service->network,
7675 "WiFi.PrivateKeyFile",
7676 service->private_key_file);
7678 if (service->private_key_passphrase)
7679 connman_network_set_string(service->network,
7680 "WiFi.PrivateKeyPassphrase",
7681 service->private_key_passphrase);
7683 if (service->phase2)
7684 connman_network_set_string(service->network, "WiFi.Phase2",
7688 static int service_connect(struct connman_service *service)
7692 if (service->hidden)
7695 #if defined TIZEN_EXT
7699 index = __connman_service_get_index(service);
7701 for (list = service_list; list; list = list->next) {
7702 struct connman_service *temp = list->data;
7704 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7707 if (!is_connecting(temp) && !is_connected(temp))
7710 if (service == temp)
7713 if (service->type != temp->type)
7716 if (__connman_service_get_index(temp) == index &&
7717 __connman_service_disconnect(temp) == -EINPROGRESS)
7718 return -EINPROGRESS;
7722 switch (service->type) {
7723 case CONNMAN_SERVICE_TYPE_UNKNOWN:
7724 case CONNMAN_SERVICE_TYPE_SYSTEM:
7725 case CONNMAN_SERVICE_TYPE_GPS:
7726 case CONNMAN_SERVICE_TYPE_P2P:
7728 case CONNMAN_SERVICE_TYPE_ETHERNET:
7729 case CONNMAN_SERVICE_TYPE_GADGET:
7730 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
7731 case CONNMAN_SERVICE_TYPE_CELLULAR:
7732 case CONNMAN_SERVICE_TYPE_VPN:
7734 case CONNMAN_SERVICE_TYPE_WIFI:
7735 switch (service->security) {
7736 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
7737 case CONNMAN_SERVICE_SECURITY_NONE:
7739 case CONNMAN_SERVICE_SECURITY_WEP:
7740 case CONNMAN_SERVICE_SECURITY_PSK:
7741 case CONNMAN_SERVICE_SECURITY_WPA:
7742 case CONNMAN_SERVICE_SECURITY_RSN:
7743 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
7746 if (service->request_passphrase_input) {
7747 DBG("Now try to connect other user's favorite service");
7748 service->request_passphrase_input = false;
7750 } else if (!service->passphrase) {
7751 if (!service->network)
7754 if (!service->wps ||
7755 !connman_network_get_bool(service->network, "WiFi.UseWPS"))
7760 case CONNMAN_SERVICE_SECURITY_8021X:
7764 #if defined TIZEN_EXT
7766 * never request credentials if using EAP-TLS, EAP-SIM
7767 * or EAP-AKA (EAP-TLS, EAP-SIM and EAP-AKA networks
7768 * need to be fully provisioned)
7770 DBG("service eap: %s", service->eap);
7771 if (g_str_equal(service->eap, "tls") ||
7772 g_str_equal(service->eap, "sim") ||
7773 g_str_equal(service->eap, "aka"))
7777 * never request credentials if using EAP-TLS
7778 * (EAP-TLS networks need to be fully provisioned)
7780 if (g_str_equal(service->eap, "tls"))
7784 * Return -ENOKEY if either identity or passphrase is
7785 * missing. Agent provided credentials can be used as
7786 * fallback if needed.
7788 if (((!service->identity &&
7789 !service->agent_identity) ||
7790 !service->passphrase) ||
7791 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
7799 if (service->network) {
7800 if (!prepare_network(service))
7803 switch (service->security) {
7804 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
7805 case CONNMAN_SERVICE_SECURITY_NONE:
7806 case CONNMAN_SERVICE_SECURITY_WEP:
7807 case CONNMAN_SERVICE_SECURITY_PSK:
7808 case CONNMAN_SERVICE_SECURITY_WPA:
7809 case CONNMAN_SERVICE_SECURITY_RSN:
7811 case CONNMAN_SERVICE_SECURITY_8021X:
7812 prepare_8021x(service);
7816 if (__connman_stats_service_register(service) == 0) {
7817 __connman_stats_get(service, false,
7818 &service->stats.data);
7819 __connman_stats_get(service, true,
7820 &service->stats_roaming.data);
7823 if (service->ipconfig_ipv4)
7824 __connman_ipconfig_enable(service->ipconfig_ipv4);
7825 if (service->ipconfig_ipv6)
7826 __connman_ipconfig_enable(service->ipconfig_ipv6);
7828 err = __connman_network_connect(service->network);
7829 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7831 err = __connman_provider_connect(service->provider);
7836 if (err != -EINPROGRESS) {
7837 __connman_ipconfig_disable(service->ipconfig_ipv4);
7838 __connman_ipconfig_disable(service->ipconfig_ipv6);
7839 __connman_stats_service_unregister(service);
7846 int __connman_service_connect(struct connman_service *service,
7847 enum connman_service_connect_reason reason)
7851 DBG("service %p state %s connect reason %s -> %s",
7852 service, state2string(service->state),
7853 reason2string(service->connect_reason),
7854 reason2string(reason));
7856 if (is_connected(service))
7859 if (is_connecting(service))
7862 switch (service->type) {
7863 case CONNMAN_SERVICE_TYPE_UNKNOWN:
7864 case CONNMAN_SERVICE_TYPE_SYSTEM:
7865 case CONNMAN_SERVICE_TYPE_GPS:
7866 case CONNMAN_SERVICE_TYPE_P2P:
7869 case CONNMAN_SERVICE_TYPE_ETHERNET:
7870 case CONNMAN_SERVICE_TYPE_GADGET:
7871 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
7872 case CONNMAN_SERVICE_TYPE_CELLULAR:
7873 case CONNMAN_SERVICE_TYPE_VPN:
7874 case CONNMAN_SERVICE_TYPE_WIFI:
7878 if (!is_ipconfig_usable(service))
7881 __connman_service_clear_error(service);
7883 err = service_connect(service);
7885 service->connect_reason = reason;
7889 if (err == -EINPROGRESS) {
7890 if (service->timeout == 0)
7891 service->timeout = g_timeout_add_seconds(
7892 CONNECT_TIMEOUT, connect_timeout, service);
7894 return -EINPROGRESS;
7897 if (service->network)
7898 __connman_network_disconnect(service->network);
7899 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7901 connman_provider_disconnect(service->provider);
7903 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
7904 if (err == -ENOKEY || err == -EPERM) {
7905 DBusMessage *pending = NULL;
7908 * We steal the reply here. The idea is that the
7909 * connecting client will see the connection status
7910 * after the real hidden network is connected or
7911 * connection failed.
7913 if (service->hidden) {
7914 pending = service->pending;
7915 service->pending = NULL;
7918 err = __connman_agent_request_passphrase_input(service,
7920 get_dbus_sender(service),
7922 if (service->hidden && err != -EINPROGRESS)
7923 service->pending = pending;
7927 reply_pending(service, -err);
7933 int __connman_service_disconnect(struct connman_service *service)
7937 DBG("service %p", service);
7939 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
7940 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
7942 connman_agent_cancel(service);
7944 reply_pending(service, ECONNABORTED);
7946 if (service->network) {
7947 err = __connman_network_disconnect(service->network);
7948 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7950 err = connman_provider_disconnect(service->provider);
7954 if (err < 0 && err != -EINPROGRESS)
7957 __connman_6to4_remove(service->ipconfig_ipv4);
7959 if (service->ipconfig_ipv4)
7960 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
7963 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
7966 #if defined TIZEN_EXT
7968 * Skip the functions If there is any connected profiles
7969 * that use same interface
7971 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7972 __connman_service_get_connected_count_of_iface(service) <= 0) {
7974 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
7975 settings_changed(service, service->ipconfig_ipv4);
7977 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
7978 settings_changed(service, service->ipconfig_ipv6);
7980 __connman_ipconfig_disable(service->ipconfig_ipv4);
7981 __connman_ipconfig_disable(service->ipconfig_ipv6);
7982 #if defined TIZEN_EXT
7986 __connman_stats_service_unregister(service);
7991 int __connman_service_disconnect_all(void)
7993 struct connman_service *service;
7994 GSList *services = NULL, *list;
7999 for (iter = service_list; iter; iter = iter->next) {
8000 service = iter->data;
8002 if (!is_connected(service))
8005 services = g_slist_prepend(services, service);
8008 for (list = services; list; list = list->next) {
8009 struct connman_service *service = list->data;
8011 service->ignore = true;
8013 __connman_service_disconnect(service);
8016 g_slist_free(services);
8022 * lookup_by_identifier:
8023 * @identifier: service identifier
8025 * Look up a service by identifier (reference count will not be increased)
8027 static struct connman_service *lookup_by_identifier(const char *identifier)
8029 return g_hash_table_lookup(service_hash, identifier);
8032 struct provision_user_data {
8037 static void provision_changed(gpointer value, gpointer user_data)
8039 struct connman_service *service = value;
8040 struct provision_user_data *data = user_data;
8041 const char *path = data->ident;
8044 ret = __connman_config_provision_service_ident(service, path,
8045 service->config_file, service->config_entry);
8050 int __connman_service_provision_changed(const char *ident)
8052 struct provision_user_data data = {
8057 g_list_foreach(service_list, provision_changed, (void *)&data);
8060 * Because the provision_changed() might have set some services
8061 * as favorite, we must sort the sequence now.
8063 if (services_dirty) {
8064 services_dirty = false;
8066 service_list_sort();
8068 __connman_connection_update_gateway();
8074 void __connman_service_set_config(struct connman_service *service,
8075 const char *file_id, const char *entry)
8080 g_free(service->config_file);
8081 service->config_file = g_strdup(file_id);
8083 g_free(service->config_entry);
8084 service->config_entry = g_strdup(entry);
8088 * __connman_service_get:
8089 * @identifier: service identifier
8091 * Look up a service by identifier or create a new one if not found
8093 static struct connman_service *service_get(const char *identifier)
8095 struct connman_service *service;
8097 service = g_hash_table_lookup(service_hash, identifier);
8099 connman_service_ref(service);
8103 service = connman_service_create();
8107 DBG("service %p", service);
8109 service->identifier = g_strdup(identifier);
8111 service_list = g_list_insert_sorted(service_list, service,
8114 g_hash_table_insert(service_hash, service->identifier, service);
8119 static int service_register(struct connman_service *service)
8121 DBG("service %p", service);
8126 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
8127 service->identifier);
8129 DBG("path %s", service->path);
8131 if (__connman_config_provision_service(service) < 0)
8132 service_load(service);
8134 g_dbus_register_interface(connection, service->path,
8135 CONNMAN_SERVICE_INTERFACE,
8136 service_methods, service_signals,
8137 NULL, service, NULL);
8139 service_list_sort();
8141 __connman_connection_update_gateway();
8146 static void service_up(struct connman_ipconfig *ipconfig,
8149 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8151 DBG("%s up", ifname);
8153 link_changed(service);
8155 service->stats.valid = false;
8156 service->stats_roaming.valid = false;
8159 static void service_down(struct connman_ipconfig *ipconfig,
8162 DBG("%s down", ifname);
8165 static void service_lower_up(struct connman_ipconfig *ipconfig,
8168 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8170 DBG("%s lower up", ifname);
8172 stats_start(service);
8175 static void service_lower_down(struct connman_ipconfig *ipconfig,
8178 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8180 DBG("%s lower down", ifname);
8182 if (!is_idle_state(service, service->state_ipv4))
8183 __connman_ipconfig_disable(service->ipconfig_ipv4);
8185 if (!is_idle_state(service, service->state_ipv6))
8186 __connman_ipconfig_disable(service->ipconfig_ipv6);
8188 stats_stop(service);
8189 service_save(service);
8192 static void service_ip_bound(struct connman_ipconfig *ipconfig,
8195 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8196 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8197 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8198 #if defined TIZEN_EXT
8202 DBG("%s ip bound", ifname);
8204 type = __connman_ipconfig_get_config_type(ipconfig);
8205 method = __connman_ipconfig_get_method(ipconfig);
8207 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8210 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8211 method == CONNMAN_IPCONFIG_METHOD_AUTO)
8212 #if defined TIZEN_EXT
8214 err = __connman_ipconfig_gateway_add(ipconfig, service);
8217 __connman_connection_gateway_activate(service,
8218 CONNMAN_IPCONFIG_TYPE_IPV6);
8221 __connman_service_ipconfig_indicate_state(service,
8222 CONNMAN_SERVICE_STATE_READY,
8223 CONNMAN_IPCONFIG_TYPE_IPV6);
8226 settings_changed(service, ipconfig);
8229 static void service_ip_release(struct connman_ipconfig *ipconfig,
8232 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8233 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8234 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8236 DBG("%s ip release", ifname);
8238 type = __connman_ipconfig_get_config_type(ipconfig);
8239 method = __connman_ipconfig_get_method(ipconfig);
8241 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8244 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8245 method == CONNMAN_IPCONFIG_METHOD_OFF)
8246 __connman_service_ipconfig_indicate_state(service,
8247 CONNMAN_SERVICE_STATE_DISCONNECT,
8248 CONNMAN_IPCONFIG_TYPE_IPV6);
8250 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
8251 method == CONNMAN_IPCONFIG_METHOD_OFF)
8252 __connman_service_ipconfig_indicate_state(service,
8253 CONNMAN_SERVICE_STATE_DISCONNECT,
8254 CONNMAN_IPCONFIG_TYPE_IPV4);
8256 settings_changed(service, ipconfig);
8259 static void service_route_changed(struct connman_ipconfig *ipconfig,
8262 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8264 DBG("%s route changed", ifname);
8266 settings_changed(service, ipconfig);
8269 static const struct connman_ipconfig_ops service_ops = {
8271 .down = service_down,
8272 .lower_up = service_lower_up,
8273 .lower_down = service_lower_down,
8274 .ip_bound = service_ip_bound,
8275 .ip_release = service_ip_release,
8276 .route_set = service_route_changed,
8277 .route_unset = service_route_changed,
8280 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
8281 int index, enum connman_ipconfig_method method)
8283 struct connman_ipconfig *ipconfig_ipv4;
8285 ipconfig_ipv4 = __connman_ipconfig_create(index,
8286 CONNMAN_IPCONFIG_TYPE_IPV4);
8290 __connman_ipconfig_set_method(ipconfig_ipv4, method);
8292 __connman_ipconfig_set_data(ipconfig_ipv4, service);
8294 __connman_ipconfig_set_ops(ipconfig_ipv4, &service_ops);
8296 return ipconfig_ipv4;
8299 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
8302 struct connman_ipconfig *ipconfig_ipv6;
8304 ipconfig_ipv6 = __connman_ipconfig_create(index,
8305 CONNMAN_IPCONFIG_TYPE_IPV6);
8309 __connman_ipconfig_set_data(ipconfig_ipv6, service);
8311 __connman_ipconfig_set_ops(ipconfig_ipv6, &service_ops);
8313 return ipconfig_ipv6;
8316 void __connman_service_read_ip4config(struct connman_service *service)
8320 if (!service->ipconfig_ipv4)
8323 keyfile = connman_storage_load_service(service->identifier);
8327 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
8328 service->identifier, "IPv4.");
8330 g_key_file_free(keyfile);
8333 void connman_service_create_ip4config(struct connman_service *service,
8336 DBG("ipv4 %p", service->ipconfig_ipv4);
8338 if (service->ipconfig_ipv4)
8341 service->ipconfig_ipv4 = create_ip4config(service, index,
8342 CONNMAN_IPCONFIG_METHOD_DHCP);
8343 __connman_service_read_ip4config(service);
8346 void __connman_service_read_ip6config(struct connman_service *service)
8350 if (!service->ipconfig_ipv6)
8353 keyfile = connman_storage_load_service(service->identifier);
8357 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
8358 service->identifier, "IPv6.");
8360 g_key_file_free(keyfile);
8363 void connman_service_create_ip6config(struct connman_service *service,
8366 DBG("ipv6 %p", service->ipconfig_ipv6);
8368 if (service->ipconfig_ipv6)
8371 service->ipconfig_ipv6 = create_ip6config(service, index);
8373 __connman_service_read_ip6config(service);
8377 * connman_service_lookup_from_network:
8378 * @network: network structure
8380 * Look up a service by network (reference count will not be increased)
8382 struct connman_service *connman_service_lookup_from_network(struct connman_network *network)
8384 struct connman_service *service;
8385 const char *ident, *group;
8391 ident = __connman_network_get_ident(network);
8395 group = connman_network_get_group(network);
8399 name = g_strdup_printf("%s_%s_%s",
8400 __connman_network_get_type(network), ident, group);
8401 service = lookup_by_identifier(name);
8407 struct connman_service *__connman_service_lookup_from_index(int index)
8409 struct connman_service *service;
8412 for (list = service_list; list; list = list->next) {
8413 service = list->data;
8415 if (__connman_ipconfig_get_index(service->ipconfig_ipv4)
8419 if (__connman_ipconfig_get_index(service->ipconfig_ipv6)
8427 struct connman_service *__connman_service_lookup_from_ident(const char *identifier)
8429 return lookup_by_identifier(identifier);
8432 const char *__connman_service_get_ident(struct connman_service *service)
8434 return service->identifier;
8437 const char *__connman_service_get_path(struct connman_service *service)
8439 return service->path;
8442 const char *__connman_service_get_name(struct connman_service *service)
8444 return service->name;
8447 enum connman_service_state __connman_service_get_state(struct connman_service *service)
8449 return service->state;
8452 unsigned int __connman_service_get_order(struct connman_service *service)
8454 unsigned int order = 0;
8461 if (!service->favorite)
8464 #if defined TIZEN_EXT
8465 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8466 service->do_split_routing == FALSE)
8468 else if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
8469 if (service->order < 5)
8471 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
8473 else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
8475 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8476 __connman_service_is_internet_profile(service) == TRUE)
8478 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8479 __connman_service_is_tethering_profile(service) == TRUE)
8481 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8486 if (service == service_list->data)
8489 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8490 !service->do_split_routing) {
8491 service->order = 10;
8495 DBG("service %p name %s order %d split %d", service, service->name,
8496 order, service->do_split_routing);
8501 void __connman_service_update_ordering(void)
8503 if (service_list && service_list->next)
8504 service_list = g_list_sort(service_list, service_compare);
8507 static enum connman_service_type convert_network_type(struct connman_network *network)
8509 enum connman_network_type type = connman_network_get_type(network);
8512 case CONNMAN_NETWORK_TYPE_UNKNOWN:
8513 case CONNMAN_NETWORK_TYPE_VENDOR:
8515 case CONNMAN_NETWORK_TYPE_ETHERNET:
8516 return CONNMAN_SERVICE_TYPE_ETHERNET;
8517 case CONNMAN_NETWORK_TYPE_WIFI:
8518 return CONNMAN_SERVICE_TYPE_WIFI;
8519 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
8520 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
8521 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
8522 case CONNMAN_NETWORK_TYPE_CELLULAR:
8523 return CONNMAN_SERVICE_TYPE_CELLULAR;
8524 case CONNMAN_NETWORK_TYPE_GADGET:
8525 return CONNMAN_SERVICE_TYPE_GADGET;
8528 return CONNMAN_SERVICE_TYPE_UNKNOWN;
8531 static enum connman_service_security convert_wifi_security(const char *security)
8534 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8535 else if (g_str_equal(security, "none"))
8536 return CONNMAN_SERVICE_SECURITY_NONE;
8537 else if (g_str_equal(security, "wep"))
8538 return CONNMAN_SERVICE_SECURITY_WEP;
8539 else if (g_str_equal(security, "psk"))
8540 return CONNMAN_SERVICE_SECURITY_PSK;
8541 else if (g_str_equal(security, "ieee8021x"))
8542 return CONNMAN_SERVICE_SECURITY_8021X;
8543 else if (g_str_equal(security, "wpa"))
8544 return CONNMAN_SERVICE_SECURITY_WPA;
8545 else if (g_str_equal(security, "rsn"))
8546 return CONNMAN_SERVICE_SECURITY_RSN;
8547 #if defined TIZEN_EXT
8548 else if (g_str_equal(security, "ft_psk") == TRUE)
8549 return CONNMAN_SERVICE_SECURITY_PSK;
8550 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
8551 return CONNMAN_SERVICE_SECURITY_8021X;
8554 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8557 static void update_from_network(struct connman_service *service,
8558 struct connman_network *network)
8560 uint8_t strength = service->strength;
8563 DBG("service %p network %p", service, network);
8565 if (is_connected(service))
8568 if (is_connecting(service))
8571 str = connman_network_get_string(network, "Name");
8573 g_free(service->name);
8574 service->name = g_strdup(str);
8575 service->hidden = false;
8577 g_free(service->name);
8578 service->name = NULL;
8579 service->hidden = true;
8582 service->strength = connman_network_get_strength(network);
8583 service->roaming = connman_network_get_bool(network, "Roaming");
8585 if (service->strength == 0) {
8587 * Filter out 0-values; it's unclear what they mean
8588 * and they cause anomalous sorting of the priority list.
8590 service->strength = strength;
8593 str = connman_network_get_string(network, "WiFi.Security");
8594 service->security = convert_wifi_security(str);
8596 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
8597 service->wps = connman_network_get_bool(network, "WiFi.WPS");
8599 if (service->strength > strength && service->network) {
8600 connman_network_unref(service->network);
8601 service->network = connman_network_ref(network);
8603 strength_changed(service);
8606 if (!service->network)
8607 service->network = connman_network_ref(network);
8609 service_list_sort();
8613 * __connman_service_create_from_network:
8614 * @network: network structure
8616 * Look up service by network and if not found, create one
8618 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
8620 struct connman_service *service;
8621 struct connman_device *device;
8622 const char *ident, *group;
8624 unsigned int *auto_connect_types;
8627 DBG("network %p", network);
8632 ident = __connman_network_get_ident(network);
8636 group = connman_network_get_group(network);
8640 name = g_strdup_printf("%s_%s_%s",
8641 __connman_network_get_type(network), ident, group);
8642 service = service_get(name);
8648 if (__connman_network_get_weakness(network))
8651 if (service->path) {
8652 update_from_network(service, network);
8653 __connman_connection_update_gateway();
8657 service->type = convert_network_type(network);
8659 auto_connect_types = connman_setting_get_uint_list("DefaultAutoConnectTechnologies");
8660 service->autoconnect = false;
8661 for (i = 0; auto_connect_types &&
8662 auto_connect_types[i] != 0; i++) {
8663 if (service->type == auto_connect_types[i]) {
8664 service->autoconnect = true;
8669 switch (service->type) {
8670 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8671 case CONNMAN_SERVICE_TYPE_SYSTEM:
8672 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8673 case CONNMAN_SERVICE_TYPE_GPS:
8674 case CONNMAN_SERVICE_TYPE_VPN:
8675 case CONNMAN_SERVICE_TYPE_GADGET:
8676 case CONNMAN_SERVICE_TYPE_WIFI:
8677 case CONNMAN_SERVICE_TYPE_CELLULAR:
8678 case CONNMAN_SERVICE_TYPE_P2P:
8680 case CONNMAN_SERVICE_TYPE_ETHERNET:
8681 service->favorite = true;
8685 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
8686 service->state = combine_state(service->state_ipv4, service->state_ipv6);
8688 update_from_network(service, network);
8690 index = connman_network_get_index(network);
8692 if (!service->ipconfig_ipv4)
8693 service->ipconfig_ipv4 = create_ip4config(service, index,
8694 CONNMAN_IPCONFIG_METHOD_DHCP);
8696 if (!service->ipconfig_ipv6)
8697 service->ipconfig_ipv6 = create_ip6config(service, index);
8699 service_register(service);
8701 if (service->favorite) {
8702 device = connman_network_get_device(service->network);
8703 if (device && !connman_device_get_scanning(device)) {
8705 switch (service->type) {
8706 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8707 case CONNMAN_SERVICE_TYPE_SYSTEM:
8708 case CONNMAN_SERVICE_TYPE_P2P:
8711 case CONNMAN_SERVICE_TYPE_GADGET:
8712 case CONNMAN_SERVICE_TYPE_ETHERNET:
8713 if (service->autoconnect) {
8714 __connman_service_connect(service,
8715 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
8720 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8721 case CONNMAN_SERVICE_TYPE_GPS:
8722 case CONNMAN_SERVICE_TYPE_VPN:
8723 case CONNMAN_SERVICE_TYPE_WIFI:
8724 case CONNMAN_SERVICE_TYPE_CELLULAR:
8725 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
8730 #if defined TIZEN_EXT
8731 /* TIZEN synchronizes below information when the service creates */
8732 if (service->eap != NULL)
8733 connman_network_set_string(service->network, "WiFi.EAP",
8735 if (service->identity != NULL)
8736 connman_network_set_string(service->network, "WiFi.Identity",
8738 if (service->phase2 != NULL)
8739 connman_network_set_string(service->network, "WiFi.Phase2",
8744 __connman_notifier_service_add(service, service->name);
8745 service_schedule_added(service);
8750 void __connman_service_update_from_network(struct connman_network *network)
8752 bool need_sort = false;
8753 struct connman_service *service;
8759 service = connman_service_lookup_from_network(network);
8763 if (!service->network)
8766 #if defined TIZEN_EXT
8767 if (service->storage_reload) {
8768 service_load(service);
8769 __connman_service_set_storage_reload(service, false);
8773 name = connman_network_get_string(service->network, "Name");
8774 if (g_strcmp0(service->name, name) != 0) {
8775 g_free(service->name);
8776 service->name = g_strdup(name);
8778 if (allow_property_changed(service))
8779 connman_dbus_property_changed_basic(service->path,
8780 CONNMAN_SERVICE_INTERFACE, "Name",
8781 DBUS_TYPE_STRING, &service->name);
8784 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
8785 service->wps = connman_network_get_bool(network, "WiFi.WPS");
8787 strength = connman_network_get_strength(service->network);
8788 if (strength == service->strength)
8791 service->strength = strength;
8794 strength_changed(service);
8797 roaming = connman_network_get_bool(service->network, "Roaming");
8798 if (roaming == service->roaming)
8801 stats_enable = stats_enabled(service);
8803 stats_stop(service);
8805 service->roaming = roaming;
8809 stats_start(service);
8811 roaming_changed(service);
8815 service_list_sort();
8819 void __connman_service_remove_from_network(struct connman_network *network)
8821 struct connman_service *service;
8823 service = connman_service_lookup_from_network(network);
8825 DBG("network %p service %p", network, service);
8830 service->ignore = true;
8832 __connman_connection_gateway_remove(service,
8833 CONNMAN_IPCONFIG_TYPE_ALL);
8835 connman_service_unref(service);
8839 * __connman_service_create_from_provider:
8840 * @provider: provider structure
8842 * Look up service by provider and if not found, create one
8844 struct connman_service *
8845 __connman_service_create_from_provider(struct connman_provider *provider)
8847 struct connman_service *service;
8848 const char *ident, *str;
8850 int index = connman_provider_get_index(provider);
8852 DBG("provider %p", provider);
8854 ident = __connman_provider_get_ident(provider);
8858 name = g_strdup_printf("vpn_%s", ident);
8859 service = service_get(name);
8865 service->type = CONNMAN_SERVICE_TYPE_VPN;
8866 service->provider = connman_provider_ref(provider);
8867 service->autoconnect = false;
8868 service->favorite = true;
8870 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
8871 service->state = combine_state(service->state_ipv4, service->state_ipv6);
8873 str = connman_provider_get_string(provider, "Name");
8875 g_free(service->name);
8876 service->name = g_strdup(str);
8877 service->hidden = false;
8879 g_free(service->name);
8880 service->name = NULL;
8881 service->hidden = true;
8884 service->strength = 0;
8886 if (!service->ipconfig_ipv4)
8887 service->ipconfig_ipv4 = create_ip4config(service, index,
8888 CONNMAN_IPCONFIG_METHOD_MANUAL);
8890 if (!service->ipconfig_ipv6)
8891 service->ipconfig_ipv6 = create_ip6config(service, index);
8893 service_register(service);
8895 __connman_notifier_service_add(service, service->name);
8896 service_schedule_added(service);
8901 static void remove_unprovisioned_services(void)
8904 GKeyFile *keyfile, *configkeyfile;
8905 char *file, *section;
8908 services = connman_storage_get_services();
8912 for (; services[i]; i++) {
8913 file = section = NULL;
8914 keyfile = configkeyfile = NULL;
8916 keyfile = connman_storage_load_service(services[i]);
8920 file = g_key_file_get_string(keyfile, services[i],
8921 "Config.file", NULL);
8925 section = g_key_file_get_string(keyfile, services[i],
8926 "Config.ident", NULL);
8930 configkeyfile = __connman_storage_load_config(file);
8931 if (!configkeyfile) {
8933 * Config file is missing, remove the provisioned
8936 __connman_storage_remove_service(services[i]);
8940 if (!g_key_file_has_group(configkeyfile, section))
8942 * Config section is missing, remove the provisioned
8945 __connman_storage_remove_service(services[i]);
8949 g_key_file_free(keyfile);
8952 g_key_file_free(configkeyfile);
8958 g_strfreev(services);
8961 static int agent_probe(struct connman_agent *agent)
8963 DBG("agent %p", agent);
8967 static void agent_remove(struct connman_agent *agent)
8969 DBG("agent %p", agent);
8972 static void *agent_context_ref(void *context)
8974 struct connman_service *service = context;
8976 return (void *)connman_service_ref(service);
8979 static void agent_context_unref(void *context)
8981 struct connman_service *service = context;
8983 connman_service_unref(service);
8986 static struct connman_agent_driver agent_driver = {
8988 .interface = CONNMAN_AGENT_INTERFACE,
8989 .probe = agent_probe,
8990 .remove = agent_remove,
8991 .context_ref = agent_context_ref,
8992 .context_unref = agent_context_unref,
8995 int __connman_service_init(void)
9001 err = connman_agent_driver_register(&agent_driver);
9003 connman_error("Cannot register agent driver for %s",
9008 connection = connman_dbus_get_connection();
9010 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
9011 NULL, service_free);
9013 services_notify = g_new0(struct _services_notify, 1);
9014 services_notify->remove = g_hash_table_new_full(g_str_hash,
9015 g_str_equal, g_free, NULL);
9016 services_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
9018 remove_unprovisioned_services();
9023 void __connman_service_cleanup(void)
9027 if (vpn_autoconnect_timeout) {
9028 g_source_remove(vpn_autoconnect_timeout);
9029 vpn_autoconnect_timeout = 0;
9032 if (autoconnect_timeout != 0) {
9033 g_source_remove(autoconnect_timeout);
9034 autoconnect_timeout = 0;
9037 connman_agent_driver_unregister(&agent_driver);
9039 g_list_free(service_list);
9040 service_list = NULL;
9042 g_hash_table_destroy(service_hash);
9043 service_hash = NULL;
9045 g_slist_free(counter_list);
9046 counter_list = NULL;
9048 if (services_notify->id != 0) {
9049 g_source_remove(services_notify->id);
9050 service_send_changed(NULL);
9051 g_hash_table_destroy(services_notify->remove);
9052 g_hash_table_destroy(services_notify->add);
9054 g_free(services_notify);
9056 dbus_connection_unref(connection);