예제 #1
0
int connman_session_config_update(struct connman_session *session)
{
    struct session_info *info = session->info;
    GSList *allowed_bearers;
    int err;

    DBG("session %p", session);

    /*
     * We update all configuration even though only one entry
     * might have changed. We can still optimize this later.
     */

    if (session->id_type != session->policy_config->id_type) {
        cleanup_firewall_session(session);
        err = init_firewall_session(session);
        if (err < 0) {
            connman_session_destroy(session);
            return err;
        }

        session->id_type = session->policy_config->id_type;
    }

    apply_policy_on_bearers(
        session->policy_config->allowed_bearers,
        session->user_allowed_bearers,
        &allowed_bearers);

    if (session->active)
        set_active_session(session, false);

    session->active = false;
    session_deactivate(session);

    g_slist_free(info->config.allowed_bearers);
    info->config.allowed_bearers = allowed_bearers;

    session_activate(session);

    info->config.type = apply_policy_on_type(
                            session->policy_config->type,
                            info->config.type);

    info->config.roaming_policy = session->policy_config->roaming_policy;

    info->config.ecall = session->policy_config->ecall;
    if (info->config.ecall)
        ecall_session = session;

    info->config.priority = session->policy_config->priority;

    session_notify(session);

    return 0;
}
예제 #2
0
파일: session.c 프로젝트: leinomii/connman
int connman_session_config_update(struct connman_session *session)
{
	struct session_info *info = session->info;
	GSList *allowed_bearers;
	int err;

	DBG("session %p", session);

	/*
	 * We update all configuration even though only one entry
	 * might have changed. We can still optimize this later.
	 */

	err = apply_policy_on_bearers(
		session->policy_config->allowed_bearers,
		session->user_allowed_bearers,
		&allowed_bearers);
	if (err < 0)
		return err;

	g_slist_free(info->config.allowed_bearers);
	info->config.allowed_bearers = allowed_bearers;

	info->config.type = apply_policy_on_type(
				session->policy_config->type,
				info->config.type);

	info->config.roaming_policy = session->policy_config->roaming_policy;

	info->config.ecall = session->policy_config->ecall;
	if (info->config.ecall == TRUE)
		ecall_session = session;

	info->config.priority = session->policy_config->priority;

	session_changed(session, CONNMAN_SESSION_TRIGGER_SETTING);

	return 0;
}
예제 #3
0
static int session_policy_config_cb(struct connman_session *session,
                                    struct connman_session_config *config,
                                    void *user_data, int err)
{
    struct creation_data *creation_data = user_data;
    struct session_info *info, *info_last;
    DBusMessage *reply;

    DBG("session %p config %p", session, config);

    if (err < 0)
        goto err;

    session->policy_config = config;

    session->mark = session_mark++;
    session->index = -1;

    err = init_firewall_session(session);
    if (err < 0)
        goto err;

    err = init_routing_table(session);
    if (err < 0)
        goto err;

    info = session->info;
    info_last = session->info_last;

    if (session->policy_config->ecall)
        ecall_session = session;

    info->state = CONNMAN_SESSION_STATE_DISCONNECTED;
    info->config.type = apply_policy_on_type(
                            session->policy_config->type,
                            creation_data->type);
    info->config.priority = session->policy_config->priority;
    info->config.roaming_policy = session->policy_config->roaming_policy;

    session->user_allowed_bearers = creation_data->allowed_bearers;
    creation_data->allowed_bearers = NULL;

    apply_policy_on_bearers(
        session->policy_config->allowed_bearers,
        session->user_allowed_bearers,
        &info->config.allowed_bearers);

    g_hash_table_replace(session_hash, session->session_path, session);

    DBG("add %s", session->session_path);

    if (!g_dbus_register_interface(connection, session->session_path,
                                   CONNMAN_SESSION_INTERFACE,
                                   session_methods, NULL, NULL,
                                   session, NULL)) {
        connman_error("Failed to register %s", session->session_path);
        g_hash_table_remove(session_hash, session->session_path);
        err = -EINVAL;
        goto err;
    }

    reply = g_dbus_create_reply(creation_data->pending,
                                DBUS_TYPE_OBJECT_PATH, &session->session_path,
                                DBUS_TYPE_INVALID);
    g_dbus_send_message(connection, reply);
    creation_data->pending = NULL;

    info_last->state = info->state;
    info_last->config.priority = info->config.priority;
    info_last->config.roaming_policy = info->config.roaming_policy;
    info_last->config.allowed_bearers = info->config.allowed_bearers;

    session->append_all = true;

    cleanup_creation_data(creation_data);

    session_activate(session);

    return 0;

err:
    reply = __connman_error_failed(creation_data->pending, -err);
    g_dbus_send_message(connection, reply);
    creation_data->pending = NULL;

    cleanup_session(session);
    cleanup_creation_data(creation_data);

    return err;
}
예제 #4
0
static DBusMessage *change_session(DBusConnection *conn,
                                   DBusMessage *msg, void *user_data)
{
    struct connman_session *session = user_data;
    struct session_info *info = session->info;
    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))
        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")) {
            err = parse_bearers(&value, &allowed_bearers);
            if (err < 0)
                return __connman_error_failed(msg, -err);

            if (session->active)
                set_active_session(session, false);

            session->active = false;
            session_deactivate(session);

            g_slist_free(info->config.allowed_bearers);
            session->user_allowed_bearers = allowed_bearers;

            apply_policy_on_bearers(
                session->policy_config->allowed_bearers,
                session->user_allowed_bearers,
                &info->config.allowed_bearers);

            session_activate(session);
        } else {
            goto err;
        }
        break;
    case DBUS_TYPE_STRING:
        if (g_str_equal(name, "ConnectionType")) {
            dbus_message_iter_get_basic(&value, &val);
            info->config.type = apply_policy_on_type(
                                    session->policy_config->type,
                                    connman_session_parse_connection_type(val));
        } else {
            goto err;
        }
        break;
    default:
        goto err;
    }

    session_notify(session);

    return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);

