*
* Connection Manager
*
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
* Copyright (C) 2011 BWM CarIT GmbH. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
#include <gdbus.h>
+#include <connman/session.h>
+
#include "connman.h"
static DBusConnection *connection;
static GHashTable *session_hash;
static connman_bool_t sessionmode;
static struct connman_session *ecall_session;
+static GSList *policy_list;
enum connman_session_trigger {
CONNMAN_SESSION_TRIGGER_UNKNOWN = 0,
CONNMAN_SESSION_TRIGGER_SETTING = 1,
CONNMAN_SESSION_TRIGGER_CONNECT = 2,
CONNMAN_SESSION_TRIGGER_DISCONNECT = 3,
- CONNMAN_SESSION_TRIGGER_PERIODIC = 4,
- CONNMAN_SESSION_TRIGGER_SERVICE = 5,
- CONNMAN_SESSION_TRIGGER_ECALL = 6,
+ CONNMAN_SESSION_TRIGGER_SERVICE = 4,
+ CONNMAN_SESSION_TRIGGER_ECALL = 5,
};
enum connman_session_reason {
CONNMAN_SESSION_REASON_UNKNOWN = 0,
CONNMAN_SESSION_REASON_CONNECT = 1,
CONNMAN_SESSION_REASON_FREE_RIDE = 2,
- CONNMAN_SESSION_REASON_PERIODIC = 3,
};
-enum connman_session_roaming_policy {
- CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN = 0,
- CONNMAN_SESSION_ROAMING_POLICY_DEFAULT = 1,
- CONNMAN_SESSION_ROAMING_POLICY_ALWAYS = 2,
- CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN = 3,
- CONNMAN_SESSION_ROAMING_POLICY_NATIONAL = 4,
- CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL = 5,
+enum connman_session_state {
+ CONNMAN_SESSION_STATE_DISCONNECTED = 0,
+ CONNMAN_SESSION_STATE_CONNECTED = 1,
+ CONNMAN_SESSION_STATE_ONLINE = 2,
};
struct service_entry {
struct connman_service *service;
char *ifname;
const char *bearer;
+ GSList *pending_timeouts;
};
struct session_info {
- connman_bool_t online;
- connman_bool_t priority;
- GSList *allowed_bearers;
- connman_bool_t avoid_handover;
- connman_bool_t stay_connected;
- unsigned int periodic_connect;
- unsigned int idle_timeout;
- connman_bool_t ecall;
- enum connman_session_roaming_policy roaming_policy;
- unsigned int marker;
-
+ struct connman_session_config config;
+ enum connman_session_state state;
struct service_entry *entry;
enum connman_session_reason reason;
};
char *notify_path;
guint notify_watch;
+ struct connman_session_policy *policy;
+
connman_bool_t append_all;
- connman_bool_t info_dirty;
struct session_info *info;
struct session_info *info_last;
+ struct connman_session_config *policy_config;
+
+ connman_bool_t ecall;
GSequence *service_list;
GHashTable *service_hash;
};
-struct bearer_info {
- char *name;
- connman_bool_t match_all;
- enum connman_service_type service_type;
-};
-
static const char *trigger2string(enum connman_session_trigger trigger)
{
switch (trigger) {
return "connect";
case CONNMAN_SESSION_TRIGGER_DISCONNECT:
return "disconnect";
- case CONNMAN_SESSION_TRIGGER_PERIODIC:
- return "periodic";
case CONNMAN_SESSION_TRIGGER_SERVICE:
return "service";
case CONNMAN_SESSION_TRIGGER_ECALL:
return "connect";
case CONNMAN_SESSION_REASON_FREE_RIDE:
return "free-ride";
- case CONNMAN_SESSION_REASON_PERIODIC:
- return "periodic";
}
return NULL;
}
-static const char *roamingpolicy2string(enum connman_session_roaming_policy policy)
+static const char *state2string(enum connman_session_state state)
{
- switch (policy) {
- case CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN:
- return "unknown";
- case CONNMAN_SESSION_ROAMING_POLICY_DEFAULT:
- return "default";
- case CONNMAN_SESSION_ROAMING_POLICY_ALWAYS:
- return "always";
- case CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN:
- return "forbidden";
- case CONNMAN_SESSION_ROAMING_POLICY_NATIONAL:
- return "national";
- case CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL:
- return "international";
+ switch (state) {
+ case CONNMAN_SESSION_STATE_DISCONNECTED:
+ return "disconnected";
+ case CONNMAN_SESSION_STATE_CONNECTED:
+ return "connected";
+ case CONNMAN_SESSION_STATE_ONLINE:
+ return "online";
}
return NULL;
}
-static enum connman_session_roaming_policy string2roamingpolicy(const char *policy)
+static const char *type2string(enum connman_session_type type)
{
- if (g_strcmp0(policy, "default") == 0)
- return CONNMAN_SESSION_ROAMING_POLICY_DEFAULT;
- else if (g_strcmp0(policy, "always") == 0)
- return CONNMAN_SESSION_ROAMING_POLICY_ALWAYS;
- else if (g_strcmp0(policy, "forbidden") == 0)
- return CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN;
- else if (g_strcmp0(policy, "national") == 0)
- return CONNMAN_SESSION_ROAMING_POLICY_NATIONAL;
- else if (g_strcmp0(policy, "international") == 0)
- return CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL;
- else
- return CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN;
+ switch (type) {
+ case CONNMAN_SESSION_TYPE_UNKNOWN:
+ return "";
+ case CONNMAN_SESSION_TYPE_ANY:
+ return "any";
+ case CONNMAN_SESSION_TYPE_LOCAL:
+ return "local";
+ case CONNMAN_SESSION_TYPE_INTERNET:
+ return "internet";
+ }
+
+ return NULL;
+}
+
+static enum connman_session_type string2type(const char *type)
+{
+ if (g_strcmp0(type, "any") == 0)
+ return CONNMAN_SESSION_TYPE_ANY;
+ if (g_strcmp0(type, "local") == 0)
+ return CONNMAN_SESSION_TYPE_LOCAL;
+ else if (g_strcmp0(type, "internet") == 0)
+ return CONNMAN_SESSION_TYPE_INTERNET;
+
+ return CONNMAN_SESSION_TYPE_UNKNOWN;
}
static enum connman_service_type bearer2service(const char *bearer)
return CONNMAN_SERVICE_TYPE_WIMAX;
else if (g_strcmp0(bearer, "bluetooth") == 0)
return CONNMAN_SERVICE_TYPE_BLUETOOTH;
- else if (g_strcmp0(bearer, "3g") == 0)
+ else if (g_strcmp0(bearer, "cellular") == 0)
return CONNMAN_SERVICE_TYPE_CELLULAR;
else if (g_strcmp0(bearer, "vpn") == 0)
return CONNMAN_SERVICE_TYPE_VPN;
case CONNMAN_SERVICE_TYPE_BLUETOOTH:
return "bluetooth";
case CONNMAN_SERVICE_TYPE_CELLULAR:
- return "3g";
+ return "cellular";
case CONNMAN_SERVICE_TYPE_VPN:
return "vpn";
case CONNMAN_SERVICE_TYPE_UNKNOWN:
return "";
}
-static void cleanup_bearer_info(gpointer data, gpointer user_data)
+static int assign_policy_plugin(struct connman_session *session)
+{
+ GSList *list;
+ struct connman_session_policy *policy;
+
+ if (session->policy != NULL)
+ return -EALREADY;
+
+ for (list = policy_list; list != NULL; list = list->next) {
+ policy = list->data;
+
+ session->policy = policy;
+ break;
+ }
+
+ return 0;
+}
+
+static int create_policy_config(struct connman_session *session)
+{
+ struct connman_session_config *config;
+
+ if (session->policy == NULL)
+ config = connman_session_create_default_config();
+ else
+ config = (*session->policy->create)(session);
+
+ if (config == NULL)
+ return -ENOMEM;
+
+ session->policy_config = config;
+
+ return 0;
+}
+
+static void destroy_policy_config(struct connman_session *session)
+{
+ if (session->policy == NULL) {
+ connman_session_free_bearers(
+ session->policy_config->allowed_bearers);
+ g_free(session->policy_config);
+ } else {
+ (*session->policy->destroy)(session);
+ }
+}
+
+static void probe_policy(struct connman_session_policy *policy)
+{
+
+ GHashTableIter iter;
+ gpointer key, value;
+ struct connman_session *session;
+
+ DBG("policy %p name %s", policy, policy->name);
+
+ g_hash_table_iter_init(&iter, session_hash);
+
+ while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ session = value;
+
+ if (session->policy != NULL)
+ continue;
+
+ assign_policy_plugin(session);
+ }
+}
+
+static void remove_policy(struct connman_session_policy *policy)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+ struct connman_session *session;
+
+ DBG("policy %p name %s", policy, policy->name);
+
+ g_hash_table_iter_init(&iter, session_hash);
+
+ while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ session = value;
+
+ if (session->policy != policy)
+ continue;
+
+ session->policy = NULL;
+ assign_policy_plugin(session);
+ }
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+ const struct connman_session_policy *policy1 = a;
+ const struct connman_session_policy *policy2 = b;
+
+ return policy2->priority - policy1->priority;
+}
+
+
+int connman_session_policy_register(struct connman_session_policy *policy)
+{
+ DBG("name %s", policy->name);
+
+ policy_list = g_slist_insert_sorted(policy_list, policy,
+ compare_priority);
+
+ probe_policy(policy);
+
+ return 0;
+}
+
+void connman_session_policy_unregister(struct connman_session_policy *policy)
+{
+ DBG("name %s", policy->name);
+
+ policy_list = g_slist_remove(policy_list, policy);
+
+ remove_policy(policy);
+}
+
+struct connman_session_config *connman_session_create_default_config(void)
+{
+ struct connman_session_config *config;
+
+ config = g_try_new0(struct connman_session_config, 1);
+ if (config == NULL)
+ return NULL;
+
+ config->priority = FALSE;
+ config->roaming_policy = CONNMAN_SESSION_ROAMING_POLICY_DEFAULT;
+ config->type = CONNMAN_SESSION_TYPE_ANY;
+ config->ecall = FALSE;
+ config->allowed_bearers = connman_session_allowed_bearers_any();
+ if (config->allowed_bearers == NULL) {
+ g_free(config);
+ return NULL;
+ }
+
+ return config;
+}
+
+static enum connman_session_type apply_policy_on_type(
+ enum connman_session_type policy,
+ enum connman_session_type type)
{
- struct bearer_info *info = data;
+ if (type == CONNMAN_SESSION_TYPE_UNKNOWN)
+ return CONNMAN_SESSION_TYPE_UNKNOWN;
+
+ if (policy == CONNMAN_SESSION_TYPE_ANY)
+ return type;
+
+ if (policy == CONNMAN_SESSION_TYPE_LOCAL)
+ return CONNMAN_SESSION_TYPE_LOCAL;
+
+ return CONNMAN_SESSION_TYPE_INTERNET;
+}
+
+static void cleanup_bearer(gpointer data)
+{
+ struct connman_session_bearer *bearer = data;
+
+ g_free(bearer->name);
+ g_free(bearer);
+}
- g_free(info->name);
- g_free(info);
+void connman_session_free_bearers(GSList *bearers)
+{
+ g_slist_free_full(bearers, cleanup_bearer);
}
-static GSList *session_parse_allowed_bearers(DBusMessageIter *iter)
+static int session_parse_allowed_bearers(DBusMessageIter *iter, GSList **list)
{
- struct bearer_info *info;
+ struct connman_session_bearer *bearer;
DBusMessageIter array;
- GSList *list = NULL;
dbus_message_iter_recurse(iter, &array);
- while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
- char *bearer = NULL;
+ *list = NULL;
- dbus_message_iter_get_basic(&array, &bearer);
+ while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
+ char *bearer_name = NULL;
- info = g_try_new0(struct bearer_info, 1);
- if (info == NULL) {
- g_slist_foreach(list, cleanup_bearer_info, NULL);
- g_slist_free(list);
+ dbus_message_iter_get_basic(&array, &bearer_name);
- return NULL;
+ bearer = g_try_new0(struct connman_session_bearer, 1);
+ if (bearer == NULL) {
+ connman_session_free_bearers(*list);
+ *list = NULL;
+ return -ENOMEM;
}
- info->name = g_strdup(bearer);
- info->service_type = bearer2service(info->name);
+ bearer->name = g_strdup(bearer_name);
+ bearer->service_type = bearer2service(bearer->name);
- if (info->service_type == CONNMAN_SERVICE_TYPE_UNKNOWN &&
- g_strcmp0(info->name, "*") == 0) {
- info->match_all = TRUE;
+ if (bearer->service_type == CONNMAN_SERVICE_TYPE_UNKNOWN &&
+ g_strcmp0(bearer->name, "*") == 0) {
+ bearer->match_all = TRUE;
} else {
- info->match_all = FALSE;
+ bearer->match_all = FALSE;
}
- list = g_slist_append(list, info);
+ *list = g_slist_append(*list, bearer);
dbus_message_iter_next(&array);
}
- return list;
+ return 0;
}
-static GSList *session_allowed_bearers_any(void)
+static struct connman_session_bearer *clone_bearer(
+ struct connman_session_bearer *orig)
{
- struct bearer_info *info;
- GSList *list = NULL;
-
- info = g_try_new0(struct bearer_info, 1);
- if (info == NULL) {
- g_slist_free(list);
+ struct connman_session_bearer *bearer;
+ bearer = g_try_new0(struct connman_session_bearer, 1);
+ if (bearer == NULL)
return NULL;
+
+ bearer->name = g_strdup(orig->name);
+ bearer->match_all = orig->match_all;
+ bearer->service_type = orig->service_type;
+
+ return bearer;
+}
+
+static int filter_bearer(GSList *policy_bearers,
+ struct connman_session_bearer *bearer,
+ GSList **list)
+{
+ struct connman_session_bearer *policy, *tmp;
+ GSList *it;
+
+ if (policy_bearers == NULL)
+ goto clone;
+
+ for (it = policy_bearers; it != NULL; it = it->next) {
+ policy = it->data;
+
+ if (policy->match_all == FALSE &&
+ bearer->service_type != policy->service_type)
+ continue;
+
+ goto clone;
+ }
+
+ *list = NULL;
+
+ return 0;
+
+clone:
+ tmp = clone_bearer(bearer);
+ if (tmp == NULL) {
+ connman_session_free_bearers(*list);
+ *list = NULL;
+ return -ENOMEM;
+ }
+ *list = g_slist_append(*list, tmp);
+
+ return 0;
+}
+
+static connman_bool_t is_bearer_valid(struct connman_session_bearer *bearer)
+{
+ if (bearer->match_all == FALSE &&
+ bearer->service_type == CONNMAN_SERVICE_TYPE_UNKNOWN)
+ return FALSE;
+
+ return TRUE;
+}
+
+static int apply_policy_on_bearers(GSList *policy_bearers, GSList *bearers,
+ GSList **list)
+{
+ struct connman_session_bearer *bearer;
+ GSList *it;
+ int err;
+
+ *list = NULL;
+
+ for (it = bearers; it != NULL; it = it->next) {
+ bearer = it->data;
+
+ if (is_bearer_valid(bearer) == FALSE)
+ continue;
+
+ err = filter_bearer(policy_bearers, bearer, list);
+ if (err < 0)
+ return err;
}
- info->name = g_strdup("");
- info->match_all = TRUE;
- info->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
+ return 0;
+}
+
+GSList *connman_session_allowed_bearers_any(void)
+{
+ struct connman_session_bearer *bearer;
+ GSList *list = NULL;
+
+ bearer = g_try_new0(struct connman_session_bearer, 1);
+ if (bearer == NULL)
+ return NULL;
- list = g_slist_append(list, info);
+ bearer->name = g_strdup("");
+ bearer->match_all = TRUE;
+ bearer->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
+
+ list = g_slist_append(list, bearer);
return list;
}
struct session_info *info = user_data;
GSList *list;
- for (list = info->allowed_bearers;
+ for (list = info->config.allowed_bearers;
list != NULL; list = list->next) {
- struct bearer_info *info = list->data;
+ struct connman_session_bearer *bearer = list->data;
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
- &info->name);
+ &bearer->name);
}
}
if (service == NULL)
return;
+ if (__connman_service_is_connected_state(service,
+ CONNMAN_IPCONFIG_TYPE_IPV4) == FALSE) {
+ return;
+ }
+
ipconfig_ipv4 = __connman_service_get_ip4config(service);
if (ipconfig_ipv4 == NULL)
return;
if (service == NULL)
return;
+ if (__connman_service_is_connected_state(service,
+ CONNMAN_IPCONFIG_TYPE_IPV6) == FALSE) {
+ return;
+ }
+
ipconfig_ipv4 = __connman_service_get_ip4config(service);
ipconfig_ipv6 = __connman_service_get_ip6config(service);
if (ipconfig_ipv6 == NULL)
{
struct session_info *info = session->info;
struct session_info *info_last = session->info_last;
- const char *policy;
struct connman_service *service;
const char *name, *ifname, *bearer;
if (session->append_all == TRUE ||
- info->online != info_last->online) {
- connman_dbus_dict_append_basic(dict, "Online",
- DBUS_TYPE_BOOLEAN,
- &info->online);
- info_last->online = info->online;
+ info->state != info_last->state) {
+ const char *state = state2string(info->state);
+
+ connman_dbus_dict_append_basic(dict, "State",
+ DBUS_TYPE_STRING,
+ &state);
+ info_last->state = info->state;
}
if (session->append_all == TRUE ||
info_last->entry = info->entry;
}
-
if (session->append_all == TRUE ||
- info->priority != info_last->priority) {
- connman_dbus_dict_append_basic(dict, "Priority",
- DBUS_TYPE_BOOLEAN,
- &info->priority);
- info_last->priority = info->priority;
+ info->config.type != info_last->config.type) {
+ const char *type = type2string(info->config.type);
+
+ connman_dbus_dict_append_basic(dict, "ConnectionType",
+ DBUS_TYPE_STRING,
+ &type);
+ info_last->config.type = info->config.type;
}
if (session->append_all == TRUE ||
- info->allowed_bearers != info_last->allowed_bearers) {
+ info->config.allowed_bearers != info_last->config.allowed_bearers) {
connman_dbus_dict_append_array(dict, "AllowedBearers",
DBUS_TYPE_STRING,
append_allowed_bearers,
info);
- info_last->allowed_bearers = info->allowed_bearers;
+ info_last->config.allowed_bearers = info->config.allowed_bearers;
}
- if (session->append_all == TRUE ||
- info->avoid_handover != info_last->avoid_handover) {
- connman_dbus_dict_append_basic(dict, "AvoidHandover",
- DBUS_TYPE_BOOLEAN,
- &info->avoid_handover);
- info_last->avoid_handover = info->avoid_handover;
- }
+ session->append_all = FALSE;
+}
- if (session->append_all == TRUE ||
- info->stay_connected != info_last->stay_connected) {
- connman_dbus_dict_append_basic(dict, "StayConnected",
- DBUS_TYPE_BOOLEAN,
- &info->stay_connected);
- info_last->stay_connected = info->stay_connected;
- }
+static connman_bool_t is_type_matching_state(enum connman_session_state *state,
+ enum connman_session_type type)
+{
+ switch (type) {
+ case CONNMAN_SESSION_TYPE_UNKNOWN:
+ return FALSE;
+ case CONNMAN_SESSION_TYPE_ANY:
+ return TRUE;
+ case CONNMAN_SESSION_TYPE_LOCAL:
+ if (*state >= CONNMAN_SESSION_STATE_CONNECTED) {
+ *state = CONNMAN_SESSION_STATE_CONNECTED;
+ return TRUE;
+ }
- if (session->append_all == TRUE ||
- info->periodic_connect != info_last->periodic_connect) {
- connman_dbus_dict_append_basic(dict, "PeriodicConnect",
- DBUS_TYPE_UINT32,
- &info->periodic_connect);
- info_last->periodic_connect = info->periodic_connect;
+ break;
+ case CONNMAN_SESSION_TYPE_INTERNET:
+ if (*state == CONNMAN_SESSION_STATE_ONLINE)
+ return TRUE;
+ break;
}
- if (session->append_all == TRUE ||
- info->idle_timeout != info_last->idle_timeout) {
- connman_dbus_dict_append_basic(dict, "IdleTimeout",
- DBUS_TYPE_UINT32,
- &info->idle_timeout);
- info_last->idle_timeout = info->idle_timeout;
- }
+ return FALSE;
+}
- if (session->append_all == TRUE ||
- info->ecall != info_last->ecall) {
- connman_dbus_dict_append_basic(dict, "EmergencyCall",
- DBUS_TYPE_BOOLEAN,
- &info->ecall);
- info_last->ecall = info->ecall;
- }
+static connman_bool_t compute_notifiable_changes(struct connman_session *session)
+{
+ struct session_info *info_last = session->info_last;
+ struct session_info *info = session->info;
- if (session->append_all == TRUE ||
- info->roaming_policy != info_last->roaming_policy) {
- policy = roamingpolicy2string(info->roaming_policy);
- connman_dbus_dict_append_basic(dict, "RoamingPolicy",
- DBUS_TYPE_STRING,
- &policy);
- info_last->roaming_policy = info->roaming_policy;
- }
+ if (session->append_all == TRUE)
+ return TRUE;
- if (session->append_all == TRUE ||
- info->marker != info_last->marker) {
- connman_dbus_dict_append_basic(dict, "SessionMarker",
- DBUS_TYPE_UINT32,
- &info->marker);
- info_last->marker = info->marker;
- }
+ if (info->state != info_last->state)
+ return TRUE;
- session->append_all = FALSE;
- session->info_dirty = FALSE;
+ if (info->entry != info_last->entry &&
+ info->state >= CONNMAN_SESSION_STATE_CONNECTED)
+ return TRUE;
+
+ if (info->config.allowed_bearers != info_last->config.allowed_bearers ||
+ info->config.type != info_last->config.type)
+ return TRUE;
+
+ return FALSE;
}
static gboolean session_notify(gpointer user_data)
DBusMessage *msg;
DBusMessageIter array, dict;
- if (session->info_dirty == FALSE)
- return 0;
+ if (compute_notifiable_changes(session) == FALSE)
+ return FALSE;
DBG("session %p owner %s notify_path %s", session,
session->owner, session->notify_path);
g_dbus_send_message(connection, msg);
- session->info_dirty = FALSE;
-
return FALSE;
}
struct session_info *info = session->info;
GSList *list;
- for (list = info->allowed_bearers;
+ for (list = info->config.allowed_bearers;
list != NULL; list = list->next) {
- struct bearer_info *info = list->data;
+ struct connman_session_bearer *bearer = list->data;
enum connman_service_type service_type;
- if (info->match_all == TRUE)
+ if (bearer->match_all == TRUE)
return TRUE;
service_type = connman_service_get_type(service);
- if (info->service_type == service_type)
+ if (bearer->service_type == service_type)
return TRUE;
}
* 1. Ethernet
* 2. Bluetooth
* 3. WiFi/WiMAX
- * 4. GSM/UTMS/3G
+ * 4. Cellular
*/
switch (type) {
type_a = connman_service_get_type(service_a);
type_b = connman_service_get_type(service_b);
- for (list = info->allowed_bearers;
+ for (list = info->config.allowed_bearers;
list != NULL; list = list->next) {
- struct bearer_info *info = list->data;
+ struct connman_session_bearer *bearer = list->data;
- if (info->match_all == TRUE) {
+ if (bearer->match_all == TRUE) {
if (type_a != type_b) {
weight_a = service_type_weight(type_a);
weight_b = service_type_weight(type_b);
}
}
- if (type_a == info->service_type &&
- type_b == info->service_type) {
+ if (type_a == bearer->service_type &&
+ type_b == bearer->service_type) {
return 0;
}
- if (type_a == info->service_type &&
- type_b != info->service_type) {
+ if (type_a == bearer->service_type &&
+ type_b != bearer->service_type) {
return -1;
}
- if (type_a != info->service_type &&
- type_b == info->service_type) {
+ if (type_a != bearer->service_type &&
+ type_b == bearer->service_type) {
return 1;
}
}
__connman_service_disconnect(info->entry->service);
}
- g_slist_foreach(info->allowed_bearers, cleanup_bearer_info, NULL);
- g_slist_free(info->allowed_bearers);
-
+ destroy_policy_config(session);
+ connman_session_free_bearers(session->info->config.allowed_bearers);
g_free(session->owner);
g_free(session->session_path);
g_free(session->notify_path);
g_free(session);
}
-static connman_bool_t is_online(enum connman_service_state state)
+static enum connman_session_state service_to_session_state(enum connman_service_state state)
{
switch (state) {
case CONNMAN_SERVICE_STATE_UNKNOWN:
case CONNMAN_SERVICE_STATE_CONFIGURATION:
case CONNMAN_SERVICE_STATE_DISCONNECT:
case CONNMAN_SERVICE_STATE_FAILURE:
+ break;
case CONNMAN_SERVICE_STATE_READY:
+ return CONNMAN_SESSION_STATE_CONNECTED;
+ case CONNMAN_SERVICE_STATE_ONLINE:
+ return CONNMAN_SESSION_STATE_ONLINE;
+ }
+
+ return CONNMAN_SESSION_STATE_DISCONNECTED;
+}
+
+static connman_bool_t is_connected(enum connman_service_state state)
+{
+ switch (state) {
+ case CONNMAN_SERVICE_STATE_UNKNOWN:
+ case CONNMAN_SERVICE_STATE_IDLE:
+ case CONNMAN_SERVICE_STATE_ASSOCIATION:
+ case CONNMAN_SERVICE_STATE_CONFIGURATION:
+ case CONNMAN_SERVICE_STATE_DISCONNECT:
+ case CONNMAN_SERVICE_STATE_FAILURE:
break;
+ case CONNMAN_SERVICE_STATE_READY:
case CONNMAN_SERVICE_STATE_ONLINE:
return TRUE;
}
break;
case CONNMAN_SERVICE_STATE_ASSOCIATION:
case CONNMAN_SERVICE_STATE_CONFIGURATION:
- case CONNMAN_SERVICE_STATE_READY:
return TRUE;
case CONNMAN_SERVICE_STATE_DISCONNECT:
case CONNMAN_SERVICE_STATE_FAILURE:
+ case CONNMAN_SERVICE_STATE_READY:
case CONNMAN_SERVICE_STATE_ONLINE:
break;
}
case CONNMAN_SESSION_REASON_FREE_RIDE:
break;
case CONNMAN_SESSION_REASON_CONNECT:
- case CONNMAN_SESSION_REASON_PERIODIC:
return TRUE;
}
return FALSE;
}
-static connman_bool_t explicit_disconnect(struct connman_session *session)
+static connman_bool_t explicit_disconnect(struct session_info *info)
{
- struct session_info *info = session->info;
-
if (info->entry == NULL)
return FALSE;
- DBG("session %p, reason %s service %p state %d",
- session, reason2string(info->entry->reason),
+ DBG("reason %s service %p state %d",
+ reason2string(info->entry->reason),
info->entry->service, info->entry->state);
if (info->entry->reason == CONNMAN_SESSION_REASON_UNKNOWN)
if (__connman_service_session_dec(info->entry->service) == FALSE)
return FALSE;
- if (ecall_session != NULL && ecall_session != session)
- return FALSE;
-
return TRUE;
}
-static gboolean call_disconnect(gpointer user_data)
-{
- struct connman_service *service = user_data;
+struct pending_data {
+ unsigned int timeout;
+ struct service_entry *entry;
+ gboolean (*cb)(gpointer);
+};
- /*
- * TODO: We should mark this entry as pending work. In case
- * disconnect fails we just unassign this session from the
- * service and can't do anything later on it
- */
- DBG("disconnect service %p", service);
- __connman_service_disconnect(service);
+static void pending_timeout_free(gpointer data, gpointer user_data)
+{
+ struct pending_data *pending = data;
- return FALSE;
+ DBG("pending %p timeout %d", pending, pending->timeout);
+ g_source_remove(pending->timeout);
+ g_free(pending);
}
-static gboolean call_connect(gpointer user_data)
+static void pending_timeout_remove_all(struct service_entry *entry)
{
- struct connman_service *service = user_data;
+ DBG("");
- DBG("connect service %p", service);
- __connman_service_connect(service);
+ g_slist_foreach(entry->pending_timeouts, pending_timeout_free, NULL);
+ g_slist_free(entry->pending_timeouts);
+ entry->pending_timeouts = NULL;
+}
+
+static gboolean pending_timeout_cb(gpointer data)
+{
+ struct pending_data *pending = data;
+ struct service_entry *entry = pending->entry;
+ gboolean ret;
+
+ DBG("pending %p timeout %d", pending, pending->timeout);
+
+ ret = pending->cb(pending->entry);
+ if (ret == FALSE) {
+ entry->pending_timeouts =
+ g_slist_remove(entry->pending_timeouts,
+ pending);
+ g_free(pending);
+ }
+ return ret;
+}
+
+static connman_bool_t pending_timeout_add(unsigned int seconds,
+ gboolean (*cb)(gpointer),
+ struct service_entry *entry)
+{
+ struct pending_data *pending = g_try_new0(struct pending_data, 1);
+
+ if (pending == NULL || cb == NULL || entry == NULL) {
+ g_free(pending);
+ return FALSE;
+ }
+
+ pending->cb = cb;
+ pending->entry = entry;
+ pending->timeout = g_timeout_add_seconds(seconds, pending_timeout_cb,
+ pending);
+ entry->pending_timeouts = g_slist_prepend(entry->pending_timeouts,
+ pending);
+
+ DBG("pending %p entry %p timeout id %d", pending, entry,
+ pending->timeout);
+
+ return TRUE;
+}
+
+static gboolean call_disconnect(gpointer user_data)
+{
+ struct service_entry *entry = user_data;
+ struct connman_service *service = entry->service;
+
+ /*
+ * TODO: We should mark this entry as pending work. In case
+ * disconnect fails we just unassign this session from the
+ * service and can't do anything later on it
+ */
+ DBG("disconnect service %p", service);
+ __connman_service_disconnect(service);
return FALSE;
}
-static void test_and_disconnect(struct connman_session *session)
+static gboolean call_connect(gpointer user_data)
{
- struct session_info *info = session->info;
- struct connman_service *service;
- connman_bool_t disconnect, online;
+ struct service_entry *entry = user_data;
+ struct connman_service *service = entry->service;
+
+ DBG("connect service %p", service);
+ __connman_service_connect(service);
+
+ return FALSE;
+}
+
+static void deselect_service(struct session_info *info)
+{
+ struct service_entry *entry;
+ connman_bool_t disconnect, connected;
+
+ DBG("");
if (info->entry == NULL)
return;
- disconnect = explicit_disconnect(session);
+ disconnect = explicit_disconnect(info);
- online = is_connecting(info->entry->state) == TRUE ||
- is_online(info->entry->state) == TRUE;
+ connected = is_connecting(info->entry->state) == TRUE ||
+ is_connected(info->entry->state) == TRUE;
- info->online = FALSE;
- info->reason = CONNMAN_SESSION_REASON_UNKNOWN;
+ info->state = CONNMAN_SESSION_STATE_DISCONNECTED;
info->entry->reason = CONNMAN_SESSION_REASON_UNKNOWN;
- service = info->entry->service;
+ entry = info->entry;
info->entry = NULL;
- if (disconnect == TRUE && online == TRUE)
- g_timeout_add_seconds(0, call_disconnect, service);
+ DBG("disconnect %d connected %d", disconnect, connected);
+
+ if (disconnect == TRUE && connected == TRUE)
+ pending_timeout_add(0, call_disconnect, entry);
}
-static void deselect_previous_service(struct connman_session *session,
- struct service_entry *entry)
+static void deselect_and_disconnect(struct connman_session *session)
{
struct session_info *info = session->info;
- if (info->entry != NULL && info->entry != entry)
- test_and_disconnect(session);
+ deselect_service(info);
+
+ info->reason = CONNMAN_SESSION_REASON_FREE_RIDE;
}
-static void select_online_service(struct connman_session *session,
+static void select_connected_service(struct session_info *info,
struct service_entry *entry)
{
- struct session_info *info = session->info;
+ enum connman_session_state state;
+
+ state = service_to_session_state(entry->state);
+ if (is_type_matching_state(&state, info->config.type) == FALSE)
+ return;
- info->online = TRUE;
+ info->state = state;
info->entry = entry;
info->entry->reason = info->reason;
__connman_service_session_inc(info->entry->service);
}
-static void select_offline_service(struct connman_session *session,
+static void select_offline_service(struct session_info *info,
struct service_entry *entry)
{
- struct session_info *info = session->info;
-
- if (explicit_connect(info->reason) == FALSE) {
- /* Don't select this service. It is not online and we
- * don't call connect on it. This happends for example
- * when the system is idle and we create a new session
- * which is in free ride mode.
- */
+ if (explicit_connect(info->reason) == FALSE)
return;
- }
- info->online = FALSE;
+ info->state = service_to_session_state(entry->state);
info->entry = entry;
info->entry->reason = info->reason;
__connman_service_session_inc(info->entry->service);
- g_timeout_add_seconds(0, call_connect, info->entry->service);
+ pending_timeout_add(0, call_connect, entry);
}
-static void select_service(struct connman_session *session,
+static void select_service(struct session_info *info,
struct service_entry *entry)
{
- DBG("session %p service %p", session, entry->service);
-
- deselect_previous_service(session, entry);
+ DBG("service %p", entry->service);
- if (is_online(entry->state) == TRUE)
- select_online_service(session, entry);
+ if (is_connected(entry->state) == TRUE)
+ select_connected_service(info, entry);
else
- select_offline_service(session, entry);
+ select_offline_service(info, entry);
}
static void select_and_connect(struct connman_session *session,
case CONNMAN_SERVICE_STATE_ONLINE:
case CONNMAN_SERVICE_STATE_IDLE:
case CONNMAN_SERVICE_STATE_DISCONNECT:
- select_service(session, entry);
+ select_service(info, entry);
return;
case CONNMAN_SERVICE_STATE_UNKNOWN:
case CONNMAN_SERVICE_STATE_FAILURE:
}
}
-static void session_changed(struct connman_session *session,
- enum connman_session_trigger trigger)
-{
- struct session_info *info = session->info;
- struct session_info *info_last = session->info_last;
- GSequenceIter *iter;
-
- /*
- * TODO: This only a placeholder for the 'real' algorithm to
- * play a bit around. So we are going to improve it step by step.
- */
-
- DBG("session %p trigger %s", session, trigger2string(trigger));
-
- switch (trigger) {
- case CONNMAN_SESSION_TRIGGER_UNKNOWN:
- DBG("ignore session changed event");
- return;
- case CONNMAN_SESSION_TRIGGER_SETTING:
- if (info->entry != NULL) {
- iter = g_hash_table_lookup(session->service_hash,
- info->entry->service);
- if (iter == NULL) {
- /*
- * This service is not part of this
- * session anymore.
- */
- test_and_disconnect(session);
- }
- }
-
- if (info->online == FALSE) {
- select_and_connect(session,
- CONNMAN_SESSION_REASON_FREE_RIDE);
- }
-
- break;
- case CONNMAN_SESSION_TRIGGER_CONNECT:
- if (info->online == TRUE) {
- if (info->entry->reason == CONNMAN_SESSION_REASON_CONNECT)
- break;
- info->entry->reason = CONNMAN_SESSION_REASON_CONNECT;
- __connman_service_session_inc(info->entry->service);
- break;
- }
-
- select_and_connect(session,
- CONNMAN_SESSION_REASON_CONNECT);
-
- break;
- case CONNMAN_SESSION_TRIGGER_DISCONNECT:
- test_and_disconnect(session);
-
- break;
- case CONNMAN_SESSION_TRIGGER_PERIODIC:
- if (info->online == TRUE) {
- info->entry->reason = CONNMAN_SESSION_REASON_PERIODIC;
- __connman_service_session_inc(info->entry->service);
- break;
- }
-
- select_and_connect(session,
- CONNMAN_SESSION_REASON_PERIODIC);
-
- break;
- case CONNMAN_SESSION_TRIGGER_SERVICE:
- if (info->entry != NULL &&
- (is_connecting(info->entry->state) == TRUE ||
- is_online(info->entry->state) == TRUE)) {
- break;
- }
-
- switch (info->reason) {
- case CONNMAN_SESSION_REASON_CONNECT:
- /*
- * We are not online, we are not connecting, that
- * means we could still have a valid info->entry.
- * Though something has changed from the service layer.
- * Therefore we want to restart the algorithm. Before we
- * can do that we have to cleanup a potientional old entry.
- */
- test_and_disconnect(session);
- info->reason = CONNMAN_SESSION_REASON_CONNECT; /* restore value */
-
- DBG("Retry to find a matching session");
- /*
- * The user called Connect() but there was no
- * matching session available at this point.
- * Now there might be a new one. Let's retry
- * to select and connect
- */
- select_and_connect(session,
- CONNMAN_SESSION_REASON_CONNECT);
- break;
- case CONNMAN_SESSION_REASON_PERIODIC:
- case CONNMAN_SESSION_REASON_FREE_RIDE:
- if (info->stay_connected == TRUE) {
- DBG("StayConnected");
- select_and_connect(session,
- CONNMAN_SESSION_REASON_CONNECT);
- } else {
- select_and_connect(session,
- CONNMAN_SESSION_REASON_FREE_RIDE);
- }
- break;
- case CONNMAN_SESSION_REASON_UNKNOWN:
- break;
- }
- break;
- case CONNMAN_SESSION_TRIGGER_ECALL:
- if (info->online == FALSE && info->entry != NULL &&
- info->entry->service != NULL) {
- test_and_disconnect(session);
- }
-
- break;
- }
-
- if (info->entry != info_last->entry)
- session->info_dirty = TRUE;
-
- session_notify(session);
-}
-
-static DBusMessage *connect_session(DBusConnection *conn,
- DBusMessage *msg, void *user_data)
-{
- struct connman_session *session = user_data;
-
- DBG("session %p", session);
-
- if (ecall_session != NULL && ecall_session != session)
- return __connman_error_failed(msg, EBUSY);
-
- session_changed(session, CONNMAN_SESSION_TRIGGER_CONNECT);
-
- return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-}
-
-static DBusMessage *disconnect_session(DBusConnection *conn,
- DBusMessage *msg, void *user_data)
-{
- struct connman_session *session = user_data;
-
- DBG("session %p", session);
-
- if (ecall_session != NULL && ecall_session != session)
- return __connman_error_failed(msg, EBUSY);
-
- session_changed(session, CONNMAN_SESSION_TRIGGER_DISCONNECT);
-
- return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-}
-
static struct service_entry *create_service_entry(struct connman_service *service,
const char *name,
enum connman_service_state state)
{
struct service_entry *entry = data;
+ pending_timeout_remove_all(entry);
g_free(entry->ifname);
g_free(entry);
}
-static void update_allowed_bearers(struct connman_session *session)
+static void populate_service_list(struct connman_session *session)
{
struct service_entry *entry;
GSequenceIter *iter;
- if (session->service_list != NULL) {
- g_hash_table_remove_all(session->service_hash);
- g_sequence_free(session->service_list);
- }
-
+ session->service_hash =
+ g_hash_table_new_full(g_direct_hash, g_direct_equal,
+ NULL, NULL);
session->service_list = __connman_service_get_list(session,
service_match,
create_service_entry,
iter = g_sequence_iter_next(iter);
}
-
- session->info_dirty = TRUE;
}
-static void update_ecall_sessions(struct connman_session *session)
+static void session_changed(struct connman_session *session,
+ enum connman_session_trigger trigger)
{
struct session_info *info = session->info;
- struct connman_session *session_iter;
- GHashTableIter iter;
- gpointer key, value;
+ struct session_info *info_last = session->info_last;
+ GSequenceIter *service_iter = NULL, *service_iter_last = NULL;
+ GSequence *service_list_last;
+ GHashTable *service_hash_last;
- g_hash_table_iter_init(&iter, session_hash);
+ /*
+ * TODO: This only a placeholder for the 'real' algorithm to
+ * play a bit around. So we are going to improve it step by step.
+ */
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
- session_iter = value;
+ DBG("session %p trigger %s reason %s", session, trigger2string(trigger),
+ reason2string(info->reason));
- if (session_iter == session)
- continue;
+ if (info->entry != NULL) {
+ enum connman_session_state state;
- session_iter->info->ecall = info->ecall;
- session_iter->info_dirty = TRUE;
+ state = service_to_session_state(info->entry->state);
- session_changed(session_iter, CONNMAN_SESSION_TRIGGER_ECALL);
+ if (is_type_matching_state(&state, info->config.type) == TRUE)
+ info->state = state;
}
+
+ switch (trigger) {
+ case CONNMAN_SESSION_TRIGGER_UNKNOWN:
+ DBG("ignore session changed event");
+ return;
+ case CONNMAN_SESSION_TRIGGER_SETTING:
+ if (info->config.allowed_bearers != info_last->config.allowed_bearers) {
+
+ service_hash_last = session->service_hash;
+ service_list_last = session->service_list;
+
+ populate_service_list(session);
+
+ if (info->entry != NULL) {
+ service_iter_last = g_hash_table_lookup(
+ service_hash_last,
+ info->entry->service);
+ service_iter = g_hash_table_lookup(
+ session->service_hash,
+ info->entry->service);
+ }
+
+ if (service_iter == NULL && service_iter_last != NULL) {
+ /*
+ * The currently selected service is
+ * not part of this session anymore.
+ */
+ deselect_and_disconnect(session);
+ }
+
+ g_hash_table_remove_all(service_hash_last);
+ g_sequence_free(service_list_last);
+ }
+
+ if (info->config.type != info_last->config.type) {
+ if (info->state >= CONNMAN_SESSION_STATE_CONNECTED &&
+ is_type_matching_state(&info->state,
+ info->config.type) == FALSE)
+ deselect_and_disconnect(session);
+ }
+
+ if (info->state == CONNMAN_SESSION_STATE_DISCONNECTED) {
+ select_and_connect(session,
+ CONNMAN_SESSION_REASON_FREE_RIDE);
+ }
+
+ break;
+ case CONNMAN_SESSION_TRIGGER_ECALL:
+ /*
+ * For the time beeing we fallback to normal connect
+ * strategy.
+ */
+ case CONNMAN_SESSION_TRIGGER_CONNECT:
+ if (info->state >= CONNMAN_SESSION_STATE_CONNECTED) {
+ if (info->entry->reason == CONNMAN_SESSION_REASON_CONNECT)
+ break;
+ info->entry->reason = CONNMAN_SESSION_REASON_CONNECT;
+ __connman_service_session_inc(info->entry->service);
+ break;
+ }
+
+ if (info->entry != NULL &&
+ is_connecting(info->entry->state) == TRUE) {
+ break;
+ }
+
+ select_and_connect(session,
+ CONNMAN_SESSION_REASON_CONNECT);
+
+ break;
+ case CONNMAN_SESSION_TRIGGER_DISCONNECT:
+ deselect_and_disconnect(session);
+
+ break;
+ case CONNMAN_SESSION_TRIGGER_SERVICE:
+ if (info->entry != NULL &&
+ (is_connecting(info->entry->state) == TRUE ||
+ is_connected(info->entry->state) == TRUE)) {
+ break;
+ }
+
+ deselect_and_disconnect(session);
+
+ if (info->reason == CONNMAN_SESSION_REASON_FREE_RIDE) {
+ select_and_connect(session, info->reason);
+ }
+
+ break;
+ }
+
+ session_notify(session);
}
-static void update_ecall(struct connman_session *session)
+static DBusMessage *connect_session(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
{
- struct session_info *info = session->info;
- struct session_info *info_last = session->info_last;
+ struct connman_session *session = user_data;
- DBG("session %p ecall_session %p ecall %d -> %d", session,
- ecall_session, info_last->ecall, info->ecall);
+ DBG("session %p", session);
- if (ecall_session == NULL) {
- if (!(info_last->ecall == FALSE && info->ecall == TRUE))
- goto err;
+ if (ecall_session != NULL) {
+ if (ecall_session->ecall == TRUE && ecall_session != session)
+ return __connman_error_failed(msg, EBUSY);
- ecall_session = session;
- } else if (ecall_session == session) {
- if (!(info_last->ecall == TRUE && info->ecall == FALSE))
- goto err;
+ session->ecall = TRUE;
+ session_changed(session, CONNMAN_SESSION_TRIGGER_ECALL);
+ } else
+ session_changed(session, CONNMAN_SESSION_TRIGGER_CONNECT);
- ecall_session = NULL;
- } else {
- goto err;
- }
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *disconnect_session(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
+{
+ struct connman_session *session = user_data;
- update_ecall_sessions(session);
+ DBG("session %p", session);
- session->info_dirty = TRUE;
- return;
+ if (ecall_session != NULL) {
+ if (ecall_session->ecall == TRUE && ecall_session != session)
+ return __connman_error_failed(msg, EBUSY);
-err:
- /* not a valid transition */
- info->ecall = info_last->ecall;
+ session->ecall = FALSE;
+ }
+
+ session_changed(session, CONNMAN_SESSION_TRIGGER_DISCONNECT);
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
static DBusMessage *change_session(DBusConnection *conn,
{
struct connman_session *session = user_data;
struct session_info *info = session->info;
- struct session_info *info_last = session->info_last;
DBusMessageIter iter, value;
const char *name;
+ const char *val;
GSList *allowed_bearers;
+ int err;
DBG("session %p", session);
if (dbus_message_iter_init(msg, &iter) == FALSE)
return __connman_error_invalid_arguments(msg);
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return __connman_error_invalid_arguments(msg);
+
dbus_message_iter_get_basic(&iter, &name);
dbus_message_iter_next(&iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+ return __connman_error_invalid_arguments(msg);
+
dbus_message_iter_recurse(&iter, &value);
switch (dbus_message_iter_get_arg_type(&value)) {
case DBUS_TYPE_ARRAY:
if (g_str_equal(name, "AllowedBearers") == TRUE) {
- allowed_bearers = session_parse_allowed_bearers(&value);
-
- g_slist_foreach(info->allowed_bearers,
- cleanup_bearer_info, NULL);
- g_slist_free(info->allowed_bearers);
-
- if (allowed_bearers == NULL) {
- allowed_bearers = session_allowed_bearers_any();
-
- if (allowed_bearers == NULL)
- return __connman_error_failed(msg, ENOMEM);
- }
-
- info->allowed_bearers = allowed_bearers;
-
- update_allowed_bearers(session);
- } else {
- goto err;
- }
- break;
- case DBUS_TYPE_BOOLEAN:
- if (g_str_equal(name, "Priority") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &info->priority);
-
- if (info_last->priority != info->priority)
- session->info_dirty = TRUE;
- } else if (g_str_equal(name, "AvoidHandover") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &info->avoid_handover);
-
- if (info_last->avoid_handover != info->avoid_handover)
- session->info_dirty = TRUE;
- } else if (g_str_equal(name, "StayConnected") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &info->stay_connected);
-
- if (info_last->stay_connected != info->stay_connected)
- session->info_dirty = TRUE;
- } else if (g_str_equal(name, "EmergencyCall") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &info->ecall);
-
- update_ecall(session);
- } else {
- goto err;
- }
- break;
- case DBUS_TYPE_UINT32:
- if (g_str_equal(name, "PeriodicConnect") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &info->periodic_connect);
-
- if (info_last->periodic_connect != info->periodic_connect)
- session->info_dirty = TRUE;
- } else if (g_str_equal(name, "IdleTimeout") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &info->idle_timeout);
-
- if (info_last->idle_timeout != info->idle_timeout)
- session->info_dirty = TRUE;
+ err = session_parse_allowed_bearers(&value,
+ &allowed_bearers);
+ if (err < 0)
+ return __connman_error_failed(msg, err);
+
+ connman_session_free_bearers(info->config.allowed_bearers);
+ err = apply_policy_on_bearers(
+ session->policy_config->allowed_bearers,
+ allowed_bearers,
+ &info->config.allowed_bearers);
+
+ connman_session_free_bearers(allowed_bearers);
+ if (err < 0)
+ return __connman_error_failed(msg, err);
} else {
goto err;
}
break;
case DBUS_TYPE_STRING:
- if (g_str_equal(name, "RoamingPolicy") == TRUE) {
- const char *val;
+ if (g_str_equal(name, "ConnectionType") == TRUE) {
dbus_message_iter_get_basic(&value, &val);
- info->roaming_policy =
- string2roamingpolicy(val);
-
- if (info_last->roaming_policy != info->roaming_policy)
- session->info_dirty = TRUE;
+ info->config.type = apply_policy_on_type(
+ session->policy_config->type,
+ string2type(val));
} else {
goto err;
}
goto err;
}
- if (session->info_dirty == TRUE)
- session_changed(session, CONNMAN_SESSION_TRIGGER_SETTING);
+ session_changed(session, CONNMAN_SESSION_TRIGGER_SETTING);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
g_dbus_unregister_interface(connection, session->session_path,
CONNMAN_SESSION_INTERFACE);
- test_and_disconnect(session);
+ deselect_and_disconnect(session);
g_hash_table_remove(session_hash, session->session_path);
DBG("session %p", session);
+ if (ecall_session != NULL && ecall_session != session)
+ return __connman_error_failed(msg, EBUSY);
+
+ session_disconnect(session);
+
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
-static GDBusMethodTable session_methods[] = {
- { "Destroy", "", "", destroy_session },
- { "Connect", "", "", connect_session },
- { "Disconnect", "", "", disconnect_session },
- { "Change", "sv", "", change_session },
+static const GDBusMethodTable session_methods[] = {
+ { GDBUS_METHOD("Destroy", NULL, NULL, destroy_session) },
+ { GDBUS_METHOD("Connect", NULL, NULL, connect_session) },
+ { GDBUS_METHOD("Disconnect", NULL, NULL,
+ disconnect_session ) },
+ { GDBUS_METHOD("Change",
+ GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
+ NULL, change_session) },
{ },
};
DBusMessageIter iter, array;
struct connman_session *session = NULL;
struct session_info *info, *info_last;
-
- connman_bool_t priority = FALSE, avoid_handover = FALSE;
- connman_bool_t stay_connected = FALSE, ecall = FALSE;
- enum connman_session_roaming_policy roaming_policy =
- CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN;
+ enum connman_session_type type = CONNMAN_SESSION_TYPE_ANY;
GSList *allowed_bearers = NULL;
- unsigned int periodic_connect = 0;
- unsigned int idle_timeout = 0;
-
+ connman_bool_t allowed_bearers_valid = FALSE;
+ connman_bool_t type_valid = FALSE;
int err;
owner = dbus_message_get_sender(msg);
DBG("owner %s", owner);
- if (ecall_session != NULL) {
+ if (ecall_session != NULL && ecall_session->ecall == TRUE) {
/*
* If there is an emergency call already going on,
* ignore session creation attempt
switch (dbus_message_iter_get_arg_type(&value)) {
case DBUS_TYPE_ARRAY:
if (g_str_equal(key, "AllowedBearers") == TRUE) {
- allowed_bearers =
- session_parse_allowed_bearers(&value);
- } else {
- return -EINVAL;
- }
- break;
- case DBUS_TYPE_BOOLEAN:
- if (g_str_equal(key, "Priority") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &priority);
- } else if (g_str_equal(key, "AvoidHandover") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &avoid_handover);
- } else if (g_str_equal(key, "StayConnected") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &stay_connected);
- } else if (g_str_equal(key, "EmergencyCall") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &ecall);
- } else {
- return -EINVAL;
- }
- break;
- case DBUS_TYPE_UINT32:
- if (g_str_equal(key, "PeriodicConnect") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &periodic_connect);
- } else if (g_str_equal(key, "IdleTimeout") == TRUE) {
- dbus_message_iter_get_basic(&value,
- &idle_timeout);
+ err = session_parse_allowed_bearers(&value,
+ &allowed_bearers);
+ if (err < 0)
+ goto err;
+
+ allowed_bearers_valid = TRUE;
} else {
return -EINVAL;
}
break;
case DBUS_TYPE_STRING:
- if (g_str_equal(key, "RoamingPolicy") == TRUE) {
+ if (g_str_equal(key, "ConnectionType") == TRUE) {
dbus_message_iter_get_basic(&value, &val);
- roaming_policy = string2roamingpolicy(val);
+ type = string2type(val);
+ type_valid = TRUE;
} else {
return -EINVAL;
}
g_dbus_add_disconnect_watch(connection, session->owner,
owner_disconnect, session, NULL);
- session->service_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
- NULL, NULL);
-
- info->online = FALSE;
- info->priority = priority;
- info->avoid_handover = avoid_handover;
- info->stay_connected = stay_connected;
- info->periodic_connect = periodic_connect;
- info->idle_timeout = idle_timeout;
- info->ecall = ecall;
- info->roaming_policy = roaming_policy;
- info->entry = NULL;
- info->marker = 0;
+ err = assign_policy_plugin(session);
+ if (err < 0)
+ goto err;
+ err = create_policy_config(session);
+ if (err < 0)
+ goto err;
- if (allowed_bearers == NULL) {
- info->allowed_bearers =
- session_allowed_bearers_any();
+ if (session->policy_config->ecall == TRUE)
+ ecall_session = session;
- if (info->allowed_bearers == NULL) {
+ info->state = CONNMAN_SESSION_STATE_DISCONNECTED;
+ if (type_valid == FALSE)
+ type = CONNMAN_SESSION_TYPE_ANY;
+ info->config.type = apply_policy_on_type(
+ session->policy_config->type,
+ type);
+ info->config.priority = session->policy_config->priority;
+ info->config.roaming_policy = session->policy_config->roaming_policy;
+ info->entry = NULL;
+
+ if (allowed_bearers_valid == FALSE) {
+ allowed_bearers = connman_session_allowed_bearers_any();
+ if (allowed_bearers == NULL) {
err = -ENOMEM;
goto err;
}
- } else {
- info->allowed_bearers = allowed_bearers;
}
+ err = apply_policy_on_bearers(
+ session->policy_config->allowed_bearers,
+ allowed_bearers,
+ &info->config.allowed_bearers);
+ if (err < 0)
+ goto err;
+
g_hash_table_replace(session_hash, session->session_path, session);
DBG("add %s", session->session_path);
DBUS_TYPE_INVALID);
- update_allowed_bearers(session);
- if (info->ecall == TRUE) {
- ecall_session = session;
- update_ecall_sessions(session);
- }
+ populate_service_list(session);
- info_last->online = info->online;
- info_last->priority = info->priority;
- info_last->avoid_handover = info->avoid_handover;
- info_last->stay_connected = info->stay_connected;
- info_last->periodic_connect = info->periodic_connect;
- info_last->idle_timeout = info->idle_timeout;
- info_last->ecall = info->ecall;
- info_last->roaming_policy = info->roaming_policy;
+ info_last->state = info->state;
+ info_last->config.priority = info->config.priority;
+ info_last->config.roaming_policy = info->config.roaming_policy;
info_last->entry = info->entry;
- info_last->marker = info->marker;
- info_last->allowed_bearers = info->allowed_bearers;
+ info_last->config.allowed_bearers = info->config.allowed_bearers;
- session->info_dirty = TRUE;
session->append_all = TRUE;
session_changed(session, CONNMAN_SESSION_TRIGGER_SETTING);
g_free(session_path);
- g_slist_foreach(allowed_bearers, cleanup_bearer_info, NULL);
- g_slist_free(allowed_bearers);
+ connman_session_free_bearers(allowed_bearers);
return err;
}
{
DBG("enable %d", enable);
- sessionmode = enable;
+ if (sessionmode != enable) {
+ sessionmode = enable;
+
+ connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
+ CONNMAN_MANAGER_INTERFACE, "SessionMode",
+ DBUS_TYPE_BOOLEAN, &sessionmode);
+ }
if (sessionmode == TRUE)
__connman_service_disconnect_all();
g_hash_table_iter_init(&iter, session_hash);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
- GSequenceIter *iter;
+ GSequenceIter *seq_iter;
session = value;
info = session->info;
- iter = g_hash_table_lookup(session->service_hash, service);
- if (iter == NULL)
+ seq_iter = g_hash_table_lookup(session->service_hash, service);
+ if (seq_iter == NULL)
continue;
- g_sequence_remove(iter);
+ g_sequence_remove(seq_iter);
if (info->entry != NULL && info->entry->service == service)
info->entry = NULL;
{
GHashTableIter iter;
gpointer key, value;
- struct connman_session *session;
- struct session_info *info, *info_last;
DBG("service %p state %d", service, state);
g_hash_table_iter_init(&iter, session_hash);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ struct connman_session *session = value;
GSequenceIter *service_iter;
- session = value;
- info = session->info;
- info_last = session->info_last;
-
service_iter = g_hash_table_lookup(session->service_hash, service);
if (service_iter != NULL) {
struct service_entry *entry;
entry = g_sequence_get(service_iter);
entry->state = state;
-
- if (info->entry == entry) {
- info->online = is_online(entry->state);
- if (info_last->online != info->online)
- session->info_dirty = TRUE;
- }
}
session_changed(session,
session = value;
info = session->info;
+ if (info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
+ continue;
+
if (info->entry != NULL && info->entry->service == service) {
if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
ipconfig_ipv4_changed(session);