From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH 1/2] huawei: poll sim state
Date: Wed, 11 Aug 2010 18:08:58 -0500 [thread overview]
Message-ID: <4C632D8A.2080704@gmail.com> (raw)
In-Reply-To: <20100810095735.18457.31162.stgit@potku.valot.fi>
[-- Attachment #1: Type: text/plain, Size: 3208 bytes --]
Hi Kalle,
On 08/10/2010 04:57 AM, Kalle Valo wrote:
> On my Huawei E1552 when I plug in the modem (ie. cold start) with PIN locked
> SIM, the sim state is 255 (HUAWEI_SIM_STATE_NOT_EXISTENT). As the modem
> doesn't send ^SIMST notifications, poll the sim state until it's ready.
>
> In theory it might be possible to do this better, for example follow
> ^BOOT notifications or something, but it's unknown what parameter we
> should check for.
> ---
> plugins/huawei.c | 34 ++++++++++++++++++++++++++++++----
> 1 files changed, 30 insertions(+), 4 deletions(-)
>
> diff --git a/plugins/huawei.c b/plugins/huawei.c
> index f8ada24..ba66513 100644
> --- a/plugins/huawei.c
> +++ b/plugins/huawei.c
> @@ -73,8 +73,11 @@ struct huawei_data {
> enum huawei_sim_state sim_state;
> struct ofono_gprs *gprs;
> struct ofono_gprs_context *gc;
> + guint query_sim_state;
> };
>
> +static gboolean query_sim_state(gpointer user_data);
> +
> static int huawei_probe(struct ofono_modem *modem)
> {
> struct huawei_data *data;
> @@ -114,8 +117,15 @@ static void notify_sim_state(struct ofono_modem *modem,
> {
> struct huawei_data *data = ofono_modem_get_data(modem);
>
> - if (sim_state == HUAWEI_SIM_STATE_NOT_EXISTENT)
> + DBG("%d", sim_state);
> +
> + if (sim_state == HUAWEI_SIM_STATE_NOT_EXISTENT) {
> ofono_sim_inserted_notify(data->sim, FALSE);
> +
> + /* SIM is not ready, try again a bit later */
> + data->query_sim_state =
> + g_timeout_add_seconds(2, query_sim_state, modem);
> + }
Polling the sim state forever might not be a good idea if the SIM is not
inserted in the first place. You might want to give up after several
tries or so.
> else
> ofono_sim_inserted_notify(data->sim, TRUE);
>
> @@ -154,6 +164,21 @@ static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
> notify_sim_state(modem, (enum huawei_sim_state) sim_state);
> }
>
> +static gboolean query_sim_state(gpointer user_data)
> +{
> + struct ofono_modem *modem = user_data;
> + struct huawei_data *data = ofono_modem_get_data(modem);
> +
> + DBG("");
> +
> + data->query_sim_state = 0;
> +
> + g_at_chat_send(data->pcui, "AT^SYSINFO", sysinfo_prefix,
> + sysinfo_cb, modem, NULL);
> +
> + return FALSE;
> +}
> +
> static void simst_notify(GAtResult *result, gpointer user_data)
> {
> struct ofono_modem *modem = user_data;
> @@ -187,9 +212,7 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
> g_at_chat_register(data->pcui, "^SIMST:", simst_notify,
> FALSE, modem, NULL);
>
> - /* query current sim state */
> - g_at_chat_send(data->pcui, "AT^SYSINFO", sysinfo_prefix,
> - sysinfo_cb, modem, NULL);
> + query_sim_state(modem);
> }
>
> static GAtChat *create_port(const char *device)
> @@ -319,6 +342,9 @@ static int huawei_disable(struct ofono_modem *modem)
>
> DBG("%p", modem);
>
> + if (data->query_sim_state)
> + g_source_remove(data->query_sim_state);
> +
> if (data->modem) {
> g_at_chat_cancel_all(data->modem);
> g_at_chat_unregister_all(data->modem);
Otherwise patch looks good.
Regards,
-Denis
next prev parent reply other threads:[~2010-08-11 23:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-10 9:57 [PATCH 0/2] huawei: PIN unlock working with E1552 Kalle Valo
2010-08-10 9:57 ` [PATCH 1/2] huawei: poll sim state Kalle Valo
2010-08-11 23:08 ` Denis Kenzior [this message]
2010-08-13 8:11 ` Kalle Valo
2010-08-10 9:57 ` [PATCH 2/2] huawei: postpone post_sim until SIM is ready Kalle Valo
2010-08-11 23:23 ` Denis Kenzior
2010-08-13 8:15 ` Kalle Valo
2010-08-13 15:38 ` Denis Kenzior
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=4C632D8A.2080704@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 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.