err:
    return __connman_error_invalid_arguments(msg);
}
예제 #5
0
파일: session.c 프로젝트: leinomii/connman
static int session_create_cb(struct connman_session *session,
				struct connman_session_config *config,
				void *user_data, int err)
{
	DBusMessage *reply;
	struct user_config *user_config = user_data;
	struct session_info *info, *info_last;

	DBG("session %p config %p", session, config);

	if (err != 0)
		goto out;

	session->policy_config = config;

	info = session->info;
	info_last = session->info_last;

	if (session->policy_config->ecall == TRUE)
		ecall_session = session;

	info->state = CONNMAN_SESSION_STATE_DISCONNECTED;
	info->config.type = apply_policy_on_type(
				session->policy_config->type,
				user_config->type);
	info->config.priority = session->policy_config->priority;
	info->config.roaming_policy = session->policy_config->roaming_policy;
	info->entry = NULL;

	session->user_allowed_bearers = user_config->allowed_bearers;
	user_config->allowed_bearers = NULL;

	err = apply_policy_on_bearers(
			session->policy_config->allowed_bearers,
			session->user_allowed_bearers,
			&info->config.allowed_bearers);
	if (err < 0)
		goto out;

	g_hash_table_replace(session_hash, session->session_path, session);

	DBG("add %s", session->session_path);

	if (g_dbus_register_interface(connection, session->session_path,
					CONNMAN_SESSION_INTERFACE,
					session_methods, NULL,
					NULL, session, NULL) == FALSE) {
		connman_error("Failed to register %s", session->session_path);
		g_hash_table_remove(session_hash, session->session_path);
		err = -EINVAL;
		goto out;
	}

	reply = g_dbus_create_reply(user_config->pending,
				DBUS_TYPE_OBJECT_PATH, &session->session_path,
				DBUS_TYPE_INVALID);
	g_dbus_send_message(connection, reply);
	user_config->pending = NULL;

	populate_service_list(session);

	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->config.allowed_bearers = info->config.allowed_bearers;

	session->append_all = TRUE;

	session_changed(session, CONNMAN_SESSION_TRIGGER_SETTING);

out:
	if (err < 0) {
		reply = __connman_error_failed(user_config->pending, -err);
		g_dbus_send_message(connection, reply);

		free_session(session);
	}

	cleanup_user_config(user_config);

	return err;
}