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_ipv4;
83 struct connman_ipconfig *ipconfig_ipv6;
84 struct connman_network *network;
85 struct connman_provider *provider;
90 /* 802.1x settings from the config files */
94 char *client_cert_file;
95 char *private_key_file;
96 char *private_key_passphrase;
100 struct connman_location *location;
101 struct connman_stats stats;
102 struct connman_stats stats_roaming;
103 GHashTable *counter_table;
104 enum connman_service_proxy_method proxy;
110 static void append_path(gpointer value, gpointer user_data)
112 struct connman_service *service = value;
113 DBusMessageIter *iter = user_data;
115 if (service->path == NULL || service->hidden == TRUE)
118 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
122 void __connman_service_list(DBusMessageIter *iter, void *user_data)
124 g_sequence_foreach(service_list, append_path, iter);
129 struct connman_service *service;
132 static void compare_path(gpointer value, gpointer user_data)
134 struct connman_service *service = value;
135 struct find_data *data = user_data;
137 if (data->service != NULL)
140 if (g_strcmp0(service->path, data->path) == 0)
141 data->service = service;
144 static struct connman_service *find_service(const char *path)
146 struct find_data data = { .path = path, .service = NULL };
148 DBG("path %s", path);
150 g_sequence_foreach(service_list, compare_path, &data);
155 const char *__connman_service_type2string(enum connman_service_type type)
158 case CONNMAN_SERVICE_TYPE_UNKNOWN:
160 case CONNMAN_SERVICE_TYPE_SYSTEM:
162 case CONNMAN_SERVICE_TYPE_ETHERNET:
164 case CONNMAN_SERVICE_TYPE_WIFI:
166 case CONNMAN_SERVICE_TYPE_WIMAX:
168 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
170 case CONNMAN_SERVICE_TYPE_CELLULAR:
172 case CONNMAN_SERVICE_TYPE_GPS:
174 case CONNMAN_SERVICE_TYPE_VPN:
176 case CONNMAN_SERVICE_TYPE_GADGET:
183 static const char *mode2string(enum connman_service_mode mode)
186 case CONNMAN_SERVICE_MODE_UNKNOWN:
188 case CONNMAN_SERVICE_MODE_MANAGED:
190 case CONNMAN_SERVICE_MODE_ADHOC:
192 case CONNMAN_SERVICE_MODE_GPRS:
194 case CONNMAN_SERVICE_MODE_EDGE:
196 case CONNMAN_SERVICE_MODE_UMTS:
203 static const char *security2string(enum connman_service_security security)
206 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
208 case CONNMAN_SERVICE_SECURITY_NONE:
210 case CONNMAN_SERVICE_SECURITY_WEP:
212 case CONNMAN_SERVICE_SECURITY_PSK:
214 case CONNMAN_SERVICE_SECURITY_8021X:
216 case CONNMAN_SERVICE_SECURITY_WPA:
218 case CONNMAN_SERVICE_SECURITY_RSN:
225 static const char *state2string(enum connman_service_state state)
228 case CONNMAN_SERVICE_STATE_UNKNOWN:
230 case CONNMAN_SERVICE_STATE_IDLE:
232 case CONNMAN_SERVICE_STATE_ASSOCIATION:
233 return "association";
234 case CONNMAN_SERVICE_STATE_CONFIGURATION:
235 return "configuration";
236 case CONNMAN_SERVICE_STATE_READY:
238 case CONNMAN_SERVICE_STATE_ONLINE:
240 case CONNMAN_SERVICE_STATE_DISCONNECT:
242 case CONNMAN_SERVICE_STATE_FAILURE:
249 static const char *error2string(enum connman_service_error error)
252 case CONNMAN_SERVICE_ERROR_UNKNOWN:
254 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
255 return "out-of-range";
256 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
257 return "pin-missing";
258 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
259 return "dhcp-failed";
260 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
261 return "connect-failed";
267 static enum connman_service_error string2error(const char *error)
269 if (g_strcmp0(error, "dhcp-failed") == 0)
270 return CONNMAN_SERVICE_ERROR_DHCP_FAILED;
271 else if (g_strcmp0(error, "pin-missing") == 0)
272 return CONNMAN_SERVICE_ERROR_PIN_MISSING;
274 return CONNMAN_SERVICE_ERROR_UNKNOWN;
277 static const char *proxymethod2string(enum connman_service_proxy_method method)
280 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
282 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
284 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
286 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
293 static enum connman_service_proxy_method string2proxymethod(const char *method)
295 if (g_strcmp0(method, "direct") == 0)
296 return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
297 else if (g_strcmp0(method, "auto") == 0)
298 return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
299 else if (g_strcmp0(method, "manual") == 0)
300 return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
302 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
305 static connman_bool_t is_connecting(struct connman_service *service)
307 switch (service->state) {
308 case CONNMAN_SERVICE_STATE_UNKNOWN:
309 case CONNMAN_SERVICE_STATE_IDLE:
310 case CONNMAN_SERVICE_STATE_FAILURE:
311 if (service->network != NULL)
312 return __connman_network_get_connecting(
314 case CONNMAN_SERVICE_STATE_DISCONNECT:
315 case CONNMAN_SERVICE_STATE_READY:
316 case CONNMAN_SERVICE_STATE_ONLINE:
318 case CONNMAN_SERVICE_STATE_ASSOCIATION:
319 case CONNMAN_SERVICE_STATE_CONFIGURATION:
326 static connman_bool_t is_connected(const struct connman_service *service)
328 switch (service->state) {
329 case CONNMAN_SERVICE_STATE_UNKNOWN:
330 case CONNMAN_SERVICE_STATE_IDLE:
331 case CONNMAN_SERVICE_STATE_ASSOCIATION:
332 case CONNMAN_SERVICE_STATE_CONFIGURATION:
333 case CONNMAN_SERVICE_STATE_DISCONNECT:
334 case CONNMAN_SERVICE_STATE_FAILURE:
336 case CONNMAN_SERVICE_STATE_READY:
337 case CONNMAN_SERVICE_STATE_ONLINE:
344 static void update_nameservers(struct connman_service *service)
348 if (service->ipconfig_ipv4)
349 ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv4);
350 else if (service->ipconfig_ipv6)
351 ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv6);
358 switch (service->state) {
359 case CONNMAN_SERVICE_STATE_UNKNOWN:
360 case CONNMAN_SERVICE_STATE_IDLE:
361 case CONNMAN_SERVICE_STATE_ASSOCIATION:
362 case CONNMAN_SERVICE_STATE_CONFIGURATION:
364 case CONNMAN_SERVICE_STATE_FAILURE:
365 case CONNMAN_SERVICE_STATE_DISCONNECT:
366 connman_resolver_remove_all(ifname);
368 case CONNMAN_SERVICE_STATE_READY:
369 case CONNMAN_SERVICE_STATE_ONLINE:
373 connman_resolver_remove_all(ifname);
375 if (service->nameservers != NULL) {
378 for (i = 0; service->nameservers[i]; i++)
379 connman_resolver_append(ifname, NULL,
380 service->nameservers[i]);
381 } else if (service->nameserver != NULL)
382 connman_resolver_append(ifname, NULL, service->nameserver);
384 if (service->domains != NULL) {
387 for (i = 0; service->domains[i]; i++)
388 connman_resolver_append(ifname, service->domains[i],
390 } else if (service->domainname != NULL)
391 connman_resolver_append(ifname, service->domainname, NULL);
393 connman_resolver_flush();
396 void __connman_service_append_nameserver(struct connman_service *service,
397 const char *nameserver)
399 DBG("service %p nameserver %s", service, nameserver);
401 if (nameserver == NULL)
404 g_free(service->nameserver);
405 service->nameserver = g_strdup(nameserver);
407 update_nameservers(service);
410 void __connman_service_remove_nameserver(struct connman_service *service,
411 const char *nameserver)
413 DBG("service %p nameserver %s", service, nameserver);
415 if (nameserver == NULL)
418 g_free(service->nameserver);
419 service->nameserver = NULL;
421 update_nameservers(service);
424 void __connman_service_nameserver_add_routes(struct connman_service *service,
432 index = connman_network_get_index(service->network);
434 if (service->nameservers != NULL) {
438 * We add nameservers host routes for nameservers that
439 * are not on our subnet. For those who are, the subnet
440 * route will be installed by the time the dns proxy code
441 * tries to reach them. The subnet route is installed
442 * when setting the interface IP address.
444 for (i = 0; service->nameservers[i]; i++) {
445 if (connman_inet_compare_subnet(index,
446 service->nameservers[i]))
449 connman_inet_add_host_route(index,
450 service->nameservers[i], gw);
452 } else if (service->nameserver != NULL) {
453 if (connman_inet_compare_subnet(index, service->nameserver))
456 connman_inet_add_host_route(index, service->nameserver, gw);
460 void __connman_service_nameserver_del_routes(struct connman_service *service)
467 index = connman_network_get_index(service->network);
469 if (service->nameservers != NULL) {
472 for (i = 0; service->nameservers[i]; i++)
473 connman_inet_del_host_route(index,
474 service->nameservers[i]);
475 } else if (service->nameserver != NULL) {
476 connman_inet_del_host_route(index, service->nameserver);
480 static struct connman_stats *stats_get(struct connman_service *service)
482 if (service->roaming == TRUE)
483 return &service->stats_roaming;
485 return &service->stats;
488 static connman_bool_t stats_enabled(struct connman_service *service)
490 struct connman_stats *stats = stats_get(service);
492 return stats->enabled;
495 static void stats_start(struct connman_service *service)
497 struct connman_stats *stats = stats_get(service);
499 DBG("service %p", service);
501 if (stats->timer == NULL)
504 stats->enabled = TRUE;
505 stats->data_last.time = stats->data.time;
507 g_timer_start(stats->timer);
510 static void stats_stop(struct connman_service *service)
512 struct connman_stats *stats = stats_get(service);
513 unsigned int seconds;
515 DBG("service %p", service);
517 if (stats->timer == NULL)
520 if (stats->enabled == FALSE)
523 g_timer_stop(stats->timer);
525 seconds = g_timer_elapsed(stats->timer, NULL);
526 stats->data.time = stats->data_last.time + seconds;
528 stats->enabled = FALSE;
531 static void reset_stats(struct connman_service *service)
533 DBG("service %p", service);
536 service->stats.valid = FALSE;
538 service->stats.data.rx_packets = 0;
539 service->stats.data.tx_packets = 0;
540 service->stats.data.rx_bytes = 0;
541 service->stats.data.tx_bytes = 0;
542 service->stats.data.rx_errors = 0;
543 service->stats.data.tx_errors = 0;
544 service->stats.data.rx_dropped = 0;
545 service->stats.data.tx_dropped = 0;
546 service->stats.data.time = 0;
547 service->stats.data_last.time = 0;
549 g_timer_reset(service->stats.timer);
552 service->stats_roaming.valid = FALSE;
554 service->stats_roaming.data.rx_packets = 0;
555 service->stats_roaming.data.tx_packets = 0;
556 service->stats_roaming.data.rx_bytes = 0;
557 service->stats_roaming.data.tx_bytes = 0;
558 service->stats_roaming.data.rx_errors = 0;
559 service->stats_roaming.data.tx_errors = 0;
560 service->stats_roaming.data.rx_dropped = 0;
561 service->stats_roaming.data.tx_dropped = 0;
562 service->stats_roaming.data.time = 0;
563 service->stats_roaming.data_last.time = 0;
565 g_timer_reset(service->stats_roaming.timer);
568 static struct connman_service *get_default(void)
570 struct connman_service *service;
573 iter = g_sequence_get_begin_iter(service_list);
575 if (g_sequence_iter_is_end(iter) == TRUE)
578 service = g_sequence_get(iter);
580 if (is_connected(service) == FALSE)
586 static void default_changed(void)
588 struct connman_service *service = get_default();
590 __connman_notifier_default_changed(service);
593 const char *__connman_service_default(void)
595 struct connman_service *service;
597 service = get_default();
601 return __connman_service_type2string(service->type);
604 static void mode_changed(struct connman_service *service)
608 str = mode2string(service->mode);
612 connman_dbus_property_changed_basic(service->path,
613 CONNMAN_SERVICE_INTERFACE, "Mode",
614 DBUS_TYPE_STRING, &str);
617 static void state_changed(struct connman_service *service)
621 str = state2string(service->state);
625 connman_dbus_property_changed_basic(service->path,
626 CONNMAN_SERVICE_INTERFACE, "State",
627 DBUS_TYPE_STRING, &str);
630 static void strength_changed(struct connman_service *service)
632 if (service->strength == 0)
635 connman_dbus_property_changed_basic(service->path,
636 CONNMAN_SERVICE_INTERFACE, "Strength",
637 DBUS_TYPE_BYTE, &service->strength);
640 static void favorite_changed(struct connman_service *service)
642 if (service->path == NULL)
645 connman_dbus_property_changed_basic(service->path,
646 CONNMAN_SERVICE_INTERFACE, "Favorite",
647 DBUS_TYPE_BOOLEAN, &service->favorite);
650 static void immutable_changed(struct connman_service *service)
652 if (service->path == NULL)
655 connman_dbus_property_changed_basic(service->path,
656 CONNMAN_SERVICE_INTERFACE, "Immutable",
657 DBUS_TYPE_BOOLEAN, &service->immutable);
660 static void roaming_changed(struct connman_service *service)
662 if (service->path == NULL)
665 connman_dbus_property_changed_basic(service->path,
666 CONNMAN_SERVICE_INTERFACE, "Roaming",
667 DBUS_TYPE_BOOLEAN, &service->roaming);
670 static void autoconnect_changed(struct connman_service *service)
672 if (service->path == NULL)
675 connman_dbus_property_changed_basic(service->path,
676 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
677 DBUS_TYPE_BOOLEAN, &service->autoconnect);
680 static void passphrase_changed(struct connman_service *service)
682 dbus_bool_t required;
684 switch (service->type) {
685 case CONNMAN_SERVICE_TYPE_UNKNOWN:
686 case CONNMAN_SERVICE_TYPE_SYSTEM:
687 case CONNMAN_SERVICE_TYPE_ETHERNET:
688 case CONNMAN_SERVICE_TYPE_WIMAX:
689 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
690 case CONNMAN_SERVICE_TYPE_CELLULAR:
691 case CONNMAN_SERVICE_TYPE_GPS:
692 case CONNMAN_SERVICE_TYPE_VPN:
693 case CONNMAN_SERVICE_TYPE_GADGET:
695 case CONNMAN_SERVICE_TYPE_WIFI:
698 switch (service->security) {
699 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
700 case CONNMAN_SERVICE_SECURITY_NONE:
702 case CONNMAN_SERVICE_SECURITY_WEP:
703 case CONNMAN_SERVICE_SECURITY_PSK:
704 case CONNMAN_SERVICE_SECURITY_WPA:
705 case CONNMAN_SERVICE_SECURITY_RSN:
706 if (service->passphrase == NULL)
709 case CONNMAN_SERVICE_SECURITY_8021X:
715 connman_dbus_property_changed_basic(service->path,
716 CONNMAN_SERVICE_INTERFACE, "PassphraseRequired",
717 DBUS_TYPE_BOOLEAN, &required);
720 static void login_changed(struct connman_service *service)
722 dbus_bool_t required = service->login_required;
724 if (service->path == NULL)
727 connman_dbus_property_changed_basic(service->path,
728 CONNMAN_SERVICE_INTERFACE, "LoginRequired",
729 DBUS_TYPE_BOOLEAN, &required);
732 static void apn_changed(struct connman_service *service)
734 dbus_bool_t required;
736 switch (service->type) {
737 case CONNMAN_SERVICE_TYPE_UNKNOWN:
738 case CONNMAN_SERVICE_TYPE_SYSTEM:
739 case CONNMAN_SERVICE_TYPE_ETHERNET:
740 case CONNMAN_SERVICE_TYPE_WIMAX:
741 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
742 case CONNMAN_SERVICE_TYPE_WIFI:
743 case CONNMAN_SERVICE_TYPE_GPS:
744 case CONNMAN_SERVICE_TYPE_VPN:
745 case CONNMAN_SERVICE_TYPE_GADGET:
747 case CONNMAN_SERVICE_TYPE_CELLULAR:
751 required = (service->apn == NULL) ? TRUE : FALSE;
753 connman_dbus_property_changed_basic(service->path,
754 CONNMAN_SERVICE_INTERFACE, "SetupRequired",
755 DBUS_TYPE_BOOLEAN, &required);
758 static void append_ethernet(DBusMessageIter *iter, void *user_data)
760 struct connman_service *service = user_data;
762 if (service->ipconfig_ipv4 != NULL)
763 __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
765 else if (service->ipconfig_ipv6 != NULL)
766 __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
770 static void append_ipv4(DBusMessageIter *iter, void *user_data)
772 struct connman_service *service = user_data;
774 if (is_connected(service) == FALSE)
777 if (service->ipconfig_ipv4 != NULL)
778 __connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
781 static void append_ipv6(DBusMessageIter *iter, void *user_data)
783 struct connman_service *service = user_data;
785 if (is_connected(service) == FALSE)
788 if (service->ipconfig_ipv6 != NULL)
789 __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter);
792 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
794 struct connman_service *service = user_data;
796 if (service->ipconfig_ipv4 != NULL)
797 __connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
801 static void append_ipv6config(DBusMessageIter *iter, void *user_data)
803 struct connman_service *service = user_data;
805 if (service->ipconfig_ipv6 != NULL)
806 __connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
810 static void append_dns(DBusMessageIter *iter, void *user_data)
812 struct connman_service *service = user_data;
814 if (is_connected(service) == FALSE)
817 if (service->nameservers != NULL) {
820 for (i = 0; service->nameservers[i]; i++)
821 dbus_message_iter_append_basic(iter,
822 DBUS_TYPE_STRING, &service->nameservers[i]);
827 if (service->nameserver == NULL)
830 dbus_message_iter_append_basic(iter,
831 DBUS_TYPE_STRING, &service->nameserver);
834 static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
836 struct connman_service *service = user_data;
839 if (service->nameservers == NULL)
842 for (i = 0; service->nameservers[i]; i++)
843 dbus_message_iter_append_basic(iter,
844 DBUS_TYPE_STRING, &service->nameservers[i]);
847 static void append_domain(DBusMessageIter *iter, void *user_data)
849 struct connman_service *service = user_data;
851 if (is_connected(service) == FALSE && is_connecting(service) == FALSE)
854 if (service->domainname == NULL)
857 dbus_message_iter_append_basic(iter,
858 DBUS_TYPE_STRING, &service->domainname);
861 static void append_domainconfig(DBusMessageIter *iter, void *user_data)
863 struct connman_service *service = user_data;
866 if (service->domains == NULL)
869 for (i = 0; service->domains[i]; i++)
870 dbus_message_iter_append_basic(iter,
871 DBUS_TYPE_STRING, &service->domains[i]);
874 static void append_proxies(DBusMessageIter *iter, void *user_data)
876 struct connman_service *service = user_data;
879 if (service->proxies == NULL)
882 for (i = 0; service->proxies[i]; i++)
883 dbus_message_iter_append_basic(iter,
884 DBUS_TYPE_STRING, &service->proxies[i]);
887 static void append_excludes(DBusMessageIter *iter, void *user_data)
889 struct connman_service *service = user_data;
892 if (service->excludes == NULL)
895 for (i = 0; service->excludes[i]; i++)
896 dbus_message_iter_append_basic(iter,
897 DBUS_TYPE_STRING, &service->excludes[i]);
900 static void append_proxy(DBusMessageIter *iter, void *user_data)
902 struct connman_service *service = user_data;
903 const char *pac = NULL;
904 const char *method = proxymethod2string(
905 CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
909 if (is_connected(service) == FALSE)
912 switch (service->proxy) {
913 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
914 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
916 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
918 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
919 connman_dbus_dict_append_array(iter, "Servers",
920 DBUS_TYPE_STRING, append_proxies,
923 connman_dbus_dict_append_array(iter, "Excludes",
924 DBUS_TYPE_STRING, append_excludes,
927 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
928 /* Maybe DHCP, or WPAD, has provided an url for a pac file */
929 if (service->ipconfig_ipv4 != NULL)
930 pac = __connman_ipconfig_get_proxy_autoconfig(
931 service->ipconfig_ipv4);
932 else if (service->ipconfig_ipv6 != NULL)
933 pac = __connman_ipconfig_get_proxy_autoconfig(
934 service->ipconfig_ipv6);
936 if (service->pac == NULL && pac == NULL)
939 if (service->pac != NULL)
942 connman_dbus_dict_append_basic(iter, "URL",
943 DBUS_TYPE_STRING, &pac);
947 method = proxymethod2string(service->proxy);
950 connman_dbus_dict_append_basic(iter, "Method",
951 DBUS_TYPE_STRING, &method);
954 static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
956 struct connman_service *service = user_data;
959 switch (service->proxy) {
960 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
962 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
963 if (service->proxies != NULL)
964 connman_dbus_dict_append_array(iter, "Servers",
966 append_proxies, service);
968 if (service->excludes != NULL)
969 connman_dbus_dict_append_array(iter, "Excludes",
971 append_excludes, service);
973 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
974 if (service->pac != NULL)
975 connman_dbus_dict_append_basic(iter, "URL",
976 DBUS_TYPE_STRING, &service->pac);
978 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
979 service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
983 method = proxymethod2string(service->proxy);
985 connman_dbus_dict_append_basic(iter, "Method",
986 DBUS_TYPE_STRING, &method);
989 static void append_provider(DBusMessageIter *iter, void *user_data)
991 struct connman_service *service = user_data;
993 DBG("%p %p", service, service->provider);
995 if (is_connected(service) == FALSE)
998 if (service->provider != NULL)
999 __connman_provider_append_properties(service->provider, iter);
1003 static void settings_changed(struct connman_service *service)
1005 connman_dbus_property_changed_dict(service->path,
1006 CONNMAN_SERVICE_INTERFACE, "IPv4",
1007 append_ipv4, service);
1009 connman_dbus_property_changed_dict(service->path,
1010 CONNMAN_SERVICE_INTERFACE, "IPv6",
1011 append_ipv6, service);
1014 static void ipv4_configuration_changed(struct connman_service *service)
1016 connman_dbus_property_changed_dict(service->path,
1017 CONNMAN_SERVICE_INTERFACE,
1018 "IPv4.Configuration",
1023 static void ipv6_configuration_changed(struct connman_service *service)
1025 connman_dbus_property_changed_dict(service->path,
1026 CONNMAN_SERVICE_INTERFACE,
1027 "IPv6.Configuration",
1032 static void dns_changed(struct connman_service *service)
1034 connman_dbus_property_changed_array(service->path,
1035 CONNMAN_SERVICE_INTERFACE, "Nameservers",
1036 DBUS_TYPE_STRING, append_dns, service);
1039 static void dns_configuration_changed(struct connman_service *service)
1041 connman_dbus_property_changed_array(service->path,
1042 CONNMAN_SERVICE_INTERFACE,
1043 "Nameservers.Configuration",
1044 DBUS_TYPE_STRING, append_dnsconfig, service);
1046 dns_changed(service);
1049 static void domain_changed(struct connman_service *service)
1051 connman_dbus_property_changed_array(service->path,
1052 CONNMAN_SERVICE_INTERFACE, "Domains",
1053 DBUS_TYPE_STRING, append_domain, service);
1056 static void domain_configuration_changed(struct connman_service *service)
1058 connman_dbus_property_changed_array(service->path,
1059 CONNMAN_SERVICE_INTERFACE,
1060 "Domains.Configuration",
1061 DBUS_TYPE_STRING, append_domainconfig, service);
1064 static void proxy_changed(struct connman_service *service)
1066 connman_dbus_property_changed_dict(service->path,
1067 CONNMAN_SERVICE_INTERFACE, "Proxy",
1068 append_proxy, service);
1071 static void proxy_configuration_changed(struct connman_service *service)
1073 connman_dbus_property_changed_dict(service->path,
1074 CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
1075 append_proxyconfig, service);
1077 proxy_changed(service);
1080 static void link_changed(struct connman_service *service)
1082 connman_dbus_property_changed_dict(service->path,
1083 CONNMAN_SERVICE_INTERFACE, "Ethernet",
1084 append_ethernet, service);
1087 static void stats_append_counters(DBusMessageIter *dict,
1088 struct connman_stats_data *stats,
1089 struct connman_stats_data *counters,
1090 connman_bool_t append_all)
1092 if (counters->rx_packets != stats->rx_packets || append_all) {
1093 counters->rx_packets = stats->rx_packets;
1094 connman_dbus_dict_append_basic(dict, "RX.Packets",
1095 DBUS_TYPE_UINT32, &stats->rx_packets);
1098 if (counters->tx_packets != stats->tx_packets || append_all) {
1099 counters->tx_packets = stats->tx_packets;
1100 connman_dbus_dict_append_basic(dict, "TX.Packets",
1101 DBUS_TYPE_UINT32, &stats->tx_packets);
1104 if (counters->rx_bytes != stats->rx_bytes || append_all) {
1105 counters->rx_bytes = stats->rx_bytes;
1106 connman_dbus_dict_append_basic(dict, "RX.Bytes",
1107 DBUS_TYPE_UINT32, &stats->rx_bytes);
1110 if (counters->tx_bytes != stats->tx_bytes || append_all) {
1111 counters->tx_bytes = stats->tx_bytes;
1112 connman_dbus_dict_append_basic(dict, "TX.Bytes",
1113 DBUS_TYPE_UINT32, &stats->tx_bytes);
1116 if (counters->rx_errors != stats->rx_errors || append_all) {
1117 counters->rx_errors = stats->rx_errors;
1118 connman_dbus_dict_append_basic(dict, "RX.Errors",
1119 DBUS_TYPE_UINT32, &stats->rx_errors);
1122 if (counters->tx_errors != stats->tx_errors || append_all) {
1123 counters->tx_errors = stats->tx_errors;
1124 connman_dbus_dict_append_basic(dict, "TX.Errors",
1125 DBUS_TYPE_UINT32, &stats->tx_errors);
1128 if (counters->rx_dropped != stats->rx_dropped || append_all) {
1129 counters->rx_dropped = stats->rx_dropped;
1130 connman_dbus_dict_append_basic(dict, "RX.Dropped",
1131 DBUS_TYPE_UINT32, &stats->rx_dropped);
1134 if (counters->tx_dropped != stats->tx_dropped || append_all) {
1135 counters->tx_dropped = stats->tx_dropped;
1136 connman_dbus_dict_append_basic(dict, "TX.Dropped",
1137 DBUS_TYPE_UINT32, &stats->tx_dropped);
1140 if (counters->time != stats->time || append_all) {
1141 counters->time = stats->time;
1142 connman_dbus_dict_append_basic(dict, "Time",
1143 DBUS_TYPE_UINT32, &stats->time);
1147 static void stats_append(struct connman_service *service,
1148 const char *counter,
1149 struct connman_stats_counter *counters,
1150 connman_bool_t append_all)
1152 DBusMessageIter array, dict;
1155 DBG("service %p counter %s", service, counter);
1157 msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
1161 dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
1162 &service->path, DBUS_TYPE_INVALID);
1164 dbus_message_iter_init_append(msg, &array);
1167 connman_dbus_dict_open(&array, &dict);
1169 stats_append_counters(&dict, &service->stats.data,
1170 &counters->stats.data, append_all);
1172 connman_dbus_dict_close(&array, &dict);
1174 /* roaming counter */
1175 connman_dbus_dict_open(&array, &dict);
1177 stats_append_counters(&dict, &service->stats_roaming.data,
1178 &counters->stats_roaming.data, append_all);
1180 connman_dbus_dict_close(&array, &dict);
1182 __connman_counter_send_usage(counter, msg);
1185 static void stats_update(struct connman_service *service,
1186 unsigned int rx_packets, unsigned int tx_packets,
1187 unsigned int rx_bytes, unsigned int tx_bytes,
1188 unsigned int rx_errors, unsigned int tx_errors,
1189 unsigned int rx_dropped, unsigned int tx_dropped)
1191 struct connman_stats *stats = stats_get(service);
1192 struct connman_stats_data *data_last = &stats->data_last;
1193 struct connman_stats_data *data = &stats->data;
1194 unsigned int seconds;
1196 DBG("service %p", service);
1198 if (stats->valid == TRUE) {
1200 rx_packets - data_last->rx_packets;
1202 tx_packets - data_last->tx_packets;
1204 rx_bytes - data_last->rx_bytes;
1206 tx_bytes - data_last->tx_bytes;
1208 rx_errors - data_last->rx_errors;
1210 tx_errors - data_last->tx_errors;
1212 rx_dropped - data_last->rx_dropped;
1214 tx_dropped - data_last->tx_dropped;
1216 stats->valid = TRUE;
1219 data_last->rx_packets = rx_packets;
1220 data_last->tx_packets = tx_packets;
1221 data_last->rx_bytes = rx_bytes;
1222 data_last->tx_bytes = tx_bytes;
1223 data_last->rx_errors = rx_errors;
1224 data_last->tx_errors = tx_errors;
1225 data_last->rx_dropped = rx_dropped;
1226 data_last->tx_dropped = tx_dropped;
1228 seconds = g_timer_elapsed(stats->timer, NULL);
1229 stats->data.time = stats->data_last.time + seconds;
1232 void __connman_service_notify(struct connman_service *service,
1233 unsigned int rx_packets, unsigned int tx_packets,
1234 unsigned int rx_bytes, unsigned int tx_bytes,
1235 unsigned int rx_errors, unsigned int tx_errors,
1236 unsigned int rx_dropped, unsigned int tx_dropped)
1238 GHashTableIter iter;
1239 gpointer key, value;
1240 const char *counter;
1241 struct connman_stats_counter *counters;
1242 struct connman_stats_data *data;
1245 if (service == NULL)
1248 if (is_connected(service) == FALSE)
1251 stats_update(service,
1252 rx_packets, tx_packets,
1254 rx_errors, tx_errors,
1255 rx_dropped, tx_dropped);
1257 data = &stats_get(service)->data;
1258 err = __connman_stats_update(service, service->roaming, data);
1260 connman_error("Failed to store statistics for %s",
1261 service->identifier);
1263 g_hash_table_iter_init(&iter, service->counter_table);
1264 while (g_hash_table_iter_next(&iter, &key, &value)) {
1268 stats_append(service, counter, counters, counters->append_all);
1269 counters->append_all = FALSE;
1273 int __connman_service_counter_register(const char *counter)
1275 struct connman_service *service;
1276 GSequenceIter *iter;
1277 struct connman_stats_counter *counters;
1279 DBG("counter %s", counter);
1281 counter_list = g_slist_append(counter_list, (gpointer)counter);
1283 iter = g_sequence_get_begin_iter(service_list);
1285 while (g_sequence_iter_is_end(iter) == FALSE) {
1286 service = g_sequence_get(iter);
1288 counters = g_try_new0(struct connman_stats_counter, 1);
1289 if (counters == NULL)
1292 counters->append_all = TRUE;
1294 g_hash_table_replace(service->counter_table, (gpointer)counter,
1297 iter = g_sequence_iter_next(iter);
1303 void __connman_service_counter_unregister(const char *counter)
1305 struct connman_service *service;
1306 GSequenceIter *iter;
1308 DBG("counter %s", counter);
1310 iter = g_sequence_get_begin_iter(service_list);
1312 while (g_sequence_iter_is_end(iter) == FALSE) {
1313 service = g_sequence_get(iter);
1315 g_hash_table_remove(service->counter_table, counter);
1317 iter = g_sequence_iter_next(iter);
1320 counter_list = g_slist_remove(counter_list, counter);
1323 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
1324 struct connman_service *service)
1326 dbus_bool_t required;
1329 str = __connman_service_type2string(service->type);
1331 connman_dbus_dict_append_basic(dict, "Type",
1332 DBUS_TYPE_STRING, &str);
1334 str = mode2string(service->mode);
1336 connman_dbus_dict_append_basic(dict, "Mode",
1337 DBUS_TYPE_STRING, &str);
1339 str = security2string(service->security);
1341 connman_dbus_dict_append_basic(dict, "Security",
1342 DBUS_TYPE_STRING, &str);
1344 str = state2string(service->state);
1346 connman_dbus_dict_append_basic(dict, "State",
1347 DBUS_TYPE_STRING, &str);
1349 str = error2string(service->error);
1351 connman_dbus_dict_append_basic(dict, "Error",
1352 DBUS_TYPE_STRING, &str);
1354 if (service->strength > 0)
1355 connman_dbus_dict_append_basic(dict, "Strength",
1356 DBUS_TYPE_BYTE, &service->strength);
1358 connman_dbus_dict_append_basic(dict, "Favorite",
1359 DBUS_TYPE_BOOLEAN, &service->favorite);
1361 connman_dbus_dict_append_basic(dict, "Immutable",
1362 DBUS_TYPE_BOOLEAN, &service->immutable);
1364 if (service->favorite == TRUE)
1365 connman_dbus_dict_append_basic(dict, "AutoConnect",
1366 DBUS_TYPE_BOOLEAN, &service->autoconnect);
1368 connman_dbus_dict_append_basic(dict, "AutoConnect",
1369 DBUS_TYPE_BOOLEAN, &service->favorite);
1371 if (service->name != NULL)
1372 connman_dbus_dict_append_basic(dict, "Name",
1373 DBUS_TYPE_STRING, &service->name);
1375 connman_dbus_dict_append_basic(dict, "LoginRequired",
1376 DBUS_TYPE_BOOLEAN, &service->login_required);
1378 switch (service->type) {
1379 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1380 case CONNMAN_SERVICE_TYPE_SYSTEM:
1381 case CONNMAN_SERVICE_TYPE_GPS:
1382 case CONNMAN_SERVICE_TYPE_VPN:
1383 case CONNMAN_SERVICE_TYPE_GADGET:
1385 case CONNMAN_SERVICE_TYPE_CELLULAR:
1386 connman_dbus_dict_append_basic(dict, "Roaming",
1387 DBUS_TYPE_BOOLEAN, &service->roaming);
1389 if (service->mcc != NULL && service->mnc != NULL) {
1390 connman_dbus_dict_append_basic(dict, "MCC",
1391 DBUS_TYPE_STRING, &service->mcc);
1392 connman_dbus_dict_append_basic(dict, "MNC",
1393 DBUS_TYPE_STRING, &service->mnc);
1396 if (service->apn != NULL) {
1397 connman_dbus_dict_append_basic(dict, "APN",
1398 DBUS_TYPE_STRING, &service->apn);
1400 if (service->username != NULL)
1401 connman_dbus_dict_append_basic(dict,
1402 "Username", DBUS_TYPE_STRING,
1403 &service->username);
1405 if (service->password != NULL)
1406 connman_dbus_dict_append_basic(dict,
1407 "Password", DBUS_TYPE_STRING,
1408 &service->password);
1414 connman_dbus_dict_append_basic(dict, "SetupRequired",
1415 DBUS_TYPE_BOOLEAN, &required);
1416 connman_dbus_dict_append_dict(dict, "Ethernet",
1417 append_ethernet, service);
1419 case CONNMAN_SERVICE_TYPE_WIFI:
1420 if (service->passphrase != NULL && limited == FALSE)
1421 connman_dbus_dict_append_basic(dict, "Passphrase",
1422 DBUS_TYPE_STRING, &service->passphrase);
1426 switch (service->security) {
1427 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1428 case CONNMAN_SERVICE_SECURITY_NONE:
1430 case CONNMAN_SERVICE_SECURITY_WEP:
1431 case CONNMAN_SERVICE_SECURITY_PSK:
1432 case CONNMAN_SERVICE_SECURITY_WPA:
1433 case CONNMAN_SERVICE_SECURITY_RSN:
1434 if (service->passphrase == NULL)
1437 case CONNMAN_SERVICE_SECURITY_8021X:
1441 connman_dbus_dict_append_basic(dict, "PassphraseRequired",
1442 DBUS_TYPE_BOOLEAN, &required);
1444 case CONNMAN_SERVICE_TYPE_ETHERNET:
1445 case CONNMAN_SERVICE_TYPE_WIMAX:
1446 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1447 connman_dbus_dict_append_dict(dict, "Ethernet",
1448 append_ethernet, service);
1452 connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
1454 connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
1455 append_ipv4config, service);
1457 connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
1459 connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
1460 append_ipv6config, service);
1462 connman_dbus_dict_append_array(dict, "Nameservers",
1463 DBUS_TYPE_STRING, append_dns, service);
1465 connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
1466 DBUS_TYPE_STRING, append_dnsconfig, service);
1468 connman_dbus_dict_append_array(dict, "Domains",
1469 DBUS_TYPE_STRING, append_domain, service);
1471 connman_dbus_dict_append_array(dict, "Domains.Configuration",
1472 DBUS_TYPE_STRING, append_domainconfig, service);
1474 connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
1476 connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
1477 append_proxyconfig, service);
1479 connman_dbus_dict_append_dict(dict, "Provider",
1480 append_provider, service);
1483 static void append_struct(gpointer value, gpointer user_data)
1485 struct connman_service *service = value;
1486 DBusMessageIter *iter = user_data;
1487 DBusMessageIter entry, dict;
1489 if (service->path == NULL || service->hidden == TRUE)
1492 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
1494 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
1497 connman_dbus_dict_open(&entry, &dict);
1498 append_properties(&dict, TRUE, service);
1499 connman_dbus_dict_close(&entry, &dict);
1501 dbus_message_iter_close_container(iter, &entry);
1504 void __connman_service_list_struct(DBusMessageIter *iter)
1506 g_sequence_foreach(service_list, append_struct, iter);
1509 int __connman_service_get_index(struct connman_service *service)
1511 if (service == NULL)
1514 if (service->network == NULL)
1517 return connman_network_get_index(service->network);
1520 void __connman_service_set_domainname(struct connman_service *service,
1521 const char *domainname)
1523 if (service == NULL)
1526 g_free(service->domainname);
1527 service->domainname = g_strdup(domainname);
1529 domain_changed(service);
1532 const char *connman_service_get_domainname(struct connman_service *service)
1534 if (service == NULL)
1537 if (service->domains != NULL)
1538 return service->domains[0];
1540 return service->domainname;
1543 const char *connman_service_get_nameserver(struct connman_service *service)
1545 if (service == NULL)
1548 return service->nameserver;
1551 enum connman_service_proxy_method connman_service_get_proxy_method(
1552 struct connman_service *service)
1554 if (service == NULL)
1555 return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
1557 return service->proxy;
1560 char **connman_service_get_proxy_servers(struct connman_service *service)
1562 return g_strdupv(service->proxies);
1565 char **connman_service_get_proxy_excludes(struct connman_service *service)
1567 return g_strdupv(service->excludes);
1570 const char *connman_service_get_proxy_url(struct connman_service *service)
1572 if (service == NULL)
1575 return service->pac;
1578 void __connman_service_set_proxy_autoconfig(struct connman_service *service,
1581 if (service == NULL)
1584 if (service->ipconfig_ipv4) {
1585 if (__connman_ipconfig_set_proxy_autoconfig(
1586 service->ipconfig_ipv4, url) < 0)
1588 } else if (service->ipconfig_ipv6) {
1589 if (__connman_ipconfig_set_proxy_autoconfig(
1590 service->ipconfig_ipv6, url) < 0)
1595 proxy_changed(service);
1598 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
1600 if (service == NULL)
1603 if (service->ipconfig_ipv4)
1604 return __connman_ipconfig_get_proxy_autoconfig(
1605 service->ipconfig_ipv4);
1606 else if (service->ipconfig_ipv6)
1607 return __connman_ipconfig_get_proxy_autoconfig(
1608 service->ipconfig_ipv6);
1612 void __connman_service_set_passphrase(struct connman_service *service,
1613 const char* passphrase)
1615 if (service->immutable == TRUE)
1618 g_free(service->passphrase);
1619 service->passphrase = g_strdup(passphrase);
1621 passphrase_changed(service);
1623 if (service->network != NULL)
1624 connman_network_set_string(service->network,
1626 service->passphrase);
1628 __connman_storage_save_service(service);
1631 static DBusMessage *get_properties(DBusConnection *conn,
1632 DBusMessage *msg, void *user_data)
1634 struct connman_service *service = user_data;
1636 DBusMessageIter array, dict;
1638 DBG("service %p", service);
1640 reply = dbus_message_new_method_return(msg);
1644 dbus_message_iter_init_append(reply, &array);
1646 connman_dbus_dict_open(&array, &dict);
1647 append_properties(&dict, FALSE, service);
1648 connman_dbus_dict_close(&array, &dict);
1653 static int update_proxy_configuration(struct connman_service *service,
1654 DBusMessageIter *array)
1656 DBusMessageIter dict;
1657 enum connman_service_proxy_method method;
1658 GString *servers_str = NULL;
1659 GString *excludes_str = NULL;
1660 const char *url = NULL;
1662 method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
1664 dbus_message_iter_recurse(array, &dict);
1666 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1667 DBusMessageIter entry, variant;
1671 dbus_message_iter_recurse(&dict, &entry);
1673 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1676 dbus_message_iter_get_basic(&entry, &key);
1677 dbus_message_iter_next(&entry);
1679 if (dbus_message_iter_get_arg_type(&entry) !=
1683 dbus_message_iter_recurse(&entry, &variant);
1684 type = dbus_message_iter_get_arg_type(&variant);
1686 if (g_str_equal(key, "Method") == TRUE) {
1689 if (type != DBUS_TYPE_STRING)
1692 dbus_message_iter_get_basic(&variant, &val);
1693 method = string2proxymethod(val);
1694 } else if (g_str_equal(key, "URL") == TRUE) {
1695 if (type != DBUS_TYPE_STRING)
1698 dbus_message_iter_get_basic(&variant, &url);
1699 } else if (g_str_equal(key, "Servers") == TRUE) {
1700 DBusMessageIter str_array;
1702 if (type != DBUS_TYPE_ARRAY)
1705 servers_str = g_string_new(NULL);
1706 if (servers_str == NULL)
1709 dbus_message_iter_recurse(&variant, &str_array);
1711 while (dbus_message_iter_get_arg_type(&str_array) ==
1715 dbus_message_iter_get_basic(&str_array, &val);
1717 if (servers_str->len > 0)
1718 g_string_append_printf(servers_str,
1721 g_string_append(servers_str, val);
1723 dbus_message_iter_next(&str_array);
1725 } else if (g_str_equal(key, "Excludes") == TRUE) {
1726 DBusMessageIter str_array;
1728 if (type != DBUS_TYPE_ARRAY)
1731 excludes_str = g_string_new(NULL);
1732 if (excludes_str == NULL)
1735 dbus_message_iter_recurse(&variant, &str_array);
1737 while (dbus_message_iter_get_arg_type(&str_array) ==
1741 dbus_message_iter_get_basic(&str_array, &val);
1743 if (excludes_str->len > 0)
1744 g_string_append_printf(excludes_str,
1747 g_string_append(excludes_str, val);
1749 dbus_message_iter_next(&str_array);
1753 dbus_message_iter_next(&dict);
1757 case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
1759 case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
1760 if (servers_str == NULL && service->proxies == NULL)
1763 if (servers_str != NULL) {
1764 g_strfreev(service->proxies);
1766 if (servers_str->len > 0)
1767 service->proxies = g_strsplit_set(
1768 servers_str->str, " ", 0);
1770 service->proxies = NULL;
1773 if (excludes_str != NULL) {
1774 g_strfreev(service->excludes);
1776 if (excludes_str->len > 0)
1777 service->excludes = g_strsplit_set(
1778 excludes_str->str, " ", 0);
1780 service->excludes = NULL;
1783 if (service->proxies == NULL)
1784 method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
1787 case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
1788 g_free(service->pac);
1790 if (url != NULL && strlen(url) > 0)
1791 service->pac = g_strdup(url);
1793 service->pac = NULL;
1795 /* if we are connected:
1796 - if service->pac == NULL
1797 - if __connman_ipconfig_get_proxy_autoconfig(
1798 service->ipconfig) == NULL
1799 --> We should start WPAD */
1802 case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
1806 if (servers_str != NULL)
1807 g_string_free(servers_str, TRUE);
1809 if (excludes_str != NULL)
1810 g_string_free(excludes_str, TRUE);
1812 service->proxy = method;
1817 if (servers_str != NULL)
1818 g_string_free(servers_str, TRUE);
1820 if (excludes_str != NULL)
1821 g_string_free(excludes_str, TRUE);
1826 static DBusMessage *set_property(DBusConnection *conn,
1827 DBusMessage *msg, void *user_data)
1829 struct connman_service *service = user_data;
1830 DBusMessageIter iter, value;
1834 DBG("service %p", service);
1836 if (dbus_message_iter_init(msg, &iter) == FALSE)
1837 return __connman_error_invalid_arguments(msg);
1839 dbus_message_iter_get_basic(&iter, &name);
1840 dbus_message_iter_next(&iter);
1841 dbus_message_iter_recurse(&iter, &value);
1843 type = dbus_message_iter_get_arg_type(&value);
1845 if (g_str_has_prefix(name, "AutoConnect") == TRUE) {
1846 connman_bool_t autoconnect;
1848 if (type != DBUS_TYPE_BOOLEAN)
1849 return __connman_error_invalid_arguments(msg);
1851 if (service->favorite == FALSE)
1852 return __connman_error_invalid_service(msg);
1854 dbus_message_iter_get_basic(&value, &autoconnect);
1856 if (service->autoconnect == autoconnect)
1857 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1859 service->autoconnect = autoconnect;
1861 autoconnect_changed(service);
1863 __connman_storage_save_service(service);
1864 } else if (g_str_equal(name, "Passphrase") == TRUE) {
1865 const char *passphrase;
1867 if (type != DBUS_TYPE_STRING)
1868 return __connman_error_invalid_arguments(msg);
1870 if (service->immutable == TRUE)
1871 return __connman_error_not_supported(msg);
1873 dbus_message_iter_get_basic(&value, &passphrase);
1875 __connman_service_set_passphrase(service, passphrase);
1876 } else if (g_str_equal(name, "APN") == TRUE) {
1879 if (type != DBUS_TYPE_STRING)
1880 return __connman_error_invalid_arguments(msg);
1882 if (service->immutable == TRUE)
1883 return __connman_error_not_supported(msg);
1885 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
1886 return __connman_error_invalid_service(msg);
1888 dbus_message_iter_get_basic(&value, &apn);
1890 g_free(service->apn);
1891 service->apn = g_strdup(apn);
1893 apn_changed(service);
1895 if (service->network != NULL)
1896 connman_network_set_string(service->network,
1897 "Cellular.APN", service->apn);
1899 __connman_storage_save_service(service);
1900 } else if (g_str_equal(name, "Username") == TRUE) {
1901 const char *username;
1903 if (type != DBUS_TYPE_STRING)
1904 return __connman_error_invalid_arguments(msg);
1906 if (service->immutable == TRUE)
1907 return __connman_error_not_supported(msg);
1909 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
1910 return __connman_error_invalid_service(msg);
1912 dbus_message_iter_get_basic(&value, &username);
1914 g_free(service->username);
1915 service->username = g_strdup(username);
1917 if (service->network != NULL)
1918 connman_network_set_string(service->network,
1919 "Cellular.Username", service->username);
1921 __connman_storage_save_service(service);
1922 } else if (g_str_equal(name, "Password") == TRUE) {
1923 const char *password;
1925 if (type != DBUS_TYPE_STRING)
1926 return __connman_error_invalid_arguments(msg);
1928 if (service->immutable == TRUE)
1929 return __connman_error_not_supported(msg);
1931 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
1932 return __connman_error_invalid_service(msg);
1934 dbus_message_iter_get_basic(&value, &password);
1936 g_free(service->password);
1937 service->password = g_strdup(password);
1939 if (service->network != NULL)
1940 connman_network_set_string(service->network,
1941 "Cellular.Password", service->password);
1943 __connman_storage_save_service(service);
1944 } else if (g_str_equal(name, "Nameservers.Configuration") == TRUE) {
1945 DBusMessageIter entry;
1950 if (type != DBUS_TYPE_ARRAY)
1951 return __connman_error_invalid_arguments(msg);
1953 str = g_string_new(NULL);
1955 return __connman_error_invalid_arguments(msg);
1957 index = connman_network_get_index(service->network);
1958 gw = __connman_ipconfig_get_gateway(index);
1960 if (gw && strlen(gw))
1961 __connman_service_nameserver_del_routes(service);
1963 dbus_message_iter_recurse(&value, &entry);
1965 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
1967 dbus_message_iter_get_basic(&entry, &val);
1968 dbus_message_iter_next(&entry);
1970 g_string_append_printf(str, " %s", val);
1972 g_string_append(str, val);
1975 g_strfreev(service->nameservers);
1978 service->nameservers = g_strsplit_set(str->str, " ", 0);
1980 service->nameservers = NULL;
1982 g_string_free(str, TRUE);
1984 if (gw && strlen(gw))
1985 __connman_service_nameserver_add_routes(service, gw);
1987 update_nameservers(service);
1988 dns_configuration_changed(service);
1990 __connman_storage_save_service(service);
1991 } else if (g_str_equal(name, "Domains.Configuration") == TRUE) {
1992 DBusMessageIter entry;
1995 if (type != DBUS_TYPE_ARRAY)
1996 return __connman_error_invalid_arguments(msg);
1998 str = g_string_new(NULL);
2000 return __connman_error_invalid_arguments(msg);
2002 dbus_message_iter_recurse(&value, &entry);
2004 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
2006 dbus_message_iter_get_basic(&entry, &val);
2007 dbus_message_iter_next(&entry);
2009 g_string_append_printf(str, " %s", val);
2011 g_string_append(str, val);
2014 g_strfreev(service->domains);
2017 service->domains = g_strsplit_set(str->str, " ", 0);
2019 service->domains = NULL;
2021 g_string_free(str, TRUE);
2023 update_nameservers(service);
2024 domain_configuration_changed(service);
2026 __connman_storage_save_service(service);
2027 } else if (g_str_equal(name, "Proxy.Configuration") == TRUE) {
2030 if (type != DBUS_TYPE_ARRAY)
2031 return __connman_error_invalid_arguments(msg);
2033 err = update_proxy_configuration(service, &value);
2036 return __connman_error_failed(msg, -err);
2038 proxy_configuration_changed(service);
2040 __connman_storage_save_service(service);
2041 } else if (g_str_equal(name, "IPv4.Configuration") == TRUE ||
2042 g_str_equal(name, "IPv6.Configuration")) {
2044 enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
2049 if (service->ipconfig_ipv4 == NULL &&
2050 service->ipconfig_ipv6 == NULL)
2051 return __connman_error_invalid_property(msg);
2053 if (is_connecting(service) ||
2054 is_connected(service)) {
2055 __connman_network_clear_ipconfig(service->network,
2056 service->ipconfig_ipv4);
2057 __connman_network_clear_ipconfig(service->network,
2058 service->ipconfig_ipv6);
2061 if (g_str_equal(name, "IPv4.Configuration") == TRUE) {
2062 type = CONNMAN_IPCONFIG_TYPE_IPV4;
2063 err = __connman_ipconfig_set_config(
2064 service->ipconfig_ipv4, type, &value);
2065 } else if (g_str_equal(name, "IPv6.Configuration") == TRUE) {
2066 type = CONNMAN_IPCONFIG_TYPE_IPV6;
2067 err = __connman_ipconfig_set_config(
2068 service->ipconfig_ipv6, type, &value);
2072 if (is_connected(service) ||
2073 is_connecting(service))
2074 __connman_network_set_ipconfig(
2076 service->ipconfig_ipv4,
2077 service->ipconfig_ipv6);
2078 return __connman_error_failed(msg, -err);
2081 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
2082 ipv4_configuration_changed(service);
2083 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
2084 ipv6_configuration_changed(service);
2086 if (is_connecting(service) ||
2087 is_connected(service))
2088 __connman_network_set_ipconfig(service->network,
2089 service->ipconfig_ipv4,
2090 service->ipconfig_ipv6);
2092 __connman_storage_save_service(service);
2094 return __connman_error_invalid_property(msg);
2096 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2099 static void set_idle(struct connman_service *service)
2101 service->state = CONNMAN_SERVICE_STATE_IDLE;
2102 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
2103 state_changed(service);
2106 static DBusMessage *clear_property(DBusConnection *conn,
2107 DBusMessage *msg, void *user_data)
2109 struct connman_service *service = user_data;
2112 DBG("service %p", service);
2114 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
2117 if (g_str_equal(name, "Error") == TRUE) {
2120 g_get_current_time(&service->modified);
2121 __connman_storage_save_service(service);
2122 } else if (g_str_equal(name, "Passphrase") == TRUE) {
2123 if (service->immutable == TRUE)
2124 return __connman_error_not_supported(msg);
2126 g_free(service->passphrase);
2127 service->passphrase = NULL;
2129 passphrase_changed(service);
2131 __connman_storage_save_service(service);
2133 return __connman_error_invalid_property(msg);
2135 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2138 static connman_bool_t is_ignore(struct connman_service *service)
2140 if (service->autoconnect == FALSE)
2143 if (service->roaming == TRUE)
2146 if (service->ignore == TRUE)
2149 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
2155 void __connman_service_auto_connect(void)
2157 struct connman_service *service = NULL;
2158 GSequenceIter *iter;
2162 iter = g_sequence_get_begin_iter(service_list);
2164 while (g_sequence_iter_is_end(iter) == FALSE) {
2165 service = g_sequence_get(iter);
2167 if (service->pending != NULL)
2170 if (is_connecting(service) == TRUE)
2173 if (service->favorite == FALSE)
2176 if (is_connected(service) == TRUE)
2179 if (is_ignore(service) == FALSE &&
2180 service->state == CONNMAN_SERVICE_STATE_IDLE)
2185 iter = g_sequence_iter_next(iter);
2188 if (service != NULL) {
2189 service->userconnect = FALSE;
2190 __connman_service_connect(service);
2194 static void remove_timeout(struct connman_service *service)
2196 if (service->timeout > 0) {
2197 g_source_remove(service->timeout);
2198 service->timeout = 0;
2202 static void reply_pending(struct connman_service *service, int error)
2204 remove_timeout(service);
2206 if (service->pending != NULL) {
2210 reply = __connman_error_failed(service->pending,
2213 g_dbus_send_message(connection, reply);
2215 g_dbus_send_reply(connection, service->pending,
2218 dbus_message_unref(service->pending);
2219 service->pending = NULL;
2223 static gboolean connect_timeout(gpointer user_data)
2225 struct connman_service *service = user_data;
2226 connman_bool_t autoconnect = FALSE;
2228 DBG("service %p", service);
2230 service->timeout = 0;
2232 if (service->network != NULL)
2233 __connman_network_disconnect(service->network);
2235 if (service->ipconfig_ipv4)
2236 if (!__connman_ipconfig_disable(service->ipconfig_ipv4))
2237 service->ipconfig_ipv4 = NULL;
2239 if (service->ipconfig_ipv6)
2240 if (!__connman_ipconfig_disable(service->ipconfig_ipv6))
2241 service->ipconfig_ipv6 = NULL;
2243 __connman_stats_service_unregister(service);
2245 if (service->pending != NULL) {
2248 reply = __connman_error_operation_timeout(service->pending);
2250 g_dbus_send_message(connection, reply);
2252 dbus_message_unref(service->pending);
2253 service->pending = NULL;
2257 __connman_service_indicate_state(service,
2258 CONNMAN_SERVICE_STATE_FAILURE);
2260 if (autoconnect == TRUE && service->userconnect == FALSE)
2261 __connman_service_auto_connect();
2266 static void set_reconnect_state(struct connman_service *service,
2267 connman_bool_t reconnect)
2269 struct connman_device *device;
2271 if (service->network == NULL)
2274 device = connman_network_get_device(service->network);
2278 __connman_device_set_reconnect(device, reconnect);
2281 static connman_bool_t get_reconnect_state(struct connman_service *service)
2283 struct connman_device *device;
2285 if (service->network == NULL)
2288 device = connman_network_get_device(service->network);
2292 return __connman_device_get_reconnect(device);
2295 static void request_input_cb (struct connman_service *service,
2296 const char *passphrase, void *user_data)
2298 DBG ("RequestInput return, %p", service);
2300 if (passphrase == NULL)
2302 __connman_service_set_passphrase(service, passphrase);
2303 __connman_service_connect(service);
2306 struct connman_service *
2307 __connman_service_connect_type(enum connman_service_type type)
2309 struct connman_service *service;
2310 GSequenceIter *iter;
2313 DBG("type %d", type);
2316 * We go through the already sorted service list.
2317 * We pick the first one matching our type, or just
2318 * the first available one if we have no type.
2320 iter = g_sequence_get_begin_iter(service_list);
2321 if (g_sequence_iter_is_end(iter))
2323 service = g_sequence_get(iter);
2326 * If the first service is connected or about to be
2327 * connected, we return it, regardless of the type.
2329 if ((g_sequence_iter_is_end(iter) == FALSE) &&
2330 (is_connecting(service) == TRUE ||
2331 is_connected(service) == TRUE))
2334 while (g_sequence_iter_is_end(iter) == FALSE) {
2335 if (service->type == type ||
2336 type == CONNMAN_SERVICE_TYPE_UNKNOWN)
2339 iter = g_sequence_iter_next(iter);
2340 service = g_sequence_get(iter);
2343 if (g_sequence_iter_is_end(iter))
2346 service->ignore = FALSE;
2348 service->userconnect = TRUE;
2350 set_reconnect_state(service, FALSE);
2352 err = __connman_service_connect(service);
2355 if ( __connman_agent_request_input(service,
2360 if (err != -EINPROGRESS)
2367 static DBusMessage *connect_service(DBusConnection *conn,
2368 DBusMessage *msg, void *user_data)
2370 struct connman_service *service = user_data;
2371 GSequenceIter *iter;
2374 DBG("service %p", service);
2376 if (service->pending != NULL)
2377 return __connman_error_in_progress(msg);
2379 iter = g_sequence_get_begin_iter(service_list);
2381 while (g_sequence_iter_is_end(iter) == FALSE) {
2382 struct connman_service *temp = g_sequence_get(iter);
2384 if (service->type == temp->type &&
2385 is_connecting(temp) == TRUE)
2386 return __connman_error_in_progress(msg);
2388 iter = g_sequence_iter_next(iter);
2391 service->ignore = FALSE;
2393 service->userconnect = TRUE;
2395 service->pending = dbus_message_ref(msg);
2397 set_reconnect_state(service, FALSE);
2399 err = __connman_service_connect(service);
2401 if (err == -ENOKEY) {
2402 if (__connman_agent_request_input(service,
2408 if (err != -EINPROGRESS) {
2409 dbus_message_unref(service->pending);
2410 service->pending = NULL;
2412 return __connman_error_failed(msg, -err);
2418 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2421 static DBusMessage *disconnect_service(DBusConnection *conn,
2422 DBusMessage *msg, void *user_data)
2424 struct connman_service *service = user_data;
2427 DBG("service %p", service);
2429 reply_pending(service, ECONNABORTED);
2431 service->ignore = TRUE;
2433 set_reconnect_state(service, FALSE);
2435 err = __connman_service_disconnect(service);
2437 if (err != -EINPROGRESS)
2438 return __connman_error_failed(msg, -err);
2443 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2446 static DBusMessage *remove_service(DBusConnection *conn,
2447 DBusMessage *msg, void *user_data)
2449 struct connman_service *service = user_data;
2451 DBG("service %p", service);
2453 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
2454 return __connman_error_not_supported(msg);
2456 if (service->immutable == TRUE)
2457 return __connman_error_not_supported(msg);
2459 if (service->favorite == FALSE &&
2460 service->state != CONNMAN_SERVICE_STATE_FAILURE)
2461 return __connman_error_not_supported(msg);
2463 if (service->network != NULL) {
2464 set_reconnect_state(service, FALSE);
2466 __connman_network_disconnect(service->network);
2469 g_hash_table_destroy(service->counter_table);
2471 g_free(service->passphrase);
2472 service->passphrase = NULL;
2474 passphrase_changed(service);
2476 g_free(service->apn);
2477 service->apn = NULL;
2479 g_free(service->username);
2480 service->username = NULL;
2482 g_free(service->password);
2483 service->password = NULL;
2485 apn_changed(service);
2489 __connman_service_set_favorite(service, FALSE);
2490 __connman_storage_save_service(service);
2492 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2495 static DBusMessage *move_service(DBusConnection *conn,
2496 DBusMessage *msg, void *user_data,
2499 struct connman_service *service = user_data;
2500 struct connman_service *target;
2502 GSequenceIter *src, *dst;
2504 DBG("service %p", service);
2506 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
2509 if (service->favorite == FALSE)
2510 return __connman_error_not_supported(msg);
2512 target = find_service(path);
2513 if (target == NULL || target->favorite == FALSE || target == service)
2514 return __connman_error_invalid_service(msg);
2516 DBG("target %s", target->identifier);
2518 if (target->state != service->state)
2519 return __connman_error_invalid_service(msg);
2521 g_get_current_time(&service->modified);
2522 __connman_storage_save_service(service);
2524 src = g_hash_table_lookup(service_hash, service->identifier);
2525 dst = g_hash_table_lookup(service_hash, target->identifier);
2527 before ? g_sequence_move(src, dst) : g_sequence_move(dst, src);
2529 __connman_profile_changed(FALSE);
2531 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2534 static DBusMessage *move_before(DBusConnection *conn,
2535 DBusMessage *msg, void *user_data)
2537 return move_service(conn, msg, user_data, TRUE);
2540 static DBusMessage *move_after(DBusConnection *conn,
2541 DBusMessage *msg, void *user_data)
2543 return move_service(conn, msg, user_data, FALSE);
2546 static DBusMessage *reset_counters(DBusConnection *conn,
2547 DBusMessage *msg, void *user_data)
2549 struct connman_service *service = user_data;
2551 reset_stats(service);
2553 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2556 static GDBusMethodTable service_methods[] = {
2557 { "GetProperties", "", "a{sv}", get_properties },
2558 { "SetProperty", "sv", "", set_property },
2559 { "ClearProperty", "s", "", clear_property },
2560 { "Connect", "", "", connect_service,
2561 G_DBUS_METHOD_FLAG_ASYNC },
2562 { "Disconnect", "", "", disconnect_service },
2563 { "Remove", "", "", remove_service },
2564 { "MoveBefore", "o", "", move_before },
2565 { "MoveAfter", "o", "", move_after },
2566 { "ResetCounters", "", "", reset_counters },
2570 static GDBusSignalTable service_signals[] = {
2571 { "PropertyChanged", "sv" },
2575 static void service_free(gpointer user_data)
2577 struct connman_service *service = user_data;
2578 char *path = service->path;
2580 DBG("service %p", service);
2582 reply_pending(service, ENOENT);
2584 g_hash_table_remove(service_hash, service->identifier);
2586 stats_stop(service);
2587 __connman_storage_save_service(service);
2589 service->path = NULL;
2592 __connman_profile_changed(FALSE);
2594 g_dbus_unregister_interface(connection, path,
2595 CONNMAN_SERVICE_INTERFACE);
2599 if (service->network != NULL)
2600 connman_network_unref(service->network);
2602 if (service->provider != NULL)
2603 connman_provider_unref(service->provider);
2605 if (service->ipconfig_ipv4 != NULL) {
2606 connman_ipconfig_unref(service->ipconfig_ipv4);
2607 service->ipconfig_ipv4 = NULL;
2610 if (service->ipconfig_ipv6 != NULL) {
2611 connman_ipconfig_unref(service->ipconfig_ipv6);
2612 service->ipconfig_ipv6 = NULL;
2615 if (service->location != NULL)
2616 connman_location_unref(service->location);
2618 g_strfreev(service->nameservers);
2619 g_strfreev(service->domains);
2620 g_strfreev(service->proxies);
2621 g_strfreev(service->excludes);
2623 g_free(service->nameserver);
2624 g_free(service->domainname);
2625 g_free(service->pac);
2626 g_free(service->mcc);
2627 g_free(service->mnc);
2628 g_free(service->apn);
2629 g_free(service->username);
2630 g_free(service->password);
2631 g_free(service->profile);
2632 g_free(service->name);
2633 g_free(service->passphrase);
2634 g_free(service->identifier);
2635 g_free(service->eap);
2636 g_free(service->identity);
2637 g_free(service->ca_cert_file);
2638 g_free(service->client_cert_file);
2639 g_free(service->private_key_file);
2640 g_free(service->private_key_passphrase);
2641 g_free(service->phase2);
2643 if (service->stats.timer != NULL)
2644 g_timer_destroy(service->stats.timer);
2645 if (service->stats_roaming.timer != NULL)
2646 g_timer_destroy(service->stats_roaming.timer);
2652 * __connman_service_put:
2653 * @service: service structure
2655 * Release service if no longer needed
2657 void __connman_service_put(struct connman_service *service)
2659 DBG("service %p", service);
2661 if (g_atomic_int_dec_and_test(&service->refcount) == TRUE) {
2662 GSequenceIter *iter;
2664 iter = g_hash_table_lookup(service_hash, service->identifier);
2666 reply_pending(service, ECONNABORTED);
2668 __connman_service_disconnect(service);
2670 g_sequence_remove(iter);
2672 service_free(service);
2676 static void stats_init(struct connman_service *service)
2679 service->stats.valid = FALSE;
2680 service->stats.enabled = FALSE;
2681 service->stats.timer = g_timer_new();
2684 service->stats_roaming.valid = FALSE;
2685 service->stats_roaming.enabled = FALSE;
2686 service->stats_roaming.timer = g_timer_new();
2689 static void service_initialize(struct connman_service *service)
2691 DBG("service %p", service);
2693 service->refcount = 1;
2695 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
2696 service->mode = CONNMAN_SERVICE_MODE_UNKNOWN;
2697 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
2698 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
2700 service->favorite = FALSE;
2701 service->immutable = FALSE;
2702 service->hidden = FALSE;
2704 service->ignore = FALSE;
2706 service->userconnect = FALSE;
2710 stats_init(service);
2712 service->provider = NULL;
2716 * connman_service_create:
2718 * Allocate a new service.
2720 * Returns: a newly-allocated #connman_service structure
2722 struct connman_service *connman_service_create(void)
2725 struct connman_stats_counter *counters;
2726 const char *counter;
2728 struct connman_service *service;
2730 service = g_try_new0(struct connman_service, 1);
2731 if (service == NULL)
2734 DBG("service %p", service);
2736 service->counter_table = g_hash_table_new_full(g_str_hash,
2737 g_str_equal, NULL, g_free);
2739 for (list = counter_list; list; list = list->next) {
2740 counter = list->data;
2742 counters = g_try_new0(struct connman_stats_counter, 1);
2743 if (counters == NULL) {
2744 g_hash_table_destroy(service->counter_table);
2749 counters->append_all = TRUE;
2751 g_hash_table_replace(service->counter_table, (gpointer)counter,
2755 service_initialize(service);
2757 service->location = __connman_location_create(service);
2762 struct connman_location *__connman_service_get_location(struct connman_service *service)
2764 return service->location;
2768 * connman_service_ref:
2769 * @service: service structure
2771 * Increase reference counter of service
2773 struct connman_service *connman_service_ref(struct connman_service *service)
2777 g_atomic_int_inc(&service->refcount);
2783 * connman_service_unref:
2784 * @service: service structure
2786 * Decrease reference counter of service
2788 void connman_service_unref(struct connman_service *service)
2790 __connman_service_put(service);
2793 static gint service_compare(gconstpointer a, gconstpointer b,
2796 struct connman_service *service_a = (void *) a;
2797 struct connman_service *service_b = (void *) b;
2799 if (service_a->state != service_b->state) {
2800 if (is_connected(service_a) == TRUE)
2802 if (is_connected(service_b) == TRUE)
2805 if (is_connecting(service_a) == TRUE)
2807 if (is_connecting(service_b) == TRUE)
2811 if (service_a->order > service_b->order)
2814 if (service_a->order < service_b->order)
2817 if (service_a->favorite == TRUE && service_b->favorite == FALSE)
2820 if (service_a->favorite == FALSE && service_b->favorite == TRUE)
2823 if (service_a->type != service_b->type) {
2824 switch (service_a->type) {
2825 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2826 case CONNMAN_SERVICE_TYPE_SYSTEM:
2827 case CONNMAN_SERVICE_TYPE_ETHERNET:
2828 case CONNMAN_SERVICE_TYPE_GPS:
2829 case CONNMAN_SERVICE_TYPE_VPN:
2830 case CONNMAN_SERVICE_TYPE_GADGET:
2832 case CONNMAN_SERVICE_TYPE_WIFI:
2834 case CONNMAN_SERVICE_TYPE_WIMAX:
2835 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2836 case CONNMAN_SERVICE_TYPE_CELLULAR:
2841 return (gint) service_b->strength - (gint) service_a->strength;
2845 * connman_service_get_type:
2846 * @service: service structure
2848 * Get the type of service
2850 enum connman_service_type connman_service_get_type(struct connman_service *service)
2852 if (service == NULL)
2853 return CONNMAN_SERVICE_TYPE_UNKNOWN;
2855 return service->type;
2859 * connman_service_get_interface:
2860 * @service: service structure
2862 * Get network interface of service
2864 char *connman_service_get_interface(struct connman_service *service)
2868 if (service == NULL)
2871 if (service->type == CONNMAN_SERVICE_TYPE_VPN) {
2872 if (service->ipconfig_ipv4)
2873 index = connman_ipconfig_get_index(
2874 service->ipconfig_ipv4);
2875 else if (service->ipconfig_ipv6)
2876 index = connman_ipconfig_get_index(
2877 service->ipconfig_ipv6);
2881 return connman_inet_ifname(index);
2884 if (service->network == NULL)
2887 index = connman_network_get_index(service->network);
2889 return connman_inet_ifname(index);
2893 * connman_service_get_network:
2894 * @service: service structure
2896 * Get the service network
2898 struct connman_network *
2899 __connman_service_get_network(struct connman_service *service)
2901 if (service == NULL)
2904 return service->network;
2907 struct connman_ipconfig *
2908 __connman_service_get_ip4config(struct connman_service *service)
2910 if (service == NULL)
2913 return service->ipconfig_ipv4;
2916 struct connman_ipconfig *
2917 __connman_service_get_ip6config(struct connman_service *service)
2919 if (service == NULL)
2922 return service->ipconfig_ipv6;
2925 enum connman_service_security __connman_service_get_security(struct connman_service *service)
2927 if (service == NULL)
2928 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
2930 return service->security;
2934 * __connman_service_set_favorite:
2935 * @service: service structure
2936 * @favorite: favorite value
2938 * Change the favorite setting of service
2940 int __connman_service_set_favorite(struct connman_service *service,
2941 connman_bool_t favorite)
2943 GSequenceIter *iter;
2945 iter = g_hash_table_lookup(service_hash, service->identifier);
2949 if (service->favorite == favorite)
2952 service->favorite = favorite;
2954 favorite_changed(service);
2956 g_sequence_sort_changed(iter, service_compare, NULL);
2958 __connman_profile_changed(FALSE);
2963 int __connman_service_set_immutable(struct connman_service *service,
2964 connman_bool_t immutable)
2966 service->immutable = immutable;
2968 immutable_changed(service);
2973 void __connman_service_set_string(struct connman_service *service,
2974 const char *key, const char *value)
2976 if (g_str_equal(key, "EAP") == TRUE) {
2977 g_free(service->eap);
2978 service->eap = g_strdup(value);
2979 } else if (g_str_equal(key, "Identity") == TRUE) {
2980 g_free(service->identity);
2981 service->identity = g_strdup(value);
2982 } else if (g_str_equal(key, "CACertFile") == TRUE) {
2983 g_free(service->ca_cert_file);
2984 service->ca_cert_file = g_strdup(value);
2985 } else if (g_str_equal(key, "ClientCertFile") == TRUE) {
2986 g_free(service->client_cert_file);
2987 service->client_cert_file = g_strdup(value);
2988 } else if (g_str_equal(key, "PrivateKeyFile") == TRUE) {
2989 g_free(service->private_key_file);
2990 service->private_key_file = g_strdup(value);
2991 } else if (g_str_equal(key, "PrivateKeyPassphrase") == TRUE) {
2992 g_free(service->private_key_passphrase);
2993 service->private_key_passphrase = g_strdup(value);
2994 } else if (g_str_equal(key, "Phase2") == TRUE) {
2995 g_free(service->phase2);
2996 service->phase2 = g_strdup(value);
2997 } else if (g_str_equal(key, "Passphrase") == TRUE) {
2998 g_free(service->passphrase);
2999 service->passphrase = g_strdup(value);
3003 static void service_complete(struct connman_service *service)
3005 reply_pending(service, EIO);
3007 if (service->userconnect == FALSE)
3008 __connman_service_auto_connect();
3010 g_get_current_time(&service->modified);
3011 __connman_storage_save_service(service);
3014 static void report_error_cb(struct connman_service *service,
3015 gboolean retry, void *user_data)
3018 __connman_service_connect(service);
3020 service_complete(service);
3021 __connman_profile_changed(FALSE);
3022 __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
3026 int __connman_service_indicate_state(struct connman_service *service,
3027 enum connman_service_state state)
3029 GSequenceIter *iter;
3031 DBG("service %p state %d", service, state);
3033 if (service == NULL)
3036 if (service->state == state)
3039 if (service->state == CONNMAN_SERVICE_STATE_FAILURE &&
3040 state == CONNMAN_SERVICE_STATE_IDLE)
3043 if (service->state == CONNMAN_SERVICE_STATE_IDLE &&
3044 state == CONNMAN_SERVICE_STATE_DISCONNECT)
3047 if (state == CONNMAN_SERVICE_STATE_IDLE &&
3048 service->state != CONNMAN_SERVICE_STATE_DISCONNECT) {
3049 service->state = CONNMAN_SERVICE_STATE_DISCONNECT;
3050 state_changed(service);
3052 reply_pending(service, ECONNABORTED);
3054 __connman_service_disconnect(service);
3057 if (state == CONNMAN_SERVICE_STATE_CONFIGURATION) {
3058 if (__connman_stats_service_register(service) == 0) {
3059 __connman_stats_get(service, FALSE,
3060 &service->stats.data);
3061 __connman_stats_get(service, TRUE,
3062 &service->stats_roaming.data);
3065 if (service->ipconfig_ipv4)
3066 __connman_ipconfig_enable(service->ipconfig_ipv4);
3067 if (service->ipconfig_ipv6)
3068 __connman_ipconfig_enable(service->ipconfig_ipv6);
3071 service->state = state;
3072 state_changed(service);
3074 if (state == CONNMAN_SERVICE_STATE_ONLINE) {
3075 if (service->login_required == TRUE) {
3076 service->login_required = FALSE;
3077 login_changed(service);
3080 connman_timeserver_sync();
3083 if (state == CONNMAN_SERVICE_STATE_IDLE) {
3084 connman_bool_t reconnect;
3086 reconnect = get_reconnect_state(service);
3087 if (reconnect == TRUE)
3088 __connman_service_auto_connect();
3091 if (state == CONNMAN_SERVICE_STATE_READY) {
3092 set_reconnect_state(service, TRUE);
3094 __connman_service_set_favorite(service, TRUE);
3096 reply_pending(service, 0);
3098 service->userconnect = FALSE;
3100 g_get_current_time(&service->modified);
3101 __connman_storage_save_service(service);
3103 update_nameservers(service);
3104 dns_changed(service);
3105 domain_changed(service);
3107 __connman_wpad_start(service);
3109 __connman_notifier_connect(service->type);
3112 } else if (state == CONNMAN_SERVICE_STATE_DISCONNECT) {
3113 __connman_location_finish(service);
3117 __connman_wpad_stop(service);
3119 update_nameservers(service);
3120 dns_changed(service);
3121 domain_changed(service);
3123 __connman_notifier_disconnect(service->type);
3126 if (state == CONNMAN_SERVICE_STATE_FAILURE) {
3127 if (service->userconnect == TRUE &&
3128 __connman_agent_report_error(service,
3129 error2string(service->error),
3130 report_error_cb, NULL) == -EIO)
3132 service_complete(service);
3134 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
3136 iter = g_hash_table_lookup(service_hash, service->identifier);
3138 g_sequence_sort_changed(iter, service_compare, NULL);
3140 __connman_profile_changed(FALSE);
3142 if (service->state == CONNMAN_SERVICE_STATE_ONLINE)
3145 if (service->state == CONNMAN_SERVICE_STATE_DISCONNECT) {
3146 struct connman_service *def_service = get_default();
3148 if (__connman_notifier_count_connected() == 0 &&
3149 def_service != NULL &&
3150 def_service->provider != NULL)
3151 __connman_provider_disconnect(def_service->provider);
3154 if (service->state == CONNMAN_SERVICE_STATE_IDLE ||
3155 service->state == CONNMAN_SERVICE_STATE_FAILURE)
3156 __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
3161 int __connman_service_indicate_error(struct connman_service *service,
3162 enum connman_service_error error)
3164 DBG("service %p error %d", service, error);
3166 if (service == NULL)
3169 service->error = error;
3171 return __connman_service_indicate_state(service,
3172 CONNMAN_SERVICE_STATE_FAILURE);
3175 int __connman_service_indicate_default(struct connman_service *service)
3177 DBG("service %p", service);
3181 __connman_location_detect(service);
3186 int __connman_service_request_login(struct connman_service *service)
3188 DBG("service %p", service);
3190 if (service == NULL)
3193 service->login_required = TRUE;
3194 login_changed(service);
3199 static connman_bool_t prepare_network(struct connman_service *service)
3201 enum connman_network_type type;
3202 unsigned int ssid_len;
3204 type = connman_network_get_type(service->network);
3207 case CONNMAN_NETWORK_TYPE_UNKNOWN:
3208 case CONNMAN_NETWORK_TYPE_VENDOR:
3210 case CONNMAN_NETWORK_TYPE_WIFI:
3211 if (connman_network_get_blob(service->network, "WiFi.SSID",
3215 connman_network_set_string(service->network,
3216 "WiFi.Passphrase", service->passphrase);
3218 case CONNMAN_NETWORK_TYPE_ETHERNET:
3219 case CONNMAN_NETWORK_TYPE_WIMAX:
3220 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
3221 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
3223 case CONNMAN_NETWORK_TYPE_CELLULAR:
3224 connman_network_set_string(service->network,
3225 "Cellular.APN", service->apn);
3227 connman_network_set_string(service->network,
3228 "Cellular.Username", service->username);
3229 connman_network_set_string(service->network,
3230 "Cellular.Password", service->password);
3237 static void prepare_8021x(struct connman_service *service)
3239 if (service->eap != NULL)
3240 connman_network_set_string(service->network, "WiFi.EAP",
3243 if (service->identity != NULL)
3244 connman_network_set_string(service->network, "WiFi.Identity",
3247 if (service->ca_cert_file != NULL)
3248 connman_network_set_string(service->network, "WiFi.CACertFile",
3249 service->ca_cert_file);
3251 if (service->client_cert_file != NULL)
3252 connman_network_set_string(service->network,
3253 "WiFi.ClientCertFile",
3254 service->client_cert_file);
3256 if (service->private_key_file != NULL)
3257 connman_network_set_string(service->network,
3258 "WiFi.PrivateKeyFile",
3259 service->private_key_file);
3261 if (service->private_key_passphrase != NULL)
3262 connman_network_set_string(service->network,
3263 "WiFi.PrivateKeyPassphrase",
3264 service->private_key_passphrase);
3266 if (service->phase2 != NULL)
3267 connman_network_set_string(service->network, "WiFi.Phase2",
3271 int __connman_service_connect(struct connman_service *service)
3275 DBG("service %p", service);
3277 if (is_connected(service) == TRUE)
3280 if (is_connecting(service) == TRUE)
3283 switch (service->type) {
3284 case CONNMAN_SERVICE_TYPE_UNKNOWN:
3285 case CONNMAN_SERVICE_TYPE_SYSTEM:
3286 case CONNMAN_SERVICE_TYPE_GPS:
3287 case CONNMAN_SERVICE_TYPE_GADGET:
3289 case CONNMAN_SERVICE_TYPE_ETHERNET:
3290 case CONNMAN_SERVICE_TYPE_WIMAX:
3291 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
3292 case CONNMAN_SERVICE_TYPE_VPN:
3294 case CONNMAN_SERVICE_TYPE_CELLULAR:
3295 if (service->apn == NULL)
3298 case CONNMAN_SERVICE_TYPE_WIFI:
3299 switch (service->security) {
3300 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3301 case CONNMAN_SERVICE_SECURITY_NONE:
3303 case CONNMAN_SERVICE_SECURITY_WEP:
3304 case CONNMAN_SERVICE_SECURITY_PSK:
3305 case CONNMAN_SERVICE_SECURITY_WPA:
3306 case CONNMAN_SERVICE_SECURITY_RSN:
3307 if (service->passphrase == NULL)
3310 case CONNMAN_SERVICE_SECURITY_8021X:
3316 if (service->network != NULL) {
3317 if (prepare_network(service) == FALSE)
3320 switch (service->security) {
3321 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
3322 case CONNMAN_SERVICE_SECURITY_NONE:
3323 case CONNMAN_SERVICE_SECURITY_WEP:
3324 case CONNMAN_SERVICE_SECURITY_PSK:
3325 case CONNMAN_SERVICE_SECURITY_WPA:
3326 case CONNMAN_SERVICE_SECURITY_RSN:
3328 case CONNMAN_SERVICE_SECURITY_8021X:
3329 prepare_8021x(service);
3333 if (__connman_stats_service_register(service) == 0) {
3334 __connman_stats_get(service, FALSE,
3335 &service->stats.data);
3336 __connman_stats_get(service, TRUE,
3337 &service->stats_roaming.data);
3340 if (service->ipconfig_ipv4)
3341 __connman_ipconfig_enable(service->ipconfig_ipv4);
3342 if (service->ipconfig_ipv6)
3343 __connman_ipconfig_enable(service->ipconfig_ipv6);
3345 err = __connman_network_connect(service->network);
3346 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
3347 service->provider != NULL)
3348 err = __connman_provider_connect(service->provider);
3353 if (err != -EINPROGRESS) {
3354 if (service->ipconfig_ipv4)
3355 if (!__connman_ipconfig_disable(
3356 service->ipconfig_ipv4))
3357 service->ipconfig_ipv4 = NULL;
3359 if (service->ipconfig_ipv6)
3360 if (!__connman_ipconfig_disable(
3361 service->ipconfig_ipv6))
3362 service->ipconfig_ipv6 = NULL;
3364 __connman_stats_service_unregister(service);
3365 if (service->userconnect == TRUE)
3366 return __connman_agent_report_error(service,
3367 error2string(service->error),
3368 report_error_cb, NULL);
3373 service->timeout = g_timeout_add_seconds(CONNECT_TIMEOUT,
3374 connect_timeout, service);
3376 return -EINPROGRESS;
3382 int __connman_service_disconnect(struct connman_service *service)
3386 DBG("service %p", service);
3388 if (service->network != NULL) {
3389 err = __connman_network_disconnect(service->network);
3390 } else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
3391 service->provider != NULL)
3392 err = __connman_provider_disconnect(service->provider);
3396 if (service->ipconfig_ipv4)
3397 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
3400 __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
3403 __connman_ipconfig_clear_address(service->ipconfig_ipv4);
3404 __connman_ipconfig_clear_address(service->ipconfig_ipv6);
3406 if (__connman_ipconfig_disable(service->ipconfig_ipv4) < 0)
3407 service->ipconfig_ipv4 = NULL;
3409 if (__connman_ipconfig_disable(service->ipconfig_ipv6) < 0)
3410 service->ipconfig_ipv6 = NULL;
3412 __connman_stats_service_unregister(service);
3415 if (err != -EINPROGRESS)
3418 return -EINPROGRESS;
3425 * __connman_service_lookup:
3426 * @pattern: search pattern
3427 * @path: return object path
3429 * Look up a service path from a search pattern
3431 int __connman_service_lookup(const char *pattern, const char **path)
3433 GHashTableIter iter;
3434 gpointer key, value;
3436 g_hash_table_iter_init(&iter, service_hash);
3438 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
3439 GSequenceIter *iter = value;
3440 struct connman_service *service = g_sequence_get(iter);
3442 if (g_strcmp0(service->identifier, pattern) == 0 ||
3443 g_strcmp0(service->name, pattern) == 0) {
3444 *path = (const char *) service->path;
3453 * lookup_by_identifier:
3454 * @identifier: service identifier
3456 * Look up a service by identifier (reference count will not be increased)
3458 static struct connman_service *lookup_by_identifier(const char *identifier)
3460 GSequenceIter *iter;
3462 iter = g_hash_table_lookup(service_hash, identifier);
3464 return g_sequence_get(iter);
3469 static struct connman_network *create_hidden_wifi(struct connman_device *device,
3470 const char *ssid, const char *mode, const char *security)
3472 struct connman_network *network;
3475 unsigned int i, ssid_len;
3477 ssid_len = strlen(ssid);
3481 network = connman_network_create(NULL, CONNMAN_NETWORK_TYPE_WIFI);
3482 if (network == NULL)
3485 connman_network_set_blob(network, "WiFi.SSID",
3486 (unsigned char *) ssid, ssid_len);
3488 connman_network_set_string(network, "WiFi.Mode", mode);
3489 connman_network_set_string(network, "WiFi.Security", security);
3491 name = g_try_malloc0(ssid_len + 1);
3493 connman_network_unref(network);
3497 for (i = 0; i < ssid_len; i++) {
3498 if (g_ascii_isprint(ssid[i]))
3504 connman_network_set_name(network, name);
3508 index = connman_device_get_index(device);
3509 connman_network_set_index(network, index);
3511 if (connman_device_add_network(device, network) < 0) {
3512 connman_network_unref(network);
3516 connman_network_set_available(network, TRUE);
3521 int __connman_service_create_and_connect(DBusMessage *msg)
3523 struct connman_service *service;
3524 struct connman_network *network;
3525 struct connman_device *device;
3526 DBusMessageIter iter, array;
3527 const char *mode = "managed", *security = "none", *group_security;
3528 const char *type = NULL, *ssid = NULL, *passphrase = NULL;
3529 unsigned int ssid_len = 0;
3532 gboolean created = FALSE;
3535 dbus_message_iter_init(msg, &iter);
3536 dbus_message_iter_recurse(&iter, &array);
3538 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
3539 DBusMessageIter entry, value;
3542 dbus_message_iter_recurse(&array, &entry);
3543 dbus_message_iter_get_basic(&entry, &key);
3545 dbus_message_iter_next(&entry);
3546 dbus_message_iter_recurse(&entry, &value);
3548 switch (dbus_message_iter_get_arg_type(&value)) {
3549 case DBUS_TYPE_STRING:
3550 if (g_str_equal(key, "Type") == TRUE)
3551 dbus_message_iter_get_basic(&value, &type);
3552 else if (g_str_equal(key, "WiFi.Mode") == TRUE ||
3553 g_str_equal(key, "Mode") == TRUE)
3554 dbus_message_iter_get_basic(&value, &mode);
3555 else if (g_str_equal(key, "WiFi.Security") == TRUE ||
3556 g_str_equal(key, "Security") == TRUE)
3557 dbus_message_iter_get_basic(&value, &security);
3558 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE ||
3559 g_str_equal(key, "Passphrase") == TRUE)
3560 dbus_message_iter_get_basic(&value, &passphrase);
3561 else if (g_str_equal(key, "WiFi.SSID") == TRUE ||
3562 g_str_equal(key, "SSID") == TRUE)
3563 dbus_message_iter_get_basic(&value, &ssid);
3566 dbus_message_iter_next(&array);
3572 if (g_strcmp0(type, "wifi") != 0 || g_strcmp0(mode, "managed") != 0)
3578 ssid_len = strlen(ssid);
3582 if (g_strcmp0(security, "none") != 0 &&
3583 g_strcmp0(security, "wep") != 0 &&
3584 g_strcmp0(security, "psk") != 0 &&
3585 g_strcmp0(security, "wpa") != 0 &&
3586 g_strcmp0(security, "rsn") != 0 &&
3587 g_strcmp0(security, "ieee8021x") != 0)
3590 device = __connman_element_find_device(CONNMAN_SERVICE_TYPE_WIFI);
3594 ident = connman_device_get_ident(device);
3599 if (!g_strcmp0(security, "wpa") ||
3600 !g_strcmp0(security, "rsn"))
3601 group_security = "psk";
3603 group_security = security;
3605 group = connman_wifi_build_group_name((unsigned char *) ssid,
3606 ssid_len, mode, group_security);
3610 name = g_strdup_printf("%s_%s_%s", type, ident, group);
3612 service = lookup_by_identifier(name);
3614 if (service != NULL)
3617 network = create_hidden_wifi(device, ssid, mode, security);
3618 if (network != NULL) {
3619 connman_network_set_group(network, group);
3623 service = lookup_by_identifier(name);
3629 if (service == NULL) {
3634 set_reconnect_state(service, FALSE);
3636 __connman_device_disconnect(device);
3638 if (passphrase != NULL) {
3639 g_free(service->passphrase);
3640 service->passphrase = g_strdup(passphrase);
3643 service->userconnect = TRUE;
3645 err = __connman_service_connect(service);
3646 if (err < 0 && err != -EINPROGRESS)
3649 g_dbus_send_reply(connection, msg,
3650 DBUS_TYPE_OBJECT_PATH, &service->path,
3656 if (service != NULL && created == TRUE) {
3657 struct connman_network *network = service->network;
3659 if (network != NULL) {
3660 connman_network_set_available(network, FALSE);
3661 __connman_device_cleanup_networks(device);
3663 __connman_service_put(service);
3670 * __connman_service_get:
3671 * @identifier: service identifier
3673 * Look up a service by identifier or create a new one if not found
3675 static struct connman_service *service_get(const char *identifier)
3677 struct connman_service *service;
3678 GSequenceIter *iter;
3680 iter = g_hash_table_lookup(service_hash, identifier);
3682 service = g_sequence_get(iter);
3683 if (service != NULL)
3684 connman_service_ref(service);
3688 service = connman_service_create();
3689 if (service == NULL)
3692 DBG("service %p", service);
3694 service->identifier = g_strdup(identifier);
3696 service->profile = g_strdup(__connman_profile_active_ident());
3698 iter = g_sequence_insert_sorted(service_list, service,
3699 service_compare, NULL);
3701 g_hash_table_insert(service_hash, service->identifier, iter);
3706 static int service_register(struct connman_service *service)
3708 const char *path = __connman_profile_active_path();
3709 GSequenceIter *iter;
3711 DBG("service %p", service);
3713 if (service->path != NULL)
3716 service->path = g_strdup_printf("%s/%s", path, service->identifier);
3718 DBG("path %s", service->path);
3720 __connman_config_provision_service(service);
3722 __connman_storage_load_service(service);
3724 g_dbus_register_interface(connection, service->path,
3725 CONNMAN_SERVICE_INTERFACE,
3726 service_methods, service_signals,
3727 NULL, service, NULL);
3729 iter = g_hash_table_lookup(service_hash, service->identifier);
3731 g_sequence_sort_changed(iter, service_compare, NULL);
3733 __connman_profile_changed(TRUE);
3738 static void service_up(struct connman_ipconfig *ipconfig)
3740 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
3742 connman_info("%s up", connman_ipconfig_get_ifname(ipconfig));
3744 link_changed(service);
3746 service->stats.valid = FALSE;
3747 service->stats_roaming.valid = FALSE;
3750 static void service_down(struct connman_ipconfig *ipconfig)
3752 connman_info("%s down", connman_ipconfig_get_ifname(ipconfig));
3755 static void service_lower_up(struct connman_ipconfig *ipconfig)
3757 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
3759 connman_info("%s lower up", connman_ipconfig_get_ifname(ipconfig));
3761 stats_start(service);
3764 static void service_lower_down(struct connman_ipconfig *ipconfig)
3766 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
3768 connman_info("%s lower down", connman_ipconfig_get_ifname(ipconfig));
3770 stats_stop(service);
3771 __connman_storage_save_service(service);
3774 static void service_ip_bound(struct connman_ipconfig *ipconfig)
3776 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
3778 connman_info("%s ip bound", connman_ipconfig_get_ifname(ipconfig));
3780 settings_changed(service);
3783 static void service_ip_release(struct connman_ipconfig *ipconfig)
3785 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
3787 connman_info("%s ip release", connman_ipconfig_get_ifname(ipconfig));
3789 settings_changed(service);
3792 static const struct connman_ipconfig_ops service_ops = {
3794 .down = service_down,
3795 .lower_up = service_lower_up,
3796 .lower_down = service_lower_down,
3797 .ip_bound = service_ip_bound,
3798 .ip_release = service_ip_release,
3801 static void setup_ip4config(struct connman_service *service, int index)
3806 service->ipconfig_ipv4 = connman_ipconfig_create(index,
3807 CONNMAN_IPCONFIG_TYPE_IPV4);
3808 if (service->ipconfig_ipv4 == NULL)
3811 connman_ipconfig_set_method(service->ipconfig_ipv4,
3812 CONNMAN_IPCONFIG_METHOD_DHCP);
3814 connman_ipconfig_set_data(service->ipconfig_ipv4, service);
3816 connman_ipconfig_set_ops(service->ipconfig_ipv4, &service_ops);
3819 static void setup_ip6config(struct connman_service *service, int index)
3824 service->ipconfig_ipv6 = connman_ipconfig_create(index,
3825 CONNMAN_IPCONFIG_TYPE_IPV6);
3826 if (service->ipconfig_ipv6 == NULL)
3829 connman_ipconfig_set_method(service->ipconfig_ipv6,
3830 CONNMAN_IPCONFIG_METHOD_OFF);
3832 connman_ipconfig_set_data(service->ipconfig_ipv6, service);
3834 connman_ipconfig_set_ops(service->ipconfig_ipv6, &service_ops);
3837 void __connman_service_create_ip4config(struct connman_service *service,
3840 const char *ident = service->profile;
3843 DBG("ipv4 %p", service->ipconfig_ipv4);
3845 if (service->ipconfig_ipv4 != NULL)
3848 setup_ip4config(service, index);
3853 keyfile = __connman_storage_open_profile(ident);
3854 if (keyfile == NULL)
3857 if (service->ipconfig_ipv4)
3858 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
3859 service->identifier, "IPv4.");
3860 g_key_file_free(keyfile);
3863 void __connman_service_create_ip6config(struct connman_service *service,
3866 const char *ident = service->profile;
3869 DBG("ipv6 %p", service->ipconfig_ipv6);
3871 if (service->ipconfig_ipv6 != NULL)
3874 setup_ip6config(service, index);
3879 keyfile = __connman_storage_open_profile(ident);
3880 if (keyfile == NULL)
3883 if (service->ipconfig_ipv6 != NULL)
3884 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
3885 service->identifier, "IPv6.");
3887 g_key_file_free(keyfile);
3891 * __connman_service_lookup_from_network:
3892 * @network: network structure
3894 * Look up a service by network (reference count will not be increased)
3896 struct connman_service *__connman_service_lookup_from_network(struct connman_network *network)
3898 struct connman_service *service;
3899 const char *ident, *group;
3902 DBG("network %p", network);
3904 ident = __connman_network_get_ident(network);
3908 group = connman_network_get_group(network);
3912 name = g_strdup_printf("%s_%s_%s",
3913 __connman_network_get_type(network), ident, group);
3914 service = lookup_by_identifier(name);
3920 struct connman_service *__connman_service_lookup_from_index(int index)
3922 struct connman_service *service;
3923 GSequenceIter *iter;
3925 iter = g_sequence_get_begin_iter(service_list);
3927 while (g_sequence_iter_is_end(iter) == FALSE) {
3928 service = g_sequence_get(iter);
3930 if (connman_ipconfig_get_index(service->ipconfig_ipv4)
3934 if (connman_ipconfig_get_index(service->ipconfig_ipv6)
3938 iter = g_sequence_iter_next(iter);
3944 const char *__connman_service_get_ident(struct connman_service *service)
3946 return service->identifier;
3949 const char *__connman_service_get_path(struct connman_service *service)
3951 return service->path;
3954 unsigned int __connman_service_get_order(struct connman_service *service)
3956 GSequenceIter *iter;
3958 if (service == NULL)
3961 if (service->favorite == FALSE) {
3966 iter = g_hash_table_lookup(service_hash, service->identifier);
3968 if (g_sequence_iter_get_position(iter) == 0)
3970 else if (service->type == CONNMAN_SERVICE_TYPE_VPN)
3971 service->order = 10;
3977 return service->order;
3980 static enum connman_service_type convert_network_type(struct connman_network *network)
3982 enum connman_network_type type = connman_network_get_type(network);
3985 case CONNMAN_NETWORK_TYPE_UNKNOWN:
3986 case CONNMAN_NETWORK_TYPE_VENDOR:
3988 case CONNMAN_NETWORK_TYPE_ETHERNET:
3989 return CONNMAN_SERVICE_TYPE_ETHERNET;
3990 case CONNMAN_NETWORK_TYPE_WIFI:
3991 return CONNMAN_SERVICE_TYPE_WIFI;
3992 case CONNMAN_NETWORK_TYPE_WIMAX:
3993 return CONNMAN_SERVICE_TYPE_WIMAX;
3994 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
3995 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
3996 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
3997 case CONNMAN_NETWORK_TYPE_CELLULAR:
3998 return CONNMAN_SERVICE_TYPE_CELLULAR;
4001 return CONNMAN_SERVICE_TYPE_UNKNOWN;
4004 static enum connman_service_mode convert_wifi_mode(const char *mode)
4007 return CONNMAN_SERVICE_MODE_UNKNOWN;
4008 else if (g_str_equal(mode, "managed") == TRUE)
4009 return CONNMAN_SERVICE_MODE_MANAGED;
4010 else if (g_str_equal(mode, "adhoc") == TRUE)
4011 return CONNMAN_SERVICE_MODE_ADHOC;
4013 return CONNMAN_SERVICE_MODE_UNKNOWN;
4016 static enum connman_service_security convert_wifi_security(const char *security)
4018 if (security == NULL)
4019 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
4020 else if (g_str_equal(security, "none") == TRUE)
4021 return CONNMAN_SERVICE_SECURITY_NONE;
4022 else if (g_str_equal(security, "wep") == TRUE)
4023 return CONNMAN_SERVICE_SECURITY_WEP;
4024 else if (g_str_equal(security, "psk") == TRUE)
4025 return CONNMAN_SERVICE_SECURITY_PSK;
4026 else if (g_str_equal(security, "ieee8021x") == TRUE)
4027 return CONNMAN_SERVICE_SECURITY_8021X;
4028 else if (g_str_equal(security, "wpa") == TRUE)
4029 return CONNMAN_SERVICE_SECURITY_WPA;
4030 else if (g_str_equal(security, "rsn") == TRUE)
4031 return CONNMAN_SERVICE_SECURITY_RSN;
4033 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
4036 static enum connman_service_mode convert_cellular_mode(connman_uint8_t mode)
4041 return CONNMAN_SERVICE_MODE_GPRS;
4043 return CONNMAN_SERVICE_MODE_EDGE;
4048 return CONNMAN_SERVICE_MODE_UMTS;
4051 return CONNMAN_SERVICE_MODE_UNKNOWN;
4054 static void update_from_network(struct connman_service *service,
4055 struct connman_network *network)
4057 connman_uint8_t strength = service->strength;
4058 GSequenceIter *iter;
4061 DBG("service %p network %p", service, network);
4063 if (is_connected(service) == TRUE)
4066 if (is_connecting(service) == TRUE)
4069 str = connman_network_get_string(network, "Name");
4071 g_free(service->name);
4072 service->name = g_strdup(str);
4073 service->hidden = FALSE;
4075 g_free(service->name);
4076 service->name = NULL;
4077 service->hidden = TRUE;
4080 service->strength = connman_network_get_uint8(network, "Strength");
4081 service->roaming = connman_network_get_bool(network, "Roaming");
4083 if (service->strength == 0) {
4085 * Filter out 0-values; it's unclear what they mean
4086 * and they cause anomalous sorting of the priority list.
4088 service->strength = strength;
4091 str = connman_network_get_string(network, "WiFi.Mode");
4092 service->mode = convert_wifi_mode(str);
4094 str = connman_network_get_string(network, "WiFi.Security");
4095 service->security = convert_wifi_security(str);
4097 str = connman_network_get_string(network, "Cellular.MCC");
4098 g_free(service->mcc);
4099 service->mcc = g_strdup(str);
4101 str = connman_network_get_string(network, "Cellular.MNC");
4102 g_free(service->mnc);
4103 service->mnc = g_strdup(str);
4105 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
4106 connman_uint8_t value = connman_network_get_uint8(network,
4109 service->mode = convert_cellular_mode(value);
4112 if (service->strength > strength && service->network != NULL) {
4113 connman_network_unref(service->network);
4114 service->network = connman_network_ref(network);
4116 strength_changed(service);
4119 if (service->network == NULL)
4120 service->network = connman_network_ref(network);
4122 iter = g_hash_table_lookup(service_hash, service->identifier);
4124 g_sequence_sort_changed(iter, service_compare, NULL);
4128 * __connman_service_create_from_network:
4129 * @network: network structure
4131 * Look up service by network and if not found, create one
4133 struct connman_service * __connman_service_create_from_network(struct connman_network *network)
4135 struct connman_service *service;
4136 struct connman_device *device;
4137 const char *ident, *group;
4141 DBG("network %p", network);
4143 ident = __connman_network_get_ident(network);
4147 group = connman_network_get_group(network);
4151 name = g_strdup_printf("%s_%s_%s",
4152 __connman_network_get_type(network), ident, group);
4153 service = service_get(name);
4156 if (service == NULL)
4159 if (__connman_network_get_weakness(network) == TRUE)
4162 if (service->path != NULL) {
4163 update_from_network(service, network);
4164 __connman_profile_changed(TRUE);
4168 service->type = convert_network_type(network);
4170 switch (service->type) {
4171 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4172 case CONNMAN_SERVICE_TYPE_SYSTEM:
4173 case CONNMAN_SERVICE_TYPE_ETHERNET:
4174 case CONNMAN_SERVICE_TYPE_WIMAX:
4175 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4176 case CONNMAN_SERVICE_TYPE_GPS:
4177 case CONNMAN_SERVICE_TYPE_VPN:
4178 case CONNMAN_SERVICE_TYPE_GADGET:
4179 service->autoconnect = FALSE;
4181 case CONNMAN_SERVICE_TYPE_WIFI:
4182 case CONNMAN_SERVICE_TYPE_CELLULAR:
4183 service->autoconnect = TRUE;
4187 service->state = CONNMAN_SERVICE_STATE_IDLE;
4189 update_from_network(service, network);
4191 index = connman_network_get_index(network);
4192 setup_ip4config(service, index);
4193 setup_ip6config(service, index);
4195 service_register(service);
4197 if (service->favorite == TRUE) {
4198 device = connman_network_get_device(service->network);
4199 if (device && __connman_device_scanning(device) == FALSE)
4200 __connman_service_auto_connect();
4206 void __connman_service_update_from_network(struct connman_network *network)
4208 struct connman_service *service;
4209 enum connman_service_mode mode;
4210 connman_uint8_t strength, value;
4211 connman_bool_t roaming;
4212 GSequenceIter *iter;
4214 connman_bool_t stats_enable;
4216 DBG("network %p", network);
4218 service = __connman_service_lookup_from_network(network);
4219 if (service == NULL)
4222 if (service->network == NULL)
4225 name = connman_network_get_string(service->network, "Name");
4226 if (g_strcmp0(service->name, name) != 0) {
4227 g_free(service->name);
4228 service->name = g_strdup(name);
4229 connman_dbus_property_changed_basic(service->path,
4230 CONNMAN_SERVICE_INTERFACE, "Name",
4231 DBUS_TYPE_STRING, &service->name);
4234 strength = connman_network_get_uint8(service->network, "Strength");
4235 if (strength == service->strength)
4238 service->strength = strength;
4240 strength_changed(service);
4243 roaming = connman_network_get_bool(service->network, "Roaming");
4244 if (roaming == service->roaming)
4247 stats_enable = stats_enabled(service);
4248 if (stats_enable == TRUE)
4249 stats_stop(service);
4251 service->roaming = roaming;
4253 if (stats_enable == TRUE)
4254 stats_start(service);
4256 roaming_changed(service);
4258 iter = g_hash_table_lookup(service_hash, service->identifier);
4260 g_sequence_sort_changed(iter, service_compare, NULL);
4263 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
4266 value = connman_network_get_uint8(service->network, "Cellular.Mode");
4267 mode = convert_cellular_mode(value);
4269 if (mode == service->mode)
4272 service->mode = mode;
4274 mode_changed(service);
4277 void __connman_service_remove_from_network(struct connman_network *network)
4279 struct connman_service *service;
4281 DBG("network %p", network);
4283 service = __connman_service_lookup_from_network(network);
4284 if (service == NULL)
4287 __connman_service_put(service);
4291 * __connman_service_create_from_provider:
4292 * @provider: provider structure
4294 * Look up service by provider and if not found, create one
4296 struct connman_service *
4297 __connman_service_create_from_provider(struct connman_provider *provider)
4299 struct connman_service *service;
4300 const char *ident, *str;
4302 int index = connman_provider_get_index(provider);
4304 DBG("provider %p", provider);
4306 ident = __connman_provider_get_ident(provider);
4310 name = g_strdup_printf("vpn_%s", ident);
4311 service = service_get(name);
4314 if (service == NULL)
4317 service->type = CONNMAN_SERVICE_TYPE_VPN;
4318 service->provider = connman_provider_ref(provider);
4319 service->autoconnect = FALSE;
4321 service->state = CONNMAN_SERVICE_STATE_IDLE;
4323 str = connman_provider_get_string(provider, "Name");
4325 g_free(service->name);
4326 service->name = g_strdup(str);
4327 service->hidden = FALSE;
4329 g_free(service->name);
4330 service->name = NULL;
4331 service->hidden = TRUE;
4334 service->strength = 0;
4336 service->ipconfig_ipv4 = connman_ipconfig_create(index,
4337 CONNMAN_IPCONFIG_TYPE_IPV4);
4338 if (service->ipconfig_ipv4 == NULL)
4341 connman_ipconfig_set_method(service->ipconfig_ipv4,
4342 CONNMAN_IPCONFIG_METHOD_MANUAL);
4343 connman_ipconfig_set_data(service->ipconfig_ipv4, service);
4344 connman_ipconfig_set_ops(service->ipconfig_ipv4, &service_ops);
4346 service->ipconfig_ipv6 = connman_ipconfig_create(index,
4347 CONNMAN_IPCONFIG_TYPE_IPV6);
4348 if (service->ipconfig_ipv6 == NULL)
4351 connman_ipconfig_set_method(service->ipconfig_ipv6,
4352 CONNMAN_IPCONFIG_METHOD_OFF);
4353 connman_ipconfig_set_data(service->ipconfig_ipv6, service);
4354 connman_ipconfig_set_ops(service->ipconfig_ipv6, &service_ops);
4356 service_register(service);
4361 static int service_load(struct connman_service *service)
4363 const char *ident = service->profile;
4365 GError *error = NULL;
4366 gchar *pathname, *data = NULL;
4369 connman_bool_t autoconnect;
4370 unsigned int ssid_len;
4373 DBG("service %p", service);
4378 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
4379 if (pathname == NULL)
4382 keyfile = g_key_file_new();
4384 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
4391 if (g_key_file_load_from_data(keyfile, data, length,
4392 0, NULL) == FALSE) {
4399 switch (service->type) {
4400 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4401 case CONNMAN_SERVICE_TYPE_SYSTEM:
4402 case CONNMAN_SERVICE_TYPE_ETHERNET:
4403 case CONNMAN_SERVICE_TYPE_GPS:
4404 case CONNMAN_SERVICE_TYPE_VPN:
4405 case CONNMAN_SERVICE_TYPE_GADGET:
4407 case CONNMAN_SERVICE_TYPE_WIFI:
4408 if (service->name == NULL) {
4411 name = g_key_file_get_string(keyfile,
4412 service->identifier, "Name", NULL);
4414 g_free(service->name);
4415 service->name = name;
4418 if (service->network != NULL)
4419 connman_network_set_name(service->network,
4423 if (service->network &&
4424 connman_network_get_blob(service->network,
4425 "WiFi.SSID", &ssid_len) == NULL) {
4428 hex_ssid = g_key_file_get_string(keyfile,
4429 service->identifier,
4432 if (hex_ssid != NULL) {
4434 unsigned int i, j = 0, hex;
4435 size_t hex_ssid_len = strlen(hex_ssid);
4437 ssid = g_try_malloc0(hex_ssid_len / 2);
4444 for (i = 0; i < hex_ssid_len; i += 2) {
4445 sscanf(hex_ssid + i, "%02x", &hex);
4449 connman_network_set_blob(service->network,
4450 "WiFi.SSID", ssid, hex_ssid_len / 2);
4457 case CONNMAN_SERVICE_TYPE_WIMAX:
4458 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4459 case CONNMAN_SERVICE_TYPE_CELLULAR:
4460 service->apn = g_key_file_get_string(keyfile,
4461 service->identifier, "APN", NULL);
4463 service->username = g_key_file_get_string(keyfile,
4464 service->identifier, "Username", NULL);
4466 service->password = g_key_file_get_string(keyfile,
4467 service->identifier, "Password", NULL);
4469 service->favorite = g_key_file_get_boolean(keyfile,
4470 service->identifier, "Favorite", NULL);
4472 autoconnect = g_key_file_get_boolean(keyfile,
4473 service->identifier, "AutoConnect", &error);
4475 service->autoconnect = autoconnect;
4476 g_clear_error(&error);
4478 str = g_key_file_get_string(keyfile,
4479 service->identifier, "Failure", NULL);
4481 if (service->favorite == FALSE)
4482 service->state = CONNMAN_SERVICE_STATE_FAILURE;
4483 service->error = string2error(str);
4488 str = g_key_file_get_string(keyfile,
4489 service->identifier, "Modified", NULL);
4491 g_time_val_from_iso8601(str, &service->modified);
4495 str = g_key_file_get_string(keyfile,
4496 service->identifier, "Passphrase", NULL);
4498 g_free(service->passphrase);
4499 service->passphrase = str;
4502 if (service->ipconfig_ipv4 != NULL)
4503 __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
4504 service->identifier, "IPv4.");
4506 if (service->ipconfig_ipv6 != NULL)
4507 __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
4508 service->identifier, "IPv6.");
4510 service->nameservers = g_key_file_get_string_list(keyfile,
4511 service->identifier, "Nameservers", &length, NULL);
4512 if (service->nameservers != NULL && length == 0) {
4513 g_strfreev(service->nameservers);
4514 service->nameservers = NULL;
4517 service->domains = g_key_file_get_string_list(keyfile,
4518 service->identifier, "Domains", &length, NULL);
4519 if (service->domains != NULL && length == 0) {
4520 g_strfreev(service->domains);
4521 service->domains = NULL;
4524 str = g_key_file_get_string(keyfile,
4525 service->identifier, "Proxy.Method", NULL);
4526 service->proxy = string2proxymethod(str);
4528 service->proxies = g_key_file_get_string_list(keyfile,
4529 service->identifier, "Proxy.Servers", &length, NULL);
4530 if (service->proxies != NULL && length == 0) {
4531 g_strfreev(service->proxies);
4532 service->proxies = NULL;
4535 service->excludes = g_key_file_get_string_list(keyfile,
4536 service->identifier, "Proxy.Excludes", &length, NULL);
4537 if (service->excludes != NULL && length == 0) {
4538 g_strfreev(service->excludes);
4539 service->excludes = NULL;
4542 str = g_key_file_get_string(keyfile,
4543 service->identifier, "Proxy.URL", NULL);
4545 g_free(service->pac);
4550 g_key_file_free(keyfile);
4555 static int service_save(struct connman_service *service)
4557 const char *ident = service->profile;
4559 gchar *pathname, *data = NULL;
4562 const char *cst_str = NULL;
4565 DBG("service %p", service);
4570 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
4571 if (pathname == NULL)
4574 keyfile = g_key_file_new();
4576 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
4580 if (g_key_file_load_from_data(keyfile, data, length,
4588 if (service->name != NULL)
4589 g_key_file_set_string(keyfile, service->identifier,
4590 "Name", service->name);
4592 switch (service->type) {
4593 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4594 case CONNMAN_SERVICE_TYPE_SYSTEM:
4595 case CONNMAN_SERVICE_TYPE_ETHERNET:
4596 case CONNMAN_SERVICE_TYPE_GPS:
4597 case CONNMAN_SERVICE_TYPE_VPN:
4598 case CONNMAN_SERVICE_TYPE_GADGET:
4600 case CONNMAN_SERVICE_TYPE_WIFI:
4601 if (service->network) {
4602 const unsigned char *ssid;
4603 unsigned int ssid_len = 0;
4605 ssid = connman_network_get_blob(service->network,
4606 "WiFi.SSID", &ssid_len);
4608 if (ssid != NULL && ssid_len > 0 && ssid[0] != '\0') {
4609 char *identifier = service->identifier;
4613 str = g_string_sized_new(ssid_len * 2);
4619 for (i = 0; i < ssid_len; i++)
4620 g_string_append_printf(str,
4623 g_key_file_set_string(keyfile, identifier,
4626 g_string_free(str, TRUE);
4631 case CONNMAN_SERVICE_TYPE_WIMAX:
4632 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
4633 case CONNMAN_SERVICE_TYPE_CELLULAR:
4634 if (service->apn != NULL)
4635 g_key_file_set_string(keyfile, service->identifier,
4636 "APN", service->apn);
4638 if (service->username != NULL)
4639 g_key_file_set_string(keyfile, service->identifier,
4640 "Username", service->username);
4642 if (service->password != NULL)
4643 g_key_file_set_string(keyfile, service->identifier,
4644 "Password", service->password);
4646 g_key_file_set_boolean(keyfile, service->identifier,
4647 "Favorite", service->favorite);
4649 if (service->favorite == TRUE)
4650 g_key_file_set_boolean(keyfile, service->identifier,
4651 "AutoConnect", service->autoconnect);
4653 if (service->state == CONNMAN_SERVICE_STATE_FAILURE) {
4654 const char *failure = error2string(service->error);
4655 if (failure != NULL)
4656 g_key_file_set_string(keyfile,
4657 service->identifier,
4658 "Failure", failure);
4660 g_key_file_remove_key(keyfile, service->identifier,
4666 str = g_time_val_to_iso8601(&service->modified);
4668 g_key_file_set_string(keyfile, service->identifier,
4673 if (service->passphrase != NULL && strlen(service->passphrase) > 0)
4674 g_key_file_set_string(keyfile, service->identifier,
4675 "Passphrase", service->passphrase);
4677 g_key_file_remove_key(keyfile, service->identifier,
4678 "Passphrase", NULL);
4680 if (service->ipconfig_ipv4 != NULL)
4681 __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
4682 service->identifier, "IPv4.");
4684 if (service->ipconfig_ipv6 != NULL)
4685 __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
4686 service->identifier, "IPv6.");
4688 if (service->nameservers != NULL) {
4689 guint len = g_strv_length(service->nameservers);
4691 g_key_file_set_string_list(keyfile, service->identifier,
4693 (const gchar **) service->nameservers, len);
4695 g_key_file_remove_key(keyfile, service->identifier,
4696 "Nameservers", NULL);
4698 if (service->domains != NULL) {
4699 guint len = g_strv_length(service->domains);
4701 g_key_file_set_string_list(keyfile, service->identifier,
4703 (const gchar **) service->domains, len);
4705 g_key_file_remove_key(keyfile, service->identifier,
4708 cst_str = proxymethod2string(service->proxy);
4709 if (cst_str != NULL)
4710 g_key_file_set_string(keyfile, service->identifier,
4711 "Proxy.Method", cst_str);
4713 if (service->proxies != NULL) {
4714 guint len = g_strv_length(service->proxies);
4716 g_key_file_set_string_list(keyfile, service->identifier,
4718 (const gchar **) service->proxies, len);
4720 g_key_file_remove_key(keyfile, service->identifier,
4721 "Proxy.Servers", NULL);
4723 if (service->excludes != NULL) {
4724 guint len = g_strv_length(service->excludes);
4726 g_key_file_set_string_list(keyfile, service->identifier,
4728 (const gchar **) service->excludes, len);
4730 g_key_file_remove_key(keyfile, service->identifier,
4731 "Proxy.Excludes", NULL);
4733 if (service->pac != NULL && strlen(service->pac) > 0)
4734 g_key_file_set_string(keyfile, service->identifier,
4735 "Proxy.URL", service->pac);
4737 g_key_file_remove_key(keyfile, service->identifier,
4740 data = g_key_file_to_data(keyfile, &length, NULL);
4742 if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
4743 connman_error("Failed to store service information");
4748 g_key_file_free(keyfile);
4755 static struct connman_storage service_storage = {
4757 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
4758 .service_load = service_load,
4759 .service_save = service_save,
4762 int __connman_service_init(void)
4766 connection = connman_dbus_get_connection();
4768 if (connman_storage_register(&service_storage) < 0)
4769 connman_error("Failed to register service storage");
4771 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
4774 service_list = g_sequence_new(service_free);
4779 void __connman_service_cleanup(void)
4783 g_sequence_free(service_list);
4784 service_list = NULL;
4786 g_hash_table_destroy(service_hash);
4787 service_hash = NULL;
4789 g_slist_free(counter_list);
4790 counter_list = NULL;
4792 connman_storage_unregister(&service_storage);
4794 dbus_connection_unref(connection);