Export the version-format to clients

This allows a vendor to verify the VersionFormat of a device without running
the daemon in verbose mode.
This commit is contained in:
Richard Hughes 2019-04-27 09:24:42 +01:00
parent 396026582d
commit c84b36c541
25 changed files with 350 additions and 276 deletions

View File

@ -47,6 +47,7 @@ typedef struct {
gchar *version; gchar *version;
gchar *version_lowest; gchar *version_lowest;
gchar *version_bootloader; gchar *version_bootloader;
FwupdVersionFormat version_format;
GPtrArray *checksums; GPtrArray *checksums;
guint32 flashes_left; guint32 flashes_left;
guint32 install_duration; guint32 install_duration;
@ -57,6 +58,12 @@ typedef struct {
FwupdDevice *parent; FwupdDevice *parent;
} FwupdDevicePrivate; } FwupdDevicePrivate;
enum {
PROP_0,
PROP_VERSION_FORMAT,
PROP_LAST
};
G_DEFINE_TYPE_WITH_PRIVATE (FwupdDevice, fwupd_device, G_TYPE_OBJECT) G_DEFINE_TYPE_WITH_PRIVATE (FwupdDevice, fwupd_device, G_TYPE_OBJECT)
#define GET_PRIVATE(o) (fwupd_device_get_instance_private (o)) #define GET_PRIVATE(o) (fwupd_device_get_instance_private (o))
@ -1050,6 +1057,8 @@ fwupd_device_incorporate (FwupdDevice *self, FwupdDevice *donor)
fwupd_device_set_version_lowest (self, priv_donor->version_lowest); fwupd_device_set_version_lowest (self, priv_donor->version_lowest);
if (priv->version_bootloader == NULL) if (priv->version_bootloader == NULL)
fwupd_device_set_version_bootloader (self, priv_donor->version_bootloader); fwupd_device_set_version_bootloader (self, priv_donor->version_bootloader);
if (priv->version_format == FWUPD_VERSION_FORMAT_UNKNOWN)
fwupd_device_set_version_format (self, priv_donor->version_format);
for (guint i = 0; i < priv_donor->guids->len; i++) { for (guint i = 0; i < priv_donor->guids->len; i++) {
const gchar *tmp = g_ptr_array_index (priv_donor->guids, i); const gchar *tmp = g_ptr_array_index (priv_donor->guids, i);
fwupd_device_add_guid (self, tmp); fwupd_device_add_guid (self, tmp);
@ -1214,6 +1223,11 @@ fwupd_device_to_variant_full (FwupdDevice *device, FwupdDeviceFlags flags)
FWUPD_RESULT_KEY_UPDATE_STATE, FWUPD_RESULT_KEY_UPDATE_STATE,
g_variant_new_uint32 (priv->update_state)); g_variant_new_uint32 (priv->update_state));
} }
if (priv->version_format != FWUPD_VERSION_FORMAT_UNKNOWN) {
g_variant_builder_add (&builder, "{sv}",
FWUPD_RESULT_KEY_VERSION_FORMAT,
g_variant_new_uint32 (priv->version_format));
}
if (flags & FWUPD_DEVICE_FLAG_TRUSTED) { if (flags & FWUPD_DEVICE_FLAG_TRUSTED) {
if (priv->serial != NULL) { if (priv->serial != NULL) {
g_variant_builder_add (&builder, "{sv}", g_variant_builder_add (&builder, "{sv}",
@ -1383,6 +1397,10 @@ fwupd_device_from_key_value (FwupdDevice *device, const gchar *key, GVariant *va
fwupd_device_set_update_state (device, g_variant_get_uint32 (value)); fwupd_device_set_update_state (device, g_variant_get_uint32 (value));
return; return;
} }
if (g_strcmp0 (key, FWUPD_RESULT_KEY_VERSION_FORMAT) == 0) {
fwupd_device_set_version_format (device, g_variant_get_uint32 (value));
return;
}
} }
static void static void
@ -1477,6 +1495,41 @@ fwupd_device_set_update_state (FwupdDevice *device, FwupdUpdateState update_stat
priv->update_state = update_state; priv->update_state = update_state;
} }
/**
* fwupd_device_get_version_format:
* @device: A #FwupdDevice
*
* Gets the update state.
*
* Returns: the update state, or %FWUPD_VERSION_FORMAT_UNKNOWN if unset
*
* Since: 1.2.9
**/
FwupdVersionFormat
fwupd_device_get_version_format (FwupdDevice *device)
{
FwupdDevicePrivate *priv = GET_PRIVATE (device);
g_return_val_if_fail (FWUPD_IS_DEVICE (device), FWUPD_VERSION_FORMAT_UNKNOWN);
return priv->version_format;
}
/**
* fwupd_device_set_version_format:
* @device: A #FwupdDevice
* @version_format: the state, e.g. %FWUPD_VERSION_FORMAT_PENDING
*
* Sets the update state.
*
* Since: 1.2.9
**/
void
fwupd_device_set_version_format (FwupdDevice *device, FwupdVersionFormat version_format)
{
FwupdDevicePrivate *priv = GET_PRIVATE (device);
g_return_if_fail (FWUPD_IS_DEVICE (device));
priv->version_format = version_format;
}
/** /**
* fwupd_device_get_update_message: * fwupd_device_get_update_message:
* @device: A #FwupdDevice * @device: A #FwupdDevice
@ -1690,6 +1743,8 @@ fwupd_device_to_json (FwupdDevice *device, JsonBuilder *builder)
fwupd_device_json_add_string (builder, FWUPD_RESULT_KEY_VERSION, priv->version); fwupd_device_json_add_string (builder, FWUPD_RESULT_KEY_VERSION, priv->version);
fwupd_device_json_add_string (builder, FWUPD_RESULT_KEY_VERSION_LOWEST, priv->version_lowest); fwupd_device_json_add_string (builder, FWUPD_RESULT_KEY_VERSION_LOWEST, priv->version_lowest);
fwupd_device_json_add_string (builder, FWUPD_RESULT_KEY_VERSION_BOOTLOADER, priv->version_bootloader); fwupd_device_json_add_string (builder, FWUPD_RESULT_KEY_VERSION_BOOTLOADER, priv->version_bootloader);
fwupd_device_json_add_string (builder, FWUPD_RESULT_KEY_VERSION_FORMAT,
fwupd_version_format_to_string (priv->version_format));
fwupd_device_json_add_int (builder, FWUPD_RESULT_KEY_FLASHES_LEFT, priv->flashes_left); fwupd_device_json_add_int (builder, FWUPD_RESULT_KEY_FLASHES_LEFT, priv->flashes_left);
if (priv->icons->len > 0) { if (priv->icons->len > 0) {
json_builder_set_member_name (builder, "Icons"); json_builder_set_member_name (builder, "Icons");
@ -1778,6 +1833,8 @@ fwupd_device_to_string (FwupdDevice *device)
fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_VERSION, priv->version); fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_VERSION, priv->version);
fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_VERSION_LOWEST, priv->version_lowest); fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_VERSION_LOWEST, priv->version_lowest);
fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_VERSION_BOOTLOADER, priv->version_bootloader); fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_VERSION_BOOTLOADER, priv->version_bootloader);
fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_VERSION_FORMAT,
fwupd_version_format_to_string (priv->version_format));
if (priv->flashes_left < 2) if (priv->flashes_left < 2)
fwupd_pad_kv_int (str, FWUPD_RESULT_KEY_FLASHES_LEFT, priv->flashes_left); fwupd_pad_kv_int (str, FWUPD_RESULT_KEY_FLASHES_LEFT, priv->flashes_left);
if (priv->icons->len > 0) { if (priv->icons->len > 0) {
@ -1806,11 +1863,54 @@ fwupd_device_to_string (FwupdDevice *device)
return g_string_free (str, FALSE); return g_string_free (str, FALSE);
} }
static void
fwupd_device_get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
FwupdDevice *self = FWUPD_DEVICE (object);
FwupdDevicePrivate *priv = GET_PRIVATE (self);
switch (prop_id) {
case PROP_VERSION_FORMAT:
g_value_set_uint (value, priv->version_format);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
fwupd_device_set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
FwupdDevice *self = FWUPD_DEVICE (object);
switch (prop_id) {
case PROP_VERSION_FORMAT:
fwupd_device_set_version_format (self, g_value_get_uint (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void static void
fwupd_device_class_init (FwupdDeviceClass *klass) fwupd_device_class_init (FwupdDeviceClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
object_class->finalize = fwupd_device_finalize; object_class->finalize = fwupd_device_finalize;
object_class->get_property = fwupd_device_get_property;
object_class->set_property = fwupd_device_set_property;
pspec = g_param_spec_uint ("version-format", NULL, NULL,
FWUPD_VERSION_FORMAT_UNKNOWN,
FWUPD_VERSION_FORMAT_LAST,
FWUPD_VERSION_FORMAT_UNKNOWN,
G_PARAM_READWRITE |
G_PARAM_STATIC_NAME);
g_object_class_install_property (object_class, PROP_VERSION_FORMAT, pspec);
} }
static void static void

View File

@ -62,6 +62,9 @@ void fwupd_device_set_version_lowest (FwupdDevice *device,
const gchar *fwupd_device_get_version_bootloader (FwupdDevice *device); const gchar *fwupd_device_get_version_bootloader (FwupdDevice *device);
void fwupd_device_set_version_bootloader (FwupdDevice *device, void fwupd_device_set_version_bootloader (FwupdDevice *device,
const gchar *version_bootloader); const gchar *version_bootloader);
FwupdVersionFormat fwupd_device_get_version_format (FwupdDevice *device);
void fwupd_device_set_version_format (FwupdDevice *device,
FwupdVersionFormat version_format);
guint32 fwupd_device_get_flashes_left (FwupdDevice *device); guint32 fwupd_device_get_flashes_left (FwupdDevice *device);
void fwupd_device_set_flashes_left (FwupdDevice *device, void fwupd_device_set_flashes_left (FwupdDevice *device,
guint32 flashes_left); guint32 flashes_left);

View File

@ -45,6 +45,7 @@ G_BEGIN_DECLS
#define FWUPD_RESULT_KEY_VENDOR "Vendor" /* s */ #define FWUPD_RESULT_KEY_VENDOR "Vendor" /* s */
#define FWUPD_RESULT_KEY_VENDOR "Vendor" /* s */ #define FWUPD_RESULT_KEY_VENDOR "Vendor" /* s */
#define FWUPD_RESULT_KEY_VERSION_BOOTLOADER "VersionBootloader" /* s */ #define FWUPD_RESULT_KEY_VERSION_BOOTLOADER "VersionBootloader" /* s */
#define FWUPD_RESULT_KEY_VERSION_FORMAT "VersionFormat" /* u */
#define FWUPD_RESULT_KEY_VERSION_LOWEST "VersionLowest" /* s */ #define FWUPD_RESULT_KEY_VERSION_LOWEST "VersionLowest" /* s */
#define FWUPD_RESULT_KEY_VERSION "Version" /* s */ #define FWUPD_RESULT_KEY_VERSION "Version" /* s */

View File

@ -427,3 +427,67 @@ fwupd_release_flag_from_string (const gchar *release_flag)
return FWUPD_RELEASE_FLAG_BLOCKED_APPROVAL; return FWUPD_RELEASE_FLAG_BLOCKED_APPROVAL;
return FWUPD_RELEASE_FLAG_NONE; return FWUPD_RELEASE_FLAG_NONE;
} }
/**
* fwupd_version_format_from_string:
* @str: A string, e.g. `quad`
*
* Converts text to a display version type.
*
* Returns: A #FwupdVersionFormat, e.g. %FWUPD_VERSION_FORMAT_TRIPLET
*
* Since: 1.2.9
**/
FwupdVersionFormat
fwupd_version_format_from_string (const gchar *str)
{
if (g_strcmp0 (str, "plain") == 0)
return FWUPD_VERSION_FORMAT_PLAIN;
if (g_strcmp0 (str, "pair") == 0)
return FWUPD_VERSION_FORMAT_PAIR;
if (g_strcmp0 (str, "number") == 0)
return FWUPD_VERSION_FORMAT_NUMBER;
if (g_strcmp0 (str, "triplet") == 0)
return FWUPD_VERSION_FORMAT_TRIPLET;
if (g_strcmp0 (str, "quad") == 0)
return FWUPD_VERSION_FORMAT_QUAD;
if (g_strcmp0 (str, "bcd") == 0)
return FWUPD_VERSION_FORMAT_BCD;
if (g_strcmp0 (str, "intel-me") == 0)
return FWUPD_VERSION_FORMAT_INTEL_ME;
if (g_strcmp0 (str, "intel-me2") == 0)
return FWUPD_VERSION_FORMAT_INTEL_ME2;
return FWUPD_VERSION_FORMAT_UNKNOWN;
}
/**
* fwupd_version_format_to_string:
* @kind: A #FwupdVersionFormat, e.g. %FWUPD_VERSION_FORMAT_TRIPLET
*
* Converts a display version type to text.
*
* Returns: A string, e.g. `quad`, or %NULL if not known
*
* Since: 1.2.9
**/
const gchar *
fwupd_version_format_to_string (FwupdVersionFormat kind)
{
if (kind == FWUPD_VERSION_FORMAT_PLAIN)
return "plain";
if (kind == FWUPD_VERSION_FORMAT_NUMBER)
return "number";
if (kind == FWUPD_VERSION_FORMAT_PAIR)
return "pair";
if (kind == FWUPD_VERSION_FORMAT_TRIPLET)
return "triplet";
if (kind == FWUPD_VERSION_FORMAT_QUAD)
return "quad";
if (kind == FWUPD_VERSION_FORMAT_BCD)
return "bcd";
if (kind == FWUPD_VERSION_FORMAT_INTEL_ME)
return "intel-me";
if (kind == FWUPD_VERSION_FORMAT_INTEL_ME2)
return "intel-me2";
return NULL;
}

