From 357499597ef8b65633c8aa6d903dde3abf121650 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 27 Jul 2011 16:29:52 +0200 Subject: [PATCH] gobi: Add timeout for modem enabling handling Some GOBI cards stop responding to AT commands when RFKILL has been enabled. In that case just timeout after 5 seconds. --- plugins/gobi.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/plugins/gobi.c b/plugins/gobi.c index f31e0cd9..a234f4e0 100644 --- a/plugins/gobi.c +++ b/plugins/gobi.c @@ -52,6 +52,7 @@ struct gobi_data { GAtChat *chat; struct ofono_sim *sim; gboolean have_sim; + guint cfun_timeout; }; static void gobi_debug(const char *str, void *user_data) @@ -165,11 +166,16 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data) DBG(""); + if (data->cfun_timeout > 0) { + g_source_remove(data->cfun_timeout); + data->cfun_timeout = 0; + } + if (!ok) { g_at_chat_unref(data->chat); data->chat = NULL; - ofono_modem_set_powered(modem, ok); + ofono_modem_set_powered(modem, FALSE); return; } @@ -184,7 +190,24 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data) g_at_chat_send(data->chat, "AT$QCSIMSTAT?", none_prefix, NULL, NULL, NULL); - ofono_modem_set_powered(modem, ok); + ofono_modem_set_powered(modem, TRUE); +} + +static gboolean cfun_timeout(gpointer user_data) +{ + struct ofono_modem *modem = user_data; + struct gobi_data *data = ofono_modem_get_data(modem); + + ofono_error("Modem enabling timeout, RFKILL enabled?"); + + data->cfun_timeout = 0; + + g_at_chat_unref(data->chat); + data->chat = NULL; + + ofono_modem_set_powered(modem, FALSE); + + return FALSE; } static int gobi_enable(struct ofono_modem *modem) @@ -203,6 +226,8 @@ static int gobi_enable(struct ofono_modem *modem) g_at_chat_send(data->chat, "AT+CFUN=4", none_prefix, cfun_enable, modem, NULL); + data->cfun_timeout = g_timeout_add_seconds(5, cfun_timeout, modem); + return -EINPROGRESS; }