[PATCH 2/2] huawei: ignore ^RFSWITCH unsolicited messages

Ben Chan benchan at chromium.org
Mon Aug 19 14:22:22 PDT 2013


This patch ignores the ^RFSWITCH unsolicited messages in order to avoid
them being mixed with other unsolicited messages. The modem power state
is explicitly determined by the ^RFSWITCH? command, if supported, so we
don't need to depend on the ^RFSWITCH unsolicited messages.
---
 plugins/huawei/mm-broadband-modem-huawei.c | 38 ++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c
index f356102..cc3cde5 100644
--- a/plugins/huawei/mm-broadband-modem-huawei.c
+++ b/plugins/huawei/mm-broadband-modem-huawei.c
@@ -94,6 +94,7 @@ struct _MMBroadbandModemHuaweiPrivate {
     GRegex *hcsq_regex;
     GRegex *ndisstat_regex;
     GRegex *pdpdeact_regex;
+    GRegex *rfswitch_regex;
 
     NdisdupSupport ndisdup_support;
     RfswitchSupport rfswitch_support;
@@ -2582,6 +2583,27 @@ modem_time_load_network_time (MMIfaceModemTime *self,
 /* Power state loading (Modem interface) */
 
 static void
+enable_disable_unsolicited_rfswitch_event_handler (MMBroadbandModemHuawei *self,
+                                                   gboolean enable)
+{
+    MMAtSerialPort *ports[2];
+    guint i;
+
+    mm_dbg ("%s ^RFSWITCH unsolicited event handler",
+            enable ? "Enable" : "Disable");
+
+    ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
+    ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
+
+    for (i = 0; i < 2; i++)
+        if (ports[i])
+            mm_at_serial_port_enable_disable_unsolicited_msg_handler (
+                ports[i],
+                self->priv->rfswitch_regex,
+                enable);
+}
+
+static void
 parent_load_power_state_ready (MMIfaceModem *self,
                                GAsyncResult *res,
                                GSimpleAsyncResult *result)
@@ -2609,6 +2631,9 @@ huawei_rfswitch_check_ready (MMBaseModem *_self,
     const gchar *response;
     gint sw_state;
 
+    enable_disable_unsolicited_rfswitch_event_handler (MM_BROADBAND_MODEM_HUAWEI (self),
+                                                       TRUE /* enable */);
+
     response = mm_base_modem_at_command_finish (_self, res, &error);
     if (response) {
         response = mm_strip_tag (response, "^RFSWITCH:");
@@ -2684,6 +2709,12 @@ load_power_state (MMIfaceModem *self,
     switch (MM_BROADBAND_MODEM_HUAWEI (self)->priv->rfswitch_support) {
     case RFSWITCH_SUPPORT_UNKNOWN:
     case RFSWITCH_SUPPORTED: {
+        /* Temporarily disable the unsolicited ^RFSWITCH event handler in order to
+         * prevent it from discarding the response to the ^RFSWITCH? command.
+         * It will be re-enabled in huawei_rfswitch_check_ready.
+         */
+        enable_disable_unsolicited_rfswitch_event_handler (MM_BROADBAND_MODEM_HUAWEI (self),
+                                                           FALSE /* enable */);
         mm_base_modem_at_command (MM_BASE_MODEM (self),
                                   "^RFSWITCH?",
                                   3,
@@ -2878,6 +2909,10 @@ set_ignored_unsolicited_events_handlers (MMBroadbandModemHuawei *self)
             ports[i],
             self->priv->pdpdeact_regex,
             NULL, NULL, NULL);
+        mm_at_serial_port_add_unsolicited_msg_handler (
+            ports[i],
+            self->priv->rfswitch_regex,
+            NULL, NULL, NULL);
     }
 }
 
@@ -2951,6 +2986,8 @@ mm_broadband_modem_huawei_init (MMBroadbandModemHuawei *self)
                                               G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
     self->priv->pdpdeact_regex = g_regex_new ("\\r\\n\\^PDPDEACT:.+\\r+\\n",
                                               G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+    self->priv->rfswitch_regex = g_regex_new ("\\r\\n\\^RFSWITCH:.+\\r\\n",
+                                              G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
 
     self->priv->ndisdup_support = NDISDUP_SUPPORT_UNKNOWN;
     self->priv->rfswitch_support = RFSWITCH_SUPPORT_UNKNOWN;
@@ -2977,6 +3014,7 @@ finalize (GObject *object)
     g_regex_unref (self->priv->hcsq_regex);
     g_regex_unref (self->priv->ndisstat_regex);
     g_regex_unref (self->priv->pdpdeact_regex);
+    g_regex_unref (self->priv->rfswitch_regex);
 
     G_OBJECT_CLASS (mm_broadband_modem_huawei_parent_class)->finalize (object);
 }
-- 
1.8.3



More information about the ModemManager-devel mailing list