5 * Copyright (C) 2007-2014 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 #include <connman/storage.h>
37 #include <connman/setting.h>
38 #include <connman/agent.h>
42 #define CONNECT_TIMEOUT 120
45 #define USER_NONE (uid_t)-1
48 #define WIFI_BSSID_STR_LEN 18
51 static DBusConnection *connection = NULL;
53 static GList *service_list = NULL;
54 static GHashTable *service_hash = NULL;
55 static GSList *counter_list = NULL;
56 static unsigned int autoconnect_timeout = 0;
57 static unsigned int vpn_autoconnect_timeout = 0;
58 static struct connman_service *current_default = NULL;
59 static bool services_dirty = false;
61 struct connman_stats {
64 struct connman_stats_data data_last;
65 struct connman_stats_data data;
69 struct connman_stats_counter {
71 struct connman_stats stats;
72 struct connman_stats stats_roaming;
75 struct connman_service_user {
80 #if defined TIZEN_TV_EXT
81 enum connman_dnsconfig_method {
82 CONNMAN_DNSCONFIG_METHOD_UNKNOWN = 0,
83 CONNMAN_DNSCONFIG_METHOD_MANUAL = 1,
84 CONNMAN_DNSCONFIG_METHOD_DHCP = 2,
88 struct connman_service {
92 enum connman_service_type type;
93 enum connman_service_security security;
94 enum connman_service_state state;
95 enum connman_service_state state_ipv4;
96 enum connman_service_state state_ipv6;
97 enum connman_service_error error;
98 enum connman_service_connect_reason connect_reason;
110 bool request_passphrase_input;
111 struct connman_service_user user;
112 struct connman_ipconfig *ipconfig_ipv4;
113 struct connman_ipconfig *ipconfig_ipv6;
114 struct connman_network *network;
115 struct connman_provider *provider;
117 char **nameservers_config;
118 char **nameservers_auto;
123 char **timeservers_config;
124 /* 802.1x settings from the config files */
127 char *agent_identity;
129 char *client_cert_file;
130 char *private_key_file;
131 char *private_key_passphrase;
133 DBusMessage *pending;
134 DBusMessage *provider_pending;
136 struct connman_stats stats;
137 struct connman_stats stats_roaming;
138 GHashTable *counter_table;
139 enum connman_service_proxy_method proxy;
140 enum connman_service_proxy_method proxy_config;
145 int online_check_count;
146 bool do_split_routing;
151 #if defined TIZEN_EXT
153 * Description: TIZEN implements system global connection management.
154 * It's only for PDP (cellular) bearer. Wi-Fi is managed
155 * by ConnMan automatically. Reference count can help to
156 * manage open/close connection requests by each application.
158 int user_pdn_connection_refcount;
161 * Description: In case of EAP security type,
162 * user can select the keymgmt type for roaming(802.11r).
163 * - FT, CCKM, OKC, ...
166 int disconnect_reason;
168 #if defined TIZEN_TV_EXT
169 enum connman_dnsconfig_method dns_config_method;
173 static bool allow_property_changed(struct connman_service *service);
175 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
176 int index, enum connman_ipconfig_method method);
177 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
183 struct connman_service *service;
186 #if defined TIZEN_EXT
188 * Public APIs to use user_pdn_connection_refcount
190 void connman_service_user_pdn_connection_ref(struct connman_service *service)
192 __sync_fetch_and_add(&service->user_pdn_connection_refcount, 1);
194 DBG("User made PDN connection referenced: %d",
195 service->user_pdn_connection_refcount);
198 gboolean connman_service_user_pdn_connection_unref_and_test(
199 struct connman_service *service)
201 __sync_synchronize();
203 DBG("User made PDN connection referenced: %d, which will be decreased",
204 service->user_pdn_connection_refcount);
206 if (service->user_pdn_connection_refcount < 1)
209 if (__sync_sub_and_fetch(&service->user_pdn_connection_refcount, 1) == 0)
215 gboolean connman_service_is_no_ref_user_pdn_connection(
216 struct connman_service *cellular)
218 if (cellular == NULL)
221 __sync_synchronize();
222 if (cellular->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
223 cellular->user_pdn_connection_refcount == 0)
230 static void compare_path(gpointer value, gpointer user_data)
232 struct connman_service *service = value;
233 struct find_data *data = user_data;
238 if (g_strcmp0(service->path, data->path) == 0)
239 data->service = service;
242 static struct connman_service *find_service(const char *path)
244 struct find_data data = { .path = path, .service = NULL };
246 DBG("path %s", path);
248 g_list_foreach(service_list, compare_path, &data);
253 static const char *reason2string(enum connman_service_connect_reason reason)
257 case CONNMAN_SERVICE_CONNECT_REASON_NONE:
259 case CONNMAN_SERVICE_CONNECT_REASON_USER:
261 case CONNMAN_SERVICE_CONNECT_REASON_AUTO:
263 case CONNMAN_SERVICE_CONNECT_REASON_SESSION:
270 const char *__connman_service_type2string(enum connman_service_type type)
273 case CONNMAN_SERVICE_TYPE_UNKNOWN:
275 case CONNMAN_SERVICE_TYPE_SYSTEM:
277 case CONNMAN_SERVICE_TYPE_ETHERNET:
279 case CONNMAN_SERVICE_TYPE_WIFI:
281 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
283 case CONNMAN_SERVICE_TYPE_CELLULAR:
285 case CONNMAN_SERVICE_TYPE_GPS:
287 case CONNMAN_SERVICE_TYPE_VPN:
289 case CONNMAN_SERVICE_TYPE_GADGET:
291 case CONNMAN_SERVICE_TYPE_P2P:
298 enum connman_service_type __connman_service_string2type(const char *str)
301 return CONNMAN_SERVICE_TYPE_UNKNOWN;
303 if (strcmp(str, "ethernet") == 0)
304 return CONNMAN_SERVICE_TYPE_ETHERNET;
305 if (strcmp(str, "gadget") == 0)
306 return CONNMAN_SERVICE_TYPE_GADGET;
307 if (strcmp(str, "wifi") == 0)
308 return CONNMAN_SERVICE_TYPE_WIFI;
309 if (strcmp(str, "cellular") == 0)
310 return CONNMAN_SERVICE_TYPE_CELLULAR;
311 if (strcmp(str, "bluetooth") == 0)
312 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
313 if (strcmp(str, "vpn") == 0)
314 return CONNMAN_SERVICE_TYPE_VPN;
315 if (strcmp(str, "gps") == 0)
316 return CONNMAN_SERVICE_TYPE_GPS;
317 if (strcmp(str, "system") == 0)
318 return CONNMAN_SERVICE_TYPE_SYSTEM;
319 if (strcmp(str, "p2p") == 0)
320 return CONNMAN_SERVICE_TYPE_P2P;
322 return CONNMAN_SERVICE_TYPE_UNKNOWN;
325 enum connman_service_security __connman_service_string2security(const char *str)
328 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
330 if (!strcmp(str, "psk"))
331 return CONNMAN_SERVICE_SECURITY_PSK;
332 if (!strcmp(str, "ieee8021x"))
333 return CONNMAN_SERVICE_SECURITY_8021X;
334 if (!strcmp(str, "none"))
335 return CONNMAN_SERVICE_SECURITY_NONE;
336 if (!strcmp(str, "wep"))
337 return CONNMAN_SERVICE_SECURITY_WEP;
338 #if defined TIZEN_EXT
339 if (!strcmp(str, "rsn"))
340 return CONNMAN_SERVICE_SECURITY_RSN;
343 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
346 static const char *security2string(enum connman_service_security security)
349 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
351 case CONNMAN_SERVICE_SECURITY_NONE:
353 case CONNMAN_SERVICE_SECURITY_WEP:
355 case CONNMAN_SERVICE_SECURITY_PSK:
356 case CONNMAN_SERVICE_SECURITY_WPA:
357 #if defined TIZEN_EXT
359 case CONNMAN_SERVICE_SECURITY_RSN:
362 case CONNMAN_SERVICE_SECURITY_RSN:
365 case CONNMAN_SERVICE_SECURITY_8021X:
372 static const char *state2string(enum connman_service_state state)
375 case CONNMAN_SERVICE_STATE_UNKNOWN:
377 case CONNMAN_SERVICE_STATE_IDLE:
379 case CONNMAN_SERVICE_STATE_ASSOCIATION:
380 return "association";
381 case CONNMAN_SERVICE_STATE_CONFIGURATION:
382 return "configuration";
383 case CONNMAN_SERVICE_STATE_READY:
385 case CONNMAN_SERVICE_STATE_ONLINE:
387 case CONNMAN_SERVICE_STATE_DISCONNECT:
389 case CONNMAN_SERVICE_STATE_FAILURE:
396 static const char *error2string(enum connman_service_error error)
399 case CONNMAN_SERVICE_ERROR_UNKNOWN:
401 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
402 return "out-of-range";
403 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
404 return "pin-missing";
405 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
406 return "dhcp-failed";
407 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
408 return "connect-failed";
409 case CONNMAN_SERVICE_ERROR_LOGIN_FAILED:
410 return "login-failed";
411 case CONNMAN_SERVICE_ERROR_AUTH_FAILED:
412 return "auth-failed";
413 case CONNMAN_SERVICE_ERROR_INVALID_KEY:
414 return "invalid-key";
420 static const char *proxymethod2string(enum connman_service_proxy_method method)
423 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
425 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
427 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
429 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
436 static enum connman_service_proxy_method string2proxymethod(const char *method)
438 if (g_strcmp0(method, "direct") == 0)
439 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
440 else if (g_strcmp0(method, "auto") == 0)
441 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
442 else if (g_strcmp0(method, "manual") == 0)
443 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
445 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
448 #if defined TIZEN_TV_EXT
449 static const char *__connman_dnsconfig_method2string(enum connman_dnsconfig_method method)
452 case CONNMAN_DNSCONFIG_METHOD_UNKNOWN:
454 case CONNMAN_DNSCONFIG_METHOD_MANUAL:
456 case CONNMAN_DNSCONFIG_METHOD_DHCP:
463 static enum connman_dnsconfig_method __connman_dnsconfig_string2method(
466 if (g_strcmp0(method, "manual") == 0)
467 return CONNMAN_DNSCONFIG_METHOD_MANUAL;
468 else if (g_strcmp0(method, "dhcp") == 0)
469 return CONNMAN_DNSCONFIG_METHOD_DHCP;
471 return CONNMAN_DNSCONFIG_METHOD_UNKNOWN;
476 connman_service_is_user_allowed(struct connman_service *service, uid_t uid)
478 uid_t favorite_user = service->user.favorite_user;
479 uid_t current_user = uid;
481 DBG("Service favorite UID: %d, current UID: %d", favorite_user, current_user);
482 if (favorite_user == USER_NONE || current_user == USER_ROOT)
485 if (favorite_user != current_user || current_user == USER_NONE) {
486 DBG("Current user is not a favorite user to this service!");
493 #if !defined TIZEN_EXT
494 static GList *connman_service_get_login_users()
498 GList *user_list = NULL;
502 while ((utmp = getutxent()) != NULL) {
503 DBG("User Name: %s", utmp->ut_user);
505 pwd = getpwnam(utmp->ut_user);
507 if (!g_list_find(user_list, GUINT_TO_POINTER(pwd->pw_uid)))
508 user_list = g_list_append(user_list,
509 GUINT_TO_POINTER(pwd->pw_uid));
511 DBG("User Name: %s, UID: %d", utmp->ut_user, pwd->pw_uid);
521 static bool is_service_owner_user_login(struct connman_service *service)
523 #if defined TIZEN_EXT
526 GList *list, *user_list;
529 /* Here we only care about wifi service */
530 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
533 DBG("service favorite user id is: %d", service->user.favorite_user);
535 user_list = connman_service_get_login_users();
536 if (user_list == NULL) {
537 DBG("Can not get any logged in user info.");
541 for (list = user_list; list; list = list->next) {
542 uid_t uid = GPOINTER_TO_UINT(list->data);
544 DBG("login user id is %d", uid);
546 if (service->user.favorite_user == uid) {
552 g_list_free(user_list);
558 int __connman_service_load_modifiable(struct connman_service *service)
561 GError *error = NULL;
565 DBG("service %p", service);
567 keyfile = connman_storage_load_service(service->identifier);
571 switch (service->type) {
572 case CONNMAN_SERVICE_TYPE_UNKNOWN:
573 case CONNMAN_SERVICE_TYPE_SYSTEM:
574 case CONNMAN_SERVICE_TYPE_GPS:
575 case CONNMAN_SERVICE_TYPE_P2P:
577 case CONNMAN_SERVICE_TYPE_VPN:
578 service->do_split_routing = g_key_file_get_boolean(keyfile,
579 service->identifier, "SplitRouting", NULL);
581 case CONNMAN_SERVICE_TYPE_WIFI:
582 case CONNMAN_SERVICE_TYPE_GADGET:
583 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
584 case CONNMAN_SERVICE_TYPE_CELLULAR:
585 case CONNMAN_SERVICE_TYPE_ETHERNET:
586 autoconnect = g_key_file_get_boolean(keyfile,
587 service->identifier, "AutoConnect", &error);
589 service->autoconnect = autoconnect;
590 g_clear_error(&error);
594 str = g_key_file_get_string(keyfile,
595 service->identifier, "Modified", NULL);
597 g_time_val_from_iso8601(str, &service->modified);
601 g_key_file_free(keyfile);
606 static int service_load_passphrase(struct connman_service *service)
611 keyfile = connman_storage_load_service(service->identifier);
615 str = g_key_file_get_string(keyfile,
616 service->identifier, "Passphrase", NULL);
618 service->passphrase = str;
623 static int service_load(struct connman_service *service)
626 GError *error = NULL;
630 unsigned int ssid_len;
633 DBG("service %p", service);
635 keyfile = connman_storage_load_service(service->identifier);
637 service->new_service = true;
640 service->new_service = false;
642 switch (service->type) {
643 case CONNMAN_SERVICE_TYPE_UNKNOWN:
644 case CONNMAN_SERVICE_TYPE_SYSTEM:
645 case CONNMAN_SERVICE_TYPE_GPS:
646 case CONNMAN_SERVICE_TYPE_P2P:
648 case CONNMAN_SERVICE_TYPE_VPN:
649 service->do_split_routing = g_key_file_get_boolean(keyfile,
650 service->identifier, "SplitRouting", NULL);
651 autoconnect = g_key_file_get_boolean(keyfile,
652 service->identifier, "AutoConnect", &error);
654 service->autoconnect = autoconnect;
655 g_clear_error(&error);
657 case CONNMAN_SERVICE_TYPE_WIFI:
658 if (!service->name) {
661 name = g_key_file_get_string(keyfile,
662 service->identifier, "Name", NULL);
664 g_free(service->name);
665 service->name = name;
668 if (service->network)
669 connman_network_set_name(service->network,
673 if (service->network &&
674 !connman_network_get_blob(service->network,
675 "WiFi.SSID", &ssid_len)) {
678 hex_ssid = g_key_file_get_string(keyfile,
684 unsigned int i, j = 0, hex;
685 size_t hex_ssid_len = strlen(hex_ssid);
687 ssid = g_try_malloc0(hex_ssid_len / 2);
694 for (i = 0; i < hex_ssid_len; i += 2) {
695 sscanf(hex_ssid + i, "%02x", &hex);
699 connman_network_set_blob(service->network,
700 "WiFi.SSID", ssid, hex_ssid_len / 2);
709 case CONNMAN_SERVICE_TYPE_GADGET:
710 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
711 case CONNMAN_SERVICE_TYPE_CELLULAR:
712 service->favorite = g_key_file_get_boolean(keyfile,
713 service->identifier, "Favorite", NULL);
717 case CONNMAN_SERVICE_TYPE_ETHERNET:
718 autoconnect = g_key_file_get_boolean(keyfile,
719 service->identifier, "AutoConnect", &error);
721 service->autoconnect = autoconnect;
722 g_clear_error(&error);
726 str = g_key_file_get_string(keyfile,
727 service->identifier, "Modified", NULL);
729 g_time_val_from_iso8601(str, &service->modified);
733 str = g_key_file_get_string(keyfile,
734 service->identifier, "Passphrase", NULL);
736 g_free(service->passphrase);
737 service->passphrase = str;
740 if (service->ipconfig_ipv4)
741 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
742 service->identifier, "IPv4.");
744 if (service->ipconfig_ipv6)
745 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
746 service->identifier, "IPv6.");
748 service->nameservers_config = g_key_file_get_string_list(keyfile,
749 service->identifier, "Nameservers", &length, NULL);
750 if (service->nameservers_config && length == 0) {
751 g_strfreev(service->nameservers_config);
752 service->nameservers_config = NULL;
755 #if defined TIZEN_TV_EXT
757 dns_method = g_key_file_get_string(keyfile, service->identifier,
758 "Nameservers.method", NULL);
759 service->dns_config_method = __connman_dnsconfig_string2method(dns_method);
762 service->timeservers_config = g_key_file_get_string_list(keyfile,
763 service->identifier, "Timeservers", &length, NULL);
764 if (service->timeservers_config && length == 0) {
765 g_strfreev(service->timeservers_config);
766 service->timeservers_config = NULL;
769 service->domains = g_key_file_get_string_list(keyfile,
770 service->identifier, "Domains", &length, NULL);
771 if (service->domains && length == 0) {
772 g_strfreev(service->domains);
773 service->domains = NULL;
776 str = g_key_file_get_string(keyfile,
777 service->identifier, "Proxy.Method", NULL);
779 service->proxy_config = string2proxymethod(str);
783 service->proxies = g_key_file_get_string_list(keyfile,
784 service->identifier, "Proxy.Servers", &length, NULL);
785 if (service->proxies && length == 0) {
786 g_strfreev(service->proxies);
787 service->proxies = NULL;
790 service->excludes = g_key_file_get_string_list(keyfile,
791 service->identifier, "Proxy.Excludes", &length, NULL);
792 if (service->excludes && length == 0) {
793 g_strfreev(service->excludes);
794 service->excludes = NULL;
797 str = g_key_file_get_string(keyfile,
798 service->identifier, "Proxy.URL", NULL);
800 g_free(service->pac);
804 service->hidden_service = g_key_file_get_boolean(keyfile,
805 service->identifier, "Hidden", NULL);
807 #if defined TIZEN_EXT
808 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
809 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
810 str = g_key_file_get_string(keyfile,
811 service->identifier, "EAP", NULL);
813 g_free(service->eap);
817 str = g_key_file_get_string(keyfile,
818 service->identifier, "Phase2", NULL);
820 g_free(service->phase2);
821 service->phase2 = str;
824 str = g_key_file_get_string(keyfile,
825 service->identifier, "Identity", NULL);
827 g_free(service->identity);
828 service->identity = str;
831 str = g_key_file_get_string(keyfile,
832 service->identifier, "CACertFile", NULL);
834 g_free(service->ca_cert_file);
835 service->ca_cert_file = str;
838 str = g_key_file_get_string(keyfile,
839 service->identifier, "ClientCertFile", NULL);
841 g_free(service->client_cert_file);
842 service->client_cert_file = str;
845 str = g_key_file_get_string(keyfile,
846 service->identifier, "PrivateKeyFile", NULL);
848 g_free(service->private_key_file);
849 service->private_key_file = str;
852 str = g_key_file_get_string(keyfile,
853 service->identifier, "PrivateKeyPassphrase", NULL);
855 g_free(service->private_key_passphrase);
856 service->private_key_passphrase = str;
861 if (g_key_file_has_key(keyfile, service->identifier, "UID", NULL))
862 service->user.favorite_user = g_key_file_get_integer(keyfile,
863 service->identifier, "UID", NULL);
865 g_key_file_free(keyfile);
870 static int service_save(struct connman_service *service)
875 const char *cst_str = NULL;
878 DBG("service %p new %d", service, service->new_service);
880 if (service->new_service)
883 keyfile = __connman_storage_open_service(service->identifier);
888 g_key_file_set_string(keyfile, service->identifier,
889 "Name", service->name);
891 switch (service->type) {
892 case CONNMAN_SERVICE_TYPE_UNKNOWN:
893 case CONNMAN_SERVICE_TYPE_SYSTEM:
894 case CONNMAN_SERVICE_TYPE_GPS:
895 case CONNMAN_SERVICE_TYPE_P2P:
897 case CONNMAN_SERVICE_TYPE_VPN:
898 g_key_file_set_boolean(keyfile, service->identifier,
899 "SplitRouting", service->do_split_routing);
900 if (service->favorite)
901 g_key_file_set_boolean(keyfile, service->identifier,
902 "AutoConnect", service->autoconnect);
904 case CONNMAN_SERVICE_TYPE_WIFI:
905 if (service->network) {
906 const unsigned char *ssid;
907 unsigned int ssid_len = 0;
909 if (service->user.favorite_user == USER_NONE)
910 g_key_file_remove_key(keyfile, service->identifier,
913 g_key_file_set_integer(keyfile, service->identifier,
914 "UID", service->user.favorite_user);
916 ssid = connman_network_get_blob(service->network,
917 "WiFi.SSID", &ssid_len);
919 if (ssid && ssid_len > 0 && ssid[0] != '\0') {
920 char *identifier = service->identifier;
924 ssid_str = g_string_sized_new(ssid_len * 2);
930 for (i = 0; i < ssid_len; i++)
931 g_string_append_printf(ssid_str,
934 g_key_file_set_string(keyfile, identifier,
935 "SSID", ssid_str->str);
937 g_string_free(ssid_str, TRUE);
940 freq = connman_network_get_frequency(service->network);
941 g_key_file_set_integer(keyfile, service->identifier,
946 case CONNMAN_SERVICE_TYPE_GADGET:
947 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
948 case CONNMAN_SERVICE_TYPE_CELLULAR:
949 g_key_file_set_boolean(keyfile, service->identifier,
950 "Favorite", service->favorite);
952 g_key_file_remove_key(keyfile, service->identifier,
957 case CONNMAN_SERVICE_TYPE_ETHERNET:
958 if (service->favorite)
959 g_key_file_set_boolean(keyfile, service->identifier,
960 "AutoConnect", service->autoconnect);
964 str = g_time_val_to_iso8601(&service->modified);
966 g_key_file_set_string(keyfile, service->identifier,
971 if (service->user.current_user == service->user.favorite_user) {
972 if (service->passphrase && strlen(service->passphrase) > 0)
973 g_key_file_set_string(keyfile, service->identifier,
974 "Passphrase", service->passphrase);
976 g_key_file_remove_key(keyfile, service->identifier,
980 if (service->ipconfig_ipv4)
981 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
982 service->identifier, "IPv4.");
984 if (service->ipconfig_ipv6)
985 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
986 service->identifier, "IPv6.");
988 if (service->nameservers_config) {
989 guint len = g_strv_length(service->nameservers_config);
991 g_key_file_set_string_list(keyfile, service->identifier,
993 (const gchar **) service->nameservers_config, len);
995 g_key_file_remove_key(keyfile, service->identifier,
996 "Nameservers", NULL);
998 #if defined TIZEN_TV_EXT
999 if(service->dns_config_method != 0) {
1001 method = __connman_dnsconfig_method2string(
1002 service->dns_config_method);
1003 g_key_file_set_string(keyfile, service->identifier,
1004 "Nameservers.method", method);
1006 g_key_file_remove_key(keyfile, service->identifier,
1007 "Nameservers.method", NULL);
1010 if (service->timeservers_config) {
1011 guint len = g_strv_length(service->timeservers_config);
1013 g_key_file_set_string_list(keyfile, service->identifier,
1015 (const gchar **) service->timeservers_config, len);
1017 g_key_file_remove_key(keyfile, service->identifier,
1018 "Timeservers", NULL);
1020 if (service->domains) {
1021 guint len = g_strv_length(service->domains);
1023 g_key_file_set_string_list(keyfile, service->identifier,
1025 (const gchar **) service->domains, len);
1027 g_key_file_remove_key(keyfile, service->identifier,
1030 cst_str = proxymethod2string(service->proxy_config);
1032 g_key_file_set_string(keyfile, service->identifier,
1033 "Proxy.Method", cst_str);
1035 if (service->proxies) {
1036 guint len = g_strv_length(service->proxies);
1038 g_key_file_set_string_list(keyfile, service->identifier,
1040 (const gchar **) service->proxies, len);
1042 g_key_file_remove_key(keyfile, service->identifier,
1043 "Proxy.Servers", NULL);
1045 if (service->excludes) {
1046 guint len = g_strv_length(service->excludes);
1048 g_key_file_set_string_list(keyfile, service->identifier,
1050 (const gchar **) service->excludes, len);
1052 g_key_file_remove_key(keyfile, service->identifier,
1053 "Proxy.Excludes", NULL);
1055 if (service->pac && strlen(service->pac) > 0)
1056 g_key_file_set_string(keyfile, service->identifier,
1057 "Proxy.URL", service->pac);
1059 g_key_file_remove_key(keyfile, service->identifier,
1062 if (service->hidden_service)
1063 g_key_file_set_boolean(keyfile, service->identifier, "Hidden",
1066 if (service->config_file && strlen(service->config_file) > 0)
1067 g_key_file_set_string(keyfile, service->identifier,
1068 "Config.file", service->config_file);
1070 if (service->config_entry &&
1071 strlen(service->config_entry) > 0)
1072 g_key_file_set_string(keyfile, service->identifier,
1073 "Config.ident", service->config_entry);
1075 #if defined TIZEN_EXT
1076 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1077 service->security == CONNMAN_SERVICE_SECURITY_8021X) {
1078 if (service->eap != NULL && strlen(service->eap) > 0)
1079 g_key_file_set_string(keyfile, service->identifier,
1080 "EAP", service->eap);
1082 g_key_file_remove_key(keyfile, service->identifier,
1085 if (service->phase2 != NULL && strlen(service->phase2) > 0)
1086 g_key_file_set_string(keyfile, service->identifier,
1087 "Phase2", service->phase2);
1089 g_key_file_remove_key(keyfile, service->identifier,
1092 if (service->identity != NULL && strlen(service->identity) > 0)
1093 g_key_file_set_string(keyfile, service->identifier,
1094 "Identity", service->identity);
1096 g_key_file_remove_key(keyfile, service->identifier,
1099 if (service->ca_cert_file != NULL && strlen(service->ca_cert_file) > 0)
1100 g_key_file_set_string(keyfile, service->identifier,
1101 "CACertFile", service->ca_cert_file);
1103 g_key_file_remove_key(keyfile, service->identifier,
1104 "CACertFile", NULL);
1106 if (service->client_cert_file != NULL && strlen(service->client_cert_file) > 0)
1107 g_key_file_set_string(keyfile, service->identifier,
1108 "ClientCertFile", service->client_cert_file);
1110 g_key_file_remove_key(keyfile, service->identifier,
1111 "ClientCertFile", NULL);
1113 if (service->private_key_file != NULL && strlen(service->private_key_file) > 0)
1114 g_key_file_set_string(keyfile, service->identifier,
1115 "PrivateKeyFile", service->private_key_file);
1117 g_key_file_remove_key(keyfile, service->identifier,
1118 "PrivateKeyFile", NULL);
1120 if (service->private_key_passphrase != NULL && strlen(service->private_key_passphrase) > 0)
1121 g_key_file_set_string(keyfile, service->identifier,
1122 "PrivateKeyPassphrase", service->private_key_passphrase);
1124 g_key_file_remove_key(keyfile, service->identifier,
1125 "PrivateKeyPassphrase", NULL);
1130 __connman_storage_save_service(keyfile, service->identifier);
1132 g_key_file_free(keyfile);
1137 void __connman_service_save(struct connman_service *service)
1142 service_save(service);
1145 static enum connman_service_state combine_state(
1146 enum connman_service_state state_a,
1147 enum connman_service_state state_b)
1149 enum connman_service_state result;
1151 if (state_a == state_b) {
1156 if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
1161 if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
1166 if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
1171 if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
1176 if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
1181 if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
1186 if (state_a == CONNMAN_SERVICE_STATE_READY) {
1191 if (state_b == CONNMAN_SERVICE_STATE_READY) {
1196 if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1201 if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
1206 if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1211 if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
1216 if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
1221 if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
1226 result = CONNMAN_SERVICE_STATE_FAILURE;
1232 static bool is_connecting_state(struct connman_service *service,
1233 enum connman_service_state state)
1236 case CONNMAN_SERVICE_STATE_UNKNOWN:
1237 case CONNMAN_SERVICE_STATE_IDLE:
1238 case CONNMAN_SERVICE_STATE_FAILURE:
1239 if (service->network)
1240 return connman_network_get_connecting(service->network);
1241 case CONNMAN_SERVICE_STATE_DISCONNECT:
1242 case CONNMAN_SERVICE_STATE_READY:
1243 case CONNMAN_SERVICE_STATE_ONLINE:
1245 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1246 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1253 static bool is_connected_state(const struct connman_service *service,
1254 enum connman_service_state state)
1257 case CONNMAN_SERVICE_STATE_UNKNOWN:
1258 case CONNMAN_SERVICE_STATE_IDLE:
1259 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1260 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1261 case CONNMAN_SERVICE_STATE_DISCONNECT:
1262 case CONNMAN_SERVICE_STATE_FAILURE:
1264 case CONNMAN_SERVICE_STATE_READY:
1265 case CONNMAN_SERVICE_STATE_ONLINE:
1272 static bool is_idle_state(const struct connman_service *service,
1273 enum connman_service_state state)
1276 case CONNMAN_SERVICE_STATE_UNKNOWN:
1277 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1278 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1279 case CONNMAN_SERVICE_STATE_READY:
1280 case CONNMAN_SERVICE_STATE_ONLINE:
1281 case CONNMAN_SERVICE_STATE_DISCONNECT:
1282 case CONNMAN_SERVICE_STATE_FAILURE:
1284 case CONNMAN_SERVICE_STATE_IDLE:
1291 static bool is_connecting(struct connman_service *service)
1293 return is_connecting_state(service, service->state);
1296 static bool is_connected(struct connman_service *service)
1298 return is_connected_state(service, service->state);
1301 static bool nameserver_available(struct connman_service *service,
1306 family = connman_inet_check_ipaddress(ns);
1308 if (family == AF_INET)
1309 return is_connected_state(service, service->state_ipv4);
1311 if (family == AF_INET6)
1312 return is_connected_state(service, service->state_ipv6);
1317 static int nameserver_add(struct connman_service *service,
1318 const char *nameserver)
1322 if (!nameserver_available(service, nameserver))
1325 index = __connman_service_get_index(service);
1329 return connman_resolver_append(index, NULL, nameserver);
1332 static int nameserver_add_all(struct connman_service *service)
1336 if (service->nameservers_config) {
1337 while (service->nameservers_config[i]) {
1338 nameserver_add(service, service->nameservers_config[i]);
1345 if (service->nameservers) {
1346 while (service->nameservers[i]) {
1347 nameserver_add(service, service->nameservers[i]);
1355 static int nameserver_remove(struct connman_service *service,
1356 const char *nameserver)
1360 if (!nameserver_available(service, nameserver))
1363 index = __connman_service_get_index(service);
1367 return connman_resolver_remove(index, NULL, nameserver);
1370 static int nameserver_remove_all(struct connman_service *service)
1372 #if defined TIZEN_EXT
1374 * Skip this function if there is any connected profiles
1375 * that use same interface
1377 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
1378 __connman_service_get_connected_count_of_iface(service) > 0)
1383 index = __connman_service_get_index(service);
1387 while (service->nameservers_config && service->nameservers_config[i]) {
1389 nameserver_remove(service, service->nameservers_config[i]);
1394 while (service->nameservers && service->nameservers[i]) {
1395 nameserver_remove(service, service->nameservers[i]);
1402 static int searchdomain_add_all(struct connman_service *service)
1406 if (!is_connected(service))
1409 index = __connman_service_get_index(service);
1413 if (service->domains) {
1414 while (service->domains[i]) {
1415 connman_resolver_append(index, service->domains[i],
1423 if (service->domainname)
1424 connman_resolver_append(index, service->domainname, NULL);
1430 static int searchdomain_remove_all(struct connman_service *service)
1434 if (!is_connected(service))
1437 index = __connman_service_get_index(service);
1441 while (service->domains && service->domains[i]) {
1442 connman_resolver_remove(index, service->domains[i], NULL);
1446 if (service->domainname)
1447 connman_resolver_remove(index, service->domainname, NULL);
1453 * The is_auto variable is set to true when IPv6 autoconf nameservers are
1454 * inserted to resolver via netlink message (see rtnl.c:rtnl_newnduseropt()
1455 * for details) and not through service.c
1457 int __connman_service_nameserver_append(struct connman_service *service,
1458 const char *nameserver, bool is_auto)
1463 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1469 nameservers = service->nameservers_auto;
1471 nameservers = service->nameservers;
1473 for (i = 0; nameservers && nameservers[i]; i++)
1474 if (g_strcmp0(nameservers[i], nameserver) == 0)
1478 len = g_strv_length(nameservers);
1479 nameservers = g_try_renew(char *, nameservers, len + 2);
1482 nameservers = g_try_new0(char *, len + 2);
1488 nameservers[len] = g_strdup(nameserver);
1489 if (!nameservers[len])
1492 nameservers[len + 1] = NULL;
1494 #if defined TIZEN_TV_EXT
1495 if(service->dns_config_method == CONNMAN_DNSCONFIG_METHOD_UNKNOWN)
1496 service->dns_config_method = CONNMAN_DNSCONFIG_METHOD_DHCP;
1500 service->nameservers_auto = nameservers;
1502 service->nameservers = nameservers;
1503 nameserver_add(service, nameserver);
1509 int __connman_service_nameserver_remove(struct connman_service *service,
1510 const char *nameserver, bool is_auto)
1512 char **servers, **nameservers;
1516 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
1522 nameservers = service->nameservers_auto;
1524 nameservers = service->nameservers;
1529 for (i = 0; nameservers && nameservers[i]; i++)
1530 if (g_strcmp0(nameservers[i], nameserver) == 0) {
1538 len = g_strv_length(nameservers);
1545 servers = g_try_new0(char *, len);
1549 for (i = 0, j = 0; i < len; i++) {
1550 if (g_strcmp0(nameservers[i], nameserver)) {
1551 servers[j] = nameservers[i];
1554 g_free(nameservers[i]);
1556 nameservers[i] = NULL;
1558 servers[len - 1] = NULL;
1561 g_strfreev(nameservers);
1562 nameservers = servers;
1565 service->nameservers_auto = nameservers;
1567 service->nameservers = nameservers;
1568 nameserver_remove(service, nameserver);
1574 void __connman_service_nameserver_clear(struct connman_service *service)
1576 nameserver_remove_all(service);
1578 g_strfreev(service->nameservers);
1579 service->nameservers = NULL;
1581 nameserver_add_all(service);
1584 static void add_nameserver_route(int family, int index, char *nameserver,
1589 if (connman_inet_compare_subnet(index, nameserver))
1592 if (connman_inet_add_host_route(index, nameserver, gw) < 0)
1593 /* For P-t-P link the above route add will fail */
1594 connman_inet_add_host_route(index, nameserver, NULL);
1598 if (connman_inet_add_ipv6_host_route(index, nameserver,
1600 connman_inet_add_ipv6_host_route(index, nameserver,
1606 static void nameserver_add_routes(int index, char **nameservers,
1609 int i, ns_family, gw_family;
1611 gw_family = connman_inet_check_ipaddress(gw);
1615 for (i = 0; nameservers[i]; i++) {
1616 ns_family = connman_inet_check_ipaddress(nameservers[i]);
1617 if (ns_family < 0 || ns_family != gw_family)
1620 add_nameserver_route(ns_family, index, nameservers[i], gw);
1624 static void nameserver_del_routes(int index, char **nameservers,
1625 enum connman_ipconfig_type type)
1629 for (i = 0; nameservers[i]; i++) {
1630 family = connman_inet_check_ipaddress(nameservers[i]);
1636 if (type != CONNMAN_IPCONFIG_TYPE_IPV6)
1637 connman_inet_del_host_route(index,
1641 if (type != CONNMAN_IPCONFIG_TYPE_IPV4)
1642 connman_inet_del_ipv6_host_route(index,
1649 void __connman_service_nameserver_add_routes(struct connman_service *service,
1657 index = __connman_service_get_index(service);
1659 if (service->nameservers_config) {
1661 * Configured nameserver takes preference over the
1662 * discoverd nameserver gathered from DHCP, VPN, etc.
1664 nameserver_add_routes(index, service->nameservers_config, gw);
1665 } else if (service->nameservers) {
1667 * We add nameservers host routes for nameservers that
1668 * are not on our subnet. For those who are, the subnet
1669 * route will be installed by the time the dns proxy code
1670 * tries to reach them. The subnet route is installed
1671 * when setting the interface IP address.
1673 nameserver_add_routes(index, service->nameservers, gw);
1677 void __connman_service_nameserver_del_routes(struct connman_service *service,
1678 enum connman_ipconfig_type type)
1685 index = __connman_service_get_index(service);
1687 if (service->nameservers_config)
1688 nameserver_del_routes(index, service->nameservers_config,
1690 else if (service->nameservers)
1691 nameserver_del_routes(index, service->nameservers, type);
1694 static struct connman_stats *stats_get(struct connman_service *service)
1696 if (service->roaming)
1697 return &service->stats_roaming;
1699 return &service->stats;
1702 static bool stats_enabled(struct connman_service *service)
1704 struct connman_stats *stats = stats_get(service);
1706 return stats->enabled;
1709 static void stats_start(struct connman_service *service)
1711 struct connman_stats *stats = stats_get(service);
1713 DBG("service %p", service);
1718 stats->enabled = true;
1719 stats->data_last.time = stats->data.time;
1721 g_timer_start(stats->timer);
1724 static void stats_stop(struct connman_service *service)
1726 struct connman_stats *stats = stats_get(service);
1727 unsigned int seconds;
1729 DBG("service %p", service);
1734 if (!stats->enabled)
1737 g_timer_stop(stats->timer);
1739 seconds = g_timer_elapsed(stats->timer, NULL);
1740 stats->data.time = stats->data_last.time + seconds;
1742 stats->enabled = false;
1745 static void reset_stats(struct connman_service *service)
1747 DBG("service %p", service);
1750 service->stats.valid = false;
1752 service->stats.data.rx_packets = 0;
1753 service->stats.data.tx_packets = 0;
1754 service->stats.data.rx_bytes = 0;
1755 service->stats.data.tx_bytes = 0;
1756 service->stats.data.rx_errors = 0;
1757 service->stats.data.tx_errors = 0;
1758 service->stats.data.rx_dropped = 0;
1759 service->stats.data.tx_dropped = 0;
1760 service->stats.data.time = 0;
1761 service->stats.data_last.time = 0;
1763 g_timer_reset(service->stats.timer);
1766 service->stats_roaming.valid = false;
1768 service->stats_roaming.data.rx_packets = 0;
1769 service->stats_roaming.data.tx_packets = 0;
1770 service->stats_roaming.data.rx_bytes = 0;
1771 service->stats_roaming.data.tx_bytes = 0;
1772 service->stats_roaming.data.rx_errors = 0;
1773 service->stats_roaming.data.tx_errors = 0;
1774 service->stats_roaming.data.rx_dropped = 0;
1775 service->stats_roaming.data.tx_dropped = 0;
1776 service->stats_roaming.data.time = 0;
1777 service->stats_roaming.data_last.time = 0;
1779 g_timer_reset(service->stats_roaming.timer);
1782 #if defined TIZEN_EXT
1783 static gboolean __connman_service_is_internet_profile(
1784 struct connman_service *cellular)
1786 const char internet_suffix[] = "_1";
1788 DBG("Service path: %s", cellular->path);
1790 if (g_str_has_suffix(cellular->path, internet_suffix) == TRUE)
1796 static gboolean __connman_service_is_tethering_profile(
1797 struct connman_service *cellular)
1799 const char tethering_suffix[] = "_5";
1801 DBG("Service path: %s", cellular->path);
1803 if (g_str_has_suffix(cellular->path, tethering_suffix) == TRUE)
1809 struct connman_service *connman_service_get_default_connection(void)
1812 struct connman_service *service;
1813 struct connman_service *default_service = NULL;
1815 for (list = service_list; list; list = list->next) {
1816 service = list->data;
1818 DBG("service: %p %s %s %s", service, service->name,
1819 state2string(service->state),
1820 __connman_service_type2string(service->type));
1822 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
1823 is_connected(service) == TRUE) {
1825 } else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
1826 __connman_service_is_internet_profile(service) == TRUE) {
1827 if (default_service == NULL)
1828 default_service = service;
1829 else if (is_connected(service) == TRUE &&
1830 is_connected(default_service) == FALSE)
1831 default_service = service;
1832 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET &&
1833 is_connected(service) == TRUE) {
1834 if (default_service == NULL)
1835 default_service = service;
1836 } else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH &&
1837 is_connected(service) == TRUE) {
1838 if (default_service == NULL)
1839 default_service = service;
1843 return default_service;
1847 struct connman_service *__connman_service_get_default(void)
1849 struct connman_service *service;
1854 service = service_list->data;
1856 if (!is_connected(service))
1862 bool __connman_service_index_is_default(int index)
1864 struct connman_service *service;
1869 service = __connman_service_get_default();
1871 return __connman_service_get_index(service) == index;
1874 static void default_changed(void)
1876 struct connman_service *service = __connman_service_get_default();
1878 if (service == current_default)
1881 DBG("current default %p %s", current_default,
1882 current_default ? current_default->identifier : "");
1883 DBG("new default %p %s", service, service ? service->identifier : "");
1885 #if defined TIZEN_EXT
1886 current_default = service;
1888 __connman_service_timeserver_changed(service, NULL);
1890 __connman_service_timeserver_changed(current_default, NULL);
1892 current_default = service;
1896 if (service->hostname &&
1897 connman_setting_get_bool("AllowHostnameUpdates"))
1898 __connman_utsname_set_hostname(service->hostname);
1900 if (service->domainname)
1901 __connman_utsname_set_domainname(service->domainname);
1904 __connman_notifier_default_changed(service);
1907 static void state_changed(struct connman_service *service)
1911 __connman_notifier_service_state_changed(service, service->state);
1913 str = state2string(service->state);
1917 #if !defined TIZEN_EXT
1918 if (!allow_property_changed(service))
1922 connman_dbus_property_changed_basic(service->path,
1923 CONNMAN_SERVICE_INTERFACE, "State",
1924 DBUS_TYPE_STRING, &str);
1927 static void strength_changed(struct connman_service *service)
1929 if (service->strength == 0)
1932 if (!allow_property_changed(service))
1935 connman_dbus_property_changed_basic(service->path,
1936 CONNMAN_SERVICE_INTERFACE, "Strength",
1937 DBUS_TYPE_BYTE, &service->strength);
1940 static void favorite_changed(struct connman_service *service)
1942 dbus_bool_t favorite;
1947 if (!allow_property_changed(service))
1950 favorite = service->favorite;
1951 connman_dbus_property_changed_basic(service->path,
1952 CONNMAN_SERVICE_INTERFACE, "Favorite",
1953 DBUS_TYPE_BOOLEAN, &favorite);
1956 static void immutable_changed(struct connman_service *service)
1958 dbus_bool_t immutable;
1963 if (!allow_property_changed(service))
1966 immutable = service->immutable;
1967 connman_dbus_property_changed_basic(service->path,
1968 CONNMAN_SERVICE_INTERFACE, "Immutable",
1969 DBUS_TYPE_BOOLEAN, &immutable);
1972 static void roaming_changed(struct connman_service *service)
1974 dbus_bool_t roaming;
1979 if (!allow_property_changed(service))
1982 roaming = service->roaming;
1983 connman_dbus_property_changed_basic(service->path,
1984 CONNMAN_SERVICE_INTERFACE, "Roaming",
1985 DBUS_TYPE_BOOLEAN, &roaming);
1988 static void autoconnect_changed(struct connman_service *service)
1990 dbus_bool_t autoconnect;
1995 if (!allow_property_changed(service))
1998 autoconnect = service->autoconnect;
1999 connman_dbus_property_changed_basic(service->path,
2000 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
2001 DBUS_TYPE_BOOLEAN, &autoconnect);
2004 static void append_security(DBusMessageIter *iter, void *user_data)
2006 struct connman_service *service = user_data;
2009 str = security2string(service->security);
2011 dbus_message_iter_append_basic(iter,
2012 DBUS_TYPE_STRING, &str);
2015 * Some access points incorrectly advertise WPS even when they
2016 * are configured as open or no security, so filter
2020 switch (service->security) {
2021 case CONNMAN_SERVICE_SECURITY_PSK:
2022 case CONNMAN_SERVICE_SECURITY_WPA:
2023 case CONNMAN_SERVICE_SECURITY_RSN:
2025 dbus_message_iter_append_basic(iter,
2026 DBUS_TYPE_STRING, &str);
2028 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
2029 case CONNMAN_SERVICE_SECURITY_NONE:
2030 case CONNMAN_SERVICE_SECURITY_WEP:
2031 case CONNMAN_SERVICE_SECURITY_8021X:
2037 static void append_ethernet(DBusMessageIter *iter, void *user_data)
2039 struct connman_service *service = user_data;
2041 if (service->ipconfig_ipv4)
2042 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
2044 else if (service->ipconfig_ipv6)
2045 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
2049 static void append_ipv4(DBusMessageIter *iter, void *user_data)
2051 struct connman_service *service = user_data;
2053 if (!is_connected_state(service, service->state_ipv4))
2056 if (service->ipconfig_ipv4)
2057 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
2060 static void append_ipv6(DBusMessageIter *iter, void *user_data)
2062 struct connman_service *service = user_data;
2064 if (!is_connected_state(service, service->state_ipv6))
2067 if (service->ipconfig_ipv6)
2068 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
2069 service->ipconfig_ipv4);
2072 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
2074 struct connman_service *service = user_data;
2076 if (service->ipconfig_ipv4)
2077 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
2081 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
2083 struct connman_service *service = user_data;
2085 if (service->ipconfig_ipv6)
2086 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
2090 static void append_nameservers(DBusMessageIter *iter,
2091 struct connman_service *service, char **servers)
2094 bool available = true;
2096 for (i = 0; servers[i]; i++) {
2098 available = nameserver_available(service, servers[i]);
2100 DBG("servers[%d] %s available %d", i, servers[i], available);
2103 dbus_message_iter_append_basic(iter,
2104 DBUS_TYPE_STRING, &servers[i]);
2108 static void append_dns(DBusMessageIter *iter, void *user_data)
2110 struct connman_service *service = user_data;
2112 if (!is_connected(service))
2115 #if defined TIZEN_TV_EXT
2116 /* Append DNS Config Type */
2118 str = __connman_dnsconfig_method2string(service->dns_config_method);
2120 dbus_message_iter_append_basic(iter,
2121 DBUS_TYPE_STRING, &str);
2124 if (service->nameservers_config) {
2125 append_nameservers(iter, service, service->nameservers_config);
2128 if (service->nameservers)
2129 append_nameservers(iter, service,
2130 service->nameservers);
2132 if (service->nameservers_auto)
2133 append_nameservers(iter, service,
2134 service->nameservers_auto);
2136 if (!service->nameservers && !service->nameservers_auto) {
2139 DBG("append fallback nameservers");
2141 ns = connman_setting_get_string_list("FallbackNameservers");
2143 append_nameservers(iter, service, ns);
2148 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
2150 struct connman_service *service = user_data;
2152 #if defined TIZEN_TV_EXT
2153 /* Append DNS Config Type */
2155 str = __connman_dnsconfig_method2string(service->dns_config_method);
2157 dbus_message_iter_append_basic(iter,
2158 DBUS_TYPE_STRING, &str);
2161 if (!service->nameservers_config)
2164 append_nameservers(iter, NULL, service->nameservers_config);
2167 static void append_ts(DBusMessageIter *iter, void *user_data)
2169 GSList *list = user_data;
2172 char *timeserver = list->data;
2175 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
2178 list = g_slist_next(list);
2182 static void append_tsconfig(DBusMessageIter *iter, void *user_data)
2184 struct connman_service *service = user_data;
2187 if (!service->timeservers_config)
2190 for (i = 0; service->timeservers_config[i]; i++) {
2191 dbus_message_iter_append_basic(iter,
2193 &service->timeservers_config[i]);
2197 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
2199 struct connman_service *service = user_data;
2202 if (!service->domains)
2205 for (i = 0; service->domains[i]; i++)
2206 dbus_message_iter_append_basic(iter,
2207 DBUS_TYPE_STRING, &service->domains[i]);
2210 static void append_domain(DBusMessageIter *iter, void *user_data)
2212 struct connman_service *service = user_data;
2214 if (!is_connected(service) &&
2215 !is_connecting(service))
2218 if (service->domains)
2219 append_domainconfig(iter, user_data);
2220 else if (service->domainname)
2221 dbus_message_iter_append_basic(iter,
2222 DBUS_TYPE_STRING, &service->domainname);
2225 static void append_proxies(DBusMessageIter *iter, void *user_data)
2227 struct connman_service *service = user_data;
2230 if (!service->proxies)
2233 for (i = 0; service->proxies[i]; i++)
2234 dbus_message_iter_append_basic(iter,
2235 DBUS_TYPE_STRING, &service->proxies[i]);
2238 static void append_excludes(DBusMessageIter *iter, void *user_data)
2240 struct connman_service *service = user_data;
2243 if (!service->excludes)
2246 for (i = 0; service->excludes[i]; i++)
2247 dbus_message_iter_append_basic(iter,
2248 DBUS_TYPE_STRING, &service->excludes[i]);
2251 static void append_proxy(DBusMessageIter *iter, void *user_data)
2253 struct connman_service *service = user_data;
2254 enum connman_service_proxy_method proxy;
2255 const char *pac = NULL;
2256 const char *method = proxymethod2string(
2257 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
2259 if (!is_connected(service))
2262 proxy = connman_service_get_proxy_method(service);
2265 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2267 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2269 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2270 connman_dbus_dict_append_array(iter, "Servers",
2271 DBUS_TYPE_STRING, append_proxies,
2274 connman_dbus_dict_append_array(iter, "Excludes",
2275 DBUS_TYPE_STRING, append_excludes,
2278 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2279 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
2280 if (service->ipconfig_ipv4)
2281 pac = __connman_ipconfig_get_proxy_autoconfig(
2282 service->ipconfig_ipv4);
2283 else if (service->ipconfig_ipv6)
2284 pac = __connman_ipconfig_get_proxy_autoconfig(
2285 service->ipconfig_ipv6);
2287 if (!service->pac && !pac)
2293 connman_dbus_dict_append_basic(iter, "URL",
2294 DBUS_TYPE_STRING, &pac);
2298 method = proxymethod2string(proxy);
2301 connman_dbus_dict_append_basic(iter, "Method",
2302 DBUS_TYPE_STRING, &method);
2305 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
2307 struct connman_service *service = user_data;
2310 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
2313 switch (service->proxy_config) {
2314 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2316 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2318 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2319 if (service->proxies)
2320 connman_dbus_dict_append_array(iter, "Servers",
2322 append_proxies, service);
2324 if (service->excludes)
2325 connman_dbus_dict_append_array(iter, "Excludes",
2327 append_excludes, service);
2329 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2331 connman_dbus_dict_append_basic(iter, "URL",
2332 DBUS_TYPE_STRING, &service->pac);
2336 method = proxymethod2string(service->proxy_config);
2338 connman_dbus_dict_append_basic(iter, "Method",
2339 DBUS_TYPE_STRING, &method);
2342 static void append_provider(DBusMessageIter *iter, void *user_data)
2344 struct connman_service *service = user_data;
2346 if (!is_connected(service))
2349 if (service->provider)
2350 __connman_provider_append_properties(service->provider, iter);
2354 static void settings_changed(struct connman_service *service,
2355 struct connman_ipconfig *ipconfig)
2357 enum connman_ipconfig_type type;
2359 if (!allow_property_changed(service))
2362 type = __connman_ipconfig_get_config_type(ipconfig);
2364 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
2365 connman_dbus_property_changed_dict(service->path,
2366 CONNMAN_SERVICE_INTERFACE, "IPv4",
2367 append_ipv4, service);
2368 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2369 connman_dbus_property_changed_dict(service->path,
2370 CONNMAN_SERVICE_INTERFACE, "IPv6",
2371 append_ipv6, service);
2373 __connman_notifier_ipconfig_changed(service, ipconfig);
2376 static void ipv4_configuration_changed(struct connman_service *service)
2378 if (!allow_property_changed(service))
2381 connman_dbus_property_changed_dict(service->path,
2382 CONNMAN_SERVICE_INTERFACE,
2383 "IPv4.Configuration",
2388 static void ipv6_configuration_changed(struct connman_service *service)
2390 if (!allow_property_changed(service))
2393 connman_dbus_property_changed_dict(service->path,
2394 CONNMAN_SERVICE_INTERFACE,
2395 "IPv6.Configuration",
2400 static void dns_changed(struct connman_service *service)
2402 if (!allow_property_changed(service))
2405 connman_dbus_property_changed_array(service->path,
2406 CONNMAN_SERVICE_INTERFACE, "Nameservers",
2407 DBUS_TYPE_STRING, append_dns, service);
2410 static void dns_configuration_changed(struct connman_service *service)
2412 if (!allow_property_changed(service))
2415 connman_dbus_property_changed_array(service->path,
2416 CONNMAN_SERVICE_INTERFACE,
2417 "Nameservers.Configuration",
2418 DBUS_TYPE_STRING, append_dnsconfig, service);
2420 dns_changed(service);
2423 static void domain_changed(struct connman_service *service)
2425 if (!allow_property_changed(service))
2428 connman_dbus_property_changed_array(service->path,
2429 CONNMAN_SERVICE_INTERFACE, "Domains",
2430 DBUS_TYPE_STRING, append_domain, service);
2433 static void domain_configuration_changed(struct connman_service *service)
2435 if (!allow_property_changed(service))
2438 connman_dbus_property_changed_array(service->path,
2439 CONNMAN_SERVICE_INTERFACE,
2440 "Domains.Configuration",
2441 DBUS_TYPE_STRING, append_domainconfig, service);
2444 static void proxy_changed(struct connman_service *service)
2446 if (!allow_property_changed(service))
2449 connman_dbus_property_changed_dict(service->path,
2450 CONNMAN_SERVICE_INTERFACE, "Proxy",
2451 append_proxy, service);
2454 static void proxy_configuration_changed(struct connman_service *service)
2456 if (!allow_property_changed(service))
2459 connman_dbus_property_changed_dict(service->path,
2460 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
2461 append_proxyconfig, service);
2463 proxy_changed(service);
2466 static void timeservers_configuration_changed(struct connman_service *service)
2468 if (!allow_property_changed(service))
2471 connman_dbus_property_changed_array(service->path,
2472 CONNMAN_SERVICE_INTERFACE,
2473 "Timeservers.Configuration",
2475 append_tsconfig, service);
2478 static void link_changed(struct connman_service *service)
2480 if (!allow_property_changed(service))
2483 connman_dbus_property_changed_dict(service->path,
2484 CONNMAN_SERVICE_INTERFACE, "Ethernet",
2485 append_ethernet, service);
2488 static void stats_append_counters(DBusMessageIter *dict,
2489 struct connman_stats_data *stats,
2490 struct connman_stats_data *counters,
2493 if (counters->rx_packets != stats->rx_packets || append_all) {
2494 counters->rx_packets = stats->rx_packets;
2495 connman_dbus_dict_append_basic(dict, "RX.Packets",
2496 DBUS_TYPE_UINT32, &stats->rx_packets);
2499 if (counters->tx_packets != stats->tx_packets || append_all) {
2500 counters->tx_packets = stats->tx_packets;
2501 connman_dbus_dict_append_basic(dict, "TX.Packets",
2502 DBUS_TYPE_UINT32, &stats->tx_packets);
2505 if (counters->rx_bytes != stats->rx_bytes || append_all) {
2506 counters->rx_bytes = stats->rx_bytes;
2507 connman_dbus_dict_append_basic(dict, "RX.Bytes",
2508 DBUS_TYPE_UINT32, &stats->rx_bytes);
2511 if (counters->tx_bytes != stats->tx_bytes || append_all) {
2512 counters->tx_bytes = stats->tx_bytes;
2513 connman_dbus_dict_append_basic(dict, "TX.Bytes",
2514 DBUS_TYPE_UINT32, &stats->tx_bytes);
2517 if (counters->rx_errors != stats->rx_errors || append_all) {
2518 counters->rx_errors = stats->rx_errors;
2519 connman_dbus_dict_append_basic(dict, "RX.Errors",
2520 DBUS_TYPE_UINT32, &stats->rx_errors);
2523 if (counters->tx_errors != stats->tx_errors || append_all) {
2524 counters->tx_errors = stats->tx_errors;
2525 connman_dbus_dict_append_basic(dict, "TX.Errors",
2526 DBUS_TYPE_UINT32, &stats->tx_errors);
2529 if (counters->rx_dropped != stats->rx_dropped || append_all) {
2530 counters->rx_dropped = stats->rx_dropped;
2531 connman_dbus_dict_append_basic(dict, "RX.Dropped",
2532 DBUS_TYPE_UINT32, &stats->rx_dropped);
2535 if (counters->tx_dropped != stats->tx_dropped || append_all) {
2536 counters->tx_dropped = stats->tx_dropped;
2537 connman_dbus_dict_append_basic(dict, "TX.Dropped",
2538 DBUS_TYPE_UINT32, &stats->tx_dropped);
2541 if (counters->time != stats->time || append_all) {
2542 counters->time = stats->time;
2543 connman_dbus_dict_append_basic(dict, "Time",
2544 DBUS_TYPE_UINT32, &stats->time);
2548 static void stats_append(struct connman_service *service,
2549 const char *counter,
2550 struct connman_stats_counter *counters,
2553 DBusMessageIter array, dict;
2556 DBG("service %p counter %s", service, counter);
2558 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
2562 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
2563 &service->path, DBUS_TYPE_INVALID);
2565 dbus_message_iter_init_append(msg, &array);
2568 connman_dbus_dict_open(&array, &dict);
2570 stats_append_counters(&dict, &service->stats.data,
2571 &counters->stats.data, append_all);
2573 connman_dbus_dict_close(&array, &dict);
2575 /* roaming counter */
2576 connman_dbus_dict_open(&array, &dict);
2578 stats_append_counters(&dict, &service->stats_roaming.data,
2579 &counters->stats_roaming.data, append_all);
2581 connman_dbus_dict_close(&array, &dict);
2583 __connman_counter_send_usage(counter, msg);
2586 static void stats_update(struct connman_service *service,
2587 unsigned int rx_packets, unsigned int tx_packets,
2588 unsigned int rx_bytes, unsigned int tx_bytes,
2589 unsigned int rx_errors, unsigned int tx_errors,
2590 unsigned int rx_dropped, unsigned int tx_dropped)
2592 struct connman_stats *stats = stats_get(service);
2593 struct connman_stats_data *data_last = &stats->data_last;
2594 struct connman_stats_data *data = &stats->data;
2595 unsigned int seconds;
2597 DBG("service %p", service);
2601 rx_packets - data_last->rx_packets;
2603 tx_packets - data_last->tx_packets;
2605 rx_bytes - data_last->rx_bytes;
2607 tx_bytes - data_last->tx_bytes;
2609 rx_errors - data_last->rx_errors;
2611 tx_errors - data_last->tx_errors;
2613 rx_dropped - data_last->rx_dropped;
2615 tx_dropped - data_last->tx_dropped;
2617 stats->valid = true;
2620 data_last->rx_packets = rx_packets;
2621 data_last->tx_packets = tx_packets;
2622 data_last->rx_bytes = rx_bytes;
2623 data_last->tx_bytes = tx_bytes;
2624 data_last->rx_errors = rx_errors;
2625 data_last->tx_errors = tx_errors;
2626 data_last->rx_dropped = rx_dropped;
2627 data_last->tx_dropped = tx_dropped;
2629 seconds = g_timer_elapsed(stats->timer, NULL);
2630 stats->data.time = stats->data_last.time + seconds;
2633 void __connman_service_notify(struct connman_service *service,
2634 unsigned int rx_packets, unsigned int tx_packets,
2635 unsigned int rx_bytes, unsigned int tx_bytes,
2636 unsigned int rx_errors, unsigned int tx_errors,
2637 unsigned int rx_dropped, unsigned int tx_dropped)
2639 GHashTableIter iter;
2640 gpointer key, value;
2641 const char *counter;
2642 struct connman_stats_counter *counters;
2643 struct connman_stats_data *data;
2649 if (!is_connected(service))
2652 stats_update(service,
2653 rx_packets, tx_packets,
2655 rx_errors, tx_errors,
2656 rx_dropped, tx_dropped);
2658 data = &stats_get(service)->data;
2659 err = __connman_stats_update(service, service->roaming, data);
2661 connman_error("Failed to store statistics for %s",
2662 service->identifier);
2664 g_hash_table_iter_init(&iter, service->counter_table);
2665 while (g_hash_table_iter_next(&iter, &key, &value)) {
2669 stats_append(service, counter, counters, counters->append_all);
2670 counters->append_all = false;
2674 int __connman_service_counter_register(const char *counter)
2676 struct connman_service *service;
2678 struct connman_stats_counter *counters;
2680 DBG("counter %s", counter);
2682 counter_list = g_slist_prepend(counter_list, (gpointer)counter);
2684 for (list = service_list; list; list = list->next) {
2685 service = list->data;
2687 counters = g_try_new0(struct connman_stats_counter, 1);
2691 counters->append_all = true;
2693 g_hash_table_replace(service->counter_table, (gpointer)counter,
2700 void __connman_service_counter_unregister(const char *counter)
2702 struct connman_service *service;
2705 DBG("counter %s", counter);
2707 for (list = service_list; list; list = list->next) {
2708 service = list->data;
2710 g_hash_table_remove(service->counter_table, counter);
2713 counter_list = g_slist_remove(counter_list, counter);
2716 int __connman_service_iterate_services(service_iterate_cb cb, void *user_data)
2720 for (list = service_list; list; list = list->next) {
2721 struct connman_service *service = list->data;
2723 cb(service, user_data);
2729 #if defined TIZEN_EXT
2730 static void append_wifi_ext_info(DBusMessageIter *dict,
2731 struct connman_network *network)
2733 char bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
2734 char *bssid_str = bssid_buff;
2735 unsigned char *bssid;
2736 unsigned int maxrate;
2737 unsigned int keymgmt;
2739 const char *enc_mode;
2742 bssid = connman_network_get_bssid(network);
2743 maxrate = connman_network_get_maxrate(network);
2744 frequency = connman_network_get_frequency(network);
2745 enc_mode = connman_network_get_enc_mode(network);
2746 passpoint = connman_network_get_is_hs20AP(network);
2747 keymgmt = connman_network_get_keymgmt(network);
2749 snprintf(bssid_str, WIFI_BSSID_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
2750 bssid[0], bssid[1], bssid[2],
2751 bssid[3], bssid[4], bssid[5]);
2753 connman_dbus_dict_append_basic(dict, "BSSID",
2754 DBUS_TYPE_STRING, &bssid_str);
2755 connman_dbus_dict_append_basic(dict, "MaxRate",
2756 DBUS_TYPE_UINT32, &maxrate);
2757 connman_dbus_dict_append_basic(dict, "Frequency",
2758 DBUS_TYPE_UINT16, &frequency);
2759 connman_dbus_dict_append_basic(dict, "EncryptionMode",
2760 DBUS_TYPE_STRING, &enc_mode);
2761 connman_dbus_dict_append_basic(dict, "Passpoint",
2762 DBUS_TYPE_BOOLEAN, &passpoint);
2763 connman_dbus_dict_append_basic(dict, "Keymgmt",
2764 DBUS_TYPE_UINT32, &keymgmt);
2768 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
2769 struct connman_service *service)
2775 #if defined TIZEN_EXT
2776 unsigned int frequency = 0U;
2777 if (service && service->network) {
2778 frequency = connman_network_get_frequency(service->network);
2779 connman_dbus_dict_append_basic(dict, "Frequency",
2780 DBUS_TYPE_UINT16, &frequency);
2784 str = __connman_service_type2string(service->type);
2786 connman_dbus_dict_append_basic(dict, "Type",
2787 DBUS_TYPE_STRING, &str);
2789 connman_dbus_dict_append_array(dict, "Security",
2790 DBUS_TYPE_STRING, append_security, service);
2792 str = state2string(service->state);
2794 connman_dbus_dict_append_basic(dict, "State",
2795 DBUS_TYPE_STRING, &str);
2797 #if defined TIZEN_TV_EXT
2798 str = state2string(service->state_ipv6);
2800 connman_dbus_dict_append_basic(dict, "StateIPv6",
2801 DBUS_TYPE_STRING, &str);
2804 str = error2string(service->error);
2806 connman_dbus_dict_append_basic(dict, "Error",
2807 DBUS_TYPE_STRING, &str);
2809 if (service->strength > 0)
2810 connman_dbus_dict_append_basic(dict, "Strength",
2811 DBUS_TYPE_BYTE, &service->strength);
2813 val = service->favorite;
2814 connman_dbus_dict_append_basic(dict, "Favorite",
2815 DBUS_TYPE_BOOLEAN, &val);
2817 val = service->immutable;
2818 connman_dbus_dict_append_basic(dict, "Immutable",
2819 DBUS_TYPE_BOOLEAN, &val);
2821 if (service->favorite)
2822 val = service->autoconnect;
2824 val = service->favorite;
2826 connman_dbus_dict_append_basic(dict, "AutoConnect",
2827 DBUS_TYPE_BOOLEAN, &val);
2830 connman_dbus_dict_append_basic(dict, "Name",
2831 DBUS_TYPE_STRING, &service->name);
2833 switch (service->type) {
2834 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2835 case CONNMAN_SERVICE_TYPE_SYSTEM:
2836 case CONNMAN_SERVICE_TYPE_GPS:
2837 case CONNMAN_SERVICE_TYPE_VPN:
2838 case CONNMAN_SERVICE_TYPE_P2P:
2840 case CONNMAN_SERVICE_TYPE_CELLULAR:
2841 val = service->roaming;
2842 connman_dbus_dict_append_basic(dict, "Roaming",
2843 DBUS_TYPE_BOOLEAN, &val);
2845 connman_dbus_dict_append_dict(dict, "Ethernet",
2846 append_ethernet, service);
2848 case CONNMAN_SERVICE_TYPE_WIFI:
2849 #if defined TIZEN_EXT
2850 if (service->network != NULL)
2851 append_wifi_ext_info(dict, service->network);
2853 connman_dbus_dict_append_dict(dict, "Ethernet",
2854 append_ethernet, service);
2856 connman_dbus_dict_append_basic(dict, "DisconnectReason",
2857 DBUS_TYPE_INT32, &service->disconnect_reason);
2861 case CONNMAN_SERVICE_TYPE_ETHERNET:
2862 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2863 case CONNMAN_SERVICE_TYPE_GADGET:
2864 connman_dbus_dict_append_dict(dict, "Ethernet",
2865 append_ethernet, service);
2869 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
2871 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
2872 append_ipv4config, service);
2874 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
2876 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
2877 append_ipv6config, service);
2879 connman_dbus_dict_append_array(dict, "Nameservers",
2880 DBUS_TYPE_STRING, append_dns, service);
2882 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
2883 DBUS_TYPE_STRING, append_dnsconfig, service);
2885 if (service->state == CONNMAN_SERVICE_STATE_READY ||
2886 service->state == CONNMAN_SERVICE_STATE_ONLINE)
2887 list = __connman_timeserver_get_all(service);
2891 connman_dbus_dict_append_array(dict, "Timeservers",
2892 DBUS_TYPE_STRING, append_ts, list);
2894 g_slist_free_full(list, g_free);
2896 connman_dbus_dict_append_array(dict, "Timeservers.Configuration",
2897 DBUS_TYPE_STRING, append_tsconfig, service);
2899 connman_dbus_dict_append_array(dict, "Domains",
2900 DBUS_TYPE_STRING, append_domain, service);
2902 connman_dbus_dict_append_array(dict, "Domains.Configuration",
2903 DBUS_TYPE_STRING, append_domainconfig, service);
2905 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
2907 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
2908 append_proxyconfig, service);
2910 connman_dbus_dict_append_dict(dict, "Provider",
2911 append_provider, service);
2914 static void append_struct_service(DBusMessageIter *iter,
2915 connman_dbus_append_cb_t function,
2916 struct connman_service *service)
2918 DBusMessageIter entry, dict;
2920 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
2922 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
2925 connman_dbus_dict_open(&entry, &dict);
2927 function(&dict, service);
2928 connman_dbus_dict_close(&entry, &dict);
2930 dbus_message_iter_close_container(iter, &entry);
2933 static void append_dict_properties(DBusMessageIter *dict, void *user_data)
2935 struct connman_service *service = user_data;
2937 append_properties(dict, TRUE, service);
2940 static void append_struct(gpointer value, gpointer user_data)
2942 struct connman_service *service = value;
2943 DBusMessageIter *iter = user_data;
2948 append_struct_service(iter, append_dict_properties, service);
2951 void __connman_service_list_struct(DBusMessageIter *iter)
2953 g_list_foreach(service_list, append_struct, iter);
2956 bool __connman_service_is_hidden(struct connman_service *service)
2958 return service->hidden;
2962 __connman_service_is_split_routing(struct connman_service *service)
2964 return service->do_split_routing;
2967 bool __connman_service_index_is_split_routing(int index)
2969 struct connman_service *service;
2974 service = __connman_service_lookup_from_index(index);
2978 return __connman_service_is_split_routing(service);
2981 int __connman_service_get_index(struct connman_service *service)
2986 if (service->network)
2987 return connman_network_get_index(service->network);
2988 else if (service->provider)
2989 return connman_provider_get_index(service->provider);
2994 void __connman_service_set_hidden(struct connman_service *service)
2996 if (!service || service->hidden)
2999 service->hidden_service = true;
3002 void __connman_service_set_hostname(struct connman_service *service,
3003 const char *hostname)
3005 if (!service || service->hidden)
3008 g_free(service->hostname);
3009 service->hostname = g_strdup(hostname);
3012 const char *__connman_service_get_hostname(struct connman_service *service)
3017 return service->hostname;
3020 void __connman_service_set_domainname(struct connman_service *service,
3021 const char *domainname)
3023 if (!service || service->hidden)
3026 g_free(service->domainname);
3027 service->domainname = g_strdup(domainname);
3029 domain_changed(service);
3032 const char *connman_service_get_domainname(struct connman_service *service)
3037 if (service->domains)
3038 return service->domains[0];
3040 return service->domainname;
3043 char **connman_service_get_nameservers(struct connman_service *service)
3048 if (service->nameservers_config)
3049 return g_strdupv(service->nameservers_config);
3050 else if (service->nameservers ||
3051 service->nameservers_auto) {
3052 int len = 0, len_auto = 0, i;
3055 if (service->nameservers)
3056 len = g_strv_length(service->nameservers);
3057 if (service->nameservers_auto)
3058 len_auto = g_strv_length(service->nameservers_auto);
3060 nameservers = g_try_new0(char *, len + len_auto + 1);
3064 for (i = 0; i < len; i++)
3065 nameservers[i] = g_strdup(service->nameservers[i]);
3067 for (i = 0; i < len_auto; i++)
3068 nameservers[i + len] =
3069 g_strdup(service->nameservers_auto[i]);
3074 return g_strdupv(connman_setting_get_string_list("FallbackNameservers"));
3077 char **connman_service_get_timeservers_config(struct connman_service *service)
3082 return service->timeservers_config;
3085 char **connman_service_get_timeservers(struct connman_service *service)
3090 return service->timeservers;
3093 #if defined TIZEN_EXT
3095 * Description: Telephony plug-in requires manual PROXY setting function
3097 int connman_service_set_proxy(struct connman_service *service,
3098 const char *proxy, gboolean active)
3100 char **proxies_array = NULL;
3102 if (service == NULL)
3105 switch (service->type) {
3106 case CONNMAN_SERVICE_TYPE_CELLULAR:
3107 case CONNMAN_SERVICE_TYPE_ETHERNET:
3108 case CONNMAN_SERVICE_TYPE_WIFI:
3115 g_strfreev(service->proxies);
3116 service->proxies = NULL;
3119 proxies_array = g_strsplit(proxy, " ", 0);
3121 service->proxies = proxies_array;
3123 if (proxy == NULL) {
3124 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
3125 DBG("proxy changed (%d)", active);
3127 service->proxy_config = CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
3128 DBG("proxy chagned %s (%d)", proxy, active);
3131 if (active == TRUE) {
3132 proxy_changed(service);
3134 __connman_notifier_proxy_changed(service);
3141 void connman_service_set_proxy_method(struct connman_service *service,
3142 enum connman_service_proxy_method method)
3144 if (!service || service->hidden)
3147 service->proxy = method;
3149 proxy_changed(service);
3151 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
3152 __connman_notifier_proxy_changed(service);
3155 enum connman_service_proxy_method connman_service_get_proxy_method(
3156 struct connman_service *service)
3159 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
3161 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
3162 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
3164 return service->proxy;
3166 return service->proxy_config;
3169 return service->proxy;
3172 char **connman_service_get_proxy_servers(struct connman_service *service)
3174 return g_strdupv(service->proxies);
3177 char **connman_service_get_proxy_excludes(struct connman_service *service)
3179 return g_strdupv(service->excludes);
3182 const char *connman_service_get_proxy_url(struct connman_service *service)
3187 return service->pac;
3190 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
3193 if (!service || service->hidden)
3196 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
3198 if (service->ipconfig_ipv4) {
3199 if (__connman_ipconfig_set_proxy_autoconfig(
3200 service->ipconfig_ipv4, url) < 0)
3202 } else if (service->ipconfig_ipv6) {
3203 if (__connman_ipconfig_set_proxy_autoconfig(
3204 service->ipconfig_ipv6, url) < 0)
3209 proxy_changed(service);
3211 __connman_notifier_proxy_changed(service);
3214 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
3219 if (service->ipconfig_ipv4)
3220 return __connman_ipconfig_get_proxy_autoconfig(
3221 service->ipconfig_ipv4);
3222 else if (service->ipconfig_ipv6)
3223 return __connman_ipconfig_get_proxy_autoconfig(
3224 service->ipconfig_ipv6);
3228 void __connman_service_set_timeservers(struct connman_service *service,
3236 g_strfreev(service->timeservers);
3237 service->timeservers = NULL;
3239 for (i = 0; timeservers && timeservers[i]; i++)
3240 __connman_service_timeserver_append(service, timeservers[i]);
3243 int __connman_service_timeserver_append(struct connman_service *service,
3244 const char *timeserver)
3248 DBG("service %p timeserver %s", service, timeserver);
3253 if (service->timeservers) {
3256 for (i = 0; service->timeservers[i]; i++)
3257 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
3260 len = g_strv_length(service->timeservers);
3261 service->timeservers = g_try_renew(char *, service->timeservers,
3265 service->timeservers = g_try_new0(char *, len + 2);
3268 if (!service->timeservers)
3271 service->timeservers[len] = g_strdup(timeserver);
3272 service->timeservers[len + 1] = NULL;
3277 int __connman_service_timeserver_remove(struct connman_service *service,
3278 const char *timeserver)
3281 int len, i, j, found = 0;
3283 DBG("service %p timeserver %s", service, timeserver);
3288 if (!service->timeservers)
3291 for (i = 0; service->timeservers &&
3292 service->timeservers[i]; i++)
3293 if (g_strcmp0(service->timeservers[i], timeserver) == 0) {
3301 len = g_strv_length(service->timeservers);
3304 g_strfreev(service->timeservers);
3305 service->timeservers = NULL;
3310 servers = g_try_new0(char *, len);
3314 for (i = 0, j = 0; i < len; i++) {
3315 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
3316 servers[j] = g_strdup(service->timeservers[i]);
3322 servers[len - 1] = NULL;
3324 g_strfreev(service->timeservers);
3325 service->timeservers = servers;
3330 void __connman_service_timeserver_changed(struct connman_service *service,
3336 if (!allow_property_changed(service))
3339 connman_dbus_property_changed_array(service->path,
3340 CONNMAN_SERVICE_INTERFACE, "Timeservers",
3341 DBUS_TYPE_STRING, append_ts, ts_list);
3344 void __connman_service_set_pac(struct connman_service *service,
3347 if (service->hidden)
3349 g_free(service->pac);
3350 service->pac = g_strdup(pac);
3352 proxy_changed(service);
3355 #if defined TIZEN_EXT
3356 void __connman_service_set_proxy(struct connman_service *service,
3357 const char *proxies)
3359 char **proxies_array = NULL;
3361 g_strfreev(service->proxies);
3362 service->proxies = NULL;
3364 if (proxies != NULL)
3365 proxies_array = g_strsplit(proxies, " ", 0);
3367 service->proxies = proxies_array;
3371 void __connman_service_set_identity(struct connman_service *service,
3372 const char *identity)
3374 if (service->immutable || service->hidden)
3377 g_free(service->identity);
3378 service->identity = g_strdup(identity);
3380 if (service->network)
3381 connman_network_set_string(service->network,
3386 void __connman_service_set_agent_identity(struct connman_service *service,
3387 const char *agent_identity)
3389 if (service->hidden)
3391 g_free(service->agent_identity);
3392 service->agent_identity = g_strdup(agent_identity);
3394 if (service->network)
3395 connman_network_set_string(service->network,
3396 "WiFi.AgentIdentity",
3397 service->agent_identity);
3400 static int check_passphrase(enum connman_service_security security,
3401 const char *passphrase)
3409 length = strlen(passphrase);
3412 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3413 case CONNMAN_SERVICE_SECURITY_NONE:
3414 case CONNMAN_SERVICE_SECURITY_WPA:
3415 #if !defined TIZEN_EXT
3416 case CONNMAN_SERVICE_SECURITY_RSN:
3419 DBG("service security '%s' (%d) not handled",
3420 security2string(security), security);
3424 case CONNMAN_SERVICE_SECURITY_PSK:
3425 #if defined TIZEN_EXT
3426 case CONNMAN_SERVICE_SECURITY_RSN:
3428 /* A raw key is always 64 bytes length,
3429 * its content is in hex representation.
3430 * A PSK key must be between [8..63].
3433 for (i = 0; i < 64; i++)
3434 if (!isxdigit((unsigned char)
3437 } else if (length < 8 || length > 63)
3440 case CONNMAN_SERVICE_SECURITY_WEP:
3441 /* length of WEP key is 10 or 26
3442 * length of WEP passphrase is 5 or 13
3444 if (length == 10 || length == 26) {
3445 for (i = 0; i < length; i++)
3446 if (!isxdigit((unsigned char)
3449 } else if (length != 5 && length != 13)
3453 case CONNMAN_SERVICE_SECURITY_8021X:
3460 int __connman_service_set_passphrase(struct connman_service *service,
3461 const char *passphrase)
3465 if (service->hidden)
3468 if (service->immutable &&
3469 service->security != CONNMAN_SERVICE_SECURITY_8021X)
3472 err = check_passphrase(service->security, passphrase);
3477 g_free(service->passphrase);
3478 service->passphrase = g_strdup(passphrase);
3480 if (service->network)
3481 connman_network_set_string(service->network, "WiFi.Passphrase",
3482 service->passphrase);
3487 const char *__connman_service_get_passphrase(struct connman_service *service)
3492 return service->passphrase;
3495 static DBusMessage *get_properties(DBusConnection *conn,
3496 DBusMessage *msg, void *user_data)
3498 struct connman_service *service = user_data;
3500 DBusMessageIter array, dict;
3502 DBG("service %p", service);
3504 reply = dbus_message_new_method_return(msg);
3508 dbus_message_iter_init_append(reply, &array);
3510 connman_dbus_dict_open(&array, &dict);
3511 append_properties(&dict, FALSE, service);
3512 connman_dbus_dict_close(&array, &dict);
3517 static int update_proxy_configuration(struct connman_service *service,
3518 DBusMessageIter *array)
3520 DBusMessageIter dict;
3521 enum connman_service_proxy_method method;
3522 GString *servers_str = NULL;
3523 GString *excludes_str = NULL;
3524 const char *url = NULL;
3526 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
3528 dbus_message_iter_recurse(array, &dict);
3530 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
3531 DBusMessageIter entry, variant;
3535 dbus_message_iter_recurse(&dict, &entry);
3537 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
3540 dbus_message_iter_get_basic(&entry, &key);
3541 dbus_message_iter_next(&entry);
3543 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
3546 dbus_message_iter_recurse(&entry, &variant);
3548 type = dbus_message_iter_get_arg_type(&variant);
3550 if (g_str_equal(key, "Method")) {
3553 if (type != DBUS_TYPE_STRING)
3556 dbus_message_iter_get_basic(&variant, &val);
3557 method = string2proxymethod(val);
3558 } else if (g_str_equal(key, "URL")) {
3559 if (type != DBUS_TYPE_STRING)
3562 dbus_message_iter_get_basic(&variant, &url);
3563 } else if (g_str_equal(key, "Servers")) {
3564 DBusMessageIter str_array;
3566 if (type != DBUS_TYPE_ARRAY)
3569 servers_str = g_string_new(NULL);
3573 dbus_message_iter_recurse(&variant, &str_array);
3575 while (dbus_message_iter_get_arg_type(&str_array) ==
3579 dbus_message_iter_get_basic(&str_array, &val);
3581 if (servers_str->len > 0)
3582 g_string_append_printf(servers_str,
3585 g_string_append(servers_str, val);
3587 dbus_message_iter_next(&str_array);
3589 } else if (g_str_equal(key, "Excludes")) {
3590 DBusMessageIter str_array;
3592 if (type != DBUS_TYPE_ARRAY)
3595 excludes_str = g_string_new(NULL);
3599 dbus_message_iter_recurse(&variant, &str_array);
3601 while (dbus_message_iter_get_arg_type(&str_array) ==
3605 dbus_message_iter_get_basic(&str_array, &val);
3607 if (excludes_str->len > 0)
3608 g_string_append_printf(excludes_str,
3611 g_string_append(excludes_str, val);
3613 dbus_message_iter_next(&str_array);
3617 dbus_message_iter_next(&dict);
3621 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
3623 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
3624 if (!servers_str && !service->proxies)
3628 g_strfreev(service->proxies);
3630 if (servers_str->len > 0)
3631 service->proxies = g_strsplit_set(
3632 servers_str->str, " ", 0);
3634 service->proxies = NULL;
3638 g_strfreev(service->excludes);
3640 if (excludes_str->len > 0)
3641 service->excludes = g_strsplit_set(
3642 excludes_str->str, " ", 0);
3644 service->excludes = NULL;
3647 if (!service->proxies)
3648 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
3651 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
3652 g_free(service->pac);
3654 if (url && strlen(url) > 0)
3655 service->pac = g_strdup(url);
3657 service->pac = NULL;
3659 /* if we are connected:
3660 - if service->pac == NULL
3661 - if __connman_ipconfig_get_proxy_autoconfig(
3662 service->ipconfig) == NULL
3663 --> We should start WPAD */
3666 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
3671 g_string_free(servers_str, TRUE);
3674 g_string_free(excludes_str, TRUE);
3676 service->proxy_config = method;
3682 g_string_free(servers_str, TRUE);
3685 g_string_free(excludes_str, TRUE);
3690 int __connman_service_reset_ipconfig(struct connman_service *service,
3691 enum connman_ipconfig_type type, DBusMessageIter *array,
3692 enum connman_service_state *new_state)
3694 struct connman_ipconfig *ipconfig, *new_ipconfig;
3695 enum connman_ipconfig_method old_method, new_method;
3696 enum connman_service_state state;
3699 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
3700 ipconfig = service->ipconfig_ipv4;
3701 state = service->state_ipv4;
3702 new_method = CONNMAN_IPCONFIG_METHOD_DHCP;
3703 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
3704 ipconfig = service->ipconfig_ipv6;
3705 state = service->state_ipv6;
3706 new_method = CONNMAN_IPCONFIG_METHOD_AUTO;
3713 old_method = __connman_ipconfig_get_method(ipconfig);
3714 index = __connman_ipconfig_get_index(ipconfig);
3716 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
3717 new_ipconfig = create_ip4config(service, index,
3718 CONNMAN_IPCONFIG_METHOD_UNKNOWN);
3720 new_ipconfig = create_ip6config(service, index);
3723 err = __connman_ipconfig_set_config(new_ipconfig, array);
3725 __connman_ipconfig_unref(new_ipconfig);
3729 new_method = __connman_ipconfig_get_method(new_ipconfig);
3732 if (is_connecting_state(service, state) ||
3733 is_connected_state(service, state))
3734 __connman_network_clear_ipconfig(service->network, ipconfig);
3736 __connman_ipconfig_unref(ipconfig);
3738 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
3739 service->ipconfig_ipv4 = new_ipconfig;
3740 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
3741 service->ipconfig_ipv6 = new_ipconfig;
3743 if (is_connecting_state(service, state) ||
3744 is_connected_state(service, state))
3745 __connman_ipconfig_enable(new_ipconfig);
3747 if (new_state && new_method != old_method) {
3748 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
3749 *new_state = service->state_ipv4;
3751 *new_state = service->state_ipv6;
3753 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
3756 DBG("err %d ipconfig %p type %d method %d state %s", err,
3757 new_ipconfig, type, new_method,
3758 !new_state ? "-" : state2string(*new_state));
3763 static DBusMessage *set_property(DBusConnection *conn,
3764 DBusMessage *msg, void *user_data)
3766 struct connman_service *service = user_data;
3767 DBusMessageIter iter, value;
3771 DBG("service %p", service);
3773 if (!dbus_message_iter_init(msg, &iter))
3774 return __connman_error_invalid_arguments(msg);
3776 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
3777 return __connman_error_invalid_arguments(msg);
3779 if (service->type == CONNMAN_SERVICE_TYPE_WIFI && is_connected(service)) {
3781 if (connman_dbus_get_connection_unix_user_sync(conn,
3782 dbus_message_get_sender(msg),
3784 DBG("Can not get unix user id!");
3785 return __connman_error_permission_denied(msg);
3788 if (!connman_service_is_user_allowed(service, uid)) {
3789 DBG("Not allow this user to operate this wifi service now!");
3790 return __connman_error_permission_denied(msg);
3794 dbus_message_iter_get_basic(&iter, &name);
3795 dbus_message_iter_next(&iter);
3797 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
3798 return __connman_error_invalid_arguments(msg);
3800 dbus_message_iter_recurse(&iter, &value);
3802 type = dbus_message_iter_get_arg_type(&value);
3804 if (g_str_equal(name, "AutoConnect")) {
3805 dbus_bool_t autoconnect;
3807 if (type != DBUS_TYPE_BOOLEAN)
3808 return __connman_error_invalid_arguments(msg);
3810 if (!service->favorite)
3811 return __connman_error_invalid_service(msg);
3813 dbus_message_iter_get_basic(&value, &autoconnect);
3815 if (service->autoconnect == autoconnect)
3816 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3818 service->autoconnect = autoconnect;
3820 autoconnect_changed(service);
3823 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
3825 service_save(service);
3826 } else if (g_str_equal(name, "Nameservers.Configuration")) {
3827 DBusMessageIter entry;
3832 if (__connman_provider_is_immutable(service->provider) ||
3834 return __connman_error_not_supported(msg);
3836 if (type != DBUS_TYPE_ARRAY)
3837 return __connman_error_invalid_arguments(msg);
3839 str = g_string_new(NULL);
3841 return __connman_error_invalid_arguments(msg);
3843 index = __connman_service_get_index(service);
3844 gw = __connman_ipconfig_get_gateway_from_index(index,
3845 CONNMAN_IPCONFIG_TYPE_ALL);
3847 if (gw && strlen(gw))
3848 __connman_service_nameserver_del_routes(service,
3849 CONNMAN_IPCONFIG_TYPE_ALL);
3851 dbus_message_iter_recurse(&value, &entry);
3853 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
3855 dbus_message_iter_get_basic(&entry, &val);
3856 dbus_message_iter_next(&entry);
3857 #if defined TIZEN_TV_EXT
3858 /* First unpack the DNS Config Method */
3859 if(g_strcmp0(val, "manual") == 0) {
3860 service->dns_config_method =
3861 CONNMAN_DNSCONFIG_METHOD_MANUAL;
3863 } else if(g_strcmp0(val, "dhcp") == 0) {
3864 service->dns_config_method =
3865 CONNMAN_DNSCONFIG_METHOD_DHCP;
3869 if (connman_inet_check_ipaddress(val) > 0) {
3871 g_string_append_printf(str, " %s", val);
3873 g_string_append(str, val);
3877 nameserver_remove_all(service);
3878 g_strfreev(service->nameservers_config);
3881 service->nameservers_config =
3882 g_strsplit_set(str->str, " ", 0);
3884 service->nameservers_config = NULL;
3887 g_string_free(str, TRUE);
3889 if (gw && strlen(gw))
3890 __connman_service_nameserver_add_routes(service, gw);
3892 nameserver_add_all(service);
3893 dns_configuration_changed(service);
3895 if (__connman_service_is_connected_state(service,
3896 CONNMAN_IPCONFIG_TYPE_IPV4))
3897 __connman_wispr_start(service,
3898 CONNMAN_IPCONFIG_TYPE_IPV4);
3900 if (__connman_service_is_connected_state(service,
3901 CONNMAN_IPCONFIG_TYPE_IPV6))
3902 __connman_wispr_start(service,
3903 CONNMAN_IPCONFIG_TYPE_IPV6);
3905 service_save(service);
3906 } else if (g_str_equal(name, "Timeservers.Configuration")) {
3907 DBusMessageIter entry;
3908 GSList *list = NULL;
3911 if (service->immutable)
3912 return __connman_error_not_supported(msg);
3914 if (type != DBUS_TYPE_ARRAY)
3915 return __connman_error_invalid_arguments(msg);
3917 dbus_message_iter_recurse(&value, &entry);
3919 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
3923 dbus_message_iter_get_basic(&entry, &val);
3925 new_head = __connman_timeserver_add_list(list, val);
3926 if (list != new_head) {
3931 dbus_message_iter_next(&entry);
3934 g_strfreev(service->timeservers_config);
3935 service->timeservers_config = NULL;
3938 service->timeservers_config = g_new0(char *, count+1);
3942 service->timeservers_config[count] = list->data;
3943 list = g_slist_delete_link(list, list);
3947 service_save(service);
3948 timeservers_configuration_changed(service);
3950 if (service == __connman_service_get_default())
3951 __connman_timeserver_sync(service);
3953 } else if (g_str_equal(name, "Domains.Configuration")) {
3954 DBusMessageIter entry;
3957 if (service->immutable)
3958 return __connman_error_not_supported(msg);
3960 if (type != DBUS_TYPE_ARRAY)
3961 return __connman_error_invalid_arguments(msg);
3963 str = g_string_new(NULL);
3965 return __connman_error_invalid_arguments(msg);
3967 dbus_message_iter_recurse(&value, &entry);
3969 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
3971 dbus_message_iter_get_basic(&entry, &val);
3972 dbus_message_iter_next(&entry);
3974 g_string_append_printf(str, " %s", val);
3976 g_string_append(str, val);
3979 searchdomain_remove_all(service);
3980 g_strfreev(service->domains);
3983 service->domains = g_strsplit_set(str->str, " ", 0);
3985 service->domains = NULL;
3987 g_string_free(str, TRUE);
3989 searchdomain_add_all(service);
3990 domain_configuration_changed(service);
3991 domain_changed(service);
3993 service_save(service);
3994 } else if (g_str_equal(name, "Proxy.Configuration")) {
3997 if (service->immutable)
3998 return __connman_error_not_supported(msg);
4000 if (type != DBUS_TYPE_ARRAY)
4001 return __connman_error_invalid_arguments(msg);
4003 err = update_proxy_configuration(service, &value);
4006 return __connman_error_failed(msg, -err);
4008 proxy_configuration_changed(service);
4010 __connman_notifier_proxy_changed(service);
4012 service_save(service);
4013 } else if (g_str_equal(name, "IPv4.Configuration") ||
4014 g_str_equal(name, "IPv6.Configuration")) {
4016 enum connman_service_state state =
4017 CONNMAN_SERVICE_STATE_UNKNOWN;
4018 enum connman_ipconfig_type type =
4019 CONNMAN_IPCONFIG_TYPE_UNKNOWN;
4022 if (service->type == CONNMAN_SERVICE_TYPE_VPN ||
4024 return __connman_error_not_supported(msg);
4028 if (!service->ipconfig_ipv4 &&
4029 !service->ipconfig_ipv6)
4030 return __connman_error_invalid_property(msg);
4032 if (g_str_equal(name, "IPv4.Configuration"))
4033 type = CONNMAN_IPCONFIG_TYPE_IPV4;
4035 type = CONNMAN_IPCONFIG_TYPE_IPV6;
4037 err = __connman_service_reset_ipconfig(service, type, &value,
4041 if (is_connected_state(service, state) ||
4042 is_connecting_state(service, state)) {
4043 __connman_network_enable_ipconfig(service->network,
4044 service->ipconfig_ipv4);
4045 __connman_network_enable_ipconfig(service->network,
4046 service->ipconfig_ipv6);
4049 return __connman_error_failed(msg, -err);
4052 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4053 ipv4_configuration_changed(service);
4055 ipv6_configuration_changed(service);
4057 if (is_connecting(service) || is_connected(service)) {
4058 __connman_network_enable_ipconfig(service->network,
4059 service->ipconfig_ipv4);
4060 __connman_network_enable_ipconfig(service->network,
4061 service->ipconfig_ipv6);
4064 service_save(service);
4066 return __connman_error_invalid_property(msg);
4068 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4071 static void set_error(struct connman_service *service,
4072 enum connman_service_error error)
4076 if (service->error == error)
4079 service->error = error;
4084 if (!allow_property_changed(service))
4087 str = error2string(service->error);
4092 connman_dbus_property_changed_basic(service->path,
4093 CONNMAN_SERVICE_INTERFACE, "Error",
4094 DBUS_TYPE_STRING, &str);
4097 static void set_idle(struct connman_service *service)
4099 service->state = service->state_ipv4 = service->state_ipv6 =
4100 CONNMAN_SERVICE_STATE_IDLE;
4101 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4102 state_changed(service);
4105 static DBusMessage *clear_property(DBusConnection *conn,
4106 DBusMessage *msg, void *user_data)
4108 struct connman_service *service = user_data;
4111 DBG("service %p", service);
4113 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
4116 if (g_str_equal(name, "Error")) {
4117 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
4119 g_get_current_time(&service->modified);
4120 service_save(service);
4122 return __connman_error_invalid_property(msg);
4124 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4127 static bool is_ipconfig_usable(struct connman_service *service)
4129 if (!__connman_ipconfig_is_usable(service->ipconfig_ipv4) &&
4130 !__connman_ipconfig_is_usable(service->ipconfig_ipv6))
4136 static bool is_ignore(struct connman_service *service)
4138 if (!service->autoconnect)
4141 if (service->roaming)
4144 if (service->ignore)
4147 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
4150 if (!is_ipconfig_usable(service))
4156 static void disconnect_on_last_session(enum connman_service_type type)
4160 for (list = service_list; list; list = list->next) {
4161 struct connman_service *service = list->data;
4163 if (service->type != type)
4166 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_SESSION)
4169 __connman_service_disconnect(service);
4174 static int active_sessions[MAX_CONNMAN_SERVICE_TYPES] = {};
4175 static int active_count = 0;
4177 void __connman_service_set_active_session(bool enable, GSList *list)
4187 while (list != NULL) {
4188 enum connman_service_type type = GPOINTER_TO_INT(list->data);
4191 case CONNMAN_SERVICE_TYPE_ETHERNET:
4192 case CONNMAN_SERVICE_TYPE_WIFI:
4193 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4194 case CONNMAN_SERVICE_TYPE_CELLULAR:
4195 case CONNMAN_SERVICE_TYPE_GADGET:
4197 active_sessions[type]++;
4199 active_sessions[type]--;
4202 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4203 case CONNMAN_SERVICE_TYPE_SYSTEM:
4204 case CONNMAN_SERVICE_TYPE_GPS:
4205 case CONNMAN_SERVICE_TYPE_VPN:
4206 case CONNMAN_SERVICE_TYPE_P2P:
4210 if (active_sessions[type] == 0)
4211 disconnect_on_last_session(type);
4213 list = g_slist_next(list);
4216 DBG("eth %d wifi %d bt %d cellular %d gadget %d sessions %d",
4217 active_sessions[CONNMAN_SERVICE_TYPE_ETHERNET],
4218 active_sessions[CONNMAN_SERVICE_TYPE_WIFI],
4219 active_sessions[CONNMAN_SERVICE_TYPE_BLUETOOTH],
4220 active_sessions[CONNMAN_SERVICE_TYPE_CELLULAR],
4221 active_sessions[CONNMAN_SERVICE_TYPE_GADGET],
4225 struct preferred_tech_data {
4226 GList *preferred_list;
4227 enum connman_service_type type;
4230 static void preferred_tech_add_by_type(gpointer data, gpointer user_data)
4232 struct connman_service *service = data;
4233 struct preferred_tech_data *tech_data = user_data;
4235 if (service->type == tech_data->type) {
4236 tech_data->preferred_list =
4237 g_list_append(tech_data->preferred_list, service);
4239 DBG("type %d service %p %s", tech_data->type, service,
4244 static GList *preferred_tech_list_get(void)
4246 unsigned int *tech_array;
4247 struct preferred_tech_data tech_data = { 0, };
4250 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
4254 if (connman_setting_get_bool("SingleConnectedTechnology")) {
4256 for (list = service_list; list; list = list->next) {
4257 struct connman_service *service = list->data;
4259 if (!is_connected(service))
4262 if (service->connect_reason ==
4263 CONNMAN_SERVICE_CONNECT_REASON_USER) {
4264 DBG("service %p name %s is user connected",
4265 service, service->name);
4266 #if defined TIZEN_EXT
4267 /* We can connect to a favorite service like
4268 * wifi even we have a userconnect for cellular
4269 * because we have refount for cellular service
4271 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
4274 if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
4282 for (i = 0; tech_array[i] != 0; i += 1) {
4283 tech_data.type = tech_array[i];
4284 g_list_foreach(service_list, preferred_tech_add_by_type,
4288 return tech_data.preferred_list;
4291 static bool auto_connect_service(GList *services,
4292 enum connman_service_connect_reason reason,
4295 struct connman_service *service = NULL;
4296 bool ignore[MAX_CONNMAN_SERVICE_TYPES] = { };
4297 bool autoconnecting = false;
4300 DBG("preferred %d sessions %d reason %s", preferred, active_count,
4301 reason2string(reason));
4303 ignore[CONNMAN_SERVICE_TYPE_VPN] = true;
4305 for (list = services; list; list = list->next) {
4306 service = list->data;
4308 if (ignore[service->type]) {
4309 DBG("service %p type %s ignore", service,
4310 __connman_service_type2string(service->type));
4314 #if defined TIZEN_EXT
4315 DBG("service %p %s %s %s, favorite(%d), ignore(%d), hidden(%d, %d)",
4316 service, service->name,
4317 state2string(service->state),
4318 __connman_service_type2string(service->type),
4319 service->favorite, is_ignore(service),
4320 service->hidden, service->hidden_service);
4322 /* Tizen takes Wi-Fi as the highest priority into consideration. */
4323 if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
4324 if (is_connecting(service) == TRUE || is_connected(service) == TRUE)
4328 if (service->pending ||
4329 is_connecting(service) ||
4330 is_connected(service)) {
4334 ignore[service->type] = true;
4335 autoconnecting = true;
4337 DBG("service %p type %s busy", service,
4338 __connman_service_type2string(service->type));
4343 if (!service->favorite) {
4347 return autoconnecting;
4350 if (is_ignore(service) || service->state !=
4351 CONNMAN_SERVICE_STATE_IDLE)
4354 if (autoconnecting && !active_sessions[service->type]) {
4355 DBG("service %p type %s has no users", service,
4356 __connman_service_type2string(service->type));
4360 if (!is_service_owner_user_login(service)) {
4361 DBG("favorite user not login, wifi auto connect denied");
4365 DBG("service %p %s %s", service, service->name,
4366 (preferred) ? "preferred" : reason2string(reason));
4368 __connman_service_connect(service, reason);
4373 ignore[service->type] = true;
4376 return autoconnecting;
4379 static gboolean run_auto_connect(gpointer data)
4381 enum connman_service_connect_reason reason = GPOINTER_TO_UINT(data);
4382 bool autoconnecting = false;
4383 GList *preferred_tech;
4385 autoconnect_timeout = 0;
4389 preferred_tech = preferred_tech_list_get();
4390 if (preferred_tech) {
4391 autoconnecting = auto_connect_service(preferred_tech, reason,
4393 g_list_free(preferred_tech);
4396 if (!autoconnecting || active_count)
4397 auto_connect_service(service_list, reason, false);
4402 void __connman_service_auto_connect(enum connman_service_connect_reason reason)
4406 if (autoconnect_timeout != 0)
4409 if (!__connman_session_policy_autoconnect(reason))
4412 #if defined TIZEN_EXT
4413 /* Adding Timeout of 500ms before trying to auto connect.
4414 * This is done because of below scenario
4415 * 1. Device is connected to AP1
4416 * 2. WPS Connection request is initiated for AP2
4417 * 3. Immediately WPS Connection is Cancelled
4418 * When WPS Connection Connection is initiated for AP2 then
4419 * sometimes there is a scenario where connman gets in ASSOCIATED
4420 * state with AP1 due to autoconnect and subsequently the connection
4421 * initiated by AP1 fails and connman service for AP1 comes in
4422 * FAILURE state due to this when connection with AP2 is cancelled
4423 * then autoconnect with AP1 doesn't works because its autoconnection
4424 * is ignored as its last state was FAILURE rather than IDLE */
4425 autoconnect_timeout = g_timeout_add(500, run_auto_connect,
4427 autoconnect_timeout = g_timeout_add_seconds(0, run_auto_connect,
4429 GUINT_TO_POINTER(reason));
4432 static gboolean run_vpn_auto_connect(gpointer data) {
4434 bool need_split = false;
4436 vpn_autoconnect_timeout = 0;
4438 for (list = service_list; list; list = list->next) {
4439 struct connman_service *service = list->data;
4442 if (service->type != CONNMAN_SERVICE_TYPE_VPN)
4445 if (is_connected(service) || is_connecting(service)) {
4446 if (!service->do_split_routing)
4451 if (is_ignore(service) || !service->favorite)
4454 if (need_split && !service->do_split_routing) {
4455 DBG("service %p no split routing", service);
4459 DBG("service %p %s %s", service, service->name,
4460 service->do_split_routing ?
4461 "split routing" : "");
4463 res = __connman_service_connect(service,
4464 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4465 if (res < 0 && res != -EINPROGRESS)
4468 if (!service->do_split_routing)
4475 static void vpn_auto_connect(void)
4477 if (vpn_autoconnect_timeout)
4480 vpn_autoconnect_timeout =
4481 g_timeout_add_seconds(0, run_vpn_auto_connect, NULL);
4484 static void remove_timeout(struct connman_service *service)
4486 if (service->timeout > 0) {
4487 g_source_remove(service->timeout);
4488 service->timeout = 0;
4492 static void reply_pending(struct connman_service *service, int error)
4494 remove_timeout(service);
4496 if (service->pending) {
4497 connman_dbus_reply_pending(service->pending, error, NULL);
4498 service->pending = NULL;
4501 if (service->provider_pending) {
4502 connman_dbus_reply_pending(service->provider_pending,
4503 error, service->path);
4504 service->provider_pending = NULL;
4509 __connman_service_is_provider_pending(struct connman_service *service)
4514 if (service->provider_pending)
4520 void __connman_service_set_provider_pending(struct connman_service *service,
4523 if (service->provider_pending) {
4524 DBG("service %p provider pending msg %p already exists",
4525 service, service->provider_pending);
4529 service->provider_pending = msg;
4533 static void check_pending_msg(struct connman_service *service)
4535 if (!service->pending)
4538 DBG("service %p pending msg %p already exists", service,
4540 dbus_message_unref(service->pending);
4543 void __connman_service_set_hidden_data(struct connman_service *service,
4546 DBusMessage *pending = user_data;
4548 DBG("service %p pending %p", service, pending);
4553 check_pending_msg(service);
4555 service->pending = pending;
4558 void __connman_service_return_error(struct connman_service *service,
4559 int error, gpointer user_data)
4561 DBG("service %p error %d user_data %p", service, error, user_data);
4563 __connman_service_set_hidden_data(service, user_data);
4565 reply_pending(service, error);
4568 static gboolean connect_timeout(gpointer user_data)
4570 struct connman_service *service = user_data;
4571 bool autoconnect = false;
4573 DBG("service %p", service);
4575 service->timeout = 0;
4577 if (service->network)
4578 __connman_network_disconnect(service->network);
4579 else if (service->provider)
4580 connman_provider_disconnect(service->provider);
4582 __connman_ipconfig_disable(service->ipconfig_ipv4);
4583 __connman_ipconfig_disable(service->ipconfig_ipv6);
4585 __connman_stats_service_unregister(service);
4587 if (service->pending) {
4590 reply = __connman_error_operation_timeout(service->pending);
4592 g_dbus_send_message(connection, reply);
4594 dbus_message_unref(service->pending);
4595 service->pending = NULL;
4599 __connman_service_ipconfig_indicate_state(service,
4600 CONNMAN_SERVICE_STATE_FAILURE,
4601 CONNMAN_IPCONFIG_TYPE_IPV4);
4602 __connman_service_ipconfig_indicate_state(service,
4603 CONNMAN_SERVICE_STATE_FAILURE,
4604 CONNMAN_IPCONFIG_TYPE_IPV6);
4607 service->connect_reason !=
4608 CONNMAN_SERVICE_CONNECT_REASON_USER)
4609 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
4614 static DBusMessage *connect_service(DBusConnection *conn,
4615 DBusMessage *msg, void *user_data)
4617 struct connman_service *service = user_data;
4621 DBG("service %p", service);
4623 #if defined TIZEN_EXT
4625 * Description: TIZEN implements system global connection management.
4627 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
4628 connman_service_user_pdn_connection_ref(service);
4631 if (service->pending)
4632 return __connman_error_in_progress(msg);
4634 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
4636 if (connman_dbus_get_connection_unix_user_sync(conn,
4637 dbus_message_get_sender(msg),
4639 DBG("Can not get unix user id!");
4640 return __connman_error_permission_denied(msg);
4643 if (!__connman_service_is_user_allowed(CONNMAN_SERVICE_TYPE_WIFI, uid)) {
4644 DBG("Not allow this user to connect this wifi service now!");
4645 return __connman_error_permission_denied(msg);
4648 if (uid != USER_ROOT && uid != service->user.favorite_user)
4649 service->request_passphrase_input = true;
4651 service->user.current_user = uid;
4653 if (!service->passphrase && uid == service->user.favorite_user) {
4654 DBG("Now load this favorite user's passphrase.");
4655 service_load_passphrase(service);
4659 index = __connman_service_get_index(service);
4661 for (list = service_list; list; list = list->next) {
4662 struct connman_service *temp = list->data;
4664 #if defined TIZEN_EXT
4665 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
4668 if (!is_connecting(temp) && !is_connected(temp))
4671 if (service == temp)
4674 if (service->type != temp->type)
4677 if (__connman_service_get_index(temp) == index &&
4678 __connman_service_disconnect(temp) == -EINPROGRESS)
4682 if (err == -EINPROGRESS)
4683 return __connman_error_operation_timeout(msg);
4685 service->ignore = false;
4687 service->pending = dbus_message_ref(msg);
4689 err = __connman_service_connect(service,
4690 CONNMAN_SERVICE_CONNECT_REASON_USER);
4692 if (err == -EINPROGRESS)
4695 if (service->pending) {
4696 dbus_message_unref(service->pending);
4697 service->pending = NULL;
4701 return __connman_error_failed(msg, -err);
4703 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4706 static DBusMessage *disconnect_service(DBusConnection *conn,
4707 DBusMessage *msg, void *user_data)
4709 struct connman_service *service = user_data;
4712 DBG("service %p", service);
4714 #if defined TIZEN_EXT
4716 * Description: TIZEN implements system global connection management.
4718 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
4719 if (connman_service_user_pdn_connection_unref_and_test(service) != TRUE)
4720 return __connman_error_failed(msg, EISCONN);
4722 if (is_connected(service) == TRUE &&
4723 service == connman_service_get_default_connection())
4724 return __connman_error_failed(msg, EISCONN);
4728 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
4730 if (connman_dbus_get_connection_unix_user_sync(conn,
4731 dbus_message_get_sender(msg),
4733 DBG("Can not get unix user id!");
4734 return __connman_error_permission_denied(msg);
4737 if (!connman_service_is_user_allowed(service, uid)) {
4738 DBG("Not allow this user to disconnect this wifi service now!");
4739 return __connman_error_permission_denied(msg);
4743 service->ignore = true;
4745 err = __connman_service_disconnect(service);
4746 if (err < 0 && err != -EINPROGRESS)
4747 return __connman_error_failed(msg, -err);
4749 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4752 #if defined TIZEN_EXT
4753 static void __connman_service_cleanup_network_8021x(struct connman_service *service)
4755 if (service == NULL)
4758 DBG("service %p ", service);
4760 connman_network_set_string(service->network, "WiFi.EAP", NULL);
4761 connman_network_set_string(service->network, "WiFi.Identity", NULL);
4762 connman_network_set_string(service->network, "WiFi.CACertFile", NULL);
4763 connman_network_set_string(service->network, "WiFi.ClientCertFile", NULL);
4764 connman_network_set_string(service->network, "WiFi.PrivateKeyFile", NULL);
4765 connman_network_set_string(service->network, "WiFi.PrivateKeyPassphrase", NULL);
4766 connman_network_set_string(service->network, "WiFi.Phase2", NULL);
4770 bool __connman_service_remove(struct connman_service *service)
4772 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET ||
4773 service->type == CONNMAN_SERVICE_TYPE_GADGET)
4776 if (service->immutable || service->hidden ||
4777 __connman_provider_is_immutable(service->provider))
4780 if (!service->favorite && service->state !=
4781 CONNMAN_SERVICE_STATE_FAILURE)
4784 __connman_service_disconnect(service);
4786 g_free(service->passphrase);
4787 service->passphrase = NULL;
4789 g_free(service->identity);
4790 service->identity = NULL;
4792 g_free(service->agent_identity);
4793 service->agent_identity = NULL;
4795 g_free(service->eap);
4796 service->eap = NULL;
4798 #if defined TIZEN_EXT
4799 g_free(service->ca_cert_file);
4800 service->ca_cert_file = NULL;
4802 g_free(service->client_cert_file);
4803 service->client_cert_file = NULL;
4805 g_free(service->private_key_file);
4806 service->private_key_file = NULL;
4808 g_free(service->private_key_passphrase);
4809 service->private_key_passphrase = NULL;
4811 g_free(service->phase2);
4812 service->phase2 = NULL;
4814 __connman_service_cleanup_network_8021x(service);
4816 __connman_ipconfig_set_method(service->ipconfig_ipv4, CONNMAN_IPCONFIG_METHOD_DHCP);
4817 __connman_ipconfig_set_method(service->ipconfig_ipv6, CONNMAN_IPCONFIG_METHOD_AUTO);
4818 connman_service_set_proxy(service, NULL, false);
4820 __connman_service_nameserver_clear(service);
4822 g_strfreev(service->nameservers_config);
4823 service->nameservers_config = NULL;
4827 #if defined TIZEN_EXT
4828 if (service->security != CONNMAN_SERVICE_SECURITY_8021X)
4832 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
4834 service->user.favorite_user = USER_NONE;
4836 __connman_service_set_favorite(service, false);
4838 __connman_ipconfig_ipv6_reset_privacy(service->ipconfig_ipv6);
4840 #if defined TIZEN_EXT
4841 __connman_storage_remove_service(service->identifier);
4843 service_save(service);
4849 static DBusMessage *remove_service(DBusConnection *conn,
4850 DBusMessage *msg, void *user_data)
4852 struct connman_service *service = user_data;
4854 DBG("service %p", service);
4856 if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
4858 if (connman_dbus_get_connection_unix_user_sync(conn,
4859 dbus_message_get_sender(msg),
4861 DBG("Can not get unix user id!");
4862 return __connman_error_permission_denied(msg);
4865 #if !defined TIZEN_EXT
4866 if (!connman_service_is_user_allowed(service, uid)) {
4867 DBG("Not allow this user to remove this wifi service now!");
4868 return __connman_error_permission_denied(msg);
4873 if (!__connman_service_remove(service))
4874 return __connman_error_not_supported(msg);
4876 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
4879 static bool check_suitable_state(enum connman_service_state a,
4880 enum connman_service_state b)
4883 * Special check so that "ready" service can be moved before
4886 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
4887 b == CONNMAN_SERVICE_STATE_READY) ||
4888 (b == CONNMAN_SERVICE_STATE_ONLINE &&
4889 a == CONNMAN_SERVICE_STATE_READY))
4895 static void downgrade_state(struct connman_service *service)
4900 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
4901 service->state_ipv6);
4903 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
4904 __connman_service_ipconfig_indicate_state(service,
4905 CONNMAN_SERVICE_STATE_READY,
4906 CONNMAN_IPCONFIG_TYPE_IPV4);
4908 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
4909 __connman_service_ipconfig_indicate_state(service,
4910 CONNMAN_SERVICE_STATE_READY,
4911 CONNMAN_IPCONFIG_TYPE_IPV6);
4914 static void apply_relevant_default_downgrade(struct connman_service *service)
4916 struct connman_service *def_service;
4918 def_service = __connman_service_get_default();
4922 if (def_service == service &&
4923 def_service->state == CONNMAN_SERVICE_STATE_ONLINE) {
4924 def_service->state = CONNMAN_SERVICE_STATE_READY;
4925 __connman_notifier_leave_online(def_service->type);
4926 state_changed(def_service);
4930 static void switch_default_service(struct connman_service *default_service,
4931 struct connman_service *downgrade_service)
4933 struct connman_service *service;
4936 apply_relevant_default_downgrade(default_service);
4937 src = g_list_find(service_list, downgrade_service);
4938 dst = g_list_find(service_list, default_service);
4941 if (src == dst || src->next == dst)
4944 service = src->data;
4945 service_list = g_list_delete_link(service_list, src);
4946 service_list = g_list_insert_before(service_list, dst, service);
4948 downgrade_state(downgrade_service);
4951 static DBusMessage *move_service(DBusConnection *conn,
4952 DBusMessage *msg, void *user_data,
4955 struct connman_service *service = user_data;
4956 struct connman_service *target;
4958 enum connman_ipconfig_method target4, target6;
4959 enum connman_ipconfig_method service4, service6;
4961 DBG("service %p", service);
4963 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
4966 if (!service->favorite)
4967 return __connman_error_not_supported(msg);
4969 target = find_service(path);
4970 if (!target || !target->favorite || target == service)
4971 return __connman_error_invalid_service(msg);
4973 if (target->type == CONNMAN_SERVICE_TYPE_VPN) {
4975 * We only allow VPN route splitting if there are
4976 * routes defined for a given VPN.
4978 if (!__connman_provider_check_routes(target->provider)) {
4979 connman_info("Cannot move service. "
4980 "No routes defined for provider %s",
4981 __connman_provider_get_ident(target->provider));
4982 return __connman_error_invalid_service(msg);
4985 target->do_split_routing = true;
4987 target->do_split_routing = false;
4989 service->do_split_routing = false;
4991 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
4992 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
4993 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
4994 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
4996 DBG("target %s method %d/%d state %d/%d split %d", target->identifier,
4997 target4, target6, target->state_ipv4, target->state_ipv6,
4998 target->do_split_routing);
5000 DBG("service %s method %d/%d state %d/%d", service->identifier,
5002 service->state_ipv4, service->state_ipv6);
5005 * If method is OFF, then we do not need to check the corresponding
5008 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5009 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5010 if (!check_suitable_state(target->state_ipv6,
5011 service->state_ipv6))
5012 return __connman_error_invalid_service(msg);
5016 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5017 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5018 if (!check_suitable_state(target->state_ipv4,
5019 service->state_ipv4))
5020 return __connman_error_invalid_service(msg);
5024 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
5025 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
5026 if (!check_suitable_state(target->state_ipv6,
5027 service->state_ipv6))
5028 return __connman_error_invalid_service(msg);
5032 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
5033 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
5034 if (!check_suitable_state(target->state_ipv4,
5035 service->state_ipv4))
5036 return __connman_error_invalid_service(msg);
5040 g_get_current_time(&service->modified);
5041 service_save(service);
5042 service_save(target);
5045 * If the service which goes down is the default service and is
5046 * online, we downgrade directly its state to ready so:
5047 * the service which goes up, needs to recompute its state which
5048 * is triggered via downgrading it - if relevant - to state ready.
5051 switch_default_service(target, service);
5053 switch_default_service(service, target);
5055 __connman_connection_update_gateway();
5057 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5060 static DBusMessage *move_before(DBusConnection *conn,
5061 DBusMessage *msg, void *user_data)
5063 return move_service(conn, msg, user_data, true);
5066 static DBusMessage *move_after(DBusConnection *conn,
5067 DBusMessage *msg, void *user_data)
5069 return move_service(conn, msg, user_data, false);
5072 static DBusMessage *reset_counters(DBusConnection *conn,
5073 DBusMessage *msg, void *user_data)
5075 struct connman_service *service = user_data;
5077 reset_stats(service);
5079 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5082 static DBusMessage *get_user_favorite(DBusConnection *conn,
5083 DBusMessage *msg, void *user_data)
5086 uid_t uid = USER_NONE;
5087 dbus_bool_t user_favorite = false;
5088 struct connman_service *service = user_data;
5090 connman_dbus_get_connection_unix_user_sync(conn,
5091 dbus_message_get_sender(msg),
5093 if (uid == USER_ROOT)
5094 user_favorite = service->favorite;
5095 else if (uid != USER_NONE && uid == service->user.favorite_user) {
5096 DBG("The service is favorite to this user!");
5097 user_favorite = true;
5100 reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
5101 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN,
5102 &user_favorite, DBUS_TYPE_INVALID);
5106 static struct _services_notify {
5112 static void service_append_added_foreach(gpointer data, gpointer user_data)
5114 struct connman_service *service = data;
5115 DBusMessageIter *iter = user_data;
5117 if (!service || !service->path) {
5118 DBG("service %p or path is NULL", service);
5122 if (g_hash_table_lookup(services_notify->add, service->path)) {
5123 DBG("new %s", service->path);
5125 append_struct(service, iter);
5126 g_hash_table_remove(services_notify->add, service->path);
5128 DBG("changed %s", service->path);
5130 append_struct_service(iter, NULL, service);
5134 static void service_append_ordered(DBusMessageIter *iter, void *user_data)
5136 g_list_foreach(service_list, service_append_added_foreach, iter);
5139 static void append_removed(gpointer key, gpointer value, gpointer user_data)
5141 char *objpath = key;
5142 DBusMessageIter *iter = user_data;
5144 DBG("removed %s", objpath);
5145 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath);
5148 static void service_append_removed(DBusMessageIter *iter, void *user_data)
5150 g_hash_table_foreach(services_notify->remove, append_removed, iter);
5153 static gboolean service_send_changed(gpointer data)
5155 DBusMessage *signal;
5159 services_notify->id = 0;
5161 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
5162 CONNMAN_MANAGER_INTERFACE, "ServicesChanged");
5166 __connman_dbus_append_objpath_dict_array(signal,
5167 service_append_ordered, NULL);
5168 __connman_dbus_append_objpath_array(signal,
5169 service_append_removed, NULL);
5171 dbus_connection_send(connection, signal, NULL);
5172 dbus_message_unref(signal);
5174 g_hash_table_remove_all(services_notify->remove);
5175 g_hash_table_remove_all(services_notify->add);
5180 static void service_schedule_changed(void)
5182 if (services_notify->id != 0)
5185 services_notify->id = g_timeout_add(100, service_send_changed, NULL);
5188 static void service_schedule_added(struct connman_service *service)
5190 DBG("service %p", service);
5192 g_hash_table_remove(services_notify->remove, service->path);
5193 g_hash_table_replace(services_notify->add, service->path, service);
5195 service_schedule_changed();
5198 static void service_schedule_removed(struct connman_service *service)
5200 if (!service || !service->path) {
5201 DBG("service %p or path is NULL", service);
5205 DBG("service %p %s", service, service->path);
5207 g_hash_table_remove(services_notify->add, service->path);
5208 g_hash_table_replace(services_notify->remove, g_strdup(service->path),
5211 service_schedule_changed();
5214 static bool allow_property_changed(struct connman_service *service)
5216 #if defined TIZEN_EXT
5217 if (service->path == NULL)
5220 if (g_hash_table_lookup_extended(services_notify->add, service->path,
5222 DBG("no property updates for service %p", service);
5229 static const GDBusMethodTable service_methods[] = {
5230 { GDBUS_DEPRECATED_METHOD("GetProperties",
5231 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
5233 { GDBUS_METHOD("SetProperty",
5234 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
5235 NULL, set_property) },
5236 { GDBUS_METHOD("ClearProperty",
5237 GDBUS_ARGS({ "name", "s" }), NULL,
5239 { GDBUS_ASYNC_METHOD("Connect", NULL, NULL,
5241 { GDBUS_METHOD("Disconnect", NULL, NULL,
5242 disconnect_service) },
5243 { GDBUS_METHOD("Remove", NULL, NULL, remove_service) },
5244 { GDBUS_METHOD("MoveBefore",
5245 GDBUS_ARGS({ "service", "o" }), NULL,
5247 { GDBUS_METHOD("MoveAfter",
5248 GDBUS_ARGS({ "service", "o" }), NULL,
5250 { GDBUS_METHOD("ResetCounters", NULL, NULL, reset_counters) },
5251 { GDBUS_METHOD("GetUserFavorite",
5252 NULL, GDBUS_ARGS({ "value", "v" }),
5253 get_user_favorite) },
5257 static const GDBusSignalTable service_signals[] = {
5258 { GDBUS_SIGNAL("PropertyChanged",
5259 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
5263 static void service_free(gpointer user_data)
5265 struct connman_service *service = user_data;
5266 char *path = service->path;
5268 DBG("service %p", service);
5270 reply_pending(service, ENOENT);
5272 __connman_notifier_service_remove(service);
5273 service_schedule_removed(service);
5275 __connman_wispr_stop(service);
5276 stats_stop(service);
5278 service->path = NULL;
5281 __connman_connection_update_gateway();
5283 g_dbus_unregister_interface(connection, path,
5284 CONNMAN_SERVICE_INTERFACE);
5288 g_hash_table_destroy(service->counter_table);
5290 if (service->network) {
5291 __connman_network_disconnect(service->network);
5292 connman_network_unref(service->network);
5293 service->network = NULL;
5296 if (service->provider)
5297 connman_provider_unref(service->provider);
5299 if (service->ipconfig_ipv4) {
5300 __connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
5301 __connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
5302 __connman_ipconfig_unref(service->ipconfig_ipv4);
5303 service->ipconfig_ipv4 = NULL;
5306 if (service->ipconfig_ipv6) {
5307 __connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
5308 __connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
5309 __connman_ipconfig_unref(service->ipconfig_ipv6);
5310 service->ipconfig_ipv6 = NULL;
5313 g_strfreev(service->timeservers);
5314 g_strfreev(service->timeservers_config);
5315 g_strfreev(service->nameservers);
5316 g_strfreev(service->nameservers_config);
5317 g_strfreev(service->nameservers_auto);
5318 g_strfreev(service->domains);
5319 g_strfreev(service->proxies);
5320 g_strfreev(service->excludes);
5322 g_free(service->hostname);
5323 g_free(service->domainname);
5324 g_free(service->pac);
5325 g_free(service->name);
5326 g_free(service->passphrase);
5327 g_free(service->identifier);
5328 g_free(service->eap);
5329 g_free(service->identity);
5330 g_free(service->agent_identity);
5331 g_free(service->ca_cert_file);
5332 g_free(service->client_cert_file);
5333 g_free(service->private_key_file);
5334 g_free(service->private_key_passphrase);
5335 g_free(service->phase2);
5336 g_free(service->config_file);
5337 g_free(service->config_entry);
5339 if (service->stats.timer)
5340 g_timer_destroy(service->stats.timer);
5341 if (service->stats_roaming.timer)
5342 g_timer_destroy(service->stats_roaming.timer);
5344 if (current_default == service)
5345 current_default = NULL;
5350 static void stats_init(struct connman_service *service)
5353 service->stats.valid = false;
5354 service->stats.enabled = false;
5355 service->stats.timer = g_timer_new();
5358 service->stats_roaming.valid = false;
5359 service->stats_roaming.enabled = false;
5360 service->stats_roaming.timer = g_timer_new();
5363 static void service_initialize(struct connman_service *service)
5365 DBG("service %p", service);
5367 service->refcount = 1;
5369 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
5371 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
5372 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
5374 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
5375 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
5376 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
5378 service->favorite = false;
5379 service->immutable = false;
5380 service->hidden = false;
5382 service->ignore = false;
5384 service->user.favorite_user = USER_NONE;
5385 service->user.current_user = USER_NONE;
5387 service->request_passphrase_input = false;
5389 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
5393 stats_init(service);
5395 service->provider = NULL;
5397 service->wps = false;
5398 #if defined TIZEN_EXT
5399 service->storage_reload = false;
5401 * Description: TIZEN implements system global connection management.
5403 service->user_pdn_connection_refcount = 0;
5404 __sync_synchronize();
5409 * connman_service_create:
5411 * Allocate a new service.
5413 * Returns: a newly-allocated #connman_service structure
5415 struct connman_service *connman_service_create(void)
5418 struct connman_stats_counter *counters;
5419 const char *counter;
5421 struct connman_service *service;
5423 service = g_try_new0(struct connman_service, 1);
5427 DBG("service %p", service);
5429 service->counter_table = g_hash_table_new_full(g_str_hash,
5430 g_str_equal, NULL, g_free);
5432 for (list = counter_list; list; list = list->next) {
5433 counter = list->data;
5435 counters = g_try_new0(struct connman_stats_counter, 1);
5437 g_hash_table_destroy(service->counter_table);
5442 counters->append_all = true;
5444 g_hash_table_replace(service->counter_table, (gpointer)counter,
5448 service_initialize(service);
5454 * connman_service_ref:
5455 * @service: service structure
5457 * Increase reference counter of service
5459 struct connman_service *
5460 connman_service_ref_debug(struct connman_service *service,
5461 const char *file, int line, const char *caller)
5463 DBG("%p ref %d by %s:%d:%s()", service, service->refcount + 1,
5464 file, line, caller);
5466 __sync_fetch_and_add(&service->refcount, 1);
5472 * connman_service_unref:
5473 * @service: service structure
5475 * Decrease reference counter of service and release service if no
5478 void connman_service_unref_debug(struct connman_service *service,
5479 const char *file, int line, const char *caller)
5481 DBG("%p ref %d by %s:%d:%s()", service, service->refcount - 1,
5482 file, line, caller);
5484 if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
5487 service_list = g_list_remove(service_list, service);
5489 __connman_service_disconnect(service);
5491 g_hash_table_remove(service_hash, service->identifier);
5494 static gint service_compare(gconstpointer a, gconstpointer b)
5496 struct connman_service *service_a = (void *) a;
5497 struct connman_service *service_b = (void *) b;
5498 enum connman_service_state state_a, state_b;
5499 bool a_connected, b_connected;
5502 state_a = service_a->state;
5503 state_b = service_b->state;
5504 a_connected = is_connected(service_a);
5505 b_connected = is_connected(service_b);
5507 if (a_connected && b_connected) {
5508 if (service_a->order > service_b->order)
5511 if (service_a->order < service_b->order)
5515 if (state_a != state_b) {
5516 if (a_connected && b_connected) {
5517 /* We prefer online over ready state */
5518 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
5521 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
5530 if (is_connecting(service_a))
5532 if (is_connecting(service_b))
5536 if (service_a->favorite && !service_b->favorite)
5539 if (!service_a->favorite && service_b->favorite)
5542 if (service_a->type != service_b->type) {
5544 if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
5546 if (service_b->type == CONNMAN_SERVICE_TYPE_ETHERNET)
5549 if (service_a->type == CONNMAN_SERVICE_TYPE_WIFI)
5551 if (service_b->type == CONNMAN_SERVICE_TYPE_WIFI)
5554 if (service_a->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5556 if (service_b->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5559 if (service_a->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
5561 if (service_b->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
5564 if (service_a->type == CONNMAN_SERVICE_TYPE_VPN)
5566 if (service_b->type == CONNMAN_SERVICE_TYPE_VPN)
5569 if (service_a->type == CONNMAN_SERVICE_TYPE_GADGET)
5571 if (service_b->type == CONNMAN_SERVICE_TYPE_GADGET)
5575 strength = (gint) service_b->strength - (gint) service_a->strength;
5579 return g_strcmp0(service_a->name, service_b->name);
5582 static void service_list_sort(void)
5584 if (service_list && service_list->next) {
5585 service_list = g_list_sort(service_list, service_compare);
5586 service_schedule_changed();
5591 * connman_service_get_type:
5592 * @service: service structure
5594 * Get the type of service
5596 enum connman_service_type connman_service_get_type(struct connman_service *service)
5599 return CONNMAN_SERVICE_TYPE_UNKNOWN;
5601 return service->type;
5605 * connman_service_get_interface:
5606 * @service: service structure
5608 * Get network interface of service
5610 char *connman_service_get_interface(struct connman_service *service)
5617 index = __connman_service_get_index(service);
5619 return connman_inet_ifname(index);
5623 * __connman_service_is_user_allowed:
5624 * @type: service type
5627 * Check a user is allowed to operate a type of service
5629 bool __connman_service_is_user_allowed(enum connman_service_type type,
5633 uid_t owner_user = USER_NONE;
5635 for (list = service_list; list; list = list->next) {
5636 struct connman_service *service = list->data;
5638 if (service->type != type)
5641 if (is_connected(service)) {
5642 owner_user = service->user.favorite_user;
5647 if (uid == USER_NONE ||
5648 (uid != USER_ROOT &&
5649 owner_user != USER_NONE &&
5657 * connman_service_get_network:
5658 * @service: service structure
5660 * Get the service network
5662 struct connman_network *
5663 __connman_service_get_network(struct connman_service *service)
5668 return service->network;
5671 struct connman_ipconfig *
5672 __connman_service_get_ip4config(struct connman_service *service)
5677 return service->ipconfig_ipv4;
5680 struct connman_ipconfig *
5681 __connman_service_get_ip6config(struct connman_service *service)
5686 return service->ipconfig_ipv6;
5689 struct connman_ipconfig *
5690 __connman_service_get_ipconfig(struct connman_service *service, int family)
5692 if (family == AF_INET)
5693 return __connman_service_get_ip4config(service);
5694 else if (family == AF_INET6)
5695 return __connman_service_get_ip6config(service);
5701 bool __connman_service_is_connected_state(struct connman_service *service,
5702 enum connman_ipconfig_type type)
5708 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
5710 case CONNMAN_IPCONFIG_TYPE_IPV4:
5711 return is_connected_state(service, service->state_ipv4);
5712 case CONNMAN_IPCONFIG_TYPE_IPV6:
5713 return is_connected_state(service, service->state_ipv6);
5714 case CONNMAN_IPCONFIG_TYPE_ALL:
5715 return is_connected_state(service,
5716 CONNMAN_IPCONFIG_TYPE_IPV4) &&
5717 is_connected_state(service,
5718 CONNMAN_IPCONFIG_TYPE_IPV6);
5723 enum connman_service_security __connman_service_get_security(
5724 struct connman_service *service)
5727 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
5729 return service->security;
5732 const char *__connman_service_get_phase2(struct connman_service *service)
5737 return service->phase2;
5740 bool __connman_service_wps_enabled(struct connman_service *service)
5745 return service->wps;
5748 void __connman_service_mark_dirty(void)
5750 services_dirty = true;
5753 #if defined TIZEN_EXT
5755 * Returns profile count if there is any connected profiles
5756 * that use same interface
5758 int __connman_service_get_connected_count_of_iface(
5759 struct connman_service *service)
5768 index1 = __connman_service_get_index(service);
5773 for (list = service_list; list; list = list->next) {
5774 struct connman_service *service2 = list->data;
5776 if (service == service2)
5779 index2 = __connman_service_get_index(service2);
5781 if (is_connected(service2) && index2 > 0 && index1 == index2)
5787 DBG("Interface index %d, count %d", index1, count);
5792 void __connman_service_set_storage_reload(struct connman_service *service,
5793 bool storage_reload)
5795 if (service != NULL)
5796 service->storage_reload = storage_reload;
5801 * __connman_service_set_favorite_delayed:
5802 * @service: service structure
5803 * @favorite: favorite value
5804 * @delay_ordering: do not order service sequence
5806 * Change the favorite setting of service
5808 int __connman_service_set_favorite_delayed(struct connman_service *service,
5810 bool delay_ordering)
5812 #if defined TIZEN_EXT
5813 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
5816 if (service->hidden)
5819 if (service->favorite == favorite)
5822 service->favorite = favorite;
5824 if (!delay_ordering)
5825 __connman_service_get_order(service);
5827 favorite_changed(service);
5829 if (!delay_ordering) {
5831 service_list_sort();
5833 __connman_connection_update_gateway();
5840 * __connman_service_set_favorite:
5841 * @service: service structure
5842 * @favorite: favorite value
5844 * Change the favorite setting of service
5846 int __connman_service_set_favorite(struct connman_service *service,
5849 return __connman_service_set_favorite_delayed(service, favorite,
5853 bool connman_service_get_favorite(struct connman_service *service)
5855 return service->favorite;
5858 bool connman_service_get_autoconnect(struct connman_service *service)
5860 return service->autoconnect;
5863 int __connman_service_set_immutable(struct connman_service *service,
5866 if (service->hidden)
5869 if (service->immutable == immutable)
5872 service->immutable = immutable;
5874 immutable_changed(service);
5879 int __connman_service_set_ignore(struct connman_service *service,
5885 service->ignore = ignore;
5890 void __connman_service_set_string(struct connman_service *service,
5891 const char *key, const char *value)
5893 if (service->hidden)
5895 if (g_str_equal(key, "EAP")) {
5896 g_free(service->eap);
5897 service->eap = g_strdup(value);
5898 } else if (g_str_equal(key, "Identity")) {
5899 g_free(service->identity);
5900 service->identity = g_strdup(value);
5901 } else if (g_str_equal(key, "CACertFile")) {
5902 g_free(service->ca_cert_file);
5903 service->ca_cert_file = g_strdup(value);
5904 } else if (g_str_equal(key, "ClientCertFile")) {
5905 g_free(service->client_cert_file);
5906 service->client_cert_file = g_strdup(value);
5907 } else if (g_str_equal(key, "PrivateKeyFile")) {
5908 g_free(service->private_key_file);
5909 service->private_key_file = g_strdup(value);
5910 } else if (g_str_equal(key, "PrivateKeyPassphrase")) {
5911 g_free(service->private_key_passphrase);
5912 service->private_key_passphrase = g_strdup(value);
5913 } else if (g_str_equal(key, "Phase2")) {
5914 g_free(service->phase2);
5915 service->phase2 = g_strdup(value);
5916 } else if (g_str_equal(key, "Passphrase"))
5917 __connman_service_set_passphrase(service, value);
5920 void __connman_service_set_search_domains(struct connman_service *service,
5923 searchdomain_remove_all(service);
5925 if (service->domains)
5926 g_strfreev(service->domains);
5928 service->domains = g_strdupv(domains);
5930 searchdomain_add_all(service);
5933 static void service_complete(struct connman_service *service)
5935 reply_pending(service, EIO);
5937 if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
5938 __connman_service_auto_connect(service->connect_reason);
5940 g_get_current_time(&service->modified);
5941 service_save(service);
5944 static void report_error_cb(void *user_context, bool retry,
5947 struct connman_service *service = user_context;
5950 __connman_service_connect(service,
5951 CONNMAN_SERVICE_CONNECT_REASON_USER);
5953 /* It is not relevant to stay on Failure state
5954 * when failing is due to wrong user input */
5955 __connman_service_clear_error(service);
5956 #if defined TIZEN_EXT
5957 /* Reseting the state back in case of failure state */
5958 service->state_ipv4 = service->state_ipv6 =
5959 CONNMAN_SERVICE_STATE_IDLE;
5961 if (service->error != CONNMAN_SERVICE_ERROR_AUTH_FAILED)
5962 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
5964 service_complete(service);
5965 __connman_connection_update_gateway();
5969 static int check_wpspin(struct connman_service *service, const char *wpspin)
5977 length = strlen(wpspin);
5979 /* If 0, it will mean user wants to use PBC method */
5981 connman_network_set_string(service->network,
5982 "WiFi.PinWPS", NULL);
5986 /* A WPS PIN is always 8 chars length,
5987 * its content is in digit representation.
5992 for (i = 0; i < 8; i++)
5993 if (!isdigit((unsigned char) wpspin[i]))
5996 connman_network_set_string(service->network, "WiFi.PinWPS", wpspin);
6001 #if defined TIZEN_EXT
6002 static int __connman_service_connect_hidden(struct connman_service *service,
6003 const char *name, int name_len,
6004 const char *identity, const char *passphrase, void *user_data)
6008 for (list = service_list; list; list = list->next) {
6009 struct connman_service *target = list->data;
6010 const char *target_ssid = NULL;
6011 unsigned int target_ssid_len = 0;
6013 if (service->network != NULL &&
6014 service->security == target->security) {
6015 target_ssid = connman_network_get_blob(service->network,
6016 "WiFi.SSID", &target_ssid_len);
6017 if (target_ssid_len == name_len &&
6018 memcmp(target_ssid, name, name_len) == 0) {
6019 return connman_network_connect_hidden(service->network,
6020 (char *)identity, (char *)passphrase, user_data);
6029 static void request_input_cb(struct connman_service *service,
6030 bool values_received,
6031 const char *name, int name_len,
6032 const char *identity, const char *passphrase,
6033 bool wps, const char *wpspin,
6034 const char *error, void *user_data)
6036 struct connman_device *device;
6037 const char *security;
6040 DBG("RequestInput return, %p", service);
6043 DBG("error: %s", error);
6045 if (g_strcmp0(error,
6046 "net.connman.Agent.Error.Canceled") == 0) {
6049 if (service->hidden)
6050 __connman_service_return_error(service,
6051 ECANCELED, user_data);
6054 if (service->hidden)
6055 __connman_service_return_error(service,
6056 ETIMEDOUT, user_data);
6060 if (service->hidden && name_len > 0 && name_len <= 32) {
6061 #if defined TIZEN_EXT
6062 /* TIZEN already has Wi-Fi hidden scan before this hidden connection */
6063 err = __connman_service_connect_hidden(service, name, name_len,
6064 identity, passphrase, user_data);
6065 if (err == 0 || err == -EALREADY || err == -EINPROGRESS)
6069 device = connman_network_get_device(service->network);
6070 security = connman_network_get_string(service->network,
6072 err = __connman_device_request_hidden_scan(device,
6074 identity, passphrase,
6075 security, user_data);
6077 __connman_service_return_error(service, -err,
6081 if (!values_received || service->hidden) {
6086 if (wps && service->network) {
6087 err = check_wpspin(service, wpspin);
6091 connman_network_set_bool(service->network, "WiFi.UseWPS", wps);
6095 __connman_service_set_agent_identity(service, identity);
6098 err = __connman_service_set_passphrase(service, passphrase);
6102 /* We forget any previous error. */
6103 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6105 __connman_service_connect(service,
6106 CONNMAN_SERVICE_CONNECT_REASON_USER);
6108 } else if (err == -ENOKEY) {
6109 __connman_service_indicate_error(service,
6110 CONNMAN_SERVICE_ERROR_INVALID_KEY);
6112 /* It is not relevant to stay on Failure state
6113 * when failing is due to wrong user input */
6114 service->state = CONNMAN_SERVICE_STATE_IDLE;
6116 if (!service->hidden) {
6118 * If there was a real error when requesting
6119 * hidden scan, then that error is returned already
6120 * to the user somewhere above so do not try to
6123 __connman_service_return_error(service, -err,
6127 service_complete(service);
6128 __connman_connection_update_gateway();
6132 static void downgrade_connected_services(void)
6134 struct connman_service *up_service;
6137 for (list = service_list; list; list = list->next) {
6138 up_service = list->data;
6140 if (!is_connected(up_service))
6143 if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
6146 downgrade_state(up_service);
6150 static int service_update_preferred_order(struct connman_service *default_service,
6151 struct connman_service *new_service,
6152 enum connman_service_state new_state)
6154 unsigned int *tech_array;
6157 if (!default_service || default_service == new_service ||
6158 default_service->state != new_state)
6161 tech_array = connman_setting_get_uint_list("PreferredTechnologies");
6164 for (i = 0; tech_array[i] != 0; i += 1) {
6165 if (default_service->type == tech_array[i])
6168 if (new_service->type == tech_array[i]) {
6169 switch_default_service(default_service,
6171 __connman_connection_update_gateway();
6180 #if defined TIZEN_EXT
6181 static gboolean __connman_service_can_drop(struct connman_service *service)
6183 if (is_connected(service) == TRUE || is_connecting(service) == TRUE) {
6184 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
6186 else if (connman_service_is_no_ref_user_pdn_connection(service) == TRUE)
6192 static struct connman_device *default_connecting_device = NULL;
6194 static void __connman_service_disconnect_default(struct connman_service *service)
6196 struct connman_device *default_device = NULL;
6198 if (default_connecting_device == NULL)
6201 default_device = connman_network_get_device(
6202 __connman_service_get_network(service));
6204 DBG("Disconnecting service %p %s", service, service->path);
6205 DBG("Disconnecting device %p %p %s",
6206 default_connecting_device,
6208 connman_device_get_string(default_device, "Name"));
6210 if (default_connecting_device == default_device)
6211 default_connecting_device = NULL;
6214 static void __connman_service_connect_default(struct connman_service *current)
6218 bool default_internet;
6219 struct connman_service *service;
6220 struct connman_service *default_service = NULL;
6221 struct connman_device *default_device = NULL;
6223 if (current->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
6224 switch (current->state) {
6225 case CONNMAN_SERVICE_STATE_UNKNOWN:
6226 case CONNMAN_SERVICE_STATE_ASSOCIATION:
6227 case CONNMAN_SERVICE_STATE_CONFIGURATION:
6233 if (default_connecting_device &&
6234 __connman_service_is_internet_profile(current) == TRUE) {
6235 if (current->network == NULL)
6238 default_device = connman_network_get_device(current->network);
6239 if (default_connecting_device == default_device) {
6240 DBG("Cellular service[%s] %p %s",
6241 state2string(current->state), current, current->path);
6242 DBG("Cellular device %p %p %s",
6243 default_connecting_device, default_device,
6244 connman_device_get_string(default_device, "Name"));
6246 default_connecting_device = NULL;
6251 } else if (is_connected(current) == TRUE || is_connecting(current) == TRUE)
6254 /* Always-on: keep default cellular connection as possible */
6255 for (list = service_list; list; list = list->next) {
6256 service = list->data;
6258 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
6259 __connman_service_is_internet_profile(service) != TRUE ||
6260 service->network == NULL) {
6265 connman_network_get_bool(service->network, "DefaultInternet");
6267 DBG("service: %p %s %s %s (default: %d)", service, service->name,
6268 __connman_service_type2string(service->type),
6269 state2string(service->state), default_internet);
6271 if (default_internet) {
6272 default_service = service;
6273 if (is_connected(default_service) == TRUE ||
6274 is_connecting(default_service) == TRUE)
6277 default_device = connman_network_get_device(default_service->network);
6278 if (default_connecting_device == default_device) {
6279 DBG("Device is connecting (%p)", default_connecting_device);
6283 default_connecting_device = default_device;
6284 default_service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_USER;
6286 err = __connman_network_connect(default_service->network);
6287 DBG("Connecting default service %p %s [%d]",
6288 default_service, default_service->path, err);
6289 DBG("Connecting device %p %s", default_connecting_device,
6290 connman_device_get_string(default_connecting_device, "Name"));
6291 if (err < 0 && err != -EINPROGRESS) {
6292 default_connecting_device = NULL;
6300 static void single_connected_tech(struct connman_service *allowed)
6302 struct connman_service *service;
6303 GSList *services = NULL, *list;
6306 DBG("keeping %p %s", allowed, allowed->path);
6308 #if defined TIZEN_EXT
6309 if (!allowed || allowed->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6313 for (iter = service_list; iter; iter = iter->next) {
6314 service = iter->data;
6316 #if defined TIZEN_EXT
6317 if (service != allowed && service->type != allowed->type &&
6318 __connman_service_can_drop(service) == TRUE)
6320 if (!is_connected(service))
6323 if (service == allowed)
6326 services = g_slist_prepend(services, service);
6329 for (list = services; list; list = list->next) {
6330 service = list->data;
6332 DBG("disconnecting %p %s", service, service->path);
6333 #if defined TIZEN_EXT
6334 __connman_service_disconnect_default(service);
6336 __connman_service_disconnect(service);
6339 g_slist_free(services);
6342 #if defined TIZEN_EXT
6343 static void set_priority_connected_service(void)
6345 struct connman_service *service;
6348 for (list = service_list; list; list = list->next) {
6349 service = list->data;
6351 if (is_connected(service) == FALSE)
6359 static const char *get_dbus_sender(struct connman_service *service)
6361 if (!service->pending)
6364 return dbus_message_get_sender(service->pending);
6367 static int service_indicate_state(struct connman_service *service)
6369 enum connman_service_state old_state, new_state;
6370 struct connman_service *def_service;
6371 enum connman_ipconfig_method method;
6377 old_state = service->state;
6378 new_state = combine_state(service->state_ipv4, service->state_ipv6);
6380 DBG("service %p old %s - new %s/%s => %s",
6382 state2string(old_state),
6383 state2string(service->state_ipv4),
6384 state2string(service->state_ipv6),
6385 state2string(new_state));
6387 if (old_state == new_state)
6390 def_service = __connman_service_get_default();
6392 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
6393 result = service_update_preferred_order(def_service,
6394 service, new_state);
6395 if (result == -EALREADY)
6399 if (old_state == CONNMAN_SERVICE_STATE_ONLINE)
6400 __connman_notifier_leave_online(service->type);
6402 if (is_connected_state(service, old_state) &&
6403 !is_connected_state(service, new_state))
6404 searchdomain_remove_all(service);
6406 service->state = new_state;
6407 state_changed(service);
6410 case CONNMAN_SERVICE_STATE_UNKNOWN:
6414 case CONNMAN_SERVICE_STATE_IDLE:
6415 if (old_state != CONNMAN_SERVICE_STATE_DISCONNECT)
6416 __connman_service_disconnect(service);
6420 case CONNMAN_SERVICE_STATE_ASSOCIATION:
6424 case CONNMAN_SERVICE_STATE_CONFIGURATION:
6425 if (!service->new_service &&
6426 __connman_stats_service_register(service) == 0) {
6428 * For new services the statistics are updated after
6429 * we have successfully connected.
6431 __connman_stats_get(service, false,
6432 &service->stats.data);
6433 __connman_stats_get(service, true,
6434 &service->stats_roaming.data);
6439 case CONNMAN_SERVICE_STATE_READY:
6440 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6442 if (service->new_service &&
6443 __connman_stats_service_register(service) == 0) {
6445 * This is normally done after configuring state
6446 * but for new service do this after we have connected
6449 __connman_stats_get(service, false,
6450 &service->stats.data);
6451 __connman_stats_get(service, true,
6452 &service->stats_roaming.data);
6455 service->new_service = false;
6459 def_service = __connman_service_get_default();
6461 service_update_preferred_order(def_service, service, new_state);
6463 __connman_service_set_favorite(service, true);
6465 reply_pending(service, 0);
6467 g_get_current_time(&service->modified);
6468 service_save(service);
6470 searchdomain_add_all(service);
6471 dns_changed(service);
6472 domain_changed(service);
6473 proxy_changed(service);
6475 if (old_state != CONNMAN_SERVICE_STATE_ONLINE)
6476 __connman_notifier_connect(service->type);
6478 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
6479 connman_network_get_bool(service->network,
6483 pass = connman_network_get_string(service->network,
6486 __connman_service_set_passphrase(service, pass);
6488 connman_network_set_bool(service->network,
6489 "WiFi.UseWPS", false);
6492 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
6493 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
6494 __connman_ipconfig_disable_ipv6(
6495 service->ipconfig_ipv6);
6497 if (connman_setting_get_bool("SingleConnectedTechnology"))
6498 single_connected_tech(service);
6499 else if (service->type != CONNMAN_SERVICE_TYPE_VPN)
6502 #if defined TIZEN_EXT
6503 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
6504 set_priority_connected_service();
6509 case CONNMAN_SERVICE_STATE_ONLINE:
6513 case CONNMAN_SERVICE_STATE_DISCONNECT:
6514 set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
6516 reply_pending(service, ECONNABORTED);
6518 def_service = __connman_service_get_default();
6519 service->disconnect_reason = connman_network_get_disconnect_reason(service->network);
6521 if (!__connman_notifier_is_connected() &&
6523 def_service->provider)
6524 connman_provider_disconnect(def_service->provider);
6528 __connman_wispr_stop(service);
6530 __connman_wpad_stop(service);
6532 #if defined TIZEN_EXT
6534 * Skip the functions if there is any connected profiles
6535 * that use same interface
6537 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
6538 __connman_service_get_connected_count_of_iface(
6541 dns_changed(service);
6542 domain_changed(service);
6543 proxy_changed(service);
6544 #if defined TIZEN_EXT
6549 * Previous services which are connected and which states
6550 * are set to online should reset relevantly ipconfig_state
6551 * to ready so wispr/portal will be rerun on those
6553 downgrade_connected_services();
6555 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
6558 case CONNMAN_SERVICE_STATE_FAILURE:
6559 #if defined TIZEN_EXT
6560 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
6563 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
6564 connman_agent_report_error(service, service->path,
6565 error2string(service->error),
6567 get_dbus_sender(service),
6568 NULL) == -EINPROGRESS)
6570 service_complete(service);
6575 service_list_sort();
6577 #if defined TIZEN_EXT
6578 __connman_service_connect_default(service);
6581 __connman_connection_update_gateway();
6583 if ((old_state == CONNMAN_SERVICE_STATE_ONLINE &&
6584 new_state != CONNMAN_SERVICE_STATE_READY) ||
6585 (old_state == CONNMAN_SERVICE_STATE_READY &&
6586 new_state != CONNMAN_SERVICE_STATE_ONLINE)) {
6587 __connman_notifier_disconnect(service->type);
6590 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
6591 __connman_notifier_enter_online(service->type);
6595 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
6596 service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
6597 (new_state == CONNMAN_SERVICE_STATE_READY ||
6598 new_state == CONNMAN_SERVICE_STATE_ONLINE)) {
6599 if (service->user.favorite_user != service->user.current_user) {
6600 DBG("Now set service favorite user id from %d to %d",
6601 service->user.favorite_user, service->user.current_user);
6603 service->user.favorite_user = service->user.current_user;
6605 service_save(service);
6612 int __connman_service_indicate_error(struct connman_service *service,
6613 enum connman_service_error error)
6615 DBG("service %p error %d", service, error);
6620 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
6623 set_error(service, error);
6625 /* default internet service: fix not cleared if pdp activation*/
6626 #if defined TIZEN_EXT
6628 * If connection failed for default service(DefaultInternet),
6629 * default_connecting_device should be cleared.
6631 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
6632 service->error == CONNMAN_SERVICE_ERROR_CONNECT_FAILED)
6633 __connman_service_disconnect_default(service);
6635 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
6636 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY) {
6637 g_free(service->passphrase);
6638 service->passphrase = NULL;
6642 __connman_service_ipconfig_indicate_state(service,
6643 CONNMAN_SERVICE_STATE_FAILURE,
6644 CONNMAN_IPCONFIG_TYPE_IPV4);
6645 __connman_service_ipconfig_indicate_state(service,
6646 CONNMAN_SERVICE_STATE_FAILURE,
6647 CONNMAN_IPCONFIG_TYPE_IPV6);
6651 int __connman_service_clear_error(struct connman_service *service)
6653 DBusMessage *pending, *provider_pending;
6655 DBG("service %p", service);
6660 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
6663 pending = service->pending;
6664 service->pending = NULL;
6665 provider_pending = service->provider_pending;
6666 service->provider_pending = NULL;
6668 __connman_service_ipconfig_indicate_state(service,
6669 CONNMAN_SERVICE_STATE_IDLE,
6670 CONNMAN_IPCONFIG_TYPE_IPV6);
6672 __connman_service_ipconfig_indicate_state(service,
6673 CONNMAN_SERVICE_STATE_IDLE,
6674 CONNMAN_IPCONFIG_TYPE_IPV4);
6676 service->pending = pending;
6677 service->provider_pending = provider_pending;
6682 int __connman_service_indicate_default(struct connman_service *service)
6684 DBG("service %p state %s", service, state2string(service->state));
6686 if (!is_connected(service)) {
6688 * If service is not yet fully connected, then we must not
6689 * change the default yet. The default gw will be changed
6690 * after the service state is in ready.
6692 return -EINPROGRESS;
6700 enum connman_service_state __connman_service_ipconfig_get_state(
6701 struct connman_service *service,
6702 enum connman_ipconfig_type type)
6705 return CONNMAN_SERVICE_STATE_UNKNOWN;
6707 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
6708 return service->state_ipv4;
6710 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
6711 return service->state_ipv6;
6713 return CONNMAN_SERVICE_STATE_UNKNOWN;
6716 static void check_proxy_setup(struct connman_service *service)
6719 * We start WPAD if we haven't got a PAC URL from DHCP and
6720 * if our proxy manual configuration is either empty or set
6721 * to AUTO with an empty URL.
6724 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
6727 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
6728 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
6732 if (__connman_wpad_start(service) < 0) {
6733 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
6734 __connman_notifier_proxy_changed(service);
6741 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
6744 #if defined TIZEN_EXT
6745 void connman_check_proxy_setup_and_wispr_start(struct connman_service *service){
6747 DBG("check the proxy and start wispr");
6748 check_proxy_setup(service);
6754 * How many networks are connected at the same time. If more than 1,
6755 * then set the rp_filter setting properly (loose mode routing) so that network
6756 * connectivity works ok. This is only done for IPv4 networks as IPv6
6757 * does not have rp_filter knob.
6759 static int connected_networks_count;
6760 static int original_rp_filter;
6762 static void service_rp_filter(struct connman_service *service,
6765 enum connman_ipconfig_method method;
6767 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
6770 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
6771 case CONNMAN_IPCONFIG_METHOD_OFF:
6772 case CONNMAN_IPCONFIG_METHOD_AUTO:
6774 case CONNMAN_IPCONFIG_METHOD_FIXED:
6775 case CONNMAN_IPCONFIG_METHOD_MANUAL:
6776 case CONNMAN_IPCONFIG_METHOD_DHCP:
6781 if (connected_networks_count == 1) {
6783 filter_value = __connman_ipconfig_set_rp_filter();
6784 if (filter_value < 0)
6787 original_rp_filter = filter_value;
6789 connected_networks_count++;
6792 if (connected_networks_count == 2)
6793 __connman_ipconfig_unset_rp_filter(original_rp_filter);
6795 connected_networks_count--;
6796 if (connected_networks_count < 0)
6797 connected_networks_count = 0;
6800 DBG("%s %s ipconfig %p method %d count %d filter %d",
6801 connected ? "connected" : "disconnected", service->identifier,
6802 service->ipconfig_ipv4, method,
6803 connected_networks_count, original_rp_filter);
6806 static gboolean redo_wispr(gpointer user_data)
6808 struct connman_service *service = user_data;
6809 int refcount = service->refcount - 1;
6811 connman_service_unref(service);
6812 if (refcount == 0) {
6813 DBG("Service %p already removed", service);
6817 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV6);
6822 int __connman_service_online_check_failed(struct connman_service *service,
6823 enum connman_ipconfig_type type)
6825 DBG("service %p type %d count %d", service, type,
6826 service->online_check_count);
6828 /* currently we only retry IPv6 stuff */
6829 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 ||
6830 service->online_check_count != 1) {
6831 connman_warn("Online check failed for %p %s", service,
6836 service->online_check_count = 0;
6839 * We set the timeout to 1 sec so that we have a chance to get
6840 * necessary IPv6 router advertisement messages that might have
6843 g_timeout_add_seconds(1, redo_wispr, connman_service_ref(service));
6848 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
6849 enum connman_service_state new_state,
6850 enum connman_ipconfig_type type)
6852 struct connman_ipconfig *ipconfig = NULL;
6853 enum connman_service_state old_state;
6854 enum connman_ipconfig_method method;
6860 case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
6861 case CONNMAN_IPCONFIG_TYPE_ALL:
6864 case CONNMAN_IPCONFIG_TYPE_IPV4:
6865 old_state = service->state_ipv4;
6866 ipconfig = service->ipconfig_ipv4;
6870 case CONNMAN_IPCONFIG_TYPE_IPV6:
6871 old_state = service->state_ipv6;
6872 ipconfig = service->ipconfig_ipv6;
6881 if (old_state == new_state)
6884 #if defined TIZEN_EXT
6885 __sync_synchronize();
6886 if (service->user_pdn_connection_refcount > 0 &&
6887 service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
6888 if (new_state == CONNMAN_SERVICE_STATE_FAILURE ||
6889 new_state == CONNMAN_SERVICE_STATE_DISCONNECT ||
6890 new_state == CONNMAN_SERVICE_STATE_IDLE) {
6891 service->user_pdn_connection_refcount = 0;
6892 __sync_synchronize();
6896 DBG("service %p (%s) old state %d (%s) new state %d (%s) type %d (%s)",
6897 service, service ? service->identifier : NULL,
6898 old_state, state2string(old_state),
6899 new_state, state2string(new_state),
6900 type, __connman_ipconfig_type2string(type));
6902 switch (new_state) {
6903 case CONNMAN_SERVICE_STATE_UNKNOWN:
6904 case CONNMAN_SERVICE_STATE_IDLE:
6905 case CONNMAN_SERVICE_STATE_ASSOCIATION:
6907 case CONNMAN_SERVICE_STATE_CONFIGURATION:
6908 __connman_ipconfig_enable(ipconfig);
6910 case CONNMAN_SERVICE_STATE_READY:
6911 #if defined TIZEN_EXT
6912 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
6913 __connman_service_is_internet_profile(service) != TRUE) {
6914 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
6915 service_rp_filter(service, TRUE);
6920 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
6921 #if !defined TIZEN_EXT
6922 check_proxy_setup(service);
6924 service_rp_filter(service, true);
6926 service->online_check_count = 1;
6927 __connman_wispr_start(service, type);
6930 case CONNMAN_SERVICE_STATE_ONLINE:
6932 case CONNMAN_SERVICE_STATE_DISCONNECT:
6933 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
6936 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
6937 service_rp_filter(service, false);
6940 case CONNMAN_SERVICE_STATE_FAILURE:
6944 /* Keep that state, but if the ipconfig method is OFF, then we set
6945 the state to IDLE so that it will not affect the combined state
6948 method = __connman_ipconfig_get_method(ipconfig);
6950 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
6951 case CONNMAN_IPCONFIG_METHOD_OFF:
6952 new_state = CONNMAN_SERVICE_STATE_IDLE;
6955 case CONNMAN_IPCONFIG_METHOD_FIXED:
6956 case CONNMAN_IPCONFIG_METHOD_MANUAL:
6957 case CONNMAN_IPCONFIG_METHOD_DHCP:
6958 case CONNMAN_IPCONFIG_METHOD_AUTO:
6963 if (is_connected_state(service, old_state) &&
6964 !is_connected_state(service, new_state))
6965 nameserver_remove_all(service);
6967 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
6968 service->state_ipv4 = new_state;
6970 service->state_ipv6 = new_state;
6972 if (!is_connected_state(service, old_state) &&
6973 is_connected_state(service, new_state))
6974 nameserver_add_all(service);
6976 #if defined TIZEN_EXT
6977 int ret = service_indicate_state(service);
6978 /*Sent the Ready changed signal again in case IPv4 IP set
6981 if(ret == -EALREADY && type == CONNMAN_IPCONFIG_TYPE_IPV4
6982 && new_state == CONNMAN_SERVICE_STATE_READY) {
6983 DBG("Notify IPv4 state new/old %d/%d", new_state,old_state);
6984 state_changed(service);
6989 return service_indicate_state(service);
6992 static bool prepare_network(struct connman_service *service)
6994 enum connman_network_type type;
6995 unsigned int ssid_len;
6997 type = connman_network_get_type(service->network);
7000 case CONNMAN_NETWORK_TYPE_UNKNOWN:
7001 case CONNMAN_NETWORK_TYPE_VENDOR:
7003 case CONNMAN_NETWORK_TYPE_WIFI:
7004 if (!connman_network_get_blob(service->network, "WiFi.SSID",
7008 if (service->passphrase)
7009 connman_network_set_string(service->network,
7010 "WiFi.Passphrase", service->passphrase);
7012 case CONNMAN_NETWORK_TYPE_ETHERNET:
7013 case CONNMAN_NETWORK_TYPE_GADGET:
7014 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
7015 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
7016 case CONNMAN_NETWORK_TYPE_CELLULAR:
7023 static void prepare_8021x(struct connman_service *service)
7026 connman_network_set_string(service->network, "WiFi.EAP",
7029 if (service->identity)
7030 connman_network_set_string(service->network, "WiFi.Identity",
7033 if (service->ca_cert_file)
7034 connman_network_set_string(service->network, "WiFi.CACertFile",
7035 service->ca_cert_file);
7037 if (service->client_cert_file)
7038 connman_network_set_string(service->network,
7039 "WiFi.ClientCertFile",
7040 service->client_cert_file);
7042 if (service->private_key_file)
7043 connman_network_set_string(service->network,
7044 "WiFi.PrivateKeyFile",
7045 service->private_key_file);
7047 if (service->private_key_passphrase)
7048 connman_network_set_string(service->network,
7049 "WiFi.PrivateKeyPassphrase",
7050 service->private_key_passphrase);
7052 if (service->phase2)
7053 connman_network_set_string(service->network, "WiFi.Phase2",
7057 static int service_connect(struct connman_service *service)
7061 if (service->hidden)
7064 switch (service->type) {
7065 case CONNMAN_SERVICE_TYPE_UNKNOWN:
7066 case CONNMAN_SERVICE_TYPE_SYSTEM:
7067 case CONNMAN_SERVICE_TYPE_GPS:
7068 case CONNMAN_SERVICE_TYPE_P2P:
7070 case CONNMAN_SERVICE_TYPE_ETHERNET:
7071 case CONNMAN_SERVICE_TYPE_GADGET:
7072 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
7073 case CONNMAN_SERVICE_TYPE_CELLULAR:
7074 case CONNMAN_SERVICE_TYPE_VPN:
7076 case CONNMAN_SERVICE_TYPE_WIFI:
7077 switch (service->security) {
7078 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
7079 case CONNMAN_SERVICE_SECURITY_NONE:
7081 case CONNMAN_SERVICE_SECURITY_WEP:
7082 case CONNMAN_SERVICE_SECURITY_PSK:
7083 case CONNMAN_SERVICE_SECURITY_WPA:
7084 case CONNMAN_SERVICE_SECURITY_RSN:
7085 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
7088 if (service->request_passphrase_input) {
7089 DBG("Now try to connect other user's favorite service");
7090 service->request_passphrase_input = false;
7092 } else if (!service->passphrase) {
7093 if (!service->network)
7096 if (!service->wps ||
7097 !connman_network_get_bool(service->network, "WiFi.UseWPS"))
7102 case CONNMAN_SERVICE_SECURITY_8021X:
7106 #if defined TIZEN_EXT
7108 * never request credentials if using EAP-TLS, EAP-SIM
7109 * or EAP-AKA (EAP-TLS, EAP-SIM and EAP-AKA networks
7110 * need to be fully provisioned)
7112 if (g_str_equal(service->eap, "tls") ||
7113 g_str_equal(service->eap, "sim") ||
7114 g_str_equal(service->eap, "aka"))
7118 * never request credentials if using EAP-TLS
7119 * (EAP-TLS networks need to be fully provisioned)
7121 if (g_str_equal(service->eap, "tls"))
7125 * Return -ENOKEY if either identity or passphrase is
7126 * missing. Agent provided credentials can be used as
7127 * fallback if needed.
7129 if (((!service->identity &&
7130 !service->agent_identity) ||
7131 !service->passphrase) ||
7132 service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
7140 if (service->network) {
7141 if (!prepare_network(service))
7144 switch (service->security) {
7145 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
7146 case CONNMAN_SERVICE_SECURITY_NONE:
7147 case CONNMAN_SERVICE_SECURITY_WEP:
7148 case CONNMAN_SERVICE_SECURITY_PSK:
7149 case CONNMAN_SERVICE_SECURITY_WPA:
7150 case CONNMAN_SERVICE_SECURITY_RSN:
7152 case CONNMAN_SERVICE_SECURITY_8021X:
7153 prepare_8021x(service);
7157 if (__connman_stats_service_register(service) == 0) {
7158 __connman_stats_get(service, false,
7159 &service->stats.data);
7160 __connman_stats_get(service, true,
7161 &service->stats_roaming.data);
7164 if (service->ipconfig_ipv4)
7165 __connman_ipconfig_enable(service->ipconfig_ipv4);
7166 if (service->ipconfig_ipv6)
7167 __connman_ipconfig_enable(service->ipconfig_ipv6);
7169 err = __connman_network_connect(service->network);
7170 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7172 err = __connman_provider_connect(service->provider);
7177 if (err != -EINPROGRESS) {
7178 __connman_ipconfig_disable(service->ipconfig_ipv4);
7179 __connman_ipconfig_disable(service->ipconfig_ipv6);
7180 __connman_stats_service_unregister(service);
7187 int __connman_service_connect(struct connman_service *service,
7188 enum connman_service_connect_reason reason)
7192 DBG("service %p state %s connect reason %s -> %s",
7193 service, state2string(service->state),
7194 reason2string(service->connect_reason),
7195 reason2string(reason));
7197 if (is_connected(service))
7200 if (is_connecting(service))
7203 switch (service->type) {
7204 case CONNMAN_SERVICE_TYPE_UNKNOWN:
7205 case CONNMAN_SERVICE_TYPE_SYSTEM:
7206 case CONNMAN_SERVICE_TYPE_GPS:
7207 case CONNMAN_SERVICE_TYPE_P2P:
7210 case CONNMAN_SERVICE_TYPE_ETHERNET:
7211 case CONNMAN_SERVICE_TYPE_GADGET:
7212 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
7213 case CONNMAN_SERVICE_TYPE_CELLULAR:
7214 case CONNMAN_SERVICE_TYPE_VPN:
7215 case CONNMAN_SERVICE_TYPE_WIFI:
7219 if (!is_ipconfig_usable(service))
7222 __connman_service_clear_error(service);
7224 err = service_connect(service);
7226 service->connect_reason = reason;
7230 if (err == -EINPROGRESS) {
7231 if (service->timeout == 0)
7232 service->timeout = g_timeout_add_seconds(
7233 CONNECT_TIMEOUT, connect_timeout, service);
7235 return -EINPROGRESS;
7238 if (service->network)
7239 __connman_network_disconnect(service->network);
7240 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7242 connman_provider_disconnect(service->provider);
7244 if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
7245 if (err == -ENOKEY || err == -EPERM) {
7246 DBusMessage *pending = NULL;
7249 * We steal the reply here. The idea is that the
7250 * connecting client will see the connection status
7251 * after the real hidden network is connected or
7252 * connection failed.
7254 if (service->hidden) {
7255 pending = service->pending;
7256 service->pending = NULL;
7259 err = __connman_agent_request_passphrase_input(service,
7261 get_dbus_sender(service),
7263 if (service->hidden && err != -EINPROGRESS)
7264 service->pending = pending;
7268 reply_pending(service, -err);
7274 int __connman_service_disconnect(struct connman_service *service)
7278 DBG("service %p", service);
7280 service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
7281 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
7283 connman_agent_cancel(service);
7285 reply_pending(service, ECONNABORTED);
7287 if (service->network) {
7288 err = __connman_network_disconnect(service->network);
7289 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7291 err = connman_provider_disconnect(service->provider);
7295 if (err < 0 && err != -EINPROGRESS)
7298 __connman_6to4_remove(service->ipconfig_ipv4);
7300 if (service->ipconfig_ipv4)
7301 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
7304 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
7307 #if defined TIZEN_EXT
7309 * Skip the functions If there is any connected profiles
7310 * that use same interface
7312 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR ||
7313 __connman_service_get_connected_count_of_iface(service) <= 0) {
7315 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
7316 settings_changed(service, service->ipconfig_ipv4);
7318 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
7319 settings_changed(service, service->ipconfig_ipv6);
7321 __connman_ipconfig_disable(service->ipconfig_ipv4);
7322 __connman_ipconfig_disable(service->ipconfig_ipv6);
7323 #if defined TIZEN_EXT
7327 __connman_stats_service_unregister(service);
7332 int __connman_service_disconnect_all(void)
7334 struct connman_service *service;
7335 GSList *services = NULL, *list;
7340 for (iter = service_list; iter; iter = iter->next) {
7341 service = iter->data;
7343 if (!is_connected(service))
7346 services = g_slist_prepend(services, service);
7349 for (list = services; list; list = list->next) {
7350 struct connman_service *service = list->data;
7352 service->ignore = true;
7354 __connman_service_disconnect(service);
7357 g_slist_free(services);
7363 * lookup_by_identifier:
7364 * @identifier: service identifier
7366 * Look up a service by identifier (reference count will not be increased)
7368 static struct connman_service *lookup_by_identifier(const char *identifier)
7370 return g_hash_table_lookup(service_hash, identifier);
7373 struct provision_user_data {
7378 static void provision_changed(gpointer value, gpointer user_data)
7380 struct connman_service *service = value;
7381 struct provision_user_data *data = user_data;
7382 const char *path = data->ident;
7385 ret = __connman_config_provision_service_ident(service, path,
7386 service->config_file, service->config_entry);
7391 int __connman_service_provision_changed(const char *ident)
7393 struct provision_user_data data = {
7398 g_list_foreach(service_list, provision_changed, (void *)&data);
7401 * Because the provision_changed() might have set some services
7402 * as favorite, we must sort the sequence now.
7404 if (services_dirty) {
7405 services_dirty = false;
7407 service_list_sort();
7409 __connman_connection_update_gateway();
7415 void __connman_service_set_config(struct connman_service *service,
7416 const char *file_id, const char *entry)
7421 g_free(service->config_file);
7422 service->config_file = g_strdup(file_id);
7424 g_free(service->config_entry);
7425 service->config_entry = g_strdup(entry);
7429 * __connman_service_get:
7430 * @identifier: service identifier
7432 * Look up a service by identifier or create a new one if not found
7434 static struct connman_service *service_get(const char *identifier)
7436 struct connman_service *service;
7438 service = g_hash_table_lookup(service_hash, identifier);
7440 connman_service_ref(service);
7444 service = connman_service_create();
7448 DBG("service %p", service);
7450 service->identifier = g_strdup(identifier);
7452 service_list = g_list_insert_sorted(service_list, service,
7455 g_hash_table_insert(service_hash, service->identifier, service);
7460 static int service_register(struct connman_service *service)
7462 DBG("service %p", service);
7467 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
7468 service->identifier);
7470 DBG("path %s", service->path);
7472 if (__connman_config_provision_service(service) < 0)
7473 service_load(service);
7475 g_dbus_register_interface(connection, service->path,
7476 CONNMAN_SERVICE_INTERFACE,
7477 service_methods, service_signals,
7478 NULL, service, NULL);
7480 service_list_sort();
7482 __connman_connection_update_gateway();
7487 static void service_up(struct connman_ipconfig *ipconfig,
7490 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
7492 DBG("%s up", ifname);
7494 link_changed(service);
7496 service->stats.valid = false;
7497 service->stats_roaming.valid = false;
7500 static void service_down(struct connman_ipconfig *ipconfig,
7503 DBG("%s down", ifname);
7506 static void service_lower_up(struct connman_ipconfig *ipconfig,
7509 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
7511 DBG("%s lower up", ifname);
7513 stats_start(service);
7516 static void service_lower_down(struct connman_ipconfig *ipconfig,
7519 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
7521 DBG("%s lower down", ifname);
7523 if (!is_idle_state(service, service->state_ipv4))
7524 __connman_ipconfig_disable(service->ipconfig_ipv4);
7526 if (!is_idle_state(service, service->state_ipv6))
7527 __connman_ipconfig_disable(service->ipconfig_ipv6);
7529 stats_stop(service);
7530 service_save(service);
7533 static void service_ip_bound(struct connman_ipconfig *ipconfig,
7536 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
7537 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
7538 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
7540 DBG("%s ip bound", ifname);
7542 type = __connman_ipconfig_get_config_type(ipconfig);
7543 method = __connman_ipconfig_get_method(ipconfig);
7545 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
7548 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
7549 method == CONNMAN_IPCONFIG_METHOD_AUTO)
7550 __connman_service_ipconfig_indicate_state(service,
7551 CONNMAN_SERVICE_STATE_READY,
7552 CONNMAN_IPCONFIG_TYPE_IPV6);
7554 settings_changed(service, ipconfig);
7557 static void service_ip_release(struct connman_ipconfig *ipconfig,
7560 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
7561 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
7562 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
7564 DBG("%s ip release", ifname);
7566 type = __connman_ipconfig_get_config_type(ipconfig);
7567 method = __connman_ipconfig_get_method(ipconfig);
7569 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
7572 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
7573 method == CONNMAN_IPCONFIG_METHOD_OFF)
7574 __connman_service_ipconfig_indicate_state(service,
7575 CONNMAN_SERVICE_STATE_DISCONNECT,
7576 CONNMAN_IPCONFIG_TYPE_IPV6);
7578 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
7579 method == CONNMAN_IPCONFIG_METHOD_OFF)
7580 __connman_service_ipconfig_indicate_state(service,
7581 CONNMAN_SERVICE_STATE_DISCONNECT,
7582 CONNMAN_IPCONFIG_TYPE_IPV4);
7584 settings_changed(service, ipconfig);
7587 static void service_route_changed(struct connman_ipconfig *ipconfig,
7590 struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
7592 DBG("%s route changed", ifname);
7594 settings_changed(service, ipconfig);
7597 static const struct connman_ipconfig_ops service_ops = {
7599 .down = service_down,
7600 .lower_up = service_lower_up,
7601 .lower_down = service_lower_down,
7602 .ip_bound = service_ip_bound,
7603 .ip_release = service_ip_release,
7604 .route_set = service_route_changed,
7605 .route_unset = service_route_changed,
7608 static struct connman_ipconfig *create_ip4config(struct connman_service *service,
7609 int index, enum connman_ipconfig_method method)
7611 struct connman_ipconfig *ipconfig_ipv4;
7613 ipconfig_ipv4 = __connman_ipconfig_create(index,
7614 CONNMAN_IPCONFIG_TYPE_IPV4);
7618 __connman_ipconfig_set_method(ipconfig_ipv4, method);
7620 __connman_ipconfig_set_data(ipconfig_ipv4, service);
7622 __connman_ipconfig_set_ops(ipconfig_ipv4, &service_ops);
7624 return ipconfig_ipv4;
7627 static struct connman_ipconfig *create_ip6config(struct connman_service *service,
7630 struct connman_ipconfig *ipconfig_ipv6;
7632 ipconfig_ipv6 = __connman_ipconfig_create(index,
7633 CONNMAN_IPCONFIG_TYPE_IPV6);
7637 __connman_ipconfig_set_data(ipconfig_ipv6, service);
7639 __connman_ipconfig_set_ops(ipconfig_ipv6, &service_ops);
7641 return ipconfig_ipv6;
7644 void __connman_service_read_ip4config(struct connman_service *service)
7648 if (!service->ipconfig_ipv4)
7651 keyfile = connman_storage_load_service(service->identifier);
7655 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
7656 service->identifier, "IPv4.");
7658 g_key_file_free(keyfile);
7661 void connman_service_create_ip4config(struct connman_service *service,
7664 DBG("ipv4 %p", service->ipconfig_ipv4);
7666 if (service->ipconfig_ipv4)
7669 service->ipconfig_ipv4 = create_ip4config(service, index,
7670 CONNMAN_IPCONFIG_METHOD_DHCP);
7671 __connman_service_read_ip4config(service);
7674 void __connman_service_read_ip6config(struct connman_service *service)
7678 if (!service->ipconfig_ipv6)
7681 keyfile = connman_storage_load_service(service->identifier);
7685 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
7686 service->identifier, "IPv6.");
7688 g_key_file_free(keyfile);
7691 void connman_service_create_ip6config(struct connman_service *service,
7694 DBG("ipv6 %p", service->ipconfig_ipv6);
7696 if (service->ipconfig_ipv6)
7699 service->ipconfig_ipv6 = create_ip6config(service, index);
7701 __connman_service_read_ip6config(service);
7705 * connman_service_lookup_from_network:
7706 * @network: network structure
7708 * Look up a service by network (reference count will not be increased)
7710 struct connman_service *connman_service_lookup_from_network(struct connman_network *network)
7712 struct connman_service *service;
7713 const char *ident, *group;
7719 ident = __connman_network_get_ident(network);
7723 group = connman_network_get_group(network);
7727 name = g_strdup_printf("%s_%s_%s",
7728 __connman_network_get_type(network), ident, group);
7729 service = lookup_by_identifier(name);
7735 struct connman_service *__connman_service_lookup_from_index(int index)
7737 struct connman_service *service;
7740 for (list = service_list; list; list = list->next) {
7741 service = list->data;
7743 if (__connman_ipconfig_get_index(service->ipconfig_ipv4)
7747 if (__connman_ipconfig_get_index(service->ipconfig_ipv6)
7755 struct connman_service *__connman_service_lookup_from_ident(const char *identifier)
7757 return lookup_by_identifier(identifier);
7760 const char *__connman_service_get_ident(struct connman_service *service)
7762 return service->identifier;
7765 const char *__connman_service_get_path(struct connman_service *service)
7767 return service->path;
7770 const char *__connman_service_get_name(struct connman_service *service)
7772 return service->name;
7775 enum connman_service_state __connman_service_get_state(struct connman_service *service)
7777 return service->state;
7780 unsigned int __connman_service_get_order(struct connman_service *service)
7782 unsigned int order = 0;
7789 if (!service->favorite)
7792 #if defined TIZEN_EXT
7793 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7794 service->do_split_routing == FALSE)
7796 else if (service->type == CONNMAN_SERVICE_TYPE_WIFI) {
7797 if (service->order < 5)
7799 } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
7801 else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
7803 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7804 __connman_service_is_internet_profile(service) == TRUE)
7806 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
7807 __connman_service_is_tethering_profile(service) == TRUE)
7809 else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR)
7814 if (service == service_list->data)
7817 if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
7818 !service->do_split_routing) {
7819 service->order = 10;
7823 DBG("service %p name %s order %d split %d", service, service->name,
7824 order, service->do_split_routing);
7829 void __connman_service_update_ordering(void)
7831 if (service_list && service_list->next)
7832 service_list = g_list_sort(service_list, service_compare);
7835 static enum connman_service_type convert_network_type(struct connman_network *network)
7837 enum connman_network_type type = connman_network_get_type(network);
7840 case CONNMAN_NETWORK_TYPE_UNKNOWN:
7841 case CONNMAN_NETWORK_TYPE_VENDOR:
7843 case CONNMAN_NETWORK_TYPE_ETHERNET:
7844 return CONNMAN_SERVICE_TYPE_ETHERNET;
7845 case CONNMAN_NETWORK_TYPE_WIFI:
7846 return CONNMAN_SERVICE_TYPE_WIFI;
7847 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
7848 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
7849 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
7850 case CONNMAN_NETWORK_TYPE_CELLULAR:
7851 return CONNMAN_SERVICE_TYPE_CELLULAR;
7852 case CONNMAN_NETWORK_TYPE_GADGET:
7853 return CONNMAN_SERVICE_TYPE_GADGET;
7856 return CONNMAN_SERVICE_TYPE_UNKNOWN;
7859 static enum connman_service_security convert_wifi_security(const char *security)
7862 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
7863 else if (g_str_equal(security, "none"))
7864 return CONNMAN_SERVICE_SECURITY_NONE;
7865 else if (g_str_equal(security, "wep"))
7866 return CONNMAN_SERVICE_SECURITY_WEP;
7867 else if (g_str_equal(security, "psk"))
7868 return CONNMAN_SERVICE_SECURITY_PSK;
7869 else if (g_str_equal(security, "ieee8021x"))
7870 return CONNMAN_SERVICE_SECURITY_8021X;
7871 else if (g_str_equal(security, "wpa"))
7872 return CONNMAN_SERVICE_SECURITY_WPA;
7873 else if (g_str_equal(security, "rsn"))
7874 return CONNMAN_SERVICE_SECURITY_RSN;
7875 #if defined TIZEN_EXT
7876 else if (g_str_equal(security, "ft_psk") == TRUE)
7877 return CONNMAN_SERVICE_SECURITY_PSK;
7878 else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
7879 return CONNMAN_SERVICE_SECURITY_8021X;
7882 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
7885 static void update_from_network(struct connman_service *service,
7886 struct connman_network *network)
7888 uint8_t strength = service->strength;
7891 DBG("service %p network %p", service, network);
7893 if (is_connected(service))
7896 if (is_connecting(service))
7899 str = connman_network_get_string(network, "Name");
7901 g_free(service->name);
7902 service->name = g_strdup(str);
7903 service->hidden = false;
7905 g_free(service->name);
7906 service->name = NULL;
7907 service->hidden = true;
7910 service->strength = connman_network_get_strength(network);
7911 service->roaming = connman_network_get_bool(network, "Roaming");
7913 if (service->strength == 0) {
7915 * Filter out 0-values; it's unclear what they mean
7916 * and they cause anomalous sorting of the priority list.
7918 service->strength = strength;
7921 str = connman_network_get_string(network, "WiFi.Security");
7922 service->security = convert_wifi_security(str);
7924 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
7925 service->wps = connman_network_get_bool(network, "WiFi.WPS");
7927 if (service->strength > strength && service->network) {
7928 connman_network_unref(service->network);
7929 service->network = connman_network_ref(network);
7931 strength_changed(service);
7934 if (!service->network)
7935 service->network = connman_network_ref(network);
7937 service_list_sort();
7941 * __connman_service_create_from_network:
7942 * @network: network structure
7944 * Look up service by network and if not found, create one
7946 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
7948 struct connman_service *service;
7949 struct connman_device *device;
7950 const char *ident, *group;
7952 unsigned int *auto_connect_types;
7955 DBG("network %p", network);
7960 ident = __connman_network_get_ident(network);
7964 group = connman_network_get_group(network);
7968 name = g_strdup_printf("%s_%s_%s",
7969 __connman_network_get_type(network), ident, group);
7970 service = service_get(name);
7976 if (__connman_network_get_weakness(network))
7979 if (service->path) {
7980 update_from_network(service, network);
7981 __connman_connection_update_gateway();
7985 service->type = convert_network_type(network);
7987 auto_connect_types = connman_setting_get_uint_list("DefaultAutoConnectTechnologies");
7988 service->autoconnect = false;
7989 for (i = 0; auto_connect_types &&
7990 auto_connect_types[i] != 0; i++) {
7991 if (service->type == auto_connect_types[i]) {
7992 service->autoconnect = true;
7997 switch (service->type) {
7998 case CONNMAN_SERVICE_TYPE_UNKNOWN:
7999 case CONNMAN_SERVICE_TYPE_SYSTEM:
8000 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8001 case CONNMAN_SERVICE_TYPE_GPS:
8002 case CONNMAN_SERVICE_TYPE_VPN:
8003 case CONNMAN_SERVICE_TYPE_GADGET:
8004 case CONNMAN_SERVICE_TYPE_WIFI:
8005 case CONNMAN_SERVICE_TYPE_CELLULAR:
8006 case CONNMAN_SERVICE_TYPE_P2P:
8008 case CONNMAN_SERVICE_TYPE_ETHERNET:
8009 service->favorite = true;
8013 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
8014 service->state = combine_state(service->state_ipv4, service->state_ipv6);
8016 update_from_network(service, network);
8018 index = connman_network_get_index(network);
8020 if (!service->ipconfig_ipv4)
8021 service->ipconfig_ipv4 = create_ip4config(service, index,
8022 CONNMAN_IPCONFIG_METHOD_DHCP);
8024 if (!service->ipconfig_ipv6)
8025 service->ipconfig_ipv6 = create_ip6config(service, index);
8027 service_register(service);
8029 if (service->favorite) {
8030 device = connman_network_get_device(service->network);
8031 if (device && !connman_device_get_scanning(device)) {
8033 switch (service->type) {
8034 case CONNMAN_SERVICE_TYPE_UNKNOWN:
8035 case CONNMAN_SERVICE_TYPE_SYSTEM:
8036 case CONNMAN_SERVICE_TYPE_P2P:
8039 case CONNMAN_SERVICE_TYPE_GADGET:
8040 case CONNMAN_SERVICE_TYPE_ETHERNET:
8041 if (service->autoconnect) {
8042 __connman_service_connect(service,
8043 CONNMAN_SERVICE_CONNECT_REASON_AUTO);
8048 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
8049 case CONNMAN_SERVICE_TYPE_GPS:
8050 case CONNMAN_SERVICE_TYPE_VPN:
8051 case CONNMAN_SERVICE_TYPE_WIFI:
8052 case CONNMAN_SERVICE_TYPE_CELLULAR:
8053 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
8058 #if defined TIZEN_EXT
8059 /* TIZEN synchronizes below information when the service creates */
8060 if (service->eap != NULL)
8061 connman_network_set_string(service->network, "WiFi.EAP",
8063 if (service->identity != NULL)
8064 connman_network_set_string(service->network, "WiFi.Identity",
8066 if (service->phase2 != NULL)
8067 connman_network_set_string(service->network, "WiFi.Phase2",
8072 __connman_notifier_service_add(service, service->name);
8073 service_schedule_added(service);
8078 void __connman_service_update_from_network(struct connman_network *network)
8080 bool need_sort = false;
8081 struct connman_service *service;
8087 service = connman_service_lookup_from_network(network);
8091 if (!service->network)
8094 #if defined TIZEN_EXT
8095 if (service->storage_reload) {
8096 service_load(service);
8097 __connman_service_set_storage_reload(service, false);
8101 name = connman_network_get_string(service->network, "Name");
8102 if (g_strcmp0(service->name, name) != 0) {
8103 g_free(service->name);
8104 service->name = g_strdup(name);
8106 if (allow_property_changed(service))
8107 connman_dbus_property_changed_basic(service->path,
8108 CONNMAN_SERVICE_INTERFACE, "Name",
8109 DBUS_TYPE_STRING, &service->name);
8112 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
8113 service->wps = connman_network_get_bool(network, "WiFi.WPS");
8115 strength = connman_network_get_strength(service->network);
8116 if (strength == service->strength)
8119 service->strength = strength;
8122 strength_changed(service);
8125 roaming = connman_network_get_bool(service->network, "Roaming");
8126 if (roaming == service->roaming)
8129 stats_enable = stats_enabled(service);
8131 stats_stop(service);
8133 service->roaming = roaming;
8137 stats_start(service);
8139 roaming_changed(service);
8143 service_list_sort();
8147 void __connman_service_remove_from_network(struct connman_network *network)
8149 struct connman_service *service;
8151 service = connman_service_lookup_from_network(network);
8153 DBG("network %p service %p", network, service);
8158 service->ignore = true;
8160 __connman_connection_gateway_remove(service,
8161 CONNMAN_IPCONFIG_TYPE_ALL);
8163 connman_service_unref(service);
8167 * __connman_service_create_from_provider:
8168 * @provider: provider structure
8170 * Look up service by provider and if not found, create one
8172 struct connman_service *
8173 __connman_service_create_from_provider(struct connman_provider *provider)
8175 struct connman_service *service;
8176 const char *ident, *str;
8178 int index = connman_provider_get_index(provider);
8180 DBG("provider %p", provider);
8182 ident = __connman_provider_get_ident(provider);
8186 name = g_strdup_printf("vpn_%s", ident);
8187 service = service_get(name);
8193 service->type = CONNMAN_SERVICE_TYPE_VPN;
8194 service->provider = connman_provider_ref(provider);
8195 service->autoconnect = false;
8196 service->favorite = true;
8198 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
8199 service->state = combine_state(service->state_ipv4, service->state_ipv6);
8201 str = connman_provider_get_string(provider, "Name");
8203 g_free(service->name);
8204 service->name = g_strdup(str);
8205 service->hidden = false;
8207 g_free(service->name);
8208 service->name = NULL;
8209 service->hidden = true;
8212 service->strength = 0;
8214 if (!service->ipconfig_ipv4)
8215 service->ipconfig_ipv4 = create_ip4config(service, index,
8216 CONNMAN_IPCONFIG_METHOD_MANUAL);
8218 if (!service->ipconfig_ipv6)
8219 service->ipconfig_ipv6 = create_ip6config(service, index);
8221 service_register(service);
8223 __connman_notifier_service_add(service, service->name);
8224 service_schedule_added(service);
8229 static void remove_unprovisioned_services(void)
8232 GKeyFile *keyfile, *configkeyfile;
8233 char *file, *section;
8236 services = connman_storage_get_services();
8240 for (; services[i]; i++) {
8241 file = section = NULL;
8242 keyfile = configkeyfile = NULL;
8244 keyfile = connman_storage_load_service(services[i]);
8248 file = g_key_file_get_string(keyfile, services[i],
8249 "Config.file", NULL);
8253 section = g_key_file_get_string(keyfile, services[i],
8254 "Config.ident", NULL);
8258 configkeyfile = __connman_storage_load_config(file);
8259 if (!configkeyfile) {
8261 * Config file is missing, remove the provisioned
8264 __connman_storage_remove_service(services[i]);
8268 if (!g_key_file_has_group(configkeyfile, section))
8270 * Config section is missing, remove the provisioned
8273 __connman_storage_remove_service(services[i]);
8277 g_key_file_free(keyfile);
8280 g_key_file_free(configkeyfile);
8286 g_strfreev(services);
8289 static int agent_probe(struct connman_agent *agent)
8291 DBG("agent %p", agent);
8295 static void agent_remove(struct connman_agent *agent)
8297 DBG("agent %p", agent);
8300 static void *agent_context_ref(void *context)
8302 struct connman_service *service = context;
8304 return (void *)connman_service_ref(service);
8307 static void agent_context_unref(void *context)
8309 struct connman_service *service = context;
8311 connman_service_unref(service);
8314 static struct connman_agent_driver agent_driver = {
8316 .interface = CONNMAN_AGENT_INTERFACE,
8317 .probe = agent_probe,
8318 .remove = agent_remove,
8319 .context_ref = agent_context_ref,
8320 .context_unref = agent_context_unref,
8323 int __connman_service_init(void)
8329 err = connman_agent_driver_register(&agent_driver);
8331 connman_error("Cannot register agent driver for %s",
8336 connection = connman_dbus_get_connection();
8338 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
8339 NULL, service_free);
8341 services_notify = g_new0(struct _services_notify, 1);
8342 services_notify->remove = g_hash_table_new_full(g_str_hash,
8343 g_str_equal, g_free, NULL);
8344 services_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
8346 remove_unprovisioned_services();
8351 void __connman_service_cleanup(void)
8355 if (vpn_autoconnect_timeout) {
8356 g_source_remove(vpn_autoconnect_timeout);
8357 vpn_autoconnect_timeout = 0;
8360 if (autoconnect_timeout != 0) {
8361 g_source_remove(autoconnect_timeout);
8362 autoconnect_timeout = 0;
8365 connman_agent_driver_unregister(&agent_driver);
8367 g_list_free(service_list);
8368 service_list = NULL;
8370 g_hash_table_destroy(service_hash);
8371 service_hash = NULL;
8373 g_slist_free(counter_list);
8374 counter_list = NULL;
8376 if (services_notify->id != 0) {
8377 g_source_remove(services_notify->id);
8378 service_send_changed(NULL);
8379 g_hash_table_destroy(services_notify->remove);
8380 g_hash_table_destroy(services_notify->add);
8382 g_free(services_notify);
8384 dbus_connection_unref(connection);