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

Dan Williams dcbw at redhat.com
Thu Mar 15 15:18:25 UTC 2018


On Fri, 2018-03-09 at 18:45 +0100, Aleksander Morgado wrote:
> 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.

LGTM

> ---
>  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_S
> TATE,
> -                                               "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_WRO
> NG_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_S
> TATE,
> -                                               "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;
>      }


More information about the ModemManager-devel mailing list