From f83a4b5ed428dbe412b3c9cc779bd85fc8dbe583 Mon Sep 17 00:00:00 2001
From: Dylan Van Assche <me@dylanvanassche.be>
Date: Sat, 30 Jan 2021 21:57:50 +0100
Subject: [PATCH] broadband-modem-qmi: Enable AT URCs and QMI indications

Enable both AT URCs and QMI indications for messaging events.
This allows to receive text messages during suspend
on the PinePhone with a Quectel EG25 modem.
---
 src/mm-broadband-modem-qmi.c | 109 +++++++++++++++++++++++++----------
 1 file changed, 80 insertions(+), 29 deletions(-)

diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c
index d161d96ec..bac5cf1b2 100644
--- a/src/mm-broadband-modem-qmi.c
+++ b/src/mm-broadband-modem-qmi.c
@@ -6115,13 +6115,6 @@ messaging_cleanup_unsolicited_events_finish (MMIfaceModemMessaging *_self,
                                              GAsyncResult *res,
                                              GError **error)
 {
-    MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self);
-
-    /* Handle fallback */
-    if (self->priv->messaging_fallback_at) {
-        return iface_modem_messaging_parent->cleanup_unsolicited_events_finish (_self, res, error);
-    }
-
     return g_task_propagate_boolean (G_TASK (res), error);
 }
 
@@ -6130,14 +6123,39 @@ messaging_setup_unsolicited_events_finish (MMIfaceModemMessaging *_self,
                                              GAsyncResult *res,
                                              GError **error)
 {
-    MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self);
+    return g_task_propagate_boolean (G_TASK (res), error);
+}
 
-    /* Handle fallback */
-    if (self->priv->messaging_fallback_at) {
-        return iface_modem_messaging_parent->setup_unsolicited_events_finish (_self, res, error);
-    }
+static void
+common_cleanup_unsolicited_events_finish (MMIfaceModemMessaging *self,
+                                        GAsyncResult *res,
+                                        GTask *task)
+{
+    GError *error = NULL;
 
-    return g_task_propagate_boolean (G_TASK (res), error);
+    messaging_cleanup_unsolicited_events_finish (self, res, &error);
+    if (error)
+        g_task_return_error (task, error);
+    else
+        g_task_return_boolean (task, TRUE);
+
+    g_object_unref (task);
+}
+
+static void
+common_setup_unsolicited_events_finish (MMIfaceModemMessaging *self,
+                                        GAsyncResult *res,
+                                        GTask *task)
+{
+    GError *error = NULL;
+
+    messaging_setup_unsolicited_events_finish (self, res, &error);
+    if (error)
+        g_task_return_error (task, error);
+    else
+        g_task_return_boolean (task, TRUE);
+
+    g_object_unref (task);
 }
 
 static void
@@ -6185,6 +6203,26 @@ common_setup_cleanup_messaging_unsolicited_events (MMBroadbandModemQmi *self,
     g_object_unref (task);
 }
 
+static void
+parent_messaging_cleanup_unsolicited_events_ready (MMIfaceModemMessaging *_self,
+                                                   GAsyncResult *res,
+                                                   GTask *task)
+{
+    GError *error = NULL;
+
+    if (!iface_modem_messaging_parent->cleanup_unsolicited_events_finish (_self, res, &error)) {
+        g_task_return_error (task, error);
+        g_object_unref (task);
+        return;
+    }
+
+    /* Disable QMI indications */
+    common_setup_cleanup_messaging_unsolicited_events (MM_BROADBAND_MODEM_QMI (_self),
+                                                       FALSE,
+                                                       (GAsyncReadyCallback)common_cleanup_unsolicited_events_finish,
+                                                       task);
+}
+
 static void
 messaging_cleanup_unsolicited_events (MMIfaceModemMessaging *_self,
                                       GAsyncReadyCallback callback,
@@ -6192,15 +6230,32 @@ messaging_cleanup_unsolicited_events (MMIfaceModemMessaging *_self,
 {
     MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self);
 
-    /* Handle fallback */
-    if (self->priv->messaging_fallback_at) {
-        return iface_modem_messaging_parent->cleanup_unsolicited_events (_self, callback, user_data);
+    /* Disable AT URCs parent and chain QMI indications disabling */
+    iface_modem_messaging_parent->cleanup_unsolicited_events (
+        _self,
+        (GAsyncReadyCallback)parent_messaging_cleanup_unsolicited_events_ready,
+        g_task_new (self, NULL, callback, user_data));
+}
+
+static void
+parent_messaging_setup_unsolicited_events_ready (MMIfaceModemMessaging *_self,
+                                                  GAsyncResult *res,
+                                                  GTask *task)
+{
+    GError *error = NULL;
+
+    if (!iface_modem_messaging_parent->setup_unsolicited_events_finish (_self, res, &error)) {
+        g_task_return_error (task, error);
+        g_object_unref (task);
+        return;
     }
 
-    common_setup_cleanup_messaging_unsolicited_events (MM_BROADBAND_MODEM_QMI (self),
-                                                       FALSE,
-                                                       callback,
-                                                       user_data);
+    /* Enable QMI indications */
+    common_setup_cleanup_messaging_unsolicited_events (MM_BROADBAND_MODEM_QMI (_self),
+                                                       TRUE,
+                                                       (GAsyncReadyCallback)common_setup_unsolicited_events_finish,
+                                                       task);
+
 }
 
 static void
@@ -6210,15 +6265,11 @@ messaging_setup_unsolicited_events (MMIfaceModemMessaging *_self,
 {
     MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self);
 
-    /* Handle fallback */
-    if (self->priv->messaging_fallback_at) {
-        return iface_modem_messaging_parent->setup_unsolicited_events (_self, callback, user_data);
-    }
-
-    common_setup_cleanup_messaging_unsolicited_events (MM_BROADBAND_MODEM_QMI (self),
-                                                       TRUE,
-                                                       callback,
-                                                       user_data);
+    /* Enable AT URCs parent and chain QMI indication enabling */
+    iface_modem_messaging_parent->setup_unsolicited_events (
+        _self,
+        (GAsyncReadyCallback)parent_messaging_setup_unsolicited_events_ready,
+        g_task_new (self, NULL, callback, user_data));
 }
 
 /*****************************************************************************/
-- 
GitLab

