From e6fe40e5e92a6942869a2fc7e7cb210d18da3929 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 26 Feb 2007 00:15:27 +0000 Subject: Add skeleton for serial port service --- serial/main.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 serial/main.c (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c new file mode 100644 index 00000000..b6f52d46 --- /dev/null +++ b/serial/main.c @@ -0,0 +1,60 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2007 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 + +#include "logging.h" + +static void sig_term(int sig) +{ +} + +int main(int argc, char *argv[]) +{ + struct sigaction sa; + + start_logging("serial", "Bluetooth Serial Port 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(); + + info("Exit"); + + stop_logging(); + + return 0; +} -- cgit From 6dc594dbea588a7285dff7eac35d1c0c3fca206d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 23 Apr 2007 17:12:00 +0000 Subject: Add skeleton for manager interface --- serial/main.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index b6f52d46..d249e672 100644 --- a/serial/main.c +++ b/serial/main.c @@ -30,6 +30,8 @@ #include "logging.h" +#include "manager.h" + static void sig_term(int sig) { } -- cgit From cdb1b7c3435688bc6f30a3953f1152247ec51b95 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Tue, 1 May 2007 11:23:55 +0000 Subject: serial: added main loop integration --- serial/main.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index d249e672..5bacd121 100644 --- a/serial/main.c +++ b/serial/main.c @@ -25,19 +25,26 @@ #include #endif +#include #include #include +#include #include "logging.h" +#include "dbus.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[]) { + DBusConnection *conn; struct sigaction sa; start_logging("serial", "Bluetooth Serial Port daemon"); @@ -54,6 +61,31 @@ int main(int argc, char *argv[]) enable_debug(); + 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(EXIT_FAILURE); + } + + if (serial_init(conn) < 0) { + dbus_connection_unref(conn); + g_main_loop_unref(main_loop); + exit(EXIT_FAILURE); + } + + if (argc > 1 && !strcmp(argv[1], "-s")) + register_external_service(conn, "serial", "Serial service", ""); + + g_main_loop_run(main_loop); + + serial_exit(); + + dbus_connection_unref(conn); + + g_main_loop_unref(main_loop); + info("Exit"); stop_logging(); -- 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 --- serial/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index 5bacd121..3554eeeb 100644 --- a/serial/main.c +++ b/serial/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 d78b22fe007467b1e5129e6e7f0f5752fac85efe Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 22 Mar 2008 16:07:37 +0000 Subject: Convert serial service to a plugin --- serial/main.c | 73 +++++++++++++++++------------------------------------------ 1 file changed, 21 insertions(+), 52 deletions(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index 3554eeeb..466ee883 100644 --- a/serial/main.c +++ b/serial/main.c @@ -25,70 +25,39 @@ #include #endif -#include -#include -#include -#include -#include "logging.h" -#include "dbus.h" +#include +#include -#include "manager.h" +#include -static GMainLoop *main_loop; +#include "plugin.h" +#include "dbus.h" +#include "manager.h" -static void sig_term(int sig) -{ - g_main_loop_quit(main_loop); -} +static DBusConnection *conn; -int main(int argc, char *argv[]) +static int serial_init(void) { - DBusConnection *conn; - struct sigaction sa; - - start_logging("serial", "Bluetooth Serial Port 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(); - - main_loop = g_main_loop_new(NULL, FALSE); + conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (conn == NULL) + return -EIO; - conn = dbus_bus_system_setup_with_main_loop(NULL, NULL, NULL); - if (!conn) { - g_main_loop_unref(main_loop); - exit(EXIT_FAILURE); - } - - if (serial_init(conn) < 0) { + if (serial_manager_init(conn) < 0) { dbus_connection_unref(conn); - g_main_loop_unref(main_loop); - exit(EXIT_FAILURE); + return -EIO; } - if (argc > 1 && !strcmp(argv[1], "-s")) - register_external_service(conn, "serial", "Serial service", ""); + register_external_service(conn, "serial", "Serial service", ""); - g_main_loop_run(main_loop); + return 0; +} - serial_exit(); +static void serial_exit(void) +{ + serial_manager_exit(); dbus_connection_unref(conn); - - g_main_loop_unref(main_loop); - - info("Exit"); - - stop_logging(); - - return 0; } + +BLUETOOTH_PLUGIN_DEFINE("serial", serial_init, serial_exit) -- cgit From 60202f31c998cc68c14f57c91e4b40d2c39f95f2 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Wed, 9 Apr 2008 22:00:34 +0000 Subject: Broken build: missing headers --- serial/main.c | 1 + 1 file changed, 1 insertion(+) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index 466ee883..9d094123 100644 --- a/serial/main.c +++ b/serial/main.c @@ -29,6 +29,7 @@ #include #include +#include #include #include "plugin.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 --- serial/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index 9d094123..0916f760 100644 --- a/serial/main.c +++ b/serial/main.c @@ -34,6 +34,7 @@ #include "plugin.h" #include "dbus.h" +#include "dbus-service.h" #include "manager.h" static DBusConnection *conn; @@ -49,13 +50,15 @@ static int serial_init(void) return -EIO; } - register_external_service(conn, "serial", "Serial service", ""); + register_service("serial"); return 0; } static void serial_exit(void) { + unregister_service("serial"); + serial_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 --- serial/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index 0916f760..57a65f88 100644 --- a/serial/main.c +++ b/serial/main.c @@ -50,7 +50,7 @@ static int serial_init(void) return -EIO; } - register_service("serial"); + register_service("serial", NULL); return 0; } -- 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 --- serial/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index 57a65f88..b4533a01 100644 --- a/serial/main.c +++ b/serial/main.c @@ -30,10 +30,11 @@ #include #include + +#include #include #include "plugin.h" -#include "dbus.h" #include "dbus-service.h" #include "manager.h" -- cgit From 24cce397c3479e95f3e525da9285234fbafd2984 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 28 May 2008 13:11:05 +0000 Subject: Add first skeletion of device driver integration --- serial/main.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index b4533a01..24de70a5 100644 --- a/serial/main.c +++ b/serial/main.c @@ -35,11 +35,32 @@ #include #include "plugin.h" +#include "device.h" +#include "logging.h" #include "dbus-service.h" #include "manager.h" static DBusConnection *conn; +static int serial_probe(const char *path) +{ + debug("path %s", path); + + return 0; +} + +static void serial_remove(const char *path) +{ + debug("path %s", path); +} + +static struct btd_device_driver serial_driver = { + .name = "serial", + .uuids = BTD_UUIDS("spp", "dun"), + .probe = serial_probe, + .remove = serial_remove, +}; + static int serial_init(void) { conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); @@ -53,11 +74,15 @@ static int serial_init(void) register_service("serial", NULL); + btd_register_device_driver(&serial_driver); + return 0; } static void serial_exit(void) { + btd_unregister_device_driver(&serial_driver); + unregister_service("serial"); serial_manager_exit(); -- cgit From a1a1a2637ec9090c021dd83ed7707aabf5a8c0f4 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 28 May 2008 13:22:23 +0000 Subject: Add basic D-Bus skeleton --- serial/main.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index 24de70a5..fcff75f5 100644 --- a/serial/main.c +++ b/serial/main.c @@ -31,8 +31,7 @@ #include -#include -#include +#include #include "plugin.h" #include "device.h" @@ -40,18 +39,54 @@ #include "dbus-service.h" #include "manager.h" +#define SERIAL_INTERFACE "org.bluez.Serial" + +static DBusMessage *serial_connect(DBusConnection *conn, + DBusMessage *msg, void *user_data) +{ + const char *target, *device = "/dev/rfcomm0"; + + 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 *serial_disconnect(DBusConnection *conn, + DBusMessage *msg, void *user_data) +{ + const char *device; + + if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &device, + DBUS_TYPE_INVALID) == FALSE) + return NULL; + + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); +} + +static GDBusMethodTable serial_methods[] = { + { "Connect", "s", "s", serial_connect }, + { "Disconnect", "s", "", serial_disconnect }, + { } +}; + static DBusConnection *conn; static int serial_probe(const char *path) { debug("path %s", path); - return 0; + return g_dbus_register_interface(conn, path, SERIAL_INTERFACE, + serial_methods, NULL, NULL, NULL, NULL); } static void serial_remove(const char *path) { debug("path %s", path); + + g_dbus_unregister_interface(conn, path, SERIAL_INTERFACE); } static struct btd_device_driver serial_driver = { -- cgit From de29b2ff1d8531fd0583e49e4b8840198681ffe8 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 29 May 2008 07:39:11 +0000 Subject: Handle the service UUID mapping via device driver --- serial/main.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index fcff75f5..d0d24982 100644 --- a/serial/main.c +++ b/serial/main.c @@ -36,7 +36,6 @@ #include "plugin.h" #include "device.h" #include "logging.h" -#include "dbus-service.h" #include "manager.h" #define SERIAL_INTERFACE "org.bluez.Serial" @@ -107,8 +106,6 @@ static int serial_init(void) return -EIO; } - register_service("serial", NULL); - btd_register_device_driver(&serial_driver); return 0; @@ -118,8 +115,6 @@ static void serial_exit(void) { btd_unregister_device_driver(&serial_driver); - unregister_service("serial"); - serial_manager_exit(); dbus_connection_unref(conn); -- cgit From 03b145d3945ccce2855d7a09944c81c9badf798a Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 8 Jun 2008 17:16:28 +0000 Subject: Fix up the serial UUIDs --- serial/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index d0d24982..3c69642c 100644 --- a/serial/main.c +++ b/serial/main.c @@ -40,6 +40,9 @@ #define SERIAL_INTERFACE "org.bluez.Serial" +#define SERIAL_PORT_UUID "00001101-0000-1000-8000-00805F9B34FB" +#define DIALUP_NET_UUID "00001103-0000-1000-8000-00805F9B34FB" + static DBusMessage *serial_connect(DBusConnection *conn, DBusMessage *msg, void *user_data) { @@ -90,7 +93,7 @@ static void serial_remove(const char *path) static struct btd_device_driver serial_driver = { .name = "serial", - .uuids = BTD_UUIDS("spp", "dun"), + .uuids = BTD_UUIDS(SERIAL_PORT_UUID, DIALUP_NET_UUID), .probe = serial_probe, .remove = serial_remove, }; -- 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 --- serial/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index 3c69642c..ee1cb9f9 100644 --- a/serial/main.c +++ b/serial/main.c @@ -78,7 +78,7 @@ static DBusConnection *conn; static int serial_probe(const char *path) { - debug("path %s", path); + DBG("path %s", path); return g_dbus_register_interface(conn, path, SERIAL_INTERFACE, serial_methods, NULL, NULL, NULL, NULL); @@ -86,7 +86,7 @@ static int serial_probe(const char *path) static void serial_remove(const char *path) { - debug("path %s", path); + DBG("path %s", path); g_dbus_unregister_interface(conn, path, SERIAL_INTERFACE); } -- 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 --- serial/main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index ee1cb9f9..b042e2e7 100644 --- a/serial/main.c +++ b/serial/main.c @@ -38,11 +38,11 @@ #include "logging.h" #include "manager.h" -#define SERIAL_INTERFACE "org.bluez.Serial" - #define SERIAL_PORT_UUID "00001101-0000-1000-8000-00805F9B34FB" #define DIALUP_NET_UUID "00001103-0000-1000-8000-00805F9B34FB" +#define SERIAL_INTERFACE "org.bluez.Serial" + static DBusMessage *serial_connect(DBusConnection *conn, DBusMessage *msg, void *user_data) { @@ -80,8 +80,12 @@ static int serial_probe(const char *path) { DBG("path %s", path); - return g_dbus_register_interface(conn, path, SERIAL_INTERFACE, - serial_methods, NULL, NULL, NULL, NULL); + if (g_dbus_register_interface(conn, path, SERIAL_INTERFACE, + serial_methods, NULL, NULL, + NULL, NULL) == FALSE) + return -1; + + return 0; } static void serial_remove(const char *path) -- 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 --- serial/main.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index b042e2e7..60ce9d45 100644 --- a/serial/main.c +++ b/serial/main.c @@ -35,64 +35,84 @@ #include "plugin.h" #include "device.h" +#include "adapter.h" #include "logging.h" #include "manager.h" +#include "port.h" #define SERIAL_PORT_UUID "00001101-0000-1000-8000-00805F9B34FB" #define DIALUP_NET_UUID "00001103-0000-1000-8000-00805F9B34FB" -#define SERIAL_INTERFACE "org.bluez.Serial" +#define SERIAL_INTERFACE "org.bluez.Serial" +#define ERROR_INVALID_ARGS "org.bluez.Error.InvalidArguments" +#define ERROR_DOES_NOT_EXIST "org.bluez.Error.DoesNotExist" static DBusMessage *serial_connect(DBusConnection *conn, DBusMessage *msg, void *user_data) { - const char *target, *device = "/dev/rfcomm0"; + struct btd_device *device = user_data; + const char *target; + char src[18], dst[18]; 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); + ba2str(&device->src, src); + ba2str(&device->dst, dst); + + service_connect(conn, msg, src, dst, target); + + return NULL; } static DBusMessage *serial_disconnect(DBusConnection *conn, DBusMessage *msg, void *user_data) { - const char *device; + const char *device, *sender; + int err, id; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &device, DBUS_TYPE_INVALID) == FALSE) return NULL; + sender = dbus_message_get_sender(msg); + + if (sscanf(device, "/dev/rfcomm%d", &id) != 1) + return g_dbus_create_error(msg, ERROR_INVALID_ARGS, NULL); + + err = port_remove_listener(sender, device); + if (err < 0) + return g_dbus_create_error(msg, ERROR_DOES_NOT_EXIST, NULL); + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } static GDBusMethodTable serial_methods[] = { - { "Connect", "s", "s", serial_connect }, + { "Connect", "s", "s", serial_connect, G_DBUS_METHOD_FLAG_ASYNC }, { "Disconnect", "s", "", serial_disconnect }, { } }; static DBusConnection *conn; -static int serial_probe(const char *path) +static int serial_probe(struct btd_device *device) { - DBG("path %s", path); + DBG("path %s", device->path); - if (g_dbus_register_interface(conn, path, SERIAL_INTERFACE, + if (g_dbus_register_interface(conn, device->path, SERIAL_INTERFACE, serial_methods, NULL, NULL, - NULL, NULL) == FALSE) + device, NULL) == FALSE) return -1; return 0; } -static void serial_remove(const char *path) +static void serial_remove(struct btd_device *device) { - DBG("path %s", path); + DBG("path %s", device->path); - g_dbus_unregister_interface(conn, path, SERIAL_INTERFACE); + g_dbus_unregister_interface(conn, device->path, SERIAL_INTERFACE); } static struct btd_device_driver serial_driver = { -- cgit From 64f8405b60509908b8668a4160d3ebe120f7b67f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 8 Jun 2008 22:59:14 +0000 Subject: Remove empty line --- serial/main.c | 1 - 1 file changed, 1 deletion(-) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index 60ce9d45..0de87da3 100644 --- a/serial/main.c +++ b/serial/main.c @@ -25,7 +25,6 @@ #include #endif - #include #include -- 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 --- serial/main.c | 1 + 1 file changed, 1 insertion(+) (limited to 'serial/main.c') diff --git a/serial/main.c b/serial/main.c index 0de87da3..20aea93a 100644 --- a/serial/main.c +++ b/serial/main.c @@ -29,6 +29,7 @@ #include #include +#include #include -- cgit