summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorCidorvan Leite <cidorvan.leite@openbossa.org>2008-04-10 22:36:58 +0000
committerCidorvan Leite <cidorvan.leite@openbossa.org>2008-04-10 22:36:58 +0000
commitfb27732e05fb7b69c3b784ed8a6aaed2d9d939ae (patch)
treef6d262f6a6bf0733c761399b8e15b7ed130ae0c9 /hcid
parent61a6576b2b7badd8963219873b631e6a51df612c (diff)
Added local agent in CreatePairedDevice
Diffstat (limited to 'hcid')
-rw-r--r--hcid/adapter.c48
-rw-r--r--hcid/adapter.h3
-rw-r--r--hcid/agent.c19
-rw-r--r--hcid/dbus-hci.c22
-rw-r--r--hcid/device.c3
-rw-r--r--hcid/device.h1
6 files changed, 61 insertions, 35 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c
index 66ac4d0e..0934ad02 100644
--- a/hcid/adapter.c
+++ b/hcid/adapter.c
@@ -231,10 +231,17 @@ int pending_remote_name_cancel(struct adapter *adapter)
return err;
}
+static void device_agent_removed(struct agent *agent, struct device *device)
+{
+ if (device->agent == agent)
+ device->agent = NULL;
+}
+
static struct bonding_request_info *bonding_request_new(DBusConnection *conn,
DBusMessage *msg,
struct adapter *adapter,
- const char *address)
+ const char *address,
+ const char *agent_path)
{
struct bonding_request_info *bonding;
struct device *device;
@@ -244,10 +251,18 @@ static struct bonding_request_info *bonding_request_new(DBusConnection *conn,
bonding->conn = dbus_connection_ref(conn);
bonding->msg = dbus_message_ref(msg);
- /* FIXME: should be removed on 4.0 */
if (hcid_dbus_use_experimental()) {
device = adapter_get_device(conn, adapter, address);
+ if (!device)
+ return NULL;
+
device->temporary = TRUE;
+
+ if (agent_path && strcmp(agent_path, "/"))
+ device->agent = agent_create(adapter,
+ dbus_message_get_sender(msg), agent_path,
+ NULL, (agent_remove_cb) device_agent_removed,
+ device);
}
str2ba(address, &bonding->bdaddr);
@@ -2277,19 +2292,12 @@ struct device *adapter_find_device(struct adapter *adapter, const char *dest)
return device;
}
-struct device *adapter_get_device(DBusConnection *conn,
- struct adapter *adapter, const gchar *address)
+struct device *adapter_create_device(DBusConnection *conn,
+ struct adapter *adapter, const char *address)
{
struct device *device;
char path[MAX_PATH_LENGTH];
- if (!adapter)
- return NULL;
-
- device = adapter_find_device(adapter, address);
- if (device)
- return device;
-
device = device_create(conn, adapter, address, NULL);
if (!device)
return NULL;
@@ -2326,6 +2334,21 @@ void adapter_remove_device(DBusConnection *conn, struct adapter *adapter,
adapter->devices = g_slist_remove(adapter->devices, device);
}
+struct device *adapter_get_device(DBusConnection *conn,
+ struct adapter *adapter, const gchar *address)
+{
+ struct device *device;
+
+ if (!adapter)
+ return NULL;
+
+ device = adapter_find_device(adapter, address);
+ if (device)
+ return device;
+
+ return adapter_create_device(conn, adapter, address);
+}
+
static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond,
struct adapter *adapter)
{
@@ -2495,7 +2518,8 @@ static DBusHandlerResult create_bonding(DBusConnection *conn, DBusMessage *msg,
if (sk < 0)
return error_connection_attempt_failed(conn, msg, 0);
- adapter->bonding = bonding_request_new(conn, msg, adapter, address);
+ adapter->bonding = bonding_request_new(conn, msg, adapter, address,
+ agent_path);
if (!adapter->bonding) {
close(sk);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
diff --git a/hcid/adapter.h b/hcid/adapter.h
index 9a40ed4b..767cbde7 100644
--- a/hcid/adapter.h
+++ b/hcid/adapter.h
@@ -118,6 +118,9 @@ struct device *adapter_get_device(DBusConnection *conn,
struct device *adapter_find_device(struct adapter *adapter, const char *dest);
+struct device *adapter_create_device(DBusConnection *conn,
+ struct adapter *adapter, const char *address);
+
void adapter_remove_device(DBusConnection *conn, struct adapter *adapter,
struct device *device);
diff --git a/hcid/agent.c b/hcid/agent.c
index 3b85ebd4..f560f8d8 100644
--- a/hcid/agent.c
+++ b/hcid/agent.c
@@ -129,12 +129,9 @@ static void agent_request_free(struct agent_request *req)
static void agent_exited(const char *name, struct agent *agent)
{
- struct adapter *adapter = agent->adapter;
-
debug("Agent %s exited without calling Unregister", name);
agent_destroy(agent, TRUE);
- adapter->agent = NULL;
}
static void agent_free(struct agent *agent)
@@ -142,6 +139,9 @@ static void agent_free(struct agent *agent)
if (!agent)
return;
+ if (agent->remove_cb)
+ agent->remove_cb(agent, agent->remove_cb_data);
+
if (agent->request) {
DBusError err;
@@ -189,9 +189,6 @@ static gboolean agent_timeout(struct agent *agent)
agent->timeout = 0;
- if (agent->remove_cb)
- agent->remove_cb(agent, agent->remove_cb_data);
-
agent_free(agent);
return FALSE;
@@ -331,11 +328,8 @@ done:
agent->request = NULL;
agent_request_free(req);
- if (agent->addr) {
- if (agent->remove_cb)
- agent->remove_cb(agent, agent->remove_cb_data);
+ if (agent->addr)
agent_free(agent);
- }
}
int agent_authorize(struct agent *agent,
@@ -454,11 +448,8 @@ done:
dbus_pending_call_cancel(req->call);
agent_request_free(req);
- if (agent->addr) {
- if (agent->remove_cb)
- agent->remove_cb(agent, agent->remove_cb_data);
+ if (agent->addr)
agent_free(agent);
- }
}
int agent_request_passkey(struct agent *agent, struct device *device,
diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c
index 0a06138a..9b48a11f 100644
--- a/hcid/dbus-hci.c
+++ b/hcid/dbus-hci.c
@@ -962,8 +962,6 @@ static void passkey_cb(struct agent *agent, DBusError *err, const char *passkey,
goto done;
}
- device->temporary = FALSE;
-
len = strlen(passkey);
set_pin_length(&sba, len);
@@ -983,6 +981,7 @@ int hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci)
char path[MAX_PATH_LENGTH], addr[18];
struct adapter *adapter;
struct device *device;
+ struct agent *agent;
int id;
ba2str(sba, addr);
@@ -1004,16 +1003,20 @@ int hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci)
goto old_fallback;
}
- if (!adapter->agent)
- goto old_fallback;
-
ba2str(&ci->bdaddr, addr);
- device = adapter_get_device(connection, adapter, addr);
- if (!device)
- return -ENODEV;
+ device = adapter_find_device(adapter, addr);
+ agent = device && device->agent ? device->agent : adapter->agent;
+ if (!agent)
+ goto old_fallback;
- return agent_request_passkey(adapter->agent, device,
+ if (!device) {
+ device = adapter_create_device(connection, adapter, addr);
+ if (!device)
+ return -ENODEV;
+ }
+
+ return agent_request_passkey(agent, device,
(agent_passkey_cb) passkey_cb,
device);
@@ -1093,6 +1096,7 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer,
device = adapter_get_device(connection, adapter, paddr);
if (device) {
+ device->temporary = FALSE;
dbus_connection_emit_property_changed(connection,
device->path, DEVICE_INTERFACE,
"Paired", DBUS_TYPE_BOOLEAN, &paired);
diff --git a/hcid/device.c b/hcid/device.c
index 1a0840e5..1e80b51e 100644
--- a/hcid/device.c
+++ b/hcid/device.c
@@ -60,6 +60,7 @@
#include "dbus-hci.h"
#include "error.h"
#include "glib-helper.h"
+#include "agent.h"
#define MAX_DEVICES 16
@@ -737,6 +738,8 @@ int get_encryption_key_size(uint16_t dev_id, const bdaddr_t *baddr)
static void device_free(struct device *device)
{
+ if (device->agent)
+ agent_destroy(device->agent, FALSE);
g_slist_foreach(device->uuids, (GFunc) g_free, NULL);
g_slist_free(device->uuids);
g_free(device->address);
diff --git a/hcid/device.h b/hcid/device.h
index 273d23d5..4bfa9feb 100644
--- a/hcid/device.h
+++ b/hcid/device.h
@@ -30,6 +30,7 @@ struct device {
struct adapter *adapter;
GSList *uuids;
gboolean temporary;
+ struct agent *agent;
};
struct device *device_create(DBusConnection *conn, struct adapter *adapter,