api,firmware: expose firmware version

This commit is contained in:
Aleksander Morgado
2018-12-18 15:50:53 +01:00
committed by Dan Williams
parent 67b3b830c8
commit f35d64a899
10 changed files with 133 additions and 17 deletions

View File

@@ -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 ();
}

View File

@@ -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, },

View File

@@ -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,

View File

@@ -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

View File

@@ -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&amp;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

View File

@@ -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;
};
@@ -90,6 +92,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);

View File

@@ -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,

View File

@@ -282,6 +282,24 @@ mm_iface_modem_firmware_initialize_finish (MMIfaceModemFirmware *self,
return g_task_propagate_boolean (G_TASK (res), error);
}
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,
@@ -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);

View File

@@ -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

View File

@@ -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,