All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -v3 01/23] udevng: look also to VID
@ 2011-09-26 17:26 Gustavo F. Padovan
  2011-09-26 17:26 ` [PATCH -v3 02/23] sap: Add basic sap plugin Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:26 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

Some drivers name are not properly set, so we need to rely on the VID
information as well
---
 plugins/udevng.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/plugins/udevng.c b/plugins/udevng.c
index 1365bd1..5fd9475 100644
--- a/plugins/udevng.c
+++ b/plugins/udevng.c
@@ -857,14 +857,16 @@ static void check_usb_device(struct udev_device *device)
 		DBG("%s [%s:%s]", drv, vid, pid);
 
 		for (i = 0; vendor_list[i].driver; i++) {
-			if (g_str_equal(vendor_list[i].drv, drv) == FALSE)
-				continue;
-
-			if (vendor_list[i].vid == NULL) {
-				driver = vendor_list[i].driver;
-				break;
+			if (g_str_equal(vendor_list[i].drv, drv) == TRUE) {
+				if (vendor_list[i].vid == NULL) {
+					driver = vendor_list[i].driver;
+					break;
+				}
 			}
 
+			if (vendor_list[i].vid == NULL)
+				continue;
+
 			if (g_str_equal(vendor_list[i].vid, vid) == TRUE) {
 				if (vendor_list[i].pid == NULL) {
 					if (driver == NULL)
-- 
1.7.6.2


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

* [PATCH -v3 02/23] sap: Add basic sap plugin
  2011-09-26 17:26 [PATCH -v3 01/23] udevng: look also to VID Gustavo F. Padovan
@ 2011-09-26 17:26 ` Gustavo F. Padovan
  2011-09-26 17:26   ` [PATCH -v3 03/23] telit: add support to enable SAP client Gustavo F. Padovan
  2011-09-26 18:55   ` [PATCH -v3 02/23] sap: Add basic sap plugin Denis Kenzior
  0 siblings, 2 replies; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:26 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 Makefile.am         |    3 +
 plugins/bluetooth.c |    1 -
 plugins/bluetooth.h |   12 ++
 plugins/hfp_hf.c    |    2 -
 plugins/sap.c       |  277 +++++++++++++++++++++++++++++++++++++++++++++++++++
 plugins/telit.c     |   10 ++
 6 files changed, 302 insertions(+), 3 deletions(-)
 create mode 100644 plugins/sap.c

diff --git a/Makefile.am b/Makefile.am
index 71962ea..8771cb2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -369,6 +369,9 @@ builtin_sources += plugins/hfp_ag.c plugins/bluetooth.h
 builtin_modules += dun_gw
 builtin_sources += plugins/dun_gw.c plugins/bluetooth.h
 
+builtin_modules += sap
+builtin_sources += plugins/sap.c plugins/bluetooth.h
+
 builtin_modules += connman
 builtin_sources += plugins/connman.c
 
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index a286dd4..274d25b 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -33,7 +33,6 @@
 #include <gdbus.h>
 
 #define OFONO_API_SUBJECT_TO_CHANGE
-#include <ofono/dbus.h>
 #include <ofono/plugin.h>
 #include <ofono/log.h>
 
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 4056f0a..b21ab64 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -19,6 +19,9 @@
  *
  */
 
+#include <ofono/modem.h>
+#include <ofono/dbus.h>
+
 #define	BLUEZ_SERVICE "org.bluez"
 #define	BLUEZ_MANAGER_INTERFACE		BLUEZ_SERVICE ".Manager"
 #define	BLUEZ_ADAPTER_INTERFACE		BLUEZ_SERVICE ".Adapter"
@@ -30,6 +33,7 @@
 #define DUN_GW_UUID	"00001103-0000-1000-8000-00805f9b34fb"
 #define HFP_AG_UUID	"0000111f-0000-1000-8000-00805f9b34fb"
 #define HFP_HS_UUID	"0000111e-0000-1000-8000-00805f9b34fb"
