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
34 #define CONNECT_TIMEOUT 120
36 static DBusConnection *connection = NULL;
38 static GSequence *service_list = NULL;
39 static GHashTable *service_hash = NULL;
40 static GSList *counter_list = NULL;
42 struct connman_stats {
44 connman_bool_t enabled;
45 struct connman_stats_data data_last;
46 struct connman_stats_data data;
50 struct connman_stats_counter {
51 connman_bool_t append_all;
52 struct connman_stats stats;
53 struct connman_stats stats_roaming;
56 struct connman_service {
58 gint session_usage_count;
61 enum connman_service_type type;
62 enum connman_service_security security;
63 enum connman_service_state state;
64 enum connman_service_state state_ipv4;
65 enum connman_service_state state_ipv6;
66 enum connman_service_error error;
67 connman_uint8_t strength;
68 connman_bool_t favorite;
69 connman_bool_t immutable;
70 connman_bool_t hidden;
71 connman_bool_t ignore;
72 connman_bool_t autoconnect;
73 connman_bool_t userconnect;
78 char *agent_passphrase;
79 connman_bool_t roaming;
80 connman_bool_t login_required;
81 connman_bool_t network_created;
82 struct connman_ipconfig *ipconfig_ipv4;
83 struct connman_ipconfig *ipconfig_ipv6;
84 struct connman_network *network;
85 struct connman_provider *provider;
87 char **nameservers_config;
91 /* 802.1x settings from the config files */
96 char *client_cert_file;
97 char *private_key_file;
98 char *private_key_passphrase;
100 DBusMessage *pending;
102 struct connman_location *location;
103 struct connman_stats stats;
104 struct connman_stats stats_roaming;
105 GHashTable *counter_table;
106 enum connman_service_proxy_method proxy;
107 enum connman_service_proxy_method proxy_config;
114 static void append_path(gpointer value, gpointer user_data)
116 struct connman_service *service = value;
117 DBusMessageIter *iter = user_data;
119 if (service->path == NULL || service->hidden == TRUE)
122 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
126 void __connman_service_list(DBusMessageIter *iter, void *user_data)
128 if (service_list == NULL)
131 g_sequence_foreach(service_list, append_path, iter);
136 struct connman_service *service;
139 static void compare_path(gpointer value, gpointer user_data)
141 struct connman_service *service = value;
142 struct find_data *data = user_data;
144 if (data->service != NULL)
147 if (g_strcmp0(service->path, data->path) == 0)
148 data->service = service;
151 static struct connman_service *find_service(const char *path)
153 struct find_data data = { .path = path, .service = NULL };
155 DBG("path %s", path);
157 g_sequence_foreach(service_list, compare_path, &data);
162 const char *__connman_service_type2string(enum connman_service_type type)
165 case CONNMAN_SERVICE_TYPE_UNKNOWN:
167 case CONNMAN_SERVICE_TYPE_SYSTEM:
169 case CONNMAN_SERVICE_TYPE_ETHERNET:
171 case CONNMAN_SERVICE_TYPE_WIFI:
173 case CONNMAN_SERVICE_TYPE_WIMAX:
175 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
177 case CONNMAN_SERVICE_TYPE_CELLULAR:
179 case CONNMAN_SERVICE_TYPE_GPS:
181 case CONNMAN_SERVICE_TYPE_VPN:
183 case CONNMAN_SERVICE_TYPE_GADGET:
190 static const char *security2string(enum connman_service_security security)
193 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
195 case CONNMAN_SERVICE_SECURITY_NONE:
197 case CONNMAN_SERVICE_SECURITY_WEP:
199 case CONNMAN_SERVICE_SECURITY_PSK:
201 case CONNMAN_SERVICE_SECURITY_8021X:
203 case CONNMAN_SERVICE_SECURITY_WPA:
205 case CONNMAN_SERVICE_SECURITY_RSN:
212 static const char *state2string(enum connman_service_state state)
215 case CONNMAN_SERVICE_STATE_UNKNOWN:
217 case CONNMAN_SERVICE_STATE_IDLE:
219 case CONNMAN_SERVICE_STATE_ASSOCIATION:
220 return "association";
221 case CONNMAN_SERVICE_STATE_CONFIGURATION:
222 return "configuration";
223 case CONNMAN_SERVICE_STATE_READY:
225 case CONNMAN_SERVICE_STATE_ONLINE:
227 case CONNMAN_SERVICE_STATE_DISCONNECT:
229 case CONNMAN_SERVICE_STATE_FAILURE:
236 static const char *error2string(enum connman_service_error error)
239 case CONNMAN_SERVICE_ERROR_UNKNOWN:
241 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
242 return "out-of-range";
243 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
244 return "pin-missing";
245 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
246 return "dhcp-failed";
247 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
248 return "connect-failed";
249 case CONNMAN_SERVICE_ERROR_LOGIN_FAILED:
250 return "login-failed";
251 case CONNMAN_SERVICE_ERROR_AUTH_FAILED:
252 return "auth-failed";
253 case CONNMAN_SERVICE_ERROR_INVALID_KEY:
254 return "invalid-key";
260 static enum connman_service_error string2error(const char *error)
262 if (g_strcmp0(error, "dhcp-failed") == 0)
263 return CONNMAN_SERVICE_ERROR_DHCP_FAILED;
264 else if (g_strcmp0(error, "pin-missing") == 0)
265 return CONNMAN_SERVICE_ERROR_PIN_MISSING;
266 else if (g_strcmp0(error, "invalid-key") == 0)
267 return CONNMAN_SERVICE_ERROR_INVALID_KEY;
269 return CONNMAN_SERVICE_ERROR_UNKNOWN;
272 static const char *proxymethod2string(enum connman_service_proxy_method method)
275 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
277 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
279 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
281 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
288 static enum connman_service_proxy_method string2proxymethod(const char *method)
290 if (g_strcmp0(method, "direct") == 0)
291 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
292 else if (g_strcmp0(method, "auto") == 0)
293 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
294 else if (g_strcmp0(method, "manual") == 0)
295 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
297 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
300 static int service_load(struct connman_service *service)
302 const char *ident = "default";
304 GError *error = NULL;
305 gchar *pathname, *data = NULL;
308 connman_bool_t autoconnect;
309 unsigned int ssid_len;
312 DBG("service %p", service);
317 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
318 if (pathname == NULL)
321 keyfile = g_key_file_new();
323 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
330 if (g_key_file_load_from_data(keyfile, data, length,
338 switch (service->type) {
339 case CONNMAN_SERVICE_TYPE_UNKNOWN:
340 case CONNMAN_SERVICE_TYPE_SYSTEM:
341 case CONNMAN_SERVICE_TYPE_ETHERNET:
342 case CONNMAN_SERVICE_TYPE_GPS:
343 case CONNMAN_SERVICE_TYPE_VPN:
344 case CONNMAN_SERVICE_TYPE_GADGET:
346 case CONNMAN_SERVICE_TYPE_WIFI:
347 if (service->name == NULL) {
350 name = g_key_file_get_string(keyfile,
351 service->identifier, "Name", NULL);
353 g_free(service->name);
354 service->name = name;
357 if (service->network != NULL)
358 connman_network_set_name(service->network,
362 if (service->network &&
363 connman_network_get_blob(service->network,
364 "WiFi.SSID", &ssid_len) == NULL) {
367 hex_ssid = g_key_file_get_string(keyfile,
371 if (hex_ssid != NULL) {
373 unsigned int i, j = 0, hex;
374 size_t hex_ssid_len = strlen(hex_ssid);
376 ssid = g_try_malloc0(hex_ssid_len / 2);
383 for (i = 0; i < hex_ssid_len; i += 2) {
384 sscanf(hex_ssid + i, "%02x", &hex);
388 connman_network_set_blob(service->network,
389 "WiFi.SSID", ssid, hex_ssid_len / 2);
396 case CONNMAN_SERVICE_TYPE_WIMAX:
397 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
398 case CONNMAN_SERVICE_TYPE_CELLULAR:
399 service->favorite = g_key_file_get_boolean(keyfile,
400 service->identifier, "Favorite", NULL);
402 autoconnect = g_key_file_get_boolean(keyfile,
403 service->identifier, "AutoConnect", &error);
405 service->autoconnect = autoconnect;
406 g_clear_error(&error);
408 str = g_key_file_get_string(keyfile,
409 service->identifier, "Failure", NULL);
411 if (service->favorite == FALSE)
412 service->state_ipv4 = service->state_ipv6 =
413 CONNMAN_SERVICE_STATE_FAILURE;
414 service->error = string2error(str);
419 str = g_key_file_get_string(keyfile,
420 service->identifier, "Modified", NULL);
422 g_time_val_from_iso8601(str, &service->modified);
426 str = g_key_file_get_string(keyfile,
427 service->identifier, "Passphrase", NULL);
429 g_free(service->passphrase);
430 service->passphrase = str;
433 if (service->ipconfig_ipv4 != NULL)
434 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
435 service->identifier, "IPv4.");
437 if (service->ipconfig_ipv6 != NULL)
438 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
439 service->identifier, "IPv6.");
441 service->nameservers_config = g_key_file_get_string_list(keyfile,
442 service->identifier, "Nameservers", &length, NULL);
443 if (service->nameservers_config != NULL && length == 0) {
444 g_strfreev(service->nameservers_config);
445 service->nameservers_config = NULL;
448 service->domains = g_key_file_get_string_list(keyfile,
449 service->identifier, "Domains", &length, NULL);
450 if (service->domains != NULL && length == 0) {
451 g_strfreev(service->domains);
452 service->domains = NULL;
455 str = g_key_file_get_string(keyfile,
456 service->identifier, "Proxy.Method", NULL);
458 service->proxy_config = string2proxymethod(str);
462 service->proxies = g_key_file_get_string_list(keyfile,
463 service->identifier, "Proxy.Servers", &length, NULL);
464 if (service->proxies != NULL && length == 0) {
465 g_strfreev(service->proxies);
466 service->proxies = NULL;
469 service->excludes = g_key_file_get_string_list(keyfile,
470 service->identifier, "Proxy.Excludes", &length, NULL);
471 if (service->excludes != NULL && length == 0) {
472 g_strfreev(service->excludes);
473 service->excludes = NULL;
476 str = g_key_file_get_string(keyfile,
477 service->identifier, "Proxy.URL", NULL);
479 g_free(service->pac);
484 g_key_file_free(keyfile);
489 static int service_save(struct connman_service *service)
491 const char *ident = "default";
493 gchar *pathname, *data = NULL;
496 const char *cst_str = NULL;
499 DBG("service %p", service);
504 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
505 if (pathname == NULL)
508 keyfile = g_key_file_new();
510 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
514 if (g_key_file_load_from_data(keyfile, data, length,
522 if (service->name != NULL)
523 g_key_file_set_string(keyfile, service->identifier,
524 "Name", service->name);
526 switch (service->type) {
527 case CONNMAN_SERVICE_TYPE_UNKNOWN:
528 case CONNMAN_SERVICE_TYPE_SYSTEM:
529 case CONNMAN_SERVICE_TYPE_ETHERNET:
530 case CONNMAN_SERVICE_TYPE_GPS:
531 case CONNMAN_SERVICE_TYPE_VPN:
532 case CONNMAN_SERVICE_TYPE_GADGET:
534 case CONNMAN_SERVICE_TYPE_WIFI:
535 if (service->network) {
536 const unsigned char *ssid;
537 unsigned int ssid_len = 0;
539 ssid = connman_network_get_blob(service->network,
540 "WiFi.SSID", &ssid_len);
542 if (ssid != NULL && ssid_len > 0 && ssid[0] != '\0') {
543 char *identifier = service->identifier;
547 str = g_string_sized_new(ssid_len * 2);
553 for (i = 0; i < ssid_len; i++)
554 g_string_append_printf(str,
557 g_key_file_set_string(keyfile, identifier,
560 g_string_free(str, TRUE);
565 case CONNMAN_SERVICE_TYPE_WIMAX:
566 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
567 case CONNMAN_SERVICE_TYPE_CELLULAR:
568 g_key_file_set_boolean(keyfile, service->identifier,
569 "Favorite", service->favorite);
571 if (service->favorite == TRUE)
572 g_key_file_set_boolean(keyfile, service->identifier,
573 "AutoConnect", service->autoconnect);
575 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_FAILURE ||
576 service->state_ipv6 == CONNMAN_SERVICE_STATE_FAILURE) {
577 const char *failure = error2string(service->error);
579 g_key_file_set_string(keyfile,
583 g_key_file_remove_key(keyfile, service->identifier,
589 str = g_time_val_to_iso8601(&service->modified);
591 g_key_file_set_string(keyfile, service->identifier,
596 if (service->passphrase != NULL && strlen(service->passphrase) > 0)
597 g_key_file_set_string(keyfile, service->identifier,
598 "Passphrase", service->passphrase);
600 g_key_file_remove_key(keyfile, service->identifier,
603 if (service->ipconfig_ipv4 != NULL)
604 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
605 service->identifier, "IPv4.");
607 if (service->ipconfig_ipv6 != NULL)
608 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
609 service->identifier, "IPv6.");
611 if (service->nameservers_config != NULL) {
612 guint len = g_strv_length(service->nameservers_config);
614 g_key_file_set_string_list(keyfile, service->identifier,
616 (const gchar **) service->nameservers_config, len);
618 g_key_file_remove_key(keyfile, service->identifier,
619 "Nameservers", NULL);
621 if (service->domains != NULL) {
622 guint len = g_strv_length(service->domains);
624 g_key_file_set_string_list(keyfile, service->identifier,
626 (const gchar **) service->domains, len);
628 g_key_file_remove_key(keyfile, service->identifier,
631 cst_str = proxymethod2string(service->proxy_config);
633 g_key_file_set_string(keyfile, service->identifier,
634 "Proxy.Method", cst_str);
636 if (service->proxies != NULL) {
637 guint len = g_strv_length(service->proxies);
639 g_key_file_set_string_list(keyfile, service->identifier,
641 (const gchar **) service->proxies, len);
643 g_key_file_remove_key(keyfile, service->identifier,
644 "Proxy.Servers", NULL);
646 if (service->excludes != NULL) {
647 guint len = g_strv_length(service->excludes);
649 g_key_file_set_string_list(keyfile, service->identifier,
651 (const gchar **) service->excludes, len);
653 g_key_file_remove_key(keyfile, service->identifier,
654 "Proxy.Excludes", NULL);
656 if (service->pac != NULL && strlen(service->pac) > 0)
657 g_key_file_set_string(keyfile, service->identifier,
658 "Proxy.URL", service->pac);
660 g_key_file_remove_key(keyfile, service->identifier,
663 data = g_key_file_to_data(keyfile, &length, NULL);
665 if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
666 connman_error("Failed to store service information");
671 g_key_file_free(keyfile);
678 static guint changed_timeout = 0;
680 static gboolean notify_services_changed(gpointer user_data)
684 connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
685 CONNMAN_MANAGER_INTERFACE, "Services",
686 DBUS_TYPE_OBJECT_PATH, __connman_service_list,
692 static void services_changed(gboolean delayed)
696 if (changed_timeout > 0) {
697 g_source_remove(changed_timeout);
701 if (__connman_connection_update_gateway() == TRUE) {
702 notify_services_changed(NULL);
706 if (delayed == FALSE) {
707 notify_services_changed(NULL);
711 changed_timeout = g_timeout_add_seconds(1, notify_services_changed,
715 static enum connman_service_state combine_state(
716 enum connman_service_state state_a,
717 enum connman_service_state state_b)
719 enum connman_service_state result;
721 if (state_a == state_b) {
726 if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
731 if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
736 if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
741 if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
746 if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
751 if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
756 if (state_a == CONNMAN_SERVICE_STATE_READY) {
761 if (state_b == CONNMAN_SERVICE_STATE_READY) {
766 if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
771 if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
776 if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
781 if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
786 if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
791 if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
796 result = CONNMAN_SERVICE_STATE_FAILURE;
802 static connman_bool_t is_connecting_state(struct connman_service *service,
803 enum connman_service_state state)
806 case CONNMAN_SERVICE_STATE_UNKNOWN:
807 case CONNMAN_SERVICE_STATE_IDLE:
808 case CONNMAN_SERVICE_STATE_FAILURE:
809 if (service->network != NULL)
810 return connman_network_get_connecting(service->network);
811 case CONNMAN_SERVICE_STATE_DISCONNECT:
812 case CONNMAN_SERVICE_STATE_READY:
813 case CONNMAN_SERVICE_STATE_ONLINE:
815 case CONNMAN_SERVICE_STATE_ASSOCIATION:
816 case CONNMAN_SERVICE_STATE_CONFIGURATION:
823 static connman_bool_t is_connected_state(const struct connman_service *service,
824 enum connman_service_state state)
827 case CONNMAN_SERVICE_STATE_UNKNOWN:
828 case CONNMAN_SERVICE_STATE_IDLE:
829 case CONNMAN_SERVICE_STATE_ASSOCIATION:
830 case CONNMAN_SERVICE_STATE_CONFIGURATION:
831 case CONNMAN_SERVICE_STATE_DISCONNECT:
832 case CONNMAN_SERVICE_STATE_FAILURE:
834 case CONNMAN_SERVICE_STATE_READY:
835 case CONNMAN_SERVICE_STATE_ONLINE:
842 static connman_bool_t is_connecting(struct connman_service *service)
844 return is_connecting_state(service, service->state);
847 static connman_bool_t is_connected(struct connman_service *service)
849 return is_connected_state(service, service->state);
852 static void update_nameservers(struct connman_service *service)
856 if (service->ipconfig_ipv4)
857 ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv4);
858 else if (service->ipconfig_ipv6)
859 ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv6);
866 switch (combine_state(service->state_ipv4, service->state_ipv6)) {
867 case CONNMAN_SERVICE_STATE_UNKNOWN:
868 case CONNMAN_SERVICE_STATE_IDLE:
869 case CONNMAN_SERVICE_STATE_ASSOCIATION:
870 case CONNMAN_SERVICE_STATE_CONFIGURATION:
872 case CONNMAN_SERVICE_STATE_FAILURE:
873 case CONNMAN_SERVICE_STATE_DISCONNECT:
874 connman_resolver_remove_all(ifname);
876 case CONNMAN_SERVICE_STATE_READY:
877 case CONNMAN_SERVICE_STATE_ONLINE:
881 connman_resolver_remove_all(ifname);
883 if (service->nameservers_config != NULL) {
886 for (i = 0; service->nameservers_config[i] != NULL; i++) {
887 connman_resolver_append(ifname, NULL,
888 service->nameservers_config[i]);
890 } else if (service->nameservers != NULL) {
893 for (i = 0; service->nameservers[i] != NULL; i++) {
894 connman_resolver_append(ifname, NULL,
895 service->nameservers[i]);
899 if (service->domains != NULL) {
902 for (i = 0; service->domains[i]; i++)
903 connman_resolver_append(ifname, service->domains[i],
905 } else if (service->domainname != NULL)
906 connman_resolver_append(ifname, service->domainname, NULL);
908 connman_resolver_flush();
911 int __connman_service_nameserver_append(struct connman_service *service,
912 const char *nameserver)
916 DBG("service %p nameserver %s", service, nameserver);
918 if (nameserver == NULL)
921 if (service->nameservers != NULL) {
924 for (i = 0; service->nameservers[i] != NULL; i++)
925 if (g_strcmp0(service->nameservers[i], nameserver) == 0)
928 len = g_strv_length(service->nameservers);
929 service->nameservers = g_try_renew(char *, service->nameservers,
933 service->nameservers = g_try_new0(char *, len + 2);
936 if (service->nameservers == NULL)
939 service->nameservers[len] = g_strdup(nameserver);
940 service->nameservers[len + 1] = NULL;
942 update_nameservers(service);
947 int __connman_service_nameserver_remove(struct connman_service *service,
948 const char *nameserver)
953 DBG("service %p nameserver %s", service, nameserver);
955 if (nameserver == NULL)
958 if (service->nameservers == NULL)
961 len = g_strv_length(service->nameservers);
963 if (g_strcmp0(service->nameservers[0], nameserver) != 0)
966 g_strfreev(service->nameservers);
967 service->nameservers = NULL;
972 servers = g_try_new0(char *, len);
976 for (i = 0, j = 0; i < len; i++) {
977 if (g_strcmp0(service->nameservers[i], nameserver) != 0) {
978 servers[j] = g_strdup(service->nameservers[i]);
982 servers[len - 1] = NULL;
984 g_strfreev(service->nameservers);
985 service->nameservers = servers;
987 update_nameservers(service);
992 void __connman_service_nameserver_clear(struct connman_service *service)
994 g_strfreev(service->nameservers);
995 service->nameservers = NULL;
997 update_nameservers(service);
1000 static void nameserver_add_routes(int index, char **nameservers,
1004 struct addrinfo hints;
1005 struct addrinfo *addr;
1007 for (i = 0; nameservers[i] != NULL; i++) {
1008 memset(&hints, 0, sizeof(struct addrinfo));
1009 hints.ai_flags = AI_NUMERICHOST;
1012 ret = getaddrinfo(nameservers[i], NULL, &hints, &addr);
1013 if (ret == EAI_NONAME)
1014 family = AF_INET; /* use the IPv4 as a default */
1018 family = addr->ai_family;
1020 if (family == AF_INET) {
1021 if (connman_inet_compare_subnet(index,
1022 nameservers[i]) != TRUE)
1023 connman_inet_add_host_route(index,
1024 nameservers[i], gw);
1025 } else if (family == AF_INET6)
1026 connman_inet_add_ipv6_host_route(index,
1027 nameservers[i], gw);
1033 static void nameserver_del_routes(int index, char **nameservers)
1036 struct addrinfo hints;
1037 struct addrinfo *addr;
1039 for (i = 0; nameservers[i] != NULL; i++) {
1040 memset(&hints, 0, sizeof(struct addrinfo));
1041 hints.ai_flags = AI_NUMERICHOST;
1044 ret = getaddrinfo(nameservers[i], NULL, &hints, &addr);
1045 if (ret == EAI_NONAME)
1046 family = AF_INET; /* use the IPv4 as a default */
1050 family = addr->ai_family;
1052 if (family == AF_INET)
1053 connman_inet_del_host_route(index, nameservers[i]);
1054 else if (family == AF_INET6)
1055 connman_inet_del_ipv6_host_route(index,
1062 void __connman_service_nameserver_add_routes(struct connman_service *service,
1067 if (service == NULL)
1070 if (service->network != NULL)
1071 index = connman_network_get_index(service->network);
1072 else if (service->provider != NULL)
1073 index = connman_provider_get_index(service->provider);
1075 if (service->nameservers_config != NULL) {
1077 * Configured nameserver takes preference over the
1078 * discoverd nameserver gathered from DHCP, VPN, etc.
1080 nameserver_add_routes(index, service->nameservers_config, gw);
1081 } else if (service->nameservers != NULL) {
1083 * We add nameservers host routes for nameservers that
1084 * are not on our subnet. For those who are, the subnet
1085 * route will be installed by the time the dns proxy code
1086 * tries to reach them. The subnet route is installed
1087 * when setting the interface IP address.
1089 nameserver_add_routes(index, service->nameservers, gw);
1093 void __connman_service_nameserver_del_routes(struct connman_service *service)
1097 if (service == NULL)
1100 if (service->network != NULL)
1101 index = connman_network_get_index(service->network);
1102 else if (service->provider != NULL)
1103 index = connman_provider_get_index(service->provider);
1105 if (service->nameservers_config != NULL)
1106 nameserver_del_routes(index, service->nameservers_config);
1107 else if (service->nameservers != NULL)
1108 nameserver_del_routes(index, service->nameservers);
1111 static struct connman_stats *stats_get(struct connman_service *service)
1113 if (service->roaming == TRUE)
1114 return &service->stats_roaming;
1116 return &service->stats;
1119 static connman_bool_t stats_enabled(struct connman_service *service)
1121 struct connman_stats *stats = stats_get(service);
1123 return stats->enabled;
1126 static void stats_start(struct connman_service *service)
1128 struct connman_stats *stats = stats_get(service);
1130 DBG("service %p", service);
1132 if (stats->timer == NULL)
1135 stats->enabled = TRUE;
1136 stats->data_last.time = stats->data.time;
1138 g_timer_start(stats->timer);
1141 static void stats_stop(struct connman_service *service)
1143 struct connman_stats *stats = stats_get(service);
1144 unsigned int seconds;
1146 DBG("service %p", service);
1148 if (stats->timer == NULL)
1151 if (stats->enabled == FALSE)
1154 g_timer_stop(stats->timer);
1156 seconds = g_timer_elapsed(stats->timer, NULL);
1157 stats->data.time = stats->data_last.time + seconds;
1159 stats->enabled = FALSE;
1162 static void reset_stats(struct connman_service *service)
1164 DBG("service %p", service);
1167 service->stats.valid = FALSE;
1169 service->stats.data.rx_packets = 0;
1170 service->stats.data.tx_packets = 0;
1171 service->stats.data.rx_bytes = 0;
1172 service->stats.data.tx_bytes = 0;
1173 service->stats.data.rx_errors = 0;
1174 service->stats.data.tx_errors = 0;
1175 service->stats.data.rx_dropped = 0;
1176 service->stats.data.tx_dropped = 0;
1177 service->stats.data.time = 0;
1178 service->stats.data_last.time = 0;
1180 g_timer_reset(service->stats.timer);
1183 service->stats_roaming.valid = FALSE;
1185 service->stats_roaming.data.rx_packets = 0;
1186 service->stats_roaming.data.tx_packets = 0;
1187 service->stats_roaming.data.rx_bytes = 0;
1188 service->stats_roaming.data.tx_bytes = 0;
1189 service->stats_roaming.data.rx_errors = 0;
1190 service->stats_roaming.data.tx_errors = 0;
1191 service->stats_roaming.data.rx_dropped = 0;
1192 service->stats_roaming.data.tx_dropped = 0;
1193 service->stats_roaming.data.time = 0;
1194 service->stats_roaming.data_last.time = 0;
1196 g_timer_reset(service->stats_roaming.timer);
1199 static struct connman_service *get_default(void)
1201 struct connman_service *service;
1202 GSequenceIter *iter;
1204 iter = g_sequence_get_begin_iter(service_list);
1206 if (g_sequence_iter_is_end(iter) == TRUE)
1209 service = g_sequence_get(iter);
1211 if (is_connected(service) == FALSE)
1217 static void default_changed(void)
1219 struct connman_service *service = get_default();
1221 __connman_notifier_default_changed(service);
1224 const char *__connman_service_default(void)
1226 struct connman_service *service;
1228 service = get_default();
1229 if (service == NULL)
1232 return __connman_service_type2string(service->type);
1235 static void state_changed(struct connman_service *service)
1239 __connman_notifier_service_state_changed(service, service->state);
1241 str = state2string(service->state);
1245 connman_dbus_property_changed_basic(service->path,
1246 CONNMAN_SERVICE_INTERFACE, "State",
1247 DBUS_TYPE_STRING, &str);
1250 static void strength_changed(struct connman_service *service)
1252 if (service->strength == 0)
1255 connman_dbus_property_changed_basic(service->path,
1256 CONNMAN_SERVICE_INTERFACE, "Strength",
1257 DBUS_TYPE_BYTE, &service->strength);
1260 static void favorite_changed(struct connman_service *service)
1262 if (service->path == NULL)
1265 connman_dbus_property_changed_basic(service->path,
1266 CONNMAN_SERVICE_INTERFACE, "Favorite",
1267 DBUS_TYPE_BOOLEAN, &service->favorite);
1270 static void immutable_changed(struct connman_service *service)
1272 if (service->path == NULL)
1275 connman_dbus_property_changed_basic(service->path,
1276 CONNMAN_SERVICE_INTERFACE, "Immutable",
1277 DBUS_TYPE_BOOLEAN, &service->immutable);
1280 static void roaming_changed(struct connman_service *service)
1282 if (service->path == NULL)
1285 connman_dbus_property_changed_basic(service->path,
1286 CONNMAN_SERVICE_INTERFACE, "Roaming",
1287 DBUS_TYPE_BOOLEAN, &service->roaming);
1290 static void autoconnect_changed(struct connman_service *service)
1292 if (service->path == NULL)
1295 connman_dbus_property_changed_basic(service->path,
1296 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
1297 DBUS_TYPE_BOOLEAN, &service->autoconnect);
1300 static void passphrase_changed(struct connman_service *service)
1302 dbus_bool_t required;
1304 switch (service->type) {
1305 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1306 case CONNMAN_SERVICE_TYPE_SYSTEM:
1307 case CONNMAN_SERVICE_TYPE_ETHERNET:
1308 case CONNMAN_SERVICE_TYPE_WIMAX:
1309 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1310 case CONNMAN_SERVICE_TYPE_CELLULAR:
1311 case CONNMAN_SERVICE_TYPE_GPS:
1312 case CONNMAN_SERVICE_TYPE_VPN:
1313 case CONNMAN_SERVICE_TYPE_GADGET:
1315 case CONNMAN_SERVICE_TYPE_WIFI:
1318 switch (service->security) {
1319 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1320 case CONNMAN_SERVICE_SECURITY_NONE:
1322 case CONNMAN_SERVICE_SECURITY_WEP:
1323 case CONNMAN_SERVICE_SECURITY_PSK:
1324 case CONNMAN_SERVICE_SECURITY_WPA:
1325 case CONNMAN_SERVICE_SECURITY_RSN:
1326 if (service->passphrase == NULL)
1329 case CONNMAN_SERVICE_SECURITY_8021X:
1335 connman_dbus_property_changed_basic(service->path,
1336 CONNMAN_SERVICE_INTERFACE, "PassphraseRequired",
1337 DBUS_TYPE_BOOLEAN, &required);
1340 static void login_changed(struct connman_service *service)
1342 dbus_bool_t required = service->login_required;
1344 if (service->path == NULL)
1347 connman_dbus_property_changed_basic(service->path,
1348 CONNMAN_SERVICE_INTERFACE, "LoginRequired",
1349 DBUS_TYPE_BOOLEAN, &required);
1352 static void append_security(DBusMessageIter *iter, void *user_data)
1354 struct connman_service *service = user_data;
1357 str = security2string(service->security);
1359 dbus_message_iter_append_basic(iter,
1360 DBUS_TYPE_STRING, &str);
1363 if (service->wps == TRUE)
1364 dbus_message_iter_append_basic(iter,
1365 DBUS_TYPE_STRING, &str);
1368 static void append_ethernet(DBusMessageIter *iter, void *user_data)
1370 struct connman_service *service = user_data;
1372 if (service->ipconfig_ipv4 != NULL)
1373 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
1375 else if (service->ipconfig_ipv6 != NULL)
1376 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
1380 static void append_ipv4(DBusMessageIter *iter, void *user_data)
1382 struct connman_service *service = user_data;
1384 DBG("ipv4 %p state %s", service->ipconfig_ipv4,
1385 state2string(service->state_ipv4));
1387 if (is_connected_state(service, service->state_ipv4) == FALSE)
1390 if (service->ipconfig_ipv4 != NULL)
1391 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
1394 static void append_ipv6(DBusMessageIter *iter, void *user_data)
1396 struct connman_service *service = user_data;
1398 DBG("ipv6 %p state %s", service->ipconfig_ipv6,
1399 state2string(service->state_ipv6));
1401 if (is_connected_state(service, service->state_ipv6) == FALSE)
1404 if (service->ipconfig_ipv6 != NULL)
1405 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
1406 service->ipconfig_ipv4);
1409 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
1411 struct connman_service *service = user_data;
1413 if (service->ipconfig_ipv4 != NULL)
1414 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
1418 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
1420 struct connman_service *service = user_data;
1422 if (service->ipconfig_ipv6 != NULL)
1423 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
1427 static void append_nameserver(DBusMessageIter *iter, char ***nameservers)
1432 servers = *nameservers;
1434 for (i = 0; servers[i] != NULL; i++) {
1435 dbus_message_iter_append_basic(iter,
1436 DBUS_TYPE_STRING, &servers[i]);
1440 static void append_dns(DBusMessageIter *iter, void *user_data)
1442 struct connman_service *service = user_data;
1444 if (is_connected(service) == FALSE)
1447 if (service->nameservers_config != NULL) {
1448 append_nameserver(iter, &service->nameservers_config);
1450 } else if (service->nameservers != NULL) {
1451 append_nameserver(iter, &service->nameservers);
1456 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
1458 struct connman_service *service = user_data;
1461 if (service->nameservers_config == NULL)
1464 for (i = 0; service->nameservers_config[i]; i++) {
1465 dbus_message_iter_append_basic(iter,
1467 &service->nameservers_config[i]);
1471 static void append_domain(DBusMessageIter *iter, void *user_data)
1473 struct connman_service *service = user_data;
1475 if (is_connected(service) == FALSE &&
1476 is_connecting(service) == FALSE)
1479 if (service->domainname == NULL)
1482 dbus_message_iter_append_basic(iter,
1483 DBUS_TYPE_STRING, &service->domainname);
1486 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
1488 struct connman_service *service = user_data;
1491 if (service->domains == NULL)
1494 for (i = 0; service->domains[i]; i++)
1495 dbus_message_iter_append_basic(iter,
1496 DBUS_TYPE_STRING, &service->domains[i]);
1499 static void append_proxies(DBusMessageIter *iter, void *user_data)
1501 struct connman_service *service = user_data;
1504 if (service->proxies == NULL)
1507 for (i = 0; service->proxies[i]; i++)
1508 dbus_message_iter_append_basic(iter,
1509 DBUS_TYPE_STRING, &service->proxies[i]);
1512 static void append_excludes(DBusMessageIter *iter, void *user_data)
1514 struct connman_service *service = user_data;
1517 if (service->excludes == NULL)
1520 for (i = 0; service->excludes[i]; i++)
1521 dbus_message_iter_append_basic(iter,
1522 DBUS_TYPE_STRING, &service->excludes[i]);
1525 static void append_proxy(DBusMessageIter *iter, void *user_data)
1527 struct connman_service *service = user_data;
1528 enum connman_service_proxy_method proxy;
1529 const char *pac = NULL;
1530 const char *method = proxymethod2string(
1531 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
1535 if (is_connected(service) == FALSE)
1538 proxy = connman_service_get_proxy_method(service);
1541 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
1543 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
1545 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
1546 connman_dbus_dict_append_array(iter, "Servers",
1547 DBUS_TYPE_STRING, append_proxies,
1550 connman_dbus_dict_append_array(iter, "Excludes",
1551 DBUS_TYPE_STRING, append_excludes,
1554 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
1555 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
1556 if (service->ipconfig_ipv4 != NULL)
1557 pac = __connman_ipconfig_get_proxy_autoconfig(
1558 service->ipconfig_ipv4);
1559 else if (service->ipconfig_ipv6 != NULL)
1560 pac = __connman_ipconfig_get_proxy_autoconfig(
1561 service->ipconfig_ipv6);
1563 if (service->pac == NULL && pac == NULL)
1566 if (service->pac != NULL)
1569 connman_dbus_dict_append_basic(iter, "URL",
1570 DBUS_TYPE_STRING, &pac);
1574 method = proxymethod2string(proxy);
1577 connman_dbus_dict_append_basic(iter, "Method",
1578 DBUS_TYPE_STRING, &method);
1581 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
1583 struct connman_service *service = user_data;
1586 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
1589 switch (service->proxy_config) {
1590 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
1592 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
1594 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
1595 if (service->proxies != NULL)
1596 connman_dbus_dict_append_array(iter, "Servers",
1598 append_proxies, service);
1600 if (service->excludes != NULL)
1601 connman_dbus_dict_append_array(iter, "Excludes",
1603 append_excludes, service);
1605 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
1606 if (service->pac != NULL)
1607 connman_dbus_dict_append_basic(iter, "URL",
1608 DBUS_TYPE_STRING, &service->pac);
1612 method = proxymethod2string(service->proxy_config);
1614 connman_dbus_dict_append_basic(iter, "Method",
1615 DBUS_TYPE_STRING, &method);
1618 static void append_provider(DBusMessageIter *iter, void *user_data)
1620 struct connman_service *service = user_data;
1622 DBG("%p %p", service, service->provider);
1624 if (is_connected(service) == FALSE)
1627 if (service->provider != NULL)
1628 __connman_provider_append_properties(service->provider, iter);
1632 static void settings_changed(struct connman_service *service,
1633 struct connman_ipconfig *ipconfig)
1635 connman_dbus_property_changed_dict(service->path,
1636 CONNMAN_SERVICE_INTERFACE, "IPv4",
1637 append_ipv4, service);
1639 connman_dbus_property_changed_dict(service->path,
1640 CONNMAN_SERVICE_INTERFACE, "IPv6",
1641 append_ipv6, service);
1643 __connman_notifier_ipconfig_changed(service, ipconfig);
1646 static void ipv4_configuration_changed(struct connman_service *service)
1648 connman_dbus_property_changed_dict(service->path,
1649 CONNMAN_SERVICE_INTERFACE,
1650 "IPv4.Configuration",
1655 static void ipv6_configuration_changed(struct connman_service *service)
1657 connman_dbus_property_changed_dict(service->path,
1658 CONNMAN_SERVICE_INTERFACE,
1659 "IPv6.Configuration",
1664 static void dns_changed(struct connman_service *service)
1666 connman_dbus_property_changed_array(service->path,
1667 CONNMAN_SERVICE_INTERFACE, "Nameservers",
1668 DBUS_TYPE_STRING, append_dns, service);
1671 static void dns_configuration_changed(struct connman_service *service)
1673 connman_dbus_property_changed_array(service->path,
1674 CONNMAN_SERVICE_INTERFACE,
1675 "Nameservers.Configuration",
1676 DBUS_TYPE_STRING, append_dnsconfig, service);
1678 dns_changed(service);
1681 static void domain_changed(struct connman_service *service)
1683 connman_dbus_property_changed_array(service->path,
1684 CONNMAN_SERVICE_INTERFACE, "Domains",
1685 DBUS_TYPE_STRING, append_domain, service);
1688 static void domain_configuration_changed(struct connman_service *service)
1690 connman_dbus_property_changed_array(service->path,
1691 CONNMAN_SERVICE_INTERFACE,
1692 "Domains.Configuration",
1693 DBUS_TYPE_STRING, append_domainconfig, service);
1696 static void proxy_changed(struct connman_service *service)
1698 connman_dbus_property_changed_dict(service->path,
1699 CONNMAN_SERVICE_INTERFACE, "Proxy",
1700 append_proxy, service);
1703 static void proxy_configuration_changed(struct connman_service *service)
1705 connman_dbus_property_changed_dict(service->path,
1706 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
1707 append_proxyconfig, service);
1709 proxy_changed(service);
1712 static void link_changed(struct connman_service *service)
1714 connman_dbus_property_changed_dict(service->path,
1715 CONNMAN_SERVICE_INTERFACE, "Ethernet",
1716 append_ethernet, service);
1719 static void stats_append_counters(DBusMessageIter *dict,
1720 struct connman_stats_data *stats,
1721 struct connman_stats_data *counters,
1722 connman_bool_t append_all)
1724 if (counters->rx_packets != stats->rx_packets || append_all) {
1725 counters->rx_packets = stats->rx_packets;
1726 connman_dbus_dict_append_basic(dict, "RX.Packets",
1727 DBUS_TYPE_UINT32, &stats->rx_packets);
1730 if (counters->tx_packets != stats->tx_packets || append_all) {
1731 counters->tx_packets = stats->tx_packets;
1732 connman_dbus_dict_append_basic(dict, "TX.Packets",
1733 DBUS_TYPE_UINT32, &stats->tx_packets);
1736 if (counters->rx_bytes != stats->rx_bytes || append_all) {
1737 counters->rx_bytes = stats->rx_bytes;
1738 connman_dbus_dict_append_basic(dict, "RX.Bytes",
1739 DBUS_TYPE_UINT32, &stats->rx_bytes);
1742 if (counters->tx_bytes != stats->tx_bytes || append_all) {
1743 counters->tx_bytes = stats->tx_bytes;
1744 connman_dbus_dict_append_basic(dict, "TX.Bytes",
1745 DBUS_TYPE_UINT32, &stats->tx_bytes);
1748 if (counters->rx_errors != stats->rx_errors || append_all) {
1749 counters->rx_errors = stats->rx_errors;
1750 connman_dbus_dict_append_basic(dict, "RX.Errors",
1751 DBUS_TYPE_UINT32, &stats->rx_errors);
1754 if (counters->tx_errors != stats->tx_errors || append_all) {
1755 counters->tx_errors = stats->tx_errors;
1756 connman_dbus_dict_append_basic(dict, "TX.Errors",
1757 DBUS_TYPE_UINT32, &stats->tx_errors);
1760 if (counters->rx_dropped != stats->rx_dropped || append_all) {
1761 counters->rx_dropped = stats->rx_dropped;
1762 connman_dbus_dict_append_basic(dict, "RX.Dropped",
1763 DBUS_TYPE_UINT32, &stats->rx_dropped);
1766 if (counters->tx_dropped != stats->tx_dropped || append_all) {
1767 counters->tx_dropped = stats->tx_dropped;
1768 connman_dbus_dict_append_basic(dict, "TX.Dropped",
1769 DBUS_TYPE_UINT32, &stats->tx_dropped);
1772 if (counters->time != stats->time || append_all) {
1773 counters->time = stats->time;
1774 connman_dbus_dict_append_basic(dict, "Time",
1775 DBUS_TYPE_UINT32, &stats->time);
1779 static void stats_append(struct connman_service *service,
1780 const char *counter,
1781 struct connman_stats_counter *counters,
1782 connman_bool_t append_all)
1784 DBusMessageIter array, dict;
1787 DBG("service %p counter %s", service, counter);
1789 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
1793 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
1794 &service->path, DBUS_TYPE_INVALID);
1796 dbus_message_iter_init_append(msg, &array);
1799 connman_dbus_dict_open(&array, &dict);
1801 stats_append_counters(&dict, &service->stats.data,
1802 &counters->stats.data, append_all);
1804 connman_dbus_dict_close(&array, &dict);
1806 /* roaming counter */
1807 connman_dbus_dict_open(&array, &dict);
1809 stats_append_counters(&dict, &service->stats_roaming.data,
1810 &counters->stats_roaming.data, append_all);
1812 connman_dbus_dict_close(&array, &dict);
1814 __connman_counter_send_usage(counter, msg);
1817 static void stats_update(struct connman_service *service,
1818 unsigned int rx_packets, unsigned int tx_packets,
1819 unsigned int rx_bytes, unsigned int tx_bytes,
1820 unsigned int rx_errors, unsigned int tx_errors,
1821 unsigned int rx_dropped, unsigned int tx_dropped)
1823 struct connman_stats *stats = stats_get(service);
1824 struct connman_stats_data *data_last = &stats->data_last;
1825 struct connman_stats_data *data = &stats->data;
1826 unsigned int seconds;
1828 DBG("service %p", service);
1830 if (stats->valid == TRUE) {
1832 rx_packets - data_last->rx_packets;
1834 tx_packets - data_last->tx_packets;
1836 rx_bytes - data_last->rx_bytes;
1838 tx_bytes - data_last->tx_bytes;
1840 rx_errors - data_last->rx_errors;
1842 tx_errors - data_last->tx_errors;
1844 rx_dropped - data_last->rx_dropped;
1846 tx_dropped - data_last->tx_dropped;
1848 stats->valid = TRUE;
1851 data_last->rx_packets = rx_packets;
1852 data_last->tx_packets = tx_packets;
1853 data_last->rx_bytes = rx_bytes;
1854 data_last->tx_bytes = tx_bytes;
1855 data_last->rx_errors = rx_errors;
1856 data_last->tx_errors = tx_errors;
1857 data_last->rx_dropped = rx_dropped;
1858 data_last->tx_dropped = tx_dropped;
1860 seconds = g_timer_elapsed(stats->timer, NULL);
1861 stats->data.time = stats->data_last.time + seconds;
1864 static char *wifi_build_group_name(const unsigned char *ssid,
1865 unsigned int ssid_len,
1867 const char *security)
1872 /* the last 3 is for the 2 '_' and '\0' */
1873 str = g_string_sized_new((ssid_len * 2) + strlen(mode)
1874 + strlen(security) + 3);
1878 for (i = 0; i < ssid_len; i++)
1879 g_string_append_printf(str, "%02x", ssid[i]);
1881 g_string_append_printf(str, "_%s_%s", mode, security);
1883 return g_string_free(str, FALSE);
1886 void __connman_service_notify(struct connman_service *service,
1887 unsigned int rx_packets, unsigned int tx_packets,
1888 unsigned int rx_bytes, unsigned int tx_bytes,
1889 unsigned int rx_errors, unsigned int tx_errors,
1890 unsigned int rx_dropped, unsigned int tx_dropped)
1892 GHashTableIter iter;
1893 gpointer key, value;
1894 const char *counter;
1895 struct connman_stats_counter *counters;
1896 struct connman_stats_data *data;
1899 if (service == NULL)
1902 if (is_connected(service) == FALSE)
1905 stats_update(service,
1906 rx_packets, tx_packets,
1908 rx_errors, tx_errors,
1909 rx_dropped, tx_dropped);
1911 data = &stats_get(service)->data;
1912 err = __connman_stats_update(service, service->roaming, data);
1914 connman_error("Failed to store statistics for %s",
1915 service->identifier);
1917 g_hash_table_iter_init(&iter, service->counter_table);
1918 while (g_hash_table_iter_next(&iter, &key, &value)) {
1922 stats_append(service, counter, counters, counters->append_all);
1923 counters->append_all = FALSE;
1927 int __connman_service_counter_register(const char *counter)
1929 struct connman_service *service;
1930 GSequenceIter *iter;
1931 struct connman_stats_counter *counters;
1933 DBG("counter %s", counter);
1935 counter_list = g_slist_append(counter_list, (gpointer)counter);
1937 iter = g_sequence_get_begin_iter(service_list);
1939 while (g_sequence_iter_is_end(iter) == FALSE) {
1940 service = g_sequence_get(iter);
1942 counters = g_try_new0(struct connman_stats_counter, 1);
1943 if (counters == NULL)
1946 counters->append_all = TRUE;
1948 g_hash_table_replace(service->counter_table, (gpointer)counter,
1951 iter = g_sequence_iter_next(iter);
1957 void __connman_service_counter_unregister(const char *counter)
1959 struct connman_service *service;
1960 GSequenceIter *iter;
1962 DBG("counter %s", counter);
1964 iter = g_sequence_get_begin_iter(service_list);
1966 while (g_sequence_iter_is_end(iter) == FALSE) {
1967 service = g_sequence_get(iter);
1969 g_hash_table_remove(service->counter_table, counter);
1971 iter = g_sequence_iter_next(iter);
1974 counter_list = g_slist_remove(counter_list, counter);
1977 GSequence *__connman_service_get_list(struct connman_session *session,
1978 service_match_cb service_match,
1979 create_service_entry_cb create_service_entry,
1980 GDestroyNotify destroy_service_entry)
1983 GSequenceIter *iter;
1984 struct connman_service *service;
1985 struct service_entry *entry;
1987 list = g_sequence_new(destroy_service_entry);
1991 iter = g_sequence_get_begin_iter(service_list);
1993 while (g_sequence_iter_is_end(iter) == FALSE) {
1994 service = g_sequence_get(iter);
1996 if (service_match(session, service) == TRUE) {
1997 entry = create_service_entry(service, service->name,
2002 g_sequence_append(list, entry);
2005 iter = g_sequence_iter_next(iter);
2011 void __connman_service_session_inc(struct connman_service *service)
2013 DBG("service %p ref count %d", service,
2014 g_atomic_int_get(&service->session_usage_count) + 1);
2016 g_atomic_int_inc(&service->session_usage_count);
2019 connman_bool_t __connman_service_session_dec(struct connman_service *service)
2021 DBG("service %p ref count %d", service,
2022 g_atomic_int_get(&service->session_usage_count) - 1);
2024 if (g_atomic_int_dec_and_test(&service->session_usage_count) == FALSE)
2030 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
2031 struct connman_service *service)
2033 dbus_bool_t required;
2036 str = __connman_service_type2string(service->type);
2038 connman_dbus_dict_append_basic(dict, "Type",
2039 DBUS_TYPE_STRING, &str);
2041 connman_dbus_dict_append_array(dict, "Security",
2042 DBUS_TYPE_STRING, append_security, service);
2044 str = state2string(service->state);
2046 connman_dbus_dict_append_basic(dict, "State",
2047 DBUS_TYPE_STRING, &str);
2049 str = error2string(service->error);
2051 connman_dbus_dict_append_basic(dict, "Error",
2052 DBUS_TYPE_STRING, &str);
2054 if (service->strength > 0)
2055 connman_dbus_dict_append_basic(dict, "Strength",
2056 DBUS_TYPE_BYTE, &service->strength);
2058 connman_dbus_dict_append_basic(dict, "Favorite",
2059 DBUS_TYPE_BOOLEAN, &service->favorite);
2061 connman_dbus_dict_append_basic(dict, "Immutable",
2062 DBUS_TYPE_BOOLEAN, &service->immutable);
2064 if (service->favorite == TRUE)
2065 connman_dbus_dict_append_basic(dict, "AutoConnect",
2066 DBUS_TYPE_BOOLEAN, &service->autoconnect);
2068 connman_dbus_dict_append_basic(dict, "AutoConnect",
2069 DBUS_TYPE_BOOLEAN, &service->favorite);
2071 if (service->name != NULL)
2072 connman_dbus_dict_append_basic(dict, "Name",
2073 DBUS_TYPE_STRING, &service->name);
2075 connman_dbus_dict_append_basic(dict, "LoginRequired",
2076 DBUS_TYPE_BOOLEAN, &service->login_required);
2078 switch (service->type) {
2079 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2080 case CONNMAN_SERVICE_TYPE_SYSTEM:
2081 case CONNMAN_SERVICE_TYPE_GPS:
2082 case CONNMAN_SERVICE_TYPE_VPN:
2083 case CONNMAN_SERVICE_TYPE_GADGET:
2085 case CONNMAN_SERVICE_TYPE_CELLULAR:
2086 connman_dbus_dict_append_basic(dict, "Roaming",
2087 DBUS_TYPE_BOOLEAN, &service->roaming);
2090 connman_dbus_dict_append_basic(dict, "SetupRequired",
2091 DBUS_TYPE_BOOLEAN, &required);
2092 connman_dbus_dict_append_dict(dict, "Ethernet",
2093 append_ethernet, service);
2095 case CONNMAN_SERVICE_TYPE_WIFI:
2096 if (service->passphrase != NULL && limited == FALSE)
2097 connman_dbus_dict_append_basic(dict, "Passphrase",
2098 DBUS_TYPE_STRING, &service->passphrase);
2102 switch (service->security) {
2103 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
2104 case CONNMAN_SERVICE_SECURITY_NONE:
2106 case CONNMAN_SERVICE_SECURITY_WEP:
2107 case CONNMAN_SERVICE_SECURITY_PSK:
2108 case CONNMAN_SERVICE_SECURITY_WPA:
2109 case CONNMAN_SERVICE_SECURITY_RSN:
2110 if (service->passphrase == NULL)
2113 case CONNMAN_SERVICE_SECURITY_8021X:
2117 connman_dbus_dict_append_basic(dict, "PassphraseRequired",
2118 DBUS_TYPE_BOOLEAN, &required);
2121 case CONNMAN_SERVICE_TYPE_ETHERNET:
2122 case CONNMAN_SERVICE_TYPE_WIMAX:
2123 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2124 connman_dbus_dict_append_dict(dict, "Ethernet",
2125 append_ethernet, service);
2129 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
2131 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
2132 append_ipv4config, service);
2134 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
2136 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
2137 append_ipv6config, service);
2139 connman_dbus_dict_append_array(dict, "Nameservers",
2140 DBUS_TYPE_STRING, append_dns, service);
2142 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
2143 DBUS_TYPE_STRING, append_dnsconfig, service);
2145 connman_dbus_dict_append_array(dict, "Domains",
2146 DBUS_TYPE_STRING, append_domain, service);
2148 connman_dbus_dict_append_array(dict, "Domains.Configuration",
2149 DBUS_TYPE_STRING, append_domainconfig, service);
2151 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
2153 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
2154 append_proxyconfig, service);
2156 connman_dbus_dict_append_dict(dict, "Provider",
2157 append_provider, service);
2160 static void append_struct(gpointer value, gpointer user_data)
2162 struct connman_service *service = value;
2163 DBusMessageIter *iter = user_data;
2164 DBusMessageIter entry, dict;
2166 if (service->path == NULL || service->hidden == TRUE)
2169 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
2171 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
2174 connman_dbus_dict_open(&entry, &dict);
2175 append_properties(&dict, TRUE, service);
2176 connman_dbus_dict_close(&entry, &dict);
2178 dbus_message_iter_close_container(iter, &entry);
2181 void __connman_service_list_struct(DBusMessageIter *iter)
2183 g_sequence_foreach(service_list, append_struct, iter);
2186 int __connman_service_get_index(struct connman_service *service)
2188 if (service == NULL)
2191 if (service->network != NULL)
2192 return connman_network_get_index(service->network);
2193 else if (service->provider != NULL)
2194 return connman_provider_get_index(service->provider);
2199 void __connman_service_set_domainname(struct connman_service *service,
2200 const char *domainname)
2202 if (service == NULL)
2205 g_free(service->domainname);
2206 service->domainname = g_strdup(domainname);
2208 domain_changed(service);
2211 const char *connman_service_get_domainname(struct connman_service *service)
2213 if (service == NULL)
2216 if (service->domains != NULL)
2217 return service->domains[0];
2219 return service->domainname;
2222 char **connman_service_get_nameservers(struct connman_service *service)
2224 if (service == NULL)
2227 if (service->nameservers_config != NULL)
2228 return service->nameservers_config;
2229 else if (service->nameservers != NULL)
2230 return service->nameservers;
2235 void connman_service_set_proxy_method(struct connman_service *service,
2236 enum connman_service_proxy_method method)
2238 if (service == NULL)
2241 service->proxy = method;
2243 proxy_changed(service);
2245 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
2246 __connman_notifier_proxy_changed(service);
2249 enum connman_service_proxy_method connman_service_get_proxy_method(
2250 struct connman_service *service)
2252 if (service == NULL)
2253 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
2255 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
2256 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
2257 service->pac == NULL)
2258 return service->proxy;
2260 return service->proxy_config;
2263 return service->proxy;
2266 char **connman_service_get_proxy_servers(struct connman_service *service)
2268 return g_strdupv(service->proxies);
2271 char **connman_service_get_proxy_excludes(struct connman_service *service)
2273 return g_strdupv(service->excludes);
2276 const char *connman_service_get_proxy_url(struct connman_service *service)
2278 if (service == NULL)
2281 return service->pac;
2284 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
2287 if (service == NULL)
2290 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
2292 if (service->ipconfig_ipv4) {
2293 if (__connman_ipconfig_set_proxy_autoconfig(
2294 service->ipconfig_ipv4, url) < 0)
2296 } else if (service->ipconfig_ipv6) {
2297 if (__connman_ipconfig_set_proxy_autoconfig(
2298 service->ipconfig_ipv6, url) < 0)
2303 proxy_changed(service);
2305 __connman_notifier_proxy_changed(service);
2308 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
2310 if (service == NULL)
2313 if (service->ipconfig_ipv4)
2314 return __connman_ipconfig_get_proxy_autoconfig(
2315 service->ipconfig_ipv4);
2316 else if (service->ipconfig_ipv6)
2317 return __connman_ipconfig_get_proxy_autoconfig(
2318 service->ipconfig_ipv6);
2322 static void update_timeservers(struct connman_service *service)
2326 if (service->timeservers == NULL)
2329 switch (service->state) {
2330 case CONNMAN_SERVICE_STATE_UNKNOWN:
2331 case CONNMAN_SERVICE_STATE_IDLE:
2332 case CONNMAN_SERVICE_STATE_ASSOCIATION:
2333 case CONNMAN_SERVICE_STATE_CONFIGURATION:
2335 case CONNMAN_SERVICE_STATE_FAILURE:
2336 case CONNMAN_SERVICE_STATE_DISCONNECT:
2337 for (i = 0; service->timeservers[i] != NULL; i++)
2338 connman_timeserver_remove(service->timeservers[i]);
2340 case CONNMAN_SERVICE_STATE_READY:
2341 case CONNMAN_SERVICE_STATE_ONLINE:
2345 for (i = 0; service->timeservers[i] != NULL; i++)
2346 connman_timeserver_append(service->timeservers[i]);
2349 int __connman_service_timeserver_append(struct connman_service *service,
2350 const char *timeserver)
2354 DBG("service %p timeserver %s", service, timeserver);
2356 if (timeserver == NULL)
2359 if (service->timeservers != NULL) {
2362 for (i = 0; service->timeservers[i] != NULL; i++)
2363 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
2366 len = g_strv_length(service->timeservers);
2367 service->timeservers = g_try_renew(char *, service->timeservers,
2371 service->timeservers = g_try_new0(char *, len + 2);
2374 if (service->timeservers == NULL)
2377 service->timeservers[len] = g_strdup(timeserver);
2378 service->timeservers[len + 1] = NULL;
2380 update_timeservers(service);
2385 int __connman_service_timeserver_remove(struct connman_service *service,
2386 const char *timeserver)
2391 DBG("service %p timeserver %s", service, timeserver);
2393 if (timeserver == NULL)
2396 if (service->timeservers == NULL)
2399 len = g_strv_length(service->timeservers);
2401 if (g_strcmp0(service->timeservers[0], timeserver) != 0)
2404 g_strfreev(service->timeservers);
2405 service->timeservers = NULL;
2410 servers = g_try_new0(char *, len - 1);
2411 if (servers == NULL)
2414 for (i = 0, j = 0; i < len; i++) {
2415 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
2416 servers[j] = g_strdup(service->timeservers[i]);
2420 servers[len - 2] = NULL;
2422 g_strfreev(service->timeservers);
2423 service->timeservers = servers;
2425 update_timeservers(service);
2430 void __connman_service_set_pac(struct connman_service *service,
2433 g_free(service->pac);
2434 service->pac = g_strdup(pac);
2436 proxy_changed(service);
2439 void __connman_service_set_identity(struct connman_service *service,
2440 const char *identity)
2442 if (service->immutable)
2445 g_free(service->identity);
2446 service->identity = g_strdup(identity);
2448 if (service->network != NULL)
2449 connman_network_set_string(service->network,
2454 void __connman_service_set_agent_identity(struct connman_service *service,
2455 const char *agent_identity)
2457 g_free(service->agent_identity);
2458 service->agent_identity = g_strdup(agent_identity);
2460 if (service->network != NULL)
2461 connman_network_set_string(service->network,
2462 "WiFi.AgentIdentity",
2463 service->agent_identity);
2466 void __connman_service_set_passphrase(struct connman_service *service,
2467 const char* passphrase)
2469 if (service->immutable == TRUE)
2472 g_free(service->passphrase);
2473 service->passphrase = g_strdup(passphrase);
2475 passphrase_changed(service);
2477 if (service->network != NULL)
2478 connman_network_set_string(service->network,
2480 service->passphrase);
2482 service_save(service);
2485 void __connman_service_set_agent_passphrase(struct connman_service *service,
2486 const char *agent_passphrase)
2488 g_free(service->agent_passphrase);
2489 service->agent_passphrase = g_strdup(agent_passphrase);
2491 if (service->network != NULL)
2492 connman_network_set_string(service->network,
2493 "WiFi.AgentPassphrase",
2494 service->agent_passphrase);
2497 static DBusMessage *get_properties(DBusConnection *conn,
2498 DBusMessage *msg, void *user_data)
2500 struct connman_service *service = user_data;
2502 DBusMessageIter array, dict;
2504 DBG("service %p", service);
2506 reply = dbus_message_new_method_return(msg);
2510 dbus_message_iter_init_append(reply, &array);
2512 connman_dbus_dict_open(&array, &dict);
2513 append_properties(&dict, FALSE, service);
2514 connman_dbus_dict_close(&array, &dict);
2519 static int update_proxy_configuration(struct connman_service *service,
2520 DBusMessageIter *array)
2522 DBusMessageIter dict;
2523 enum connman_service_proxy_method method;
2524 GString *servers_str = NULL;
2525 GString *excludes_str = NULL;
2526 const char *url = NULL;
2528 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
2530 dbus_message_iter_recurse(array, &dict);
2532 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2533 DBusMessageIter entry, variant;
2537 dbus_message_iter_recurse(&dict, &entry);
2539 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2542 dbus_message_iter_get_basic(&entry, &key);
2543 dbus_message_iter_next(&entry);
2545 if (dbus_message_iter_get_arg_type(&entry) !=
2549 dbus_message_iter_recurse(&entry, &variant);
2550 type = dbus_message_iter_get_arg_type(&variant);
2552 if (g_str_equal(key, "Method") == TRUE) {
2555 if (type != DBUS_TYPE_STRING)
2558 dbus_message_iter_get_basic(&variant, &val);
2559 method = string2proxymethod(val);
2560 } else if (g_str_equal(key, "URL") == TRUE) {
2561 if (type != DBUS_TYPE_STRING)
2564 dbus_message_iter_get_basic(&variant, &url);
2565 } else if (g_str_equal(key, "Servers") == TRUE) {
2566 DBusMessageIter str_array;
2568 if (type != DBUS_TYPE_ARRAY)
2571 servers_str = g_string_new(NULL);
2572 if (servers_str == NULL)
2575 dbus_message_iter_recurse(&variant, &str_array);
2577 while (dbus_message_iter_get_arg_type(&str_array) ==
2581 dbus_message_iter_get_basic(&str_array, &val);
2583 if (servers_str->len > 0)
2584 g_string_append_printf(servers_str,
2587 g_string_append(servers_str, val);
2589 dbus_message_iter_next(&str_array);
2591 } else if (g_str_equal(key, "Excludes") == TRUE) {
2592 DBusMessageIter str_array;
2594 if (type != DBUS_TYPE_ARRAY)
2597 excludes_str = g_string_new(NULL);
2598 if (excludes_str == NULL)
2601 dbus_message_iter_recurse(&variant, &str_array);
2603 while (dbus_message_iter_get_arg_type(&str_array) ==
2607 dbus_message_iter_get_basic(&str_array, &val);
2609 if (excludes_str->len > 0)
2610 g_string_append_printf(excludes_str,
2613 g_string_append(excludes_str, val);
2615 dbus_message_iter_next(&str_array);
2619 dbus_message_iter_next(&dict);
2623 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2625 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2626 if (servers_str == NULL && service->proxies == NULL)
2629 if (servers_str != NULL) {
2630 g_strfreev(service->proxies);
2632 if (servers_str->len > 0)
2633 service->proxies = g_strsplit_set(
2634 servers_str->str, " ", 0);
2636 service->proxies = NULL;
2639 if (excludes_str != NULL) {
2640 g_strfreev(service->excludes);
2642 if (excludes_str->len > 0)
2643 service->excludes = g_strsplit_set(
2644 excludes_str->str, " ", 0);
2646 service->excludes = NULL;
2649 if (service->proxies == NULL)
2650 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
2653 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2654 g_free(service->pac);
2656 if (url != NULL && strlen(url) > 0)
2657 service->pac = g_strdup(url);
2659 service->pac = NULL;
2661 /* if we are connected:
2662 - if service->pac == NULL
2663 - if __connman_ipconfig_get_proxy_autoconfig(
2664 service->ipconfig) == NULL
2665 --> We should start WPAD */
2668 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2672 if (servers_str != NULL)
2673 g_string_free(servers_str, TRUE);
2675 if (excludes_str != NULL)
2676 g_string_free(excludes_str, TRUE);
2678 service->proxy_config = method;
2683 if (servers_str != NULL)
2684 g_string_free(servers_str, TRUE);
2686 if (excludes_str != NULL)
2687 g_string_free(excludes_str, TRUE);
2692 static int set_ipconfig(struct connman_service *service,
2693 struct connman_ipconfig *ipconfig,
2694 DBusMessageIter *array,
2695 enum connman_service_state state,
2696 enum connman_service_state *new_state)
2698 enum connman_ipconfig_method old_method;
2699 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
2700 enum connman_ipconfig_type type;
2703 if (ipconfig == NULL)
2706 old_method = __connman_ipconfig_get_method(ipconfig);
2708 if (is_connecting_state(service, state) ||
2709 is_connected_state(service, state))
2710 __connman_network_clear_ipconfig(service->network, ipconfig);
2712 err = __connman_ipconfig_set_config(ipconfig, array);
2713 method = __connman_ipconfig_get_method(ipconfig);
2714 type = __connman_ipconfig_get_config_type(ipconfig);
2716 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
2717 if (err == 0 && old_method == CONNMAN_IPCONFIG_METHOD_OFF &&
2718 method == CONNMAN_IPCONFIG_METHOD_DHCP) {
2719 *new_state = service->state_ipv4 =
2720 CONNMAN_SERVICE_STATE_CONFIGURATION;
2721 __connman_ipconfig_enable(ipconfig);
2724 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
2725 if (err == 0 && old_method == CONNMAN_IPCONFIG_METHOD_OFF &&
2726 method == CONNMAN_IPCONFIG_METHOD_AUTO) {
2727 *new_state = service->state_ipv6;
2728 __connman_ipconfig_enable(ipconfig);
2732 DBG("err %d ipconfig %p type %d method %d state %s", err, ipconfig,
2733 type, method, state2string(*new_state));
2738 static DBusMessage *set_property(DBusConnection *conn,
2739 DBusMessage *msg, void *user_data)
2741 struct connman_service *service = user_data;
2742 DBusMessageIter iter, value;
2746 DBG("service %p", service);
2748 if (dbus_message_iter_init(msg, &iter) == FALSE)
2749 return __connman_error_invalid_arguments(msg);
2751 dbus_message_iter_get_basic(&iter, &name);
2752 dbus_message_iter_next(&iter);
2753 dbus_message_iter_recurse(&iter, &value);
2755 type = dbus_message_iter_get_arg_type(&value);
2757 if (g_str_equal(name, "AutoConnect") == TRUE) {
2758 connman_bool_t autoconnect;
2760 if (type != DBUS_TYPE_BOOLEAN)
2761 return __connman_error_invalid_arguments(msg);
2763 if (service->favorite == FALSE)
2764 return __connman_error_invalid_service(msg);
2766 dbus_message_iter_get_basic(&value, &autoconnect);
2768 if (service->autoconnect == autoconnect)
2769 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2771 service->autoconnect = autoconnect;
2773 autoconnect_changed(service);
2775 service_save(service);
2776 } else if (g_str_equal(name, "Passphrase") == TRUE) {
2777 const char *passphrase;
2779 if (type != DBUS_TYPE_STRING)
2780 return __connman_error_invalid_arguments(msg);
2782 if (service->immutable == TRUE)
2783 return __connman_error_not_supported(msg);
2785 dbus_message_iter_get_basic(&value, &passphrase);
2787 __connman_service_set_passphrase(service, passphrase);
2788 } else if (g_str_equal(name, "Nameservers.Configuration") == TRUE) {
2789 DBusMessageIter entry;
2794 if (type != DBUS_TYPE_ARRAY)
2795 return __connman_error_invalid_arguments(msg);
2797 str = g_string_new(NULL);
2799 return __connman_error_invalid_arguments(msg);
2801 index = connman_network_get_index(service->network);
2802 gw = __connman_ipconfig_get_gateway_from_index(index);
2804 if (gw && strlen(gw))
2805 __connman_service_nameserver_del_routes(service);
2807 dbus_message_iter_recurse(&value, &entry);
2809 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
2811 dbus_message_iter_get_basic(&entry, &val);
2812 dbus_message_iter_next(&entry);
2814 g_string_append_printf(str, " %s", val);
2816 g_string_append(str, val);
2819 g_strfreev(service->nameservers_config);
2822 service->nameservers_config =
2823 g_strsplit_set(str->str, " ", 0);
2825 service->nameservers_config = NULL;
2828 g_string_free(str, TRUE);
2830 if (gw && strlen(gw))
2831 __connman_service_nameserver_add_routes(service, gw);
2833 update_nameservers(service);
2834 dns_configuration_changed(service);
2836 service_save(service);
2837 } else if (g_str_equal(name, "Domains.Configuration") == TRUE) {
2838 DBusMessageIter entry;
2841 if (type != DBUS_TYPE_ARRAY)
2842 return __connman_error_invalid_arguments(msg);
2844 str = g_string_new(NULL);
2846 return __connman_error_invalid_arguments(msg);
2848 dbus_message_iter_recurse(&value, &entry);
2850 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
2852 dbus_message_iter_get_basic(&entry, &val);
2853 dbus_message_iter_next(&entry);
2855 g_string_append_printf(str, " %s", val);
2857 g_string_append(str, val);
2860 g_strfreev(service->domains);
2863 service->domains = g_strsplit_set(str->str, " ", 0);
2865 service->domains = NULL;
2867 g_string_free(str, TRUE);
2869 update_nameservers(service);
2870 domain_configuration_changed(service);
2872 service_save(service);
2873 } else if (g_str_equal(name, "Proxy.Configuration") == TRUE) {
2876 if (type != DBUS_TYPE_ARRAY)
2877 return __connman_error_invalid_arguments(msg);
2879 err = update_proxy_configuration(service, &value);
2882 return __connman_error_failed(msg, -err);
2884 proxy_configuration_changed(service);
2886 __connman_notifier_proxy_changed(service);
2888 service_save(service);
2889 } else if (g_str_equal(name, "IPv4.Configuration") == TRUE ||
2890 g_str_equal(name, "IPv6.Configuration")) {
2892 struct connman_ipconfig *ipv4 = NULL, *ipv6 = NULL;
2893 enum connman_service_state state =
2894 CONNMAN_SERVICE_STATE_UNKNOWN;
2899 if (service->ipconfig_ipv4 == NULL &&
2900 service->ipconfig_ipv6 == NULL)
2901 return __connman_error_invalid_property(msg);
2903 if (g_str_equal(name, "IPv4.Configuration") == TRUE) {
2904 ipv4 = service->ipconfig_ipv4;
2905 err = set_ipconfig(service, ipv4, &value,
2906 service->state_ipv4, &state);
2908 } else if (g_str_equal(name, "IPv6.Configuration") == TRUE) {
2909 ipv6 = service->ipconfig_ipv6;
2910 err = set_ipconfig(service, ipv6, &value,
2911 service->state_ipv6, &state);
2915 if (is_connected_state(service, state) ||
2916 is_connecting_state(service, state))
2917 __connman_network_set_ipconfig(service->network,
2919 return __connman_error_failed(msg, -err);
2923 ipv4_configuration_changed(service);
2925 ipv6_configuration_changed(service);
2927 if (is_connecting(service) || is_connected(service))
2928 __connman_network_set_ipconfig(service->network,
2931 service_save(service);
2933 return __connman_error_invalid_property(msg);
2935 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2938 static void set_idle(struct connman_service *service)
2940 service->state = service->state_ipv4 = service->state_ipv6 =
2941 CONNMAN_SERVICE_STATE_IDLE;
2942 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
2943 state_changed(service);
2946 static DBusMessage *clear_property(DBusConnection *conn,
2947 DBusMessage *msg, void *user_data)
2949 struct connman_service *service = user_data;
2952 DBG("service %p", service);
2954 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
2957 if (g_str_equal(name, "Error") == TRUE) {
2960 g_get_current_time(&service->modified);
2961 service_save(service);
2962 } else if (g_str_equal(name, "Passphrase") == TRUE) {
2963 if (service->immutable == TRUE)
2964 return __connman_error_not_supported(msg);
2966 g_free(service->passphrase);
2967 service->passphrase = NULL;
2969 passphrase_changed(service);
2971 service_save(service);
2973 return __connman_error_invalid_property(msg);
2975 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2978 static connman_bool_t is_ignore(struct connman_service *service)
2980 if (service->autoconnect == FALSE)
2983 if (service->roaming == TRUE)
2986 if (service->ignore == TRUE)
2989 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
2995 void __connman_service_auto_connect(void)
2997 struct connman_service *service = NULL;
2998 GSequenceIter *iter;
3002 if (__connman_session_mode() == TRUE) {
3003 DBG("Session mode enabled: auto connect disabled");
3007 iter = g_sequence_get_begin_iter(service_list);
3009 while (g_sequence_iter_is_end(iter) == FALSE) {
3010 service = g_sequence_get(iter);
3012 if (service->pending != NULL)
3015 if (is_connecting(service) == TRUE)
3018 if (service->favorite == FALSE)
3021 if (is_connected(service) == TRUE)
3024 if (is_ignore(service) == FALSE && service->state ==
3025 CONNMAN_SERVICE_STATE_IDLE)
3030 iter = g_sequence_iter_next(iter);
3033 if (service != NULL) {
3034 service->userconnect = FALSE;
3035 __connman_service_connect(service);
3039 static void remove_timeout(struct connman_service *service)
3041 if (service->timeout > 0) {
3042 g_source_remove(service->timeout);
3043 service->timeout = 0;
3047 static void reply_pending(struct connman_service *service, int error)
3049 remove_timeout(service);
3051 if (service->pending != NULL) {
3055 reply = __connman_error_failed(service->pending,
3058 g_dbus_send_message(connection, reply);
3062 sender = dbus_message_get_interface(service->pending);
3064 DBG("sender %s", sender);
3066 if (g_strcmp0(sender, CONNMAN_MANAGER_INTERFACE) == 0)
3067 g_dbus_send_reply(connection, service->pending,
3068 DBUS_TYPE_OBJECT_PATH, &service->path,
3071 g_dbus_send_reply(connection, service->pending,
3075 dbus_message_unref(service->pending);
3076 service->pending = NULL;
3080 static gboolean connect_timeout(gpointer user_data)
3082 struct connman_service *service = user_data;
3083 connman_bool_t autoconnect = FALSE;
3085 DBG("service %p", service);
3087 service->timeout = 0;
3089 if (service->network != NULL)
3090 __connman_network_disconnect(service->network);
3092 __connman_ipconfig_disable(service->ipconfig_ipv4);
3093 __connman_ipconfig_disable(service->ipconfig_ipv6);
3095 __connman_stats_service_unregister(service);
3097 if (service->pending != NULL) {
3100 reply = __connman_error_operation_timeout(service->pending);
3102 g_dbus_send_message(connection, reply);
3104 dbus_message_unref(service->pending);
3105 service->pending = NULL;
3109 __connman_service_ipconfig_indicate_state(service,
3110 CONNMAN_SERVICE_STATE_FAILURE,
3111 CONNMAN_IPCONFIG_TYPE_IPV4);
3112 __connman_service_ipconfig_indicate_state(service,
3113 CONNMAN_SERVICE_STATE_FAILURE,
3114 CONNMAN_IPCONFIG_TYPE_IPV6);
3116 if (autoconnect == TRUE && service->userconnect == FALSE)
3117 __connman_service_auto_connect();
3122 static void set_reconnect_state(struct connman_service *service,
3123 connman_bool_t reconnect)
3125 struct connman_device *device;
3127 if (service->network == NULL)
3130 device = connman_network_get_device(service->network);
3134 __connman_device_set_reconnect(device, reconnect);
3137 static connman_bool_t get_reconnect_state(struct connman_service *service)
3139 struct connman_device *device;
3141 if (service->network == NULL)
3144 device = connman_network_get_device(service->network);
3148 return __connman_device_get_reconnect(device);
3151 static void request_input_cb (struct connman_service *service,
3152 const char *identity, const char *passphrase,
3155 DBG ("RequestInput return, %p", service);
3157 if (identity == NULL && passphrase == NULL && service->wps == FALSE)
3160 if (identity != NULL)
3161 __connman_service_set_agent_identity(service, identity);
3163 if (passphrase != NULL) {
3164 switch (service->security) {
3165 case CONNMAN_SERVICE_SECURITY_WEP:
3166 case CONNMAN_SERVICE_SECURITY_PSK:
3167 __connman_service_set_passphrase(service, passphrase);
3169 case CONNMAN_SERVICE_SECURITY_8021X:
3170 __connman_service_set_agent_passphrase(service,
3173 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3174 case CONNMAN_SERVICE_SECURITY_NONE:
3175 case CONNMAN_SERVICE_SECURITY_WPA:
3176 case CONNMAN_SERVICE_SECURITY_RSN:
3177 DBG("service security '%s' not handled",
3178 security2string(service->security));
3183 __connman_service_connect(service);
3185 /* Never cache agent provided credentials */
3186 __connman_service_set_agent_identity(service, NULL);
3187 __connman_service_set_agent_passphrase(service, NULL);
3190 static DBusMessage *connect_service(DBusConnection *conn,
3191 DBusMessage *msg, void *user_data)
3193 struct connman_service *service = user_data;
3194 GSequenceIter *iter;
3197 DBG("service %p", service);
3199 if (service->pending != NULL)
3200 return __connman_error_in_progress(msg);
3202 iter = g_sequence_get_begin_iter(service_list);
3204 while (g_sequence_iter_is_end(iter) == FALSE) {
3205 struct connman_service *temp = g_sequence_get(iter);
3207 if (service->type == temp->type && is_connecting(temp) == TRUE)
3208 return __connman_error_in_progress(msg);
3210 iter = g_sequence_iter_next(iter);
3213 service->ignore = FALSE;
3215 service->userconnect = TRUE;
3217 service->pending = dbus_message_ref(msg);
3219 set_reconnect_state(service, FALSE);
3221 err = __connman_service_connect(service);
3223 if (service->pending == NULL)
3226 if (err != -EINPROGRESS) {
3227 dbus_message_unref(service->pending);
3228 service->pending = NULL;
3230 return __connman_error_failed(msg, -err);
3236 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3239 static DBusMessage *disconnect_service(DBusConnection *conn,
3240 DBusMessage *msg, void *user_data)
3242 struct connman_service *service = user_data;
3245 DBG("service %p", service);
3247 reply_pending(service, ECONNABORTED);
3249 service->ignore = TRUE;
3251 set_reconnect_state(service, FALSE);
3253 err = __connman_service_disconnect(service);
3255 if (err != -EINPROGRESS)
3256 return __connman_error_failed(msg, -err);
3261 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3264 static DBusMessage *remove_service(DBusConnection *conn,
3265 DBusMessage *msg, void *user_data)
3267 struct connman_service *service = user_data;
3269 DBG("service %p", service);
3271 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
3272 return __connman_error_not_supported(msg);
3274 if (service->immutable == TRUE)
3275 return __connman_error_not_supported(msg);
3277 if (service->favorite == FALSE && service->state !=
3278 CONNMAN_SERVICE_STATE_FAILURE)
3279 return __connman_error_not_supported(msg);
3281 if (service->network != NULL) {
3282 set_reconnect_state(service, FALSE);
3284 __connman_network_disconnect(service->network);
3287 g_free(service->passphrase);
3288 service->passphrase = NULL;
3290 passphrase_changed(service);
3294 __connman_service_set_favorite(service, FALSE);
3295 service_save(service);
3297 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3300 static gboolean check_suitable_state(enum connman_service_state a,
3301 enum connman_service_state b)
3304 * Special check so that "ready" service can be moved before
3307 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
3308 b == CONNMAN_SERVICE_STATE_READY) ||
3309 (b == CONNMAN_SERVICE_STATE_ONLINE &&
3310 a == CONNMAN_SERVICE_STATE_READY))
3316 static DBusMessage *move_service(DBusConnection *conn,
3317 DBusMessage *msg, void *user_data,
3320 struct connman_service *service = user_data;
3321 struct connman_service *target;
3323 GSequenceIter *src, *dst;
3324 enum connman_ipconfig_method target4, target6;
3325 enum connman_ipconfig_method service4, service6;
3327 DBG("service %p", service);
3329 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
3332 if (service->favorite == FALSE)
3333 return __connman_error_not_supported(msg);
3335 target = find_service(path);
3336 if (target == NULL || target->favorite == FALSE || target == service)
3337 return __connman_error_invalid_service(msg);
3339 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
3340 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
3341 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
3342 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
3344 DBG("target %s method %d/%d state %d/%d", target->identifier,
3346 target->state_ipv4, target->state_ipv6);
3348 DBG("service %s method %d/%d state %d/%d", service->identifier,
3350 service->state_ipv4, service->state_ipv6);
3353 * If method is OFF, then we do not need to check the corresponding
3356 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
3357 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
3358 if (check_suitable_state(target->state_ipv6,
3359 service->state_ipv6) == FALSE)
3360 return __connman_error_invalid_service(msg);
3364 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
3365 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
3366 if (check_suitable_state(target->state_ipv4,
3367 service->state_ipv4) == FALSE)
3368 return __connman_error_invalid_service(msg);
3372 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
3373 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
3374 if (check_suitable_state(target->state_ipv6,
3375 service->state_ipv6) == FALSE)
3376 return __connman_error_invalid_service(msg);
3380 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
3381 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
3382 if (check_suitable_state(target->state_ipv4,
3383 service->state_ipv4) == FALSE)
3384 return __connman_error_invalid_service(msg);
3388 g_get_current_time(&service->modified);
3389 service_save(service);
3391 src = g_hash_table_lookup(service_hash, service->identifier);
3392 dst = g_hash_table_lookup(service_hash, target->identifier);
3394 before ? g_sequence_move(src, dst) : g_sequence_move(dst, src);
3396 services_changed(FALSE);
3398 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3401 static DBusMessage *move_before(DBusConnection *conn,
3402 DBusMessage *msg, void *user_data)
3404 return move_service(conn, msg, user_data, TRUE);
3407 static DBusMessage *move_after(DBusConnection *conn,
3408 DBusMessage *msg, void *user_data)
3410 return move_service(conn, msg, user_data, FALSE);
3413 static DBusMessage *reset_counters(DBusConnection *conn,
3414 DBusMessage *msg, void *user_data)
3416 struct connman_service *service = user_data;
3418 reset_stats(service);
3420 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3423 static GDBusMethodTable service_methods[] = {
3424 { "GetProperties", "", "a{sv}", get_properties },
3425 { "SetProperty", "sv", "", set_property },
3426 { "ClearProperty", "s", "", clear_property },
3427 { "Connect", "", "", connect_service,
3428 G_DBUS_METHOD_FLAG_ASYNC },
3429 { "Disconnect", "", "", disconnect_service },
3430 { "Remove", "", "", remove_service },
3431 { "MoveBefore", "o", "", move_before },
3432 { "MoveAfter", "o", "", move_after },
3433 { "ResetCounters", "", "", reset_counters },
3437 static GDBusSignalTable service_signals[] = {
3438 { "PropertyChanged", "sv" },
3442 static void service_free(gpointer user_data)
3444 struct connman_service *service = user_data;
3445 char *path = service->path;
3447 DBG("service %p", service);
3449 reply_pending(service, ENOENT);
3451 g_hash_table_remove(service_hash, service->identifier);
3453 __connman_notifier_service_remove(service);
3455 stats_stop(service);
3456 service_save(service);
3458 service->path = NULL;
3461 services_changed(FALSE);
3463 g_dbus_unregister_interface(connection, path,
3464 CONNMAN_SERVICE_INTERFACE);
3468 g_hash_table_destroy(service->counter_table);
3470 if (service->network != NULL) {
3471 if (service->network_created == TRUE)
3472 connman_network_unref(service->network);
3475 if (service->provider != NULL)
3476 connman_provider_unref(service->provider);
3478 if (service->ipconfig_ipv4 != NULL) {
3479 connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
3480 connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
3481 connman_ipconfig_unref(service->ipconfig_ipv4);
3482 service->ipconfig_ipv4 = NULL;
3485 if (service->ipconfig_ipv6 != NULL) {
3486 connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
3487 connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
3488 connman_ipconfig_unref(service->ipconfig_ipv6);
3489 service->ipconfig_ipv6 = NULL;
3492 if (service->location != NULL)
3493 connman_location_unref(service->location);
3495 g_strfreev(service->nameservers);
3496 g_strfreev(service->nameservers_config);
3497 g_strfreev(service->domains);
3498 g_strfreev(service->proxies);
3499 g_strfreev(service->excludes);
3501 g_free(service->domainname);
3502 g_free(service->pac);
3503 g_free(service->name);
3504 g_free(service->passphrase);
3505 g_free(service->agent_passphrase);
3506 g_free(service->identifier);
3507 g_free(service->eap);
3508 g_free(service->identity);
3509 g_free(service->agent_identity);
3510 g_free(service->ca_cert_file);
3511 g_free(service->client_cert_file);
3512 g_free(service->private_key_file);
3513 g_free(service->private_key_passphrase);
3514 g_free(service->phase2);
3516 if (service->stats.timer != NULL)
3517 g_timer_destroy(service->stats.timer);
3518 if (service->stats_roaming.timer != NULL)
3519 g_timer_destroy(service->stats_roaming.timer);
3525 * __connman_service_put:
3526 * @service: service structure
3528 * Release service if no longer needed
3530 void __connman_service_put(struct connman_service *service)
3532 DBG("service %p", service);
3534 if (g_atomic_int_dec_and_test(&service->refcount) == TRUE) {
3535 GSequenceIter *iter;
3537 iter = g_hash_table_lookup(service_hash, service->identifier);
3539 reply_pending(service, ECONNABORTED);
3541 __connman_service_disconnect(service);
3543 g_sequence_remove(iter);
3545 service_free(service);
3549 static void stats_init(struct connman_service *service)
3552 service->stats.valid = FALSE;
3553 service->stats.enabled = FALSE;
3554 service->stats.timer = g_timer_new();
3557 service->stats_roaming.valid = FALSE;
3558 service->stats_roaming.enabled = FALSE;
3559 service->stats_roaming.timer = g_timer_new();
3562 static void service_initialize(struct connman_service *service)
3564 DBG("service %p", service);
3566 service->refcount = 1;
3567 service->session_usage_count = 0;
3569 service->network_created = FALSE;
3571 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
3572 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
3574 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
3575 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
3576 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
3578 service->favorite = FALSE;
3579 service->immutable = FALSE;
3580 service->hidden = FALSE;
3582 service->ignore = FALSE;
3584 service->userconnect = FALSE;
3588 stats_init(service);
3590 service->provider = NULL;
3592 service->wps = FALSE;
3596 * connman_service_create:
3598 * Allocate a new service.
3600 * Returns: a newly-allocated #connman_service structure
3602 struct connman_service *connman_service_create(void)
3605 struct connman_stats_counter *counters;
3606 const char *counter;
3608 struct connman_service *service;
3610 service = g_try_new0(struct connman_service, 1);
3611 if (service == NULL)
3614 DBG("service %p", service);
3616 service->counter_table = g_hash_table_new_full(g_str_hash,
3617 g_str_equal, NULL, g_free);
3619 for (list = counter_list; list; list = list->next) {
3620 counter = list->data;
3622 counters = g_try_new0(struct connman_stats_counter, 1);
3623 if (counters == NULL) {
3624 g_hash_table_destroy(service->counter_table);
3629 counters->append_all = TRUE;
3631 g_hash_table_replace(service->counter_table, (gpointer)counter,
3635 service_initialize(service);
3637 service->location = __connman_location_create(service);
3642 struct connman_location *__connman_service_get_location(struct connman_service *service)
3644 return service->location;
3648 * connman_service_ref:
3649 * @service: service structure
3651 * Increase reference counter of service
3653 struct connman_service *connman_service_ref(struct connman_service *service)
3657 g_atomic_int_inc(&service->refcount);
3663 * connman_service_unref:
3664 * @service: service structure
3666 * Decrease reference counter of service
3668 void connman_service_unref(struct connman_service *service)
3670 __connman_service_put(service);
3673 static gint service_compare(gconstpointer a, gconstpointer b,
3676 struct connman_service *service_a = (void *) a;
3677 struct connman_service *service_b = (void *) b;
3678 enum connman_service_state state_a, state_b;
3680 state_a = service_a->state;
3681 state_b = service_b->state;
3683 if (state_a != state_b) {
3684 gboolean a_connected = is_connected(service_a);
3685 gboolean b_connected = is_connected(service_b);
3687 if (a_connected == TRUE && b_connected == TRUE) {
3688 /* We prefer online over ready state */
3689 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
3692 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
3696 if (a_connected == TRUE)
3698 if (b_connected == TRUE)
3701 if (is_connecting(service_a) == TRUE)
3703 if (is_connecting(service_b) == TRUE)
3707 if (service_a->order > service_b->order)
3710 if (service_a->order < service_b->order)
3713 if (service_a->favorite == TRUE && service_b->favorite == FALSE)
3716 if (service_a->favorite == FALSE && service_b->favorite == TRUE)
3719 if (service_a->type != service_b->type) {
3720 switch (service_a->type) {
3721 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3722 case CONNMAN_SERVICE_TYPE_SYSTEM:
3723 case CONNMAN_SERVICE_TYPE_ETHERNET:
3724 case CONNMAN_SERVICE_TYPE_GPS:
3725 case CONNMAN_SERVICE_TYPE_VPN:
3726 case CONNMAN_SERVICE_TYPE_GADGET:
3728 case CONNMAN_SERVICE_TYPE_WIFI:
3730 case CONNMAN_SERVICE_TYPE_WIMAX:
3731 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3732 case CONNMAN_SERVICE_TYPE_CELLULAR:
3737 return (gint) service_b->strength - (gint) service_a->strength;
3741 * connman_service_get_type:
3742 * @service: service structure
3744 * Get the type of service
3746 enum connman_service_type connman_service_get_type(struct connman_service *service)
3748 if (service == NULL)
3749 return CONNMAN_SERVICE_TYPE_UNKNOWN;
3751 return service->type;
3755 * connman_service_get_interface:
3756 * @service: service structure
3758 * Get network interface of service
3760 char *connman_service_get_interface(struct connman_service *service)
3764 if (service == NULL)
3767 if (service->type == CONNMAN_SERVICE_TYPE_VPN) {
3768 if (service->ipconfig_ipv4)
3769 index = connman_ipconfig_get_index(
3770 service->ipconfig_ipv4);
3771 else if (service->ipconfig_ipv6)
3772 index = connman_ipconfig_get_index(
3773 service->ipconfig_ipv6);
3777 return connman_inet_ifname(index);
3780 if (service->network == NULL)
3783 index = connman_network_get_index(service->network);
3785 return connman_inet_ifname(index);
3789 * connman_service_get_network:
3790 * @service: service structure
3792 * Get the service network
3794 struct connman_network *
3795 __connman_service_get_network(struct connman_service *service)
3797 if (service == NULL)
3800 return service->network;
3803 struct connman_ipconfig *
3804 __connman_service_get_ip4config(struct connman_service *service)
3806 if (service == NULL)
3809 return service->ipconfig_ipv4;
3812 struct connman_ipconfig *
3813 __connman_service_get_ip6config(struct connman_service *service)
3815 if (service == NULL)
3818 return service->ipconfig_ipv6;
3821 struct connman_ipconfig *
3822 __connman_service_get_ipconfig(struct connman_service *service, int family)
3824 if (family == AF_INET)
3825 return __connman_service_get_ip4config(service);
3826 else if (family == AF_INET6)
3827 return __connman_service_get_ip6config(service);
3833 enum connman_service_security __connman_service_get_security(struct connman_service *service)
3835 if (service == NULL)
3836 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
3838 return service->security;
3841 const char *__connman_service_get_phase2(struct connman_service *service)
3843 if (service == NULL)
3846 return service->phase2;
3849 connman_bool_t __connman_service_wps_enabled(struct connman_service *service)
3851 if (service == NULL)
3854 return service->wps;
3858 * __connman_service_set_favorite:
3859 * @service: service structure
3860 * @favorite: favorite value
3862 * Change the favorite setting of service
3864 int __connman_service_set_favorite(struct connman_service *service,
3865 connman_bool_t favorite)
3867 GSequenceIter *iter;
3869 iter = g_hash_table_lookup(service_hash, service->identifier);
3873 if (service->favorite == favorite)
3876 service->favorite = favorite;
3878 favorite_changed(service);
3880 g_sequence_sort_changed(iter, service_compare, NULL);
3882 services_changed(FALSE);
3887 int __connman_service_set_immutable(struct connman_service *service,
3888 connman_bool_t immutable)
3890 service->immutable = immutable;
3892 immutable_changed(service);
3897 void __connman_service_set_string(struct connman_service *service,
3898 const char *key, const char *value)
3900 if (g_str_equal(key, "EAP") == TRUE) {
3901 g_free(service->eap);
3902 service->eap = g_strdup(value);
3903 } else if (g_str_equal(key, "Identity") == TRUE) {
3904 g_free(service->identity);
3905 service->identity = g_strdup(value);
3906 } else if (g_str_equal(key, "CACertFile") == TRUE) {
3907 g_free(service->ca_cert_file);
3908 service->ca_cert_file = g_strdup(value);
3909 } else if (g_str_equal(key, "ClientCertFile") == TRUE) {
3910 g_free(service->client_cert_file);
3911 service->client_cert_file = g_strdup(value);
3912 } else if (g_str_equal(key, "PrivateKeyFile") == TRUE) {
3913 g_free(service->private_key_file);
3914 service->private_key_file = g_strdup(value);
3915 } else if (g_str_equal(key, "PrivateKeyPassphrase") == TRUE) {
3916 g_free(service->private_key_passphrase);
3917 service->private_key_passphrase = g_strdup(value);
3918 } else if (g_str_equal(key, "Phase2") == TRUE) {
3919 g_free(service->phase2);
3920 service->phase2 = g_strdup(value);
3921 } else if (g_str_equal(key, "Passphrase") == TRUE) {
3922 g_free(service->passphrase);
3923 service->passphrase = g_strdup(value);
3927 static void service_complete(struct connman_service *service)
3929 reply_pending(service, EIO);
3931 if (service->userconnect == FALSE)
3932 __connman_service_auto_connect();
3934 g_get_current_time(&service->modified);
3935 service_save(service);
3938 static void report_error_cb(struct connman_service *service,
3939 gboolean retry, void *user_data)
3942 __connman_service_connect(service);
3944 service_complete(service);
3945 services_changed(FALSE);
3946 __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
3950 static int service_indicate_state(struct connman_service *service)
3952 enum connman_service_state old_state, new_state;
3953 GSequenceIter *iter;
3955 if (service == NULL)
3958 old_state = service->state;
3959 new_state = combine_state(service->state_ipv4, service->state_ipv6);
3961 DBG("service %p old %s - new %s/%s => %s",
3963 state2string(old_state),
3964 state2string(service->state_ipv4),
3965 state2string(service->state_ipv6),
3966 state2string(new_state));
3968 if (old_state == new_state)
3971 service->state = new_state;
3972 state_changed(service);
3974 if (new_state == CONNMAN_SERVICE_STATE_IDLE &&
3975 old_state != CONNMAN_SERVICE_STATE_DISCONNECT) {
3976 reply_pending(service, ECONNABORTED);
3978 __connman_service_disconnect(service);
3981 if (new_state == CONNMAN_SERVICE_STATE_CONFIGURATION) {
3982 if (__connman_stats_service_register(service) == 0) {
3983 __connman_stats_get(service, FALSE,
3984 &service->stats.data);
3985 __connman_stats_get(service, TRUE,
3986 &service->stats_roaming.data);
3990 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
3991 if (service->login_required == TRUE) {
3992 service->login_required = FALSE;
3993 login_changed(service);
3996 connman_timeserver_sync();
3999 if (new_state == CONNMAN_SERVICE_STATE_IDLE) {
4000 connman_bool_t reconnect;
4002 reconnect = get_reconnect_state(service);
4003 if (reconnect == TRUE)
4004 __connman_service_auto_connect();
4006 __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
4009 if (new_state == CONNMAN_SERVICE_STATE_READY) {
4010 enum connman_ipconfig_method method;
4012 set_reconnect_state(service, TRUE);
4014 __connman_service_set_favorite(service, TRUE);
4016 reply_pending(service, 0);
4018 service->userconnect = FALSE;
4020 g_get_current_time(&service->modified);
4021 service_save(service);
4023 update_nameservers(service);
4024 dns_changed(service);
4025 domain_changed(service);
4027 __connman_notifier_connect(service->type);
4029 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
4030 connman_network_get_bool(service->network,
4031 "WiFi.UseWPS") == TRUE) {
4034 pass = connman_network_get_string(service->network,
4037 __connman_service_set_passphrase(service, pass);
4039 connman_network_set_bool(service->network,
4040 "WiFi.UseWPS", FALSE);
4045 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
4046 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
4047 __connman_ipconfig_disable_ipv6(
4048 service->ipconfig_ipv6);
4050 } else if (new_state == CONNMAN_SERVICE_STATE_DISCONNECT) {
4051 struct connman_service *def_service = get_default();
4053 if (__connman_notifier_count_connected() == 0 &&
4054 def_service != NULL &&
4055 def_service->provider != NULL)
4056 __connman_provider_disconnect(def_service->provider);
4058 __connman_location_finish(service);
4062 __connman_wpad_stop(service);
4064 update_nameservers(service);
4065 dns_changed(service);
4066 domain_changed(service);
4068 __connman_notifier_disconnect(service->type);
4071 if (new_state == CONNMAN_SERVICE_STATE_FAILURE) {
4072 if (service->userconnect == TRUE &&
4073 __connman_agent_report_error(service,
4074 error2string(service->error),
4075 report_error_cb, NULL) == -EIO)
4077 service_complete(service);
4079 __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
4081 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
4083 iter = g_hash_table_lookup(service_hash, service->identifier);
4085 g_sequence_sort_changed(iter, service_compare, NULL);
4087 services_changed(FALSE);
4089 if (new_state == CONNMAN_SERVICE_STATE_ONLINE)
4095 int __connman_service_indicate_error(struct connman_service *service,
4096 enum connman_service_error error)
4098 DBG("service %p error %d", service, error);
4100 if (service == NULL)
4103 service->error = error;
4105 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
4106 __connman_service_set_passphrase(service, NULL);
4108 __connman_service_ipconfig_indicate_state(service,
4109 CONNMAN_SERVICE_STATE_FAILURE,
4110 CONNMAN_IPCONFIG_TYPE_IPV4);
4111 __connman_service_ipconfig_indicate_state(service,
4112 CONNMAN_SERVICE_STATE_FAILURE,
4113 CONNMAN_IPCONFIG_TYPE_IPV6);
4117 int __connman_service_clear_error(struct connman_service *service)
4119 DBG("service %p", service);
4121 if (service == NULL)
4124 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
4127 service->state_ipv4 = service->state_ipv6 =
4128 CONNMAN_SERVICE_STATE_UNKNOWN;
4129 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;;
4131 if (service->favorite == TRUE)
4132 set_reconnect_state(service, TRUE);
4134 __connman_service_ipconfig_indicate_state(service,
4135 CONNMAN_SERVICE_STATE_IDLE,
4136 CONNMAN_IPCONFIG_TYPE_IPV6);
4139 * Toggling the IPv6 state to IDLE could trigger the auto connect
4140 * machinery and consequently the IPv4 state.
4142 if (service->state_ipv4 != CONNMAN_SERVICE_STATE_UNKNOWN &&
4143 service->state_ipv4 != CONNMAN_SERVICE_STATE_FAILURE)
4146 return __connman_service_ipconfig_indicate_state(service,
4147 CONNMAN_SERVICE_STATE_IDLE,
4148 CONNMAN_IPCONFIG_TYPE_IPV4);
4151 int __connman_service_indicate_default(struct connman_service *service)
4153 DBG("service %p", service);
4157 __connman_location_detect(service);
4162 enum connman_service_state __connman_service_ipconfig_get_state(
4163 struct connman_service *service,
4164 enum connman_ipconfig_type type)
4166 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4167 return service->state_ipv4;
4169 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4170 return service->state_ipv6;
4172 return CONNMAN_SERVICE_STATE_UNKNOWN;
4175 static void check_proxy_setup(struct connman_service *service)
4178 * We start WPAD if we haven't got a PAC URL from DHCP and
4179 * if our proxy manual configuration is either empty or set
4180 * to AUTO with an empty URL.
4183 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
4186 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
4187 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
4188 service->pac != NULL))
4191 if (__connman_wpad_start(service) < 0) {
4192 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
4193 __connman_notifier_proxy_changed(service);
4197 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
4198 enum connman_service_state new_state,
4199 enum connman_ipconfig_type type)
4201 struct connman_ipconfig *ipconfig = NULL;
4202 enum connman_service_state old_state;
4205 if (service == NULL)
4208 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4209 old_state = service->state_ipv4;
4210 ipconfig = service->ipconfig_ipv4;
4211 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4212 old_state = service->state_ipv6;
4213 ipconfig = service->ipconfig_ipv6;
4216 if (ipconfig == NULL)
4220 if (old_state == new_state)
4223 DBG("service %p (%s) state %d (%s) type %d (%s)",
4224 service, service ? service->identifier : NULL,
4225 new_state, state2string(new_state),
4226 type, __connman_ipconfig_type2string(type));
4228 switch (new_state) {
4229 case CONNMAN_SERVICE_STATE_UNKNOWN:
4230 case CONNMAN_SERVICE_STATE_IDLE:
4231 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
4234 case CONNMAN_SERVICE_STATE_ASSOCIATION:
4236 case CONNMAN_SERVICE_STATE_CONFIGURATION:
4237 __connman_ipconfig_enable(ipconfig);
4239 case CONNMAN_SERVICE_STATE_READY:
4240 update_nameservers(service);
4242 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4243 check_proxy_setup(service);
4245 case CONNMAN_SERVICE_STATE_ONLINE:
4247 case CONNMAN_SERVICE_STATE_DISCONNECT:
4248 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
4251 case CONNMAN_SERVICE_STATE_FAILURE:
4255 /* We keep that state */
4256 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4257 service->state_ipv4 = new_state;
4258 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4259 service->state_ipv6 = new_state;
4261 ret = service_indicate_state(service);
4264 * If the ipconfig method is OFF, then we set the state to IDLE
4265 * so that it will not affect the combined state in the future.
4267 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4268 enum connman_ipconfig_method method;
4269 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
4270 if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
4271 method == CONNMAN_IPCONFIG_METHOD_UNKNOWN) {
4272 service->state_ipv4 = CONNMAN_SERVICE_STATE_IDLE;
4273 ret = service_indicate_state(service);
4276 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4277 enum connman_ipconfig_method method;
4278 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
4279 if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
4280 method == CONNMAN_IPCONFIG_METHOD_UNKNOWN) {
4281 service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
4282 ret = service_indicate_state(service);
4289 int __connman_service_request_login(struct connman_service *service)
4291 DBG("service %p", service);
4293 if (service == NULL)
4296 service->login_required = TRUE;
4297 login_changed(service);
4302 static connman_bool_t prepare_network(struct connman_service *service)
4304 enum connman_network_type type;
4305 unsigned int ssid_len;
4307 type = connman_network_get_type(service->network);
4310 case CONNMAN_NETWORK_TYPE_UNKNOWN:
4311 case CONNMAN_NETWORK_TYPE_VENDOR:
4313 case CONNMAN_NETWORK_TYPE_WIFI:
4314 if (connman_network_get_blob(service->network, "WiFi.SSID",
4318 if (service->passphrase != NULL)
4319 connman_network_set_string(service->network,
4320 "WiFi.Passphrase", service->passphrase);
4322 case CONNMAN_NETWORK_TYPE_ETHERNET:
4323 case CONNMAN_NETWORK_TYPE_WIMAX:
4324 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
4325 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
4326 case CONNMAN_NETWORK_TYPE_CELLULAR:
4333 static void prepare_8021x(struct connman_service *service)
4335 if (service->eap != NULL)
4336 connman_network_set_string(service->network, "WiFi.EAP",
4339 if (service->identity != NULL)
4340 connman_network_set_string(service->network, "WiFi.Identity",
4343 if (service->ca_cert_file != NULL)
4344 connman_network_set_string(service->network, "WiFi.CACertFile",
4345 service->ca_cert_file);
4347 if (service->client_cert_file != NULL)
4348 connman_network_set_string(service->network,
4349 "WiFi.ClientCertFile",
4350 service->client_cert_file);
4352 if (service->private_key_file != NULL)
4353 connman_network_set_string(service->network,
4354 "WiFi.PrivateKeyFile",
4355 service->private_key_file);
4357 if (service->private_key_passphrase != NULL)
4358 connman_network_set_string(service->network,
4359 "WiFi.PrivateKeyPassphrase",
4360 service->private_key_passphrase);
4362 if (service->phase2 != NULL)
4363 connman_network_set_string(service->network, "WiFi.Phase2",
4367 static int service_connect(struct connman_service *service)
4371 switch (service->type) {
4372 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4373 case CONNMAN_SERVICE_TYPE_SYSTEM:
4374 case CONNMAN_SERVICE_TYPE_GPS:
4375 case CONNMAN_SERVICE_TYPE_GADGET:
4377 case CONNMAN_SERVICE_TYPE_ETHERNET:
4378 case CONNMAN_SERVICE_TYPE_WIMAX:
4379 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4380 case CONNMAN_SERVICE_TYPE_CELLULAR:
4381 case CONNMAN_SERVICE_TYPE_VPN:
4383 case CONNMAN_SERVICE_TYPE_WIFI:
4384 switch (service->security) {
4385 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
4386 case CONNMAN_SERVICE_SECURITY_NONE:
4388 case CONNMAN_SERVICE_SECURITY_WEP:
4389 case CONNMAN_SERVICE_SECURITY_PSK:
4390 case CONNMAN_SERVICE_SECURITY_WPA:
4391 case CONNMAN_SERVICE_SECURITY_RSN:
4392 if (service->passphrase == NULL) {
4393 if (service->network == NULL)
4396 if (service->wps == FALSE ||
4397 connman_network_get_bool(
4399 "WiFi.UseWPS") == FALSE)
4403 case CONNMAN_SERVICE_SECURITY_8021X:
4404 if (service->eap == NULL)
4408 * never request credentials if using EAP-TLS
4409 * (EAP-TLS networks need to be fully provisioned)
4411 if (g_str_equal(service->eap, "tls") == TRUE)
4415 * Return -ENOKEY if either identity or passphrase is
4416 * missing. Agent provided credentials can be used as
4417 * fallback if needed.
4419 if ((service->identity == NULL &&
4420 service->agent_identity == NULL) ||
4421 (service->passphrase == NULL &&
4422 service->agent_passphrase == NULL))
4430 if (service->network != NULL) {
4431 if (prepare_network(service) == FALSE)
4434 switch (service->security) {
4435 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
4436 case CONNMAN_SERVICE_SECURITY_NONE:
4437 case CONNMAN_SERVICE_SECURITY_WEP:
4438 case CONNMAN_SERVICE_SECURITY_PSK:
4439 case CONNMAN_SERVICE_SECURITY_WPA:
4440 case CONNMAN_SERVICE_SECURITY_RSN:
4442 case CONNMAN_SERVICE_SECURITY_8021X:
4443 prepare_8021x(service);
4447 if (__connman_stats_service_register(service) == 0) {
4448 __connman_stats_get(service, FALSE,
4449 &service->stats.data);
4450 __connman_stats_get(service, TRUE,
4451 &service->stats_roaming.data);
4454 if (service->ipconfig_ipv4)
4455 __connman_ipconfig_enable(service->ipconfig_ipv4);
4456 if (service->ipconfig_ipv6)
4457 __connman_ipconfig_enable(service->ipconfig_ipv6);
4459 err = __connman_network_connect(service->network);
4460 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
4461 service->provider != NULL)
4462 err = __connman_provider_connect(service->provider);
4467 if (err != -EINPROGRESS) {
4468 __connman_ipconfig_disable(service->ipconfig_ipv4);
4469 __connman_ipconfig_disable(service->ipconfig_ipv6);
4470 __connman_stats_service_unregister(service);
4478 int __connman_service_connect(struct connman_service *service)
4482 DBG("service %p state %s", service, state2string(service->state));
4484 if (is_connected(service) == TRUE)
4487 if (is_connecting(service) == TRUE)
4490 switch (service->type) {
4491 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4492 case CONNMAN_SERVICE_TYPE_SYSTEM:
4493 case CONNMAN_SERVICE_TYPE_GPS:
4494 case CONNMAN_SERVICE_TYPE_GADGET:
4497 err = service_connect(service);
4503 if (err == -EINPROGRESS) {
4504 if (service->timeout == 0)
4505 service->timeout = g_timeout_add_seconds(
4506 CONNECT_TIMEOUT, connect_timeout, service);
4508 return -EINPROGRESS;
4511 __connman_service_ipconfig_indicate_state(service,
4512 CONNMAN_SERVICE_STATE_FAILURE,
4513 CONNMAN_IPCONFIG_TYPE_IPV4);
4514 __connman_service_ipconfig_indicate_state(service,
4515 CONNMAN_SERVICE_STATE_FAILURE,
4516 CONNMAN_IPCONFIG_TYPE_IPV6);
4518 if (service->network != NULL)
4519 __connman_network_disconnect(service->network);
4520 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
4521 service->provider != NULL)
4522 __connman_provider_disconnect(service->provider);
4524 if (service->userconnect == TRUE) {
4525 if (err == -ENOKEY) {
4526 if (__connman_agent_request_input(service,
4529 return -EINPROGRESS;
4531 reply_pending(service, err);
4537 int __connman_service_disconnect(struct connman_service *service)
4541 DBG("service %p", service);
4543 if (service->network != NULL) {
4544 err = __connman_network_disconnect(service->network);
4545 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
4546 service->provider != NULL)
4547 err = __connman_provider_disconnect(service->provider);
4551 if (err < 0 && err != -EINPROGRESS)
4554 __connman_6to4_remove(service->ipconfig_ipv4);
4556 if (service->ipconfig_ipv4)
4557 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
4560 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
4563 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
4564 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
4566 __connman_ipconfig_disable(service->ipconfig_ipv4);
4567 __connman_ipconfig_disable(service->ipconfig_ipv6);
4569 __connman_stats_service_unregister(service);
4574 int __connman_service_disconnect_all(void)
4576 GSequenceIter *iter;
4580 iter = g_sequence_get_begin_iter(service_list);
4582 while (g_sequence_iter_is_end(iter) == FALSE) {
4583 struct connman_service *service = g_sequence_get(iter);
4585 service->ignore = TRUE;
4587 set_reconnect_state(service, FALSE);
4589 __connman_service_disconnect(service);
4591 iter = g_sequence_iter_next(iter);
4599 * __connman_service_lookup:
4600 * @pattern: search pattern
4601 * @path: return object path
4603 * Look up a service path from a search pattern
4605 int __connman_service_lookup(const char *pattern, const char **path)
4607 GHashTableIter iter;
4608 gpointer key, value;
4610 g_hash_table_iter_init(&iter, service_hash);
4612 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
4613 GSequenceIter *iter = value;
4614 struct connman_service *service = g_sequence_get(iter);
4616 if (g_strcmp0(service->identifier, pattern) == 0 ||
4617 g_strcmp0(service->name, pattern) == 0) {
4618 *path = (const char *) service->path;
4627 * lookup_by_identifier:
4628 * @identifier: service identifier
4630 * Look up a service by identifier (reference count will not be increased)
4632 static struct connman_service *lookup_by_identifier(const char *identifier)
4634 GSequenceIter *iter;
4636 iter = g_hash_table_lookup(service_hash, identifier);
4638 return g_sequence_get(iter);
4643 static struct connman_network *create_hidden_wifi(struct connman_device *device,
4644 const char *ssid, const char *mode, const char *security,
4647 struct connman_network *network;
4650 unsigned int i, ssid_len;
4652 ssid_len = strlen(ssid);
4656 network = connman_network_create(group, CONNMAN_NETWORK_TYPE_WIFI);
4657 if (network == NULL)
4660 connman_network_set_blob(network, "WiFi.SSID",
4661 (unsigned char *) ssid, ssid_len);
4663 connman_network_set_string(network, "WiFi.Mode", mode);
4664 connman_network_set_string(network, "WiFi.Security", security);
4666 name = g_try_malloc0(ssid_len + 1);
4668 connman_network_unref(network);
4672 for (i = 0; i < ssid_len; i++) {
4673 if (g_ascii_isprint(ssid[i]))
4679 connman_network_set_name(network, name);
4683 index = connman_device_get_index(device);
4684 connman_network_set_index(network, index);
4686 if (connman_device_add_network(device, network) < 0) {
4687 connman_network_unref(network);
4691 connman_network_set_available(network, TRUE);
4696 int __connman_service_create_and_connect(DBusMessage *msg)
4698 struct connman_service *service;
4699 struct connman_network *network;
4700 struct connman_device *device;
4701 DBusMessageIter iter, array;
4702 const char *mode = "managed", *security = "none", *group_security;
4703 const char *type = NULL, *ssid = NULL, *passphrase = NULL;
4704 unsigned int ssid_len = 0;
4709 dbus_message_iter_init(msg, &iter);
4710 dbus_message_iter_recurse(&iter, &array);
4712 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
4713 DBusMessageIter entry, value;
4716 dbus_message_iter_recurse(&array, &entry);
4717 dbus_message_iter_get_basic(&entry, &key);
4719 dbus_message_iter_next(&entry);
4720 dbus_message_iter_recurse(&entry, &value);
4722 switch (dbus_message_iter_get_arg_type(&value)) {
4723 case DBUS_TYPE_STRING:
4724 if (g_str_equal(key, "Type") == TRUE)
4725 dbus_message_iter_get_basic(&value, &type);
4726 else if (g_str_equal(key, "WiFi.Mode") == TRUE ||
4727 g_str_equal(key, "Mode") == TRUE)
4728 dbus_message_iter_get_basic(&value, &mode);
4729 else if (g_str_equal(key, "WiFi.Security") == TRUE ||
4730 g_str_equal(key, "Security") == TRUE)
4731 dbus_message_iter_get_basic(&value, &security);
4732 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE ||
4733 g_str_equal(key, "Passphrase") == TRUE)
4734 dbus_message_iter_get_basic(&value, &passphrase);
4735 else if (g_str_equal(key, "WiFi.SSID") == TRUE ||
4736 g_str_equal(key, "SSID") == TRUE)
4737 dbus_message_iter_get_basic(&value, &ssid);
4740 dbus_message_iter_next(&array);
4746 if (g_strcmp0(type, "wifi") != 0 || g_strcmp0(mode, "managed") != 0)
4752 ssid_len = strlen(ssid);
4756 if (g_strcmp0(security, "none") != 0 &&
4757 g_strcmp0(security, "wep") != 0 &&
4758 g_strcmp0(security, "psk") != 0 &&
4759 g_strcmp0(security, "wpa") != 0 &&
4760 g_strcmp0(security, "rsn") != 0 &&
4761 g_strcmp0(security, "ieee8021x") != 0)
4764 device = __connman_device_find_device(CONNMAN_SERVICE_TYPE_WIFI);
4768 ident = connman_device_get_ident(device);
4773 if (!g_strcmp0(security, "wpa") ||
4774 !g_strcmp0(security, "rsn"))
4775 group_security = "psk";
4777 group_security = security;
4779 group = wifi_build_group_name((unsigned char *) ssid,
4780 ssid_len, mode, group_security);
4784 name = g_strdup_printf("%s_%s_%s", type, ident, group);
4786 service = lookup_by_identifier(name);
4788 if (service != NULL)
4791 network = create_hidden_wifi(device, ssid, mode, security, group);
4792 if (network != NULL)
4793 connman_network_set_group(network, group);
4795 service = lookup_by_identifier(name);
4801 if (service == NULL) {
4806 service->network_created = TRUE;
4808 if (is_connected(service) == TRUE) {
4813 if (is_connecting(service) == TRUE) {
4818 set_reconnect_state(service, FALSE);
4820 __connman_device_disconnect(device);
4822 if (passphrase != NULL) {
4823 g_free(service->passphrase);
4824 service->passphrase = g_strdup(passphrase);
4827 service->userconnect = TRUE;
4829 err = __connman_service_connect(service);
4830 if (err < 0 && err != -EINPROGRESS)
4833 service->pending = dbus_message_ref(msg);
4838 if (service != NULL && service->network_created == TRUE) {
4839 struct connman_network *network = service->network;
4841 if (network != NULL) {
4842 connman_network_set_available(network, FALSE);
4843 __connman_device_cleanup_networks(device);
4845 __connman_service_put(service);
4851 static void provision_changed(gpointer value, gpointer user_data)
4853 struct connman_service *service = value;
4854 char *path = user_data;
4856 __connman_config_provision_service_ident(service, path);
4859 void __connman_service_provision_changed(const char *ident)
4861 g_sequence_foreach(service_list, provision_changed, (void *)ident);
4864 int __connman_service_provision(DBusMessage *msg)
4866 GKeyFile *keyfile = NULL;
4867 const char *config_str = NULL;
4868 char *group = NULL, *ident = NULL;
4870 struct connman_service *service;
4874 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &config_str,
4877 if (config_str == NULL || strlen(config_str) == 0)
4880 keyfile = g_key_file_new();
4882 /* populate GKeyFile with config_str */
4883 if (g_key_file_load_from_data(keyfile, config_str,
4884 strlen(config_str), 0, NULL) == FALSE) {
4890 * read only one group of settings (only one service supported, no
4893 group = g_key_file_get_start_group(keyfile);
4895 if (group == NULL || g_str_has_prefix(group, "service_") == FALSE) {
4900 err = __connman_config_load_service(keyfile, group, TRUE);
4904 ident = group + strlen("service_");
4906 /* trigger service provisioning if service exists */
4907 service = lookup_by_identifier(ident);
4908 if (service != NULL)
4909 __connman_config_provision_service(service);
4911 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
4917 if (keyfile != NULL)
4918 g_key_file_free(keyfile);
4924 * __connman_service_get:
4925 * @identifier: service identifier
4927 * Look up a service by identifier or create a new one if not found
4929 static struct connman_service *service_get(const char *identifier)
4931 struct connman_service *service;
4932 GSequenceIter *iter;
4934 iter = g_hash_table_lookup(service_hash, identifier);
4936 service = g_sequence_get(iter);
4937 if (service != NULL)
4938 connman_service_ref(service);
4942 service = connman_service_create();
4943 if (service == NULL)
4946 DBG("service %p", service);
4948 service->identifier = g_strdup(identifier);
4950 iter = g_sequence_insert_sorted(service_list, service,
4951 service_compare, NULL);
4953 g_hash_table_insert(service_hash, service->identifier, iter);
4958 static int service_register(struct connman_service *service)
4960 GSequenceIter *iter;
4962 DBG("service %p", service);
4964 if (service->path != NULL)
4967 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
4968 service->identifier);
4970 DBG("path %s", service->path);
4972 __connman_config_provision_service(service);
4974 service_load(service);
4976 g_dbus_register_interface(connection, service->path,
4977 CONNMAN_SERVICE_INTERFACE,
4978 service_methods, service_signals,
4979 NULL, service, NULL);
4981 iter = g_hash_table_lookup(service_hash, service->identifier);
4983 g_sequence_sort_changed(iter, service_compare, NULL);
4985 services_changed(TRUE);
4990 static void service_up(struct connman_ipconfig *ipconfig)
4992 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
4994 DBG("%s up", connman_ipconfig_get_ifname(ipconfig));
4996 link_changed(service);
4998 service->stats.valid = FALSE;
4999 service->stats_roaming.valid = FALSE;
5002 static void service_down(struct connman_ipconfig *ipconfig)
5004 DBG("%s down", connman_ipconfig_get_ifname(ipconfig));
5007 static void service_lower_up(struct connman_ipconfig *ipconfig)
5009 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
5011 DBG("%s lower up", connman_ipconfig_get_ifname(ipconfig));
5013 stats_start(service);
5016 static void service_lower_down(struct connman_ipconfig *ipconfig)
5018 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
5020 DBG("%s lower down", connman_ipconfig_get_ifname(ipconfig));
5022 stats_stop(service);
5023 service_save(service);
5026 static void service_ip_bound(struct connman_ipconfig *ipconfig)
5028 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
5029 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
5030 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
5032 DBG("%s ip bound", connman_ipconfig_get_ifname(ipconfig));
5034 type = __connman_ipconfig_get_config_type(ipconfig);
5035 method = __connman_ipconfig_get_method(ipconfig);
5037 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
5040 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
5041 method == CONNMAN_IPCONFIG_METHOD_AUTO)
5042 __connman_service_ipconfig_indicate_state(service,
5043 CONNMAN_SERVICE_STATE_READY,
5044 CONNMAN_IPCONFIG_TYPE_IPV6);
5046 settings_changed(service, ipconfig);
5049 static void service_ip_release(struct connman_ipconfig *ipconfig)
5051 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
5052 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
5053 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
5055 DBG("%s ip release", connman_ipconfig_get_ifname(ipconfig));
5057 type = __connman_ipconfig_get_config_type(ipconfig);
5058 method = __connman_ipconfig_get_method(ipconfig);
5060 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
5063 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
5064 method == CONNMAN_IPCONFIG_METHOD_OFF)
5065 __connman_service_ipconfig_indicate_state(service,
5066 CONNMAN_SERVICE_STATE_DISCONNECT,
5067 CONNMAN_IPCONFIG_TYPE_IPV6);
5069 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
5070 method == CONNMAN_IPCONFIG_METHOD_OFF)
5071 __connman_service_ipconfig_indicate_state(service,
5072 CONNMAN_SERVICE_STATE_DISCONNECT,
5073 CONNMAN_IPCONFIG_TYPE_IPV4);
5075 settings_changed(service, ipconfig);
5078 static const struct connman_ipconfig_ops service_ops = {
5080 .down = service_down,
5081 .lower_up = service_lower_up,
5082 .lower_down = service_lower_down,
5083 .ip_bound = service_ip_bound,
5084 .ip_release = service_ip_release,
5087 static void setup_ip4config(struct connman_service *service, int index,
5088 enum connman_ipconfig_method method)
5093 service->ipconfig_ipv4 = connman_ipconfig_create(index,
5094 CONNMAN_IPCONFIG_TYPE_IPV4);
5095 if (service->ipconfig_ipv4 == NULL)
5098 connman_ipconfig_set_method(service->ipconfig_ipv4, method);
5100 connman_ipconfig_set_data(service->ipconfig_ipv4, service);
5102 connman_ipconfig_set_ops(service->ipconfig_ipv4, &service_ops);
5105 static void setup_ip6config(struct connman_service *service, int index)
5110 service->ipconfig_ipv6 = connman_ipconfig_create(index,
5111 CONNMAN_IPCONFIG_TYPE_IPV6);
5112 if (service->ipconfig_ipv6 == NULL)
5115 connman_ipconfig_set_data(service->ipconfig_ipv6, service);
5117 connman_ipconfig_set_ops(service->ipconfig_ipv6, &service_ops);
5120 void __connman_service_read_ip4config(struct connman_service *service)
5124 if (service->ipconfig_ipv4 == NULL)
5127 keyfile = __connman_storage_open_profile("default");
5128 if (keyfile == NULL)
5131 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
5132 service->identifier, "IPv4.");
5134 g_key_file_free(keyfile);
5137 void __connman_service_create_ip4config(struct connman_service *service,
5140 DBG("ipv4 %p", service->ipconfig_ipv4);
5142 if (service->ipconfig_ipv4 != NULL)
5145 setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_DHCP);
5146 __connman_service_read_ip4config(service);
5149 void __connman_service_read_ip6config(struct connman_service *service)
5153 if (service->ipconfig_ipv6 == NULL)
5156 keyfile = __connman_storage_open_profile("default");
5157 if (keyfile == NULL)
5160 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
5161 service->identifier, "IPv6.");
5163 g_key_file_free(keyfile);
5166 void __connman_service_create_ip6config(struct connman_service *service,
5169 DBG("ipv6 %p", service->ipconfig_ipv6);
5171 if (service->ipconfig_ipv6 != NULL)
5174 setup_ip6config(service, index);
5175 __connman_service_read_ip6config(service);
5179 * __connman_service_lookup_from_network:
5180 * @network: network structure
5182 * Look up a service by network (reference count will not be increased)
5184 struct connman_service *__connman_service_lookup_from_network(struct connman_network *network)
5186 struct connman_service *service;
5187 const char *ident, *group;
5190 DBG("network %p", network);
5192 if (network == NULL)
5195 ident = __connman_network_get_ident(network);
5199 group = connman_network_get_group(network);
5203 name = g_strdup_printf("%s_%s_%s",
5204 __connman_network_get_type(network), ident, group);
5205 service = lookup_by_identifier(name);
5211 struct connman_service *__connman_service_lookup_from_index(int index)
5213 struct connman_service *service;
5214 GSequenceIter *iter;
5216 iter = g_sequence_get_begin_iter(service_list);
5218 while (g_sequence_iter_is_end(iter) == FALSE) {
5219 service = g_sequence_get(iter);
5221 if (connman_ipconfig_get_index(service->ipconfig_ipv4)
5225 if (connman_ipconfig_get_index(service->ipconfig_ipv6)
5229 iter = g_sequence_iter_next(iter);
5235 const char *__connman_service_get_ident(struct connman_service *service)
5237 return service->identifier;
5240 const char *__connman_service_get_path(struct connman_service *service)
5242 return service->path;
5245 unsigned int __connman_service_get_order(struct connman_service *service)
5247 GSequenceIter *iter;
5249 if (service == NULL)
5252 if (service->favorite == FALSE) {
5257 iter = g_hash_table_lookup(service_hash, service->identifier);
5259 if (g_sequence_iter_get_position(iter) == 0)
5261 else if (service->type == CONNMAN_SERVICE_TYPE_VPN)
5262 service->order = 10;
5268 return service->order;
5271 static enum connman_service_type convert_network_type(struct connman_network *network)
5273 enum connman_network_type type = connman_network_get_type(network);
5276 case CONNMAN_NETWORK_TYPE_UNKNOWN:
5277 case CONNMAN_NETWORK_TYPE_VENDOR:
5279 case CONNMAN_NETWORK_TYPE_ETHERNET:
5280 return CONNMAN_SERVICE_TYPE_ETHERNET;
5281 case CONNMAN_NETWORK_TYPE_WIFI:
5282 return CONNMAN_SERVICE_TYPE_WIFI;
5283 case CONNMAN_NETWORK_TYPE_WIMAX:
5284 return CONNMAN_SERVICE_TYPE_WIMAX;
5285 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
5286 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
5287 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
5288 case CONNMAN_NETWORK_TYPE_CELLULAR:
5289 return CONNMAN_SERVICE_TYPE_CELLULAR;
5292 return CONNMAN_SERVICE_TYPE_UNKNOWN;
5295 static enum connman_service_security convert_wifi_security(const char *security)
5297 if (security == NULL)
5298 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
5299 else if (g_str_equal(security, "none") == TRUE)
5300 return CONNMAN_SERVICE_SECURITY_NONE;
5301 else if (g_str_equal(security, "wep") == TRUE)
5302 return CONNMAN_SERVICE_SECURITY_WEP;
5303 else if (g_str_equal(security, "psk") == TRUE)
5304 return CONNMAN_SERVICE_SECURITY_PSK;
5305 else if (g_str_equal(security, "ieee8021x") == TRUE)
5306 return CONNMAN_SERVICE_SECURITY_8021X;
5307 else if (g_str_equal(security, "wpa") == TRUE)
5308 return CONNMAN_SERVICE_SECURITY_WPA;
5309 else if (g_str_equal(security, "rsn") == TRUE)
5310 return CONNMAN_SERVICE_SECURITY_RSN;
5312 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
5315 static void update_from_network(struct connman_service *service,
5316 struct connman_network *network)
5318 connman_uint8_t strength = service->strength;
5319 GSequenceIter *iter;
5322 DBG("service %p network %p", service, network);
5324 if (is_connected(service) == TRUE)
5327 if (is_connecting(service) == TRUE)
5330 str = connman_network_get_string(network, "Name");
5332 g_free(service->name);
5333 service->name = g_strdup(str);
5334 service->hidden = FALSE;
5336 g_free(service->name);
5337 service->name = NULL;
5338 service->hidden = TRUE;
5341 service->strength = connman_network_get_strength(network);
5342 service->roaming = connman_network_get_bool(network, "Roaming");
5344 if (service->strength == 0) {
5346 * Filter out 0-values; it's unclear what they mean
5347 * and they cause anomalous sorting of the priority list.
5349 service->strength = strength;
5352 str = connman_network_get_string(network, "WiFi.Security");
5353 service->security = convert_wifi_security(str);
5355 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
5356 service->wps = connman_network_get_bool(network, "WiFi.WPS");
5358 if (service->strength > strength && service->network != NULL) {
5359 service->network = network;
5361 strength_changed(service);
5364 if (service->network == NULL)
5365 service->network = network;
5367 iter = g_hash_table_lookup(service_hash, service->identifier);
5369 g_sequence_sort_changed(iter, service_compare, NULL);
5373 * __connman_service_create_from_network:
5374 * @network: network structure
5376 * Look up service by network and if not found, create one
5378 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
5380 struct connman_service *service;
5381 struct connman_device *device;
5382 const char *ident, *group;
5386 DBG("network %p", network);
5388 if (network == NULL)
5391 ident = __connman_network_get_ident(network);
5395 group = connman_network_get_group(network);
5399 name = g_strdup_printf("%s_%s_%s",
5400 __connman_network_get_type(network), ident, group);
5401 service = service_get(name);
5404 if (service == NULL)
5407 if (__connman_network_get_weakness(network) == TRUE)
5410 if (service->path != NULL) {
5411 update_from_network(service, network);
5412 services_changed(TRUE);
5416 service->type = convert_network_type(network);
5418 switch (service->type) {
5419 case CONNMAN_SERVICE_TYPE_UNKNOWN:
5420 case CONNMAN_SERVICE_TYPE_SYSTEM:
5421 case CONNMAN_SERVICE_TYPE_ETHERNET:
5422 case CONNMAN_SERVICE_TYPE_WIMAX:
5423 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
5424 case CONNMAN_SERVICE_TYPE_GPS:
5425 case CONNMAN_SERVICE_TYPE_VPN:
5426 case CONNMAN_SERVICE_TYPE_GADGET:
5427 service->autoconnect = FALSE;
5429 case CONNMAN_SERVICE_TYPE_WIFI:
5430 case CONNMAN_SERVICE_TYPE_CELLULAR:
5431 service->autoconnect = TRUE;
5435 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
5436 service->state = combine_state(service->state_ipv4, service->state_ipv6);
5438 update_from_network(service, network);
5440 index = connman_network_get_index(network);
5442 if (service->ipconfig_ipv4 == NULL)
5443 setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_DHCP);
5445 if (service->ipconfig_ipv6 == NULL)
5446 setup_ip6config(service, index);
5448 service_register(service);
5450 if (service->favorite == TRUE) {
5451 device = connman_network_get_device(service->network);
5452 if (device && __connman_device_scanning(device) == FALSE)
5453 __connman_service_auto_connect();
5456 __connman_notifier_service_add(service, service->name);
5461 void __connman_service_update_from_network(struct connman_network *network)
5463 struct connman_service *service;
5464 connman_uint8_t strength;
5465 connman_bool_t roaming;
5466 GSequenceIter *iter;
5468 connman_bool_t stats_enable;
5470 DBG("network %p", network);
5472 service = __connman_service_lookup_from_network(network);
5473 if (service == NULL)
5476 if (service->network == NULL)
5479 name = connman_network_get_string(service->network, "Name");
5480 if (g_strcmp0(service->name, name) != 0) {
5481 g_free(service->name);
5482 service->name = g_strdup(name);
5483 connman_dbus_property_changed_basic(service->path,
5484 CONNMAN_SERVICE_INTERFACE, "Name",
5485 DBUS_TYPE_STRING, &service->name);
5488 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
5489 service->wps = connman_network_get_bool(network, "WiFi.WPS");
5491 strength = connman_network_get_strength(service->network);
5492 if (strength == service->strength)
5495 service->strength = strength;
5497 strength_changed(service);
5500 roaming = connman_network_get_bool(service->network, "Roaming");
5501 if (roaming == service->roaming)
5504 stats_enable = stats_enabled(service);
5505 if (stats_enable == TRUE)
5506 stats_stop(service);
5508 service->roaming = roaming;
5510 if (stats_enable == TRUE)
5511 stats_start(service);
5513 roaming_changed(service);
5515 iter = g_hash_table_lookup(service_hash, service->identifier);
5517 g_sequence_sort_changed(iter, service_compare, NULL);
5520 void __connman_service_remove_from_network(struct connman_network *network)
5522 struct connman_service *service;
5524 DBG("network %p", network);
5526 service = __connman_service_lookup_from_network(network);
5527 if (service == NULL)
5530 __connman_service_put(service);
5534 * __connman_service_create_from_provider:
5535 * @provider: provider structure
5537 * Look up service by provider and if not found, create one
5539 struct connman_service *
5540 __connman_service_create_from_provider(struct connman_provider *provider)
5542 struct connman_service *service;
5543 const char *ident, *str;
5545 int index = connman_provider_get_index(provider);
5547 DBG("provider %p", provider);
5549 ident = __connman_provider_get_ident(provider);
5553 name = g_strdup_printf("vpn_%s", ident);
5554 service = service_get(name);
5557 if (service == NULL)
5560 service->type = CONNMAN_SERVICE_TYPE_VPN;
5561 service->provider = connman_provider_ref(provider);
5562 service->autoconnect = FALSE;
5563 service->userconnect = TRUE;
5565 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
5567 str = connman_provider_get_string(provider, "Name");
5569 g_free(service->name);
5570 service->name = g_strdup(str);
5571 service->hidden = FALSE;
5573 g_free(service->name);
5574 service->name = NULL;
5575 service->hidden = TRUE;
5578 service->strength = 0;
5580 if (service->ipconfig_ipv4 == NULL)
5581 setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_MANUAL);
5583 if (service->ipconfig_ipv6 == NULL)
5584 setup_ip6config(service, index);
5586 service_register(service);
5588 __connman_notifier_service_add(service, service->name);
5593 void __connman_service_downgrade_state(struct connman_service *service)
5595 if (service == NULL)
5598 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
5599 service->state_ipv6);
5601 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
5602 __connman_service_ipconfig_indicate_state(service,
5603 CONNMAN_SERVICE_STATE_READY,
5604 CONNMAN_IPCONFIG_TYPE_IPV4);
5606 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
5607 __connman_service_ipconfig_indicate_state(service,
5608 CONNMAN_SERVICE_STATE_READY,
5609 CONNMAN_IPCONFIG_TYPE_IPV6);
5612 int __connman_service_init(void)
5616 connection = connman_dbus_get_connection();
5618 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
5621 service_list = g_sequence_new(service_free);
5626 void __connman_service_cleanup(void)
5632 list = service_list;
5633 service_list = NULL;
5634 g_sequence_free(list);
5636 g_hash_table_destroy(service_hash);
5637 service_hash = NULL;
5639 g_slist_free(counter_list);
5640 counter_list = NULL;
5642 dbus_connection_unref(connection);