All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] reopen data device once if open data device failed
@ 2011-05-11  2:25 Caiwen Zhang
  2011-05-11  2:41 ` Marcel Holtmann
  0 siblings, 1 reply; 6+ messages in thread
From: Caiwen Zhang @ 2011-05-11  2:25 UTC (permalink / raw)
  To: ofono

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

Sometimes when open the data device, it may fail. If open the data device
failed, retry once one second later.

---
 plugins/huawei.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/plugins/huawei.c b/plugins/huawei.c
index e791718..b888b0f 100644
--- a/plugins/huawei.c
+++ b/plugins/huawei.c
@@ -51,6 +51,7 @@
 #include <ofono/phonebook.h>
 #include <ofono/message-waiting.h>
 #include <ofono/log.h>
+#include <ofono.h>
 
 #include <drivers/atmodem/atutil.h>
 #include <drivers/atmodem/vendor.h>
@@ -80,6 +81,8 @@ struct huawei_data {
 	gboolean ndis;
 	guint sim_poll_timeout;
 	guint sim_poll_count;
+	guint reopen_source;
+	ofono_bool_t online;
 };
 
 #define MAX_SIM_POLL_COUNT 5
@@ -107,6 +110,11 @@ static void huawei_remove(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
+	if (data->reopen_source > 0) {
+		g_source_remove(data->reopen_source);
+		data->reopen_source = 0;
+	}
+
 	ofono_modem_set_data(modem, NULL);
 
 	if (data->modem)
@@ -465,6 +473,14 @@ static GAtChat *open_device(struct ofono_modem *modem,
 	return chat;
 }
 
+static void huawei_disconnect(gpointer user_data);
+
+static gboolean reopen_callback(gpointer user_data)
+{
+	huawei_disconnect(user_data);
+	return FALSE;
+}
+
 static void huawei_disconnect(gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -476,15 +492,26 @@ static void huawei_disconnect(gpointer user_data)
 	data->modem = NULL;
 
 	data->modem = open_device(modem, "Modem", "Modem: ");
-	if (data->modem == NULL)
+	/* retry once if failed */
+	if (data->modem == NULL && data->reopen_source == 0) {
+		data->reopen_source =
+			g_timeout_add_seconds(1, reopen_callback, modem);
+
+		ofono_debug("open device failed, try to reopen it.");
 		return;
+	}
+
+	if (data->reopen_source > 0)
+		data->reopen_source = 0;
 
 	g_at_chat_set_disconnect_function(data->modem,
 						huawei_disconnect, modem);
 
-	/* gprs_context has been destructed and needs not reopen */
-	if (data->gc == NULL)
-		return;
+	/* gprs_context has been destructed, if offline needs not recreate.
+	    if device is online, need recreate.
+	 */
+	 if (data->gc == NULL && data->online == FALSE)
+		return;
 
 	ofono_gprs_context_remove(data->gc);
 
@@ -492,6 +519,13 @@ static void huawei_disconnect(gpointer user_data)
 			data->sim_state == HUAWEI_SIM_STATE_INVALID_CS) {
 		ofono_info("Reopened GPRS context channel");
 
+		if (__ofono_modem_find_atom(modem,
+				OFONO_ATOM_TYPE_GPRS) == NULL) {
+			data->gprs = ofono_gprs_create(modem,
+					OFONO_VENDOR_HUAWEI,
+					"atmodem", data->pcui);
+		}
+
 		data->gc = ofono_gprs_context_create(modem, 0, "atmodem",
 								data->modem);
 
@@ -559,6 +593,11 @@ static int huawei_disable(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
+	if (data->reopen_source > 0) {
+		g_source_remove(data->reopen_source);
+		data->reopen_source = 0;
+	}
+
 	if (data->sim_poll_timeout > 0) {
 		g_source_remove(data->sim_poll_timeout);
 		data->sim_poll_timeout = 0;
@@ -588,6 +627,12 @@ static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	ofono_modem_online_cb_t cb = cbd->cb;
 	struct ofono_error error;
 
+	if (ok) {
+		struct huawei_data *data = cbd->user;
+
+		data->online = TRUE;
+	}
+
 	decode_at_error(&error, g_at_result_final_response(result));
 	cb(&error, cbd->data);
 }
@@ -603,6 +648,7 @@ static void set_offline_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
 		data->gc = NULL;
 		data->gprs = NULL;
+		data->online = FALSE;
 	}
 
 	decode_at_error(&error, g_at_result_final_response(result));
-- 
1.7.5


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

end of thread, other threads:[~2011-05-11 16:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-11  2:25 [PATCH] reopen data device once if open data device failed Caiwen Zhang
2011-05-11  2:41 ` Marcel Holtmann
2011-05-11  3:41   ` Zhang, Caiwen
2011-05-11  3:45     ` Denis Kenzior
2011-05-11  5:49       ` Zhang, Caiwen
2011-05-11 16:21         ` 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.