summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hcid/agent.c6
-rw-r--r--hcid/agent.h2
-rw-r--r--hcid/dbus-common.c1
-rw-r--r--hcid/dbus-database.c4
-rw-r--r--hcid/plugin.c98
-rw-r--r--hcid/plugin.h6
6 files changed, 110 insertions, 7 deletions
diff --git a/hcid/agent.c b/hcid/agent.c
index af350661..3b85ebd4 100644
--- a/hcid/agent.c
+++ b/hcid/agent.c
@@ -339,7 +339,7 @@ done:
}
int agent_authorize(struct agent *agent,
- struct device *device,
+ const char *path,
const char *uuid,
agent_cb cb,
void *user_data)
@@ -351,7 +351,7 @@ int agent_authorize(struct agent *agent,
req = agent_request_new(agent, AGENT_REQUEST_AUTHORIZE, cb, user_data);
- req->call = agent_call_authorize(agent, device->path, uuid);
+ req->call = agent_call_authorize(agent, path, uuid);
if (!req->call) {
agent_request_free(req);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -360,7 +360,7 @@ int agent_authorize(struct agent *agent,
dbus_pending_call_set_notify(req->call, simple_agent_reply, req, NULL);
agent->request = req;
- debug("authorize request was sent for %s", device->path);
+ debug("authorize request was sent for %s", path);
return 0;
}
diff --git a/hcid/agent.h b/hcid/agent.h
index 9a4fed70..9d2ac377 100644
--- a/hcid/agent.h
+++ b/hcid/agent.h
@@ -38,7 +38,7 @@ struct agent *agent_create(struct adapter *adapter, const char *name,
int agent_destroy(struct agent *agent, gboolean exited);
-int agent_authorize(struct agent *agent, struct device *device,
+int agent_authorize(struct agent *agent, const char *path,
const char *uuid, agent_cb cb, void *user_data);
int agent_request_passkey(struct agent *agent, struct device *device,
diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c
index 37815c61..0094c11e 100644
--- a/hcid/dbus-common.c
+++ b/hcid/dbus-common.c
@@ -55,7 +55,6 @@
#include "dbus-error.h"
#include "manager.h"
#include "adapter.h"
-#include "device.h"
#include "dbus-hci.h"
#include "dbus-service.h"
#include "dbus-database.h"
diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c
index 4479f78c..a32bc810 100644
--- a/hcid/dbus-database.c
+++ b/hcid/dbus-database.c
@@ -406,7 +406,7 @@ static DBusHandlerResult unregister_service(DBusConnection *conn,
return send_message_and_unref(conn, reply);
}
-static DBusHandlerResult request_authorization(DBusConnection *conn,
+static DBusHandlerResult request_authorization_old(DBusConnection *conn,
DBusMessage *msg, void *data)
{
const char *sender, *address, *uuid;
@@ -482,7 +482,7 @@ static DBusMethodVTable database_methods[] = {
{ "RemoveServiceRecord", remove_service_record, "u", "" },
{ "RegisterService", register_service, "sss", "" },
{ "UnregisterService", unregister_service, "s", "" },
- { "RequestAuthorization", request_authorization, "ss", "" },
+ { "RequestAuthorization", request_authorization_old, "ss", "" },
{ "CancelAuthorizationRequest", cancel_authorization_request, "ss", "" },
{ NULL, NULL, NULL, NULL }
};
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);
+}
diff --git a/hcid/plugin.h b/hcid/plugin.h
index 9248aab6..09f617e2 100644
--- a/hcid/plugin.h
+++ b/hcid/plugin.h
@@ -31,3 +31,9 @@ struct bluetooth_plugin_desc {
struct bluetooth_plugin_desc bluetooth_plugin_desc = { \
name, init, exit \
};
+
+
+typedef void (*plugin_auth_cb) (DBusError *derr, void *user_data);
+int plugin_req_auth(bdaddr_t *src, bdaddr_t *dst,
+ const char *uuid, plugin_auth_cb cb, void *user_data);
+int plugin_cancel_auth(bdaddr_t *src);