+#define SAP_UUID	"0000112d-0000-1000-8000-00805f9b34fb"
 
 struct bluetooth_profile {
 	const char *name;
@@ -39,6 +43,10 @@ struct bluetooth_profile {
 	void (*set_alias)(const char *device, const char *);
 };
 
+struct bluetooth_sap_driver {
+	const char *name;
+};
+
 struct server;
 
 typedef void (*ConnectFunc)(GIOChannel *io, GError *err, gpointer user_data);
@@ -60,3 +68,7 @@ int bluetooth_send_with_reply(const char *path, const char *interface,
 				void *user_data, DBusFreeFunction free_func,
 				int timeout, int type, ...);
 void bluetooth_parse_properties(DBusMessage *reply, const char *property, ...);
+
+int bluetooth_sap_client_register(struct bluetooth_sap_driver *sap,
+					struct ofono_modem *modem);
+void bluetooth_sap_client_unregister(struct ofono_modem *modem);
diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index 0c6ed83..d5f26c0 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -45,8 +45,6 @@
 
 #include <drivers/hfpmodem/slc.h>
 
-#include <ofono/dbus.h>
-
 #include "bluetooth.h"
 
 #define	BLUEZ_GATEWAY_INTERFACE		BLUEZ_SERVICE ".HandsfreeGateway"
diff --git a/plugins/sap.c b/plugins/sap.c
new file mode 100644
index 0000000..52fb2fb
--- /dev/null
+++ b/plugins/sap.c
@@ -0,0 +1,277 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2010-2011  ProFUSION embedded systems
+ *
+ *  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 <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <glib.h>
+#include <gdbus.h>
+#include <ofono.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/log.h>
+#include <ofono/modem.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 struct ofono_modem *sap_hw_modem = NULL;
+static struct bluetooth_sap_driver *sap_hw_driver = NULL;
+
+struct sap_data {
+	char *server_path;
+	struct ofono_modem *hw_modem;
+	struct bluetooth_sap_driver *sap_driver;
+};
+
+int bluetooth_sap_client_register(struct bluetooth_sap_driver *sap,
+					struct ofono_modem *modem)
+{
+	if (sap_hw_modem != NULL)
+		return -EPERM;
+
+	sap_hw_modem = modem;
+	sap_hw_driver = sap;
+
+	return 0;
+}
+
+static void sap_remove_modem(struct ofono_modem *modem)
+{
+	struct sap_data *data = ofono_modem_get_data(modem);
+
+	g_free(data->server_path);
+	g_free(data);
+
+	ofono_modem_set_data(modem, NULL);
+
+	ofono_modem_remove(modem);
+}
+
+void bluetooth_sap_client_unregister(struct ofono_modem *modem)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	if (sap_hw_modem == NULL)
+		return;
+
+	g_hash_table_iter_init(&iter, modem_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+
+		g_hash_table_iter_remove(&iter);
+
+		sap_remove_modem(value);
+	}
+
+	sap_hw_modem = NULL;
+	sap_hw_driver = NULL;
+}
+
+static int sap_probe(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+
+	return 0;
+}
+
+static void sap_remove(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+}
+
+/* power up hardware */
+static int sap_enable(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+
+	return 0;
+}
+
+static int sap_disable(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+
+	return 0;
+}
+
+static void sap_pre_sim(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+}
+
+static void sap_post_sim(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+}
+
+static int bluetooth_sap_probe(const char *device, const char *dev_addr,
+				const char *adapter_addr, const char *alias)
+{
+	struct ofono_modem *modem;
+	struct sap_data *data;
+	char buf[256];
+
+	if(sap_hw_modem == NULL)
+		return -ENODEV;
+
+	/* 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, "sap/");
+	bluetooth_create_path(dev_addr, adapter_addr, buf + 4,
+						sizeof(buf) - 4);
+
+	modem = ofono_modem_create(buf, "sap");
+	if (modem == NULL)
+		return -ENOMEM;
+
+	data = g_try_new0(struct sap_data, 1);
+	if (data == NULL)
+		goto free;
+
+	data->server_path = g_strdup(device);
+	if (data->server_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 void bluetooth_sap_remove(const char *prefix)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	DBG("%s", prefix);
+
+	if (modem_hash == NULL || prefix == NULL)
+		return;
+
+	g_hash_table_iter_init(&iter, modem_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+
+		if (g_str_has_prefix((char *)key, prefix) == FALSE)
+			continue;
+
+		g_hash_table_iter_remove(&iter);
+
+		sap_remove_modem(value);
+	}
+}
+
+static void bluetooth_sap_set_alias(const char *device, const char *alias)
+{
+	struct ofono_modem *modem;
+
+	if (device == NULL || alias == NULL)
+		return;
+
+	modem =	g_hash_table_lookup(modem_hash, device);
+	if (modem == NULL)
+		return;
+
+	ofono_modem_set_name(modem, alias);
+}
+
+static struct ofono_modem_driver sap_driver = {
+	.name		= "sap",
+	.probe		= sap_probe,
+	.remove		= sap_remove,
+	.enable		= sap_enable,
+	.disable	= sap_disable,
+	.pre_sim	= sap_pre_sim,
+	.post_sim	= sap_post_sim,
+};
+
+static struct bluetooth_profile sap = {
+	.name		= "sap",
+	.probe		= bluetooth_sap_probe,
+	.remove		= bluetooth_sap_remove,
+	.set_alias	= bluetooth_sap_set_alias,
+};
+
+static int sap_init(void)
+{
+	int err;
+
+	if (DBUS_TYPE_UNIX_FD < 0)
+		return -EBADF;
+
+	connection = ofono_dbus_get_connection();
+
+	err = ofono_modem_driver_register(&sap_driver);
+	if (err < 0)
+		return err;
+
+	err = bluetooth_register_uuid(SAP_UUID, &sap);
+	if (err < 0) {
+		ofono_modem_driver_unregister(&sap_driver);
+		return err;
+	}
+
+	modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, NULL);
+
+	return 0;
+}
+
+static void sap_exit(void)
+{
+	DBG("");
+
+	bluetooth_unregister_uuid(SAP_UUID);
+	ofono_modem_driver_unregister(&sap_driver);
+	g_hash_table_destroy(modem_hash);
+	modem_hash = NULL;
+}
+
+OFONO_PLUGIN_DEFINE(sap, "Sim Access Profile Plugins", VERSION,
+			OFONO_PLUGIN_PRIORITY_DEFAULT, sap_init, sap_exit)
diff --git a/plugins/telit.c b/plugins/telit.c
index 9c8eb0d..18cf0c4 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -54,6 +54,8 @@
 #include <drivers/atmodem/atutil.h>
 #include <drivers/atmodem/vendor.h>
 
+#include "bluetooth.h"
+
 static const char *none_prefix[] = { NULL };
 static const char *qss_prefix[] = { "#QSS:", NULL };
 
@@ -63,6 +65,10 @@ struct telit_data {
 	guint sim_inserted_source;
 };
 
+static struct bluetooth_sap_driver sap_driver = {
+	.name = "telit",
+};
+
 static void telit_debug(const char *str, void *user_data)
 {
 	const char *prefix = user_data;
@@ -82,6 +88,8 @@ static int telit_probe(struct ofono_modem *modem)
 
 	ofono_modem_set_data(modem, data);
 
+	bluetooth_sap_client_register(&sap_driver, modem);
+
 	return 0;
 }
 
@@ -91,6 +99,8 @@ static void telit_remove(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
+	bluetooth_sap_client_unregister(modem);
+
 	ofono_modem_set_data(modem, NULL);
 
 	if (data->sim_inserted_source > 0)
-- 
1.7.6.2


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

* [PATCH -v3 03/23] telit: add support to enable SAP client
  2011-09-26 17:26 ` [PATCH -v3 02/23] sap: Add basic sap plugin Gustavo F. Padovan
@ 2011-09-26 17:26   ` Gustavo F. Padovan
  2011-09-26 17:26     ` [PATCH -v3 04/23] sap: add support to connect the RFCOMM link Gustavo F. Padovan
  2011-09-26 18:56     ` [PATCH -v3 03/23] telit: add support to enable SAP client Denis Kenzior
  2011-09-26 18:55   ` [PATCH -v3 02/23] sap: Add basic sap plugin Denis Kenzior
  1 sibling, 2 replies; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:26 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/bluetooth.h |    1 +
 plugins/sap.c       |    4 +-
 plugins/telit.c     |  109 ++++++++++++++++++++++++++++++++++-----------------
 3 files changed, 76 insertions(+), 38 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index b21ab64..6cde7bc 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -45,6 +45,7 @@ struct bluetooth_profile {
 
 struct bluetooth_sap_driver {
 	const char *name;
+	int (*enable) (struct ofono_modem *modem);
 };
 
 struct server;
diff --git a/plugins/sap.c b/plugins/sap.c
index 52fb2fb..d127f0d 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -114,9 +114,9 @@ static void sap_remove(struct ofono_modem *modem)
 /* power up hardware */
 static int sap_enable(struct ofono_modem *modem)
 {
-	DBG("%p", modem);
+	struct sap_data *data = ofono_modem_get_data(modem);
 
-	return 0;
+	return data->sap_driver->enable(data->hw_modem);
 }
 
 static int sap_disable(struct ofono_modem *modem)
diff --git a/plugins/telit.c b/plugins/telit.c
index 18cf0c4..cc10668 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -58,6 +58,7 @@
 
 static const char *none_prefix[] = { NULL };
 static const char *qss_prefix[] = { "#QSS:", NULL };
+static const char *rsen_prefix[]= { "#RSEN:", NULL };
 
 struct telit_data {
 	GAtChat *chat;
@@ -65,10 +66,6 @@ struct telit_data {
 	guint sim_inserted_source;
 };
 
-static struct bluetooth_sap_driver sap_driver = {
-	.name = "telit",
-};
-
 static void telit_debug(const char *str, void *user_data)
 {
 	const char *prefix = user_data;
@@ -76,6 +73,78 @@ static void telit_debug(const char *str, void *user_data)
 	ofono_info("%s%s", prefix, str);
 }
 
+static GAtChat *open_device(struct ofono_modem *modem,
+				const char *key, char *debug)
+{
+	const char *device;
+	GAtSyntax *syntax;
+	GIOChannel *channel;
+	GAtChat *chat;
+
+	device = ofono_modem_get_string(modem, key);
+	if (device == NULL)
+		return NULL;
+
+	DBG("%s %s", key, device);
+
+	channel = g_at_tty_open(device, NULL);
+	if (channel == NULL)
+		return NULL;
+
+	syntax = g_at_syntax_new_gsmv1();
+	chat = g_at_chat_new(channel, syntax);
+	g_at_syntax_unref(syntax);
+	g_io_channel_unref(channel);
+
+	if (chat == NULL)
+		return NULL;
+
+	if (getenv("OFONO_AT_DEBUG"))
+		g_at_chat_set_debug(chat, telit_debug, debug);
+
+	return chat;
+}
+
+static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct telit_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	if (!ok) {
+		g_at_chat_unref(data->chat);
+		data->chat = NULL;
+		ofono_modem_set_powered(modem, FALSE);
+		return;
+	}
+
+}
+
+static int telit_sap_enable(struct ofono_modem *modem)
+{
+	struct telit_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	data->chat = open_device(modem, "Data", "Aux: ");
+	if (data->chat == NULL)
+		return -EINVAL;
+
+	g_at_chat_send(data->chat, "AT#NOPT=3", NULL, NULL, NULL, NULL);
+
+	/* Set SAP functionality */
+	g_at_chat_send(data->chat, "AT#RSEN=1,1,0,2,0", rsen_prefix,
+				rsen_enable_cb, modem, NULL);
+
+	return -EINPROGRESS;
+}
+
+static struct bluetooth_sap_driver sap_driver = {
+	.name = "telit",
+	.enable = telit_sap_enable,
+};
+
 static int telit_probe(struct ofono_modem *modem)
 {
 	struct telit_data *data;
@@ -232,38 +301,6 @@ static void cfun_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 		ofono_modem_set_powered(modem, FALSE);
 }
 
-static GAtChat *open_device(struct ofono_modem *modem,
-				const char *key, char *debug)
-{
-	const char *device;
-	GAtSyntax *syntax;
-	GIOChannel *channel;
-	GAtChat *chat;
-
-	device = ofono_modem_get_string(modem, key);
-	if (device == NULL)
-		return NULL;
-
-	DBG("%s %s", key, device);
-
-	channel = g_at_tty_open(device, NULL);
-	if (channel == NULL)
-		return NULL;
-
-	syntax = g_at_syntax_new_gsmv1();
-	chat = g_at_chat_new(channel, syntax);
-	g_at_syntax_unref(syntax);
-	g_io_channel_unref(channel);
-
-	if (chat == NULL)
-		return NULL;
-
-	if (getenv("OFONO_AT_DEBUG"))
-		g_at_chat_set_debug(chat, telit_debug, debug);
-
-	return chat;
-}
-
 static int telit_enable(struct ofono_modem *modem)
 {
 	struct telit_data *data = ofono_modem_get_data(modem);
-- 
1.7.6.2


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

* [PATCH -v3 04/23] sap: add support to connect the RFCOMM link
  2011-09-26 17:26   ` [PATCH -v3 03/23] telit: add support to enable SAP client Gustavo F. Padovan
@ 2011-09-26 17:26     ` Gustavo F. Padovan
  2011-09-26 17:26       ` [PATCH -v3 05/23] telit: add #RSEN notify Gustavo F. Padovan
  2011-09-26 18:57       ` [PATCH -v3 04/23] sap: add support to connect the RFCOMM link Denis Kenzior
  2011-09-26 18:56     ` [PATCH -v3 03/23] telit: add support to enable SAP client Denis Kenzior
  1 sibling, 2 replies; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:26 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/sap.c |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/plugins/sap.c b/plugins/sap.c
index d127f0d..3151c4c 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -38,11 +38,14 @@
 #include <ofono/modem.h>
 
 #include "bluetooth.h"
+#include "util.h"
 
 #ifndef DBUS_TYPE_UNIX_FD
 #define DBUS_TYPE_UNIX_FD -1
 #endif
 
+#define BLUEZ_SERIAL_INTERFACE	BLUEZ_SERVICE ".Serial"
+
 static DBusConnection *connection;
 static GHashTable *modem_hash = NULL;
 static struct ofono_modem *sap_hw_modem = NULL;
@@ -111,12 +114,52 @@ static void sap_remove(struct ofono_modem *modem)
 	DBG("%p", modem);
 }
 
+static void sap_connect_reply(DBusPendingCall *call, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	DBusError derr;
+	DBusMessage *reply;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (ofono_modem_get_powered(modem))
+		goto done;
+
+	dbus_error_init(&derr);
+	if (!dbus_set_error_from_message(&derr, reply))
+		goto done;
+
+	DBG("Connect reply: %s", derr.message);
+
+	ofono_modem_set_powered(modem, FALSE);
+
+	dbus_error_free(&derr);
+
+done:
+	dbus_message_unref(reply);
+}
+
 /* power up hardware */
 static int sap_enable(struct ofono_modem *modem)
 {
 	struct sap_data *data = ofono_modem_get_data(modem);
+	int status;
+	const char *str = "sap";
+
+	DBG("%p", modem);
+
+	status = bluetooth_send_with_reply(data->server_path,
+					BLUEZ_SERIAL_INTERFACE, "ConnectFD",
+					sap_connect_reply, modem, NULL,
+					DBUS_TIMEOUT, DBUS_TYPE_STRING,
+					&str, DBUS_TYPE_INVALID);
+
+	if (status < 0)
+		return -EINVAL;
 
-	return data->sap_driver->enable(data->hw_modem);
+	return -EINPROGRESS;
 }
 
 static int sap_disable(struct ofono_modem *modem)
-- 
1.7.6.2


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

* [PATCH -v3 05/23] telit: add #RSEN notify
  2011-09-26 17:26     ` [PATCH -v3 04/23] sap: add support to connect the RFCOMM link Gustavo F. Padovan
@ 2011-09-26 17:26       ` Gustavo F. Padovan
  2011-09-26 17:26         ` [PATCH -v3 06/23] sap: add watch for the Bluetooth Link Gustavo F. Padovan
  2011-09-26 18:57         ` [PATCH -v3 05/23] telit: add #RSEN notify Denis Kenzior
  2011-09-26 18:57       ` [PATCH -v3 04/23] sap: add support to connect the RFCOMM link Denis Kenzior
  1 sibling, 2 replies; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:26 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

RSEN URC tells if the SAP Client was enabled or not
---
 plugins/telit.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/plugins/telit.c b/plugins/telit.c
index cc10668..1f950aa 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -105,6 +105,22 @@ static GAtChat *open_device(struct ofono_modem *modem,
 	return chat;
 }
 
+static void telit_rsen_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	int status;
+	GAtResultIter iter;
+
+	DBG("%p", modem);
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "#RSEN:"))
+		return;
+
+	g_at_result_iter_next_number(&iter, &status);
+}
+
 static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -131,6 +147,9 @@ static int telit_sap_enable(struct ofono_modem *modem)
 	if (data->chat == NULL)
 		return -EINVAL;
 
+	g_at_chat_register(data->chat, "#RSEN:", telit_rsen_notify,
+				FALSE, modem, NULL);
+
 	g_at_chat_send(data->chat, "AT#NOPT=3", NULL, NULL, NULL, NULL);
 
 	/* Set SAP functionality */
-- 
1.7.6.2


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

* [PATCH -v3 06/23] sap: add watch for the Bluetooth Link
  2011-09-26 17:26       ` [PATCH -v3 05/23] telit: add #RSEN notify Gustavo F. Padovan
@ 2011-09-26 17:26         ` Gustavo F. Padovan
  2011-09-26 17:27           ` [PATCH -v3 07/23] sap: add support to open the channel for SAP data Gustavo F. Padovan
  2011-09-26 18:57         ` [PATCH -v3 05/23] telit: add #RSEN notify Denis Kenzior
  1 sibling, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:26 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/sap.c |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/plugins/sap.c b/plugins/sap.c
index 3151c4c..b620309 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -55,6 +55,8 @@ struct sap_data {
 	char *server_path;
 	struct ofono_modem *hw_modem;
 	struct bluetooth_sap_driver *sap_driver;
+	GIOChannel *bt_io;
+	guint bt_watch;
 };
 
 int bluetooth_sap_client_register(struct bluetooth_sap_driver *sap,
@@ -102,6 +104,33 @@ void bluetooth_sap_client_unregister(struct ofono_modem *modem)
 	sap_hw_driver = NULL;
 }
 
