Re: [MM] [PATCH] broadband-modem: retry +CPIN? when SIM is busy
- From: Aleksander Morgado <aleksander lanedo com>
- To: Ben Chan <benchan chromium org>
- Cc: networkmanager-list gnome org
- Subject: Re: [MM] [PATCH] broadband-modem: retry +CPIN? when SIM is busy
- Date: Thu, 09 Aug 2012 09:41:09 +0200
Hey Ben,
> When the modem checks if a SIM requires unlock, the SIM may not be
> ready. This patch modifies modem_load_unlock_required to retry +CPIN?
> under that scenario.
The logic to retry the unlock check is kept in the Modem interface file,
mm-iface-modem.c, see mm_iface_modem_unlock_check(), and it should
already be doing the retries, even with the 2 second delay between
retries. Didn't that work for you? Do you have debug logs of a case
where it didn't work?
> ---
> src/mm-broadband-modem.c | 70 +++++++++++++++++++++++++++++++++++++--------
> 1 files changed, 57 insertions(+), 13 deletions(-)
>
> diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c
> index edc9507..53bce9b 100644
> --- a/src/mm-broadband-modem.c
> +++ b/src/mm-broadband-modem.c
> @@ -816,6 +816,21 @@ static CPinResult unlock_results[] = {
> { NULL }
> };
>
> +typedef struct {
> + MMIfaceModem *self;
> + GSimpleAsyncResult *result;
> + guint retries;
> +} ModemLoadUnlockRequiredContext;
> +
> +static void
> +modem_load_unlock_required_context_complete_and_free (ModemLoadUnlockRequiredContext *ctx)
> +{
> + g_simple_async_result_complete (ctx->result);
> + g_object_unref (ctx->result);
> + g_object_unref (ctx->self);
> + g_free (ctx);
> +}
> +
> static MMModemLock
> modem_load_unlock_required_finish (MMIfaceModem *self,
> GAsyncResult *res,
> @@ -828,10 +843,20 @@ modem_load_unlock_required_finish (MMIfaceModem *self,
> G_SIMPLE_ASYNC_RESULT (res)));
> }
>
> +static void modem_load_unlock_required_context_step (ModemLoadUnlockRequiredContext *ctx);
> +
> +static gboolean
> +cpin_timeout_cb (ModemLoadUnlockRequiredContext *ctx)
> +{
> + ctx->retries--;
> + modem_load_unlock_required_context_step (ctx);
> + return FALSE;
> +}
> +
> static void
> cpin_query_ready (MMIfaceModem *self,
> GAsyncResult *res,
> - GSimpleAsyncResult *simple)
> + ModemLoadUnlockRequiredContext *ctx)
> {
>
> MMModemLock lock = MM_MODEM_LOCK_UNKNOWN;
> @@ -840,9 +865,17 @@ cpin_query_ready (MMIfaceModem *self,
>
> result = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
> if (error) {
> - g_simple_async_result_take_error (simple, error);
> - g_simple_async_result_complete (simple);
> - g_object_unref (simple);
> + if (ctx->retries > 0 &&
> + g_error_matches (error,
> + MM_MOBILE_EQUIPMENT_ERROR,
> + MM_MOBILE_EQUIPMENT_ERROR_SIM_BUSY)) {
> + g_error_free (error);
> + /* Retry in 2 seconds */
> + g_timeout_add_seconds (2, (GSourceFunc)cpin_timeout_cb, ctx);
> + } else {
> + g_simple_async_result_take_error (ctx->result, error);
> + modem_load_unlock_required_context_complete_and_free (ctx);
> + }
> return;
> }
>
> @@ -870,11 +903,21 @@ cpin_query_ready (MMIfaceModem *self,
> }
> }
>
> - g_simple_async_result_set_op_res_gpointer (simple,
> + g_simple_async_result_set_op_res_gpointer (ctx->result,
> GUINT_TO_POINTER (lock),
> NULL);
> - g_simple_async_result_complete (simple);
> - g_object_unref (simple);
> + modem_load_unlock_required_context_complete_and_free (ctx);
> +}
> +
> +static void
> +modem_load_unlock_required_context_step (ModemLoadUnlockRequiredContext *ctx)
> +{
> + mm_base_modem_at_command (MM_BASE_MODEM (ctx->self),
> + "+CPIN?",
> + 3,
> + FALSE,
> + (GAsyncReadyCallback)cpin_query_ready,
> + ctx);
> }
>
> static void
> @@ -882,6 +925,7 @@ modem_load_unlock_required (MMIfaceModem *self,
> GAsyncReadyCallback callback,
> gpointer user_data)
> {
> + ModemLoadUnlockRequiredContext *ctx;
> GSimpleAsyncResult *result;
>
> result = g_simple_async_result_new (G_OBJECT (self),
> @@ -900,13 +944,13 @@ modem_load_unlock_required (MMIfaceModem *self,
> return;
> }
>
> + ctx = g_new0 (ModemLoadUnlockRequiredContext, 1);
> + ctx->self = g_object_ref (self);
> + ctx->retries = 3;
> + ctx->result = result;
> +
> mm_dbg ("checking if unlock required...");
> - mm_base_modem_at_command (MM_BASE_MODEM (self),
> - "+CPIN?",
> - 3,
> - FALSE,
> - (GAsyncReadyCallback)cpin_query_ready,
> - result);
> + modem_load_unlock_required_context_step (ctx);
> }
>
> /*****************************************************************************/
>
--
Aleksander
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]