Open Source Telephony
 help / color / mirror / Atom feed
From: Ming Li Wu <mingli@southpole.se>
To: ofono@ofono.org
Subject: Re: [PATCH 1/1] telit: stay 'online' until POST_SIM state reached
Date: Tue, 18 Dec 2012 18:28:43 +0100	[thread overview]
Message-ID: <50D0A7CB.8030707@southpole.se> (raw)
In-Reply-To: <1354636010-9624-1-git-send-email-jonas@southpole.se>

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

Hi Christopher,

>
>   plugins/telit.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++----
>   1 file changed, 60 insertions(+), 4 deletions(-)
>
> diff --git a/plugins/telit.c b/plugins/telit.c
> index fe2ccd6..a0f7deb 100644
> --- a/plugins/telit.c
> +++ b/plugins/telit.c
> @@ -62,6 +62,7 @@
>   
>   static const char *none_prefix[] = { NULL };
>   static const char *rsen_prefix[]= { "#RSEN:", NULL };
> +static const char *qss_prefix[] = { "#QSS:", NULL };
>   
>   struct telit_data {
>   	GAtChat *chat;		/* AT chat */
> @@ -219,7 +220,7 @@ static void switch_sim_state_status(struct ofono_modem *modem, int status)
>   
>   	switch (status) {
>   	case 0:	/* SIM not inserted */
> -		if (data->have_sim == TRUE) {
> +		if (data->have_sim == TRUE && ofono_modem_get_online(modem)) {
>   			ofono_sim_inserted_notify(data->sim, FALSE);
>   			data->have_sim = FALSE;
>   			data->sms_phonebook_added = FALSE;
> @@ -233,6 +234,14 @@ static void switch_sim_state_status(struct ofono_modem *modem, int status)
>   		}
>   		break;
>   	case 3:	/* SIM inserted, SMS and phonebook ready */
> +		/* It's possible that we arrive at QSS=3 state without
> +		 * ever seeing QSS=2, so we need to make sure that we've
> +		 * also done the QSS=2 work, as well
> +		 */
> +		if (data->have_sim == FALSE) {
> +			ofono_sim_inserted_notify(data->sim, TRUE);
> +			data->have_sim = TRUE;
> +		}
>   		if (data->sms_phonebook_added == FALSE) {
>   			ofono_phonebook_create(modem, 0, "atmodem", data->chat);
>   			ofono_sms_create(modem, 0, "atmodem", data->chat);
> @@ -245,6 +254,28 @@ static void switch_sim_state_status(struct ofono_modem *modem, int status)
>   	}
>   }
>   
> +/*
> + * telit_qss_cb gets invoked once when querying the QSS status immediately
> + * after enabling the modem.
> + */
> +static void telit_qss_cb(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> +	struct ofono_modem *modem = user_data;
> +	int mode;
> +	int status;
> +	GAtResultIter iter;
> +
> +	g_at_result_iter_init(&iter, result);
> +
> +	DBG("%p", modem);
> +	if (!g_at_result_iter_next(&iter, "#QSS:"))
> +		return;
> +	g_at_result_iter_next_number(&iter, &mode);
> +	g_at_result_iter_next_number(&iter, &status);
> +
> +	switch_sim_state_status(modem, status);
> +}
> +
>   static void telit_qss_notify(GAtResult *result, gpointer user_data)
>   {
>   	struct ofono_modem *modem = user_data;
> @@ -304,6 +335,12 @@ static void cfun_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
>   
>   	/* Enable sim state notification */
>   	g_at_chat_send(data->chat, "AT#QSS=2", none_prefix, NULL, NULL, NULL);
> +
> +	/* Query current sim state so that we don't need to wait a long
> +	 * time for a notification in case SIM state is already 'ready'
> +	 */
> +	g_at_chat_send(data->chat, "AT#QSS?", qss_prefix,
> +				telit_qss_cb, modem, NULL);
>   }
>   
>   static int telit_enable(struct ofono_modem *modem)
> @@ -334,12 +371,19 @@ static int telit_enable(struct ofono_modem *modem)
>   
>   	/*
>   	 * Disable sim state notification so that we sure get a notification
> -	 * when we enable it again later and don't have to query it.
> +	 * when we enable it again later and don't have to query it.  For
> +	 * the HE910, this doesn't seem to work... querying appears to be
> +	 * necessary as there will be no notification unless there is an
> +	 * actual _change_ of state.
>   	 */
>   	g_at_chat_send(data->chat, "AT#QSS=0", none_prefix, NULL, NULL, NULL);
>   
> -	/* Set phone functionality */
> -	g_at_chat_send(data->chat, "AT+CFUN=4", none_prefix,
> +	/* Set phone functionality.
> +	 * When enabling the modem, we need to have the modem powered
> +	 * up until we've been able to get to post_sim state... for this
> +	 * reason, we start off with CFUN=4
> +	 */
> +	g_at_chat_send(data->chat, "AT+CFUN=1", none_prefix,
>   				cfun_enable_cb, modem, NULL);
>   
>   	return -EINPROGRESS;
> @@ -565,6 +609,10 @@ static void telit_post_sim(struct ofono_modem *modem)
>   
>   	if (gprs && gc)
>   		ofono_gprs_add_context(gprs, gc);
> +
> +	if (!ofono_modem_get_online(modem))
> +		g_at_chat_send(data->chat, "AT+CFUN=4", none_prefix,
> +				NULL, NULL, NULL);
>   }
>   
>   static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
> @@ -588,6 +636,14 @@ static void telit_set_online(struct ofono_modem *modem, ofono_bool_t online,
>   
>   	g_at_chat_send(data->chat, command, none_prefix, set_online_cb,
>   						cbd, g_free);
> +
> +	if (online) {
> +		/* Query current sim state in case it changed while we
> +		 * were offline and ignoring the QSS: 0 reports.
> +		 */
> +		g_at_chat_send(data->chat, "AT#QSS?", qss_prefix,
> +					telit_qss_cb, modem, NULL);
> +	}
>   }
>   
>   static void telit_post_online(struct ofono_modem *modem)
Although this patch works for me, Is it a reasonable solution, or are 
there any better solutions for this problem?

Thanks

Mingli


-- 
Mingli Wu                       South Pole AB
Phone:  +46 8 56237100          Anderstorpsvägen 16
Mobile: +46 73 7628460          SE - 171 54 Solna
e-mail: mingli(a)southpole.se      www.southpole.se


      parent reply	other threads:[~2012-12-18 17:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-04 15:46 [PATCH 1/1] telit: stay 'online' until POST_SIM state reached Jonas Bonn
2012-12-04 16:47 ` Marcel Holtmann
2012-12-02 19:40   ` Denis Kenzior
2012-12-05  5:55 ` Denis Kenzior
2012-12-07  6:22   ` Jonas Bonn
2012-12-07  8:09     ` Jonas Bonn
2012-12-07 13:58     ` Denis Kenzior
2012-12-10 10:52       ` Christopher Vogl
2012-12-10 16:49         ` Denis Kenzior
2012-12-10 17:11           ` Christopher Vogl
2012-12-10 18:24             ` Denis Kenzior
2012-12-10 12:20       ` Christopher Vogl
2012-12-18 17:28 ` Ming Li Wu [this message]

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=50D0A7CB.8030707@southpole.se \
    --to=mingli@southpole.se \
    --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