All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 0/2] CPIN polling mechanism
@ 2011-07-21 10:01 Nicolas Bertrand
  2011-07-21 10:01 ` [PATCHv2 1/2] speedup: add cpin " Nicolas Bertrand
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nicolas Bertrand @ 2011-07-21 10:01 UTC (permalink / raw)
  To: ofono

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

v2 changes:
 - change AT channel from modem to aux
 - raise timeout to 20 since some dongle take a while to be
   operational
 - send sim inserted notify related to the current status

As no SIM card status urc is available with ZTE and Speedup, the SIM 
state is set by default to OFONO_SIM_STATE_INSERTED even if no SIM card 
is inserted. Also, we are facing with a modem latency after the ttyUSB 
is opened (first AT commands are failing and the PIN status query 
returns CME ERROR: 14 - SIM Busy).
So, to deal with those 2 issues, this patch set is introducing a 
preliminary PIN status polling in the ZTE/Speedup plugins. In practice, 
this polling is started after the modem is enabled and stopped when the 
CPIN query returns an other result than CME ERROR 14 or when the polling 
duration exceeds 5 seconds.
As a result, the SIM state is set according the result of the CPIN query 
and the update of the modem_powered state is postponed which delays the 
next AT commands.

Developed conjointly with philippe nunes.

Nicolas Bertrand (2):
  speedup: add cpin polling mechanism
  zte: add cpin polling mechanism

 plugins/speedup.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 plugins/zte.c     |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 129 insertions(+), 4 deletions(-)

-- 
1.7.4.1


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

* [PATCHv2 1/2] speedup: add cpin polling mechanism
  2011-07-21 10:01 [PATCHv2 0/2] CPIN polling mechanism Nicolas Bertrand
@ 2011-07-21 10:01 ` Nicolas Bertrand
  2011-07-21 10:01 ` [PATCHv2 2/2] zte: " Nicolas Bertrand
  2011-07-22 14:18 ` [PATCHv2 0/2] CPIN " Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Nicolas Bertrand @ 2011-07-21 10:01 UTC (permalink / raw)
  To: ofono

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

Make sure that the SIM card is ready before sending commands
---
 plugins/speedup.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/plugins/speedup.c b/plugins/speedup.c
index 7e89b6f..afd9b40 100644
--- a/plugins/speedup.c
+++ b/plugins/speedup.c
@@ -49,10 +49,14 @@
 #include <drivers/atmodem/vendor.h>
 
 static const char *none_prefix[] = { NULL };
+static const char *cpin_prefix[] = { "+CPIN:", NULL };
 
 struct speedup_data {
 	GAtChat *modem;
 	GAtChat *aux;
+	guint cpin_poll_source;
+	guint cpin_poll_count;
+	gboolean have_sim;
 	struct ofono_gprs *gprs;
 	struct ofono_gprs_context *gc;
 };
@@ -83,6 +87,9 @@ static void speedup_remove(struct ofono_modem *modem)
 	g_at_chat_unref(data->modem);
 	g_at_chat_unref(data->aux);
 
+	if (data->cpin_poll_source > 0)
+		g_source_remove(data->cpin_poll_source);
+
 	g_free(data);
 }
 
@@ -152,13 +159,68 @@ static void speedup_disconnect(gpointer user_data)
 		ofono_gprs_add_context(data->gprs, data->gc);
 }
 
+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;
+	struct speedup_data *data = ofono_modem_get_data(modem);
+	struct ofono_error error;
+
+	DBG("");
+
+	decode_at_error(&error, g_at_result_final_response(result));
+
+	/* Modem returns an error if SIM is not ready. */
+	switch (error.error) {
+	case 10:
+	case 13:
+		data->have_sim = FALSE;
+		break;
+	case 14: /* SIM Busy, wait and check again the SIM pin status */
+		if (data->cpin_poll_count++ < 20) {
+			data->cpin_poll_source =
+				g_timeout_add_seconds(1, init_simpin_check,
+						modem);
+			return;
+		}
+		/*SIM card is present but not accessible*/
+		data->have_sim = FALSE;
+		break;
+	default:
+		data->have_sim = TRUE;
+	}
+
+	data->cpin_poll_count = 0;
+
+	ofono_modem_set_powered(modem, TRUE);
+}
+
+static gboolean init_simpin_check(gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct speedup_data *data = ofono_modem_get_data(modem);
+
+	data->cpin_poll_source = 0;
+
+	g_at_chat_send(data->aux, "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("");
 
-	ofono_modem_set_powered(modem, ok);
+	if (!ok) {
+		ofono_modem_set_powered(modem, FALSE);
+		return;
+	}
+
+	init_simpin_check(modem);
 }
 
 static int speedup_enable(struct ofono_modem *modem)
@@ -272,7 +334,7 @@ static void speedup_pre_sim(struct ofono_modem *modem)
 				"atmodem", data->aux);
 
 	if (sim)
-		ofono_sim_inserted_notify(sim, TRUE);
+		ofono_sim_inserted_notify(sim, data->have_sim);
 }
 
 static void speedup_post_sim(struct ofono_modem *modem)
-- 
1.7.4.1


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

* [PATCHv2 2/2] zte: add cpin polling mechanism
  2011-07-21 10:01 [PATCHv2 0/2] CPIN polling mechanism Nicolas Bertrand
  2011-07-21 10:01 ` [PATCHv2 1/2] speedup: add cpin " Nicolas Bertrand
@ 2011-07-21 10:01 ` Nicolas Bertrand
  2011-07-22 14:18 ` [PATCHv2 0/2] CPIN " Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Nicolas Bertrand @ 2011-07-21 10:01 UTC (permalink / raw)
  To: ofono

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

Make sure that the SIM card is ready before sending commands
---
 plugins/zte.c |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/plugins/zte.c b/plugins/zte.c
index 4bac3cf..9964a44 100644
--- a/plugins/zte.c
+++ b/plugins/zte.c
@@ -49,10 +49,14 @@
 #include <drivers/atmodem/vendor.h>
 
 static const char *none_prefix[] = { NULL };
+static const char *cpin_prefix[] = { "+CPIN:", NULL };
 
 struct zte_data {
 	GAtChat *modem;
 	GAtChat *aux;
+	guint cpin_poll_source;
+	guint cpin_poll_count;
+	gboolean have_sim;
 	struct ofono_gprs *gprs;
 	struct ofono_gprs_context *gc;
 };
@@ -83,6 +87,9 @@ static void zte_remove(struct ofono_modem *modem)
 	g_at_chat_unref(data->modem);
 	g_at_chat_unref(data->aux);
 
+	if (data->cpin_poll_source > 0)
+		g_source_remove(data->cpin_poll_source);
+
 	g_free(data);
 }
 
@@ -152,13 +159,69 @@ static void zte_disconnect(gpointer user_data)
 		ofono_gprs_add_context(data->gprs, data->gc);
 }
 
+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;
+	struct zte_data *data = ofono_modem_get_data(modem);
+	struct ofono_error error;
+
+	DBG("");
+
+	decode_at_error(&error, g_at_result_final_response(result));
+
+	/* Modem returns an error if SIM is not ready. */
+	switch (error.error) {
+	case 10:
+	case 13:
+		data->have_sim = FALSE;
+		break;
+	case 14: /* SIM Busy, wait and check again the card status */
+		if (data->cpin_poll_count++ < 20) {
+			data->cpin_poll_source =
+				g_timeout_add_seconds(1, init_simpin_check,
+						modem);
+			return;
+		}
+		/*SIM card is present but not accessible*/
+		data->have_sim = FALSE;
+		break;
+	default:
+		data->have_sim = TRUE;
+	}
+
+	data->cpin_poll_count = 0;
+
+	ofono_modem_set_powered(modem, TRUE);
+}
+
+static gboolean init_simpin_check(gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct zte_data *data = ofono_modem_get_data(modem);
+
+	data->cpin_poll_source = 0;
+
+	g_at_chat_send(data->aux, "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("");
 
-	ofono_modem_set_powered(modem, ok);
+	if (!ok) {
+		ofono_modem_set_powered(modem, FALSE);
+		return;
+	}
+
+	init_simpin_check(modem);
 }
 
 static int zte_enable(struct ofono_modem *modem)
@@ -273,7 +336,7 @@ static void zte_pre_sim(struct ofono_modem *modem)
 				"atmodem", data->aux);
 
 	if (sim)
-		ofono_sim_inserted_notify(sim, TRUE);
+		ofono_sim_inserted_notify(sim, data->have_sim);
 }
 
 static void zte_post_sim(struct ofono_modem *modem)
-- 
1.7.4.1


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

* Re: [PATCHv2 0/2] CPIN polling mechanism
  2011-07-21 10:01 [PATCHv2 0/2] CPIN polling mechanism Nicolas Bertrand
  2011-07-21 10:01 ` [PATCHv2 1/2] speedup: add cpin " Nicolas Bertrand
  2011-07-21 10:01 ` [PATCHv2 2/2] zte: " Nicolas Bertrand
@ 2011-07-22 14:18 ` Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2011-07-22 14:18 UTC (permalink / raw)
  To: ofono

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

Hi Nicolas,

On 07/21/2011 05:01 AM, Nicolas Bertrand wrote:
> v2 changes:
>  - change AT channel from modem to aux
>  - raise timeout to 20 since some dongle take a while to be
>    operational
>  - send sim inserted notify related to the current status
> 
> As no SIM card status urc is available with ZTE and Speedup, the SIM 
> state is set by default to OFONO_SIM_STATE_INSERTED even if no SIM card 
> is inserted. Also, we are facing with a modem latency after the ttyUSB 
> is opened (first AT commands are failing and the PIN status query 
> returns CME ERROR: 14 - SIM Busy).
> So, to deal with those 2 issues, this patch set is introducing a 
> preliminary PIN status polling in the ZTE/Speedup plugins. In practice, 
> this polling is started after the modem is enabled and stopped when the 
> CPIN query returns an other result than CME ERROR 14 or when the polling 
> duration exceeds 5 seconds.
> As a result, the SIM state is set according the result of the CPIN query 
> and the update of the modem_powered state is postponed which delays the 
> next AT commands.
> 
> Developed conjointly with philippe nunes.
> 

I've added PIN polling utility to drivers/atmodem/atutil.c and have made
the mbm plugin use this.  Can you check whether this utility is suitable
for ZTE/Speedup drivers?

Regards,
-Denis

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

end of thread, other threads:[~2011-07-22 14:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-21 10:01 [PATCHv2 0/2] CPIN polling mechanism Nicolas Bertrand
2011-07-21 10:01 ` [PATCHv2 1/2] speedup: add cpin " Nicolas Bertrand
2011-07-21 10:01 ` [PATCHv2 2/2] zte: " Nicolas Bertrand
2011-07-22 14:18 ` [PATCHv2 0/2] CPIN " 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.