Open Source Telephony
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH 4/4] atmodem: Add support for the PIN counter command AT+CPNNUM
Date: Fri, 22 Jul 2011 09:05:41 -0500	[thread overview]
Message-ID: <4E2983B5.4090402@gmail.com> (raw)
In-Reply-To: <1311351329-1241-5-git-send-email-philippe.nunes@linux.intel.com>

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

Hi Philippe,

On 07/22/2011 11:15 AM, Philippe Nunes wrote:
> ---
>  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;

I know this string is non-standard and the vendor should be ridiculed
publically.  However, it seems to me there's entirely too much code for
this purpose.  Have you considered using sscanf or g_strsplit_set for
this purpose?

> +
> +	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,

It is my understanding that SpeedUp also supports AT+BMCPNCNT for CPIN
queries, or are these interchangeable?

> +					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)

Regards,
-Denis

  reply	other threads:[~2011-07-22 14:05 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 ` [PATCH 4/4] atmodem: Add support for the PIN counter command AT+CPNNUM Philippe Nunes
2011-07-22 14:05   ` Denis Kenzior [this message]
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=4E2983B5.4090402@gmail.com \
    --to=denkenz@gmail.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