All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mbm: poll SIM status when initializing
@ 2010-07-14 16:28 Pekka.Pessi
  2010-07-14 16:40 ` Denis Kenzior
  0 siblings, 1 reply; 7+ messages in thread
From: Pekka.Pessi @ 2010-07-14 16:28 UTC (permalink / raw)
  To: ofono

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

From: Pekka Pessi <Pekka.Pessi@nokia.com>

---
 plugins/mbm.c |   39 +++++++++++++++++++++++++++++++++++----
 1 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/plugins/mbm.c b/plugins/mbm.c
index 864b0df..9e63005 100644
--- a/plugins/mbm.c
+++ b/plugins/mbm.c
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <glib.h>
 #include <gatchat.h>
@@ -54,6 +55,8 @@ static const char *none_prefix[] = { NULL };
 struct mbm_data {
 	GAtChat *modem_port;
 	GAtChat *data_port;
+	guint sim_poll;
+	guint sim_polled;
 	gboolean have_sim;
 };
 
@@ -82,6 +85,10 @@ static void mbm_remove(struct ofono_modem *modem)
 
 	g_at_chat_unref(data->data_port);
 	g_at_chat_unref(data->modem_port);
+
+	if (data->sim_poll > 0)
+		g_source_remove(data->sim_poll);
+
 	g_free(data);
 }
 
@@ -92,6 +99,8 @@ static void mbm_debug(const char *str, void *user_data)
 	ofono_info("%s %s", prefix, str);
 }
 
+static gboolean init_simpin_check(gpointer user_data);
+
 static void simpin_check(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -99,17 +108,40 @@ static void simpin_check(gboolean ok, GAtResult *result, gpointer user_data)
 
 	DBG("");
 
-	/* Modem returns error if there is no SIM in slot */
+	/* Modem returns +CME ERROR: 10 if SIM is not ready. */
+	if (!ok && result->final_or_pdu &&
+		!strcmp(result->final_or_pdu, "+CME ERROR: 10") &&
+		data->sim_polled++ < 5) {
+		data->sim_poll =
+			g_timeout_add_seconds(1, init_simpin_check, modem);
+		return;
+	}
+
+	data->sim_polled = 0;
+
+	/* Modem returns ERROR if there is no SIM in slot. */
 	data->have_sim = ok;
 
 	ofono_modem_set_powered(modem, TRUE);
 }
 
-static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
+static gboolean init_simpin_check(gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
 	struct mbm_data *data = ofono_modem_get_data(modem);
 
+	data->sim_poll = 0;
+
+	g_at_chat_send(data->modem_port, "AT+CPIN?", cpin_prefix,
+			simpin_check, modem, NULL);
+
+	return FALSE;
+}
+
+static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+
 	DBG("");
 
 	if (!ok) {
@@ -117,8 +149,7 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 		return;
 	}
 
-	g_at_chat_send(data->modem_port, "AT+CPIN?", cpin_prefix,
-			simpin_check, modem, NULL);
+	init_simpin_check(modem);
 }
 
 static void cfun_query(gboolean ok, GAtResult *result, gpointer user_data)
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH] mbm: poll SIM status when initializing
@ 2010-07-14 15:43 Pekka.Pessi
  2010-07-14 16:00 ` Denis Kenzior
  0 siblings, 1 reply; 7+ messages in thread
From: Pekka.Pessi @ 2010-07-14 15:43 UTC (permalink / raw)
  To: ofono

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

From: Pekka Pessi <Pekka.Pessi@nokia.com>

---
 plugins/mbm.c |   28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/plugins/mbm.c b/plugins/mbm.c
index 864b0df..5058b7c 100644
--- a/plugins/mbm.c
+++ b/plugins/mbm.c
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <glib.h>
 #include <gatchat.h>
@@ -92,6 +93,8 @@ static void mbm_debug(const char *str, void *user_data)
 	ofono_info("%s %s", prefix, str);
 }
 
+static gboolean init_simpin_check(gpointer user_data);
+
 static void simpin_check(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -99,17 +102,35 @@ static void simpin_check(gboolean ok, GAtResult *result, gpointer user_data)
 
 	DBG("");
 
-	/* Modem returns error if there is no SIM in slot */
+	/* Modem returns +CME ERROR: 10 if SIM is not ready. */
+	if (!ok && result->final_or_pdu &&
+		!strcmp(result->final_or_pdu, "+CME ERROR: 10")) {
+		g_timeout_add_seconds(1, init_simpin_check, modem);
+		return;
+	}
+
+	/* Modem returns ERROR if there is no SIM in slot. */
 	data->have_sim = ok;
 
 	ofono_modem_set_powered(modem, TRUE);
 }
 
-static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
+
+static gboolean init_simpin_check(gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
 	struct mbm_data *data = ofono_modem_get_data(modem);
 
+	g_at_chat_send(data->modem_port, "AT+CPIN?", cpin_prefix,
+			simpin_check, modem, NULL);
+
+	return FALSE;
+}
+
+static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+
 	DBG("");
 
 	if (!ok) {
@@ -117,8 +138,7 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 		return;
 	}
 
-	g_at_chat_send(data->modem_port, "AT+CPIN?", cpin_prefix,
-			simpin_check, modem, NULL);
+	init_simpin_check(modem);
 }
 
 static void cfun_query(gboolean ok, GAtResult *result, gpointer user_data)
-- 
1.7.0.4


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

end of thread, other threads:[~2010-07-15 14:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-14 16:28 [PATCH] mbm: poll SIM status when initializing Pekka.Pessi
2010-07-14 16:40 ` Denis Kenzior
2010-07-15 14:05   ` Pekka.Pessi
2010-07-15 14:20     ` Denis Kenzior
  -- strict thread matches above, loose matches on Subject: below --
2010-07-14 15:43 Pekka.Pessi
2010-07-14 16:00 ` Denis Kenzior
2010-07-14 16:15   ` Pekka Pessi

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.