View File

@ -216,6 +216,37 @@ typedef enum {
FWUPD_KEYRING_KIND_LAST FWUPD_KEYRING_KIND_LAST
} FwupdKeyringKind; } FwupdKeyringKind;
/**
* FwupdVersionFormat:
* @FWUPD_VERSION_FORMAT_UNKNOWN: Unknown version format
* @FWUPD_VERSION_FORMAT_PLAIN: An unidentified format text string
* @FWUPD_VERSION_FORMAT_NUMBER: A single integer version number
* @FWUPD_VERSION_FORMAT_PAIR: Two AABB.CCDD version numbers
* @FWUPD_VERSION_FORMAT_TRIPLET: Microsoft-style AA.BB.CCDD version numbers
* @FWUPD_VERSION_FORMAT_QUAD: Dell-style AA.BB.CC.DD version numbers
* @FWUPD_VERSION_FORMAT_BCD: Binary coded decimal notation
* @FWUPD_VERSION_FORMAT_INTEL_ME: Intel ME-style bitshifted notation
* @FWUPD_VERSION_FORMAT_INTEL_ME2: Intel ME-style A.B.CC.DDDD notation notation
*
* The flags used when parsing version numbers.
*
* If no verification is required then %FWUPD_VERSION_FORMAT_PLAIN should
* be used to signify an unparsable text string.
**/
typedef enum {
FWUPD_VERSION_FORMAT_UNKNOWN, /* Since: 1.2.9 */
FWUPD_VERSION_FORMAT_PLAIN, /* Since: 1.2.9 */
FWUPD_VERSION_FORMAT_NUMBER, /* Since: 1.2.9 */
FWUPD_VERSION_FORMAT_PAIR, /* Since: 1.2.9 */
FWUPD_VERSION_FORMAT_TRIPLET, /* Since: 1.2.9 */
FWUPD_VERSION_FORMAT_QUAD, /* Since: 1.2.9 */
FWUPD_VERSION_FORMAT_BCD, /* Since: 1.2.9 */
FWUPD_VERSION_FORMAT_INTEL_ME, /* Since: 1.2.9 */
FWUPD_VERSION_FORMAT_INTEL_ME2, /* Since: 1.2.9 */
/*< private >*/
FWUPD_VERSION_FORMAT_LAST
} FwupdVersionFormat;
const gchar *fwupd_status_to_string (FwupdStatus status); const gchar *fwupd_status_to_string (FwupdStatus status);
FwupdStatus fwupd_status_from_string (const gchar *status); FwupdStatus fwupd_status_from_string (const gchar *status);
const gchar *fwupd_device_flag_to_string (FwupdDeviceFlags device_flag); const gchar *fwupd_device_flag_to_string (FwupdDeviceFlags device_flag);
@ -228,5 +259,7 @@ const gchar *fwupd_trust_flag_to_string (FwupdTrustFlags trust_flag);
FwupdTrustFlags fwupd_trust_flag_from_string (const gchar *trust_flag); FwupdTrustFlags fwupd_trust_flag_from_string (const gchar *trust_flag);
FwupdKeyringKind fwupd_keyring_kind_from_string (const gchar *keyring_kind); FwupdKeyringKind fwupd_keyring_kind_from_string (const gchar *keyring_kind);
const gchar *fwupd_keyring_kind_to_string (FwupdKeyringKind keyring_kind); const gchar *fwupd_keyring_kind_to_string (FwupdKeyringKind keyring_kind);
FwupdVersionFormat fwupd_version_format_from_string (const gchar *str);
const gchar *fwupd_version_format_to_string (FwupdVersionFormat kind);
G_END_DECLS G_END_DECLS

View File

@ -122,6 +122,11 @@ fwupd_enums_func (void)
g_assert_cmpstr (tmp, !=, NULL); g_assert_cmpstr (tmp, !=, NULL);
g_assert_cmpint (fwupd_trust_flag_from_string (tmp), ==, i); g_assert_cmpint (fwupd_trust_flag_from_string (tmp), ==, i);
} }
for (guint i = 1; i < FWUPD_VERSION_FORMAT_LAST; i++) {
const gchar *tmp = fwupd_version_format_to_string (i);
g_assert_cmpstr (tmp, !=, NULL);
g_assert_cmpint (fwupd_version_format_from_string (tmp), ==, i);
}
/* bitfield */ /* bitfield */
for (guint64 i = 1; i < FWUPD_DEVICE_FLAG_UNKNOWN; i *= 2) { for (guint64 i = 1; i < FWUPD_DEVICE_FLAG_UNKNOWN; i *= 2) {

View File

@ -354,3 +354,12 @@ LIBFWUPD_1.2.8 {
fwupd_client_modify_config; fwupd_client_modify_config;
local: *; local: *;
} LIBFWUPD_1.2.7; } LIBFWUPD_1.2.7;
LIBFWUPD_1.2.9 {
global:
fwupd_device_get_version_format;
fwupd_device_set_version_format;
fwupd_version_format_from_string;
fwupd_version_format_to_string;
local: *;
} LIBFWUPD_1.2.8;

View File

@ -181,7 +181,7 @@ fu_ata_device_parse_id_maybe_dell (FuAtaDevice *self, const guint16 *buf)
guid_efi = fu_ata_device_get_guid_safe (buf, 129); guid_efi = fu_ata_device_get_guid_safe (buf, 129);
if (guid_efi != NULL) if (guid_efi != NULL)
fu_device_add_guid (FU_DEVICE (self), guid_efi); fu_device_add_guid (FU_DEVICE (self), guid_efi);
fu_device_set_version_format (FU_DEVICE (self), FU_VERSION_FORMAT_PLAIN); fu_device_set_version_format (FU_DEVICE (self), FWUPD_VERSION_FORMAT_PLAIN);
} }
static gboolean static gboolean

View File

