All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] atmodem: implement query for remaining pin retries
@ 2011-01-10 21:59 Lucas De Marchi
  2011-01-10 21:59 ` [PATCH 2/2] TODO: mark 'SIM PIN retry counter' task as done Lucas De Marchi
  2011-01-10 22:22 ` [PATCH 1/2] atmodem: implement query for remaining pin retries Denis Kenzior
  0 siblings, 2 replies; 4+ messages in thread
From: Lucas De Marchi @ 2011-01-10 21:59 UTC (permalink / raw)
  To: ofono

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

Implement query method for the remaining pin retries on huawei modem.
---
 drivers/atmodem/sim.c |   96 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 96 insertions(+), 0 deletions(-)

diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
index 33f756d..5fd15d2 100644
--- a/drivers/atmodem/sim.c
+++ b/drivers/atmodem/sim.c
@@ -44,6 +44,8 @@
 #define EF_STATUS_INVALIDATED 0
 #define EF_STATUS_VALID 1
 
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
 struct sim_data {
 	GAtChat *chat;
 	unsigned int vendor;
@@ -53,6 +55,7 @@ struct sim_data {
 static const char *crsm_prefix[] = { "+CRSM:", NULL };
 static const char *cpin_prefix[] = { "+CPIN:", NULL };
 static const char *clck_prefix[] = { "+CLCK:", NULL };
+static const char *huawei_cpin_prefix[] = { "^CPIN:", NULL };
 static const char *none_prefix[] = { NULL };
 
 static void at_crsm_info_cb(gboolean ok, GAtResult *result, gpointer user_data)
@@ -458,6 +461,98 @@ static struct {
 	{ OFONO_SIM_PASSWORD_PHCORP_PUK,	"PH-CORP PUK"	},
 };
 
+static void huawei_cpin_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_sim_pin_retries_cb_t cb = cbd->cb;
+	const char *final = g_at_result_final_response(result);
+	GAtResultIter iter;
+	struct ofono_error error;
+	int retries[OFONO_SIM_PASSWORD_INVALID];
+	size_t i;
+	static enum ofono_sim_password_type _password_types[] = {
+		OFONO_SIM_PASSWORD_SIM_PUK,
+		OFONO_SIM_PASSWORD_SIM_PIN,
+		OFONO_SIM_PASSWORD_SIM_PUK2,
+		OFONO_SIM_PASSWORD_SIM_PIN2,
+	};
+
+	decode_at_error(&error, final);
+
+	if (!ok) {
+		cb(&error, NULL, cbd->data);
+		return;
+	}
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "^CPIN:"))
+		goto error;
+
+	/* Skip status since we are not interested in this */
+	if (!g_at_result_iter_skip_next(&iter))
+		goto error;
+
+	/* Skip "overall counter" since we'll grab each one individually */
+	if (!g_at_result_iter_skip_next(&iter))
+		goto error;
+
+	for (i = 0; i < OFONO_SIM_PASSWORD_INVALID; i++)
+		retries[i] = -1;
+
+	for (i = 0; i < ARRAY_SIZE(_password_types); i++) {
+		int val;
+
+		if (!g_at_result_iter_next_number(&iter, &val))
+			goto error;
+
+		retries[_password_types[i]]= val;
+
+		DBG("retry counter id=%d, val=%d", _password_types[i],
+						retries[_password_types[i]]);
+	}
+
+	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)
+{
+	struct sim_data *sd = ofono_sim_get_data(sim);
+	int retries[OFONO_SIM_PASSWORD_INVALID];
+	int i;
+
+	DBG("");
+
+	if (sd->vendor == OFONO_VENDOR_HUAWEI) {
+		struct cb_data *cbd = cb_data_new(cb, data);
+
+		if (cbd == NULL) {
+			CALLBACK_WITH_FAILURE(cb, NULL, data);
+
+			return;
+		}
+
+		if (g_at_chat_send(sd->chat, "AT^CPIN?", huawei_cpin_prefix,
+					huawei_cpin_cb, cbd, g_free) > 0)
+			return;
+
+		g_free(cbd);
+
+		CALLBACK_WITH_FAILURE(cb, NULL, data);
+	}
+
+	for(i = 0; i < OFONO_SIM_PASSWORD_INVALID; i++)
+		retries[i] = -1;
+
+	CALLBACK_WITH_SUCCESS(cb, retries, data);
+}
+
 static void at_cpin_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct cb_data *cbd = user_data;
