All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] huawei: cancel poll timeout when going to a valid state
@ 2010-12-20 21:51 Lucas De Marchi
  2010-12-20 21:51 ` [PATCH 2/2] huawei: fix SIM state notification when locked Lucas De Marchi
  2010-12-21 23:21 ` [PATCH 1/2] huawei: cancel poll timeout when going to a valid state Denis Kenzior
  0 siblings, 2 replies; 6+ messages in thread
From: Lucas De Marchi @ 2010-12-20 21:51 UTC (permalink / raw)
  To: ofono

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

---
 plugins/huawei.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/plugins/huawei.c b/plugins/huawei.c
index 0c8d8c0..bff1343 100644
--- a/plugins/huawei.c
+++ b/plugins/huawei.c
@@ -205,6 +205,11 @@ static gboolean notify_sim_state(struct ofono_modem *modem,
 	case HUAWEI_SIM_STATE_INVALID_CS:
 	case HUAWEI_SIM_STATE_INVALID_PS:
 	case HUAWEI_SIM_STATE_INVALID_PS_AND_CS:
+		if (data->sim_poll_timeout) {
+			g_source_remove(data->sim_poll_timeout);
+			data->sim_poll_timeout = 0;
+		}
+
 		/*
 		 * In the "warm start" case the modem skips
 		 * HUAWEI_SIM_STATE_INVALID_OR_LOCKED altogether, so need
-- 
1.7.3.4


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

* [PATCH 2/2] huawei: fix SIM state notification when locked
  2010-12-20 21:51 [PATCH 1/2] huawei: cancel poll timeout when going to a valid state Lucas De Marchi
@ 2010-12-20 21:51 ` Lucas De Marchi
  2010-12-21 19:19   ` Lucas De Marchi
  2010-12-21 19:27   ` [PATCH] " Lucas De Marchi
  2010-12-21 23:21 ` [PATCH 1/2] huawei: cancel poll timeout when going to a valid state Denis Kenzior
  1 sibling, 2 replies; 6+ messages in thread
From: Lucas De Marchi @ 2010-12-20 21:51 UTC (permalink / raw)
  To: ofono

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

When SIM is locked, huawei modem does not send any notification about
SIM state change because it does not differentiate 'invalid' from
'locked'.

In order to be able to unlock the sim, this patch forces a notification
of a valid state after a timeout.
---
 plugins/huawei.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/plugins/huawei.c b/plugins/huawei.c
index bff1343..7934956 100644
--- a/plugins/huawei.c
+++ b/plugins/huawei.c
@@ -56,6 +56,7 @@
 #include <drivers/atmodem/vendor.h>
 
 static const char *none_prefix[] = { NULL };
+static const char *cpin_prefix[] = { "+CPIN:", NULL };
 static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
 static const char *ussdmode_prefix[] = { "^USSDMODE:", NULL };
 static const char *cvoice_prefix[] = { "^CVOICE:", NULL };
@@ -226,6 +227,41 @@ static gboolean notify_sim_state(struct ofono_modem *modem,
 	return FALSE;
 }
 
+static void cpin_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	const char *value;
+	GAtResultIter iter;
+
+	if (!ok)
+		return;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "+CPIN:"))
+		return;
+
+	if (!g_at_result_iter_next_unquoted_string(&iter, &value))
+		return;
+
+	/* Force notification of SIM ready because it's in a locked state */
+	if (g_str_has_prefix(value, "SIM"))
+		notify_sim_state(modem, HUAWEI_SIM_STATE_VALID);
+}
+
+static gboolean query_sim_locked(gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct huawei_data *data = ofono_modem_get_data(modem);
+
+	data->sim_poll_timeout = 0;
+
+	g_at_chat_send(data->pcui, "AT+CPIN?", cpin_prefix,
+			cpin_cb, modem, NULL);
+
+	return FALSE;
+}
+
 static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -264,6 +300,10 @@ static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
 		data->sim_poll_timeout = g_timeout_add_seconds(2,
 								query_sim_state,
 								modem);
+	} else if (sim_state ==	HUAWEI_SIM_STATE_INVALID_OR_LOCKED) {
+		data->sim_poll_timeout = g_timeout_add_seconds(2,
+								query_sim_locked,
+								modem);
 	}
 }
 
-- 
1.7.3.4


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

* Re: [PATCH 2/2] huawei: fix SIM state notification when locked
  2010-12-20 21:51 ` [PATCH 2/2] huawei: fix SIM state notification when locked Lucas De Marchi
@ 2010-12-21 19:19   ` Lucas De Marchi
  2010-12-21 19:27   ` [PATCH] " Lucas De Marchi
  1 sibling, 0 replies; 6+ messages in thread
From: Lucas De Marchi @ 2010-12-21 19:19 UTC (permalink / raw)
  To: ofono

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

On Mon, Dec 20, 2010 at 7:51 PM, Lucas De Marchi
<lucas.demarchi@profusion.mobi> wrote:
> When SIM is locked, huawei modem does not send any notification about
> SIM state change because it does not differentiate 'invalid' from
> 'locked'.
>
> In order to be able to unlock the sim, this patch forces a notification
> of a valid state after a timeout.
> ---
>  plugins/huawei.c |   40 ++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 40 insertions(+), 0 deletions(-)
>
> diff --git a/plugins/huawei.c b/plugins/huawei.c
> index bff1343..7934956 100644
> --- a/plugins/huawei.c
> +++ b/plugins/huawei.c
> @@ -56,6 +56,7 @@
>  #include <drivers/atmodem/vendor.h>
>
>  static const char *none_prefix[] = { NULL };
> +static const char *cpin_prefix[] = { "+CPIN:", NULL };
>  static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
>  static const char *ussdmode_prefix[] = { "^USSDMODE:", NULL };
>  static const char *cvoice_prefix[] = { "^CVOICE:", NULL };
> @@ -226,6 +227,41 @@ static gboolean notify_sim_state(struct ofono_modem *modem,
>        return FALSE;
>  }
>
> +static void cpin_cb(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> +       struct ofono_modem *modem = user_data;
> +       const char *value;
> +       GAtResultIter iter;
> +
> +       if (!ok)
> +               return;
> +
> +       g_at_result_iter_init(&iter, result);
> +
> +       if (!g_at_result_iter_next(&iter, "+CPIN:"))
> +               return;
> +
> +       if (!g_at_result_iter_next_unquoted_string(&iter, &value))
> +               return;
> +
> +       /* Force notification of SIM ready because it's in a locked state */
> +       if (g_str_has_prefix(value, "SIM"))
> +               notify_sim_state(modem, HUAWEI_SIM_STATE_VALID);
> +}

As I talked to Denis through IRC, this can be simplified. We can cheat
here, not doing all this parsing and only relying on "ok" value. I
tested it with Huawei E220. I'll send  another patch.


Lucas De Marchi

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

* [PATCH] huawei: fix SIM state notification when locked
  2010-12-20 21:51 ` [PATCH 2/2] huawei: fix SIM state notification when locked Lucas De Marchi
  2010-12-21 19:19   ` Lucas De Marchi
@ 2010-12-21 19:27   ` Lucas De Marchi
  2010-12-21 19:37     ` Denis Kenzior
  1 sibling, 1 reply; 6+ messages in thread
From: Lucas De Marchi @ 2010-12-21 19:27 UTC (permalink / raw)
  To: ofono

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

When SIM is locked, huawei modem does not send any notification about
SIM state change because it does not differentiate 'invalid' from
'locked'.

In order to be able to unlock the sim, this patch forces a notification
of a valid state after a timeout.
---
 plugins/huawei.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/plugins/huawei.c b/plugins/huawei.c
index bff1343..de45b03 100644
--- a/plugins/huawei.c
+++ b/plugins/huawei.c
@@ -226,6 +226,30 @@ static gboolean notify_sim_state(struct ofono_modem *modem,
 	return FALSE;
 }
 
+static void cpin_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+
+	if (!ok)
+		return;
+
+	/* Force notification of SIM ready because it's in a locked state */
+	notify_sim_state(modem, HUAWEI_SIM_STATE_VALID);
+}
+
+static gboolean query_sim_locked(gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct huawei_data *data = ofono_modem_get_data(modem);
+
+	data->sim_poll_timeout = 0;
+
+	g_at_chat_send(data->pcui, "AT+CPIN?", NULL,
+			cpin_cb, modem, NULL);
+
+	return FALSE;
+}
+
 static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -264,6 +288,10 @@ static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
 		data->sim_poll_timeout = g_timeout_add_seconds(2,
 								query_sim_state,
 								modem);
+	} else if (sim_state ==	HUAWEI_SIM_STATE_INVALID_OR_LOCKED) {
+		data->sim_poll_timeout = g_timeout_add_seconds(2,
+								query_sim_locked,
+								modem);
 	}
 }
 
-- 
1.7.3.4


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

* Re: [PATCH] huawei: fix SIM state notification when locked
  2010-12-21 19:27   ` [PATCH] " Lucas De Marchi
@ 2010-12-21 19:37     ` Denis Kenzior
  0 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2010-12-21 19:37 UTC (permalink / raw)
  To: ofono

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

Hi Lucas,

On 12/21/2010 01:27 PM, Lucas De Marchi wrote:
> When SIM is locked, huawei modem does not send any notification about
> SIM state change because it does not differentiate 'invalid' from
> 'locked'.
> 
> In order to be able to unlock the sim, this patch forces a notification
> of a valid state after a timeout.
> ---
>  plugins/huawei.c |   28 ++++++++++++++++++++++++++++
>  1 files changed, 28 insertions(+), 0 deletions(-)
> 

Looks good to me.  Patch has been applied, thanks.

Regards,
-Denis

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

* Re: [PATCH 1/2] huawei: cancel poll timeout when going to a valid state
  2010-12-20 21:51 [PATCH 1/2] huawei: cancel poll timeout when going to a valid state Lucas De Marchi
  2010-12-20 21:51 ` [PATCH 2/2] huawei: fix SIM state notification when locked Lucas De Marchi
@ 2010-12-21 23:21 ` Denis Kenzior
  1 sibling, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2010-12-21 23:21 UTC (permalink / raw)
  To: ofono

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

Hi Lucas,

On 12/20/2010 03:51 PM, Lucas De Marchi wrote:
> ---
>  plugins/huawei.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 

Patch has been applied, thanks.

Regards,
-Denis

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

end of thread, other threads:[~2010-12-21 23:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-20 21:51 [PATCH 1/2] huawei: cancel poll timeout when going to a valid state Lucas De Marchi
2010-12-20 21:51 ` [PATCH 2/2] huawei: fix SIM state notification when locked Lucas De Marchi
2010-12-21 19:19   ` Lucas De Marchi
2010-12-21 19:27   ` [PATCH] " Lucas De Marchi
2010-12-21 19:37     ` Denis Kenzior
2010-12-21 23:21 ` [PATCH 1/2] huawei: cancel poll timeout when going to a valid state 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.