@ -259,7 +259,7 @@ fu_plugin_dell_inject_fake_data (FuPlugin *plugin,
data->can_switch_modes = TRUE; data->can_switch_modes = TRUE;
} }
static FuVersionFormat static FwupdVersionFormat
fu_plugin_dell_get_version_format (FuPlugin *plugin) fu_plugin_dell_get_version_format (FuPlugin *plugin)
{ {
const gchar *content; const gchar *content;
@ -268,15 +268,15 @@ fu_plugin_dell_get_version_format (FuPlugin *plugin)
content = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_MANUFACTURER); content = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_MANUFACTURER);
if (content == NULL) if (content == NULL)
return FU_VERSION_FORMAT_TRIPLET; return FWUPD_VERSION_FORMAT_TRIPLET;
/* any quirks match */ /* any quirks match */
group = g_strdup_printf ("SmbiosManufacturer=%s", content); group = g_strdup_printf ("SmbiosManufacturer=%s", content);
quirk = fu_plugin_lookup_quirk_by_id (plugin, group, quirk = fu_plugin_lookup_quirk_by_id (plugin, group,
FU_QUIRKS_UEFI_VERSION_FORMAT); FU_QUIRKS_UEFI_VERSION_FORMAT);
if (quirk == NULL) if (quirk == NULL)
return FU_VERSION_FORMAT_TRIPLET; return FWUPD_VERSION_FORMAT_TRIPLET;
return fu_common_version_format_from_string (quirk); return fwupd_version_format_from_string (quirk);
} }
static gboolean static gboolean
@ -344,7 +344,7 @@ fu_plugin_usb_device_added (FuPlugin *plugin,
GError **error) GError **error)
{ {
FuPluginData *data = fu_plugin_get_data (plugin); FuPluginData *data = fu_plugin_get_data (plugin);
FuVersionFormat version_format; FwupdVersionFormat version_format;
guint16 pid; guint16 pid;
guint16 vid; guint16 vid;
const gchar *query_str; const gchar *query_str;
@ -641,7 +641,7 @@ fu_plugin_dell_detect_tpm (FuPlugin *plugin, GError **error)
g_debug ("Creating primary TPM GUID %s and secondary TPM GUID %s", g_debug ("Creating primary TPM GUID %s and secondary TPM GUID %s",
tpm_guid_raw, tpm_guid_raw_alt); tpm_guid_raw, tpm_guid_raw_alt);
version_str = fu_common_version_from_uint32 (out->fw_version, version_str = fu_common_version_from_uint32 (out->fw_version,
FU_VERSION_FORMAT_QUAD); FWUPD_VERSION_FORMAT_QUAD);
/* make it clear that the TPM is a discrete device of the product */ /* make it clear that the TPM is a discrete device of the product */
if (!data->smi_obj->fake_smbios) { if (!data->smi_obj->fake_smbios) {

View File

@ -644,7 +644,7 @@ dfu_firmware_to_string (DfuFirmware *firmware)
g_return_val_if_fail (DFU_IS_FIRMWARE (firmware), NULL); g_return_val_if_fail (DFU_IS_FIRMWARE (firmware), NULL);
release_str = fu_common_version_from_uint16 (priv->release, release_str = fu_common_version_from_uint16 (priv->release,
FU_VERSION_FORMAT_BCD); FWUPD_VERSION_FORMAT_BCD);
str = g_string_new (""); str = g_string_new ("");
g_string_append_printf (str, "vid: 0x%04x\n", priv->vid); g_string_append_printf (str, "vid: 0x%04x\n", priv->vid);
g_string_append_printf (str, "pid: 0x%04x\n", priv->pid); g_string_append_printf (str, "pid: 0x%04x\n", priv->pid);

View File

@ -2037,7 +2037,7 @@ dfu_tool_list (DfuToolPrivate *priv, gchar **values, GError **error)
if (!fu_device_probe (FU_DEVICE (device), NULL)) if (!fu_device_probe (FU_DEVICE (device), NULL))
continue; continue;
version = fu_common_version_from_uint16 (g_usb_device_get_release (usb_device), version = fu_common_version_from_uint16 (g_usb_device_get_release (usb_device),
FU_VERSION_FORMAT_BCD); FWUPD_VERSION_FORMAT_BCD);
g_print ("%s %04x:%04x [v%s]:\n", g_print ("%s %04x:%04x [v%s]:\n",
/* TRANSLATORS: detected a DFU device */ /* TRANSLATORS: detected a DFU device */
_("Found"), _("Found"),

View File

@ -201,22 +201,22 @@ fu_nvme_device_parse_cns_maybe_dell (FuNvmeDevice *self, const guint8 *buf)
guid_efi = fu_nvme_device_get_guid_safe (buf, 0x0c26); guid_efi = fu_nvme_device_get_guid_safe (buf, 0x0c26);
if (guid_efi != NULL) if (guid_efi != NULL)
fu_device_add_guid (FU_DEVICE (self), guid_efi); fu_device_add_guid (FU_DEVICE (self), guid_efi);
fu_device_set_version_format (FU_DEVICE (self), FU_VERSION_FORMAT_PLAIN); fu_device_set_version_format (FU_DEVICE (self), FWUPD_VERSION_FORMAT_PLAIN);
} }
static gboolean static gboolean
fu_nvme_device_set_version (FuNvmeDevice *self, const gchar *version, GError **error) fu_nvme_device_set_version (FuNvmeDevice *self, const gchar *version, GError **error)
{ {
FuVersionFormat fmt = fu_device_get_version_format (FU_DEVICE (self)); FwupdVersionFormat fmt = fu_device_get_version_format (FU_DEVICE (self));
/* unset */ /* unset */
if (fmt == FU_VERSION_FORMAT_UNKNOWN || fmt == FU_VERSION_FORMAT_PLAIN) { if (fmt == FWUPD_VERSION_FORMAT_UNKNOWN || fmt == FWUPD_VERSION_FORMAT_PLAIN) {
fu_device_set_version (FU_DEVICE (self), version); fu_device_set_version (FU_DEVICE (self), version);
return TRUE; return TRUE;
} }
/* AA.BB.CC.DD */ /* AA.BB.CC.DD */
if (fmt == FU_VERSION_FORMAT_QUAD) { if (fmt == FWUPD_VERSION_FORMAT_QUAD) {
guint64 tmp = g_ascii_strtoull (version, NULL, 16); guint64 tmp = g_ascii_strtoull (version, NULL, 16);
g_autofree gchar *version_new = NULL; g_autofree gchar *version_new = NULL;
if (tmp == 0 || tmp > G_MAXUINT32) { if (tmp == 0 || tmp > G_MAXUINT32) {
@ -227,7 +227,7 @@ fu_nvme_device_set_version (FuNvmeDevice *self, const gchar *version, GError **e
version); version);
return FALSE; return FALSE;
} }
version_new = fu_common_version_from_uint32 (tmp, FU_VERSION_FORMAT_QUAD); version_new = fu_common_version_from_uint32 (tmp, FWUPD_VERSION_FORMAT_QUAD);
fu_device_set_version (FU_DEVICE (self), version_new); fu_device_set_version (FU_DEVICE (self), version_new);
return TRUE; return TRUE;
} }
@ -237,7 +237,7 @@ fu_nvme_device_set_version (FuNvmeDevice *self, const gchar *version, GError **e
G_IO_ERROR, G_IO_ERROR,
G_IO_ERROR_INVALID_DATA, G_IO_ERROR_INVALID_DATA,
"version format %s not handled", "version format %s not handled",
fu_common_version_format_to_string (fmt)); fwupd_version_format_to_string (fmt));
return FALSE; return FALSE;
} }

View File

@ -69,7 +69,7 @@ fu_plugin_coldplug (FuPlugin *plugin, GError **error)
fu_device_add_guid (child1, "7fddead7-12b5-4fb9-9fa0-6d30305df755"); fu_device_add_guid (child1, "7fddead7-12b5-4fb9-9fa0-6d30305df755");
fu_device_set_name (child1, "Module1"); fu_device_set_name (child1, "Module1");
fu_device_set_version (child1, "1"); fu_device_set_version (child1, "1");
fu_device_set_version_format (child1, FU_VERSION_FORMAT_PLAIN); fu_device_set_version_format (child1, FWUPD_VERSION_FORMAT_PLAIN);
fu_device_add_parent_guid (child1, "b585990a-003e-5270-89d5-3705a17f9a43"); fu_device_add_parent_guid (child1, "b585990a-003e-5270-89d5-3705a17f9a43");
fu_device_add_flag (child1, FWUPD_DEVICE_FLAG_UPDATABLE); fu_device_add_flag (child1, FWUPD_DEVICE_FLAG_UPDATABLE);
fu_plugin_device_add (plugin, child1); fu_plugin_device_add (plugin, child1);
@ -80,7 +80,7 @@ fu_plugin_coldplug (FuPlugin *plugin, GError **error)
fu_device_add_guid (child2, "b8fe6b45-8702-4bcd-8120-ef236caac76f"); fu_device_add_guid (child2, "b8fe6b45-8702-4bcd-8120-ef236caac76f");
fu_device_set_name (child2, "Module2"); fu_device_set_name (child2, "Module2");
fu_device_set_version (child2, "10"); fu_device_set_version (child2, "10");
fu_device_set_version_format (child2, FU_VERSION_FORMAT_PLAIN); fu_device_set_version_format (child2, FWUPD_VERSION_FORMAT_PLAIN);
fu_device_add_parent_guid (child2, "b585990a-003e-5270-89d5-3705a17f9a43"); fu_device_add_parent_guid (child2, "b585990a-003e-5270-89d5-3705a17f9a43");
fu_device_add_flag (child2, FWUPD_DEVICE_FLAG_UPDATABLE); fu_device_add_flag (child2, FWUPD_DEVICE_FLAG_UPDATABLE);
fu_plugin_device_add (plugin, child2); fu_plugin_device_add (plugin, child2);

View File

@ -450,7 +450,7 @@ fu_plugin_device_registered (FuPlugin *plugin, FuDevice *device)
} }
} }
static FuVersionFormat static FwupdVersionFormat
fu_plugin_uefi_get_version_format_for_type (FuPlugin *plugin, FuUefiDeviceKind device_kind) fu_plugin_uefi_get_version_format_for_type (FuPlugin *plugin, FuUefiDeviceKind device_kind)
{ {
const gchar *content; const gchar *content;
@ -459,19 +459,19 @@ fu_plugin_uefi_get_version_format_for_type (FuPlugin *plugin, FuUefiDeviceKind d
/* we have no information for devices */ /* we have no information for devices */
if (device_kind == FU_UEFI_DEVICE_KIND_DEVICE_FIRMWARE) if (device_kind == FU_UEFI_DEVICE_KIND_DEVICE_FIRMWARE)
return FU_VERSION_FORMAT_TRIPLET; return FWUPD_VERSION_FORMAT_TRIPLET;
content = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_MANUFACTURER); content = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_MANUFACTURER);
if (content == NULL) if (content == NULL)
return FU_VERSION_FORMAT_TRIPLET; return FWUPD_VERSION_FORMAT_TRIPLET;
/* any quirks match */ /* any quirks match */
group = g_strdup_printf ("SmbiosManufacturer=%s", content); group = g_strdup_printf ("SmbiosManufacturer=%s", content);
quirk = fu_plugin_lookup_quirk_by_id (plugin, group, quirk = fu_plugin_lookup_quirk_by_id (plugin, group,
FU_QUIRKS_UEFI_VERSION_FORMAT); FU_QUIRKS_UEFI_VERSION_FORMAT);
if (quirk == NULL) if (quirk == NULL)
return FU_VERSION_FORMAT_TRIPLET; return FWUPD_VERSION_FORMAT_TRIPLET;
return fu_common_version_format_from_string (quirk); return fwupd_version_format_from_string (quirk);
} }
static const gchar * static const gchar *
@ -514,7 +514,7 @@ static gboolean
fu_plugin_uefi_coldplug_device (FuPlugin *plugin, FuUefiDevice *dev, GError **error) fu_plugin_uefi_coldplug_device (FuPlugin *plugin, FuUefiDevice *dev, GError **error)
{ {
FuUefiDeviceKind device_kind; FuUefiDeviceKind device_kind;
FuVersionFormat version_format; FwupdVersionFormat version_format;
/* set default version format */ /* set default version format */
device_kind = fu_uefi_device_get_kind (dev); device_kind = fu_uefi_device_get_kind (dev);

View File

@ -492,7 +492,7 @@ static gboolean
fu_uefi_device_probe (FuDevice *device, GError **error) fu_uefi_device_probe (FuDevice *device, GError **error)
{ {
FuUefiDevice *self = FU_UEFI_DEVICE (device); FuUefiDevice *self = FU_UEFI_DEVICE (device);
FuVersionFormat version_format; FwupdVersionFormat version_format;
g_autofree gchar *devid = NULL; g_autofree gchar *devid = NULL;
g_autofree gchar *guid_strup = NULL; g_autofree gchar *guid_strup = NULL;
g_autofree gchar *version_lowest = NULL; g_autofree gchar *version_lowest = NULL;

View File

@ -89,14 +89,14 @@ fu_plugin_udev_device_added (FuPlugin *plugin, FuUdevDevice *device, GError **er
/* runtime */ /* runtime */
if (fu_device_has_custom_flag (FU_DEVICE (device), "is-receiver")) { if (fu_device_has_custom_flag (FU_DEVICE (device), "is-receiver")) {
dev = g_object_new (FU_TYPE_UNIFYING_RUNTIME, dev = g_object_new (FU_TYPE_UNIFYING_RUNTIME,
"version-format", FU_VERSION_FORMAT_PLAIN, "version-format", FWUPD_VERSION_FORMAT_PLAIN,
NULL); NULL);
fu_device_incorporate (dev, FU_DEVICE (device)); fu_device_incorporate (dev, FU_DEVICE (device));
} else { } else {
/* create device so we can run ->probe() and add UFY GUIDs */ /* create device so we can run ->probe() and add UFY GUIDs */
dev = g_object_new (FU_TYPE_UNIFYING_PERIPHERAL, dev = g_object_new (FU_TYPE_UNIFYING_PERIPHERAL,
"version-format", FU_VERSION_FORMAT_PLAIN, "version-format", FWUPD_VERSION_FORMAT_PLAIN,
NULL); NULL);
fu_device_incorporate (dev, FU_DEVICE (device)); fu_device_incorporate (dev, FU_DEVICE (device));
if (!fu_device_probe (dev, error)) if (!fu_device_probe (dev, error))
@ -136,12 +136,12 @@ fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **erro
} }
if (fu_device_has_custom_flag (FU_DEVICE (device), "is-nordic")) { if (fu_device_has_custom_flag (FU_DEVICE (device), "is-nordic")) {
dev = g_object_new (FU_TYPE_UNIFYING_BOOTLOADER_NORDIC, dev = g_object_new (FU_TYPE_UNIFYING_BOOTLOADER_NORDIC,
"version-format", FU_VERSION_FORMAT_PLAIN, "version-format", FWUPD_VERSION_FORMAT_PLAIN,
NULL); NULL);
fu_device_incorporate (dev, FU_DEVICE (device)); fu_device_incorporate (dev, FU_DEVICE (device));
} else if (fu_device_has_custom_flag (FU_DEVICE (device), "is-texas")) { } else if (fu_device_has_custom_flag (FU_DEVICE (device), "is-texas")) {
dev = g_object_new (FU_TYPE_UNIFYING_BOOTLOADER_TEXAS, dev = g_object_new (FU_TYPE_UNIFYING_BOOTLOADER_TEXAS,
"version-format", FU_VERSION_FORMAT_PLAIN, "version-format", FWUPD_VERSION_FORMAT_PLAIN,
NULL); NULL);
fu_device_incorporate (dev, FU_DEVICE (device)); fu_device_incorporate (dev, FU_DEVICE (device));
g_usleep (200*1000); g_usleep (200*1000);

View File

@ -40,7 +40,7 @@ fu_wacom_emr_device_setup (FuDevice *device, GError **error)
return FALSE; return FALSE;
fw_ver = fu_common_read_uint16 (data + 11, G_LITTLE_ENDIAN); fw_ver = fu_common_read_uint16 (data + 11, G_LITTLE_ENDIAN);
fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_IS_BOOTLOADER); fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_IS_BOOTLOADER);
version = fu_common_version_from_uint16 (fw_ver, FU_VERSION_FORMAT_PAIR); version = fu_common_version_from_uint16 (fw_ver, FWUPD_VERSION_FORMAT_PAIR);
fu_device_set_version (device, version); fu_device_set_version (device, version);
} }

View File

@ -10,76 +10,17 @@
#include <string.h> #include <string.h>
#include "fwupd-enums.h"
#include "fwupd-error.h" #include "fwupd-error.h"
#include "fu-common-version.h" #include "fu-common-version.h"
#define FU_COMMON_VERSION_DECODE_BCD(val) ((((val) >> 4) & 0x0f) * 10 + ((val) & 0x0f)) #define FU_COMMON_VERSION_DECODE_BCD(val) ((((val) >> 4) & 0x0f) * 10 + ((val) & 0x0f))
/**
* fu_common_version_format_from_string:
* @str: A string, e.g. `quad`
*
* Converts text to a display version type.
*
* Returns: A #FuVersionFormat, e.g. %FU_VERSION_FORMAT_TRIPLET
*
* Since: 1.2.0
**/
FuVersionFormat
fu_common_version_format_from_string (const gchar *str)
{
if (g_strcmp0 (str, "triplet") == 0)
return FU_VERSION_FORMAT_TRIPLET;
if (g_strcmp0 (str, "quad") == 0)
return FU_VERSION_FORMAT_QUAD;
if (g_strcmp0 (str, "intel-me2") == 0)
return FU_VERSION_FORMAT_INTEL_ME2;
if (g_strcmp0 (str, "bcd") == 0)
return FU_VERSION_FORMAT_BCD;
if (g_strcmp0 (str, "plain") == 0)
return FU_VERSION_FORMAT_PLAIN;
if (g_strcmp0 (str, "intel-me") == 0)
return FU_VERSION_FORMAT_INTEL_ME;
if (g_strcmp0 (str, "pair") == 0)
return FU_VERSION_FORMAT_PAIR;
return FU_VERSION_FORMAT_UNKNOWN;
}
/**
* fu_common_version_format_to_string:
* @kind: A #FuVersionFormat, e.g. %FU_VERSION_FORMAT_TRIPLET
*
* Converts a display version type to text.
*
* Returns: A string, e.g. `quad`, or %NULL if not known
*
* Since: 1.2.0
**/
const gchar *
fu_common_version_format_to_string (FuVersionFormat kind)
{
if (kind == FU_VERSION_FORMAT_TRIPLET)
return "triplet";
if (kind == FU_VERSION_FORMAT_QUAD)
return "quad";
if (kind == FU_VERSION_FORMAT_INTEL_ME2)
return "intel-me2";
if (kind == FU_VERSION_FORMAT_BCD)
return "bcd";
if (kind == FU_VERSION_FORMAT_PLAIN)
return "plain";
if (kind == FU_VERSION_FORMAT_INTEL_ME)
return "intel-me";
if (kind == FU_VERSION_FORMAT_PAIR)
return "pair";
return NULL;
}
/** /**
* fu_common_version_from_uint32: * fu_common_version_from_uint32:
* @val: A uint32le version number * @val: A uint32le version number
* @kind: version kind used for formatting, e.g. %FU_VERSION_FORMAT_TRIPLET * @kind: version kind used for formatting, e.g. %FWUPD_VERSION_FORMAT_TRIPLET
* *
* Returns a dotted decimal version string from a 32 bit number. * Returns a dotted decimal version string from a 32 bit number.
* *
@ -88,9 +29,9 @@ fu_common_version_format_to_string (FuVersionFormat kind)
* Since: 1.2.0 * Since: 1.2.0
**/ **/
gchar * gchar *
fu_common_version_from_uint32 (guint32 val, FuVersionFormat kind) fu_common_version_from_uint32 (guint32 val, FwupdVersionFormat kind)
{ {
if (kind == FU_VERSION_FORMAT_QUAD) { if (kind == FWUPD_VERSION_FORMAT_QUAD) {
/* AA.BB.CC.DD */ /* AA.BB.CC.DD */
return g_strdup_printf ("%u.%u.%u.%u", return g_strdup_printf ("%u.%u.%u.%u",
(val >> 24) & 0xff, (val >> 24) & 0xff,
@ -98,24 +39,24 @@ fu_common_version_from_uint32 (guint32 val, FuVersionFormat kind)
(val >> 8) & 0xff, (val >> 8) & 0xff,
val & 0xff); val & 0xff);
} }
if (kind == FU_VERSION_FORMAT_TRIPLET) { if (kind == FWUPD_VERSION_FORMAT_TRIPLET) {
/* AA.BB.CCDD */ /* AA.BB.CCDD */
return g_strdup_printf ("%u.%u.%u", return g_strdup_printf ("%u.%u.%u",
(val >> 24) & 0xff, (val >> 24) & 0xff,
(val >> 16) & 0xff, (val >> 16) & 0xff,
val & 0xffff); val & 0xffff);
} }
if (kind == FU_VERSION_FORMAT_PAIR) { if (kind == FWUPD_VERSION_FORMAT_PAIR) {
/* AABB.CCDD */ /* AABB.CCDD */
return g_strdup_printf ("%u.%u", return g_strdup_printf ("%u.%u",
(val >> 16) & 0xffff, (val >> 16) & 0xffff,
val & 0xffff); val & 0xffff);
} }
if (kind == FU_VERSION_FORMAT_PLAIN) { if (kind == FWUPD_VERSION_FORMAT_NUMBER) {
/* AABBCCDD */ /* AABBCCDD */
return g_strdup_printf ("%" G_GUINT32_FORMAT, val); return g_strdup_printf ("%" G_GUINT32_FORMAT, val);
} }
if (kind == FU_VERSION_FORMAT_BCD) { if (kind == FWUPD_VERSION_FORMAT_BCD) {
/* AA.BB.CC.DD, but BCD */ /* AA.BB.CC.DD, but BCD */
return g_strdup_printf ("%u.%u.%u.%u", return g_strdup_printf ("%u.%u.%u.%u",
FU_COMMON_VERSION_DECODE_BCD(val >> 24), FU_COMMON_VERSION_DECODE_BCD(val >> 24),
@ -123,7 +64,7 @@ fu_common_version_from_uint32 (guint32 val, FuVersionFormat kind)
FU_COMMON_VERSION_DECODE_BCD(val >> 8), FU_COMMON_VERSION_DECODE_BCD(val >> 8),
FU_COMMON_VERSION_DECODE_BCD(val)); FU_COMMON_VERSION_DECODE_BCD(val));
} }
if (kind == FU_VERSION_FORMAT_INTEL_ME) { if (kind == FWUPD_VERSION_FORMAT_INTEL_ME) {
/* aaa+11.bbbbb.cccccccc.dddddddddddddddd */ /* aaa+11.bbbbb.cccccccc.dddddddddddddddd */
return g_strdup_printf ("%u.%u.%u.%u", return g_strdup_printf ("%u.%u.%u.%u",
((val >> 29) & 0x07) + 0x0b, ((val >> 29) & 0x07) + 0x0b,
@ -131,7 +72,7 @@ fu_common_version_from_uint32 (guint32 val, FuVersionFormat kind)
(val >> 16) & 0xff, (val >> 16) & 0xff,
val & 0xffff); val & 0xffff);
} }
if (kind == FU_VERSION_FORMAT_INTEL_ME2) { if (kind == FWUPD_VERSION_FORMAT_INTEL_ME2) {
/* A.B.CC.DDDD */ /* A.B.CC.DDDD */
return g_strdup_printf ("%u.%u.%u.%u", return g_strdup_printf ("%u.%u.%u.%u",
(val >> 28) & 0x0f, (val >> 28) & 0x0f,
@ -139,13 +80,15 @@ fu_common_version_from_uint32 (guint32 val, FuVersionFormat kind)
(val >> 16) & 0xff, (val >> 16) & 0xff,
val & 0xffff); val & 0xffff);
} }
g_critical ("failed to convert version format %s: %u",
fwupd_version_format_to_string (kind), val);
return NULL; return NULL;
} }
/** /**
* fu_common_version_from_uint16: * fu_common_version_from_uint16:
* @val: A uint16le version number * @val: A uint16le version number
* @kind: version kind used for formatting, e.g. %FU_VERSION_FORMAT_TRIPLET * @kind: version kind used for formatting, e.g. %FWUPD_VERSION_FORMAT_TRIPLET
* *
* Returns a dotted decimal version string from a 16 bit number. * Returns a dotted decimal version string from a 16 bit number.
* *
@ -154,21 +97,23 @@ fu_common_version_from_uint32 (guint32 val, FuVersionFormat kind)
* Since: 1.2.0 * Since: 1.2.0
**/ **/
gchar * gchar *
fu_common_version_from_uint16 (guint16 val, FuVersionFormat kind) fu_common_version_from_uint16 (guint16 val, FwupdVersionFormat kind)
{ {
if (kind == FU_VERSION_FORMAT_BCD) { if (kind == FWUPD_VERSION_FORMAT_BCD) {
return g_strdup_printf ("%i.%i", return g_strdup_printf ("%i.%i",
FU_COMMON_VERSION_DECODE_BCD(val >> 8), FU_COMMON_VERSION_DECODE_BCD(val >> 8),
FU_COMMON_VERSION_DECODE_BCD(val)); FU_COMMON_VERSION_DECODE_BCD(val));
} }
if (kind == FU_VERSION_FORMAT_PAIR) { if (kind == FWUPD_VERSION_FORMAT_PAIR) {
return g_strdup_printf ("%u.%u", return g_strdup_printf ("%u.%u",
(guint) (val >> 8) & 0xff, (guint) (val >> 8) & 0xff,
(guint) val & 0xff); (guint) val & 0xff);
} }
if (kind == FU_VERSION_FORMAT_PLAIN) { if (kind == FWUPD_VERSION_FORMAT_NUMBER) {
return g_strdup_printf ("%" G_GUINT16_FORMAT, val); return g_strdup_printf ("%" G_GUINT16_FORMAT, val);
} }
g_critical ("failed to convert version format %s: %u",
fwupd_version_format_to_string (kind), val);
return NULL; return NULL;
} }
@ -270,7 +215,7 @@ fu_common_version_parse (const gchar *version)
return g_strdup (version); return g_strdup (version);
if (tmp == 0) if (tmp == 0)
return g_strdup (version); return g_strdup (version);
return fu_common_version_from_uint32 ((guint32) tmp, FU_VERSION_FORMAT_TRIPLET); return fu_common_version_from_uint32 ((guint32) tmp, FWUPD_VERSION_FORMAT_TRIPLET);
} }
/** /**
@ -282,13 +227,13 @@ fu_common_version_parse (const gchar *version)
* possible. * possible.
* *
* If the version format cannot be guessed with any degree of accuracy, the * If the version format cannot be guessed with any degree of accuracy, the
* %FU_VERSION_FORMAT_UNKNOWN constant is returned. * %FWUPD_VERSION_FORMAT_UNKNOWN constant is returned.
* *
* Returns: A #FuVersionFormat, e.g. %FU_VERSION_FORMAT_QUAD * Returns: A #FwupdVersionFormat, e.g. %FWUPD_VERSION_FORMAT_QUAD
* *
* Since: 1.2.0 * Since: 1.2.0
*/ */
FuVersionFormat FwupdVersionFormat
fu_common_version_guess_format (const gchar *version) fu_common_version_guess_format (const gchar *version)
{ {
guint sz; guint sz;
@ -296,7 +241,7 @@ fu_common_version_guess_format (const gchar *version)
/* nothing to use */ /* nothing to use */
if (version == NULL || version[0] == '\0') if (version == NULL || version[0] == '\0')
return FU_VERSION_FORMAT_UNKNOWN; return FWUPD_VERSION_FORMAT_UNKNOWN;
/* no dots, assume just text */ /* no dots, assume just text */
split = g_strsplit (version, ".", -1); split = g_strsplit (version, ".", -1);
@ -305,27 +250,27 @@ fu_common_version_guess_format (const gchar *version)
if (g_str_has_prefix (version, "0x")) if (g_str_has_prefix (version, "0x"))
version += 2; version += 2;
if (_g_ascii_is_digits (version)) if (_g_ascii_is_digits (version))
return FU_VERSION_FORMAT_UNKNOWN; return FWUPD_VERSION_FORMAT_NUMBER;
return FU_VERSION_FORMAT_PLAIN; return FWUPD_VERSION_FORMAT_PLAIN;
} }
/* check for only-digit semver version */ /* check for only-digit semver version */
for (guint i = 0; split[i] != NULL; i++) { for (guint i = 0; split[i] != NULL; i++) {
/* check sections are plain numbers */ /* check sections are plain numbers */
if (!_g_ascii_is_digits (split[i])) if (!_g_ascii_is_digits (split[i]))
return FU_VERSION_FORMAT_PLAIN; return FWUPD_VERSION_FORMAT_PLAIN;
} }
/* the most common formats */ /* the most common formats */
if (sz == 2) if (sz == 2)
return FU_VERSION_FORMAT_PAIR; return FWUPD_VERSION_FORMAT_PAIR;
if (sz == 3) if (sz == 3)
return FU_VERSION_FORMAT_TRIPLET; return FWUPD_VERSION_FORMAT_TRIPLET;
if (sz == 4) if (sz == 4)
return FU_VERSION_FORMAT_QUAD; return FWUPD_VERSION_FORMAT_QUAD;
/* unknown! */ /* unknown! */
return FU_VERSION_FORMAT_UNKNOWN; return FWUPD_VERSION_FORMAT_UNKNOWN;
} }
/** /**

View File

@ -7,45 +7,17 @@
#pragma once #pragma once
#include <gio/gio.h> #include <gio/gio.h>
#include <fwupd.h>
G_BEGIN_DECLS G_BEGIN_DECLS
/**
* FuVersionFormat:
* @FU_VERSION_FORMAT_UNKNOWN: Unknown version format
* @FU_VERSION_FORMAT_PLAIN: Use plain integer version numbers
* @FU_VERSION_FORMAT_QUAD: Use Dell-style AA.BB.CC.DD version numbers
* @FU_VERSION_FORMAT_TRIPLET: Use Microsoft-style AA.BB.CCDD version numbers
* @FU_VERSION_FORMAT_PAIR: Use two AABB.CCDD version numbers
* @FU_VERSION_FORMAT_BCD: Use binary coded decimal notation
* @FU_VERSION_FORMAT_INTEL_ME: Use Intel ME-style bitshifted notation
* @FU_VERSION_FORMAT_INTEL_ME2: Use Intel ME-style A.B.CC.DDDD notation notation
*
* The flags used when parsing version numbers.
**/
typedef enum {
FU_VERSION_FORMAT_UNKNOWN, /* Since: 1.2.0 */
FU_VERSION_FORMAT_PLAIN, /* Since: 1.2.0 */
FU_VERSION_FORMAT_QUAD, /* Since: 1.2.0 */
FU_VERSION_FORMAT_TRIPLET, /* Since: 1.2.0 */
FU_VERSION_FORMAT_PAIR, /* Since: 1.2.0 */
FU_VERSION_FORMAT_BCD, /* Since: 1.2.0 */
FU_VERSION_FORMAT_INTEL_ME, /* Since: 1.2.0 */
FU_VERSION_FORMAT_INTEL_ME2, /* Since: 1.2.0 */
/*< private >*/
FU_VERSION_FORMAT_LAST
} FuVersionFormat;
FuVersionFormat fu_common_version_format_from_string (const gchar *str);
const gchar *fu_common_version_format_to_string (FuVersionFormat kind);
gint fu_common_vercmp (const gchar *version_a, gint fu_common_vercmp (const gchar *version_a,
const gchar *version_b); const gchar *version_b);
gchar *fu_common_version_from_uint32 (guint32 val, gchar *fu_common_version_from_uint32 (guint32 val,
FuVersionFormat kind); FwupdVersionFormat kind);
gchar *fu_common_version_from_uint16 (guint16 val, gchar *fu_common_version_from_uint16 (guint16 val,
FuVersionFormat kind); FwupdVersionFormat kind);
gchar *fu_common_version_parse (const gchar *version); gchar *fu_common_version_parse (const gchar *version);
FuVersionFormat fu_common_version_guess_format (const gchar *version); FwupdVersionFormat fu_common_version_guess_format (const gchar *version);
G_END_DECLS G_END_DECLS

