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;
39 struct connman_service {
43 enum connman_service_type type;
44 enum connman_service_mode mode;
45 enum connman_service_security security;
46 enum connman_service_state state;
47 enum connman_service_error error;
48 connman_uint8_t strength;
49 connman_bool_t favorite;
50 connman_bool_t immutable;
51 connman_bool_t hidden;
52 connman_bool_t ignore;
53 connman_bool_t autoconnect;
54 connman_bool_t userconnect;
65 connman_bool_t roaming;
66 struct connman_ipconfig *ipconfig;
67 struct connman_network *network;
68 /* 802.1x settings from the config files */
72 char *client_cert_file;
73 char *private_key_file;
74 char *private_key_passphrase;
78 struct connman_location *location;
81 static void append_path(gpointer value, gpointer user_data)
83 struct connman_service *service = value;
84 DBusMessageIter *iter = user_data;
86 if (service->path == NULL || service->hidden == TRUE)
89 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
93 void __connman_service_list(DBusMessageIter *iter, void *user_data)
95 g_sequence_foreach(service_list, append_path, iter);
100 struct connman_service *service;
103 static void compare_path(gpointer value, gpointer user_data)
105 struct connman_service *service = value;
106 struct find_data *data = user_data;
108 if (data->service != NULL)
111 if (g_strcmp0(service->path, data->path) == 0)
112 data->service = service;
115 static struct connman_service *find_service(const char *path)
117 struct find_data data = { .path = path, .service = NULL };
119 DBG("path %s", path);
121 g_sequence_foreach(service_list, compare_path, &data);
126 const char *__connman_service_type2string(enum connman_service_type type)
129 case CONNMAN_SERVICE_TYPE_UNKNOWN:
131 case CONNMAN_SERVICE_TYPE_SYSTEM:
133 case CONNMAN_SERVICE_TYPE_ETHERNET:
135 case CONNMAN_SERVICE_TYPE_WIFI:
137 case CONNMAN_SERVICE_TYPE_WIMAX:
139 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
141 case CONNMAN_SERVICE_TYPE_CELLULAR:
143 case CONNMAN_SERVICE_TYPE_GPS:
145 case CONNMAN_SERVICE_TYPE_VPN:
152 static const char *mode2string(enum connman_service_mode mode)
155 case CONNMAN_SERVICE_MODE_UNKNOWN:
157 case CONNMAN_SERVICE_MODE_MANAGED:
159 case CONNMAN_SERVICE_MODE_ADHOC:
161 case CONNMAN_SERVICE_MODE_GPRS:
163 case CONNMAN_SERVICE_MODE_EDGE:
165 case CONNMAN_SERVICE_MODE_UMTS:
172 static const char *security2string(enum connman_service_security security)
175 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
177 case CONNMAN_SERVICE_SECURITY_NONE:
179 case CONNMAN_SERVICE_SECURITY_WEP:
181 case CONNMAN_SERVICE_SECURITY_PSK:
183 case CONNMAN_SERVICE_SECURITY_8021X:
185 case CONNMAN_SERVICE_SECURITY_WPA:
187 case CONNMAN_SERVICE_SECURITY_RSN:
194 static const char *state2string(enum connman_service_state state)
197 case CONNMAN_SERVICE_STATE_UNKNOWN:
199 case CONNMAN_SERVICE_STATE_IDLE:
201 case CONNMAN_SERVICE_STATE_ASSOCIATION:
202 return "association";
203 case CONNMAN_SERVICE_STATE_CONFIGURATION:
204 return "configuration";
205 case CONNMAN_SERVICE_STATE_READY:
207 case CONNMAN_SERVICE_STATE_LOGIN:
209 case CONNMAN_SERVICE_STATE_ONLINE:
211 case CONNMAN_SERVICE_STATE_DISCONNECT:
213 case CONNMAN_SERVICE_STATE_FAILURE:
220 static const char *error2string(enum connman_service_error error)
223 case CONNMAN_SERVICE_ERROR_UNKNOWN:
225 case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
226 return "out-of-range";
227 case CONNMAN_SERVICE_ERROR_PIN_MISSING:
228 return "pin-missing";
229 case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
230 return "dhcp-failed";
231 case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
232 return "connect-failed";
238 static enum connman_service_error string2error(const char *error)
240 if (g_strcmp0(error, "dhcp-failed") == 0)
241 return CONNMAN_SERVICE_ERROR_DHCP_FAILED;
242 else if (g_strcmp0(error, "pin-missing") == 0)
243 return CONNMAN_SERVICE_ERROR_PIN_MISSING;
245 return CONNMAN_SERVICE_ERROR_UNKNOWN;
248 static struct connman_service *get_default(void)
250 struct connman_service *service;
253 iter = g_sequence_get_begin_iter(service_list);
255 if (g_sequence_iter_is_end(iter) == TRUE)
258 service = g_sequence_get(iter);
260 if (service->state != CONNMAN_SERVICE_STATE_READY)
266 static void default_changed(void)
268 struct connman_service *service = get_default();
270 __connman_notifier_default_changed(service);
273 const char *__connman_service_default(void)
275 struct connman_service *service;
277 service = get_default();
281 return __connman_service_type2string(service->type);
284 static void mode_changed(struct connman_service *service)
288 str = mode2string(service->mode);
292 connman_dbus_property_changed_basic(service->path,
293 CONNMAN_SERVICE_INTERFACE, "Mode",
294 DBUS_TYPE_STRING, &str);
297 static void state_changed(struct connman_service *service)
301 str = state2string(service->state);
305 connman_dbus_property_changed_basic(service->path,
306 CONNMAN_SERVICE_INTERFACE, "State",
307 DBUS_TYPE_STRING, &str);
310 static void strength_changed(struct connman_service *service)
312 if (service->strength == 0)
315 connman_dbus_property_changed_basic(service->path,
316 CONNMAN_SERVICE_INTERFACE, "Strength",
317 DBUS_TYPE_BYTE, &service->strength);
320 static void favorite_changed(struct connman_service *service)
322 if (service->path == NULL)
325 connman_dbus_property_changed_basic(service->path,
326 CONNMAN_SERVICE_INTERFACE, "Favorite",
327 DBUS_TYPE_BOOLEAN, &service->favorite);
330 static void immutable_changed(struct connman_service *service)
332 if (service->path == NULL)
335 connman_dbus_property_changed_basic(service->path,
336 CONNMAN_SERVICE_INTERFACE, "Immutable",
337 DBUS_TYPE_BOOLEAN, &service->immutable);
340 static void roaming_changed(struct connman_service *service)
342 if (service->path == NULL)
345 connman_dbus_property_changed_basic(service->path,
346 CONNMAN_SERVICE_INTERFACE, "Roaming",
347 DBUS_TYPE_BOOLEAN, &service->roaming);
350 static void autoconnect_changed(struct connman_service *service)
352 if (service->path == NULL)
355 connman_dbus_property_changed_basic(service->path,
356 CONNMAN_SERVICE_INTERFACE, "AutoConnect",
357 DBUS_TYPE_BOOLEAN, &service->autoconnect);
360 static void passphrase_changed(struct connman_service *service)
362 dbus_bool_t required;
364 switch (service->type) {
365 case CONNMAN_SERVICE_TYPE_UNKNOWN:
366 case CONNMAN_SERVICE_TYPE_SYSTEM:
367 case CONNMAN_SERVICE_TYPE_ETHERNET:
368 case CONNMAN_SERVICE_TYPE_WIMAX:
369 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
370 case CONNMAN_SERVICE_TYPE_CELLULAR:
371 case CONNMAN_SERVICE_TYPE_GPS:
372 case CONNMAN_SERVICE_TYPE_VPN:
374 case CONNMAN_SERVICE_TYPE_WIFI:
377 switch (service->security) {
378 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
379 case CONNMAN_SERVICE_SECURITY_NONE:
381 case CONNMAN_SERVICE_SECURITY_WEP:
382 case CONNMAN_SERVICE_SECURITY_PSK:
383 case CONNMAN_SERVICE_SECURITY_WPA:
384 case CONNMAN_SERVICE_SECURITY_RSN:
385 if (service->passphrase == NULL)
388 case CONNMAN_SERVICE_SECURITY_8021X:
394 connman_dbus_property_changed_basic(service->path,
395 CONNMAN_SERVICE_INTERFACE, "PassphraseRequired",
396 DBUS_TYPE_BOOLEAN, &required);
399 static void apn_changed(struct connman_service *service)
401 dbus_bool_t required;
403 switch (service->type) {
404 case CONNMAN_SERVICE_TYPE_UNKNOWN:
405 case CONNMAN_SERVICE_TYPE_SYSTEM:
406 case CONNMAN_SERVICE_TYPE_ETHERNET:
407 case CONNMAN_SERVICE_TYPE_WIMAX:
408 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
409 case CONNMAN_SERVICE_TYPE_WIFI:
410 case CONNMAN_SERVICE_TYPE_GPS:
411 case CONNMAN_SERVICE_TYPE_VPN:
413 case CONNMAN_SERVICE_TYPE_CELLULAR:
417 required = (service->apn == NULL) ? TRUE : FALSE;
419 connman_dbus_property_changed_basic(service->path,
420 CONNMAN_SERVICE_INTERFACE, "SetupRequired",
421 DBUS_TYPE_BOOLEAN, &required);
424 static void append_ethernet(DBusMessageIter *iter, void *user_data)
426 struct connman_service *service = user_data;
428 switch (service->state) {
429 case CONNMAN_SERVICE_STATE_UNKNOWN:
430 case CONNMAN_SERVICE_STATE_IDLE:
431 case CONNMAN_SERVICE_STATE_FAILURE:
432 case CONNMAN_SERVICE_STATE_DISCONNECT:
434 case CONNMAN_SERVICE_STATE_ASSOCIATION:
435 case CONNMAN_SERVICE_STATE_CONFIGURATION:
436 case CONNMAN_SERVICE_STATE_READY:
437 case CONNMAN_SERVICE_STATE_LOGIN:
438 case CONNMAN_SERVICE_STATE_ONLINE:
442 if (service->ipconfig != NULL)
443 __connman_ipconfig_append_ethernet(service->ipconfig, iter);
446 static void append_ipv4(DBusMessageIter *iter, void *user_data)
448 struct connman_service *service = user_data;
450 switch (service->state) {
451 case CONNMAN_SERVICE_STATE_UNKNOWN:
452 case CONNMAN_SERVICE_STATE_IDLE:
453 case CONNMAN_SERVICE_STATE_FAILURE:
454 case CONNMAN_SERVICE_STATE_DISCONNECT:
455 case CONNMAN_SERVICE_STATE_ASSOCIATION:
456 case CONNMAN_SERVICE_STATE_CONFIGURATION:
458 case CONNMAN_SERVICE_STATE_READY:
459 case CONNMAN_SERVICE_STATE_LOGIN:
460 case CONNMAN_SERVICE_STATE_ONLINE:
464 if (service->ipconfig != NULL)
465 __connman_ipconfig_append_ipv4(service->ipconfig, iter);
468 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
470 struct connman_service *service = user_data;
472 if (service->ipconfig != NULL)
473 __connman_ipconfig_append_ipv4config(service->ipconfig, iter);
476 static void append_proxy(DBusMessageIter *iter, void *user_data)
478 struct connman_service *service = user_data;
480 switch (service->state) {
481 case CONNMAN_SERVICE_STATE_UNKNOWN:
482 case CONNMAN_SERVICE_STATE_IDLE:
483 case CONNMAN_SERVICE_STATE_FAILURE:
484 case CONNMAN_SERVICE_STATE_DISCONNECT:
485 case CONNMAN_SERVICE_STATE_ASSOCIATION:
486 case CONNMAN_SERVICE_STATE_CONFIGURATION:
488 case CONNMAN_SERVICE_STATE_READY:
489 case CONNMAN_SERVICE_STATE_LOGIN:
490 case CONNMAN_SERVICE_STATE_ONLINE:
494 if (service->ipconfig != NULL)
495 __connman_ipconfig_append_proxy(service->ipconfig, iter);
498 static void settings_changed(struct connman_service *service)
500 connman_dbus_property_changed_dict(service->path,
501 CONNMAN_SERVICE_INTERFACE, "IPv4",
502 append_ipv4, service);
505 static void ipv4_configuration_changed(struct connman_service *service)
507 connman_dbus_property_changed_dict(service->path,
508 CONNMAN_SERVICE_INTERFACE,
509 "IPv4.Configuration",
514 static DBusMessage *get_properties(DBusConnection *conn,
515 DBusMessage *msg, void *user_data)
517 struct connman_service *service = user_data;
519 DBusMessageIter array, dict;
520 dbus_bool_t required;
523 DBG("service %p", service);
525 reply = dbus_message_new_method_return(msg);
529 dbus_message_iter_init_append(reply, &array);
531 connman_dbus_dict_open(&array, &dict);
533 str = __connman_service_type2string(service->type);
535 connman_dbus_dict_append_basic(&dict, "Type",
536 DBUS_TYPE_STRING, &str);
538 str = mode2string(service->mode);
540 connman_dbus_dict_append_basic(&dict, "Mode",
541 DBUS_TYPE_STRING, &str);
543 str = security2string(service->security);
545 connman_dbus_dict_append_basic(&dict, "Security",
546 DBUS_TYPE_STRING, &str);
548 str = state2string(service->state);
550 connman_dbus_dict_append_basic(&dict, "State",
551 DBUS_TYPE_STRING, &str);
553 str = error2string(service->error);
555 connman_dbus_dict_append_basic(&dict, "Error",
556 DBUS_TYPE_STRING, &str);
558 if (service->strength > 0)
559 connman_dbus_dict_append_basic(&dict, "Strength",
560 DBUS_TYPE_BYTE, &service->strength);
562 connman_dbus_dict_append_basic(&dict, "Favorite",
563 DBUS_TYPE_BOOLEAN, &service->favorite);
565 connman_dbus_dict_append_basic(&dict, "Immutable",
566 DBUS_TYPE_BOOLEAN, &service->immutable);
568 if (service->favorite == TRUE)
569 connman_dbus_dict_append_basic(&dict, "AutoConnect",
570 DBUS_TYPE_BOOLEAN, &service->autoconnect);
572 connman_dbus_dict_append_basic(&dict, "AutoConnect",
573 DBUS_TYPE_BOOLEAN, &service->favorite);
575 if (service->name != NULL)
576 connman_dbus_dict_append_basic(&dict, "Name",
577 DBUS_TYPE_STRING, &service->name);
579 switch (service->type) {
580 case CONNMAN_SERVICE_TYPE_UNKNOWN:
581 case CONNMAN_SERVICE_TYPE_SYSTEM:
582 case CONNMAN_SERVICE_TYPE_GPS:
583 case CONNMAN_SERVICE_TYPE_VPN:
585 case CONNMAN_SERVICE_TYPE_CELLULAR:
586 connman_dbus_dict_append_basic(&dict, "Roaming",
587 DBUS_TYPE_BOOLEAN, &service->roaming);
589 if (service->mcc != NULL && service->mnc != NULL) {
590 connman_dbus_dict_append_basic(&dict, "MCC",
591 DBUS_TYPE_STRING, &service->mcc);
592 connman_dbus_dict_append_basic(&dict, "MNC",
593 DBUS_TYPE_STRING, &service->mnc);
596 if (service->apn != NULL) {
597 connman_dbus_dict_append_basic(&dict, "APN",
598 DBUS_TYPE_STRING, &service->apn);
600 if (service->username != NULL)
601 connman_dbus_dict_append_basic(&dict,
602 "Username", DBUS_TYPE_STRING,
605 if (service->password != NULL)
606 connman_dbus_dict_append_basic(&dict,
607 "Password", DBUS_TYPE_STRING,
614 connman_dbus_dict_append_basic(&dict, "SetupRequired",
615 DBUS_TYPE_BOOLEAN, &required);
617 case CONNMAN_SERVICE_TYPE_WIFI:
618 if (service->passphrase != NULL &&
619 __connman_security_check_privilege(msg,
620 CONNMAN_SECURITY_PRIVILEGE_SECRET) == 0)
621 connman_dbus_dict_append_basic(&dict, "Passphrase",
622 DBUS_TYPE_STRING, &service->passphrase);
626 switch (service->security) {
627 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
628 case CONNMAN_SERVICE_SECURITY_NONE:
630 case CONNMAN_SERVICE_SECURITY_WEP:
631 case CONNMAN_SERVICE_SECURITY_PSK:
632 case CONNMAN_SERVICE_SECURITY_WPA:
633 case CONNMAN_SERVICE_SECURITY_RSN:
634 if (service->passphrase == NULL)
637 case CONNMAN_SERVICE_SECURITY_8021X:
641 connman_dbus_dict_append_basic(&dict, "PassphraseRequired",
642 DBUS_TYPE_BOOLEAN, &required);
644 case CONNMAN_SERVICE_TYPE_ETHERNET:
645 case CONNMAN_SERVICE_TYPE_WIMAX:
646 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
647 connman_dbus_dict_append_dict(&dict, "Ethernet",
648 append_ethernet, service);
652 connman_dbus_dict_append_dict(&dict, "IPv4", append_ipv4, service);
654 connman_dbus_dict_append_dict(&dict, "IPv4.Configuration",
655 append_ipv4config, service);
657 connman_dbus_dict_append_dict(&dict, "Proxy", append_proxy, service);
659 connman_dbus_dict_close(&array, &dict);
664 static DBusMessage *set_property(DBusConnection *conn,
665 DBusMessage *msg, void *user_data)
667 struct connman_service *service = user_data;
668 DBusMessageIter iter, value;
672 DBG("service %p", service);
674 if (dbus_message_iter_init(msg, &iter) == FALSE)
675 return __connman_error_invalid_arguments(msg);
677 dbus_message_iter_get_basic(&iter, &name);
678 dbus_message_iter_next(&iter);
679 dbus_message_iter_recurse(&iter, &value);
681 if (__connman_security_check_privilege(msg,
682 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
683 return __connman_error_permission_denied(msg);
685 type = dbus_message_iter_get_arg_type(&value);
687 if (g_str_has_prefix(name, "AutoConnect") == TRUE) {
688 connman_bool_t autoconnect;
690 if (type != DBUS_TYPE_BOOLEAN)
691 return __connman_error_invalid_arguments(msg);
693 if (service->favorite == FALSE)
694 return __connman_error_invalid_service(msg);
696 dbus_message_iter_get_basic(&value, &autoconnect);
698 if (service->autoconnect == autoconnect)
699 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
701 service->autoconnect = autoconnect;
703 autoconnect_changed(service);
705 __connman_storage_save_service(service);
706 } else if (g_str_equal(name, "Passphrase") == TRUE) {
707 const char *passphrase;
709 if (type != DBUS_TYPE_STRING)
710 return __connman_error_invalid_arguments(msg);
712 if (__connman_security_check_privilege(msg,
713 CONNMAN_SECURITY_PRIVILEGE_SECRET) < 0)
714 return __connman_error_permission_denied(msg);
716 dbus_message_iter_get_basic(&value, &passphrase);
718 g_free(service->passphrase);
719 service->passphrase = g_strdup(passphrase);
721 passphrase_changed(service);
723 if (service->network != NULL)
724 connman_network_set_string(service->network,
725 "WiFi.Passphrase", service->passphrase);
727 __connman_storage_save_service(service);
728 } else if (g_str_equal(name, "APN") == TRUE) {
731 if (type != DBUS_TYPE_STRING)
732 return __connman_error_invalid_arguments(msg);
734 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
735 return __connman_error_invalid_service(msg);
737 dbus_message_iter_get_basic(&value, &apn);
739 g_free(service->apn);
740 service->apn = g_strdup(apn);
742 apn_changed(service);
744 if (service->network != NULL)
745 connman_network_set_string(service->network,
746 "Cellular.APN", service->apn);
748 __connman_storage_save_service(service);
749 } else if (g_str_equal(name, "Username") == TRUE) {
750 const char *username;
752 if (type != DBUS_TYPE_STRING)
753 return __connman_error_invalid_arguments(msg);
755 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
756 return __connman_error_invalid_service(msg);
758 dbus_message_iter_get_basic(&value, &username);
760 g_free(service->username);
761 service->username = g_strdup(username);
763 if (service->network != NULL)
764 connman_network_set_string(service->network,
765 "Cellular.Username", service->username);
767 __connman_storage_save_service(service);
768 } else if (g_str_equal(name, "Password") == TRUE) {
769 const char *password;
771 if (type != DBUS_TYPE_STRING)
772 return __connman_error_invalid_arguments(msg);
774 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
775 return __connman_error_invalid_service(msg);
777 dbus_message_iter_get_basic(&value, &password);
779 g_free(service->password);
780 service->password = g_strdup(password);
782 if (service->network != NULL)
783 connman_network_set_string(service->network,
784 "Cellular.Password", service->password);
786 __connman_storage_save_service(service);
787 } else if (g_str_equal(name, "IPv4.Configuration") == TRUE) {
790 if (service->ipconfig == NULL)
791 return __connman_error_invalid_property(msg);
793 err = __connman_ipconfig_set_ipv4config(service->ipconfig,
796 return __connman_error_failed(msg, -err);
798 ipv4_configuration_changed(service);
800 __connman_storage_save_service(service);
802 return __connman_error_invalid_property(msg);
804 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
807 static void set_idle(struct connman_service *service)
809 service->state = CONNMAN_SERVICE_STATE_IDLE;
810 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
811 state_changed(service);
814 static DBusMessage *clear_property(DBusConnection *conn,
815 DBusMessage *msg, void *user_data)
817 struct connman_service *service = user_data;
820 DBG("service %p", service);
822 dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
825 if (__connman_security_check_privilege(msg,
826 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
827 return __connman_error_permission_denied(msg);
829 if (g_str_equal(name, "Error") == TRUE) {
832 g_get_current_time(&service->modified);
833 __connman_storage_save_service(service);
834 } else if (g_str_equal(name, "Passphrase") == TRUE) {
835 g_free(service->passphrase);
836 service->passphrase = NULL;
838 passphrase_changed(service);
840 __connman_storage_save_service(service);
842 return __connman_error_invalid_property(msg);
844 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
847 static connman_bool_t is_connecting(struct connman_service *service)
849 switch (service->state) {
850 case CONNMAN_SERVICE_STATE_UNKNOWN:
851 case CONNMAN_SERVICE_STATE_IDLE:
852 case CONNMAN_SERVICE_STATE_FAILURE:
853 case CONNMAN_SERVICE_STATE_DISCONNECT:
854 case CONNMAN_SERVICE_STATE_READY:
855 case CONNMAN_SERVICE_STATE_LOGIN:
856 case CONNMAN_SERVICE_STATE_ONLINE:
858 case CONNMAN_SERVICE_STATE_ASSOCIATION:
859 case CONNMAN_SERVICE_STATE_CONFIGURATION:
866 static connman_bool_t is_ignore(struct connman_service *service)
868 if (service->autoconnect == FALSE)
871 if (service->roaming == TRUE)
874 if (service->ignore == TRUE)
877 if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
883 void __connman_service_auto_connect(void)
885 struct connman_service *service = NULL;
890 iter = g_sequence_get_begin_iter(service_list);
892 while (g_sequence_iter_is_end(iter) == FALSE) {
893 service = g_sequence_get(iter);
895 if (service->pending != NULL)
898 if (is_connecting(service) == TRUE)
901 if (service->favorite == FALSE)
904 if (service->state == CONNMAN_SERVICE_STATE_READY)
907 if (is_ignore(service) == FALSE &&
908 service->state == CONNMAN_SERVICE_STATE_IDLE)
913 iter = g_sequence_iter_next(iter);
916 if (service != NULL) {
917 service->userconnect = FALSE;
918 __connman_service_connect(service);
922 static void remove_timeout(struct connman_service *service)
924 if (service->timeout > 0) {
925 g_source_remove(service->timeout);
926 service->timeout = 0;
930 static void reply_pending(struct connman_service *service, int error)
932 remove_timeout(service);
934 if (service->pending != NULL) {
938 reply = __connman_error_failed(service->pending,
941 g_dbus_send_message(connection, reply);
943 g_dbus_send_reply(connection, service->pending,
946 dbus_message_unref(service->pending);
947 service->pending = NULL;
951 static gboolean connect_timeout(gpointer user_data)
953 struct connman_service *service = user_data;
954 connman_bool_t autoconnect = FALSE;
956 DBG("service %p", service);
958 service->timeout = 0;
960 if (service->network != NULL)
961 __connman_network_disconnect(service->network);
963 __connman_ipconfig_disable(service->ipconfig);
965 if (service->pending != NULL) {
968 reply = __connman_error_operation_timeout(service->pending);
970 g_dbus_send_message(connection, reply);
972 dbus_message_unref(service->pending);
973 service->pending = NULL;
977 __connman_service_indicate_state(service,
978 CONNMAN_SERVICE_STATE_FAILURE);
980 if (autoconnect == TRUE && service->userconnect == FALSE)
981 __connman_service_auto_connect();
986 static void set_reconnect_state(struct connman_service *service,
987 connman_bool_t reconnect)
989 struct connman_device *device;
991 if (service->network == NULL)
994 device = connman_network_get_device(service->network);
998 __connman_device_set_reconnect(device, reconnect);
1001 static connman_bool_t get_reconnect_state(struct connman_service *service)
1003 struct connman_device *device;
1005 if (service->network == NULL)
1008 device = connman_network_get_device(service->network);
1012 return __connman_device_get_reconnect(device);
1015 static DBusMessage *connect_service(DBusConnection *conn,
1016 DBusMessage *msg, void *user_data)
1018 struct connman_service *service = user_data;
1019 GSequenceIter *iter;
1022 DBG("service %p", service);
1024 if (service->pending != NULL)
1025 return __connman_error_in_progress(msg);
1027 iter = g_sequence_get_begin_iter(service_list);
1029 while (g_sequence_iter_is_end(iter) == FALSE) {
1030 struct connman_service *temp = g_sequence_get(iter);
1032 if (service->type == temp->type &&
1033 is_connecting(temp) == TRUE)
1034 return __connman_error_in_progress(msg);
1036 iter = g_sequence_iter_next(iter);
1039 service->ignore = FALSE;
1041 service->userconnect = TRUE;
1043 service->pending = dbus_message_ref(msg);
1045 set_reconnect_state(service, FALSE);
1047 err = __connman_service_connect(service);
1049 if (err == -ENOKEY) {
1050 if (__connman_agent_request_passphrase(service,
1055 if (err != -EINPROGRESS) {
1056 dbus_message_unref(service->pending);
1057 service->pending = NULL;
1059 return __connman_error_failed(msg, -err);
1065 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1068 static DBusMessage *disconnect_service(DBusConnection *conn,
1069 DBusMessage *msg, void *user_data)
1071 struct connman_service *service = user_data;
1074 DBG("service %p", service);
1076 reply_pending(service, ECONNABORTED);
1078 service->ignore = TRUE;
1080 set_reconnect_state(service, FALSE);
1082 err = __connman_service_disconnect(service);
1084 if (err != -EINPROGRESS)
1085 return __connman_error_failed(msg, -err);
1090 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1093 static DBusMessage *remove_service(DBusConnection *conn,
1094 DBusMessage *msg, void *user_data)
1096 struct connman_service *service = user_data;
1098 DBG("service %p", service);
1100 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
1101 return __connman_error_not_supported(msg);
1103 if (service->favorite == FALSE &&
1104 service->state != CONNMAN_SERVICE_STATE_FAILURE)
1105 return __connman_error_not_supported(msg);
1107 if (service->network != NULL) {
1108 set_reconnect_state(service, FALSE);
1110 __connman_network_disconnect(service->network);
1113 g_free(service->passphrase);
1114 service->passphrase = NULL;
1116 passphrase_changed(service);
1118 g_free(service->apn);
1119 service->apn = NULL;
1121 g_free(service->username);
1122 service->username = NULL;
1124 g_free(service->password);
1125 service->password = NULL;
1127 apn_changed(service);
1131 __connman_service_set_favorite(service, FALSE);
1132 __connman_storage_save_service(service);
1134 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1137 static DBusMessage *move_service(DBusConnection *conn,
1138 DBusMessage *msg, void *user_data,
1141 struct connman_service *service = user_data;
1142 struct connman_service *target;
1144 GSequenceIter *src, *dst;
1146 DBG("service %p", service);
1148 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
1151 if (service->favorite == FALSE)
1152 return __connman_error_not_supported(msg);
1154 target = find_service(path);
1155 if (target == NULL || target->favorite == FALSE || target == service)
1156 return __connman_error_invalid_service(msg);
1158 DBG("target %s", target->identifier);
1160 if (target->state != service->state)
1161 return __connman_error_invalid_service(msg);
1163 g_get_current_time(&service->modified);
1164 __connman_storage_save_service(service);
1166 src = g_hash_table_lookup(service_hash, service->identifier);
1167 dst = g_hash_table_lookup(service_hash, target->identifier);
1169 before ? g_sequence_move(src, dst) : g_sequence_move(dst, src);
1171 __connman_profile_changed(FALSE);
1173 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1176 static DBusMessage *move_before(DBusConnection *conn,
1177 DBusMessage *msg, void *user_data)
1179 return move_service(conn, msg, user_data, TRUE);
1182 static DBusMessage *move_after(DBusConnection *conn,
1183 DBusMessage *msg, void *user_data)
1185 return move_service(conn, msg, user_data, FALSE);
1188 static GDBusMethodTable service_methods[] = {
1189 { "GetProperties", "", "a{sv}", get_properties },
1190 { "SetProperty", "sv", "", set_property },
1191 { "ClearProperty", "s", "", clear_property },
1192 { "Connect", "", "", connect_service,
1193 G_DBUS_METHOD_FLAG_ASYNC },
1194 { "Disconnect", "", "", disconnect_service },
1195 { "Remove", "", "", remove_service },
1196 { "MoveBefore", "o", "", move_before },
1197 { "MoveAfter", "o", "", move_after },
1201 static GDBusSignalTable service_signals[] = {
1202 { "PropertyChanged", "sv" },
1206 static void service_free(gpointer user_data)
1208 struct connman_service *service = user_data;
1209 char *path = service->path;
1211 DBG("service %p", service);
1213 reply_pending(service, ENOENT);
1215 g_hash_table_remove(service_hash, service->identifier);
1217 service->path = NULL;
1220 __connman_profile_changed(FALSE);
1222 g_dbus_unregister_interface(connection, path,
1223 CONNMAN_SERVICE_INTERFACE);
1227 if (service->network != NULL)
1228 connman_network_unref(service->network);
1230 if (service->ipconfig != NULL) {
1231 connman_ipconfig_unref(service->ipconfig);
1232 service->ipconfig = NULL;
1235 if (service->location != NULL)
1236 connman_location_unref(service->location);
1238 g_free(service->mcc);
1239 g_free(service->mnc);
1240 g_free(service->apn);
1241 g_free(service->username);
1242 g_free(service->password);
1243 g_free(service->profile);
1244 g_free(service->name);
1245 g_free(service->passphrase);
1246 g_free(service->identifier);
1247 g_free(service->eap);
1248 g_free(service->identity);
1249 g_free(service->ca_cert_file);
1250 g_free(service->client_cert_file);
1251 g_free(service->private_key_file);
1252 g_free(service->private_key_passphrase);
1253 g_free(service->phase2);
1258 * __connman_service_put:
1259 * @service: service structure
1261 * Release service if no longer needed
1263 void __connman_service_put(struct connman_service *service)
1265 DBG("service %p", service);
1267 if (g_atomic_int_dec_and_test(&service->refcount) == TRUE) {
1268 GSequenceIter *iter;
1270 iter = g_hash_table_lookup(service_hash, service->identifier);
1272 reply_pending(service, ECONNABORTED);
1274 __connman_service_disconnect(service);
1276 g_sequence_remove(iter);
1278 service_free(service);
1282 static void __connman_service_initialize(struct connman_service *service)
1284 DBG("service %p", service);
1286 service->refcount = 1;
1288 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
1289 service->mode = CONNMAN_SERVICE_MODE_UNKNOWN;
1290 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
1291 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
1293 service->favorite = FALSE;
1294 service->immutable = FALSE;
1295 service->hidden = FALSE;
1297 service->ignore = FALSE;
1299 service->userconnect = FALSE;
1305 * connman_service_create:
1307 * Allocate a new service.
1309 * Returns: a newly-allocated #connman_service structure
1311 struct connman_service *connman_service_create(void)
1313 struct connman_service *service;
1315 service = g_try_new0(struct connman_service, 1);
1316 if (service == NULL)
1319 DBG("service %p", service);
1321 __connman_service_initialize(service);
1323 service->location = __connman_location_create(service);
1328 struct connman_location *__connman_service_get_location(struct connman_service *service)
1330 return service->location;
1334 * connman_service_ref:
1335 * @service: service structure
1337 * Increase reference counter of service
1339 struct connman_service *connman_service_ref(struct connman_service *service)
1341 g_atomic_int_inc(&service->refcount);
1347 * connman_service_unref:
1348 * @service: service structure
1350 * Decrease reference counter of service
1352 void connman_service_unref(struct connman_service *service)
1354 __connman_service_put(service);
1357 static gint service_compare(gconstpointer a, gconstpointer b,
1360 struct connman_service *service_a = (void *) a;
1361 struct connman_service *service_b = (void *) b;
1363 if (service_a->state != service_b->state) {
1364 if (service_a->state == CONNMAN_SERVICE_STATE_READY)
1366 if (service_b->state == CONNMAN_SERVICE_STATE_READY)
1370 if (service_a->order > service_b->order)
1373 if (service_a->order < service_b->order)
1376 if (service_a->favorite == TRUE && service_b->favorite == FALSE)
1379 if (service_a->favorite == FALSE && service_b->favorite == TRUE)
1382 if (service_a->type != service_b->type) {
1383 switch (service_a->type) {
1384 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1385 case CONNMAN_SERVICE_TYPE_SYSTEM:
1386 case CONNMAN_SERVICE_TYPE_ETHERNET:
1387 case CONNMAN_SERVICE_TYPE_GPS:
1388 case CONNMAN_SERVICE_TYPE_VPN:
1390 case CONNMAN_SERVICE_TYPE_WIFI:
1392 case CONNMAN_SERVICE_TYPE_WIMAX:
1393 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1394 case CONNMAN_SERVICE_TYPE_CELLULAR:
1399 return (gint) service_b->strength - (gint) service_a->strength;
1403 * connman_service_get_type:
1404 * @service: service structure
1406 * Get the type of service
1408 enum connman_service_type connman_service_get_type(struct connman_service *service)
1410 if (service == NULL)
1411 return CONNMAN_SERVICE_TYPE_UNKNOWN;
1413 return service->type;
1417 * connman_service_get_interface:
1418 * @service: service structure
1420 * Get network interface of service
1422 char *connman_service_get_interface(struct connman_service *service)
1426 if (service == NULL)
1429 if (service->network == NULL)
1432 index = connman_network_get_index(service->network);
1434 return connman_inet_ifname(index);
1438 * connman_service_get_network:
1439 * @service: service structure
1441 * Get the service network
1443 struct connman_network *
1444 __connman_service_get_network(struct connman_service *service)
1446 if (service == NULL)
1449 return service->network;
1452 struct connman_ipconfig *
1453 __connman_service_get_ipconfig(struct connman_service *service)
1455 if (service == NULL)
1458 return service->ipconfig;
1462 * __connman_service_set_favorite:
1463 * @service: service structure
1464 * @favorite: favorite value
1466 * Change the favorite setting of service
1468 int __connman_service_set_favorite(struct connman_service *service,
1469 connman_bool_t favorite)
1471 GSequenceIter *iter;
1473 iter = g_hash_table_lookup(service_hash, service->identifier);
1477 if (service->favorite == favorite)
1480 service->favorite = favorite;
1482 favorite_changed(service);
1484 g_sequence_sort_changed(iter, service_compare, NULL);
1486 __connman_profile_changed(FALSE);
1491 int __connman_service_set_immutable(struct connman_service *service,
1492 connman_bool_t immutable)
1494 service->immutable = immutable;
1496 immutable_changed(service);
1501 void __connman_service_set_string(struct connman_service *service,
1502 const char *key, const char *value)
1504 if (g_str_equal(key, "EAP") == TRUE) {
1505 g_free(service->eap);
1506 service->eap = g_strdup(value);
1507 } else if (g_str_equal(key, "Identity") == TRUE) {
1508 g_free(service->identity);
1509 service->identity = g_strdup(value);
1510 } else if (g_str_equal(key, "CACertFile") == TRUE) {
1511 g_free(service->ca_cert_file);
1512 service->ca_cert_file = g_strdup(value);
1513 } else if (g_str_equal(key, "ClientCertFile") == TRUE) {
1514 g_free(service->client_cert_file);
1515 service->client_cert_file = g_strdup(value);
1516 } else if (g_str_equal(key, "PrivateKeyFile") == TRUE) {
1517 g_free(service->private_key_file);
1518 service->private_key_file = g_strdup(value);
1519 } else if (g_str_equal(key, "PrivateKeyPassphrase") == TRUE) {
1520 g_free(service->private_key_passphrase);
1521 service->private_key_passphrase = g_strdup(value);
1522 } else if (g_str_equal(key, "Phase2") == TRUE) {
1523 g_free(service->phase2);
1524 service->phase2 = g_strdup(value);
1525 } else if (g_str_equal(key, "Passphrase") == TRUE) {
1526 g_free(service->passphrase);
1527 service->passphrase = g_strdup(value);
1531 int __connman_service_indicate_state(struct connman_service *service,
1532 enum connman_service_state state)
1534 GSequenceIter *iter;
1536 DBG("service %p state %d", service, state);
1538 if (service == NULL)
1541 if (service->state == state)
1544 if (service->state == CONNMAN_SERVICE_STATE_FAILURE &&
1545 state == CONNMAN_SERVICE_STATE_IDLE)
1548 if (service->state == CONNMAN_SERVICE_STATE_IDLE &&
1549 state == CONNMAN_SERVICE_STATE_DISCONNECT)
1552 if (state == CONNMAN_SERVICE_STATE_IDLE &&
1553 service->state != CONNMAN_SERVICE_STATE_DISCONNECT) {
1554 service->state = CONNMAN_SERVICE_STATE_DISCONNECT;
1555 state_changed(service);
1557 reply_pending(service, ECONNABORTED);
1559 __connman_service_disconnect(service);
1562 if (state == CONNMAN_SERVICE_STATE_CONFIGURATION)
1563 __connman_ipconfig_enable(service->ipconfig);
1565 service->state = state;
1566 state_changed(service);
1568 if (state == CONNMAN_SERVICE_STATE_IDLE) {
1569 connman_bool_t reconnect;
1571 reconnect = get_reconnect_state(service);
1572 if (reconnect == TRUE)
1573 __connman_service_auto_connect();
1576 if (state == CONNMAN_SERVICE_STATE_READY) {
1577 set_reconnect_state(service, TRUE);
1579 __connman_service_set_favorite(service, TRUE);
1581 reply_pending(service, 0);
1583 service->userconnect = FALSE;
1585 g_get_current_time(&service->modified);
1586 __connman_storage_save_service(service);
1588 __connman_notifier_connect(service->type);
1592 } else if (state == CONNMAN_SERVICE_STATE_DISCONNECT) {
1593 __connman_location_finish(service);
1597 __connman_notifier_disconnect(service->type);
1600 if (state == CONNMAN_SERVICE_STATE_FAILURE) {
1601 reply_pending(service, EIO);
1603 if (service->userconnect == FALSE)
1604 __connman_service_auto_connect();
1606 g_get_current_time(&service->modified);
1607 __connman_storage_save_service(service);
1609 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
1611 iter = g_hash_table_lookup(service_hash, service->identifier);
1613 g_sequence_sort_changed(iter, service_compare, NULL);
1615 __connman_profile_changed(FALSE);
1617 if (service->state == CONNMAN_SERVICE_STATE_IDLE ||
1618 service->state == CONNMAN_SERVICE_STATE_FAILURE)
1619 __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
1624 int __connman_service_indicate_error(struct connman_service *service,
1625 enum connman_service_error error)
1627 DBG("service %p error %d", service, error);
1629 if (service == NULL)
1632 service->error = error;
1634 return __connman_service_indicate_state(service,
1635 CONNMAN_SERVICE_STATE_FAILURE);
1638 int __connman_service_indicate_default(struct connman_service *service)
1640 DBG("service %p", service);
1644 __connman_location_detect(service);
1649 static connman_bool_t prepare_network(struct connman_service *service)
1651 enum connman_network_type type;
1652 unsigned int ssid_len;
1654 type = connman_network_get_type(service->network);
1657 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1658 case CONNMAN_NETWORK_TYPE_VENDOR:
1660 case CONNMAN_NETWORK_TYPE_WIFI:
1661 if (connman_network_get_blob(service->network, "WiFi.SSID",
1665 connman_network_set_string(service->network,
1666 "WiFi.Passphrase", service->passphrase);
1668 case CONNMAN_NETWORK_TYPE_ETHERNET:
1669 case CONNMAN_NETWORK_TYPE_WIMAX:
1670 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1671 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1673 case CONNMAN_NETWORK_TYPE_CELLULAR:
1674 connman_network_set_string(service->network,
1675 "Cellular.APN", service->apn);
1677 connman_network_set_string(service->network,
1678 "Cellular.Username", service->username);
1679 connman_network_set_string(service->network,
1680 "Cellular.Password", service->password);
1687 static void prepare_8021x(struct connman_service *service)
1689 if (service->eap != NULL)
1690 connman_network_set_string(service->network, "WiFi.EAP",
1693 if (service->identity != NULL)
1694 connman_network_set_string(service->network, "WiFi.Identity",
1697 if (service->ca_cert_file != NULL)
1698 connman_network_set_string(service->network, "WiFi.CACertFile",
1699 service->ca_cert_file);
1701 if (service->client_cert_file != NULL)
1702 connman_network_set_string(service->network,
1703 "WiFi.ClientCertFile",
1704 service->client_cert_file);
1706 if (service->private_key_file != NULL)
1707 connman_network_set_string(service->network,
1708 "WiFi.PrivateKeyFile",
1709 service->private_key_file);
1711 if (service->private_key_passphrase != NULL)
1712 connman_network_set_string(service->network,
1713 "WiFi.PrivateKeyPassphrase",
1714 service->private_key_passphrase);
1716 if (service->phase2 != NULL)
1717 connman_network_set_string(service->network, "WiFi.Phase2",
1721 int __connman_service_connect(struct connman_service *service)
1725 DBG("service %p", service);
1727 if (service->state == CONNMAN_SERVICE_STATE_READY)
1730 if (is_connecting(service) == TRUE)
1733 switch (service->type) {
1734 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1735 case CONNMAN_SERVICE_TYPE_SYSTEM:
1736 case CONNMAN_SERVICE_TYPE_GPS:
1737 case CONNMAN_SERVICE_TYPE_VPN:
1739 case CONNMAN_SERVICE_TYPE_ETHERNET:
1740 case CONNMAN_SERVICE_TYPE_WIMAX:
1741 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1743 case CONNMAN_SERVICE_TYPE_CELLULAR:
1744 if (service->apn == NULL)
1747 case CONNMAN_SERVICE_TYPE_WIFI:
1748 switch (service->security) {
1749 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1750 case CONNMAN_SERVICE_SECURITY_NONE:
1752 case CONNMAN_SERVICE_SECURITY_WEP:
1753 case CONNMAN_SERVICE_SECURITY_PSK:
1754 case CONNMAN_SERVICE_SECURITY_WPA:
1755 case CONNMAN_SERVICE_SECURITY_RSN:
1756 if (service->passphrase == NULL)
1759 case CONNMAN_SERVICE_SECURITY_8021X:
1765 if (service->network != NULL) {
1766 if (prepare_network(service) == FALSE)
1769 switch (service->security) {
1770 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1771 case CONNMAN_SERVICE_SECURITY_NONE:
1772 case CONNMAN_SERVICE_SECURITY_WEP:
1773 case CONNMAN_SERVICE_SECURITY_PSK:
1774 case CONNMAN_SERVICE_SECURITY_WPA:
1775 case CONNMAN_SERVICE_SECURITY_RSN:
1777 case CONNMAN_SERVICE_SECURITY_8021X:
1778 prepare_8021x(service);
1782 __connman_ipconfig_enable(service->ipconfig);
1784 err = __connman_network_connect(service->network);
1789 if (err != -EINPROGRESS) {
1790 __connman_ipconfig_disable(service->ipconfig);
1794 service->timeout = g_timeout_add_seconds(CONNECT_TIMEOUT,
1795 connect_timeout, service);
1797 return -EINPROGRESS;
1803 int __connman_service_disconnect(struct connman_service *service)
1807 DBG("service %p", service);
1809 if (service->network != NULL) {
1810 err = __connman_network_disconnect(service->network);
1814 __connman_ipconfig_clear_address(service->ipconfig);
1816 __connman_ipconfig_disable(service->ipconfig);
1819 if (err != -EINPROGRESS)
1822 return -EINPROGRESS;
1829 * __connman_service_lookup:
1830 * @identifier: service identifier
1832 * Look up a service by identifier (reference count will not be increased)
1834 static struct connman_service *__connman_service_lookup(const char *identifier)
1836 GSequenceIter *iter;
1838 iter = g_hash_table_lookup(service_hash, identifier);
1840 return g_sequence_get(iter);
1845 static struct connman_network *create_hidden_wifi(struct connman_device *device,
1846 const char *ssid, const char *mode, const char *security)
1848 struct connman_network *network;
1851 unsigned int i, ssid_len;
1853 ssid_len = strlen(ssid);
1857 network = connman_network_create(NULL, CONNMAN_NETWORK_TYPE_WIFI);
1858 if (network == NULL)
1861 connman_network_set_blob(network, "WiFi.SSID",
1862 (unsigned char *) ssid, ssid_len);
1864 connman_network_set_string(network, "WiFi.Mode", mode);
1865 connman_network_set_string(network, "WiFi.Security", security);
1867 name = g_try_malloc0(ssid_len + 1);
1869 connman_network_unref(network);
1873 for (i = 0; i < ssid_len; i++) {
1874 if (g_ascii_isprint(ssid[i]))
1880 connman_network_set_name(network, name);
1884 index = connman_device_get_index(device);
1885 connman_network_set_index(network, index);
1887 connman_network_set_protocol(network, CONNMAN_NETWORK_PROTOCOL_IP);
1889 if (connman_device_add_network(device, network) < 0) {
1890 connman_network_unref(network);
1894 connman_network_set_available(network, TRUE);
1899 int __connman_service_create_and_connect(DBusMessage *msg)
1901 struct connman_service *service;
1902 struct connman_network *network;
1903 struct connman_device *device;
1904 DBusMessageIter iter, array;
1905 const char *mode = "managed", *security = "none";
1906 const char *type = NULL, *ssid = NULL, *passphrase = NULL;
1907 unsigned int ssid_len = 0;
1910 gboolean created = FALSE;
1913 dbus_message_iter_init(msg, &iter);
1914 dbus_message_iter_recurse(&iter, &array);
1916 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
1917 DBusMessageIter entry, value;
1920 dbus_message_iter_recurse(&array, &entry);
1921 dbus_message_iter_get_basic(&entry, &key);
1923 dbus_message_iter_next(&entry);
1924 dbus_message_iter_recurse(&entry, &value);
1926 switch (dbus_message_iter_get_arg_type(&value)) {
1927 case DBUS_TYPE_STRING:
1928 if (g_str_equal(key, "Type") == TRUE)
1929 dbus_message_iter_get_basic(&value, &type);
1930 else if (g_str_equal(key, "WiFi.Mode") == TRUE ||
1931 g_str_equal(key, "Mode") == TRUE)
1932 dbus_message_iter_get_basic(&value, &mode);
1933 else if (g_str_equal(key, "WiFi.Security") == TRUE ||
1934 g_str_equal(key, "Security") == TRUE)
1935 dbus_message_iter_get_basic(&value, &security);
1936 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE ||
1937 g_str_equal(key, "Passphrase") == TRUE)
1938 dbus_message_iter_get_basic(&value, &passphrase);
1939 else if (g_str_equal(key, "WiFi.SSID") == TRUE ||
1940 g_str_equal(key, "SSID") == TRUE)
1941 dbus_message_iter_get_basic(&value, &ssid);
1944 dbus_message_iter_next(&array);
1950 if (g_strcmp0(type, "wifi") != 0 || g_strcmp0(mode, "managed") != 0)
1956 ssid_len = strlen(ssid);
1960 if (g_strcmp0(security, "none") != 0 &&
1961 g_strcmp0(security, "wep") != 0 &&
1962 g_strcmp0(security, "psk") != 0 &&
1963 g_strcmp0(security, "wpa") != 0 &&
1964 g_strcmp0(security, "rsn") != 0 &&
1965 g_strcmp0(security, "ieee8021x") != 0)
1968 device = __connman_element_find_device(CONNMAN_DEVICE_TYPE_WIFI);
1972 ident = __connman_device_get_ident(device);
1976 group = connman_wifi_build_group_name((unsigned char *) ssid,
1977 ssid_len, mode, security);
1981 name = g_strdup_printf("%s_%s_%s", type, ident, group);
1983 service = __connman_service_lookup(name);
1985 if (service != NULL)
1988 network = create_hidden_wifi(device, ssid, mode, security);
1989 if (network != NULL) {
1990 connman_network_set_group(network, group);
1994 service = __connman_service_lookup(name);
2000 if (service == NULL) {
2005 set_reconnect_state(service, FALSE);
2007 __connman_device_disconnect(device);
2009 if (passphrase != NULL) {
2010 g_free(service->passphrase);
2011 service->passphrase = g_strdup(passphrase);
2014 service->userconnect = TRUE;
2016 err = __connman_service_connect(service);
2017 if (err < 0 && err != -EINPROGRESS)
2020 g_dbus_send_reply(connection, msg,
2021 DBUS_TYPE_OBJECT_PATH, &service->path,
2027 if (service != NULL && created == TRUE) {
2028 struct connman_network *network = service->network;
2030 if (network != NULL) {
2031 connman_network_set_available(network, FALSE);
2032 __connman_device_cleanup_networks(device);
2034 __connman_service_put(service);
2041 * __connman_service_get:
2042 * @identifier: service identifier
2044 * Look up a service by identifier or create a new one if not found
2046 static struct connman_service *__connman_service_get(const char *identifier)
2048 struct connman_service *service;
2049 GSequenceIter *iter;
2051 iter = g_hash_table_lookup(service_hash, identifier);
2053 service = g_sequence_get(iter);
2054 if (service != NULL)
2055 g_atomic_int_inc(&service->refcount);
2059 service = connman_service_create();
2060 if (service == NULL)
2063 DBG("service %p", service);
2065 service->identifier = g_strdup(identifier);
2067 service->profile = g_strdup(__connman_profile_active_ident());
2069 iter = g_sequence_insert_sorted(service_list, service,
2070 service_compare, NULL);
2072 g_hash_table_insert(service_hash, service->identifier, iter);
2077 static int service_register(struct connman_service *service)
2079 const char *path = __connman_profile_active_path();
2080 GSequenceIter *iter;
2082 DBG("service %p", service);
2084 if (service->path != NULL)
2087 service->path = g_strdup_printf("%s/%s", path, service->identifier);
2089 DBG("path %s", service->path);
2091 __connman_config_provision_service(service);
2093 __connman_storage_load_service(service);
2095 g_dbus_register_interface(connection, service->path,
2096 CONNMAN_SERVICE_INTERFACE,
2097 service_methods, service_signals,
2098 NULL, service, NULL);
2100 iter = g_hash_table_lookup(service_hash, service->identifier);
2102 g_sequence_sort_changed(iter, service_compare, NULL);
2104 __connman_profile_changed(TRUE);
2109 static void service_up(struct connman_ipconfig *ipconfig)
2111 connman_info("%s up", connman_ipconfig_get_ifname(ipconfig));
2114 static void service_down(struct connman_ipconfig *ipconfig)
2116 connman_info("%s down", connman_ipconfig_get_ifname(ipconfig));
2119 static void service_lower_up(struct connman_ipconfig *ipconfig)
2121 connman_info("%s lower up", connman_ipconfig_get_ifname(ipconfig));
2124 static void service_lower_down(struct connman_ipconfig *ipconfig)
2126 connman_info("%s lower down", connman_ipconfig_get_ifname(ipconfig));
2129 static void service_ip_bound(struct connman_ipconfig *ipconfig)
2131 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
2133 connman_info("%s ip bound", connman_ipconfig_get_ifname(ipconfig));
2135 settings_changed(service);
2138 static void service_ip_release(struct connman_ipconfig *ipconfig)
2140 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
2142 connman_info("%s ip release", connman_ipconfig_get_ifname(ipconfig));
2144 settings_changed(service);
2147 static const struct connman_ipconfig_ops service_ops = {
2149 .down = service_down,
2150 .lower_up = service_lower_up,
2151 .lower_down = service_lower_down,
2152 .ip_bound = service_ip_bound,
2153 .ip_release = service_ip_release,
2156 static void setup_ipconfig(struct connman_service *service, int index)
2161 service->ipconfig = connman_ipconfig_create(index);
2162 if (service->ipconfig == NULL)
2165 connman_ipconfig_set_method(service->ipconfig,
2166 CONNMAN_IPCONFIG_METHOD_DHCP);
2168 connman_ipconfig_set_data(service->ipconfig, service);
2170 connman_ipconfig_set_ops(service->ipconfig, &service_ops);
2173 void __connman_service_create_ipconfig(struct connman_service *service,
2176 if (service->ipconfig != NULL)
2179 setup_ipconfig(service, index);
2183 * __connman_service_lookup_from_network:
2184 * @network: network structure
2186 * Look up a service by network (reference count will not be increased)
2188 struct connman_service *__connman_service_lookup_from_network(struct connman_network *network)
2190 struct connman_service *service;
2191 const char *ident, *group;
2194 DBG("network %p", network);
2196 ident = __connman_network_get_ident(network);
2200 group = connman_network_get_group(network);
2204 name = g_strdup_printf("%s_%s_%s",
2205 __connman_network_get_type(network), ident, group);
2206 service = __connman_service_lookup(name);
2212 const char *__connman_service_get_path(struct connman_service *service)
2214 return service->path;
2217 unsigned int __connman_service_get_order(struct connman_service *service)
2219 GSequenceIter *iter;
2221 if (service == NULL)
2224 if (service->favorite == FALSE) {
2229 iter = g_hash_table_lookup(service_hash, service->identifier);
2231 if (g_sequence_iter_get_position(iter) == 0)
2238 return service->order;
2241 static enum connman_service_type convert_network_type(struct connman_network *network)
2243 enum connman_network_type type = connman_network_get_type(network);
2246 case CONNMAN_NETWORK_TYPE_UNKNOWN:
2247 case CONNMAN_NETWORK_TYPE_VENDOR:
2249 case CONNMAN_NETWORK_TYPE_ETHERNET:
2250 return CONNMAN_SERVICE_TYPE_ETHERNET;
2251 case CONNMAN_NETWORK_TYPE_WIFI:
2252 return CONNMAN_SERVICE_TYPE_WIFI;
2253 case CONNMAN_NETWORK_TYPE_WIMAX:
2254 return CONNMAN_SERVICE_TYPE_WIMAX;
2255 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
2256 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
2257 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
2258 case CONNMAN_NETWORK_TYPE_CELLULAR:
2259 return CONNMAN_SERVICE_TYPE_CELLULAR;
2262 return CONNMAN_SERVICE_TYPE_UNKNOWN;
2265 static enum connman_service_mode convert_wifi_mode(const char *mode)
2268 return CONNMAN_SERVICE_MODE_UNKNOWN;
2269 else if (g_str_equal(mode, "managed") == TRUE)
2270 return CONNMAN_SERVICE_MODE_MANAGED;
2271 else if (g_str_equal(mode, "adhoc") == TRUE)
2272 return CONNMAN_SERVICE_MODE_ADHOC;
2274 return CONNMAN_SERVICE_MODE_UNKNOWN;
2277 static enum connman_service_security convert_wifi_security(const char *security)
2279 if (security == NULL)
2280 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
2281 else if (g_str_equal(security, "none") == TRUE)
2282 return CONNMAN_SERVICE_SECURITY_NONE;
2283 else if (g_str_equal(security, "wep") == TRUE)
2284 return CONNMAN_SERVICE_SECURITY_WEP;
2285 else if (g_str_equal(security, "psk") == TRUE)
2286 return CONNMAN_SERVICE_SECURITY_PSK;
2287 else if (g_str_equal(security, "ieee8021x") == TRUE)
2288 return CONNMAN_SERVICE_SECURITY_8021X;
2289 else if (g_str_equal(security, "wpa") == TRUE)
2290 return CONNMAN_SERVICE_SECURITY_WPA;
2291 else if (g_str_equal(security, "rsn") == TRUE)
2292 return CONNMAN_SERVICE_SECURITY_RSN;
2294 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
2297 static enum connman_service_mode convert_cellular_mode(connman_uint8_t mode)
2302 return CONNMAN_SERVICE_MODE_GPRS;
2304 return CONNMAN_SERVICE_MODE_EDGE;
2309 return CONNMAN_SERVICE_MODE_UMTS;
2312 return CONNMAN_SERVICE_MODE_UNKNOWN;
2315 static void update_from_network(struct connman_service *service,
2316 struct connman_network *network)
2318 connman_uint8_t strength = service->strength;
2319 GSequenceIter *iter;
2322 DBG("service %p network %p", service, network);
2324 if (service->state == CONNMAN_SERVICE_STATE_READY)
2327 if (is_connecting(service) == TRUE)
2330 str = connman_network_get_string(network, "Name");
2332 g_free(service->name);
2333 service->name = g_strdup(str);
2334 service->hidden = FALSE;
2336 g_free(service->name);
2337 service->name = NULL;
2338 service->hidden = TRUE;
2341 service->strength = connman_network_get_uint8(network, "Strength");
2342 service->roaming = connman_network_get_bool(network, "Roaming");
2344 if (service->strength == 0) {
2346 * Filter out 0-values; it's unclear what they mean
2347 * and they cause anomalous sorting of the priority list.
2349 service->strength = strength;
2352 str = connman_network_get_string(network, "WiFi.Mode");
2353 service->mode = convert_wifi_mode(str);
2355 str = connman_network_get_string(network, "WiFi.Security");
2356 service->security = convert_wifi_security(str);
2358 str = connman_network_get_string(network, "Cellular.MCC");
2359 g_free(service->mcc);
2360 service->mcc = g_strdup(str);
2362 str = connman_network_get_string(network, "Cellular.MNC");
2363 g_free(service->mnc);
2364 service->mnc = g_strdup(str);
2366 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
2367 connman_uint8_t value = connman_network_get_uint8(network,
2370 service->mode = convert_cellular_mode(value);
2373 if (service->strength > strength && service->network != NULL) {
2374 connman_network_unref(service->network);
2375 service->network = connman_network_ref(network);
2377 strength_changed(service);
2380 if (service->network == NULL)
2381 service->network = connman_network_ref(network);
2383 iter = g_hash_table_lookup(service_hash, service->identifier);
2385 g_sequence_sort_changed(iter, service_compare, NULL);
2389 * __connman_service_create_from_network:
2390 * @network: network structure
2392 * Look up service by network and if not found, create one
2394 struct connman_service *__connman_service_create_from_network(struct connman_network *network)
2396 struct connman_service *service;
2397 const char *ident, *group;
2400 DBG("network %p", network);
2402 ident = __connman_network_get_ident(network);
2406 group = connman_network_get_group(network);
2410 name = g_strdup_printf("%s_%s_%s",
2411 __connman_network_get_type(network), ident, group);
2412 service = __connman_service_get(name);
2415 if (service == NULL)
2418 if (__connman_network_get_weakness(network) == TRUE)
2421 if (service->path != NULL) {
2422 update_from_network(service, network);
2423 __connman_profile_changed(TRUE);
2427 service->type = convert_network_type(network);
2429 switch (service->type) {
2430 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2431 case CONNMAN_SERVICE_TYPE_SYSTEM:
2432 case CONNMAN_SERVICE_TYPE_ETHERNET:
2433 case CONNMAN_SERVICE_TYPE_WIMAX:
2434 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2435 case CONNMAN_SERVICE_TYPE_GPS:
2436 case CONNMAN_SERVICE_TYPE_VPN:
2437 service->autoconnect = FALSE;
2439 case CONNMAN_SERVICE_TYPE_WIFI:
2440 case CONNMAN_SERVICE_TYPE_CELLULAR:
2441 service->autoconnect = TRUE;
2445 service->state = CONNMAN_SERVICE_STATE_IDLE;
2447 update_from_network(service, network);
2449 setup_ipconfig(service, connman_network_get_index(network));
2451 service_register(service);
2453 if (service->favorite == TRUE)
2454 __connman_service_auto_connect();
2459 void __connman_service_update_from_network(struct connman_network *network)
2461 struct connman_service *service;
2462 enum connman_service_mode mode;
2463 connman_uint8_t strength, value;
2464 connman_bool_t roaming;
2465 GSequenceIter *iter;
2467 DBG("network %p", network);
2469 service = __connman_service_lookup_from_network(network);
2470 if (service == NULL)
2473 if (service->network == NULL)
2476 strength = connman_network_get_uint8(service->network, "Strength");
2477 if (strength == service->strength)
2480 service->strength = strength;
2482 strength_changed(service);
2485 roaming = connman_network_get_bool(service->network, "Roaming");
2486 if (roaming == service->roaming)
2489 service->roaming = roaming;
2491 roaming_changed(service);
2493 iter = g_hash_table_lookup(service_hash, service->identifier);
2495 g_sequence_sort_changed(iter, service_compare, NULL);
2498 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
2501 value = connman_network_get_uint8(service->network, "Cellular.Mode");
2502 mode = convert_cellular_mode(value);
2504 if (mode == service->mode)
2507 service->mode = mode;
2509 mode_changed(service);
2512 void __connman_service_remove_from_network(struct connman_network *network)
2514 struct connman_service *service;
2516 DBG("network %p", network);
2518 service = __connman_service_lookup_from_network(network);
2519 if (service == NULL)
2522 __connman_service_put(service);
2525 static int service_load(struct connman_service *service)
2527 const char *ident = service->profile;
2529 GError *error = NULL;
2530 gchar *pathname, *data = NULL;
2533 connman_bool_t autoconnect;
2534 unsigned int ssid_len;
2537 DBG("service %p", service);
2542 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
2543 if (pathname == NULL)
2546 keyfile = g_key_file_new();
2548 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
2555 if (g_key_file_load_from_data(keyfile, data, length,
2556 0, NULL) == FALSE) {
2563 switch (service->type) {
2564 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2565 case CONNMAN_SERVICE_TYPE_SYSTEM:
2566 case CONNMAN_SERVICE_TYPE_ETHERNET:
2567 case CONNMAN_SERVICE_TYPE_GPS:
2568 case CONNMAN_SERVICE_TYPE_VPN:
2570 case CONNMAN_SERVICE_TYPE_WIFI:
2571 if (service->name == NULL) {
2574 name = g_key_file_get_string(keyfile,
2575 service->identifier, "Name", NULL);
2577 g_free(service->name);
2578 service->name = name;
2581 if (service->network != NULL)
2582 connman_network_set_name(service->network,
2586 if (service->network &&
2587 connman_network_get_blob(service->network,
2588 "WiFi.SSID", &ssid_len) == NULL) {
2591 hex_ssid = g_key_file_get_string(keyfile,
2592 service->identifier,
2595 if (hex_ssid != NULL) {
2597 unsigned int i, j = 0, hex;
2598 size_t hex_ssid_len = strlen(hex_ssid);
2600 ssid = g_try_malloc0(hex_ssid_len / 2);
2607 for (i = 0; i < hex_ssid_len; i += 2) {
2608 sscanf(hex_ssid + i, "%02x", &hex);
2612 connman_network_set_blob(service->network,
2613 "WiFi.SSID", ssid, hex_ssid_len / 2);
2620 case CONNMAN_SERVICE_TYPE_WIMAX:
2621 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2622 case CONNMAN_SERVICE_TYPE_CELLULAR:
2623 service->apn = g_key_file_get_string(keyfile,
2624 service->identifier, "APN", NULL);
2626 service->username = g_key_file_get_string(keyfile,
2627 service->identifier, "Username", NULL);
2629 service->username = g_key_file_get_string(keyfile,
2630 service->identifier, "Password", NULL);
2632 service->favorite = g_key_file_get_boolean(keyfile,
2633 service->identifier, "Favorite", NULL);
2635 autoconnect = g_key_file_get_boolean(keyfile,
2636 service->identifier, "AutoConnect", &error);
2638 service->autoconnect = autoconnect;
2639 g_clear_error(&error);
2641 str = g_key_file_get_string(keyfile,
2642 service->identifier, "Failure", NULL);
2644 service->state = CONNMAN_SERVICE_STATE_FAILURE;
2645 service->error = string2error(str);
2650 str = g_key_file_get_string(keyfile,
2651 service->identifier, "Modified", NULL);
2653 g_time_val_from_iso8601(str, &service->modified);
2657 str = g_key_file_get_string(keyfile,
2658 service->identifier, "Passphrase", NULL);
2660 g_free(service->passphrase);
2661 service->passphrase = str;
2664 if (service->ipconfig != NULL)
2665 __connman_ipconfig_load(service->ipconfig, keyfile,
2666 service->identifier, "IPv4.");
2669 g_key_file_free(keyfile);
2674 static int service_save(struct connman_service *service)
2676 const char *ident = service->profile;
2678 gchar *pathname, *data = NULL;
2683 DBG("service %p", service);
2688 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
2689 if (pathname == NULL)
2692 keyfile = g_key_file_new();
2694 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
2698 if (g_key_file_load_from_data(keyfile, data, length,
2706 if (service->name != NULL)
2707 g_key_file_set_string(keyfile, service->identifier,
2708 "Name", service->name);
2710 switch (service->type) {
2711 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2712 case CONNMAN_SERVICE_TYPE_SYSTEM:
2713 case CONNMAN_SERVICE_TYPE_ETHERNET:
2714 case CONNMAN_SERVICE_TYPE_GPS:
2715 case CONNMAN_SERVICE_TYPE_VPN:
2717 case CONNMAN_SERVICE_TYPE_WIFI:
2718 if (service->network) {
2719 const unsigned char *ssid;
2720 unsigned int ssid_len = 0;
2722 ssid = connman_network_get_blob(service->network,
2723 "WiFi.SSID", &ssid_len);
2725 if (ssid != NULL && ssid_len > 0 && ssid[0] != '\0') {
2726 char *identifier = service->identifier;
2730 str = g_string_sized_new(ssid_len * 2);
2736 for (i = 0; i < ssid_len; i++)
2737 g_string_append_printf(str,
2740 g_key_file_set_string(keyfile, identifier,
2743 g_string_free(str, TRUE);
2748 case CONNMAN_SERVICE_TYPE_WIMAX:
2749 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2750 case CONNMAN_SERVICE_TYPE_CELLULAR:
2751 if (service->apn != NULL)
2752 g_key_file_set_string(keyfile, service->identifier,
2753 "APN", service->apn);
2755 if (service->username != NULL)
2756 g_key_file_set_string(keyfile, service->identifier,
2757 "Username", service->username);
2759 if (service->password != NULL)
2760 g_key_file_set_string(keyfile, service->identifier,
2761 "Password", service->password);
2763 g_key_file_set_boolean(keyfile, service->identifier,
2764 "Favorite", service->favorite);
2766 if (service->favorite == TRUE)
2767 g_key_file_set_boolean(keyfile, service->identifier,
2768 "AutoConnect", service->autoconnect);
2770 if (service->state == CONNMAN_SERVICE_STATE_FAILURE) {
2771 const char *failure = error2string(service->error);
2772 if (failure != NULL)
2773 g_key_file_set_string(keyfile,
2774 service->identifier,
2775 "Failure", failure);
2777 g_key_file_remove_key(keyfile, service->identifier,
2783 str = g_time_val_to_iso8601(&service->modified);
2785 g_key_file_set_string(keyfile, service->identifier,
2790 if (service->passphrase != NULL && strlen(service->passphrase) > 0)
2791 g_key_file_set_string(keyfile, service->identifier,
2792 "Passphrase", service->passphrase);
2794 g_key_file_remove_key(keyfile, service->identifier,
2795 "Passphrase", NULL);
2797 if (service->ipconfig != NULL)
2798 __connman_ipconfig_save(service->ipconfig, keyfile,
2799 service->identifier, "IPv4.");
2801 data = g_key_file_to_data(keyfile, &length, NULL);
2803 if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
2804 connman_error("Failed to store service information");
2809 g_key_file_free(keyfile);
2816 static struct connman_storage service_storage = {
2818 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
2819 .service_load = service_load,
2820 .service_save = service_save,
2823 int __connman_service_init(void)
2827 connection = connman_dbus_get_connection();
2829 if (connman_storage_register(&service_storage) < 0)
2830 connman_error("Failed to register service storage");
2832 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
2835 service_list = g_sequence_new(service_free);
2840 void __connman_service_cleanup(void)
2844 g_sequence_free(service_list);
2845 service_list = NULL;
2847 g_hash_table_destroy(service_hash);
2848 service_hash = NULL;
2850 connman_storage_unregister(&service_storage);
2852 dbus_connection_unref(connection);