<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">> <span style="color:rgb(0,0,0);font-size:12.8px;font-family:arial,sans-serif">Is this previous part really needed? Is there any case in which a LOCK</span></div><span style="color:rgb(0,0,0);font-size:12.8px">command would succeed but then UNLOCK command report a "not supported"</span><br style="color:rgb(0,0,0);font-size:12.8px"><span style="color:rgb(0,0,0);font-size:12.8px">error? I guess it doesn't harm to have this, though, your call.</span><div><span style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0);font-size:12.8px"><br></span></div><div><span style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0);font-size:12.8px"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">​Right, there is no real need for this, but just for completeness I prefer to keep it, if you don't mind</div></span></div><div><span style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0);font-size:12.8px"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">​</div>​</span></div><div><span style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0);font-size:12.8px">><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">​ </div></span><span style="color:rgb(0,0,0);font-size:12.8px">Looks like csim_lock_support isn't set anywhere to FEATURE_SUPPORTED? It</span></div><div><span style="color:rgb(0,0,0);font-size:12.8px">should be set here I believe.</span><span style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0);font-size:12.8px"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">​</div></span></div><div><span style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0);font-size:12.8px"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline"><br></div></span></div><div><span style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0);font-size:12.8px"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">Doh!<br>I'll fix it :D</div></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 10 April 2017 at 13:25, Aleksander Morgado <span dir="ltr"><<a href="mailto:aleksander@aleksander.es" target="_blank">aleksander@aleksander.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 10/04/17 12:25, Carlo Lobrano wrote:<br>
> Some modems do not support CSIM lock/unlock, but they do support<br>
> querying SIM unlock retries through +CSIM command.<br>
><br>
> If CSIM lock returns with "unsupported command" do not propagate<br>
> the error and continue with the other CSIM queries instead, moreover the<br>
> CSIM lock feature is signed as FEATURE_UNSUPPORTED in Telit modem<br>
> private structure to prevent being sent again (e.g. calling CSIM<br>
> unlock AT command).<br>
> ---<br>
><br>
> Hi Aleksander,<br>
><br>
> I added private structure to store whether csim lock is supported or not (and so<br>
> skip the command). Let me know if this is ok now.<br>
><br>
<br>
</span>See below.<br>
<div><div class="h5"><br>
> Carlo<br>
><br>
> ---<br>
>  plugins/telit/mm-broadband-<wbr>modem-telit.c | 86 ++++++++++++++++++++++++++----<wbr>--<br>
>  plugins/telit/mm-broadband-<wbr>modem-telit.h |  2 +<br>
>  2 files changed, 72 insertions(+), 16 deletions(-)<br>
><br>
> diff --git a/plugins/telit/mm-broadband-<wbr>modem-telit.c b/plugins/telit/mm-broadband-<wbr>modem-telit.c<br>
> index cce0229..841a48b 100644<br>
> --- a/plugins/telit/mm-broadband-<wbr>modem-telit.c<br>
> +++ b/plugins/telit/mm-broadband-<wbr>modem-telit.c<br>
> @@ -42,6 +42,15 @@ G_DEFINE_TYPE_EXTENDED (MMBroadbandModemTelit, mm_broadband_modem_telit, MM_TYPE<br>
>                          G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init)<br>
>                          G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init));<br>
><br>
> +typedef enum {<br>
> +    FEATURE_SUPPORT_UNKNOWN,<br>
> +    FEATURE_NOT_SUPPORTED,<br>
> +    FEATURE_SUPPORTED<br>
> +} FeatureSupport;<br>
> +<br>
> +struct _MMBroadbandModemTelitPrivate {<br>
> +    FeatureSupport csim_lock_support;<br>
> +};<br>
><br>
>  /*****************************<wbr>******************************<wbr>******************/<br>
>  /* After Sim Unlock (Modem interface) */<br>
> @@ -521,6 +530,11 @@ csim_unlock_ready (MMBaseModem              *self,<br>
>      /* Ignore errors */<br>
>      response = mm_base_modem_at_command_<wbr>finish (self, res, &error);<br>
>      if (!response) {<br>
> +        if (g_error_matches (error,<br>
> +                             MM_MOBILE_EQUIPMENT_ERROR,<br>
> +                             MM_MOBILE_EQUIPMENT_ERROR_NOT_<wbr>SUPPORTED)) {<br>
> +            ctx->self->priv->csim_lock_<wbr>support = FEATURE_NOT_SUPPORTED;<br>
> +        }<br>
<br>
</div></div>Is this previous part really needed? Is there any case in which a LOCK<br>
command would succeed but then UNLOCK command report a "not supported"<br>
error? I guess it doesn't harm to have this, though, your call.<br>
<span class=""><br>
>          mm_warn ("Couldn't unlock SIM card: %s", error->message);<br>
>          g_error_free (error);<br>
>      }<br>
> @@ -591,10 +605,18 @@ csim_lock_ready (MMBaseModem              *self,<br>
><br>
>      response = mm_base_modem_at_command_<wbr>finish (self, res, &error);<br>
>      if (!response) {<br>
> -        g_prefix_error (&error, "Couldn't lock SIM card: ");<br>
> -        g_simple_async_result_take_<wbr>error (ctx->result, error);<br>
> -        load_unlock_retries_context_<wbr>complete_and_free (ctx);<br>
> -        return;<br>
> +        if (g_error_matches (error,<br>
> +                             MM_MOBILE_EQUIPMENT_ERROR,<br>
> +                             MM_MOBILE_EQUIPMENT_ERROR_NOT_<wbr>SUPPORTED)) {<br>
> +            ctx->self->priv->csim_lock_<wbr>support = FEATURE_NOT_SUPPORTED;<br>
> +            mm_warn ("Couldn't lock SIM card: %s. Continuing without CSIM lock.", error->message);<br>
> +            g_error_free (error);<br>
> +        } else {<br>
> +            g_prefix_error (&error, "Couldn't lock SIM card: ");<br>
> +            g_simple_async_result_take_<wbr>error (ctx->result, error);<br>
> +            load_unlock_retries_context_<wbr>complete_and_free (ctx);<br>
> +            return;<br>
> +        }<br>
>      }<br>
<br>
<br>
</span>Looks like csim_lock_support isn't set anywhere to FEATURE_SUPPORTED? It<br>
should be set here I believe.<br>
<div><div class="h5"><br>
><br>
>      ctx->step++;<br>
> @@ -602,6 +624,40 @@ csim_lock_ready (MMBaseModem              *self,<br>
>  }<br>
><br>
>  static void<br>
> +handle_csim_locking (LoadUnlockRetriesContext *ctx, gboolean is_lock)<br>
> +{<br>
> +    switch (ctx->self->priv->csim_lock_<wbr>support) {<br>
> +        case FEATURE_SUPPORT_UNKNOWN:<br>
> +        case FEATURE_SUPPORTED:<br>
> +            if (is_lock) {<br>
> +                mm_base_modem_at_command (MM_BASE_MODEM (ctx->self),<br>
> +                                          CSIM_LOCK_STR,<br>
> +                                          CSIM_QUERY_TIMEOUT,<br>
> +                                          FALSE,<br>
> +                                          (GAsyncReadyCallback) csim_lock_ready,<br>
> +                                          ctx);<br>
> +            } else {<br>
> +                mm_base_modem_at_command (MM_BASE_MODEM (ctx->self),<br>
> +                                          CSIM_UNLOCK_STR,<br>
> +                                          CSIM_QUERY_TIMEOUT,<br>
> +                                          FALSE,<br>
> +                                          (GAsyncReadyCallback) csim_unlock_ready,<br>
> +                                          ctx);<br>
> +            }<br>
> +            break;<br>
> +        case FEATURE_NOT_SUPPORTED:<br>
> +            mm_dbg ("CSIM lock not supported by this modem. Skipping %s command",<br>
> +                    is_lock ? "lock" : "unlock");<br>
> +            ctx->step++;<br>
> +            load_unlock_retries_step (ctx);<br>
> +            break;<br>
> +        default:<br>
> +            g_assert_not_reached ();<br>
> +            break;<br>
> +    }<br>
> +}<br>
> +<br>
> +static void<br>
>  load_unlock_retries_step (LoadUnlockRetriesContext *ctx)<br>
>  {<br>
>      switch (ctx->step) {<br>
> @@ -609,12 +665,7 @@ load_unlock_retries_step (LoadUnlockRetriesContext *ctx)<br>
>              /* Fall back on next step */<br>
>              ctx->step++;<br>
>          case LOAD_UNLOCK_RETRIES_STEP_LOCK:<br>
> -            mm_base_modem_at_command (MM_BASE_MODEM (ctx->self),<br>
> -                                      CSIM_LOCK_STR,<br>
> -                                      CSIM_QUERY_TIMEOUT,<br>
> -                                      FALSE,<br>
> -                                      (GAsyncReadyCallback) csim_lock_ready,<br>
> -                                      ctx);<br>
> +            handle_csim_locking (ctx, TRUE);<br>
>              break;<br>
>          case LOAD_UNLOCK_RETRIES_STEP_PIN:<br>
>              mm_base_modem_at_command (MM_BASE_MODEM (ctx->self),<br>
> @@ -649,12 +700,7 @@ load_unlock_retries_step (LoadUnlockRetriesContext *ctx)<br>
>                                        ctx);<br>
>              break;<br>
>          case LOAD_UNLOCK_RETRIES_STEP_<wbr>UNLOCK:<br>
> -            mm_base_modem_at_command (MM_BASE_MODEM (ctx->self),<br>
> -                                      CSIM_UNLOCK_STR,<br>
> -                                      CSIM_QUERY_TIMEOUT,<br>
> -                                      FALSE,<br>
> -                                      (GAsyncReadyCallback) csim_unlock_ready,<br>
> -                                      ctx);<br>
> +            handle_csim_locking (ctx, FALSE);<br>
>              break;<br>
>          case LOAD_UNLOCK_RETRIES_STEP_LAST:<br>
>              if (ctx->succeded_requests == 0) {<br>
> @@ -1220,6 +1266,11 @@ mm_broadband_modem_telit_new (const gchar *device,<br>
>  static void<br>
>  mm_broadband_modem_telit_init (MMBroadbandModemTelit *self)<br>
>  {<br>
> +    self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,<br>
> +                                              MM_TYPE_BROADBAND_MODEM_TELIT,<br>
> +                                              MMBroadbandModemTelitPrivate);<br>
> +<br>
> +    self->priv->csim_lock_support = FEATURE_SUPPORT_UNKNOWN;<br>
>  }<br>
><br>
>  static void<br>
> @@ -1263,4 +1314,7 @@ iface_modem_3gpp_init (MMIfaceModem3gpp *iface)<br>
>  static void<br>
>  mm_broadband_modem_telit_<wbr>class_init (MMBroadbandModemTelitClass *klass)<br>
>  {<br>
> +    GObjectClass *object_class = G_OBJECT_CLASS (klass);<br>
> +<br>
> +    g_type_class_add_private (object_class, sizeof (MMBroadbandModemTelitPrivate)<wbr>);<br>
>  }<br>
> diff --git a/plugins/telit/mm-broadband-<wbr>modem-telit.h b/plugins/telit/mm-broadband-<wbr>modem-telit.h<br>
> index 50e6365..f68465e 100644<br>
> --- a/plugins/telit/mm-broadband-<wbr>modem-telit.h<br>
> +++ b/plugins/telit/mm-broadband-<wbr>modem-telit.h<br>
> @@ -29,9 +29,11 @@<br>
><br>
>  typedef struct _MMBroadbandModemTelit MMBroadbandModemTelit;<br>
>  typedef struct _MMBroadbandModemTelitClass MMBroadbandModemTelitClass;<br>
> +typedef struct _MMBroadbandModemTelitPrivate MMBroadbandModemTelitPrivate;<br>
><br>
>  struct _MMBroadbandModemTelit {<br>
>      MMBroadbandModem parent;<br>
> +    MMBroadbandModemTelitPrivate *priv;<br>
>  };<br>
><br>
>  struct _MMBroadbandModemTelitClass{<br>
><br>
<br>
<br>
--<br>
</div></div>Aleksander<br>
<a href="https://aleksander.es" rel="noreferrer" target="_blank">https://aleksander.es</a><br>
</blockquote></div><br></div>