[PATCH 2/2] mbimcli: new '--intel-modem-reboot' action

Aleksander Morgado aleksander at aleksander.es
Wed Jan 10 21:06:20 UTC 2018


On 10/01/18 21:47, Ben Chan wrote:
> ---
>  docs/man/Makefile.am                        |   1 +
>  src/mbimcli/Makefile.am                     |   3 +-
>  src/mbimcli/mbimcli-intel-firmware-update.c | 159 ++++++++++++++++++++++++++++
>  src/mbimcli/mbimcli.c                       |   8 ++
>  src/mbimcli/mbimcli.h                       |   4 +
>  5 files changed, 174 insertions(+), 1 deletion(-)
>  create mode 100644 src/mbimcli/mbimcli-intel-firmware-update.c
> 

Pushed to git master, thanks!

> diff --git a/docs/man/Makefile.am b/docs/man/Makefile.am
> index 674edab..bb32c48 100644
> --- a/docs/man/Makefile.am
> +++ b/docs/man/Makefile.am
> @@ -10,6 +10,7 @@ MBIMCLI_SOURCES_WITH_HELP = \
>  	$(top_srcdir)/src/mbimcli/mbimcli-dss.c \
>  	$(top_srcdir)/src/mbimcli/mbimcli-ms-firmware-id.c \
>  	$(top_srcdir)/src/mbimcli/mbimcli-ms-host-shutdown.c \
> +	$(top_srcdir)/src/mbimcli/mbimcli-intel-firmware-update.c \
>  	$(top_srcdir)/src/mbimcli/mbimcli-phonebook.c \
>  	$(top_srcdir)/src/mbimcli/mbimcli.c
>  
> diff --git a/src/mbimcli/Makefile.am b/src/mbimcli/Makefile.am
> index 0c38ad3..48f272f 100644
> --- a/src/mbimcli/Makefile.am
> +++ b/src/mbimcli/Makefile.am
> @@ -18,7 +18,8 @@ mbimcli_SOURCES = \
>  	mbimcli-dss.c \
>  	mbimcli-ms-firmware-id.c \
>  	mbimcli-ms-host-shutdown.c \
> -	mbimcli-atds.c
> +	mbimcli-atds.c \
> +	mbimcli-intel-firmware-update.c
>  
>  mbimcli_LDADD = \
>  	$(MBIMCLI_LIBS) \
> diff --git a/src/mbimcli/mbimcli-intel-firmware-update.c b/src/mbimcli/mbimcli-intel-firmware-update.c
> new file mode 100644
> index 0000000..8eabf03
> --- /dev/null
> +++ b/src/mbimcli/mbimcli-intel-firmware-update.c
> @@ -0,0 +1,159 @@
> +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
> +/*
> + * mbimcli -- Command line interface to control MBIM devices
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> + *
> + * Copyright 2018 Google LLC
> + */
> +
> +#include "config.h"
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <locale.h>
> +#include <string.h>
> +
> +#include <glib.h>
> +#include <gio/gio.h>
> +
> +#include <libmbim-glib.h>
> +
> +#include "mbimcli.h"
> +
> +/* Context */
> +typedef struct {
> +    MbimDevice *device;
> +    GCancellable *cancellable;
> +} Context;
> +static Context *ctx;
> +
> +/* Options */
> +static gboolean modem_reboot_flag;
> +
> +static GOptionEntry entries[] = {
> +    { "intel-modem-reboot", 0, 0, G_OPTION_ARG_NONE, &modem_reboot_flag,
> +      "Reboot modem",
> +      NULL
> +    },
> +    { NULL }
> +};
> +
> +GOptionGroup *
> +mbimcli_intel_firmware_update_get_option_group (void)
> +{
> +   GOptionGroup *group;
> +
> +   group = g_option_group_new ("intel-firmware-update",
> +                               "Intel Firmware Update Service options",
> +                               "Show Intel Firmware Update Service options",
> +                               NULL,
> +                               NULL);
> +   g_option_group_add_entries (group, entries);
> +
> +   return group;
> +}
> +
> +gboolean
> +mbimcli_intel_firmware_update_options_enabled (void)
> +{
> +    static guint n_actions = 0;
> +    static gboolean checked = FALSE;
> +
> +    if (checked)
> +        return !!n_actions;
> +
> +    n_actions = modem_reboot_flag;
> +
> +    if (n_actions > 1) {
> +        g_printerr ("error: too many Intel Firmware Update Service actions requested\n");
> +        exit (EXIT_FAILURE);
> +    }
> +
> +    checked = TRUE;
> +    return !!n_actions;
> +}
> +
> +static void
> +context_free (Context *context)
> +{
> +    if (!context)
> +        return;
> +
> +    if (context->cancellable)
> +        g_object_unref (context->cancellable);
> +    if (context->device)
> +        g_object_unref (context->device);
> +    g_slice_free (Context, context);
> +}
> +
> +static void
> +shutdown (gboolean operation_status)
> +{
> +    /* Cleanup context and finish async operation */
> +    context_free (ctx);
> +    mbimcli_async_operation_done (operation_status);
> +}
> +
> +static void
> +modem_reboot_ready (MbimDevice   *device,
> +                    GAsyncResult *res)
> +{
> +    MbimMessage *response;
> +    GError *error = NULL;
> +
> +    response = mbim_device_command_finish (device, res, &error);
> +    if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
> +        g_printerr ("error: operation failed: %s\n", error->message);
> +        g_error_free (error);
> +        if (response)
> +            mbim_message_unref (response);
> +        shutdown (FALSE);
> +        return;
> +    }
> +
> +    g_print ("[%s] Successfully requested modem to reboot for firmware update\n\n",
> +             mbim_device_get_path_display (device));
> +
> +    mbim_message_unref (response);
> +    shutdown (TRUE);
> +}
> +
> +void
> +mbimcli_intel_firmware_update_run (MbimDevice   *device,
> +                          GCancellable *cancellable)
> +{
> +    /* Initialize context */
> +    ctx = g_slice_new (Context);
> +    ctx->device = g_object_ref (device);
> +    ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
> +
> +    /* Request to reboot modem? */
> +    if (modem_reboot_flag) {
> +        MbimMessage *request;
> +
> +        g_debug ("Asynchronously rebooting modem...");
> +        request = (mbim_message_intel_firmware_update_modem_reboot_set_new (NULL));
> +        mbim_device_command (ctx->device,
> +                             request,
> +                             10,
> +                             ctx->cancellable,
> +                             (GAsyncReadyCallback)modem_reboot_ready,
> +                             NULL);
> +        mbim_message_unref (request);
> +        return;
> +    }
> +
> +    g_warn_if_reached ();
> +}
> diff --git a/src/mbimcli/mbimcli.c b/src/mbimcli/mbimcli.c
> index 27bb634..c97c6dd 100644
> --- a/src/mbimcli/mbimcli.c
> +++ b/src/mbimcli/mbimcli.c
> @@ -275,6 +275,9 @@ device_open_ready (MbimDevice   *dev,
>      case MBIM_SERVICE_ATDS:
>          mbimcli_atds_run (dev, cancellable);
>          return;
> +    case MBIM_SERVICE_INTEL_FIRMWARE_UPDATE:
> +        mbimcli_intel_firmware_update_run (dev, cancellable);
> +        return;
>      default:
>          g_assert_not_reached ();
>      }
> @@ -349,6 +352,9 @@ parse_actions (void)
>      } else if (mbimcli_atds_options_enabled ()) {
>          service = MBIM_SERVICE_ATDS;
>          actions_enabled++;
> +    } else if (mbimcli_intel_firmware_update_options_enabled ()) {
> +        service = MBIM_SERVICE_INTEL_FIRMWARE_UPDATE;
> +        actions_enabled++;
>      }
>  
>      /* Noop */
> @@ -392,6 +398,8 @@ int main (int argc, char **argv)
>                                  mbimcli_ms_host_shutdown_get_option_group ());
>      g_option_context_add_group (context,
>                                  mbimcli_atds_get_option_group ());
> +    g_option_context_add_group (context,
> +                                mbimcli_intel_firmware_update_get_option_group ());
>      g_option_context_add_main_entries (context, main_entries, NULL);
>      if (!g_option_context_parse (context, &argc, &argv, &error)) {
>          g_printerr ("error: %s\n",
> diff --git a/src/mbimcli/mbimcli.h b/src/mbimcli/mbimcli.h
> index 02a1b78..a920872 100644
> --- a/src/mbimcli/mbimcli.h
> +++ b/src/mbimcli/mbimcli.h
> @@ -35,6 +35,7 @@ GOptionGroup *mbimcli_dss_get_option_group              (void);
>  GOptionGroup *mbimcli_ms_firmware_id_get_option_group   (void);
>  GOptionGroup *mbimcli_ms_host_shutdown_get_option_group (void);
>  GOptionGroup *mbimcli_atds_get_option_group             (void);
> +GOptionGroup *mbimcli_intel_firmware_update_get_option_group (void);
>  
>  gboolean      mbimcli_basic_connect_options_enabled     (void);
>  gboolean      mbimcli_phonebook_options_enabled         (void);
> @@ -42,6 +43,7 @@ gboolean      mbimcli_dss_options_enabled               (void);
>  gboolean      mbimcli_ms_firmware_id_options_enabled    (void);
>  gboolean      mbimcli_ms_host_shutdown_options_enabled  (void);
>  gboolean      mbimcli_atds_options_enabled              (void);
> +gboolean      mbimcli_intel_firmware_update_options_enabled (void);
>  
>  void          mbimcli_basic_connect_run                 (MbimDevice *device,
>                                                           GCancellable *cancellable);
> @@ -55,5 +57,7 @@ void          mbimcli_ms_host_shutdown_run              (MbimDevice *device,
>                                                           GCancellable *cancellable);
>  void          mbimcli_atds_run                          (MbimDevice *device,
>                                                           GCancellable *cancellable);
> +void          mbimcli_intel_firmware_update_run         (MbimDevice *device,
> +                                                         GCancellable *cancellable);
>  
>  #endif /* __MBIMCLI_H__ */
> 


-- 
Aleksander
https://aleksander.es


More information about the libmbim-devel mailing list