+static gboolean bt_event_cb(GIOChannel *bt_io, GIOCondition condition,
+							gpointer data)
+{
+	struct ofono_modem *modem = data;
+	struct sap_data *sap_data = ofono_modem_get_data(modem);
+
+	if (condition & G_IO_IN) {
+		GIOStatus status;
+		gsize bytes_read;
+		gchar buf[300];
+
+		status = g_io_channel_read_chars(bt_io, buf, 300,
+							&bytes_read, NULL);
+
+		if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
+			return FALSE;
+
+		return TRUE;
+	}
+
+	ofono_modem_set_powered(modem, FALSE);
+
+	sap_data->bt_watch = 0;
+
+	return FALSE;
+}
+
 static int sap_probe(struct ofono_modem *modem)
 {
 	DBG("%p", modem);
@@ -117,8 +146,10 @@ static void sap_remove(struct ofono_modem *modem)
 static void sap_connect_reply(DBusPendingCall *call, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
+	struct sap_data *data = ofono_modem_get_data(modem);
 	DBusError derr;
-	DBusMessage *reply;
+	DBusMessage *reply, *msg;
+	int fd;
 
 	DBG("");
 
@@ -128,14 +159,44 @@ static void sap_connect_reply(DBusPendingCall *call, gpointer user_data)
 		goto done;
 
 	dbus_error_init(&derr);
-	if (!dbus_set_error_from_message(&derr, reply))
+	if (dbus_set_error_from_message(&derr, reply)) {
+
+		DBG("Connect reply: %s", derr.message);
+
+		if (dbus_error_has_name(&derr, DBUS_ERROR_NO_REPLY)) {
+			const char *str = "sap";
+
+			msg = dbus_message_new_method_call(BLUEZ_SERVICE,
+					data->server_path,
+					BLUEZ_SERIAL_INTERFACE, "Disconnect");
+			dbus_message_append_args(msg, DBUS_TYPE_STRING,
+					&str, DBUS_TYPE_INVALID);
+			if (msg == NULL)
+				ofono_error("Disconnect failed");
+			else
+				g_dbus_send_message(connection, msg);
+		}
+
+		ofono_modem_set_powered(modem, FALSE);
+
+		dbus_error_free(&derr);
 		goto done;
+	}
+
+	if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_UNIX_FD, &fd,
+				DBUS_TYPE_INVALID))
+		return;
 
-	DBG("Connect reply: %s", derr.message);
+	data->bt_io = g_io_channel_unix_new(fd);
+	if (data->bt_io == NULL)
+		return;
 
-	ofono_modem_set_powered(modem, FALSE);
+	g_io_channel_set_encoding(data->bt_io, NULL, NULL);
+	g_io_channel_set_buffered(data->bt_io, FALSE);
+	g_io_channel_set_close_on_unref(data->bt_io, TRUE);
 
-	dbus_error_free(&derr);
+	data->bt_watch = g_io_add_watch(data->bt_io, G_IO_HUP | G_IO_ERR
+				| G_IO_NVAL | G_IO_IN, bt_event_cb, modem);
 
 done:
 	dbus_message_unref(reply);
@@ -152,7 +213,7 @@ static int sap_enable(struct ofono_modem *modem)
 
 	status = bluetooth_send_with_reply(data->server_path,
 					BLUEZ_SERIAL_INTERFACE, "ConnectFD",
-					sap_connect_reply, modem, NULL,
+					NULL, sap_connect_reply, modem, NULL,
 					DBUS_TIMEOUT, DBUS_TYPE_STRING,
 					&str, DBUS_TYPE_INVALID);
 
-- 
1.7.6.2


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

* [PATCH -v3 07/23] sap: add support to open the channel for SAP data
  2011-09-26 17:26         ` [PATCH -v3 06/23] sap: add watch for the Bluetooth Link Gustavo F. Padovan
@ 2011-09-26 17:27           ` Gustavo F. Padovan
  2011-09-26 17:27             ` [PATCH -v3 08/23] sap: connect the hw and the bluetooth link Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/bluetooth.h |    1 +
 plugins/telit.c     |   28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 6cde7bc..341b108 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -46,6 +46,7 @@ struct bluetooth_profile {
 struct bluetooth_sap_driver {
 	const char *name;
 	int (*enable) (struct ofono_modem *modem);
+	int (*open) (struct ofono_modem *modem);
 };
 
 struct server;
diff --git a/plugins/telit.c b/plugins/telit.c
index 1f950aa..69f9eed 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -27,6 +27,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <string.h>
 
 #include <glib.h>
 #include <gatchat.h>
@@ -134,7 +137,31 @@ static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 		ofono_modem_set_powered(modem, FALSE);
 		return;
 	}
+}
+
+static int telit_sap_open(struct ofono_modem *modem)
+{
+	const char *device = "/dev/ttyUSB4";
+	struct termios ti;
+	int fd;
+
+	DBG("%s", device);
+
+	fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
+	if (fd < 0)
+		return -1;
+
+	/* Switch TTY to raw mode */
+	memset(&ti, 0, sizeof(ti));
+	cfmakeraw(&ti);
+
+	tcflush(fd, TCIOFLUSH);
+	if (tcsetattr(fd, TCSANOW, &ti) < 0) {
+		close(fd);
+		return -EBADF;
+	}
 
+	return fd;
 }
 
 static int telit_sap_enable(struct ofono_modem *modem)
@@ -162,6 +189,7 @@ static int telit_sap_enable(struct ofono_modem *modem)
 static struct bluetooth_sap_driver sap_driver = {
 	.name = "telit",
 	.enable = telit_sap_enable,
+	.open = telit_sap_open,
 };
 
 static int telit_probe(struct ofono_modem *modem)
-- 
1.7.6.2


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

* [PATCH -v3 08/23] sap: connect the hw and the bluetooth link
  2011-09-26 17:27           ` [PATCH -v3 07/23] sap: add support to open the channel for SAP data Gustavo F. Padovan
@ 2011-09-26 17:27             ` Gustavo F. Padovan
  2011-09-26 17:27               ` [PATCH -v3 09/23] telit: add telit_sap_disable() Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

data is now passed from one side to another
---
 plugins/sap.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 65 insertions(+), 1 deletions(-)

diff --git a/plugins/sap.c b/plugins/sap.c
index b620309..6181ac7 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -56,7 +56,9 @@ struct sap_data {
 	struct ofono_modem *hw_modem;
 	struct bluetooth_sap_driver *sap_driver;
 	GIOChannel *bt_io;
+	GIOChannel *hw_io;
 	guint bt_watch;
+	guint hw_watch;
 };
 
 int bluetooth_sap_client_register(struct bluetooth_sap_driver *sap,
@@ -112,12 +114,16 @@ static gboolean bt_event_cb(GIOChannel *bt_io, GIOCondition condition,
 
 	if (condition & G_IO_IN) {
 		GIOStatus status;
-		gsize bytes_read;
+		gsize bytes_read, bytes_written;
 		gchar buf[300];
 
 		status = g_io_channel_read_chars(bt_io, buf, 300,
 							&bytes_read, NULL);
 
+		if (bytes_read > 0)
+			g_io_channel_write_chars(sap_data->bt_io, buf,
+					bytes_read, &bytes_written, NULL);
+
 		if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
 			return FALSE;
 
@@ -131,6 +137,37 @@ static gboolean bt_event_cb(GIOChannel *bt_io, GIOCondition condition,
 	return FALSE;
 }
 
+static gboolean hw_event_cb(GIOChannel *hw_io, GIOCondition condition,
+							gpointer data)
+{
+	struct ofono_modem *modem = data;
+	struct sap_data *sap_data = ofono_modem_get_data(modem);
+
+	if (condition & G_IO_IN) {
+		GIOStatus status;
+		gsize bytes_read, bytes_written;
+		gchar buf[300];
+
+		status = g_io_channel_read_chars(hw_io, buf, 300,
+							&bytes_read, NULL);
+
+		if (bytes_read > 0)
+			g_io_channel_write_chars(sap_data->bt_io, buf,
+					bytes_read, &bytes_written, NULL);
+
+		if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
+			return FALSE;
+
+		return TRUE;
+	}
+
+	ofono_modem_set_powered(modem, FALSE);
+
+	sap_data->hw_watch = 0;
+
+	return FALSE;
+}
+
 static int sap_probe(struct ofono_modem *modem)
 {
 	DBG("%p", modem);
@@ -198,6 +235,33 @@ static void sap_connect_reply(DBusPendingCall *call, gpointer user_data)
 	data->bt_watch = g_io_add_watch(data->bt_io, G_IO_HUP | G_IO_ERR
 				| G_IO_NVAL | G_IO_IN, bt_event_cb, modem);
 
+	data->hw_modem = sap_hw_modem;
+	data->sap_driver = sap_hw_driver;
+
+	fd = data->sap_driver->open(data->hw_modem);
+	if (!fd)  {
+		g_io_channel_unref(data->bt_io);
+		return;
+	}
+
+	data->hw_io = g_io_channel_unix_new(fd);
+	if (data->hw_io == NULL) {
+		g_io_channel_unref(data->bt_io);
+		close(fd);
+		return;
+	}
+
+	g_io_channel_set_encoding(data->hw_io, NULL, NULL);
+	g_io_channel_set_buffered(data->hw_io, FALSE);
+	g_io_channel_set_close_on_unref(data->hw_io, TRUE);
+
+	data->hw_watch = g_io_add_watch(data->hw_io, G_IO_HUP | G_IO_ERR
+				| G_IO_NVAL | G_IO_IN, hw_event_cb, modem);
+
+	data->sap_driver->enable(data->hw_modem);
+
+	ofono_modem_set_powered(modem, TRUE);
+
 done:
 	dbus_message_unref(reply);
 }
-- 
1.7.6.2


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

* [PATCH -v3 09/23] telit: add telit_sap_disable()
  2011-09-26 17:27             ` [PATCH -v3 08/23] sap: connect the hw and the bluetooth link Gustavo F. Padovan
@ 2011-09-26 17:27               ` Gustavo F. Padovan
  2011-09-26 17:27                 ` [PATCH -v3 10/23] sap: add support to the disable the SAP client Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

Support to disable the SAP modem from the sap plugin
---
 plugins/bluetooth.h |    1 +
 plugins/telit.c     |   30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 341b108..8b4bfe2 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -46,6 +46,7 @@ struct bluetooth_profile {
 struct bluetooth_sap_driver {
 	const char *name;
 	int (*enable) (struct ofono_modem *modem);
+	int (*disable) (struct ofono_modem *modem);
 	int (*open) (struct ofono_modem *modem);
 };
 
diff --git a/plugins/telit.c b/plugins/telit.c
index 69f9eed..4626c4b 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -139,6 +139,20 @@ static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	}
 }
 
+static void rsen_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct telit_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	g_at_chat_unref(data->chat);
+	data->chat = NULL;
+
+	if (ok)
+		ofono_modem_set_powered(modem, FALSE);
+}
+
 static int telit_sap_open(struct ofono_modem *modem)
 {
 	const char *device = "/dev/ttyUSB4";
@@ -186,9 +200,25 @@ static int telit_sap_enable(struct ofono_modem *modem)
 	return -EINPROGRESS;
 }
 
+static int telit_sap_disable(struct ofono_modem *modem)
+{
+	struct telit_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	g_at_chat_cancel_all(data->chat);
+	g_at_chat_unregister_all(data->chat);
+
+	g_at_chat_send(data->chat, "AT#RSEN=0", rsen_prefix,
+				rsen_disable_cb, modem, NULL);
+
+	return 0;
+}
+
 static struct bluetooth_sap_driver sap_driver = {
 	.name = "telit",
 	.enable = telit_sap_enable,
+	.disable = telit_sap_disable,
 	.open = telit_sap_open,
 };
 
-- 
1.7.6.2


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

* [PATCH -v3 10/23] sap: add support to the disable the SAP client
  2011-09-26 17:27               ` [PATCH -v3 09/23] telit: add telit_sap_disable() Gustavo F. Padovan
@ 2011-09-26 17:27                 ` Gustavo F. Padovan
  2011-09-26 17:27                   ` [PATCH -v3 11/23] telit: add aux GAtChat Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/sap.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/plugins/sap.c b/plugins/sap.c
index 6181ac7..92e1a5e 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -289,8 +289,12 @@ static int sap_enable(struct ofono_modem *modem)
 
 static int sap_disable(struct ofono_modem *modem)
 {
+	struct sap_data *data = ofono_modem_get_data(modem);
+
 	DBG("%p", modem);
 
+	data->sap_driver->disable(data->hw_modem);
+
 	return 0;
 }
 
-- 
1.7.6.2


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

* [PATCH -v3 11/23] telit: add aux GAtChat
  2011-09-26 17:27                 ` [PATCH -v3 10/23] sap: add support to the disable the SAP client Gustavo F. Padovan
@ 2011-09-26 17:27                   ` Gustavo F. Padovan
  2011-09-26 17:27                     ` [PATCH -v3 12/23] sap: enable modem only when #RSEN is 1 Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/telit.c |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/plugins/telit.c b/plugins/telit.c
index 4626c4b..b6d408f 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -65,6 +65,7 @@ static const char *rsen_prefix[]= { "#RSEN:", NULL };
 
 struct telit_data {
 	GAtChat *chat;
+	GAtChat *aux;
 	struct ofono_sim *sim;
 	guint sim_inserted_source;
 };
@@ -132,8 +133,8 @@ static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	DBG("%p", modem);
 
 	if (!ok) {
-		g_at_chat_unref(data->chat);
-		data->chat = NULL;
+		g_at_chat_unref(data->aux);
+		data->aux = NULL;
 		ofono_modem_set_powered(modem, FALSE);
 		return;
 	}
@@ -146,8 +147,8 @@ static void rsen_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
 	DBG("%p", modem);
 
-	g_at_chat_unref(data->chat);
-	data->chat = NULL;
+	g_at_chat_unref(data->aux);
+	data->aux = NULL;
 
 	if (ok)
 		ofono_modem_set_powered(modem, FALSE);
@@ -184,17 +185,17 @@ static int telit_sap_enable(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
-	data->chat = open_device(modem, "Data", "Aux: ");
-	if (data->chat == NULL)
+	data->aux = open_device(modem, "Data", "Aux: ");
+	if (data->aux == NULL)
 		return -EINVAL;
 
-	g_at_chat_register(data->chat, "#RSEN:", telit_rsen_notify,
+	g_at_chat_register(data->aux, "#RSEN:", telit_rsen_notify,
 				FALSE, modem, NULL);
 
-	g_at_chat_send(data->chat, "AT#NOPT=3", NULL, NULL, NULL, NULL);
+	g_at_chat_send(data->aux, "AT#NOPT=3", NULL, NULL, NULL, NULL);
 
 	/* Set SAP functionality */
-	g_at_chat_send(data->chat, "AT#RSEN=1,1,0,2,0", rsen_prefix,
+	g_at_chat_send(data->aux, "AT#RSEN=1,1,0,2,0", rsen_prefix,
 				rsen_enable_cb, modem, NULL);
 
 	return -EINPROGRESS;
-- 
1.7.6.2


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

* [PATCH -v3 12/23] sap: enable modem only when #RSEN is 1
  2011-09-26 17:27                   ` [PATCH -v3 11/23] telit: add aux GAtChat Gustavo F. Padovan
@ 2011-09-26 17:27                     ` Gustavo F. Padovan
  2011-09-26 17:27                       ` [PATCH -v3 13/23] telit: enable the telit modem when SAP is enabled Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

Only put modem powered when Remote SAP Server is enabled
---
 plugins/bluetooth.h |    2 +-
 plugins/sap.c       |    4 +---
 plugins/telit.c     |   18 +++++++++++++++---
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 8b4bfe2..1a7d120 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -45,7 +45,7 @@ struct bluetooth_profile {
 
 struct bluetooth_sap_driver {
 	const char *name;
-	int (*enable) (struct ofono_modem *modem);
+	int (*enable) (struct ofono_modem *modem, struct ofono_modem *sap_modem);
 	int (*disable) (struct ofono_modem *modem);
 	int (*open) (struct ofono_modem *modem);
 };
diff --git a/plugins/sap.c b/plugins/sap.c
index 92e1a5e..2caa10b 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -258,9 +258,7 @@ static void sap_connect_reply(DBusPendingCall *call, gpointer user_data)
 	data->hw_watch = g_io_add_watch(data->hw_io, G_IO_HUP | G_IO_ERR
 				| G_IO_NVAL | G_IO_IN, hw_event_cb, modem);
 
-	data->sap_driver->enable(data->hw_modem);
-
-	ofono_modem_set_powered(modem, TRUE);
+	data->sap_driver->enable(data->hw_modem, modem);
 
 done:
 	dbus_message_unref(reply);
diff --git a/plugins/telit.c b/plugins/telit.c
index b6d408f..a89fce1 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -68,6 +68,7 @@ struct telit_data {
 	GAtChat *aux;
 	struct ofono_sim *sim;
 	guint sim_inserted_source;
+	struct ofono_modem *sap_modem;
 };
 
 static void telit_debug(const char *str, void *user_data)
@@ -112,6 +113,7 @@ static GAtChat *open_device(struct ofono_modem *modem,
 static void telit_rsen_notify(GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
+	struct telit_data *data = ofono_modem_get_data(modem);
 	int status;
 	GAtResultIter iter;
 
@@ -123,6 +125,13 @@ static void telit_rsen_notify(GAtResult *result, gpointer user_data)
 		return;
 
 	g_at_result_iter_next_number(&iter, &status);
+
+	if (status == 0) {
+		ofono_modem_set_powered(data->sap_modem, FALSE);
+		return;
+	}
+
+	ofono_modem_set_powered(data->sap_modem, TRUE);
 }
 
 static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
@@ -135,7 +144,7 @@ static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	if (!ok) {
 		g_at_chat_unref(data->aux);
 		data->aux = NULL;
-		ofono_modem_set_powered(modem, FALSE);
+		ofono_modem_set_powered(data->sap_modem, FALSE);
 		return;
 	}
 }
@@ -151,7 +160,7 @@ static void rsen_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	data->aux = NULL;
 
 	if (ok)
-		ofono_modem_set_powered(modem, FALSE);
+		ofono_modem_set_powered(data->sap_modem, FALSE);
 }
 
 static int telit_sap_open(struct ofono_modem *modem)
@@ -179,7 +188,8 @@ static int telit_sap_open(struct ofono_modem *modem)
 	return fd;
 }
 
-static int telit_sap_enable(struct ofono_modem *modem)
+static int telit_sap_enable(struct ofono_modem *modem,
+					struct ofono_modem *sap_modem)
 {
 	struct telit_data *data = ofono_modem_get_data(modem);
 
@@ -189,6 +199,8 @@ static int telit_sap_enable(struct ofono_modem *modem)
 	if (data->aux == NULL)
 		return -EINVAL;
 
+	data->sap_modem = sap_modem;
+
 	g_at_chat_register(data->aux, "#RSEN:", telit_rsen_notify,
 				FALSE, modem, NULL);
 
-- 
1.7.6.2


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

* [PATCH -v3 13/23] telit: enable the telit modem when SAP is enabled.
  2011-09-26 17:27                     ` [PATCH -v3 12/23] sap: enable modem only when #RSEN is 1 Gustavo F. Padovan
@ 2011-09-26 17:27                       ` Gustavo F. Padovan
  2011-09-26 17:27                         ` [PATCH -v3 14/23] sap: add pre_sim handling Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/telit.c |  265 ++++++++++++++++++++++++++++---------------------------
 1 files changed, 133 insertions(+), 132 deletions(-)

diff --git a/plugins/telit.c b/plugins/telit.c
index a89fce1..856230f 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -110,6 +110,137 @@ static GAtChat *open_device(struct ofono_modem *modem,
 	return chat;
 }
 
+static gboolean sim_inserted_timeout_cb(gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct telit_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	data->sim_inserted_source = 0;
+
+	ofono_sim_inserted_notify(data->sim, TRUE);
+
+	return FALSE;
+}
+
+static void switch_sim_state_status(struct ofono_modem *modem, int status)
+{
+	struct telit_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	switch (status) {
+	case 0:
+		DBG("SIM not inserted");
+		ofono_sim_inserted_notify(data->sim, FALSE);
+		break;
+	case 1:
+		DBG("SIM inserted");
+		/* We need to sleep a bit */
+		data->sim_inserted_source = g_timeout_add_seconds(1,
+							sim_inserted_timeout_cb,
+							modem);
+		break;
+	case 2:
+		DBG("SIM inserted and PIN unlocked");
+		break;
+	case 3:
+		DBG("SIM inserted and ready");
+		break;
+	}
+}
+
+static void telit_qss_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	int status;
+	GAtResultIter iter;
+
+	DBG("%p", modem);
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "#QSS:"))
+		return;
+
+	g_at_result_iter_next_number(&iter, &status);
+
+	switch_sim_state_status(modem, status);
+}
+
+static void telit_qss_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	int mode;
+	int status;
+	GAtResultIter iter;
+	g_at_result_iter_init(&iter, result);
+
+	DBG("%p", modem);
+
+	if (!g_at_result_iter_next(&iter, "#QSS:"))
+		return;
+
+	g_at_result_iter_next_number(&iter, &mode);
+	g_at_result_iter_next_number(&iter, &status);
+
+	switch_sim_state_status(modem, status);
+}
+
+static void cfun_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct telit_data *data = ofono_modem_get_data(modem);
+	struct ofono_modem *m = data->sap_modem ? : modem;
+
+	DBG("%p", modem);
+
+	if (!ok) {
+		g_at_chat_unref(data->chat);
+		data->chat = NULL;
+		ofono_modem_set_powered(m, FALSE);
+		return;
+	}
+
+	ofono_modem_set_powered(m, TRUE);
+
+	/* Enable sim state notification */
+	g_at_chat_send(data->chat, "AT#QSS=1", none_prefix, NULL, NULL, NULL);
+
+	/* Follow sim state */
+	g_at_chat_register(data->chat, "#QSS:", telit_qss_notify,
+				FALSE, modem, NULL);
+
+	/* Query current sim state */
+	g_at_chat_send(data->chat, "AT#QSS?", qss_prefix,
+				telit_qss_cb, modem, NULL);
+}
+
+static int telit_enable(struct ofono_modem *modem)
+{
+	struct telit_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	data->chat = open_device(modem, "Modem", "Modem: ");
+	if (data->chat == NULL)
+		return -EINVAL;
+
+	/*
+	 * Disable command echo and
+	 * enable the Extended Error Result Codes
+	 */
+	g_at_chat_send(data->chat, "ATE0 +CMEE=1", none_prefix,
+				NULL, NULL, NULL);
+
+	/* Set phone functionality */
+	g_at_chat_send(data->chat, "AT+CFUN=4", none_prefix,
+				cfun_enable_cb, modem, NULL);
+
+	return -EINPROGRESS;
+}
+
 static void telit_rsen_notify(GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -131,7 +262,7 @@ static void telit_rsen_notify(GAtResult *result, gpointer user_data)
 		return;
 	}
 
-	ofono_modem_set_powered(data->sap_modem, TRUE);
+	telit_enable(modem);
 }
 
 static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
@@ -204,7 +335,7 @@ static int telit_sap_enable(struct ofono_modem *modem,
 	g_at_chat_register(data->aux, "#RSEN:", telit_rsen_notify,
 				FALSE, modem, NULL);
 
-	g_at_chat_send(data->aux, "AT#NOPT=3", NULL, NULL, NULL, NULL);
+	g_at_chat_send(data->aux, "AT#NOPT=0", NULL, NULL, NULL, NULL);
 
 	/* Set SAP functionality */
 	g_at_chat_send(data->aux, "AT#RSEN=1,1,0,2,0", rsen_prefix,
@@ -268,112 +399,6 @@ static void telit_remove(struct ofono_modem *modem)
 	g_free(data);
 }
 
-static gboolean sim_inserted_timeout_cb(gpointer user_data)
-{
-	struct ofono_modem *modem = user_data;
-	struct telit_data *data = ofono_modem_get_data(modem);
-
-	DBG("%p", modem);
-
-	data->sim_inserted_source = 0;
-
-	ofono_sim_inserted_notify(data->sim, TRUE);
-
-	return FALSE;
-}
-
-static void switch_sim_state_status(struct ofono_modem *modem, int status)
-{
-	struct telit_data *data = ofono_modem_get_data(modem);
-
-	DBG("%p", modem);
-
-	switch (status) {
-	case 0:
-		DBG("SIM not inserted");
-		ofono_sim_inserted_notify(data->sim, FALSE);
-		break;
-	case 1:
-		DBG("SIM inserted");
-		/* We need to sleep a bit */
-		data->sim_inserted_source = g_timeout_add_seconds(1,
-							sim_inserted_timeout_cb,
-							modem);
-		break;
-	case 2:
-		DBG("SIM inserted and PIN unlocked");
-		break;
-	case 3:
-		DBG("SIM inserted and ready");
-		break;
-	}
-}
-
-static void telit_qss_notify(GAtResult *result, gpointer user_data)
-{
-	struct ofono_modem *modem = user_data;
-	int status;
-	GAtResultIter iter;
-
-	DBG("%p", modem);
-
-	g_at_result_iter_init(&iter, result);
-
-	if (!g_at_result_iter_next(&iter, "#QSS:"))
-		return;
-
-	g_at_result_iter_next_number(&iter, &status);
-
-	switch_sim_state_status(modem, status);
-}
-
-static void telit_qss_cb(gboolean ok, GAtResult *result, gpointer user_data)
-{
-	struct ofono_modem *modem = user_data;
-	int mode;
-	int status;
-	GAtResultIter iter;
-	g_at_result_iter_init(&iter, result);
-
-	DBG("%p", modem);
-
-	if (!g_at_result_iter_next(&iter, "#QSS:"))
-		return;
-
-	g_at_result_iter_next_number(&iter, &mode);
-	g_at_result_iter_next_number(&iter, &status);
-
-	switch_sim_state_status(modem, status);
-}
-
-static void cfun_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
-{
-	struct ofono_modem *modem = user_data;
-	struct telit_data *data = ofono_modem_get_data(modem);
-
-	DBG("%p", modem);
-
-	if (!ok) {
-		g_at_chat_unref(data->chat);
-		data->chat = NULL;
-		ofono_modem_set_powered(modem, FALSE);
-		return;
-	}
-
-	ofono_modem_set_powered(modem, TRUE);
-
-	/* Enable sim state notification */
-	g_at_chat_send(data->chat, "AT#QSS=1", none_prefix, NULL, NULL, NULL);
-
-	/* Follow sim state */
-	g_at_chat_register(data->chat, "#QSS:", telit_qss_notify,
-				FALSE, modem, NULL);
-
-	/* Query current sim state */
-	g_at_chat_send(data->chat, "AT#QSS?", qss_prefix,
-				telit_qss_cb, modem, NULL);
-}
-
 static void cfun_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -391,30 +416,6 @@ static void cfun_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 		ofono_modem_set_powered(modem, FALSE);
 }
 
-static int telit_enable(struct ofono_modem *modem)
-{
-	struct telit_data *data = ofono_modem_get_data(modem);
-
-	DBG("%p", modem);
-
-	data->chat = open_device(modem, "Modem", "Modem: ");
-	if (data->chat == NULL)
-		return -EINVAL;
-
-	/*
-	 * Disable command echo and
-	 * enable the Extended Error Result Codes
-	 */
-	g_at_chat_send(data->chat, "ATE0 +CMEE=1", none_prefix,
-				NULL, NULL, NULL);
-
-	/* Set phone functionality */
-	g_at_chat_send(data->chat, "AT+CFUN=4", none_prefix,
-				cfun_enable_cb, modem, NULL);
-
-	return -EINPROGRESS;
-}
-
 static int telit_disable(struct ofono_modem *modem)
 {
 	struct telit_data *data = ofono_modem_get_data(modem);
-- 
1.7.6.2


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

* [PATCH -v3 14/23] sap: add pre_sim handling
  2011-09-26 17:27                       ` [PATCH -v3 13/23] telit: enable the telit modem when SAP is enabled Gustavo F. Padovan
@ 2011-09-26 17:27                         ` Gustavo F. Padovan
  2011-09-26 17:27                           ` [PATCH -v3 15/23] sap: add set_online handling Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/bluetooth.h |    1 +
 plugins/sap.c       |    4 ++++
 plugins/telit.c     |   26 +++++++++++++++-----------
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 1a7d120..ab81592 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -46,6 +46,7 @@ struct bluetooth_profile {
 struct bluetooth_sap_driver {
 	const char *name;
 	int (*enable) (struct ofono_modem *modem, struct ofono_modem *sap_modem);
+	void (*pre_sim) (struct ofono_modem *modem);
 	int (*disable) (struct ofono_modem *modem);
 	int (*open) (struct ofono_modem *modem);
 };
diff --git a/plugins/sap.c b/plugins/sap.c
index 2caa10b..d9425d0 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -298,7 +298,11 @@ static int sap_disable(struct ofono_modem *modem)
 
 static void sap_pre_sim(struct ofono_modem *modem)
 {
+	struct sap_data *data = ofono_modem_get_data(modem);
+
 	DBG("%p", modem);
+
+	data->sap_driver->pre_sim(data->hw_modem);
 }
 
 static void sap_post_sim(struct ofono_modem *modem)
diff --git a/plugins/telit.c b/plugins/telit.c
index 856230f..c116606 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -359,9 +359,24 @@ static int telit_sap_disable(struct ofono_modem *modem)
 	return 0;
 }
 
+static void telit_pre_sim(struct ofono_modem *modem)
+{
+	struct telit_data *data = ofono_modem_get_data(modem);
+
+	if (data->sap_modem)
+		modem = data->sap_modem;
+
+	DBG("%p", modem);
+
+	ofono_devinfo_create(modem, 0, "atmodem", data->chat);
+	data->sim = ofono_sim_create(modem, 0, "atmodem", data->chat);
+	ofono_voicecall_create(modem, 0, "atmodem", data->chat);
+}
+
 static struct bluetooth_sap_driver sap_driver = {
 	.name = "telit",
 	.enable = telit_sap_enable,
+	.pre_sim = telit_pre_sim,
 	.disable = telit_sap_disable,
 	.open = telit_sap_open,
 };
@@ -454,17 +469,6 @@ static void telit_set_online(struct ofono_modem *modem, ofono_bool_t online,
 						cbd, g_free);
 }
 
-static void telit_pre_sim(struct ofono_modem *modem)
-{
-	struct telit_data *data = ofono_modem_get_data(modem);
-
-	DBG("%p", modem);
-
-	ofono_devinfo_create(modem, 0, "atmodem", data->chat);
-	data->sim = ofono_sim_create(modem, 0, "atmodem", data->chat);
-	ofono_voicecall_create(modem, 0, "atmodem", data->chat);
-}
-
 static void telit_post_sim(struct ofono_modem *modem)
 {
 	struct telit_data *data = ofono_modem_get_data(modem);
-- 
1.7.6.2


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

* [PATCH -v3 15/23] sap: add set_online handling
  2011-09-26 17:27                         ` [PATCH -v3 14/23] sap: add pre_sim handling Gustavo F. Padovan
@ 2011-09-26 17:27                           ` Gustavo F. Padovan
  2011-09-26 17:27                             ` [PATCH -v3 16/23] sap: add post_sim handling Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/bluetooth.h |    2 +
 plugins/sap.c       |   11 +++++++
 plugins/telit.c     |   83 +++++++++++++++------------------------------------
 3 files changed, 37 insertions(+), 59 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index ab81592..910f7d9 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -47,6 +47,8 @@ struct bluetooth_sap_driver {
 	const char *name;
 	int (*enable) (struct ofono_modem *modem, struct ofono_modem *sap_modem);
 	void (*pre_sim) (struct ofono_modem *modem);
+	void (*set_online) (struct ofono_modem *modem, ofono_bool_t online,
+				ofono_modem_online_cb_t cb, void *user_data);
 	int (*disable) (struct ofono_modem *modem);
 	int (*open) (struct ofono_modem *modem);
 };
diff --git a/plugins/sap.c b/plugins/sap.c
index d9425d0..69f25a7 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -310,6 +310,16 @@ static void sap_post_sim(struct ofono_modem *modem)
 	DBG("%p", modem);
 }
 
+static void sap_set_online(struct ofono_modem *modem, ofono_bool_t online,
+				ofono_modem_online_cb_t cb, void *user_data)
+{
+	struct sap_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	data->sap_driver->set_online(data->hw_modem, online, cb, user_data);
+}
+
 static int bluetooth_sap_probe(const char *device, const char *dev_addr,
 				const char *adapter_addr, const char *alias)
 {
@@ -403,6 +413,7 @@ static struct ofono_modem_driver sap_driver = {
 	.disable	= sap_disable,
 	.pre_sim	= sap_pre_sim,
 	.post_sim	= sap_post_sim,
+	.set_online	= sap_set_online,
 };
 
 static struct bluetooth_profile sap = {
diff --git a/plugins/telit.c b/plugins/telit.c
index c116606..1098420 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -373,10 +373,34 @@ static void telit_pre_sim(struct ofono_modem *modem)
 	ofono_voicecall_create(modem, 0, "atmodem", data->chat);
 }
 
+static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_modem_online_cb_t cb = cbd->cb;
+	struct ofono_error error;
+
+	decode_at_error(&error, g_at_result_final_response(result));
+	cb(&error, cbd->data);
+}
+
+static void telit_set_online(struct ofono_modem *modem, ofono_bool_t online,
+				ofono_modem_online_cb_t cb, void *user_data)
+{
+	struct telit_data *data = ofono_modem_get_data(modem);
+	struct cb_data *cbd = cb_data_new(cb, user_data);
+	char const *command = online ? "AT+CFUN=1" : "AT+CFUN=4";
+
+	DBG("modem %p %s", modem, online ? "online" : "offline");
+
+	g_at_chat_send(data->chat, command, none_prefix, set_online_cb,
+						cbd, g_free);
+}
+
 static struct bluetooth_sap_driver sap_driver = {
 	.name = "telit",
 	.enable = telit_sap_enable,
 	.pre_sim = telit_pre_sim,
+	.set_online = telit_set_online,
 	.disable = telit_sap_disable,
 	.open = telit_sap_open,
 };
@@ -446,65 +470,6 @@ static int telit_disable(struct ofono_modem *modem)
 	return -EINPROGRESS;
 }
 
-static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
-{
-	struct cb_data *cbd = user_data;
-	ofono_modem_online_cb_t cb = cbd->cb;
-	struct ofono_error error;
-
-	decode_at_error(&error, g_at_result_final_response(result));
-	cb(&error, cbd->data);
-}
-
-static void telit_set_online(struct ofono_modem *modem, ofono_bool_t online,
-				ofono_modem_online_cb_t cb, void *user_data)
-{
-	struct telit_data *data = ofono_modem_get_data(modem);
-	struct cb_data *cbd = cb_data_new(cb, user_data);
-	char const *command = online ? "AT+CFUN=1" : "AT+CFUN=4";
-
-	DBG("modem %p %s", modem, online ? "online" : "offline");
-
-	g_at_chat_send(data->chat, command, none_prefix, set_online_cb,
-						cbd, g_free);
-}
-
-static void telit_post_sim(struct ofono_modem *modem)
-{
-	struct telit_data *data = ofono_modem_get_data(modem);
-
-	DBG("%p", modem);
-
-	ofono_sms_create(modem, 0, "atmodem", data->chat);
-}
-
-static void telit_post_online(struct ofono_modem *modem)
-{
-	struct telit_data *data = ofono_modem_get_data(modem);
-	struct ofono_message_waiting *mw;
-	struct ofono_gprs *gprs;
-	struct ofono_gprs_context *gc;
-
-	DBG("%p", modem);
-
-	ofono_netreg_create(modem, OFONO_VENDOR_TELIT, "atmodem", data->chat);
-	ofono_ussd_create(modem, 0, "atmodem", data->chat);
-	ofono_call_forwarding_create(modem, 0, "atmodem", data->chat);
-	ofono_call_settings_create(modem, 0, "atmodem", data->chat);
-	ofono_call_meter_create(modem, 0, "atmodem", data->chat);
-	ofono_call_barring_create(modem, 0, "atmodem", data->chat);
-
-	gprs = ofono_gprs_create(modem, 0, "atmodem", data->chat);
-	gc = ofono_gprs_context_create(modem, 0, "atmodem", data->chat);
-
-	if (gprs && gc)
-		ofono_gprs_add_context(gprs, gc);
-
-	mw = ofono_message_waiting_create(modem);
-	if (mw)
-		ofono_message_waiting_register(mw);
-}
-
 static struct ofono_modem_driver telit_driver = {
 	.name		= "telit",
 	.probe		= telit_probe,
-- 
1.7.6.2


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

* [PATCH -v3 16/23] sap: add post_sim handling
  2011-09-26 17:27                           ` [PATCH -v3 15/23] sap: add set_online handling Gustavo F. Padovan
@ 2011-09-26 17:27                             ` Gustavo F. Padovan
  2011-09-26 17:27                               ` [PATCH -v3 17/23] sap: add post_online handling Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/bluetooth.h |    1 +
 plugins/sap.c       |    4 ++++
 plugins/telit.c     |   40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 910f7d9..7e33a4a 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -47,6 +47,7 @@ struct bluetooth_sap_driver {
 	const char *name;
 	int (*enable) (struct ofono_modem *modem, struct ofono_modem *sap_modem);
 	void (*pre_sim) (struct ofono_modem *modem);
+	void (*post_sim) (struct ofono_modem *modem);
 	void (*set_online) (struct ofono_modem *modem, ofono_bool_t online,
 				ofono_modem_online_cb_t cb, void *user_data);
 	int (*disable) (struct ofono_modem *modem);
diff --git a/plugins/sap.c b/plugins/sap.c
index 69f25a7..7aea2af 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -307,7 +307,11 @@ static void sap_pre_sim(struct ofono_modem *modem)
 
 static void sap_post_sim(struct ofono_modem *modem)
 {
+	struct sap_data *data = ofono_modem_get_data(modem);
+
 	DBG("%p", modem);
+
+	data->sap_driver->post_sim(data->hw_modem);
 }
 
 static void sap_set_online(struct ofono_modem *modem, ofono_bool_t online,
diff --git a/plugins/telit.c b/plugins/telit.c
index 1098420..7bdbd8c 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -373,6 +373,18 @@ static void telit_pre_sim(struct ofono_modem *modem)
 	ofono_voicecall_create(modem, 0, "atmodem", data->chat);
 }
 
+static void telit_post_sim(struct ofono_modem *modem)
+{
+	struct telit_data *data = ofono_modem_get_data(modem);
+
+	if (data->sap_modem)
+		modem = data->sap_modem;
+
+	DBG("%p", modem);
+
+	ofono_sms_create(modem, 0, "atmodem", data->chat);
+}
+
 static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct cb_data *cbd = user_data;
@@ -400,6 +412,7 @@ static struct bluetooth_sap_driver sap_driver = {
 	.name = "telit",
 	.enable = telit_sap_enable,
 	.pre_sim = telit_pre_sim,
+	.post_sim = telit_post_sim,
 	.set_online = telit_set_online,
 	.disable = telit_sap_disable,
 	.open = telit_sap_open,
@@ -470,6 +483,33 @@ static int telit_disable(struct ofono_modem *modem)
 	return -EINPROGRESS;
 }
 
+static void telit_post_online(struct ofono_modem *modem)
+{
+	struct telit_data *data = ofono_modem_get_data(modem);
+	struct ofono_message_waiting *mw;
+	struct ofono_gprs *gprs;
+	struct ofono_gprs_context *gc;
+
+	DBG("%p", modem);
+
+	ofono_netreg_create(modem, OFONO_VENDOR_TELIT, "atmodem", data->chat);
+	ofono_ussd_create(modem, 0, "atmodem", data->chat);
+	ofono_call_forwarding_create(modem, 0, "atmodem", data->chat);
+	ofono_call_settings_create(modem, 0, "atmodem", data->chat);
+	ofono_call_meter_create(modem, 0, "atmodem", data->chat);
+	ofono_call_barring_create(modem, 0, "atmodem", data->chat);
+
+	gprs = ofono_gprs_create(modem, 0, "atmodem", data->chat);
+	gc = ofono_gprs_context_create(modem, 0, "atmodem", data->chat);
+
+	if (gprs && gc)
+		ofono_gprs_add_context(gprs, gc);
+
+	mw = ofono_message_waiting_create(modem);
+	if (mw)
+		ofono_message_waiting_register(mw);
+}
+
 static struct ofono_modem_driver telit_driver = {
 	.name		= "telit",
 	.probe		= telit_probe,
-- 
1.7.6.2


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

* [PATCH -v3 17/23] sap: add post_online handling
  2011-09-26 17:27                             ` [PATCH -v3 16/23] sap: add post_sim handling Gustavo F. Padovan
@ 2011-09-26 17:27                               ` Gustavo F. Padovan
  2011-09-26 17:27                                 ` [PATCH -v3 18/23] telit: improve sap disable Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/bluetooth.h |    1 +
 plugins/sap.c       |   10 ++++++++
 plugins/telit.c     |   58 +++++++++++++++++++++++++++-----------------------
 3 files changed, 42 insertions(+), 27 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 7e33a4a..6564609 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -50,6 +50,7 @@ struct bluetooth_sap_driver {
 	void (*post_sim) (struct ofono_modem *modem);
 	void (*set_online) (struct ofono_modem *modem, ofono_bool_t online,
 				ofono_modem_online_cb_t cb, void *user_data);
+	void (*post_online) (struct ofono_modem *modem);
 	int (*disable) (struct ofono_modem *modem);
 	int (*open) (struct ofono_modem *modem);
 };
diff --git a/plugins/sap.c b/plugins/sap.c
index 7aea2af..e19361c 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -324,6 +324,15 @@ static void sap_set_online(struct ofono_modem *modem, ofono_bool_t online,
 	data->sap_driver->set_online(data->hw_modem, online, cb, user_data);
 }
 
+static void sap_post_online(struct ofono_modem *modem)
+{
+	struct sap_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	data->sap_driver->post_online(data->hw_modem);
+}
+
 static int bluetooth_sap_probe(const char *device, const char *dev_addr,
 				const char *adapter_addr, const char *alias)
 {
@@ -418,6 +427,7 @@ static struct ofono_modem_driver sap_driver = {
 	.pre_sim	= sap_pre_sim,
 	.post_sim	= sap_post_sim,
 	.set_online	= sap_set_online,
+	.post_online	= sap_post_online,
 };
 
 static struct bluetooth_profile sap = {
diff --git a/plugins/telit.c b/plugins/telit.c
index 7bdbd8c..5d72b79 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -408,12 +408,43 @@ static void telit_set_online(struct ofono_modem *modem, ofono_bool_t online,
 						cbd, g_free);
 }
 
+static void telit_post_online(struct ofono_modem *modem)
+{
+	struct telit_data *data = ofono_modem_get_data(modem);
+	struct ofono_message_waiting *mw;
+	struct ofono_gprs *gprs;
+	struct ofono_gprs_context *gc;
+
+	if(data->sap_modem)
+		modem = data->sap_modem;
+
+	DBG("%p", modem);
+
+	ofono_netreg_create(modem, OFONO_VENDOR_TELIT, "atmodem", data->chat);
+	ofono_ussd_create(modem, 0, "atmodem", data->chat);
+	ofono_call_forwarding_create(modem, 0, "atmodem", data->chat);
+	ofono_call_settings_create(modem, 0, "atmodem", data->chat);
+	ofono_call_meter_create(modem, 0, "atmodem", data->chat);
+	ofono_call_barring_create(modem, 0, "atmodem", data->chat);
+
+	gprs = ofono_gprs_create(modem, 0, "atmodem", data->chat);
+	gc = ofono_gprs_context_create(modem, 0, "atmodem", data->chat);
+
+	if (gprs && gc)
+		ofono_gprs_add_context(gprs, gc);
+
+	mw = ofono_message_waiting_create(modem);
+	if (mw)
+		ofono_message_waiting_register(mw);
+}
+
 static struct bluetooth_sap_driver sap_driver = {
 	.name = "telit",
 	.enable = telit_sap_enable,
 	.pre_sim = telit_pre_sim,
 	.post_sim = telit_post_sim,
 	.set_online = telit_set_online,
+	.post_online = telit_post_online,
 	.disable = telit_sap_disable,
 	.open = telit_sap_open,
 };
@@ -483,33 +514,6 @@ static int telit_disable(struct ofono_modem *modem)
 	return -EINPROGRESS;
 }
 
-static void telit_post_online(struct ofono_modem *modem)
-{
-	struct telit_data *data = ofono_modem_get_data(modem);
-	struct ofono_message_waiting *mw;
-	struct ofono_gprs *gprs;
-	struct ofono_gprs_context *gc;
-
-	DBG("%p", modem);
-
-	ofono_netreg_create(modem, OFONO_VENDOR_TELIT, "atmodem", data->chat);
-	ofono_ussd_create(modem, 0, "atmodem", data->chat);
-	ofono_call_forwarding_create(modem, 0, "atmodem", data->chat);
-	ofono_call_settings_create(modem, 0, "atmodem", data->chat);
-	ofono_call_meter_create(modem, 0, "atmodem", data->chat);
-	ofono_call_barring_create(modem, 0, "atmodem", data->chat);
-
-	gprs = ofono_gprs_create(modem, 0, "atmodem", data->chat);
-	gc = ofono_gprs_context_create(modem, 0, "atmodem", data->chat);
-
-	if (gprs && gc)
-		ofono_gprs_add_context(gprs, gc);
-
-	mw = ofono_message_waiting_create(modem);
-	if (mw)
-		ofono_message_waiting_register(mw);
-}
-
 static struct ofono_modem_driver telit_driver = {
 	.name		= "telit",
 	.probe		= telit_probe,
-- 
1.7.6.2


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

* [PATCH -v3 18/23] telit: improve sap disable
  2011-09-26 17:27                               ` [PATCH -v3 17/23] sap: add post_online handling Gustavo F. Padovan
@ 2011-09-26 17:27                                 ` Gustavo F. Padovan
  2011-09-26 17:27                                   ` [PATCH -v3 19/23] sap: disconnect link if enable() fails Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/telit.c |   78 +++++++++++++++++++++++++++++--------------------------
 1 files changed, 41 insertions(+), 37 deletions(-)

diff --git a/plugins/telit.c b/plugins/telit.c
index 5d72b79..47a82d9 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -280,6 +280,43 @@ static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	}
 }
 
+static void cfun_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct telit_data *data = ofono_modem_get_data(modem);
+
+	if(data->sap_modem)
+		modem = data->sap_modem;
+
+	DBG("%p", modem);
+
+	g_at_chat_unref(data->chat);
+	data->chat = NULL;
+
+	if (data->sim_inserted_source > 0)
+		g_source_remove(data->sim_inserted_source);
+
+	if (ok)
+		ofono_modem_set_powered(modem, FALSE);
+
+	data->sap_modem = NULL;
+}
+
+static int telit_disable(struct ofono_modem *modem)
+{
+	struct telit_data *data = ofono_modem_get_data(modem);
+	DBG("%p", modem);
+
+	g_at_chat_cancel_all(data->chat);
+	g_at_chat_unregister_all(data->chat);
+
+	/* Power down modem */
+	g_at_chat_send(data->chat, "AT+CFUN=0", none_prefix,
+				cfun_disable_cb, modem, NULL);
+
+	return -EINPROGRESS;
+}
+
 static void rsen_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -290,8 +327,7 @@ static void rsen_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	g_at_chat_unref(data->aux);
 	data->aux = NULL;
 
-	if (ok)
-		ofono_modem_set_powered(data->sap_modem, FALSE);
+	telit_disable(modem);
 }
 
 static int telit_sap_open(struct ofono_modem *modem)
@@ -350,10 +386,10 @@ static int telit_sap_disable(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
-	g_at_chat_cancel_all(data->chat);
-	g_at_chat_unregister_all(data->chat);
+	g_at_chat_cancel_all(data->aux);
+	g_at_chat_unregister_all(data->aux);
 
-	g_at_chat_send(data->chat, "AT#RSEN=0", rsen_prefix,
+	g_at_chat_send(data->aux, "AT#RSEN=0", rsen_prefix,
 				rsen_disable_cb, modem, NULL);
 
 	return 0;
@@ -482,38 +518,6 @@ static void telit_remove(struct ofono_modem *modem)
 	g_free(data);
 }
 
-static void cfun_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
-{
-	struct ofono_modem *modem = user_data;
-	struct telit_data *data = ofono_modem_get_data(modem);
-
-	DBG("%p", modem);
-
-	g_at_chat_unref(data->chat);
-	data->chat = NULL;
-
-	if (data->sim_inserted_source > 0)
-		g_source_remove(data->sim_inserted_source);
-
-	if (ok)
-		ofono_modem_set_powered(modem, FALSE);
-}
-
-static int telit_disable(struct ofono_modem *modem)
-{
-	struct telit_data *data = ofono_modem_get_data(modem);
-	DBG("%p", modem);
-
-	g_at_chat_cancel_all(data->chat);
-	g_at_chat_unregister_all(data->chat);
-
-	/* Power down modem */
-	g_at_chat_send(data->chat, "AT+CFUN=0", none_prefix,
-				cfun_disable_cb, modem, NULL);
-
-	return -EINPROGRESS;
-}
-
 static struct ofono_modem_driver telit_driver = {
 	.name		= "telit",
 	.probe		= telit_probe,
-- 
1.7.6.2


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

* [PATCH -v3 19/23] sap: disconnect link if enable() fails
  2011-09-26 17:27                                 ` [PATCH -v3 18/23] telit: improve sap disable Gustavo F. Padovan
@ 2011-09-26 17:27                                   ` Gustavo F. Padovan
  2011-09-26 17:27                                     ` [PATCH -v3 20/23] sap: do a proper shutdown of the channels Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

We should disconnect the bluetooh link if sap_modem enabling fails.
---
 plugins/bluetooth.h |    5 ++++-
 plugins/sap.c       |    7 ++++++-
 plugins/telit.c     |    9 ++++++++-
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 6564609..81eed9d 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -43,9 +43,12 @@ struct bluetooth_profile {
 	void (*set_alias)(const char *device, const char *);
 };
 
+typedef void (*ConnectFailed)(struct ofono_modem *modem);
+
 struct bluetooth_sap_driver {
 	const char *name;
-	int (*enable) (struct ofono_modem *modem, struct ofono_modem *sap_modem);
+	int (*enable) (struct ofono_modem *modem, struct ofono_modem *sap_modem,
+							ConnectFailed cb);
 	void (*pre_sim) (struct ofono_modem *modem);
 	void (*post_sim) (struct ofono_modem *modem);
 	void (*set_online) (struct ofono_modem *modem, ofono_bool_t online,
diff --git a/plugins/sap.c b/plugins/sap.c
index e19361c..5b52d89 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -180,6 +180,11 @@ static void sap_remove(struct ofono_modem *modem)
 	DBG("%p", modem);
 }
 
+static void sap_failed_cb(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+}
+
 static void sap_connect_reply(DBusPendingCall *call, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -258,7 +263,7 @@ static void sap_connect_reply(DBusPendingCall *call, gpointer user_data)
 	data->hw_watch = g_io_add_watch(data->hw_io, G_IO_HUP | G_IO_ERR
 				| G_IO_NVAL | G_IO_IN, hw_event_cb, modem);
 
-	data->sap_driver->enable(data->hw_modem, modem);
+	data->sap_driver->enable(data->hw_modem, modem, sap_failed_cb);
 
 done:
 	dbus_message_unref(reply);
diff --git a/plugins/telit.c b/plugins/telit.c
index 47a82d9..0c8061f 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -69,6 +69,7 @@ struct telit_data {
 	struct ofono_sim *sim;
 	guint sim_inserted_source;
 	struct ofono_modem *sap_modem;
+	ConnectFailed cb;
 };
 
 static void telit_debug(const char *str, void *user_data)
@@ -200,6 +201,7 @@ static void cfun_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 		g_at_chat_unref(data->chat);
 		data->chat = NULL;
 		ofono_modem_set_powered(m, FALSE);
+		data->cb(data->sap_modem);
 		return;
 	}
 
@@ -259,6 +261,7 @@ static void telit_rsen_notify(GAtResult *result, gpointer user_data)
 
 	if (status == 0) {
 		ofono_modem_set_powered(data->sap_modem, FALSE);
+		data->cb(data->sap_modem);
 		return;
 	}
 
@@ -276,6 +279,7 @@ static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
 		g_at_chat_unref(data->aux);
 		data->aux = NULL;
 		ofono_modem_set_powered(data->sap_modem, FALSE);
+		data->cb(data->sap_modem);
 		return;
 	}
 }
@@ -356,7 +360,8 @@ static int telit_sap_open(struct ofono_modem *modem)
 }
 
 static int telit_sap_enable(struct ofono_modem *modem,
-					struct ofono_modem *sap_modem)
+					struct ofono_modem *sap_modem,
+					ConnectFailed cb)
 {
 	struct telit_data *data = ofono_modem_get_data(modem);
 
@@ -368,6 +373,8 @@ static int telit_sap_enable(struct ofono_modem *modem,
 
 	data->sap_modem = sap_modem;
 
+	data->cb = cb;
+
 	g_at_chat_register(data->aux, "#RSEN:", telit_rsen_notify,
 				FALSE, modem, NULL);
 
-- 
1.7.6.2


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

* [PATCH -v3 20/23] sap: do a proper shutdown of the channels
  2011-09-26 17:27                                   ` [PATCH -v3 19/23] sap: disconnect link if enable() fails Gustavo F. Padovan
@ 2011-09-26 17:27                                     ` Gustavo F. Padovan
  2011-09-26 17:27                                       ` [PATCH -v3 21/23] sap: retrigger bluetooth GetProperties call Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/sap.c |   39 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/plugins/sap.c b/plugins/sap.c
index 5b52d89..222b98e 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
+#include <sys/socket.h>
 #include <glib.h>
 #include <gdbus.h>
 #include <ofono.h>
@@ -73,10 +74,40 @@ int bluetooth_sap_client_register(struct bluetooth_sap_driver *sap,
 	return 0;
 }
 
+static void sap_close_io(struct ofono_modem *modem)
+{
+	struct sap_data *data = ofono_modem_get_data(modem);
+
+	if (data->bt_io != NULL) {
+		int sk = g_io_channel_unix_get_fd(data->bt_io);
+		shutdown(sk, SHUT_RDWR);
+
+		g_io_channel_unref(data->bt_io);
+		data->bt_io = NULL;
+	}
+
+	if (data->bt_watch > 0) {
+		g_source_remove(data->bt_watch);
+		data->bt_watch = 0;
+	}
+
+	if (data->hw_io != NULL) {
+		g_io_channel_unref(data->hw_io);
+		data->hw_io = NULL;
+	}
+
+	if (data->hw_watch > 0) {
+		g_source_remove(data->hw_watch);
+		data->hw_watch = 0;
+	}
+}
+
 static void sap_remove_modem(struct ofono_modem *modem)
 {
 	struct sap_data *data = ofono_modem_get_data(modem);
 
+	sap_close_io(modem);
+
 	g_free(data->server_path);
 	g_free(data);
 
@@ -183,6 +214,8 @@ static void sap_remove(struct ofono_modem *modem)
 static void sap_failed_cb(struct ofono_modem *modem)
 {
 	DBG("%p", modem);
+
+	sap_close_io(modem);
 }
 
 static void sap_connect_reply(DBusPendingCall *call, gpointer user_data)
@@ -245,13 +278,13 @@ static void sap_connect_reply(DBusPendingCall *call, gpointer user_data)
 
 	fd = data->sap_driver->open(data->hw_modem);
 	if (!fd)  {
-		g_io_channel_unref(data->bt_io);
+		sap_close_io(modem);
 		return;
 	}
 
 	data->hw_io = g_io_channel_unix_new(fd);
 	if (data->hw_io == NULL) {
-		g_io_channel_unref(data->bt_io);
+		sap_close_io(modem);
 		close(fd);
 		return;
 	}
@@ -296,6 +329,8 @@ static int sap_disable(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
+	sap_close_io(modem);
+
 	data->sap_driver->disable(data->hw_modem);
 
 	return 0;
-- 
1.7.6.2


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

* [PATCH -v3 21/23] sap: retrigger bluetooth GetProperties call
  2011-09-26 17:27                                     ` [PATCH -v3 20/23] sap: do a proper shutdown of the channels Gustavo F. Padovan
@ 2011-09-26 17:27                                       ` Gustavo F. Padovan
  2011-09-26 17:27                                         ` [PATCH -v3 22/23] telit: add needed flags to proper connect the serial port Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

When plugging a SAP capable modem, GetProperties need to be called again
to fetch the SAP Server devices from BlueZ.
---
 plugins/bluetooth.c |    6 ++++++
 plugins/bluetooth.h |    1 +
 plugins/sap.c       |    2 ++
 3 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 274d25b..573c7c8 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -900,6 +900,12 @@ static void bluetooth_unref(void)
 	g_hash_table_destroy(adapter_address_hash);
 }
 
+void bluetooth_get_properties()
+{
+	g_hash_table_foreach(adapter_address_hash,
+				(GHFunc) get_adapter_properties, NULL);
+}
+
 int bluetooth_register_uuid(const char *uuid, struct bluetooth_profile *profile)
 {
 	bluetooth_ref();
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 81eed9d..c723b6e 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -62,6 +62,7 @@ struct server;
 
 typedef void (*ConnectFunc)(GIOChannel *io, GError *err, gpointer user_data);
 
+void bluetooth_get_properties();
 int bluetooth_register_uuid(const char *uuid,
 				struct bluetooth_profile *profile);
 void bluetooth_unregister_uuid(const char *uuid);
diff --git a/plugins/sap.c b/plugins/sap.c
index 222b98e..d69ba6d 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -71,6 +71,8 @@ int bluetooth_sap_client_register(struct bluetooth_sap_driver *sap,
 	sap_hw_modem = modem;
 	sap_hw_driver = sap;
 
+	bluetooth_get_properties();
+
 	return 0;
 }
 
-- 
1.7.6.2


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

* [PATCH -v3 22/23] telit: add needed flags to proper connect the serial port
  2011-09-26 17:27                                       ` [PATCH -v3 21/23] sap: retrigger bluetooth GetProperties call Gustavo F. Padovan
@ 2011-09-26 17:27                                         ` Gustavo F. Padovan
  2011-09-26 17:27                                           ` [PATCH -v3 23/23] sap: de-register DBus callback if BlueZ goes down Gustavo F. Padovan
  0 siblings, 1 reply; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/telit.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/plugins/telit.c b/plugins/telit.c
index 0c8061f..467a7b6 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -350,6 +350,8 @@ static int telit_sap_open(struct ofono_modem *modem)
 	memset(&ti, 0, sizeof(ti));
 	cfmakeraw(&ti);
 
+	ti.c_cflag |= (B115200 | CLOCAL | CREAD);
+
 	tcflush(fd, TCIOFLUSH);
 	if (tcsetattr(fd, TCSANOW, &ti) < 0) {
 		close(fd);
-- 
1.7.6.2


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

* [PATCH -v3 23/23] sap: de-register DBus callback if BlueZ goes down
  2011-09-26 17:27                                         ` [PATCH -v3 22/23] telit: add needed flags to proper connect the serial port Gustavo F. Padovan
@ 2011-09-26 17:27                                           ` Gustavo F. Padovan
  0 siblings, 0 replies; 27+ messages in thread
From: Gustavo F. Padovan @ 2011-09-26 17:27 UTC (permalink / raw)
  To: ofono

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

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

---
 plugins/sap.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/plugins/sap.c b/plugins/sap.c
index d69ba6d..b6643d8 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -60,6 +60,7 @@ struct sap_data {
 	GIOChannel *hw_io;
 	guint bt_watch;
 	guint hw_watch;
+	DBusPendingCall *call;
 };
 
 int bluetooth_sap_client_register(struct bluetooth_sap_driver *sap,
@@ -110,6 +111,9 @@ static void sap_remove_modem(struct ofono_modem *modem)
 
 	sap_close_io(modem);
 
+	if (data->call != NULL)
+		dbus_pending_call_cancel(data->call);
+
 	g_free(data->server_path);
 	g_free(data);
 
@@ -232,6 +236,8 @@ static void sap_connect_reply(DBusPendingCall *call, gpointer user_data)
 
 	reply = dbus_pending_call_steal_reply(call);
 
+	data->call = NULL;
+
 	if (ofono_modem_get_powered(modem))
 		goto done;
 
@@ -308,6 +314,7 @@ done:
 static int sap_enable(struct ofono_modem *modem)
 {
 	struct sap_data *data = ofono_modem_get_data(modem);
+	DBusPendingCall *call;
 	int status;
 	const char *str = "sap";
 
@@ -315,13 +322,15 @@ static int sap_enable(struct ofono_modem *modem)
 
 	status = bluetooth_send_with_reply(data->server_path,
 					BLUEZ_SERIAL_INTERFACE, "ConnectFD",
-					NULL, sap_connect_reply, modem, NULL,
+					&call, sap_connect_reply, modem, NULL,
 					DBUS_TIMEOUT, DBUS_TYPE_STRING,
 					&str, DBUS_TYPE_INVALID);
 
 	if (status < 0)
 		return -EINVAL;
 
+	data->call = call;
+
 	return -EINPROGRESS;
 }
 
-- 
1.7.6.2


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

* Re: [PATCH -v3 02/23] sap: Add basic sap plugin
  2011-09-26 17:26 ` [PATCH -v3 02/23] sap: Add basic sap plugin Gustavo F. Padovan
  2011-09-26 17:26   ` [PATCH -v3 03/23] telit: add support to enable SAP client Gustavo F. Padovan
@ 2011-09-26 18:55   ` Denis Kenzior
  1 sibling, 0 replies; 27+ messages in thread
From: Denis Kenzior @ 2011-09-26 18:55 UTC (permalink / raw)
  To: ofono

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

Hi Gustavo,

On 09/26/2011 12:26 PM, Gustavo F. Padovan wrote:
> From: "Gustavo F. Padovan" <padovan@profusion.mobi>
> 
> ---
>  Makefile.am         |    3 +
>  plugins/bluetooth.c |    1 -
>  plugins/bluetooth.h |   12 ++
>  plugins/hfp_hf.c    |    2 -
>  plugins/sap.c       |  277 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  plugins/telit.c     |   10 ++
>  6 files changed, 302 insertions(+), 3 deletions(-)
>  create mode 100644 plugins/sap.c
> 

Patch has been applied, thanks.

Regards,
-Denis

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

* Re: [PATCH -v3 03/23] telit: add support to enable SAP client
  2011-09-26 17:26   ` [PATCH -v3 03/23] telit: add support to enable SAP client Gustavo F. Padovan
  2011-09-26 17:26     ` [PATCH -v3 04/23] sap: add support to connect the RFCOMM link Gustavo F. Padovan
@ 2011-09-26 18:56     ` Denis Kenzior
  1 sibling, 0 replies; 27+ messages in thread
From: Denis Kenzior @ 2011-09-26 18:56 UTC (permalink / raw)
  To: ofono

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

Hi Gustavo,

On 09/26/2011 12:26 PM, Gustavo F. Padovan wrote:
> From: "Gustavo F. Padovan" <padovan@profusion.mobi>
> 
> ---
>  plugins/bluetooth.h |    1 +
>  plugins/sap.c       |    4 +-
>  plugins/telit.c     |  109 ++++++++++++++++++++++++++++++++++-----------------
>  3 files changed, 76 insertions(+), 38 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis

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

* Re: [PATCH -v3 04/23] sap: add support to connect the RFCOMM link
  2011-09-26 17:26     ` [PATCH -v3 04/23] sap: add support to connect the RFCOMM link Gustavo F. Padovan
  2011-09-26 17:26       ` [PATCH -v3 05/23] telit: add #RSEN notify Gustavo F. Padovan
@ 2011-09-26 18:57       ` Denis Kenzior
  1 sibling, 0 replies; 27+ messages in thread
From: Denis Kenzior @ 2011-09-26 18:57 UTC (permalink / raw)
  To: ofono

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

On 09/26/2011 12:26 PM, Gustavo F. Padovan wrote:
> From: "Gustavo F. Padovan" <padovan@profusion.mobi>
> 
> ---
>  plugins/sap.c |   45 ++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 44 insertions(+), 1 deletions(-)
> 

Patch applied, but...

>  /* power up hardware */
>  static int sap_enable(struct ofono_modem *modem)
>  {
>  	struct sap_data *data = ofono_modem_get_data(modem);
> +	int status;
> +	const char *str = "sap";
> +
> +	DBG("%p", modem);
> +
> +	status = bluetooth_send_with_reply(data->server_path,
> +					BLUEZ_SERIAL_INTERFACE, "ConnectFD",
> +					sap_connect_reply, modem, NULL,
> +					DBUS_TIMEOUT, DBUS_TYPE_STRING,
> +					&str, DBUS_TYPE_INVALID);

I had to amend this part for it to compile

Regards,
-Denis

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

* Re: [PATCH -v3 05/23] telit: add #RSEN notify
  2011-09-26 17:26       ` [PATCH -v3 05/23] telit: add #RSEN notify Gustavo F. Padovan
  2011-09-26 17:26         ` [PATCH -v3 06/23] sap: add watch for the Bluetooth Link Gustavo F. Padovan
@ 2011-09-26 18:57         ` Denis Kenzior
  1 sibling, 0 replies; 27+ messages in thread
From: Denis Kenzior @ 2011-09-26 18:57 UTC (permalink / raw)
  To: ofono

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

Hi Gustavo,

On 09/26/2011 12:26 PM, Gustavo F. Padovan wrote:
> From: "Gustavo F. Padovan" <padovan@profusion.mobi>
> 
> RSEN URC tells if the SAP Client was enabled or not
> ---
>  plugins/telit.c |   19 +++++++++++++++++++
>  1 files changed, 19 insertions(+), 0 deletions(-)
> 

Patch has been applied, thanks.

Regards,
-Denis

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

end of thread, other threads:[~2011-09-26 18:57 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-26 17:26 [PATCH -v3 01/23] udevng: look also to VID Gustavo F. Padovan
2011-09-26 17:26 ` [PATCH -v3 02/23] sap: Add basic sap plugin Gustavo F. Padovan
2011-09-26 17:26   ` [PATCH -v3 03/23] telit: add support to enable SAP client Gustavo F. Padovan
2011-09-26 17:26     ` [PATCH -v3 04/23] sap: add support to connect the RFCOMM link Gustavo F. Padovan
2011-09-26 17:26       ` [PATCH -v3 05/23] telit: add #RSEN notify Gustavo F. Padovan
2011-09-26 17:26         ` [PATCH -v3 06/23] sap: add watch for the Bluetooth Link Gustavo F. Padovan
2011-09-26 17:27           ` [PATCH -v3 07/23] sap: add support to open the channel for SAP data Gustavo F. Padovan
2011-09-26 17:27             ` [PATCH -v3 08/23] sap: connect the hw and the bluetooth link Gustavo F. Padovan
2011-09-26 17:27               ` [PATCH -v3 09/23] telit: add telit_sap_disable() Gustavo F. Padovan
2011-09-26 17:27                 ` [PATCH -v3 10/23] sap: add support to the disable the SAP client Gustavo F. Padovan
2011-09-26 17:27                   ` [PATCH -v3 11/23] telit: add aux GAtChat Gustavo F. Padovan
2011-09-26 17:27                     ` [PATCH -v3 12/23] sap: enable modem only when #RSEN is 1 Gustavo F. Padovan
2011-09-26 17:27                       ` [PATCH -v3 13/23] telit: enable the telit modem when SAP is enabled Gustavo F. Padovan
2011-09-26 17:27                         ` [PATCH -v3 14/23] sap: add pre_sim handling Gustavo F. Padovan
2011-09-26 17:27                           ` [PATCH -v3 15/23] sap: add set_online handling Gustavo F. Padovan
2011-09-26 17:27                             ` [PATCH -v3 16/23] sap: add post_sim handling Gustavo F. Padovan
2011-09-26 17:27                               ` [PATCH -v3 17/23] sap: add post_online handling Gustavo F. Padovan
2011-09-26 17:27                                 ` [PATCH -v3 18/23] telit: improve sap disable Gustavo F. Padovan
2011-09-26 17:27                                   ` [PATCH -v3 19/23] sap: disconnect link if enable() fails Gustavo F. Padovan
2011-09-26 17:27                                     ` [PATCH -v3 20/23] sap: do a proper shutdown of the channels Gustavo F. Padovan
2011-09-26 17:27                                       ` [PATCH -v3 21/23] sap: retrigger bluetooth GetProperties call Gustavo F. Padovan
2011-09-26 17:27                                         ` [PATCH -v3 22/23] telit: add needed flags to proper connect the serial port Gustavo F. Padovan
2011-09-26 17:27                                           ` [PATCH -v3 23/23] sap: de-register DBus callback if BlueZ goes down Gustavo F. Padovan
2011-09-26 18:57         ` [PATCH -v3 05/23] telit: add #RSEN notify Denis Kenzior
2011-09-26 18:57       ` [PATCH -v3 04/23] sap: add support to connect the RFCOMM link Denis Kenzior
2011-09-26 18:56     ` [PATCH -v3 03/23] telit: add support to enable SAP client Denis Kenzior
2011-09-26 18:55   ` [PATCH -v3 02/23] sap: Add basic sap plugin Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.