summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-03-16 19:58:29 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-03-16 19:58:29 +0000
commit7ba9c777c7755dc380443f29f41fcd2a61e1b7df (patch)
tree193345ab4e9c568c4df7545abbc2152c2e57dce1 /network
parent57821cca7bfdb47cd3ddc32e70b6779a4a6cca2d (diff)
Add minimal support for bridge creation and removal
Diffstat (limited to 'network')
-rw-r--r--network/Makefile.am3
-rw-r--r--network/bridge.c76
-rw-r--r--network/bridge.h28
-rw-r--r--network/main.c4
-rw-r--r--network/manager.c17
5 files changed, 125 insertions, 3 deletions
diff --git a/network/Makefile.am b/network/Makefile.am
index 22a7aef3..094f95e8 100644
--- a/network/Makefile.am
+++ b/network/Makefile.am
@@ -12,7 +12,8 @@ noinst_PROGRAMS = bluetoothd-service-network
bluetoothd_service_network_SOURCES = main.c \
manager.h manager.c error.h error.c \
- server.h server.c connection.h connection.c
+ server.h server.c bridge.h bridge.c \
+ connection.h connection.c
LDADD = $(top_builddir)/common/libhelper.a \
@GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@
diff --git a/network/bridge.c b/network/bridge.c
new file mode 100644
index 00000000..76c2a507
--- /dev/null
+++ b/network/bridge.c
@@ -0,0 +1,76 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
+
+#include <net/if.h>
+#include <linux/sockios.h>
+
+#include "bridge.h"
+
+static int bridge_socket = -1;
+
+int bridge_init(void)
+{
+ bridge_socket = socket(AF_INET, SOCK_STREAM, 0);
+ if (bridge_socket < 0)
+ return -errno;
+
+ return 0;
+}
+
+void bridge_cleanup(void)
+{
+ close(bridge_socket);
+
+ bridge_socket = -1;
+}
+
+int bridge_create(const char *name)
+{
+ int err;
+
+ err = ioctl(bridge_socket, SIOCBRADDBR, name);
+ if (err < 0)
+ return -errno;
+
+ return 0;
+}
+
+int bridge_remove(const char *name)
+{
+ int err;
+
+ err = ioctl(bridge_socket, SIOCBRDELBR, name);
+ if (err < 0)
+ return -errno;
+
+ return 0;
+}
diff --git a/network/bridge.h b/network/bridge.h
new file mode 100644
index 00000000..45e744d3
--- /dev/null
+++ b/network/bridge.h
@@ -0,0 +1,28 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+int bridge_init(void);
+void bridge_cleanup(void);
+
+int bridge_create(const char *name);
+int bridge_remove(const char *name);
diff --git a/network/main.c b/network/main.c
index 9b201bf2..5e8f2739 100644
--- a/network/main.c
+++ b/network/main.c
@@ -66,11 +66,11 @@ int main(int argc, char *argv[])
/* Create event loop */
main_loop = g_main_loop_new(NULL, FALSE);
- network_init();
-
if (argc > 1 && !strcmp(argv[1], "-s"))
internal_service("network");
+ network_init();
+
g_main_loop_run(main_loop);
network_exit();
diff --git a/network/manager.c b/network/manager.c
index 8487bbb1..26ebf57b 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -38,6 +38,7 @@
#define NETWORK_MANAGER_INTERFACE "org.bluez.network.Manager"
#define NETWORK_ERROR_INTERFACE "org.bluez.Error"
+#include "bridge.h"
#include "manager.h"
struct manager {
@@ -262,10 +263,26 @@ void internal_service(const char *identifier)
int network_init(void)
{
network_dbus_init();
+
+ if (bridge_init() < 0) {
+ error("Can't init bridge module");
+ return -1;
+ }
+
+ if (bridge_create("pan0") < 0) {
+ error("Can't create bridge");
+ return -1;
+ }
+
return 0;
}
void network_exit(void)
{
+ if (bridge_remove("pan0") < 0)
+ error("Can't remove bridge");
+
+ bridge_cleanup();
+
network_dbus_exit();
}