* [PATCH v7 01/16] bluetooth: Add Serial interface definition
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 02/16] dundee: Add documentation Daniel Wagner
` (15 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 577 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
plugins/bluetooth.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index daa1873..4fc16ad 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -27,6 +27,7 @@
#define BLUEZ_ADAPTER_INTERFACE BLUEZ_SERVICE ".Adapter"
#define BLUEZ_DEVICE_INTERFACE BLUEZ_SERVICE ".Device"
#define BLUEZ_SERVICE_INTERFACE BLUEZ_SERVICE ".Service"
+#define BLUEZ_SERIAL_INTERFACE BLUEZ_SERVICE ".Serial"
#define DBUS_TIMEOUT 15
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 02/16] dundee: Add documentation
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 01/16] bluetooth: Add Serial interface definition Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 03/16] dundee: Add test scripts Daniel Wagner
` (14 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2430 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
doc/dundee-api.txt | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 doc/dundee-api.txt
diff --git a/doc/dundee-api.txt b/doc/dundee-api.txt
new file mode 100644
index 0000000..9f4cfe6
--- /dev/null
+++ b/doc/dundee-api.txt
@@ -0,0 +1,76 @@
+
+Manager hierarchy
+=================
+
+Service org.ofono.dundee
+Interface org.ofono.dundee.Manager
+Object path /
+
+Methods array{object,dict} GetDevices()
+
+ Get an array of device objects and properties
+ that represent the currently attached devices.
+
+ This method call should only be used once when an
+ application starts up. Further device additions
+ and removal shall be monitored via DeviceAdded and
+ DeviceRemoved signals.
+
+Signals DeviceAdded(object path, dict properties)
+
+ Signal that is sent when a new device is added. It
+ contains the object path of new device and its
+ properties.
+
+ DeviceRemoved(object path)
+
+ Signal that is sent when a device has been removed.
+ The object path is no longer accessible after this
+ signal and only emitted for reference.
+
+
+Device hierarchy
+================
+
+Service org.ofono.dundee
+Interface org.ofono.dundee.Device
+Object path /{device0,device1,...}
+
+Methods dict GetProperties()
+
+ Returns properties for the device object. See
+ the properties section for available properties.
+
+Signals PropertyChanged(string name, variant value)
+
+ This signal indicates a changed value of the given
+ property.
+
+Properties string Name [readonly]
+
+ Friendly name of the device.
+
+ boolean Active [readwrite]
+
+ Holds whether the device is connected. A
+ connection will be established when this value
+ is set to true. A existing connection will be
+ teared down when set to false.
+
+ dict Settings [readonly]
+
+ Holds all the IP network settings.
+
+ string Interface [readonly, optional]
+
+ Holds the interface of the network interface
+ used by this connection (e.g. "ppp0" "usb0")
+
+ string Address [readonly, optional]
+
+ Holds the IP address for this connection.
+
+ array{string} DomainNameServers [readonly, optional]
+
+ Holds the list of domain name servers for this
+ connection.
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 03/16] dundee: Add test scripts
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 01/16] bluetooth: Add Serial interface definition Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 02/16] dundee: Add documentation Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 04/16] dundee: Add skeleton implementation Daniel Wagner
` (13 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 4907 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
test/dundee-connect | 20 +++++++++
test/dundee-disconnect | 20 +++++++++
test/monitor-dundee | 109 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 149 insertions(+)
create mode 100755 test/dundee-connect
create mode 100755 test/dundee-disconnect
create mode 100755 test/monitor-dundee
diff --git a/test/dundee-connect b/test/dundee-connect
new file mode 100755
index 0000000..0e1ae40
--- /dev/null
+++ b/test/dundee-connect
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import dbus
+import sys
+
+bus = dbus.SystemBus()
+
+if len(sys.argv) == 2:
+ path = sys.argv[1]
+else:
+ manager = dbus.Interface(bus.get_object('org.ofono.dundee', '/'),
+ 'org.ofono.dundee.Manager')
+ devices = manager.GetDevices()
+ path = devices[0][0]
+
+print "Connect device %s..." % path
+device = dbus.Interface(bus.get_object('org.ofono.dundee', path),
+ 'org.ofono.dundee.Device')
+
+device.SetProperty("Active", True)
diff --git a/test/dundee-disconnect b/test/dundee-disconnect
new file mode 100755
index 0000000..5b3113e
--- /dev/null
+++ b/test/dundee-disconnect
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import dbus
+import sys
+
+bus = dbus.SystemBus()
+
+if len(sys.argv) == 2:
+ path = sys.argv[1]
+else:
+ manager = dbus.Interface(bus.get_object('org.ofono.dundee', '/'),
+ 'org.ofono.dundee.Manager')
+ devices = manager.GetDevices()
+ path = devices[0][0]
+
+print "Disonnect device %s..." % path
+device = dbus.Interface(bus.get_object('org.ofono.dundee', path),
+ 'org.ofono.dundee.Device')
+
+device.SetProperty("Active", False)
diff --git a/test/monitor-dundee b/test/monitor-dundee
new file mode 100755
index 0000000..cf96ceb
--- /dev/null
+++ b/test/monitor-dundee
@@ -0,0 +1,109 @@
+#!/usr/bin/python
+
+import gobject
+
+import dbus
+import dbus.mainloop.glib
+
+_dbus2py = {
+ dbus.String : unicode,
+ dbus.UInt32 : int,
+ dbus.Int32 : int,
+ dbus.Int16 : int,
+ dbus.UInt16 : int,
+ dbus.UInt64 : int,
+ dbus.Int64 : int,
+ dbus.Byte : int,
+ dbus.Boolean : bool,
+ dbus.ByteArray : str,
+ dbus.ObjectPath : str
+ }
+
+def dbus2py(d):
+ t = type(d)
+ if t in _dbus2py:
+ return _dbus2py[t](d)
+ if t is dbus.Dictionary:
+ return dict([(dbus2py(k), dbus2py(v)) for k, v in d.items()])
+ if t is dbus.Array and d.signature == "y":
+ return "".join([chr(b) for b in d])
+ if t is dbus.Array or t is list:
+ return [dbus2py(v) for v in d]
+ if t is dbus.Struct or t is tuple:
+ return tuple([dbus2py(v) for v in d])
+ return d
+
+def pretty(d):
+ d = dbus2py(d)
+ t = type(d)
+
+ if t in (dict, tuple, list) and len(d) > 0:
+ if t is dict:
+ d = ", ".join(["%s = %s" % (k, pretty(v))
+ for k, v in d.items()])
+ return "{ %s }" % d
+
+ d = " ".join([pretty(e) for e in d])
+
+ if t is tuple:
+ return "( %s )" % d
+
+ return str(d)
+
+def property_changed(name, value, path, interface):
+ iface = interface[interface.rfind(".") + 1:]
+ print "{%s} [%s] %s = %s" % (iface, path, name, pretty(value))
+
+def added(name, value, member, path, interface):
+ iface = interface[interface.rfind(".") + 1:]
+ print "{%s} [%s] %s %s" % (iface, member, name, pretty(value))
+
+def removed(name, member, path, interface):
+ iface = interface[interface.rfind(".") + 1:]
+ print "{%s} [%s] %s" % (iface, member, name)
+
+def event(member, path, interface):
+ iface = interface[interface.rfind(".") + 1:]
+ print "{%s} [%s] %s" % (iface, path, member)
+
+def message(msg, args, member, path, interface):
+ iface = interface[interface.rfind(".") + 1:]
+ print "{%s} [%s] %s %s (%s)" % (iface, path, member,
+ str(msg), pretty(args))
+
+def ussd(msg, member, path, interface):
+ iface = interface[interface.rfind(".") + 1:]
+ print "{%s} [%s] %s %s" % (iface, path, member, str(msg))
+
+def value(value, member, path, interface):
+ iface = interface[interface.rfind(".") + 1:]
+ print "{%s} [%s] %s %s" % (iface, path, member, str(value))
+
+if __name__ == '__main__':
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+ bus = dbus.SystemBus()
+
+ bus.add_signal_receiver(property_changed,
+ bus_name="org.ofono.dundee",
+ signal_name = "PropertyChanged",
+ path_keyword="path",
+ interface_keyword="interface")
+
+ bus.add_signal_receiver(added,
+ bus_name="org.ofono.dundee",
+ signal_name = "DeviceAdded",
+ member_keyword="member",
+ path_keyword="path",
+ interface_keyword="interface")
+
+ bus.add_signal_receiver(removed,
+ bus_name="org.ofono.dundee",
+ signal_name = "DeviceRemoved",
+ member_keyword="member",
+ path_keyword="path",
+ interface_keyword="interface")
+
+
+ mainloop = gobject.MainLoop()
+ mainloop.run()
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 04/16] dundee: Add skeleton implementation
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (2 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 03/16] dundee: Add test scripts Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 05/16] dundee: Add D-Bus error messages Daniel Wagner
` (12 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 9724 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
Makefile.am | 12 +++
bootstrap-configure | 1 +
configure.ac | 4 +
dundee/dundee.h | 46 ++++++++++
dundee/main.c | 255 +++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 318 insertions(+)
create mode 100644 dundee/dundee.h
create mode 100644 dundee/main.c
diff --git a/Makefile.am b/Makefile.am
index 869bd2b..9925435 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -683,6 +683,18 @@ tools_lookup_provider_name_SOURCES = plugins/mbpi.c plugins/mbpi.h \
tools_lookup_provider_name_LDADD = @GLIB_LIBS@
endif
+if DUNDEE
+
+sbin_PROGRAMS += dundee/dundee
+
+dundee_dundee_SOURCES = $(gdbus_sources) \
+ src/log.c src/dbus.c \
+ dundee/dundee.h dundee/main.c
+
+dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
+
+endif
+
noinst_PROGRAMS += gatchat/gsmdial gatchat/test-server gatchat/test-qcdm
gatchat_gsmdial_SOURCES = gatchat/gsmdial.c $(gatchat_sources)
diff --git a/bootstrap-configure b/bootstrap-configure
index db70c66..1fae158 100755
--- a/bootstrap-configure
+++ b/bootstrap-configure
@@ -14,4 +14,5 @@ fi
--localstatedir=/var \
--enable-capng \
--enable-tools \
+ --enable-dundee \
--disable-datafiles $*
diff --git a/configure.ac b/configure.ac
index 9f77a3c..0377298 100644
--- a/configure.ac
+++ b/configure.ac
@@ -152,6 +152,10 @@ if (test "${enable_tools}" = "yes"); then
fi
AM_CONDITIONAL(TOOLS, test "${enable_tools}" = "yes")
+AC_ARG_ENABLE(dundee, AC_HELP_STRING([--enable-dundee],
+ [enable DUN deamon support]), [enable_dundee=${enableval}])
+AM_CONDITIONAL(DUNDEE, test "${enable_dundee}" = "yes")
+
AC_ARG_ENABLE(atmodem, AC_HELP_STRING([--disable-atmodem],
[disable ETSI AT modem support]),
[enable_atmodem=${enableval}])
diff --git a/dundee/dundee.h b/dundee/dundee.h
new file mode 100644
index 0000000..c4c9800
--- /dev/null
+++ b/dundee/dundee.h
@@ -0,0 +1,46 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2008-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2012 BMW Car IT GmbH. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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
+ *
+ */
+
+#include <glib.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+
+#include <ofono/types.h>
+
+void __dundee_exit(void);
+
+#include <ofono/log.h>
+
+int __ofono_log_init(const char *program, const char *debug,
+ ofono_bool_t detach);
+void __ofono_log_cleanup(void);
+void __ofono_log_enable(struct ofono_debug_desc *start,
+ struct ofono_debug_desc *stop);
+
+#include <ofono/dbus.h>
+
+#define DUNDEE_SERVICE "org.ofono.dundee"
+
+int __ofono_dbus_init(DBusConnection *conn);
+void __ofono_dbus_cleanup(void);
+
+void __ofono_dbus_pending_reply(DBusMessage **msg, DBusMessage *reply);
diff --git a/dundee/main.c b/dundee/main.c
new file mode 100644
index 0000000..95ee795
--- /dev/null
+++ b/dundee/main.c
@@ -0,0 +1,255 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2008-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2012 BMW Car IT GmbH. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/signalfd.h>
+
+#include <gdbus.h>
+
+#ifdef HAVE_CAPNG
+#include <cap-ng.h>
+#endif
+
+#include "dundee.h"
+
+#define SHUTDOWN_GRACE_SECONDS 10
+
+static GMainLoop *event_loop;
+
+void __dundee_exit(void)
+{
+ g_main_loop_quit(event_loop);
+}
+
+static gboolean quit_eventloop(gpointer user_data)
+{
+ __dundee_exit();
+ return FALSE;
+}
+
+static unsigned int __terminated = 0;
+
+static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
+ gpointer user_data)
+{
+ struct signalfd_siginfo si;
+ ssize_t result;
+ int fd;
+
+ if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
+ return FALSE;
+
+ fd = g_io_channel_unix_get_fd(channel);
+
+ result = read(fd, &si, sizeof(si));
+ if (result != sizeof(si))
+ return FALSE;
+
+ switch (si.ssi_signo) {
+ case SIGINT:
+ case SIGTERM:
+ if (__terminated == 0) {
+ ofono_info("Terminating");
+ g_timeout_add_seconds(SHUTDOWN_GRACE_SECONDS,
+ quit_eventloop, NULL);
+
+ quit_eventloop(NULL);
+ }
+
+ __terminated = 1;
+ break;
+ }
+
+ return TRUE;
+}
+
+static guint setup_signalfd(void)
+{
+ GIOChannel *channel;
+ guint source;
+ sigset_t mask;
+ int fd;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGINT);
+ sigaddset(&mask, SIGTERM);
+
+ if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
+ perror("Failed to set signal mask");
+ return 0;
+ }
+
+ fd = signalfd(-1, &mask, 0);
+ if (fd < 0) {
+ perror("Failed to create signal descriptor");
+ return 0;
+ }
+
+ channel = g_io_channel_unix_new(fd);
+
+ g_io_channel_set_close_on_unref(channel, TRUE);
+ g_io_channel_set_encoding(channel, NULL, NULL);
+ g_io_channel_set_buffered(channel, FALSE);
+
+ source = g_io_add_watch(channel,
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ signal_handler, NULL);
+
+ g_io_channel_unref(channel);
+
+ return source;
+}
+
+static void system_bus_disconnected(DBusConnection *conn, void *user_data)
+{
+ ofono_error("System bus has disconnected!");
+
+ g_main_loop_quit(event_loop);
+}
+
+static gchar *option_debug = NULL;
+static gboolean option_detach = TRUE;
+static gboolean option_version = FALSE;
+
+static gboolean parse_debug(const char *key, const char *value,
+ gpointer user_data, GError **error)
+{
+ if (value)
+ option_debug = g_strdup(value);
+ else
+ option_debug = g_strdup("*");
+
+ return TRUE;
+}
+
+static GOptionEntry options[] = {
+ { "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
+ G_OPTION_ARG_CALLBACK, parse_debug,
+ "Specify debug options to enable", "DEBUG" },
+ { "nodetach", 'n', G_OPTION_FLAG_REVERSE,
+ G_OPTION_ARG_NONE, &option_detach,
+ "Don't run as daemon in background" },
+ { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
+ "Show version information and exit" },
+ { NULL },
+};
+
+int main(int argc, char **argv)
+{
+ GOptionContext *context;
+ GError *err = NULL;
+ DBusConnection *conn;
+ DBusError error;
+ guint signal;
+
+#ifdef HAVE_CAPNG
+ /* Drop capabilities */
+ capng_clear(CAPNG_SELECT_BOTH);
+ capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE | CAPNG_PERMITTED,
+ CAP_NET_BIND_SERVICE, CAP_NET_ADMIN,
+ CAP_NET_RAW, CAP_SYS_ADMIN, -1);
+ capng_apply(CAPNG_SELECT_BOTH);
+#endif
+
+ context = g_option_context_new(NULL);
+ g_option_context_add_main_entries(context, options, NULL);
+
+ if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) {
+ if (err != NULL) {
+ g_printerr("%s\n", err->message);
+ g_error_free(err);
+ return 1;
+ }
+
+ g_printerr("An unknown error occurred\n");
+ return 1;
+ }
+
+ g_option_context_free(context);
+
+ if (option_version == TRUE) {
+ printf("%s\n", VERSION);
+ exit(0);
+ }
+
+ if (option_detach == TRUE) {
+ if (daemon(0, 0)) {
+ perror("Can't start daemon");
+ return 1;
+ }
+ }
+
+ event_loop = g_main_loop_new(NULL, FALSE);
+
+ signal = setup_signalfd();
+
+ __ofono_log_init(argv[0], option_debug, option_detach);
+
+ dbus_error_init(&error);
+
+ conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, DUNDEE_SERVICE, &error);
+ if (conn == NULL) {
+ if (dbus_error_is_set(&error) == TRUE) {
+ ofono_error("Unable to hop onto D-Bus: %s",
+ error.message);
+ dbus_error_free(&error);
+ } else {
+ ofono_error("Unable to hop onto D-Bus");
+ }
+
+ goto cleanup;
+ }
+
+ g_dbus_set_disconnect_function(conn, system_bus_disconnected,
+ NULL, NULL);
+
+ __ofono_dbus_init(conn);
+
+ /*
+ * The reason why this DBG is here is that we have the __stop__debug,
+ * __start__debug linking symbols in the object. As soon we
+ * have real DBG we can remove this one again.
+ */
+ DBG("");
+
+ g_main_loop_run(event_loop);
+
+ __ofono_dbus_cleanup();
+ dbus_connection_unref(conn);
+
+cleanup:
+ g_source_remove(signal);
+
+ g_main_loop_unref(event_loop);
+
+ __ofono_log_cleanup();
+
+ return 0;
+}
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 05/16] dundee: Add D-Bus error messages
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (3 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 04/16] dundee: Add skeleton implementation Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 06/16] dundee: Add D-Bus configuration file Daniel Wagner
` (11 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2649 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
Makefile.am | 2 +-
dundee/dbus.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
dundee/dundee.h | 3 +++
3 files changed, 49 insertions(+), 1 deletion(-)
create mode 100644 dundee/dbus.c
diff --git a/Makefile.am b/Makefile.am
index 9925435..068e4e8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -689,7 +689,7 @@ sbin_PROGRAMS += dundee/dundee
dundee_dundee_SOURCES = $(gdbus_sources) \
src/log.c src/dbus.c \
- dundee/dundee.h dundee/main.c
+ dundee/dundee.h dundee/main.c dundee/dbus.c
dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
diff --git a/dundee/dbus.c b/dundee/dbus.c
new file mode 100644
index 0000000..c245eab
--- /dev/null
+++ b/dundee/dbus.c
@@ -0,0 +1,45 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2012 BMW Car IT GmbH. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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 <glib.h>
+#include <gdbus.h>
+
+#include "dundee.h"
+
+#define DUNDEE_ERROR_INTERFACE "org.ofono.dundee.Error"
+
+DBusMessage *__dundee_error_invalid_args(DBusMessage *msg)
+{
+ return g_dbus_create_error(msg, DUNDEE_ERROR_INTERFACE
+ ".InvalidArguments",
+ "Invalid arguments in method call");
+}
+
+DBusMessage *__dundee_error_failed(DBusMessage *msg)
+{
+ return g_dbus_create_error(msg, DUNDEE_ERROR_INTERFACE
+ ".Failed",
+ "Operation failed");
+}
diff --git a/dundee/dundee.h b/dundee/dundee.h
index c4c9800..c972af0 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -44,3 +44,6 @@ int __ofono_dbus_init(DBusConnection *conn);
void __ofono_dbus_cleanup(void);
void __ofono_dbus_pending_reply(DBusMessage **msg, DBusMessage *reply);
+
+DBusMessage *__dundee_error_invalid_args(DBusMessage *msg);
+DBusMessage *__dundee_error_failed(DBusMessage *msg);
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 06/16] dundee: Add D-Bus configuration file
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (4 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 05/16] dundee: Add D-Bus error messages Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 07/16] dundee: Add systemd " Daniel Wagner
` (10 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1549 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
Makefile.am | 6 ++++++
dundee/dundee.conf | 23 +++++++++++++++++++++++
2 files changed, 29 insertions(+)
create mode 100644 dundee/dundee.conf
diff --git a/Makefile.am b/Makefile.am
index 068e4e8..ee83faa 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -693,6 +693,12 @@ dundee_dundee_SOURCES = $(gdbus_sources) \
dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
+if DATAFILES
+
+dist_dbusconf_DATA += dundee/dundee.conf
+
+endif
+
endif
noinst_PROGRAMS += gatchat/gsmdial gatchat/test-server gatchat/test-qcdm
diff --git a/dundee/dundee.conf b/dundee/dundee.conf
new file mode 100644
index 0000000..de79dd5
--- /dev/null
+++ b/dundee/dundee.conf
@@ -0,0 +1,23 @@
+<!-- This configuration file specifies the required security policies
+ for oFono dundee (DUN) daemon to work. -->
+
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+
+ <!-- ../system.conf have denied everything, so we just punch some holes -->
+
+ <policy user="root">
+ <allow own="org.ofono.dundee"/>
+ <allow send_destination="org.ofono.dundee"/>
+ </policy>
+
+ <policy at_console="true">
+ <allow send_destination="org.ofono.dundee"/>
+ </policy>
+
+ <policy context="default">
+ <deny send_destination="org.ofono.dundee"/>
+ </policy>
+
+</busconfig>
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 07/16] dundee: Add systemd configuration file
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (5 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 06/16] dundee: Add D-Bus configuration file Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 08/16] dundee: Add Manager interface Daniel Wagner
` (9 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1359 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
Makefile.am | 6 ++++++
configure.ac | 3 ++-
dundee/dundee.service.in | 11 +++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
create mode 100644 dundee/dundee.service.in
diff --git a/Makefile.am b/Makefile.am
index ee83faa..31e0110 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -697,6 +697,12 @@ if DATAFILES
dist_dbusconf_DATA += dundee/dundee.conf
+if SYSTEMD
+
+systemdunit_DATA += dundee/dundee.service
+
+endif
+
endif
endif
diff --git a/configure.ac b/configure.ac
index 0377298..d2092b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -242,4 +242,5 @@ fi
AC_DEFINE_UNQUOTED(CONFIGDIR, "${configdir}",
[Directory for the configuration files])
-AC_OUTPUT(Makefile include/version.h src/ofono.service ofono.pc)
+AC_OUTPUT(Makefile include/version.h src/ofono.service ofono.pc \
+ dundee/dundee.service)
diff --git a/dundee/dundee.service.in b/dundee/dundee.service.in
new file mode 100644
index 0000000..c57c618
--- /dev/null
+++ b/dundee/dundee.service.in
@@ -0,0 +1,11 @@
+[Unit]
+Description=DUN service
+After=syslog.target
+
+[Service]
+Type=dbus
+BusName=org.ofono.dundee
+ExecStart=@prefix@/sbin/dundee -n
+
+[Install]
+WantedBy=multi-user.target
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 08/16] dundee: Add Manager interface
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (6 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 07/16] dundee: Add systemd " Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 09/16] dundee: Add skeleton implementation for device Daniel Wagner
` (8 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 5061 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
Makefile.am | 3 +-
dundee/dundee.h | 6 ++++
dundee/main.c | 9 ++---
dundee/manager.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 111 insertions(+), 7 deletions(-)
create mode 100644 dundee/manager.c
diff --git a/Makefile.am b/Makefile.am
index 31e0110..00e1118 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -689,7 +689,8 @@ sbin_PROGRAMS += dundee/dundee
dundee_dundee_SOURCES = $(gdbus_sources) \
src/log.c src/dbus.c \
- dundee/dundee.h dundee/main.c dundee/dbus.c
+ dundee/dundee.h dundee/main.c dundee/dbus.c \
+ dundee/manager.c
dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
diff --git a/dundee/dundee.h b/dundee/dundee.h
index c972af0..3050baf 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -39,6 +39,8 @@ void __ofono_log_enable(struct ofono_debug_desc *start,
#include <ofono/dbus.h>
#define DUNDEE_SERVICE "org.ofono.dundee"
+#define DUNDEE_MANAGER_INTERFACE "org.ofono.dundee.Manager"
+#define DUNDEE_MANAGER_PATH "/"
int __ofono_dbus_init(DBusConnection *conn);
void __ofono_dbus_cleanup(void);
@@ -47,3 +49,7 @@ void __ofono_dbus_pending_reply(DBusMessage **msg, DBusMessage *reply);
DBusMessage *__dundee_error_invalid_args(DBusMessage *msg);
DBusMessage *__dundee_error_failed(DBusMessage *msg);
+
+
+int __dundee_manager_init(void);
+void __dundee_manager_cleanup(void);
diff --git a/dundee/main.c b/dundee/main.c
index 95ee795..07b8501 100644
--- a/dundee/main.c
+++ b/dundee/main.c
@@ -232,15 +232,12 @@ int main(int argc, char **argv)
__ofono_dbus_init(conn);
- /*
- * The reason why this DBG is here is that we have the __stop__debug,
- * __start__debug linking symbols in the object. As soon we
- * have real DBG we can remove this one again.
- */
- DBG("");
+ __dundee_manager_init();
g_main_loop_run(event_loop);
+ __dundee_manager_cleanup();
+
__ofono_dbus_cleanup();
dbus_connection_unref(conn);
diff --git a/dundee/manager.c b/dundee/manager.c
new file mode 100644
index 0000000..61fa25e
--- /dev/null
+++ b/dundee/manager.c
@@ -0,0 +1,100 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2008-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2012 BMW Car IT GmbH. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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 <string.h>
+#include <glib.h>
+#include <gdbus.h>
+
+#include "dundee.h"
+
+static DBusMessage *manager_get_devices(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ DBusMessageIter iter;
+ DBusMessageIter array;
+
+ DBG("");
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+ DBUS_TYPE_OBJECT_PATH_AS_STRING
+ DBUS_TYPE_ARRAY_AS_STRING
+ DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+ DBUS_TYPE_STRING_AS_STRING
+ DBUS_TYPE_VARIANT_AS_STRING
+ DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+ DBUS_STRUCT_END_CHAR_AS_STRING,
+ &array);
+
+ dbus_message_iter_close_container(&iter, &array);
+
+ return reply;
+}
+
+static const GDBusMethodTable manager_methods[] = {
+ { GDBUS_METHOD("GetDevices", NULL,
+ GDBUS_ARGS({ "devices", "a(oa{sv})" }), manager_get_devices) },
+ { }
+};
+
+static const GDBusSignalTable manager_signals[] = {
+ { GDBUS_SIGNAL("DevicesAdded",
+ GDBUS_ARGS({ "path", "o"},{ "properties", "a{sv}" })) },
+ { GDBUS_SIGNAL("DeviceRemoved",
+ GDBUS_ARGS({ "path", "o"})) },
+ { }
+};
+
+int __dundee_manager_init(void)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ gboolean ret;
+
+ ret = g_dbus_register_interface(conn, DUNDEE_MANAGER_PATH,
+ DUNDEE_MANAGER_INTERFACE,
+ manager_methods, manager_signals,
+ NULL, NULL, NULL);
+
+ if (ret == FALSE)
+ return -1;
+
+ return 0;
+}
+
+void __dundee_manager_cleanup(void)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+
+ g_dbus_unregister_interface(conn, DUNDEE_MANAGER_PATH,
+ DUNDEE_MANAGER_INTERFACE);
+}
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 09/16] dundee: Add skeleton implementation for device
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (7 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 08/16] dundee: Add Manager interface Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 10/16] dundee: Manager append devices Daniel Wagner
` (7 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 4702 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
Makefile.am | 2 +-
dundee/device.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
dundee/dundee.h | 15 +++++++++
dundee/main.c | 4 ++-
4 files changed, 119 insertions(+), 2 deletions(-)
create mode 100644 dundee/device.c
diff --git a/Makefile.am b/Makefile.am
index 00e1118..1e0934d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -690,7 +690,7 @@ sbin_PROGRAMS += dundee/dundee
dundee_dundee_SOURCES = $(gdbus_sources) \
src/log.c src/dbus.c \
dundee/dundee.h dundee/main.c dundee/dbus.c \
- dundee/manager.c
+ dundee/manager.c dundee/device.c
dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
diff --git a/dundee/device.c b/dundee/device.c
new file mode 100644
index 0000000..d9fc928
--- /dev/null
+++ b/dundee/device.c
@@ -0,0 +1,100 @@
+/*
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2008-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2012 BMW Car IT GmbH. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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 <string.h>
+#include <stdio.h>
+#include <netinet/ether.h>
+
+#include <glib.h>
+#include <gdbus.h>
+
+#include "dundee.h"
+
+static GHashTable *device_hash;
+
+struct dundee_device {
+};
+
+const char *__dundee_device_get_path(struct dundee_device *device)
+{
+ return "/";
+}
+
+void __dundee_device_append_properties(struct dundee_device *device,
+ DBusMessageIter *dict)
+{
+}
+
+void __dundee_device_foreach(dundee_device_foreach_func func, void *userdata)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ DBG("");
+
+ g_hash_table_iter_init(&iter, device_hash);
+
+ while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ struct dundee_device *device = value;
+
+ func(device, userdata);
+ }
+}
+
+static void destroy_device(gpointer user)
+{
+ struct dundee_device *device = user;
+
+ g_free(device);
+}
+
+static void device_shutdown(gpointer key, gpointer value, gpointer user_data)
+{
+}
+
+void __dundee_device_shutdown(void)
+{
+ g_hash_table_foreach(device_hash, device_shutdown, NULL);
+
+ __dundee_exit();
+}
+
+int __dundee_device_init(void)
+{
+ DBG("");
+
+ device_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, destroy_device);
+
+ return 0;
+}
+
+void __dundee_device_cleanup(void)
+{
+ DBG("");
+
+ g_hash_table_destroy(device_hash);
+}
diff --git a/dundee/dundee.h b/dundee/dundee.h
index 3050baf..4f8aa10 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -53,3 +53,18 @@ DBusMessage *__dundee_error_failed(DBusMessage *msg);
int __dundee_manager_init(void);
void __dundee_manager_cleanup(void);
+
+
+struct dundee_device;
+
+int __dundee_device_init(void);
+void __dundee_device_cleanup(void);
+void __dundee_device_shutdown(void);
+
+typedef void (*dundee_device_foreach_func)(struct dundee_device *device,
+ void *data);
+void __dundee_device_foreach(dundee_device_foreach_func cb, void *userdata);
+
+const char *__dundee_device_get_path(struct dundee_device *device);
+void __dundee_device_append_properties(struct dundee_device *device,
+ DBusMessageIter *dict);
diff --git a/dundee/main.c b/dundee/main.c
index 07b8501..2d3d75e 100644
--- a/dundee/main.c
+++ b/dundee/main.c
@@ -80,7 +80,7 @@ static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
g_timeout_add_seconds(SHUTDOWN_GRACE_SECONDS,
quit_eventloop, NULL);
- quit_eventloop(NULL);
+ __dundee_device_shutdown();
}
__terminated = 1;
@@ -233,9 +233,11 @@ int main(int argc, char **argv)
__ofono_dbus_init(conn);
__dundee_manager_init();
+ __dundee_device_init();
g_main_loop_run(event_loop);
+ __dundee_device_cleanup();
__dundee_manager_cleanup();
__ofono_dbus_cleanup();
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 10/16] dundee: Manager append devices
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (8 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 09/16] dundee: Add skeleton implementation for device Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 11/16] dundee: Add callback helpers Daniel Wagner
` (6 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1375 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
dundee/manager.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/dundee/manager.c b/dundee/manager.c
index 61fa25e..d7374d6 100644
--- a/dundee/manager.c
+++ b/dundee/manager.c
@@ -30,6 +30,26 @@
#include "dundee.h"
+static void append_device(struct dundee_device *device, void *userdata)
+{
+ DBusMessageIter *array = userdata;
+ const char *path = __dundee_device_get_path(device);
+ DBusMessageIter entry, dict;
+
+ dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
+ NULL, &entry);
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
+ &path);
+ dbus_message_iter_open_container(&entry, DBUS_TYPE_ARRAY,
+ OFONO_PROPERTIES_ARRAY_SIGNATURE,
+ &dict);
+
+ __dundee_device_append_properties(device, &dict);
+
+ dbus_message_iter_close_container(&entry, &dict);
+ dbus_message_iter_close_container(array, &entry);
+}
+
static DBusMessage *manager_get_devices(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -56,6 +76,8 @@ static DBusMessage *manager_get_devices(DBusConnection *conn,
DBUS_STRUCT_END_CHAR_AS_STRING,
&array);
+ __dundee_device_foreach(append_device, &array);
+
dbus_message_iter_close_container(&iter, &array);
return reply;
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 11/16] dundee: Add callback helpers
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (9 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 10/16] dundee: Manager append devices Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 12/16] dundee: Add device un/register Daniel Wagner
` (5 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1337 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
dundee/dundee.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/dundee/dundee.h b/dundee/dundee.h
index 4f8aa10..366938e 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -28,6 +28,50 @@
void __dundee_exit(void);
+enum dundee_error_type {
+ DUNDEE_ERROR_TYPE_NO_ERROR = 0,
+ DUNDEE_ERROR_TYPE_FAILURE,
+};
+
+struct dundee_error {
+ enum dundee_error_type type;
+ int error;
+};
+
+struct cb_data {
+ void *cb;
+ void *data;
+ void *user;
+};
+
+static inline struct cb_data *cb_data_new(void *cb, void *data)
+{
+ struct cb_data *ret;
+
+ ret = g_new0(struct cb_data, 1);
+ ret->cb = cb;
+ ret->data = data;
+
+ return ret;
+}
+
+#define CALLBACK_WITH_FAILURE(cb, args...) \
+ do { \
+ struct dundee_error cb_e; \
+ cb_e.type = DUNDEE_ERROR_TYPE_FAILURE; \
+ cb_e.error = 0; \
+ \
+ cb(&cb_e, ##args); \
+ } while (0) \
+
+#define CALLBACK_WITH_SUCCESS(f, args...) \
+ do { \
+ struct dundee_error e; \
+ e.type = DUNDEE_ERROR_TYPE_NO_ERROR; \
+ e.error = 0; \
+ f(&e, ##args); \
+ } while(0) \
+
#include <ofono/log.h>
int __ofono_log_init(const char *program, const char *debug,
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 12/16] dundee: Add device un/register
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (10 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 11/16] dundee: Add callback helpers Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 13/16] dundee: Add driver helper functions Daniel Wagner
` (4 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 3529 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
dundee/device.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
dundee/dundee.h | 21 +++++++++++++++++
2 files changed, 89 insertions(+), 1 deletion(-)
diff --git a/dundee/device.c b/dundee/device.c
index d9fc928..9ed1687 100644
--- a/dundee/device.c
+++ b/dundee/device.c
@@ -33,14 +33,19 @@
#include "dundee.h"
+static int next_device_id = 0;
static GHashTable *device_hash;
struct dundee_device {
+ char *path;
+ struct dundee_device_driver *driver;
+ gboolean registered;
+
};
const char *__dundee_device_get_path(struct dundee_device *device)
{
- return "/";
+ return device->path;
}
void __dundee_device_append_properties(struct dundee_device *device,
@@ -64,15 +69,77 @@ void __dundee_device_foreach(dundee_device_foreach_func func, void *userdata)
}
}
+static int register_device(struct dundee_device *device)
+{
+ return 0;
+}
+
+static int unregister_device(struct dundee_device *device)
+{
+ return 0;
+}
+
static void destroy_device(gpointer user)
{
struct dundee_device *device = user;
+ g_free(device->path);
+
g_free(device);
}
+struct dundee_device *dundee_device_create(struct dundee_device_driver *d)
+{
+ struct dundee_device *device;
+
+ device = g_try_new0(struct dundee_device, 1);
+ if (device == NULL)
+ return NULL;
+
+ device->driver = d;
+
+ device->path = g_strdup_printf("/device%d", next_device_id);
+ if (device->path == NULL) {
+ g_free(device);
+ return NULL;
+ }
+
+ next_device_id += 1;
+
+ return device;
+}
+
+int dundee_device_register(struct dundee_device *device)
+{
+ int err;
+
+ err = register_device(device);
+ if (err < 0)
+ return err;
+
+ device->registered = TRUE;
+
+ g_hash_table_insert(device_hash, g_strdup(device->path), device);
+
+ return 0;
+}
+
+void dundee_device_unregister(struct dundee_device *device)
+{
+ DBG("%p", device);
+
+ unregister_device(device);
+
+ device->registered = FALSE;
+
+ g_hash_table_remove(device_hash, device->path);
+}
+
static void device_shutdown(gpointer key, gpointer value, gpointer user_data)
{
+ struct dundee_device *device = value;
+
+ unregister_device(device);
}
void __dundee_device_shutdown(void)
diff --git a/dundee/dundee.h b/dundee/dundee.h
index 366938e..ae14e01 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -105,6 +105,27 @@ int __dundee_device_init(void);
void __dundee_device_cleanup(void);
void __dundee_device_shutdown(void);
+typedef void (*dundee_device_connect_cb_t)(const struct dundee_error *error,
+ int fd, void *data);
+typedef void (*dundee_device_disconnect_cb_t)(const struct dundee_error *error,
+ void *data);
+
+struct dundee_device_driver {
+ const char *name;
+
+ /* Connect and dial */
+ void (*connect)(struct dundee_device *device,
+ dundee_device_connect_cb_t cb, void *data);
+
+ /* Hangup and disconnect */
+ void (*disconnect)(struct dundee_device *device,
+ dundee_device_disconnect_cb_t cb, void *data);
+};
+
+struct dundee_device *dundee_device_create(struct dundee_device_driver *d);
+int dundee_device_register(struct dundee_device *device);
+void dundee_device_unregister(struct dundee_device *device);
+
typedef void (*dundee_device_foreach_func)(struct dundee_device *device,
void *data);
void __dundee_device_foreach(dundee_device_foreach_func cb, void *userdata);
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 13/16] dundee: Add driver helper functions
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (11 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 12/16] dundee: Add device un/register Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 14/16] dundee: Add device D-Bus interface Daniel Wagner
` (3 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1873 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
dundee/device.c | 18 ++++++++++++++++++
dundee/dundee.h | 5 +++++
2 files changed, 23 insertions(+)
diff --git a/dundee/device.c b/dundee/device.c
index 9ed1687..1a83f76 100644
--- a/dundee/device.c
+++ b/dundee/device.c
@@ -41,6 +41,7 @@ struct dundee_device {
struct dundee_device_driver *driver;
gboolean registered;
+ void *data;
};
const char *__dundee_device_get_path(struct dundee_device *device)
@@ -135,6 +136,23 @@ void dundee_device_unregister(struct dundee_device *device)
g_hash_table_remove(device_hash, device->path);
}
+void dundee_device_set_data(struct dundee_device *device, void *data)
+{
+ device->data = data;
+}
+
+void *dundee_device_get_data(struct dundee_device *device)
+{
+ return device->data;
+}
+
+int dundee_device_set_name(struct dundee_device *device, const char *name)
+{
+ DBG("%p name %s", device, name);
+
+ return 0;
+}
+
static void device_shutdown(gpointer key, gpointer value, gpointer user_data)
{
struct dundee_device *device = value;
diff --git a/dundee/dundee.h b/dundee/dundee.h
index ae14e01..cf0c36a 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -126,6 +126,11 @@ struct dundee_device *dundee_device_create(struct dundee_device_driver *d);
int dundee_device_register(struct dundee_device *device);
void dundee_device_unregister(struct dundee_device *device);
+void dundee_device_set_data(struct dundee_device *device, void *data);
+void *dundee_device_get_data(struct dundee_device *device);
+
+int dundee_device_set_name(struct dundee_device *device, const char *name);
+
typedef void (*dundee_device_foreach_func)(struct dundee_device *device,
void *data);
void __dundee_device_foreach(dundee_device_foreach_func cb, void *userdata);
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 14/16] dundee: Add device D-Bus interface
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (12 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 13/16] dundee: Add driver helper functions Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 15/16] dundee: Add PPP handling code to device Daniel Wagner
` (2 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 8229 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
dundee/device.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
dundee/dundee.h | 1 +
2 files changed, 226 insertions(+)
diff --git a/dundee/device.c b/dundee/device.c
index 1a83f76..8baf760 100644
--- a/dundee/device.c
+++ b/dundee/device.c
@@ -36,11 +36,21 @@
static int next_device_id = 0;
static GHashTable *device_hash;
+struct ipv4_settings {
+ char *interface;
+ char *ip;
+ char **nameservers;
+};
+
struct dundee_device {
char *path;
struct dundee_device_driver *driver;
gboolean registered;
+ char *name;
+ gboolean active;
+ struct ipv4_settings settings;
+
void *data;
};
@@ -49,9 +59,75 @@ const char *__dundee_device_get_path(struct dundee_device *device)
return device->path;
}
+static void settings_append(struct dundee_device *device,
+ DBusMessageIter *iter)
+{
+ DBusMessageIter variant;
+ DBusMessageIter array;
+ char typesig[5];
+ char arraysig[6];
+
+ arraysig[0] = DBUS_TYPE_ARRAY;
+ arraysig[1] = typesig[0] = DBUS_DICT_ENTRY_BEGIN_CHAR;
+ arraysig[2] = typesig[1] = DBUS_TYPE_STRING;
+ arraysig[3] = typesig[2] = DBUS_TYPE_VARIANT;
+ arraysig[4] = typesig[3] = DBUS_DICT_ENTRY_END_CHAR;
+ arraysig[5] = typesig[4] = '\0';
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+ arraysig, &variant);
+
+ dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
+ typesig, &array);
+
+ if (device->active == FALSE)
+ goto out;
+
+ if (device->settings.interface)
+ ofono_dbus_dict_append(&array, "Interface",
+ DBUS_TYPE_STRING, &device->settings.interface);
+
+ if (device->settings.ip)
+ ofono_dbus_dict_append(&array, "Address", DBUS_TYPE_STRING,
+ &device->settings.ip);
+
+ if (device->settings.nameservers)
+ ofono_dbus_dict_append_array(&array, "DomainNameServers",
+ DBUS_TYPE_STRING,
+ &device->settings.nameservers);
+
+out:
+ dbus_message_iter_close_container(&variant, &array);
+
+ dbus_message_iter_close_container(iter, &variant);
+}
+
+static void settings_append_dict(struct dundee_device *device,
+ DBusMessageIter *dict)
+{
+ DBusMessageIter entry;
+ const char *key = "Settings";
+
+ dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+ NULL, &entry);
+
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+ settings_append(device, &entry);
+
+ dbus_message_iter_close_container(dict, &entry);
+}
+
void __dundee_device_append_properties(struct dundee_device *device,
DBusMessageIter *dict)
{
+ settings_append_dict(device, dict);
+
+ ofono_dbus_dict_append(dict, "Name", DBUS_TYPE_STRING,
+ &device->name);
+
+ ofono_dbus_dict_append(dict, "Active", DBUS_TYPE_BOOLEAN,
+ &device->active);
}
void __dundee_device_foreach(dundee_device_foreach_func func, void *userdata)
@@ -70,13 +146,145 @@ void __dundee_device_foreach(dundee_device_foreach_func func, void *userdata)
}
}
+static DBusMessage *device_get_properties(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct dundee_device *device = data;
+ DBusMessage *reply;
+ DBusMessageIter iter;
+ DBusMessageIter dict;
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ OFONO_PROPERTIES_ARRAY_SIGNATURE,
+ &dict);
+
+ __dundee_device_append_properties(device, &dict);
+
+ dbus_message_iter_close_container(&iter, &dict);
+
+ return reply;
+}
+
+static DBusMessage *set_property_active(struct dundee_device *device,
+ DBusMessage *msg,
+ DBusMessageIter *var)
+{
+ ofono_bool_t active;
+
+ DBG("%p path %s", device, device->path);
+
+ if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_BOOLEAN)
+ return __dundee_error_invalid_args(msg);
+
+ dbus_message_iter_get_basic(var, &active);
+
+ device->active = active;
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *device_set_property(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct dundee_device *device = data;
+ DBusMessageIter iter, var;
+ const char *name;
+
+ if (dbus_message_iter_init(msg, &iter) == FALSE)
+ return __dundee_error_invalid_args(msg);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return __dundee_error_invalid_args(msg);
+
+ dbus_message_iter_get_basic(&iter, &name);
+ dbus_message_iter_next(&iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+ return __dundee_error_invalid_args(msg);
+
+ dbus_message_iter_recurse(&iter, &var);
+
+ if (g_str_equal(name, "Active"))
+ return set_property_active(device, msg, &var);
+
+ return __dundee_error_invalid_args(msg);
+}
+
+static const GDBusMethodTable device_methods[] = {
+ { GDBUS_METHOD("GetProperties",
+ NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+ device_get_properties) },
+ { GDBUS_ASYNC_METHOD("SetProperty",
+ GDBUS_ARGS({ "property", "s" }, { "value", "v" }),
+ NULL, device_set_property) },
+ { }
+};
+
+static const GDBusSignalTable device_signals[] = {
+ { GDBUS_SIGNAL("PropertyChanged",
+ GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+ { }
+};
+
static int register_device(struct dundee_device *device)
{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ DBusMessage *signal;
+ DBusMessageIter iter;
+ DBusMessageIter dict;
+
+ DBG("%p path %s", device, device->path);
+
+ if (!g_dbus_register_interface(conn, device->path,
+ DUNDEE_DEVICE_INTERFACE,
+ device_methods, device_signals,
+ NULL, device, NULL)) {
+ ofono_error("Could not register Device %s", device->path);
+ return -EIO;
+ }
+
+ signal = dbus_message_new_signal(DUNDEE_MANAGER_PATH,
+ DUNDEE_MANAGER_INTERFACE,
+ "DeviceAdded");
+
+ if (signal == NULL)
+ return -ENOMEM;
+
+ dbus_message_iter_init_append(signal, &iter);
+
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+ &device->path);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ OFONO_PROPERTIES_ARRAY_SIGNATURE,
+ &dict);
+ __dundee_device_append_properties(device, &dict);
+ dbus_message_iter_close_container(&iter, &dict);
+
+ g_dbus_send_message(conn, signal);
+
return 0;
}
static int unregister_device(struct dundee_device *device)
{
+ DBusConnection *conn = ofono_dbus_get_connection();
+
+ DBG("%p path %s", device, device->path);
+
+ g_dbus_unregister_interface(conn, device->path,
+ DUNDEE_DEVICE_INTERFACE);
+
+ g_dbus_emit_signal(conn, DUNDEE_MANAGER_PATH,
+ DUNDEE_MANAGER_INTERFACE, "DeviceRemoved",
+ DBUS_TYPE_OBJECT_PATH, &device->path,
+ DBUS_TYPE_INVALID);
+
return 0;
}
@@ -84,7 +292,12 @@ static void destroy_device(gpointer user)
{
struct dundee_device *device = user;
+ g_free(device->settings.interface);
+ g_free(device->settings.ip);
+ g_strfreev(device->settings.nameservers);
+
g_free(device->path);
+ g_free(device->name);
g_free(device);
}
@@ -148,8 +361,20 @@ void *dundee_device_get_data(struct dundee_device *device)
int dundee_device_set_name(struct dundee_device *device, const char *name)
{
+ DBusConnection *conn = ofono_dbus_get_connection();
+
DBG("%p name %s", device, name);
+ g_free(device->name);
+ device->name = g_strdup(name);
+
+ if (device->registered == FALSE)
+ return 0;
+
+ ofono_dbus_signal_property_changed(conn, device->path,
+ DUNDEE_DEVICE_INTERFACE, "Name",
+ DBUS_TYPE_STRING, &device->name);
+
return 0;
}
diff --git a/dundee/dundee.h b/dundee/dundee.h
index cf0c36a..7104531 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -84,6 +84,7 @@ void __ofono_log_enable(struct ofono_debug_desc *start,
#define DUNDEE_SERVICE "org.ofono.dundee"
#define DUNDEE_MANAGER_INTERFACE "org.ofono.dundee.Manager"
+#define DUNDEE_DEVICE_INTERFACE "org.ofono.dundee.Device"
#define DUNDEE_MANAGER_PATH "/"
int __ofono_dbus_init(DBusConnection *conn);
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 15/16] dundee: Add PPP handling code to device
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (13 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 14/16] dundee: Add device D-Bus interface Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 16:33 ` [PATCH v7 16/16] dundee: Add Bluetooth DUN driver Daniel Wagner
2012-05-22 19:10 ` [PATCH v7 00/16] Add DUN support Daniel Wagner
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 8606 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
Makefile.am | 2 +-
dundee/device.c | 254 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 253 insertions(+), 3 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 1e0934d..19261ce 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -687,7 +687,7 @@ if DUNDEE
sbin_PROGRAMS += dundee/dundee
-dundee_dundee_SOURCES = $(gdbus_sources) \
+dundee_dundee_SOURCES = $(gdbus_sources) $(gatchat_sources) \
src/log.c src/dbus.c \
dundee/dundee.h dundee/main.c dundee/dbus.c \
dundee/manager.c dundee/device.c
diff --git a/dundee/device.c b/dundee/device.c
index 8baf760..709919a 100644
--- a/dundee/device.c
+++ b/dundee/device.c
@@ -30,12 +30,16 @@
#include <glib.h>
#include <gdbus.h>
+#include <gatchat.h>
+#include <gatppp.h>
#include "dundee.h"
static int next_device_id = 0;
static GHashTable *device_hash;
+static const char *none_prefix[] = { NULL };
+
struct ipv4_settings {
char *interface;
char *ip;
@@ -47,10 +51,14 @@ struct dundee_device {
struct dundee_device_driver *driver;
gboolean registered;
+ GAtPPP *ppp;
+ GAtChat *chat;
+
char *name;
gboolean active;
struct ipv4_settings settings;
+ DBusMessage *pending;
void *data;
};
@@ -146,6 +154,27 @@ void __dundee_device_foreach(dundee_device_foreach_func func, void *userdata)
}
}
+static void settings_changed(struct dundee_device *device)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ DBusMessage *signal;
+ DBusMessageIter iter;
+ const char *key = "Settings";
+
+ signal = dbus_message_new_signal(device->path,
+ DUNDEE_DEVICE_INTERFACE,
+ "PropertyChanged");
+
+ if (signal == NULL)
+ return;
+ dbus_message_iter_init_append(signal, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
+
+ settings_append(device, &iter);
+
+ g_dbus_send_message(conn, signal);
+}
+
static DBusMessage *device_get_properties(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -171,6 +200,213 @@ static DBusMessage *device_get_properties(DBusConnection *conn,
return reply;
}
+
+static void debug(const char *str, void *data)
+{
+ DBG("%s: %s\n", (const char *) data, str);
+}
+
+static void ppp_connect(const char *iface, const char *local, const char *peer,
+ const char *dns1, const char *dns2,
+ gpointer user_data)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ struct dundee_device *device = user_data;
+ const char *dns[3] = { dns1, dns2, 0 };
+
+ DBG("%p", device);
+ DBG("Network Device: %s\n", iface);
+ DBG("IP Address: %s\n", local);
+ DBG("Peer IP Address: %s\n", peer);
+ DBG("Primary DNS Server: %s\n", dns1);
+ DBG("Secondary DNS Server: %s\n", dns2);
+
+ g_free(device->settings.interface);
+ device->settings.interface = g_strdup(iface);
+ if (device->settings.interface == NULL)
+ goto err;
+
+ g_free(device->settings.ip);
+ device->settings.ip = g_strdup(local);
+ if (device->settings.ip == NULL)
+ goto err;
+
+ g_strfreev(device->settings.nameservers);
+ device->settings.nameservers = g_strdupv((gchar **)dns);
+ if (device->settings.nameservers == NULL)
+ goto err;
+
+ __ofono_dbus_pending_reply(&device->pending,
+ dbus_message_new_method_return(device->pending));
+ device->pending = NULL;
+
+ device->active = TRUE;
+
+ settings_changed(device);
+ ofono_dbus_signal_property_changed(conn, device->path,
+ DUNDEE_DEVICE_INTERFACE, "Active",
+ DBUS_TYPE_BOOLEAN, &device->active);
+
+ return;
+
+err:
+ g_free(device->settings.interface);
+ g_free(device->settings.ip);
+ g_strfreev(device->settings.nameservers);
+ device->settings.interface = NULL;
+ device->settings.ip = NULL;
+ device->settings.nameservers = NULL;
+
+ __ofono_dbus_pending_reply(&device->pending,
+ __dundee_error_failed(device->pending));
+ device->pending = NULL;
+}
+
+static void disconnect_callback(const struct dundee_error *error, void *data)
+{
+ struct dundee_device *device = data;
+
+ DBG("%p", device);
+
+ g_at_chat_unref(device->chat);
+ device->chat = NULL;
+
+ if (device->pending == NULL)
+ return;
+
+ if (error->type != DUNDEE_ERROR_TYPE_NO_ERROR) {
+ __ofono_dbus_pending_reply(&device->pending,
+ __dundee_error_failed(device->pending));
+ goto out;
+ }
+
+ __ofono_dbus_pending_reply(&device->pending,
+ dbus_message_new_method_return(device->pending));
+
+out:
+ device->pending = NULL;
+}
+
+static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ struct dundee_device *device = user_data;
+
+ DBG("%p", device);
+ DBG("PPP Link down: %d\n", reason);
+
+ g_at_ppp_unref(device->ppp);
+ device->ppp = NULL;
+
+ g_at_chat_resume(device->chat);
+
+ g_free(device->settings.interface);
+ g_free(device->settings.ip);
+ g_strfreev(device->settings.nameservers);
+ device->settings.interface = NULL;
+ device->settings.ip = NULL;
+ device->settings.nameservers = NULL;
+
+ device->active = FALSE;
+
+ settings_changed(device);
+ ofono_dbus_signal_property_changed(conn, device->path,
+ DUNDEE_DEVICE_INTERFACE, "Active",
+ DBUS_TYPE_BOOLEAN, &device->active);
+
+ device->driver->disconnect(device, disconnect_callback, device);
+}
+
+static void dial_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ struct dundee_device *device = user_data;
+ GAtIO *io;
+
+ if (!ok) {
+ DBG("Unable to define context\n");
+ goto err;
+ }
+
+ /* get the data IO channel */
+ io = g_at_chat_get_io(device->chat);
+
+ /*
+ * shutdown gatchat or else it tries to take all the input
+ * from the modem and does not let PPP get it.
+ */
+ g_at_chat_suspend(device->chat);
+
+ /* open ppp */
+ device->ppp = g_at_ppp_new();
+ if (device->ppp == NULL) {
+ DBG("Unable to create PPP object\n");
+ goto err;
+ }
+ g_at_ppp_set_debug(device->ppp, debug, "PPP");
+
+ /* set connect and disconnect callbacks */
+ g_at_ppp_set_connect_function(device->ppp, ppp_connect, device);
+ g_at_ppp_set_disconnect_function(device->ppp, ppp_disconnect, device);
+
+ /* open the ppp connection */
+ g_at_ppp_open(device->ppp, io);
+
+ return;
+
+err:
+ __ofono_dbus_pending_reply(&device->pending,
+ __dundee_error_failed(device->pending));
+ device->pending = NULL;
+}
+
+static int device_dial_setup(struct dundee_device *device, int fd)
+{
+ GAtSyntax *syntax;
+ GIOChannel *io;
+
+ io = g_io_channel_unix_new(fd);
+ if (io == NULL)
+ return -EIO;
+
+ syntax = g_at_syntax_new_gsm_permissive();
+ device->chat = g_at_chat_new(io, syntax);
+ g_io_channel_unref(io);
+ g_at_syntax_unref(syntax);
+
+ if (device->chat == NULL)
+ return -EIO;
+
+ g_at_chat_set_debug(device->chat, debug, "Control");
+
+ g_at_chat_send(device->chat, "ATD*99#", none_prefix, dial_cb,
+ device, NULL);
+
+ return 0;
+}
+
+static void connect_callback(const struct dundee_error *error,
+ int fd, void *data)
+{
+ struct dundee_device *device = data;
+ int err;
+
+ DBG("%p", device);
+
+ if (error->type != DUNDEE_ERROR_TYPE_NO_ERROR)
+ goto err;
+
+ err = device_dial_setup(device, fd);
+ if (err < 0)
+ goto err;
+
+ return;
+
+err:
+ __ofono_dbus_pending_reply(&device->pending,
+ __dundee_error_failed(device->pending));
+ device->pending = NULL;
+}
+
static DBusMessage *set_property_active(struct dundee_device *device,
DBusMessage *msg,
DBusMessageIter *var)
@@ -184,9 +420,14 @@ static DBusMessage *set_property_active(struct dundee_device *device,
dbus_message_iter_get_basic(var, &active);
- device->active = active;
+ device->pending = dbus_message_ref(msg);
+
+ if (active)
+ device->driver->connect(device, connect_callback, device);
+ else if (device->ppp)
+ g_at_ppp_shutdown(device->ppp);
- return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+ return NULL;
}
static DBusMessage *device_set_property(DBusConnection *conn,
@@ -292,6 +533,15 @@ static void destroy_device(gpointer user)
{
struct dundee_device *device = user;
+ if (device->chat != NULL)
+ g_at_chat_unref(device->chat);
+
+ if (device->ppp != NULL)
+ g_at_ppp_unref(device->ppp);
+
+ if (device->pending)
+ dbus_message_unref(device->pending);
+
g_free(device->settings.interface);
g_free(device->settings.ip);
g_strfreev(device->settings.nameservers);
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v7 16/16] dundee: Add Bluetooth DUN driver
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (14 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 15/16] dundee: Add PPP handling code to device Daniel Wagner
@ 2012-05-22 16:33 ` Daniel Wagner
2012-05-22 19:10 ` [PATCH v7 00/16] Add DUN support Daniel Wagner
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 16:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 8510 bytes --]
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
Makefile.am | 6 +-
dundee/bluetooth.c | 290 ++++++++++++++++++++++++++++++++++++++++++++++++++++
dundee/dundee.h | 3 +
dundee/main.c | 2 +
4 files changed, 298 insertions(+), 3 deletions(-)
create mode 100644 dundee/bluetooth.c
diff --git a/Makefile.am b/Makefile.am
index 19261ce..19844d9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -687,10 +687,10 @@ if DUNDEE
sbin_PROGRAMS += dundee/dundee
-dundee_dundee_SOURCES = $(gdbus_sources) $(gatchat_sources) \
- src/log.c src/dbus.c \
+dundee_dundee_SOURCES = $(gdbus_sources) $(gatchat_sources) $(btio_sources) \
+ src/log.c src/dbus.c plugins/bluetooth.c \
dundee/dundee.h dundee/main.c dundee/dbus.c \
- dundee/manager.c dundee/device.c
+ dundee/manager.c dundee/device.c dundee/bluetooth.c
dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
diff --git a/dundee/bluetooth.c b/dundee/bluetooth.c
new file mode 100644
index 0000000..e2e2bca
--- /dev/null
+++ b/dundee/bluetooth.c
@@ -0,0 +1,290 @@
+/*
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2008-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2012 BMW Car IT GmbH. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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 <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include "plugins/bluetooth.h"
+
+#include "dundee.h"
+
+static GHashTable *bluetooth_hash;
+
+struct bluetooth_device {
+ struct dundee_device *device;
+
+ char *path;
+ char *address;
+ char *name;
+
+ DBusPendingCall *call;
+};
+
+static void bt_disconnect(struct dundee_device *device,
+ dundee_device_disconnect_cb_t cb, void *data)
+{
+ struct bluetooth_device *bt = dundee_device_get_data(device);
+
+ DBG("%p", bt);
+
+ CALLBACK_WITH_SUCCESS(cb, data);
+}
+
+static void bt_connect_reply(DBusPendingCall *call, gpointer user_data)
+{
+ struct cb_data *cbd = user_data;
+ dundee_device_connect_cb_t cb = cbd->cb;
+ struct bluetooth_device *bt = cbd->user;
+ DBusMessage *reply;
+ DBusError derr;
+ int fd;
+
+ DBG("%p", bt);
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ bt->call = NULL;
+
+ dbus_error_init(&derr);
+ if (dbus_set_error_from_message(&derr, reply)) {
+ DBG("Connection to bt serial returned with error: %s, %s",
+ derr.name, derr.message);
+
+ dbus_error_free(&derr);
+
+ CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+ goto done;
+ }
+
+ dbus_message_get_args(reply, NULL, DBUS_TYPE_UNIX_FD, &fd,
+ DBUS_TYPE_INVALID);
+
+ DBG("%p fd %d", bt, fd);
+
+ if (fd < 0) {
+ CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+ goto done;
+ }
+
+ CALLBACK_WITH_SUCCESS(cb, fd, cbd->data);
+
+done:
+ dbus_message_unref(reply);
+ g_free(cbd);
+}
+
+static void bt_connect(struct dundee_device *device,
+ dundee_device_connect_cb_t cb, void *data)
+{
+ struct bluetooth_device *bt = dundee_device_get_data(device);
+ struct cb_data *cbd = cb_data_new(cb, data);
+ char *profile = "dun";
+ int status;
+
+ DBG("%p", bt);
+
+ cbd->user = bt;
+
+ status = bluetooth_send_with_reply(bt->path,
+ BLUEZ_SERIAL_INTERFACE, "ConnectFD",
+ &bt->call, bt_connect_reply,
+ cbd, NULL, DBUS_TIMEOUT,
+ DBUS_TYPE_STRING, &profile,
+ DBUS_TYPE_INVALID);
+ if (status == 0)
+ return;
+
+ g_free(cbd);
+
+ CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+}
+
+struct dundee_device_driver bluetooth_driver = {
+ .name = "bluetooth",
+ .connect = bt_connect,
+ .disconnect = bt_disconnect,
+};
+
+static int bt_probe(const char *path, const char *dev_addr,
+ const char *adapter_addr, const char *alias)
+{
+ struct bluetooth_device *bt;
+ struct dundee_device *device;
+ char buf[256];
+
+ DBG("");
+
+ /* We already have this device in our hash, ignore */
+ if (g_hash_table_lookup(bluetooth_hash, path) != NULL)
+ return -EALREADY;
+
+ ofono_info("Using device: %s, devaddr: %s, adapter: %s",
+ path, dev_addr, adapter_addr);
+
+ strcpy(buf, "dun/");
+ bluetooth_create_path(dev_addr, adapter_addr, buf + 4, sizeof(buf) - 4);
+
+ bt = g_try_new0(struct bluetooth_device, 1);
+ if (bt == NULL)
+ return -ENOMEM;
+
+ DBG("%p", bt);
+
+ device = dundee_device_create(&bluetooth_driver);
+ if (device == NULL)
+ goto free;
+
+ dundee_device_set_data(device, bt);
+
+ bt->path = g_strdup(path);
+ if (bt->path == NULL)
+ goto free;
+
+ bt->address = g_strdup(dev_addr);
+ if (bt->address == NULL)
+ goto free;
+
+ bt->name = g_strdup(alias);
+ if (bt->name == NULL)
+ goto free;
+
+ dundee_device_set_name(device, bt->name);
+
+ if (dundee_device_register(device) < 0) {
+ g_free(device);
+ goto free;
+ }
+
+ bt->device = device;
+ g_hash_table_insert(bluetooth_hash, g_strdup(path), bt);
+
+ return 0;
+
+free:
+ g_free(bt->path);
+ g_free(bt->address);
+ g_free(bt->name);
+ g_free(bt);
+
+ return -ENOMEM;
+}
+
+static void destroy_device(gpointer user)
+{
+ struct bluetooth_device *bt = user;
+
+ DBG("%p", bt);
+
+ if (bt->call != NULL)
+ dbus_pending_call_cancel(bt->call);
+
+ g_free(bt->path);
+ g_free(bt->address);
+
+ g_free(bt);
+}
+
+static gboolean bt_remove_device(gpointer key, gpointer value,
+ gpointer user_data)
+{
+ struct bluetooth_device *bt = value;
+ const char *path = key;
+ const char *prefix = user_data;
+
+ DBG("%p", bt);
+
+ if (prefix && g_str_has_prefix(path, prefix) == FALSE)
+ return FALSE;
+
+ dundee_device_unregister(bt->device);
+
+ return TRUE;
+}
+
+static void bt_remove(const char *prefix)
+{
+ DBG("%s", prefix);
+
+ if (bluetooth_hash == NULL)
+ return;
+
+ g_hash_table_foreach_remove(bluetooth_hash, bt_remove_device,
+ (gpointer) prefix);
+}
+
+static void bt_set_alias(const char *path, const char *alias)
+{
+ struct bluetooth_device *bt;
+
+ DBG("");
+
+ if (path == NULL || alias == NULL)
+ return;
+
+ bt = g_hash_table_lookup(bluetooth_hash, path);
+ if (bt == NULL)
+ return;
+
+ g_free(bt->name);
+ bt->name = g_strdup(alias);
+
+ dundee_device_set_name(bt->device, bt->name);
+}
+
+static struct bluetooth_profile dun_profile = {
+ .name = "dun_dt",
+ .probe = bt_probe,
+ .remove = bt_remove,
+ .set_alias = bt_set_alias,
+};
+
+int __dundee_bluetooth_init(void)
+{
+ int err;
+
+ DBG("");
+
+ err = bluetooth_register_uuid(DUN_GW_UUID, &dun_profile);
+ if (err < 0)
+ return err;
+
+ bluetooth_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, destroy_device);
+
+ return 0;
+}
+
+void __dundee_bluetooth_cleanup(void)
+{
+ DBG("");
+
+ bluetooth_unregister_uuid(DUN_GW_UUID);
+ g_hash_table_destroy(bluetooth_hash);
+}
diff --git a/dundee/dundee.h b/dundee/dundee.h
index 7104531..8866007 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -139,3 +139,6 @@ void __dundee_device_foreach(dundee_device_foreach_func cb, void *userdata);
const char *__dundee_device_get_path(struct dundee_device *device);
void __dundee_device_append_properties(struct dundee_device *device,
DBusMessageIter *dict);
+
+int __dundee_bluetooth_init(void);
+void __dundee_bluetooth_cleanup(void);
diff --git a/dundee/main.c b/dundee/main.c
index 2d3d75e..5e2da80 100644
--- a/dundee/main.c
+++ b/dundee/main.c
@@ -234,9 +234,11 @@ int main(int argc, char **argv)
__dundee_manager_init();
__dundee_device_init();
+ __dundee_bluetooth_init();
g_main_loop_run(event_loop);
+ __dundee_bluetooth_cleanup();
__dundee_device_cleanup();
__dundee_manager_cleanup();
--
1.7.10.130.g36e6c
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v7 00/16] Add DUN support
2012-05-22 16:33 [PATCH v7 00/16] Add DUN support Daniel Wagner
` (15 preceding siblings ...)
2012-05-22 16:33 ` [PATCH v7 16/16] dundee: Add Bluetooth DUN driver Daniel Wagner
@ 2012-05-22 19:10 ` Daniel Wagner
16 siblings, 0 replies; 18+ messages in thread
From: Daniel Wagner @ 2012-05-22 19:10 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 421 bytes --]
On 05/22/2012 06:33 PM, Daniel Wagner wrote:
> From: Daniel Wagner <daniel.wagner@bmw-carit.de>
>
> Hi,
>
> Changes v7:
> - Fixed test scripts
> - SetProperty("Active", True) will be deferred until PPP link is up
> or an error happens
> - GDBUS changes added
> - Fixed a crash in set_property_active: device->ppp can be NULL
> - Copyright year update and whitespace fixes
All patches applied.
^ permalink raw reply [flat|nested] 18+ messages in thread