summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaiwen Zhang <caiwen.zhang@windriver.com>2011-06-03 17:00:10 +0800
committerDenis Kenzior <denkenz@gmail.com>2011-06-02 15:59:03 -0500
commitafc894e6b47f590cd6a242e5882174c44bc434ff (patch)
treed734c704fabd3d9fb558f64400f98d24f12af27e
parent3c82e9b9ccbee8a74f0f6feade12215be684fd9c (diff)
downloadofono-afc894e6b47f590cd6a242e5882174c44bc434ff.tar.bz2
huawei: reopen once if open device failed
Sometimes when we try to open the modem (PPP) device, it may fail. If opening the tty failed, retry once one second later.
-rw-r--r--plugins/huawei.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/plugins/huawei.c b/plugins/huawei.c
index 26621d25..c80593e6 100644
--- a/plugins/huawei.c
+++ b/plugins/huawei.c
@@ -80,6 +80,7 @@ struct huawei_data {
gboolean ndis;
guint sim_poll_timeout;
guint sim_poll_count;
+ guint reopen_timeout;
};
#define MAX_SIM_POLL_COUNT 5
@@ -107,6 +108,11 @@ static void huawei_remove(struct ofono_modem *modem)
DBG("%p", modem);
+ if (data->reopen_timeout > 0) {
+ g_source_remove(data->reopen_timeout);
+ data->reopen_timeout = 0;
+ }
+
ofono_modem_set_data(modem, NULL);
if (data->modem)
@@ -465,6 +471,20 @@ static GAtChat *open_device(struct ofono_modem *modem,
return chat;
}
+static void huawei_disconnect(gpointer user_data);
+
+static gboolean reopen_callback(gpointer user_data)
+{
+ struct ofono_modem *modem = user_data;
+ struct huawei_data *data = ofono_modem_get_data(modem);
+
+ huawei_disconnect(user_data);
+
+ data->reopen_timeout = 0;
+
+ return FALSE;
+}
+
static void huawei_disconnect(gpointer user_data)
{
struct ofono_modem *modem = user_data;
@@ -476,8 +496,17 @@ 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) {
+ if (data->reopen_timeout > 0)
+ return;
+
+ data->reopen_timeout = g_timeout_add_seconds(1,
+ reopen_callback, modem);
+
+ ofono_debug("open device failed, try to reopen it.");
return;
+ }
g_at_chat_set_disconnect_function(data->modem,
huawei_disconnect, modem);
@@ -559,6 +588,11 @@ static int huawei_disable(struct ofono_modem *modem)
DBG("%p", modem);
+ if (data->reopen_timeout > 0) {
+ g_source_remove(data->reopen_timeout);
+ data->reopen_timeout = 0;
+ }
+
if (data->sim_poll_timeout > 0) {
g_source_remove(data->sim_poll_timeout);
data->sim_poll_timeout = 0;