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);
3250 const void *wifi_vsie;
3251 unsigned int wifi_vsie_len;
3252 wifi_vsie = connman_network_get_blob(service->network, "WiFi.Vsie", &wifi_vsie_len);
3253 if(wifi_vsie_len > 0) {
3254 DBG("ConnMan, service->path=%s vsie length=%d", service->path, wifi_vsie_len);
3256 connman_dbus_dict_append_fixed_array(dict, "Vsie", DBUS_TYPE_BYTE,
3257 &wifi_vsie, wifi_vsie_len);
3260 str = __connman_service_type2string(service->type);
3262 connman_dbus_dict_append_basic(dict, "Type",
3263 DBUS_TYPE_STRING, &str);
3265 connman_dbus_dict_append_array(dict, "Security",
3266 DBUS_TYPE_STRING, append_security, service);
3268 str = state2string(service->state);
3270 connman_dbus_dict_append_basic(dict, "State",
3271 DBUS_TYPE_STRING, &str);
3274 str = state2string(service->state_ipv6);
3276 connman_dbus_dict_append_basic(dict, "StateIPv6",
3277 DBUS_TYPE_STRING, &str);
3280 str = error2string(service->error);
3282 connman_dbus_dict_append_basic(dict, "Error",
3283 DBUS_TYPE_STRING, &str);
3285 if (service->strength > 0)
3286 connman_dbus_dict_append_basic(dict, "Strength",
3287 DBUS_TYPE_BYTE, &service->strength);
3289 val = service->favorite;
3290 connman_dbus_dict_append_basic(dict, "Favorite",
3291 DBUS_TYPE_BOOLEAN, &val);
3293 val = service->immutable;
3294 connman_dbus_dict_append_basic(dict, "Immutable",
3295 DBUS_TYPE_BOOLEAN, &val);
3297 if (service->favorite)
3298 val = service->autoconnect;
3300 val = service->favorite;
3302 connman_dbus_dict_append_basic(dict, "AutoConnect",
3303 DBUS_TYPE_BOOLEAN, &val);
3306 connman_dbus_dict_append_basic(dict, "Name",
3307 DBUS_TYPE_STRING, &service->name);
3309 switch (service->type) {
3310 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3311 case CONNMAN_SERVICE_TYPE_SYSTEM:
3312 case CONNMAN_SERVICE_TYPE_GPS:
3313 case CONNMAN_SERVICE_TYPE_VPN:
3314 case CONNMAN_SERVICE_TYPE_P2P:
3316 case CONNMAN_SERVICE_TYPE_CELLULAR:
3317 val = service->roaming;
3318 connman_dbus_dict_append_basic(dict, "Roaming",
3319 DBUS_TYPE_BOOLEAN, &val);
3321 connman_dbus_dict_append_dict(dict, "Ethernet",
3322 append_ethernet, service);
3324 case CONNMAN_SERVICE_TYPE_WIFI:
3325 #if defined TIZEN_EXT
3326 if (service->network != NULL)
3327 append_wifi_ext_info(dict, service->network);
3329 connman_dbus_dict_append_dict(dict, "Ethernet",
3330 append_ethernet, service);
3332 connman_dbus_dict_append_basic(dict, "DisconnectReason",
3333 DBUS_TYPE_INT32, &service->disconnect_reason);
3337 case CONNMAN_SERVICE_TYPE_ETHERNET:
3338 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3339 case CONNMAN_SERVICE_TYPE_GADGET:
3340 connman_dbus_dict_append_dict(dict, "Ethernet",
3341 append_ethernet, service);
3345 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
3347 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
3348 append_ipv4config, service);
3350 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
3352 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
3353 append_ipv6config, service);
3355 connman_dbus_dict_append_array(dict, "Nameservers",
3356 DBUS_TYPE_STRING, append_dns, service);
3358 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
3359 DBUS_TYPE_STRING, append_dnsconfig, service);
3361 if (service->state == CONNMAN_SERVICE_STATE_READY ||
3362 service->state == CONNMAN_SERVICE_STATE_ONLINE)
3363 list = __connman_timeserver_get_all(service);
3367 connman_dbus_dict_append_array(dict, "Timeservers",
3368 DBUS_TYPE_STRING, append_ts, list);
3370 g_slist_free_full(list, g_free);
3372 connman_dbus_dict_append_array(dict, "Timeservers.Configuration",
3373 DBUS_TYPE_STRING, append_tsconfig, service);
3375 connman_dbus_dict_append_array(dict, "Domains",
3376 DBUS_TYPE_STRING, append_domain, service);
3378 connman_dbus_dict_append_array(dict, "Domains.Configuration",
3379 DBUS_TYPE_STRING, append_domainconfig, service);
3381 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
3383 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
3384 append_proxyconfig, service);
3386 connman_dbus_dict_append_dict(dict, "Provider",
3387 append_provider, service);
3390 static void append_struct_service(DBusMessageIter *iter,
3391 connman_dbus_append_cb_t function,
3392 struct connman_service *service)
3394 DBusMessageIter entry, dict;
3396 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
3398 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
3401 connman_dbus_dict_open(&entry, &dict);
3403 function(&dict, service);
3404 connman_dbus_dict_close(&entry, &dict);
3406 dbus_message_iter_close_container(iter, &entry);
3409 static void append_dict_properties(DBusMessageIter *dict, void *user_data)
3411 struct connman_service *service = user_data;
3413 append_properties(dict, TRUE, service);
3416 static void append_struct(gpointer value, gpointer user_data)
3418 struct connman_service *service = value;
3419 DBusMessageIter *iter = user_data;
3424 append_struct_service(iter, append_dict_properties, service);
3427 void __connman_service_list_struct(DBusMessageIter *iter)
3429 g_list_foreach(service_list, append_struct, iter);
3432 #if defined TIZEN_EXT
3433 static void append_wifi_vsie_properties(DBusMessageIter *iter,
3434 struct connman_service *service)
3436 DBusMessageIter dict;
3437 const void *wifi_vsie;
3438 unsigned int wifi_vsie_len;
3440 connman_dbus_dict_open(iter, &dict);
3442 wifi_vsie = connman_network_get_blob(service->network, "WiFi.Vsie", &wifi_vsie_len);
3444 if(wifi_vsie_len > 0) {
3445 DBG("ConnMan, service->path=%s vsie length=%d", service->path, wifi_vsie_len);
3448 connman_dbus_dict_append_fixed_array(&dict, "Vsie", DBUS_TYPE_BYTE,
3449 &wifi_vsie, wifi_vsie_len);
3451 connman_dbus_dict_close(iter, &dict);
3454 void __connman_wifi_vsie_list_struct(DBusMessageIter *iter)
3457 DBusMessageIter entry;
3459 DBG("ConnMan, __connman_wifi_vsie_list_struct API called");
3461 for (list = service_list; list; list = list->next) {
3462 struct connman_service *service = list->data;
3464 if (!service->path ||
3465 service->type != CONNMAN_SERVICE_TYPE_WIFI ||
3466 service->network == NULL)
3469 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT,
3471 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
3473 append_wifi_vsie_properties(&entry, service);
3474 dbus_message_iter_close_container(iter, &entry);
3479 bool __connman_service_is_hidden(struct connman_service *service)
3481 return service->hidden;
3485 __connman_service_is_split_routing(struct connman_service *service)
3487 return service->do_split_routing;
3490 bool __connman_service_index_is_split_routing(int index)
3492 struct connman_service *service;
3497 service = __connman_service_lookup_from_index(index);
3501 return __connman_service_is_split_routing(service);
3504 int __connman_service_get_index(struct connman_service *service)
3509 if (service->network)
3510 return connman_network_get_index(service->network);
3511 else if (service->provider)
3512 return connman_provider_get_index(service->provider);
3517 void __connman_service_set_hidden(struct connman_service *service)
3519 if (!service || service->hidden)
3522 service->hidden_service = true;
3525 void __connman_service_set_hostname(struct connman_service *service,
3526 const char *hostname)
3528 if (!service || service->hidden)
3531 g_free(service->hostname);
3532 service->hostname = g_strdup(hostname);
3535 const char *__connman_service_get_hostname(struct connman_service *service)
3540 return service->hostname;
3543 void __connman_service_set_domainname(struct connman_service *service,
3544 const char *domainname)
3546 if (!service || service->hidden)
3549 g_free(service->domainname);
3550 service->domainname = g_strdup(domainname);
3552 domain_changed(service);
3555 const char *connman_service_get_domainname(struct connman_service *service)
3560 if (service->domains)
3561 return service->domains[0];
3563 return service->domainname;
3566 char **connman_service_get_nameservers(struct connman_service *service)
3571 if (service->nameservers_config)
3572 return g_strdupv(service->nameservers_config);
3573 else if (service->nameservers ||
3574 service->nameservers_auto) {
3575 int len = 0, len_auto = 0, i;
3578 if (service->nameservers)
3579 len = g_strv_length(service->nameservers);
3580 if (service->nameservers_auto)
3581 len_auto = g_strv_length(service->nameservers_auto);
3583 nameservers = g_try_new0(char *, len + len_auto + 1);
3587 for (i = 0; i < len; i++)
3588 nameservers[i] = g_strdup(service->nameservers[i]);
3590 for (i = 0; i < len_auto; i++)
3591 nameservers[i + len] =
3592 g_strdup(service->nameservers_auto[i]);
3597 return g_strdupv(connman_setting_get_string_list("FallbackNameservers"));
3600 char **connman_service_get_timeservers_config(struct connman_service *service)
3605 return service->timeservers_config;
3608 char **connman_service_get_timeservers(struct connman_service *service)
3613 return service->timeservers;
3616 #if defined TIZEN_EXT
3618 * Description: Telephony plug-in requires manual PROXY setting function
3620 int connman_service_set_proxy(struct connman_service *service,
3621 const char *proxy, gboolean active)
3623 char **proxies_array = NULL;
3625 if (service == NULL)
3628 switch (service->type) {
3629 case CONNMAN_SERVICE_TYPE_CELLULAR:
3630 case CONNMAN_SERVICE_TYPE_ETHERNET:
3631 case CONNMAN_SERVICE_TYPE_WIFI:
3638 g_strfreev(service->proxies);
3639 service->proxies = NULL;
3642 proxies_array = g_strsplit(proxy, " ", 0);
3644 service->proxies = proxies_array;
3646 if (proxy == NULL) {
3647 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
3648 DBG("proxy changed (%d)", active);
3650 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
3651 DBG("proxy chagned %s (%d)", proxy, active);
3654 if (active == TRUE) {
3655 proxy_changed(service);
3657 __connman_notifier_proxy_changed(service);
3664 void connman_service_set_proxy_method(struct connman_service *service,
3665 enum connman_service_proxy_method method)
3667 if (!service || service->hidden)
3670 service->proxy = method;
3672 proxy_changed(service);
3674 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
3675 __connman_notifier_proxy_changed(service);
3678 enum connman_service_proxy_method connman_service_get_proxy_method(
3679 struct connman_service *service)
3682 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
3684 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
3685 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
3687 return service->proxy;
3689 return service->proxy_config;
3692 return service->proxy;
3695 char **connman_service_get_proxy_servers(struct connman_service *service)
3697 return g_strdupv(service->proxies);
3700 char **connman_service_get_proxy_excludes(struct connman_service *service)
3702 return g_strdupv(service->excludes);
3705 const char *connman_service_get_proxy_url(struct connman_service *service)
3710 return service->pac;
3713 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
3716 if (!service || service->hidden)
3719 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
3721 if (service->ipconfig_ipv4) {
3722 if (__connman_ipconfig_set_proxy_autoconfig(
3723 service->ipconfig_ipv4, url) < 0)
3725 } else if (service->ipconfig_ipv6) {
3726 if (__connman_ipconfig_set_proxy_autoconfig(
3727 service->ipconfig_ipv6, url) < 0)
3732 proxy_changed(service);
3734 __connman_notifier_proxy_changed(service);
3737 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
3742 if (service->ipconfig_ipv4)
3743 return __connman_ipconfig_get_proxy_autoconfig(
3744 service->ipconfig_ipv4);
3745 else if (service->ipconfig_ipv6)
3746 return __connman_ipconfig_get_proxy_autoconfig(
3747 service->ipconfig_ipv6);
3751 #if defined TIZEN_EXT
3752 int connman_service_get_ipv6_dns_method(struct connman_service *service)
3755 DBG("Service is NULL");
3759 return service->dns_config_method_ipv6;
3763 void __connman_service_set_timeservers(struct connman_service *service,
3771 g_strfreev(service->timeservers);
3772 service->timeservers = NULL;
3774 for (i = 0; timeservers && timeservers[i]; i++)
3775 __connman_service_timeserver_append(service, timeservers[i]);
3778 int __connman_service_timeserver_append(struct connman_service *service,
3779 const char *timeserver)
3783 DBG("service %p timeserver %s", service, timeserver);
3788 if (service->timeservers) {
3791 for (i = 0; service->timeservers[i]; i++)
3792 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
3795 len = g_strv_length(service->timeservers);
3796 service->timeservers = g_try_renew(char *, service->timeservers,
3800 service->timeservers = g_try_new0(char *, len + 2);
3803 if (!service->timeservers)
3806 service->timeservers[len] = g_strdup(timeserver);
3807 service->timeservers[len + 1] = NULL;
3812 int __connman_service_timeserver_remove(struct connman_service *service,
3813 const char *timeserver)
3816 int len, i, j, found = 0;
3818 DBG("service %p timeserver %s", service, timeserver);
3823 if (!service->timeservers)
3826 for (i = 0; service->timeservers &&
3827 service->timeservers[i]; i++)
3828 if (g_strcmp0(service->timeservers[i], timeserver) == 0) {
3836 len = g_strv_length(service->timeservers);
3839 g_strfreev(service->timeservers);
3840 service->timeservers = NULL;
3845 servers = g_try_new0(char *, len);
3849 for (i = 0, j = 0; i < len; i++) {
3850 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
3851 servers[j] = g_strdup(service->timeservers[i]);
3857 servers[len - 1] = NULL;
3859 g_strfreev(service->timeservers);
3860 service->timeservers = servers;
3865 void __connman_service_timeserver_changed(struct connman_service *service,
3871 if (!allow_property_changed(service))
3874 connman_dbus_property_changed_array(service->path,
3875 CONNMAN_SERVICE_INTERFACE, "Timeservers",
3876 DBUS_TYPE_STRING, append_ts, ts_list);
3879 void __connman_service_set_pac(struct connman_service *service,
3882 if (service->hidden)
3884 g_free(service->pac);
3885 service->pac = g_strdup(pac);
3887 proxy_changed(service);
3890 #if defined TIZEN_EXT
3891 void __connman_service_set_proxy(struct connman_service *service,
3892 const char *proxies)
3894 char **proxies_array = NULL;
3896 g_strfreev(service->proxies);
3897 service->proxies = NULL;
3899 if (proxies != NULL)
3900 proxies_array = g_strsplit(proxies, " ", 0);
3902 service->proxies = proxies_array;
3906 void __connman_service_set_identity(struct connman_service *service,
3907 const char *identity)
3909 if (service->immutable || service->hidden)
3912 g_free(service->identity);
3913 service->identity = g_strdup(identity);
3915 if (service->network)
3916 connman_network_set_string(service->network,
3921 void __connman_service_set_agent_identity(struct connman_service *service,
3922 const char *agent_identity)
3924 if (service->hidden)
3926 g_free(service->agent_identity);
3927 service->agent_identity = g_strdup(agent_identity);
3929 if (service->network)
3930 connman_network_set_string(service->network,
3931 "WiFi.AgentIdentity",
3932 service->agent_identity);
3935 static int check_passphrase(enum connman_service_security security,
3936 const char *passphrase)
3944 length = strlen(passphrase);
3947 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3948 case CONNMAN_SERVICE_SECURITY_NONE:
3949 case CONNMAN_SERVICE_SECURITY_WPA:
3950 #if !defined TIZEN_EXT
3951 case CONNMAN_SERVICE_SECURITY_RSN:
3954 DBG("service security '%s' (%d) not handled",
3955 security2string(security), security);
3959 case CONNMAN_SERVICE_SECURITY_PSK:
3960 #if defined TIZEN_EXT
3961 case CONNMAN_SERVICE_SECURITY_RSN:
3963 /* A raw key is always 64 bytes length,
3964 * its content is in hex representation.
3965 * A PSK key must be between [8..63].
3968 for (i = 0; i < 64; i++)
3969 if (!isxdigit((unsigned char)
3972 } else if (length < 8 || length > 63)
3975 case CONNMAN_SERVICE_SECURITY_WEP:
3976 /* length of WEP key is 10 or 26
3977 * length of WEP passphrase is 5 or 13
3979 if (length == 10 || length == 26) {
3980 for (i = 0; i < length; i++)
3981 if (!isxdigit((unsigned char)
3984 } else if (length != 5 && length != 13)
3988 case CONNMAN_SERVICE_SECURITY_8021X:
3995 int __connman_service_set_passphrase(struct connman_service *service,
3996 const char *passphrase)
4000 if (service->hidden)
4003 if (service->immutable &&
4004 service->security != CONNMAN_SERVICE_SECURITY_8021X)
4007 err = check_passphrase(service->security, passphrase);
4012 g_free(service->passphrase);
4013 service->passphrase = g_strdup(passphrase);
4015 if (service->network)
4016 connman_network_set_string(service->network, "WiFi.Passphrase",
4017 service->passphrase);
4022 const char *__connman_service_get_passphrase(struct connman_service *service)
4027 return service->passphrase;
4030 static DBusMessage *get_properties(DBusConnection *conn,
4031 DBusMessage *msg, void *user_data)
4033 struct connman_service *service = user_data;
4035 DBusMessageIter array, dict;
4037 DBG("service %p", service);
4039 reply = dbus_message_new_method_return(msg);
4043 dbus_message_iter_init_append(reply, &array);
4045 connman_dbus_dict_open(&array, &dict);
4046 append_properties(&dict, FALSE, service);
4047 connman_dbus_dict_close(&array, &dict);
4052 static int update_proxy_configuration(struct connman_service *service,
4053 DBusMessageIter *array)
4055 DBusMessageIter dict;
4056 enum connman_service_proxy_method method;
4057 GString *servers_str = NULL;
4058 GString *excludes_str = NULL;
4059 const char *url = NULL;
4061 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
4063 dbus_message_iter_recurse(array, &dict);
4065 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
4066 DBusMessageIter entry, variant;
4070 dbus_message_iter_recurse(&dict, &entry);
4072 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
4075 dbus_message_iter_get_basic(&entry, &key);
4076 dbus_message_iter_next(&entry);
4078 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
4081 dbus_message_iter_recurse(&entry, &variant);
4083 type = dbus_message_iter_get_arg_type(&variant);
4085 if (g_str_equal(key, "Method")) {
4088 if (type != DBUS_TYPE_STRING)
4091 dbus_message_iter_get_basic(&variant, &val);
4092 method = string2proxymethod(val);
4093 } else if (g_str_equal(key, "URL")) {
4094 if (type != DBUS_TYPE_STRING)
4097 dbus_message_iter_get_basic(&variant, &url);
4098 } else if (g_str_equal(key, "Servers")) {
4099 DBusMessageIter str_array;
4101 if (type != DBUS_TYPE_ARRAY)
4104 servers_str = g_string_new(NULL);
4108 dbus_message_iter_recurse(&variant, &str_array);
4110 while (dbus_message_iter_get_arg_type(&str_array) ==
4114 dbus_message_iter_get_basic(&str_array, &val);
4116 if (servers_str->len > 0)
4117 g_string_append_printf(servers_str,
4120 g_string_append(servers_str, val);
4122 dbus_message_iter_next(&str_array);
4124 } else if (g_str_equal(key, "Excludes")) {
4125 DBusMessageIter str_array;
4127 if (type != DBUS_TYPE_ARRAY)
4130 excludes_str = g_string_new(NULL);
4134 dbus_message_iter_recurse(&variant, &str_array);
4136 while (dbus_message_iter_get_arg_type(&str_array) ==
4140 dbus_message_iter_get_basic(&str_array, &val);
4142 if (excludes_str->len > 0)
4143 g_string_append_printf(excludes_str,
4146 g_string_append(excludes_str, val);
4148 dbus_message_iter_next(&str_array);
4152 dbus_message_iter_next(&dict);
4156 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
4158 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
4159 if (!servers_str && !service->proxies)
4163 g_strfreev(service->proxies);
4165 if (servers_str->len > 0)
4166 service->proxies = g_strsplit_set(
4167 servers_str->str, " ", 0);
4169 service->proxies = NULL;
4173 g_strfreev(service->excludes);
4175 if (excludes_str->len > 0)
4176 service->excludes = g_strsplit_set(
4177 excludes_str->str, " ", 0);
4179 service->excludes = NULL;
4182 if (!service->proxies)
4183 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
4186 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
4187 g_free(service->pac);
4189 if (url && strlen(url) > 0)
4190 service->pac = g_strdup(url);
4192 service->pac = NULL;
4194 /* if we are connected:
4195 - if service->pac == NULL
4196 - if __connman_ipconfig_get_proxy_autoconfig(
4197 service->ipconfig) == NULL
4198 --> We should start WPAD */
4201 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
4206 g_string_free(servers_str, TRUE);
4209 g_string_free(excludes_str, TRUE);
4211 service->proxy_config = method;
4217 g_string_free(servers_str, TRUE);
4220 g_string_free(excludes_str, TRUE);
4225 int __connman_service_reset_ipconfig(struct connman_service *service,
4226 enum connman_ipconfig_type type, DBusMessageIter *array,
4227 enum connman_service_state *new_state)
4229 struct connman_ipconfig *ipconfig, *new_ipconfig;
4230 enum connman_ipconfig_method old_method, new_method;
4231 enum connman_service_state state;
4234 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4235 ipconfig = service->ipconfig_ipv4;
4236 state = service->state_ipv4;
4237 new_method = CONNMAN_IPCONFIG_METHOD_DHCP;
4238 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4239 ipconfig = service->ipconfig_ipv6;
4240 state = service->state_ipv6;
4241 new_method = CONNMAN_IPCONFIG_METHOD_AUTO;
4248 old_method = __connman_ipconfig_get_method(ipconfig);
4249 index = __connman_ipconfig_get_index(ipconfig);
4251 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4252 new_ipconfig = create_ip4config(service, index,
4253 CONNMAN_IPCONFIG_METHOD_UNKNOWN);
4255 new_ipconfig = create_ip6config(service, index);
4258 err = __connman_ipconfig_set_config(new_ipconfig, array);
4260 __connman_ipconfig_unref(new_ipconfig);
4264 new_method = __connman_ipconfig_get_method(new_ipconfig);
4267 if (is_connecting_state(service, state) ||
4268 is_connected_state(service, state))
4269 __connman_network_clear_ipconfig(service->network, ipconfig);
4271 __connman_ipconfig_unref(ipconfig);
4273 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4274 service->ipconfig_ipv4 = new_ipconfig;
4275 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4276 service->ipconfig_ipv6 = new_ipconfig;
4278 if (is_connecting_state(service, state) ||
4279 is_connected_state(service, state))
4280 __connman_ipconfig_enable(new_ipconfig);
4282 if (new_state && new_method != old_method) {
4283 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4284 *new_state = service->state_ipv4;
4286 *new_state = service->state_ipv6;
4288 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4291 DBG("err %d ipconfig %p type %d method %d state %s", err,
4292 new_ipconfig, type, new_method,
4293 !new_state ? "-" : state2string(*new_state));
4298 static DBusMessage *set_property(DBusConnection *conn,
4299 DBusMessage *msg, void *user_data)
4301 struct connman_service *service = user_data;
4302 DBusMessageIter iter, value;
4306 DBG("service %p", service);
4308 if (!dbus_message_iter_init(msg, &iter))
4309 return __connman_error_invalid_arguments(msg);
4311 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
4312 return __connman_error_invalid_arguments(msg);
4314 if (service->type == CONNMAN_SERVICE_TYPE_WIFI && is_connected(service)) {
4316 if (connman_dbus_get_connection_unix_user_sync(conn,
4317 dbus_message_get_sender(msg),
4319 DBG("Can not get unix user id!");
4320 return __connman_error_permission_denied(msg);
4323 if (!connman_service_is_user_allowed(service, uid)) {
4324 DBG("Not allow this user to operate this wifi service now!");
4325 return __connman_error_permission_denied(msg);
4329 dbus_message_iter_get_basic(&iter, &name);
4330 dbus_message_iter_next(&iter);
4332 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
4333 return __connman_error_invalid_arguments(msg);
4335 dbus_message_iter_recurse(&iter, &value);
4337 type = dbus_message_iter_get_arg_type(&value);
4339 if (g_str_equal(name, "AutoConnect")) {
4340 dbus_bool_t autoconnect;
4342 if (type != DBUS_TYPE_BOOLEAN)
4343 return __connman_error_invalid_arguments(msg);
4345 if (!service->favorite)
4346 return __connman_error_invalid_service(msg);
4348 dbus_message_iter_get_basic(&value, &autoconnect);
4350 if (service->autoconnect == autoconnect)
4351 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4353 service->autoconnect = autoconnect;
4355 autoconnect_changed(service);
4358 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4360 service_save(service);
4361 } else if (g_str_equal(name, "Nameservers.Configuration")) {
4362 DBusMessageIter entry;
4366 #if defined TIZEN_EXT
4367 enum connman_ipconfig_type ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4371 if (__connman_provider_is_immutable(service->provider) ||
4373 return __connman_error_not_supported(msg);
4375 if (type != DBUS_TYPE_ARRAY)
4376 return __connman_error_invalid_arguments(msg);
4378 str = g_string_new(NULL);
4380 return __connman_error_invalid_arguments(msg);
4382 index = __connman_service_get_index(service);
4383 gw = __connman_ipconfig_get_gateway_from_index(index,
4384 CONNMAN_IPCONFIG_TYPE_ALL);
4386 if (gw && strlen(gw))
4387 __connman_service_nameserver_del_routes(service,
4388 CONNMAN_IPCONFIG_TYPE_ALL);
4390 dbus_message_iter_recurse(&value, &entry);
4392 #if defined TIZEN_EXT
4393 /* IPv4/IPv6 Last DNS config method */
4394 int last_dns_ipv4 = service->dns_config_method_ipv4;
4395 int last_dns_ipv6 = service->dns_config_method_ipv6;
4396 DBG("Last DNS Config Method IPv4: %d IPv6: %d", last_dns_ipv4, last_dns_ipv6);
4399 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4401 dbus_message_iter_get_basic(&entry, &val);
4402 dbus_message_iter_next(&entry);
4404 /* First unpack the DNS Config Method */
4405 DBG("DNS Config Method: %s", val);
4406 if((g_strcmp0(val, "ipv4.manual") == 0)) {
4407 service->dns_config_method_ipv4 =
4408 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4410 if(last_dns_ipv4 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4411 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4412 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4414 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4417 } else if(g_strcmp0(val, "ipv4.dhcp") == 0) {
4418 service->dns_config_method_ipv4 =
4419 CONNMAN_DNSCONFIG_METHOD_DHCP;
4420 if(last_dns_ipv4 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4421 ip_type = CONNMAN_IPCONFIG_TYPE_IPV4;
4424 } else if(g_strcmp0(val, "ipv6.manual") == 0) {
4425 service->dns_config_method_ipv6 =
4426 CONNMAN_DNSCONFIG_METHOD_MANUAL;
4427 if(last_dns_ipv6 != CONNMAN_DNSCONFIG_METHOD_MANUAL) {
4428 if(ip_type == CONNMAN_IPCONFIG_TYPE_UNKNOWN)
4429 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4431 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4434 } else if(g_strcmp0(val, "ipv6.dhcp") == 0) {
4435 service->dns_config_method_ipv6 =
4436 CONNMAN_DNSCONFIG_METHOD_DHCP;
4437 if(last_dns_ipv6 == CONNMAN_DNSCONFIG_METHOD_MANUAL)
4438 ip_type = CONNMAN_IPCONFIG_TYPE_IPV6;
4443 if (connman_inet_check_ipaddress(val) > 0) {
4445 g_string_append_printf(str, " %s", val);
4447 g_string_append(str, val);
4451 #if defined TIZEN_EXT
4452 if (service->dns_config_method_ipv4 == CONNMAN_DNSCONFIG_METHOD_DHCP &&
4453 service->dns_config_method_ipv6 == CONNMAN_DNSCONFIG_METHOD_DHCP) {
4454 DBG("Both IPv4 and IPv6 DNS Method DHCP");
4455 ip_type = CONNMAN_IPCONFIG_TYPE_ALL;
4457 if (gw && strlen(gw))
4458 __connman_service_nameserver_del_routes(service,
4461 DBG("%s ip_type: %d nameserver remove all", name, ip_type);
4462 nameserver_remove_all(service, ip_type);
4464 nameserver_remove_all(service);
4466 g_strfreev(service->nameservers_config);
4469 service->nameservers_config =
4470 g_strsplit_set(str->str, " ", 0);
4472 service->nameservers_config = NULL;
4475 g_string_free(str, TRUE);
4477 if (gw && strlen(gw))
4478 __connman_service_nameserver_add_routes(service, gw);
4480 #if defined TIZEN_EXT
4481 DBG("%s ip_type: %d nameserver add all", name, ip_type);
4482 nameserver_add_all(service, ip_type);
4484 nameserver_add_all(service);
4486 dns_configuration_changed(service);
4488 if (__connman_service_is_connected_state(service,
4489 CONNMAN_IPCONFIG_TYPE_IPV4))
4490 __connman_wispr_start(service,
4491 CONNMAN_IPCONFIG_TYPE_IPV4);
4493 if (__connman_service_is_connected_state(service,
4494 CONNMAN_IPCONFIG_TYPE_IPV6))
4495 __connman_wispr_start(service,
4496 CONNMAN_IPCONFIG_TYPE_IPV6);
4498 service_save(service);
4499 } else if (g_str_equal(name, "Timeservers.Configuration")) {
4500 DBusMessageIter entry;
4501 GSList *list = NULL;
4504 if (service->immutable)
4505 return __connman_error_not_supported(msg);
4507 if (type != DBUS_TYPE_ARRAY)
4508 return __connman_error_invalid_arguments(msg);
4510 dbus_message_iter_recurse(&value, &entry);
4512 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4516 dbus_message_iter_get_basic(&entry, &val);
4518 new_head = __connman_timeserver_add_list(list, val);
4519 if (list != new_head) {
4524 dbus_message_iter_next(&entry);
4527 g_strfreev(service->timeservers_config);
4528 service->timeservers_config = NULL;
4531 service->timeservers_config = g_new0(char *, count+1);
4535 service->timeservers_config[count] = list->data;
4536 list = g_slist_delete_link(list, list);
4540 service_save(service);
4541 timeservers_configuration_changed(service);
4543 if (service == __connman_service_get_default())
4544 __connman_timeserver_sync(service);
4546 } else if (g_str_equal(name, "Domains.Configuration")) {
4547 DBusMessageIter entry;
4550 if (service->immutable)
4551 return __connman_error_not_supported(msg);
4553 if (type != DBUS_TYPE_ARRAY)
4554 return __connman_error_invalid_arguments(msg);
4556 str = g_string_new(NULL);
4558 return __connman_error_invalid_arguments(msg);
4560 dbus_message_iter_recurse(&value, &entry);
4562 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
4564 dbus_message_iter_get_basic(&entry, &val);
4565 dbus_message_iter_next(&entry);
4567 g_string_append_printf(str, " %s", val);
4569 g_string_append(str, val);
4572 searchdomain_remove_all(service);
4573 g_strfreev(service->domains);
4576 service->domains = g_strsplit_set(str->str, " ", 0);
4578 service->domains = NULL;
4580 g_string_free(str, TRUE);
4582 searchdomain_add_all(service);
4583 domain_configuration_changed(service);
4584 domain_changed(service);
4586 service_save(service);
4587 } else if (g_str_equal(name, "Proxy.Configuration")) {
4590 if (service->immutable)
4591 return __connman_error_not_supported(msg);
4593 if (type != DBUS_TYPE_ARRAY)
4594 return __connman_error_invalid_arguments(msg);
4596 err = update_proxy_configuration(service, &value);
4599 return __connman_error_failed(msg, -err);
4601 proxy_configuration_changed(service);
4603 __connman_notifier_proxy_changed(service);
4605 service_save(service);
4606 } else if (g_str_equal(name, "IPv4.Configuration") ||
4607 g_str_equal(name, "IPv6.Configuration")) {
4609 enum connman_service_state state =
4610 CONNMAN_SERVICE_STATE_UNKNOWN;
4611 enum connman_ipconfig_type type =
4612 CONNMAN_IPCONFIG_TYPE_UNKNOWN;
4615 if (service->type == CONNMAN_SERVICE_TYPE_VPN ||
4617 return __connman_error_not_supported(msg);
4621 if (!service->ipconfig_ipv4 &&
4622 !service->ipconfig_ipv6)
4623 return __connman_error_invalid_property(msg);
4625 if (g_str_equal(name, "IPv4.Configuration"))
4626 type = CONNMAN_IPCONFIG_TYPE_IPV4;
4628 type = CONNMAN_IPCONFIG_TYPE_IPV6;
4630 err = __connman_service_reset_ipconfig(service, type, &value,
4634 if (is_connected_state(service, state) ||
4635 is_connecting_state(service, state)) {
4636 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4637 __connman_network_enable_ipconfig(service->network,
4638 service->ipconfig_ipv4);
4640 __connman_network_enable_ipconfig(service->network,
4641 service->ipconfig_ipv6);
4644 return __connman_error_failed(msg, -err);
4647 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4648 ipv4_configuration_changed(service);
4650 ipv6_configuration_changed(service);
4652 if (is_connecting(service) || is_connected(service)) {
4653 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4654 __connman_network_enable_ipconfig(service->network,
4655 service->ipconfig_ipv4);
4657 __connman_network_enable_ipconfig(service->network,
4658 service->ipconfig_ipv6);
4661 service_save(service);
4663 return __connman_error_invalid_property(msg);
4665 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4668 static void set_error(struct connman_service *service,
4669 enum connman_service_error error)
4673 if (service->error == error)
4676 service->error = error;
4681 #if !defined TIZEN_EXT
4682 if (!allow_property_changed(service))
4686 str = error2string(service->error);
4691 connman_dbus_property_changed_basic(service->path,
4692 CONNMAN_SERVICE_INTERFACE, "Error",
4693 DBUS_TYPE_STRING, &str);
4696 static void set_idle(struct connman_service *service)
4698 service->state = service->state_ipv4 = service->state_ipv6 =
4699 CONNMAN_SERVICE_STATE_IDLE;
4700 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4701 state_changed(service);
4704 static DBusMessage *clear_property(DBusConnection *conn,
4705 DBusMessage *msg, void *user_data)
4707 struct connman_service *service = user_data;
4710 DBG("service %p", service);
4712 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
4715 if (g_str_equal(name, "Error")) {
4716 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4718 g_get_current_time(&service->modified);
4719 service_save(service);
4721 return __connman_error_invalid_property(msg);
4723 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4726 static bool is_ipconfig_usable(struct connman_service *service)
4728 if (!__connman_ipconfig_is_usable(service->ipconfig_ipv4) &&
4729 !__connman_ipconfig_is_usable(service->ipconfig_ipv6))
4735 static bool is_ignore(struct connman_service *service)
4737 if (!service->autoconnect)
4740 if (service->roaming)
4743 if (service->ignore)
4746 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
4749 if (!is_ipconfig_usable(service))
4755 static void disconnect_on_last_session(enum connman_service_type type)
4759 for (list = service_list; list; list = list->next) {
4760 struct connman_service *service = list->data;
4762 if (service->type != type)
4765 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_SESSION)
4768 __connman_service_disconnect(service);
4773 static int active_sessions[MAX_CONNMAN_SERVICE_TYPES] = {};
4774 static int active_count = 0;
4776 void __connman_service_set_active_session(bool enable, GSList *list)
4786 while (list != NULL) {
4787 enum connman_service_type type = GPOINTER_TO_INT(list->data);
4790 case CONNMAN_SERVICE_TYPE_ETHERNET:
4791 case CONNMAN_SERVICE_TYPE_WIFI:
4792 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4793 case CONNMAN_SERVICE_TYPE_CELLULAR:
4794 case CONNMAN_SERVICE_TYPE_GADGET:
4796 active_sessions[type]++;
4798 active_sessions[type]--;
4801 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4802 case CONNMAN_SERVICE_TYPE_SYSTEM:
4803 case CONNMAN_SERVICE_TYPE_GPS:
4804 case CONNMAN_SERVICE_TYPE_VPN:
4805 case CONNMAN_SERVICE_TYPE_P2P:
4809 if (active_sessions[type] == 0)
4810 disconnect_on_last_session(type);
4812 list = g_slist_next(list);
4815 DBG("eth %d wifi %d bt %d cellular %d gadget %d sessions %d",
4816 active_sessions[CONNMAN_SERVICE_TYPE_ETHERNET],
4817 active_sessions[CONNMAN_SERVICE_TYPE_WIFI],
4818 active_sessions[CONNMAN_SERVICE_TYPE_BLUETOOTH],
4819 active_sessions[CONNMAN_SERVICE_TYPE_CELLULAR],
4820 active_sessions[CONNMAN_SERVICE_TYPE_GADGET],
4824 struct preferred_tech_data {
4825 GList *preferred_list;
4826 enum connman_service_type type;
4829 static void preferred_tech_add_by_type(gpointer data, gpointer user_data)
4831 struct connman_service *service = data;
4832 struct preferred_tech_data *tech_data = user_data;
4834 if (service->type == tech_data->type) {
4835 tech_data->preferred_list =
4836 g_list_append(tech_data->preferred_list, service);
4838 DBG("type %d service %p %s", tech_data->type, service,
4843 static GList *preferred_tech_list_get(void)
4845 unsigned int *tech_array;
4846 struct preferred_tech_data tech_data = { 0, };
4849 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
4853 if (connman_setting_get_bool("SingleConnectedTechnology")) {
4855 for (list = service_list; list; list = list->next) {
4856 struct connman_service *service = list->data;
4858 if (!is_connected(service))
4861 if (service->connect_reason ==
4862 CONNMAN_SERVICE_CONNECT_REASON_USER) {
4863 DBG("service %p name %s is user connected",
4864 service, service->name);
4865 #if defined TIZEN_EXT
4866 /* We can connect to a favorite service like
4867 * wifi even we have a userconnect for cellular
4868 * because we have refount for cellular service
4870 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
4873 if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
4881 for (i = 0; tech_array[i] != 0; i += 1) {
4882 tech_data.type = tech_array[i];
4883 g_list_foreach(service_list, preferred_tech_add_by_type,
4887 return tech_data.preferred_list;
4890 static bool auto_connect_service(GList *services,
4891 enum connman_service_connect_reason reason,
4894 struct connman_service *service = NULL;
4895 bool ignore[MAX_CONNMAN_SERVICE_TYPES] = { };
4896 bool autoconnecting = false;
4899 DBG("preferred %d sessions %d reason %s", preferred, active_count,
4900 reason2string(reason));
4902 ignore[CONNMAN_SERVICE_TYPE_VPN] = true;
4904 for (list = services; list; list = list->next) {
4905 service = list->data;
4907 if (ignore[service->type]) {
4908 DBG("service %p type %s ignore", service,
4909 __connman_service_type2string(service->type));
4913 #if defined TIZEN_EXT
4914 DBG("service %p %s %s %s, favorite(%d), ignore(%d), hidden(%d, %d)",
4915 service, service->name,
4916 state2string(service->state),
4917 __connman_service_type2string(service->type),
4918 service->favorite, is_ignore(service),
4919 service->hidden, service->hidden_service);
4921 /* Tizen takes Wi-Fi as the highest priority into consideration. */
4922 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
4923 if (is_connecting(service) == TRUE || is_connected(service) == TRUE)
4927 if (service->pending ||
4928 is_connecting(service) ||
4929 is_connected(service)) {
4933 ignore[service->type] = true;
4934 autoconnecting = true;
4936 DBG("service %p type %s busy", service,
4937 __connman_service_type2string(service->type));
4942 if (!service->favorite) {
4946 #if defined TIZEN_EXT
4947 DBG("Service is not favorite, autoconnecting %d",
4950 return autoconnecting;
4953 #if defined TIZEN_EXT
4954 DBG("service %p identifier %s roaming %d ignore %d "
4955 "ipconfig_usable %d autoconnect %d state %d",
4957 service->identifier, service->roaming,
4958 service->ignore, is_ipconfig_usable(service),
4959 service->autoconnect, service->state);
4961 if (is_ignore(service) || service->state !=
4962 CONNMAN_SERVICE_STATE_IDLE)
4965 if (autoconnecting && !active_sessions[service->type]) {
4966 DBG("service %p type %s has no users", service,
4967 __connman_service_type2string(service->type));
4971 if (!is_service_owner_user_login(service)) {
4972 DBG("favorite user not login, wifi auto connect denied");
4976 DBG("service %p %s %s", service, service->name,
4977 (preferred) ? "preferred" : reason2string(reason));
4979 __connman_service_connect(service, reason);
4984 ignore[service->type] = true;
4987 return autoconnecting;
4990 static gboolean run_auto_connect(gpointer data)
4992 enum connman_service_connect_reason reason = GPOINTER_TO_UINT(data);
4993 bool autoconnecting = false;
4994 GList *preferred_tech;
4996 autoconnect_timeout = 0;
5000 preferred_tech = preferred_tech_list_get();
5001 if (preferred_tech) {
5002 autoconnecting = auto_connect_service(preferred_tech, reason,
5004 g_list_free(preferred_tech);
5007 if (!autoconnecting || active_count)
5008 auto_connect_service(service_list, reason, false);
5013 #if defined TIZEN_EXT
5014 bool __connman_service_get_auto_connect_mode(void)
5016 return auto_connect_mode;
5019 void __connman_service_set_auto_connect_mode(bool enable)
5021 DBG("set auto_connect_mode = %d", enable);
5023 if (auto_connect_mode != enable)
5024 auto_connect_mode = enable;
5028 void __connman_service_auto_connect(enum connman_service_connect_reason reason)
5032 if (autoconnect_timeout != 0)
5035 #if defined TIZEN_EXT
5036 if (auto_connect_mode == FALSE) {
5037 DBG("Currently, not auto connection mode");
5042 if (!__connman_session_policy_autoconnect(reason))
5045 #if defined TIZEN_EXT
5046 /* Adding Timeout of 500ms before trying to auto connect.
5047 * This is done because of below scenario
5048 * 1. Device is connected to AP1
5049 * 2. WPS Connection request is initiated for AP2
5050 * 3. Immediately WPS Connection is Cancelled
5051 * When WPS Connection Connection is initiated for AP2 then
5052 * sometimes there is a scenario where connman gets in ASSOCIATED
5053 * state with AP1 due to autoconnect and subsequently the connection
5054 * initiated by AP1 fails and connman service for AP1 comes in
5055 * FAILURE state due to this when connection with AP2 is cancelled
5056 * then autoconnect with AP1 doesn't works because its autoconnection
5057 * is ignored as its last state was FAILURE rather than IDLE */
5058 autoconnect_timeout = g_timeout_add(500, run_auto_connect,
5060 autoconnect_timeout = g_timeout_add_seconds(0, run_auto_connect,
5062 GUINT_TO_POINTER(reason));
5065 static gboolean run_vpn_auto_connect(gpointer data) {
5067 bool need_split = false;
5069 vpn_autoconnect_timeout = 0;
5071 for (list = service_list; list; list = list->next) {
5072 struct connman_service *service = list->data;
5075 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
5078 if (is_connected(service) || is_connecting(service)) {
5079 if (!service->do_split_routing)
5084 if (is_ignore(service) || !service->favorite)
5087 if (need_split && !service->do_split_routing) {
5088 DBG("service %p no split routing", service);
5092 DBG("service %p %s %s", service, service->name,
5093 service->do_split_routing ?
5094 "split routing" : "");
5096 res = __connman_service_connect(service,
5097 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5098 if (res < 0 && res != -EINPROGRESS)
5101 if (!service->do_split_routing)
5108 static void vpn_auto_connect(void)
5110 if (vpn_autoconnect_timeout)
5113 vpn_autoconnect_timeout =
5114 g_timeout_add_seconds(0, run_vpn_auto_connect, NULL);
5117 static void remove_timeout(struct connman_service *service)
5119 if (service->timeout > 0) {
5120 g_source_remove(service->timeout);
5121 service->timeout = 0;
5125 static void reply_pending(struct connman_service *service, int error)
5127 remove_timeout(service);
5129 if (service->pending) {
5130 connman_dbus_reply_pending(service->pending, error, NULL);
5131 service->pending = NULL;
5134 if (service->provider_pending) {
5135 connman_dbus_reply_pending(service->provider_pending,
5136 error, service->path);
5137 service->provider_pending = NULL;
5142 __connman_service_is_provider_pending(struct connman_service *service)
5147 if (service->provider_pending)
5153 void __connman_service_set_provider_pending(struct connman_service *service,
5156 if (service->provider_pending) {
5157 DBG("service %p provider pending msg %p already exists",
5158 service, service->provider_pending);
5162 service->provider_pending = msg;
5166 static void check_pending_msg(struct connman_service *service)
5168 if (!service->pending)
5171 DBG("service %p pending msg %p already exists", service,
5173 dbus_message_unref(service->pending);
5176 void __connman_service_set_hidden_data(struct connman_service *service,
5179 DBusMessage *pending = user_data;
5181 DBG("service %p pending %p", service, pending);
5186 check_pending_msg(service);
5188 service->pending = pending;
5191 void __connman_service_return_error(struct connman_service *service,
5192 int error, gpointer user_data)
5194 DBG("service %p error %d user_data %p", service, error, user_data);
5196 __connman_service_set_hidden_data(service, user_data);
5198 reply_pending(service, error);
5201 static gboolean connect_timeout(gpointer user_data)
5203 struct connman_service *service = user_data;
5204 bool autoconnect = false;
5206 DBG("service %p", service);
5208 service->timeout = 0;
5210 if (service->network)
5211 __connman_network_disconnect(service->network);
5212 else if (service->provider)
5213 connman_provider_disconnect(service->provider);
5215 __connman_ipconfig_disable(service->ipconfig_ipv4);
5216 __connman_ipconfig_disable(service->ipconfig_ipv6);
5218 __connman_stats_service_unregister(service);
5220 if (service->pending) {
5223 reply = __connman_error_operation_timeout(service->pending);
5225 g_dbus_send_message(connection, reply);
5227 dbus_message_unref(service->pending);
5228 service->pending = NULL;
5232 __connman_service_ipconfig_indicate_state(service,
5233 CONNMAN_SERVICE_STATE_FAILURE,
5234 CONNMAN_IPCONFIG_TYPE_IPV4);
5235 __connman_service_ipconfig_indicate_state(service,
5236 CONNMAN_SERVICE_STATE_FAILURE,
5237 CONNMAN_IPCONFIG_TYPE_IPV6);
5240 service->connect_reason !=
5241 CONNMAN_SERVICE_CONNECT_REASON_USER)
5242 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
5247 static DBusMessage *connect_service(DBusConnection *conn,
5248 DBusMessage *msg, void *user_data)
5250 struct connman_service *service = user_data;
5251 #if defined TIZEN_EXT
5258 DBG("service %p", service);
5260 #if defined TIZEN_EXT
5262 * Description: TIZEN implements system global connection management.
5264 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5265 connman_service_user_pdn_connection_ref(service);
5267 /*Reset the Disconnect Reason while issue connect request*/
5268 service->disconnect_reason = 0;
5271 if (service->pending)
5272 return __connman_error_in_progress(msg);
5274 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5276 if (connman_dbus_get_connection_unix_user_sync(conn,
5277 dbus_message_get_sender(msg),
5279 DBG("Can not get unix user id!");
5280 return __connman_error_permission_denied(msg);
5283 if (!__connman_service_is_user_allowed(CONNMAN_SERVICE_TYPE_WIFI, uid)) {
5284 DBG("Not allow this user to connect this wifi service now!");
5285 return __connman_error_permission_denied(msg);
5288 if (uid != USER_ROOT && uid != service->user.favorite_user)
5289 service->request_passphrase_input = true;
5291 service->user.current_user = uid;
5293 if (!service->passphrase && uid == service->user.favorite_user) {
5294 DBG("Now load this favorite user's passphrase.");
5295 service_load_passphrase(service);
5299 #if !defined TIZEN_EXT
5300 index = __connman_service_get_index(service);
5302 for (list = service_list; list; list = list->next) {
5303 struct connman_service *temp = list->data;
5305 #if defined TIZEN_EXT
5306 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5309 if (!is_connecting(temp) && !is_connected(temp))
5312 if (service == temp)
5315 if (service->type != temp->type)
5318 if (__connman_service_get_index(temp) == index &&
5319 __connman_service_disconnect(temp) == -EINPROGRESS)
5323 if (err == -EINPROGRESS)
5324 return __connman_error_operation_timeout(msg);
5327 service->ignore = false;
5329 service->pending = dbus_message_ref(msg);
5331 err = __connman_service_connect(service,
5332 CONNMAN_SERVICE_CONNECT_REASON_USER);
5334 if (err == -EINPROGRESS)
5337 if (service->pending) {
5338 dbus_message_unref(service->pending);
5339 service->pending = NULL;
5343 return __connman_error_failed(msg, -err);
5345 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5348 static DBusMessage *disconnect_service(DBusConnection *conn,
5349 DBusMessage *msg, void *user_data)
5351 struct connman_service *service = user_data;
5354 DBG("service %p", service);
5356 #if defined TIZEN_EXT
5358 * Description: TIZEN implements system global connection management.
5360 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
5361 if (connman_service_user_pdn_connection_unref_and_test(service) != TRUE)
5362 return __connman_error_failed(msg, EISCONN);
5364 if (is_connected(service) == TRUE &&
5365 service == connman_service_get_default_connection())
5366 return __connman_error_failed(msg, EISCONN);
5370 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5372 if (connman_dbus_get_connection_unix_user_sync(conn,
5373 dbus_message_get_sender(msg),
5375 DBG("Can not get unix user id!");
5376 return __connman_error_permission_denied(msg);
5379 if (!connman_service_is_user_allowed(service, uid)) {
5380 DBG("Not allow this user to disconnect this wifi service now!");
5381 return __connman_error_permission_denied(msg);
5385 service->ignore = true;
5387 err = __connman_service_disconnect(service);
5388 if (err < 0 && err != -EINPROGRESS)
5389 return __connman_error_failed(msg, -err);
5391 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5394 #if defined TIZEN_EXT
5395 static void __connman_service_cleanup_network_8021x(struct connman_service *service)
5397 if (service == NULL)
5400 DBG("service %p ", service);
5402 connman_network_set_string(service->network, "WiFi.EAP", NULL);
5403 connman_network_set_string(service->network, "WiFi.Identity", NULL);
5404 connman_network_set_string(service->network, "WiFi.CACertFile", NULL);
5405 connman_network_set_string(service->network, "WiFi.ClientCertFile", NULL);
5406 connman_network_set_string(service->network, "WiFi.PrivateKeyFile", NULL);
5407 connman_network_set_string(service->network, "WiFi.PrivateKeyPassphrase", NULL);
5408 connman_network_set_string(service->network, "WiFi.Phase2", NULL);
5412 bool __connman_service_remove(struct connman_service *service)
5414 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET ||
5415 service->type == CONNMAN_SERVICE_TYPE_GADGET)
5418 if (service->immutable || service->hidden ||
5419 __connman_provider_is_immutable(service->provider))
5422 #if !defined TIZEN_EXT
5423 if (!service->favorite && service->state !=
5424 CONNMAN_SERVICE_STATE_FAILURE)
5428 __connman_service_disconnect(service);
5430 g_free(service->passphrase);
5431 service->passphrase = NULL;
5433 g_free(service->identity);
5434 service->identity = NULL;
5436 g_free(service->agent_identity);
5437 service->agent_identity = NULL;
5439 g_free(service->eap);
5440 service->eap = NULL;
5442 #if defined TIZEN_EXT
5443 g_free(service->ca_cert_file);
5444 service->ca_cert_file = NULL;
5446 g_free(service->client_cert_file);
5447 service->client_cert_file = NULL;
5449 g_free(service->private_key_file);
5450 service->private_key_file = NULL;
5452 g_free(service->private_key_passphrase);
5453 service->private_key_passphrase = NULL;
5455 g_free(service->phase2);
5456 service->phase2 = NULL;
5458 __connman_service_cleanup_network_8021x(service);
5460 __connman_ipconfig_set_method(service->ipconfig_ipv4, CONNMAN_IPCONFIG_METHOD_DHCP);
5461 __connman_ipconfig_set_method(service->ipconfig_ipv6, CONNMAN_IPCONFIG_METHOD_AUTO);
5462 connman_service_set_proxy(service, NULL, false);
5464 __connman_service_nameserver_clear(service);
5466 g_strfreev(service->nameservers_config);
5467 service->nameservers_config = NULL;
5471 #if defined TIZEN_EXT
5472 if (service->security != CONNMAN_SERVICE_SECURITY_8021X)
5476 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
5478 service->user.favorite_user = USER_NONE;
5480 __connman_service_set_favorite(service, false);
5482 __connman_ipconfig_ipv6_reset_privacy(service->ipconfig_ipv6);
5484 #if defined TIZEN_EXT
5485 /* Reset IP Method and DNS Method to DHCP */
5486 __connman_ipconfig_set_method(service->ipconfig_ipv4,
5487 CONNMAN_IPCONFIG_METHOD_DHCP);
5488 service->dns_config_method_ipv4 = CONNMAN_DNSCONFIG_METHOD_DHCP;
5489 g_strfreev(service->nameservers_config);
5490 service->nameservers_config = NULL;
5493 #if defined TIZEN_EXT
5494 __connman_storage_remove_service(service->identifier);
5496 service_save(service);
5502 static DBusMessage *remove_service(DBusConnection *conn,
5503 DBusMessage *msg, void *user_data)
5505 struct connman_service *service = user_data;
5507 DBG("service %p", service);
5509 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
5511 if (connman_dbus_get_connection_unix_user_sync(conn,
5512 dbus_message_get_sender(msg),
5514 DBG("Can not get unix user id!");
5515 return __connman_error_permission_denied(msg);
5518 #if !defined TIZEN_EXT
5519 if (!connman_service_is_user_allowed(service, uid)) {
5520 DBG("Not allow this user to remove this wifi service now!");
5521 return __connman_error_permission_denied(msg);
5526 if (!__connman_service_remove(service))
5527 return __connman_error_not_supported(msg);
5529 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5532 static bool check_suitable_state(enum connman_service_state a,
5533 enum connman_service_state b)
5536 * Special check so that "ready" service can be moved before
5539 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
5540 b == CONNMAN_SERVICE_STATE_READY) ||
5541 (b == CONNMAN_SERVICE_STATE_ONLINE &&
5542 a == CONNMAN_SERVICE_STATE_READY))
5548 static void downgrade_state(struct connman_service *service)
5553 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
5554 service->state_ipv6);
5556 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
5557 __connman_service_ipconfig_indicate_state(service,
5558 CONNMAN_SERVICE_STATE_READY,
5559 CONNMAN_IPCONFIG_TYPE_IPV4);
5561 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
5562 __connman_service_ipconfig_indicate_state(service,
5563 CONNMAN_SERVICE_STATE_READY,
5564 CONNMAN_IPCONFIG_TYPE_IPV6);
5567 static void apply_relevant_default_downgrade(struct connman_service *service)
5569 struct connman_service *def_service;
5571 def_service = __connman_service_get_default();
5575 if (def_service == service &&
5576 def_service->state == CONNMAN_SERVICE_STATE_ONLINE) {
5577 def_service->state = CONNMAN_SERVICE_STATE_READY;
5578 __connman_notifier_leave_online(def_service->type);
5579 state_changed(def_service);
5583 static void switch_default_service(struct connman_service *default_service,
5584 struct connman_service *downgrade_service)
5586 struct connman_service *service;
5589 apply_relevant_default_downgrade(default_service);
5590 src = g_list_find(service_list, downgrade_service);
5591 dst = g_list_find(service_list, default_service);
5594 if (src == dst || src->next == dst)
5597 service = src->data;
5598 service_list = g_list_delete_link(service_list, src);
5599 service_list = g_list_insert_before(service_list, dst, service);
5601 downgrade_state(downgrade_service);
5604 static DBusMessage *move_service(DBusConnection *conn,
5605 DBusMessage *msg, void *user_data,
5608 struct connman_service *service = user_data;
5609 struct connman_service *target;
5611 enum connman_ipconfig_method target4, target6;
5612 enum connman_ipconfig_method service4, service6;
5614 DBG("service %p", service);
5616 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
5619 if (!service->favorite)
5620 return __connman_error_not_supported(msg);
5622 target = find_service(path);
5623 if (!target || !target->favorite || target == service)
5624 return __connman_error_invalid_service(msg);
5626 if (target->type == CONNMAN_SERVICE_TYPE_VPN) {
5628 * We only allow VPN route splitting if there are
5629 * routes defined for a given VPN.
5631 if (!__connman_provider_check_routes(target->provider)) {
5632 connman_info("Cannot move service. "
5633 "No routes defined for provider %s",
5634 __connman_provider_get_ident(target->provider));
5635 return __connman_error_invalid_service(msg);
5638 target->do_split_routing = true;
5640 target->do_split_routing = false;
5642 service->do_split_routing = false;
5644 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
5645 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
5646 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
5647 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
5649 DBG("target %s method %d/%d state %d/%d split %d", target->identifier,
5650 target4, target6, target->state_ipv4, target->state_ipv6,
5651 target->do_split_routing);
5653 DBG("service %s method %d/%d state %d/%d", service->identifier,
5655 service->state_ipv4, service->state_ipv6);
5658 * If method is OFF, then we do not need to check the corresponding
5661 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5662 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5663 if (!check_suitable_state(target->state_ipv6,
5664 service->state_ipv6))
5665 return __connman_error_invalid_service(msg);
5669 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5670 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5671 if (!check_suitable_state(target->state_ipv4,
5672 service->state_ipv4))
5673 return __connman_error_invalid_service(msg);
5677 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5678 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5679 if (!check_suitable_state(target->state_ipv6,
5680 service->state_ipv6))
5681 return __connman_error_invalid_service(msg);
5685 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5686 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5687 if (!check_suitable_state(target->state_ipv4,
5688 service->state_ipv4))
5689 return __connman_error_invalid_service(msg);
5693 g_get_current_time(&service->modified);
5694 service_save(service);
5695 service_save(target);
5698 * If the service which goes down is the default service and is
5699 * online, we downgrade directly its state to ready so:
5700 * the service which goes up, needs to recompute its state which
5701 * is triggered via downgrading it - if relevant - to state ready.
5704 switch_default_service(target, service);
5706 switch_default_service(service, target);
5708 __connman_connection_update_gateway();
5710 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5713 static DBusMessage *move_before(DBusConnection *conn,
5714 DBusMessage *msg, void *user_data)
5716 return move_service(conn, msg, user_data, true);
5719 static DBusMessage *move_after(DBusConnection *conn,
5720 DBusMessage *msg, void *user_data)
5722 return move_service(conn, msg, user_data, false);
5725 static DBusMessage *reset_counters(DBusConnection *conn,
5726 DBusMessage *msg, void *user_data)
5728 struct connman_service *service = user_data;
5730 reset_stats(service);
5732 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5735 static DBusMessage *get_user_favorite(DBusConnection *conn,
5736 DBusMessage *msg, void *user_data)
5739 uid_t uid = USER_NONE;
5740 dbus_bool_t user_favorite = false;
5741 struct connman_service *service = user_data;
5743 connman_dbus_get_connection_unix_user_sync(conn,
5744 dbus_message_get_sender(msg),
5746 if (uid == USER_ROOT)
5747 user_favorite = service->favorite;
5748 else if (uid != USER_NONE && uid == service->user.favorite_user) {
5749 DBG("The service is favorite to this user!");
5750 user_favorite = true;
5753 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5754 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN,
5755 &user_favorite, DBUS_TYPE_INVALID);
5759 static struct _services_notify {
5765 static void service_append_added_foreach(gpointer data, gpointer user_data)
5767 struct connman_service *service = data;
5768 DBusMessageIter *iter = user_data;
5770 if (!service || !service->path) {
5771 #if !defined TIZEN_EXT
5772 DBG("service %p or path is NULL", service);
5777 if (g_hash_table_lookup(services_notify->add, service->path)) {
5778 #if !defined TIZEN_EXT
5779 DBG("new %s", service->path);
5782 append_struct(service, iter);
5783 g_hash_table_remove(services_notify->add, service->path);
5785 #if !defined TIZEN_EXT
5786 DBG("changed %s", service->path);
5789 append_struct_service(iter, NULL, service);
5793 static void service_append_ordered(DBusMessageIter *iter, void *user_data)
5795 g_list_foreach(service_list, service_append_added_foreach, iter);
5798 static void append_removed(gpointer key, gpointer value, gpointer user_data)
5800 char *objpath = key;
5801 DBusMessageIter *iter = user_data;
5803 DBG("removed %s", objpath);
5804 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath);
5807 static void service_append_removed(DBusMessageIter *iter, void *user_data)
5809 g_hash_table_foreach(services_notify->remove, append_removed, iter);
5812 static gboolean service_send_changed(gpointer data)
5814 DBusMessage *signal;
5818 services_notify->id = 0;
5820 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
5821 CONNMAN_MANAGER_INTERFACE, "ServicesChanged");
5825 __connman_dbus_append_objpath_dict_array(signal,
5826 service_append_ordered, NULL);
5827 __connman_dbus_append_objpath_array(signal,
5828 service_append_removed, NULL);
5830 dbus_connection_send(connection, signal, NULL);
5831 dbus_message_unref(signal);
5833 g_hash_table_remove_all(services_notify->remove);
5834 g_hash_table_remove_all(services_notify->add);
5839 static void service_schedule_changed(void)
5841 if (services_notify->id != 0)
5844 services_notify->id = g_timeout_add(100, service_send_changed, NULL);
5847 static void service_schedule_added(struct connman_service *service)
5849 DBG("service %p", service);
5851 g_hash_table_remove(services_notify->remove, service->path);
5852 g_hash_table_replace(services_notify->add, service->path, service);
5854 service_schedule_changed();
5857 static void service_schedule_removed(struct connman_service *service)
5859 if (!service || !service->path) {
5860 DBG("service %p or path is NULL", service);
5864 DBG("service %p %s", service, service->path);
5866 g_hash_table_remove(services_notify->add, service->path);
5867 g_hash_table_replace(services_notify->remove, g_strdup(service->path),
5870 service_schedule_changed();
5873 static bool allow_property_changed(struct connman_service *service)
5875 #if defined TIZEN_EXT
5876 if (service->path == NULL)
5879 if (g_hash_table_lookup_extended(services_notify->add, service->path,
5881 DBG("no property updates for service %p", service);
5888 static const GDBusMethodTable service_methods[] = {
5889 { GDBUS_DEPRECATED_METHOD("GetProperties",
5890 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
5892 { GDBUS_METHOD("SetProperty",
5893 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
5894 NULL, set_property) },
5895 { GDBUS_METHOD("ClearProperty",
5896 GDBUS_ARGS({ "name", "s" }), NULL,
5898 { GDBUS_ASYNC_METHOD("Connect", NULL, NULL,
5900 { GDBUS_METHOD("Disconnect", NULL, NULL,
5901 disconnect_service) },
5902 { GDBUS_METHOD("Remove", NULL, NULL, remove_service) },
5903 { GDBUS_METHOD("MoveBefore",
5904 GDBUS_ARGS({ "service", "o" }), NULL,
5906 { GDBUS_METHOD("MoveAfter",
5907 GDBUS_ARGS({ "service", "o" }), NULL,
5909 { GDBUS_METHOD("ResetCounters", NULL, NULL, reset_counters) },
5910 { GDBUS_METHOD("GetUserFavorite",
5911 NULL, GDBUS_ARGS({ "value", "v" }),
5912 get_user_favorite) },
5916 static const GDBusSignalTable service_signals[] = {
5917 { GDBUS_SIGNAL("PropertyChanged",
5918 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
5922 static void service_free(gpointer user_data)
5924 struct connman_service *service = user_data;
5925 char *path = service->path;
5927 DBG("service %p", service);
5929 reply_pending(service, ENOENT);
5931 __connman_notifier_service_remove(service);
5932 service_schedule_removed(service);
5934 __connman_wispr_stop(service);
5935 stats_stop(service);
5937 service->path = NULL;
5940 __connman_connection_update_gateway();
5942 g_dbus_unregister_interface(connection, path,
5943 CONNMAN_SERVICE_INTERFACE);
5947 g_hash_table_destroy(service->counter_table);
5949 if (service->network) {
5950 __connman_network_disconnect(service->network);
5951 connman_network_unref(service->network);
5952 service->network = NULL;
5955 if (service->provider)
5956 connman_provider_unref(service->provider);
5958 if (service->ipconfig_ipv4) {
5959 __connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
5960 __connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
5961 __connman_ipconfig_unref(service->ipconfig_ipv4);
5962 service->ipconfig_ipv4 = NULL;
5965 if (service->ipconfig_ipv6) {
5966 __connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
5967 __connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
5968 __connman_ipconfig_unref(service->ipconfig_ipv6);
5969 service->ipconfig_ipv6 = NULL;
5972 g_strfreev(service->timeservers);
5973 g_strfreev(service->timeservers_config);
5974 g_strfreev(service->nameservers);
5975 g_strfreev(service->nameservers_config);
5976 g_strfreev(service->nameservers_auto);
5977 g_strfreev(service->domains);
5978 g_strfreev(service->proxies);
5979 g_strfreev(service->excludes);
5981 g_free(service->hostname);
5982 g_free(service->domainname);
5983 g_free(service->pac);
5984 g_free(service->name);
5985 g_free(service->passphrase);
5986 g_free(service->identifier);
5987 g_free(service->eap);
5988 g_free(service->identity);
5989 g_free(service->agent_identity);
5990 g_free(service->ca_cert_file);
5991 g_free(service->client_cert_file);
5992 g_free(service->private_key_file);
5993 g_free(service->private_key_passphrase);
5994 g_free(service->phase2);
5995 g_free(service->config_file);
5996 g_free(service->config_entry);
5998 if (service->stats.timer)
5999 g_timer_destroy(service->stats.timer);
6000 if (service->stats_roaming.timer)
6001 g_timer_destroy(service->stats_roaming.timer);
6003 if (current_default == service)
6004 current_default = NULL;
6009 static void stats_init(struct connman_service *service)
6012 service->stats.valid = false;
6013 service->stats.enabled = false;
6014 service->stats.timer = g_timer_new();
6017 service->stats_roaming.valid = false;
6018 service->stats_roaming.enabled = false;
6019 service->stats_roaming.timer = g_timer_new();
6022 static void service_initialize(struct connman_service *service)
6024 DBG("service %p", service);
6026 service->refcount = 1;
6028 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
6030 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
6031 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
6033 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
6034 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
6035 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
6037 service->favorite = false;
6038 service->immutable = false;
6039 service->hidden = false;
6041 service->ignore = false;
6043 service->user.favorite_user = USER_NONE;
6044 service->user.current_user = USER_NONE;
6046 service->request_passphrase_input = false;
6048 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
6052 stats_init(service);
6054 service->provider = NULL;
6056 service->wps = false;
6057 #if defined TIZEN_EXT
6058 service->storage_reload = false;
6060 * Description: TIZEN implements system global connection management.
6062 service->user_pdn_connection_refcount = 0;
6063 __sync_synchronize();
6068 * connman_service_create:
6070 * Allocate a new service.
6072 * Returns: a newly-allocated #connman_service structure
6074 struct connman_service *connman_service_create(void)
6077 struct connman_stats_counter *counters;
6078 const char *counter;
6080 struct connman_service *service;
6082 service = g_try_new0(struct connman_service, 1);
6086 DBG("service %p", service);
6088 service->counter_table = g_hash_table_new_full(g_str_hash,
6089 g_str_equal, NULL, g_free);
6091 for (list = counter_list; list; list = list->next) {
6092 counter = list->data;
6094 counters = g_try_new0(struct connman_stats_counter, 1);
6096 g_hash_table_destroy(service->counter_table);
6101 counters->append_all = true;
6103 g_hash_table_replace(service->counter_table, (gpointer)counter,
6107 service_initialize(service);
6113 * connman_service_ref:
6114 * @service: service structure
6116 * Increase reference counter of service
6118 struct connman_service *
6119 connman_service_ref_debug(struct connman_service *service,
6120 const char *file, int line, const char *caller)
6122 DBG("%p ref %d by %s:%d:%s()", service, service->refcount + 1,
6123 file, line, caller);
6125 __sync_fetch_and_add(&service->refcount, 1);
6131 * connman_service_unref:
6132 * @service: service structure
6134 * Decrease reference counter of service and release service if no
6137 void connman_service_unref_debug(struct connman_service *service,
6138 const char *file, int line, const char *caller)
6140 DBG("%p ref %d by %s:%d:%s()", service, service->refcount - 1,
6141 file, line, caller);
6143 if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
6146 service_list = g_list_remove(service_list, service);
6148 __connman_service_disconnect(service);
6150 g_hash_table_remove(service_hash, service->identifier);
6153 static gint service_compare(gconstpointer a, gconstpointer b)
6155 struct connman_service *service_a = (void *) a;
6156 struct connman_service *service_b = (void *) b;
6157 enum connman_service_state state_a, state_b;
6158 bool a_connected, b_connected;
6161 state_a = service_a->state;
6162 state_b = service_b->state;
6163 a_connected = is_connected(service_a);
6164 b_connected = is_connected(service_b);
6166 if (a_connected && b_connected) {
6167 if (service_a->order > service_b->order)
6170 if (service_a->order < service_b->order)
6174 if (state_a != state_b) {
6175 if (a_connected && b_connected) {
6176 /* We prefer online over ready state */
6177 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
6180 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
6189 if (is_connecting(service_a))
6191 if (is_connecting(service_b))
6195 if (service_a->favorite && !service_b->favorite)
6198 if (!service_a->favorite && service_b->favorite)
6201 if (service_a->type != service_b->type) {
6203 if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6205 if (service_b->type == CONNMAN_SERVICE_TYPE_ETHERNET)
6208 if (service_a->type == CONNMAN_SERVICE_TYPE_WIFI)
6210 if (service_b->type == CONNMAN_SERVICE_TYPE_WIFI)
6213 if (service_a->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6215 if (service_b->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6218 if (service_a->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6220 if (service_b->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
6223 if (service_a->type == CONNMAN_SERVICE_TYPE_VPN)
6225 if (service_b->type == CONNMAN_SERVICE_TYPE_VPN)
6228 if (service_a->type == CONNMAN_SERVICE_TYPE_GADGET)
6230 if (service_b->type == CONNMAN_SERVICE_TYPE_GADGET)
6234 strength = (gint) service_b->strength - (gint) service_a->strength;
6238 return g_strcmp0(service_a->name, service_b->name);
6241 static void service_list_sort(void)
6243 if (service_list && service_list->next) {
6244 service_list = g_list_sort(service_list, service_compare);
6245 service_schedule_changed();
6250 * connman_service_get_type:
6251 * @service: service structure
6253 * Get the type of service
6255 enum connman_service_type connman_service_get_type(struct connman_service *service)
6258 return CONNMAN_SERVICE_TYPE_UNKNOWN;
6260 return service->type;
6264 * connman_service_get_interface:
6265 * @service: service structure
6267 * Get network interface of service
6269 char *connman_service_get_interface(struct connman_service *service)
6276 index = __connman_service_get_index(service);
6278 return connman_inet_ifname(index);
6282 * __connman_service_is_user_allowed:
6283 * @type: service type
6286 * Check a user is allowed to operate a type of service
6288 bool __connman_service_is_user_allowed(enum connman_service_type type,
6292 uid_t owner_user = USER_NONE;
6294 for (list = service_list; list; list = list->next) {
6295 struct connman_service *service = list->data;
6297 if (service->type != type)
6300 if (is_connected(service)) {
6301 owner_user = service->user.favorite_user;
6306 if (uid == USER_NONE ||
6307 (uid != USER_ROOT &&
6308 owner_user != USER_NONE &&
6316 * connman_service_get_network:
6317 * @service: service structure
6319 * Get the service network
6321 struct connman_network *
6322 __connman_service_get_network(struct connman_service *service)
6327 return service->network;
6330 struct connman_ipconfig *
6331 __connman_service_get_ip4config(struct connman_service *service)
6336 return service->ipconfig_ipv4;
6339 struct connman_ipconfig *
6340 __connman_service_get_ip6config(struct connman_service *service)
6345 return service->ipconfig_ipv6;
6348 struct connman_ipconfig *
6349 __connman_service_get_ipconfig(struct connman_service *service, int family)
6351 if (family == AF_INET)
6352 return __connman_service_get_ip4config(service);
6353 else if (family == AF_INET6)
6354 return __connman_service_get_ip6config(service);
6360 bool __connman_service_is_connected_state(struct connman_service *service,
6361 enum connman_ipconfig_type type)
6367 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
6369 case CONNMAN_IPCONFIG_TYPE_IPV4:
6370 return is_connected_state(service, service->state_ipv4);
6371 case CONNMAN_IPCONFIG_TYPE_IPV6:
6372 return is_connected_state(service, service->state_ipv6);
6373 case CONNMAN_IPCONFIG_TYPE_ALL:
6374 return is_connected_state(service,
6375 CONNMAN_IPCONFIG_TYPE_IPV4) &&
6376 is_connected_state(service,
6377 CONNMAN_IPCONFIG_TYPE_IPV6);
6382 enum connman_service_security __connman_service_get_security(
6383 struct connman_service *service)
6386 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
6388 return service->security;
6391 const char *__connman_service_get_phase2(struct connman_service *service)
6396 return service->phase2;
6399 bool __connman_service_wps_enabled(struct connman_service *service)
6404 return service->wps;
6407 void __connman_service_mark_dirty(void)
6409 services_dirty = true;
6412 #if defined TIZEN_EXT
6414 * Returns profile count if there is any connected profiles
6415 * that use same interface
6417 int __connman_service_get_connected_count_of_iface(
6418 struct connman_service *service)
6427 index1 = __connman_service_get_index(service);
6432 for (list = service_list; list; list = list->next) {
6433 struct connman_service *service2 = list->data;
6435 if (service == service2)
6438 index2 = __connman_service_get_index(service2);
6440 if (is_connected(service2) && index2 > 0 && index1 == index2)
6446 DBG("Interface index %d, count %d", index1, count);
6451 void __connman_service_set_storage_reload(struct connman_service *service,
6452 bool storage_reload)
6454 if (service != NULL)
6455 service->storage_reload = storage_reload;
6460 * __connman_service_set_favorite_delayed:
6461 * @service: service structure
6462 * @favorite: favorite value
6463 * @delay_ordering: do not order service sequence
6465 * Change the favorite setting of service
6467 int __connman_service_set_favorite_delayed(struct connman_service *service,
6469 bool delay_ordering)
6471 #if defined TIZEN_EXT
6472 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6475 if (service->hidden)
6478 if (service->favorite == favorite)
6481 service->favorite = favorite;
6483 if (!delay_ordering)
6484 __connman_service_get_order(service);
6486 favorite_changed(service);
6488 if (!delay_ordering) {
6490 service_list_sort();
6492 __connman_connection_update_gateway();
6499 * __connman_service_set_favorite:
6500 * @service: service structure
6501 * @favorite: favorite value
6503 * Change the favorite setting of service
6505 int __connman_service_set_favorite(struct connman_service *service,
6508 return __connman_service_set_favorite_delayed(service, favorite,
6512 bool connman_service_get_favorite(struct connman_service *service)
6514 return service->favorite;
6517 bool connman_service_get_autoconnect(struct connman_service *service)
6519 return service->autoconnect;
6522 int __connman_service_set_immutable(struct connman_service *service,
6525 if (service->hidden)
6528 if (service->immutable == immutable)
6531 service->immutable = immutable;
6533 immutable_changed(service);
6538 int __connman_service_set_ignore(struct connman_service *service,
6544 service->ignore = ignore;
6549 void __connman_service_set_string(struct connman_service *service,
6550 const char *key, const char *value)
6552 if (service->hidden)
6554 if (g_str_equal(key, "EAP")) {
6555 g_free(service->eap);
6556 service->eap = g_strdup(value);
6557 } else if (g_str_equal(key, "Identity")) {
6558 g_free(service->identity);
6559 service->identity = g_strdup(value);
6560 } else if (g_str_equal(key, "CACertFile")) {
6561 g_free(service->ca_cert_file);
6562 service->ca_cert_file = g_strdup(value);
6563 } else if (g_str_equal(key, "ClientCertFile")) {
6564 g_free(service->client_cert_file);
6565 service->client_cert_file = g_strdup(value);
6566 } else if (g_str_equal(key, "PrivateKeyFile")) {
6567 g_free(service->private_key_file);
6568 service->private_key_file = g_strdup(value);
6569 } else if (g_str_equal(key, "PrivateKeyPassphrase")) {
6570 g_free(service->private_key_passphrase);
6571 service->private_key_passphrase = g_strdup(value);
6572 } else if (g_str_equal(key, "Phase2")) {
6573 g_free(service->phase2);
6574 service->phase2 = g_strdup(value);
6575 } else if (g_str_equal(key, "Passphrase"))
6576 __connman_service_set_passphrase(service, value);
6579 void __connman_service_set_search_domains(struct connman_service *service,
6582 searchdomain_remove_all(service);
6584 if (service->domains)
6585 g_strfreev(service->domains);
6587 service->domains = g_strdupv(domains);
6589 searchdomain_add_all(service);
6592 static void service_complete(struct connman_service *service)
6594 reply_pending(service, EIO);
6596 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
6597 __connman_service_auto_connect(service->connect_reason);
6599 g_get_current_time(&service->modified);
6600 service_save(service);
6603 static void report_error_cb(void *user_context, bool retry,
6606 struct connman_service *service = user_context;
6609 __connman_service_connect(service,
6610 CONNMAN_SERVICE_CONNECT_REASON_USER);
6612 /* It is not relevant to stay on Failure state
6613 * when failing is due to wrong user input */
6614 __connman_service_clear_error(service);
6615 #if defined TIZEN_EXT
6616 /* Reseting the state back in case of failure state */
6617 service->state_ipv4 = service->state_ipv6 =
6618 CONNMAN_SERVICE_STATE_IDLE;
6620 if (service->error != CONNMAN_SERVICE_ERROR_AUTH_FAILED)
6621 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6623 service_complete(service);
6624 __connman_connection_update_gateway();
6628 static int check_wpspin(struct connman_service *service, const char *wpspin)
6636 length = strlen(wpspin);
6638 /* If 0, it will mean user wants to use PBC method */
6640 connman_network_set_string(service->network,
6641 "WiFi.PinWPS", NULL);
6645 /* A WPS PIN is always 8 chars length,
6646 * its content is in digit representation.
6651 for (i = 0; i < 8; i++)
6652 if (!isdigit((unsigned char) wpspin[i]))
6655 connman_network_set_string(service->network, "WiFi.PinWPS", wpspin);
6660 static void request_input_cb(struct connman_service *service,
6661 bool values_received,
6662 const char *name, int name_len,
6663 const char *identity, const char *passphrase,
6664 bool wps, const char *wpspin,
6665 const char *error, void *user_data)
6667 struct connman_device *device;
6668 const char *security;
6671 DBG("RequestInput return, %p", service);
6674 DBG("error: %s", error);
6676 if (g_strcmp0(error,
6677 "net.connman.Agent.Error.Canceled") == 0) {
6680 if (service->hidden)
6681 __connman_service_return_error(service,
6682 ECANCELED, user_data);
6685 if (service->hidden)
6686 __connman_service_return_error(service,
6687 ETIMEDOUT, user_data);
6691 if (service->hidden && name_len > 0 && name_len <= 32) {
6692 device = connman_network_get_device(service->network);
6693 security = connman_network_get_string(service->network,
6695 err = __connman_device_request_hidden_scan(device,
6697 identity, passphrase,
6698 security, user_data);
6700 __connman_service_return_error(service, -err,
6704 if (!values_received || service->hidden) {
6709 if (wps && service->network) {
6710 err = check_wpspin(service, wpspin);
6714 connman_network_set_bool(service->network, "WiFi.UseWPS", wps);
6718 __connman_service_set_agent_identity(service, identity);
6721 err = __connman_service_set_passphrase(service, passphrase);
6725 /* We forget any previous error. */
6726 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6728 __connman_service_connect(service,
6729 CONNMAN_SERVICE_CONNECT_REASON_USER);
6731 } else if (err == -ENOKEY) {
6732 __connman_service_indicate_error(service,
6733 CONNMAN_SERVICE_ERROR_INVALID_KEY);
6735 /* It is not relevant to stay on Failure state
6736 * when failing is due to wrong user input */
6737 service->state = CONNMAN_SERVICE_STATE_IDLE;
6739 if (!service->hidden) {
6741 * If there was a real error when requesting
6742 * hidden scan, then that error is returned already
6743 * to the user somewhere above so do not try to
6746 __connman_service_return_error(service, -err,
6750 service_complete(service);
6751 __connman_connection_update_gateway();
6755 static void downgrade_connected_services(void)
6757 struct connman_service *up_service;
6760 for (list = service_list; list; list = list->next) {
6761 up_service = list->data;
6763 if (!is_connected(up_service))
6766 if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
6769 downgrade_state(up_service);
6773 static int service_update_preferred_order(struct connman_service *default_service,
6774 struct connman_service *new_service,
6775 enum connman_service_state new_state)
6777 unsigned int *tech_array;
6780 if (!default_service || default_service == new_service ||
6781 default_service->state != new_state)
6784 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
6787 for (i = 0; tech_array[i] != 0; i += 1) {
6788 if (default_service->type == tech_array[i])
6791 if (new_service->type == tech_array[i]) {
6792 switch_default_service(default_service,
6794 __connman_connection_update_gateway();
6803 #if defined TIZEN_EXT
6804 static gboolean __connman_service_can_drop(struct connman_service *service)
6806 if (is_connected(service) == TRUE || is_connecting(service) == TRUE) {
6807 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
6809 else if (connman_service_is_no_ref_user_pdn_connection(service) == TRUE)
6815 static struct connman_device *default_connecting_device = NULL;
6817 static void __connman_service_disconnect_default(struct connman_service *service)
6819 struct connman_device *default_device = NULL;
6821 if (default_connecting_device == NULL)
6824 default_device = connman_network_get_device(
6825 __connman_service_get_network(service));
6827 DBG("Disconnecting service %p %s", service, service->path);
6828 DBG("Disconnecting device %p %p %s",
6829 default_connecting_device,
6831 connman_device_get_string(default_device, "Name"));
6833 if (default_connecting_device == default_device)
6834 default_connecting_device = NULL;
6837 static void __connman_service_connect_default(struct connman_service *current)
6841 bool default_internet;
6842 struct connman_service *service;
6843 struct connman_service *default_service = NULL;
6844 struct connman_device *default_device = NULL;
6846 if (current->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
6847 switch (current->state) {
6848 case CONNMAN_SERVICE_STATE_UNKNOWN:
6849 case CONNMAN_SERVICE_STATE_ASSOCIATION:
6850 case CONNMAN_SERVICE_STATE_CONFIGURATION:
6856 if (default_connecting_device &&
6857 __connman_service_is_internet_profile(current) == TRUE) {
6858 if (current->network == NULL)
6861 default_device = connman_network_get_device(current->network);
6862 if (default_connecting_device == default_device) {
6863 DBG("Cellular service[%s] %p %s",
6864 state2string(current->state), current, current->path);
6865 DBG("Cellular device %p %p %s",
6866 default_connecting_device, default_device,
6867 connman_device_get_string(default_device, "Name"));
6869 default_connecting_device = NULL;
6874 } else if (is_connected(current) == TRUE || is_connecting(current) == TRUE)
6877 /* Always-on: keep default cellular connection as possible */
6878 for (list = service_list; list; list = list->next) {
6879 service = list->data;
6881 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
6882 __connman_service_is_internet_profile(service) != TRUE ||
6883 service->network == NULL) {
6888 connman_network_get_bool(service->network, "DefaultInternet");
6890 DBG("service: %p %s %s %s (default: %d)", service, service->name,
6891 __connman_service_type2string(service->type),
6892 state2string(service->state), default_internet);
6894 if (default_internet) {
6895 default_service = service;
6896 if (is_connected(default_service) == TRUE ||
6897 is_connecting(default_service) == TRUE)
6900 default_device = connman_network_get_device(default_service->network);
6901 if (default_connecting_device == default_device) {
6902 DBG("Device is connecting (%p)", default_connecting_device);
6906 default_connecting_device = default_device;
6907 default_service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_USER;
6909 err = __connman_network_connect(default_service->network);
6910 DBG("Connecting default service %p %s [%d]",
6911 default_service, default_service->path, err);
6912 DBG("Connecting device %p %s", default_connecting_device,
6913 connman_device_get_string(default_connecting_device, "Name"));
6914 if (err < 0 && err != -EINPROGRESS) {
6915 default_connecting_device = NULL;
6923 static void single_connected_tech(struct connman_service *allowed)
6925 struct connman_service *service;
6926 GSList *services = NULL, *list;
6929 DBG("keeping %p %s", allowed, allowed->path);
6931 #if defined TIZEN_EXT
6932 if (!allowed || allowed->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6936 for (iter = service_list; iter; iter = iter->next) {
6937 service = iter->data;
6939 #if defined TIZEN_EXT
6940 if (service != allowed && service->type != allowed->type &&
6941 __connman_service_can_drop(service) == TRUE)
6943 if (!is_connected(service))
6946 if (service == allowed)
6949 services = g_slist_prepend(services, service);
6952 for (list = services; list; list = list->next) {
6953 service = list->data;
6955 DBG("disconnecting %p %s", service, service->path);
6956 #if defined TIZEN_EXT
6957 __connman_service_disconnect_default(service);
6959 __connman_service_disconnect(service);
6962 g_slist_free(services);
6965 #if defined TIZEN_EXT
6966 static void set_priority_connected_service(void)
6968 struct connman_service *service;
6971 for (list = service_list; list; list = list->next) {
6972 service = list->data;
6974 if (is_connected(service) == FALSE)
6982 static const char *get_dbus_sender(struct connman_service *service)
6984 if (!service->pending)
6987 return dbus_message_get_sender(service->pending);
6990 static int service_indicate_state(struct connman_service *service)
6992 enum connman_service_state old_state, new_state;
6993 struct connman_service *def_service;
6994 enum connman_ipconfig_method method;
7000 old_state = service->state;
7001 new_state = combine_state(service->state_ipv4, service->state_ipv6);
7003 DBG("service %p old %s - new %s/%s => %s",
7005 state2string(old_state),
7006 state2string(service->state_ipv4),
7007 state2string(service->state_ipv6),
7008 state2string(new_state));
7010 if (old_state == new_state)
7013 def_service = __connman_service_get_default();
7015 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
7016 result = service_update_preferred_order(def_service,
7017 service, new_state);
7018 if (result == -EALREADY)
7022 if (old_state == CONNMAN_SERVICE_STATE_ONLINE)
7023 __connman_notifier_leave_online(service->type);
7025 if (is_connected_state(service, old_state) &&
7026 !is_connected_state(service, new_state))
7027 searchdomain_remove_all(service);
7029 service->state = new_state;
7030 state_changed(service);
7033 case CONNMAN_SERVICE_STATE_UNKNOWN:
7037 case CONNMAN_SERVICE_STATE_IDLE:
7038 if (old_state != CONNMAN_SERVICE_STATE_DISCONNECT)
7039 __connman_service_disconnect(service);
7043 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7047 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7048 if (!service->new_service &&
7049 __connman_stats_service_register(service) == 0) {
7051 * For new services the statistics are updated after
7052 * we have successfully connected.
7054 __connman_stats_get(service, false,
7055 &service->stats.data);
7056 __connman_stats_get(service, true,
7057 &service->stats_roaming.data);
7062 case CONNMAN_SERVICE_STATE_READY:
7063 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7065 if (service->new_service &&
7066 __connman_stats_service_register(service) == 0) {
7068 * This is normally done after configuring state
7069 * but for new service do this after we have connected
7072 __connman_stats_get(service, false,
7073 &service->stats.data);
7074 __connman_stats_get(service, true,
7075 &service->stats_roaming.data);
7078 service->new_service = false;
7082 def_service = __connman_service_get_default();
7084 service_update_preferred_order(def_service, service, new_state);
7086 __connman_service_set_favorite(service, true);
7088 reply_pending(service, 0);
7090 g_get_current_time(&service->modified);
7091 service_save(service);
7093 searchdomain_add_all(service);
7094 dns_changed(service);
7095 domain_changed(service);
7096 proxy_changed(service);
7098 if (old_state != CONNMAN_SERVICE_STATE_ONLINE)
7099 __connman_notifier_connect(service->type);
7101 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7102 connman_network_get_bool(service->network,
7106 pass = connman_network_get_string(service->network,
7109 __connman_service_set_passphrase(service, pass);
7111 connman_network_set_bool(service->network,
7112 "WiFi.UseWPS", false);
7115 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
7116 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
7117 __connman_ipconfig_disable_ipv6(
7118 service->ipconfig_ipv6);
7120 if (connman_setting_get_bool("SingleConnectedTechnology"))
7121 single_connected_tech(service);
7122 else if (service->type != CONNMAN_SERVICE_TYPE_VPN)
7125 #if defined TIZEN_EXT
7126 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7127 set_priority_connected_service();
7132 case CONNMAN_SERVICE_STATE_ONLINE:
7136 case CONNMAN_SERVICE_STATE_DISCONNECT:
7137 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
7139 reply_pending(service, ECONNABORTED);
7141 def_service = __connman_service_get_default();
7142 service->disconnect_reason = connman_network_get_disconnect_reason(service->network);
7144 if (!__connman_notifier_is_connected() &&
7146 def_service->provider)
7147 connman_provider_disconnect(def_service->provider);
7151 __connman_wispr_stop(service);
7153 __connman_wpad_stop(service);
7155 #if defined TIZEN_EXT
7157 * Skip the functions if there is any connected profiles
7158 * that use same interface
7160 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7161 __connman_service_get_connected_count_of_iface(
7164 dns_changed(service);
7165 domain_changed(service);
7166 proxy_changed(service);
7167 #if defined TIZEN_EXT
7172 * Previous services which are connected and which states
7173 * are set to online should reset relevantly ipconfig_state
7174 * to ready so wispr/portal will be rerun on those
7176 downgrade_connected_services();
7178 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7181 case CONNMAN_SERVICE_STATE_FAILURE:
7182 #if defined TIZEN_EXT
7183 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7185 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
7187 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7188 connman_agent_report_error(service, service->path,
7189 error2string(service->error),
7191 get_dbus_sender(service),
7192 NULL) == -EINPROGRESS)
7194 service_complete(service);
7199 service_list_sort();
7201 #if defined TIZEN_EXT
7202 __connman_service_connect_default(service);
7205 __connman_connection_update_gateway();
7207 if ((old_state == CONNMAN_SERVICE_STATE_ONLINE &&
7208 new_state != CONNMAN_SERVICE_STATE_READY) ||
7209 (old_state == CONNMAN_SERVICE_STATE_READY &&
7210 new_state != CONNMAN_SERVICE_STATE_ONLINE)) {
7211 __connman_notifier_disconnect(service->type);
7214 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
7215 __connman_notifier_enter_online(service->type);
7219 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7220 service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
7221 (new_state == CONNMAN_SERVICE_STATE_READY ||
7222 new_state == CONNMAN_SERVICE_STATE_ONLINE)) {
7223 if (service->user.favorite_user != service->user.current_user) {
7224 DBG("Now set service favorite user id from %d to %d",
7225 service->user.favorite_user, service->user.current_user);
7227 service->user.favorite_user = service->user.current_user;
7229 service_save(service);
7236 int __connman_service_indicate_error(struct connman_service *service,
7237 enum connman_service_error error)
7239 DBG("service %p error %d", service, error);
7244 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
7247 set_error(service, error);
7249 /* default internet service: fix not cleared if pdp activation*/
7250 #if defined TIZEN_EXT
7252 * If connection failed for default service(DefaultInternet),
7253 * default_connecting_device should be cleared.
7255 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7256 service->error == CONNMAN_SERVICE_ERROR_CONNECT_FAILED)
7257 __connman_service_disconnect_default(service);
7259 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
7260 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY) {
7261 g_free(service->passphrase);
7262 service->passphrase = NULL;
7266 __connman_service_ipconfig_indicate_state(service,
7267 CONNMAN_SERVICE_STATE_FAILURE,
7268 CONNMAN_IPCONFIG_TYPE_IPV4);
7269 __connman_service_ipconfig_indicate_state(service,
7270 CONNMAN_SERVICE_STATE_FAILURE,
7271 CONNMAN_IPCONFIG_TYPE_IPV6);
7275 int __connman_service_clear_error(struct connman_service *service)
7277 DBusMessage *pending, *provider_pending;
7279 DBG("service %p", service);
7284 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
7287 pending = service->pending;
7288 service->pending = NULL;
7289 provider_pending = service->provider_pending;
7290 service->provider_pending = NULL;
7292 __connman_service_ipconfig_indicate_state(service,
7293 CONNMAN_SERVICE_STATE_IDLE,
7294 CONNMAN_IPCONFIG_TYPE_IPV6);
7296 __connman_service_ipconfig_indicate_state(service,
7297 CONNMAN_SERVICE_STATE_IDLE,
7298 CONNMAN_IPCONFIG_TYPE_IPV4);
7300 service->pending = pending;
7301 service->provider_pending = provider_pending;
7306 int __connman_service_indicate_default(struct connman_service *service)
7308 DBG("service %p state %s", service, state2string(service->state));
7310 if (!is_connected(service)) {
7312 * If service is not yet fully connected, then we must not
7313 * change the default yet. The default gw will be changed
7314 * after the service state is in ready.
7316 return -EINPROGRESS;
7324 enum connman_service_state __connman_service_ipconfig_get_state(
7325 struct connman_service *service,
7326 enum connman_ipconfig_type type)
7329 return CONNMAN_SERVICE_STATE_UNKNOWN;
7331 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7332 return service->state_ipv4;
7334 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
7335 return service->state_ipv6;
7337 return CONNMAN_SERVICE_STATE_UNKNOWN;
7340 static void check_proxy_setup(struct connman_service *service)
7343 * We start WPAD if we haven't got a PAC URL from DHCP and
7344 * if our proxy manual configuration is either empty or set
7345 * to AUTO with an empty URL.
7348 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
7351 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
7352 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
7356 if (__connman_wpad_start(service) < 0) {
7357 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
7358 __connman_notifier_proxy_changed(service);
7365 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
7368 #if defined TIZEN_EXT
7369 void connman_check_proxy_setup_and_wispr_start(struct connman_service *service){
7371 DBG("check the proxy and start wispr");
7372 check_proxy_setup(service);
7378 * How many networks are connected at the same time. If more than 1,
7379 * then set the rp_filter setting properly (loose mode routing) so that network
7380 * connectivity works ok. This is only done for IPv4 networks as IPv6
7381 * does not have rp_filter knob.
7383 static int connected_networks_count;
7384 static int original_rp_filter;
7386 static void service_rp_filter(struct connman_service *service,
7389 enum connman_ipconfig_method method;
7391 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
7394 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7395 case CONNMAN_IPCONFIG_METHOD_OFF:
7396 case CONNMAN_IPCONFIG_METHOD_AUTO:
7398 case CONNMAN_IPCONFIG_METHOD_FIXED:
7399 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7400 case CONNMAN_IPCONFIG_METHOD_DHCP:
7405 if (connected_networks_count == 1) {
7407 filter_value = __connman_ipconfig_set_rp_filter();
7408 if (filter_value < 0)
7411 original_rp_filter = filter_value;
7413 connected_networks_count++;
7416 if (connected_networks_count == 2)
7417 __connman_ipconfig_unset_rp_filter(original_rp_filter);
7419 connected_networks_count--;
7420 if (connected_networks_count < 0)
7421 connected_networks_count = 0;
7424 DBG("%s %s ipconfig %p method %d count %d filter %d",
7425 connected ? "connected" : "disconnected", service->identifier,
7426 service->ipconfig_ipv4, method,
7427 connected_networks_count, original_rp_filter);
7430 static gboolean redo_wispr(gpointer user_data)
7432 struct connman_service *service = user_data;
7433 int refcount = service->refcount - 1;
7435 connman_service_unref(service);
7436 if (refcount == 0) {
7437 DBG("Service %p already removed", service);
7441 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV6);
7446 int __connman_service_online_check_failed(struct connman_service *service,
7447 enum connman_ipconfig_type type)
7449 DBG("service %p type %d count %d", service, type,
7450 service->online_check_count);
7452 /* currently we only retry IPv6 stuff */
7453 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 ||
7454 service->online_check_count != 1) {
7455 connman_warn("Online check failed for %p %s", service,
7460 service->online_check_count = 0;
7463 * We set the timeout to 1 sec so that we have a chance to get
7464 * necessary IPv6 router advertisement messages that might have
7467 g_timeout_add_seconds(1, redo_wispr, connman_service_ref(service));
7472 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
7473 enum connman_service_state new_state,
7474 enum connman_ipconfig_type type)
7476 struct connman_ipconfig *ipconfig = NULL;
7477 enum connman_service_state old_state;
7478 enum connman_ipconfig_method method;
7484 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
7485 case CONNMAN_IPCONFIG_TYPE_ALL:
7488 case CONNMAN_IPCONFIG_TYPE_IPV4:
7489 old_state = service->state_ipv4;
7490 ipconfig = service->ipconfig_ipv4;
7494 case CONNMAN_IPCONFIG_TYPE_IPV6:
7495 old_state = service->state_ipv6;
7496 ipconfig = service->ipconfig_ipv6;
7505 if (old_state == new_state)
7508 #if defined TIZEN_EXT
7509 __sync_synchronize();
7510 if (service->user_pdn_connection_refcount > 0 &&
7511 service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7512 if (new_state == CONNMAN_SERVICE_STATE_FAILURE ||
7513 new_state == CONNMAN_SERVICE_STATE_DISCONNECT ||
7514 new_state == CONNMAN_SERVICE_STATE_IDLE) {
7515 service->user_pdn_connection_refcount = 0;
7516 __sync_synchronize();
7520 DBG("service %p (%s) old state %d (%s) new state %d (%s) type %d (%s)",
7521 service, service ? service->identifier : NULL,
7522 old_state, state2string(old_state),
7523 new_state, state2string(new_state),
7524 type, __connman_ipconfig_type2string(type));
7526 switch (new_state) {
7527 case CONNMAN_SERVICE_STATE_UNKNOWN:
7528 case CONNMAN_SERVICE_STATE_IDLE:
7529 case CONNMAN_SERVICE_STATE_ASSOCIATION:
7531 case CONNMAN_SERVICE_STATE_CONFIGURATION:
7532 __connman_ipconfig_enable(ipconfig);
7534 case CONNMAN_SERVICE_STATE_READY:
7535 #if defined TIZEN_EXT
7536 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7537 __connman_service_is_internet_profile(service) != TRUE) {
7538 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7539 service_rp_filter(service, TRUE);
7544 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
7545 #if !defined TIZEN_EXT
7546 check_proxy_setup(service);
7548 service_rp_filter(service, true);
7550 service->online_check_count = 1;
7551 __connman_wispr_start(service, type);
7554 case CONNMAN_SERVICE_STATE_ONLINE:
7556 case CONNMAN_SERVICE_STATE_DISCONNECT:
7557 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
7560 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7561 service_rp_filter(service, false);
7564 case CONNMAN_SERVICE_STATE_FAILURE:
7568 /* Keep that state, but if the ipconfig method is OFF, then we set
7569 the state to IDLE so that it will not affect the combined state
7572 method = __connman_ipconfig_get_method(ipconfig);
7574 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
7575 case CONNMAN_IPCONFIG_METHOD_OFF:
7576 new_state = CONNMAN_SERVICE_STATE_IDLE;
7579 case CONNMAN_IPCONFIG_METHOD_FIXED:
7580 case CONNMAN_IPCONFIG_METHOD_MANUAL:
7581 case CONNMAN_IPCONFIG_METHOD_DHCP:
7582 case CONNMAN_IPCONFIG_METHOD_AUTO:
7587 if (is_connected_state(service, old_state) &&
7588 !is_connected_state(service, new_state))
7589 #if defined TIZEN_EXT
7591 DBG("nameserver remove all, type: %d", type);
7592 nameserver_remove_all(service, type);
7594 nameserver_remove_all(service);
7596 #if defined TIZEN_EXT
7600 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
7601 service->state_ipv4 = new_state;
7603 service->state_ipv6 = new_state;
7605 if (!is_connected_state(service, old_state) &&
7606 is_connected_state(service, new_state))
7607 #if defined TIZEN_EXT
7609 DBG("nameserver add all, type: %d", type);
7610 nameserver_add_all(service, type);
7612 nameserver_add_all(service);
7614 #if defined TIZEN_EXT
7618 #if defined TIZEN_EXT
7619 int ret = service_indicate_state(service);
7620 /*Sent the Ready changed signal again in case IPv4 IP set
7623 if(ret == -EALREADY && type == CONNMAN_IPCONFIG_TYPE_IPV4
7624 && new_state == CONNMAN_SERVICE_STATE_READY) {
7625 DBG("Notify IPv4 state new/old %d/%d", new_state,old_state);
7626 state_changed(service);
7631 return service_indicate_state(service);
7634 static bool prepare_network(struct connman_service *service)
7636 enum connman_network_type type;
7637 unsigned int ssid_len;
7639 type = connman_network_get_type(service->network);
7642 case CONNMAN_NETWORK_TYPE_UNKNOWN:
7643 case CONNMAN_NETWORK_TYPE_VENDOR:
7645 case CONNMAN_NETWORK_TYPE_WIFI:
7646 if (!connman_network_get_blob(service->network, "WiFi.SSID",
7650 if (service->passphrase)
7651 connman_network_set_string(service->network,
7652 "WiFi.Passphrase", service->passphrase);
7654 case CONNMAN_NETWORK_TYPE_ETHERNET:
7655 case CONNMAN_NETWORK_TYPE_GADGET:
7656 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
7657 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
7658 case CONNMAN_NETWORK_TYPE_CELLULAR:
7665 static void prepare_8021x(struct connman_service *service)
7668 connman_network_set_string(service->network, "WiFi.EAP",
7671 if (service->identity)
7672 connman_network_set_string(service->network, "WiFi.Identity",
7675 if (service->ca_cert_file)
7676 connman_network_set_string(service->network, "WiFi.CACertFile",
7677 service->ca_cert_file);
7679 if (service->client_cert_file)
7680 connman_network_set_string(service->network,
7681 "WiFi.ClientCertFile",
7682 service->client_cert_file);
7684 if (service->private_key_file)
7685 connman_network_set_string(service->network,
7686 "WiFi.PrivateKeyFile",
7687 service->private_key_file);
7689 if (service->private_key_passphrase)
7690 connman_network_set_string(service->network,
7691 "WiFi.PrivateKeyPassphrase",
7692 service->private_key_passphrase);
7694 if (service->phase2)
7695 connman_network_set_string(service->network, "WiFi.Phase2",
7699 static int service_connect(struct connman_service *service)
7703 if (service->hidden)
7706 #if defined TIZEN_EXT
7710 index = __connman_service_get_index(service);
7712 for (list = service_list; list; list = list->next) {
7713 struct connman_service *temp = list->data;
7715 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7718 if (!is_connecting(temp) && !is_connected(temp))
7721 if (service == temp)
7724 if (service->type != temp->type)
7727 if (__connman_service_get_index(temp) == index &&
7728 __connman_service_disconnect(temp) == -EINPROGRESS)
7729 return -EINPROGRESS;
7733 switch (service->type) {
7734 case CONNMAN_SERVICE_TYPE_UNKNOWN:
7735 case CONNMAN_SERVICE_TYPE_SYSTEM:
7736 case CONNMAN_SERVICE_TYPE_GPS:
7737 case CONNMAN_SERVICE_TYPE_P2P:
7739 case CONNMAN_SERVICE_TYPE_ETHERNET:
7740 case CONNMAN_SERVICE_TYPE_GADGET:
7741 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
7742 case CONNMAN_SERVICE_TYPE_CELLULAR:
7743 case CONNMAN_SERVICE_TYPE_VPN:
7745 case CONNMAN_SERVICE_TYPE_WIFI:
7746 switch (service->security) {
7747 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
7748 case CONNMAN_SERVICE_SECURITY_NONE:
7750 case CONNMAN_SERVICE_SECURITY_WEP:
7751 case CONNMAN_SERVICE_SECURITY_PSK:
7752 case CONNMAN_SERVICE_SECURITY_WPA:
7753 case CONNMAN_SERVICE_SECURITY_RSN:
7754 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
7757 if (service->request_passphrase_input) {
7758 DBG("Now try to connect other user's favorite service");
7759 service->request_passphrase_input = false;
7761 } else if (!service->passphrase) {
7762 if (!service->network)
7765 if (!service->wps ||
7766 !connman_network_get_bool(service->network, "WiFi.UseWPS"))
7771 case CONNMAN_SERVICE_SECURITY_8021X:
7775 #if defined TIZEN_EXT
7777 * never request credentials if using EAP-TLS, EAP-SIM
7778 * or EAP-AKA (EAP-TLS, EAP-SIM and EAP-AKA networks
7779 * need to be fully provisioned)
7781 DBG("service eap: %s", service->eap);
7782 if (g_str_equal(service->eap, "tls") ||
7783 g_str_equal(service->eap, "sim") ||
7784 g_str_equal(service->eap, "aka"))
7788 * never request credentials if using EAP-TLS
7789 * (EAP-TLS networks need to be fully provisioned)
7791 if (g_str_equal(service->eap, "tls"))
7795 * Return -ENOKEY if either identity or passphrase is
7796 * missing. Agent provided credentials can be used as
7797 * fallback if needed.
7799 if (((!service->identity &&
7800 !service->agent_identity) ||
7801 !service->passphrase) ||
7802 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
7810 if (service->network) {
7811 if (!prepare_network(service))
7814 switch (service->security) {
7815 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
7816 case CONNMAN_SERVICE_SECURITY_NONE:
7817 case CONNMAN_SERVICE_SECURITY_WEP:
7818 case CONNMAN_SERVICE_SECURITY_PSK:
7819 case CONNMAN_SERVICE_SECURITY_WPA:
7820 case CONNMAN_SERVICE_SECURITY_RSN:
7822 case CONNMAN_SERVICE_SECURITY_8021X:
7823 prepare_8021x(service);
7827 if (__connman_stats_service_register(service) == 0) {
7828 __connman_stats_get(service, false,
7829 &service->stats.data);
7830 __connman_stats_get(service, true,
7831 &service->stats_roaming.data);
7834 if (service->ipconfig_ipv4)
7835 __connman_ipconfig_enable(service->ipconfig_ipv4);
7836 if (service->ipconfig_ipv6)
7837 __connman_ipconfig_enable(service->ipconfig_ipv6);
7839 err = __connman_network_connect(service->network);
7840 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7842 err = __connman_provider_connect(service->provider);
7847 if (err != -EINPROGRESS) {
7848 __connman_ipconfig_disable(service->ipconfig_ipv4);
7849 __connman_ipconfig_disable(service->ipconfig_ipv6);
7850 __connman_stats_service_unregister(service);
7857 int __connman_service_connect(struct connman_service *service,
7858 enum connman_service_connect_reason reason)
7862 DBG("service %p state %s connect reason %s -> %s",
7863 service, state2string(service->state),
7864 reason2string(service->connect_reason),
7865 reason2string(reason));
7867 if (is_connected(service))
7870 if (is_connecting(service))
7873 switch (service->type) {
7874 case CONNMAN_SERVICE_TYPE_UNKNOWN:
7875 case CONNMAN_SERVICE_TYPE_SYSTEM:
7876 case CONNMAN_SERVICE_TYPE_GPS:
7877 case CONNMAN_SERVICE_TYPE_P2P:
7880 case CONNMAN_SERVICE_TYPE_ETHERNET:
7881 case CONNMAN_SERVICE_TYPE_GADGET:
7882 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
7883 case CONNMAN_SERVICE_TYPE_CELLULAR:
7884 case CONNMAN_SERVICE_TYPE_VPN:
7885 case CONNMAN_SERVICE_TYPE_WIFI:
7889 if (!is_ipconfig_usable(service))
7892 __connman_service_clear_error(service);
7894 err = service_connect(service);
7896 service->connect_reason = reason;
7900 if (err == -EINPROGRESS) {
7901 if (service->timeout == 0)
7902 service->timeout = g_timeout_add_seconds(
7903 CONNECT_TIMEOUT, connect_timeout, service);
7905 return -EINPROGRESS;
7908 if (service->network)
7909 __connman_network_disconnect(service->network);
7910 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7912 connman_provider_disconnect(service->provider);
7914 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
7915 if (err == -ENOKEY || err == -EPERM) {
7916 DBusMessage *pending = NULL;
7919 * We steal the reply here. The idea is that the
7920 * connecting client will see the connection status
7921 * after the real hidden network is connected or
7922 * connection failed.
7924 if (service->hidden) {
7925 pending = service->pending;
7926 service->pending = NULL;
7929 err = __connman_agent_request_passphrase_input(service,
7931 get_dbus_sender(service),
7933 if (service->hidden && err != -EINPROGRESS)
7934 service->pending = pending;
7938 reply_pending(service, -err);
7944 int __connman_service_disconnect(struct connman_service *service)
7948 DBG("service %p", service);
7950 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
7951 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
7953 connman_agent_cancel(service);
7955 reply_pending(service, ECONNABORTED);
7957 if (service->network) {
7958 err = __connman_network_disconnect(service->network);
7959 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7961 err = connman_provider_disconnect(service->provider);
7965 if (err < 0 && err != -EINPROGRESS)
7968 __connman_6to4_remove(service->ipconfig_ipv4);
7970 if (service->ipconfig_ipv4)
7971 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
7974 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
7977 #if defined TIZEN_EXT
7979 * Skip the functions If there is any connected profiles
7980 * that use same interface
7982 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7983 __connman_service_get_connected_count_of_iface(service) <= 0) {
7985 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
7986 settings_changed(service, service->ipconfig_ipv4);
7988 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
7989 settings_changed(service, service->ipconfig_ipv6);
7991 __connman_ipconfig_disable(service->ipconfig_ipv4);
7992 __connman_ipconfig_disable(service->ipconfig_ipv6);
7993 #if defined TIZEN_EXT
7997 __connman_stats_service_unregister(service);
8002 int __connman_service_disconnect_all(void)
8004 struct connman_service *service;
8005 GSList *services = NULL, *list;
8010 for (iter = service_list; iter; iter = iter->next) {
8011 service = iter->data;
8013 if (!is_connected(service))
8016 services = g_slist_prepend(services, service);
8019 for (list = services; list; list = list->next) {
8020 struct connman_service *service = list->data;
8022 service->ignore = true;
8024 __connman_service_disconnect(service);
8027 g_slist_free(services);
8033 * lookup_by_identifier:
8034 * @identifier: service identifier
8036 * Look up a service by identifier (reference count will not be increased)
8038 static struct connman_service *lookup_by_identifier(const char *identifier)
8040 return g_hash_table_lookup(service_hash, identifier);
8043 struct provision_user_data {
8048 static void provision_changed(gpointer value, gpointer user_data)
8050 struct connman_service *service = value;
8051 struct provision_user_data *data = user_data;
8052 const char *path = data->ident;
8055 ret = __connman_config_provision_service_ident(service, path,
8056 service->config_file, service->config_entry);
8061 int __connman_service_provision_changed(const char *ident)
8063 struct provision_user_data data = {
8068 g_list_foreach(service_list, provision_changed, (void *)&data);
8071 * Because the provision_changed() might have set some services
8072 * as favorite, we must sort the sequence now.
8074 if (services_dirty) {
8075 services_dirty = false;
8077 service_list_sort();
8079 __connman_connection_update_gateway();
8085 void __connman_service_set_config(struct connman_service *service,
8086 const char *file_id, const char *entry)
8091 g_free(service->config_file);
8092 service->config_file = g_strdup(file_id);
8094 g_free(service->config_entry);
8095 service->config_entry = g_strdup(entry);
8099 * __connman_service_get:
8100 * @identifier: service identifier
8102 * Look up a service by identifier or create a new one if not found
8104 static struct connman_service *service_get(const char *identifier)
8106 struct connman_service *service;
8108 service = g_hash_table_lookup(service_hash, identifier);
8110 connman_service_ref(service);
8114 service = connman_service_create();
8118 DBG("service %p", service);
8120 service->identifier = g_strdup(identifier);
8122 service_list = g_list_insert_sorted(service_list, service,
8125 g_hash_table_insert(service_hash, service->identifier, service);
8130 static int service_register(struct connman_service *service)
8132 DBG("service %p", service);
8137 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
8138 service->identifier);
8140 DBG("path %s", service->path);
8142 if (__connman_config_provision_service(service) < 0)
8143 service_load(service);
8145 g_dbus_register_interface(connection, service->path,
8146 CONNMAN_SERVICE_INTERFACE,
8147 service_methods, service_signals,
8148 NULL, service, NULL);
8150 service_list_sort();
8152 __connman_connection_update_gateway();
8157 static void service_up(struct connman_ipconfig *ipconfig,
8160 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8162 DBG("%s up", ifname);
8164 link_changed(service);
8166 service->stats.valid = false;
8167 service->stats_roaming.valid = false;
8170 static void service_down(struct connman_ipconfig *ipconfig,
8173 DBG("%s down", ifname);
8176 static void service_lower_up(struct connman_ipconfig *ipconfig,
8179 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8181 DBG("%s lower up", ifname);
8183 stats_start(service);
8186 static void service_lower_down(struct connman_ipconfig *ipconfig,
8189 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8191 DBG("%s lower down", ifname);
8193 if (!is_idle_state(service, service->state_ipv4))
8194 __connman_ipconfig_disable(service->ipconfig_ipv4);
8196 if (!is_idle_state(service, service->state_ipv6))
8197 __connman_ipconfig_disable(service->ipconfig_ipv6);
8199 stats_stop(service);
8200 service_save(service);
8203 static void service_ip_bound(struct connman_ipconfig *ipconfig,
8206 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8207 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8208 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8209 #if defined TIZEN_EXT
8213 DBG("%s ip bound", ifname);
8215 type = __connman_ipconfig_get_config_type(ipconfig);
8216 method = __connman_ipconfig_get_method(ipconfig);
8218 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8221 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8222 method == CONNMAN_IPCONFIG_METHOD_AUTO)
8223 #if defined TIZEN_EXT
8225 err = __connman_ipconfig_gateway_add(ipconfig, service);
8228 __connman_connection_gateway_activate(service,
8229 CONNMAN_IPCONFIG_TYPE_IPV6);
8232 __connman_service_ipconfig_indicate_state(service,
8233 CONNMAN_SERVICE_STATE_READY,
8234 CONNMAN_IPCONFIG_TYPE_IPV6);
8237 settings_changed(service, ipconfig);
8240 static void service_ip_release(struct connman_ipconfig *ipconfig,
8243 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8244 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
8245 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
8247 DBG("%s ip release", ifname);
8249 type = __connman_ipconfig_get_config_type(ipconfig);
8250 method = __connman_ipconfig_get_method(ipconfig);
8252 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
8255 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
8256 method == CONNMAN_IPCONFIG_METHOD_OFF)
8257 __connman_service_ipconfig_indicate_state(service,
8258 CONNMAN_SERVICE_STATE_DISCONNECT,
8259 CONNMAN_IPCONFIG_TYPE_IPV6);
8261 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
8262 method == CONNMAN_IPCONFIG_METHOD_OFF)
8263 __connman_service_ipconfig_indicate_state(service,
8264 CONNMAN_SERVICE_STATE_DISCONNECT,
8265 CONNMAN_IPCONFIG_TYPE_IPV4);
8267 settings_changed(service, ipconfig);
8270 static void service_route_changed(struct connman_ipconfig *ipconfig,
8273 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
8275 DBG("%s route changed", ifname);
8277 settings_changed(service, ipconfig);
8280 static const struct connman_ipconfig_ops service_ops = {
8282 .down = service_down,
8283 .lower_up = service_lower_up,
8284 .lower_down = service_lower_down,
8285 .ip_bound = service_ip_bound,
8286 .ip_release = service_ip_release,
8287 .route_set = service_route_changed,
8288 .route_unset = service_route_changed,
8291 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
8292 int index, enum connman_ipconfig_method method)
8294 struct connman_ipconfig *ipconfig_ipv4;
8296 ipconfig_ipv4 = __connman_ipconfig_create(index,
8297 CONNMAN_IPCONFIG_TYPE_IPV4);
8301 __connman_ipconfig_set_method(ipconfig_ipv4, method);
8303 __connman_ipconfig_set_data(ipconfig_ipv4, service);
8305 __connman_ipconfig_set_ops(ipconfig_ipv4, &service_ops);
8307 return ipconfig_ipv4;
8310 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
8313 struct connman_ipconfig *ipconfig_ipv6;
8315 ipconfig_ipv6 = __connman_ipconfig_create(index,
8316 CONNMAN_IPCONFIG_TYPE_IPV6);
8320 __connman_ipconfig_set_data(ipconfig_ipv6, service);
8322 __connman_ipconfig_set_ops(ipconfig_ipv6, &service_ops);
8324 return ipconfig_ipv6;
8327 void __connman_service_read_ip4config(struct connman_service *service)
8331 if (!service->ipconfig_ipv4)
8334 keyfile = connman_storage_load_service(service->identifier);
8338 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
8339 service->identifier, "IPv4.");
8341 g_key_file_free(keyfile);
8344 void connman_service_create_ip4config(struct connman_service *service,
8347 DBG("ipv4 %p", service->ipconfig_ipv4);
8349 if (service->ipconfig_ipv4)
8352 service->ipconfig_ipv4 = create_ip4config(service, index,
8353 CONNMAN_IPCONFIG_METHOD_DHCP);
8354 __connman_service_read_ip4config(service);
8357 void __connman_service_read_ip6config(struct connman_service *service)
8361 if (!service->ipconfig_ipv6)
8364 keyfile = connman_storage_load_service(service->identifier);
8368 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
8369 service->identifier, "IPv6.");
8371 g_key_file_free(keyfile);
8374 void connman_service_create_ip6config(struct connman_service *service,
8377 DBG("ipv6 %p", service->ipconfig_ipv6);
8379 if (service->ipconfig_ipv6)
8382 service->ipconfig_ipv6 = create_ip6config(service, index);
8384 __connman_service_read_ip6config(service);
8388 * connman_service_lookup_from_network:
8389 * @network: network structure
8391 * Look up a service by network (reference count will not be increased)
8393 struct connman_service *connman_service_lookup_from_network(struct connman_network *network)
8395 struct connman_service *service;
8396 const char *ident, *group;
8402 ident = __connman_network_get_ident(network);
8406 group = connman_network_get_group(network);
8410 name = g_strdup_printf("%s_%s_%s",
8411 __connman_network_get_type(network), ident, group);
8412 service = lookup_by_identifier(name);
8418 struct connman_service *__connman_service_lookup_from_index(int index)
8420 struct connman_service *service;
8423 for (list = service_list; list; list = list->next) {
8424 service = list->data;
8426 if (__connman_ipconfig_get_index(service->ipconfig_ipv4)
8430 if (__connman_ipconfig_get_index(service->ipconfig_ipv6)
8438 struct connman_service *__connman_service_lookup_from_ident(const char *identifier)
8440 return lookup_by_identifier(identifier);
8443 const char *__connman_service_get_ident(struct connman_service *service)
8445 return service->identifier;
8448 const char *__connman_service_get_path(struct connman_service *service)
8450 return service->path;
8453 const char *__connman_service_get_name(struct connman_service *service)
8455 return service->name;
8458 enum connman_service_state __connman_service_get_state(struct connman_service *service)
8460 return service->state;
8463 unsigned int __connman_service_get_order(struct connman_service *service)
8465 unsigned int order = 0;
8472 if (!service->favorite)
8475 #if defined TIZEN_EXT
8476 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8477 service->do_split_routing == FALSE)
8479 else if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
8480 if (service->order < 5)
8482 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
8484 else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
8486 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8487 __connman_service_is_internet_profile(service) == TRUE)
8489 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
8490 __connman_service_is_tethering_profile(service) == TRUE)
8492 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
8497 if (service == service_list->data)
8500 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
8501 !service->do_split_routing) {
8502 service->order = 10;
8506 DBG("service %p name %s order %d split %d", service, service->name,
8507 order, service->do_split_routing);
8512 void __connman_service_update_ordering(void)
8514 if (service_list && service_list->next)
8515 service_list = g_list_sort(service_list, service_compare);
8518 static enum connman_service_type convert_network_type(struct connman_network *network)
8520 enum connman_network_type type = connman_network_get_type(network);
8523 case CONNMAN_NETWORK_TYPE_UNKNOWN:
8524 case CONNMAN_NETWORK_TYPE_VENDOR:
8526 case CONNMAN_NETWORK_TYPE_ETHERNET:
8527 return CONNMAN_SERVICE_TYPE_ETHERNET;
8528 case CONNMAN_NETWORK_TYPE_WIFI:
8529 return CONNMAN_SERVICE_TYPE_WIFI;
8530 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
8531 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
8532 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
8533 case CONNMAN_NETWORK_TYPE_CELLULAR:
8534 return CONNMAN_SERVICE_TYPE_CELLULAR;
8535 case CONNMAN_NETWORK_TYPE_GADGET:
8536 return CONNMAN_SERVICE_TYPE_GADGET;
8539 return CONNMAN_SERVICE_TYPE_UNKNOWN;
8542 static enum connman_service_security convert_wifi_security(const char *security)
8545 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8546 else if (g_str_equal(security, "none"))
8547 return CONNMAN_SERVICE_SECURITY_NONE;
8548 else if (g_str_equal(security, "wep"))
8549 return CONNMAN_SERVICE_SECURITY_WEP;
8550 else if (g_str_equal(security, "psk"))
8551 return CONNMAN_SERVICE_SECURITY_PSK;
8552 else if (g_str_equal(security, "ieee8021x"))
8553 return CONNMAN_SERVICE_SECURITY_8021X;
8554 else if (g_str_equal(security, "wpa"))
8555 return CONNMAN_SERVICE_SECURITY_WPA;
8556 else if (g_str_equal(security, "rsn"))
8557 return CONNMAN_SERVICE_SECURITY_RSN;
8558 #if defined TIZEN_EXT
8559 else if (g_str_equal(security, "ft_psk") == TRUE)
8560 return CONNMAN_SERVICE_SECURITY_PSK;
8561 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
8562 return CONNMAN_SERVICE_SECURITY_8021X;
8565 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
8568 static void update_from_network(struct connman_service *service,
8569 struct connman_network *network)
8571 uint8_t strength = service->strength;
8574 DBG("service %p network %p", service, network);
8576 if (is_connected(service))
8579 if (is_connecting(service))
8582 str = connman_network_get_string(network, "Name");
8584 g_free(service->name);
8585 service->name = g_strdup(str);
8586 service->hidden = false;
8588 g_free(service->name);
8589 service->name = NULL;
8590 service->hidden = true;
8593 service->strength = connman_network_get_strength(network);
8594 service->roaming = connman_network_get_bool(network, "Roaming");
8596 if (service->strength == 0) {
8598 * Filter out 0-values; it's unclear what they mean
8599 * and they cause anomalous sorting of the priority list.
8601 service->strength = strength;
8604 str = connman_network_get_string(network, "WiFi.Security");
8605 service->security = convert_wifi_security(str);
8607 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
8608 service->wps = connman_network_get_bool(network, "WiFi.WPS");
8610 if (service->strength > strength && service->network) {
8611 connman_network_unref(service->network);
8612 service->network = connman_network_ref(network);
8614 strength_changed(service);
8617 if (!service->network)
8618 service->network = connman_network_ref(network);
8620 service_list_sort();
8624 * __connman_service_create_from_network:
8625 * @network: network structure
8627 * Look up service by network and if not found, create one
8629 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
8631 struct connman_service *service;
8632 struct connman_device *device;
8633 const char *ident, *group;
8635 unsigned int *auto_connect_types;
8638 DBG("network %p", network);
8643 ident = __connman_network_get_ident(network);
8647 group = connman_network_get_group(network);
8651 name = g_strdup_printf("%s_%s_%s",
8652 __connman_network_get_type(network), ident, group);
8653 service = service_get(name);
8659 if (__connman_network_get_weakness(network))
8662 if (service->path) {
8663 update_from_network(service, network);
8664 __connman_connection_update_gateway();
8668 service->type = convert_network_type(network);
8670 auto_connect_types = connman_setting_get_uint_list("DefaultAutoConnectTechnologies");
8671 service->autoconnect = false;
8672 for (i = 0; auto_connect_types &&
8673 auto_connect_types[i] != 0; i++) {
8674 if (service->type == auto_connect_types[i]) {
8675 service->autoconnect = true;
8680 switch (service->type) {
8681 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8682 case CONNMAN_SERVICE_TYPE_SYSTEM:
8683 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8684 case CONNMAN_SERVICE_TYPE_GPS:
8685 case CONNMAN_SERVICE_TYPE_VPN:
8686 case CONNMAN_SERVICE_TYPE_GADGET:
8687 case CONNMAN_SERVICE_TYPE_WIFI:
8688 case CONNMAN_SERVICE_TYPE_CELLULAR:
8689 case CONNMAN_SERVICE_TYPE_P2P:
8691 case CONNMAN_SERVICE_TYPE_ETHERNET:
8692 service->favorite = true;
8696 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
8697 service->state = combine_state(service->state_ipv4, service->state_ipv6);
8699 update_from_network(service, network);
8701 index = connman_network_get_index(network);
8703 if (!service->ipconfig_ipv4)
8704 service->ipconfig_ipv4 = create_ip4config(service, index,
8705 CONNMAN_IPCONFIG_METHOD_DHCP);
8707 if (!service->ipconfig_ipv6)
8708 service->ipconfig_ipv6 = create_ip6config(service, index);
8710 service_register(service);
8712 if (service->favorite) {
8713 device = connman_network_get_device(service->network);
8714 if (device && !connman_device_get_scanning(device)) {
8716 switch (service->type) {
8717 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8718 case CONNMAN_SERVICE_TYPE_SYSTEM:
8719 case CONNMAN_SERVICE_TYPE_P2P:
8722 case CONNMAN_SERVICE_TYPE_GADGET:
8723 case CONNMAN_SERVICE_TYPE_ETHERNET:
8724 if (service->autoconnect) {
8725 __connman_service_connect(service,
8726 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
8731 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8732 case CONNMAN_SERVICE_TYPE_GPS:
8733 case CONNMAN_SERVICE_TYPE_VPN:
8734 case CONNMAN_SERVICE_TYPE_WIFI:
8735 case CONNMAN_SERVICE_TYPE_CELLULAR:
8736 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
8741 #if defined TIZEN_EXT
8742 /* TIZEN synchronizes below information when the service creates */
8743 if (service->eap != NULL)
8744 connman_network_set_string(service->network, "WiFi.EAP",
8746 if (service->identity != NULL)
8747 connman_network_set_string(service->network, "WiFi.Identity",
8749 if (service->phase2 != NULL)
8750 connman_network_set_string(service->network, "WiFi.Phase2",
8755 __connman_notifier_service_add(service, service->name);
8756 service_schedule_added(service);
8761 void __connman_service_update_from_network(struct connman_network *network)
8763 bool need_sort = false;
8764 struct connman_service *service;
8770 service = connman_service_lookup_from_network(network);
8774 if (!service->network)
8777 #if defined TIZEN_EXT
8778 if (service->storage_reload) {
8779 service_load(service);
8780 __connman_service_set_storage_reload(service, false);
8784 name = connman_network_get_string(service->network, "Name");
8785 if (g_strcmp0(service->name, name) != 0) {
8786 g_free(service->name);
8787 service->name = g_strdup(name);
8789 if (allow_property_changed(service))
8790 connman_dbus_property_changed_basic(service->path,
8791 CONNMAN_SERVICE_INTERFACE, "Name",
8792 DBUS_TYPE_STRING, &service->name);
8795 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
8796 service->wps = connman_network_get_bool(network, "WiFi.WPS");
8798 strength = connman_network_get_strength(service->network);
8799 if (strength == service->strength)
8802 service->strength = strength;
8805 strength_changed(service);
8808 roaming = connman_network_get_bool(service->network, "Roaming");
8809 if (roaming == service->roaming)
8812 stats_enable = stats_enabled(service);
8814 stats_stop(service);
8816 service->roaming = roaming;
8820 stats_start(service);
8822 roaming_changed(service);
8826 service_list_sort();
8830 void __connman_service_remove_from_network(struct connman_network *network)
8832 struct connman_service *service;
8834 service = connman_service_lookup_from_network(network);
8836 DBG("network %p service %p", network, service);
8841 service->ignore = true;
8843 __connman_connection_gateway_remove(service,
8844 CONNMAN_IPCONFIG_TYPE_ALL);
8846 connman_service_unref(service);
8850 * __connman_service_create_from_provider:
8851 * @provider: provider structure
8853 * Look up service by provider and if not found, create one
8855 struct connman_service *
8856 __connman_service_create_from_provider(struct connman_provider *provider)
8858 struct connman_service *service;
8859 const char *ident, *str;
8861 int index = connman_provider_get_index(provider);
8863 DBG("provider %p", provider);
8865 ident = __connman_provider_get_ident(provider);
8869 name = g_strdup_printf("vpn_%s", ident);
8870 service = service_get(name);
8876 service->type = CONNMAN_SERVICE_TYPE_VPN;
8877 service->provider = connman_provider_ref(provider);
8878 service->autoconnect = false;
8879 service->favorite = true;
8881 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
8882 service->state = combine_state(service->state_ipv4, service->state_ipv6);
8884 str = connman_provider_get_string(provider, "Name");
8886 g_free(service->name);
8887 service->name = g_strdup(str);
8888 service->hidden = false;
8890 g_free(service->name);
8891 service->name = NULL;
8892 service->hidden = true;
8895 service->strength = 0;
8897 if (!service->ipconfig_ipv4)
8898 service->ipconfig_ipv4 = create_ip4config(service, index,
8899 CONNMAN_IPCONFIG_METHOD_MANUAL);
8901 if (!service->ipconfig_ipv6)
8902 service->ipconfig_ipv6 = create_ip6config(service, index);
8904 service_register(service);
8906 __connman_notifier_service_add(service, service->name);
8907 service_schedule_added(service);
8912 static void remove_unprovisioned_services(void)
8915 GKeyFile *keyfile, *configkeyfile;
8916 char *file, *section;
8919 services = connman_storage_get_services();
8923 for (; services[i]; i++) {
8924 file = section = NULL;
8925 keyfile = configkeyfile = NULL;
8927 keyfile = connman_storage_load_service(services[i]);
8931 file = g_key_file_get_string(keyfile, services[i],
8932 "Config.file", NULL);
8936 section = g_key_file_get_string(keyfile, services[i],
8937 "Config.ident", NULL);
8941 configkeyfile = __connman_storage_load_config(file);
8942 if (!configkeyfile) {
8944 * Config file is missing, remove the provisioned
8947 __connman_storage_remove_service(services[i]);
8951 if (!g_key_file_has_group(configkeyfile, section))
8953 * Config section is missing, remove the provisioned
8956 __connman_storage_remove_service(services[i]);
8960 g_key_file_free(keyfile);
8963 g_key_file_free(configkeyfile);
8969 g_strfreev(services);
8972 static int agent_probe(struct connman_agent *agent)
8974 DBG("agent %p", agent);
8978 static void agent_remove(struct connman_agent *agent)
8980 DBG("agent %p", agent);
8983 static void *agent_context_ref(void *context)
8985 struct connman_service *service = context;
8987 return (void *)connman_service_ref(service);
8990 static void agent_context_unref(void *context)
8992 struct connman_service *service = context;
8994 connman_service_unref(service);
8997 static struct connman_agent_driver agent_driver = {
8999 .interface = CONNMAN_AGENT_INTERFACE,
9000 .probe = agent_probe,
9001 .remove = agent_remove,
9002 .context_ref = agent_context_ref,
9003 .context_unref = agent_context_unref,
9006 int __connman_service_init(void)
9012 err = connman_agent_driver_register(&agent_driver);
9014 connman_error("Cannot register agent driver for %s",
9019 connection = connman_dbus_get_connection();
9021 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
9022 NULL, service_free);
9024 services_notify = g_new0(struct _services_notify, 1);
9025 services_notify->remove = g_hash_table_new_full(g_str_hash,
9026 g_str_equal, g_free, NULL);
9027 services_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
9029 remove_unprovisioned_services();
9034 void __connman_service_cleanup(void)
9038 if (vpn_autoconnect_timeout) {
9039 g_source_remove(vpn_autoconnect_timeout);
9040 vpn_autoconnect_timeout = 0;
9043 if (autoconnect_timeout != 0) {
9044 g_source_remove(autoconnect_timeout);
9045 autoconnect_timeout = 0;
9048 connman_agent_driver_unregister(&agent_driver);
9050 g_list_free(service_list);
9051 service_list = NULL;
9053 g_hash_table_destroy(service_hash);
9054 service_hash = NULL;
9056 g_slist_free(counter_list);
9057 counter_list = NULL;
9059 if (services_notify->id != 0) {
9060 g_source_remove(services_notify->id);
9061 service_send_changed(NULL);
9062 g_hash_table_destroy(services_notify->remove);
9063 g_hash_table_destroy(services_notify->add);
9065 g_free(services_notify);
9067 dbus_connection_unref(connection);