@@ -888,6 +983,7 @@ static struct ofono_sim_driver driver = {
 	.write_file_cyclic	= at_sim_update_cyclic,
 	.read_imsi		= at_read_imsi,
 	.query_passwd_state	= at_pin_query,
+	.query_pin_retries	= at_pin_retries_query,
 	.send_passwd		= at_pin_send,
 	.reset_passwd		= at_pin_send_puk,
 	.lock			= at_pin_enable,
-- 
1.7.3.5


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

* [PATCH 2/2] TODO: mark 'SIM PIN retry counter' task as done
  2011-01-10 21:59 [PATCH 1/2] atmodem: implement query for remaining pin retries Lucas De Marchi
@ 2011-01-10 21:59 ` Lucas De Marchi
  2011-01-10 22:23   ` Denis Kenzior
  2011-01-10 22:22 ` [PATCH 1/2] atmodem: implement query for remaining pin retries Denis Kenzior
  1 sibling, 1 reply; 4+ messages in thread
From: Lucas De Marchi @ 2011-01-10 21:59 UTC (permalink / raw)
  To: ofono

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

---
 TODO             |    8 --------
 doc/features.txt |    5 +++++
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/TODO b/TODO
index 12f313b..495d539 100644
--- a/TODO
+++ b/TODO
@@ -72,14 +72,6 @@ SIM / SIM File system
   Priority: Low
   Complexity: C2
 
-- Support proprietary extensions for SIM PIN retry counter.  Most vendors
-  provide an extension commands to obtain such a retry counter for PINs and
-  PUKs.  Need to enable this as a property in oFono.
-
-  Priority: Low
-  Complexity: C2
-  Owner: Lucas De Marchi <lucas.demarchi@profusion.mobi>
-
 - Add support for SIM 'ready' notifications from the driver to the core.  Most
   modem manufacturers initialize the SIM (e.g. cache SIM file system, STK
   initialization, etc) internally before allowing the telephony stack to
diff --git a/doc/features.txt b/doc/features.txt
index a9fdb86..0a3357f 100644
--- a/doc/features.txt
+++ b/doc/features.txt
@@ -256,6 +256,11 @@ SIM
   ForwardingFlagOnSim will be set and VoiceUnconditional may contain the
   "forwarded to" number if the number is available.
 
+- Support SIM retry counters. oFono exports all the retry counters available on
+  SIM, e.g., PIN, PIN2, PUK and PUK2. Whenever an action changes them, a signal
+  is sent with the updated values, so user can keep track of how many times
+  he/she can still give a wrong pin before the SIM locking down.
+
 Radio settings
 ==============
 
-- 
1.7.3.5


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

* Re: [PATCH 1/2] atmodem: implement query for remaining pin retries
  2011-01-10 21:59 [PATCH 1/2] atmodem: implement query for remaining pin retries Lucas De Marchi
  2011-01-10 21:59 ` [PATCH 2/2] TODO: mark 'SIM PIN retry counter' task as done Lucas De Marchi
@ 2011-01-10 22:22 ` Denis Kenzior
  1 sibling, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2011-01-10 22:22 UTC (permalink / raw)
  To: ofono

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

On 01/10/2011 03:59 PM, Lucas De Marchi wrote:
> Implement query method for the remaining pin retries on huawei modem.
> ---
>  drivers/atmodem/sim.c |   96 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 96 insertions(+), 0 deletions(-)
> 

Patch has been applied, but I pushed a couple of fixes afterward.

Regards,
-Denis

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

* Re: [PATCH 2/2] TODO: mark 'SIM PIN retry counter' task as done
  2011-01-10 21:59 ` [PATCH 2/2] TODO: mark 'SIM PIN retry counter' task as done Lucas De Marchi
@ 2011-01-10 22:23   ` Denis Kenzior
  0 siblings, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2011-01-10 22:23 UTC (permalink / raw)
  To: ofono

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

Hi Lucas,

On 01/10/2011 03:59 PM, Lucas De Marchi wrote:
> ---
>  TODO             |    8 --------
>  doc/features.txt |    5 +++++
>  2 files changed, 5 insertions(+), 8 deletions(-)
> 

Patch has been applied, thanks.

Regards,
-Denis

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

end of thread, other threads:[~2011-01-10 22:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-10 21:59 [PATCH 1/2] atmodem: implement query for remaining pin retries Lucas De Marchi
2011-01-10 21:59 ` [PATCH 2/2] TODO: mark 'SIM PIN retry counter' task as done Lucas De Marchi
2011-01-10 22:23   ` Denis Kenzior
2011-01-10 22:22 ` [PATCH 1/2] atmodem: implement query for remaining pin retries 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.