Blame profiles/network/manager.c

Packit 34410b
/*
Packit 34410b
 *
Packit 34410b
 *  BlueZ - Bluetooth protocol stack for Linux
Packit 34410b
 *
Packit 34410b
 *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
Packit 34410b
 *
Packit 34410b
 *
Packit 34410b
 *  This program is free software; you can redistribute it and/or modify
Packit 34410b
 *  it under the terms of the GNU General Public License as published by
Packit 34410b
 *  the Free Software Foundation; either version 2 of the License, or
Packit 34410b
 *  (at your option) any later version.
Packit 34410b
 *
Packit 34410b
 *  This program is distributed in the hope that it will be useful,
Packit 34410b
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 34410b
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 34410b
 *  GNU General Public License for more details.
Packit 34410b
 *
Packit 34410b
 *  You should have received a copy of the GNU General Public License
Packit 34410b
 *  along with this program; if not, write to the Free Software
Packit 34410b
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Packit 34410b
 *
Packit 34410b
 */
Packit 34410b
Packit 34410b
#ifdef HAVE_CONFIG_H
Packit 34410b
#include <config.h>
Packit 34410b
#endif
Packit 34410b
Packit 34410b
#include <errno.h>
Packit 34410b
#include <stdbool.h>
Packit 34410b
Packit 34410b
#include <glib.h>
Packit 34410b
Packit 34410b
#include "lib/bluetooth.h"
Packit 34410b
#include "lib/bnep.h"
Packit 34410b
#include "lib/sdp.h"
Packit 34410b
#include "lib/uuid.h"
Packit 34410b
Packit 34410b
#include "src/log.h"
Packit 34410b
#include "src/plugin.h"
Packit 34410b
#include "src/adapter.h"
Packit 34410b
#include "src/device.h"
Packit 34410b
#include "src/profile.h"
Packit 34410b
#include "src/service.h"
Packit 34410b
Packit 34410b
#include "bnep.h"
Packit 34410b
#include "connection.h"
Packit 34410b
#include "server.h"
Packit 34410b
Packit 34410b
static gboolean conf_security = TRUE;
Packit 34410b
Packit 34410b
static void read_config(const char *file)
Packit 34410b
{
Packit 34410b
	GKeyFile *keyfile;
Packit 34410b
	GError *err = NULL;
Packit 34410b
Packit 34410b
	keyfile = g_key_file_new();
Packit 34410b
Packit 34410b
	if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
Packit 34410b
		g_clear_error(&err;;
Packit 34410b
		goto done;
Packit 34410b
	}
Packit 34410b
Packit 34410b
	conf_security = !g_key_file_get_boolean(keyfile, "General",
Packit 34410b
						"DisableSecurity", &err;;
Packit 34410b
	if (err) {
Packit 34410b
		DBG("%s: %s", file, err->message);
Packit 34410b
		g_clear_error(&err;;
Packit 34410b
	}
Packit 34410b
Packit 34410b
done:
Packit 34410b
	g_key_file_free(keyfile);
Packit 34410b
Packit 34410b
	DBG("Config options: Security=%s",
Packit 34410b
				conf_security ? "true" : "false");
Packit 34410b
}
Packit 34410b
Packit 34410b
static int panu_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
Packit 34410b
{
Packit 34410b
	const char *path = adapter_get_path(adapter);
Packit 34410b
Packit 34410b
	DBG("path %s", path);
Packit 34410b
Packit 34410b
	return server_register(adapter, BNEP_SVC_PANU);
Packit 34410b
}
Packit 34410b
Packit 34410b
static void panu_server_remove(struct btd_profile *p,
Packit 34410b
						struct btd_adapter *adapter)
Packit 34410b
{
Packit 34410b
	const char *path = adapter_get_path(adapter);
Packit 34410b
Packit 34410b
	DBG("path %s", path);
Packit 34410b
Packit 34410b
	server_unregister(adapter, BNEP_SVC_PANU);
Packit 34410b
}
Packit 34410b
Packit 34410b
static int gn_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
Packit 34410b
{
Packit 34410b
	const char *path = adapter_get_path(adapter);
Packit 34410b
Packit 34410b
	DBG("path %s", path);
Packit 34410b
Packit 34410b
	return server_register(adapter, BNEP_SVC_GN);
Packit 34410b
}
Packit 34410b
Packit 34410b
static void gn_server_remove(struct btd_profile *p,
Packit 34410b
						struct btd_adapter *adapter)
Packit 34410b
{
Packit 34410b
	const char *path = adapter_get_path(adapter);
Packit 34410b
Packit 34410b
	DBG("path %s", path);
Packit 34410b
Packit 34410b
	server_unregister(adapter, BNEP_SVC_GN);
Packit 34410b
}
Packit 34410b
Packit 34410b
static int nap_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
Packit 34410b
{
Packit 34410b
	const char *path = adapter_get_path(adapter);
Packit 34410b
Packit 34410b
	DBG("path %s", path);
Packit 34410b
Packit 34410b
	return server_register(adapter, BNEP_SVC_NAP);
Packit 34410b
}
Packit 34410b
Packit 34410b
static void nap_server_remove(struct btd_profile *p,
Packit 34410b
						struct btd_adapter *adapter)
Packit 34410b
{
Packit 34410b
	const char *path = adapter_get_path(adapter);
Packit 34410b
Packit 34410b
	DBG("path %s", path);
Packit 34410b
Packit 34410b
	server_unregister(adapter, BNEP_SVC_NAP);
Packit 34410b
}
Packit 34410b
Packit 34410b
static struct btd_profile panu_profile = {
Packit 34410b
	.name		= "network-panu",
Packit 34410b
	.local_uuid	= NAP_UUID,
Packit 34410b
	.remote_uuid	= PANU_UUID,
Packit 34410b
	.device_probe	= connection_register,
Packit 34410b
	.device_remove	= connection_unregister,
Packit 34410b
	.connect	= connection_connect,
Packit 34410b
	.disconnect	= connection_disconnect,
Packit 34410b
	.adapter_probe	= panu_server_probe,
Packit 34410b
	.adapter_remove	= panu_server_remove,
Packit 34410b
};
Packit 34410b
Packit 34410b
static struct btd_profile gn_profile = {
Packit 34410b
	.name		= "network-gn",
Packit 34410b
	.local_uuid	= PANU_UUID,
Packit 34410b
	.remote_uuid	= GN_UUID,
Packit 34410b
	.device_probe	= connection_register,
Packit 34410b
	.device_remove	= connection_unregister,
Packit 34410b
	.connect	= connection_connect,
Packit 34410b
	.disconnect	= connection_disconnect,
Packit 34410b
	.adapter_probe	= gn_server_probe,
Packit 34410b
	.adapter_remove	= gn_server_remove,
Packit 34410b
};
Packit 34410b
Packit 34410b
static struct btd_profile nap_profile = {
Packit 34410b
	.name		= "network-nap",
Packit 34410b
	.local_uuid	= PANU_UUID,
Packit 34410b
	.remote_uuid	= NAP_UUID,
Packit 34410b
	.device_probe	= connection_register,
Packit 34410b
	.device_remove	= connection_unregister,
Packit 34410b
	.connect	= connection_connect,
Packit 34410b
	.disconnect	= connection_disconnect,
Packit 34410b
	.adapter_probe	= nap_server_probe,
Packit 34410b
	.adapter_remove	= nap_server_remove,
Packit 34410b
};
Packit 34410b
Packit 34410b
static int network_init(void)
Packit 34410b
{
Packit 34410b
	int err;
Packit 34410b
Packit 34410b
	read_config(CONFIGDIR "/network.conf");
Packit 34410b
Packit 34410b
	err = bnep_init();
Packit 34410b
	if (err) {
Packit 34410b
		if (err == -EPROTONOSUPPORT)
Packit 34410b
			err = -ENOSYS;
Packit 34410b
		return err;
Packit 34410b
	}
Packit 34410b
Packit 34410b
	/*
Packit 34410b
	 * There is one socket to handle the incoming connections. NAP,
Packit 34410b
	 * GN and PANU servers share the same PSM. The initial BNEP message
Packit 34410b
	 * (setup connection request) contains the destination service
Packit 34410b
	 * field that defines which service the source is connecting to.
Packit 34410b
	 */
Packit 34410b
Packit 34410b
	if (server_init(conf_security) < 0)
Packit 34410b
		return -1;
Packit 34410b
Packit 34410b
	btd_profile_register(&panu_profile);
Packit 34410b
	btd_profile_register(&gn_profile);
Packit 34410b
	btd_profile_register(&nap_profile);
Packit 34410b
Packit 34410b
	return 0;
Packit 34410b
}
Packit 34410b
Packit 34410b
static void network_exit(void)
Packit 34410b
{
Packit 34410b
	btd_profile_unregister(&panu_profile);
Packit 34410b
	btd_profile_unregister(&gn_profile);
Packit 34410b
	btd_profile_unregister(&nap_profile);
Packit 34410b
Packit 34410b
	bnep_cleanup();
Packit 34410b
}
Packit 34410b
Packit 34410b
BLUETOOTH_PLUGIN_DEFINE(network, VERSION,
Packit 34410b
			BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, network_init, network_exit)