[PATCH 2/2] mm-broadband-modem: trigger registration checks only after enabling all ifaces

Aleksander Morgado aleksander at aleksander.es
Wed Oct 14 11:01:29 PDT 2015


Given that the Location interface requires 3GPP info reported by the 3GPP
interface, we should only trigger registration checks once the Location
interface has been already enabled and ready to be used. If we don't do this,
we'll end up e.g. getting initial MCCMNC values but never reaching the Location
interface properly.

So, fix this by triggering all registration checks (CDMA and 3GPP) only after
having enabled all interfaces.
---
 src/mm-broadband-modem.c  | 63 +++++++++++++++++++++++++++++++++++++++++++++++
 src/mm-iface-modem-3gpp.c | 27 --------------------
 src/mm-iface-modem-cdma.c | 25 -------------------
 3 files changed, 63 insertions(+), 52 deletions(-)

diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c
index af24248..89a1280 100644
--- a/src/mm-broadband-modem.c
+++ b/src/mm-broadband-modem.c
@@ -8185,6 +8185,59 @@ enabling_started (MMBroadbandModem *self,
 }
 
 /*****************************************************************************/
+/* First registration checks */
+
+static void
+modem_3gpp_run_registration_checks_ready (MMIfaceModem3gpp *self,
+                                          GAsyncResult *res)
+{
+    GError *error = NULL;
+
+    if (!mm_iface_modem_3gpp_run_registration_checks_finish (self, res, &error)) {
+        mm_warn ("Initial 3GPP registration check failed: %s", error->message);
+        g_error_free (error);
+        return;
+    }
+    mm_dbg ("Initial 3GPP registration checks finished");
+}
+
+static void
+modem_cdma_run_registration_checks_ready (MMIfaceModemCdma *self,
+                                          GAsyncResult *res)
+{
+    GError *error = NULL;
+
+    if (!mm_iface_modem_cdma_run_registration_checks_finish (self, res, &error)) {
+        mm_warn ("Initial CDMA registration check failed: %s", error->message);
+        g_error_free (error);
+        return;
+    }
+    mm_dbg ("Initial CDMA registration checks finished");
+}
+
+static gboolean
+schedule_initial_registration_checks_cb (MMBroadbandModem *self)
+{
+    if (mm_iface_modem_is_3gpp (MM_IFACE_MODEM (self)))
+        mm_iface_modem_3gpp_run_registration_checks (MM_IFACE_MODEM_3GPP (self),
+                                                     (GAsyncReadyCallback) modem_3gpp_run_registration_checks_ready,
+                                                     NULL);
+    if (mm_iface_modem_is_cdma (MM_IFACE_MODEM (self)))
+        mm_iface_modem_cdma_run_registration_checks (MM_IFACE_MODEM_CDMA (self),
+                                                     (GAsyncReadyCallback) modem_cdma_run_registration_checks_ready,
+                                                     NULL);
+    /* We got a full reference, so balance it out here */
+    g_object_unref (self);
+    return FALSE;
+}
+
+static void
+schedule_initial_registration_checks (MMBroadbandModem *self)
+{
+    g_idle_add ((GSourceFunc) schedule_initial_registration_checks_cb, g_object_ref (self));
+}
+
+/*****************************************************************************/
 
 typedef enum {
     DISABLING_STEP_FIRST,
@@ -8866,6 +8919,16 @@ enabling_step (EnablingContext *ctx)
 
     case ENABLING_STEP_LAST:
         ctx->enabled = TRUE;
+
+        /* Once all interfaces have been enabled, trigger registration checks in
+         * 3GPP and CDMA modems. We have to do this at this point so that e.g.
+         * location interface gets proper registration related info reported.
+         *
+         * We do this in an idle so that we don't mess up the logs at this point
+         * with the new requests being triggered.
+         */
+        schedule_initial_registration_checks (ctx->self);
+
         /* All enabled without errors! */
         g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
         enabling_context_complete_and_free (ctx);
diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c
index 199b880..c8f3c2e 100644
--- a/src/mm-iface-modem-3gpp.c
+++ b/src/mm-iface-modem-3gpp.c
@@ -1551,7 +1551,6 @@ typedef enum {
     ENABLING_STEP_ENABLE_UNSOLICITED_EVENTS,
     ENABLING_STEP_SETUP_UNSOLICITED_REGISTRATION_EVENTS,
     ENABLING_STEP_ENABLE_UNSOLICITED_REGISTRATION_EVENTS,
-    ENABLING_STEP_RUN_REGISTRATION_CHECKS,
     ENABLING_STEP_LAST
 } EnablingStep;
 
@@ -1690,25 +1689,6 @@ enable_unsolicited_registration_events_ready (MMIfaceModem3gpp *self,
 }
 
 static void
-run_all_registration_checks_ready (MMIfaceModem3gpp *self,
-                                   GAsyncResult *res,
-                                   EnablingContext *ctx)
-{
-    GError *error = NULL;
-
-    mm_iface_modem_3gpp_run_registration_checks_finish (self, res, &error);
-    if (error) {
-        g_simple_async_result_take_error (ctx->result, error);
-        enabling_context_complete_and_free (ctx);
-        return;
-    }
-
-    /* Go on to next step */
-    ctx->step++;
-    interface_enabling_step (ctx);
-}
-
-static void
 interface_enabling_step (EnablingContext *ctx)
 {
     /* Don't run new steps if we're cancelled */
@@ -1782,13 +1762,6 @@ interface_enabling_step (EnablingContext *ctx)
         ctx->step++;
     }
 
-    case ENABLING_STEP_RUN_REGISTRATION_CHECKS:
-        mm_iface_modem_3gpp_run_registration_checks (
-            ctx->self,
-            (GAsyncReadyCallback)run_all_registration_checks_ready,
-            ctx);
-        return;
-
     case ENABLING_STEP_LAST:
         /* We are done without errors! */
         g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
diff --git a/src/mm-iface-modem-cdma.c b/src/mm-iface-modem-cdma.c
index 853f1db..67d360a 100644
--- a/src/mm-iface-modem-cdma.c
+++ b/src/mm-iface-modem-cdma.c
@@ -1414,7 +1414,6 @@ typedef enum {
     ENABLING_STEP_FIRST,
     ENABLING_STEP_SETUP_UNSOLICITED_EVENTS,
     ENABLING_STEP_ENABLE_UNSOLICITED_EVENTS,
-    ENABLING_STEP_RUN_REGISTRATION_CHECKS,
     ENABLING_STEP_PERIODIC_REGISTRATION_CHECKS,
     ENABLING_STEP_LAST
 } EnablingStep;
@@ -1500,24 +1499,6 @@ enable_unsolicited_events_ready (MMIfaceModemCdma *self,
 }
 
 static void
-run_registration_checks_ready (MMIfaceModemCdma *self,
-                                   GAsyncResult *res,
-                                   EnablingContext *ctx)
-{
-    GError *error = NULL;
-
-    if (!mm_iface_modem_cdma_run_registration_checks_finish (self, res, &error)) {
-        g_simple_async_result_take_error (ctx->result, error);
-        enabling_context_complete_and_free (ctx);
-        return;
-    }
-
-    /* Go on to next step */
-    ctx->step++;
-    interface_enabling_step (ctx);
-}
-
-static void
 interface_enabling_step (EnablingContext *ctx)
 {
     /* Don't run new steps if we're cancelled */
@@ -1553,12 +1534,6 @@ interface_enabling_step (EnablingContext *ctx)
         /* Fall down to next step */
         ctx->step++;
 
-    case ENABLING_STEP_RUN_REGISTRATION_CHECKS:
-        mm_iface_modem_cdma_run_registration_checks (ctx->self,
-                                                     (GAsyncReadyCallback)run_registration_checks_ready,
-                                                     ctx);
-        return;
-
     case ENABLING_STEP_PERIODIC_REGISTRATION_CHECKS:
         periodic_registration_check_enable (ctx->self);
         /* Fall down to next step */
-- 
2.6.1



More information about the ModemManager-devel mailing list