Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH 1/3] Bluetooth DUN modem prototype
@ 2010-07-30  2:09 Gustavo F. Padovan
  2010-07-30  2:09 ` [PATCH 2/3] Add dun_enable() function Gustavo F. Padovan
  2010-08-02 14:33 ` [PATCH 1/3] Bluetooth DUN modem prototype Zhang, Zhenhua
  0 siblings, 2 replies; 7+ messages in thread
From: Gustavo F. Padovan @ 2010-07-30  2:09 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 10487 bytes --]

Add a still dummy DUN code, now it can only creates and removes modems.
The DUN plugin follows the HFP one a lot, the is basics a copy of some
HFP plugin's parts.
---
 Makefile.am                 |    6 ++
 drivers/dunmodem/dunmodem.c |   51 +++++++++++
 drivers/dunmodem/dunmodem.h |   29 ++++++
 plugins/bluetooth.c         |   11 +++
 plugins/bluetooth.h         |    2 +
 plugins/dun.c               |  202 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 301 insertions(+), 0 deletions(-)
 create mode 100644 drivers/dunmodem/dunmodem.c
 create mode 100644 drivers/dunmodem/dunmodem.h
 create mode 100644 plugins/dun.c

diff --git a/Makefile.am b/Makefile.am
index e256841..a6f2bff 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -179,6 +179,9 @@ builtin_sources += drivers/atmodem/atutil.h \
 			drivers/hfpmodem/network-registration.c \
 			drivers/hfpmodem/call-volume.c
 
+builtin_modules += dunmodem
+builtin_sources += drivers/dunmodem/dunmodem.h drivers/dunmodem/dunmodem.c
+
 builtin_modules += mbmmodem
 builtin_sources += drivers/atmodem/atutil.h \
 			drivers/mbmmodem/mbmmodem.h \
@@ -242,6 +245,9 @@ builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
 builtin_modules += hfp
 builtin_sources += plugins/hfp.c plugins/bluetooth.h
 
+builtin_modules += dun
+builtin_sources += plugins/dun.c
+
 builtin_modules += palmpre
 builtin_sources += plugins/palmpre.c
 
diff --git a/drivers/dunmodem/dunmodem.c b/drivers/dunmodem/dunmodem.c
new file mode 100644
index 0000000..8658bee
--- /dev/null
+++ b/drivers/dunmodem/dunmodem.c
@@ -0,0 +1,51 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2010 Gustavo F. Padovan <gustavo@padovan.org>
+ *
+ *  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
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <glib.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/log.h>
+#include <ofono/modem.h>
+
+#include "dunmodem.h"
+
+static int dunmodem_init(void)
+{
+	return 0;
+}
+
+static void dunmodem_exit(void)
+{
+}
+
+OFONO_PLUGIN_DEFINE(dunmodem, "Dial-up Networking Driver", VERSION,
+		OFONO_PLUGIN_PRIORITY_DEFAULT, dunmodem_init, dunmodem_exit)
+
diff --git a/drivers/dunmodem/dunmodem.h b/drivers/dunmodem/dunmodem.h
new file mode 100644
index 0000000..6bbf7b9
--- /dev/null
+++ b/drivers/dunmodem/dunmodem.h
@@ -0,0 +1,29 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010 Gustavo F. Padovan <gustavo@padovan.org>
+ *
+ *  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
+ *
+ */
+#ifndef __DUN_MODEM_H__
+#define __DUN_MODEM_H__
+
+struct dun_data {
+	char *dun_path;
+};
+
+#endif
+
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 5a85eaa..b7ec0d3 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -218,6 +218,9 @@ static void has_uuid(DBusMessageIter *array, gpointer user_data)
 		if (!strcasecmp(uuid, HFP_AG_UUID))
 			*profiles |= HFP_AG;
 
+		if (!strcasecmp(uuid, DUN_GW_UUID))
+			*profiles |= DUN_GW;
+
 		dbus_message_iter_next(&value);
 	}
 }
@@ -276,6 +279,14 @@ static void device_properties_cb(DBusPendingCall *call, gpointer user_data)
 		profile->create(path, device_addr, adapter_addr, alias);
 	}
 
+	if ((have_uuid & DUN_GW) && device_addr && adapter_addr) {
+		profile = g_hash_table_lookup(uuid_hash, DUN_GW_UUID);
+		if (!profile || !profile->create)
+			goto done;
+
+		profile->create(path, device_addr, adapter_addr, alias);
+	}
+
 done:
 	dbus_message_unref(reply);
 }
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index fb0d841..09e6efa 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -24,9 +24,11 @@
 #define	BLUEZ_DEVICE_INTERFACE		BLUEZ_SERVICE ".Device"
 
 #define HFP_AG_UUID	"0000111F-0000-1000-8000-00805F9B34FB"
+#define DUN_GW_UUID	"00001103-0000-1000-8000-00805F9B34FB"
 
 /* Profiles bitfield */
 #define HFP_AG 0x01
