Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH 1/5] bluetooth: define DBUS_TIMEOUT macro
@ 2010-08-04 10:22 Gustavo F. Padovan
  2010-08-04 10:22 ` [PATCH 2/5] Bluetooth DUN modem prototype Gustavo F. Padovan
  2010-08-05 15:35 ` [PATCH 1/5] bluetooth: define DBUS_TIMEOUT macro Denis Kenzior
  0 siblings, 2 replies; 8+ messages in thread
From: Gustavo F. Padovan @ 2010-08-04 10:22 UTC (permalink / raw)
  To: ofono

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

---
 plugins/bluetooth.h |    2 ++
 plugins/hfp.c       |    6 +++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index fb0d841..b70bb0c 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -23,6 +23,8 @@
 #define	BLUEZ_ADAPTER_INTERFACE		BLUEZ_SERVICE ".Adapter"
 #define	BLUEZ_DEVICE_INTERFACE		BLUEZ_SERVICE ".Device"
 
+#define DBUS_TIMEOUT 15
+
 #define HFP_AG_UUID	"0000111F-0000-1000-8000-00805F9B34FB"
 
 /* Profiles bitfield */
diff --git a/plugins/hfp.c b/plugins/hfp.c
index b6cd415..0337891 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -595,7 +595,7 @@ static int hfp_enable(struct ofono_modem *modem)
 	status = bluetooth_send_with_reply(data->handsfree_path,
 					BLUEZ_GATEWAY_INTERFACE, "Connect",
 					hfp_connect_reply, modem, NULL,
-					15, DBUS_TYPE_INVALID);
+					DBUS_TIMEOUT, DBUS_TYPE_INVALID);
 
 	if (status < 0)
 		return -EINVAL;
@@ -636,8 +636,8 @@ static int hfp_disable(struct ofono_modem *modem)
 	if (data->agent_registered) {
 		status = bluetooth_send_with_reply(data->handsfree_path,
 					BLUEZ_GATEWAY_INTERFACE, "Disconnect",
-					hfp_power_down, modem, NULL, 15,
-					DBUS_TYPE_INVALID);
+					hfp_power_down, modem, NULL,
+					DBUS_TIMEOUT, DBUS_TYPE_INVALID);
 
 		if (status < 0)
 			return -EINVAL;
-- 
1.7.1.1


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

* [PATCH 2/5] Bluetooth DUN modem prototype
  2010-08-04 10:22 [PATCH 1/5] bluetooth: define DBUS_TIMEOUT macro Gustavo F. Padovan
@ 2010-08-04 10:22 ` Gustavo F. Padovan
  2010-08-04 10:22   ` [PATCH 3/5] Add dun_enable() function Gustavo F. Padovan
  2010-08-05 15:35 ` [PATCH 1/5] bluetooth: define DBUS_TIMEOUT macro Denis Kenzior
  1 sibling, 1 reply; 8+ messages in thread
From: Gustavo F. Padovan @ 2010-08-04 10:22 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 10370 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 |   50 +++++++++++
 drivers/dunmodem/dunmodem.h |   24 +++++
 plugins/bluetooth.c         |   11 +++
 plugins/bluetooth.h         |    2 +
 plugins/dun.c               |  203 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 296 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 b64ce8e..62ffc17 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..5657668
--- /dev/null
+++ b/drivers/dunmodem/dunmodem.c
@@ -0,0 +1,50 @@
+/*
+ *
+ *  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/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..291e2ce
--- /dev/null
+++ b/drivers/dunmodem/dunmodem.h
@@ -0,0 +1,24 @@
+/*
+ *
+ *  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
+ *
+ */
+
+struct dun_data {
+	char *dun_path;
+};
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 b70bb0c..d1302d4 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -26,9 +26,11 @@
 #define DBUS_TIMEOUT 15
 
 #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..1e9f972
--- /dev/null
+++ b/plugins/dun.c
@@ -0,0 +1,203 @@
+/*
+ *  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] 8+ messages in thread

* [PATCH 3/5] Add dun_enable() function
  2010-08-04 10:22 ` [PATCH 2/5] Bluetooth DUN modem prototype Gustavo F. Padovan
@ 2010-08-04 10:22   ` Gustavo F. Padovan
  2010-08-04 10:22     ` [PATCH 4/5] Add dun_disable() to power down the modem Gustavo F. Padovan
  2010-08-05 15:42     ` [PATCH 3/5] Add dun_enable() function Denis Kenzior
  0 siblings, 2 replies; 8+ messages in thread
From: Gustavo F. Padovan @ 2010-08-04 10:22 UTC (permalink / raw)
  To: ofono

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

dun_enable() is called by setting the Powered property to true.
It creates a rfcomm link throught the BlueZ Serial API.
---
 drivers/dunmodem/dunmodem.h |    1 +
 plugins/bluetooth.h         |    1 +
 plugins/dun.c               |   62 +++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/drivers/dunmodem/dunmodem.h b/drivers/dunmodem/dunmodem.h
index 291e2ce..6d545c9 100644
--- a/drivers/dunmodem/dunmodem.h
+++ b/drivers/dunmodem/dunmodem.h
@@ -21,4 +21,5 @@
 
 struct dun_data {
 	char *dun_path;
+	char *rfcomm;
 };
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index d1302d4..2a4a549 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -22,6 +22,7 @@
 #define	BLUEZ_MANAGER_INTERFACE		BLUEZ_SERVICE ".Manager"
 #define	BLUEZ_ADAPTER_INTERFACE		BLUEZ_SERVICE ".Adapter"
 #define	BLUEZ_DEVICE_INTERFACE		BLUEZ_SERVICE ".Device"
+#define	BLUEZ_SERIAL_INTERFACE		BLUEZ_SERVICE ".Serial"
 
 #define DBUS_TIMEOUT 15
 
diff --git a/plugins/dun.c b/plugins/dun.c
index 1e9f972..60d0271 100644
--- a/plugins/dun.c
+++ b/plugins/dun.c
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <gdbus.h>
 #include <glib.h>
 #include <ofono.h>
 
@@ -139,10 +140,67 @@ static void dun_remove(struct ofono_modem *modem)
 	ofono_modem_set_data(modem, NULL);
 }
 
+static void dun_connect_reply(DBusPendingCall *call, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct dun_data *data = ofono_modem_get_data(modem);
+	const char *dev;
+	DBusError derr;
+	DBusMessage *reply, *msg;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (ofono_modem_get_powered(modem))
+		goto done;
+
+	if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &dev,
+				DBUS_TYPE_INVALID))
+		goto done;
+
+	data->rfcomm = g_strdup(dev);
+
+	dbus_error_init(&derr);
+	if (!dbus_set_error_from_message(&derr, reply)) {
+		ofono_modem_set_powered(modem, TRUE);
+		goto done;
+	}
+
+	DBG("Connect reply: %s", derr.message);
+
+	if (dbus_error_has_name(&derr, DBUS_ERROR_NO_REPLY)) {
+		msg = dbus_message_new_method_call(BLUEZ_SERVICE,
+				data->dun_path,
+				BLUEZ_SERIAL_INTERFACE, "Disconnect");
+		if (!msg)
+			ofono_error("Disconnect failed");
+		else
+			g_dbus_send_message(connection, msg);
+	}
+
+	ofono_modem_set_powered(modem, FALSE);
+
+	dbus_error_free(&derr);
+
+done:
+	dbus_message_unref(reply);
+}
+
 static int dun_enable(struct ofono_modem *modem)
 {
-	DBG("%p", modem);
-	return 0;
+	struct dun_data *data = ofono_modem_get_data(modem);
+	int status;
+	const char *uuid = DUN_GW_UUID;
+
+	status = bluetooth_send_with_reply(data->dun_path,
+					BLUEZ_SERIAL_INTERFACE, "Connect",
+					dun_connect_reply, modem, NULL,
+					DBUS_TIMEOUT, DBUS_TYPE_STRING, &uuid,
+					DBUS_TYPE_INVALID);
+
+	if (status < 0)
+		return -EINVAL;
+
+	return -EINPROGRESS;
 }
 
 static int dun_disable(struct ofono_modem *modem)
-- 
1.7.1.1


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

* [PATCH 4/5] Add dun_disable() to power down the modem
  2010-08-04 10:22   ` [PATCH 3/5] Add dun_enable() function Gustavo F. Padovan
@ 2010-08-04 10:22     ` Gustavo F. Padovan
  2010-08-04 10:22       ` [PATCH 5/5] dun: Add GAtChat for the rfcomm device Gustavo F. Padovan
  2010-08-05 15:43       ` [PATCH 4/5] Add dun_disable() to power down the modem Denis Kenzior
  2010-08-05 15:42     ` [PATCH 3/5] Add dun_enable() function Denis Kenzior
  1 sibling, 2 replies; 8+ messages in thread
From: Gustavo F. Padovan @ 2010-08-04 10:22 UTC (permalink / raw)
  To: ofono

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

When setting Powered to 0 the link rfcomm is disconnected.
---
 plugins/dun.c |   42 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/plugins/dun.c b/plugins/dun.c
index 60d0271..3d1e5c4 100644
--- a/plugins/dun.c
+++ b/plugins/dun.c
@@ -203,10 +203,48 @@ static int dun_enable(struct ofono_modem *modem)
 	return -EINPROGRESS;
 }
 
+static void dun_power_down(DBusPendingCall *call, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct dun_data *data = ofono_modem_get_data(modem);
+	DBusMessage *reply;
+	DBusError derr;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&derr);
+	if (dbus_set_error_from_message(&derr, reply)) {
+		DBG("Disconnect reply: %s", derr.message);
+		dbus_error_free(&derr);
+		goto done;
+	}
+
+	ofono_modem_set_powered(modem, FALSE);
+
+done:
+	g_free(data->rfcomm);
+
+	dbus_message_unref(reply);
+}
+
 static int dun_disable(struct ofono_modem *modem)
 {
-	DBG("%p", modem);
-	return 0;
+	struct dun_data *data = ofono_modem_get_data(modem);
+	int status;
+
+	if (!ofono_modem_get_powered(modem))
+		return 0;
+
+	status = bluetooth_send_with_reply(data->dun_path,
+				BLUEZ_SERIAL_INTERFACE, "Disconnect",
+				dun_power_down, modem, NULL, DBUS_TIMEOUT,
+				DBUS_TYPE_STRING, &data->rfcomm,
+				DBUS_TYPE_INVALID);
+
+	if (status < 0)
+		return -EINVAL;
+
+	return -EINPROGRESS;
 }
 
 static struct ofono_modem_driver dun_driver = {
-- 
1.7.1.1


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

* [PATCH 5/5] dun: Add GAtChat for the rfcomm device
  2010-08-04 10:22     ` [PATCH 4/5] Add dun_disable() to power down the modem Gustavo F. Padovan
@ 2010-08-04 10:22       ` Gustavo F. Padovan
  2010-08-05 15:43       ` [PATCH 4/5] Add dun_disable() to power down the modem Denis Kenzior
  1 sibling, 0 replies; 8+ messages in thread
From: Gustavo F. Padovan @ 2010-08-04 10:22 UTC (permalink / raw)
  To: ofono

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

---
 drivers/dunmodem/dunmodem.c |    1 +
 drivers/dunmodem/dunmodem.h |    1 +
 plugins/dun.c               |   56 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/drivers/dunmodem/dunmodem.c b/drivers/dunmodem/dunmodem.c
index 5657668..1020dd2 100644
--- a/drivers/dunmodem/dunmodem.c
+++ b/drivers/dunmodem/dunmodem.c
@@ -30,6 +30,7 @@
 #include <errno.h>
 
 #include <glib.h>
+#include <gatchat.h>
 
 #define OFONO_API_SUBJECT_TO_CHANGE
 #include <ofono/plugin.h>
diff --git a/drivers/dunmodem/dunmodem.h b/drivers/dunmodem/dunmodem.h
index 6d545c9..f7351b7 100644
--- a/drivers/dunmodem/dunmodem.h
+++ b/drivers/dunmodem/dunmodem.h
@@ -22,4 +22,5 @@
 struct dun_data {
 	char *dun_path;
 	char *rfcomm;
+	GAtChat *chat;
 };
diff --git a/plugins/dun.c b/plugins/dun.c
index 3d1e5c4..488e7a3 100644
--- a/plugins/dun.c
+++ b/plugins/dun.c
@@ -23,11 +23,14 @@
 #include <config.h>
 #endif
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <gdbus.h>
 #include <glib.h>
 #include <ofono.h>
+#include <gatchat.h>
+#include <gattty.h>
 
 #define OFONO_API_SUBJECT_TO_CHANGE
 #include <ofono/plugin.h>
@@ -47,6 +50,48 @@
 static DBusConnection *connection;
 static GHashTable *modem_hash = NULL;
 
+static void dun_debug(const char *str, void *user_data)
+{
+	ofono_info("%s", str);
+}
+
+static GAtChat *create_port(const char *device)
+{
+	GAtSyntax *syntax;
+	GIOChannel *channel;
+	GAtChat *chat;
+
+	channel = g_at_tty_open(device, NULL);
+	if (!channel)
+		return NULL;
+
+	syntax = g_at_syntax_new_gsm_permissive();
+	chat = g_at_chat_new(channel, syntax);
+	g_at_syntax_unref(syntax);
+	g_io_channel_unref(channel);
+
+	if (!chat)
+		return NULL;
+
+	return chat;
+}
+
+static GAtChat *open_device(const char *device, char *debug)
+{
+	GAtChat *chat;
+
+	DBG("%s", device);
+
+	chat = create_port(device);
+	if (chat == NULL)
+		return NULL;
+
+	if (getenv("OFONO_AT_DEBUG"))
+		g_at_chat_set_debug(chat, dun_debug, debug);
+
+	return chat;
+}
+
 static int dun_create_modem(const char *device, const char *dev_addr,
 				const char *adapter_addr, const char *alias)
 {
@@ -159,6 +204,10 @@ static void dun_connect_reply(DBusPendingCall *call, gpointer user_data)
 
 	data->rfcomm = g_strdup(dev);
 
+	data->chat = open_device(dev, "Modem:");
+	if (data->chat == NULL)
+		goto done;
+
 	dbus_error_init(&derr);
 	if (!dbus_set_error_from_message(&derr, reply)) {
 		ofono_modem_set_powered(modem, TRUE);
@@ -235,6 +284,13 @@ static int dun_disable(struct ofono_modem *modem)
 	if (!ofono_modem_get_powered(modem))
 		return 0;
 
+	if (data->chat) {
+		g_at_chat_cancel_all(data->chat);
+		g_at_chat_unregister_all(data->chat);
+		g_at_chat_unref(data->chat);
+		data->chat = NULL;
+	}
+
 	status = bluetooth_send_with_reply(data->dun_path,
 				BLUEZ_SERIAL_INTERFACE, "Disconnect",
 				dun_power_down, modem, NULL, DBUS_TIMEOUT,
-- 
1.7.1.1


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

* Re: [PATCH 1/5] bluetooth: define DBUS_TIMEOUT macro
  2010-08-04 10:22 [PATCH 1/5] bluetooth: define DBUS_TIMEOUT macro Gustavo F. Padovan
  2010-08-04 10:22 ` [PATCH 2/5] Bluetooth DUN modem prototype Gustavo F. Padovan
@ 2010-08-05 15:35 ` Denis Kenzior
  1 sibling, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2010-08-05 15:35 UTC (permalink / raw)
  To: ofono

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

Hi Gustavo,

On 08/04/2010 05:22 AM, Gustavo F. Padovan wrote:
> ---
>  plugins/bluetooth.h |    2 ++
>  plugins/hfp.c       |    6 +++---
>  2 files changed, 5 insertions(+), 3 deletions(-)
> 

This patch has been applied, thanks.

Regards,
-Denis

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

* Re: [PATCH 3/5] Add dun_enable() function
  2010-08-04 10:22   ` [PATCH 3/5] Add dun_enable() function Gustavo F. Padovan
  2010-08-04 10:22     ` [PATCH 4/5] Add dun_disable() to power down the modem Gustavo F. Padovan
@ 2010-08-05 15:42     ` Denis Kenzior
  1 sibling, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2010-08-05 15:42 UTC (permalink / raw)
  To: ofono

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

Hi Gustavo,

> +static void dun_connect_reply(DBusPendingCall *call, gpointer user_data)
> +{
> +	struct ofono_modem *modem = user_data;
> +	struct dun_data *data = ofono_modem_get_data(modem);
> +	const char *dev;
> +	DBusError derr;
> +	DBusMessage *reply, *msg;
> +
> +	reply = dbus_pending_call_steal_reply(call);
> +
> +	if (ofono_modem_get_powered(modem))
> +		goto done;

I prefer you don't do this check above.  If the core isn't doing
something right I want things to crash right away.

> +
> +	if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &dev,
> +				DBUS_TYPE_INVALID))
> +		goto done;

That seems wrong, you need to tell the core powering up failed.  This
should be treated as an error.

> +
> +	data->rfcomm = g_strdup(dev);
> +
> +	dbus_error_init(&derr);
> +	if (!dbus_set_error_from_message(&derr, reply)) {
> +		ofono_modem_set_powered(modem, TRUE);
> +		goto done;
> +	}

Checking for D-Bus Error should be done before grabbing the reply
arguments, especially since you never free rfcomm above.

> +
> +	DBG("Connect reply: %s", derr.message);
> +
> +	if (dbus_error_has_name(&derr, DBUS_ERROR_NO_REPLY)) {
> +		msg = dbus_message_new_method_call(BLUEZ_SERVICE,
> +				data->dun_path,
> +				BLUEZ_SERIAL_INTERFACE, "Disconnect");
> +		if (!msg)
> +			ofono_error("Disconnect failed");
> +		else
> +			g_dbus_send_message(connection, msg);
> +	}

I'm not sure this part is really necessary.  How can we trigger a
condition where this function fails but the tty device is created?

> +
> +	ofono_modem_set_powered(modem, FALSE);
> +
> +	dbus_error_free(&derr);

Might want to localize dbus_error_free() to the same area where it is
being used.  Makes the code easier to read.

> +
> +done:
> +	dbus_message_unref(reply);
> +}
> +
>  static int dun_enable(struct ofono_modem *modem)
>  {
> -	DBG("%p", modem);

Might want to leave the DBG in there.

> -	return 0;
> +	struct dun_data *data = ofono_modem_get_data(modem);
> +	int status;
> +	const char *uuid = DUN_GW_UUID;
> +
> +	status = bluetooth_send_with_reply(data->dun_path,
> +					BLUEZ_SERIAL_INTERFACE, "Connect",
> +					dun_connect_reply, modem, NULL,
> +					DBUS_TIMEOUT, DBUS_TYPE_STRING, &uuid,
> +					DBUS_TYPE_INVALID);
> +
> +	if (status < 0)
> +		return -EINVAL;
> +
> +	return -EINPROGRESS;
>  }
>  
>  static int dun_disable(struct ofono_modem *modem)

Regards,
-Denis

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

* Re: [PATCH 4/5] Add dun_disable() to power down the modem
  2010-08-04 10:22     ` [PATCH 4/5] Add dun_disable() to power down the modem Gustavo F. Padovan
  2010-08-04 10:22       ` [PATCH 5/5] dun: Add GAtChat for the rfcomm device Gustavo F. Padovan
@ 2010-08-05 15:43       ` Denis Kenzior
  1 sibling, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2010-08-05 15:43 UTC (permalink / raw)
  To: ofono

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

Hi Gustavo,

On 08/04/2010 05:22 AM, Gustavo F. Padovan wrote:
> When setting Powered to 0 the link rfcomm is disconnected.
> ---
>  plugins/dun.c |   42 ++++++++++++++++++++++++++++++++++++++++--
>  1 files changed, 40 insertions(+), 2 deletions(-)
> 
> diff --git a/plugins/dun.c b/plugins/dun.c
> index 60d0271..3d1e5c4 100644
> --- a/plugins/dun.c
> +++ b/plugins/dun.c
> @@ -203,10 +203,48 @@ static int dun_enable(struct ofono_modem *modem)
>  	return -EINPROGRESS;
>  }
>  
> +static void dun_power_down(DBusPendingCall *call, gpointer user_data)
> +{
> +	struct ofono_modem *modem = user_data;
> +	struct dun_data *data = ofono_modem_get_data(modem);
> +	DBusMessage *reply;
> +	DBusError derr;
> +
> +	reply = dbus_pending_call_steal_reply(call);
> +
> +	dbus_error_init(&derr);
> +	if (dbus_set_error_from_message(&derr, reply)) {
> +		DBG("Disconnect reply: %s", derr.message);
> +		dbus_error_free(&derr);
> +		goto done;
> +	}
> +
> +	ofono_modem_set_powered(modem, FALSE);
> +
> +done:
> +	g_free(data->rfcomm);
> +
> +	dbus_message_unref(reply);
> +}
> +
>  static int dun_disable(struct ofono_modem *modem)
>  {
> -	DBG("%p", modem);
> -	return 0;
> +	struct dun_data *data = ofono_modem_get_data(modem);
> +	int status;
> +
> +	if (!ofono_modem_get_powered(modem))
> +		return 0;

Again, please don't do this part.  If the core messes up, I want to know
early.

> +
> +	status = bluetooth_send_with_reply(data->dun_path,
> +				BLUEZ_SERIAL_INTERFACE, "Disconnect",
> +				dun_power_down, modem, NULL, DBUS_TIMEOUT,
> +				DBUS_TYPE_STRING, &data->rfcomm,
> +				DBUS_TYPE_INVALID);
> +
> +	if (status < 0)
> +		return -EINVAL;
> +
> +	return -EINPROGRESS;
>  }
>  
>  static struct ofono_modem_driver dun_driver = {

Regards,
-Denis

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

end of thread, other threads:[~2010-08-05 15:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-04 10:22 [PATCH 1/5] bluetooth: define DBUS_TIMEOUT macro Gustavo F. Padovan
2010-08-04 10:22 ` [PATCH 2/5] Bluetooth DUN modem prototype Gustavo F. Padovan
2010-08-04 10:22   ` [PATCH 3/5] Add dun_enable() function Gustavo F. Padovan
2010-08-04 10:22     ` [PATCH 4/5] Add dun_disable() to power down the modem Gustavo F. Padovan
2010-08-04 10:22       ` [PATCH 5/5] dun: Add GAtChat for the rfcomm device Gustavo F. Padovan
2010-08-05 15:43       ` [PATCH 4/5] Add dun_disable() to power down the modem Denis Kenzior
2010-08-05 15:42     ` [PATCH 3/5] Add dun_enable() function Denis Kenzior
2010-08-05 15:35 ` [PATCH 1/5] bluetooth: define DBUS_TIMEOUT macro Denis Kenzior

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