View File

@ -44,7 +44,6 @@ typedef struct {
GPtrArray *children; GPtrArray *children;
guint remove_delay; /* ms */ guint remove_delay; /* ms */
FwupdStatus status; FwupdStatus status;
FuVersionFormat version_format;
guint progress; guint progress;
guint order; guint order;
guint priority; guint priority;
@ -63,7 +62,6 @@ enum {
PROP_PHYSICAL_ID, PROP_PHYSICAL_ID,
PROP_LOGICAL_ID, PROP_LOGICAL_ID,
PROP_QUIRKS, PROP_QUIRKS,
PROP_VERSION_FORMAT,
PROP_LAST PROP_LAST
}; };
@ -83,9 +81,6 @@ fu_device_get_property (GObject *object, guint prop_id,
case PROP_PROGRESS: case PROP_PROGRESS:
g_value_set_uint (value, priv->progress); g_value_set_uint (value, priv->progress);
break; break;
case PROP_VERSION_FORMAT:
g_value_set_uint (value, priv->version_format);
break;
case PROP_PHYSICAL_ID: case PROP_PHYSICAL_ID:
g_value_set_string (value, fu_device_get_physical_id (self)); g_value_set_string (value, fu_device_get_physical_id (self));
break; break;
@ -113,9 +108,6 @@ fu_device_set_property (GObject *object, guint prop_id,
case PROP_PROGRESS: case PROP_PROGRESS:
fu_device_set_progress (self, g_value_get_uint (value)); fu_device_set_progress (self, g_value_get_uint (value));
break; break;
case PROP_VERSION_FORMAT:
fu_device_set_version_format (self, g_value_get_uint (value));
break;
case PROP_PHYSICAL_ID: case PROP_PHYSICAL_ID:
fu_device_set_physical_id (self, g_value_get_string (value)); fu_device_set_physical_id (self, g_value_get_string (value));
break; break;
@ -691,7 +683,7 @@ fu_device_set_quirk_kv (FuDevice *self,
return TRUE; return TRUE;
} }
if (g_strcmp0 (key, FU_QUIRKS_VERSION_FORMAT) == 0) { if (g_strcmp0 (key, FU_QUIRKS_VERSION_FORMAT) == 0) {
fu_device_set_version_format (self, fu_common_version_format_from_string (value)); fu_device_set_version_format (self, fwupd_version_format_from_string (value));
return TRUE; return TRUE;
} }
if (g_strcmp0 (key, FU_QUIRKS_CHILDREN) == 0) { if (g_strcmp0 (key, FU_QUIRKS_CHILDREN) == 0) {
@ -1194,15 +1186,15 @@ fu_device_is_valid_semver_char (gchar c)
void void
fu_device_set_version (FuDevice *self, const gchar *version) fu_device_set_version (FuDevice *self, const gchar *version)
{ {
FuDevicePrivate *priv = GET_PRIVATE (self); FwupdVersionFormat version_format = fu_device_get_version_format (self);
g_autoptr(GString) version_safe = NULL; g_autoptr(GString) version_safe = NULL;
g_return_if_fail (FU_IS_DEVICE (self)); g_return_if_fail (FU_IS_DEVICE (self));
g_return_if_fail (version != NULL); g_return_if_fail (version != NULL);
/* sanitize if required */ /* sanitize if required */
if (priv->version_format != FU_VERSION_FORMAT_UNKNOWN && if (version_format != FWUPD_VERSION_FORMAT_UNKNOWN &&
priv->version_format != FU_VERSION_FORMAT_PLAIN) { version_format != FWUPD_VERSION_FORMAT_PLAIN) {
version_safe = g_string_new (NULL); version_safe = g_string_new (NULL);
for (guint i = 0; version[i] != '\0'; i++) { for (guint i = 0; version[i] != '\0'; i++) {
if (fu_device_is_valid_semver_char (version[i])) if (fu_device_is_valid_semver_char (version[i]))
@ -1217,8 +1209,10 @@ fu_device_set_version (FuDevice *self, const gchar *version)
} }
/* try to autodetect the version-format */ /* try to autodetect the version-format */
if (priv->version_format == FU_VERSION_FORMAT_UNKNOWN) if (version_format == FWUPD_VERSION_FORMAT_UNKNOWN) {
priv->version_format = fu_common_version_guess_format (version_safe->str); version_format = fu_common_version_guess_format (version_safe->str);
fu_device_set_version_format (self, version_format);
}
fwupd_device_set_version (FWUPD_DEVICE (self), version_safe->str); fwupd_device_set_version (FWUPD_DEVICE (self), version_safe->str);
} }
@ -1532,43 +1526,6 @@ fu_device_set_status (FuDevice *self, FwupdStatus status)
g_object_notify (G_OBJECT (self), "status"); g_object_notify (G_OBJECT (self), "status");
} }
/**
* fu_device_get_version_format:
* @self: A #FuDevice
*
* Returns how the device version should be formatted.
*
* Returns: the version format, e.g. %FU_VERSION_FORMAT_TRIPLET
*
* Since: 1.2.0
**/
FuVersionFormat
fu_device_get_version_format (FuDevice *self)
{
FuDevicePrivate *priv = GET_PRIVATE (self);
g_return_val_if_fail (FU_IS_DEVICE (self), 0);
return priv->version_format;
}
/**
* fu_device_set_version_format:
* @self: A #FuDevice
* @version_format: the version_format value, e.g. %FU_VERSION_FORMAT_TRIPLET
*
* Sets how the version should be formatted.
*
* Since: 1.2.0
**/
void
fu_device_set_version_format (FuDevice *self, FuVersionFormat version_format)
{
FuDevicePrivate *priv = GET_PRIVATE (self);
g_return_if_fail (FU_IS_DEVICE (self));
if (priv->version_format == version_format)
return;
priv->version_format = version_format;
}
/** /**
* fu_device_get_progress: * fu_device_get_progress:
* @self: A #FuDevice * @self: A #FuDevice
@ -1653,10 +1610,6 @@ fu_device_to_string (FuDevice *self)
tmp = fwupd_device_to_string (FWUPD_DEVICE (self)); tmp = fwupd_device_to_string (FWUPD_DEVICE (self));
if (tmp != NULL && tmp[0] != '\0') if (tmp != NULL && tmp[0] != '\0')
g_string_append (str, tmp); g_string_append (str, tmp);
if (priv->version_format != FU_VERSION_FORMAT_UNKNOWN) {
fwupd_pad_kv_str (str, "VersionFormat",
fu_common_version_format_to_string (priv->version_format));
}
if (priv->alternate_id != NULL) if (priv->alternate_id != NULL)
fwupd_pad_kv_str (str, "AlternateId", priv->alternate_id); fwupd_pad_kv_str (str, "AlternateId", priv->alternate_id);
if (priv->equivalent_id != NULL) if (priv->equivalent_id != NULL)
@ -2236,8 +2189,6 @@ fu_device_incorporate (FuDevice *self, FuDevice *donor)
fu_device_set_equivalent_id (self, fu_device_get_equivalent_id (donor)); fu_device_set_equivalent_id (self, fu_device_get_equivalent_id (donor));
if (priv->quirks == NULL) if (priv->quirks == NULL)
fu_device_set_quirks (self, fu_device_get_quirks (donor)); fu_device_set_quirks (self, fu_device_get_quirks (donor));
if (priv->version_format == FU_VERSION_FORMAT_UNKNOWN)
fu_device_set_version_format (self, fu_device_get_version_format (donor));
fu_mutex_read_lock (priv_donor->parent_guids_mutex); fu_mutex_read_lock (priv_donor->parent_guids_mutex);
for (guint i = 0; i < parent_guids->len; i++) for (guint i = 0; i < parent_guids->len; i++)
fu_device_add_parent_guid (self, g_ptr_array_index (parent_guids, i)); fu_device_add_parent_guid (self, g_ptr_array_index (parent_guids, i));
@ -2312,14 +2263,6 @@ fu_device_class_init (FuDeviceClass *klass)
G_PARAM_STATIC_NAME); G_PARAM_STATIC_NAME);
g_object_class_install_property (object_class, PROP_PROGRESS, pspec); g_object_class_install_property (object_class, PROP_PROGRESS, pspec);
pspec = g_param_spec_uint ("version-format", NULL, NULL,
FU_VERSION_FORMAT_UNKNOWN,
FU_VERSION_FORMAT_LAST,
FU_VERSION_FORMAT_UNKNOWN,
G_PARAM_READWRITE |
G_PARAM_STATIC_NAME);
g_object_class_install_property (object_class, PROP_VERSION_FORMAT, pspec);
pspec = g_param_spec_object ("quirks", NULL, NULL, pspec = g_param_spec_object ("quirks", NULL, NULL,
FU_TYPE_QUIRKS, FU_TYPE_QUIRKS,
G_PARAM_READWRITE | G_PARAM_READWRITE |

View File

@ -97,6 +97,7 @@ FuDevice *fu_device_new (void);
#define fu_device_set_vendor_id(d,v) fwupd_device_set_vendor_id(FWUPD_DEVICE(d),v) #define fu_device_set_vendor_id(d,v) fwupd_device_set_vendor_id(FWUPD_DEVICE(d),v)
#define fu_device_set_version_lowest(d,v) fwupd_device_set_version_lowest(FWUPD_DEVICE(d),v) #define fu_device_set_version_lowest(d,v) fwupd_device_set_version_lowest(FWUPD_DEVICE(d),v)
#define fu_device_set_version_bootloader(d,v) fwupd_device_set_version_bootloader(FWUPD_DEVICE(d),v) #define fu_device_set_version_bootloader(d,v) fwupd_device_set_version_bootloader(FWUPD_DEVICE(d),v)
#define fu_device_set_version_format(d,v) fwupd_device_set_version_format(FWUPD_DEVICE(d),v)
#define fu_device_set_flashes_left(d,v) fwupd_device_set_flashes_left(FWUPD_DEVICE(d),v) #define fu_device_set_flashes_left(d,v) fwupd_device_set_flashes_left(FWUPD_DEVICE(d),v)
#define fu_device_set_install_duration(d,v) fwupd_device_set_install_duration(FWUPD_DEVICE(d),v) #define fu_device_set_install_duration(d,v) fwupd_device_set_install_duration(FWUPD_DEVICE(d),v)
#define fu_device_get_checksums(d) fwupd_device_get_checksums(FWUPD_DEVICE(d)) #define fu_device_get_checksums(d) fwupd_device_get_checksums(FWUPD_DEVICE(d))
@ -117,6 +118,7 @@ FuDevice *fu_device_new (void);
#define fu_device_get_version(d) fwupd_device_get_version(FWUPD_DEVICE(d)) #define fu_device_get_version(d) fwupd_device_get_version(FWUPD_DEVICE(d))
#define fu_device_get_version_lowest(d) fwupd_device_get_version_lowest(FWUPD_DEVICE(d)) #define fu_device_get_version_lowest(d) fwupd_device_get_version_lowest(FWUPD_DEVICE(d))
#define fu_device_get_version_bootloader(d) fwupd_device_get_version_bootloader(FWUPD_DEVICE(d)) #define fu_device_get_version_bootloader(d) fwupd_device_get_version_bootloader(FWUPD_DEVICE(d))
#define fu_device_get_version_format(d) fwupd_device_get_version_format(FWUPD_DEVICE(d))
#define fu_device_get_vendor_id(d) fwupd_device_get_vendor_id(FWUPD_DEVICE(d)) #define fu_device_get_vendor_id(d) fwupd_device_get_vendor_id(FWUPD_DEVICE(d))
#define fu_device_get_flashes_left(d) fwupd_device_get_flashes_left(FWUPD_DEVICE(d)) #define fu_device_get_flashes_left(d) fwupd_device_get_flashes_left(FWUPD_DEVICE(d))
#define fu_device_get_install_duration(d) fwupd_device_get_install_duration(FWUPD_DEVICE(d)) #define fu_device_get_install_duration(d) fwupd_device_get_install_duration(FWUPD_DEVICE(d))
@ -183,9 +185,6 @@ void fu_device_set_remove_delay (FuDevice *self,
FwupdStatus fu_device_get_status (FuDevice *self); FwupdStatus fu_device_get_status (FuDevice *self);
void fu_device_set_status (FuDevice *self, void fu_device_set_status (FuDevice *self,
FwupdStatus status); FwupdStatus status);
FuVersionFormat fu_device_get_version_format (FuDevice *self);
void fu_device_set_version_format (FuDevice *self,
FuVersionFormat version_format);
void fu_device_set_firmware_size (FuDevice *self, void fu_device_set_firmware_size (FuDevice *self,
guint64 size); guint64 size);
void fu_device_set_firmware_size_min (FuDevice *self, void fu_device_set_firmware_size_min (FuDevice *self,

View File

@ -210,7 +210,7 @@ fu_engine_device_changed_cb (FuDeviceList *device_list, FuDevice *device, FuEngi
static gboolean static gboolean
fu_engine_set_device_version_format (FuEngine *self, FuDevice *device, XbNode *component, GError **error) fu_engine_set_device_version_format (FuEngine *self, FuDevice *device, XbNode *component, GError **error)
{ {
FuVersionFormat fmt; FwupdVersionFormat fmt;
const gchar *developer_name; const gchar *developer_name;
const gchar *version_format; const gchar *version_format;
@ -219,8 +219,8 @@ fu_engine_set_device_version_format (FuEngine *self, FuDevice *device, XbNode *c
"custom/value[@key='LVFS::VersionFormat']", "custom/value[@key='LVFS::VersionFormat']",
NULL); NULL);
if (version_format != NULL) { if (version_format != NULL) {
fmt = fu_common_version_format_from_string (version_format); fmt = fwupd_version_format_from_string (version_format);
if (fmt == FU_VERSION_FORMAT_UNKNOWN) { if (fmt == FWUPD_VERSION_FORMAT_UNKNOWN) {
g_set_error (error, g_set_error (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
@ -241,8 +241,8 @@ fu_engine_set_device_version_format (FuEngine *self, FuDevice *device, XbNode *c
version_format = fu_quirks_lookup_by_id (self->quirks, group, version_format = fu_quirks_lookup_by_id (self->quirks, group,
FU_QUIRKS_UEFI_VERSION_FORMAT); FU_QUIRKS_UEFI_VERSION_FORMAT);
if (version_format != NULL) { if (version_format != NULL) {
fmt = fu_common_version_format_from_string (version_format); fmt = fwupd_version_format_from_string (version_format);
if (fmt == FU_VERSION_FORMAT_UNKNOWN) { if (fmt == FWUPD_VERSION_FORMAT_UNKNOWN) {
g_set_error (error, g_set_error (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
@ -265,7 +265,7 @@ fu_engine_set_device_version_format (FuEngine *self, FuDevice *device, XbNode *c
static gchar * static gchar *
fu_engine_get_release_version (FuEngine *self, FuDevice *dev, XbNode *rel, GError **error) fu_engine_get_release_version (FuEngine *self, FuDevice *dev, XbNode *rel, GError **error)
{ {
FuVersionFormat fmt = FU_VERSION_FORMAT_TRIPLET; FwupdVersionFormat fmt = FWUPD_VERSION_FORMAT_TRIPLET;
const gchar *version; const gchar *version;
guint64 ver_uint32; guint64 ver_uint32;
@ -285,7 +285,7 @@ fu_engine_get_release_version (FuEngine *self, FuDevice *dev, XbNode *rel, GErro
/* specified in metadata or from a quirk */ /* specified in metadata or from a quirk */
fmt = fu_device_get_version_format (dev); fmt = fu_device_get_version_format (dev);
if (fmt == FU_VERSION_FORMAT_UNKNOWN) { if (fmt == FWUPD_VERSION_FORMAT_UNKNOWN) {
g_set_error (error, g_set_error (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
@ -295,7 +295,7 @@ fu_engine_get_release_version (FuEngine *self, FuDevice *dev, XbNode *rel, GErro
} }
/* don't touch my version! */ /* don't touch my version! */
if (fmt == FU_VERSION_FORMAT_PLAIN) if (fmt == FWUPD_VERSION_FORMAT_PLAIN)
return g_strdup (version); return g_strdup (version);
/* parse as integer */ /* parse as integer */
@ -3734,7 +3734,7 @@ fu_engine_add_device (FuEngine *self, FuDevice *device)
} }
if (fu_device_get_version (device) != NULL && if (fu_device_get_version (device) != NULL &&
fu_device_get_version_format (device) == FU_VERSION_FORMAT_UNKNOWN) { fu_device_get_version_format (device) == FWUPD_VERSION_FORMAT_UNKNOWN) {
fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE); fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE);
fu_device_set_update_error (device, "VersionFormat is ambiguous for this device"); fu_device_set_update_error (device, "VersionFormat is ambiguous for this device");
} }

View File

@ -92,7 +92,7 @@ fu_install_task_get_is_downgrade (FuInstallTask *self)
return self->is_downgrade; return self->is_downgrade;
} }
static FuVersionFormat static FwupdVersionFormat
fu_install_task_guess_version_format (FuInstallTask *self, const gchar *version) fu_install_task_guess_version_format (FuInstallTask *self, const gchar *version)
{ {
const gchar *tmp; const gchar *tmp;
@ -100,7 +100,7 @@ fu_install_task_guess_version_format (FuInstallTask *self, const gchar *version)
/* explicit set */ /* explicit set */
tmp = xb_node_query_text (self->component, "custom/value[@key='LVFS::VersionFormat']", NULL); tmp = xb_node_query_text (self->component, "custom/value[@key='LVFS::VersionFormat']", NULL);
if (tmp != NULL) if (tmp != NULL)
return fu_common_version_format_from_string (tmp); return fwupd_version_format_from_string (tmp);
/* count section from dotted notation */ /* count section from dotted notation */
return fu_common_version_guess_format (version); return fu_common_version_guess_format (version);
@ -123,7 +123,7 @@ fu_install_task_check_requirements (FuInstallTask *self,
FwupdInstallFlags flags, FwupdInstallFlags flags,
GError **error) GError **error)
{ {
FuVersionFormat fmt; FwupdVersionFormat fmt;
const gchar *version; const gchar *version;
const gchar *version_release; const gchar *version_release;
const gchar *version_lowest; const gchar *version_lowest;
@ -234,21 +234,21 @@ fu_install_task_check_requirements (FuInstallTask *self,
/* check the version formats match */ /* check the version formats match */
fmt = fu_install_task_guess_version_format (self, version_release); fmt = fu_install_task_guess_version_format (self, version_release);
if (fmt != FU_VERSION_FORMAT_UNKNOWN && if (fmt != FWUPD_VERSION_FORMAT_UNKNOWN &&
fmt != fu_device_get_version_format (self->device)) { fmt != fu_device_get_version_format (self->device)) {
FuVersionFormat fmt_dev = fu_device_get_version_format (self->device); FwupdVersionFormat fmt_dev = fu_device_get_version_format (self->device);
if (flags & FWUPD_INSTALL_FLAG_FORCE) { if (flags & FWUPD_INSTALL_FLAG_FORCE) {
g_warning ("ignoring version format difference %s:%s", g_warning ("ignoring version format difference %s:%s",
fu_common_version_format_to_string (fmt_dev), fwupd_version_format_to_string (fmt_dev),
fu_common_version_format_to_string (fmt)); fwupd_version_format_to_string (fmt));
} else { } else {
g_set_error (error, g_set_error (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
"Firmware version formats were different, " "Firmware version formats were different, "
"device was '%s' and release is '%s'", "device was '%s' and release is '%s'",
fu_common_version_format_to_string (fmt_dev), fwupd_version_format_to_string (fmt_dev),
fu_common_version_format_to_string (fmt)); fwupd_version_format_to_string (fmt));
return FALSE; return FALSE;
} }
} }

View File

@ -156,16 +156,16 @@ fu_archive_cab_func (void)
static void static void
fu_common_version_guess_format_func (void) fu_common_version_guess_format_func (void)
{ {
g_assert_cmpint (fu_common_version_guess_format (NULL), ==, FU_VERSION_FORMAT_UNKNOWN); g_assert_cmpint (fu_common_version_guess_format (NULL), ==, FWUPD_VERSION_FORMAT_UNKNOWN);
g_assert_cmpint (fu_common_version_guess_format (""), ==, FU_VERSION_FORMAT_UNKNOWN); g_assert_cmpint (fu_common_version_guess_format (""), ==, FWUPD_VERSION_FORMAT_UNKNOWN);
g_assert_cmpint (fu_common_version_guess_format ("1234ac"), ==, FU_VERSION_FORMAT_PLAIN); g_assert_cmpint (fu_common_version_guess_format ("1234ac"), ==, FWUPD_VERSION_FORMAT_PLAIN);
g_assert_cmpint (fu_common_version_guess_format ("1.2"), ==, FU_VERSION_FORMAT_PAIR); g_assert_cmpint (fu_common_version_guess_format ("1.2"), ==, FWUPD_VERSION_FORMAT_PAIR);
g_assert_cmpint (fu_common_version_guess_format ("1.2.3"), ==, FU_VERSION_FORMAT_TRIPLET); g_assert_cmpint (fu_common_version_guess_format ("1.2.3"), ==, FWUPD_VERSION_FORMAT_TRIPLET);
g_assert_cmpint (fu_common_version_guess_format ("1.2.3.4"), ==, FU_VERSION_FORMAT_QUAD); g_assert_cmpint (fu_common_version_guess_format ("1.2.3.4"), ==, FWUPD_VERSION_FORMAT_QUAD);
g_assert_cmpint (fu_common_version_guess_format ("1.2.3.4.5"), ==, FU_VERSION_FORMAT_UNKNOWN); g_assert_cmpint (fu_common_version_guess_format ("1.2.3.4.5"), ==, FWUPD_VERSION_FORMAT_UNKNOWN);
g_assert_cmpint (fu_common_version_guess_format ("1a.2b.3"), ==, FU_VERSION_FORMAT_PLAIN); g_assert_cmpint (fu_common_version_guess_format ("1a.2b.3"), ==, FWUPD_VERSION_FORMAT_PLAIN);
g_assert_cmpint (fu_common_version_guess_format ("1"), ==, FU_VERSION_FORMAT_UNKNOWN); g_assert_cmpint (fu_common_version_guess_format ("1"), ==, FWUPD_VERSION_FORMAT_NUMBER);
g_assert_cmpint (fu_common_version_guess_format ("0x10201"), ==, FU_VERSION_FORMAT_UNKNOWN); g_assert_cmpint (fu_common_version_guess_format ("0x10201"), ==, FWUPD_VERSION_FORMAT_NUMBER);
} }
static void static void
@ -740,7 +740,7 @@ fu_engine_device_unlock_func (void)
fu_device_set_id (device, "UEFI-dummy-dev0"); fu_device_set_id (device, "UEFI-dummy-dev0");
fu_device_add_guid (device, "2d47f29b-83a2-4f31-a2e8-63474f4d4c2e"); fu_device_add_guid (device, "2d47f29b-83a2-4f31-a2e8-63474f4d4c2e");
fu_device_add_flag (device, FWUPD_DEVICE_FLAG_LOCKED); fu_device_add_flag (device, FWUPD_DEVICE_FLAG_LOCKED);
fu_device_set_version_format (device, FU_VERSION_FORMAT_PLAIN); fu_device_set_version_format (device, FWUPD_VERSION_FORMAT_PLAIN);
fu_engine_add_device (engine, device); fu_engine_add_device (engine, device);
/* ensure the metainfo was matched */ /* ensure the metainfo was matched */
@ -1144,6 +1144,7 @@ fu_engine_history_func (void)
" Plugin: test\n" " Plugin: test\n"
" Flags: updatable\n" " Flags: updatable\n"
" Version: 1.2.2\n" " Version: 1.2.2\n"
" VersionFormat: triplet\n"
" Created: 2018-01-07\n" " Created: 2018-01-07\n"
" Modified: 2017-12-27\n" " Modified: 2017-12-27\n"
" UpdateState: success\n" " UpdateState: success\n"
@ -1151,8 +1152,7 @@ fu_engine_history_func (void)
" [Release]\n" " [Release]\n"
" Version: 1.2.3\n" " Version: 1.2.3\n"
" Checksum: SHA1(%s)\n" " Checksum: SHA1(%s)\n"
" Flags: none\n" " Flags: none\n",
" VersionFormat: triplet\n",
checksum); checksum);
ret = fu_test_compare_lines (device_str, device_str_expected, &error); ret = fu_test_compare_lines (device_str, device_str_expected, &error);
g_assert_no_error (error); g_assert_no_error (error);
@ -1377,6 +1377,7 @@ fu_engine_history_error_func (void)
" Plugin: test\n" " Plugin: test\n"
" Flags: updatable\n" " Flags: updatable\n"
" Version: 1.2.2\n" " Version: 1.2.2\n"
" VersionFormat: triplet\n"
" Created: 2018-01-07\n" " Created: 2018-01-07\n"
" Modified: 2017-12-27\n" " Modified: 2017-12-27\n"
" UpdateState: failed\n" " UpdateState: failed\n"
@ -1385,8 +1386,7 @@ fu_engine_history_error_func (void)
" [Release]\n" " [Release]\n"
" Version: 1.2.3\n" " Version: 1.2.3\n"
" Checksum: SHA1(%s)\n" " Checksum: SHA1(%s)\n"
" Flags: none\n" " Flags: none\n",
" VersionFormat: triplet\n",
checksum); checksum);
ret = fu_test_compare_lines (device_str, device_str_expected, &error); ret = fu_test_compare_lines (device_str, device_str_expected, &error);
g_assert_no_error (error); g_assert_no_error (error);
@ -1797,7 +1797,7 @@ static void
fu_device_version_format_func (void) fu_device_version_format_func (void)
{ {
g_autoptr(FuDevice) device = fu_device_new (); g_autoptr(FuDevice) device = fu_device_new ();
fu_device_set_version_format (device, FU_VERSION_FORMAT_TRIPLET); fu_device_set_version_format (device, FWUPD_VERSION_FORMAT_TRIPLET);
fu_device_set_version (device, "Ver1.2.3 RELEASE"); fu_device_set_version (device, "Ver1.2.3 RELEASE");
g_assert_cmpstr (fu_device_get_version (device), ==, "1.2.3"); g_assert_cmpstr (fu_device_get_version (device), ==, "1.2.3");
} }
@ -3537,39 +3537,39 @@ fu_common_version_func (void)
struct { struct {
guint32 val; guint32 val;
const gchar *ver; const gchar *ver;
FuVersionFormat flags; FwupdVersionFormat flags;
} version_from_uint32[] = { } version_from_uint32[] = {
{ 0x0, "0.0.0.0", FU_VERSION_FORMAT_QUAD }, { 0x0, "0.0.0.0", FWUPD_VERSION_FORMAT_QUAD },
{ 0xff, "0.0.0.255", FU_VERSION_FORMAT_QUAD }, { 0xff, "0.0.0.255", FWUPD_VERSION_FORMAT_QUAD },
{ 0xff01, "0.0.255.1", FU_VERSION_FORMAT_QUAD }, { 0xff01, "0.0.255.1", FWUPD_VERSION_FORMAT_QUAD },
{ 0xff0001, "0.255.0.1", FU_VERSION_FORMAT_QUAD }, { 0xff0001, "0.255.0.1", FWUPD_VERSION_FORMAT_QUAD },
{ 0xff000100, "255.0.1.0", FU_VERSION_FORMAT_QUAD }, { 0xff000100, "255.0.1.0", FWUPD_VERSION_FORMAT_QUAD },
{ 0x0, "0.0.0", FU_VERSION_FORMAT_TRIPLET }, { 0x0, "0.0.0", FWUPD_VERSION_FORMAT_TRIPLET },
{ 0xff, "0.0.255", FU_VERSION_FORMAT_TRIPLET }, { 0xff, "0.0.255", FWUPD_VERSION_FORMAT_TRIPLET },
{ 0xff01, "0.0.65281", FU_VERSION_FORMAT_TRIPLET }, { 0xff01, "0.0.65281", FWUPD_VERSION_FORMAT_TRIPLET },
{ 0xff0001, "0.255.1", FU_VERSION_FORMAT_TRIPLET }, { 0xff0001, "0.255.1", FWUPD_VERSION_FORMAT_TRIPLET },
{ 0xff000100, "255.0.256", FU_VERSION_FORMAT_TRIPLET }, { 0xff000100, "255.0.256", FWUPD_VERSION_FORMAT_TRIPLET },
{ 0x0, "0", FU_VERSION_FORMAT_PLAIN }, { 0x0, "0", FWUPD_VERSION_FORMAT_NUMBER },
{ 0xff000100, "4278190336", FU_VERSION_FORMAT_PLAIN }, { 0xff000100, "4278190336", FWUPD_VERSION_FORMAT_NUMBER },
{ 0x0, "11.0.0.0", FU_VERSION_FORMAT_INTEL_ME }, { 0x0, "11.0.0.0", FWUPD_VERSION_FORMAT_INTEL_ME },
{ 0xffffffff, "18.31.255.65535", FU_VERSION_FORMAT_INTEL_ME }, { 0xffffffff, "18.31.255.65535", FWUPD_VERSION_FORMAT_INTEL_ME },
{ 0x0b32057a, "11.11.50.1402", FU_VERSION_FORMAT_INTEL_ME }, { 0x0b32057a, "11.11.50.1402", FWUPD_VERSION_FORMAT_INTEL_ME },
{ 0xb8320d84, "11.8.50.3460", FU_VERSION_FORMAT_INTEL_ME2 }, { 0xb8320d84, "11.8.50.3460", FWUPD_VERSION_FORMAT_INTEL_ME2 },
{ 0, NULL } { 0, NULL }
}; };
struct { struct {
guint16 val; guint16 val;
const gchar *ver; const gchar *ver;
FuVersionFormat flags; FwupdVersionFormat flags;
} version_from_uint16[] = { } version_from_uint16[] = {
{ 0x0, "0.0", FU_VERSION_FORMAT_PAIR }, { 0x0, "0.0", FWUPD_VERSION_FORMAT_PAIR },
{ 0xff, "0.255", FU_VERSION_FORMAT_PAIR }, { 0xff, "0.255", FWUPD_VERSION_FORMAT_PAIR },
{ 0xff01, "255.1", FU_VERSION_FORMAT_PAIR }, { 0xff01, "255.1", FWUPD_VERSION_FORMAT_PAIR },
{ 0x0, "0.0", FU_VERSION_FORMAT_BCD }, { 0x0, "0.0", FWUPD_VERSION_FORMAT_BCD },
{ 0x0110, "1.10", FU_VERSION_FORMAT_BCD }, { 0x0110, "1.10", FWUPD_VERSION_FORMAT_BCD },
{ 0x9999, "99.99", FU_VERSION_FORMAT_BCD }, { 0x9999, "99.99", FWUPD_VERSION_FORMAT_BCD },
{ 0x0, "0", FU_VERSION_FORMAT_PLAIN }, { 0x0, "0", FWUPD_VERSION_FORMAT_NUMBER },
{ 0x1234, "4660", FU_VERSION_FORMAT_PLAIN }, { 0x1234, "4660", FWUPD_VERSION_FORMAT_NUMBER },
{ 0, NULL } { 0, NULL }
}; };
struct { struct {

View File

@ -239,7 +239,7 @@ fu_usb_device_probe (FuDevice *device, GError **error)
release = g_usb_device_get_release (priv->usb_device); release = g_usb_device_get_release (priv->usb_device);
if (release != 0x0) { if (release != 0x0) {
g_autofree gchar *version = NULL; g_autofree gchar *version = NULL;
version = fu_common_version_from_uint16 (release, FU_VERSION_FORMAT_BCD); version = fu_common_version_from_uint16 (release, FWUPD_VERSION_FORMAT_BCD);
fu_device_set_version (device, version); fu_device_set_version (device, version);
} }