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 __connman_location_detect(service);
1593 } else if (state == CONNMAN_SERVICE_STATE_DISCONNECT) {
1594 __connman_location_finish(service);
1598 __connman_notifier_disconnect(service->type);
1601 if (state == CONNMAN_SERVICE_STATE_FAILURE) {
1602 reply_pending(service, EIO);
1604 if (service->userconnect == FALSE)
1605 __connman_service_auto_connect();
1607 g_get_current_time(&service->modified);
1608 __connman_storage_save_service(service);
1610 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
1612 iter = g_hash_table_lookup(service_hash, service->identifier);
1614 g_sequence_sort_changed(iter, service_compare, NULL);
1616 __connman_profile_changed(FALSE);
1618 if (service->state == CONNMAN_SERVICE_STATE_IDLE ||
1619 service->state == CONNMAN_SERVICE_STATE_FAILURE)
1620 __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
1625 int __connman_service_indicate_error(struct connman_service *service,
1626 enum connman_service_error error)
1628 DBG("service %p error %d", service, error);
1630 if (service == NULL)
1633 service->error = error;
1635 return __connman_service_indicate_state(service,
1636 CONNMAN_SERVICE_STATE_FAILURE);
1639 int __connman_service_indicate_default(struct connman_service *service)
1641 DBG("service %p", service);
1648 static connman_bool_t prepare_network(struct connman_service *service)
1650 enum connman_network_type type;
1651 unsigned int ssid_len;
1653 type = connman_network_get_type(service->network);
1656 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1657 case CONNMAN_NETWORK_TYPE_VENDOR:
1659 case CONNMAN_NETWORK_TYPE_WIFI:
1660 if (connman_network_get_blob(service->network, "WiFi.SSID",
1664 connman_network_set_string(service->network,
1665 "WiFi.Passphrase", service->passphrase);
1667 case CONNMAN_NETWORK_TYPE_ETHERNET:
1668 case CONNMAN_NETWORK_TYPE_WIMAX:
1669 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1670 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1672 case CONNMAN_NETWORK_TYPE_CELLULAR:
1673 case CONNMAN_NETWORK_TYPE_MBM:
1674 case CONNMAN_NETWORK_TYPE_HSO:
1675 connman_network_set_string(service->network,
1676 "Cellular.APN", service->apn);
1678 connman_network_set_string(service->network,
1679 "Cellular.Username", service->username);
1680 connman_network_set_string(service->network,
1681 "Cellular.Password", service->password);
1688 static void prepare_8021x(struct connman_service *service)
1690 if (service->eap != NULL)
1691 connman_network_set_string(service->network, "WiFi.EAP",
1694 if (service->identity != NULL)
1695 connman_network_set_string(service->network, "WiFi.Identity",
1698 if (service->ca_cert_file != NULL)
1699 connman_network_set_string(service->network, "WiFi.CACertFile",
1700 service->ca_cert_file);
1702 if (service->client_cert_file != NULL)
1703 connman_network_set_string(service->network,
1704 "WiFi.ClientCertFile",
1705 service->client_cert_file);
1707 if (service->private_key_file != NULL)
1708 connman_network_set_string(service->network,
1709 "WiFi.PrivateKeyFile",
1710 service->private_key_file);
1712 if (service->private_key_passphrase != NULL)
1713 connman_network_set_string(service->network,
1714 "WiFi.PrivateKeyPassphrase",
1715 service->private_key_passphrase);
1717 if (service->phase2 != NULL)
1718 connman_network_set_string(service->network, "WiFi.Phase2",
1722 int __connman_service_connect(struct connman_service *service)
1726 DBG("service %p", service);
1728 if (service->state == CONNMAN_SERVICE_STATE_READY)
1731 if (is_connecting(service) == TRUE)
1734 switch (service->type) {
1735 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1736 case CONNMAN_SERVICE_TYPE_SYSTEM:
1737 case CONNMAN_SERVICE_TYPE_GPS:
1738 case CONNMAN_SERVICE_TYPE_VPN:
1740 case CONNMAN_SERVICE_TYPE_ETHERNET:
1741 case CONNMAN_SERVICE_TYPE_WIMAX:
1742 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1744 case CONNMAN_SERVICE_TYPE_CELLULAR:
1745 if (service->apn == NULL)
1748 case CONNMAN_SERVICE_TYPE_WIFI:
1749 switch (service->security) {
1750 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1751 case CONNMAN_SERVICE_SECURITY_NONE:
1753 case CONNMAN_SERVICE_SECURITY_WEP:
1754 case CONNMAN_SERVICE_SECURITY_PSK:
1755 case CONNMAN_SERVICE_SECURITY_WPA:
1756 case CONNMAN_SERVICE_SECURITY_RSN:
1757 if (service->passphrase == NULL)
1760 case CONNMAN_SERVICE_SECURITY_8021X:
1766 if (service->network != NULL) {
1767 if (prepare_network(service) == FALSE)
1770 switch (service->security) {
1771 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1772 case CONNMAN_SERVICE_SECURITY_NONE:
1773 case CONNMAN_SERVICE_SECURITY_WEP:
1774 case CONNMAN_SERVICE_SECURITY_PSK:
1775 case CONNMAN_SERVICE_SECURITY_WPA:
1776 case CONNMAN_SERVICE_SECURITY_RSN:
1778 case CONNMAN_SERVICE_SECURITY_8021X:
1779 prepare_8021x(service);
1783 __connman_ipconfig_enable(service->ipconfig);
1785 err = __connman_network_connect(service->network);
1790 if (err != -EINPROGRESS) {
1791 __connman_ipconfig_disable(service->ipconfig);
1795 service->timeout = g_timeout_add_seconds(CONNECT_TIMEOUT,
1796 connect_timeout, service);
1798 return -EINPROGRESS;
1804 int __connman_service_disconnect(struct connman_service *service)
1808 DBG("service %p", service);
1810 if (service->network != NULL) {
1811 err = __connman_network_disconnect(service->network);
1815 __connman_ipconfig_clear_address(service->ipconfig);
1817 __connman_ipconfig_disable(service->ipconfig);
1820 if (err != -EINPROGRESS)
1823 return -EINPROGRESS;
1830 * __connman_service_lookup:
1831 * @identifier: service identifier
1833 * Look up a service by identifier (reference count will not be increased)
1835 static struct connman_service *__connman_service_lookup(const char *identifier)
1837 GSequenceIter *iter;
1839 iter = g_hash_table_lookup(service_hash, identifier);
1841 return g_sequence_get(iter);
1846 static struct connman_network *create_hidden_wifi(struct connman_device *device,
1847 const char *ssid, const char *mode, const char *security)
1849 struct connman_network *network;
1852 unsigned int i, ssid_len;
1854 ssid_len = strlen(ssid);
1858 network = connman_network_create(NULL, CONNMAN_NETWORK_TYPE_WIFI);
1859 if (network == NULL)
1862 connman_network_set_blob(network, "WiFi.SSID",
1863 (unsigned char *) ssid, ssid_len);
1865 connman_network_set_string(network, "WiFi.Mode", mode);
1866 connman_network_set_string(network, "WiFi.Security", security);
1868 name = g_try_malloc0(ssid_len + 1);
1870 connman_network_unref(network);
1874 for (i = 0; i < ssid_len; i++) {
1875 if (g_ascii_isprint(ssid[i]))
1881 connman_network_set_name(network, name);
1885 index = connman_device_get_index(device);
1886 connman_network_set_index(network, index);
1888 connman_network_set_protocol(network, CONNMAN_NETWORK_PROTOCOL_IP);
1890 if (connman_device_add_network(device, network) < 0) {
1891 connman_network_unref(network);
1895 connman_network_set_available(network, TRUE);
1900 int __connman_service_create_and_connect(DBusMessage *msg)
1902 struct connman_service *service;
1903 struct connman_network *network;
1904 struct connman_device *device;
1905 DBusMessageIter iter, array;
1906 const char *mode = "managed", *security = "none";
1907 const char *type = NULL, *ssid = NULL, *passphrase = NULL;
1908 unsigned int ssid_len = 0;
1911 gboolean created = FALSE;
1914 dbus_message_iter_init(msg, &iter);
1915 dbus_message_iter_recurse(&iter, &array);
1917 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
1918 DBusMessageIter entry, value;
1921 dbus_message_iter_recurse(&array, &entry);
1922 dbus_message_iter_get_basic(&entry, &key);
1924 dbus_message_iter_next(&entry);
1925 dbus_message_iter_recurse(&entry, &value);
1927 switch (dbus_message_iter_get_arg_type(&value)) {
1928 case DBUS_TYPE_STRING:
1929 if (g_str_equal(key, "Type") == TRUE)
1930 dbus_message_iter_get_basic(&value, &type);
1931 else if (g_str_equal(key, "WiFi.Mode") == TRUE ||
1932 g_str_equal(key, "Mode") == TRUE)
1933 dbus_message_iter_get_basic(&value, &mode);
1934 else if (g_str_equal(key, "WiFi.Security") == TRUE ||
1935 g_str_equal(key, "Security") == TRUE)
1936 dbus_message_iter_get_basic(&value, &security);
1937 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE ||
1938 g_str_equal(key, "Passphrase") == TRUE)
1939 dbus_message_iter_get_basic(&value, &passphrase);
1940 else if (g_str_equal(key, "WiFi.SSID") == TRUE ||
1941 g_str_equal(key, "SSID") == TRUE)
1942 dbus_message_iter_get_basic(&value, &ssid);
1945 dbus_message_iter_next(&array);
1951 if (g_strcmp0(type, "wifi") != 0 || g_strcmp0(mode, "managed") != 0)
1957 ssid_len = strlen(ssid);
1961 if (g_strcmp0(security, "none") != 0 &&
1962 g_strcmp0(security, "wep") != 0 &&
1963 g_strcmp0(security, "psk") != 0 &&
1964 g_strcmp0(security, "wpa") != 0 &&
1965 g_strcmp0(security, "rsn") != 0 &&
1966 g_strcmp0(security, "ieee8021x") != 0)
1969 device = __connman_element_find_device(CONNMAN_DEVICE_TYPE_WIFI);
1973 ident = __connman_device_get_ident(device);
1977 group = connman_wifi_build_group_name((unsigned char *) ssid,
1978 ssid_len, mode, security);
1982 name = g_strdup_printf("%s_%s_%s", type, ident, group);
1984 service = __connman_service_lookup(name);
1986 if (service != NULL)
1989 network = create_hidden_wifi(device, ssid, mode, security);
1990 if (network != NULL) {
1991 connman_network_set_group(network, group);
1995 service = __connman_service_lookup(name);
2001 if (service == NULL) {
2006 set_reconnect_state(service, FALSE);
2008 __connman_device_disconnect(device);
2010 if (passphrase != NULL) {
2011 g_free(service->passphrase);
2012 service->passphrase = g_strdup(passphrase);
2015 service->userconnect = TRUE;
2017 err = __connman_service_connect(service);
2018 if (err < 0 && err != -EINPROGRESS)
2021 g_dbus_send_reply(connection, msg,
2022 DBUS_TYPE_OBJECT_PATH, &service->path,
2028 if (service != NULL && created == TRUE) {
2029 struct connman_network *network = service->network;
2031 if (network != NULL) {
2032 connman_network_set_available(network, FALSE);
2033 __connman_device_cleanup_networks(device);
2035 __connman_service_put(service);
2042 * __connman_service_get:
2043 * @identifier: service identifier
2045 * Look up a service by identifier or create a new one if not found
2047 static struct connman_service *__connman_service_get(const char *identifier)
2049 struct connman_service *service;
2050 GSequenceIter *iter;
2052 iter = g_hash_table_lookup(service_hash, identifier);
2054 service = g_sequence_get(iter);
2055 if (service != NULL)
2056 g_atomic_int_inc(&service->refcount);
2060 service = connman_service_create();
2061 if (service == NULL)
2064 DBG("service %p", service);
2066 service->identifier = g_strdup(identifier);
2068 service->profile = g_strdup(__connman_profile_active_ident());
2070 iter = g_sequence_insert_sorted(service_list, service,
2071 service_compare, NULL);
2073 g_hash_table_insert(service_hash, service->identifier, iter);
2078 static int service_register(struct connman_service *service)
2080 const char *path = __connman_profile_active_path();
2081 GSequenceIter *iter;
2083 DBG("service %p", service);
2085 if (service->path != NULL)
2088 service->path = g_strdup_printf("%s/%s", path, service->identifier);
2090 DBG("path %s", service->path);
2092 __connman_config_provision_service(service);
2094 __connman_storage_load_service(service);
2096 g_dbus_register_interface(connection, service->path,
2097 CONNMAN_SERVICE_INTERFACE,
2098 service_methods, service_signals,
2099 NULL, service, NULL);
2101 iter = g_hash_table_lookup(service_hash, service->identifier);
2103 g_sequence_sort_changed(iter, service_compare, NULL);
2105 __connman_profile_changed(TRUE);
2110 static void service_up(struct connman_ipconfig *ipconfig)
2112 connman_info("%s up", connman_ipconfig_get_ifname(ipconfig));
2115 static void service_down(struct connman_ipconfig *ipconfig)
2117 connman_info("%s down", connman_ipconfig_get_ifname(ipconfig));
2120 static void service_lower_up(struct connman_ipconfig *ipconfig)
2122 connman_info("%s lower up", connman_ipconfig_get_ifname(ipconfig));
2125 static void service_lower_down(struct connman_ipconfig *ipconfig)
2127 connman_info("%s lower down", connman_ipconfig_get_ifname(ipconfig));
2130 static void service_ip_bound(struct connman_ipconfig *ipconfig)
2132 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
2134 connman_info("%s ip bound", connman_ipconfig_get_ifname(ipconfig));
2136 settings_changed(service);
2139 static void service_ip_release(struct connman_ipconfig *ipconfig)
2141 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
2143 connman_info("%s ip release", connman_ipconfig_get_ifname(ipconfig));
2145 settings_changed(service);
2148 static const struct connman_ipconfig_ops service_ops = {
2150 .down = service_down,
2151 .lower_up = service_lower_up,
2152 .lower_down = service_lower_down,
2153 .ip_bound = service_ip_bound,
2154 .ip_release = service_ip_release,
2157 static void setup_ipconfig(struct connman_service *service, int index)
2162 service->ipconfig = connman_ipconfig_create(index);
2163 if (service->ipconfig == NULL)
2166 connman_ipconfig_set_method(service->ipconfig,
2167 CONNMAN_IPCONFIG_METHOD_DHCP);
2169 connman_ipconfig_set_data(service->ipconfig, service);
2171 connman_ipconfig_set_ops(service->ipconfig, &service_ops);
2174 void __connman_service_create_ipconfig(struct connman_service *service,
2177 if (service->ipconfig != NULL)
2180 setup_ipconfig(service, index);
2184 * __connman_service_lookup_from_network:
2185 * @network: network structure
2187 * Look up a service by network (reference count will not be increased)
2189 struct connman_service *__connman_service_lookup_from_network(struct connman_network *network)
2191 struct connman_service *service;
2192 const char *ident, *group;
2195 DBG("network %p", network);
2197 ident = __connman_network_get_ident(network);
2201 group = connman_network_get_group(network);
2205 name = g_strdup_printf("%s_%s_%s",
2206 __connman_network_get_type(network), ident, group);
2207 service = __connman_service_lookup(name);
2213 const char *__connman_service_get_path(struct connman_service *service)
2215 return service->path;
2218 unsigned int __connman_service_get_order(struct connman_service *service)
2220 GSequenceIter *iter;
2222 if (service == NULL)
2225 if (service->favorite == FALSE) {
2230 iter = g_hash_table_lookup(service_hash, service->identifier);
2232 if (g_sequence_iter_get_position(iter) == 0)
2239 return service->order;
2242 static enum connman_service_type convert_network_type(struct connman_network *network)
2244 enum connman_network_type type = connman_network_get_type(network);
2247 case CONNMAN_NETWORK_TYPE_UNKNOWN:
2248 case CONNMAN_NETWORK_TYPE_VENDOR:
2250 case CONNMAN_NETWORK_TYPE_ETHERNET:
2251 return CONNMAN_SERVICE_TYPE_ETHERNET;
2252 case CONNMAN_NETWORK_TYPE_WIFI:
2253 return CONNMAN_SERVICE_TYPE_WIFI;
2254 case CONNMAN_NETWORK_TYPE_WIMAX:
2255 return CONNMAN_SERVICE_TYPE_WIMAX;
2256 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
2257 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
2258 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
2259 case CONNMAN_NETWORK_TYPE_CELLULAR:
2260 case CONNMAN_NETWORK_TYPE_MBM:
2261 case CONNMAN_NETWORK_TYPE_HSO:
2262 return CONNMAN_SERVICE_TYPE_CELLULAR;
2265 return CONNMAN_SERVICE_TYPE_UNKNOWN;
2268 static enum connman_service_mode convert_wifi_mode(const char *mode)
2271 return CONNMAN_SERVICE_MODE_UNKNOWN;
2272 else if (g_str_equal(mode, "managed") == TRUE)
2273 return CONNMAN_SERVICE_MODE_MANAGED;
2274 else if (g_str_equal(mode, "adhoc") == TRUE)
2275 return CONNMAN_SERVICE_MODE_ADHOC;
2277 return CONNMAN_SERVICE_MODE_UNKNOWN;
2280 static enum connman_service_security convert_wifi_security(const char *security)
2282 if (security == NULL)
2283 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
2284 else if (g_str_equal(security, "none") == TRUE)
2285 return CONNMAN_SERVICE_SECURITY_NONE;
2286 else if (g_str_equal(security, "wep") == TRUE)
2287 return CONNMAN_SERVICE_SECURITY_WEP;
2288 else if (g_str_equal(security, "wep") == TRUE)
2289 return CONNMAN_SERVICE_SECURITY_PSK;
2290 else if (g_str_equal(security, "ieee8021x") == TRUE)
2291 return CONNMAN_SERVICE_SECURITY_8021X;
2292 else if (g_str_equal(security, "wpa") == TRUE)
2293 return CONNMAN_SERVICE_SECURITY_WPA;
2294 else if (g_str_equal(security, "rsn") == TRUE)
2295 return CONNMAN_SERVICE_SECURITY_RSN;
2297 return CONNMAN_SERVICE_SECURITY_UNKNOWN;
2300 static enum connman_service_mode convert_cellular_mode(connman_uint8_t mode)
2305 return CONNMAN_SERVICE_MODE_GPRS;
2307 return CONNMAN_SERVICE_MODE_EDGE;
2312 return CONNMAN_SERVICE_MODE_UMTS;
2315 return CONNMAN_SERVICE_MODE_UNKNOWN;
2318 static void update_from_network(struct connman_service *service,
2319 struct connman_network *network)
2321 connman_uint8_t strength = service->strength;
2322 GSequenceIter *iter;
2325 DBG("service %p network %p", service, network);
2327 if (service->state == CONNMAN_SERVICE_STATE_READY)
2330 if (is_connecting(service) == TRUE)
2333 str = connman_network_get_string(network, "Name");
2335 g_free(service->name);
2336 service->name = g_strdup(str);
2337 service->hidden = FALSE;
2339 g_free(service->name);
2340 service->name = NULL;
2341 service->hidden = TRUE;
2344 service->strength = connman_network_get_uint8(network, "Strength");
2345 service->roaming = connman_network_get_bool(network, "Roaming");
2347 if (service->strength == 0) {
2349 * Filter out 0-values; it's unclear what they mean
2350 * and they cause anomalous sorting of the priority list.
2352 service->strength = strength;
2355 str = connman_network_get_string(network, "WiFi.Mode");
2356 service->mode = convert_wifi_mode(str);
2358 str = connman_network_get_string(network, "WiFi.Security");
2359 service->security = convert_wifi_security(str);
2361 str = connman_network_get_string(network, "Cellular.MCC");
2362 g_free(service->mcc);
2363 service->mcc = g_strdup(str);
2365 str = connman_network_get_string(network, "Cellular.MNC");
2366 g_free(service->mnc);
2367 service->mnc = g_strdup(str);
2369 if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
2370 connman_uint8_t value = connman_network_get_uint8(network,
2373 service->mode = convert_cellular_mode(value);
2376 if (service->strength > strength && service->network != NULL) {
2377 connman_network_unref(service->network);
2378 service->network = connman_network_ref(network);
2380 strength_changed(service);
2383 if (service->network == NULL)
2384 service->network = connman_network_ref(network);
2386 iter = g_hash_table_lookup(service_hash, service->identifier);
2388 g_sequence_sort_changed(iter, service_compare, NULL);
2392 * __connman_service_create_from_network:
2393 * @network: network structure
2395 * Look up service by network and if not found, create one
2397 struct connman_service *__connman_service_create_from_network(struct connman_network *network)
2399 struct connman_service *service;
2400 const char *ident, *group;
2403 DBG("network %p", network);
2405 ident = __connman_network_get_ident(network);
2409 group = connman_network_get_group(network);
2413 name = g_strdup_printf("%s_%s_%s",
2414 __connman_network_get_type(network), ident, group);
2415 service = __connman_service_get(name);
2418 if (service == NULL)
2421 if (__connman_network_get_weakness(network) == TRUE)
2424 if (service->path != NULL) {
2425 update_from_network(service, network);
2426 __connman_profile_changed(TRUE);
2430 service->type = convert_network_type(network);
2432 switch (service->type) {
2433 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2434 case CONNMAN_SERVICE_TYPE_SYSTEM:
2435 case CONNMAN_SERVICE_TYPE_ETHERNET:
2436 case CONNMAN_SERVICE_TYPE_WIMAX:
2437 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2438 case CONNMAN_SERVICE_TYPE_GPS:
2439 case CONNMAN_SERVICE_TYPE_VPN:
2440 service->autoconnect = FALSE;
2442 case CONNMAN_SERVICE_TYPE_WIFI:
2443 case CONNMAN_SERVICE_TYPE_CELLULAR:
2444 service->autoconnect = TRUE;
2448 service->state = CONNMAN_SERVICE_STATE_IDLE;
2450 update_from_network(service, network);
2452 setup_ipconfig(service, connman_network_get_index(network));
2454 service_register(service);
2456 if (service->favorite == TRUE)
2457 __connman_service_auto_connect();
2462 void __connman_service_update_from_network(struct connman_network *network)
2464 struct connman_service *service;
2465 enum connman_service_mode mode;
2466 connman_uint8_t strength, value;
2467 connman_bool_t roaming;
2468 GSequenceIter *iter;
2470 DBG("network %p", network);
2472 service = __connman_service_lookup_from_network(network);
2473 if (service == NULL)
2476 if (service->network == NULL)
2479 strength = connman_network_get_uint8(service->network, "Strength");
2480 if (strength == service->strength)
2483 service->strength = strength;
2485 strength_changed(service);
2488 roaming = connman_network_get_bool(service->network, "Roaming");
2489 if (roaming == service->roaming)
2492 service->roaming = roaming;
2494 roaming_changed(service);
2496 iter = g_hash_table_lookup(service_hash, service->identifier);
2498 g_sequence_sort_changed(iter, service_compare, NULL);
2501 if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
2504 value = connman_network_get_uint8(service->network, "Cellular.Mode");
2505 mode = convert_cellular_mode(value);
2507 if (mode == service->mode)
2510 service->mode = mode;
2512 mode_changed(service);
2515 void __connman_service_remove_from_network(struct connman_network *network)
2517 struct connman_service *service;
2519 DBG("network %p", network);
2521 service = __connman_service_lookup_from_network(network);
2522 if (service == NULL)
2525 __connman_service_put(service);
2528 static int service_load(struct connman_service *service)
2530 const char *ident = service->profile;
2532 GError *error = NULL;
2533 gchar *pathname, *data = NULL;
2536 connman_bool_t autoconnect;
2537 unsigned int ssid_len;
2540 DBG("service %p", service);
2545 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
2546 if (pathname == NULL)
2549 keyfile = g_key_file_new();
2551 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
2558 if (g_key_file_load_from_data(keyfile, data, length,
2559 0, NULL) == FALSE) {
2566 switch (service->type) {
2567 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2568 case CONNMAN_SERVICE_TYPE_SYSTEM:
2569 case CONNMAN_SERVICE_TYPE_ETHERNET:
2570 case CONNMAN_SERVICE_TYPE_GPS:
2571 case CONNMAN_SERVICE_TYPE_VPN:
2573 case CONNMAN_SERVICE_TYPE_WIFI:
2574 if (service->name == NULL) {
2577 name = g_key_file_get_string(keyfile,
2578 service->identifier, "Name", NULL);
2580 g_free(service->name);
2581 service->name = name;
2584 if (service->network != NULL)
2585 connman_network_set_name(service->network,
2589 if (service->network &&
2590 connman_network_get_blob(service->network,
2591 "WiFi.SSID", &ssid_len) == NULL) {
2594 hex_ssid = g_key_file_get_string(keyfile,
2595 service->identifier,
2598 if (hex_ssid != NULL) {
2600 unsigned int i, j = 0, hex;
2601 size_t hex_ssid_len = strlen(hex_ssid);
2603 ssid = g_try_malloc0(hex_ssid_len / 2);
2610 for (i = 0; i < hex_ssid_len; i += 2) {
2611 sscanf(hex_ssid + i, "%02x", &hex);
2615 connman_network_set_blob(service->network,
2616 "WiFi.SSID", ssid, hex_ssid_len / 2);
2623 case CONNMAN_SERVICE_TYPE_WIMAX:
2624 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2625 case CONNMAN_SERVICE_TYPE_CELLULAR:
2626 service->apn = g_key_file_get_string(keyfile,
2627 service->identifier, "APN", NULL);
2629 service->username = g_key_file_get_string(keyfile,
2630 service->identifier, "Username", NULL);
2632 service->username = g_key_file_get_string(keyfile,
2633 service->identifier, "Password", NULL);
2635 service->favorite = g_key_file_get_boolean(keyfile,
2636 service->identifier, "Favorite", NULL);
2638 autoconnect = g_key_file_get_boolean(keyfile,
2639 service->identifier, "AutoConnect", &error);
2641 service->autoconnect = autoconnect;
2642 g_clear_error(&error);
2644 str = g_key_file_get_string(keyfile,
2645 service->identifier, "Failure", NULL);
2647 service->state = CONNMAN_SERVICE_STATE_FAILURE;
2648 service->error = string2error(str);
2653 str = g_key_file_get_string(keyfile,
2654 service->identifier, "Modified", NULL);
2656 g_time_val_from_iso8601(str, &service->modified);
2660 str = g_key_file_get_string(keyfile,
2661 service->identifier, "Passphrase", NULL);
2663 g_free(service->passphrase);
2664 service->passphrase = str;
2667 if (service->ipconfig != NULL)
2668 __connman_ipconfig_load(service->ipconfig, keyfile,
2669 service->identifier, "IPv4.");
2672 g_key_file_free(keyfile);
2677 static int service_save(struct connman_service *service)
2679 const char *ident = service->profile;
2681 gchar *pathname, *data = NULL;
2686 DBG("service %p", service);
2691 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
2692 if (pathname == NULL)
2695 keyfile = g_key_file_new();
2697 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
2701 if (g_key_file_load_from_data(keyfile, data, length,
2709 if (service->name != NULL)
2710 g_key_file_set_string(keyfile, service->identifier,
2711 "Name", service->name);
2713 switch (service->type) {
2714 case CONNMAN_SERVICE_TYPE_UNKNOWN:
2715 case CONNMAN_SERVICE_TYPE_SYSTEM:
2716 case CONNMAN_SERVICE_TYPE_ETHERNET:
2717 case CONNMAN_SERVICE_TYPE_GPS:
2718 case CONNMAN_SERVICE_TYPE_VPN:
2720 case CONNMAN_SERVICE_TYPE_WIFI:
2721 if (service->network) {
2722 const unsigned char *ssid;
2723 unsigned int ssid_len = 0;
2725 ssid = connman_network_get_blob(service->network,
2726 "WiFi.SSID", &ssid_len);
2728 if (ssid != NULL && ssid_len > 0 && ssid[0] != '\0') {
2729 char *identifier = service->identifier;
2733 str = g_string_sized_new(ssid_len * 2);
2739 for (i = 0; i < ssid_len; i++)
2740 g_string_append_printf(str,
2743 g_key_file_set_string(keyfile, identifier,
2746 g_string_free(str, TRUE);
2751 case CONNMAN_SERVICE_TYPE_WIMAX:
2752 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
2753 case CONNMAN_SERVICE_TYPE_CELLULAR:
2754 if (service->apn != NULL)
2755 g_key_file_set_string(keyfile, service->identifier,
2756 "APN", service->apn);
2758 if (service->username != NULL)
2759 g_key_file_set_string(keyfile, service->identifier,
2760 "Username", service->username);
2762 if (service->password != NULL)
2763 g_key_file_set_string(keyfile, service->identifier,
2764 "Password", service->password);
2766 g_key_file_set_boolean(keyfile, service->identifier,
2767 "Favorite", service->favorite);
2769 if (service->favorite == TRUE)
2770 g_key_file_set_boolean(keyfile, service->identifier,
2771 "AutoConnect", service->autoconnect);
2773 if (service->state == CONNMAN_SERVICE_STATE_FAILURE) {
2774 const char *failure = error2string(service->error);
2775 if (failure != NULL)
2776 g_key_file_set_string(keyfile,
2777 service->identifier,
2778 "Failure", failure);
2780 g_key_file_remove_key(keyfile, service->identifier,
2786 str = g_time_val_to_iso8601(&service->modified);
2788 g_key_file_set_string(keyfile, service->identifier,
2793 if (service->passphrase != NULL && strlen(service->passphrase) > 0)
2794 g_key_file_set_string(keyfile, service->identifier,
2795 "Passphrase", service->passphrase);
2797 g_key_file_remove_key(keyfile, service->identifier,
2798 "Passphrase", NULL);
2800 if (service->ipconfig != NULL)
2801 __connman_ipconfig_save(service->ipconfig, keyfile,
2802 service->identifier, "IPv4.");
2804 data = g_key_file_to_data(keyfile, &length, NULL);
2806 if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
2807 connman_error("Failed to store service information");
2812 g_key_file_free(keyfile);
2819 static struct connman_storage service_storage = {
2821 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
2822 .service_load = service_load,
2823 .service_save = service_save,
2826 int __connman_service_init(void)
2830 connection = connman_dbus_get_connection();
2832 if (connman_storage_register(&service_storage) < 0)
2833 connman_error("Failed to register service storage");
2835 service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
2838 service_list = g_sequence_new(service_free);
2843 void __connman_service_cleanup(void)
2847 g_sequence_free(service_list);
2848 service_list = NULL;
2850 g_hash_table_destroy(service_hash);
2851 service_hash = NULL;
2853 connman_storage_unregister(&service_storage);
2855 dbus_connection_unref(connection);