summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2009-02-18 19:17:52 -0300
committerJohan Hedberg <johan.hedberg@nokia.com>2009-02-19 13:41:44 +0200
commit2ecef94bcdd0324da979752352a286be85520059 (patch)
tree1d343368ed280535761a43dd4c5a3a77c4806f24 /network
parentc95494ee508a9f36096af5ddb1c2ac1579a32b1d (diff)
Make network plugin to use BtIO API.
Diffstat (limited to 'network')
-rw-r--r--network/connection.c63
-rw-r--r--network/server.c31
2 files changed, 56 insertions, 38 deletions
diff --git a/network/connection.c b/network/connection.c
index 3093f3fb..fd91bd27 100644
--- a/network/connection.c
+++ b/network/connection.c
@@ -40,6 +40,7 @@
#include "logging.h"
#include "glib-helper.h"
+#include "btio.h"
#include "dbus-common.h"
#include "error.h"
@@ -132,10 +133,12 @@ static inline DBusMessage *not_permited(DBusMessage *msg)
"Operation not permited");
}
-static inline DBusMessage *connection_attempt_failed(DBusMessage *msg, int err)
+static inline DBusMessage *connection_attempt_failed(DBusMessage *msg,
+ const char *err)
{
- return g_dbus_create_error(msg, ERROR_INTERFACE ".ConnectionAttemptFailed",
- err ? strerror(err) : "Connection attempt failed");
+ return g_dbus_create_error(msg,
+ ERROR_INTERFACE ".ConnectionAttemptFailed",
+ err ? err : "Connection attempt failed");
}
static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
@@ -270,7 +273,7 @@ static gboolean bnep_connect_cb(GIOChannel *chan, GIOCondition cond,
failed:
if (nc->state != DISCONNECTED) {
nc->state = DISCONNECTED;
- reply = connection_attempt_failed(nc->msg, EIO);
+ reply = connection_attempt_failed(nc->msg, strerror(EIO));
g_dbus_send_message(connection, reply);
g_io_channel_close(chan);
}
@@ -317,22 +320,25 @@ out:
return err;
}
-static void connect_cb(GIOChannel *chan, int err, const bdaddr_t *src,
- const bdaddr_t *dst, gpointer data)
+static void connect_cb(GIOChannel *chan, GError *err, gpointer data)
{
struct network_conn *nc = data;
DBusMessage *reply;
+ const char *err_msg;
+ int perr;
- if (err < 0) {
- error("l2cap connect(): %s (%d)", strerror(-err), -err);
+ if (err) {
+ error("%s", err->message);
+ err_msg = err->message;
goto failed;
}
nc->sk = g_io_channel_unix_get_fd(chan);
- err = bnep_connect(nc);
- if (err < 0) {
- error("bnep connect(): %s (%d)", strerror(-err), -err);
+ perr = bnep_connect(nc);
+ if (perr < 0) {
+ err_msg = strerror(-perr);
+ error("bnep connect(): %s (%d)", err_msg, -perr);
g_io_channel_close(chan);
g_io_channel_unref(chan);
goto failed;
@@ -347,7 +353,7 @@ failed:
nc->watch = 0;
}
- reply = connection_attempt_failed(nc->msg, -err);
+ reply = connection_attempt_failed(nc->msg, err_msg);
g_dbus_send_message(connection, reply);
}
@@ -372,7 +378,8 @@ static DBusMessage *connection_connect(DBusConnection *conn,
struct network_conn *nc;
const char *svc;
uint16_t id;
- int err;
+ GError *err = NULL;
+ GIOChannel *io;
if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &svc,
DBUS_TYPE_INVALID) == FALSE)
@@ -386,6 +393,24 @@ static DBusMessage *connection_connect(DBusConnection *conn,
if (nc->state != DISCONNECTED)
return already_connected(msg);
+ io = bt_io_connect(BT_IO_L2CAP, connect_cb, nc,
+ NULL, &err,
+ BT_IO_OPT_SOURCE_BDADDR, &peer->src,
+ BT_IO_OPT_DEST_BDADDR, &peer->dst,
+ BT_IO_OPT_PSM, BNEP_PSM,
+ BT_IO_OPT_OMTU, BNEP_MTU,
+ BT_IO_OPT_IMTU, BNEP_MTU,
+ BT_IO_OPT_INVALID);
+ if (!io) {
+ DBusMessage *reply;
+ error("%s", err->message);
+ reply = connection_attempt_failed(msg, err->message);
+ g_error_free(err);
+ return reply;
+ }
+
+ g_io_channel_unref(io);
+
nc->state = CONNECTING;
nc->msg = dbus_message_ref(msg);
nc->watch = g_dbus_add_disconnect_watch(conn,
@@ -393,18 +418,6 @@ static DBusMessage *connection_connect(DBusConnection *conn,
connection_destroy,
nc, NULL);
- err = bt_l2cap_connect(&peer->src, &peer->dst, BNEP_PSM, BNEP_MTU,
- connect_cb, nc);
- if (err < 0) {
- error("Connect failed. %s(%d)", strerror(errno), errno);
- dbus_message_unref(nc->msg);
- nc->msg = NULL;
- nc->state = DISCONNECTED;
- g_dbus_remove_watch(conn, nc->watch);
- nc->watch = 0;
- return connection_attempt_failed(msg, -err);
- }
-
return NULL;
}
diff --git a/network/server.c b/network/server.c
index 02696643..7e3b03a7 100644
--- a/network/server.c
+++ b/network/server.c
@@ -47,6 +47,7 @@
#include "logging.h"
#include "error.h"
#include "sdpd.h"
+#include "btio.h"
#include "glib-helper.h"
#include "bridge.h"
@@ -522,6 +523,8 @@ static void setup_destroy(void *user_data)
struct network_adapter *na = user_data;
struct timeout *to = na->to;
+ na->to = NULL;
+
if (to->id)
g_source_remove(to->id);
@@ -538,13 +541,12 @@ static gboolean timeout_cb(void *user_data)
return FALSE;
}
-static void connect_event(GIOChannel *chan, int err, const bdaddr_t *src,
- const bdaddr_t *dst, gpointer user_data)
+static void connect_event(GIOChannel *chan, GError *err, gpointer user_data)
{
struct network_adapter *na = user_data;
- if (err < 0) {
- error("accept(): %s(%d)", strerror(errno), errno);
+ if (err) {
+ error("%s", err->message);
return;
}
@@ -560,7 +562,6 @@ static void connect_event(GIOChannel *chan, int err, const bdaddr_t *src,
na->to->watch = g_io_add_watch_full(chan, G_PRIORITY_DEFAULT,
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
bnep_setup, na, setup_destroy);
- g_io_channel_unref(chan);
return;
}
@@ -860,24 +861,28 @@ static GDBusSignalTable server_signals[] = {
static struct network_adapter *create_adapter(const char *path, bdaddr_t *src)
{
struct network_adapter *na;
- int lm = 0;
-
- if (security)
- lm |= L2CAP_LM_AUTH | L2CAP_LM_ENCRYPT;
+ GError *err = NULL;
na = g_new0(struct network_adapter, 1);
na->path = g_strdup(path);
bacpy(&na->src, src);
- na->io = bt_l2cap_listen(src, BNEP_PSM, BNEP_MTU, lm,
- connect_event, na);
+ na->io = bt_io_listen(BT_IO_L2CAP, connect_event, NULL, na,
+ NULL, &err,
+ BT_IO_OPT_SOURCE_BDADDR, src,
+ BT_IO_OPT_PSM, BNEP_PSM,
+ BT_IO_OPT_OMTU, BNEP_MTU,
+ BT_IO_OPT_IMTU, BNEP_MTU,
+ BT_IO_OPT_SEC_LEVEL,
+ security ? BT_IO_SEC_MEDIUM : BT_IO_SEC_LOW,
+ BT_IO_OPT_INVALID);
if (!na->io) {
+ error("%s", err->message);
+ g_error_free(err);
adapter_free(na);
return NULL;
}
- g_io_channel_set_close_on_unref(na->io, FALSE);
-
return na;
}