5 * Copyright (C) 2007-2010 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
32 #include <connman/storage.h>
36 #define CONNECT_TIMEOUT 120
38 static DBusConnection *connection = NULL;
40 static GSequence *service_list = NULL;
41 static GHashTable *service_hash = NULL;
42 static GSList *counter_list = NULL;
44 struct connman_stats {
46 connman_bool_t enabled;
47 struct connman_stats_data data_last;
48 struct connman_stats_data data;
52 struct connman_stats_counter {
53 connman_bool_t append_all;
54 struct connman_stats stats;
55 struct connman_stats stats_roaming;
58 struct connman_service {
60 int session_usage_count;
63 enum connman_service_type type;
64 enum connman_service_security security;
65 enum connman_service_state state;
66 enum connman_service_state state_ipv4;
67 enum connman_service_state state_ipv6;
68 enum connman_service_error error;
69 connman_uint8_t strength;
70 connman_bool_t favorite;
71 connman_bool_t immutable;
72 connman_bool_t hidden;
73 connman_bool_t ignore;
74 connman_bool_t autoconnect;
75 connman_bool_t userconnect;
80 char *agent_passphrase;
81 connman_bool_t roaming;
82 connman_bool_t login_required;
83 connman_bool_t network_created;
84 struct connman_ipconfig *ipconfig_ipv4;
85 struct connman_ipconfig *ipconfig_ipv6;
86 struct connman_network *network;
87 struct connman_provider *provider;
89 char **nameservers_config;
90 char **nameservers_auto;
94 /* 802.1x settings from the config files */
99 char *client_cert_file;
100 char *private_key_file;
101 char *private_key_passphrase;
103 DBusMessage *pending;
105 struct connman_stats stats;
106 struct connman_stats stats_roaming;
107 GHashTable *counter_table;
108 enum connman_service_proxy_method proxy;
109 enum connman_service_proxy_method proxy_config;
116 static void append_path(gpointer value, gpointer user_data)
118 struct connman_service *service = value;
119 DBusMessageIter *iter = user_data;
121 if (service->path == NULL || service->hidden == TRUE)
124 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
128 void __connman_service_list(DBusMessageIter *iter, void *user_data)
130 if (service_list == NULL)
133 g_sequence_foreach(service_list, append_path, iter);
138 struct connman_service *service;
141 static void compare_path(gpointer value, gpointer user_data)
143 struct connman_service *service = value;
144 struct find_data *data = user_data;
146 if (data->service != NULL)
149 if (g_strcmp0(service->path, data->path) == 0)
150 data->service = service;
153 static struct connman_service *find_service(const char *path)
155 struct find_data data = { .path = path, .service = NULL };
157 DBG("path %s", path);
159 g_sequence_foreach(service_list, compare_path, &data);
164 const char *__connman_service_type2string(enum connman_service_type type)
167 case CONNMAN_SERVICE_TYPE_UNKNOWN:
169 case CONNMAN_SERVICE_TYPE_SYSTEM:
171 case CONNMAN_SERVICE_TYPE_ETHERNET:
173 case CONNMAN_SERVICE_TYPE_WIFI:
175 case CONNMAN_SERVICE_TYPE_WIMAX:
177 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
179 case CONNMAN_SERVICE_TYPE_CELLULAR:
181 case CONNMAN_SERVICE_TYPE_GPS:
183 case CONNMAN_SERVICE_TYPE_VPN:
185 case CONNMAN_SERVICE_TYPE_GADGET:
192 static const char *security2string(enum connman_service_security security)
195 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
197 case CONNMAN_SERVICE_SECURITY_NONE:
199 case CONNMAN_SERVICE_SECURITY_WEP:
201 case CONNMAN_SERVICE_SECURITY_PSK:
203 case CONNMAN_SERVICE_SECURITY_8021X:
205 case CONNMAN_SERVICE_SECURITY_WPA:
207 case CONNMAN_SERVICE_SECURITY_RSN:
214 static const char *state2string(enum connman_service_state state)
217 case CONNMAN_SERVICE_STATE_UNKNOWN:
219 case CONNMAN_SERVICE_STATE_IDLE:
221 case CONNMAN_SERVICE_STATE_ASSOCIATION:
222 return "association";
223 case CONNMAN_SERVICE_STATE_CONFIGURATION:
224 return "configuration";
225 case CONNMAN_SERVICE_STATE_READY:
227 case CONNMAN_SERVICE_STATE_ONLINE:
229 case CONNMAN_SERVICE_STATE_DISCONNECT:
231 case CONNMAN_SERVICE_STATE_FAILURE:
238 static const char *error2string(enum connman_service_error error)
241 case CONNMAN_SERVICE_ERROR_UNKNOWN:
243 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
244 return "out-of-range";
245 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
246 return "pin-missing";
247 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
248 return "dhcp-failed";
249 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
250 return "connect-failed";
251 case CONNMAN_SERVICE_ERROR_LOGIN_FAILED:
252 return "login-failed";
253 case CONNMAN_SERVICE_ERROR_AUTH_FAILED:
254 return "auth-failed";
255 case CONNMAN_SERVICE_ERROR_INVALID_KEY:
256 return "invalid-key";
262 static enum connman_service_error string2error(const char *error)
264 if (g_strcmp0(error, "dhcp-failed") == 0)
265 return CONNMAN_SERVICE_ERROR_DHCP_FAILED;
266 else if (g_strcmp0(error, "pin-missing") == 0)
267 return CONNMAN_SERVICE_ERROR_PIN_MISSING;
268 else if (g_strcmp0(error, "invalid-key") == 0)
269 return CONNMAN_SERVICE_ERROR_INVALID_KEY;
271 return CONNMAN_SERVICE_ERROR_UNKNOWN;
274 static const char *proxymethod2string(enum connman_service_proxy_method method)
277 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
279 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
281 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
283 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
290 static enum connman_service_proxy_method string2proxymethod(const char *method)
292 if (g_strcmp0(method, "direct") == 0)
293 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
294 else if (g_strcmp0(method, "auto") == 0)
295 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
296 else if (g_strcmp0(method, "manual") == 0)
297 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
299 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
302 static int service_load(struct connman_service *service)
305 GError *error = NULL;
308 connman_bool_t autoconnect;
309 unsigned int ssid_len;
312 DBG("service %p", service);
314 keyfile = connman_storage_load_service(service->identifier);
318 switch (service->type) {
319 case CONNMAN_SERVICE_TYPE_UNKNOWN:
320 case CONNMAN_SERVICE_TYPE_SYSTEM:
321 case CONNMAN_SERVICE_TYPE_ETHERNET:
322 case CONNMAN_SERVICE_TYPE_GPS:
323 case CONNMAN_SERVICE_TYPE_VPN:
324 case CONNMAN_SERVICE_TYPE_GADGET:
326 case CONNMAN_SERVICE_TYPE_WIFI:
327 if (service->name == NULL) {
330 name = g_key_file_get_string(keyfile,
331 service->identifier, "Name", NULL);
333 g_free(service->name);
334 service->name = name;
337 if (service->network != NULL)
338 connman_network_set_name(service->network,
342 if (service->network &&
343 connman_network_get_blob(service->network,
344 "WiFi.SSID", &ssid_len) == NULL) {
347 hex_ssid = g_key_file_get_string(keyfile,
351 if (hex_ssid != NULL) {
353 unsigned int i, j = 0, hex;
354 size_t hex_ssid_len = strlen(hex_ssid);
356 ssid = g_try_malloc0(hex_ssid_len / 2);
363 for (i = 0; i < hex_ssid_len; i += 2) {
364 sscanf(hex_ssid + i, "%02x", &hex);
368 connman_network_set_blob(service->network,
369 "WiFi.SSID", ssid, hex_ssid_len / 2);
376 case CONNMAN_SERVICE_TYPE_WIMAX:
377 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
378 case CONNMAN_SERVICE_TYPE_CELLULAR:
379 service->favorite = g_key_file_get_boolean(keyfile,
380 service->identifier, "Favorite", NULL);
382 autoconnect = g_key_file_get_boolean(keyfile,
383 service->identifier, "AutoConnect", &error);
385 service->autoconnect = autoconnect;
386 g_clear_error(&error);
388 str = g_key_file_get_string(keyfile,
389 service->identifier, "Failure", NULL);
391 if (service->favorite == FALSE)
392 service->state_ipv4 = service->state_ipv6 =
393 CONNMAN_SERVICE_STATE_FAILURE;
394 service->error = string2error(str);
400 str = g_key_file_get_string(keyfile,
401 service->identifier, "Modified", NULL);
403 g_time_val_from_iso8601(str, &service->modified);
407 str = g_key_file_get_string(keyfile,
408 service->identifier, "Passphrase", NULL);
410 g_free(service->passphrase);
411 service->passphrase = str;
414 if (service->ipconfig_ipv4 != NULL)
415 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
416 service->identifier, "IPv4.");
418 if (service->ipconfig_ipv6 != NULL)
419 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
420 service->identifier, "IPv6.");
422 service->nameservers_config = g_key_file_get_string_list(keyfile,
423 service->identifier, "Nameservers", &length, NULL);
424 if (service->nameservers_config != NULL && length == 0) {
425 g_strfreev(service->nameservers_config);
426 service->nameservers_config = NULL;
429 service->domains = g_key_file_get_string_list(keyfile,
430 service->identifier, "Domains", &length, NULL);
431 if (service->domains != NULL && length == 0) {
432 g_strfreev(service->domains);
433 service->domains = NULL;
436 str = g_key_file_get_string(keyfile,
437 service->identifier, "Proxy.Method", NULL);
439 service->proxy_config = string2proxymethod(str);
443 service->proxies = g_key_file_get_string_list(keyfile,
444 service->identifier, "Proxy.Servers", &length, NULL);
445 if (service->proxies != NULL && length == 0) {
446 g_strfreev(service->proxies);
447 service->proxies = NULL;
450 service->excludes = g_key_file_get_string_list(keyfile,
451 service->identifier, "Proxy.Excludes", &length, NULL);
452 if (service->excludes != NULL && length == 0) {
453 g_strfreev(service->excludes);
454 service->excludes = NULL;
457 str = g_key_file_get_string(keyfile,
458 service->identifier, "Proxy.URL", NULL);
460 g_free(service->pac);
465 g_key_file_free(keyfile);
470 static int service_save(struct connman_service *service)
475 const char *cst_str = NULL;
478 DBG("service %p", service);
480 keyfile = __connman_storage_open_service(service->identifier);
484 if (service->name != NULL)
485 g_key_file_set_string(keyfile, service->identifier,
486 "Name", service->name);
488 switch (service->type) {
489 case CONNMAN_SERVICE_TYPE_UNKNOWN:
490 case CONNMAN_SERVICE_TYPE_SYSTEM:
491 case CONNMAN_SERVICE_TYPE_ETHERNET:
492 case CONNMAN_SERVICE_TYPE_GPS:
493 case CONNMAN_SERVICE_TYPE_VPN:
494 case CONNMAN_SERVICE_TYPE_GADGET:
496 case CONNMAN_SERVICE_TYPE_WIFI:
497 if (service->network) {
498 const unsigned char *ssid;
499 unsigned int ssid_len = 0;
501 ssid = connman_network_get_blob(service->network,
502 "WiFi.SSID", &ssid_len);
504 if (ssid != NULL && ssid_len > 0 && ssid[0] != '\0') {
505 char *identifier = service->identifier;
509 str = g_string_sized_new(ssid_len * 2);
515 for (i = 0; i < ssid_len; i++)
516 g_string_append_printf(str,
519 g_key_file_set_string(keyfile, identifier,
522 g_string_free(str, TRUE);
525 freq = connman_network_get_frequency(service->network);
526 g_key_file_set_integer(keyfile, service->identifier,
531 case CONNMAN_SERVICE_TYPE_WIMAX:
532 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
533 case CONNMAN_SERVICE_TYPE_CELLULAR:
534 g_key_file_set_boolean(keyfile, service->identifier,
535 "Favorite", service->favorite);
537 if (service->favorite == TRUE)
538 g_key_file_set_boolean(keyfile, service->identifier,
539 "AutoConnect", service->autoconnect);
541 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_FAILURE ||
542 service->state_ipv6 == CONNMAN_SERVICE_STATE_FAILURE) {
543 const char *failure = error2string(service->error);
545 g_key_file_set_string(keyfile,
549 g_key_file_remove_key(keyfile, service->identifier,
555 str = g_time_val_to_iso8601(&service->modified);
557 g_key_file_set_string(keyfile, service->identifier,
562 if (service->passphrase != NULL && strlen(service->passphrase) > 0)
563 g_key_file_set_string(keyfile, service->identifier,
564 "Passphrase", service->passphrase);
566 g_key_file_remove_key(keyfile, service->identifier,
569 if (service->ipconfig_ipv4 != NULL)
570 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
571 service->identifier, "IPv4.");
573 if (service->ipconfig_ipv6 != NULL)
574 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
575 service->identifier, "IPv6.");
577 if (service->nameservers_config != NULL) {
578 guint len = g_strv_length(service->nameservers_config);
580 g_key_file_set_string_list(keyfile, service->identifier,
582 (const gchar **) service->nameservers_config, len);
584 g_key_file_remove_key(keyfile, service->identifier,
585 "Nameservers", NULL);
587 if (service->domains != NULL) {
588 guint len = g_strv_length(service->domains);
590 g_key_file_set_string_list(keyfile, service->identifier,
592 (const gchar **) service->domains, len);
594 g_key_file_remove_key(keyfile, service->identifier,
597 cst_str = proxymethod2string(service->proxy_config);
599 g_key_file_set_string(keyfile, service->identifier,
600 "Proxy.Method", cst_str);
602 if (service->proxies != NULL) {
603 guint len = g_strv_length(service->proxies);
605 g_key_file_set_string_list(keyfile, service->identifier,
607 (const gchar **) service->proxies, len);
609 g_key_file_remove_key(keyfile, service->identifier,
610 "Proxy.Servers", NULL);
612 if (service->excludes != NULL) {
613 guint len = g_strv_length(service->excludes);
615 g_key_file_set_string_list(keyfile, service->identifier,
617 (const gchar **) service->excludes, len);
619 g_key_file_remove_key(keyfile, service->identifier,
620 "Proxy.Excludes", NULL);
622 if (service->pac != NULL && strlen(service->pac) > 0)
623 g_key_file_set_string(keyfile, service->identifier,
624 "Proxy.URL", service->pac);
626 g_key_file_remove_key(keyfile, service->identifier,
630 __connman_storage_save_service(keyfile, service->identifier);
632 g_key_file_free(keyfile);
637 static guint changed_timeout = 0;
639 static gboolean notify_services_changed(gpointer user_data)
643 connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
644 CONNMAN_MANAGER_INTERFACE, "Services",
645 DBUS_TYPE_OBJECT_PATH, __connman_service_list,
651 static void services_changed(gboolean delayed)
655 if (changed_timeout > 0) {
656 g_source_remove(changed_timeout);
660 if (__connman_connection_update_gateway() == TRUE) {
661 notify_services_changed(NULL);
665 if (delayed == FALSE) {
666 notify_services_changed(NULL);
670 changed_timeout = g_timeout_add_seconds(1, notify_services_changed,
674 static enum connman_service_state combine_state(
675 enum connman_service_state state_a,
676 enum connman_service_state state_b)
678 enum connman_service_state result;
680 if (state_a == state_b) {
685 if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
690 if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
695 if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
700 if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
705 if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
710 if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
715 if (state_a == CONNMAN_SERVICE_STATE_READY) {
720 if (state_b == CONNMAN_SERVICE_STATE_READY) {
725 if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
730 if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
735 if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
740 if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
745 if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
750 if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
755 result = CONNMAN_SERVICE_STATE_FAILURE;
761 static connman_bool_t is_connecting_state(struct connman_service *service,
762 enum connman_service_state state)
765 case CONNMAN_SERVICE_STATE_UNKNOWN:
766 case CONNMAN_SERVICE_STATE_IDLE:
767 case CONNMAN_SERVICE_STATE_FAILURE:
768 if (service->network != NULL)
769 return connman_network_get_connecting(service->network);
770 case CONNMAN_SERVICE_STATE_DISCONNECT:
771 case CONNMAN_SERVICE_STATE_READY:
772 case CONNMAN_SERVICE_STATE_ONLINE:
774 case CONNMAN_SERVICE_STATE_ASSOCIATION:
775 case CONNMAN_SERVICE_STATE_CONFIGURATION:
782 static connman_bool_t is_connected_state(const struct connman_service *service,
783 enum connman_service_state state)
786 case CONNMAN_SERVICE_STATE_UNKNOWN:
787 case CONNMAN_SERVICE_STATE_IDLE:
788 case CONNMAN_SERVICE_STATE_ASSOCIATION:
789 case CONNMAN_SERVICE_STATE_CONFIGURATION:
790 case CONNMAN_SERVICE_STATE_DISCONNECT:
791 case CONNMAN_SERVICE_STATE_FAILURE:
793 case CONNMAN_SERVICE_STATE_READY:
794 case CONNMAN_SERVICE_STATE_ONLINE:
801 static connman_bool_t is_connecting(struct connman_service *service)
803 return is_connecting_state(service, service->state);
806 static connman_bool_t is_connected(struct connman_service *service)
808 return is_connected_state(service, service->state);
811 static void update_nameservers(struct connman_service *service)
815 if (service->ipconfig_ipv4)
816 ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv4);
817 else if (service->ipconfig_ipv6)
818 ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv6);
825 switch (combine_state(service->state_ipv4, service->state_ipv6)) {
826 case CONNMAN_SERVICE_STATE_UNKNOWN:
827 case CONNMAN_SERVICE_STATE_IDLE:
828 case CONNMAN_SERVICE_STATE_ASSOCIATION:
829 case CONNMAN_SERVICE_STATE_CONFIGURATION:
831 case CONNMAN_SERVICE_STATE_FAILURE:
832 case CONNMAN_SERVICE_STATE_DISCONNECT:
833 connman_resolver_remove_all(ifname);
835 case CONNMAN_SERVICE_STATE_READY:
836 case CONNMAN_SERVICE_STATE_ONLINE:
840 if (service->nameservers_config != NULL) {
843 for (i = 0; service->nameservers_config[i] != NULL; i++) {
844 connman_resolver_append(ifname, NULL,
845 service->nameservers_config[i]);
847 } else if (service->nameservers != NULL) {
850 for (i = 0; service->nameservers[i] != NULL; i++) {
851 connman_resolver_append(ifname, NULL,
852 service->nameservers[i]);
856 if (service->domains != NULL) {
859 for (i = 0; service->domains[i]; i++)
860 connman_resolver_append(ifname, service->domains[i],
862 } else if (service->domainname != NULL)
863 connman_resolver_append(ifname, service->domainname, NULL);
865 connman_resolver_flush();
869 * The is_auto variable is set to true when IPv6 autoconf nameservers are
870 * inserted to resolver via netlink message (see rtnl.c:rtnl_newnduseropt()
871 * for details) and not through service.c
873 int __connman_service_nameserver_append(struct connman_service *service,
874 const char *nameserver, gboolean is_auto)
879 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
881 if (nameserver == NULL)
885 nameservers = service->nameservers_auto;
887 nameservers = service->nameservers;
889 for (i = 0; nameservers != NULL && nameservers[i] != NULL; i++)
890 if (g_strcmp0(nameservers[i], nameserver) == 0)
893 if (nameservers != NULL) {
894 len = g_strv_length(nameservers);
895 nameservers = g_try_renew(char *, nameservers, len + 2);
898 nameservers = g_try_new0(char *, len + 2);
901 if (nameservers == NULL)
904 nameservers[len] = g_strdup(nameserver);
905 if (nameservers[len] == NULL)
908 nameservers[len + 1] = NULL;
910 if (is_auto == TRUE) {
911 service->nameservers_auto = nameservers;
913 service->nameservers = nameservers;
914 update_nameservers(service);
920 int __connman_service_nameserver_remove(struct connman_service *service,
921 const char *nameserver, gboolean is_auto)
923 char **servers, **nameservers;
924 gboolean found = FALSE;
927 DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
929 if (nameserver == NULL)
933 nameservers = service->nameservers_auto;
935 nameservers = service->nameservers;
937 if (nameservers == NULL)
940 for (i = 0; nameservers != NULL && nameservers[i] != NULL; i++)
941 if (g_strcmp0(nameservers[i], nameserver) == 0) {
949 len = g_strv_length(nameservers);
952 g_strfreev(nameservers);
954 service->nameservers_auto = NULL;
956 service->nameservers = NULL;
961 servers = g_try_new0(char *, len);
965 for (i = 0, j = 0; i < len; i++) {
966 if (g_strcmp0(nameservers[i], nameserver) != 0) {
967 servers[j] = g_strdup(nameservers[i]);
968 if (servers[j] == NULL)
973 servers[len - 1] = NULL;
975 g_strfreev(nameservers);
976 nameservers = servers;
978 if (is_auto == TRUE) {
979 service->nameservers_auto = nameservers;
981 service->nameservers = nameservers;
982 update_nameservers(service);
988 void __connman_service_nameserver_clear(struct connman_service *service)
990 g_strfreev(service->nameservers);
991 service->nameservers = NULL;
993 update_nameservers(service);
996 static void nameserver_add_routes(int index, char **nameservers,
1000 struct addrinfo hints;
1001 struct addrinfo *addr;
1003 for (i = 0; nameservers[i] != NULL; i++) {
1004 memset(&hints, 0, sizeof(struct addrinfo));
1005 hints.ai_flags = AI_NUMERICHOST;
1008 ret = getaddrinfo(nameservers[i], NULL, &hints, &addr);
1009 if (ret == EAI_NONAME)
1010 family = AF_INET; /* use the IPv4 as a default */
1014 family = addr->ai_family;
1016 if (family == AF_INET) {
1017 if (connman_inet_compare_subnet(index,
1018 nameservers[i]) != TRUE)
1019 connman_inet_add_host_route(index,
1020 nameservers[i], gw);
1021 } else if (family == AF_INET6)
1022 connman_inet_add_ipv6_host_route(index,
1023 nameservers[i], gw);
1029 static void nameserver_del_routes(int index, char **nameservers)
1032 struct addrinfo hints;
1033 struct addrinfo *addr;
1035 for (i = 0; nameservers[i] != NULL; i++) {
1036 memset(&hints, 0, sizeof(struct addrinfo));
1037 hints.ai_flags = AI_NUMERICHOST;
1040 ret = getaddrinfo(nameservers[i], NULL, &hints, &addr);
1041 if (ret == EAI_NONAME)
1042 family = AF_INET; /* use the IPv4 as a default */
1046 family = addr->ai_family;
1048 if (family == AF_INET)
1049 connman_inet_del_host_route(index, nameservers[i]);
1050 else if (family == AF_INET6)
1051 connman_inet_del_ipv6_host_route(index,
1058 void __connman_service_nameserver_add_routes(struct connman_service *service,
1063 if (service == NULL)
1066 if (service->network != NULL)
1067 index = connman_network_get_index(service->network);
1068 else if (service->provider != NULL)
1069 index = connman_provider_get_index(service->provider);
1071 if (service->nameservers_config != NULL) {
1073 * Configured nameserver takes preference over the
1074 * discoverd nameserver gathered from DHCP, VPN, etc.
1076 nameserver_add_routes(index, service->nameservers_config, gw);
1077 } else if (service->nameservers != NULL) {
1079 * We add nameservers host routes for nameservers that
1080 * are not on our subnet. For those who are, the subnet
1081 * route will be installed by the time the dns proxy code
1082 * tries to reach them. The subnet route is installed
1083 * when setting the interface IP address.
1085 nameserver_add_routes(index, service->nameservers, gw);
1089 void __connman_service_nameserver_del_routes(struct connman_service *service)
1093 if (service == NULL)
1096 if (service->network != NULL)
1097 index = connman_network_get_index(service->network);
1098 else if (service->provider != NULL)
1099 index = connman_provider_get_index(service->provider);
1101 if (service->nameservers_config != NULL)
1102 nameserver_del_routes(index, service->nameservers_config);
1103 else if (service->nameservers != NULL)
1104 nameserver_del_routes(index, service->nameservers);
1107 static struct connman_stats *stats_get(struct connman_service *service)
1109 if (service->roaming == TRUE)
1110 return &service->stats_roaming;
1112 return &service->stats;
1115 static connman_bool_t stats_enabled(struct connman_service *service)
1117 struct connman_stats *stats = stats_get(service);
1119 return stats->enabled;
1122 static void stats_start(struct connman_service *service)
1124 struct connman_stats *stats = stats_get(service);
1126 DBG("service %p", service);
1128 if (stats->timer == NULL)
1131 stats->enabled = TRUE;
1132 stats->data_last.time = stats->data.time;
1134 g_timer_start(stats->timer);
1137 static void stats_stop(struct connman_service *service)
1139 struct connman_stats *stats = stats_get(service);
1140 unsigned int seconds;
1142 DBG("service %p", service);
1144 if (stats->timer == NULL)
1147 if (stats->enabled == FALSE)
1150 g_timer_stop(stats->timer);
1152 seconds = g_timer_elapsed(stats->timer, NULL);
1153 stats->data.time = stats->data_last.time + seconds;
1155 stats->enabled = FALSE;
1158 static void reset_stats(struct connman_service *service)
1160 DBG("service %p", service);
1163 service->stats.valid = FALSE;
1165 service->stats.data.rx_packets = 0;
1166 service->stats.data.tx_packets = 0;
1167 service->stats.data.rx_bytes = 0;
1168 service->stats.data.tx_bytes = 0;
1169 service->stats.data.rx_errors = 0;
1170 service->stats.data.tx_errors = 0;
1171 service->stats.data.rx_dropped = 0;
1172 service->stats.data.tx_dropped = 0;
1173 service->stats.data.time = 0;
1174 service->stats.data_last.time = 0;
1176 g_timer_reset(service->stats.timer);
1179 service->stats_roaming.valid = FALSE;
1181 service->stats_roaming.data.rx_packets = 0;
1182 service->stats_roaming.data.tx_packets = 0;
1183 service->stats_roaming.data.rx_bytes = 0;
1184 service->stats_roaming.data.tx_bytes = 0;
1185 service->stats_roaming.data.rx_errors = 0;
1186 service->stats_roaming.data.tx_errors = 0;
1187 service->stats_roaming.data.rx_dropped = 0;
1188 service->stats_roaming.data.tx_dropped = 0;
1189 service->stats_roaming.data.time = 0;
1190 service->stats_roaming.data_last.time = 0;
1192 g_timer_reset(service->stats_roaming.timer);
1195 static struct connman_service *get_default(void)
1197 struct connman_service *service;
1198 GSequenceIter *iter;
1200 iter = g_sequence_get_begin_iter(service_list);
1202 if (g_sequence_iter_is_end(iter) == TRUE)
1205 service = g_sequence_get(iter);
1207 if (is_connected(service) == FALSE)
1213 static void default_changed(void)
1215 struct connman_service *service = get_default();
1217 __connman_notifier_default_changed(service);
1220 const char *__connman_service_default(void)
1222 struct connman_service *service;
1224 service = get_default();
1225 if (service == NULL)
1228 return __connman_service_type2string(service->type);
1231 static void state_changed(struct connman_service *service)
1235 __connman_notifier_service_state_changed(service, service->state);
1237 str = state2string(service->state);
1241 connman_dbus_property_changed_basic(service->path,
1242 CONNMAN_SERVICE_INTERFACE, "State",
1243 DBUS_TYPE_STRING, &str);
1246 static void strength_changed(struct connman_service *service)
1248 if (service->strength == 0)
1251 connman_dbus_property_changed_basic(service->path,
1252 CONNMAN_SERVICE_INTERFACE, "Strength",
1253 DBUS_TYPE_BYTE, &service->strength);
1256 static void favorite_changed(struct connman_service *service)
1258 if (service->path == NULL)
1261 connman_dbus_property_changed_basic(service->path,
1262 CONNMAN_SERVICE_INTERFACE, "Favorite",
1263 DBUS_TYPE_BOOLEAN, &service->favorite);
1266 static void immutable_changed(struct connman_service *service)
1268 if (service->path == NULL)
1271 connman_dbus_property_changed_basic(service->path,
1272 CONNMAN_SERVICE_INTERFACE, "Immutable",
1273 DBUS_TYPE_BOOLEAN, &service->immutable);
1276 static void roaming_changed(struct connman_service *service)
1278 if (service->path == NULL)
1281 connman_dbus_property_changed_basic(service->path,
1282 CONNMAN_SERVICE_INTERFACE, "Roaming",
1283 DBUS_TYPE_BOOLEAN, &service->roaming);
1286 static void autoconnect_changed(struct connman_service *service)
1288 if (service->path == NULL)
1291 connman_dbus_property_changed_basic(service->path,
1292 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
1293 DBUS_TYPE_BOOLEAN, &service->autoconnect);
1296 static void passphrase_changed(struct connman_service *service)
1298 dbus_bool_t required;
1300 switch (service->type) {
1301 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1302 case CONNMAN_SERVICE_TYPE_SYSTEM:
1303 case CONNMAN_SERVICE_TYPE_ETHERNET:
1304 case CONNMAN_SERVICE_TYPE_WIMAX:
1305 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1306 case CONNMAN_SERVICE_TYPE_CELLULAR:
1307 case CONNMAN_SERVICE_TYPE_GPS:
1308 case CONNMAN_SERVICE_TYPE_VPN:
1309 case CONNMAN_SERVICE_TYPE_GADGET:
1311 case CONNMAN_SERVICE_TYPE_WIFI:
1314 switch (service->security) {
1315 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1316 case CONNMAN_SERVICE_SECURITY_NONE:
1318 case CONNMAN_SERVICE_SECURITY_WEP:
1319 case CONNMAN_SERVICE_SECURITY_PSK:
1320 case CONNMAN_SERVICE_SECURITY_WPA:
1321 case CONNMAN_SERVICE_SECURITY_RSN:
1322 if (service->passphrase == NULL)
1325 case CONNMAN_SERVICE_SECURITY_8021X:
1331 connman_dbus_property_changed_basic(service->path,
1332 CONNMAN_SERVICE_INTERFACE, "PassphraseRequired",
1333 DBUS_TYPE_BOOLEAN, &required);
1336 static void login_changed(struct connman_service *service)
1338 dbus_bool_t required = service->login_required;
1340 if (service->path == NULL)
1343 connman_dbus_property_changed_basic(service->path,
1344 CONNMAN_SERVICE_INTERFACE, "LoginRequired",
1345 DBUS_TYPE_BOOLEAN, &required);
1348 static void append_security(DBusMessageIter *iter, void *user_data)
1350 struct connman_service *service = user_data;
1353 str = security2string(service->security);
1355 dbus_message_iter_append_basic(iter,
1356 DBUS_TYPE_STRING, &str);
1359 * Some access points incorrectly advertise WPS even when they
1360 * are configured as open or no security, so filter
1363 if (service->wps == TRUE) {
1364 switch (service->security) {
1365 case CONNMAN_SERVICE_SECURITY_PSK:
1366 case CONNMAN_SERVICE_SECURITY_WPA:
1367 case CONNMAN_SERVICE_SECURITY_RSN:
1369 dbus_message_iter_append_basic(iter,
1370 DBUS_TYPE_STRING, &str);
1372 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1373 case CONNMAN_SERVICE_SECURITY_NONE:
1374 case CONNMAN_SERVICE_SECURITY_WEP:
1375 case CONNMAN_SERVICE_SECURITY_8021X:
1381 static void append_ethernet(DBusMessageIter *iter, void *user_data)
1383 struct connman_service *service = user_data;
1385 if (service->ipconfig_ipv4 != NULL)
1386 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
1388 else if (service->ipconfig_ipv6 != NULL)
1389 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
1393 static void append_ipv4(DBusMessageIter *iter, void *user_data)
1395 struct connman_service *service = user_data;
1397 DBG("ipv4 %p state %s", service->ipconfig_ipv4,
1398 state2string(service->state_ipv4));
1400 if (is_connected_state(service, service->state_ipv4) == FALSE)
1403 if (service->ipconfig_ipv4 != NULL)
1404 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
1407 static void append_ipv6(DBusMessageIter *iter, void *user_data)
1409 struct connman_service *service = user_data;
1411 DBG("ipv6 %p state %s", service->ipconfig_ipv6,
1412 state2string(service->state_ipv6));
1414 if (is_connected_state(service, service->state_ipv6) == FALSE)
1417 if (service->ipconfig_ipv6 != NULL)
1418 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
1419 service->ipconfig_ipv4);
1422 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
1424 struct connman_service *service = user_data;
1426 if (service->ipconfig_ipv4 != NULL)
1427 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
1431 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
1433 struct connman_service *service = user_data;
1435 if (service->ipconfig_ipv6 != NULL)
1436 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
1440 static void append_nameserver(DBusMessageIter *iter, char ***nameservers)
1445 servers = *nameservers;
1447 for (i = 0; servers[i] != NULL; i++) {
1448 dbus_message_iter_append_basic(iter,
1449 DBUS_TYPE_STRING, &servers[i]);
1453 static void append_dns(DBusMessageIter *iter, void *user_data)
1455 struct connman_service *service = user_data;
1457 if (is_connected(service) == FALSE)
1460 if (service->nameservers_config != NULL) {
1461 append_nameserver(iter, &service->nameservers_config);
1464 if (service->nameservers != NULL)
1465 append_nameserver(iter, &service->nameservers);
1467 if (service->nameservers_auto != NULL)
1468 append_nameserver(iter, &service->nameservers_auto);
1472 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
1474 struct connman_service *service = user_data;
1477 if (service->nameservers_config == NULL)
1480 for (i = 0; service->nameservers_config[i]; i++) {
1481 dbus_message_iter_append_basic(iter,
1483 &service->nameservers_config[i]);
1487 static void append_domain(DBusMessageIter *iter, void *user_data)
1489 struct connman_service *service = user_data;
1491 if (is_connected(service) == FALSE &&
1492 is_connecting(service) == FALSE)
1495 if (service->domainname == NULL)
1498 dbus_message_iter_append_basic(iter,
1499 DBUS_TYPE_STRING, &service->domainname);
1502 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
1504 struct connman_service *service = user_data;
1507 if (service->domains == NULL)
1510 for (i = 0; service->domains[i]; i++)
1511 dbus_message_iter_append_basic(iter,
1512 DBUS_TYPE_STRING, &service->domains[i]);
1515 static void append_proxies(DBusMessageIter *iter, void *user_data)
1517 struct connman_service *service = user_data;
1520 if (service->proxies == NULL)
1523 for (i = 0; service->proxies[i]; i++)
1524 dbus_message_iter_append_basic(iter,
1525 DBUS_TYPE_STRING, &service->proxies[i]);
1528 static void append_excludes(DBusMessageIter *iter, void *user_data)
1530 struct connman_service *service = user_data;
1533 if (service->excludes == NULL)
1536 for (i = 0; service->excludes[i]; i++)
1537 dbus_message_iter_append_basic(iter,
1538 DBUS_TYPE_STRING, &service->excludes[i]);
1541 static void append_proxy(DBusMessageIter *iter, void *user_data)
1543 struct connman_service *service = user_data;
1544 enum connman_service_proxy_method proxy;
1545 const char *pac = NULL;
1546 const char *method = proxymethod2string(
1547 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
1551 if (is_connected(service) == FALSE)
1554 proxy = connman_service_get_proxy_method(service);
1557 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
1559 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
1561 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
1562 connman_dbus_dict_append_array(iter, "Servers",
1563 DBUS_TYPE_STRING, append_proxies,
1566 connman_dbus_dict_append_array(iter, "Excludes",
1567 DBUS_TYPE_STRING, append_excludes,
1570 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
1571 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
1572 if (service->ipconfig_ipv4 != NULL)
1573 pac = __connman_ipconfig_get_proxy_autoconfig(
1574 service->ipconfig_ipv4);
1575 else if (service->ipconfig_ipv6 != NULL)
1576 pac = __connman_ipconfig_get_proxy_autoconfig(
1577 service->ipconfig_ipv6);
1579 if (service->pac == NULL && pac == NULL)
1582 if (service->pac != NULL)
1585 connman_dbus_dict_append_basic(iter, "URL",
1586 DBUS_TYPE_STRING, &pac);
1590 method = proxymethod2string(proxy);
1593 connman_dbus_dict_append_basic(iter, "Method",
1594 DBUS_TYPE_STRING, &method);
1597 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
1599 struct connman_service *service = user_data;
1602 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
1605 switch (service->proxy_config) {
1606 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
1608 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
1610 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
1611 if (service->proxies != NULL)
1612 connman_dbus_dict_append_array(iter, "Servers",
1614 append_proxies, service);
1616 if (service->excludes != NULL)
1617 connman_dbus_dict_append_array(iter, "Excludes",
1619 append_excludes, service);
1621 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
1622 if (service->pac != NULL)
1623 connman_dbus_dict_append_basic(iter, "URL",
1624 DBUS_TYPE_STRING, &service->pac);
1628 method = proxymethod2string(service->proxy_config);
1630 connman_dbus_dict_append_basic(iter, "Method",
1631 DBUS_TYPE_STRING, &method);
1634 static void append_provider(DBusMessageIter *iter, void *user_data)
1636 struct connman_service *service = user_data;
1638 DBG("%p %p", service, service->provider);
1640 if (is_connected(service) == FALSE)
1643 if (service->provider != NULL)
1644 __connman_provider_append_properties(service->provider, iter);
1648 static void settings_changed(struct connman_service *service,
1649 struct connman_ipconfig *ipconfig)
1651 connman_dbus_property_changed_dict(service->path,
1652 CONNMAN_SERVICE_INTERFACE, "IPv4",
1653 append_ipv4, service);
1655 connman_dbus_property_changed_dict(service->path,
1656 CONNMAN_SERVICE_INTERFACE, "IPv6",
1657 append_ipv6, service);
1659 __connman_notifier_ipconfig_changed(service, ipconfig);
1662 static void ipv4_configuration_changed(struct connman_service *service)
1664 connman_dbus_property_changed_dict(service->path,
1665 CONNMAN_SERVICE_INTERFACE,
1666 "IPv4.Configuration",
1671 static void ipv6_configuration_changed(struct connman_service *service)
1673 connman_dbus_property_changed_dict(service->path,
1674 CONNMAN_SERVICE_INTERFACE,
1675 "IPv6.Configuration",
1680 static void dns_changed(struct connman_service *service)
1682 connman_dbus_property_changed_array(service->path,
1683 CONNMAN_SERVICE_INTERFACE, "Nameservers",
1684 DBUS_TYPE_STRING, append_dns, service);
1687 static void dns_configuration_changed(struct connman_service *service)
1689 connman_dbus_property_changed_array(service->path,
1690 CONNMAN_SERVICE_INTERFACE,
1691 "Nameservers.Configuration",
1692 DBUS_TYPE_STRING, append_dnsconfig, service);
1694 dns_changed(service);
1697 static void domain_changed(struct connman_service *service)
1699 connman_dbus_property_changed_array(service->path,
1700 CONNMAN_SERVICE_INTERFACE, "Domains",
1701 DBUS_TYPE_STRING, append_domain, service);
1704 static void domain_configuration_changed(struct connman_service *service)
1706 connman_dbus_property_changed_array(service->path,
1707 CONNMAN_SERVICE_INTERFACE,
1708 "Domains.Configuration",
1709 DBUS_TYPE_STRING, append_domainconfig, service);
1712 static void proxy_changed(struct connman_service *service)
1714 connman_dbus_property_changed_dict(service->path,
1715 CONNMAN_SERVICE_INTERFACE, "Proxy",
1716 append_proxy, service);
1719 static void proxy_configuration_changed(struct connman_service *service)
1721 connman_dbus_property_changed_dict(service->path,
1722 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
1723 append_proxyconfig, service);
1725 proxy_changed(service);
1728 static void link_changed(struct connman_service *service)
1730 connman_dbus_property_changed_dict(service->path,
1731 CONNMAN_SERVICE_INTERFACE, "Ethernet",
1732 append_ethernet, service);
1735 static void stats_append_counters(DBusMessageIter *dict,
1736 struct connman_stats_data *stats,
1737 struct connman_stats_data *counters,
1738 connman_bool_t append_all)
1740 if (counters->rx_packets != stats->rx_packets || append_all) {
1741 counters->rx_packets = stats->rx_packets;
1742 connman_dbus_dict_append_basic(dict, "RX.Packets",
1743 DBUS_TYPE_UINT32, &stats->rx_packets);
1746 if (counters->tx_packets != stats->tx_packets || append_all) {
1747 counters->tx_packets = stats->tx_packets;
1748 connman_dbus_dict_append_basic(dict, "TX.Packets",
1749 DBUS_TYPE_UINT32, &stats->tx_packets);
1752 if (counters->rx_bytes != stats->rx_bytes || append_all) {
1753 counters->rx_bytes = stats->rx_bytes;
1754 connman_dbus_dict_append_basic(dict, "RX.Bytes",
1755 DBUS_TYPE_UINT32, &stats->rx_bytes);
1758 if (counters->tx_bytes != stats->tx_bytes || append_all) {
1759 counters->tx_bytes = stats->tx_bytes;
1760 connman_dbus_dict_append_basic(dict, "TX.Bytes",
1761 DBUS_TYPE_UINT32, &stats->tx_bytes);
1764 if (counters->rx_errors != stats->rx_errors || append_all) {
1765 counters->rx_errors = stats->rx_errors;
1766 connman_dbus_dict_append_basic(dict, "RX.Errors",
1767 DBUS_TYPE_UINT32, &stats->rx_errors);
1770 if (counters->tx_errors != stats->tx_errors || append_all) {
1771 counters->tx_errors = stats->tx_errors;
1772 connman_dbus_dict_append_basic(dict, "TX.Errors",
1773 DBUS_TYPE_UINT32, &stats->tx_errors);
1776 if (counters->rx_dropped != stats->rx_dropped || append_all) {
1777 counters->rx_dropped = stats->rx_dropped;
1778 connman_dbus_dict_append_basic(dict, "RX.Dropped",
1779 DBUS_TYPE_UINT32, &stats->rx_dropped);
1782 if (counters->tx_dropped != stats->tx_dropped || append_all) {
1783 counters->tx_dropped = stats->tx_dropped;
1784 connman_dbus_dict_append_basic(dict, "TX.Dropped",
1785 DBUS_TYPE_UINT32, &stats->tx_dropped);
1788 if (counters->time != stats->time || append_all) {
1789 counters->time = stats->time;
1790 connman_dbus_dict_append_basic(dict, "Time",
1791 DBUS_TYPE_UINT32, &stats->time);
1795 static void stats_append(struct connman_service *service,
1796 const char *counter,
1797 struct connman_stats_counter *counters,
1798 connman_bool_t append_all)
1800 DBusMessageIter array, dict;
1803 DBG("service %p counter %s", service, counter);
1805 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
1809 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
1810 &service->path, DBUS_TYPE_INVALID);
1812 dbus_message_iter_init_append(msg, &array);
1815 connman_dbus_dict_open(&array, &dict);
1817 stats_append_counters(&dict, &service->stats.data,
1818 &counters->stats.data, append_all);
1820 connman_dbus_dict_close(&array, &dict);
1822 /* roaming counter */
1823 connman_dbus_dict_open(&array, &dict);
1825 stats_append_counters(&dict, &service->stats_roaming.data,
1826 &counters->stats_roaming.data, append_all);
1828 connman_dbus_dict_close(&array, &dict);
1830 __connman_counter_send_usage(counter, msg);
1833 static void stats_update(struct connman_service *service,
1834 unsigned int rx_packets, unsigned int tx_packets,
1835 unsigned int rx_bytes, unsigned int tx_bytes,
1836 unsigned int rx_errors, unsigned int tx_errors,
1837 unsigned int rx_dropped, unsigned int tx_dropped)
1839 struct connman_stats *stats = stats_get(service);
1840 struct connman_stats_data *data_last = &stats->data_last;
1841 struct connman_stats_data *data = &stats->data;
1842 unsigned int seconds;
1844 DBG("service %p", service);
1846 if (stats->valid == TRUE) {
1848 rx_packets - data_last->rx_packets;
1850 tx_packets - data_last->tx_packets;
1852 rx_bytes - data_last->rx_bytes;
1854 tx_bytes - data_last->tx_bytes;
1856 rx_errors - data_last->rx_errors;
1858 tx_errors - data_last->tx_errors;
1860 rx_dropped - data_last->rx_dropped;
1862 tx_dropped - data_last->tx_dropped;
1864 stats->valid = TRUE;
1867 data_last->rx_packets = rx_packets;
1868 data_last->tx_packets = tx_packets;
1869 data_last->rx_bytes = rx_bytes;
1870 data_last->tx_bytes = tx_bytes;
1871 data_last->rx_errors = rx_errors;
1872 data_last->tx_errors = tx_errors;
1873 data_last->rx_dropped = rx_dropped;
1874 data_last->tx_dropped = tx_dropped;
1876 seconds = g_timer_elapsed(stats->timer, NULL);
1877 stats->data.time = stats->data_last.time + seconds;
1880 void __connman_service_notify(struct connman_service *service,
1881 unsigned int rx_packets, unsigned int tx_packets,
1882 unsigned int rx_bytes, unsigned int tx_bytes,
1883 unsigned int rx_errors, unsigned int tx_errors,
1884 unsigned int rx_dropped, unsigned int tx_dropped)
1886 GHashTableIter iter;
1887 gpointer key, value;
1888 const char *counter;
1889 struct connman_stats_counter *counters;
1890 struct connman_stats_data *data;
1893 if (service == NULL)
1896 if (is_connected(service) == FALSE)
1899 stats_update(service,
1900 rx_packets, tx_packets,
1902 rx_errors, tx_errors,
1903 rx_dropped, tx_dropped);
1905 data = &stats_get(service)->data;
1906 err = __connman_stats_update(service, service->roaming, data);
1908 connman_error("Failed to store statistics for %s",
1909 service->identifier);
1911 g_hash_table_iter_init(&iter, service->counter_table);
1912 while (g_hash_table_iter_next(&iter, &key, &value)) {
1916 stats_append(service, counter, counters, counters->append_all);
1917 counters->append_all = FALSE;
1921 int __connman_service_counter_register(const char *counter)
1923 struct connman_service *service;
1924 GSequenceIter *iter;
1925 struct connman_stats_counter *counters;
1927 DBG("counter %s", counter);
1929 counter_list = g_slist_append(counter_list, (gpointer)counter);
1931 iter = g_sequence_get_begin_iter(service_list);
1933 while (g_sequence_iter_is_end(iter) == FALSE) {
1934 service = g_sequence_get(iter);
1936 counters = g_try_new0(struct connman_stats_counter, 1);
1937 if (counters == NULL)
1940 counters->append_all = TRUE;
1942 g_hash_table_replace(service->counter_table, (gpointer)counter,
1945 iter = g_sequence_iter_next(iter);
1951 void __connman_service_counter_unregister(const char *counter)
1953 struct connman_service *service;
1954 GSequenceIter *iter;
1956 DBG("counter %s", counter);
1958 iter = g_sequence_get_begin_iter(service_list);
1960 while (g_sequence_iter_is_end(iter) == FALSE) {
1961 service = g_sequence_get(iter);
1963 g_hash_table_remove(service->counter_table, counter);
1965 iter = g_sequence_iter_next(iter);
1968 counter_list = g_slist_remove(counter_list, counter);
1971 GSequence *__connman_service_get_list(struct connman_session *session,
1972 service_match_cb service_match,
1973 create_service_entry_cb create_service_entry,
1974 GDestroyNotify destroy_service_entry)
1977 GSequenceIter *iter;
1978 struct connman_service *service;
1979 struct service_entry *entry;
1981 list = g_sequence_new(destroy_service_entry);
1985 iter = g_sequence_get_begin_iter(service_list);
1987 while (g_sequence_iter_is_end(iter) == FALSE) {
1988 service = g_sequence_get(iter);
1990 if (service_match(session, service) == TRUE) {
1991 entry = create_service_entry(service, service->name,
1996 g_sequence_append(list, entry);
1999 iter = g_sequence_iter_next(iter);
2005 void __connman_service_session_inc(struct connman_service *service)
2007 DBG("service %p ref count %d", service,
2008 service->session_usage_count + 1);
2010 __sync_fetch_and_add(&service->session_usage_count, 1);
2013 connman_bool_t __connman_service_session_dec(struct connman_service *service)
2015 DBG("service %p ref count %d", service,
2016 service->session_usage_count - 1);
2018 if (__sync_fetch_and_sub(&service->session_usage_count, 1) != 1)
2024 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
2025 struct connman_service *service)
2027 dbus_bool_t required;
2030 str = __connman_service_type2string(service->type);
2032 connman_dbus_dict_append_basic(dict, "Type",
2033 DBUS_TYPE_STRING, &str);
2035 connman_dbus_dict_append_array(dict, "Security",
2036 DBUS_TYPE_STRING, append_security, service);
2038 str = state2string(service->state);
2040 connman_dbus_dict_append_basic(dict, "State",
2041 DBUS_TYPE_STRING, &str);
2043 str = error2string(service->error);
2045 connman_dbus_dict_append_basic(dict, "Error",
2046 DBUS_TYPE_STRING, &str);
2048 if (service->strength > 0)
2049 connman_dbus_dict_append_basic(dict, "Strength",
2050 DBUS_TYPE_BYTE, &service->strength);
2052 connman_dbus_dict_append_basic(dict, "Favorite",
2053 DBUS_TYPE_BOOLEAN, &service->favorite);
2055 connman_dbus_dict_append_basic(dict, "Immutable",
2056 DBUS_TYPE_BOOLEAN, &service->immutable);
2058 if (service->favorite == TRUE)
2059 connman_dbus_dict_append_basic(dict, "AutoConnect",
2060 DBUS_TYPE_BOOLEAN, &service->autoconnect);
2062 connman_dbus_dict_append_basic(dict, "AutoConnect",
2063 DBUS_TYPE_BOOLEAN, &service->favorite);
2065 if (service->name != NULL)
2066 connman_dbus_dict_append_basic(dict, "Name",
2067 DBUS_TYPE_STRING, &service->name);
2069 connman_dbus_dict_append_basic(dict, "LoginRequired",
2070 DBUS_TYPE_BOOLEAN, &service->login_required);
2072 switch (service->type) {
2073 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2074 case CONNMAN_SERVICE_TYPE_SYSTEM:
2075 case CONNMAN_SERVICE_TYPE_GPS:
2076 case CONNMAN_SERVICE_TYPE_VPN:
2077 case CONNMAN_SERVICE_TYPE_GADGET:
2079 case CONNMAN_SERVICE_TYPE_CELLULAR:
2080 connman_dbus_dict_append_basic(dict, "Roaming",
2081 DBUS_TYPE_BOOLEAN, &service->roaming);
2083 connman_dbus_dict_append_dict(dict, "Ethernet",
2084 append_ethernet, service);
2086 case CONNMAN_SERVICE_TYPE_WIFI:
2087 if (service->passphrase != NULL && limited == FALSE)
2088 connman_dbus_dict_append_basic(dict, "Passphrase",
2089 DBUS_TYPE_STRING, &service->passphrase);
2093 switch (service->security) {
2094 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
2095 case CONNMAN_SERVICE_SECURITY_NONE:
2097 case CONNMAN_SERVICE_SECURITY_WEP:
2098 case CONNMAN_SERVICE_SECURITY_PSK:
2099 case CONNMAN_SERVICE_SECURITY_WPA:
2100 case CONNMAN_SERVICE_SECURITY_RSN:
2101 if (service->passphrase == NULL)
2104 case CONNMAN_SERVICE_SECURITY_8021X:
2108 connman_dbus_dict_append_basic(dict, "PassphraseRequired",
2109 DBUS_TYPE_BOOLEAN, &required);
2112 case CONNMAN_SERVICE_TYPE_ETHERNET:
2113 case CONNMAN_SERVICE_TYPE_WIMAX:
2114 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2115 connman_dbus_dict_append_dict(dict, "Ethernet",
2116 append_ethernet, service);
2120 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
2122 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
2123 append_ipv4config, service);
2125 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
2127 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
2128 append_ipv6config, service);
2130 connman_dbus_dict_append_array(dict, "Nameservers",
2131 DBUS_TYPE_STRING, append_dns, service);
2133 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
2134 DBUS_TYPE_STRING, append_dnsconfig, service);
2136 connman_dbus_dict_append_array(dict, "Domains",
2137 DBUS_TYPE_STRING, append_domain, service);
2139 connman_dbus_dict_append_array(dict, "Domains.Configuration",
2140 DBUS_TYPE_STRING, append_domainconfig, service);
2142 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
2144 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
2145 append_proxyconfig, service);
2147 connman_dbus_dict_append_dict(dict, "Provider",
2148 append_provider, service);
2151 static void append_struct(gpointer value, gpointer user_data)
2153 struct connman_service *service = value;
2154 DBusMessageIter *iter = user_data;
2155 DBusMessageIter entry, dict;
2157 if (service->path == NULL || service->hidden == TRUE)
2160 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
2162 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
2165 connman_dbus_dict_open(&entry, &dict);
2166 append_properties(&dict, TRUE, service);
2167 connman_dbus_dict_close(&entry, &dict);
2169 dbus_message_iter_close_container(iter, &entry);
2172 void __connman_service_list_struct(DBusMessageIter *iter)
2174 g_sequence_foreach(service_list, append_struct, iter);
2177 int __connman_service_get_index(struct connman_service *service)
2179 if (service == NULL)
2182 if (service->network != NULL)
2183 return connman_network_get_index(service->network);
2184 else if (service->provider != NULL)
2185 return connman_provider_get_index(service->provider);
2190 void __connman_service_set_domainname(struct connman_service *service,
2191 const char *domainname)
2193 if (service == NULL)
2196 g_free(service->domainname);
2197 service->domainname = g_strdup(domainname);
2199 domain_changed(service);
2202 const char *connman_service_get_domainname(struct connman_service *service)
2204 if (service == NULL)
2207 if (service->domains != NULL)
2208 return service->domains[0];
2210 return service->domainname;
2213 char **connman_service_get_nameservers(struct connman_service *service)
2215 if (service == NULL)
2218 if (service->nameservers_config != NULL)
2219 return service->nameservers_config;
2220 else if (service->nameservers != NULL)
2221 return service->nameservers;
2226 void connman_service_set_proxy_method(struct connman_service *service,
2227 enum connman_service_proxy_method method)
2229 if (service == NULL)
2232 service->proxy = method;
2234 proxy_changed(service);
2236 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
2237 __connman_notifier_proxy_changed(service);
2240 enum connman_service_proxy_method connman_service_get_proxy_method(
2241 struct connman_service *service)
2243 if (service == NULL)
2244 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
2246 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
2247 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
2248 service->pac == NULL)
2249 return service->proxy;
2251 return service->proxy_config;
2254 return service->proxy;
2257 char **connman_service_get_proxy_servers(struct connman_service *service)
2259 return g_strdupv(service->proxies);
2262 char **connman_service_get_proxy_excludes(struct connman_service *service)
2264 return g_strdupv(service->excludes);
2267 const char *connman_service_get_proxy_url(struct connman_service *service)
2269 if (service == NULL)
2272 return service->pac;
2275 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
2278 if (service == NULL)
2281 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
2283 if (service->ipconfig_ipv4) {
2284 if (__connman_ipconfig_set_proxy_autoconfig(
2285 service->ipconfig_ipv4, url) < 0)
2287 } else if (service->ipconfig_ipv6) {
2288 if (__connman_ipconfig_set_proxy_autoconfig(
2289 service->ipconfig_ipv6, url) < 0)
2294 proxy_changed(service);
2296 __connman_notifier_proxy_changed(service);
2299 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
2301 if (service == NULL)
2304 if (service->ipconfig_ipv4)
2305 return __connman_ipconfig_get_proxy_autoconfig(
2306 service->ipconfig_ipv4);
2307 else if (service->ipconfig_ipv6)
2308 return __connman_ipconfig_get_proxy_autoconfig(
2309 service->ipconfig_ipv6);
2313 static void update_timeservers(struct connman_service *service)
2317 if (service->timeservers == NULL)
2320 switch (service->state) {
2321 case CONNMAN_SERVICE_STATE_UNKNOWN:
2322 case CONNMAN_SERVICE_STATE_IDLE:
2323 case CONNMAN_SERVICE_STATE_ASSOCIATION:
2324 case CONNMAN_SERVICE_STATE_CONFIGURATION:
2326 case CONNMAN_SERVICE_STATE_FAILURE:
2327 case CONNMAN_SERVICE_STATE_DISCONNECT:
2328 for (i = 0; service->timeservers[i] != NULL; i++)
2329 connman_timeserver_remove(service->timeservers[i]);
2331 case CONNMAN_SERVICE_STATE_READY:
2332 case CONNMAN_SERVICE_STATE_ONLINE:
2336 for (i = 0; service->timeservers[i] != NULL; i++)
2337 connman_timeserver_append(service->timeservers[i]);
2340 int __connman_service_timeserver_append(struct connman_service *service,
2341 const char *timeserver)
2345 DBG("service %p timeserver %s", service, timeserver);
2347 if (timeserver == NULL)
2350 if (service->timeservers != NULL) {
2353 for (i = 0; service->timeservers[i] != NULL; i++)
2354 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
2357 len = g_strv_length(service->timeservers);
2358 service->timeservers = g_try_renew(char *, service->timeservers,
2362 service->timeservers = g_try_new0(char *, len + 2);
2365 if (service->timeservers == NULL)
2368 service->timeservers[len] = g_strdup(timeserver);
2369 service->timeservers[len + 1] = NULL;
2371 update_timeservers(service);
2376 int __connman_service_timeserver_remove(struct connman_service *service,
2377 const char *timeserver)
2382 DBG("service %p timeserver %s", service, timeserver);
2384 if (timeserver == NULL)
2387 if (service->timeservers == NULL)
2390 len = g_strv_length(service->timeservers);
2392 if (g_strcmp0(service->timeservers[0], timeserver) != 0)
2395 g_strfreev(service->timeservers);
2396 service->timeservers = NULL;
2401 servers = g_try_new0(char *, len - 1);
2402 if (servers == NULL)
2405 for (i = 0, j = 0; i < len; i++) {
2406 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
2407 servers[j] = g_strdup(service->timeservers[i]);
2411 servers[len - 2] = NULL;
2413 g_strfreev(service->timeservers);
2414 service->timeservers = servers;
2416 update_timeservers(service);
2421 void __connman_service_set_pac(struct connman_service *service,
2424 g_free(service->pac);
2425 service->pac = g_strdup(pac);
2427 proxy_changed(service);
2430 void __connman_service_set_identity(struct connman_service *service,
2431 const char *identity)
2433 if (service->immutable)
2436 g_free(service->identity);
2437 service->identity = g_strdup(identity);
2439 if (service->network != NULL)
2440 connman_network_set_string(service->network,
2445 void __connman_service_set_agent_identity(struct connman_service *service,
2446 const char *agent_identity)
2448 g_free(service->agent_identity);
2449 service->agent_identity = g_strdup(agent_identity);
2451 if (service->network != NULL)
2452 connman_network_set_string(service->network,
2453 "WiFi.AgentIdentity",
2454 service->agent_identity);
2457 void __connman_service_set_passphrase(struct connman_service *service,
2458 const char* passphrase)
2460 if (service->immutable == TRUE)
2463 g_free(service->passphrase);
2464 service->passphrase = g_strdup(passphrase);
2466 passphrase_changed(service);
2468 if (service->network != NULL)
2469 connman_network_set_string(service->network,
2471 service->passphrase);
2473 service_save(service);
2476 void __connman_service_set_agent_passphrase(struct connman_service *service,
2477 const char *agent_passphrase)
2479 g_free(service->agent_passphrase);
2480 service->agent_passphrase = g_strdup(agent_passphrase);
2482 if (service->network != NULL)
2483 connman_network_set_string(service->network,
2484 "WiFi.AgentPassphrase",
2485 service->agent_passphrase);
2488 static DBusMessage *get_properties(DBusConnection *conn,
2489 DBusMessage *msg, void *user_data)
2491 struct connman_service *service = user_data;
2493 DBusMessageIter array, dict;
2495 DBG("service %p", service);
2497 reply = dbus_message_new_method_return(msg);
2501 dbus_message_iter_init_append(reply, &array);
2503 connman_dbus_dict_open(&array, &dict);
2504 append_properties(&dict, FALSE, service);
2505 connman_dbus_dict_close(&array, &dict);
2510 static int update_proxy_configuration(struct connman_service *service,
2511 DBusMessageIter *array)
2513 DBusMessageIter dict;
2514 enum connman_service_proxy_method method;
2515 GString *servers_str = NULL;
2516 GString *excludes_str = NULL;
2517 const char *url = NULL;
2519 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
2521 dbus_message_iter_recurse(array, &dict);
2523 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2524 DBusMessageIter entry, variant;
2528 dbus_message_iter_recurse(&dict, &entry);
2530 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2533 dbus_message_iter_get_basic(&entry, &key);
2534 dbus_message_iter_next(&entry);
2536 if (dbus_message_iter_get_arg_type(&entry) !=
2540 dbus_message_iter_recurse(&entry, &variant);
2541 type = dbus_message_iter_get_arg_type(&variant);
2543 if (g_str_equal(key, "Method") == TRUE) {
2546 if (type != DBUS_TYPE_STRING)
2549 dbus_message_iter_get_basic(&variant, &val);
2550 method = string2proxymethod(val);
2551 } else if (g_str_equal(key, "URL") == TRUE) {
2552 if (type != DBUS_TYPE_STRING)
2555 dbus_message_iter_get_basic(&variant, &url);
2556 } else if (g_str_equal(key, "Servers") == TRUE) {
2557 DBusMessageIter str_array;
2559 if (type != DBUS_TYPE_ARRAY)
2562 servers_str = g_string_new(NULL);
2563 if (servers_str == NULL)
2566 dbus_message_iter_recurse(&variant, &str_array);
2568 while (dbus_message_iter_get_arg_type(&str_array) ==
2572 dbus_message_iter_get_basic(&str_array, &val);
2574 if (servers_str->len > 0)
2575 g_string_append_printf(servers_str,
2578 g_string_append(servers_str, val);
2580 dbus_message_iter_next(&str_array);
2582 } else if (g_str_equal(key, "Excludes") == TRUE) {
2583 DBusMessageIter str_array;
2585 if (type != DBUS_TYPE_ARRAY)
2588 excludes_str = g_string_new(NULL);
2589 if (excludes_str == NULL)
2592 dbus_message_iter_recurse(&variant, &str_array);
2594 while (dbus_message_iter_get_arg_type(&str_array) ==
2598 dbus_message_iter_get_basic(&str_array, &val);
2600 if (excludes_str->len > 0)
2601 g_string_append_printf(excludes_str,
2604 g_string_append(excludes_str, val);
2606 dbus_message_iter_next(&str_array);
2610 dbus_message_iter_next(&dict);
2614 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2616 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2617 if (servers_str == NULL && service->proxies == NULL)
2620 if (servers_str != NULL) {
2621 g_strfreev(service->proxies);
2623 if (servers_str->len > 0)
2624 service->proxies = g_strsplit_set(
2625 servers_str->str, " ", 0);
2627 service->proxies = NULL;
2630 if (excludes_str != NULL) {
2631 g_strfreev(service->excludes);
2633 if (excludes_str->len > 0)
2634 service->excludes = g_strsplit_set(
2635 excludes_str->str, " ", 0);
2637 service->excludes = NULL;
2640 if (service->proxies == NULL)
2641 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
2644 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2645 g_free(service->pac);
2647 if (url != NULL && strlen(url) > 0)
2648 service->pac = g_strdup(url);
2650 service->pac = NULL;
2652 /* if we are connected:
2653 - if service->pac == NULL
2654 - if __connman_ipconfig_get_proxy_autoconfig(
2655 service->ipconfig) == NULL
2656 --> We should start WPAD */
2659 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2663 if (servers_str != NULL)
2664 g_string_free(servers_str, TRUE);
2666 if (excludes_str != NULL)
2667 g_string_free(excludes_str, TRUE);
2669 service->proxy_config = method;
2674 if (servers_str != NULL)
2675 g_string_free(servers_str, TRUE);
2677 if (excludes_str != NULL)
2678 g_string_free(excludes_str, TRUE);
2683 static int set_ipconfig(struct connman_service *service,
2684 struct connman_ipconfig *ipconfig,
2685 DBusMessageIter *array,
2686 enum connman_service_state state,
2687 enum connman_service_state *new_state)
2689 enum connman_ipconfig_method old_method;
2690 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
2691 enum connman_ipconfig_type type;
2694 if (ipconfig == NULL)
2697 old_method = __connman_ipconfig_get_method(ipconfig);
2699 if (is_connecting_state(service, state) ||
2700 is_connected_state(service, state))
2701 __connman_network_clear_ipconfig(service->network, ipconfig);
2703 err = __connman_ipconfig_set_config(ipconfig, array);
2704 method = __connman_ipconfig_get_method(ipconfig);
2705 type = __connman_ipconfig_get_config_type(ipconfig);
2707 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
2708 if (err == 0 && old_method == CONNMAN_IPCONFIG_METHOD_OFF &&
2709 method == CONNMAN_IPCONFIG_METHOD_DHCP) {
2710 *new_state = service->state_ipv4 =
2711 CONNMAN_SERVICE_STATE_CONFIGURATION;
2712 __connman_ipconfig_enable(ipconfig);
2715 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
2716 if (err == 0 && old_method == CONNMAN_IPCONFIG_METHOD_OFF &&
2717 method == CONNMAN_IPCONFIG_METHOD_AUTO) {
2718 *new_state = service->state_ipv6;
2719 __connman_ipconfig_enable(ipconfig);
2723 DBG("err %d ipconfig %p type %d method %d state %s", err, ipconfig,
2724 type, method, state2string(*new_state));
2729 static DBusMessage *set_property(DBusConnection *conn,
2730 DBusMessage *msg, void *user_data)
2732 struct connman_service *service = user_data;
2733 DBusMessageIter iter, value;
2737 DBG("service %p", service);
2739 if (dbus_message_iter_init(msg, &iter) == FALSE)
2740 return __connman_error_invalid_arguments(msg);
2742 dbus_message_iter_get_basic(&iter, &name);
2743 dbus_message_iter_next(&iter);
2744 dbus_message_iter_recurse(&iter, &value);
2746 type = dbus_message_iter_get_arg_type(&value);
2748 if (g_str_equal(name, "AutoConnect") == TRUE) {
2749 connman_bool_t autoconnect;
2751 if (type != DBUS_TYPE_BOOLEAN)
2752 return __connman_error_invalid_arguments(msg);
2754 if (service->favorite == FALSE)
2755 return __connman_error_invalid_service(msg);
2757 dbus_message_iter_get_basic(&value, &autoconnect);
2759 if (service->autoconnect == autoconnect)
2760 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2762 service->autoconnect = autoconnect;
2764 autoconnect_changed(service);
2766 service_save(service);
2767 } else if (g_str_equal(name, "Passphrase") == TRUE) {
2768 const char *passphrase;
2770 if (type != DBUS_TYPE_STRING)
2771 return __connman_error_invalid_arguments(msg);
2773 if (service->immutable == TRUE)
2774 return __connman_error_not_supported(msg);
2776 dbus_message_iter_get_basic(&value, &passphrase);
2778 __connman_service_set_passphrase(service, passphrase);
2779 } else if (g_str_equal(name, "Nameservers.Configuration") == TRUE) {
2780 DBusMessageIter entry;
2785 if (type != DBUS_TYPE_ARRAY)
2786 return __connman_error_invalid_arguments(msg);
2788 str = g_string_new(NULL);
2790 return __connman_error_invalid_arguments(msg);
2792 index = connman_network_get_index(service->network);
2793 gw = __connman_ipconfig_get_gateway_from_index(index);
2795 if (gw && strlen(gw))
2796 __connman_service_nameserver_del_routes(service);
2798 dbus_message_iter_recurse(&value, &entry);
2800 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
2802 dbus_message_iter_get_basic(&entry, &val);
2803 dbus_message_iter_next(&entry);
2805 g_string_append_printf(str, " %s", val);
2807 g_string_append(str, val);
2810 g_strfreev(service->nameservers_config);
2813 service->nameservers_config =
2814 g_strsplit_set(str->str, " ", 0);
2816 service->nameservers_config = NULL;
2819 g_string_free(str, TRUE);
2821 if (gw && strlen(gw))
2822 __connman_service_nameserver_add_routes(service, gw);
2824 update_nameservers(service);
2825 dns_configuration_changed(service);
2827 service_save(service);
2828 } else if (g_str_equal(name, "Domains.Configuration") == TRUE) {
2829 DBusMessageIter entry;
2832 if (type != DBUS_TYPE_ARRAY)
2833 return __connman_error_invalid_arguments(msg);
2835 str = g_string_new(NULL);
2837 return __connman_error_invalid_arguments(msg);
2839 dbus_message_iter_recurse(&value, &entry);
2841 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
2843 dbus_message_iter_get_basic(&entry, &val);
2844 dbus_message_iter_next(&entry);
2846 g_string_append_printf(str, " %s", val);
2848 g_string_append(str, val);
2851 g_strfreev(service->domains);
2854 service->domains = g_strsplit_set(str->str, " ", 0);
2856 service->domains = NULL;
2858 g_string_free(str, TRUE);
2860 update_nameservers(service);
2861 domain_configuration_changed(service);
2863 service_save(service);
2864 } else if (g_str_equal(name, "Proxy.Configuration") == TRUE) {
2867 if (type != DBUS_TYPE_ARRAY)
2868 return __connman_error_invalid_arguments(msg);
2870 err = update_proxy_configuration(service, &value);
2873 return __connman_error_failed(msg, -err);
2875 proxy_configuration_changed(service);
2877 __connman_notifier_proxy_changed(service);
2879 service_save(service);
2880 } else if (g_str_equal(name, "IPv4.Configuration") == TRUE ||
2881 g_str_equal(name, "IPv6.Configuration")) {
2883 struct connman_ipconfig *ipv4 = NULL, *ipv6 = NULL;
2884 enum connman_service_state state =
2885 CONNMAN_SERVICE_STATE_UNKNOWN;
2890 if (service->ipconfig_ipv4 == NULL &&
2891 service->ipconfig_ipv6 == NULL)
2892 return __connman_error_invalid_property(msg);
2894 if (g_str_equal(name, "IPv4.Configuration") == TRUE) {
2895 ipv4 = service->ipconfig_ipv4;
2896 err = set_ipconfig(service, ipv4, &value,
2897 service->state_ipv4, &state);
2899 } else if (g_str_equal(name, "IPv6.Configuration") == TRUE) {
2900 ipv6 = service->ipconfig_ipv6;
2901 err = set_ipconfig(service, ipv6, &value,
2902 service->state_ipv6, &state);
2906 if (is_connected_state(service, state) ||
2907 is_connecting_state(service, state))
2908 __connman_network_set_ipconfig(service->network,
2910 return __connman_error_failed(msg, -err);
2914 ipv4_configuration_changed(service);
2916 ipv6_configuration_changed(service);
2918 if (is_connecting(service) || is_connected(service))
2919 __connman_network_set_ipconfig(service->network,
2922 service_save(service);
2924 return __connman_error_invalid_property(msg);
2926 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2929 static void set_idle(struct connman_service *service)
2931 service->state = service->state_ipv4 = service->state_ipv6 =
2932 CONNMAN_SERVICE_STATE_IDLE;
2933 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
2934 state_changed(service);
2937 static DBusMessage *clear_property(DBusConnection *conn,
2938 DBusMessage *msg, void *user_data)
2940 struct connman_service *service = user_data;
2943 DBG("service %p", service);
2945 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
2948 if (g_str_equal(name, "Error") == TRUE) {
2951 g_get_current_time(&service->modified);
2952 service_save(service);
2953 } else if (g_str_equal(name, "Passphrase") == TRUE) {
2954 if (service->immutable == TRUE)
2955 return __connman_error_not_supported(msg);
2957 g_free(service->passphrase);
2958 service->passphrase = NULL;
2960 passphrase_changed(service);
2962 service_save(service);
2964 return __connman_error_invalid_property(msg);
2966 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2969 static connman_bool_t is_ignore(struct connman_service *service)
2971 if (service->autoconnect == FALSE)
2974 if (service->roaming == TRUE)
2977 if (service->ignore == TRUE)
2980 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
2986 void __connman_service_auto_connect(void)
2988 struct connman_service *service = NULL;
2989 GSequenceIter *iter;
2993 if (__connman_session_mode() == TRUE) {
2994 DBG("Session mode enabled: auto connect disabled");
2998 iter = g_sequence_get_begin_iter(service_list);
3000 while (g_sequence_iter_is_end(iter) == FALSE) {
3001 service = g_sequence_get(iter);
3003 if (service->pending != NULL)
3006 if (is_connecting(service) == TRUE)
3009 if (service->favorite == FALSE)
3012 if (is_connected(service) == TRUE)
3015 if (is_ignore(service) == FALSE && service->state ==
3016 CONNMAN_SERVICE_STATE_IDLE)
3021 iter = g_sequence_iter_next(iter);
3024 if (service != NULL) {
3025 service->userconnect = FALSE;
3026 __connman_service_connect(service);
3030 static void remove_timeout(struct connman_service *service)
3032 if (service->timeout > 0) {
3033 g_source_remove(service->timeout);
3034 service->timeout = 0;
3038 static void reply_pending(struct connman_service *service, int error)
3040 remove_timeout(service);
3042 if (service->pending != NULL) {
3046 reply = __connman_error_failed(service->pending,
3049 g_dbus_send_message(connection, reply);
3053 sender = dbus_message_get_interface(service->pending);
3055 DBG("sender %s", sender);
3057 if (g_strcmp0(sender, CONNMAN_MANAGER_INTERFACE) == 0)
3058 g_dbus_send_reply(connection, service->pending,
3059 DBUS_TYPE_OBJECT_PATH, &service->path,
3062 g_dbus_send_reply(connection, service->pending,
3066 dbus_message_unref(service->pending);
3067 service->pending = NULL;
3071 static gboolean connect_timeout(gpointer user_data)
3073 struct connman_service *service = user_data;
3074 connman_bool_t autoconnect = FALSE;
3076 DBG("service %p", service);
3078 service->timeout = 0;
3080 if (service->network != NULL)
3081 __connman_network_disconnect(service->network);
3083 __connman_ipconfig_disable(service->ipconfig_ipv4);
3084 __connman_ipconfig_disable(service->ipconfig_ipv6);
3086 __connman_stats_service_unregister(service);
3088 if (service->pending != NULL) {
3091 reply = __connman_error_operation_timeout(service->pending);
3093 g_dbus_send_message(connection, reply);
3095 dbus_message_unref(service->pending);
3096 service->pending = NULL;
3100 __connman_service_ipconfig_indicate_state(service,
3101 CONNMAN_SERVICE_STATE_FAILURE,
3102 CONNMAN_IPCONFIG_TYPE_IPV4);
3103 __connman_service_ipconfig_indicate_state(service,
3104 CONNMAN_SERVICE_STATE_FAILURE,
3105 CONNMAN_IPCONFIG_TYPE_IPV6);
3107 if (autoconnect == TRUE && service->userconnect == FALSE)
3108 __connman_service_auto_connect();
3113 static void set_reconnect_state(struct connman_service *service,
3114 connman_bool_t reconnect)
3116 struct connman_device *device;
3118 if (service->network == NULL)
3121 device = connman_network_get_device(service->network);
3125 __connman_device_set_reconnect(device, reconnect);
3128 static connman_bool_t get_reconnect_state(struct connman_service *service)
3130 struct connman_device *device;
3132 if (service->network == NULL)
3135 device = connman_network_get_device(service->network);
3139 return __connman_device_get_reconnect(device);
3142 static DBusMessage *connect_service(DBusConnection *conn,
3143 DBusMessage *msg, void *user_data)
3145 struct connman_service *service = user_data;
3146 GSequenceIter *iter;
3149 DBG("service %p", service);
3151 if (service->pending != NULL)
3152 return __connman_error_in_progress(msg);
3154 iter = g_sequence_get_begin_iter(service_list);
3156 while (g_sequence_iter_is_end(iter) == FALSE) {
3157 struct connman_service *temp = g_sequence_get(iter);
3159 if (service->type == temp->type && is_connecting(temp) == TRUE)
3160 return __connman_error_in_progress(msg);
3162 iter = g_sequence_iter_next(iter);
3165 service->ignore = FALSE;
3167 service->userconnect = TRUE;
3169 service->pending = dbus_message_ref(msg);
3171 set_reconnect_state(service, FALSE);
3173 err = __connman_service_connect(service);
3175 if (service->pending == NULL)
3178 if (err != -EINPROGRESS) {
3179 dbus_message_unref(service->pending);
3180 service->pending = NULL;
3182 return __connman_error_failed(msg, -err);
3188 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3191 static DBusMessage *disconnect_service(DBusConnection *conn,
3192 DBusMessage *msg, void *user_data)
3194 struct connman_service *service = user_data;
3197 DBG("service %p", service);
3199 reply_pending(service, ECONNABORTED);
3201 service->ignore = TRUE;
3203 set_reconnect_state(service, FALSE);
3205 err = __connman_service_disconnect(service);
3207 if (err != -EINPROGRESS)
3208 return __connman_error_failed(msg, -err);
3213 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3216 static DBusMessage *remove_service(DBusConnection *conn,
3217 DBusMessage *msg, void *user_data)
3219 struct connman_service *service = user_data;
3221 DBG("service %p", service);
3223 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
3224 return __connman_error_not_supported(msg);
3226 if (service->immutable == TRUE)
3227 return __connman_error_not_supported(msg);
3229 if (service->favorite == FALSE && service->state !=
3230 CONNMAN_SERVICE_STATE_FAILURE)
3231 return __connman_error_not_supported(msg);
3233 set_reconnect_state(service, FALSE);
3235 __connman_service_disconnect(service);
3237 g_free(service->passphrase);
3238 service->passphrase = NULL;
3240 passphrase_changed(service);
3244 __connman_service_set_favorite(service, FALSE);
3245 service_save(service);
3247 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3250 static gboolean check_suitable_state(enum connman_service_state a,
3251 enum connman_service_state b)
3254 * Special check so that "ready" service can be moved before
3257 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
3258 b == CONNMAN_SERVICE_STATE_READY) ||
3259 (b == CONNMAN_SERVICE_STATE_ONLINE &&
3260 a == CONNMAN_SERVICE_STATE_READY))
3266 static void downgrade_state(struct connman_service *service)
3268 if (service == NULL)
3271 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
3272 service->state_ipv6);
3274 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
3275 __connman_service_ipconfig_indicate_state(service,
3276 CONNMAN_SERVICE_STATE_READY,
3277 CONNMAN_IPCONFIG_TYPE_IPV4);
3279 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
3280 __connman_service_ipconfig_indicate_state(service,
3281 CONNMAN_SERVICE_STATE_READY,
3282 CONNMAN_IPCONFIG_TYPE_IPV6);
3285 static void apply_relevant_default_downgrade(struct connman_service *service)
3287 struct connman_service *def_service;
3289 def_service = get_default();
3290 if (def_service == NULL)
3293 if (def_service == service &&
3294 def_service->state == CONNMAN_SERVICE_STATE_ONLINE)
3295 def_service->state = CONNMAN_SERVICE_STATE_READY;
3298 static DBusMessage *move_service(DBusConnection *conn,
3299 DBusMessage *msg, void *user_data,
3302 struct connman_service *service = user_data;
3303 struct connman_service *target;
3305 GSequenceIter *src, *dst;
3306 enum connman_ipconfig_method target4, target6;
3307 enum connman_ipconfig_method service4, service6;
3309 DBG("service %p", service);
3311 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
3314 if (service->favorite == FALSE)
3315 return __connman_error_not_supported(msg);
3317 target = find_service(path);
3318 if (target == NULL || target->favorite == FALSE || target == service ||
3319 target->type == CONNMAN_SERVICE_TYPE_VPN)
3320 return __connman_error_invalid_service(msg);
3322 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
3323 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
3324 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
3325 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
3327 DBG("target %s method %d/%d state %d/%d", target->identifier,
3329 target->state_ipv4, target->state_ipv6);
3331 DBG("service %s method %d/%d state %d/%d", service->identifier,
3333 service->state_ipv4, service->state_ipv6);
3336 * If method is OFF, then we do not need to check the corresponding
3339 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
3340 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
3341 if (check_suitable_state(target->state_ipv6,
3342 service->state_ipv6) == FALSE)
3343 return __connman_error_invalid_service(msg);
3347 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
3348 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
3349 if (check_suitable_state(target->state_ipv4,
3350 service->state_ipv4) == FALSE)
3351 return __connman_error_invalid_service(msg);
3355 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
3356 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
3357 if (check_suitable_state(target->state_ipv6,
3358 service->state_ipv6) == FALSE)
3359 return __connman_error_invalid_service(msg);
3363 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
3364 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
3365 if (check_suitable_state(target->state_ipv4,
3366 service->state_ipv4) == FALSE)
3367 return __connman_error_invalid_service(msg);
3371 g_get_current_time(&service->modified);
3372 service_save(service);
3374 src = g_hash_table_lookup(service_hash, service->identifier);
3375 dst = g_hash_table_lookup(service_hash, target->identifier);
3378 * If the service which goes down is the default service and is
3379 * online, we downgrade directly its state to ready so:
3380 * the service which goes up, needs to recompute its state which
3381 * is triggered via downgrading it - if relevant - to state ready.
3383 if (before == TRUE) {
3384 apply_relevant_default_downgrade(target);
3385 g_sequence_move(src, dst);
3386 downgrade_state(service);
3388 apply_relevant_default_downgrade(service);
3389 g_sequence_move(dst, src);
3390 downgrade_state(target);
3393 services_changed(FALSE);
3395 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3398 static DBusMessage *move_before(DBusConnection *conn,
3399 DBusMessage *msg, void *user_data)
3401 return move_service(conn, msg, user_data, TRUE);
3404 static DBusMessage *move_after(DBusConnection *conn,
3405 DBusMessage *msg, void *user_data)
3407 return move_service(conn, msg, user_data, FALSE);
3410 static DBusMessage *reset_counters(DBusConnection *conn,
3411 DBusMessage *msg, void *user_data)
3413 struct connman_service *service = user_data;
3415 reset_stats(service);
3417 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3420 static GDBusMethodTable service_methods[] = {
3421 { "GetProperties", "", "a{sv}", get_properties },
3422 { "SetProperty", "sv", "", set_property },
3423 { "ClearProperty", "s", "", clear_property },
3424 { "Connect", "", "", connect_service,
3425 G_DBUS_METHOD_FLAG_ASYNC },
3426 { "Disconnect", "", "", disconnect_service },
3427 { "Remove", "", "", remove_service },
3428 { "MoveBefore", "o", "", move_before },
3429 { "MoveAfter", "o", "", move_after },
3430 { "ResetCounters", "", "", reset_counters },
3434 static GDBusSignalTable service_signals[] = {
3435 { "PropertyChanged", "sv" },
3439 static void service_free(gpointer user_data)
3441 struct connman_service *service = user_data;
3442 char *path = service->path;
3444 DBG("service %p", service);
3446 reply_pending(service, ENOENT);
3448 g_hash_table_remove(service_hash, service->identifier);
3450 __connman_notifier_service_remove(service);
3452 stats_stop(service);
3454 service->path = NULL;
3457 services_changed(FALSE);
3459 g_dbus_unregister_interface(connection, path,
3460 CONNMAN_SERVICE_INTERFACE);
3464 g_hash_table_destroy(service->counter_table);
3466 if (service->network != NULL) {
3467 if (service->network_created == TRUE)
3468 connman_network_unref(service->network);
3471 if (service->provider != NULL)
3472 connman_provider_unref(service->provider);
3474 if (service->ipconfig_ipv4 != NULL) {
3475 connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
3476 connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
3477 connman_ipconfig_unref(service->ipconfig_ipv4);
3478 service->ipconfig_ipv4 = NULL;
3481 if (service->ipconfig_ipv6 != NULL) {
3482 connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
3483 connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
3484 connman_ipconfig_unref(service->ipconfig_ipv6);
3485 service->ipconfig_ipv6 = NULL;
3488 g_strfreev(service->nameservers);
3489 g_strfreev(service->nameservers_config);
3490 g_strfreev(service->nameservers_auto);
3491 g_strfreev(service->domains);
3492 g_strfreev(service->proxies);
3493 g_strfreev(service->excludes);
3495 g_free(service->domainname);
3496 g_free(service->pac);
3497 g_free(service->name);
3498 g_free(service->passphrase);
3499 g_free(service->agent_passphrase);
3500 g_free(service->identifier);
3501 g_free(service->eap);
3502 g_free(service->identity);
3503 g_free(service->agent_identity);
3504 g_free(service->ca_cert_file);
3505 g_free(service->client_cert_file);
3506 g_free(service->private_key_file);
3507 g_free(service->private_key_passphrase);
3508 g_free(service->phase2);
3510 if (service->stats.timer != NULL)
3511 g_timer_destroy(service->stats.timer);
3512 if (service->stats_roaming.timer != NULL)
3513 g_timer_destroy(service->stats_roaming.timer);
3519 * __connman_service_put:
3520 * @service: service structure
3522 * Release service if no longer needed
3524 void __connman_service_put(struct connman_service *service)
3526 GSequenceIter *iter;
3528 DBG("service %p", service);
3530 if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
3533 iter = g_hash_table_lookup(service_hash, service->identifier);
3535 reply_pending(service, ECONNABORTED);
3537 __connman_service_disconnect(service);
3539 g_sequence_remove(iter);
3541 service_free(service);
3545 static void stats_init(struct connman_service *service)
3548 service->stats.valid = FALSE;
3549 service->stats.enabled = FALSE;
3550 service->stats.timer = g_timer_new();
3553 service->stats_roaming.valid = FALSE;
3554 service->stats_roaming.enabled = FALSE;
3555 service->stats_roaming.timer = g_timer_new();
3558 static void service_initialize(struct connman_service *service)
3560 DBG("service %p", service);
3562 service->refcount = 1;
3563 service->session_usage_count = 0;
3565 service->network_created = FALSE;
3567 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
3568 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
3570 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
3571 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
3572 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
3574 service->favorite = FALSE;
3575 service->immutable = FALSE;
3576 service->hidden = FALSE;
3578 service->ignore = FALSE;
3580 service->userconnect = FALSE;
3584 stats_init(service);
3586 service->provider = NULL;
3588 service->wps = FALSE;
3592 * connman_service_create:
3594 * Allocate a new service.
3596 * Returns: a newly-allocated #connman_service structure
3598 struct connman_service *connman_service_create(void)
3601 struct connman_stats_counter *counters;
3602 const char *counter;
3604 struct connman_service *service;
3606 service = g_try_new0(struct connman_service, 1);
3607 if (service == NULL)
3610 DBG("service %p", service);
3612 service->counter_table = g_hash_table_new_full(g_str_hash,
3613 g_str_equal, NULL, g_free);
3615 for (list = counter_list; list; list = list->next) {
3616 counter = list->data;
3618 counters = g_try_new0(struct connman_stats_counter, 1);
3619 if (counters == NULL) {
3620 g_hash_table_destroy(service->counter_table);
3625 counters->append_all = TRUE;
3627 g_hash_table_replace(service->counter_table, (gpointer)counter,
3631 service_initialize(service);
3637 * connman_service_ref:
3638 * @service: service structure
3640 * Increase reference counter of service
3642 struct connman_service *connman_service_ref(struct connman_service *service)
3646 __sync_fetch_and_add(&service->refcount, 1);
3652 * connman_service_unref:
3653 * @service: service structure
3655 * Decrease reference counter of service
3657 void connman_service_unref(struct connman_service *service)
3659 __connman_service_put(service);
3662 static gint service_compare(gconstpointer a, gconstpointer b,
3665 struct connman_service *service_a = (void *) a;
3666 struct connman_service *service_b = (void *) b;
3667 enum connman_service_state state_a, state_b;
3669 state_a = service_a->state;
3670 state_b = service_b->state;
3672 if (state_a != state_b) {
3673 gboolean a_connected = is_connected(service_a);
3674 gboolean b_connected = is_connected(service_b);
3676 if (a_connected == TRUE && b_connected == TRUE) {
3677 /* We prefer online over ready state */
3678 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
3681 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
3685 if (a_connected == TRUE)
3687 if (b_connected == TRUE)
3690 if (is_connecting(service_a) == TRUE)
3692 if (is_connecting(service_b) == TRUE)
3696 if (service_a->order > service_b->order)
3699 if (service_a->order < service_b->order)
3702 if (service_a->favorite == TRUE && service_b->favorite == FALSE)
3705 if (service_a->favorite == FALSE && service_b->favorite == TRUE)
3708 if (service_a->type != service_b->type) {
3709 switch (service_a->type) {
3710 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3711 case CONNMAN_SERVICE_TYPE_SYSTEM:
3712 case CONNMAN_SERVICE_TYPE_ETHERNET:
3713 case CONNMAN_SERVICE_TYPE_GPS:
3714 case CONNMAN_SERVICE_TYPE_VPN:
3715 case CONNMAN_SERVICE_TYPE_GADGET:
3717 case CONNMAN_SERVICE_TYPE_WIFI:
3719 case CONNMAN_SERVICE_TYPE_WIMAX:
3720 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3721 case CONNMAN_SERVICE_TYPE_CELLULAR:
3726 return (gint) service_b->strength - (gint) service_a->strength;
3730 * connman_service_get_type:
3731 * @service: service structure
3733 * Get the type of service
3735 enum connman_service_type connman_service_get_type(struct connman_service *service)
3737 if (service == NULL)
3738 return CONNMAN_SERVICE_TYPE_UNKNOWN;
3740 return service->type;
3744 * connman_service_get_interface:
3745 * @service: service structure
3747 * Get network interface of service
3749 char *connman_service_get_interface(struct connman_service *service)
3753 if (service == NULL)
3756 if (service->type == CONNMAN_SERVICE_TYPE_VPN) {
3757 if (service->ipconfig_ipv4)
3758 index = connman_ipconfig_get_index(
3759 service->ipconfig_ipv4);
3760 else if (service->ipconfig_ipv6)
3761 index = connman_ipconfig_get_index(
3762 service->ipconfig_ipv6);
3766 return connman_inet_ifname(index);
3769 if (service->network == NULL)
3772 index = connman_network_get_index(service->network);
3774 return connman_inet_ifname(index);
3778 * connman_service_get_network:
3779 * @service: service structure
3781 * Get the service network
3783 struct connman_network *
3784 __connman_service_get_network(struct connman_service *service)
3786 if (service == NULL)
3789 return service->network;
3792 struct connman_ipconfig *
3793 __connman_service_get_ip4config(struct connman_service *service)
3795 if (service == NULL)
3798 return service->ipconfig_ipv4;
3801 struct connman_ipconfig *
3802 __connman_service_get_ip6config(struct connman_service *service)
3804 if (service == NULL)
3807 return service->ipconfig_ipv6;
3810 struct connman_ipconfig *
3811 __connman_service_get_ipconfig(struct connman_service *service, int family)
3813 if (family == AF_INET)
3814 return __connman_service_get_ip4config(service);
3815 else if (family == AF_INET6)
3816 return __connman_service_get_ip6config(service);
3822 enum connman_service_security __connman_service_get_security(struct connman_service *service)
3824 if (service == NULL)
3825 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
3827 return service->security;
3830 const char *__connman_service_get_phase2(struct connman_service *service)
3832 if (service == NULL)
3835 return service->phase2;
3838 connman_bool_t __connman_service_wps_enabled(struct connman_service *service)
3840 if (service == NULL)
3843 return service->wps;
3847 * __connman_service_set_favorite:
3848 * @service: service structure
3849 * @favorite: favorite value
3851 * Change the favorite setting of service
3853 int __connman_service_set_favorite(struct connman_service *service,
3854 connman_bool_t favorite)
3856 GSequenceIter *iter;
3858 iter = g_hash_table_lookup(service_hash, service->identifier);
3862 if (service->favorite == favorite)
3865 service->favorite = favorite;
3866 service->order = __connman_service_get_order(service);
3868 favorite_changed(service);
3870 g_sequence_sort_changed(iter, service_compare, NULL);
3872 services_changed(FALSE);
3877 int __connman_service_set_immutable(struct connman_service *service,
3878 connman_bool_t immutable)
3880 service->immutable = immutable;
3882 immutable_changed(service);
3887 void __connman_service_set_string(struct connman_service *service,
3888 const char *key, const char *value)
3890 if (g_str_equal(key, "EAP") == TRUE) {
3891 g_free(service->eap);
3892 service->eap = g_strdup(value);
3893 } else if (g_str_equal(key, "Identity") == TRUE) {
3894 g_free(service->identity);
3895 service->identity = g_strdup(value);
3896 } else if (g_str_equal(key, "CACertFile") == TRUE) {
3897 g_free(service->ca_cert_file);
3898 service->ca_cert_file = g_strdup(value);
3899 } else if (g_str_equal(key, "ClientCertFile") == TRUE) {
3900 g_free(service->client_cert_file);
3901 service->client_cert_file = g_strdup(value);
3902 } else if (g_str_equal(key, "PrivateKeyFile") == TRUE) {
3903 g_free(service->private_key_file);
3904 service->private_key_file = g_strdup(value);
3905 } else if (g_str_equal(key, "PrivateKeyPassphrase") == TRUE) {
3906 g_free(service->private_key_passphrase);
3907 service->private_key_passphrase = g_strdup(value);
3908 } else if (g_str_equal(key, "Phase2") == TRUE) {
3909 g_free(service->phase2);
3910 service->phase2 = g_strdup(value);
3911 } else if (g_str_equal(key, "Passphrase") == TRUE) {
3912 g_free(service->passphrase);
3913 service->passphrase = g_strdup(value);
3917 static void service_complete(struct connman_service *service)
3919 reply_pending(service, EIO);
3921 if (service->userconnect == FALSE)
3922 __connman_service_auto_connect();
3924 g_get_current_time(&service->modified);
3925 service_save(service);
3928 static void report_error_cb(struct connman_service *service,
3929 gboolean retry, void *user_data)
3932 __connman_service_connect(service);
3934 service_complete(service);
3935 services_changed(FALSE);
3936 __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
3940 static void request_input_cb (struct connman_service *service,
3941 const char *identity, const char *passphrase,
3944 DBG ("RequestInput return, %p", service);
3946 if (identity == NULL && passphrase == NULL && service->wps == FALSE) {
3947 service_complete(service);
3948 services_changed(FALSE);
3949 __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
3953 if (identity != NULL)
3954 __connman_service_set_agent_identity(service, identity);
3956 if (passphrase != NULL) {
3957 switch (service->security) {
3958 case CONNMAN_SERVICE_SECURITY_WEP:
3959 case CONNMAN_SERVICE_SECURITY_PSK:
3960 __connman_service_set_passphrase(service, passphrase);
3962 case CONNMAN_SERVICE_SECURITY_8021X:
3963 __connman_service_set_agent_passphrase(service,
3966 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3967 case CONNMAN_SERVICE_SECURITY_NONE:
3968 case CONNMAN_SERVICE_SECURITY_WPA:
3969 case CONNMAN_SERVICE_SECURITY_RSN:
3970 DBG("service security '%s' not handled",
3971 security2string(service->security));
3976 __connman_service_connect(service);
3978 /* Never cache agent provided credentials */
3979 __connman_service_set_agent_identity(service, NULL);
3980 __connman_service_set_agent_passphrase(service, NULL);
3983 static void downgrade_connected_services(void)
3985 struct connman_service *up_service;
3986 GSequenceIter *iter;
3988 iter = g_sequence_get_begin_iter(service_list);
3989 while (g_sequence_iter_is_end(iter) == FALSE) {
3990 up_service = g_sequence_get(iter);
3992 if (is_connected(up_service) == FALSE) {
3993 iter = g_sequence_iter_next(iter);
3997 if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
4000 downgrade_state(up_service);
4002 iter = g_sequence_iter_next(iter);
4006 static int service_indicate_state(struct connman_service *service)
4008 enum connman_service_state old_state, new_state;
4009 struct connman_service *def_service;
4010 GSequenceIter *iter;
4012 if (service == NULL)
4015 old_state = service->state;
4016 new_state = combine_state(service->state_ipv4, service->state_ipv6);
4018 DBG("service %p old %s - new %s/%s => %s",
4020 state2string(old_state),
4021 state2string(service->state_ipv4),
4022 state2string(service->state_ipv6),
4023 state2string(new_state));
4025 if (old_state == new_state)
4028 def_service = get_default();
4030 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
4031 if (def_service != NULL && def_service != service &&
4032 def_service->state == CONNMAN_SERVICE_STATE_ONLINE)
4036 service->state = new_state;
4037 state_changed(service);
4039 if (new_state == CONNMAN_SERVICE_STATE_IDLE &&
4040 old_state != CONNMAN_SERVICE_STATE_DISCONNECT) {
4041 reply_pending(service, ECONNABORTED);
4043 __connman_service_disconnect(service);
4046 if (new_state == CONNMAN_SERVICE_STATE_CONFIGURATION) {
4047 if (__connman_stats_service_register(service) == 0) {
4048 __connman_stats_get(service, FALSE,
4049 &service->stats.data);
4050 __connman_stats_get(service, TRUE,
4051 &service->stats_roaming.data);
4055 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
4056 if (service->login_required == TRUE) {
4057 service->login_required = FALSE;
4058 login_changed(service);
4061 connman_timeserver_sync();
4064 if (new_state == CONNMAN_SERVICE_STATE_IDLE) {
4065 connman_bool_t reconnect;
4067 reconnect = get_reconnect_state(service);
4068 if (reconnect == TRUE)
4069 __connman_service_auto_connect();
4071 __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
4074 if (new_state == CONNMAN_SERVICE_STATE_READY) {
4075 enum connman_ipconfig_method method;
4077 set_reconnect_state(service, TRUE);
4079 __connman_service_set_favorite(service, TRUE);
4081 reply_pending(service, 0);
4083 service->userconnect = FALSE;
4085 g_get_current_time(&service->modified);
4086 service_save(service);
4088 update_nameservers(service);
4089 dns_changed(service);
4090 domain_changed(service);
4092 __connman_notifier_connect(service->type);
4094 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
4095 connman_network_get_bool(service->network,
4096 "WiFi.UseWPS") == TRUE) {
4099 pass = connman_network_get_string(service->network,
4102 __connman_service_set_passphrase(service, pass);
4104 connman_network_set_bool(service->network,
4105 "WiFi.UseWPS", FALSE);
4110 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
4111 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
4112 __connman_ipconfig_disable_ipv6(
4113 service->ipconfig_ipv6);
4115 } else if (new_state == CONNMAN_SERVICE_STATE_DISCONNECT) {
4116 def_service = get_default();
4118 if (__connman_notifier_count_connected() == 0 &&
4119 def_service != NULL &&
4120 def_service->provider != NULL)
4121 __connman_provider_disconnect(def_service->provider);
4125 __connman_wispr_stop(service);
4127 __connman_wpad_stop(service);
4129 update_nameservers(service);
4130 dns_changed(service);
4131 domain_changed(service);
4133 __connman_notifier_disconnect(service->type);
4136 * Previous services which are connected and which states
4137 * are set to online should reset relevantly ipconfig_state
4138 * to ready so wispr/portal will be rerun on those
4140 downgrade_connected_services();
4143 if (new_state == CONNMAN_SERVICE_STATE_FAILURE) {
4144 if (service->userconnect == TRUE &&
4145 __connman_agent_report_error(service,
4146 error2string(service->error),
4147 report_error_cb, NULL) == -EIO)
4149 service_complete(service);
4151 __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
4153 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
4155 iter = g_hash_table_lookup(service_hash, service->identifier);
4157 g_sequence_sort_changed(iter, service_compare, NULL);
4159 services_changed(FALSE);
4161 if (new_state == CONNMAN_SERVICE_STATE_ONLINE)
4167 int __connman_service_indicate_error(struct connman_service *service,
4168 enum connman_service_error error)
4170 DBG("service %p error %d", service, error);
4172 if (service == NULL)
4175 service->error = error;
4177 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
4178 __connman_service_set_passphrase(service, NULL);
4180 __connman_service_ipconfig_indicate_state(service,
4181 CONNMAN_SERVICE_STATE_FAILURE,
4182 CONNMAN_IPCONFIG_TYPE_IPV4);
4183 __connman_service_ipconfig_indicate_state(service,
4184 CONNMAN_SERVICE_STATE_FAILURE,
4185 CONNMAN_IPCONFIG_TYPE_IPV6);
4189 int __connman_service_clear_error(struct connman_service *service)
4191 DBG("service %p", service);
4193 if (service == NULL)
4196 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
4199 service->state_ipv4 = service->state_ipv6 =
4200 CONNMAN_SERVICE_STATE_UNKNOWN;
4201 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;;
4203 if (service->favorite == TRUE)
4204 set_reconnect_state(service, TRUE);
4206 __connman_service_ipconfig_indicate_state(service,
4207 CONNMAN_SERVICE_STATE_IDLE,
4208 CONNMAN_IPCONFIG_TYPE_IPV6);
4211 * Toggling the IPv6 state to IDLE could trigger the auto connect
4212 * machinery and consequently the IPv4 state.
4214 if (service->state_ipv4 != CONNMAN_SERVICE_STATE_UNKNOWN &&
4215 service->state_ipv4 != CONNMAN_SERVICE_STATE_FAILURE)
4218 return __connman_service_ipconfig_indicate_state(service,
4219 CONNMAN_SERVICE_STATE_IDLE,
4220 CONNMAN_IPCONFIG_TYPE_IPV4);
4223 int __connman_service_indicate_default(struct connman_service *service)
4225 DBG("service %p", service);
4232 enum connman_service_state __connman_service_ipconfig_get_state(
4233 struct connman_service *service,
4234 enum connman_ipconfig_type type)
4236 if (service == NULL)
4237 return CONNMAN_SERVICE_STATE_UNKNOWN;
4239 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4240 return service->state_ipv4;
4242 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4243 return service->state_ipv6;
4245 return CONNMAN_SERVICE_STATE_UNKNOWN;
4248 static void check_proxy_setup(struct connman_service *service)
4251 * We start WPAD if we haven't got a PAC URL from DHCP and
4252 * if our proxy manual configuration is either empty or set
4253 * to AUTO with an empty URL.
4256 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
4259 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
4260 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
4261 service->pac != NULL))
4264 if (__connman_wpad_start(service) < 0) {
4265 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
4266 __connman_notifier_proxy_changed(service);
4273 __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
4277 * How many networks are connected at the same time. If more than 1,
4278 * then set the rp_filter setting properly (loose mode routing) so that network
4279 * connectivity works ok. This is only done for IPv4 networks as IPv6
4280 * does not have rp_filter knob.
4282 static int connected_networks_count;
4283 static int original_rp_filter;
4285 static void service_rp_filter(struct connman_service *service,
4288 enum connman_ipconfig_method method;
4290 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
4293 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
4294 case CONNMAN_IPCONFIG_METHOD_OFF:
4295 case CONNMAN_IPCONFIG_METHOD_AUTO:
4297 case CONNMAN_IPCONFIG_METHOD_FIXED:
4298 case CONNMAN_IPCONFIG_METHOD_MANUAL:
4299 case CONNMAN_IPCONFIG_METHOD_DHCP:
4303 if (connected == TRUE) {
4304 if (connected_networks_count == 1) {
4306 filter_value = __connman_ipconfig_set_rp_filter();
4307 if (filter_value < 0)
4310 original_rp_filter = filter_value;
4312 connected_networks_count++;
4315 if (connected_networks_count == 2)
4316 __connman_ipconfig_unset_rp_filter(original_rp_filter);
4318 connected_networks_count--;
4319 if (connected_networks_count < 0)
4320 connected_networks_count = 0;
4323 DBG("%s %s ipconfig %p method %d count %d filter %d",
4324 connected ? "connected" : "disconnected", service->identifier,
4325 service->ipconfig_ipv4, method,
4326 connected_networks_count, original_rp_filter);
4329 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
4330 enum connman_service_state new_state,
4331 enum connman_ipconfig_type type)
4333 struct connman_ipconfig *ipconfig = NULL;
4334 enum connman_service_state old_state;
4337 if (service == NULL)
4340 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4341 old_state = service->state_ipv4;
4342 ipconfig = service->ipconfig_ipv4;
4343 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4344 old_state = service->state_ipv6;
4345 ipconfig = service->ipconfig_ipv6;
4348 if (ipconfig == NULL)
4352 if (old_state == new_state)
4355 DBG("service %p (%s) state %d (%s) type %d (%s)",
4356 service, service ? service->identifier : NULL,
4357 new_state, state2string(new_state),
4358 type, __connman_ipconfig_type2string(type));
4360 switch (new_state) {
4361 case CONNMAN_SERVICE_STATE_UNKNOWN:
4362 case CONNMAN_SERVICE_STATE_IDLE:
4363 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
4366 case CONNMAN_SERVICE_STATE_ASSOCIATION:
4368 case CONNMAN_SERVICE_STATE_CONFIGURATION:
4369 __connman_ipconfig_enable(ipconfig);
4371 case CONNMAN_SERVICE_STATE_READY:
4372 update_nameservers(service);
4374 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4375 check_proxy_setup(service);
4376 service_rp_filter(service, TRUE);
4378 __connman_wispr_start(service, type);
4380 case CONNMAN_SERVICE_STATE_ONLINE:
4382 case CONNMAN_SERVICE_STATE_DISCONNECT:
4383 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
4386 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4387 service_rp_filter(service, FALSE);
4390 case CONNMAN_SERVICE_STATE_FAILURE:
4394 /* We keep that state */
4395 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4396 service->state_ipv4 = new_state;
4397 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4398 service->state_ipv6 = new_state;
4400 ret = service_indicate_state(service);
4403 * If the ipconfig method is OFF, then we set the state to IDLE
4404 * so that it will not affect the combined state in the future.
4406 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4407 enum connman_ipconfig_method method;
4408 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
4409 if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
4410 method == CONNMAN_IPCONFIG_METHOD_UNKNOWN) {
4411 service->state_ipv4 = CONNMAN_SERVICE_STATE_IDLE;
4412 ret = service_indicate_state(service);
4415 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4416 enum connman_ipconfig_method method;
4417 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
4418 if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
4419 method == CONNMAN_IPCONFIG_METHOD_UNKNOWN) {
4420 service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
4421 ret = service_indicate_state(service);
4428 int __connman_service_request_login(struct connman_service *service)
4430 DBG("service %p", service);
4432 if (service == NULL)
4435 service->login_required = TRUE;
4436 login_changed(service);
4441 static connman_bool_t prepare_network(struct connman_service *service)
4443 enum connman_network_type type;
4444 unsigned int ssid_len;
4446 type = connman_network_get_type(service->network);
4449 case CONNMAN_NETWORK_TYPE_UNKNOWN:
4450 case CONNMAN_NETWORK_TYPE_VENDOR:
4452 case CONNMAN_NETWORK_TYPE_WIFI:
4453 if (connman_network_get_blob(service->network, "WiFi.SSID",
4457 if (service->passphrase != NULL)
4458 connman_network_set_string(service->network,
4459 "WiFi.Passphrase", service->passphrase);
4461 case CONNMAN_NETWORK_TYPE_ETHERNET:
4462 case CONNMAN_NETWORK_TYPE_WIMAX:
4463 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
4464 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
4465 case CONNMAN_NETWORK_TYPE_CELLULAR:
4472 static void prepare_8021x(struct connman_service *service)
4474 if (service->eap != NULL)
4475 connman_network_set_string(service->network, "WiFi.EAP",
4478 if (service->identity != NULL)
4479 connman_network_set_string(service->network, "WiFi.Identity",
4482 if (service->ca_cert_file != NULL)
4483 connman_network_set_string(service->network, "WiFi.CACertFile",
4484 service->ca_cert_file);
4486 if (service->client_cert_file != NULL)
4487 connman_network_set_string(service->network,
4488 "WiFi.ClientCertFile",
4489 service->client_cert_file);
4491 if (service->private_key_file != NULL)
4492 connman_network_set_string(service->network,
4493 "WiFi.PrivateKeyFile",
4494 service->private_key_file);
4496 if (service->private_key_passphrase != NULL)
4497 connman_network_set_string(service->network,
4498 "WiFi.PrivateKeyPassphrase",
4499 service->private_key_passphrase);
4501 if (service->phase2 != NULL)
4502 connman_network_set_string(service->network, "WiFi.Phase2",
4506 static int service_connect(struct connman_service *service)
4510 switch (service->type) {
4511 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4512 case CONNMAN_SERVICE_TYPE_SYSTEM:
4513 case CONNMAN_SERVICE_TYPE_GPS:
4514 case CONNMAN_SERVICE_TYPE_GADGET:
4516 case CONNMAN_SERVICE_TYPE_ETHERNET:
4517 case CONNMAN_SERVICE_TYPE_WIMAX:
4518 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4519 case CONNMAN_SERVICE_TYPE_CELLULAR:
4520 case CONNMAN_SERVICE_TYPE_VPN:
4522 case CONNMAN_SERVICE_TYPE_WIFI:
4523 switch (service->security) {
4524 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
4525 case CONNMAN_SERVICE_SECURITY_NONE:
4527 case CONNMAN_SERVICE_SECURITY_WEP:
4528 case CONNMAN_SERVICE_SECURITY_PSK:
4529 case CONNMAN_SERVICE_SECURITY_WPA:
4530 case CONNMAN_SERVICE_SECURITY_RSN:
4531 if (service->passphrase == NULL) {
4532 if (service->network == NULL)
4535 if (service->wps == FALSE ||
4536 connman_network_get_bool(
4538 "WiFi.UseWPS") == FALSE)
4542 case CONNMAN_SERVICE_SECURITY_8021X:
4543 if (service->eap == NULL)
4547 * never request credentials if using EAP-TLS
4548 * (EAP-TLS networks need to be fully provisioned)
4550 if (g_str_equal(service->eap, "tls") == TRUE)
4554 * Return -ENOKEY if either identity or passphrase is
4555 * missing. Agent provided credentials can be used as
4556 * fallback if needed.
4558 if ((service->identity == NULL &&
4559 service->agent_identity == NULL) ||
4560 (service->passphrase == NULL &&
4561 service->agent_passphrase == NULL))
4569 if (service->network != NULL) {
4570 if (prepare_network(service) == FALSE)
4573 switch (service->security) {
4574 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
4575 case CONNMAN_SERVICE_SECURITY_NONE:
4576 case CONNMAN_SERVICE_SECURITY_WEP:
4577 case CONNMAN_SERVICE_SECURITY_PSK:
4578 case CONNMAN_SERVICE_SECURITY_WPA:
4579 case CONNMAN_SERVICE_SECURITY_RSN:
4581 case CONNMAN_SERVICE_SECURITY_8021X:
4582 prepare_8021x(service);
4586 if (__connman_stats_service_register(service) == 0) {
4587 __connman_stats_get(service, FALSE,
4588 &service->stats.data);
4589 __connman_stats_get(service, TRUE,
4590 &service->stats_roaming.data);
4593 if (service->ipconfig_ipv4)
4594 __connman_ipconfig_enable(service->ipconfig_ipv4);
4595 if (service->ipconfig_ipv6)
4596 __connman_ipconfig_enable(service->ipconfig_ipv6);
4598 err = __connman_network_connect(service->network);
4599 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
4600 service->provider != NULL)
4601 err = __connman_provider_connect(service->provider);
4606 if (err != -EINPROGRESS) {
4607 __connman_ipconfig_disable(service->ipconfig_ipv4);
4608 __connman_ipconfig_disable(service->ipconfig_ipv6);
4609 __connman_stats_service_unregister(service);
4617 int __connman_service_connect(struct connman_service *service)
4621 DBG("service %p state %s", service, state2string(service->state));
4623 if (is_connected(service) == TRUE)
4626 if (is_connecting(service) == TRUE)
4629 switch (service->type) {
4630 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4631 case CONNMAN_SERVICE_TYPE_SYSTEM:
4632 case CONNMAN_SERVICE_TYPE_GPS:
4633 case CONNMAN_SERVICE_TYPE_GADGET:
4636 err = service_connect(service);
4642 if (err == -EINPROGRESS) {
4643 if (service->timeout == 0)
4644 service->timeout = g_timeout_add_seconds(
4645 CONNECT_TIMEOUT, connect_timeout, service);
4647 return -EINPROGRESS;
4650 __connman_service_ipconfig_indicate_state(service,
4651 CONNMAN_SERVICE_STATE_FAILURE,
4652 CONNMAN_IPCONFIG_TYPE_IPV4);
4653 __connman_service_ipconfig_indicate_state(service,
4654 CONNMAN_SERVICE_STATE_FAILURE,
4655 CONNMAN_IPCONFIG_TYPE_IPV6);
4657 if (service->network != NULL)
4658 __connman_network_disconnect(service->network);
4659 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
4660 service->provider != NULL)
4661 __connman_provider_disconnect(service->provider);
4663 if (service->userconnect == TRUE) {
4664 if (err == -ENOKEY) {
4665 if (__connman_agent_request_passphrase_input(service,
4668 return -EINPROGRESS;
4670 reply_pending(service, err);
4676 int __connman_service_disconnect(struct connman_service *service)
4680 DBG("service %p", service);
4682 if (service->network != NULL) {
4683 err = __connman_network_disconnect(service->network);
4684 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
4685 service->provider != NULL)
4686 err = __connman_provider_disconnect(service->provider);
4690 if (err < 0 && err != -EINPROGRESS)
4693 __connman_6to4_remove(service->ipconfig_ipv4);
4695 if (service->ipconfig_ipv4)
4696 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
4699 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
4702 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
4703 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
4705 __connman_ipconfig_disable(service->ipconfig_ipv4);
4706 __connman_ipconfig_disable(service->ipconfig_ipv6);
4708 __connman_stats_service_unregister(service);
4713 int __connman_service_disconnect_all(void)
4715 GSequenceIter *iter;
4716 GSList *services = NULL, *list;
4720 iter = g_sequence_get_begin_iter(service_list);
4722 while (g_sequence_iter_is_end(iter) == FALSE) {
4723 struct connman_service *service = g_sequence_get(iter);
4725 services = g_slist_prepend(services, service);
4727 iter = g_sequence_iter_next(iter);
4730 for (list = services; list != NULL; list = list->next) {
4731 struct connman_service *service = list->data;
4733 service->ignore = TRUE;
4735 set_reconnect_state(service, FALSE);
4737 __connman_service_disconnect(service);
4747 * lookup_by_identifier:
4748 * @identifier: service identifier
4750 * Look up a service by identifier (reference count will not be increased)
4752 static struct connman_service *lookup_by_identifier(const char *identifier)
4754 GSequenceIter *iter;
4756 iter = g_hash_table_lookup(service_hash, identifier);
4758 return g_sequence_get(iter);
4763 static void provision_changed(gpointer value, gpointer user_data)
4765 struct connman_service *service = value;
4766 char *path = user_data;
4768 __connman_config_provision_service_ident(service, path);
4771 void __connman_service_provision_changed(const char *ident)
4773 g_sequence_foreach(service_list, provision_changed, (void *)ident);
4777 * __connman_service_get:
4778 * @identifier: service identifier
4780 * Look up a service by identifier or create a new one if not found
4782 static struct connman_service *service_get(const char *identifier)
4784 struct connman_service *service;
4785 GSequenceIter *iter;
4787 iter = g_hash_table_lookup(service_hash, identifier);
4789 service = g_sequence_get(iter);
4790 if (service != NULL)
4791 connman_service_ref(service);
4795 service = connman_service_create();
4796 if (service == NULL)
4799 DBG("service %p", service);
4801 service->identifier = g_strdup(identifier);
4803 iter = g_sequence_insert_sorted(service_list, service,
4804 service_compare, NULL);
4806 g_hash_table_insert(service_hash, service->identifier, iter);
4811 static int service_register(struct connman_service *service)
4813 GSequenceIter *iter;
4815 DBG("service %p", service);
4817 if (service->path != NULL)
4820 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
4821 service->identifier);
4823 DBG("path %s", service->path);
4825 __connman_config_provision_service(service);
4827 service_load(service);
4829 g_dbus_register_interface(connection, service->path,
4830 CONNMAN_SERVICE_INTERFACE,
4831 service_methods, service_signals,
4832 NULL, service, NULL);
4834 iter = g_hash_table_lookup(service_hash, service->identifier);
4836 g_sequence_sort_changed(iter, service_compare, NULL);
4838 services_changed(TRUE);
4843 static void service_up(struct connman_ipconfig *ipconfig)
4845 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
4847 DBG("%s up", connman_ipconfig_get_ifname(ipconfig));
4849 link_changed(service);
4851 service->stats.valid = FALSE;
4852 service->stats_roaming.valid = FALSE;
4855 static void service_down(struct connman_ipconfig *ipconfig)
4857 DBG("%s down", connman_ipconfig_get_ifname(ipconfig));
4860 static void service_lower_up(struct connman_ipconfig *ipconfig)
4862 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
4864 DBG("%s lower up", connman_ipconfig_get_ifname(ipconfig));
4866 stats_start(service);
4869 static void service_lower_down(struct connman_ipconfig *ipconfig)
4871 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
4873 DBG("%s lower down", connman_ipconfig_get_ifname(ipconfig));
4875 stats_stop(service);
4876 service_save(service);
4879 static void service_ip_bound(struct connman_ipconfig *ipconfig)
4881 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
4882 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
4883 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
4885 DBG("%s ip bound", connman_ipconfig_get_ifname(ipconfig));
4887 type = __connman_ipconfig_get_config_type(ipconfig);
4888 method = __connman_ipconfig_get_method(ipconfig);
4890 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
4893 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
4894 method == CONNMAN_IPCONFIG_METHOD_AUTO)
4895 __connman_service_ipconfig_indicate_state(service,
4896 CONNMAN_SERVICE_STATE_READY,
4897 CONNMAN_IPCONFIG_TYPE_IPV6);
4899 settings_changed(service, ipconfig);
4902 static void service_ip_release(struct connman_ipconfig *ipconfig)
4904 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
4905 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
4906 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
4908 DBG("%s ip release", connman_ipconfig_get_ifname(ipconfig));
4910 type = __connman_ipconfig_get_config_type(ipconfig);
4911 method = __connman_ipconfig_get_method(ipconfig);
4913 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
4916 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
4917 method == CONNMAN_IPCONFIG_METHOD_OFF)
4918 __connman_service_ipconfig_indicate_state(service,
4919 CONNMAN_SERVICE_STATE_DISCONNECT,
4920 CONNMAN_IPCONFIG_TYPE_IPV6);
4922 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
4923 method == CONNMAN_IPCONFIG_METHOD_OFF)
4924 __connman_service_ipconfig_indicate_state(service,
4925 CONNMAN_SERVICE_STATE_DISCONNECT,
4926 CONNMAN_IPCONFIG_TYPE_IPV4);
4928 settings_changed(service, ipconfig);
4931 static const struct connman_ipconfig_ops service_ops = {
4933 .down = service_down,
4934 .lower_up = service_lower_up,
4935 .lower_down = service_lower_down,
4936 .ip_bound = service_ip_bound,
4937 .ip_release = service_ip_release,
4940 static void setup_ip4config(struct connman_service *service, int index,
4941 enum connman_ipconfig_method method)
4946 service->ipconfig_ipv4 = connman_ipconfig_create(index,
4947 CONNMAN_IPCONFIG_TYPE_IPV4);
4948 if (service->ipconfig_ipv4 == NULL)
4951 connman_ipconfig_set_method(service->ipconfig_ipv4, method);
4953 connman_ipconfig_set_data(service->ipconfig_ipv4, service);
4955 connman_ipconfig_set_ops(service->ipconfig_ipv4, &service_ops);
4958 static void setup_ip6config(struct connman_service *service, int index)
4963 service->ipconfig_ipv6 = connman_ipconfig_create(index,
4964 CONNMAN_IPCONFIG_TYPE_IPV6);
4965 if (service->ipconfig_ipv6 == NULL)
4968 connman_ipconfig_set_data(service->ipconfig_ipv6, service);
4970 connman_ipconfig_set_ops(service->ipconfig_ipv6, &service_ops);
4973 void __connman_service_read_ip4config(struct connman_service *service)
4977 if (service->ipconfig_ipv4 == NULL)
4980 keyfile = connman_storage_load_service(service->identifier);
4981 if (keyfile == NULL)
4984 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
4985 service->identifier, "IPv4.");
4987 g_key_file_free(keyfile);
4990 void __connman_service_create_ip4config(struct connman_service *service,
4993 DBG("ipv4 %p", service->ipconfig_ipv4);
4995 if (service->ipconfig_ipv4 != NULL)
4998 setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_DHCP);
4999 __connman_service_read_ip4config(service);
5002 void __connman_service_read_ip6config(struct connman_service *service)
5006 if (service->ipconfig_ipv6 == NULL)
5009 keyfile = connman_storage_load_service(service->identifier);
5010 if (keyfile == NULL)
5013 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
5014 service->identifier, "IPv6.");
5016 g_key_file_free(keyfile);
5019 void __connman_service_create_ip6config(struct connman_service *service,
5022 DBG("ipv6 %p", service->ipconfig_ipv6);
5024 if (service->ipconfig_ipv6 != NULL)
5027 setup_ip6config(service, index);
5029 __connman_service_read_ip6config(service);
5033 * __connman_service_lookup_from_network:
5034 * @network: network structure
5036 * Look up a service by network (reference count will not be increased)
5038 struct connman_service *__connman_service_lookup_from_network(struct connman_network *network)
5040 struct connman_service *service;
5041 const char *ident, *group;
5044 DBG("network %p", network);
5046 if (network == NULL)
5049 ident = __connman_network_get_ident(network);
5053 group = connman_network_get_group(network);
5057 name = g_strdup_printf("%s_%s_%s",
5058 __connman_network_get_type(network), ident, group);
5059 service = lookup_by_identifier(name);
5065 struct connman_service *__connman_service_lookup_from_index(int index)
5067 struct connman_service *service;
5068 GSequenceIter *iter;
5070 iter = g_sequence_get_begin_iter(service_list);
5072 while (g_sequence_iter_is_end(iter) == FALSE) {
5073 service = g_sequence_get(iter);
5075 if (connman_ipconfig_get_index(service->ipconfig_ipv4)
5079 if (connman_ipconfig_get_index(service->ipconfig_ipv6)
5083 iter = g_sequence_iter_next(iter);
5089 const char *__connman_service_get_ident(struct connman_service *service)
5091 return service->identifier;
5094 const char *__connman_service_get_path(struct connman_service *service)
5096 return service->path;
5099 unsigned int __connman_service_get_order(struct connman_service *service)
5101 GSequenceIter *iter;
5103 if (service == NULL)
5106 if (service->favorite == FALSE) {
5111 iter = g_hash_table_lookup(service_hash, service->identifier);
5113 if (g_sequence_iter_get_position(iter) == 0)
5115 else if (service->type == CONNMAN_SERVICE_TYPE_VPN)
5116 service->order = 10;
5122 return service->order;
5125 static enum connman_service_type convert_network_type(struct connman_network *network)
5127 enum connman_network_type type = connman_network_get_type(network);
5130 case CONNMAN_NETWORK_TYPE_UNKNOWN:
5131 case CONNMAN_NETWORK_TYPE_VENDOR:
5133 case CONNMAN_NETWORK_TYPE_ETHERNET:
5134 return CONNMAN_SERVICE_TYPE_ETHERNET;
5135 case CONNMAN_NETWORK_TYPE_WIFI:
5136 return CONNMAN_SERVICE_TYPE_WIFI;
5137 case CONNMAN_NETWORK_TYPE_WIMAX:
5138 return CONNMAN_SERVICE_TYPE_WIMAX;
5139 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
5140 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
5141 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
5142 case CONNMAN_NETWORK_TYPE_CELLULAR:
5143 return CONNMAN_SERVICE_TYPE_CELLULAR;
5146 return CONNMAN_SERVICE_TYPE_UNKNOWN;
5149 static enum connman_service_security convert_wifi_security(const char *security)
5151 if (security == NULL)
5152 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
5153 else if (g_str_equal(security, "none") == TRUE)
5154 return CONNMAN_SERVICE_SECURITY_NONE;
5155 else if (g_str_equal(security, "wep") == TRUE)
5156 return CONNMAN_SERVICE_SECURITY_WEP;
5157 else if (g_str_equal(security, "psk") == TRUE)
5158 return CONNMAN_SERVICE_SECURITY_PSK;
5159 else if (g_str_equal(security, "ieee8021x") == TRUE)
5160 return CONNMAN_SERVICE_SECURITY_8021X;
5161 else if (g_str_equal(security, "wpa") == TRUE)
5162 return CONNMAN_SERVICE_SECURITY_WPA;
5163 else if (g_str_equal(security, "rsn") == TRUE)
5164 return CONNMAN_SERVICE_SECURITY_RSN;
5166 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
5169 static void update_from_network(struct connman_service *service,
5170 struct connman_network *network)
5172 connman_uint8_t strength = service->strength;
5173 GSequenceIter *iter;
5176 DBG("service %p network %p", service, network);
5178 if (is_connected(service) == TRUE)
5181 if (is_connecting(service) == TRUE)
5184 str = connman_network_get_string(network, "Name");
5186 g_free(service->name);
5187 service->name = g_strdup(str);
5188 service->hidden = FALSE;
5190 g_free(service->name);
5191 service->name = NULL;
5192 service->hidden = TRUE;
5195 service->strength = connman_network_get_strength(network);
5196 service->roaming = connman_network_get_bool(network, "Roaming");
5198 if (service->strength == 0) {
5200 * Filter out 0-values; it's unclear what they mean
5201 * and they cause anomalous sorting of the priority list.
5203 service->strength = strength;
5206 str = connman_network_get_string(network, "WiFi.Security");
5207 service->security = convert_wifi_security(str);
5209 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
5210 service->wps = connman_network_get_bool(network, "WiFi.WPS");
5212 if (service->strength > strength && service->network != NULL) {
5213 service->network = network;
5215 strength_changed(service);
5218 if (service->network == NULL)
5219 service->network = network;
5221 iter = g_hash_table_lookup(service_hash, service->identifier);
5223 g_sequence_sort_changed(iter, service_compare, NULL);
5227 * __connman_service_create_from_network:
5228 * @network: network structure
5230 * Look up service by network and if not found, create one
5232 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
5234 struct connman_service *service;
5235 struct connman_device *device;
5236 const char *ident, *group;
5240 DBG("network %p", network);
5242 if (network == NULL)
5245 ident = __connman_network_get_ident(network);
5249 group = connman_network_get_group(network);
5253 name = g_strdup_printf("%s_%s_%s",
5254 __connman_network_get_type(network), ident, group);
5255 service = service_get(name);
5258 if (service == NULL)
5261 if (__connman_network_get_weakness(network) == TRUE)
5264 if (service->path != NULL) {
5265 update_from_network(service, network);
5266 services_changed(TRUE);
5270 service->type = convert_network_type(network);
5272 switch (service->type) {
5273 case CONNMAN_SERVICE_TYPE_UNKNOWN:
5274 case CONNMAN_SERVICE_TYPE_SYSTEM:
5275 case CONNMAN_SERVICE_TYPE_ETHERNET:
5276 case CONNMAN_SERVICE_TYPE_WIMAX:
5277 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
5278 case CONNMAN_SERVICE_TYPE_GPS:
5279 case CONNMAN_SERVICE_TYPE_VPN:
5280 case CONNMAN_SERVICE_TYPE_GADGET:
5281 service->autoconnect = FALSE;
5283 case CONNMAN_SERVICE_TYPE_WIFI:
5284 case CONNMAN_SERVICE_TYPE_CELLULAR:
5285 service->autoconnect = TRUE;
5289 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
5290 service->state = combine_state(service->state_ipv4, service->state_ipv6);
5292 update_from_network(service, network);
5294 index = connman_network_get_index(network);
5296 if (service->ipconfig_ipv4 == NULL)
5297 setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_DHCP);
5299 if (service->ipconfig_ipv6 == NULL)
5300 setup_ip6config(service, index);
5302 service_register(service);
5304 if (service->favorite == TRUE) {
5305 device = connman_network_get_device(service->network);
5306 if (device && __connman_device_scanning(device) == FALSE)
5307 __connman_service_auto_connect();
5310 __connman_notifier_service_add(service, service->name);
5315 void __connman_service_update_from_network(struct connman_network *network)
5317 connman_bool_t need_sort = FALSE;
5318 struct connman_service *service;
5319 connman_uint8_t strength;
5320 connman_bool_t roaming;
5321 GSequenceIter *iter;
5323 connman_bool_t stats_enable;
5325 DBG("network %p", network);
5327 service = __connman_service_lookup_from_network(network);
5328 if (service == NULL)
5331 if (service->network == NULL)
5334 name = connman_network_get_string(service->network, "Name");
5335 if (g_strcmp0(service->name, name) != 0) {
5336 g_free(service->name);
5337 service->name = g_strdup(name);
5338 connman_dbus_property_changed_basic(service->path,
5339 CONNMAN_SERVICE_INTERFACE, "Name",
5340 DBUS_TYPE_STRING, &service->name);
5343 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
5344 service->wps = connman_network_get_bool(network, "WiFi.WPS");
5346 strength = connman_network_get_strength(service->network);
5347 if (strength == service->strength)
5350 service->strength = strength;
5353 strength_changed(service);
5356 roaming = connman_network_get_bool(service->network, "Roaming");
5357 if (roaming == service->roaming)
5360 stats_enable = stats_enabled(service);
5361 if (stats_enable == TRUE)
5362 stats_stop(service);
5364 service->roaming = roaming;
5367 if (stats_enable == TRUE)
5368 stats_start(service);
5370 roaming_changed(service);
5373 if (need_sort == TRUE) {
5374 iter = g_hash_table_lookup(service_hash, service->identifier);
5376 g_sequence_sort_changed(iter, service_compare, NULL);
5380 void __connman_service_remove_from_network(struct connman_network *network)
5382 struct connman_service *service;
5384 DBG("network %p", network);
5386 service = __connman_service_lookup_from_network(network);
5387 if (service == NULL)
5390 __connman_connection_gateway_remove(service,
5391 CONNMAN_IPCONFIG_TYPE_ALL);
5393 __connman_service_put(service);
5397 * __connman_service_create_from_provider:
5398 * @provider: provider structure
5400 * Look up service by provider and if not found, create one
5402 struct connman_service *
5403 __connman_service_create_from_provider(struct connman_provider *provider)
5405 struct connman_service *service;
5406 const char *ident, *str;
5408 int index = connman_provider_get_index(provider);
5410 DBG("provider %p", provider);
5412 ident = __connman_provider_get_ident(provider);
5416 name = g_strdup_printf("vpn_%s", ident);
5417 service = service_get(name);
5420 if (service == NULL)
5423 service->type = CONNMAN_SERVICE_TYPE_VPN;
5424 service->provider = connman_provider_ref(provider);
5425 service->autoconnect = FALSE;
5426 service->userconnect = TRUE;
5428 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
5430 str = connman_provider_get_string(provider, "Name");
5432 g_free(service->name);
5433 service->name = g_strdup(str);
5434 service->hidden = FALSE;
5436 g_free(service->name);
5437 service->name = NULL;
5438 service->hidden = TRUE;
5441 service->strength = 0;
5443 if (service->ipconfig_ipv4 == NULL)
5444 setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_MANUAL);
5446 if (service->ipconfig_ipv6 == NULL)
5447 setup_ip6config(service, index);
5449 service_register(service);
5451 __connman_notifier_service_add(service, service->name);
5456 int __connman_service_init(void)
5460 connection = connman_dbus_get_connection();
5462 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
5465 service_list = g_sequence_new(service_free);
5470 void __connman_service_cleanup(void)
5476 list = service_list;
5477 service_list = NULL;
5478 g_sequence_free(list);
5480 g_hash_table_destroy(service_hash);
5481 service_hash = NULL;
5483 g_slist_free(counter_list);
5484 counter_list = NULL;
5486 dbus_connection_unref(connection);