diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-12-18 15:50:53 +0100 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2019-01-03 18:53:52 +0000 |
commit | f35d64a8992a06e75585c774090e407ae21f24fe (patch) | |
tree | cfec844fb190d153bb43f45f19d2d31b5ec9881e | |
parent | 67b3b830c87e79827a9934362e673e1a23116026 (diff) |
api,firmware: expose firmware version
-rw-r--r-- | cli/mmcli-modem-firmware.c | 5 | ||||
-rw-r--r-- | cli/mmcli-output.c | 1 | ||||
-rw-r--r-- | cli/mmcli-output.h | 1 | ||||
-rw-r--r-- | docs/reference/libmm-glib/libmm-glib-sections.txt | 2 | ||||
-rw-r--r-- | introspection/org.freedesktop.ModemManager1.Modem.Firmware.xml | 10 | ||||
-rw-r--r-- | libmm-glib/mm-firmware-update-settings.c | 52 | ||||
-rw-r--r-- | libmm-glib/mm-firmware-update-settings.h | 3 | ||||
-rw-r--r-- | src/mm-iface-modem-firmware.c | 53 | ||||
-rw-r--r-- | src/mm-iface-modem.c | 18 | ||||
-rw-r--r-- | src/mm-iface-modem.h | 5 |
10 files changed, 133 insertions, 17 deletions
diff --git a/cli/mmcli-modem-firmware.c b/cli/mmcli-modem-firmware.c index 21ba5bb8..edc92ad1 100644 --- a/cli/mmcli-modem-firmware.c +++ b/cli/mmcli-modem-firmware.c @@ -145,6 +145,7 @@ print_firmware_status (void) MMFirmwareUpdateSettings *update_settings; const gchar *method = NULL; const gchar **device_ids = NULL; + const gchar *version = NULL; const gchar *fastboot_at = NULL; update_settings = mm_modem_firmware_peek_update_settings (ctx->modem_firmware); @@ -155,6 +156,7 @@ print_firmware_status (void) if (m != MM_MODEM_FIRMWARE_UPDATE_METHOD_UNKNOWN) { method = mm_modem_firmware_update_method_get_string (m); device_ids = mm_firmware_update_settings_get_device_ids (update_settings); + version = mm_firmware_update_settings_get_version (update_settings); } switch (m) { @@ -179,7 +181,8 @@ print_firmware_status (void) } mmcli_output_string (MMC_F_FIRMWARE_METHOD, method); - mmcli_output_string_array (MMC_F_FIRMWARE_DEVICE_IDS, device_ids, FALSE); + mmcli_output_string_array (MMC_F_FIRMWARE_DEVICE_IDS, device_ids, TRUE); + mmcli_output_string (MMC_F_FIRMWARE_VERSION, version); mmcli_output_string (MMC_F_FIRMWARE_FASTBOOT_AT, fastboot_at); mmcli_output_dump (); } diff --git a/cli/mmcli-output.c b/cli/mmcli-output.c index 0b191286..5822ff51 100644 --- a/cli/mmcli-output.c +++ b/cli/mmcli-output.c @@ -192,6 +192,7 @@ static FieldInfo field_infos[] = { [MMC_F_FIRMWARE_LIST] = { "modem.firmware.list", "list", MMC_S_MODEM_FIRMWARE, }, [MMC_F_FIRMWARE_METHOD] = { "modem.firmware.method", "method", MMC_S_MODEM_FIRMWARE, }, [MMC_F_FIRMWARE_DEVICE_IDS] = { "modem.firmware.device-ids", "device ids", MMC_S_MODEM_FIRMWARE, }, + [MMC_F_FIRMWARE_VERSION] = { "modem.firmware.version", "version", MMC_S_MODEM_FIRMWARE, }, [MMC_F_FIRMWARE_FASTBOOT_AT] = { "modem.firmware.fastboot.at", "at command", MMC_S_MODEM_FIRMWARE_FASTBOOT, }, [MMC_F_BEARER_GENERAL_DBUS_PATH] = { "bearer.dbus-path", "dbus path", MMC_S_BEARER_GENERAL, }, [MMC_F_BEARER_GENERAL_TYPE] = { "bearer.type", "type", MMC_S_BEARER_GENERAL, }, diff --git a/cli/mmcli-output.h b/cli/mmcli-output.h index 8cf50009..4a9a9c46 100644 --- a/cli/mmcli-output.h +++ b/cli/mmcli-output.h @@ -205,6 +205,7 @@ typedef enum { MMC_F_FIRMWARE_LIST, MMC_F_FIRMWARE_METHOD, MMC_F_FIRMWARE_DEVICE_IDS, + MMC_F_FIRMWARE_VERSION, MMC_F_FIRMWARE_FASTBOOT_AT, /* Bearer general section */ MMC_F_BEARER_GENERAL_DBUS_PATH, diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index 40b9fe3c..cb1f7a24 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -739,12 +739,14 @@ MMFirmwareUpdateSettings mm_firmware_update_settings_get_fastboot_at mm_firmware_update_settings_get_method mm_firmware_update_settings_get_device_ids +mm_firmware_update_settings_get_version <SUBSECTION Private> mm_firmware_update_settings_get_variant mm_firmware_update_settings_new mm_firmware_update_settings_new_from_variant mm_firmware_update_settings_set_fastboot_at mm_firmware_update_settings_set_device_ids +mm_firmware_update_settings_set_version <SUBSECTION Standard> MMFirmwareUpdateSettingsClass MMFirmwareUpdateSettingsPrivate diff --git a/introspection/org.freedesktop.ModemManager1.Modem.Firmware.xml b/introspection/org.freedesktop.ModemManager1.Modem.Firmware.xml index 8e4a4f72..c2fe7eb0 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.Firmware.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.Firmware.xml @@ -122,6 +122,7 @@ Detailed settings that provide information about how the module should be updated. + The settings are given as a <link linkend="MMModemFirmwareUpdateMethod">MMModemFirmwareUpdateMethod</link> value specifying the type of firmware update procedure expected followed by a dictionary that includes other parameters applicable to the specific method. @@ -142,6 +143,15 @@ <literal>"USB\VID_413C&PID_81D7"</literal> and <literal>"USB\VID_413C"</literal>. </listitem> </varlistentry> + <varlistentry><term><literal>"version"</literal></term> + <listitem> + (Required) This property exposes the current firmware version string of the module. + If the module uses separate version numbers for firmware version and carrier configuration, + this version string will be a combination of both, and so it may be different to the + version string showed in the #org.freedesktop.ModemManager1.Modem:Revision property. + (signature <literal>'s'</literal>) + </listitem> + </varlistentry> <varlistentry><term><literal>"fastboot-at"</literal></term> <listitem> (Required) This property exposes the AT command that should be sent to the diff --git a/libmm-glib/mm-firmware-update-settings.c b/libmm-glib/mm-firmware-update-settings.c index a8886c49..362f1011 100644 --- a/libmm-glib/mm-firmware-update-settings.c +++ b/libmm-glib/mm-firmware-update-settings.c @@ -31,12 +31,14 @@ G_DEFINE_TYPE (MMFirmwareUpdateSettings, mm_firmware_update_settings, G_TYPE_OBJECT) #define PROPERTY_DEVICE_IDS "device-ids" +#define PROPERTY_VERSION "version" #define PROPERTY_FASTBOOT_AT "fastboot-at" struct _MMFirmwareUpdateSettingsPrivate { /* Generic */ MMModemFirmwareUpdateMethod method; gchar **device_ids; + gchar *version; /* Fasboot specific */ gchar *fastboot_at; }; @@ -91,6 +93,35 @@ mm_firmware_update_settings_set_device_ids (MMFirmwareUpdateSettings *self, /*****************************************************************************/ /** + * mm_firmware_update_settings_get_version: + * @self: a #MMFirmwareUpdateSettings. + * + * Gets firmware version string. + * + * + * Returns: The version string, or %NULL if unknown. Do not free the returned value, it is owned by @self. + */ +const gchar * +mm_firmware_update_settings_get_version (MMFirmwareUpdateSettings *self) +{ + g_return_val_if_fail (MM_IS_FIRMWARE_UPDATE_SETTINGS (self), NULL); + + return self->priv->version; +} + +void +mm_firmware_update_settings_set_version (MMFirmwareUpdateSettings *self, + const gchar *version) +{ + g_return_if_fail (MM_IS_FIRMWARE_UPDATE_SETTINGS (self)); + + g_free (self->priv->version); + self->priv->version = g_strdup (version); +} + +/*****************************************************************************/ + +/** * mm_firmware_update_settings_get_fastboot_at: * @self: a #MMFirmwareUpdateSettings. * @@ -149,6 +180,11 @@ mm_firmware_update_settings_get_variant (MMFirmwareUpdateSettings *self) PROPERTY_DEVICE_IDS, g_variant_new_strv ((const gchar * const *)self->priv->device_ids, -1)); + g_variant_builder_add (&builder, + "{sv}", + PROPERTY_VERSION, + g_variant_new_string (self->priv->version)); + switch (method) { case MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT: g_variant_builder_add (&builder, @@ -176,6 +212,9 @@ consume_variant (MMFirmwareUpdateSettings *self, if (g_str_equal (key, PROPERTY_FASTBOOT_AT)) { g_free (self->priv->fastboot_at); self->priv->fastboot_at = g_variant_dup_string (value, NULL); + } else if (g_str_equal (key, PROPERTY_VERSION)) { + g_free (self->priv->version); + self->priv->version = g_variant_dup_string (value, NULL); } else if (g_str_equal (key, PROPERTY_DEVICE_IDS)) { g_strfreev (self->priv->device_ids); self->priv->device_ids = g_variant_dup_strv (value, NULL); @@ -232,9 +271,15 @@ mm_firmware_update_settings_new_from_variant (GVariant *variant, g_variant_unref (value); } - if (!inner_error && !self->priv->device_ids) - inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, - "Missing required'" PROPERTY_DEVICE_IDS "' setting"); + if (!inner_error) { + if (!self->priv->device_ids) + inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Missing required '" PROPERTY_DEVICE_IDS "' setting"); + else if (!self->priv->version) + inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Missing required '" PROPERTY_VERSION "' setting"); + } + if (!inner_error) { switch (method) { case MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT: @@ -281,6 +326,7 @@ finalize (GObject *object) MMFirmwareUpdateSettings *self = MM_FIRMWARE_UPDATE_SETTINGS (object); g_strfreev (self->priv->device_ids); + g_free (self->priv->version); g_free (self->priv->fastboot_at); G_OBJECT_CLASS (mm_firmware_update_settings_parent_class)->finalize (object); diff --git a/libmm-glib/mm-firmware-update-settings.h b/libmm-glib/mm-firmware-update-settings.h index 2a4cb805..da8cb311 100644 --- a/libmm-glib/mm-firmware-update-settings.h +++ b/libmm-glib/mm-firmware-update-settings.h @@ -63,6 +63,7 @@ MMModemFirmwareUpdateMethod mm_firmware_update_settings_get_method (MMFirmwareUp /* Generic */ const gchar **mm_firmware_update_settings_get_device_ids (MMFirmwareUpdateSettings *self); +const gchar *mm_firmware_update_settings_get_version (MMFirmwareUpdateSettings *self); /* Fastboot specific */ const gchar *mm_firmware_update_settings_get_fastboot_at (MMFirmwareUpdateSettings *self); @@ -84,6 +85,8 @@ GVariant *mm_firmware_update_settings_get_variant (MMFirmwareUpdateSettings *sel /* Generic */ void mm_firmware_update_settings_set_device_ids (MMFirmwareUpdateSettings *self, const gchar **device_ids); +void mm_firmware_update_settings_set_version (MMFirmwareUpdateSettings *self, + const gchar *version); /* Fastboot specific */ void mm_firmware_update_settings_set_fastboot_at (MMFirmwareUpdateSettings *self, diff --git a/src/mm-iface-modem-firmware.c b/src/mm-iface-modem-firmware.c index 11eff7c3..5cbe8741 100644 --- a/src/mm-iface-modem-firmware.c +++ b/src/mm-iface-modem-firmware.c @@ -283,6 +283,24 @@ mm_iface_modem_firmware_initialize_finish (MMIfaceModemFirmware *self, } static gboolean +add_generic_version (MMBaseModem *self, + MMFirmwareUpdateSettings *update_settings, + GError **error) +{ + const gchar *revision; + + revision = mm_iface_modem_get_revision (MM_IFACE_MODEM (self)); + if (!revision) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Unknown revision"); + return FALSE; + } + + mm_firmware_update_settings_set_version (update_settings, revision); + return TRUE; +} + +static gboolean add_generic_device_ids (MMBaseModem *self, MMFirmwareUpdateSettings *update_settings, GError **error) @@ -343,20 +361,33 @@ load_update_settings_ready (MMIfaceModemFirmware *self, if (!update_settings) { mm_dbg ("Couldn't load update settings: '%s'", error->message); g_error_free (error); - } else { - /* If the plugin didn't specify custom device ids, add the default ones ourselves */ - if (!mm_firmware_update_settings_get_device_ids (update_settings) && - !add_generic_device_ids (MM_BASE_MODEM (self), update_settings, &error)) { - mm_warn ("Couldn't build device ids: '%s'", error->message); - g_error_free (error); - } else { - variant = mm_firmware_update_settings_get_variant (update_settings); - g_object_unref (update_settings); - } + goto out; } - mm_gdbus_modem_firmware_set_update_settings (ctx->skeleton, variant); + /* If the plugin didn't specify custom device ids, add the default ones ourselves */ + if (!mm_firmware_update_settings_get_device_ids (update_settings) && + !add_generic_device_ids (MM_BASE_MODEM (self), update_settings, &error)) { + mm_warn ("Couldn't build device ids: '%s'", error->message); + g_error_free (error); + g_clear_object (&update_settings); + goto out; + } + /* If the plugin didn't specify custom version, add the default one ourselves */ + if (!mm_firmware_update_settings_get_version (update_settings) && + !add_generic_version (MM_BASE_MODEM (self), update_settings, &error)) { + mm_warn ("Couldn't set version: '%s'", error->message); + g_error_free (error); + g_clear_object (&update_settings); + goto out; + } + +out: + if (update_settings) { + variant = mm_firmware_update_settings_get_variant (update_settings); + g_object_unref (update_settings); + } + mm_gdbus_modem_firmware_set_update_settings (ctx->skeleton, variant); if (variant) g_variant_unref (variant); diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index a18accdd..1ffcb967 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -5329,6 +5329,24 @@ mm_iface_modem_get_model (MMIfaceModem *self) return model; } +const gchar * +mm_iface_modem_get_revision (MMIfaceModem *self) +{ + const gchar *revision = NULL; + MmGdbusModem *skeleton; + + g_object_get (self, + MM_IFACE_MODEM_DBUS_SKELETON, &skeleton, + NULL); + + if (skeleton) { + revision = mm_gdbus_modem_get_revision (skeleton); + g_object_unref (skeleton); + } + + return revision; +} + /*****************************************************************************/ static void diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h index cc3e087e..5b1c891d 100644 --- a/src/mm-iface-modem.h +++ b/src/mm-iface-modem.h @@ -380,8 +380,9 @@ gboolean mm_iface_modem_is_3g_only (MMIfaceModem *self); gboolean mm_iface_modem_is_4g (MMIfaceModem *self); gboolean mm_iface_modem_is_4g_only (MMIfaceModem *self); -/* Helper to query model */ -const gchar *mm_iface_modem_get_model (MMIfaceModem *self); +/* Helpers to query properties */ +const gchar *mm_iface_modem_get_model (MMIfaceModem *self); +const gchar *mm_iface_modem_get_revision (MMIfaceModem *self); /* Initialize Modem interface (async) */ void mm_iface_modem_initialize (MMIfaceModem *self, |