5 * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
6 * Copyright (C) 2011 BWM CarIT GmbH. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <connman/session.h>
35 static DBusConnection *connection;
36 static GHashTable *session_hash;
37 static connman_bool_t sessionmode;
38 static struct session_info *ecall_info;
39 static struct connman_session_config *session_config;
41 enum connman_session_trigger {
42 CONNMAN_SESSION_TRIGGER_UNKNOWN = 0,
43 CONNMAN_SESSION_TRIGGER_SETTING = 1,
44 CONNMAN_SESSION_TRIGGER_CONNECT = 2,
45 CONNMAN_SESSION_TRIGGER_DISCONNECT = 3,
46 CONNMAN_SESSION_TRIGGER_SERVICE = 4,
47 CONNMAN_SESSION_TRIGGER_ECALL = 5,
50 enum connman_session_reason {
51 CONNMAN_SESSION_REASON_UNKNOWN = 0,
52 CONNMAN_SESSION_REASON_CONNECT = 1,
53 CONNMAN_SESSION_REASON_DISCONNECT = 2,
54 CONNMAN_SESSION_REASON_FREE_RIDE = 3,
57 enum connman_session_state {
58 CONNMAN_SESSION_STATE_DISCONNECTED = 0,
59 CONNMAN_SESSION_STATE_CONNECTED = 1,
60 CONNMAN_SESSION_STATE_ONLINE = 2,
63 enum connman_session_type {
64 CONNMAN_SESSION_TYPE_ANY = 0,
65 CONNMAN_SESSION_TYPE_LOCAL = 1,
66 CONNMAN_SESSION_TYPE_INTERNET = 2,
69 enum connman_session_roaming_policy {
70 CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN = 0,
71 CONNMAN_SESSION_ROAMING_POLICY_DEFAULT = 1,
72 CONNMAN_SESSION_ROAMING_POLICY_ALWAYS = 2,
73 CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN = 3,
74 CONNMAN_SESSION_ROAMING_POLICY_NATIONAL = 4,
75 CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL = 5,
78 struct service_entry {
79 /* track why this service was selected */
80 enum connman_session_reason reason;
81 enum connman_service_state state;
83 struct connman_service *service;
86 GSList *pending_timeouts;
90 enum connman_session_state state;
91 enum connman_session_type type;
92 connman_bool_t priority;
93 GSList *allowed_bearers;
94 connman_bool_t avoid_handover;
96 enum connman_session_roaming_policy roaming_policy;
98 struct service_entry *entry;
99 enum connman_session_reason reason;
102 struct connman_session {
108 connman_bool_t append_all;
109 struct session_info *info;
110 struct session_info *info_last;
112 GSequence *service_list;
113 GHashTable *service_hash;
118 connman_bool_t match_all;
119 enum connman_service_type service_type;
122 static const char *trigger2string(enum connman_session_trigger trigger)
125 case CONNMAN_SESSION_TRIGGER_UNKNOWN:
127 case CONNMAN_SESSION_TRIGGER_SETTING:
129 case CONNMAN_SESSION_TRIGGER_CONNECT:
131 case CONNMAN_SESSION_TRIGGER_DISCONNECT:
133 case CONNMAN_SESSION_TRIGGER_SERVICE:
135 case CONNMAN_SESSION_TRIGGER_ECALL:
142 static const char *reason2string(enum connman_session_reason reason)
145 case CONNMAN_SESSION_REASON_UNKNOWN:
147 case CONNMAN_SESSION_REASON_CONNECT:
149 case CONNMAN_SESSION_REASON_DISCONNECT:
151 case CONNMAN_SESSION_REASON_FREE_RIDE:
158 static const char *state2string(enum connman_session_state state)
161 case CONNMAN_SESSION_STATE_DISCONNECTED:
162 return "disconnected";
163 case CONNMAN_SESSION_STATE_CONNECTED:
165 case CONNMAN_SESSION_STATE_ONLINE:
172 static const char *type2string(enum connman_session_type type)
175 case CONNMAN_SESSION_TYPE_ANY:
177 case CONNMAN_SESSION_TYPE_LOCAL:
179 case CONNMAN_SESSION_TYPE_INTERNET:
186 static enum connman_session_type string2type(const char *type)
188 if (g_strcmp0(type, "local") == 0)
189 return CONNMAN_SESSION_TYPE_LOCAL;
190 else if (g_strcmp0(type, "internet") == 0)
191 return CONNMAN_SESSION_TYPE_INTERNET;
193 return CONNMAN_SESSION_TYPE_ANY;
196 static const char *roamingpolicy2string(enum connman_session_roaming_policy policy)
199 case CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN:
201 case CONNMAN_SESSION_ROAMING_POLICY_DEFAULT:
203 case CONNMAN_SESSION_ROAMING_POLICY_ALWAYS:
205 case CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN:
207 case CONNMAN_SESSION_ROAMING_POLICY_NATIONAL:
209 case CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL:
210 return "international";
216 static enum connman_session_roaming_policy string2roamingpolicy(const char *policy)
218 if (g_strcmp0(policy, "default") == 0)
219 return CONNMAN_SESSION_ROAMING_POLICY_DEFAULT;
220 else if (g_strcmp0(policy, "always") == 0)
221 return CONNMAN_SESSION_ROAMING_POLICY_ALWAYS;
222 else if (g_strcmp0(policy, "forbidden") == 0)
223 return CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN;
224 else if (g_strcmp0(policy, "national") == 0)
225 return CONNMAN_SESSION_ROAMING_POLICY_NATIONAL;
226 else if (g_strcmp0(policy, "international") == 0)
227 return CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL;
229 return CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN;
232 static enum connman_service_type bearer2service(const char *bearer)
235 return CONNMAN_SERVICE_TYPE_UNKNOWN;
237 if (g_strcmp0(bearer, "ethernet") == 0)
238 return CONNMAN_SERVICE_TYPE_ETHERNET;
239 else if (g_strcmp0(bearer, "wifi") == 0)
240 return CONNMAN_SERVICE_TYPE_WIFI;
241 else if (g_strcmp0(bearer, "wimax") == 0)
242 return CONNMAN_SERVICE_TYPE_WIMAX;
243 else if (g_strcmp0(bearer, "bluetooth") == 0)
244 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
245 else if (g_strcmp0(bearer, "cellular") == 0)
246 return CONNMAN_SERVICE_TYPE_CELLULAR;
247 else if (g_strcmp0(bearer, "vpn") == 0)
248 return CONNMAN_SERVICE_TYPE_VPN;
250 return CONNMAN_SERVICE_TYPE_UNKNOWN;
253 static char *service2bearer(enum connman_service_type type)
256 case CONNMAN_SERVICE_TYPE_ETHERNET:
258 case CONNMAN_SERVICE_TYPE_WIFI:
260 case CONNMAN_SERVICE_TYPE_WIMAX:
262 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
264 case CONNMAN_SERVICE_TYPE_CELLULAR:
266 case CONNMAN_SERVICE_TYPE_VPN:
268 case CONNMAN_SERVICE_TYPE_UNKNOWN:
269 case CONNMAN_SERVICE_TYPE_SYSTEM:
270 case CONNMAN_SERVICE_TYPE_GPS:
271 case CONNMAN_SERVICE_TYPE_GADGET:
278 static int config_get_bool(const char *id, const char *key, connman_bool_t *val)
280 if (session_config == NULL) {
285 return (*session_config->get_bool)(id, key, val);
288 static void cleanup_bearer_info(gpointer data, gpointer user_data)
290 struct bearer_info *info = data;
296 static GSList *session_parse_allowed_bearers(DBusMessageIter *iter)
298 struct bearer_info *info;
299 DBusMessageIter array;
302 dbus_message_iter_recurse(iter, &array);
304 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
307 dbus_message_iter_get_basic(&array, &bearer);
309 info = g_try_new0(struct bearer_info, 1);
311 g_slist_foreach(list, cleanup_bearer_info, NULL);
317 info->name = g_strdup(bearer);
318 info->service_type = bearer2service(info->name);
320 if (info->service_type == CONNMAN_SERVICE_TYPE_UNKNOWN &&
321 g_strcmp0(info->name, "*") == 0) {
322 info->match_all = TRUE;
324 info->match_all = FALSE;
327 list = g_slist_append(list, info);
329 dbus_message_iter_next(&array);
335 static GSList *session_allowed_bearers_any(void)
337 struct bearer_info *info;
340 info = g_try_new0(struct bearer_info, 1);
347 info->name = g_strdup("");
348 info->match_all = TRUE;
349 info->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
351 list = g_slist_append(list, info);
356 static void append_allowed_bearers(DBusMessageIter *iter, void *user_data)
358 struct session_info *info = user_data;
361 for (list = info->allowed_bearers;
362 list != NULL; list = list->next) {
363 struct bearer_info *bearer_info = list->data;
365 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
370 static void append_ipconfig_ipv4(DBusMessageIter *iter, void *user_data)
372 struct connman_service *service = user_data;
373 struct connman_ipconfig *ipconfig_ipv4;
378 if (__connman_service_is_connected_state(service,
379 CONNMAN_IPCONFIG_TYPE_IPV4) == FALSE) {
383 ipconfig_ipv4 = __connman_service_get_ip4config(service);
384 if (ipconfig_ipv4 == NULL)
387 __connman_ipconfig_append_ipv4(ipconfig_ipv4, iter);
390 static void append_ipconfig_ipv6(DBusMessageIter *iter, void *user_data)
392 struct connman_service *service = user_data;
393 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
398 if (__connman_service_is_connected_state(service,
399 CONNMAN_IPCONFIG_TYPE_IPV6) == FALSE) {
403 ipconfig_ipv4 = __connman_service_get_ip4config(service);
404 ipconfig_ipv6 = __connman_service_get_ip6config(service);
405 if (ipconfig_ipv6 == NULL)
408 __connman_ipconfig_append_ipv6(ipconfig_ipv6, iter, ipconfig_ipv4);
411 static void append_notify(DBusMessageIter *dict,
412 struct connman_session *session)
414 struct session_info *info = session->info;
415 struct session_info *info_last = session->info_last;
417 struct connman_service *service;
418 const char *name, *ifname, *bearer;
420 if (session->append_all == TRUE ||
421 info->state != info_last->state) {
422 const char *state = state2string(info->state);
424 connman_dbus_dict_append_basic(dict, "State",
427 info_last->state = info->state;
430 if (session->append_all == TRUE ||
431 info->entry != info_last->entry) {
432 if (info->entry == NULL) {
438 name = info->entry->name;
439 ifname = info->entry->ifname;
440 service = info->entry->service;
441 bearer = info->entry->bearer;
444 connman_dbus_dict_append_basic(dict, "Name",
448 connman_dbus_dict_append_dict(dict, "IPv4",
449 append_ipconfig_ipv4,
452 connman_dbus_dict_append_dict(dict, "IPv6",
453 append_ipconfig_ipv6,
456 connman_dbus_dict_append_basic(dict, "Interface",
460 connman_dbus_dict_append_basic(dict, "Bearer",
464 info_last->entry = info->entry;
467 if (session->append_all == TRUE || info->type != info_last->type) {
468 const char *type = type2string(info->type);
470 connman_dbus_dict_append_basic(dict, "ConnectionType",
473 info_last->type = info->type;
476 if (session->append_all == TRUE ||
477 info->allowed_bearers != info_last->allowed_bearers) {
478 connman_dbus_dict_append_array(dict, "AllowedBearers",
480 append_allowed_bearers,
482 info_last->allowed_bearers = info->allowed_bearers;
485 if (session->append_all == TRUE ||
486 info->avoid_handover != info_last->avoid_handover) {
487 connman_dbus_dict_append_basic(dict, "AvoidHandover",
489 &info->avoid_handover);
490 info_last->avoid_handover = info->avoid_handover;
493 if (session->append_all == TRUE ||
494 info->ecall != info_last->ecall) {
495 connman_dbus_dict_append_basic(dict, "EmergencyCall",
498 info_last->ecall = info->ecall;
501 if (session->append_all == TRUE ||
502 info->roaming_policy != info_last->roaming_policy) {
503 policy = roamingpolicy2string(info->roaming_policy);
504 connman_dbus_dict_append_basic(dict, "RoamingPolicy",
507 info_last->roaming_policy = info->roaming_policy;
510 session->append_all = FALSE;
513 static connman_bool_t is_type_matching_state(enum connman_session_state *state,
514 enum connman_session_type type)
517 case CONNMAN_SESSION_TYPE_ANY:
519 case CONNMAN_SESSION_TYPE_LOCAL:
520 if (*state >= CONNMAN_SESSION_STATE_CONNECTED) {
521 *state = CONNMAN_SESSION_STATE_CONNECTED;
526 case CONNMAN_SESSION_TYPE_INTERNET:
527 if (*state == CONNMAN_SESSION_STATE_ONLINE)
535 static connman_bool_t compute_notifiable_changes(struct connman_session *session)
537 struct session_info *info_last = session->info_last;
538 struct session_info *info = session->info;
540 if (session->append_all == TRUE)
543 if (info->state != info_last->state)
546 if (info->entry != info_last->entry &&
547 info->state >= CONNMAN_SESSION_STATE_CONNECTED)
550 if (info->allowed_bearers != info_last->allowed_bearers ||
551 info->avoid_handover != info_last->avoid_handover ||
552 info->roaming_policy != info_last->roaming_policy ||
553 info->ecall != info_last->ecall ||
554 info->type != info_last->type)
560 static gboolean session_notify(gpointer user_data)
562 struct connman_session *session = user_data;
564 DBusMessageIter array, dict;
566 if (compute_notifiable_changes(session) == FALSE)
569 DBG("session %p owner %s notify_path %s", session,
570 session->owner, session->notify_path);
572 msg = dbus_message_new_method_call(session->owner, session->notify_path,
573 CONNMAN_NOTIFICATION_INTERFACE,
578 dbus_message_iter_init_append(msg, &array);
579 connman_dbus_dict_open(&array, &dict);
581 append_notify(&dict, session);
583 connman_dbus_dict_close(&array, &dict);
585 g_dbus_send_message(connection, msg);
590 static void ipconfig_ipv4_changed(struct connman_session *session)
592 struct session_info *info = session->info;
594 connman_dbus_setting_changed_dict(session->owner, session->notify_path,
595 "IPv4", append_ipconfig_ipv4,
596 info->entry->service);
599 static void ipconfig_ipv6_changed(struct connman_session *session)
601 struct session_info *info = session->info;
603 connman_dbus_setting_changed_dict(session->owner, session->notify_path,
604 "IPv6", append_ipconfig_ipv6,
605 info->entry->service);
608 static connman_bool_t service_type_match(struct connman_session *session,
609 struct connman_service *service)
611 struct session_info *info = session->info;
614 for (list = info->allowed_bearers;
615 list != NULL; list = list->next) {
616 struct bearer_info *bearer_info = list->data;
617 enum connman_service_type service_type;
619 if (bearer_info->match_all == TRUE)
622 service_type = connman_service_get_type(service);
623 if (bearer_info->service_type == service_type)
630 static connman_bool_t service_match(struct connman_session *session,
631 struct connman_service *service)
633 if (service_type_match(session, service) == FALSE)
639 static int service_type_weight(enum connman_service_type type)
642 * The session doesn't care which service
643 * to use. Nevertheless we have to sort them
644 * according their type. The ordering is
653 case CONNMAN_SERVICE_TYPE_ETHERNET:
655 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
657 case CONNMAN_SERVICE_TYPE_WIFI:
658 case CONNMAN_SERVICE_TYPE_WIMAX:
660 case CONNMAN_SERVICE_TYPE_CELLULAR:
662 case CONNMAN_SERVICE_TYPE_UNKNOWN:
663 case CONNMAN_SERVICE_TYPE_SYSTEM:
664 case CONNMAN_SERVICE_TYPE_GPS:
665 case CONNMAN_SERVICE_TYPE_VPN:
666 case CONNMAN_SERVICE_TYPE_GADGET:
673 static gint sort_allowed_bearers(struct connman_service *service_a,
674 struct connman_service *service_b,
675 struct connman_session *session)
677 struct session_info *info = session->info;
679 enum connman_service_type type_a, type_b;
680 int weight_a, weight_b;
682 type_a = connman_service_get_type(service_a);
683 type_b = connman_service_get_type(service_b);
685 for (list = info->allowed_bearers;
686 list != NULL; list = list->next) {
687 struct bearer_info *bearer_info = list->data;
689 if (bearer_info->match_all == TRUE) {
690 if (type_a != type_b) {
691 weight_a = service_type_weight(type_a);
692 weight_b = service_type_weight(type_b);
694 if (weight_a > weight_b)
697 if (weight_a < weight_b)
704 if (type_a == bearer_info->service_type &&
705 type_b == bearer_info->service_type) {
709 if (type_a == bearer_info->service_type &&
710 type_b != bearer_info->service_type) {
714 if (type_a != bearer_info->service_type &&
715 type_b == bearer_info->service_type) {
723 static gint sort_services(gconstpointer a, gconstpointer b, gpointer user_data)
725 struct service_entry *entry_a = (void *)a;
726 struct service_entry *entry_b = (void *)b;
727 struct connman_session *session = user_data;
729 return sort_allowed_bearers(entry_a->service, entry_b->service,
733 static void cleanup_session(gpointer user_data)
735 struct connman_session *session = user_data;
736 struct session_info *info = session->info;
738 DBG("remove %s", session->session_path);
740 g_hash_table_destroy(session->service_hash);
741 g_sequence_free(session->service_list);
743 if (info->entry != NULL &&
744 info->entry->reason == CONNMAN_SESSION_REASON_CONNECT) {
745 __connman_service_disconnect(info->entry->service);
748 g_slist_foreach(info->allowed_bearers, cleanup_bearer_info, NULL);
749 g_slist_free(info->allowed_bearers);
751 g_free(session->owner);
752 g_free(session->session_path);
753 g_free(session->notify_path);
754 g_free(session->info);
755 g_free(session->info_last);
760 static enum connman_session_state service_to_session_state(enum connman_service_state state)
763 case CONNMAN_SERVICE_STATE_UNKNOWN:
764 case CONNMAN_SERVICE_STATE_IDLE:
765 case CONNMAN_SERVICE_STATE_ASSOCIATION:
766 case CONNMAN_SERVICE_STATE_CONFIGURATION:
767 case CONNMAN_SERVICE_STATE_DISCONNECT:
768 case CONNMAN_SERVICE_STATE_FAILURE:
770 case CONNMAN_SERVICE_STATE_READY:
771 return CONNMAN_SESSION_STATE_CONNECTED;
772 case CONNMAN_SERVICE_STATE_ONLINE:
773 return CONNMAN_SESSION_STATE_ONLINE;
776 return CONNMAN_SESSION_STATE_DISCONNECTED;
779 static connman_bool_t is_connected(enum connman_service_state state)
782 case CONNMAN_SERVICE_STATE_UNKNOWN:
783 case CONNMAN_SERVICE_STATE_IDLE:
784 case CONNMAN_SERVICE_STATE_ASSOCIATION:
785 case CONNMAN_SERVICE_STATE_CONFIGURATION:
786 case CONNMAN_SERVICE_STATE_DISCONNECT:
787 case CONNMAN_SERVICE_STATE_FAILURE:
789 case CONNMAN_SERVICE_STATE_READY:
790 case CONNMAN_SERVICE_STATE_ONLINE:
797 static connman_bool_t is_connecting(enum connman_service_state state)
800 case CONNMAN_SERVICE_STATE_UNKNOWN:
801 case CONNMAN_SERVICE_STATE_IDLE:
803 case CONNMAN_SERVICE_STATE_ASSOCIATION:
804 case CONNMAN_SERVICE_STATE_CONFIGURATION:
806 case CONNMAN_SERVICE_STATE_DISCONNECT:
807 case CONNMAN_SERVICE_STATE_FAILURE:
808 case CONNMAN_SERVICE_STATE_READY:
809 case CONNMAN_SERVICE_STATE_ONLINE:
816 static connman_bool_t explicit_connect(enum connman_session_reason reason)
819 case CONNMAN_SESSION_REASON_UNKNOWN:
820 case CONNMAN_SESSION_REASON_FREE_RIDE:
821 case CONNMAN_SESSION_REASON_DISCONNECT:
823 case CONNMAN_SESSION_REASON_CONNECT:
830 static connman_bool_t explicit_disconnect(struct session_info *info)
832 if (info->entry == NULL)
835 DBG("reason %s service %p state %d",
836 reason2string(info->entry->reason),
837 info->entry->service, info->entry->state);
839 if (info->entry->reason == CONNMAN_SESSION_REASON_UNKNOWN)
842 if (explicit_connect(info->entry->reason) == FALSE)
845 if (__connman_service_session_dec(info->entry->service) == FALSE)
848 if (ecall_info != NULL && ecall_info != info)
854 struct pending_data {
855 unsigned int timeout;
856 struct service_entry *entry;
857 gboolean (*cb)(gpointer);
860 static void pending_timeout_free(gpointer data, gpointer user_data)
862 struct pending_data *pending = data;
864 DBG("pending %p timeout %d", pending, pending->timeout);
865 g_source_remove(pending->timeout);
869 static void pending_timeout_remove_all(struct service_entry *entry)
873 g_slist_foreach(entry->pending_timeouts, pending_timeout_free, NULL);
874 g_slist_free(entry->pending_timeouts);
875 entry->pending_timeouts = NULL;
878 static gboolean pending_timeout_cb(gpointer data)
880 struct pending_data *pending = data;
881 struct service_entry *entry = pending->entry;
884 DBG("pending %p timeout %d", pending, pending->timeout);
886 ret = pending->cb(pending->entry);
888 entry->pending_timeouts =
889 g_slist_remove(entry->pending_timeouts,
896 static connman_bool_t pending_timeout_add(unsigned int seconds,
897 gboolean (*cb)(gpointer),
898 struct service_entry *entry)
900 struct pending_data *pending = g_try_new0(struct pending_data, 1);
902 if (pending == NULL || cb == NULL || entry == NULL) {
908 pending->entry = entry;
909 pending->timeout = g_timeout_add_seconds(seconds, pending_timeout_cb,
911 entry->pending_timeouts = g_slist_prepend(entry->pending_timeouts,
914 DBG("pending %p entry %p timeout id %d", pending, entry,
920 static gboolean call_disconnect(gpointer user_data)
922 struct service_entry *entry = user_data;
923 struct connman_service *service = entry->service;
926 * TODO: We should mark this entry as pending work. In case
927 * disconnect fails we just unassign this session from the
928 * service and can't do anything later on it
930 DBG("disconnect service %p", service);
931 __connman_service_disconnect(service);
936 static gboolean call_connect(gpointer user_data)
938 struct service_entry *entry = user_data;
939 struct connman_service *service = entry->service;
941 DBG("connect service %p", service);
942 __connman_service_connect(service);
947 static void deselect_service(struct session_info *info)
949 struct service_entry *entry;
950 connman_bool_t disconnect, connected;
954 if (info->entry == NULL)
957 disconnect = explicit_disconnect(info);
959 connected = is_connecting(info->entry->state) == TRUE ||
960 is_connected(info->entry->state) == TRUE;
962 info->state = CONNMAN_SESSION_STATE_DISCONNECTED;
963 info->entry->reason = CONNMAN_SESSION_REASON_UNKNOWN;
968 DBG("disconnect %d connected %d", disconnect, connected);
970 if (disconnect == TRUE && connected == TRUE)
971 pending_timeout_add(0, call_disconnect, entry);
974 static void deselect_and_disconnect(struct connman_session *session,
975 enum connman_session_reason reason)
977 struct session_info *info = session->info;
979 deselect_service(info);
981 info->reason = reason;
984 static void select_connected_service(struct session_info *info,
985 struct service_entry *entry)
987 enum connman_session_state state;
989 state = service_to_session_state(entry->state);
990 if (is_type_matching_state(&state, info->type) == FALSE)
996 info->entry->reason = info->reason;
998 if (explicit_connect(info->reason) == FALSE)
1001 __connman_service_session_inc(info->entry->service);
1004 static void select_offline_service(struct session_info *info,
1005 struct service_entry *entry)
1007 if (explicit_connect(info->reason) == FALSE)
1010 info->state = service_to_session_state(entry->state);
1012 info->entry = entry;
1013 info->entry->reason = info->reason;
1015 __connman_service_session_inc(info->entry->service);
1016 pending_timeout_add(0, call_connect, entry);
1019 static void select_service(struct session_info *info,
1020 struct service_entry *entry)
1022 DBG("service %p", entry->service);
1024 if (is_connected(entry->state) == TRUE)
1025 select_connected_service(info, entry);
1027 select_offline_service(info, entry);
1030 static void select_and_connect(struct connman_session *session,
1031 enum connman_session_reason reason)
1033 struct session_info *info = session->info;
1034 struct service_entry *entry = NULL;
1035 GSequenceIter *iter;
1037 DBG("session %p reason %s", session, reason2string(reason));
1039 info->reason = reason;
1041 iter = g_sequence_get_begin_iter(session->service_list);
1043 while (g_sequence_iter_is_end(iter) == FALSE) {
1044 entry = g_sequence_get(iter);
1046 switch (entry->state) {
1047 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1048 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1049 case CONNMAN_SERVICE_STATE_READY:
1050 case CONNMAN_SERVICE_STATE_ONLINE:
1051 case CONNMAN_SERVICE_STATE_IDLE:
1052 case CONNMAN_SERVICE_STATE_DISCONNECT:
1053 select_service(info, entry);
1055 case CONNMAN_SERVICE_STATE_UNKNOWN:
1056 case CONNMAN_SERVICE_STATE_FAILURE:
1060 iter = g_sequence_iter_next(iter);
1064 static struct service_entry *create_service_entry(struct connman_service *service,
1066 enum connman_service_state state)
1068 struct service_entry *entry;
1069 enum connman_service_type type;
1072 entry = g_try_new0(struct service_entry, 1);
1076 entry->reason = CONNMAN_SESSION_REASON_UNKNOWN;
1077 entry->state = state;
1082 entry->service = service;
1084 idx = __connman_service_get_index(entry->service);
1085 entry->ifname = connman_inet_ifname(idx);
1086 if (entry->ifname == NULL)
1087 entry->ifname = g_strdup("");
1089 type = connman_service_get_type(entry->service);
1090 entry->bearer = service2bearer(type);
1095 static void destroy_service_entry(gpointer data)
1097 struct service_entry *entry = data;
1099 pending_timeout_remove_all(entry);
1100 g_free(entry->ifname);
1105 static void populate_service_list(struct connman_session *session)
1107 struct service_entry *entry;
1108 GSequenceIter *iter;
1110 session->service_hash =
1111 g_hash_table_new_full(g_direct_hash, g_direct_equal,
1113 session->service_list = __connman_service_get_list(session,
1115 create_service_entry,
1116 destroy_service_entry);
1118 g_sequence_sort(session->service_list, sort_services, session);
1120 iter = g_sequence_get_begin_iter(session->service_list);
1122 while (g_sequence_iter_is_end(iter) == FALSE) {
1123 entry = g_sequence_get(iter);
1125 DBG("service %p type %s name %s", entry->service,
1126 service2bearer(connman_service_get_type(entry->service)),
1129 g_hash_table_replace(session->service_hash,
1130 entry->service, iter);
1132 iter = g_sequence_iter_next(iter);
1136 static void session_changed(struct connman_session *session,
1137 enum connman_session_trigger trigger)
1139 struct session_info *info = session->info;
1140 struct session_info *info_last = session->info_last;
1141 GSequenceIter *service_iter = NULL, *service_iter_last = NULL;
1142 GSequence *service_list_last;
1143 GHashTable *service_hash_last;
1146 * TODO: This only a placeholder for the 'real' algorithm to
1147 * play a bit around. So we are going to improve it step by step.
1150 DBG("session %p trigger %s reason %s", session, trigger2string(trigger),
1151 reason2string(info->reason));
1153 if (info->entry != NULL) {
1154 enum connman_session_state state;
1156 state = service_to_session_state(info->entry->state);
1158 if (is_type_matching_state(&state, info->type) == TRUE)
1159 info->state = state;
1163 case CONNMAN_SESSION_TRIGGER_UNKNOWN:
1164 DBG("ignore session changed event");
1166 case CONNMAN_SESSION_TRIGGER_SETTING:
1167 if (info->allowed_bearers != info_last->allowed_bearers) {
1169 service_hash_last = session->service_hash;
1170 service_list_last = session->service_list;
1172 populate_service_list(session);
1174 if (info->entry != NULL) {
1175 service_iter_last = g_hash_table_lookup(
1177 info->entry->service);
1178 service_iter = g_hash_table_lookup(
1179 session->service_hash,
1180 info->entry->service);
1183 if (service_iter == NULL && service_iter_last != NULL) {
1185 * The currently selected service is
1186 * not part of this session anymore.
1188 deselect_and_disconnect(session, info->reason);
1191 g_hash_table_remove_all(service_hash_last);
1192 g_sequence_free(service_list_last);
1195 if (info->type != info_last->type) {
1196 if (info->state >= CONNMAN_SESSION_STATE_CONNECTED &&
1197 is_type_matching_state(&info->state,
1198 info->type) == FALSE)
1199 deselect_and_disconnect(session, info->reason);
1202 if (info->state == CONNMAN_SESSION_STATE_DISCONNECTED) {
1203 select_and_connect(session,
1204 CONNMAN_SESSION_REASON_FREE_RIDE);
1208 case CONNMAN_SESSION_TRIGGER_CONNECT:
1209 if (info->state >= CONNMAN_SESSION_STATE_CONNECTED) {
1210 if (info->entry->reason == CONNMAN_SESSION_REASON_CONNECT)
1212 info->entry->reason = CONNMAN_SESSION_REASON_CONNECT;
1213 __connman_service_session_inc(info->entry->service);
1217 if (info->entry != NULL &&
1218 is_connecting(info->entry->state) == TRUE) {
1222 select_and_connect(session,
1223 CONNMAN_SESSION_REASON_CONNECT);
1226 case CONNMAN_SESSION_TRIGGER_DISCONNECT:
1227 deselect_and_disconnect(session,
1228 CONNMAN_SESSION_REASON_DISCONNECT);
1231 case CONNMAN_SESSION_TRIGGER_SERVICE:
1232 if (info->entry != NULL &&
1233 (is_connecting(info->entry->state) == TRUE ||
1234 is_connected(info->entry->state) == TRUE)) {
1238 deselect_and_disconnect(session, info->reason);
1240 if (info->reason == CONNMAN_SESSION_REASON_FREE_RIDE) {
1241 select_and_connect(session, info->reason);
1245 case CONNMAN_SESSION_TRIGGER_ECALL:
1246 if (info->state == CONNMAN_SESSION_STATE_DISCONNECTED &&
1247 info->entry != NULL &&
1248 info->entry->service != NULL) {
1249 deselect_and_disconnect(session, info->reason);
1255 session_notify(session);
1258 static DBusMessage *connect_session(DBusConnection *conn,
1259 DBusMessage *msg, void *user_data)
1261 struct connman_session *session = user_data;
1262 struct session_info *info = session->info;
1264 DBG("session %p", session);
1266 if (ecall_info != NULL && ecall_info != info)
1267 return __connman_error_failed(msg, EBUSY);
1269 session_changed(session, CONNMAN_SESSION_TRIGGER_CONNECT);
1271 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1274 static DBusMessage *disconnect_session(DBusConnection *conn,
1275 DBusMessage *msg, void *user_data)
1277 struct connman_session *session = user_data;
1278 struct session_info *info = session->info;
1280 DBG("session %p", session);
1282 if (ecall_info != NULL && ecall_info != info)
1283 return __connman_error_failed(msg, EBUSY);
1285 session_changed(session, CONNMAN_SESSION_TRIGGER_DISCONNECT);
1287 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1290 static void update_ecall_sessions(struct connman_session *session)
1292 struct session_info *info = session->info;
1293 struct connman_session *session_iter;
1294 GHashTableIter iter;
1295 gpointer key, value;
1297 g_hash_table_iter_init(&iter, session_hash);
1299 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1300 session_iter = value;
1302 if (session_iter == session)
1305 session_iter->info->ecall = info->ecall;
1307 session_changed(session_iter, CONNMAN_SESSION_TRIGGER_ECALL);
1311 static void update_ecall(struct connman_session *session)
1313 struct session_info *info = session->info;
1314 struct session_info *info_last = session->info_last;
1316 DBG("session %p ecall_info %p ecall %d -> %d", session,
1317 ecall_info, info_last->ecall, info->ecall);
1319 if (ecall_info == NULL) {
1320 if (!(info_last->ecall == FALSE && info->ecall == TRUE))
1324 } else if (ecall_info == info) {
1325 if (!(info_last->ecall == TRUE && info->ecall == FALSE))
1333 update_ecall_sessions(session);
1338 /* not a valid transition */
1339 info->ecall = info_last->ecall;
1342 static DBusMessage *change_session(DBusConnection *conn,
1343 DBusMessage *msg, void *user_data)
1345 struct connman_session *session = user_data;
1346 struct session_info *info = session->info;
1347 DBusMessageIter iter, value;
1350 GSList *allowed_bearers;
1352 DBG("session %p", session);
1353 if (dbus_message_iter_init(msg, &iter) == FALSE)
1354 return __connman_error_invalid_arguments(msg);
1356 dbus_message_iter_get_basic(&iter, &name);
1357 dbus_message_iter_next(&iter);
1358 dbus_message_iter_recurse(&iter, &value);
1360 switch (dbus_message_iter_get_arg_type(&value)) {
1361 case DBUS_TYPE_ARRAY:
1362 if (g_str_equal(name, "AllowedBearers") == TRUE) {
1363 allowed_bearers = session_parse_allowed_bearers(&value);
1365 g_slist_foreach(info->allowed_bearers,
1366 cleanup_bearer_info, NULL);
1367 g_slist_free(info->allowed_bearers);
1369 if (allowed_bearers == NULL) {
1370 allowed_bearers = session_allowed_bearers_any();
1372 if (allowed_bearers == NULL)
1373 return __connman_error_failed(msg, ENOMEM);
1376 info->allowed_bearers = allowed_bearers;
1381 case DBUS_TYPE_BOOLEAN:
1382 if (g_str_equal(name, "AvoidHandover") == TRUE) {
1383 dbus_message_iter_get_basic(&value,
1384 &info->avoid_handover);
1385 } else if (g_str_equal(name, "EmergencyCall") == TRUE) {
1386 dbus_message_iter_get_basic(&value,
1389 update_ecall(session);
1394 case DBUS_TYPE_STRING:
1395 if (g_str_equal(name, "ConnectionType") == TRUE) {
1396 dbus_message_iter_get_basic(&value, &val);
1397 info->type = string2type(val);
1398 } else if (g_str_equal(name, "RoamingPolicy") == TRUE) {
1399 dbus_message_iter_get_basic(&value, &val);
1400 info->roaming_policy =
1401 string2roamingpolicy(val);
1410 session_changed(session, CONNMAN_SESSION_TRIGGER_SETTING);
1412 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1415 return __connman_error_invalid_arguments(msg);
1418 static void release_session(gpointer key, gpointer value, gpointer user_data)
1420 struct connman_session *session = value;
1421 DBusMessage *message;
1423 DBG("owner %s path %s", session->owner, session->notify_path);
1425 if (session->notify_watch > 0)
1426 g_dbus_remove_watch(connection, session->notify_watch);
1428 g_dbus_unregister_interface(connection, session->session_path,
1429 CONNMAN_SESSION_INTERFACE);
1431 message = dbus_message_new_method_call(session->owner,
1432 session->notify_path,
1433 CONNMAN_NOTIFICATION_INTERFACE,
1435 if (message == NULL)
1438 dbus_message_set_no_reply(message, TRUE);
1440 g_dbus_send_message(connection, message);
1443 static int session_disconnect(struct connman_session *session)
1445 DBG("session %p, %s", session, session->owner);
1447 if (session->notify_watch > 0)
1448 g_dbus_remove_watch(connection, session->notify_watch);
1450 g_dbus_unregister_interface(connection, session->session_path,
1451 CONNMAN_SESSION_INTERFACE);
1453 deselect_and_disconnect(session,
1454 CONNMAN_SESSION_REASON_DISCONNECT);
1456 g_hash_table_remove(session_hash, session->session_path);
1461 static void owner_disconnect(DBusConnection *conn, void *user_data)
1463 struct connman_session *session = user_data;
1465 DBG("session %p, %s died", session, session->owner);
1467 session_disconnect(session);
1470 static DBusMessage *destroy_session(DBusConnection *conn,
1471 DBusMessage *msg, void *user_data)
1473 struct connman_session *session = user_data;
1474 struct session_info *info = session->info;
1476 DBG("session %p", session);
1478 if (ecall_info != NULL && ecall_info != info)
1479 return __connman_error_failed(msg, EBUSY);
1481 session_disconnect(session);
1483 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1486 static const GDBusMethodTable session_methods[] = {
1487 { GDBUS_METHOD("Destroy", NULL, NULL, destroy_session) },
1488 { GDBUS_METHOD("Connect", NULL, NULL, connect_session) },
1489 { GDBUS_METHOD("Disconnect", NULL, NULL,
1490 disconnect_session ) },
1491 { GDBUS_METHOD("Change",
1492 GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
1493 NULL, change_session) },
1497 int __connman_session_create(DBusMessage *msg)
1499 const char *owner, *notify_path;
1500 char *session_path = NULL;
1501 DBusMessageIter iter, array;
1502 struct connman_session *session = NULL;
1503 struct session_info *info, *info_last;
1505 enum connman_session_type type = CONNMAN_SESSION_TYPE_ANY;
1506 connman_bool_t priority, avoid_handover = FALSE;
1507 connman_bool_t ecall = FALSE;
1508 enum connman_session_roaming_policy roaming_policy =
1509 CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN;
1510 GSList *allowed_bearers = NULL;
1513 owner = dbus_message_get_sender(msg);
1515 DBG("owner %s", owner);
1517 if (ecall_info != NULL) {
1519 * If there is an emergency call already going on,
1520 * ignore session creation attempt
1526 dbus_message_iter_init(msg, &iter);
1527 dbus_message_iter_recurse(&iter, &array);
1529 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
1530 DBusMessageIter entry, value;
1531 const char *key, *val;
1533 dbus_message_iter_recurse(&array, &entry);
1534 dbus_message_iter_get_basic(&entry, &key);
1536 dbus_message_iter_next(&entry);
1537 dbus_message_iter_recurse(&entry, &value);
1539 switch (dbus_message_iter_get_arg_type(&value)) {
1540 case DBUS_TYPE_ARRAY:
1541 if (g_str_equal(key, "AllowedBearers") == TRUE) {
1543 session_parse_allowed_bearers(&value);
1548 case DBUS_TYPE_BOOLEAN:
1549 if (g_str_equal(key, "AvoidHandover") == TRUE) {
1550 dbus_message_iter_get_basic(&value,
1552 } else if (g_str_equal(key, "EmergencyCall") == TRUE) {
1553 dbus_message_iter_get_basic(&value,
1559 case DBUS_TYPE_STRING:
1560 if (g_str_equal(key, "ConnectionType") == TRUE) {
1561 dbus_message_iter_get_basic(&value, &val);
1562 type = string2type(val);
1563 } else if (g_str_equal(key, "RoamingPolicy") == TRUE) {
1564 dbus_message_iter_get_basic(&value, &val);
1565 roaming_policy = string2roamingpolicy(val);
1570 dbus_message_iter_next(&array);
1573 dbus_message_iter_next(&iter);
1574 dbus_message_iter_get_basic(&iter, ¬ify_path);
1576 if (notify_path == NULL) {
1581 session_path = g_strdup_printf("/sessions%s", notify_path);
1582 if (session_path == NULL) {
1587 session = g_hash_table_lookup(session_hash, session_path);
1588 if (session != NULL) {
1594 session = g_try_new0(struct connman_session, 1);
1595 if (session == NULL) {
1600 session->info = g_try_new0(struct session_info, 1);
1601 if (session->info == NULL) {
1606 session->info_last = g_try_new0(struct session_info, 1);
1607 if (session->info_last == NULL) {
1612 info = session->info;
1613 info_last = session->info_last;
1615 config_get_bool(owner, "Priority", &priority);
1617 session->owner = g_strdup(owner);
1618 session->session_path = session_path;
1619 session->notify_path = g_strdup(notify_path);
1620 session->notify_watch =
1621 g_dbus_add_disconnect_watch(connection, session->owner,
1622 owner_disconnect, session, NULL);
1624 info->state = CONNMAN_SESSION_STATE_DISCONNECTED;
1626 info->priority = priority;
1627 info->avoid_handover = avoid_handover;
1628 info->ecall = ecall;
1629 info->roaming_policy = roaming_policy;
1632 if (allowed_bearers == NULL) {
1633 info->allowed_bearers =
1634 session_allowed_bearers_any();
1636 if (info->allowed_bearers == NULL) {
1641 info->allowed_bearers = allowed_bearers;
1644 g_hash_table_replace(session_hash, session->session_path, session);
1646 DBG("add %s", session->session_path);
1648 if (g_dbus_register_interface(connection, session->session_path,
1649 CONNMAN_SESSION_INTERFACE,
1650 session_methods, NULL,
1651 NULL, session, NULL) == FALSE) {
1652 connman_error("Failed to register %s", session->session_path);
1653 g_hash_table_remove(session_hash, session->session_path);
1660 g_dbus_send_reply(connection, msg,
1661 DBUS_TYPE_OBJECT_PATH, &session->session_path,
1665 populate_service_list(session);
1666 if (info->ecall == TRUE) {
1668 update_ecall_sessions(session);
1671 info_last->state = info->state;
1672 info_last->priority = info->priority;
1673 info_last->avoid_handover = info->avoid_handover;
1674 info_last->ecall = info->ecall;
1675 info_last->roaming_policy = info->roaming_policy;
1676 info_last->entry = info->entry;
1677 info_last->allowed_bearers = info->allowed_bearers;
1679 session->append_all = TRUE;
1681 session_changed(session, CONNMAN_SESSION_TRIGGER_SETTING);
1686 connman_error("Failed to create session");
1688 if (session != NULL) {
1689 if (session->info_last != NULL)
1690 g_free(session->info_last);
1691 if (session->info != NULL)
1692 g_free(session->info);
1696 g_free(session_path);
1698 g_slist_foreach(allowed_bearers, cleanup_bearer_info, NULL);
1699 g_slist_free(allowed_bearers);
1704 int __connman_session_destroy(DBusMessage *msg)
1706 const char *owner, *session_path;
1707 struct connman_session *session;
1709 owner = dbus_message_get_sender(msg);
1711 DBG("owner %s", owner);
1713 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &session_path,
1715 if (session_path == NULL)
1718 session = g_hash_table_lookup(session_hash, session_path);
1719 if (session == NULL)
1722 if (g_strcmp0(owner, session->owner) != 0)
1725 session_disconnect(session);
1730 connman_bool_t __connman_session_mode()
1735 void __connman_session_set_mode(connman_bool_t enable)
1737 DBG("enable %d", enable);
1739 if (sessionmode != enable) {
1740 sessionmode = enable;
1742 connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
1743 CONNMAN_MANAGER_INTERFACE, "SessionMode",
1744 DBUS_TYPE_BOOLEAN, &sessionmode);
1747 if (sessionmode == TRUE)
1748 __connman_service_disconnect_all();
1751 static void service_add(struct connman_service *service,
1754 GHashTableIter iter;
1755 GSequenceIter *iter_service_list;
1756 gpointer key, value;
1757 struct connman_session *session;
1758 struct service_entry *entry;
1760 DBG("service %p", service);
1762 g_hash_table_iter_init(&iter, session_hash);
1764 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1767 if (service_match(session, service) == FALSE)
1770 entry = create_service_entry(service, name,
1771 CONNMAN_SERVICE_STATE_IDLE);
1776 g_sequence_insert_sorted(session->service_list,
1777 entry, sort_services,
1780 g_hash_table_replace(session->service_hash, service,
1783 session_changed(session, CONNMAN_SESSION_TRIGGER_SERVICE);
1787 static void service_remove(struct connman_service *service)
1790 GHashTableIter iter;
1791 gpointer key, value;
1792 struct connman_session *session;
1793 struct session_info *info;
1795 DBG("service %p", service);
1797 g_hash_table_iter_init(&iter, session_hash);
1799 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1800 GSequenceIter *seq_iter;
1802 info = session->info;
1804 seq_iter = g_hash_table_lookup(session->service_hash, service);
1805 if (seq_iter == NULL)
1808 g_sequence_remove(seq_iter);
1810 if (info->entry != NULL && info->entry->service == service)
1812 session_changed(session, CONNMAN_SESSION_TRIGGER_SERVICE);
1816 static void service_state_changed(struct connman_service *service,
1817 enum connman_service_state state)
1819 GHashTableIter iter;
1820 gpointer key, value;
1822 DBG("service %p state %d", service, state);
1824 g_hash_table_iter_init(&iter, session_hash);
1826 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1827 struct connman_session *session = value;
1828 GSequenceIter *service_iter;
1830 service_iter = g_hash_table_lookup(session->service_hash, service);
1831 if (service_iter != NULL) {
1832 struct service_entry *entry;
1834 entry = g_sequence_get(service_iter);
1835 entry->state = state;
1838 session_changed(session,
1839 CONNMAN_SESSION_TRIGGER_SERVICE);
1843 static void ipconfig_changed(struct connman_service *service,
1844 struct connman_ipconfig *ipconfig)
1846 GHashTableIter iter;
1847 gpointer key, value;
1848 struct connman_session *session;
1849 struct session_info *info;
1850 enum connman_ipconfig_type type;
1852 DBG("service %p ipconfig %p", service, ipconfig);
1854 type = __connman_ipconfig_get_config_type(ipconfig);
1856 g_hash_table_iter_init(&iter, session_hash);
1858 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1860 info = session->info;
1862 if (info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
1865 if (info->entry != NULL && info->entry->service == service) {
1866 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1867 ipconfig_ipv4_changed(session);
1868 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1869 ipconfig_ipv6_changed(session);
1874 static struct connman_notifier session_notifier = {
1876 .service_add = service_add,
1877 .service_remove = service_remove,
1878 .service_state_changed = service_state_changed,
1879 .ipconfig_changed = ipconfig_changed,
1882 static struct connman_session *session_lookup_by_id(const char *id)
1884 struct connman_session *session;
1885 GHashTableIter iter;
1886 gpointer key, value;
1890 g_hash_table_iter_init(&iter, session_hash);
1892 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1895 if (g_strcmp0(session->owner, id) == FALSE)
1901 DBG("No session found by id %s", id);
1906 int connman_session_update_bool(const char *id, const char *key,
1909 struct connman_session *session;
1910 struct session_info *info;
1912 session = session_lookup_by_id(id);
1913 if (session == NULL)
1916 info = session->info;
1920 DBG("%s %d", key, val);
1925 int connman_session_update_string(const char *id, const char *key,
1928 struct connman_session *session;
1929 struct session_info *info;
1931 session = session_lookup_by_id(id);
1932 if (session == NULL)
1935 info = session->info;
1939 DBG("%s %s", key, val);
1944 int connman_session_config_register(struct connman_session_config *config)
1946 DBG("name %s", config->name);
1948 if (session_config != NULL) {
1949 connman_warn("A session configuration plugin '%s' is "
1950 "already registerd. Skipping registration "
1952 session_config->name, config->name);
1956 session_config = config;
1961 void connman_session_config_unregister(struct connman_session_config *config)
1963 DBG("name %s", config->name);
1965 if (config != session_config) {
1966 connman_warn("Trying to unregister session configuration "
1967 "plugin '%s'", config->name);
1971 session_config = NULL;
1974 int __connman_session_init(void)
1980 connection = connman_dbus_get_connection();
1981 if (connection == NULL)
1984 err = connman_notifier_register(&session_notifier);
1986 dbus_connection_unref(connection);
1990 session_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1991 NULL, cleanup_session);
1993 sessionmode = FALSE;
1997 void __connman_session_cleanup(void)
2001 if (connection == NULL)
2004 connman_notifier_unregister(&session_notifier);
2006 g_hash_table_foreach(session_hash, release_session, NULL);
2007 g_hash_table_destroy(session_hash);
2008 session_hash = NULL;
2010 dbus_connection_unref(connection);