5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #define CONNECT_TIMEOUT 120
34 static DBusConnection *connection = NULL;
36 static GSequence *service_list = NULL;
37 static GHashTable *service_hash = NULL;
38 static GSList *counter_list = NULL;
40 struct connman_stats {
42 connman_bool_t enabled;
43 struct connman_stats_data data_last;
44 struct connman_stats_data data;
48 struct connman_stats_counter {
49 connman_bool_t append_all;
50 struct connman_stats stats;
51 struct connman_stats stats_roaming;
54 struct connman_service {
58 enum connman_service_type type;
59 enum connman_service_mode mode;
60 enum connman_service_security security;
61 enum connman_service_state state;
62 enum connman_service_error error;
63 connman_uint8_t strength;
64 connman_bool_t favorite;
65 connman_bool_t immutable;
66 connman_bool_t hidden;
67 connman_bool_t ignore;
68 connman_bool_t autoconnect;
69 connman_bool_t userconnect;
80 connman_bool_t roaming;
81 connman_bool_t login_required;
82 struct connman_ipconfig *ipconfig;
83 struct connman_network *network;
84 struct connman_provider *provider;
89 /* 802.1x settings from the config files */
93 char *client_cert_file;
94 char *private_key_file;
95 char *private_key_passphrase;
99 struct connman_location *location;
100 struct connman_stats stats;
101 struct connman_stats stats_roaming;
102 GHashTable *counter_table;
103 enum connman_service_proxy_method proxy;
109 static void append_path(gpointer value, gpointer user_data)
111 struct connman_service *service = value;
112 DBusMessageIter *iter = user_data;
114 if (service->path == NULL || service->hidden == TRUE)
117 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
121 void __connman_service_list(DBusMessageIter *iter, void *user_data)
123 g_sequence_foreach(service_list, append_path, iter);
128 struct connman_service *service;
131 static void compare_path(gpointer value, gpointer user_data)
133 struct connman_service *service = value;
134 struct find_data *data = user_data;
136 if (data->service != NULL)
139 if (g_strcmp0(service->path, data->path) == 0)
140 data->service = service;
143 static struct connman_service *find_service(const char *path)
145 struct find_data data = { .path = path, .service = NULL };
147 DBG("path %s", path);
149 g_sequence_foreach(service_list, compare_path, &data);
154 const char *__connman_service_type2string(enum connman_service_type type)
157 case CONNMAN_SERVICE_TYPE_UNKNOWN:
159 case CONNMAN_SERVICE_TYPE_SYSTEM:
161 case CONNMAN_SERVICE_TYPE_ETHERNET:
163 case CONNMAN_SERVICE_TYPE_WIFI:
165 case CONNMAN_SERVICE_TYPE_WIMAX:
167 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
169 case CONNMAN_SERVICE_TYPE_CELLULAR:
171 case CONNMAN_SERVICE_TYPE_GPS:
173 case CONNMAN_SERVICE_TYPE_VPN:
175 case CONNMAN_SERVICE_TYPE_GADGET:
182 static const char *mode2string(enum connman_service_mode mode)
185 case CONNMAN_SERVICE_MODE_UNKNOWN:
187 case CONNMAN_SERVICE_MODE_MANAGED:
189 case CONNMAN_SERVICE_MODE_ADHOC:
191 case CONNMAN_SERVICE_MODE_GPRS:
193 case CONNMAN_SERVICE_MODE_EDGE:
195 case CONNMAN_SERVICE_MODE_UMTS:
202 static const char *security2string(enum connman_service_security security)
205 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
207 case CONNMAN_SERVICE_SECURITY_NONE:
209 case CONNMAN_SERVICE_SECURITY_WEP:
211 case CONNMAN_SERVICE_SECURITY_PSK:
213 case CONNMAN_SERVICE_SECURITY_8021X:
215 case CONNMAN_SERVICE_SECURITY_WPA:
217 case CONNMAN_SERVICE_SECURITY_RSN:
224 static const char *state2string(enum connman_service_state state)
227 case CONNMAN_SERVICE_STATE_UNKNOWN:
229 case CONNMAN_SERVICE_STATE_IDLE:
231 case CONNMAN_SERVICE_STATE_ASSOCIATION:
232 return "association";
233 case CONNMAN_SERVICE_STATE_CONFIGURATION:
234 return "configuration";
235 case CONNMAN_SERVICE_STATE_READY:
237 case CONNMAN_SERVICE_STATE_ONLINE:
239 case CONNMAN_SERVICE_STATE_DISCONNECT:
241 case CONNMAN_SERVICE_STATE_FAILURE:
248 static const char *error2string(enum connman_service_error error)
251 case CONNMAN_SERVICE_ERROR_UNKNOWN:
253 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
254 return "out-of-range";
255 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
256 return "pin-missing";
257 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
258 return "dhcp-failed";
259 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
260 return "connect-failed";
266 static enum connman_service_error string2error(const char *error)
268 if (g_strcmp0(error, "dhcp-failed") == 0)
269 return CONNMAN_SERVICE_ERROR_DHCP_FAILED;
270 else if (g_strcmp0(error, "pin-missing") == 0)
271 return CONNMAN_SERVICE_ERROR_PIN_MISSING;
273 return CONNMAN_SERVICE_ERROR_UNKNOWN;
276 static const char *proxymethod2string(enum connman_service_proxy_method method)
279 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
281 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
283 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
285 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
292 static enum connman_service_proxy_method string2proxymethod(const char *method)
294 if (g_strcmp0(method, "direct") == 0)
295 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
296 else if (g_strcmp0(method, "auto") == 0)
297 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
298 else if (g_strcmp0(method, "manual") == 0)
299 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
301 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
304 static connman_bool_t is_connecting(struct connman_service *service)
306 switch (service->state) {
307 case CONNMAN_SERVICE_STATE_UNKNOWN:
308 case CONNMAN_SERVICE_STATE_IDLE:
309 case CONNMAN_SERVICE_STATE_FAILURE:
310 case CONNMAN_SERVICE_STATE_DISCONNECT:
311 case CONNMAN_SERVICE_STATE_READY:
312 case CONNMAN_SERVICE_STATE_ONLINE:
314 case CONNMAN_SERVICE_STATE_ASSOCIATION:
315 case CONNMAN_SERVICE_STATE_CONFIGURATION:
322 static connman_bool_t is_connected(const struct connman_service *service)
324 switch (service->state) {
325 case CONNMAN_SERVICE_STATE_UNKNOWN:
326 case CONNMAN_SERVICE_STATE_IDLE:
327 case CONNMAN_SERVICE_STATE_ASSOCIATION:
328 case CONNMAN_SERVICE_STATE_CONFIGURATION:
329 case CONNMAN_SERVICE_STATE_DISCONNECT:
330 case CONNMAN_SERVICE_STATE_FAILURE:
332 case CONNMAN_SERVICE_STATE_READY:
333 case CONNMAN_SERVICE_STATE_ONLINE:
340 static void update_nameservers(struct connman_service *service)
342 const char *ifname = connman_ipconfig_get_ifname(service->ipconfig);
347 switch (service->state) {
348 case CONNMAN_SERVICE_STATE_UNKNOWN:
349 case CONNMAN_SERVICE_STATE_IDLE:
350 case CONNMAN_SERVICE_STATE_ASSOCIATION:
351 case CONNMAN_SERVICE_STATE_CONFIGURATION:
353 case CONNMAN_SERVICE_STATE_FAILURE:
354 case CONNMAN_SERVICE_STATE_DISCONNECT:
355 connman_resolver_remove_all(ifname);
357 case CONNMAN_SERVICE_STATE_READY:
358 case CONNMAN_SERVICE_STATE_ONLINE:
362 connman_resolver_remove_all(ifname);
364 if (service->nameservers != NULL) {
367 for (i = 0; service->nameservers[i]; i++)
368 connman_resolver_append(ifname, NULL,
369 service->nameservers[i]);
370 } else if (service->nameserver != NULL)
371 connman_resolver_append(ifname, NULL, service->nameserver);
373 if (service->domains != NULL) {
376 for (i = 0; service->domains[i]; i++)
377 connman_resolver_append(ifname, service->domains[i],
379 } else if (service->domainname != NULL)
380 connman_resolver_append(ifname, service->domainname, NULL);
382 connman_resolver_flush();
385 void __connman_service_append_nameserver(struct connman_service *service,
386 const char *nameserver)
388 DBG("service %p nameserver %s", service, nameserver);
390 if (nameserver == NULL)
393 g_free(service->nameserver);
394 service->nameserver = g_strdup(nameserver);
396 update_nameservers(service);
399 void __connman_service_remove_nameserver(struct connman_service *service,
400 const char *nameserver)
402 DBG("service %p nameserver %s", service, nameserver);
404 if (nameserver == NULL)
407 g_free(service->nameserver);
408 service->nameserver = NULL;
410 update_nameservers(service);
413 void __connman_service_nameserver_add_routes(struct connman_service *service,
421 index = connman_network_get_index(service->network);
423 if (service->nameservers != NULL) {
427 * We add nameservers host routes for nameservers that
428 * are not on our subnet. For those who are, the subnet
429 * route will be installed by the time the dns proxy code
430 * tries to reach them. The subnet route is installed
431 * when setting the interface IP address.
433 for (i = 0; service->nameservers[i]; i++) {
434 if (connman_inet_compare_subnet(index,
435 service->nameservers[i]))
438 connman_inet_add_host_route(index,
439 service->nameservers[i], gw);
441 } else if (service->nameserver != NULL) {
442 if (connman_inet_compare_subnet(index, service->nameserver))
445 connman_inet_add_host_route(index, service->nameserver, gw);
449 void __connman_service_nameserver_del_routes(struct connman_service *service)
456 index = connman_network_get_index(service->network);
458 if (service->nameservers != NULL) {
461 for (i = 0; service->nameservers[i]; i++)
462 connman_inet_del_host_route(index,
463 service->nameservers[i]);
464 } else if (service->nameserver != NULL) {
465 connman_inet_del_host_route(index, service->nameserver);
469 static struct connman_stats *stats_get(struct connman_service *service)
471 if (service->roaming == TRUE)
472 return &service->stats_roaming;
474 return &service->stats;
477 static connman_bool_t stats_enabled(struct connman_service *service)
479 struct connman_stats *stats = stats_get(service);
481 return stats->enabled;
484 static void stats_start(struct connman_service *service)
486 struct connman_stats *stats = stats_get(service);
488 DBG("service %p", service);
490 if (stats->timer == NULL)
493 stats->enabled = TRUE;
494 stats->data_last.time = stats->data.time;
496 g_timer_start(stats->timer);
499 static void stats_stop(struct connman_service *service)
501 struct connman_stats *stats = stats_get(service);
502 unsigned int seconds;
504 DBG("service %p", service);
506 if (stats->timer == NULL)
509 if (stats->enabled == FALSE)
512 g_timer_stop(stats->timer);
514 seconds = g_timer_elapsed(stats->timer, NULL);
515 stats->data.time = stats->data_last.time + seconds;
517 stats->enabled = FALSE;
520 static void reset_stats(struct connman_service *service)
522 DBG("service %p", service);
525 service->stats.valid = FALSE;
527 service->stats.data.rx_packets = 0;
528 service->stats.data.tx_packets = 0;
529 service->stats.data.rx_bytes = 0;
530 service->stats.data.tx_bytes = 0;
531 service->stats.data.rx_errors = 0;
532 service->stats.data.tx_errors = 0;
533 service->stats.data.rx_dropped = 0;
534 service->stats.data.tx_dropped = 0;
535 service->stats.data.time = 0;
536 service->stats.data_last.time = 0;
538 g_timer_reset(service->stats.timer);
541 service->stats_roaming.valid = FALSE;
543 service->stats_roaming.data.rx_packets = 0;
544 service->stats_roaming.data.tx_packets = 0;
545 service->stats_roaming.data.rx_bytes = 0;
546 service->stats_roaming.data.tx_bytes = 0;
547 service->stats_roaming.data.rx_errors = 0;
548 service->stats_roaming.data.tx_errors = 0;
549 service->stats_roaming.data.rx_dropped = 0;
550 service->stats_roaming.data.tx_dropped = 0;
551 service->stats_roaming.data.time = 0;
552 service->stats_roaming.data_last.time = 0;
554 g_timer_reset(service->stats_roaming.timer);
557 static struct connman_service *get_default(void)
559 struct connman_service *service;
562 iter = g_sequence_get_begin_iter(service_list);
564 if (g_sequence_iter_is_end(iter) == TRUE)
567 service = g_sequence_get(iter);
569 if (is_connected(service) == FALSE)
575 static void default_changed(void)
577 struct connman_service *service = get_default();
579 __connman_notifier_default_changed(service);
582 const char *__connman_service_default(void)
584 struct connman_service *service;
586 service = get_default();
590 return __connman_service_type2string(service->type);
593 static void mode_changed(struct connman_service *service)
597 str = mode2string(service->mode);
601 connman_dbus_property_changed_basic(service->path,
602 CONNMAN_SERVICE_INTERFACE, "Mode",
603 DBUS_TYPE_STRING, &str);
606 static void state_changed(struct connman_service *service)
610 str = state2string(service->state);
614 connman_dbus_property_changed_basic(service->path,
615 CONNMAN_SERVICE_INTERFACE, "State",
616 DBUS_TYPE_STRING, &str);
619 static void strength_changed(struct connman_service *service)
621 if (service->strength == 0)
624 connman_dbus_property_changed_basic(service->path,
625 CONNMAN_SERVICE_INTERFACE, "Strength",
626 DBUS_TYPE_BYTE, &service->strength);
629 static void favorite_changed(struct connman_service *service)
631 if (service->path == NULL)
634 connman_dbus_property_changed_basic(service->path,
635 CONNMAN_SERVICE_INTERFACE, "Favorite",
636 DBUS_TYPE_BOOLEAN, &service->favorite);
639 static void immutable_changed(struct connman_service *service)
641 if (service->path == NULL)
644 connman_dbus_property_changed_basic(service->path,
645 CONNMAN_SERVICE_INTERFACE, "Immutable",
646 DBUS_TYPE_BOOLEAN, &service->immutable);
649 static void roaming_changed(struct connman_service *service)
651 if (service->path == NULL)
654 connman_dbus_property_changed_basic(service->path,
655 CONNMAN_SERVICE_INTERFACE, "Roaming",
656 DBUS_TYPE_BOOLEAN, &service->roaming);
659 static void autoconnect_changed(struct connman_service *service)
661 if (service->path == NULL)
664 connman_dbus_property_changed_basic(service->path,
665 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
666 DBUS_TYPE_BOOLEAN, &service->autoconnect);
669 static void passphrase_changed(struct connman_service *service)
671 dbus_bool_t required;
673 switch (service->type) {
674 case CONNMAN_SERVICE_TYPE_UNKNOWN:
675 case CONNMAN_SERVICE_TYPE_SYSTEM:
676 case CONNMAN_SERVICE_TYPE_ETHERNET:
677 case CONNMAN_SERVICE_TYPE_WIMAX:
678 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
679 case CONNMAN_SERVICE_TYPE_CELLULAR:
680 case CONNMAN_SERVICE_TYPE_GPS:
681 case CONNMAN_SERVICE_TYPE_VPN:
682 case CONNMAN_SERVICE_TYPE_GADGET:
684 case CONNMAN_SERVICE_TYPE_WIFI:
687 switch (service->security) {
688 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
689 case CONNMAN_SERVICE_SECURITY_NONE:
691 case CONNMAN_SERVICE_SECURITY_WEP:
692 case CONNMAN_SERVICE_SECURITY_PSK:
693 case CONNMAN_SERVICE_SECURITY_WPA:
694 case CONNMAN_SERVICE_SECURITY_RSN:
695 if (service->passphrase == NULL)
698 case CONNMAN_SERVICE_SECURITY_8021X:
704 connman_dbus_property_changed_basic(service->path,
705 CONNMAN_SERVICE_INTERFACE, "PassphraseRequired",
706 DBUS_TYPE_BOOLEAN, &required);
709 static void login_changed(struct connman_service *service)
711 dbus_bool_t required = service->login_required;
713 if (service->path == NULL)
716 connman_dbus_property_changed_basic(service->path,
717 CONNMAN_SERVICE_INTERFACE, "LoginRequired",
718 DBUS_TYPE_BOOLEAN, &required);
721 static void apn_changed(struct connman_service *service)
723 dbus_bool_t required;
725 switch (service->type) {
726 case CONNMAN_SERVICE_TYPE_UNKNOWN:
727 case CONNMAN_SERVICE_TYPE_SYSTEM:
728 case CONNMAN_SERVICE_TYPE_ETHERNET:
729 case CONNMAN_SERVICE_TYPE_WIMAX:
730 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
731 case CONNMAN_SERVICE_TYPE_WIFI:
732 case CONNMAN_SERVICE_TYPE_GPS:
733 case CONNMAN_SERVICE_TYPE_VPN:
734 case CONNMAN_SERVICE_TYPE_GADGET:
736 case CONNMAN_SERVICE_TYPE_CELLULAR:
740 required = (service->apn == NULL) ? TRUE : FALSE;
742 connman_dbus_property_changed_basic(service->path,
743 CONNMAN_SERVICE_INTERFACE, "SetupRequired",
744 DBUS_TYPE_BOOLEAN, &required);
747 static void append_ethernet(DBusMessageIter *iter, void *user_data)
749 struct connman_service *service = user_data;
751 if (service->ipconfig != NULL)
752 __connman_ipconfig_append_ethernet(service->ipconfig, iter);
755 static void append_ipv4(DBusMessageIter *iter, void *user_data)
757 struct connman_service *service = user_data;
759 if (is_connected(service) == FALSE)
762 if (service->ipconfig != NULL)
763 __connman_ipconfig_append_ipv4(service->ipconfig, iter);
766 static void append_ipv6(DBusMessageIter *iter, void *user_data)
768 struct connman_service *service = user_data;
769 struct connman_ipconfig *ipv6config;
771 if (is_connected(service) == FALSE)
774 if (service->ipconfig == NULL)
777 ipv6config = connman_ipconfig_get_ipv6config(service->ipconfig);
778 if (ipv6config == NULL)
781 __connman_ipconfig_append_ipv6(ipv6config, iter);
784 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
786 struct connman_service *service = user_data;
788 if (service->ipconfig != NULL)
789 __connman_ipconfig_append_ipv4config(service->ipconfig, iter);
792 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
794 struct connman_service *service = user_data;
795 struct connman_ipconfig *ipv6config;
797 if (service->ipconfig == NULL)
800 ipv6config = connman_ipconfig_get_ipv6config(service->ipconfig);
801 if (ipv6config == NULL)
804 __connman_ipconfig_append_ipv6config(ipv6config, iter);
807 static void append_dns(DBusMessageIter *iter, void *user_data)
809 struct connman_service *service = user_data;
811 if (is_connected(service) == FALSE)
814 if (service->nameservers != NULL) {
817 for (i = 0; service->nameservers[i]; i++)
818 dbus_message_iter_append_basic(iter,
819 DBUS_TYPE_STRING, &service->nameservers[i]);
824 if (service->nameserver == NULL)
827 dbus_message_iter_append_basic(iter,
828 DBUS_TYPE_STRING, &service->nameserver);
831 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
833 struct connman_service *service = user_data;
836 if (service->nameservers == NULL)
839 for (i = 0; service->nameservers[i]; i++)
840 dbus_message_iter_append_basic(iter,
841 DBUS_TYPE_STRING, &service->nameservers[i]);
844 static void append_domain(DBusMessageIter *iter, void *user_data)
846 struct connman_service *service = user_data;
848 if (is_connected(service) == FALSE && is_connecting(service) == FALSE)
851 if (service->domainname == NULL)
854 dbus_message_iter_append_basic(iter,
855 DBUS_TYPE_STRING, &service->domainname);
858 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
860 struct connman_service *service = user_data;
863 if (service->domains == NULL)
866 for (i = 0; service->domains[i]; i++)
867 dbus_message_iter_append_basic(iter,
868 DBUS_TYPE_STRING, &service->domains[i]);
871 static void append_proxies(DBusMessageIter *iter, void *user_data)
873 struct connman_service *service = user_data;
876 if (service->proxies == NULL)
879 for (i = 0; service->proxies[i]; i++)
880 dbus_message_iter_append_basic(iter,
881 DBUS_TYPE_STRING, &service->proxies[i]);
884 static void append_excludes(DBusMessageIter *iter, void *user_data)
886 struct connman_service *service = user_data;
889 if (service->excludes == NULL)
892 for (i = 0; service->excludes[i]; i++)
893 dbus_message_iter_append_basic(iter,
894 DBUS_TYPE_STRING, &service->excludes[i]);
897 static void append_proxy(DBusMessageIter *iter, void *user_data)
899 struct connman_service *service = user_data;
900 const char *pac = NULL;
901 const char *method = proxymethod2string(
902 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
906 if (is_connected(service) == FALSE)
909 switch (service->proxy) {
910 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
911 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
913 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
915 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
916 connman_dbus_dict_append_array(iter, "Servers",
917 DBUS_TYPE_STRING, append_proxies,
920 connman_dbus_dict_append_array(iter, "Excludes",
921 DBUS_TYPE_STRING, append_excludes,
924 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
925 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
926 if (service->ipconfig != NULL)
927 pac = __connman_ipconfig_get_proxy_autoconfig(
930 if (service->pac == NULL && pac == NULL)
933 if (service->pac != NULL)
936 connman_dbus_dict_append_basic(iter, "URL",
937 DBUS_TYPE_STRING, &pac);
941 method = proxymethod2string(service->proxy);
944 connman_dbus_dict_append_basic(iter, "Method",
945 DBUS_TYPE_STRING, &method);
948 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
950 struct connman_service *service = user_data;
953 switch (service->proxy) {
954 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
956 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
957 if (service->proxies != NULL)
958 connman_dbus_dict_append_array(iter, "Servers",
960 append_proxies, service);
962 if (service->excludes != NULL)
963 connman_dbus_dict_append_array(iter, "Excludes",
965 append_excludes, service);
967 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
968 if (service->pac != NULL)
969 connman_dbus_dict_append_basic(iter, "URL",
970 DBUS_TYPE_STRING, &service->pac);
972 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
973 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
977 method = proxymethod2string(service->proxy);
979 connman_dbus_dict_append_basic(iter, "Method",
980 DBUS_TYPE_STRING, &method);
983 static void append_provider(DBusMessageIter *iter, void *user_data)
985 struct connman_service *service = user_data;
987 DBG("%p %p", service, service->provider);
989 if (is_connected(service) == FALSE)
992 if (service->provider != NULL)
993 __connman_provider_append_properties(service->provider, iter);
997 static void settings_changed(struct connman_service *service)
999 connman_dbus_property_changed_dict(service->path,
1000 CONNMAN_SERVICE_INTERFACE, "IPv4",
1001 append_ipv4, service);
1003 connman_dbus_property_changed_dict(service->path,
1004 CONNMAN_SERVICE_INTERFACE, "IPv6",
1005 append_ipv6, service);
1008 static void ipv4_configuration_changed(struct connman_service *service)
1010 connman_dbus_property_changed_dict(service->path,
1011 CONNMAN_SERVICE_INTERFACE,
1012 "IPv4.Configuration",
1017 static void ipv6_configuration_changed(struct connman_service *service)
1019 connman_dbus_property_changed_dict(service->path,
1020 CONNMAN_SERVICE_INTERFACE,
1021 "IPv6.Configuration",
1026 static void dns_changed(struct connman_service *service)
1028 connman_dbus_property_changed_array(service->path,
1029 CONNMAN_SERVICE_INTERFACE, "Nameservers",
1030 DBUS_TYPE_STRING, append_dns, service);
1033 static void dns_configuration_changed(struct connman_service *service)
1035 connman_dbus_property_changed_array(service->path,
1036 CONNMAN_SERVICE_INTERFACE,
1037 "Nameservers.Configuration",
1038 DBUS_TYPE_STRING, append_dnsconfig, service);
1040 dns_changed(service);
1043 static void domain_changed(struct connman_service *service)
1045 connman_dbus_property_changed_array(service->path,
1046 CONNMAN_SERVICE_INTERFACE, "Domains",
1047 DBUS_TYPE_STRING, append_domain, service);
1050 static void domain_configuration_changed(struct connman_service *service)
1052 connman_dbus_property_changed_array(service->path,
1053 CONNMAN_SERVICE_INTERFACE,
1054 "Domains.Configuration",
1055 DBUS_TYPE_STRING, append_domainconfig, service);
1058 static void proxy_changed(struct connman_service *service)
1060 connman_dbus_property_changed_dict(service->path,
1061 CONNMAN_SERVICE_INTERFACE, "Proxy",
1062 append_proxy, service);
1065 static void proxy_configuration_changed(struct connman_service *service)
1067 connman_dbus_property_changed_dict(service->path,
1068 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
1069 append_proxyconfig, service);
1071 proxy_changed(service);
1074 static void link_changed(struct connman_service *service)
1076 connman_dbus_property_changed_dict(service->path,
1077 CONNMAN_SERVICE_INTERFACE, "Ethernet",
1078 append_ethernet, service);
1081 static void stats_append_counters(DBusMessageIter *dict,
1082 struct connman_stats_data *stats,
1083 struct connman_stats_data *counters,
1084 connman_bool_t append_all)
1086 if (counters->rx_packets != stats->rx_packets || append_all) {
1087 counters->rx_packets = stats->rx_packets;
1088 connman_dbus_dict_append_basic(dict, "RX.Packets",
1089 DBUS_TYPE_UINT32, &stats->rx_packets);
1092 if (counters->tx_packets != stats->tx_packets || append_all) {
1093 counters->tx_packets = stats->tx_packets;
1094 connman_dbus_dict_append_basic(dict, "TX.Packets",
1095 DBUS_TYPE_UINT32, &stats->tx_packets);
1098 if (counters->rx_bytes != stats->rx_bytes || append_all) {
1099 counters->rx_bytes = stats->rx_bytes;
1100 connman_dbus_dict_append_basic(dict, "RX.Bytes",
1101 DBUS_TYPE_UINT32, &stats->rx_bytes);
1104 if (counters->tx_bytes != stats->tx_bytes || append_all) {
1105 counters->tx_bytes = stats->tx_bytes;
1106 connman_dbus_dict_append_basic(dict, "TX.Bytes",
1107 DBUS_TYPE_UINT32, &stats->tx_bytes);
1110 if (counters->rx_errors != stats->rx_errors || append_all) {
1111 counters->rx_errors = stats->rx_errors;
1112 connman_dbus_dict_append_basic(dict, "RX.Errors",
1113 DBUS_TYPE_UINT32, &stats->rx_errors);
1116 if (counters->tx_errors != stats->tx_errors || append_all) {
1117 counters->tx_errors = stats->tx_errors;
1118 connman_dbus_dict_append_basic(dict, "TX.Errors",
1119 DBUS_TYPE_UINT32, &stats->tx_errors);
1122 if (counters->rx_dropped != stats->rx_dropped || append_all) {
1123 counters->rx_dropped = stats->rx_dropped;
1124 connman_dbus_dict_append_basic(dict, "RX.Dropped",
1125 DBUS_TYPE_UINT32, &stats->rx_dropped);
1128 if (counters->tx_dropped != stats->tx_dropped || append_all) {
1129 counters->tx_dropped = stats->tx_dropped;
1130 connman_dbus_dict_append_basic(dict, "TX.Dropped",
1131 DBUS_TYPE_UINT32, &stats->tx_dropped);
1134 if (counters->time != stats->time || append_all) {
1135 counters->time = stats->time;
1136 connman_dbus_dict_append_basic(dict, "Time",
1137 DBUS_TYPE_UINT32, &stats->time);
1141 static void stats_append(struct connman_service *service,
1142 const char *counter,
1143 struct connman_stats_counter *counters,
1144 connman_bool_t append_all)
1146 DBusMessageIter array, dict;
1149 DBG("service %p counter %s", service, counter);
1151 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
1155 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
1156 &service->path, DBUS_TYPE_INVALID);
1158 dbus_message_iter_init_append(msg, &array);
1161 connman_dbus_dict_open(&array, &dict);
1163 stats_append_counters(&dict, &service->stats.data,
1164 &counters->stats.data, append_all);
1166 connman_dbus_dict_close(&array, &dict);
1168 /* roaming counter */
1169 connman_dbus_dict_open(&array, &dict);
1171 stats_append_counters(&dict, &service->stats_roaming.data,
1172 &counters->stats_roaming.data, append_all);
1174 connman_dbus_dict_close(&array, &dict);
1176 __connman_counter_send_usage(counter, msg);
1179 static void stats_update(struct connman_service *service,
1180 unsigned int rx_packets, unsigned int tx_packets,
1181 unsigned int rx_bytes, unsigned int tx_bytes,
1182 unsigned int rx_errors, unsigned int tx_errors,
1183 unsigned int rx_dropped, unsigned int tx_dropped)
1185 struct connman_stats *stats = stats_get(service);
1186 struct connman_stats_data *data_last = &stats->data_last;
1187 struct connman_stats_data *data = &stats->data;
1188 unsigned int seconds;
1190 DBG("service %p", service);
1192 if (stats->valid == TRUE) {
1194 rx_packets - data_last->rx_packets;
1196 tx_packets - data_last->tx_packets;
1198 rx_bytes - data_last->rx_bytes;
1200 tx_bytes - data_last->tx_bytes;
1202 rx_errors - data_last->rx_errors;
1204 tx_errors - data_last->tx_errors;
1206 rx_dropped - data_last->rx_dropped;
1208 tx_dropped - data_last->tx_dropped;
1210 stats->valid = TRUE;
1213 data_last->rx_packets = rx_packets;
1214 data_last->tx_packets = tx_packets;
1215 data_last->rx_bytes = rx_bytes;
1216 data_last->tx_bytes = tx_bytes;
1217 data_last->rx_errors = rx_errors;
1218 data_last->tx_errors = tx_errors;
1219 data_last->rx_dropped = rx_dropped;
1220 data_last->tx_dropped = tx_dropped;
1222 seconds = g_timer_elapsed(stats->timer, NULL);
1223 stats->data.time = stats->data_last.time + seconds;
1226 void __connman_service_notify(struct connman_service *service,
1227 unsigned int rx_packets, unsigned int tx_packets,
1228 unsigned int rx_bytes, unsigned int tx_bytes,
1229 unsigned int rx_errors, unsigned int tx_errors,
1230 unsigned int rx_dropped, unsigned int tx_dropped)
1232 GHashTableIter iter;
1233 gpointer key, value;
1234 const char *counter;
1235 struct connman_stats_counter *counters;
1236 struct connman_stats_data *data;
1239 if (service == NULL)
1242 if (is_connected(service) == FALSE)
1245 stats_update(service,
1246 rx_packets, tx_packets,
1248 rx_errors, tx_errors,
1249 rx_dropped, tx_dropped);
1251 data = &stats_get(service)->data;
1252 err = __connman_stats_update(service, service->roaming, data);
1254 connman_error("Failed to store statistics for %s",
1255 service->identifier);
1257 g_hash_table_iter_init(&iter, service->counter_table);
1258 while (g_hash_table_iter_next(&iter, &key, &value)) {
1262 stats_append(service, counter, counters, counters->append_all);
1263 counters->append_all = FALSE;
1267 int __connman_service_counter_register(const char *counter)
1269 struct connman_service *service;
1270 GSequenceIter *iter;
1271 struct connman_stats_counter *counters;
1273 DBG("counter %s", counter);
1275 counter_list = g_slist_append(counter_list, (gpointer)counter);
1277 iter = g_sequence_get_begin_iter(service_list);
1279 while (g_sequence_iter_is_end(iter) == FALSE) {
1280 service = g_sequence_get(iter);
1282 counters = g_try_new0(struct connman_stats_counter, 1);
1283 if (counters == NULL)
1286 counters->append_all = TRUE;
1288 g_hash_table_replace(service->counter_table, (gpointer)counter,
1291 iter = g_sequence_iter_next(iter);
1297 void __connman_service_counter_unregister(const char *counter)
1299 struct connman_service *service;
1300 GSequenceIter *iter;
1302 DBG("counter %s", counter);
1304 iter = g_sequence_get_begin_iter(service_list);
1306 while (g_sequence_iter_is_end(iter) == FALSE) {
1307 service = g_sequence_get(iter);
1309 g_hash_table_remove(service->counter_table, counter);
1311 iter = g_sequence_iter_next(iter);
1314 counter_list = g_slist_remove(counter_list, counter);
1317 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
1318 struct connman_service *service)
1320 dbus_bool_t required;
1323 str = __connman_service_type2string(service->type);
1325 connman_dbus_dict_append_basic(dict, "Type",
1326 DBUS_TYPE_STRING, &str);
1328 str = mode2string(service->mode);
1330 connman_dbus_dict_append_basic(dict, "Mode",
1331 DBUS_TYPE_STRING, &str);
1333 str = security2string(service->security);
1335 connman_dbus_dict_append_basic(dict, "Security",
1336 DBUS_TYPE_STRING, &str);
1338 str = state2string(service->state);
1340 connman_dbus_dict_append_basic(dict, "State",
1341 DBUS_TYPE_STRING, &str);
1343 str = error2string(service->error);
1345 connman_dbus_dict_append_basic(dict, "Error",
1346 DBUS_TYPE_STRING, &str);
1348 if (service->strength > 0)
1349 connman_dbus_dict_append_basic(dict, "Strength",
1350 DBUS_TYPE_BYTE, &service->strength);
1352 connman_dbus_dict_append_basic(dict, "Favorite",
1353 DBUS_TYPE_BOOLEAN, &service->favorite);
1355 connman_dbus_dict_append_basic(dict, "Immutable",
1356 DBUS_TYPE_BOOLEAN, &service->immutable);
1358 if (service->favorite == TRUE)
1359 connman_dbus_dict_append_basic(dict, "AutoConnect",
1360 DBUS_TYPE_BOOLEAN, &service->autoconnect);
1362 connman_dbus_dict_append_basic(dict, "AutoConnect",
1363 DBUS_TYPE_BOOLEAN, &service->favorite);
1365 if (service->name != NULL)
1366 connman_dbus_dict_append_basic(dict, "Name",
1367 DBUS_TYPE_STRING, &service->name);
1369 connman_dbus_dict_append_basic(dict, "LoginRequired",
1370 DBUS_TYPE_BOOLEAN, &service->login_required);
1372 switch (service->type) {
1373 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1374 case CONNMAN_SERVICE_TYPE_SYSTEM:
1375 case CONNMAN_SERVICE_TYPE_GPS:
1376 case CONNMAN_SERVICE_TYPE_VPN:
1377 case CONNMAN_SERVICE_TYPE_GADGET:
1379 case CONNMAN_SERVICE_TYPE_CELLULAR:
1380 connman_dbus_dict_append_basic(dict, "Roaming",
1381 DBUS_TYPE_BOOLEAN, &service->roaming);
1383 if (service->mcc != NULL && service->mnc != NULL) {
1384 connman_dbus_dict_append_basic(dict, "MCC",
1385 DBUS_TYPE_STRING, &service->mcc);
1386 connman_dbus_dict_append_basic(dict, "MNC",
1387 DBUS_TYPE_STRING, &service->mnc);
1390 if (service->apn != NULL) {
1391 connman_dbus_dict_append_basic(dict, "APN",
1392 DBUS_TYPE_STRING, &service->apn);
1394 if (service->username != NULL)
1395 connman_dbus_dict_append_basic(dict,
1396 "Username", DBUS_TYPE_STRING,
1397 &service->username);
1399 if (service->password != NULL)
1400 connman_dbus_dict_append_basic(dict,
1401 "Password", DBUS_TYPE_STRING,
1402 &service->password);
1408 connman_dbus_dict_append_basic(dict, "SetupRequired",
1409 DBUS_TYPE_BOOLEAN, &required);
1410 connman_dbus_dict_append_dict(dict, "Ethernet",
1411 append_ethernet, service);
1413 case CONNMAN_SERVICE_TYPE_WIFI:
1414 if (service->passphrase != NULL && limited == FALSE)
1415 connman_dbus_dict_append_basic(dict, "Passphrase",
1416 DBUS_TYPE_STRING, &service->passphrase);
1420 switch (service->security) {
1421 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1422 case CONNMAN_SERVICE_SECURITY_NONE:
1424 case CONNMAN_SERVICE_SECURITY_WEP:
1425 case CONNMAN_SERVICE_SECURITY_PSK:
1426 case CONNMAN_SERVICE_SECURITY_WPA:
1427 case CONNMAN_SERVICE_SECURITY_RSN:
1428 if (service->passphrase == NULL)
1431 case CONNMAN_SERVICE_SECURITY_8021X:
1435 connman_dbus_dict_append_basic(dict, "PassphraseRequired",
1436 DBUS_TYPE_BOOLEAN, &required);
1438 case CONNMAN_SERVICE_TYPE_ETHERNET:
1439 case CONNMAN_SERVICE_TYPE_WIMAX:
1440 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1441 connman_dbus_dict_append_dict(dict, "Ethernet",
1442 append_ethernet, service);
1446 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
1448 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
1449 append_ipv4config, service);
1451 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
1453 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
1454 append_ipv6config, service);
1456 connman_dbus_dict_append_array(dict, "Nameservers",
1457 DBUS_TYPE_STRING, append_dns, service);
1459 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
1460 DBUS_TYPE_STRING, append_dnsconfig, service);
1462 connman_dbus_dict_append_array(dict, "Domains",
1463 DBUS_TYPE_STRING, append_domain, service);
1465 connman_dbus_dict_append_array(dict, "Domains.Configuration",
1466 DBUS_TYPE_STRING, append_domainconfig, service);
1468 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
1470 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
1471 append_proxyconfig, service);
1473 connman_dbus_dict_append_dict(dict, "Provider",
1474 append_provider, service);
1477 static void append_struct(gpointer value, gpointer user_data)
1479 struct connman_service *service = value;
1480 DBusMessageIter *iter = user_data;
1481 DBusMessageIter entry, dict;
1483 if (service->path == NULL || service->hidden == TRUE)
1486 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
1488 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
1491 connman_dbus_dict_open(&entry, &dict);
1492 append_properties(&dict, TRUE, service);
1493 connman_dbus_dict_close(&entry, &dict);
1495 dbus_message_iter_close_container(iter, &entry);
1498 void __connman_service_list_struct(DBusMessageIter *iter)
1500 g_sequence_foreach(service_list, append_struct, iter);
1503 int __connman_service_get_index(struct connman_service *service)
1505 if (service == NULL)
1508 if (service->network == NULL)
1511 return connman_network_get_index(service->network);
1514 void __connman_service_set_domainname(struct connman_service *service,
1515 const char *domainname)
1517 if (service == NULL)
1520 g_free(service->domainname);
1521 service->domainname = g_strdup(domainname);
1523 domain_changed(service);
1526 const char *connman_service_get_domainname(struct connman_service *service)
1528 if (service == NULL)
1531 if (service->domains != NULL)
1532 return service->domains[0];
1534 return service->domainname;
1537 const char *connman_service_get_nameserver(struct connman_service *service)
1539 if (service == NULL)
1542 return service->nameserver;
1545 enum connman_service_proxy_method connman_service_get_proxy_method(
1546 struct connman_service *service)
1548 if (service == NULL)
1549 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
1551 return service->proxy;
1554 char **connman_service_get_proxy_servers(struct connman_service *service)
1556 return g_strdupv(service->proxies);
1559 char **connman_service_get_proxy_excludes(struct connman_service *service)
1561 return g_strdupv(service->excludes);
1564 const char *connman_service_get_proxy_url(struct connman_service *service)
1566 if (service == NULL)
1569 return service->pac;
1572 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
1575 if (service == NULL)
1578 if (__connman_ipconfig_set_proxy_autoconfig(service->ipconfig,
1582 proxy_changed(service);
1585 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
1587 if (service == NULL)
1590 return __connman_ipconfig_get_proxy_autoconfig(service->ipconfig);
1593 void __connman_service_set_passphrase(struct connman_service *service,
1594 const char* passphrase)
1596 if (service->immutable == TRUE)
1599 g_free(service->passphrase);
1600 service->passphrase = g_strdup(passphrase);
1602 passphrase_changed(service);
1604 if (service->network != NULL)
1605 connman_network_set_string(service->network,
1607 service->passphrase);
1609 __connman_storage_save_service(service);
1612 static DBusMessage *get_properties(DBusConnection *conn,
1613 DBusMessage *msg, void *user_data)
1615 struct connman_service *service = user_data;
1617 DBusMessageIter array, dict;
1619 DBG("service %p", service);
1621 reply = dbus_message_new_method_return(msg);
1625 dbus_message_iter_init_append(reply, &array);
1627 connman_dbus_dict_open(&array, &dict);
1628 append_properties(&dict, FALSE, service);
1629 connman_dbus_dict_close(&array, &dict);
1634 static int update_proxy_configuration(struct connman_service *service,
1635 DBusMessageIter *array)
1637 DBusMessageIter dict;
1638 enum connman_service_proxy_method method;
1639 GString *servers_str = NULL;
1640 GString *excludes_str = NULL;
1641 const char *url = NULL;
1643 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
1645 dbus_message_iter_recurse(array, &dict);
1647 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1648 DBusMessageIter entry, variant;
1652 dbus_message_iter_recurse(&dict, &entry);
1654 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1657 dbus_message_iter_get_basic(&entry, &key);
1658 dbus_message_iter_next(&entry);
1660 if (dbus_message_iter_get_arg_type(&entry) !=
1664 dbus_message_iter_recurse(&entry, &variant);
1665 type = dbus_message_iter_get_arg_type(&variant);
1667 if (g_str_equal(key, "Method") == TRUE) {
1670 if (type != DBUS_TYPE_STRING)
1673 dbus_message_iter_get_basic(&variant, &val);
1674 method = string2proxymethod(val);
1675 } else if (g_str_equal(key, "URL") == TRUE) {
1676 if (type != DBUS_TYPE_STRING)
1679 dbus_message_iter_get_basic(&variant, &url);
1680 } else if (g_str_equal(key, "Servers") == TRUE) {
1681 DBusMessageIter str_array;
1683 if (type != DBUS_TYPE_ARRAY)
1686 servers_str = g_string_new(NULL);
1687 if (servers_str == NULL)
1690 dbus_message_iter_recurse(&variant, &str_array);
1692 while (dbus_message_iter_get_arg_type(&str_array) ==
1696 dbus_message_iter_get_basic(&str_array, &val);
1698 if (servers_str->len > 0)
1699 g_string_append_printf(servers_str,
1702 g_string_append(servers_str, val);
1704 dbus_message_iter_next(&str_array);
1706 } else if (g_str_equal(key, "Excludes") == TRUE) {
1707 DBusMessageIter str_array;
1709 if (type != DBUS_TYPE_ARRAY)
1712 excludes_str = g_string_new(NULL);
1713 if (excludes_str == NULL)
1716 dbus_message_iter_recurse(&variant, &str_array);
1718 while (dbus_message_iter_get_arg_type(&str_array) ==
1722 dbus_message_iter_get_basic(&str_array, &val);
1724 if (excludes_str->len > 0)
1725 g_string_append_printf(excludes_str,
1728 g_string_append(excludes_str, val);
1730 dbus_message_iter_next(&str_array);
1734 dbus_message_iter_next(&dict);
1738 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
1740 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
1741 if (servers_str == NULL && service->proxies == NULL)
1744 if (servers_str != NULL) {
1745 g_strfreev(service->proxies);
1747 if (servers_str->len > 0)
1748 service->proxies = g_strsplit_set(
1749 servers_str->str, " ", 0);
1751 service->proxies = NULL;
1754 if (excludes_str != NULL) {
1755 g_strfreev(service->excludes);
1757 if (excludes_str->len > 0)
1758 service->excludes = g_strsplit_set(
1759 excludes_str->str, " ", 0);
1761 service->excludes = NULL;
1764 if (service->proxies == NULL)
1765 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
1768 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
1769 g_free(service->pac);
1771 if (url != NULL && strlen(url) > 0)
1772 service->pac = g_strdup(url);
1774 service->pac = NULL;
1776 /* if we are connected:
1777 - if service->pac == NULL
1778 - if __connman_ipconfig_get_proxy_autoconfig(
1779 service->ipconfig) == NULL
1780 --> We should start WPAD */
1783 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
1787 if (servers_str != NULL)
1788 g_string_free(servers_str, TRUE);
1790 if (excludes_str != NULL)
1791 g_string_free(excludes_str, TRUE);
1793 service->proxy = method;
1798 if (servers_str != NULL)
1799 g_string_free(servers_str, TRUE);
1801 if (excludes_str != NULL)
1802 g_string_free(excludes_str, TRUE);
1807 static DBusMessage *set_property(DBusConnection *conn,
1808 DBusMessage *msg, void *user_data)
1810 struct connman_service *service = user_data;
1811 DBusMessageIter iter, value;
1815 DBG("service %p", service);
1817 if (dbus_message_iter_init(msg, &iter) == FALSE)
1818 return __connman_error_invalid_arguments(msg);
1820 dbus_message_iter_get_basic(&iter, &name);
1821 dbus_message_iter_next(&iter);
1822 dbus_message_iter_recurse(&iter, &value);
1824 type = dbus_message_iter_get_arg_type(&value);
1826 if (g_str_has_prefix(name, "AutoConnect") == TRUE) {
1827 connman_bool_t autoconnect;
1829 if (type != DBUS_TYPE_BOOLEAN)
1830 return __connman_error_invalid_arguments(msg);
1832 if (service->favorite == FALSE)
1833 return __connman_error_invalid_service(msg);
1835 dbus_message_iter_get_basic(&value, &autoconnect);
1837 if (service->autoconnect == autoconnect)
1838 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1840 service->autoconnect = autoconnect;
1842 autoconnect_changed(service);
1844 __connman_storage_save_service(service);
1845 } else if (g_str_equal(name, "Passphrase") == TRUE) {
1846 const char *passphrase;
1848 if (type != DBUS_TYPE_STRING)
1849 return __connman_error_invalid_arguments(msg);
1851 if (service->immutable == TRUE)
1852 return __connman_error_not_supported(msg);
1854 dbus_message_iter_get_basic(&value, &passphrase);
1856 __connman_service_set_passphrase(service, passphrase);
1857 } else if (g_str_equal(name, "APN") == TRUE) {
1860 if (type != DBUS_TYPE_STRING)
1861 return __connman_error_invalid_arguments(msg);
1863 if (service->immutable == TRUE)
1864 return __connman_error_not_supported(msg);
1866 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
1867 return __connman_error_invalid_service(msg);
1869 dbus_message_iter_get_basic(&value, &apn);
1871 g_free(service->apn);
1872 service->apn = g_strdup(apn);
1874 apn_changed(service);
1876 if (service->network != NULL)
1877 connman_network_set_string(service->network,
1878 "Cellular.APN", service->apn);
1880 __connman_storage_save_service(service);
1881 } else if (g_str_equal(name, "Username") == TRUE) {
1882 const char *username;
1884 if (type != DBUS_TYPE_STRING)
1885 return __connman_error_invalid_arguments(msg);
1887 if (service->immutable == TRUE)
1888 return __connman_error_not_supported(msg);
1890 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
1891 return __connman_error_invalid_service(msg);
1893 dbus_message_iter_get_basic(&value, &username);
1895 g_free(service->username);
1896 service->username = g_strdup(username);
1898 if (service->network != NULL)
1899 connman_network_set_string(service->network,
1900 "Cellular.Username", service->username);
1902 __connman_storage_save_service(service);
1903 } else if (g_str_equal(name, "Password") == TRUE) {
1904 const char *password;
1906 if (type != DBUS_TYPE_STRING)
1907 return __connman_error_invalid_arguments(msg);
1909 if (service->immutable == TRUE)
1910 return __connman_error_not_supported(msg);
1912 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
1913 return __connman_error_invalid_service(msg);
1915 dbus_message_iter_get_basic(&value, &password);
1917 g_free(service->password);
1918 service->password = g_strdup(password);
1920 if (service->network != NULL)
1921 connman_network_set_string(service->network,
1922 "Cellular.Password", service->password);
1924 __connman_storage_save_service(service);
1925 } else if (g_str_equal(name, "Nameservers.Configuration") == TRUE) {
1926 DBusMessageIter entry;
1931 if (type != DBUS_TYPE_ARRAY)
1932 return __connman_error_invalid_arguments(msg);
1934 str = g_string_new(NULL);
1936 return __connman_error_invalid_arguments(msg);
1938 index = connman_network_get_index(service->network);
1939 gw = __connman_ipconfig_get_gateway(index);
1941 if (gw && strlen(gw))
1942 __connman_service_nameserver_del_routes(service);
1944 dbus_message_iter_recurse(&value, &entry);
1946 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
1948 dbus_message_iter_get_basic(&entry, &val);
1949 dbus_message_iter_next(&entry);
1951 g_string_append_printf(str, " %s", val);
1953 g_string_append(str, val);
1956 g_strfreev(service->nameservers);
1959 service->nameservers = g_strsplit_set(str->str, " ", 0);
1961 service->nameservers = NULL;
1963 g_string_free(str, TRUE);
1965 if (gw && strlen(gw))
1966 __connman_service_nameserver_add_routes(service, gw);
1968 update_nameservers(service);
1969 dns_configuration_changed(service);
1971 __connman_storage_save_service(service);
1972 } else if (g_str_equal(name, "Domains.Configuration") == TRUE) {
1973 DBusMessageIter entry;
1976 if (type != DBUS_TYPE_ARRAY)
1977 return __connman_error_invalid_arguments(msg);
1979 str = g_string_new(NULL);
1981 return __connman_error_invalid_arguments(msg);
1983 dbus_message_iter_recurse(&value, &entry);
1985 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
1987 dbus_message_iter_get_basic(&entry, &val);
1988 dbus_message_iter_next(&entry);
1990 g_string_append_printf(str, " %s", val);
1992 g_string_append(str, val);
1995 g_strfreev(service->domains);
1998 service->domains = g_strsplit_set(str->str, " ", 0);
2000 service->domains = NULL;
2002 g_string_free(str, TRUE);
2004 update_nameservers(service);
2005 domain_configuration_changed(service);
2007 __connman_storage_save_service(service);
2008 } else if (g_str_equal(name, "Proxy.Configuration") == TRUE) {
2011 if (type != DBUS_TYPE_ARRAY)
2012 return __connman_error_invalid_arguments(msg);
2014 err = update_proxy_configuration(service, &value);
2017 return __connman_error_failed(msg, -err);
2019 proxy_configuration_changed(service);
2021 __connman_storage_save_service(service);
2022 } else if (g_str_equal(name, "IPv4.Configuration") == TRUE ||
2023 g_str_equal(name, "IPv6.Configuration")) {
2025 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
2027 struct connman_ipconfig *ipv6config;
2031 ipv6config = connman_ipconfig_get_ipv6config(
2033 if (service->ipconfig == NULL)
2034 return __connman_error_invalid_property(msg);
2036 if (is_connecting(service) ||
2037 is_connected(service)) {
2038 __connman_network_clear_ipconfig(service->network,
2040 __connman_network_clear_ipconfig(service->network,
2044 if (g_str_equal(name, "IPv4.Configuration") == TRUE) {
2045 type = CONNMAN_IPCONFIG_TYPE_IPV4;
2046 err = __connman_ipconfig_set_config(
2047 service->ipconfig, type, &value);
2048 } else if (g_str_equal(name, "IPv6.Configuration") == TRUE) {
2049 type = CONNMAN_IPCONFIG_TYPE_IPV6;
2050 err = __connman_ipconfig_set_config(
2051 ipv6config, type, &value);
2055 if (is_connected(service) ||
2056 is_connecting(service))
2057 __connman_network_set_ipconfig(
2060 return __connman_error_failed(msg, -err);
2063 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
2064 ipv4_configuration_changed(service);
2065 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2066 ipv6_configuration_changed(service);
2068 if (is_connecting(service) ||
2069 is_connected(service))
2070 __connman_network_set_ipconfig(service->network,
2073 __connman_storage_save_service(service);
2075 return __connman_error_invalid_property(msg);
2077 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2080 static void set_idle(struct connman_service *service)
2082 service->state = CONNMAN_SERVICE_STATE_IDLE;
2083 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
2084 state_changed(service);
2087 static DBusMessage *clear_property(DBusConnection *conn,
2088 DBusMessage *msg, void *user_data)
2090 struct connman_service *service = user_data;
2093 DBG("service %p", service);
2095 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
2098 if (g_str_equal(name, "Error") == TRUE) {
2101 g_get_current_time(&service->modified);
2102 __connman_storage_save_service(service);
2103 } else if (g_str_equal(name, "Passphrase") == TRUE) {
2104 if (service->immutable == TRUE)
2105 return __connman_error_not_supported(msg);
2107 g_free(service->passphrase);
2108 service->passphrase = NULL;
2110 passphrase_changed(service);
2112 __connman_storage_save_service(service);
2114 return __connman_error_invalid_property(msg);
2116 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2119 static connman_bool_t is_ignore(struct connman_service *service)
2121 if (service->autoconnect == FALSE)
2124 if (service->roaming == TRUE)
2127 if (service->ignore == TRUE)
2130 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
2136 void __connman_service_auto_connect(void)
2138 struct connman_service *service = NULL;
2139 GSequenceIter *iter;
2143 iter = g_sequence_get_begin_iter(service_list);
2145 while (g_sequence_iter_is_end(iter) == FALSE) {
2146 service = g_sequence_get(iter);
2148 if (service->pending != NULL)
2151 if (is_connecting(service) == TRUE)
2154 if (service->favorite == FALSE)
2157 if (is_connected(service) == TRUE)
2160 if (is_ignore(service) == FALSE &&
2161 service->state == CONNMAN_SERVICE_STATE_IDLE)
2166 iter = g_sequence_iter_next(iter);
2169 if (service != NULL) {
2170 service->userconnect = FALSE;
2171 __connman_service_connect(service);
2175 static void remove_timeout(struct connman_service *service)
2177 if (service->timeout > 0) {
2178 g_source_remove(service->timeout);
2179 service->timeout = 0;
2183 static void reply_pending(struct connman_service *service, int error)
2185 remove_timeout(service);
2187 if (service->pending != NULL) {
2191 reply = __connman_error_failed(service->pending,
2194 g_dbus_send_message(connection, reply);
2196 g_dbus_send_reply(connection, service->pending,
2199 dbus_message_unref(service->pending);
2200 service->pending = NULL;
2204 static gboolean connect_timeout(gpointer user_data)
2206 struct connman_service *service = user_data;
2207 connman_bool_t autoconnect = FALSE;
2209 DBG("service %p", service);
2211 service->timeout = 0;
2213 if (service->network != NULL)
2214 __connman_network_disconnect(service->network);
2216 __connman_ipconfig_disable(service->ipconfig);
2217 __connman_stats_service_unregister(service);
2219 if (service->pending != NULL) {
2222 reply = __connman_error_operation_timeout(service->pending);
2224 g_dbus_send_message(connection, reply);
2226 dbus_message_unref(service->pending);
2227 service->pending = NULL;
2231 __connman_service_indicate_state(service,
2232 CONNMAN_SERVICE_STATE_FAILURE);
2234 if (autoconnect == TRUE && service->userconnect == FALSE)
2235 __connman_service_auto_connect();
2240 static void set_reconnect_state(struct connman_service *service,
2241 connman_bool_t reconnect)
2243 struct connman_device *device;
2245 if (service->network == NULL)
2248 device = connman_network_get_device(service->network);
2252 __connman_device_set_reconnect(device, reconnect);
2255 static connman_bool_t get_reconnect_state(struct connman_service *service)
2257 struct connman_device *device;
2259 if (service->network == NULL)
2262 device = connman_network_get_device(service->network);
2266 return __connman_device_get_reconnect(device);
2269 static void request_input_cb (struct connman_service *service,
2270 const char *passphrase, void *user_data)
2272 DBG ("RequestInput return, %p", service);
2274 if (passphrase == NULL)
2276 __connman_service_set_passphrase(service, passphrase);
2277 __connman_service_connect(service);
2280 struct connman_service *
2281 __connman_service_connect_type(enum connman_service_type type)
2283 struct connman_service *service;
2284 GSequenceIter *iter;
2287 DBG("type %d", type);
2290 * We go through the already sorted service list.
2291 * We pick the first one matching our type, or just
2292 * the first available one if we have no type.
2294 iter = g_sequence_get_begin_iter(service_list);
2295 if (g_sequence_iter_is_end(iter))
2297 service = g_sequence_get(iter);
2300 * If the first service is connected or about to be
2301 * connected, we return it, regardless of the type.
2303 if ((g_sequence_iter_is_end(iter) == FALSE) &&
2304 (is_connecting(service) == TRUE ||
2305 is_connected(service) == TRUE))
2308 while (g_sequence_iter_is_end(iter) == FALSE) {
2309 if (service->type == type ||
2310 type == CONNMAN_SERVICE_TYPE_UNKNOWN)
2313 iter = g_sequence_iter_next(iter);
2314 service = g_sequence_get(iter);
2317 if (g_sequence_iter_is_end(iter))
2320 service->ignore = FALSE;
2322 service->userconnect = TRUE;
2324 set_reconnect_state(service, FALSE);
2326 err = __connman_service_connect(service);
2329 if ( __connman_agent_request_input(service,
2334 if (err != -EINPROGRESS)
2341 static DBusMessage *connect_service(DBusConnection *conn,
2342 DBusMessage *msg, void *user_data)
2344 struct connman_service *service = user_data;
2345 GSequenceIter *iter;
2348 DBG("service %p", service);
2350 if (service->pending != NULL)
2351 return __connman_error_in_progress(msg);
2353 iter = g_sequence_get_begin_iter(service_list);
2355 while (g_sequence_iter_is_end(iter) == FALSE) {
2356 struct connman_service *temp = g_sequence_get(iter);
2358 if (service->type == temp->type &&
2359 is_connecting(temp) == TRUE)
2360 return __connman_error_in_progress(msg);
2362 iter = g_sequence_iter_next(iter);
2365 service->ignore = FALSE;
2367 service->userconnect = TRUE;
2369 service->pending = dbus_message_ref(msg);
2371 set_reconnect_state(service, FALSE);
2373 err = __connman_service_connect(service);
2375 if (err == -ENOKEY) {
2376 if (__connman_agent_request_input(service,
2382 if (err != -EINPROGRESS) {
2383 dbus_message_unref(service->pending);
2384 service->pending = NULL;
2386 return __connman_error_failed(msg, -err);
2392 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2395 static DBusMessage *disconnect_service(DBusConnection *conn,
2396 DBusMessage *msg, void *user_data)
2398 struct connman_service *service = user_data;
2401 DBG("service %p", service);
2403 reply_pending(service, ECONNABORTED);
2405 service->ignore = TRUE;
2407 set_reconnect_state(service, FALSE);
2409 err = __connman_service_disconnect(service);
2411 if (err != -EINPROGRESS)
2412 return __connman_error_failed(msg, -err);
2417 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2420 static DBusMessage *remove_service(DBusConnection *conn,
2421 DBusMessage *msg, void *user_data)
2423 struct connman_service *service = user_data;
2425 DBG("service %p", service);
2427 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
2428 return __connman_error_not_supported(msg);
2430 if (service->immutable == TRUE)
2431 return __connman_error_not_supported(msg);
2433 if (service->favorite == FALSE &&
2434 service->state != CONNMAN_SERVICE_STATE_FAILURE)
2435 return __connman_error_not_supported(msg);
2437 if (service->network != NULL) {
2438 set_reconnect_state(service, FALSE);
2440 __connman_network_disconnect(service->network);
2443 g_hash_table_destroy(service->counter_table);
2445 g_free(service->passphrase);
2446 service->passphrase = NULL;
2448 passphrase_changed(service);
2450 g_free(service->apn);
2451 service->apn = NULL;
2453 g_free(service->username);
2454 service->username = NULL;
2456 g_free(service->password);
2457 service->password = NULL;
2459 apn_changed(service);
2463 __connman_service_set_favorite(service, FALSE);
2464 __connman_storage_save_service(service);
2466 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2469 static DBusMessage *move_service(DBusConnection *conn,
2470 DBusMessage *msg, void *user_data,
2473 struct connman_service *service = user_data;
2474 struct connman_service *target;
2476 GSequenceIter *src, *dst;
2478 DBG("service %p", service);
2480 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
2483 if (service->favorite == FALSE)
2484 return __connman_error_not_supported(msg);
2486 target = find_service(path);
2487 if (target == NULL || target->favorite == FALSE || target == service)
2488 return __connman_error_invalid_service(msg);
2490 DBG("target %s", target->identifier);
2492 if (target->state != service->state)
2493 return __connman_error_invalid_service(msg);
2495 g_get_current_time(&service->modified);
2496 __connman_storage_save_service(service);
2498 src = g_hash_table_lookup(service_hash, service->identifier);
2499 dst = g_hash_table_lookup(service_hash, target->identifier);
2501 before ? g_sequence_move(src, dst) : g_sequence_move(dst, src);
2503 __connman_profile_changed(FALSE);
2505 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2508 static DBusMessage *move_before(DBusConnection *conn,
2509 DBusMessage *msg, void *user_data)
2511 return move_service(conn, msg, user_data, TRUE);
2514 static DBusMessage *move_after(DBusConnection *conn,
2515 DBusMessage *msg, void *user_data)
2517 return move_service(conn, msg, user_data, FALSE);
2520 static DBusMessage *reset_counters(DBusConnection *conn,
2521 DBusMessage *msg, void *user_data)
2523 struct connman_service *service = user_data;
2525 reset_stats(service);
2527 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2530 static GDBusMethodTable service_methods[] = {
2531 { "GetProperties", "", "a{sv}", get_properties },
2532 { "SetProperty", "sv", "", set_property },
2533 { "ClearProperty", "s", "", clear_property },
2534 { "Connect", "", "", connect_service,
2535 G_DBUS_METHOD_FLAG_ASYNC },
2536 { "Disconnect", "", "", disconnect_service },
2537 { "Remove", "", "", remove_service },
2538 { "MoveBefore", "o", "", move_before },
2539 { "MoveAfter", "o", "", move_after },
2540 { "ResetCounters", "", "", reset_counters },
2544 static GDBusSignalTable service_signals[] = {
2545 { "PropertyChanged", "sv" },
2549 static void service_free(gpointer user_data)
2551 struct connman_service *service = user_data;
2552 char *path = service->path;
2554 DBG("service %p", service);
2556 reply_pending(service, ENOENT);
2558 g_hash_table_remove(service_hash, service->identifier);
2560 stats_stop(service);
2561 __connman_storage_save_service(service);
2563 service->path = NULL;
2566 __connman_profile_changed(FALSE);
2568 g_dbus_unregister_interface(connection, path,
2569 CONNMAN_SERVICE_INTERFACE);
2573 if (service->network != NULL)
2574 connman_network_unref(service->network);
2576 if (service->provider != NULL)
2577 connman_provider_unref(service->provider);
2579 if (service->ipconfig != NULL) {
2580 connman_ipconfig_unref(service->ipconfig);
2581 service->ipconfig = NULL;
2584 if (service->location != NULL)
2585 connman_location_unref(service->location);
2587 g_strfreev(service->nameservers);
2588 g_strfreev(service->domains);
2589 g_strfreev(service->proxies);
2590 g_strfreev(service->excludes);
2592 g_free(service->nameserver);
2593 g_free(service->domainname);
2594 g_free(service->pac);
2595 g_free(service->mcc);
2596 g_free(service->mnc);
2597 g_free(service->apn);
2598 g_free(service->username);
2599 g_free(service->password);
2600 g_free(service->profile);
2601 g_free(service->name);
2602 g_free(service->passphrase);
2603 g_free(service->identifier);
2604 g_free(service->eap);
2605 g_free(service->identity);
2606 g_free(service->ca_cert_file);
2607 g_free(service->client_cert_file);
2608 g_free(service->private_key_file);
2609 g_free(service->private_key_passphrase);
2610 g_free(service->phase2);
2612 if (service->stats.timer != NULL)
2613 g_timer_destroy(service->stats.timer);
2614 if (service->stats_roaming.timer != NULL)
2615 g_timer_destroy(service->stats_roaming.timer);
2621 * __connman_service_put:
2622 * @service: service structure
2624 * Release service if no longer needed
2626 void __connman_service_put(struct connman_service *service)
2628 DBG("service %p", service);
2630 if (g_atomic_int_dec_and_test(&service->refcount) == TRUE) {
2631 GSequenceIter *iter;
2633 iter = g_hash_table_lookup(service_hash, service->identifier);
2635 reply_pending(service, ECONNABORTED);
2637 __connman_service_disconnect(service);
2639 g_sequence_remove(iter);
2641 service_free(service);
2645 static void stats_init(struct connman_service *service)
2648 service->stats.valid = FALSE;
2649 service->stats.enabled = FALSE;
2650 service->stats.timer = g_timer_new();
2653 service->stats_roaming.valid = FALSE;
2654 service->stats_roaming.enabled = FALSE;
2655 service->stats_roaming.timer = g_timer_new();
2658 static void service_initialize(struct connman_service *service)
2660 DBG("service %p", service);
2662 service->refcount = 1;
2664 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
2665 service->mode = CONNMAN_SERVICE_MODE_UNKNOWN;
2666 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
2667 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
2669 service->favorite = FALSE;
2670 service->immutable = FALSE;
2671 service->hidden = FALSE;
2673 service->ignore = FALSE;
2675 service->userconnect = FALSE;
2679 stats_init(service);
2681 service->provider = NULL;
2685 * connman_service_create:
2687 * Allocate a new service.
2689 * Returns: a newly-allocated #connman_service structure
2691 struct connman_service *connman_service_create(void)
2694 struct connman_stats_counter *counters;
2695 const char *counter;
2697 struct connman_service *service;
2699 service = g_try_new0(struct connman_service, 1);
2700 if (service == NULL)
2703 DBG("service %p", service);
2705 service->counter_table = g_hash_table_new_full(g_str_hash,
2706 g_str_equal, NULL, g_free);
2708 for (list = counter_list; list; list = list->next) {
2709 counter = list->data;
2711 counters = g_try_new0(struct connman_stats_counter, 1);
2712 if (counters == NULL) {
2713 g_hash_table_destroy(service->counter_table);
2718 counters->append_all = TRUE;
2720 g_hash_table_replace(service->counter_table, (gpointer)counter,
2724 service_initialize(service);
2726 service->location = __connman_location_create(service);
2731 struct connman_location *__connman_service_get_location(struct connman_service *service)
2733 return service->location;
2737 * connman_service_ref:
2738 * @service: service structure
2740 * Increase reference counter of service
2742 struct connman_service *connman_service_ref(struct connman_service *service)
2746 g_atomic_int_inc(&service->refcount);
2752 * connman_service_unref:
2753 * @service: service structure
2755 * Decrease reference counter of service
2757 void connman_service_unref(struct connman_service *service)
2759 __connman_service_put(service);
2762 static gint service_compare(gconstpointer a, gconstpointer b,
2765 struct connman_service *service_a = (void *) a;
2766 struct connman_service *service_b = (void *) b;
2768 if (service_a->state != service_b->state) {
2769 if (is_connected(service_a) == TRUE)
2771 if (is_connected(service_b) == TRUE)
2775 if (service_a->order > service_b->order)
2778 if (service_a->order < service_b->order)
2781 if (service_a->favorite == TRUE && service_b->favorite == FALSE)
2784 if (service_a->favorite == FALSE && service_b->favorite == TRUE)
2787 if (service_a->type != service_b->type) {
2788 switch (service_a->type) {
2789 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2790 case CONNMAN_SERVICE_TYPE_SYSTEM:
2791 case CONNMAN_SERVICE_TYPE_ETHERNET:
2792 case CONNMAN_SERVICE_TYPE_GPS:
2793 case CONNMAN_SERVICE_TYPE_VPN:
2794 case CONNMAN_SERVICE_TYPE_GADGET:
2796 case CONNMAN_SERVICE_TYPE_WIFI:
2798 case CONNMAN_SERVICE_TYPE_WIMAX:
2799 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2800 case CONNMAN_SERVICE_TYPE_CELLULAR:
2805 return (gint) service_b->strength - (gint) service_a->strength;
2809 * connman_service_get_type:
2810 * @service: service structure
2812 * Get the type of service
2814 enum connman_service_type connman_service_get_type(struct connman_service *service)
2816 if (service == NULL)
2817 return CONNMAN_SERVICE_TYPE_UNKNOWN;
2819 return service->type;
2823 * connman_service_get_interface:
2824 * @service: service structure
2826 * Get network interface of service
2828 char *connman_service_get_interface(struct connman_service *service)
2832 if (service == NULL)
2835 if (service->type == CONNMAN_SERVICE_TYPE_VPN) {
2836 index = connman_ipconfig_get_index(service->ipconfig);
2838 return connman_inet_ifname(index);
2841 if (service->network == NULL)
2844 index = connman_network_get_index(service->network);
2846 return connman_inet_ifname(index);
2850 * connman_service_get_network:
2851 * @service: service structure
2853 * Get the service network
2855 struct connman_network *
2856 __connman_service_get_network(struct connman_service *service)
2858 if (service == NULL)
2861 return service->network;
2864 struct connman_ipconfig *__connman_service_get_ipconfig(struct connman_service *service)
2866 if (service == NULL)
2869 return service->ipconfig;
2872 enum connman_service_security __connman_service_get_security(struct connman_service *service)
2874 if (service == NULL)
2875 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
2877 return service->security;
2881 * __connman_service_set_favorite:
2882 * @service: service structure
2883 * @favorite: favorite value
2885 * Change the favorite setting of service
2887 int __connman_service_set_favorite(struct connman_service *service,
2888 connman_bool_t favorite)
2890 GSequenceIter *iter;
2892 iter = g_hash_table_lookup(service_hash, service->identifier);
2896 if (service->favorite == favorite)
2899 service->favorite = favorite;
2901 favorite_changed(service);
2903 g_sequence_sort_changed(iter, service_compare, NULL);
2905 __connman_profile_changed(FALSE);
2910 int __connman_service_set_immutable(struct connman_service *service,
2911 connman_bool_t immutable)
2913 service->immutable = immutable;
2915 immutable_changed(service);
2920 void __connman_service_set_string(struct connman_service *service,
2921 const char *key, const char *value)
2923 if (g_str_equal(key, "EAP") == TRUE) {
2924 g_free(service->eap);
2925 service->eap = g_strdup(value);
2926 } else if (g_str_equal(key, "Identity") == TRUE) {
2927 g_free(service->identity);
2928 service->identity = g_strdup(value);
2929 } else if (g_str_equal(key, "CACertFile") == TRUE) {
2930 g_free(service->ca_cert_file);
2931 service->ca_cert_file = g_strdup(value);
2932 } else if (g_str_equal(key, "ClientCertFile") == TRUE) {
2933 g_free(service->client_cert_file);
2934 service->client_cert_file = g_strdup(value);
2935 } else if (g_str_equal(key, "PrivateKeyFile") == TRUE) {
2936 g_free(service->private_key_file);
2937 service->private_key_file = g_strdup(value);
2938 } else if (g_str_equal(key, "PrivateKeyPassphrase") == TRUE) {
2939 g_free(service->private_key_passphrase);
2940 service->private_key_passphrase = g_strdup(value);
2941 } else if (g_str_equal(key, "Phase2") == TRUE) {
2942 g_free(service->phase2);
2943 service->phase2 = g_strdup(value);
2944 } else if (g_str_equal(key, "Passphrase") == TRUE) {
2945 g_free(service->passphrase);
2946 service->passphrase = g_strdup(value);
2950 static void service_complete(struct connman_service *service)
2952 reply_pending(service, EIO);
2954 if (service->userconnect == FALSE)
2955 __connman_service_auto_connect();
2957 g_get_current_time(&service->modified);
2958 __connman_storage_save_service(service);
2961 static void report_error_cb(struct connman_service *service,
2962 gboolean retry, void *user_data)
2965 __connman_service_connect(service);
2967 service_complete(service);
2968 __connman_profile_changed(FALSE);
2969 __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
2973 int __connman_service_indicate_state(struct connman_service *service,
2974 enum connman_service_state state)
2976 GSequenceIter *iter;
2978 DBG("service %p state %d", service, state);
2980 if (service == NULL)
2983 if (service->state == state)
2986 if (service->state == CONNMAN_SERVICE_STATE_FAILURE &&
2987 state == CONNMAN_SERVICE_STATE_IDLE)
2990 if (service->state == CONNMAN_SERVICE_STATE_IDLE &&
2991 state == CONNMAN_SERVICE_STATE_DISCONNECT)
2994 if (state == CONNMAN_SERVICE_STATE_IDLE &&
2995 service->state != CONNMAN_SERVICE_STATE_DISCONNECT) {
2996 service->state = CONNMAN_SERVICE_STATE_DISCONNECT;
2997 state_changed(service);
2999 reply_pending(service, ECONNABORTED);
3001 __connman_service_disconnect(service);
3004 if (state == CONNMAN_SERVICE_STATE_CONFIGURATION) {
3005 if (__connman_stats_service_register(service) == 0) {
3006 __connman_stats_get(service, FALSE,
3007 &service->stats.data);
3008 __connman_stats_get(service, TRUE,
3009 &service->stats_roaming.data);
3012 __connman_ipconfig_enable(service->ipconfig);
3015 service->state = state;
3016 state_changed(service);
3018 if (state == CONNMAN_SERVICE_STATE_ONLINE) {
3019 if (service->login_required == TRUE) {
3020 service->login_required = FALSE;
3021 login_changed(service);
3024 connman_timeserver_sync();
3027 if (state == CONNMAN_SERVICE_STATE_IDLE) {
3028 connman_bool_t reconnect;
3030 reconnect = get_reconnect_state(service);
3031 if (reconnect == TRUE)
3032 __connman_service_auto_connect();
3035 if (state == CONNMAN_SERVICE_STATE_READY) {
3036 set_reconnect_state(service, TRUE);
3038 __connman_service_set_favorite(service, TRUE);
3040 reply_pending(service, 0);
3042 service->userconnect = FALSE;
3044 g_get_current_time(&service->modified);
3045 __connman_storage_save_service(service);
3047 update_nameservers(service);
3048 dns_changed(service);
3049 domain_changed(service);
3051 __connman_wpad_start(service);
3053 __connman_notifier_connect(service->type);
3056 } else if (state == CONNMAN_SERVICE_STATE_DISCONNECT) {
3057 __connman_location_finish(service);
3061 __connman_wpad_stop(service);
3063 update_nameservers(service);
3064 dns_changed(service);
3065 domain_changed(service);
3067 __connman_notifier_disconnect(service->type);
3070 if (state == CONNMAN_SERVICE_STATE_FAILURE) {
3071 if (service->userconnect == TRUE &&
3072 __connman_agent_report_error(service,
3073 error2string(service->error),
3074 report_error_cb, NULL) == -EIO)
3076 service_complete(service);
3078 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
3080 iter = g_hash_table_lookup(service_hash, service->identifier);
3082 g_sequence_sort_changed(iter, service_compare, NULL);
3084 __connman_profile_changed(FALSE);
3086 if (service->state == CONNMAN_SERVICE_STATE_ONLINE)
3089 if (service->state == CONNMAN_SERVICE_STATE_DISCONNECT) {
3090 struct connman_service *def_service = get_default();
3092 if (__connman_notifier_count_connected() == 0 &&
3093 def_service != NULL &&
3094 def_service->provider != NULL)
3095 __connman_provider_disconnect(def_service->provider);
3098 if (service->state == CONNMAN_SERVICE_STATE_IDLE ||
3099 service->state == CONNMAN_SERVICE_STATE_FAILURE)
3100 __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
3105 int __connman_service_indicate_error(struct connman_service *service,
3106 enum connman_service_error error)
3108 DBG("service %p error %d", service, error);
3110 if (service == NULL)
3113 service->error = error;
3115 return __connman_service_indicate_state(service,
3116 CONNMAN_SERVICE_STATE_FAILURE);
3119 int __connman_service_indicate_default(struct connman_service *service)
3121 DBG("service %p", service);
3125 __connman_location_detect(service);
3130 int __connman_service_request_login(struct connman_service *service)
3132 DBG("service %p", service);
3134 if (service == NULL)
3137 service->login_required = TRUE;
3138 login_changed(service);
3143 static connman_bool_t prepare_network(struct connman_service *service)
3145 enum connman_network_type type;
3146 unsigned int ssid_len;
3148 type = connman_network_get_type(service->network);
3151 case CONNMAN_NETWORK_TYPE_UNKNOWN:
3152 case CONNMAN_NETWORK_TYPE_VENDOR:
3154 case CONNMAN_NETWORK_TYPE_WIFI:
3155 if (connman_network_get_blob(service->network, "WiFi.SSID",
3159 connman_network_set_string(service->network,
3160 "WiFi.Passphrase", service->passphrase);
3162 case CONNMAN_NETWORK_TYPE_ETHERNET:
3163 case CONNMAN_NETWORK_TYPE_WIMAX:
3164 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
3165 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
3167 case CONNMAN_NETWORK_TYPE_CELLULAR:
3168 connman_network_set_string(service->network,
3169 "Cellular.APN", service->apn);
3171 connman_network_set_string(service->network,
3172 "Cellular.Username", service->username);
3173 connman_network_set_string(service->network,
3174 "Cellular.Password", service->password);
3181 static void prepare_8021x(struct connman_service *service)
3183 if (service->eap != NULL)
3184 connman_network_set_string(service->network, "WiFi.EAP",
3187 if (service->identity != NULL)
3188 connman_network_set_string(service->network, "WiFi.Identity",
3191 if (service->ca_cert_file != NULL)
3192 connman_network_set_string(service->network, "WiFi.CACertFile",
3193 service->ca_cert_file);
3195 if (service->client_cert_file != NULL)
3196 connman_network_set_string(service->network,
3197 "WiFi.ClientCertFile",
3198 service->client_cert_file);
3200 if (service->private_key_file != NULL)
3201 connman_network_set_string(service->network,
3202 "WiFi.PrivateKeyFile",
3203 service->private_key_file);
3205 if (service->private_key_passphrase != NULL)
3206 connman_network_set_string(service->network,
3207 "WiFi.PrivateKeyPassphrase",
3208 service->private_key_passphrase);
3210 if (service->phase2 != NULL)
3211 connman_network_set_string(service->network, "WiFi.Phase2",
3215 int __connman_service_connect(struct connman_service *service)
3219 DBG("service %p", service);
3221 if (is_connected(service) == TRUE)
3224 if (is_connecting(service) == TRUE)
3227 switch (service->type) {
3228 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3229 case CONNMAN_SERVICE_TYPE_SYSTEM:
3230 case CONNMAN_SERVICE_TYPE_GPS:
3231 case CONNMAN_SERVICE_TYPE_GADGET:
3233 case CONNMAN_SERVICE_TYPE_ETHERNET:
3234 case CONNMAN_SERVICE_TYPE_WIMAX:
3235 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3236 case CONNMAN_SERVICE_TYPE_VPN:
3238 case CONNMAN_SERVICE_TYPE_CELLULAR:
3239 if (service->apn == NULL)
3242 case CONNMAN_SERVICE_TYPE_WIFI:
3243 switch (service->security) {
3244 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3245 case CONNMAN_SERVICE_SECURITY_NONE:
3247 case CONNMAN_SERVICE_SECURITY_WEP:
3248 case CONNMAN_SERVICE_SECURITY_PSK:
3249 case CONNMAN_SERVICE_SECURITY_WPA:
3250 case CONNMAN_SERVICE_SECURITY_RSN:
3251 if (service->passphrase == NULL)
3254 case CONNMAN_SERVICE_SECURITY_8021X:
3260 if (service->network != NULL) {
3261 if (prepare_network(service) == FALSE)
3264 switch (service->security) {
3265 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3266 case CONNMAN_SERVICE_SECURITY_NONE:
3267 case CONNMAN_SERVICE_SECURITY_WEP:
3268 case CONNMAN_SERVICE_SECURITY_PSK:
3269 case CONNMAN_SERVICE_SECURITY_WPA:
3270 case CONNMAN_SERVICE_SECURITY_RSN:
3272 case CONNMAN_SERVICE_SECURITY_8021X:
3273 prepare_8021x(service);
3277 if (__connman_stats_service_register(service) == 0) {
3278 __connman_stats_get(service, FALSE,
3279 &service->stats.data);
3280 __connman_stats_get(service, TRUE,
3281 &service->stats_roaming.data);
3284 __connman_ipconfig_enable(service->ipconfig);
3286 err = __connman_network_connect(service->network);
3287 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
3288 service->provider != NULL)
3289 err = __connman_provider_connect(service->provider);
3294 if (err != -EINPROGRESS) {
3295 __connman_ipconfig_disable(service->ipconfig);
3296 __connman_stats_service_unregister(service);
3297 if (service->userconnect == TRUE)
3298 return __connman_agent_report_error(service,
3299 error2string(service->error),
3300 report_error_cb, NULL);
3305 service->timeout = g_timeout_add_seconds(CONNECT_TIMEOUT,
3306 connect_timeout, service);
3308 return -EINPROGRESS;
3314 int __connman_service_disconnect(struct connman_service *service)
3316 struct connman_ipconfig *ipv6config;
3319 DBG("service %p", service);
3321 if (service->network != NULL) {
3322 err = __connman_network_disconnect(service->network);
3323 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
3324 service->provider != NULL)
3325 err = __connman_provider_disconnect(service->provider);
3329 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig, NULL);
3331 __connman_ipconfig_clear_address(service->ipconfig);
3333 ipv6config = connman_ipconfig_get_ipv6config(service->ipconfig);
3335 __connman_ipconfig_clear_address(ipv6config);
3337 __connman_ipconfig_disable(service->ipconfig);
3338 __connman_stats_service_unregister(service);
3341 if (err != -EINPROGRESS)
3344 return -EINPROGRESS;
3351 * __connman_service_lookup:
3352 * @pattern: search pattern
3353 * @path: return object path
3355 * Look up a service path from a search pattern
3357 int __connman_service_lookup(const char *pattern, const char **path)
3359 GHashTableIter iter;
3360 gpointer key, value;
3362 g_hash_table_iter_init(&iter, service_hash);
3364 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
3365 GSequenceIter *iter = value;
3366 struct connman_service *service = g_sequence_get(iter);
3368 if (g_strcmp0(service->identifier, pattern) == 0 ||
3369 g_strcmp0(service->name, pattern) == 0) {
3370 *path = (const char *) service->path;
3379 * lookup_by_identifier:
3380 * @identifier: service identifier
3382 * Look up a service by identifier (reference count will not be increased)
3384 static struct connman_service *lookup_by_identifier(const char *identifier)
3386 GSequenceIter *iter;
3388 iter = g_hash_table_lookup(service_hash, identifier);
3390 return g_sequence_get(iter);
3395 static struct connman_network *create_hidden_wifi(struct connman_device *device,
3396 const char *ssid, const char *mode, const char *security)
3398 struct connman_network *network;
3401 unsigned int i, ssid_len;
3403 ssid_len = strlen(ssid);
3407 network = connman_network_create(NULL, CONNMAN_NETWORK_TYPE_WIFI);
3408 if (network == NULL)
3411 connman_network_set_blob(network, "WiFi.SSID",
3412 (unsigned char *) ssid, ssid_len);
3414 connman_network_set_string(network, "WiFi.Mode", mode);
3415 connman_network_set_string(network, "WiFi.Security", security);
3417 name = g_try_malloc0(ssid_len + 1);
3419 connman_network_unref(network);
3423 for (i = 0; i < ssid_len; i++) {
3424 if (g_ascii_isprint(ssid[i]))
3430 connman_network_set_name(network, name);
3434 index = connman_device_get_index(device);
3435 connman_network_set_index(network, index);
3437 if (connman_device_add_network(device, network) < 0) {
3438 connman_network_unref(network);
3442 connman_network_set_available(network, TRUE);
3447 int __connman_service_create_and_connect(DBusMessage *msg)
3449 struct connman_service *service;
3450 struct connman_network *network;
3451 struct connman_device *device;
3452 DBusMessageIter iter, array;
3453 const char *mode = "managed", *security = "none", *group_security;
3454 const char *type = NULL, *ssid = NULL, *passphrase = NULL;
3455 unsigned int ssid_len = 0;
3458 gboolean created = FALSE;
3461 dbus_message_iter_init(msg, &iter);
3462 dbus_message_iter_recurse(&iter, &array);
3464 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
3465 DBusMessageIter entry, value;
3468 dbus_message_iter_recurse(&array, &entry);
3469 dbus_message_iter_get_basic(&entry, &key);
3471 dbus_message_iter_next(&entry);
3472 dbus_message_iter_recurse(&entry, &value);
3474 switch (dbus_message_iter_get_arg_type(&value)) {
3475 case DBUS_TYPE_STRING:
3476 if (g_str_equal(key, "Type") == TRUE)
3477 dbus_message_iter_get_basic(&value, &type);
3478 else if (g_str_equal(key, "WiFi.Mode") == TRUE ||
3479 g_str_equal(key, "Mode") == TRUE)
3480 dbus_message_iter_get_basic(&value, &mode);
3481 else if (g_str_equal(key, "WiFi.Security") == TRUE ||
3482 g_str_equal(key, "Security") == TRUE)
3483 dbus_message_iter_get_basic(&value, &security);
3484 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE ||
3485 g_str_equal(key, "Passphrase") == TRUE)
3486 dbus_message_iter_get_basic(&value, &passphrase);
3487 else if (g_str_equal(key, "WiFi.SSID") == TRUE ||
3488 g_str_equal(key, "SSID") == TRUE)
3489 dbus_message_iter_get_basic(&value, &ssid);
3492 dbus_message_iter_next(&array);
3498 if (g_strcmp0(type, "wifi") != 0 || g_strcmp0(mode, "managed") != 0)
3504 ssid_len = strlen(ssid);
3508 if (g_strcmp0(security, "none") != 0 &&
3509 g_strcmp0(security, "wep") != 0 &&
3510 g_strcmp0(security, "psk") != 0 &&
3511 g_strcmp0(security, "wpa") != 0 &&
3512 g_strcmp0(security, "rsn") != 0 &&
3513 g_strcmp0(security, "ieee8021x") != 0)
3516 device = __connman_element_find_device(CONNMAN_SERVICE_TYPE_WIFI);
3520 ident = connman_device_get_ident(device);
3525 if (!g_strcmp0(security, "wpa") ||
3526 !g_strcmp0(security, "rsn"))
3527 group_security = "psk";
3529 group_security = security;
3531 group = connman_wifi_build_group_name((unsigned char *) ssid,
3532 ssid_len, mode, group_security);
3536 name = g_strdup_printf("%s_%s_%s", type, ident, group);
3538 service = lookup_by_identifier(name);
3540 if (service != NULL)
3543 network = create_hidden_wifi(device, ssid, mode, security);
3544 if (network != NULL) {
3545 connman_network_set_group(network, group);
3549 service = lookup_by_identifier(name);
3555 if (service == NULL) {
3560 set_reconnect_state(service, FALSE);
3562 __connman_device_disconnect(device);
3564 if (passphrase != NULL) {
3565 g_free(service->passphrase);
3566 service->passphrase = g_strdup(passphrase);
3569 service->userconnect = TRUE;
3571 err = __connman_service_connect(service);
3572 if (err < 0 && err != -EINPROGRESS)
3575 g_dbus_send_reply(connection, msg,
3576 DBUS_TYPE_OBJECT_PATH, &service->path,
3582 if (service != NULL && created == TRUE) {
3583 struct connman_network *network = service->network;
3585 if (network != NULL) {
3586 connman_network_set_available(network, FALSE);
3587 __connman_device_cleanup_networks(device);
3589 __connman_service_put(service);
3596 * __connman_service_get:
3597 * @identifier: service identifier
3599 * Look up a service by identifier or create a new one if not found
3601 static struct connman_service *service_get(const char *identifier)
3603 struct connman_service *service;
3604 GSequenceIter *iter;
3606 iter = g_hash_table_lookup(service_hash, identifier);
3608 service = g_sequence_get(iter);
3609 if (service != NULL)
3610 connman_service_ref(service);
3614 service = connman_service_create();
3615 if (service == NULL)
3618 DBG("service %p", service);
3620 service->identifier = g_strdup(identifier);
3622 service->profile = g_strdup(__connman_profile_active_ident());
3624 iter = g_sequence_insert_sorted(service_list, service,
3625 service_compare, NULL);
3627 g_hash_table_insert(service_hash, service->identifier, iter);
3632 static int service_register(struct connman_service *service)
3634 const char *path = __connman_profile_active_path();
3635 GSequenceIter *iter;
3637 DBG("service %p", service);
3639 if (service->path != NULL)
3642 service->path = g_strdup_printf("%s/%s", path, service->identifier);
3644 DBG("path %s", service->path);
3646 __connman_config_provision_service(service);
3648 __connman_storage_load_service(service);
3650 g_dbus_register_interface(connection, service->path,
3651 CONNMAN_SERVICE_INTERFACE,
3652 service_methods, service_signals,
3653 NULL, service, NULL);
3655 iter = g_hash_table_lookup(service_hash, service->identifier);
3657 g_sequence_sort_changed(iter, service_compare, NULL);
3659 __connman_profile_changed(TRUE);
3664 static void service_up(struct connman_ipconfig *ipconfig)
3666 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
3668 connman_info("%s up", connman_ipconfig_get_ifname(ipconfig));
3670 link_changed(service);
3672 service->stats.valid = FALSE;
3673 service->stats_roaming.valid = FALSE;
3676 static void service_down(struct connman_ipconfig *ipconfig)
3678 connman_info("%s down", connman_ipconfig_get_ifname(ipconfig));
3681 static void service_lower_up(struct connman_ipconfig *ipconfig)
3683 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
3685 connman_info("%s lower up", connman_ipconfig_get_ifname(ipconfig));
3687 stats_start(service);
3690 static void service_lower_down(struct connman_ipconfig *ipconfig)
3692 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
3694 connman_info("%s lower down", connman_ipconfig_get_ifname(ipconfig));
3696 stats_stop(service);
3697 __connman_storage_save_service(service);
3700 static void service_ip_bound(struct connman_ipconfig *ipconfig)
3702 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
3704 connman_info("%s ip bound", connman_ipconfig_get_ifname(ipconfig));
3706 settings_changed(service);
3709 static void service_ip_release(struct connman_ipconfig *ipconfig)
3711 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
3713 connman_info("%s ip release", connman_ipconfig_get_ifname(ipconfig));
3715 settings_changed(service);
3718 static const struct connman_ipconfig_ops service_ops = {
3720 .down = service_down,
3721 .lower_up = service_lower_up,
3722 .lower_down = service_lower_down,
3723 .ip_bound = service_ip_bound,
3724 .ip_release = service_ip_release,
3727 static void setup_ipconfig(struct connman_service *service, int index)
3732 service->ipconfig = connman_ipconfig_create(index);
3733 if (service->ipconfig == NULL)
3736 connman_ipconfig_set_method(service->ipconfig,
3737 CONNMAN_IPCONFIG_METHOD_DHCP);
3739 connman_ipconfig_set_data(service->ipconfig, service);
3741 connman_ipconfig_set_ops(service->ipconfig, &service_ops);
3744 void __connman_service_create_ipconfig(struct connman_service *service,
3747 struct connman_ipconfig *ipv6config;
3748 const char *ident = service->profile;
3751 if (service->ipconfig != NULL)
3754 setup_ipconfig(service, index);
3759 keyfile = __connman_storage_open_profile(ident);
3760 if (keyfile == NULL)
3764 ipv6config = connman_ipconfig_get_ipv6config(service->ipconfig);
3765 if (ipv6config != NULL)
3766 __connman_ipconfig_load(ipv6config, keyfile,
3767 service->identifier, "IPv6.");
3769 __connman_ipconfig_load(service->ipconfig, keyfile,
3770 service->identifier, "IPv4.");
3771 g_key_file_free(keyfile);
3775 * __connman_service_lookup_from_network:
3776 * @network: network structure
3778 * Look up a service by network (reference count will not be increased)
3780 struct connman_service *__connman_service_lookup_from_network(struct connman_network *network)
3782 struct connman_service *service;
3783 const char *ident, *group;
3786 DBG("network %p", network);
3788 ident = __connman_network_get_ident(network);
3792 group = connman_network_get_group(network);
3796 name = g_strdup_printf("%s_%s_%s",
3797 __connman_network_get_type(network), ident, group);
3798 service = lookup_by_identifier(name);
3804 struct connman_service *__connman_service_lookup_from_index(int index)
3806 struct connman_service *service;
3807 GSequenceIter *iter;
3809 iter = g_sequence_get_begin_iter(service_list);
3811 while (g_sequence_iter_is_end(iter) == FALSE) {
3812 service = g_sequence_get(iter);
3814 if (connman_ipconfig_get_index(service->ipconfig) == index)
3817 iter = g_sequence_iter_next(iter);
3823 const char *__connman_service_get_ident(struct connman_service *service)
3825 return service->identifier;
3828 const char *__connman_service_get_path(struct connman_service *service)
3830 return service->path;
3833 unsigned int __connman_service_get_order(struct connman_service *service)
3835 GSequenceIter *iter;
3837 if (service == NULL)
3840 if (service->favorite == FALSE) {
3845 iter = g_hash_table_lookup(service_hash, service->identifier);
3847 if (g_sequence_iter_get_position(iter) == 0)
3849 else if (service->type == CONNMAN_SERVICE_TYPE_VPN)
3850 service->order = 10;
3856 return service->order;
3859 static enum connman_service_type convert_network_type(struct connman_network *network)
3861 enum connman_network_type type = connman_network_get_type(network);
3864 case CONNMAN_NETWORK_TYPE_UNKNOWN:
3865 case CONNMAN_NETWORK_TYPE_VENDOR:
3867 case CONNMAN_NETWORK_TYPE_ETHERNET:
3868 return CONNMAN_SERVICE_TYPE_ETHERNET;
3869 case CONNMAN_NETWORK_TYPE_WIFI:
3870 return CONNMAN_SERVICE_TYPE_WIFI;
3871 case CONNMAN_NETWORK_TYPE_WIMAX:
3872 return CONNMAN_SERVICE_TYPE_WIMAX;
3873 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
3874 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
3875 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
3876 case CONNMAN_NETWORK_TYPE_CELLULAR:
3877 return CONNMAN_SERVICE_TYPE_CELLULAR;
3880 return CONNMAN_SERVICE_TYPE_UNKNOWN;
3883 static enum connman_service_mode convert_wifi_mode(const char *mode)
3886 return CONNMAN_SERVICE_MODE_UNKNOWN;
3887 else if (g_str_equal(mode, "managed") == TRUE)
3888 return CONNMAN_SERVICE_MODE_MANAGED;
3889 else if (g_str_equal(mode, "adhoc") == TRUE)
3890 return CONNMAN_SERVICE_MODE_ADHOC;
3892 return CONNMAN_SERVICE_MODE_UNKNOWN;
3895 static enum connman_service_security convert_wifi_security(const char *security)
3897 if (security == NULL)
3898 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
3899 else if (g_str_equal(security, "none") == TRUE)
3900 return CONNMAN_SERVICE_SECURITY_NONE;
3901 else if (g_str_equal(security, "wep") == TRUE)
3902 return CONNMAN_SERVICE_SECURITY_WEP;
3903 else if (g_str_equal(security, "psk") == TRUE)
3904 return CONNMAN_SERVICE_SECURITY_PSK;
3905 else if (g_str_equal(security, "ieee8021x") == TRUE)
3906 return CONNMAN_SERVICE_SECURITY_8021X;
3907 else if (g_str_equal(security, "wpa") == TRUE)
3908 return CONNMAN_SERVICE_SECURITY_WPA;
3909 else if (g_str_equal(security, "rsn") == TRUE)
3910 return CONNMAN_SERVICE_SECURITY_RSN;
3912 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
3915 static enum connman_service_mode convert_cellular_mode(connman_uint8_t mode)
3920 return CONNMAN_SERVICE_MODE_GPRS;
3922 return CONNMAN_SERVICE_MODE_EDGE;
3927 return CONNMAN_SERVICE_MODE_UMTS;
3930 return CONNMAN_SERVICE_MODE_UNKNOWN;
3933 static void update_from_network(struct connman_service *service,
3934 struct connman_network *network)
3936 connman_uint8_t strength = service->strength;
3937 GSequenceIter *iter;
3940 DBG("service %p network %p", service, network);
3942 if (is_connected(service) == TRUE)
3945 if (is_connecting(service) == TRUE)
3948 str = connman_network_get_string(network, "Name");
3950 g_free(service->name);
3951 service->name = g_strdup(str);
3952 service->hidden = FALSE;
3954 g_free(service->name);
3955 service->name = NULL;
3956 service->hidden = TRUE;
3959 service->strength = connman_network_get_uint8(network, "Strength");
3960 service->roaming = connman_network_get_bool(network, "Roaming");
3962 if (service->strength == 0) {
3964 * Filter out 0-values; it's unclear what they mean
3965 * and they cause anomalous sorting of the priority list.
3967 service->strength = strength;
3970 str = connman_network_get_string(network, "WiFi.Mode");
3971 service->mode = convert_wifi_mode(str);
3973 str = connman_network_get_string(network, "WiFi.Security");
3974 service->security = convert_wifi_security(str);
3976 str = connman_network_get_string(network, "Cellular.MCC");
3977 g_free(service->mcc);
3978 service->mcc = g_strdup(str);
3980 str = connman_network_get_string(network, "Cellular.MNC");
3981 g_free(service->mnc);
3982 service->mnc = g_strdup(str);
3984 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
3985 connman_uint8_t value = connman_network_get_uint8(network,
3988 service->mode = convert_cellular_mode(value);
3991 if (service->strength > strength && service->network != NULL) {
3992 connman_network_unref(service->network);
3993 service->network = connman_network_ref(network);
3995 strength_changed(service);
3998 if (service->network == NULL)
3999 service->network = connman_network_ref(network);
4001 iter = g_hash_table_lookup(service_hash, service->identifier);
4003 g_sequence_sort_changed(iter, service_compare, NULL);
4007 * __connman_service_create_from_network:
4008 * @network: network structure
4010 * Look up service by network and if not found, create one
4012 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
4014 struct connman_service *service;
4015 const char *ident, *group;
4018 DBG("network %p", network);
4020 ident = __connman_network_get_ident(network);
4024 group = connman_network_get_group(network);
4028 name = g_strdup_printf("%s_%s_%s",
4029 __connman_network_get_type(network), ident, group);
4030 service = service_get(name);
4033 if (service == NULL)
4036 if (__connman_network_get_weakness(network) == TRUE)
4039 if (service->path != NULL) {
4040 update_from_network(service, network);
4041 __connman_profile_changed(TRUE);
4045 service->type = convert_network_type(network);
4047 switch (service->type) {
4048 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4049 case CONNMAN_SERVICE_TYPE_SYSTEM:
4050 case CONNMAN_SERVICE_TYPE_ETHERNET:
4051 case CONNMAN_SERVICE_TYPE_WIMAX:
4052 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4053 case CONNMAN_SERVICE_TYPE_GPS:
4054 case CONNMAN_SERVICE_TYPE_VPN:
4055 case CONNMAN_SERVICE_TYPE_GADGET:
4056 service->autoconnect = FALSE;
4058 case CONNMAN_SERVICE_TYPE_WIFI:
4059 case CONNMAN_SERVICE_TYPE_CELLULAR:
4060 service->autoconnect = TRUE;
4064 service->state = CONNMAN_SERVICE_STATE_IDLE;
4066 update_from_network(service, network);
4068 setup_ipconfig(service, connman_network_get_index(network));
4070 service_register(service);
4072 if (service->favorite == TRUE)
4073 __connman_service_auto_connect();
4078 void __connman_service_update_from_network(struct connman_network *network)
4080 struct connman_service *service;
4081 enum connman_service_mode mode;
4082 connman_uint8_t strength, value;
4083 connman_bool_t roaming;
4084 GSequenceIter *iter;
4086 connman_bool_t stats_enable;
4088 DBG("network %p", network);
4090 service = __connman_service_lookup_from_network(network);
4091 if (service == NULL)
4094 if (service->network == NULL)
4097 name = connman_network_get_string(service->network, "Name");
4098 if (g_strcmp0(service->name, name) != 0) {
4099 g_free(service->name);
4100 service->name = g_strdup(name);
4101 connman_dbus_property_changed_basic(service->path,
4102 CONNMAN_SERVICE_INTERFACE, "Name",
4103 DBUS_TYPE_STRING, &service->name);
4106 strength = connman_network_get_uint8(service->network, "Strength");
4107 if (strength == service->strength)
4110 service->strength = strength;
4112 strength_changed(service);
4115 roaming = connman_network_get_bool(service->network, "Roaming");
4116 if (roaming == service->roaming)
4119 stats_enable = stats_enabled(service);
4120 if (stats_enable == TRUE)
4121 stats_stop(service);
4123 service->roaming = roaming;
4125 if (stats_enable == TRUE)
4126 stats_start(service);
4128 roaming_changed(service);
4130 iter = g_hash_table_lookup(service_hash, service->identifier);
4132 g_sequence_sort_changed(iter, service_compare, NULL);
4135 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
4138 value = connman_network_get_uint8(service->network, "Cellular.Mode");
4139 mode = convert_cellular_mode(value);
4141 if (mode == service->mode)
4144 service->mode = mode;
4146 mode_changed(service);
4149 void __connman_service_remove_from_network(struct connman_network *network)
4151 struct connman_service *service;
4153 DBG("network %p", network);
4155 service = __connman_service_lookup_from_network(network);
4156 if (service == NULL)
4159 __connman_service_put(service);
4163 * __connman_service_create_from_provider:
4164 * @provider: provider structure
4166 * Look up service by provider and if not found, create one
4168 struct connman_service *
4169 __connman_service_create_from_provider(struct connman_provider *provider)
4171 struct connman_service *service;
4172 const char *ident, *str;
4174 int index = connman_provider_get_index(provider);
4176 DBG("provider %p", provider);
4178 ident = __connman_provider_get_ident(provider);
4182 name = g_strdup_printf("vpn_%s", ident);
4183 service = service_get(name);
4186 if (service == NULL)
4189 service->type = CONNMAN_SERVICE_TYPE_VPN;
4190 service->provider = connman_provider_ref(provider);
4191 service->autoconnect = FALSE;
4193 service->state = CONNMAN_SERVICE_STATE_IDLE;
4195 str = connman_provider_get_string(provider, "Name");
4197 g_free(service->name);
4198 service->name = g_strdup(str);
4199 service->hidden = FALSE;
4201 g_free(service->name);
4202 service->name = NULL;
4203 service->hidden = TRUE;
4206 service->strength = 0;
4208 service->ipconfig = connman_ipconfig_create(index);
4209 if (service->ipconfig == NULL)
4212 connman_ipconfig_set_method(service->ipconfig,
4213 CONNMAN_IPCONFIG_METHOD_MANUAL);
4215 connman_ipconfig_set_data(service->ipconfig, service);
4217 connman_ipconfig_set_ops(service->ipconfig, &service_ops);
4219 service_register(service);
4224 static int service_load(struct connman_service *service)
4226 const char *ident = service->profile;
4228 GError *error = NULL;
4229 gchar *pathname, *data = NULL;
4232 connman_bool_t autoconnect;
4233 unsigned int ssid_len;
4236 DBG("service %p", service);
4241 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
4242 if (pathname == NULL)
4245 keyfile = g_key_file_new();
4247 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
4254 if (g_key_file_load_from_data(keyfile, data, length,
4255 0, NULL) == FALSE) {
4262 switch (service->type) {
4263 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4264 case CONNMAN_SERVICE_TYPE_SYSTEM:
4265 case CONNMAN_SERVICE_TYPE_ETHERNET:
4266 case CONNMAN_SERVICE_TYPE_GPS:
4267 case CONNMAN_SERVICE_TYPE_VPN:
4268 case CONNMAN_SERVICE_TYPE_GADGET:
4270 case CONNMAN_SERVICE_TYPE_WIFI:
4271 if (service->name == NULL) {
4274 name = g_key_file_get_string(keyfile,
4275 service->identifier, "Name", NULL);
4277 g_free(service->name);
4278 service->name = name;
4281 if (service->network != NULL)
4282 connman_network_set_name(service->network,
4286 if (service->network &&
4287 connman_network_get_blob(service->network,
4288 "WiFi.SSID", &ssid_len) == NULL) {
4291 hex_ssid = g_key_file_get_string(keyfile,
4292 service->identifier,
4295 if (hex_ssid != NULL) {
4297 unsigned int i, j = 0, hex;
4298 size_t hex_ssid_len = strlen(hex_ssid);
4300 ssid = g_try_malloc0(hex_ssid_len / 2);
4307 for (i = 0; i < hex_ssid_len; i += 2) {
4308 sscanf(hex_ssid + i, "%02x", &hex);
4312 connman_network_set_blob(service->network,
4313 "WiFi.SSID", ssid, hex_ssid_len / 2);
4320 case CONNMAN_SERVICE_TYPE_WIMAX:
4321 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4322 case CONNMAN_SERVICE_TYPE_CELLULAR:
4323 service->apn = g_key_file_get_string(keyfile,
4324 service->identifier, "APN", NULL);
4326 service->username = g_key_file_get_string(keyfile,
4327 service->identifier, "Username", NULL);
4329 service->password = g_key_file_get_string(keyfile,
4330 service->identifier, "Password", NULL);
4332 service->favorite = g_key_file_get_boolean(keyfile,
4333 service->identifier, "Favorite", NULL);
4335 autoconnect = g_key_file_get_boolean(keyfile,
4336 service->identifier, "AutoConnect", &error);
4338 service->autoconnect = autoconnect;
4339 g_clear_error(&error);
4341 str = g_key_file_get_string(keyfile,
4342 service->identifier, "Failure", NULL);
4344 if (service->favorite == FALSE)
4345 service->state = CONNMAN_SERVICE_STATE_FAILURE;
4346 service->error = string2error(str);
4351 str = g_key_file_get_string(keyfile,
4352 service->identifier, "Modified", NULL);
4354 g_time_val_from_iso8601(str, &service->modified);
4358 str = g_key_file_get_string(keyfile,
4359 service->identifier, "Passphrase", NULL);
4361 g_free(service->passphrase);
4362 service->passphrase = str;
4365 if (service->ipconfig != NULL) {
4366 struct connman_ipconfig *ipv6config;
4368 ipv6config = connman_ipconfig_get_ipv6config(
4370 if (ipv6config != NULL)
4371 __connman_ipconfig_load(ipv6config, keyfile,
4372 service->identifier, "IPv6.");
4374 __connman_ipconfig_load(service->ipconfig, keyfile,
4375 service->identifier, "IPv4.");
4378 service->nameservers = g_key_file_get_string_list(keyfile,
4379 service->identifier, "Nameservers", &length, NULL);
4380 if (service->nameservers != NULL && length == 0) {
4381 g_strfreev(service->nameservers);
4382 service->nameservers = NULL;
4385 service->domains = g_key_file_get_string_list(keyfile,
4386 service->identifier, "Domains", &length, NULL);
4387 if (service->domains != NULL && length == 0) {
4388 g_strfreev(service->domains);
4389 service->domains = NULL;
4392 str = g_key_file_get_string(keyfile,
4393 service->identifier, "Proxy.Method", NULL);
4394 service->proxy = string2proxymethod(str);
4396 service->proxies = g_key_file_get_string_list(keyfile,
4397 service->identifier, "Proxy.Servers", &length, NULL);
4398 if (service->proxies != NULL && length == 0) {
4399 g_strfreev(service->proxies);
4400 service->proxies = NULL;
4403 service->excludes = g_key_file_get_string_list(keyfile,
4404 service->identifier, "Proxy.Excludes", &length, NULL);
4405 if (service->excludes != NULL && length == 0) {
4406 g_strfreev(service->excludes);
4407 service->excludes = NULL;
4410 str = g_key_file_get_string(keyfile,
4411 service->identifier, "Proxy.URL", NULL);
4413 g_free(service->pac);
4418 g_key_file_free(keyfile);
4423 static int service_save(struct connman_service *service)
4425 const char *ident = service->profile;
4427 gchar *pathname, *data = NULL;
4430 const char *cst_str = NULL;
4433 DBG("service %p", service);
4438 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
4439 if (pathname == NULL)
4442 keyfile = g_key_file_new();
4444 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
4448 if (g_key_file_load_from_data(keyfile, data, length,
4456 if (service->name != NULL)
4457 g_key_file_set_string(keyfile, service->identifier,
4458 "Name", service->name);
4460 switch (service->type) {
4461 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4462 case CONNMAN_SERVICE_TYPE_SYSTEM:
4463 case CONNMAN_SERVICE_TYPE_ETHERNET:
4464 case CONNMAN_SERVICE_TYPE_GPS:
4465 case CONNMAN_SERVICE_TYPE_VPN:
4466 case CONNMAN_SERVICE_TYPE_GADGET:
4468 case CONNMAN_SERVICE_TYPE_WIFI:
4469 if (service->network) {
4470 const unsigned char *ssid;
4471 unsigned int ssid_len = 0;
4473 ssid = connman_network_get_blob(service->network,
4474 "WiFi.SSID", &ssid_len);
4476 if (ssid != NULL && ssid_len > 0 && ssid[0] != '\0') {
4477 char *identifier = service->identifier;
4481 str = g_string_sized_new(ssid_len * 2);
4487 for (i = 0; i < ssid_len; i++)
4488 g_string_append_printf(str,
4491 g_key_file_set_string(keyfile, identifier,
4494 g_string_free(str, TRUE);
4499 case CONNMAN_SERVICE_TYPE_WIMAX:
4500 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4501 case CONNMAN_SERVICE_TYPE_CELLULAR:
4502 if (service->apn != NULL)
4503 g_key_file_set_string(keyfile, service->identifier,
4504 "APN", service->apn);
4506 if (service->username != NULL)
4507 g_key_file_set_string(keyfile, service->identifier,
4508 "Username", service->username);
4510 if (service->password != NULL)
4511 g_key_file_set_string(keyfile, service->identifier,
4512 "Password", service->password);
4514 g_key_file_set_boolean(keyfile, service->identifier,
4515 "Favorite", service->favorite);
4517 if (service->favorite == TRUE)
4518 g_key_file_set_boolean(keyfile, service->identifier,
4519 "AutoConnect", service->autoconnect);
4521 if (service->state == CONNMAN_SERVICE_STATE_FAILURE) {
4522 const char *failure = error2string(service->error);
4523 if (failure != NULL)
4524 g_key_file_set_string(keyfile,
4525 service->identifier,
4526 "Failure", failure);
4528 g_key_file_remove_key(keyfile, service->identifier,
4534 str = g_time_val_to_iso8601(&service->modified);
4536 g_key_file_set_string(keyfile, service->identifier,
4541 if (service->passphrase != NULL && strlen(service->passphrase) > 0)
4542 g_key_file_set_string(keyfile, service->identifier,
4543 "Passphrase", service->passphrase);
4545 g_key_file_remove_key(keyfile, service->identifier,
4546 "Passphrase", NULL);
4548 if (service->ipconfig != NULL) {
4549 struct connman_ipconfig *ipv6config;
4551 ipv6config = connman_ipconfig_get_ipv6config(service->ipconfig);
4552 if (ipv6config != NULL)
4553 __connman_ipconfig_save(ipv6config, keyfile,
4554 service->identifier, "IPv6.");
4556 __connman_ipconfig_save(service->ipconfig, keyfile,
4557 service->identifier, "IPv4.");
4560 if (service->nameservers != NULL) {
4561 guint len = g_strv_length(service->nameservers);
4563 g_key_file_set_string_list(keyfile, service->identifier,
4565 (const gchar **) service->nameservers, len);
4567 g_key_file_remove_key(keyfile, service->identifier,
4568 "Nameservers", NULL);
4570 if (service->domains != NULL) {
4571 guint len = g_strv_length(service->domains);
4573 g_key_file_set_string_list(keyfile, service->identifier,
4575 (const gchar **) service->domains, len);
4577 g_key_file_remove_key(keyfile, service->identifier,
4580 cst_str = proxymethod2string(service->proxy);
4581 if (cst_str != NULL)
4582 g_key_file_set_string(keyfile, service->identifier,
4583 "Proxy.Method", cst_str);
4585 if (service->proxies != NULL) {
4586 guint len = g_strv_length(service->proxies);
4588 g_key_file_set_string_list(keyfile, service->identifier,
4590 (const gchar **) service->proxies, len);
4592 g_key_file_remove_key(keyfile, service->identifier,
4593 "Proxy.Servers", NULL);
4595 if (service->excludes != NULL) {
4596 guint len = g_strv_length(service->excludes);
4598 g_key_file_set_string_list(keyfile, service->identifier,
4600 (const gchar **) service->excludes, len);
4602 g_key_file_remove_key(keyfile, service->identifier,
4603 "Proxy.Excludes", NULL);
4605 if (service->pac != NULL && strlen(service->pac) > 0)
4606 g_key_file_set_string(keyfile, service->identifier,
4607 "Proxy.URL", service->pac);
4609 g_key_file_remove_key(keyfile, service->identifier,
4612 data = g_key_file_to_data(keyfile, &length, NULL);
4614 if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
4615 connman_error("Failed to store service information");
4620 g_key_file_free(keyfile);
4627 static struct connman_storage service_storage = {
4629 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
4630 .service_load = service_load,
4631 .service_save = service_save,
4634 int __connman_service_init(void)
4638 connection = connman_dbus_get_connection();
4640 if (connman_storage_register(&service_storage) < 0)
4641 connman_error("Failed to register service storage");
4643 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
4646 service_list = g_sequence_new(service_free);
4651 void __connman_service_cleanup(void)
4655 g_sequence_free(service_list);
4656 service_list = NULL;
4658 g_hash_table_destroy(service_hash);
4659 service_hash = NULL;
4661 g_slist_free(counter_list);
4662 counter_list = NULL;
4664 connman_storage_unregister(&service_storage);
4666 dbus_connection_unref(connection);