summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-04-16 20:54:02 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-04-16 20:54:02 +0000
commitef29c39ffc97adc9893841165f9e9a3f6a1e9a0a (patch)
treec52388a01e836caa18be12c2c3bfd83ee9982e9f /network
parentd3d1ce6e2bc9ecbfb70b5d306e419750ba0936b6 (diff)
Move code to bring up interface to common and use it on connection.
Diffstat (limited to 'network')
-rw-r--r--network/common.c33
-rw-r--r--network/common.h1
-rw-r--r--network/connection.c7
-rw-r--r--network/server.c13
4 files changed, 40 insertions, 14 deletions
diff --git a/network/common.c b/network/common.c
index d9f60374..0a11d306 100644
--- a/network/common.c
+++ b/network/common.c
@@ -30,6 +30,9 @@
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <net/if.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/l2cap.h>
@@ -139,13 +142,13 @@ int bnep_kill_all_connections(void)
{
struct bnep_connlist_req req;
struct bnep_conninfo ci[7];
- int i;
+ int i, err;
memset(&req, 0, sizeof(req));
req.cnum = 7;
req.ci = ci;
if (ioctl(ctl, BNEPGETCONNLIST, &req)) {
- int err = errno;
+ err = errno;
error("Failed to get connection list: %s (%d)",
strerror(err), err);
return -err;
@@ -168,12 +171,36 @@ int bnep_connadd(int sk, uint16_t role, char *dev)
req.device[15] = '\0';
req.sock = sk;
req.role = role;
- if (ioctl(ctl, BNEPCONNADD, &req)) {
+ if (ioctl(ctl, BNEPCONNADD, &req) < 0) {
int err = errno;
error("Failed to add device %s: %s(%d)",
dev, strerror(err), err);
return -err;
}
+
strncpy(dev, req.device, 16);
return 0;
}
+
+int bnep_if_up(const char *devname, int up)
+{
+ int sd, err;
+ struct ifreq ifr;
+
+ sd = socket(AF_INET6, SOCK_DGRAM, 0);
+ strcpy(ifr.ifr_name, devname);
+
+ if (up)
+ ifr.ifr_flags |= IFF_UP;
+ else
+ ifr.ifr_flags &= ~IFF_UP;
+
+ if((ioctl(sd, SIOCSIFFLAGS, (caddr_t) &ifr)) < 0) {
+ err = errno;
+ error("Could not bring up %d. %s(%d)", devname, strerror(err),
+ err);
+ return -err;
+ }
+
+ return 0;
+}
diff --git a/network/common.h b/network/common.h
index b3941e4f..bfbe83d2 100644
--- a/network/common.h
+++ b/network/common.h
@@ -32,3 +32,4 @@ int bnep_kill_connection(bdaddr_t *dst);
int bnep_kill_all_connections(void);
int bnep_connadd(int sk, uint16_t role, char *dev);
+int bnep_if_up(const char *devname, int up);
diff --git a/network/connection.c b/network/connection.c
index 0bd255d2..50f60023 100644
--- a/network/connection.c
+++ b/network/connection.c
@@ -155,6 +155,8 @@ static gboolean bnep_connect_cb(GIOChannel *chan, GIOCondition cond,
goto failed;
}
+ bnep_if_up(nc->dev, TRUE);
+
signal = dbus_message_new_signal(nc->path,
NETWORK_CONNECTION_INTERFACE, "Connected");
@@ -461,6 +463,7 @@ static DBusHandlerResult connection_disconnect(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}
+ bnep_if_up(nc->dev, FALSE);
bnep_kill_connection(&nc->dst);
reply = dbus_message_new_method_return(msg);
@@ -534,8 +537,10 @@ static void connection_free(struct network_conn *nc)
if (nc->path)
g_free(nc->path);
- if (nc->state == CONNECTED)
+ if (nc->state == CONNECTED) {
+ bnep_if_up(nc->dev, FALSE);
bnep_kill_connection(&nc->dst);
+ }
if (nc->name)
g_free(nc->name);
diff --git a/network/server.c b/network/server.c
index e47c06ac..7f4fbcf6 100644
--- a/network/server.c
+++ b/network/server.c
@@ -286,8 +286,7 @@ static void authorization_callback(DBusPendingCall *pcall, void *data)
char devname[16];
DBusError derr;
uint16_t response;
- int sk, sd, err;
- struct ifreq ifr;
+ int sk;
if (!ns->pauth) {
dbus_message_unref(reply);
@@ -327,14 +326,8 @@ static void authorization_callback(DBusPendingCall *pcall, void *data)
goto failed;
}
- sd = socket(AF_INET6, SOCK_DGRAM, 0);
- strcpy(ifr.ifr_name, devname);
- ifr.ifr_flags |= IFF_UP;
- if((ioctl(sd, SIOCSIFFLAGS, (caddr_t) &ifr)) < 0) {
- err = errno;
- error("Could not bring up %d. %s(%d)", devname, strerror(err),
- err);
- }
+ bnep_if_up(devname, TRUE);
+ bnep_if_up("pan0", TRUE);
/* FIXME: Enable routing if applied */