<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">> Pushed to git master, thanks.<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Thanks!<br><br>> I suppose there is a bit of a race in the code, because:<br>> <br>> First the current SIM insertion state is checked (with AT#QSS?), and<br>> stored, and afterwards unsolicited notifications are enabled "AT#QSS=1".<br>> <br>> If a SIM eject happens between the two, then the SIM removed event<br>> wouldn't be caught, and the internal stored state would be incorrect -<br>> the fix would be to issue and parse the AT#QSS? command after the<br>> AT#QSS=1 command.  This could also serve to verify that the modem did<br>> enable hot swap notifiation.  In practise this is highly unlikely, but<br>> just thought I'd mention it.<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">and thanks Tim, you're right, I'll work on this as well<br><br><br>
</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 1 August 2017 at 10:34, 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 25/07/17 09:03, Carlo Lobrano wrote:<br>
> Currently, when SIM hot swap fails in either mm-iface or plugin, the<br>
> ModemManager still opens ports context and prints a message saying that<br>
> SIM hot swap is supported and that it's waiting for SIM insertion,<br>
> instead of clearly saying that SIM hot swap is not working.<br>
><br>
> This patch:<br>
><br>
> 1. introduces a new property MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED<br>
>    which is FALSE by default and set to TRUE only when<br>
>    setup_sim_hot_swap_finish() succeded.<br>
> 2. subordinates the completion of SIM hot swap setup (in<br>
>    mm-broadband-modem) and the related messages to the the value of<br>
>    MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED<br>
><br>
> Finally, this patch replaces the MBIM's sim_hot_swap_on private property<br>
> with the new property MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED, since they have the<br>
> same meaning.<br>
> ---<br>
><br>
> Please ignore the previous patch, since it was rebased on the wrong branch.<br>
> This one is rebased on master branch at commit<br>
> aa0a6bed363419659101084b3861a5<wbr>1144eee859<br>
><br>
<br>
</span>Pushed to git master, thanks.<br>
<div><div class="h5"><br>
> ---<br>
>  plugins/telit/mm-broadband-<wbr>modem-telit.c |  1 +<br>
>  src/mm-broadband-modem-mbim.c            | 21 ++++---<br>
>  src/mm-broadband-modem.c                 | 94 ++++++++++++++++++++++--------<wbr>--<br>
>  src/mm-iface-modem.c                     | 14 ++++-<br>
>  src/mm-iface-modem.h                     |  1 +<br>
>  5 files changed, 93 insertions(+), 38 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 e7650c0..edd9093 100644<br>
> --- a/plugins/telit/mm-broadband-<wbr>modem-telit.c<br>
> +++ b/plugins/telit/mm-broadband-<wbr>modem-telit.c<br>
> @@ -1377,6 +1377,7 @@ mm_broadband_modem_telit_new (const gchar *device,<br>
>                           MM_BASE_MODEM_VENDOR_ID, vendor_id,<br>
>                           MM_BASE_MODEM_PRODUCT_ID, product_id,<br>
>                           MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED, TRUE,<br>
> +                         MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED, FALSE,<br>
>                           NULL);<br>
>  }<br>
><br>
> diff --git a/src/mm-broadband-modem-mbim.<wbr>c b/src/mm-broadband-modem-mbim.<wbr>c<br>
> index c69893f..7f5d2fc 100644<br>
> --- a/src/mm-broadband-modem-mbim.<wbr>c<br>
> +++ b/src/mm-broadband-modem-mbim.<wbr>c<br>
> @@ -89,8 +89,6 @@ struct _MMBroadbandModemMbimPrivate {<br>
>      MbimDataClass available_data_classes;<br>
>      MbimDataClass highest_available_data_class;<br>
><br>
> -    /* For checking whether the SIM has been hot swapped */<br>
> -    gboolean sim_hot_swap_on;<br>
>      MbimSubscriberReadyState last_ready_state;<br>
>  };<br>
><br>
> @@ -1990,6 +1988,7 @@ basic_connect_notification_<wbr>subscriber_ready_status (MMBroadbandModemMbim *self,<br>
>          (self->priv->last_ready_state == MBIM_SUBSCRIBER_READY_STATE_<wbr>SIM_NOT_INSERTED &&<br>
>                 ready_state != MBIM_SUBSCRIBER_READY_STATE_<wbr>SIM_NOT_INSERTED)) {<br>
>          /* SIM has been removed or reinserted, re-probe to ensure correct interfaces are exposed */<br>
> +        mm_dbg ("SIM hot swap detected");<br>
>          mm_broadband_modem_update_sim_<wbr>hot_swap_detected (MM_BROADBAND_MODEM (self));<br>
>      }<br>
><br>
> @@ -2286,10 +2285,15 @@ cleanup_unsolicited_events_<wbr>3gpp (MMIfaceModem3gpp *_self,<br>
>                                   gpointer user_data)<br>
>  {<br>
>      MMBroadbandModemMbim *self = MM_BROADBAND_MODEM_MBIM (_self);<br>
> +    gboolean is_sim_hot_swap_configured = FALSE;<br>
> +<br>
> +    g_object_get (self,<br>
> +                  MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED, &is_sim_hot_swap_configured,<br>
> +                  NULL);<br>
><br>
>      self->priv->setup_flags &= ~PROCESS_NOTIFICATION_FLAG_<wbr>SIGNAL_QUALITY;<br>
>      self->priv->setup_flags &= ~PROCESS_NOTIFICATION_FLAG_<wbr>CONNECT;<br>
> -    if (self->priv->sim_hot_swap_on)<br>
> +    if (is_sim_hot_swap_configured)<br>
>          self->priv->setup_flags &= ~PROCESS_NOTIFICATION_FLAG_<wbr>SUBSCRIBER_INFO;<br>
>      self->priv->setup_flags &= ~PROCESS_NOTIFICATION_FLAG_<wbr>PACKET_SERVICE;<br>
>      common_setup_cleanup_<wbr>unsolicited_events (self, FALSE, callback, user_data);<br>
> @@ -2500,7 +2504,6 @@ enable_subscriber_info_<wbr>unsolicited_events_ready (MMBroadbandModemMbim *self,<br>
><br>
>      if (!common_enable_disable_<wbr>unsolicited_events_finish (self, res, &error)) {<br>
>          mm_dbg ("Failed to enable subscriber info events: %s", error->message);<br>
> -        self->priv->sim_hot_swap_on = FALSE;<br>
>          g_task_return_error (task, error);<br>
>          g_object_unref (task);<br>
>          return;<br>
> @@ -2519,7 +2522,6 @@ setup_subscriber_info_<wbr>unsolicited_events_ready (MMBroadbandModemMbim *self,<br>
><br>
>      if (!common_setup_cleanup_<wbr>unsolicited_events_finish (self, res, &error)) {<br>
>          mm_dbg ("Failed to set up subscriber info events: %s", error->message);<br>
> -        self->priv->sim_hot_swap_on = FALSE;<br>
>          g_task_return_error (task, error);<br>
>          g_object_unref (task);<br>
>          return;<br>
> @@ -2541,7 +2543,6 @@ modem_setup_sim_hot_swap (MMIfaceModem *_self,<br>
><br>
>      task = g_task_new (self, NULL, callback, user_data);<br>
><br>
> -    self->priv->sim_hot_swap_on = TRUE;<br>
>      self->priv->setup_flags |= PROCESS_NOTIFICATION_FLAG_<wbr>SUBSCRIBER_INFO;<br>
>      common_setup_cleanup_<wbr>unsolicited_events (self,<br>
>                                               TRUE,<br>
> @@ -2566,10 +2567,15 @@ modem_3gpp_disable_<wbr>unsolicited_events (MMIfaceModem3gpp *_self,<br>
>                                         gpointer user_data)<br>
>  {<br>
>      MMBroadbandModemMbim *self = MM_BROADBAND_MODEM_MBIM (_self);<br>
> +    gboolean is_sim_hot_swap_configured = FALSE;<br>
> +<br>
> +    g_object_get (self,<br>
> +                  MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED, &is_sim_hot_swap_configured,<br>
> +                  NULL);<br>
><br>
>      self->priv->enable_flags &= ~PROCESS_NOTIFICATION_FLAG_<wbr>SIGNAL_QUALITY;<br>
>      self->priv->enable_flags &= ~PROCESS_NOTIFICATION_FLAG_<wbr>CONNECT;<br>
> -    if (!self->priv->sim_hot_swap_on)<br>
> +    if (is_sim_hot_swap_configured)<br>
>          self->priv->enable_flags &= ~PROCESS_NOTIFICATION_FLAG_<wbr>SUBSCRIBER_INFO;<br>
>      self->priv->enable_flags &= ~PROCESS_NOTIFICATION_FLAG_<wbr>PACKET_SERVICE;<br>
>      common_enable_disable_<wbr>unsolicited_events (self, callback, user_data);<br>
> @@ -3154,6 +3160,7 @@ mm_broadband_modem_mbim_new (const gchar *device,<br>
>                           MM_BASE_MODEM_VENDOR_ID, vendor_id,<br>
>                           MM_BASE_MODEM_PRODUCT_ID, product_id,<br>
>                           MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED, TRUE,<br>
> +                         MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED, FALSE,<br>
>                           NULL);<br>
>  }<br>
><br>
> diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c<br>
> index d3d349e..2d2f650 100644<br>
> --- a/src/mm-broadband-modem.c<br>
> +++ b/src/mm-broadband-modem.c<br>
> @@ -116,6 +116,7 @@ enum {<br>
>      PROP_MODEM_VOICE_CALL_LIST,<br>
>      PROP_MODEM_SIMPLE_STATUS,<br>
>      PROP_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED,<br>
> +    PROP_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED,<br>
>      PROP_FLOW_CONTROL,<br>
>      PROP_LAST<br>
>  };<br>
> @@ -134,6 +135,7 @@ struct _MMBroadbandModemPrivate {<br>
>      PortsContext *sim_hot_swap_ports_ctx;<br>
>      gboolean modem_init_run;<br>
>      gboolean sim_hot_swap_supported;<br>
> +    gboolean sim_hot_swap_configured;<br>
><br>
>      /*<--- Modem interface --->*/<br>
>      /* Properties */<br>
> @@ -10098,27 +10100,38 @@ initialize_step (GTask *task)<br>
>           * (we may be re-running the initialization step after SIM-PIN unlock) */<br>
>          if (!ctx->self->priv->sim_hot_<wbr>swap_ports_ctx) {<br>
>              gboolean is_sim_hot_swap_supported = FALSE;<br>
> +            gboolean is_sim_hot_swap_configured = FALSE;<br>
><br>
>              g_object_get (ctx->self,<br>
>                            MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED, &is_sim_hot_swap_supported,<br>
>                            NULL);<br>
><br>
> +            g_object_get (ctx->self,<br>
> +                          MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED, &is_sim_hot_swap_configured,<br>
> +                          NULL);<br>
> +<br>
>              if (is_sim_hot_swap_supported) {<br>
> -                PortsContext *ports;<br>
> -                GError *error = NULL;<br>
><br>
> -                mm_dbg ("Creating ports context for SIM hot swap");<br>
> +                if (!is_sim_hot_swap_configured) {<br>
> +                    mm_warn ("SIM hot swap supported but not configured. Skipping opening ports");<br>
> +                } else {<br>
> +                    PortsContext *ports;<br>
> +                    GError *error = NULL;<br>
><br>
> -                ports = g_new0 (PortsContext, 1);<br>
> -                ports->ref_count = 1;<br>
> +                    mm_dbg ("Creating ports context for SIM hot swap");<br>
><br>
> -                if (!open_ports_enabling (ctx->self, ports, FALSE, &error)) {<br>
> -                    mm_warn ("Couldn't open ports during Modem SIM hot swap enabling: %s", error? error->message : "unknown reason");<br>
> -                    g_error_free (error);<br>
> -                } else<br>
> -                    ctx->self->priv->sim_hot_swap_<wbr>ports_ctx = ports_context_ref (ports);<br>
> +                    ports = g_new0 (PortsContext, 1);<br>
> +                    ports->ref_count = 1;<br>
><br>
> -                ports_context_unref (ports);<br>
> +                    if (!open_ports_enabling (ctx->self, ports, FALSE, &error)) {<br>
> +                        mm_warn ("Couldn't open ports during Modem SIM hot swap enabling: %s", error? error->message : "unknown reason");<br>
> +                        g_error_free (error);<br>
> +                    } else {<br>
> +                        ctx->self->priv->sim_hot_swap_<wbr>ports_ctx = ports_context_ref (ports);<br>
> +                    }<br>
> +<br>
> +                    ports_context_unref (ports);<br>
> +                }<br>
>              }<br>
>          } else<br>
>              mm_dbg ("Ports context for SIM hot swap already available");<br>
> @@ -10146,32 +10159,44 @@ initialize_step (GTask *task)<br>
>              } else {<br>
>                  /* Fatal SIM, firmware, or modem failure :-( */<br>
>                  gboolean is_sim_hot_swap_supported = FALSE;<br>
> +                gboolean is_sim_hot_swap_configured = FALSE;<br>
> +<br>
>                  MMModemStateFailedReason reason =<br>
>                      mm_gdbus_modem_get_state_<wbr>failed_reason (<br>
>                          (MmGdbusModem*)ctx->self-><wbr>priv->modem_dbus_skeleton);<br>
><br>
>                  g_object_get (ctx->self,<br>
> -                             MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED,<br>
> -                             &is_sim_hot_swap_supported,<br>
> -                             NULL);<br>
> -<br>
> -                if (reason == MM_MODEM_STATE_FAILED_REASON_<wbr>SIM_MISSING &&<br>
> -                    is_sim_hot_swap_supported &&<br>
> -                    ctx->self->priv->sim_hot_swap_<wbr>ports_ctx) {<br>
> -                    mm_info ("SIM is missing, but the modem supports SIM hot swap. Waiting for SIM...");<br>
> -                    error = g_error_new (MM_CORE_ERROR,<br>
> -                                         MM_CORE_ERROR_WRONG_STATE,<br>
> -                                         "Modem is unusable due to SIM missing, "<br>
> -                                         "cannot fully initialize, "<br>
> -                                         "waiting for SIM insertion.");<br>
> -                } else {<br>
> -                    mm_dbg ("SIM is missing and Modem does not support SIM Hot Swap");<br>
> -                    error = g_error_new (MM_CORE_ERROR,<br>
> -                                         MM_CORE_ERROR_WRONG_STATE,<br>
> -                                         "Modem is unusable, "<br>
> -                                         "cannot fully initialize");<br>
> +                              MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED,<br>
> +                              &is_sim_hot_swap_supported,<br>
> +                              NULL);<br>
> +<br>
> +                g_object_get (ctx->self,<br>
> +                              MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED,<br>
> +                              &is_sim_hot_swap_configured,<br>
> +                              NULL);<br>
> +<br>
> +                if (reason == MM_MODEM_STATE_FAILED_REASON_<wbr>SIM_MISSING) {<br>
> +                    if (!is_sim_hot_swap_supported) {<br>
> +                        mm_dbg ("SIM is missing, but this modem does not support SIM hot swap.");<br>
> +                    } else if (!is_sim_hot_swap_configured) {<br>
> +                        mm_warn ("SIM is missing, but SIM hot swap could not be configured.");<br>
> +                    } else if (!ctx->self->priv->sim_hot_<wbr>swap_ports_ctx) {<br>
> +                        mm_err ("SIM is missing and SIM hot swap is configured, but ports are not opened.");<br>
> +                    } else {<br>
> +                        mm_dbg ("SIM is missing, but SIM hot swap is enabled. Waiting for SIM...");<br>
> +                        error = g_error_new (MM_CORE_ERROR,<br>
> +                                             MM_CORE_ERROR_WRONG_STATE,<br>
> +                                             "Modem is unusable due to SIM missing, "<br>
> +                                             "cannot fully initialize, waiting for SIM insertion.");<br>
> +                        goto sim_hot_swap_enabled;<br>
> +                    }<br>
>                  }<br>
><br>
> +                error = g_error_new (MM_CORE_ERROR,<br>
> +                                     MM_CORE_ERROR_WRONG_STATE,<br>
> +                                     "Modem is unusable, "<br>
> +                                     "cannot fully initialize");<br>
> +sim_hot_swap_enabled:<br>
>                  /* Ensure we only leave the Modem, OMA, and Firmware interfaces<br>
>                   * around.  A failure could be caused by firmware issues, which<br>
>                   * a firmware update, switch, or provisioning could fix.<br>
> @@ -10498,6 +10523,9 @@ set_property (GObject *object,<br>
>      case PROP_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED:<br>
>          self->priv->sim_hot_swap_<wbr>supported = g_value_get_boolean (value);<br>
>          break;<br>
> +    case PROP_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED:<br>
> +        self->priv->sim_hot_swap_<wbr>configured = g_value_get_boolean (value);<br>
> +        break;<br>
>      default:<br>
>          G_OBJECT_WARN_INVALID_<wbr>PROPERTY_ID (object, prop_id, pspec);<br>
>          break;<br>
> @@ -10603,6 +10631,9 @@ get_property (GObject *object,<br>
>      case PROP_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED:<br>
>          g_value_set_boolean (value, self->priv->sim_hot_swap_<wbr>supported);<br>
>          break;<br>
> +    case PROP_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED:<br>
> +        g_value_set_boolean (value, self->priv->sim_hot_swap_<wbr>configured);<br>
> +        break;<br>
>      case PROP_FLOW_CONTROL:<br>
>          g_value_set_flags (value, self->priv->flow_control);<br>
>          break;<br>
> @@ -11102,6 +11133,9 @@ mm_broadband_modem_class_init (MMBroadbandModemClass *klass)<br>
>                                        PROP_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED,<br>
>                                        MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED);<br>
><br>
> +    g_object_class_override_<wbr>property (object_class,<br>
> +                                      PROP_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED,<br>
> +                                      MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED);<br>
>      properties[PROP_FLOW_CONTROL] =<br>
>          g_param_spec_flags (MM_BROADBAND_MODEM_FLOW_<wbr>CONTROL,<br>
>                              "Flow control",<br>
> diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c<br>
> index d59303a..ec453a8 100644<br>
> --- a/src/mm-iface-modem.c<br>
> +++ b/src/mm-iface-modem.c<br>
> @@ -4335,6 +4335,9 @@ setup_sim_hot_swap_ready (MMIfaceModem *self,<br>
>          g_error_free (error);<br>
>      } else {<br>
>          mm_dbg ("Iface modem: SIM hot swap setup succeded");<br>
> +        g_object_set (self,<br>
> +                      MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED, TRUE,<br>
> +                      NULL);<br>
>      }<br>
><br>
>      /* Go on to next step */<br>
> @@ -4880,8 +4883,9 @@ interface_initialization_step (GTask *task)<br>
>                                MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED, &is_sim_hot_swap_supported,<br>
>                                NULL);<br>
><br>
> -                if (is_sim_hot_swap_supported)<br>
> +                if (is_sim_hot_swap_supported) {<br>
>                      mm_iface_modem_update_failed_<wbr>state (self, MM_MODEM_STATE_FAILED_REASON_<wbr>SIM_MISSING);<br>
> +                }<br>
>              }<br>
>          } else {<br>
>              /* We are done without errors!<br>
> @@ -5284,6 +5288,7 @@ iface_modem_init (gpointer g_iface)<br>
>                                "List of bearers handled by the modem",<br>
>                                MM_TYPE_BEARER_LIST,<br>
>                                G_PARAM_READWRITE));<br>
> +<br>
>      g_object_interface_install_<wbr>property<br>
>          (g_iface,<br>
>           g_param_spec_boolean (MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED,<br>
> @@ -5292,6 +5297,13 @@ iface_modem_init (gpointer g_iface)<br>
>                                 FALSE,<br>
>                                 G_PARAM_READWRITE));<br>
><br>
> +    g_object_interface_install_<wbr>property<br>
> +        (g_iface,<br>
> +         g_param_spec_boolean (MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED,<br>
> +                               "Sim Hot Swap Configured",<br>
> +                               "Whether the sim hot swap support is configured correctly.",<br>
> +                               FALSE,<br>
> +                               G_PARAM_READWRITE));<br>
>      initialized = TRUE;<br>
>  }<br>
><br>
> diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h<br>
> index 17ded5b..711d2f2 100644<br>
> --- a/src/mm-iface-modem.h<br>
> +++ b/src/mm-iface-modem.h<br>
> @@ -37,6 +37,7 @@<br>
>  #define MM_IFACE_MODEM_SIM                     "iface-modem-sim"<br>
>  #define MM_IFACE_MODEM_BEARER_LIST             "iface-modem-bearer-list"<br>
>  #define MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>SUPPORTED  "iface-modem-sim-hot-swap-<wbr>supported"<br>
> +#define MM_IFACE_MODEM_SIM_HOT_SWAP_<wbr>CONFIGURED "iface-modem-sim-hot-swap-<wbr>configured"<br>
><br>
>  typedef struct _MMIfaceModem MMIfaceModem;<br>
><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>