From c761480865c6b65e370e2bba750c86c226a7fc3f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 27 Oct 2006 14:46:36 +0000 Subject: Add skeletons for service implementations --- network/main.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 network/main.c (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c new file mode 100644 index 00000000..c04bb251 --- /dev/null +++ b/network/main.c @@ -0,0 +1,34 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2005-2006 Marcel Holtmann + * + * + * 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 +#endif + +#include +#include + +int main(int argc, char *argv[]) +{ + return 0; +} -- cgit From 3406c27e758f3dfa182f6fdfcc878bc3a53e3c98 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 9 Mar 2007 15:33:38 +0000 Subject: Add skeleton for network service --- network/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index c04bb251..7f643c58 100644 --- a/network/main.c +++ b/network/main.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2005-2006 Marcel Holtmann + * Copyright (C) 2004-2007 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From 855cf216127e1fd6f6aba60c3761a0ead17ae910 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 9 Mar 2007 15:37:57 +0000 Subject: Create init and exit functions --- network/main.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 7f643c58..e51c73aa 100644 --- a/network/main.c +++ b/network/main.c @@ -28,7 +28,13 @@ #include #include +#include "manager.h" + int main(int argc, char *argv[]) { + network_init(); + + network_exit(); + return 0; } -- cgit From e7e20e6343bd6b8c9b3100e66a612900ab94caff Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Fri, 9 Mar 2007 22:12:19 +0000 Subject: Network: main loop creation --- network/main.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index e51c73aa..776ea517 100644 --- a/network/main.c +++ b/network/main.c @@ -26,15 +26,57 @@ #endif #include +#include +#include +#include #include +#include +#include + +#include "dbus.h" +#include "logging.h" #include "manager.h" +static GMainLoop *main_loop; + +static void sig_term(int sig) +{ + g_main_loop_quit(main_loop); +} + int main(int argc, char *argv[]) { + struct sigaction sa; + + start_logging("network", "Bluetooth Network daemon"); + + memset(&sa, 0, sizeof(sa)); + sa.sa_flags = SA_NOCLDSTOP; + sa.sa_handler = sig_term; + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGINT, &sa, NULL); + + sa.sa_handler = SIG_IGN; + sigaction(SIGCHLD, &sa, NULL); + sigaction(SIGPIPE, &sa, NULL); + + enable_debug(); + + /* Create event loop */ + main_loop = g_main_loop_new(NULL, FALSE); + network_init(); + g_main_loop_run(main_loop); + network_exit(); + g_main_loop_unref(main_loop); + + info("Exit"); + + stop_logging(); + return 0; } -- cgit From 6bd2d4e0d8f2a74c1ec87a9de3d00a612e9c7bf7 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Mon, 12 Mar 2007 20:15:15 +0000 Subject: Network: support for standalone start mode --- network/main.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 776ea517..9b201bf2 100644 --- a/network/main.c +++ b/network/main.c @@ -68,6 +68,9 @@ int main(int argc, char *argv[]) network_init(); + if (argc > 1 && !strcmp(argv[1], "-s")) + internal_service("network"); + g_main_loop_run(main_loop); network_exit(); -- cgit From 7ba9c777c7755dc380443f29f41fcd2a61e1b7df Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 16 Mar 2007 19:58:29 +0000 Subject: Add minimal support for bridge creation and removal --- network/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'network/main.c') 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(); -- cgit From 851ad267e554850ae2cbfd486922cbcfb897f8b5 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 19 Mar 2007 13:24:41 +0000 Subject: - Fix standalone init when there is no bluetooth adapter. --- network/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 5e8f2739..d0daf429 100644 --- a/network/main.c +++ b/network/main.c @@ -66,15 +66,17 @@ int main(int argc, char *argv[]) /* Create event loop */ main_loop = g_main_loop_new(NULL, FALSE); + if (network_init() == -1) + goto fail; + if (argc > 1 && !strcmp(argv[1], "-s")) internal_service("network"); - network_init(); - g_main_loop_run(main_loop); network_exit(); +fail: g_main_loop_unref(main_loop); info("Exit"); -- cgit From e867e1dc937eedbaa3ac7f678f4703fab78d2d4e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 19 Mar 2007 19:46:43 +0000 Subject: Try to init the HAL context --- network/main.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index d0daf429..607285f7 100644 --- a/network/main.c +++ b/network/main.c @@ -37,6 +37,7 @@ #include "logging.h" #include "manager.h" +#include "hal.h" static GMainLoop *main_loop; @@ -66,6 +67,8 @@ int main(int argc, char *argv[]) /* Create event loop */ main_loop = g_main_loop_new(NULL, FALSE); + hal_init(NULL); + if (network_init() == -1) goto fail; @@ -76,6 +79,8 @@ int main(int argc, char *argv[]) network_exit(); + hal_cleanup(); + fail: g_main_loop_unref(main_loop); -- cgit From 833ce8edc2b4cde819a2aa7efb8e562958c48acd Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 21 Mar 2007 14:24:15 +0000 Subject: Implement generic HAL device helpers --- network/main.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 607285f7..d6c3ac0d 100644 --- a/network/main.c +++ b/network/main.c @@ -69,6 +69,8 @@ int main(int argc, char *argv[]) hal_init(NULL); + hal_add_device(NULL); + if (network_init() == -1) goto fail; -- cgit From 4128274b3b8c47a58f6895e1dbe5b1949887b9e1 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 21 Mar 2007 19:35:35 +0000 Subject: Add functions for creating and removing HAL devices --- network/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index d6c3ac0d..16a173c5 100644 --- a/network/main.c +++ b/network/main.c @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) hal_init(NULL); - hal_add_device(NULL); + hal_create_device(NULL); if (network_init() == -1) goto fail; @@ -81,6 +81,8 @@ int main(int argc, char *argv[]) network_exit(); + hal_remove_device(NULL); + hal_cleanup(); fail: -- cgit From 3ee5b90642bb7c8d2e88904600edac9d0d33efb4 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 27 Mar 2007 10:21:45 +0000 Subject: Improve D-Bus system bus integration --- network/main.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 16a173c5..74675184 100644 --- a/network/main.c +++ b/network/main.c @@ -48,6 +48,7 @@ static void sig_term(int sig) int main(int argc, char *argv[]) { + DBusConnection *conn; struct sigaction sa; start_logging("network", "Bluetooth Network daemon"); @@ -64,18 +65,26 @@ int main(int argc, char *argv[]) enable_debug(); - /* Create event loop */ main_loop = g_main_loop_new(NULL, FALSE); - hal_init(NULL); + conn = dbus_bus_system_setup_with_main_loop(NULL, NULL, NULL); + if (!conn) { + g_main_loop_unref(main_loop); + exit(1); + } + + hal_init(conn); hal_create_device(NULL); - if (network_init() == -1) - goto fail; + if (network_init(conn) < 0) { + dbus_connection_unref(conn); + g_main_loop_unref(main_loop); + exit(1); + } if (argc > 1 && !strcmp(argv[1], "-s")) - internal_service("network"); + register_external_service(conn, "network", "Network service", ""); g_main_loop_run(main_loop); @@ -85,7 +94,8 @@ int main(int argc, char *argv[]) hal_cleanup(); -fail: + dbus_connection_unref(conn); + g_main_loop_unref(main_loop); info("Exit"); -- cgit From 4d8f5eb37c895d875a7fdcce45f03c406adfa668 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 12 Apr 2007 18:42:47 +0000 Subject: network: changed the server D-Bus path and moved storage functions to manager.c --- network/main.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 74675184..2d9d44b6 100644 --- a/network/main.c +++ b/network/main.c @@ -33,6 +33,8 @@ #include #include +#include + #include "dbus.h" #include "logging.h" -- cgit From 2033d8e42102bb6513e5ea71e147a8a7dcce1420 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 28 Sep 2007 13:15:53 +0000 Subject: Add support for config file. --- network/main.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 2d9d44b6..5d1f5013 100644 --- a/network/main.c +++ b/network/main.c @@ -41,13 +41,128 @@ #include "manager.h" #include "hal.h" +#define IFACE_PREFIX "bnep%d" +#define PANU_IFACE "pan0" +#define GN_IFACE "pan1" +#define NAP_IFACE "pan2" + static GMainLoop *main_loop; +static struct network_conf conf = { + .connection_enabled = TRUE, + .server_enabled = TRUE, + .iface_prefix = NULL, + .conn.panu_script = NULL, + .conn.gn_script = NULL, + .conn.nap_script = NULL, + .server.panu_iface = NULL, + .server.gn_iface = NULL, + .server.nap_iface = NULL, + .server.disable_security = FALSE +}; + static void sig_term(int sig) { g_main_loop_quit(main_loop); } +static void read_config(const char *file) +{ + GKeyFile *keyfile; + GError *err = NULL; + + keyfile = g_key_file_new(); + + if (!g_key_file_load_from_file(keyfile, file, 0, &err)) { + error("Parsing %s failed: %s", file, err->message); + g_error_free(err); + g_key_file_free(keyfile); + return; + } + + conf.iface_prefix = g_key_file_get_string(keyfile, "Connection", + "InterfacePrefix", &err); + if (!conf.iface_prefix) + conf.iface_prefix = g_strdup(IFACE_PREFIX); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.conn.panu_script = g_key_file_get_string(keyfile, "Connection", + "PANUScript", &err); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.conn.gn_script = g_key_file_get_string(keyfile, "Connection", + "GNScript", &err); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.conn.nap_script = g_key_file_get_string(keyfile, "Connection", + "NAPScript", &err); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.server.panu_iface = g_key_file_get_string(keyfile, "Server", + "PANUInterface", &err); + if (!conf.server.panu_iface) + conf.server.panu_iface = g_strdup(PANU_IFACE); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.server.gn_iface = g_key_file_get_string(keyfile, "Server", + "GNInterface", &err); + if (!conf.server.gn_iface) + conf.server.gn_iface = g_strdup(GN_IFACE); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.server.nap_iface = g_key_file_get_string(keyfile, "Server", + "NAPInterface", &err); + if (!conf.server.nap_iface) + conf.server.nap_iface = g_strdup(NAP_IFACE); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + conf.server.disable_security = g_key_file_get_boolean(keyfile, "Server", + "DisableSecurity", &err); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + + debug("Config options: InterfacePrefix=%s, PANUScript=%s, GNScript=%s, " + "NAPScript=%s, PANUInterface=%s, GNInterface=%s, " + "NAPInterface=%s, DisableSecurity=%s", conf.iface_prefix, + conf.conn.panu_script, conf.conn.gn_script, conf.conn.nap_script, + conf.server.panu_iface, conf.server.gn_iface, + conf.server.nap_iface, + conf.server.disable_security ? "true" : "false"); + + g_key_file_free(keyfile); +} + int main(int argc, char *argv[]) { DBusConnection *conn; @@ -67,6 +182,8 @@ int main(int argc, char *argv[]) enable_debug(); + read_config(CONFIGDIR "/network.conf"); + main_loop = g_main_loop_new(NULL, FALSE); conn = dbus_bus_system_setup_with_main_loop(NULL, NULL, NULL); -- cgit From b94d1033b7c6919ca4705cf11139fb8224c3ecde Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 28 Sep 2007 13:19:21 +0000 Subject: Add bridge name support. --- network/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 5d1f5013..6260ac4e 100644 --- a/network/main.c +++ b/network/main.c @@ -196,7 +196,7 @@ int main(int argc, char *argv[]) hal_create_device(NULL); - if (network_init(conn) < 0) { + if (network_init(conn, &conf) < 0) { dbus_connection_unref(conn); g_main_loop_unref(main_loop); exit(1); -- cgit From 6113615ecfb8026a6a3ce0af38fc79ec8abec748 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 28 Sep 2007 13:23:51 +0000 Subject: Rework configuration file to use roles. --- network/main.c | 75 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 6260ac4e..3ede75fe 100644 --- a/network/main.c +++ b/network/main.c @@ -52,13 +52,12 @@ static struct network_conf conf = { .connection_enabled = TRUE, .server_enabled = TRUE, .iface_prefix = NULL, - .conn.panu_script = NULL, - .conn.gn_script = NULL, - .conn.nap_script = NULL, - .server.panu_iface = NULL, - .server.gn_iface = NULL, - .server.nap_iface = NULL, - .server.disable_security = FALSE + .panu_script = NULL, + .gn_script = NULL, + .nap_script = NULL, + .gn_iface = NULL, + .nap_iface = NULL, + .security = TRUE }; static void sig_term(int sig) @@ -70,6 +69,7 @@ static void read_config(const char *file) { GKeyFile *keyfile; GError *err = NULL; + const char *disabled; keyfile = g_key_file_new(); @@ -80,72 +80,75 @@ static void read_config(const char *file) return; } - conf.iface_prefix = g_key_file_get_string(keyfile, "Connection", - "InterfacePrefix", &err); - if (!conf.iface_prefix) - conf.iface_prefix = g_strdup(IFACE_PREFIX); + disabled = g_key_file_get_string(keyfile, "General", + "Disable", &err); if (err) { debug("%s: %s", file, err->message); g_error_free(err); err = NULL; + } else { + if (strstr(disabled, "Connection")) + conf.connection_enabled = FALSE; + if (strstr(disabled, "Server")) + conf.server_enabled = FALSE; } - conf.conn.panu_script = g_key_file_get_string(keyfile, "Connection", - "PANUScript", &err); + conf.iface_prefix = g_key_file_get_string(keyfile, "General", + "InterfacePrefix", &err); + if (!conf.iface_prefix) + conf.iface_prefix = g_strdup(IFACE_PREFIX); if (err) { debug("%s: %s", file, err->message); g_error_free(err); err = NULL; } - conf.conn.gn_script = g_key_file_get_string(keyfile, "Connection", - "GNScript", &err); + conf.security = g_key_file_get_boolean(keyfile, "General", + "DisableSecurity", &err); if (err) { debug("%s: %s", file, err->message); g_error_free(err); err = NULL; } - conf.conn.nap_script = g_key_file_get_string(keyfile, "Connection", - "NAPScript", &err); + conf.panu_script = g_key_file_get_string(keyfile, "PANU Role", + "Script", &err); if (err) { debug("%s: %s", file, err->message); g_error_free(err); err = NULL; } - conf.server.panu_iface = g_key_file_get_string(keyfile, "Server", - "PANUInterface", &err); - if (!conf.server.panu_iface) - conf.server.panu_iface = g_strdup(PANU_IFACE); + conf.gn_script = g_key_file_get_string(keyfile, "GN Role", + "Script", &err); if (err) { debug("%s: %s", file, err->message); g_error_free(err); err = NULL; } - conf.server.gn_iface = g_key_file_get_string(keyfile, "Server", - "GNInterface", &err); - if (!conf.server.gn_iface) - conf.server.gn_iface = g_strdup(GN_IFACE); + conf.nap_script = g_key_file_get_string(keyfile, "NAP Role", + "Script", &err); if (err) { debug("%s: %s", file, err->message); g_error_free(err); err = NULL; } - conf.server.nap_iface = g_key_file_get_string(keyfile, "Server", - "NAPInterface", &err); - if (!conf.server.nap_iface) - conf.server.nap_iface = g_strdup(NAP_IFACE); + conf.gn_iface = g_key_file_get_string(keyfile, "GN Role", + "Interface", &err); + if (!conf.gn_iface) + conf.gn_iface = g_strdup(GN_IFACE); if (err) { debug("%s: %s", file, err->message); g_error_free(err); err = NULL; } - conf.server.disable_security = g_key_file_get_boolean(keyfile, "Server", - "DisableSecurity", &err); + conf.nap_iface = g_key_file_get_string(keyfile, "NAP Role", + "Interface", &err); + if (!conf.nap_iface) + conf.nap_iface = g_strdup(NAP_IFACE); if (err) { debug("%s: %s", file, err->message); g_error_free(err); @@ -153,12 +156,10 @@ static void read_config(const char *file) } debug("Config options: InterfacePrefix=%s, PANUScript=%s, GNScript=%s, " - "NAPScript=%s, PANUInterface=%s, GNInterface=%s, " - "NAPInterface=%s, DisableSecurity=%s", conf.iface_prefix, - conf.conn.panu_script, conf.conn.gn_script, conf.conn.nap_script, - conf.server.panu_iface, conf.server.gn_iface, - conf.server.nap_iface, - conf.server.disable_security ? "true" : "false"); + "NAPScript=%s, GNInterface=%s, NAPInterface=%s, Security=%s", + conf.iface_prefix, conf.panu_script, conf.gn_script, + conf.nap_script, conf.gn_iface, conf.nap_iface, + conf.security ? "true" : "false"); g_key_file_free(keyfile); } -- cgit From ec7083e9e5ba28b679f231c7bc341330feddf2ce Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 28 Sep 2007 13:25:27 +0000 Subject: Fixes codestyle, bridge creation and some code cleanup. --- network/main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 3ede75fe..6225ff4e 100644 --- a/network/main.c +++ b/network/main.c @@ -103,7 +103,7 @@ static void read_config(const char *file) err = NULL; } - conf.security = g_key_file_get_boolean(keyfile, "General", + conf.security = !g_key_file_get_boolean(keyfile, "General", "DisableSecurity", &err); if (err) { debug("%s: %s", file, err->message); @@ -155,8 +155,9 @@ static void read_config(const char *file) err = NULL; } - debug("Config options: InterfacePrefix=%s, PANUScript=%s, GNScript=%s, " - "NAPScript=%s, GNInterface=%s, NAPInterface=%s, Security=%s", + debug("Config options: InterfacePrefix=%s, PANU_Script=%s, " + "GN_Script=%s, NAP_Script=%s, GN_Interface=%s, " + "NAP_Interface=%s, Security=%s", conf.iface_prefix, conf.panu_script, conf.gn_script, conf.nap_script, conf.gn_iface, conf.nap_iface, conf.security ? "true" : "false"); -- cgit From 684fe2781c46ccfb30a4e653fad126286bddcdcb Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 28 Sep 2007 13:29:59 +0000 Subject: Fix default configuration when config file is missing. --- network/main.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 6225ff4e..8c9bdc54 100644 --- a/network/main.c +++ b/network/main.c @@ -42,9 +42,8 @@ #include "hal.h" #define IFACE_PREFIX "bnep%d" -#define PANU_IFACE "pan0" -#define GN_IFACE "pan1" -#define NAP_IFACE "pan2" +#define GN_IFACE "pan0" +#define NAP_IFACE "pan1" static GMainLoop *main_loop; @@ -76,8 +75,7 @@ static void read_config(const char *file) if (!g_key_file_load_from_file(keyfile, file, 0, &err)) { error("Parsing %s failed: %s", file, err->message); g_error_free(err); - g_key_file_free(keyfile); - return; + goto done; } disabled = g_key_file_get_string(keyfile, "General", @@ -93,16 +91,6 @@ static void read_config(const char *file) conf.server_enabled = FALSE; } - conf.iface_prefix = g_key_file_get_string(keyfile, "General", - "InterfacePrefix", &err); - if (!conf.iface_prefix) - conf.iface_prefix = g_strdup(IFACE_PREFIX); - if (err) { - debug("%s: %s", file, err->message); - g_error_free(err); - err = NULL; - } - conf.security = !g_key_file_get_boolean(keyfile, "General", "DisableSecurity", &err); if (err) { @@ -135,10 +123,16 @@ static void read_config(const char *file) err = NULL; } + conf.iface_prefix = g_key_file_get_string(keyfile, "PANU Role", + "Interface", &err); + if (err) { + debug("%s: %s", file, err->message); + g_error_free(err); + err = NULL; + } + conf.gn_iface = g_key_file_get_string(keyfile, "GN Role", "Interface", &err); - if (!conf.gn_iface) - conf.gn_iface = g_strdup(GN_IFACE); if (err) { debug("%s: %s", file, err->message); g_error_free(err); @@ -147,22 +141,28 @@ static void read_config(const char *file) conf.nap_iface = g_key_file_get_string(keyfile, "NAP Role", "Interface", &err); - if (!conf.nap_iface) - conf.nap_iface = g_strdup(NAP_IFACE); if (err) { debug("%s: %s", file, err->message); g_error_free(err); err = NULL; } +done: + g_key_file_free(keyfile); + + if (!conf.iface_prefix) + conf.iface_prefix = g_strdup(IFACE_PREFIX); + if (!conf.gn_iface) + conf.gn_iface = g_strdup(GN_IFACE); + if (!conf.nap_iface) + conf.nap_iface = g_strdup(NAP_IFACE); + debug("Config options: InterfacePrefix=%s, PANU_Script=%s, " "GN_Script=%s, NAP_Script=%s, GN_Interface=%s, " "NAP_Interface=%s, Security=%s", conf.iface_prefix, conf.panu_script, conf.gn_script, conf.nap_script, conf.gn_iface, conf.nap_iface, conf.security ? "true" : "false"); - - g_key_file_free(keyfile); } int main(int argc, char *argv[]) -- cgit From e823c15e43a6f924779e466d434c51157002d9ee Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 2 Feb 2008 03:37:05 +0000 Subject: Update copyright information --- network/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 8c9bdc54..914cb9c1 100644 --- a/network/main.c +++ b/network/main.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2004-2007 Marcel Holtmann + * Copyright (C) 2004-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From 88e798a8b8126d997ded2adcebafbc3fb1fcb509 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 22 Mar 2008 15:49:07 +0000 Subject: Convert network service into a plugin --- network/main.c | 85 +++++++++++++++------------------------------------------- 1 file changed, 21 insertions(+), 64 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 914cb9c1..e749762e 100644 --- a/network/main.c +++ b/network/main.c @@ -25,28 +25,22 @@ #include #endif -#include -#include -#include -#include #include -#include -#include - +#include #include +#include +#include + +#include "plugin.h" #include "dbus.h" #include "logging.h" - #include "manager.h" -#include "hal.h" #define IFACE_PREFIX "bnep%d" #define GN_IFACE "pan0" #define NAP_IFACE "pan1" -static GMainLoop *main_loop; - static struct network_conf conf = { .connection_enabled = TRUE, .server_enabled = TRUE, @@ -59,11 +53,6 @@ static struct network_conf conf = { .security = TRUE }; -static void sig_term(int sig) -{ - g_main_loop_quit(main_loop); -} - static void read_config(const char *file) { GKeyFile *keyfile; @@ -165,63 +154,31 @@ done: conf.security ? "true" : "false"); } -int main(int argc, char *argv[]) -{ - DBusConnection *conn; - struct sigaction sa; - - start_logging("network", "Bluetooth Network daemon"); - - memset(&sa, 0, sizeof(sa)); - sa.sa_flags = SA_NOCLDSTOP; - sa.sa_handler = sig_term; - sigaction(SIGTERM, &sa, NULL); - sigaction(SIGINT, &sa, NULL); +static DBusConnection *conn; - sa.sa_handler = SIG_IGN; - sigaction(SIGCHLD, &sa, NULL); - sigaction(SIGPIPE, &sa, NULL); - - enable_debug(); +static int network_init(void) +{ + conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (conn == NULL) + return -EIO; read_config(CONFIGDIR "/network.conf"); - main_loop = g_main_loop_new(NULL, FALSE); - - conn = dbus_bus_system_setup_with_main_loop(NULL, NULL, NULL); - if (!conn) { - g_main_loop_unref(main_loop); - exit(1); - } - - hal_init(conn); - - hal_create_device(NULL); - - if (network_init(conn, &conf) < 0) { + if (network_manager_init(conn, &conf) < 0) { dbus_connection_unref(conn); - g_main_loop_unref(main_loop); - exit(1); + return -EIO; } - if (argc > 1 && !strcmp(argv[1], "-s")) - register_external_service(conn, "network", "Network service", ""); + register_external_service(conn, "network", "Network service", ""); - g_main_loop_run(main_loop); - - network_exit(); - - hal_remove_device(NULL); + return 0; +} - hal_cleanup(); +static void network_exit(void) +{ + network_manager_exit(); dbus_connection_unref(conn); - - g_main_loop_unref(main_loop); - - info("Exit"); - - stop_logging(); - - return 0; } + +BLUETOOTH_PLUGIN_DEFINE("network", network_init, network_exit) -- cgit From 31f2ffeffd5ff735329821113c4d4d4d54f4f8dd Mon Sep 17 00:00:00 2001 From: Vinicius Gomes Date: Fri, 11 Apr 2008 23:04:17 +0000 Subject: network: fixes a memory leak when reading the Disable config option. --- network/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index e749762e..66266b90 100644 --- a/network/main.c +++ b/network/main.c @@ -57,7 +57,7 @@ static void read_config(const char *file) { GKeyFile *keyfile; GError *err = NULL; - const char *disabled; + char *disabled; keyfile = g_key_file_new(); @@ -79,6 +79,7 @@ static void read_config(const char *file) if (strstr(disabled, "Server")) conf.server_enabled = FALSE; } + g_free(disabled); conf.security = !g_key_file_get_boolean(keyfile, "General", "DisableSecurity", &err); -- cgit From 098cd10838193272c669348c5ffd0410218e1bcc Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 1 May 2008 01:05:46 +0000 Subject: fixed service authorization --- network/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 66266b90..2dfd6696 100644 --- a/network/main.c +++ b/network/main.c @@ -41,6 +41,17 @@ #define GN_IFACE "pan0" #define NAP_IFACE "pan1" +#define PANU_UUID "00001115-0000-1000-8000-00805f9b34fb" +#define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb" +#define GN_UUID "00001117-0000-1000-8000-00805f9b34fb" + +static const char *uuids[] = { + PANU_UUID, + NAP_UUID, + GN_UUID, + NULL +}; + static struct network_conf conf = { .connection_enabled = TRUE, .server_enabled = TRUE, @@ -170,6 +181,8 @@ static int network_init(void) return -EIO; } + register_uuids("network", &uuids); + register_external_service(conn, "network", "Network service", ""); return 0; -- cgit From 3f8860031e5241fbb145fdd71e1a46c2c28f393e Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 1 May 2008 01:23:02 +0000 Subject: fixed build warnings --- network/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 2dfd6696..576ead8e 100644 --- a/network/main.c +++ b/network/main.c @@ -33,6 +33,7 @@ #include #include "plugin.h" +#include "dbus-service.h" #include "dbus.h" #include "logging.h" #include "manager.h" @@ -181,7 +182,7 @@ static int network_init(void) return -EIO; } - register_uuids("network", &uuids); + register_uuids("network", uuids); register_external_service(conn, "network", "Network service", ""); -- cgit From 9491a544f622e40453265c30f24ce44a61440cc1 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 1 May 2008 13:52:26 +0000 Subject: Moving authorization code to dbus-service.c --- network/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 576ead8e..037ee062 100644 --- a/network/main.c +++ b/network/main.c @@ -29,12 +29,10 @@ #include #include -#include -#include +#include "dbus.h" #include "plugin.h" #include "dbus-service.h" -#include "dbus.h" #include "logging.h" #include "manager.h" -- cgit From 2af3c3a7ddc43577c067892cdfdc06dc4e63386c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 8 May 2008 17:24:48 +0000 Subject: Remove service daemon activation handling --- network/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 037ee062..54bdf3d6 100644 --- a/network/main.c +++ b/network/main.c @@ -180,15 +180,19 @@ static int network_init(void) return -EIO; } - register_uuids("network", uuids); + register_service("network"); - register_external_service(conn, "network", "Network service", ""); + register_uuids("network", uuids); return 0; } static void network_exit(void) { + unregister_uuids("network"); + + unregister_service("network"); + network_manager_exit(); dbus_connection_unref(conn); -- cgit From b5514e6c7f0258da455bbde02482fbcdb29d4442 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 8 May 2008 18:37:09 +0000 Subject: Register service and UUIDs in one step --- network/main.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 54bdf3d6..c84ba59b 100644 --- a/network/main.c +++ b/network/main.c @@ -180,17 +180,13 @@ static int network_init(void) return -EIO; } - register_service("network"); - - register_uuids("network", uuids); + register_service("network", uuids); return 0; } static void network_exit(void) { - unregister_uuids("network"); - unregister_service("network"); network_manager_exit(); -- cgit From e7d668ac9e813bc9922ee7d771848bd8822d5d1f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 8 May 2008 20:23:45 +0000 Subject: Move D-Bus watch functions into libgdbus --- network/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index c84ba59b..f710080f 100644 --- a/network/main.c +++ b/network/main.c @@ -29,7 +29,8 @@ #include #include -#include "dbus.h" +#include +#include #include "plugin.h" #include "dbus-service.h" -- cgit From 86ca72eb302bc00c6c58b56d20ba06f1d7000214 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 16 May 2008 12:49:57 +0000 Subject: Use g_key_file_get_string_list instead of g_key_file_get_string --- network/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index f710080f..02c3fcc8 100644 --- a/network/main.c +++ b/network/main.c @@ -68,7 +68,7 @@ static void read_config(const char *file) { GKeyFile *keyfile; GError *err = NULL; - char *disabled; + char **disabled; keyfile = g_key_file_new(); @@ -78,19 +78,22 @@ static void read_config(const char *file) goto done; } - disabled = g_key_file_get_string(keyfile, "General", - "Disable", &err); + disabled = g_key_file_get_string_list(keyfile, "General", + "Disable", NULL, &err); if (err) { debug("%s: %s", file, err->message); g_error_free(err); err = NULL; } else { - if (strstr(disabled, "Connection")) - conf.connection_enabled = FALSE; - if (strstr(disabled, "Server")) - conf.server_enabled = FALSE; + int i; + for (i = 0; disabled[i] != NULL; i++) { + if (g_str_equal(disabled[i], "Connection")) + conf.connection_enabled = FALSE; + else if (g_str_equal(disabled[i], "Server")) + conf.server_enabled = FALSE; + } + g_strfreev(disabled); } - g_free(disabled); conf.security = !g_key_file_get_boolean(keyfile, "General", "DisableSecurity", &err); -- cgit From 2d6bcaff198acfb9453416fd73df2358dec96108 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 29 May 2008 08:35:54 +0000 Subject: Register network service as network driver --- network/main.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 02c3fcc8..dd53c1d1 100644 --- a/network/main.c +++ b/network/main.c @@ -26,30 +26,43 @@ #endif #include -#include + #include -#include -#include +#include #include "plugin.h" -#include "dbus-service.h" +#include "device.h" #include "logging.h" #include "manager.h" #define IFACE_PREFIX "bnep%d" -#define GN_IFACE "pan0" +#define GN_IFACE "pan0" #define NAP_IFACE "pan1" #define PANU_UUID "00001115-0000-1000-8000-00805f9b34fb" -#define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb" -#define GN_UUID "00001117-0000-1000-8000-00805f9b34fb" - -static const char *uuids[] = { - PANU_UUID, - NAP_UUID, - GN_UUID, - NULL +#define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb" +#define GN_UUID "00001117-0000-1000-8000-00805f9b34fb" + +static DBusConnection *conn; + +static int network_probe(const char *path) +{ + debug("path %s", path); + + return 0; +} + +static void network_remove(const char *path) +{ + debug("path %s", path); +} + +static struct btd_device_driver network_driver = { + .name = "network", + .uuids = BTD_UUIDS(PANU_UUID, NAP_UUID, GN_UUID), + .probe = network_probe, + .remove = network_remove, }; static struct network_conf conf = { @@ -169,8 +182,6 @@ done: conf.security ? "true" : "false"); } -static DBusConnection *conn; - static int network_init(void) { conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); @@ -184,14 +195,14 @@ static int network_init(void) return -EIO; } - register_service("network", uuids); + btd_register_device_driver(&network_driver); return 0; } static void network_exit(void) { - unregister_service("network"); + btd_unregister_device_driver(&network_driver); network_manager_exit(); -- cgit From 8bf636881f152a97727774f4f9ea2504c72dfb23 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 8 Jun 2008 20:54:55 +0000 Subject: Use DBG in plugin to show function names --- network/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index dd53c1d1..106c2a76 100644 --- a/network/main.c +++ b/network/main.c @@ -48,14 +48,14 @@ static DBusConnection *conn; static int network_probe(const char *path) { - debug("path %s", path); + DBG("path %s", path); return 0; } static void network_remove(const char *path) { - debug("path %s", path); + DBG("path %s", path); } static struct btd_device_driver network_driver = { -- cgit From 0f62b72c8564608f849b3bbe54bf48db07c45015 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 8 Jun 2008 21:21:54 +0000 Subject: Update plugin interface registration --- network/main.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 106c2a76..edfd0757 100644 --- a/network/main.c +++ b/network/main.c @@ -44,18 +44,61 @@ #define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb" #define GN_UUID "00001117-0000-1000-8000-00805f9b34fb" +#define NETWORK_INTERFACE "org.bluez.Network" + +static DBusMessage *network_connect(DBusConnection *conn, + DBusMessage *msg, void *user_data) +{ + const char *target, *device = "bnep0"; + + if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &target, + DBUS_TYPE_INVALID) == FALSE) + return NULL; + + return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &device, + DBUS_TYPE_INVALID); +} + +static DBusMessage *network_disconnect(DBusConnection *conn, + DBusMessage *msg, void *user_data) +{ + if (dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID) == FALSE) + return NULL; + + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); +} + +static GDBusMethodTable network_methods[] = { + { "Connect", "s", "s", network_connect }, + { "Disconnect", "", "", network_disconnect }, + { } +}; + +static GDBusSignalTable network_signals[] = { + { "Connected", "ss" }, + { "Disconnected", "s" }, + { } +}; + static DBusConnection *conn; static int network_probe(const char *path) { DBG("path %s", path); + if (g_dbus_register_interface(conn, path, NETWORK_INTERFACE, + network_methods, network_signals, NULL, + NULL, NULL) == FALSE) + return -1; + return 0; } static void network_remove(const char *path) { DBG("path %s", path); + + g_dbus_unregister_interface(conn, path, NETWORK_INTERFACE); } static struct btd_device_driver network_driver = { -- cgit From 5243ac4fd278b0176ece84cbcec537a92a9c7290 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 8 Jun 2008 22:57:11 +0000 Subject: Update probe/remove callback and implement serial API --- network/main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index edfd0757..8e18dd99 100644 --- a/network/main.c +++ b/network/main.c @@ -82,23 +82,23 @@ static GDBusSignalTable network_signals[] = { static DBusConnection *conn; -static int network_probe(const char *path) +static int network_probe(struct btd_device *device) { - DBG("path %s", path); + DBG("path %s", device->path); - if (g_dbus_register_interface(conn, path, NETWORK_INTERFACE, + if (g_dbus_register_interface(conn, device->path, NETWORK_INTERFACE, network_methods, network_signals, NULL, - NULL, NULL) == FALSE) + device, NULL) == FALSE) return -1; return 0; } -static void network_remove(const char *path) +static void network_remove(struct btd_device *device) { - DBG("path %s", path); + DBG("path %s", device->path); - g_dbus_unregister_interface(conn, path, NETWORK_INTERFACE); + g_dbus_unregister_interface(conn, device->path, NETWORK_INTERFACE); } static struct btd_device_driver network_driver = { -- cgit From c4139033616c53b1f790fe165d1a22fcce292e74 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Mon, 30 Jun 2008 17:35:47 +0000 Subject: Fixed missing include --- network/main.c | 1 + 1 file changed, 1 insertion(+) (limited to 'network/main.c') diff --git a/network/main.c b/network/main.c index 8e18dd99..f18223cc 100644 --- a/network/main.c +++ b/network/main.c @@ -28,6 +28,7 @@ #include #include +#include #include -- cgit