5 * Copyright (C) 2007-2010 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
33 static DBusConnection *connection;
34 static GHashTable *session_hash;
35 static connman_bool_t sessionmode;
36 static struct session_info *ecall_info;
38 enum connman_session_trigger {
39 CONNMAN_SESSION_TRIGGER_UNKNOWN = 0,
40 CONNMAN_SESSION_TRIGGER_SETTING = 1,
41 CONNMAN_SESSION_TRIGGER_CONNECT = 2,
42 CONNMAN_SESSION_TRIGGER_DISCONNECT = 3,
43 CONNMAN_SESSION_TRIGGER_PERIODIC = 4,
44 CONNMAN_SESSION_TRIGGER_SERVICE = 5,
45 CONNMAN_SESSION_TRIGGER_ECALL = 6,
48 enum connman_session_reason {
49 CONNMAN_SESSION_REASON_UNKNOWN = 0,
50 CONNMAN_SESSION_REASON_CONNECT = 1,
51 CONNMAN_SESSION_REASON_DISCONNECT = 2,
52 CONNMAN_SESSION_REASON_FREE_RIDE = 3,
53 CONNMAN_SESSION_REASON_PERIODIC = 4,
56 enum connman_session_state {
57 CONNMAN_SESSION_STATE_DISCONNECTED = 0,
58 CONNMAN_SESSION_STATE_CONNECTED = 1,
59 CONNMAN_SESSION_STATE_ONLINE = 2,
62 enum connman_session_roaming_policy {
63 CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN = 0,
64 CONNMAN_SESSION_ROAMING_POLICY_DEFAULT = 1,
65 CONNMAN_SESSION_ROAMING_POLICY_ALWAYS = 2,
66 CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN = 3,
67 CONNMAN_SESSION_ROAMING_POLICY_NATIONAL = 4,
68 CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL = 5,
71 struct service_entry {
72 /* track why this service was selected */
73 enum connman_session_reason reason;
74 enum connman_service_state state;
76 struct connman_service *service;
79 GSList *pending_timeouts;
83 enum connman_session_state state;
84 connman_bool_t priority;
85 GSList *allowed_bearers;
86 connman_bool_t avoid_handover;
87 connman_bool_t stay_connected;
88 unsigned int periodic_connect;
89 unsigned int idle_timeout;
91 enum connman_session_roaming_policy roaming_policy;
94 struct service_entry *entry;
95 enum connman_session_reason reason;
98 struct connman_session {
104 connman_bool_t append_all;
105 struct session_info *info;
106 struct session_info *info_last;
108 GSequence *service_list;
109 GHashTable *service_hash;
114 connman_bool_t match_all;
115 enum connman_service_type service_type;
118 static const char *trigger2string(enum connman_session_trigger trigger)
121 case CONNMAN_SESSION_TRIGGER_UNKNOWN:
123 case CONNMAN_SESSION_TRIGGER_SETTING:
125 case CONNMAN_SESSION_TRIGGER_CONNECT:
127 case CONNMAN_SESSION_TRIGGER_DISCONNECT:
129 case CONNMAN_SESSION_TRIGGER_PERIODIC:
131 case CONNMAN_SESSION_TRIGGER_SERVICE:
133 case CONNMAN_SESSION_TRIGGER_ECALL:
140 static const char *reason2string(enum connman_session_reason reason)
143 case CONNMAN_SESSION_REASON_UNKNOWN:
145 case CONNMAN_SESSION_REASON_CONNECT:
147 case CONNMAN_SESSION_REASON_DISCONNECT:
149 case CONNMAN_SESSION_REASON_FREE_RIDE:
151 case CONNMAN_SESSION_REASON_PERIODIC:
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 *roamingpolicy2string(enum connman_session_roaming_policy policy)
175 case CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN:
177 case CONNMAN_SESSION_ROAMING_POLICY_DEFAULT:
179 case CONNMAN_SESSION_ROAMING_POLICY_ALWAYS:
181 case CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN:
183 case CONNMAN_SESSION_ROAMING_POLICY_NATIONAL:
185 case CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL:
186 return "international";
192 static enum connman_session_roaming_policy string2roamingpolicy(const char *policy)
194 if (g_strcmp0(policy, "default") == 0)
195 return CONNMAN_SESSION_ROAMING_POLICY_DEFAULT;
196 else if (g_strcmp0(policy, "always") == 0)
197 return CONNMAN_SESSION_ROAMING_POLICY_ALWAYS;
198 else if (g_strcmp0(policy, "forbidden") == 0)
199 return CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN;
200 else if (g_strcmp0(policy, "national") == 0)
201 return CONNMAN_SESSION_ROAMING_POLICY_NATIONAL;
202 else if (g_strcmp0(policy, "international") == 0)
203 return CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL;
205 return CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN;
208 static enum connman_service_type bearer2service(const char *bearer)
211 return CONNMAN_SERVICE_TYPE_UNKNOWN;
213 if (g_strcmp0(bearer, "ethernet") == 0)
214 return CONNMAN_SERVICE_TYPE_ETHERNET;
215 else if (g_strcmp0(bearer, "wifi") == 0)
216 return CONNMAN_SERVICE_TYPE_WIFI;
217 else if (g_strcmp0(bearer, "wimax") == 0)
218 return CONNMAN_SERVICE_TYPE_WIMAX;
219 else if (g_strcmp0(bearer, "bluetooth") == 0)
220 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
221 else if (g_strcmp0(bearer, "cellular") == 0)
222 return CONNMAN_SERVICE_TYPE_CELLULAR;
223 else if (g_strcmp0(bearer, "vpn") == 0)
224 return CONNMAN_SERVICE_TYPE_VPN;
226 return CONNMAN_SERVICE_TYPE_UNKNOWN;
229 static char *service2bearer(enum connman_service_type type)
232 case CONNMAN_SERVICE_TYPE_ETHERNET:
234 case CONNMAN_SERVICE_TYPE_WIFI:
236 case CONNMAN_SERVICE_TYPE_WIMAX:
238 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
240 case CONNMAN_SERVICE_TYPE_CELLULAR:
242 case CONNMAN_SERVICE_TYPE_VPN:
244 case CONNMAN_SERVICE_TYPE_UNKNOWN:
245 case CONNMAN_SERVICE_TYPE_SYSTEM:
246 case CONNMAN_SERVICE_TYPE_GPS:
247 case CONNMAN_SERVICE_TYPE_GADGET:
254 static void cleanup_bearer_info(gpointer data, gpointer user_data)
256 struct bearer_info *info = data;
262 static GSList *session_parse_allowed_bearers(DBusMessageIter *iter)
264 struct bearer_info *info;
265 DBusMessageIter array;
268 dbus_message_iter_recurse(iter, &array);
270 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
273 dbus_message_iter_get_basic(&array, &bearer);
275 info = g_try_new0(struct bearer_info, 1);
277 g_slist_foreach(list, cleanup_bearer_info, NULL);
283 info->name = g_strdup(bearer);
284 info->service_type = bearer2service(info->name);
286 if (info->service_type == CONNMAN_SERVICE_TYPE_UNKNOWN &&
287 g_strcmp0(info->name, "*") == 0) {
288 info->match_all = TRUE;
290 info->match_all = FALSE;
293 list = g_slist_append(list, info);
295 dbus_message_iter_next(&array);
301 static GSList *session_allowed_bearers_any(void)
303 struct bearer_info *info;
306 info = g_try_new0(struct bearer_info, 1);
313 info->name = g_strdup("");
314 info->match_all = TRUE;
315 info->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
317 list = g_slist_append(list, info);
322 static void append_allowed_bearers(DBusMessageIter *iter, void *user_data)
324 struct session_info *info = user_data;
327 for (list = info->allowed_bearers;
328 list != NULL; list = list->next) {
329 struct bearer_info *info = list->data;
331 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
336 static void append_ipconfig_ipv4(DBusMessageIter *iter, void *user_data)
338 struct connman_service *service = user_data;
339 struct connman_ipconfig *ipconfig_ipv4;
344 ipconfig_ipv4 = __connman_service_get_ip4config(service);
345 if (ipconfig_ipv4 == NULL)
348 __connman_ipconfig_append_ipv4(ipconfig_ipv4, iter);
351 static void append_ipconfig_ipv6(DBusMessageIter *iter, void *user_data)
353 struct connman_service *service = user_data;
354 struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
359 ipconfig_ipv4 = __connman_service_get_ip4config(service);
360 ipconfig_ipv6 = __connman_service_get_ip6config(service);
361 if (ipconfig_ipv6 == NULL)
364 __connman_ipconfig_append_ipv6(ipconfig_ipv6, iter, ipconfig_ipv4);
367 static void append_notify(DBusMessageIter *dict,
368 struct connman_session *session)
370 struct session_info *info = session->info;
371 struct session_info *info_last = session->info_last;
373 struct connman_service *service;
374 const char *name, *ifname, *bearer;
376 if (session->append_all == TRUE ||
377 info->state != info_last->state) {
378 const char *state = state2string(info->state);
380 connman_dbus_dict_append_basic(dict, "State",
383 info_last->state = info->state;
386 if (session->append_all == TRUE ||
387 info->entry != info_last->entry) {
388 if (info->entry == NULL) {
394 name = info->entry->name;
395 ifname = info->entry->ifname;
396 service = info->entry->service;
397 bearer = info->entry->bearer;
400 connman_dbus_dict_append_basic(dict, "Name",
404 connman_dbus_dict_append_dict(dict, "IPv4",
405 append_ipconfig_ipv4,
408 connman_dbus_dict_append_dict(dict, "IPv6",
409 append_ipconfig_ipv6,
412 connman_dbus_dict_append_basic(dict, "Interface",
416 connman_dbus_dict_append_basic(dict, "Bearer",
420 info_last->entry = info->entry;
424 if (session->append_all == TRUE ||
425 info->priority != info_last->priority) {
426 connman_dbus_dict_append_basic(dict, "Priority",
429 info_last->priority = info->priority;
432 if (session->append_all == TRUE ||
433 info->allowed_bearers != info_last->allowed_bearers) {
434 connman_dbus_dict_append_array(dict, "AllowedBearers",
436 append_allowed_bearers,
438 info_last->allowed_bearers = info->allowed_bearers;
441 if (session->append_all == TRUE ||
442 info->avoid_handover != info_last->avoid_handover) {
443 connman_dbus_dict_append_basic(dict, "AvoidHandover",
445 &info->avoid_handover);
446 info_last->avoid_handover = info->avoid_handover;
449 if (session->append_all == TRUE ||
450 info->stay_connected != info_last->stay_connected) {
451 connman_dbus_dict_append_basic(dict, "StayConnected",
453 &info->stay_connected);
454 info_last->stay_connected = info->stay_connected;
457 if (session->append_all == TRUE ||
458 info->periodic_connect != info_last->periodic_connect) {
459 connman_dbus_dict_append_basic(dict, "PeriodicConnect",
461 &info->periodic_connect);
462 info_last->periodic_connect = info->periodic_connect;
465 if (session->append_all == TRUE ||
466 info->idle_timeout != info_last->idle_timeout) {
467 connman_dbus_dict_append_basic(dict, "IdleTimeout",
469 &info->idle_timeout);
470 info_last->idle_timeout = info->idle_timeout;
473 if (session->append_all == TRUE ||
474 info->ecall != info_last->ecall) {
475 connman_dbus_dict_append_basic(dict, "EmergencyCall",
478 info_last->ecall = info->ecall;
481 if (session->append_all == TRUE ||
482 info->roaming_policy != info_last->roaming_policy) {
483 policy = roamingpolicy2string(info->roaming_policy);
484 connman_dbus_dict_append_basic(dict, "RoamingPolicy",
487 info_last->roaming_policy = info->roaming_policy;
490 if (session->append_all == TRUE ||
491 info->marker != info_last->marker) {
492 connman_dbus_dict_append_basic(dict, "SessionMarker",
495 info_last->marker = info->marker;
498 session->append_all = FALSE;
501 static connman_bool_t compute_notifiable_changes(struct connman_session *session)
503 struct session_info *info_last = session->info_last;
504 struct session_info *info = session->info;
506 if (session->append_all == TRUE)
509 if (info->state != info_last->state)
512 if (info->entry != info_last->entry &&
513 info->state >= CONNMAN_SESSION_STATE_CONNECTED)
516 if (info->periodic_connect != info_last->periodic_connect ||
517 info->allowed_bearers != info_last->allowed_bearers ||
518 info->avoid_handover != info_last->avoid_handover ||
519 info->stay_connected != info_last->stay_connected ||
520 info->roaming_policy != info_last->roaming_policy ||
521 info->idle_timeout != info_last->idle_timeout ||
522 info->priority != info_last->priority ||
523 info->marker != info_last->marker ||
524 info->ecall != info_last->ecall)
530 static gboolean session_notify(gpointer user_data)
532 struct connman_session *session = user_data;
534 DBusMessageIter array, dict;
536 if (compute_notifiable_changes(session) == FALSE)
539 DBG("session %p owner %s notify_path %s", session,
540 session->owner, session->notify_path);
542 msg = dbus_message_new_method_call(session->owner, session->notify_path,
543 CONNMAN_NOTIFICATION_INTERFACE,
548 dbus_message_iter_init_append(msg, &array);
549 connman_dbus_dict_open(&array, &dict);
551 append_notify(&dict, session);
553 connman_dbus_dict_close(&array, &dict);
555 g_dbus_send_message(connection, msg);
560 static void ipconfig_ipv4_changed(struct connman_session *session)
562 struct session_info *info = session->info;
564 connman_dbus_setting_changed_dict(session->owner, session->notify_path,
565 "IPv4", append_ipconfig_ipv4,
566 info->entry->service);
569 static void ipconfig_ipv6_changed(struct connman_session *session)
571 struct session_info *info = session->info;
573 connman_dbus_setting_changed_dict(session->owner, session->notify_path,
574 "IPv6", append_ipconfig_ipv6,
575 info->entry->service);
578 static connman_bool_t service_type_match(struct connman_session *session,
579 struct connman_service *service)
581 struct session_info *info = session->info;
584 for (list = info->allowed_bearers;
585 list != NULL; list = list->next) {
586 struct bearer_info *info = list->data;
587 enum connman_service_type service_type;
589 if (info->match_all == TRUE)
592 service_type = connman_service_get_type(service);
593 if (info->service_type == service_type)
600 static connman_bool_t service_match(struct connman_session *session,
601 struct connman_service *service)
603 if (service_type_match(session, service) == FALSE)
609 static int service_type_weight(enum connman_service_type type)
612 * The session doesn't care which service
613 * to use. Nevertheless we have to sort them
614 * according their type. The ordering is
623 case CONNMAN_SERVICE_TYPE_ETHERNET:
625 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
627 case CONNMAN_SERVICE_TYPE_WIFI:
628 case CONNMAN_SERVICE_TYPE_WIMAX:
630 case CONNMAN_SERVICE_TYPE_CELLULAR:
632 case CONNMAN_SERVICE_TYPE_UNKNOWN:
633 case CONNMAN_SERVICE_TYPE_SYSTEM:
634 case CONNMAN_SERVICE_TYPE_GPS:
635 case CONNMAN_SERVICE_TYPE_VPN:
636 case CONNMAN_SERVICE_TYPE_GADGET:
643 static gint sort_allowed_bearers(struct connman_service *service_a,
644 struct connman_service *service_b,
645 struct connman_session *session)
647 struct session_info *info = session->info;
649 enum connman_service_type type_a, type_b;
650 int weight_a, weight_b;
652 type_a = connman_service_get_type(service_a);
653 type_b = connman_service_get_type(service_b);
655 for (list = info->allowed_bearers;
656 list != NULL; list = list->next) {
657 struct bearer_info *info = list->data;
659 if (info->match_all == TRUE) {
660 if (type_a != type_b) {
661 weight_a = service_type_weight(type_a);
662 weight_b = service_type_weight(type_b);
664 if (weight_a > weight_b)
667 if (weight_a < weight_b)
674 if (type_a == info->service_type &&
675 type_b == info->service_type) {
679 if (type_a == info->service_type &&
680 type_b != info->service_type) {
684 if (type_a != info->service_type &&
685 type_b == info->service_type) {
693 static gint sort_services(gconstpointer a, gconstpointer b, gpointer user_data)
695 struct service_entry *entry_a = (void *)a;
696 struct service_entry *entry_b = (void *)b;
697 struct connman_session *session = user_data;
699 return sort_allowed_bearers(entry_a->service, entry_b->service,
703 static void cleanup_session(gpointer user_data)
705 struct connman_session *session = user_data;
706 struct session_info *info = session->info;
708 DBG("remove %s", session->session_path);
710 g_hash_table_destroy(session->service_hash);
711 g_sequence_free(session->service_list);
713 if (info->entry != NULL &&
714 info->entry->reason == CONNMAN_SESSION_REASON_CONNECT) {
715 __connman_service_disconnect(info->entry->service);
718 g_slist_foreach(info->allowed_bearers, cleanup_bearer_info, NULL);
719 g_slist_free(info->allowed_bearers);
721 g_free(session->owner);
722 g_free(session->session_path);
723 g_free(session->notify_path);
724 g_free(session->info);
725 g_free(session->info_last);
730 static enum connman_session_state service_to_session_state(enum connman_service_state state)
733 case CONNMAN_SERVICE_STATE_UNKNOWN:
734 case CONNMAN_SERVICE_STATE_IDLE:
735 case CONNMAN_SERVICE_STATE_ASSOCIATION:
736 case CONNMAN_SERVICE_STATE_CONFIGURATION:
737 case CONNMAN_SERVICE_STATE_DISCONNECT:
738 case CONNMAN_SERVICE_STATE_FAILURE:
740 case CONNMAN_SERVICE_STATE_READY:
741 return CONNMAN_SESSION_STATE_CONNECTED;
742 case CONNMAN_SERVICE_STATE_ONLINE:
743 return CONNMAN_SESSION_STATE_ONLINE;
746 return CONNMAN_SESSION_STATE_DISCONNECTED;
749 static connman_bool_t is_connected(enum connman_service_state state)
752 case CONNMAN_SERVICE_STATE_UNKNOWN:
753 case CONNMAN_SERVICE_STATE_IDLE:
754 case CONNMAN_SERVICE_STATE_ASSOCIATION:
755 case CONNMAN_SERVICE_STATE_CONFIGURATION:
756 case CONNMAN_SERVICE_STATE_DISCONNECT:
757 case CONNMAN_SERVICE_STATE_FAILURE:
759 case CONNMAN_SERVICE_STATE_READY:
760 case CONNMAN_SERVICE_STATE_ONLINE:
767 static connman_bool_t is_connecting(enum connman_service_state state)
770 case CONNMAN_SERVICE_STATE_UNKNOWN:
771 case CONNMAN_SERVICE_STATE_IDLE:
773 case CONNMAN_SERVICE_STATE_ASSOCIATION:
774 case CONNMAN_SERVICE_STATE_CONFIGURATION:
776 case CONNMAN_SERVICE_STATE_DISCONNECT:
777 case CONNMAN_SERVICE_STATE_FAILURE:
778 case CONNMAN_SERVICE_STATE_READY:
779 case CONNMAN_SERVICE_STATE_ONLINE:
786 static connman_bool_t explicit_connect(enum connman_session_reason reason)
789 case CONNMAN_SESSION_REASON_UNKNOWN:
790 case CONNMAN_SESSION_REASON_FREE_RIDE:
791 case CONNMAN_SESSION_REASON_DISCONNECT:
793 case CONNMAN_SESSION_REASON_CONNECT:
794 case CONNMAN_SESSION_REASON_PERIODIC:
801 static connman_bool_t explicit_disconnect(struct session_info *info)
803 if (info->entry == NULL)
806 DBG("reason %s service %p state %d",
807 reason2string(info->entry->reason),
808 info->entry->service, info->entry->state);
810 if (info->entry->reason == CONNMAN_SESSION_REASON_UNKNOWN)
813 if (explicit_connect(info->entry->reason) == FALSE)
816 if (__connman_service_session_dec(info->entry->service) == FALSE)
819 if (ecall_info != NULL && ecall_info != info)
825 struct pending_data {
826 unsigned int timeout;
827 struct service_entry *entry;
828 gboolean (*cb)(gpointer);
831 static void pending_timeout_free(gpointer data, gpointer user_data)
833 struct pending_data *pending = data;
835 DBG("pending %p timeout %d", pending, pending->timeout);
836 g_source_remove(pending->timeout);
840 static void pending_timeout_remove_all(struct service_entry *entry)
844 g_slist_foreach(entry->pending_timeouts, pending_timeout_free, NULL);
845 g_slist_free(entry->pending_timeouts);
846 entry->pending_timeouts = NULL;
849 static gboolean pending_timeout_cb(gpointer data)
851 struct pending_data *pending = data;
852 struct service_entry *entry = pending->entry;
855 DBG("pending %p timeout %d", pending, pending->timeout);
857 ret = pending->cb(pending->entry);
859 entry->pending_timeouts =
860 g_slist_remove(entry->pending_timeouts,
867 static connman_bool_t pending_timeout_add(unsigned int seconds,
868 gboolean (*cb)(gpointer),
869 struct service_entry *entry)
871 struct pending_data *pending = g_try_new0(struct pending_data, 1);
873 if (pending == NULL || cb == NULL || entry == NULL) {
879 pending->entry = entry;
880 pending->timeout = g_timeout_add_seconds(seconds, pending_timeout_cb,
882 entry->pending_timeouts = g_slist_prepend(entry->pending_timeouts,
885 DBG("pending %p entry %p timeout id %d", pending, entry,
891 static gboolean call_disconnect(gpointer user_data)
893 struct service_entry *entry = user_data;
894 struct connman_service *service = entry->service;
897 * TODO: We should mark this entry as pending work. In case
898 * disconnect fails we just unassign this session from the
899 * service and can't do anything later on it
901 DBG("disconnect service %p", service);
902 __connman_service_disconnect(service);
907 static gboolean call_connect(gpointer user_data)
909 struct service_entry *entry = user_data;
910 struct connman_service *service = entry->service;
912 DBG("connect service %p", service);
913 __connman_service_connect(service);
918 static void deselect_service(struct session_info *info)
920 struct service_entry *entry;
921 connman_bool_t disconnect, connected;
925 if (info->entry == NULL)
928 disconnect = explicit_disconnect(info);
930 connected = is_connecting(info->entry->state) == TRUE ||
931 is_connected(info->entry->state) == TRUE;
933 info->state = CONNMAN_SESSION_STATE_DISCONNECTED;
934 info->entry->reason = CONNMAN_SESSION_REASON_UNKNOWN;
939 DBG("disconnect %d connected %d", disconnect, connected);
941 if (disconnect == TRUE && connected == TRUE)
942 pending_timeout_add(0, call_disconnect, entry);
945 static void deselect_and_disconnect(struct connman_session *session,
946 enum connman_session_reason reason)
948 struct session_info *info = session->info;
950 deselect_service(info);
952 info->reason = reason;
955 static void select_connected_service(struct session_info *info,
956 struct service_entry *entry)
958 info->state = service_to_session_state(entry->state);
961 info->entry->reason = info->reason;
963 if (explicit_connect(info->reason) == FALSE)
966 __connman_service_session_inc(info->entry->service);
969 static void select_offline_service(struct session_info *info,
970 struct service_entry *entry)
972 if (explicit_connect(info->reason) == FALSE)
975 info->state = service_to_session_state(entry->state);
978 info->entry->reason = info->reason;
980 __connman_service_session_inc(info->entry->service);
981 pending_timeout_add(0, call_connect, entry);
984 static void select_service(struct session_info *info,
985 struct service_entry *entry)
987 DBG("service %p", entry->service);
989 if (is_connected(entry->state) == TRUE)
990 select_connected_service(info, entry);
992 select_offline_service(info, entry);
995 static void select_and_connect(struct connman_session *session,
996 enum connman_session_reason reason)
998 struct session_info *info = session->info;
999 struct service_entry *entry = NULL;
1000 GSequenceIter *iter;
1002 DBG("session %p reason %s", session, reason2string(reason));
1004 info->reason = reason;
1006 iter = g_sequence_get_begin_iter(session->service_list);
1008 while (g_sequence_iter_is_end(iter) == FALSE) {
1009 entry = g_sequence_get(iter);
1011 switch (entry->state) {
1012 case CONNMAN_SERVICE_STATE_ASSOCIATION:
1013 case CONNMAN_SERVICE_STATE_CONFIGURATION:
1014 case CONNMAN_SERVICE_STATE_READY:
1015 case CONNMAN_SERVICE_STATE_ONLINE:
1016 case CONNMAN_SERVICE_STATE_IDLE:
1017 case CONNMAN_SERVICE_STATE_DISCONNECT:
1018 select_service(info, entry);
1020 case CONNMAN_SERVICE_STATE_UNKNOWN:
1021 case CONNMAN_SERVICE_STATE_FAILURE:
1025 iter = g_sequence_iter_next(iter);
1029 static struct service_entry *create_service_entry(struct connman_service *service,
1031 enum connman_service_state state)
1033 struct service_entry *entry;
1034 enum connman_service_type type;
1037 entry = g_try_new0(struct service_entry, 1);
1041 entry->reason = CONNMAN_SESSION_REASON_UNKNOWN;
1042 entry->state = state;
1047 entry->service = service;
1049 idx = __connman_service_get_index(entry->service);
1050 entry->ifname = connman_inet_ifname(idx);
1051 if (entry->ifname == NULL)
1052 entry->ifname = g_strdup("");
1054 type = connman_service_get_type(entry->service);
1055 entry->bearer = service2bearer(type);
1060 static void destroy_service_entry(gpointer data)
1062 struct service_entry *entry = data;
1064 pending_timeout_remove_all(entry);
1065 g_free(entry->ifname);
1070 static void populate_service_list(struct connman_session *session)
1072 struct service_entry *entry;
1073 GSequenceIter *iter;
1075 session->service_hash =
1076 g_hash_table_new_full(g_direct_hash, g_direct_equal,
1078 session->service_list = __connman_service_get_list(session,
1080 create_service_entry,
1081 destroy_service_entry);
1083 g_sequence_sort(session->service_list, sort_services, session);
1085 iter = g_sequence_get_begin_iter(session->service_list);
1087 while (g_sequence_iter_is_end(iter) == FALSE) {
1088 entry = g_sequence_get(iter);
1090 DBG("service %p type %s name %s", entry->service,
1091 service2bearer(connman_service_get_type(entry->service)),
1094 g_hash_table_replace(session->service_hash,
1095 entry->service, iter);
1097 iter = g_sequence_iter_next(iter);
1101 static void session_changed(struct connman_session *session,
1102 enum connman_session_trigger trigger)
1104 struct session_info *info = session->info;
1105 struct session_info *info_last = session->info_last;
1106 GSequenceIter *service_iter = NULL, *service_iter_last = NULL;
1107 GSequence *service_list_last;
1108 GHashTable *service_hash_last;
1111 * TODO: This only a placeholder for the 'real' algorithm to
1112 * play a bit around. So we are going to improve it step by step.
1115 DBG("session %p trigger %s reason %s", session, trigger2string(trigger),
1116 reason2string(info->reason));
1118 if (info->entry != NULL)
1119 info->state = service_to_session_state(info->entry->state);
1122 case CONNMAN_SESSION_TRIGGER_UNKNOWN:
1123 DBG("ignore session changed event");
1125 case CONNMAN_SESSION_TRIGGER_SETTING:
1126 if (info->allowed_bearers != info_last->allowed_bearers) {
1128 service_hash_last = session->service_hash;
1129 service_list_last = session->service_list;
1131 populate_service_list(session);
1133 if (info->entry != NULL) {
1134 service_iter_last = g_hash_table_lookup(
1136 info->entry->service);
1137 service_iter = g_hash_table_lookup(
1138 session->service_hash,
1139 info->entry->service);
1142 if (service_iter == NULL && service_iter_last != NULL) {
1144 * The currently selected service is
1145 * not part of this session anymore.
1147 deselect_and_disconnect(session, info->reason);
1150 g_hash_table_remove_all(service_hash_last);
1151 g_sequence_free(service_list_last);
1154 if (info->state == CONNMAN_SESSION_STATE_DISCONNECTED) {
1155 select_and_connect(session,
1156 CONNMAN_SESSION_REASON_FREE_RIDE);
1160 case CONNMAN_SESSION_TRIGGER_CONNECT:
1161 if (info->state >= CONNMAN_SESSION_STATE_CONNECTED) {
1162 if (info->entry->reason == CONNMAN_SESSION_REASON_CONNECT)
1164 info->entry->reason = CONNMAN_SESSION_REASON_CONNECT;
1165 __connman_service_session_inc(info->entry->service);
1169 if (info->entry != NULL &&
1170 is_connecting(info->entry->state) == TRUE) {
1174 select_and_connect(session,
1175 CONNMAN_SESSION_REASON_CONNECT);
1178 case CONNMAN_SESSION_TRIGGER_DISCONNECT:
1179 deselect_and_disconnect(session,
1180 CONNMAN_SESSION_REASON_DISCONNECT);
1183 case CONNMAN_SESSION_TRIGGER_PERIODIC:
1184 if (info->state >= CONNMAN_SESSION_STATE_CONNECTED) {
1185 info->entry->reason = CONNMAN_SESSION_REASON_PERIODIC;
1186 __connman_service_session_inc(info->entry->service);
1190 select_and_connect(session,
1191 CONNMAN_SESSION_REASON_PERIODIC);
1194 case CONNMAN_SESSION_TRIGGER_SERVICE:
1195 if (info->entry != NULL &&
1196 (is_connecting(info->entry->state) == TRUE ||
1197 is_connected(info->entry->state) == TRUE)) {
1201 deselect_and_disconnect(session, info->reason);
1203 if (info->reason == CONNMAN_SESSION_REASON_FREE_RIDE ||
1204 info->stay_connected == TRUE) {
1205 select_and_connect(session, info->reason);
1209 case CONNMAN_SESSION_TRIGGER_ECALL:
1210 if (info->state == CONNMAN_SESSION_STATE_DISCONNECTED &&
1211 info->entry != NULL &&
1212 info->entry->service != NULL) {
1213 deselect_and_disconnect(session, info->reason);
1219 session_notify(session);
1222 static DBusMessage *connect_session(DBusConnection *conn,
1223 DBusMessage *msg, void *user_data)
1225 struct connman_session *session = user_data;
1226 struct session_info *info = session->info;
1228 DBG("session %p", session);
1230 if (ecall_info != NULL && ecall_info != info)
1231 return __connman_error_failed(msg, EBUSY);
1233 session_changed(session, CONNMAN_SESSION_TRIGGER_CONNECT);
1235 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1238 static DBusMessage *disconnect_session(DBusConnection *conn,
1239 DBusMessage *msg, void *user_data)
1241 struct connman_session *session = user_data;
1242 struct session_info *info = session->info;
1244 DBG("session %p", session);
1246 if (ecall_info != NULL && ecall_info != info)
1247 return __connman_error_failed(msg, EBUSY);
1249 session_changed(session, CONNMAN_SESSION_TRIGGER_DISCONNECT);
1251 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1254 static void update_ecall_sessions(struct connman_session *session)
1256 struct session_info *info = session->info;
1257 struct connman_session *session_iter;
1258 GHashTableIter iter;
1259 gpointer key, value;
1261 g_hash_table_iter_init(&iter, session_hash);
1263 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1264 session_iter = value;
1266 if (session_iter == session)
1269 session_iter->info->ecall = info->ecall;
1271 session_changed(session_iter, CONNMAN_SESSION_TRIGGER_ECALL);
1275 static void update_ecall(struct connman_session *session)
1277 struct session_info *info = session->info;
1278 struct session_info *info_last = session->info_last;
1280 DBG("session %p ecall_info %p ecall %d -> %d", session,
1281 ecall_info, info_last->ecall, info->ecall);
1283 if (ecall_info == NULL) {
1284 if (!(info_last->ecall == FALSE && info->ecall == TRUE))
1288 } else if (ecall_info == info) {
1289 if (!(info_last->ecall == TRUE && info->ecall == FALSE))
1297 update_ecall_sessions(session);
1302 /* not a valid transition */
1303 info->ecall = info_last->ecall;
1306 static DBusMessage *change_session(DBusConnection *conn,
1307 DBusMessage *msg, void *user_data)
1309 struct connman_session *session = user_data;
1310 struct session_info *info = session->info;
1311 DBusMessageIter iter, value;
1313 GSList *allowed_bearers;
1315 DBG("session %p", session);
1316 if (dbus_message_iter_init(msg, &iter) == FALSE)
1317 return __connman_error_invalid_arguments(msg);
1319 dbus_message_iter_get_basic(&iter, &name);
1320 dbus_message_iter_next(&iter);
1321 dbus_message_iter_recurse(&iter, &value);
1323 switch (dbus_message_iter_get_arg_type(&value)) {
1324 case DBUS_TYPE_ARRAY:
1325 if (g_str_equal(name, "AllowedBearers") == TRUE) {
1326 allowed_bearers = session_parse_allowed_bearers(&value);
1328 g_slist_foreach(info->allowed_bearers,
1329 cleanup_bearer_info, NULL);
1330 g_slist_free(info->allowed_bearers);
1332 if (allowed_bearers == NULL) {
1333 allowed_bearers = session_allowed_bearers_any();
1335 if (allowed_bearers == NULL)
1336 return __connman_error_failed(msg, ENOMEM);
1339 info->allowed_bearers = allowed_bearers;
1344 case DBUS_TYPE_BOOLEAN:
1345 if (g_str_equal(name, "Priority") == TRUE) {
1346 dbus_message_iter_get_basic(&value,
1348 } else if (g_str_equal(name, "AvoidHandover") == TRUE) {
1349 dbus_message_iter_get_basic(&value,
1350 &info->avoid_handover);
1351 } else if (g_str_equal(name, "StayConnected") == TRUE) {
1352 dbus_message_iter_get_basic(&value,
1353 &info->stay_connected);
1354 } else if (g_str_equal(name, "EmergencyCall") == TRUE) {
1355 dbus_message_iter_get_basic(&value,
1358 update_ecall(session);
1363 case DBUS_TYPE_UINT32:
1364 if (g_str_equal(name, "PeriodicConnect") == TRUE) {
1365 dbus_message_iter_get_basic(&value,
1366 &info->periodic_connect);
1367 } else if (g_str_equal(name, "IdleTimeout") == TRUE) {
1368 dbus_message_iter_get_basic(&value,
1369 &info->idle_timeout);
1374 case DBUS_TYPE_STRING:
1375 if (g_str_equal(name, "RoamingPolicy") == TRUE) {
1377 dbus_message_iter_get_basic(&value, &val);
1378 info->roaming_policy =
1379 string2roamingpolicy(val);
1388 session_changed(session, CONNMAN_SESSION_TRIGGER_SETTING);
1390 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1393 return __connman_error_invalid_arguments(msg);
1396 static void release_session(gpointer key, gpointer value, gpointer user_data)
1398 struct connman_session *session = value;
1399 DBusMessage *message;
1401 DBG("owner %s path %s", session->owner, session->notify_path);
1403 if (session->notify_watch > 0)
1404 g_dbus_remove_watch(connection, session->notify_watch);
1406 g_dbus_unregister_interface(connection, session->session_path,
1407 CONNMAN_SESSION_INTERFACE);
1409 message = dbus_message_new_method_call(session->owner,
1410 session->notify_path,
1411 CONNMAN_NOTIFICATION_INTERFACE,
1413 if (message == NULL)
1416 dbus_message_set_no_reply(message, TRUE);
1418 g_dbus_send_message(connection, message);
1421 static int session_disconnect(struct connman_session *session)
1423 DBG("session %p, %s", session, session->owner);
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 deselect_and_disconnect(session,
1432 CONNMAN_SESSION_REASON_DISCONNECT);
1434 g_hash_table_remove(session_hash, session->session_path);
1439 static void owner_disconnect(DBusConnection *conn, void *user_data)
1441 struct connman_session *session = user_data;
1443 DBG("session %p, %s died", session, session->owner);
1445 session_disconnect(session);
1448 static DBusMessage *destroy_session(DBusConnection *conn,
1449 DBusMessage *msg, void *user_data)
1451 struct connman_session *session = user_data;
1452 struct session_info *info = session->info;
1454 DBG("session %p", session);
1456 if (ecall_info != NULL && ecall_info != info)
1457 return __connman_error_failed(msg, EBUSY);
1459 session_disconnect(session);
1461 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1464 static GDBusMethodTable session_methods[] = {
1465 { "Destroy", "", "", destroy_session },
1466 { "Connect", "", "", connect_session },
1467 { "Disconnect", "", "", disconnect_session },
1468 { "Change", "sv", "", change_session },
1472 int __connman_session_create(DBusMessage *msg)
1474 const char *owner, *notify_path;
1475 char *session_path = NULL;
1476 DBusMessageIter iter, array;
1477 struct connman_session *session = NULL;
1478 struct session_info *info, *info_last;
1480 connman_bool_t priority = FALSE, avoid_handover = FALSE;
1481 connman_bool_t stay_connected = FALSE, ecall = FALSE;
1482 enum connman_session_roaming_policy roaming_policy =
1483 CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN;
1484 GSList *allowed_bearers = NULL;
1485 unsigned int periodic_connect = 0;
1486 unsigned int idle_timeout = 0;
1490 owner = dbus_message_get_sender(msg);
1492 DBG("owner %s", owner);
1494 if (ecall_info != NULL) {
1496 * If there is an emergency call already going on,
1497 * ignore session creation attempt
1503 dbus_message_iter_init(msg, &iter);
1504 dbus_message_iter_recurse(&iter, &array);
1506 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
1507 DBusMessageIter entry, value;
1508 const char *key, *val;
1510 dbus_message_iter_recurse(&array, &entry);
1511 dbus_message_iter_get_basic(&entry, &key);
1513 dbus_message_iter_next(&entry);
1514 dbus_message_iter_recurse(&entry, &value);
1516 switch (dbus_message_iter_get_arg_type(&value)) {
1517 case DBUS_TYPE_ARRAY:
1518 if (g_str_equal(key, "AllowedBearers") == TRUE) {
1520 session_parse_allowed_bearers(&value);
1525 case DBUS_TYPE_BOOLEAN:
1526 if (g_str_equal(key, "Priority") == TRUE) {
1527 dbus_message_iter_get_basic(&value,
1529 } else if (g_str_equal(key, "AvoidHandover") == TRUE) {
1530 dbus_message_iter_get_basic(&value,
1532 } else if (g_str_equal(key, "StayConnected") == TRUE) {
1533 dbus_message_iter_get_basic(&value,
1535 } else if (g_str_equal(key, "EmergencyCall") == TRUE) {
1536 dbus_message_iter_get_basic(&value,
1542 case DBUS_TYPE_UINT32:
1543 if (g_str_equal(key, "PeriodicConnect") == TRUE) {
1544 dbus_message_iter_get_basic(&value,
1546 } else if (g_str_equal(key, "IdleTimeout") == TRUE) {
1547 dbus_message_iter_get_basic(&value,
1553 case DBUS_TYPE_STRING:
1554 if (g_str_equal(key, "RoamingPolicy") == TRUE) {
1555 dbus_message_iter_get_basic(&value, &val);
1556 roaming_policy = string2roamingpolicy(val);
1561 dbus_message_iter_next(&array);
1564 dbus_message_iter_next(&iter);
1565 dbus_message_iter_get_basic(&iter, ¬ify_path);
1567 if (notify_path == NULL) {
1572 session_path = g_strdup_printf("/sessions%s", notify_path);
1573 if (session_path == NULL) {
1578 session = g_hash_table_lookup(session_hash, session_path);
1579 if (session != NULL) {
1585 session = g_try_new0(struct connman_session, 1);
1586 if (session == NULL) {
1591 session->info = g_try_new0(struct session_info, 1);
1592 if (session->info == NULL) {
1597 session->info_last = g_try_new0(struct session_info, 1);
1598 if (session->info_last == NULL) {
1603 info = session->info;
1604 info_last = session->info_last;
1606 session->owner = g_strdup(owner);
1607 session->session_path = session_path;
1608 session->notify_path = g_strdup(notify_path);
1609 session->notify_watch =
1610 g_dbus_add_disconnect_watch(connection, session->owner,
1611 owner_disconnect, session, NULL);
1613 info->state = CONNMAN_SESSION_STATE_DISCONNECTED;
1614 info->priority = priority;
1615 info->avoid_handover = avoid_handover;
1616 info->stay_connected = stay_connected;
1617 info->periodic_connect = periodic_connect;
1618 info->idle_timeout = idle_timeout;
1619 info->ecall = ecall;
1620 info->roaming_policy = roaming_policy;
1624 if (allowed_bearers == NULL) {
1625 info->allowed_bearers =
1626 session_allowed_bearers_any();
1628 if (info->allowed_bearers == NULL) {
1633 info->allowed_bearers = allowed_bearers;
1636 g_hash_table_replace(session_hash, session->session_path, session);
1638 DBG("add %s", session->session_path);
1640 if (g_dbus_register_interface(connection, session->session_path,
1641 CONNMAN_SESSION_INTERFACE,
1642 session_methods, NULL,
1643 NULL, session, NULL) == FALSE) {
1644 connman_error("Failed to register %s", session->session_path);
1645 g_hash_table_remove(session_hash, session->session_path);
1652 g_dbus_send_reply(connection, msg,
1653 DBUS_TYPE_OBJECT_PATH, &session->session_path,
1657 populate_service_list(session);
1658 if (info->ecall == TRUE) {
1660 update_ecall_sessions(session);
1663 info_last->state = info->state;
1664 info_last->priority = info->priority;
1665 info_last->avoid_handover = info->avoid_handover;
1666 info_last->stay_connected = info->stay_connected;
1667 info_last->periodic_connect = info->periodic_connect;
1668 info_last->idle_timeout = info->idle_timeout;
1669 info_last->ecall = info->ecall;
1670 info_last->roaming_policy = info->roaming_policy;
1671 info_last->entry = info->entry;
1672 info_last->marker = info->marker;
1673 info_last->allowed_bearers = info->allowed_bearers;
1675 session->append_all = TRUE;
1677 session_changed(session, CONNMAN_SESSION_TRIGGER_SETTING);
1682 connman_error("Failed to create session");
1684 if (session != NULL) {
1685 if (session->info_last != NULL)
1686 g_free(session->info_last);
1687 if (session->info != NULL)
1688 g_free(session->info);
1692 g_free(session_path);
1694 g_slist_foreach(allowed_bearers, cleanup_bearer_info, NULL);
1695 g_slist_free(allowed_bearers);
1700 int __connman_session_destroy(DBusMessage *msg)
1702 const char *owner, *session_path;
1703 struct connman_session *session;
1705 owner = dbus_message_get_sender(msg);
1707 DBG("owner %s", owner);
1709 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &session_path,
1711 if (session_path == NULL)
1714 session = g_hash_table_lookup(session_hash, session_path);
1715 if (session == NULL)
1718 if (g_strcmp0(owner, session->owner) != 0)
1721 session_disconnect(session);
1726 connman_bool_t __connman_session_mode()
1731 void __connman_session_set_mode(connman_bool_t enable)
1733 DBG("enable %d", enable);
1735 if (sessionmode != enable) {
1736 sessionmode = enable;
1738 connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
1739 CONNMAN_MANAGER_INTERFACE, "SessionMode",
1740 DBUS_TYPE_BOOLEAN, &sessionmode);
1743 if (sessionmode == TRUE)
1744 __connman_service_disconnect_all();
1747 static void service_add(struct connman_service *service,
1750 GHashTableIter iter;
1751 GSequenceIter *iter_service_list;
1752 gpointer key, value;
1753 struct connman_session *session;
1754 struct service_entry *entry;
1756 DBG("service %p", service);
1758 g_hash_table_iter_init(&iter, session_hash);
1760 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1763 if (service_match(session, service) == FALSE)
1766 entry = create_service_entry(service, name,
1767 CONNMAN_SERVICE_STATE_IDLE);
1772 g_sequence_insert_sorted(session->service_list,
1773 entry, sort_services,
1776 g_hash_table_replace(session->service_hash, service,
1779 session_changed(session, CONNMAN_SESSION_TRIGGER_SERVICE);
1783 static void service_remove(struct connman_service *service)
1786 GHashTableIter iter;
1787 gpointer key, value;
1788 struct connman_session *session;
1789 struct session_info *info;
1791 DBG("service %p", service);
1793 g_hash_table_iter_init(&iter, session_hash);
1795 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1796 GSequenceIter *iter;
1798 info = session->info;
1800 iter = g_hash_table_lookup(session->service_hash, service);
1804 g_sequence_remove(iter);
1806 if (info->entry != NULL && info->entry->service == service)
1808 session_changed(session, CONNMAN_SESSION_TRIGGER_SERVICE);
1812 static void service_state_changed(struct connman_service *service,
1813 enum connman_service_state state)
1815 GHashTableIter iter;
1816 gpointer key, value;
1818 DBG("service %p state %d", service, state);
1820 g_hash_table_iter_init(&iter, session_hash);
1822 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1823 struct connman_session *session = value;
1824 GSequenceIter *service_iter;
1826 service_iter = g_hash_table_lookup(session->service_hash, service);
1827 if (service_iter != NULL) {
1828 struct service_entry *entry;
1830 entry = g_sequence_get(service_iter);
1831 entry->state = state;
1834 session_changed(session,
1835 CONNMAN_SESSION_TRIGGER_SERVICE);
1839 static void ipconfig_changed(struct connman_service *service,
1840 struct connman_ipconfig *ipconfig)
1842 GHashTableIter iter;
1843 gpointer key, value;
1844 struct connman_session *session;
1845 struct session_info *info;
1846 enum connman_ipconfig_type type;
1848 DBG("service %p ipconfig %p", service, ipconfig);
1850 type = __connman_ipconfig_get_config_type(ipconfig);
1852 g_hash_table_iter_init(&iter, session_hash);
1854 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1856 info = session->info;
1858 if (info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
1861 if (info->entry != NULL && info->entry->service == service) {
1862 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1863 ipconfig_ipv4_changed(session);
1864 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
1865 ipconfig_ipv6_changed(session);
1870 static struct connman_notifier session_notifier = {
1872 .service_add = service_add,
1873 .service_remove = service_remove,
1874 .service_state_changed = service_state_changed,
1875 .ipconfig_changed = ipconfig_changed,
1878 int __connman_session_init(void)
1884 connection = connman_dbus_get_connection();
1885 if (connection == NULL)
1888 err = connman_notifier_register(&session_notifier);
1890 dbus_connection_unref(connection);
1894 session_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1895 NULL, cleanup_session);
1897 sessionmode = FALSE;
1901 void __connman_session_cleanup(void)
1905 if (connection == NULL)
1908 connman_notifier_unregister(&session_notifier);
1910 g_hash_table_foreach(session_hash, release_session, NULL);
1911 g_hash_table_destroy(session_hash);
1912 session_hash = NULL;
1914 dbus_connection_unref(connection);