From: Philippe Nunes <philippe.nunes@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 4/4] atmodem: Add support for the PIN counter command AT+CPNNUM
Date: Fri, 22 Jul 2011 18:15:29 +0200 [thread overview]
Message-ID: <1311351329-1241-5-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: 2871 bytes --]
---
drivers/atmodem/sim.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 95 insertions(+), 0 deletions(-)
diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
index b28f3f8..49f5245 100644
--- a/drivers/atmodem/sim.c
+++ b/drivers/atmodem/sim.c
@@ -667,6 +667,95 @@ static void at_cpinr_cb(gboolean ok, GAtResult *result, gpointer user_data)
cb(&error, retries, cbd->data);
}
+static gboolean skip_to_field(GAtResultIter *iter, const char *field)
+{
+ char *line;
+ char *offset;
+ int field_len = field ? strlen(field) : 0;
+
+ if (iter == NULL)
+ return FALSE;
+
+ if (iter->l == NULL)
+ return FALSE;
+
+ line = iter->l->data;
+
+ if (field_len == 0) {
+ iter->line_pos = 0;
+ return TRUE;
+ }
+
+ offset = g_strrstr(line, field);
+ if (offset == NULL)
+ return FALSE;
+
+ iter->line_pos = (offset - line) + field_len;
+
+ return TRUE;
+}
+
+static void at_cpnnum_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ struct cb_data *cbd = user_data;
+ ofono_sim_pin_retries_cb_t cb = cbd->cb;
+ GAtResultIter iter;
+ struct ofono_error error;
+ int retries[OFONO_SIM_PASSWORD_INVALID];
+ size_t i;
+
+ decode_at_error(&error, g_at_result_final_response(result));
+
+ if (!ok) {
+ cb(&error, NULL, cbd->data);
+ return;
+ }
+
+ for (i = 0; i < OFONO_SIM_PASSWORD_INVALID; i++)
+ retries[i] = -1;
+
+ g_at_result_iter_init(&iter, result);
+
+ /*
+ * Even if this is not really a suffix, we rely on the tag PIN1 to
+ * recognize the correct response line.
+ */
+ if (!g_at_result_iter_next(&iter, "PIN1="))
+ goto error;
+
+ if (!g_at_result_iter_next_number(&iter,
+ &retries[OFONO_SIM_PASSWORD_SIM_PIN]))
+ goto error;
+
+ if (!skip_to_field(&iter, "PUK1="))
+ goto error;
+
+ if (!g_at_result_iter_next_number(&iter,
+ &retries[OFONO_SIM_PASSWORD_SIM_PUK]))
+ goto error;
+
+ if (!skip_to_field(&iter, "PIN2="))
+ goto error;
+
+ if (!g_at_result_iter_next_number(&iter,
+ &retries[OFONO_SIM_PASSWORD_SIM_PIN2]))
+ goto error;
+
+ if (!skip_to_field(&iter, "PUK2="))
+ goto error;
+
+ if (!g_at_result_iter_next_number(&iter,
+ &retries[OFONO_SIM_PASSWORD_SIM_PUK2]))
+ goto error;
+
+ cb(&error, retries, cbd->data);
+
+ return;
+
+error:
+ CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
+}
+
static void at_pin_retries_query(struct ofono_sim *sim,
ofono_sim_pin_retries_cb_t cb,
void *data)
@@ -695,6 +784,12 @@ static void at_pin_retries_query(struct ofono_sim *sim,
return;
break;
+ case OFONO_VENDOR_SPEEDUP:
+ if (g_at_chat_send(sd->chat, "AT+CPNNUM", NULL,
+ at_cpnnum_cb, cbd, g_free) > 0)
+ return;
+
+ break;
default:
if (g_at_chat_send(sd->chat, "AT+CPINR", cpinr_prefixes,
at_cpinr_cb, cbd, g_free) > 0)
--
1.7.1
next prev 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 ` [PATCH 3/4] atmodem: Add a polling based on CPIN query to detect SIM state change Philippe Nunes
2011-07-27 14:19 ` Marcel Holtmann
2011-07-22 16:15 ` Philippe Nunes [this message]
2011-07-22 14:05 ` [PATCH 4/4] atmodem: Add support for the PIN counter command AT+CPNNUM 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-5-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