linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhenhua Zhang <zhenhua.zhang@intel.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 5/6] dun_gw: Add DUN server plugin for oFono
Date: Thu, 29 Jul 2010 15:18:20 +0800	[thread overview]
Message-ID: <1280387901-8581-6-git-send-email-zhenhua.zhang@intel.com> (raw)
In-Reply-To: <1280387901-8581-1-git-send-email-zhenhua.zhang@intel.com>

DUN server plug-in watches ofono modem status. When the modem comes to
ONLINE state, it registers itself on Bluetooth adapter and want for
incoming DUN connection.
---
 Makefile.am      |    4 ++
 plugins/dun_gw.c |  143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 147 insertions(+), 0 deletions(-)
 create mode 100644 plugins/dun_gw.c

diff --git a/Makefile.am b/Makefile.am
index e256841..2e08ff2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -242,6 +242,10 @@ builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
 builtin_modules += hfp
 builtin_sources += plugins/hfp.c plugins/bluetooth.h
 
+builtin_modules += dun_gw
+builtin_sources += plugins/dun_gw.c plugins/bluetooth.h plugins/btio.c \
+			plugins/btio.h
+
 builtin_modules += palmpre
 builtin_sources += plugins/palmpre.c
 
diff --git a/plugins/dun_gw.c b/plugins/dun_gw.c
new file mode 100644
index 0000000..56bd03d
--- /dev/null
+++ b/plugins/dun_gw.c
@@ -0,0 +1,143 @@
+/*
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010  Intel Corporation. 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 <string.h>
+#include <errno.h>
+#include <glib.h>
+#include <ofono.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/log.h>
+#include <ofono/modem.h>
+
+#include <ofono/dbus.h>
+
+#include "gdbus.h"
+#include "bluetooth.h"
+
+#ifndef DBUS_TYPE_UNIX_FD
+#define DBUS_TYPE_UNIX_FD -1
+#endif
+
+#define DUN_GW_CHANNEL	1
+
+static struct server *server;
+static int modem_watch;
+
+static void dun_gw_connect_cb(GIOChannel *io, GError *err, gpointer user_data)
+{
+	DBG("");
+
+	if (err) {
+		DBG("%s", err->message);
+		goto failed;
+	}
+
+	return;
+
+failed:
+	g_io_channel_shutdown(io, TRUE, NULL);
+	bluetooth_unregister_server(server);
+	server = NULL;
+}
+
+static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
+					void *user_data)
+{
+	const char *property;
+	DBusMessageIter iter, var;
+
+	dbus_message_iter_init(msg, &iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return FALSE;
+
+	dbus_message_iter_get_basic(&iter, &property);
+
+	if (g_str_equal(property, "Online") == TRUE) {
+		const char *path = dbus_message_get_path(msg);
+		struct ofono_modem *modem;
+		struct ofono_atom *gprs;
+		gboolean online;
+
+		if (!dbus_message_iter_next(&iter))
+			return FALSE;
+
+		if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+			return FALSE;
+
+		dbus_message_iter_recurse(&iter, &var);
+
+		dbus_message_iter_get_basic(&var, &online);
+
+		if (online == FALSE) {
+			bluetooth_unregister_server(server);
+			server = NULL;
+			goto done;
+		}
+
+		/* Create DUN server */
+		modem = ofono_modem_get_modem_by_path(path);
+		gprs = __ofono_modem_find_atom(modem,
+						OFONO_ATOM_TYPE_GPRS);
+		/* Make sure the modem has GPRS atom */
+		if (!gprs)
+			goto done;
+
+		server = bluetooth_register_server(DUN_GW,
+				"Dial-Up Networking", DUN_GW_CHANNEL,
+				dun_gw_connect_cb, modem);
+	}
+
+done:
+	return TRUE;
+}
+
+static int dun_gw_init()
+{
+	DBusConnection *connection = ofono_dbus_get_connection();
+
+	if (DBUS_TYPE_UNIX_FD < 0)
+		return -EBADF;
+
+	modem_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+						OFONO_MODEM_INTERFACE,
+						"PropertyChanged",
+						property_changed, NULL, NULL);
+
+	return 0;
+}
+
+static void dun_gw_exit()
+{
+	if (server)
+		bluetooth_unregister_server(server);
+
+	if (modem_watch)
+		g_source_remove(modem_watch);
+}
+
+OFONO_PLUGIN_DEFINE(dun_gw, "Dial-up Networking Profile Plugins", VERSION,
+			OFONO_PLUGIN_PRIORITY_DEFAULT, dun_gw_init, dun_gw_exit)
-- 
1.7.0.4


  parent reply	other threads:[~2010-07-29  7:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-29  7:18 [PATCH 0/6] oFono patches for BT DUN server Zhenhua Zhang
2010-07-29  7:18 ` [PATCH 1/6] bluetooth: Add reference count for bluetooth utils Zhenhua Zhang
2010-07-31 23:25   ` Gustavo F. Padovan
2010-08-02  0:20     ` Zhang, Zhenhua
2010-07-29  7:18 ` [PATCH 2/6] bluetooth: Add Btio library for DUN Zhenhua Zhang
2010-07-29  7:18 ` [PATCH 3/6] bluetooth: Add bluetooth server support " Zhenhua Zhang
2010-07-29  7:18 ` [PATCH 4/6] modem: Add method to get modem by path Zhenhua Zhang
2010-07-29  7:18 ` Zhenhua Zhang [this message]
2010-07-29  7:18 ` [PATCH 6/6] emulator: Add emulator atom in oFono Zhenhua Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1280387901-8581-6-git-send-email-zhenhua.zhang@intel.com \
    --to=zhenhua.zhang@intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).