From d079b1a6ca16bc60656ec6bdfac0332979c99ab9 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 6 Mar 2015 10:09:55 +0000 Subject: [PATCH] Allow installing firmware without a specified device ID --- src/fu-common.h | 2 ++ src/fu-main.c | 61 ++++++++++++++++++++++++++++------- src/fu-util.c | 23 +++++++++++++ src/org.freedesktop.fwupd.xml | 4 ++- 4 files changed, 78 insertions(+), 12 deletions(-) diff --git a/src/fu-common.h b/src/fu-common.h index d89f513f4..eef441496 100644 --- a/src/fu-common.h +++ b/src/fu-common.h @@ -26,6 +26,8 @@ #define FWUPD_DBUS_SERVICE "org.freedesktop.fwupd" #define FWUPD_DBUS_INTERFACE "org.freedesktop.fwupd" +#define FWUPD_DEVICE_ID_ANY "*" + #define FU_ERROR fu_error_quark() #define FU_DEVICE_KEY_VERSION "Version" diff --git a/src/fu-main.c b/src/fu-main.c index 0226696de..324eebc0f 100644 --- a/src/fu-main.c +++ b/src/fu-main.c @@ -109,6 +109,25 @@ fu_main_get_item_by_id (FuMainPrivate *priv, const gchar *id) return NULL; } +/** + * fu_main_get_item_by_guid: + **/ +static FuDeviceItem * +fu_main_get_item_by_guid (FuMainPrivate *priv, const gchar *guid) +{ + FuDeviceItem *item; + const gchar *tmp; + guint i; + + for (i = 0; i < priv->devices->len; i++) { + item = g_ptr_array_index (priv->devices, i); + tmp = fu_device_get_metadata (item->device, FU_DEVICE_KEY_GUID); + if (g_strcmp0 (tmp, guid) == 0) + return item; + } + return NULL; +} + typedef struct { GDBusMethodInvocation *invocation; FuDevice *device; @@ -153,7 +172,8 @@ fu_main_helper_free (FuMainAuthHelper *helper) g_free (helper->id); g_free (helper->inf_filename); g_free (helper->tmp_path); - g_object_unref (helper->device); + if (helper->device != NULL) + g_object_unref (helper->device); g_object_unref (helper->invocation); g_object_unref (helper->cab_stream); g_free (helper); @@ -358,6 +378,22 @@ fu_main_update_helper (FuMainAuthHelper *helper, GError **error) error_local->message); return FALSE; } + + /* are we matching *any* hardware */ + if (helper->device == NULL) { + FuDeviceItem *item; + item = fu_main_get_item_by_guid (helper->priv, guid); + if (item == NULL) { + g_set_error (error, + FU_ERROR, + FU_ERROR_INVALID_FILE, + "no hardware matched %s", + guid); + return FALSE; + } + helper->device = g_object_ref (item->device); + } + tmp = fu_device_get_metadata (helper->device, FU_DEVICE_KEY_GUID); if (g_strcmp0 (guid, tmp) != 0) { g_set_error (error, @@ -498,7 +534,7 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender, /* return '' */ if (g_strcmp0 (method_name, "Update") == 0) { - FuDeviceItem *item; + FuDeviceItem *item = NULL; FuMainAuthHelper *helper; FuProviderFlags flags = FU_PROVIDER_UPDATE_FLAG_NONE; GDBusMessage *message; @@ -515,14 +551,16 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender, /* check the id exists */ g_variant_get (parameters, "(&sha{sv})", &id, &fd_handle, &iter); g_debug ("Called %s(%s,%i)", method_name, id, fd_handle); - item = fu_main_get_item_by_id (priv, id); - if (item == NULL) { - g_dbus_method_invocation_return_error (invocation, - FU_ERROR, - FU_ERROR_NO_SUCH_DEVICE, - "no such ID %s", - id); - return; + if (g_strcmp0 (id, FWUPD_DEVICE_ID_ANY) != 0) { + item = fu_main_get_item_by_id (priv, id); + if (item == NULL) { + g_dbus_method_invocation_return_error (invocation, + FU_ERROR, + FU_ERROR_NO_SUCH_DEVICE, + "no such device %s", + id); + return; + } } /* get options */ @@ -565,7 +603,8 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender, helper->id = g_strdup (id); helper->flags = flags; helper->priv = priv; - helper->device = g_object_ref (item->device); + if (item != NULL) + helper->device = g_object_ref (item->device); if (!fu_main_update_helper (helper, &error)) { g_dbus_method_invocation_return_gerror (helper->invocation, error); diff --git a/src/fu-util.c b/src/fu-util.c index 44903e73e..c89ae567c 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -372,6 +372,23 @@ fu_util_update_online (FuUtilPrivate *priv, gchar **values, GError **error) priv->flags, error); } +/** + * fu_util_install: + **/ +static gboolean +fu_util_install (FuUtilPrivate *priv, gchar **values, GError **error) +{ + if (g_strv_length (values) != 1) { + g_set_error_literal (error, + FU_ERROR, + FU_ERROR_INTERNAL, + "Invalid arguments: expected 'filename'"); + return FALSE; + } + return fu_util_update (priv, FWUPD_DEVICE_ID_ANY, + values[0], priv->flags, error); +} + /** * fu_util_update_prepared: **/ @@ -523,6 +540,12 @@ main (int argc, char *argv[]) /* TRANSLATORS: command description */ _("Install prepared updates now"), fu_util_update_prepared); + fu_util_add (priv->cmd_array, + "install", + NULL, + /* TRANSLATORS: command description */ + _("Install a firmware file on this hardware"), + fu_util_install); /* sort by command name */ g_ptr_array_sort (priv->cmd_array, diff --git a/src/org.freedesktop.fwupd.xml b/src/org.freedesktop.fwupd.xml index 829f10a0e..7faa768c8 100644 --- a/src/org.freedesktop.fwupd.xml +++ b/src/org.freedesktop.fwupd.xml @@ -52,7 +52,9 @@ - An ID, typically a GUID of the hardware to update. + + An ID, typically a GUID of the hardware to update, or the string + * to match any applicable hardware.