summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-10-22 20:19:53 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-10-22 20:19:53 +0000
commitc95ffdc65e97a75e65dbbd22e7fae7086346595e (patch)
tree16f35bf85b914303d03cd3264b587489bec711be /network
parent723ff52c61b23cfaac0293b9d5a206f8df94396e (diff)
Fixes cross storage and adapter path.
Diffstat (limited to 'network')
-rw-r--r--network/connection.c20
-rw-r--r--network/manager.c75
-rw-r--r--network/server.c5
3 files changed, 86 insertions, 14 deletions
diff --git a/network/connection.c b/network/connection.c
index 821560f8..439aaa30 100644
--- a/network/connection.c
+++ b/network/connection.c
@@ -32,6 +32,8 @@
#include <netinet/in.h>
#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/hci_lib.h>
#include <bluetooth/l2cap.h>
#include <bluetooth/bnep.h>
@@ -56,6 +58,7 @@ typedef enum {
struct network_conn {
DBusMessage *msg;
+ bdaddr_t store;
bdaddr_t src;
bdaddr_t dst;
char *path; /* D-Bus path */
@@ -636,6 +639,16 @@ int connection_register(const char *path, bdaddr_t *src, bdaddr_t *dst,
uint16_t id, const char *name, const char *desc)
{
struct network_conn *nc;
+ bdaddr_t default_src;
+ int dev_id;
+
+ if (!path)
+ return -EINVAL;
+
+ bacpy(&default_src, BDADDR_ANY);
+ dev_id = hci_get_route(&default_src);
+ if ((dev_id < 0) || (hci_devba(dev_id, &default_src) < 0))
+ return -1;
nc = g_new0(struct network_conn, 1);
@@ -657,7 +670,8 @@ int connection_register(const char *path, bdaddr_t *src, bdaddr_t *dst,
}
nc->path = g_strdup(path);
- bacpy(&nc->src, src);
+ bacpy(&nc->store, src);
+ bacpy(&nc->src, &default_src);
bacpy(&nc->dst, dst);
nc->id = id;
nc->name = g_strdup(name);
@@ -693,7 +707,7 @@ int connection_store(const char *path, gboolean default_path)
role = bnep_name(nc->id);
snprintf(key, 32, "%s#%s", dst_addr, role);
- ba2str(&nc->src, src_addr);
+ ba2str(&nc->store, src_addr);
create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "network");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -768,7 +782,7 @@ int connection_remove_stored(const char *path)
role = bnep_name(nc->id);
snprintf(key, 32, "%s#%s", dst_addr, role);
- ba2str(&nc->src, src_addr);
+ ba2str(&nc->store, src_addr);
create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "network");
err = textfile_del(filename, key);
diff --git a/network/manager.c b/network/manager.c
index 683ff0a0..26553b7f 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -507,6 +507,60 @@ static DBusHandlerResult find_connection(DBusConnection *conn,
return send_message_and_unref(conn, reply);
}
+char *find_adapter(DBusConnection *conn, bdaddr_t *src)
+{
+ DBusMessage *msg, *reply;
+ DBusError derr;
+ char address[18], *addr_ptr = address;
+ char *path, *ret;
+
+ msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
+ "org.bluez.Manager",
+ "FindAdapter");
+ if (!msg) {
+ error("Unable to allocate new method call");
+ return NULL;
+ }
+
+ ba2str(src, address);
+
+ dbus_message_append_args(msg, DBUS_TYPE_STRING, &addr_ptr,
+ DBUS_TYPE_INVALID);
+
+ dbus_error_init(&derr);
+ reply = dbus_connection_send_with_reply_and_block(conn, msg, -1,
+ &derr);
+
+ dbus_message_unref(msg);
+
+ if (dbus_error_is_set(&derr) ||
+ dbus_set_error_from_message(&derr, reply)) {
+ error("FindAdapter(%s) failed: %s", address, derr.message);
+ dbus_error_free(&derr);
+ return NULL;
+ }
+
+ dbus_error_init(&derr);
+ dbus_message_get_args(reply, &derr,
+ DBUS_TYPE_STRING, &path,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_error_is_set(&derr)) {
+ error("Unable to get message args");
+ dbus_message_unref(reply);
+ dbus_error_free(&derr);
+ return FALSE;
+ }
+
+ ret = g_strdup(path);
+
+ dbus_message_unref(reply);
+
+ debug("Got path %s for adapter with address %s", ret, address);
+
+ return ret;
+}
+
static DBusHandlerResult create_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -546,11 +600,18 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
}
bacpy(&src, BDADDR_ANY);
- dev_id = hci_get_route(NULL);
- if ((dev_id < 0) || (hci_devba(dev_id, &src) < 0))
+ dev_id = hci_get_route(&src);
+ if (dev_id < 0 || hci_devba(dev_id, &src) < 0)
return err_failed(conn, msg, "Adapter not available");
pr = g_new0(struct pending_reply, 1);
+
+ pr->adapter_path = find_adapter(conn, &src);
+ if (!pr->adapter_path) {
+ pending_reply_free (pr);
+ return err_failed(conn, msg, "Adapter not available");
+ }
+
pr->conn = dbus_connection_ref(conn);
pr->msg = dbus_message_ref(msg);
bacpy(&pr->src, &src);
@@ -561,9 +622,6 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
snprintf(pr->path, MAX_PATH_LENGTH,
NETWORK_PATH"/connection%d", net_uid++);
- pr->adapter_path = g_malloc0(16);
- snprintf(pr->adapter_path, 16, "/org/bluez/hci%d", dev_id);
-
if (get_handles(pr, pan_handle_reply) < 0)
return err_not_supported(conn, msg);
@@ -795,10 +853,9 @@ static void register_connections_stored(const char *adapter)
/* Check default connection for current default adapter */
bacpy(&default_src, BDADDR_ANY);
dev_id = hci_get_route(&default_src);
- if (dev_id < 0)
+ if (dev_id < 0 || hci_devba(dev_id, &default_src) < 0)
return;
- hci_devba(dev_id, &default_src);
if (bacmp(&default_src, &src) != 0)
return;
@@ -826,11 +883,9 @@ static void register_server(uint16_t id)
bacpy(&src, BDADDR_ANY);
dev_id = hci_get_route(&src);
- if (dev_id < 0)
+ if (dev_id < 0 || hci_devba(dev_id, &src))
return;
- hci_devba(dev_id, &src);
-
if (server_register(path, &src, id) < 0)
return;
diff --git a/network/server.c b/network/server.c
index dd4c816a..1622d102 100644
--- a/network/server.c
+++ b/network/server.c
@@ -848,7 +848,7 @@ static DBusHandlerResult enable(DBusConnection *conn,
if (bacmp(&ns->src, BDADDR_ANY) == 0) {
int dev_id;
- dev_id = hci_get_route(NULL);
+ dev_id = hci_get_route(&ns->src);
if ((dev_id < 0) || (hci_devba(dev_id, &ns->src) < 0))
return err_failed(conn, msg, "Adapter not available");
@@ -1170,6 +1170,9 @@ int server_register_from_file(const char *path, const bdaddr_t *src,
struct network_server *ns;
char *str;
+ if (!path)
+ return -EINVAL;
+
ns = g_new0(struct network_server, 1);
bacpy(&ns->src, src);