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_stats stats;
103 struct connman_stats stats_roaming;
104 GHashTable *counter_table;
105 enum connman_service_proxy_method proxy;
106 enum connman_service_proxy_method proxy_config;
113 static void append_path(gpointer value, gpointer user_data)
115 struct connman_service *service = value;
116 DBusMessageIter *iter = user_data;
118 if (service->path == NULL || service->hidden == TRUE)
121 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
125 void __connman_service_list(DBusMessageIter *iter, void *user_data)
127 if (service_list == NULL)
130 g_sequence_foreach(service_list, append_path, iter);
135 struct connman_service *service;
138 static void compare_path(gpointer value, gpointer user_data)
140 struct connman_service *service = value;
141 struct find_data *data = user_data;
143 if (data->service != NULL)
146 if (g_strcmp0(service->path, data->path) == 0)
147 data->service = service;
150 static struct connman_service *find_service(const char *path)
152 struct find_data data = { .path = path, .service = NULL };
154 DBG("path %s", path);
156 g_sequence_foreach(service_list, compare_path, &data);
161 const char *__connman_service_type2string(enum connman_service_type type)
164 case CONNMAN_SERVICE_TYPE_UNKNOWN:
166 case CONNMAN_SERVICE_TYPE_SYSTEM:
168 case CONNMAN_SERVICE_TYPE_ETHERNET:
170 case CONNMAN_SERVICE_TYPE_WIFI:
172 case CONNMAN_SERVICE_TYPE_WIMAX:
174 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
176 case CONNMAN_SERVICE_TYPE_CELLULAR:
178 case CONNMAN_SERVICE_TYPE_GPS:
180 case CONNMAN_SERVICE_TYPE_VPN:
182 case CONNMAN_SERVICE_TYPE_GADGET:
189 static const char *security2string(enum connman_service_security security)
192 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
194 case CONNMAN_SERVICE_SECURITY_NONE:
196 case CONNMAN_SERVICE_SECURITY_WEP:
198 case CONNMAN_SERVICE_SECURITY_PSK:
200 case CONNMAN_SERVICE_SECURITY_8021X:
202 case CONNMAN_SERVICE_SECURITY_WPA:
204 case CONNMAN_SERVICE_SECURITY_RSN:
211 static const char *state2string(enum connman_service_state state)
214 case CONNMAN_SERVICE_STATE_UNKNOWN:
216 case CONNMAN_SERVICE_STATE_IDLE:
218 case CONNMAN_SERVICE_STATE_ASSOCIATION:
219 return "association";
220 case CONNMAN_SERVICE_STATE_CONFIGURATION:
221 return "configuration";
222 case CONNMAN_SERVICE_STATE_READY:
224 case CONNMAN_SERVICE_STATE_ONLINE:
226 case CONNMAN_SERVICE_STATE_DISCONNECT:
228 case CONNMAN_SERVICE_STATE_FAILURE:
235 static const char *error2string(enum connman_service_error error)
238 case CONNMAN_SERVICE_ERROR_UNKNOWN:
240 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
241 return "out-of-range";
242 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
243 return "pin-missing";
244 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
245 return "dhcp-failed";
246 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
247 return "connect-failed";
248 case CONNMAN_SERVICE_ERROR_LOGIN_FAILED:
249 return "login-failed";
250 case CONNMAN_SERVICE_ERROR_AUTH_FAILED:
251 return "auth-failed";
252 case CONNMAN_SERVICE_ERROR_INVALID_KEY:
253 return "invalid-key";
259 static enum connman_service_error string2error(const char *error)
261 if (g_strcmp0(error, "dhcp-failed") == 0)
262 return CONNMAN_SERVICE_ERROR_DHCP_FAILED;
263 else if (g_strcmp0(error, "pin-missing") == 0)
264 return CONNMAN_SERVICE_ERROR_PIN_MISSING;
265 else if (g_strcmp0(error, "invalid-key") == 0)
266 return CONNMAN_SERVICE_ERROR_INVALID_KEY;
268 return CONNMAN_SERVICE_ERROR_UNKNOWN;
271 static const char *proxymethod2string(enum connman_service_proxy_method method)
274 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
276 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
278 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
280 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
287 static enum connman_service_proxy_method string2proxymethod(const char *method)
289 if (g_strcmp0(method, "direct") == 0)
290 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
291 else if (g_strcmp0(method, "auto") == 0)
292 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
293 else if (g_strcmp0(method, "manual") == 0)
294 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
296 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
299 static int service_load(struct connman_service *service)
302 GError *error = NULL;
305 connman_bool_t autoconnect;
306 unsigned int ssid_len;
309 DBG("service %p", service);
311 keyfile = __connman_storage_load_service(service->identifier);
315 switch (service->type) {
316 case CONNMAN_SERVICE_TYPE_UNKNOWN:
317 case CONNMAN_SERVICE_TYPE_SYSTEM:
318 case CONNMAN_SERVICE_TYPE_ETHERNET:
319 case CONNMAN_SERVICE_TYPE_GPS:
320 case CONNMAN_SERVICE_TYPE_VPN:
321 case CONNMAN_SERVICE_TYPE_GADGET:
323 case CONNMAN_SERVICE_TYPE_WIFI:
324 if (service->name == NULL) {
327 name = g_key_file_get_string(keyfile,
328 service->identifier, "Name", NULL);
330 g_free(service->name);
331 service->name = name;
334 if (service->network != NULL)
335 connman_network_set_name(service->network,
339 if (service->network &&
340 connman_network_get_blob(service->network,
341 "WiFi.SSID", &ssid_len) == NULL) {
344 hex_ssid = g_key_file_get_string(keyfile,
348 if (hex_ssid != NULL) {
350 unsigned int i, j = 0, hex;
351 size_t hex_ssid_len = strlen(hex_ssid);
353 ssid = g_try_malloc0(hex_ssid_len / 2);
360 for (i = 0; i < hex_ssid_len; i += 2) {
361 sscanf(hex_ssid + i, "%02x", &hex);
365 connman_network_set_blob(service->network,
366 "WiFi.SSID", ssid, hex_ssid_len / 2);
373 case CONNMAN_SERVICE_TYPE_WIMAX:
374 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
375 case CONNMAN_SERVICE_TYPE_CELLULAR:
376 service->favorite = g_key_file_get_boolean(keyfile,
377 service->identifier, "Favorite", NULL);
379 autoconnect = g_key_file_get_boolean(keyfile,
380 service->identifier, "AutoConnect", &error);
382 service->autoconnect = autoconnect;
383 g_clear_error(&error);
385 str = g_key_file_get_string(keyfile,
386 service->identifier, "Failure", NULL);
388 if (service->favorite == FALSE)
389 service->state_ipv4 = service->state_ipv6 =
390 CONNMAN_SERVICE_STATE_FAILURE;
391 service->error = string2error(str);
396 str = g_key_file_get_string(keyfile,
397 service->identifier, "Modified", NULL);
399 g_time_val_from_iso8601(str, &service->modified);
403 str = g_key_file_get_string(keyfile,
404 service->identifier, "Passphrase", NULL);
406 g_free(service->passphrase);
407 service->passphrase = str;
410 if (service->ipconfig_ipv4 != NULL)
411 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
412 service->identifier, "IPv4.");
414 if (service->ipconfig_ipv6 != NULL)
415 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
416 service->identifier, "IPv6.");
418 service->nameservers_config = g_key_file_get_string_list(keyfile,
419 service->identifier, "Nameservers", &length, NULL);
420 if (service->nameservers_config != NULL && length == 0) {
421 g_strfreev(service->nameservers_config);
422 service->nameservers_config = NULL;
425 service->domains = g_key_file_get_string_list(keyfile,
426 service->identifier, "Domains", &length, NULL);
427 if (service->domains != NULL && length == 0) {
428 g_strfreev(service->domains);
429 service->domains = NULL;
432 str = g_key_file_get_string(keyfile,
433 service->identifier, "Proxy.Method", NULL);
435 service->proxy_config = string2proxymethod(str);
439 service->proxies = g_key_file_get_string_list(keyfile,
440 service->identifier, "Proxy.Servers", &length, NULL);
441 if (service->proxies != NULL && length == 0) {
442 g_strfreev(service->proxies);
443 service->proxies = NULL;
446 service->excludes = g_key_file_get_string_list(keyfile,
447 service->identifier, "Proxy.Excludes", &length, NULL);
448 if (service->excludes != NULL && length == 0) {
449 g_strfreev(service->excludes);
450 service->excludes = NULL;
453 str = g_key_file_get_string(keyfile,
454 service->identifier, "Proxy.URL", NULL);
456 g_free(service->pac);
461 g_key_file_free(keyfile);
466 static int service_save(struct connman_service *service)
470 const char *cst_str = NULL;
473 DBG("service %p", service);
475 keyfile = __connman_storage_open_service(service->identifier);
479 if (service->name != NULL)
480 g_key_file_set_string(keyfile, service->identifier,
481 "Name", service->name);
483 switch (service->type) {
484 case CONNMAN_SERVICE_TYPE_UNKNOWN:
485 case CONNMAN_SERVICE_TYPE_SYSTEM:
486 case CONNMAN_SERVICE_TYPE_ETHERNET:
487 case CONNMAN_SERVICE_TYPE_GPS:
488 case CONNMAN_SERVICE_TYPE_VPN:
489 case CONNMAN_SERVICE_TYPE_GADGET:
491 case CONNMAN_SERVICE_TYPE_WIFI:
492 if (service->network) {
493 const unsigned char *ssid;
494 unsigned int ssid_len = 0;
496 ssid = connman_network_get_blob(service->network,
497 "WiFi.SSID", &ssid_len);
499 if (ssid != NULL && ssid_len > 0 && ssid[0] != '\0') {
500 char *identifier = service->identifier;
504 str = g_string_sized_new(ssid_len * 2);
510 for (i = 0; i < ssid_len; i++)
511 g_string_append_printf(str,
514 g_key_file_set_string(keyfile, identifier,
517 g_string_free(str, TRUE);
522 case CONNMAN_SERVICE_TYPE_WIMAX:
523 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
524 case CONNMAN_SERVICE_TYPE_CELLULAR:
525 g_key_file_set_boolean(keyfile, service->identifier,
526 "Favorite", service->favorite);
528 if (service->favorite == TRUE)
529 g_key_file_set_boolean(keyfile, service->identifier,
530 "AutoConnect", service->autoconnect);
532 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_FAILURE ||
533 service->state_ipv6 == CONNMAN_SERVICE_STATE_FAILURE) {
534 const char *failure = error2string(service->error);
536 g_key_file_set_string(keyfile,
540 g_key_file_remove_key(keyfile, service->identifier,
546 str = g_time_val_to_iso8601(&service->modified);
548 g_key_file_set_string(keyfile, service->identifier,
553 if (service->passphrase != NULL && strlen(service->passphrase) > 0)
554 g_key_file_set_string(keyfile, service->identifier,
555 "Passphrase", service->passphrase);
557 g_key_file_remove_key(keyfile, service->identifier,
560 if (service->ipconfig_ipv4 != NULL)
561 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
562 service->identifier, "IPv4.");
564 if (service->ipconfig_ipv6 != NULL)
565 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
566 service->identifier, "IPv6.");
568 if (service->nameservers_config != NULL) {
569 guint len = g_strv_length(service->nameservers_config);
571 g_key_file_set_string_list(keyfile, service->identifier,
573 (const gchar **) service->nameservers_config, len);
575 g_key_file_remove_key(keyfile, service->identifier,
576 "Nameservers", NULL);
578 if (service->domains != NULL) {
579 guint len = g_strv_length(service->domains);
581 g_key_file_set_string_list(keyfile, service->identifier,
583 (const gchar **) service->domains, len);
585 g_key_file_remove_key(keyfile, service->identifier,
588 cst_str = proxymethod2string(service->proxy_config);
590 g_key_file_set_string(keyfile, service->identifier,
591 "Proxy.Method", cst_str);
593 if (service->proxies != NULL) {
594 guint len = g_strv_length(service->proxies);
596 g_key_file_set_string_list(keyfile, service->identifier,
598 (const gchar **) service->proxies, len);
600 g_key_file_remove_key(keyfile, service->identifier,
601 "Proxy.Servers", NULL);
603 if (service->excludes != NULL) {
604 guint len = g_strv_length(service->excludes);
606 g_key_file_set_string_list(keyfile, service->identifier,
608 (const gchar **) service->excludes, len);
610 g_key_file_remove_key(keyfile, service->identifier,
611 "Proxy.Excludes", NULL);
613 if (service->pac != NULL && strlen(service->pac) > 0)
614 g_key_file_set_string(keyfile, service->identifier,
615 "Proxy.URL", service->pac);
617 g_key_file_remove_key(keyfile, service->identifier,
621 __connman_storage_save_service(keyfile, service->identifier);
623 g_key_file_free(keyfile);
628 static guint changed_timeout = 0;
630 static gboolean notify_services_changed(gpointer user_data)
634 connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
635 CONNMAN_MANAGER_INTERFACE, "Services",
636 DBUS_TYPE_OBJECT_PATH, __connman_service_list,
642 static void services_changed(gboolean delayed)
646 if (changed_timeout > 0) {
647 g_source_remove(changed_timeout);
651 if (__connman_connection_update_gateway() == TRUE) {
652 notify_services_changed(NULL);
656 if (delayed == FALSE) {
657 notify_services_changed(NULL);
661 changed_timeout = g_timeout_add_seconds(1, notify_services_changed,
665 static enum connman_service_state combine_state(
666 enum connman_service_state state_a,
667 enum connman_service_state state_b)
669 enum connman_service_state result;
671 if (state_a == state_b) {
676 if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
681 if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
686 if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
691 if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
696 if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
701 if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
706 if (state_a == CONNMAN_SERVICE_STATE_READY) {
711 if (state_b == CONNMAN_SERVICE_STATE_READY) {
716 if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
721 if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
726 if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
731 if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
736 if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
741 if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
746 result = CONNMAN_SERVICE_STATE_FAILURE;
752 static connman_bool_t is_connecting_state(struct connman_service *service,
753 enum connman_service_state state)
756 case CONNMAN_SERVICE_STATE_UNKNOWN:
757 case CONNMAN_SERVICE_STATE_IDLE:
758 case CONNMAN_SERVICE_STATE_FAILURE:
759 if (service->network != NULL)
760 return connman_network_get_connecting(service->network);
761 case CONNMAN_SERVICE_STATE_DISCONNECT:
762 case CONNMAN_SERVICE_STATE_READY:
763 case CONNMAN_SERVICE_STATE_ONLINE:
765 case CONNMAN_SERVICE_STATE_ASSOCIATION:
766 case CONNMAN_SERVICE_STATE_CONFIGURATION:
773 static connman_bool_t is_connected_state(const struct connman_service *service,
774 enum connman_service_state state)
777 case CONNMAN_SERVICE_STATE_UNKNOWN:
778 case CONNMAN_SERVICE_STATE_IDLE:
779 case CONNMAN_SERVICE_STATE_ASSOCIATION:
780 case CONNMAN_SERVICE_STATE_CONFIGURATION:
781 case CONNMAN_SERVICE_STATE_DISCONNECT:
782 case CONNMAN_SERVICE_STATE_FAILURE:
784 case CONNMAN_SERVICE_STATE_READY:
785 case CONNMAN_SERVICE_STATE_ONLINE:
792 static connman_bool_t is_connecting(struct connman_service *service)
794 return is_connecting_state(service, service->state);
797 static connman_bool_t is_connected(struct connman_service *service)
799 return is_connected_state(service, service->state);
802 static void update_nameservers(struct connman_service *service)
806 if (service->ipconfig_ipv4)
807 ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv4);
808 else if (service->ipconfig_ipv6)
809 ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv6);
816 switch (combine_state(service->state_ipv4, service->state_ipv6)) {
817 case CONNMAN_SERVICE_STATE_UNKNOWN:
818 case CONNMAN_SERVICE_STATE_IDLE:
819 case CONNMAN_SERVICE_STATE_ASSOCIATION:
820 case CONNMAN_SERVICE_STATE_CONFIGURATION:
822 case CONNMAN_SERVICE_STATE_FAILURE:
823 case CONNMAN_SERVICE_STATE_DISCONNECT:
824 connman_resolver_remove_all(ifname);
826 case CONNMAN_SERVICE_STATE_READY:
827 case CONNMAN_SERVICE_STATE_ONLINE:
831 connman_resolver_remove_all(ifname);
833 if (service->nameservers_config != NULL) {
836 for (i = 0; service->nameservers_config[i] != NULL; i++) {
837 connman_resolver_append(ifname, NULL,
838 service->nameservers_config[i]);
840 } else if (service->nameservers != NULL) {
843 for (i = 0; service->nameservers[i] != NULL; i++) {
844 connman_resolver_append(ifname, NULL,
845 service->nameservers[i]);
849 if (service->domains != NULL) {
852 for (i = 0; service->domains[i]; i++)
853 connman_resolver_append(ifname, service->domains[i],
855 } else if (service->domainname != NULL)
856 connman_resolver_append(ifname, service->domainname, NULL);
858 connman_resolver_flush();
861 int __connman_service_nameserver_append(struct connman_service *service,
862 const char *nameserver)
866 DBG("service %p nameserver %s", service, nameserver);
868 if (nameserver == NULL)
871 if (service->nameservers != NULL) {
874 for (i = 0; service->nameservers[i] != NULL; i++)
875 if (g_strcmp0(service->nameservers[i], nameserver) == 0)
878 len = g_strv_length(service->nameservers);
879 service->nameservers = g_try_renew(char *, service->nameservers,
883 service->nameservers = g_try_new0(char *, len + 2);
886 if (service->nameservers == NULL)
889 service->nameservers[len] = g_strdup(nameserver);
890 service->nameservers[len + 1] = NULL;
892 update_nameservers(service);
897 int __connman_service_nameserver_remove(struct connman_service *service,
898 const char *nameserver)
903 DBG("service %p nameserver %s", service, nameserver);
905 if (nameserver == NULL)
908 if (service->nameservers == NULL)
911 len = g_strv_length(service->nameservers);
913 if (g_strcmp0(service->nameservers[0], nameserver) != 0)
916 g_strfreev(service->nameservers);
917 service->nameservers = NULL;
922 servers = g_try_new0(char *, len);
926 for (i = 0, j = 0; i < len; i++) {
927 if (g_strcmp0(service->nameservers[i], nameserver) != 0) {
928 servers[j] = g_strdup(service->nameservers[i]);
932 servers[len - 1] = NULL;
934 g_strfreev(service->nameservers);
935 service->nameservers = servers;
937 update_nameservers(service);
942 void __connman_service_nameserver_clear(struct connman_service *service)
944 g_strfreev(service->nameservers);
945 service->nameservers = NULL;
947 update_nameservers(service);
950 static void nameserver_add_routes(int index, char **nameservers,
954 struct addrinfo hints;
955 struct addrinfo *addr;
957 for (i = 0; nameservers[i] != NULL; i++) {
958 memset(&hints, 0, sizeof(struct addrinfo));
959 hints.ai_flags = AI_NUMERICHOST;
962 ret = getaddrinfo(nameservers[i], NULL, &hints, &addr);
963 if (ret == EAI_NONAME)
964 family = AF_INET; /* use the IPv4 as a default */
968 family = addr->ai_family;
970 if (family == AF_INET) {
971 if (connman_inet_compare_subnet(index,
972 nameservers[i]) != TRUE)
973 connman_inet_add_host_route(index,
975 } else if (family == AF_INET6)
976 connman_inet_add_ipv6_host_route(index,
983 static void nameserver_del_routes(int index, char **nameservers)
986 struct addrinfo hints;
987 struct addrinfo *addr;
989 for (i = 0; nameservers[i] != NULL; i++) {
990 memset(&hints, 0, sizeof(struct addrinfo));
991 hints.ai_flags = AI_NUMERICHOST;
994 ret = getaddrinfo(nameservers[i], NULL, &hints, &addr);
995 if (ret == EAI_NONAME)
996 family = AF_INET; /* use the IPv4 as a default */
1000 family = addr->ai_family;
1002 if (family == AF_INET)
1003 connman_inet_del_host_route(index, nameservers[i]);
1004 else if (family == AF_INET6)
1005 connman_inet_del_ipv6_host_route(index,
1012 void __connman_service_nameserver_add_routes(struct connman_service *service,
1017 if (service == NULL)
1020 if (service->network != NULL)
1021 index = connman_network_get_index(service->network);
1022 else if (service->provider != NULL)
1023 index = connman_provider_get_index(service->provider);
1025 if (service->nameservers_config != NULL) {
1027 * Configured nameserver takes preference over the
1028 * discoverd nameserver gathered from DHCP, VPN, etc.
1030 nameserver_add_routes(index, service->nameservers_config, gw);
1031 } else if (service->nameservers != NULL) {
1033 * We add nameservers host routes for nameservers that
1034 * are not on our subnet. For those who are, the subnet
1035 * route will be installed by the time the dns proxy code
1036 * tries to reach them. The subnet route is installed
1037 * when setting the interface IP address.
1039 nameserver_add_routes(index, service->nameservers, gw);
1043 void __connman_service_nameserver_del_routes(struct connman_service *service)
1047 if (service == NULL)
1050 if (service->network != NULL)
1051 index = connman_network_get_index(service->network);
1052 else if (service->provider != NULL)
1053 index = connman_provider_get_index(service->provider);
1055 if (service->nameservers_config != NULL)
1056 nameserver_del_routes(index, service->nameservers_config);
1057 else if (service->nameservers != NULL)
1058 nameserver_del_routes(index, service->nameservers);
1061 static struct connman_stats *stats_get(struct connman_service *service)
1063 if (service->roaming == TRUE)
1064 return &service->stats_roaming;
1066 return &service->stats;
1069 static connman_bool_t stats_enabled(struct connman_service *service)
1071 struct connman_stats *stats = stats_get(service);
1073 return stats->enabled;
1076 static void stats_start(struct connman_service *service)
1078 struct connman_stats *stats = stats_get(service);
1080 DBG("service %p", service);
1082 if (stats->timer == NULL)
1085 stats->enabled = TRUE;
1086 stats->data_last.time = stats->data.time;
1088 g_timer_start(stats->timer);
1091 static void stats_stop(struct connman_service *service)
1093 struct connman_stats *stats = stats_get(service);
1094 unsigned int seconds;
1096 DBG("service %p", service);
1098 if (stats->timer == NULL)
1101 if (stats->enabled == FALSE)
1104 g_timer_stop(stats->timer);
1106 seconds = g_timer_elapsed(stats->timer, NULL);
1107 stats->data.time = stats->data_last.time + seconds;
1109 stats->enabled = FALSE;
1112 static void reset_stats(struct connman_service *service)
1114 DBG("service %p", service);
1117 service->stats.valid = FALSE;
1119 service->stats.data.rx_packets = 0;
1120 service->stats.data.tx_packets = 0;
1121 service->stats.data.rx_bytes = 0;
1122 service->stats.data.tx_bytes = 0;
1123 service->stats.data.rx_errors = 0;
1124 service->stats.data.tx_errors = 0;
1125 service->stats.data.rx_dropped = 0;
1126 service->stats.data.tx_dropped = 0;
1127 service->stats.data.time = 0;
1128 service->stats.data_last.time = 0;
1130 g_timer_reset(service->stats.timer);
1133 service->stats_roaming.valid = FALSE;
1135 service->stats_roaming.data.rx_packets = 0;
1136 service->stats_roaming.data.tx_packets = 0;
1137 service->stats_roaming.data.rx_bytes = 0;
1138 service->stats_roaming.data.tx_bytes = 0;
1139 service->stats_roaming.data.rx_errors = 0;
1140 service->stats_roaming.data.tx_errors = 0;
1141 service->stats_roaming.data.rx_dropped = 0;
1142 service->stats_roaming.data.tx_dropped = 0;
1143 service->stats_roaming.data.time = 0;
1144 service->stats_roaming.data_last.time = 0;
1146 g_timer_reset(service->stats_roaming.timer);
1149 static struct connman_service *get_default(void)
1151 struct connman_service *service;
1152 GSequenceIter *iter;
1154 iter = g_sequence_get_begin_iter(service_list);
1156 if (g_sequence_iter_is_end(iter) == TRUE)
1159 service = g_sequence_get(iter);
1161 if (is_connected(service) == FALSE)
1167 static void default_changed(void)
1169 struct connman_service *service = get_default();
1171 __connman_notifier_default_changed(service);
1174 const char *__connman_service_default(void)
1176 struct connman_service *service;
1178 service = get_default();
1179 if (service == NULL)
1182 return __connman_service_type2string(service->type);
1185 static void state_changed(struct connman_service *service)
1189 __connman_notifier_service_state_changed(service, service->state);
1191 str = state2string(service->state);
1195 connman_dbus_property_changed_basic(service->path,
1196 CONNMAN_SERVICE_INTERFACE, "State",
1197 DBUS_TYPE_STRING, &str);
1200 static void strength_changed(struct connman_service *service)
1202 if (service->strength == 0)
1205 connman_dbus_property_changed_basic(service->path,
1206 CONNMAN_SERVICE_INTERFACE, "Strength",
1207 DBUS_TYPE_BYTE, &service->strength);
1210 static void favorite_changed(struct connman_service *service)
1212 if (service->path == NULL)
1215 connman_dbus_property_changed_basic(service->path,
1216 CONNMAN_SERVICE_INTERFACE, "Favorite",
1217 DBUS_TYPE_BOOLEAN, &service->favorite);
1220 static void immutable_changed(struct connman_service *service)
1222 if (service->path == NULL)
1225 connman_dbus_property_changed_basic(service->path,
1226 CONNMAN_SERVICE_INTERFACE, "Immutable",
1227 DBUS_TYPE_BOOLEAN, &service->immutable);
1230 static void roaming_changed(struct connman_service *service)
1232 if (service->path == NULL)
1235 connman_dbus_property_changed_basic(service->path,
1236 CONNMAN_SERVICE_INTERFACE, "Roaming",
1237 DBUS_TYPE_BOOLEAN, &service->roaming);
1240 static void autoconnect_changed(struct connman_service *service)
1242 if (service->path == NULL)
1245 connman_dbus_property_changed_basic(service->path,
1246 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
1247 DBUS_TYPE_BOOLEAN, &service->autoconnect);
1250 static void passphrase_changed(struct connman_service *service)
1252 dbus_bool_t required;
1254 switch (service->type) {
1255 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1256 case CONNMAN_SERVICE_TYPE_SYSTEM:
1257 case CONNMAN_SERVICE_TYPE_ETHERNET:
1258 case CONNMAN_SERVICE_TYPE_WIMAX:
1259 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1260 case CONNMAN_SERVICE_TYPE_CELLULAR:
1261 case CONNMAN_SERVICE_TYPE_GPS:
1262 case CONNMAN_SERVICE_TYPE_VPN:
1263 case CONNMAN_SERVICE_TYPE_GADGET:
1265 case CONNMAN_SERVICE_TYPE_WIFI:
1268 switch (service->security) {
1269 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1270 case CONNMAN_SERVICE_SECURITY_NONE:
1272 case CONNMAN_SERVICE_SECURITY_WEP:
1273 case CONNMAN_SERVICE_SECURITY_PSK:
1274 case CONNMAN_SERVICE_SECURITY_WPA:
1275 case CONNMAN_SERVICE_SECURITY_RSN:
1276 if (service->passphrase == NULL)
1279 case CONNMAN_SERVICE_SECURITY_8021X:
1285 connman_dbus_property_changed_basic(service->path,
1286 CONNMAN_SERVICE_INTERFACE, "PassphraseRequired",
1287 DBUS_TYPE_BOOLEAN, &required);
1290 static void login_changed(struct connman_service *service)
1292 dbus_bool_t required = service->login_required;
1294 if (service->path == NULL)
1297 connman_dbus_property_changed_basic(service->path,
1298 CONNMAN_SERVICE_INTERFACE, "LoginRequired",
1299 DBUS_TYPE_BOOLEAN, &required);
1302 static void append_security(DBusMessageIter *iter, void *user_data)
1304 struct connman_service *service = user_data;
1307 str = security2string(service->security);
1309 dbus_message_iter_append_basic(iter,
1310 DBUS_TYPE_STRING, &str);
1313 * Some access points incorrectly advertise WPS even when they
1314 * are configured as open or no security, so filter
1317 if (service->wps == TRUE) {
1318 switch (service->security) {
1319 case CONNMAN_SERVICE_SECURITY_PSK:
1320 case CONNMAN_SERVICE_SECURITY_WPA:
1321 case CONNMAN_SERVICE_SECURITY_RSN:
1323 dbus_message_iter_append_basic(iter,
1324 DBUS_TYPE_STRING, &str);
1326 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1327 case CONNMAN_SERVICE_SECURITY_NONE:
1328 case CONNMAN_SERVICE_SECURITY_WEP:
1329 case CONNMAN_SERVICE_SECURITY_8021X:
1335 static void append_ethernet(DBusMessageIter *iter, void *user_data)
1337 struct connman_service *service = user_data;
1339 if (service->ipconfig_ipv4 != NULL)
1340 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
1342 else if (service->ipconfig_ipv6 != NULL)
1343 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
1347 static void append_ipv4(DBusMessageIter *iter, void *user_data)
1349 struct connman_service *service = user_data;
1351 DBG("ipv4 %p state %s", service->ipconfig_ipv4,
1352 state2string(service->state_ipv4));
1354 if (is_connected_state(service, service->state_ipv4) == FALSE)
1357 if (service->ipconfig_ipv4 != NULL)
1358 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
1361 static void append_ipv6(DBusMessageIter *iter, void *user_data)
1363 struct connman_service *service = user_data;
1365 DBG("ipv6 %p state %s", service->ipconfig_ipv6,
1366 state2string(service->state_ipv6));
1368 if (is_connected_state(service, service->state_ipv6) == FALSE)
1371 if (service->ipconfig_ipv6 != NULL)
1372 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
1373 service->ipconfig_ipv4);
1376 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
1378 struct connman_service *service = user_data;
1380 if (service->ipconfig_ipv4 != NULL)
1381 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
1385 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
1387 struct connman_service *service = user_data;
1389 if (service->ipconfig_ipv6 != NULL)
1390 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
1394 static void append_nameserver(DBusMessageIter *iter, char ***nameservers)
1399 servers = *nameservers;
1401 for (i = 0; servers[i] != NULL; i++) {
1402 dbus_message_iter_append_basic(iter,
1403 DBUS_TYPE_STRING, &servers[i]);
1407 static void append_dns(DBusMessageIter *iter, void *user_data)
1409 struct connman_service *service = user_data;
1411 if (is_connected(service) == FALSE)
1414 if (service->nameservers_config != NULL) {
1415 append_nameserver(iter, &service->nameservers_config);
1417 } else if (service->nameservers != NULL) {
1418 append_nameserver(iter, &service->nameservers);
1423 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
1425 struct connman_service *service = user_data;
1428 if (service->nameservers_config == NULL)
1431 for (i = 0; service->nameservers_config[i]; i++) {
1432 dbus_message_iter_append_basic(iter,
1434 &service->nameservers_config[i]);
1438 static void append_domain(DBusMessageIter *iter, void *user_data)
1440 struct connman_service *service = user_data;
1442 if (is_connected(service) == FALSE &&
1443 is_connecting(service) == FALSE)
1446 if (service->domainname == NULL)
1449 dbus_message_iter_append_basic(iter,
1450 DBUS_TYPE_STRING, &service->domainname);
1453 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
1455 struct connman_service *service = user_data;
1458 if (service->domains == NULL)
1461 for (i = 0; service->domains[i]; i++)
1462 dbus_message_iter_append_basic(iter,
1463 DBUS_TYPE_STRING, &service->domains[i]);
1466 static void append_proxies(DBusMessageIter *iter, void *user_data)
1468 struct connman_service *service = user_data;
1471 if (service->proxies == NULL)
1474 for (i = 0; service->proxies[i]; i++)
1475 dbus_message_iter_append_basic(iter,
1476 DBUS_TYPE_STRING, &service->proxies[i]);
1479 static void append_excludes(DBusMessageIter *iter, void *user_data)
1481 struct connman_service *service = user_data;
1484 if (service->excludes == NULL)
1487 for (i = 0; service->excludes[i]; i++)
1488 dbus_message_iter_append_basic(iter,
1489 DBUS_TYPE_STRING, &service->excludes[i]);
1492 static void append_proxy(DBusMessageIter *iter, void *user_data)
1494 struct connman_service *service = user_data;
1495 enum connman_service_proxy_method proxy;
1496 const char *pac = NULL;
1497 const char *method = proxymethod2string(
1498 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
1502 if (is_connected(service) == FALSE)
1505 proxy = connman_service_get_proxy_method(service);
1508 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
1510 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
1512 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
1513 connman_dbus_dict_append_array(iter, "Servers",
1514 DBUS_TYPE_STRING, append_proxies,
1517 connman_dbus_dict_append_array(iter, "Excludes",
1518 DBUS_TYPE_STRING, append_excludes,
1521 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
1522 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
1523 if (service->ipconfig_ipv4 != NULL)
1524 pac = __connman_ipconfig_get_proxy_autoconfig(
1525 service->ipconfig_ipv4);
1526 else if (service->ipconfig_ipv6 != NULL)
1527 pac = __connman_ipconfig_get_proxy_autoconfig(
1528 service->ipconfig_ipv6);
1530 if (service->pac == NULL && pac == NULL)
1533 if (service->pac != NULL)
1536 connman_dbus_dict_append_basic(iter, "URL",
1537 DBUS_TYPE_STRING, &pac);
1541 method = proxymethod2string(proxy);
1544 connman_dbus_dict_append_basic(iter, "Method",
1545 DBUS_TYPE_STRING, &method);
1548 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
1550 struct connman_service *service = user_data;
1553 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
1556 switch (service->proxy_config) {
1557 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
1559 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
1561 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
1562 if (service->proxies != NULL)
1563 connman_dbus_dict_append_array(iter, "Servers",
1565 append_proxies, service);
1567 if (service->excludes != NULL)
1568 connman_dbus_dict_append_array(iter, "Excludes",
1570 append_excludes, service);
1572 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
1573 if (service->pac != NULL)
1574 connman_dbus_dict_append_basic(iter, "URL",
1575 DBUS_TYPE_STRING, &service->pac);
1579 method = proxymethod2string(service->proxy_config);
1581 connman_dbus_dict_append_basic(iter, "Method",
1582 DBUS_TYPE_STRING, &method);
1585 static void append_provider(DBusMessageIter *iter, void *user_data)
1587 struct connman_service *service = user_data;
1589 DBG("%p %p", service, service->provider);
1591 if (is_connected(service) == FALSE)
1594 if (service->provider != NULL)
1595 __connman_provider_append_properties(service->provider, iter);
1599 static void settings_changed(struct connman_service *service,
1600 struct connman_ipconfig *ipconfig)
1602 connman_dbus_property_changed_dict(service->path,
1603 CONNMAN_SERVICE_INTERFACE, "IPv4",
1604 append_ipv4, service);
1606 connman_dbus_property_changed_dict(service->path,
1607 CONNMAN_SERVICE_INTERFACE, "IPv6",
1608 append_ipv6, service);
1610 __connman_notifier_ipconfig_changed(service, ipconfig);
1613 static void ipv4_configuration_changed(struct connman_service *service)
1615 connman_dbus_property_changed_dict(service->path,
1616 CONNMAN_SERVICE_INTERFACE,
1617 "IPv4.Configuration",
1622 static void ipv6_configuration_changed(struct connman_service *service)
1624 connman_dbus_property_changed_dict(service->path,
1625 CONNMAN_SERVICE_INTERFACE,
1626 "IPv6.Configuration",
1631 static void dns_changed(struct connman_service *service)
1633 connman_dbus_property_changed_array(service->path,
1634 CONNMAN_SERVICE_INTERFACE, "Nameservers",
1635 DBUS_TYPE_STRING, append_dns, service);
1638 static void dns_configuration_changed(struct connman_service *service)
1640 connman_dbus_property_changed_array(service->path,
1641 CONNMAN_SERVICE_INTERFACE,
1642 "Nameservers.Configuration",
1643 DBUS_TYPE_STRING, append_dnsconfig, service);
1645 dns_changed(service);
1648 static void domain_changed(struct connman_service *service)
1650 connman_dbus_property_changed_array(service->path,
1651 CONNMAN_SERVICE_INTERFACE, "Domains",
1652 DBUS_TYPE_STRING, append_domain, service);
1655 static void domain_configuration_changed(struct connman_service *service)
1657 connman_dbus_property_changed_array(service->path,
1658 CONNMAN_SERVICE_INTERFACE,
1659 "Domains.Configuration",
1660 DBUS_TYPE_STRING, append_domainconfig, service);
1663 static void proxy_changed(struct connman_service *service)
1665 connman_dbus_property_changed_dict(service->path,
1666 CONNMAN_SERVICE_INTERFACE, "Proxy",
1667 append_proxy, service);
1670 static void proxy_configuration_changed(struct connman_service *service)
1672 connman_dbus_property_changed_dict(service->path,
1673 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
1674 append_proxyconfig, service);
1676 proxy_changed(service);
1679 static void link_changed(struct connman_service *service)
1681 connman_dbus_property_changed_dict(service->path,
1682 CONNMAN_SERVICE_INTERFACE, "Ethernet",
1683 append_ethernet, service);
1686 static void stats_append_counters(DBusMessageIter *dict,
1687 struct connman_stats_data *stats,
1688 struct connman_stats_data *counters,
1689 connman_bool_t append_all)
1691 if (counters->rx_packets != stats->rx_packets || append_all) {
1692 counters->rx_packets = stats->rx_packets;
1693 connman_dbus_dict_append_basic(dict, "RX.Packets",
1694 DBUS_TYPE_UINT32, &stats->rx_packets);
1697 if (counters->tx_packets != stats->tx_packets || append_all) {
1698 counters->tx_packets = stats->tx_packets;
1699 connman_dbus_dict_append_basic(dict, "TX.Packets",
1700 DBUS_TYPE_UINT32, &stats->tx_packets);
1703 if (counters->rx_bytes != stats->rx_bytes || append_all) {
1704 counters->rx_bytes = stats->rx_bytes;
1705 connman_dbus_dict_append_basic(dict, "RX.Bytes",
1706 DBUS_TYPE_UINT32, &stats->rx_bytes);
1709 if (counters->tx_bytes != stats->tx_bytes || append_all) {
1710 counters->tx_bytes = stats->tx_bytes;
1711 connman_dbus_dict_append_basic(dict, "TX.Bytes",
1712 DBUS_TYPE_UINT32, &stats->tx_bytes);
1715 if (counters->rx_errors != stats->rx_errors || append_all) {
1716 counters->rx_errors = stats->rx_errors;
1717 connman_dbus_dict_append_basic(dict, "RX.Errors",
1718 DBUS_TYPE_UINT32, &stats->rx_errors);
1721 if (counters->tx_errors != stats->tx_errors || append_all) {
1722 counters->tx_errors = stats->tx_errors;
1723 connman_dbus_dict_append_basic(dict, "TX.Errors",
1724 DBUS_TYPE_UINT32, &stats->tx_errors);
1727 if (counters->rx_dropped != stats->rx_dropped || append_all) {
1728 counters->rx_dropped = stats->rx_dropped;
1729 connman_dbus_dict_append_basic(dict, "RX.Dropped",
1730 DBUS_TYPE_UINT32, &stats->rx_dropped);
1733 if (counters->tx_dropped != stats->tx_dropped || append_all) {
1734 counters->tx_dropped = stats->tx_dropped;
1735 connman_dbus_dict_append_basic(dict, "TX.Dropped",
1736 DBUS_TYPE_UINT32, &stats->tx_dropped);
1739 if (counters->time != stats->time || append_all) {
1740 counters->time = stats->time;
1741 connman_dbus_dict_append_basic(dict, "Time",
1742 DBUS_TYPE_UINT32, &stats->time);
1746 static void stats_append(struct connman_service *service,
1747 const char *counter,
1748 struct connman_stats_counter *counters,
1749 connman_bool_t append_all)
1751 DBusMessageIter array, dict;
1754 DBG("service %p counter %s", service, counter);
1756 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
1760 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
1761 &service->path, DBUS_TYPE_INVALID);
1763 dbus_message_iter_init_append(msg, &array);
1766 connman_dbus_dict_open(&array, &dict);
1768 stats_append_counters(&dict, &service->stats.data,
1769 &counters->stats.data, append_all);
1771 connman_dbus_dict_close(&array, &dict);
1773 /* roaming counter */
1774 connman_dbus_dict_open(&array, &dict);
1776 stats_append_counters(&dict, &service->stats_roaming.data,
1777 &counters->stats_roaming.data, append_all);
1779 connman_dbus_dict_close(&array, &dict);
1781 __connman_counter_send_usage(counter, msg);
1784 static void stats_update(struct connman_service *service,
1785 unsigned int rx_packets, unsigned int tx_packets,
1786 unsigned int rx_bytes, unsigned int tx_bytes,
1787 unsigned int rx_errors, unsigned int tx_errors,
1788 unsigned int rx_dropped, unsigned int tx_dropped)
1790 struct connman_stats *stats = stats_get(service);
1791 struct connman_stats_data *data_last = &stats->data_last;
1792 struct connman_stats_data *data = &stats->data;
1793 unsigned int seconds;
1795 DBG("service %p", service);
1797 if (stats->valid == TRUE) {
1799 rx_packets - data_last->rx_packets;
1801 tx_packets - data_last->tx_packets;
1803 rx_bytes - data_last->rx_bytes;
1805 tx_bytes - data_last->tx_bytes;
1807 rx_errors - data_last->rx_errors;
1809 tx_errors - data_last->tx_errors;
1811 rx_dropped - data_last->rx_dropped;
1813 tx_dropped - data_last->tx_dropped;
1815 stats->valid = TRUE;
1818 data_last->rx_packets = rx_packets;
1819 data_last->tx_packets = tx_packets;
1820 data_last->rx_bytes = rx_bytes;
1821 data_last->tx_bytes = tx_bytes;
1822 data_last->rx_errors = rx_errors;
1823 data_last->tx_errors = tx_errors;
1824 data_last->rx_dropped = rx_dropped;
1825 data_last->tx_dropped = tx_dropped;
1827 seconds = g_timer_elapsed(stats->timer, NULL);
1828 stats->data.time = stats->data_last.time + seconds;
1831 static char *wifi_build_group_name(const unsigned char *ssid,
1832 unsigned int ssid_len,
1834 const char *security)
1839 /* the last 3 is for the 2 '_' and '\0' */
1840 str = g_string_sized_new((ssid_len * 2) + strlen(mode)
1841 + strlen(security) + 3);
1845 for (i = 0; i < ssid_len; i++)
1846 g_string_append_printf(str, "%02x", ssid[i]);
1848 g_string_append_printf(str, "_%s_%s", mode, security);
1850 return g_string_free(str, FALSE);
1853 void __connman_service_notify(struct connman_service *service,
1854 unsigned int rx_packets, unsigned int tx_packets,
1855 unsigned int rx_bytes, unsigned int tx_bytes,
1856 unsigned int rx_errors, unsigned int tx_errors,
1857 unsigned int rx_dropped, unsigned int tx_dropped)
1859 GHashTableIter iter;
1860 gpointer key, value;
1861 const char *counter;
1862 struct connman_stats_counter *counters;
1863 struct connman_stats_data *data;
1866 if (service == NULL)
1869 if (is_connected(service) == FALSE)
1872 stats_update(service,
1873 rx_packets, tx_packets,
1875 rx_errors, tx_errors,
1876 rx_dropped, tx_dropped);
1878 data = &stats_get(service)->data;
1879 err = __connman_stats_update(service, service->roaming, data);
1881 connman_error("Failed to store statistics for %s",
1882 service->identifier);
1884 g_hash_table_iter_init(&iter, service->counter_table);
1885 while (g_hash_table_iter_next(&iter, &key, &value)) {
1889 stats_append(service, counter, counters, counters->append_all);
1890 counters->append_all = FALSE;
1894 int __connman_service_counter_register(const char *counter)
1896 struct connman_service *service;
1897 GSequenceIter *iter;
1898 struct connman_stats_counter *counters;
1900 DBG("counter %s", counter);
1902 counter_list = g_slist_append(counter_list, (gpointer)counter);
1904 iter = g_sequence_get_begin_iter(service_list);
1906 while (g_sequence_iter_is_end(iter) == FALSE) {
1907 service = g_sequence_get(iter);
1909 counters = g_try_new0(struct connman_stats_counter, 1);
1910 if (counters == NULL)
1913 counters->append_all = TRUE;
1915 g_hash_table_replace(service->counter_table, (gpointer)counter,
1918 iter = g_sequence_iter_next(iter);
1924 void __connman_service_counter_unregister(const char *counter)
1926 struct connman_service *service;
1927 GSequenceIter *iter;
1929 DBG("counter %s", counter);
1931 iter = g_sequence_get_begin_iter(service_list);
1933 while (g_sequence_iter_is_end(iter) == FALSE) {
1934 service = g_sequence_get(iter);
1936 g_hash_table_remove(service->counter_table, counter);
1938 iter = g_sequence_iter_next(iter);
1941 counter_list = g_slist_remove(counter_list, counter);
1944 GSequence *__connman_service_get_list(struct connman_session *session,
1945 service_match_cb service_match,
1946 create_service_entry_cb create_service_entry,
1947 GDestroyNotify destroy_service_entry)
1950 GSequenceIter *iter;
1951 struct connman_service *service;
1952 struct service_entry *entry;
1954 list = g_sequence_new(destroy_service_entry);
1958 iter = g_sequence_get_begin_iter(service_list);
1960 while (g_sequence_iter_is_end(iter) == FALSE) {
1961 service = g_sequence_get(iter);
1963 if (service_match(session, service) == TRUE) {
1964 entry = create_service_entry(service, service->name,
1969 g_sequence_append(list, entry);
1972 iter = g_sequence_iter_next(iter);
1978 void __connman_service_session_inc(struct connman_service *service)
1980 DBG("service %p ref count %d", service,
1981 g_atomic_int_get(&service->session_usage_count) + 1);
1983 g_atomic_int_inc(&service->session_usage_count);
1986 connman_bool_t __connman_service_session_dec(struct connman_service *service)
1988 DBG("service %p ref count %d", service,
1989 g_atomic_int_get(&service->session_usage_count) - 1);
1991 if (g_atomic_int_dec_and_test(&service->session_usage_count) == FALSE)
1997 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
1998 struct connman_service *service)
2000 dbus_bool_t required;
2003 str = __connman_service_type2string(service->type);
2005 connman_dbus_dict_append_basic(dict, "Type",
2006 DBUS_TYPE_STRING, &str);
2008 connman_dbus_dict_append_array(dict, "Security",
2009 DBUS_TYPE_STRING, append_security, service);
2011 str = state2string(service->state);
2013 connman_dbus_dict_append_basic(dict, "State",
2014 DBUS_TYPE_STRING, &str);
2016 str = error2string(service->error);
2018 connman_dbus_dict_append_basic(dict, "Error",
2019 DBUS_TYPE_STRING, &str);
2021 if (service->strength > 0)
2022 connman_dbus_dict_append_basic(dict, "Strength",
2023 DBUS_TYPE_BYTE, &service->strength);
2025 connman_dbus_dict_append_basic(dict, "Favorite",
2026 DBUS_TYPE_BOOLEAN, &service->favorite);
2028 connman_dbus_dict_append_basic(dict, "Immutable",
2029 DBUS_TYPE_BOOLEAN, &service->immutable);
2031 if (service->favorite == TRUE)
2032 connman_dbus_dict_append_basic(dict, "AutoConnect",
2033 DBUS_TYPE_BOOLEAN, &service->autoconnect);
2035 connman_dbus_dict_append_basic(dict, "AutoConnect",
2036 DBUS_TYPE_BOOLEAN, &service->favorite);
2038 if (service->name != NULL)
2039 connman_dbus_dict_append_basic(dict, "Name",
2040 DBUS_TYPE_STRING, &service->name);
2042 connman_dbus_dict_append_basic(dict, "LoginRequired",
2043 DBUS_TYPE_BOOLEAN, &service->login_required);
2045 switch (service->type) {
2046 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2047 case CONNMAN_SERVICE_TYPE_SYSTEM:
2048 case CONNMAN_SERVICE_TYPE_GPS:
2049 case CONNMAN_SERVICE_TYPE_VPN:
2050 case CONNMAN_SERVICE_TYPE_GADGET:
2052 case CONNMAN_SERVICE_TYPE_CELLULAR:
2053 connman_dbus_dict_append_basic(dict, "Roaming",
2054 DBUS_TYPE_BOOLEAN, &service->roaming);
2057 connman_dbus_dict_append_basic(dict, "SetupRequired",
2058 DBUS_TYPE_BOOLEAN, &required);
2059 connman_dbus_dict_append_dict(dict, "Ethernet",
2060 append_ethernet, service);
2062 case CONNMAN_SERVICE_TYPE_WIFI:
2063 if (service->passphrase != NULL && limited == FALSE)
2064 connman_dbus_dict_append_basic(dict, "Passphrase",
2065 DBUS_TYPE_STRING, &service->passphrase);
2069 switch (service->security) {
2070 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
2071 case CONNMAN_SERVICE_SECURITY_NONE:
2073 case CONNMAN_SERVICE_SECURITY_WEP:
2074 case CONNMAN_SERVICE_SECURITY_PSK:
2075 case CONNMAN_SERVICE_SECURITY_WPA:
2076 case CONNMAN_SERVICE_SECURITY_RSN:
2077 if (service->passphrase == NULL)
2080 case CONNMAN_SERVICE_SECURITY_8021X:
2084 connman_dbus_dict_append_basic(dict, "PassphraseRequired",
2085 DBUS_TYPE_BOOLEAN, &required);
2088 case CONNMAN_SERVICE_TYPE_ETHERNET:
2089 case CONNMAN_SERVICE_TYPE_WIMAX:
2090 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2091 connman_dbus_dict_append_dict(dict, "Ethernet",
2092 append_ethernet, service);
2096 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
2098 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
2099 append_ipv4config, service);
2101 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
2103 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
2104 append_ipv6config, service);
2106 connman_dbus_dict_append_array(dict, "Nameservers",
2107 DBUS_TYPE_STRING, append_dns, service);
2109 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
2110 DBUS_TYPE_STRING, append_dnsconfig, service);
2112 connman_dbus_dict_append_array(dict, "Domains",
2113 DBUS_TYPE_STRING, append_domain, service);
2115 connman_dbus_dict_append_array(dict, "Domains.Configuration",
2116 DBUS_TYPE_STRING, append_domainconfig, service);
2118 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
2120 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
2121 append_proxyconfig, service);
2123 connman_dbus_dict_append_dict(dict, "Provider",
2124 append_provider, service);
2127 static void append_struct(gpointer value, gpointer user_data)
2129 struct connman_service *service = value;
2130 DBusMessageIter *iter = user_data;
2131 DBusMessageIter entry, dict;
2133 if (service->path == NULL || service->hidden == TRUE)
2136 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
2138 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
2141 connman_dbus_dict_open(&entry, &dict);
2142 append_properties(&dict, TRUE, service);
2143 connman_dbus_dict_close(&entry, &dict);
2145 dbus_message_iter_close_container(iter, &entry);
2148 void __connman_service_list_struct(DBusMessageIter *iter)
2150 g_sequence_foreach(service_list, append_struct, iter);
2153 int __connman_service_get_index(struct connman_service *service)
2155 if (service == NULL)
2158 if (service->network != NULL)
2159 return connman_network_get_index(service->network);
2160 else if (service->provider != NULL)
2161 return connman_provider_get_index(service->provider);
2166 void __connman_service_set_domainname(struct connman_service *service,
2167 const char *domainname)
2169 if (service == NULL)
2172 g_free(service->domainname);
2173 service->domainname = g_strdup(domainname);
2175 domain_changed(service);
2178 const char *connman_service_get_domainname(struct connman_service *service)
2180 if (service == NULL)
2183 if (service->domains != NULL)
2184 return service->domains[0];
2186 return service->domainname;
2189 char **connman_service_get_nameservers(struct connman_service *service)
2191 if (service == NULL)
2194 if (service->nameservers_config != NULL)
2195 return service->nameservers_config;
2196 else if (service->nameservers != NULL)
2197 return service->nameservers;
2202 void connman_service_set_proxy_method(struct connman_service *service,
2203 enum connman_service_proxy_method method)
2205 if (service == NULL)
2208 service->proxy = method;
2210 proxy_changed(service);
2212 if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
2213 __connman_notifier_proxy_changed(service);
2216 enum connman_service_proxy_method connman_service_get_proxy_method(
2217 struct connman_service *service)
2219 if (service == NULL)
2220 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
2222 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
2223 if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
2224 service->pac == NULL)
2225 return service->proxy;
2227 return service->proxy_config;
2230 return service->proxy;
2233 char **connman_service_get_proxy_servers(struct connman_service *service)
2235 return g_strdupv(service->proxies);
2238 char **connman_service_get_proxy_excludes(struct connman_service *service)
2240 return g_strdupv(service->excludes);
2243 const char *connman_service_get_proxy_url(struct connman_service *service)
2245 if (service == NULL)
2248 return service->pac;
2251 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
2254 if (service == NULL)
2257 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
2259 if (service->ipconfig_ipv4) {
2260 if (__connman_ipconfig_set_proxy_autoconfig(
2261 service->ipconfig_ipv4, url) < 0)
2263 } else if (service->ipconfig_ipv6) {
2264 if (__connman_ipconfig_set_proxy_autoconfig(
2265 service->ipconfig_ipv6, url) < 0)
2270 proxy_changed(service);
2272 __connman_notifier_proxy_changed(service);
2275 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
2277 if (service == NULL)
2280 if (service->ipconfig_ipv4)
2281 return __connman_ipconfig_get_proxy_autoconfig(
2282 service->ipconfig_ipv4);
2283 else if (service->ipconfig_ipv6)
2284 return __connman_ipconfig_get_proxy_autoconfig(
2285 service->ipconfig_ipv6);
2289 static void update_timeservers(struct connman_service *service)
2293 if (service->timeservers == NULL)
2296 switch (service->state) {
2297 case CONNMAN_SERVICE_STATE_UNKNOWN:
2298 case CONNMAN_SERVICE_STATE_IDLE:
2299 case CONNMAN_SERVICE_STATE_ASSOCIATION:
2300 case CONNMAN_SERVICE_STATE_CONFIGURATION:
2302 case CONNMAN_SERVICE_STATE_FAILURE:
2303 case CONNMAN_SERVICE_STATE_DISCONNECT:
2304 for (i = 0; service->timeservers[i] != NULL; i++)
2305 connman_timeserver_remove(service->timeservers[i]);
2307 case CONNMAN_SERVICE_STATE_READY:
2308 case CONNMAN_SERVICE_STATE_ONLINE:
2312 for (i = 0; service->timeservers[i] != NULL; i++)
2313 connman_timeserver_append(service->timeservers[i]);
2316 int __connman_service_timeserver_append(struct connman_service *service,
2317 const char *timeserver)
2321 DBG("service %p timeserver %s", service, timeserver);
2323 if (timeserver == NULL)
2326 if (service->timeservers != NULL) {
2329 for (i = 0; service->timeservers[i] != NULL; i++)
2330 if (g_strcmp0(service->timeservers[i], timeserver) == 0)
2333 len = g_strv_length(service->timeservers);
2334 service->timeservers = g_try_renew(char *, service->timeservers,
2338 service->timeservers = g_try_new0(char *, len + 2);
2341 if (service->timeservers == NULL)
2344 service->timeservers[len] = g_strdup(timeserver);
2345 service->timeservers[len + 1] = NULL;
2347 update_timeservers(service);
2352 int __connman_service_timeserver_remove(struct connman_service *service,
2353 const char *timeserver)
2358 DBG("service %p timeserver %s", service, timeserver);
2360 if (timeserver == NULL)
2363 if (service->timeservers == NULL)
2366 len = g_strv_length(service->timeservers);
2368 if (g_strcmp0(service->timeservers[0], timeserver) != 0)
2371 g_strfreev(service->timeservers);
2372 service->timeservers = NULL;
2377 servers = g_try_new0(char *, len - 1);
2378 if (servers == NULL)
2381 for (i = 0, j = 0; i < len; i++) {
2382 if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
2383 servers[j] = g_strdup(service->timeservers[i]);
2387 servers[len - 2] = NULL;
2389 g_strfreev(service->timeservers);
2390 service->timeservers = servers;
2392 update_timeservers(service);
2397 void __connman_service_set_pac(struct connman_service *service,
2400 g_free(service->pac);
2401 service->pac = g_strdup(pac);
2403 proxy_changed(service);
2406 void __connman_service_set_identity(struct connman_service *service,
2407 const char *identity)
2409 if (service->immutable)
2412 g_free(service->identity);
2413 service->identity = g_strdup(identity);
2415 if (service->network != NULL)
2416 connman_network_set_string(service->network,
2421 void __connman_service_set_agent_identity(struct connman_service *service,
2422 const char *agent_identity)
2424 g_free(service->agent_identity);
2425 service->agent_identity = g_strdup(agent_identity);
2427 if (service->network != NULL)
2428 connman_network_set_string(service->network,
2429 "WiFi.AgentIdentity",
2430 service->agent_identity);
2433 void __connman_service_set_passphrase(struct connman_service *service,
2434 const char* passphrase)
2436 if (service->immutable == TRUE)
2439 g_free(service->passphrase);
2440 service->passphrase = g_strdup(passphrase);
2442 passphrase_changed(service);
2444 if (service->network != NULL)
2445 connman_network_set_string(service->network,
2447 service->passphrase);
2449 service_save(service);
2452 void __connman_service_set_agent_passphrase(struct connman_service *service,
2453 const char *agent_passphrase)
2455 g_free(service->agent_passphrase);
2456 service->agent_passphrase = g_strdup(agent_passphrase);
2458 if (service->network != NULL)
2459 connman_network_set_string(service->network,
2460 "WiFi.AgentPassphrase",
2461 service->agent_passphrase);
2464 static DBusMessage *get_properties(DBusConnection *conn,
2465 DBusMessage *msg, void *user_data)
2467 struct connman_service *service = user_data;
2469 DBusMessageIter array, dict;
2471 DBG("service %p", service);
2473 reply = dbus_message_new_method_return(msg);
2477 dbus_message_iter_init_append(reply, &array);
2479 connman_dbus_dict_open(&array, &dict);
2480 append_properties(&dict, FALSE, service);
2481 connman_dbus_dict_close(&array, &dict);
2486 static int update_proxy_configuration(struct connman_service *service,
2487 DBusMessageIter *array)
2489 DBusMessageIter dict;
2490 enum connman_service_proxy_method method;
2491 GString *servers_str = NULL;
2492 GString *excludes_str = NULL;
2493 const char *url = NULL;
2495 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
2497 dbus_message_iter_recurse(array, &dict);
2499 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
2500 DBusMessageIter entry, variant;
2504 dbus_message_iter_recurse(&dict, &entry);
2506 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
2509 dbus_message_iter_get_basic(&entry, &key);
2510 dbus_message_iter_next(&entry);
2512 if (dbus_message_iter_get_arg_type(&entry) !=
2516 dbus_message_iter_recurse(&entry, &variant);
2517 type = dbus_message_iter_get_arg_type(&variant);
2519 if (g_str_equal(key, "Method") == TRUE) {
2522 if (type != DBUS_TYPE_STRING)
2525 dbus_message_iter_get_basic(&variant, &val);
2526 method = string2proxymethod(val);
2527 } else if (g_str_equal(key, "URL") == TRUE) {
2528 if (type != DBUS_TYPE_STRING)
2531 dbus_message_iter_get_basic(&variant, &url);
2532 } else if (g_str_equal(key, "Servers") == TRUE) {
2533 DBusMessageIter str_array;
2535 if (type != DBUS_TYPE_ARRAY)
2538 servers_str = g_string_new(NULL);
2539 if (servers_str == NULL)
2542 dbus_message_iter_recurse(&variant, &str_array);
2544 while (dbus_message_iter_get_arg_type(&str_array) ==
2548 dbus_message_iter_get_basic(&str_array, &val);
2550 if (servers_str->len > 0)
2551 g_string_append_printf(servers_str,
2554 g_string_append(servers_str, val);
2556 dbus_message_iter_next(&str_array);
2558 } else if (g_str_equal(key, "Excludes") == TRUE) {
2559 DBusMessageIter str_array;
2561 if (type != DBUS_TYPE_ARRAY)
2564 excludes_str = g_string_new(NULL);
2565 if (excludes_str == NULL)
2568 dbus_message_iter_recurse(&variant, &str_array);
2570 while (dbus_message_iter_get_arg_type(&str_array) ==
2574 dbus_message_iter_get_basic(&str_array, &val);
2576 if (excludes_str->len > 0)
2577 g_string_append_printf(excludes_str,
2580 g_string_append(excludes_str, val);
2582 dbus_message_iter_next(&str_array);
2586 dbus_message_iter_next(&dict);
2590 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
2592 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
2593 if (servers_str == NULL && service->proxies == NULL)
2596 if (servers_str != NULL) {
2597 g_strfreev(service->proxies);
2599 if (servers_str->len > 0)
2600 service->proxies = g_strsplit_set(
2601 servers_str->str, " ", 0);
2603 service->proxies = NULL;
2606 if (excludes_str != NULL) {
2607 g_strfreev(service->excludes);
2609 if (excludes_str->len > 0)
2610 service->excludes = g_strsplit_set(
2611 excludes_str->str, " ", 0);
2613 service->excludes = NULL;
2616 if (service->proxies == NULL)
2617 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
2620 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
2621 g_free(service->pac);
2623 if (url != NULL && strlen(url) > 0)
2624 service->pac = g_strdup(url);
2626 service->pac = NULL;
2628 /* if we are connected:
2629 - if service->pac == NULL
2630 - if __connman_ipconfig_get_proxy_autoconfig(
2631 service->ipconfig) == NULL
2632 --> We should start WPAD */
2635 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
2639 if (servers_str != NULL)
2640 g_string_free(servers_str, TRUE);
2642 if (excludes_str != NULL)
2643 g_string_free(excludes_str, TRUE);
2645 service->proxy_config = method;
2650 if (servers_str != NULL)
2651 g_string_free(servers_str, TRUE);
2653 if (excludes_str != NULL)
2654 g_string_free(excludes_str, TRUE);
2659 static int set_ipconfig(struct connman_service *service,
2660 struct connman_ipconfig *ipconfig,
2661 DBusMessageIter *array,
2662 enum connman_service_state state,
2663 enum connman_service_state *new_state)
2665 enum connman_ipconfig_method old_method;
2666 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
2667 enum connman_ipconfig_type type;
2670 if (ipconfig == NULL)
2673 old_method = __connman_ipconfig_get_method(ipconfig);
2675 if (is_connecting_state(service, state) ||
2676 is_connected_state(service, state))
2677 __connman_network_clear_ipconfig(service->network, ipconfig);
2679 err = __connman_ipconfig_set_config(ipconfig, array);
2680 method = __connman_ipconfig_get_method(ipconfig);
2681 type = __connman_ipconfig_get_config_type(ipconfig);
2683 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
2684 if (err == 0 && old_method == CONNMAN_IPCONFIG_METHOD_OFF &&
2685 method == CONNMAN_IPCONFIG_METHOD_DHCP) {
2686 *new_state = service->state_ipv4 =
2687 CONNMAN_SERVICE_STATE_CONFIGURATION;
2688 __connman_ipconfig_enable(ipconfig);
2691 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
2692 if (err == 0 && old_method == CONNMAN_IPCONFIG_METHOD_OFF &&
2693 method == CONNMAN_IPCONFIG_METHOD_AUTO) {
2694 *new_state = service->state_ipv6;
2695 __connman_ipconfig_enable(ipconfig);
2699 DBG("err %d ipconfig %p type %d method %d state %s", err, ipconfig,
2700 type, method, state2string(*new_state));
2705 static DBusMessage *set_property(DBusConnection *conn,
2706 DBusMessage *msg, void *user_data)
2708 struct connman_service *service = user_data;
2709 DBusMessageIter iter, value;
2713 DBG("service %p", service);
2715 if (dbus_message_iter_init(msg, &iter) == FALSE)
2716 return __connman_error_invalid_arguments(msg);
2718 dbus_message_iter_get_basic(&iter, &name);
2719 dbus_message_iter_next(&iter);
2720 dbus_message_iter_recurse(&iter, &value);
2722 type = dbus_message_iter_get_arg_type(&value);
2724 if (g_str_equal(name, "AutoConnect") == TRUE) {
2725 connman_bool_t autoconnect;
2727 if (type != DBUS_TYPE_BOOLEAN)
2728 return __connman_error_invalid_arguments(msg);
2730 if (service->favorite == FALSE)
2731 return __connman_error_invalid_service(msg);
2733 dbus_message_iter_get_basic(&value, &autoconnect);
2735 if (service->autoconnect == autoconnect)
2736 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2738 service->autoconnect = autoconnect;
2740 autoconnect_changed(service);
2742 service_save(service);
2743 } else if (g_str_equal(name, "Passphrase") == TRUE) {
2744 const char *passphrase;
2746 if (type != DBUS_TYPE_STRING)
2747 return __connman_error_invalid_arguments(msg);
2749 if (service->immutable == TRUE)
2750 return __connman_error_not_supported(msg);
2752 dbus_message_iter_get_basic(&value, &passphrase);
2754 __connman_service_set_passphrase(service, passphrase);
2755 } else if (g_str_equal(name, "Nameservers.Configuration") == TRUE) {
2756 DBusMessageIter entry;
2761 if (type != DBUS_TYPE_ARRAY)
2762 return __connman_error_invalid_arguments(msg);
2764 str = g_string_new(NULL);
2766 return __connman_error_invalid_arguments(msg);
2768 index = connman_network_get_index(service->network);
2769 gw = __connman_ipconfig_get_gateway_from_index(index);
2771 if (gw && strlen(gw))
2772 __connman_service_nameserver_del_routes(service);
2774 dbus_message_iter_recurse(&value, &entry);
2776 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
2778 dbus_message_iter_get_basic(&entry, &val);
2779 dbus_message_iter_next(&entry);
2781 g_string_append_printf(str, " %s", val);
2783 g_string_append(str, val);
2786 g_strfreev(service->nameservers_config);
2789 service->nameservers_config =
2790 g_strsplit_set(str->str, " ", 0);
2792 service->nameservers_config = NULL;
2795 g_string_free(str, TRUE);
2797 if (gw && strlen(gw))
2798 __connman_service_nameserver_add_routes(service, gw);
2800 update_nameservers(service);
2801 dns_configuration_changed(service);
2803 service_save(service);
2804 } else if (g_str_equal(name, "Domains.Configuration") == TRUE) {
2805 DBusMessageIter entry;
2808 if (type != DBUS_TYPE_ARRAY)
2809 return __connman_error_invalid_arguments(msg);
2811 str = g_string_new(NULL);
2813 return __connman_error_invalid_arguments(msg);
2815 dbus_message_iter_recurse(&value, &entry);
2817 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
2819 dbus_message_iter_get_basic(&entry, &val);
2820 dbus_message_iter_next(&entry);
2822 g_string_append_printf(str, " %s", val);
2824 g_string_append(str, val);
2827 g_strfreev(service->domains);
2830 service->domains = g_strsplit_set(str->str, " ", 0);
2832 service->domains = NULL;
2834 g_string_free(str, TRUE);
2836 update_nameservers(service);
2837 domain_configuration_changed(service);
2839 service_save(service);
2840 } else if (g_str_equal(name, "Proxy.Configuration") == TRUE) {
2843 if (type != DBUS_TYPE_ARRAY)
2844 return __connman_error_invalid_arguments(msg);
2846 err = update_proxy_configuration(service, &value);
2849 return __connman_error_failed(msg, -err);
2851 proxy_configuration_changed(service);
2853 __connman_notifier_proxy_changed(service);
2855 service_save(service);
2856 } else if (g_str_equal(name, "IPv4.Configuration") == TRUE ||
2857 g_str_equal(name, "IPv6.Configuration")) {
2859 struct connman_ipconfig *ipv4 = NULL, *ipv6 = NULL;
2860 enum connman_service_state state =
2861 CONNMAN_SERVICE_STATE_UNKNOWN;
2866 if (service->ipconfig_ipv4 == NULL &&
2867 service->ipconfig_ipv6 == NULL)
2868 return __connman_error_invalid_property(msg);
2870 if (g_str_equal(name, "IPv4.Configuration") == TRUE) {
2871 ipv4 = service->ipconfig_ipv4;
2872 err = set_ipconfig(service, ipv4, &value,
2873 service->state_ipv4, &state);
2875 } else if (g_str_equal(name, "IPv6.Configuration") == TRUE) {
2876 ipv6 = service->ipconfig_ipv6;
2877 err = set_ipconfig(service, ipv6, &value,
2878 service->state_ipv6, &state);
2882 if (is_connected_state(service, state) ||
2883 is_connecting_state(service, state))
2884 __connman_network_set_ipconfig(service->network,
2886 return __connman_error_failed(msg, -err);
2890 ipv4_configuration_changed(service);
2892 ipv6_configuration_changed(service);
2894 if (is_connecting(service) || is_connected(service))
2895 __connman_network_set_ipconfig(service->network,
2898 service_save(service);
2900 return __connman_error_invalid_property(msg);
2902 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2905 static void set_idle(struct connman_service *service)
2907 service->state = service->state_ipv4 = service->state_ipv6 =
2908 CONNMAN_SERVICE_STATE_IDLE;
2909 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
2910 state_changed(service);
2913 static DBusMessage *clear_property(DBusConnection *conn,
2914 DBusMessage *msg, void *user_data)
2916 struct connman_service *service = user_data;
2919 DBG("service %p", service);
2921 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
2924 if (g_str_equal(name, "Error") == TRUE) {
2927 g_get_current_time(&service->modified);
2928 service_save(service);
2929 } else if (g_str_equal(name, "Passphrase") == TRUE) {
2930 if (service->immutable == TRUE)
2931 return __connman_error_not_supported(msg);
2933 g_free(service->passphrase);
2934 service->passphrase = NULL;
2936 passphrase_changed(service);
2938 service_save(service);
2940 return __connman_error_invalid_property(msg);
2942 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2945 static connman_bool_t is_ignore(struct connman_service *service)
2947 if (service->autoconnect == FALSE)
2950 if (service->roaming == TRUE)
2953 if (service->ignore == TRUE)
2956 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
2962 void __connman_service_auto_connect(void)
2964 struct connman_service *service = NULL;
2965 GSequenceIter *iter;
2969 if (__connman_session_mode() == TRUE) {
2970 DBG("Session mode enabled: auto connect disabled");
2974 iter = g_sequence_get_begin_iter(service_list);
2976 while (g_sequence_iter_is_end(iter) == FALSE) {
2977 service = g_sequence_get(iter);
2979 if (service->pending != NULL)
2982 if (is_connecting(service) == TRUE)
2985 if (service->favorite == FALSE)
2988 if (is_connected(service) == TRUE)
2991 if (is_ignore(service) == FALSE && service->state ==
2992 CONNMAN_SERVICE_STATE_IDLE)
2997 iter = g_sequence_iter_next(iter);
3000 if (service != NULL) {
3001 service->userconnect = FALSE;
3002 __connman_service_connect(service);
3006 static void remove_timeout(struct connman_service *service)
3008 if (service->timeout > 0) {
3009 g_source_remove(service->timeout);
3010 service->timeout = 0;
3014 static void reply_pending(struct connman_service *service, int error)
3016 remove_timeout(service);
3018 if (service->pending != NULL) {
3022 reply = __connman_error_failed(service->pending,
3025 g_dbus_send_message(connection, reply);
3029 sender = dbus_message_get_interface(service->pending);
3031 DBG("sender %s", sender);
3033 if (g_strcmp0(sender, CONNMAN_MANAGER_INTERFACE) == 0)
3034 g_dbus_send_reply(connection, service->pending,
3035 DBUS_TYPE_OBJECT_PATH, &service->path,
3038 g_dbus_send_reply(connection, service->pending,
3042 dbus_message_unref(service->pending);
3043 service->pending = NULL;
3047 static gboolean connect_timeout(gpointer user_data)
3049 struct connman_service *service = user_data;
3050 connman_bool_t autoconnect = FALSE;
3052 DBG("service %p", service);
3054 service->timeout = 0;
3056 if (service->network != NULL)
3057 __connman_network_disconnect(service->network);
3059 __connman_ipconfig_disable(service->ipconfig_ipv4);
3060 __connman_ipconfig_disable(service->ipconfig_ipv6);
3062 __connman_stats_service_unregister(service);
3064 if (service->pending != NULL) {
3067 reply = __connman_error_operation_timeout(service->pending);
3069 g_dbus_send_message(connection, reply);
3071 dbus_message_unref(service->pending);
3072 service->pending = NULL;
3076 __connman_service_ipconfig_indicate_state(service,
3077 CONNMAN_SERVICE_STATE_FAILURE,
3078 CONNMAN_IPCONFIG_TYPE_IPV4);
3079 __connman_service_ipconfig_indicate_state(service,
3080 CONNMAN_SERVICE_STATE_FAILURE,
3081 CONNMAN_IPCONFIG_TYPE_IPV6);
3083 if (autoconnect == TRUE && service->userconnect == FALSE)
3084 __connman_service_auto_connect();
3089 static void set_reconnect_state(struct connman_service *service,
3090 connman_bool_t reconnect)
3092 struct connman_device *device;
3094 if (service->network == NULL)
3097 device = connman_network_get_device(service->network);
3101 __connman_device_set_reconnect(device, reconnect);
3104 static connman_bool_t get_reconnect_state(struct connman_service *service)
3106 struct connman_device *device;
3108 if (service->network == NULL)
3111 device = connman_network_get_device(service->network);
3115 return __connman_device_get_reconnect(device);
3118 static DBusMessage *connect_service(DBusConnection *conn,
3119 DBusMessage *msg, void *user_data)
3121 struct connman_service *service = user_data;
3122 GSequenceIter *iter;
3125 DBG("service %p", service);
3127 if (service->pending != NULL)
3128 return __connman_error_in_progress(msg);
3130 iter = g_sequence_get_begin_iter(service_list);
3132 while (g_sequence_iter_is_end(iter) == FALSE) {
3133 struct connman_service *temp = g_sequence_get(iter);
3135 if (service->type == temp->type && is_connecting(temp) == TRUE)
3136 return __connman_error_in_progress(msg);
3138 iter = g_sequence_iter_next(iter);
3141 service->ignore = FALSE;
3143 service->userconnect = TRUE;
3145 service->pending = dbus_message_ref(msg);
3147 set_reconnect_state(service, FALSE);
3149 err = __connman_service_connect(service);
3151 if (service->pending == NULL)
3154 if (err != -EINPROGRESS) {
3155 dbus_message_unref(service->pending);
3156 service->pending = NULL;
3158 return __connman_error_failed(msg, -err);
3164 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3167 static DBusMessage *disconnect_service(DBusConnection *conn,
3168 DBusMessage *msg, void *user_data)
3170 struct connman_service *service = user_data;
3173 DBG("service %p", service);
3175 reply_pending(service, ECONNABORTED);
3177 service->ignore = TRUE;
3179 set_reconnect_state(service, FALSE);
3181 err = __connman_service_disconnect(service);
3183 if (err != -EINPROGRESS)
3184 return __connman_error_failed(msg, -err);
3189 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3192 static DBusMessage *remove_service(DBusConnection *conn,
3193 DBusMessage *msg, void *user_data)
3195 struct connman_service *service = user_data;
3197 DBG("service %p", service);
3199 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
3200 return __connman_error_not_supported(msg);
3202 if (service->immutable == TRUE)
3203 return __connman_error_not_supported(msg);
3205 if (service->favorite == FALSE && service->state !=
3206 CONNMAN_SERVICE_STATE_FAILURE)
3207 return __connman_error_not_supported(msg);
3209 if (service->network != NULL) {
3210 set_reconnect_state(service, FALSE);
3212 __connman_network_disconnect(service->network);
3215 g_free(service->passphrase);
3216 service->passphrase = NULL;
3218 passphrase_changed(service);
3222 __connman_service_set_favorite(service, FALSE);
3223 service_save(service);
3225 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3228 static gboolean check_suitable_state(enum connman_service_state a,
3229 enum connman_service_state b)
3232 * Special check so that "ready" service can be moved before
3235 if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
3236 b == CONNMAN_SERVICE_STATE_READY) ||
3237 (b == CONNMAN_SERVICE_STATE_ONLINE &&
3238 a == CONNMAN_SERVICE_STATE_READY))
3244 static DBusMessage *move_service(DBusConnection *conn,
3245 DBusMessage *msg, void *user_data,
3248 struct connman_service *service = user_data;
3249 struct connman_service *target;
3251 GSequenceIter *src, *dst;
3252 enum connman_ipconfig_method target4, target6;
3253 enum connman_ipconfig_method service4, service6;
3255 DBG("service %p", service);
3257 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
3260 if (service->favorite == FALSE)
3261 return __connman_error_not_supported(msg);
3263 target = find_service(path);
3264 if (target == NULL || target->favorite == FALSE || target == service ||
3265 target->type == CONNMAN_SERVICE_TYPE_VPN)
3266 return __connman_error_invalid_service(msg);
3268 target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
3269 target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
3270 service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
3271 service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
3273 DBG("target %s method %d/%d state %d/%d", target->identifier,
3275 target->state_ipv4, target->state_ipv6);
3277 DBG("service %s method %d/%d state %d/%d", service->identifier,
3279 service->state_ipv4, service->state_ipv6);
3282 * If method is OFF, then we do not need to check the corresponding
3285 if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
3286 if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
3287 if (check_suitable_state(target->state_ipv6,
3288 service->state_ipv6) == FALSE)
3289 return __connman_error_invalid_service(msg);
3293 if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
3294 if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
3295 if (check_suitable_state(target->state_ipv4,
3296 service->state_ipv4) == FALSE)
3297 return __connman_error_invalid_service(msg);
3301 if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
3302 if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
3303 if (check_suitable_state(target->state_ipv6,
3304 service->state_ipv6) == FALSE)
3305 return __connman_error_invalid_service(msg);
3309 if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
3310 if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
3311 if (check_suitable_state(target->state_ipv4,
3312 service->state_ipv4) == FALSE)
3313 return __connman_error_invalid_service(msg);
3317 g_get_current_time(&service->modified);
3318 service_save(service);
3320 src = g_hash_table_lookup(service_hash, service->identifier);
3321 dst = g_hash_table_lookup(service_hash, target->identifier);
3323 before ? g_sequence_move(src, dst) : g_sequence_move(dst, src);
3325 services_changed(FALSE);
3327 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3330 static DBusMessage *move_before(DBusConnection *conn,
3331 DBusMessage *msg, void *user_data)
3333 return move_service(conn, msg, user_data, TRUE);
3336 static DBusMessage *move_after(DBusConnection *conn,
3337 DBusMessage *msg, void *user_data)
3339 return move_service(conn, msg, user_data, FALSE);
3342 static DBusMessage *reset_counters(DBusConnection *conn,
3343 DBusMessage *msg, void *user_data)
3345 struct connman_service *service = user_data;
3347 reset_stats(service);
3349 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
3352 static GDBusMethodTable service_methods[] = {
3353 { "GetProperties", "", "a{sv}", get_properties },
3354 { "SetProperty", "sv", "", set_property },
3355 { "ClearProperty", "s", "", clear_property },
3356 { "Connect", "", "", connect_service,
3357 G_DBUS_METHOD_FLAG_ASYNC },
3358 { "Disconnect", "", "", disconnect_service },
3359 { "Remove", "", "", remove_service },
3360 { "MoveBefore", "o", "", move_before },
3361 { "MoveAfter", "o", "", move_after },
3362 { "ResetCounters", "", "", reset_counters },
3366 static GDBusSignalTable service_signals[] = {
3367 { "PropertyChanged", "sv" },
3371 static void service_free(gpointer user_data)
3373 struct connman_service *service = user_data;
3374 char *path = service->path;
3376 DBG("service %p", service);
3378 reply_pending(service, ENOENT);
3380 g_hash_table_remove(service_hash, service->identifier);
3382 __connman_notifier_service_remove(service);
3384 stats_stop(service);
3386 service->path = NULL;
3389 services_changed(FALSE);
3391 g_dbus_unregister_interface(connection, path,
3392 CONNMAN_SERVICE_INTERFACE);
3396 g_hash_table_destroy(service->counter_table);
3398 if (service->network != NULL) {
3399 if (service->network_created == TRUE)
3400 connman_network_unref(service->network);
3403 if (service->provider != NULL)
3404 connman_provider_unref(service->provider);
3406 if (service->ipconfig_ipv4 != NULL) {
3407 connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
3408 connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
3409 connman_ipconfig_unref(service->ipconfig_ipv4);
3410 service->ipconfig_ipv4 = NULL;
3413 if (service->ipconfig_ipv6 != NULL) {
3414 connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
3415 connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
3416 connman_ipconfig_unref(service->ipconfig_ipv6);
3417 service->ipconfig_ipv6 = NULL;
3420 g_strfreev(service->nameservers);
3421 g_strfreev(service->nameservers_config);
3422 g_strfreev(service->domains);
3423 g_strfreev(service->proxies);
3424 g_strfreev(service->excludes);
3426 g_free(service->domainname);
3427 g_free(service->pac);
3428 g_free(service->name);
3429 g_free(service->passphrase);
3430 g_free(service->agent_passphrase);
3431 g_free(service->identifier);
3432 g_free(service->eap);
3433 g_free(service->identity);
3434 g_free(service->agent_identity);
3435 g_free(service->ca_cert_file);
3436 g_free(service->client_cert_file);
3437 g_free(service->private_key_file);
3438 g_free(service->private_key_passphrase);
3439 g_free(service->phase2);
3441 if (service->stats.timer != NULL)
3442 g_timer_destroy(service->stats.timer);
3443 if (service->stats_roaming.timer != NULL)
3444 g_timer_destroy(service->stats_roaming.timer);
3450 * __connman_service_put:
3451 * @service: service structure
3453 * Release service if no longer needed
3455 void __connman_service_put(struct connman_service *service)
3457 DBG("service %p", service);
3459 if (g_atomic_int_dec_and_test(&service->refcount) == TRUE) {
3460 GSequenceIter *iter;
3462 iter = g_hash_table_lookup(service_hash, service->identifier);
3464 reply_pending(service, ECONNABORTED);
3466 __connman_service_disconnect(service);
3468 g_sequence_remove(iter);
3470 service_free(service);
3474 static void stats_init(struct connman_service *service)
3477 service->stats.valid = FALSE;
3478 service->stats.enabled = FALSE;
3479 service->stats.timer = g_timer_new();
3482 service->stats_roaming.valid = FALSE;
3483 service->stats_roaming.enabled = FALSE;
3484 service->stats_roaming.timer = g_timer_new();
3487 static void service_initialize(struct connman_service *service)
3489 DBG("service %p", service);
3491 service->refcount = 1;
3492 service->session_usage_count = 0;
3494 service->network_created = FALSE;
3496 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
3497 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
3499 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
3500 service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
3501 service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
3503 service->favorite = FALSE;
3504 service->immutable = FALSE;
3505 service->hidden = FALSE;
3507 service->ignore = FALSE;
3509 service->userconnect = FALSE;
3513 stats_init(service);
3515 service->provider = NULL;
3517 service->wps = FALSE;
3521 * connman_service_create:
3523 * Allocate a new service.
3525 * Returns: a newly-allocated #connman_service structure
3527 struct connman_service *connman_service_create(void)
3530 struct connman_stats_counter *counters;
3531 const char *counter;
3533 struct connman_service *service;
3535 service = g_try_new0(struct connman_service, 1);
3536 if (service == NULL)
3539 DBG("service %p", service);
3541 service->counter_table = g_hash_table_new_full(g_str_hash,
3542 g_str_equal, NULL, g_free);
3544 for (list = counter_list; list; list = list->next) {
3545 counter = list->data;
3547 counters = g_try_new0(struct connman_stats_counter, 1);
3548 if (counters == NULL) {
3549 g_hash_table_destroy(service->counter_table);
3554 counters->append_all = TRUE;
3556 g_hash_table_replace(service->counter_table, (gpointer)counter,
3560 service_initialize(service);
3566 * connman_service_ref:
3567 * @service: service structure
3569 * Increase reference counter of service
3571 struct connman_service *connman_service_ref(struct connman_service *service)
3575 g_atomic_int_inc(&service->refcount);
3581 * connman_service_unref:
3582 * @service: service structure
3584 * Decrease reference counter of service
3586 void connman_service_unref(struct connman_service *service)
3588 __connman_service_put(service);
3591 static gint service_compare(gconstpointer a, gconstpointer b,
3594 struct connman_service *service_a = (void *) a;
3595 struct connman_service *service_b = (void *) b;
3596 enum connman_service_state state_a, state_b;
3598 state_a = service_a->state;
3599 state_b = service_b->state;
3601 if (state_a != state_b) {
3602 gboolean a_connected = is_connected(service_a);
3603 gboolean b_connected = is_connected(service_b);
3605 if (a_connected == TRUE && b_connected == TRUE) {
3606 /* We prefer online over ready state */
3607 if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
3610 if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
3614 if (a_connected == TRUE)
3616 if (b_connected == TRUE)
3619 if (is_connecting(service_a) == TRUE)
3621 if (is_connecting(service_b) == TRUE)
3625 if (service_a->order > service_b->order)
3628 if (service_a->order < service_b->order)
3631 if (service_a->favorite == TRUE && service_b->favorite == FALSE)
3634 if (service_a->favorite == FALSE && service_b->favorite == TRUE)
3637 if (service_a->type != service_b->type) {
3638 switch (service_a->type) {
3639 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3640 case CONNMAN_SERVICE_TYPE_SYSTEM:
3641 case CONNMAN_SERVICE_TYPE_ETHERNET:
3642 case CONNMAN_SERVICE_TYPE_GPS:
3643 case CONNMAN_SERVICE_TYPE_VPN:
3644 case CONNMAN_SERVICE_TYPE_GADGET:
3646 case CONNMAN_SERVICE_TYPE_WIFI:
3648 case CONNMAN_SERVICE_TYPE_WIMAX:
3649 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3650 case CONNMAN_SERVICE_TYPE_CELLULAR:
3655 return (gint) service_b->strength - (gint) service_a->strength;
3659 * connman_service_get_type:
3660 * @service: service structure
3662 * Get the type of service
3664 enum connman_service_type connman_service_get_type(struct connman_service *service)
3666 if (service == NULL)
3667 return CONNMAN_SERVICE_TYPE_UNKNOWN;
3669 return service->type;
3673 * connman_service_get_interface:
3674 * @service: service structure
3676 * Get network interface of service
3678 char *connman_service_get_interface(struct connman_service *service)
3682 if (service == NULL)
3685 if (service->type == CONNMAN_SERVICE_TYPE_VPN) {
3686 if (service->ipconfig_ipv4)
3687 index = connman_ipconfig_get_index(
3688 service->ipconfig_ipv4);
3689 else if (service->ipconfig_ipv6)
3690 index = connman_ipconfig_get_index(
3691 service->ipconfig_ipv6);
3695 return connman_inet_ifname(index);
3698 if (service->network == NULL)
3701 index = connman_network_get_index(service->network);
3703 return connman_inet_ifname(index);
3707 * connman_service_get_network:
3708 * @service: service structure
3710 * Get the service network
3712 struct connman_network *
3713 __connman_service_get_network(struct connman_service *service)
3715 if (service == NULL)
3718 return service->network;
3721 struct connman_ipconfig *
3722 __connman_service_get_ip4config(struct connman_service *service)
3724 if (service == NULL)
3727 return service->ipconfig_ipv4;
3730 struct connman_ipconfig *
3731 __connman_service_get_ip6config(struct connman_service *service)
3733 if (service == NULL)
3736 return service->ipconfig_ipv6;
3739 struct connman_ipconfig *
3740 __connman_service_get_ipconfig(struct connman_service *service, int family)
3742 if (family == AF_INET)
3743 return __connman_service_get_ip4config(service);
3744 else if (family == AF_INET6)
3745 return __connman_service_get_ip6config(service);
3751 enum connman_service_security __connman_service_get_security(struct connman_service *service)
3753 if (service == NULL)
3754 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
3756 return service->security;
3759 const char *__connman_service_get_phase2(struct connman_service *service)
3761 if (service == NULL)
3764 return service->phase2;
3767 connman_bool_t __connman_service_wps_enabled(struct connman_service *service)
3769 if (service == NULL)
3772 return service->wps;
3776 * __connman_service_set_favorite:
3777 * @service: service structure
3778 * @favorite: favorite value
3780 * Change the favorite setting of service
3782 int __connman_service_set_favorite(struct connman_service *service,
3783 connman_bool_t favorite)
3785 GSequenceIter *iter;
3787 iter = g_hash_table_lookup(service_hash, service->identifier);
3791 if (service->favorite == favorite)
3794 service->favorite = favorite;
3796 favorite_changed(service);
3798 g_sequence_sort_changed(iter, service_compare, NULL);
3800 services_changed(FALSE);
3805 int __connman_service_set_immutable(struct connman_service *service,
3806 connman_bool_t immutable)
3808 service->immutable = immutable;
3810 immutable_changed(service);
3815 void __connman_service_set_string(struct connman_service *service,
3816 const char *key, const char *value)
3818 if (g_str_equal(key, "EAP") == TRUE) {
3819 g_free(service->eap);
3820 service->eap = g_strdup(value);
3821 } else if (g_str_equal(key, "Identity") == TRUE) {
3822 g_free(service->identity);
3823 service->identity = g_strdup(value);
3824 } else if (g_str_equal(key, "CACertFile") == TRUE) {
3825 g_free(service->ca_cert_file);
3826 service->ca_cert_file = g_strdup(value);
3827 } else if (g_str_equal(key, "ClientCertFile") == TRUE) {
3828 g_free(service->client_cert_file);
3829 service->client_cert_file = g_strdup(value);
3830 } else if (g_str_equal(key, "PrivateKeyFile") == TRUE) {
3831 g_free(service->private_key_file);
3832 service->private_key_file = g_strdup(value);
3833 } else if (g_str_equal(key, "PrivateKeyPassphrase") == TRUE) {
3834 g_free(service->private_key_passphrase);
3835 service->private_key_passphrase = g_strdup(value);
3836 } else if (g_str_equal(key, "Phase2") == TRUE) {
3837 g_free(service->phase2);
3838 service->phase2 = g_strdup(value);
3839 } else if (g_str_equal(key, "Passphrase") == TRUE) {
3840 g_free(service->passphrase);
3841 service->passphrase = g_strdup(value);
3845 static void service_complete(struct connman_service *service)
3847 reply_pending(service, EIO);
3849 if (service->userconnect == FALSE)
3850 __connman_service_auto_connect();
3852 g_get_current_time(&service->modified);
3853 service_save(service);
3856 static void report_error_cb(struct connman_service *service,
3857 gboolean retry, void *user_data)
3860 __connman_service_connect(service);
3862 service_complete(service);
3863 services_changed(FALSE);
3864 __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
3868 static void request_input_cb (struct connman_service *service,
3869 const char *identity, const char *passphrase,
3872 DBG ("RequestInput return, %p", service);
3874 if (identity == NULL && passphrase == NULL && service->wps == FALSE) {
3875 service_complete(service);
3876 services_changed(FALSE);
3877 __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
3881 if (identity != NULL)
3882 __connman_service_set_agent_identity(service, identity);
3884 if (passphrase != NULL) {
3885 switch (service->security) {
3886 case CONNMAN_SERVICE_SECURITY_WEP:
3887 case CONNMAN_SERVICE_SECURITY_PSK:
3888 __connman_service_set_passphrase(service, passphrase);
3890 case CONNMAN_SERVICE_SECURITY_8021X:
3891 __connman_service_set_agent_passphrase(service,
3894 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3895 case CONNMAN_SERVICE_SECURITY_NONE:
3896 case CONNMAN_SERVICE_SECURITY_WPA:
3897 case CONNMAN_SERVICE_SECURITY_RSN:
3898 DBG("service security '%s' not handled",
3899 security2string(service->security));
3904 __connman_service_connect(service);
3906 /* Never cache agent provided credentials */
3907 __connman_service_set_agent_identity(service, NULL);
3908 __connman_service_set_agent_passphrase(service, NULL);
3911 static int service_indicate_state(struct connman_service *service)
3913 enum connman_service_state old_state, new_state;
3914 GSequenceIter *iter;
3916 if (service == NULL)
3919 old_state = service->state;
3920 new_state = combine_state(service->state_ipv4, service->state_ipv6);
3922 DBG("service %p old %s - new %s/%s => %s",
3924 state2string(old_state),
3925 state2string(service->state_ipv4),
3926 state2string(service->state_ipv6),
3927 state2string(new_state));
3929 if (old_state == new_state)
3932 service->state = new_state;
3933 state_changed(service);
3935 if (new_state == CONNMAN_SERVICE_STATE_IDLE &&
3936 old_state != CONNMAN_SERVICE_STATE_DISCONNECT) {
3937 reply_pending(service, ECONNABORTED);
3939 __connman_service_disconnect(service);
3942 if (new_state == CONNMAN_SERVICE_STATE_CONFIGURATION) {
3943 if (__connman_stats_service_register(service) == 0) {
3944 __connman_stats_get(service, FALSE,
3945 &service->stats.data);
3946 __connman_stats_get(service, TRUE,
3947 &service->stats_roaming.data);
3951 if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
3952 if (service->login_required == TRUE) {
3953 service->login_required = FALSE;
3954 login_changed(service);
3957 connman_timeserver_sync();
3960 if (new_state == CONNMAN_SERVICE_STATE_IDLE) {
3961 connman_bool_t reconnect;
3963 reconnect = get_reconnect_state(service);
3964 if (reconnect == TRUE)
3965 __connman_service_auto_connect();
3967 __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
3970 if (new_state == CONNMAN_SERVICE_STATE_READY) {
3971 enum connman_ipconfig_method method;
3973 set_reconnect_state(service, TRUE);
3975 __connman_service_set_favorite(service, TRUE);
3977 reply_pending(service, 0);
3979 service->userconnect = FALSE;
3981 g_get_current_time(&service->modified);
3982 service_save(service);
3984 update_nameservers(service);
3985 dns_changed(service);
3986 domain_changed(service);
3988 __connman_notifier_connect(service->type);
3990 if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
3991 connman_network_get_bool(service->network,
3992 "WiFi.UseWPS") == TRUE) {
3995 pass = connman_network_get_string(service->network,
3998 __connman_service_set_passphrase(service, pass);
4000 connman_network_set_bool(service->network,
4001 "WiFi.UseWPS", FALSE);
4006 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
4007 if (method == CONNMAN_IPCONFIG_METHOD_OFF)
4008 __connman_ipconfig_disable_ipv6(
4009 service->ipconfig_ipv6);
4011 } else if (new_state == CONNMAN_SERVICE_STATE_DISCONNECT) {
4012 struct connman_service *def_service = get_default();
4014 if (__connman_notifier_count_connected() == 0 &&
4015 def_service != NULL &&
4016 def_service->provider != NULL)
4017 __connman_provider_disconnect(def_service->provider);
4021 __connman_wpad_stop(service);
4023 update_nameservers(service);
4024 dns_changed(service);
4025 domain_changed(service);
4027 __connman_notifier_disconnect(service->type);
4030 if (new_state == CONNMAN_SERVICE_STATE_FAILURE) {
4031 if (service->userconnect == TRUE &&
4032 __connman_agent_report_error(service,
4033 error2string(service->error),
4034 report_error_cb, NULL) == -EIO)
4036 service_complete(service);
4038 __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
4040 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
4042 iter = g_hash_table_lookup(service_hash, service->identifier);
4044 g_sequence_sort_changed(iter, service_compare, NULL);
4046 services_changed(FALSE);
4048 if (new_state == CONNMAN_SERVICE_STATE_ONLINE)
4054 int __connman_service_indicate_error(struct connman_service *service,
4055 enum connman_service_error error)
4057 DBG("service %p error %d", service, error);
4059 if (service == NULL)
4062 service->error = error;
4064 if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
4065 __connman_service_set_passphrase(service, NULL);
4067 __connman_service_ipconfig_indicate_state(service,
4068 CONNMAN_SERVICE_STATE_FAILURE,
4069 CONNMAN_IPCONFIG_TYPE_IPV4);
4070 __connman_service_ipconfig_indicate_state(service,
4071 CONNMAN_SERVICE_STATE_FAILURE,
4072 CONNMAN_IPCONFIG_TYPE_IPV6);
4076 int __connman_service_clear_error(struct connman_service *service)
4078 DBG("service %p", service);
4080 if (service == NULL)
4083 if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
4086 service->state_ipv4 = service->state_ipv6 =
4087 CONNMAN_SERVICE_STATE_UNKNOWN;
4088 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;;
4090 if (service->favorite == TRUE)
4091 set_reconnect_state(service, TRUE);
4093 __connman_service_ipconfig_indicate_state(service,
4094 CONNMAN_SERVICE_STATE_IDLE,
4095 CONNMAN_IPCONFIG_TYPE_IPV6);
4098 * Toggling the IPv6 state to IDLE could trigger the auto connect
4099 * machinery and consequently the IPv4 state.
4101 if (service->state_ipv4 != CONNMAN_SERVICE_STATE_UNKNOWN &&
4102 service->state_ipv4 != CONNMAN_SERVICE_STATE_FAILURE)
4105 return __connman_service_ipconfig_indicate_state(service,
4106 CONNMAN_SERVICE_STATE_IDLE,
4107 CONNMAN_IPCONFIG_TYPE_IPV4);
4110 int __connman_service_indicate_default(struct connman_service *service)
4112 DBG("service %p", service);
4119 enum connman_service_state __connman_service_ipconfig_get_state(
4120 struct connman_service *service,
4121 enum connman_ipconfig_type type)
4123 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4124 return service->state_ipv4;
4126 if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4127 return service->state_ipv6;
4129 return CONNMAN_SERVICE_STATE_UNKNOWN;
4132 static void check_proxy_setup(struct connman_service *service)
4135 * We start WPAD if we haven't got a PAC URL from DHCP and
4136 * if our proxy manual configuration is either empty or set
4137 * to AUTO with an empty URL.
4140 if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
4143 if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
4144 (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
4145 service->pac != NULL))
4148 if (__connman_wpad_start(service) < 0) {
4149 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
4150 __connman_notifier_proxy_changed(service);
4154 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
4155 enum connman_service_state new_state,
4156 enum connman_ipconfig_type type)
4158 struct connman_ipconfig *ipconfig = NULL;
4159 enum connman_service_state old_state;
4162 if (service == NULL)
4165 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4166 old_state = service->state_ipv4;
4167 ipconfig = service->ipconfig_ipv4;
4168 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4169 old_state = service->state_ipv6;
4170 ipconfig = service->ipconfig_ipv6;
4173 if (ipconfig == NULL)
4177 if (old_state == new_state)
4180 DBG("service %p (%s) state %d (%s) type %d (%s)",
4181 service, service ? service->identifier : NULL,
4182 new_state, state2string(new_state),
4183 type, __connman_ipconfig_type2string(type));
4185 switch (new_state) {
4186 case CONNMAN_SERVICE_STATE_UNKNOWN:
4187 case CONNMAN_SERVICE_STATE_IDLE:
4188 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
4191 case CONNMAN_SERVICE_STATE_ASSOCIATION:
4193 case CONNMAN_SERVICE_STATE_CONFIGURATION:
4194 __connman_ipconfig_enable(ipconfig);
4196 case CONNMAN_SERVICE_STATE_READY:
4197 update_nameservers(service);
4199 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4200 check_proxy_setup(service);
4202 case CONNMAN_SERVICE_STATE_ONLINE:
4204 case CONNMAN_SERVICE_STATE_DISCONNECT:
4205 if (service->state == CONNMAN_SERVICE_STATE_IDLE)
4208 case CONNMAN_SERVICE_STATE_FAILURE:
4212 /* We keep that state */
4213 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
4214 service->state_ipv4 = new_state;
4215 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
4216 service->state_ipv6 = new_state;
4218 ret = service_indicate_state(service);
4221 * If the ipconfig method is OFF, then we set the state to IDLE
4222 * so that it will not affect the combined state in the future.
4224 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
4225 enum connman_ipconfig_method method;
4226 method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
4227 if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
4228 method == CONNMAN_IPCONFIG_METHOD_UNKNOWN) {
4229 service->state_ipv4 = CONNMAN_SERVICE_STATE_IDLE;
4230 ret = service_indicate_state(service);
4233 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
4234 enum connman_ipconfig_method method;
4235 method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
4236 if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
4237 method == CONNMAN_IPCONFIG_METHOD_UNKNOWN) {
4238 service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
4239 ret = service_indicate_state(service);
4246 int __connman_service_request_login(struct connman_service *service)
4248 DBG("service %p", service);
4250 if (service == NULL)
4253 service->login_required = TRUE;
4254 login_changed(service);
4259 static connman_bool_t prepare_network(struct connman_service *service)
4261 enum connman_network_type type;
4262 unsigned int ssid_len;
4264 type = connman_network_get_type(service->network);
4267 case CONNMAN_NETWORK_TYPE_UNKNOWN:
4268 case CONNMAN_NETWORK_TYPE_VENDOR:
4270 case CONNMAN_NETWORK_TYPE_WIFI:
4271 if (connman_network_get_blob(service->network, "WiFi.SSID",
4275 if (service->passphrase != NULL)
4276 connman_network_set_string(service->network,
4277 "WiFi.Passphrase", service->passphrase);
4279 case CONNMAN_NETWORK_TYPE_ETHERNET:
4280 case CONNMAN_NETWORK_TYPE_WIMAX:
4281 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
4282 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
4283 case CONNMAN_NETWORK_TYPE_CELLULAR:
4290 static void prepare_8021x(struct connman_service *service)
4292 if (service->eap != NULL)
4293 connman_network_set_string(service->network, "WiFi.EAP",
4296 if (service->identity != NULL)
4297 connman_network_set_string(service->network, "WiFi.Identity",
4300 if (service->ca_cert_file != NULL)
4301 connman_network_set_string(service->network, "WiFi.CACertFile",
4302 service->ca_cert_file);
4304 if (service->client_cert_file != NULL)
4305 connman_network_set_string(service->network,
4306 "WiFi.ClientCertFile",
4307 service->client_cert_file);
4309 if (service->private_key_file != NULL)
4310 connman_network_set_string(service->network,
4311 "WiFi.PrivateKeyFile",
4312 service->private_key_file);
4314 if (service->private_key_passphrase != NULL)
4315 connman_network_set_string(service->network,
4316 "WiFi.PrivateKeyPassphrase",
4317 service->private_key_passphrase);
4319 if (service->phase2 != NULL)
4320 connman_network_set_string(service->network, "WiFi.Phase2",
4324 static int service_connect(struct connman_service *service)
4328 switch (service->type) {
4329 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4330 case CONNMAN_SERVICE_TYPE_SYSTEM:
4331 case CONNMAN_SERVICE_TYPE_GPS:
4332 case CONNMAN_SERVICE_TYPE_GADGET:
4334 case CONNMAN_SERVICE_TYPE_ETHERNET:
4335 case CONNMAN_SERVICE_TYPE_WIMAX:
4336 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4337 case CONNMAN_SERVICE_TYPE_CELLULAR:
4338 case CONNMAN_SERVICE_TYPE_VPN:
4340 case CONNMAN_SERVICE_TYPE_WIFI:
4341 switch (service->security) {
4342 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
4343 case CONNMAN_SERVICE_SECURITY_NONE:
4345 case CONNMAN_SERVICE_SECURITY_WEP:
4346 case CONNMAN_SERVICE_SECURITY_PSK:
4347 case CONNMAN_SERVICE_SECURITY_WPA:
4348 case CONNMAN_SERVICE_SECURITY_RSN:
4349 if (service->passphrase == NULL) {
4350 if (service->network == NULL)
4353 if (service->wps == FALSE ||
4354 connman_network_get_bool(
4356 "WiFi.UseWPS") == FALSE)
4360 case CONNMAN_SERVICE_SECURITY_8021X:
4361 if (service->eap == NULL)
4365 * never request credentials if using EAP-TLS
4366 * (EAP-TLS networks need to be fully provisioned)
4368 if (g_str_equal(service->eap, "tls") == TRUE)
4372 * Return -ENOKEY if either identity or passphrase is
4373 * missing. Agent provided credentials can be used as
4374 * fallback if needed.
4376 if ((service->identity == NULL &&
4377 service->agent_identity == NULL) ||
4378 (service->passphrase == NULL &&
4379 service->agent_passphrase == NULL))
4387 if (service->network != NULL) {
4388 if (prepare_network(service) == FALSE)
4391 switch (service->security) {
4392 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
4393 case CONNMAN_SERVICE_SECURITY_NONE:
4394 case CONNMAN_SERVICE_SECURITY_WEP:
4395 case CONNMAN_SERVICE_SECURITY_PSK:
4396 case CONNMAN_SERVICE_SECURITY_WPA:
4397 case CONNMAN_SERVICE_SECURITY_RSN:
4399 case CONNMAN_SERVICE_SECURITY_8021X:
4400 prepare_8021x(service);
4404 if (__connman_stats_service_register(service) == 0) {
4405 __connman_stats_get(service, FALSE,
4406 &service->stats.data);
4407 __connman_stats_get(service, TRUE,
4408 &service->stats_roaming.data);
4411 if (service->ipconfig_ipv4)
4412 __connman_ipconfig_enable(service->ipconfig_ipv4);
4413 if (service->ipconfig_ipv6)
4414 __connman_ipconfig_enable(service->ipconfig_ipv6);
4416 err = __connman_network_connect(service->network);
4417 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
4418 service->provider != NULL)
4419 err = __connman_provider_connect(service->provider);
4424 if (err != -EINPROGRESS) {
4425 __connman_ipconfig_disable(service->ipconfig_ipv4);
4426 __connman_ipconfig_disable(service->ipconfig_ipv6);
4427 __connman_stats_service_unregister(service);
4435 int __connman_service_connect(struct connman_service *service)
4439 DBG("service %p state %s", service, state2string(service->state));
4441 if (is_connected(service) == TRUE)
4444 if (is_connecting(service) == TRUE)
4447 switch (service->type) {
4448 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4449 case CONNMAN_SERVICE_TYPE_SYSTEM:
4450 case CONNMAN_SERVICE_TYPE_GPS:
4451 case CONNMAN_SERVICE_TYPE_GADGET:
4454 err = service_connect(service);
4460 if (err == -EINPROGRESS) {
4461 if (service->timeout == 0)
4462 service->timeout = g_timeout_add_seconds(
4463 CONNECT_TIMEOUT, connect_timeout, service);
4465 return -EINPROGRESS;
4468 __connman_service_ipconfig_indicate_state(service,
4469 CONNMAN_SERVICE_STATE_FAILURE,
4470 CONNMAN_IPCONFIG_TYPE_IPV4);
4471 __connman_service_ipconfig_indicate_state(service,
4472 CONNMAN_SERVICE_STATE_FAILURE,
4473 CONNMAN_IPCONFIG_TYPE_IPV6);
4475 if (service->network != NULL)
4476 __connman_network_disconnect(service->network);
4477 else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
4478 service->provider != NULL)
4479 __connman_provider_disconnect(service->provider);
4481 if (service->userconnect == TRUE) {
4482 if (err == -ENOKEY) {
4483 if (__connman_agent_request_input(service,
4486 return -EINPROGRESS;
4488 reply_pending(service, err);
4494 int __connman_service_disconnect(struct connman_service *service)
4498 DBG("service %p", service);
4500 if (service->network != NULL) {
4501 err = __connman_network_disconnect(service->network);
4502 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
4503 service->provider != NULL)
4504 err = __connman_provider_disconnect(service->provider);
4508 if (err < 0 && err != -EINPROGRESS)
4511 __connman_6to4_remove(service->ipconfig_ipv4);
4513 if (service->ipconfig_ipv4)
4514 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
4517 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
4520 __connman_ipconfig_address_remove(service->ipconfig_ipv4);
4521 __connman_ipconfig_address_remove(service->ipconfig_ipv6);
4523 __connman_ipconfig_disable(service->ipconfig_ipv4);
4524 __connman_ipconfig_disable(service->ipconfig_ipv6);
4526 __connman_stats_service_unregister(service);
4531 int __connman_service_disconnect_all(void)
4533 GSequenceIter *iter;
4537 iter = g_sequence_get_begin_iter(service_list);
4539 while (g_sequence_iter_is_end(iter) == FALSE) {
4540 struct connman_service *service = g_sequence_get(iter);
4542 service->ignore = TRUE;
4544 set_reconnect_state(service, FALSE);
4546 __connman_service_disconnect(service);
4548 iter = g_sequence_iter_next(iter);
4556 * __connman_service_lookup:
4557 * @pattern: search pattern
4558 * @path: return object path
4560 * Look up a service path from a search pattern
4562 int __connman_service_lookup(const char *pattern, const char **path)
4564 GHashTableIter iter;
4565 gpointer key, value;
4567 g_hash_table_iter_init(&iter, service_hash);
4569 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
4570 GSequenceIter *iter = value;
4571 struct connman_service *service = g_sequence_get(iter);
4573 if (g_strcmp0(service->identifier, pattern) == 0 ||
4574 g_strcmp0(service->name, pattern) == 0) {
4575 *path = (const char *) service->path;
4584 * lookup_by_identifier:
4585 * @identifier: service identifier
4587 * Look up a service by identifier (reference count will not be increased)
4589 static struct connman_service *lookup_by_identifier(const char *identifier)
4591 GSequenceIter *iter;
4593 iter = g_hash_table_lookup(service_hash, identifier);
4595 return g_sequence_get(iter);
4600 static struct connman_network *create_hidden_wifi(struct connman_device *device,
4601 const char *ssid, const char *mode, const char *security,
4604 struct connman_network *network;
4607 unsigned int i, ssid_len;
4609 ssid_len = strlen(ssid);
4613 network = connman_network_create(group, CONNMAN_NETWORK_TYPE_WIFI);
4614 if (network == NULL)
4617 connman_network_set_blob(network, "WiFi.SSID",
4618 (unsigned char *) ssid, ssid_len);
4620 connman_network_set_string(network, "WiFi.Mode", mode);
4621 connman_network_set_string(network, "WiFi.Security", security);
4623 name = g_try_malloc0(ssid_len + 1);
4625 connman_network_unref(network);
4629 for (i = 0; i < ssid_len; i++) {
4630 if (g_ascii_isprint(ssid[i]))
4636 connman_network_set_name(network, name);
4640 index = connman_device_get_index(device);
4641 connman_network_set_index(network, index);
4643 if (connman_device_add_network(device, network) < 0) {
4644 connman_network_unref(network);
4648 connman_network_set_available(network, TRUE);
4653 int __connman_service_create_and_connect(DBusMessage *msg)
4655 struct connman_service *service;
4656 struct connman_network *network;
4657 struct connman_device *device;
4658 DBusMessageIter iter, array;
4659 const char *mode = "managed", *security = "none", *group_security;
4660 const char *type = NULL, *ssid = NULL, *passphrase = NULL;
4661 unsigned int ssid_len = 0;
4666 dbus_message_iter_init(msg, &iter);
4667 dbus_message_iter_recurse(&iter, &array);
4669 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
4670 DBusMessageIter entry, value;
4673 dbus_message_iter_recurse(&array, &entry);
4674 dbus_message_iter_get_basic(&entry, &key);
4676 dbus_message_iter_next(&entry);
4677 dbus_message_iter_recurse(&entry, &value);
4679 switch (dbus_message_iter_get_arg_type(&value)) {
4680 case DBUS_TYPE_STRING:
4681 if (g_str_equal(key, "Type") == TRUE)
4682 dbus_message_iter_get_basic(&value, &type);
4683 else if (g_str_equal(key, "WiFi.Mode") == TRUE ||
4684 g_str_equal(key, "Mode") == TRUE)
4685 dbus_message_iter_get_basic(&value, &mode);
4686 else if (g_str_equal(key, "WiFi.Security") == TRUE ||
4687 g_str_equal(key, "Security") == TRUE)
4688 dbus_message_iter_get_basic(&value, &security);
4689 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE ||
4690 g_str_equal(key, "Passphrase") == TRUE)
4691 dbus_message_iter_get_basic(&value, &passphrase);
4692 else if (g_str_equal(key, "WiFi.SSID") == TRUE ||
4693 g_str_equal(key, "SSID") == TRUE)
4694 dbus_message_iter_get_basic(&value, &ssid);
4697 dbus_message_iter_next(&array);
4703 if (g_strcmp0(type, "wifi") != 0 || g_strcmp0(mode, "managed") != 0)
4709 ssid_len = strlen(ssid);
4713 if (g_strcmp0(security, "none") != 0 &&
4714 g_strcmp0(security, "wep") != 0 &&
4715 g_strcmp0(security, "psk") != 0 &&
4716 g_strcmp0(security, "wpa") != 0 &&
4717 g_strcmp0(security, "rsn") != 0 &&
4718 g_strcmp0(security, "ieee8021x") != 0)
4721 device = __connman_device_find_device(CONNMAN_SERVICE_TYPE_WIFI);
4725 ident = connman_device_get_ident(device);
4730 if (!g_strcmp0(security, "wpa") ||
4731 !g_strcmp0(security, "rsn"))
4732 group_security = "psk";
4734 group_security = security;
4736 group = wifi_build_group_name((unsigned char *) ssid,
4737 ssid_len, mode, group_security);
4741 name = g_strdup_printf("%s_%s_%s", type, ident, group);
4743 service = lookup_by_identifier(name);
4745 if (service != NULL)
4748 network = create_hidden_wifi(device, ssid, mode, security, group);
4749 if (network != NULL)
4750 connman_network_set_group(network, group);
4752 service = lookup_by_identifier(name);
4758 if (service == NULL) {
4763 service->network_created = TRUE;
4765 if (is_connected(service) == TRUE) {
4770 if (is_connecting(service) == TRUE) {
4775 set_reconnect_state(service, FALSE);
4777 __connman_device_disconnect(device);
4779 if (passphrase != NULL) {
4780 g_free(service->passphrase);
4781 service->passphrase = g_strdup(passphrase);
4784 service->userconnect = TRUE;
4786 err = __connman_service_connect(service);
4787 if (err < 0 && err != -EINPROGRESS)
4790 service->pending = dbus_message_ref(msg);
4795 if (service != NULL && service->network_created == TRUE) {
4796 struct connman_network *network = service->network;
4798 if (network != NULL) {
4799 connman_network_set_available(network, FALSE);
4800 __connman_device_cleanup_networks(device);
4802 __connman_service_put(service);
4808 static void provision_changed(gpointer value, gpointer user_data)
4810 struct connman_service *service = value;
4811 char *path = user_data;
4813 __connman_config_provision_service_ident(service, path);
4816 void __connman_service_provision_changed(const char *ident)
4818 g_sequence_foreach(service_list, provision_changed, (void *)ident);
4821 int __connman_service_provision(DBusMessage *msg)
4823 GKeyFile *keyfile = NULL;
4824 const char *config_str = NULL;
4825 char *group = NULL, *ident = NULL;
4827 struct connman_service *service;
4831 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &config_str,
4834 if (config_str == NULL || strlen(config_str) == 0)
4837 keyfile = g_key_file_new();
4839 /* populate GKeyFile with config_str */
4840 if (g_key_file_load_from_data(keyfile, config_str,
4841 strlen(config_str), 0, NULL) == FALSE) {
4847 * read only one group of settings (only one service supported, no
4850 group = g_key_file_get_start_group(keyfile);
4852 if (group == NULL || g_str_has_prefix(group, "service_") == FALSE) {
4857 err = __connman_config_load_service(keyfile, group, TRUE);
4861 ident = group + strlen("service_");
4863 /* trigger service provisioning if service exists */
4864 service = lookup_by_identifier(ident);
4865 if (service != NULL)
4866 __connman_config_provision_service(service);
4868 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
4874 if (keyfile != NULL)
4875 g_key_file_free(keyfile);
4881 * __connman_service_get:
4882 * @identifier: service identifier
4884 * Look up a service by identifier or create a new one if not found
4886 static struct connman_service *service_get(const char *identifier)
4888 struct connman_service *service;
4889 GSequenceIter *iter;
4891 iter = g_hash_table_lookup(service_hash, identifier);
4893 service = g_sequence_get(iter);
4894 if (service != NULL)
4895 connman_service_ref(service);
4899 service = connman_service_create();
4900 if (service == NULL)
4903 DBG("service %p", service);
4905 service->identifier = g_strdup(identifier);
4907 iter = g_sequence_insert_sorted(service_list, service,
4908 service_compare, NULL);
4910 g_hash_table_insert(service_hash, service->identifier, iter);
4915 static int service_register(struct connman_service *service)
4917 GSequenceIter *iter;
4919 DBG("service %p", service);
4921 if (service->path != NULL)
4924 service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
4925 service->identifier);
4927 DBG("path %s", service->path);
4929 __connman_config_provision_service(service);
4931 service_load(service);
4933 g_dbus_register_interface(connection, service->path,
4934 CONNMAN_SERVICE_INTERFACE,
4935 service_methods, service_signals,
4936 NULL, service, NULL);
4938 iter = g_hash_table_lookup(service_hash, service->identifier);
4940 g_sequence_sort_changed(iter, service_compare, NULL);
4942 services_changed(TRUE);
4947 static void service_up(struct connman_ipconfig *ipconfig)
4949 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
4951 DBG("%s up", connman_ipconfig_get_ifname(ipconfig));
4953 link_changed(service);
4955 service->stats.valid = FALSE;
4956 service->stats_roaming.valid = FALSE;
4959 static void service_down(struct connman_ipconfig *ipconfig)
4961 DBG("%s down", connman_ipconfig_get_ifname(ipconfig));
4964 static void service_lower_up(struct connman_ipconfig *ipconfig)
4966 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
4968 DBG("%s lower up", connman_ipconfig_get_ifname(ipconfig));
4970 stats_start(service);
4973 static void service_lower_down(struct connman_ipconfig *ipconfig)
4975 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
4977 DBG("%s lower down", connman_ipconfig_get_ifname(ipconfig));
4979 stats_stop(service);
4980 service_save(service);
4983 static void service_ip_bound(struct connman_ipconfig *ipconfig)
4985 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
4986 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
4987 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
4989 DBG("%s ip bound", connman_ipconfig_get_ifname(ipconfig));
4991 type = __connman_ipconfig_get_config_type(ipconfig);
4992 method = __connman_ipconfig_get_method(ipconfig);
4994 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
4997 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
4998 method == CONNMAN_IPCONFIG_METHOD_AUTO)
4999 __connman_service_ipconfig_indicate_state(service,
5000 CONNMAN_SERVICE_STATE_READY,
5001 CONNMAN_IPCONFIG_TYPE_IPV6);
5003 settings_changed(service, ipconfig);
5006 static void service_ip_release(struct connman_ipconfig *ipconfig)
5008 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
5009 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
5010 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
5012 DBG("%s ip release", connman_ipconfig_get_ifname(ipconfig));
5014 type = __connman_ipconfig_get_config_type(ipconfig);
5015 method = __connman_ipconfig_get_method(ipconfig);
5017 DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
5020 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
5021 method == CONNMAN_IPCONFIG_METHOD_OFF)
5022 __connman_service_ipconfig_indicate_state(service,
5023 CONNMAN_SERVICE_STATE_DISCONNECT,
5024 CONNMAN_IPCONFIG_TYPE_IPV6);
5026 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
5027 method == CONNMAN_IPCONFIG_METHOD_OFF)
5028 __connman_service_ipconfig_indicate_state(service,
5029 CONNMAN_SERVICE_STATE_DISCONNECT,
5030 CONNMAN_IPCONFIG_TYPE_IPV4);
5032 settings_changed(service, ipconfig);
5035 static const struct connman_ipconfig_ops service_ops = {
5037 .down = service_down,
5038 .lower_up = service_lower_up,
5039 .lower_down = service_lower_down,
5040 .ip_bound = service_ip_bound,
5041 .ip_release = service_ip_release,
5044 static void setup_ip4config(struct connman_service *service, int index,
5045 enum connman_ipconfig_method method)
5050 service->ipconfig_ipv4 = connman_ipconfig_create(index,
5051 CONNMAN_IPCONFIG_TYPE_IPV4);
5052 if (service->ipconfig_ipv4 == NULL)
5055 connman_ipconfig_set_method(service->ipconfig_ipv4, method);
5057 connman_ipconfig_set_data(service->ipconfig_ipv4, service);
5059 connman_ipconfig_set_ops(service->ipconfig_ipv4, &service_ops);
5062 static void setup_ip6config(struct connman_service *service, int index)
5067 service->ipconfig_ipv6 = connman_ipconfig_create(index,
5068 CONNMAN_IPCONFIG_TYPE_IPV6);
5069 if (service->ipconfig_ipv6 == NULL)
5072 connman_ipconfig_set_data(service->ipconfig_ipv6, service);
5074 connman_ipconfig_set_ops(service->ipconfig_ipv6, &service_ops);
5077 void __connman_service_read_ip4config(struct connman_service *service)
5081 if (service->ipconfig_ipv4 == NULL)
5084 keyfile = __connman_storage_load_global();
5085 if (keyfile == NULL)
5088 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
5089 service->identifier, "IPv4.");
5091 g_key_file_free(keyfile);
5094 void __connman_service_create_ip4config(struct connman_service *service,
5097 DBG("ipv4 %p", service->ipconfig_ipv4);
5099 if (service->ipconfig_ipv4 != NULL)
5102 setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_DHCP);
5103 __connman_service_read_ip4config(service);
5106 void __connman_service_read_ip6config(struct connman_service *service)
5110 if (service->ipconfig_ipv6 == NULL)
5113 keyfile = __connman_storage_load_service(service->identifier);
5114 if (keyfile == NULL)
5117 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
5118 service->identifier, "IPv6.");
5120 g_key_file_free(keyfile);
5123 void __connman_service_create_ip6config(struct connman_service *service,
5126 DBG("ipv6 %p", service->ipconfig_ipv6);
5128 if (service->ipconfig_ipv6 != NULL)
5131 setup_ip6config(service, index);
5133 __connman_service_read_ip6config(service);
5137 * __connman_service_lookup_from_network:
5138 * @network: network structure
5140 * Look up a service by network (reference count will not be increased)
5142 struct connman_service *__connman_service_lookup_from_network(struct connman_network *network)
5144 struct connman_service *service;
5145 const char *ident, *group;
5148 DBG("network %p", network);
5150 if (network == NULL)
5153 ident = __connman_network_get_ident(network);
5157 group = connman_network_get_group(network);
5161 name = g_strdup_printf("%s_%s_%s",
5162 __connman_network_get_type(network), ident, group);
5163 service = lookup_by_identifier(name);
5169 struct connman_service *__connman_service_lookup_from_index(int index)
5171 struct connman_service *service;
5172 GSequenceIter *iter;
5174 iter = g_sequence_get_begin_iter(service_list);
5176 while (g_sequence_iter_is_end(iter) == FALSE) {
5177 service = g_sequence_get(iter);
5179 if (connman_ipconfig_get_index(service->ipconfig_ipv4)
5183 if (connman_ipconfig_get_index(service->ipconfig_ipv6)
5187 iter = g_sequence_iter_next(iter);
5193 const char *__connman_service_get_ident(struct connman_service *service)
5195 return service->identifier;
5198 const char *__connman_service_get_path(struct connman_service *service)
5200 return service->path;
5203 unsigned int __connman_service_get_order(struct connman_service *service)
5205 GSequenceIter *iter;
5207 if (service == NULL)
5210 if (service->favorite == FALSE) {
5215 iter = g_hash_table_lookup(service_hash, service->identifier);
5217 if (g_sequence_iter_get_position(iter) == 0)
5219 else if (service->type == CONNMAN_SERVICE_TYPE_VPN)
5220 service->order = 10;
5226 return service->order;
5229 static enum connman_service_type convert_network_type(struct connman_network *network)
5231 enum connman_network_type type = connman_network_get_type(network);
5234 case CONNMAN_NETWORK_TYPE_UNKNOWN:
5235 case CONNMAN_NETWORK_TYPE_VENDOR:
5237 case CONNMAN_NETWORK_TYPE_ETHERNET:
5238 return CONNMAN_SERVICE_TYPE_ETHERNET;
5239 case CONNMAN_NETWORK_TYPE_WIFI:
5240 return CONNMAN_SERVICE_TYPE_WIFI;
5241 case CONNMAN_NETWORK_TYPE_WIMAX:
5242 return CONNMAN_SERVICE_TYPE_WIMAX;
5243 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
5244 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
5245 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
5246 case CONNMAN_NETWORK_TYPE_CELLULAR:
5247 return CONNMAN_SERVICE_TYPE_CELLULAR;
5250 return CONNMAN_SERVICE_TYPE_UNKNOWN;
5253 static enum connman_service_security convert_wifi_security(const char *security)
5255 if (security == NULL)
5256 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
5257 else if (g_str_equal(security, "none") == TRUE)
5258 return CONNMAN_SERVICE_SECURITY_NONE;
5259 else if (g_str_equal(security, "wep") == TRUE)
5260 return CONNMAN_SERVICE_SECURITY_WEP;
5261 else if (g_str_equal(security, "psk") == TRUE)
5262 return CONNMAN_SERVICE_SECURITY_PSK;
5263 else if (g_str_equal(security, "ieee8021x") == TRUE)
5264 return CONNMAN_SERVICE_SECURITY_8021X;
5265 else if (g_str_equal(security, "wpa") == TRUE)
5266 return CONNMAN_SERVICE_SECURITY_WPA;
5267 else if (g_str_equal(security, "rsn") == TRUE)
5268 return CONNMAN_SERVICE_SECURITY_RSN;
5270 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
5273 static void update_from_network(struct connman_service *service,
5274 struct connman_network *network)
5276 connman_uint8_t strength = service->strength;
5277 GSequenceIter *iter;
5280 DBG("service %p network %p", service, network);
5282 if (is_connected(service) == TRUE)
5285 if (is_connecting(service) == TRUE)
5288 str = connman_network_get_string(network, "Name");
5290 g_free(service->name);
5291 service->name = g_strdup(str);
5292 service->hidden = FALSE;
5294 g_free(service->name);
5295 service->name = NULL;
5296 service->hidden = TRUE;
5299 service->strength = connman_network_get_strength(network);
5300 service->roaming = connman_network_get_bool(network, "Roaming");
5302 if (service->strength == 0) {
5304 * Filter out 0-values; it's unclear what they mean
5305 * and they cause anomalous sorting of the priority list.
5307 service->strength = strength;
5310 str = connman_network_get_string(network, "WiFi.Security");
5311 service->security = convert_wifi_security(str);
5313 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
5314 service->wps = connman_network_get_bool(network, "WiFi.WPS");
5316 if (service->strength > strength && service->network != NULL) {
5317 service->network = network;
5319 strength_changed(service);
5322 if (service->network == NULL)
5323 service->network = network;
5325 iter = g_hash_table_lookup(service_hash, service->identifier);
5327 g_sequence_sort_changed(iter, service_compare, NULL);
5331 * __connman_service_create_from_network:
5332 * @network: network structure
5334 * Look up service by network and if not found, create one
5336 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
5338 struct connman_service *service;
5339 struct connman_device *device;
5340 const char *ident, *group;
5344 DBG("network %p", network);
5346 if (network == NULL)
5349 ident = __connman_network_get_ident(network);
5353 group = connman_network_get_group(network);
5357 name = g_strdup_printf("%s_%s_%s",
5358 __connman_network_get_type(network), ident, group);
5359 service = service_get(name);
5362 if (service == NULL)
5365 if (__connman_network_get_weakness(network) == TRUE)
5368 if (service->path != NULL) {
5369 update_from_network(service, network);
5370 services_changed(TRUE);
5374 service->type = convert_network_type(network);
5376 switch (service->type) {
5377 case CONNMAN_SERVICE_TYPE_UNKNOWN:
5378 case CONNMAN_SERVICE_TYPE_SYSTEM:
5379 case CONNMAN_SERVICE_TYPE_ETHERNET:
5380 case CONNMAN_SERVICE_TYPE_WIMAX:
5381 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
5382 case CONNMAN_SERVICE_TYPE_GPS:
5383 case CONNMAN_SERVICE_TYPE_VPN:
5384 case CONNMAN_SERVICE_TYPE_GADGET:
5385 service->autoconnect = FALSE;
5387 case CONNMAN_SERVICE_TYPE_WIFI:
5388 case CONNMAN_SERVICE_TYPE_CELLULAR:
5389 service->autoconnect = TRUE;
5393 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
5394 service->state = combine_state(service->state_ipv4, service->state_ipv6);
5396 update_from_network(service, network);
5398 index = connman_network_get_index(network);
5400 if (service->ipconfig_ipv4 == NULL)
5401 setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_DHCP);
5403 if (service->ipconfig_ipv6 == NULL)
5404 setup_ip6config(service, index);
5406 service_register(service);
5408 if (service->favorite == TRUE) {
5409 device = connman_network_get_device(service->network);
5410 if (device && __connman_device_scanning(device) == FALSE)
5411 __connman_service_auto_connect();
5414 __connman_notifier_service_add(service, service->name);
5419 void __connman_service_update_from_network(struct connman_network *network)
5421 struct connman_service *service;
5422 connman_uint8_t strength;
5423 connman_bool_t roaming;
5424 GSequenceIter *iter;
5426 connman_bool_t stats_enable;
5428 DBG("network %p", network);
5430 service = __connman_service_lookup_from_network(network);
5431 if (service == NULL)
5434 if (service->network == NULL)
5437 name = connman_network_get_string(service->network, "Name");
5438 if (g_strcmp0(service->name, name) != 0) {
5439 g_free(service->name);
5440 service->name = g_strdup(name);
5441 connman_dbus_property_changed_basic(service->path,
5442 CONNMAN_SERVICE_INTERFACE, "Name",
5443 DBUS_TYPE_STRING, &service->name);
5446 if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
5447 service->wps = connman_network_get_bool(network, "WiFi.WPS");
5449 strength = connman_network_get_strength(service->network);
5450 if (strength == service->strength)
5453 service->strength = strength;
5455 strength_changed(service);
5458 roaming = connman_network_get_bool(service->network, "Roaming");
5459 if (roaming == service->roaming)
5462 stats_enable = stats_enabled(service);
5463 if (stats_enable == TRUE)
5464 stats_stop(service);
5466 service->roaming = roaming;
5468 if (stats_enable == TRUE)
5469 stats_start(service);
5471 roaming_changed(service);
5473 iter = g_hash_table_lookup(service_hash, service->identifier);
5475 g_sequence_sort_changed(iter, service_compare, NULL);
5478 void __connman_service_remove_from_network(struct connman_network *network)
5480 struct connman_service *service;
5482 DBG("network %p", network);
5484 service = __connman_service_lookup_from_network(network);
5485 if (service == NULL)
5488 __connman_service_put(service);
5492 * __connman_service_create_from_provider:
5493 * @provider: provider structure
5495 * Look up service by provider and if not found, create one
5497 struct connman_service *
5498 __connman_service_create_from_provider(struct connman_provider *provider)
5500 struct connman_service *service;
5501 const char *ident, *str;
5503 int index = connman_provider_get_index(provider);
5505 DBG("provider %p", provider);
5507 ident = __connman_provider_get_ident(provider);
5511 name = g_strdup_printf("vpn_%s", ident);
5512 service = service_get(name);
5515 if (service == NULL)
5518 service->type = CONNMAN_SERVICE_TYPE_VPN;
5519 service->provider = connman_provider_ref(provider);
5520 service->autoconnect = FALSE;
5521 service->userconnect = TRUE;
5523 service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
5525 str = connman_provider_get_string(provider, "Name");
5527 g_free(service->name);
5528 service->name = g_strdup(str);
5529 service->hidden = FALSE;
5531 g_free(service->name);
5532 service->name = NULL;
5533 service->hidden = TRUE;
5536 service->strength = 0;
5538 if (service->ipconfig_ipv4 == NULL)
5539 setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_MANUAL);
5541 if (service->ipconfig_ipv6 == NULL)
5542 setup_ip6config(service, index);
5544 service_register(service);
5546 __connman_notifier_service_add(service, service->name);
5551 void __connman_service_downgrade_state(struct connman_service *service)
5553 if (service == NULL)
5556 DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
5557 service->state_ipv6);
5559 if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
5560 __connman_service_ipconfig_indicate_state(service,
5561 CONNMAN_SERVICE_STATE_READY,
5562 CONNMAN_IPCONFIG_TYPE_IPV4);
5564 if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
5565 __connman_service_ipconfig_indicate_state(service,
5566 CONNMAN_SERVICE_STATE_READY,
5567 CONNMAN_IPCONFIG_TYPE_IPV6);
5570 int __connman_service_init(void)
5574 connection = connman_dbus_get_connection();
5576 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
5579 service_list = g_sequence_new(service_free);
5584 void __connman_service_cleanup(void)
5590 list = service_list;
5591 service_list = NULL;
5592 g_sequence_free(list);
5594 g_hash_table_destroy(service_hash);
5595 service_hash = NULL;
5597 g_slist_free(counter_list);
5598 counter_list = NULL;
5600 dbus_connection_unref(connection);