Open Source Telephony
 help / color / mirror / Atom feed
From: Philippe Nunes <philippe.nunes@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 3/4] atmodem: Add a polling based on CPIN query to detect SIM state change
Date: Fri, 22 Jul 2011 18:15:28 +0200	[thread overview]
Message-ID: <1311351329-1241-4-git-send-email-philippe.nunes@linux.intel.com> (raw)
In-Reply-To: <1311351329-1241-1-git-send-email-philippe.nunes@linux.intel.com>

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

On ZTE/Speedup modem, AT+CPIN? keeps returning CME ERROR 14 for a moment
after successful AT+CPIN=".."
As there is no card status notification, a pooling with CPIN queries is used
to detect the state change.
---
 drivers/atmodem/sim.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
index a4a09f5..b28f3f8 100644
--- a/drivers/atmodem/sim.c
+++ b/drivers/atmodem/sim.c
@@ -46,10 +46,13 @@
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
+#define POLL_INTERVAL	1
+
 struct sim_data {
 	GAtChat *chat;
 	unsigned int vendor;
 	guint ready_id;
+	guint cpin_poll_count;
 };
 
 static const char *crsm_prefix[] = { "+CRSM:", NULL };
@@ -61,6 +64,8 @@ static const char *cpinr_prefixes[] = { "+CPINR:", "+CPINRE:", NULL };
 static const char *epin_prefix[] = { "*EPIN:", NULL };
 static const char *none_prefix[] = { NULL };
 
+static void pin_status_cb(gboolean ok, GAtResult *result, gpointer user_data);
+
 static void at_crsm_info_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct cb_data *cbd = user_data;
@@ -757,6 +762,44 @@ static void at_cpin_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	cb(&error, pin_type, cbd->data);
 }
 
+static gboolean pin_status_poll(gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	struct sim_data *sd = cbd->user;
+	ofono_sim_lock_unlock_cb_t cb = cbd->cb;
+
+	if (g_at_chat_send(sd->chat, "AT+CPIN?", cpin_prefix, pin_status_cb,
+			cbd, NULL) == 0) {
+		CALLBACK_WITH_FAILURE(cb, cbd->data);
+		g_free(cbd);
+	}
+
+	return FALSE;
+}
+
+static void pin_status_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	struct sim_data *sd = cbd->user;
+	ofono_sim_lock_unlock_cb_t cb = cbd->cb;
+	struct ofono_error error;
+
+	decode_at_error(&error, g_at_result_final_response(result));
+
+	if (error.error == 14 && sd->cpin_poll_count++ < 5) {
+		/* SIM Busy, wait and check again the pin status */
+		sd->ready_id = g_timeout_add_seconds(POLL_INTERVAL,
+							pin_status_poll, cbd);
+		return;
+	}
+
+	sd->cpin_poll_count = 0;
+	sd->ready_id = 0;
+	cb(&error, cbd->data);
+
+	g_free(cbd);
+}
+
 static void at_pin_query(struct ofono_sim *sim, ofono_sim_passwd_cb_t cb,
 			void *data)
 {
@@ -852,6 +895,18 @@ static void at_pin_send_cb(gboolean ok, GAtResult *result,
 							at_epev_notify,
 							FALSE, cbd, g_free);
 		return;
+	case OFONO_VENDOR_QUALCOMM_MSM:
+	case OFONO_VENDOR_SPEEDUP:
+		/* On ZTE/Speedup modem, AT+CPIN? keeps returning CME ERROR 14
+		 * for a moment after successful AT+CPIN=".."
+		 * As there is no card status notification, a pooling with
+		 * CPIN queries is used to detect the state change
+		 */
+		sd->cpin_poll_count = 0;
+
+		g_at_chat_send(sd->chat, "AT+CPIN?", cpin_prefix,
+						pin_status_cb, cbd, NULL);
+		return;
 	}
 
 done:
-- 
1.7.1


  parent reply	other threads:[~2011-07-22 16:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-22 16:15 [PATCH 0/4] ZTE/SpeedUp specificities Philippe Nunes
2011-07-22 16:15 ` [PATCH 1/4] atmodem: Add vendor entry for SpeedUp modems Philippe Nunes
2011-07-27 14:13   ` Marcel Holtmann
2011-07-22 16:15 ` [PATCH 2/4] speedup: Create SIM atom with SpeedUp vendor to handle proprietary commands Philippe Nunes
2011-07-27 14:15   ` Marcel Holtmann
2011-07-22 16:15 ` Philippe Nunes [this message]
2011-07-27 14:19   ` [PATCH 3/4] atmodem: Add a polling based on CPIN query to detect SIM state change Marcel Holtmann
2011-07-22 16:15 ` [PATCH 4/4] atmodem: Add support for the PIN counter command AT+CPNNUM Philippe Nunes
2011-07-22 14:05   ` Denis Kenzior
2011-07-27 14:17   ` Marcel Holtmann
2011-08-04  7:34     ` Aygon, Bertrand
2011-08-04 15:44       ` Marcel Holtmann
2011-08-04 15:56         ` Aygon, Bertrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1311351329-1241-4-git-send-email-philippe.nunes@linux.intel.com \
    --to=philippe.nunes@linux.intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox