Commit 9cab001a authored by Richard Hughes's avatar Richard Hughes
Browse files

Format the BCD USB revision numbers correctly

Add lots of code because it's not cool to hard depend on appstream-glib master.
parent ee18968b
......@@ -748,6 +748,18 @@ dfu_firmware_write_file (DfuFirmware *firmware, GFile *file,
error);
}
static gchar *
_bcd_version_from_uint16 (guint16 val)
{
#if AS_CHECK_VERSION(0,7,3)
return as_utils_version_from_uint16 (val, AS_VERSION_PARSE_FLAG_USE_BCD);
#else
guint maj = ((val >> 12) & 0x0f) * 10 + ((val >> 8) & 0x0f);
guint min = ((val >> 4) & 0x0f) * 10 + (val & 0x0f);
return g_strdup_printf ("%u.%u", maj, min);
#endif
}
/**
* dfu_firmware_to_string:
* @firmware: a #DfuFirmware
......@@ -771,8 +783,7 @@ dfu_firmware_to_string (DfuFirmware *firmware)
g_return_val_if_fail (DFU_IS_FIRMWARE (firmware), NULL);
release_str = as_utils_version_from_uint16 (priv->release,
AS_VERSION_PARSE_FLAG_NONE);
release_str = _bcd_version_from_uint16 (priv->release);
str = g_string_new ("");
g_string_append_printf (str, "vid: 0x%04x\n", priv->vid);
g_string_append_printf (str, "pid: 0x%04x\n", priv->pid);
......
......@@ -2059,6 +2059,18 @@ dfu_tool_list_target (DfuTarget *target)
}
}
static gchar *
_bcd_version_from_uint16 (guint16 val)
{
#if AS_CHECK_VERSION(0,7,3)
return as_utils_version_from_uint16 (val, AS_VERSION_PARSE_FLAG_USE_BCD);
#else
guint maj = ((val >> 12) & 0x0f) * 10 + ((val >> 8) & 0x0f);
guint min = ((val >> 4) & 0x0f) * 10 + (val & 0x0f);
return g_strdup_printf ("%u.%u", maj, min);
#endif
}
static gboolean
dfu_tool_list (DfuToolPrivate *priv, gchar **values, GError **error)
{
......@@ -2085,8 +2097,7 @@ dfu_tool_list (DfuToolPrivate *priv, gchar **values, GError **error)
/* device specific */
device = g_ptr_array_index (devices, i);
dev = dfu_device_get_usb_dev (device);
version = as_utils_version_from_uint16 (g_usb_device_get_release (dev),
AS_VERSION_PARSE_FLAG_NONE);
version = _bcd_version_from_uint16 (g_usb_device_get_release (dev));
g_print ("%s %04x:%04x [v%s]:\n",
/* TRANSLATORS: detected a DFU device */
_("Found"),
......
......@@ -31,6 +31,18 @@ struct FuPluginData {
DfuContext *context;
};
static gchar *
_bcd_version_from_uint16 (guint16 val)
{
#if AS_CHECK_VERSION(0,7,3)
return as_utils_version_from_uint16 (val, AS_VERSION_PARSE_FLAG_USE_BCD);
#else
guint maj = ((val >> 12) & 0x0f) * 10 + ((val >> 8) & 0x0f);
guint min = ((val >> 4) & 0x0f) * 10 + (val & 0x0f);
return g_strdup_printf ("%u.%u", maj, min);
#endif
}
static gboolean
fu_plugin_dfu_device_update (FuPlugin *plugin,
FuDevice *dev,
......@@ -68,8 +80,7 @@ fu_plugin_dfu_device_update (FuPlugin *plugin,
/* get version number, falling back to the DFU device release */
release = dfu_device_get_runtime_release (device);
if (release != 0xffff) {
version = as_utils_version_from_uint16 (release,
AS_VERSION_PARSE_FLAG_NONE);
version = _bcd_version_from_uint16 (release);
fu_device_set_version (dev, version);
}
......
......@@ -26,6 +26,18 @@
#include "fu-plugin.h"
#include "fu-plugin-vfuncs.h"
static gchar *
_bcd_version_from_uint16 (guint16 val)
{
#if AS_CHECK_VERSION(0,7,3)
return as_utils_version_from_uint16 (val, AS_VERSION_PARSE_FLAG_USE_BCD);
#else
guint maj = ((val >> 12) & 0x0f) * 10 + ((val >> 8) & 0x0f);
guint min = ((val >> 4) & 0x0f) * 10 + (val & 0x0f);
return g_strdup_printf ("%u.%u", maj, min);
#endif
}
static void
fu_plugin_usb_device_added_cb (GUsbContext *ctx,
GUsbDevice *device,
......@@ -91,10 +103,8 @@ fu_plugin_usb_device_added_cb (GUsbContext *ctx,
if (idx != 0x00)
version = g_usb_device_get_string_descriptor (device, idx, NULL);
if (version == NULL) {
guint16 release;
release = g_usb_device_get_release (device);
version = as_utils_version_from_uint16 (release,
AS_VERSION_PARSE_FLAG_NONE);
guint16 release = g_usb_device_get_release (device);
version = _bcd_version_from_uint16 (release);
}
fu_device_set_version (dev, version);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment