diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2008-04-09 21:48:30 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2008-04-09 21:48:30 +0000 |
commit | e17ea9f35ae810afd33b332978d5882953696cfd (patch) | |
tree | 6250fc0e87e017fa8846e54d9b0204a1f11f1b5f /hcid/plugin.c | |
parent | a1c12f0ffeeb1bd2ab9cb287ce4e16125492c521 (diff) |
Added new function for plugin authorization
Diffstat (limited to 'hcid/plugin.c')
-rw-r--r-- | hcid/plugin.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/hcid/plugin.c b/hcid/plugin.c index 847bf5e6..3fcbf126 100644 --- a/hcid/plugin.c +++ b/hcid/plugin.c @@ -32,7 +32,17 @@ #include <sys/stat.h> #include <errno.h> +#include <bluetooth/bluetooth.h> +#include <bluetooth/hci.h> +#include <bluetooth/hci_lib.h> +#include <dbus/dbus.h> + +#include "dbus-helper.h" +#include "adapter.h" +#include "dbus-hci.h" +#include "agent.h" #include "plugin.h" +#include "device.h" #include "logging.h" static GSList *plugins = NULL; @@ -42,6 +52,11 @@ struct bluetooth_plugin { struct bluetooth_plugin_desc *desc; }; +struct plugin_auth { + plugin_auth_cb cb; + void *user_data; +}; + static gboolean add_plugin(GModule *module, struct bluetooth_plugin_desc *desc) { struct bluetooth_plugin *plugin; @@ -146,3 +161,86 @@ void plugin_cleanup(void) g_slist_free(plugins); } + +static struct adapter *ba2adapter(bdaddr_t *src) +{ + DBusConnection *conn = get_dbus_connection(); + struct adapter *adapter = NULL; + char address[18], path[6]; + int dev_id; + + ba2str(src, address); + dev_id = hci_devid(address); + if (dev_id < 0) + return NULL; + + /* FIXME: id2adapter? Create a list of adapters? */ + snprintf(path, sizeof(path), "/hci%d", dev_id); + if (dbus_connection_get_object_user_data(conn, + path, (void *) &adapter) == FALSE) + return NULL; + + return adapter; +} + +static void agent_auth_cb(struct agent *agent, DBusError *derr, void *user_data) +{ + struct plugin_auth *auth = user_data; + + auth->cb(derr, auth->user_data); + + g_free(auth); +} + +int plugin_req_auth(bdaddr_t *src, bdaddr_t *dst, + const char *uuid, plugin_auth_cb cb, void *user_data) +{ + struct plugin_auth *auth; + struct adapter *adapter; + struct device *device; + char address[18]; + + adapter = ba2adapter(src); + if (!adapter) + return -EPERM; + + /* Device connected? */ + if (!g_slist_find_custom(adapter->active_conn, + dst, active_conn_find_by_bdaddr)) + return -ENOTCONN; + + /* FIXME: Is there a plugin that exports this service? */ + + ba2str(dst, address); + device = adapter_find_device(adapter, address); + if (!device) + return -EPERM; + + /* + * FIXME: Trusted device? Currently, service are based on a friendly + * name, it is necessary convert UUID128 to friendly name or store the + * UUID128 in the trusted file. + */ + + if (!adapter->agent) + return -EPERM; + + auth = g_try_new0(struct plugin_auth, 1); + if (!auth) + return -ENOMEM; + + auth->cb = cb; + auth->user_data = user_data; + + return agent_authorize(adapter->agent, device->path, uuid, agent_auth_cb, auth); +} + +int plugin_cancel_auth(bdaddr_t *src) +{ + struct adapter *adapter = ba2adapter(src); + + if (!adapter || !adapter->agent) + return -EPERM; + + return agent_cancel(adapter->agent); +} |