* [PATCH] zte: poll sim before sim_inserted_notify
@ 2010-12-16 18:36 Pekka.Pessi
2010-12-16 18:45 ` Gustavo F. Padovan
0 siblings, 1 reply; 2+ messages in thread
From: Pekka.Pessi @ 2010-12-16 18:36 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2516 bytes --]
From: Pekka Pessi <Pekka.Pessi@nokia.com>
Ensure that SIM is ready before calling ofono_sim_inserted_notify().
---
plugins/zte.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/plugins/zte.c b/plugins/zte.c
index 82f322a..50f6280 100644
--- a/plugins/zte.c
+++ b/plugins/zte.c
@@ -55,6 +55,9 @@ struct zte_data {
GAtChat *aux;
struct ofono_gprs *gprs;
struct ofono_gprs_context *gc;
+ struct ofono_sim *sim;
+ guint poll_source;
+ guint poll_count;
};
static int zte_probe(struct ofono_modem *modem)
@@ -221,6 +224,13 @@ static int zte_disable(struct ofono_modem *modem)
if (data->aux == NULL)
return 0;
+ data->sim = NULL;
+
+ if (data->poll_source) {
+ g_source_remove(data->poll_source);
+ data->poll_source = 0;
+ }
+
g_at_chat_cancel_all(data->aux);
g_at_chat_unregister_all(data->aux);
g_at_chat_send(data->aux, "AT+CFUN=0", none_prefix,
@@ -262,19 +272,56 @@ error:
CALLBACK_WITH_FAILURE(cb, cbd->data);
}
+static gboolean poll_sim(gpointer user_data);
+
+static void sim_poll_result(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ struct ofono_modem *modem = user_data;
+ struct zte_data *data = ofono_modem_get_data(modem);
+
+ DBG("%p", modem);
+
+ if (ok) {
+ ofono_sim_inserted_notify(data->sim, ok);
+ return;
+ }
+
+ if (++data->poll_count > 5)
+ /* Give up after 5 seconds - there is probably no SIM */
+ return;
+
+ data->poll_source = g_timeout_add_seconds(1, poll_sim, modem);
+}
+
+static gboolean poll_sim(gpointer user_data)
+{
+ struct ofono_modem *modem = user_data;
+ struct zte_data *data = ofono_modem_get_data(modem);
+
+ DBG("%p", modem);
+
+ data->poll_source = 0;
+
+ g_at_chat_send(data->aux, "AT+CPIN?", none_prefix,
+ sim_poll_result, modem, NULL);
+
+ return FALSE;
+}
+
static void zte_pre_sim(struct ofono_modem *modem)
{
struct zte_data *data = ofono_modem_get_data(modem);
- struct ofono_sim *sim;
DBG("%p", modem);
ofono_devinfo_create(modem, 0, "atmodem", data->aux);
- sim = ofono_sim_create(modem, OFONO_VENDOR_QUALCOMM_MSM,
- "atmodem", data->aux);
- if (sim)
- ofono_sim_inserted_notify(sim, TRUE);
+ data->poll_count = 0;
+
+ data->sim = ofono_sim_create(modem, OFONO_VENDOR_QUALCOMM_MSM,
+ "atmodem", data->aux);
+ if (data->sim)
+ poll_sim(modem);
}
static void zte_post_sim(struct ofono_modem *modem)
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] zte: poll sim before sim_inserted_notify
2010-12-16 18:36 [PATCH] zte: poll sim before sim_inserted_notify Pekka.Pessi
@ 2010-12-16 18:45 ` Gustavo F. Padovan
0 siblings, 0 replies; 2+ messages in thread
From: Gustavo F. Padovan @ 2010-12-16 18:45 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1863 bytes --]
Hi Pekka,
* Pekka.Pessi(a)nokia.com <Pekka.Pessi@nokia.com> [2010-12-16 20:36:39 +0200]:
> From: Pekka Pessi <Pekka.Pessi@nokia.com>
>
> Ensure that SIM is ready before calling ofono_sim_inserted_notify().
> ---
> plugins/zte.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
> 1 files changed, 52 insertions(+), 5 deletions(-)
>
> diff --git a/plugins/zte.c b/plugins/zte.c
> index 82f322a..50f6280 100644
> --- a/plugins/zte.c
> +++ b/plugins/zte.c
> @@ -55,6 +55,9 @@ struct zte_data {
> GAtChat *aux;
> struct ofono_gprs *gprs;
> struct ofono_gprs_context *gc;
> + struct ofono_sim *sim;
> + guint poll_source;
> + guint poll_count;
> };
>
> static int zte_probe(struct ofono_modem *modem)
> @@ -221,6 +224,13 @@ static int zte_disable(struct ofono_modem *modem)
> if (data->aux == NULL)
> return 0;
>
> + data->sim = NULL;
> +
> + if (data->poll_source) {
> + g_source_remove(data->poll_source);
> + data->poll_source = 0;
> + }
> +
> g_at_chat_cancel_all(data->aux);
> g_at_chat_unregister_all(data->aux);
> g_at_chat_send(data->aux, "AT+CFUN=0", none_prefix,
> @@ -262,19 +272,56 @@ error:
> CALLBACK_WITH_FAILURE(cb, cbd->data);
> }
>
> +static gboolean poll_sim(gpointer user_data);
Why not moving the whole function to here instead adding a its declaration
here.
> +
> +static void sim_poll_result(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> + struct ofono_modem *modem = user_data;
> + struct zte_data *data = ofono_modem_get_data(modem);
> +
> + DBG("%p", modem);
> +
> + if (ok) {
> + ofono_sim_inserted_notify(data->sim, ok);
> + return;
> + }
> +
> + if (++data->poll_count > 5)
> + /* Give up after 5 seconds - there is probably no SIM */
s/seconds/times/ ?
--
Gustavo F. Padovan
http://profusion.mobi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-12-16 18:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-16 18:36 [PATCH] zte: poll sim before sim_inserted_notify Pekka.Pessi
2010-12-16 18:45 ` Gustavo F. Padovan
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.