[PATCH] iface-modem: allow power off from any state

Aleksander Morgado aleksander at aleksander.es
Fri Mar 9 17:45:32 UTC 2018


We shouldn't be limiting the power off state from a non-enabled one
only, in the same way we always allow doing a reset from any state.
---
 src/mm-iface-modem.c | 53 +++++++++++++++++++++-------------------------------
 1 file changed, 21 insertions(+), 32 deletions(-)

diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c
index 06441e22..21b8b6ff 100644
--- a/src/mm-iface-modem.c
+++ b/src/mm-iface-modem.c
@@ -1806,45 +1806,34 @@ handle_set_power_state_auth_ready (MMBaseModem *self,
         return;
     }
 
-    /* Only 'off', 'low' or 'up' expected */
-    if (ctx->power_state != MM_MODEM_POWER_STATE_LOW &&
-        ctx->power_state != MM_MODEM_POWER_STATE_ON &&
-        ctx->power_state != MM_MODEM_POWER_STATE_OFF) {
-        g_dbus_method_invocation_return_error (ctx->invocation,
-                                               MM_CORE_ERROR,
-                                               MM_CORE_ERROR_INVALID_ARGS,
-                                               "Cannot set '%s' power state",
-                                               mm_modem_power_state_get_string (ctx->power_state));
-        handle_set_power_state_context_free (ctx);
-        return;
-    }
-
     modem_state = MM_MODEM_STATE_UNKNOWN;
     g_object_get (self,
                   MM_IFACE_MODEM_STATE, &modem_state,
                   NULL);
 
-    /* Going into LOW or ON only allowed in disabled state */
-    if ((ctx->power_state == MM_MODEM_POWER_STATE_LOW ||
-         ctx->power_state == MM_MODEM_POWER_STATE_ON) &&
-        modem_state != MM_MODEM_STATE_DISABLED) {
-        g_dbus_method_invocation_return_error (ctx->invocation,
-                                               MM_CORE_ERROR,
-                                               MM_CORE_ERROR_WRONG_STATE,
-                                               "Cannot set power state: not in disabled state");
-        handle_set_power_state_context_free (ctx);
-        return;
-    }
-
-    /* Going into OFF, only allowed if locked, disabled or failed */
-    if (ctx->power_state == MM_MODEM_POWER_STATE_OFF &&
-        modem_state != MM_MODEM_STATE_FAILED &&
-        modem_state != MM_MODEM_STATE_LOCKED &&
-        modem_state != MM_MODEM_STATE_DISABLED) {
+    switch (ctx->power_state) {
+    case MM_MODEM_POWER_STATE_LOW:
+    case MM_MODEM_POWER_STATE_ON:
+        /* Going into LOW or ON only allowed in disabled state */
+        if (modem_state != MM_MODEM_STATE_DISABLED) {
+            g_dbus_method_invocation_return_error (ctx->invocation,
+                                                   MM_CORE_ERROR,
+                                                   MM_CORE_ERROR_WRONG_STATE,
+                                                   "Cannot set power state: not in disabled state");
+            handle_set_power_state_context_free (ctx);
+            return;
+        }
+        break;
+    case MM_MODEM_POWER_STATE_OFF:
+        /* Going into OFF always allowed */
+        break;
+    default:
+        /* Only 'off', 'low' or 'up' expected */
         g_dbus_method_invocation_return_error (ctx->invocation,
                                                MM_CORE_ERROR,
-                                               MM_CORE_ERROR_WRONG_STATE,
-                                               "Cannot set power state: modem either enabled or initializing");
+                                               MM_CORE_ERROR_INVALID_ARGS,
+                                               "Cannot set '%s' power state",
+                                               mm_modem_power_state_get_string (ctx->power_state));
         handle_set_power_state_context_free (ctx);
         return;
     }
-- 
2.15.1



More information about the ModemManager-devel mailing list