+#define DUN_GW 0x02
 
 struct bluetooth_profile {
 	const char *name;
diff --git a/plugins/dun.c b/plugins/dun.c
new file mode 100644
index 0000000..9b4288e
--- /dev/null
+++ b/plugins/dun.c
@@ -0,0 +1,202 @@
+/*
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2010 Gustavo F. Padovan <gustavo@padovan.org>
+ *
+ *  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 <drivers/dunmodem/dunmodem.h>
+
+#include <ofono/dbus.h>
+
+#include "bluetooth.h"
+
+#ifndef DBUS_TYPE_UNIX_FD
+#define DBUS_TYPE_UNIX_FD -1
+#endif
+
+static DBusConnection *connection;
+static GHashTable *modem_hash = NULL;
+
+static int dun_create_modem(const char *device, const char *dev_addr,
+				const char *adapter_addr, const char *alias)
+{
+	struct ofono_modem *modem;
+	struct dun_data *data;
+	char buf[256];
+
+	/* We already have this device in our hash, ignore */
+	if (g_hash_table_lookup(modem_hash, device) != NULL)
+		return -EALREADY;
+
+	ofono_info("Using device: %s, devaddr: %s, adapter: %s",
+			device, dev_addr, adapter_addr);
+
+	strcpy(buf, "dun/");
+	bluetooth_create_path(dev_addr, adapter_addr, buf + 4, sizeof(buf) - 4);
+
+	modem = ofono_modem_create(buf, "dun");
+	if (modem == NULL)
+		return -ENOMEM;
+
+	data = g_try_new0(struct dun_data, 1);
+	if (!data)
+		goto free;
+
+	data->dun_path = g_strdup(device);
+	if (data->dun_path == NULL)
+		goto free;
+
+	ofono_modem_set_data(modem, data);
+	ofono_modem_set_name(modem, alias);
+	ofono_modem_register(modem);
+
+	g_hash_table_insert(modem_hash, g_strdup(device), modem);
+	return 0;
+
+free:
+	g_free(data);
+	ofono_modem_remove(modem);
+
+	return -ENOMEM;
+}
+
+static gboolean dun_remove_each_modem(gpointer key, gpointer value, gpointer user_data)
+{
+	struct ofono_modem *modem = value;
+
+	ofono_modem_remove(modem);
+
+	return TRUE;
+}
+
+static void dun_remove_all_modem()
+{
+	if (modem_hash == NULL)
+		return;
+
+	g_hash_table_foreach_remove(modem_hash, dun_remove_each_modem, NULL);
+}
+
+static void dun_set_alias(const char *device, const char *alias)
+{
+	struct ofono_modem *modem;
+
+	if (!device || !alias)
+		return;
+
+	modem =	g_hash_table_lookup(modem_hash, device);
+	if (!modem)
+		return;
+
+	ofono_modem_set_name(modem, alias);
+}
+
+static int dun_probe(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+	return 0;
+}
+
+static void dun_remove(struct ofono_modem *modem)
+{
+	struct dun_data *data = ofono_modem_get_data(modem);
+
+	g_hash_table_remove(modem_hash, data->dun_path);
+
+	g_free(data->dun_path);
+	g_free(data);
+
+	ofono_modem_set_data(modem, NULL);
+}
+
+static int dun_enable(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+	return 0;
+}
+
+static int dun_disable(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+	return 0;
+}
+
+static struct ofono_modem_driver dun_driver = {
+	.name		= "dun",
+	.probe		= dun_probe,
+	.remove		= dun_remove,
+	.enable		= dun_enable,
+	.disable	= dun_disable,
+};
+
+static struct bluetooth_profile dun_profile = {
+	.name		= "dun",
+	.create		= dun_create_modem,
+	.remove_all	= dun_remove_all_modem,
+	.set_alias	= dun_set_alias,
+};
+
+static int dun_init()
+{
+	int err;
+
+	if (DBUS_TYPE_UNIX_FD < 0)
+		return -EBADF;
+
+	connection = ofono_dbus_get_connection();
+
+	err = ofono_modem_driver_register(&dun_driver);
+	if (err < 0)
+		return err;
+
+	err = bluetooth_register_uuid(DUN_GW_UUID, &dun_profile);
+	if (err < 0) {
+		ofono_modem_driver_unregister(&dun_driver);
+		return err;
+	}
+
+	modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, NULL);
+
+	return 0;
+}
+
+static void dun_exit()
+{
+	bluetooth_unregister_uuid(DUN_GW_UUID);
+	ofono_modem_driver_unregister(&dun_driver);
+
+	g_hash_table_destroy(modem_hash);
+}
+
+OFONO_PLUGIN_DEFINE(dun, "Dial-up Networking Profile Plugins", VERSION,
+			OFONO_PLUGIN_PRIORITY_DEFAULT, dun_init, dun_exit)
-- 
1.7.1.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-08-03 22:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-30  2:09 [PATCH 1/3] Bluetooth DUN modem prototype Gustavo F. Padovan
2010-07-30  2:09 ` [PATCH 2/3] Add dun_enable() function Gustavo F. Padovan
2010-07-30  2:09   ` [PATCH 3/3] Add dun_disable() to power down the modem Gustavo F. Padovan
2010-08-02 14:24   ` [PATCH 2/3] Add dun_enable() function Zhang, Zhenhua
2010-08-02 14:28   ` Zhang, Zhenhua
2010-08-03 22:58     ` Gustavo F. Padovan
2010-08-02 14:33 ` [PATCH 1/3] Bluetooth DUN modem prototype Zhang, Zhenhua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox