All of lore.kernel.org
 help / color / mirror / Atom feed
* [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

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

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

Hi Pekka,

> @@ -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. */

What if the modem has no SIM present at all?  You might want to set a
retry threshold so that we don't poll the modem into oblivion.

Regards,
-Denis

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

* Re: [PATCH] mbm: poll SIM status when initializing
  2010-07-14 16:00 ` Denis Kenzior
@ 2010-07-14 16:15   ` Pekka Pessi
  0 siblings, 0 replies; 7+ messages in thread
From: Pekka Pessi @ 2010-07-14 16:15 UTC (permalink / raw)
  To: ofono

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

Hi Denis,

2010/7/14 Denis Kenzior <denkenz@gmail.com>:
>> @@ -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. */
>
> What if the modem has no SIM present at all?  You might want to set a
> retry threshold so that we don't poll the modem into oblivion.

If there is no SIM, +CPIN? returns plain ERROR (as I try to explain in
the comment above).

+CME ERROR: 10 is returned while modem is busy trying to connect with
the SIM card.

I'll add a check to stop polling after 5 seconds.

-- 
Pekka.Pessi mail at nokia.com

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

* [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

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

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

Hi Pekka,

> @@ -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;
>  };

Can we rename sim_poll to cpin_poll_source?

Can we rename sim_polled to cpin_poll_retry or cpin_poll_retries?

> -	/* 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;
> +	}
> +

Please note that whenever you have a multi-line if condition like the
one above, the conditions after the if should be indented one more level
than the if body block.  E.g. put an extra indent before !strcmp and
data->sim_polled.

Regards,
-Denis

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

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

[-- Attachment #1: Type: text/plain, Size: 2734 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..4f6b46e 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 cpin_poll_source;
+	guint cpin_poll_count;
 	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->cpin_poll_source > 0)
+		g_source_remove(data->cpin_poll_source);
+
 	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->cpin_poll_count++ < 5) {
+		data->cpin_poll_source =
+			g_timeout_add_seconds(1, init_simpin_check, modem);
+		return;
+	}
+
+	data->cpin_poll_count = 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->cpin_poll_source = 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

* Re: [PATCH] mbm: poll SIM status when initializing
  2010-07-15 14:05   ` Pekka.Pessi
@ 2010-07-15 14:20     ` Denis Kenzior
  0 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2010-07-15 14:20 UTC (permalink / raw)
  To: ofono

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

Hi Pekka,

On 07/15/2010 09:05 AM, Pekka.Pessi(a)nokia.com wrote:
> From: Pekka Pessi <Pekka.Pessi@nokia.com>
> 
> ---
>  plugins/mbm.c |   39 +++++++++++++++++++++++++++++++++++----
>  1 files changed, 35 insertions(+), 4 deletions(-)
> 

Patch has been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[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 15:43 [PATCH] mbm: poll SIM status when initializing Pekka.Pessi
2010-07-14 16:00 ` Denis Kenzior
2010-07-14 16:15   ` Pekka Pessi
  -- strict thread matches above, loose matches on Subject: below --
2010-07-14 16:28 Pekka.Pessi
2010-07-14 16:40 ` Denis Kenzior
2010-07-15 14:05   ` Pekka.Pessi
2010-07-15 14:20     ` 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.