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 dbus_message_unref(service->pending);
1066 service->pending = NULL;
1068 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1071 static DBusMessage *disconnect_service(DBusConnection *conn,
1072 DBusMessage *msg, void *user_data)
1074 struct connman_service *service = user_data;
1077 DBG("service %p", service);
1079 reply_pending(service, ECONNABORTED);
1081 service->ignore = TRUE;
1083 set_reconnect_state(service, FALSE);
1085 err = __connman_service_disconnect(service);
1087 if (err != -EINPROGRESS)
1088 return __connman_error_failed(msg, -err);
1093 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1096 static DBusMessage *remove_service(DBusConnection *conn,
1097 DBusMessage *msg, void *user_data)
1099 struct connman_service *service = user_data;
1101 DBG("service %p", service);
1103 if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
1104 return __connman_error_not_supported(msg);
1106 if (service->favorite == FALSE &&
1107 service->state != CONNMAN_SERVICE_STATE_FAILURE)
1108 return __connman_error_not_supported(msg);
1110 if (service->network != NULL) {
1111 set_reconnect_state(service, FALSE);
1113 __connman_network_disconnect(service->network);
1116 g_free(service->passphrase);
1117 service->passphrase = NULL;
1119 passphrase_changed(service);
1121 g_free(service->apn);
1122 service->apn = NULL;
1124 g_free(service->username);
1125 service->username = NULL;
1127 g_free(service->password);
1128 service->password = NULL;
1130 apn_changed(service);
1134 __connman_service_set_favorite(service, FALSE);
1135 __connman_storage_save_service(service);
1137 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1140 static DBusMessage *move_before(DBusConnection *conn,
1141 DBusMessage *msg, void *user_data)
1143 struct connman_service *service = user_data;
1144 struct connman_service *target;
1146 GSequenceIter *src, *dst;
1148 DBG("service %p", service);
1150 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
1153 if (service->favorite == FALSE)
1154 return __connman_error_not_supported(msg);
1156 target = find_service(path);
1157 if (target == NULL || target->favorite == FALSE || target == service)
1158 return __connman_error_invalid_service(msg);
1160 DBG("target %s", target->identifier);
1162 if (target->state != service->state)
1163 return __connman_error_invalid_service(msg);
1165 g_get_current_time(&service->modified);
1166 __connman_storage_save_service(service);
1168 src = g_hash_table_lookup(service_hash, service->identifier);
1169 dst = g_hash_table_lookup(service_hash, target->identifier);
1171 g_sequence_move(src, dst);
1173 __connman_profile_changed(FALSE);
1175 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1178 static DBusMessage *move_after(DBusConnection *conn,
1179 DBusMessage *msg, void *user_data)
1181 struct connman_service *service = user_data;
1182 struct connman_service *target;
1185 DBG("service %p", service);
1187 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
1190 if (service->favorite == FALSE)
1191 return __connman_error_not_supported(msg);
1193 target = find_service(path);
1194 if (target == NULL || target->favorite == FALSE || target == service)
1195 return __connman_error_invalid_service(msg);
1197 DBG("target %s", target->identifier);
1199 if (target->state != service->state)
1200 return __connman_error_invalid_service(msg);
1202 g_get_current_time(&service->modified);
1203 __connman_storage_save_service(service);
1205 return __connman_error_not_implemented(msg);
1208 static GDBusMethodTable service_methods[] = {
1209 { "GetProperties", "", "a{sv}", get_properties },
1210 { "SetProperty", "sv", "", set_property },
1211 { "ClearProperty", "s", "", clear_property },
1212 { "Connect", "", "", connect_service,
1213 G_DBUS_METHOD_FLAG_ASYNC },
1214 { "Disconnect", "", "", disconnect_service },
1215 { "Remove", "", "", remove_service },
1216 { "MoveBefore", "o", "", move_before },
1217 { "MoveAfter", "o", "", move_after },
1221 static GDBusSignalTable service_signals[] = {
1222 { "PropertyChanged", "sv" },
1226 static void service_free(gpointer user_data)
1228 struct connman_service *service = user_data;
1229 char *path = service->path;
1231 DBG("service %p", service);
1233 reply_pending(service, ENOENT);
1235 g_hash_table_remove(service_hash, service->identifier);
1237 service->path = NULL;
1240 __connman_profile_changed(FALSE);
1242 g_dbus_unregister_interface(connection, path,
1243 CONNMAN_SERVICE_INTERFACE);
1247 if (service->network != NULL)
1248 connman_network_unref(service->network);
1250 if (service->ipconfig != NULL) {
1251 connman_ipconfig_unref(service->ipconfig);
1252 service->ipconfig = NULL;
1255 if (service->location != NULL)
1256 connman_location_unref(service->location);
1258 g_free(service->mcc);
1259 g_free(service->mnc);
1260 g_free(service->apn);
1261 g_free(service->username);
1262 g_free(service->password);
1263 g_free(service->profile);
1264 g_free(service->name);
1265 g_free(service->passphrase);
1266 g_free(service->identifier);
1267 g_free(service->eap);
1268 g_free(service->identity);
1269 g_free(service->ca_cert_file);
1270 g_free(service->client_cert_file);
1271 g_free(service->private_key_file);
1272 g_free(service->private_key_passphrase);
1273 g_free(service->phase2);
1278 * __connman_service_put:
1279 * @service: service structure
1281 * Release service if no longer needed
1283 void __connman_service_put(struct connman_service *service)
1285 DBG("service %p", service);
1287 if (g_atomic_int_dec_and_test(&service->refcount) == TRUE) {
1288 GSequenceIter *iter;
1290 iter = g_hash_table_lookup(service_hash, service->identifier);
1292 reply_pending(service, ECONNABORTED);
1294 __connman_service_disconnect(service);
1296 g_sequence_remove(iter);
1298 service_free(service);
1302 static void __connman_service_initialize(struct connman_service *service)
1304 DBG("service %p", service);
1306 service->refcount = 1;
1308 service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
1309 service->mode = CONNMAN_SERVICE_MODE_UNKNOWN;
1310 service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
1311 service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
1313 service->favorite = FALSE;
1314 service->immutable = FALSE;
1315 service->hidden = FALSE;
1317 service->ignore = FALSE;
1319 service->userconnect = FALSE;
1325 * connman_service_create:
1327 * Allocate a new service.
1329 * Returns: a newly-allocated #connman_service structure
1331 struct connman_service *connman_service_create(void)
1333 struct connman_service *service;
1335 service = g_try_new0(struct connman_service, 1);
1336 if (service == NULL)
1339 DBG("service %p", service);
1341 __connman_service_initialize(service);
1343 service->location = __connman_location_create(service);
1348 struct connman_location *__connman_service_get_location(struct connman_service *service)
1350 return service->location;
1354 * connman_service_ref:
1355 * @service: service structure
1357 * Increase reference counter of service
1359 struct connman_service *connman_service_ref(struct connman_service *service)
1361 g_atomic_int_inc(&service->refcount);
1367 * connman_service_unref:
1368 * @service: service structure
1370 * Decrease reference counter of service
1372 void connman_service_unref(struct connman_service *service)
1374 __connman_service_put(service);
1377 static gint service_compare(gconstpointer a, gconstpointer b,
1380 struct connman_service *service_a = (void *) a;
1381 struct connman_service *service_b = (void *) b;
1383 if (service_a->state != service_b->state) {
1384 if (service_a->state == CONNMAN_SERVICE_STATE_READY)
1386 if (service_b->state == CONNMAN_SERVICE_STATE_READY)
1390 if (service_a->order > service_b->order)
1393 if (service_a->order < service_b->order)
1396 if (service_a->favorite == TRUE && service_b->favorite == FALSE)
1399 if (service_a->favorite == FALSE && service_b->favorite == TRUE)
1402 if (service_a->type != service_b->type) {
1403 switch (service_a->type) {
1404 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1405 case CONNMAN_SERVICE_TYPE_SYSTEM:
1406 case CONNMAN_SERVICE_TYPE_ETHERNET:
1407 case CONNMAN_SERVICE_TYPE_GPS:
1408 case CONNMAN_SERVICE_TYPE_VPN:
1410 case CONNMAN_SERVICE_TYPE_WIFI:
1412 case CONNMAN_SERVICE_TYPE_WIMAX:
1413 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1414 case CONNMAN_SERVICE_TYPE_CELLULAR:
1419 return (gint) service_b->strength - (gint) service_a->strength;
1423 * connman_service_get_type:
1424 * @service: service structure
1426 * Get the type of service
1428 enum connman_service_type connman_service_get_type(struct connman_service *service)
1430 if (service == NULL)
1431 return CONNMAN_SERVICE_TYPE_UNKNOWN;
1433 return service->type;
1437 * connman_service_get_interface:
1438 * @service: service structure
1440 * Get network interface of service
1442 char *connman_service_get_interface(struct connman_service *service)
1446 if (service == NULL)
1449 if (service->network == NULL)
1452 index = connman_network_get_index(service->network);
1454 return connman_inet_ifname(index);
1458 * connman_service_get_network:
1459 * @service: service structure
1461 * Get the service network
1463 struct connman_network *
1464 __connman_service_get_network(struct connman_service *service)
1466 if (service == NULL)
1469 return service->network;
1473 * __connman_service_set_favorite:
1474 * @service: service structure
1475 * @favorite: favorite value
1477 * Change the favorite setting of service
1479 int __connman_service_set_favorite(struct connman_service *service,
1480 connman_bool_t favorite)
1482 GSequenceIter *iter;
1484 iter = g_hash_table_lookup(service_hash, service->identifier);
1488 if (service->favorite == favorite)
1491 service->favorite = favorite;
1493 favorite_changed(service);
1495 g_sequence_sort_changed(iter, service_compare, NULL);
1497 __connman_profile_changed(FALSE);
1502 int __connman_service_set_immutable(struct connman_service *service,
1503 connman_bool_t immutable)
1505 service->immutable = immutable;
1507 immutable_changed(service);
1512 void __connman_service_set_string(struct connman_service *service,
1513 const char *key, const char *value)
1515 if (g_str_equal(key, "EAP") == TRUE) {
1516 g_free(service->eap);
1517 service->eap = g_strdup(value);
1518 } else if (g_str_equal(key, "Identity") == TRUE) {
1519 g_free(service->identity);
1520 service->identity = g_strdup(value);
1521 } else if (g_str_equal(key, "CACertFile") == TRUE) {
1522 g_free(service->ca_cert_file);
1523 service->ca_cert_file = g_strdup(value);
1524 } else if (g_str_equal(key, "ClientCertFile") == TRUE) {
1525 g_free(service->client_cert_file);
1526 service->client_cert_file = g_strdup(value);
1527 } else if (g_str_equal(key, "PrivateKeyFile") == TRUE) {
1528 g_free(service->private_key_file);
1529 service->private_key_file = g_strdup(value);
1530 } else if (g_str_equal(key, "PrivateKeyPassphrase") == TRUE) {
1531 g_free(service->private_key_passphrase);
1532 service->private_key_passphrase = g_strdup(value);
1533 } else if (g_str_equal(key, "Phase2") == TRUE) {
1534 g_free(service->phase2);
1535 service->phase2 = g_strdup(value);
1536 } else if (g_str_equal(key, "Passphrase") == TRUE) {
1537 g_free(service->passphrase);
1538 service->passphrase = g_strdup(value);
1542 int __connman_service_indicate_state(struct connman_service *service,
1543 enum connman_service_state state)
1545 GSequenceIter *iter;
1547 DBG("service %p state %d", service, state);
1549 if (service == NULL)
1552 if (service->state == state)
1555 if (service->state == CONNMAN_SERVICE_STATE_FAILURE &&
1556 state == CONNMAN_SERVICE_STATE_IDLE)
1559 if (service->state == CONNMAN_SERVICE_STATE_IDLE &&
1560 state == CONNMAN_SERVICE_STATE_DISCONNECT)
1563 if (state == CONNMAN_SERVICE_STATE_IDLE &&
1564 service->state != CONNMAN_SERVICE_STATE_DISCONNECT) {
1565 service->state = CONNMAN_SERVICE_STATE_DISCONNECT;
1566 state_changed(service);
1568 reply_pending(service, ECONNABORTED);
1570 __connman_service_disconnect(service);
1573 if (state == CONNMAN_SERVICE_STATE_CONFIGURATION)
1574 __connman_ipconfig_enable(service->ipconfig);
1576 service->state = state;
1577 state_changed(service);
1579 if (state == CONNMAN_SERVICE_STATE_IDLE) {
1580 connman_bool_t reconnect;
1582 reconnect = get_reconnect_state(service);
1583 if (reconnect == TRUE)
1584 __connman_service_auto_connect();
1587 if (state == CONNMAN_SERVICE_STATE_READY) {
1588 set_reconnect_state(service, TRUE);
1590 __connman_service_set_favorite(service, TRUE);
1592 reply_pending(service, 0);
1594 service->userconnect = FALSE;
1596 g_get_current_time(&service->modified);
1597 __connman_storage_save_service(service);
1599 __connman_notifier_connect(service->type);
1603 __connman_location_detect(service);
1604 } else if (state == CONNMAN_SERVICE_STATE_DISCONNECT) {
1605 __connman_location_finish(service);
1609 __connman_notifier_disconnect(service->type);
1612 if (state == CONNMAN_SERVICE_STATE_FAILURE) {
1613 reply_pending(service, EIO);
1615 if (service->userconnect == FALSE)
1616 __connman_service_auto_connect();
1618 g_get_current_time(&service->modified);
1619 __connman_storage_save_service(service);
1621 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
1623 iter = g_hash_table_lookup(service_hash, service->identifier);
1625 g_sequence_sort_changed(iter, service_compare, NULL);
1627 __connman_profile_changed(FALSE);
1629 if (service->state == CONNMAN_SERVICE_STATE_IDLE ||
1630 service->state == CONNMAN_SERVICE_STATE_FAILURE)
1631 __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
1636 int __connman_service_indicate_error(struct connman_service *service,
1637 enum connman_service_error error)
1639 DBG("service %p error %d", service, error);
1641 if (service == NULL)
1644 service->error = error;
1646 return __connman_service_indicate_state(service,
1647 CONNMAN_SERVICE_STATE_FAILURE);
1650 int __connman_service_indicate_default(struct connman_service *service)
1652 DBG("service %p", service);
1659 static connman_bool_t prepare_network(struct connman_service *service)
1661 enum connman_network_type type;
1662 unsigned int ssid_len;
1664 type = connman_network_get_type(service->network);
1667 case CONNMAN_NETWORK_TYPE_UNKNOWN:
1668 case CONNMAN_NETWORK_TYPE_VENDOR:
1670 case CONNMAN_NETWORK_TYPE_WIFI:
1671 if (connman_network_get_blob(service->network, "WiFi.SSID",
1675 connman_network_set_string(service->network,
1676 "WiFi.Passphrase", service->passphrase);
1678 case CONNMAN_NETWORK_TYPE_ETHERNET:
1679 case CONNMAN_NETWORK_TYPE_WIMAX:
1680 case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
1681 case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
1683 case CONNMAN_NETWORK_TYPE_CELLULAR:
1684 case CONNMAN_NETWORK_TYPE_MBM:
1685 case CONNMAN_NETWORK_TYPE_HSO:
1686 connman_network_set_string(service->network,
1687 "Cellular.APN", service->apn);
1689 connman_network_set_string(service->network,
1690 "Cellular.Username", service->username);
1691 connman_network_set_string(service->network,
1692 "Cellular.Password", service->password);
1699 static void prepare_8021x(struct connman_service *service)
1701 if (service->eap != NULL)
1702 connman_network_set_string(service->network, "WiFi.EAP",
1705 if (service->identity != NULL)
1706 connman_network_set_string(service->network, "WiFi.Identity",
1709 if (service->ca_cert_file != NULL)
1710 connman_network_set_string(service->network, "WiFi.CACertFile",
1711 service->ca_cert_file);
1713 if (service->client_cert_file != NULL)
1714 connman_network_set_string(service->network,
1715 "WiFi.ClientCertFile",
1716 service->client_cert_file);
1718 if (service->private_key_file != NULL)
1719 connman_network_set_string(service->network,
1720 "WiFi.PrivateKeyFile",
1721 service->private_key_file);
1723 if (service->private_key_passphrase != NULL)
1724 connman_network_set_string(service->network,
1725 "WiFi.PrivateKeyPassphrase",
1726 service->private_key_passphrase);
1728 if (service->phase2 != NULL)
1729 connman_network_set_string(service->network, "WiFi.Phase2",
1733 int __connman_service_connect(struct connman_service *service)
1737 DBG("service %p", service);
1739 if (service->state == CONNMAN_SERVICE_STATE_READY)
1742 if (is_connecting(service) == TRUE)
1745 switch (service->type) {
1746 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1747 case CONNMAN_SERVICE_TYPE_SYSTEM:
1748 case CONNMAN_SERVICE_TYPE_GPS:
1749 case CONNMAN_SERVICE_TYPE_VPN:
1751 case CONNMAN_SERVICE_TYPE_ETHERNET:
1752 case CONNMAN_SERVICE_TYPE_WIMAX:
1753 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1755 case CONNMAN_SERVICE_TYPE_CELLULAR:
1756 if (service->apn == NULL)
1759 case CONNMAN_SERVICE_TYPE_WIFI:
1760 switch (service->security) {
1761 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1762 case CONNMAN_SERVICE_SECURITY_NONE:
1764 case CONNMAN_SERVICE_SECURITY_WEP:
1765 case CONNMAN_SERVICE_SECURITY_PSK:
1766 case CONNMAN_SERVICE_SECURITY_WPA:
1767 case CONNMAN_SERVICE_SECURITY_RSN:
1768 if (service->passphrase == NULL)
1771 case CONNMAN_SERVICE_SECURITY_8021X:
1777 if (service->network != NULL) {
1778 if (prepare_network(service) == FALSE)
1781 switch (service->security) {
1782 case CONNMAN_SERVICE_SECURITY_UNKNOWN:
1783 case CONNMAN_SERVICE_SECURITY_NONE:
1784 case CONNMAN_SERVICE_SECURITY_WEP:
1785 case CONNMAN_SERVICE_SECURITY_PSK:
1786 case CONNMAN_SERVICE_SECURITY_WPA:
1787 case CONNMAN_SERVICE_SECURITY_RSN:
1789 case CONNMAN_SERVICE_SECURITY_8021X:
1790 prepare_8021x(service);
1794 __connman_ipconfig_enable(service->ipconfig);
1796 err = __connman_network_connect(service->network);
1801 if (err != -EINPROGRESS) {
1802 __connman_ipconfig_disable(service->ipconfig);
1806 service->timeout = g_timeout_add_seconds(CONNECT_TIMEOUT,
1807 connect_timeout, service);
1809 return -EINPROGRESS;
1815 int __connman_service_disconnect(struct connman_service *service)
1819 DBG("service %p", service);
1821 if (service->network != NULL) {
1822 err = __connman_network_disconnect(service->network);
1826 __connman_ipconfig_disable(service->ipconfig);
1829 if (err != -EINPROGRESS)
1832 return -EINPROGRESS;
1839 * __connman_service_lookup:
1840 * @identifier: service identifier
1842 * Look up a service by identifier (reference count will not be increased)
1844 static struct connman_service *__connman_service_lookup(const char *identifier)
1846 GSequenceIter *iter;
1848 iter = g_hash_table_lookup(service_hash, identifier);
1850 return g_sequence_get(iter);
1855 static struct connman_network *create_hidden_wifi(struct connman_device *device,
1856 const char *ssid, const char *mode, const char *security)
1858 struct connman_network *network;
1861 unsigned int i, ssid_len;
1863 ssid_len = strlen(ssid);
1867 network = connman_network_create(NULL, CONNMAN_NETWORK_TYPE_WIFI);
1868 if (network == NULL)
1871 connman_network_set_blob(network, "WiFi.SSID",
1872 (unsigned char *) ssid, ssid_len);
1874 connman_network_set_string(network, "WiFi.Mode", mode);
1875 connman_network_set_string(network, "WiFi.Security", security);
1877 name = g_try_malloc0(ssid_len + 1);
1879 connman_network_unref(network);
1883 for (i = 0; i < ssid_len; i++) {
1884 if (g_ascii_isprint(ssid[i]))
1890 connman_network_set_name(network, name);
1894 index = connman_device_get_index(device);
1895 connman_network_set_index(network, index);
1897 connman_network_set_protocol(network, CONNMAN_NETWORK_PROTOCOL_IP);
1899 if (connman_device_add_network(device, network) < 0) {
1900 connman_network_unref(network);
1904 connman_network_set_available(network, TRUE);
1909 int __connman_service_create_and_connect(DBusMessage *msg)
1911 struct connman_service *service;
1912 struct connman_network *network;
1913 struct connman_device *device;
1914 DBusMessageIter iter, array;
1915 const char *mode = "managed", *security = "none";
1916 const char *type = NULL, *ssid = NULL, *passphrase = NULL;
1917 unsigned int ssid_len = 0;
1920 gboolean created = FALSE;
1923 dbus_message_iter_init(msg, &iter);
1924 dbus_message_iter_recurse(&iter, &array);
1926 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
1927 DBusMessageIter entry, value;
1930 dbus_message_iter_recurse(&array, &entry);
1931 dbus_message_iter_get_basic(&entry, &key);
1933 dbus_message_iter_next(&entry);
1934 dbus_message_iter_recurse(&entry, &value);
1936 switch (dbus_message_iter_get_arg_type(&value)) {
1937 case DBUS_TYPE_STRING:
1938 if (g_str_equal(key, "Type") == TRUE)
1939 dbus_message_iter_get_basic(&value, &type);
1940 else if (g_str_equal(key, "WiFi.Mode") == TRUE ||
1941 g_str_equal(key, "Mode") == TRUE)
1942 dbus_message_iter_get_basic(&value, &mode);
1943 else if (g_str_equal(key, "WiFi.Security") == TRUE ||
1944 g_str_equal(key, "Security") == TRUE)
1945 dbus_message_iter_get_basic(&value, &security);
1946 else if (g_str_equal(key, "WiFi.Passphrase") == TRUE ||
1947 g_str_equal(key, "Passphrase") == TRUE)
1948 dbus_message_iter_get_basic(&value, &passphrase);
1949 else if (g_str_equal(key, "WiFi.SSID") == TRUE ||
1950 g_str_equal(key, "SSID") == TRUE)
1951 dbus_message_iter_get_basic(&value, &ssid);
1954 dbus_message_iter_next(&array);
1960 if (g_strcmp0(type, "wifi") != 0 || g_strcmp0(mode, "managed") != 0)
1966 ssid_len = strlen(ssid);
1970 if (g_strcmp0(security, "none") != 0 &&
1971 g_strcmp0(security, "wep") != 0 &&
1972 g_strcmp0(security, "psk") != 0 &&
1973 g_strcmp0(security, "wpa") != 0 &&
1974 g_strcmp0(security, "rsn") != 0 &&
1975 g_strcmp0(security, "ieee8021x") != 0)
1978 device = __connman_element_find_device(CONNMAN_DEVICE_TYPE_WIFI);
1982 ident = __connman_device_get_ident(device);
1986 group = connman_wifi_build_group_name((unsigned char *) ssid,
1987 ssid_len, mode, security);
1991 name = g_strdup_printf("%s_%s_%s", type, ident, group);
1993 service = __connman_service_lookup(name);
1995 if (service != NULL)
1998 network = create_hidden_wifi(device, ssid, mode, security);
1999 if (network != NULL) {
2000 connman_network_set_group(network, group);
2004 service = __connman_service_lookup(name);
2010 if (service == NULL) {
2015 set_reconnect_state(service, FALSE);
2017 __connman_device_disconnect(device);
2019 if (passphrase != NULL) {
2020 g_free(service->passphrase);
2021 service->passphrase = g_strdup(passphrase);
2024 service->userconnect = TRUE;
2026 err = __connman_service_connect(service);
2027 if (err < 0 && err != -EINPROGRESS)
2030 g_dbus_send_reply(connection, msg,
2031 DBUS_TYPE_OBJECT_PATH, &service->path,
2037 if (service != NULL && created == TRUE) {
2038 struct connman_network *network = service->network;
2040 if (network != NULL) {
2041 connman_network_set_available(network, FALSE);
2042 __connman_device_cleanup_networks(device);
2044 __connman_service_put(service);
2051 * __connman_service_get:
2052 * @identifier: service identifier
2054 * Look up a service by identifier or create a new one if not found
2056 static struct connman_service *__connman_service_get(const char *identifier)
2058 struct connman_service *service;
2059 GSequenceIter *iter;
2061 iter = g_hash_table_lookup(service_hash, identifier);
2063 service = g_sequence_get(iter);
2064 if (service != NULL)
2065 g_atomic_int_inc(&service->refcount);
2069 service = connman_service_create();
2070 if (service == NULL)
2073 DBG("service %p", service);
2075 service->identifier = g_strdup(identifier);
2077 service->profile = g_strdup(__connman_profile_active_ident());
2079 iter = g_sequence_insert_sorted(service_list, service,
2080 service_compare, NULL);
2082 g_hash_table_insert(service_hash, service->identifier, iter);
2087 static int service_register(struct connman_service *service)
2089 const char *path = __connman_profile_active_path();
2090 GSequenceIter *iter;
2092 DBG("service %p", service);
2094 if (service->path != NULL)
2097 service->path = g_strdup_printf("%s/%s", path, service->identifier);
2099 DBG("path %s", service->path);
2101 __connman_config_provision_service(service);
2103 __connman_storage_load_service(service);
2105 g_dbus_register_interface(connection, service->path,
2106 CONNMAN_SERVICE_INTERFACE,
2107 service_methods, service_signals,
2108 NULL, service, NULL);
2110 iter = g_hash_table_lookup(service_hash, service->identifier);
2112 g_sequence_sort_changed(iter, service_compare, NULL);
2114 __connman_profile_changed(TRUE);
2119 static void service_up(struct connman_ipconfig *ipconfig)
2121 connman_info("%s up", connman_ipconfig_get_ifname(ipconfig));
2124 static void service_down(struct connman_ipconfig *ipconfig)
2126 connman_info("%s down", connman_ipconfig_get_ifname(ipconfig));
2129 static void service_lower_up(struct connman_ipconfig *ipconfig)
2131 connman_info("%s lower up", connman_ipconfig_get_ifname(ipconfig));
2134 static void service_lower_down(struct connman_ipconfig *ipconfig)
2136 connman_info("%s lower down", connman_ipconfig_get_ifname(ipconfig));
2139 static void service_ip_bound(struct connman_ipconfig *ipconfig)
2141 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
2143 connman_info("%s ip bound", connman_ipconfig_get_ifname(ipconfig));
2145 settings_changed(service);
2148 static void service_ip_release(struct connman_ipconfig *ipconfig)
2150 struct connman_service *service = connman_ipconfig_get_data(ipconfig);
2152 connman_info("%s ip release", connman_ipconfig_get_ifname(ipconfig));
2154 settings_changed(service);
2157 static const struct connman_ipconfig_ops service_ops = {
2159 .down = service_down,
2160 .lower_up = service_lower_up,
2161 .lower_down = service_lower_down,
2162 .ip_bound = service_ip_bound,
2163 .ip_release = service_ip_release,
2166 static void setup_ipconfig(struct connman_service *service, int index)
2171 service->ipconfig = connman_ipconfig_create(index);
2172 if (service->ipconfig == NULL)
2175 connman_ipconfig_set_method(service->ipconfig,
2176 CONNMAN_IPCONFIG_METHOD_DHCP);
2178 connman_ipconfig_set_data(service->ipconfig, service);
2180 connman_ipconfig_set_ops(service->ipconfig, &service_ops);
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);